0024157: Parallelization of assembly part of BO
[occt.git] / src / IFSelect / IFSelect_ContextModif.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <IFSelect_ContextModif.ixx>
19#include <IFSelect_Selection.hxx>
20#include <Message_Messenger.hxx>
21#include <Message.hxx>
22#include <Standard_NoSuchObject.hxx>
23
24
25//=======================================================================
26//function : IFSelect_ContextModif
27//purpose :
28//=======================================================================
29
30IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
31 const Interface_CopyTool& TC,
32 const Standard_CString filename)
33 : thegraf (graph,Standard_False) , thefile (filename) ,
34 thelist (graph.Size(),' ')
35{
36 themap = TC.Control(); thesel = Standard_False; thecurr = thecurt = 0;
37 Standard_Integer nb = thelist.Length();
38 Handle(Standard_Transient) newent;
39 for (Standard_Integer i = 1; i <= nb; i ++) {
40 if (themap->Search(graph.Entity(i),newent)) thelist.SetValue(i,'1');
41 }
42}
43
44
45//=======================================================================
46//function : IFSelect_ContextModif
47//purpose :
48//=======================================================================
49
50IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
51 const Standard_CString filename)
52 : thegraf (graph,Standard_False) , thefile (filename) ,
53 thelist (graph.Size(),' ')
54{
55 thesel = Standard_False; thecurr = thecurt = 0;
56 Standard_Integer nb = thelist.Length();
57 Handle(Standard_Transient) newent;
58 for (Standard_Integer i = 1; i <= nb; i ++) thelist.SetValue(i,'1');
59}
60
61
62//=======================================================================
63//function : Select
64//purpose :
65//=======================================================================
66
67void IFSelect_ContextModif::Select (Interface_EntityIterator& list)
68{
69 thesel = Standard_True;
70 Standard_Integer nb = thelist.Length();
71 for (Standard_Integer i = 1; i <= nb; i ++) thelist.SetValue(i,' ');
72 for (list.Start(); list.More(); list.Next()) {
73 Handle(Standard_Transient) start,newent;
74 start = list.Value();
75 Standard_Integer num = thegraf.EntityNumber(start);
76 if (num > nb || num < 0) num = 0;
77 if (themap.IsNull() && num > 0) thelist.SetValue(num,'1');
78 else if (themap->Search (start,newent)) {
79 if (num > 0) thelist.SetValue(num,'1');
80 }
81 }
82}
83
84
85//=======================================================================
86//function : OriginalGraph
87//purpose :
88//=======================================================================
89
90const Interface_Graph& IFSelect_ContextModif::OriginalGraph () const
91{
92 return thegraf;
93}
94
95
96//=======================================================================
97//function : OriginalModel
98//purpose :
99//=======================================================================
100
101Handle(Interface_InterfaceModel) IFSelect_ContextModif::OriginalModel() const
102{
103 return thegraf.Model();
104}
105
106
107//=======================================================================
108//function : SetProtocol
109//purpose :
110//=======================================================================
111
112void IFSelect_ContextModif::SetProtocol(const Handle(Interface_Protocol)& prot)
113{
114 theprot = prot;
115}
116
117
118//=======================================================================
119//function : Protocol
120//purpose :
121//=======================================================================
122
123Handle(Interface_Protocol) IFSelect_ContextModif::Protocol() const
124{
125 return theprot;
126}
127
128
129//=======================================================================
130//function : HasFileName
131//purpose :
132//=======================================================================
133
134Standard_Boolean IFSelect_ContextModif::HasFileName() const
135{
136 return (thefile.Length() > 0);
137}
138
139
140//=======================================================================
141//function : FileName
142//purpose :
143//=======================================================================
144
145Standard_CString IFSelect_ContextModif::FileName () const
146{
147 return thefile.ToCString();
148}
149
150
151//=======================================================================
152//function : Control
153//purpose :
154//=======================================================================
155
156Handle(Interface_CopyControl) IFSelect_ContextModif::Control () const
157{
158 return themap;
159}
160
161
162//=======================================================================
163//function : IsForNone
164//purpose :
165//=======================================================================
166
167Standard_Boolean IFSelect_ContextModif::IsForNone () const
168{
169 if (!thesel) return Standard_False;
170 Standard_Integer nb = thelist.Length();
171 for (Standard_Integer i = 1; i <= nb; i ++) {
172 if (thelist.Value(i) != ' ') return Standard_False;
173 }
174 return Standard_True;
175}
176
177
178//=======================================================================
179//function : IsForAll
180//purpose :
181//=======================================================================
182
183Standard_Boolean IFSelect_ContextModif::IsForAll () const
184{
185 return (!thesel);
186}
187
188
189//=======================================================================
190//function : IsTransferred
191//purpose :
192//=======================================================================
193
194Standard_Boolean IFSelect_ContextModif::IsTransferred
195 (const Handle(Standard_Transient)& ent) const
196{
197 if (themap.IsNull()) return Standard_True;
198 Handle(Standard_Transient) newent;
199 return themap->Search(ent,newent);
200}
201
202
203//=======================================================================
204//function : IsSelected
205//purpose :
206//=======================================================================
207
208Standard_Boolean IFSelect_ContextModif::IsSelected
209 (const Handle(Standard_Transient)& ent) const
210{
211 // Select a deja verifie "IsTransferred"
212 Standard_Integer num = thegraf.EntityNumber(ent);
213 if (num == 0) return Standard_False;
214 return (thelist.Value(num) != ' ');
215}
216
217
218//=======================================================================
219//function : SelectedOriginal
220//purpose :
221//=======================================================================
222
223Interface_EntityIterator IFSelect_ContextModif::SelectedOriginal () const
224{
225 Interface_EntityIterator list;
226 Standard_Integer nb = thelist.Length();
227 for (Standard_Integer i = 1; i <= nb; i ++) {
228 if (thelist.Value(i) != ' ') list.GetOneItem (thegraf.Entity(i));
229 }
230 return list;
231}
232
233
234//=======================================================================
235//function : SelectedResult
236//purpose :
237//=======================================================================
238
239Interface_EntityIterator IFSelect_ContextModif::SelectedResult () const
240{
241 Interface_EntityIterator list;
242 Standard_Integer nb = thelist.Length();
243 for (Standard_Integer i = 1; i <= nb; i ++) {
244 Handle(Standard_Transient) newent;
245 if (themap.IsNull()) newent = thegraf.Entity(i);
246 else if (thelist.Value(i) != ' ') themap->Search (thegraf.Entity(i),newent);
247 if (!newent.IsNull()) list.GetOneItem (newent);
248 }
249 return list;
250}
251
252
253//=======================================================================
254//function : SelectedCount
255//purpose :
256//=======================================================================
257
258Standard_Integer IFSelect_ContextModif::SelectedCount () const
259{
260 Standard_Integer nb = thelist.Length();
261 Standard_Integer ns = 0;
262 for (Standard_Integer i = 1; i <= nb; i ++)
263 { if (thelist.Value(i) != ' ') ns ++; }
264 return ns;
265}
266
267
268//=======================================================================
269//function : Start
270//purpose :
271//=======================================================================
272
273void IFSelect_ContextModif::Start ()
274{
275 thecurr = thecurt = 0;
276 Next();
277}
278
279
280//=======================================================================
281//function : More
282//purpose :
283//=======================================================================
284
285Standard_Boolean IFSelect_ContextModif::More () const
286{
287 return (thecurr > 0);
288}
289
290
291//=======================================================================
292//function : Next
293//purpose :
294//=======================================================================
295
296void IFSelect_ContextModif::Next()
297{
298 Standard_Integer nb = thelist.Length();
299// thecurr = thecurt;
300// if (thecurr <= 0 && thecurt >= 0) return;
301 for (Standard_Integer i = thecurr+1; i <= nb; i ++) {
302 if (thelist.Value(i) != ' ') { thecurr = i; thecurt ++; return; }
303 }
304 thecurr = thecurt = 0;
305}
306
307
308//=======================================================================
309//function : ValueOriginal
310//purpose :
311//=======================================================================
312
313Handle(Standard_Transient) IFSelect_ContextModif::ValueOriginal () const
314{
315 if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
316 return thegraf.Entity(thecurr);
317}
318
319
320//=======================================================================
321//function : ValueResult
322//purpose :
323//=======================================================================
324
325Handle(Standard_Transient) IFSelect_ContextModif::ValueResult () const
326{
327 if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
328 Handle(Standard_Transient) ent,newent;
329 ent = thegraf.Entity(thecurr);
330 if (themap.IsNull()) newent = ent;
331 else themap->Search(ent,newent);
332 return newent;
333}
334
335
336//=======================================================================
337//function : TraceModifier
338//purpose :
339//=======================================================================
340
341void IFSelect_ContextModif::TraceModifier
342 (const Handle(IFSelect_GeneralModifier)& modif)
343{
344 if (modif.IsNull()) return;
345
346 Handle(Message_Messenger) sout = Message::DefaultMessenger();
347 sout << "--- Run Modifier:" << endl;
348 Handle(IFSelect_Selection) sel = modif->Selection();
349 if (!sel.IsNull()) sout<<" Selection:"<<sel->Label();
350 else sout<<" (no Selection)";
351
352// on va simplement compter les entites
353 Standard_Integer ne = 0, nb = thelist.Length();
354 for (Standard_Integer i = 1; i <= nb; i ++) {
355 if (thelist.Value(i) != ' ') ne ++;
356 }
357 if (nb == ne) sout<<" All Model ("<<nb<<" Entities)"<<endl;
358 else sout<<" Entities,Total:"<<nb<<" Concerned:"<<ne<<endl;
359}
360
361
362//=======================================================================
363//function : Trace
364//purpose :
365//=======================================================================
366
367void IFSelect_ContextModif::Trace (const Standard_CString mess)
368{
369// Trace courante
370 if (thecurr <= 0) return;
371 Handle(Message_Messenger) sout = Message::DefaultMessenger();
372 if (ValueOriginal() == ValueResult())
373 sout<<"-- ContextModif. Entity n0 "<<thecurr<<endl;
374 else
375 sout<<"-- ContextModif. Entity in Original, n0 "<<thecurr<<" in Result, n0 "
376 <<thecurt<<endl;
377 if (mess[0] != '\0') sout<<"-- Message:"<<mess<<endl;
378}
379
380
381//=======================================================================
382//function : AddCheck
383//purpose :
384//=======================================================================
385
386void IFSelect_ContextModif::AddCheck(const Handle(Interface_Check)& check)
387{
388 if (check->NbFails() + check->NbWarnings() == 0) return;
389 const Handle(Standard_Transient)& ent = check->Entity();
390 Standard_Integer num = thegraf.EntityNumber(ent);
391 if (num == 0 && !ent.IsNull()) num = -1; // force enregistrement
392 thechek.Add(check,num);
393}
394
395
396//=======================================================================
397//function : AddWarning
398//purpose :
399//=======================================================================
400
401void IFSelect_ContextModif::AddWarning(const Handle(Standard_Transient)& start,
402 const Standard_CString mess,
403 const Standard_CString orig)
404{
405 thechek.CCheck(thegraf.EntityNumber(start))->AddWarning(mess,orig);
406}
407
408
409//=======================================================================
410//function : AddFail
411//purpose :
412//=======================================================================
413
414void IFSelect_ContextModif::AddFail(const Handle(Standard_Transient)& start,
415 const Standard_CString mess,
416 const Standard_CString orig)
417{
418 thechek.CCheck(thegraf.EntityNumber(start))->AddFail(mess,orig);
419}
420
421
422//=======================================================================
423//function : CCheck
424//purpose :
425//=======================================================================
426
427Handle(Interface_Check) IFSelect_ContextModif::CCheck(const Standard_Integer num)
428{
429 Handle(Interface_Check) ach = thechek.CCheck(num);
430 if (num > 0 && num <= thegraf.Size()) ach->SetEntity(thegraf.Entity(num));
431 return ach;
432}
433
434
435//=======================================================================
436//function : CCheck
437//purpose :
438//=======================================================================
439
440Handle(Interface_Check) IFSelect_ContextModif::CCheck
441 (const Handle(Standard_Transient)& ent)
442{
443 Standard_Integer num = thegraf.EntityNumber(ent);
444 if (num == 0) num = -1; // force l enregistrement
445 Handle(Interface_Check)& ach = thechek.CCheck(num);
446 ach->SetEntity(ent);
447 return ach;
448}
449
450
451//=======================================================================
452//function : CheckList
453//purpose :
454//=======================================================================
455
456Interface_CheckIterator IFSelect_ContextModif::CheckList () const
457{
458 return thechek;
459}