0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitCurve2d.cxx
CommitLineData
b311480e 1// Created on: 1998-03-12
2// Created by: Pierre BARRAS
3// Copyright (c) 1998-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.
7fd59977 16
42cf5bc1 17
18#include <Geom2d_BezierCurve.hxx>
7fd59977 19#include <Geom2d_BSplineCurve.hxx>
42cf5bc1 20#include <Geom2d_Curve.hxx>
7fd59977 21#include <Geom2d_OffsetCurve.hxx>
42cf5bc1 22#include <Geom2d_TrimmedCurve.hxx>
7fd59977 23#include <Precision.hxx>
7fd59977 24#include <ShapeAnalysis_Curve.hxx>
42cf5bc1 25#include <ShapeExtend.hxx>
26#include <ShapeUpgrade.hxx>
27#include <ShapeUpgrade_SplitCurve2d.hxx>
28#include <Standard_ErrorHandler.hxx>
29#include <Standard_Failure.hxx>
30#include <Standard_Type.hxx>
31#include <TColGeom2d_HArray1OfCurve.hxx>
32#include <TColStd_HSequenceOfReal.hxx>
33#include <TColStd_ListIteratorOfListOfReal.hxx>
7fd59977 34
92efcf78 35IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_SplitCurve2d,ShapeUpgrade_SplitCurve)
36
7fd59977 37//=======================================================================
38//function : ShapeUpgrade_SplitCurve2d
39//purpose :
40//=======================================================================
7fd59977 41ShapeUpgrade_SplitCurve2d::ShapeUpgrade_SplitCurve2d()
42{
43}
44
45//=======================================================================
46//function : Init
47//purpose :
48//=======================================================================
49
50 void ShapeUpgrade_SplitCurve2d::Init(const Handle(Geom2d_Curve)& C)
51{
52 Init (C, C->FirstParameter(), C->LastParameter());
53}
54
55//=======================================================================
56//function : Init
57//purpose :
58//=======================================================================
59
60 void ShapeUpgrade_SplitCurve2d::Init(const Handle(Geom2d_Curve)& C,
61 const Standard_Real First,
62 const Standard_Real Last)
63{
64// if (ShapeUpgrade::Debug()) cout << "SplitCurve2d::Init"<<endl;
65 Handle(Geom2d_Curve) CopyOfC = Handle(Geom2d_Curve)::DownCast(C->Copy());
66 myCurve = CopyOfC;
67
68 Standard_Real precision = Precision::PConfusion();
69 Standard_Real firstPar = First;
70 Standard_Real lastPar = Last;
71 Handle (Geom2d_Curve) aCurve = myCurve;
72 if(aCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
73 aCurve=Handle(Geom2d_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
74 // 15.11.2002 PTV OCC966
75 if(!ShapeAnalysis_Curve::IsPeriodic(C)) {
76 Standard_Real fP = aCurve->FirstParameter();
77 Standard_Real lP = aCurve->LastParameter();
78 if(Abs(firstPar-fP) < precision)
79 firstPar = fP;
80 if(Abs(lastPar-lP) < precision)
81 lastPar = lP;
82 if(firstPar < fP){
0797d9d3 83#ifdef OCCT_DEBUG
7fd59977 84 cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
85#endif
86 firstPar = fP;
87 }
88 if(lastPar > lP){
0797d9d3 89#ifdef OCCT_DEBUG
7fd59977 90 cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
91#endif
92 lastPar = lP;
93 }
94 if( (lastPar-firstPar) < precision)
95 lastPar=firstPar+2*precision;
96 }
97
98 ShapeUpgrade_SplitCurve::Init (firstPar, lastPar);
99
100 // first, we make a copy of C to prevent modification:
101// if (ShapeUpgrade::Debug()) cout << ". copy of the curve"<<endl;
102
103 myNbCurves = 1;
104}
105
106//=======================================================================
107//function : Build
108//purpose :
109//=======================================================================
110
111 void ShapeUpgrade_SplitCurve2d::Build(const Standard_Boolean Segment)
112{
113// if (ShapeUpgrade::Debug()) cout<<"ShapeUpgrade_SplitCurve2d::Build"<<endl;
114 Standard_Real First = mySplitValues->Value(1);
115 Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
116 //PrepareKnots();
117 if (mySplitValues->Length() > 2)
118 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
119 if (myCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
120 Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (myCurve);
121 Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
122 ShapeUpgrade_SplitCurve2d spc;
123 spc.Init(BasCurve,First,Last);
124 spc.SetSplitValues(mySplitValues);
125 spc.Build(Segment);
126 myNbCurves = spc.GetCurves()->Length();
127
128 myResultingCurves=new TColGeom2d_HArray1OfCurve (1,myNbCurves);
129 if (myNbCurves == 1) {
130 Handle(Geom2d_TrimmedCurve) NewTrimCurve =
131 new Geom2d_TrimmedCurve(spc.GetCurves()->Value(1),First,Last);
132 myResultingCurves->SetValue(1,NewTrimCurve);
133 }
134 else
135 myResultingCurves = spc.GetCurves();
136 myStatus |= spc.myStatus;
137 return;
138 }
139 else if (myCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) {
140 Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (myCurve);
141 Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
142 Standard_Real Offset = tmp->Offset();
143 ShapeUpgrade_SplitCurve2d spc;
144 spc.Init(BasCurve,First,Last);
145 spc.SetSplitValues(mySplitValues);
146 spc.Build(Segment);
147 myNbCurves = spc.GetCurves()->Length();
148 myResultingCurves = new TColGeom2d_HArray1OfCurve (1,myNbCurves);
149 for(Standard_Integer i = 1; i <= myNbCurves; i++) {
150 Handle(Geom2d_OffsetCurve) NewOffsetCurve = new Geom2d_OffsetCurve(spc.GetCurves()->Value(i),Offset);
151 myResultingCurves->SetValue(i,NewOffsetCurve);
152 }
153 myStatus |= spc.myStatus;
154 return;
155 }
156
157 myNbCurves = mySplitValues->Length() -1;
158 myResultingCurves=new TColGeom2d_HArray1OfCurve (1,myNbCurves);
159 if(myNbCurves ==1) {
160 Standard_Boolean filled = Standard_True;
161 if ( Abs ( myCurve->FirstParameter() - First ) < Precision::PConfusion() &&
162 Abs ( myCurve->LastParameter() - Last ) < Precision::PConfusion() )
163 myResultingCurves->SetValue(1,myCurve);
164
165 else if ( ! Segment || (!myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) &&
166 !myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve))) || ! Status ( ShapeExtend_DONE2 ) ) {
167 if(myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) ||
168 myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve) )) {
169 Handle(Geom2d_Curve) theNewCurve = Handle(Geom2d_Curve)::DownCast(myCurve->Copy());
170 try {
171 OCC_CATCH_SIGNALS
172 if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)))
173 Handle(Geom2d_BSplineCurve)::DownCast(theNewCurve)->Segment (First, Last);
174 else if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve)))
175 Handle(Geom2d_BezierCurve)::DownCast(theNewCurve)->Segment (First, Last);
176 }
177 catch (Standard_Failure) {
0797d9d3 178#ifdef OCCT_DEBUG
7fd59977 179 cout << "Warning: ShapeUpgrade_Split2dCurve::Build(): Exception in Segment :";
180 Standard_Failure::Caught()->Print(cout); cout << endl;
181#endif
182 theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),First,Last);
183 }
184 myResultingCurves->SetValue (1, theNewCurve);
185
186 }
187 else {
188 Handle(Geom2d_TrimmedCurve) theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),First,Last);
189 myResultingCurves->SetValue (1, theNewCurve);
190 }
191 }
192 else filled = Standard_False;
193 if ( filled ) return;
194 }
195
196
197 if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve))) {
198 Handle(Geom2d_BSplineCurve) BsCurve = Handle(Geom2d_BSplineCurve)::DownCast(myCurve->Copy());
199 Standard_Integer FirstInd =BsCurve->FirstUKnotIndex(),
200 LastInd = BsCurve->LastUKnotIndex();
201 Standard_Integer j = FirstInd;
202 for(Standard_Integer ii =1 ; ii <= mySplitValues->Length(); ii++) {
203 Standard_Real spval = mySplitValues->Value(ii);
204 for(; j <=LastInd;j++) {
205 if( spval > BsCurve->Knot(j) + Precision::PConfusion()) continue;
206 if( spval < BsCurve->Knot(j) - Precision::PConfusion()) break;
207 mySplitValues->SetValue(ii,BsCurve->Knot(j));
208 }
209 if(j == LastInd) break;
210 }
211
212 }
213 for (Standard_Integer i = 1; i <= myNbCurves; i++) {
214 // skl : in the next block I change "First","Last" to "Firstt","Lastt"
215 Standard_Real Firstt = mySplitValues->Value(i), Lastt = mySplitValues->Value(i+1);
216 Handle(Geom2d_Curve) theNewCurve;
217 if(Segment) {
218 // creates a copy of myCurve before to segment:
219 if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) ||
220 myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve))) {
221 theNewCurve = Handle(Geom2d_Curve)::DownCast(myCurve->Copy());
222 try {
223 OCC_CATCH_SIGNALS
224 if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)))
225 Handle(Geom2d_BSplineCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
226 else if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve)))
227 Handle(Geom2d_BezierCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
228 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
229 }
230 catch (Standard_Failure) {
0797d9d3 231#ifdef OCCT_DEBUG
7fd59977 232 cout << "Warning: ShapeUpgrade_Split2dCurve::Build(): Exception in Segment :";
233 Standard_Failure::Caught()->Print(cout); cout << endl;
234#endif
235 theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
236 }
237 }
238 else
239 theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
240 }
241 myResultingCurves->SetValue (i, theNewCurve);
242 }
243}
244
245//=======================================================================
246//function : GetCurves
247//purpose :
248//=======================================================================
249
250const Handle(TColGeom2d_HArray1OfCurve)& ShapeUpgrade_SplitCurve2d::GetCurves() const
251{
252 return myResultingCurves;
253}