1 // Created on: 1998-12-16
2 // Created by: Roman LYGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Plane.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <gp_Trsf2d.hxx>
25 #include <IGESData_IGESEntity.hxx>
26 #include <IGESToBRep.hxx>
27 #include <IGESToBRep_CurveAndSurface.hxx>
28 #include <IGESToBRep_IGESBoundary.hxx>
29 #include <IGESToBRep_TopoCurve.hxx>
30 #include <Precision.hxx>
31 #include <ShapeBuild_Edge.hxx>
32 #include <ShapeExtend_WireData.hxx>
33 #include <ShapeFix_Wire.hxx>
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>
40 IMPLEMENT_STANDARD_RTTIEXT(IGESToBRep_IGESBoundary,Standard_Transient)
42 //=======================================================================
43 //function : IGESToBRep_IGESBoundary
45 //=======================================================================
46 IGESToBRep_IGESBoundary::IGESToBRep_IGESBoundary()
50 //=======================================================================
51 //function : IGESToBRep_IGESBoundary
53 //=======================================================================
55 IGESToBRep_IGESBoundary::IGESToBRep_IGESBoundary(const IGESToBRep_CurveAndSurface& CS)
60 //=======================================================================
63 //=======================================================================
65 void IGESToBRep_IGESBoundary::Init(const IGESToBRep_CurveAndSurface& CS,
66 const Handle(IGESData_IGESEntity)& entity,
67 const TopoDS_Face& face,
68 const gp_Trsf2d& trans,
69 const Standard_Real uFact,
70 const Standard_Integer filepreference)
77 myfilepreference = filepreference;
80 //=======================================================================
83 //=======================================================================
85 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean& okCurve,
86 Standard_Boolean& okCurve3d,
87 Standard_Boolean& okCurve2d,
88 const Handle(IGESData_IGESEntity)& curve3d,
89 const Standard_Boolean toreverse3d,
90 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
91 const Standard_Integer number)
93 Handle(ShapeExtend_WireData) scurve3d, lsewd; //temporary objects
94 return Transfer (okCurve, okCurve3d, okCurve2d,
95 curve3d, scurve3d, Standard_False, toreverse3d,
96 curves2d, Standard_False,
100 //=======================================================================
101 //function : Transfer
103 //=======================================================================
105 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean& okCurve,
106 Standard_Boolean& okCurve3d,
107 Standard_Boolean& okCurve2d,
108 const Handle(ShapeExtend_WireData)& curve3d,
109 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
110 const Standard_Boolean toreverse2d,
111 const Standard_Integer number,
112 Handle(ShapeExtend_WireData)& lsewd)
114 Handle(IGESData_IGESEntity) icurve3d; //temporary object
115 return Transfer (okCurve, okCurve3d, okCurve2d,
116 icurve3d, curve3d, Standard_True, Standard_False,
117 curves2d, toreverse2d,
121 //=======================================================================
124 //=======================================================================
126 void IGESToBRep_IGESBoundary::Check(const Standard_Boolean,const Standard_Boolean,const Standard_Boolean,const Standard_Boolean)
128 // Implemented in Advanced Data Exchange
131 //=======================================================================
132 //function : Transfer
134 //=======================================================================
136 Standard_Boolean IGESToBRep_IGESBoundary::Transfer(Standard_Boolean&,
139 const Handle(IGESData_IGESEntity)& icurve3d,
140 const Handle(ShapeExtend_WireData)& scurve3d,
141 const Standard_Boolean usescurve,
142 const Standard_Boolean toreverse3d,
143 const Handle(IGESData_HArray1OfIGESEntity)& curves2d,
144 const Standard_Boolean toreverse2d,
145 const Standard_Integer number,
146 Handle(ShapeExtend_WireData)& Gsewd)
148 Gsewd = new ShapeExtend_WireData;//local translation (for mysewd)
149 Handle(ShapeExtend_WireData) Gsewd3d = new ShapeExtend_WireData;//local translation (for mysewd3d)
150 Handle(ShapeExtend_WireData) Gsewd2d = new ShapeExtend_WireData;//local translation (for mysewd2d)
152 Standard_Boolean GTranslate3d = Standard_True, GTranslate2d = Standard_True,
153 Preferred3d = Standard_True, Preferred2d = Standard_True;
155 Standard_Integer len3d = 0, len2d = 0;
156 Handle(TColStd_HSequenceOfTransient) seq3d, seq2d;
158 len3d = scurve3d->NbEdges();
160 IGESToBRep::IGESCurveToSequenceOfIGESCurve (icurve3d, seq3d);
161 len3d = seq3d->Length();
163 if (!curves2d.IsNull()) {
164 for (Standard_Integer i = 1; i <= curves2d->Length(); i++)
165 IGESToBRep::IGESCurveToSequenceOfIGESCurve (curves2d->Value (i), seq2d);
166 len2d = seq2d->Length();
170 GTranslate3d = Standard_False;
172 GTranslate2d = Standard_False;
174 if (GTranslate3d && GTranslate2d) {
175 //Setting preference in the case of inconsitency between 3D and 2D
176 if (myfilepreference == 2) Preferred3d = Standard_False;
177 else if (myfilepreference == 3) Preferred2d = Standard_False;
178 else Preferred3d = Standard_False;
180 if (GTranslate3d && GTranslate2d && len3d != len2d) {
181 GTranslate3d = Preferred3d;
182 GTranslate2d = Preferred2d;
185 IGESToBRep_TopoCurve TC (myCS);
187 if (GTranslate3d && !GTranslate2d) {
189 Gsewd->Add (scurve3d->Wire());
191 TopoDS_Shape Sh = TC.TransferTopoCurve (icurve3d);
195 ReverseCurves3d (Gsewd3d);
196 Gsewd->Add (Gsewd3d->Wire());
198 else Gsewd->Add (Sh);//Gsewd = Gsewd3d is impossible to avoid sharing of sewd (UK1.igs entity 7)
202 else if (!GTranslate3d && GTranslate2d) {
203 for (Standard_Integer i = curves2d->Lower(); i <= curves2d->Upper(); i++) {
204 TopoDS_Shape Sh = TC.Transfer2dTopoCurve (curves2d->Value (i), myface, mytrsf, myuFact);
205 if (!Sh.IsNull()) Gsewd2d->Add (Sh);
208 ReverseCurves2d (Gsewd2d, myface);
209 Gsewd->Add (Gsewd2d->Wire());
211 else if (GTranslate3d && GTranslate2d) {
212 //Translate both curves 3D and 2D
213 //Suppose that i-th segment in 2D curve corresponds to i-th segment in 3D curve
214 for (Standard_Integer i = 1; i <= len3d; i++) {
215 Standard_Boolean LTranslate3d = Standard_True, LTranslate2d = Standard_True;
217 Handle(ShapeExtend_WireData) Lsewd3d = new ShapeExtend_WireData;
218 TC.SetBadCase (Standard_False); //:27
220 Lsewd3d->Add (scurve3d->Edge (i));
222 TopoDS_Shape shape3d = TC.TransferTopoCurve (Handle(IGESData_IGESEntity)::DownCast (seq3d->Value (i)));
223 if (!shape3d.IsNull()) {
224 Lsewd3d->Add (shape3d);
226 ReverseCurves3d (Lsewd3d);
228 else LTranslate3d = Standard_False;
230 Gsewd3d->Add (Lsewd3d->Wire());
232 Handle(ShapeExtend_WireData) Lsewd2d = new ShapeExtend_WireData;
233 TopoDS_Shape shape2d = TC.Transfer2dTopoCurve (Handle(IGESData_IGESEntity)::DownCast (seq2d->Value (i)),
234 myface, mytrsf, myuFact);
235 if (!shape2d.IsNull()) {
236 Lsewd2d->Add (shape2d);
238 ReverseCurves2d (Lsewd2d, myface);
239 Gsewd2d->Add (Lsewd2d->Wire());
241 else LTranslate2d = Standard_False;
243 if (LTranslate3d && LTranslate2d && Lsewd3d->NbEdges() != Lsewd2d->NbEdges()) {
244 LTranslate3d = Preferred3d;
245 LTranslate2d = Preferred2d;
247 Handle(ShapeExtend_WireData) Lsewd;//Lsewd3d or Lsewd2d or Lsewd3d+pcurve
248 if ( LTranslate3d && !LTranslate2d) Lsewd = Lsewd3d;
249 else if (!LTranslate3d && LTranslate2d) Lsewd = Lsewd2d;
252 //copying pcurve to edge with 3D curve
253 for (Standard_Integer iedge = 1; iedge <= Lsewd3d->NbEdges(); iedge++) {
254 TopoDS_Edge edge3d = Lsewd3d->Edge (iedge), edge2d = Lsewd2d->Edge (iedge);
255 if (!IGESToBRep::TransferPCurve (edge2d, edge3d, myface)) continue;
258 Gsewd->Add (Lsewd->Wire());
263 mysewd ->Add (Gsewd ->Wire());
264 mysewd3d->Add (Gsewd3d->Wire());
265 mysewd2d->Add (Gsewd2d->Wire());
272 return Standard_True;
275 //=======================================================================
276 //function : ReverseCurves3d
277 //purpose : Reverses 3D curves of the edges in the wire and reverses
278 // the order of edges in the wire.
279 // Orientation of each edge is not changed
280 //=======================================================================
282 void IGESToBRep_IGESBoundary::ReverseCurves3d (const Handle(ShapeExtend_WireData)& sewd)
288 for (Standard_Integer i = 1; i <= sewd->NbEdges(); i++) {
289 TopoDS_Edge oldedge = sewd->Edge (i), newedge;
291 Standard_Real p1, p2;
292 Handle(Geom_Curve) curve = BRep_Tool::Curve (oldedge, L, p1, p2);
293 if (curve->IsPeriodic()) //#21
294 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), L,
295 curve->ReversedParameter (p2),
296 curve->ReversedParameter (p1));
297 else ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), L,
298 Max (curve->ReversedParameter(curve->LastParameter()), curve->ReversedParameter (p2)),
299 Min (curve->ReversedParameter(curve->FirstParameter()), curve->ReversedParameter (p1)));
300 newedge.Orientation(TopAbs::Reverse (oldedge.Orientation()));
301 //sewd->Set (newedge, i);
304 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire();
307 sewd->Init(sfw->Wire());
310 //=======================================================================
311 //function : ReverseCurves2d
312 //purpose : Reverses pcurves of the edges in the wire and reverses
313 // the order of edges in the wire.
314 // Orientation of each edge is also changed
315 //=======================================================================
317 void IGESToBRep_IGESBoundary::ReverseCurves2d (const Handle(ShapeExtend_WireData)& sewd, const TopoDS_Face& face)
320 for (Standard_Integer i = 1; i <= sewd->NbEdges(); i++) {
321 TopoDS_Edge oldedge = sewd->Edge (i), newedge;
322 Standard_Real p1, p2;
323 Handle(Geom2d_Curve) curve = BRep_Tool::CurveOnSurface (oldedge, face, p1, p2);
325 // skl 24.04.2002 for OCC314
326 if(curve->IsPeriodic())
327 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), face,
328 curve->ReversedParameter (p2),
329 curve->ReversedParameter (p1));
331 ShapeBuild_Edge().MakeEdge (newedge, curve->Reversed(), face,
332 Max (curve->FirstParameter(), curve->ReversedParameter (p2)),//BUC50001 entity 936 2DForced
333 Min (curve->LastParameter(), curve->ReversedParameter (p1)));
334 newedge.Orientation(oldedge.Orientation());
335 sewd->Set (newedge, i);