0024339: Vectors not displayed correctly in MFC samples [6.7.0 Beta]: ISession_Direct...
[occt.git] / samples / mfc / standard / 01_Geometry / src / GeomSources.cpp
1 // GeomSources.cpp: implementation of the GeomSources class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "stdafx.h"
6 #include "GeomSources.h"
7 #include "GeometryApp.h"
8 #include "MainFrm.h"
9
10 GeomSources::GeomSources()
11 {
12 }
13
14 GeomSources::~GeomSources()
15 {
16 }
17 void GeomSources::PreProcess(CGeometryDoc* aDoc,DisplayType aDisplayType)
18 {
19   if (aDisplayType == No2D3D )
20   {   
21     aDoc->GetAISContext()->EraseAll();
22     aDoc->Put3DOnTop(); 
23   }
24
25   if (aDisplayType == a2DNo3D)
26   { 
27     aDoc->GetISessionContext()->EraseAll();
28     aDoc->Put2DOnTop();
29   }
30
31   if (aDisplayType != No2D3D && aDisplayType != a2D3D)
32   {  
33     aDoc->Minimize3D();
34   }
35
36   if (aDisplayType != a2DNo3D && aDisplayType != a2D3D)
37   {  
38     aDoc->Minimize2D();
39   }
40
41   if (aDisplayType == a2D3D)
42   {
43     aDoc->GetAISContext()->EraseAll();
44     aDoc->GetISessionContext()->EraseAll();
45     aDoc->Put3DOnTop(false); 
46     aDoc->Put2DOnTop(false);
47
48     // both on top
49     // send the message Title Horizontaly to the child of doc main frame
50     CGeometryApp* TheAppli = (CGeometryApp*)AfxGetApp();
51     CMainFrame* TheMainFrame= (CMainFrame*)TheAppli->m_pMainWnd;
52     ::SendMessage(TheMainFrame->m_hWndMDIClient, WM_MDITILE, 0, 0);
53   }
54 }
55
56 void GeomSources::PostProcess(CGeometryDoc* aDoc,
57                                                           UINT anID,
58                                                           DisplayType aDisplayType,
59                                                           const char* aString,
60                                                           Quantity_Coefficient Coef /* = -1 */
61                                                           /* double Zoom = -1 */)
62 {
63   if (aDisplayType == No2D3D || aDisplayType == a2D3D)
64   {   
65     aDoc->Fit3DViews(Coef);
66   }
67
68   if (aDisplayType == a2DNo3D || aDisplayType == a2D3D)
69   { 
70     aDoc->Fit2DViews();  
71   }
72
73   TCollection_AsciiString Message("Results are ");
74
75   switch (aDisplayType)
76   {
77   case No2DNo3D: Message = "All results are in this box \n";
78     break;
79   case No2D3D:   Message += "only in 3D \n";
80     break;
81   case a2DNo3D:   Message += "only in 2d \n";
82     break;
83   case a2D3D:     Message += "in both 2D and 3D \n";
84     break;
85   }   
86   Message += "====================================\n";
87   Message += aString;
88
89   CString text(Message.ToCString());
90   aDoc->myCResultDialog.SetText(text);
91
92   CString s;
93   if (! s.LoadString( anID ))
94     AfxMessageBox("Error Loading String: ");
95
96   CString Title = s.Left( s.Find( '\n' ));
97
98   aDoc->myCResultDialog.SetTitle(Title);
99   aDoc->SetTitle(Title);
100 }
101
102 void GeomSources::AddSeparator(CGeometryDoc* /*aDoc*/,TCollection_AsciiString& aMessage)
103 {
104   aMessage+= "------------------------------------------------------------------------\n";
105 }
106 void GeomSources::DisplayPoint(CGeometryDoc* aDoc,
107                           const gp_Pnt2d& aPoint,
108                           const char* aText,
109                           Standard_Boolean UpdateViewer,
110                           Standard_Real anXoffset,
111                           Standard_Real anYoffset,
112                           Standard_Real TextScale)
113 {
114   Handle(ISession_Point) aGraphicPoint = new ISession_Point(aPoint);
115   aDoc->GetISessionContext()->Display(aGraphicPoint,UpdateViewer);
116   Handle(ISession_Text)  aGraphicText = new ISession_Text(aText,aPoint.X()+anXoffset,aPoint.Y()+anYoffset);
117   aGraphicText->SetScale  (TextScale);
118   aDoc->GetISessionContext()->Display(aGraphicText,UpdateViewer);
119 }
120
121 void GeomSources::DisplayPoint(CGeometryDoc* aDoc,
122                           const gp_Pnt& aPoint,
123                           const char* aText,
124                           Standard_Boolean UpdateViewer,
125                           Standard_Real anXoffset,
126                           Standard_Real anYoffset,
127                           Standard_Real aZoffset,
128                           Standard_Real TextScale)
129 {
130   Handle(ISession_Point) aGraphicPoint = new ISession_Point(aPoint);
131   aDoc->GetAISContext()->Display(aGraphicPoint,UpdateViewer);
132   Handle(ISession_Text)  aGraphicText = new ISession_Text(aText,aPoint.X()+anXoffset,aPoint.Y()+anYoffset,aPoint.Z()+aZoffset);
133   aGraphicText->SetScale  (TextScale);
134   aDoc->GetAISContext()->Display(aGraphicText,UpdateViewer);
135 }
136
137 void GeomSources::DisplayCurve(CGeometryDoc* aDoc,
138                           Handle(Geom2d_Curve) aCurve,
139                           Standard_Integer aColorIndex,
140                           Standard_Boolean UpdateViewer)
141 {
142   Handle(ISession2D_Curve) aGraphicCurve = new ISession2D_Curve(aCurve);
143   aGraphicCurve->SetColorIndex(aColorIndex) ;
144   aDoc->GetISessionContext()->Display(aGraphicCurve,UpdateViewer);
145 }
146
147 void GeomSources::DisplayCurveAndCurvature(CGeometryDoc* aDoc,
148                           Handle(Geom2d_Curve) aCurve,
149                           Standard_Integer aColorIndex,
150                           Standard_Boolean UpdateViewer)
151 {
152   Handle(ISession2D_Curve) aGraphicCurve = new ISession2D_Curve(aCurve);
153   aGraphicCurve->SetDisplayCurbure(Standard_True) ;
154   aGraphicCurve->SetDiscretisation(20);
155   aGraphicCurve->SetColorIndex(aColorIndex) ;
156   aDoc->GetISessionContext()->Display(aGraphicCurve,UpdateViewer);
157 }
158
159 void GeomSources::DisplayCurve(CGeometryDoc* aDoc,
160                           Handle(Geom_Curve) aCurve,
161                           Quantity_NameOfColor aNameOfColor, 
162                           Standard_Boolean UpdateViewer)
163 {
164   Handle(ISession_Curve) aGraphicCurve = new ISession_Curve(aCurve);
165   aDoc->GetAISContext()->SetColor(aGraphicCurve,aNameOfColor, Standard_False);
166   aGraphicCurve->Attributes()->LineAspect()->SetColor(aNameOfColor);
167   aDoc->GetAISContext()->Display(aGraphicCurve,UpdateViewer);
168 }
169
170 void GeomSources::DisplayCurve(CGeometryDoc* aDoc,
171                           Handle(Geom_Curve) aCurve,
172                           Standard_Boolean UpdateViewer)
173 {
174     Handle(ISession_Curve) aGraphicCurve = new ISession_Curve(aCurve);
175     aDoc->GetAISContext()->Display(aGraphicCurve,UpdateViewer);
176 }
177
178
179
180
181 void GeomSources::DisplaySurface(CGeometryDoc* aDoc,
182                           Handle(Geom_Surface) aSurface,
183                           Quantity_NameOfColor aNameOfColor, 
184                           Standard_Boolean UpdateViewer)
185 {
186   Handle(ISession_Surface) aGraphicalSurface = new ISession_Surface(aSurface);
187   aDoc->GetAISContext()->SetColor(aGraphicalSurface,aNameOfColor, Standard_False);
188   aGraphicalSurface->Attributes()->FreeBoundaryAspect()->SetColor(aNameOfColor);
189   aGraphicalSurface->Attributes()->UIsoAspect()->SetColor(aNameOfColor);
190   aGraphicalSurface->Attributes()->VIsoAspect()->SetColor(aNameOfColor);
191   aDoc->GetAISContext()->Display(aGraphicalSurface,UpdateViewer);
192 }
193
194 void GeomSources::DisplaySurface(CGeometryDoc* aDoc,
195                           Handle(Geom_Surface) aSurface,
196                           Standard_Boolean UpdateViewer)
197 {
198   Handle(ISession_Surface) aGraphicalSurface = new ISession_Surface(aSurface);
199   aDoc->GetAISContext()->Display(aGraphicalSurface,UpdateViewer);
200 }
201
202 // Function name        : GeomSources::gpTest1
203 // Description      : 
204 // Return type          : void 
205 // Argument         : CGeometryDoc* aDoc
206 void GeomSources::gpTest1(CGeometryDoc* aDoc)
207 {
208   DisplayType TheDisplayType = No2D3D;
209   PreProcess(aDoc,TheDisplayType);
210   //==============================================================
211
212   gp_XYZ A(1,2,3);                        
213   gp_XYZ B(2,2,2);                        
214   gp_XYZ C(3,2,3);                        
215   Standard_Real result = A.DotCross(B,C); 
216                                         
217 //==============================================================
218   TCollection_AsciiString Message ("\
219                                         \n\
220 gp_XYZ A(1,2,3);                        \n\
221 gp_XYZ B(2,2,2);                        \n\
222 gp_XYZ C(3,2,3);                        \n\
223 Standard_Real result = A.DotCross(B,C); \n\
224                                         \n");
225   AddSeparator(aDoc,Message);
226 //--------------------------------------------------------------
227
228     DisplayPoint(aDoc,gp_Pnt(A),"A (1,2,3)",false,0.1);
229     DisplayPoint(aDoc,gp_Pnt(B),"B (2,2,2)",false,0.1);
230     DisplayPoint(aDoc,gp_Pnt(C),"C (3,2,3)",false,0.1);
231
232 // to add a numeric value in a TCollectionAsciiString   
233   TCollection_AsciiString Message2 (result);
234     
235   Message+= " result = ";
236   Message+= Message2;
237   PostProcess(aDoc,ID_BUTTON_Test_1,TheDisplayType,Message.ToCString());
238 }
239
240 // Function name        : GeomSources::gpTest2
241 // Description      : 
242 // Return type          : void 
243 // Argument         : CGeometryDoc* aDoc
244 void GeomSources::gpTest2(CGeometryDoc* aDoc)
245 {
246   DisplayType TheDisplayType = No2D3D;
247   PreProcess(aDoc,TheDisplayType);
248 //==============================================================
249                    
250   gp_Pnt P1(1,2,3);  
251                    
252 //==============================================================
253   TCollection_AsciiString Message ("\
254                   \n\
255 gp_Pnt P1(1,2,3); \n\
256                   \n");
257   AddSeparator(aDoc,Message);
258 //--------------------------------------------------------------
259   DisplayPoint(aDoc,P1,"P1 (1,2,3)",false,0.5);
260   PostProcess(aDoc,ID_BUTTON_Test_2,TheDisplayType,Message.ToCString(),1.0);
261 }
262
263
264 // Function name        : GeomSources::gpTest3
265 // Description      : 
266 // Return type          : void 
267 // Argument         : CGeometryDoc* aDoc
268 void GeomSources::gpTest3(CGeometryDoc* aDoc)
269 {
270   DisplayType TheDisplayType = No2D3D;
271   PreProcess(aDoc,TheDisplayType);
272 //==============================================================
273                   
274   gp_XYZ A(1,2,3);  
275   gp_Pnt P2(A);     
276                   
277 //==============================================================
278   TCollection_AsciiString Message ("\
279                    \n\
280 gp_XYZ A(1,2,3);   \n\
281 gp_Pnt P2(A);      \n\
282                    \n");
283   AddSeparator(aDoc,Message);
284 //--------------------------------------------------------------
285   DisplayPoint(aDoc,P2,"P2 (1,2,3)",false,0.5);
286   PostProcess(aDoc,ID_BUTTON_Test_3,TheDisplayType,Message.ToCString(),1.0 /*0.02*/);
287 }
288
289
290 // Function name        : GeomSources::gpTest4
291 // Description      : 
292 // Return type          : void 
293 // Argument         : CGeometryDoc* aDoc
294 void GeomSources::gpTest4(CGeometryDoc* aDoc)
295 {
296   DisplayType TheDisplayType = No2D3D;
297   PreProcess(aDoc,TheDisplayType);
298 //==============================================================
299                                               
300   gp_Pnt P3 = gp::Origin();                     
301   Standard_Real TheX = P3.X();
302   Standard_Real TheY = P3.Y();
303   Standard_Real TheZ = P3.Z();
304   
305                                               
306 //==============================================================
307     TCollection_AsciiString Message ("\
308                                \n\
309 gp_Pnt P3 = gp::Origin();      \n\
310 Standard_Real TheX = P3.X();   \n\
311 Standard_Real TheY = P3.Y();   \n\
312 Standard_Real TheZ = P3.Z();   \n\
313                                \n");
314   AddSeparator(aDoc,Message);
315 //--------------------------------------------------------------
316   DisplayPoint(aDoc,P3,"P3 = gp::Origin()",false,0.5);
317
318   TCollection_AsciiString Message2 (TheX);
319   TCollection_AsciiString Message3 (TheY);
320   TCollection_AsciiString Message4 (TheZ);
321
322   Message += " TheX = ";
323   Message += Message2;
324   Message += " TheY = "; 
325   Message += Message3;
326   Message += " TheZ = "; 
327   Message4 = TheZ;
328   Message += Message4;
329
330   PostProcess(aDoc,ID_BUTTON_Test_4,TheDisplayType,Message.ToCString(),1.0 /*0.02*/);
331 }
332
333
334 // Function name        : GeomSources::gpTest5
335 // Description      : 
336 // Return type          : void 
337 // Argument         : CGeometryDoc* aDoc
338 void GeomSources::gpTest5(CGeometryDoc* aDoc)
339 {
340   DisplayType TheDisplayType = No2D3D;
341   PreProcess(aDoc,TheDisplayType);
342 //==============================================================
343                                
344   gp_Pnt P1(1,2,3);              
345   gp_Pnt P2(3,4,5);              
346   gp_Pnt PB = P1;                
347   Standard_Real alpha = 3;       
348   Standard_Real beta = 7;        
349   PB.BaryCenter(alpha,P2,beta);  
350                                
351 //==============================================================
352   TCollection_AsciiString Message ("\
353                                  \n\
354 gp_Pnt P1(1,2,3);                \n\
355 gp_Pnt P2(3,4,5);                \n\
356 gp_Pnt PB = P1;                  \n\
357 Standard_Real alpha = 3;         \n\
358 Standard_Real beta = 7;          \n\
359 PB.BaryCenter(alpha,P2,beta);    \n\
360                                  \n");
361
362   AddSeparator(aDoc,Message);
363 //--------------------------------------------------------------
364
365   DisplayPoint(aDoc,P1,"P1",false,0.2);
366   DisplayPoint(aDoc,P2,"P2",false,0.2);
367   DisplayPoint(aDoc,PB,"PB = barycenter ( 3 * P1 , 7 * P2) ",false,0.2);
368
369   TCollection_AsciiString Message2 (PB.X());
370   TCollection_AsciiString Message3 (PB.Y());
371   TCollection_AsciiString Message4 (PB.Z());
372
373   Message += " PB ( ";
374   Message += Message2; 
375   Message += " , ";
376   Message += Message3; 
377   Message += " , ";
378   Message += Message4; 
379   Message += " ); ";
380   PostProcess(aDoc,ID_BUTTON_Test_5,TheDisplayType,Message.ToCString());
381 }
382
383
384 // Function name        : GeomSources::gpTest6
385 // Description      : 
386 // Return type          : void 
387 // Argument         : CGeometryDoc* aDoc
388 void GeomSources::gpTest6(CGeometryDoc* aDoc)
389 {
390   DisplayType TheDisplayType = No2D3D;
391   PreProcess(aDoc,TheDisplayType);
392 //==============================================================
393                                                                  
394 //  Compute a 3d point P as BaryCenter of an array of point
395   gp_Pnt P1(0,0,5);
396   gp_Pnt P2(1,2,3);
397   gp_Pnt P3(2,3,-2);
398   gp_Pnt P4(4,3,5);
399   gp_Pnt P5(5,5,4);                                                
400   TColgp_Array1OfPnt array (1,5); // sizing array                  
401   array.SetValue(1,P1);
402   array.SetValue(2,P2);
403   array.SetValue(3,P3);
404   array.SetValue(4,P4);
405   array.SetValue(5,P5);
406
407   Standard_Real Tolerance = 8; // ajout de la tolerance            
408   GProp_PEquation PE (array,Tolerance);
409
410   gp_Pnt P; // P declaration
411   Standard_Boolean IsPoint;
412
413   if (PE.IsPoint())
414   {
415     IsPoint = true;
416     P = PE .Point();
417   }
418   else 
419   { 
420     IsPoint = false;
421   }                     
422
423   if (PE.IsLinear()){ /*... */ }
424   if (PE.IsPlanar()){ /*... */ }
425   if (PE.IsSpace()) { /*... */ }
426                                                                  
427 //==============================================================
428   TCollection_AsciiString Message ("\
429                                                                  \n\
430                                                                  \n\
431 //  Compute a 3d point P as BaryCenter of an array of point      \n\
432 gp_Pnt P1(0,0,5);                                                \n\
433 gp_Pnt P2(1,2,3);                                                \n\
434 gp_Pnt P3(2,3,-2);                                               \n\
435 gp_Pnt P4(4,3,5);                                                \n\
436 gp_Pnt P5(5,5,4);                                                \n\
437 TColgp_Array1OfPnt array (1,5); // sizing array                  \n\
438 array.SetValue(1,P1);                                            \n\
439 array.SetValue(2,P2);                                            \n\
440 array.SetValue(3,P3);                                            \n\
441 array.SetValue(4,P4);                                            \n\
442 array.SetValue(5,P5);                                            \n\
443                                                                  \n\
444 Standard_Real Tolerance = 8; // ajout de la tolerance            \n\
445 GProp_PEquation PE (array,Tolerance);                            \n\
446                                                                  \n\
447 gp_Pnt P; // P declaration                                       \n\
448 Standard_Boolean IsPoint;                                        \n\
449 if (PE.IsPoint()){IsPoint = true;                                \n\
450                   P = PE .Point();}                              \n\
451                   else { IsPoint = false;  }                     \n\
452 if (PE.IsLinear()){ /*... */ }                                   \n\
453 if (PE.IsPlanar()){ /*... */ }                                   \n\
454 if (PE.IsSpace()) { /*... */ }                                   \n\
455                                                                  \n");
456   AddSeparator(aDoc,Message);
457     //--------------------------------------------------------------
458
459   TCollection_AsciiString PointName("P");
460     
461
462         for(Standard_Integer i= array.Lower();i <= array.Upper(); i++)
463   { 
464     TCollection_AsciiString TheString (i);
465     TheString = PointName+ TheString;
466     DisplayPoint(aDoc,array(i),TheString.ToCString(),false,0.5);
467   }
468
469   DisplayPoint(aDoc,P,"P",false,0.5);
470   TCollection_AsciiString Message2 (P.X());
471   TCollection_AsciiString Message3 (P.Y());
472   TCollection_AsciiString Message4 (P.Z());
473
474   Message += " IsPoint = ";
475   if (IsPoint) 
476   {
477     Message += "True   -->  ";
478     Message += " P ( ";
479
480     Message += Message2; Message += " , ";
481     Message += Message3; Message += " , ";
482     Message += Message4; Message += " ); \n";
483         }  
484   else 
485     Message += "False\n";
486
487   Message += " IsLinear = ";  
488   if (PE.IsLinear()) 
489     Message += "True \n"; 
490   else
491     Message += "False\n";
492
493   Message += " IsPlanar = ";
494   if (PE.IsPlanar())
495     Message += "True \n";
496   else
497     Message += "False\n";
498
499   Message += " IsSpace = ";
500   if
501     (PE.IsSpace())
502     Message += "True \n";
503   else
504     Message += "False\n";
505
506     PostProcess(aDoc,ID_BUTTON_Test_6,TheDisplayType,Message.ToCString());
507 }
508
509 // Function name        : GeomSources::gpTest7
510 // Description      : 
511 // Return type          : void 
512 // Argument         : CGeometryDoc* aDoc
513 void GeomSources::gpTest7(CGeometryDoc* aDoc)
514 {
515   DisplayType TheDisplayType = a2DNo3D;
516   PreProcess(aDoc,TheDisplayType);
517 //==============================================================
518                                            
519   gp_Pnt2d P1(0,5);                                       
520   gp_Pnt2d P2(5.5,1);                                     
521   gp_Pnt2d P3(-2,2);                                      
522
523   Handle(Geom2d_TrimmedCurve) C =                         
524     GCE2d_MakeArcOfCircle (P1,P2,P3).Value();           
525
526   Standard_Real FirstParameter = C->FirstParameter();
527   Standard_Real LastParameter = C->LastParameter();
528   Standard_Real MiddleParameter = (FirstParameter+LastParameter)/2;
529   Standard_Real param = MiddleParameter; //in radians    
530
531   gp_Pnt2d P;                                             
532   gp_Vec2d V;                                             
533   C->D1(param,P,V);                          
534 // we recover point P and the vector V     
535                                            
536 //==============================================================
537   TCollection_AsciiString Message ("\
538                                                     \n\
539                                                     \n\
540 gp_Pnt2d P1(0,5);                                   \n\
541 gp_Pnt2d P2(5.5,1);                                 \n\
542 gp_Pnt2d P3(-2,2);                                  \n\
543                                                     \n\
544 Handle(Geom2d_TrimmedCurve) C =                     \n\
545     GCE2d_MakeArcOfCircle (P1,P2,P3).Value();       \n\
546                                                     \n\
547 Standard_Real FirstParameter = C->FirstParameter(); \n\
548 Standard_Real LastParameter = C->LastParameter();   \n\
549 Standard_Real MiddleParameter =                     \n\
550            (FirstParameter+LastParameter)/2;        \n\
551 Standard_Real param = MiddleParameter; //in radians \n\
552                                                     \n\
553 gp_Pnt2d P;                                         \n\
554 gp_Vec2d V;                                         \n\
555 C->D1(param,P,V);                                   \n\
556 // we recover point P and the vector V              \n\
557                                                     \n");
558   AddSeparator(aDoc,Message);
559   //--------------------------------------------------------------
560
561   DisplayCurve(aDoc,C);
562   Handle(ISession_Direction) aDirection = new ISession_Direction(P,V);
563   aDoc->GetISessionContext()->Display(aDirection, Standard_False);
564
565   DisplayPoint(aDoc,P,"P",false,0.5);
566
567   PostProcess(aDoc,ID_BUTTON_Test_7,TheDisplayType,Message.ToCString());
568 }
569
570 // Function name        : GeomSources::gpTest8
571 // Description      : 
572 // Return type          : void 
573 // Argument         : CGeometryDoc* aDoc
574 void GeomSources::gpTest8(CGeometryDoc* aDoc)
575 {
576   DisplayType TheDisplayType = a2DNo3D;
577   PreProcess(aDoc,TheDisplayType);
578 //==============================================================
579                                                    
580   Standard_Real radius = 5;                          
581   Handle(Geom2d_Circle) C =                          
582     new Geom2d_Circle(gp::OX2d(),radius);          
583   Standard_Real param = 1.2*M_PI;                      
584   Geom2dLProp_CLProps2d CLP                          
585     (C,param,2,Precision::PConfusion());           
586   gp_Dir2d D;                                    
587   CLP.Tangent(D);                                    
588 // D is the Tangent direction at parameter 1.2*PI  
589                                                    
590 //==============================================================
591   TCollection_AsciiString Message (" \
592                                                    \n\
593 Standard_Real radius = 5;                          \n\
594 Handle(Geom2d_Circle) C =                          \n\
595     new Geom2d_Circle(gp::OX2d(),radius);          \n\
596 Standard_Real param = 1.2*PI;                      \n\
597 Geom2dLProp_CLProps2d CLP                          \n\
598     (C,param,2,Precision::PConfusion());           \n\
599     gp_Dir2d D;                                    \n\
600 CLP.Tangent(D);                                    \n\
601 // D is the Tangent direction at parameter 1.2*PI  \n\
602                                                    \n");
603   AddSeparator(aDoc,Message);
604   //--------------------------------------------------------------
605   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(C);
606   aDoc->GetISessionContext()->Display(aCurve,Standard_False);
607   Handle(ISession_Direction) aDirection = new ISession_Direction(gp_Pnt2d(0,0),D,2);
608   aDoc->GetISessionContext()->Display(aDirection,Standard_False);
609
610   TCollection_AsciiString Message2 (D.X());
611   TCollection_AsciiString Message3 (D.Y());
612
613   Message += " D ( ";
614   Message += Message2; Message += " , ";
615   Message += Message3; Message += " ); \n";
616
617   PostProcess(aDoc,ID_BUTTON_Test_8,TheDisplayType,Message.ToCString());
618 }
619
620 // Function name        : GeomSources::gpTest9
621 // Description      : 
622 // Return type          : void 
623 // Argument         : CGeometryDoc* aDoc
624 void GeomSources::gpTest9(CGeometryDoc* aDoc)
625 {
626   DisplayType TheDisplayType = a2DNo3D;
627   PreProcess(aDoc,TheDisplayType);
628
629   //==============================================================
630                                                              
631   Standard_Real radius = 5;                                    
632   Handle(Geom2d_Circle) C =                                    
633     new Geom2d_Circle(gp::OX2d(),radius);                    
634   Geom2dAdaptor_Curve GAC (C);                                 
635   Standard_Real startparam = 10*M_PI/180;                                
636   Standard_Real abscissa = 45*M_PI/180;                                  
637   gp_Pnt2d P1;
638   C->D0(startparam,P1);                                                
639   // abscissa is the distance along the curve from startparam  
640   GCPnts_AbscissaPoint AP (GAC, abscissa, startparam);         
641   gp_Pnt2d P2;                                                  
642   if (AP.IsDone()){C->D0(AP.Parameter(),P2);}                   
643   // P is now correctly set                                    
644
645   //==============================================================
646   TCollection_AsciiString Message (" \n\
647                                                              \n\
648                                                              \n\
649 Standard_Real radius = 5;                                    \n\
650 Handle(Geom2d_Circle) C =                                    \n\
651     new Geom2d_Circle(gp::OX2d(),radius);                    \n\
652 Geom2dAdaptor_Curve GAC (C);                                 \n\
653 Standard_Real startparam = 10*PI180;                            \n\
654 Standard_Real abscissa = 45*PI180;                                 \n\
655 gp_Pnt2d P1;                                                 \n\
656 C->D0(startparam,P1);                                                \n\
657 // abscissa is the distance along the curve from startparam  \n\
658 GCPnts_AbscissaPoint AP (GAC, abscissa, startparam);         \n\
659 gp_Pnt2d P2;                                                  \n\
660 if (AP.IsDone()){C->D0(AP.Parameter(),P2);}                   \n\
661 // P is now correctly set                                    \n\
662                                                              \n\
663                                                              \n");
664   AddSeparator(aDoc,Message);
665   //--------------------------------------------------------------
666   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(C);
667   aDoc->GetISessionContext()->Display(aCurve,Standard_False);
668
669   DisplayPoint(aDoc,P1,"P1");
670   if (AP.IsDone())    DisplayPoint(aDoc,P2,"P2");
671
672   TCollection_AsciiString Message2 (P1.X());
673   TCollection_AsciiString Message3 (P1.Y());
674
675   TCollection_AsciiString Message4 (P2.X());
676   TCollection_AsciiString Message5 (P2.Y());
677
678   Message += " P1 ( ";
679   Message += Message2; Message += " , ";
680   Message += Message3; Message += " ); \n";
681
682   Message += " P2 ( ";
683   Message += Message4; Message += " , ";
684   Message += Message5; Message += " ); \n";
685   PostProcess(aDoc,ID_BUTTON_Test_9,TheDisplayType,Message.ToCString());
686 }
687
688 // Function name        : GeomSources::gpTest10
689 // Description      : 
690 // Return type          : void 
691 // Argument         : CGeometryDoc* aDoc
692 void GeomSources::gpTest10(CGeometryDoc* aDoc)
693 {
694   DisplayType TheDisplayType = a2DNo3D;
695   PreProcess(aDoc,TheDisplayType);
696   //==============================================================
697                                                         
698   gp_Pnt2d P;
699   Standard_Real radius = 5;
700   Handle(Geom2d_Circle) C =
701     new Geom2d_Circle(gp::OX2d(),radius);
702   Geom2dAdaptor_Curve GAC (C);
703   Standard_Real abscissa = 3;
704   GCPnts_UniformAbscissa UA (GAC,abscissa);
705   TColgp_SequenceOfPnt2d aSequence;
706   if (UA.IsDone())
707   {                                                     
708     Standard_Real N = UA.NbPoints();
709     Standard_Integer count = 1;
710     for(;count<=N;count++)
711     {                                                  
712       C->D0(UA.Parameter(count),P);
713       //Standard_Real Parameter = UA.Parameter(count);
714       // append P in a Sequence
715       aSequence.Append(P);
716     }                                                   
717   }                                                       
718   Standard_Real Abscissa  = UA.Abscissa();                
719                                                         
720   //==============================================================
721   TCollection_AsciiString Message (" \
722                                                         \n\
723 gp_Pnt2d P;                                             \n\
724 Standard_Real radius = 5;                               \n\
725 Handle(Geom2d_Circle) C =                               \n\
726     new Geom2d_Circle(gp::OX2d(),radius);               \n\
727 Geom2dAdaptor_Curve GAC (C);                            \n\
728 Standard_Real abscissa = 3;                             \n\
729 GCPnts_UniformAbscissa UA (GAC,abscissa);               \n\
730 TColgp_SequenceOfPnt2d aSequence;                       \n\
731 if (UA.IsDone())                                        \n\
732   {                                                     \n\
733     Standard_Real N = UA.NbPoints();                    \n\
734     Standard_Integer count = 1;                         \n\
735     for(;count<=N;count++)                              \n\
736      {                                                  \n\
737         C->D0(UA.Parameter(count),P);                   \n\
738         Standard_Real Parameter = UA.Parameter(count);  \n\
739         // append P in a Sequence                       \n\
740         aSequence.Append(P);                            \n\
741     }                                                   \n\
742 }                                                       \n\
743 Standard_Real Abscissa  = UA.Abscissa();                \n\
744                                                         \n");
745   AddSeparator(aDoc,Message);
746   //--------------------------------------------------------------
747   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(C);
748   aDoc->GetISessionContext()->Display(aCurve,Standard_False);
749
750   TCollection_AsciiString aString;
751   for (Standard_Integer i=1;i<= aSequence.Length();i++)
752   {
753
754     TCollection_AsciiString Message2 (i);
755     TCollection_AsciiString Message3 (UA.Parameter(i));
756
757     aString = "P";
758     aString += Message2; 
759     aString +=": Parameter : "; 
760     aString += Message3;
761
762     //   First and Last texts are displayed with an Y offset, point 4 is upper
763     Standard_Real YOffset = -0.3;
764     YOffset +=  0.2 * ( i == 1 );
765     YOffset +=  0.4 * ( i == 4 );
766     YOffset += -0.2 * ( i == aSequence.Length() ); 
767
768     DisplayPoint(aDoc,aSequence(i),aString.ToCString(),false,0.5,YOffset,0.04);
769   }
770
771   TCollection_AsciiString Message3 (Abscissa);
772
773   Message += "Abscissa  = ";
774   Message += Message3;
775   Message += " \n";
776
777   PostProcess(aDoc,ID_BUTTON_Test_10,TheDisplayType,Message.ToCString());
778 }
779
780 // Function name        : GeomSources::gpTest11
781 // Description      : 
782 // Return type          : void 
783 // Argument         : CGeometryDoc* aDoc
784 void GeomSources::gpTest11(CGeometryDoc* aDoc)
785 {
786   DisplayType TheDisplayType = No2D3D;
787   PreProcess(aDoc,TheDisplayType);
788   //==============================================================
789                  
790   Standard_Real radius = 5;
791   Handle(Geom_SphericalSurface) SP =
792     new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);
793   Standard_Real u = 2;
794   Standard_Real v = 3;
795   gp_Pnt P = SP->Value(u,v);                
796                        
797 //==============================================================
798     TCollection_AsciiString Message (" \
799                                                           \n\
800 Standard_Real radius = 5;                                 \n\
801 Handle(Geom_SphericalSurface) SP =                        \n\
802     new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);  \n\
803 Standard_Real u = 2;                                      \n\
804 Standard_Real v = 3;                                      \n\
805 gp_Pnt P = SP->Value(u,v);                                \n\
806                                                           \n");
807   AddSeparator(aDoc,Message);
808   //--------------------------------------------------------------
809
810   DisplaySurface(aDoc,SP);
811   DisplayPoint(aDoc,P,"P",false,0.5);
812   TCollection_AsciiString Message2 (P.X());
813   TCollection_AsciiString Message3 (P.Y());
814         
815   Message += " P ( ";
816   Message += Message2; 
817   Message += " , ";
818   Message += Message3; 
819   Message += " ); \n";
820
821   PostProcess(aDoc,ID_BUTTON_Test_11,TheDisplayType,Message.ToCString());
822 }
823
824 // Function name        : GeomSources::gpTest12
825 // Description      : 
826 // Return type          : void 
827 // Argument         : CGeometryDoc* aDoc
828 void GeomSources::gpTest12(CGeometryDoc* aDoc)
829 {
830   DisplayType TheDisplayType = No2D3D;
831   PreProcess(aDoc,TheDisplayType);
832   //==============================================================
833
834   gp_Pnt N,Q,P(1,2,3);
835   Standard_Real distance, radius = 5;
836   Handle(Geom_Circle) C = new Geom_Circle(gp::XOY(),radius);
837   GeomAPI_ProjectPointOnCurve PPC (P,C);
838   N = PPC.NearestPoint();
839   Standard_Integer NbResults = PPC.NbPoints();
840
841   if(NbResults>0)
842   {
843     for(Standard_Integer i = 1;i<=NbResults;i++)
844     {
845       Q = PPC.Point(i);
846       distance = PPC.Distance(i);
847       // do something with Q or distance here
848     }
849   }                                                          
850
851   //==============================================================
852   TCollection_AsciiString Message (" \
853                                                             \n\
854 gp_Pnt N,Q,P(1,2,3);                                        \n\
855 Standard_Real distance, radius = 5;                         \n\
856 Handle(Geom_Circle) C = new Geom_Circle(gp::XOY(),radius);  \n\
857 GeomAPI_ProjectPointOnCurve PPC (P,C);                      \n\
858 N = PPC.NearestPoint();                                     \n\
859 Standard_Integer NbResults = PPC.NbPoints();                \n\
860                                                             \n\
861 if(NbResults>0){                                            \n\
862     for(Standard_Integer i = 1;i<=NbResults;i++){           \n\
863       Q = PPC.Point(i);                                     \n\
864       distance = PPC.Distance(i);                           \n\
865         // do something with Q or distance here             \n\
866       }                                                     \n\
867  }                                                          \n\
868                                                             \n");
869     AddSeparator(aDoc,Message);
870 //--------------------------------------------------------------
871
872   TCollection_AsciiString aString;
873
874   DisplayPoint(aDoc,P,"P",false,0.5);
875
876   TCollection_AsciiString Message2 (PPC.LowerDistance());
877
878   aString = "N : at Distance : "; 
879   aString += Message2;
880
881   DisplayPoint(aDoc,N,aString.ToCString(),false,0.5,0,-0.5);
882   DisplayCurve(aDoc,C,false);
883
884   if(NbResults>0)
885   {
886     for(Standard_Integer i = 1;i<=NbResults;i++)
887     {
888       Q = PPC.Point(i);
889       distance = PPC.Distance(i);       
890       TCollection_AsciiString Message3 (i);
891       TCollection_AsciiString Message4 (distance);
892
893       aString = "Q";
894       aString += Message3; 
895       aString +=": at Distance : "; 
896       aString += Message4;
897       DisplayPoint(aDoc,Q,aString.ToCString(),false,0.5);
898     }
899   }
900
901   PostProcess(aDoc,ID_BUTTON_Test_12,TheDisplayType,Message.ToCString());
902 }
903
904 // Function name        : GeomSources::gpTest13
905 // Description      : 
906 // Return type          : void 
907 // Argument         : CGeometryDoc* aDoc
908 void GeomSources::gpTest13(CGeometryDoc* aDoc)
909 {
910   DisplayType TheDisplayType = No2D3D;
911   PreProcess(aDoc,TheDisplayType);
912
913   //==============================================================
914         
915   gp_Pnt N,Q,P(7,8,9);
916   Standard_Real distance, radius = 5;
917   Handle(Geom_SphericalSurface) SP =
918     new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);
919   GeomAPI_ProjectPointOnSurf PPS(P,SP);
920   N = PPS.NearestPoint();
921   Standard_Integer NbResults = PPS.NbPoints();
922   if(NbResults>0)
923   {
924     for(Standard_Integer i = 1;i<=NbResults;i++)
925     {
926       Q = PPS.Point(i);
927       distance = PPS.Distance(i);
928       // do something with Q or distance here
929     }
930   }                                                         
931                                                           
932   //==============================================================
933     TCollection_AsciiString Message (" \
934                                                           \n\
935 gp_Pnt N,Q,P(7,8,9);                                      \n\
936 Standard_Real distance, radius = 5;                       \n\
937 Handle(Geom_SphericalSurface) SP =                        \n\
938     new Geom_SphericalSurface(gp_Ax3(gp::XOY()),radius);  \n\
939 GeomAPI_ProjectPointOnSurf PPS(P,SP);                     \n\
940 N = PPS.NearestPoint();                                   \n\
941 Standard_Integer NbResults = PPS.NbPoints();              \n\
942 if(NbResults>0){                                          \n\
943     for(Standard_Integer i = 1;i<=NbResults;i++){         \n\
944     Q = PPS.Point(i);                                     \n\
945     distance = PPS.Distance(i);                           \n\
946     // do something with Q or distance here               \n\
947     }                                                     \n\
948 }                                                         \n\
949                                                           \n");
950  AddSeparator(aDoc,Message);
951  //--------------------------------------------------------------
952  TCollection_AsciiString aString;
953
954  DisplayPoint(aDoc,P,"P",false,0.5);
955  TCollection_AsciiString Message2 (PPS.LowerDistance());
956
957  aString = "N  : at Distance : "; aString += Message2;
958  DisplayPoint(aDoc,N,aString.ToCString(),false,0.5,0,-0.6);
959
960  Handle(ISession_Surface) aSurface = new ISession_Surface(SP);
961  Handle (AIS_Drawer) CurDrawer = aSurface->Attributes();
962  CurDrawer->UIsoAspect()->SetNumber(10);
963  CurDrawer->VIsoAspect()->SetNumber(10);
964  aDoc->GetAISContext()->SetLocalAttributes(aSurface, CurDrawer);
965  aDoc->GetAISContext()->Display(aSurface, Standard_False);
966
967  if(NbResults>0)
968  {
969    for(Standard_Integer i = 1;i<=NbResults;i++)
970    {
971
972      Q = PPS.Point(i);
973      distance = PPS.Distance(i);        
974      TCollection_AsciiString Message3 (i);
975      TCollection_AsciiString Message4 (distance);
976
977      aString = "Q";
978      aString += Message3; 
979      aString +=": at Distance : "; 
980      aString += Message4;
981
982      DisplayPoint(aDoc,Q,aString.ToCString(),false,0.5);                        
983    }
984  }
985  PostProcess(aDoc,ID_BUTTON_Test_13,TheDisplayType,Message.ToCString());
986 }
987
988 // Function name        : GeomSources::gpTest14
989 // Description      : 
990 // Return type          : void 
991 // Argument         : CGeometryDoc* aDoc
992 void GeomSources::gpTest14(CGeometryDoc* aDoc)
993 {
994   DisplayType TheDisplayType = No2D3D;
995   PreProcess(aDoc,TheDisplayType);
996   //==============================================================
997                                                           
998   gp_Pnt P; 
999   gp_Ax3 theAxe(gp::XOY());
1000   gp_Pln PL(theAxe);                            
1001   Standard_Real MinorRadius = 5;                            
1002   Standard_Real MajorRadius = 8;                            
1003   gp_Elips EL (gp::YOZ(),MajorRadius,MinorRadius);          
1004   IntAna_IntConicQuad ICQ                                   
1005     (EL,PL,Precision::Angular(),Precision::Confusion());  
1006   if (ICQ.IsDone()){                                        
1007     Standard_Integer NbResults = ICQ.NbPoints();          
1008     if (NbResults>0){                                     
1009       for(Standard_Integer i = 1;i<=NbResults;i++){         
1010         P = ICQ.Point(i);                                 
1011         // do something with P here                       
1012       }                                                 
1013     }                                                      
1014   }                                                         
1015                                                           
1016   //==============================================================
1017   TCollection_AsciiString Message (" \
1018                                                           \n\
1019 gp_Pnt P;                                                 \n\
1020 gp_Pln PL (gp_Ax3(gp::XOY()));                            \n\
1021 Standard_Real MinorRadius = 5;                            \n\
1022 Standard_Real MajorRadius = 8;                            \n\
1023 gp_Elips EL (gp::YOZ(),MajorRadius,MinorRadius);          \n\
1024 IntAna_IntConicQuad ICQ                                   \n\
1025     (EL,PL,Precision::Angular(),Precision::Confusion());  \n\
1026 if (ICQ.IsDone()){                                        \n\
1027     Standard_Integer NbResults = ICQ.NbPoints();          \n\
1028     if (NbResults>0){                                     \n\
1029     for(Standard_Integer i = 1;i<=NbResults;i++){         \n\
1030         P = ICQ.Point(i);                                 \n\
1031         // do something with P here                       \n\
1032         }                                                 \n\
1033    }                                                      \n\
1034 }                                                         \n\
1035                                                           \n");
1036  AddSeparator(aDoc,Message);
1037  //--------------------------------------------------------------
1038
1039  Handle(Geom_Plane) aPlane = GC_MakePlane(PL).Value();
1040  Handle(Geom_RectangularTrimmedSurface) aSurface= new Geom_RectangularTrimmedSurface(aPlane,-8.,8.,-12.,12.);
1041
1042  DisplaySurface(aDoc,aSurface);
1043
1044  Handle(Geom_Ellipse) anEllips = GC_MakeEllipse(EL).Value();
1045  DisplayCurve(aDoc,anEllips,false);
1046
1047  TCollection_AsciiString aString;
1048
1049  if (ICQ.IsDone())
1050  {
1051    Standard_Integer NbResults = ICQ.NbPoints();
1052    if (NbResults>0)
1053    {
1054      for(Standard_Integer i = 1;i<=NbResults;i++)
1055      {
1056
1057        TCollection_AsciiString Message2(i);
1058
1059        P = ICQ.Point(i);
1060        aString = "P";aString += Message2; 
1061        DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
1062      }
1063    }
1064  }
1065
1066  PostProcess(aDoc,ID_BUTTON_Test_14,TheDisplayType,Message.ToCString());
1067 }
1068
1069 // Function name        : GeomSources::gpTest15
1070 // Description      : 
1071 // Return type          : void 
1072 // Argument         : CGeometryDoc* aDoc
1073 void GeomSources::gpTest15(CGeometryDoc* aDoc)
1074 {
1075   DisplayType TheDisplayType = No2D3D;
1076   PreProcess(aDoc,TheDisplayType);
1077   //==============================================================
1078  
1079   gp_Pnt P1(1,2,3);    
1080   gp_Pnt P1Copy = P1;  
1081   gp_Pnt P2(5,4,6);    
1082   gp_Trsf TRSF;        
1083   TRSF.SetMirror(P2);  
1084   P1Copy.Transform(TRSF);  
1085
1086   //==============================================================
1087     TCollection_AsciiString Message (" \
1088                          \n\
1089 gp_Pnt P1(1,2,3);        \n\
1090 gp_Pnt P1Copy = P1;      \n\
1091 gp_Pnt P2(5,4,6);        \n\
1092 gp_Trsf TRSF;            \n\
1093 TRSF.SetMirror(P2);      \n\
1094 P1Copy.Transform(TRSF);  \n\
1095                          \n");
1096  AddSeparator(aDoc,Message);
1097  //--------------------------------------------------------------
1098
1099  DisplayPoint(aDoc,P1Copy,"P1Copy",false,0.5);
1100  DisplayPoint(aDoc,P1,"P1",false,0.5);
1101  DisplayPoint(aDoc,P2,"P2",false,0.5);
1102
1103  PostProcess(aDoc,ID_BUTTON_Test_15,TheDisplayType,Message.ToCString());
1104 }
1105
1106 // Function name        : GeomSources::gpTest16
1107 // Description      : 
1108 // Return type          : void 
1109 // Argument         : CGeometryDoc* aDoc
1110 void GeomSources::gpTest16(CGeometryDoc* aDoc)
1111 {
1112   DisplayType TheDisplayType = No2D3D;
1113   PreProcess(aDoc,TheDisplayType);
1114 //==============================================================
1115                                          
1116   gp_Pnt P1(1,2,3);                        
1117   gp_Pnt P2(5,4,6);                        
1118   gp_Vec V1 (P1,P2);                       
1119
1120   gp_Pnt P3(10,4,7);                       
1121   gp_Pnt P4(2,0,1);                        
1122   gp_Vec V2 (P3,P4);                       
1123
1124   Standard_Boolean result =                
1125     V1.IsOpposite(V2,Precision::Angular());  
1126   // result should be true                 
1127                                          
1128 //==============================================================
1129   TCollection_AsciiString Message (" \
1130                                          \n\
1131 gp_Pnt P1(1,2,3);                        \n\
1132 gp_Pnt P2(5,4,6);                        \n\
1133 gp_Vec V1 (P1,P2);                       \n\
1134                                          \n\
1135 gp_Pnt P3(10,4,7);                       \n\
1136 gp_Pnt P4(2,0,1);                        \n\
1137 gp_Vec V2 (P3,P4);                       \n\
1138                                          \n\
1139 Standard_Boolean result =                \n\
1140 V1.IsOpposite(V2,Precision::Angular());  \n\
1141 // result should be true                 \n\
1142                                          \n");
1143  AddSeparator(aDoc,Message);
1144  //--------------------------------------------------------------
1145
1146  DisplayPoint(aDoc,P1,"P1",false,0.5);
1147  DisplayPoint(aDoc,P2,"P2",false,0.5);
1148  DisplayPoint(aDoc,P3,"P3",false,0.5);
1149  DisplayPoint(aDoc,P4,"P4",false,0.5);
1150
1151  Handle(ISession_Direction) aDirection1 = new ISession_Direction(P1,V1);
1152  aDoc->GetAISContext()->Display(aDirection1, Standard_False);
1153
1154  Handle(ISession_Direction) aDirection2 = new ISession_Direction(P3,V2);
1155  aDoc->GetAISContext()->Display(aDirection2, Standard_False);
1156
1157  Message += "result = ";
1158  if (result) Message += "True \n"; else Message += "False \n";
1159
1160  PostProcess(aDoc,ID_BUTTON_Test_16,TheDisplayType,Message.ToCString());
1161 }
1162
1163 // Function name        : GeomSources::gpTest17
1164 // Description      : 
1165 // Return type          : void 
1166 // Argument         : CGeometryDoc* aDoc
1167 void GeomSources::gpTest17(CGeometryDoc* aDoc)
1168 {
1169   DisplayType TheDisplayType = No2D3D;
1170   PreProcess(aDoc,TheDisplayType);
1171   //==============================================================
1172
1173   gp_Dir D1(1,2,3);
1174   gp_Dir D2(3,4,5);
1175   Standard_Real ang = D1.Angle(D2);
1176   // the result is in radians in the range [0,PI]  
1177                                                  
1178   //==============================================================
1179   TCollection_AsciiString Message (" \
1180                                                  \n\
1181 gp_Dir D1(1,2,3);                                \n\
1182 gp_Dir D2(3,4,5);                                \n\
1183 Standard_Real ang = D1.Angle(D2);                \n\
1184 // the result is in radians in the range [0,PI]  \n\
1185                                                  \n");
1186   AddSeparator(aDoc,Message);
1187   //--------------------------------------------------------------
1188
1189   Handle(ISession_Direction) aDirection1 = new ISession_Direction(gp_Pnt(0,0,0),D1,3);
1190   aDoc->GetAISContext()->Display(aDirection1, Standard_False);
1191
1192   Handle(ISession_Direction) aDirection2 = new ISession_Direction(gp_Pnt(0,0,0),D2,3);
1193   aDoc->GetAISContext()->Display(aDirection2, Standard_False);
1194
1195   cout<<" D1.Angle(D2) : "<<ang<<endl;
1196
1197   TCollection_AsciiString Message2 (ang);
1198   TCollection_AsciiString Message3 (ang/M_PI/180);
1199
1200   Message += " ang =  "; 
1201   Message += Message2; 
1202   Message += "   radian \n";
1203   Message += " ang/PI180 =  "; 
1204   Message += Message3; 
1205   Message += "   degree \n";
1206
1207   PostProcess(aDoc,ID_BUTTON_Test_17,TheDisplayType,Message.ToCString());
1208 }
1209
1210 // Function name        : GeomSources::gpTest18
1211 // Description      : 
1212 // Return type          : void 
1213 // Argument         : CGeometryDoc* aDoc
1214 void GeomSources::gpTest18(CGeometryDoc* aDoc)
1215 {
1216   DisplayType TheDisplayType = a2DNo3D;
1217   PreProcess(aDoc,TheDisplayType);
1218   //==============================================================
1219
1220   gp_Pnt2d P(2,3);
1221   gp_Dir2d D(4,5);
1222   gp_Ax22d A(P,D);
1223   gp_Parab2d Para(A,6);
1224   // P is the vertex point                  
1225   // P and D give the axis of symmetry      
1226   // 6 is the focal length of the parabola
1227
1228   //==============================================================
1229   TCollection_AsciiString Message (" \
1230                                           \n\
1231 gp_Pnt2d P(2,3);                          \n\
1232 gp_Dir2d D(4,5);                          \n\
1233 gp_Ax22d A(P,D);                          \n\
1234 gp_Parab2d Para(A,6);                     \n\
1235 // P is the vertex point                  \n\
1236 // P and D give the axis of symmetry      \n\
1237 // 6 is the focal length of the parabola  \n\
1238                                           \n");
1239   AddSeparator(aDoc,Message);
1240   //--------------------------------------------------------------
1241
1242   DisplayPoint(aDoc,P,"P",false,0.5,0,3);
1243
1244   Handle(ISession_Direction) aDirection = new ISession_Direction(P,D,200);
1245   aDoc->GetISessionContext()->Display(aDirection,Standard_False);
1246   Handle(Geom2d_Parabola) aParabola = GCE2d_MakeParabola(Para);
1247   Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aParabola,-100,100);
1248   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aTrimmedCurve);
1249   //aCurve->SetColorIndex(3);
1250   aDoc->GetISessionContext()->Display(aCurve, Standard_False);  
1251
1252   Message += " The entity A of type gp_Ax22d is not displayable \n ";
1253   Message += " The entity D of type gp_Dir2d is displayed as a vector \n    ( mean with a length != 1 ) \n ";
1254   PostProcess(aDoc,ID_BUTTON_Test_18,TheDisplayType,Message.ToCString());
1255 }
1256
1257 // Function name        : GeomSources::gpTest19
1258 // Description      : 
1259 // Return type          : void 
1260 // Argument         : CGeometryDoc* aDoc
1261 void GeomSources::gpTest19(CGeometryDoc* aDoc)
1262 {
1263   DisplayType TheDisplayType = No2D3D;
1264   PreProcess(aDoc,TheDisplayType);
1265   //==============================================================
1266   
1267   gp_Pnt P1(2,3,4);                           
1268   gp_Dir D(4,5,6);                            
1269   gp_Ax3 A(P1,D);                              
1270   Standard_Boolean IsDirectA = A.Direct();    
1271
1272   gp_Dir AXDirection = A.XDirection() ;       
1273   gp_Dir AYDirection = A.YDirection() ;       
1274
1275   gp_Pnt P2(5,3,4);                           
1276   gp_Ax3 A2(P2,D);                            
1277   A2.YReverse();                              
1278   // axis3 is now left handed                 
1279   Standard_Boolean IsDirectA2 = A2.Direct();  
1280               
1281   gp_Dir A2XDirection = A2.XDirection() ;
1282   gp_Dir A2YDirection = A2.YDirection() ;
1283
1284   //==============================================================
1285   TCollection_AsciiString Message (" \
1286                                             \n\
1287 gp_Pnt P1(2,3,4);                           \n\
1288 gp_Dir D(4,5,6);                            \n\
1289 gp_Ax3 A(P,D);                              \n\
1290 Standard_Boolean IsDirectA = A.Direct();    \n\
1291                                             \n\
1292 gp_Dir AXDirection = A.XDirection() ;       \n\
1293 gp_Dir AYDirection = A.YDirection() ;       \n\
1294                                             \n\
1295 gp_Pnt P2(5,3,4);                           \n\
1296 gp_Ax3 A2(P2,D);                            \n\
1297 A2.YReverse();                              \n\
1298 // axis3 is now left handed                 \n\
1299 Standard_Boolean IsDirectA2 = A2.Direct();  \n\
1300                                             \n\
1301 gp_Dir A2XDirection = A2.XDirection() ;     \n\
1302 gp_Dir A2YDirection = A2.YDirection() ;     \n\
1303                                             \n");
1304  AddSeparator(aDoc,Message);
1305  //--------------------------------------------------------------
1306
1307  // Set style for vector lines
1308  Handle(Prs3d_LineAspect) anAxesAspect = new Prs3d_LineAspect (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 1.0);
1309
1310  DisplayPoint(aDoc,P1,"P1",false,0.1);
1311  Handle(ISession_Direction) aDirection = new ISession_Direction(P1,D,2);
1312  aDoc->GetAISContext()->Display(aDirection, Standard_False);
1313
1314  Handle(ISession_Direction) aDirection2 = new ISession_Direction(P1,AXDirection,2);
1315  aDirection2->SetText("A.XDirection");
1316  aDirection2->SetLineAspect (anAxesAspect);
1317  aDoc->GetAISContext()->Display(aDirection2, Standard_False);
1318  Handle(ISession_Direction) aDirection3 = new ISession_Direction(P1,AYDirection,2);
1319  aDirection3->SetText("A.YDirection");
1320  aDirection3->SetLineAspect (anAxesAspect);
1321  aDoc->GetAISContext()->Display(aDirection3, Standard_False);
1322
1323  DisplayPoint(aDoc,P2,"P2",false,0.1);
1324  Handle(ISession_Direction) aDirection4 = new ISession_Direction(P2,D,2);
1325  aDoc->GetAISContext()->Display(aDirection4, Standard_False);
1326
1327  Handle(ISession_Direction) aDirection5 = new ISession_Direction(P2,A2XDirection,2);
1328  aDirection5->SetText("A2 XDirection");
1329  aDirection5->SetLineAspect (anAxesAspect);
1330  aDoc->GetAISContext()->Display(aDirection5, Standard_False);
1331  Handle(ISession_Direction) aDirection6 = new ISession_Direction(P2,A2YDirection,2);
1332  aDirection6->SetText("A2 YDirection");
1333  aDirection6->SetLineAspect (anAxesAspect);
1334  aDoc->GetAISContext()->Display(aDirection6, Standard_False);
1335
1336  Message += "IsDirectA = ";
1337  if(IsDirectA)
1338    Message += "True = Right Handed \n";
1339  else
1340    Message += "False = Left Handed \n";
1341
1342  Message += "IsDirectA2 = ";
1343  if(IsDirectA2)
1344    Message += "True = Right Handed \n";
1345  else
1346    Message += "False = Left Handed  \n";
1347
1348  PostProcess(aDoc,ID_BUTTON_Test_19,TheDisplayType,Message.ToCString());
1349 }
1350
1351 // Function name        : GeomSources::gpTest20
1352 // Description      : 
1353 // Return type          : void 
1354 // Argument         : CGeometryDoc* aDoc
1355 void GeomSources::gpTest20(CGeometryDoc* aDoc)
1356 {
1357   DisplayType TheDisplayType = a2DNo3D;
1358   PreProcess(aDoc,TheDisplayType);
1359   //==============================================================
1360
1361   TColgp_Array1OfPnt2d array (1,5); // sizing array                    
1362   array.SetValue(1,gp_Pnt2d (0,0));
1363   array.SetValue(2,gp_Pnt2d (1,2));
1364   array.SetValue(3,gp_Pnt2d (2,3));
1365   array.SetValue(4,gp_Pnt2d (4,3));
1366   array.SetValue(5,gp_Pnt2d (5,5));
1367   Handle(Geom2d_BSplineCurve) SPL1 =
1368     Geom2dAPI_PointsToBSpline(array);
1369                                                                      
1370   Handle(TColgp_HArray1OfPnt2d) harray =
1371     new TColgp_HArray1OfPnt2d (1,5); // sizing harray
1372   harray->SetValue(1,gp_Pnt2d (7+ 0,0));
1373   harray->SetValue(2,gp_Pnt2d (7+ 1,2));
1374   harray->SetValue(3,gp_Pnt2d (7+ 2,3));
1375   harray->SetValue(4,gp_Pnt2d (7+ 4,3));
1376   harray->SetValue(5,gp_Pnt2d (7+ 5,5));
1377   Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);
1378   anInterpolation.Perform();
1379   Handle(Geom2d_BSplineCurve) SPL2 = anInterpolation.Curve();
1380
1381   Handle(TColgp_HArray1OfPnt2d) harray2 =
1382     new TColgp_HArray1OfPnt2d (1,5); // sizing harray
1383   harray2->SetValue(1,gp_Pnt2d (11+ 0,0));
1384   harray2->SetValue(2,gp_Pnt2d (11+ 1,2));
1385   harray2->SetValue(3,gp_Pnt2d (11+ 2,3));
1386   harray2->SetValue(4,gp_Pnt2d (11+ 4,3));
1387   harray2->SetValue(5,gp_Pnt2d (11+ 5,5));
1388   Geom2dAPI_Interpolate anInterpolation2(harray2,Standard_True,0.01);
1389   anInterpolation2.Perform();
1390   Handle(Geom2d_BSplineCurve) SPL3 = anInterpolation2.Curve();
1391   // redefined C++ operator allows these assignments
1392  
1393   //==============================================================
1394   TCollection_AsciiString Message (" \
1395                                                                      \n\
1396 TColgp_Array1OfPnt2d array (1,5); // sizing array                    \n\
1397 array.SetValue(1,gp_Pnt2d (0,0));                                    \n\
1398 array.SetValue(2,gp_Pnt2d (1,2));                                    \n\
1399 array.SetValue(3,gp_Pnt2d (2,3));                                    \n\
1400 array.SetValue(4,gp_Pnt2d (4,3));                                    \n\
1401 array.SetValue(5,gp_Pnt2d (5,5));                                    \n\
1402 Handle(Geom2d_BSplineCurve) SPL1 =                                   \n\
1403     Geom2dAPI_PointsToBSpline(array);                                \n\
1404                                                                      \n\
1405 Handle(TColgp_HArray1OfPnt2d) harray =                               \n\
1406     new TColgp_HArray1OfPnt2d (1,5); // sizing harray                \n\
1407 harray->SetValue(1,gp_Pnt2d (7+ 0,0));                               \n\
1408 harray->SetValue(2,gp_Pnt2d (7+ 1,2));                               \n\
1409 harray->SetValue(3,gp_Pnt2d (7+ 2,3));                               \n\
1410 harray->SetValue(4,gp_Pnt2d (7+ 4,3));                               \n\
1411 harray->SetValue(5,gp_Pnt2d (7+ 5,5));                               \n\
1412 Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);   \n\
1413 anInterpolation.Perform();                                           \n\
1414 Handle(Geom2d_BSplineCurve) SPL2 = anInterpolation.Curve();          \n\
1415                                                                      \n\
1416 Handle(TColgp_HArray1OfPnt2d) harray2 =                              \n\
1417     new TColgp_HArray1OfPnt2d (1,5); // sizing harray                \n");
1418   Message += "\
1419 harray2->SetValue(1,gp_Pnt2d (11+ 0,0));                             \n\
1420 harray2->SetValue(2,gp_Pnt2d (11+ 1,2));                             \n\
1421 harray2->SetValue(3,gp_Pnt2d (11+ 2,3));                             \n\
1422 harray2->SetValue(4,gp_Pnt2d (11+ 4,3));                             \n\
1423 harray2->SetValue(5,gp_Pnt2d (11+ 5,5));                             \n\
1424 Geom2dAPI_Interpolate anInterpolation2(harray2,Standard_True,0.01);  \n\
1425 anInterpolation2.Perform();                                          \n\
1426 Handle(Geom2d_BSplineCurve) SPL3 = anInterpolation2.Curve();         \n\
1427 // redefined C++ operator allows these assignments                   \n\
1428                                                                      \n";
1429   AddSeparator(aDoc,Message);
1430   //--------------------------------------------------------------
1431   TCollection_AsciiString aString;
1432         Standard_Integer i;
1433   for(i = array.Lower();i<=array.Upper();i++)
1434   {
1435     gp_Pnt2d P = array(i);
1436     TCollection_AsciiString Message2 (i);
1437     aString = "array ";aString += Message2;
1438     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
1439   }
1440   for( int i = harray->Lower();i<=harray->Upper();i++)
1441   {
1442     gp_Pnt2d P = harray->Value(i);
1443     TCollection_AsciiString Message2 (i);
1444     aString = "harray ";aString += Message2; 
1445     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
1446   }
1447   for( i = harray2->Lower();i<=harray2->Upper();i++)
1448   {
1449     gp_Pnt2d P = harray2->Value(i);
1450     TCollection_AsciiString Message2 (i);
1451     aString = "harray2 ";aString += Message2; 
1452     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
1453   }
1454
1455   if (!SPL1.IsNull())
1456   { 
1457     Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(SPL1);
1458     aCurve->SetColorIndex(3);
1459     aDoc->GetISessionContext()->Display(aCurve, Standard_False);
1460   }
1461   else
1462     MessageBox(0,"SPL1.IsNull()","CasCade Error",MB_ICONERROR);
1463
1464   if (!SPL2.IsNull())
1465   {
1466     Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(SPL2);
1467     aCurve2->SetColorIndex(5);
1468     aDoc->GetISessionContext()->Display(aCurve2, Standard_False);  
1469   }
1470   else
1471     MessageBox(0,"SPL2.IsNull()","CasCade Error",MB_ICONERROR);
1472
1473   if (!SPL3.IsNull())
1474   {
1475     Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(SPL3);
1476     aCurve2->SetColorIndex(6);
1477     aDoc->GetISessionContext()->Display(aCurve2, Standard_False);  
1478   }
1479   else
1480     MessageBox(0,"SPL3.IsNull()","CasCade Error",MB_ICONERROR);
1481
1482   Message += " SPL1  is Red  \n";
1483   Message += " SPL2  is Blue \n";   
1484   Message += " SPL3  is Yellow \n";   
1485
1486   PostProcess(aDoc,ID_BUTTON_Test_20,TheDisplayType,Message.ToCString());
1487 }
1488
1489 void GeomSources::gpTest21(CGeometryDoc* aDoc)
1490 {
1491   DisplayType TheDisplayType = a2DNo3D;
1492   PreProcess(aDoc,TheDisplayType);
1493
1494   //==============================================================
1495
1496   gp_Pnt2d P1(-184, 101);
1497   gp_Pnt2d P2(20 ,84);
1498   Standard_Real aheight = 1;
1499   FairCurve_Batten B (P1,P2,aheight);
1500   B.SetAngle1(22*M_PI/180);
1501   B.SetAngle2(44*M_PI/180);
1502   FairCurve_AnalysisCode anAnalysisCode;
1503   B.Compute(anAnalysisCode);
1504   Handle(Geom2d_BSplineCurve) C = B.Curve();
1505
1506   //==============================================================
1507   TCollection_AsciiString Message (" \
1508                                             \n\
1509 gp_Pnt2d P1(-184, 101);                     \n\
1510 gp_Pnt2d P2(20 ,84);                        \n\
1511 Standard_Real aheight = 1;                  \n\
1512 FairCurve_Batten B (P1,P2,aheight);         \n\
1513 B.SetAngle1(22*PI180);                      \n\
1514 B.SetAngle2(44*PI180);                      \n\
1515 FairCurve_AnalysisCode anAnalysisCode;      \n\
1516 B.Compute(anAnalysisCode);                  \n\
1517 Handle(Geom2d_BSplineCurve) C = B.Curve();  \n\
1518                                             \n");
1519   AddSeparator(aDoc,Message);
1520   //--------------------------------------------------------------
1521
1522   DisplayCurveAndCurvature(aDoc,C,6,Standard_False);               
1523
1524   PostProcess(aDoc,ID_BUTTON_Test_21,TheDisplayType,Message.ToCString());
1525 }
1526
1527 void GeomSources::gpTest22(CGeometryDoc* aDoc)
1528 {
1529   DisplayType TheDisplayType = a2DNo3D;
1530   PreProcess(aDoc,TheDisplayType);
1531
1532   //==============================================================
1533                                                 
1534   gp_Pnt2d P1(-184, 41);                          
1535   gp_Pnt2d P2(20 ,24);                            
1536   Standard_Real aheight = 1;                      
1537   FairCurve_MinimalVariation MV (P1,P2,aheight);  
1538   MV.SetAngle1(22*M_PI/180);                         
1539   MV.SetAngle2(44*M_PI/180);                         
1540
1541   FairCurve_AnalysisCode anAnalysisCode;          
1542   MV.Compute(anAnalysisCode);                     
1543
1544   Handle(Geom2d_BSplineCurve) C = MV.Curve();     
1545
1546   //==============================================================
1547   TCollection_AsciiString Message (" \
1548                                                 \n\
1549 gp_Pnt2d P1(-184, 41);                          \n\
1550 gp_Pnt2d P2(20 ,24);                            \n\
1551 Standard_Real aheight = 1;                      \n\
1552 FairCurve_MinimalVariation MV (P1,P2,aheight);  \n\
1553 MV.SetAngle1(22*PI180);                         \n\
1554 MV.SetAngle2(44*PI180);                         \n\
1555                                                 \n\
1556 FairCurve_AnalysisCode anAnalysisCode;          \n\
1557 MV.Compute(anAnalysisCode);                     \n\
1558                                                 \n\
1559 Handle(Geom2d_BSplineCurve) C = MV.Curve();     \n\
1560                                                 \n");
1561   AddSeparator(aDoc,Message);
1562   //--------------------------------------------------------------
1563
1564   DisplayCurveAndCurvature(aDoc,C,7,Standard_False);                   
1565   DisplayPoint(aDoc,P1,"P1",false,0.5);
1566   DisplayPoint(aDoc,P2,"P2",false,0.5);
1567
1568   PostProcess(aDoc,ID_BUTTON_Test_22,TheDisplayType,Message.ToCString());
1569 }
1570
1571 // Function name        : GeomSources::gpTest23
1572 // Description      : 
1573 // Return type          : void 
1574 // Argument         : CGeometryDoc* aDoc
1575 void GeomSources::gpTest23(CGeometryDoc* aDoc)
1576 {
1577   DisplayType TheDisplayType = a2DNo3D;
1578   PreProcess(aDoc,TheDisplayType);
1579   //==============================================================
1580
1581   Standard_Real major = 12;                                               
1582   Standard_Real minor = 4;                                                
1583   gp_Ax2d axis = gp::OX2d();                                              
1584   Handle(Geom2d_Ellipse) E = GCE2d_MakeEllipse (axis,major,minor);
1585   Handle(Geom2d_TrimmedCurve) TC = new Geom2d_TrimmedCurve(E,-1,2);
1586
1587   // The segment goes in the direction Vfrom P1  
1588   // to the point projected on this line by P2   
1589   // In the example (0,6).
1590   Handle(Geom2d_BSplineCurve) SPL =
1591     Geom2dConvert::CurveToBSplineCurve(TC);
1592
1593   //==============================================================
1594   TCollection_AsciiString Message (" \
1595                                                                    \n\
1596 Standard_Real major = 12;                                          \n\
1597 Standard_Real minor = 4;                                           \n\
1598 gp_Ax2d axis = gp::OX2d();                                         \n\
1599 Handle(Geom2d_Ellipse) E = GCE2d_MakeEllipse (axis,major,minor);   \n\
1600                                                                    \n\
1601 Handle(Geom2d_TrimmedCurve) TC = new Geom2d_TrimmedCurve(E,-1,2);  \n\
1602                                                                    \n\
1603 // The segment goes in the direction Vfrom P1                      \n\
1604 // to the point projected on this line by P2                       \n\
1605 // In the example (0,6).                                           \n\
1606 Handle(Geom2d_BSplineCurve) SPL =                                  \n\
1607     Geom2dConvert::CurveToBSplineCurve(TC);                        \n\
1608                                                                    \n");
1609   AddSeparator(aDoc,Message);
1610   //--------------------------------------------------------------
1611
1612   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(E);
1613   aCurve->SetColorIndex(3); // Red
1614   aCurve->SetTypeOfLine(Aspect_TOL_DOTDASH);
1615   aDoc->GetISessionContext()->Display(aCurve, Standard_False);
1616
1617   Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(SPL);
1618   aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
1619
1620   PostProcess(aDoc,ID_BUTTON_Test_23,TheDisplayType,Message.ToCString());
1621 }
1622
1623 // Function name        : GeomSources::gpTest24
1624 // Description      : 
1625 // Return type          : void 
1626 // Argument         : CGeometryDoc* aDoc
1627 void GeomSources::gpTest24(CGeometryDoc* aDoc)
1628 {
1629   DisplayType TheDisplayType = a2D3D;
1630   PreProcess(aDoc,TheDisplayType);
1631   //==============================================================
1632   
1633   Standard_Real radius = 5;
1634   gp_Ax2d ax2d(gp_Pnt2d(2,3),gp_Dir2d(1,0));
1635
1636   Handle(Geom2d_Circle) circ2d =
1637     new Geom2d_Circle(ax2d,radius);
1638
1639   gp_Ax2d circ2dXAxis = circ2d->XAxis();
1640
1641   // create a 3D curve in a given plane
1642   Handle(Geom_Curve) C3D =
1643     GeomAPI::To3d(circ2d,gp_Pln(gp_Ax3(gp::XOY())));
1644   Handle(Geom_Circle) C3DCircle =
1645     Handle(Geom_Circle)::DownCast(C3D);
1646
1647   gp_Ax1 C3DCircleXAxis = C3DCircle->XAxis();
1648
1649   // project it to a 2D curve in another plane
1650
1651   gp_Pln ProjectionPlane(gp_Pnt(1,1,0),gp_Dir( 1,1,1 ));
1652
1653   Handle(Geom2d_Curve) C2D =
1654     GeomAPI::To2d(C3D,ProjectionPlane);
1655
1656   Handle(Geom2d_Circle) C2DCircle =
1657     Handle(Geom2d_Circle)::DownCast(C2D);
1658   gp_Ax2d C2DCircleXAxis = C2DCircle->XAxis();
1659
1660   //==============================================================
1661   TCollection_AsciiString Message (" \
1662                                                         \n\
1663 Standard_Real radius = 5;                               \n\
1664 gp_Ax2d ax2d(gp_Pnt2d(2,3),gp_Dir2d(1,0));              \n\
1665                                                         \n\
1666 Handle(Geom2d_Circle) circ2d =                          \n\
1667     new Geom2d_Circle(ax2d,radius);                     \n\
1668                                                         \n\
1669 gp_Ax2d circ2dXAxis = circ2d->XAxis();                  \n\
1670                                                         \n\
1671 // create a 3D curve in a given plane                   \n\
1672 Handle(Geom_Curve) C3D =                                \n\
1673     GeomAPI::To3d(circ2d,gp_Pln(gp_Ax3(gp::XOY())));    \n\
1674 Handle(Geom_Circle) C3DCircle =                         \n\
1675    Handle(Geom_Circle)::DownCast(C3D);                  \n\
1676                                                         \n\
1677 gp_Ax1 C3DCircleXAxis = C3DCircle->XAxis();             \n\
1678                                                         \n\
1679 // project it to a 2D curve in another plane            \n\
1680                                                         \n\
1681 gp_Pln ProjectionPlane(gp_Pnt(1,1,0),gp_Dir( 1,1,1 ));  \n\
1682                                                         \n\
1683 Handle(Geom2d_Curve) C2D =                              \n\
1684     GeomAPI::To2d(C3D,ProjectionPlane);                 \n\
1685                                                         \n\
1686 Handle(Geom2d_Circle) C2DCircle =                       \n\
1687   Handle(Geom2d_Circle)::DownCast(C2D);                 \n\
1688 gp_Ax2d C2DCircleXAxis = C2DCircle->XAxis();            \n\
1689                                                         \n");
1690  AddSeparator(aDoc,Message);
1691  //--------------------------------------------------------------
1692  Handle(Geom_Plane) aPlane = GC_MakePlane(gp_Pln(gp_Ax3(gp::XOY()))).Value();
1693  Handle(Geom_RectangularTrimmedSurface) aSurface= new Geom_RectangularTrimmedSurface(aPlane,-8.,8.,-12.,12.);   
1694  DisplaySurface(aDoc,aSurface);
1695
1696  Handle(Geom_Plane) aProjectionPlane = GC_MakePlane(ProjectionPlane).Value();
1697  Handle(Geom_RectangularTrimmedSurface) aProjectionPlaneSurface=
1698    new Geom_RectangularTrimmedSurface(aProjectionPlane,-8.,8.,-12.,12.);
1699
1700  DisplaySurface(aDoc,aProjectionPlaneSurface);
1701
1702  Standard_CString aC3DEntityTypeName = C3D->DynamicType()->Name();        
1703  Standard_CString aC2DEntityTypeName = C2D->DynamicType()->Name();        
1704
1705  Message += " C3D->DynamicType()->Name() = ";
1706  Message += aC3DEntityTypeName; Message += " \n";
1707  Message += " C2D->DynamicType()->Name() = ";
1708  Message += aC2DEntityTypeName; Message += " \n";
1709
1710  DisplayCurve(aDoc,circ2d,4,false);
1711  DisplayCurve(aDoc,C3D,false);
1712  DisplayCurve(aDoc,C2D,5,false);
1713
1714  Handle(ISession_Direction) aC3DCircleXAxisDirection = new ISession_Direction(C3DCircleXAxis.Location(),C3DCircleXAxis.Direction(),5.2);
1715  aDoc->GetAISContext()->Display(aC3DCircleXAxisDirection, Standard_False);
1716
1717  Handle(ISession_Direction) acirc2dXAxisDirection = new ISession_Direction(circ2dXAxis.Location(),circ2dXAxis.Direction(),5.2);
1718  aDoc->GetISessionContext()->Display(acirc2dXAxisDirection, Standard_False);
1719
1720  Handle(ISession_Direction) aC2DCircleXAxisDirection = new ISession_Direction(C2DCircleXAxis.Location(),C2DCircleXAxis.Direction(),5.2);
1721  aDoc->GetISessionContext()->Display(aC2DCircleXAxisDirection, Standard_False);
1722
1723  PostProcess(aDoc,ID_BUTTON_Test_24,TheDisplayType,Message.ToCString());
1724 }
1725
1726 // Function name        : GeomSources::gpTest25
1727 // Description      : 
1728 // Return type          : void 
1729 // Argument         : CGeometryDoc* aDoc
1730 void GeomSources::gpTest25(CGeometryDoc* aDoc)
1731 {
1732   DisplayType TheDisplayType = a2DNo3D;
1733   PreProcess(aDoc,TheDisplayType);
1734
1735   //==============================================================
1736
1737   Handle(TColgp_HArray1OfPnt2d) harray =
1738     new TColgp_HArray1OfPnt2d (1,5); // sizing harray
1739   harray->SetValue(1,gp_Pnt2d (0,0));
1740   harray->SetValue(2,gp_Pnt2d (-3,1));
1741   harray->SetValue(3,gp_Pnt2d (-2,5));
1742   harray->SetValue(4,gp_Pnt2d (2,9));
1743   harray->SetValue(5,gp_Pnt2d (-4,14));
1744
1745 Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);
1746 anInterpolation.Perform();
1747 Handle(Geom2d_BSplineCurve) SPL = anInterpolation.Curve();
1748
1749 gp_Pnt2d P1(-1,-2);
1750 gp_Pnt2d P2(0,15);
1751 gp_Dir2d V1 = gp::DY2d();
1752 Handle(Geom2d_TrimmedCurve) TC1 =
1753     GCE2d_MakeSegment(P1,V1,P2);
1754
1755 Standard_Real tolerance = Precision::Confusion();
1756 Geom2dAPI_InterCurveCurve ICC (SPL,TC1,tolerance);
1757 Standard_Integer NbPoints =ICC.NbPoints();
1758 gp_Pnt2d PK;
1759
1760 for (Standard_Integer k = 1;k<=NbPoints;k++)
1761 {                                                                 
1762   PK = ICC.Point(k);                                              
1763   // do something with each intersection point                    
1764 }                                                                 
1765
1766   //==============================================================
1767   TCollection_AsciiString Message (" \
1768                                                                     \n\
1769 Handle(TColgp_HArray1OfPnt2d) harray =                              \n\
1770     new TColgp_HArray1OfPnt2d (1,5); // sizing harray               \n\
1771 harray->SetValue(1,gp_Pnt2d (0,0));                                 \n\
1772 harray->SetValue(2,gp_Pnt2d (-3,1));                                \n\
1773 harray->SetValue(3,gp_Pnt2d (-2,5));                                \n\
1774 harray->SetValue(4,gp_Pnt2d (2,9));                                 \n\
1775 harray->SetValue(5,gp_Pnt2d (-4,14));                               \n\
1776                                                                     \n\
1777 Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);  \n\
1778 anInterpolation.Perform();                                          \n\
1779 Handle(Geom2d_BSplineCurve) SPL = anInterpolation.Curve();          \n\
1780                                                                     \n\
1781 gp_Pnt2d P1(-1,-2);                                                 \n\
1782 gp_Pnt2d P2(0,15);                                                  \n\
1783 gp_Dir2d V1 = gp::DY2d();                                           \n\
1784 Handle(Geom2d_TrimmedCurve) TC1=                                    \n\
1785     GCE2d_MakeSegment(P1,V1,P2);                                    \n\
1786                                                                     \n\
1787 Standard_Real tolerance = Precision::Confusion();                   \n\
1788 Geom2dAPI_InterCurveCurve ICC (SPL,TC1,tolerance);                  \n\
1789 Standard_Integer NbPoints =ICC.NbPoints();                          \n\
1790 gp_Pnt2d PK;                                                        \n\
1791 for (Standard_Integer k = 1;k<=NbPoints;k++)                        \n\
1792   {                                                                 \n\
1793     PK = ICC.Point(k);                                              \n\
1794     // do something with each intersection point                    \n\
1795   }                                                                 \n\
1796                                                                     \n");
1797   AddSeparator(aDoc,Message);
1798   //--------------------------------------------------------------
1799
1800   Handle(ISession2D_Curve) aCurve1 = new ISession2D_Curve(SPL);
1801   aCurve1->SetDisplayPole(Standard_False);
1802   aDoc->GetISessionContext()->Display(aCurve1, Standard_False);
1803   Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(TC1);
1804   aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
1805
1806   TCollection_AsciiString aString;
1807   for (Standard_Integer i = 1;i<=NbPoints;i++)
1808   {
1809     PK = ICC.Point(i);
1810     // do something with each intersection point
1811     TCollection_AsciiString Message2 (i);
1812     TCollection_AsciiString Message3 (PK.X());
1813     TCollection_AsciiString Message4 (PK.Y());
1814     aString = "PK_";
1815     aString += Message2; 
1816
1817     DisplayPoint(aDoc,PK,aString.ToCString(),false,0.5);
1818
1819     Message += "PK_"; 
1820     Message += Message2; 
1821     Message += " ( ";
1822     Message += Message3; 
1823     Message += " , "; 
1824     Message += Message4; 
1825     Message += " )\n"; 
1826   }
1827
1828   PostProcess(aDoc,ID_BUTTON_Test_25,TheDisplayType,Message.ToCString());
1829 }
1830
1831 // Function name        : GeomSources::gpTest26
1832 // Description      : 
1833 // Return type          : void 
1834 // Argument         : CGeometryDoc* aDoc
1835 void GeomSources::gpTest26(CGeometryDoc* aDoc)
1836 {
1837   DisplayType TheDisplayType = a2DNo3D;
1838   PreProcess(aDoc,TheDisplayType);
1839
1840   //==============================================================
1841
1842   //----------- Build TC1 -----------------------
1843   gp_Pnt2d P1(0,0);  gp_Pnt2d P2(2,6);
1844   gp_Dir2d V1 = gp::DY2d();
1845   Handle(Geom2d_TrimmedCurve) TC1 =  GCE2d_MakeSegment(P1,V1,P2);
1846   Standard_Real FP1 = TC1->FirstParameter();
1847   Standard_Real LP1 = TC1->LastParameter();
1848   //----------- Build TC2 -----------------------
1849   gp_Pnt2d P3(-9,6.5);       gp_Dir2d V2 = gp::DX2d();
1850   Handle(Geom2d_TrimmedCurve) TC2 = GCE2d_MakeSegment(P3,V2,P2);
1851   Standard_Real FP2 = TC1->FirstParameter();
1852   Standard_Real LP2 = TC1->LastParameter();
1853   //----------- Extrema TC1 / TC2 ---------------
1854   Geom2dAPI_ExtremaCurveCurve ECC (TC1,TC2, FP1,LP1, FP2,LP2);
1855   Standard_Real shortestdistance =-1;
1856   if (ECC.NbExtrema() != 0)  shortestdistance = ECC.LowerDistance();
1857   //----------- Build SPL1 ---------------------- 
1858   TColgp_Array1OfPnt2d array (1,5); // sizing array
1859   array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2));
1860   array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3));
1861   array.SetValue(5,gp_Pnt2d (-3,5));
1862   Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);
1863   Standard_Real FPSPL1 = SPL1->FirstParameter();
1864   Standard_Real LPSPL1 = SPL1->LastParameter();
1865   //----------- Extrema TC1 / SPL1  -------------                       
1866   Geom2dAPI_ExtremaCurveCurve ECC2 (TC1,SPL1, FP1,LP1, FPSPL1,LPSPL1);
1867   Standard_Real SPL1shortestdistance =-1;
1868   if (ECC2.NbExtrema()!=0) SPL1shortestdistance = ECC2.LowerDistance();
1869   Standard_Integer NbExtrema = ECC2.NbExtrema();
1870   TColgp_Array2OfPnt2d aSolutionArray(1,NbExtrema,1,2);
1871   for(int i=1;i <= NbExtrema; i++)
1872   {                                  
1873     gp_Pnt2d P1,P2;
1874     ECC2.Points(i,P1,P2);
1875     aSolutionArray(i,1) = P1;
1876     aSolutionArray(i,2) = P2;
1877   }            
1878
1879   //==============================================================
1880   TCollection_AsciiString Message (" \
1881 //----------- Build TC1 -----------------------                       \n\
1882 gp_Pnt2d P1(0,0);  gp_Pnt2d P2(2,6);                                  \n\
1883 gp_Dir2d V1 = gp::DY2d();                                             \n\
1884 Handle(Geom2d_TrimmedCurve) TC1 =  GCE2d_MakeSegment(P1,V1,P2);       \n\
1885 Standard_Real FP1 = TC1->FirstParameter();                            \n\
1886 Standard_Real LP1 = TC1->LastParameter();                             \n\
1887 //----------- Build TC2 -----------------------                       \n\
1888 gp_Pnt2d P3(-9,6.5);       gp_Dir2d V2 = gp::DX2d();                    \n\
1889 Handle(Geom2d_TrimmedCurve) TC2 = GCE2d_MakeSegment(P3,V2,P2);        \n\
1890 Standard_Real FP2 = TC1->FirstParameter();                            \n\
1891 Standard_Real LP2 = TC1->LastParameter();                             \n\
1892 //----------- Extrema TC1 / TC2 ---------------                       \n\
1893 Geom2dAPI_ExtremaCurveCurve ECC (TC1,TC2, FP1,LP1, FP2,LP2);          \n\
1894 Standard_Real shortestdistance =-1;                                   \n\
1895 if (ECC.NbExtrema() != 0)  shortestdistance = ECC.LowerDistance();    \n\
1896 //----------- Build SPL1 ----------------------                       \n\
1897 TColgp_Array1OfPnt2d array (1,5); // sizing array                     \n\
1898 array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2)); \n\
1899 array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3)); \n\
1900 array.SetValue(5,gp_Pnt2d (-3,5));                                    \n\
1901 Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);  \n\
1902 Standard_Real FPSPL1 = SPL1->FirstParameter();                        \n");
1903 Message += "\
1904 Standard_Real LPSPL1 = SPL1->LastParameter();                         \n\
1905 //----------- Extrema TC1 / SPL1  -------------                       \n\
1906 Geom2dAPI_ExtremaCurveCurve ECC2 (TC1,SPL1, FP1,LP1, FPSPL1,LPSPL1);  \n\
1907 Standard_Real SPL1shortestdistance =-1;                               \n\
1908 if (ECC2.NbExtrema()!=0) SPL1shortestdistance = ECC2.LowerDistance(); \n\
1909 Standard_Integer NbExtrema = ECC2.NbExtrema();                        \n\
1910 TColgp_Array2OfPnt2d aSolutionArray(1,NbExtrema,1,2);                 \n\
1911 for(int i=1;i <= NbExtrema; i++)   {                                  \n\
1912     gp_Pnt2d P1,P2;                                                   \n\
1913     ECC2.Points(i,P1,P2);                                             \n\
1914     aSolutionArray(i,1) = P1;  aSolutionArray(i,2) = P2; }            \n";
1915  AddSeparator(aDoc,Message);
1916  //--------------------------------------------------------------
1917
1918  TCollection_AsciiString aString;
1919  for(int i = array.Lower();i<=array.Upper();i++)
1920  {
1921    TCollection_AsciiString Message2 (i);
1922    gp_Pnt2d P = array(i);
1923    aString = "array ";
1924    aString += Message2; 
1925    DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
1926  }
1927
1928  if (!SPL1.IsNull())
1929  { 
1930    Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(SPL1);
1931    aCurve->SetDisplayPole(Standard_False);
1932    aCurve->SetColorIndex(3);
1933    aDoc->GetISessionContext()->Display(aCurve, Standard_False);
1934  }
1935  else
1936    MessageBox(0,"SPL1.IsNull()","CasCade Error",MB_ICONERROR);
1937
1938  Handle(ISession2D_Curve) aCurve1 = new ISession2D_Curve(TC1);
1939  aCurve1->SetColorIndex(6);
1940  aDoc->GetISessionContext()->Display(aCurve1, Standard_False);
1941  Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(TC2);
1942  aCurve2->SetColorIndex(5);
1943  aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
1944
1945  for(int i=1;i <= NbExtrema; i++)
1946  {
1947    gp_Pnt2d P1 =aSolutionArray(i,1);
1948
1949    TCollection_AsciiString Message2 (i);
1950    aString = "P1_";
1951    aString += Message2; 
1952    DisplayPoint(aDoc,P1,aString.ToCString(),false,0.7*i);
1953
1954    gp_Pnt2d P2 = aSolutionArray(i,2);
1955
1956    Handle(Geom2d_TrimmedCurve) SolutionCurve =
1957      GCE2d_MakeSegment(P1,P2);
1958    Handle(ISession2D_Curve) aSolutionCurve = new ISession2D_Curve(SolutionCurve);
1959    aDoc->GetISessionContext()->Display(aSolutionCurve, Standard_False);
1960  }
1961
1962  Message += "TC1 is  Yellow ,TC2 is  Blue ,SPL1 is Red \n";
1963  Message += "ECC.NbExtrema()  = ";
1964  Message += ECC.NbExtrema();
1965  Message += "    shortestdistance = ";
1966  Message+= shortestdistance;
1967  Message += "\n";
1968  Message += "ECC2.NbExtrema() = ";
1969  Message += NbExtrema;
1970  Message += "    SPL1shortestdistance = ";
1971  Message+= SPL1shortestdistance;
1972  Message += "\n";
1973
1974  PostProcess(aDoc,ID_BUTTON_Test_26,TheDisplayType,Message.ToCString());
1975 }
1976
1977 // Function name        : GeomSources::gpTest27
1978 // Description      : 
1979 // Return type          : void 
1980 // Argument         : CGeometryDoc* aDoc
1981 void GeomSources::gpTest27(CGeometryDoc* aDoc)
1982 {
1983   DisplayType TheDisplayType = a2DNo3D;
1984   PreProcess(aDoc,TheDisplayType);
1985   //==============================================================
1986
1987   TColgp_Array1OfPnt2d array (1,5); // sizing array
1988   array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2));
1989   array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3));
1990   array.SetValue(5,gp_Pnt2d (-3,5));
1991   Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);
1992
1993   Standard_Real dist = 1;
1994   Handle(Geom2d_OffsetCurve) OC =
1995     new Geom2d_OffsetCurve(SPL1,dist);
1996   Standard_Boolean result = OC->IsCN(2);
1997   Standard_Real dist2 = 1.5;
1998   Handle(Geom2d_OffsetCurve) OC2 =
1999     new Geom2d_OffsetCurve(SPL1,dist2);
2000   Standard_Boolean result2 = OC2->IsCN(2);
2001
2002   //==============================================================
2003   TCollection_AsciiString Message (" \
2004                                                                        \n\
2005 TColgp_Array1OfPnt2d array (1,5); // sizing array                      \n\
2006 array.SetValue(1,gp_Pnt2d (-4,0)); array.SetValue(2,gp_Pnt2d (-7,2));  \n\
2007 array.SetValue(3,gp_Pnt2d (-6,3)); array.SetValue(4,gp_Pnt2d (-4,3));  \n\
2008 array.SetValue(5,gp_Pnt2d (-3,5));                                     \n\
2009 Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);   \n\
2010                                                                        \n\
2011 Standard_Real dist = 1;                                                \n\
2012 Handle(Geom2d_OffsetCurve) OC =                                        \n\
2013        new Geom2d_OffsetCurve(SPL1,dist);                              \n\
2014 Standard_Boolean result = OC->IsCN(2);                                 \n\
2015                                                                        \n\
2016 Standard_Real dist2 = 1.5;                                             \n\
2017 Handle(Geom2d_OffsetCurve) OC2 =                                       \n\
2018        new Geom2d_OffsetCurve(SPL1,dist2);                             \n\
2019 Standard_Boolean result2 = OC2->IsCN(2);                               \n\
2020                                                                        \n");
2021   AddSeparator(aDoc,Message);
2022   //--------------------------------------------------------------
2023   Handle(ISession2D_Curve) aCurve1 = new ISession2D_Curve(SPL1);
2024   aCurve1->SetColorIndex(6);
2025   aDoc->GetISessionContext()->Display(aCurve1, Standard_False);
2026   Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(OC);
2027   aCurve2->SetColorIndex(5);
2028   aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
2029   Handle(ISession2D_Curve) aCurve3 = new ISession2D_Curve(OC2);
2030   aCurve3->SetColorIndex(3);
2031   aDoc->GetISessionContext()->Display(aCurve3, Standard_False);
2032
2033
2034   Message += "SPL1 is Yellow \n";
2035   Message += "OC   is Blue \n";
2036   Message += "OC2  is Red \n\n";
2037   Message += "  Warning, Continuity is not guaranteed :  \n ";
2038   if(result)
2039     Message += " result  = True  \n";
2040   else
2041     Message += " result  = False \n";
2042   if(result2)
2043     Message += " result2 = True  \n";
2044   else
2045     Message += " result2 = False \n";
2046
2047   PostProcess(aDoc,ID_BUTTON_Test_27,TheDisplayType,Message.ToCString());
2048 }
2049
2050 // Function name        : GeomSources::gpTest28
2051 // Description      : 
2052 // Return type          : void 
2053 // Argument         : CGeometryDoc* aDoc
2054 void GeomSources::gpTest28(CGeometryDoc* aDoc)
2055 {
2056   DisplayType TheDisplayType = a2DNo3D;
2057   PreProcess(aDoc,TheDisplayType);
2058   //==============================================================
2059
2060   gp_Pnt2d P1(1,2);
2061   gp_Pnt2d P2(4,5);
2062   gp_Lin2d L = gce_MakeLin2d(P1,P2);
2063   // assignment by overloaded operator  
2064
2065   //==============================================================
2066   TCollection_AsciiString Message (" \
2067                                       \n\
2068 gp_Pnt2d P1(1,2);                     \n\
2069 gp_Pnt2d P2(4,5);                     \n\
2070 gp_Lin2d L = gce_MakeLin2d(P1,P2);    \n\
2071 // assignment by overloaded operator  \n\
2072                                       \n");
2073   AddSeparator(aDoc,Message);
2074   //--------------------------------------------------------------
2075
2076   DisplayPoint(aDoc,P1,"P1",false,0.5);
2077   DisplayPoint(aDoc,P2,"P2",false,0.5);
2078
2079   Handle(Geom2d_TrimmedCurve) aLine = GCE2d_MakeSegment(L,-3,8);
2080   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aLine);
2081   aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2082
2083   PostProcess(aDoc,ID_BUTTON_Test_28,TheDisplayType,Message.ToCString());
2084 }
2085
2086 // Function name        : GeomSources::gpTest29
2087 // Description      : 
2088 // Return type          : void 
2089 // Argument         : CGeometryDoc* aDoc
2090 void GeomSources::gpTest29(CGeometryDoc* aDoc)
2091 {
2092   DisplayType TheDisplayType = a2DNo3D;
2093   PreProcess(aDoc,TheDisplayType);
2094
2095   //==============================================================
2096                              
2097   gp_Pnt2d P1(1,2);
2098   gp_Pnt2d P2(4,5);
2099   gp_Lin2d L;
2100   GccAna_Pnt2dBisec B(P1,P2);
2101   if (B.IsDone())
2102   {
2103     L = B.ThisSolution();
2104   }
2105
2106   //==============================================================
2107   TCollection_AsciiString Message (" \
2108                              \n\
2109 gp_Pnt2d P1(1,2);            \n\
2110 gp_Pnt2d P2(4,5);            \n\
2111 gp_Lin2d L;                  \n\
2112 GccAna_Pnt2dBisec B(P1,P2);  \n\
2113 if (B.IsDone())              \n\
2114     {                        \n\
2115     L = B.ThisSolution();    \n\
2116     }                        \n\
2117                              \n");
2118   AddSeparator(aDoc,Message);
2119   //--------------------------------------------------------------
2120
2121   DisplayPoint(aDoc,P1,"P1",false,0.5);
2122   DisplayPoint(aDoc,P2,"P2",false,0.5);
2123
2124   if (B.IsDone())
2125   {
2126     Handle(Geom2d_TrimmedCurve) aLine = GCE2d_MakeSegment(L,-8,8);
2127     Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aLine);
2128     aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2129   }
2130
2131   if (B.IsDone()) Message += " \n   B Is Done   ";
2132   else            Message += " \n   B Is not Done    ";
2133   PostProcess(aDoc,ID_BUTTON_Test_29,TheDisplayType,Message.ToCString());
2134 }
2135
2136 // Function name        : GeomSources::gpTest30
2137 // Description      : 
2138 // Return type          : void 
2139 // Argument         : CGeometryDoc* aDoc
2140 void GeomSources::gpTest30(CGeometryDoc* aDoc)
2141 {
2142   DisplayType TheDisplayType =a2DNo3D ;
2143   PreProcess(aDoc,TheDisplayType);
2144
2145   //==============================================================
2146
2147   gp_Pnt2d P1 (2,3);
2148   gp_Pnt2d P2 (4,4);
2149   gp_Pnt2d P3 (6,7);
2150   gp_Pnt2d P4 (10,10);
2151   gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);
2152   GccEnt_QualifiedCirc QC = GccEnt::Outside(C);
2153   GccAna_Lin2d2Tan LT (QC,P4,Precision::Confusion());
2154   Standard_Integer NbSol = 0;
2155   if (LT.IsDone())
2156   {
2157     NbSol = LT.NbSolutions();
2158     for(Standard_Integer k=1; k<=NbSol; k++)
2159     {
2160       gp_Lin2d L = LT.ThisSolution(k);
2161       // do something with L
2162     }
2163   }
2164
2165   //==============================================================
2166   TCollection_AsciiString Message (" \
2167                                                      \n\
2168 gp_Pnt2d P1 (2,3);                                   \n\
2169 gp_Pnt2d P2 (4,4);                                   \n\
2170 gp_Pnt2d P3 (6,7);                                   \n\
2171 gp_Pnt2d P4 (10,10);                                 \n\
2172 gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);             \n\
2173 GccEnt_QualifiedCirc QC = GccEnt::Outside(C);        \n\
2174 GccAna_Lin2d2Tan LT (QC,P4,Precision::Confusion());  \n\
2175 Standard_Integer NbSol;                              \n\
2176 if (LT.IsDone())                                     \n\
2177   {                                                  \n\
2178       NbSol = LT.NbSolutions();                      \n\
2179       for(Standard_Integer k=1; k<=NbSol; k++)       \n\
2180         {                                            \n\
2181          gp_Lin2d L = LT.ThisSolution(k);            \n\
2182           // do something with L                     \n\
2183         }                                            \n\
2184   }                                                  \n\
2185                                                      \n");
2186   AddSeparator(aDoc,Message);
2187   //--------------------------------------------------------------
2188
2189   DisplayPoint(aDoc,P1,"P1",false,0.5,-1,0.1);
2190   DisplayPoint(aDoc,P2,"P2",false,0.5,-0.7,0.1);
2191   DisplayPoint(aDoc,P3,"P3",false,0.5,-0.5,0.1);
2192   DisplayPoint(aDoc,P4,"P4",false,0.5,0,0.1);
2193
2194   Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(C);
2195   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aCircle);
2196   aCurve->SetColorIndex(5);
2197   aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2198
2199   if (LT.IsDone())
2200   {
2201     Standard_Integer NbSol = LT.NbSolutions();
2202     for(Standard_Integer k=1; k<=NbSol; k++)
2203     {
2204       gp_Lin2d L = LT.ThisSolution(k);
2205       Handle(Geom2d_TrimmedCurve) aLine = GCE2d_MakeSegment(L,-10,20);
2206       Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aLine);
2207       aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2208     }
2209   }
2210   Message += " C is Blue \n\n";
2211   Message += "LT.IsDone() = "; 
2212   if (LT.IsDone())  Message += "True \n"; else Message += "False \n";
2213   TCollection_AsciiString Message2 (NbSol);
2214   Message += "NbSol       = "; Message += Message2      ; Message += "\n";
2215
2216   PostProcess(aDoc,ID_BUTTON_Test_30,TheDisplayType,Message.ToCString());
2217 }
2218
2219 // Function name        : GeomSources::gpTest31
2220 // Description      : 
2221 // Return type          : void 
2222 // Argument         : CGeometryDoc* aDoc
2223 void GeomSources::gpTest31(CGeometryDoc* aDoc)
2224 {
2225   DisplayType TheDisplayType = a2DNo3D;
2226   PreProcess(aDoc,TheDisplayType);
2227
2228   //==============================================================
2229
2230 gp_Pnt2d P1 (9,6);
2231 gp_Pnt2d P2 (10,4);
2232 gp_Pnt2d P3 (6,7);
2233 gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);
2234 GccEnt_QualifiedCirc QC = GccEnt::Outside(C);
2235 gp_Pnt2d P4 (-2,7);
2236 gp_Pnt2d P5 (12,-3);
2237 gp_Lin2d L = GccAna_Lin2d2Tan(P4,P5,Precision::Confusion()).ThisSolution(1);
2238 GccEnt_QualifiedLin QL = GccEnt::Unqualified(L);
2239 Standard_Real radius = 2;
2240 GccAna_Circ2d2TanRad TR (QC,QL,radius,Precision::Confusion());
2241 Standard_Real parsol,pararg;
2242 gp_Pnt2d tangentpoint1,tangentpoint2;
2243 gp_Circ2d circ;
2244 if (TR.IsDone())
2245 {
2246   Standard_Integer NbSol = TR.NbSolutions();
2247   for (Standard_Integer k=1; k<=NbSol; k++)
2248   {
2249     circ = TR.ThisSolution(k);
2250     // find the solution circle
2251     TR.Tangency1(k,parsol,pararg,tangentpoint1);
2252     // find the first tangent point
2253     TR.Tangency2(k,parsol,pararg,tangentpoint2);
2254     // find the second tangent point
2255   }
2256 }
2257
2258   //==============================================================
2259   TCollection_AsciiString Message;
2260   Message = "\
2261                                                                               \n\
2262 gp_Pnt2d P1 (9,6);                                                            \n\
2263 gp_Pnt2d P2 (10,4);                                                           \n\
2264 gp_Pnt2d P3 (6,7);                                                            \n\
2265 gp_Circ2d C = gce_MakeCirc2d (P1,P2,P3);                                      \n\
2266 GccEnt_QualifiedCirc QC = GccEnt::Outside(C);                                 \n\
2267 gp_Pnt2d P4 (-2,7);                                                           \n\
2268 gp_Pnt2d P5 (12,-3);                                                          \n\
2269 gp_Lin2d L = GccAna_Lin2d2Tan(P4,P5,Precision::Confusion()).ThisSolution(1);  \n\
2270 GccEnt_QualifiedLin QL = GccEnt::Unqualified(L);                              \n\
2271 Standard_Real radius = 2;                                                     \n\
2272 GccAna_Circ2d2TanRad TR (QC,QL,radius,Precision::Confusion());                \n\
2273 Standard_Real parsol,pararg;                                                  \n\
2274 gp_Pnt2d tangentpoint1,tangentpoint2;                                         \n\
2275 gp_Circ2d circ;                                                               \n\
2276 if (TR.IsDone())                                                              \n\
2277     {                                                                         \n\
2278       Standard_Integer NbSol = TR.NbSolutions();                              \n\
2279       for (Standard_Integer k=1; k<=NbSol; k++)                               \n\
2280         {                                                                     \n";
2281   Message += "\
2282           circ = TR.ThisSolution(k);                                          \n\
2283           // find the solution circle                                         \n\
2284           TR.Tangency1(k,parsol,pararg,tangentpoint1);                        \n\
2285           // find the first tangent point                                     \n\
2286           TR.Tangency2(k,parsol,pararg,tangentpoint2);                        \n\
2287           // find the second tangent point                                    \n\
2288         }                                                                     \n\
2289     }                                                                         \n\
2290                                                                               \n";
2291   AddSeparator(aDoc,Message);
2292
2293   //--------------------------------------------------------------
2294   DisplayPoint(aDoc,P1,"P1",false,0.3);
2295   DisplayPoint(aDoc,P2,"P2",false,0.3);
2296   DisplayPoint(aDoc,P3,"P3",false,0.3);
2297   DisplayPoint(aDoc,P4,"P4",false,0.3);
2298   DisplayPoint(aDoc,P5,"P5",false,0.3);
2299
2300   Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(C);
2301   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aCircle);
2302   aCurve->SetColorIndex(3);
2303
2304   aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2305   Handle(Geom2d_TrimmedCurve) aLine = GCE2d_MakeSegment(L,-2,20);
2306   Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(aLine);
2307   aCurve2->SetColorIndex(5);
2308   aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
2309
2310   if (TR.IsDone())
2311   {
2312     Standard_Integer NbSol = TR.NbSolutions();
2313     for (Standard_Integer k=1; k<=NbSol; k++)
2314     {
2315       circ = TR.ThisSolution(k);
2316       Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(circ);
2317       Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(aCircle);
2318       aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2319
2320       // find the solution circle
2321       TR.Tangency1(k,parsol,pararg,tangentpoint1);
2322       // find the first tangent point                                                                    
2323       TR.Tangency2(k,parsol,pararg,tangentpoint2);
2324       // find the second tangent point
2325       DisplayPoint(aDoc,tangentpoint1,"tangentpoint1",false,0.3);
2326       DisplayPoint(aDoc,tangentpoint2,"tangentpoint2",false,0.3);
2327     }
2328   }
2329   Message += "C is Red \n";
2330   Message += "L is Blue \n";
2331   PostProcess(aDoc,ID_BUTTON_Test_31,TheDisplayType,Message.ToCString());
2332 }
2333
2334 // Function name        : GeomSources::gpTest32
2335 // Description      : 
2336 // Return type          : void 
2337 // Argument         : CGeometryDoc* aDoc
2338 void GeomSources::gpTest32(CGeometryDoc* aDoc)
2339 {
2340   DisplayType TheDisplayType = a2DNo3D;
2341   PreProcess(aDoc,TheDisplayType);
2342
2343   //==============================================================
2344
2345   Standard_Real major = 12;
2346   Standard_Real minor = 4;
2347   gp_Ax2d axis = gp::OX2d();
2348   gp_Elips2d EE(axis,major,minor);
2349   Handle(Geom2d_TrimmedCurve) arc = GCE2d_MakeArcOfEllipse(EE,0.0,M_PI/4);
2350
2351   //==============================================================
2352   TCollection_AsciiString Message (" \
2353                                                                         \n\
2354 Standard_Real major = 12;                                               \n\
2355 Standard_Real minor = 4;                                                \n\
2356 gp_Ax2d axis = gp::OX2d();                                              \n\
2357 gp_Elips2d EE(axis,major,minor);                                        \n\
2358 Handle(Geom2d_TrimmedCurve) arc = GCE2d_MakeArcOfEllipse(EE,0.0,PI/4);  \n\
2359                                                                         \n");
2360   AddSeparator(aDoc,Message);
2361   //--------------------------------------------------------------
2362   Handle(Geom2d_Curve) E = GCE2d_MakeEllipse(EE);
2363   Handle(ISession2D_Curve) aCurve = new ISession2D_Curve(E);
2364   aCurve->SetColorIndex(3);
2365   aCurve->SetTypeOfLine(Aspect_TOL_DOTDASH);
2366   //SetWidthOfLine                 
2367   aDoc->GetISessionContext()->Display(aCurve, Standard_False);
2368   Handle(ISession2D_Curve) aCurve2 = new ISession2D_Curve(arc);
2369   aDoc->GetISessionContext()->Display(aCurve2, Standard_False);
2370   TCollection_AsciiString Message2 (M_PI);
2371   Message += " PI = ";Message+= Message2;
2372
2373   PostProcess(aDoc,ID_BUTTON_Test_32,TheDisplayType,Message.ToCString());
2374 }
2375
2376 // Function name        : GeomSources::gpTest33
2377 // Description      : 
2378 // Return type          : void 
2379 // Argument         : CGeometryDoc* aDoc
2380 void GeomSources::gpTest33(CGeometryDoc* aDoc)
2381 {
2382   DisplayType TheDisplayType = No2D3D;
2383   PreProcess(aDoc,TheDisplayType);
2384
2385   //==============================================================
2386
2387   gp_Pnt P1(0,0,1);
2388   gp_Pnt P2(1,2,2);
2389   gp_Pnt P3(2,3,3);
2390   gp_Pnt P4(4,3,4);
2391   gp_Pnt P5(5,5,5);
2392   TColgp_Array1OfPnt array (1,5); // sizing array
2393   array.SetValue(1,P1);
2394   array.SetValue(2,P2);
2395   array.SetValue(3,P3);
2396   array.SetValue(4,P4);
2397   array.SetValue(5,P5);
2398   Handle(TColgp_HArray1OfPnt) harray =
2399     new TColgp_HArray1OfPnt (1,5); // sizing harray
2400   harray->SetValue(1,P1.Translated(gp_Vec(4,0,0)));
2401   harray->SetValue(2,P2.Translated(gp_Vec(4,0,0)));
2402   harray->SetValue(3,P3.Translated(gp_Vec(4,0,0)));
2403   harray->SetValue(4,P4.Translated(gp_Vec(4,0,0)));
2404   harray->SetValue(5,P5.Translated(gp_Vec(4,0,0)));
2405   Handle(Geom_BSplineCurve) SPL1 =
2406     GeomAPI_PointsToBSpline(array).Curve();
2407
2408   GeomAPI_Interpolate anInterpolation(harray,Standard_False,Precision::Approximation());
2409   anInterpolation.Perform();
2410
2411   Handle(Geom_BSplineCurve) SPL2;
2412   if (anInterpolation.IsDone())
2413     SPL2 = anInterpolation.Curve();
2414   else
2415     MessageBox(0,"The Interpolation is Not done","CasCade Warning",MB_ICONWARNING);
2416
2417   //==============================================================
2418   TCollection_AsciiString Message (" \
2419                                                                                         \n\
2420 gp_Pnt P1(0,0,1);                                                                       \n\
2421 gp_Pnt P2(1,2,2);                                                                       \n\
2422 gp_Pnt P3(2,3,3);                                                                       \n\
2423 gp_Pnt P4(4,3,4);                                                                       \n\
2424 gp_Pnt P5(5,5,5);                                                                       \n\
2425 TColgp_Array1OfPnt array (1,5); // sizing array                                         \n\
2426 array.SetValue(1,P1);                                                                   \n\
2427 array.SetValue(2,P2);                                                                   \n\
2428 array.SetValue(3,P3);                                                                   \n\
2429 array.SetValue(4,P4);                                                                   \n\
2430 array.SetValue(5,P5);                                                                   \n\
2431 Handle(TColgp_HArray1OfPnt) harray =                                                    \n\
2432     new TColgp_HArray1OfPnt (1,5); // sizing harray                                     \n\
2433 harray->SetValue(1,P1.Translated(gp_Vec(4,0,0)));                                       \n\
2434 harray->SetValue(2,P2.Translated(gp_Vec(4,0,0)));                                       \n\
2435 harray->SetValue(3,P3.Translated(gp_Vec(4,0,0)));                                       \n\
2436 harray->SetValue(4,P4.Translated(gp_Vec(4,0,0)));                                       \n\
2437 harray->SetValue(5,P5.Translated(gp_Vec(4,0,0)));                                       \n\
2438 Handle(Geom_BSplineCurve) SPL1 =                                                        \n\
2439     GeomAPI_PointsToBSpline(array).Curve();                                             \n");
2440  Message += "\
2441                                                                                         \n\
2442 GeomAPI_Interpolate anInterpolation(harray,Standard_False,Precision::Approximation());  \n\
2443 anInterpolation.Perform();                                                              \n\
2444                                                                                         \n\
2445 Handle(Geom_BSplineCurve) SPL2;                                                         \n\
2446 if (anInterpolation.IsDone())                                                           \n\
2447        SPL2 = anInterpolation.Curve();                                                  \n\
2448 else                                                                                    \n\
2449    MessageBox(0,\"The Interpolation is Not done\",\"CasCade Warning\",MB_ICONWARNING);  \n\
2450                                                                                         \n";
2451   AddSeparator(aDoc,Message);
2452
2453   //--------------------------------------------------------------
2454
2455   TCollection_AsciiString aString;
2456   for(Standard_Integer i = array.Lower();i<=array.Upper();i++)
2457   {
2458
2459     TCollection_AsciiString Message2 (i);
2460     gp_Pnt P = array(i);
2461
2462     aString = "P";
2463     aString += Message2; 
2464     if (i == 1) aString += " (array)  ";
2465     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);\
2466
2467       aString = "P";
2468     aString += Message2; 
2469     if (i == 1) aString += " (harray)  ";
2470     DisplayPoint(aDoc,P.Translated(gp_Vec(4,0,0)),aString.ToCString(),false,0.5);\
2471
2472   }
2473
2474   Handle(ISession_Curve) aCurve = new ISession_Curve(SPL1);
2475   aDoc->GetAISContext()->SetDisplayMode(aCurve,1);
2476   aDoc->GetAISContext()->Display(aCurve, Standard_False);
2477
2478   if (anInterpolation.IsDone())
2479   {
2480     Handle(ISession_Curve) aCurve2 = new ISession_Curve(SPL2);
2481     aDoc->GetAISContext()->SetDisplayMode(aCurve2,1);
2482     aDoc->GetAISContext()->Display(aCurve2, Standard_False);
2483   }
2484
2485   PostProcess(aDoc,ID_BUTTON_Test_33,TheDisplayType,Message.ToCString());
2486 }
2487
2488 // Function name        : GeomSources::gpTest34
2489 // Description      : 
2490 // Return type          : void 
2491 // Argument         : CGeometryDoc* aDoc
2492 void GeomSources::gpTest34(CGeometryDoc* aDoc)
2493 {
2494   DisplayType TheDisplayType = No2D3D;
2495   PreProcess(aDoc,TheDisplayType);
2496
2497   //==============================================================
2498
2499   TColgp_Array1OfPnt array (1,5); // sizing array
2500   array.SetValue(1,gp_Pnt(0,0,1));
2501   array.SetValue(2,gp_Pnt(1,2,2));
2502   array.SetValue(3,gp_Pnt(2,3,3));
2503   array.SetValue(4,gp_Pnt(4,4,4));
2504   array.SetValue(5,gp_Pnt(5,5,5));
2505
2506   GProp_PEquation PE (array,1.5 );
2507
2508   if (PE.IsPoint())
2509   {/* ... */}
2510   gp_Lin L;
2511   if (PE.IsLinear())
2512   {
2513     L = PE.Line();
2514   }
2515   if (PE.IsPlanar())
2516   {/* ... */}
2517   if (PE.IsSpace())
2518   {/* ... */}
2519                                                                  
2520   //==============================================================
2521   TCollection_AsciiString Message (" \
2522                                                 \n\
2523 TColgp_Array1OfPnt array (1,5); // sizing array \n\
2524 array.SetValue(1,gp_Pnt(0,0,1));                \n\
2525 array.SetValue(2,gp_Pnt(1,2,2));                \n\
2526 array.SetValue(3,gp_Pnt(2,3,3));                \n\
2527 array.SetValue(4,gp_Pnt(4,4,4));                \n\
2528 array.SetValue(5,gp_Pnt(5,5,5));                \n\
2529                                                 \n\
2530 GProp_PEquation PE (array,1.5 );                \n\
2531                                                 \n\
2532 if (PE.IsPoint()){ /* ... */  }                 \n\
2533 gp_Lin L;                                       \n\
2534 if (PE.IsLinear()) {  L = PE.Line();    }       \n\
2535 if (PE.IsPlanar()){ /* ... */  }                \n\
2536 if (PE.IsSpace()) { /* ... */  }                \n\
2537                                                 \n");
2538   AddSeparator(aDoc,Message);
2539   //--------------------------------------------------------------
2540   TCollection_AsciiString aString;
2541   for(Standard_Integer i = array.Lower();i<=array.Upper();i++)
2542   {
2543     TCollection_AsciiString Message2 (i);
2544     gp_Pnt P = array(i);
2545
2546     aString = "P";
2547     aString += Message2; 
2548     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
2549   }
2550
2551   Message += " PE.IsPoint()  = ";
2552   if (PE.IsPoint())
2553     Message += "True \n";
2554   else
2555     Message += "False\n";
2556
2557   if (PE.IsLinear()) { 
2558     Message += " PE.IsLinear() = True \n";
2559     L = PE.Line();
2560     Handle(Geom_Line) aLine = new Geom_Line(L);
2561     Handle(Geom_TrimmedCurve) aTrimmedCurve = new Geom_TrimmedCurve(aLine,-10,10);
2562     Handle(ISession_Curve) aCurve = new ISession_Curve(aTrimmedCurve);
2563     aDoc->GetAISContext()->Display(aCurve, Standard_False);
2564   }
2565   else
2566     Message += "PE.IsLinear() = False \n";
2567
2568   Message += " PE.IsPlanar() = ";
2569   if (PE.IsPlanar())
2570     Message += "True \n";
2571   else
2572     Message += "False\n";
2573
2574   Message += " PE.IsSpace() = ";
2575   if (PE.IsSpace())
2576     Message += "True \n";
2577   else
2578     Message += "False\n";
2579
2580   PostProcess(aDoc,ID_BUTTON_Test_34,TheDisplayType,Message.ToCString());
2581 }
2582
2583 // Function name        : GeomSources::gpTest35
2584 // Description      : 
2585 // Return type          : void 
2586 // Argument         : CGeometryDoc* aDoc
2587 void GeomSources::gpTest35(CGeometryDoc* aDoc)
2588 {
2589   DisplayType TheDisplayType = No2D3D;
2590   PreProcess(aDoc,TheDisplayType);
2591
2592   //==============================================================
2593
2594   gp_Pnt P1(-5,-5,0);
2595   gp_Pnt P2(9,9,9);
2596   Handle(Geom_Curve) aCurve = GC_MakeSegment(P1,P2).Value();
2597   gp_Pnt P3(3,0,0);
2598   gp_Pnt P4(3,0,10);
2599   Standard_Real radius1 = 3;
2600   Standard_Real radius2 = 2;
2601   Handle(Geom_Surface) aSurface =
2602       GC_MakeConicalSurface(P3,P4,radius1,radius2).Value();
2603   GeomAPI_IntCS CS (aCurve,aSurface);
2604   Handle(Geom_Curve) segment;
2605
2606   Standard_Integer NbSeg = 0;
2607   Standard_Integer NbPoints = 0;
2608   if(CS.IsDone())
2609   {
2610     NbSeg = CS.NbSegments();
2611     for (Standard_Integer k=1; k<=NbSeg; k++)
2612     {
2613       segment = CS.Segment(k);
2614       // do something with the segment
2615     }
2616
2617     NbPoints = CS.NbPoints();
2618     for (int k=1; k<=NbPoints; k++)
2619     {
2620       gp_Pnt aPoint=CS.Point(k);
2621       // do something with the point
2622     }
2623   }
2624
2625   //==============================================================
2626   TCollection_AsciiString Message (" \
2627                                                             \n\
2628 gp_Pnt P1(-5,-5,0);                                         \n\
2629 gp_Pnt P2(9,9,9);                                           \n\
2630 Handle(Geom_Curve) aCurve = GC_MakeSegment(P1,P2).Value();  \n\
2631 gp_Pnt P3(3,0,0);                                           \n\
2632 gp_Pnt P4(3,0,10);                                          \n\
2633 Standard_Real radius1 = 3;                                  \n\
2634 Standard_Real radius2 = 2;                                  \n\
2635 Handle(Geom_Surface) aSurface =                             \n\
2636     GC_MakeConicalSurface(P3,P4,radius1,radius2).Value();   \n\
2637 GeomAPI_IntCS CS (aCurve,aSurface);                         \n\
2638 Handle(Geom_Curve) segment;                                 \n\
2639                                                             \n\
2640 Standard_Integer NbSeg;                                     \n\
2641 Standard_Integer NbPoints;                                  \n\
2642 if(CS.IsDone())                                             \n\
2643     {                                                       \n\
2644       NbSeg = CS.NbSegments();                              \n\
2645       for (Standard_Integer k=1; k<=NbSeg; k++)             \n\
2646         {                                                   \n\
2647           segment = CS.Segment(k);                          \n\
2648          // do something with the segment                   \n\
2649         }                                                   \n\
2650                                                             \n\
2651       NbPoints = CS.NbPoints();                             \n\
2652       for (k=1; k<=NbPoints; k++)                           \n\
2653         {                                                   \n\
2654           gp_Pnt aPoint=CS.Point(k);                        \n\
2655           // do something with the point                    \n\
2656         }                                                   \n\
2657     }                                                       \n\
2658                                                             \n");
2659   AddSeparator(aDoc,Message);
2660
2661   //--------------------------------------------------------------
2662  
2663   Handle(ISession_Curve) aCurve2 = new ISession_Curve(aCurve);
2664   aDoc->GetAISContext()->Display(aCurve2, Standard_False);
2665
2666   Handle(Geom_RectangularTrimmedSurface) aTrimmedSurface= new Geom_RectangularTrimmedSurface(aSurface,-50.,50.,false);
2667
2668   DisplaySurface(aDoc,aTrimmedSurface);
2669
2670   TCollection_AsciiString aString;
2671   Standard_Integer k;
2672   if(CS.IsDone())
2673   {
2674     Standard_Integer NbSeg = CS.NbSegments();
2675     for (k=1; k<=NbSeg; k++)
2676     {
2677       TCollection_AsciiString Message2 (k);
2678       segment = CS.Segment(k);
2679       aString = "S_";aString += Message2;
2680       Handle(ISession_Curve) aCurve = new ISession_Curve(segment);
2681       aDoc->GetAISContext()->Display(aCurve, Standard_False);
2682     }
2683
2684     for ( k=1; k<=NbPoints; k++)
2685     {
2686       TCollection_AsciiString Message2 (k);
2687       gp_Pnt aPoint=CS.Point(k);
2688       aString = "P_";aString += Message2;
2689       DisplayPoint(aDoc,aPoint,aString.ToCString(),false,0.5);
2690       // do something with the point
2691     }
2692   }
2693   TCollection_AsciiString Message2 (NbSeg);
2694   TCollection_AsciiString Message3 (NbPoints);
2695
2696   Message += "NbSeg       = "; Message += Message2      ; Message += "\n";
2697   Message += "NbPoints  = "; Message += Message3      ; Message += "\n";
2698
2699   PostProcess(aDoc,ID_BUTTON_Test_35,TheDisplayType,Message.ToCString());
2700 }
2701
2702 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2703
2704 // Function name        : GeomSources::gpTest36
2705 // Description      : 
2706 // Return type          : void 
2707 // Argument         : CGeometryDoc* aDoc
2708 void GeomSources::gpTest36(CGeometryDoc* aDoc)
2709 {
2710   DisplayType TheDisplayType = No2D3D;
2711   PreProcess(aDoc,TheDisplayType);
2712 //==============================================================
2713
2714   gp_Pnt centre (5,5,0); gp_Pnt axispoint (9,9,0);
2715   Standard_Real radius = 3;
2716   Handle(Geom_Circle) circle =
2717   GC_MakeCircle(centre,axispoint,radius);
2718
2719   Handle(Geom_Geometry) aRotatedEntity = circle->Rotated(gp::OZ(),M_PI/4);
2720   Standard_CString aRotatedEntityTypeName = aRotatedEntity->DynamicType()->Name();
2721
2722   Handle(Geom_Geometry) aMirroredEntity = aRotatedEntity->Mirrored(gp::ZOX());
2723   Standard_CString aMirroredEntityTypeName = aMirroredEntity->DynamicType()->Name();
2724
2725   gp_Pnt scalepoint (4,8,0);
2726   Standard_Real scalefactor = 0.2;
2727   Handle(Geom_Geometry) aScaledEntity =
2728   aMirroredEntity->Scaled(scalepoint, scalefactor);
2729   Standard_CString aScaledEntityTypeName = aScaledEntity->DynamicType()->Name();
2730
2731   Handle (Geom_Transformation) GT = GC_MakeTranslation (centre, scalepoint);
2732   gp_Trsf TR = GT->Trsf();
2733
2734   gp_Vec aTranslationVector(TR.TranslationPart ());
2735   Handle(Geom_Geometry) aTranslatedEntity =
2736   aScaledEntity->Translated( aTranslationVector );
2737   Standard_CString aTranslatedEntityTypeName = aTranslatedEntity->DynamicType()->Name();
2738
2739   gp_Mat matrix = TR.HVectorialPart();
2740   Standard_Real value = matrix.Determinant();
2741
2742 //==============================================================
2743     TCollection_AsciiString Message (" \
2744                                                                                         \n\
2745 gp_Pnt centre (5,5,0);  gp_Pnt axispoint (9,9,0);                                       \n\
2746 Standard_Real radius = 3;                                                               \n\
2747 Handle(Geom_Circle) circle =                                                            \n\
2748     GC_MakeCircle(centre,axispoint,radius);                                             \n\
2749                                                                                         \n\
2750 Handle(Geom_Geometry) aRotatedEntity  = circle->Rotated(gp::OZ(),PI/4);                 \n\
2751 Standard_CString aRotatedEntityTypeName = aRotatedEntity->DynamicType()->Name();        \n\
2752                                                                                         \n\
2753 Handle(Geom_Geometry) aMirroredEntity = aRotatedEntity->Mirrored(gp::ZOX());            \n\
2754 Standard_CString aMirroredEntityTypeName = aMirroredEntity->DynamicType()->Name();      \n\
2755                                                                                         \n\
2756 gp_Pnt scalepoint (4,8,0);                                                              \n\
2757 Standard_Real scalefactor = 0.2;                                                        \n\
2758 Handle(Geom_Geometry) aScaledEntity =                                                   \n\
2759      aMirroredEntity->Scaled(scalepoint, scalefactor);                                  \n\
2760 Standard_CString aScaledEntityTypeName = aScaledEntity->DynamicType()->Name();          \n\
2761                                                                                         \n\
2762 Handle (Geom_Transformation) GT =   GC_MakeTranslation  (centre, scalepoint);           \n\
2763 gp_Trsf TR = GT->Trsf();                                                                \n\
2764                                                                                         \n");
2765    Message +="\
2766 gp_Vec aTranslationVector(TR.TranslationPart ());                                       \n\
2767 Handle(Geom_Geometry) aTranslatedEntity =                                               \n\
2768        aScaledEntity->Translated(  aTranslationVector  );                               \n\
2769 Standard_CString aTranslatedEntityTypeName = aTranslatedEntity->DynamicType()->Name();  \n\
2770                                                                                         \n\
2771 gp_Mat matrix = TR.HVectorialPart();                                                    \n\
2772 Standard_Real value = matrix.Determinant();                                             \n\
2773                                                                                         \n";
2774   AddSeparator(aDoc,Message);
2775   //--------------------------------------------------------------
2776
2777   DisplayPoint(aDoc,centre,"centre",false,0.5);
2778   DisplayPoint(aDoc,axispoint,"axispoint",false,0.5);
2779   DisplayPoint(aDoc,scalepoint,"scalepoint",false,0.5);
2780
2781   DisplayCurve(aDoc,circle, Quantity_NOC_RED,false);
2782   DisplayCurve(aDoc,Handle(Geom_Curve)::DownCast(aRotatedEntity),Quantity_NOC_PEACHPUFF, false);
2783   DisplayCurve(aDoc,Handle(Geom_Curve)::DownCast(aMirroredEntity), Quantity_NOC_YELLOWGREEN,false);
2784   DisplayCurve(aDoc,Handle(Geom_Curve)::DownCast(aScaledEntity), Quantity_NOC_GREEN,false);
2785   DisplayCurve(aDoc,Handle(Geom_Curve)::DownCast(aTranslatedEntity),Quantity_NOC_WHITE,false);
2786
2787   TCollection_AsciiString Message0 (M_PI);
2788   Message += " PI = ";
2789   Message+= Message0;
2790   Message += "\n";
2791   Message += " circle is Red; aRotatedEntity is Peach; aMirroredEntity is Yellow Green\n";
2792   Message += " aScaleEntity is Green; aTranslatedEntity is White\n\n";
2793
2794   TCollection_AsciiString Message2 (aTranslationVector.X());
2795   TCollection_AsciiString Message3 (aTranslationVector.Y());
2796   TCollection_AsciiString Message4 (aTranslationVector.Z());
2797   Message += " aTranslationVector ( ";
2798   Message += Message2; Message += " , ";
2799   Message += Message3; Message += " , ";
2800   Message += Message4; Message += " ); \n";
2801
2802   TCollection_AsciiString Message5 (value);
2803   Message += " value = ";Message+= Message5; Message += "\n";
2804
2805   TCollection_AsciiString Message6 (aRotatedEntityTypeName);
2806   TCollection_AsciiString Message7 (aMirroredEntityTypeName);
2807   TCollection_AsciiString Message8 (aScaledEntityTypeName);
2808   TCollection_AsciiString Message9 (aTranslatedEntityTypeName);
2809
2810   Message += " aRotatedEntityTypeName = ";Message+= Message6; Message += "\n";
2811   Message += " aMirroredEntityTypeName = ";Message+= Message7; Message += "\n";
2812   Message += " aScaledEntityTypeName = ";Message+= Message8; Message += "\n";
2813   Message += " aTranslatedEntityTypeName = ";Message+= Message9; Message += "\n";
2814
2815   PostProcess(aDoc,ID_BUTTON_Test_36,TheDisplayType,Message.ToCString());
2816 }
2817
2818 // Function name        : GeomSources::gpTest37
2819 // Description      : 
2820 // Return type          : void 
2821 // Argument         : CGeometryDoc* aDoc
2822 void GeomSources::gpTest37(CGeometryDoc* aDoc)
2823 {
2824   DisplayType TheDisplayType = No2D3D;
2825   PreProcess(aDoc,TheDisplayType);
2826   //==============================================================
2827
2828   TColgp_Array1OfPnt anArrayofPnt (1,5); // sizing array
2829   anArrayofPnt.SetValue(1,gp_Pnt(0,0,1));
2830   anArrayofPnt.SetValue(2,gp_Pnt(1,2,2));
2831   anArrayofPnt.SetValue(3,gp_Pnt(2,3,3));
2832   anArrayofPnt.SetValue(4,gp_Pnt(4,3,4));
2833   anArrayofPnt.SetValue(5,gp_Pnt(5,5,5));
2834
2835   Standard_Real Tolerance = 1;
2836
2837   gp_Pln P;
2838   GProp_PEquation PE (anArrayofPnt,Tolerance);
2839   if (PE.IsPlanar()) { P = PE.Plane();}
2840
2841   if (PE.IsPoint()) { /* ... */ }
2842   if (PE.IsLinear()) { /* ... */ }
2843   if (PE.IsPlanar()) { P = PE.Plane();}
2844   if (PE.IsSpace()) { /* ... */ }
2845
2846   //==============================================================
2847     TCollection_AsciiString Message (" \
2848                                                                  \n\
2849 TColgp_Array1OfPnt anArrayofPnt (1,5); // sizing array           \n\
2850 anArrayofPnt.SetValue(1,gp_Pnt(0,0,1));                          \n\
2851 anArrayofPnt.SetValue(2,gp_Pnt(1,2,2));                          \n\
2852 anArrayofPnt.SetValue(3,gp_Pnt(2,3,3));                          \n\
2853 anArrayofPnt.SetValue(4,gp_Pnt(4,3,4));                          \n\
2854 anArrayofPnt.SetValue(5,gp_Pnt(5,5,5));                          \n\
2855                                                                  \n\
2856 Standard_Real Tolerance = 1;                                     \n\
2857                                                                  \n\
2858 gp_Pln P;                                                        \n\
2859 GProp_PEquation PE (anArrayofPnt,Tolerance);                     \n\
2860 if (PE.IsPlanar()) { P = PE.Plane();}                            \n\
2861                                                                  \n\
2862 if (PE.IsPoint())  { /* ... */  }                                \n\
2863 if (PE.IsLinear()) { /* ... */  }                                \n\
2864 if (PE.IsPlanar()) { P = PE.Plane();}                            \n\
2865 if (PE.IsSpace())  { /* ... */  }                                \n\
2866                                                                  \n");
2867   AddSeparator(aDoc,Message);
2868   //--------------------------------------------------------------
2869
2870   TCollection_AsciiString aString;
2871   for(Standard_Integer i = anArrayofPnt.Lower();i<=anArrayofPnt.Upper();i++){
2872     TCollection_AsciiString Message2(i);
2873     gp_Pnt P = anArrayofPnt(i);
2874     aString = "P";aString += Message2; 
2875     DisplayPoint(aDoc,P,aString.ToCString(),false,0.5);
2876   }
2877
2878   Message += " PE.IsPoint()  = ";  if (PE.IsPoint()) Message += "True \n";  else Message += "False\n";
2879   Message += " PE.IsLinear() = ";  if (PE.IsLinear()) Message += "True \n";  else Message += "False\n";
2880
2881   if (PE.IsPlanar()) { 
2882     Message +=  " PE.IsPlanar() = True \n";
2883     P = PE.Plane();
2884     Handle(Geom_Plane) aPlane = new Geom_Plane(P);
2885     Handle(Geom_RectangularTrimmedSurface) aSurface= new Geom_RectangularTrimmedSurface(aPlane,-4.,4.,-4.,4.);
2886
2887     DisplaySurface(aDoc,aSurface);
2888
2889   }
2890   else
2891     Message += " PE.IsPlanar() = False \n";
2892
2893   Message += " PE.IsSpace() = ";   if (PE.IsSpace() ) Message += "True \n";  else Message += "False\n";
2894
2895   PostProcess(aDoc,ID_BUTTON_Test_37,TheDisplayType,Message.ToCString());
2896 }
2897
2898 void GeomSources::gpTest38(CGeometryDoc* aDoc)
2899 {
2900   DisplayType TheDisplayType = No2D3D;
2901   PreProcess(aDoc,TheDisplayType);
2902   //==============================================================
2903
2904   TColgp_Array1OfPnt array1 (1,5); // sizing array
2905   array1.SetValue(1,gp_Pnt (-4,0,2 )); array1.SetValue(2,gp_Pnt (-7,2,2 ));
2906   array1.SetValue(3,gp_Pnt (-6,3,1 )); array1.SetValue(4,gp_Pnt (-4,3,-1));
2907   array1.SetValue(5,gp_Pnt (-3,5,-2));
2908   Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(array1).Curve();
2909
2910   TColgp_Array1OfPnt array2 (1,5); // sizing array
2911   array2.SetValue(1,gp_Pnt (-4,0, 2)); array2.SetValue(2,gp_Pnt (-2,2,0 ));
2912   array2.SetValue(3,gp_Pnt (2 ,3,-1)); array2.SetValue(4,gp_Pnt (3 ,7,-2));
2913   array2.SetValue(5,gp_Pnt (4 ,9,-1));
2914   Handle(Geom_BSplineCurve) SPL2 = GeomAPI_PointsToBSpline(array2).Curve();
2915
2916   GeomFill_FillingStyle Type = GeomFill_StretchStyle;
2917   GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);
2918   Handle(Geom_BSplineSurface) aBSplineSurface1 = aGeomFill1.Surface();
2919
2920   Type = GeomFill_CoonsStyle;
2921   GeomFill_BSplineCurves aGeomFill2(
2922   Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(10,0,0))),
2923   Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(10,0,0))),Type);
2924   Handle(Geom_BSplineSurface) aBSplineSurface2 = aGeomFill2.Surface();
2925   Type = GeomFill_CurvedStyle;
2926   GeomFill_BSplineCurves aGeomFill3(
2927   Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(20,0,0))),
2928   Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(20,0,0))),Type);
2929   Handle(Geom_BSplineSurface) aBSplineSurface3 = aGeomFill3.Surface();
2930
2931   //==============================================================
2932   TCollection_AsciiString Message (" \
2933                                                                                       \n\
2934 TColgp_Array1OfPnt array1 (1,5); // sizing array                                      \n\
2935 array1.SetValue(1,gp_Pnt (-4,0,2 )); array1.SetValue(2,gp_Pnt (-7,2,2 ));             \n\
2936 array1.SetValue(3,gp_Pnt (-6,3,1 )); array1.SetValue(4,gp_Pnt (-4,3,-1));             \n\
2937 array1.SetValue(5,gp_Pnt (-3,5,-2));                                                  \n\
2938 Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(array1).Curve();             \n\
2939                                                                                       \n\
2940 TColgp_Array1OfPnt array2 (1,5); // sizing array                                      \n\
2941 array2.SetValue(1,gp_Pnt (-4,0, 2)); array2.SetValue(2,gp_Pnt (-2,2,0 ));             \n\
2942 array2.SetValue(3,gp_Pnt (2 ,3,-1)); array2.SetValue(4,gp_Pnt (3 ,7,-2));             \n\
2943 array2.SetValue(5,gp_Pnt (4 ,9,-1));                                                  \n\
2944 Handle(Geom_BSplineCurve) SPL2 = GeomAPI_PointsToBSpline(array2).Curve();             \n\
2945                                                                                       \n\
2946 GeomFill_FillingStyle Type = GeomFill_StretchStyle;                                   \n\
2947 GeomFill_BSplineCurves aGeomFill1(SPL1,SPL2,Type);                                    \n\
2948 Handle(Geom_BSplineSurface)    aBSplineSurface1 = aGeomFill1.Surface();               \n\
2949                                                                                       \n\
2950 Type = GeomFill_CoonsStyle;                                                           \n\
2951 GeomFill_BSplineCurves aGeomFill2(                                                    \n");
2952 Message += "\
2953         Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(10,0,0))),        \n\
2954         Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(10,0,0))),Type);  \n\
2955 Handle(Geom_BSplineSurface)    aBSplineSurface2 = aGeomFill2.Surface();               \n\
2956 Type = GeomFill_CurvedStyle;                                                          \n\
2957 GeomFill_BSplineCurves aGeomFill3(                                                    \n\
2958         Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(20,0,0))),        \n\
2959         Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(20,0,0))),Type);  \n\
2960 Handle(Geom_BSplineSurface)    aBSplineSurface3 = aGeomFill3.Surface();               \n\
2961                                                                                       \n";
2962   AddSeparator(aDoc,Message);
2963   //--------------------------------------------------------------
2964
2965   // Trace des frontieres.  -> FreeBoundaryAspect
2966   // Trace des isoparametriques.  --> UIsoAspect()
2967
2968   DisplaySurface(aDoc,aBSplineSurface1,Quantity_NOC_YELLOW);
2969   DisplaySurface(aDoc,aBSplineSurface2,Quantity_NOC_SALMON);
2970   DisplaySurface(aDoc,aBSplineSurface3,Quantity_NOC_HOTPINK);
2971
2972   for (int i=0;i<=2;i++)
2973   {
2974     DisplayCurve(aDoc,Handle(Geom_BSplineCurve)::DownCast(SPL1->Translated(gp_Vec(i*10,0,0))), Quantity_NOC_RED,false);
2975     DisplayCurve(aDoc,Handle(Geom_BSplineCurve)::DownCast(SPL2->Translated(gp_Vec(i*10,0,0))), Quantity_NOC_GREEN,false);
2976   }
2977
2978   Message += "SPL1                      is Red; \n";
2979   Message += "SPL2                      is Green; \n";
2980   Message += "aBSplineSurface1  is Yellow;       ( GeomFill_StretchStyle )\n";   
2981   Message += "aBSplineSurface2  is Salmon;     ( GeomFill_CoonsStyle ) \n";
2982   Message += "aBSplineSurface3  is Hot pink;   ( GeomFill_CurvedStyle ) \n";
2983
2984   PostProcess(aDoc,ID_BUTTON_Test_38,TheDisplayType,Message.ToCString());
2985 }
2986 void GeomSources::gpTest39(CGeometryDoc* aDoc)
2987 {
2988   DisplayType TheDisplayType = No2D3D;
2989   PreProcess(aDoc,TheDisplayType);