1 // Created on: 1997-06-11
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_Localizer.ixx>
24 #include <TNaming_Identifier.hxx>
25 #include <TNaming_ShapesSet.hxx>
26 #include <TNaming_ListIteratorOfListOfMapOfShape.hxx>
27 #include <TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape.hxx>
28 #include <TNaming_DataMapOfShapeShapesSet.hxx>
29 #include <TNaming_IteratorOnShapesSet.hxx>
30 #include <TNaming_Evolution.hxx>
31 #include <TNaming_Iterator.hxx>
32 #include <TNaming_NewShapeIterator.hxx>
33 #include <TNaming_OldShapeIterator.hxx>
34 #include <TNaming_Tool.hxx>
35 #include <TNaming_ListOfNamedShape.hxx>
36 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
37 #include <TDF_Label.hxx>
38 #include <TopoDS_Iterator.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_MapIteratorOfMapOfShape.hxx>
44 #include <TopExp_Explorer.hxx>
50 #include <TDF_Tool.hxx>
51 #include <TDF_MapIteratorOfLabelMap.hxx>
53 #include <TCollection_AsciiString.hxx>
54 #include <BRepTools.hxx>
55 void LPrintEntry(const TDF_Label& label)
57 TCollection_AsciiString entry;
58 TDF_Tool::Entry(label, entry);
59 cout << "LabelEntry = "<< entry << endl;
61 static void LWrite(const TopoDS_Shape& shape,
62 const Standard_CString filename)
65 if(strlen(filename) > 256) return;
67 strcpy_s (buf, filename);
69 strcpy (buf, filename);
79 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
80 save << "DBRep_DrawableShape" << endl << endl;
81 if(!shape.IsNull()) BRepTools::Write(shape, save);
85 //=======================================================================
86 static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
87 const Standard_CString filename)
89 if(!NS.IsNull() && !NS->IsEmpty() ) {
90 TCollection_AsciiString aNam (filename);
91 TCollection_AsciiString oldS ("_Old");
92 TCollection_AsciiString newS ("_New_");
93 Standard_Integer i(0);
94 TNaming_Iterator it(NS);
95 for(;it.More(); it.Next(),i++) {
96 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
97 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
98 const TopoDS_Shape& oldShape = it.OldShape();
99 const TopoDS_Shape& newShape = it.NewShape();
100 if(!oldShape.IsNull())
101 LWrite ( oldShape, aName1.ToCString());
102 if(!newShape.IsNull())
103 LWrite ( newShape, aName2.ToCString());
109 //=======================================================================
110 //function : FindFeatureInAncestors
111 //purpose : Cherche les ancetres de S qui sont sous des labels
112 //=======================================================================
114 void TNaming_Localizer::FindFeaturesInAncestors
115 (const TopoDS_Shape& S,
116 const TopoDS_Shape& Context,
117 TopTools_MapOfShape& AncInFeature)
120 LWrite(S, "Localizer_S.brep");
121 LWrite(Context, "Localizer_Context.brep");
124 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
126 if (Anc.Contains(S)) {
128 cout <<"Localizer: S in ancestor" <<endl;
130 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
131 TopTools_ListIteratorOfListOfShape itL(L);
132 for (; itL.More(); itL.Next()) {
133 const TopoDS_Shape& AS = itL.Value();
135 LWrite(AS, "Localizer_AS.brep");
137 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
139 // if (TNaming_Tool::HasLabel(myUS,AS)) {
140 AncInFeature.Add(AS);
142 else if (AS.ShapeType() > TopAbs_FACE) {
143 FindFeaturesInAncestors (AS, Context, AncInFeature);
147 cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<endl;
155 cout <<" TNaming_Localization : S n est pas dans le solide"<<endl;//S is not in the solid
160 //=======================================================================
161 //function : SubShapes
163 //=======================================================================
165 const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
166 const TopAbs_ShapeEnum TS)
169 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
170 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
171 // Standard_Boolean Found = Standard_False;
172 for (; itS.More(); itS.Next(),itSS.Next()) {
173 if (In.IsSame(itS.Value())) {
174 TopTools_MapOfShape& SubShapes = itSS.Value();
175 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
176 const TopoDS_Shape& SS = exp.Current();
177 if (SubShapes.Contains(SS)) {
186 TopTools_MapOfShape emptyMap;
187 mySubShapes.Prepend(emptyMap);
188 myShapeWithSubShapes.Prepend(In);
190 TopTools_MapOfShape& SubShapes = mySubShapes.First();
191 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
192 const TopoDS_Shape& SS = exp.Current();
193 if (SubShapes.Contains(SS)) {
202 //=======================================================================
203 //function : Ancestors
205 //=======================================================================
207 const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
208 (const TopoDS_Shape& In,
209 const TopAbs_ShapeEnum TS)
211 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
212 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
213 // Standard_Boolean Found = Standard_False;
214 for (; itS.More(); itS.Next(),itA.Next()) {
215 if (In.IsSame(itS.Value())) {
216 //-----------------------
217 // Ancetres existent.
218 //-----------------------
219 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
221 TopExp_Explorer exp(In,TS);
223 if (!exp.More()) cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
225 const TopoDS_Shape& SS = exp.Current();
227 if (Anc.Contains(SS)) {
231 //----------------------------
232 // Completion des ancetres.
233 //----------------------------
234 TopAbs_ShapeEnum TA = TopAbs_FACE;
235 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
236 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
237 if (TA >= In.ShapeType()) {
238 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
242 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
249 //-----------------------------------
250 // Construction des ancetres
251 //-----------------------------------
252 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
253 myShapeWithAncestors.Prepend(In);
254 myAncestors .Prepend(emptyAnc);
256 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
258 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
259 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
260 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
261 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
262 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
266 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
269 return myAncestors.First();
272 //=======================================================================
275 //=======================================================================
277 Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
278 const Handle(TNaming_NamedShape)& NS)
280 TNaming_Iterator itLab(NS);
281 for (; itLab.More(); itLab.Next()) {
282 if (itLab.OldShape().IsSame(S)) {
283 return Standard_False;
286 if (itLab.NewShape().IsSame(S)) {
287 return Standard_True;
292 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
294 return Standard_False;
298 //=======================================================================
301 //=======================================================================
303 void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
304 const TDF_Label& Lab,
305 const TNaming_Evolution Evol,
306 TopTools_ListOfShape& LBS,
307 TNaming_ListOfNamedShape& LBNS)
309 // Standard_Integer TrDef;
311 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
314 //-----------------------------------------------------------
315 // Pas d'ascendants => Recherche et exploration du contenant
316 //----------------------------------------------------------
317 const TDF_Label& Father = Lab.Father();
318 TNaming_Iterator itLab(Father);
320 Sol = itLab.OldShape();
321 //-------------------------------------------
322 // Recherche des ancetres dans des features.
323 //-------------------------------------------
325 TopTools_MapOfShape AncInFeature;
326 FindFeaturesInAncestors (S, Sol, AncInFeature);
327 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
328 for ( ; itF.More(); itF.Next()) {
329 const TopoDS_Shape& AncOfS = itF.Key();
331 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
336 for ( ; it.More(); it.Next()) {
337 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
338 if (it.NamedShape()->Evolution() == Evol) {
339 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
341 LBS.Append (it.Shape());
342 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
346 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
354 //=======================================================================
355 //function : Backward
357 //=======================================================================
359 void TNaming_Localizer::Backward (const TopoDS_Shape& S,
360 TDF_LabelMap& Primitives,
361 TopTools_MapOfShape& ValidShapes)
363 Standard_Integer PrevTrans = myCurTrans - 1;
364 Standard_Integer TrDef;
365 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
366 TNaming_Evolution Evol = Evolution(Lab);
369 TopTools_ListOfShape LBS;
372 GoBack(S,Lab,LBS,LBLab);
375 TopTools_ListIteratorOfListOfShape itLBS (LBS);
376 TDF_ListIteratorOfLabelList itLBLab(LBLab);
381 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
382 const TopoDS_Shape& OS = itLBS.Value();
383 const TDF_Label& LabOS = itLBLab.Value();
385 Evol = Evolution(LabOS);
387 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
388 //---------------------------------------------------------
389 // Le Shape est valid dans la transaction myCurTrans => STOP
390 //---------------------------------------------------------
393 else if (Evol == TNaming_PRIMITIVE) {
394 Primitives.Add(LabOS);
396 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
397 //--------------------------------------------------------------
398 // Passage par une generation
399 // le shape dans myCurTrans descendra d un element de cet attribut.
400 // Localisation de OS dans la transaction courrante.
401 // les shapes obtenus seront des antecedants du shape cherche.
402 //--------------------------------------------------------------
404 // A faire seulememt si OS est un newShape dans LabOS.
405 TNaming_ShapesSet ResGen;
407 TDF_Label Father = LabOS.Father();
408 TNaming_Iterator itLab(Father,PrevTrans);
409 for (; itLab.More(); itLab.Next()) {
410 PrevIn= itLab.OldShape();
413 Localize(PrevIn,LabOS,OS,ResGen);
414 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
415 ValidShapes.Add(itLoc.Value());
418 else if (Evol == TNaming_SELECTED) {
420 TNaming_ShapesSet ResSel;
421 TopoDS_Shape PrevIn,CurIn;
422 // FindIn (LabOS,PrevIn,CurIn);
423 Localize(PrevIn,CurIn,OS,ResSel);
424 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
425 ValidShapes.Add(itLoc.Value());
429 Backward(itLBS.Value(),Primitives,ValidShapes);
435 //=======================================================================
436 //function : NamedShape
438 //=======================================================================
440 Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
442 Handle(TNaming_NamedShape) NS;
443 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
447 //=======================================================================
448 //function : Backward
450 //=======================================================================
452 void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
453 const TopoDS_Shape& S,
454 TNaming_MapOfNamedShape& Primitives,
455 TopTools_MapOfShape& Shapes)
457 TNaming_Evolution Evol = NS->Evolution();
458 TDF_Label LabNS = NS->Label();
460 TopTools_ListOfShape LBS;
461 TNaming_ListOfNamedShape LBNS;
463 GoBack(S,LabNS,Evol,LBS,LBNS);
466 TopTools_ListIteratorOfListOfShape itLBS (LBS);
467 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
472 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
473 const TopoDS_Shape& OS = itLBS.Value();
474 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
475 Evol = NOS->Evolution();
476 if (Evol == TNaming_PRIMITIVE) {
479 else if (Evol == TNaming_GENERATED) {
483 Backward(NOS, itLBS.Value(),Primitives,Shapes);
488 //=======================================================================
489 //function : ValidCandidat
491 //=======================================================================
494 /*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
495 const TopTools_MapOfShape& ShapeOfSol,
496 TopAbs_ShapeEnum TargetType,
497 TNaming_ShapesSet& Res)
499 Standard_Boolean Valid = Standard_False;
501 if (ShapeOfSol.Contains(S)) {
502 if (S.ShapeType() == TargetType) {
504 return Standard_True;
506 else if (S.ShapeType() < TargetType) {
507 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
508 const TopoDS_Shape& SS = exp.Current();
510 Valid = Standard_True;
519 //=======================================================================
522 //=======================================================================
524 void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
525 const TopTools_MapOfShape& Target,
526 const TopAbs_ShapeEnum TargetType,
527 TNaming_ShapesSet& Res)
530 Standard_Integer TrDef;
531 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
532 if (StoreValid (S, Target, TargetType, Res)) {
535 TNaming_Evolution Evol = Evolution(Lab);
536 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
538 for ( ; NewIt.More(); NewIt.Next()) {
539 const TopoDS_Shape& NS = NewIt.Shape();
540 GoForward ( NS, Target, TargetType, Res);
546 //=======================================================================
547 //function : FindNeighbourg
549 //=======================================================================
551 void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
552 const TopoDS_Shape& S,
553 TopTools_MapOfShape& Neighbourg)
555 TopAbs_ShapeEnum TA = S.ShapeType();
556 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
558 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
559 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
560 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
561 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
562 // szy 30.03.10 to process case when Candidate is of type Vertex
563 // if (TA == TopAbs_VERTEX) {
565 // cout <<"construction voisins des vertex impossible"<<endl;
569 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
570 const TopoDS_Shape& SS = Exp.Current();
571 if (!Anc.Contains(SS)) {
572 //----------------------------------------------------
573 // Construction des ancetres
574 //----------------------------------------------------
578 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
579 for ( ; itL.More(); itL.Next()) {
580 if (!itL.Value().IsSame(S)) {
581 Neighbourg.Add(itL.Value());
588 //=======================================================================
589 //function : TNaming_Localizer
591 //=======================================================================
593 TNaming_Localizer::TNaming_Localizer()
598 //=======================================================================
601 //=======================================================================
603 void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
604 const Standard_Integer CurTrans)
607 myCurTrans = CurTrans;
611 //=======================================================================
614 //=======================================================================
617 /*static void Explode (TNaming_ShapesSet& Res,
619 TNaming_ShapesSet& ResGoodType)
621 TNaming_IteratorOnShapesSet it(Res);
622 for ( ; it.More(); it.Next()) {
623 const TopoDS_Shape& S = it.Value();
624 TopExp_Explorer exp(S,TS);
625 for (; exp.More(); exp.Next()) {
626 ResGoodType.Add(exp.Current());
633 //=======================================================================
634 //function : Localize
636 //=======================================================================
638 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
639 const TopoDS_Shape& CurIn ,
640 const TopoDS_Shape& S,
641 TNaming_ShapesSet& Res)
644 TDF_LabelMap Primitives;
645 TopTools_MapOfShape ValidShapes;
646 Standard_Integer PrevTrans = myCurTrans-1;
648 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
650 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
653 Standard_Integer TrDef;
654 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
655 TNaming_Evolution Evol = Evolution(Lab);
656 if (Evol == TNaming_PRIMITIVE) {
657 //------------------------
658 // Label est une primitive
659 //------------------------
661 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
664 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
665 Localize(PrevIn,Lab,S,Res);
670 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
671 //-------------------
672 // Remontee Descente.
673 //-------------------
674 Backward (S, Primitives, ValidShapes);
675 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
678 //----------------------------------------------
679 // Localisation des ancetres.
680 //----------------------------------------------
681 TopTools_MapOfShape AncInFeature;
682 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
683 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
684 Standard_Boolean First = Standard_True;
686 for ( ; itF.More(); itF.Next()) {
687 const TopoDS_Shape& AncOfS = itF.Key();
688 TNaming_ShapesSet ResAnc;
690 Localize (PrevIn, CurIn, AncOfS, ResAnc);
692 //---------------------------
693 // Res = Commun des resultats
694 //---------------------------
696 Explode (ResAnc,S.ShapeType(),Res);
700 TNaming_ShapesSet ResGoodType;
701 Explode (ResAnc,S.ShapeType(),ResGoodType);
702 Res.Filter(ResGoodType);
709 //=======================================================================
710 //function : FindGenerator
711 //purpose : Finds all generators of the <S> kept in <NS>
712 //=======================================================================
714 void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
715 const TopoDS_Shape& S,
716 TopTools_ListOfShape& theListOfGenerators)
719 Handle(TNaming_UsedShapes) US;
720 TDF_Label LabNS = NS->Label();
721 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
723 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
724 if (it.Label() == LabNS) {
725 theListOfGenerators.Append(it.Shape());
726 // break; //szy 16.10.03
732 //=======================================================================
733 //function : FindShapeContext
734 //purpose : Finds context of the shape <S>.
735 // : Looks for all oldshapes kept at father label of <NS>.
736 // : If <S> validated as subshape of one of the old shapes -
737 // : this oldshape is Context.
738 //=======================================================================
740 void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
741 const TopoDS_Shape& S,
746 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
748 TopTools_ListOfShape aList;
749 TDF_Label Father = NS->Label().Father();
750 TNaming_Iterator itLab(Father);
751 for (; itLab.More(); itLab.Next()) {
752 aList.Append(itLab.OldShape()); //szy
755 TopTools_ListIteratorOfListOfShape it(aList);
756 Standard_Boolean found = 0;
757 for(;it.More();it.Next()) {
760 LWrite(SC, "FSC_OldShape.brep");
762 if (SC.IsNull()) continue;
764 if (SC.ShapeType() < S.ShapeType()) {
765 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
766 if (exp.Current().IsSame(S)) {
769 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
781 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
784 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
786 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
789 LWriteNSOnLabel(aNS, "FSC");
791 TNaming_Iterator anIter(aNS->Label());
792 for(;anIter.More();anIter.Next()) {
793 aShape = anIter.NewShape();
794 if (!aShape.IsNull()) break;
796 if (!aShape.IsNull()) SC=aShape;
805 //=======================================================================
806 //function : Localize
808 //=======================================================================
810 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
811 const TDF_Label& InLab ,
812 const TopoDS_Shape& S,
813 TNaming_ShapesSet& Res)
816 TDF_LabelMap Primitives;
817 TopTools_MapOfShape ValidShapes;
818 Standard_Integer PrevTrans = myCurTrans - 1;
820 //---------------------------------------------
821 // Recuperation du nouveau contenant generateur.
822 //---------------------------------------------
824 TDF_Label Father = InLab.Father();
825 TNaming_Iterator itLab(Father,myCurTrans);
826 for (; itLab.More(); itLab.Next()) {
827 CurIn= itLab.OldShape();
831 Standard_Boolean First = 1;
832 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
834 for (; OldIt.More(); OldIt.Next()) {
835 if (OldIt.Label().IsEqual(InLab)) {
836 TNaming_ShapesSet RO;
837 TNaming_ShapesSet RInLab;
838 const TopoDS_Shape& OS = OldIt.Shape();
839 //---------------------------------
840 // Localisation des generateurs.
841 //---------------------------------
842 Localize(PrevIn,CurIn ,OS, RO);
844 //--------------------------------------------------------------------
845 // Resultat = intersection des descendants(dans InLab) des generateurs
846 //--------------------------------------------------------------------
847 TNaming_IteratorOnShapesSet itRO(RO);
848 for (; itRO.More(); itRO.Next()) {
849 const TopoDS_Shape& CO = itRO.Value();
850 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
851 for (; NewIt.More(); NewIt.Next()) {
852 if (NewIt.Label().IsEqual(InLab)) {
853 if (First) Res.Add(NewIt.Shape());
855 RInLab.Add(NewIt.Shape());
860 if (!First) Res.Filter(RInLab);
861 First = Standard_False;
866 //=======================================================================
869 //=======================================================================
871 void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
872 const TopAbs_ShapeEnum TS,
873 const TDF_LabelMap& Primitives,
874 const TopTools_MapOfShape& ValidShapes,
875 TNaming_ShapesSet& Res)
877 //-------------------------------------------------------
878 // Descente dans la transaction courrante = myCurTrans
879 //----------------------------------------------------------
880 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
881 Standard_Boolean First = 1;
882 Standard_Boolean YaFromValid = 0;
883 Standard_Boolean YaFromPrimitives = 0;
885 for (; itV.More(); itV.Next()) {
887 const TopoDS_Shape& NS = itV.Key();
889 GoForward (NS, CurSubShapes, TS, Res);
893 TNaming_ShapesSet ResNS;
894 GoForward (NS, CurSubShapes, TS, ResNS);
899 TDF_MapIteratorOfLabelMap itP(Primitives);
900 TNaming_ShapesSet ResPrim;
902 for ( ; itP.More(); itP.Next()) {
903 YaFromPrimitives = 1;
904 const TDF_Label& Lab = itP.Key();
905 TNaming_Iterator itL(Lab,myCurTrans);
906 TNaming_ShapesSet ResLab;
908 for (; itL.More(); itL.Next()) {
909 const TopoDS_Shape& NS = itL.NewShape();
910 GoForward (NS, CurSubShapes, TS, ResLab);
917 ResPrim.Filter(ResLab);
921 if (YaFromPrimitives) {
931 //=======================================================================
932 //function : FilterbyNeighbourgs
934 //=======================================================================
936 void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
937 const TopoDS_Shape& CurIn ,
938 const TopoDS_Shape& S,
939 TNaming_ShapesSet& Res)
941 TopTools_MapOfShape Neighbourg;
942 TopAbs_ShapeEnum TA = S.ShapeType();
943 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
944 TNaming_DataMapOfShapeShapesSet MapShapeRes;
945 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
946 Ancestors(PrevIn,TS);
948 //--------------------------------
949 // Construction des Voisins.
950 //--------------------------------
951 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
952 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
954 TNaming_ShapesSet NewNeig;
955 for (; itNeig.More(); itNeig.Next()) {
956 const TopoDS_Shape& Neig = itNeig.Key();
957 //--------------------------------------------
958 // Localisation des voisins.
959 //--------------------------------------------
960 if (!MapShapeRes.IsBound(Neig)) {
961 TNaming_ShapesSet ResNeig;
962 Localize(PrevIn,CurIn,Neig,ResNeig);
963 MapShapeRes.Bind(Neig,ResNeig);
964 NewNeig.Add(ResNeig);
967 NewNeig.Add(MapShapeRes(Neig));
971 //---------------------------------------------
972 // Filtre la solution par le resultat du voisin.
973 // ie : F est solution si ses voisins dans CurSol
974 // sont dans les descendants des voisins
975 //---------------------------------------------
976 TNaming_ShapesSet Reject;
977 TNaming_IteratorOnShapesSet itRes(Res);
979 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
982 for (; itRes.More(); itRes.Next()) {
983 const TopoDS_Shape& Cand = itRes.Value();
984 TopTools_MapOfShape Neighbourg;
985 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
986 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
987 for (; itNeig.More(); itNeig.Next()) {
988 const TopoDS_Shape& Neig = itNeig.Key();
989 if (!NewNeig.Contains(Neig)) {