1 // Created on: 1997-09-03
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TNaming_Naming.ixx>
19 #include <TNaming_Builder.hxx>
20 #include <TNaming_Tool.hxx>
21 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
22 #include <TNaming_Iterator.hxx>
23 #include <TNaming_Scope.hxx>
24 #include <TNaming_NamingTool.hxx>
25 #include <TNaming_Name.hxx>
26 #include <TNaming_Identifier.hxx>
27 #include <TNaming_Localizer.hxx>
28 #include <TNaming_NewShapeIterator.hxx>
29 #include <TNaming_OldShapeIterator.hxx>
30 #include <TNaming_Selector.hxx>
31 #include <TNaming.hxx>
32 #include <TDF_ChildIterator.hxx>
33 #include <TDF_LabelList.hxx>
34 #include <TDF_Data.hxx>
35 #include <TDF_LabelMap.hxx>
36 #include <TDF_TagSource.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopTools_MapOfShape.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <TopTools_MapIteratorOfMapOfShape.hxx>
42 #include <Standard_DomainError.hxx>
43 #include <TopTools_ListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TColStd_MapOfInteger.hxx>
47 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
48 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
49 #include <TopTools_HArray1OfShape.hxx>
50 #include <BRepTools.hxx>
51 #include <BRep_Tool.hxx>
53 #include <TopoDS_Wire.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Shell.hxx>
56 #include <TopoDS_Solid.hxx>
57 // #include <TNaming_NCollections.hxx>
58 #include <NCollection_Map.hxx>
59 #include <NCollection_DataMap.hxx>
60 typedef NCollection_Map<TopoDS_Shape> TNaming_MapOfShape;
61 typedef TNaming_MapOfShape::Iterator TNaming_MapIteratorOfMapOfShape;
62 typedef NCollection_DataMap<TopoDS_Shape, TNaming_MapOfShape> TNaming_DataMapOfShapeMapOfShape;
63 typedef TNaming_DataMapOfShapeMapOfShape::Iterator TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape;
64 // The bug concerns access to a null object in the method Filter():
70 #define ALLOW_CHILD_NBS
73 //#define MDTV_DEB_MOD
75 //#define MDTV_DEB_INNS
76 //#define MDTV_DEB_NBS
78 //#define MDTV_DEB_WIN
80 #include <TDF_MapIteratorOfLabelMap.hxx>
81 #include <TCollection_AsciiString.hxx>
82 #include <TDF_Tool.hxx>
83 #include <BRepTools.hxx>
84 #include <TNaming_Tool.hxx>
85 #include <DbgTools.hxx>
88 #include <TDF_Tool.hxx>
89 #include <TDF_MapIteratorOfLabelMap.hxx>
91 #include <TCollection_AsciiString.hxx>
92 #include <BRepTools.hxx>
93 void Print_Entry(const TDF_Label& label)
95 TCollection_AsciiString entry;
96 TDF_Tool::Entry(label, entry);
97 cout << "LabelEntry = "<< entry << endl;
99 static void Write(const TopoDS_Shape& shape,
100 const Standard_CString filename)
103 if(strlen(filename) > 256) return;
104 strcpy (buf, filename);
113 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
114 save << "DBRep_DrawableShape" << endl << endl;
115 if(!shape.IsNull()) BRepTools::Write(shape, save);
118 void WriteNSOnLabel(const Handle(TNaming_NamedShape) & NS, const TCollection_AsciiString& Nam)
121 TCollection_AsciiString entry;
122 TDF_Tool::Entry(NS->Label(), entry);
123 TopoDS_Shape Sh = TNaming_Tool::GetShape (NS);
125 TCollection_AsciiString Entry = Nam + entry + ".brep";
126 Write(Sh, Entry.ToCString());
129 cout << "WriteNSOnLabel>>> TopoDS_Shape IS NULL on Entry = "<< entry << endl;
132 cout << "WriteNSOnLabel >>> NamedShape IS NULL" << endl;
136 //==========================================================================================
137 static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
139 const TopoDS_Shape& S,
140 const TopoDS_Shape& Context,
141 const Handle(TNaming_NamedShape)& Stop,
142 const Standard_Boolean Geometry);
144 //=======================================================================
145 static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
146 const TopoDS_Shape& Context);
147 //=======================================================================
148 extern Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2);
150 //=======================================================================
152 //purpose : voir avec YFR comment retrouver le bon resulat et le mettre
153 // : dans le NamedShape de L
154 //=======================================================================
155 Standard_Boolean TNaming_Naming::Solve (TDF_LabelMap& Valid)
157 Handle(TNaming_Naming) subname;
158 for (TDF_ChildIterator it (Label(),Standard_False); it.More(); it.Next()) {
160 TCollection_AsciiString anEntry;
161 TDF_Tool::Entry(it.Value(), anEntry);
162 cout << "TNaming_Naming::Solve: Label to be solved = " << anEntry << endl;
164 if (it.Value().FindAttribute(TNaming_Naming::GetID(),subname)) {
165 if (!subname->Solve (Valid)) {
166 return Standard_False; // not necessary to continue
171 TDF_MapIteratorOfLabelMap anItr(Valid);
172 cout << "TNaming_Naming::Solve:: Valid label Map" << endl;
173 for (; anItr.More(); anItr.Next()) {
174 const TDF_Label& aLabel = anItr.Key();
175 TCollection_AsciiString anEntry;
176 TDF_Tool::Entry(aLabel, anEntry);
177 cout << "Label = " << anEntry << endl;
180 if (Regenerate(Valid)) {
181 if (!Valid.IsEmpty()) Valid.Add(Label());
182 return Standard_True;
184 return Standard_False;
188 //=======================================================================
191 //=======================================================================
193 const Standard_GUID& TNaming_Naming::GetID ()
195 static Standard_GUID TNaming_NamingID("c0a19201-5b78-11d1-8940-080009dc3333");
196 return TNaming_NamingID;
199 //=======================================================================
202 //=======================================================================
204 Handle(TNaming_Naming) TNaming_Naming::Insert (const TDF_Label& under)
206 Handle(TNaming_Naming) N;
207 TDF_Label child = TDF_TagSource::NewChild(under);
208 N = new TNaming_Naming ();
209 child.AddAttribute (N);
213 //=======================================================================
215 //purpose : returns a new NamedShape, which is built as selection:
216 // : TNaming_Builder::Select("S","S") at the new child label of the label <F>.
217 //=======================================================================
219 static Handle(TNaming_NamedShape) BuildNS (const TDF_Label& F,
220 const TopoDS_Shape& S,
221 const TNaming_NameType& Name)
223 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert (F);
225 TNaming_Name& theName = Naming->ChangeName();
226 theName.ShapeType(S.ShapeType());
228 theName.Orientation(S.Orientation());
230 TNaming_Builder B(Naming->Label());
232 return B.NamedShape();
235 //=======================================================================
236 //function : FindIndex
238 //=======================================================================
240 static Standard_Integer FindIndex(const Handle(TNaming_NamedShape)& NS,
241 const TopoDS_Shape& S)
243 TDF_LabelList Labels;
244 TopoDS_Shape IS = TNaming_Tool::InitialShape(S,NS->Label(),Labels);
245 Standard_Integer Index = 1;
246 for (TNaming_Iterator itNS(NS); itNS.More(); itNS.Next(),Index++) {
247 if (IS.IsSame(itNS.NewShape())) break;
253 //=======================================================================
254 //function : CompareInGeneration
255 //purpose : returns true, only if the specified NS contains only <S> in
256 // : the "new shapes" set.
257 //=======================================================================
259 static Standard_Boolean CompareInGeneration (const Handle(TNaming_NamedShape)& NS,
260 const TopoDS_Shape& S)
262 for (TNaming_Iterator it(NS); it.More(); it.Next()) {
263 if (!it.NewShape().IsSame(S)) return 0;
270 //=======================================================================
271 //function : GetShapeEvolutions
272 //purpose : returns Standard_True, if target has parent in source; list contains inheritance chain
273 //=======================================================================
274 static Standard_Boolean GetShapeEvolutions(const TopoDS_Shape& theTarget, // this is changed in recursion
275 const Handle(TNaming_NamedShape)& theSource,
276 TopTools_ListOfShape& aList) // returns list in the backward order
278 Handle(TNaming_NamedShape) aTarget = TNaming_Tool::NamedShape(theTarget,theSource->Label());
279 if (!aTarget.IsNull()) {
281 cout <<"GetShapeEvolutions: target NS = ";
282 Print_Entry(aTarget->Label());
283 cout <<"GetShapeEvolutions: Source NS = ";
284 Print_Entry(theSource->Label());
285 TCollection_AsciiString aNam("GetShapeEvolutions");
286 WriteNSOnLabel(aTarget,aNam);
288 if (aTarget->Label() == theSource->Label()) return Standard_True; // check if target is in the source
289 } else return Standard_False;
291 TNaming_Iterator anIter(aTarget);
292 for(;anIter.More();anIter.Next()) { // check all appropriate old shapes of target
294 if(!anIter.OldShape().IsNull()) {
295 Write(anIter.OldShape(), "Target_OldS.brep");
296 cout <<"Target OldS TS =" <<anIter.OldShape().TShape()->This() <<endl;
298 if(!anIter.NewShape().IsNull()) {
299 Write(anIter.NewShape(), "Target_NewS.brep");
300 cout <<"Target NewS TS =" <<anIter.NewShape().TShape()->This() <<endl;
303 if (anIter.OldShape().IsNull() || anIter.NewShape().IsNull()) continue;
304 if (!anIter.NewShape().IsSame(theTarget)) continue;
305 if (GetShapeEvolutions(anIter.OldShape(),theSource,aList)) { // recursion: now target is old shape
306 aList.Append(theTarget); // if oldshape has the source as parent (or belongs to it) , fill the list
307 return Standard_True;
310 return Standard_False;
313 //=======================================================================
314 //function : CompareInModification
315 //purpose : returns empty named shape if naming is already done
316 //=======================================================================
318 static Handle(TNaming_NamedShape) CompareInModification (const Handle(TNaming_NamedShape)& NS, // parent
319 const TopoDS_Shape& S) // target
321 Handle(TNaming_NamedShape) aResult;
322 if (S.IsNull() || NS.IsNull()) return aResult;
324 cout <<"CompareInModification: parent NS = ";
325 Print_Entry(NS->Label());
326 Write(S, "CompareInM_S.brep");
327 TCollection_AsciiString aNam("CompareInM");
328 WriteNSOnLabel(NS,aNam);
330 Handle(TNaming_NamedShape) aSource; // parent NamedShape, which can be found by TopoDS shape
331 TNaming_Iterator anIt(NS);
332 for(;anIt.More() && aSource.IsNull();anIt.Next()) {
333 if (!anIt.NewShape().IsNull()) {
334 aSource = TNaming_Tool::NamedShape(anIt.NewShape(),NS->Label());
336 TCollection_AsciiString aNam("CompareInM_Source");
337 WriteNSOnLabel(aSource,aNam);
341 // searching for 1:n to the same label modifications (in this case current naming is insufficient)
342 TopTools_ListOfShape aList;
343 if (GetShapeEvolutions(S,aSource,aList) && aList.Extent() > 0) {
344 TopTools_ListIteratorOfListOfShape anIter(aList);
345 for(;anIter.More();anIter.Next()) {
346 aResult = TNaming_Tool::NamedShape(anIter.Value(),NS->Label());
347 if (aResult->Evolution()!=TNaming_MODIFY) { // evolution must be modify, otherwise everything is OK
351 TopTools_MapOfShape aMap; // collection of the old shapes of the shape from list
352 TNaming_Iterator aNIter1(aResult);
354 for(;aNIter1.More();aNIter1.Next()) {
355 if (aNIter1.NewShape().IsSame(anIter.Value())) {// if isSame
356 aMap.Add(aNIter1.OldShape());
359 TNaming_Iterator aNIter2(aResult); // if some another shapes has oldshape from map, return namedshape with this oldshape
361 for(;aNIter2.More();aNIter2.Next()) {
362 if (aNIter2.NewShape().IsSame(anIter.Value())) continue;
363 if (aMap.Contains(aNIter2.OldShape())) { // if one shape was modified to the two at the shared label, return this one
364 aResult = TNaming_Tool::NamedShape(aNIter2.OldShape(),NS->Label());
365 if (!aResult.IsNull()) return aResult;
375 //=======================================================================
376 static Standard_Boolean FillSMap(const TopoDS_Shape& S, TopTools_MapOfShape& MS)
378 if(S.IsNull()) return Standard_False;
379 Standard_Boolean isHomogen(Standard_True);
380 TopAbs_ShapeEnum aPrevType(TopAbs_SHAPE);
381 TopoDS_Iterator it(S);
382 for (; it.More(); it.Next()) {
383 const TopAbs_ShapeEnum aType = it.Value().ShapeType();
385 cout <<"TestSolution_FillMap: S_Type = :" << it.Value().ShapeType() <<" TShape = " << it.Value().TShape()->This() <<endl;
387 if(aType > TopAbs_COMPSOLID) {
389 if(aPrevType == TopAbs_SHAPE)
391 else if(aPrevType != aType)
392 isHomogen = Standard_False;
395 if(!FillSMap(it.Value(), MS))
396 isHomogen = Standard_False;
400 //=======================================================================
402 //purpose : checks naming of the shape <S> in the NamedShape <NS>.
403 // : Returns true, if it's correct. Details ==>
404 // : The method takes all modifications of the "NS" (see CurrentShape method),
405 // : which are in the "MDF" (if it's not empty) before <Stop> shape and check them.
406 // : whether these modifications contain only "S". If yes then the method
407 // : returns true, otherwise it returns false.
408 //=======================================================================
410 static Standard_Boolean Compare (const Handle(TNaming_NamedShape)& NS,
411 const TNaming_Scope& MDF,
412 const Handle(TNaming_NamedShape)& Stop,
413 const TopoDS_Shape& S)
415 TDF_LabelMap Forbiden;
416 TopTools_MapOfShape MS;
417 if (!Stop.IsNull()) TNaming_NamingTool::BuildDescendants(Stop,Forbiden);
418 TNaming_NamingTool::CurrentShape(MDF.GetValid(),Forbiden,NS,MS);
420 Write(S, "Compare_S.brep");
421 cout << "S: TShape = " <<S.TShape()->This() <<endl;
422 Standard_Integer i =1;
423 TopTools_MapIteratorOfMapOfShape it(MS);
424 TCollection_AsciiString aNam("Compare_MS_");
425 TCollection_AsciiString ext(".brep");
426 for(;it.More();it.Next(), i++) {
427 TCollection_AsciiString aName = aNam + i + ext;
428 Write(it.Key(), aName.ToCString()) ;
429 cout << aName.ToCString()<< ": TShape = " <<it.Key().TShape()->This() <<endl;
432 return (MS.Contains(S) && MS.Extent() == 1);
434 //=======================================================================
435 //function : TestSolution
436 //purpose : returns true, if last modification of shape from "NS" is equal to "S":
437 // : If shape "S" has atomic type (TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX),
438 // : then returns S.IsSame(shape from "NS").
439 // : Otherwise the result of exploration of these shapes must be same.
440 //=======================================================================
442 static Standard_Boolean TestSolution(const TNaming_Scope& MDF,
443 const Handle(TNaming_NamedShape)& NS,
444 const TopoDS_Shape& S)
447 if (NS.IsNull()) return Standard_False;
448 TopoDS_Shape Res = MDF.CurrentShape(NS);// last modification of NS taken into account Valid map
449 if(S.IsNull() || Res.IsNull()) return Standard_False;
451 Write(S, "TSol_S.brep");
452 Write(Res, "TSol_Res.brep");
456 if ((S.ShapeType() == TopAbs_FACE ||
457 S.ShapeType() == TopAbs_EDGE ||
458 S.ShapeType() == TopAbs_VERTEX ) &&
459 Res.ShapeType() != TopAbs_COMPOUND) {
460 return (Res.IsSame(S));
461 } else if (S.ShapeType() == TopAbs_SOLID ||
462 S.ShapeType() == TopAbs_COMPSOLID) {
463 TopTools_MapOfShape aMS;
465 for (exp.Init(S,TopAbs_FACE) ; exp.More(); exp.Next()) {
466 aMS.Add(exp.Current());
468 for (exp.Init(Res,TopAbs_FACE) ; exp.More(); exp.Next()) { //content of MS and Res should be the same
469 if (aMS.Contains(exp.Current())) {
470 aMS.Remove(exp.Current());
474 return aMS.IsEmpty();
479 if (S.ShapeType() == TopAbs_SOLID ||
480 S.ShapeType() == TopAbs_FACE ||
481 S.ShapeType() == TopAbs_EDGE ||
482 S.ShapeType() == TopAbs_VERTEX ) {
483 return (Res.IsSame(S));
489 TopTools_MapOfShape MS;
490 Standard_Boolean isHom = FillSMap(S, MS);
491 TopAbs_ShapeEnum aType(TopAbs_SHAPE);
492 TColStd_MapOfInteger aView;
493 TopTools_MapIteratorOfMapOfShape itm(MS);
494 for(;itm.More();itm.Next()) {
495 aType = itm.Key().ShapeType();
499 aView.Add(itm.Key().ShapeType());
502 if (MS.Contains(Res)) {
504 if (MS.IsEmpty()) return 1;
506 if (Res.ShapeType() == TopAbs_SOLID ||
507 Res.ShapeType() == TopAbs_COMPSOLID ||
508 Res.ShapeType() == TopAbs_COMPOUND)
512 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
513 if (MS.Contains(exp.Current())) {
514 MS.Remove(exp.Current());
517 TColStd_MapIteratorOfMapOfInteger itm(aView);
518 for(;itm.More();itm.Next()) {
519 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)itm.Key();
520 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
521 if (MS.Contains(exp.Current())) {
522 MS.Remove(exp.Current());
529 return Standard_True;
530 TopoDS_Iterator it(Res);
531 for (; it.More(); it.Next()) { //content of MS and Res should be the same
532 if (MS.Contains(it.Value())) {
533 MS.Remove(it.Value());
542 //=======================================================================
543 //function : FindNewShapeInFather
545 //=======================================================================
547 static void FindNewShapeInFather (const Handle(TNaming_NamedShape)& NS,
550 const TDF_Label& Father = NS->Label().Father();
551 TNaming_Iterator itLab(Father);
553 SC = itLab.NewShape();
556 //=======================================================================
557 //function : NextModif
559 //=======================================================================
561 static Handle(TNaming_NamedShape) NextModif(const Handle(TNaming_NamedShape)& NS)
563 Handle (TNaming_NamedShape) Next;
565 TNaming_NewShapeIterator it(NS);
566 if (it.More()&& it.IsModification()) Next = it.NamedShape();
570 //=======================================================================
571 // C1 - cand shape of the father, C2 - shape of rebuild child Naming attr.
572 // (to be Compound of elementary shapes)
573 //=======================================================================
574 static Standard_Boolean IsContSame(const TopoDS_Shape& C1, const TopoDS_Shape& C2)
576 Standard_Boolean aRes(Standard_False);
577 if(!C1.IsNull() && !C2.IsNull()) {
578 TopTools_MapOfShape aMap;
579 if(FillSMap(C1, aMap)) {
580 aRes = Standard_True;
581 TopoDS_Iterator it(C2);
582 for(;it.More();it.Next()) {
583 if(!aMap.Contains(it.Value())) {
584 aRes = Standard_False;
593 //=======================================================================
594 // Identifies the case when Filter haven't sense because of multiplicity
595 //=======================================================================
596 static Standard_Boolean IsMultipleCase(const TopoDS_Shape& S,
597 const TopoDS_Shape& Context,
598 const TopTools_MapOfShape& Neighbourgs) {
600 TopTools_IndexedDataMapOfShapeListOfShape aDM;
601 TNaming_MapOfShape aM;
602 TopTools_MapOfShape aNbs;
603 aNbs.Assign(Neighbourgs);
605 TNaming_DataMapOfShapeMapOfShape aDMM;
606 TopExp::MapShapesAndAncestors (Context, TopAbs_EDGE, TopAbs_FACE, aDM);
607 TopTools_MapIteratorOfMapOfShape it(aNbs);
608 for(;it.More();it.Next()) {
609 if(aDM.Contains(it.Key())) {
610 TNaming_MapOfShape aMS;
611 const TopTools_ListOfShape& aL = aDM.FindFromKey(it.Key());
612 TopTools_ListIteratorOfListOfShape lit(aL);
613 for(;lit.More();lit.Next()) {
615 aMS.Add(lit.Value());
618 aDMM.Bind(it.Key(), aMS);
621 cout << "Key is not BOUND!" <<endl;
623 return Standard_False;
627 Standard_Boolean isCommon(Standard_True);
628 TNaming_MapIteratorOfMapOfShape itm(aM);
629 for(;itm.More();itm.Next()) {
630 isCommon = Standard_True; // statement: this shape (itm.Key()) is common (to be checked below)
631 TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape itdm(aDMM);
632 for (;itdm.More();itdm.Next()) {
633 const TNaming_MapOfShape& aMap = itdm.Value();
634 if(!aMap.Contains(itm.Key())) {
635 isCommon = Standard_False;
639 if(isCommon) break; // common single face found
641 if(isCommon && aM.Extent() < aNbs.Extent()) {// number of unique faces (to have single solution)
642 //should be at least no less than (Nb of Neighbourgs) +1
643 return Standard_True;
645 return Standard_False;
647 //=======================================================================
649 //purpose : sets the name with type "FILTERBYNEIGHBOURGS" and returns true,
650 // : if it was correctly done.
653 //=======================================================================
655 static Standard_Boolean Filter (const TDF_Label& F,
657 const TopoDS_Shape& S,
658 const TopoDS_Shape& Context,
659 TNaming_Localizer& Localizer,
660 Handle(TNaming_NamedShape)& NS,
661 const Standard_Integer Lev)
663 // 1. Localizer.FindNeighbourg("Context", "S", "Neighbourg") - looks for neighbourgs of "S" with the same shape type in the "Context"
664 // shape and adds them to the "Neighbourg" map;
665 // 2. If "Neighbourg" map is empty, tries to do the same with the new context shape: shape from the father label of the "S" named shape;
666 // 3. If "Neighbourg" map is still empty, returns false;
667 // 4. Adds to the new child of label "L" new TNaming_Naming attribute with the next properties name: shape type is shape type of the "S",
668 // type is TNaming_FILTERBYNEIGHBOURGS, stop shape ( "Until" ) is "Context" of corresponding NamedShape;
669 // first argument of name is "NS" NamedShape.
670 // 5. Adds to the Name all shapes from "Neighbourg" map: build it with the BuildName( new generated TNaming_Naming attribute, MDF,
671 // argument shape from "Neighbourg", "Context", NextModif( "Until" ), true ) method.
672 // 6. Creates resulting NamedShape with the "Regenerate" ( it just calls TName::Solve method ) method from TNaming_Naming class.
673 // 7. If Compare( result NamedShape, MDF, stop, "S" ) returns true, "Filter" method returns true, else returns false.
675 //------------------------------
676 // Construction des voisins ==> of neighbors.
677 //------------------------------
678 Standard_Integer aLev(Lev);
679 TopTools_MapOfShape Neighbourg;
680 Localizer.FindNeighbourg (Context,S,Neighbourg);
682 //DbgTools::DisplayShape(Context, F, Quantity_NOC_GREEN);
683 //DbgTools::DisplayShape(S, F, Quantity_NOC_BLUE1);
684 Write(Context, "FNBS_Context.brep");
685 Write(S, "FNBS_S.brep");
686 Write(Neighbourg, "NBS");
689 // mpv : NS and shape must be the same
690 Standard_Boolean isIn = Standard_False;
691 TNaming_Iterator anIter(NS);
692 for(;anIter.More();anIter.Next()) {
694 //DbgTools::DisplayShape(anIter.NewShape(), F, Quantity_NOC_RED);
696 if (anIter.NewShape().IsSame(S)) {
697 isIn = Standard_True;
701 if (!isIn) if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
702 // if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
705 if (Neighbourg.IsEmpty()) {
706 // Recherche du vrai context. (Research of context truth)
707 Handle(TNaming_NamedShape) GenS = TNaming_Tool::NamedShape(S,NS->Label());
709 if (GenS.IsNull()) return Standard_False;
711 TDF_Label Father = (GenS->Label()).Father();
712 Father.FindAttribute(TNaming_NamedShape::GetID(),GenS);
713 TopoDS_Shape GoodContext = TNaming_Tool::GetShape(GenS);
714 Localizer.FindNeighbourg (GoodContext,S,Neighbourg);
718 if (Neighbourg.IsEmpty()) {
720 cout <<"FindNeighbourg: impossible"<<endl;
725 Write(Neighbourg, "Neighbourgs");
728 //cout <<"Filter: Lev = " << aLev << endl;
730 if(aLev > 3) return 0;
731 #ifdef ALLOW_CHILD_NBS
732 Handle(TNaming_Naming) aFNaming;
733 TopoDS_Shape aFatherCandSh;
734 F.FindAttribute(TNaming_Naming::GetID(), aFNaming);
735 if(!aFNaming.IsNull()) {
736 const TNaming_Name& aName = aFNaming->GetName();
737 if (aName.Type() == TNaming_FILTERBYNEIGHBOURGS) {
738 aFatherCandSh = aName.Arguments().First()->Get();
741 if(S.ShapeType() == TopAbs_EDGE && aFatherCandSh.IsNull()) {
742 //check the applicability
743 if(!NS.IsNull() && !NS->Get().IsNull() && NS->Get().ShapeType() == TopAbs_COMPOUND)
744 if(IsMultipleCase(S, Context, Neighbourg)) {
745 //cout << "Filter: ==> MultipleCase!" << endl;
746 NS->Label().FindAttribute(TNaming_Naming::GetID(), aFNaming);
747 if(!aFNaming.IsNull()) {
748 TNaming_Name& aName = aFNaming->ChangeName();
749 if (aName.Type() == TNaming_INTERSECTION) {
750 Standard_Integer ij(1);
751 TNaming_ListIteratorOfListOfNamedShape itA(aName.Arguments());
752 for (; itA.More(); itA.Next(), ij++) {
753 const TopoDS_Shape& aFace = TNaming_Tool::CurrentShape(itA.Value());
755 Write(aFace, "First_Face.brep");
756 cout <<"Selection TS = " << S.TShape()->This() <<endl;
758 Standard_Integer i(1), indxW(0),indxE(0),nbW(0),nbE(0), indxF(0);
759 Standard_Boolean isFound(Standard_False);
760 TopoDS_Iterator it(aFace);
761 for (;it.More();it.Next(),i++) {
764 Write(it.Value(), "First_Wire.brep");
767 Standard_Integer j(1);
768 TopoDS_Iterator it2(it.Value());
769 for (;it2.More();it2.Next(),j++) {
772 Write(it2.Value(), "First_Wire.brep");
773 cout <<"Edge TS = " << it2.Value().TShape()->This() <<endl;
775 if(S.IsEqual(it2.Value())) {
779 isFound = Standard_True;
785 Standard_Integer Index = indxE & 0x000000FF;
786 Index = Index | (nbE << 8);
787 Index = Index | (indxW << 16);
788 Index = Index | (nbW << 20);
789 Index = Index | (indxF << 24);
791 //------------------------------
792 // Compute the TNaming_NamedShape
793 //------------------------------
794 aFNaming->Regenerate(MDF.ChangeValid());
795 aFNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
796 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
797 Handle (TNaming_NamedShape) Stop = NextModif(Until);
798 if (Compare (NS,MDF,Stop,S)) return 1;
809 //-----------------------------------------------------
810 // Construction function de naming. et insertion sous F
811 //-----------------------------------------------------
812 Handle (TNaming_Naming) NF = TNaming_Naming::Insert (F);
814 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
815 Handle (TNaming_NamedShape) Stop = NextModif(Until);
816 TNaming_Name& theName = NF->ChangeName();
817 theName.ShapeType(S.ShapeType());
819 theName.Orientation(S.Orientation());
820 theName.Type(TNaming_FILTERBYNEIGHBOURGS);
822 theName.StopNamedShape (Until);
824 cout << "FilterByNBS: ";
825 Print_Entry(NF->Label());
826 cout <<"AppendNS = " ;
827 Print_Entry(NS->Label());
829 //---------------------
830 // Naming des voisins.
831 //---------------------
833 TopTools_MapIteratorOfMapOfShape itN(Neighbourg);
834 for (; itN.More(); itN.Next()) {
835 #ifdef ALLOW_CHILD_NBS
836 const TopoDS_Shape& aS = itN.Key();
837 Handle (TNaming_NamedShape) aNS =
838 BuildName(NF->Label(), MDF, aS, Context, Stop, 1);
840 const TopoDS_Shape& aS2 = aNS->Get();
842 cout << "Shape arg type = " << aS.ShapeType() <<" TSH = " << aS.TShape()->This()<<endl;
844 cout << "Build shape type = " << aS2.ShapeType() <<" TSH = " << aS2.TShape()->This()<<endl;
845 Write (aS2, "NBS_BuildShape.brep");
848 cout <<"AppendNS = " ;
849 Print_Entry(aNS->Label());
853 const TopoDS_Shape aSNS = aNS->Get(); //allow child level
854 Standard_Boolean allowChild(Standard_True);
855 if(!aSNS.IsNull() && aSNS.ShapeType() == TopAbs_COMPOUND && !aFatherCandSh.IsNull())
856 allowChild = !IsContSame(aFatherCandSh, aSNS);
857 if(allowChild && !aSNS.IsNull() && aS.ShapeType() != aSNS.ShapeType() &&
858 aSNS.ShapeType() == TopAbs_COMPOUND)
861 cout <<"Father label = ";
862 Print_Entry(aNS->Label().Father());
863 Write(aS,"SelectionS.brep");
864 Write(aSNS,"SelectionSNS.brep");
866 Handle(TNaming_Naming) aNaming;
867 Standard_Boolean StandardFilter(Standard_True);
868 aNS->FindAttribute(TNaming_Naming::GetID(), aNaming);
869 if(!aNaming.IsNull()) {
870 const TNaming_Name& aName = aNaming->GetName();
871 if (aName.Type() == TNaming_GENERATION)
872 StandardFilter = Standard_False;
874 if (!Compare (aNS,MDF,Stop,aS)) {
875 TNaming_Localizer aLocalizer;
876 Filter (NF->Label(), MDF,aS,Context, aLocalizer,aNS, aLev);
882 theName.Append(BuildName(NF->Label(), MDF, itN.Key(), Context, Stop, 1));
885 //------------------------------
886 // Compute the TNaming_NamedShape
887 //------------------------------
888 NF->Regenerate(MDF.ChangeValid());
889 NF->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
894 if (Compare (NS,MDF,Stop,S)) return 1;
896 cout <<"TNaming_Naming::Name Filter insufficient"<<endl;
902 //=======================================================================
903 //function : BuildNameInNS
904 //purpose : Calls BuildName method, but with new context and new stop shape.
905 // : Context is searched at the father label of the "Context" label :
906 // : old shapes from the NamedShape at the defined father label.
907 // : If it's impossible, then "S" set as context.
908 // : If "S" is in new context, then stop shape is named shape,
909 // : which belongs to the father label of the "Context" named shape.
910 // : For example, face (F2) of prism (P) is generated from the edge (E)
911 // : of primitive face (F1) of box (B). F2 is named as GENERATION from E.
912 // : Naming of E is done with help BuildNameInNS function:
913 // : with context B and stop shape P.
914 //=======================================================================
915 static Handle(TNaming_NamedShape) BuildNameInNS (const TDF_Label& F,
917 const TopoDS_Shape& S,
918 const Handle(TNaming_NamedShape)& Context,
919 const Handle(TNaming_NamedShape)& Stop,
920 const Standard_Boolean Geometry)
923 // il faut determiner un nouveau context et un nouveau Stop.
924 // it is necessary to determine a new context and a new Stop
926 Handle(TNaming_NamedShape) NewStop = Stop;
928 TNaming_Localizer::FindShapeContext (Context,S,SC);
931 // <Context> is Ident.NamedShapeOfGeneration() ==
932 TDF_Label Father = Context->Label().Father();
933 Father.FindAttribute(TNaming_NamedShape::GetID(),NewStop);
936 {cout <<" Stop NS : "; Print_Entry( Stop->Label());}
937 if(!NewStop.IsNull())
938 {cout <<" NewStop : "; Print_Entry( NewStop->Label());}
939 cout <<"ContextLabel: "; Print_Entry( Context->Label());
940 cout <<"Father : "; Print_Entry( Father);
945 cout <<"BuildNameInNS:: NewStop shape is NULL" << endl;
947 return BuildName (F,MDF,S,SC,NewStop,Geometry);
950 //=======================================================================
953 //=======================================================================
955 static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
957 const TopoDS_Shape& Selection,
958 const TopoDS_Shape& Context,
959 const Handle(TNaming_NamedShape)& Stop,
960 const Standard_Boolean Geom)
965 // Create an identifier
966 Standard_Boolean OnlyOne = !Geom;
967 Standard_Boolean IsGeneration = Standard_False;
969 cout <<"BuildName: F => ";
971 cout <<" Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
972 Write(Selection, "BName_Selection.brep");
973 Write(Context, "BName_Context.brep");
975 TNaming_Identifier Ident(F, Selection, Context,OnlyOne);
977 Handle (TNaming_Naming) Naming;
978 Handle (TNaming_NamedShape) NS;
980 if (!Ident.IsDone()) {
981 return BuildNS (F,Selection, TNaming_UNKNOWN);
983 if (Ident.IsFeature() && Stop.IsNull()) {
987 if (!OnlyOne) return Ident.FeatureArg();
988 else NS = Ident.FeatureArg();
991 //---------------------------------------------
992 // Construction de la fonction d identification.
993 //---------------------------------------------
994 //Standard_Boolean NotOnlyOne = 0;
996 Naming = TNaming_Naming::Insert(F);
998 TNaming_Name& theName = Naming->ChangeName();
999 theName.ShapeType(Selection.ShapeType());
1000 theName.Shape(Selection);
1001 theName.Orientation(Selection.Orientation());
1002 theName.Type(Ident.Type());
1004 cout <<"BuildName: Inserted Naming Att at ";
1005 Print_Entry(Naming->Label());
1006 cout <<" NameType = " << theName.Type() <<endl;
1008 if (Ident.IsFeature()) {
1009 theName.Append(Ident.FeatureArg());
1011 if (theName.Type() == TNaming_GENERATION) {
1012 theName.Append(Ident.NamedShapeOfGeneration());
1013 IsGeneration = Standard_True;
1015 if (theName.Type() == TNaming_CONSTSHAPE) {
1016 theName.Index(FindIndex(Ident.FeatureArg(),Selection));
1018 //------------------------------------
1019 // Renseignement du NamedShape d arret.
1020 //------------------------------------
1021 theName.StopNamedShape (Stop);
1023 if(!Stop.IsNull()) {
1024 TCollection_AsciiString Es;
1025 TDF_Tool::Entry(Stop->Label(), Es);
1026 cout <<"StopNS at Label = "<< Es << endl;
1029 //---------------------------------
1030 // Identification des arguments.
1031 //---------------------------------
1033 for (Ident.InitArgs(); Ident.MoreArgs(); Ident.NextArg()) {
1034 if (Ident.ArgIsFeature()) {
1035 theName.Append(Ident.FeatureArg());
1037 if(!Ident.FeatureArg().IsNull()) {
1038 TCollection_AsciiString E;
1039 TDF_Tool::Entry(Ident.FeatureArg()->Label(), E);
1040 cout <<"Added argument NS from Label = "<< E << endl;
1046 cout <<"BuildName: NameType = " <<theName.Type() << " NS ";
1047 Print_Entry(Naming->Label());
1048 cout <<"Ident.ShapeArg() type = " << Ident.ShapeArg().ShapeType() << " TS = " << Ident.ShapeArg().TShape()->This() << endl;
1049 Write(Ident.ShapeArg(), "BName_ShapeArg.brep");
1051 if (theName.Type() == TNaming_GENERATION)
1052 theName.Append(BuildNameInNS(Naming->Label(),MDF,Ident.ShapeArg(),Ident.NamedShapeOfGeneration(),Stop,Geom));
1054 theName.Append(BuildName(Naming->Label(),MDF,Ident.ShapeArg(),Context,Stop,Geom));
1058 //------------------------
1059 // Reconstruction of Name
1060 //------------------------
1061 Naming->Regenerate(MDF.ChangeValid());
1063 TCollection_AsciiString E2;
1064 TDF_Tool::Entry(Naming->Label(), E2);
1065 cout <<"Regenerated Naming Att at Label = "<< E2 << endl;
1067 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1068 if(NS.IsNull()) return NS;
1069 if (MDF.WithValid()) MDF.Valid(NS->Label());
1072 TCollection_AsciiString E;
1073 TDF_Tool::Entry(NS->Label(), E);
1074 cout <<"Regenerated NS at Label = "<< E << endl;
1080 //-------------------------------------------------
1081 // Filtre par les voisins
1082 // pour construire le nom correspondant a S.
1083 //-------------------------------------------------
1086 if(NS.IsNull()) return NS;
1089 TNaming_Localizer Localizer;
1090 TNaming_Iterator itNS(NS);
1098 Standard_Boolean StandardFilter = !IsGeneration;
1100 if (!CompareInGeneration (NS,Selection)) {
1102 TopoDS_Shape NewContext;
1103 Handle(TNaming_NamedShape) NewStop;
1104 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1105 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1107 } else if (Ident.Type() == TNaming_MODIFUNTIL ||
1108 (Ident.Type() == TNaming_INTERSECTION && Naming->ChangeName().Arguments().Extent() == 1)) {
1110 cout <<"BuildName(CompareInModification): NameType = " <<Ident.Type() << " NS ";
1111 Print_Entry(Ident.Type() == TNaming_MODIFUNTIL ? NS->Label() : Naming->ChangeName().Arguments().First()->Label());
1112 cout <<"Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
1114 Handle(TNaming_NamedShape) NewNS =
1115 CompareInModification(Ident.Type() == TNaming_MODIFUNTIL ? NS : Naming->ChangeName().Arguments().First(), Selection);
1116 if (!NewNS.IsNull()) { // there is need to describe name in detail: modification with type 1:n in the same label
1117 StandardFilter = Standard_False;
1118 if (Ident.IsFeature()) { // for MODIFUNTIL: change it to the GENERATION
1119 Naming = TNaming_Naming::Insert(F);
1120 TNaming_Name& theName = Naming->ChangeName();
1121 theName.ShapeType(Selection.ShapeType());
1122 theName.Shape(Selection);
1123 theName.Orientation(Selection.Orientation());
1124 theName.Type(TNaming_GENERATION);
1125 theName.Append(TNaming_Tool::NamedShape(Selection,F));
1126 theName.Append(NewNS);
1127 Naming->Regenerate(MDF.ChangeValid());
1128 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1131 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1134 if (StandardFilter) if (!Compare (NS,MDF,Stop,Selection)) {
1135 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1141 if (!CompareInGeneration (NS,Selection)) {
1142 TopoDS_Shape NewContext;
1143 Handle(TNaming_NamedShape) NewStop;
1144 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1145 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1149 if (!Compare (NS,MDF,Stop,Selection))
1150 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1157 if (MDF.WithValid()) MDF.Valid(NS->Label());
1160 TCollection_AsciiString E;
1161 TDF_Tool::Entry(NS->Label(), E);
1162 cout <<"Returned NS from Label = "<< E << endl;
1168 //=======================================================================
1169 //function : Validate
1171 //=======================================================================
1173 static void Validate(TNaming_Scope& MDF,
1174 TNaming_OldShapeIterator& it)
1176 MDF.Valid(it.Label());
1177 MDF.ValidChildren(it.Label());
1179 TNaming_OldShapeIterator it2(it);
1180 for (; it2.More(); it2.Next()) {
1185 //=======================================================================
1186 //function : UnValidate
1188 //=======================================================================
1190 static void UnValidate(TNaming_Scope& MDF,
1191 TNaming_NewShapeIterator& it)
1193 MDF.Unvalid(it.Label());
1194 MDF.UnvalidChildren(it.Label());
1196 TNaming_NewShapeIterator it2(it);
1197 for (; it2.More(); it2.Next()) {
1198 UnValidate (MDF,it2);
1202 //=======================================================================
1203 //function : BuildScope
1204 //purpose : adds to the MDF the label of <Context> NamedShape,
1205 // : its children, all its oldShapes and its children.
1206 // : unvalidates all newShapes and it's children.
1207 // : If <Context> is null or next modification has an empty newShape
1208 // : ( this shape was deleted ), then MDF.WithValid(Standard_False)
1209 // : and nothing is added to the scope.
1210 //=======================================================================
1212 static void BuildScope (TNaming_Scope& MDF,
1213 const TopoDS_Shape& Context,
1214 const TDF_Label& Acces)
1216 if (Context.IsNull()) {
1217 MDF.WithValid(Standard_False);
1221 //----------------------------------------------------
1222 // Is context the current state
1223 //----------------------------------------------------
1224 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(Context,Acces);
1225 Handle(TNaming_NamedShape) Next = NextModif(NS); // if NS has subsequent evolution = MODIFY, return it
1226 if (Next.IsNull()) {
1227 MDF.WithValid(Standard_False);
1230 //-----------------------------
1231 // a posteriori naming
1232 //-----------------------------
1233 MDF.WithValid(Standard_True);
1234 MDF.Valid(NS->Label());
1235 MDF.ValidChildren(NS->Label());
1236 TNaming_OldShapeIterator it(Context,Acces);
1238 for (; it.More(); it.Next()) {
1242 TNaming_NewShapeIterator it2(Context,Acces);
1243 for (;it2.More(); it2.Next()) {
1244 UnValidate (MDF,it2);
1248 //=======================================================================
1249 //function : HasAncFace
1250 //purpose : Returns True & <Face> if ancestor face is found
1251 //=======================================================================
1252 static Standard_Boolean HasAncFace(const TopoDS_Shape& Context,
1253 const TopoDS_Shape& W, TopoDS_Shape& Face, Standard_Boolean& isOuter)
1255 Standard_Boolean hasFace(Standard_False);
1256 if(W.ShapeType() != TopAbs_WIRE)
1258 TopExp_Explorer exp(Context, TopAbs_FACE);
1259 for(;exp.More(); exp.Next()) {
1260 for (TopoDS_Iterator it(exp.Current()) ; it.More(); it.Next()) {
1261 if(it.Value().IsEqual(W)) {// is the Wire ?
1262 Face = exp.Current();
1263 if(!Face.IsNull()) {
1264 hasFace = Standard_True;
1265 // cout << "HasAncFace: TS = " <<theFace.TShape()->This() <<endl;
1266 const TopoDS_Face aFace(TopoDS::Face(Face));
1267 TopoDS_Wire anOuterW;
1268 if(TNaming::OuterWire(aFace, anOuterW)) {
1269 if(!anOuterW.IsNull() && anOuterW.IsEqual(W))
1270 isOuter = Standard_True;
1272 isOuter = Standard_False;
1283 //=======================================================================
1284 //function : BuildNameWire
1285 //purpose : Names Wire
1286 //=======================================================================
1288 static Handle(TNaming_NamedShape) BuildNameWire (const TDF_Label& F,
1290 const TopoDS_Shape& Selection,
1291 const TopoDS_Shape& Context,
1292 const Handle(TNaming_NamedShape)& Stop,
1293 const Standard_Boolean Geom)
1295 Handle (TNaming_NamedShape) NS;
1296 Standard_Boolean found(Standard_False);
1297 Handle (TNaming_Naming) Naming;
1298 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1299 Naming = new TNaming_Naming ();
1300 F.AddAttribute (Naming);
1301 TNaming_Name& theName = Naming->ChangeName();
1302 theName.ShapeType(Selection.ShapeType());
1303 theName.Shape(Selection);
1304 theName.Orientation(Selection.Orientation());
1307 TNaming_Name& theName = Naming->ChangeName();
1309 Standard_Boolean isOuter(Standard_False);
1310 Standard_Boolean hasFace = HasAncFace(Context, Selection, aFace, isOuter);
1311 if(hasFace && Selection.ShapeType() > Context.ShapeType()) {
1312 theName.Type(TNaming_WIREIN);
1313 if(Context.ShapeType() == TopAbs_FACE) {
1314 for (TopoDS_Iterator it(Context) ; it.More(); it.Next()) {
1315 if(it.Value().IsEqual(Selection)) {
1316 if (TNaming_Selector::IsIdentified (F, Context, NS, Geom)) {
1318 found = Standard_True;
1324 theName.Append(BuildName (Naming->Label(),MDF,aFace,Context,Stop,Geom));
1329 for (TopExp_Explorer exp(Selection,TopAbs_EDGE) ; exp.More(); exp.Next()) {
1330 if(exp.Current().IsNull()) continue;
1331 if (BRep_Tool::Degenerated(TopoDS::Edge(exp.Current()))) continue;
1332 theName.Append(TNaming_Naming::Name(Naming->Label(),exp.Current(),Context, Geom, 1, 0));
1336 return BuildNS (F,Selection, TNaming_UNKNOWN);
1338 } else { // context is not Face
1339 theName.Append(BuildName (Naming->Label(),MDF,aFace,Context,Stop,Geom));
1343 for (TopExp_Explorer exp(Selection,TopAbs_EDGE) ; exp.More(); exp.Next()) {
1344 if(exp.Current().IsNull()) continue;
1345 if (BRep_Tool::Degenerated(TopoDS::Edge(exp.Current()))) continue;
1346 theName.Append(TNaming_Naming::Name(Naming->Label(),exp.Current(),Context, Geom, 1, 0));
1351 else { // => no Face
1352 theName.Type(TNaming_UNION);
1353 for (TopExp_Explorer exp(Selection,TopAbs_EDGE) ; exp.More(); exp.Next()) {
1354 if(exp.Current().IsNull()) continue;
1355 if (BRep_Tool::Degenerated(TopoDS::Edge(exp.Current()))) continue;
1356 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1359 //Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1360 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1364 //=======================================================================
1365 static Standard_Boolean IsOneIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1367 Standard_Boolean found(Standard_False);
1368 if(S.IsNull() || Context.IsNull()) return found;
1369 for (TopExp_Explorer exp(Context,S.ShapeType()); exp.More(); exp.Next()) {
1370 if (exp.Current().IsEqual(S)) {
1371 found = Standard_True;
1378 //=======================================================================
1379 static Standard_Boolean IsAllIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1382 Write(S, "IsAllIn_Sel.brep");
1384 Standard_Boolean found(Standard_False);
1385 if(S.IsNull() || Context.IsNull()) return found;
1386 Standard_Integer num1(0), num2(0);
1387 for(TopoDS_Iterator it(S);it.More();it.Next(),num1++) {
1389 cout <<"S sub-shape type = " << it.Value().ShapeType() <<endl;
1390 Write (it.Value(), "Sel_ItValue.brep");
1392 if(it.Value().ShapeType() != TopAbs_COMPOUND)
1393 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1395 cout <<"Context sub-shape type = " << exp.Current().ShapeType() <<endl;
1396 Write(exp.Current(), "Contex_Curnt.brep");
1398 if (exp.Current().IsEqual(it.Value())) {
1403 Standard_Boolean isAll = IsAllIn(it.Value(), Context);
1409 found = Standard_True;
1412 cout <<"Compound case : selected num1 = " << num1 << " context contains num2 = " << num2 << endl;
1416 //=======================================================================
1417 //function : RepeatabilityInContext
1419 //=======================================================================
1420 static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
1421 const TopoDS_Shape& Context)
1423 Standard_Integer aNum(0);
1424 if (!Context.IsNull() && !Selection.IsNull()) {
1425 // Write(Selection, "Repeat_Selection.brep");
1426 // Write(Context, "Repeat_Context.brep");
1427 if (Context.ShapeType() < Selection.ShapeType()) {
1428 if(Selection.ShapeType() != TopAbs_SHELL) {
1429 for (TopExp_Explorer exp(Context,Selection.ShapeType()); exp.More(); exp.Next()) {
1430 if (exp.Current().IsSame(Selection))
1435 else if(Selection.ShapeType() == TopAbs_COMPOUND) {
1436 TopoDS_Iterator it(Selection);
1437 for(;it.More();it.Next()) {
1438 Standard_Integer n(0);
1439 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1440 if (exp.Current().IsSame(it.Value())) {
1444 if(n > aNum) aNum = n;
1449 cout <<"RepeatabilityInContext: = " <<aNum <<endl;
1454 //=======================================================================
1455 //function : HasAncSolid
1456 //purpose : Returns true if Sh has ancestor solid in this context
1457 //=======================================================================
1458 static Standard_Boolean HasAncSolid(const TopoDS_Shape& Context,
1459 const TopoDS_Shape& Sh, TopoDS_Shape& Solid,
1460 Standard_Boolean& isOuter)
1462 Standard_Boolean hasSolid(Standard_False);
1463 if(Sh.ShapeType() != TopAbs_SHELL)
1465 TopExp_Explorer exp(Context, TopAbs_SOLID);
1466 for(;exp.More(); exp.Next()) {
1467 for (TopoDS_Iterator it(exp.Current()) ; it.More(); it.Next()) {
1468 if(it.Value().IsEqual(Sh)) {// is the Solid ?
1469 Solid = exp.Current();
1470 if(!Solid.IsNull()) {
1471 hasSolid = Standard_True;
1472 TopoDS_Shell anOuterShell;
1473 if(TNaming::OuterShell(TopoDS::Solid(Solid), anOuterShell)) {
1474 #ifdef MDTV_DEB_TSOL
1475 Write(anOuterShell, "OuterShell.brep");
1477 if(!anOuterShell.IsNull() && anOuterShell.IsEqual(Sh))
1478 isOuter = Standard_True;
1480 isOuter = Standard_False;
1490 //=======================================================================
1491 //function : BuildNameShell
1492 //purpose : Names Shell
1493 //=======================================================================
1495 static Handle(TNaming_NamedShape) BuildNameShell (const TDF_Label& F,
1497 const TopoDS_Shape& Selection,
1498 const TopoDS_Shape& Context,
1499 const Handle(TNaming_NamedShape)& Stop,
1500 const Standard_Boolean Geom)
1502 Handle (TNaming_NamedShape) NS;
1503 Standard_Boolean found(Standard_False);
1504 Handle (TNaming_Naming) Naming;
1505 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1506 Naming = new TNaming_Naming ();
1507 F.AddAttribute (Naming);
1508 TNaming_Name& theName = Naming->ChangeName();
1509 theName.ShapeType(Selection.ShapeType());
1510 theName.Shape(Selection);
1511 theName.Orientation(Selection.Orientation());
1514 TNaming_Name& theName = Naming->ChangeName();
1515 TopoDS_Shape aSolid;
1516 Standard_Boolean isOuter(Standard_False);
1517 Standard_Boolean hasSolid = HasAncSolid(Context, Selection, aSolid, isOuter);
1518 if(hasSolid && Selection.ShapeType() > Context.ShapeType()) {
1519 theName.Type(TNaming_SHELLIN);// SHELLIN
1521 if(Context.ShapeType() == TopAbs_SOLID) {
1522 for (TopoDS_Iterator it(Context) ; it.More(); it.Next()) {
1523 #ifdef MDTV_DEB_TSOL
1524 Write(it.Value(), "Shell_inSo.brep");
1526 if(it.Value().IsEqual(Selection)) {
1527 found = Standard_True;
1532 // solid => aSolid which is also a context
1533 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(Context,F);
1535 theName.ContextLabel(aNS->Label());
1536 theName.Append(aNS);
1539 } else { //not OuterShell
1541 for (TopExp_Explorer exp(Selection,TopAbs_FACE) ; exp.More(); exp.Next()) {
1542 if(exp.Current().IsNull()) continue;
1543 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1547 return BuildNS (F,Selection, TNaming_UNKNOWN);
1549 // context is not SOLID
1550 //theName.Append(BuildName (Naming->Label(),MDF,aSolid,Context,Stop,Geom));//###########
1552 #ifdef MDTV_DEB_TSOL
1553 Write(aSolid, "foundSolid.brep");
1556 Handle (TNaming_Naming) NamingSo = TNaming_Naming::Insert(F);
1557 TNaming_Name& theNameSo = NamingSo->ChangeName();
1558 theNameSo.ShapeType(aSolid.ShapeType());
1559 theNameSo.Shape(aSolid);
1560 theNameSo.Type(TNaming_UNION);
1561 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(Context,F);
1563 theNameSo.ContextLabel(aNS->Label());
1564 for (TopExp_Explorer exp(aSolid,TopAbs_FACE) ; exp.More(); exp.Next())
1565 theNameSo.Append(BuildName (NamingSo->Label(),MDF,exp.Current(),Context,Stop,Geom));
1566 NamingSo->GetName().Solve(NamingSo->Label(),MDF.GetValid());
1568 NamingSo->Label().FindAttribute(TNaming_NamedShape::GetID(),aNS);
1569 theName.Append(aNS);
1572 // - name Solid: theName.Append(BuildName (Naming->Label(),MDF, aSolid,Context,Stop,Geom));
1573 Handle (TNaming_Naming) NamingSo = TNaming_Naming::Insert(F);
1574 TNaming_Name& theNameSo = NamingSo->ChangeName();
1575 theNameSo.ShapeType(aSolid.ShapeType());
1576 theNameSo.Shape(aSolid);
1577 theNameSo.Type(TNaming_UNION);
1578 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(Context,F);
1580 theNameSo.ContextLabel(aNS->Label());
1581 for (TopExp_Explorer exp(aSolid,TopAbs_FACE) ; exp.More(); exp.Next())
1582 theNameSo.Append(BuildName (NamingSo->Label(),MDF,exp.Current(),Context,Stop,Geom));
1583 NamingSo->GetName().Solve(NamingSo->Label(),MDF.GetValid());
1585 NamingSo->Label().FindAttribute(TNaming_NamedShape::GetID(),aNS);
1586 theName.Append(aNS);
1588 for (TopExp_Explorer exp(Selection,TopAbs_FACE) ; exp.More(); exp.Next()) {
1589 if(exp.Current().IsNull()) continue;
1590 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1595 else { // => no Solid
1596 theName.Type(TNaming_UNION);
1597 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(Context,F);
1599 theName.ContextLabel(aNS->Label());
1600 for (TopExp_Explorer exp(Selection,TopAbs_FACE) ; exp.More(); exp.Next()) {
1601 if(exp.Current().IsNull()) continue;
1602 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1605 //Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1606 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1610 //=======================================================================
1611 //function : BuildAggregationNam
1613 //=======================================================================
1614 static void BuildAggregationName (const TDF_Label& F,
1616 const TopoDS_Shape& S,
1617 const TopoDS_Shape& Context,
1618 const Handle(TNaming_NamedShape)& Stop,
1619 const Standard_Boolean Geom)
1621 const Standard_Boolean found2 = IsAllIn(S, Context);
1622 Handle (TNaming_Naming) Naming;
1623 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1624 Naming = new TNaming_Naming ();
1625 F.AddAttribute (Naming);
1626 TNaming_Name& theName = Naming->ChangeName();
1627 theName.ShapeType(S.ShapeType());
1629 theName.Orientation(S.Orientation());
1632 cout <<"BuildAggregationName ==> ";
1633 Print_Entry(Naming->Label());
1635 TNaming_Name& theName = Naming->ChangeName();
1636 for (TopoDS_Iterator itc(S) ; itc.More(); itc.Next()) {
1637 const TopoDS_Shape& aS = itc.Value();
1638 if ((aS.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(aS,Naming->Label()).IsNull()) ||
1639 aS.ShapeType() == TopAbs_FACE ||
1640 aS.ShapeType() == TopAbs_EDGE ||
1641 aS.ShapeType() == TopAbs_VERTEX ) {
1642 theName.Append(BuildName (F, MDF, aS,Context,Stop,Geom));
1643 } else { // ==> union of union || union of wires
1644 TopAbs_ShapeEnum atomTyp;
1645 switch (aS.ShapeType())
1649 atomTyp = TopAbs_FACE;
1652 atomTyp = TopAbs_EDGE;
1655 atomTyp = TopAbs_SHAPE;
1658 Handle(TNaming_NamedShape) aNS;
1659 Handle (TNaming_Naming) aNaming = TNaming_Naming::Insert(F);
1660 TNaming_Name& aName = aNaming->ChangeName();
1661 aName.ShapeType(aS.ShapeType());
1663 theName.Orientation(aS.Orientation());
1664 aName.Type(TNaming_UNION);
1666 if (atomTyp != TopAbs_SHAPE) {
1667 if(aS.ShapeType() == TopAbs_WIRE) {
1668 aNS = BuildNameWire (aNaming->Label(), MDF, aS, Context,Stop,Geom);
1670 else if(aS.ShapeType() == TopAbs_SHELL)
1671 aNS = BuildNameShell (aNaming->Label(), MDF, aS, Context,Stop,Geom);
1673 for (TopExp_Explorer exp(aS,atomTyp) ; exp.More(); exp.Next()) {
1674 aName.Append(BuildName (aNaming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1679 cout << "atomic type is NOT defined ... ==> Aggregation" <<endl;
1681 BuildAggregationName(aNaming->Label(),MDF, aS, Context,Stop,Geom);
1684 aNS = TNaming_Tool::NamedShape(Context, F);
1686 aNaming->ChangeName().ContextLabel(aNS->Label());
1689 aNaming->GetName().Solve(aNaming->Label(),MDF.GetValid());
1690 if(aNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),aNS))
1691 if (!Geom && TestSolution(MDF,aNS,aS)) {
1692 theName.Append(aNS);
1699 //=======================================================================
1702 //=======================================================================
1704 Handle(TNaming_NamedShape) TNaming_Naming::Name (const TDF_Label& F,
1705 const TopoDS_Shape& S,
1706 const TopoDS_Shape& Context,
1707 const Standard_Boolean Geom,
1708 const Standard_Boolean KeepOrientation,
1709 const Standard_Boolean BNProblem)
1712 Handle(TNaming_NamedShape) NS;
1713 if (KeepOrientation) {
1714 #ifdef MDTV_DEB_INNS
1715 cout <<"KeepOR = 1: "; Print_Entry(F);
1717 Standard_Integer aNum = RepeatabilityInContext(S, Context);
1719 Standard_Boolean aBNproblem = (BNProblem) ? (aNum /*== 1*/ && S != Context) : Standard_False;
1721 if (aNum > 1 || aBNproblem) {
1722 TopoDS_Shape UC = TNaming::FindUniqueContext(S, Context);
1723 Handle(TopTools_HArray1OfShape) Arr;
1724 if (UC.IsNull() && S.ShapeType() == TopAbs_COMPOUND) {
1725 UC = TNaming::FindUniqueContextSet(S, Context, Arr);
1727 Write(UC, "UniqueContextSet.brep");
1728 Write(S, "InitialSelection.brep");
1729 if(S.ShapeType()==TopAbs_COMPOUND) {
1730 TCollection_AsciiString aNam("S_");
1731 TopoDS_Iterator it(S);
1732 for(int i=1;it.More();it.Next(),i++) {
1733 TCollection_AsciiString aName = aNam + i + ".brep";
1734 Write(it.Value(), aName.ToCString());
1740 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1741 TNaming_Name& theName = Naming->ChangeName();
1742 theName.ShapeType(S.ShapeType());
1744 theName.Type(TNaming_ORIENTATION);
1745 theName.Orientation(S.Orientation());
1747 if (!TNaming_Selector::IsIdentified (F, S, NS, Geom))
1748 NS = TNaming_Naming::Name(Naming->Label(),S,Context,Geom,0);
1749 theName.Append (NS);
1751 cout << " Sel Label ==> "; Print_Entry(NS->Label());
1754 if(S.ShapeType() == TopAbs_EDGE && UC.ShapeType() == TopAbs_FACE) {
1755 if(RepeatabilityInContext(S, UC) == 2) { //sim. edge
1756 TopoDS_Iterator itw(UC);
1757 for(;itw.More();itw.Next()) {
1758 Standard_Boolean found(Standard_False);
1759 TopoDS_Iterator it(itw.Value());
1760 for(int i=1;it.More();it.Next(),i++) {
1761 if(it.Value().IsEqual(S)) {
1762 theName.Index(i);//We use this field to save a Seam Shape Index; Before this field was used for GENERATED only
1763 found = Standard_True;
1765 cout << "ORDER = " << i <<endl;
1775 if(S.ShapeType() == TopAbs_COMPOUND && Arr->Length() > 1) {
1776 // N arguments: to be optimized to avoid duplication of the same Context shape
1777 for(Standard_Integer i = Arr->Lower(); i <= Arr->Upper(); i++) {
1778 NS = TNaming_Naming::Name(Naming->Label(), Arr->Value(i), Context, Geom, 1, aBNproblem);
1779 theName.Append (NS);
1782 NS = TNaming_Naming::Name(Naming->Label(),UC,Context, Geom, 1, aBNproblem);
1783 theName.Append (NS);
1785 cout << " Cont Label ==> "; Print_Entry(NS->Label());
1790 BuildScope (MDF,Context,F);
1791 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1792 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1793 theName.ContextLabel(NS->Label());
1794 if (Geom) return NS;
1796 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1797 return BuildNS (F,S, TNaming_UNKNOWN);
1800 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1801 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1803 // Naming n is unsatisfactory
1804 return BuildNS (F,S, TNaming_UNKNOWN);
1807 if (TNaming_Selector::IsIdentified (F, S, NS, Geom))
1811 //------------------------------------------------------------
1812 // Construction du MDF tel que <Context> soit le dernier etat
1814 // Ceci pour les localisation a posteriori par exemple.
1815 //------------------------------------------------------------
1818 BuildScope (MDF,Context,F);
1819 Handle(TNaming_NamedShape) Stop;
1823 if ((S.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(S,F).IsNull()) ||
1827 if (S.ShapeType() == TopAbs_SOLID ||
1831 S.ShapeType() == TopAbs_FACE ||
1832 S.ShapeType() == TopAbs_EDGE ||
1833 S.ShapeType() == TopAbs_VERTEX ) {
1834 //---------------------------------------
1835 // Localisation de S comme element simple.
1836 //---------------------------------------
1837 Handle(TNaming_NamedShape) NS = BuildName (F,MDF,S,Context,Stop,Geom);
1838 if (Geom) return NS;
1839 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1842 //----------------------------------------------------
1843 // Localisation de S comme ensemble d elements simples.
1844 //-----------------------------------------------------
1845 Handle(TNaming_NamedShape) NS;
1846 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1847 TNaming_Name& theName = Naming->ChangeName();
1849 theName.ShapeType(S.ShapeType());// modified by vro 05.09.00
1851 theName.Orientation(S.Orientation());
1852 if(S.ShapeType() != TopAbs_WIRE)
1853 theName.Type(TNaming_UNION);
1856 TopAbs_ShapeEnum atomType;
1857 switch (S.ShapeType()) {
1858 case TopAbs_COMPSOLID:
1861 atomType = TopAbs_FACE;
1864 atomType = TopAbs_EDGE;
1867 atomType = TopAbs_SHAPE;
1869 Standard_Boolean found(Standard_False);
1870 if (!Context.IsNull()) {
1871 if (Context.ShapeType() < S.ShapeType())
1872 found = IsOneIn(S, Context);
1874 NS = TNaming_Tool::NamedShape(Context, F);
1876 theName.ContextLabel(NS->Label());
1879 if (atomType == TopAbs_SHAPE) {
1880 if(S.ShapeType() == TopAbs_COMPOUND) {
1881 BuildAggregationName(Naming->Label(),MDF, S, Context,Stop,Geom);
1883 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1884 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1888 if(S.ShapeType() == TopAbs_WIRE)
1889 NS = BuildNameWire (Naming->Label(), MDF, S, Context,Stop,Geom);
1890 else if(S.ShapeType() == TopAbs_SHELL) {
1891 NS = BuildNameShell (Naming->Label(), MDF, S, Context,Stop,Geom);
1894 theName.Type(TNaming_UNION);
1895 for (TopExp_Explorer exp(S,atomType) ; exp.More(); exp.Next()) {
1896 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1901 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1902 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1907 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1908 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1909 if (Geom) return NS;
1912 if(NS.IsNull()) return BuildNS (F,S, TNaming_UNKNOWN);
1915 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1918 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1920 // Naming n is not satisfactory
1921 return BuildNS (F,S, TNaming_UNKNOWN);
1925 //=======================================================================
1926 //function : TNaming_Naming
1928 //=======================================================================
1930 TNaming_Naming::TNaming_Naming() {}
1932 //=======================================================================
1935 //=======================================================================
1937 const Standard_GUID& TNaming_Naming::ID () const
1943 //=======================================================================
1944 //function : IsDefined
1946 //=======================================================================
1948 Standard_Boolean TNaming_Naming::IsDefined() const
1950 return (myName.Type() != TNaming_UNKNOWN);
1953 //=======================================================================
1954 //function : GetName
1956 //=======================================================================
1958 const TNaming_Name& TNaming_Naming::GetName() const
1963 //=======================================================================
1964 //function : ChangeName
1966 //=======================================================================
1968 TNaming_Name& TNaming_Naming::ChangeName()
1973 //=======================================================================
1974 //function : Regenerate
1975 //purpose : idem designer
1976 //=======================================================================
1978 Standard_Boolean TNaming_Naming::Regenerate (TDF_LabelMap& MDF)
1981 return myName.Solve(Label(),MDF);
1985 //=======================================================================
1986 //function : NewEmpty
1988 //=======================================================================
1990 Handle(TDF_Attribute) TNaming_Naming::NewEmpty () const
1992 return new TNaming_Naming ();
1996 //=======================================================================
1997 //function : Restore
1999 //=======================================================================
2001 void TNaming_Naming::Restore(const Handle(TDF_Attribute)& other)
2003 Handle(TNaming_Naming) OtherNaming = Handle(TNaming_Naming)::DownCast(other);
2004 myName = OtherNaming->ChangeName();
2007 //=======================================================================
2010 //=======================================================================
2012 void TNaming_Naming::Paste (const Handle(TDF_Attribute)& into,
2013 const Handle(TDF_RelocationTable)& RT) const
2015 Handle(TNaming_Naming) NewNaming = Handle(TNaming_Naming)::DownCast(into);
2016 myName.Paste(NewNaming->ChangeName(),RT);
2019 //=======================================================================
2020 //function : References
2021 //purpose : Redefined from TDF_Attribute
2022 //=======================================================================
2024 void TNaming_Naming::References(const Handle(TDF_DataSet)& DataSet) const
2026 // Iteration on NamedShape of the name
2027 TNaming_ListIteratorOfListOfNamedShape it(myName.Arguments());
2028 for (;it.More();it.Next()) DataSet->AddAttribute(it.Value());
2029 if (!myName.StopNamedShape().IsNull()) DataSet->AddAttribute(myName.StopNamedShape());
2031 //=======================================================================
2034 //=======================================================================
2036 Standard_OStream& TNaming_Naming::Dump (Standard_OStream& anOS) const
2038 anOS << "TNaming_Naming";
2043 //=======================================================================
2044 //function :ExtendedDump
2046 //=======================================================================
2048 void TNaming_Naming::ExtendedDump(Standard_OStream& anOS,
2049 const TDF_IDFilter& /*aFilter*/,
2050 TDF_AttributeIndexedMap& /*aMap*/) const
2052 anOS << "TNaming_Naming ExtendedDump ";
2053 //anOS<<"myContext: #" <<aMap.Add(myContext)<<endl;