1 // Created on: 1997-06-11
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.
18 #include <TDF_Label.hxx>
19 #include <TNaming_DataMapOfShapeShapesSet.hxx>
20 #include <TNaming_Evolution.hxx>
21 #include <TNaming_Identifier.hxx>
22 #include <TNaming_Iterator.hxx>
23 #include <TNaming_IteratorOnShapesSet.hxx>
24 #include <TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape.hxx>
25 #include <TNaming_ListIteratorOfListOfMapOfShape.hxx>
26 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
27 #include <TNaming_ListOfNamedShape.hxx>
28 #include <TNaming_Localizer.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <TNaming_NewShapeIterator.hxx>
31 #include <TNaming_OldShapeIterator.hxx>
32 #include <TNaming_ShapesSet.hxx>
33 #include <TNaming_Tool.hxx>
34 #include <TNaming_UsedShapes.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_MapIteratorOfMapOfShape.hxx>
47 #include <TDF_Tool.hxx>
48 #include <TDF_MapIteratorOfLabelMap.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <BRepTools.hxx>
52 void LPrintEntry(const TDF_Label& label)
54 TCollection_AsciiString entry;
55 TDF_Tool::Entry(label, entry);
56 cout << "LabelEntry = "<< entry << endl;
58 static void LWrite(const TopoDS_Shape& shape,
59 const Standard_CString filename)
62 if(strlen(filename) > 256) return;
64 strcpy_s (buf, filename);
66 strcpy (buf, filename);
76 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
77 save << "DBRep_DrawableShape" << endl << endl;
78 if(!shape.IsNull()) BRepTools::Write(shape, save);
82 //=======================================================================
83 static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
84 const Standard_CString filename)
86 if(!NS.IsNull() && !NS->IsEmpty() ) {
87 TCollection_AsciiString aNam (filename);
88 TCollection_AsciiString oldS ("_Old");
89 TCollection_AsciiString newS ("_New_");
90 Standard_Integer i(0);
91 TNaming_Iterator it(NS);
92 for(;it.More(); it.Next(),i++) {
93 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
94 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
95 const TopoDS_Shape& oldShape = it.OldShape();
96 const TopoDS_Shape& newShape = it.NewShape();
97 if(!oldShape.IsNull())
98 LWrite ( oldShape, aName1.ToCString());
99 if(!newShape.IsNull())
100 LWrite ( newShape, aName2.ToCString());
106 //=======================================================================
107 //function : FindFeatureInAncestors
108 //purpose : Cherche les ancetres de S qui sont sous des labels
109 //=======================================================================
111 void TNaming_Localizer::FindFeaturesInAncestors
112 (const TopoDS_Shape& S,
113 const TopoDS_Shape& Context,
114 TopTools_MapOfShape& AncInFeature)
117 LWrite(S, "Localizer_S.brep");
118 LWrite(Context, "Localizer_Context.brep");
121 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
123 if (Anc.Contains(S)) {
125 cout <<"Localizer: S in ancestor" <<endl;
127 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
128 TopTools_ListIteratorOfListOfShape itL(L);
129 for (; itL.More(); itL.Next()) {
130 const TopoDS_Shape& AS = itL.Value();
132 LWrite(AS, "Localizer_AS.brep");
134 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
136 // if (TNaming_Tool::HasLabel(myUS,AS)) {
137 AncInFeature.Add(AS);
139 else if (AS.ShapeType() > TopAbs_FACE) {
140 FindFeaturesInAncestors (AS, Context, AncInFeature);
144 cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<endl;
152 cout <<" TNaming_Localization : S n est pas dans le solide"<<endl;//S is not in the solid
157 //=======================================================================
158 //function : SubShapes
160 //=======================================================================
162 const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
163 const TopAbs_ShapeEnum TS)
166 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
167 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
168 // Standard_Boolean Found = Standard_False;
169 for (; itS.More(); itS.Next(),itSS.Next()) {
170 if (In.IsSame(itS.Value())) {
171 TopTools_MapOfShape& SubShapes = itSS.Value();
172 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
173 const TopoDS_Shape& SS = exp.Current();
174 if (SubShapes.Contains(SS)) {
183 TopTools_MapOfShape emptyMap;
184 mySubShapes.Prepend(emptyMap);
185 myShapeWithSubShapes.Prepend(In);
187 TopTools_MapOfShape& SubShapes = mySubShapes.First();
188 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
189 const TopoDS_Shape& SS = exp.Current();
190 if (SubShapes.Contains(SS)) {
199 //=======================================================================
200 //function : Ancestors
202 //=======================================================================
204 const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
205 (const TopoDS_Shape& In,
206 const TopAbs_ShapeEnum TS)
208 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
209 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
210 // Standard_Boolean Found = Standard_False;
211 for (; itS.More(); itS.Next(),itA.Next()) {
212 if (In.IsSame(itS.Value())) {
213 //-----------------------
214 // Ancetres existent.
215 //-----------------------
216 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
218 TopExp_Explorer exp(In,TS);
220 if (!exp.More()) cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
222 const TopoDS_Shape& SS = exp.Current();
224 if (Anc.Contains(SS)) {
228 //----------------------------
229 // Completion des ancetres.
230 //----------------------------
231 TopAbs_ShapeEnum TA = TopAbs_FACE;
232 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
233 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
234 if (TA >= In.ShapeType()) {
235 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
239 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
246 //-----------------------------------
247 // Construction des ancetres
248 //-----------------------------------
249 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
250 myShapeWithAncestors.Prepend(In);
251 myAncestors .Prepend(emptyAnc);
253 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
255 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
256 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
257 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
258 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
259 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
263 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
266 return myAncestors.First();
269 //=======================================================================
272 //=======================================================================
274 Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
275 const Handle(TNaming_NamedShape)& NS)
277 TNaming_Iterator itLab(NS);
278 for (; itLab.More(); itLab.Next()) {
279 if (itLab.OldShape().IsSame(S)) {
280 return Standard_False;
282 if (itLab.NewShape().IsSame(S)) {
283 return Standard_True;
287 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
289 return Standard_False;
293 //=======================================================================
296 //=======================================================================
298 void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
299 const TDF_Label& Lab,
300 const TNaming_Evolution Evol,
301 TopTools_ListOfShape& LBS,
302 TNaming_ListOfNamedShape& LBNS)
304 // Standard_Integer TrDef;
306 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
309 //-----------------------------------------------------------
310 // Pas d'ascendants => Recherche et exploration du contenant
311 //----------------------------------------------------------
312 const TDF_Label& Father = Lab.Father();
313 TNaming_Iterator itLab(Father);
315 Sol = itLab.OldShape();
316 //-------------------------------------------
317 // Recherche des ancetres dans des features.
318 //-------------------------------------------
320 TopTools_MapOfShape AncInFeature;
321 FindFeaturesInAncestors (S, Sol, AncInFeature);
322 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
323 for ( ; itF.More(); itF.Next()) {
324 const TopoDS_Shape& AncOfS = itF.Key();
326 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
331 for ( ; it.More(); it.Next()) {
332 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
333 if (it.NamedShape()->Evolution() == Evol) {
334 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
336 LBS.Append (it.Shape());
337 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
341 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
349 //=======================================================================
350 //function : Backward
352 //=======================================================================
354 void TNaming_Localizer::Backward (const TopoDS_Shape& S,
355 TDF_LabelMap& Primitives,
356 TopTools_MapOfShape& ValidShapes)
358 Standard_Integer PrevTrans = myCurTrans - 1;
359 Standard_Integer TrDef;
360 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
361 TNaming_Evolution Evol = Evolution(Lab);
364 TopTools_ListOfShape LBS;
367 GoBack(S,Lab,LBS,LBLab);
370 TopTools_ListIteratorOfListOfShape itLBS (LBS);
371 TDF_ListIteratorOfLabelList itLBLab(LBLab);
376 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
377 const TopoDS_Shape& OS = itLBS.Value();
378 const TDF_Label& LabOS = itLBLab.Value();
380 Evol = Evolution(LabOS);
382 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
383 //---------------------------------------------------------
384 // Le Shape est valid dans la transaction myCurTrans => STOP
385 //---------------------------------------------------------
388 else if (Evol == TNaming_PRIMITIVE) {
389 Primitives.Add(LabOS);
391 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
392 //--------------------------------------------------------------
393 // Passage par une generation
394 // le shape dans myCurTrans descendra d un element de cet attribut.
395 // Localisation de OS dans la transaction courrante.
396 // les shapes obtenus seront des antecedants du shape cherche.
397 //--------------------------------------------------------------
399 // A faire seulememt si OS est un newShape dans LabOS.
400 TNaming_ShapesSet ResGen;
402 TDF_Label Father = LabOS.Father();
403 TNaming_Iterator itLab(Father,PrevTrans);
404 for (; itLab.More(); itLab.Next()) {
405 PrevIn= itLab.OldShape();
408 Localize(PrevIn,LabOS,OS,ResGen);
409 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
410 ValidShapes.Add(itLoc.Value());
413 else if (Evol == TNaming_SELECTED) {
415 TNaming_ShapesSet ResSel;
416 TopoDS_Shape PrevIn,CurIn;
417 // FindIn (LabOS,PrevIn,CurIn);
418 Localize(PrevIn,CurIn,OS,ResSel);
419 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
420 ValidShapes.Add(itLoc.Value());
424 Backward(itLBS.Value(),Primitives,ValidShapes);
430 //=======================================================================
431 //function : NamedShape
433 //=======================================================================
435 Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
437 Handle(TNaming_NamedShape) NS;
438 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
442 //=======================================================================
443 //function : Backward
445 //=======================================================================
447 void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
448 const TopoDS_Shape& S,
449 TNaming_MapOfNamedShape& Primitives,
450 TopTools_MapOfShape& Shapes)
452 TNaming_Evolution Evol = NS->Evolution();
453 TDF_Label LabNS = NS->Label();
455 TopTools_ListOfShape LBS;
456 TNaming_ListOfNamedShape LBNS;
458 GoBack(S,LabNS,Evol,LBS,LBNS);
461 TopTools_ListIteratorOfListOfShape itLBS (LBS);
462 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
467 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
468 const TopoDS_Shape& OS = itLBS.Value();
469 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
470 Evol = NOS->Evolution();
471 if (Evol == TNaming_PRIMITIVE) {
474 else if (Evol == TNaming_GENERATED) {
478 Backward(NOS, itLBS.Value(),Primitives,Shapes);
483 //=======================================================================
484 //function : ValidCandidat
486 //=======================================================================
489 /*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
490 const TopTools_MapOfShape& ShapeOfSol,
491 TopAbs_ShapeEnum TargetType,
492 TNaming_ShapesSet& Res)
494 Standard_Boolean Valid = Standard_False;
496 if (ShapeOfSol.Contains(S)) {
497 if (S.ShapeType() == TargetType) {
499 return Standard_True;
501 else if (S.ShapeType() < TargetType) {
502 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
503 const TopoDS_Shape& SS = exp.Current();
505 Valid = Standard_True;
514 //=======================================================================
517 //=======================================================================
519 void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
520 const TopTools_MapOfShape& Target,
521 const TopAbs_ShapeEnum TargetType,
522 TNaming_ShapesSet& Res)
525 Standard_Integer TrDef;
526 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
527 if (StoreValid (S, Target, TargetType, Res)) {
530 TNaming_Evolution Evol = Evolution(Lab);
531 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
533 for ( ; NewIt.More(); NewIt.Next()) {
534 const TopoDS_Shape& NS = NewIt.Shape();
535 GoForward ( NS, Target, TargetType, Res);
541 //=======================================================================
542 //function : FindNeighbourg
544 //=======================================================================
546 void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
547 const TopoDS_Shape& S,
548 TopTools_MapOfShape& Neighbourg)
550 if(Sol.IsNull() || S.IsNull()) return;
551 TopAbs_ShapeEnum TA = S.ShapeType();
552 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
554 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
555 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
556 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
557 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
558 // szy 30.03.10 to process case when Candidate is of type Vertex
559 // if (TA == TopAbs_VERTEX) {
561 // cout <<"construction voisins des vertex impossible"<<endl;
565 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
566 const TopoDS_Shape& SS = Exp.Current();
567 if (!Anc.Contains(SS)) {
568 //----------------------------------------------------
569 // Construction des ancetres
570 //----------------------------------------------------
574 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
575 for ( ; itL.More(); itL.Next()) {
576 if (!itL.Value().IsSame(S)) {
577 Neighbourg.Add(itL.Value());
584 //=======================================================================
585 //function : TNaming_Localizer
587 //=======================================================================
589 TNaming_Localizer::TNaming_Localizer()
594 //=======================================================================
597 //=======================================================================
599 void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
600 const Standard_Integer CurTrans)
603 myCurTrans = CurTrans;
607 //=======================================================================
610 //=======================================================================
613 /*static void Explode (TNaming_ShapesSet& Res,
615 TNaming_ShapesSet& ResGoodType)
617 TNaming_IteratorOnShapesSet it(Res);
618 for ( ; it.More(); it.Next()) {
619 const TopoDS_Shape& S = it.Value();
620 TopExp_Explorer exp(S,TS);
621 for (; exp.More(); exp.Next()) {
622 ResGoodType.Add(exp.Current());
629 //=======================================================================
630 //function : Localize
632 //=======================================================================
634 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
635 const TopoDS_Shape& CurIn ,
636 const TopoDS_Shape& S,
637 TNaming_ShapesSet& Res)
640 TDF_LabelMap Primitives;
641 TopTools_MapOfShape ValidShapes;
642 Standard_Integer PrevTrans = myCurTrans-1;
644 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
646 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
649 Standard_Integer TrDef;
650 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
651 TNaming_Evolution Evol = Evolution(Lab);
652 if (Evol == TNaming_PRIMITIVE) {
653 //------------------------
654 // Label est une primitive
655 //------------------------
657 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
660 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
661 Localize(PrevIn,Lab,S,Res);
666 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
667 //-------------------
668 // Remontee Descente.
669 //-------------------
670 Backward (S, Primitives, ValidShapes);
671 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
674 //----------------------------------------------
675 // Localisation des ancetres.
676 //----------------------------------------------
677 TopTools_MapOfShape AncInFeature;
678 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
679 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
680 Standard_Boolean First = Standard_True;
682 for ( ; itF.More(); itF.Next()) {
683 const TopoDS_Shape& AncOfS = itF.Key();
684 TNaming_ShapesSet ResAnc;
686 Localize (PrevIn, CurIn, AncOfS, ResAnc);
688 //---------------------------
689 // Res = Commun des resultats
690 //---------------------------
692 Explode (ResAnc,S.ShapeType(),Res);
696 TNaming_ShapesSet ResGoodType;
697 Explode (ResAnc,S.ShapeType(),ResGoodType);
698 Res.Filter(ResGoodType);
705 //=======================================================================
706 //function : FindGenerator
707 //purpose : Finds all generators of the <S> kept in <NS>
708 //=======================================================================
710 void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
711 const TopoDS_Shape& S,
712 TopTools_ListOfShape& theListOfGenerators)
715 Handle(TNaming_UsedShapes) US;
716 TDF_Label LabNS = NS->Label();
717 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
719 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
720 if (it.Label() == LabNS) {
721 theListOfGenerators.Append(it.Shape());
722 // break; //szy 16.10.03
728 //=======================================================================
729 //function : FindShapeContext
730 //purpose : Finds context of the shape <S>.
731 // : Looks for all oldshapes kept at father label of <NS>.
732 // : If <S> validated as subshape of one of the old shapes -
733 // : this oldshape is Context.
734 //=======================================================================
736 void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
737 const TopoDS_Shape& S,
742 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
744 TopTools_ListOfShape aList;
745 TDF_Label Father = NS->Label().Father();
746 TNaming_Iterator itLab(Father);
747 for (; itLab.More(); itLab.Next()) {
748 aList.Append(itLab.OldShape()); //szy
751 TopTools_ListIteratorOfListOfShape it(aList);
752 Standard_Boolean found = 0;
753 for(;it.More();it.Next()) {
756 LWrite(SC, "FSC_OldShape.brep");
758 if (SC.IsNull()) continue;
760 if (SC.ShapeType() < S.ShapeType()) {
761 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
762 if (exp.Current().IsSame(S)) {
765 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
776 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
779 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
781 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
784 LWriteNSOnLabel(aNS, "FSC");
786 TNaming_Iterator anIter(aNS->Label());
787 for(;anIter.More();anIter.Next()) {
788 aShape = anIter.NewShape();
789 if (!aShape.IsNull()) break;
791 if (!aShape.IsNull()) SC=aShape;
799 //=======================================================================
800 //function : Localize
802 //=======================================================================
804 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
805 const TDF_Label& InLab ,
806 const TopoDS_Shape& S,
807 TNaming_ShapesSet& Res)
810 TDF_LabelMap Primitives;
811 TopTools_MapOfShape ValidShapes;
812 Standard_Integer PrevTrans = myCurTrans - 1;
814 //---------------------------------------------
815 // Recuperation du nouveau contenant generateur.
816 //---------------------------------------------
818 TDF_Label Father = InLab.Father();
819 TNaming_Iterator itLab(Father,myCurTrans);
820 for (; itLab.More(); itLab.Next()) {
821 CurIn= itLab.OldShape();
825 Standard_Boolean First = 1;
826 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
828 for (; OldIt.More(); OldIt.Next()) {
829 if (OldIt.Label().IsEqual(InLab)) {
830 TNaming_ShapesSet RO;
831 TNaming_ShapesSet RInLab;
832 const TopoDS_Shape& OS = OldIt.Shape();
833 //---------------------------------
834 // Localisation des generateurs.
835 //---------------------------------
836 Localize(PrevIn,CurIn ,OS, RO);
838 //--------------------------------------------------------------------
839 // Resultat = intersection des descendants(dans InLab) des generateurs
840 //--------------------------------------------------------------------
841 TNaming_IteratorOnShapesSet itRO(RO);
842 for (; itRO.More(); itRO.Next()) {
843 const TopoDS_Shape& CO = itRO.Value();
844 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
845 for (; NewIt.More(); NewIt.Next()) {
846 if (NewIt.Label().IsEqual(InLab)) {
847 if (First) Res.Add(NewIt.Shape());
849 RInLab.Add(NewIt.Shape());
854 if (!First) Res.Filter(RInLab);
855 First = Standard_False;
860 //=======================================================================
863 //=======================================================================
865 void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
866 const TopAbs_ShapeEnum TS,
867 const TDF_LabelMap& Primitives,
868 const TopTools_MapOfShape& ValidShapes,
869 TNaming_ShapesSet& Res)
871 //-------------------------------------------------------
872 // Descente dans la transaction courrante = myCurTrans
873 //----------------------------------------------------------
874 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
875 Standard_Boolean First = 1;
876 Standard_Boolean YaFromValid = 0;
877 Standard_Boolean YaFromPrimitives = 0;
879 for (; itV.More(); itV.Next()) {
881 const TopoDS_Shape& NS = itV.Key();
883 GoForward (NS, CurSubShapes, TS, Res);
887 TNaming_ShapesSet ResNS;
888 GoForward (NS, CurSubShapes, TS, ResNS);
893 TDF_MapIteratorOfLabelMap itP(Primitives);
894 TNaming_ShapesSet ResPrim;
896 for ( ; itP.More(); itP.Next()) {
897 YaFromPrimitives = 1;
898 const TDF_Label& Lab = itP.Key();
899 TNaming_Iterator itL(Lab,myCurTrans);
900 TNaming_ShapesSet ResLab;
902 for (; itL.More(); itL.Next()) {
903 const TopoDS_Shape& NS = itL.NewShape();
904 GoForward (NS, CurSubShapes, TS, ResLab);
911 ResPrim.Filter(ResLab);
915 if (YaFromPrimitives) {
925 //=======================================================================
926 //function : FilterbyNeighbourgs
928 //=======================================================================
930 void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
931 const TopoDS_Shape& CurIn ,
932 const TopoDS_Shape& S,
933 TNaming_ShapesSet& Res)
935 TopTools_MapOfShape Neighbourg;
936 TopAbs_ShapeEnum TA = S.ShapeType();
937 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
938 TNaming_DataMapOfShapeShapesSet MapShapeRes;
939 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
940 Ancestors(PrevIn,TS);
942 //--------------------------------
943 // Construction des Voisins.
944 //--------------------------------
945 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
946 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
948 TNaming_ShapesSet NewNeig;
949 for (; itNeig.More(); itNeig.Next()) {
950 const TopoDS_Shape& Neig = itNeig.Key();
951 //--------------------------------------------
952 // Localisation des voisins.
953 //--------------------------------------------
954 if (!MapShapeRes.IsBound(Neig)) {
955 TNaming_ShapesSet ResNeig;
956 Localize(PrevIn,CurIn,Neig,ResNeig);
957 MapShapeRes.Bind(Neig,ResNeig);
958 NewNeig.Add(ResNeig);
961 NewNeig.Add(MapShapeRes(Neig));
965 //---------------------------------------------
966 // Filtre la solution par le resultat du voisin.
967 // ie : F est solution si ses voisins dans CurSol
968 // sont dans les descendants des voisins
969 //---------------------------------------------
970 TNaming_ShapesSet Reject;
971 TNaming_IteratorOnShapesSet itRes(Res);
973 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
976 for (; itRes.More(); itRes.Next()) {
977 const TopoDS_Shape& Cand = itRes.Value();
978 TopTools_MapOfShape Neighbourg;
979 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
980 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
981 for (; itNeig.More(); itNeig.Next()) {
982 const TopoDS_Shape& Neig = itNeig.Key();
983 if (!NewNeig.Contains(Neig)) {