0025582: SIGSEGV in thrusections of circle segments
[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>
33
7fd59977 34#ifdef WNT
35#include <stdio.h>
36//#define strcasecmp strcmp Already defined
37#endif
38
39
40//=======================================================================
41//function : extendcurve
42//purpose :
43//=======================================================================
44
45static Standard_Integer extendcurve (Draw_Interpretor& di, Standard_Integer n, const char** a)
46{
47 if (n < 4) return 1;
48
49 Handle(Geom_BoundedCurve) GB =
50 Handle(Geom_BoundedCurve)::DownCast(DrawTrSurf::GetCurve(a[1]));
51 if (GB.IsNull()) {
52 di << "extendcurve needs a Bounded curve";
53 return 1;
54 }
55
56 gp_Pnt P;
57 if ( !DrawTrSurf::GetPoint(a[2],P)) return 1;
58 Standard_Boolean apres = Standard_True;
59 if (n == 5) {
60 if (strcmp(a[4], "B") == 0) {
61 apres = Standard_False ;
62 }
63 }
91322f44 64 Standard_Integer cont=Draw::Atoi(a[3]);
7fd59977 65 GeomLib::ExtendCurveToPoint(GB,P,cont,apres);
66 DrawTrSurf::Set(a[1],GB);
67 return 0;
68}
69
70//=======================================================================
71//function : extendsurf
72//purpose :
73//=======================================================================
74
75static Standard_Integer extendsurf (Draw_Interpretor& di, Standard_Integer n, const char** a)
76{
77 if (n < 4) return 1;
78
79 Handle(Geom_BoundedSurface) GB =
80 Handle(Geom_BoundedSurface)::DownCast(DrawTrSurf::GetSurface(a[1]));
81 if (GB.IsNull()) {
82 di << "extendsurf needs a Bounded surface";
83 return 1;
84 }
91322f44 85 Standard_Real chord=Draw::Atof(a[2]);
86 Standard_Integer cont=Draw::Atoi(a[3]);
7fd59977 87 Standard_Boolean enU = Standard_True, apres = Standard_True;
88 if (n >= 5) {
89 if (strcmp(a[4], "V") == 0) {
90 enU = Standard_False ;
91 }
92 if (strcmp(a[4], "B") == 0) {
93 apres = Standard_False ;
94 }
95 }
96 if (n == 6) {
97 if (strcmp(a[5], "B") == 0) {
98 apres = Standard_False ;
99 }
100 }
101
102
103 GeomLib::ExtendSurfByLength(GB,chord,cont,enU,apres);
104 DrawTrSurf::Set(a[1],GB);
105
106 return 0;
107}
108
109
110//=======================================================================
111//function : samerange
112//purpose :
113//=======================================================================
114
35e08fe8 115static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
7fd59977 116{
117 if (n < 6) return 1;
118 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
119 Handle(Geom2d_Curve) Res;
120 Standard_Real f, l, rf, rl;
91322f44 121 f = Draw::Atof(a[3]);
122 l = Draw::Atof(a[4]);
123 rf = Draw::Atof(a[5]);
124 rl = Draw::Atof(a[6]);
7fd59977 125
126 GeomLib::SameRange(Precision::PConfusion(), C,
127 f, l, rf, rl, Res);
128
129 DrawTrSurf::Set(a[1],Res);
130
131 return 0;
132
133}
134
52ba6031 135//=======================================================================
136//function : setweight
137//purpose : Changes a weight of a pole on B-spline curve/surface
138//=======================================================================
139
76eeac70 140static Standard_Integer setweight(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
52ba6031 141{
142 if (n < 4 || n > 5)
143 {
144 std::cout << "Wrong parameters" << std::endl;
145 return 1;
146 }
147
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]);
151
152 Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
153 if (!aBSplCurve.IsNull())
154 {
155 aBSplCurve->SetWeight(anIndex1, aWeight);
156 return 0;
157 }
158
159 Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
160 if (!aBezCurve.IsNull())
161 {
162 aBezCurve->SetWeight(anIndex1, aWeight);
163 return 0;
164 }
165
166 Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
167 if (!aBSplCurve2d.IsNull())
168 {
169 aBSplCurve2d->SetWeight(anIndex1, aWeight);
170 return 0;
171 }
172
173 Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
174 if (!aBezCurve2d.IsNull())
175 {
176 aBezCurve2d->SetWeight(anIndex1, aWeight);
177 return 0;
178 }
179
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()))
183 {
184 std::cout << "Incorrect parameters" << std::endl;
185 return 1;
186 }
187
188 if (!aBSplSurf.IsNull())
189 {
190 aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
191 return 0;
192 }
193
194 if (!aBezSurf.IsNull())
195 {
196 aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
197 return 0;
198 }
199
200 std::cout << a[1] << " is not a B-spline nor a Bezier curve/surface" << std::endl;
201 return 1;
202}
203
7fd59977 204//=======================================================================
205//function : ModificationCommands
206//purpose :
207//=======================================================================
208
209
210void GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
211{
212 static Standard_Boolean loaded = Standard_False;
213 if (loaded) return;
214 loaded = Standard_True;
215
216 DrawTrSurf::BasicCommands(theCommands);
217
218 const char* g;
219
220 g = "GEOMETRY Curves and Surfaces modification";
221
222
223 theCommands.Add("extendcurve",
224 "extendcurve name point cont [A(fter)/B(efore)]",
225 __FILE__,
226 extendcurve , g);
227
228
229 theCommands.Add("extendsurf",
230 "extendsurf name length cont [U/V] [A(fter)/B(efore)]",
231 __FILE__,
232 extendsurf, g);
233
234
235 theCommands.Add("chgrange",
236 "chgrange newname curve2d first last RequestedFirst RequestedLast ]",
237 __FILE__,
238 samerange, g);
239
52ba6031 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)",
243 __FILE__,
244 setweight,g);
245
7fd59977 246}
247
248
249
250