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
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.
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
67 Standard_IMPORT Draw_Viewer dout;
73 //=======================================================================
76 //=======================================================================
78 static Standard_Integer sweep (Draw_Interpretor&,
79 Standard_Integer n, const char** a)
81 GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet;
82 Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10;
83 Standard_Real Tol = 1.e-4;
85 static Standard_Boolean AdvApprox_Debug = 1;
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 DrawTrSurf::Set(a[1], Pipe.Surface());
155 //=======================================================================
158 //=======================================================================
160 static Standard_Integer tuyau (Draw_Interpretor&,
161 Standard_Integer n, const char** a)
163 if ( n < 4) return 1;
165 static Standard_Boolean AdvApprox_Debug = 1;
168 GeomAbs_Shape Cont = GeomAbs_C2;
170 Pipe.GenerateParticularCase(Standard_True);
172 Standard_Boolean Option_NS = Standard_False;
173 Standard_Integer indice_path = 2, narg = n;
174 if (! strcmp(a[1],"-NS")) {
175 Option_NS = Standard_True;
179 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]);
180 if ( path.IsNull()) return 1;
182 Standard_Integer isect = indice_path+1;
183 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]);
184 if ( firstS.IsNull()) {
186 // tuyau a rayon constant.
187 Pipe.Init(path, Draw::Atof(a[isect]));
194 // tuyau a section constante.
195 Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet);
198 if ( narg == 5 && !Option_NS) {
199 // tuyau a section evolutive
200 Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]);
202 Pipe.Init(path, firstS, lastS);
205 // tuyau a N sections, N>=2
206 TColGeom_SequenceOfCurve Seq;
209 for (Standard_Integer i=isect+1;i<n;i++) {
210 Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]);
214 Pipe.Init(path, Seq);
219 Pipe.Perform(1.e-4, Standard_False, Cont);
220 DrawTrSurf::Set(a[indice_path-1], Pipe.Surface());
225 //=======================================================================
228 //=======================================================================
230 static Standard_Integer ruled(Draw_Interpretor& di,
231 Standard_Integer n, const char** a)
233 if ( n < 4) return 1;
235 Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]);
237 di << " C1 is not a Curve ==> Command failed" << "\n";
240 Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]);
242 di << " C2 is not a Curve ==> Command failed" << "\n";
246 Handle(Geom_Surface) S = GeomFill::Surface(C1,C2);
247 if ( S.IsNull()) return 1;
249 DrawTrSurf::Set(a[1],S);
253 //=======================================================================
256 //=======================================================================
258 static Standard_Integer appsurf(Draw_Interpretor& di,
259 Standard_Integer n, const char** a)
261 if ( n < 4) return 1;
263 GeomFill_SectionGenerator Section;
265 Handle(Geom_Curve) C;
266 for ( i = 2; i < n; i++) {
267 C = DrawTrSurf::GetCurve(a[i]);
273 Section.Perform(Precision::PConfusion());
275 Handle(GeomFill_Line) Line = new GeomFill_Line(n-2);
276 Standard_Integer NbIt = 0;
277 GeomFill_AppSurf App( 3, 8, Precision::Confusion(), Precision::PConfusion(),
280 App.Perform( Line, Section);
282 if ( !App.IsDone()) {
283 di << " Approximation aux fraises " << "\n";
286 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
287 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
289 Handle(Geom_BSplineSurface) GBS = new
290 Geom_BSplineSurface(App.SurfPoles(),
299 DrawTrSurf::Set(a[1],GBS);
303 static Standard_Integer fillcurves(Draw_Interpretor& /*di*/,
304 Standard_Integer n, const char** a)
306 if ( n < 6) return 1;
309 Handle(Geom_Curve) aC;
310 Handle(Geom_BSplineCurve) C[4];
311 for ( i = 2; i < 6; i++) {
312 aC = DrawTrSurf::GetCurve(a[i]);
315 C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1);
318 Standard_Integer ist = 2;
319 GeomFill_FillingStyle Style = GeomFill_CoonsStyle;
320 if(n > 6) ist = Draw::Atoi(a[6]);
322 if(ist == 1) Style = GeomFill_StretchStyle;
323 if(ist == 2) Style = GeomFill_CoonsStyle;
324 if(ist == 3) Style = GeomFill_CurvedStyle;
326 GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style);
328 const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface();
329 DrawTrSurf::Set(a[1],GBS);
333 //=======================================================================
334 //function : SurfaceCommands
336 //=======================================================================
339 void GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands)
341 static Standard_Boolean loaded = Standard_False;
343 loaded = Standard_True;
345 DrawTrSurf::BasicCommands(theCommands);
349 g = "GEOMETRY surfaces creation";
352 theCommands.Add("tuyau",
353 "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 ",
357 theCommands.Add("partuyau",
358 "tuyau result Path Curve/Radius [Curve2]\n the parametrization of the surface in the V direction will be as the Path",
362 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" ,
366 theCommands.Add("ruled",
367 "ruled result C1 C2",
371 theCommands.Add("appsurf",
372 "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves",
376 theCommands.Add("fillcurves",
377 "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves",