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