1 // Created on: 1993-08-12
2 // Created by: Joelle CHAUVET
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest
18 // Modified: Mon Jan 18 11:06:46 1999
19 // option -NS dans la commande tuyau pour distinguer les tuyaux
20 // a section evolutive des tuyaux a N sections avec N = 2
22 #include <GeometryTest.hxx>
23 #include <DrawTrSurf.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <Draw_Appli.hxx>
27 #include <Draw_Display.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
30 #include <GeomAbs_IsoType.hxx>
31 #include <GeomAbs_Shape.hxx>
33 #include <Geom_BSplineSurface.hxx>
34 #include <Geom_BSplineCurve.hxx>
35 #include <GeomConvert.hxx>
38 #include <GeomAdaptor_Surface.hxx>
39 #include <GeomAdaptor_Curve.hxx>
40 #include <Geom2dAdaptor_Curve.hxx>
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>
51 #include <Precision.hxx>
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>
61 #include <DrawTrSurf_BezierSurface.hxx>
62 #include <DrawTrSurf_BSplineSurface.hxx>
66 //#define strcasecmp strcmp Already defined
70 Standard_IMPORT Draw_Viewer dout;
76 //=======================================================================
79 //=======================================================================
81 static Standard_Integer sweep (Draw_Interpretor& di,
82 Standard_Integer n, const char** a)
84 GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet;
85 Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10;
86 Standard_Real Tol = 1.e-4;
90 if (! strcmp(a[2],"-FX")) {
92 Option = GeomFill_IsFixed;
94 if (! strcmp(a[2],"-FR")) {
96 Option = GeomFill_IsFrenet;
98 if (! strcmp(a[2],"-CF")) {
100 Option = GeomFill_IsCorrectedFrenet;
102 if (! strcmp(a[2],"-CN")) {
105 Option = GeomFill_IsConstantNormal;
107 if (! strcmp(a[2],"-DX")) {
110 Option = GeomFill_IsDarboux;
114 Pipe.GenerateParticularCase(Standard_True);
116 if (Option == GeomFill_IsDarboux) {
117 Handle(Geom2d_Curve) path = DrawTrSurf::GetCurve2d(a[ipath]);
118 if ( path.IsNull()) return 1;
120 Handle(Geom_Surface) Support = DrawTrSurf::GetSurface(a[ipath+1]);
121 if ( Support.IsNull()) return 1;
123 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+2]);
124 if ( firstS.IsNull()) return 1;
126 Pipe.Init(path, Support, firstS);
128 else if (Option == GeomFill_IsConstantNormal) {
129 gp_Dir D ( Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]) );
130 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[6]);
131 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[7]);
132 Pipe.Init(path, firstS, D);
135 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[ipath]);
136 if ( path.IsNull()) return 1;
138 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+1]);
139 if ( firstS.IsNull()) return 1;
141 Pipe.Init(path, firstS, Option);
144 if (n >=isection+2) {
145 MaxDegree = Draw::Atoi(a[isection+1]);
146 if (n >isection+2) NbSeg = Draw::Atoi(a[isection+2]);
149 Pipe.Perform(Tol, Standard_False, GeomAbs_C2, MaxDegree, NbSeg);
151 if (!Pipe.IsDone()) {
152 di << "GeomFill_Pipe cannot make a surface\n";
156 Standard_Real Accuracy = Pipe.ErrorOnSurf();
157 di << "Accuracy of approximation = " << Accuracy << "\n";
159 DrawTrSurf::Set(a[1], Pipe.Surface());
163 //=======================================================================
166 //=======================================================================
168 static Standard_Integer tuyau (Draw_Interpretor& di,
169 Standard_Integer n, const char** a)
171 if ( n < 4) return 1;
173 GeomAbs_Shape Cont = GeomAbs_C2;
175 Pipe.GenerateParticularCase(Standard_True);
177 Standard_Boolean Option_NS = Standard_False;
178 Standard_Integer indice_path = 2, narg = n;
179 if (! strcmp(a[1],"-NS")) {
180 Option_NS = Standard_True;
184 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]);
185 if ( path.IsNull()) return 1;
187 Standard_Integer isect = indice_path+1;
188 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]);
189 if ( firstS.IsNull()) {
191 // tuyau a rayon constant.
192 Pipe.Init(path, Draw::Atof(a[isect]));
199 // tuyau a section constante.
200 Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet);
203 if ( narg == 5 && !Option_NS) {
204 // tuyau a section evolutive
205 Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]);
207 Pipe.Init(path, firstS, lastS);
210 // tuyau a N sections, N>=2
211 TColGeom_SequenceOfCurve Seq;
214 for (Standard_Integer i=isect+1;i<n;i++) {
215 Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]);
219 Pipe.Init(path, Seq);
224 Pipe.Perform(1.e-4, Standard_False, Cont);
225 if (!Pipe.IsDone()) {
226 di << "GeomFill_Pipe cannot make a surface\n";
230 Standard_Real Accuracy = Pipe.ErrorOnSurf();
231 di << "Accuracy of approximation = " << Accuracy << "\n";
233 DrawTrSurf::Set(a[indice_path-1], Pipe.Surface());
238 //=======================================================================
241 //=======================================================================
243 static Standard_Integer ruled(Draw_Interpretor& di,
244 Standard_Integer n, const char** a)
246 if ( n < 4) return 1;
248 Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]);
250 di << " C1 is not a Curve ==> Command failed\n";
253 Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]);
255 di << " C2 is not a Curve ==> Command failed\n";
259 Handle(Geom_Surface) S = GeomFill::Surface(C1,C2);
260 if ( S.IsNull()) return 1;
262 DrawTrSurf::Set(a[1],S);
266 //=======================================================================
269 //=======================================================================
271 static Standard_Integer appsurf(Draw_Interpretor& di,
272 Standard_Integer n, const char** a)
274 if ( n < 4) return 1;
276 GeomFill_SectionGenerator Section;
278 Handle(Geom_Curve) C;
279 for ( i = 2; i < n; i++) {
280 C = DrawTrSurf::GetCurve(a[i]);
286 Section.Perform(Precision::PConfusion());
288 Handle(GeomFill_Line) Line = new GeomFill_Line(n-2);
289 Standard_Integer NbIt = 0;
290 GeomFill_AppSurf App( 3, 8, Precision::Confusion(), Precision::PConfusion(),
293 App.Perform( Line, Section);
295 if ( !App.IsDone()) {
296 di << " Approximation aux fraises \n";
299 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
300 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
302 Handle(Geom_BSplineSurface) GBS = new
303 Geom_BSplineSurface(App.SurfPoles(),
312 DrawTrSurf::Set(a[1],GBS);
316 static Standard_Integer fillcurves(Draw_Interpretor& /*di*/,
317 Standard_Integer n, const char** a)
319 if ( n < 6) return 1;
322 Handle(Geom_Curve) aC;
323 Handle(Geom_BSplineCurve) C[4];
324 for ( i = 2; i < 6; i++) {
325 aC = DrawTrSurf::GetCurve(a[i]);
328 C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1);
331 Standard_Integer ist = 2;
332 GeomFill_FillingStyle Style = GeomFill_CoonsStyle;
333 if(n > 6) ist = Draw::Atoi(a[6]);
335 if(ist == 1) Style = GeomFill_StretchStyle;
336 if(ist == 2) Style = GeomFill_CoonsStyle;
337 if(ist == 3) Style = GeomFill_CurvedStyle;
339 GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style);
341 const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface();
342 DrawTrSurf::Set(a[1],GBS);
347 //=======================================================================
348 //function : GetSurfaceContinuity
349 //purpose : Returns the continuity of the given surface
350 //=======================================================================
351 static Standard_Integer GetSurfaceContinuity( Draw_Interpretor& theDI,
352 Standard_Integer theNArg,
353 const char** theArgv)
357 theDI << "Use: getsurfcontinuity surface\n";
361 Handle(Geom_Surface) GS1 = DrawTrSurf::GetSurface(theArgv[1]);
364 theDI << "Argument is not a surface!\n";
368 char aContName[7][3] = {"C0", //0
376 theDI << theArgv[1] << " has " << aContName[GS1->Continuity()] << " continuity.\n";
382 //=======================================================================
383 //function : SurfaceCommands
385 //=======================================================================
388 void GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands)
390 static Standard_Boolean loaded = Standard_False;
392 loaded = Standard_True;
394 DrawTrSurf::BasicCommands(theCommands);
398 g = "GEOMETRY surfaces creation";
401 theCommands.Add("tuyau",
402 "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 ",
406 theCommands.Add("partuyau",
407 "tuyau result Path Curve/Radius [Curve2]\n the parametrization of the surface in the V direction will be as the Path",
411 theCommands.Add("sweep", "sweep result [options] path [Surf] curve [Tol [nbsegment]]\n sweep 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" ,
415 theCommands.Add("ruled",
416 "ruled result C1 C2",
420 theCommands.Add("appsurf",
421 "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves",
425 theCommands.Add("fillcurves",
426 "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves",
430 theCommands.Add("getsurfcontinuity",
431 "getsurfcontinuity surface: \n\tReturns the continuity of the given surface",
433 GetSurfaceContinuity,g);