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.
17 #include <TopoDSToStep_MakeStepEdge.ixx>
19 #include <TopoDSToStep_MakeStepVertex.hxx>
21 #include <Geom_Line.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Surface.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_BSplineCurve.hxx>
27 #include <Geom2d_Curve.hxx>
28 #include <Geom2d_Line.hxx>
31 #include <BRepLib.hxx>
32 #include <BRep_Tool.hxx>
33 #include <TopoDS_Iterator.hxx>
35 #include <BRepAdaptor_Curve.hxx>
36 #include <BRepAdaptor_Surface.hxx>
38 #include <StepShape_Vertex.hxx>
39 #include <StepShape_EdgeCurve.hxx>
40 #include <StepGeom_Curve.hxx>
41 #include <StepGeom_HArray1OfPcurveOrSurface.hxx>
42 #include <StepGeom_SeamCurve.hxx>
43 #include <StepGeom_SurfaceCurve.hxx>
45 #include <GeomToStep_MakeCurve.hxx>
46 #include <GeomToStep_MakeLine.hxx>
48 #include <Adaptor3d_CurveOnSurface.hxx>
50 #include <TColgp_Array1OfPnt.hxx>
51 #include <TColgp_Array1OfPnt.hxx>
52 #include <TColStd_Array1OfReal.hxx>
53 #include <TColStd_Array1OfInteger.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TransferBRep_ShapeMapper.hxx>
58 #include <TCollection_HAsciiString.hxx>
60 // Processing of non-manifold topology (ssv; 11.11.2010)
61 #include <TransferBRep.hxx>
62 #include <Interface_Static.hxx>
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 TopoDSToStep_MakeStepEdge::TopoDSToStep_MakeStepEdge()
70 done = Standard_False;
73 TopoDSToStep_MakeStepEdge::TopoDSToStep_MakeStepEdge
74 (const TopoDS_Edge& E,
76 const Handle(Transfer_FinderProcess)& FP)
78 done = Standard_False;
82 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 void TopoDSToStep_MakeStepEdge::Init(const TopoDS_Edge& aEdge,
88 TopoDSToStep_Tool& aTool,
89 const Handle(Transfer_FinderProcess)& FP)
91 // ------------------------------------------------------------------
92 // The edge is given with its relative orientation (i.e. in the wire)
93 // ------------------------------------------------------------------
95 aTool.SetCurrentEdge(aEdge);
97 // [BEGIN] Processing non-manifold topology (ssv; 11.11.2010)
98 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
100 Handle(StepShape_EdgeCurve) anEC;
101 Handle(TransferBRep_ShapeMapper) aSTEPMapper = TransferBRep::ShapeMapper(FP, aEdge);
102 if ( FP->FindTypedTransient(aSTEPMapper, STANDARD_TYPE(StepShape_EdgeCurve), anEC) ) {
103 // Non-manifold topology detected
104 myError = TopoDSToStep_EdgeDone;
106 done = Standard_True;
110 // [END] Processing non-manifold topology (ssv; 11.11.2010)
112 if (aTool.IsBound(aEdge)) {
113 myError = TopoDSToStep_EdgeDone;
114 done = Standard_True;
115 myResult = aTool.Find(aEdge);
122 Standard_Real U, U1, U2;
125 Standard_Boolean isSeam = BRep_Tool::IsClosed(aEdge, aTool.CurrentFace());
127 //:i4 abv 02 Sep 98: ProSTEP TR8 Motor.rle f3 & f62: check that edge
128 // participates twice in the wires of the face before making it seam
129 // (else it can have two pcurves on the same surface being shared by
130 // two faces on that surface)
131 // This fix is necessary because sharing of surfaces is not preserved when
132 // writing faces to STEP (see TopoDSToSTEP_MakeStepFace)
134 Standard_Integer count = 0;
135 TopExp_Explorer exp ( aTool.CurrentFace(), TopAbs_EDGE );
136 for ( ; exp.More(); exp.Next() )
137 if ( aEdge.IsSame ( exp.Current() ) ) count++;
138 if ( count < 2 ) isSeam = Standard_False;
141 BRepAdaptor_Curve CA = BRepAdaptor_Curve(aEdge);
142 BRepAdaptor_Surface SA = BRepAdaptor_Surface(aTool.CurrentFace());
144 if (aEdge.Orientation() == TopAbs_INTERNAL ||
145 aEdge.Orientation() == TopAbs_EXTERNAL ) {
146 Handle(TransferBRep_ShapeMapper) errShape =
147 new TransferBRep_ShapeMapper(aEdge);
148 FP->AddWarning(errShape, " Edge(internal/external) from Non Manifold Topology");
149 myError = TopoDSToStep_NonManifoldEdge;
150 done = Standard_False;
156 Handle(StepShape_Vertex) V1,V2;
157 Handle(StepShape_TopologicalRepresentationItem) Gpms2;
158 TopoDS_Vertex Vfirst, Vlast;
160 TopExp::Vertices(aEdge,Vfirst, Vlast);
162 TopoDSToStep_MakeStepVertex MkVertex;
164 MkVertex.Init(Vfirst, aTool, FP);
165 if (MkVertex.IsDone())
166 V1 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
168 Handle(TransferBRep_ShapeMapper) errShape =
169 new TransferBRep_ShapeMapper(aEdge);
170 FP->AddWarning(errShape, " First Vertex of Edge not mapped");
171 myError = TopoDSToStep_EdgeOther;
172 done = Standard_False;
176 MkVertex.Init(Vlast, aTool, FP);
177 if (MkVertex.IsDone())
178 V2 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
180 Handle(TransferBRep_ShapeMapper) errShape =
181 new TransferBRep_ShapeMapper(aEdge);
182 FP->AddWarning(errShape, " Last Vertex of Edge not mapped");
183 myError = TopoDSToStep_EdgeOther;
184 done = Standard_False;
188 // ---------------------------------------
189 // Translate 3D representation of the Edge
190 // ---------------------------------------
192 Handle(StepGeom_Curve) Gpms;
193 Handle(Geom_Curve) C = CA.Curve().Curve();
195 C = Handle(Geom_Curve)::DownCast(C->Copy());
196 gp_Trsf Tr1 = CA.Trsf();
198 GeomToStep_MakeCurve MkCurve(C);
199 Gpms = MkCurve.Value();
203 // -------------------------
204 // a 3D Curve is constructed
205 // -------------------------
208 cout << "Warning: TopoDSToStep_MakeStepEdge: edge without 3d curve; creating..." << endl;
210 if ((SA.GetType() == GeomAbs_Plane) &&
211 (CA.GetType() == GeomAbs_Line)) {
212 U1 = CA.FirstParameter();
213 U2 = CA.LastParameter();
214 gp_Vec V = gp_Vec( CA.Value(U1), CA.Value(U2) );
215 Handle(Geom_Line) L =
216 new Geom_Line(CA.Value(U1), gp_Dir(V));
217 GeomToStep_MakeLine MkLine(L);
218 Gpms = MkLine.Value();
221 // To Be Optimized : create an approximated BSpline
222 // using GeomAPI_PointsToBSpline
223 TColgp_Array1OfPnt Points(1,Nbpt);
224 TColStd_Array1OfReal Knots(1,Nbpt);
225 TColStd_Array1OfInteger Mult(1,Nbpt);
226 U1 = CA.FirstParameter();
227 U2 = CA.LastParameter();
228 for ( i=1; i<=Nbpt; i++ ) {
229 U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1);
231 Points.SetValue(i,P);
235 //Points.SetValue(1, BRep_Tool::Pnt(Vfirst));
236 //Points.SetValue(Nbpt, BRep_Tool::Pnt(Vlast));
238 Mult.SetValue(Nbpt,2);
239 Handle(Geom_BSplineCurve) Bs =
240 new Geom_BSplineCurve(Points, Knots, Mult, 1);
241 GeomToStep_MakeCurve MkCurve(Bs);
242 Gpms = MkCurve.Value();
246 // ---------------------------------------------------------
247 // Warning : if the edge is connected aGeom->Length = 2
249 // and enumeration is pscrPcurveS2 or pscrPcurveS1
250 // This is corrected in the Write File phases !
251 // ---------------------------------------------------------
253 //:abv 25.01.00 CAX-IF TRJ3
254 // if PcurveMode is 1 (default), make surface_curve instead of simple 3d curve
255 if ( aTool.PCurveMode() != 0 ) {
257 Handle(StepGeom_HArray1OfPcurveOrSurface) aGeom =
258 new StepGeom_HArray1OfPcurveOrSurface(1,2);
259 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
262 Handle(StepGeom_SurfaceCurve) SurfaceCurve = new StepGeom_SurfaceCurve;
263 SurfaceCurve->Init(aName, Gpms, aGeom, StepGeom_pscrPcurveS1);
267 Handle(StepGeom_SeamCurve) SeamCurve = new StepGeom_SeamCurve;
268 SeamCurve->Init(aName, Gpms, aGeom, StepGeom_pscrPcurveS1);
274 Handle(StepShape_EdgeCurve) Epms = new StepShape_EdgeCurve;
275 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
276 Epms->Init(aName, V1, V2, Gpms, Standard_True);
278 aTool.Bind(aEdge, Epms);
279 myError = TopoDSToStep_EdgeDone;
281 done = Standard_True;
285 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
290 const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepEdge::Value() const
292 StdFail_NotDone_Raise_if(!done,"");
296 // ----------------------------------------------------------------------------
299 // ----------------------------------------------------------------------------
301 TopoDSToStep_MakeEdgeError TopoDSToStep_MakeStepEdge::Error() const