1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <IFSelect_ContextModif.ixx>
19 #include <IFSelect_Selection.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Message.hxx>
22 #include <Standard_NoSuchObject.hxx>
25 //=======================================================================
26 //function : IFSelect_ContextModif
28 //=======================================================================
30 IFSelect_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(),' ')
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');
45 //=======================================================================
46 //function : IFSelect_ContextModif
48 //=======================================================================
50 IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
51 const Standard_CString filename)
52 : thegraf (graph,Standard_False) , thefile (filename) ,
53 thelist (graph.Size(),' ')
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');
62 //=======================================================================
65 //=======================================================================
67 void IFSelect_ContextModif::Select (Interface_EntityIterator& list)
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;
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');
85 //=======================================================================
86 //function : OriginalGraph
88 //=======================================================================
90 const Interface_Graph& IFSelect_ContextModif::OriginalGraph () const
96 //=======================================================================
97 //function : OriginalModel
99 //=======================================================================
101 Handle(Interface_InterfaceModel) IFSelect_ContextModif::OriginalModel() const
103 return thegraf.Model();
107 //=======================================================================
108 //function : SetProtocol
110 //=======================================================================
112 void IFSelect_ContextModif::SetProtocol(const Handle(Interface_Protocol)& prot)
118 //=======================================================================
119 //function : Protocol
121 //=======================================================================
123 Handle(Interface_Protocol) IFSelect_ContextModif::Protocol() const
129 //=======================================================================
130 //function : HasFileName
132 //=======================================================================
134 Standard_Boolean IFSelect_ContextModif::HasFileName() const
136 return (thefile.Length() > 0);
140 //=======================================================================
141 //function : FileName
143 //=======================================================================
145 Standard_CString IFSelect_ContextModif::FileName () const
147 return thefile.ToCString();
151 //=======================================================================
154 //=======================================================================
156 Handle(Interface_CopyControl) IFSelect_ContextModif::Control () const
162 //=======================================================================
163 //function : IsForNone
165 //=======================================================================
167 Standard_Boolean IFSelect_ContextModif::IsForNone () const
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;
174 return Standard_True;
178 //=======================================================================
179 //function : IsForAll
181 //=======================================================================
183 Standard_Boolean IFSelect_ContextModif::IsForAll () const
189 //=======================================================================
190 //function : IsTransferred
192 //=======================================================================
194 Standard_Boolean IFSelect_ContextModif::IsTransferred
195 (const Handle(Standard_Transient)& ent) const
197 if (themap.IsNull()) return Standard_True;
198 Handle(Standard_Transient) newent;
199 return themap->Search(ent,newent);
203 //=======================================================================
204 //function : IsSelected
206 //=======================================================================
208 Standard_Boolean IFSelect_ContextModif::IsSelected
209 (const Handle(Standard_Transient)& ent) const
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) != ' ');
218 //=======================================================================
219 //function : SelectedOriginal
221 //=======================================================================
223 Interface_EntityIterator IFSelect_ContextModif::SelectedOriginal () const
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));
234 //=======================================================================
235 //function : SelectedResult
237 //=======================================================================
239 Interface_EntityIterator IFSelect_ContextModif::SelectedResult () const
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);
253 //=======================================================================
254 //function : SelectedCount
256 //=======================================================================
258 Standard_Integer IFSelect_ContextModif::SelectedCount () const
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 ++; }
268 //=======================================================================
271 //=======================================================================
273 void IFSelect_ContextModif::Start ()
275 thecurr = thecurt = 0;
280 //=======================================================================
283 //=======================================================================
285 Standard_Boolean IFSelect_ContextModif::More () const
287 return (thecurr > 0);
291 //=======================================================================
294 //=======================================================================
296 void IFSelect_ContextModif::Next()
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; }
304 thecurr = thecurt = 0;
308 //=======================================================================
309 //function : ValueOriginal
311 //=======================================================================
313 Handle(Standard_Transient) IFSelect_ContextModif::ValueOriginal () const
315 if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
316 return thegraf.Entity(thecurr);
320 //=======================================================================
321 //function : ValueResult
323 //=======================================================================
325 Handle(Standard_Transient) IFSelect_ContextModif::ValueResult () const
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);
336 //=======================================================================
337 //function : TraceModifier
339 //=======================================================================
341 void IFSelect_ContextModif::TraceModifier
342 (const Handle(IFSelect_GeneralModifier)& modif)
344 if (modif.IsNull()) return;
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)";
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 ++;
357 if (nb == ne) sout<<" All Model ("<<nb<<" Entities)"<<endl;
358 else sout<<" Entities,Total:"<<nb<<" Concerned:"<<ne<<endl;
362 //=======================================================================
365 //=======================================================================
367 void IFSelect_ContextModif::Trace (const Standard_CString mess)
370 if (thecurr <= 0) return;
371 Handle(Message_Messenger) sout = Message::DefaultMessenger();
372 if (ValueOriginal() == ValueResult())
373 sout<<"-- ContextModif. Entity n0 "<<thecurr<<endl;
375 sout<<"-- ContextModif. Entity in Original, n0 "<<thecurr<<" in Result, n0 "
377 if (mess[0] != '\0') sout<<"-- Message:"<<mess<<endl;
381 //=======================================================================
382 //function : AddCheck
384 //=======================================================================
386 void IFSelect_ContextModif::AddCheck(const Handle(Interface_Check)& check)
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);
396 //=======================================================================
397 //function : AddWarning
399 //=======================================================================
401 void IFSelect_ContextModif::AddWarning(const Handle(Standard_Transient)& start,
402 const Standard_CString mess,
403 const Standard_CString orig)
405 thechek.CCheck(thegraf.EntityNumber(start))->AddWarning(mess,orig);
409 //=======================================================================
412 //=======================================================================
414 void IFSelect_ContextModif::AddFail(const Handle(Standard_Transient)& start,
415 const Standard_CString mess,
416 const Standard_CString orig)
418 thechek.CCheck(thegraf.EntityNumber(start))->AddFail(mess,orig);
422 //=======================================================================
425 //=======================================================================
427 Handle(Interface_Check) IFSelect_ContextModif::CCheck(const Standard_Integer num)
429 Handle(Interface_Check) ach = thechek.CCheck(num);
430 if (num > 0 && num <= thegraf.Size()) ach->SetEntity(thegraf.Entity(num));
435 //=======================================================================
438 //=======================================================================
440 Handle(Interface_Check) IFSelect_ContextModif::CCheck
441 (const Handle(Standard_Transient)& ent)
443 Standard_Integer num = thegraf.EntityNumber(ent);
444 if (num == 0) num = -1; // force l enregistrement
445 Handle(Interface_Check)& ach = thechek.CCheck(num);
451 //=======================================================================
452 //function : CheckList
454 //=======================================================================
456 Interface_CheckIterator IFSelect_ContextModif::CheckList () const