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