b311480e |
1 | // Created on: 1993-08-12 |
2 | // Created by: Joelle CHAUVET |
3 | // Copyright (c) 1993-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest |
22 | // Modified: Mon Jan 18 11:06:46 1999 |
7fd59977 |
23 | // option -NS dans la commande tuyau pour distinguer les tuyaux |
24 | // a section evolutive des tuyaux a N sections avec N = 2 |
25 | |
26 | #include <GeometryTest.hxx> |
27 | #include <DrawTrSurf.hxx> |
28 | #include <Draw.hxx> |
29 | #include <Draw_Interpretor.hxx> |
30 | #include <Draw_Appli.hxx> |
31 | #include <Draw_Display.hxx> |
32 | |
33 | #include <GeomAbs_SurfaceType.hxx> |
34 | #include <GeomAbs_IsoType.hxx> |
35 | #include <GeomAbs_Shape.hxx> |
36 | |
37 | #include <Geom_BSplineSurface.hxx> |
38 | #include <Geom_BSplineCurve.hxx> |
39 | #include <GeomConvert.hxx> |
40 | |
41 | |
42 | #include <GeomAdaptor_Surface.hxx> |
43 | #include <GeomAdaptor_Curve.hxx> |
44 | #include <Geom2dAdaptor_Curve.hxx> |
45 | |
46 | #include <TColgp_Array1OfPnt.hxx> |
47 | #include <TColgp_Array2OfPnt.hxx> |
48 | #include <TColStd_Array1OfReal.hxx> |
49 | #include <TColStd_Array2OfReal.hxx> |
50 | #include <TColStd_Array1OfInteger.hxx> |
51 | #include <TColStd_HArray1OfReal.hxx> |
52 | #include <TColStd_HArray2OfReal.hxx> |
53 | #include <TColGeom_SequenceOfCurve.hxx> |
54 | |
55 | #include <Precision.hxx> |
56 | |
57 | #include <GeomFill.hxx> |
58 | #include <GeomFill_BSplineCurves.hxx> |
59 | #include <GeomFill_Pipe.hxx> |
60 | #include <GeomFill_SectionGenerator.hxx> |
61 | #include <GeomFill_Line.hxx> |
62 | #include <GeomFill_AppSurf.hxx> |
63 | |
64 | |
65 | #include <DrawTrSurf_BezierSurface.hxx> |
66 | #include <DrawTrSurf_BSplineSurface.hxx> |
67 | |
68 | #ifdef WNT |
69 | #include <stdio.h> |
70 | //#define strcasecmp strcmp Already defined |
71 | Standard_IMPORT Draw_Viewer dout; |
72 | #endif |
73 | |
74 | |
75 | |
76 | |
77 | //======================================================================= |
78 | //function : sweep |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | static Standard_Integer sweep (Draw_Interpretor&, |
83 | Standard_Integer n, const char** a) |
84 | { |
85 | GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet; |
86 | Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10; |
87 | Standard_Real Tol = 1.e-4; |
88 | #if DEB |
89 | static Standard_Boolean AdvApprox_Debug = 1; |
90 | #endif |
91 | |
92 | if (n < 4 ) return 1; |
93 | |
94 | if (! strcmp(a[2],"-FX")) { |
95 | ipath = 3; |
96 | Option = GeomFill_IsFixed; |
97 | } |
98 | if (! strcmp(a[2],"-FR")) { |
99 | ipath = 3; |
100 | Option = GeomFill_IsFrenet; |
101 | } |
102 | if (! strcmp(a[2],"-CF")) { |
103 | ipath = 3; |
104 | Option = GeomFill_IsCorrectedFrenet; |
105 | } |
106 | if (! strcmp(a[2],"-CN")) { |
107 | ipath = 3; |
108 | isection = 7; |
109 | Option = GeomFill_IsConstantNormal; |
110 | } |
111 | if (! strcmp(a[2],"-DX")) { |
112 | ipath = 3; |
113 | isection = 5; |
114 | Option = GeomFill_IsDarboux; |
115 | } |
116 | |
117 | GeomFill_Pipe Pipe; |
118 | Pipe.GenerateParticularCase(Standard_True); |
119 | |
120 | if (Option == GeomFill_IsDarboux) { |
121 | Handle(Geom2d_Curve) path = DrawTrSurf::GetCurve2d(a[ipath]); |
122 | if ( path.IsNull()) return 1; |
123 | |
124 | Handle(Geom_Surface) Support = DrawTrSurf::GetSurface(a[ipath+1]); |
125 | if ( Support.IsNull()) return 1; |
126 | |
127 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+2]); |
128 | if ( firstS.IsNull()) return 1; |
129 | |
130 | Pipe.Init(path, Support, firstS); |
131 | } |
132 | else if (Option == GeomFill_IsConstantNormal) { |
91322f44 |
133 | gp_Dir D ( Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]) ); |
7fd59977 |
134 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[6]); |
135 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[7]); |
136 | Pipe.Init(path, firstS, D); |
137 | } |
138 | else { |
139 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[ipath]); |
140 | if ( path.IsNull()) return 1; |
141 | |
142 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+1]); |
143 | if ( firstS.IsNull()) return 1; |
144 | |
145 | Pipe.Init(path, firstS, Option); |
146 | } |
147 | |
148 | if (n >=isection+2) { |
91322f44 |
149 | MaxDegree = Draw::Atoi(a[isection+1]); |
150 | if (n >isection+2) NbSeg = Draw::Atoi(a[isection+2]); |
7fd59977 |
151 | } |
152 | |
153 | Pipe.Perform(Tol, Standard_False, GeomAbs_C2, MaxDegree, NbSeg); |
154 | |
155 | DrawTrSurf::Set(a[1], Pipe.Surface()); |
156 | return 0; |
157 | |
158 | } |
159 | //======================================================================= |
160 | //function : tuyau |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | static Standard_Integer tuyau (Draw_Interpretor&, |
165 | Standard_Integer n, const char** a) |
166 | { |
167 | if ( n < 4) return 1; |
168 | #if DEB |
169 | static Standard_Boolean AdvApprox_Debug = 1; |
170 | #endif |
171 | |
172 | GeomAbs_Shape Cont = GeomAbs_C2; |
173 | GeomFill_Pipe Pipe; |
174 | Pipe.GenerateParticularCase(Standard_True); |
175 | |
176 | Standard_Boolean Option_NS = Standard_False; |
177 | Standard_Integer indice_path = 2, narg = n; |
178 | if (! strcmp(a[1],"-NS")) { |
179 | Option_NS = Standard_True; |
180 | indice_path++; |
181 | narg--; |
182 | } |
183 | Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]); |
184 | if ( path.IsNull()) return 1; |
185 | |
186 | Standard_Integer isect = indice_path+1; |
187 | Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]); |
188 | if ( firstS.IsNull()) { |
189 | if ( narg == 4) { |
190 | // tuyau a rayon constant. |
91322f44 |
191 | Pipe.Init(path, Draw::Atof(a[isect])); |
7fd59977 |
192 | } |
193 | else |
194 | return 1; |
195 | } |
196 | else { |
197 | if ( narg == 4) { |
198 | // tuyau a section constante. |
199 | Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet); |
200 | } |
201 | else { |
202 | if ( narg == 5 && !Option_NS) { |
203 | // tuyau a section evolutive |
204 | Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]); |
205 | Cont = GeomAbs_C2; |
206 | Pipe.Init(path, firstS, lastS); |
207 | } |
208 | else { |
209 | // tuyau a N sections, N>=2 |
210 | TColGeom_SequenceOfCurve Seq; |
211 | Seq.Clear(); |
212 | Seq.Append(firstS); |
213 | for (Standard_Integer i=isect+1;i<n;i++) { |
214 | Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]); |
215 | Seq.Append(nextS); |
216 | } |
217 | Cont = GeomAbs_C2; |
218 | Pipe.Init(path, Seq); |
219 | } |
220 | } |
221 | } |
222 | |
223 | Pipe.Perform(1.e-4, Standard_False, Cont); |
224 | DrawTrSurf::Set(a[indice_path-1], Pipe.Surface()); |
225 | |
226 | return 0; |
227 | } |
228 | |
229 | //======================================================================= |
230 | //function : ruled |
231 | //purpose : |
232 | //======================================================================= |
233 | |
234 | static Standard_Integer ruled(Draw_Interpretor& di, |
235 | Standard_Integer n, const char** a) |
236 | { |
237 | if ( n < 4) return 1; |
238 | |
239 | Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]); |
240 | if ( C1.IsNull()) { |
241 | di << " C1 is not a Curve ==> Command failed" << "\n"; |
242 | return 1; |
243 | } |
244 | Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]); |
245 | if ( C2.IsNull()) { |
246 | di << " C2 is not a Curve ==> Command failed" << "\n"; |
247 | return 1; |
248 | } |
249 | |
250 | Handle(Geom_Surface) S = GeomFill::Surface(C1,C2); |
251 | if ( S.IsNull()) return 1; |
252 | |
253 | DrawTrSurf::Set(a[1],S); |
254 | return 0; |
255 | } |
256 | |
257 | //======================================================================= |
258 | //function : appsurf |
259 | //purpose : |
260 | //======================================================================= |
261 | |
262 | static Standard_Integer appsurf(Draw_Interpretor& di, |
263 | Standard_Integer n, const char** a) |
264 | { |
265 | if ( n < 4) return 1; |
266 | |
267 | GeomFill_SectionGenerator Section; |
268 | Standard_Integer i; |
269 | Handle(Geom_Curve) C; |
270 | for ( i = 2; i < n; i++) { |
271 | C = DrawTrSurf::GetCurve(a[i]); |
272 | if (C.IsNull()) |
273 | return 1; |
274 | Section.AddCurve(C); |
275 | } |
276 | |
277 | Section.Perform(Precision::PConfusion()); |
278 | |
279 | Handle(GeomFill_Line) Line = new GeomFill_Line(n-2); |
280 | Standard_Integer NbIt = 0; |
281 | GeomFill_AppSurf App( 3, 8, Precision::Confusion(), Precision::PConfusion(), |
282 | NbIt); |
283 | |
284 | App.Perform( Line, Section); |
285 | |
286 | if ( !App.IsDone()) { |
287 | di << " Approximation aux fraises " << "\n"; |
288 | } |
289 | |
290 | Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots; |
291 | App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots); |
292 | |
293 | Handle(Geom_BSplineSurface) GBS = new |
294 | Geom_BSplineSurface(App.SurfPoles(), |
295 | App.SurfWeights(), |
296 | App.SurfUKnots(), |
297 | App.SurfVKnots(), |
298 | App.SurfUMults(), |
299 | App.SurfVMults(), |
300 | App.UDegree(), |
301 | App.VDegree()); |
302 | |
303 | DrawTrSurf::Set(a[1],GBS); |
304 | return 0; |
305 | } |
306 | |
307 | static Standard_Integer fillcurves(Draw_Interpretor& di, |
308 | Standard_Integer n, const char** a) |
309 | { |
310 | if ( n < 6) return 1; |
311 | |
312 | Standard_Integer i; |
313 | Handle(Geom_Curve) aC; |
314 | Handle(Geom_BSplineCurve) C[4]; |
315 | for ( i = 2; i < 6; i++) { |
316 | aC = DrawTrSurf::GetCurve(a[i]); |
317 | if (aC.IsNull()) |
318 | return 1; |
319 | C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1); |
320 | } |
321 | |
322 | Standard_Integer ist = 2; |
323 | GeomFill_FillingStyle Style = GeomFill_CoonsStyle; |
91322f44 |
324 | if(n > 6) ist = Draw::Atoi(a[6]); |
7fd59977 |
325 | |
326 | if(ist == 1) Style = GeomFill_StretchStyle; |
327 | if(ist == 2) Style = GeomFill_CoonsStyle; |
328 | if(ist == 3) Style = GeomFill_CurvedStyle; |
329 | |
330 | GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style); |
331 | |
332 | const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface(); |
333 | DrawTrSurf::Set(a[1],GBS); |
334 | return 0; |
335 | } |
336 | |
337 | //======================================================================= |
338 | //function : SurfaceCommands |
339 | //purpose : |
340 | //======================================================================= |
341 | |
342 | |
343 | void GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands) |
344 | { |
345 | static Standard_Boolean loaded = Standard_False; |
346 | if (loaded) return; |
347 | loaded = Standard_True; |
348 | |
349 | DrawTrSurf::BasicCommands(theCommands); |
350 | |
351 | const char* g; |
352 | |
353 | g = "GEOMETRY surfaces creation"; |
354 | |
355 | |
356 | theCommands.Add("tuyau", |
357 | "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 ", |
358 | __FILE__, |
359 | tuyau,g); |
360 | |
361 | theCommands.Add("partuyau", |
362 | "tuyau result Path Curve/Radius [Curve2]\n the parametrization of the surface in the V direction will be as the Path", |
363 | __FILE__, |
364 | tuyau,g); |
365 | |
366 | 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" , |
367 | __FILE__, |
368 | sweep, g); |
369 | |
370 | theCommands.Add("ruled", |
371 | "ruled result C1 C2", |
372 | __FILE__, |
373 | ruled,g); |
374 | |
375 | theCommands.Add("appsurf", |
376 | "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves", |
377 | __FILE__, |
378 | appsurf,g); |
379 | |
380 | theCommands.Add("fillcurves", |
381 | "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves", |
382 | __FILE__, |
383 | fillcurves,g); |
384 | |
385 | } |
386 | |
387 | |
388 | |
389 | |