b311480e |
1 | // Created on: 1999-03-09 |
2 | // Created by: Roman LYGIN |
3 | // Copyright (c) 1999-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 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | #include <SWDRAW_ShapeCustom.ixx> |
91322f44 |
18 | |
19 | #include <Draw.hxx> |
7fd59977 |
20 | #include <DBRep.hxx> |
21 | #include <SWDRAW.hxx> |
22 | #include <TopoDS_Shape.hxx> |
23 | #include <ShapeCustom.hxx> |
24 | #include <ShapeCustom_BSplineRestriction.hxx> |
25 | #include <ShapeCustom_RestrictionParameters.hxx> |
26 | #include <TopoDS_Face.hxx> |
27 | #include <TopoDS_Edge.hxx> |
28 | #include <TopoDS_Edge.hxx> |
29 | #include <Geom_Surface.hxx> |
30 | #include <Geom_Surface.hxx> |
31 | #include <Geom_Surface.hxx> |
32 | #include <Geom_Curve.hxx> |
33 | #include <Geom2d_Curve.hxx> |
34 | #include <TopoDS.hxx> |
35 | #include <BRep_Tool.hxx> |
36 | #include <TopAbs.hxx> |
37 | #include <DrawTrSurf.hxx> |
38 | #include <TopExp_Explorer.hxx> |
39 | #include <TopLoc_Location.hxx> |
40 | #include <TopoDS_Face.hxx> |
41 | #include <TopoDS.hxx> |
42 | #include <Geom_SweptSurface.hxx> |
43 | #include <Geom_BSplineCurve.hxx> |
44 | #include <Geom_SweptSurface.hxx> |
45 | #include <Geom_BezierCurve.hxx> |
46 | #include <Geom_RectangularTrimmedSurface.hxx> |
47 | #include <Geom_BSplineSurface.hxx> |
48 | #include <Geom_BezierSurface.hxx> |
49 | #include <Geom_OffsetSurface.hxx> |
50 | #include <ShapeFix.hxx> |
51 | #include <GeomAbs_Shape.hxx> |
52 | #include <TColStd_Array2OfInteger.hxx> |
53 | #include <Geom_TrimmedCurve.hxx> |
54 | #include <Geom_OffsetCurve.hxx> |
55 | #include <Geom2d_TrimmedCurve.hxx> |
56 | #include <Geom2d_Curve.hxx> |
57 | #include <Geom2d_OffsetCurve.hxx> |
58 | #include <Geom2d_BSplineCurve.hxx> |
59 | #include <Geom2d_BezierCurve.hxx> |
60 | #include <Geom_Plane.hxx> |
61 | #include <TColStd_Array1OfReal.hxx> |
62 | |
63 | static Standard_Integer ContToInteger( const GeomAbs_Shape Cont) |
64 | { |
65 | Standard_Integer result =0; |
66 | switch(Cont) { |
67 | case GeomAbs_C0: |
68 | case GeomAbs_G1: result = 0; break; |
69 | case GeomAbs_C1: |
70 | case GeomAbs_G2: result = 1; break; |
71 | case GeomAbs_C2: result = 2; break; |
72 | case GeomAbs_C3: result = 3; break; |
73 | default : result = 4; break; |
74 | } |
75 | return result; |
76 | } |
77 | |
78 | static Standard_Integer directfaces(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
79 | { |
80 | if (argc < 3) { di<<"Donner un nom de SHAPE + un nom de RESULTAT"<<"\n"; return 1 /* Error */; } |
81 | Standard_CString arg1 = argv[1]; |
82 | Standard_CString arg2 = argv[2]; |
83 | TopoDS_Shape Shape = DBRep::Get(arg2); |
84 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 /* Error */; } |
85 | |
86 | TopoDS_Shape result = ShapeCustom::DirectFaces (Shape); |
87 | if (result.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; } |
88 | else if (result == Shape) { di<<"No modif"<<"\n"; return 0; } |
89 | di<<"DirectFaces -> Result : "<<arg1<<"\n"; |
90 | DBRep::Set (arg1,result); |
91 | return 0; // Done |
92 | } |
93 | |
94 | static Standard_Integer ckeckKnots(const TColStd_Array1OfReal& theKnots, |
95 | Standard_Real theFirst, |
96 | Standard_Real theLast) |
97 | { |
98 | Standard_Integer i =1, nb = theKnots.Length(); |
99 | Standard_Integer aNum =0; |
100 | for( ; i< nb; i++) |
101 | { |
102 | if(!aNum) |
103 | { |
104 | Standard_Real aDF = theKnots(i) - theFirst; |
105 | if(fabs(aDF) <= Precision::PConfusion() || |
106 | aDF > Precision::PConfusion()) |
107 | { |
108 | aNum++; |
109 | continue; |
110 | } |
111 | } |
112 | else |
113 | { |
114 | Standard_Real aDL = theKnots(i) - theLast; |
115 | if(fabs(aDL) <= Precision::PConfusion() || |
116 | aDL > Precision::PConfusion()) |
117 | break; |
118 | aNum++; |
119 | |
120 | } |
121 | |
122 | } |
123 | return aNum; |
124 | } |
125 | |
126 | static void expcurv2d(const Handle(Geom2d_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree, |
127 | const Standard_Integer MaxSeg, |
128 | const Standard_Integer theCont, |
129 | Standard_Real theFirst, |
130 | Standard_Real theLast) |
131 | { |
132 | if(aCurve.IsNull()) return; |
133 | |
134 | if (aCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { |
135 | Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (aCurve); |
136 | Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); |
137 | expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); |
138 | return; |
139 | } |
140 | if (aCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) { |
141 | Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (aCurve); |
142 | Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); |
143 | expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); |
144 | return; |
145 | } |
146 | Standard_Integer aCont = ContToInteger(aCurve->Continuity()); |
147 | if(aCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) { |
148 | Handle(Geom2d_BSplineCurve) Bs = Handle(Geom2d_BSplineCurve)::DownCast(aCurve); |
149 | if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; |
150 | if(Bs->NbKnots() -1 > MaxSeg) Nb.ChangeValue(1,2)++; |
151 | if(Bs->IsRational()) Nb.ChangeValue(1,3)++; |
152 | if(aCont < theCont && Bs->NbKnots() > 2) |
153 | { |
154 | TColStd_Array1OfReal aKnots(1,Bs->NbKnots()); |
155 | Bs->Knots(aKnots); |
156 | Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast); |
157 | if(nbInt >1) |
158 | Nb.ChangeValue(1,4)++; |
159 | } |
160 | return; |
161 | } |
162 | if (aCurve->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) { |
163 | Handle(Geom2d_BezierCurve) Bs = Handle(Geom2d_BezierCurve)::DownCast(aCurve); |
164 | if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++; |
165 | if(Bs->IsRational() > ((unsigned int)MaxSeg) ) Nb.ChangeValue(2,3)++; |
166 | if(aCont < theCont) |
167 | { |
168 | |
169 | Nb.ChangeValue(2,4)++; |
170 | } |
171 | return; |
172 | } |
173 | else |
174 | Nb.ChangeValue(1,5)++; |
175 | return; |
176 | } |
177 | |
178 | static void expcurv(const Handle(Geom_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree, |
179 | const Standard_Integer MaxSeg, |
180 | const Standard_Integer theCont, |
181 | Standard_Real theFirst, |
182 | Standard_Real theLast) |
183 | { |
184 | if(aCurve.IsNull()) return; |
185 | if (aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { |
186 | Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (aCurve); |
187 | Handle(Geom_Curve) BasCurve = tmp->BasisCurve(); |
188 | expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); |
189 | return; |
190 | } |
191 | if (aCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) { |
192 | Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (aCurve); |
193 | Handle(Geom_Curve) BasCurve = tmp->BasisCurve(); |
194 | expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); |
195 | return; |
196 | } |
197 | |
198 | Standard_Integer aCont = ContToInteger(aCurve->Continuity()); |
199 | if(aCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { |
200 | Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast(aCurve); |
201 | if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; |
202 | if(Bs->NbKnots() -1 > MaxSeg) Nb.ChangeValue(1,2)++; |
203 | if(Bs->IsRational()) Nb.ChangeValue(1,3)++; |
204 | if(aCont < theCont && Bs->NbKnots() > 2) |
205 | { |
206 | TColStd_Array1OfReal aKnots(1,Bs->NbKnots()); |
207 | Bs->Knots(aKnots); |
208 | Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast); |
209 | if(nbInt >1) |
210 | Nb.ChangeValue(1,4)++; |
211 | } |
212 | return; |
213 | } |
214 | if (aCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { |
215 | Handle(Geom_BezierCurve) Bs = Handle(Geom_BezierCurve)::DownCast(aCurve); |
216 | if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++; |
217 | if(Bs->IsRational() > ((unsigned int)MaxSeg) ) Nb.ChangeValue(2,3)++; |
218 | if(aCont < theCont) |
219 | Nb.ChangeValue(2,4)++; |
220 | return; |
221 | } |
222 | else |
223 | Nb.ChangeValue(1,5)++; |
224 | return; |
225 | } |
226 | static void expsurf(const Handle(Geom_Surface)& aSurface, TColStd_Array2OfInteger& NbSurf, const Standard_Integer Degree, |
227 | const Standard_Integer MaxSeg, |
228 | const Standard_Integer theCont) |
229 | { |
230 | if (aSurface.IsNull()) return; |
231 | if (aSurface->IsKind(STANDARD_TYPE(Geom_SweptSurface))) { |
232 | Handle(Geom_SweptSurface) aSurf = Handle(Geom_SweptSurface)::DownCast(aSurface); |
233 | Handle(Geom_Curve) BasCurve = aSurf->BasisCurve(); |
234 | expcurv(BasCurve,NbSurf,Degree,MaxSeg,theCont,BasCurve->FirstParameter(), |
235 | BasCurve->LastParameter()); |
236 | return; |
237 | } |
238 | if (aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
239 | Handle(Geom_RectangularTrimmedSurface) aSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); |
240 | Handle(Geom_Surface) theSurf = aSurf->BasisSurface(); |
241 | expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont); |
242 | return; |
243 | } |
244 | if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { |
245 | Handle(Geom_OffsetSurface) aSurf = Handle(Geom_OffsetSurface)::DownCast(aSurface); |
246 | Handle(Geom_Surface) theSurf = aSurf->BasisSurface(); |
247 | expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont); |
248 | return; |
249 | |
250 | } |
251 | Standard_Integer aCont = ContToInteger(aSurface->Continuity()); |
252 | |
253 | if (aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) { |
254 | Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(aSurface); |
255 | if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(1,1)++; |
256 | if(((BS->NbUKnots()-1) * (BS->NbVKnots()-1)) >MaxSeg) NbSurf.ChangeValue(1,2)++; |
257 | if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(1,3)++; |
258 | if(aCont < theCont) |
259 | NbSurf.ChangeValue(1,4)++; |
260 | return; |
261 | } |
262 | if (aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) { |
263 | Handle(Geom_BezierSurface) BS = Handle(Geom_BezierSurface)::DownCast(aSurface); |
264 | if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(2,1)++; |
265 | if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(2,3)++; |
266 | if(aCont < theCont) |
267 | NbSurf.ChangeValue(2,4)++; |
268 | return; |
269 | } |
270 | if(aSurface->IsKind(STANDARD_TYPE(Geom_Plane))) |
271 | { |
272 | NbSurf.ChangeValue(1,5)++; |
273 | } |
274 | else |
275 | NbSurf.ChangeValue(2,5)++; |
276 | } |
277 | |
278 | static Standard_Integer expshape(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
279 | { |
280 | if (argc <4) { |
281 | di << "Incorrect number of arguments. Must be 3" << "\n"; |
282 | return 1 /* Error */; |
283 | } |
284 | Standard_CString arg2 = argv[1]; |
285 | TopoDS_Shape Shape = DBRep::Get(arg2); |
91322f44 |
286 | Standard_Integer Degree = Draw::Atoi(argv[2]); |
287 | Standard_Integer MaxSeg = Draw::Atoi(argv[3]); |
7fd59977 |
288 | GeomAbs_Shape aCont3 = GeomAbs_C0; |
289 | Standard_Integer k = 4; |
290 | if( argc > k) |
291 | { |
292 | if(strcmp(argv[k],"C0") == 0) aCont3 = GeomAbs_C0; |
293 | else if (strcmp(argv[k],"C1") == 0) aCont3 = GeomAbs_C1; |
294 | else if (strcmp(argv[k],"C2") == 0) aCont3 = GeomAbs_C2; |
295 | else if (strcmp(argv[k],"C3") == 0) aCont3 = GeomAbs_C3; |
296 | else if (strcmp(argv[k],"CN") == 0) aCont3 = GeomAbs_CN; |
297 | else if (strcmp(argv[k],"G1") == 0) aCont3 = GeomAbs_C0; |
298 | else if (strcmp(argv[k],"G2") == 0) aCont3 = GeomAbs_C1; |
299 | else { |
300 | di<< "Invalid argument Cont3e" << "\n"; return 1; } |
301 | |
302 | |
303 | } |
304 | |
305 | Standard_Integer aCont = ContToInteger(aCont3); |
306 | TColStd_Array2OfInteger NbSurf(1,2,1,5); |
307 | TColStd_Array2OfInteger NbCurv(1,2,1,5); |
308 | TColStd_Array2OfInteger NbCurv2d(1,2,1,5); |
309 | Standard_Integer nbSeam =0; |
310 | NbSurf.Init(0); |
311 | NbCurv.Init(0); |
312 | NbCurv2d.Init(0); |
313 | if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; } |
314 | TopExp_Explorer Ex; |
315 | |
316 | Standard_Integer nbF =1; |
317 | for (Ex.Init(Shape,TopAbs_FACE); Ex.More(); Ex.Next(),nbF++) { |
318 | TopoDS_Face F = TopoDS::Face(Ex.Current()); |
319 | TopLoc_Location L; |
320 | Handle(Geom_Surface) aSurface = BRep_Tool::Surface(F,L); |
321 | expsurf(aSurface,NbSurf,Degree,MaxSeg,aCont); |
322 | TopExp_Explorer exp; |
323 | |
324 | Standard_Integer nbE = 1; |
325 | for(exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next(),nbE++) { |
326 | TopoDS_Edge E = TopoDS::Edge(exp.Current()); |
327 | if(BRep_Tool::IsClosed(E,F)) |
328 | nbSeam++; |
329 | Standard_Real First,Last; |
330 | Handle(Geom_Curve) aCurve = BRep_Tool::Curve(E,L,First, Last); |
331 | expcurv(aCurve,NbCurv,Degree,MaxSeg,aCont,First, Last); |
332 | Standard_Real First2d,Last2d; |
333 | Handle(Geom2d_Curve) aCurve2d = BRep_Tool::CurveOnSurface(E,F,First2d,Last2d); |
334 | expcurv2d(aCurve2d,NbCurv2d,Degree,MaxSeg,aCont,First2d,Last2d); |
335 | } |
336 | } |
337 | di<<"Number of seam edges - "<<nbSeam<<"\n"; |
338 | //if(NbSurf.Value(1,1) !=0) |
339 | di<< "Number of BSpline surfaces with degree more then "<< Degree << " - " <<NbSurf.Value(1,1)<<"\n"; |
340 | //if(NbSurf.Value(1,2) !=0) |
341 | di<< "Number of BSpline surfaces with number of spans more then "<< MaxSeg << " - " <<NbSurf.Value(1,2)<<"\n"; |
342 | //if(NbSurf.Value(1,3) !=0) |
343 | di<< "Number of Rational BSpline surfaces " << NbSurf.Value(1,3)<<"\n"; |
344 | //if(NbSurf.Value(1,4) !=0) |
345 | di<< "Number of BSpline surfaces with continuity less than specified - " << NbSurf.Value(1,4)<<"\n"; |
346 | //if(NbSurf.Value(2,1) !=0) |
347 | di<< "Number of Bezier surfaces with degree more then "<< Degree << " - " <<NbSurf.Value(2,1)<<"\n"; |
348 | //if(NbSurf.Value(2,3) !=0) |
349 | di<< "Number of Rational Bezier surfaces " << " - " <<NbSurf.Value(2,3)<<"\n"; |
350 | //if(NbSurf.Value(2,4) !=0) |
351 | di<< "Number of Bezier surfaces with continuity less than specified - " << NbSurf.Value(2,4)<<"\n"; |
352 | |
353 | //if(NbSurf.Value(1,5) !=0) |
354 | di<< "Number of Planes - " << NbSurf.Value(1,5)<<"\n"; |
355 | //if(NbSurf.Value(2,5) !=0) |
356 | di<< "Number of other surfaces - " << NbSurf.Value(2,5)<<"\n"; |
357 | |
358 | //if(NbCurv.Value(1,1) !=0) |
359 | di<< "Number of BSpline curves with degree more then "<< Degree << " - " <<NbCurv.Value(1,1)<<"\n"; |
360 | //if(NbCurv.Value(1,2) !=0) |
361 | di<< "Number of BSpline curves with number of spans more then - "<< MaxSeg << " - " <<NbCurv.Value(1,2)<<"\n"; |
362 | //if(NbCurv.Value(1,3) !=0) |
363 | di<< "Number of Rational BSpline curves " << NbCurv.Value(1,3)<<"\n"; |
364 | //if(NbCurv.Value(1,4) !=0) |
365 | di<< "Number of BSpline curves with less continuity - " << NbCurv.Value(1,4)<<"\n"; |
366 | //if(NbCurv.Value(2,1) !=0) |
367 | di<< "Number of Bezier curves with degree more then - "<< Degree << " - " <<NbCurv.Value(2,1)<<"\n"; |
368 | //if(NbCurv.Value(2,3) !=0) |
369 | di<< "Number of Rational Bezier curves " << " - " <<NbCurv.Value(2,3)<<"\n"; |
370 | //if(NbCurv.Value(2,4) !=0) |
371 | di<< "Number of Bezier curves with less continuity - " << NbCurv.Value(2,4)<<"\n"; |
372 | |
373 | //if(NbCurv.Value(1,5) !=0) |
374 | di<< "Number of other curves - " << NbCurv.Value(1,5)<<"\n"; |
375 | |
376 | //if(NbCurv2d.Value(1,1) !=0) |
377 | di<< "Number of BSpline pcurves with degree more then - "<< Degree << " - " <<NbCurv2d.Value(1,1)<<"\n"; |
378 | //if(NbCurv2d.Value(1,2) !=0) |
379 | di<< "Number of BSpline pcurves with number of spans more then "<< MaxSeg << " - " <<NbCurv2d.Value(1,2)<<"\n"; |
380 | //if(NbCurv2d.Value(1,3) !=0) |
381 | di<< "Number of Rational BSpline pcurves - " << NbCurv2d.Value(1,3)<<"\n"; |
382 | // if(NbCurv2d.Value(1,4) !=0) |
383 | di<< "Number of BSpline pcurves with less continuity - " << NbCurv2d.Value(1,4)<<"\n"; |
384 | //if(NbCurv2d.Value(2,1) !=0) |
385 | di<< "Number of Bezier pcurves with degree more then "<< Degree <<" - " <<" - " <<NbCurv2d.Value(2,1)<<"\n"; |
386 | //if(NbCurv2d.Value(2,3) !=0) |
387 | di<< "Number of Rational Bezier pcurves " << " - " <<NbCurv2d.Value(2,3)<<"\n"; |
388 | //if(NbCurv2d.Value(2,4) !=0) |
389 | di<< "Number of Bezier pcurves with less continuity - " << NbCurv2d.Value(2,4)<<"\n"; |
390 | |
391 | //if(NbCurv2d.Value(1,5) !=0) |
392 | di<< "Number of other pcurves - " << NbCurv2d.Value(1,5)<<"\n"; |
393 | return 0; |
394 | } |
395 | |
396 | static Standard_Integer scaleshape(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
397 | { |
398 | if (argc !=4) { |
399 | di << "Incorrect number of arguments. Must be 4" << "\n"; |
400 | return 1 /* Error */; |
401 | } |
402 | Standard_CString arg2 = argv[2]; |
403 | TopoDS_Shape Shape = DBRep::Get(arg2); |
404 | if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; } |
405 | |
91322f44 |
406 | TopoDS_Shape result = ShapeCustom::ScaleShape (Shape, Draw::Atof(argv[3])); |
7fd59977 |
407 | if (result.IsNull()) { di << "NO RESULT" << "\n"; return 1; } |
408 | else if (result == Shape) { di << "NO MODIFICATIONS" << "\n"; return 0; } |
409 | DBRep::Set (argv[1],result); |
410 | return 0; |
411 | } |
412 | static Standard_Integer BSplRes(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
413 | { |
414 | if (argc < 11) { |
415 | di << "Incorrect number of arguments. Must be 10" << "\n"; |
416 | return 1 /* Error */; |
417 | } |
418 | Standard_CString arg2 = argv[2]; |
419 | TopoDS_Shape Shape = DBRep::Get(arg2); |
420 | if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; } |
421 | GeomAbs_Shape aCont3; |
422 | if(strcmp(argv[7],"C0") == 0) aCont3 = GeomAbs_C0; |
423 | else if (strcmp(argv[7],"C1") == 0) aCont3 = GeomAbs_C1; |
424 | else if (strcmp(argv[7],"C2") == 0) aCont3 = GeomAbs_C2; |
425 | else if (strcmp(argv[7],"C3") == 0) aCont3 = GeomAbs_C3; |
426 | else if (strcmp(argv[7],"CN") == 0) aCont3 = GeomAbs_CN; |
427 | else if (strcmp(argv[7],"G1") == 0) aCont3 = GeomAbs_C0; |
428 | else if (strcmp(argv[7],"G2") == 0) aCont3 = GeomAbs_C1; |
429 | else { |
430 | di<< "Invalid argument Cont3e" << "\n"; return 1; } |
431 | GeomAbs_Shape aCont2; |
432 | if(strcmp(argv[8],"C0") == 0) aCont2 = GeomAbs_C0; |
433 | else if (strcmp(argv[8],"C1") == 0) aCont2 = GeomAbs_C1; |
434 | else if (strcmp(argv[8],"C2") == 0) aCont2 = GeomAbs_C2; |
435 | else if (strcmp(argv[8],"C3") == 0) aCont2 = GeomAbs_C3; |
436 | else if (strcmp(argv[8],"CN") == 0) aCont2 = GeomAbs_CN; |
437 | else if (strcmp(argv[8],"G1") == 0) aCont2 = GeomAbs_C0; |
438 | else if (strcmp(argv[8],"G2") == 0) aCont2 = GeomAbs_C1; |
439 | else { |
440 | di<< "Invalid argument Cont3e" << "\n"; return 1; } |
441 | |
442 | Handle(ShapeCustom_RestrictionParameters) aParameters = new ShapeCustom_RestrictionParameters; |
91322f44 |
443 | TopoDS_Shape result = ShapeCustom::BSplineRestriction (Shape, Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atoi(argv[5]),Draw::Atoi(argv[6]),aCont3,aCont2,(Standard_Boolean) Draw::Atoi(argv[9]),(Standard_Boolean) Draw::Atoi(argv[10]),aParameters); |
7fd59977 |
444 | if (result.IsNull()) { di << "NO RESULT" << "\n"; return 1; } |
445 | else if (result == Shape) { |
446 | di << "NO MODIFICATIONS" << "\n"; |
447 | DBRep::Set (argv[1],result); return 0; |
448 | } |
449 | ShapeFix::SameParameter(result,Standard_False); |
450 | |
451 | DBRep::Set (argv[1],result); |
452 | return 0; |
453 | } |
454 | |
455 | static Standard_Integer convtorevol(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
456 | { |
457 | if (argc < 3) { di<<"Convert surfaces to revolution: convtorevol result shape"<<"\n"; return 1; } |
458 | |
459 | Standard_CString arg1 = argv[1]; |
460 | Standard_CString arg2 = argv[2]; |
461 | TopoDS_Shape Shape = DBRep::Get(arg2); |
462 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1; } |
463 | |
464 | TopoDS_Shape result = ShapeCustom::ConvertToRevolution (Shape); |
465 | if (result.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; } |
466 | else if (result == Shape) { di<<"No modif"<<"\n"; return 0; } |
467 | di<<"ConvertToRevolution -> Result : "<<arg1<<"\n"; |
468 | DBRep::Set (arg1,result); |
469 | return 0; // Done |
470 | } |
471 | |
472 | //====================================================================== |
473 | //function : InitCommands |
474 | //purpose : |
475 | //======================================================================= |
476 | |
477 | void SWDRAW_ShapeCustom::InitCommands(Draw_Interpretor& theCommands) |
478 | { |
479 | static Standard_Integer initactor = 0; |
480 | if (initactor) return; initactor = 1; |
481 | |
482 | Standard_CString g = SWDRAW::GroupName(); |
483 | |
484 | theCommands.Add ("directfaces", "directfaces result shape", __FILE__, directfaces, g); |
485 | theCommands.Add ("expshape", "expshape shape maxdegree maxseg [min_continuity]", __FILE__, expshape, g); |
486 | theCommands.Add ("scaleshape", "scaleshape result shape scale", __FILE__, scaleshape, g); |
487 | theCommands.Add ("bsplres", "BSplineRestriction result shape tol3d tol2d reqdegree reqnbsegments continuity3d continuity2d PriorDeg RationalConvert", __FILE__,BSplRes, g); |
488 | theCommands.Add ("convtorevol", "convtorevol result shape", __FILE__, convtorevol, g); |
489 | } |