0024077: Build errors on master branch on Mac OS X
[occt.git] / src / StepToTopoDS / StepToTopoDS_TranslateCompositeCurve.cxx
CommitLineData
b311480e 1// Created on: 1999-02-12
2// Created by: Andrey BETENEV
3// Copyright (c) 1999-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21//:o3 abv 17.02.99: r0301_db.stp #57082: apply FixReorder to composite curve
22//:s5 abv 22.04.99 Adding debug printouts in catch {} blocks
23
24#include <StepToTopoDS_TranslateCompositeCurve.ixx>
25#include <Standard_ErrorHandler.hxx>
26#include <Standard_Failure.hxx>
27#include <Interface_Static.hxx>
28#include <Precision.hxx>
29
30#include <Geom_Curve.hxx>
31#include <Geom2d_Curve.hxx>
32#include <StepGeom_Pcurve.hxx>
33#include <StepGeom_SurfaceCurve.hxx>
34#include <StepGeom_PcurveOrSurface.hxx>
35#include <StepGeom_CompositeCurveSegment.hxx>
36#include <StepToGeom_MakeCurve.hxx>
37#include <StepToTopoDS_TranslateEdge.hxx>
38
39#include <BRepBuilderAPI_MakeEdge.hxx>
40#include <BRep_Builder.hxx>
41
42#include <TopoDS.hxx>
43#include <TopoDS_Edge.hxx>
44#include <TopoDS_Iterator.hxx>
45
46#include <ShapeExtend_WireData.hxx>
47#include <ShapeFix_Wire.hxx>
48
49//=======================================================================
50//function : Create
51//purpose :
52//=======================================================================
53
54StepToTopoDS_TranslateCompositeCurve::StepToTopoDS_TranslateCompositeCurve () {}
55
56//=======================================================================
57//function : Create
58//purpose :
59//=======================================================================
60
61StepToTopoDS_TranslateCompositeCurve::StepToTopoDS_TranslateCompositeCurve (
62 const Handle(StepGeom_CompositeCurve) &CC,
63 const Handle(Transfer_TransientProcess) &TP)
64{
65 Init ( CC, TP );
66}
67
68//=======================================================================
69//function : Create
70//purpose :
71//=======================================================================
72
73StepToTopoDS_TranslateCompositeCurve::StepToTopoDS_TranslateCompositeCurve (
74 const Handle(StepGeom_CompositeCurve) &CC,
75 const Handle(Transfer_TransientProcess) &TP,
76 const Handle(StepGeom_Surface) &S,
77 const Handle(Geom_Surface) &Surf)
78{
79 Init ( CC, TP, S, Surf );
80}
81
82//=======================================================================
83//function : Init
84//purpose :
85//=======================================================================
86
87Standard_Boolean StepToTopoDS_TranslateCompositeCurve::Init (const Handle(StepGeom_CompositeCurve) &CC,
88 const Handle(Transfer_TransientProcess) &TP)
89{
90 Handle(StepGeom_Surface) S;
91 Handle(Geom_Surface) Surf;
92 return Init ( CC, TP, S, Surf );
93}
94
95//=======================================================================
96//function : Init
97//purpose :
98//=======================================================================
99
100Standard_Boolean StepToTopoDS_TranslateCompositeCurve::Init (const Handle(StepGeom_CompositeCurve) &CC,
101 const Handle(Transfer_TransientProcess) &TP,
102 const Handle(StepGeom_Surface) &S,
103 const Handle(Geom_Surface) &Surf)
104{
105 myWire.Nullify();
42e4630c 106 myInfiniteSegment = Standard_False;
7fd59977 107 if ( CC.IsNull() ) return Standard_False;
108
109 Standard_Boolean SurfMode = ( ! S.IsNull() && ! Surf.IsNull() );
110 Standard_Boolean isClosed = Standard_False;
111
112 if ( SurfMode ) {
113 Standard_Integer modepcurve = Interface_Static::IVal("read.surfacecurve.mode");
114 if ( modepcurve ==-3 ) SurfMode = Standard_False;
115 }
116
117 Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData;
118 Standard_Integer nbs = CC->NbSegments();
119 for ( Standard_Integer i=1; i <= nbs; i++ ) {
120 Handle(StepGeom_CompositeCurveSegment) ccs = CC->SegmentsValue ( i );
121 if ( ccs.IsNull() ) {
122 TP->AddFail ( CC, "Null segment" );
123 return Standard_False;
124 }
125 Handle(StepGeom_Curve) crv = ccs->ParentCurve();
126 if ( crv.IsNull() ) {
127 TP->AddFail ( CC, "Segment has null parent curve" );
128 return Standard_False;
129 }
130 isClosed = ( ccs->Transition() != StepGeom_tcDiscontinuous );
131
132 // if segment is itself a composite_curve, translate recursively
133 if ( crv->IsKind(STANDARD_TYPE(StepGeom_CompositeCurve)) ) {
134 if ( crv == CC ) { // cyclic reference protection
135 TP->AddFail (ccs, "Cyclic reference; segment dropped" );
136 continue;
137 }
138 Handle(StepGeom_CompositeCurve) cc = Handle(StepGeom_CompositeCurve)::DownCast ( crv );
139 if ( ! Init ( cc, TP, S, Surf ) || myWire.IsNull() ) continue;
140 Standard_Integer nb = sbwd->NbEdges() + 1;
141 for ( TopoDS_Iterator it ( myWire ); it.More(); it.Next() ) {
142 TopoDS_Edge edge = TopoDS::Edge ( it.Value() );
143 if ( ccs->SameSense() ) sbwd->Add ( edge );
144 else {
145 edge.Reverse();
146 sbwd->Add ( edge, nb > sbwd->NbEdges() ? 0 : nb );
147 }
148 }
149 myWire.Nullify();
150 continue;
151 }
152
153 // ordinary segment
154
155 // detect pcurve and 3d curve
156 Handle(StepGeom_Pcurve) pcurve = Handle(StepGeom_Pcurve)::DownCast ( crv );
157 if ( pcurve.IsNull() ) {
158 Handle(StepGeom_SurfaceCurve) sc = Handle(StepGeom_SurfaceCurve)::DownCast ( crv );
159 if ( ! sc.IsNull() ) {
160 crv = sc->Curve3d();
161 if ( SurfMode ) { // find proper pcurve
162 for ( Standard_Integer j=1; j <= sc->NbAssociatedGeometry(); j++ ) {
163 StepGeom_PcurveOrSurface PCorS = sc->AssociatedGeometryValue ( j );
164 Handle(StepGeom_Pcurve) pc = PCorS.Pcurve();
165 if ( pc.IsNull() || pc->BasisSurface() != S ) continue;
166 pcurve = pc;
167 if ( ccs->SameSense() ) break;
168 }
169 }
170 }
171 }
172 else {
173 if ( ! SurfMode || pcurve->BasisSurface() != S ) pcurve.Nullify();
174 crv.Nullify();
175 }
176
177 // prepare edge
178 TopoDS_Edge edge;
179
180 // translate 3d curve, if present
181 if ( ! crv.IsNull() ) {
182 try {
183 OCC_CATCH_SIGNALS
184 Handle(Geom_Curve) c3d;
185 if (StepToGeom_MakeCurve::Convert(crv,c3d)) {
186 BRepBuilderAPI_MakeEdge MkEdge ( c3d, c3d->FirstParameter(), c3d->LastParameter() );
42e4630c 187 if (MkEdge.IsDone())
188 {
189 if (Precision::IsNegativeInfinite (c3d->FirstParameter()) || Precision::IsPositiveInfinite (c3d->LastParameter()))
190 {
191 myInfiniteSegment = Standard_True;
192 TP->AddWarning (CC, "Segment with infinite parameters");
193 }
194 edge = MkEdge.Edge();
195 }
7fd59977 196 }
197 }
198 catch(Standard_Failure) {
199#ifdef DEB
200 cout << "Warning: StepToTopoDS_TranslateCompositeCurve: Exception: ";
201 Standard_Failure::Caught()->Print(cout); cout << endl;
202#endif
203 }
204 }
205
206 // translate pcurve, if available
207 if ( ! pcurve.IsNull() ) {
208 try {
209 OCC_CATCH_SIGNALS
210 StepToTopoDS_TranslateEdge TrE;
211 Handle(Geom2d_Curve) c2d = TrE.MakePCurve ( pcurve, Surf );
212 if ( ! c2d.IsNull() ) {
213 if ( edge.IsNull() ) {
214 BRepBuilderAPI_MakeEdge MkEdge ( c2d, Surf, c2d->FirstParameter(), c2d->LastParameter() );
42e4630c 215 if (MkEdge.IsDone())
216 {
217 if (Precision::IsNegativeInfinite (c2d->FirstParameter()) || Precision::IsPositiveInfinite (c2d->LastParameter()))
218 {
219 myInfiniteSegment = Standard_True;
220 TP->AddWarning (CC, "Segment with infinite parameters");
221 }
222 edge = MkEdge.Edge();
223 }
7fd59977 224 }
225 else {
226 BRep_Builder B;
227 TopLoc_Location L;
228 B.UpdateEdge ( edge, c2d, Surf, L, 0. );
229 B.Range ( edge, Surf, L, c2d->FirstParameter(), c2d->LastParameter() );
230 B.SameRange ( edge, Standard_False );
231 B.SameParameter ( edge, Standard_False );
232 }
233 }
234 }
235 catch(Standard_Failure) {
236#ifdef DEB
237 cout << "Warning: StepToTopoDS_TranslateCompositeCurve: Exception: ";
238 Standard_Failure::Caught()->Print(cout); cout << endl;
239#endif
240 }
241 }
242
243 if ( edge.IsNull() ) {
244 TP->AddFail ( crv, "Curve can not be translated");
245 continue;
246 }
247
248 if ( ! ccs->SameSense() ) edge.Reverse();
249 sbwd->Add ( edge );
250 }
251 if ( sbwd->NbEdges() <=0 ) {
252 TP->AddFail ( CC, "Translation gives no result" );
253 return Standard_False;
254 }
255
256 // connect wire; all other fixes are left for caller
257 Standard_Real preci = Precision();
258 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
259 sfw->Load ( sbwd );
260 sfw->SetPrecision ( preci );
261 sfw->ClosedWireMode() = isClosed;
262 sfw->FixReorder(); //:o3 abv 17 Feb 99: r0301_db.stp #57082
263 if ( sfw->StatusReorder ( ShapeExtend_DONE ) ) {
264 TP->AddWarning ( CC, "Segments were disordered; fixed" );
265 }
266 sfw->FixConnected ( preci );
267 if ( sfw->StatusConnected ( ShapeExtend_FAIL ) ) {
268 TP->AddWarning ( CC, "Segments are not connected" );
269 }
270
271 myWire = sbwd->Wire();
272 done = ( sbwd->NbEdges() >0 );
273 return Standard_True;
274}
275
276//=======================================================================
277//function : Value
278//purpose : return resulting wire
279//=======================================================================
280
281const TopoDS_Wire& StepToTopoDS_TranslateCompositeCurve::Value () const
282{
283 return myWire;
284}