0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TDataXtd / TDataXtd_Geometry.cxx
CommitLineData
b311480e 1// Created on: 2009-04-06
973c2be1 2// Copyright (c) 2009-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
7fd59977 15
7fd59977 16#include <BRep_Tool.hxx>
7fd59977 17#include <Geom_CartesianPoint.hxx>
7fd59977 18#include <Geom_Circle.hxx>
19#include <Geom_Curve.hxx>
7fd59977 20#include <Geom_CylindricalSurface.hxx>
42cf5bc1 21#include <Geom_Ellipse.hxx>
22#include <Geom_Line.hxx>
23#include <Geom_Plane.hxx>
24#include <Geom_RectangularTrimmedSurface.hxx>
25#include <Geom_TrimmedCurve.hxx>
26#include <gp_Ax1.hxx>
27#include <gp_Circ.hxx>
28#include <gp_Cylinder.hxx>
29#include <gp_Elips.hxx>
42cf5bc1 30#include <gp_Pln.hxx>
31#include <gp_Pnt.hxx>
42cf5bc1 32#include <Standard_Type.hxx>
42cf5bc1 33#include <TDataXtd.hxx>
34#include <TDataXtd_Geometry.hxx>
35#include <TDF_Attribute.hxx>
36#include <TDF_Label.hxx>
37#include <TDF_RelocationTable.hxx>
42cf5bc1 38#include <TNaming_Tool.hxx>
42cf5bc1 39#include <TopoDS.hxx>
40#include <TopoDS_Edge.hxx>
42cf5bc1 41#include <TopoDS_Vertex.hxx>
7fd59977 42
92efcf78 43IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Geometry,TDF_Attribute)
44
7fd59977 45//=======================================================================
46//function : GetID
47//purpose :
48//=======================================================================
7fd59977 49const Standard_GUID& TDataXtd_Geometry::GetID ()
50{
51 static Standard_GUID TDataXtd_GeometryID ("2a96b604-ec8b-11d0-bee7-080009dc3333");
52 return TDataXtd_GeometryID;
53}
54
55
56
57//=======================================================================
58//function : Set
59//purpose :
60//=======================================================================
61
62Handle(TDataXtd_Geometry) TDataXtd_Geometry::Set (const TDF_Label& L)
63{
64 Handle(TDataXtd_Geometry) A;
65 if (!L.FindAttribute(TDataXtd_Geometry::GetID(),A)) {
66 A = new TDataXtd_Geometry ();
67// A->SetType(TDataXtd_ANY_GEOM);
68 L.AddAttribute(A);
69 }
70 return A;
71}
72
73
74//=======================================================================
75//function : Point
76//purpose :
77//=======================================================================
78
79Standard_Boolean TDataXtd_Geometry::Point(const TDF_Label& L,gp_Pnt& G)
80{
81 Handle(TNaming_NamedShape) NS;
82 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
83 return Point(NS,G);
84 }
85 return Standard_False;
86}
87
88//=======================================================================
89//function : Point
90//purpose :
91//=======================================================================
92
93Standard_Boolean TDataXtd_Geometry::Point(const Handle(TNaming_NamedShape)& NS, gp_Pnt& G)
94{
95 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
96 if (shape.IsNull()) return Standard_False;
97 if (shape.ShapeType() == TopAbs_VERTEX) {
98 const TopoDS_Vertex& vertex = TopoDS::Vertex(shape);
99 G = BRep_Tool::Pnt (TopoDS::Vertex (vertex));
100 return Standard_True;
101 }
102 return Standard_False;
103}
104
105//=======================================================================
106//function : Axis
107//purpose :
108//=======================================================================
109
110Standard_Boolean TDataXtd_Geometry::Axis(const TDF_Label& L,gp_Ax1& G)
111{
112 Handle(TNaming_NamedShape) NS;
113 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
114 return Axis(NS,G);
115 }
116 return Standard_False;
117}
118
119//=======================================================================
120//function : Axis
121//purpose :
122//=======================================================================
123
124Standard_Boolean TDataXtd_Geometry::Axis(const Handle(TNaming_NamedShape)& NS, gp_Ax1& G)
125{
126 gp_Lin lin;
127 if (Line(NS, lin)) {
128 G = lin.Position();
129 return Standard_True;
130 }
131 return Standard_False;
132}
133
134
135//=======================================================================
136//function : Line
137//purpose :
138//=======================================================================
139
140Standard_Boolean TDataXtd_Geometry::Line(const TDF_Label& L,gp_Lin& G)
141{
142 Handle(TNaming_NamedShape) NS;
143 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
144 return Line(NS,G);
145 }
146 return Standard_False;
147}
148
149//=======================================================================
150//function : Line
151//purpose :
152//=======================================================================
153
154Standard_Boolean TDataXtd_Geometry::Line(const Handle(TNaming_NamedShape)& NS,gp_Lin& G)
155{
156 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
157 if (shape.IsNull()) return Standard_False;
158 if (shape.ShapeType() == TopAbs_EDGE) {
159 const TopoDS_Edge& edge = TopoDS::Edge(shape);
160 Standard_Real first,last;
161 // TopLoc_Location loc;
162 Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,first,last);
163 if (!curve.IsNull()) {
164 if (curve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
165 curve = (Handle(Geom_TrimmedCurve)::DownCast (curve))->BasisCurve ();
166 Handle(Geom_Line) C = Handle(Geom_Line)::DownCast(curve);
167 if (!C.IsNull()) {
168 G = C->Lin();
169 return Standard_True;
170 }
171 }
172 }
173 return Standard_False;
174}
175
176//=======================================================================
177//function : Circle
178//purpose :
179//=======================================================================
180
181Standard_Boolean TDataXtd_Geometry::Circle(const TDF_Label& L,gp_Circ& G)
182{
183 Handle(TNaming_NamedShape) NS;
184 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
185 return Circle(NS,G);
186 }
187 return Standard_False;
188}
189
190//=======================================================================
191//function : Circle
192//purpose :
193//=======================================================================
194
195Standard_Boolean TDataXtd_Geometry::Circle(const Handle(TNaming_NamedShape)& NS,gp_Circ& G)
196{
197 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
198 if (shape.IsNull()) return Standard_False;
199 if (shape.ShapeType() == TopAbs_EDGE) {
200 const TopoDS_Edge& edge = TopoDS::Edge(shape);
201 Standard_Real first,last;
202 // TopLoc_Location loc;
203 Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,first,last);
204 if (!curve.IsNull()) {
205 if (curve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
206 curve = (Handle(Geom_TrimmedCurve)::DownCast (curve))->BasisCurve ();
207 Handle(Geom_Circle) C = Handle(Geom_Circle)::DownCast(curve);
208 if (!C.IsNull()) {
209 G = C->Circ();
210 return Standard_True;
211 }
212 }
213 }
214 return Standard_False;
215}
216
217
218//=======================================================================
219//function : Ellipse
220//purpose :
221//=======================================================================
222
223Standard_Boolean TDataXtd_Geometry::Ellipse(const TDF_Label& L,gp_Elips& G)
224{
225 Handle(TNaming_NamedShape) NS;
226 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
227 return Ellipse(NS,G);
228 }
229 return Standard_False;
230}
231
232
233//=======================================================================
234//function : Ellipse
235//purpose :
236//=======================================================================
237
238Standard_Boolean TDataXtd_Geometry::Ellipse(const Handle(TNaming_NamedShape)& NS, gp_Elips& G)
239{
240 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
241 if (shape.IsNull()) return Standard_False;
242 if (shape.ShapeType() == TopAbs_EDGE) {
243 const TopoDS_Edge& edge = TopoDS::Edge(shape);
244 Standard_Real first,last;
245 Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,first,last);
246 if (!curve.IsNull()) {
247 if (curve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
248 curve = (Handle(Geom_TrimmedCurve)::DownCast (curve))->BasisCurve ();
249 Handle(Geom_Ellipse) C = Handle(Geom_Ellipse)::DownCast(curve);
250 if (!C.IsNull()) {
251 G = C->Elips();
252 return Standard_True;
253 }
254 }
255 }
256 return Standard_False;
257}
258
259
260//=======================================================================
261//function : Plane
262//purpose :
263//=======================================================================
264
265Standard_Boolean TDataXtd_Geometry::Plane(const TDF_Label& L, gp_Pln& G)
266{
267 Handle(TNaming_NamedShape) NS;
268 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
269 return Plane(NS,G);
270 }
271 return Standard_False;
272}
273
274
275//=======================================================================
276//function : Plane
277//purpose :
278//=======================================================================
279
280Standard_Boolean TDataXtd_Geometry::Plane(const Handle(TNaming_NamedShape)& NS, gp_Pln& G)
281{
282 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
283 if (shape.IsNull()) return Standard_False;
284 if (shape.ShapeType() == TopAbs_FACE) {
285 const TopoDS_Face& face = TopoDS::Face(shape);
286 Handle(Geom_Surface) surface = BRep_Tool::Surface (face);
287 if (!surface.IsNull()) {
288 if (surface->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
c5f3a425 289 surface = Handle(Geom_RectangularTrimmedSurface)::DownCast (surface)->BasisSurface();
7fd59977 290 Handle(Geom_Plane) S = Handle(Geom_Plane)::DownCast(surface);
291 if (!S.IsNull()) {
292 G = S->Pln();
293 return Standard_True;
294 }
295 }
296 }
297 return Standard_False;
298}
299
300
301//=======================================================================
302//function : Cylinder
303//purpose :
304//=======================================================================
305
306Standard_Boolean TDataXtd_Geometry::Cylinder(const TDF_Label& L, gp_Cylinder& G)
307{
308 Handle(TNaming_NamedShape) NS;
309 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
310 return Cylinder (NS,G);
311 }
312 return Standard_False;
313}
314
315
316//=======================================================================
317//function : Cylinder
318//purpose :
319//=======================================================================
320
321Standard_Boolean TDataXtd_Geometry::Cylinder(const Handle(TNaming_NamedShape)& NS, gp_Cylinder& G)
322{
323 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
324 if (shape.IsNull()) return Standard_False;
325 if (shape.ShapeType() == TopAbs_FACE) {
326 const TopoDS_Face& face = TopoDS::Face(shape);
327 Handle(Geom_Surface) surface = BRep_Tool::Surface (face);
328 if (!surface.IsNull()) {
329 if (surface->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
c5f3a425 330 surface = Handle(Geom_RectangularTrimmedSurface)::DownCast (surface)->BasisSurface();
7fd59977 331 Handle(Geom_CylindricalSurface) S = Handle(Geom_CylindricalSurface)::DownCast(surface);
332 if (!S.IsNull()) {
333 G = S->Cylinder();
334 return Standard_True;
335 }
336
337 }
338 }
339 return Standard_False;
340}
341
342
343//=======================================================================
344//function : Type
345//purpose :
346//=======================================================================
347
348TDataXtd_GeometryEnum TDataXtd_Geometry::Type (const TDF_Label& L)
349{
350 Handle(TNaming_NamedShape) NS;
351 if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
352 return Type (NS);
353 }
354 return TDataXtd_ANY_GEOM;
355}
356
357//=======================================================================
358//function : Type
359//purpose :
360//=======================================================================
361
362TDataXtd_GeometryEnum TDataXtd_Geometry::Type (const Handle(TNaming_NamedShape)& NS)
363{
364 TDataXtd_GeometryEnum type (TDataXtd_ANY_GEOM);
365 const TopoDS_Shape& shape = TNaming_Tool::GetShape(NS);
366 switch (shape.ShapeType()) {
367 case TopAbs_VERTEX :
368 {
369 type = TDataXtd_POINT;
370 break;
371 }
372 case TopAbs_EDGE :
373 {
374 const TopoDS_Edge& edge = TopoDS::Edge(shape);
375 Standard_Real first,last;
376 // TopLoc_Location loc;
377 Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,first,last);
378 if (!curve.IsNull()) {
b1811c1d 379 if (curve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve))) {
380 curve = (Handle(Geom_TrimmedCurve)::DownCast (curve))->BasisCurve ();
381 }
382 if (curve->IsInstance(STANDARD_TYPE(Geom_Line))) {
383 type = TDataXtd_LINE;
384 }
385 else if (curve->IsInstance(STANDARD_TYPE(Geom_Circle))) {
386 type = TDataXtd_CIRCLE;
387 }
388 else if (curve->IsInstance(STANDARD_TYPE(Geom_Ellipse))) {
389 type = TDataXtd_ELLIPSE;
390 }
7fd59977 391 }
0797d9d3 392#ifdef OCCT_DEBUG
7fd59977 393 else {
b1811c1d 394 throw Standard_Failure("curve Null dans TDataXtd_Geometry");
7fd59977 395 }
396#endif
b1811c1d 397 break;
7fd59977 398 }
399 case TopAbs_FACE :
400 {
401 const TopoDS_Face& face = TopoDS::Face(shape);
402 Handle(Geom_Surface) surface = BRep_Tool::Surface (face);
403 if (!surface.IsNull()) {
b1811c1d 404 if (surface->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
405 surface = Handle(Geom_RectangularTrimmedSurface)::DownCast (surface)->BasisSurface();
406 }
407 if (surface->IsInstance(STANDARD_TYPE(Geom_CylindricalSurface))) {
408 type = TDataXtd_CYLINDER;
409 }
410 else if (surface->IsInstance(STANDARD_TYPE(Geom_Plane))) {
411 type = TDataXtd_PLANE;
412 }
7fd59977 413 }
0797d9d3 414#ifdef OCCT_DEBUG
7fd59977 415 else {
b1811c1d 416 throw Standard_Failure("surface Null dans TDataXtd_Geometry");
7fd59977 417 }
418#endif
419 break;
420 }
421 default :
b1811c1d 422 break;
7fd59977 423 }
424 return type;
425}
426
427//=======================================================================
428//function : TDataXtd_Geometry
429//purpose :
430//=======================================================================
431
432TDataXtd_Geometry::TDataXtd_Geometry ()
433 : myType (TDataXtd_ANY_GEOM)
434 { }
435
436
437//=======================================================================
438//function : GetType
439//purpose :
440//=======================================================================
441
442TDataXtd_GeometryEnum TDataXtd_Geometry::GetType () const
443{
444 return myType;
445}
446
447
448//=======================================================================
449//function : SetType
450//purpose :
451//=======================================================================
452
453void TDataXtd_Geometry::SetType (const TDataXtd_GeometryEnum G)
454{
455 // OCC2932 correction
456 if(myType == G) return;
457
458 Backup();
459 myType = G;
460}
461
462
463//=======================================================================
464//function : ID
465//purpose :
466//=======================================================================
467
468const Standard_GUID& TDataXtd_Geometry::ID() const { return GetID(); }
469
470
471//=======================================================================
472//function : NewEmpty
473//purpose :
474//=======================================================================
475
476Handle(TDF_Attribute) TDataXtd_Geometry::NewEmpty () const
477{
478 return new TDataXtd_Geometry();
479}
480
481//=======================================================================
482//function : Restore
483//purpose :
484//=======================================================================
485
486void TDataXtd_Geometry::Restore (const Handle(TDF_Attribute)& With)
487{
488 myType = Handle(TDataXtd_Geometry)::DownCast(With)->GetType();
489}
490
491//=======================================================================
492//function : Paste
493//purpose :
494//=======================================================================
495
35e08fe8 496void TDataXtd_Geometry::Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)&) const {
7fd59977 497 Handle(TDataXtd_Geometry)::DownCast(Into)->SetType(myType);
498}
499
500
501//=======================================================================
502//function : Dump
503//purpose :
504//=======================================================================
505
506Standard_OStream& TDataXtd_Geometry::Dump (Standard_OStream& anOS) const
507{
508 anOS << "Geometry ";
509 TDataXtd::Print(GetType(),anOS);
510 return anOS;
511}