7fd59977 |
1 | // Copyright: Matra-Datavision 1995 |
2 | // File: BRepToIGES_BRSolid.cxx |
3 | // Created: Mon Jan 30 11:51:46 1995 |
4 | // Author: Marie Jose MARTZ |
5 | // <mjm> |
6 | |
7 | |
8 | #include <BRepToIGES_BRSolid.ixx> |
9 | #include <BRepToIGES_BRShell.hxx> |
10 | #include <BRepToIGES_BRWire.hxx> |
11 | |
12 | #include <BRep_Tool.hxx> |
13 | #include <BRepTools.hxx> |
14 | |
15 | #include <IGESBasic_Group.hxx> |
16 | #include <IGESData_HArray1OfIGESEntity.hxx> |
17 | #include <IGESData_IGESEntity.hxx> |
18 | |
19 | #include <Interface_Macros.hxx> |
20 | |
21 | #include <TColStd_HSequenceOfTransient.hxx> |
22 | |
23 | |
24 | #include <TopoDS.hxx> |
25 | #include <TopoDS_Compound.hxx> |
26 | #include <TopoDS_CompSolid.hxx> |
27 | #include <TopoDS_Edge.hxx> |
28 | #include <TopoDS_Face.hxx> |
29 | #include <TopoDS_Solid.hxx> |
30 | #include <TopoDS_Shape.hxx> |
31 | #include <TopoDS_Shell.hxx> |
32 | #include <TopoDS_Vertex.hxx> |
33 | #include <TopoDS_Wire.hxx> |
34 | |
35 | #include <TopAbs_ShapeEnum.hxx> |
36 | #include <TopExp.hxx> |
37 | #include <TopExp_Explorer.hxx> |
38 | |
39 | |
0d969553 |
40 | // At first only the geometry is translated (point, curve...) |
7fd59977 |
41 | |
42 | //============================================================================= |
43 | // BRepToIGES_BRSolid |
44 | //============================================================================= |
45 | |
46 | BRepToIGES_BRSolid::BRepToIGES_BRSolid() |
47 | { |
48 | } |
49 | |
50 | |
51 | //============================================================================= |
52 | // BRepToIGES_BRSolid |
53 | //============================================================================= |
54 | |
55 | BRepToIGES_BRSolid::BRepToIGES_BRSolid |
56 | (const BRepToIGES_BREntity& BR) |
57 | : BRepToIGES_BREntity(BR) |
58 | { |
59 | } |
60 | |
61 | |
62 | //============================================================================= |
63 | // TransferSolid |
64 | //============================================================================= |
65 | |
66 | Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferSolid(const TopoDS_Shape& start) |
67 | { |
68 | Handle(IGESData_IGESEntity) res; |
69 | |
70 | if (start.IsNull()) return res; |
71 | |
72 | if (start.ShapeType() == TopAbs_SOLID) { |
73 | TopoDS_Solid M = TopoDS::Solid(start); |
74 | res = TransferSolid(M); |
75 | } |
76 | else if (start.ShapeType() == TopAbs_COMPSOLID) { |
77 | TopoDS_CompSolid C = TopoDS::CompSolid(start); |
78 | res = TransferCompSolid(C); |
79 | } |
80 | else if (start.ShapeType() == TopAbs_COMPOUND) { |
81 | TopoDS_Compound C = TopoDS::Compound(start); |
82 | res = TransferCompound(C); |
83 | } |
84 | else { |
0d969553 |
85 | // error message |
7fd59977 |
86 | } |
87 | return res; |
88 | } |
89 | |
90 | |
91 | //============================================================================= |
92 | // TransferSolid |
93 | // |
94 | //============================================================================= |
95 | |
96 | Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferSolid(const TopoDS_Solid& start) |
97 | { |
98 | Handle(IGESData_IGESEntity) res; |
99 | if ( start.IsNull()) return res; |
100 | |
101 | TopExp_Explorer Ex; |
102 | Handle(IGESData_IGESEntity) IShell; |
103 | BRepToIGES_BRShell BS(*this); |
104 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
105 | |
106 | for (Ex.Init(start,TopAbs_SHELL); Ex.More(); Ex.Next()) { |
107 | TopoDS_Shell S = TopoDS::Shell(Ex.Current()); |
108 | if (S.IsNull()) { |
109 | AddWarning(start," an Shell is a null entity"); |
110 | } |
111 | else { |
112 | IShell = BS.TransferShell(S); |
113 | if (!IShell.IsNull()) Seq->Append(IShell); |
114 | } |
115 | } |
116 | |
117 | |
118 | Standard_Integer nbshells = Seq->Length(); |
119 | Handle(IGESData_HArray1OfIGESEntity) Tab; |
120 | if ( nbshells >= 1) { |
121 | Tab = new IGESData_HArray1OfIGESEntity(1,nbshells); |
122 | for (Standard_Integer itab = 1; itab <= nbshells; itab++) { |
123 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); |
124 | Tab->SetValue(itab,item); |
125 | } |
126 | } |
127 | |
128 | if (nbshells == 1) { |
129 | res = IShell; |
130 | } |
131 | else { |
132 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
133 | IGroup->Init(Tab); |
134 | res = IGroup; |
135 | } |
136 | |
137 | SetShapeResult ( start, res ); |
138 | |
139 | return res; |
140 | } |
141 | |
142 | |
143 | //============================================================================= |
144 | // TransferCompSolid |
145 | //============================================================================= |
146 | |
147 | Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferCompSolid(const TopoDS_CompSolid& start) |
148 | { |
149 | Handle(IGESData_IGESEntity) res; |
150 | if ( start.IsNull()) return res; |
151 | |
152 | TopExp_Explorer Ex; |
153 | Handle(IGESData_IGESEntity) ISolid; |
154 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
155 | |
156 | for (Ex.Init(start,TopAbs_SOLID); Ex.More(); Ex.Next()) { |
157 | TopoDS_Solid S = TopoDS::Solid(Ex.Current()); |
158 | if (S.IsNull()) { |
159 | AddWarning(start," an Solid is a null entity"); |
160 | } |
161 | else { |
162 | ISolid = TransferSolid(S); |
163 | if (!ISolid.IsNull()) Seq->Append(ISolid); |
164 | } |
165 | } |
166 | |
167 | |
168 | Standard_Integer nbsolids = Seq->Length(); |
169 | Handle(IGESData_HArray1OfIGESEntity) Tab; |
170 | if ( nbsolids >= 1) { |
171 | Tab = new IGESData_HArray1OfIGESEntity(1,nbsolids); |
172 | for (Standard_Integer itab = 1; itab <= nbsolids; itab++) { |
173 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); |
174 | Tab->SetValue(itab,item); |
175 | } |
176 | } |
177 | |
178 | if (nbsolids == 1) { |
179 | res = ISolid; |
180 | } |
181 | else { |
182 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
183 | IGroup->Init(Tab); |
184 | res = IGroup; |
185 | } |
186 | |
187 | SetShapeResult ( start, res ); |
188 | |
189 | return res; |
190 | } |
191 | |
192 | |
193 | //============================================================================= |
194 | // TransferCompound |
195 | //============================================================================= |
196 | |
197 | Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferCompound(const TopoDS_Compound& start) |
198 | { |
199 | Handle(IGESData_IGESEntity) res; |
200 | if ( start.IsNull()) return res; |
201 | |
202 | |
203 | TopExp_Explorer Ex; |
204 | Handle(IGESData_IGESEntity) IShape; |
205 | BRepToIGES_BRShell BS(*this); |
206 | BRepToIGES_BRWire BW(*this); |
207 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
208 | |
0d969553 |
209 | // take all Solids |
7fd59977 |
210 | for (Ex.Init(start, TopAbs_SOLID); Ex.More(); Ex.Next()) { |
211 | TopoDS_Solid S = TopoDS::Solid(Ex.Current()); |
212 | if (S.IsNull()) { |
213 | AddWarning(start," a Solid is a null entity"); |
214 | } |
215 | else { |
216 | IShape = TransferSolid(S); |
217 | if (!IShape.IsNull()) Seq->Append(IShape); |
218 | } |
219 | } |
220 | |
0d969553 |
221 | // take all isolated Shells |
7fd59977 |
222 | for (Ex.Init(start, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next()) { |
223 | TopoDS_Shell S = TopoDS::Shell(Ex.Current()); |
224 | if (S.IsNull()) { |
225 | AddWarning(start," a Shell is a null entity"); |
226 | } |
227 | else { |
228 | IShape = BS.TransferShell(S); |
229 | if (!IShape.IsNull()) Seq->Append(IShape); |
230 | } |
231 | } |
232 | |
233 | |
0d969553 |
234 | // take all isolated Faces |
7fd59977 |
235 | for (Ex.Init(start, TopAbs_FACE, TopAbs_SHELL); Ex.More(); Ex.Next()) { |
236 | TopoDS_Face S = TopoDS::Face(Ex.Current()); |
237 | if (S.IsNull()) { |
238 | AddWarning(start," a Face is a null entity"); |
239 | } |
240 | else { |
241 | IShape = BS.TransferFace(S); |
242 | if (!IShape.IsNull()) Seq->Append(IShape); |
243 | } |
244 | } |
245 | |
246 | |
0d969553 |
247 | // take all isolated Wires |
7fd59977 |
248 | for (Ex.Init(start, TopAbs_WIRE, TopAbs_FACE); Ex.More(); Ex.Next()) { |
249 | TopoDS_Wire S = TopoDS::Wire(Ex.Current()); |
250 | if (S.IsNull()) { |
251 | AddWarning(start," a Wire is a null entity"); |
252 | } |
253 | else { |
254 | IShape = BW.TransferWire(S); |
255 | if (!IShape.IsNull()) Seq->Append(IShape); |
256 | } |
257 | } |
258 | |
259 | |
0d969553 |
260 | // take all isolated Edges |
7fd59977 |
261 | for (Ex.Init(start, TopAbs_EDGE, TopAbs_WIRE); Ex.More(); Ex.Next()) { |
262 | TopoDS_Edge S = TopoDS::Edge(Ex.Current()); |
263 | if (S.IsNull()) { |
264 | AddWarning(start," an Edge is a null entity"); |
265 | } |
266 | else { |
267 | IShape = BW.TransferEdge(S, Standard_False); |
268 | if (!IShape.IsNull()) Seq->Append(IShape); |
269 | } |
270 | } |
271 | |
272 | |
0d969553 |
273 | // take all isolated Vertices |
7fd59977 |
274 | for (Ex.Init(start, TopAbs_VERTEX, TopAbs_EDGE); Ex.More(); Ex.Next()) { |
275 | TopoDS_Vertex S = TopoDS::Vertex(Ex.Current()); |
276 | if (S.IsNull()) { |
277 | AddWarning(start," a Vertex is a null entity"); |
278 | } |
279 | else { |
280 | IShape = BW.TransferVertex(S); |
281 | if (!IShape.IsNull()) Seq->Append(IShape); |
282 | } |
283 | } |
284 | |
0d969553 |
285 | // construct the group |
7fd59977 |
286 | Standard_Integer nbshapes = Seq->Length(); |
287 | Handle(IGESData_HArray1OfIGESEntity) Tab; |
288 | if (nbshapes >=1) { |
289 | Tab = new IGESData_HArray1OfIGESEntity(1,nbshapes); |
290 | for (Standard_Integer itab = 1; itab <= nbshapes; itab++) { |
291 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); |
292 | Tab->SetValue(itab,item); |
293 | } |
294 | } |
295 | |
296 | if (nbshapes == 1) { |
297 | res = IShape; |
298 | } |
299 | else { |
300 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
301 | IGroup->Init(Tab); |
302 | res = IGroup; |
303 | } |
304 | |
305 | SetShapeResult ( start, res ); |
306 | |
307 | return res; |
308 | } |