1 // Created on: 1994-11-30
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <TopoDSToStep_MakeStepWire.ixx>
21 #include <TopoDSToStep_MakeStepVertex.hxx>
22 #include <TopoDSToStep_MakeStepEdge.hxx>
24 #include <BRepTools_WireExplorer.hxx>
26 #include <TColStd_SequenceOfTransient.hxx>
28 #include <TopoDS_Iterator.hxx>
30 #include <BRep_Tool.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom2d_Line.hxx>
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>
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 TopoDSToStep_MakeStepWire::TopoDSToStep_MakeStepWire()
62 done = Standard_False;
65 TopoDSToStep_MakeStepWire::TopoDSToStep_MakeStepWire
66 (const TopoDS_Wire& W,
68 const Handle(Transfer_FinderProcess)& FP)
70 done = Standard_False;
75 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 void TopoDSToStep_MakeStepWire::Init(const TopoDS_Wire& aWire,
81 TopoDSToStep_Tool& aTool,
82 const Handle(Transfer_FinderProcess)& FP)
85 // ----------------------------------------------------------------
86 // The Wire is given in its relative orientation (i.e. in the face)
87 // ----------------------------------------------------------------
89 aTool.SetCurrentWire(aWire);
91 if (aTool.IsBound(aWire)) {
92 myError = TopoDSToStep_WireDone;
94 myResult = aTool.Find(aWire);
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;
111 BRepTools_WireExplorer ItW;
112 TopoDS_Edge CurrentEdge;
113 TColStd_SequenceOfTransient mySeq;
119 if (aTool.Faceted()) {
120 Handle(StepShape_VertexPoint) VertexPoint;
121 Handle(StepGeom_Point) Point;
122 Handle(StepShape_TopologicalRepresentationItem) Gpms;
123 TopoDS_Vertex TopoDSVertex1, TopoDSVertex2;
125 TopoDSToStep_MakeStepVertex MkVertex;
126 // TopoDS_Wire ForwardWire = TopoDS::Wire(aWire.Oriented(TopAbs_FORWARD));
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);
134 TopExp::Vertices(CurrentEdge, TopoDSVertex2, TopoDSVertex1);
136 MkVertex.Init(TopoDSVertex1, aTool, FP);
137 if (MkVertex.IsDone()) {
138 VertexPoint = Handle(StepShape_VertexPoint)::DownCast(MkVertex.Value());
139 Point = VertexPoint->VertexGeometry();
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;
151 Standard_Integer nbPoints = mySeq.Length();
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)));
159 Handle(StepShape_PolyLoop) PL = new StepShape_PolyLoop();
160 Handle(TCollection_HAsciiString) aName =
161 new TCollection_HAsciiString("");
162 PL->Init(aName, aPolygon);
164 aTool.Bind(aWire, PL);
165 myError = TopoDSToStep_WireDone;
166 done = Standard_True;
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;
186 Handle(StepShape_TopologicalRepresentationItem) Gpms;
187 Handle(StepShape_Edge) Epms;
188 Handle(StepShape_OrientedEdge) OrientedEdge;
190 TopoDSToStep_MakeStepEdge MkEdge;
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
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
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);
209 Handle(ShapeExtend_WireData) sbwd = STW->WireData();
210 Standard_Integer nb = sbwd->NbEdges();
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;
217 for (ie = 1; ie <=nb; ie++) {
218 TopoDS_Edge edge = sbwd->Edge(ie);
219 if (!BRep_Tool::Degenerated(edge))
225 for ( ie = 1; ie < nb; ie++) {
226 if ( cwd->Edge(ie).IsSame(cwd->Edge(ie+1)) ) break;
230 for ( ie=nb/2+1; ie <= nb; ie++ ) {
231 if ( ! cwd->Edge(ie).IsSame(cwd->Edge(nb-ie+1)) ) break;
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;
248 nb = sbwd->NbEdges();
250 for (Standard_Integer nEdge = 1; nEdge <= sbwd->NbEdges(); nEdge++) {
252 CurrentEdge = sbwd->Edge(nEdge);
253 //#11 CurrentEdge = ItW.Current();
255 //if (ItW.Current().Orientation() != ItW.Orientation())
256 //cout << "DEBUG : Attention WireExplorer Orientation" << endl;
258 // ---------------------------------
259 // --- Is the edge Degenerated ? ---
260 // ---------------------------------
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");
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");
282 //szv#4:S4163:12Mar99 SGI warns
283 //TopoDS_Shape ssh = CurrentEdge.Oriented(TopAbs_FORWARD);
284 //const TopoDS_Edge ForwardEdge = TopoDS::Edge(ssh);
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);
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;
304 Standard_Integer nbEdges = mySeq.Length();
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)));
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;
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;
332 // ----------------------------------------------------------------------------
335 // ----------------------------------------------------------------------------
337 const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepWire::Value() const
339 StdFail_NotDone_Raise_if(!done,"");
343 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
348 TopoDSToStep_MakeWireError TopoDSToStep_MakeStepWire::Error() const