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