// Created on: 1997-03-21 // Created by: Yves FRICAUD // Copyright (c) 1997-1999 Matra Datavision // Copyright (c) 1999-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // mpv modifications 08.04.2002 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // end of mpv modifications 08.04.2002 #include #define BUC60925 #define OCC352 #ifdef DEB_DBGTOOLS_WRITE //#define OCC355 #define MDTV_DEB #define MDTV_DEB_OR #define MDTV_DEB_UNN #define MDTV_DEB_INT #define MDTV_DEB_GEN #define MDTV_DEB_MODUN #define MDTV_DEB_FNB #define MDTV_DEB_WIN #define MDTV_DEB_ARG #define MDTV_DEB_SHELL #endif #ifdef MDTV_DEB #include #include #include #endif #ifdef DEB #include #include #include #include //======================================================================= void PrintEntry(const TDF_Label& label) { TCollection_AsciiString entry; TDF_Tool::Entry(label, entry); cout << "LabelEntry = "<< entry << endl; } //======================================================================= void PrintEntries(const TDF_LabelMap& map) { cout << "=== Labels Map ===" <IsEmpty() ) { TCollection_AsciiString aNam (filename); TCollection_AsciiString oldS ("_Old"); TCollection_AsciiString newS ("_New_"); Standard_Integer i(0); TNaming_Iterator it(NS); for(;it.More(); it.Next(),i++) { TCollection_AsciiString aName1 = aNam + oldS + i + ".brep"; TCollection_AsciiString aName2 = aNam + newS + i + ".brep"; const TopoDS_Shape& oldShape = it.OldShape(); const TopoDS_Shape& newShape = it.NewShape(); if(!oldShape.IsNull()) DbgTools_Write ( oldShape, aName1.ToCString()); if(!newShape.IsNull()) DbgTools_Write ( newShape, aName2.ToCString()); } } } #endif #endif // //==================================================================== static Standard_Boolean ValidArgs(const TNaming_ListOfNamedShape& Args) { TNaming_ListIteratorOfListOfNamedShape it(Args); for (;it.More();it.Next()) { const Handle(TNaming_NamedShape)& aNS = it.Value(); if(aNS.IsNull()) { #ifdef MDTV_DEB_ARG cout << "ValidArgs:: NS (Naming argument) is NULL" <IsEmpty()) { #ifdef MDTV_DEB_ARG TCollection_AsciiString entry; TDF_Tool::Entry(aNS->Label(), entry); cout << "ValidArgs:: Empty NS, Label = " << entry <IsValid()) { #ifdef MDTV_DEB_ARG TCollection_AsciiString entry; TDF_Tool::Entry(aNS->Label(), entry); cout << "ValidArgs::Not valid NS Label = " << entry <HasRelocation(it.Value(),NS); into.myArgs.Append (NS); } if (!myStop.IsNull()) { RT->HasRelocation(myStop,NS); into.myStop = NS; } if (!myContextLabel.IsNull()) { RT->HasRelocation(myContextLabel,into.myContextLabel); } } //======================================================================= //function : Arguments //purpose : //======================================================================= const TNaming_ListOfNamedShape& TNaming_Name::Arguments() const { return myArgs; } //======================================================================= //function : Arguments //purpose : //======================================================================= Handle(TNaming_NamedShape) TNaming_Name::StopNamedShape() const { return myStop; } //======================================================================= //function : Index //purpose : //======================================================================= Standard_Integer TNaming_Name::Index() const { return myIndex; } //======================================================================= //function : MakeShape //purpose : //======================================================================= static TopoDS_Shape MakeShape (const TopTools_MapOfShape& MS) { if (!MS.IsEmpty ()) { TopTools_MapIteratorOfMapOfShape it(MS); if (MS.Extent() == 1) { return it.Key(); } else { TopoDS_Compound C; BRep_Builder B; B.MakeCompound(C); for (; it.More(); it.Next()){ B.Add(C,it.Key()); } return C; } } return TopoDS_Shape(); } #ifdef OCC352 //======================================================================= //function : ShapeWithType //purpose : Tries to make shape with given type from the given shape //======================================================================= static TopoDS_Shape ShapeWithType(const TopoDS_Shape theShape, const TopAbs_ShapeEnum theType ) { if (theShape.IsNull() || theType == TopAbs_SHAPE) return theShape; Standard_Integer aType = theShape.ShapeType(); if (aType == theType) return theShape; TopTools_ListOfShape aShapes; if (aType == TopAbs_COMPOUND) { TopoDS_Iterator anIter(theShape); if (anIter.More()) aType = anIter.Value().ShapeType(); for(;anIter.More();anIter.Next()) aShapes.Append(anIter.Value()); if (aType == theType) { if (aShapes.Extent() == 1) return aShapes.First(); else return theShape; } } else aShapes.Append(theShape); TopoDS_Shape aResult; TopTools_ListIteratorOfListOfShape aListIter(aShapes); if (aType < theType) { Standard_Integer aCount; for(aCount=0;aListIter.More();aListIter.Next()) { TopExp_Explorer anExp(aListIter.Value(),theType); if (anExp.More()) { if (!anExp.Current().IsNull()) { aResult = anExp.Current(); aCount++; if (aCount > 1) return theShape; } } } if (aCount == 1) return aResult; } else { // if the shape type more complex than shapes from aShapes list, try make it switch (aType) { case TopAbs_VERTEX: // can't do something from vertex break; case TopAbs_EDGE: {// make wire from edges if (theType <= TopAbs_SOLID) break; BRepBuilderAPI_MakeWire aMakeWire; aMakeWire.Add(aShapes); if (!aMakeWire.IsDone()) return theShape; if (theType == TopAbs_WIRE) return aMakeWire.Wire(); aShapes.Clear(); // don't break: we can do something more of it aShapes.Append(aMakeWire.Wire()); aListIter.Initialize(aShapes); } case TopAbs_WIRE: {// make faceS from wires (one per one) if (theType < TopAbs_SOLID) break; TopTools_ListOfShape aFaces; for(;aListIter.More();aListIter.Next()) { BRepBuilderAPI_MakeFace aMakeFace(TopoDS::Wire(aListIter.Value())); if (!aMakeFace.IsDone()) aFaces.Append(aMakeFace.Face()); } if (theType == TopAbs_FACE) { if (aFaces.Extent() == 1) return aFaces.First(); return theShape; } aShapes.Assign(aFaces); // don't break: we can do something more of it aListIter.Initialize(aShapes); } case TopAbs_FACE: {// make shell from faces if (theType < TopAbs_SOLID) break; BRep_Builder aShellBuilder; TopoDS_Shell aShell; aShellBuilder.MakeShell(aShell); for(;aListIter.More();aListIter.Next()) aShellBuilder.Add(aShell,TopoDS::Face(aListIter.Value())); if (theType == TopAbs_SHELL) return aShell; aShapes.Clear(); // don't break: we can do something more of it aShapes.Append(aShell); aListIter.Initialize(aShapes); } case TopAbs_SHELL: {// make solids from shells (one per one) TopTools_ListOfShape aSolids; for(;aListIter.More();aListIter.Next()) { BRepBuilderAPI_MakeSolid aMakeSolid(TopoDS::Shell(aListIter.Value())); if (aMakeSolid.IsDone()) aSolids.Append(aMakeSolid.Solid()); } if (theType == TopAbs_SOLID) { if (aSolids.Extent() == 1) return aSolids.First(); return theShape; } aShapes.Assign(aSolids); // don't break: we can do something more of it aListIter.Initialize(aShapes); } case TopAbs_SOLID: {// make compsolid from solids BRep_Builder aCompBuilder; TopoDS_CompSolid aCompSolid; aCompBuilder.MakeCompSolid(aCompSolid); for(;aListIter.More();aListIter.Next()) aCompBuilder.Add(aCompSolid,TopoDS::Solid(aListIter.Value())); if (theType == TopAbs_COMPSOLID) return aCompSolid; } } } return theShape; } #endif //======================================================================= //function : FindModifUntil //purpose : //======================================================================= static Standard_Boolean FindModifUntil (TNaming_NewShapeIterator& it, TopTools_MapOfShape& MS, const TopoDS_Shape& S, const Handle(TNaming_NamedShape)& Context) { #ifdef MDTV_DEB_MODUN if(!Context.IsNull()) PrintEntry(Context->Label()); #endif Standard_Boolean found = Standard_False; for (; it.More(); it.Next()) { if (!it.Shape().IsNull()) { #ifdef MDTV_DEB_MODUN if(!it.NamedShape().IsNull()) PrintEntry(it.NamedShape()->Label()); #endif if (it.NamedShape() == Context) { MS.Add(S); found = Standard_True; } else { // New shape != Context TNaming_NewShapeIterator it2(it); found = FindModifUntil (it2,MS,it.Shape(),Context); } } } return found; } //======================================================================= //function : ModifUntil //purpose : returns map of generators of Target //======================================================================= static void SearchModifUntil (const TDF_LabelMap& /*Valid*/, const Handle(TNaming_NamedShape)& Target, const TNaming_ListOfNamedShape& theListOfGenerators, TopTools_MapOfShape& theMS) { #ifdef MDTV_DEB_MODUN DbgTools_WriteNSOnLabel(Target, "SMUntil_"); // Target <== generated Standard_Integer i = 0; TCollection_AsciiString aGen1("Gens_New_"), aGen2("Gented_Old_"), Und("_"); #endif // Test si S apparait comme oldshape dans Context. : Test if S appears as oldshape in Context. Standard_Boolean found = Standard_False; for (TNaming_ListIteratorOfListOfNamedShape it(theListOfGenerators); it.More(); it.Next()) { const Handle(TNaming_NamedShape)& aNS = it.Value(); #ifdef MDTV_DEB_MODUN i++; Standard_Integer j = 0; #endif for (TNaming_Iterator itL (aNS); itL.More(); itL.Next()) { // <- generators const TopoDS_Shape& S = itL.NewShape(); found = Standard_False; #ifdef MDTV_DEB_MODUN j++; Standard_Integer k = 0; TCollection_AsciiString aNam1 = aGen1 + i + Und + j + ".brep"; DbgTools_Write(S, aNam1.ToCString()); PrintEntry(aNS->Label());//NSLabel #endif TNaming_Iterator itC (Target); for (; itC.More(); itC.Next()) { // <- generated const TopoDS_Shape& OS = itC.OldShape(); #ifdef MDTV_DEB_MODUN k++; TCollection_AsciiString aNam2 = aGen2 + i + Und + j + Und + k + ".brep"; DbgTools_Write(OS, aNam2.ToCString()); PrintEntry(Target->Label());//Target Label #endif if (OS.IsSame(S)) { theMS.Add(S); found = Standard_True; #ifdef MDTV_DEB_MODUN cout << aNam2 << " is Same with " << aNam1 < "; PrintEntry(L); DbgTools_WriteNSOnLabel(Args.Last(), "ModifUntil-"); #endif // all last modifications of the last argument TNaming_NamingTool::CurrentShape (Valid, Forbiden,Args.Last(),MS); #ifdef MDTV_DEB_GEN Standard_Integer i(0); TopTools_MapIteratorOfMapOfShape it(MS); TCollection_AsciiString aNam("ModifUnti_MS_"); TCollection_AsciiString ext(".brep"); #endif TNaming_Builder B(L); for (TopTools_MapIteratorOfMapOfShape itM(MS); itM.More(); itM.Next()) { const TopoDS_Shape& S = itM.Key(); B.Select(S,S); #ifdef MDTV_DEB_GEN TCollection_AsciiString aName = aNam + ++i + ext; DbgTools_Write(S, aName.ToCString()) ; cout << aName.ToCString() << " TS = " << S.TShape()->This() <Get().IsNull()) { DbgTools_Write(Stop->Get(), "Ints_Stop.brep"); PrintEntry(Stop->Label()); } cout <<"Ints: ShapeType = " << ShapeType << endl; cout <<"Argument 1 at "; PrintEntry(it.Value()->Label()); #endif TNaming_NamingTool::BuildDescendants (Stop, Forbiden); // <==<1> #ifdef MDTV_DEB_INT cout << "Intersection:: Valid Map: "< aListOfAnc.Append(CS); #ifdef MDTV_DEB_INT if(!CS.IsNull()) DbgTools_Write(CS, "Int_CS_1.brep"); Standard_Integer i=2; TCollection_AsciiString aNam("Int_CS_"); TCollection_AsciiString ext(".brep"); #endif it.Next(); // <<===<3.1> for (; it.More(); it.Next()) { MS.Clear(); TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MS); CS = MakeShape(MS); aListOfAnc.Append(CS); #ifdef MDTV_DEB_INT TCollection_AsciiString aName = aNam + i++ + ext; DbgTools_Write(CS, aName.ToCString()) ; cout <<"Argument " << i << " at "; PrintEntry(it.Value()->Label()); #endif TNaming_ShapesSet OS(CS,ShapeType); S.Filter(OS); //<<===<3.2> #ifdef MDTV_DEB_INT Standard_Integer j = 1; TCollection_AsciiString aNam2("SSMap_"), aName3; TopTools_MapIteratorOfMapOfShape itm(S.Map()); for(;itm.More();itm.Next(), j++) { aName3 = aNam2 + i + "_" + j + ".brep"; DbgTools_Write(itm.Key(), aName3.ToCString()); } #endif } #ifdef MDTV_DEB_INT aNam = "Int_S_"; i =1; #endif TNaming_Builder B(L); //<<===<4> Standard_Boolean isOK(Standard_False); if(S.Map().Extent() > 1 && Index > 0 && ShapeType == TopAbs_EDGE) { Standard_Integer indxE(0), nbE(0), indxW(0),nbW(0), indxF(0); indxE = Index & 0x000000FF; nbE = (Index & 0x0000FF00) >> 8; indxW = (Index & 0x000F0000) >> 16; nbW = (Index & 0x00F00000) >> 20; indxF = (Index & 0x0F000000) >> 24; Standard_Integer i(1); TopoDS_Shape aS; TopTools_ListIteratorOfListOfShape itl(aListOfAnc); for(;itl.More();itl.Next(),i++) { if(indxF == i) { aS = itl.Value(); break; } } #ifdef MDTV_DEB_INT cout <<"Kept: indxE = " << indxE <<" maxENum = " << nbE << " indxW = " <Label(), entry); #endif MS.Clear(); TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value() CS = MakeShape(MS); if(isOr) KeepInList(CS,ShapeType,aListS); TNaming_ShapesSet OS(CS,ShapeType); S.Add(OS); //concatenate both shapesets #ifdef MDTV_DEB_UNN ii++; TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep"; DbgTools_Write(CS, aNm.ToCString()); cout <<"Arg: Entry = " < Generated"); } // First argument : label of generation // Next arguments : generators. #ifdef BUC60925 if(!ValidArgs(Args)) return Standard_False; #endif TDF_Label LabelOfGeneration = Args.First()->Label(); #ifdef MDTV_DEB_GEN DbgTools_Write(Args.First()->Get(), "Generated.brep") ; #endif // Nouvell valeurs des generateurs dans l attribut de generation TopTools_MapOfShape aMS; TNaming_ListOfNamedShape aGenerators; aGenerators.Assign(Args); aGenerators.RemoveFirst(); #ifdef MDTV_DEB_GEN DbgTools_Write(aGenerators.First()->Get(), "Generators.brep") ; #endif SearchModifUntil (Valid, Args.First(), aGenerators, aMS); Handle(TNaming_Naming) aNaming; TopoDS_Shape aSelection; L.FindAttribute(TNaming_Naming::GetID(),aNaming); if(!aNaming.IsNull()) aSelection = aNaming->GetName().Shape(); #ifdef MDTV_DEB_GEN DbgTools_Write(aSelection, "G_Selection.brep") ; cout << "Generated::SearchModifUntil aMS.Extent() = " << aMS.Extent() <Version(); #ifdef MDTV_DEB_GEN Standard_Integer i = 0, j=1; TCollection_AsciiString aNam2("Gen_New_"); TCollection_AsciiString aNam1("Gen_Old_"); TCollection_AsciiString ext(".brep"); #endif TNaming_Builder B(L); // NS TopTools_ListOfShape aList; TNaming_DataMapOfShapeMapOfShape aDM; for (TopTools_MapIteratorOfMapOfShape itMS(aMS); itMS.More(); itMS.Next()) { const TopoDS_Shape& OS = itMS.Key(); #ifdef MDTV_DEB_GEN TCollection_AsciiString aName = aNam1 + ++i + ext; DbgTools_Write(OS, aName.ToCString()) ; Standard_Integer j=0; #endif TNaming_MapOfShape aMapDM; for (TNaming_NewShapeIterator itNew(OS,L); itNew.More(); itNew.Next()) if (itNew.Label() == LabelOfGeneration) { aMapDM.Add(itNew.Shape()); aList.Append(itNew.Shape());//szy 21.10.03 #ifdef MDTV_DEB_GEN TCollection_AsciiString aName = aNam2 + i + "_" + ++j + ext; DbgTools_Write(itNew.Shape(), aName.ToCString()) ; #endif } if(aMapDM.Extent()) aDM.Bind(OS, aMapDM); } if(aVer == -1) { //initial Standard_Integer i = 1; TNaming_Name& aName = aNaming->ChangeName(); TopTools_ListIteratorOfListOfShape it(aList); if(!aSelection.IsNull()) { for(;it.More();it.Next(),i++) { if(it.Value().IsSame(aSelection)) { B.Select(it.Value(), it.Value()); aName.Index(i); // for debug - index of selection in the list break; } } } else {// Selection == Null for(;it.More();it.Next()) B.Select(it.Value(), it.Value()); } } else { // *** Regeneration *** // if(aList.Extent() == 1) { // trivial case B.Select(aList.Last(), aList.Last()); } else { TNaming_Name& aName = aNaming->ChangeName(); const TopAbs_ShapeEnum aType = aName.ShapeType(); TopTools_ListOfShape aList2; TopTools_ListIteratorOfListOfShape it(aList); for(;it.More();it.Next()) { if(it.Value().ShapeType() == aType) //collect only the same type aList2.Append(it.Value()); } if(!aList2.Extent()) return Standard_False; // Empty Standard_Boolean found = Standard_False; TopoDS_Shape aShape = FindShape(aDM); #ifdef MDTV_DEB_GEN if(!aShape.IsNull()) DbgTools_Write(aShape, "G_FindShape.brep") ; #endif if(!aShape.IsNull()) found = Standard_True; #ifdef MDTV_DEB_GEN cout << "Generated ==>aGenerators.Extent() = " < Shape is found!" < has lost generatos!" <Get())) aLM.Append(itg.Value()->Get()); } if(aLM.Extent() == 1) {//lost 1 TopTools_ListIteratorOfListOfShape itm(aLM); TopoDS_Shape aSM = itm.Value(); // Missed for (TopTools_MapIteratorOfMapOfShape itMS1(aMS); itMS1.More(); itMS1.Next()) { const TopoDS_Shape& aS = itMS1.Key(); if(aSM.ShapeType() == aS.ShapeType()) { if(aS.ShapeType() == TopAbs_EDGE) { TopoDS_Vertex aVCom; if(TopExp::CommonVertex(TopoDS::Edge(aS), TopoDS::Edge(aSM), aVCom)) {a1NB = Standard_True; break;} //lost only 1 neigbour } else if(aS.ShapeType() == TopAbs_FACE) { TopExp_Explorer expl1(aS, TopAbs_EDGE); for(;expl1.More();expl1.Next()) { TopExp_Explorer expl2(aSM, TopAbs_EDGE); for(;expl2.More();expl2.Next()) { if(expl1.Current().IsSame(expl2.Current())) {a1NB = Standard_True; break;} //lost only 1 neigbour } } } } } // if(aShape.ShapeType() == TopAbs_VERTEX && a1NBE) { // //if atleast 1 Gen was missed and the Gen is Edge // TopTools_ListIteratorOfListOfShape it(aList); // for(;it.More();it.Next()) { // if(it.Value().ShapeType() == TopAbs_EDGE) { // const TopoDS_Shape& aV1 = TopExp::FirstVertex(TopoDS::Edge(it.Value())); // const TopoDS_Shape& aV2 = TopExp::LastVertex(TopoDS::Edge(it.Value())); // if(aShape.IsSame(aV1)) {aShape2 = aV2; cout << "##### => V2 " < V1 " < Shape is NOT found! Probably Compound will be built" < 2) { Standard_ConstructionError::Raise("TNaming_Name::Solve"); } #ifdef BUC60925 if(!ValidArgs(Args)) return Standard_False; #endif const Handle(TNaming_NamedShape)& A = Args.First(); TopTools_MapOfShape MS; TDF_LabelMap Forbiden; TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS); #ifdef MDTV_DEB_SOL2 //TCollection_AsciiString entry; //TDF_Tool::Entry(L, entry); //TDF_Tool::Entry(A->Label(), entry); #endif TNaming_Builder B(L); for (TopTools_MapIteratorOfMapOfShape itM(MS); itM.More(); itM.Next()) { #ifdef OCC352 const TopoDS_Shape& S = ShapeWithType(itM.Key(),ShapeType); #else const TopoDS_Shape& S = itM.Key(); #endif #ifdef MDTV_DEB_SOL2 //TopAbs_Orientation Or = S.Orientation(); #endif B.Select(S,S); } return Standard_True; } //======================================================================= //function : FilterByNeighbourgs //purpose : regenerated the specified shape with help of its neighbours //======================================================================= // result - is a subshape of the first argument of the Name with type = // ShapeType of this Name, which has a common subshapes (boundaries) with // each neighbour - shapes from the other arguments of the Name. //======================================================================= static Standard_Boolean FilterByNeighbourgs (const TDF_Label& L, const TDF_LabelMap& Valid, const TNaming_ListOfNamedShape& Args, const Handle(TNaming_NamedShape)& Stop, const TopAbs_ShapeEnum ShapeType) { TNaming_Builder B(L); TDF_LabelMap Forbiden; #ifdef BUC60925 if(!ValidArgs(Args)) return Standard_False; #endif TNaming_NamingTool::BuildDescendants (Stop, Forbiden); //all descendants of Stop (New shapes) are forbidden if (!Stop.IsNull()) Forbiden.Remove(Stop->Label()); //---------------------------------------- // First argument: collection has to be filtered. //---------------------------------------- Handle(TNaming_NamedShape) Cand = Args.First(); //collection of candidates #ifdef MDTV_DEB_FNB Standard_Integer i = 1; TCollection_AsciiString aNam("Cand_"); TCollection_AsciiString ext(".brep"); DbgTools_WriteNSOnLabel(Cand, aNam.ToCString()); cout << "Cand (Args.First()) Label = "; PrintEntry(Cand->Label()); cout << "Valid Label map:" < for each Arg Standard_Boolean Connected = Standard_False; // Le candidat doit etre connexe a au moins un shape de // chaque NamedShape des voisins. // The candidate should be connectedand and have at least one shape of NamedShape // of each neighbor. const Handle(TNaming_NamedShape)& NSVois = it.Value(); //neighbor #ifdef MDTV_DEB_FNB DbgTools_WriteNSOnLabel(NSVois, "Next_Neighbor_") ; #endif TopTools_MapOfShape SVois; TNaming_NamingTool::CurrentShape (Valid, Forbiden,NSVois,SVois); // fills SVois with last modifications of NSVois #ifdef MDTV_DEB_FNB TCollection_AsciiString aNam2("SVois"); DbgTools_Write(SVois, aNam2.ToCString()); #endif for (TopTools_MapIteratorOfMapOfShape itVois(SVois); itVois.More(); itVois.Next()) { //6 const TopoDS_Shape& Vois = itVois.Key(); for (TopExp_Explorer exp1(Vois,TC); exp1.More(); exp1.Next()) { //7 if (Boundaries.Contains(exp1.Current())) { Connected = Standard_True; // has common boundaries with candidate shape #ifdef MDTV_DEB_FNB DbgTools_Write(Vois, "Neighbor_Connected.brep"); #endif break; } } //7 if (Connected) break; } //6 if (!Connected) { Keep = 0; break; } } //2 if (Keep) { B.Select (S,S); isDone = Standard_True; #ifdef MDTV_DEB_FNB DbgTools_Write(S, "FilterByNbs_Sel.brep") ; #endif } } //1 return isDone; } //======================================================================= static const TopoDS_Shape FindSubShapeInAncestor(const TopoDS_Shape& Selection, const TopoDS_Shape& Context ) { #ifdef MDTV_DEB_OR_AG DbgTools_Write(Selection, "Orientation_Selection.brep"); DbgTools_Write(Context, "Orientation_Context.brep"); TopExp_Explorer expl1(Context, Selection.ShapeType()); int i = 0; TCollection_AsciiString SS( "Orientation_Current_"); for(;expl1.More(); expl1.Next()) { if(expl1.Current().IsSame(Selection)) { i++; cout <<"FindSubShape: = " < TopAbs_COMPSOLID) { const TopoDS_Shape& CS = FindSubShapeInAncestor(sel, AS); if(!CS.IsNull()) { B.Select(CS, CS); N++; } } else N += Aggregation(sel, AS, B); } return N; } //========================================================================== //function : Orientation //purpose : to solve ORIENTATION name // this function explores the second argument | arguments (Context) and // keeps at the label (L) the first argument (S) with the orientation it // has in the context. Index is used only for Seam edge recomputing //========================================================================== static Standard_Boolean ORientation (const TDF_Label& L, const TDF_LabelMap& Valid, const TNaming_ListOfNamedShape& Args, const Handle(TNaming_NamedShape)& Stop, const Standard_Integer Index) { if(!ValidArgs(Args)) return Standard_False; const Handle(TNaming_NamedShape)& A = Args.First(); TopTools_MapOfShape MS; TDF_LabelMap Forbiden; TNaming_NamingTool::BuildDescendants (Stop, Forbiden); TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS); TopoDS_Shape S; Standard_Boolean isSplit(Standard_False); if (!MS.IsEmpty ()) { TopTools_MapIteratorOfMapOfShape it(MS); if (MS.Extent() == 1) { S = it.Key(); } else { isSplit = Standard_True; S = MakeShape(MS); #ifdef MDTV_DEB_OR for(Standard_Integer i=1;it.More();it.Next(), i++) { TCollection_AsciiString aNam("OR_Selection_"); TCollection_AsciiString aName = aNam + i + ".brep"; DbgTools_Write(it.Key(), aName.ToCString()); } #endif } } TNaming_Builder B(L); if(S.IsNull()) return Standard_False; #ifdef MDTV_DEB_OR DbgTools_Write(S, "Orientation_S.brep"); #endif TopTools_ListOfShape aSList; // tmp. solution if(S.ShapeType() == TopAbs_COMPOUND && !isSplit) { TopoDS_Iterator it(S); for(;it.More();it.Next()) aSList.Append(it.Value()); } // TopTools_MapOfShape MSC; if(aSList.Extent() == 0) { const Handle(TNaming_NamedShape)& Anc = Args.Last(); #ifdef MDTV_DEB_OR cout << "### ORIENTATION: Ancestor "; PrintEntry(Anc->Label()); #endif MSC.Clear(); TNaming_NamingTool::CurrentShape (Valid,Forbiden,Anc,MSC); if(MSC.Extent() == 1) { for (TopTools_MapIteratorOfMapOfShape itM(MSC); itM.More(); itM.Next()) { const TopoDS_Shape& AS = itM.Key(); // <=== start 21.10.2009 TopoDS_Shape CS; if(Index > 0) { //only for seam edge TopoDS_Iterator itw(AS); for(;itw.More();itw.Next()) { Standard_Boolean found(Standard_False); TopoDS_Iterator it(itw.Value()); for(int i=1;it.More();it.Next(),i++) { if(i == Index && it.Value().IsSame(S)) { CS = it.Value(); found = Standard_True; #ifdef MDTV_DEB_OR cout << "ORIENTATION => ORDER = " << i <SetValue(i, 1, it1.Value()); MSC.Clear(); TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MSC); if(MSC.Extent() == 1) { for (TopTools_MapIteratorOfMapOfShape itM(MSC); itM.More(); itM.Next()) { const TopoDS_Shape& AS = itM.Key(); Arr->SetValue(i, 2, AS); } } else { const TopoDS_Shape AS = MakeShape(MSC); Arr->SetValue(i, 2, AS); } } if(aSList.Extent() == 1) { const TopoDS_Shape& S = Arr->Value(1,1); if(S.ShapeType() != TopAbs_COMPOUND) { const TopoDS_Shape& CS = FindSubShapeInAncestor(S, Arr->Value(1,2)); if(!CS.IsNull()) { B.Select(CS, CS); } else return Standard_False; } else { #ifdef MDTV_DEB_OR DbgTools_Write(Arr->Value(1,2), "Ancestor.brep"); #endif if(!Aggregation(S, Arr->Value(1,2), B)) { return Standard_False; } } } else { // > 1 for(Standard_Integer i = Arr->LowerRow();i <= Arr->UpperRow();i++) { const TopoDS_Shape& S = Arr->Value(i,1); const TopoDS_Shape& AC = Arr->Value(i,2); if(S.ShapeType() != TopAbs_COMPOUND) { const TopoDS_Shape& CS = FindSubShapeInAncestor(S, AC); if(!CS.IsNull()) { B.Select(CS, CS); } else return Standard_False; } else { #ifdef MDTV_DEB_OR DbgTools_Write(AC, "Aggregation.brep"); #endif if(!Aggregation(S, AC, B)) { return Standard_False; } } } } } // end of tmp. solution return Standard_True; } //=========================================================================== //function : WireIN //purpose : to solve WIREIN name //======================================================================= static Standard_Boolean WireIN(const TDF_Label& L, const TDF_LabelMap& Valid, const TNaming_ListOfNamedShape& Args, const Handle(TNaming_NamedShape)& Stop, Standard_Integer Index) { Standard_Boolean aResult(Standard_False); if(!ValidArgs(Args)) return aResult; TopTools_MapOfShape MS; TDF_LabelMap Forbiden; if (Args.Extent() < 1 ) Standard_ConstructionError::Raise("TNaming_Name::Solve"); const Handle(TNaming_NamedShape)& A = Args.First(); TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS); if (MS.Extent() != 1) return aResult; TopTools_MapIteratorOfMapOfShape itM(MS); const TopoDS_Shape& aCF = itM.Key() ; #ifdef MDTV_DEB_WIN cout <<"MS Extent = " <Label(), entry); TCollection_AsciiString Nam("Arg_"); TCollection_AsciiString aNam = Nam + entry + "_" + "2.brep"; DbgTools_Write(CS, aNam.ToCString()); Standard_Integer ii = 2; #endif it.Next(); for (; it.More(); it.Next()) { #ifdef MDTV_DEB_WIN TDF_Tool::Entry(it.Value()->Label(), entry); #endif MS.Clear(); TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value() CS = MakeShape(MS); TNaming_ShapesSet OS(CS,TopAbs_EDGE); aSet.Add(OS); //concatenate both shapesets #ifdef MDTV_DEB_WIN ii++; TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep"; DbgTools_Write(CS, aNm.ToCString()); cout <<"Arg: Entry = " <Label(), entry); TCollection_AsciiString Nam("Arg_"); TCollection_AsciiString aNam = Nam + entry + "_" + "2.brep"; DbgTools_Write(CS, aNam.ToCString()); Standard_Integer ii = 2; #endif it.Next(); for (; it.More(); it.Next()) { #ifdef MDTV_DEB_SHELL TDF_Tool::Entry(it.Value()->Label(), entry); #endif MS.Clear(); TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value() CS = MakeShape(MS); TNaming_ShapesSet OS(CS,TopAbs_FACE); aSet.Add(OS); //concatenate both shapesets #ifdef MDTV_DEB_SHELL ii++; TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep"; DbgTools_Write(CS, aNm.ToCString()); cout <<"Arg: Entry = " < NameType = " << NameTypeToString(myType) << " "; PrintEntry(aLab); #endif } return Done; } //======================================================================= //function : ContextLabel //purpose : Set //======================================================================= void TNaming_Name::ContextLabel(const TDF_Label& theLabel) { myContextLabel = theLabel; } //======================================================================= //function : ContextLabel //purpose : Get //======================================================================= const TDF_Label& TNaming_Name::ContextLabel() const { return myContextLabel; } //======================================================================= //function : Orientation //purpose : Set //======================================================================= void TNaming_Name::Orientation(const TopAbs_Orientation theOrientation) { myOrientation = theOrientation; }