1 // Created on: 1994-11-04
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1994-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.
17 //:p0 abv 19.02.99: management of 'done' flag improved
18 //:p3 abv 23.02.99: bm4_id_punch_d.stp #1313: shift of parameters on ellipse with R1 < R2
20 #include <StepToGeom_MakeTrimmedCurve2d.ixx>
21 #include <gp_Pnt2d.hxx>
22 #include <Geom2dConvert.hxx>
23 #include <Geom2d_CartesianPoint.hxx>
24 #include <Geom2d_Curve.hxx>
25 #include <Geom2d_TrimmedCurve.hxx>
26 #include <Geom2d_BSplineCurve.hxx>
27 #include <StepGeom_CartesianPoint.hxx>
28 #include <StepGeom_Line.hxx>
29 #include <StepGeom_Vector.hxx>
30 #include <StepGeom_Circle.hxx>
31 #include <StepGeom_Ellipse.hxx>
32 #include <StepGeom_Parabola.hxx>
33 #include <StepGeom_Hyperbola.hxx>
34 #include <StepGeom_TrimmingSelect.hxx>
35 #include <StepGeom_HArray1OfTrimmingSelect.hxx>
36 #include <StepGeom_TrimmedCurve.hxx>
37 #include <StepToGeom_MakeTrimmedCurve2d.hxx>
38 #include <StepToGeom_MakeCartesianPoint2d.hxx>
39 #include <StepToGeom_MakeCurve2d.hxx>
41 #include <UnitsMethods.hxx>
43 //=============================================================================
44 // Creation d'une Trimmed Curve de Geom2d a partir d' une Trimmed Curve de Step
45 //=============================================================================
46 // Shall be completed to treat trimming with points
48 Standard_Boolean StepToGeom_MakeTrimmedCurve2d::Convert (const Handle(StepGeom_TrimmedCurve)& SC, Handle(Geom2d_BSplineCurve)& CC)
50 const Handle(StepGeom_Curve) BasisCurve = SC->BasisCurve();
51 Handle(Geom2d_Curve) theGeomBasis;
52 if (!StepToGeom_MakeCurve2d::Convert(BasisCurve,theGeomBasis))
53 return Standard_False;
55 if (theGeomBasis->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
56 CC = Handle(Geom2d_BSplineCurve)::DownCast(theGeomBasis);
60 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel1 = SC->Trim1();
61 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel2 = SC->Trim2();
62 const Standard_Integer nbSel1 = SC->NbTrim1();
63 const Standard_Integer nbSel2 = SC->NbTrim2();
64 if ((nbSel1 == 1) && (nbSel2 == 1) &&
65 (theTrimSel1->Value(1).CaseMember() > 0) &&
66 (theTrimSel2->Value(1).CaseMember() > 0))
68 const Standard_Real u1 = theTrimSel1->Value(1).ParameterValue();
69 const Standard_Real u2 = theTrimSel2->Value(1).ParameterValue();
70 Standard_Real fact = 1., shift = 0.;
72 if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Line))) {
73 const Handle(StepGeom_Line) theLine = Handle(StepGeom_Line)::DownCast(BasisCurve);
74 fact = theLine->Dir()->Magnitude();
76 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Circle)) ||
77 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
78 // if (u1 > 2.1*M_PI || u2 > 2.1*M_PI) fact = M_PI / 180.;
79 fact = UnitsMethods::PlaneAngleFactor();
80 //:p3 abv 23 Feb 99: shift on pi/2 on ellipse with R1 < R2
81 const Handle(StepGeom_Ellipse) ellipse = Handle(StepGeom_Ellipse)::DownCast(BasisCurve);
82 if ( !ellipse.IsNull() && ellipse->SemiAxis1() - ellipse->SemiAxis2() < 0. )
85 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Parabola)) ||
86 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Hyperbola))) {
89 // CKY 16-DEC-1997 : USA60035 le texte de Part42 parle de degres
90 // mais des systemes ecrivent en radians. Exploiter UnitsMethods
92 const Standard_Real newU1 = shift + u1 * fact;
93 const Standard_Real newU2 = shift + u2 * fact;
95 const Handle(Geom2d_TrimmedCurve) theTrimmed =
96 new Geom2d_TrimmedCurve(theGeomBasis, newU1, newU2, SC->SenseAgreement());
97 CC = Geom2dConvert::CurveToBSplineCurve(theTrimmed);
100 return Standard_False;