1 // Created on: 1999-06-30
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1999-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 <BRep_TEdge.hxx>
19 #include <BRep_TFace.hxx>
20 #include <BRep_TVertex.hxx>
21 #include <BRepTools.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
24 #include <TNaming_CopyShape.hxx>
25 #include <TNaming_Translator.hxx>
26 #include <TopLoc_Datum3D.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_TCompound.hxx>
29 #include <TopoDS_TCompSolid.hxx>
30 #include <TopoDS_TShape.hxx>
31 #include <TopoDS_TShell.hxx>
32 #include <TopoDS_TSolid.hxx>
33 #include <TopoDS_TWire.hxx>
34 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
36 //=======================================================================
37 //function : TNaming_Translator
39 //=======================================================================
40 TNaming_Translator::TNaming_Translator () :myIsDone(Standard_False)
42 myDataMapOfResults.Clear();
45 //=======================================================================
48 //=======================================================================
50 void TNaming_Translator::Add(const TopoDS_Shape& aShape)
53 myDataMapOfResults.Bind(aShape, aResult);
56 //=======================================================================
59 //=======================================================================
61 Standard_Boolean TNaming_Translator::IsDone() const
66 //=======================================================================
69 //=======================================================================
71 const TopTools_DataMapOfShapeShape& TNaming_Translator::Copied() const
73 return myDataMapOfResults;
76 //=======================================================================
78 //purpose : find bind shape if it is in the Map
79 //=======================================================================
81 const TopoDS_Shape TNaming_Translator::Copied(const TopoDS_Shape& aShape) const
84 if(myDataMapOfResults.IsBound(aShape))
85 aResult = myDataMapOfResults.Find(aShape);
89 //=======================================================================
92 //=======================================================================
94 void TNaming_Translator::Perform()
97 TopTools_DataMapIteratorOfDataMapOfShapeShape itm(myDataMapOfResults);
98 for(;itm.More();itm.Next()) {
99 TNaming_CopyShape::CopyTool(itm.Key(), myMap, Result);
101 myDataMapOfResults(itm.Key()) = Result;
104 if(myDataMapOfResults.Extent()) myIsDone = Standard_True;
107 //=======================================================================
110 //=======================================================================
112 void TNaming_Translator::DumpMap(const Standard_Boolean isWrite) const
114 TCollection_AsciiString name("Map");
115 TCollection_AsciiString keyname;
116 TCollection_AsciiString itemname;
117 keyname = name.Cat("_Key");
118 itemname = name.Cat("_Item");
120 if (!myMap.Extent()) return;
122 cout <<"TNaming_Translator:: IndexedDataMap Extent = "<< myMap.Extent() << endl;
124 for (Standard_Integer i=1; i <= myMap.Extent(); i++)
126 cout <<"TNaming_Translator::DumpMap: Index = "<< i << " Type = "<< (myMap.FindKey(i))->DynamicType() << endl;
127 Handle(Standard_Type) T = (myMap.FindKey(i))->DynamicType();
128 if((T == STANDARD_TYPE (BRep_TVertex)) ||(T == STANDARD_TYPE (BRep_TEdge)) ||
129 T == STANDARD_TYPE (BRep_TFace)|| T == STANDARD_TYPE (TopoDS_TWire)||
130 T == STANDARD_TYPE (TopoDS_TShell) || T == STANDARD_TYPE (TopoDS_TSolid) ||
131 T == STANDARD_TYPE (TopoDS_TCompSolid)|| T == STANDARD_TYPE (TopoDS_TCompound))
134 Handle(TopoDS_TShape) key (Handle(TopoDS_TShape)::DownCast(myMap.FindKey(i)));
135 Handle(TopoDS_TShape) item (Handle(TopoDS_TShape)::DownCast(myMap.FindFromIndex(i)));
136 TopoDS_Shape S1; S1.TShape(key);
137 TopoDS_Shape S2; S2.TShape(item);
138 BRepTools::Write(S1, keyname.Cat(i).ToCString());
139 BRepTools::Write(S2, itemname.Cat(i).ToCString());
142 else if((myMap.FindKey(i))->DynamicType() == STANDARD_TYPE (TopLoc_Datum3D))
145 const Handle(TopLoc_Datum3D) key = Handle(TopLoc_Datum3D)::DownCast(myMap.FindKey(i));
146 const Handle(TopLoc_Datum3D) Item = Handle(TopLoc_Datum3D)::DownCast(myMap.FindFromIndex(i));
147 cout << "TNaming_Translator::DumpMap: Location_Key_name = "<< keyname.Cat(i).ToCString()<< endl;
148 key->ShallowDump(cout);
149 cout << "TNaming_Translator::DumpMap: Location_Item_name = "<< itemname.Cat(i).ToCString()<< endl;
150 Item->ShallowDump(cout);
154 cout <<"TNaming_Translator::DumpMap: Unexpected Type >> Idex = "<< i << " Type = "<<(myMap.FindKey(i))->DynamicType()<< endl;