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