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>
35 #include <Message.hxx>
39 //#define strcasecmp strcmp Already defined
43 //=======================================================================
44 //function : extendcurve
46 //=======================================================================
48 static Standard_Integer extendcurve (Draw_Interpretor& di, Standard_Integer n, const char** a)
52 Handle(Geom_BoundedCurve) GB =
53 Handle(Geom_BoundedCurve)::DownCast(DrawTrSurf::GetCurve(a[1]));
55 di << "extendcurve needs a Bounded curve";
60 if ( !DrawTrSurf::GetPoint(a[2],P)) return 1;
61 Standard_Boolean apres = Standard_True;
63 if (strcmp(a[4], "B") == 0) {
64 apres = Standard_False ;
67 Standard_Integer cont=Draw::Atoi(a[3]);
68 GeomLib::ExtendCurveToPoint(GB,P,cont,apres);
69 DrawTrSurf::Set(a[1],GB);
73 //=======================================================================
74 //function : extendsurf
76 //=======================================================================
78 static Standard_Integer extendsurf (Draw_Interpretor& di, Standard_Integer n, const char** a)
82 Handle(Geom_BoundedSurface) GB =
83 Handle(Geom_BoundedSurface)::DownCast(DrawTrSurf::GetSurface(a[1]));
85 di << "extendsurf needs a Bounded surface";
88 Standard_Real chord=Draw::Atof(a[2]);
89 Standard_Integer cont=Draw::Atoi(a[3]);
90 Standard_Boolean enU = Standard_True, apres = Standard_True;
92 if (strcmp(a[4], "V") == 0) {
93 enU = Standard_False ;
95 if (strcmp(a[4], "B") == 0) {
96 apres = Standard_False ;
100 if (strcmp(a[5], "B") == 0) {
101 apres = Standard_False ;
106 GeomLib::ExtendSurfByLength(GB,chord,cont,enU,apres);
107 DrawTrSurf::Set(a[1],GB);
113 //=======================================================================
114 //function : samerange
116 //=======================================================================
118 static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
121 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
122 Handle(Geom2d_Curve) Res;
123 Standard_Real f, l, rf, rl;
124 f = Draw::Atof(a[3]);
125 l = Draw::Atof(a[4]);
126 rf = Draw::Atof(a[5]);
127 rl = Draw::Atof(a[6]);
129 GeomLib::SameRange(Precision::PConfusion(), C,
132 DrawTrSurf::Set(a[1],Res);
138 //=======================================================================
139 //function : setweight
140 //purpose : Changes a weight of a pole on B-spline curve/surface
141 //=======================================================================
143 static Standard_Integer setweight(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
147 Message::SendFail() << "Syntax error: Wrong parameters";
151 Standard_Integer anIndex1 = Draw::Atoi(a[2]);
152 Standard_Integer anIndex2 = n == 5 ? Draw::Atoi(a[3]) : 0;
153 Standard_Real aWeight = Draw::Atof(a[n-1]);
155 Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
156 if (!aBSplCurve.IsNull())
158 aBSplCurve->SetWeight(anIndex1, aWeight);
162 Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
163 if (!aBezCurve.IsNull())
165 aBezCurve->SetWeight(anIndex1, aWeight);
169 Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
170 if (!aBSplCurve2d.IsNull())
172 aBSplCurve2d->SetWeight(anIndex1, aWeight);
176 Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
177 if (!aBezCurve2d.IsNull())
179 aBezCurve2d->SetWeight(anIndex1, aWeight);
183 Handle(Geom_BSplineSurface) aBSplSurf = DrawTrSurf::GetBSplineSurface(a[1]);
184 Handle(Geom_BezierSurface) aBezSurf = DrawTrSurf::GetBezierSurface(a[1]);
185 if (n != 5 && (!aBSplSurf.IsNull() || !aBezSurf.IsNull()))
187 Message::SendFail() << "Syntax error: Incorrect parameters";
191 if (!aBSplSurf.IsNull())
193 aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
197 if (!aBezSurf.IsNull())
199 aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
203 Message::SendFail() << a[1] << " is not a B-spline nor a Bezier curve/surface";
207 //=======================================================================
208 //function : ModificationCommands
210 //=======================================================================
213 void GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
215 static Standard_Boolean loaded = Standard_False;
217 loaded = Standard_True;
219 DrawTrSurf::BasicCommands(theCommands);
223 g = "GEOMETRY Curves and Surfaces modification";
226 theCommands.Add("extendcurve",
227 "extendcurve name point cont [A(fter)/B(efore)]",
232 theCommands.Add("extendsurf",
233 "extendsurf name length cont [U/V] [A(fter)/B(efore)]",
238 theCommands.Add("chgrange",
239 "chgrange newname curve2d first last RequestedFirst RequestedLast ]",
243 theCommands.Add("setweight",
244 "setweight curve/surf index1 [index2] weight"
245 "\n\t\tchanges a weight of a pole of B-spline curve/surface (index2 is useful for surfaces only)",