1 // File: Viewer2dTest_DisplayCommands.cxx
2 // Created: 22.01.02 16:21:20
3 // Author: Julia DOROVSKIKH
4 // Copyright: Open Cascade 2001
6 #include <Viewer2dTest.hxx>
8 #include <Viewer2dTest_EventManager.hxx>
9 #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx>
10 #include <Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
12 #include <Draw_Interpretor.hxx>
14 #include <HLRAlgo_Projector.hxx>
16 #include <V2d_Viewer.hxx>
17 #include <V2d_View.hxx>
19 #include <Prs2d_AspectRoot.hxx>
20 #include <Prs2d_AspectLine.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
28 #include <BRep_Tool.hxx>
30 #include <TCollection_AsciiString.hxx>
34 #include <AIS2D_ProjShape.hxx>
35 #include <AIS2D_InteractiveContext.hxx>
37 #include <Quantity_NameOfColor.hxx>
38 #include <Quantity_Color.hxx>
40 #include <Graphic2d_Line.hxx>
41 #include <Graphic2d_Marker.hxx>
42 #include <Graphic2d_View.hxx>
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>
76 #define OCC190 // jfa 04/03/2002 // for vertices load
77 #define OCC154 // jfa 06/03/2002 // for correct erasing
79 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
80 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
82 Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D();
83 Handle(AIS2D_InteractiveContext)& TheAIS2DContext();
84 TopoDS_Shape GetShapeFromName2d (const char* name);
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())
93 Handle(AIS2D_InteractiveObject) retsh;
95 if (GetMapOfAIS2D().IsBound2(name))
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);
103 cout << "an Object which is not an AIS2D_ProjShape already has this name!!!" << endl;
107 TopoDS_Shape S = GetShapeFromName2d(name);
111 if (S.ShapeType() == TopAbs_VERTEX)
113 TopoDS_Vertex aVert = TopoDS::Vertex(S);
114 gp_Pnt aPnt = BRep_Tool::Pnt(aVert);
117 gp_Ax3 aToSystem (anAx2);
118 aTrsf.SetTransformation(aToSystem);
119 aPnt.Transform(aTrsf);
121 Handle(V2d_View) V = Viewer2dTest::CurrentView();
122 retsh = new AIS2D_InteractiveObject();
123 retsh->SetView(V->View());
125 #define VERTEXMARKER 2
126 #define DEFAULTMARKERSIZE 3.0
128 Handle(Graphic2d_Marker) vertex = new Graphic2d_Marker
129 (retsh, VERTEXMARKER, aPnt.X(), aPnt.Y(), DEFAULTMARKERSIZE, DEFAULTMARKERSIZE, 0.0);
134 HLRAlgo_Projector aProjector (anAx2);
135 Handle(AIS2D_ProjShape) retprsh = new AIS2D_ProjShape(aProjector);
143 //=======================================================================
144 //function : GetColorFromName2d
145 //purpose : get the Quantity_NameOfColor from a string
146 //=======================================================================
147 static Quantity_NameOfColor GetColorFromName2d (const char *name)
149 Quantity_NameOfColor ret = DEFAULT_COLOR;
151 Standard_Boolean Found = Standard_False;
152 Standard_CString colstring;
153 for (Standard_Integer i = 0; i <= 514 && !Found; i++)
155 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
156 if (!strcasecmp(name,colstring))
158 ret = (Quantity_NameOfColor)i;
159 Found = Standard_True;
166 //=======================================================================
167 //function : GetMaterialFromName2d
168 //purpose : get the Graphic3d_NameOfMaterial from a string
169 //=======================================================================
170 static Graphic3d_NameOfMaterial GetMaterialFromName2d (const char *name)
172 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
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;
196 cout << " materiau" << name <<" "<<Standard_Integer(mat) << endl;
202 //==============================================================================
203 //function : Select2d
204 //purpose : pick / select an object from the last MoveTo() on a
206 //==============================================================================
207 Handle(AIS2D_InteractiveObject) Select2d (Standard_Integer /*argc*/,
208 const char** /*argv*/,
209 Standard_Boolean shift,
210 Standard_Boolean /*pick*/)
212 Handle(AIS2D_InteractiveObject) ret;
213 Handle (Viewer2dTest_EventManager) EM = Viewer2dTest::CurrentEventManager();
214 if (shift) EM->ShiftSelect();
217 const Handle(AIS2D_InteractiveContext) aContext = EM->Context();
219 if (!aContext->HasOpenedContext())
221 // aContext->InitCurrent();
222 /* while ( aContext->MoreCurrent() ) {
223 Handle(AIS2D_InteractiveObject) aisPickedShape =
224 Handle(AIS2D_InteractiveObject)::DownCast(aContext->Current());
226 const char *name = (GetMapOfAIS2D().IsBound1(aisPickedShape))?
227 GetMapOfAIS2D().Find1(aisPickedShape).ToCString() :
229 Handle(AIS2D_ProjShape) TheRealSh = Handle(AIS2D_ProjShape)::DownCast(aisPickedShape);
230 if(!TheRealSh.IsNull()){
231 cout << "Current is " << name
232 << " (" << GetTypeNameFromShape2d(TheRealSh->Shape())
235 ret = aisPickedShape;
236 if(!TheRealSh.IsNull()){
237 if ( pick && argc > 4 ) {
238 DBRep::Set(argv[4], TheRealSh->Shape());
241 aContext->NextCurrent();
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() ) {
253 TopoDS_Shape PickedShape = aContext->SelectedShape();
254 if ( pick && argc > 5 ) {
255 DBRep::Set(argv[5], PickedShape);
259 if ( aContext->Interactive().IsNull() ) {
260 cout << "??? (No InteractiveObject selected)" << endl;
263 Handle(AIS2D_InteractiveObject) aisPicked =
264 Handle(AIS2D_InteractiveObject)::DownCast(aContext->Interactive());
266 Handle(AIS2D_ProjShape) aisPickedShape = Handle(AIS2D_ProjShape)::DownCast(aisPicked);
269 const char *name = ( GetMapOfAIS2D().IsBound1(aisPicked) )?
270 GetMapOfAIS2D().Find1(aisPicked).ToCString() :
273 if(!aisPickedShape.IsNull()){
274 if ( pick && argc > 4 ) {
275 // Create a draw variable to store the wohole shape
277 DBRep::Set(argv[4], aisPickedShape->Shape());
280 cout << name << " (" << GetTypeNameFromShape2d(aisPickedShape->Shape())
284 // Goto the next selected object
285 aContext->NextSelected();
291 //==============================================================================
292 //function : Displays,Erase...
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)
301 Handle(AIS2D_InteractiveContext) Ctx = Viewer2dTest::GetAIS2DContext();
303 switch (TypeOfOperation)
306 Ctx->Display(IO,Mode,Upd);
309 Ctx->Erase(IO,Mode,Upd);
313 // Ctx->SetDisplayMode((AIS2D_DisplayMode)Mode,Upd);
315 // Ctx->SetDisplayMode(IO,Mode,Upd);
319 // Ctx->SetDisplayMode(0,Upd);
321 // Ctx->UnsetDisplayMode(IO,Upd);
329 //=======================================================================
330 //function :V2dDispMode
332 //=======================================================================
333 static int V2dDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
335 TCollection_AsciiString name;
336 if (argc > 3) return 1;
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;
344 Handle(AIS2D_InteractiveContext) Ctx = Viewer2dTest::GetAIS2DContext();
346 //unset displaymode.. comportement particulier...
347 if (TypeOfOperation == 4)
351 /* if(Ctx->NbCurrents()==0 ||
352 Ctx->NbSelected()==0){
353 Handle(AIS2D_InteractiveObject) IO;
354 VwrTst_DispErase2d(IO,-1,4,Standard_False);
356 else if(!Ctx->HasOpenedContext()){
357 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
358 VwrTst_DispErase2d(Ctx->Current(),-1,4,Standard_False);
361 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
362 VwrTst_DispErase2d(Ctx->Interactive(),-1,4,Standard_False);}*/
363 Ctx->UpdateCurrentViewer();
367 Handle(AIS2D_InteractiveObject) IO;
369 if (GetMapOfAIS2D().IsBound2(name))
371 IO = GetMapOfAIS2D().Find2(name);
372 VwrTst_DispErase2d(IO,-1,4,Standard_True);
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);
383 if (!Ctx->HasOpenedContext())
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);
389 Ctx->UpdateCurrentViewer();
393 // for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
394 // Ctx->Display(Ctx->Interactive(),Dmode);
399 Handle(AIS2D_InteractiveObject) IO;
401 if (GetMapOfAIS2D().IsBound2(name))
402 IO = GetMapOfAIS2D().Find2(name);
403 VwrTst_DispErase2d(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
410 //==============================================================================
411 //function : V2dSetBGColor
412 //purpose : v2dsetbgcolor colorname : change background color
413 //==============================================================================
414 static int V2dSetBGColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
418 cout << "Usage : v2dsetbgcolor colorname" << endl;
421 Handle(V2d_View) V = Viewer2dTest::CurrentView();
422 if (V.IsNull()) return 1;
424 V->SetBackground(GetColorFromName2d(argv[1]));
425 V->Viewer()->Update();
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)
438 theShape->SetContext(TheAIS2DContext());
440 Handle(Graphic2d_Primitive) aPrim;
441 Handle(Prs2d_AspectRoot) anAspect;
442 Standard_Integer i = 1, n = theShape->Length();
445 aPrim = theShape->Primitive(i);
446 if (theShape->HasAspect(aPrim))
448 anAspect = theShape->GetAspect(aPrim);
449 if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
450 else anAspect = NULL;
456 if (anAspect.IsNull())
459 (new Prs2d_AspectLine(theColor, Aspect_TOL_SOLID, Aspect_WOL_THIN,
460 theColor, Graphic2d_TOPF_FILLED));
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);
473 Handle(Prs2d_AspectLine) anAspectLine;
474 if ( !anAspect.IsNull() )
475 anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
477 anAspectLine = new Prs2d_AspectLine();
479 anAspectLine->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
480 if (theShape->IsKind(STANDARD_TYPE(AIS2D_ProjShape)))
482 anAspectLine->SetColor(Quantity_NOC_YELLOW);
483 anAspectLine->SetInterColor(Quantity_NOC_YELLOW);
487 anAspectLine->SetColor(Quantity_NOC_WHITE);
488 anAspectLine->SetInterColor(Quantity_NOC_WHITE);
490 theShape->SetAspect( anAspectLine );
496 static int V2dColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
498 Standard_Boolean ThereIsArgument = Standard_False;
499 Standard_Boolean HaveToSet = Standard_False;
501 if (strcasecmp(argv[0],"v2dsetcolor") == 0) HaveToSet = Standard_True;
503 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
506 if (argc < 2 || argc > 3)
508 cout << "Usage: v2dsetcolor [name] color" << endl;
513 ThereIsArgument = Standard_True;
514 aColor = GetColorFromName2d(argv[2]);
518 aColor = GetColorFromName2d(argv[1]);
525 cout << "Usage: v2dunsetcolor [name]" << endl;
528 if (argc == 2) ThereIsArgument = Standard_True;
531 if (Viewer2dTest::CurrentView().IsNull()) return -1;
532 TheAIS2DContext()->CloseLocalContext();
536 TCollection_AsciiString name = argv[1];
538 if (GetMapOfAIS2D().IsBound2(name))
540 Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
541 V2dSetUnsetColor(aShape, HaveToSet, aColor);
546 Standard_Boolean hasCurrent = Standard_False;
547 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
548 for (; it.More() && !hasCurrent; it.Next())
550 if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
552 for (it.Reset(); it.More(); it.Next())
554 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
555 if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
557 V2dSetUnsetColor(aShape, HaveToSet, aColor);
560 // TheAIS2DContext()->UpdateCurrentViewer();
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)
573 Standard_Boolean ThereIsArgument;
574 Standard_Boolean HaveToSet;
576 if (strcasecmp(argv[0], "v2dsettransp") == 0)
577 HaveToSet = Standard_True;
579 HaveToSet = Standard_False;
583 if (argc < 2 || argc > 3)
585 cout << "Usage: v2dsettransp [name] color" << endl;
588 if (argc == 2) ThereIsArgument = Standard_False;
589 else ThereIsArgument = Standard_True;
595 cout << "Usage: v2dunsettransp [name]" << endl;
598 if (argc == 2) ThereIsArgument = Standard_True;
599 else ThereIsArgument = Standard_False;
602 if (Viewer2dTest::CurrentView().IsNull()) return -1;
603 TheAIS2DContext()->CloseLocalContext();
607 TCollection_AsciiString name = argv[1];
608 if (GetMapOfAIS2D().IsBound2(name))
610 Handle(AIS2D_InteractiveObject) ashape = GetMapOfAIS2D().Find2(name);
612 // TheAIS2DContext()->SetTransparency(ashape,atof(argv[2]) );
614 // TheAIS2DContext()->UnsetTransparency(ashape);
619 // if (TheAIS2DContext()->NbCurrents() > 0)
621 /* for (TheAIS2DContext()->InitCurrent(); TheAIS2DContext()->MoreCurrent();
622 TheAIS2DContext()->NextCurrent())
624 Handle(AIS2D_InteractiveObject) ashape = TheAIS2DContext()->Current();
627 TheAIS2DContext()->SetTransparency(ashape, atof(argv[1]), Standard_False);
630 TheAIS2DContext()->UnsetTransparency(ashape, Standard_False);
633 TheAIS2DContext()->UpdateCurrentViewer();
635 // else // shape not defined (neither current, nor named)
637 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
640 Handle(AIS2D_InteractiveObject) ashape = it.Key1();
642 // TheAIS2DContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
644 // TheAIS2DContext()->UnsetTransparency(ashape,Standard_False);
647 TheAIS2DContext()->UpdateCurrentViewer();
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)
662 Standard_Boolean ThereIsName;
663 Standard_Boolean HaveToSet;
665 if (strcasecmp(argv[0], "v2dsetmaterial") == 0) HaveToSet = Standard_True;
666 else HaveToSet = Standard_False;
670 if (argc < 2 || argc > 3)
672 cout << "Usage: v2dsetmaterial [name] material" << endl;
675 if (argc == 2) ThereIsName = Standard_False;
676 else ThereIsName = Standard_True;
682 cout << "Usage: v2dunsetmaterial [name]" << endl;
685 if (argc == 2) ThereIsName = Standard_True;
686 else ThereIsName = Standard_False;
689 if (Viewer2dTest::CurrentView().IsNull()) return -1;
690 TheAIS2DContext()->CloseLocalContext();
694 TCollection_AsciiString name = argv[1];
695 if (GetMapOfAIS2D().IsBound2(name))
697 Handle(AIS2D_InteractiveObject) ashape = GetMapOfAIS2D().Find2(name);
700 // TheAIS2DContext()->SetMaterial (ashape,GetMaterialFromName2d (argv[2]) );
704 // TheAIS2DContext()->UnsetMaterial(ashape);
710 // if (TheAIS2DContext()->NbCurrents() > 0)
712 /* for (TheAIS2DContext()->InitCurrent(); TheAIS2DContext()->MoreCurrent();
713 TheAIS2DContext()->NextCurrent())
715 Handle(AIS2D_InteractiveObject) ashape = TheAIS2DContext()->Current();
718 TheAIS2DContext()->SetMaterial(ashape, GetMaterialFromName2d(argv[1]), Standard_False);
721 TheAIS2DContext()->UnsetMaterial(ashape, Standard_False);
723 TheAIS2DContext()->UpdateCurrentViewer();
725 // else // shape not defined (neither current, nor named)
727 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
730 Handle(AIS2D_InteractiveObject) ashape = it.Key1();
733 // TheAIS2DContext()->SetMaterial(ashape,GetMaterialFromName2d(argv[1]),Standard_False);
734 // else TheAIS2DContext()->UnsetMaterial(ashape,Standard_False);
737 TheAIS2DContext()->UpdateCurrentViewer();
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)
753 theShape->SetContext(TheAIS2DContext());
755 Handle(Graphic2d_Primitive) aPrim;
756 Handle(Prs2d_AspectRoot) anAspect;
757 Standard_Integer i = 1, n = theShape->Length();
760 aPrim = theShape->Primitive(i);
761 if (theShape->HasAspect(aPrim))
763 anAspect = theShape->GetAspect(aPrim);
764 if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
765 else anAspect = NULL;
771 if (anAspect.IsNull())
773 Quantity_NameOfColor aColor;
774 if (theShape->IsKind(STANDARD_TYPE(AIS2D_ProjShape)))
776 aColor = Quantity_NOC_YELLOW;
780 aColor = Quantity_NOC_WHITE;
782 anAspect = new Prs2d_AspectLine(aColor, Aspect_TOL_SOLID, theWOL,
783 aColor, Graphic2d_TOPF_EMPTY);
787 Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
788 anAspectLine->SetWidth(theWOL);
791 theShape->SetAspect(anAspect);
795 if (!anAspect.IsNull())
797 Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
798 anAspectLine->SetWidth(Aspect_WOL_THIN);
799 // anAspectLine->SetWidthIndex(0);
800 theShape->SetAspect(anAspect);
807 static int V2dWidth (Draw_Interpretor& , Standard_Integer argc, const char** argv)
809 Standard_Boolean ThereIsArgument = Standard_False;
810 Standard_Boolean HaveToSet = Standard_False;
812 if (strcasecmp(argv[0], "v2dsetwidth") == 0) HaveToSet = Standard_True;
817 if (argc < 2 || argc > 3)
819 cout << "Usage: v2dsetwidth [name] width" << endl;
824 ThereIsArgument = Standard_True;
836 cout << "Usage: v2dunsetwidth [name]" << endl;
839 if (argc == 2) ThereIsArgument = Standard_True;
842 if (Viewer2dTest::CurrentView().IsNull()) return -1;
843 TheAIS2DContext()->CloseLocalContext();
845 Aspect_WidthOfLine aWOL = Aspect_WOL_THIN;
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;
857 TCollection_AsciiString name = argv[1];
859 if (GetMapOfAIS2D().IsBound2(name))
861 Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
862 V2dSetUnsetWidth(aShape, HaveToSet, aWOL);
867 Standard_Boolean hasCurrent = Standard_False;
868 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
869 for (; it.More() && !hasCurrent; it.Next())
871 if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
873 for (it.Reset(); it.More(); it.Next())
875 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
876 if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
878 V2dSetUnsetWidth(aShape, HaveToSet, aWOL);
881 // TheAIS2DContext()->UpdateCurrentViewer();
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)
893 // Verification des arguments
894 if (argc != 2 && argc != 11)
896 cout << "Usage: v2ddisplay name [x y z dx dy dz dx1 dy1 dz1]" << endl;
900 if (Viewer2dTest::CurrentView().IsNull())
902 cout << "2D AIS Viewer Initialization ..." << endl;
903 Viewer2dTest::ViewerInit();
904 cout << "Done" << endl;
907 TCollection_AsciiString name;
908 TheAIS2DContext()->CloseLocalContext();
911 gp_Ax2 anAx2 = gp::XOY();
914 Standard_Real x = atof(argv[2]);
915 Standard_Real y = atof(argv[3]);
916 Standard_Real z = atof(argv[4]);
918 Standard_Real dx = atof(argv[5]);
919 Standard_Real dy = atof(argv[6]);
920 Standard_Real dz = atof(argv[7]);
922 Standard_Real dx1 = atof(argv[8]);
923 Standard_Real dy1 = atof(argv[9]);
924 Standard_Real dz1 = atof(argv[10]);
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);
932 Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
933 Standard_Boolean IsDatum = Standard_False;
934 Handle(AIS2D_InteractiveObject) aShape;
937 aShape = GetMapOfAIS2D().Find2(name);
938 // if (aShape->Type() == AIS2D_KOI_Datum)
940 IsDatum = Standard_True;
941 TheAIS2DContext()->Display(aShape, Standard_False);
943 TheAIS2DContext()->HighlightCurrent();
948 cout << "Display " << name << endl;
949 // Get the Shape from a name
950 TopoDS_Shape NewShape = GetShapeFromName2d((const char *)name.ToCString());
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);
960 else // Create the AIS2D_ProjShape from a name
962 aShape = GetAIS2DShapeFromName((const char *)name.ToCString(), anAx2);
963 if (!aShape.IsNull())
965 GetMapOfAIS2D().Bind(aShape, name);
966 TheAIS2DContext()->Display(aShape, Standard_False);
970 // Update the screen and redraw the view
971 TheAIS2DContext()->UpdateCurrentViewer();
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)
983 if (Viewer2dTest::CurrentView().IsNull()) return 1;
985 Standard_Boolean ThereIsArgument = argc > 1;
987 if (TheAIS2DContext()->HasOpenedContext()) TheAIS2DContext()->CloseLocalContext();
991 TheAIS2DContext()->EraseAll(Standard_True, Standard_False);
993 for (int i = 1; i < argc; i++)
995 TCollection_AsciiString name = argv[i];
996 Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
999 Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1000 TheAIS2DContext()->Display(aShape, Standard_False);
1003 TheAIS2DContext()->CurrentViewer()->Update();
1007 Standard_Boolean ThereIsCurrent = Standard_True/*= TheAIS2DContext()->NbCurrents() > 0*/;
1010 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1013 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1014 if (!TheAIS2DContext()->IsCurrent(aShape))
1015 TheAIS2DContext()->Erase(aShape, Standard_False);
1018 TheAIS2DContext()->CurrentViewer()->Update();
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)
1033 if (Viewer2dTest::CurrentView().IsNull()) return 1;
1035 if (TheAIS2DContext()->HasOpenedContext()) TheAIS2DContext()->CloseLocalContext();
1037 if (argc > 1) // has arguments
1039 for (int i = 1; i < argc; i++)
1041 TCollection_AsciiString name = argv[i];
1042 Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
1045 Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1046 TheAIS2DContext()->Erase(aShape, Standard_False);
1049 // TheAIS2DContext()->UpdateCurrentViewer();
1050 TheAIS2DContext()->CurrentViewer()->Update();
1054 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1057 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1058 if (TheAIS2DContext()->IsCurrent(aShape))
1059 TheAIS2DContext()->Erase(aShape, Standard_False);
1062 // TheAIS2DContext()->UpdateCurrentViewer();
1063 TheAIS2DContext()->CurrentViewer()->Update();
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** )
1078 cout << "Usage: v2deraseall" << endl;
1082 if (Viewer2dTest::CurrentView().IsNull())
1084 cout << " Error: v2dinit hasn't been called." << endl;
1088 TheAIS2DContext()->CloseAllContext(Standard_False);
1090 // EraseAll(Standard_True, Standard_True);
1091 TheAIS2DContext()->EraseAll();
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)
1102 if (Viewer2dTest::CurrentView().IsNull()) return 1;
1106 cout << argv[0] << " Syntaxe error" << endl;
1109 TheAIS2DContext()->CloseLocalContext();
1110 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1111 // while (it.More())
1113 // Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1114 // TheAIS2DContext()->Erase(aShape,Standard_False);
1120 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1121 TheAIS2DContext()->Display(aShape, Standard_False);
1125 TheAIS2DContext()->HighlightCurrent();
1127 TheAIS2DContext()->UpdateCurrentViewer();
1128 // TheAIS2DContext()->DisplayAll();
1132 //==============================================================================
1133 //function : VTexture
1136 //==============================================================================
1138 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, Standard_Character** argv )
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;
1146 Handle(AIS2D_InteractiveContext) myAIS2DContext = Viewer2dTest::GetAIS2DContext();
1147 if(myAIS2DContext.IsNull())
1149 cerr << "use 'vinit' command before " << argv[0] << endl;
1153 Handle(AIS2D_InteractiveObject) TheAisIO;
1154 Handle(AIS2D_TexturedShape) myShape;
1155 Standard_Integer myPreviousMode = 0;
1159 cout << argv[0] <<" syntax error - Type 'help vtex'"<<endl;
1163 TCollection_AsciiString name = argv[1];
1164 Viewer2dTest::CurrentView()->SetSurfaceDetail(V2d_TEX_ALL);
1166 if (GetMapOfAIS2D().IsBound2(name))
1167 TheAisIO = GetMapOfAIS2D().Find2(name);
1170 cout <<"shape "<<name<<" doesn\'t exist"<<endl;
1174 if (TheAisIO->IsKind(STANDARD_TYPE(AIS2D_TexturedShape)) && !TheAisIO.IsNull())
1176 myShape = Handle(AIS2D_TexturedShape)::DownCast(TheAisIO);
1177 myPreviousMode = myShape->DisplayMode() ;
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);
1189 case 1: // vtexture : we only map a texture on the shape
1192 cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1197 if(strcasecmp(argv[2],"?")==0)
1199 TCollection_AsciiString monPath = GetEnvir2d();
1201 cout<<"\n Files in current directory : \n"<<endl;
1202 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1203 di.Eval(Cmnd.ToCString());
1205 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1209 cout<<"Files in "<<monPath<<" : \n"<<endl;
1210 di.Eval(Cmnd.ToCString());
1215 myShape->SetTextureFileName(argv[2]);
1219 cout <<"Texture mapping disabled \n \
1220 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<endl;
1222 myAIS2DContext->SetDisplayMode(myShape,1,Standard_False);
1223 if (myPreviousMode == 3 )
1224 myAIS2DContext->RecomputePrsOnly(myShape);
1225 myAIS2DContext->Display(myShape, Standard_True);
1230 case 2: // vtexscale : we change the scaling factor of the texture
1234 cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
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 ) );
1243 case 3: // vtexorigin : we change the origin of the texture on the shape
1246 cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
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 ));
1254 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1257 cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1262 cout <<"Texture repeat enabled"<<endl;
1263 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1267 cout <<"Texture repeat disabled"<<endl;
1268 myShape->SetTextureRepeat(Standard_False);
1272 case 5: // vtexdefault : default texture mapping
1273 // ScaleU = ScaleV = 100.0
1274 // URepeat = VRepeat = 1.0
1275 // Uorigin = VOrigin = 0.0
1279 cerr << argv[0] <<" syntax error - Type 'help vtex'" << endl;
1282 myShape->SetTextureRepeat(Standard_False);
1283 myShape->SetTextureOrigin(Standard_False);
1284 myShape->SetTextureScale (Standard_False);
1288 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1289 myAIS2DContext->RecomputePrsOnly(myShape);
1292 myAIS2DContext->SetDisplayMode(myShape,3,Standard_False);
1293 myAIS2DContext->Display(myShape, Standard_True);
1294 myAIS2DContext->Update(myShape,Standard_True);
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)
1308 Standard_Boolean HaveToSet;
1309 // Standard_Real myDevAngle;
1310 Standard_Real myDevCoef;
1311 Handle(AIS2D_InteractiveObject) TheAisIO;
1314 if (!strcasecmp(argv[0],"vsetshading")) HaveToSet = Standard_True;
1315 else HaveToSet = Standard_False;
1316 TheAIS2DContext()->CloseLocalContext();
1324 myDevCoef = atof(argv[2]);
1327 TCollection_AsciiString name = argv[1];
1328 if (GetMapOfAIS2D().IsBound2(name)) TheAisIO = GetMapOfAIS2D().Find2(name);
1331 TheAisIO = GetAIS2DShapeFromName(name.ToCString());
1336 // TheAIS2DContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
1340 // TheAIS2DContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
1343 TheAIS2DContext()->Redisplay(TheAisIO);
1348 //=======================================================================
1349 //function : VEraseType
1351 //=======================================================================
1352 /*static int VEraseType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1354 if (argc!=2) return 1;
1356 AIS2D_KindOfInteractive TheType;
1357 Standard_Integer TheSign(-1);
1358 GetTypeAndSignfromString2d(argv[1],TheType,TheSign);
1360 AIS2D_ListOfInteractive LIO;
1362 // en attendant l'amelioration ais pour les dimensions...
1364 Standard_Integer dimension_status(-1);
1365 if(TheType==AIS2D_KOI_Relation){
1366 dimension_status = TheSign ==1 ? 1 : 0;
1370 TheAIS2DContext()->DisplayedObjects(TheType,TheSign,LIO);
1371 Handle(AIS2D_InteractiveObject) curio;
1372 for(AIS2D_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
1375 if(dimension_status == -1)
1376 TheAIS2DContext()->Erase(curio,Standard_False);
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);
1384 TheAIS2DContext()->UpdateCurrentViewer();
1388 //=======================================================================
1389 //function : V2dDisplayType
1391 //=======================================================================
1392 /*static int V2dDisplayType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1394 if (argc!=2) return 1;
1396 AIS2D_KindOfInteractive TheType;
1397 Standard_Integer TheSign(-1);
1398 GetTypeAndSignfromString2d(argv[1],TheType,TheSign);
1400 // en attendant l'amelioration ais pour les dimensions...
1402 Standard_Integer dimension_status(-1);
1403 if(TheType==AIS2D_KOI_Relation){
1404 dimension_status = TheSign ==1 ? 1 : 0;
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()){
1413 if(dimension_status == -1)
1414 TheAIS2DContext()->Display(curio,Standard_False);
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);
1424 TheAIS2DContext()->UpdateCurrentViewer();
1429 //Additional commands
1431 //=======================================================================
1432 //function : GetMaterialFromName2d
1433 //purpose : get the Graphic3d_NameOfMaterial from a string
1434 //=======================================================================
1435 static Aspect_TypeOfLine GetLineTypeFromName2d (const char *name)
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;
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 //==============================================================================
1452 static int V2dSetUnsetTypeOfLine (Handle(AIS2D_InteractiveObject) theShape,
1453 Standard_Boolean HaveToSet,
1454 Aspect_TypeOfLine theType = Aspect_TOL_SOLID)
1456 theShape->SetContext(TheAIS2DContext());
1458 Handle(Graphic2d_Primitive) aPrim;
1459 Handle(Prs2d_AspectRoot) anAspect;
1460 //get all primitives
1461 Standard_Integer i = 1, n = theShape->Length();
1464 aPrim = theShape->Primitive(i);
1465 if (theShape->HasAspect(aPrim))
1467 anAspect = theShape->GetAspect(aPrim);
1468 if (anAspect->GetAspectName() == Prs2d_AN_LINE) break;
1469 else anAspect = NULL;
1475 if (anAspect.IsNull())
1478 (new Prs2d_AspectLine(Quantity_NOC_YELLOW, theType, Aspect_WOL_THIN,
1479 Quantity_NOC_YELLOW, Graphic2d_TOPF_FILLED));
1483 Handle(Prs2d_AspectLine) anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
1484 anAspectLine->SetTypeOfFill(Graphic2d_TOPF_FILLED);
1485 anAspectLine->SetType( theType );
1486 theShape->SetAspect(anAspect);
1489 else // unset type line
1491 Handle(Prs2d_AspectLine) anAspectLine;
1492 if ( !anAspect.IsNull() )
1493 anAspectLine = Handle(Prs2d_AspectLine)::DownCast(anAspect);
1495 anAspectLine = new Prs2d_AspectLine();
1497 anAspectLine->SetTypeOfFill(Graphic2d_TOPF_EMPTY);
1498 anAspectLine->SetType(Aspect_TOL_SOLID);
1499 theShape->SetAspect( anAspectLine );
1505 static int V2dTypeOfLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1507 Standard_Boolean ThereIsArgument = Standard_False;
1508 Standard_Boolean HaveToSet = Standard_False;
1510 if (strcasecmp(argv[0],"v2dsetlinetype") == 0) HaveToSet = Standard_True;
1512 Aspect_TypeOfLine aType = Aspect_TOL_SOLID;
1513 //Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1516 if (argc < 2 || argc > 3)
1518 cout << "Usage: v2dsetlinetype [name] type" << endl;
1523 ThereIsArgument = Standard_True;
1524 aType = GetLineTypeFromName2d(argv[2]);
1528 aType = GetLineTypeFromName2d(argv[1]);
1535 cout << "Usage: v2dunsetlinetype [name]" << endl;
1538 if (argc == 2) ThereIsArgument = Standard_True;
1541 if (Viewer2dTest::CurrentView().IsNull()) return -1;
1542 TheAIS2DContext()->CloseLocalContext();
1544 if (ThereIsArgument)
1546 TCollection_AsciiString name = argv[1];
1548 if (GetMapOfAIS2D().IsBound2(name))
1550 Handle(AIS2D_InteractiveObject) aShape = GetMapOfAIS2D().Find2(name);
1551 V2dSetUnsetTypeOfLine(aShape, HaveToSet, aType);
1556 Standard_Boolean hasCurrent = Standard_False;
1557 Viewer2dTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS2D());
1558 for (; it.More() && !hasCurrent; it.Next())
1560 if (TheAIS2DContext()->IsCurrent(it.Key1())) hasCurrent = Standard_True;
1562 for (it.Reset(); it.More(); it.Next())
1564 Handle(AIS2D_InteractiveObject) aShape = it.Key1();
1565 if ((hasCurrent && TheAIS2DContext()->IsCurrent(aShape)) || !hasCurrent)
1567 V2dSetUnsetTypeOfLine(aShape, HaveToSet, aType);
1575 static int drawPoint (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1578 cout << argv[0] << " Syntaxe error" << endl;
1582 if (Viewer2dTest::CurrentView().IsNull()) {
1583 cout << "2D AIS Viewer Initialization ..." << endl;
1584 Viewer2dTest::ViewerInit();
1585 cout << "Done" << endl;
1588 Standard_Real x = 24., y = 24.;
1590 x = atof( argv[1] );
1592 y = atof( argv[2] );
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);
1600 static int drawAxis (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1603 cout << argv[0] << " Syntaxe error" << endl;
1607 if (Viewer2dTest::CurrentView().IsNull()) {
1608 cout << "2D AIS Viewer Initialization ..." << endl;
1609 Viewer2dTest::ViewerInit();
1610 cout << "Done" << endl;
1612 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1614 Standard_Real loc_x = 24., loc_y = 84.;
1616 loc_x = atof( argv[1] );
1618 loc_y = atof( argv[2] );
1619 gp_Pnt2d location(loc_x, loc_y);
1621 Standard_Real dir_x = 0., dir_y = 1.;
1623 dir_x = atof( argv[3] );
1625 dir_y = atof( argv[4] );
1626 gp_Dir2d direction(dir_x, dir_y);
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);
1635 static int drawLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1638 cout << argv[0] << " Syntaxe error" << endl;
1642 if (Viewer2dTest::CurrentView().IsNull()) {
1643 cout << "2D AIS Viewer Initialization ..." << endl;
1644 Viewer2dTest::ViewerInit();
1645 cout << "Done" << endl;
1647 Standard_Real x1 = -11., y1 = -250., d1 = 100., d2 = 200.;
1650 x1 = atof( argv[1] );
1652 y1 = atof( argv[2] );
1654 d1 = atof( argv[3] );
1656 d2 = atof( argv[4] );
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);
1664 TheAIS2DContext()->Display(aIO, Standard_True );
1668 static int drawSegment (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1671 cout << argv[0] << " Syntaxe error" << endl;
1675 if (Viewer2dTest::CurrentView().IsNull()) {
1676 cout << "2D AIS Viewer Initialization ..." << endl;
1677 Viewer2dTest::ViewerInit();
1678 cout << "Done" << endl;
1681 Standard_Real x1 = 0., y1 = 20., x2 = 100., y2 = 200.;
1684 x1 = atof( argv[1] );
1686 y1 = atof( argv[2] );
1688 x2 = atof( argv[3] );
1690 y2 = atof( argv[4] );
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);
1698 static int drawArrowLine (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1701 cout << argv[0] << " Syntaxe error" << endl;
1705 if (Viewer2dTest::CurrentView().IsNull()) {
1706 cout << "2D AIS Viewer Initialization ..." << endl;
1707 Viewer2dTest::ViewerInit();
1708 cout << "Done" << endl;
1711 Standard_Real x1 = 24, y1 = 24, x2 = 420, y2 = 420;
1714 x1 = atof( argv[2] );
1716 y1 = atof( argv[3] );
1718 x2 = atof( argv[4] );
1720 y2 = atof( argv[5] );
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.;
1731 ax = gp_Ax2d(FirstPt, gp_Dir2d(gp_Vec2d(LastPt, FirstPt)));
1733 Handle(Prs2d_Arrow) h_arrow;
1734 h_arrow = new Prs2d_Arrow(aIO, ax, arrow_angle, arrow_length, Prs2d_TypeOfArrow(arrow_type));
1736 GCE2d_MakeSegment segment(FirstPt, LastPt);
1737 Handle(Geom2d_TrimmedCurve) trCur = segment.Value();
1738 Handle(GGraphic2d_Curve) grCurve = new GGraphic2d_Curve(aIO, trCur);
1740 GetMapOfAIS2D().Bind(aIO, argv[1]);
1741 TheAIS2DContext()->Display(aIO, Standard_True );
1742 TheAIS2DContext()->UpdateCurrentViewer();
1747 static int draw2DText (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1751 cout << argv[0] << " Syntaxe error" << endl;
1755 if (Viewer2dTest::CurrentView().IsNull()) {
1756 cout << "2D AIS Viewer Initialization ..." << endl;
1757 Viewer2dTest::ViewerInit();
1758 cout << "Done" << endl;
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;
1767 x1 = atof( argv[3] );
1769 y1 = atof( argv[4] );
1771 anAngle = atof( argv[5] );
1773 aScale = atof( argv[6] );
1775 isUnderline = atoi( argv[7] );
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);
1784 Handle(Prs2d_AspectText) aspect = new Prs2d_AspectText();
1785 aspect->SetFont(Aspect_TOF_HELVETICA);
1786 aspect->SetColor(Quantity_NOC_WHITE);
1787 aIO->SetAspect(aspect);
1789 Standard_Integer color_index = 2;
1790 aText->SetColorIndex(color_index);
1793 GetMapOfAIS2D().Bind(aIO, argv[1]);
1794 TheAIS2DContext()->Display(aIO, Standard_True );
1795 TheAIS2DContext()->UpdateCurrentViewer();
1799 static int drawToleanceFrame( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1803 cout << argv[0] << " Syntaxe error" << endl;
1807 if (Viewer2dTest::CurrentView().IsNull())
1809 cout << "2D AIS Viewer Initialization ..." << endl;
1810 Viewer2dTest::ViewerInit();
1811 cout << "Done" << endl;
1814 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1815 Standard_Real aX = 24, aY = 48;
1816 Standard_Real height = 24;
1819 height = atof( argv[1] );
1822 aX = atof( argv[2] );
1824 aX = atof( argv[3] );
1826 gp_Pnt2d location(aX, aY);
1830 tol_type = atoi( argv[4] );
1833 double text_scale = 10.0;
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);
1839 TheAIS2DContext()->Display(aIO, Standard_True );
1840 TheAIS2DContext()->UpdateCurrentViewer();
1844 static int drawArc( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1848 cout << argv[0] << " Syntaxe error" << endl;
1852 if (Viewer2dTest::CurrentView().IsNull())
1854 cout << "2D AIS Viewer Initialization ..." << endl;
1855 Viewer2dTest::ViewerInit();
1856 cout << "Done" << endl;
1859 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1861 Standard_Real x1 = 0., y1 = 0., x2 = 24., y2 = 24., x3 = 12., y3 = 48.;
1864 x1 = atof( argv[1] );
1866 y1 = atof( argv[2] );
1868 x2 = atof( argv[3] );
1870 y2 = atof( argv[4] );
1872 x3= atof( argv[5] );
1874 y3 = atof( argv[6] );
1876 gp_Pnt2d point1(x1, y1);
1877 gp_Pnt2d point2(x2, y2);
1878 gp_Pnt2d point3(x3, y3);
1880 GCE2d_MakeArcOfCircle arc(point1, point2, point3);
1881 Handle_Geom2d_TrimmedCurve trCur = arc.Value();
1883 Handle_GGraphic2d_Curve grCurve = new GGraphic2d_Curve(aIO, trCur);
1884 TheAIS2DContext()->Display(aIO, Standard_True);
1888 static int drawFinishSymbol( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1892 cout << argv[0] << " Syntaxe error" << endl;
1896 if (Viewer2dTest::CurrentView().IsNull())
1898 cout << "2D AIS Viewer Initialization ..." << endl;
1899 Viewer2dTest::ViewerInit();
1900 cout << "Done" << endl;
1903 gp_Pnt2d location(48, 84);
1907 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
1909 Handle(Graphic2d_Polyline) symbol;
1910 Handle(Graphic2d_Text) text;
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);
1918 trsf.SetRotation(location, angle*M_PI/180);
1920 startPoint.Transform(trsf);
1921 leftTopPoint.Transform(trsf);
1922 btCenPoint.Transform(trsf);
1923 rightTopPoint.Transform(trsf);
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()));
1931 symbol = new Graphic2d_Polyline(aIO, vertex_arr);
1932 TheAIS2DContext()->Display(aIO, Standard_True);
1935 static int drawBezierCurve( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1939 cout << argv[0] << " Syntaxe error" << endl;
1943 if (Viewer2dTest::CurrentView().IsNull())
1945 cout << "2D AIS Viewer Initialization ..." << endl;
1946 Viewer2dTest::ViewerInit();
1947 cout << "Done" << endl;
1950 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
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);
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);
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);
1973 static int draw2DCurve( Draw_Interpretor& , Standard_Integer argc, const char** argv )
1977 cout << argv[0] << " Syntaxe error" << endl;
1981 if (Viewer2dTest::CurrentView().IsNull())
1983 cout << "2D AIS Viewer Initialization ..." << endl;
1984 Viewer2dTest::ViewerInit();
1985 cout << "Done" << endl;
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);
1992 GetMapOfAIS2D().Bind(aIO, argv[1]);
1993 TheAIS2DContext()->Display(aIO, Standard_True);
1994 TheAIS2DContext()->UpdateCurrentViewer();
1998 static int v2dtransform( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2002 cout << argv[0] << " Syntaxe error" << endl;
2006 if (Viewer2dTest::CurrentView().IsNull())
2008 cout << "2D AIS Viewer Initialization ..." << endl;
2009 Viewer2dTest::ViewerInit();
2010 cout << "Done" << endl;
2013 if(!GetMapOfAIS2D().IsBound2(argv[1])) {
2014 cout<<"Object not found"<<endl;
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());
2027 aIO->SetTransform(gp_GTrsf2d(aTrans));
2028 TheAIS2DContext()->UpdateCurrentViewer();
2032 static int v2dsetstyle( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2036 cout << argv[0] << " Syntaxe error" << endl;
2040 if (Viewer2dTest::CurrentView().IsNull())
2042 cout << "2D AIS Viewer Initialization ..." << endl;
2043 Viewer2dTest::ViewerInit();
2044 cout << "Done" << endl;
2047 if(!GetMapOfAIS2D().IsBound2(argv[1])) {
2048 cout<<"Object not found"<<endl;
2052 Handle(AIS2D_InteractiveObject) aIO = GetMapOfAIS2D().Find2(argv[1]);
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])));
2063 TheAIS2DContext()->UpdateCurrentViewer();
2069 static int v2dtest1 (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2072 if (Viewer2dTest::CurrentView().IsNull())
2074 cout << "2D AIS Viewer Initialization ..." << endl;
2075 Viewer2dTest::ViewerInit();
2076 cout << "Done" << endl;
2079 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2081 gp_Pnt2d firstPoint ( 911.84, 851.86);
2082 gp_Pnt2d newPoint (947.78, 847.375);
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);
2090 TheAIS2DContext()->Display(aIO, Standard_True );
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);
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);
2103 TheAIS2DContext()->Display(aIO, Standard_True );
2105 TheAIS2DContext()->UpdateCurrentViewer();
2109 static int v2dtable (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2113 cout << argv[0] << " Syntaxe error" << endl;
2117 if (Viewer2dTest::CurrentView().IsNull()) {
2118 cout << "2D AIS Viewer Initialization ..." << endl;
2119 Viewer2dTest::ViewerInit();
2120 cout << "Done" << endl;
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;
2129 x1 = atof( argv[2] );
2131 y1 = atof( argv[3] );
2133 numberOfColumn = atoi( argv[4] );
2135 numberOfRows = atoi( argv[5] );
2137 Handle(AIS2D_InteractiveObject) aisObj = new AIS2D_InteractiveObject();
2139 Handle(GGraphic2d_SetOfCurves) setOfCurve = new GGraphic2d_SetOfCurves(aisObj);
2141 gp_Pnt2d location(x1,y1);
2142 Standard_Real columnWidth = 100;
2143 Standard_Real rowHeight = 10;
2146 Handle(Geom2d_Curve) trCur;
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)) );
2152 trCur = segment.Value();
2153 setOfCurve->Add(trCur);
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);
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;
2168 Standard_Real text_scale = 2.0;
2170 for(Standard_Integer j=0, k=0; j<numberOfRows; ++j) {
2171 for( i=0; i<numberOfColumn; ++i) {
2173 TCollection_ExtendedString str("TableCell");
2178 Standard_Integer str_len = str.Length();
2180 Standard_Real textLength = str_len * text_scale * 1.8;
2181 Standard_Real textHight = text_scale * 1.6;
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);
2190 GetMapOfAIS2D().Bind(aisObj, argv[1]);
2191 TheAIS2DContext()->Display(aisObj, Standard_True );
2192 TheAIS2DContext()->UpdateCurrentViewer();
2198 static int drawEllipse( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2202 cout << argv[0] << " Syntaxe error" << endl;
2206 if (Viewer2dTest::CurrentView().IsNull())
2208 cout << "2D AIS Viewer Initialization ..." << endl;
2209 Viewer2dTest::ViewerInit();
2210 cout << "Done" << endl;
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);
2222 static int drawLengthDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2226 cout << argv[0] << " Syntaxe error" << endl;
2231 int distance_type = 0;
2233 distance_type = atoi(argv[1]);
2236 if (Viewer2dTest::CurrentView().IsNull())
2238 cout << "2D AIS Viewer Initialization ..." << endl;
2239 Viewer2dTest::ViewerInit();
2240 cout << "Done" << endl;
2243 gp_Pnt2d FirstPt(0, 0);
2244 gp_Pnt2d LastPt(240, 240);
2246 double text_scale = 5;
2247 double length = 100;
2248 double arrow_angle = 24;
2249 double arrow_length = 24;
2252 Standard_Boolean isReverse = Standard_True;
2254 double distance = FirstPt.Distance(LastPt);
2257 sprintf(str_, "%.2f", distance);
2259 TCollection_ExtendedString str(str_);
2261 Handle(Prs2d_Length) theLength;
2262 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
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);
2270 theLength->SetTextRelPos(.5, .5);
2272 TheAIS2DContext()->Display(aIO, Standard_True);
2273 TheAIS2DContext()->UpdateCurrentViewer();
2277 static int drawLengthDim1( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2281 cout << argv[0] << " Syntaxe error" << endl;
2285 if (Viewer2dTest::CurrentView().IsNull())
2287 cout << "2D AIS Viewer Initialization ..." << endl;
2288 Viewer2dTest::ViewerInit();
2289 cout << "Done" << endl;
2292 gp_Pnt2d FirstPt(0, 0);
2293 gp_Pnt2d LastPt(2, 2);
2295 gp_Lin2d aL1(FirstPt,gp_Dir2d(0,1));
2296 gp_Lin2d aL2(LastPt,gp_Dir2d(0,1));
2298 double text_scale = 15;
2300 int distance_type = 0;
2301 double arrow_angle = 24;
2302 double arrow_length = 24;
2306 double distance = FirstPt.Distance(LastPt);
2309 sprintf(str_, "%.2f", distance);
2311 TCollection_ExtendedString str(str_);
2313 Handle(Prs2d_Length) theLength;
2314 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2318 new Prs2d_Length(aIO, aL1, aL2,
2319 str, text_scale, length);
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);
2327 theLength->SetTextRelPos(.5, .5);
2329 TheAIS2DContext()->Display(aIO, Standard_True);
2330 TheAIS2DContext()->UpdateCurrentViewer();
2336 static int drawAngleDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2340 cout << argv[0] << " Syntaxe error" << endl;
2343 Standard_Boolean isReverse = Standard_False;
2346 isReverse = atoi(argv[1]);
2348 if (Viewer2dTest::CurrentView().IsNull())
2350 cout << "2D AIS Viewer Initialization ..." << endl;
2351 Viewer2dTest::ViewerInit();
2352 cout << "Done" << endl;
2355 gp_Pnt2d anAp1(0, 0);
2356 gp_Pnt2d anAp2(240, 240);
2357 gp_Pnt2d anAp3(0, 240);
2359 Quantity_Length aRadius = 100;
2360 TCollection_ExtendedString aText("Rad = 10%");
2362 Handle(Prs2d_Angle) theAngle;
2363 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2366 theAngle = new Prs2d_Angle(aIO, anAp1, anAp3, anAp2, aRadius, aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_ArrowSide(2),isReverse);
2370 new Prs2d_Angle(aIO, anAp1, anAp2, anAp3, aRadius, aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_ArrowSide(2),isReverse);
2373 theAngle->SetTextRelPos(.5, .5);
2375 TheAIS2DContext()->Display(aIO, Standard_True);
2376 TheAIS2DContext()->UpdateCurrentViewer();
2380 static int drawRadiusDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2384 cout << argv[0] << " Syntaxe error" << endl;
2387 Standard_Boolean isReverse = Standard_False;
2390 isReverse = atoi(argv[1]);
2392 if (Viewer2dTest::CurrentView().IsNull())
2394 cout << "2D AIS Viewer Initialization ..." << endl;
2395 Viewer2dTest::ViewerInit();
2396 cout << "Done" << endl;
2399 gp_Pnt2d anAp1(0, 0);
2400 gp_Pnt2d anAp2(240, 240);
2401 gp_Circ2d aCirc(gp_Ax2d(anAp2,gp_Dir2d(0,1)),100.);
2403 Quantity_Length aRadius = 100;
2404 TCollection_ExtendedString aText("Rad = 10%");
2406 Handle(Prs2d_Radius) theRadius;
2407 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2409 theRadius = new Prs2d_Radius(aIO, anAp1, aCirc, aText,1,10.,5.,Prs2d_TypeOfArrow(1),Prs2d_AS_BOTHAR,isReverse);
2410 theRadius->SetTextRelPos(.5, .5);
2412 TheAIS2DContext()->Display(aIO, Standard_True);
2413 TheAIS2DContext()->UpdateCurrentViewer();
2418 static int drawSymbDim( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2422 cout << argv[0] << " Syntaxe error" << endl;
2426 if (Viewer2dTest::CurrentView().IsNull())
2428 cout << "2D AIS Viewer Initialization ..." << endl;
2429 Viewer2dTest::ViewerInit();
2430 cout << "Done" << endl;
2433 gp_Pnt2d anAp1(0, 0);
2434 gp_Pnt2d anAp2(240, 240);
2435 gp_Circ2d aCirc(gp_Ax2d(anAp2,gp_Dir2d(0,1)),100.);
2437 Quantity_Length aRadius = 100;
2438 TCollection_ExtendedString aText("Rad = 10%");
2440 Handle(AIS2D_InteractiveObject) aIO = new AIS2D_InteractiveObject();
2441 Handle(Prs2d_Circularity) symbol;
2443 Standard_Real length = 100;
2444 Standard_Real angle = 270;
2445 symbol = new Prs2d_Circularity( aIO, anAp2.X(), anAp2.Y(), length, angle);
2448 TheAIS2DContext()->Display(aIO, Standard_True);
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);
2455 TheAIS2DContext()->UpdateCurrentViewer();
2460 static int drawDiameter( Draw_Interpretor& , Standard_Integer argc, const char** argv )
2464 cout << argv[0] << " Syntaxe error" << endl;
2468 if (Viewer2dTest::CurrentView().IsNull())
2470 cout << "2D AIS Viewer Initialization ..." << endl;
2471 Viewer2dTest::ViewerInit();
2472 cout << "Done" << endl;
2475 Standard_Real aRadius = 240.;
2476 aRadius = atof( argv[1] );
2478 Standard_Real aX = 0., aY = 0.;
2481 aX = atof( argv[2] );
2483 aY = atof( argv[3] );
2485 gp_Pnt2d cirLoc( aX, aY );
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);
2493 gp_Pnt2d attachPt(cirLoc.X()+aRadius, cirLoc.Y());
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);
2505 TheAIS2DContext()->Display(aIO, Standard_True);
2506 TheAIS2DContext()->UpdateCurrentViewer();
2511 static int NbAllObjects (Draw_Interpretor& , Standard_Integer argc, const char** argv)
2514 cout << argv[0] << " Syntaxe error" << endl;
2518 if (Viewer2dTest::CurrentView().IsNull()) return 1;
2520 AIS2D_ListOfIO aListObj;
2521 TheAIS2DContext()->DisplayedObjects( aListObj );
2522 int aNb = aListObj.Extent();
2524 cout << " Number all objects = " << aNb << endl;
2530 //==============================================================================
2531 //function : Viewer2dTest::Commands
2532 //purpose : Add all the viewer command in the Draw_Interpretor
2533 //==============================================================================
2534 void Viewer2dTest::DisplayCommands (Draw_Interpretor& theCommands)
2536 const char *group = "2D AIS Viewer - Display Commands";
2538 theCommands.Add("v2ddisplay",
2539 "v2ddisplay name [projection(Origin(x y z) Normal(dx dy dz) DX(dx dy dz)]",
2540 __FILE__, V2dDisplay, group);
2542 theCommands.Add("v2derase",
2543 "v2derase [name1] ... [name n]",
2544 __FILE__, V2dErase, group);
2546 theCommands.Add("v2ddonly",
2547 "v2ddonly [name1] ... [name n]",
2548 __FILE__, V2dDonly, group);
2550 theCommands.Add("v2ddisplayall",
2552 __FILE__, V2dDisplayAll, group);
2554 theCommands.Add("v2deraseall",
2556 __FILE__, V2dEraseAll, group);
2558 // theCommands.Add("v2derasetype",
2559 // "v2derasetype <Type> : erase all the displayed objects of one given kind (see vtypes)",
2560 // __FILE__, V2dEraseType, group);
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);
2567 theCommands.Add("v2ddisplaymode",
2568 "v2ddispmode [name] mode(1,2,..) : no name -> on selected objects",
2569 __FILE__, V2dDispMode, group);
2571 theCommands.Add("v2derasemode",
2572 "v2derasemode [name] mode(1,2,..) : no name -> on selected objects",
2573 __FILE__, V2dDispMode, group);
2575 theCommands.Add("v2dsetdispmode",
2576 "v2dsetdispmode [name] mode(1,2,..) : no name -> on selected objects",
2577 __FILE__, V2dDispMode, group);
2579 theCommands.Add("v2dunsetdispmode",
2580 "v2dunsetdispmode [name] mode(1,2,..) : no name -> on selected objects",
2581 __FILE__, V2dDispMode, group);
2583 theCommands.Add("v2dsetcolor",
2584 "v2dsetcolor [name of shape] ColorName",
2585 __FILE__, V2dColor, group);
2587 theCommands.Add("v2dunsetcolor",
2588 "v2dunsetcolor [name of shape]",
2589 __FILE__, V2dColor, group);
2591 theCommands.Add("v2dsetbgcolor",
2592 "v2dsetbgcolor colorname : Change background color",
2593 __FILE__, V2dSetBGColor, group);
2596 theCommands.Add("v2dsettransparency",
2597 "v2dsettransparency [name of shape] TransparencyCoef(0 -> 1)",
2598 __FILE__, V2dTransparency, group);
2600 theCommands.Add("v2dunsettransparency",
2601 "v2dunsettransparency [name of shape]",
2602 __FILE__, V2dTransparency, group);
2604 theCommands.Add("v2dsetmaterial",
2605 "v2dsetmaterial [name of shape] MaterialName",
2606 __FILE__, V2dMaterial, group);
2608 theCommands.Add("v2dunsetmaterial",
2609 "v2dunsetmaterial [name of shape]",
2610 __FILE__, V2dMaterial, group);
2612 theCommands.Add("v2dsetwidth",
2613 "v2dsetwidth [name_of_shape] width(THIN, MEDIUM, THICK, VERYTHICK)",
2614 __FILE__, V2dWidth, group);
2616 theCommands.Add("v2dunsetwidth",
2617 "v2dunsetwidth [name of shape]",
2618 __FILE__, V2dWidth, group);
2620 theCommands.Add("v2dsetshading",
2621 "v2dsetshading name Quality(default=0.0008)",
2622 __FILE__, V2dShading, group);
2624 theCommands.Add("v2dunsetshading",
2625 "v2dunsetshading name",
2626 __FILE__, V2dShading, group);
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);*/
2635 //Additional commands for primitives
2636 theCommands.Add("v2dsetlinetype",
2637 "v2dsetlinetype [name of shape] LineType(SOLID, DASH, DOT, DOTDASH )",
2638 __FILE__, V2dTypeOfLine, group);
2640 theCommands.Add("v2dunsetlinetype",
2641 "v2dunsetlinetype [name of shape]",
2642 __FILE__, V2dTypeOfLine, group);
2645 theCommands.Add("v2dpoint",
2646 "v2dpoint [x y marker_type( 0(TOM_POINT),\n \
2655 __FILE__, drawPoint, group);
2657 theCommands.Add("v2ddrawaxis",
2658 "v2ddrawaxis[loc_x loc_y dir_x dir_y]",
2659 __FILE__, drawAxis, group);
2661 theCommands.Add("v2dline",
2662 "v2dline [ x y dir_x dir_y ]",
2663 __FILE__, drawLine, group);
2665 theCommands.Add("v2dsegment",
2666 "v2dsegment [ x1 y1 x2 y2 ]",
2667 __FILE__, drawSegment, group);
2669 theCommands.Add("v2darrow",
2670 "v2ddrawArrowLine name [ x1 y1 x2 y2 ]",
2671 __FILE__, drawArrowLine, group);
2673 theCommands.Add("v2ddrawArc",
2674 "v2ddrawArc [ x1 y1 x2 y2 x3 y3]",
2675 __FILE__, drawArc, group);
2677 theCommands.Add("v2dFinishSymbol",
2679 __FILE__, drawFinishSymbol, group);
2681 theCommands.Add("v2dBezierCurve",
2683 __FILE__, drawBezierCurve, group);
2685 theCommands.Add("v2dEllipse",
2687 __FILE__, drawEllipse, group);
2689 theCommands.Add("v2daistext",
2690 "v2daistext atextname text_str x1 y1 [angle scale]",
2691 __FILE__, draw2DText, group);
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);
2711 theCommands.Add("v2dlengthdim",
2713 __FILE__, drawLengthDim, group);
2715 theCommands.Add("v2dangledim",
2717 __FILE__, drawAngleDim, group);
2719 theCommands.Add("v2dradiusdim",
2721 __FILE__, drawRadiusDim, group);
2723 theCommands.Add("v2dsymbols",
2725 __FILE__, drawSymbDim, group);
2729 theCommands.Add("v2dlen1",
2731 __FILE__, drawLengthDim1, group);
2734 theCommands.Add("v2ddiameter",
2735 "v2ddiameter radius [ circle_x_coord circle_y_coord ]",
2736 __FILE__, drawDiameter, group);
2738 theCommands.Add("v2dcurve",
2739 "v2dcurve name name",
2740 __FILE__,draw2DCurve, group);
2742 theCommands.Add("v2dtransform",
2743 "v2dtransform name a11 a12 a21 a22 s1 s2",
2744 __FILE__, v2dtransform, group);
2746 theCommands.Add("v2dtable",
2747 "v2dtable name xSt ySt nbR nbC",
2748 __FILE__, v2dtable, group);
2750 theCommands.Add("v2dsetsyle",
2751 "v2dsetsyle name style",
2752 __FILE__, v2dsetstyle, group);
2754 theCommands.Add("v2dtest1",
2756 __FILE__, v2dtest1, group);
2759 theCommands.Add("v2dcount",
2761 __FILE__, NbAllObjects, group);