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