// Created on: 1999-09-30 // Created by: Denis PASCAL // Copyright (c) 1999-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#define MDTV_DEB_SEL #ifdef OCCT_DEBUG_SEL //#define MDTV_DEB_BNP #include #include #include #include #include #include void PrintEntry(const TDF_Label& label, const Standard_Boolean allLevels) { TCollection_AsciiString entry; TDF_Tool::Entry(label, entry); cout << "LabelEntry = "<< entry << endl; if(allLevels) { TDF_ChildIterator it (label, allLevels); for (; it.More(); it.Next()) { TDF_Tool::Entry(it.Value(), entry); cout << "ChildLabelEntry = "<< entry << endl; } } } #include static void Write(const TopoDS_Shape& shape, const Standard_CString filename) { char buf[256]; if(strlen(filename) > 255) return; #if defined _MSC_VER strcpy_s (buf, filename); #else strcpy (buf, filename); #endif char* p = buf; while (*p) { if(*p == ':') *p = '-'; p++; } ofstream save (buf); if(!save) cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl; save << "DBRep_DrawableShape" << endl << endl; if(!shape.IsNull()) BRepTools::Write(shape, save); save.close(); } #endif #define ORIENTATION_DSOPT #ifdef ORIENTATION_DSOPT #include #include #include #include #include #include #include //========================================================================================== inline static void MapOfOrientedShapes(const TopoDS_Shape& S, TopTools_MapOfOrientedShape& M) { M.Add(S); TopoDS_Iterator It(S,Standard_True,Standard_True); while (It.More()) { MapOfOrientedShapes(It.Value(),M); It.Next(); } } //======================================================================= static void BuildAtomicMap(const TopoDS_Shape& S, TopTools_MapOfOrientedShape& M) { if(S.ShapeType() > TopAbs_COMPSOLID) return; TopoDS_Iterator it(S); for(;it.More();it.Next()) { if(it.Value().ShapeType() > TopAbs_COMPSOLID) M.Add(it.Value()); else BuildAtomicMap(it.Value(), M); } } //========================================================================================== static const Handle(TNaming_NamedShape) FindPrevNDS(const Handle(TNaming_NamedShape)& CNS) { Handle(TNaming_NamedShape) aNS; TNaming_Iterator it(CNS); if(it.More()) { if(!it.OldShape().IsNull()) { aNS = TNaming_Tool::NamedShape(it.OldShape(), CNS->Label()); return aNS; } } return aNS; } //========================================================================================== // Purpose: checks correspondens between orientation of sub-shapes of Context and orientation // of sub-shapes registered in DF and put under result label //========================================================================================== static Standard_Boolean IsSpecificCase(const TDF_Label& F, const TopoDS_Shape& Context) { Standard_Boolean isFound(Standard_False); TopTools_MapOfOrientedShape shapesOfContext; MapOfOrientedShapes(Context,shapesOfContext); Handle(TNaming_NamedShape) CNS = TNaming_Tool::NamedShape(Context, F); #ifdef OCCT_DEBUG_BNP PrintEntry (CNS->Label(),0); #endif if(!CNS.IsNull()) { TNaming_ListOfNamedShape aLNS; TDF_ChildIDIterator cit(CNS->Label(), TNaming_NamedShape::GetID(), Standard_False); if(!cit.More()) { // Naming data structure is empty - no sub-shapes under resulting shape const Handle(TNaming_NamedShape) aNS = FindPrevNDS(CNS); //look to old shape data structure if exist if(!aNS.IsNull()) { #ifdef OCCT_DEBUG_BNP PrintEntry (aNS->Label(),0); #endif cit.Initialize(aNS->Label(), TNaming_NamedShape::GetID(), Standard_False); } else return Standard_True; } for(;cit.More();cit.Next()) { Handle(TNaming_NamedShape) NS (Handle(TNaming_NamedShape)::DownCast(cit.Value())); if(!NS.IsNull()) { TopoDS_Shape aS = TNaming_Tool::CurrentShape(NS); if(aS.IsNull()) continue; #ifdef OCCT_DEBUG_BNP PrintEntry(NS->Label(), 0); cout <<"ShapeType =" << aS.ShapeType() < "; PrintEntry(myLabel,0); #endif if (myLabel.FindAttribute(TNaming_Naming::GetID(),name)) { return name->Solve(Valid); } return Standard_False; } //======================================================================= //function : Arguments //purpose : //======================================================================= void TNaming_Selector::Arguments (TDF_AttributeMap& args) const { TDF_Tool::OutReferences(myLabel,args); } //======================================================================= //function : TNaming_Selector //purpose : //======================================================================= Handle(TNaming_NamedShape) TNaming_Selector::NamedShape() const { Handle(TNaming_NamedShape) NS; myLabel.FindAttribute(TNaming_NamedShape::GetID(),NS); return NS; }