0024274: Eliminate GCC compiler warning (wrong initialize order)
[occt.git] / src / StepToGeom / StepToGeom_MakeTrimmedCurve2d.cxx
CommitLineData
b311480e 1// Created on: 1994-11-04
2// Created by: Frederic MAUPAS
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21//:p0 abv 19.02.99: management of 'done' flag improved
22//:p3 abv 23.02.99: bm4_id_punch_d.stp #1313: shift of parameters on ellipse with R1 < R2
23
24#include <StepToGeom_MakeTrimmedCurve2d.ixx>
25#include <gp_Pnt2d.hxx>
26#include <Geom2dConvert.hxx>
27#include <Geom2d_CartesianPoint.hxx>
28#include <Geom2d_Curve.hxx>
29#include <Geom2d_TrimmedCurve.hxx>
30#include <Geom2d_BSplineCurve.hxx>
31#include <StepGeom_CartesianPoint.hxx>
32#include <StepGeom_Line.hxx>
33#include <StepGeom_Vector.hxx>
34#include <StepGeom_Circle.hxx>
35#include <StepGeom_Ellipse.hxx>
36#include <StepGeom_Parabola.hxx>
37#include <StepGeom_Hyperbola.hxx>
38#include <StepGeom_TrimmingSelect.hxx>
39#include <StepGeom_HArray1OfTrimmingSelect.hxx>
40#include <StepGeom_TrimmedCurve.hxx>
41#include <StepToGeom_MakeTrimmedCurve2d.hxx>
42#include <StepToGeom_MakeCartesianPoint2d.hxx>
43#include <StepToGeom_MakeCurve2d.hxx>
44
45#include <UnitsMethods.hxx>
46
47//=============================================================================
48// Creation d'une Trimmed Curve de Geom2d a partir d' une Trimmed Curve de Step
49//=============================================================================
50// Shall be completed to treat trimming with points
51
52Standard_Boolean StepToGeom_MakeTrimmedCurve2d::Convert (const Handle(StepGeom_TrimmedCurve)& SC, Handle(Geom2d_BSplineCurve)& CC)
53{
54 const Handle(StepGeom_Curve) BasisCurve = SC->BasisCurve();
55 Handle(Geom2d_Curve) theGeomBasis;
56 if (!StepToGeom_MakeCurve2d::Convert(BasisCurve,theGeomBasis))
57 return Standard_False;
58
59 if (theGeomBasis->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
60 CC = Handle(Geom2d_BSplineCurve)::DownCast(theGeomBasis);
61 return Standard_True;
62 }
63
64 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel1 = SC->Trim1();
65 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel2 = SC->Trim2();
66 const Standard_Integer nbSel1 = SC->NbTrim1();
67 const Standard_Integer nbSel2 = SC->NbTrim2();
2f6cb3ac 68 if ((nbSel1 == 1) && (nbSel2 == 1) &&
7fd59977 69 (theTrimSel1->Value(1).CaseMember() > 0) &&
70 (theTrimSel2->Value(1).CaseMember() > 0))
71 {
72 const Standard_Real u1 = theTrimSel1->Value(1).ParameterValue();
73 const Standard_Real u2 = theTrimSel2->Value(1).ParameterValue();
74 Standard_Real fact = 1., shift = 0.;
75
76 if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Line))) {
77 const Handle(StepGeom_Line) theLine = Handle(StepGeom_Line)::DownCast(BasisCurve);
78 fact = theLine->Dir()->Magnitude();
79 }
80 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Circle)) ||
81 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
c6541a0c 82// if (u1 > 2.1*M_PI || u2 > 2.1*M_PI) fact = M_PI / 180.;
7fd59977 83 fact = UnitsMethods::PlaneAngleFactor();
84 //:p3 abv 23 Feb 99: shift on pi/2 on ellipse with R1 < R2
85 const Handle(StepGeom_Ellipse) ellipse = Handle(StepGeom_Ellipse)::DownCast(BasisCurve);
86 if ( !ellipse.IsNull() && ellipse->SemiAxis1() - ellipse->SemiAxis2() < 0. )
c6541a0c 87 shift = 0.5 * M_PI;
7fd59977 88 }
89 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Parabola)) ||
90 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Hyperbola))) {
91 // LATER !!!
92 }
93// CKY 16-DEC-1997 : USA60035 le texte de Part42 parle de degres
94// mais des systemes ecrivent en radians. Exploiter UnitsMethods
95
96 const Standard_Real newU1 = shift + u1 * fact;
97 const Standard_Real newU2 = shift + u2 * fact;
98
99 const Handle(Geom2d_TrimmedCurve) theTrimmed =
100 new Geom2d_TrimmedCurve(theGeomBasis, newU1, newU2, SC->SenseAgreement());
101 CC = Geom2dConvert::CurveToBSplineCurve(theTrimmed);
102 return Standard_True;
103 }
104//#ifdef DEB
105// else cout << "Warning: TrimmedCurve2d not translated" << endl;
106//#endif
107 return Standard_False;
108}