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>
36 //#define strcasecmp strcmp Already defined
40 //=======================================================================
41 //function : extendcurve
43 //=======================================================================
45 static Standard_Integer extendcurve (Draw_Interpretor& di, Standard_Integer n, const char** a)
49 Handle(Geom_BoundedCurve) GB =
50 Handle(Geom_BoundedCurve)::DownCast(DrawTrSurf::GetCurve(a[1]));
52 di << "extendcurve needs a Bounded curve";
57 if ( !DrawTrSurf::GetPoint(a[2],P)) return 1;
58 Standard_Boolean apres = Standard_True;
60 if (strcmp(a[4], "B") == 0) {
61 apres = Standard_False ;
64 Standard_Integer cont=Draw::Atoi(a[3]);
65 GeomLib::ExtendCurveToPoint(GB,P,cont,apres);
66 DrawTrSurf::Set(a[1],GB);
70 //=======================================================================
71 //function : extendsurf
73 //=======================================================================
75 static Standard_Integer extendsurf (Draw_Interpretor& di, Standard_Integer n, const char** a)
79 Handle(Geom_BoundedSurface) GB =
80 Handle(Geom_BoundedSurface)::DownCast(DrawTrSurf::GetSurface(a[1]));
82 di << "extendsurf needs a Bounded surface";
85 Standard_Real chord=Draw::Atof(a[2]);
86 Standard_Integer cont=Draw::Atoi(a[3]);
87 Standard_Boolean enU = Standard_True, apres = Standard_True;
89 if (strcmp(a[4], "V") == 0) {
90 enU = Standard_False ;
92 if (strcmp(a[4], "B") == 0) {
93 apres = Standard_False ;
97 if (strcmp(a[5], "B") == 0) {
98 apres = Standard_False ;
103 GeomLib::ExtendSurfByLength(GB,chord,cont,enU,apres);
104 DrawTrSurf::Set(a[1],GB);
110 //=======================================================================
111 //function : samerange
113 //=======================================================================
115 static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
118 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
119 Handle(Geom2d_Curve) Res;
120 Standard_Real f, l, rf, rl;
121 f = Draw::Atof(a[3]);
122 l = Draw::Atof(a[4]);
123 rf = Draw::Atof(a[5]);
124 rl = Draw::Atof(a[6]);
126 GeomLib::SameRange(Precision::PConfusion(), C,
129 DrawTrSurf::Set(a[1],Res);
135 //=======================================================================
136 //function : setweight
137 //purpose : Changes a weight of a pole on B-spline curve/surface
138 //=======================================================================
140 static Standard_Integer setweight(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
144 std::cout << "Wrong parameters" << std::endl;
148 Standard_Integer anIndex1 = Draw::Atoi(a[2]);
149 Standard_Integer anIndex2 = n == 5 ? Draw::Atoi(a[3]) : 0;
150 Standard_Real aWeight = Draw::Atof(a[n-1]);
152 Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
153 if (!aBSplCurve.IsNull())
155 aBSplCurve->SetWeight(anIndex1, aWeight);
159 Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
160 if (!aBezCurve.IsNull())
162 aBezCurve->SetWeight(anIndex1, aWeight);
166 Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
167 if (!aBSplCurve2d.IsNull())
169 aBSplCurve2d->SetWeight(anIndex1, aWeight);
173 Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
174 if (!aBezCurve2d.IsNull())
176 aBezCurve2d->SetWeight(anIndex1, aWeight);
180 Handle(Geom_BSplineSurface) aBSplSurf = DrawTrSurf::GetBSplineSurface(a[1]);
181 Handle(Geom_BezierSurface) aBezSurf = DrawTrSurf::GetBezierSurface(a[1]);
182 if (n != 5 && (!aBSplSurf.IsNull() || !aBezSurf.IsNull()))
184 std::cout << "Incorrect parameters" << std::endl;
188 if (!aBSplSurf.IsNull())
190 aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
194 if (!aBezSurf.IsNull())
196 aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
200 std::cout << a[1] << " is not a B-spline nor a Bezier curve/surface" << std::endl;
204 //=======================================================================
205 //function : ModificationCommands
207 //=======================================================================
210 void GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
212 static Standard_Boolean loaded = Standard_False;
214 loaded = Standard_True;
216 DrawTrSurf::BasicCommands(theCommands);
220 g = "GEOMETRY Curves and Surfaces modification";
223 theCommands.Add("extendcurve",
224 "extendcurve name point cont [A(fter)/B(efore)]",
229 theCommands.Add("extendsurf",
230 "extendsurf name length cont [U/V] [A(fter)/B(efore)]",
235 theCommands.Add("chgrange",
236 "chgrange newname curve2d first last RequestedFirst RequestedLast ]",
240 theCommands.Add("setweight",
241 "setweight curve/surf index1 [index2] weight"
242 "\n\t\tchanges a weight of a pole of B-spline curve/surface (index2 is useful for surfaces only)",