b311480e |
1 | // Created on: 1994-11-30 |
2 | // Created by: Frederic MAUPAS |
3 | // Copyright (c) 1994-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 | //szv#4 S4163 |
18 | |
19 | #include <TopoDSToStep_MakeStepWire.ixx> |
20 | |
21 | #include <TopoDSToStep_MakeStepVertex.hxx> |
22 | #include <TopoDSToStep_MakeStepEdge.hxx> |
23 | |
24 | #include <BRepTools_WireExplorer.hxx> |
25 | |
26 | #include <TColStd_SequenceOfTransient.hxx> |
27 | |
28 | #include <TopoDS_Iterator.hxx> |
29 | |
30 | #include <BRep_Tool.hxx> |
31 | |
32 | #include <Geom2d_Curve.hxx> |
33 | #include <Geom2d_Line.hxx> |
34 | |
35 | #include <gp_Pnt.hxx> |
36 | |
37 | #include <TopExp.hxx> |
38 | |
39 | #include <TopoDS.hxx> |
40 | |
41 | #include <StepShape_VertexPoint.hxx> |
42 | #include <StepShape_Edge.hxx> |
43 | #include <StepShape_EdgeLoop.hxx> |
44 | #include <StepShape_VertexLoop.hxx> |
45 | #include <StepShape_HArray1OfOrientedEdge.hxx> |
46 | #include <StepShape_OrientedEdge.hxx> |
47 | #include <StepShape_PolyLoop.hxx> |
48 | #include <StepGeom_CartesianPoint.hxx> |
49 | #include <StepGeom_HArray1OfCartesianPoint.hxx> |
50 | #include <TransferBRep_ShapeMapper.hxx> |
51 | #include <TCollection_HAsciiString.hxx> |
52 | #include <ShapeExtend_WireData.hxx> |
53 | #include <ShapeFix_Wire.hxx> |
54 | #include <ShapeAnalysis_Edge.hxx> |
55 | |
56 | // ---------------------------------------------------------------------------- |
57 | // Constructors |
58 | // ---------------------------------------------------------------------------- |
59 | |
60 | TopoDSToStep_MakeStepWire::TopoDSToStep_MakeStepWire() |
61 | { |
62 | done = Standard_False; |
63 | } |
64 | |
65 | TopoDSToStep_MakeStepWire::TopoDSToStep_MakeStepWire |
66 | (const TopoDS_Wire& W, |
67 | TopoDSToStep_Tool& T, |
68 | const Handle(Transfer_FinderProcess)& FP) |
69 | { |
70 | done = Standard_False; |
71 | Init(W, T, FP); |
72 | } |
73 | |
74 | |
75 | // ---------------------------------------------------------------------------- |
76 | // Method : Init |
77 | // Purpose : |
78 | // ---------------------------------------------------------------------------- |
79 | |
80 | void TopoDSToStep_MakeStepWire::Init(const TopoDS_Wire& aWire, |
81 | TopoDSToStep_Tool& aTool, |
82 | const Handle(Transfer_FinderProcess)& FP) |
83 | { |
84 | |
85 | // ---------------------------------------------------------------- |
86 | // The Wire is given in its relative orientation (i.e. in the face) |
87 | // ---------------------------------------------------------------- |
88 | |
89 | aTool.SetCurrentWire(aWire); |
90 | |
91 | if (aTool.IsBound(aWire)) { |
92 | myError = TopoDSToStep_WireDone; |
93 | done = Standard_True; |
94 | myResult = aTool.Find(aWire); |
95 | return; |
96 | } |
97 | |
98 | TopoDS_Iterator It; |
99 | Standard_Integer i; |
100 | |
101 | if (aWire.Orientation() == TopAbs_INTERNAL || |
102 | aWire.Orientation() == TopAbs_EXTERNAL ) { |
103 | Handle(TransferBRep_ShapeMapper) errShape = |
104 | new TransferBRep_ShapeMapper(aWire); |
105 | FP->AddWarning(errShape, " Wire(internal/external) from Non Manifold Topology"); |
106 | myError = TopoDSToStep_NonManifoldWire; |
107 | done = Standard_False; |
108 | return; |
109 | } |
110 | |
111 | BRepTools_WireExplorer ItW; |
112 | TopoDS_Edge CurrentEdge; |
113 | TColStd_SequenceOfTransient mySeq; |
114 | |
115 | // -------- |
116 | // Polyloop |
117 | // -------- |
118 | |
119 | if (aTool.Faceted()) { |
120 | Handle(StepShape_VertexPoint) VertexPoint; |
121 | Handle(StepGeom_Point) Point; |
122 | Handle(StepShape_TopologicalRepresentationItem) Gpms; |
123 | TopoDS_Vertex TopoDSVertex1, TopoDSVertex2; |
124 | |
125 | TopoDSToStep_MakeStepVertex MkVertex; |
126 | // TopoDS_Wire ForwardWire = TopoDS::Wire(aWire.Oriented(TopAbs_FORWARD)); |
127 | |
128 | for (ItW.Init(aWire, aTool.CurrentFace()); |
129 | ItW.More();ItW.Next()) { |
130 | CurrentEdge = ItW.Current(); |
131 | if (CurrentEdge.Orientation() == TopAbs_FORWARD) |
132 | TopExp::Vertices(CurrentEdge, TopoDSVertex1, TopoDSVertex2); |
133 | else |
134 | TopExp::Vertices(CurrentEdge, TopoDSVertex2, TopoDSVertex1); |
135 | |
136 | MkVertex.Init(TopoDSVertex1, aTool, FP); |
137 | if (MkVertex.IsDone()) { |
138 | VertexPoint = Handle(StepShape_VertexPoint)::DownCast(MkVertex.Value()); |
139 | Point = VertexPoint->VertexGeometry(); |
140 | mySeq.Append(Point); |
141 | } |
142 | else { |
143 | Handle(TransferBRep_ShapeMapper) errShape = |
144 | new TransferBRep_ShapeMapper(aWire); |
145 | FP->AddWarning(errShape, " a Vertex Point not mapped"); |
146 | myError = TopoDSToStep_WireOther; |
147 | done = Standard_False; |
148 | return; |
149 | } |
150 | } |
151 | Standard_Integer nbPoints = mySeq.Length(); |
152 | if (nbPoints>=3) { |
153 | Handle(StepGeom_HArray1OfCartesianPoint) aPolygon = |
154 | new StepGeom_HArray1OfCartesianPoint(1,nbPoints); |
155 | for ( i=1; i<=nbPoints; i++) { |
156 | aPolygon->SetValue(i, Handle(StepGeom_CartesianPoint):: |
157 | DownCast(mySeq.Value(i))); |
158 | } |
159 | Handle(StepShape_PolyLoop) PL = new StepShape_PolyLoop(); |
160 | Handle(TCollection_HAsciiString) aName = |
161 | new TCollection_HAsciiString(""); |
162 | PL->Init(aName, aPolygon); |
163 | |
164 | aTool.Bind(aWire, PL); |
165 | myError = TopoDSToStep_WireDone; |
166 | done = Standard_True; |
167 | myResult = PL; |
168 | return; |
169 | } |
170 | else { |
171 | Handle(TransferBRep_ShapeMapper) errShape = |
172 | new TransferBRep_ShapeMapper(aWire); |
173 | FP->AddWarning(errShape, " PolyLoop: Wire has less than 3 points"); |
174 | myError = TopoDSToStep_WireOther; |
175 | done = Standard_False; |
176 | return; |
177 | } |
178 | } |
179 | |
180 | // -------- |
181 | // EdgeLoop |
182 | // -------- |
183 | |
184 | else { |
185 | |
186 | Handle(StepShape_TopologicalRepresentationItem) Gpms; |
187 | Handle(StepShape_Edge) Epms; |
188 | Handle(StepShape_OrientedEdge) OrientedEdge; |
189 | |
190 | TopoDSToStep_MakeStepEdge MkEdge; |
191 | |
192 | //szv#4:S4163:12Mar99 SGI warns |
193 | TopoDS_Shape sh = aWire.Oriented(TopAbs_FORWARD); |
194 | const TopoDS_Wire ForwardWire = TopoDS::Wire(sh); |
195 | // test 25-01-96 FMA supprime CKY 2-JUN-1997, cf MakeStepFace->Face FWD] |
196 | // remis CKY 9-DEC-1997 : chaque niveau se traite en FWD |
197 | //#11 rln 16/03/98 |
198 | //TestRally8 file carter2.rle face#333 (wire is not sorted, not sorted edges are seam and iso-curve): |
199 | //aWire is REVERSED but ForwardWire is FORWARD, when exploding not connected seams their pcurves are |
200 | //returned in incorrect order (because of mismatched orientation) |
201 | //As a result not sorted edges are lost (not returned by BRepTools_WireExplorer) |
202 | //By the way, in the case of aTool.Faceted() aWire is used |
203 | |
204 | //#11 ItW.Init(ForwardWire, aTool.CurrentFace()); |
205 | //#11 for (;ItW.More();ItW.Next()) { |
206 | Handle(ShapeFix_Wire) STW = new ShapeFix_Wire; |
207 | STW->Load (ForwardWire); |
208 | STW->FixReorder(); |
209 | Handle(ShapeExtend_WireData) sbwd = STW->WireData(); |
210 | Standard_Integer nb = sbwd->NbEdges(); |
211 | |
212 | //:abv 04.05.00: CAX-IF TRJ4: writing complete sphere with single vertex_loop |
213 | // check that whole wire is one seam (perhaps made of several seam edges) |
214 | //pdn remove degenerated pcurves |
215 | Handle(ShapeExtend_WireData) cwd = new ShapeExtend_WireData; |
216 | Standard_Integer ie; |
217 | for (ie = 1; ie <=nb; ie++) { |
218 | TopoDS_Edge edge = sbwd->Edge(ie); |
219 | if (!BRep_Tool::Degenerated(edge)) |
220 | cwd->Add(edge); |
221 | } |
222 | |
223 | nb = cwd->NbEdges(); |
224 | if(nb%2 == 0 ) { |
225 | for ( ie = 1; ie < nb; ie++) { |
226 | if ( cwd->Edge(ie).IsSame(cwd->Edge(ie+1)) ) break; |
227 | } |
228 | if ( ie < nb ) { |
229 | cwd->SetLast(ie); |
230 | for ( ie=nb/2+1; ie <= nb; ie++ ) { |
231 | if ( ! cwd->Edge(ie).IsSame(cwd->Edge(nb-ie+1)) ) break; |
232 | } |
233 | if ( ie > nb ) { // make vertex_loop |
234 | ShapeAnalysis_Edge sae; |
235 | TopoDS_Vertex V = sae.FirstVertex(cwd->Edge(1)); |
236 | TopoDSToStep_MakeStepVertex mkV ( V, aTool, FP ); |
237 | Handle(StepShape_VertexLoop) vloop = new StepShape_VertexLoop; |
238 | Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( "" ); |
239 | vloop->Init ( name, Handle(StepShape_Vertex)::DownCast ( mkV.Value() ) ); |
240 | aTool.Bind(aWire, vloop); |
241 | myError = TopoDSToStep_WireDone; |
242 | done = Standard_True; |
243 | myResult = vloop; |
244 | return; |
245 | } |
246 | } |
247 | } |
248 | nb = sbwd->NbEdges(); |
249 | |
250 | for (Standard_Integer nEdge = 1; nEdge <= sbwd->NbEdges(); nEdge++) { |
251 | |
252 | CurrentEdge = sbwd->Edge(nEdge); |
253 | //#11 CurrentEdge = ItW.Current(); |
254 | |
255 | //if (ItW.Current().Orientation() != ItW.Orientation()) |
256 | //cout << "DEBUG : Attention WireExplorer Orientation" << endl; |
257 | |
258 | // --------------------------------- |
259 | // --- Is the edge Degenerated ? --- |
260 | // --------------------------------- |
261 | |
262 | Standard_Real cf, cl; |
263 | Handle(Geom2d_Curve) theC2d = |
264 | BRep_Tool::CurveOnSurface(CurrentEdge, aTool.CurrentFace(), cf, cl); |
265 | //BRepAdaptor_Curve CA; |
266 | //CA = BRepAdaptor_Curve(CurrentEdge, |
267 | //aTool.CurrentFace()); |
268 | //GeomAbs_CurveType typC = CA.CurveOnSurface().GetCurve().GetType(); |
269 | //if (typC == GeomAbs_Line && BRep_Tool::Degenerated(CurrentEdge)) { |
270 | //Handle(TransferBRep_ShapeMapper) errShape = |
271 | //new TransferBRep_ShapeMapper(aWire); |
272 | //FP->AddWarning(errShape, " EdgeLoop: Degenerated Pcurve not mapped"); |
273 | //} |
274 | if ( //:abv 26Jan00, CAX-IF TRJ3: ! theC2d.IsNull() && theC2d->IsKind(STANDARD_TYPE(Geom2d_Line)) && |
275 | BRep_Tool::Degenerated(CurrentEdge)) { |
276 | Handle(TransferBRep_ShapeMapper) errShape = |
277 | new TransferBRep_ShapeMapper(aWire); |
278 | FP->AddWarning(errShape, " EdgeLoop: Degenerated Pcurve not mapped"); |
279 | continue; |
280 | } |
281 | else { |
282 | //szv#4:S4163:12Mar99 SGI warns |
283 | //TopoDS_Shape ssh = CurrentEdge.Oriented(TopAbs_FORWARD); |
284 | //const TopoDS_Edge ForwardEdge = TopoDS::Edge(ssh); |
285 | |
286 | MkEdge.Init(CurrentEdge, aTool, FP); |
287 | if (MkEdge.IsDone()) { |
288 | OrientedEdge = new StepShape_OrientedEdge(); |
289 | Epms = Handle(StepShape_Edge)::DownCast(MkEdge.Value()); |
290 | Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(""); |
291 | OrientedEdge->Init(aName, Epms, (CurrentEdge.Orientation() == TopAbs_FORWARD)); |
292 | mySeq.Append(OrientedEdge); |
293 | } |
294 | else { |
295 | Handle(TransferBRep_ShapeMapper) errShape = |
296 | new TransferBRep_ShapeMapper(aWire); |
297 | FP->AddWarning(errShape, " EdgeLoop: an Edge not mapped"); |
298 | myError = TopoDSToStep_WireOther; |
299 | done = Standard_False; |
300 | return; |
301 | } |
302 | } |
303 | } |
304 | Standard_Integer nbEdges = mySeq.Length(); |
305 | if ( nbEdges >0 ) { |
306 | Handle(StepShape_HArray1OfOrientedEdge) aList = |
307 | new StepShape_HArray1OfOrientedEdge(1,nbEdges); |
308 | for ( i=1; i<=nbEdges; i++ ) { |
309 | aList->SetValue(i, Handle(StepShape_OrientedEdge):: |
310 | DownCast(mySeq.Value(i))); |
311 | } |
312 | Handle(StepShape_EdgeLoop) Epmsl = new StepShape_EdgeLoop; |
313 | Handle(TCollection_HAsciiString) aName = |
314 | new TCollection_HAsciiString(""); |
315 | Epmsl->Init(aName, aList); |
316 | aTool.Bind(aWire, Epmsl); |
317 | done = Standard_True; |
318 | myResult = Epmsl; |
319 | return; |
320 | } |
321 | else { |
322 | Handle(TransferBRep_ShapeMapper) errShape = |
323 | new TransferBRep_ShapeMapper(aWire); |
324 | FP->AddWarning(errShape, " No Edges of this Wire were mapped"); |
325 | myError = TopoDSToStep_WireOther; |
326 | done = Standard_False; |
327 | return; |
328 | } |
329 | } |
330 | } |
331 | |
332 | // ---------------------------------------------------------------------------- |
333 | // Method : Value |
334 | // Purpose : |
335 | // ---------------------------------------------------------------------------- |
336 | |
337 | const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepWire::Value() const |
338 | { |
339 | StdFail_NotDone_Raise_if(!done,""); |
340 | return myResult; |
341 | } |
342 | |
343 | // ---------------------------------------------------------------------------- |
344 | // Method : Error |
345 | // Purpose : |
346 | // ---------------------------------------------------------------------------- |
347 | |
348 | TopoDSToStep_MakeWireError TopoDSToStep_MakeStepWire::Error() const |
349 | { |
350 | return myError; |
351 | } |
352 | |