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