2756abaad33b2e7e69bead5094d022713f94a286
[occt.git] / src / Viewer2dTest / Viewer2dTest_DisplayCommands.cxx
1 // File:      Viewer2dTest_DisplayCommands.cxx
2 // Created:   22.01.02 16:21:20
3 // Author:    Julia DOROVSKIKH
4 // Copyright: Open Cascade 2001
5
6 #include <Viewer2dTest.hxx>
7
8 #include <Viewer2dTest_EventManager.hxx>
9 #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx>
10 #include <Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
11
12 #include <Draw_Interpretor.hxx>
13
14 #include <HLRAlgo_Projector.hxx>
15
16 #include <V2d_Viewer.hxx>
17 #include <V2d_View.hxx>
18
19 #include <Prs2d_AspectRoot.hxx>
20 #include <Prs2d_AspectLine.hxx>
21
22 #include <gp_Ax3.hxx>
23
24 #include <TopoDS.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
27
28 #include <BRep_Tool.hxx>
29
30 #include <TCollection_AsciiString.hxx>
31
32 #include <gp_Ax2.hxx>
33
34 #include <AIS2D_ProjShape.hxx>
35 #include <AIS2D_InteractiveContext.hxx>
36
37 #include <Quantity_NameOfColor.hxx>
38 #include <Quantity_Color.hxx>
39
40 #include <Graphic2d_Line.hxx>
41 #include <Graphic2d_Marker.hxx>
42 #include <Graphic2d_View.hxx>
43
44 #include <Graphic3d_NameOfMaterial.hxx>
45 #include <Prs2d_Arrow.hxx>
46 #include <GCE2d_MakeSegment.hxx>
47 #include <GGraphic2d_Curve.hxx>
48 #include <Graphic2d_Text.hxx>
49 #include <AIS2D_ListOfIO.hxx>
50 #include <Prs2d_ToleranceFrame.hxx>
51 #include <Prs2d_Length.hxx>
52 #include <gp_Ax22d.hxx>
53 #include <gp_Circ2d.hxx>
54 #include <Graphic2d_Circle.hxx>
55 #include <Prs2d_Diameter.hxx>
56 #include <Prs2d_Point.hxx>
57 #include <Prs2d_Axis.hxx>
58 #include <Geom2d_Line.hxx>
59 #include <Graphic2d_Segment.hxx>
60 #include <GCE2d_MakeArcOfCircle.hxx>
61 #include <Graphic2d_Polyline.hxx>
62 #include <Graphic2d_Array1OfVertex.hxx>
63 #include <TColgp_Array1OfPnt2d.hxx>
64 #include <Geom2d_BezierCurve.hxx>
65 #include <Geom2d_Ellipse.hxx>
66 #include <DrawTrSurf.hxx>
67 #include <GCE2d_MakeSegment.hxx>
68 #include <GGraphic2d_SetOfCurves.hxx>
69 #include <Prs2d_AspectText.hxx>
70 #include <gp_Lin2d.hxx>
71 #include <Prs2d_Angle.hxx>
72 #include <Prs2d_Radius.hxx>
73 #include <Prs2d_Circularity.hxx>
74 #include <Prs2d_Parallelism.hxx>
75
76 #define OCC190 // jfa 04/03/2002 // for vertices load
77 #define OCC154 // jfa 06/03/2002 // for correct erasing
78
79 #define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
80 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
81
82 Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D();
83 Handle(AIS2D_InteractiveContext)& TheAIS2DContext();
84 TopoDS_Shape GetShapeFromName2d (const char* name);
85
86 //==============================================================================
87 //function : GetAIS2DShapeFromName
88 //purpose  : Compute an AIS2D_ProjShape from a draw variable or a file name
89 //==============================================================================
90 Handle(AIS2D_InteractiveObject) GetAIS2DShapeFromName
91        (const char* name, gp_Ax2 anAx2 = gp::XOY())
92 {
93   Handle(AIS2D_InteractiveObject) retsh;
94
95   if (GetMapOfAIS2D().IsBound2(name))
96   {
97     Handle(AIS2D_InteractiveObject) IO = GetMapOfAIS2D().Find2(name);
98 //    if(IO->Type() == AIS2D_KOI_Shape)
99 //      if (IO->Signature() == 0){
100 //      retsh = *((Handle(AIS2D_ProjShape)*)&IO);
101 //      }
102 //    else
103     cout << "an Object which is not an AIS2D_ProjShape already has this name!!!" << endl;
104     return retsh;
105   }
106
107   TopoDS_Shape S = GetShapeFromName2d(name);
108   if (!S.IsNull())
109   {
110 #ifdef OCC190
111     if (S.ShapeType() == TopAbs_VERTEX)
112     {
113       TopoDS_Vertex aVert = TopoDS::Vertex(S);
114       gp_Pnt aPnt = BRep_Tool::Pnt(aVert);
115
116       gp_Trsf aTrsf;
117       gp_Ax3 aToSystem (anAx2);
118       aTrsf.SetTransformation(aToSystem);
119       aPnt.Transform(aTrsf);
120
121       Handle(V2d_View) V = Viewer2dTest::CurrentView();
122       retsh = new AIS2D_InteractiveObject();
123       retsh->SetView(V->View());
124
125 #define VERTEXMARKER 2
126 #define DEFAULTMARKERSIZE 3.0
127
128       Handle(Graphic2d_Marker) vertex = new Graphic2d_Marker
129         (retsh, VERTEXMARKER, aPnt.X(), aPnt.Y(), DEFAULTMARKERSIZE, DEFAULTMARKERSIZE, 0.0);
130     }
131     else
132 #endif
133     {
134       HLRAlgo_Projector aProjector (anAx2);
135       Handle(AIS2D_ProjShape) retprsh = new AIS2D_ProjShape(aProjector);
136       retprsh->Add(S);
137       retsh = retprsh;
138     }
139   }
140   return retsh; 
141 }
142
143 //=======================================================================
144 //function : GetColorFromName2d
145 //purpose  : get the Quantity_NameOfColor from a string
146 //=======================================================================
147 static Quantity_NameOfColor GetColorFromName2d (const char *name) 
148
149   Quantity_NameOfColor ret = DEFAULT_COLOR;
150   
151   Standard_Boolean Found = Standard_False;
152   Standard_CString colstring;
153   for (Standard_Integer i = 0; i <= 514 && !Found; i++)
154   {
155     colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
156     if (!strcasecmp(name,colstring))
157     {
158       ret = (Quantity_NameOfColor)i;
159       Found = Standard_True;
160     }
161   }
162
163   return ret;
164 }
165 #if 0
166 //=======================================================================
167 //function : GetMaterialFromName2d
168 //purpose  : get the Graphic3d_NameOfMaterial from a string
169 //=======================================================================
170 static Graphic3d_NameOfMaterial GetMaterialFromName2d (const char *name) 
171
172   Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
173   
174   if      ( !strcasecmp(name,"BRASS" ) )         mat = Graphic3d_NOM_BRASS;
175   else if ( !strcasecmp(name,"BRONZE" ) )        mat = Graphic3d_NOM_BRONZE;
176   else if ( !strcasecmp(name,"COPPER" ) )        mat = Graphic3d_NOM_COPPER;
177   else if ( !strcasecmp(name,"GOLD" ) )          mat = Graphic3d_NOM_GOLD;
178   else if ( !strcasecmp(name,"PEWTER" ) )        mat = Graphic3d_NOM_PEWTER;
179   else if ( !strcasecmp(name,"SILVER" ) )        mat = Graphic3d_NOM_SILVER;
180   else if ( !strcasecmp(name,"STEEL" ) )         mat = Graphic3d_NOM_STEEL;
181   else if ( !strcasecmp(name,"METALIZED" ) )     mat = Graphic3d_NOM_METALIZED;
182   else if ( !strcasecmp(name,"STONE" ) )         mat = Graphic3d_NOM_STONE;
183   else if ( !strcasecmp(name,"CHROME" ) )        mat = Graphic3d_NOM_CHROME;
184   else if ( !strcasecmp(name,"ALUMINIUM" ) )     mat = Graphic3d_NOM_ALUMINIUM;
185   else if ( !strcasecmp(name,"STONE" ) )         mat = Graphic3d_NOM_STONE;
186   else if ( !strcasecmp(name,"NEON_PHC" ) )      mat = Graphic3d_NOM_NEON_PHC;
187   else if ( !strcasecmp(name,"NEON_GNC" ) )      mat = Graphic3d_NOM_NEON_GNC;
188   else if ( !strcasecmp(name,"PLASTER" ) )       mat = Graphic3d_NOM_PLASTER;
189   else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
190   else if ( !strcasecmp(name,"SATIN" ) )         mat = Graphic3d_NOM_SATIN;
191   else if ( !strcasecmp(name,"PLASTIC" ) )       mat = Graphic3d_NOM_PLASTIC;
192   else if ( !strcasecmp(name,"OBSIDIAN" ) )      mat = Graphic3d_NOM_OBSIDIAN;
193   else if ( !strcasecmp(name,"JADE" ) )          mat = Graphic3d_NOM_JADE;
194
195 #ifdef DEB
196   cout << " materiau" << name <<" "<<Standard_Integer(mat) << endl;
197 #endif
198   return mat;
199 }
200 #endif
201
202 //==============================================================================
203 //function : Select2d
204 //purpose  : pick / select an object from the last MoveTo() on a
205 //            ButtonPress event
206 //==============================================================================
207 Handle(AIS2D_InteractiveObject) Select2d (Standard_Integer /*argc*/,
208                                           const char** /*argv*/,
209                                           Standard_Boolean shift,
210                                           Standard_Boolean /*pick*/)
211 {
212   Handle(AIS2D_InteractiveObject) ret;
213   Handle (Viewer2dTest_EventManager) EM = Viewer2dTest::CurrentEventManager();
214   if (shift) EM->ShiftSelect();
215   else       EM->Select();
216
217   const Handle(AIS2D_InteractiveContext) aContext = EM->Context();
218   
219   if (!aContext->HasOpenedContext())
220   {
221 //    aContext->InitCurrent();
222 /*    while ( aContext->MoreCurrent() ) {
223       Handle(AIS2D_InteractiveObject) aisPickedShape = 
224         Handle(AIS2D_InteractiveObject)::DownCast(aContext->Current()); 
225       
226       const char *name = (GetMapOfAIS2D().IsBound1(aisPickedShape))? 
227         GetMapOfAIS2D().Find1(aisPickedShape).ToCString() : 
228           "????";
229       Handle(AIS2D_ProjShape) TheRealSh = Handle(AIS2D_ProjShape)::DownCast(aisPickedShape);
230       if(!TheRealSh.IsNull()){
231         cout << "Current is " << name 
232           << " (" << GetTypeNameFromShape2d(TheRealSh->Shape())
233             << ")" << endl;
234       }
235       ret = aisPickedShape;
236       if(!TheRealSh.IsNull()){
237         if ( pick && argc > 4 ) {
238           DBRep::Set(argv[4], TheRealSh->Shape());
239         }
240       }
241       aContext->NextCurrent();
242     }*/
243   }
244   else
245   {
246     // A LocalContext is opened, the use xxxxSelected() 
247     // to select an object and its SubShape
248 /*    aContext->InitSelected();
249     while ( aContext->MoreSelected() ) {
250       if ( !aContext->HasSelectedShape() ) {
251       }
252       else {      
253         TopoDS_Shape PickedShape = aContext->SelectedShape();
254         if ( pick && argc > 5 ) {
255           DBRep::Set(argv[5], PickedShape);
256         }
257       }
258       
259       if ( aContext->Interactive().IsNull() ) {
260         cout << "??? (No InteractiveObject selected)" << endl;
261       }
262       else {
263         Handle(AIS2D_InteractiveObject) aisPicked = 
264           Handle(AIS2D_InteractiveObject)::DownCast(aContext->Interactive());
265         ret = aisPicked;
266         Handle(AIS2D_ProjShape) aisPickedShape = Handle(AIS2D_ProjShape)::DownCast(aisPicked);
267         
268         // Get back its name
269         const char *name = ( GetMapOfAIS2D().IsBound1(aisPicked) )? 
270           GetMapOfAIS2D().Find1(aisPicked).ToCString() : 
271             "????";
272         
273         if(!aisPickedShape.IsNull()){
274           if ( pick && argc > 4 ) {
275             // Create a draw variable to store the wohole shape 
276             // for vpick command
277             DBRep::Set(argv[4], aisPickedShape->Shape());
278           }
279           
280           cout << name << " (" << GetTypeNameFromShape2d(aisPickedShape->Shape()) 
281             << ")" << endl  ;
282         }
283       }
284       // Goto the next selected object
285       aContext->NextSelected();
286     }*/
287   }
288   return ret;
289 }
290
291 //==============================================================================
292 //function : Displays,Erase...
293 //purpose  : 
294 //Draw arg : 
295 //==============================================================================
296 static int VwrTst_DispErase2d (const Handle(AIS2D_InteractiveObject)& IO,
297                                const Standard_Integer Mode,
298                                const Standard_Integer TypeOfOperation,
299                                const Standard_Boolean Upd)
300 {
301   Handle(AIS2D_InteractiveContext) Ctx = Viewer2dTest::GetAIS2DContext();
302   
303   switch (TypeOfOperation)
304   {
305   case 1:
306     Ctx->Display(IO,Mode,Upd);
307     break;
308   case 2:
309     Ctx->Erase(IO,Mode,Upd);
310     break;
311   case 3:
312 //    if(IO.IsNull())
313 //      Ctx->SetDisplayMode((AIS2D_DisplayMode)Mode,Upd);
314 //    else
315 //      Ctx->SetDisplayMode(IO,Mode,Upd);
316     break;
317   case 4:
318 //    if(IO.IsNull())
319 //      Ctx->SetDisplayMode(0,Upd);
320 //    else
321 //      Ctx->UnsetDisplayMode(IO,Upd);
322     break;
323   }
324
325   return 0;
326 }
327
328 #if 0
329 //=======================================================================
330 //function :V2dDispMode
331 //purpose  : 
332 //=======================================================================
333 static int V2dDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
334 {
335   TCollection_AsciiString name;
336   if (argc > 3) return 1;
337
338   // display others presentations
339   Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"v2ddispmode") == 0)? 1:
340     (strcasecmp(argv[0],"v2derasemode") == 0) ? 2 :
341       (strcasecmp(argv[0],"v2dsetdispmode") == 0) ? 3 :
342         (strcasecmp(argv[0],"v2dunsetdispmode") == 0) ? 4 : -1;
343   
344   Handle(AIS2D_InteractiveContext) Ctx = Viewer2dTest::GetAIS2DContext();
345   
346   //unset displaymode.. comportement particulier...
347   if (TypeOfOperation == 4)
348   {
349     if (argc == 1)
350     {
351 /*      if(Ctx->NbCurrents()==0 ||
352          Ctx->NbSelected()==0){
353         Handle(AIS2D_InteractiveObject) IO;
354         VwrTst_DispErase2d(IO,-1,4,Standard_False);
355       }
356       else if(!Ctx->HasOpenedContext()){
357         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
358           VwrTst_DispErase2d(Ctx->Current(),-1,4,Standard_False);
359       }
360       else{
361         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
362           VwrTst_DispErase2d(Ctx->Interactive(),-1,4,Standard_False);}*/
363       Ctx->UpdateCurrentViewer();
364     }
365     else
366     {
367       Handle(AIS2D_InteractiveObject) IO;
368       name = argv[1];
369       if (GetMapOfAIS2D().IsBound2(name))
370       {
371         IO = GetMapOfAIS2D().Find2(name);
372         VwrTst_DispErase2d(IO,-1,4,Standard_True);
373       }
374     }
375   }
376   else if (argc == 2)
377   {
378 //    Standard_Integer Dmode = atoi(argv[1]);
379 //    if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
380 //      Handle(AIS2D_InteractiveObject) IO;
381 //      VwrTst_DispErase2d(IO,Dmode,TypeOfOperation,Standard_True);
382 //    }
383     if (!Ctx->HasOpenedContext())
384     {
385       // set/unset display mode sur le Contexte...
386 //      for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
387 //      VwrTst_DispErase2d(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
388 //      }
389       Ctx->UpdateCurrentViewer();
390     }
391     else
392     {
393 //      for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
394 //      Ctx->Display(Ctx->Interactive(),Dmode);
395     }
396   }
397   else
398   {
399     Handle(AIS2D_InteractiveObject) IO;
400     name = argv[1];
401     if (GetMapOfAIS2D().IsBound2(name))
402       IO = GetMapOfAIS2D().Find2(name);
403     VwrTst_DispErase2d(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
404   }
405
406   return 0;
407 }
408 #endif
409
410 //==============================================================================
411 //function : V2dSetBGColor
412 //purpose  : v2dsetbgcolor colorname : change background color
413 //==============================================================================
414 static int V2dSetBGColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
415 {
416   if (argc != 2)
417   {
418     cout << "Usage : v2dsetbgcolor colorname" << endl;
419     return 1;
420   }
421   Handle(V2d_View) V = Viewer2dTest::CurrentView(); 
422   if (V.IsNull()) return 1;
423
424   V->SetBackground(GetColorFromName2d(argv[1]));
425   V->Viewer()->Update();
426   return 0;
427 }
428
429 //==============================================================================
430 //function : V2dColor
431 //purpose  : change the color of a selected or named or displayed shape 
432 //Draw arg : v2dsetcolor [name] color 
433 //==============================================================================
434 static int V2dSetUnsetColor (Handle(AIS2D_InteractiveObject) theShape,
435                              Standard_Boolean HaveToSet,
436                              Quantity_NameOfColor theColor = Quantity_NOC_WHITE)
437 {
438   theShape->SetContext(TheAIS2DContext());
439
440   Handle(Graphic2d_Primitive) aPrim;
441   Handle(Prs2d_AspectRoot)    anAspect;
442   Standard_Integer i = 1, n = theShape->Length();
443   for (; i <= n; i++)
444   {
445     aPrim = theShape->Primitive(i);
446     if (theShape->HasAspect(aPrim))
447     {
448       anAspect = theShape->GetAspect(aPrim);
449       if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
450       else anAspect = NULL;
451     }
452   }
453
454   if (HaveToSet)
455   {
456     if (anAspect.IsNull())
457     {
458       theShape->SetAspect
459         (new Prs2d_AspectLine(theColor, Aspect_TOL_SOLID, Aspect_WOL_THIN,
460                               theColor, Graphic2d_TOPF_FILLED));
461     }
462     else
463     {
464       Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
465       anAspectLine->SetTypeOfFill(Graphic2d_TOPF_FILLED);
466       anAspectLine->SetColor(theColor);
467       anAspectLine->SetInterColor(theColor);
468       theShape->SetAspect(anAspect);
469     }
470   }
471   else // unset color
472   {
473     Handle(Prs2d_AspectLine) anAspectLine;
474     if ( !anAspect.IsNull() )
475       anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
476     else
477       anAspectLine = new Prs2d_AspectLine();
478
479     anAspectLine->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
480     if (theShape->IsKind(STANDARD_TYPE(AIS2D_ProjShape)))
481       {
482         anAspectLine->SetColor(Quantity_NOC_YELLOW);
483         anAspectLine->SetInterColor(Quantity_NOC_YELLOW);
484       }
485     else
486       {
487         anAspectLine->SetColor(Quantity_NOC_WHITE);
488         anAspectLine->SetInterColor(Quantity_NOC_WHITE);
489       }
490     theShape->SetAspect( anAspectLine );
491   }
492
493   return 0;
494 }
495
496 static int V2dColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
497 {
498   Standard_Boolean ThereIsArgument = Standard_False;
499   Standard_Boolean HaveToSet = Standard_False;
500
501   if (strcasecmp(argv[0],"v2dsetcolor") == 0) HaveToSet = Standard_True;
502
503   Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
504   if (HaveToSet)
505   {
506     if (argc < 2 || argc > 3)
507     {
508       cout << "Usage: v2dsetcolor [name] color" << endl;
509       return 1;
510     }
511     if (argc == 3)
512     {
513       ThereIsArgument = Standard_True;
514       aColor = GetColorFromName2d(argv[2]);
515     }
516     else
517     {
518       aColor = GetColorFromName2d(argv[1]);
519     }
520   }
521   else
522   {
523     if (argc > 2)
524     {
525       cout << "Usage: v2dunsetcolor [name]" << endl;
526       return 1;
527     }
528     if (argc == 2) ThereIsArgument = Standard_True;
529   }
530   
531   if (Viewer2dTest::CurrentView().IsNull()) return -1;
532   TheAIS2DContext()->CloseLocalContext();
533
534   if (ThereIsArgument)
535   {
536     TCollection_AsciiString name = argv[1];
537
538     if (GetMapOfAIS2D().IsBound2(name))
539     {
540       Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
541       V2dSetUnsetColor(aShape, HaveToSet, aColor);
542     }
543   }
544   else
545   {
546     Standard_Boolean hasCurrent = Standard_False;
547     Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
548     for (; it.More() && !hasCurrent; it.Next())
549     {
550       if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
551     }
552     for (it.Reset(); it.More(); it.Next())
553     {
554       Handle(AIS2D_InteractiveObject) aShape = it.Key1();
555       if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
556       {
557         V2dSetUnsetColor(aShape, HaveToSet, aColor);
558       }
559     }
560 //    TheAIS2DContext()->UpdateCurrentViewer();
561   }
562   return 0;
563 }
564
565 #if 0
566 //==============================================================================
567 //function : V2dTransparency
568 //purpose  : change the transparency of a selected or named or displayed shape 
569 //Draw arg : v2dsettransp [name] TransparencyCoeficient 
570 //==============================================================================
571 static int V2dTransparency (Draw_Interpretor& , Standard_Integer argc, const char** argv)
572
573   Standard_Boolean ThereIsArgument;
574   Standard_Boolean HaveToSet;
575
576   if (strcasecmp(argv[0], "v2dsettransp") == 0)
577     HaveToSet = Standard_True;
578   else 
579     HaveToSet = Standard_False;
580   
581   if (HaveToSet)
582   {
583     if (argc < 2 || argc > 3)
584     {
585       cout << "Usage: v2dsettransp [name] color" << endl;
586       return 1;
587     }
588     if (argc == 2) ThereIsArgument = Standard_False;
589     else ThereIsArgument = Standard_True;
590   }
591   else
592   {
593     if (argc > 2)
594     {
595       cout << "Usage: v2dunsettransp [name]" << endl;
596       return 1;
597     }
598     if (argc == 2) ThereIsArgument = Standard_True;
599     else ThereIsArgument = Standard_False;
600   }
601   
602   if (Viewer2dTest::CurrentView().IsNull()) return -1;
603   TheAIS2DContext()->CloseLocalContext();
604
605   if (ThereIsArgument)
606   {
607     TCollection_AsciiString name = argv[1];
608     if (GetMapOfAIS2D().IsBound2(name))
609     {
610       Handle(AIS2D_InteractiveObject) ashape = GetMapOfAIS2D().Find2(name);
611 //      if(HaveToSet)
612 //      TheAIS2DContext()->SetTransparency(ashape,atof(argv[2]) );
613 //      else 
614 //      TheAIS2DContext()->UnsetTransparency(ashape);
615     }
616   }
617   else
618   {
619 //    if (TheAIS2DContext()->NbCurrents() > 0)
620     {
621 /*      for (TheAIS2DContext()->InitCurrent(); TheAIS2DContext()->MoreCurrent();
622            TheAIS2DContext()->NextCurrent())
623       {
624         Handle(AIS2D_InteractiveObject) ashape = TheAIS2DContext()->Current();
625         if (HaveToSet)
626         {
627           TheAIS2DContext()->SetTransparency(ashape, atof(argv[1]), Standard_False);
628         }
629         else 
630           TheAIS2DContext()->UnsetTransparency(ashape, Standard_False);
631       }*/
632
633       TheAIS2DContext()->UpdateCurrentViewer();
634     }
635 //    else // shape not defined (neither current, nor named)
636     {
637       Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
638       while (it.More())
639       {
640         Handle(AIS2D_InteractiveObject) ashape = it.Key1();
641 //      if(HaveToSet)
642 //        TheAIS2DContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
643 //      else 
644 //        TheAIS2DContext()->UnsetTransparency(ashape,Standard_False);
645         it.Next();
646       }
647       TheAIS2DContext()->UpdateCurrentViewer();
648     }
649   }
650   return 0;
651 }
652 #endif
653
654 #if 0
655 //==============================================================================
656 //function : V2dMaterial
657 //purpose  : change the Material of a selected or named or displayed shape 
658 //Draw arg : v2dmaterial  [Name] Material 
659 //==============================================================================
660 static int V2dMaterial (Draw_Interpretor& , Standard_Integer argc, const char** argv)
661
662   Standard_Boolean ThereIsName;
663   Standard_Boolean HaveToSet;
664
665   if (strcasecmp(argv[0], "v2dsetmaterial") == 0) HaveToSet = Standard_True;
666   else HaveToSet = Standard_False;
667
668   if (HaveToSet)
669   {
670     if (argc < 2 || argc > 3)
671     {
672       cout << "Usage: v2dsetmaterial [name] material" << endl;
673       return 1;
674     }
675     if (argc == 2) ThereIsName = Standard_False;
676     else ThereIsName = Standard_True;
677   }
678   else
679   {
680     if (argc > 2)
681     {
682       cout << "Usage: v2dunsetmaterial [name]" << endl;
683       return 1;
684     }
685     if (argc == 2) ThereIsName = Standard_True;
686     else ThereIsName = Standard_False;
687   }
688
689   if (Viewer2dTest::CurrentView().IsNull()) return -1;
690   TheAIS2DContext()->CloseLocalContext();
691
692   if (ThereIsName)
693   {
694     TCollection_AsciiString name = argv[1];
695     if (GetMapOfAIS2D().IsBound2(name))
696     {
697       Handle(AIS2D_InteractiveObject) ashape = GetMapOfAIS2D().Find2(name);
698       if (HaveToSet)
699       {
700 //      TheAIS2DContext()->SetMaterial (ashape,GetMaterialFromName2d (argv[2]) );
701       }
702       else
703       {
704 //      TheAIS2DContext()->UnsetMaterial(ashape);
705       }
706     }
707   }
708   else
709   {
710 //    if (TheAIS2DContext()->NbCurrents() > 0)
711     {
712 /*      for (TheAIS2DContext()->InitCurrent(); TheAIS2DContext()->MoreCurrent();
713            TheAIS2DContext()->NextCurrent())
714       {
715         Handle(AIS2D_InteractiveObject) ashape = TheAIS2DContext()->Current();
716         if (HaveToSet)
717         {
718           TheAIS2DContext()->SetMaterial(ashape, GetMaterialFromName2d(argv[1]), Standard_False);
719         }
720         else
721           TheAIS2DContext()->UnsetMaterial(ashape, Standard_False);
722       }*/
723       TheAIS2DContext()->UpdateCurrentViewer();
724     }
725 //    else // shape not defined (neither current, nor named)
726     {
727       Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
728       while (it.More())
729       {
730         Handle(AIS2D_InteractiveObject) ashape = it.Key1();
731         
732 //      if (HaveToSet)
733 //        TheAIS2DContext()->SetMaterial(ashape,GetMaterialFromName2d(argv[1]),Standard_False);
734 //      else TheAIS2DContext()->UnsetMaterial(ashape,Standard_False);
735         it.Next();
736       }
737       TheAIS2DContext()->UpdateCurrentViewer();
738     }
739   }
740   return 0;
741 }
742 #endif
743
744 //==============================================================================
745 //function : V2dWidth
746 //purpose  : change the width of the edges of a selected or named or displayed shape 
747 //Draw arg : v2dsetwidth [Name] WidthEnum(THIN MEDIUM THICK VERYTHICK)
748 //==============================================================================
749 static int V2dSetUnsetWidth (Handle(AIS2D_InteractiveObject) theShape,
750                              Standard_Boolean HaveToSet,
751                              Aspect_WidthOfLine theWOL = Aspect_WOL_THIN)
752 {
753   theShape->SetContext(TheAIS2DContext());
754
755   Handle(Graphic2d_Primitive) aPrim;
756   Handle(Prs2d_AspectRoot)    anAspect;
757   Standard_Integer i = 1, n = theShape->Length();
758   for (; i <= n; i++)
759   {
760     aPrim = theShape->Primitive(i);
761     if (theShape->HasAspect(aPrim))
762     {
763       anAspect = theShape->GetAspect(aPrim);
764       if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
765       else anAspect = NULL;
766     }
767   }
768
769   if (HaveToSet)
770   {
771     if (anAspect.IsNull())
772     {
773       Quantity_NameOfColor aColor;
774       if (theShape->IsKind(STANDARD_TYPE(AIS2D_ProjShape)))
775       {
776         aColor = Quantity_NOC_YELLOW;
777       }
778       else
779       {
780         aColor = Quantity_NOC_WHITE;
781       }
782       anAspect = new Prs2d_AspectLine(aColor, Aspect_TOL_SOLID, theWOL,
783                                       aColor, Graphic2d_TOPF_EMPTY);
784     }
785     else
786     {
787       Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
788       anAspectLine->SetWidth(theWOL);
789     }
790
791     theShape->SetAspect(anAspect);
792   }
793   else // unset width
794   {
795     if (!anAspect.IsNull())
796     {
797       Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
798       anAspectLine->SetWidth(Aspect_WOL_THIN);
799 //          anAspectLine->SetWidthIndex(0);
800       theShape->SetAspect(anAspect);
801     }
802   }
803
804   return 0;
805 }
806
807 static int V2dWidth (Draw_Interpretor& , Standard_Integer argc, const char** argv)
808 {
809   Standard_Boolean ThereIsArgument = Standard_False;
810   Standard_Boolean HaveToSet = Standard_False;
811
812   if (strcasecmp(argv[0], "v2dsetwidth") == 0) HaveToSet = Standard_True;
813
814   const char* aStr;
815   if (HaveToSet)
816   {
817     if (argc < 2 || argc > 3)
818     {
819       cout << "Usage: v2dsetwidth [name] width" << endl;
820       return 1;
821     }
822     if (argc == 3)
823     {
824       ThereIsArgument = Standard_True;
825       aStr = argv[2];
826     }
827     else
828     {
829       aStr = argv[1];
830     }
831   }
832   else
833   {
834     if ( argc > 2 )
835     {
836       cout << "Usage: v2dunsetwidth [name]" << endl;
837       return 1;
838     }
839     if (argc == 2) ThereIsArgument = Standard_True;
840   }
841
842   if (Viewer2dTest::CurrentView().IsNull()) return -1;
843   TheAIS2DContext()->CloseLocalContext();
844
845   Aspect_WidthOfLine aWOL = Aspect_WOL_THIN;
846   if (HaveToSet)
847   {
848     if      (strcmp(aStr, "THIN"     ) == 0) aWOL = Aspect_WOL_THIN;
849     else if (strcmp(aStr, "MEDIUM"   ) == 0) aWOL = Aspect_WOL_MEDIUM;
850     else if (strcmp(aStr, "THICK"    ) == 0) aWOL = Aspect_WOL_THICK;
851     else if (strcmp(aStr, "VERYTHICK") == 0) aWOL = Aspect_WOL_VERYTHICK;
852     else aWOL = Aspect_WOL_USERDEFINED;
853   }
854
855   if (ThereIsArgument)
856   {
857     TCollection_AsciiString name = argv[1];
858
859     if (GetMapOfAIS2D().IsBound2(name))
860     {
861       Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
862       V2dSetUnsetWidth(aShape, HaveToSet, aWOL);
863     }
864   }
865   else
866   {
867     Standard_Boolean hasCurrent = Standard_False;
868     Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
869     for (; it.More() && !hasCurrent; it.Next())
870     {
871       if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
872     }
873     for (it.Reset(); it.More(); it.Next())
874     {
875       Handle(AIS2D_InteractiveObject) aShape = it.Key1();
876       if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
877       {
878         V2dSetUnsetWidth(aShape, HaveToSet, aWOL);
879       }
880     }
881 //    TheAIS2DContext()->UpdateCurrentViewer();
882   }
883   return 0;
884 }
885
886 //==============================================================================
887 //function : V2dDisplay
888 //purpose  : Display an object from its name
889 //Draw arg : v2ddisplay name [projection (Origin(x y z) Normal(dx dy dz) DX(dx dy dz)]
890 //==============================================================================
891 static int V2dDisplay (Draw_Interpretor& , Standard_Integer argc, const char** argv)
892 {
893   // Verification des arguments
894   if (argc != 2 && argc != 11)
895   {
896     cout << "Usage: v2ddisplay name [x y z dx dy dz dx1 dy1 dz1]" << endl;
897     return 1;
898   }
899   
900   if (Viewer2dTest::CurrentView().IsNull())
901   { 
902     cout << "2D AIS Viewer Initialization ..." << endl;
903     Viewer2dTest::ViewerInit(); 
904     cout << "Done" << endl;
905   }
906   
907   TCollection_AsciiString name;
908   TheAIS2DContext()->CloseLocalContext();
909   
910   name = argv[1];
911   gp_Ax2 anAx2 = gp::XOY();
912   if (argc == 11)
913   {
914     Standard_Real x = atof(argv[2]);
915     Standard_Real y = atof(argv[3]);
916     Standard_Real z = atof(argv[4]);
917
918     Standard_Real dx = atof(argv[5]);
919     Standard_Real dy = atof(argv[6]);
920     Standard_Real dz = atof(argv[7]);
921
922     Standard_Real dx1 = atof(argv[8]);
923     Standard_Real dy1 = atof(argv[9]);
924     Standard_Real dz1 = atof(argv[10]);
925
926     gp_Pnt anOrigin (x, y, z);
927     gp_Dir aNormal  (dx, dy, dz);
928     gp_Dir aDX      (dx1, dy1, dz1);
929     anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
930   }
931
932   Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
933   Standard_Boolean IsDatum = Standard_False;
934   Handle(AIS2D_InteractiveObject) aShape;
935   if (IsBound)
936   {
937     aShape = GetMapOfAIS2D().Find2(name);
938 //    if (aShape->Type() == AIS2D_KOI_Datum)
939     {
940       IsDatum = Standard_True;
941       TheAIS2DContext()->Display(aShape, Standard_False);
942 #ifdef OCC154
943       TheAIS2DContext()->HighlightCurrent();
944 #endif
945     }
946     if (!IsDatum)
947     {     
948       cout << "Display " << name << endl;
949       // Get the Shape from a name
950       TopoDS_Shape NewShape = GetShapeFromName2d((const char *)name.ToCString());
951
952       // Update the Shape in the AIS2D_ProjShape                                
953       Handle(AIS2D_ProjShape) TheRealSh = Handle(AIS2D_ProjShape)::DownCast(aShape);
954 //    if(!TheRealSh.IsNull())   TheRealSh->Set(NewShape);
955       TheAIS2DContext()->Redisplay(aShape, Standard_False);
956       TheAIS2DContext()->Display(aShape, Standard_False);
957     }
958     aShape.Nullify();
959   }
960   else // Create the AIS2D_ProjShape from a name
961   {
962     aShape = GetAIS2DShapeFromName((const char *)name.ToCString(), anAx2);
963     if (!aShape.IsNull())
964     {
965       GetMapOfAIS2D().Bind(aShape, name);
966       TheAIS2DContext()->Display(aShape, Standard_False);
967     }
968   }
969
970   // Update the screen and redraw the view
971   TheAIS2DContext()->UpdateCurrentViewer();
972   return 0; 
973 }
974
975 //==============================================================================
976 //function : V2dDonly
977 //purpose  : Display only a selected or named  object
978 //           if there is no selected or named object s, the whole viewer is erased
979 //Draw arg : vdonly [name1] ... [name n]
980 //==============================================================================
981 static int V2dDonly (Draw_Interpretor& , Standard_Integer argc, const char** argv)
982 {
983   if (Viewer2dTest::CurrentView().IsNull()) return 1;
984   
985   Standard_Boolean ThereIsArgument = argc > 1;
986   
987   if (TheAIS2DContext()->HasOpenedContext()) TheAIS2DContext()->CloseLocalContext();
988
989   if (ThereIsArgument)
990   {
991     TheAIS2DContext()->EraseAll(Standard_True, Standard_False);            
992
993     for (int i = 1; i < argc; i++)
994     {
995       TCollection_AsciiString name = argv[i];
996       Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
997       if (IsBound)
998       {
999         Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1000         TheAIS2DContext()->Display(aShape, Standard_False);
1001       }
1002     }
1003     TheAIS2DContext()->CurrentViewer()->Update();
1004   }
1005   else
1006   {
1007     Standard_Boolean ThereIsCurrent = Standard_True/*= TheAIS2DContext()->NbCurrents() > 0*/;
1008     if (ThereIsCurrent)
1009     {
1010       Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1011       while (it.More())
1012       {
1013         Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1014         if (!TheAIS2DContext()->IsCurrent(aShape))
1015           TheAIS2DContext()->Erase(aShape, Standard_False);        
1016         it.Next();
1017       }
1018       TheAIS2DContext()->CurrentViewer()->Update();
1019     }
1020   }
1021
1022   return 0; 
1023 }
1024
1025 //==============================================================================
1026 //function : V2dErase
1027 //purpose  : Erase some selected or named objects.
1028 //           If there is no selected or named objects, does nothing
1029 //Draw arg : v2derase [name1] ... [name n]
1030 //==============================================================================
1031 static int V2dErase (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1032 {
1033   if (Viewer2dTest::CurrentView().IsNull()) return 1;
1034   
1035   if (TheAIS2DContext()->HasOpenedContext()) TheAIS2DContext()->CloseLocalContext();
1036
1037   if (argc > 1) // has arguments
1038   {
1039     for (int i = 1; i < argc; i++)
1040     {
1041       TCollection_AsciiString name = argv[i];
1042       Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
1043       if (IsBound)
1044       {
1045         Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1046         TheAIS2DContext()->Erase(aShape, Standard_False);  
1047       }
1048     }
1049 //    TheAIS2DContext()->UpdateCurrentViewer();
1050     TheAIS2DContext()->CurrentViewer()->Update();
1051   }
1052   else
1053   {
1054     Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1055     while (it.More())
1056     {
1057       Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1058       if (TheAIS2DContext()->IsCurrent(aShape))
1059         TheAIS2DContext()->Erase(aShape, Standard_False);        
1060       it.Next();
1061     }
1062 //    TheAIS2DContext()->UpdateCurrentViewer();
1063     TheAIS2DContext()->CurrentViewer()->Update();
1064   }
1065
1066   return 0; 
1067 }
1068
1069 //==============================================================================
1070 //function : V2dEraseAll
1071 //purpose  : Erase all the objects displayed in the viewer
1072 //Draw arg : v2deraseall
1073 //==============================================================================
1074 static int V2dEraseAll (Draw_Interpretor& , Standard_Integer argc, const char** )
1075 {
1076   if (argc > 1)
1077   {
1078     cout << "Usage: v2deraseall" << endl;
1079     return 1;
1080   }
1081
1082   if (Viewer2dTest::CurrentView().IsNull())
1083   {
1084     cout << " Error: v2dinit hasn't been called." << endl;
1085     return 1;
1086   }
1087
1088   TheAIS2DContext()->CloseAllContext(Standard_False);
1089
1090   // EraseAll(Standard_True, Standard_True);            
1091   TheAIS2DContext()->EraseAll();
1092   return 0;
1093 }
1094
1095 //==============================================================================
1096 //function : V2dDisplayAll
1097 //purpose  : Display all the objects of the Map
1098 //Draw arg : v2ddisplayall
1099 //==============================================================================
1100 static int V2dDisplayAll (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1101 {
1102   if (Viewer2dTest::CurrentView().IsNull()) return 1;
1103
1104   if (argc > 1)
1105   {
1106     cout << argv[0] << " Syntaxe error" << endl;
1107     return 1;
1108   }
1109   TheAIS2DContext()->CloseLocalContext();
1110   Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1111 //  while (it.More())
1112 //  {
1113 //    Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1114 //    TheAIS2DContext()->Erase(aShape,Standard_False);        
1115 //    it.Next();
1116 //  }
1117 //  it.Reset();
1118   while (it.More())
1119   {
1120     Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1121     TheAIS2DContext()->Display(aShape, Standard_False);        
1122     it.Next();
1123   }
1124 #ifdef OCC154
1125   TheAIS2DContext()->HighlightCurrent();
1126 #endif
1127   TheAIS2DContext()->UpdateCurrentViewer();
1128 //  TheAIS2DContext()->DisplayAll();
1129   return 0; 
1130 }
1131
1132 //==============================================================================
1133 //function : VTexture
1134 //purpose  : 
1135 //Draw arg : 
1136 //==============================================================================
1137 /*
1138 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, Standard_Character** argv )
1139 {
1140   Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1141     (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1142       (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1143         (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1144           (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1145   
1146   Handle(AIS2D_InteractiveContext) myAIS2DContext = Viewer2dTest::GetAIS2DContext();
1147   if(myAIS2DContext.IsNull()) 
1148     { 
1149       cerr << "use 'vinit' command before " << argv[0] << endl;
1150       return 0;
1151     }
1152   
1153   Handle(AIS2D_InteractiveObject) TheAisIO;
1154   Handle(AIS2D_TexturedShape) myShape;
1155   Standard_Integer myPreviousMode = 0;
1156
1157   if (!argv[1])
1158     {
1159       cout << argv[0] <<" syntax error - Type 'help vtex'"<<endl;
1160       return 0;
1161     }
1162   
1163   TCollection_AsciiString name = argv[1];
1164   Viewer2dTest::CurrentView()->SetSurfaceDetail(V2d_TEX_ALL);
1165   
1166   if (GetMapOfAIS2D().IsBound2(name)) 
1167     TheAisIO = GetMapOfAIS2D().Find2(name);
1168   else
1169     {
1170       cout <<"shape "<<name<<" doesn\'t exist"<<endl;
1171       return 0;
1172     }
1173   
1174   if (TheAisIO->IsKind(STANDARD_TYPE(AIS2D_TexturedShape)) && !TheAisIO.IsNull())
1175     {
1176       myShape = Handle(AIS2D_TexturedShape)::DownCast(TheAisIO);
1177       myPreviousMode = myShape->DisplayMode() ;
1178     }
1179   else
1180     {
1181       myAIS2DContext->Erase(TheAisIO,Standard_False);
1182       myShape = new AIS2D_TexturedShape (DBRep::Get(argv[1]));
1183       GetMapOfAIS2D().UnBind1(TheAisIO);
1184       GetMapOfAIS2D().UnBind2(name);
1185       GetMapOfAIS2D().Bind(myShape, name);  
1186     }
1187   switch (command)
1188     {
1189     case 1: // vtexture : we only map a texture on the shape
1190       if(argc<=1)
1191         { 
1192           cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1193           return 0;
1194         }
1195       if (argv[2])
1196         {
1197           if(strcasecmp(argv[2],"?")==0)
1198             { 
1199               TCollection_AsciiString monPath = GetEnvir2d();
1200               
1201               cout<<"\n Files in current directory : \n"<<endl;
1202               TCollection_AsciiString Cmnd ("glob -nocomplain *");
1203               di.Eval(Cmnd.ToCString());
1204               
1205               Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1206               Cmnd += monPath ;
1207               Cmnd += "/" ;
1208               Cmnd += "* " ;
1209               cout<<"Files in "<<monPath<<" : \n"<<endl;
1210               di.Eval(Cmnd.ToCString());
1211               
1212               return 0;
1213             }
1214           else
1215             myShape->SetTextureFileName(argv[2]);
1216         }
1217       else
1218         {
1219           cout <<"Texture mapping disabled \n \
1220                   To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<endl;
1221
1222           myAIS2DContext->SetDisplayMode(myShape,1,Standard_False);
1223           if (myPreviousMode == 3 )
1224             myAIS2DContext->RecomputePrsOnly(myShape);
1225           myAIS2DContext->Display(myShape, Standard_True);
1226           return 0;
1227         }
1228       break;
1229       
1230     case 2: // vtexscale : we change the scaling factor of the texture
1231       
1232       if(argc<2) 
1233         { 
1234           cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1235           return 0;
1236         }
1237       
1238       myShape->SetTextureScale (( argv[2] ? Standard_True    : Standard_False ),
1239                                 ( argv[2] ? atof(argv[2])    : 1.0 ),
1240                                 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1241       break;
1242       
1243     case 3: // vtexorigin : we change the origin of the texture on the shape
1244       if(argc<2) 
1245         { 
1246           cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1247           return 0;
1248         }
1249       myShape->SetTextureOrigin (( argv[2] ? Standard_True    : Standard_False ),
1250                                  ( argv[2] ? atof(argv[2])    : 0.0 ),
1251                                  ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1252       break;
1253       
1254     case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1255       if(argc<2)
1256         { 
1257           cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1258           return 0;
1259         }
1260       if (argv[2])
1261         {
1262           cout <<"Texture repeat enabled"<<endl;
1263           myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1264         }
1265       else
1266         {
1267           cout <<"Texture repeat disabled"<<endl;
1268           myShape->SetTextureRepeat(Standard_False);
1269         }
1270       break;
1271       
1272     case 5: // vtexdefault : default texture mapping
1273       // ScaleU = ScaleV = 100.0
1274       // URepeat = VRepeat = 1.0
1275       // Uorigin = VOrigin = 0.0
1276       
1277       if(argc<2)
1278         { 
1279           cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1280           return 0;
1281         }
1282       myShape->SetTextureRepeat(Standard_False);
1283       myShape->SetTextureOrigin(Standard_False);
1284       myShape->SetTextureScale (Standard_False);
1285       break;
1286     }
1287
1288   if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1289     myAIS2DContext->RecomputePrsOnly(myShape);
1290   else 
1291     {
1292       myAIS2DContext->SetDisplayMode(myShape,3,Standard_False);
1293       myAIS2DContext->Display(myShape, Standard_True);
1294       myAIS2DContext->Update(myShape,Standard_True);
1295     } 
1296   return 1;
1297 }
1298 */
1299
1300 #if 0
1301 //==============================================================================
1302 //function : V2dShading
1303 //purpose  : Sharpen or roughten the quality of the shading
1304 //Draw arg : vshading ShapeName 0.1->0.00001  1 deg-> 30 deg
1305 //==============================================================================
1306 static int V2dShading (Draw_Interpretor& ,Standard_Integer argc, const char** argv)
1307 {
1308   Standard_Boolean HaveToSet;
1309 //  Standard_Real    myDevAngle;
1310   Standard_Real    myDevCoef;
1311   Handle(AIS2D_InteractiveObject) TheAisIO;
1312   
1313   // Verifications
1314   if (!strcasecmp(argv[0],"vsetshading")) HaveToSet = Standard_True;
1315   else HaveToSet = Standard_False;
1316   TheAIS2DContext()->CloseLocalContext();
1317
1318   if (argc < 3)
1319   {
1320     myDevCoef = 0.0008;
1321   }
1322   else
1323   {
1324     myDevCoef = atof(argv[2]);
1325   }
1326
1327   TCollection_AsciiString name = argv[1];
1328   if (GetMapOfAIS2D().IsBound2(name)) TheAisIO = GetMapOfAIS2D().Find2(name);
1329   else
1330   { 
1331     TheAisIO = GetAIS2DShapeFromName(name.ToCString());
1332   }
1333   
1334   if (HaveToSet)
1335   {
1336 //    TheAIS2DContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
1337   }
1338   else
1339   {
1340 //    TheAIS2DContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
1341   }
1342   
1343   TheAIS2DContext()->Redisplay(TheAisIO);
1344   return 0;
1345 }
1346 #endif
1347
1348 //=======================================================================
1349 //function : VEraseType
1350 //purpose  : 
1351 //=======================================================================
1352 /*static int VEraseType (Draw_Interpretor& , Standard_Integer argc, const char** argv) 
1353 {
1354   if (argc!=2) return 1;
1355
1356   AIS2D_KindOfInteractive TheType;
1357   Standard_Integer TheSign(-1);
1358   GetTypeAndSignfromString2d(argv[1],TheType,TheSign);
1359   
1360   AIS2D_ListOfInteractive LIO;
1361
1362   // en attendant l'amelioration ais pour les dimensions...
1363   //
1364   Standard_Integer dimension_status(-1);
1365   if(TheType==AIS2D_KOI_Relation){
1366     dimension_status = TheSign ==1 ? 1 : 0;
1367     TheSign=-1;
1368   }
1369   
1370   TheAIS2DContext()->DisplayedObjects(TheType,TheSign,LIO);
1371   Handle(AIS2D_InteractiveObject) curio;
1372   for(AIS2D_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
1373     curio  = it.Value();
1374     
1375     if(dimension_status == -1)
1376       TheAIS2DContext()->Erase(curio,Standard_False);
1377     else {
1378       AIS2D_KindOfDimension KOD = (*((Handle(AIS2D_Relation)*)&curio))->KindOfDimension();
1379       if ((dimension_status==0 && KOD == AIS2D_KOD_NONE)||
1380           (dimension_status==1 && KOD != AIS2D_KOD_NONE))
1381         TheAIS2DContext()->Erase(curio,Standard_False);
1382     }
1383   }
1384   TheAIS2DContext()->UpdateCurrentViewer();
1385   return 0;
1386 }*/
1387
1388 //=======================================================================
1389 //function : V2dDisplayType
1390 //purpose  : 
1391 //=======================================================================
1392 /*static int V2dDisplayType (Draw_Interpretor& , Standard_Integer argc, const char** argv) 
1393 {
1394   if (argc!=2) return 1;
1395
1396   AIS2D_KindOfInteractive TheType;
1397   Standard_Integer TheSign(-1);
1398   GetTypeAndSignfromString2d(argv[1],TheType,TheSign);
1399
1400   // en attendant l'amelioration ais pour les dimensions...
1401   //
1402   Standard_Integer dimension_status(-1);
1403   if(TheType==AIS2D_KOI_Relation){
1404     dimension_status = TheSign ==1 ? 1 : 0;
1405     TheSign=-1;
1406   }
1407   
1408   AIS2D_ListOfInteractive LIO;
1409   TheAIS2DContext()->ObjectsInside(LIO,TheType,TheSign);
1410   Handle(AIS2D_InteractiveObject) curio;
1411   for(AIS2D_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
1412     curio  = it.Value();
1413     if(dimension_status == -1)
1414       TheAIS2DContext()->Display(curio,Standard_False);
1415     else {
1416       AIS2D_KindOfDimension KOD = (*((Handle(AIS2D_Relation)*)&curio))->KindOfDimension();
1417       if ((dimension_status==0 && KOD == AIS2D_KOD_NONE)||
1418           (dimension_status==1 && KOD != AIS2D_KOD_NONE))
1419         TheAIS2DContext()->Display(curio,Standard_False);
1420     }
1421
1422   }
1423   
1424   TheAIS2DContext()->UpdateCurrentViewer();
1425   return 0;
1426 }*/
1427
1428
1429 //Additional commands
1430
1431  //=======================================================================
1432 //function : GetMaterialFromName2d
1433 //purpose  : get the Graphic3d_NameOfMaterial from a string
1434 //=======================================================================
1435 static Aspect_TypeOfLine GetLineTypeFromName2d (const char *name) 
1436
1437
1438   Aspect_TypeOfLine aLT = Aspect_TOL_SOLID;
1439   if      ( !strcasecmp(name,"DASH" ) )          aLT = Aspect_TOL_DASH;
1440   else if ( !strcasecmp(name,"DOT" ) )           aLT = Aspect_TOL_DOT;
1441   else if ( !strcasecmp(name,"DOTDASH" ) )       aLT = Aspect_TOL_DOTDASH;
1442   return aLT;
1443 }
1444
1445
1446 //==============================================================================
1447 //function : V2dTypeofLine
1448 //purpose  : change the line type of a selected or named or displayed shape 
1449 //Draw arg : v2dsetlinetype [name] type 
1450 //==============================================================================
1451
1452 static int V2dSetUnsetTypeOfLine (Handle(AIS2D_InteractiveObject) theShape,
1453                                   Standard_Boolean HaveToSet,
1454                                   Aspect_TypeOfLine theType = Aspect_TOL_SOLID)
1455 {
1456   theShape->SetContext(TheAIS2DContext());
1457
1458   Handle(Graphic2d_Primitive) aPrim;
1459   Handle(Prs2d_AspectRoot)    anAspect;
1460   //get all primitives
1461   Standard_Integer i = 1, n = theShape->Length();
1462   for (; i <= n; i++)
1463   {
1464     aPrim = theShape->Primitive(i);
1465     if (theShape->HasAspect(aPrim))
1466     {
1467       anAspect = theShape->GetAspect(aPrim);
1468       if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
1469       else anAspect = NULL;
1470     }
1471   }
1472
1473   if (HaveToSet)
1474   {
1475     if (anAspect.IsNull())
1476     {
1477       theShape->SetAspect
1478         (new Prs2d_AspectLine(Quantity_NOC_YELLOW, theType, Aspect_WOL_THIN,
1479                               Quantity_NOC_YELLOW, Graphic2d_TOPF_FILLED));
1480     }
1481     else
1482     {
1483       Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
1484       anAspectLine->SetTypeOfFill(Graphic2d_TOPF_FILLED);
1485       anAspectLine->SetType( theType );
1486       theShape->SetAspect(anAspect);
1487     }
1488   }
1489   else // unset type line
1490   {
1491     Handle(Prs2d_AspectLine) anAspectLine;
1492     if ( !anAspect.IsNull() )
1493       anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
1494     else
1495       anAspectLine = new Prs2d_AspectLine();
1496
1497     anAspectLine->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
1498     anAspectLine->SetType(Aspect_TOL_SOLID);
1499     theShape->SetAspect( anAspectLine );
1500   }
1501
1502   return 0;
1503 }
1504
1505 static int V2dTypeOfLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1506 {
1507   Standard_Boolean ThereIsArgument = Standard_False;
1508   Standard_Boolean HaveToSet = Standard_False;
1509
1510   if (strcasecmp(argv[0],"v2dsetlinetype") == 0) HaveToSet = Standard_True;
1511
1512   Aspect_TypeOfLine aType = Aspect_TOL_SOLID;
1513   //Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1514   if (HaveToSet)
1515   {
1516     if (argc < 2 || argc > 3)
1517     {
1518       cout << "Usage: v2dsetlinetype [name] type" << endl;
1519       return 1;
1520     }
1521     if (argc == 3)
1522     {
1523       ThereIsArgument = Standard_True;
1524       aType = GetLineTypeFromName2d(argv[2]);
1525     }
1526     else
1527     {
1528       aType = GetLineTypeFromName2d(argv[1]);
1529     }
1530   }
1531   else
1532   {
1533     if (argc > 2)
1534     {
1535       cout << "Usage: v2dunsetlinetype [name]" << endl;
1536       return 1;
1537     }
1538     if (argc == 2) ThereIsArgument = Standard_True;
1539   }
1540   
1541   if (Viewer2dTest::CurrentView().IsNull()) return -1;
1542   TheAIS2DContext()->CloseLocalContext();
1543
1544   if (ThereIsArgument)
1545   {
1546     TCollection_AsciiString name = argv[1];
1547
1548     if (GetMapOfAIS2D().IsBound2(name))
1549     {
1550       Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1551       V2dSetUnsetTypeOfLine(aShape, HaveToSet, aType);
1552     }
1553   }
1554   else
1555   {
1556     Standard_Boolean hasCurrent = Standard_False;
1557     Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1558     for (; it.More() && !hasCurrent; it.Next())
1559     {
1560       if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
1561     }
1562     for (it.Reset(); it.More(); it.Next())
1563     {
1564       Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1565       if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
1566       {
1567         V2dSetUnsetTypeOfLine(aShape, HaveToSet, aType);
1568       }
1569     }
1570   }
1571   return 0;
1572 }
1573
1574
1575 static int drawPoint (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1576 {
1577   if( argc < 1 ) {
1578     cout << argv[0] << " Syntaxe error" << endl;
1579     return 1;
1580   }
1581   
1582   if (Viewer2dTest::CurrentView().IsNull()) { 
1583     cout << "2D AIS Viewer Initialization ..." << endl;
1584     Viewer2dTest::ViewerInit(); 
1585     cout << "Done" << endl;
1586   }
1587   
1588   Standard_Real x = 24., y = 24.;
1589   if( argc >= 2 )
1590     x = atof( argv[1] );
1591   if( argc >= 3 )
1592     y = atof( argv[2] );
1593
1594   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1595   Handle_Prs2d_Point origin = new Prs2d_Point(aIO, gp_Pnt2d( x, y ), 
1596                                               Aspect_TypeOfMarker(argc >= 4 ? atoi(argv[3]) : Aspect_TOM_PLUS), 2, 2, 0);
1597   TheAIS2DContext()->Display(aIO, Standard_True);
1598   return 0;
1599 }
1600 static int drawAxis (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1601 {
1602   if( argc < 1 ) {
1603     cout << argv[0] << " Syntaxe error" << endl;
1604     return 1;
1605   }
1606   
1607   if (Viewer2dTest::CurrentView().IsNull()) { 
1608     cout << "2D AIS Viewer Initialization ..." << endl;
1609     Viewer2dTest::ViewerInit(); 
1610     cout << "Done" << endl;
1611   }
1612   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1613   
1614   Standard_Real loc_x = 24., loc_y = 84.;
1615   if( argc >= 2 )
1616     loc_x = atof( argv[1] );
1617   if( argc >= 3 )
1618     loc_y = atof( argv[2] );
1619   gp_Pnt2d location(loc_x, loc_y);
1620   
1621   Standard_Real dir_x = 0., dir_y = 1.;
1622   if( argc >= 4 )
1623     dir_x = atof( argv[3] );
1624   if( argc >= 5 )
1625     dir_y = atof( argv[4] );
1626   gp_Dir2d direction(dir_x, dir_y);
1627   
1628   gp_Dir2d refdirection(0.0, 1.0);
1629   gp_Ax22d axis(location, direction, refdirection);
1630   Handle_Prs2d_Axis axis2 = new Prs2d_Axis(aIO, axis, 48, 24.0, 24.0, Prs2d_TOA_OPENED, 10.0); 
1631   TheAIS2DContext()->Display(aIO, Standard_True);
1632   return 0;
1633 }
1634
1635 static int drawLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1636 {
1637   if( argc < 1 ) {
1638     cout << argv[0] << " Syntaxe error" << endl;
1639     return 1;
1640   }
1641   
1642   if (Viewer2dTest::CurrentView().IsNull()) { 
1643     cout << "2D AIS Viewer Initialization ..." << endl;
1644     Viewer2dTest::ViewerInit(); 
1645     cout << "Done" << endl;
1646   }
1647   Standard_Real x1 = -11., y1 = -250., d1 = 100., d2 = 200.;
1648    
1649   if( argc >= 2 )
1650     x1 = atof( argv[1] );
1651   if( argc >= 3 )
1652     y1 = atof( argv[2] );
1653   if( argc >= 4 )
1654     d1 = atof( argv[3] );
1655   if( argc == 5 )
1656     d2 = atof( argv[4] );
1657
1658   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1659   gp_Pnt2d FirstPt(x1, y1);
1660   gp_Dir2d direction(d1, d2);
1661   Handle_Geom2d_Line line = new Geom2d_Line(FirstPt, direction);
1662   Handle(GGraphic2d_Curve) grCurve = new GGraphic2d_Curve(aIO, line);
1663
1664   TheAIS2DContext()->Display(aIO, Standard_True );
1665
1666   return 0;
1667 }
1668 static int drawSegment (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1669 {
1670   if( argc < 1 ) {
1671     cout << argv[0] << " Syntaxe error" << endl;
1672     return 1;
1673   }
1674   
1675   if (Viewer2dTest::CurrentView().IsNull()) { 
1676     cout << "2D AIS Viewer Initialization ..." << endl;
1677     Viewer2dTest::ViewerInit(); 
1678     cout << "Done" << endl;
1679   }
1680
1681   Standard_Real x1 = 0., y1 = 20., x2 = 100., y2 = 200.;
1682    
1683   if( argc >= 2 )
1684     x1 = atof( argv[1] );
1685   if( argc >= 3 )
1686     y1 = atof( argv[2] );
1687   if( argc >= 4 )
1688     x2 = atof( argv[3] );
1689   if( argc == 5 )
1690     y2 = atof( argv[4] );
1691
1692   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1693   Handle(Graphic2d_Segment) theSegment = new Graphic2d_Segment( aIO, x1, y1, x2, y2 );
1694   TheAIS2DContext()->Display(aIO, Standard_True);
1695   return 0;
1696 }
1697
1698 static int drawArrowLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1699 {
1700   if( argc < 1 ) {
1701     cout << argv[0] << " Syntaxe error" << endl;
1702     return 1;
1703   }
1704   
1705   if (Viewer2dTest::CurrentView().IsNull()) { 
1706     cout << "2D AIS Viewer Initialization ..." << endl;
1707     Viewer2dTest::ViewerInit(); 
1708     cout << "Done" << endl;
1709   }
1710   
1711   Standard_Real x1 = 24, y1 = 24, x2 = 420, y2 = 420;
1712    
1713   if( argc >= 3 )
1714     x1 = atof( argv[2] );
1715   if( argc >= 4 )
1716     y1 = atof( argv[3] );
1717   if( argc >= 5 )
1718     x2 = atof( argv[4] );
1719   if( argc == 6 )
1720     y2 = atof( argv[5] );
1721
1722
1723   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1724   gp_Pnt2d FirstPt(x1, y1);
1725   gp_Pnt2d LastPt(x2, y2);
1726   double arrow_angle = 24;
1727   double arrow_length = FirstPt.Distance(LastPt)/10.;
1728   int arrow_type = 1;
1729   
1730   gp_Ax2d ax;
1731   ax = gp_Ax2d(FirstPt, gp_Dir2d(gp_Vec2d(LastPt, FirstPt)));
1732   
1733   Handle(Prs2d_Arrow) h_arrow;
1734   h_arrow = new Prs2d_Arrow(aIO, ax, arrow_angle, arrow_length, Prs2d_TypeOfArrow(arrow_type));
1735   
1736   GCE2d_MakeSegment segment(FirstPt, LastPt);
1737   Handle(Geom2d_TrimmedCurve) trCur = segment.Value();
1738   Handle(GGraphic2d_Curve) grCurve = new GGraphic2d_Curve(aIO, trCur);
1739
1740   GetMapOfAIS2D().Bind(aIO, argv[1]);
1741   TheAIS2DContext()->Display(aIO, Standard_True );
1742   TheAIS2DContext()->UpdateCurrentViewer();
1743   return 0;
1744 }
1745
1746
1747 static int draw2DText (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1748 {
1749  
1750   if( argc < 2 ) {
1751     cout << argv[0] << " Syntaxe error" << endl;
1752     return 1;
1753   }
1754   
1755   if (Viewer2dTest::CurrentView().IsNull())  { 
1756     cout << "2D AIS Viewer Initialization ..." << endl;
1757     Viewer2dTest::ViewerInit(); 
1758     cout << "Done" << endl;
1759   }
1760   
1761   Standard_Real x1 = 24, y1 = 24;
1762   Quantity_PlaneAngle anAngle = 0.0;
1763   Quantity_Factor     aScale = 1.0;
1764   Standard_Boolean isUnderline = Standard_False;
1765    
1766   if( argc >= 4 )
1767     x1 = atof( argv[3] );
1768   if( argc >= 5 )
1769     y1 = atof( argv[4] );
1770   if( argc >= 6 )
1771     anAngle = atof( argv[5] );
1772   if( argc >= 7 )
1773     aScale = atof( argv[6] );
1774   if( argc >= 8 )
1775     isUnderline = atoi( argv[7] );
1776   
1777     
1778
1779   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1780   TCollection_ExtendedString aString(argv[2]);
1781   Handle(Graphic2d_Text) aText = new Graphic2d_Text(aIO,aString,x1,y1, anAngle, Aspect_TOT_SOLID, aScale);
1782   aText->SetUnderline(isUnderline);
1783   
1784   Handle(Prs2d_AspectText) aspect = new Prs2d_AspectText();
1785   aspect->SetFont(Aspect_TOF_HELVETICA);
1786   aspect->SetColor(Quantity_NOC_WHITE);
1787   aIO->SetAspect(aspect);
1788   
1789   Standard_Integer color_index = 2;
1790   aText->SetColorIndex(color_index);
1791    
1792   
1793   GetMapOfAIS2D().Bind(aIO, argv[1]);
1794   TheAIS2DContext()->Display(aIO, Standard_True );
1795   TheAIS2DContext()->UpdateCurrentViewer();
1796   return 0;
1797 }
1798
1799 static int drawToleanceFrame( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1800 {
1801   if( argc < 1 )
1802   {
1803     cout << argv[0] << " Syntaxe error" << endl;
1804     return 1;
1805   }
1806   
1807   if (Viewer2dTest::CurrentView().IsNull())
1808   { 
1809     cout << "2D AIS Viewer Initialization ..." << endl;
1810     Viewer2dTest::ViewerInit(); 
1811     cout << "Done" << endl;
1812   }
1813
1814   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1815   Standard_Real aX = 24, aY = 48;
1816   Standard_Real height = 24;
1817
1818   if( argc >= 2 )
1819     height = atof( argv[1] );
1820   
1821   if( argc >= 3 )
1822     aX = atof( argv[2] );
1823   if( argc >= 4 )
1824     aX = atof( argv[3] );
1825
1826   gp_Pnt2d location(aX, aY);
1827   
1828   int tol_type = 10;
1829   if( argc >= 5 )
1830    tol_type = atoi( argv[4] );
1831
1832   double angle = 0.0;
1833   double text_scale = 10.0;
1834   
1835   Handle(Prs2d_ToleranceFrame) symbol;
1836   symbol = new Prs2d_ToleranceFrame( aIO, location.X(), location.Y(), height,
1837                                     Prs2d_TypeOfTolerance(tol_type), "B", "-0.01", " A", angle, text_scale);
1838   
1839   TheAIS2DContext()->Display(aIO, Standard_True );
1840   TheAIS2DContext()->UpdateCurrentViewer();
1841   return 0;
1842 }
1843
1844 static int drawArc( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1845 {
1846   if( argc < 1 )
1847   {
1848     cout << argv[0] << " Syntaxe error" << endl;
1849     return 1;
1850   }
1851   
1852   if (Viewer2dTest::CurrentView().IsNull())
1853   { 
1854     cout << "2D AIS Viewer Initialization ..." << endl;
1855     Viewer2dTest::ViewerInit(); 
1856     cout << "Done" << endl;
1857   }
1858
1859   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1860         
1861   Standard_Real x1 = 0., y1 = 0., x2 = 24., y2 = 24., x3 = 12., y3 = 48.;
1862    
1863   if( argc >= 2 )
1864     x1 = atof( argv[1] );
1865   if( argc >= 3 )
1866     y1 = atof( argv[2] );
1867   if( argc >= 4 )
1868     x2 = atof( argv[3] );
1869   if( argc >= 5 )
1870     y2 = atof( argv[4] );
1871   if( argc >= 6)
1872     x3= atof( argv[5] );
1873   if( argc >= 7 )
1874     y3 = atof( argv[6] );
1875
1876   gp_Pnt2d point1(x1, y1);
1877   gp_Pnt2d point2(x2, y2);
1878   gp_Pnt2d point3(x3, y3);
1879   
1880   GCE2d_MakeArcOfCircle arc(point1, point2, point3);
1881   Handle_Geom2d_TrimmedCurve trCur = arc.Value();
1882   
1883   Handle_GGraphic2d_Curve grCurve = new GGraphic2d_Curve(aIO, trCur);
1884   TheAIS2DContext()->Display(aIO, Standard_True);
1885   return 0;
1886 }
1887
1888 static int drawFinishSymbol( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1889 {
1890   if( argc < 1 )
1891   {
1892     cout << argv[0] << " Syntaxe error" << endl;
1893     return 1;
1894   }
1895   
1896   if (Viewer2dTest::CurrentView().IsNull())
1897   { 
1898     cout << "2D AIS Viewer Initialization ..." << endl;
1899     Viewer2dTest::ViewerInit(); 
1900     cout << "Done" << endl;
1901   }
1902
1903   gp_Pnt2d location(48, 84);
1904   double length = 10;
1905   double angle = 0;
1906
1907   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1908   
1909   Handle(Graphic2d_Polyline) symbol;
1910   Handle(Graphic2d_Text) text;
1911   
1912   gp_Pnt2d startPoint(location.X() + length/4, location.Y() + length/2);
1913   gp_Pnt2d leftTopPoint(location.X() - length/4, location.Y() + length/2);
1914   gp_Pnt2d btCenPoint(location.X(), location.Y());
1915   gp_Pnt2d rightTopPoint(location.X() + length/2, location.Y() + length);
1916                                 
1917   gp_Trsf2d trsf;
1918   trsf.SetRotation(location, angle*M_PI/180);
1919   
1920   startPoint.Transform(trsf);
1921   leftTopPoint.Transform(trsf);
1922   btCenPoint.Transform(trsf);
1923   rightTopPoint.Transform(trsf);
1924   
1925   Graphic2d_Array1OfVertex vertex_arr(1, 4);
1926   vertex_arr.SetValue( 1, Graphic2d_Vertex(startPoint.X(), startPoint.Y()));
1927   vertex_arr.SetValue( 2, Graphic2d_Vertex(leftTopPoint.X(), leftTopPoint.Y()));
1928   vertex_arr.SetValue( 3, Graphic2d_Vertex(btCenPoint.X(), btCenPoint.Y()));
1929   vertex_arr.SetValue( 4, Graphic2d_Vertex(rightTopPoint.X(), rightTopPoint.Y()));
1930   
1931   symbol = new Graphic2d_Polyline(aIO, vertex_arr);
1932   TheAIS2DContext()->Display(aIO, Standard_True);
1933   return 0;
1934 }
1935 static int drawBezierCurve( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1936 {
1937   if( argc < 1 )
1938   {
1939     cout << argv[0] << " Syntaxe error" << endl;
1940     return 1;
1941   }
1942   
1943   if (Viewer2dTest::CurrentView().IsNull())
1944   { 
1945     cout << "2D AIS Viewer Initialization ..." << endl;
1946     Viewer2dTest::ViewerInit(); 
1947     cout << "Done" << endl;
1948   }
1949
1950   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1951   
1952   TColgp_Array1OfPnt2d ptarr(1, 5);
1953   gp_Pnt2d p1(24, 24);  
1954   gp_Pnt2d p2(-48, 42);  
1955   gp_Pnt2d p3(80, 82);  
1956   gp_Pnt2d p4(240, -24);  
1957   gp_Pnt2d p5(-24, -84);  
1958   
1959   ptarr.SetValue( 1, p1);
1960   ptarr.SetValue( 2, p2);
1961   ptarr.SetValue( 3, p3);
1962   ptarr.SetValue( 4, p4);
1963   ptarr.SetValue( 5, p5);
1964   
1965   Handle(Geom2d_BezierCurve) bezierCurve = 
1966     new Geom2d_BezierCurve(ptarr);
1967   Handle_GGraphic2d_Curve grCurve = new GGraphic2d_Curve(aIO, bezierCurve);
1968   TheAIS2DContext()->Display(aIO, Standard_True);
1969   return 0;
1970 }
1971
1972
1973 static int draw2DCurve( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1974 {
1975   if( argc < 1 )
1976   {
1977     cout << argv[0] << " Syntaxe error" << endl;
1978     return 1;
1979   }
1980   
1981   if (Viewer2dTest::CurrentView().IsNull())
1982   { 
1983     cout << "2D AIS Viewer Initialization ..." << endl;
1984     Viewer2dTest::ViewerInit(); 
1985     cout << "Done" << endl;
1986   }
1987
1988   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1989   Handle(Geom2d_Curve) aCurve = DrawTrSurf::GetCurve2d(argv[2]);
1990   Handle(GGraphic2d_Curve) grCurve = new GGraphic2d_Curve(aIO, aCurve);
1991   
1992   GetMapOfAIS2D().Bind(aIO, argv[1]);                                                     
1993   TheAIS2DContext()->Display(aIO, Standard_True);
1994   TheAIS2DContext()->UpdateCurrentViewer();
1995   return 0;
1996 }
1997
1998 static int v2dtransform( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1999 {
2000   if( argc < 7 )
2001   {
2002     cout << argv[0] << " Syntaxe error" << endl;
2003     return 1;
2004   }
2005   
2006   if (Viewer2dTest::CurrentView().IsNull())
2007   { 
2008     cout << "2D AIS Viewer Initialization ..." << endl;
2009     Viewer2dTest::ViewerInit(); 
2010     cout << "Done" << endl;
2011   }
2012   
2013   if(!GetMapOfAIS2D().IsBound2(argv[1])) {
2014     cout<<"Object not found"<<endl;
2015     return 0;
2016   }
2017   
2018   Handle(AIS2D_InteractiveObject) aIO = GetMapOfAIS2D().Find2(argv[1]);
2019   gp_Trsf2d aTrans, aT1,aT2;
2020   gp_Pnt2d aP(atof(argv[2]),atof(argv[3]));
2021   Standard_Real anAngle = atof(argv[4]);
2022   gp_Pnt2d aP2(atof(argv[5]),atof(argv[6]));
2023   aT1.SetRotation(aP,anAngle);
2024   aT2.SetTranslation(aP2.XY());
2025   aTrans = aT1*aT2;
2026   
2027   aIO->SetTransform(gp_GTrsf2d(aTrans));
2028   TheAIS2DContext()->UpdateCurrentViewer();
2029   return 0;  
2030 }
2031
2032 static int v2dsetstyle( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2033 {
2034   if( argc < 3 )
2035   {
2036     cout << argv[0] << " Syntaxe error" << endl;
2037     return 1;
2038   }
2039   
2040   if (Viewer2dTest::CurrentView().IsNull())
2041   { 
2042     cout << "2D AIS Viewer Initialization ..." << endl;
2043     Viewer2dTest::ViewerInit(); 
2044     cout << "Done" << endl;
2045   }
2046   
2047   if(!GetMapOfAIS2D().IsBound2(argv[1])) {
2048     cout<<"Object not found"<<endl;
2049     return 0;
2050   }
2051   
2052   Handle(AIS2D_InteractiveObject) aIO = GetMapOfAIS2D().Find2(argv[1]);
2053   
2054   Handle(Graphic2d_Primitive) grPrim = aIO->Primitive(1);
2055   if(aIO->HasAspect(grPrim)) {
2056     Handle(Prs2d_AspectRoot) aspRoot = aIO->GetAspect(grPrim);
2057     if(!aspRoot.IsNull() && aspRoot->GetAspectName() == Prs2d_AN_LINE) {
2058       Handle(Prs2d_AspectLine) aspLine = Handle(Prs2d_AspectLine)::DownCast(aspRoot);
2059       aspLine->SetType(Aspect_TypeOfLine(atoi(argv[2])));
2060     }   
2061   }
2062   
2063   TheAIS2DContext()->UpdateCurrentViewer();
2064   return 0;  
2065 }
2066
2067
2068
2069 static int v2dtest1 (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2070 {
2071   
2072   if (Viewer2dTest::CurrentView().IsNull())
2073   { 
2074     cout << "2D AIS Viewer Initialization ..." << endl;
2075     Viewer2dTest::ViewerInit(); 
2076     cout << "Done" << endl;
2077   }
2078   
2079   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2080   
2081   gp_Pnt2d firstPoint ( 911.84, 851.86);
2082   gp_Pnt2d newPoint (947.78, 847.375);
2083   
2084   Handle(Prs2d_Length) theLength;
2085   theLength = new Prs2d_Length( aIO, firstPoint, newPoint,"     -0.2", 3, 2, 
2086                                Prs2d_TypeOfDist(Prs2d_TOD_AUTOMATIC), 
2087                                20, 5, Prs2d_TypeOfArrow(Prs2d_TOA_FILLED), 
2088                                Prs2d_ArrowSide(Prs2d_AS_BOTHAR), Standard_True);
2089   
2090   TheAIS2DContext()->Display(aIO, Standard_True );
2091   
2092   
2093   aIO = new AIS2D_InteractiveObject();
2094   gp_Pnt2d pt1 ( 209.30, 1405.29 );
2095   gp_Pnt2d pt2 ( 409.3, 1396.79);
2096   gp_Pnt2d pt3 (209.3, 1205.278);
2097
2098   
2099   Handle(Prs2d_Angle) theAngle;
2100   theAngle = new Prs2d_Angle( aIO, pt1, pt2, pt3,100,"  ", 3, 20, 6, Prs2d_TypeOfArrow(Prs2d_TOA_FILLED),
2101                              Prs2d_ArrowSide(Prs2d_AS_BOTHAR), Standard_False);
2102   
2103   TheAIS2DContext()->Display(aIO, Standard_True );
2104   
2105   TheAIS2DContext()->UpdateCurrentViewer();
2106   return 0;  
2107 }
2108
2109 static int v2dtable (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2110 {
2111  
2112   if( argc < 6 ) {
2113     cout << argv[0] << " Syntaxe error" << endl;
2114     return 1;
2115   }
2116   
2117   if (Viewer2dTest::CurrentView().IsNull())  { 
2118     cout << "2D AIS Viewer Initialization ..." << endl;
2119     Viewer2dTest::ViewerInit(); 
2120     cout << "Done" << endl;
2121   }
2122   
2123   Standard_Real x1 = 24, y1 = 24;
2124   Standard_Integer numberOfColumn = 1, numberOfRows = 1;
2125   Quantity_PlaneAngle anAngle = 0.0;
2126   Quantity_Factor     aScale = 1.0;
2127    
2128   if( argc >= 3 )
2129     x1 = atof( argv[2] );
2130   if( argc >= 4 )
2131     y1 = atof( argv[3] );
2132   if( argc >= 5 )
2133     numberOfColumn = atoi( argv[4] );
2134   if( argc >= 6 )
2135     numberOfRows = atoi( argv[5] );
2136   
2137   Handle(AIS2D_InteractiveObject) aisObj = new AIS2D_InteractiveObject();
2138
2139   Handle(GGraphic2d_SetOfCurves) setOfCurve = new GGraphic2d_SetOfCurves(aisObj);
2140
2141   gp_Pnt2d location(x1,y1);
2142   Standard_Real columnWidth = 100;
2143   Standard_Real rowHeight = 10;
2144   Standard_Integer i;
2145   
2146   Handle(Geom2d_Curve) trCur;
2147   
2148   for( i=0; i<=numberOfColumn; ++i) {
2149     GCE2d_MakeSegment segment(  gp_Pnt2d(location.X() + (columnWidth * i), location.Y()),
2150                                 gp_Pnt2d(location.X() + (columnWidth * i), location.Y() + (rowHeight * numberOfRows)) );
2151     
2152     trCur = segment.Value();
2153     setOfCurve->Add(trCur);
2154   }
2155
2156   for( i=0; i<=numberOfRows; ++i) {
2157     GCE2d_MakeSegment segment1( gp_Pnt2d(location.X(), location.Y() + (rowHeight * i)),
2158                                 gp_Pnt2d(location.X() + (numberOfColumn * columnWidth), location.Y() + (rowHeight * i)) );
2159     trCur = segment1.Value();
2160     setOfCurve->Add(trCur);
2161   }
2162
2163   Handle(Graphic2d_Text) text;
2164   Standard_Real locationX = (location.X() + (columnWidth / 2));
2165   Standard_Real locationY = (location.Y() + (rowHeight / 2));
2166   Handle(Prs2d_Point) point;
2167   
2168   Standard_Real text_scale = 2.0;
2169   
2170   for(Standard_Integer j=0,  k=0; j<numberOfRows; ++j) {
2171     for( i=0; i<numberOfColumn; ++i) {
2172       
2173       TCollection_ExtendedString str("TableCell");
2174       str+=i;
2175       str+=" ";
2176       str+=k;
2177       
2178       Standard_Integer str_len = str.Length();
2179       
2180       Standard_Real textLength = str_len * text_scale * 1.8;
2181       Standard_Real textHight = text_scale * 1.6;
2182
2183       text = new Graphic2d_Text(aisObj, str, locationX + (columnWidth * i) - (textLength /2 ),
2184                                 locationY + (rowHeight * j ) - (textHight / 2),
2185                                 0, Aspect_TypeOfText(Aspect_TOT_SOLID), text_scale);
2186       ++k;
2187     }
2188   }
2189   
2190   GetMapOfAIS2D().Bind(aisObj, argv[1]);
2191   TheAIS2DContext()->Display(aisObj, Standard_True );
2192   TheAIS2DContext()->UpdateCurrentViewer();
2193   return 0;
2194 }
2195
2196
2197
2198 static int drawEllipse( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2199 {
2200   if( argc < 1 )
2201   {
2202     cout << argv[0] << " Syntaxe error" << endl;
2203     return 1;
2204   }
2205   
2206   if (Viewer2dTest::CurrentView().IsNull())
2207   { 
2208     cout << "2D AIS Viewer Initialization ..." << endl;
2209     Viewer2dTest::ViewerInit(); 
2210     cout << "Done" << endl;
2211   }
2212
2213   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2214   Handle(Geom2d_Ellipse) ellipse ;
2215   gp_Ax2d axis(gp_Pnt2d(24, 42), gp_Dir2d(1, 0));
2216   ellipse = new Geom2d_Ellipse(axis, 420, 240, Standard_True);
2217   Handle_GGraphic2d_Curve grCurve = new GGraphic2d_Curve(aIO, ellipse);
2218   TheAIS2DContext()->Display(aIO, Standard_True);
2219   return 0;
2220 }
2221
2222 static int drawLengthDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2223 {
2224   if( argc < 1 )
2225   {
2226     cout << argv[0] << " Syntaxe error" << endl;
2227     return 1;
2228   }
2229   
2230
2231   int distance_type = 0; 
2232   if (argc >= 2) {
2233     distance_type = atoi(argv[1]);
2234   }
2235   
2236   if (Viewer2dTest::CurrentView().IsNull())
2237   { 
2238     cout << "2D AIS Viewer Initialization ..." << endl;
2239     Viewer2dTest::ViewerInit(); 
2240     cout << "Done" << endl;
2241   }
2242
2243   gp_Pnt2d FirstPt(0, 0);
2244   gp_Pnt2d LastPt(240, 240);
2245   
2246   double text_scale = 5;
2247   double length = 100; 
2248   double arrow_angle = 24;
2249   double arrow_length = 24;
2250   int arrow_type = 2;
2251   int arrow_side = 3;
2252   Standard_Boolean isReverse = Standard_True;
2253   
2254   double distance = FirstPt.Distance(LastPt);
2255   
2256   char str_[10];
2257   sprintf(str_, "%.2f", distance);
2258   
2259   TCollection_ExtendedString str(str_);
2260   
2261   Handle(Prs2d_Length) theLength;                       
2262   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2263   
2264   theLength = 
2265     new Prs2d_Length(aIO, FirstPt, LastPt, 
2266                      str, text_scale, length, Prs2d_TypeOfDist(distance_type), 
2267                      arrow_angle, arrow_length, Prs2d_TypeOfArrow(arrow_type), 
2268                      Prs2d_ArrowSide(arrow_side), isReverse);
2269   
2270   theLength->SetTextRelPos(.5, .5);
2271   
2272   TheAIS2DContext()->Display(aIO, Standard_True);
2273   TheAIS2DContext()->UpdateCurrentViewer();
2274   return 0;
2275 }
2276
2277 static int drawLengthDim1( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2278 {
2279   if( argc < 1 )
2280   {
2281     cout << argv[0] << " Syntaxe error" << endl;
2282     return 1;
2283   }
2284   
2285   if (Viewer2dTest::CurrentView().IsNull())
2286   { 
2287     cout << "2D AIS Viewer Initialization ..." << endl;
2288     Viewer2dTest::ViewerInit(); 
2289     cout << "Done" << endl;
2290   }
2291
2292   gp_Pnt2d FirstPt(0, 0);
2293   gp_Pnt2d LastPt(2, 2);
2294   
2295   gp_Lin2d aL1(FirstPt,gp_Dir2d(0,1));
2296   gp_Lin2d aL2(LastPt,gp_Dir2d(0,1));
2297   
2298   double text_scale = 15;
2299   double length = 0; 
2300   int distance_type = 0; 
2301   double arrow_angle = 24;
2302   double arrow_length = 24;
2303   int arrow_type = 2;
2304   int arrow_side = 3;
2305   
2306   double distance = FirstPt.Distance(LastPt);
2307   
2308   char str_[10];
2309   sprintf(str_, "%.2f", distance);
2310   
2311   TCollection_ExtendedString str(str_);
2312   
2313   Handle(Prs2d_Length) theLength;                       
2314   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2315   
2316   
2317   theLength = 
2318     new Prs2d_Length(aIO, aL1, aL2, 
2319                      str, text_scale, length);
2320 //  theLength = 
2321 //    new Prs2d_Length(aIO, aL1, aL2, 
2322 //                     str, text_scale, length, arrow_angle,arrow_length,
2323 //                     Prs2d_TypeOfDist(distance_type), 
2324 //                     Prs2d_TypeOfArrow(arrow_type), 
2325 //                     Prs2d_ArrowSide(arrow_side), Standard_False);
2326   
2327   theLength->SetTextRelPos(.5, .5);
2328   
2329   TheAIS2DContext()->Display(aIO, Standard_True);
2330   TheAIS2DContext()->UpdateCurrentViewer();
2331   return 0;
2332 }
2333
2334
2335
2336 static int drawAngleDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2337 {
2338   if( argc < 1 )
2339   {
2340     cout << argv[0] << " Syntaxe error" << endl;
2341     return 1;
2342   }
2343   Standard_Boolean isReverse = Standard_False;
2344
2345   if( argc >= 1 )
2346     isReverse = atoi(argv[1]);
2347   
2348   if (Viewer2dTest::CurrentView().IsNull())
2349   { 
2350     cout << "2D AIS Viewer Initialization ..." << endl;
2351     Viewer2dTest::ViewerInit(); 
2352     cout << "Done" << endl;
2353   }
2354
2355   gp_Pnt2d anAp1(0, 0);
2356   gp_Pnt2d anAp2(240, 240);
2357   gp_Pnt2d anAp3(0, 240);
2358   
2359   Quantity_Length aRadius = 100;
2360   TCollection_ExtendedString aText("Rad = 10%");
2361   
2362   Handle(Prs2d_Angle) theAngle;                 
2363   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2364
2365   if(isReverse) {
2366     theAngle = new Prs2d_Angle(aIO, anAp1, anAp3, anAp2, aRadius, aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_ArrowSide(2),isReverse);
2367   }
2368   else {
2369   theAngle = 
2370     new Prs2d_Angle(aIO, anAp1, anAp2, anAp3, aRadius, aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_ArrowSide(2),isReverse);
2371   }
2372   
2373   theAngle->SetTextRelPos(.5, .5);
2374   
2375   TheAIS2DContext()->Display(aIO, Standard_True);
2376   TheAIS2DContext()->UpdateCurrentViewer();
2377   return 0;
2378 }  
2379
2380 static int drawRadiusDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2381 {
2382   if( argc < 1 )
2383   {
2384     cout << argv[0] << " Syntaxe error" << endl;
2385     return 1;
2386   }
2387   Standard_Boolean isReverse = Standard_False;
2388
2389   if( argc >= 2 )
2390     isReverse = atoi(argv[1]);
2391   
2392   if (Viewer2dTest::CurrentView().IsNull())
2393   { 
2394     cout << "2D AIS Viewer Initialization ..." << endl;
2395     Viewer2dTest::ViewerInit(); 
2396     cout << "Done" << endl;
2397   }
2398
2399   gp_Pnt2d anAp1(0, 0);
2400   gp_Pnt2d anAp2(240, 240);
2401   gp_Circ2d aCirc(gp_Ax2d(anAp2,gp_Dir2d(0,1)),100.);
2402   
2403   Quantity_Length aRadius = 100;
2404   TCollection_ExtendedString aText("Rad = 10%");
2405   
2406   Handle(Prs2d_Radius) theRadius;                       
2407   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2408
2409   theRadius = new Prs2d_Radius(aIO, anAp1, aCirc,  aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_AS_BOTHAR,isReverse);
2410   theRadius->SetTextRelPos(.5, .5);
2411   
2412   TheAIS2DContext()->Display(aIO, Standard_True);
2413   TheAIS2DContext()->UpdateCurrentViewer();
2414   return 0;
2415 }  
2416
2417
2418 static int drawSymbDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2419 {
2420   if( argc < 1 )
2421   {
2422     cout << argv[0] << " Syntaxe error" << endl;
2423     return 1;
2424   }
2425   
2426   if (Viewer2dTest::CurrentView().IsNull())
2427   { 
2428     cout << "2D AIS Viewer Initialization ..." << endl;
2429     Viewer2dTest::ViewerInit(); 
2430     cout << "Done" << endl;
2431   }
2432
2433   gp_Pnt2d anAp1(0, 0);
2434   gp_Pnt2d anAp2(240, 240);
2435   gp_Circ2d aCirc(gp_Ax2d(anAp2,gp_Dir2d(0,1)),100.);
2436   
2437   Quantity_Length aRadius = 100;
2438   TCollection_ExtendedString aText("Rad = 10%");
2439   
2440   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2441   Handle(Prs2d_Circularity) symbol;
2442   
2443   Standard_Real length = 100;
2444   Standard_Real angle = 270;
2445   symbol = new Prs2d_Circularity( aIO, anAp2.X(), anAp2.Y(), length, angle);
2446
2447   
2448   TheAIS2DContext()->Display(aIO, Standard_True);
2449   
2450   aIO = new AIS2D_InteractiveObject();
2451   Handle(Prs2d_Parallelism) symbol1;
2452   symbol1 = new Prs2d_Parallelism( aIO, anAp2.X()+10, anAp2.Y()+10, length, angle); 
2453   TheAIS2DContext()->Display(aIO, Standard_True);
2454   
2455   TheAIS2DContext()->UpdateCurrentViewer();
2456   return 0;
2457 }  
2458
2459
2460 static int drawDiameter( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2461 {
2462   if( argc < 2 )
2463   {
2464     cout << argv[0] << " Syntaxe error" << endl;
2465     return 1;
2466   }
2467   
2468   if (Viewer2dTest::CurrentView().IsNull())
2469   { 
2470     cout << "2D AIS Viewer Initialization ..." << endl;
2471     Viewer2dTest::ViewerInit(); 
2472     cout << "Done" << endl;
2473   }
2474
2475   Standard_Real aRadius = 240.;
2476   aRadius = atof( argv[1] );
2477
2478   Standard_Real aX = 0., aY = 0.;
2479   
2480   if( argc >= 3 )
2481     aX = atof( argv[2] );
2482   if( argc >= 4 )
2483     aY = atof( argv[3] );
2484     
2485   gp_Pnt2d cirLoc( aX, aY );
2486
2487   Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2488   gp_Dir2d xdir(1.0,0.0);
2489   gp_Dir2d ydir(0.0,1.0);
2490   gp_Ax22d ax2d(cirLoc, xdir, ydir);
2491   
2492   
2493   gp_Pnt2d attachPt(cirLoc.X()+aRadius, cirLoc.Y());
2494   gp_Trsf2d trsf;
2495   trsf.SetRotation(cirLoc, (3.142/180)*-60);
2496   attachPt.Transform(trsf);
2497   gp_Circ2d aCircle(ax2d, aRadius);
2498   Handle(Graphic2d_Circle) theCircle = new Graphic2d_Circle( aIO, 0., 0.,aRadius);
2499   Handle(Prs2d_Diameter) theDiam =
2500     new Prs2d_Diameter(aIO, attachPt, aCircle, TCollection_ExtendedString( aRadius*2. ), 
2501                        24.0, 24.0, 24.0, Prs2d_TOA_CLOSED, Prs2d_AS_BOTHAR, Standard_False);
2502   theDiam->DrawSymbol(Standard_True); 
2503   theDiam->SetSymbolCode(233);
2504   
2505   TheAIS2DContext()->Display(aIO, Standard_True);
2506   TheAIS2DContext()->UpdateCurrentViewer();
2507   
2508   return 0;
2509 }
2510
2511 static int NbAllObjects (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2512 {
2513   if (argc > 1)  {
2514     cout << argv[0] << " Syntaxe error" << endl;
2515     return 1;
2516   }
2517
2518   if (Viewer2dTest::CurrentView().IsNull()) return 1;
2519   
2520   AIS2D_ListOfIO aListObj;
2521   TheAIS2DContext()->DisplayedObjects( aListObj );
2522   int aNb = aListObj.Extent();
2523
2524   cout << " Number all objects = " << aNb << endl;
2525   return 0;
2526 }
2527
2528
2529
2530 //==============================================================================
2531 //function : Viewer2dTest::Commands
2532 //purpose  : Add all the viewer command in the Draw_Interpretor
2533 //==============================================================================
2534 void Viewer2dTest::DisplayCommands (Draw_Interpretor& theCommands)
2535 {
2536   const char *group = "2D AIS Viewer - Display Commands";
2537
2538   theCommands.Add("v2ddisplay",
2539                   "v2ddisplay name [projection(Origin(x y z) Normal(dx dy dz) DX(dx dy dz)]",
2540                   __FILE__, V2dDisplay, group);
2541
2542   theCommands.Add("v2derase",
2543                   "v2derase [name1] ...  [name n]",
2544                   __FILE__, V2dErase, group);
2545
2546   theCommands.Add("v2ddonly",
2547                   "v2ddonly [name1] ...  [name n]",
2548                   __FILE__, V2dDonly, group);
2549
2550   theCommands.Add("v2ddisplayall",
2551                   "v2ddisplayall",
2552                   __FILE__, V2dDisplayAll, group);
2553
2554   theCommands.Add("v2deraseall",
2555                   "v2deraseall",
2556                   __FILE__, V2dEraseAll, group);
2557
2558 //  theCommands.Add("v2derasetype",
2559 //                "v2derasetype <Type> : erase all the displayed objects of one given kind (see vtypes)",
2560 //                __FILE__, V2dEraseType, group);
2561
2562 //  theCommands.Add("v2ddisplaytype",
2563 //                "v2ddisplaytype <Type> <Signature> : display all the objects of one given kind (see vtypes) which are stored the AIS2DContext",
2564 //                __FILE__, V2dDisplayType, group);
2565   
2566 /*
2567   theCommands.Add("v2ddisplaymode",
2568                   "v2ddispmode [name] mode(1,2,..) : no name -> on selected objects",
2569                   __FILE__, V2dDispMode, group);
2570
2571   theCommands.Add("v2derasemode",
2572                   "v2derasemode [name] mode(1,2,..) : no name -> on selected objects",
2573                   __FILE__, V2dDispMode, group);
2574
2575   theCommands.Add("v2dsetdispmode",
2576                   "v2dsetdispmode [name] mode(1,2,..) : no name -> on selected objects",
2577                   __FILE__, V2dDispMode, group);
2578
2579   theCommands.Add("v2dunsetdispmode",
2580                   "v2dunsetdispmode [name] mode(1,2,..) : no name -> on selected objects",
2581                   __FILE__, V2dDispMode, group);
2582 */
2583   theCommands.Add("v2dsetcolor",
2584                   "v2dsetcolor [name of shape] ColorName",
2585                   __FILE__, V2dColor, group);
2586
2587   theCommands.Add("v2dunsetcolor",
2588                   "v2dunsetcolor [name of shape]",
2589                   __FILE__, V2dColor, group);
2590
2591   theCommands.Add("v2dsetbgcolor",
2592                   "v2dsetbgcolor colorname       : Change background color",
2593                   __FILE__, V2dSetBGColor, group);
2594
2595  /*
2596  theCommands.Add("v2dsettransparency",
2597                   "v2dsettransparency [name of shape] TransparencyCoef(0 -> 1)",
2598                   __FILE__, V2dTransparency, group);
2599
2600   theCommands.Add("v2dunsettransparency",
2601                   "v2dunsettransparency [name of shape]",
2602                   __FILE__, V2dTransparency, group);
2603
2604   theCommands.Add("v2dsetmaterial",
2605                   "v2dsetmaterial [name of shape] MaterialName",
2606                   __FILE__, V2dMaterial, group);
2607
2608   theCommands.Add("v2dunsetmaterial",
2609                   "v2dunsetmaterial [name of shape]",
2610                   __FILE__, V2dMaterial, group);
2611 */
2612   theCommands.Add("v2dsetwidth",
2613                   "v2dsetwidth [name_of_shape] width(THIN, MEDIUM, THICK, VERYTHICK)",
2614                   __FILE__, V2dWidth, group);
2615
2616   theCommands.Add("v2dunsetwidth",
2617                   "v2dunsetwidth [name of shape]",
2618                   __FILE__, V2dWidth, group);
2619 /*
2620   theCommands.Add("v2dsetshading",
2621                   "v2dsetshading name Quality(default=0.0008)",
2622                   __FILE__, V2dShading, group);
2623
2624   theCommands.Add("v2dunsetshading",
2625                   "v2dunsetshading name",
2626                   __FILE__, V2dShading, group);
2627 */
2628 /*  theCommands.Add("v2dtexture",
2629                   "'v2dtexture NameOfShape TextureFile' \n \
2630                   or 'vtexture NameOfShape' if you want to disable texture mapping \n \
2631                   or 'vtexture NameOfShape ?' to list available textures\n \
2632                   or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n",
2633                   __FILE__, VTexture, group);*/
2634   
2635   //Additional commands for primitives
2636   theCommands.Add("v2dsetlinetype",
2637                   "v2dsetlinetype [name of shape] LineType(SOLID, DASH, DOT, DOTDASH )",
2638                   __FILE__, V2dTypeOfLine, group);
2639
2640   theCommands.Add("v2dunsetlinetype",
2641                   "v2dunsetlinetype [name of shape]",
2642                   __FILE__, V2dTypeOfLine, group);
2643
2644   
2645   theCommands.Add("v2dpoint",
2646                   "v2dpoint [x y marker_type( 0(TOM_POINT),\n \
2647                                         1(TOM_PLUS),\n \
2648                                         2(TOM_STAR),\n \
2649                                         3(TOM_O),\n \
2650                                         4(TOM_X),\n \
2651                                         5(TOM_O_POINT),\n \
2652                                         6(TOM_O_PLUS),\n \
2653                                         7(TOM_O_STAR),\n \
2654                                         8(TOM_O_X) )]",
2655                   __FILE__, drawPoint, group);
2656   
2657   theCommands.Add("v2ddrawaxis",
2658                   "v2ddrawaxis[loc_x loc_y dir_x dir_y]",
2659                   __FILE__, drawAxis, group);
2660   
2661   theCommands.Add("v2dline",
2662                   "v2dline [ x y dir_x dir_y ]",
2663                   __FILE__, drawLine, group);
2664   
2665   theCommands.Add("v2dsegment",
2666                   "v2dsegment [ x1 y1 x2 y2 ]",
2667                   __FILE__, drawSegment, group);
2668
2669   theCommands.Add("v2darrow",
2670                   "v2ddrawArrowLine name [ x1 y1 x2 y2 ]",
2671                   __FILE__, drawArrowLine, group);
2672
2673   theCommands.Add("v2ddrawArc",
2674                   "v2ddrawArc [ x1 y1 x2 y2 x3 y3]",
2675                   __FILE__, drawArc, group);
2676   
2677   theCommands.Add("v2dFinishSymbol",
2678                   "v2dFinishSymbol",
2679                   __FILE__, drawFinishSymbol, group);
2680   
2681   theCommands.Add("v2dBezierCurve",
2682                   "v2dBezierCurve",
2683                   __FILE__, drawBezierCurve, group);
2684   
2685   theCommands.Add("v2dEllipse",
2686                   "v2dEllipse",
2687                   __FILE__, drawEllipse, group);
2688     
2689   theCommands.Add("v2daistext",
2690                   "v2daistext atextname text_str x1 y1 [angle scale]",
2691                   __FILE__, draw2DText, group);
2692
2693   theCommands.Add("v2dtoleranceframe",
2694                   "v2dtoleranceframe [ height loc_x loc_y tol_type( 0(Prs2d_TOT_TAPER),\n \
2695                                                                     1(Prs2d_TOT_SYMTOTAL),\n \
2696                                                                     2(Prs2d_TOT_SYMCIRCULAR),\n \
2697                                                                     3(Prs2d_TOT_SYMMETRY),\n \
2698                                                                     4(Prs2d_TOT_CONCENTRIC),\n \
2699                                                                     5(Prs2d_TOT_POSITION),\n \
2700                                                                     6(Prs2d_TOT_ANGULARITY),\n \
2701                                                                     7(Prs2d_TOT_PERPENDIC),\n \
2702                                                                     8(Prs2d_TOT_PARALLELISM),\n \
2703                                                                     9(Prs2d_TOT_SURFACEPROF),\n \
2704                                                                     10(Prs2d_TOT_LINEPROF),\n \
2705                                                                     11(Prs2d_TOT_CYLINDRIC),\n \
2706                                                                     12(Prs2d_TOT_CIRCULARITY),\n \
2707                                                                     13(Prs2d_TOT_FLATNESS),\n \
2708                                                                     14(Prs2d_TOT_STRAIGHTNESS) )]",
2709                   __FILE__, drawToleanceFrame, group);
2710
2711   theCommands.Add("v2dlengthdim",
2712                   "v2dlengthdim ",
2713                   __FILE__, drawLengthDim, group);
2714   
2715   theCommands.Add("v2dangledim",
2716                   "v2dangledim",
2717                   __FILE__, drawAngleDim, group);
2718   
2719   theCommands.Add("v2dradiusdim",
2720                   "v2dradiusdim",
2721                   __FILE__, drawRadiusDim, group);
2722   
2723   theCommands.Add("v2dsymbols",
2724                   "v2dsymbols",
2725                   __FILE__, drawSymbDim, group);
2726   
2727
2728   
2729   theCommands.Add("v2dlen1",
2730                   "v2dlengthdim ",
2731                   __FILE__, drawLengthDim1, group);
2732
2733
2734   theCommands.Add("v2ddiameter",
2735                   "v2ddiameter radius [ circle_x_coord  circle_y_coord ]",
2736                   __FILE__, drawDiameter, group);
2737   
2738   theCommands.Add("v2dcurve",
2739                   "v2dcurve name name",
2740                   __FILE__,draw2DCurve, group);
2741   
2742   theCommands.Add("v2dtransform",
2743                   "v2dtransform name a11 a12 a21 a22 s1 s2",
2744                   __FILE__, v2dtransform, group);
2745   
2746   theCommands.Add("v2dtable",
2747                   "v2dtable name xSt ySt nbR nbC",
2748                   __FILE__, v2dtable, group);
2749   
2750   theCommands.Add("v2dsetsyle",
2751                   "v2dsetsyle name style",
2752                    __FILE__, v2dsetstyle, group);
2753   
2754   theCommands.Add("v2dtest1",
2755                   "v2dtest1",
2756                    __FILE__, v2dtest1, group);
2757
2758
2759   theCommands.Add("v2dcount",
2760                   "v2dcount",
2761                   __FILE__, NbAllObjects, group);
2762 }
2763