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