0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / StepToGeom / StepToGeom_MakeCurve.cxx
CommitLineData
b311480e 1// Created on: 1993-07-02
2// Created by: Martine LANGLOIS
3// Copyright (c) 1993-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
7fd59977 17//:n7 abv 16.02.99: S4132: adding translation of curve_replica
18//:o2 abv 17.02.99: S4132: adding translation of offset_curve_3d
19//:o5 abv 17.02.99: bm4_sd_seal_c.stp #58720: translate surface_curve (3d only)
20//:p0 abv 19.02.99: management of 'done' flag improved
21
22#include <StepToGeom_MakeCurve.ixx>
23
24#include <Geom_OffsetCurve.hxx>
25#include <Geom_Direction.hxx>
26
27#include <StepGeom_Curve.hxx>
28#include <StepGeom_TrimmedCurve.hxx>
29#include <StepGeom_Line.hxx>
30#include <StepGeom_Conic.hxx>
31#include <StepGeom_BoundedCurve.hxx>
32#include <StepGeom_CartesianTransformationOperator3d.hxx>
33#include <StepGeom_CurveReplica.hxx>
34#include <StepGeom_OffsetCurve3d.hxx>
35#include <StepGeom_SurfaceCurve.hxx>
36
37#include <StepToGeom_MakeDirection.hxx>
38#include <StepToGeom_MakeTrimmedCurve.hxx>
39#include <StepToGeom_MakeCurve.hxx>
40#include <StepToGeom_MakeLine.hxx>
41#include <StepToGeom_MakeConic.hxx>
42#include <StepToGeom_MakeBoundedCurve.hxx>
43#include <StepToGeom_MakeTransformation3d.hxx>
44
45//=============================================================================
46// Creation d' une Curve de Geom a partir d' une Curve de Step
47//=============================================================================
48
49Standard_Boolean StepToGeom_MakeCurve::Convert (const Handle(StepGeom_Curve)& SC, Handle(Geom_Curve)& CC)
50{
fb20c143 51 if (SC.IsNull()){
52 return Standard_False;
53 }
7fd59977 54 if (SC->IsKind(STANDARD_TYPE(StepGeom_Line))) {
55 const Handle(StepGeom_Line) L = Handle(StepGeom_Line)::DownCast(SC);
c5f3a425 56 return StepToGeom_MakeLine::Convert(L,Handle(Geom_Line)::DownCast (CC));
7fd59977 57 }
58 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve))) {
59 const Handle(StepGeom_TrimmedCurve) TC = Handle(StepGeom_TrimmedCurve)::DownCast(SC);
c5f3a425 60 return StepToGeom_MakeTrimmedCurve::Convert(TC,Handle(Geom_TrimmedCurve)::DownCast (CC));
7fd59977 61 }
62 if (SC->IsKind(STANDARD_TYPE(StepGeom_Conic))) {
63 const Handle(StepGeom_Conic) CO = Handle(StepGeom_Conic)::DownCast(SC);
c5f3a425 64 return StepToGeom_MakeConic::Convert(CO,Handle(Geom_Conic)::DownCast (CC));
7fd59977 65 }
66 if (SC->IsKind(STANDARD_TYPE(StepGeom_BoundedCurve))) {
67 const Handle(StepGeom_BoundedCurve) BC = Handle(StepGeom_BoundedCurve)::DownCast(SC);
c5f3a425 68 return StepToGeom_MakeBoundedCurve::Convert(BC,Handle(Geom_BoundedCurve)::DownCast (CC));
7fd59977 69 }
70 if (SC->IsKind(STANDARD_TYPE(StepGeom_CurveReplica))) { //:n7 abv 16 Feb 99
71 const Handle(StepGeom_CurveReplica) CR = Handle(StepGeom_CurveReplica)::DownCast(SC);
72 const Handle(StepGeom_Curve) PC = CR->ParentCurve();
73 const Handle(StepGeom_CartesianTransformationOperator3d) T =
74 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(CR->Transformation());
75 // protect against cyclic references and wrong type of cartop
76 if ( !T.IsNull() && PC != SC )
77 {
78 Handle(Geom_Curve) C1;
79 if (StepToGeom_MakeCurve::Convert(PC,C1))
80 {
81 gp_Trsf T1;
82 if (StepToGeom_MakeTransformation3d::Convert(T,T1))
83 {
84 C1->Transform ( T1 );
85 CC = C1;
86 return Standard_True;
87 }
88 }
89 }
90 }
91 else if (SC->IsKind(STANDARD_TYPE(StepGeom_OffsetCurve3d))) { //:o2 abv 17 Feb 99
92 const Handle(StepGeom_OffsetCurve3d) OC = Handle(StepGeom_OffsetCurve3d)::DownCast(SC);
93 const Handle(StepGeom_Curve) BC = OC->BasisCurve();
94 if ( BC != SC ) { // protect against loop
95 Handle(Geom_Curve) C1;
96 if (StepToGeom_MakeCurve::Convert(BC,C1))
97 {
98 Handle(Geom_Direction) RD;
99 if (StepToGeom_MakeDirection::Convert(OC->RefDirection(),RD))
100 {
101 CC = new Geom_OffsetCurve ( C1, -OC->Distance(), RD->Dir() );
102 return Standard_True;
103 }
104 }
105 }
106 }
107 else if (SC->IsKind(STANDARD_TYPE(StepGeom_SurfaceCurve))) { //:o5 abv 17 Feb 99
108 const Handle(StepGeom_SurfaceCurve) SurfC = Handle(StepGeom_SurfaceCurve)::DownCast(SC);
109 return StepToGeom_MakeCurve::Convert(SurfC->Curve3d(),CC);
110 }
111 return Standard_False;
112}