0031731: Draw Harness - colorize errors and exception messages
[occt.git] / src / GeometryTest / GeometryTest_ContinuityCommands.cxx
1 // Created on: 1996-07-31
2 // Created by: Herve LOUESSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <LocalAnalysis.hxx>
18 #include <LocalAnalysis_SurfaceContinuity.hxx>
19 #include <LocalAnalysis_CurveContinuity.hxx>
20 #include <Geom_Surface.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom2d_TrimmedCurve.hxx>
23 #include <Geom2d_Curve.hxx>
24 #include <DrawTrSurf.hxx>
25 #include <GeometryTest.hxx>
26 #include <GeomAbs_Shape.hxx>
27 #include <Draw_Appli.hxx>
28 #include <Draw.hxx>
29 #include <Draw_Interpretor.hxx>
30 #include <Message.hxx>
31
32 /*********************************************************************************/
33 void  InitEpsSurf(Standard_Real& epsnl,Standard_Real& epsdis, Standard_Real& epsangk1, 
34                                Standard_Real& epsangk2, Standard_Real& epsangn1, 
35                                Standard_Real& perce,Standard_Real& maxlen )
36
37   epsnl  = 0.001;
38   epsdis = 0.001;
39   epsangk1 = 0.001 ; 
40   epsangk2 = 0.001;
41   epsangn1 = 0.001 ; 
42   perce = 0.01;
43   maxlen = 10000 ;
44 }
45
46 /*********************************************************************************/
47 void InitEpsCurv(Standard_Real&  epsnl ,Standard_Real&  epsdis, Standard_Real& epsangk1, 
48                                Standard_Real& epsangk2, Standard_Real& epsangg1,
49                                Standard_Real& epsangg2,Standard_Real& percent,
50                                Standard_Real& maxlen)
51
52   epsnl  = 0.001 ;
53   epsdis = 0.001 ; 
54   epsangk1= 0.001 ; 
55   epsangk2= 0.001; 
56   epsangg1= 0.001 ;
57   epsangg2= 0.001 ; 
58   percent= 0.01;
59   maxlen= 10000; 
60 }                          
61 /*********************************************************************************/
62
63 static Standard_Integer surfaceCcontinuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
64
65   Standard_Real U1, U2, V1, V2, u1, u2, v1, v2;
66   GeomAbs_Shape TypeCont; 
67   Standard_Integer ord;
68   Standard_Boolean b1, b2, b3, b4;
69   Standard_Real epsnl,epsC0,epsC1,epsC2,epsG1,maxlen,perce;
70   if (n<8) return 1;
71  
72   InitEpsSurf(epsnl,epsC0,epsC1,epsC2,epsG1,perce,maxlen);
73
74   Handle(Geom_Surface) surf1 = DrawTrSurf::GetSurface(a[2]);
75   if (surf1.IsNull()) return 1 ;
76   
77   Handle(Geom_Surface) surf2 = DrawTrSurf::GetSurface(a[5]);
78   if (surf2.IsNull()) return 1;
79    
80   U1 = Draw::Atof(a[3]);
81   U2 = Draw::Atof(a[6]);
82   V1 = Draw::Atof(a[4]); 
83   V2 = Draw::Atof(a[7]); 
84
85   ord = Draw::Atoi(a[1]);
86
87   surf1->Bounds(u1, u2, v1, v2);
88   b1 = ((((U1>=u1)&&(U1<=u2))||((U1<=u1)&&(U1>=u2))));
89   b3 = ((((V1>=v1)&&(V1<=v2))||((V1<=v1)&&(V1>=v2))));
90
91   surf2->Bounds(u1, u2, v1, v2);
92   b2 = ((((U2>=u1)&&(U2<=u2))||((U2<=u1)&&(U2>=u2))));
93   b4 = ((((V2>=v1)&&(V2<=v2))||((V2<=v1)&&(V2>=v2))));
94
95   if (!((b1 && b2)&&(b3 && b4))) return 1;
96
97   switch ( ord )
98   { 
99   case 0 : 
100     { 
101       TypeCont = GeomAbs_C0;
102       switch(n)
103       { 
104       case 10: epsC0 = Draw::Atof(a[9]);
105         Standard_FALLTHROUGH
106       case 9 : epsnl = Draw::Atof(a[8]);
107         Standard_FALLTHROUGH
108       case 8 : break;
109       default : 
110         Message::SendFail() << "Error: invalid number of arguments: expected to get 8 - 10 parameters";
111         return 1;
112       } 
113     } 
114     break;
115
116   case 1 : 
117     { 
118       TypeCont = GeomAbs_C1;
119       switch(n)
120       { 
121       case 11 : epsC1 = Draw::Atof(a[10]); 
122         Standard_FALLTHROUGH
123       case 10 : epsC0 = Draw::Atof(a[9]);
124         Standard_FALLTHROUGH
125       case 9  : epsnl = Draw::Atof(a[8]);
126         Standard_FALLTHROUGH
127       case 8  : break;
128       default : 
129         Message::SendFail() << "Error: invalid number of arguments: expected to get 8 - 11 parameters";
130         return 1;
131       } 
132     } 
133     break;
134
135   case 2 : 
136     { 
137       TypeCont = GeomAbs_C2;
138       switch(n)
139       {
140       case 12 : epsC2 = Draw::Atof(a[11]); 
141         Standard_FALLTHROUGH
142       case 11 : epsC1 = Draw::Atof(a[10]); 
143         Standard_FALLTHROUGH
144       case 10 : epsC0 = Draw::Atof(a[9]);
145         Standard_FALLTHROUGH
146       case 9  : epsnl = Draw::Atof(a[8]);
147         Standard_FALLTHROUGH
148       case 8  : break;
149       default : 
150         Message::SendFail() << "Error: invalid number of arguments: expected to get 8 - 12 parameters";
151         return 1;
152       } 
153     }
154     break;
155   default:
156     Message::SendFail() << "Error: invalid value of parameter 1 (" << a[1] << "): should be 0, 1, or 2";
157     return 1;
158   }
159
160   LocalAnalysis_SurfaceContinuity RES (surf1, U1, V1, surf2, U2, V2, 
161                                        TypeCont, epsnl, epsC0, epsC1, epsC2, epsG1, perce, maxlen);
162   //LocalAnalysis::Dump(RES,std::cout);    
163   Standard_SStream aSStream;
164   LocalAnalysis::Dump(RES,aSStream);    
165   di << aSStream;
166   return 0; 
167 }
168
169 /*********************************************************************************/
170
171 static Standard_Integer surfaceGcontinuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
172
173   Standard_Real U1, U2, V1, V2,u1, u2, v1, v2;
174   GeomAbs_Shape TypeCont; 
175   Standard_Integer ord;
176   Standard_Boolean b1, b2, b3, b4;
177   Standard_Real epsnl,epsC0,epsC1,epsC2,epsG1,maxlen,perce;
178   
179   if (n<8) return 1;
180   InitEpsSurf(epsnl,epsC0,epsC1,epsC2,epsG1,perce,maxlen);
181
182   Handle(Geom_Surface) surf1 = DrawTrSurf::GetSurface(a[2]);
183   if (surf1.IsNull()) return 1 ;
184   
185   Handle(Geom_Surface) surf2 = DrawTrSurf::GetSurface(a[5]);
186   if (surf2.IsNull()) return 1;
187    
188   U1 = Draw::Atof(a[3]);
189   U2 = Draw::Atof(a[6]);
190   V1 = Draw::Atof(a[4]); 
191   V2 = Draw::Atof(a[7]); 
192
193   ord = Draw::Atoi(a[1]);
194
195   surf1->Bounds(u1, u2, v1, v2);
196   b1 = ((((U1>=u1)&&(U1<=u2))||((U1<=u1)&&(U1>=u2))));
197   b3 = ((((V1>=v1)&&(V1<=v2))||((V1<=v1)&&(V1>=v2))));
198
199   surf2->Bounds(u1, u2, v1, v2);
200   b2 = ((((U2>=u1)&&(U2<=u2))||((U2<=u1)&&(U2>=u2))));
201   b4 = ((((V2>=v1)&&(V2<=v2))||((V2<=v1)&&(V2>=v2))));
202
203   if (!((b1 && b2)&&(b3 && b4))) return 1;
204
205
206   switch ( ord )
207   { 
208   case 1 : 
209     { 
210       TypeCont = GeomAbs_G1;
211       switch(n)
212       { 
213       case 11 : epsG1 = Draw::Atof(a[10]); 
214         Standard_FALLTHROUGH
215       case 10 : epsC0 = Draw::Atof(a[9]);
216         Standard_FALLTHROUGH
217       case 9  : epsnl = Draw::Atof(a[8]);
218         Standard_FALLTHROUGH
219       case 8  : break;
220       default : 
221         Message::SendFail() << "Error: invalid number of arguments: expected to get 8 - 11 parameters";
222         return 1;
223       } 
224     } 
225     break;
226
227   case 2 : 
228     { 
229       TypeCont = GeomAbs_G2;
230       switch(n)
231       {
232       case 13 : maxlen = Draw::Atof (a[12]);
233         Standard_FALLTHROUGH
234       case 12 : perce = Draw::Atof(a[11]); 
235         Standard_FALLTHROUGH
236       case 11 : epsG1 = Draw::Atof(a[10]); 
237         Standard_FALLTHROUGH
238       case 10 : epsC0 = Draw::Atof(a[9]);
239         Standard_FALLTHROUGH
240       case 9  : epsnl = Draw::Atof(a[8]);
241         Standard_FALLTHROUGH
242       case 8  : break;
243       default : 
244         Message::SendFail() << "Error: invalid number of arguments: expected to get 8 - 13 parameters";
245         return 1;
246       } 
247     }
248     break;
249   default:
250     Message::SendFail() << "Error: invalid value of parameter 1 (" << a[1] << "): should be 1 or 2";
251     return 1;
252   }
253   
254   LocalAnalysis_SurfaceContinuity RES (surf1, U1, V1, surf2, U2, V2, 
255                                        TypeCont, epsnl, epsC0, epsC1, epsC2, epsG1, perce, maxlen);
256   //LocalAnalysis::Dump(RES,std::cout);
257   Standard_SStream aSStream;
258   LocalAnalysis::Dump(RES,aSStream);
259   di << aSStream;
260   return 0;  
261 }
262
263 /*********************************************************************************/
264
265 static Standard_Integer curveGcontinuity(Draw_Interpretor& di, Standard_Integer n, const char** a)
266
267   Standard_Real U1, U2, u1, u2;
268   GeomAbs_Shape  TypeCont; 
269   Standard_Integer ord;
270   Standard_Boolean b1, b2;
271   Standard_Real  epsnl,epsC0, epsC1, epsC2, epsG1, epsG2, maxlen,percent;
272   if (n<6) return 1; 
273   
274   Handle(Geom_Curve) curv1 = DrawTrSurf::GetCurve(a[2]);
275   if (curv1.IsNull()) return 1;
276   Handle(Geom_Curve) curv2 = DrawTrSurf::GetCurve(a[4]);
277   if (curv2.IsNull()) return 1;
278
279   U1 = Draw::Atof(a[3]);
280   U2 = Draw::Atof(a[5]);
281  
282   ord = Draw::Atoi(a[1]);
283
284   u1=curv1->FirstParameter();
285   u2=curv1->LastParameter();
286   b1 = ((((U1>=u1)&&(U1<=u2))||((U1<=u1)&&(U1>=u2))));
287    
288   u1=curv2->FirstParameter();
289   u2=curv2->LastParameter();   
290   b2 = ((((U2>=u1)&&(U2<=u2))||((U2<=u1)&&(U2>=u2))));
291      
292   if (!(b1 && b2)) return 1;
293
294   InitEpsCurv( epsnl,epsC0, epsC1, epsC2, epsG1, epsG2, percent,maxlen);
295   switch ( ord )
296   { 
297   case 1 : 
298     {
299       TypeCont = GeomAbs_G1;
300       switch(n)
301       { 
302       case 9 :  epsG1 = Draw::Atof(a[8]); 
303         Standard_FALLTHROUGH
304       case 8  : epsC0 = Draw::Atof(a[7]);
305         Standard_FALLTHROUGH
306       case 7  : epsnl = Draw::Atof(a[6]);
307         Standard_FALLTHROUGH
308       case 6  : break;
309       default : 
310         Message::SendFail() << "Error: invalid number of arguments: expected to get 6 - 8 parameters";
311         return 1;
312       }                         
313     } 
314     break;
315   case 2 : 
316     { 
317       TypeCont = GeomAbs_G2;
318       switch(n)
319       {
320       case 12 : maxlen = Draw::Atof(a[11]);
321         Standard_FALLTHROUGH
322       case 11 : percent = Draw::Atof(a[10]);
323         Standard_FALLTHROUGH
324       case 10 : epsG2 = Draw::Atof(a[9]); 
325         Standard_FALLTHROUGH
326       case 9  : epsG1 = Draw::Atof(a[8]); 
327         Standard_FALLTHROUGH
328       case 8  : epsC0 = Draw::Atof(a[7]);
329         Standard_FALLTHROUGH
330       case 7  : epsnl = Draw::Atof(a[6]);
331         Standard_FALLTHROUGH
332       case 6  : break;
333       default : 
334         Message::SendFail() << "Error: invalid number of arguments: expected to get 6 - 12 parameters";
335         return 1;
336       } 
337     }
338     break; 
339
340   default:
341     Message::SendFail() << "Error: invalid value of parameter 1 (" << a[1] << "): should be 1 or 2";
342     return 1;
343   }
344
345   LocalAnalysis_CurveContinuity RES (curv1, U1, curv2, U2, TypeCont,
346                                      epsnl, epsC0, epsC1, epsC2, epsG1, epsG2, percent, maxlen);
347   //LocalAnalysis::Dump(RES,std::cout);   
348   Standard_SStream aSStream;
349   LocalAnalysis::Dump(RES,aSStream);   
350   di << aSStream;
351   return 0; 
352 }
353
354 /*********************************************************************************/
355
356 static Standard_Integer curveCcontinuity(Draw_Interpretor& di, Standard_Integer n, const char** a)
357
358   Standard_Real U1, U2, u1, u2;
359   GeomAbs_Shape  TypeCont; 
360   Standard_Integer ord;
361   Standard_Boolean b1, b2;
362   Standard_Real  epsnl,epsC0, epsC1, epsC2, epsG1, epsG2, maxlen,percent;
363   if (n<6) return 1; 
364   
365   Handle(Geom_Curve) curv1 = DrawTrSurf::GetCurve(a[2]);
366   if (curv1.IsNull()) return 1;
367   Handle(Geom_Curve) curv2 = DrawTrSurf::GetCurve(a[4]);
368   if (curv2.IsNull()) return 1;
369
370   U1 = Draw::Atof(a[3]);
371   U2 = Draw::Atof(a[5]);
372
373   ord = Draw::Atoi(a[1]);
374
375   u1=curv1->FirstParameter();
376   u2=curv1->LastParameter();
377   b1 = ((((U1>=u1)&&(U1<=u2))||((U1<=u1)&&(U1>=u2))));
378
379   u1=curv2->FirstParameter();
380   u2=curv2->LastParameter();   
381   b2 = ((((U2>=u1)&&(U2<=u2))||((U2<=u1)&&(U2>=u2))));
382
383   if (!(b1 && b2)) return 1;
384
385   InitEpsCurv( epsnl,epsC0, epsC1, epsC2, epsG1, epsG2, percent,maxlen);
386   switch ( ord )
387   { 
388   case 0 : 
389     {
390       TypeCont = GeomAbs_C0;
391       switch(n)
392       { 
393       case 8  : epsC0 = Draw::Atof(a[7]);
394         Standard_FALLTHROUGH
395       case 7  : epsnl = Draw::Atof(a[6]);
396         Standard_FALLTHROUGH
397       case 6  : break;
398       default : 
399         Message::SendFail() << "Error: invalid number of arguments: expected to get 6 - 8 parameters";
400         return 1;
401       }
402     }  
403     break;
404   case 1 : 
405     { 
406       TypeCont = GeomAbs_C1;
407       switch(n)
408       { 
409       case 9 : epsC1 = Draw::Atof(a[8]);
410         Standard_FALLTHROUGH
411       case 8 : epsC0 = Draw::Atof(a[7]);
412         Standard_FALLTHROUGH
413       case 7 : epsnl = Draw::Atof(a[6]);
414         Standard_FALLTHROUGH
415       case 6 : break;
416       default : 
417         Message::SendFail() << "Error: invalid number of arguments: expected to get 6 - 9 parameters";
418         return 1;
419       }                          
420     } 
421     break;
422
423   case 2 : 
424     {  
425       TypeCont = GeomAbs_C2;
426       switch(n)
427       {
428       case 10 : epsC2 = Draw::Atof(a[9]); 
429         Standard_FALLTHROUGH
430       case 9  : epsC1 = Draw::Atof(a[8]); 
431         Standard_FALLTHROUGH
432       case 8  : epsC0 = Draw::Atof(a[7]);
433         Standard_FALLTHROUGH
434       case 7  : epsnl = Draw::Atof(a[6]);
435         Standard_FALLTHROUGH
436       case 6  : break;
437       default : 
438         Message::SendFail() << "Error: invalid number of arguments: expected to get 6 - 10 parameters";
439         return 1;
440       } 
441     }
442     break; 
443
444   default:
445     Message::SendFail() << "Error: invalid value of parameter 1 (" << a[1] << "): should be 0, 1, or 2";
446     return 1;
447   }
448
449   LocalAnalysis_CurveContinuity RES (curv1, U1, curv2, U2, TypeCont, 
450                                      epsnl, epsC0, epsC1, epsC2, epsG1, epsG2, percent, maxlen);
451   //LocalAnalysis::Dump(RES,std::cout);   
452   Standard_SStream aSStream;
453   LocalAnalysis::Dump(RES,aSStream);   
454   di << aSStream;
455   return 0;
456 }
457
458 /***************************************************************************/
459 void GeometryTest::ContinuityCommands( Draw_Interpretor& theCommands)
460 {
461   static Standard_Boolean loaded = Standard_False;
462   if ( loaded) return;
463   loaded = Standard_True;
464
465   DrawTrSurf::BasicCommands(theCommands);
466   const char* g;
467
468   g = "GEOMETRY curves and surfaces continuity analysis ";
469
470   theCommands.Add("surfaceCcontinuity",
471                   " surfaceCcontinuity   order surf1 parU1 parV1 surf2 parU2 parV2  [eps_nul[ epsC0 [epsC1 [epsC2]]]]",  
472                   __FILE__,
473                   surfaceCcontinuity ,g);
474
475   theCommands.Add("surfaceGcontinuity",
476                   " surfaceGcontinuity   order surf1 parU1 parV1 surf2 parU2 parV2  [eps_nul[ epsG0 [epsG1[percent [maxlen]]]]",  
477                   __FILE__,
478                   surfaceGcontinuity ,g);  
479
480   theCommands.Add("curveCcontinuity",
481                   "curveCcontinuity   order curv1 u1  curv2  u2   [epsnul  [epsC0 [epsC1  [epsC2 ]]]]  ",
482                   __FILE__,
483                   curveCcontinuity,g);
484
485  
486   theCommands.Add("curveGcontinuity",
487                   "curveGcontinuity   order  curv1 u1  curv2  u2   [epsnul  [epsG0  [epsG1  [epsG2 [percent  [maxlen ]]]]]] ",
488                    __FILE__,
489                   curveGcontinuity,g);
490 }
491
492
493
494
495
496
497
498