Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeStepEdge.cxx
CommitLineData
7fd59977 1// File: TopoDSToStep_MakeStepEdge.cxx
2// Created: Wed Nov 30 14:25:33 1994
3// Author: Frederic MAUPAS
4// <fma@bibox>
5
6#include <TopoDSToStep_MakeStepEdge.ixx>
7
8#include <TopoDSToStep_MakeStepVertex.hxx>
9
10#include <Geom_Line.hxx>
11#include <Geom_Curve.hxx>
12#include <Geom_Surface.hxx>
13#include <Geom_Plane.hxx>
14#include <Geom_BSplineCurve.hxx>
15
16#include <Geom2d_Curve.hxx>
17#include <Geom2d_Line.hxx>
18#include <gp_Vec.hxx>
19
20#include <BRepLib.hxx>
21#include <BRep_Tool.hxx>
22#include <TopoDS_Iterator.hxx>
23#include <TopoDS.hxx>
24#include <BRepAdaptor_Curve.hxx>
25#include <BRepAdaptor_Surface.hxx>
26
27#include <StepShape_Vertex.hxx>
28#include <StepShape_EdgeCurve.hxx>
29#include <StepGeom_Curve.hxx>
30#include <StepGeom_HArray1OfPcurveOrSurface.hxx>
31#include <StepGeom_SeamCurve.hxx>
32#include <StepGeom_SurfaceCurve.hxx>
33
34#include <GeomToStep_MakeCurve.hxx>
35#include <GeomToStep_MakeLine.hxx>
36
37#include <Adaptor3d_CurveOnSurface.hxx>
38
39#include <TColgp_Array1OfPnt.hxx>
40#include <TColgp_Array1OfPnt.hxx>
41#include <TColStd_Array1OfReal.hxx>
42#include <TColStd_Array1OfInteger.hxx>
43
44#include <TopExp_Explorer.hxx>
45#include <TopExp.hxx>
46#include <TransferBRep_ShapeMapper.hxx>
47#include <TCollection_HAsciiString.hxx>
48
49// Processing of non-manifold topology (ssv; 11.11.2010)
50#include <TransferBRep.hxx>
51#include <Interface_Static.hxx>
52
53// ----------------------------------------------------------------------------
54// Constructors
55// ----------------------------------------------------------------------------
56
57TopoDSToStep_MakeStepEdge::TopoDSToStep_MakeStepEdge()
58{
59 done = Standard_False;
60}
61
62TopoDSToStep_MakeStepEdge::TopoDSToStep_MakeStepEdge
63(const TopoDS_Edge& E,
64 TopoDSToStep_Tool& T,
65 const Handle(Transfer_FinderProcess)& FP)
66{
67 done = Standard_False;
68 Init(E, T, FP);
69}
70
71// ----------------------------------------------------------------------------
72// Method : Init
73// Purpose :
74// ----------------------------------------------------------------------------
75
76void TopoDSToStep_MakeStepEdge::Init(const TopoDS_Edge& aEdge,
77 TopoDSToStep_Tool& aTool,
78 const Handle(Transfer_FinderProcess)& FP)
79{
80 // ------------------------------------------------------------------
81 // The edge is given with its relative orientation (i.e. in the wire)
82 // ------------------------------------------------------------------
83
84 aTool.SetCurrentEdge(aEdge);
85
86 // [BEGIN] Processing non-manifold topology (ssv; 11.11.2010)
87 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
88 if (isNMMode) {
89 Handle(StepShape_EdgeCurve) anEC;
90 Handle(TransferBRep_ShapeMapper) aSTEPMapper = TransferBRep::ShapeMapper(FP, aEdge);
91 if ( FP->FindTypedTransient(aSTEPMapper, STANDARD_TYPE(StepShape_EdgeCurve), anEC) ) {
92 // Non-manifold topology detected
93 myError = TopoDSToStep_EdgeDone;
94 myResult = anEC;
95 done = Standard_True;
96 return;
97 }
98 }
99 // [END] Processing non-manifold topology (ssv; 11.11.2010)
100
101 if (aTool.IsBound(aEdge)) {
102 myError = TopoDSToStep_EdgeDone;
103 done = Standard_True;
104 myResult = aTool.Find(aEdge);
105 return;
106 }
107
108#define Nbpt 21
109 TopoDS_Iterator It;
110 Standard_Integer i;
111 Standard_Real U, U1, U2;
112 gp_Pnt P;
113
114 Standard_Boolean isSeam = BRep_Tool::IsClosed(aEdge, aTool.CurrentFace());
115
116 //:i4 abv 02 Sep 98: ProSTEP TR8 Motor.rle f3 & f62: check that edge
117 // participates twice in the wires of the face before making it seam
118 // (else it can have two pcurves on the same surface being shared by
119 // two faces on that surface)
120 // This fix is necessary because sharing of surfaces is not preserved when
121 // writing faces to STEP (see TopoDSToSTEP_MakeStepFace)
122 if ( isSeam ) {
123 Standard_Integer count = 0;
124 TopExp_Explorer exp ( aTool.CurrentFace(), TopAbs_EDGE );
125 for ( ; exp.More(); exp.Next() )
126 if ( aEdge.IsSame ( exp.Current() ) ) count++;
127 if ( count < 2 ) isSeam = Standard_False;
128 }
129
130 BRepAdaptor_Curve CA = BRepAdaptor_Curve(aEdge);
131 BRepAdaptor_Surface SA = BRepAdaptor_Surface(aTool.CurrentFace());
132
133 if (aEdge.Orientation() == TopAbs_INTERNAL ||
134 aEdge.Orientation() == TopAbs_EXTERNAL ) {
135 Handle(TransferBRep_ShapeMapper) errShape =
136 new TransferBRep_ShapeMapper(aEdge);
137 FP->AddWarning(errShape, " Edge(internal/external) from Non Manifold Topology");
138 myError = TopoDSToStep_NonManifoldEdge;
139 done = Standard_False;
140 return;
141 }
142
143 // Vertices
144
145 Handle(StepShape_Vertex) V1,V2;
146 Handle(StepShape_TopologicalRepresentationItem) Gpms2;
147 TopoDS_Vertex Vfirst, Vlast;
148
149 TopExp::Vertices(aEdge,Vfirst, Vlast);
150
151 TopoDSToStep_MakeStepVertex MkVertex;
152
153 MkVertex.Init(Vfirst, aTool, FP);
154 if (MkVertex.IsDone())
155 V1 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
156 else {
157 Handle(TransferBRep_ShapeMapper) errShape =
158 new TransferBRep_ShapeMapper(aEdge);
159 FP->AddWarning(errShape, " First Vertex of Edge not mapped");
160 myError = TopoDSToStep_EdgeOther;
161 done = Standard_False;
162 return;
163 }
164
165 MkVertex.Init(Vlast, aTool, FP);
166 if (MkVertex.IsDone())
167 V2 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
168 else {
169 Handle(TransferBRep_ShapeMapper) errShape =
170 new TransferBRep_ShapeMapper(aEdge);
171 FP->AddWarning(errShape, " Last Vertex of Edge not mapped");
172 myError = TopoDSToStep_EdgeOther;
173 done = Standard_False;
174 return;
175 }
176
177 // ---------------------------------------
178 // Translate 3D representation of the Edge
179 // ---------------------------------------
180
181 Handle(StepGeom_Curve) Gpms;
182 Handle(Geom_Curve) C = CA.Curve().Curve();
183 if (!C.IsNull()) {
184 C = Handle(Geom_Curve)::DownCast(C->Copy());
185 gp_Trsf Tr1 = CA.Trsf();
186 C->Transform(Tr1);
187 GeomToStep_MakeCurve MkCurve(C);
188 Gpms = MkCurve.Value();
189 }
190 else {
191
192 // -------------------------
193 // a 3D Curve is constructed
194 // -------------------------
195
196#ifdef DEB
197 cout << "Warning: TopoDSToStep_MakeStepEdge: edge without 3d curve; creating..." << endl;
198#endif
199 if ((SA.GetType() == GeomAbs_Plane) &&
200 (CA.GetType() == GeomAbs_Line)) {
201 U1 = CA.FirstParameter();
202 U2 = CA.LastParameter();
203 gp_Vec V = gp_Vec( CA.Value(U1), CA.Value(U2) );
204 Handle(Geom_Line) L =
205 new Geom_Line(CA.Value(U1), gp_Dir(V));
206 GeomToStep_MakeLine MkLine(L);
207 Gpms = MkLine.Value();
208 }
209 else {
210 // To Be Optimized : create an approximated BSpline
211 // using GeomAPI_PointsToBSpline
212 TColgp_Array1OfPnt Points(1,Nbpt);
213 TColStd_Array1OfReal Knots(1,Nbpt);
214 TColStd_Array1OfInteger Mult(1,Nbpt);
215 U1 = CA.FirstParameter();
216 U2 = CA.LastParameter();
217 for ( i=1; i<=Nbpt; i++ ) {
218 U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1);
219 P = CA.Value(U);
220 Points.SetValue(i,P);
221 Knots.SetValue(i,U);
222 Mult.SetValue(i,1);
223 }
224 //Points.SetValue(1, BRep_Tool::Pnt(Vfirst));
225 //Points.SetValue(Nbpt, BRep_Tool::Pnt(Vlast));
226 Mult.SetValue(1,2);
227 Mult.SetValue(Nbpt,2);
228 Handle(Geom_BSplineCurve) Bs =
229 new Geom_BSplineCurve(Points, Knots, Mult, 1);
230 GeomToStep_MakeCurve MkCurve(Bs);
231 Gpms = MkCurve.Value();
232 }
233 }
234
235 // ---------------------------------------------------------
236 // Warning : if the edge is connected aGeom->Length = 2
237 // otherwise = 1 ;
238 // and enumeration is pscrPcurveS2 or pscrPcurveS1
239 // This is corrected in the Write File phases !
240 // ---------------------------------------------------------
241
242 //:abv 25.01.00 CAX-IF TRJ3
243 // if PcurveMode is 1 (default), make surface_curve instead of simple 3d curve
244 if ( aTool.PCurveMode() != 0 ) {
245
246 Handle(StepGeom_HArray1OfPcurveOrSurface) aGeom =
247 new StepGeom_HArray1OfPcurveOrSurface(1,2);
248 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
249
250 if (!isSeam) {
251 Handle(StepGeom_SurfaceCurve) SurfaceCurve = new StepGeom_SurfaceCurve;
252 SurfaceCurve->Init(aName, Gpms, aGeom, StepGeom_pscrPcurveS1);
253 Gpms = SurfaceCurve;
254 }
255 else {
256 Handle(StepGeom_SeamCurve) SeamCurve = new StepGeom_SeamCurve;
257 SeamCurve->Init(aName, Gpms, aGeom, StepGeom_pscrPcurveS1);
258 Gpms = SeamCurve;
259 }
260 }
261
262 // Edge curve
263 Handle(StepShape_EdgeCurve) Epms = new StepShape_EdgeCurve;
264 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
265 Epms->Init(aName, V1, V2, Gpms, Standard_True);
266
267 aTool.Bind(aEdge, Epms);
268 myError = TopoDSToStep_EdgeDone;
269 myResult = Epms;
270 done = Standard_True;
271 return;
272}
273
274// ----------------------------------------------------------------------------
275// Method : Value
276// Purpose :
277// ----------------------------------------------------------------------------
278
279const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepEdge::Value() const
280{
281 StdFail_NotDone_Raise_if(!done,"");
282 return myResult;
283}
284
285// ----------------------------------------------------------------------------
286// Method : Error
287// Purpose :
288// ----------------------------------------------------------------------------
289
290TopoDSToStep_MakeEdgeError TopoDSToStep_MakeStepEdge::Error() const
291{
292 return myError;
293}