1 // Created on: 1997-04-15
2 // Created by: Joelle CHAUVET
3 // Copyright (c) 1997-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 #include <GeomliteTest.hxx>
18 #include <DrawTrSurf.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <Draw_Appli.hxx>
22 #include <Draw_Display.hxx>
24 #include <Precision.hxx>
25 #include <GeomLib.hxx>
27 #include <Geom2d_BezierCurve.hxx>
28 #include <Geom2d_BSplineCurve.hxx>
29 #include <Geom_BezierCurve.hxx>
30 #include <Geom_BezierSurface.hxx>
31 #include <Geom_BSplineCurve.hxx>
32 #include <Geom_BSplineSurface.hxx>
33 #include <Geom_BoundedCurve.hxx>
34 #include <Geom_BoundedSurface.hxx>
38 //#define strcasecmp strcmp Already defined
42 //=======================================================================
43 //function : extendcurve
45 //=======================================================================
47 static Standard_Integer extendcurve (Draw_Interpretor& di, Standard_Integer n, const char** a)
51 Handle(Geom_BoundedCurve) GB =
52 Handle(Geom_BoundedCurve)::DownCast(DrawTrSurf::GetCurve(a[1]));
54 di << "extendcurve needs a Bounded curve";
59 if ( !DrawTrSurf::GetPoint(a[2],P)) return 1;
60 Standard_Boolean apres = Standard_True;
62 if (strcmp(a[4], "B") == 0) {
63 apres = Standard_False ;
66 Standard_Integer cont=Draw::Atoi(a[3]);
67 GeomLib::ExtendCurveToPoint(GB,P,cont,apres);
68 DrawTrSurf::Set(a[1],GB);
72 //=======================================================================
73 //function : extendsurf
75 //=======================================================================
77 static Standard_Integer extendsurf (Draw_Interpretor& di, Standard_Integer n, const char** a)
81 Handle(Geom_BoundedSurface) GB =
82 Handle(Geom_BoundedSurface)::DownCast(DrawTrSurf::GetSurface(a[1]));
84 di << "extendsurf needs a Bounded surface";
87 Standard_Real chord=Draw::Atof(a[2]);
88 Standard_Integer cont=Draw::Atoi(a[3]);
89 Standard_Boolean enU = Standard_True, apres = Standard_True;
91 if (strcmp(a[4], "V") == 0) {
92 enU = Standard_False ;
94 if (strcmp(a[4], "B") == 0) {
95 apres = Standard_False ;
99 if (strcmp(a[5], "B") == 0) {
100 apres = Standard_False ;
105 GeomLib::ExtendSurfByLength(GB,chord,cont,enU,apres);
106 DrawTrSurf::Set(a[1],GB);
112 //=======================================================================
113 //function : samerange
115 //=======================================================================
117 static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
120 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
121 Handle(Geom2d_Curve) Res;
122 Standard_Real f, l, rf, rl;
123 f = Draw::Atof(a[3]);
124 l = Draw::Atof(a[4]);
125 rf = Draw::Atof(a[5]);
126 rl = Draw::Atof(a[6]);
128 GeomLib::SameRange(Precision::PConfusion(), C,
131 DrawTrSurf::Set(a[1],Res);
137 //=======================================================================
138 //function : setweight
139 //purpose : Changes a weight of a pole on B-spline curve/surface
140 //=======================================================================
142 static Standard_Integer setweight(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
146 std::cout << "Wrong parameters" << std::endl;
150 Standard_Integer anIndex1 = Draw::Atoi(a[2]);
151 Standard_Integer anIndex2 = n == 5 ? Draw::Atoi(a[3]) : 0;
152 Standard_Real aWeight = Draw::Atof(a[n-1]);
154 Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
155 if (!aBSplCurve.IsNull())
157 aBSplCurve->SetWeight(anIndex1, aWeight);
161 Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
162 if (!aBezCurve.IsNull())
164 aBezCurve->SetWeight(anIndex1, aWeight);
168 Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
169 if (!aBSplCurve2d.IsNull())
171 aBSplCurve2d->SetWeight(anIndex1, aWeight);
175 Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
176 if (!aBezCurve2d.IsNull())
178 aBezCurve2d->SetWeight(anIndex1, aWeight);
182 Handle(Geom_BSplineSurface) aBSplSurf = DrawTrSurf::GetBSplineSurface(a[1]);
183 Handle(Geom_BezierSurface) aBezSurf = DrawTrSurf::GetBezierSurface(a[1]);
184 if (n != 5 && (!aBSplSurf.IsNull() || !aBezSurf.IsNull()))
186 std::cout << "Incorrect parameters" << std::endl;
190 if (!aBSplSurf.IsNull())
192 aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
196 if (!aBezSurf.IsNull())
198 aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
202 std::cout << a[1] << " is not a B-spline nor a Bezier curve/surface" << std::endl;
206 //=======================================================================
207 //function : ModificationCommands
209 //=======================================================================
212 void GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
214 static Standard_Boolean loaded = Standard_False;
216 loaded = Standard_True;
218 DrawTrSurf::BasicCommands(theCommands);
222 g = "GEOMETRY Curves and Surfaces modification";
225 theCommands.Add("extendcurve",
226 "extendcurve name point cont [A(fter)/B(efore)]",
231 theCommands.Add("extendsurf",
232 "extendsurf name length cont [U/V] [A(fter)/B(efore)]",
237 theCommands.Add("chgrange",
238 "chgrange newname curve2d first last RequestedFirst RequestedLast ]",
242 theCommands.Add("setweight",
243 "setweight curve/surf index1 [index2] weight"
244 "\n\t\tchanges a weight of a pole of B-spline curve/surface (index2 is useful for surfaces only)",