0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESToBRep / IGESToBRep.cxx
CommitLineData
b311480e 1// Created on: 1994-03-22
2// Created by: GUYOT and UNTEREINER
3// Copyright (c) 1994-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.
b311480e 16
ce7fe22d 17#include <IGESToBRep.hxx>
7fd59977 18
42cf5bc1 19#include <BRep_Builder.hxx>
20#include <BRep_Tool.hxx>
42cf5bc1 21#include <Geom2d_Curve.hxx>
42cf5bc1 22#include <GeomLib.hxx>
42cf5bc1 23#include <IGESBasic_SingleParent.hxx>
7fd59977 24#include <IGESData_IGESEntity.hxx>
7fd59977 25#include <IGESGeom_BoundedSurface.hxx>
26#include <IGESGeom_BSplineCurve.hxx>
27#include <IGESGeom_BSplineSurface.hxx>
28#include <IGESGeom_CircularArc.hxx>
7fd59977 29#include <IGESGeom_CompositeCurve.hxx>
42cf5bc1 30#include <IGESGeom_ConicArc.hxx>
7fd59977 31#include <IGESGeom_CopiousData.hxx>
42cf5bc1 32#include <IGESGeom_Line.hxx>
7fd59977 33#include <IGESGeom_OffsetCurve.hxx>
42cf5bc1 34#include <IGESGeom_OffsetSurface.hxx>
7fd59977 35#include <IGESGeom_Plane.hxx>
36#include <IGESGeom_Point.hxx>
42cf5bc1 37#include <IGESGeom_RuledSurface.hxx>
7fd59977 38#include <IGESGeom_SplineCurve.hxx>
39#include <IGESGeom_SplineSurface.hxx>
42cf5bc1 40#include <IGESGeom_SurfaceOfRevolution.hxx>
41#include <IGESGeom_TabulatedCylinder.hxx>
42#include <IGESGeom_TrimmedSurface.hxx>
43#include <IGESSolid_ConicalSurface.hxx>
44#include <IGESSolid_CylindricalSurface.hxx>
7fd59977 45#include <IGESSolid_EdgeList.hxx>
7fd59977 46#include <IGESSolid_ManifoldSolid.hxx>
47#include <IGESSolid_PlaneSurface.hxx>
42cf5bc1 48#include <IGESSolid_Shell.hxx>
49#include <IGESSolid_SphericalSurface.hxx>
50#include <IGESSolid_ToroidalSurface.hxx>
51#include <IGESSolid_VertexList.hxx>
42cf5bc1 52#include <IGESToBRep_AlgoContainer.hxx>
53#include <Interface_Macros.hxx>
7fd59977 54#include <Precision.hxx>
42cf5bc1 55#include <Standard_ErrorHandler.hxx>
56#include <Standard_Failure.hxx>
57#include <Standard_Stream.hxx>
7fd59977 58#include <TopoDS_Edge.hxx>
42cf5bc1 59#include <TopoDS_Face.hxx>
42cf5bc1 60#include <TopoDS_Shape.hxx>
42cf5bc1 61#include <XSAlgo.hxx>
7fd59977 62
7fd59977 63static Handle(IGESToBRep_AlgoContainer) theContainer;
64
65//=======================================================================
66//function : Init
67//purpose :
68//=======================================================================
69
70 void IGESToBRep::Init()
71{
72 static Standard_Boolean init = Standard_False;
73 if (init) return;
74 init = Standard_True;
75 XSAlgo::Init();
76 theContainer = new IGESToBRep_AlgoContainer;
77}
78
79//=======================================================================
80//function : SetAlgoContainer
81//purpose :
82//=======================================================================
83
84 void IGESToBRep::SetAlgoContainer(const Handle(IGESToBRep_AlgoContainer)& aContainer)
85{
86 theContainer = aContainer;
87}
88
89//=======================================================================
90//function : AlgoContainer
91//purpose :
92//=======================================================================
93
94 Handle(IGESToBRep_AlgoContainer) IGESToBRep::AlgoContainer()
95{
96 return theContainer;
97}
98
99//=======================================================================
100//function : IsCurveAndSurface
21c7c457 101//purpose : Return True if the IgesEntity can be transferred
7fd59977 102// by TransferCurveAndSurface
103//=======================================================================
104Standard_Boolean IGESToBRep::IsCurveAndSurface(const Handle(IGESData_IGESEntity)& start)
105{
106 //S4054
107 if (start.IsNull()) return Standard_False;
108 if (IsTopoCurve(start)) return Standard_True;
109 if (IsTopoSurface(start)) return Standard_True;
110 if (IsBRepEntity(start)) return Standard_True;
111 return Standard_False;
112}
113
114
115//=======================================================================
116//function : IsBasicCurve
21c7c457 117//purpose : Return True if the IgesEntity can be transferred
7fd59977 118// by TransferBasicCurve
119//=======================================================================
120Standard_Boolean IGESToBRep::IsBasicCurve(const Handle(IGESData_IGESEntity)& start)
121{
122 //S4054
123 if (start.IsNull()) return Standard_False;
124 if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineCurve))) return Standard_True;
125 if (start->IsKind(STANDARD_TYPE(IGESGeom_Line))) return Standard_True;
126 if (start->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) return Standard_True;
127 if (start->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) return Standard_True;
128 if (start->IsKind(STANDARD_TYPE(IGESGeom_CopiousData))) return Standard_True;
129 if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineCurve))) return Standard_True;
130 return Standard_False;
131}
132
133
134//=======================================================================
135//function : IsBasicSurface
21c7c457 136//purpose : Return True if the IgesEntity can be transferred
7fd59977 137// by TransferBasicSurface
138//=======================================================================
139Standard_Boolean IGESToBRep::IsBasicSurface(const Handle(IGESData_IGESEntity)& start)
140{
141 //S4054
142 if (start.IsNull()) return Standard_False;
143 if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineSurface))) return Standard_True;
144 if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineSurface))) return Standard_True;
145 //S4181 pdn 15.04.99 added to basic surfaces
146 if (start->IsKind(STANDARD_TYPE(IGESSolid_PlaneSurface))) return Standard_True;
147 if (start->IsKind(STANDARD_TYPE(IGESSolid_CylindricalSurface))) return Standard_True;
148 if (start->IsKind(STANDARD_TYPE(IGESSolid_ConicalSurface))) return Standard_True;
149 if (start->IsKind(STANDARD_TYPE(IGESSolid_SphericalSurface))) return Standard_True;
150 if (start->IsKind(STANDARD_TYPE(IGESSolid_ToroidalSurface))) return Standard_True;
151
152 return Standard_False;
153}
154
155
156//=======================================================================
157//function : IsTopoCurve
21c7c457 158//purpose : Return True if the IgesEntity can be transferred
7fd59977 159// by TransferTopoCurve
160//=======================================================================
161Standard_Boolean IGESToBRep::IsTopoCurve(const Handle(IGESData_IGESEntity)& start)
162{
163 //S4054
164 if (start.IsNull()) return Standard_False;
165 if (IsBasicCurve(start)) return Standard_True;
166 if (start->IsKind(STANDARD_TYPE(IGESGeom_CompositeCurve))) return Standard_True;
167 if (start->IsKind(STANDARD_TYPE(IGESGeom_CurveOnSurface))) return Standard_True;
168 if (start->IsKind(STANDARD_TYPE(IGESGeom_Boundary))) return Standard_True;
169 if (start->IsKind(STANDARD_TYPE(IGESGeom_Point))) return Standard_True;
170 if (start->IsKind(STANDARD_TYPE(IGESGeom_OffsetCurve))) return Standard_True;
171 return Standard_False;
172}
173
174
175//=======================================================================
176//function : IsTopoSurface
21c7c457 177//purpose : Return True if the IgesEntity can be transferred
7fd59977 178// by TransferTopoSurface
179//=======================================================================
180Standard_Boolean IGESToBRep::IsTopoSurface(const Handle(IGESData_IGESEntity)& start)
181{
182 //S4054
183 if (start.IsNull()) return Standard_False;
184 if (IsBasicSurface(start)) return Standard_True;
185 if (start->IsKind(STANDARD_TYPE(IGESGeom_TrimmedSurface))) return Standard_True;
186 if (start->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) return Standard_True;
187 if (start->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) return Standard_True;
188 if (start->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) return Standard_True;
189 if (start->IsKind(STANDARD_TYPE(IGESGeom_Plane))) return Standard_True;
190 if (start->IsKind(STANDARD_TYPE(IGESGeom_BoundedSurface))) return Standard_True;
191 if (start->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))) return Standard_True;
192 //S4181 pdn 15.04.99 removing to basic surface
193 //if (start->IsKind(STANDARD_TYPE(IGESSolid_PlaneSurface))) return Standard_True;
194// SingleParent, cas particulier (Face Trouee : ne contient que des PLANE)
195 if (start->IsKind(STANDARD_TYPE(IGESBasic_SingleParent))) {
196 DeclareAndCast(IGESBasic_SingleParent,sp,start);
197 if (!sp->SingleParent()->IsKind(STANDARD_TYPE(IGESGeom_Plane))) return Standard_False;
198 Standard_Integer nb = sp->NbChildren();
199 for (Standard_Integer i = 1; i <= nb; i ++) {
200 if (!sp->Child(i)->IsKind(STANDARD_TYPE(IGESGeom_Plane))) return Standard_False;
201 }
202 return Standard_True;
203 }
204 return Standard_False;
205}
206
207
208//=======================================================================
209//function : IsBRepEntity
21c7c457 210//purpose : Return True if the IgesEntity can be transferred
7fd59977 211// by TransferBRepEntity
212//=======================================================================
213Standard_Boolean IGESToBRep::IsBRepEntity(const Handle(IGESData_IGESEntity)& start)
214{
215 //S4054
216 if (start.IsNull()) return Standard_False;
217 if (start->IsKind(STANDARD_TYPE(IGESSolid_Face))) return Standard_True;
218 if (start->IsKind(STANDARD_TYPE(IGESSolid_Shell))) return Standard_True;
219 if (start->IsKind(STANDARD_TYPE(IGESSolid_ManifoldSolid))) return Standard_True;
220 if (start->IsKind(STANDARD_TYPE(IGESSolid_VertexList))) return Standard_True;
221 if (start->IsKind(STANDARD_TYPE(IGESSolid_EdgeList))) return Standard_True;
222 if (start->IsKind(STANDARD_TYPE(IGESSolid_Loop))) return Standard_True;
223 return Standard_False;
224}
225
7fd59977 226//=======================================================================
227//function : IGESCurveToSequenceOfIGESCurve
228//purpose : Creates a sequence of IGES curves from IGES curve:
229// - if curve is CompositeCurve its components are recursively added,
230// - if curve is ordinary IGES curve it is simply added
231// - otherwise (Null or not curve) it is ignored
232//remark : if sequence is Null it is created, otherwise it is appended
233//returns : number of curves in sequence
234//example : (A B (C (D ( E F) G) H)) -> (A B C D E F G H)
235//=======================================================================
236
237 Standard_Integer IGESToBRep::IGESCurveToSequenceOfIGESCurve(const Handle(IGESData_IGESEntity)& curve,
238 Handle(TColStd_HSequenceOfTransient)& sequence)
239{
240 if (sequence.IsNull()) sequence = new TColStd_HSequenceOfTransient;
241 if (!curve.IsNull()) {
242 if (curve->IsKind (STANDARD_TYPE (IGESGeom_CompositeCurve))) {
243 Handle(IGESGeom_CompositeCurve) comp = Handle(IGESGeom_CompositeCurve)::DownCast (curve);
244 for (Standard_Integer i = 1; i <= comp->NbCurves(); i++) {
245 Handle(TColStd_HSequenceOfTransient) tmpsequence;
246 IGESCurveToSequenceOfIGESCurve (comp->Curve (i), tmpsequence);
247 sequence->Append (tmpsequence);
248 }
249 }
250 else if (IGESToBRep::IsTopoCurve (curve) &&
251 ! curve->IsKind (STANDARD_TYPE (IGESGeom_Point)))
252 sequence->Append (curve);
253 }
254 return sequence->Length();
255}
256
257//=======================================================================
258//function : TransferPCurve
259//purpose : Copies pcurve on face <face> from <fromedge> to <toedge>
260// If <toedge> already has pcurve on that <face>, <toedge> becomes
261// a seam-edge; if both pcurves are not SameRange, the SameRange is
262// called. Returns False if pcurves are not made SameRange
263// Making <toedge> SameParameter should be done outside the method (???)
264//=======================================================================
265
266 Standard_Boolean IGESToBRep::TransferPCurve (const TopoDS_Edge& fromedge, const TopoDS_Edge& toedge, const TopoDS_Face& face)
267{
268 Standard_Boolean result = Standard_True;
269 Standard_Real olda, oldb, a, b;
270 Handle(Geom2d_Curve) oldpcurve = BRep_Tool::CurveOnSurface (toedge, face, olda, oldb),
271 pcurve = BRep_Tool::CurveOnSurface (fromedge, face, a, b );
272 BRep_Builder B;
273 if (!oldpcurve.IsNull()) {
274 if (olda != a || oldb != b) {
275 try {
276 OCC_CATCH_SIGNALS
277 Handle(Geom2d_Curve) newpcurve;
278 GeomLib::SameRange (Precision::PConfusion(), oldpcurve, olda, oldb, a, b, newpcurve);
279 if (!newpcurve.IsNull()) {
280 olda = a; oldb = b; oldpcurve = newpcurve;
281 }
282 else {
0797d9d3 283#ifdef OCCT_DEBUG
04232180 284 std::cout << "Warning: IGESToBRep::TransferPCurve: pcurves are not SameRange" << std::endl;
7fd59977 285#endif
286 result = Standard_False;
287 }
288 }
9775fa61 289 catch(Standard_Failure const& anException) {
0797d9d3 290#ifdef OCCT_DEBUG
04232180 291 std::cout << "\n**IGESToBRep::TransferPCurve: Exception in SameRange : ";
292 anException.Print(std::cout);
7fd59977 293#endif
9775fa61 294 (void)anException;
7fd59977 295 result = Standard_False;
296 }
297 }
298 if (toedge.Orientation() == TopAbs_FORWARD)
299 B.UpdateEdge (toedge,
300 Handle(Geom2d_Curve)::DownCast (pcurve->Copy()),
301 Handle(Geom2d_Curve)::DownCast (oldpcurve->Copy()), face, 0);
302 else
303 B.UpdateEdge (toedge,
304 Handle(Geom2d_Curve)::DownCast (oldpcurve->Copy()),
305 Handle(Geom2d_Curve)::DownCast (pcurve->Copy()), face, 0);
306 }
307 else {
308 olda = a; oldb = b;
309 B.UpdateEdge (toedge, Handle(Geom2d_Curve)::DownCast (pcurve->Copy()), face, 0);
310 }
311 B.Range (toedge, face, a, b);
312 Standard_Real first, last;
313 if (!BRep_Tool::Curve (toedge, first, last).IsNull() && (first != a || last != b))
314 B.SameRange (toedge, Standard_False);
315 else
316 B.SameRange (toedge, Standard_True);
317 return result;
318}