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
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.
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.
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.
21 // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest
22 // Modified: Mon Jan 18 11:06:46 1999
23 // option -NS dans la commande tuyau pour distinguer les tuyaux
24 // a section evolutive des tuyaux a N sections avec N = 2
26 #include <GeometryTest.hxx>
27 #include <DrawTrSurf.hxx>
29 #include <Draw_Interpretor.hxx>
30 #include <Draw_Appli.hxx>
31 #include <Draw_Display.hxx>
33 #include <GeomAbs_SurfaceType.hxx>
34 #include <GeomAbs_IsoType.hxx>
35 #include <GeomAbs_Shape.hxx>
37 #include <Geom_BSplineSurface.hxx>
38 #include <Geom_BSplineCurve.hxx>
39 #include <GeomConvert.hxx>
42 #include <GeomAdaptor_Surface.hxx>
43 #include <GeomAdaptor_Curve.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
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>
55 #include <Precision.hxx>
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>
65 #include <DrawTrSurf_BezierSurface.hxx>
66 #include <DrawTrSurf_BSplineSurface.hxx>
70 //#define strcasecmp strcmp Already defined
71 Standard_IMPORT Draw_Viewer dout;
77 //=======================================================================
80 //=======================================================================
82 static Standard_Integer sweep (Draw_Interpretor&,
83 Standard_Integer n, const char** a)
85 GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet;
86 Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10;
87 Standard_Real Tol = 1.e-4;
89 static Standard_Boolean AdvApprox_Debug = 1;
94 if (! strcmp(a[2],"-FX")) {
96 Option = GeomFill_IsFixed;
98 if (! strcmp(a[2],"-FR")) {
100 Option = GeomFill_IsFrenet;
102 if (! strcmp(a[2],"-CF")) {
104 Option = GeomFill_IsCorrectedFrenet;
106 if (! strcmp(a[2],"-CN")) {
109 Option = GeomFill_IsConstantNormal;
111 if (! strcmp(a[2],"-DX")) {
114 Option = GeomFill_IsDarboux;
118 Pipe.GenerateParticularCase(Standard_True);
120 if (Option == GeomFill_IsDarboux) {
121 Handle(Geom2d_Curve) path = DrawTrSurf::GetCurve2d(a[ipath]);
122 if ( path.IsNull()) return 1;
124 Handle(Geom_Surface) Support = DrawTrSurf::GetSurface(a[ipath+1]);
125 if ( Support.IsNull()) return 1;
127 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+2]);
128 if ( firstS.IsNull()) return 1;
130 Pipe.Init(path, Support, firstS);
132 else if (Option == GeomFill_IsConstantNormal) {
133 gp_Dir D ( Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]) );
134 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[6]);
135 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[7]);
136 Pipe.Init(path, firstS, D);
139 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[ipath]);
140 if ( path.IsNull()) return 1;
142 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+1]);
143 if ( firstS.IsNull()) return 1;
145 Pipe.Init(path, firstS, Option);
148 if (n >=isection+2) {
149 MaxDegree = Draw::Atoi(a[isection+1]);
150 if (n >isection+2) NbSeg = Draw::Atoi(a[isection+2]);
153 Pipe.Perform(Tol, Standard_False, GeomAbs_C2, MaxDegree, NbSeg);
155 DrawTrSurf::Set(a[1], Pipe.Surface());
159 //=======================================================================
162 //=======================================================================
164 static Standard_Integer tuyau (Draw_Interpretor&,
165 Standard_Integer n, const char** a)
167 if ( n < 4) return 1;
169 static Standard_Boolean AdvApprox_Debug = 1;
172 GeomAbs_Shape Cont = GeomAbs_C2;
174 Pipe.GenerateParticularCase(Standard_True);
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;
183 Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]);
184 if ( path.IsNull()) return 1;
186 Standard_Integer isect = indice_path+1;
187 Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]);
188 if ( firstS.IsNull()) {
190 // tuyau a rayon constant.
191 Pipe.Init(path, Draw::Atof(a[isect]));
198 // tuyau a section constante.
199 Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet);
202 if ( narg == 5 && !Option_NS) {
203 // tuyau a section evolutive
204 Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]);
206 Pipe.Init(path, firstS, lastS);
209 // tuyau a N sections, N>=2
210 TColGeom_SequenceOfCurve Seq;
213 for (Standard_Integer i=isect+1;i<n;i++) {
214 Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]);
218 Pipe.Init(path, Seq);
223 Pipe.Perform(1.e-4, Standard_False, Cont);
224 DrawTrSurf::Set(a[indice_path-1], Pipe.Surface());
229 //=======================================================================
232 //=======================================================================
234 static Standard_Integer ruled(Draw_Interpretor& di,
235 Standard_Integer n, const char** a)
237 if ( n < 4) return 1;
239 Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]);
241 di << " C1 is not a Curve ==> Command failed" << "\n";
244 Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]);
246 di << " C2 is not a Curve ==> Command failed" << "\n";
250 Handle(Geom_Surface) S = GeomFill::Surface(C1,C2);
251 if ( S.IsNull()) return 1;
253 DrawTrSurf::Set(a[1],S);
257 //=======================================================================
260 //=======================================================================
262 static Standard_Integer appsurf(Draw_Interpretor& di,
263 Standard_Integer n, const char** a)
265 if ( n < 4) return 1;
267 GeomFill_SectionGenerator Section;
269 Handle(Geom_Curve) C;
270 for ( i = 2; i < n; i++) {
271 C = DrawTrSurf::GetCurve(a[i]);
277 Section.Perform(Precision::PConfusion());
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(),
284 App.Perform( Line, Section);
286 if ( !App.IsDone()) {
287 di << " Approximation aux fraises " << "\n";
290 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
291 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
293 Handle(Geom_BSplineSurface) GBS = new
294 Geom_BSplineSurface(App.SurfPoles(),
303 DrawTrSurf::Set(a[1],GBS);
307 static Standard_Integer fillcurves(Draw_Interpretor& /*di*/,
308 Standard_Integer n, const char** a)
310 if ( n < 6) return 1;
313 Handle(Geom_Curve) aC;
314 Handle(Geom_BSplineCurve) C[4];
315 for ( i = 2; i < 6; i++) {
316 aC = DrawTrSurf::GetCurve(a[i]);
319 C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1);
322 Standard_Integer ist = 2;
323 GeomFill_FillingStyle Style = GeomFill_CoonsStyle;
324 if(n > 6) ist = Draw::Atoi(a[6]);
326 if(ist == 1) Style = GeomFill_StretchStyle;
327 if(ist == 2) Style = GeomFill_CoonsStyle;
328 if(ist == 3) Style = GeomFill_CurvedStyle;
330 GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style);
332 const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface();
333 DrawTrSurf::Set(a[1],GBS);
337 //=======================================================================
338 //function : SurfaceCommands
340 //=======================================================================
343 void GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands)
345 static Standard_Boolean loaded = Standard_False;
347 loaded = Standard_True;
349 DrawTrSurf::BasicCommands(theCommands);
353 g = "GEOMETRY surfaces creation";
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 ",
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",
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" ,
370 theCommands.Add("ruled",
371 "ruled result C1 C2",
375 theCommands.Add("appsurf",
376 "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves",
380 theCommands.Add("fillcurves",
381 "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves",