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.
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>
31 //=======================================================================
32 //function : IFSelect_ContextModif
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(),' ')
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');
50 //=======================================================================
51 //function : IFSelect_ContextModif
53 //=======================================================================
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(),' ')
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');
67 //=======================================================================
70 //=======================================================================
72 void IFSelect_ContextModif::Select (Interface_EntityIterator& list)
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;
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');
90 //=======================================================================
91 //function : OriginalGraph
93 //=======================================================================
95 const Interface_Graph& IFSelect_ContextModif::OriginalGraph () const
101 //=======================================================================
102 //function : OriginalModel
104 //=======================================================================
106 Handle(Interface_InterfaceModel) IFSelect_ContextModif::OriginalModel() const
108 return thegraf.Model();
112 //=======================================================================
113 //function : SetProtocol
115 //=======================================================================
117 void IFSelect_ContextModif::SetProtocol(const Handle(Interface_Protocol)& prot)
123 //=======================================================================
124 //function : Protocol
126 //=======================================================================
128 Handle(Interface_Protocol) IFSelect_ContextModif::Protocol() const
134 //=======================================================================
135 //function : HasFileName
137 //=======================================================================
139 Standard_Boolean IFSelect_ContextModif::HasFileName() const
141 return (thefile.Length() > 0);
145 //=======================================================================
146 //function : FileName
148 //=======================================================================
150 Standard_CString IFSelect_ContextModif::FileName () const
152 return thefile.ToCString();
156 //=======================================================================
159 //=======================================================================
161 Handle(Interface_CopyControl) IFSelect_ContextModif::Control () const
167 //=======================================================================
168 //function : IsForNone
170 //=======================================================================
172 Standard_Boolean IFSelect_ContextModif::IsForNone () const
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;
179 return Standard_True;
183 //=======================================================================
184 //function : IsForAll
186 //=======================================================================
188 Standard_Boolean IFSelect_ContextModif::IsForAll () const
194 //=======================================================================
195 //function : IsTransferred
197 //=======================================================================
199 Standard_Boolean IFSelect_ContextModif::IsTransferred
200 (const Handle(Standard_Transient)& ent) const
202 if (themap.IsNull()) return Standard_True;
203 Handle(Standard_Transient) newent;
204 return themap->Search(ent,newent);
208 //=======================================================================
209 //function : IsSelected
211 //=======================================================================
213 Standard_Boolean IFSelect_ContextModif::IsSelected
214 (const Handle(Standard_Transient)& ent) const
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) != ' ');
223 //=======================================================================
224 //function : SelectedOriginal
226 //=======================================================================
228 Interface_EntityIterator IFSelect_ContextModif::SelectedOriginal () const
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));
239 //=======================================================================
240 //function : SelectedResult
242 //=======================================================================
244 Interface_EntityIterator IFSelect_ContextModif::SelectedResult () const
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);
258 //=======================================================================
259 //function : SelectedCount
261 //=======================================================================
263 Standard_Integer IFSelect_ContextModif::SelectedCount () const
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 ++; }
273 //=======================================================================
276 //=======================================================================
278 void IFSelect_ContextModif::Start ()
280 thecurr = thecurt = 0;
285 //=======================================================================
288 //=======================================================================
290 Standard_Boolean IFSelect_ContextModif::More () const
292 return (thecurr > 0);
296 //=======================================================================
299 //=======================================================================
301 void IFSelect_ContextModif::Next()
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; }
309 thecurr = thecurt = 0;
313 //=======================================================================
314 //function : ValueOriginal
316 //=======================================================================
318 Handle(Standard_Transient) IFSelect_ContextModif::ValueOriginal () const
320 if (thecurr <= 0) throw Standard_NoSuchObject("IFSelect_ContextModif");
321 return thegraf.Entity(thecurr);
325 //=======================================================================
326 //function : ValueResult
328 //=======================================================================
330 Handle(Standard_Transient) IFSelect_ContextModif::ValueResult () const
332 if (thecurr <= 0) throw Standard_NoSuchObject("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);
341 //=======================================================================
342 //function : TraceModifier
344 //=======================================================================
346 void IFSelect_ContextModif::TraceModifier
347 (const Handle(IFSelect_GeneralModifier)& modif)
349 if (modif.IsNull()) return;
351 Message_Messenger::StreamBuffer sout = Message::SendInfo();
352 sout << "--- Run Modifier:" << std::endl;
353 Handle(IFSelect_Selection) sel = modif->Selection();
354 if (!sel.IsNull()) sout<<" Selection:"<<sel->Label();
355 else sout<<" (no Selection)";
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 ++;
362 if (nb == ne) sout<<" All Model ("<<nb<<" Entities)"<<std::endl;
363 else sout<<" Entities,Total:"<<nb<<" Concerned:"<<ne<<std::endl;
367 //=======================================================================
370 //=======================================================================
372 void IFSelect_ContextModif::Trace (const Standard_CString mess)
375 if (thecurr <= 0) return;
376 Message_Messenger::StreamBuffer sout = Message::SendInfo();
377 if (ValueOriginal() == ValueResult())
378 sout<<"-- ContextModif. Entity n0 "<<thecurr<<std::endl;
380 sout<<"-- ContextModif. Entity in Original, n0 "<<thecurr<<" in Result, n0 "
381 <<thecurt<<std::endl;
382 if (mess[0] != '\0') sout<<"-- Message:"<<mess<<std::endl;
386 //=======================================================================
387 //function : AddCheck
389 //=======================================================================
391 void IFSelect_ContextModif::AddCheck(const Handle(Interface_Check)& check)
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);
401 //=======================================================================
402 //function : AddWarning
404 //=======================================================================
406 void IFSelect_ContextModif::AddWarning(const Handle(Standard_Transient)& start,
407 const Standard_CString mess,
408 const Standard_CString orig)
410 thechek.CCheck(thegraf.EntityNumber(start))->AddWarning(mess,orig);
414 //=======================================================================
417 //=======================================================================
419 void IFSelect_ContextModif::AddFail(const Handle(Standard_Transient)& start,
420 const Standard_CString mess,
421 const Standard_CString orig)
423 thechek.CCheck(thegraf.EntityNumber(start))->AddFail(mess,orig);
427 //=======================================================================
430 //=======================================================================
432 Handle(Interface_Check) IFSelect_ContextModif::CCheck(const Standard_Integer num)
434 Handle(Interface_Check) ach = thechek.CCheck(num);
435 if (num > 0 && num <= thegraf.Size()) ach->SetEntity(thegraf.Entity(num));
440 //=======================================================================
443 //=======================================================================
445 Handle(Interface_Check) IFSelect_ContextModif::CCheck
446 (const Handle(Standard_Transient)& ent)
448 Standard_Integer num = thegraf.EntityNumber(ent);
449 if (num == 0) num = -1; // force l enregistrement
450 Handle(Interface_Check)& ach = thechek.CCheck(num);
456 //=======================================================================
457 //function : CheckList
459 //=======================================================================
461 Interface_CheckIterator IFSelect_ContextModif::CheckList () const