7fd59977 |
1 | //:S4134 abv 10.03.99: working methods moved from package TopoDSToGBWire |
2 | //:j1 modified by abv 22 Oct 98: CSR BUC60401 |
3 | // - unused parts of code dropped |
4 | // - fixed trimming of circles and ellipses (radians used instead of degrees) |
5 | //szv#4 S4163 |
6 | |
7 | #include <TopoDSToStep_WireframeBuilder.ixx> |
8 | #include <TopoDSToStep_Tool.hxx> |
9 | |
10 | #include <TColgp_Array1OfPnt.hxx> |
11 | #include <TColStd_Array1OfReal.hxx> |
12 | #include <TColStd_Array1OfInteger.hxx> |
13 | #include <TColStd_SequenceOfTransient.hxx> |
14 | #include <MoniTool_DataMapOfShapeTransient.hxx> |
15 | #include <TCollection_HAsciiString.hxx> |
16 | #include <TransferBRep_ShapeMapper.hxx> |
17 | #include <Transfer_FinderProcess.hxx> |
18 | |
19 | #include <Precision.hxx> |
20 | #include <gp_Vec.hxx> |
21 | |
22 | #include <Geom2d_Line.hxx> |
23 | #include <Geom_Surface.hxx> |
24 | #include <Geom_TrimmedCurve.hxx> |
25 | #include <Geom_BSplineCurve.hxx> |
26 | #include <Geom_Line.hxx> |
27 | #include <Geom_Circle.hxx> |
28 | #include <Geom_Ellipse.hxx> |
29 | #include <Geom_Plane.hxx> |
30 | |
31 | #include <Adaptor3d_CurveOnSurface.hxx> |
32 | #include <BRepAdaptor_Curve.hxx> |
33 | #include <BRep_Tool.hxx> |
34 | #include <BRepTools.hxx> |
35 | |
36 | #include <TopoDS.hxx> |
37 | #include <TopoDS_Vertex.hxx> |
38 | #include <TopoDS_Face.hxx> |
39 | #include <TopoDS_Shell.hxx> |
40 | #include <TopoDS_Iterator.hxx> |
41 | #include <TopExp_Explorer.hxx> |
42 | #include <TopLoc_Location.hxx> |
43 | |
44 | #include <StepGeom_CartesianPoint.hxx> |
45 | #include <StepGeom_Curve.hxx> |
46 | #include <StepGeom_SurfaceCurve.hxx> |
47 | #include <StepGeom_SeamCurve.hxx> |
48 | #include <StepGeom_TrimmedCurve.hxx> |
49 | #include <StepGeom_TrimmingSelect.hxx> |
50 | #include <StepGeom_HArray1OfTrimmingSelect.hxx> |
51 | |
52 | #include <GeomToStep_MakeCartesianPoint.hxx> |
53 | #include <GeomToStep_MakeCurve.hxx> |
54 | #include <GeomToStep_MakeLine.hxx> |
55 | |
56 | // ============================================================================ |
57 | // Method : TopoDSToStep_Builder::TopoDSToStep_Builder |
58 | // Purpose : |
59 | // ============================================================================ |
60 | |
61 | TopoDSToStep_WireframeBuilder::TopoDSToStep_WireframeBuilder() |
62 | { |
63 | done = Standard_False; |
64 | } |
65 | |
66 | // ============================================================================ |
67 | // Method : TopoDSToStep_Builder::TopoDSToStep_Builder |
68 | // Purpose : |
69 | // ============================================================================ |
70 | |
71 | TopoDSToStep_WireframeBuilder::TopoDSToStep_WireframeBuilder(const TopoDS_Shape& aShape, TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP) |
72 | { |
73 | done = Standard_False; |
74 | Init(aShape, aTool, FP); |
75 | } |
76 | |
77 | void TopoDSToStep_WireframeBuilder::Init(const TopoDS_Shape& aShape, TopoDSToStep_Tool& /* T */, const Handle(Transfer_FinderProcess)& /* FP */) |
78 | { |
79 | Handle(TColStd_HSequenceOfTransient) itemList = |
80 | new TColStd_HSequenceOfTransient(); |
81 | MoniTool_DataMapOfShapeTransient aPmsMap; |
82 | done = GetTrimmedCurveFromShape(aShape, aPmsMap, itemList); |
83 | myResult = itemList; |
84 | } |
85 | |
86 | // ============================================================================ |
87 | // Method : TopoDSToStep_Builder::Error |
88 | // Purpose : |
89 | // ============================================================================ |
90 | |
91 | TopoDSToStep_BuilderError TopoDSToStep_WireframeBuilder::Error() const |
92 | { |
93 | return myError; |
94 | } |
95 | |
96 | // ============================================================================ |
97 | // Method : TopoDSToStep_Builder::Value |
98 | // Purpose : |
99 | // ============================================================================ |
100 | |
101 | const Handle(TColStd_HSequenceOfTransient)& TopoDSToStep_WireframeBuilder::Value() const |
102 | { |
103 | StdFail_NotDone_Raise_if(!done,""); |
104 | return myResult; |
105 | } |
106 | |
107 | |
108 | // ============================================================================ |
109 | //:S4134: abv 10 Mar 99: the methods below moved from package TopoDSToGBWire |
110 | |
111 | #define Nbpt 23 |
112 | |
113 | static Handle(StepGeom_TrimmedCurve) MakeTrimmedCurve (const Handle(StepGeom_Curve) &C, |
114 | const Handle(StepGeom_CartesianPoint) P1, |
115 | const Handle(StepGeom_CartesianPoint) P2, |
116 | Standard_Real trim1, |
117 | Standard_Real trim2, |
118 | Standard_Boolean sense) |
119 | { |
120 | Handle(StepGeom_HArray1OfTrimmingSelect) aSTS1 = |
121 | new StepGeom_HArray1OfTrimmingSelect(1,2); |
122 | StepGeom_TrimmingSelect tSel; |
123 | tSel.SetValue(P1); |
124 | aSTS1->SetValue(1,tSel); |
125 | tSel.SetParameterValue(trim1); |
126 | aSTS1->SetValue(2,tSel); |
127 | |
128 | Handle(StepGeom_HArray1OfTrimmingSelect) aSTS2 = |
129 | new StepGeom_HArray1OfTrimmingSelect(1,2); |
130 | tSel.SetValue(P2); |
131 | aSTS2->SetValue(1,tSel); |
132 | tSel.SetParameterValue(trim2); |
133 | aSTS2->SetValue(2,tSel); |
134 | |
135 | Handle(TCollection_HAsciiString) empty = |
136 | new TCollection_HAsciiString(""); |
137 | Handle(StepGeom_TrimmedCurve) pmsTC = new StepGeom_TrimmedCurve; |
138 | pmsTC->Init(empty,C,aSTS1,aSTS2,sense,StepGeom_tpParameter); |
139 | return pmsTC; |
140 | } |
141 | |
142 | Standard_Boolean TopoDSToStep_WireframeBuilder:: |
143 | GetTrimmedCurveFromEdge(const TopoDS_Edge& theEdge, |
144 | const TopoDS_Face& aFace, |
145 | MoniTool_DataMapOfShapeTransient& aMap, |
146 | Handle(TColStd_HSequenceOfTransient)& curveList) const |
147 | { |
148 | if (theEdge.Orientation() == TopAbs_INTERNAL || |
149 | theEdge.Orientation() == TopAbs_EXTERNAL ) { |
150 | #ifdef DEB |
151 | cout <<"Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Edge is internal or external; dropped" << endl; |
152 | #endif |
153 | return Standard_False; |
154 | } |
155 | //szv#4:S4163:12Mar99 SGI warns |
156 | TopoDS_Shape sh = theEdge.Oriented(TopAbs_FORWARD); |
157 | TopoDS_Edge anEdge = TopoDS::Edge ( sh ); |
158 | |
159 | // resulting curve |
160 | Handle(StepGeom_Curve) Gpms; |
161 | |
162 | if ( aMap.IsBound(anEdge)) { |
163 | Gpms = Handle(StepGeom_Curve)::DownCast ( aMap.Find(anEdge) ); |
164 | if ( Gpms.IsNull() ) return Standard_False; |
165 | //?? curveList->Append(Gpms); |
166 | return Standard_True; |
167 | } |
168 | |
169 | BRepAdaptor_Curve CA ( anEdge ); |
170 | |
171 | // Vertices |
172 | TopoDS_Vertex Vfirst, Vlast; |
173 | Handle(StepGeom_CartesianPoint) pmsP1, pmsP2; |
174 | for (TopoDS_Iterator It(anEdge);It.More();It.Next()) { |
175 | // Translates the Edge Vertices |
176 | TopoDS_Vertex V = TopoDS::Vertex(It.Value()); |
177 | gp_Pnt gpP = BRep_Tool::Pnt(V); |
178 | if ( V.Orientation() == TopAbs_FORWARD ) { |
179 | Vfirst = V; |
180 | // 1.point for trimming |
181 | GeomToStep_MakeCartesianPoint gtpP(gpP); |
182 | pmsP1 = gtpP.Value(); |
183 | } |
184 | if ( V.Orientation() == TopAbs_REVERSED ) { |
185 | Vlast = V; |
186 | // 2.point for trimming |
187 | GeomToStep_MakeCartesianPoint gtpP(gpP); |
188 | pmsP2 = gtpP.Value(); |
189 | } |
190 | } |
191 | |
192 | // --------------------------------------- |
193 | // Translate 3D representation of the Edge |
194 | // --------------------------------------- |
195 | |
196 | |
197 | // Handle(Geom_Curve) C = CA.Curve().Curve(); |
198 | |
199 | // UPDATE FMA 26-02-96 |
200 | // General remark : this full code should be deaply reworked |
201 | // Too many objects are not used ! |
202 | |
203 | Standard_Real First, Last; |
204 | Handle(Geom_Curve) C = BRep_Tool::Curve(anEdge, First, Last); |
205 | if ( ! C.IsNull() ) { |
206 | if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) |
207 | C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve(); |
208 | GeomToStep_MakeCurve gtpC(C); |
209 | Handle(StepGeom_Curve) pmsC = gtpC.Value(); |
210 | |
211 | // trim the curve |
212 | Standard_Real trim1 = CA.FirstParameter(); |
213 | Standard_Real trim2 = CA.LastParameter(); |
214 | /* //:j1 abv 22 Oct 98: radians are used in the produced STEP file (at least by default) |
215 | if(C->IsKind(STANDARD_TYPE(Geom_Circle)) || |
216 | C->IsKind(STANDARD_TYPE(Geom_Ellipse))) { |
217 | Standard_Real fact = 180. / PI; |
218 | trim1 = trim1 * fact; |
219 | trim2 = trim2 * fact; |
220 | } |
221 | */ |
222 | Gpms = MakeTrimmedCurve (pmsC, pmsP1, pmsP2, trim1, trim2, Standard_True ); |
223 | // (anEdge.Orientation() == TopAbs_FORWARD)); |
224 | } |
225 | else { |
226 | |
227 | // ------------------------- |
228 | // a 3D Curve is constructed |
229 | // ------------------------- |
230 | |
231 | Standard_Boolean iaplan = Standard_False; |
232 | if ( ! aFace.IsNull() ) { |
233 | Standard_Real cf, cl; |
234 | Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(anEdge, aFace, cf, cl); |
235 | Handle(Geom_Surface) S = BRep_Tool::Surface(aFace); |
236 | if (S->IsKind(STANDARD_TYPE(Geom_Plane)) && |
237 | C2d->IsKind(STANDARD_TYPE(Geom2d_Line))) iaplan = Standard_True; |
238 | } |
239 | |
240 | // to be modified : cf and cl are the topological trimming prameter |
241 | // these are computed after ! (U1 and U2) -> cf and cl instead |
242 | if (iaplan) { |
243 | gp_Pnt Pnt1 = CA.Value(CA.FirstParameter()), Pnt2 = CA.Value(CA.LastParameter()); |
244 | gp_Vec V ( Pnt1, Pnt2 ); |
245 | Standard_Real length = V.Magnitude(); |
246 | if ( length >= Precision::Confusion() ) { |
247 | Handle(Geom_Line) L = new Geom_Line(Pnt1, gp_Dir(V)); |
248 | GeomToStep_MakeLine gtpL(L); |
249 | Gpms = gtpL.Value(); |
250 | Gpms = MakeTrimmedCurve (gtpL.Value(), pmsP1, pmsP2, 0, length, Standard_True ); |
251 | // (anEdge.Orientation() == TopAbs_FORWARD)); |
252 | } |
253 | #ifdef DEB |
254 | else cout << "Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Null-length curve not mapped" << endl; |
255 | #endif |
256 | } |
257 | else { |
258 | TColgp_Array1OfPnt Points(1,Nbpt); |
259 | TColStd_Array1OfReal Knots(1,Nbpt); |
260 | TColStd_Array1OfInteger Mult(1,Nbpt); |
261 | Standard_Real U1 = CA.FirstParameter(); |
262 | Standard_Real U2 = CA.LastParameter(); |
263 | for ( Standard_Integer i=1; i<=Nbpt; i++ ) { |
264 | Standard_Real U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1); |
265 | gp_Pnt P = CA.Value(U); |
266 | Points.SetValue(i,P); |
267 | Knots.SetValue(i,U); |
268 | Mult.SetValue(i,1); |
269 | } |
270 | Points.SetValue(1, BRep_Tool::Pnt(Vfirst)); |
271 | Points.SetValue(Nbpt, BRep_Tool::Pnt(Vlast)); |
272 | Mult.SetValue(1,2); |
273 | Mult.SetValue(Nbpt,2); |
274 | Handle(Geom_BSplineCurve) Bs = |
275 | new Geom_BSplineCurve(Points, Knots, Mult, 1); |
276 | GeomToStep_MakeCurve gtpC(Bs); |
277 | Gpms = gtpC.Value(); |
278 | } |
279 | } |
280 | if( Gpms.IsNull() ) return Standard_False; |
281 | |
282 | aMap.Bind(anEdge, Gpms); |
283 | curveList->Append(Gpms); |
284 | return Standard_True; |
285 | } |
286 | |
287 | |
288 | Standard_Boolean TopoDSToStep_WireframeBuilder:: |
289 | GetTrimmedCurveFromFace(const TopoDS_Face& aFace, |
290 | MoniTool_DataMapOfShapeTransient& aMap, |
291 | Handle(TColStd_HSequenceOfTransient)& aCurveList) const |
292 | { |
293 | TopoDS_Shape curShape; |
294 | TopoDS_Edge curEdge; |
295 | TopExp_Explorer exp; |
296 | Standard_Boolean result = Standard_False; //szv#4:S4163:12Mar99 `done` hid one from this, initialisation needed |
297 | |
298 | for (exp.Init(aFace,TopAbs_EDGE); exp.More(); exp.Next()){ |
299 | curShape = exp.Current(); |
300 | curEdge = TopoDS::Edge(curShape); |
301 | if (GetTrimmedCurveFromEdge(curEdge, aFace, aMap, aCurveList)) result = Standard_True; |
302 | } |
303 | return result; |
304 | } |
305 | |
306 | Standard_Boolean TopoDSToStep_WireframeBuilder:: |
307 | GetTrimmedCurveFromShape(const TopoDS_Shape& aShape, |
308 | MoniTool_DataMapOfShapeTransient& aMap, |
309 | Handle(TColStd_HSequenceOfTransient)& aCurveList) const |
310 | { |
311 | TopoDS_Iterator It; |
312 | Standard_Boolean result = Standard_False; //szv#4:S4163:12Mar99 `done` hid one from this, initialisation needed |
313 | |
314 | //szv#4:S4163:12Mar99 optimized |
315 | switch (aShape.ShapeType()) { |
316 | case TopAbs_EDGE : { |
317 | const TopoDS_Edge& curEdge = TopoDS::Edge(aShape); |
318 | TopoDS_Face nulFace; |
319 | result = GetTrimmedCurveFromEdge(curEdge, nulFace, aMap, aCurveList); |
320 | break; |
321 | } |
322 | case TopAbs_WIRE : { |
323 | TopoDS_Face nulFace; |
324 | TopoDS_Shape curShape; |
325 | TopoDS_Edge curEdge; |
326 | TopExp_Explorer exp; |
327 | |
328 | for (exp.Init(aShape,TopAbs_EDGE); exp.More(); exp.Next()){ |
329 | curShape = exp.Current(); |
330 | curEdge = TopoDS::Edge(curShape); |
331 | if (GetTrimmedCurveFromEdge(curEdge, nulFace, aMap, aCurveList)) result = Standard_True; |
332 | } |
333 | break; |
334 | } |
335 | case TopAbs_FACE : { |
336 | const TopoDS_Face& curFace = TopoDS::Face(aShape); |
337 | result = GetTrimmedCurveFromFace(curFace, aMap, aCurveList); |
338 | break; |
339 | } |
340 | case TopAbs_SHELL : { |
341 | TopoDS_Shell Sh = TopoDS::Shell(aShape); |
342 | It.Initialize(Sh); |
343 | for (;It.More();It.Next()) { |
344 | TopoDS_Face curFace = TopoDS::Face(It.Value()); |
345 | if (GetTrimmedCurveFromFace(curFace, aMap, aCurveList)) result = Standard_True; |
346 | #ifdef DEBUG |
347 | if(!result) { |
348 | cout << "ERROR extracting trimmedCurve from Face" << endl; |
349 | //BRepTools::Dump(curFace,cout); cout<<endl; |
350 | } |
351 | #endif |
352 | } |
353 | break; |
354 | } |
355 | case TopAbs_SOLID : { |
356 | It.Initialize(aShape); |
357 | for (;It.More();It.Next()) { |
358 | if (It.Value().ShapeType() == TopAbs_SHELL) { |
359 | if (GetTrimmedCurveFromShape(It.Value(), aMap, aCurveList)) result = Standard_True; |
360 | } |
361 | } |
362 | break; |
363 | } |
364 | case TopAbs_COMPOUND : { |
365 | It.Initialize(aShape); |
366 | for (;It.More();It.Next()) { |
367 | /* if ((It.Value().ShapeType() == TopAbs_SHELL) || |
368 | (It.Value().ShapeType() == TopAbs_COMPOUND)) { |
369 | result = GetTrimmedCurveFromShape(It.Value(), aMap, aCurveList); |
370 | break; |
371 | } |
372 | else if (It.Value().ShapeType() == TopAbs_FACE) { |
373 | result = GetTrimmedCurveFromFace(TopoDS::Face(It.Value()), aMap, aCurveList); |
374 | break; |
375 | } */ |
376 | if (GetTrimmedCurveFromShape(It.Value(), aMap, aCurveList)) result = Standard_True; |
377 | } |
378 | break; |
379 | } |
380 | default : break; |
381 | } |
382 | return result; |
383 | } |