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