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.
17 #include <TNaming_Localizer.ixx>
18 #include <TNaming_Identifier.hxx>
19 #include <TNaming_ShapesSet.hxx>
20 #include <TNaming_ListIteratorOfListOfMapOfShape.hxx>
21 #include <TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape.hxx>
22 #include <TNaming_DataMapOfShapeShapesSet.hxx>
23 #include <TNaming_IteratorOnShapesSet.hxx>
24 #include <TNaming_Evolution.hxx>
25 #include <TNaming_Iterator.hxx>
26 #include <TNaming_NewShapeIterator.hxx>
27 #include <TNaming_OldShapeIterator.hxx>
28 #include <TNaming_Tool.hxx>
29 #include <TNaming_ListOfNamedShape.hxx>
30 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
31 #include <TDF_Label.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopTools_ListOfShape.hxx>
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
36 #include <TopTools_MapIteratorOfMapOfShape.hxx>
38 #include <TopExp_Explorer.hxx>
44 #include <TDF_Tool.hxx>
45 #include <TDF_MapIteratorOfLabelMap.hxx>
47 #include <TCollection_AsciiString.hxx>
48 #include <BRepTools.hxx>
49 void LPrintEntry(const TDF_Label& label)
51 TCollection_AsciiString entry;
52 TDF_Tool::Entry(label, entry);
53 cout << "LabelEntry = "<< entry << endl;
55 static void LWrite(const TopoDS_Shape& shape,
56 const Standard_CString filename)
59 if(strlen(filename) > 256) return;
61 strcpy_s (buf, filename);
63 strcpy (buf, filename);
73 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
74 save << "DBRep_DrawableShape" << endl << endl;
75 if(!shape.IsNull()) BRepTools::Write(shape, save);
79 //=======================================================================
80 static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
81 const Standard_CString filename)
83 if(!NS.IsNull() && !NS->IsEmpty() ) {
84 TCollection_AsciiString aNam (filename);
85 TCollection_AsciiString oldS ("_Old");
86 TCollection_AsciiString newS ("_New_");
87 Standard_Integer i(0);
88 TNaming_Iterator it(NS);
89 for(;it.More(); it.Next(),i++) {
90 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
91 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
92 const TopoDS_Shape& oldShape = it.OldShape();
93 const TopoDS_Shape& newShape = it.NewShape();
94 if(!oldShape.IsNull())
95 LWrite ( oldShape, aName1.ToCString());
96 if(!newShape.IsNull())
97 LWrite ( newShape, aName2.ToCString());
103 //=======================================================================
104 //function : FindFeatureInAncestors
105 //purpose : Cherche les ancetres de S qui sont sous des labels
106 //=======================================================================
108 void TNaming_Localizer::FindFeaturesInAncestors
109 (const TopoDS_Shape& S,
110 const TopoDS_Shape& Context,
111 TopTools_MapOfShape& AncInFeature)
114 LWrite(S, "Localizer_S.brep");
115 LWrite(Context, "Localizer_Context.brep");
118 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
120 if (Anc.Contains(S)) {
122 cout <<"Localizer: S in ancestor" <<endl;
124 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
125 TopTools_ListIteratorOfListOfShape itL(L);
126 for (; itL.More(); itL.Next()) {
127 const TopoDS_Shape& AS = itL.Value();
129 LWrite(AS, "Localizer_AS.brep");
131 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
133 // if (TNaming_Tool::HasLabel(myUS,AS)) {
134 AncInFeature.Add(AS);
136 else if (AS.ShapeType() > TopAbs_FACE) {
137 FindFeaturesInAncestors (AS, Context, AncInFeature);
141 cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<endl;
149 cout <<" TNaming_Localization : S n est pas dans le solide"<<endl;//S is not in the solid
154 //=======================================================================
155 //function : SubShapes
157 //=======================================================================
159 const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
160 const TopAbs_ShapeEnum TS)
163 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
164 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
165 // Standard_Boolean Found = Standard_False;
166 for (; itS.More(); itS.Next(),itSS.Next()) {
167 if (In.IsSame(itS.Value())) {
168 TopTools_MapOfShape& SubShapes = itSS.Value();
169 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
170 const TopoDS_Shape& SS = exp.Current();
171 if (SubShapes.Contains(SS)) {
180 TopTools_MapOfShape emptyMap;
181 mySubShapes.Prepend(emptyMap);
182 myShapeWithSubShapes.Prepend(In);
184 TopTools_MapOfShape& SubShapes = mySubShapes.First();
185 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
186 const TopoDS_Shape& SS = exp.Current();
187 if (SubShapes.Contains(SS)) {
196 //=======================================================================
197 //function : Ancestors
199 //=======================================================================
201 const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
202 (const TopoDS_Shape& In,
203 const TopAbs_ShapeEnum TS)
205 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
206 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
207 // Standard_Boolean Found = Standard_False;
208 for (; itS.More(); itS.Next(),itA.Next()) {
209 if (In.IsSame(itS.Value())) {
210 //-----------------------
211 // Ancetres existent.
212 //-----------------------
213 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
215 TopExp_Explorer exp(In,TS);
217 if (!exp.More()) cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
219 const TopoDS_Shape& SS = exp.Current();
221 if (Anc.Contains(SS)) {
225 //----------------------------
226 // Completion des ancetres.
227 //----------------------------
228 TopAbs_ShapeEnum TA = TopAbs_FACE;
229 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
230 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
231 if (TA >= In.ShapeType()) {
232 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
236 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
243 //-----------------------------------
244 // Construction des ancetres
245 //-----------------------------------
246 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
247 myShapeWithAncestors.Prepend(In);
248 myAncestors .Prepend(emptyAnc);
250 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
252 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
253 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
254 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
255 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
256 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
260 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
263 return myAncestors.First();
266 //=======================================================================
269 //=======================================================================
271 Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
272 const Handle(TNaming_NamedShape)& NS)
274 TNaming_Iterator itLab(NS);
275 for (; itLab.More(); itLab.Next()) {
276 if (itLab.OldShape().IsSame(S)) {
277 return Standard_False;
279 if (itLab.NewShape().IsSame(S)) {
280 return Standard_True;
284 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
286 return Standard_False;
290 //=======================================================================
293 //=======================================================================
295 void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
296 const TDF_Label& Lab,
297 const TNaming_Evolution Evol,
298 TopTools_ListOfShape& LBS,
299 TNaming_ListOfNamedShape& LBNS)
301 // Standard_Integer TrDef;
303 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
306 //-----------------------------------------------------------
307 // Pas d'ascendants => Recherche et exploration du contenant
308 //----------------------------------------------------------
309 const TDF_Label& Father = Lab.Father();
310 TNaming_Iterator itLab(Father);
312 Sol = itLab.OldShape();
313 //-------------------------------------------
314 // Recherche des ancetres dans des features.
315 //-------------------------------------------
317 TopTools_MapOfShape AncInFeature;
318 FindFeaturesInAncestors (S, Sol, AncInFeature);
319 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
320 for ( ; itF.More(); itF.Next()) {
321 const TopoDS_Shape& AncOfS = itF.Key();
323 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
328 for ( ; it.More(); it.Next()) {
329 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
330 if (it.NamedShape()->Evolution() == Evol) {
331 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
333 LBS.Append (it.Shape());
334 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
338 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
346 //=======================================================================
347 //function : Backward
349 //=======================================================================
351 void TNaming_Localizer::Backward (const TopoDS_Shape& S,
352 TDF_LabelMap& Primitives,
353 TopTools_MapOfShape& ValidShapes)
355 Standard_Integer PrevTrans = myCurTrans - 1;
356 Standard_Integer TrDef;
357 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
358 TNaming_Evolution Evol = Evolution(Lab);
361 TopTools_ListOfShape LBS;
364 GoBack(S,Lab,LBS,LBLab);
367 TopTools_ListIteratorOfListOfShape itLBS (LBS);
368 TDF_ListIteratorOfLabelList itLBLab(LBLab);
373 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
374 const TopoDS_Shape& OS = itLBS.Value();
375 const TDF_Label& LabOS = itLBLab.Value();
377 Evol = Evolution(LabOS);
379 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
380 //---------------------------------------------------------
381 // Le Shape est valid dans la transaction myCurTrans => STOP
382 //---------------------------------------------------------
385 else if (Evol == TNaming_PRIMITIVE) {
386 Primitives.Add(LabOS);
388 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
389 //--------------------------------------------------------------
390 // Passage par une generation
391 // le shape dans myCurTrans descendra d un element de cet attribut.
392 // Localisation de OS dans la transaction courrante.
393 // les shapes obtenus seront des antecedants du shape cherche.
394 //--------------------------------------------------------------
396 // A faire seulememt si OS est un newShape dans LabOS.
397 TNaming_ShapesSet ResGen;
399 TDF_Label Father = LabOS.Father();
400 TNaming_Iterator itLab(Father,PrevTrans);
401 for (; itLab.More(); itLab.Next()) {
402 PrevIn= itLab.OldShape();
405 Localize(PrevIn,LabOS,OS,ResGen);
406 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
407 ValidShapes.Add(itLoc.Value());
410 else if (Evol == TNaming_SELECTED) {
412 TNaming_ShapesSet ResSel;
413 TopoDS_Shape PrevIn,CurIn;
414 // FindIn (LabOS,PrevIn,CurIn);
415 Localize(PrevIn,CurIn,OS,ResSel);
416 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
417 ValidShapes.Add(itLoc.Value());
421 Backward(itLBS.Value(),Primitives,ValidShapes);
427 //=======================================================================
428 //function : NamedShape
430 //=======================================================================
432 Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
434 Handle(TNaming_NamedShape) NS;
435 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
439 //=======================================================================
440 //function : Backward
442 //=======================================================================
444 void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
445 const TopoDS_Shape& S,
446 TNaming_MapOfNamedShape& Primitives,
447 TopTools_MapOfShape& Shapes)
449 TNaming_Evolution Evol = NS->Evolution();
450 TDF_Label LabNS = NS->Label();
452 TopTools_ListOfShape LBS;
453 TNaming_ListOfNamedShape LBNS;
455 GoBack(S,LabNS,Evol,LBS,LBNS);
458 TopTools_ListIteratorOfListOfShape itLBS (LBS);
459 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
464 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
465 const TopoDS_Shape& OS = itLBS.Value();
466 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
467 Evol = NOS->Evolution();
468 if (Evol == TNaming_PRIMITIVE) {
471 else if (Evol == TNaming_GENERATED) {
475 Backward(NOS, itLBS.Value(),Primitives,Shapes);
480 //=======================================================================
481 //function : ValidCandidat
483 //=======================================================================
486 /*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
487 const TopTools_MapOfShape& ShapeOfSol,
488 TopAbs_ShapeEnum TargetType,
489 TNaming_ShapesSet& Res)
491 Standard_Boolean Valid = Standard_False;
493 if (ShapeOfSol.Contains(S)) {
494 if (S.ShapeType() == TargetType) {
496 return Standard_True;
498 else if (S.ShapeType() < TargetType) {
499 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
500 const TopoDS_Shape& SS = exp.Current();
502 Valid = Standard_True;
511 //=======================================================================
514 //=======================================================================
516 void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
517 const TopTools_MapOfShape& Target,
518 const TopAbs_ShapeEnum TargetType,
519 TNaming_ShapesSet& Res)
522 Standard_Integer TrDef;
523 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
524 if (StoreValid (S, Target, TargetType, Res)) {
527 TNaming_Evolution Evol = Evolution(Lab);
528 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
530 for ( ; NewIt.More(); NewIt.Next()) {
531 const TopoDS_Shape& NS = NewIt.Shape();
532 GoForward ( NS, Target, TargetType, Res);
538 //=======================================================================
539 //function : FindNeighbourg
541 //=======================================================================
543 void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
544 const TopoDS_Shape& S,
545 TopTools_MapOfShape& Neighbourg)
547 TopAbs_ShapeEnum TA = S.ShapeType();
548 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
550 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
551 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
552 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
553 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
554 // szy 30.03.10 to process case when Candidate is of type Vertex
555 // if (TA == TopAbs_VERTEX) {
557 // cout <<"construction voisins des vertex impossible"<<endl;
561 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
562 const TopoDS_Shape& SS = Exp.Current();
563 if (!Anc.Contains(SS)) {
564 //----------------------------------------------------
565 // Construction des ancetres
566 //----------------------------------------------------
570 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
571 for ( ; itL.More(); itL.Next()) {
572 if (!itL.Value().IsSame(S)) {
573 Neighbourg.Add(itL.Value());
580 //=======================================================================
581 //function : TNaming_Localizer
583 //=======================================================================
585 TNaming_Localizer::TNaming_Localizer()
590 //=======================================================================
593 //=======================================================================
595 void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
596 const Standard_Integer CurTrans)
599 myCurTrans = CurTrans;
603 //=======================================================================
606 //=======================================================================
609 /*static void Explode (TNaming_ShapesSet& Res,
611 TNaming_ShapesSet& ResGoodType)
613 TNaming_IteratorOnShapesSet it(Res);
614 for ( ; it.More(); it.Next()) {
615 const TopoDS_Shape& S = it.Value();
616 TopExp_Explorer exp(S,TS);
617 for (; exp.More(); exp.Next()) {
618 ResGoodType.Add(exp.Current());
625 //=======================================================================
626 //function : Localize
628 //=======================================================================
630 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
631 const TopoDS_Shape& CurIn ,
632 const TopoDS_Shape& S,
633 TNaming_ShapesSet& Res)
636 TDF_LabelMap Primitives;
637 TopTools_MapOfShape ValidShapes;
638 Standard_Integer PrevTrans = myCurTrans-1;
640 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
642 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
645 Standard_Integer TrDef;
646 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
647 TNaming_Evolution Evol = Evolution(Lab);
648 if (Evol == TNaming_PRIMITIVE) {
649 //------------------------
650 // Label est une primitive
651 //------------------------
653 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
656 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
657 Localize(PrevIn,Lab,S,Res);
662 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
663 //-------------------
664 // Remontee Descente.
665 //-------------------
666 Backward (S, Primitives, ValidShapes);
667 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
670 //----------------------------------------------
671 // Localisation des ancetres.
672 //----------------------------------------------
673 TopTools_MapOfShape AncInFeature;
674 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
675 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
676 Standard_Boolean First = Standard_True;
678 for ( ; itF.More(); itF.Next()) {
679 const TopoDS_Shape& AncOfS = itF.Key();
680 TNaming_ShapesSet ResAnc;
682 Localize (PrevIn, CurIn, AncOfS, ResAnc);
684 //---------------------------
685 // Res = Commun des resultats
686 //---------------------------
688 Explode (ResAnc,S.ShapeType(),Res);
692 TNaming_ShapesSet ResGoodType;
693 Explode (ResAnc,S.ShapeType(),ResGoodType);
694 Res.Filter(ResGoodType);
701 //=======================================================================
702 //function : FindGenerator
703 //purpose : Finds all generators of the <S> kept in <NS>
704 //=======================================================================
706 void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
707 const TopoDS_Shape& S,
708 TopTools_ListOfShape& theListOfGenerators)
711 Handle(TNaming_UsedShapes) US;
712 TDF_Label LabNS = NS->Label();
713 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
715 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
716 if (it.Label() == LabNS) {
717 theListOfGenerators.Append(it.Shape());
718 // break; //szy 16.10.03
724 //=======================================================================
725 //function : FindShapeContext
726 //purpose : Finds context of the shape <S>.
727 // : Looks for all oldshapes kept at father label of <NS>.
728 // : If <S> validated as subshape of one of the old shapes -
729 // : this oldshape is Context.
730 //=======================================================================
732 void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
733 const TopoDS_Shape& S,
738 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
740 TopTools_ListOfShape aList;
741 TDF_Label Father = NS->Label().Father();
742 TNaming_Iterator itLab(Father);
743 for (; itLab.More(); itLab.Next()) {
744 aList.Append(itLab.OldShape()); //szy
747 TopTools_ListIteratorOfListOfShape it(aList);
748 Standard_Boolean found = 0;
749 for(;it.More();it.Next()) {
752 LWrite(SC, "FSC_OldShape.brep");
754 if (SC.IsNull()) continue;
756 if (SC.ShapeType() < S.ShapeType()) {
757 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
758 if (exp.Current().IsSame(S)) {
761 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
773 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
776 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
778 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
781 LWriteNSOnLabel(aNS, "FSC");
783 TNaming_Iterator anIter(aNS->Label());
784 for(;anIter.More();anIter.Next()) {
785 aShape = anIter.NewShape();
786 if (!aShape.IsNull()) break;
788 if (!aShape.IsNull()) SC=aShape;
797 //=======================================================================
798 //function : Localize
800 //=======================================================================
802 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
803 const TDF_Label& InLab ,
804 const TopoDS_Shape& S,
805 TNaming_ShapesSet& Res)
808 TDF_LabelMap Primitives;
809 TopTools_MapOfShape ValidShapes;
810 Standard_Integer PrevTrans = myCurTrans - 1;
812 //---------------------------------------------
813 // Recuperation du nouveau contenant generateur.
814 //---------------------------------------------
816 TDF_Label Father = InLab.Father();
817 TNaming_Iterator itLab(Father,myCurTrans);
818 for (; itLab.More(); itLab.Next()) {
819 CurIn= itLab.OldShape();
823 Standard_Boolean First = 1;
824 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
826 for (; OldIt.More(); OldIt.Next()) {
827 if (OldIt.Label().IsEqual(InLab)) {
828 TNaming_ShapesSet RO;
829 TNaming_ShapesSet RInLab;
830 const TopoDS_Shape& OS = OldIt.Shape();
831 //---------------------------------
832 // Localisation des generateurs.
833 //---------------------------------
834 Localize(PrevIn,CurIn ,OS, RO);
836 //--------------------------------------------------------------------
837 // Resultat = intersection des descendants(dans InLab) des generateurs
838 //--------------------------------------------------------------------
839 TNaming_IteratorOnShapesSet itRO(RO);
840 for (; itRO.More(); itRO.Next()) {
841 const TopoDS_Shape& CO = itRO.Value();
842 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
843 for (; NewIt.More(); NewIt.Next()) {
844 if (NewIt.Label().IsEqual(InLab)) {
845 if (First) Res.Add(NewIt.Shape());
847 RInLab.Add(NewIt.Shape());
852 if (!First) Res.Filter(RInLab);
853 First = Standard_False;
858 //=======================================================================
861 //=======================================================================
863 void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
864 const TopAbs_ShapeEnum TS,
865 const TDF_LabelMap& Primitives,
866 const TopTools_MapOfShape& ValidShapes,
867 TNaming_ShapesSet& Res)
869 //-------------------------------------------------------
870 // Descente dans la transaction courrante = myCurTrans
871 //----------------------------------------------------------
872 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
873 Standard_Boolean First = 1;
874 Standard_Boolean YaFromValid = 0;
875 Standard_Boolean YaFromPrimitives = 0;
877 for (; itV.More(); itV.Next()) {
879 const TopoDS_Shape& NS = itV.Key();
881 GoForward (NS, CurSubShapes, TS, Res);
885 TNaming_ShapesSet ResNS;
886 GoForward (NS, CurSubShapes, TS, ResNS);
891 TDF_MapIteratorOfLabelMap itP(Primitives);
892 TNaming_ShapesSet ResPrim;
894 for ( ; itP.More(); itP.Next()) {
895 YaFromPrimitives = 1;
896 const TDF_Label& Lab = itP.Key();
897 TNaming_Iterator itL(Lab,myCurTrans);
898 TNaming_ShapesSet ResLab;
900 for (; itL.More(); itL.Next()) {
901 const TopoDS_Shape& NS = itL.NewShape();
902 GoForward (NS, CurSubShapes, TS, ResLab);
909 ResPrim.Filter(ResLab);
913 if (YaFromPrimitives) {
923 //=======================================================================
924 //function : FilterbyNeighbourgs
926 //=======================================================================
928 void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
929 const TopoDS_Shape& CurIn ,
930 const TopoDS_Shape& S,
931 TNaming_ShapesSet& Res)
933 TopTools_MapOfShape Neighbourg;
934 TopAbs_ShapeEnum TA = S.ShapeType();
935 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
936 TNaming_DataMapOfShapeShapesSet MapShapeRes;
937 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
938 Ancestors(PrevIn,TS);
940 //--------------------------------
941 // Construction des Voisins.
942 //--------------------------------
943 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
944 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
946 TNaming_ShapesSet NewNeig;
947 for (; itNeig.More(); itNeig.Next()) {
948 const TopoDS_Shape& Neig = itNeig.Key();
949 //--------------------------------------------
950 // Localisation des voisins.
951 //--------------------------------------------
952 if (!MapShapeRes.IsBound(Neig)) {
953 TNaming_ShapesSet ResNeig;
954 Localize(PrevIn,CurIn,Neig,ResNeig);
955 MapShapeRes.Bind(Neig,ResNeig);
956 NewNeig.Add(ResNeig);
959 NewNeig.Add(MapShapeRes(Neig));
963 //---------------------------------------------
964 // Filtre la solution par le resultat du voisin.
965 // ie : F est solution si ses voisins dans CurSol
966 // sont dans les descendants des voisins
967 //---------------------------------------------
968 TNaming_ShapesSet Reject;
969 TNaming_IteratorOnShapesSet itRes(Res);
971 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
974 for (; itRes.More(); itRes.Next()) {
975 const TopoDS_Shape& Cand = itRes.Value();
976 TopTools_MapOfShape Neighbourg;
977 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
978 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
979 for (; itNeig.More(); itNeig.Next()) {
980 const TopoDS_Shape& Neig = itNeig.Key();
981 if (!NewNeig.Contains(Neig)) {