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