b311480e |
1 | // Created on: 1999-06-30 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 1999-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <TNaming_Translator.ixx> |
24 | |
25 | #include <TopoDS_Shape.hxx> |
26 | #include <TCollection_AsciiString.hxx> |
27 | #include <TColStd_IndexedDataMapOfTransientTransient.hxx> |
28 | #include <TopoDS_TShape.hxx> |
29 | #include <BRepTools.hxx> |
30 | #include <TopLoc_Datum3D.hxx> |
31 | #include <BRep_TVertex.hxx> |
32 | #include <BRep_TFace.hxx> |
33 | #include <BRep_TEdge.hxx> |
34 | #include <TopoDS_TWire.hxx> |
35 | #include <TopoDS_TShell.hxx> |
36 | #include <TopoDS_TSolid.hxx> |
37 | #include <TopoDS_TCompSolid.hxx> |
38 | #include <TopoDS_TCompound.hxx> |
39 | #include <TNaming_CopyShape.hxx> |
40 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> |
41 | |
42 | //======================================================================= |
43 | //function : TNaming_Translator |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | TNaming_Translator::TNaming_Translator () :myIsDone(Standard_False) |
48 | { |
49 | myDataMapOfResults.Clear(); |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : Add |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | void TNaming_Translator::Add(const TopoDS_Shape& aShape) |
58 | { |
59 | TopoDS_Shape aResult; |
60 | myDataMapOfResults.Bind(aShape, aResult); |
61 | } |
62 | |
63 | //======================================================================= |
64 | //function : IsDone |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | Standard_Boolean TNaming_Translator::IsDone() const |
69 | { |
70 | return myIsDone; |
71 | } |
72 | |
73 | //======================================================================= |
74 | //function : Copied |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | const TopTools_DataMapOfShapeShape& TNaming_Translator::Copied() const |
79 | { |
80 | return myDataMapOfResults; |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : Copied |
85 | //purpose : find bind shape if it is in the Map |
86 | //======================================================================= |
87 | |
88 | const TopoDS_Shape TNaming_Translator::Copied(const TopoDS_Shape& aShape) const |
89 | { |
90 | TopoDS_Shape aResult; |
91 | if(myDataMapOfResults.IsBound(aShape)) |
92 | aResult = myDataMapOfResults.Find(aShape); |
93 | return aResult; |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : Perform |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | void TNaming_Translator::Perform() |
102 | { |
103 | TopoDS_Shape Result; |
104 | TopTools_DataMapIteratorOfDataMapOfShapeShape itm(myDataMapOfResults); |
105 | for(;itm.More();itm.Next()) { |
106 | TNaming_CopyShape::CopyTool(itm.Key(), myMap, Result); |
107 | if(!Result.IsNull()) |
108 | myDataMapOfResults(itm.Key()) = Result; |
109 | Result.Nullify(); |
110 | } |
111 | if(myDataMapOfResults.Extent()) myIsDone = Standard_True; |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : DumpMap |
116 | //purpose : |
117 | //======================================================================= |
118 | |
119 | void TNaming_Translator::DumpMap(const Standard_Boolean isWrite) const |
120 | { |
121 | TCollection_AsciiString name("Map"); |
122 | TCollection_AsciiString keyname; |
123 | TCollection_AsciiString itemname; |
124 | keyname = name.Cat("_Key"); |
125 | itemname = name.Cat("_Item"); |
126 | |
127 | if (!myMap.Extent()) return; |
128 | else |
129 | cout <<"TNaming_Translator:: IndexedDataMap Extent = "<< myMap.Extent() << endl; |
130 | |
131 | for (Standard_Integer i=1; i <= myMap.Extent(); i++) |
132 | { |
133 | cout <<"TNaming_Translator::DumpMap: Index = "<< i << " Type = "<< (myMap.FindKey(i))->DynamicType() << endl; |
134 | Handle(Standard_Type) T = (myMap.FindKey(i))->DynamicType(); |
135 | if((T == STANDARD_TYPE (BRep_TVertex)) ||(T == STANDARD_TYPE (BRep_TEdge)) || |
136 | T == STANDARD_TYPE (BRep_TFace)|| T == STANDARD_TYPE (TopoDS_TWire)|| |
137 | T == STANDARD_TYPE (TopoDS_TShell) || T == STANDARD_TYPE (TopoDS_TSolid) || |
138 | T == STANDARD_TYPE (TopoDS_TCompSolid)|| T == STANDARD_TYPE (TopoDS_TCompound)) |
139 | { |
140 | if(isWrite) { |
141 | const Handle(TopoDS_TShape)& key = Handle(TopoDS_TShape)::DownCast(myMap.FindKey(i)); |
142 | const Handle(TopoDS_TShape)& item = Handle(TopoDS_TShape)::DownCast(myMap.FindFromIndex(i)); |
143 | TopoDS_Shape S1; S1.TShape(key); |
144 | TopoDS_Shape S2; S2.TShape(item); |
145 | BRepTools::Write(S1, keyname.Cat(i).ToCString()); |
146 | BRepTools::Write(S2, itemname.Cat(i).ToCString()); |
147 | } |
148 | } |
149 | else if((myMap.FindKey(i))->DynamicType() == STANDARD_TYPE (TopLoc_Datum3D)) |
150 | { |
151 | if(isWrite) { |
152 | const Handle(TopLoc_Datum3D) key = Handle(TopLoc_Datum3D)::DownCast(myMap.FindKey(i)); |
153 | const Handle(TopLoc_Datum3D) Item = Handle(TopLoc_Datum3D)::DownCast(myMap.FindFromIndex(i)); |
154 | cout << "TNaming_Translator::DumpMap: Location_Key_name = "<< keyname.Cat(i).ToCString()<< endl; |
155 | key->ShallowDump(cout); |
156 | cout << "TNaming_Translator::DumpMap: Location_Item_name = "<< itemname.Cat(i).ToCString()<< endl; |
157 | Item->ShallowDump(cout); |
158 | } |
159 | } |
160 | else { |
161 | cout <<"TNaming_Translator::DumpMap: Unexpected Type >> Idex = "<< i << " Type = "<<(myMap.FindKey(i))->DynamicType()<< endl; |
162 | continue; |
163 | } |
164 | } |
165 | } |