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