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