Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-01-03 |
2 | // Created by: Frederic MAUPAS | |
3 | // Copyright (c) 1995-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GeometricSet |
18 | //gka 11.01.99 file PRO7755.stp #2018: work-around error in BRepLib_MakeFace | |
19 | //:n4 abv 12.02.99: S4132: treatment of GEOMETRIC_SETs implemented | |
20 | //:o7 abv 18.02.99: bm1_sy_fuel.stp #1427(items 1,2) protection against null entity | |
21 | //abv,gka 05.04.99 S4136: parameter names changed; avoid extra call to FixSameParameter | |
b311480e | 22 | |
42cf5bc1 | 23 | #include <BRep_Builder.hxx> |
24 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
25 | #include <BRepBuilderAPI_MakeFace.hxx> | |
26 | #include <BRepBuilderAPI_MakeVertex.hxx> | |
27 | #include <BRepLib.hxx> | |
28 | #include <Geom_BoundedSurface.hxx> | |
29 | #include <Geom_CartesianPoint.hxx> | |
30 | #include <Geom_Curve.hxx> | |
31 | #include <Geom_RectangularTrimmedSurface.hxx> | |
32 | #include <Geom_Surface.hxx> | |
33 | #include <Interface_Static.hxx> | |
34 | #include <Message_Messenger.hxx> | |
35 | #include <Message_ProgressSentry.hxx> | |
36 | #include <Precision.hxx> | |
37 | #include <ShapeFix_ShapeTolerance.hxx> | |
7fd59977 | 38 | #include <Standard_ErrorHandler.hxx> |
39 | #include <Standard_Failure.hxx> | |
42cf5bc1 | 40 | #include <StdFail_NotDone.hxx> |
41 | #include <STEPControl_ActorRead.hxx> | |
7fd59977 | 42 | #include <StepGeom_CartesianPoint.hxx> |
43 | #include <StepGeom_CompositeCurve.hxx> | |
42cf5bc1 | 44 | #include <StepGeom_Curve.hxx> |
45 | #include <StepGeom_CurveBoundedSurface.hxx> | |
46 | #include <StepGeom_GeometricRepresentationItem.hxx> | |
7fd59977 | 47 | #include <StepGeom_RectangularCompositeSurface.hxx> |
42cf5bc1 | 48 | #include <StepGeom_Surface.hxx> |
7fd59977 | 49 | #include <StepGeom_SurfacePatch.hxx> |
42cf5bc1 | 50 | #include <StepShape_BrepWithVoids.hxx> |
51 | #include <StepShape_ClosedShell.hxx> | |
7fd59977 | 52 | #include <StepShape_ConnectedEdgeSet.hxx> |
53 | #include <StepShape_EdgeBasedWireframeModel.hxx> | |
42cf5bc1 | 54 | #include <StepShape_FaceBasedSurfaceModel.hxx> |
55 | #include <StepShape_FaceSurface.hxx> | |
56 | #include <StepShape_FacetedBrep.hxx> | |
57 | #include <StepShape_FacetedBrepAndBrepWithVoids.hxx> | |
58 | #include <StepShape_GeometricSet.hxx> | |
59 | #include <StepShape_GeometricSetSelect.hxx> | |
7fd59977 | 60 | #include <StepShape_HArray1OfConnectedEdgeSet.hxx> |
7fd59977 | 61 | #include <StepShape_HArray1OfConnectedFaceSet.hxx> |
42cf5bc1 | 62 | #include <StepShape_HArray1OfEdge.hxx> |
7fd59977 | 63 | #include <StepShape_HArray1OfFace.hxx> |
42cf5bc1 | 64 | #include <StepShape_ManifoldSolidBrep.hxx> |
65 | #include <StepShape_OpenShell.hxx> | |
66 | #include <StepShape_OrientedClosedShell.hxx> | |
67 | #include <StepShape_Shell.hxx> | |
68 | #include <StepShape_ShellBasedSurfaceModel.hxx> | |
caaeed1b | 69 | #include <StepToGeom.hxx> |
42cf5bc1 | 70 | #include <StepToTopoDS_Builder.hxx> |
71 | #include <StepToTopoDS_DataMapOfTRI.hxx> | |
72 | #include <StepToTopoDS_NMTool.hxx> | |
73 | #include <StepToTopoDS_Tool.hxx> | |
74 | #include <StepToTopoDS_TranslateCompositeCurve.hxx> | |
75 | #include <StepToTopoDS_TranslateCurveBoundedSurface.hxx> | |
76 | #include <StepToTopoDS_TranslateEdge.hxx> | |
77 | #include <StepToTopoDS_TranslateFace.hxx> | |
78 | #include <StepToTopoDS_TranslateShell.hxx> | |
79 | #include <TopExp_Explorer.hxx> | |
80 | #include <TopoDS.hxx> | |
81 | #include <TopoDS_Compound.hxx> | |
82 | #include <TopoDS_Edge.hxx> | |
83 | #include <TopoDS_Face.hxx> | |
84 | #include <TopoDS_Shape.hxx> | |
85 | #include <TopoDS_Shell.hxx> | |
86 | #include <TopoDS_Solid.hxx> | |
38deba5d | 87 | #include <Transfer_ActorOfTransientProcess.hxx> |
42cf5bc1 | 88 | #include <Transfer_TransientProcess.hxx> |
89 | #include <TransferBRep.hxx> | |
7fd59977 | 90 | |
42cf5bc1 | 91 | #include <stdio.h> |
7fd59977 | 92 | static void ResetPreci (const TopoDS_Shape& S, Standard_Real maxtol) |
93 | { | |
94 | //:S4136 | |
95 | Standard_Integer modetol = Interface_Static::IVal("read.maxprecision.mode"); | |
96 | if (modetol) { | |
97 | ShapeFix_ShapeTolerance STU; | |
98 | STU.LimitTolerance (S,Precision::Confusion(),maxtol); | |
99 | } | |
7fd59977 | 100 | } |
101 | ||
102 | // ============================================================================ | |
103 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
104 | // Purpose : Empty constructor | |
105 | // ============================================================================ | |
106 | ||
107 | StepToTopoDS_Builder::StepToTopoDS_Builder() | |
d533dafb | 108 | : myError(StepToTopoDS_BuilderOther) |
7fd59977 | 109 | { |
110 | done = Standard_False; | |
111 | } | |
112 | ||
113 | // ============================================================================ | |
114 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
115 | // Purpose : Constructor with a ManifoldSolidBrep | |
116 | // ============================================================================ | |
117 | ||
118 | StepToTopoDS_Builder::StepToTopoDS_Builder | |
119 | (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid, | |
120 | const Handle(Transfer_TransientProcess)& TP) | |
121 | { | |
122 | Init(aManifoldSolid, TP); | |
123 | } | |
124 | ||
125 | // ============================================================================ | |
126 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
127 | // Purpose : Constructor woth a BrepWithVoids | |
128 | // ============================================================================ | |
129 | ||
130 | StepToTopoDS_Builder::StepToTopoDS_Builder | |
131 | (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids, | |
132 | const Handle(Transfer_TransientProcess)& TP) | |
133 | { | |
134 | Init(aBRepWithVoids, TP); | |
135 | } | |
136 | ||
137 | // ============================================================================ | |
138 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
139 | // Purpose : Constructor with a FacetedBrep | |
140 | // ============================================================================ | |
141 | ||
142 | StepToTopoDS_Builder::StepToTopoDS_Builder | |
143 | (const Handle(StepShape_FacetedBrep)& aFB, | |
144 | const Handle(Transfer_TransientProcess)& TP) | |
145 | { | |
146 | Init(aFB, TP); | |
147 | } | |
148 | ||
149 | // ============================================================================ | |
150 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
151 | // Purpose : Constructor with a FacetedBrepAndBrepWithVoids | |
152 | // ============================================================================ | |
153 | ||
154 | StepToTopoDS_Builder::StepToTopoDS_Builder | |
155 | (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV, | |
156 | const Handle(Transfer_TransientProcess)& TP) | |
157 | { | |
158 | Init(aFBABWV, TP); | |
159 | } | |
160 | ||
161 | // ============================================================================ | |
162 | // Method : StepToTopoDS_Builder::StepToTopoDS_Builder | |
163 | // Purpose : Constructor with a ShellBasedSurfaceModel | |
164 | // ============================================================================ | |
165 | ||
166 | StepToTopoDS_Builder::StepToTopoDS_Builder | |
167 | (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM, | |
168 | const Handle(Transfer_TransientProcess)& TP, | |
169 | StepToTopoDS_NMTool& NMTool) | |
170 | { | |
171 | Init(aSBSM, TP, NMTool); | |
172 | } | |
173 | ||
174 | // ============================================================================ | |
175 | // Method : Init | |
176 | // Purpose : Init with a ManifoldSolidBrep | |
177 | // ============================================================================ | |
178 | ||
179 | void StepToTopoDS_Builder::Init | |
180 | (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid, | |
181 | const Handle(Transfer_TransientProcess)& TP) | |
182 | { | |
0ebe5b0a | 183 | Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo(); |
7fd59977 | 184 | // Initialisation of the Tool |
185 | ||
186 | StepToTopoDS_Tool myTool; | |
187 | StepToTopoDS_DataMapOfTRI aMap; | |
188 | ||
189 | myTool.Init(aMap, TP); | |
190 | ||
191 | // Start Mapping | |
192 | ||
eab2c851 | 193 | Handle(StepShape_ConnectedFaceSet) aShell; |
194 | aShell = aManifoldSolid->Outer(); | |
7fd59977 | 195 | |
196 | StepToTopoDS_TranslateShell myTranShell; | |
197 | myTranShell.SetPrecision(Precision()); | |
198 | myTranShell.SetMaxTol(MaxTol()); | |
199 | // Non-manifold topology is not referenced by ManifoldSolidBrep (ssv; 14.11.2010) | |
200 | StepToTopoDS_NMTool dummyNMTool; | |
eab2c851 | 201 | myTranShell.Init(aShell, myTool, dummyNMTool); |
7fd59977 | 202 | |
203 | if (myTranShell.IsDone()) { | |
204 | TopoDS_Shape Sh = myTranShell.Value(); | |
205 | Sh.Closed(Standard_True); | |
206 | //BRepLib::SameParameter(Sh); | |
207 | TopoDS_Solid S; | |
208 | BRep_Builder B; | |
209 | B.MakeSolid(S); | |
210 | B.Add(S,Sh); | |
211 | myResult = S; | |
212 | myError = StepToTopoDS_BuilderDone; | |
213 | done = Standard_True; | |
214 | ||
215 | // Get Statistics : | |
216 | ||
217 | if ( TP->TraceLevel() > 2 ) | |
218 | { | |
0ebe5b0a | 219 | sout << "Geometric Statitics : " << std::endl; |
220 | sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl; | |
221 | sout << " - C1 : " << myTool.C1Surf() << std::endl; | |
222 | sout << " - C2 : " << myTool.C2Surf() << std::endl; | |
223 | sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << std::endl; | |
224 | sout << " - C1 : " << myTool.C1Cur3() << std::endl; | |
225 | sout << " - C2 : " << myTool.C2Cur3() << std::endl; | |
226 | sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << std::endl; | |
227 | sout << " - C1 : " << myTool.C1Cur2() << std::endl; | |
228 | sout << " - C2 : " << myTool.C2Cur2() << std::endl; | |
7fd59977 | 229 | } |
230 | ||
231 | //:S4136 ShapeFix::SameParameter (S,Standard_False); | |
232 | ResetPreci (S, MaxTol()); | |
233 | } | |
234 | else { | |
eab2c851 | 235 | TP->AddWarning(aShell," OuterShell from ManifoldSolidBrep not mapped to TopoDS"); |
7fd59977 | 236 | myError = StepToTopoDS_BuilderOther; |
237 | done = Standard_False; | |
238 | } | |
239 | } | |
240 | ||
241 | // ============================================================================ | |
242 | // Method : Init | |
243 | // Purpose : Init with a BrepWithVoids | |
244 | // ============================================================================ | |
245 | ||
246 | void StepToTopoDS_Builder::Init | |
247 | (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids, | |
248 | const Handle(Transfer_TransientProcess)& TP) | |
249 | { | |
0ebe5b0a | 250 | Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo(); |
7fd59977 | 251 | // Initialisation of the Tool |
252 | StepToTopoDS_Tool myTool; | |
253 | StepToTopoDS_DataMapOfTRI aMap; | |
254 | ||
255 | myTool.Init(aMap, TP); | |
256 | ||
257 | // Start Mapping | |
258 | ||
259 | Standard_Integer Nb = aBRepWithVoids->NbVoids(); | |
260 | Handle(StepShape_ClosedShell) aCShell; | |
261 | TopoDS_Solid S; | |
262 | TopoDS_Shape Sh; | |
263 | BRep_Builder B; | |
264 | B.MakeSolid(S); | |
265 | ||
266 | Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb+1, 1 ); | |
267 | ||
268 | StepToTopoDS_TranslateShell myTranShell; | |
269 | ||
270 | myTranShell.SetPrecision(Precision());//gka | |
271 | myTranShell.SetMaxTol(MaxTol()); | |
272 | // OuterBound | |
273 | ||
eab2c851 | 274 | aCShell = Handle(StepShape_ClosedShell)::DownCast(aBRepWithVoids->Outer()); |
7fd59977 | 275 | // Non-manifold topology is not referenced by BrepWithVoids (ssv; 14.11.2010) |
276 | StepToTopoDS_NMTool dummyNMTool; | |
277 | myTranShell.Init(aCShell, myTool, dummyNMTool); | |
278 | ||
279 | PS.Next(); | |
280 | ||
281 | if (myTranShell.IsDone()) { | |
282 | Sh = myTranShell.Value(); | |
283 | Sh.Closed(Standard_True); | |
284 | //BRepLib::SameParameter(Sh); | |
285 | B.MakeSolid(S); | |
286 | B.Add(S,Sh); | |
287 | myResult = S; | |
288 | myError = StepToTopoDS_BuilderDone; | |
289 | done = Standard_True; | |
290 | } | |
291 | else { | |
292 | TP->AddWarning(aCShell," OuterShell from BrepWithVoids not mapped to TopoDS"); | |
293 | myError = StepToTopoDS_BuilderOther; | |
294 | done = Standard_False; | |
295 | return; | |
296 | } | |
297 | ||
298 | // Voids | |
299 | ||
300 | for (Standard_Integer i=1; i<=Nb && PS.More(); i++, PS.Next()) { | |
301 | ||
302 | aCShell = aBRepWithVoids->VoidsValue(i); | |
303 | myTranShell.Init(aCShell, myTool, dummyNMTool); | |
304 | if (myTranShell.IsDone()) { | |
305 | Sh = myTranShell.Value(); | |
306 | Sh.Closed(Standard_True); | |
307 | ||
308 | //:e0 abv 25 Mar 98: void should be an OrientedShell | |
309 | Handle(StepShape_OrientedClosedShell) aOCShell = aBRepWithVoids->VoidsValue(i); | |
310 | if ( ! aOCShell.IsNull() && ! aOCShell->Orientation() ) Sh.Reverse(); | |
311 | ||
312 | //BRepLib::SameParameter(Sh); | |
313 | B.Add(S,Sh); | |
314 | } | |
315 | else { | |
316 | TP->AddWarning | |
317 | (aCShell," A Void from BrepWithVoids not mapped to TopoDS"); | |
318 | } | |
319 | } | |
320 | myResult = S; | |
321 | ||
322 | ||
323 | // Get Statistics : | |
324 | ||
325 | if ( TP->TraceLevel() > 2 ) | |
326 | { | |
0ebe5b0a | 327 | sout << "Geometric Statitics : " << std::endl; |
328 | sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl; | |
329 | sout << " - C1 : " << myTool.C1Surf() << std::endl; | |
330 | sout << " - C2 : " << myTool.C2Surf() << std::endl; | |
331 | sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << std::endl; | |
332 | sout << " - C1 : " << myTool.C1Cur3() << std::endl; | |
333 | sout << " - C2 : " << myTool.C2Cur3() << std::endl; | |
334 | sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << std::endl; | |
335 | sout << " - C1 : " << myTool.C1Cur2() << std::endl; | |
336 | sout << " - C2 : " << myTool.C2Cur2() << std::endl; | |
7fd59977 | 337 | } |
338 | ||
339 | //:S4136 ShapeFix::SameParameter (S,Standard_False); | |
340 | ResetPreci (S, MaxTol()); | |
341 | } | |
342 | ||
343 | // ============================================================================ | |
344 | // Method : Init | |
345 | // Purpose : Init with a FacetedBrep | |
346 | // ============================================================================ | |
347 | ||
348 | void StepToTopoDS_Builder::Init(const Handle(StepShape_FacetedBrep)& aFB, | |
349 | const Handle(Transfer_TransientProcess)& TP) | |
350 | { | |
351 | // Initialisation of the Tool | |
352 | ||
353 | StepToTopoDS_Tool myTool; | |
354 | StepToTopoDS_DataMapOfTRI aMap; | |
355 | ||
356 | myTool.Init(aMap, TP); | |
357 | ||
358 | // Start Mapping | |
359 | ||
360 | Handle(StepShape_ClosedShell) aCShell; | |
eab2c851 | 361 | aCShell = Handle(StepShape_ClosedShell)::DownCast(aFB->Outer()); |
7fd59977 | 362 | TopoDS_Shape Sh; |
363 | ||
364 | StepToTopoDS_TranslateShell myTranShell; | |
365 | myTranShell.SetPrecision(Precision()); //gka | |
366 | myTranShell.SetMaxTol(MaxTol()); | |
367 | // Non-manifold topology is not referenced by FacetedBrep (ss; 14.11.2010) | |
368 | StepToTopoDS_NMTool dummyNMTool; | |
369 | myTranShell.Init(aCShell, myTool, dummyNMTool); | |
370 | ||
371 | if (myTranShell.IsDone()) { | |
372 | Sh = myTranShell.Value(); | |
373 | Sh.Closed(Standard_True); | |
374 | //BRepLib::SameParameter(Sh); | |
375 | myTool.ClearEdgeMap(); | |
376 | myTool.ClearVertexMap(); | |
377 | TopoDS_Solid S; | |
378 | BRep_Builder B; | |
379 | B.MakeSolid(S); | |
380 | B.Add(S,Sh); | |
381 | myResult = S; | |
382 | myError = StepToTopoDS_BuilderDone; | |
383 | done = Standard_True; | |
384 | } | |
385 | else { | |
386 | TP->AddWarning | |
387 | (aCShell," OuterShell from FacetedBrep not mapped to TopoDS"); | |
388 | myError = StepToTopoDS_BuilderOther; | |
389 | done = Standard_True; | |
390 | } | |
391 | } | |
392 | ||
393 | // ============================================================================ | |
394 | // Method : Init | |
395 | // Purpose : Init with a FacetedBrepAndBrepWithVoids | |
396 | // ============================================================================ | |
397 | ||
398 | void StepToTopoDS_Builder::Init | |
399 | (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV, | |
400 | const Handle(Transfer_TransientProcess)& TP) | |
401 | { | |
402 | // Initialisation of the Tool | |
403 | ||
404 | StepToTopoDS_Tool myTool; | |
405 | StepToTopoDS_DataMapOfTRI aMap; | |
406 | ||
407 | myTool.Init(aMap, TP); | |
408 | ||
409 | // Start Mapping | |
410 | ||
411 | Handle(StepShape_ClosedShell) aCShell; | |
eab2c851 | 412 | aCShell = Handle(StepShape_ClosedShell)::DownCast(aFBABWV->Outer()); |
7fd59977 | 413 | TopoDS_Shape Sh; |
414 | ||
415 | StepToTopoDS_TranslateShell myTranShell; | |
416 | myTranShell.SetPrecision(Precision()); //gka | |
417 | myTranShell.SetMaxTol(MaxTol()); | |
418 | // Non-manifold topology is not referenced by FacetedBrepAndBrepWithVoids (ss; 14.11.2010) | |
419 | StepToTopoDS_NMTool dummyNMTool; | |
420 | myTranShell.Init(aCShell, myTool, dummyNMTool); | |
421 | ||
422 | if (myTranShell.IsDone()) { | |
423 | Sh = myTranShell.Value(); | |
424 | Sh.Closed(Standard_True); | |
425 | //BRepLib::SameParameter(Sh); | |
426 | TopoDS_Solid S; | |
427 | BRep_Builder B; | |
428 | B.MakeSolid(S); | |
429 | B.Add(S,Sh); | |
430 | Standard_Integer Nb, i; | |
431 | Nb = aFBABWV->NbVoids(); | |
432 | for ( i=1; i<=Nb; i++ ) { | |
433 | aCShell = aFBABWV->VoidsValue(i); | |
434 | myTranShell.Init(aCShell, myTool, dummyNMTool); | |
435 | if (myTranShell.IsDone()) { | |
63c71e2f | 436 | Sh = myTranShell.Value(); |
437 | Sh.Closed(Standard_True); | |
438 | //BRepLib::SameParameter(Sh); | |
439 | B.Add(S, Sh); | |
7fd59977 | 440 | } |
441 | else { | |
442 | TP->AddWarning | |
443 | (aCShell," A Void from FacetedBrepAndBrepWithVoids not mapped to TopoDS"); | |
444 | } | |
445 | } | |
446 | myResult = S; | |
447 | myError = StepToTopoDS_BuilderDone; | |
448 | done = Standard_True; | |
449 | } | |
450 | else { | |
451 | TP->AddWarning | |
452 | (aCShell," OuterShell from FacetedBrepAndBrepWithVoids not mapped to TopoDS"); | |
453 | done = Standard_False; | |
454 | myError = StepToTopoDS_BuilderOther; | |
455 | } | |
456 | } | |
457 | ||
458 | // ============================================================================ | |
459 | // Method : Init | |
460 | // Purpose : Init with a ShellBasedSurfaceModel | |
461 | // ============================================================================ | |
462 | ||
463 | void StepToTopoDS_Builder::Init | |
464 | (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM, | |
465 | const Handle(Transfer_TransientProcess)& TP, | |
466 | StepToTopoDS_NMTool& NMTool) | |
467 | { | |
0ebe5b0a | 468 | Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo(); |
7fd59977 | 469 | // Initialisation of the Tool |
470 | ||
471 | StepToTopoDS_Tool myTool; | |
472 | StepToTopoDS_DataMapOfTRI aMap; | |
473 | ||
474 | myTool.Init(aMap, TP); | |
475 | ||
476 | // Start Mapping | |
477 | ||
478 | Standard_Integer Nb = aSBSM->NbSbsmBoundary(); | |
479 | StepShape_Shell aShell; | |
480 | //Handle(StepShape_VertexShell) aVertexShell; | |
481 | Handle(StepShape_OpenShell) aOpenShell; | |
482 | Handle(StepShape_ClosedShell) aClosedShell; | |
483 | TopoDS_Compound S; | |
484 | //TopoDS_Shape Sh; | |
485 | TopoDS_Shape Shl; | |
486 | BRep_Builder B; | |
487 | B.MakeCompound(S); | |
488 | StepToTopoDS_TranslateShell myTranShell; | |
489 | ||
490 | myTranShell.SetPrecision(Precision()); | |
491 | myTranShell.SetMaxTol(MaxTol()); | |
492 | ||
493 | Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb, 1 ); | |
63c71e2f | 494 | for (Standard_Integer i = 1; i <= Nb && PS.More(); i++, PS.Next()) { |
7fd59977 | 495 | aShell = aSBSM->SbsmBoundaryValue(i); |
63c71e2f | 496 | aOpenShell = aShell.OpenShell(); |
7fd59977 | 497 | aClosedShell = aShell.ClosedShell(); |
7fd59977 | 498 | if (!aOpenShell.IsNull()) { |
499 | myTranShell.Init(aOpenShell, myTool, NMTool); | |
500 | if (myTranShell.IsDone()) { | |
63c71e2f | 501 | Shl = TopoDS::Shell(myTranShell.Value()); |
502 | Shl.Closed(Standard_False); | |
503 | B.Add(S, Shl); | |
7fd59977 | 504 | } |
63c71e2f | 505 | else { |
506 | TP->AddWarning | |
507 | (aOpenShell, " OpenShell from ShellBasedSurfaceModel not mapped to TopoDS"); | |
7fd59977 | 508 | } |
509 | } | |
510 | else if (!aClosedShell.IsNull()) { | |
511 | myTranShell.Init(aClosedShell, myTool, NMTool); | |
512 | if (myTranShell.IsDone()) { | |
63c71e2f | 513 | Shl = TopoDS::Shell(myTranShell.Value()); |
514 | Shl.Closed(Standard_True); | |
515 | B.Add(S, Shl); | |
7fd59977 | 516 | } |
63c71e2f | 517 | else { |
518 | TP->AddWarning | |
519 | (aClosedShell, " ClosedShell from ShellBasedSurfaceModel not mapped to TopoDS"); | |
7fd59977 | 520 | } |
521 | } | |
522 | } | |
523 | if(Nb>1) | |
524 | myResult = S; | |
525 | else | |
526 | myResult = Shl; | |
527 | myError = StepToTopoDS_BuilderDone; | |
528 | done = Standard_True; | |
529 | ||
530 | // Get Statistics : | |
531 | ||
532 | if ( TP->TraceLevel() > 2 ) | |
533 | { | |
0ebe5b0a | 534 | sout << "Geometric Statitics : " << std::endl; |
535 | sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl; | |
536 | sout << " - C1 : " << myTool.C1Surf() << std::endl; | |
537 | sout << " - C2 : " << myTool.C2Surf() << std::endl; | |
538 | sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << std::endl; | |
539 | sout << " - C1 : " << myTool.C1Cur3() << std::endl; | |
540 | sout << " - C2 : " << myTool.C2Cur3() << std::endl; | |
541 | sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << std::endl; | |
542 | sout << " - C1 : " << myTool.C1Cur2() << std::endl; | |
543 | sout << " - C2 : " << myTool.C2Cur2() << std::endl; | |
7fd59977 | 544 | } |
545 | ||
546 | //:S4136 ShapeFix::SameParameter (S,Standard_False); | |
547 | ResetPreci (S, MaxTol()); | |
548 | ResetPreci (Shl, MaxTol()); //skl | |
549 | } | |
550 | ||
551 | // ============================================================================ | |
552 | // Method : Init | |
553 | // Purpose : Init with a EdgeBasedWireframeModel | |
554 | // ============================================================================ | |
555 | ||
556 | void StepToTopoDS_Builder::Init (const Handle(StepShape_EdgeBasedWireframeModel)& aEBWM, | |
557 | const Handle(Transfer_TransientProcess)& TP) | |
558 | { | |
559 | myResult.Nullify(); | |
560 | ||
561 | Handle(StepShape_HArray1OfConnectedEdgeSet) boundary = aEBWM->EbwmBoundary(); | |
562 | if ( boundary.IsNull() || boundary->Length() <1 ) { | |
563 | TP->AddWarning ( aEBWM, "List of boundaries is empty" ); | |
564 | return; | |
565 | } | |
566 | ||
567 | StepToTopoDS_Tool myTool; | |
568 | StepToTopoDS_DataMapOfTRI aMap; | |
569 | myTool.Init(aMap, TP); | |
570 | ||
571 | StepToTopoDS_TranslateEdge myTranEdge; | |
572 | myTranEdge.SetPrecision(Precision()); | |
573 | myTranEdge.SetMaxTol(MaxTol()); | |
574 | ||
575 | TopoDS_Compound C; | |
576 | BRep_Builder B; | |
577 | B.MakeCompound ( C ); | |
578 | ||
579 | StepToTopoDS_NMTool dummyNMTool; | |
580 | ||
581 | for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) { | |
582 | Handle(StepShape_ConnectedEdgeSet) ces = boundary->Value(i); | |
583 | if ( ces.IsNull() ) continue; | |
584 | Handle(StepShape_HArray1OfEdge) edges = ces->CesEdges(); | |
585 | if ( edges.IsNull() || edges->Length() <1 ) { | |
586 | TP->AddWarning ( ces, "No edges in connected_edge_set" ); | |
587 | continue; | |
588 | } | |
589 | TopoDS_Wire W; | |
590 | for ( Standard_Integer j=1; j <= edges->Length(); j++ ) { | |
591 | myTranEdge.Init (edges->Value(j), myTool, dummyNMTool); | |
592 | if ( ! myTranEdge.IsDone() ) continue; | |
593 | TopoDS_Edge E = TopoDS::Edge(myTranEdge.Value()); | |
594 | if (E.IsNull()) continue; // NULL, on saute | |
595 | if ( W.IsNull() ) B.MakeWire ( W ); | |
596 | B.Add ( W, E ); | |
597 | } | |
598 | if ( W.IsNull() ) continue; | |
ab860031 | 599 | W.Closed (BRep_Tool::IsClosed (W)); |
7fd59977 | 600 | B.Add ( C, W ); |
601 | if ( myResult.IsNull() ) myResult = W; | |
602 | else myResult = C; | |
603 | } | |
604 | ||
605 | myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther ); | |
606 | done = ! myResult.IsNull(); | |
607 | ||
608 | ResetPreci (myResult, MaxTol()); | |
609 | } | |
610 | ||
611 | // ============================================================================ | |
612 | // Method : Init | |
613 | // Purpose : Init with a FaceBasedSurfaceModel | |
614 | // ============================================================================ | |
615 | ||
616 | void StepToTopoDS_Builder::Init (const Handle(StepShape_FaceBasedSurfaceModel)& aFBSM, | |
617 | const Handle(Transfer_TransientProcess)& TP) | |
618 | { | |
619 | myResult.Nullify(); | |
620 | ||
621 | Handle(StepShape_HArray1OfConnectedFaceSet) boundary = aFBSM->FbsmFaces(); | |
622 | if ( boundary.IsNull() || boundary->Length() <1 ) { | |
623 | TP->AddWarning ( aFBSM, "List of faces is empty" ); | |
624 | return; | |
625 | } | |
626 | ||
627 | StepToTopoDS_Tool myTool; | |
628 | StepToTopoDS_DataMapOfTRI aMap; | |
629 | myTool.Init(aMap, TP); | |
630 | ||
631 | StepToTopoDS_TranslateFace myTranFace; | |
632 | myTranFace.SetPrecision(Precision()); | |
633 | myTranFace.SetMaxTol(MaxTol()); | |
634 | ||
635 | TopoDS_Compound C; | |
636 | BRep_Builder B; | |
637 | B.MakeCompound ( C ); | |
638 | ||
639 | // Non-manifold topology is not mapped via FaceBasedSurfaceModel (ssv; 14.11.2010) | |
640 | StepToTopoDS_NMTool dummyNMTool; | |
641 | ||
642 | for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) { | |
643 | Handle(StepShape_ConnectedFaceSet) cfs = boundary->Value(i); | |
644 | if ( cfs.IsNull() ) continue; | |
645 | Handle(StepShape_HArray1OfFace) faces = cfs->CfsFaces(); | |
646 | if ( faces.IsNull() || faces->Length() <1 ) { | |
647 | TP->AddWarning ( cfs, "No faces in connected_face_set" ); | |
648 | continue; | |
649 | } | |
650 | TopoDS_Shell S; | |
651 | for ( Standard_Integer j=1; j <= faces->Length(); j++ ) { | |
652 | Handle(StepShape_FaceSurface) fs = Handle(StepShape_FaceSurface)::DownCast ( faces->Value(j) ); | |
653 | myTranFace.Init(fs, myTool, dummyNMTool); | |
654 | if ( ! myTranFace.IsDone() ) continue; | |
655 | TopoDS_Face F = TopoDS::Face(myTranFace.Value()); | |
656 | if (F.IsNull()) continue; // NULL, on saute | |
657 | if ( S.IsNull() ) B.MakeShell ( S ); | |
658 | B.Add ( S, F ); | |
659 | } | |
660 | if ( S.IsNull() ) continue; | |
ab860031 | 661 | S.Closed (BRep_Tool::IsClosed (S)); |
7fd59977 | 662 | B.Add ( C, S ); |
663 | if ( myResult.IsNull() ) myResult = S; | |
664 | else myResult = C; | |
665 | } | |
666 | ||
667 | myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther ); | |
668 | done = ! myResult.IsNull(); | |
669 | ||
670 | ResetPreci (myResult, MaxTol()); | |
671 | } | |
672 | ||
673 | ||
674 | // ***start DTH Apr/6 | |
675 | // ============================================================================ | |
676 | // Method : Init | |
677 | // Purpose : Init with a GeometricCurveSet | |
678 | // ============================================================================ | |
679 | //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GS: GeometricCurveSet -> GeometricSet | |
680 | ||
1c72dff6 S |
681 | static TopoDS_Face TranslateBoundedSurf (const Handle(StepGeom_Surface) &surf, |
682 | const Standard_Real TolDegen) | |
7fd59977 | 683 | { |
684 | TopoDS_Face res; | |
685 | ||
caaeed1b | 686 | Handle(Geom_Surface) theSurf = StepToGeom::MakeSurface (surf); |
687 | if (theSurf.IsNull() || //:i6: protection | |
7fd59977 | 688 | !theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) return res; |
689 | ||
9d109e39 | 690 | BRepBuilderAPI_MakeFace myMkFace; |
9d109e39 | 691 | Handle(Geom_RectangularTrimmedSurface) RS = |
692 | Handle(Geom_RectangularTrimmedSurface)::DownCast(theSurf); | |
693 | ||
694 | if (!RS.IsNull()) | |
695 | { | |
696 | Standard_Real umin, umax, vmin, vmax; | |
697 | theSurf->Bounds(umin, umax, vmin, vmax); | |
698 | ||
440906ef | 699 | myMkFace.Init(RS->BasisSurface(), umin, umax, vmin, vmax, TolDegen); |
9d109e39 | 700 | } |
701 | else | |
702 | { | |
440906ef | 703 | myMkFace.Init(theSurf, Standard_True, TolDegen); |
9d109e39 | 704 | } |
440906ef | 705 | |
7fd59977 | 706 | return myMkFace.Face(); |
707 | } | |
708 | ||
709 | void StepToTopoDS_Builder::Init | |
710 | (const Handle(StepShape_GeometricSet)& GCS, | |
38deba5d | 711 | const Handle(Transfer_TransientProcess)& TP, |
712 | const Handle(Transfer_ActorOfTransientProcess)& RA, | |
713 | const Standard_Boolean isManifold) | |
7fd59977 | 714 | { |
7fd59977 | 715 | // Start Mapping |
716 | TopoDS_Compound S; | |
717 | BRep_Builder B; | |
718 | B.MakeCompound(S); | |
719 | TopoDS_Edge theEdge; | |
720 | Standard_Integer i; | |
721 | Standard_Real preci = Precision(); //gka | |
722 | Standard_Real maxtol = MaxTol(); | |
723 | Standard_Integer nbElem = GCS->NbElements(); | |
724 | for (i = 1; i <= nbElem ; i++) { | |
725 | StepShape_GeometricSetSelect aGSS = GCS->ElementsValue(i); | |
726 | Handle(Standard_Transient) ent = aGSS.Value(); | |
727 | ||
728 | TopoDS_Shape res = TransferBRep::ShapeResult ( TP, ent ); | |
729 | if ( ! res.IsNull() ) { // already translated | |
730 | B.Add ( S, res ); | |
731 | continue; | |
732 | } | |
733 | //:o7 abv 18 Feb 99: bm1_sy_fuel.stp #1427(1,2) protection against null entity | |
734 | if ( ent.IsNull() ) { | |
735 | char buff[100]; | |
736 | sprintf ( buff, "Entity %d is a Null entity", i ); | |
737 | TP->AddWarning (GCS,buff); | |
738 | continue; | |
739 | } | |
740 | // try curve | |
741 | else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Curve)) ) { | |
742 | Handle(StepGeom_Curve) aCrv = Handle(StepGeom_Curve)::DownCast ( ent ); | |
743 | ||
744 | // try composite_curve | |
745 | Handle(StepGeom_CompositeCurve) CC = Handle(StepGeom_CompositeCurve)::DownCast(aCrv); | |
63c71e2f | 746 | if (!CC.IsNull()) { |
747 | StepToTopoDS_TranslateCompositeCurve TrCC; | |
748 | TrCC.SetPrecision(preci); | |
749 | TrCC.SetMaxTol(maxtol); | |
750 | TrCC.Init(CC, TP); | |
751 | if (TrCC.IsDone()) | |
752 | { | |
753 | if (TrCC.IsInfiniteSegment()) | |
754 | { | |
755 | BRep_Builder aB; | |
756 | TopoDS_Compound aComp; | |
757 | aB.MakeCompound(aComp); | |
758 | TopExp_Explorer anExp; | |
759 | for (anExp.Init(TrCC.Value(), TopAbs_EDGE); anExp.More(); anExp.Next()) | |
760 | aB.Add(aComp, anExp.Current()); | |
761 | res = aComp; | |
762 | } | |
763 | else | |
764 | res = TrCC.Value(); | |
765 | } | |
7fd59977 | 766 | } |
767 | else { // try other curves | |
63c71e2f | 768 | Handle(Geom_Curve) aGeomCrv; |
769 | try { | |
770 | OCC_CATCH_SIGNALS | |
771 | aGeomCrv = StepToGeom::MakeCurve(aCrv); | |
772 | } | |
773 | catch (Standard_Failure const& anException) { | |
0ebe5b0a | 774 | Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo(); |
63c71e2f | 775 | sout << "StepToTopoDS, GeometricSet, elem " << i << " of " << nbElem << ": exception "; |
0ebe5b0a | 776 | sout << anException.GetMessageString() << std::endl; |
63c71e2f | 777 | } |
778 | if (!aGeomCrv.IsNull()) { | |
779 | BRepBuilderAPI_MakeEdge anEdge(aGeomCrv, aGeomCrv->FirstParameter(), aGeomCrv->LastParameter()); | |
780 | if (anEdge.IsDone()) res = anEdge.Edge(); | |
781 | } | |
7fd59977 | 782 | } |
783 | } | |
784 | // try point | |
785 | else if ( ent->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint)) ) { | |
786 | Handle(StepGeom_CartesianPoint) aPnt = Handle(StepGeom_CartesianPoint)::DownCast ( ent ); | |
caaeed1b | 787 | Handle(Geom_CartesianPoint) thePnt = StepToGeom::MakeCartesianPoint (aPnt); |
788 | if (! thePnt.IsNull()) { | |
7fd59977 | 789 | BRepBuilderAPI_MakeVertex myMkVtx(thePnt->Pnt()); |
790 | if ( myMkVtx.IsDone() ) res = myMkVtx.Vertex(); | |
791 | } | |
792 | } | |
793 | // Element should finally be a Surface | |
63c71e2f | 794 | else if (ent->IsKind(STANDARD_TYPE(StepGeom_Surface))) { |
795 | Handle(StepGeom_Surface) aSurf = | |
796 | Handle(StepGeom_Surface)::DownCast(ent); | |
797 | ||
7fd59977 | 798 | // try curve_bounded_surf |
63c71e2f | 799 | if (ent->IsKind(STANDARD_TYPE(StepGeom_CurveBoundedSurface))) { |
800 | Handle(StepGeom_CurveBoundedSurface) CBS = | |
801 | Handle(StepGeom_CurveBoundedSurface)::DownCast(aSurf); | |
802 | StepToTopoDS_TranslateCurveBoundedSurface TrCBS; | |
803 | TrCBS.SetPrecision(preci); | |
804 | TrCBS.SetMaxTol(maxtol); | |
805 | ||
806 | TrCBS.Init(CBS, TP); | |
807 | if (TrCBS.IsDone()) res = TrCBS.Value(); | |
7fd59977 | 808 | } |
809 | // try RectangularCompositeSurface | |
63c71e2f | 810 | else if (ent->IsKind(STANDARD_TYPE(StepGeom_RectangularCompositeSurface))) { |
811 | Handle(StepGeom_RectangularCompositeSurface) RCS = | |
812 | Handle(StepGeom_RectangularCompositeSurface)::DownCast(aSurf); | |
813 | Standard_Integer nbi = RCS->NbSegmentsI(); | |
814 | Standard_Integer nbj = RCS->NbSegmentsJ(); | |
815 | TopoDS_Compound C; | |
816 | B.MakeCompound(C); | |
817 | for (Standard_Integer ii = 1; ii <= nbi; ii++) | |
818 | for (Standard_Integer j = 1; j <= nbj; j++) { | |
819 | Handle(StepGeom_SurfacePatch) patch = RCS->SegmentsValue(ii, j); | |
820 | TopoDS_Face f = TranslateBoundedSurf(patch->ParentSurface(), preci); | |
821 | if (!f.IsNull()) B.Add(C, f); | |
822 | } | |
823 | res = C; | |
7fd59977 | 824 | } |
825 | // try other surfs | |
63c71e2f | 826 | else res = TranslateBoundedSurf(aSurf, preci); |
7fd59977 | 827 | } |
38deba5d | 828 | else if ( ent->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) ) |
829 | { | |
830 | Handle(StepGeom_GeometricRepresentationItem) GRI = | |
831 | Handle(StepGeom_GeometricRepresentationItem)::DownCast(ent); | |
832 | if (!RA.IsNull()) | |
833 | { | |
834 | Handle(STEPControl_ActorRead) anActor = Handle(STEPControl_ActorRead)::DownCast(RA); | |
835 | Handle(Transfer_Binder) binder; | |
836 | if( !anActor.IsNull()) | |
837 | binder = anActor->TransferShape(GRI, TP, isManifold); | |
838 | if (!binder.IsNull()) | |
839 | { | |
840 | res = TransferBRep::ShapeResult(binder); | |
841 | } | |
842 | } | |
843 | } | |
844 | else TP->AddWarning (ent," Entity is not a Curve, Point, Surface or GeometricRepresentationItem"); | |
7fd59977 | 845 | if ( ! res.IsNull() ) { |
846 | B.Add(S, res); | |
847 | TransferBRep::SetShapeResult ( TP, ent, res ); | |
848 | } | |
849 | else TP->AddWarning (ent," Entity not mapped to TopoDS"); | |
850 | } | |
851 | myResult = S; | |
852 | myError = StepToTopoDS_BuilderDone; | |
853 | done = Standard_True; | |
854 | } | |
855 | // ***end DTH Apr/6 | |
856 | ||
857 | ||
858 | // ============================================================================ | |
859 | // Method : Value | |
860 | // Purpose : Returns the result of the mapping | |
861 | // ============================================================================ | |
862 | ||
863 | const TopoDS_Shape& StepToTopoDS_Builder::Value() const | |
864 | { | |
2d2b3d53 | 865 | StdFail_NotDone_Raise_if (!done, "StepToTopoDS_Builder::Value() - no result"); |
7fd59977 | 866 | return myResult; |
867 | } | |
868 | ||
869 | // ============================================================================ | |
870 | // Method : Error | |
871 | // Purpose : Returns the Builder Error code | |
872 | // ============================================================================ | |
873 | ||
874 | StepToTopoDS_BuilderError StepToTopoDS_Builder::Error() const | |
875 | { | |
876 | return myError; | |
877 | } | |
878 |