Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-04-25 |
2 | // Created by: Marie Jose MARTZ | |
3 | // Copyright (c) 1995-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 | // modif le 25/03/96 mjm | |
0d969553 | 24 | // implement ShapeCustom::DirectModification for indirect surfaces (out of norm IGES) |
7fd59977 | 25 | //:l4 abv 12 Jan 99: CTS22022-2: correct writing reversed shells |
26 | //:n3 abv 8 Feb 99: PRO17820: BRepTools::OuterWire() -> ShapeAnalysis::OuterWire | |
27 | //szv#4 S4163 | |
28 | //S4181 pdn 20.04.99 implementing of writing IGES elementary surfaces. | |
29 | // abv 31.01.00 inheriting from BRepToIGES_BREntity to remove code duplication | |
30 | //eap: Tue Aug 29 11:02:56 2000: Shape Processing moved to upper levels | |
31 | ||
32 | #include <BRepToIGESBRep_Entity.ixx> | |
33 | ||
34 | #include <BRepToIGES_BRWire.hxx> | |
35 | ||
36 | #include <BRepLib.hxx> | |
37 | #include <BRep_Tool.hxx> | |
38 | #include <BRepTools.hxx> | |
39 | #include <BRepTools_WireExplorer.hxx> | |
40 | ||
41 | #include <gp.hxx> | |
42 | #include <gp_Circ2d.hxx> | |
43 | #include <gp_Elips2d.hxx> | |
44 | #include <gp_Pnt.hxx> | |
45 | #include <gp_Pnt2d.hxx> | |
46 | #include <gp_Trsf.hxx> | |
47 | #include <gp_XYZ.hxx> | |
48 | #include <gp_Trsf2d.hxx> | |
49 | ||
50 | #include <Geom_BezierCurve.hxx> | |
51 | #include <Geom_BSplineCurve.hxx> | |
52 | #include <Geom_CartesianPoint.hxx> | |
53 | #include <Geom_ConicalSurface.hxx> | |
54 | #include <Geom_Circle.hxx> | |
55 | #include <Geom_Curve.hxx> | |
56 | #include <Geom_Ellipse.hxx> | |
57 | #include <Geom_Hyperbola.hxx> | |
58 | #include <Geom_Parabola.hxx> | |
59 | #include <Geom_Plane.hxx> | |
60 | #include <Geom_Surface.hxx> | |
61 | #include <Geom_CylindricalSurface.hxx> | |
62 | #include <Geom_RectangularTrimmedSurface.hxx> | |
63 | #include <Geom_SphericalSurface.hxx> | |
64 | #include <Geom_SurfaceOfLinearExtrusion.hxx> | |
65 | #include <Geom_SurfaceOfRevolution.hxx> | |
66 | #include <Geom_ToroidalSurface.hxx> | |
67 | #include <Geom_TrimmedCurve.hxx> | |
68 | ||
69 | //#include <GeomConvert.hxx> | |
70 | //#include <Geom2dConvert.hxx> | |
71 | ||
72 | #include <Geom2d_Curve.hxx> | |
73 | ||
74 | #include <GeomToIGES_GeomCurve.hxx> | |
75 | #include <GeomToIGES_GeomSurface.hxx> | |
76 | ||
77 | #include <Geom2dToIGES_Geom2dCurve.hxx> | |
78 | ||
79 | #include <IGESBasic_HArray1OfHArray1OfInteger.hxx> | |
80 | #include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx> | |
81 | #include <IGESBasic_Group.hxx> | |
82 | ||
83 | #include <IGESData_IGESEntity.hxx> | |
84 | #include <IGESData_IGESModel.hxx> | |
85 | #include <IGESData_HArray1OfIGESEntity.hxx> | |
86 | ||
87 | #include <IGESGeom_CompositeCurve.hxx> | |
88 | #include <IGESGeom_Point.hxx> | |
89 | ||
90 | #include <IGESSolid_Face.hxx> | |
91 | #include <IGESSolid_HArray1OfFace.hxx> | |
92 | #include <IGESSolid_Loop.hxx> | |
93 | #include <IGESSolid_HArray1OfLoop.hxx> | |
94 | #include <IGESSolid_Shell.hxx> | |
95 | #include <IGESSolid_HArray1OfShell.hxx> | |
96 | #include <IGESSolid_ManifoldSolid.hxx> | |
97 | #include <IGESSolid_VertexList.hxx> | |
98 | #include <IGESSolid_HArray1OfVertexList.hxx> | |
99 | #include <IGESSolid_EdgeList.hxx> | |
100 | ||
101 | #include <Interface_Macros.hxx> | |
102 | ||
103 | //#include <ShapeAnalysis.hxx> | |
104 | //#include <ShapeCustom.hxx> | |
105 | ||
106 | #include <TColgp_HArray1OfXYZ.hxx> | |
107 | ||
108 | #include <TColStd_HSequenceOfTransient.hxx> | |
109 | #include <TColStd_SequenceOfInteger.hxx> | |
110 | #include <TColStd_HArray1OfInteger.hxx> | |
111 | ||
112 | #include <TopAbs_ShapeEnum.hxx> | |
113 | #include <TopAbs_Orientation.hxx> | |
114 | ||
115 | #include <TopExp.hxx> | |
116 | #include <TopExp_Explorer.hxx> | |
117 | ||
118 | #include <TopLoc_Location.hxx> | |
119 | ||
120 | #include <TopoDS.hxx> | |
121 | #include <TopoDS_Compound.hxx> | |
122 | #include <TopoDS_CompSolid.hxx> | |
123 | #include <TopoDS_Edge.hxx> | |
124 | #include <TopoDS_Face.hxx> | |
125 | #include <TopoDS_Solid.hxx> | |
126 | #include <TopoDS_Shape.hxx> | |
127 | #include <TopoDS_Shell.hxx> | |
128 | #include <TopoDS_Vertex.hxx> | |
129 | #include <TopoDS_Wire.hxx> | |
130 | ||
131 | #include <Transfer_FinderProcess.hxx> | |
132 | #include <TransferBRep_ShapeMapper.hxx> | |
133 | #include <TransferBRep_OrientedShapeMapper.hxx> | |
134 | #include <Transfer_TransientMapper.hxx> | |
135 | #include <Transfer_SimpleBinderOfTransient.hxx> | |
136 | #include <Interface_Static.hxx> | |
137 | ||
138 | #include <ShapeAlgo.hxx> | |
139 | #include <ShapeAlgo_AlgoContainer.hxx> | |
140 | #include <Message_ProgressIndicator.hxx> | |
141 | ||
142 | //======================================================================= | |
143 | //function : BRepToIGESBRep_Entity | |
144 | //purpose : | |
145 | //======================================================================= | |
146 | ||
147 | BRepToIGESBRep_Entity::BRepToIGESBRep_Entity() | |
148 | { | |
149 | Init(); | |
150 | if (myEdgeList.IsNull()) | |
151 | myEdgeList = new IGESSolid_EdgeList; | |
152 | if (myVertexList.IsNull()) | |
153 | myVertexList = new IGESSolid_VertexList; | |
154 | } | |
155 | ||
156 | ||
157 | //======================================================================= | |
158 | //function : Clear | |
159 | //purpose : | |
160 | //======================================================================= | |
161 | ||
162 | void BRepToIGESBRep_Entity::Clear() | |
163 | { | |
164 | myVertices.Clear(); | |
165 | myEdges.Clear(); | |
166 | myCurves.Clear(); | |
167 | } | |
168 | ||
169 | ||
170 | //============================================================================= | |
171 | // TransferVertexList | |
172 | // | |
173 | //============================================================================= | |
174 | ||
175 | void BRepToIGESBRep_Entity::TransferVertexList() | |
176 | { | |
177 | ||
178 | Standard_Integer nbvertices = myVertices.Extent(); | |
572db63c G |
179 | if(!nbvertices) |
180 | return; | |
7fd59977 | 181 | Handle(TColgp_HArray1OfXYZ) vertices= new TColgp_HArray1OfXYZ(1,nbvertices); |
182 | Standard_Real Unit = GetUnit(); | |
183 | Standard_Real X,Y,Z; | |
184 | ||
185 | for (Standard_Integer ivertex = 1; ivertex <= nbvertices; ivertex++) { | |
186 | TopoDS_Shape myshape = myVertices(ivertex); | |
187 | TopoDS_Vertex myvertex = TopoDS::Vertex(myshape); | |
188 | gp_Pnt Point = BRep_Tool::Pnt(myvertex); | |
189 | Point.Coord(X,Y,Z); | |
190 | vertices->SetValue(ivertex, gp_XYZ(X/Unit,Y/Unit,Z/Unit)); | |
191 | } | |
192 | ||
193 | myVertexList->Init(vertices); | |
194 | } | |
195 | ||
196 | ||
197 | //============================================================================= | |
198 | // IndexVertex | |
199 | //============================================================================= | |
200 | Standard_Integer BRepToIGESBRep_Entity::IndexVertex(const TopoDS_Vertex& myvertex) const | |
201 | { | |
202 | TopoDS_Shape V = myvertex; | |
203 | return myVertices.FindIndex(V); | |
204 | } | |
205 | ||
206 | ||
207 | //============================================================================= | |
208 | // AddVertex | |
209 | // | |
210 | //============================================================================= | |
211 | ||
212 | Standard_Integer BRepToIGESBRep_Entity::AddVertex(const TopoDS_Vertex& myvertex) | |
213 | { | |
214 | if ( myvertex.IsNull()) return 0; | |
215 | ||
216 | TopoDS_Shape V = myvertex; | |
217 | Standard_Integer index = myVertices.FindIndex(V); | |
218 | if (index == 0) { | |
219 | index = myVertices.Add(V); | |
220 | } | |
221 | ||
222 | return index; | |
223 | } | |
224 | ||
225 | ||
226 | //============================================================================= | |
227 | // TransferEdgeList | |
228 | // | |
229 | //============================================================================= | |
230 | ||
231 | void BRepToIGESBRep_Entity::TransferEdgeList() | |
232 | { | |
233 | ||
234 | Handle(IGESSolid_VertexList) TheVertexList = myVertexList; | |
235 | ||
236 | Handle(IGESData_IGESEntity) mycurve; | |
237 | Standard_Integer mystartindex, myendindex; | |
238 | Handle(IGESSolid_VertexList) mystartlist; | |
239 | Handle(IGESSolid_VertexList) myendlist; | |
240 | ||
241 | Standard_Integer nbedges = myEdges.Extent(); | |
572db63c G |
242 | if(!nbedges) |
243 | return; | |
7fd59977 | 244 | Handle(IGESData_HArray1OfIGESEntity) Curves= |
245 | new IGESData_HArray1OfIGESEntity(1,nbedges); | |
246 | Handle(IGESSolid_HArray1OfVertexList) startVertexList = | |
247 | new IGESSolid_HArray1OfVertexList(1,nbedges); | |
248 | Handle(TColStd_HArray1OfInteger) startVertexIndex = | |
249 | new TColStd_HArray1OfInteger(1,nbedges); | |
250 | Handle(IGESSolid_HArray1OfVertexList) endVertexList = | |
251 | new IGESSolid_HArray1OfVertexList(1,nbedges); | |
252 | Handle(TColStd_HArray1OfInteger) endVertexIndex = | |
253 | new TColStd_HArray1OfInteger(1,nbedges); | |
254 | ||
255 | for (Standard_Integer iedge = 1; iedge <= nbedges; iedge++) { | |
256 | TopoDS_Shape myshape = myEdges(iedge); | |
257 | TopoDS_Edge myedge = TopoDS::Edge(myshape); | |
258 | // the curve 3D | |
259 | DeclareAndCast(IGESData_IGESEntity, amycurve, myCurves(iedge)); | |
260 | Curves->SetValue(iedge, amycurve); | |
261 | TopoDS_Vertex V1, V2; | |
262 | TopExp::Vertices(myedge, V1, V2); | |
0d969553 | 263 | // vertices follow the orientation of curve 3d |
7fd59977 | 264 | mystartindex = IndexVertex(V1); |
265 | myendindex = IndexVertex(V2); | |
266 | startVertexIndex->SetValue(iedge, mystartindex); | |
267 | endVertexIndex->SetValue(iedge, myendindex); | |
268 | startVertexList->SetValue(iedge, TheVertexList); | |
269 | endVertexList->SetValue(iedge, TheVertexList); | |
270 | } | |
271 | ||
272 | myEdgeList->Init | |
273 | (Curves, startVertexList, startVertexIndex, endVertexList, endVertexIndex); | |
274 | } | |
275 | ||
276 | ||
277 | //============================================================================= | |
278 | // IndexEdge | |
279 | //============================================================================= | |
280 | Standard_Integer BRepToIGESBRep_Entity::IndexEdge(const TopoDS_Edge& myedge) const | |
281 | { | |
282 | TopoDS_Shape E = myedge; | |
283 | return myEdges.FindIndex(E); | |
284 | } | |
285 | ||
286 | ||
287 | //============================================================================= | |
288 | // AddEdge | |
289 | // | |
290 | //============================================================================= | |
291 | ||
292 | Standard_Integer BRepToIGESBRep_Entity::AddEdge(const TopoDS_Edge& myedge, | |
293 | const Handle(IGESData_IGESEntity)& mycurve3d) | |
294 | { | |
295 | if ( myedge.IsNull()) return 0; | |
296 | ||
297 | TopoDS_Shape E = myedge; | |
298 | Handle(IGESData_IGESEntity) C = mycurve3d; | |
299 | Standard_Integer index = myEdges.FindIndex(E); | |
300 | if (index == 0) { | |
301 | index = myEdges.Add(E); | |
302 | myCurves.Add(C); | |
303 | } | |
304 | ||
305 | return index; | |
306 | } | |
307 | ||
308 | ||
309 | //======================================================================= | |
310 | //function : TransferShape | |
311 | //purpose : | |
312 | //======================================================================= | |
313 | Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferShape | |
314 | (const TopoDS_Shape& start) | |
315 | { | |
316 | Handle(IGESData_IGESEntity) res; | |
317 | //TopoDS_Shape theShape; | |
318 | ||
319 | if (start.IsNull()) return res; | |
320 | ||
321 | if (start.ShapeType() == TopAbs_VERTEX) { | |
322 | AddWarning (start, " A Vertex alone is not a IGESBRep Entity"); | |
323 | TopoDS_Vertex V = TopoDS::Vertex(start); | |
324 | BRepToIGES_BRWire BW(*this); | |
325 | BW.SetModel(GetModel()); | |
326 | res = BW.TransferVertex(V); | |
327 | return res; | |
328 | } | |
329 | else if (start.ShapeType() == TopAbs_EDGE) { | |
330 | AddWarning (start, " An Edge alone is not a IGESBRep Entity"); | |
331 | TopoDS_Edge E = TopoDS::Edge(start); | |
332 | BRepToIGES_BRWire BW(*this); | |
333 | BW.SetModel(GetModel()); | |
334 | res = BW.TransferEdge(E, Standard_False); | |
335 | return res; | |
336 | } | |
337 | else if (start.ShapeType() == TopAbs_WIRE) { | |
338 | AddWarning (start, " An Wire alone is not a IGESBRep Entity"); | |
339 | TopoDS_Wire W = TopoDS::Wire(start); | |
340 | BRepToIGES_BRWire BW(*this); | |
341 | BW.SetModel(GetModel()); | |
342 | res = BW.TransferWire(W); | |
343 | return res; | |
344 | } | |
345 | else { | |
346 | // theShape = ShapeCustom::DirectFaces(start); | |
347 | if (start.ShapeType() == TopAbs_FACE) { | |
348 | TopoDS_Face F = TopoDS::Face(start); | |
349 | res = TransferFace(F); | |
350 | } | |
351 | else if (start.ShapeType() == TopAbs_SHELL) { | |
352 | TopoDS_Shell S = TopoDS::Shell(start); | |
353 | res = TransferShell(S); | |
354 | } | |
355 | else if (start.ShapeType() == TopAbs_SOLID) { | |
356 | TopoDS_Solid M = TopoDS::Solid(start); | |
357 | res = TransferSolid(M); | |
358 | } | |
359 | else if (start.ShapeType() == TopAbs_COMPSOLID) { | |
360 | TopoDS_CompSolid C = TopoDS::CompSolid(start); | |
361 | res = TransferCompSolid(C); | |
362 | } | |
363 | else if (start.ShapeType() == TopAbs_COMPOUND) { | |
364 | TopoDS_Compound C = TopoDS::Compound(start); | |
365 | res = TransferCompound(C); | |
366 | } | |
367 | else { | |
0d969553 | 368 | // error message |
7fd59977 | 369 | } |
370 | } | |
572db63c G |
371 | if(res.IsNull()) |
372 | return res; | |
7fd59977 | 373 | |
374 | TransferVertexList(); | |
375 | TransferEdgeList(); | |
376 | return res; | |
377 | } | |
378 | ||
379 | ||
380 | //============================================================================= | |
381 | // TransferEdge | |
382 | //============================================================================= | |
383 | ||
384 | Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferEdge (const TopoDS_Edge& myedge) | |
385 | { | |
386 | BRepToIGES_BRWire BR(*this); | |
387 | BR.SetModel(GetModel()); | |
388 | return BR.TransferEdge (myedge, Standard_True); | |
389 | } | |
390 | ||
391 | ||
392 | //============================================================================= | |
393 | // TransferEdge | |
394 | //============================================================================= | |
395 | ||
396 | Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferEdge (const TopoDS_Edge& myedge, | |
397 | const TopoDS_Face& myface, | |
398 | const Standard_Real Length) | |
399 | { | |
400 | Handle(IGESData_IGESEntity) ICurve3d; | |
401 | Handle(IGESData_IGESEntity) ICurve2d; | |
402 | if ( myedge.IsNull()) return ICurve2d; | |
403 | ||
404 | BRepToIGES_BRWire BR(*this); | |
405 | BR.SetModel(GetModel()); | |
406 | ICurve2d = BR.TransferEdge (myedge, myface, Length, Standard_True); | |
407 | ||
0d969553 Y |
408 | // curve 3d is obligatory. If it does not exist it is created and stored in "myCurves". |
409 | // If the edge is degenerated, there is no associated 3d. So "edge-tuple" | |
410 | // will be a Vertex. | |
7fd59977 | 411 | |
412 | if (!BRep_Tool::Degenerated(myedge)) { | |
413 | ICurve3d = TransferEdge(myedge); | |
414 | if (ICurve3d.IsNull()) { | |
415 | AddFail (myedge, " Transfer Failed : no Curve 3D "); | |
416 | } | |
417 | AddEdge(myedge, ICurve3d); | |
418 | } | |
419 | ||
420 | return ICurve2d; | |
421 | } | |
422 | ||
423 | ||
424 | //============================================================================= | |
425 | // TransferWire | |
426 | //============================================================================= | |
427 | ||
428 | Handle(IGESSolid_Loop) BRepToIGESBRep_Entity::TransferWire (const TopoDS_Wire& mywire, | |
429 | const TopoDS_Face& myface, | |
430 | const Standard_Real Length) | |
431 | { | |
432 | Handle(IGESSolid_Loop) myLoop = new IGESSolid_Loop; | |
433 | if ( mywire.IsNull()) return myLoop; | |
434 | Handle(IGESData_IGESEntity) Pointeur; | |
435 | ||
436 | TColStd_SequenceOfInteger Seqindex; | |
437 | TColStd_SequenceOfInteger Seqorient; | |
438 | TColStd_SequenceOfInteger Seqtype; | |
439 | Handle(IGESData_IGESEntity) ent2d ; | |
440 | Handle(IGESData_IGESEntity) ent3d ; | |
441 | Handle(TColStd_HSequenceOfTransient) Seq2d = new TColStd_HSequenceOfTransient(); | |
442 | ||
443 | BRepTools_WireExplorer WE; | |
444 | //Standard_Integer nbedge = 0; //szv#4:S4163:12Mar99 unused | |
445 | TopExp_Explorer TE(mywire, TopAbs_VERTEX); | |
446 | if ( TE.More()) { | |
447 | for ( WE.Init(mywire,myface); WE.More(); WE.Next()) { | |
448 | TopoDS_Edge E = WE.Current(); | |
449 | if (E.IsNull()) { | |
450 | AddWarning(mywire, "an Edge is a null entity"); | |
451 | } | |
452 | else { | |
453 | ent2d = TransferEdge(E, myface, Length); | |
454 | Seq2d->Append(ent2d); | |
455 | Standard_Integer myindex; | |
456 | ||
0d969553 | 457 | // add Vertices in the Map "myVertices" |
7fd59977 | 458 | TopoDS_Vertex V1, V2; |
459 | TopExp::Vertices(E, V1, V2); | |
460 | //Standard_Integer Ivertex1, Ivertex2; //szv#4:S4163:12Mar99 not needed | |
461 | if (!BRep_Tool::Degenerated(E)) { | |
462 | if ( !V1.IsNull()) { | |
463 | AddVertex(V1); //szv#4:S4163:12Mar99 `Ivertex1=` not needed | |
464 | } | |
465 | if ( !V2.IsNull()) { | |
466 | AddVertex(V2); //szv#4:S4163:12Mar99 `Ivertex2=` not needed | |
467 | } | |
468 | myindex = IndexEdge(E); | |
469 | Seqtype.Append(0); | |
470 | } | |
471 | else { | |
472 | myindex = AddVertex(V1); | |
473 | Seqtype.Append(1); | |
474 | } | |
475 | Seqindex.Append(myindex); | |
476 | if (E.Orientation() == TopAbs_FORWARD ) Seqorient.Append(1); | |
477 | if (E.Orientation() == TopAbs_REVERSED) Seqorient.Append(0); | |
478 | } | |
479 | } | |
480 | } | |
481 | else | |
482 | AddWarning(mywire, " no Vertex associated to the Wire"); | |
483 | ||
484 | Standard_Integer nbedges = Seq2d->Length(); | |
485 | Handle(TColStd_HArray1OfInteger) types = new TColStd_HArray1OfInteger(1,nbedges); | |
486 | Standard_Integer mytype; | |
487 | Handle(IGESData_HArray1OfIGESEntity) edges = new IGESData_HArray1OfIGESEntity(1,nbedges); | |
488 | Handle(IGESData_IGESEntity) myedge; | |
489 | Handle(TColStd_HArray1OfInteger) index = new TColStd_HArray1OfInteger(1,nbedges); | |
490 | Standard_Integer myindex; | |
491 | Handle(TColStd_HArray1OfInteger) orient = new TColStd_HArray1OfInteger(1,nbedges); | |
492 | Standard_Integer myorient; | |
493 | Handle(TColStd_HArray1OfInteger) nbcurves = new TColStd_HArray1OfInteger(1,nbedges); | |
494 | Standard_Integer mynbcurve; | |
495 | Handle(TColStd_HArray1OfInteger) flag; | |
496 | Handle(IGESBasic_HArray1OfHArray1OfInteger) isoflags = | |
497 | new IGESBasic_HArray1OfHArray1OfInteger(1,nbedges); | |
498 | Standard_Integer myisoflag; | |
499 | Handle(IGESData_HArray1OfIGESEntity) curve; | |
500 | Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) curves = | |
501 | new IGESBasic_HArray1OfHArray1OfIGESEntity(1,nbedges); | |
502 | Handle(IGESData_IGESEntity) mycurve; | |
503 | ||
504 | ||
505 | for (Standard_Integer itab = 1; itab <= nbedges; itab++) { | |
506 | mytype = Seqtype.Value(itab); | |
507 | types->SetValue(itab,mytype); | |
508 | if ( mytype == 0) | |
509 | Pointeur = myEdgeList; | |
510 | else | |
511 | Pointeur = myVertexList; | |
512 | edges->SetValue(itab,Pointeur); | |
513 | myindex = Seqindex.Value(itab); | |
514 | index->SetValue(itab, myindex); | |
515 | myorient = Seqorient.Value(itab); | |
516 | orient->SetValue(itab, myorient); | |
517 | mynbcurve = ( Seq2d->Value(itab).IsNull() ? 0 : 1 ); // abv 31 Jan 00: to be able not to write pcurves: was 1 | |
518 | nbcurves->SetValue(itab, mynbcurve); | |
519 | myisoflag = 0; | |
520 | flag = new TColStd_HArray1OfInteger(1,1); | |
521 | flag->SetValue(1,myisoflag); | |
522 | isoflags->SetValue(itab,flag); | |
523 | mycurve = GetCasted(IGESData_IGESEntity, Seq2d->Value(itab)); | |
524 | curve = new IGESData_HArray1OfIGESEntity(1,1); | |
525 | curve->SetValue(1,mycurve); | |
526 | curves->SetValue(itab,curve); | |
527 | } | |
528 | ||
529 | myLoop->Init(types, edges, index, orient, nbcurves, isoflags, curves); | |
530 | ||
531 | SetShapeResult ( mywire, myLoop ); | |
532 | ||
533 | return myLoop; | |
534 | } | |
535 | ||
536 | ||
537 | //============================================================================= | |
538 | // TransferFace | |
539 | // | |
540 | //============================================================================= | |
541 | ||
542 | Handle(IGESSolid_Face) BRepToIGESBRep_Entity ::TransferFace(const TopoDS_Face& start) | |
543 | { | |
544 | Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress(); | |
545 | if ( ! progress.IsNull() ) { | |
546 | if ( progress->UserBreak() ) return 0; | |
547 | progress->Increment(); | |
548 | } | |
549 | ||
550 | Handle(IGESSolid_Face) myent = new IGESSolid_Face; | |
551 | if ( start.IsNull()) return myent; | |
552 | Handle(IGESData_IGESEntity) ISurf; | |
553 | Standard_Real Length = 1.; | |
554 | ||
555 | // returns the face surface, the face tolerance, the face natural restriction flag. | |
556 | // -------------------------------------------------------------------------------- | |
557 | Handle(Geom_Surface) Surf = BRep_Tool::Surface(start); | |
558 | if (!Surf.IsNull()) { | |
559 | Standard_Real U1, U2, V1, V2; | |
0d969553 | 560 | BRepTools::UVBounds(start, U1, U2, V1, V2); // to limit the base surfaces |
7fd59977 | 561 | GeomToIGES_GeomSurface GS; |
562 | //S4181 pdn 17.04.99 Boolean flags in order to define write of elementary surfaces added. | |
563 | GS.SetBRepMode(Standard_True); | |
564 | GS.SetAnalyticMode ( Interface_Static::IVal("write.convertsurface.mode") ==0 ); | |
565 | GS.SetModel(GetModel()); | |
566 | ||
567 | Handle(Geom_Surface) st; | |
568 | if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { | |
569 | DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf); | |
570 | st = rectang->BasisSurface(); | |
571 | } | |
572 | else | |
573 | st= Surf; | |
574 | ||
575 | //S4181 pdn 17.04.99 Geom_Plane translated into GeomToIGES_GeomSurface | |
576 | ISurf = GS.TransferSurface(st, U1, U2, V1, V2); | |
577 | if (ISurf.IsNull()) { | |
578 | AddWarning (start, "the basic surface is a null entity"); | |
579 | return myent; | |
580 | } | |
581 | Length = GS.Length(); | |
582 | } | |
583 | ||
584 | ||
585 | // returns the wires of start | |
586 | // -------------------------- | |
587 | ||
0d969553 | 588 | // to explore the face , it is required to set it FORWARD. |
7fd59977 | 589 | TopoDS_Face myface = start; |
590 | Standard_Boolean IsReversed = Standard_False; | |
591 | if (start.Orientation() == TopAbs_REVERSED) { | |
592 | myface.Reverse(); | |
593 | IsReversed = Standard_True; | |
594 | } | |
595 | ||
596 | // outer wire | |
597 | //:n3 TopoDS_Wire Outer = BRepTools::OuterWire(myface); | |
598 | TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3 | |
599 | Handle(IGESSolid_Loop) OuterLoop = new IGESSolid_Loop; | |
600 | Standard_Boolean OuterLoopFlag = Standard_False; | |
601 | if (!Outer.IsNull()) { | |
602 | OuterLoopFlag = Standard_True; | |
603 | OuterLoop = TransferWire(Outer, myface, Length); | |
604 | } | |
605 | ||
0d969553 | 606 | // inner wires |
7fd59977 | 607 | TopExp_Explorer Ex; |
608 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); | |
609 | ||
610 | for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) { | |
611 | TopoDS_Wire W = TopoDS::Wire(Ex.Current()); | |
612 | Handle(IGESSolid_Loop) InnerLoop = new IGESSolid_Loop; | |
613 | if (W.IsNull()) { | |
0d969553 | 614 | AddWarning(start," a Wire is a null entity"); |
7fd59977 | 615 | } |
616 | else if (!W.IsSame(Outer)) { | |
617 | InnerLoop = TransferWire(W, myface, Length); | |
618 | if (!InnerLoop.IsNull()) Seq->Append(InnerLoop); | |
619 | } | |
620 | } | |
621 | ||
0d969553 | 622 | // all inner edges not in a wire |
7fd59977 | 623 | for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) { |
624 | TopoDS_Edge E = TopoDS::Edge(Ex.Current()); | |
625 | AddWarning ( E, "An edge alone is not transfer as an IGESBRep Entity"); | |
626 | } | |
627 | ||
628 | Standard_Integer nbent = Seq->Length(); | |
629 | Handle(IGESSolid_HArray1OfLoop) TabLoop; | |
630 | TabLoop = new IGESSolid_HArray1OfLoop(1,nbent+1); | |
631 | TabLoop->SetValue(1,OuterLoop); | |
632 | if ( nbent >= 1) { | |
633 | for (Standard_Integer itab = 1; itab <= nbent; itab++) { | |
634 | Handle(IGESSolid_Loop) item = GetCasted(IGESSolid_Loop, Seq->Value(itab)); | |
635 | TabLoop->SetValue(itab+1,item); | |
636 | } | |
637 | } | |
638 | ||
639 | // returns the Face | |
640 | // ---------------- | |
641 | myent-> Init (ISurf, OuterLoopFlag, TabLoop); | |
642 | ||
643 | if (IsReversed) myface.Reverse(); | |
644 | ||
645 | SetShapeResult ( start, myent ); | |
646 | ||
647 | return myent; | |
648 | } | |
649 | ||
650 | ||
651 | //============================================================================= | |
652 | // TransferShell | |
653 | //============================================================================= | |
654 | ||
655 | Handle(IGESSolid_Shell) BRepToIGESBRep_Entity ::TransferShell(const TopoDS_Shell& start) | |
656 | { | |
657 | Handle(IGESSolid_Shell) myshell = new IGESSolid_Shell; | |
658 | if ( start.IsNull()) return myshell; | |
659 | ||
660 | TopExp_Explorer Ex; | |
661 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); | |
662 | TColStd_SequenceOfInteger SeqFlag; | |
663 | Handle(IGESSolid_Face) IFace; | |
664 | ||
665 | for (Ex.Init(start,TopAbs_FACE); Ex.More(); Ex.Next()) { | |
666 | TopoDS_Face F = TopoDS::Face(Ex.Current()); | |
667 | if ( start.Orientation() == TopAbs_REVERSED ) F.Reverse(); //:l4 abv 12 Jan 99: CTS22022-2: writing reversed shells | |
668 | if (F.IsNull()) { | |
669 | AddWarning(start," a Face is a null entity"); | |
670 | } | |
671 | else { | |
672 | IFace = TransferFace(F); | |
673 | if (!IFace.IsNull()) { | |
674 | Seq->Append(IFace); | |
675 | if (F.Orientation() == TopAbs_FORWARD ) SeqFlag.Append(1); | |
676 | if (F.Orientation() == TopAbs_REVERSED) SeqFlag.Append(0); | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | ||
682 | Standard_Integer nbfaces = Seq->Length(); | |
683 | Handle(IGESSolid_HArray1OfFace) TabFace = new IGESSolid_HArray1OfFace(1,nbfaces); | |
684 | Handle(TColStd_HArray1OfInteger) TabFlag = new TColStd_HArray1OfInteger(1,nbfaces); | |
685 | for (Standard_Integer itab = 1; itab <= nbfaces; itab++) { | |
686 | Handle(IGESSolid_Face) itemface = GetCasted(IGESSolid_Face, Seq->Value(itab)); | |
687 | TabFace->SetValue(itab,itemface); | |
688 | Standard_Integer item = SeqFlag.Value(itab); | |
689 | TabFlag->SetValue(itab, item); | |
690 | } | |
691 | ||
692 | myshell->Init(TabFace,TabFlag); | |
693 | ||
694 | SetShapeResult ( start, myshell ); | |
695 | ||
696 | return myshell; | |
697 | } | |
698 | ||
699 | ||
700 | //============================================================================= | |
701 | // TransferSolid | |
702 | // with a Solid | |
703 | //============================================================================= | |
704 | ||
705 | Handle(IGESSolid_ManifoldSolid) BRepToIGESBRep_Entity ::TransferSolid (const TopoDS_Solid& start) | |
706 | { | |
707 | Handle(IGESSolid_ManifoldSolid) mysol = new IGESSolid_ManifoldSolid; | |
708 | if ( start.IsNull()) return mysol; | |
709 | ||
710 | TopExp_Explorer Ex; | |
711 | Handle(IGESSolid_Shell) IShell, FirstShell; | |
712 | Standard_Integer ShellFlag = 1; | |
713 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); | |
714 | TColStd_SequenceOfInteger SeqFlag; | |
715 | ||
716 | for (Ex.Init(start,TopAbs_SHELL); Ex.More(); Ex.Next()) { | |
717 | TopoDS_Shell S = TopoDS::Shell(Ex.Current()); | |
718 | if (S.IsNull()) { | |
0d969553 | 719 | AddWarning(start," a Shell is a null entity"); |
7fd59977 | 720 | } |
721 | else { | |
722 | IShell = TransferShell(S); | |
723 | if (!IShell.IsNull()) { | |
724 | Seq->Append(IShell); | |
725 | if (S.Orientation() == TopAbs_FORWARD ) SeqFlag.Append(1); | |
726 | if (S.Orientation() == TopAbs_REVERSED) SeqFlag.Append(0); | |
727 | } | |
728 | } | |
729 | } | |
730 | ||
731 | ||
732 | Standard_Integer nbshells = Seq->Length(); | |
733 | Handle(IGESSolid_HArray1OfShell) Tab; | |
734 | Handle(TColStd_HArray1OfInteger) TabFlag; | |
735 | if ( nbshells > 1) { | |
736 | Tab = new IGESSolid_HArray1OfShell(1,nbshells-1); | |
737 | TabFlag = new TColStd_HArray1OfInteger(1,nbshells-1); | |
738 | for (Standard_Integer itab = 1; itab <= nbshells; itab++) { | |
739 | Handle(IGESSolid_Shell) itemShell = GetCasted(IGESSolid_Shell, Seq->Value(itab)); | |
740 | Standard_Integer item = SeqFlag.Value(itab); | |
741 | if (itab == 1) { | |
742 | FirstShell = itemShell; | |
743 | ShellFlag = item; | |
744 | } | |
745 | else { | |
746 | Tab->SetValue(itab-1,itemShell); | |
747 | TabFlag->SetValue(itab-1, item); | |
748 | } | |
749 | } | |
750 | } | |
751 | ||
752 | if (nbshells == 1) { | |
753 | FirstShell = GetCasted(IGESSolid_Shell, Seq->Value(1)); | |
754 | ShellFlag = SeqFlag.Value(1); | |
755 | Tab.Nullify(); TabFlag.Nullify(); | |
756 | mysol->Init(FirstShell, ShellFlag, Tab, TabFlag); | |
757 | } | |
758 | else if (nbshells >=2 ) { | |
759 | mysol->Init(FirstShell, ShellFlag, Tab, TabFlag); | |
760 | } | |
761 | else | |
762 | AddWarning (start, " no Result "); | |
763 | ||
764 | SetShapeResult ( start, mysol ); | |
765 | ||
766 | return mysol; | |
767 | } | |
768 | ||
769 | ||
770 | //============================================================================= | |
771 | // TransferCompSolid | |
772 | // with a CompSolid | |
773 | //============================================================================= | |
774 | ||
775 | Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferCompSolid (const TopoDS_CompSolid& start) | |
776 | { | |
777 | Handle(IGESData_IGESEntity) myent; | |
778 | if ( start.IsNull()) return myent; | |
779 | ||
780 | TopExp_Explorer Ex; | |
781 | Handle(IGESSolid_ManifoldSolid) ISolid = new IGESSolid_ManifoldSolid; | |
782 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); | |
783 | ||
784 | for (Ex.Init(start,TopAbs_SOLID); Ex.More(); Ex.Next()) { | |
785 | TopoDS_Solid S = TopoDS::Solid(Ex.Current()); | |
786 | if (S.IsNull()) { | |
787 | AddWarning(start," an Solid is a null entity"); | |
788 | } | |
789 | else { | |
790 | ISolid = TransferSolid(S); | |
791 | if (!ISolid.IsNull()) Seq->Append(ISolid); | |
792 | } | |
793 | } | |
794 | ||
795 | ||
796 | Standard_Integer nbsolids = Seq->Length(); | |
797 | Handle(IGESData_HArray1OfIGESEntity) Tab; | |
798 | if ( nbsolids > 1) { | |
799 | Tab = new IGESData_HArray1OfIGESEntity(1,nbsolids); | |
800 | for (Standard_Integer itab = 1; itab <= nbsolids; itab++) { | |
801 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); | |
802 | Tab->SetValue(itab,item); | |
803 | } | |
804 | } | |
805 | ||
806 | if (nbsolids == 1) { | |
807 | myent = ISolid; | |
808 | } | |
572db63c | 809 | else if(nbsolids > 1 ){ |
7fd59977 | 810 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
811 | IGroup->Init(Tab); | |
812 | myent = IGroup; | |
813 | } | |
814 | ||
815 | SetShapeResult ( start, myent ); | |
816 | ||
817 | return myent; | |
818 | } | |
819 | ||
820 | ||
821 | //============================================================================= | |
822 | // TransferCompound | |
823 | // with a Compound | |
824 | //============================================================================= | |
825 | ||
826 | Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferCompound (const TopoDS_Compound& start) | |
827 | { | |
828 | Handle(IGESData_IGESEntity) res; | |
829 | if ( start.IsNull()) return res; | |
830 | ||
831 | ||
832 | TopExp_Explorer Ex; | |
833 | Handle(IGESData_IGESEntity) IShape; | |
834 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); | |
835 | ||
0d969553 | 836 | // take all Solids |
7fd59977 | 837 | for (Ex.Init(start, TopAbs_SOLID); Ex.More(); Ex.Next()) { |
838 | TopoDS_Solid S = TopoDS::Solid(Ex.Current()); | |
839 | if (S.IsNull()) { | |
840 | AddWarning(start," a Solid is a null entity"); | |
841 | } | |
842 | else { | |
843 | IShape = TransferSolid(S); | |
844 | if (!IShape.IsNull()) Seq->Append(IShape); | |
845 | } | |
846 | } | |
847 | ||
0d969553 | 848 | // take all isolated Shells |
7fd59977 | 849 | for (Ex.Init(start, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next()) { |
850 | TopoDS_Shell S = TopoDS::Shell(Ex.Current()); | |
851 | if (S.IsNull()) { | |
852 | AddWarning(start," a Shell is a null entity"); | |
853 | } | |
854 | else { | |
855 | IShape = TransferShell(S); | |
856 | if (!IShape.IsNull()) Seq->Append(IShape); | |
857 | } | |
858 | } | |
859 | ||
860 | ||
0d969553 | 861 | // take all isolated Faces |
7fd59977 | 862 | for (Ex.Init(start, TopAbs_FACE, TopAbs_SHELL); Ex.More(); Ex.Next()) { |
863 | TopoDS_Face S = TopoDS::Face(Ex.Current()); | |
864 | if (S.IsNull()) { | |
865 | AddWarning(start," a Face is a null entity"); | |
866 | } | |
867 | else { | |
868 | IShape = TransferFace(S); | |
869 | if (!IShape.IsNull()) Seq->Append(IShape); | |
870 | } | |
871 | } | |
872 | ||
873 | ||
0d969553 | 874 | // take all isolated Wires |
7fd59977 | 875 | for (Ex.Init(start, TopAbs_WIRE, TopAbs_FACE); Ex.More(); Ex.Next()) { |
876 | TopoDS_Wire S = TopoDS::Wire(Ex.Current()); | |
877 | AddWarning(S," a Wire alone is not an IGESBRep entity : no Transfer"); | |
878 | } | |
879 | ||
880 | ||
0d969553 | 881 | // take all isolated Edges |
7fd59977 | 882 | for (Ex.Init(start, TopAbs_EDGE, TopAbs_WIRE); Ex.More(); Ex.Next()) { |
883 | TopoDS_Edge S = TopoDS::Edge(Ex.Current()); | |
884 | AddWarning(S," a Edge alone is not an IGESBRep entity : no Transfer"); | |
885 | } | |
886 | ||
887 | ||
0d969553 | 888 | // take all isolated Vertices |
7fd59977 | 889 | for (Ex.Init(start, TopAbs_VERTEX, TopAbs_EDGE); Ex.More(); Ex.Next()) { |
890 | TopoDS_Vertex S = TopoDS::Vertex(Ex.Current()); | |
891 | AddWarning(S," a Vertex alone is not an IGESBRep entity : no Transfer"); | |
892 | } | |
893 | ||
0d969553 | 894 | // construct the group |
7fd59977 | 895 | Standard_Integer nbshapes = Seq->Length(); |
896 | Handle(IGESData_HArray1OfIGESEntity) Tab; | |
897 | if (nbshapes > 1) { | |
898 | Tab = new IGESData_HArray1OfIGESEntity(1,nbshapes); | |
899 | for (Standard_Integer itab = 1; itab <= nbshapes; itab++) { | |
900 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); | |
901 | Tab->SetValue(itab,item); | |
902 | } | |
903 | } | |
572db63c | 904 | |
7fd59977 | 905 | if (nbshapes == 1) { |
906 | res = IShape; | |
907 | } | |
572db63c | 908 | else if(nbshapes > 1) { |
7fd59977 | 909 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
910 | IGroup->Init(Tab); | |
911 | res = IGroup; | |
912 | } | |
913 | ||
914 | SetShapeResult ( start, res ); | |
915 | ||
916 | return res; | |
917 | } |