b311480e |
1 | // Created on: 1993-08-12 |
2 | // Created by: Joelle CHAUVET |
3 | // Copyright (c) 1993-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. |
b311480e |
16 | |
7fd59977 |
17 | // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest |
18 | // Modified: Mon Jan 18 11:06:46 1999 |
7fd59977 |
19 | // option -NS dans la commande tuyau pour distinguer les tuyaux |
20 | // a section evolutive des tuyaux a N sections avec N = 2 |
21 | |
22 | #include <GeometryTest.hxx> |
23 | #include <DrawTrSurf.hxx> |
24 | #include <Draw.hxx> |
25 | #include <Draw_Interpretor.hxx> |
26 | #include <Draw_Appli.hxx> |
27 | #include <Draw_Display.hxx> |
28 | |
29 | #include <GeomAbs_SurfaceType.hxx> |
30 | #include <GeomAbs_IsoType.hxx> |
31 | #include <GeomAbs_Shape.hxx> |
32 | |
33 | #include <Geom_BSplineSurface.hxx> |
34 | #include <Geom_BSplineCurve.hxx> |
35 | #include <GeomConvert.hxx> |
36 | |
37 | |
38 | #include <GeomAdaptor_Surface.hxx> |
39 | #include <GeomAdaptor_Curve.hxx> |
40 | #include <Geom2dAdaptor_Curve.hxx> |
41 | |
42 | #include <TColgp_Array1OfPnt.hxx> |
43 | #include <TColgp_Array2OfPnt.hxx> |
44 | #include <TColStd_Array1OfReal.hxx> |
45 | #include <TColStd_Array2OfReal.hxx> |
46 | #include <TColStd_Array1OfInteger.hxx> |
47 | #include <TColStd_HArray1OfReal.hxx> |
48 | #include <TColStd_HArray2OfReal.hxx> |
49 | #include <TColGeom_SequenceOfCurve.hxx> |
50 | |
51 | #include <Precision.hxx> |
52 | |
53 | #include <GeomFill.hxx> |
54 | #include <GeomFill_BSplineCurves.hxx> |
55 | #include <GeomFill_Pipe.hxx> |
56 | #include <GeomFill_SectionGenerator.hxx> |
57 | #include <GeomFill_Line.hxx> |
58 | #include <GeomFill_AppSurf.hxx> |
59 | |
60 | |
61 | #include <DrawTrSurf_BezierSurface.hxx> |
62 | #include <DrawTrSurf_BSplineSurface.hxx> |
63 | |
57c28b61 |
64 | #ifdef _MSC_VER |
7fd59977 |
65 | #include <stdio.h> |
66 | //#define strcasecmp strcmp Already defined |
57c28b61 |
67 | #endif |
68 | |
69 | #ifdef _WIN32 |
7fd59977 |
70 | Standard_IMPORT Draw_Viewer dout; |
71 | #endif |
72 | |
73 | |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : sweep |
78 | //purpose : |
79 | //======================================================================= |
80 | |
a8b52677 |
81 | static Standard_Integer sweep (Draw_Interpretor& di, |
7fd59977 |
82 | Standard_Integer n, const char** a) |
83 | { |
84 | GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet; |
85 | Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10; |
86 | Standard_Real Tol = 1.e-4; |
7fd59977 |
87 | |
88 | if (n < 4 ) return 1; |
89 | |
90 | if (! strcmp(a[2],"-FX")) { |
91 | ipath = 3; |
92 | Option = GeomFill_IsFixed; |
93 | } |
94 | if (! strcmp(a[2],"-FR")) { |
95 | ipath = 3; |
96 | Option = GeomFill_IsFrenet; |
97 | } |
98 | if (! strcmp(a[2],"-CF")) { |
99 | ipath = 3; |
100 | Option = GeomFill_IsCorrectedFrenet; |
101 | } |
102 | if (! strcmp(a[2],"-CN")) { |
103 | ipath = 3; |
104 | isection = 7; |
105 | Option = GeomFill_IsConstantNormal; |
106 | } |
107 | if (! strcmp(a[2],"-DX")) { |
108 | ipath = 3; |
109 | isection = 5; |
110 | Option = GeomFill_IsDarboux; |
111 | } |
112 | |
113 | GeomFill_Pipe Pipe; |
114 | Pipe.GenerateParticularCase(Standard_True); |
115 | |
116 | if (Option == GeomFill_IsDarboux) { |
117 | Handle(Geom2d_Curve) path = DrawTrSurf::GetCurve2d(a[ipath]); |
118 | if ( path.IsNull()) return 1; |
119 | |
120 | Handle(Geom_Surface) Support = DrawTrSurf::GetSurface(a[ipath+1]); |
121 | if ( Support.IsNull()) return 1; |
122 | |
123 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+2]); |
124 | if ( firstS.IsNull()) return 1; |
125 | |
126 | Pipe.Init(path, Support, firstS); |
127 | } |
128 | else if (Option == GeomFill_IsConstantNormal) { |
91322f44 |
129 | gp_Dir D ( Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]) ); |
7fd59977 |
130 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[6]); |
131 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[7]); |
132 | Pipe.Init(path, firstS, D); |
133 | } |
134 | else { |
135 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[ipath]); |
136 | if ( path.IsNull()) return 1; |
137 | |
138 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+1]); |
139 | if ( firstS.IsNull()) return 1; |
140 | |
141 | Pipe.Init(path, firstS, Option); |
142 | } |
143 | |
144 | if (n >=isection+2) { |
91322f44 |
145 | MaxDegree = Draw::Atoi(a[isection+1]); |
146 | if (n >isection+2) NbSeg = Draw::Atoi(a[isection+2]); |
7fd59977 |
147 | } |
148 | |
149 | Pipe.Perform(Tol, Standard_False, GeomAbs_C2, MaxDegree, NbSeg); |
150 | |
a8b52677 |
151 | if (!Pipe.IsDone()) { |
152 | di << "GeomFill_Pipe cannot make a surface\n"; |
153 | return 1; |
154 | } |
155 | |
7fd59977 |
156 | DrawTrSurf::Set(a[1], Pipe.Surface()); |
157 | return 0; |
158 | |
159 | } |
160 | //======================================================================= |
161 | //function : tuyau |
162 | //purpose : |
163 | //======================================================================= |
164 | |
a8b52677 |
165 | static Standard_Integer tuyau (Draw_Interpretor& di, |
7fd59977 |
166 | Standard_Integer n, const char** a) |
167 | { |
168 | if ( n < 4) return 1; |
7fd59977 |
169 | |
170 | GeomAbs_Shape Cont = GeomAbs_C2; |
171 | GeomFill_Pipe Pipe; |
172 | Pipe.GenerateParticularCase(Standard_True); |
173 | |
174 | Standard_Boolean Option_NS = Standard_False; |
175 | Standard_Integer indice_path = 2, narg = n; |
176 | if (! strcmp(a[1],"-NS")) { |
177 | Option_NS = Standard_True; |
178 | indice_path++; |
179 | narg--; |
180 | } |
181 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]); |
182 | if ( path.IsNull()) return 1; |
183 | |
184 | Standard_Integer isect = indice_path+1; |
185 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]); |
186 | if ( firstS.IsNull()) { |
187 | if ( narg == 4) { |
188 | // tuyau a rayon constant. |
91322f44 |
189 | Pipe.Init(path, Draw::Atof(a[isect])); |
7fd59977 |
190 | } |
191 | else |
192 | return 1; |
193 | } |
194 | else { |
195 | if ( narg == 4) { |
196 | // tuyau a section constante. |
197 | Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet); |
198 | } |
199 | else { |
200 | if ( narg == 5 && !Option_NS) { |
201 | // tuyau a section evolutive |
202 | Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]); |
203 | Cont = GeomAbs_C2; |
204 | Pipe.Init(path, firstS, lastS); |
205 | } |
206 | else { |
207 | // tuyau a N sections, N>=2 |
208 | TColGeom_SequenceOfCurve Seq; |
209 | Seq.Clear(); |
210 | Seq.Append(firstS); |
211 | for (Standard_Integer i=isect+1;i<n;i++) { |
212 | Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]); |
213 | Seq.Append(nextS); |
214 | } |
215 | Cont = GeomAbs_C2; |
216 | Pipe.Init(path, Seq); |
217 | } |
218 | } |
219 | } |
220 | |
221 | Pipe.Perform(1.e-4, Standard_False, Cont); |
a8b52677 |
222 | if (!Pipe.IsDone()) { |
223 | di << "GeomFill_Pipe cannot make a surface\n"; |
224 | return 1; |
225 | } |
7fd59977 |
226 | DrawTrSurf::Set(a[indice_path-1], Pipe.Surface()); |
227 | |
228 | return 0; |
229 | } |
230 | |
231 | //======================================================================= |
232 | //function : ruled |
233 | //purpose : |
234 | //======================================================================= |
235 | |
236 | static Standard_Integer ruled(Draw_Interpretor& di, |
237 | Standard_Integer n, const char** a) |
238 | { |
239 | if ( n < 4) return 1; |
240 | |
241 | Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]); |
242 | if ( C1.IsNull()) { |
586db386 |
243 | di << " C1 is not a Curve ==> Command failed\n"; |
7fd59977 |
244 | return 1; |
245 | } |
246 | Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]); |
247 | if ( C2.IsNull()) { |
586db386 |
248 | di << " C2 is not a Curve ==> Command failed\n"; |
7fd59977 |
249 | return 1; |
250 | } |
251 | |
252 | Handle(Geom_Surface) S = GeomFill::Surface(C1,C2); |
253 | if ( S.IsNull()) return 1; |
254 | |
255 | DrawTrSurf::Set(a[1],S); |
256 | return 0; |
257 | } |
258 | |
259 | //======================================================================= |
260 | //function : appsurf |
261 | //purpose : |
262 | //======================================================================= |
263 | |
264 | static Standard_Integer appsurf(Draw_Interpretor& di, |
265 | Standard_Integer n, const char** a) |
266 | { |
267 | if ( n < 4) return 1; |
268 | |
269 | GeomFill_SectionGenerator Section; |
270 | Standard_Integer i; |
271 | Handle(Geom_Curve) C; |
272 | for ( i = 2; i < n; i++) { |
273 | C = DrawTrSurf::GetCurve(a[i]); |
274 | if (C.IsNull()) |
275 | return 1; |
276 | Section.AddCurve(C); |
277 | } |
278 | |
279 | Section.Perform(Precision::PConfusion()); |
280 | |
281 | Handle(GeomFill_Line) Line = new GeomFill_Line(n-2); |
282 | Standard_Integer NbIt = 0; |
283 | GeomFill_AppSurf App( 3, 8, Precision::Confusion(), Precision::PConfusion(), |
284 | NbIt); |
285 | |
286 | App.Perform( Line, Section); |
287 | |
288 | if ( !App.IsDone()) { |
586db386 |
289 | di << " Approximation aux fraises \n"; |
7fd59977 |
290 | } |
291 | |
292 | Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots; |
293 | App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots); |
294 | |
295 | Handle(Geom_BSplineSurface) GBS = new |
296 | Geom_BSplineSurface(App.SurfPoles(), |
297 | App.SurfWeights(), |
298 | App.SurfUKnots(), |
299 | App.SurfVKnots(), |
300 | App.SurfUMults(), |
301 | App.SurfVMults(), |
302 | App.UDegree(), |
303 | App.VDegree()); |
304 | |
305 | DrawTrSurf::Set(a[1],GBS); |
306 | return 0; |
307 | } |
308 | |
35e08fe8 |
309 | static Standard_Integer fillcurves(Draw_Interpretor& /*di*/, |
7fd59977 |
310 | Standard_Integer n, const char** a) |
311 | { |
312 | if ( n < 6) return 1; |
313 | |
314 | Standard_Integer i; |
315 | Handle(Geom_Curve) aC; |
316 | Handle(Geom_BSplineCurve) C[4]; |
317 | for ( i = 2; i < 6; i++) { |
318 | aC = DrawTrSurf::GetCurve(a[i]); |
319 | if (aC.IsNull()) |
320 | return 1; |
321 | C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1); |
322 | } |
323 | |
324 | Standard_Integer ist = 2; |
325 | GeomFill_FillingStyle Style = GeomFill_CoonsStyle; |
91322f44 |
326 | if(n > 6) ist = Draw::Atoi(a[6]); |
7fd59977 |
327 | |
328 | if(ist == 1) Style = GeomFill_StretchStyle; |
329 | if(ist == 2) Style = GeomFill_CoonsStyle; |
330 | if(ist == 3) Style = GeomFill_CurvedStyle; |
331 | |
332 | GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style); |
333 | |
334 | const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface(); |
335 | DrawTrSurf::Set(a[1],GBS); |
336 | return 0; |
337 | } |
338 | |
9e20ed57 |
339 | |
340 | //======================================================================= |
341 | //function : GetSurfaceContinuity |
342 | //purpose : Returns the continuity of the given surface |
343 | //======================================================================= |
344 | static Standard_Integer GetSurfaceContinuity( Draw_Interpretor& theDI, |
345 | Standard_Integer theNArg, |
346 | const char** theArgv) |
347 | { |
348 | if(theNArg != 2) |
349 | { |
350 | theDI << "Use: getsurfcontinuity surface\n"; |
351 | return 1; |
352 | } |
353 | |
354 | Handle(Geom_Surface) GS1 = DrawTrSurf::GetSurface(theArgv[1]); |
355 | if(GS1.IsNull()) |
356 | { |
357 | theDI << "Argument is not a surface!\n"; |
358 | return 1; |
359 | } |
360 | |
361 | char aContName[7][3] = {"C0", //0 |
362 | "G1", //1 |
363 | "C1", //2 |
364 | "G2", //3 |
365 | "C2", //4 |
366 | "C3", //5 |
367 | "CN"}; //6 |
368 | |
369 | theDI << theArgv[1] << " has " << aContName[GS1->Continuity()] << " continuity.\n"; |
370 | |
371 | return 0; |
372 | } |
373 | |
374 | |
7fd59977 |
375 | //======================================================================= |
376 | //function : SurfaceCommands |
377 | //purpose : |
378 | //======================================================================= |
379 | |
380 | |
381 | void GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands) |
382 | { |
383 | static Standard_Boolean loaded = Standard_False; |
384 | if (loaded) return; |
385 | loaded = Standard_True; |
386 | |
387 | DrawTrSurf::BasicCommands(theCommands); |
388 | |
389 | const char* g; |
390 | |
391 | g = "GEOMETRY surfaces creation"; |
392 | |
393 | |
394 | theCommands.Add("tuyau", |
395 | "tuyau [-NS] result Path Curve/Radius [Curve2] [Curve3] ... \n the option -NS is used only with 2 sections.\n With it, <result> is going from the first section to the last section \n Without, <result> is a pipe by evolutive section ", |
396 | __FILE__, |
397 | tuyau,g); |
398 | |
399 | theCommands.Add("partuyau", |
400 | "tuyau result Path Curve/Radius [Curve2]\n the parametrization of the surface in the V direction will be as the Path", |
401 | __FILE__, |
402 | tuyau,g); |
403 | |
404 | theCommands.Add("sweep", "sweep result [options] path [Surf] curve [Tol [nbsegment]]\n sweep the the curve along the path, options are \n -FX : Tangent and Normal are fixed\n -FR : Tangent and Normal are given by Frenet trihedron \n -CF : Tangente is given by Frenet, \n the Normal is computed to minimize the torsion \n -DX : Tangent and Normal are given by Darboux trihedron \n <path> have to be a 2d curve,\n <Surf> have to be defined\n -CN dx dy dz : Normal is given by dx dy dz" , |
405 | __FILE__, |
406 | sweep, g); |
407 | |
408 | theCommands.Add("ruled", |
409 | "ruled result C1 C2", |
410 | __FILE__, |
411 | ruled,g); |
412 | |
413 | theCommands.Add("appsurf", |
414 | "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves", |
415 | __FILE__, |
416 | appsurf,g); |
417 | |
418 | theCommands.Add("fillcurves", |
419 | "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves", |
420 | __FILE__, |
421 | fillcurves,g); |
422 | |
9e20ed57 |
423 | theCommands.Add("getsurfcontinuity", |
424 | "getsurfcontinuity surface: \n\tReturns the continuity of the given surface", |
425 | __FILE__, |
426 | GetSurfaceContinuity,g); |
427 | |
428 | |
7fd59977 |
429 | } |
430 | |
431 | |
432 | |
433 | |