0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / GeometryTest / GeometryTest_ConstraintCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-08-12
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1993-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.
b311480e 16
7fd59977 17// JPI : Commande smooth transferee dans GeomliteTest
18// PMN : Ajout de la commande smooth
19// JCT : Correction d'un trap dans la commande gcarc
20
21#include <Standard_Stream.hxx>
22
23#include <GeometryTest.hxx>
24#include <DrawTrSurf.hxx>
25#include <Draw.hxx>
26#include <Draw_Appli.hxx>
27#include <Draw_Interpretor.hxx>
28#include <Geom2dGcc_Circ2d2TanRad.hxx>
29#include <Geom2dGcc_Circ2d3Tan.hxx>
30#include <Geom2dGcc_Circ2d2TanOn.hxx>
31#include <Geom2dGcc_Circ2dTanOnRad.hxx>
32#include <Geom2dGcc_Circ2dTanCen.hxx>
33#include <Geom2dGcc_Lin2d2Tan.hxx>
34#include <Geom2dGcc_Lin2dTanObl.hxx>
35#include <Geom2dGcc.hxx>
36#include <Geom2dGcc_QualifiedCurve.hxx>
37#include <Geom2d_CartesianPoint.hxx>
38#include <Geom2d_Circle.hxx>
39#include <Geom2d_Line.hxx>
40#include <Precision.hxx>
41#include <GeomAPI_Interpolate.hxx>
42#include <Draw_Marker3D.hxx>
43#include <Geom2dAPI_Interpolate.hxx>
44#include <Draw_Marker2D.hxx>
45#include <TColgp_HArray1OfPnt.hxx>
46#include <Geom_BSplineCurve.hxx>
47#include <TColgp_HArray1OfPnt2d.hxx>
48#include <Geom2d_BSplineCurve.hxx>
543a9964 49#include <Geom_TrimmedCurve.hxx>
7fd59977 50#include <DrawTrSurf_BSplineCurve.hxx>
51#include <DrawTrSurf_BSplineCurve2d.hxx>
52#include <TColgp_HArray1OfPnt.hxx>
53#include <TColgp_Array1OfPnt.hxx>
54#include <TColgp_Array1OfPnt2d.hxx>
55#include <TColgp_HArray1OfVec.hxx>
56#include <TColgp_Array1OfVec.hxx>
57#include <TColStd_Array1OfReal.hxx>
58#include <TColStd_HArray1OfReal.hxx>
59#include <TColStd_HArray1OfBoolean.hxx>
7fd59977 60#include <AppParCurves_MultiBSpCurve.hxx>
61#include <AppDef_MultiLine.hxx>
7fd59977 62#include <AppParCurves_HArray1OfConstraintCouple.hxx>
63#include <AppParCurves_ConstraintCouple.hxx>
64#include <GC_MakeSegment.hxx>
65#include <GC_MakeArcOfCircle.hxx>
66
67//#ifdef WNT
68#include <stdio.h>
69#ifdef WNT
70Standard_IMPORT Draw_Viewer dout;
71#endif
72Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
73
74
75static Standard_Integer solutions(Draw_Interpretor& di,
f62de372 76 Geom2dGcc_Circ2d2TanRad& ct3, const char* name)
7fd59977 77{
78 char solname[200];
79
80 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
81 DrawTrSurf_CurveColor(col);
82
83 if (ct3.IsDone()) {
84 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
85 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
91322f44 86 Sprintf(solname,"%s_%d",name,i);
7fd59977 87 char* temp = solname; // pour portage WNT
88 DrawTrSurf::Set(temp,C);
89 di << solname << " ";
90 }
91 return 0;
92 }
93 else {
94 di << "Circ2d2TanRad Not done";
95 return 1;
96 }
97}
98
99static Standard_Integer solutions(Draw_Interpretor& di,
f62de372 100 Geom2dGcc_Circ2d3Tan& ct3, const char* name)
7fd59977 101{
102 char solname[200];
103
104 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
105 DrawTrSurf_CurveColor(col);
106
107 if (ct3.IsDone()) {
108 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
109 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
91322f44 110 Sprintf(solname,"%s_%d",name,i);
7fd59977 111 char* temp = solname; // pour portage WNT
112 DrawTrSurf::Set(temp,C);
113 di << solname << " ";
114 }
115 return 0;
116 }
117 else {
118 di << "Circ2d3Tan Not done";
119 return 1;
120 }
121}
122
123//=======================================================================
124//function : cirtang
125//purpose :
126//=======================================================================
127
128static Standard_Integer cirtang (Draw_Interpretor& di,Standard_Integer n, const char** a)
129{
130 if (n < 5) return 1;
131
132 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
133 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
134 Handle(Geom2d_Curve) C3 = DrawTrSurf::GetCurve2d(a[4]);
135 gp_Pnt2d P1,P2,P3;
136 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
137 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
138 Standard_Boolean ip3 = DrawTrSurf::GetPoint2d(a[4],P3);
f62de372 139
7fd59977 140 Standard_Real tol = Precision::Confusion();
91322f44 141 if (n > 5) tol = Draw::Atof(a[5]);
7fd59977 142
143
144 if (!C1.IsNull()) {
145 // C-...
146 if (!C2.IsNull()) {
147 // C-C-...
148 if (!C3.IsNull()) {
f62de372 149 // C-C-C
150 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
151 Geom2dGcc::Unqualified(C2),
152 Geom2dGcc::Unqualified(C3),
153 tol,0,0,0);
154 return solutions(di,ct3,a[1]);
7fd59977 155 }
156
157 else if (ip3) {
f62de372 158 // C-C-P
159 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
160 Geom2dGcc::Unqualified(C2),
161 new Geom2d_CartesianPoint(P3),
162 tol,0,0);
163 return solutions(di,ct3,a[1]);
7fd59977 164 }
165
166 else {
f62de372 167 // C-C-R
168 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
169 Geom2dGcc::Unqualified(C2),
170 Draw::Atof(a[4]),tol);
171 return solutions(di,ct3,a[1]);
7fd59977 172 }
173 }
174 else if (ip2) {
175 // C-P-..
176 if (!C3.IsNull()) {
f62de372 177 // C-P-C
178 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
179 Geom2dGcc::Unqualified(C3),
180 new Geom2d_CartesianPoint(P2),
181 tol,0,0);
182 return solutions(di,ct3,a[1]);
183 }
184
7fd59977 185 else if (ip3) {
f62de372 186 // C-P-P
187 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
188 new Geom2d_CartesianPoint(P2),
189 new Geom2d_CartesianPoint(P3),
190 tol,0);
191 return solutions(di,ct3,a[1]);
192 }
193
7fd59977 194 else {
f62de372 195 // C-P-R
196 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
197 new Geom2d_CartesianPoint(P2),
198 Draw::Atof(a[4]),tol);
199 return solutions(di,ct3,a[1]);
7fd59977 200 }
201 }
202
203 else {
204 // C-R-..
205 if (!C3.IsNull()) {
f62de372 206 // C-R-C
207 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
208 Geom2dGcc::Unqualified(C3),
209 Draw::Atof(a[3]),
210 tol);
211 return solutions(di,ct3,a[1]);
212 }
213
7fd59977 214 else if (ip3) {
f62de372 215 // C-R-P
216 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
217 new Geom2d_CartesianPoint(P3),
218 Draw::Atof(a[3]),
219 tol);
220 return solutions(di,ct3,a[1]);
221 }
222
7fd59977 223 else {
f62de372 224 // C-R-R
225 di << "Curve, radius, radius ???"<<"\n";
226 return 1;
7fd59977 227 }
228 }
229 }
230
231 else if (ip1) {
232 // P-...
233 if (!C2.IsNull()) {
234 // P-C-...
235 if (!C3.IsNull()) {
f62de372 236 // P-C-C
237 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
238 Geom2dGcc::Unqualified(C3),
239 new Geom2d_CartesianPoint(P1),
240 tol,0,0);
241 return solutions(di,ct3,a[1]);
7fd59977 242 }
243
244 else if (ip3) {
f62de372 245 // P-C-P
246 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
247 new Geom2d_CartesianPoint(P1),
248 new Geom2d_CartesianPoint(P3),
249 tol,0);
250 return solutions(di,ct3,a[1]);
7fd59977 251 }
252
253 else {
f62de372 254 // P-C-R
255 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
256 new Geom2d_CartesianPoint(P1),
257 Draw::Atof(a[4]),tol);
258 return solutions(di,ct3,a[1]);
7fd59977 259 }
260 }
261 else if (ip2) {
262 // P-P-..
263 if (!C3.IsNull()) {
f62de372 264 // P-P-C
265 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C3),
266 new Geom2d_CartesianPoint(P1),
267 new Geom2d_CartesianPoint(P2),
268 tol,0);
269 return solutions(di,ct3,a[1]);
270 }
271
7fd59977 272 else if (ip3) {
f62de372 273 // P-P-P
274 Geom2dGcc_Circ2d3Tan ct3(new Geom2d_CartesianPoint(P1),
275 new Geom2d_CartesianPoint(P2),
276 new Geom2d_CartesianPoint(P3),
277 tol);
278 return solutions(di,ct3,a[1]);
279 }
280
7fd59977 281 else {
f62de372 282 // P-P-R
283 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
284 new Geom2d_CartesianPoint(P2),
285 Draw::Atof(a[4]),tol);
286 return solutions(di,ct3,a[1]);
7fd59977 287 }
288 }
289
290 else {
291 // P-R-..
292 if (!C3.IsNull()) {
f62de372 293 // P-R-C
294 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
295 new Geom2d_CartesianPoint(P1),
296 Draw::Atof(a[3]),
297 tol);
298 return solutions(di,ct3,a[1]);
299 }
300
7fd59977 301 else if (ip3) {
f62de372 302 // P-R-P
303 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
304 new Geom2d_CartesianPoint(P3),
305 Draw::Atof(a[3]),
306 tol);
307 return solutions(di,ct3,a[1]);
308 }
309
7fd59977 310 else {
f62de372 311 // P-R-R
312 di << "Point, radius, radius ???"<<"\n";
313 return 1;
7fd59977 314 }
315 }
316 }
317
318 else {
319 // R-...
320 if (!C2.IsNull()) {
321 // R-C-...
322 if (!C3.IsNull()) {
f62de372 323 // R-C-C
324 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
325 Geom2dGcc::Unqualified(C3),
326 Draw::Atof(a[2]),
327 tol);
328 return solutions(di,ct3,a[1]);
7fd59977 329 }
330
331 else if (ip3) {
f62de372 332 // R-C-P
333 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
334 new Geom2d_CartesianPoint(P3),
335 Draw::Atof(a[2]),
336 tol);
337 return solutions(di,ct3,a[1]);
7fd59977 338 }
339
340 else {
d3f26155 341 // R-C-R
342 di << "Radius - Curve - Radius ??"<<"\n";
343 return 1;
7fd59977 344 }
345 }
346 else if (ip2) {
347 // R-P-..
348 if (!C3.IsNull()) {
d3f26155 349 // R-P-C
350 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
f62de372 351 new Geom2d_CartesianPoint(P2),
352 Draw::Atof(a[2]),
353 tol);
d3f26155 354 return solutions(di,ct3,a[1]);
7fd59977 355 }
f62de372 356
d3f26155 357 else if (ip3)
358 {
359 // R-P-P
360 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P2),
f62de372 361 new Geom2d_CartesianPoint(P3),
362 Draw::Atof(a[2]),
363 tol);
d3f26155 364 return solutions(di,ct3,a[1]);
365 }
7fd59977 366 else {
d3f26155 367 // R-P-R
368 di << "Radius - Point - Radius ??"<<"\n";
369 return 1;
7fd59977 370 }
371 }
7fd59977 372 else {
373 // R-R-..
374 di << "radius, radius ???"<<"\n";
375 return 1;
376 }
377 }
7fd59977 378}
379
380
381//=======================================================================
382//function : lintang
383//purpose :
384//=======================================================================
385
386static Standard_Integer lintang (Draw_Interpretor& di,Standard_Integer n, const char** a)
387{
388 if (n < 4) return 1;
389
390 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
391 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
392
393 char solname[200];
394
395 if (C1.IsNull() || C2.IsNull())
396 return 1;
397
398 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
399
400 if (n >= 5) {
401 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C2);
402 if (L.IsNull()) {
403 di << "Second argument must be a line";
404 return 1;
405 }
91322f44 406 Standard_Real ang = Draw::Atof(a[4]) * (M_PI / 180.0);
7fd59977 407 Geom2dGcc_Lin2dTanObl ct3(Geom2dGcc::Unqualified(C1),
f62de372 408 L->Lin2d(),
409 Precision::Angular(),
410 (C1->FirstParameter()+C1->LastParameter())/2.,
411 ang);
7fd59977 412 if (ct3.IsDone()) {
413 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
f62de372 414 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
415 Sprintf(solname,"%s_%d",a[1],i);
416 char* temp = solname; // pour portage WNT
417 DrawTrSurf::Set(temp,LS);
418 di << solname << " ";
7fd59977 419 }
420 }
421 else
422 di << "Lin2dTanObl Not done" << "\n";
423 }
424 else {
425 Geom2dGcc_Lin2d2Tan ct3(Geom2dGcc::Unqualified(C1),
f62de372 426 Geom2dGcc::Unqualified(C2),
427 Precision::Angular(),
428 (C1->FirstParameter()+C1->LastParameter())/2.,
429 (C2->FirstParameter()+C2->LastParameter())/2.);
7fd59977 430 if (ct3.IsDone()) {
431 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
f62de372 432 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
433 Sprintf(solname,"%s_%d",a[1],i);
434 char* temp = solname; // pour portage WNT
435 DrawTrSurf::Set(temp,LS);
436 di << solname << " ";
7fd59977 437 }
438 }
439 else
440 di << "Lin2d2Tan Not done" << "\n";
441 }
442
443 DrawTrSurf_CurveColor(col);
444
445 return 0;
446}
447
448//==================================================================================
449static Standard_Integer interpol (Draw_Interpretor& di,Standard_Integer n, const char** a)
450//==================================================================================
451{
452 if (n == 1) {
453 di <<"give a name to your curve !" << "\n";
454 return 0;
455 }
456 if (n == 2) {
457 Standard_Integer id,XX,YY,b, i, j;
458 di << "Pick points "<< "\n";
459 dout.Select(id, XX, YY, b);
460 Standard_Real zoom = dout.Zoom(id);
461 if (b != 1) return 0;
462 if (id < 0) return 0;
463 gp_Pnt P;
464 gp_Pnt2d P2d;
465 Standard_Boolean newcurve;
f62de372 466
7fd59977 467 if (dout.Is3D(id)) {
468 Handle(Draw_Marker3D) mark;
469 Handle(TColgp_HArray1OfPnt) Points = new TColgp_HArray1OfPnt(1, 1);
470 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
471 Points->SetValue(1 , P);
472 Handle(TColgp_HArray1OfPnt) ThePoints = new TColgp_HArray1OfPnt(1, 2);
473 ThePoints->SetValue(1 , P);
474 mark = new Draw_Marker3D(Points->Value(1), Draw_X, Draw_vert);
475 dout << mark;
476 dout.Flush();
477 Handle(Geom_BSplineCurve) C;
478 i = 1;
f62de372 479
7fd59977 480 while (b != 3) {
f62de372 481 dout.Select(id,XX,YY,b, Standard_False);
482 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
483 ThePoints->SetValue(i+1, P);
484 newcurve = Standard_False;
485 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
486 if (b == 1) {
487 i++;
488 mark = new Draw_Marker3D(ThePoints->Value(i), Draw_X, Draw_vert);
489 dout << mark;
490 dout.Flush();
491 Points =
492 new TColgp_HArray1OfPnt(ThePoints->Lower(),ThePoints->Upper());
493 Points->ChangeArray1() = ThePoints->Array1();
494 newcurve = Standard_True;
495 }
496 GeomAPI_Interpolate anInterpolator(ThePoints,
497 Standard_False,
498 1.0e-5);
499 anInterpolator.Perform() ;
500 if (anInterpolator.IsDone()) {
501 C = anInterpolator.Curve() ;
502 Handle(DrawTrSurf_BSplineCurve)
503 DC = new DrawTrSurf_BSplineCurve(C);
504 DC->ClearPoles();
505 DC->ClearKnots();
506 Draw::Set(a[1], DC);
507 dout.RepaintView(id);
508 }
509 if (newcurve) {
510 ThePoints = new TColgp_HArray1OfPnt(1, i+1);
511 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
512 }
513 }
7fd59977 514 }
515 GeomAPI_Interpolate anInterpolator(ThePoints,
f62de372 516 Standard_False,
517 1.0e-5);
7fd59977 518 anInterpolator.Perform() ;
519 if (anInterpolator.IsDone()) {
f62de372 520 C = anInterpolator.Curve() ;
521 DrawTrSurf::Set(a[1], C);
522 dout.RepaintView(id);
7fd59977 523 }
524 }
525 else {
526 Handle(Draw_Marker2D) mark;
527 Handle(TColgp_HArray1OfPnt2d) Points = new TColgp_HArray1OfPnt2d(1, 1);
528 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
529 Points->SetValue(1 , P2d);
530 Handle(TColgp_HArray1OfPnt2d) ThePoints = new TColgp_HArray1OfPnt2d(1, 2);
531 ThePoints->SetValue(1, P2d);
532 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
533 dout << mark;
534 dout.Flush();
535 Handle(Geom2d_BSplineCurve) C;
536 i = 1;
f62de372 537
7fd59977 538 while (b != 3) {
f62de372 539 dout.Select(id,XX,YY,b, Standard_False);
540 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
541 ThePoints->SetValue(i+1, P2d);
542 newcurve = Standard_False;
543 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
544 if (b == 1) {
545 i++;
546 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
547 dout << mark;
548 dout.Flush();
549 Points =
550 new TColgp_HArray1OfPnt2d(ThePoints->Lower(),ThePoints->Upper());
551 Points->ChangeArray1() = ThePoints->Array1();
552 newcurve = Standard_True;
553 }
7fd59977 554 Geom2dAPI_Interpolate a2dInterpolator(ThePoints,
f62de372 555 Standard_False,
556 1.0e-5) ;
7fd59977 557 a2dInterpolator.Perform() ;
558 if (a2dInterpolator.IsDone()) {
f62de372 559 C = a2dInterpolator.Curve() ;
560
561 Handle(DrawTrSurf_BSplineCurve2d)
562 DC = new DrawTrSurf_BSplineCurve2d(C);
563 DC->ClearPoles();
564 DC->ClearKnots();
565 Draw::Set(a[1], DC);
566 dout.RepaintView(id);
567 }
568
569 if (newcurve) {
570 ThePoints = new TColgp_HArray1OfPnt2d(1, i+1);
571 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
572 }
573 }
7fd59977 574 }
575 Geom2dAPI_Interpolate a2dInterpolator(Points,
f62de372 576 Standard_False,
577 1.0e-5) ;
7fd59977 578 a2dInterpolator.Perform() ;
579 if (a2dInterpolator.IsDone()) {
f62de372 580 C = a2dInterpolator.Curve() ;
581
582 DrawTrSurf::Set(a[1], C);
583 dout.RepaintView(id);
7fd59977 584 }
585
586 }
587 }
588 else if (n == 3) {
589 // lecture du fichier.
590 // nbpoints, 2d ou 3d, puis valeurs.
591 const char* nomfic = a[2];
592 ifstream iFile(nomfic, ios::in);
593 if (!iFile) return 1;
594 Standard_Integer nbp, i;
595 Standard_Real x, y, z;
596 iFile >> nbp;
597 char dimen[3];
598 iFile >> dimen;
599 if (!strcmp(dimen,"3d")) {
857ffd5e 600 Handle(TColgp_HArray1OfPnt) Point =
f62de372 601 new TColgp_HArray1OfPnt(1, nbp);
7fd59977 602 for (i = 1; i <= nbp; i++) {
f62de372 603 iFile >> x >> y >> z;
604 Point->SetValue(i, gp_Pnt(x, y, z));
7fd59977 605 }
606 GeomAPI_Interpolate anInterpolator(Point,
f62de372 607 Standard_False,
608 1.0e-5) ;
7fd59977 609 anInterpolator.Perform() ;
610 if (anInterpolator.IsDone()) {
f62de372 611 Handle(Geom_BSplineCurve) C =
612 anInterpolator.Curve();
613 DrawTrSurf::Set(a[1], C);
7fd59977 614 }
615 }
616 else if (!strcmp(dimen,"2d")) {
617 Handle(TColgp_HArray1OfPnt2d) PointPtr =
f62de372 618 new TColgp_HArray1OfPnt2d(1, nbp);
7fd59977 619 for (i = 1; i <= nbp; i++) {
f62de372 620 iFile >> x >> y;
621 PointPtr->SetValue(i, gp_Pnt2d(x, y));
7fd59977 622 }
623 Geom2dAPI_Interpolate a2dInterpolator(PointPtr,
f62de372 624 Standard_False,
625 1.0e-5);
7fd59977 626 a2dInterpolator.Perform() ;
627 if (a2dInterpolator.IsDone()) {
f62de372 628 Handle(Geom2d_BSplineCurve) C = a2dInterpolator.Curve() ;
629 DrawTrSurf::Set(a[1], C);
7fd59977 630 }
631 }
632 }
633 return 0;
634}
635
636static Standard_Integer tanginterpol (Draw_Interpretor& di,
f62de372 637 Standard_Integer n,
638 const char** a)
7fd59977 639{
640
641
642 if (n < 4)
643 return 1;
644
645 Standard_Integer
646 ii,
647 jj,
f62de372 648 // num_knots,
649 // degree,
7fd59977 650 num_tangents,
651 num_read,
652 num_start,
653 num_parameters ;
654
f62de372 655
7fd59977 656 Standard_Real
f62de372 657 // delta,
7fd59977 658 tolerance;
f62de372 659 // parameter ;
7fd59977 660
f62de372 661 Standard_Boolean periodic_flag = Standard_False ;
662 gp_Pnt a_point ;
663 gp_Vec a_vector ;
664 tolerance = 1.0e-5 ;
7fd59977 665
666
667
668
669 Handle(Geom_BSplineCurve) NewCurvePtr ;
670
671
672
673
674 num_read = 2 ;
675 if (strcmp(a[num_read],"p") == 0) {
676 periodic_flag = Standard_True ;
677 num_read += 1 ;
678 }
91322f44 679 num_parameters = Draw::Atoi(a[num_read]) ;
7fd59977 680
681 if (num_parameters < 2) {
682 num_parameters = 2 ;
683 }
684 if ( n < num_parameters * 3 + num_read) {
685 return 1 ;
686 }
857ffd5e 687 Handle(TColgp_HArray1OfPnt) PointsArrayPtr=
7fd59977 688 new TColgp_HArray1OfPnt(1,num_parameters) ;
f62de372 689
7fd59977 690 num_tangents = ((n - num_read) / 3) - num_parameters ;
691 num_tangents = Max (0,num_tangents) ;
692 num_tangents = Min (num_parameters, num_tangents) ;
693 ii = 1 ;
694 num_start = num_read ;
695 num_read += 1 ;
696 while (num_read <= num_parameters * 3 + num_start ) {
697 for (jj = 1 ; jj <= 3 ; jj++) {
91322f44 698 a_point.SetCoord(jj,Draw::Atof(a[num_read])) ;
7fd59977 699 num_read += 1 ;
700 }
701 PointsArrayPtr->SetValue(ii,a_point) ;
702 ii += 1 ;
703 }
704 GeomAPI_Interpolate anInterpolator(PointsArrayPtr,
f62de372 705 periodic_flag,
706 tolerance) ;
7fd59977 707
708 if (num_tangents > 0) {
709 TColgp_Array1OfVec TangentsArray(1,num_parameters) ;
857ffd5e 710 Handle(TColStd_HArray1OfBoolean)
7fd59977 711 TangentFlagsPtr =
f62de372 712 new TColStd_HArray1OfBoolean(1,num_parameters) ;
713
7fd59977 714 for (ii = 1 ; ii <= num_tangents ; ii++) {
715 TangentFlagsPtr->SetValue(ii,Standard_True) ;
716 }
717 for (ii = num_tangents + 1 ; ii <= num_parameters ; ii++) {
718 TangentFlagsPtr->SetValue(ii,Standard_False) ;
719 }
720 ii = 1 ;
721 while (ii <= num_tangents) {
722 for (jj = 1 ; jj <= 3 ; jj++) {
f62de372 723 a_vector.SetCoord(jj,Draw::Atof(a[num_read])) ;
724 num_read += 1 ;
7fd59977 725 }
726 TangentsArray.SetValue(ii,a_vector) ;
727 ii += 1 ;
728 }
f62de372 729
730
7fd59977 731 anInterpolator.Load(TangentsArray,
f62de372 732 TangentFlagsPtr) ;
7fd59977 733 }
734 anInterpolator.Perform() ;
735 if (anInterpolator.IsDone()) {
736 NewCurvePtr =
737 anInterpolator.Curve() ;
738
739 DrawTrSurf::Set(a[1],
f62de372 740 NewCurvePtr) ;
7fd59977 741 di << a[2] << " " ;
742
743 }
744 return 0 ;
745}
746
747//==================================================================================
748static Standard_Integer gcarc (Draw_Interpretor& di,Standard_Integer n, const char** a)
749//==================================================================================
750{
751 if (n >= 5) {
752 gp_Pnt P1,P2,P3,P4;
753 if (!strcmp(a[2], "seg")) {
754 if (DrawTrSurf::GetPoint(a[3], P1)) {
f62de372 755 if (DrawTrSurf::GetPoint(a[4], P2)) {
756 Handle(Geom_Curve) theline = GC_MakeSegment(P1,P2).Value();
757 DrawTrSurf::Set(a[1], theline);
758 return 1;
759 }
7fd59977 760 }
761 }
762 else if (!strcmp(a[2], "cir")) {
763 if (DrawTrSurf::GetPoint(a[3], P1)) {
f62de372 764 if (DrawTrSurf::GetPoint(a[4], P2)) {
765 if (DrawTrSurf::GetPoint(a[5], P3)) {
766 // if (DrawTrSurf::GetPoint(a[6], P4)) {
767 if (n>6) {
768 DrawTrSurf::GetPoint(a[6], P4);
769 gp_Vec V1 = gp_Vec(P2,P3);
770 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,V1,P4).Value();
771 DrawTrSurf::Set(a[1], thearc);
772 return 1;
773 }
774 else {
775 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,P2,P3).Value();
776 DrawTrSurf::Set(a[1], thearc);
777 return 1;
778 }
779 }
780 }
7fd59977 781 }
782 }
783 }
784 di <<"give a name for arc and the type seg or cir then" << "\n";
785 di <<"give passing points p1 p2 for seg p1 p2 p3 or p1 p2 p3 p4 for cir (p2 p3 is a tgtvec)!" << "\n";
786 return 0;
787}
788
789//=======================================================================
790//function : ConstraintCommands
791//purpose :
792//=======================================================================
793
794
795void GeometryTest::ConstraintCommands(Draw_Interpretor& theCommands)
796{
797
798 static Standard_Boolean loaded = Standard_False;
799 if (loaded) return;
800 loaded = Standard_True;
801
802 DrawTrSurf::BasicCommands(theCommands);
803
804 const char* g;
805 // constrained constructs
806 g = "GEOMETRY Constraints";
807
f62de372 808 theCommands.Add("cirtang",
809 "cirtang cname curve/point/radius curve/point/radius curve/point/radius",
810 __FILE__,
811 cirtang,g);
812
813 theCommands.Add("lintan",
814 "lintan lname curve1 curve2 [angle]",
815 __FILE__,
816 lintang,g);
817
818
819 theCommands.Add("interpol",
820 "interpol cname [fic]",
821 __FILE__,
822 interpol, g);
823 theCommands.Add("tanginterpol",
824 "tanginterpol curve [p] num_points points [tangents] modifier p = periodic",
825 __FILE__,
826 tanginterpol,g);
827
828 theCommands.Add("gcarc",
829 "gcarc name seg/cir p1 p2 p3 p4",
830 __FILE__,
831 gcarc,g);
7fd59977 832}