0022627: Change OCCT memory management defaults
[occt.git] / src / IGESToBRep / IGESToBRep_IGESBoundary.cxx
CommitLineData
7fd59977 1// File: IGESToBRep_IGESBoundary.cxx
2// Created: Wed Dec 16 17:00:20 1998
3// Author: Roman LYGIN
4// <rln@kinox.nnov.matra-dtv.fr>
5
6#include <IGESToBRep_IGESBoundary.ixx>
7#include <TColStd_HSequenceOfTransient.hxx>
8#include <Geom2d_Curve.hxx>
9#include <Geom_Curve.hxx>
10#include <Geom_Plane.hxx>
11#include <GeomAdaptor_Curve.hxx>
12#include <Precision.hxx>
13#include <TopoDS_Edge.hxx>
14#include <TopoDS_Wire.hxx>
15#include <BRep_Builder.hxx>
16#include <BRep_Tool.hxx>
17#include <ShapeBuild_Edge.hxx>
18#include <IGESToBRep.hxx>
19#include <IGESToBRep_TopoCurve.hxx>
1c433dd8 20#include <ShapeFix_Wire.hxx>
7fd59977 21
22//=======================================================================
23//function : IGESToBRep_IGESBoundary
24//purpose :
25//=======================================================================
26
27IGESToBRep_IGESBoundary::IGESToBRep_IGESBoundary()
28{
29}
30
31//=======================================================================
32//function : IGESToBRep_IGESBoundary
33//purpose :
34//=======================================================================
35
36IGESToBRep_IGESBoundary::IGESToBRep_IGESBoundary(const IGESToBRep_CurveAndSurface& CS)
37 : myCS (CS)
38{
39}
40
41//=======================================================================
42//function : Init
43//purpose :
44//=======================================================================
45
46 void IGESToBRep_IGESBoundary::Init(const IGESToBRep_CurveAndSurface& CS,
47 const Handle(IGESData_IGESEntity)& entity,
48 const TopoDS_Face& face,
49 const gp_Trsf2d& trans,
50 const Standard_Real uFact,
51 const Standard_Integer filepreference)
52{
53 myCS = CS;
54 myentity = entity;
55 myface = face;
56 mytrsf = trans;
57 myuFact = uFact;
58 myfilepreference = filepreference;
59}
60
61//=======================================================================
62//function : Transfer
63//purpose :
64//=======================================================================
65
66 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean& okCurve,
67 Standard_Boolean& okCurve3d,
68 Standard_Boolean& okCurve2d,
69 const Handle(IGESData_IGESEntity)& curve3d,
70 const Standard_Boolean toreverse3d,
71 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
72 const Standard_Integer number)
73{
74 Handle(ShapeExtend_WireData) scurve3d, lsewd; //temporary objects
75 return Transfer (okCurve, okCurve3d, okCurve2d,
76 curve3d, scurve3d, Standard_False, toreverse3d,
77 curves2d, Standard_False,
78 number, lsewd);
79}
80
81//=======================================================================
82//function : Transfer
83//purpose :
84//=======================================================================
85
86 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean& okCurve,
87 Standard_Boolean& okCurve3d,
88 Standard_Boolean& okCurve2d,
89 const Handle(ShapeExtend_WireData)& curve3d,
90 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
91 const Standard_Boolean toreverse2d,
92 const Standard_Integer number,
93 Handle(ShapeExtend_WireData)& lsewd)
94{
95 Handle(IGESData_IGESEntity) icurve3d; //temporary object
96 return Transfer (okCurve, okCurve3d, okCurve2d,
97 icurve3d, curve3d, Standard_True, Standard_False,
98 curves2d, toreverse2d,
99 number, lsewd);
100}
101
102//=======================================================================
103//function : Check
104//purpose :
105//=======================================================================
106
107 void IGESToBRep_IGESBoundary::Check(const Standard_Boolean,const Standard_Boolean,const Standard_Boolean,const Standard_Boolean)
108{
109 // Implemented in Advanced Data Exchange
110}
111
112//=======================================================================
113//function : Transfer
114//purpose :
115//=======================================================================
116
117 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean&,
118 Standard_Boolean&,
119 Standard_Boolean&,
120 const Handle(IGESData_IGESEntity)& icurve3d,
121 const Handle(ShapeExtend_WireData)& scurve3d,
122 const Standard_Boolean usescurve,
123 const Standard_Boolean toreverse3d,
124 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
125 const Standard_Boolean toreverse2d,
126 const Standard_Integer number,
127 Handle(ShapeExtend_WireData)& Gsewd)
128{
129 Gsewd = new ShapeExtend_WireData;//local translation (for mysewd)
130 Handle(ShapeExtend_WireData) Gsewd3d = new ShapeExtend_WireData;//local translation (for mysewd3d)
131 Handle(ShapeExtend_WireData) Gsewd2d = new ShapeExtend_WireData;//local translation (for mysewd2d)
132
133 Standard_Boolean GTranslate3d = Standard_True, GTranslate2d = Standard_True,
134 Preferred3d = Standard_True, Preferred2d = Standard_True;
135
136 Standard_Integer len3d = 0, len2d = 0;
137 Handle(TColStd_HSequenceOfTransient) seq3d, seq2d;
138 if (usescurve)
139 len3d = scurve3d->NbEdges();
140 else {
141 IGESToBRep::IGESCurveToSequenceOfIGESCurve (icurve3d, seq3d);
142 len3d = seq3d->Length();
143 }
144 if (!curves2d.IsNull()) {
145 for (Standard_Integer i = 1; i <= curves2d->Length(); i++)
146 IGESToBRep::IGESCurveToSequenceOfIGESCurve (curves2d->Value (i), seq2d);
147 len2d = seq2d->Length();
148 }
149
150 if (len3d == 0)
151 GTranslate3d = Standard_False;
152 else if (len2d == 0)
153 GTranslate2d = Standard_False;
154
155 if (GTranslate3d && GTranslate2d)
156 //Setting preference in the case of inconsitency between 3D and 2D
157 if (myfilepreference == 2) Preferred3d = Standard_False;
158 else if (myfilepreference == 3) Preferred2d = Standard_False;
159 else Preferred3d = Standard_False;
160
161 if (GTranslate3d && GTranslate2d && len3d != len2d) {
162 GTranslate3d = Preferred3d;
163 GTranslate2d = Preferred2d;
164 }
165
166 IGESToBRep_TopoCurve TC (myCS);
167
168 if (GTranslate3d && !GTranslate2d) {
169 if (usescurve)
170 Gsewd->Add (scurve3d->Wire());
171 else {
172 TopoDS_Shape Sh = TC.TransferTopoCurve (icurve3d);
173 if (!Sh.IsNull()) {
174 Gsewd3d->Add (Sh);
175 if (toreverse3d) {
176 ReverseCurves3d (Gsewd3d);
177 Gsewd->Add (Gsewd3d->Wire());
178 }
179 else Gsewd->Add (Sh);//Gsewd = Gsewd3d is impossible to avoid sharing of sewd (UK1.igs entity 7)
180 }
181 }
182 }
183 else if (!GTranslate3d && GTranslate2d) {
184 for (Standard_Integer i = curves2d->Lower(); i <= curves2d->Upper(); i++) {
185 TopoDS_Shape Sh = TC.Transfer2dTopoCurve (Handle(IGESData_IGESEntity)::DownCast (curves2d->Value (i)),
186 myface, mytrsf, myuFact);
187 if (!Sh.IsNull()) Gsewd2d->Add (Sh);
188 }
189 if (toreverse2d)
190 ReverseCurves2d (Gsewd2d, myface);
191 Gsewd->Add (Gsewd2d->Wire());
192 }
193 else if (GTranslate3d && GTranslate2d) {
194 //Translate both curves 3D and 2D
195 //Suppose that i-th segment in 2D curve corresponds to i-th segment in 3D curve
196 for (Standard_Integer i = 1; i <= len3d; i++) {
197 Standard_Boolean LTranslate3d = Standard_True, LTranslate2d = Standard_True;
198
199 Handle(ShapeExtend_WireData) Lsewd3d = new ShapeExtend_WireData;
200 TC.SetBadCase (Standard_False); //:27
201 if (usescurve)
202 Lsewd3d->Add (scurve3d->Edge (i));
203 else {
204 TopoDS_Shape shape3d = TC.TransferTopoCurve (Handle(IGESData_IGESEntity)::DownCast (seq3d->Value (i)));
205 if (!shape3d.IsNull()) {
206 Lsewd3d->Add (shape3d);
207 if (toreverse3d)
208 ReverseCurves3d (Lsewd3d);
209 }
210 else LTranslate3d = Standard_False;
211 }
212 Gsewd3d->Add (Lsewd3d->Wire());
213
214 Handle(ShapeExtend_WireData) Lsewd2d = new ShapeExtend_WireData;
215 TopoDS_Shape shape2d = TC.Transfer2dTopoCurve (Handle(IGESData_IGESEntity)::DownCast (seq2d->Value (i)),
216 myface, mytrsf, myuFact);
217 if (!shape2d.IsNull()) {
218 Lsewd2d->Add (shape2d);
219 if (toreverse2d)
220 ReverseCurves2d (Lsewd2d, myface);
221 Gsewd2d->Add (Lsewd2d->Wire());
222 }
223 else LTranslate2d = Standard_False;
224
225 if (LTranslate3d && LTranslate2d && Lsewd3d->NbEdges() != Lsewd2d->NbEdges()) {
226 LTranslate3d = Preferred3d;
227 LTranslate2d = Preferred2d;
228 }
229 Handle(ShapeExtend_WireData) Lsewd;//Lsewd3d or Lsewd2d or Lsewd3d+pcurve
230 if ( LTranslate3d && !LTranslate2d) Lsewd = Lsewd3d;
231 else if (!LTranslate3d && LTranslate2d) Lsewd = Lsewd2d;
232 else {
233 Lsewd = Lsewd3d;
234 //copying pcurve to edge with 3D curve
235 for (Standard_Integer iedge = 1; iedge <= Lsewd3d->NbEdges(); iedge++) {
236 TopoDS_Edge edge3d = Lsewd3d->Edge (iedge), edge2d = Lsewd2d->Edge (iedge);
237 if (!IGESToBRep::TransferPCurve (edge2d, edge3d, myface)) continue;
238 }
239 }
240 Gsewd->Add (Lsewd->Wire());
241 }
242 }
243
244 if (number > 1) {
245 mysewd ->Add (Gsewd ->Wire());
246 mysewd3d->Add (Gsewd3d->Wire());
247 mysewd2d->Add (Gsewd2d->Wire());
248 }
249 else {
250 mysewd = Gsewd;
251 mysewd3d = Gsewd3d;
252 mysewd2d = Gsewd2d;
253 }
254 return Standard_True;
255}
256
257//=======================================================================
258//function : ReverseCurves3d
259//purpose : Reverses 3D curves of the edges in the wire and reverses
260// the order of edges in the wire.
261// Orientation of each edge is not changed
262//=======================================================================
263
1c433dd8 264void IGESToBRep_IGESBoundary::ReverseCurves3d (const Handle(ShapeExtend_WireData)& sewd)
7fd59977 265{
266 sewd->Reverse();
1c433dd8
S
267 BRep_Builder B;
268 TopoDS_Wire W;
269 B.MakeWire(W);
7fd59977 270 for (Standard_Integer i = 1; i <= sewd->NbEdges(); i++) {
271 TopoDS_Edge oldedge = sewd->Edge (i), newedge;
272 TopLoc_Location L;
273 Standard_Real p1, p2;
274 Handle(Geom_Curve) curve = BRep_Tool::Curve (oldedge, L, p1, p2);
275 if (curve->IsPeriodic()) //#21
276 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), L,
277 curve->ReversedParameter (p2),
278 curve->ReversedParameter (p1));
279 else ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), L,
280 Max (curve->ReversedParameter(curve->LastParameter()), curve->ReversedParameter (p2)),
281 Min (curve->ReversedParameter(curve->FirstParameter()), curve->ReversedParameter (p1)));
282 newedge.Orientation(TopAbs::Reverse (oldedge.Orientation()));
1c433dd8
S
283 //sewd->Set (newedge, i);
284 B.Add(W,newedge);
7fd59977 285 }
1c433dd8
S
286 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire();
287 sfw->Load(W);
288 sfw->FixConnected();
289 sewd->Init(sfw->Wire());
7fd59977 290}
291
292//=======================================================================
293//function : ReverseCurves2d
294//purpose : Reverses pcurves of the edges in the wire and reverses
295// the order of edges in the wire.
296// Orientation of each edge is also changed
297//=======================================================================
298
299 void IGESToBRep_IGESBoundary::ReverseCurves2d (const Handle(ShapeExtend_WireData)& sewd, const TopoDS_Face& face)
300{
301 sewd->Reverse(face);
302 for (Standard_Integer i = 1; i <= sewd->NbEdges(); i++) {
303 TopoDS_Edge oldedge = sewd->Edge (i), newedge;
304 Standard_Real p1, p2;
305 Handle(Geom2d_Curve) curve = BRep_Tool::CurveOnSurface (oldedge, face, p1, p2);
306
307 // skl 24.04.2002 for OCC314
308 if(curve->IsPeriodic())
309 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), face,
310 curve->ReversedParameter (p2),
311 curve->ReversedParameter (p1));
312 else
313 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), face,
314 Max (curve->FirstParameter(), curve->ReversedParameter (p2)),//BUC50001 entity 936 2DForced
315 Min (curve->LastParameter(), curve->ReversedParameter (p1)));
316 newedge.Orientation(oldedge.Orientation());
317 sewd->Set (newedge, i);
318 }
319}
320