0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / GeomliteTest / GeomliteTest_ModificationCommands.cxx
CommitLineData
b311480e 1// Created on: 1997-04-15
2// Created by: Joelle CHAUVET
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <GeomliteTest.hxx>
18#include <DrawTrSurf.hxx>
19#include <Draw.hxx>
20#include <Draw_Interpretor.hxx>
21#include <Draw_Appli.hxx>
22#include <Draw_Display.hxx>
23
24#include <Precision.hxx>
25#include <GeomLib.hxx>
26
52ba6031 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>
ec357c5c 33#include <Geom_BoundedCurve.hxx>
34#include <Geom_BoundedSurface.hxx>
52ba6031 35
57c28b61 36#ifdef _MSC_VER
7fd59977 37#include <stdio.h>
38//#define strcasecmp strcmp Already defined
39#endif
40
41
42//=======================================================================
43//function : extendcurve
44//purpose :
45//=======================================================================
46
47static Standard_Integer extendcurve (Draw_Interpretor& di, Standard_Integer n, const char** a)
48{
49 if (n < 4) return 1;
50
51 Handle(Geom_BoundedCurve) GB =
52 Handle(Geom_BoundedCurve)::DownCast(DrawTrSurf::GetCurve(a[1]));
53 if (GB.IsNull()) {
54 di << "extendcurve needs a Bounded curve";
55 return 1;
56 }
57
58 gp_Pnt P;
59 if ( !DrawTrSurf::GetPoint(a[2],P)) return 1;
60 Standard_Boolean apres = Standard_True;
61 if (n == 5) {
62 if (strcmp(a[4], "B") == 0) {
63 apres = Standard_False ;
64 }
65 }
91322f44 66 Standard_Integer cont=Draw::Atoi(a[3]);
7fd59977 67 GeomLib::ExtendCurveToPoint(GB,P,cont,apres);
68 DrawTrSurf::Set(a[1],GB);
69 return 0;
70}
71
72//=======================================================================
73//function : extendsurf
74//purpose :
75//=======================================================================
76
77static Standard_Integer extendsurf (Draw_Interpretor& di, Standard_Integer n, const char** a)
78{
79 if (n < 4) return 1;
80
81 Handle(Geom_BoundedSurface) GB =
82 Handle(Geom_BoundedSurface)::DownCast(DrawTrSurf::GetSurface(a[1]));
83 if (GB.IsNull()) {
84 di << "extendsurf needs a Bounded surface";
85 return 1;
86 }
91322f44 87 Standard_Real chord=Draw::Atof(a[2]);
88 Standard_Integer cont=Draw::Atoi(a[3]);
7fd59977 89 Standard_Boolean enU = Standard_True, apres = Standard_True;
90 if (n >= 5) {
91 if (strcmp(a[4], "V") == 0) {
92 enU = Standard_False ;
93 }
94 if (strcmp(a[4], "B") == 0) {
95 apres = Standard_False ;
96 }
97 }
98 if (n == 6) {
99 if (strcmp(a[5], "B") == 0) {
100 apres = Standard_False ;
101 }
102 }
103
104
105 GeomLib::ExtendSurfByLength(GB,chord,cont,enU,apres);
106 DrawTrSurf::Set(a[1],GB);
107
108 return 0;
109}
110
111
112//=======================================================================
113//function : samerange
114//purpose :
115//=======================================================================
116
35e08fe8 117static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
7fd59977 118{
119 if (n < 6) return 1;
120 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
121 Handle(Geom2d_Curve) Res;
122 Standard_Real f, l, rf, rl;
91322f44 123 f = Draw::Atof(a[3]);
124 l = Draw::Atof(a[4]);
125 rf = Draw::Atof(a[5]);
126 rl = Draw::Atof(a[6]);
7fd59977 127
128 GeomLib::SameRange(Precision::PConfusion(), C,
129 f, l, rf, rl, Res);
130
131 DrawTrSurf::Set(a[1],Res);
132
133 return 0;
134
135}
136
137//=======================================================================
52ba6031 138//function : setweight
139//purpose : Changes a weight of a pole on B-spline curve/surface
140//=======================================================================
141
76eeac70 142static Standard_Integer setweight(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
52ba6031 143{
144 if (n < 4 || n > 5)
145 {
146 std::cout << "Wrong parameters" << std::endl;
147 return 1;
148 }
149
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]);
153
154 Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
155 if (!aBSplCurve.IsNull())
156 {
157 aBSplCurve->SetWeight(anIndex1, aWeight);
158 return 0;
159 }
160
161 Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
162 if (!aBezCurve.IsNull())
163 {
164 aBezCurve->SetWeight(anIndex1, aWeight);
165 return 0;
166 }
167
168 Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
169 if (!aBSplCurve2d.IsNull())
170 {
171 aBSplCurve2d->SetWeight(anIndex1, aWeight);
172 return 0;
173 }
174
175 Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
176 if (!aBezCurve2d.IsNull())
177 {
178 aBezCurve2d->SetWeight(anIndex1, aWeight);
179 return 0;
180 }
181
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()))
185 {
186 std::cout << "Incorrect parameters" << std::endl;
187 return 1;
188 }
189
190 if (!aBSplSurf.IsNull())
191 {
192 aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
193 return 0;
194 }
195
196 if (!aBezSurf.IsNull())
197 {
198 aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
199 return 0;
200 }
201
202 std::cout << a[1] << " is not a B-spline nor a Bezier curve/surface" << std::endl;
203 return 1;
204}
205
206//=======================================================================
7fd59977 207//function : ModificationCommands
208//purpose :
209//=======================================================================
210
211
212void GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
213{
214 static Standard_Boolean loaded = Standard_False;
215 if (loaded) return;
216 loaded = Standard_True;
217
218 DrawTrSurf::BasicCommands(theCommands);
219
220 const char* g;
221
222 g = "GEOMETRY Curves and Surfaces modification";
223
224
225 theCommands.Add("extendcurve",
226 "extendcurve name point cont [A(fter)/B(efore)]",
227 __FILE__,
228 extendcurve , g);
229
230
231 theCommands.Add("extendsurf",
232 "extendsurf name length cont [U/V] [A(fter)/B(efore)]",
233 __FILE__,
234 extendsurf, g);
235
236
237 theCommands.Add("chgrange",
238 "chgrange newname curve2d first last RequestedFirst RequestedLast ]",
239 __FILE__,
240 samerange, g);
241
52ba6031 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)",
245 __FILE__,
246 setweight,g);
247
7fd59977 248}
249
250
251
252