1 // Created on: 1997-09-03
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <TNaming_Naming.ixx>
25 #include <TNaming_Builder.hxx>
26 #include <TNaming_Tool.hxx>
27 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
28 #include <TNaming_Iterator.hxx>
29 #include <TNaming_Scope.hxx>
30 #include <TNaming_NamingTool.hxx>
31 #include <TNaming_Name.hxx>
32 #include <TNaming_Identifier.hxx>
33 #include <TNaming_Localizer.hxx>
34 #include <TNaming_NewShapeIterator.hxx>
35 #include <TNaming_OldShapeIterator.hxx>
36 #include <TNaming_Selector.hxx>
37 #include <TNaming.hxx>
38 #include <TDF_ChildIterator.hxx>
39 #include <TDF_LabelList.hxx>
40 #include <TDF_Data.hxx>
41 #include <TDF_LabelMap.hxx>
42 #include <TDF_TagSource.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopTools_MapIteratorOfMapOfShape.hxx>
48 #include <Standard_DomainError.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
52 #include <TColStd_MapOfInteger.hxx>
53 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
54 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
55 #include <TopTools_HArray1OfShape.hxx>
56 #include <BRep_Tool.hxx>
58 // #include <TNaming_NCollections.hxx>
59 #include <NCollection_Map.hxx>
60 #include <NCollection_DataMap.hxx>
61 typedef NCollection_Map<TopoDS_Shape> TNaming_MapOfShape;
62 typedef TNaming_MapOfShape::Iterator TNaming_MapIteratorOfMapOfShape;
63 typedef NCollection_DataMap<TopoDS_Shape, TNaming_MapOfShape> TNaming_DataMapOfShapeMapOfShape;
64 typedef TNaming_DataMapOfShapeMapOfShape::Iterator TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape;
65 // The bug concerns access to a null object in the method Filter():
71 #define ALLOW_CHILD_NBS
74 //#define MDTV_DEB_MOD
76 //#define MDTV_DEB_INNS
77 //#define MDTV_DEB_NBS
79 //#define MDTV_DEB_WIN
81 #include <TDF_MapIteratorOfLabelMap.hxx>
82 #include <TCollection_AsciiString.hxx>
83 #include <TDF_Tool.hxx>
84 #include <BRepTools.hxx>
85 #include <TNaming_Tool.hxx>
86 #include <DbgTools.hxx>
89 #include <TDF_Tool.hxx>
90 #include <TDF_MapIteratorOfLabelMap.hxx>
92 #include <TCollection_AsciiString.hxx>
93 #include <BRepTools.hxx>
94 void Print_Entry(const TDF_Label& label)
96 TCollection_AsciiString entry;
97 TDF_Tool::Entry(label, entry);
98 cout << "LabelEntry = "<< entry << endl;
100 static void Write(const TopoDS_Shape& shape,
101 const Standard_CString filename)
104 if(strlen(filename) > 256) return;
105 strcpy (buf, filename);
114 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
115 save << "DBRep_DrawableShape" << endl << endl;
116 if(!shape.IsNull()) BRepTools::Write(shape, save);
119 void WriteNSOnLabel(const Handle(TNaming_NamedShape) & NS, const TCollection_AsciiString& Nam)
122 TCollection_AsciiString entry;
123 TDF_Tool::Entry(NS->Label(), entry);
124 TopoDS_Shape Sh = TNaming_Tool::GetShape (NS);
126 TCollection_AsciiString Entry = Nam + entry + ".brep";
127 Write(Sh, Entry.ToCString());
130 cout << "WriteNSOnLabel>>> TopoDS_Shape IS NULL on Entry = "<< entry << endl;
133 cout << "WriteNSOnLabel >>> NamedShape IS NULL" << endl;
135 //=======================================================================
136 static void Write(const TopTools_MapOfShape& MS, const Standard_CString filename)
138 if (!MS.IsEmpty ()) {
139 TCollection_AsciiString aNam (filename);
140 Standard_Integer i(0);
141 TopTools_MapIteratorOfMapOfShape it(MS);
142 for(;it.More();it.Next(),i++) {
143 TCollection_AsciiString aName = aNam + "_" + i + ".brep";
144 Write ( it.Key(), aName.ToCString());
150 //==========================================================================================
151 static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
153 const TopoDS_Shape& S,
154 const TopoDS_Shape& Context,
155 const Handle(TNaming_NamedShape)& Stop,
156 const Standard_Boolean Geometry);
158 //=======================================================================
159 static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
160 const TopoDS_Shape& Context);
161 //=======================================================================
162 extern Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2);
164 //=======================================================================
166 //purpose : voir avec YFR comment retrouver le bon resulat et le mettre
167 // : dans le NamedShape de L
168 //=======================================================================
169 Standard_Boolean TNaming_Naming::Solve (TDF_LabelMap& Valid)
171 Handle(TNaming_Naming) subname;
172 for (TDF_ChildIterator it (Label(),Standard_False); it.More(); it.Next()) {
174 TCollection_AsciiString anEntry;
175 TDF_Tool::Entry(it.Value(), anEntry);
176 cout << "TNaming_Naming::Solve: Label to be solved = " << anEntry << endl;
178 if (it.Value().FindAttribute(TNaming_Naming::GetID(),subname)) {
179 if (!subname->Solve (Valid)) {
180 return Standard_False; // not necessary to continue
185 TDF_MapIteratorOfLabelMap anItr(Valid);
186 cout << "TNaming_Naming::Solve:: Valid label Map" << endl;
187 for (; anItr.More(); anItr.Next()) {
188 const TDF_Label& aLabel = anItr.Key();
189 TCollection_AsciiString anEntry;
190 TDF_Tool::Entry(aLabel, anEntry);
191 cout << "Label = " << anEntry << endl;
194 if (Regenerate(Valid)) {
195 if (!Valid.IsEmpty()) Valid.Add(Label());
196 return Standard_True;
198 return Standard_False;
202 //=======================================================================
205 //=======================================================================
207 const Standard_GUID& TNaming_Naming::GetID ()
209 static Standard_GUID TNaming_NamingID("c0a19201-5b78-11d1-8940-080009dc3333");
210 return TNaming_NamingID;
213 //=======================================================================
216 //=======================================================================
218 Handle(TNaming_Naming) TNaming_Naming::Insert (const TDF_Label& under)
220 Handle(TNaming_Naming) N;
221 TDF_Label child = TDF_TagSource::NewChild(under);
222 N = new TNaming_Naming ();
223 child.AddAttribute (N);
227 //=======================================================================
229 //purpose : returns a new NamedShape, which is built as selection:
230 // : TNaming_Builder::Select("S","S") at the new child label of the label <F>.
231 //=======================================================================
233 static Handle(TNaming_NamedShape) BuildNS (const TDF_Label& F,
234 const TopoDS_Shape& S,
235 const TNaming_NameType& Name)
237 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert (F);
239 TNaming_Name& theName = Naming->ChangeName();
240 theName.ShapeType(S.ShapeType());
243 TNaming_Builder B(Naming->Label());
245 return B.NamedShape();
248 //=======================================================================
249 //function : FindIndex
251 //=======================================================================
253 static Standard_Integer FindIndex(const Handle(TNaming_NamedShape)& NS,
254 const TopoDS_Shape& S)
256 TDF_LabelList Labels;
257 TopoDS_Shape IS = TNaming_Tool::InitialShape(S,NS->Label(),Labels);
258 Standard_Integer Index = 1;
259 for (TNaming_Iterator itNS(NS); itNS.More(); itNS.Next(),Index++) {
260 if (IS.IsSame(itNS.NewShape())) break;
266 //=======================================================================
267 //function : CompareInGeneration
268 //purpose : returns true, only if the specified NS contains only <S> in
269 // : the "new shapes" set.
270 //=======================================================================
272 static Standard_Boolean CompareInGeneration (const Handle(TNaming_NamedShape)& NS,
273 const TopoDS_Shape& S)
275 for (TNaming_Iterator it(NS); it.More(); it.Next()) {
276 if (!it.NewShape().IsSame(S)) return 0;
283 //=======================================================================
284 //function : GetShapeEvolutions
285 //purpose : returns Standard_True, if target has parent in source; list contains inheritance chain
286 //=======================================================================
287 static Standard_Boolean GetShapeEvolutions(const TopoDS_Shape& theTarget, // this is changed in recursion
288 const Handle(TNaming_NamedShape)& theSource,
289 TopTools_ListOfShape& aList) // returns list in the backward order
291 Handle(TNaming_NamedShape) aTarget = TNaming_Tool::NamedShape(theTarget,theSource->Label());
292 if (!aTarget.IsNull()) {
294 cout <<"GetShapeEvolutions: target NS = ";
295 Print_Entry(aTarget->Label());
296 cout <<"GetShapeEvolutions: Source NS = ";
297 Print_Entry(theSource->Label());
298 TCollection_AsciiString aNam("GetShapeEvolutions");
299 WriteNSOnLabel(aTarget,aNam);
301 if (aTarget->Label() == theSource->Label()) return Standard_True; // check if target is in the source
302 } else return Standard_False;
304 TNaming_Iterator anIter(aTarget);
305 for(;anIter.More();anIter.Next()) { // check all appropriate old shapes of target
307 if(!anIter.OldShape().IsNull()) {
308 Write(anIter.OldShape(), "Target_OldS.brep");
309 cout <<"Target OldS TS =" <<anIter.OldShape().TShape()->This() <<endl;
311 if(!anIter.NewShape().IsNull()) {
312 Write(anIter.NewShape(), "Target_NewS.brep");
313 cout <<"Target NewS TS =" <<anIter.NewShape().TShape()->This() <<endl;
316 if (anIter.OldShape().IsNull() || anIter.NewShape().IsNull()) continue;
317 if (!anIter.NewShape().IsSame(theTarget)) continue;
318 if (GetShapeEvolutions(anIter.OldShape(),theSource,aList)) { // recursion: now target is old shape
319 aList.Append(theTarget); // if oldshape has the source as parent (or belongs to it) , fill the list
320 return Standard_True;
323 return Standard_False;
326 //=======================================================================
327 //function : CompareInModification
328 //purpose : returns empty named shape if naming is already done
329 //=======================================================================
331 static Handle(TNaming_NamedShape) CompareInModification (const Handle(TNaming_NamedShape)& NS, // parent
332 const TopoDS_Shape& S) // target
334 Handle(TNaming_NamedShape) aResult;
335 if (S.IsNull() || NS.IsNull()) return aResult;
337 cout <<"CompareInModification: parent NS = ";
338 Print_Entry(NS->Label());
339 Write(S, "CompareInM_S.brep");
340 TCollection_AsciiString aNam("CompareInM");
341 WriteNSOnLabel(NS,aNam);
343 Handle(TNaming_NamedShape) aSource; // parent NamedShape, which can be found by TopoDS shape
344 TNaming_Iterator anIt(NS);
345 for(;anIt.More() && aSource.IsNull();anIt.Next()) {
346 if (!anIt.NewShape().IsNull()) {
347 aSource = TNaming_Tool::NamedShape(anIt.NewShape(),NS->Label());
349 TCollection_AsciiString aNam("CompareInM_Source");
350 WriteNSOnLabel(aSource,aNam);
354 // searching for 1:n to the same label modifications (in this case current naming is insufficient)
355 TopTools_ListOfShape aList;
356 if (GetShapeEvolutions(S,aSource,aList) && aList.Extent() > 0) {
357 TopTools_ListIteratorOfListOfShape anIter(aList);
358 for(;anIter.More();anIter.Next()) {
359 aResult = TNaming_Tool::NamedShape(anIter.Value(),NS->Label());
360 if (aResult->Evolution()!=TNaming_MODIFY) { // evolution must be modify, otherwise everything is OK
364 TopTools_MapOfShape aMap; // collection of the old shapes of the shape from list
365 TNaming_Iterator aNIter1(aResult);
367 for(;aNIter1.More();aNIter1.Next()) {
368 if (aNIter1.NewShape().IsSame(anIter.Value())) {// if isSame
369 aMap.Add(aNIter1.OldShape());
372 TNaming_Iterator aNIter2(aResult); // if some another shapes has oldshape from map, return namedshape with this oldshape
374 for(;aNIter2.More();aNIter2.Next()) {
375 if (aNIter2.NewShape().IsSame(anIter.Value())) continue;
376 if (aMap.Contains(aNIter2.OldShape())) { // if one shape was modified to the two at the shared label, return this one
377 aResult = TNaming_Tool::NamedShape(aNIter2.OldShape(),NS->Label());
378 if (!aResult.IsNull()) return aResult;
388 //=======================================================================
389 static Standard_Boolean FillSMap(const TopoDS_Shape& S, TopTools_MapOfShape& MS)
391 if(S.IsNull()) return Standard_False;
392 Standard_Boolean isHomogen(Standard_True);
393 TopAbs_ShapeEnum aPrevType(TopAbs_SHAPE);
394 TopoDS_Iterator it(S);
395 for (; it.More(); it.Next()) {
396 const TopAbs_ShapeEnum aType = it.Value().ShapeType();
398 cout <<"TestSolution_FillMap: S_Type = :" << it.Value().ShapeType() <<" TShape = " << it.Value().TShape()->This() <<endl;
400 if(aType > TopAbs_COMPSOLID) {
402 if(aPrevType == TopAbs_SHAPE)
404 else if(aPrevType != aType)
405 isHomogen = Standard_False;
408 if(!FillSMap(it.Value(), MS))
409 isHomogen = Standard_False;
413 //=======================================================================
415 //purpose : checks naming of the shape <S> in the NamedShape <NS>.
416 // : Returns true, if it's correct. Details ==>
417 // : The method takes all modifications of the "NS" (see CurrentShape method),
418 // : which are in the "MDF" (if it's not empty) before <Stop> shape and check them.
419 // : whether these modifications contain only "S". If yes then the method
420 // : returns true, otherwise it returns false.
421 //=======================================================================
423 static Standard_Boolean Compare (const Handle(TNaming_NamedShape)& NS,
424 const TNaming_Scope& MDF,
425 const Handle(TNaming_NamedShape)& Stop,
426 const TopoDS_Shape& S)
428 TDF_LabelMap Forbiden;
429 TopTools_MapOfShape MS;
430 if (!Stop.IsNull()) TNaming_NamingTool::BuildDescendants(Stop,Forbiden);
431 TNaming_NamingTool::CurrentShape(MDF.GetValid(),Forbiden,NS,MS);
433 Write(S, "Compare_S.brep");
434 cout << "S: TShape = " <<S.TShape()->This() <<endl;
435 Standard_Integer i =1;
436 TopTools_MapIteratorOfMapOfShape it(MS);
437 TCollection_AsciiString aNam("Compare_MS_");
438 TCollection_AsciiString ext(".brep");
439 for(;it.More();it.Next(), i++) {
440 TCollection_AsciiString aName = aNam + i + ext;
441 Write(it.Key(), aName.ToCString()) ;
442 cout << aName.ToCString()<< ": TShape = " <<it.Key().TShape()->This() <<endl;
445 return (MS.Contains(S) && MS.Extent() == 1);
447 //=======================================================================
448 //function : TestSolution
449 //purpose : returns true, if last modification of shape from "NS" is equal to "S":
450 // : If shape "S" has atomic type (TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX),
451 // : then returns S.IsSame(shape from "NS").
452 // : Otherwise the result of exploration of these shapes must be same.
453 //=======================================================================
455 static Standard_Boolean TestSolution(const TNaming_Scope& MDF,
456 const Handle(TNaming_NamedShape)& NS,
457 const TopoDS_Shape& S)
460 if (NS.IsNull()) return Standard_False;
461 TopoDS_Shape Res = MDF.CurrentShape(NS);// last modification of NS taken into account Valid map
462 if(S.IsNull() || Res.IsNull()) return Standard_False;
464 Write(S, "TSol_S.brep");
465 Write(Res, "TSol_Res.brep");
469 if ((S.ShapeType() == TopAbs_FACE ||
470 S.ShapeType() == TopAbs_EDGE ||
471 S.ShapeType() == TopAbs_VERTEX ) &&
472 Res.ShapeType() != TopAbs_COMPOUND) {
473 return (Res.IsSame(S));
474 } else if (S.ShapeType() == TopAbs_SOLID ||
475 S.ShapeType() == TopAbs_COMPSOLID) {
476 TopTools_MapOfShape aMS;
478 for (exp.Init(S,TopAbs_FACE) ; exp.More(); exp.Next()) {
479 aMS.Add(exp.Current());
481 for (exp.Init(Res,TopAbs_FACE) ; exp.More(); exp.Next()) { //content of MS and Res should be the same
482 if (aMS.Contains(exp.Current())) {
483 aMS.Remove(exp.Current());
487 return aMS.IsEmpty();
492 if (S.ShapeType() == TopAbs_SOLID ||
493 S.ShapeType() == TopAbs_FACE ||
494 S.ShapeType() == TopAbs_EDGE ||
495 S.ShapeType() == TopAbs_VERTEX ) {
496 return (Res.IsSame(S));
502 TopTools_MapOfShape MS;
503 Standard_Boolean isHom = FillSMap(S, MS);
504 TopAbs_ShapeEnum aType(TopAbs_SHAPE);
505 TColStd_MapOfInteger aView;
506 TopTools_MapIteratorOfMapOfShape itm(MS);
507 for(;itm.More();itm.Next()) {
508 aType = itm.Key().ShapeType();
512 aView.Add(itm.Key().ShapeType());
515 if (MS.Contains(Res)) {
517 if (MS.IsEmpty()) return 1;
519 if (Res.ShapeType() == TopAbs_SOLID ||
520 Res.ShapeType() == TopAbs_COMPSOLID ||
521 Res.ShapeType() == TopAbs_COMPOUND)
525 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
526 if (MS.Contains(exp.Current())) {
527 MS.Remove(exp.Current());
530 TColStd_MapIteratorOfMapOfInteger itm(aView);
531 for(;itm.More();itm.Next()) {
532 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)itm.Key();
533 for (exp.Init(Res,aType) ; exp.More(); exp.Next()) {
534 if (MS.Contains(exp.Current())) {
535 MS.Remove(exp.Current());
542 return Standard_True;
543 TopoDS_Iterator it(Res);
544 for (; it.More(); it.Next()) { //content of MS and Res should be the same
545 if (MS.Contains(it.Value())) {
546 MS.Remove(it.Value());
555 //=======================================================================
556 //function : FindNewShapeInFather
558 //=======================================================================
560 static void FindNewShapeInFather (const Handle(TNaming_NamedShape)& NS,
563 TDF_Label Father = NS->Label().Father();
564 TNaming_Iterator itLab(Father);
565 for (; itLab.More(); itLab.Next()) {
566 SC= itLab.NewShape();
571 //=======================================================================
572 //function : NextModif
574 //=======================================================================
576 static Handle(TNaming_NamedShape) NextModif(const Handle(TNaming_NamedShape)& NS)
578 Handle (TNaming_NamedShape) Next;
580 TNaming_NewShapeIterator it(NS);
581 if (it.More()&& it.IsModification()) Next = it.NamedShape();
585 //=======================================================================
586 // C1 - cand shape of the father, C2 - shape of rebuild child Naming attr.
587 // (to be Compound of elementary shapes)
588 //=======================================================================
589 static Standard_Boolean IsContSame(const TopoDS_Shape& C1, const TopoDS_Shape& C2)
591 Standard_Boolean aRes(Standard_False);
592 if(!C1.IsNull() && !C2.IsNull()) {
593 TopTools_MapOfShape aMap;
594 if(FillSMap(C1, aMap)) {
595 aRes = Standard_True;
596 TopoDS_Iterator it(C2);
597 for(;it.More();it.Next()) {
598 if(!aMap.Contains(it.Value())) {
599 aRes = Standard_False;
608 //=======================================================================
609 // Identifies the case when Filter haven't sense because of multiplicity
610 //=======================================================================
611 static Standard_Boolean IsMultipleCase(const TopoDS_Shape& S,
612 const TopoDS_Shape& Context,
613 const TopTools_MapOfShape& Neighbourgs) {
615 TopTools_IndexedDataMapOfShapeListOfShape aDM;
616 TNaming_MapOfShape aM;
617 TopTools_MapOfShape aNbs;
618 aNbs.Assign(Neighbourgs);
620 TNaming_DataMapOfShapeMapOfShape aDMM;
621 TopExp::MapShapesAndAncestors (Context, TopAbs_EDGE, TopAbs_FACE, aDM);
622 TopTools_MapIteratorOfMapOfShape it(aNbs);
623 for(;it.More();it.Next()) {
624 if(aDM.Contains(it.Key())) {
625 TNaming_MapOfShape aMS;
626 const TopTools_ListOfShape& aL = aDM.FindFromKey(it.Key());
627 TopTools_ListIteratorOfListOfShape lit(aL);
628 for(;lit.More();lit.Next()) {
630 aMS.Add(lit.Value());
633 aDMM.Bind(it.Key(), aMS);
636 cout << "Key is not BOUND!" <<endl;
638 return Standard_False;
642 Standard_Boolean isCommon(Standard_True);
643 TNaming_MapIteratorOfMapOfShape itm(aM);
644 for(;itm.More();itm.Next()) {
645 isCommon = Standard_True; // statement: this shape (itm.Key()) is common (to be checked below)
646 TNaming_DataMapIteratorOfDataMapOfShapeMapOfShape itdm(aDMM);
647 for (;itdm.More();itdm.Next()) {
648 const TNaming_MapOfShape& aMap = itdm.Value();
649 if(!aMap.Contains(itm.Key())) {
650 isCommon = Standard_False;
654 if(isCommon) break; // common single face found
656 if(isCommon && aM.Extent() < aNbs.Extent()) {// number of unique faces (to have single solution)
657 //should be at least no less than (Nb of Neighbourgs) +1
658 return Standard_True;
660 return Standard_False;
662 //=======================================================================
664 //purpose : sets the name with type "FILTERBYNEIGHBOURGS" and returns true,
665 // : if it was correctly done.
668 //=======================================================================
670 static Standard_Boolean Filter (const TDF_Label& F,
672 const TopoDS_Shape& S,
673 const TopoDS_Shape& Context,
674 TNaming_Localizer& Localizer,
675 Handle(TNaming_NamedShape)& NS,
676 const Standard_Integer Lev)
678 // 1. Localizer.FindNeighbourg("Context", "S", "Neighbourg") - looks for neighbourgs of "S" with the same shape type in the "Context"
679 // shape and adds them to the "Neighbourg" map;
680 // 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;
681 // 3. If "Neighbourg" map is still empty, returns false;
682 // 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",
683 // type is TNaming_FILTERBYNEIGHBOURGS, stop shape ( "Until" ) is "Context" of corresponding NamedShape;
684 // first argument of name is "NS" NamedShape.
685 // 5. Adds to the Name all shapes from "Neighbourg" map: build it with the BuildName( new generated TNaming_Naming attribute, MDF,
686 // argument shape from "Neighbourg", "Context", NextModif( "Until" ), true ) method.
687 // 6. Creates resulting NamedShape with the "Regenerate" ( it just calls TName::Solve method ) method from TNaming_Naming class.
688 // 7. If Compare( result NamedShape, MDF, stop, "S" ) returns true, "Filter" method returns true, else returns false.
690 //------------------------------
691 // Construction des voisins ==> of neighbors.
692 //------------------------------
693 Standard_Integer aLev(Lev);
694 TopTools_MapOfShape Neighbourg;
695 Localizer.FindNeighbourg (Context,S,Neighbourg);
697 //DbgTools::DisplayShape(Context, F, Quantity_NOC_GREEN);
698 //DbgTools::DisplayShape(S, F, Quantity_NOC_BLUE1);
699 Write(Context, "FNBS_Context.brep");
700 Write(S, "FNBS_S.brep");
703 // mpv : NS and shape must be the same
704 Standard_Boolean isIn = Standard_False;
705 TNaming_Iterator anIter(NS);
706 for(;anIter.More();anIter.Next()) {
708 //DbgTools::DisplayShape(anIter.NewShape(), F, Quantity_NOC_RED);
710 if (anIter.NewShape().IsSame(S)) {
711 isIn = Standard_True;
715 if (!isIn) if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
716 // if (!TNaming_Tool::NamedShape(S,F).IsNull()) NS = TNaming_Tool::NamedShape(S,F);
719 if (Neighbourg.IsEmpty()) {
720 // Recherche du vrai context. (Research of context truth)
721 Handle(TNaming_NamedShape) GenS = TNaming_Tool::NamedShape(S,NS->Label());
723 if (GenS.IsNull()) return Standard_False;
725 TDF_Label Father = (GenS->Label()).Father();
726 Father.FindAttribute(TNaming_NamedShape::GetID(),GenS);
727 TopoDS_Shape GoodContext = TNaming_Tool::GetShape(GenS);
728 Localizer.FindNeighbourg (GoodContext,S,Neighbourg);
732 if (Neighbourg.IsEmpty()) {
734 cout <<"FindNeighbourg: impossible"<<endl;
739 Write(Neighbourg, "Neighbourgs");
742 //cout <<"Filter: Lev = " << aLev << endl;
744 if(aLev > 3) return 0;
745 #ifdef ALLOW_CHILD_NBS
746 Handle(TNaming_Naming) aFNaming;
747 TopoDS_Shape aFatherCandSh;
748 F.FindAttribute(TNaming_Naming::GetID(), aFNaming);
749 if(!aFNaming.IsNull()) {
750 const TNaming_Name& aName = aFNaming->GetName();
751 if (aName.Type() == TNaming_FILTERBYNEIGHBOURGS) {
752 aFatherCandSh = aName.Arguments().First()->Get();
755 if(S.ShapeType() == TopAbs_EDGE && aFatherCandSh.IsNull()) {
756 //check the applicability
757 if(!NS.IsNull() && !NS->Get().IsNull() && NS->Get().ShapeType() == TopAbs_COMPOUND)
758 if(IsMultipleCase(S, Context, Neighbourg)) {
759 //cout << "Filter: ==> MultipleCase!" << endl;
760 NS->Label().FindAttribute(TNaming_Naming::GetID(), aFNaming);
761 if(!aFNaming.IsNull()) {
762 TNaming_Name& aName = aFNaming->ChangeName();
763 if (aName.Type() == TNaming_INTERSECTION) {
764 Standard_Integer ij(1);
765 TNaming_ListIteratorOfListOfNamedShape itA(aName.Arguments());
766 for (; itA.More(); itA.Next(), ij++) {
767 const TopoDS_Shape& aFace = TNaming_Tool::CurrentShape(itA.Value());
769 Write(aFace, "First_Face.brep");
770 cout <<"Selection TS = " << S.TShape()->This() <<endl;
772 Standard_Integer i(1), indxW(0),indxE(0),nbW(0),nbE(0), indxF(0);
773 Standard_Boolean isFound(Standard_False);
774 TopoDS_Iterator it(aFace);
775 for (;it.More();it.Next(),i++) {
778 Write(it.Value(), "First_Wire.brep");
781 Standard_Integer j(1);
782 TopoDS_Iterator it2(it.Value());
783 for (;it2.More();it2.Next(),j++) {
786 Write(it2.Value(), "First_Wire.brep");
787 cout <<"Edge TS = " << it2.Value().TShape()->This() <<endl;
789 if(S.IsEqual(it2.Value())) {
793 isFound = Standard_True;
799 Standard_Integer Index = indxE & 0x000000FF;
800 Index = Index | (nbE << 8);
801 Index = Index | (indxW << 16);
802 Index = Index | (nbW << 20);
803 Index = Index | (indxF << 24);
805 //------------------------------
806 // Compute the TNaming_NamedShape
807 //------------------------------
808 aFNaming->Regenerate(MDF.ChangeValid());
809 aFNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
810 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
811 Handle (TNaming_NamedShape) Stop = NextModif(Until);
812 if (Compare (NS,MDF,Stop,S)) return 1;
823 //-----------------------------------------------------
824 // Construction function de naming. et insertion sous F
825 //-----------------------------------------------------
826 Handle (TNaming_Naming) NF = TNaming_Naming::Insert (F);
828 Handle (TNaming_NamedShape) Until = TNaming_Tool::NamedShape(Context,NS->Label());
829 Handle (TNaming_NamedShape) Stop = NextModif(Until);
830 TNaming_Name& theName = NF->ChangeName();
831 theName.ShapeType(S.ShapeType());
833 theName.Type(TNaming_FILTERBYNEIGHBOURGS);
835 theName.StopNamedShape (Until);
837 cout << "FilterByNBS: ";
838 Print_Entry(NF->Label());
840 //---------------------
841 // Naming des voisins.
842 //---------------------
844 TopTools_MapIteratorOfMapOfShape itN(Neighbourg);
845 for (; itN.More(); itN.Next()) {
846 #ifdef ALLOW_CHILD_NBS
847 const TopoDS_Shape& aS = itN.Key();
848 Handle (TNaming_NamedShape) aNS =
849 BuildName(NF->Label(), MDF, aS, Context, Stop, 1);
851 const TopoDS_Shape& aS2 = aNS->Get();
853 cout << "Shape arg type = " << aS.ShapeType() <<" TSH = " << aS.TShape()->This()<<endl;
855 cout << "Build shape type = " << aS2.ShapeType() <<" TSH = " << aS2.TShape()->This()<<endl;
858 const TopoDS_Shape aSNS = aNS->Get(); //allow child level
859 Standard_Boolean allowChild(Standard_True);
860 if(!aSNS.IsNull() && aSNS.ShapeType() == TopAbs_COMPOUND && !aFatherCandSh.IsNull())
861 allowChild = !IsContSame(aFatherCandSh, aSNS);
862 if(allowChild && !aSNS.IsNull() && aS.ShapeType() != aSNS.ShapeType() &&
863 aSNS.ShapeType() == TopAbs_COMPOUND)
866 cout <<"Father label = ";
867 Print_Entry(aNS->Label().Father());
868 Write(aS,"SelectionS.brep");
869 Write(aSNS,"SelectionSNS.brep");
871 Handle(TNaming_Naming) aNaming;
872 Standard_Boolean StandardFilter(Standard_True);
873 aNS->FindAttribute(TNaming_Naming::GetID(), aNaming);
874 if(!aNaming.IsNull()) {
875 const TNaming_Name& aName = aNaming->GetName();
876 if (aName.Type() == TNaming_GENERATION)
877 StandardFilter = Standard_False;
879 if (!Compare (aNS,MDF,Stop,aS)) {
880 TNaming_Localizer aLocalizer;
881 Filter (NF->Label(), MDF,aS,Context, aLocalizer,aNS, aLev);
887 theName.Append(BuildName(NF->Label(), MDF, itN.Key(), Context, Stop, 1));
890 //------------------------------
891 // Compute the TNaming_NamedShape
892 //------------------------------
893 NF->Regenerate(MDF.ChangeValid());
894 NF->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
899 if (Compare (NS,MDF,Stop,S)) return 1;
901 cout <<"TNaming_Naming::Name Filter insufficient"<<endl;
907 //=======================================================================
908 //function : BuildNameInNS
909 //purpose : Calls BuildName method, but with new context and new stop shape.
910 // : Context is searched at the father label of the "Context" label :
911 // : old shapes from the NamedShape at the defined father label.
912 // : If it's impossible, then "S" set as context.
913 // : If "S" is in new context, then stop shape is named shape,
914 // : which belongs to the father label of the "Context" named shape.
915 // : For example, face (F2) of prism (P) is generated from the edge (E)
916 // : of primitive face (F1) of box (B). F2 is named as GENERATION from E.
917 // : Naming of E is done with help BuildNameInNS function:
918 // : with context B and stop shape P.
919 //=======================================================================
920 static Handle(TNaming_NamedShape) BuildNameInNS (const TDF_Label& F,
922 const TopoDS_Shape& S,
923 const Handle(TNaming_NamedShape)& Context,
924 const Handle(TNaming_NamedShape)& Stop,
925 const Standard_Boolean Geometry)
928 // il faut determiner un nouveau context et un nouveau Stop.
929 // it is necessary to determine new a context and a new Stop
931 Handle(TNaming_NamedShape) NewStop = Stop;
933 TNaming_Localizer::FindShapeContext (Context,S,SC);
936 // <Context> is Ident.NamedShapeOfGeneration() ==
937 TDF_Label Father = Context->Label().Father();
938 Father.FindAttribute(TNaming_NamedShape::GetID(),NewStop);
941 {cout <<" Stop NS : "; Print_Entry( Stop->Label());}
942 if(!NewStop.IsNull())
943 {cout <<" NewStop : "; Print_Entry( NewStop->Label());}
944 cout <<"ContextLabel: "; Print_Entry( Context->Label());
945 cout <<"Father : "; Print_Entry( Father);
950 cout <<"BuildNameInNS:: NewStop shape is NULL" << endl;
952 return BuildName (F,MDF,S,SC,NewStop,Geometry);
955 //=======================================================================
958 //=======================================================================
960 static Handle(TNaming_NamedShape) BuildName (const TDF_Label& F,
962 const TopoDS_Shape& Selection,
963 const TopoDS_Shape& Context,
964 const Handle(TNaming_NamedShape)& Stop,
965 const Standard_Boolean Geom)
970 // Create an identifier
971 Standard_Boolean OnlyOne = !Geom;
972 Standard_Boolean IsGeneration = Standard_False;
974 cout <<"BuildName: F => ";
976 cout <<" Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
977 Write(Selection, "BName_Selection.brep");
978 Write(Context, "BName_Context.brep");
980 TNaming_Identifier Ident(F, Selection, Context,OnlyOne);
982 Handle (TNaming_Naming) Naming;
983 Handle (TNaming_NamedShape) NS;
985 if (!Ident.IsDone()) {
986 return BuildNS (F,Selection, TNaming_UNKNOWN);
988 if (Ident.IsFeature() && Stop.IsNull()) {
992 if (!OnlyOne) return Ident.FeatureArg();
993 else NS = Ident.FeatureArg();
996 //---------------------------------------------
997 // Construction de la fonction d identification.
998 //---------------------------------------------
999 //Standard_Boolean NotOnlyOne = 0;
1001 Naming = TNaming_Naming::Insert(F);
1003 TNaming_Name& theName = Naming->ChangeName();
1004 theName.ShapeType(Selection.ShapeType());
1005 theName.Shape(Selection);
1006 theName.Type(Ident.Type());
1008 cout <<"BuildName: Inserted Naming Att at ";
1009 Print_Entry(Naming->Label());
1010 cout <<" NameType = " << theName.Type() <<endl;
1012 if (Ident.IsFeature()) {
1013 theName.Append(Ident.FeatureArg());
1015 if (theName.Type() == TNaming_GENERATION) {
1016 theName.Append(Ident.NamedShapeOfGeneration());
1017 IsGeneration = Standard_True;
1019 if (theName.Type() == TNaming_CONSTSHAPE) {
1020 theName.Index(FindIndex(Ident.FeatureArg(),Selection));
1022 //------------------------------------
1023 // Renseignement du NamedShape d arret.
1024 //------------------------------------
1025 theName.StopNamedShape (Stop);
1027 if(!Stop.IsNull()) {
1028 TCollection_AsciiString Es;
1029 TDF_Tool::Entry(Stop->Label(), Es);
1030 cout <<"StopNS at Label = "<< Es << endl;
1033 //---------------------------------
1034 // Identification des arguments.
1035 //---------------------------------
1037 for (Ident.InitArgs(); Ident.MoreArgs(); Ident.NextArg()) {
1038 if (Ident.ArgIsFeature()) {
1039 theName.Append(Ident.FeatureArg());
1041 if(!Ident.FeatureArg().IsNull()) {
1042 TCollection_AsciiString E;
1043 TDF_Tool::Entry(Ident.FeatureArg()->Label(), E);
1044 cout <<"Added argument NS from Label = "<< E << endl;
1050 cout <<"BuildName: NameType = " <<theName.Type() << " NS ";
1051 Print_Entry(Naming->Label());
1052 cout <<"Ident.ShapeArg() type = " << Ident.ShapeArg().ShapeType() << " TS = " << Ident.ShapeArg().TShape()->This() << endl;
1053 Write(Ident.ShapeArg(), "BName_ShapeArg.brep");
1055 if (theName.Type() == TNaming_GENERATION)
1056 theName.Append(BuildNameInNS(Naming->Label(),MDF,Ident.ShapeArg(),Ident.NamedShapeOfGeneration(),Stop,Geom));
1058 theName.Append(BuildName(Naming->Label(),MDF,Ident.ShapeArg(),Context,Stop,Geom));
1062 //------------------------
1063 // Reconstruction of Name
1064 //------------------------
1065 Naming->Regenerate(MDF.ChangeValid());
1067 TCollection_AsciiString E2;
1068 TDF_Tool::Entry(Naming->Label(), E2);
1069 cout <<"Regenerated Naming Att at Label = "<< E2 << endl;
1071 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1072 if(NS.IsNull()) return NS;
1073 if (MDF.WithValid()) MDF.Valid(NS->Label());
1076 TCollection_AsciiString E;
1077 TDF_Tool::Entry(NS->Label(), E);
1078 cout <<"Regenerated NS at Label = "<< E << endl;
1084 //-------------------------------------------------
1085 // Filtre par les voisins
1086 // pour construire le nom correspondant a S.
1087 //-------------------------------------------------
1090 if(NS.IsNull()) return NS;
1093 TNaming_Localizer Localizer;
1094 TNaming_Iterator itNS(NS);
1102 Standard_Boolean StandardFilter = !IsGeneration;
1104 if (!CompareInGeneration (NS,Selection)) {
1106 TopoDS_Shape NewContext;
1107 Handle(TNaming_NamedShape) NewStop;
1108 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1109 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1111 } else if (Ident.Type() == TNaming_MODIFUNTIL ||
1112 (Ident.Type() == TNaming_INTERSECTION && Naming->ChangeName().Arguments().Extent() == 1)) {
1114 cout <<"BuildName(CompareInModification): NameType = " <<Ident.Type() << " NS ";
1115 Print_Entry(Ident.Type() == TNaming_MODIFUNTIL ? NS->Label() : Naming->ChangeName().Arguments().First()->Label());
1116 cout <<"Selection type = " << Selection.ShapeType() << " TS = " << Selection.TShape()->This() << endl;
1118 Handle(TNaming_NamedShape) NewNS =
1119 CompareInModification(Ident.Type() == TNaming_MODIFUNTIL ? NS : Naming->ChangeName().Arguments().First(), Selection);
1120 if (!NewNS.IsNull()) { // there is need to describe name in detail: modification with type 1:n in the same label
1121 StandardFilter = Standard_False;
1122 if (Ident.IsFeature()) { // for MODIFUNTIL: change it to the GENERATION
1123 Naming = TNaming_Naming::Insert(F);
1124 TNaming_Name& theName = Naming->ChangeName();
1125 theName.ShapeType(Selection.ShapeType());
1126 theName.Shape(Selection); //szy 21.10.03
1127 theName.Type(TNaming_GENERATION);
1128 theName.Append(TNaming_Tool::NamedShape(Selection,F));
1129 theName.Append(NewNS);
1130 Naming->Regenerate(MDF.ChangeValid());
1131 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1134 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1137 if (StandardFilter) if (!Compare (NS,MDF,Stop,Selection)) {
1138 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1144 if (!CompareInGeneration (NS,Selection)) {
1145 TopoDS_Shape NewContext;
1146 Handle(TNaming_NamedShape) NewStop;
1147 FindNewShapeInFather (Ident.NamedShapeOfGeneration(),NewContext);
1148 Filter (F,MDF,Selection,NewContext,Localizer,NS,0);
1152 if (!Compare (NS,MDF,Stop,Selection))
1153 Filter (F,MDF,Selection,Context,Localizer,NS,0);
1160 if (MDF.WithValid()) MDF.Valid(NS->Label());
1163 TCollection_AsciiString E;
1164 TDF_Tool::Entry(NS->Label(), E);
1165 cout <<"Returned NS from Label = "<< E << endl;
1171 //=======================================================================
1172 //function : Validate
1174 //=======================================================================
1176 static void Validate(TNaming_Scope& MDF,
1177 TNaming_OldShapeIterator& it)
1179 MDF.Valid(it.Label());
1180 MDF.ValidChildren(it.Label());
1182 TNaming_OldShapeIterator it2(it);
1183 for (; it2.More(); it2.Next()) {
1188 //=======================================================================
1189 //function : UnValidate
1191 //=======================================================================
1193 static void UnValidate(TNaming_Scope& MDF,
1194 TNaming_NewShapeIterator& it)
1196 MDF.Unvalid(it.Label());
1197 MDF.UnvalidChildren(it.Label());
1199 TNaming_NewShapeIterator it2(it);
1200 for (; it2.More(); it2.Next()) {
1201 UnValidate (MDF,it2);
1205 //=======================================================================
1206 //function : BuildScope
1207 //purpose : adds to the MDF the label of <Context> NamedShape,
1208 // : its children, all its oldShapes and its children.
1209 // : unvalidates all newShapes and it's children.
1210 // : If <Context> is null or next modification has an empty newShape
1211 // : ( this shape was deleted ), then MDF.WithValid(Standard_False)
1212 // : and nothing is added to the scope.
1213 //=======================================================================
1215 static void BuildScope (TNaming_Scope& MDF,
1216 const TopoDS_Shape& Context,
1217 const TDF_Label& Acces)
1219 if (Context.IsNull()) {
1220 MDF.WithValid(Standard_False);
1224 //----------------------------------------------------
1225 // Is context the current state
1226 //----------------------------------------------------
1227 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(Context,Acces);
1228 Handle(TNaming_NamedShape) Next = NextModif(NS); // if NS has subsequent evolution = MODIFY, return it
1229 if (Next.IsNull()) {
1230 MDF.WithValid(Standard_False);
1233 //-----------------------------
1234 // a posteriori naming
1235 //-----------------------------
1236 MDF.WithValid(Standard_True);
1237 MDF.Valid(NS->Label());
1238 MDF.ValidChildren(NS->Label());
1239 TNaming_OldShapeIterator it(Context,Acces);
1241 for (; it.More(); it.Next()) {
1245 TNaming_NewShapeIterator it2(Context,Acces);
1246 for (;it2.More(); it2.Next()) {
1247 UnValidate (MDF,it2);
1251 //=======================================================================
1252 static Standard_Boolean HasAncFace(const TopoDS_Shape& Context,
1253 const TopoDS_Shape& W, TopoDS_Shape& Face)
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;
1275 //=======================================================================
1276 //function : BuildNameWire
1277 //purpose : Names Wire
1278 //=======================================================================
1280 static Handle(TNaming_NamedShape) BuildNameWire (const TDF_Label& F,
1282 const TopoDS_Shape& Selection,
1283 const TopoDS_Shape& Context,
1284 const Handle(TNaming_NamedShape)& Stop,
1285 const Standard_Boolean Geom)
1287 Handle (TNaming_NamedShape) NS;
1288 Standard_Boolean found(Standard_False);
1289 Handle (TNaming_Naming) Naming;
1290 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1291 Naming = new TNaming_Naming ();
1292 F.AddAttribute (Naming);
1293 TNaming_Name& theName = Naming->ChangeName();
1294 theName.ShapeType(Selection.ShapeType());
1295 theName.Shape(Selection);
1298 TNaming_Name& theName = Naming->ChangeName();
1300 Standard_Boolean hasFace = HasAncFace(Context, Selection, aFace);
1301 if(Selection.ShapeType() == TopAbs_WIRE && Context.ShapeType() < Selection.ShapeType() && hasFace) {
1302 theName.Type(TNaming_WIREIN);
1303 if(Context.ShapeType() == TopAbs_FACE) {
1304 for (TopoDS_Iterator it(Context) ; it.More(); it.Next()) {
1305 if(it.Value().IsEqual(Selection)) {
1306 if (TNaming_Selector::IsIdentified (F, Context, NS, Geom)) {
1308 found = Standard_True;
1314 return BuildNS (F,Selection, TNaming_UNKNOWN);
1316 Standard_Integer indx(0), i(0);
1317 for (TopoDS_Iterator it(aFace); it.More(); it.Next()) {
1319 if(it.Value().IsEqual(Selection)) {
1320 found = Standard_True;
1321 theName.Append(BuildName (Naming->Label(),MDF,aFace,Context,Stop,Geom));
1326 const Standard_Integer num(i);
1327 indx = indx | num << 8;
1328 //cout << " final Index = " << indx <<endl;
1329 theName.Index(indx);
1331 return BuildNS (F,Selection, TNaming_UNKNOWN);
1335 theName.Type(TNaming_UNION);
1336 for (TopExp_Explorer exp(Selection,TopAbs_EDGE) ; exp.More(); exp.Next()) {
1337 if(exp.Current().IsNull()) continue;
1338 if (BRep_Tool::Degenerated(TopoDS::Edge(exp.Current()))) continue;//03.03.2010
1339 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1342 //Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1343 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1347 //=======================================================================
1348 static Standard_Boolean IsOneIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1350 Standard_Boolean found(Standard_False);
1351 if(S.IsNull() || Context.IsNull()) return found;
1352 for (TopExp_Explorer exp(Context,S.ShapeType()); exp.More(); exp.Next()) {
1353 if (exp.Current().IsEqual(S)) {
1354 found = Standard_True;
1361 //=======================================================================
1362 static Standard_Boolean IsAllIn (const TopoDS_Shape& S, const TopoDS_Shape& Context)
1365 Write(S, "IsAllIn_Sel.brep");
1367 Standard_Boolean found(Standard_False);
1368 if(S.IsNull() || Context.IsNull()) return found;
1369 Standard_Integer num1(0), num2(0);
1370 for(TopoDS_Iterator it(S);it.More();it.Next(),num1++) {
1372 cout <<"S sub-shape type = " << it.Value().ShapeType() <<endl;
1373 Write (it.Value(), "Sel_ItValue.brep");
1375 if(it.Value().ShapeType() != TopAbs_COMPOUND)
1376 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1378 cout <<"Context sub-shape type = " << exp.Current().ShapeType() <<endl;
1379 Write(exp.Current(), "Contex_Curnt.brep");
1381 if (exp.Current().IsEqual(it.Value())) {
1386 Standard_Boolean isAll = IsAllIn(it.Value(), Context);
1392 found = Standard_True;
1395 cout <<"Compound case : selected num1 = " << num1 << " context contains num2 = " << num2 << endl;
1399 //=======================================================================
1400 //function : RepeatabilityInContext
1402 //=======================================================================
1403 static Standard_Integer RepeatabilityInContext(const TopoDS_Shape& Selection,
1404 const TopoDS_Shape& Context)
1406 Standard_Integer aNum(0);
1407 if (!Context.IsNull() && !Selection.IsNull()) {
1408 // Write(Selection, "Repeat_Selection.brep");
1409 // Write(Context, "Repeat_Context.brep");
1410 if (Context.ShapeType() < Selection.ShapeType()) {
1411 for (TopExp_Explorer exp(Context,Selection.ShapeType()); exp.More(); exp.Next()) {
1412 if (exp.Current().IsSame(Selection))
1416 else if(Selection.ShapeType() == TopAbs_COMPOUND) {
1417 TopoDS_Iterator it(Selection);
1418 for(;it.More();it.Next()) {
1419 Standard_Integer n(0);
1420 for (TopExp_Explorer exp(Context,it.Value().ShapeType()); exp.More(); exp.Next()) {
1421 if (exp.Current().IsSame(it.Value())) {
1425 if(n > aNum) aNum = n;
1430 cout <<"RepeatabilityInContext: = " <<aNum <<endl;
1434 //=======================================================================
1435 //function : BuildAggregationNam
1437 //=======================================================================
1438 static void BuildAggregationName (const TDF_Label& F,
1440 const TopoDS_Shape& S,
1441 const TopoDS_Shape& Context,
1442 const Handle(TNaming_NamedShape)& Stop,
1443 const Standard_Boolean Geom)
1445 const Standard_Boolean found2 = IsAllIn(S, Context);
1446 Handle (TNaming_Naming) Naming;
1447 if(!F.FindAttribute(TNaming_Naming::GetID(), Naming)) {
1448 Naming = new TNaming_Naming ();
1449 F.AddAttribute (Naming);
1450 TNaming_Name& theName = Naming->ChangeName();
1451 theName.ShapeType(S.ShapeType());
1455 cout <<"BuildAggregationName ==> ";
1456 Print_Entry(Naming->Label());
1458 TNaming_Name& theName = Naming->ChangeName();
1459 for (TopoDS_Iterator itc(S) ; itc.More(); itc.Next()) {
1460 const TopoDS_Shape& aS = itc.Value();
1461 if ((aS.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(aS,Naming->Label()).IsNull()) ||
1462 aS.ShapeType() == TopAbs_FACE ||
1463 aS.ShapeType() == TopAbs_EDGE ||
1464 aS.ShapeType() == TopAbs_VERTEX ) {
1465 theName.Append(BuildName (F, MDF, aS,Context,Stop,Geom));
1466 } else { // ==> union of union || union of wires
1467 TopAbs_ShapeEnum atomTyp;
1468 switch (aS.ShapeType())
1472 atomTyp = TopAbs_FACE;
1475 atomTyp = TopAbs_EDGE;
1478 atomTyp = TopAbs_SHAPE;
1481 Handle(TNaming_NamedShape) aNS;
1482 Handle (TNaming_Naming) aNaming = TNaming_Naming::Insert(F);
1483 TNaming_Name& aName = aNaming->ChangeName();
1484 aName.ShapeType(aS.ShapeType());
1486 aName.Type(TNaming_UNION);
1488 if (atomTyp != TopAbs_SHAPE) {
1489 if(aS.ShapeType() == TopAbs_WIRE) {
1490 aNS = BuildNameWire (aNaming->Label(), MDF, aS, Context,Stop,Geom);
1493 for (TopExp_Explorer exp(aS,atomTyp) ; exp.More(); exp.Next()) {
1494 aName.Append(BuildName (aNaming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1499 cout << "atomic type is NOT defined ... ==> Aggregation" <<endl;
1501 BuildAggregationName(aNaming->Label(),MDF, aS, Context,Stop,Geom);
1504 aNS = TNaming_Tool::NamedShape(Context, F);
1506 aNaming->ChangeName().ContextLabel(aNS->Label());
1509 aNaming->GetName().Solve(aNaming->Label(),MDF.GetValid());
1510 if(aNaming->Label().FindAttribute(TNaming_NamedShape::GetID(),aNS))
1511 if (!Geom && TestSolution(MDF,aNS,aS)) {
1512 theName.Append(aNS);
1519 //=======================================================================
1522 //=======================================================================
1524 Handle(TNaming_NamedShape) TNaming_Naming::Name (const TDF_Label& F,
1525 const TopoDS_Shape& S,
1526 const TopoDS_Shape& Context,
1527 const Standard_Boolean Geom,
1528 const Standard_Boolean KeepOrientation,
1529 const Standard_Boolean BNProblem)
1532 Handle(TNaming_NamedShape) NS;
1533 if (KeepOrientation) {
1534 #ifdef MDTV_DEB_INNS
1535 cout <<"KeepOR = 1: "; Print_Entry(F);
1537 Standard_Integer aNum = RepeatabilityInContext(S, Context);
1539 Standard_Boolean aBNproblem = (BNProblem) ? (aNum /*== 1*/ && S != Context) : Standard_False;
1541 if (aNum > 1 || aBNproblem) {
1542 TopoDS_Shape UC = TNaming::FindUniqueContext(S, Context);
1543 Handle(TopTools_HArray1OfShape) Arr;
1544 if (UC.IsNull() && S.ShapeType() == TopAbs_COMPOUND) {
1545 UC = TNaming::FindUniqueContextSet(S, Context, Arr);
1547 Write(UC, "UniqueContextSet.brep");
1548 Write(S, "InitialSelection.brep");
1549 if(S.ShapeType()==TopAbs_COMPOUND) {
1550 TCollection_AsciiString aNam("S_");
1551 TopoDS_Iterator it(S);
1552 for(int i=1;it.More();it.Next(),i++) {
1553 TCollection_AsciiString aName = aNam + i + ".brep";
1554 Write(it.Value(), aName.ToCString());
1560 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1561 TNaming_Name& theName = Naming->ChangeName();
1562 theName.ShapeType(S.ShapeType());
1564 theName.Type(TNaming_ORIENTATION);
1566 if (!TNaming_Selector::IsIdentified (F, S, NS, Geom))
1567 NS = TNaming_Naming::Name(Naming->Label(),S,Context,Geom,0);
1568 theName.Append (NS);
1570 cout << " Sel Label ==> "; Print_Entry(NS->Label());
1573 if(S.ShapeType() == TopAbs_EDGE && UC.ShapeType() == TopAbs_FACE) {
1574 if(RepeatabilityInContext(S, UC) == 2) { //sim. edge
1575 TopoDS_Iterator itw(UC);
1576 for(;itw.More();itw.Next()) {
1577 Standard_Boolean found(Standard_False);
1578 TopoDS_Iterator it(itw.Value());
1579 for(int i=1;it.More();it.Next(),i++) {
1580 if(it.Value().IsEqual(S)) {
1582 found = Standard_True;
1584 cout << "ORDER = " << i <<endl;
1594 if(S.ShapeType() == TopAbs_COMPOUND && Arr->Length() > 1) {
1595 // N arguments: to be optimized to avoid duplication of the same Context shape
1596 for(Standard_Integer i = Arr->Lower(); i <= Arr->Upper(); i++) {
1597 NS = TNaming_Naming::Name(Naming->Label(), Arr->Value(i), Context, Geom, 1, aBNproblem);
1598 theName.Append (NS);
1601 NS = TNaming_Naming::Name(Naming->Label(),UC,Context, Geom, 1, aBNproblem);
1602 theName.Append (NS);
1604 cout << " Cont Label ==> "; Print_Entry(NS->Label());
1609 BuildScope (MDF,Context,F);
1610 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1611 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1612 theName.ContextLabel(NS->Label());
1613 if (Geom) return NS;
1615 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1616 return BuildNS (F,S, TNaming_UNKNOWN);
1619 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1620 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1622 // Naming n is unsatisfactory
1623 return BuildNS (F,S, TNaming_UNKNOWN);
1626 if (TNaming_Selector::IsIdentified (F, S, NS, Geom))
1630 //------------------------------------------------------------
1631 // Construction du MDF tel que <Context> soit le dernier etat
1633 // Ceci pour les localisation a posteriori par exemple.
1634 //------------------------------------------------------------
1637 BuildScope (MDF,Context,F);
1638 Handle(TNaming_NamedShape) Stop;
1642 if ((S.ShapeType() == TopAbs_SOLID && !TNaming_Tool::NamedShape(S,F).IsNull()) ||
1646 if (S.ShapeType() == TopAbs_SOLID ||
1650 S.ShapeType() == TopAbs_FACE ||
1651 S.ShapeType() == TopAbs_EDGE ||
1652 S.ShapeType() == TopAbs_VERTEX ) {
1653 //---------------------------------------
1654 // Localisation de S comme element simple.
1655 //---------------------------------------
1656 Handle(TNaming_NamedShape) NS = BuildName (F,MDF,S,Context,Stop,Geom);
1657 if (Geom) return NS;
1658 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1661 //----------------------------------------------------
1662 // Localisation de S comme ensemble d elements simples.
1663 //-----------------------------------------------------
1664 Handle(TNaming_NamedShape) NS;
1665 Handle (TNaming_Naming) Naming = TNaming_Naming::Insert(F);
1666 TNaming_Name& theName = Naming->ChangeName();
1668 theName.ShapeType(S.ShapeType());// modified by vro 05.09.00
1670 if(S.ShapeType() != TopAbs_WIRE)
1671 theName.Type(TNaming_UNION);
1674 TopAbs_ShapeEnum atomType;
1675 switch (S.ShapeType()) {
1676 case TopAbs_COMPSOLID:
1679 atomType = TopAbs_FACE;
1682 atomType = TopAbs_EDGE;
1685 atomType = TopAbs_SHAPE;
1687 Standard_Boolean found(Standard_False);
1688 if (!Context.IsNull()) {
1689 if (Context.ShapeType() < S.ShapeType())
1690 found = IsOneIn(S, Context);
1692 NS = TNaming_Tool::NamedShape(Context, F);
1694 theName.ContextLabel(NS->Label());
1697 if (atomType == TopAbs_SHAPE) {
1698 if(S.ShapeType() == TopAbs_COMPOUND) {
1699 BuildAggregationName(Naming->Label(),MDF, S, Context,Stop,Geom);
1701 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1702 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1706 if(S.ShapeType() == TopAbs_WIRE)
1707 NS = BuildNameWire (Naming->Label(), MDF, S, Context,Stop,Geom);
1709 theName.Type(TNaming_UNION);
1710 for (TopExp_Explorer exp(S,atomType) ; exp.More(); exp.Next()) {
1711 theName.Append(BuildName (Naming->Label(),MDF,exp.Current(),Context,Stop,Geom));
1716 for (TopoDS_Iterator it(S) ; it.More(); it.Next()) {
1717 theName.Append(BuildName (Naming->Label(),MDF,it.Value(),Context,Stop,Geom));
1722 Naming->GetName().Solve(Naming->Label(),MDF.GetValid());
1723 Naming->Label().FindAttribute(TNaming_NamedShape::GetID(),NS);
1724 if (Geom) return NS;
1727 if(NS.IsNull()) return BuildNS (F,S, TNaming_UNKNOWN);
1730 if (!Geom && TestSolution(MDF,NS,S)) return NS;
1733 cout <<" %%% WARNING: TNaming_Naming::Name: FAILED"<<endl;
1735 // Naming n is not satisfactory
1736 return BuildNS (F,S, TNaming_UNKNOWN);
1740 //=======================================================================
1741 //function : TNaming_Naming
1743 //=======================================================================
1745 TNaming_Naming::TNaming_Naming() {}
1747 //=======================================================================
1750 //=======================================================================
1752 const Standard_GUID& TNaming_Naming::ID () const
1758 //=======================================================================
1759 //function : IsDefined
1761 //=======================================================================
1763 Standard_Boolean TNaming_Naming::IsDefined() const
1765 return (myName.Type() != TNaming_UNKNOWN);
1768 //=======================================================================
1769 //function : GetName
1771 //=======================================================================
1773 const TNaming_Name& TNaming_Naming::GetName() const
1778 //=======================================================================
1779 //function : ChangeName
1781 //=======================================================================
1783 TNaming_Name& TNaming_Naming::ChangeName()
1788 //=======================================================================
1789 //function : Regenerate
1790 //purpose : idem designer
1791 //=======================================================================
1793 Standard_Boolean TNaming_Naming::Regenerate (TDF_LabelMap& MDF)
1796 return myName.Solve(Label(),MDF);
1800 //=======================================================================
1801 //function : NewEmpty
1803 //=======================================================================
1805 Handle(TDF_Attribute) TNaming_Naming::NewEmpty () const
1807 return new TNaming_Naming ();
1811 //=======================================================================
1812 //function : Restore
1814 //=======================================================================
1816 void TNaming_Naming::Restore(const Handle(TDF_Attribute)& other)
1818 Handle(TNaming_Naming) OtherNaming = Handle(TNaming_Naming)::DownCast(other);
1819 myName = OtherNaming->ChangeName();
1822 //=======================================================================
1825 //=======================================================================
1827 void TNaming_Naming::Paste (const Handle(TDF_Attribute)& into,
1828 const Handle(TDF_RelocationTable)& RT) const
1830 Handle(TNaming_Naming) NewNaming = Handle(TNaming_Naming)::DownCast(into);
1831 myName.Paste(NewNaming->ChangeName(),RT);
1834 //=======================================================================
1835 //function : References
1836 //purpose : Redefined from TDF_Attribute
1837 //=======================================================================
1839 void TNaming_Naming::References(const Handle(TDF_DataSet)& DataSet) const
1841 // Iteration on NamedShape of the name
1842 TNaming_ListIteratorOfListOfNamedShape it(myName.Arguments());
1843 for (;it.More();it.Next()) DataSet->AddAttribute(it.Value());
1844 if (!myName.StopNamedShape().IsNull()) DataSet->AddAttribute(myName.StopNamedShape());
1846 //=======================================================================
1849 //=======================================================================
1851 Standard_OStream& TNaming_Naming::Dump (Standard_OStream& anOS) const
1853 anOS << "TNaming_Naming";
1858 //=======================================================================
1859 //function :ExtendedDump
1861 //=======================================================================
1863 void TNaming_Naming::ExtendedDump(Standard_OStream& anOS,
1864 const TDF_IDFilter& /*aFilter*/,
1865 TDF_AttributeIndexedMap& /*aMap*/) const
1867 anOS << "TNaming_Naming ExtendedDump ";
1868 //anOS<<"myContext: #" <<aMap.Add(myContext)<<endl;