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 <TNaming_Identifier.hxx>
19 #include <TNaming_Iterator.hxx>
20 #include <TNaming_ListOfNamedShape.hxx>
21 #include <TNaming_Localizer.hxx>
22 #include <TNaming_NamedShape.hxx>
23 #include <TNaming_OldShapeIterator.hxx>
24 #include <TNaming_Tool.hxx>
25 #include <TNaming_UsedShapes.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
30 #include <TopTools_ListOfShape.hxx>
35 #include <TDF_Tool.hxx>
36 #include <TDF_MapIteratorOfLabelMap.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <BRepTools.hxx>
40 void LPrintEntry(const TDF_Label& label)
42 TCollection_AsciiString entry;
43 TDF_Tool::Entry(label, entry);
44 std::cout << "LabelEntry = "<< entry << std::endl;
46 static void LWrite(const TopoDS_Shape& shape,
47 const Standard_CString filename)
50 if(strlen(filename) > 256) return;
52 strcpy_s (buf, filename);
54 strcpy (buf, filename);
62 std::ofstream save (buf);
64 std::cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << std::endl;
65 save << "DBRep_DrawableShape" << std::endl << std::endl;
66 if(!shape.IsNull()) BRepTools::Write(shape, save);
70 //=======================================================================
71 static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
72 const Standard_CString filename)
74 if(!NS.IsNull() && !NS->IsEmpty() ) {
75 TCollection_AsciiString aNam (filename);
76 TCollection_AsciiString oldS ("_Old");
77 TCollection_AsciiString newS ("_New_");
78 Standard_Integer i(0);
79 TNaming_Iterator it(NS);
80 for(;it.More(); it.Next(),i++) {
81 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
82 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
83 const TopoDS_Shape& oldShape = it.OldShape();
84 const TopoDS_Shape& newShape = it.NewShape();
85 if(!oldShape.IsNull())
86 LWrite ( oldShape, aName1.ToCString());
87 if(!newShape.IsNull())
88 LWrite ( newShape, aName2.ToCString());
94 //=======================================================================
95 //function : FindFeatureInAncestors
96 //purpose : Cherche les ancetres de S qui sont sous des labels
97 //=======================================================================
99 void TNaming_Localizer::FindFeaturesInAncestors
100 (const TopoDS_Shape& S,
101 const TopoDS_Shape& Context,
102 TopTools_MapOfShape& AncInFeature)
105 LWrite(S, "Localizer_S.brep");
106 LWrite(Context, "Localizer_Context.brep");
109 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
111 if (Anc.Contains(S)) {
113 std::cout <<"Localizer: S in ancestor" <<std::endl;
115 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
116 TopTools_ListIteratorOfListOfShape itL(L);
117 for (; itL.More(); itL.Next()) {
118 const TopoDS_Shape& AS = itL.Value();
120 LWrite(AS, "Localizer_AS.brep");
122 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
124 // if (TNaming_Tool::HasLabel(myUS,AS)) {
125 AncInFeature.Add(AS);
127 else if (AS.ShapeType() > TopAbs_FACE) {
128 FindFeaturesInAncestors (AS, Context, AncInFeature);
132 std::cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<std::endl;
140 std::cout <<" TNaming_Localization : S n est pas dans le solide"<<std::endl;//S is not in the solid
145 //=======================================================================
146 //function : SubShapes
148 //=======================================================================
150 const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
151 const TopAbs_ShapeEnum TS)
154 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
155 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
156 // Standard_Boolean Found = Standard_False;
157 for (; itS.More(); itS.Next(),itSS.Next()) {
158 if (In.IsSame(itS.Value())) {
159 TopTools_MapOfShape& SubShapes = itSS.Value();
160 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
161 const TopoDS_Shape& SS = exp.Current();
162 if (SubShapes.Contains(SS)) {
171 TopTools_MapOfShape emptyMap;
172 mySubShapes.Prepend(emptyMap);
173 myShapeWithSubShapes.Prepend(In);
175 TopTools_MapOfShape& SubShapes = mySubShapes.First();
176 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
177 const TopoDS_Shape& SS = exp.Current();
178 if (SubShapes.Contains(SS)) {
187 //=======================================================================
188 //function : Ancestors
190 //=======================================================================
192 const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
193 (const TopoDS_Shape& In,
194 const TopAbs_ShapeEnum TS)
196 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
197 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
198 // Standard_Boolean Found = Standard_False;
199 for (; itS.More(); itS.Next(),itA.Next()) {
200 if (In.IsSame(itS.Value())) {
201 //-----------------------
202 // Ancetres existent.
203 //-----------------------
204 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
206 TopExp_Explorer exp(In,TS);
208 if (!exp.More()) std::cout <<" TNaming_Localization : Construction ancetres impossible"<<std::endl;
210 const TopoDS_Shape& SS = exp.Current();
212 if (Anc.Contains(SS)) {
216 //----------------------------
217 // Completion des ancetres.
218 //----------------------------
219 TopAbs_ShapeEnum TA = TopAbs_FACE;
220 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
221 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
222 if (TA >= In.ShapeType()) {
223 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
227 std::cout <<" TNaming_Localization : Construction ancetres impossible"<<std::endl;
234 //-----------------------------------
235 // Construction des ancetres
236 //-----------------------------------
237 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
238 myShapeWithAncestors.Prepend(In);
239 myAncestors .Prepend(emptyAnc);
241 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
243 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
244 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
245 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
246 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
247 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
251 std::cout <<" TNaming_Localization : Construction ancetres impossible"<<std::endl;
254 return myAncestors.First();
257 //=======================================================================
260 //=======================================================================
262 Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
263 const Handle(TNaming_NamedShape)& NS)
265 TNaming_Iterator itLab(NS);
266 for (; itLab.More(); itLab.Next()) {
267 if (itLab.OldShape().IsSame(S)) {
268 return Standard_False;
270 if (itLab.NewShape().IsSame(S)) {
271 return Standard_True;
275 std::cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<std::endl;
277 return Standard_False;
281 //=======================================================================
284 //=======================================================================
286 void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
287 const TDF_Label& Lab,
288 const TNaming_Evolution Evol,
289 TopTools_ListOfShape& LBS,
290 TNaming_ListOfNamedShape& LBNS)
292 // Standard_Integer TrDef;
294 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
297 //-----------------------------------------------------------
298 // Pas d'ascendants => Recherche et exploration du contenant
299 //----------------------------------------------------------
300 const TDF_Label& Father = Lab.Father();
301 TNaming_Iterator itLab(Father);
303 Sol = itLab.OldShape();
304 //-------------------------------------------
305 // Recherche des ancetres dans des features.
306 //-------------------------------------------
308 TopTools_MapOfShape AncInFeature;
309 FindFeaturesInAncestors (S, Sol, AncInFeature);
310 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
311 for ( ; itF.More(); itF.Next()) {
312 const TopoDS_Shape& AncOfS = itF.Key();
314 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
319 for ( ; it.More(); it.Next()) {
320 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
321 if (it.NamedShape()->Evolution() == Evol) {
322 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
324 LBS.Append (it.Shape());
325 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
329 std::cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<std::endl;
337 //=======================================================================
338 //function : Backward
340 //=======================================================================
342 void TNaming_Localizer::Backward (const TopoDS_Shape& S,
343 TDF_LabelMap& Primitives,
344 TopTools_MapOfShape& ValidShapes)
346 Standard_Integer PrevTrans = myCurTrans - 1;
347 Standard_Integer TrDef;
348 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
349 TNaming_Evolution Evol = Evolution(Lab);
352 TopTools_ListOfShape LBS;
355 GoBack(S,Lab,LBS,LBLab);
358 TopTools_ListIteratorOfListOfShape itLBS (LBS);
359 TDF_ListIteratorOfLabelList itLBLab(LBLab);
364 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
365 const TopoDS_Shape& OS = itLBS.Value();
366 const TDF_Label& LabOS = itLBLab.Value();
368 Evol = Evolution(LabOS);
370 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
371 //---------------------------------------------------------
372 // Le Shape est valid dans la transaction myCurTrans => STOP
373 //---------------------------------------------------------
376 else if (Evol == TNaming_PRIMITIVE) {
377 Primitives.Add(LabOS);
379 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
380 //--------------------------------------------------------------
381 // Passage par une generation
382 // le shape dans myCurTrans descendra d un element de cet attribut.
383 // Localisation de OS dans la transaction courrante.
384 // les shapes obtenus seront des antecedants du shape cherche.
385 //--------------------------------------------------------------
387 // A faire seulememt si OS est un newShape dans LabOS.
388 TNaming_ShapesSet ResGen;
390 TDF_Label Father = LabOS.Father();
391 TNaming_Iterator itLab(Father,PrevTrans);
392 for (; itLab.More(); itLab.Next()) {
393 PrevIn= itLab.OldShape();
396 Localize(PrevIn,LabOS,OS,ResGen);
397 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
398 ValidShapes.Add(itLoc.Value());
401 else if (Evol == TNaming_SELECTED) {
403 TNaming_ShapesSet ResSel;
404 TopoDS_Shape PrevIn,CurIn;
405 // FindIn (LabOS,PrevIn,CurIn);
406 Localize(PrevIn,CurIn,OS,ResSel);
407 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
408 ValidShapes.Add(itLoc.Value());
412 Backward(itLBS.Value(),Primitives,ValidShapes);
418 //=======================================================================
419 //function : NamedShape
421 //=======================================================================
423 Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
425 Handle(TNaming_NamedShape) NS;
426 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
430 //=======================================================================
431 //function : Backward
433 //=======================================================================
435 void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
436 const TopoDS_Shape& S,
437 TNaming_MapOfNamedShape& Primitives,
438 TopTools_MapOfShape& Shapes)
440 TNaming_Evolution Evol = NS->Evolution();
441 TDF_Label LabNS = NS->Label();
443 TopTools_ListOfShape LBS;
444 TNaming_ListOfNamedShape LBNS;
446 GoBack(S,LabNS,Evol,LBS,LBNS);
449 TopTools_ListIteratorOfListOfShape itLBS (LBS);
450 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
455 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
456 const TopoDS_Shape& OS = itLBS.Value();
457 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
458 Evol = NOS->Evolution();
459 if (Evol == TNaming_PRIMITIVE) {
462 else if (Evol == TNaming_GENERATED) {
466 Backward(NOS, itLBS.Value(),Primitives,Shapes);
471 //=======================================================================
472 //function : ValidCandidat
474 //=======================================================================
477 /*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
478 const TopTools_MapOfShape& ShapeOfSol,
479 TopAbs_ShapeEnum TargetType,
480 TNaming_ShapesSet& Res)
482 Standard_Boolean Valid = Standard_False;
484 if (ShapeOfSol.Contains(S)) {
485 if (S.ShapeType() == TargetType) {
487 return Standard_True;
489 else if (S.ShapeType() < TargetType) {
490 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
491 const TopoDS_Shape& SS = exp.Current();
493 Valid = Standard_True;
502 //=======================================================================
505 //=======================================================================
507 void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
508 const TopTools_MapOfShape& Target,
509 const TopAbs_ShapeEnum TargetType,
510 TNaming_ShapesSet& Res)
513 Standard_Integer TrDef;
514 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
515 if (StoreValid (S, Target, TargetType, Res)) {
518 TNaming_Evolution Evol = Evolution(Lab);
519 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
521 for ( ; NewIt.More(); NewIt.Next()) {
522 const TopoDS_Shape& NS = NewIt.Shape();
523 GoForward ( NS, Target, TargetType, Res);
529 //=======================================================================
530 //function : FindNeighbourg
532 //=======================================================================
534 void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
535 const TopoDS_Shape& S,
536 TopTools_MapOfShape& Neighbourg)
538 if(Sol.IsNull() || S.IsNull()) return;
539 TopAbs_ShapeEnum TA = S.ShapeType();
540 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
542 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
543 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
544 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
545 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
546 // szy 30.03.10 to process case when Candidate is of type Vertex
547 // if (TA == TopAbs_VERTEX) {
549 // std::cout <<"construction voisins des vertex impossible"<<std::endl;
553 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
554 const TopoDS_Shape& SS = Exp.Current();
555 if (!Anc.Contains(SS)) {
556 //----------------------------------------------------
557 // Construction des ancetres
558 //----------------------------------------------------
562 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
563 for ( ; itL.More(); itL.Next()) {
564 if (!itL.Value().IsSame(S)) {
565 Neighbourg.Add(itL.Value());
572 //=======================================================================
573 //function : TNaming_Localizer
575 //=======================================================================
577 TNaming_Localizer::TNaming_Localizer()
582 //=======================================================================
585 //=======================================================================
587 void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
588 const Standard_Integer CurTrans)
591 myCurTrans = CurTrans;
595 //=======================================================================
598 //=======================================================================
601 /*static void Explode (TNaming_ShapesSet& Res,
603 TNaming_ShapesSet& ResGoodType)
605 TNaming_IteratorOnShapesSet it(Res);
606 for ( ; it.More(); it.Next()) {
607 const TopoDS_Shape& S = it.Value();
608 TopExp_Explorer exp(S,TS);
609 for (; exp.More(); exp.Next()) {
610 ResGoodType.Add(exp.Current());
617 //=======================================================================
618 //function : Localize
620 //=======================================================================
622 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
623 const TopoDS_Shape& CurIn ,
624 const TopoDS_Shape& S,
625 TNaming_ShapesSet& Res)
628 TDF_LabelMap Primitives;
629 TopTools_MapOfShape ValidShapes;
630 Standard_Integer PrevTrans = myCurTrans-1;
632 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
634 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
637 Standard_Integer TrDef;
638 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
639 TNaming_Evolution Evol = Evolution(Lab);
640 if (Evol == TNaming_PRIMITIVE) {
641 //------------------------
642 // Label est une primitive
643 //------------------------
645 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
648 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
649 Localize(PrevIn,Lab,S,Res);
654 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
655 //-------------------
656 // Remontee Descente.
657 //-------------------
658 Backward (S, Primitives, ValidShapes);
659 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
662 //----------------------------------------------
663 // Localisation des ancetres.
664 //----------------------------------------------
665 TopTools_MapOfShape AncInFeature;
666 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
667 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
668 Standard_Boolean First = Standard_True;
670 for ( ; itF.More(); itF.Next()) {
671 const TopoDS_Shape& AncOfS = itF.Key();
672 TNaming_ShapesSet ResAnc;
674 Localize (PrevIn, CurIn, AncOfS, ResAnc);
676 //---------------------------
677 // Res = Commun des resultats
678 //---------------------------
680 Explode (ResAnc,S.ShapeType(),Res);
684 TNaming_ShapesSet ResGoodType;
685 Explode (ResAnc,S.ShapeType(),ResGoodType);
686 Res.Filter(ResGoodType);
693 //=======================================================================
694 //function : FindGenerator
695 //purpose : Finds all generators of the <S> kept in <NS>
696 //=======================================================================
698 void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
699 const TopoDS_Shape& S,
700 TopTools_ListOfShape& theListOfGenerators)
703 Handle(TNaming_UsedShapes) US;
704 TDF_Label LabNS = NS->Label();
705 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
707 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
708 if (it.Label() == LabNS) {
709 theListOfGenerators.Append(it.Shape());
710 // break; //szy 16.10.03
716 //=======================================================================
717 //function : FindShapeContext
718 //purpose : Finds context of the shape <S>.
719 // : Looks for all oldshapes kept at father label of <NS>.
720 // : If <S> validated as subshape of one of the old shapes -
721 // : this oldshape is Context.
722 //=======================================================================
724 void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
725 const TopoDS_Shape& S,
730 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
732 TopTools_ListOfShape aList;
733 TDF_Label Father = NS->Label().Father();
734 TNaming_Iterator itLab(Father);
735 for (; itLab.More(); itLab.Next()) {
736 aList.Append(itLab.OldShape()); //szy
739 TopTools_ListIteratorOfListOfShape it(aList);
740 Standard_Boolean found = 0;
741 for(;it.More();it.Next()) {
744 LWrite(SC, "FSC_OldShape.brep");
746 if (SC.IsNull()) continue;
748 if (SC.ShapeType() < S.ShapeType()) {
749 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
750 if (exp.Current().IsSame(S)) {
753 std::cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<std::endl;
764 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
767 std::cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
769 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
772 LWriteNSOnLabel(aNS, "FSC");
774 TNaming_Iterator anIter(aNS->Label());
775 for(;anIter.More();anIter.Next()) {
776 aShape = anIter.NewShape();
777 if (!aShape.IsNull()) break;
779 if (!aShape.IsNull()) SC=aShape;
787 //=======================================================================
788 //function : Localize
790 //=======================================================================
792 void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
793 const TDF_Label& InLab ,
794 const TopoDS_Shape& S,
795 TNaming_ShapesSet& Res)
798 TDF_LabelMap Primitives;
799 TopTools_MapOfShape ValidShapes;
800 Standard_Integer PrevTrans = myCurTrans - 1;
802 //---------------------------------------------
803 // Recuperation du nouveau contenant generateur.
804 //---------------------------------------------
806 TDF_Label Father = InLab.Father();
807 TNaming_Iterator itLab(Father,myCurTrans);
808 for (; itLab.More(); itLab.Next()) {
809 CurIn= itLab.OldShape();
813 Standard_Boolean First = 1;
814 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
816 for (; OldIt.More(); OldIt.Next()) {
817 if (OldIt.Label().IsEqual(InLab)) {
818 TNaming_ShapesSet RO;
819 TNaming_ShapesSet RInLab;
820 const TopoDS_Shape& OS = OldIt.Shape();
821 //---------------------------------
822 // Localisation des generateurs.
823 //---------------------------------
824 Localize(PrevIn,CurIn ,OS, RO);
826 //--------------------------------------------------------------------
827 // Resultat = intersection des descendants(dans InLab) des generateurs
828 //--------------------------------------------------------------------
829 TNaming_IteratorOnShapesSet itRO(RO);
830 for (; itRO.More(); itRO.Next()) {
831 const TopoDS_Shape& CO = itRO.Value();
832 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
833 for (; NewIt.More(); NewIt.Next()) {
834 if (NewIt.Label().IsEqual(InLab)) {
835 if (First) Res.Add(NewIt.Shape());
837 RInLab.Add(NewIt.Shape());
842 if (!First) Res.Filter(RInLab);
843 First = Standard_False;
848 //=======================================================================
851 //=======================================================================
853 void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
854 const TopAbs_ShapeEnum TS,
855 const TDF_LabelMap& Primitives,
856 const TopTools_MapOfShape& ValidShapes,
857 TNaming_ShapesSet& Res)
859 //-------------------------------------------------------
860 // Descente dans la transaction courrante = myCurTrans
861 //----------------------------------------------------------
862 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
863 Standard_Boolean First = 1;
864 Standard_Boolean YaFromValid = 0;
865 Standard_Boolean YaFromPrimitives = 0;
867 for (; itV.More(); itV.Next()) {
869 const TopoDS_Shape& NS = itV.Key();
871 GoForward (NS, CurSubShapes, TS, Res);
875 TNaming_ShapesSet ResNS;
876 GoForward (NS, CurSubShapes, TS, ResNS);
881 TDF_MapIteratorOfLabelMap itP(Primitives);
882 TNaming_ShapesSet ResPrim;
884 for ( ; itP.More(); itP.Next()) {
885 YaFromPrimitives = 1;
886 const TDF_Label& Lab = itP.Key();
887 TNaming_Iterator itL(Lab,myCurTrans);
888 TNaming_ShapesSet ResLab;
890 for (; itL.More(); itL.Next()) {
891 const TopoDS_Shape& NS = itL.NewShape();
892 GoForward (NS, CurSubShapes, TS, ResLab);
899 ResPrim.Filter(ResLab);
903 if (YaFromPrimitives) {
913 //=======================================================================
914 //function : FilterbyNeighbourgs
916 //=======================================================================
918 void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
919 const TopoDS_Shape& CurIn ,
920 const TopoDS_Shape& S,
921 TNaming_ShapesSet& Res)
923 TopTools_MapOfShape Neighbourg;
924 TopAbs_ShapeEnum TA = S.ShapeType();
925 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
926 TNaming_DataMapOfShapeShapesSet MapShapeRes;
927 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
928 Ancestors(PrevIn,TS);
930 //--------------------------------
931 // Construction des Voisins.
932 //--------------------------------
933 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
934 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
936 TNaming_ShapesSet NewNeig;
937 for (; itNeig.More(); itNeig.Next()) {
938 const TopoDS_Shape& Neig = itNeig.Key();
939 //--------------------------------------------
940 // Localisation des voisins.
941 //--------------------------------------------
942 if (!MapShapeRes.IsBound(Neig)) {
943 TNaming_ShapesSet ResNeig;
944 Localize(PrevIn,CurIn,Neig,ResNeig);
945 MapShapeRes.Bind(Neig,ResNeig);
946 NewNeig.Add(ResNeig);
949 NewNeig.Add(MapShapeRes(Neig));
953 //---------------------------------------------
954 // Filtre la solution par le resultat du voisin.
955 // ie : F est solution si ses voisins dans CurSol
956 // sont dans les descendants des voisins
957 //---------------------------------------------
958 TNaming_ShapesSet Reject;
959 TNaming_IteratorOnShapesSet itRes(Res);
961 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
964 for (; itRes.More(); itRes.Next()) {
965 const TopoDS_Shape& Cand = itRes.Value();
966 TopTools_MapOfShape Neighbourg;
967 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
968 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
969 for (; itNeig.More(); itNeig.Next()) {
970 const TopoDS_Shape& Neig = itNeig.Key();
971 if (!NewNeig.Contains(Neig)) {