1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IFSelect_ContextModif.ixx>
15 #include <IFSelect_Selection.hxx>
16 #include <Message_Messenger.hxx>
17 #include <Message.hxx>
18 #include <Standard_NoSuchObject.hxx>
21 //=======================================================================
22 //function : IFSelect_ContextModif
24 //=======================================================================
26 IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
27 const Interface_CopyTool& TC,
28 const Standard_CString filename)
29 : thegraf (graph,Standard_False) , thefile (filename) ,
30 thelist (graph.Size(),' ')
32 themap = TC.Control(); thesel = Standard_False; thecurr = thecurt = 0;
33 Standard_Integer nb = thelist.Length();
34 Handle(Standard_Transient) newent;
35 for (Standard_Integer i = 1; i <= nb; i ++) {
36 if (themap->Search(graph.Entity(i),newent)) thelist.SetValue(i,'1');
41 //=======================================================================
42 //function : IFSelect_ContextModif
44 //=======================================================================
46 IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
47 const Standard_CString filename)
48 : thegraf (graph,Standard_False) , thefile (filename) ,
49 thelist (graph.Size(),' ')
51 thesel = Standard_False; thecurr = thecurt = 0;
52 Standard_Integer nb = thelist.Length();
53 Handle(Standard_Transient) newent;
54 for (Standard_Integer i = 1; i <= nb; i ++) thelist.SetValue(i,'1');
58 //=======================================================================
61 //=======================================================================
63 void IFSelect_ContextModif::Select (Interface_EntityIterator& list)
65 thesel = Standard_True;
66 Standard_Integer nb = thelist.Length();
67 for (Standard_Integer i = 1; i <= nb; i ++) thelist.SetValue(i,' ');
68 for (list.Start(); list.More(); list.Next()) {
69 Handle(Standard_Transient) start,newent;
71 Standard_Integer num = thegraf.EntityNumber(start);
72 if (num > nb || num < 0) num = 0;
73 if (themap.IsNull() && num > 0) thelist.SetValue(num,'1');
74 else if (themap->Search (start,newent)) {
75 if (num > 0) thelist.SetValue(num,'1');
81 //=======================================================================
82 //function : OriginalGraph
84 //=======================================================================
86 const Interface_Graph& IFSelect_ContextModif::OriginalGraph () const
92 //=======================================================================
93 //function : OriginalModel
95 //=======================================================================
97 Handle(Interface_InterfaceModel) IFSelect_ContextModif::OriginalModel() const
99 return thegraf.Model();
103 //=======================================================================
104 //function : SetProtocol
106 //=======================================================================
108 void IFSelect_ContextModif::SetProtocol(const Handle(Interface_Protocol)& prot)
114 //=======================================================================
115 //function : Protocol
117 //=======================================================================
119 Handle(Interface_Protocol) IFSelect_ContextModif::Protocol() const
125 //=======================================================================
126 //function : HasFileName
128 //=======================================================================
130 Standard_Boolean IFSelect_ContextModif::HasFileName() const
132 return (thefile.Length() > 0);
136 //=======================================================================
137 //function : FileName
139 //=======================================================================
141 Standard_CString IFSelect_ContextModif::FileName () const
143 return thefile.ToCString();
147 //=======================================================================
150 //=======================================================================
152 Handle(Interface_CopyControl) IFSelect_ContextModif::Control () const
158 //=======================================================================
159 //function : IsForNone
161 //=======================================================================
163 Standard_Boolean IFSelect_ContextModif::IsForNone () const
165 if (!thesel) return Standard_False;
166 Standard_Integer nb = thelist.Length();
167 for (Standard_Integer i = 1; i <= nb; i ++) {
168 if (thelist.Value(i) != ' ') return Standard_False;
170 return Standard_True;
174 //=======================================================================
175 //function : IsForAll
177 //=======================================================================
179 Standard_Boolean IFSelect_ContextModif::IsForAll () const
185 //=======================================================================
186 //function : IsTransferred
188 //=======================================================================
190 Standard_Boolean IFSelect_ContextModif::IsTransferred
191 (const Handle(Standard_Transient)& ent) const
193 if (themap.IsNull()) return Standard_True;
194 Handle(Standard_Transient) newent;
195 return themap->Search(ent,newent);
199 //=======================================================================
200 //function : IsSelected
202 //=======================================================================
204 Standard_Boolean IFSelect_ContextModif::IsSelected
205 (const Handle(Standard_Transient)& ent) const
207 // Select a deja verifie "IsTransferred"
208 Standard_Integer num = thegraf.EntityNumber(ent);
209 if (num == 0) return Standard_False;
210 return (thelist.Value(num) != ' ');
214 //=======================================================================
215 //function : SelectedOriginal
217 //=======================================================================
219 Interface_EntityIterator IFSelect_ContextModif::SelectedOriginal () const
221 Interface_EntityIterator list;
222 Standard_Integer nb = thelist.Length();
223 for (Standard_Integer i = 1; i <= nb; i ++) {
224 if (thelist.Value(i) != ' ') list.GetOneItem (thegraf.Entity(i));
230 //=======================================================================
231 //function : SelectedResult
233 //=======================================================================
235 Interface_EntityIterator IFSelect_ContextModif::SelectedResult () const
237 Interface_EntityIterator list;
238 Standard_Integer nb = thelist.Length();
239 for (Standard_Integer i = 1; i <= nb; i ++) {
240 Handle(Standard_Transient) newent;
241 if (themap.IsNull()) newent = thegraf.Entity(i);
242 else if (thelist.Value(i) != ' ') themap->Search (thegraf.Entity(i),newent);
243 if (!newent.IsNull()) list.GetOneItem (newent);
249 //=======================================================================
250 //function : SelectedCount
252 //=======================================================================
254 Standard_Integer IFSelect_ContextModif::SelectedCount () const
256 Standard_Integer nb = thelist.Length();
257 Standard_Integer ns = 0;
258 for (Standard_Integer i = 1; i <= nb; i ++)
259 { if (thelist.Value(i) != ' ') ns ++; }
264 //=======================================================================
267 //=======================================================================
269 void IFSelect_ContextModif::Start ()
271 thecurr = thecurt = 0;
276 //=======================================================================
279 //=======================================================================
281 Standard_Boolean IFSelect_ContextModif::More () const
283 return (thecurr > 0);
287 //=======================================================================
290 //=======================================================================
292 void IFSelect_ContextModif::Next()
294 Standard_Integer nb = thelist.Length();
295 // thecurr = thecurt;
296 // if (thecurr <= 0 && thecurt >= 0) return;
297 for (Standard_Integer i = thecurr+1; i <= nb; i ++) {
298 if (thelist.Value(i) != ' ') { thecurr = i; thecurt ++; return; }
300 thecurr = thecurt = 0;
304 //=======================================================================
305 //function : ValueOriginal
307 //=======================================================================
309 Handle(Standard_Transient) IFSelect_ContextModif::ValueOriginal () const
311 if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
312 return thegraf.Entity(thecurr);
316 //=======================================================================
317 //function : ValueResult
319 //=======================================================================
321 Handle(Standard_Transient) IFSelect_ContextModif::ValueResult () const
323 if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
324 Handle(Standard_Transient) ent,newent;
325 ent = thegraf.Entity(thecurr);
326 if (themap.IsNull()) newent = ent;
327 else themap->Search(ent,newent);
332 //=======================================================================
333 //function : TraceModifier
335 //=======================================================================
337 void IFSelect_ContextModif::TraceModifier
338 (const Handle(IFSelect_GeneralModifier)& modif)
340 if (modif.IsNull()) return;
342 Handle(Message_Messenger) sout = Message::DefaultMessenger();
343 sout << "--- Run Modifier:" << endl;
344 Handle(IFSelect_Selection) sel = modif->Selection();
345 if (!sel.IsNull()) sout<<" Selection:"<<sel->Label();
346 else sout<<" (no Selection)";
348 // on va simplement compter les entites
349 Standard_Integer ne = 0, nb = thelist.Length();
350 for (Standard_Integer i = 1; i <= nb; i ++) {
351 if (thelist.Value(i) != ' ') ne ++;
353 if (nb == ne) sout<<" All Model ("<<nb<<" Entities)"<<endl;
354 else sout<<" Entities,Total:"<<nb<<" Concerned:"<<ne<<endl;
358 //=======================================================================
361 //=======================================================================
363 void IFSelect_ContextModif::Trace (const Standard_CString mess)
366 if (thecurr <= 0) return;
367 Handle(Message_Messenger) sout = Message::DefaultMessenger();
368 if (ValueOriginal() == ValueResult())
369 sout<<"-- ContextModif. Entity n0 "<<thecurr<<endl;
371 sout<<"-- ContextModif. Entity in Original, n0 "<<thecurr<<" in Result, n0 "
373 if (mess[0] != '\0') sout<<"-- Message:"<<mess<<endl;
377 //=======================================================================
378 //function : AddCheck
380 //=======================================================================
382 void IFSelect_ContextModif::AddCheck(const Handle(Interface_Check)& check)
384 if (check->NbFails() + check->NbWarnings() == 0) return;
385 const Handle(Standard_Transient)& ent = check->Entity();
386 Standard_Integer num = thegraf.EntityNumber(ent);
387 if (num == 0 && !ent.IsNull()) num = -1; // force enregistrement
388 thechek.Add(check,num);
392 //=======================================================================
393 //function : AddWarning
395 //=======================================================================
397 void IFSelect_ContextModif::AddWarning(const Handle(Standard_Transient)& start,
398 const Standard_CString mess,
399 const Standard_CString orig)
401 thechek.CCheck(thegraf.EntityNumber(start))->AddWarning(mess,orig);
405 //=======================================================================
408 //=======================================================================
410 void IFSelect_ContextModif::AddFail(const Handle(Standard_Transient)& start,
411 const Standard_CString mess,
412 const Standard_CString orig)
414 thechek.CCheck(thegraf.EntityNumber(start))->AddFail(mess,orig);
418 //=======================================================================
421 //=======================================================================
423 Handle(Interface_Check) IFSelect_ContextModif::CCheck(const Standard_Integer num)
425 Handle(Interface_Check) ach = thechek.CCheck(num);
426 if (num > 0 && num <= thegraf.Size()) ach->SetEntity(thegraf.Entity(num));
431 //=======================================================================
434 //=======================================================================
436 Handle(Interface_Check) IFSelect_ContextModif::CCheck
437 (const Handle(Standard_Transient)& ent)
439 Standard_Integer num = thegraf.EntityNumber(ent);
440 if (num == 0) num = -1; // force l enregistrement
441 Handle(Interface_Check)& ach = thechek.CCheck(num);
447 //=======================================================================
448 //function : CheckList
450 //=======================================================================
452 Interface_CheckIterator IFSelect_ContextModif::CheckList () const