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>
43 #include <TDF_Tool.hxx>
44 #include <TDF_MapIteratorOfLabelMap.hxx>
46 #include <TCollection_AsciiString.hxx>
47 #include <BRepTools.hxx>
48 void LPrintEntry(const TDF_Label& label)
50 TCollection_AsciiString entry;
51 TDF_Tool::Entry(label, entry);
52 cout << "LabelEntry = "<< entry << endl;
54 static void LWrite(const TopoDS_Shape& shape,
55 const Standard_CString filename)
58 if(strlen(filename) > 256) return;
60 strcpy_s (buf, filename);
62 strcpy (buf, filename);
72 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
73 save << "DBRep_DrawableShape" << endl << endl;
74 if(!shape.IsNull()) BRepTools::Write(shape, save);
78 //=======================================================================
79 static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
80 const Standard_CString filename)
82 if(!NS.IsNull() && !NS->IsEmpty() ) {
83 TCollection_AsciiString aNam (filename);
84 TCollection_AsciiString oldS ("_Old");
85 TCollection_AsciiString newS ("_New_");
86 Standard_Integer i(0);
87 TNaming_Iterator it(NS);
88 for(;it.More(); it.Next(),i++) {
89 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
90 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
91 const TopoDS_Shape& oldShape = it.OldShape();
92 const TopoDS_Shape& newShape = it.NewShape();
93 if(!oldShape.IsNull())
94 LWrite ( oldShape, aName1.ToCString());
95 if(!newShape.IsNull())
96 LWrite ( newShape, aName2.ToCString());
102 //=======================================================================
103 //function : FindFeatureInAncestors
104 //purpose : Cherche les ancetres de S qui sont sous des labels
105 //=======================================================================
107 void TNaming_Localizer::FindFeaturesInAncestors
108 (const TopoDS_Shape& S,
109 const TopoDS_Shape& Context,
110 TopTools_MapOfShape& AncInFeature)
113 LWrite(S, "Localizer_S.brep");
114 LWrite(Context, "Localizer_Context.brep");
117 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
119 if (Anc.Contains(S)) {
121 cout <<"Localizer: S in ancestor" <<endl;
123 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
124 TopTools_ListIteratorOfListOfShape itL(L);
125 for (; itL.More(); itL.Next()) {
126 const TopoDS_Shape& AS = itL.Value();
128 LWrite(AS, "Localizer_AS.brep");
130 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
132 // if (TNaming_Tool::HasLabel(myUS,AS)) {
133 AncInFeature.Add(AS);
135 else if (AS.ShapeType() > TopAbs_FACE) {
136 FindFeaturesInAncestors (AS, Context, AncInFeature);
140 cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<endl;
148 cout <<" TNaming_Localization : S n est pas dans le solide"<<endl;//S is not in the solid
153 //=======================================================================
154 //function : SubShapes
156 //=======================================================================
158 const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
159 const TopAbs_ShapeEnum TS)
162 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
163 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
164 // Standard_Boolean Found = Standard_False;
165 for (; itS.More(); itS.Next(),itSS.Next()) {
166 if (In.IsSame(itS.Value())) {
167 TopTools_MapOfShape& SubShapes = itSS.Value();
168 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
169 const TopoDS_Shape& SS = exp.Current();
170 if (SubShapes.Contains(SS)) {
179 TopTools_MapOfShape emptyMap;
180 mySubShapes.Prepend(emptyMap);
181 myShapeWithSubShapes.Prepend(In);
183 TopTools_MapOfShape& SubShapes = mySubShapes.First();
184 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
185 const TopoDS_Shape& SS = exp.Current();
186 if (SubShapes.Contains(SS)) {
195 //=======================================================================
196 //function : Ancestors
198 //=======================================================================
200 const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
201 (const TopoDS_Shape& In,
202 const TopAbs_ShapeEnum TS)
204 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
205 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
206 // Standard_Boolean Found = Standard_False;
207 for (; itS.More(); itS.Next(),itA.Next()) {
208 if (In.IsSame(itS.Value())) {
209 //-----------------------
210 // Ancetres existent.
211 //-----------------------
212 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
214 TopExp_Explorer exp(In,TS);
216 if (!exp.More()) cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
218 const TopoDS_Shape& SS = exp.Current();
220 if (Anc.Contains(SS)) {
224 //----------------------------
225 // Completion des ancetres.
226 //----------------------------
227 TopAbs_ShapeEnum TA = TopAbs_FACE;
228 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
229 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
230 if (TA >= In.ShapeType()) {
231 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
235 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
242 //-----------------------------------
243 // Construction des ancetres
244 //-----------------------------------
245 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
246 myShapeWithAncestors.Prepend(In);
247 myAncestors .Prepend(emptyAnc);
249 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
251 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
252 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
253 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
254 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
255 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
259 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
262 return myAncestors.First();
265 //=======================================================================
268 //=======================================================================
270 Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
271 const Handle(TNaming_NamedShape)& NS)
273 TNaming_Iterator itLab(NS);
274 for (; itLab.More(); itLab.Next()) {
275 if (itLab.OldShape().IsSame(S)) {
276 return Standard_False;
278 if (itLab.NewShape().IsSame(S)) {
279 return Standard_True;
283 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
285 return Standard_False;
289 //=======================================================================
292 //=======================================================================
294 void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
295 const TDF_Label& Lab,
296 const TNaming_Evolution Evol,
297 TopTools_ListOfShape& LBS,
298 TNaming_ListOfNamedShape& LBNS)
300 // Standard_Integer TrDef;
302 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
305 //-----------------------------------------------------------
306 // Pas d'ascendants => Recherche et exploration du contenant
307 //----------------------------------------------------------
308 const TDF_Label& Father = Lab.Father();
309 TNaming_Iterator itLab(Father);
311 Sol = itLab.OldShape();
312 //-------------------------------------------
313 // Recherche des ancetres dans des features.
314 //-------------------------------------------
316 TopTools_MapOfShape AncInFeature;
317 FindFeaturesInAncestors (S, Sol, AncInFeature);
318 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
319 for ( ; itF.More(); itF.Next()) {
320 const TopoDS_Shape& AncOfS = itF.Key();
322 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
327 for ( ; it.More(); it.Next()) {
328 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
329 if (it.NamedShape()->Evolution() == Evol) {
330 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
332 LBS.Append (it.Shape());
333 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
337 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
345 //=======================================================================
346 //function : Backward
348 //=======================================================================
350 void TNaming_Localizer::Backward (const TopoDS_Shape& S,
351 TDF_LabelMap& Primitives,
352 TopTools_MapOfShape& ValidShapes)
354 Standard_Integer PrevTrans = myCurTrans - 1;
355 Standard_Integer TrDef;
356 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
357 TNaming_Evolution Evol = Evolution(Lab);
360 TopTools_ListOfShape LBS;
363 GoBack(S,Lab,LBS,LBLab);
366 TopTools_ListIteratorOfListOfShape itLBS (LBS);
367 TDF_ListIteratorOfLabelList itLBLab(LBLab);
372 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
373 const TopoDS_Shape& OS = itLBS.Value();
374 const TDF_Label& LabOS = itLBLab.Value();
376 Evol = Evolution(LabOS);
378 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
379 //---------------------------------------------------------
380 // Le Shape est valid dans la transaction myCurTrans => STOP
381 //---------------------------------------------------------
384 else if (Evol == TNaming_PRIMITIVE) {
385 Primitives.Add(LabOS);
387 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
388 //--------------------------------------------------------------
389 // Passage par une generation
390 // le shape dans myCurTrans descendra d un element de cet attribut.
391 // Localisation de OS dans la transaction courrante.
392 // les shapes obtenus seront des antecedants du shape cherche.
393 //--------------------------------------------------------------
395 // A faire seulememt si OS est un newShape dans LabOS.
396 TNaming_ShapesSet ResGen;
398 TDF_Label Father = LabOS.Father();
399 TNaming_Iterator itLab(Father,PrevTrans);
400 for (; itLab.More(); itLab.Next()) {
401 PrevIn= itLab.OldShape();
404 Localize(PrevIn,LabOS,OS,ResGen);
405 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
406 ValidShapes.Add(itLoc.Value());
409 else if (Evol == TNaming_SELECTED) {
411 TNaming_ShapesSet ResSel;
412 TopoDS_Shape PrevIn,CurIn;
413 // FindIn (LabOS,PrevIn,CurIn);
414 Localize(PrevIn,CurIn,OS,ResSel);
415 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
416 ValidShapes.Add(itLoc.Value());
420 Backward(itLBS.Value(),Primitives,ValidShapes);
426 //=======================================================================
427 //function : NamedShape
429 //=======================================================================
431 Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
433 Handle(TNaming_NamedShape) NS;
434 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
438 //=======================================================================
439 //function : Backward
441 //=======================================================================
443 void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
444 const TopoDS_Shape& S,
445 TNaming_MapOfNamedShape& Primitives,
446 TopTools_MapOfShape& Shapes)
448 TNaming_Evolution Evol = NS->Evolution();
449 TDF_Label LabNS = NS->Label();
451 TopTools_ListOfShape LBS;
452 TNaming_ListOfNamedShape LBNS;
454 GoBack(S,LabNS,Evol,LBS,LBNS);
457 TopTools_ListIteratorOfListOfShape itLBS (LBS);
458 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
463 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
464 const TopoDS_Shape& OS = itLBS.Value();
465 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
466 Evol = NOS->Evolution();
467 if (Evol == TNaming_PRIMITIVE) {
470 else if (Evol == TNaming_GENERATED) {
474 Backward(NOS, itLBS.Value(),Primitives,Shapes);
479 //=======================================================================
480 //function : ValidCandidat
482 //=======================================================================
485 /*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
486 const TopTools_MapOfShape& ShapeOfSol,
487 TopAbs_ShapeEnum TargetType,
488 TNaming_ShapesSet& Res)
490 Standard_Boolean Valid = Standard_False;
492 if (ShapeOfSol.Contains(S)) {
493 if (S.ShapeType() == TargetType) {
495 return Standard_True;
497 else if (S.ShapeType() < TargetType) {
498 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
499 const TopoDS_Shape& SS = exp.Current();
501 Valid = Standard_True;
510 //=======================================================================
513 //=======================================================================
515 void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
516 const TopTools_MapOfShape& Target,
517 const TopAbs_ShapeEnum TargetType,
518 TNaming_ShapesSet& Res)
521 Standard_Integer TrDef;
522 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
523 if (StoreValid (S, Target, TargetType, Res)) {
526 TNaming_Evolution Evol = Evolution(Lab);
527 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
529 for ( ; NewIt.More(); NewIt.Next()) {
530 const TopoDS_Shape& NS = NewIt.Shape();
531 GoForward ( NS, Target, TargetType, Res);
537 //=======================================================================
538 //function : FindNeighbourg
540 //=======================================================================
542 void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
543 const TopoDS_Shape& S,
544 TopTools_MapOfShape& Neighbourg)
546 TopAbs_ShapeEnum TA = S.ShapeType();
547 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
549 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
550 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
551 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
552 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
553 // szy 30.03.10 to process case when Candidate is of type Vertex
554 // if (TA == TopAbs_VERTEX) {
556 // cout <<"construction voisins des vertex impossible"<<endl;
560 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
561 const TopoDS_Shape& SS = Exp.Current();
562 if (!Anc.Contains(SS)) {
563 //----------------------------------------------------
564 // Construction des ancetres
565 //----------------------------------------------------
569 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
570 for ( ; itL.More(); itL.Next()) {
571 if (!itL.Value().IsSame(S)) {
572 Neighbourg.Add(itL.Value());
579 //=======================================================================
580 //function : TNaming_Localizer
582 //=======================================================================
584 TNaming_Localizer::TNaming_Localizer()
589 //=======================================================================
592 //=======================================================================
594 void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
595 const Standard_Integer CurTrans)
598 myCurTrans = CurTrans;
602 //=======================================================================
605 //=======================================================================
608 /*static void Explode (TNaming_ShapesSet& Res,
610 TNaming_ShapesSet& ResGoodType)
612 TNaming_IteratorOnShapesSet it(Res);
613 for ( ; it.More(); it.Next()) {
614 const TopoDS_Shape& S = it.Value();
615 TopExp_Explorer exp(S,TS);
616 for (; exp.More(); exp.Next()) {
617 ResGoodType.Add(exp.Current());
624 //=======================================================================
625 //function : Localize
627 //=======================================================================
629 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
630 const TopoDS_Shape& CurIn ,
631 const TopoDS_Shape& S,
632 TNaming_ShapesSet& Res)
635 TDF_LabelMap Primitives;
636 TopTools_MapOfShape ValidShapes;
637 Standard_Integer PrevTrans = myCurTrans-1;
639 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
641 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
644 Standard_Integer TrDef;
645 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
646 TNaming_Evolution Evol = Evolution(Lab);
647 if (Evol == TNaming_PRIMITIVE) {
648 //------------------------
649 // Label est une primitive
650 //------------------------
652 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
655 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
656 Localize(PrevIn,Lab,S,Res);
661 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
662 //-------------------
663 // Remontee Descente.
664 //-------------------
665 Backward (S, Primitives, ValidShapes);
666 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
669 //----------------------------------------------
670 // Localisation des ancetres.
671 //----------------------------------------------
672 TopTools_MapOfShape AncInFeature;
673 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
674 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
675 Standard_Boolean First = Standard_True;
677 for ( ; itF.More(); itF.Next()) {
678 const TopoDS_Shape& AncOfS = itF.Key();
679 TNaming_ShapesSet ResAnc;
681 Localize (PrevIn, CurIn, AncOfS, ResAnc);
683 //---------------------------
684 // Res = Commun des resultats
685 //---------------------------
687 Explode (ResAnc,S.ShapeType(),Res);
691 TNaming_ShapesSet ResGoodType;
692 Explode (ResAnc,S.ShapeType(),ResGoodType);
693 Res.Filter(ResGoodType);
700 //=======================================================================
701 //function : FindGenerator
702 //purpose : Finds all generators of the <S> kept in <NS>
703 //=======================================================================
705 void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
706 const TopoDS_Shape& S,
707 TopTools_ListOfShape& theListOfGenerators)
710 Handle(TNaming_UsedShapes) US;
711 TDF_Label LabNS = NS->Label();
712 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
714 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
715 if (it.Label() == LabNS) {
716 theListOfGenerators.Append(it.Shape());
717 // break; //szy 16.10.03
723 //=======================================================================
724 //function : FindShapeContext
725 //purpose : Finds context of the shape <S>.
726 // : Looks for all oldshapes kept at father label of <NS>.
727 // : If <S> validated as subshape of one of the old shapes -
728 // : this oldshape is Context.
729 //=======================================================================
731 void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
732 const TopoDS_Shape& S,
737 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
739 TopTools_ListOfShape aList;
740 TDF_Label Father = NS->Label().Father();
741 TNaming_Iterator itLab(Father);
742 for (; itLab.More(); itLab.Next()) {
743 aList.Append(itLab.OldShape()); //szy
746 TopTools_ListIteratorOfListOfShape it(aList);
747 Standard_Boolean found = 0;
748 for(;it.More();it.Next()) {
751 LWrite(SC, "FSC_OldShape.brep");
753 if (SC.IsNull()) continue;
755 if (SC.ShapeType() < S.ShapeType()) {
756 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
757 if (exp.Current().IsSame(S)) {
760 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
771 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
774 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
776 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
779 LWriteNSOnLabel(aNS, "FSC");
781 TNaming_Iterator anIter(aNS->Label());
782 for(;anIter.More();anIter.Next()) {
783 aShape = anIter.NewShape();
784 if (!aShape.IsNull()) break;
786 if (!aShape.IsNull()) SC=aShape;
794 //=======================================================================
795 //function : Localize
797 //=======================================================================
799 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
800 const TDF_Label& InLab ,
801 const TopoDS_Shape& S,
802 TNaming_ShapesSet& Res)
805 TDF_LabelMap Primitives;
806 TopTools_MapOfShape ValidShapes;
807 Standard_Integer PrevTrans = myCurTrans - 1;
809 //---------------------------------------------
810 // Recuperation du nouveau contenant generateur.
811 //---------------------------------------------
813 TDF_Label Father = InLab.Father();
814 TNaming_Iterator itLab(Father,myCurTrans);
815 for (; itLab.More(); itLab.Next()) {
816 CurIn= itLab.OldShape();
820 Standard_Boolean First = 1;
821 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
823 for (; OldIt.More(); OldIt.Next()) {
824 if (OldIt.Label().IsEqual(InLab)) {
825 TNaming_ShapesSet RO;
826 TNaming_ShapesSet RInLab;
827 const TopoDS_Shape& OS = OldIt.Shape();
828 //---------------------------------
829 // Localisation des generateurs.
830 //---------------------------------
831 Localize(PrevIn,CurIn ,OS, RO);
833 //--------------------------------------------------------------------
834 // Resultat = intersection des descendants(dans InLab) des generateurs
835 //--------------------------------------------------------------------
836 TNaming_IteratorOnShapesSet itRO(RO);
837 for (; itRO.More(); itRO.Next()) {
838 const TopoDS_Shape& CO = itRO.Value();
839 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
840 for (; NewIt.More(); NewIt.Next()) {
841 if (NewIt.Label().IsEqual(InLab)) {
842 if (First) Res.Add(NewIt.Shape());
844 RInLab.Add(NewIt.Shape());
849 if (!First) Res.Filter(RInLab);
850 First = Standard_False;
855 //=======================================================================
858 //=======================================================================
860 void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
861 const TopAbs_ShapeEnum TS,
862 const TDF_LabelMap& Primitives,
863 const TopTools_MapOfShape& ValidShapes,
864 TNaming_ShapesSet& Res)
866 //-------------------------------------------------------
867 // Descente dans la transaction courrante = myCurTrans
868 //----------------------------------------------------------
869 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
870 Standard_Boolean First = 1;
871 Standard_Boolean YaFromValid = 0;
872 Standard_Boolean YaFromPrimitives = 0;
874 for (; itV.More(); itV.Next()) {
876 const TopoDS_Shape& NS = itV.Key();
878 GoForward (NS, CurSubShapes, TS, Res);
882 TNaming_ShapesSet ResNS;
883 GoForward (NS, CurSubShapes, TS, ResNS);
888 TDF_MapIteratorOfLabelMap itP(Primitives);
889 TNaming_ShapesSet ResPrim;
891 for ( ; itP.More(); itP.Next()) {
892 YaFromPrimitives = 1;
893 const TDF_Label& Lab = itP.Key();
894 TNaming_Iterator itL(Lab,myCurTrans);
895 TNaming_ShapesSet ResLab;
897 for (; itL.More(); itL.Next()) {
898 const TopoDS_Shape& NS = itL.NewShape();
899 GoForward (NS, CurSubShapes, TS, ResLab);
906 ResPrim.Filter(ResLab);
910 if (YaFromPrimitives) {
920 //=======================================================================
921 //function : FilterbyNeighbourgs
923 //=======================================================================
925 void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
926 const TopoDS_Shape& CurIn ,
927 const TopoDS_Shape& S,
928 TNaming_ShapesSet& Res)
930 TopTools_MapOfShape Neighbourg;
931 TopAbs_ShapeEnum TA = S.ShapeType();
932 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
933 TNaming_DataMapOfShapeShapesSet MapShapeRes;
934 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
935 Ancestors(PrevIn,TS);
937 //--------------------------------
938 // Construction des Voisins.
939 //--------------------------------
940 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
941 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
943 TNaming_ShapesSet NewNeig;
944 for (; itNeig.More(); itNeig.Next()) {
945 const TopoDS_Shape& Neig = itNeig.Key();
946 //--------------------------------------------
947 // Localisation des voisins.
948 //--------------------------------------------
949 if (!MapShapeRes.IsBound(Neig)) {
950 TNaming_ShapesSet ResNeig;
951 Localize(PrevIn,CurIn,Neig,ResNeig);
952 MapShapeRes.Bind(Neig,ResNeig);
953 NewNeig.Add(ResNeig);
956 NewNeig.Add(MapShapeRes(Neig));
960 //---------------------------------------------
961 // Filtre la solution par le resultat du voisin.
962 // ie : F est solution si ses voisins dans CurSol
963 // sont dans les descendants des voisins
964 //---------------------------------------------
965 TNaming_ShapesSet Reject;
966 TNaming_IteratorOnShapesSet itRes(Res);
968 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
971 for (; itRes.More(); itRes.Next()) {
972 const TopoDS_Shape& Cand = itRes.Value();
973 TopTools_MapOfShape Neighbourg;
974 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
975 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
976 for (; itNeig.More(); itNeig.Next()) {
977 const TopoDS_Shape& Neig = itNeig.Key();
978 if (!NewNeig.Contains(Neig)) {