1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <Quantity_NameOfColor.hxx>
20 #include <Draw_Interpretor.hxx>
22 #include <Draw_Appli.hxx>
25 #include <Font_BRepFont.hxx>
26 #include <Font_FontMgr.hxx>
27 #include <OSD_Chronometer.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <Visual3d_View.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_DisplayMode.hxx>
36 #include <AIS_PointCloud.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_AutoUpdater.hxx>
40 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_EventManager.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Builder.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Face.hxx>
62 #include <Draw_Window.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_DisplayMode.hxx>
66 #include <AIS_Shape.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <Geom_Plane.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <TCollection_HAsciiString.hxx>
73 #include <GC_MakePlane.hxx>
74 #include <gp_Circ.hxx>
75 #include <AIS_Axis.hxx>
76 #include <Geom_Axis2Placement.hxx>
77 #include <Geom_Axis1Placement.hxx>
78 #include <AIS_Trihedron.hxx>
79 #include <AIS_Axis.hxx>
80 #include <gp_Trsf.hxx>
81 #include <TopLoc_Location.hxx>
83 #include <HLRAlgo_Projector.hxx>
84 #include <HLRBRep_PolyAlgo.hxx>
85 #include <HLRBRep_PolyHLRToShape.hxx>
86 #include <Aspect_Window.hxx>
88 #include <Graphic3d_ArrayOfPoints.hxx>
89 #include <Graphic3d_ArrayOfSegments.hxx>
90 #include <Graphic3d_ArrayOfPolylines.hxx>
91 #include <Graphic3d_ArrayOfTriangles.hxx>
92 #include <Graphic3d_ArrayOfTriangleFans.hxx>
93 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
94 #include <Graphic3d_ArrayOfQuadrangles.hxx>
95 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
96 #include <Graphic3d_ArrayOfPolygons.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_Group.hxx>
99 #include <Standard_Real.hxx>
101 #include <AIS_Circle.hxx>
102 #include <BRepBuilderAPI_MakeEdge.hxx>
103 #include <BRepBuilderAPI_MakeFace.hxx>
104 #include <BRepBuilderAPI_MakeWire.hxx>
105 #include <Geom_Circle.hxx>
106 #include <GC_MakeCircle.hxx>
107 #include <Prs3d_Presentation.hxx>
108 #include <Select3D_SensitiveCircle.hxx>
109 #include <SelectMgr_EntityOwner.hxx>
110 #include <SelectMgr_Selection.hxx>
111 #include <StdFail_NotDone.hxx>
112 #include <StdPrs_ShadedShape.hxx>
113 #include <TopoDS_Wire.hxx>
115 #include <AIS_MultipleConnectedInteractive.hxx>
116 #include <AIS_ConnectedInteractive.hxx>
117 #include <AIS_TextLabel.hxx>
118 #include <TopLoc_Location.hxx>
119 #include <TColStd_ListOfInteger.hxx>
120 #include <TColStd_ListIteratorOfListOfInteger.hxx>
122 #include <Select3D_SensitiveTriangle.hxx>
123 #include <Select3D_SensitiveCurve.hxx>
124 #include <Select3D_SensitivePoint.hxx>
125 #include <BRepAdaptor_Curve.hxx>
126 #include <StdPrs_Curve.hxx>
128 #include <BRepExtrema_ExtPC.hxx>
129 #include <BRepExtrema_ExtPF.hxx>
131 #include <Prs3d_Drawer.hxx>
132 #include <Prs3d_VertexDrawMode.hxx>
133 #include <Prs3d_LineAspect.hxx>
134 #include <Prs3d_PointAspect.hxx>
135 #include <Prs3d_TextAspect.hxx>
137 #include <Image_AlienPixMap.hxx>
138 #include <TColStd_HArray1OfAsciiString.hxx>
141 # define _CRT_SECURE_NO_DEPRECATE
142 # pragma warning (disable:4996)
145 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
146 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
147 const Handle(AIS_InteractiveObject)& theAISObj,
148 Standard_Boolean theReplaceIfExists = Standard_True);
149 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
150 extern Handle(AIS_InteractiveContext)& TheAISContext();
153 //==============================================================================
154 //function : Vtrihedron 2d
155 //purpose : Create a plane with a 2D trihedron from a faceselection
156 //Draw arg : vtri2d name
157 //==============================================================================
158 #include <AIS_PlaneTrihedron.hxx>
162 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
165 // Verification des arguments
166 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
169 Standard_Integer myCurrentIndex;
170 // Fermeture des contextes
171 TheAISContext()->CloseAllContexts();
172 // Ouverture d'un contexte local et recuperation de son index.
173 TheAISContext()->OpenLocalContext();
174 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
175 // On active les modes de selections faces.
176 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
177 di<<" Select a face ."<<"\n";
179 // Boucle d'attente waitpick.
180 Standard_Integer argccc = 5;
181 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
182 const char **argvvv = (const char **) bufff;
183 while (ViewerMainLoop( argccc, argvvv) ) { }
187 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
188 ShapeB = TheAISContext()->SelectedShape();
191 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
193 // Construction du Plane
194 // recuperation des edges des faces.
195 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
197 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
201 // si il y a plusieurs edges
202 if (FaceExpB.More() ) {
204 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
205 BRepAdaptor_Curve theCurveB(EdgeB);
206 BRepAdaptor_Curve theCurveC(EdgeC);
207 A=theCurveC.Value(0.1);
208 B=theCurveC.Value(0.9);
209 C=theCurveB.Value(0.5);
212 // FaceB a 1 unique edge courbe
213 BRepAdaptor_Curve theCurveB(EdgeB);
214 A=theCurveB.Value(0.1);
215 B=theCurveB.Value(0.9);
216 C=theCurveB.Value(0.5);
218 // Construction du Geom_Plane
219 GC_MakePlane MkPlane(A,B,C);
220 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
222 // Construction de l'AIS_PlaneTrihedron
223 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
225 // Fermeture du contexte local.
226 TheAISContext()->CloseLocalContext(myCurrentIndex);
228 // on le display & bind
229 TheAISContext()->Display(theAISPlaneTri );
230 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
237 //==============================================================================
238 //function : VTriherdron
239 //purpose : Create a trihedron. If no arguments are set, the default
240 // trihedron (Oxyz) is created.
241 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
242 //==============================================================================
244 static int VTrihedron (Draw_Interpretor& theDi,
245 Standard_Integer theArgsNb,
246 const char** theArgVec)
248 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
250 theDi << theArgVec[0] << " Syntax error\n";
254 gp_Pnt anOrigin (0.0, 0.0, 0.0);
255 gp_Dir aDirZ = gp::DZ();
256 gp_Dir aDirX = gp::DX();
257 Standard_Integer anArgIter = 2; // 1st is an IO name
258 if (anArgIter < theArgsNb)
260 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
261 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
262 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
263 if (anArgIter < theArgsNb)
265 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
266 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
267 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
268 aDirZ.SetCoord (aX, aY, aZ);
270 aX = Draw::Atof (theArgVec[anArgIter++]);
271 aY = Draw::Atof (theArgVec[anArgIter++]);
272 aZ = Draw::Atof (theArgVec[anArgIter++]);
273 aDirX.SetCoord (aX, aY, aZ);
277 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
279 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
283 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
284 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
285 VDisplayAISObject (theArgVec[1], aShape);
289 //==============================================================================
292 //purpose : Change the size of a named or selected trihedron
293 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
294 // if no value, the value is set at 100 by default
295 //Draw arg : vsize [name] [size]
296 //==============================================================================
298 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
301 // Declaration de booleens
302 Standard_Boolean ThereIsName;
303 Standard_Boolean ThereIsCurrent;
305 Standard_Boolean hascol;
307 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
309 // Verification des arguments
310 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
312 // Verification du nombre d'arguments
313 if (argc==1) {ThereIsName=Standard_False;value=100;}
314 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
315 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
317 // On ferme le contexte local pour travailler dans le contexte global
318 if(TheAISContext()->HasOpenedContext())
319 TheAISContext()->CloseLocalContext();
321 // On set le booleen ThereIsCurrent
322 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
323 else {ThereIsCurrent=Standard_False;}
327 //===============================================================
328 // Il n'y a pas de nom mais des objets selectionnes
329 //===============================================================
330 if (!ThereIsName && ThereIsCurrent)
333 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
336 while ( it.More() ) {
338 Handle(AIS_InteractiveObject) aShape=
339 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
341 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
344 // On verifie que l'AIS InteraciveObject selectionne est bien
346 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
348 if (aShape->HasColor()) {
349 hascol=Standard_True;
351 // On recupere la couleur de aShape
352 col=aShape->Color();}
354 else hascol=Standard_False;
356 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
357 // pour lui appliquer la methode SetSize()
358 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
360 // C'est bien un triedre,on chage sa valeur!
361 aTrihedron->SetSize(value);
363 // On donne la couleur au Trihedron
364 if(hascol) aTrihedron->SetColor(col);
365 else aTrihedron->UnsetColor();
368 // The trihedron hasn't be errased from the map
369 // so you just have to redisplay it
370 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
379 TheAISContext() ->UpdateCurrentViewer();
382 //===============================================================
383 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
384 //===============================================================
388 //===============================================================
389 // Il y a un nom de triedre passe en argument
390 //===============================================================
392 TCollection_AsciiString name=argv[1];
394 // on verifie que ce nom correspond bien a une shape
395 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
399 // on recupere la shape dans la map des objets displayes
400 Handle(AIS_InteractiveObject) aShape =
401 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
403 // On verifie que l'AIS InteraciveObject est bien
405 if (!aShape.IsNull() &&
406 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
409 if (aShape->HasColor()) {
410 hascol=Standard_True;
412 // On recupere la couleur de aShape
413 col=aShape->Color();}
415 else hascol=Standard_False;
417 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
418 // pour lui appliquer la methode SetSize()
419 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
421 // C'est bien un triedre,on chage sa valeur
422 aTrihedron->SetSize(value);
424 // On donne la couleur au Trihedron
425 if(hascol) aTrihedron->SetColor(col);
426 else aTrihedron->UnsetColor();
428 // The trihedron hasn't be errased from the map
429 // so you just have to redisplay it
430 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
432 TheAISContext() ->UpdateCurrentViewer();
440 //==============================================================================
442 //==============================================================================
443 //function : VPlaneTrihedron
444 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
445 //Draw arg : vplanetri name
446 //==============================================================================
447 #include <AIS_Plane.hxx>
451 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
454 // Verification des arguments
455 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
458 Standard_Integer myCurrentIndex;
459 // Fermeture des contextes locaux
460 TheAISContext()->CloseAllContexts();
462 // On recupere tous les trihedrons de la GetMapOfAIS()
463 // et on active le mode de selection par face.
464 // =================================================
466 // Ouverture d'un contexte local et recuperation de son index.
467 TheAISContext()->OpenLocalContext(Standard_False);
468 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
470 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
473 Handle(AIS_InteractiveObject) ShapeA =
474 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
475 // On verifie que c'est bien un trihedron
476 if (!ShapeA.IsNull() &&
477 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
479 Handle(AIS_Trihedron) TrihedronA =(Handle(AIS_Trihedron)::DownCast (ShapeA));
480 // on le charge dans le contexte et on active le mode Plane.
481 TheAISContext()->Load(TrihedronA,0,Standard_False);
482 TheAISContext()->Activate(TrihedronA,3);
487 di<<" Select a plane."<<"\n";
488 // Boucle d'attente waitpick.
489 Standard_Integer argccc = 5;
490 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
491 const char **argvvv = (const char **) bufff;
492 while (ViewerMainLoop( argccc, argvvv) ) { }
495 Handle(AIS_InteractiveObject) theIOB;
496 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
497 theIOB = TheAISContext()->SelectedInteractive();
500 Handle(AIS_Plane) PlaneB =(Handle(AIS_Plane)::DownCast (theIOB));
502 // Fermeture du contexte local.
503 TheAISContext()->CloseLocalContext(myCurrentIndex);
505 // on le display & bind
506 TheAISContext()->Display(PlaneB );
507 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
514 //==============================================================================
515 // Fonction First click 2de click
517 // vaxis vertex vertex
519 // vaxispara edge vertex
520 // vaxisortho edge Vertex
521 // vaxisinter Face Face
522 //==============================================================================
524 //==============================================================================
525 //function : VAxisBuilder
527 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
528 //==============================================================================
529 #include <TopoDS_Edge.hxx>
530 #include <TopoDS_Vertex.hxx>
531 #include <TopExp.hxx>
532 #include <Geom_Line.hxx>
534 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
537 Standard_Boolean HasArg;
538 TCollection_AsciiString name;
539 Standard_Integer MyCurrentIndex;
542 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
543 if (argc==8) HasArg=Standard_True;
544 else HasArg=Standard_False;
547 // Fermeture des contextes
548 TheAISContext()->CloseAllContexts();
550 // Cas ou il y a des arguments
551 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
553 Standard_Real coord[6];
554 for(Standard_Integer i=0;i<=5;i++){
555 coord[i]=Draw::Atof(argv[2+i]);
557 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
559 gp_Vec myVect (p1,p2);
560 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
561 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
562 GetMapOfAIS().Bind (TheAxis,name);
563 TheAISContext()->Display(TheAxis);
569 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
570 if ( !strcasecmp(argv[0], "vaxis")) {
571 TheAISContext()->OpenLocalContext();
572 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
574 // Active le mode edge et le mode vertex
575 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
576 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
577 di<<" Select an edge or a vertex."<<"\n";
579 // Boucle d'attente waitpick.
580 Standard_Integer argcc = 5;
581 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
582 const char **argvv = (const char **) buff;
583 while (ViewerMainLoop( argcc, argvv) ) { }
586 // recuperation de la shape.
588 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
589 ShapeA = TheAISContext()->SelectedShape();
591 // recuperation de l'AIS_InteractiveObject
592 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
593 // down cast en AIS_Point si sig et type
594 // AIS_Point -> Geom_Pnt ....
596 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
597 // on desactive le mode edge
598 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
599 di<<" Select a different vertex."<<"\n";
603 // Boucle d'attente waitpick.
604 Standard_Integer argccc = 5;
605 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
606 const char **argvvv = (const char **) bufff;
607 while (ViewerMainLoop( argccc, argvvv) ) { }
609 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
610 ShapeB = TheAISContext()->SelectedShape();
614 } while(ShapeB.IsSame(ShapeA) );
616 // Fermeture du context local
617 TheAISContext()->CloseLocalContext(MyCurrentIndex);
619 // Construction de l'axe
620 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
621 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
624 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
625 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
626 GetMapOfAIS().Bind (TheAxis,name);
627 TheAISContext()->Display(TheAxis);
630 // Un unique edge (ShapeA) a ete picke
631 // Fermeture du context local
632 TheAISContext()->CloseLocalContext(MyCurrentIndex);
633 // Constuction de l'axe
634 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
636 TopExp::Vertices(ed,Va,Vb );
637 gp_Pnt A=BRep_Tool::Pnt(Va);
638 gp_Pnt B=BRep_Tool::Pnt(Vb);
641 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
642 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
643 GetMapOfAIS().Bind (TheAxis,name);
644 TheAISContext()->Display(TheAxis);
650 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
651 else if ( !strcasecmp(argv[0], "vaxispara")) {
653 TheAISContext()->OpenLocalContext();
654 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
656 // Active le mode edge
657 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
658 di<<" Select an edge."<<"\n";
660 // Boucle d'attente waitpick.
661 Standard_Integer argcc = 5;
662 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
663 const char **argvv = (const char **) buff;
664 while (ViewerMainLoop( argcc, argvv) ) { }
668 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
669 ShapeA = TheAISContext()->SelectedShape();
671 // Active le mode vertex et deactive edges
672 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
673 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
674 di<<" Select a vertex."<<"\n";
676 // Boucle d'attente waitpick.
677 Standard_Integer argccc = 5;
678 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
679 const char **argvvv = (const char **) bufff;
680 while (ViewerMainLoop( argccc, argvvv) ) { }
683 // On peut choisir un pnt sur l'edge
685 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
686 ShapeB = TheAISContext()->SelectedShape();
688 // Fermeture du context local
689 TheAISContext()->CloseLocalContext(MyCurrentIndex);
691 // Construction de l'axe
692 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
693 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
695 TopExp::Vertices(ed,Va,Vc );
696 gp_Pnt A=BRep_Tool::Pnt(Va);
697 gp_Pnt C=BRep_Tool::Pnt(Vc);
700 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
701 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
702 GetMapOfAIS().Bind (TheAxis,name);
703 TheAISContext()->Display(TheAxis);
707 // Fonction axisortho
709 TheAISContext()->OpenLocalContext();
710 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
712 // Active le mode edge
713 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
714 di<<" Select an edge."<<"\n";
716 // Boucle d'attente waitpick.
717 Standard_Integer argcc = 5;
718 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
719 const char **argvv = (const char **) buff;
720 while (ViewerMainLoop( argcc, argvv) ) { }
724 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
725 ShapeA = TheAISContext()->SelectedShape();
727 // Active le mode vertex et deactive edges
728 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
729 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
730 di<<" Slect a vertex."<<"\n";
732 // Boucle d'attente waitpick.
733 Standard_Integer argccc = 5;
734 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
735 const char **argvvv = (const char **) bufff;
736 while (ViewerMainLoop( argccc, argvvv) ) { }
739 // On peut choisir un pnt sur l'edge
741 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
742 ShapeB = TheAISContext()->SelectedShape();
744 // Fermeture du context local
745 TheAISContext()->CloseLocalContext(MyCurrentIndex);
747 // Construction de l'axe
748 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
749 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
751 TopExp::Vertices(ed,Va,Vc );
752 gp_Pnt A=BRep_Tool::Pnt(Va);
753 gp_Pnt C=BRep_Tool::Pnt(Vc);
754 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
757 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
758 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
759 GetMapOfAIS().Bind (TheAxis,name);
760 TheAISContext()->Display(TheAxis);
769 //==============================================================================
770 // Fonction First click Result
772 // vpoint vertex AIS_Point=Vertex
773 // edge AIS_Point=Middle of the edge
774 //==============================================================================
776 //==============================================================================
777 //function : VPointBuilder
778 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
779 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
780 //==============================================================================
781 #include <TopoDS_Edge.hxx>
782 #include <TopoDS_Vertex.hxx>
783 #include <TopExp.hxx>
784 #include <AIS_Point.hxx>
785 #include <Geom_CartesianPoint.hxx>
787 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
790 Standard_Boolean HasArg;
791 TCollection_AsciiString name;
792 Standard_Integer myCurrentIndex;
795 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
796 if (argc==5) HasArg=Standard_True;
797 else HasArg=Standard_False;
800 // Fermeture des contextes
801 TheAISContext()->CloseAllContexts();
803 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
805 Standard_Real thecoord[3];
806 for(Standard_Integer i=0;i<=2;i++)
807 thecoord[i]=Draw::Atof(argv[2+i]);
808 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
809 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
810 GetMapOfAIS().Bind (myAISPoint,name);
811 TheAISContext()->Display(myAISPoint);
814 // Il n'a pas d'arguments
816 TheAISContext()->OpenLocalContext();
817 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
819 // Active le mode Vertex et Edges
820 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
821 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
822 di<<" Select a vertex or an edge(build the middle)"<<"\n";
824 // Boucle d'attente waitpick.
825 Standard_Integer argcc = 5;
826 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
827 const char **argvv = (const char **) buff;
828 while (ViewerMainLoop( argcc, argvv) ) { }
832 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
833 ShapeA= TheAISContext()->SelectedShape();
836 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
837 // Un vertex a ete selectionne
838 // Fermeture du context local
839 TheAISContext()->CloseLocalContext(myCurrentIndex);
841 // Construction du point
842 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
843 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
844 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
845 GetMapOfAIS().Bind(myAISPoint,name);
846 TheAISContext()->Display(myAISPoint);
849 // Un Edge a ete selectionne
850 // Fermeture du context local
851 TheAISContext()->CloseLocalContext(myCurrentIndex);
853 // Construction du point milieu de l'edge
854 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
855 TopoDS_Vertex myVertexA,myVertexB;
856 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
857 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
858 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
859 // M est le milieu de [AB]
860 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
861 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
862 GetMapOfAIS().Bind(myAISPointM,name);
863 TheAISContext()->Display(myAISPointM);
871 //==============================================================================
872 // Function 1st click 2de click 3de click
873 // vplane Vertex Vertex Vertex
877 // vplanepara Face Vertex
879 // vplaneortho Face Edge
881 //==============================================================================
883 //==============================================================================
884 //function : VPlaneBuilder
885 //purpose : Build an AIS_Plane from selected entities or Named AIS components
886 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
887 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
888 // [PlaneName] [PointName] [TypeOfSensitivity]
889 //==============================================================================
891 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
892 Standard_Integer argc,
896 Standard_Boolean hasArg;
897 TCollection_AsciiString aName;
898 Standard_Integer aCurrentIndex;
901 if (argc<2 || argc>6 )
903 std::cout<<" Syntax error\n";
906 if (argc == 6 || argc==5 || argc==4)
907 hasArg=Standard_True;
909 hasArg=Standard_False;
912 // Close all contexts
913 TheAISContext()->CloseAllContexts();
915 // There are some arguments
918 if (!GetMapOfAIS().IsBound2(argv[2] ))
920 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
923 // Get shape from map
924 Handle(AIS_InteractiveObject) aShapeA =
925 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
927 // The first argument is an AIS_Point
928 if (!aShapeA.IsNull() &&
929 aShapeA->Type()==AIS_KOI_Datum &&
930 aShapeA->Signature()==1)
932 // The second argument must also be an AIS_Point
933 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
935 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
938 // Get shape from map
939 Handle(AIS_InteractiveObject) aShapeB =
940 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
941 // If B is not an AIS_Point
942 if (aShapeB.IsNull() ||
943 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
945 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
948 // The third object is an AIS_Point
949 if (!GetMapOfAIS().IsBound2(argv[4]) )
951 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
954 // Get shape from map
955 Handle(AIS_InteractiveObject) aShapeC =
956 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
957 // If C is not an AIS_Point
958 if (aShapeC.IsNull() ||
959 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
961 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
965 // Treatment of objects A, B, C
966 // Downcast an AIS_IO to AIS_Point
967 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
968 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
969 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
971 Handle(Geom_CartesianPoint ) aCartPointA =
972 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
974 Handle(Geom_CartesianPoint ) aCartPointB =
975 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
977 Handle(Geom_CartesianPoint ) aCartPointC =
978 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
980 // Verification that the three points are different
981 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
982 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
983 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
986 std::cout<<"vplane error: same points"<<"\n";return 1;
988 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
989 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
990 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
993 std::cout<<"vplane error: same points"<<"\n";return 1;
995 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
996 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
997 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1000 std::cout<<"vplane error: same points"<<"\n";return 1;
1003 gp_Pnt A = aCartPointA->Pnt();
1004 gp_Pnt B = aCartPointB->Pnt();
1005 gp_Pnt C = aCartPointC->Pnt();
1007 // Construction of AIS_Plane
1008 GC_MakePlane MkPlane (A,B,C);
1009 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1010 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1011 GetMapOfAIS().Bind (anAISPlane,aName );
1014 Standard_Integer aType = Draw::Atoi (argv[5]);
1015 if (aType != 0 && aType != 1)
1017 std::cout << "vplane error: wrong type of sensitivity!\n"
1018 << "Should be one of the following values:\n"
1026 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1029 TheAISContext()->Display(anAISPlane);
1032 // The first argument is an AIS_Axis
1033 // Creation of a plane orthogonal to the axis through a point
1034 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1035 // The second argument should be an AIS_Point
1036 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1038 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1041 // Get shape from map
1042 Handle(AIS_InteractiveObject) aShapeB =
1043 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1044 // If B is not an AIS_Point
1045 if (aShapeB.IsNull() ||
1046 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1048 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1052 // Treatment of objects A and B
1053 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1054 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1056 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1057 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1059 gp_Ax1 anAxis = aGeomLineA->Position();
1060 Handle(Geom_CartesianPoint) aCartPointB =
1061 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1063 gp_Dir D =anAxis.Direction();
1064 gp_Pnt B = aCartPointB->Pnt();
1066 // Construction of AIS_Plane
1067 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1068 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1069 GetMapOfAIS().Bind (anAISPlane,aName );
1072 Standard_Integer aType = Draw::Atoi (argv[4]);
1073 if (aType != 0 && aType != 1)
1075 std::cout << "vplane error: wrong type of sensitivity!\n"
1076 << "Should be one of the following values:\n"
1084 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1087 TheAISContext()->Display(anAISPlane);
1090 // The first argumnet is an AIS_Plane
1091 // Creation of a plane parallel to the plane passing through the point
1092 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1094 // The second argument should be an AIS_Point
1095 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1097 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1100 // Get shape from map
1101 Handle(AIS_InteractiveObject) aShapeB =
1102 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1103 // B should be an AIS_Point
1104 if (aShapeB.IsNull() ||
1105 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1107 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1111 // Treatment of objects A and B
1112 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1113 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1115 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1116 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1118 Handle(Geom_CartesianPoint) aCartPointB =
1119 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1120 gp_Pnt B= aCartPointB->Pnt();
1122 // Construction of an AIS_Plane
1123 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1124 GetMapOfAIS().Bind (anAISPlane, aName);
1127 Standard_Integer aType = Draw::Atoi (argv[4]);
1128 if (aType != 0 && aType != 1)
1130 std::cout << "vplane error: wrong type of sensitivity!\n"
1131 << "Should be one of the following values:\n"
1139 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1142 TheAISContext()->Display(anAISPlane);
1147 std::cout<<"vplane: error 1st object is not an AIS\n";
1151 // There are no arguments
1155 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1156 if (!strcasecmp(argv[0], "vplane"))
1158 TheAISContext()->OpenLocalContext();
1159 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1161 // Active modes Vertex, Edge and Face
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1163 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1164 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1165 std::cout<<"Select a vertex, a face or an edge\n";
1168 Standard_Integer argcc = 5;
1169 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1170 const char **argvv = (const char **) buff;
1171 while (ViewerMainLoop( argcc, argvv) ) { }
1174 TopoDS_Shape aShapeA;
1175 for (TheAISContext()->InitSelected();
1176 TheAISContext()->MoreSelected();
1177 TheAISContext()->NextSelected())
1179 aShapeA = TheAISContext()->SelectedShape();
1182 // aShapeA is a Vertex
1183 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1185 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1186 std::cout<<" Select an edge or a different vertex\n";
1189 Standard_Integer argccc = 5;
1190 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1191 const char **argvvv = (const char **) bufff;
1192 while (ViewerMainLoop( argccc, argvvv) ) { }
1195 TopoDS_Shape aShapeB;
1196 for (TheAISContext()->InitSelected();
1197 TheAISContext()->MoreSelected();
1198 TheAISContext()->NextSelected())
1200 aShapeB = TheAISContext()->SelectedShape();
1202 // aShapeB is a Vertex
1203 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1205 // A and B are the same
1206 if (aShapeB.IsSame(aShapeA))
1208 std::cout<<" vplane: error, same points selected\n";
1211 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1212 std::cout<<" Select a different vertex\n";
1215 Standard_Integer argcccc = 5;
1216 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1217 const char **argvvvv = (const char **) buffff;
1218 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1221 TopoDS_Shape aShapeC;
1222 for (TheAISContext()->InitSelected();
1223 TheAISContext()->MoreSelected();
1224 TheAISContext()->NextSelected())
1226 aShapeC = TheAISContext()->SelectedShape();
1228 // aShapeC is the same as A or B
1229 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1231 std::cout<<" vplane: error, same points selected\n";
1235 // Close the local context
1236 TheAISContext()->CloseLocalContext(aCurrentIndex);
1238 // Construction of plane
1239 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1240 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1241 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1242 GC_MakePlane MkPlane(A, B, C);
1243 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1244 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1245 GetMapOfAIS().Bind (anAISPlane, aName);
1246 TheAISContext()->Display(anAISPlane);
1248 // ShapeB is an edge
1251 // Verify that the vertex is not on the edge ShapeB
1252 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1253 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1255 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1256 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1258 // The vertex is on the edge
1259 std::cout<<" vplane: error point is on the edge\n";
1264 // Close the local context
1265 TheAISContext()->CloseLocalContext(aCurrentIndex);
1266 // Construction of plane
1267 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1268 TopoDS_Vertex aVBa, aVBb;
1269 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1270 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1271 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1272 GC_MakePlane MkPlane (A, aBa, aBb);
1273 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1274 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1275 GetMapOfAIS().Bind (anAISPlane, aName);
1276 TheAISContext()->Display(anAISPlane);
1280 // aShapeA is an edge
1281 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1283 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1284 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1285 std::cout<<" Select a vertex that don't belong to the edge\n";
1288 Standard_Integer argccc = 5;
1289 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1290 const char **argvvv = (const char **) bufff;
1291 while (ViewerMainLoop( argccc, argvvv) ) { }
1294 TopoDS_Shape aShapeB;
1295 for (TheAISContext()->InitSelected();
1296 TheAISContext()->MoreSelected();
1297 TheAISContext()->NextSelected())
1299 aShapeB = TheAISContext()->SelectedShape();
1301 // aShapeB should be a Vertex
1302 // Check that the vertex aShapeB is not on the edge
1303 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1304 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1306 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1307 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1309 // The vertex is on the edge
1310 std::cout<<" vplane: error point is on the edge\n";
1315 // Close the local context
1316 TheAISContext()->CloseLocalContext(aCurrentIndex);
1317 // Construction of plane
1318 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1319 TopoDS_Vertex aVAa, aVAb;
1320 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1321 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1322 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1323 GC_MakePlane MkPlane (B,Aa,Ab);
1324 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1325 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1326 GetMapOfAIS().Bind (anAISPlane ,aName);
1327 TheAISContext()->Display(anAISPlane);
1330 // aShapeA is a Face
1333 // Close the local context: nothing to select
1334 TheAISContext()->CloseLocalContext(aCurrentIndex);
1335 // Construction of plane
1336 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1337 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1338 if (aSurface.GetType()==GeomAbs_Plane)
1340 gp_Pln aPlane = aSurface.Plane();
1341 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1342 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1343 GetMapOfAIS().Bind (anAISPlane, aName);
1344 TheAISContext()->Display(anAISPlane);
1348 std::cout<<" vplane: error\n";
1354 // Function vPlanePara
1355 // ===================
1356 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1357 else if (!strcasecmp(argv[0], "vplanepara"))
1359 TheAISContext()->OpenLocalContext();
1360 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1362 // Activate modes Vertex and Face
1363 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1364 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1365 std::cout<<" Select a vertex or a face\n";
1368 Standard_Integer argcc = 5;
1369 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1370 const char **argvv = (const char **) buff;
1371 while (ViewerMainLoop( argcc, argvv) ) { }
1374 TopoDS_Shape aShapeA;
1375 for (TheAISContext()->InitSelected();
1376 TheAISContext()->MoreSelected();
1377 TheAISContext()->NextSelected())
1379 aShapeA = TheAISContext()->SelectedShape();
1382 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1384 // aShapeA is a vertex
1385 // Deactivate the mode Vertex
1386 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1387 std::cout<<" Select a face\n";
1390 Standard_Integer argccc = 5;
1391 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1392 const char **argvvv = (const char **) bufff;
1393 while (ViewerMainLoop( argccc, argvvv) ) { }
1396 TopoDS_Shape aShapeB;
1397 for (TheAISContext()->InitSelected();
1398 TheAISContext()->MoreSelected();
1399 TheAISContext()->NextSelected())
1401 // A vertex ShapeA can be on Face ShapeB
1402 aShapeB = TheAISContext()->SelectedShape();
1405 // Close the local context
1406 TheAISContext()->CloseLocalContext(aCurrentIndex);
1408 // Construction of plane
1409 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1411 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1412 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1413 if (aSurface.GetType()==GeomAbs_Plane )
1415 gp_Pln aPlane = aSurface.Plane();
1416 // Construct a plane parallel to aGeomPlane through A
1417 aPlane.SetLocation(A);
1418 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1419 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1420 GetMapOfAIS().Bind (aAISPlane ,aName);
1421 TheAISContext()->Display(aAISPlane);
1425 std::cout<<" vplanepara: error\n";
1432 // Deactive the mode Face
1433 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1434 std::cout<<" Select a vertex\n";
1437 Standard_Integer argccc = 5;
1438 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1439 const char **argvvv = (const char **) bufff;
1440 while (ViewerMainLoop( argccc, argvvv) ) { }
1443 TopoDS_Shape aShapeB;
1444 for (TheAISContext()->InitSelected();
1445 TheAISContext()->MoreSelected();
1446 TheAISContext()->NextSelected())
1448 // A vertex ShapeB can be on Face ShapeA
1449 aShapeB = TheAISContext()->SelectedShape();
1451 // Close the local context
1452 TheAISContext()->CloseLocalContext(aCurrentIndex);
1454 // Construction of plane
1455 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1457 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1458 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1459 if (aSurface.GetType()==GeomAbs_Plane )
1461 gp_Pln aPlane = aSurface.Plane();
1462 aPlane.SetLocation(B);
1463 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1464 // Construct a plane parallel to aGeomPlane through B
1465 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1466 GetMapOfAIS().Bind (anAISPlane, aName);
1467 TheAISContext()->Display(anAISPlane);
1471 std::cout<<" vplanepara: error"<<"\n";return 1;
1476 // Function vplaneortho
1477 // ====================
1478 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1481 TheAISContext()->OpenLocalContext();
1482 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1484 // Activate the modes Edge and Face
1485 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1486 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1487 std::cout<<" Select a face and an edge coplanar\n";
1490 Standard_Integer argcc = 5;
1491 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1492 const char **argvv = (const char **) buff;
1493 while (ViewerMainLoop( argcc, argvv) ) { }
1496 TopoDS_Shape aShapeA;
1497 for (TheAISContext()->InitSelected();
1498 TheAISContext()->MoreSelected();
1499 TheAISContext()->NextSelected())
1501 aShapeA = TheAISContext()->SelectedShape();
1504 if (aShapeA.ShapeType()==TopAbs_EDGE )
1506 // ShapeA is an edge, deactivate the mode Edge...
1507 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1508 std::cout<<" Select a face\n";
1511 Standard_Integer argccc = 5;
1512 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1513 const char **argvvv = (const char **) bufff;
1514 while (ViewerMainLoop( argccc, argvvv) ) { }
1517 TopoDS_Shape aShapeB;
1518 for (TheAISContext()->InitSelected();
1519 TheAISContext()->MoreSelected();
1520 TheAISContext()->NextSelected())
1522 // Edge ShapeA can be on Face ShapeB
1523 aShapeB = TheAISContext()->SelectedShape();
1526 // Close the local context
1527 TheAISContext()->CloseLocalContext(aCurrentIndex);
1529 // Construction of plane
1530 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1531 TopoDS_Vertex aVAa, aVAb;
1532 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1533 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1534 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1538 // Creation of rotation axis
1539 gp_Ax1 aRotAxis (Aa,Dab);
1541 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1542 // The edge must be parallel to the face
1543 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1544 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1545 // Compare to heights
1546 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1547 >Precision::Confusion())
1549 // the edge is not parallel to the face
1550 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1554 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1555 if (aSurface.GetType()==GeomAbs_Plane)
1557 gp_Pln aPlane = aSurface.Plane();
1558 // It rotates a half turn round the axis of rotation
1559 aPlane.Rotate(aRotAxis , M_PI/2);
1561 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1562 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1563 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1564 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1565 GetMapOfAIS().Bind (anAISPlane, aName);
1566 TheAISContext()->Display(anAISPlane);
1570 std::cout<<" vplaneortho: error\n";
1576 // ShapeA is a Face, deactive the mode Face.
1577 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1578 std::cout<<" Select an edge\n";
1581 Standard_Integer argccc = 5;
1582 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1583 const char **argvvv = (const char **) bufff;
1584 while (ViewerMainLoop( argccc, argvvv) ) { }
1587 TopoDS_Shape aShapeB;
1588 for (TheAISContext()->InitSelected();
1589 TheAISContext()->MoreSelected();
1590 TheAISContext()->NextSelected())
1592 // Edge ShapeB can be on Face ShapeA
1593 aShapeB = TheAISContext()->SelectedShape();
1595 // Close the local context
1596 TheAISContext()->CloseLocalContext(aCurrentIndex);
1598 // Construction of plane
1599 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1600 TopoDS_Vertex aVBa, aVBb;
1601 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1602 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1603 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1604 gp_Vec ab (aBa,aBb);
1606 // Creation of rotation axe
1607 gp_Ax1 aRotAxis (aBa,Dab);
1609 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1610 // The edge must be parallel to the face
1611 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1612 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1613 // Comparing the two heights
1614 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1615 >Precision::Confusion())
1617 // the edge is not parallel to the face
1618 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1622 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1623 if (aSurface.GetType()==GeomAbs_Plane)
1625 gp_Pln aPlane = aSurface.Plane();
1626 // It rotates a half turn round the axis of rotation
1627 aPlane.Rotate(aRotAxis , M_PI/2);
1628 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1629 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1630 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1631 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1632 GetMapOfAIS().Bind (anAISPlane ,aName);
1633 TheAISContext()->Display(anAISPlane);
1637 std::cout<<" vplaneortho: error\n";
1646 //===============================================================================================
1647 //function : VChangePlane
1649 //===============================================================================================
1650 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1652 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1653 if (aContextAIS.IsNull())
1655 std::cout << theArgVec[0] << "AIS context is not available.\n";
1659 if (theArgsNb < 3 || theArgsNb > 11)
1661 std::cerr << theArgVec[0]
1662 << ": incorrect number of command arguments.\n"
1663 << "Type help for more information.\n";
1667 TCollection_AsciiString aName (theArgVec[1]);
1669 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1670 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1673 if ( aPlane.IsNull() )
1675 std::cout << theArgVec[0]
1676 << ": there is no interactive plane with the given name."
1677 << "Type help for more information.\n";
1681 Standard_Real aCenterX = aPlane->Center().X();
1682 Standard_Real aCenterY = aPlane->Center().Y();
1683 Standard_Real aCenterZ = aPlane->Center().Z();
1685 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1686 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1687 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1689 Standard_Real aSizeX = 0.0;
1690 Standard_Real aSizeY = 0.0;
1691 aPlane->Size (aSizeX, aSizeY);
1692 Standard_Boolean isUpdate = Standard_True;
1694 TCollection_AsciiString aPName, aPValue;
1695 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1697 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1698 TCollection_AsciiString anArgCase = anArg;
1699 anArgCase.UpperCase();
1700 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1703 if (aPName.IsEqual ("X"))
1705 aCenterX = aPValue.RealValue();
1707 else if (aPName.IsEqual ("Y"))
1709 aCenterY = aPValue.RealValue();
1711 else if (aPName.IsEqual ("Z"))
1713 aCenterZ = aPValue.RealValue();
1715 else if (aPName.IsEqual ("DX"))
1717 aDirX = aPValue.RealValue();
1719 else if (aPName.IsEqual ("DY"))
1721 aDirY = aPValue.RealValue();
1723 else if (aPName.IsEqual ("DZ"))
1725 aDirZ = aPValue.RealValue();
1727 else if (aPName.IsEqual ("SX"))
1729 aSizeX = aPValue.RealValue();
1731 else if (aPName.IsEqual ("SY"))
1733 aSizeY = aPValue.RealValue();
1736 else if (anArg.IsEqual ("NOUPDATE"))
1738 isUpdate = Standard_False;
1742 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1743 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1744 aPlane->SetCenter (aCenterPnt);
1745 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1746 aPlane->SetSize (aSizeX, aSizeY);
1748 aContextAIS->Update (aPlane, isUpdate);
1753 //==============================================================================
1755 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1756 //==============================================================================
1758 //==============================================================================
1759 //function : VLineBuilder
1760 //purpose : Build an AIS_Line
1761 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1762 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1763 //==============================================================================
1764 #include <Geom_CartesianPoint.hxx>
1765 #include <AIS_Line.hxx>
1768 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1770 Standard_Integer myCurrentIndex;
1772 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1773 // Fermeture des contextes
1774 TheAISContext()->CloseAllContexts();
1776 // On recupere les parametres
1777 Handle(AIS_InteractiveObject) theShapeA;
1778 Handle(AIS_InteractiveObject) theShapeB;
1780 // Parametres: AIS_Point AIS_Point
1781 // ===============================
1784 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1785 // On verifie que c'est bien une AIS_Point
1786 if (!theShapeA.IsNull() &&
1787 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1788 // on recupere le deuxieme AIS_Point
1790 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1791 if (theShapeA.IsNull() ||
1792 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1794 di <<"vline error: wrong type of 2de argument."<<"\n";
1798 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1799 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1801 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1803 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1804 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1805 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1807 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1808 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1809 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1811 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1813 di<<"vline error: same points"<<"\n";return 1;
1815 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817 GetMapOfAIS().Bind(theAISLine,argv[1] );
1818 TheAISContext()->Display(theAISLine );
1822 // Parametres 6 Reals
1823 // ==================
1826 // On verifie que les deux points ne sont pas confondus
1828 Standard_Real coord[6];
1829 for(Standard_Integer i=0;i<=2;i++){
1830 coord[i]=Draw::Atof(argv[2+i]);
1831 coord[i+3]=Draw::Atof(argv[5+i]);
1834 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1837 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838 GetMapOfAIS().Bind(theAISLine,argv[1] );
1839 TheAISContext()->Display(theAISLine );
1843 // Pas de parametres: Selection dans le viewer.
1844 // ============================================
1847 TheAISContext()->OpenLocalContext();
1848 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1850 // Active le mode Vertex.
1851 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1852 di<<" Select a vertex "<<"\n";
1854 // Boucle d'attente waitpick.
1855 Standard_Integer argcc = 5;
1856 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1857 const char **argvv = (const char **) buff;
1858 while (ViewerMainLoop( argcc, argvv) ) { }
1861 TopoDS_Shape ShapeA;
1862 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1863 ShapeA = TheAISContext()->SelectedShape();
1866 // ShapeA est un Vertex
1867 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1869 di<<" Select a different vertex."<<"\n";
1871 TopoDS_Shape ShapeB;
1874 // Boucle d'attente waitpick.
1875 Standard_Integer argccc = 5;
1876 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1877 const char **argvvv = (const char **) bufff;
1878 while (ViewerMainLoop( argccc, argvvv) ) { }
1881 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1882 ShapeB = TheAISContext()->SelectedShape();
1886 } while(ShapeB.IsSame(ShapeA) );
1888 // Fermeture du context local
1889 TheAISContext()->CloseLocalContext(myCurrentIndex);
1891 // Construction de la line
1892 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1893 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1895 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1896 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1898 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1899 GetMapOfAIS().Bind(theAISLine,argv[1] );
1900 TheAISContext()->Display(theAISLine );
1904 di<<"vline error."<<"\n";
1912 //==============================================================================
1913 // class : FilledCircle
1914 // purpose : creates filled circle based on AIS_InteractiveObject
1916 // This class is used to check method Matches() of class
1917 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1918 // because none of AIS classes provides creation of
1919 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1920 // (look method ComputeSelection() )
1921 //==============================================================================
1923 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1925 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1926 gp_Circ aCirc(anAxes, theRadius);
1927 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1931 class FilledCircle : public AIS_InteractiveObject
1935 DEFINE_STANDARD_RTTI(FilledCircle, AIS_InteractiveObject);
1937 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1938 FilledCircle(Handle(Geom_Circle) theCircle);
1941 TopoDS_Face ComputeFace();
1943 // Virtual methods implementation
1944 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1945 const Handle(Prs3d_Presentation)& thePresentation,
1946 const Standard_Integer theMode);
1948 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1949 const Standard_Integer theMode);
1952 Handle(Geom_Circle) myCircle;
1953 Standard_Boolean myFilledStatus;
1958 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1960 myCircle = CreateCircle(theCenter, theRadius);
1961 myFilledStatus = Standard_True;
1964 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1966 myCircle = theCircle;
1967 myFilledStatus = Standard_True;
1970 TopoDS_Face FilledCircle::ComputeFace()
1972 // Create edge from myCircle
1973 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1974 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1976 // Create wire from anEdge
1977 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1978 TopoDS_Wire aWire = aWireMaker.Wire();
1980 // Create face from aWire
1981 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1982 TopoDS_Face aFace = aFaceMaker.Face();
1987 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1988 const Handle(Prs3d_Presentation) &thePresentation,
1989 const Standard_Integer theMode)
1991 thePresentation->Clear();
1993 TopoDS_Face aFace = ComputeFace();
1995 if (aFace.IsNull()) return;
1996 if (theMode != 0) return;
1998 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2001 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2002 const Standard_Integer /*theMode*/)
2004 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2005 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2006 myCircle, myFilledStatus);
2007 theSelection->Add(aSensitiveCircle);
2010 //==============================================================================
2012 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2013 //==============================================================================
2015 //==============================================================================
2016 //function : VCircleBuilder
2017 //purpose : Build an AIS_Circle
2018 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2019 // PointName PointName PointName IsFilled
2020 //==============================================================================
2022 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2023 TCollection_AsciiString theName,
2024 Standard_Boolean isFilled)
2026 Handle(AIS_InteractiveObject) aCircle;
2029 aCircle = new FilledCircle(theGeomCircle);
2033 aCircle = new AIS_Circle(theGeomCircle);
2034 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2037 // Check if there is an object with given name
2038 // and remove it from context
2039 if (GetMapOfAIS().IsBound2(theName))
2041 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2042 Handle(AIS_InteractiveObject) anInterObj =
2043 Handle(AIS_InteractiveObject)::DownCast(anObj);
2044 TheAISContext()->Remove(anInterObj, Standard_False);
2045 GetMapOfAIS().UnBind2(theName);
2048 // Bind the circle to its name
2049 GetMapOfAIS().Bind(aCircle, theName);
2051 // Display the circle
2052 TheAISContext()->Display(aCircle);
2056 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2058 Standard_Integer myCurrentIndex;
2059 // Verification of the arguments
2060 if (argc>6 || argc<2)
2062 std::cout << "vcircle error: expect 4 arguments.\n";
2063 return 1; // TCL_ERROR
2065 TheAISContext()->CloseAllContexts();
2067 // There are all arguments
2071 TCollection_AsciiString aName(argv[1]);
2072 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2074 Handle(AIS_InteractiveObject) theShapeA;
2075 Handle(AIS_InteractiveObject) theShapeB;
2078 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2080 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2083 // Arguments: AIS_Point AIS_Point AIS_Point
2084 // ========================================
2085 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2086 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2088 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2090 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2091 return 1; // TCL_ERROR
2093 // The third object must be a point
2094 Handle(AIS_InteractiveObject) theShapeC =
2095 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2096 if (theShapeC.IsNull() ||
2097 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2099 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2100 return 1; // TCL_ERROR
2103 // Verify that the three points are different
2104 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2105 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2106 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2108 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2109 Handle(Geom_CartesianPoint) myCartPointA =
2110 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2112 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2113 Handle(Geom_CartesianPoint) myCartPointB =
2114 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2116 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2117 Handle(Geom_CartesianPoint) myCartPointC =
2118 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2121 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2122 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2123 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2125 std::cout << "vcircle error: Same points.\n";
2126 return 1; // TCL_ERROR
2129 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2130 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2131 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2133 std::cout << "vcircle error: Same points.\n";
2134 return 1; // TCL_ERROR
2137 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2138 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2139 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2141 std::cout << "vcircle error: Same points.\n";
2142 return 1;// TCL_ERROR
2144 // Construction of the circle
2145 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2146 myCartPointB->Pnt(), myCartPointC->Pnt() );
2147 Handle (Geom_Circle) theGeomCircle;
2150 theGeomCircle = Cir.Value();
2152 catch (StdFail_NotDone)
2154 std::cout << "vcircle error: can't create circle\n";
2155 return -1; // TCL_ERROR
2158 DisplayCircle(theGeomCircle, aName, isFilled);
2161 // Arguments: AIS_Plane AIS_Point Real
2162 // ===================================
2163 else if (theShapeA->Type() == AIS_KOI_Datum &&
2164 theShapeA->Signature() == 7 )
2166 if (theShapeB->Type() != AIS_KOI_Datum ||
2167 theShapeB->Signature() != 1 )
2169 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2170 return 1; // TCL_ERROR
2172 // Check that the radius is >= 0
2173 if (Draw::Atof(argv[4]) <= 0 )
2175 std::cout << "vcircle error: the radius must be >=0.\n";
2176 return 1; // TCL_ERROR
2179 // Recover the normal to the plane
2180 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2181 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2183 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2184 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2185 Handle(Geom_CartesianPoint) myCartPointB =
2186 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2188 gp_Pln mygpPlane = myGeomPlane->Pln();
2189 gp_Ax1 thegpAxe = mygpPlane.Axis();
2190 gp_Dir theDir = thegpAxe.Direction();
2191 gp_Pnt theCenter = myCartPointB->Pnt();
2192 Standard_Real TheR = Draw::Atof(argv[4]);
2193 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2194 Handle (Geom_Circle) theGeomCircle;
2197 theGeomCircle = Cir.Value();
2199 catch (StdFail_NotDone)
2201 std::cout << "vcircle error: can't create circle\n";
2202 return -1; // TCL_ERROR
2205 DisplayCircle(theGeomCircle, aName, isFilled);
2212 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2213 return 1; // TCL_ERROR
2217 // No arguments: selection in the viewer
2218 // =========================================
2221 // Get the name of the circle
2222 TCollection_AsciiString aName(argv[1]);
2224 TheAISContext()->OpenLocalContext();
2225 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2227 // Activate selection mode for vertices and faces
2228 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2229 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2230 std::cout << " Select a vertex or a face\n";
2233 Standard_Integer argcc = 5;
2234 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2235 const char **argvv = (const char **) buff;
2236 while (ViewerMainLoop( argcc, argvv) ) { }
2239 TopoDS_Shape ShapeA;
2240 for(TheAISContext()->InitSelected();
2241 TheAISContext()->MoreSelected();
2242 TheAISContext()->NextSelected() )
2244 ShapeA = TheAISContext()->SelectedShape();
2247 // ShapeA is a Vertex
2248 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2250 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2251 std::cout << " Select a different vertex\n";
2253 TopoDS_Shape ShapeB;
2257 Standard_Integer argccc = 5;
2258 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2259 const char **argvvv = (const char **) bufff;
2260 while (ViewerMainLoop( argccc, argvvv) ) { }
2263 for(TheAISContext()->InitSelected();
2264 TheAISContext()->MoreSelected();
2265 TheAISContext()->NextSelected() )
2267 ShapeB = TheAISContext()->SelectedShape();
2269 } while(ShapeB.IsSame(ShapeA) );
2271 // Selection of ShapeC
2272 std::cout << " Select the last vertex\n";
2273 TopoDS_Shape ShapeC;
2277 Standard_Integer argcccc = 5;
2278 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2279 const char **argvvvv = (const char **) buffff;
2280 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2283 for(TheAISContext()->InitSelected();
2284 TheAISContext()->MoreSelected();
2285 TheAISContext()->NextSelected() )
2287 ShapeC = TheAISContext()->SelectedShape();
2289 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2292 Standard_Boolean isFilled;
2293 std::cout << "Enter filled status (0 or 1)\n";
2296 // Close the local context
2297 TheAISContext()->CloseLocalContext(myCurrentIndex);
2299 // Construction of the circle
2300 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2301 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2302 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2304 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2305 Handle (Geom_Circle) theGeomCircle;
2308 theGeomCircle = Cir.Value();
2310 catch (StdFail_NotDone)
2312 std::cout << "vcircle error: can't create circle\n";
2313 return -1; // TCL_ERROR
2316 DisplayCircle(theGeomCircle, aName, isFilled);
2322 std::cout << " Select a vertex (in your face)\n";
2323 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2325 TopoDS_Shape ShapeB;
2327 Standard_Integer argccc = 5;
2328 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2329 const char **argvvv = (const char **) bufff;
2330 while (ViewerMainLoop( argccc, argvvv) ) { }
2333 for(TheAISContext()->InitSelected();
2334 TheAISContext()->MoreSelected();
2335 TheAISContext()->NextSelected() )
2337 ShapeB = TheAISContext()->SelectedShape();
2340 // Recover the radius
2341 Standard_Real theRad;
2344 std::cout << " Enter the value of the radius:\n";
2346 } while (theRad <= 0);
2348 // Get filled status
2349 Standard_Boolean isFilled;
2350 std::cout << "Enter filled status (0 or 1)\n";
2353 // Close the local context
2354 TheAISContext()->CloseLocalContext(myCurrentIndex);
2355 // Construction of the circle
2357 // Recover the normal to the plane. tag
2358 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2359 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2360 gp_Pln myPlane = mySurface.Plane();
2361 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2362 gp_Pln mygpPlane = theGeomPlane->Pln();
2363 gp_Ax1 thegpAxe = mygpPlane.Axis();
2364 gp_Dir theDir = thegpAxe.Direction();
2366 // Recover the center
2367 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2369 // Construct the circle
2370 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2371 Handle (Geom_Circle) theGeomCircle;
2374 theGeomCircle = Cir.Value();
2376 catch (StdFail_NotDone)
2378 std::cout << "vcircle error: can't create circle\n";
2379 return -1; // TCL_ERROR
2382 DisplayCircle(theGeomCircle, aName, isFilled);
2391 //=======================================================================
2392 //function : VDrawText
2394 //=======================================================================
2395 static int VDrawText (Draw_Interpretor& theDI,
2396 Standard_Integer theArgsNb,
2397 const char** theArgVec)
2399 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2402 std::cout << "Error: wrong number of arguments! See usage:\n";
2403 theDI.PrintHelp (theArgVec[0]);
2406 else if (aContext.IsNull())
2408 std::cout << "Error: no active view!\n";
2412 Standard_Integer anArgIt = 1;
2413 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2414 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2415 Handle(AIS_TextLabel) aTextPrs;
2416 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2418 if (GetMapOfAIS().IsBound2 (aName))
2420 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2424 aTextPrs = new AIS_TextLabel();
2425 aTextPrs->SetFont ("Courier");
2428 aTextPrs->SetText (aText);
2430 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
2432 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2434 for (; anArgIt < theArgsNb; ++anArgIt)
2436 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2439 if (anAutoUpdater.parseRedrawMode (aParam))
2443 else if (aParam == "-pos"
2444 || aParam == "-position")
2446 if (anArgIt + 3 >= theArgsNb)
2448 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2453 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2454 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2455 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2456 aTextPrs->SetPosition (aPos);
2458 else if (aParam == "-color")
2460 if (anArgIt + 1 >= theArgsNb)
2462 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2466 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2467 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2468 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2471 aTextPrs->SetColor (aNameOfColor);
2474 else if (anArgIt + 3 >= theArgsNb)
2476 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2480 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2481 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2482 if (!aColor.IsRealValue()
2483 || !aGreen.IsRealValue()
2484 || !aBlue.IsRealValue())
2486 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2490 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2494 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2497 else if (aParam == "-halign")
2499 if (++anArgIt >= theArgsNb)
2501 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2505 TCollection_AsciiString aType (theArgVec[anArgIt]);
2507 if (aType == "left")
2509 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2511 else if (aType == "center")
2513 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2515 else if (aType == "right")
2517 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2521 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2525 else if (aParam == "-valign")
2527 if (++anArgIt >= theArgsNb)
2529 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2533 TCollection_AsciiString aType (theArgVec[anArgIt]);
2537 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2539 else if (aType == "center")
2541 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2543 else if (aType == "bottom")
2545 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2549 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2553 else if (aParam == "-angle")
2555 if (++anArgIt >= theArgsNb)
2557 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2561 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2563 else if (aParam == "-zoom")
2565 if (++anArgIt >= theArgsNb)
2567 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2571 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2573 else if (aParam == "-height")
2575 if (++anArgIt >= theArgsNb)
2577 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2581 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2583 else if (aParam == "-aspect")
2585 if (++anArgIt >= theArgsNb)
2587 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2591 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2592 anOption.LowerCase();
2593 if (anOption.IsEqual ("regular"))
2595 aTextPrs->SetFontAspect (Font_FA_Regular);
2597 else if (anOption.IsEqual ("bold"))
2599 aTextPrs->SetFontAspect (Font_FA_Bold);
2601 else if (anOption.IsEqual ("italic"))
2603 aTextPrs->SetFontAspect (Font_FA_Italic);
2605 else if (anOption.IsEqual ("bolditalic"))
2607 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2610 else if (aParam == "-font")
2612 if (++anArgIt >= theArgsNb)
2614 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2618 aTextPrs->SetFont (theArgVec[anArgIt]);
2620 else if (aParam == "-disptype"
2621 || aParam == "-displaytype")
2623 if (++anArgIt >= theArgsNb)
2625 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2628 TCollection_AsciiString aType (theArgVec[anArgIt]);
2630 if (aType == "subtitle")
2631 aDisplayType = Aspect_TODT_SUBTITLE;
2632 else if (aType == "decal")
2633 aDisplayType = Aspect_TODT_DEKALE;
2634 else if (aType == "blend")
2635 aDisplayType = Aspect_TODT_BLEND;
2636 else if (aType == "dimension")
2637 aDisplayType = Aspect_TODT_DIMENSION;
2638 else if (aType == "normal")
2639 aDisplayType = Aspect_TODT_NORMAL;
2642 std::cout << "Error: wrong display type '" << aType << "'.\n";
2646 else if (aParam == "-subcolor"
2647 || aParam == "-subtitlecolor")
2649 if (anArgIt + 1 >= theArgsNb)
2651 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2655 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2656 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2657 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2660 aTextPrs->SetColorSubTitle (aNameOfColor);
2663 else if (anArgIt + 3 >= theArgsNb)
2665 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2669 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2670 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2671 if (!aColor.IsRealValue()
2672 || !aGreen.IsRealValue()
2673 || !aBlue.IsRealValue())
2675 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2679 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2683 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2686 else if (aParam == "-2d")
2688 aTrsfPersFlags = Graphic3d_TMF_2d;
2690 else if (aParam == "-trsfperspos"
2691 || aParam == "-perspos")
2693 if (anArgIt + 2 >= theArgsNb)
2695 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2699 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2700 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2701 TCollection_AsciiString aZ = "0";
2702 if (!aX.IsIntegerValue()
2703 || !aY.IsIntegerValue())
2705 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2708 if (anArgIt + 1 < theArgsNb)
2710 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2711 if (aTemp.IsIntegerValue())
2717 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
2721 std::cout << "Error: unknown argument '" << aParam << "'\n";
2726 if (aTrsfPersFlags != Graphic3d_TMF_None)
2728 aTextPrs->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
2729 aTextPrs->SetDisplayType (aDisplayType);
2730 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2731 if (aTextPrs->GetPosition().Z() != 0)
2733 aTextPrs->SetPosition (gp_Pnt(aTextPrs->GetPosition().X(), aTextPrs->GetPosition().Y(), 0));
2736 else if (aTrsfPersFlags != aTextPrs->TransformPersistence().Flags)
2738 aTextPrs->SetTransformPersistence (aTrsfPersFlags);
2739 aTextPrs->SetDisplayType (Aspect_TODT_NORMAL);
2741 ViewerTest::Display (aName, aTextPrs, Standard_False);
2746 #include <gp_Pnt.hxx>
2747 #include <Graphic3d_ArrayOfPoints.hxx>
2748 #include <Graphic3d_ArrayOfPrimitives.hxx>
2749 #include <Graphic3d_ArrayOfTriangles.hxx>
2750 #include <Poly_Array1OfTriangle.hxx>
2751 #include <Poly_Triangle.hxx>
2752 #include <Poly_Triangulation.hxx>
2753 #include <TColgp_Array1OfPnt.hxx>
2754 #include <TShort_Array1OfShortReal.hxx>
2755 #include <TShort_HArray1OfShortReal.hxx>
2757 #include <AIS_Triangulation.hxx>
2758 #include <StdPrs_ToolTriangulatedShape.hxx>
2759 #include <Poly_Connect.hxx>
2760 #include <TColgp_Array1OfDir.hxx>
2761 #include <Graphic3d_GraphicDriver.hxx>
2763 #include <TColStd_Array1OfInteger.hxx>
2764 #include <TColStd_HArray1OfInteger.hxx>
2765 #include <Prs3d_ShadingAspect.hxx>
2766 #include <Graphic3d_MaterialAspect.hxx>
2767 #include <Graphic3d_AspectFillArea3d.hxx>
2769 #include <BRepPrimAPI_MakeCylinder.hxx>
2770 #include <TopoDS_Shape.hxx>
2771 #include <TopExp_Explorer.hxx>
2772 #include <TopAbs.hxx>
2773 #include <StdSelect_ShapeTypeFilter.hxx>
2774 #include <AIS_InteractiveObject.hxx>
2777 //===============================================================================================
2778 //function : CalculationOfSphere
2780 //purpose : Create a Sphere
2781 //===============================================================================================
2783 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2786 double mRadius = Radius;
2787 double mCenter[3] = {X,Y,Z};
2788 int mThetaResolution;
2790 double mStartTheta = 0;//StartTheta;
2791 double mEndTheta = 360;//EndTheta;
2792 double mStartPhi = 0;//StartPhi;
2793 double mEndPhi = 180;//EndPhi;
2794 res = res < 4 ? 4 : res;
2796 mThetaResolution = res;
2797 mPhiResolution = res;
2800 int jStart, jEnd, numOffset;
2801 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2802 double startTheta, endTheta, startPhi, endPhi;
2803 int base, numPoles=0, thetaResolution, phiResolution;
2808 if ( numPieces > mThetaResolution ) {
2809 numPieces = mThetaResolution;
2812 int localThetaResolution = mThetaResolution;
2813 double localStartTheta = mStartTheta;
2814 double localEndTheta = mEndTheta;
2816 while ( localEndTheta < localStartTheta ) {
2817 localEndTheta += 360.0;
2820 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2822 // Change the ivars based on pieces.
2824 start = piece * localThetaResolution / numPieces;
2825 end = (piece+1) * localThetaResolution / numPieces;
2826 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2827 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2828 localThetaResolution = end - start;
2830 // Create north pole if needed
2831 int number_point = 0;
2832 int number_pointArray = 0;
2834 if ( mStartPhi <= 0.0 ) {
2835 number_pointArray++;
2838 if ( mEndPhi >= 180.0 ) {
2839 number_pointArray++;
2843 // Check data, determine increments, and convert to radians
2844 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2845 startTheta *= M_PI / 180.0;
2846 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2847 endTheta *= M_PI / 180.0;
2850 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2851 startPhi *= M_PI / 180.0;
2852 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2853 endPhi *= M_PI / 180.0;
2855 phiResolution = mPhiResolution - numPoles;
2856 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2857 thetaResolution = localThetaResolution;
2858 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2859 ++localThetaResolution;
2861 deltaTheta = (endTheta - startTheta) / thetaResolution;
2863 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2864 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2866 // Create intermediate points
2867 for ( i = 0; i < localThetaResolution; i++ ) {
2868 for ( j = jStart; j < jEnd; j++ ) {
2869 number_pointArray++;
2873 //Generate mesh connectivity
2874 base = phiResolution * localThetaResolution;
2876 int number_triangle = 0 ;
2877 if ( mStartPhi <= 0.0 ) { // around north pole
2878 number_triangle += localThetaResolution;
2881 if ( mEndPhi >= 180.0 ) { // around south pole
2882 number_triangle += localThetaResolution;
2885 // bands in-between poles
2886 for ( i=0; i < localThetaResolution; i++){
2887 for ( j=0; j < (phiResolution-1); j++){
2888 number_triangle +=2;
2892 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2893 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2894 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2896 if ( mStartPhi <= 0.0 ){
2899 x[2] = mCenter[2] + mRadius;
2900 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2903 // Create south pole if needed
2904 if ( mEndPhi >= 180.0 ){
2907 x[2] = mCenter[2] - mRadius;
2908 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2912 for ( i=0; i < localThetaResolution; i++){
2913 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2914 for ( j = jStart; j < jEnd; j++){
2915 phi = startPhi + j*deltaPhi;
2916 radius = mRadius * sin((double)phi);
2917 n[0] = radius * cos((double)theta);
2918 n[1] = radius * sin((double)theta);
2919 n[2] = mRadius * cos((double)phi);
2920 x[0] = n[0] + mCenter[0];
2921 x[1] = n[1] + mCenter[1];
2922 x[2] = n[2] + mCenter[2];
2923 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2929 number_triangle = 1;
2930 if ( mStartPhi <= 0.0 ){// around north pole
2931 for (i=0; i < localThetaResolution; i++){
2932 pts[0] = phiResolution*i + numPoles;
2933 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2935 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2940 if ( mEndPhi >= 180.0 ){ // around south pole
2941 numOffset = phiResolution - 1 + numPoles;
2942 for (i=0; i < localThetaResolution; i++){
2943 pts[0] = phiResolution*i + numOffset;
2944 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2945 pts[1] = numPoles - 1;
2946 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2951 // bands in-between poles
2953 for (i=0; i < localThetaResolution; i++){
2954 for (j=0; j < (phiResolution-1); j++){
2955 pts[0] = phiResolution*i + j + numPoles;
2956 pts[1] = pts[0] + 1;
2957 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2958 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2961 pts[2] = pts[1] - 1;
2962 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2967 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2969 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2971 Standard_Integer index[3];
2972 Standard_Real Tol = Precision::Confusion();
2975 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2976 gp_XYZ eqPlan(0, 0, 0);
2977 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2978 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2979 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2980 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2982 Standard_Real mod = vv.Modulus();
2983 if(mod < Tol) continue;
2987 Standard_Real modmax = eqPlan.Modulus();
2990 Nor = gp_Dir(eqPlan);
2992 Nor = gp_Dir(0., 0., 1.);
2994 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2995 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2996 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2997 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
3001 polyTriangulation->SetNormals(Normals);
3003 return polyTriangulation;
3006 //===============================================================================================
3007 //function : VDrawSphere
3009 //purpose : Create an AIS shape.
3010 //===============================================================================================
3011 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
3014 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3015 if (aContextAIS.IsNull())
3017 std::cout << "Call vinit before!\n";
3022 std::cout << "Use: " << argv[0]
3023 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
3027 // read the arguments
3028 TCollection_AsciiString aShapeName (argv[1]);
3029 Standard_Integer aResolution = Draw::Atoi (argv[2]);
3030 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
3031 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
3032 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3033 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
3034 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3035 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
3037 // remove AIS object with given name from map
3038 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
3041 std::cout << "Compute Triangulation...\n";
3042 Handle(AIS_Triangulation) aShape
3043 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3046 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3047 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3049 // stupid initialization of Green color in RGBA space as integer
3050 // probably wrong for big-endian CPUs
3051 Standard_Integer aRed = 0;
3052 Standard_Integer aGreen = 255;
3053 Standard_Integer aBlue = 0;
3054 Standard_Integer anAlpha = 0; // not used
3055 Standard_Integer aColorInt = aRed;
3056 aColorInt += aGreen << 8;
3057 aColorInt += aBlue << 16;
3058 aColorInt += anAlpha << 24;
3060 // setup colors array per vertex
3061 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3062 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3064 aColorArray->SetValue (aNodeId, aColorInt);
3066 aShape->SetColors (aColorArray);
3069 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3070 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3071 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3072 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3073 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3074 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3075 aTotalSize >>= 20; //MB
3076 aNormalsSize >>= 20;
3078 aTrianglesSize >>= 20;
3079 aPolyConnectSize >>= 20;
3082 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3083 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3084 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3085 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3086 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3087 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3090 // Setting material properties, very important for desirable visual result!
3091 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3092 aMat.SetAmbient (0.2);
3093 aMat.SetSpecular (0.5);
3094 Handle(Graphic3d_AspectFillArea3d) anAspect
3095 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3097 Quantity_NOC_YELLOW,
3102 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3105 anAspect->SetEdgeOn();
3109 anAspect->SetEdgeOff();
3111 aShAsp->SetAspect (anAspect);
3112 aShape->Attributes()->SetShadingAspect (aShAsp);
3114 VDisplayAISObject (aShapeName, aShape);
3118 //=============================================================================
3119 //function : VComputeHLR
3121 //=============================================================================
3123 static int VComputeHLR (Draw_Interpretor& di,
3124 Standard_Integer argc,
3127 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3129 if (aContextAIS.IsNull ())
3131 di << "Please call vinit before\n";
3135 if ( argc != 3 && argc != 12 )
3137 di << "Usage: " << argv[0] << " ShapeName HlrName "
3138 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3139 << " ShapeName - name of the initial shape\n"
3140 << " HlrName - result hlr object from initial shape\n"
3141 << " eye, dir are eye position and look direction\n"
3142 << " up is the look up direction vector\n"
3143 << " Use vtop to see projected hlr shape\n";
3147 // shape and new object name
3148 TCollection_AsciiString aShapeName (argv[1]);
3149 TCollection_AsciiString aHlrName (argv[2]);
3151 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3154 BRep_Builder aBrepBuilder;
3155 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3158 di << "No shape with name " << argv[1] << " found\n";
3163 if (GetMapOfAIS ().IsBound2 (aHlrName))
3165 di << "Presentable object with name " << argv[2] << " already exists\n";
3169 // close local context
3170 if (aContextAIS->HasOpenedContext ())
3171 aContextAIS->CloseLocalContext ();
3173 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3174 HLRBRep_PolyHLRToShape aHLRToShape;
3183 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3184 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3185 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3186 aProjAx.SetLocation (anEye);
3187 aProjAx.SetDirection (aDir);
3188 aProjAx.SetYDirection (anUp);
3194 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3195 Handle(V3d_View) aView = ViewerTest::CurrentView();
3196 Standard_Integer aWidth, aHeight;
3197 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3198 Standard_Real aRightX, aRightY, aRightZ;
3199 aView->Window()->Size (aWidth, aHeight);
3201 aView->ConvertWithProj (aWidth, aHeight/2,
3202 aRightX, aRightY, aRightZ,
3203 aDirX, aDirY, aDirZ);
3205 aView->ConvertWithProj (aWidth/2, aHeight/2,
3206 aCentX, aCentY, aCentZ,
3207 aDirX, aDirY, aDirZ);
3209 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3210 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3211 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3212 aProjAx.SetLocation (anEye);
3213 aProjAx.SetDirection (aDir);
3214 aProjAx.SetXDirection (aRight);
3217 HLRAlgo_Projector aProjector (aProjAx);
3218 aPolyAlgo->Projector (aProjector);
3219 aPolyAlgo->Load (aSh);
3220 aPolyAlgo->Update ();
3222 aHLRToShape.Update (aPolyAlgo);
3224 // make hlr shape from input shape
3225 TopoDS_Compound aHlrShape;
3226 BRep_Builder aBuilder;
3227 aBuilder.MakeCompound (aHlrShape);
3229 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3230 if (!aCompound.IsNull ())
3232 aBuilder.Add (aHlrShape, aCompound);
3235 // extract visible outlines
3236 aCompound = aHLRToShape.OutLineVCompound();
3237 if (!aCompound.IsNull ())
3239 aBuilder.Add (aHlrShape, aCompound);
3242 // create an AIS shape and display it
3243 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3244 GetMapOfAIS().Bind (anObject, aHlrName);
3245 aContextAIS->Display (anObject);
3247 aContextAIS->UpdateCurrentViewer ();
3252 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3253 // manipulating and displaying such an array with AIS context
3255 class MyPArrayObject : public AIS_InteractiveObject
3260 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3261 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3263 myArrayDescription = theArrayDescription;
3264 myMarkerAspect = theMarkerAspect;
3267 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
3271 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3272 const Handle(Prs3d_Presentation)& aPresentation,
3273 const Standard_Integer aMode);
3275 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3276 const Standard_Integer /*theMode*/);
3278 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3279 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3280 Standard_Integer &theArgIndex,
3281 Standard_Integer theArgCount,
3282 Standard_Integer theMaxArgs);
3286 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3287 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3292 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3293 const Handle(Prs3d_Presentation)& aPresentation,
3294 const Standard_Integer /*aMode*/)
3297 // Parsing array description
3298 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3299 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3300 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3302 Standard_Integer anArgIndex = 0;
3303 Standard_Integer anArgsCount = myArrayDescription->Length();
3304 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3306 TCollection_AsciiString aCommand;
3307 while (anArgIndex < anArgsCount)
3309 aCommand = myArrayDescription->Value (anArgIndex);
3310 aCommand.LowerCase();
3313 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3315 // vertex has a normal or normal with color or texel
3316 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3317 hasNormals = Standard_True;
3319 // vertex has a color
3320 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3321 hasVColors = Standard_True;
3323 // vertex has a texel
3324 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3325 hasTexels = Standard_True;
3330 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3333 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3334 hasBColors = Standard_True;
3339 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3348 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3349 if (anArrayType == "points")
3351 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3353 else if (anArrayType == "segments")
3354 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3355 else if (anArrayType == "polylines")
3356 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3357 hasVColors, hasBColors);
3358 else if (anArrayType == "triangles")
3359 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3360 hasVColors, hasTexels);
3361 else if (anArrayType == "trianglefans")
3362 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3363 hasNormals, hasVColors,
3364 hasBColors, hasTexels);
3365 else if (anArrayType == "trianglestrips")
3366 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3367 hasNormals, hasVColors,
3368 hasBColors, hasTexels);
3369 else if (anArrayType == "quads")
3370 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3371 hasNormals, hasVColors,
3373 else if (anArrayType == "quadstrips")
3374 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3375 hasNormals, hasVColors,
3376 hasBColors, hasTexels);
3377 else if (anArrayType == "polygons")
3378 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3379 hasNormals, hasVColors, hasBColors,
3383 while (anArgIndex < anArgsCount)
3385 aCommand = myArrayDescription->Value (anArgIndex);
3386 aCommand.LowerCase();
3387 if (!aCommand.IsAscii())
3391 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3393 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3394 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3395 myArrayDescription->Value (anArgIndex - 1).RealValue());
3396 const Standard_Integer aVertIndex = anArray->VertexNumber();
3398 // vertex has a normal or normal with color or texel
3399 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3400 anArray->SetVertexNormal (aVertIndex,
3401 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3402 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3403 myArrayDescription->Value (anArgIndex - 1).RealValue());
3405 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3406 anArray->SetVertexColor (aVertIndex,
3407 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3408 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3409 myArrayDescription->Value (anArgIndex - 1).RealValue());
3411 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3412 anArray->SetVertexTexel (aVertIndex,
3413 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3414 myArrayDescription->Value (anArgIndex - 1).RealValue());
3417 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3419 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3421 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3422 anArray->AddBound (aVertCount,
3423 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3424 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3425 myArrayDescription->Value (anArgIndex - 1).RealValue());
3428 anArray->AddBound (aVertCount);
3431 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3433 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3434 anArray->AddEdge (aVertIndex);
3441 aPresentation->Clear();
3442 if (!myMarkerAspect.IsNull())
3444 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3446 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3449 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3450 const Standard_Integer /*theMode*/)
3452 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3454 Standard_Integer anArgIndex = 1;
3455 while (anArgIndex < myArrayDescription->Length())
3457 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3459 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3460 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3461 myArrayDescription->Value (anArgIndex - 1).RealValue());
3462 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3463 theSelection->Add (aSensetivePoint);
3472 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3473 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3474 Standard_Integer &theArgIndex,
3475 Standard_Integer theArgCount,
3476 Standard_Integer theMaxArgs)
3478 // check if there is more elements than expected
3479 if (theArgIndex >= theMaxArgs)
3482 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3483 aStrCommand.LowerCase();
3484 if (aStrCommand.Search(theCommand) != 1 ||
3485 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3488 // go to the first data element
3491 // check data if it can be converted to numeric
3492 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3494 aStrCommand = theArgsArray->Value (theArgIndex);
3495 if (!aStrCommand.IsRealValue())
3502 //=============================================================================
3503 //function : VDrawPArray
3504 //purpose : Draws primitives array from list of vertexes, bounds, edges
3505 //=============================================================================
3507 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3509 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3510 if (aContextAIS.IsNull())
3512 di << "Call vinit before!\n";
3517 di << "Use: " << argv[0] << " Name TypeOfArray"
3518 << " [vertex] ... [bounds] ... [edges]\n"
3519 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3520 << " trianglefans | trianglestrips | quads |\n"
3521 << " quadstrips | polygons }\n"
3522 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3523 << " [texel={ 't' tx ty }] } \n"
3524 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3525 << " edges={ 'e' vertex_id }\n";
3529 // read the arguments
3530 Standard_Integer aArgIndex = 1;
3531 TCollection_AsciiString aName (argv[aArgIndex++]);
3532 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3534 Standard_Boolean hasVertex = Standard_False;
3536 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3537 anArgsArray->SetValue (0, anArrayType);
3539 if (anArrayType != "points" &&
3540 anArrayType != "segments" &&
3541 anArrayType != "polylines" &&
3542 anArrayType != "triangles" &&
3543 anArrayType != "trianglefans" &&
3544 anArrayType != "trianglestrips" &&
3545 anArrayType != "quads" &&
3546 anArrayType != "quadstrips" &&
3547 anArrayType != "polygons")
3549 di << "Unexpected type of primitives array\n";
3553 TCollection_AsciiString aCommand;
3554 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3556 aCommand = argv[anArgIndex];
3557 aCommand.LowerCase();
3558 if (!aCommand.IsAscii())
3560 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3561 << "should be an array element: 'v', 'b', 'e' \n";
3565 if (aCommand == "v")
3567 hasVertex = Standard_True;
3570 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3575 di << "You should pass any verticies in the list of array elements\n";
3579 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3580 if (anArrayType == "points")
3582 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3585 // create primitives array object
3586 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3588 // register the object in map
3589 VDisplayAISObject (aName, aPObject);
3594 //=======================================================================
3595 //function : VSetLocation
3596 //purpose : Change location of AIS interactive object
3597 //=======================================================================
3599 static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
3600 Standard_Integer theArgNb,
3601 const char** theArgVec)
3603 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3604 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3605 if (aContext.IsNull())
3607 std::cout << "Error: no active view!\n";
3611 TCollection_AsciiString aName;
3613 Standard_Boolean isSetLoc = Standard_False;
3615 Standard_Integer anArgIter = 1;
3616 for (; anArgIter < theArgNb; ++anArgIter)
3618 Standard_CString anArg = theArgVec[anArgIter];
3619 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3623 else if (aName.IsEmpty())
3629 isSetLoc = Standard_True;
3630 if (anArgIter + 1 >= theArgNb)
3632 std::cout << "Error: syntax error at '" << anArg << "'\n";
3635 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3636 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3637 if (anArgIter + 1 < theArgNb)
3639 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3644 std::cout << "Error: unknown argument '" << anArg << "'\n";
3650 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3651 Handle(AIS_InteractiveObject) anIObj;
3652 if (aMap.IsBound2 (aName))
3654 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3656 if (anIObj.IsNull())
3658 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3663 aTrsf.SetTranslation (aLocVec);
3664 TopLoc_Location aLocation (aTrsf);
3665 aContext->SetLocation (anIObj, aLocation);
3669 //=======================================================================
3670 //function : TransformPresentation
3671 //purpose : Change transformation of AIS interactive object
3672 //=======================================================================
3673 static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3674 Standard_Integer theArgNb,
3675 const char** theArgVec)
3679 std::cout << "Error: too few arguments.\n";
3683 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3684 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3685 if (aContext.IsNull())
3687 std::cout << "Error: no active view!\n";
3692 Standard_Integer aLast = theArgNb;
3693 const char* aName = theArgVec[0];
3695 Standard_Boolean isReset = Standard_False;
3696 Standard_Boolean isMove = Standard_False;
3701 if (!strcmp (aName, "reset"))
3703 isReset = Standard_True;
3705 else if (!strcmp (aName, "move"))
3709 std::cout << "Error: too few arguments.\n";
3713 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3715 Handle(AIS_InteractiveObject) anIObj;
3716 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3718 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3721 if (anIObj.IsNull())
3723 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3727 isMove = Standard_True;
3729 aTrsf = anIObj->Transformation();
3730 aLast = theArgNb - 1;
3732 else if (!strcmp (aName, "translate"))
3736 std::cout << "Error: too few arguments.\n";
3739 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3740 Draw::Atof (theArgVec[theArgNb - 2]),
3741 Draw::Atof (theArgVec[theArgNb - 1])));
3742 aLast = theArgNb - 3;
3744 else if (!strcmp (aName, "rotate"))
3748 std::cout << "Error: too few arguments.\n";
3753 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3754 Draw::Atof (theArgVec[theArgNb - 6]),
3755 Draw::Atof (theArgVec[theArgNb - 5])),
3756 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3757 Draw::Atof (theArgVec[theArgNb - 3]),
3758 Draw::Atof (theArgVec[theArgNb - 2]))),
3759 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3761 aLast = theArgNb - 7;
3763 else if (!strcmp (aName, "mirror"))
3767 std::cout << "Error: too few arguments.\n";
3771 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3772 Draw::Atof(theArgVec[theArgNb - 5]),
3773 Draw::Atof(theArgVec[theArgNb - 4])),
3774 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3775 Draw::Atof(theArgVec[theArgNb - 2]),
3776 Draw::Atof(theArgVec[theArgNb - 1]))));
3777 aLast = theArgNb - 6;
3779 else if (!strcmp (aName, "scale"))
3783 std::cout << "Error: too few arguments.\n";
3787 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3788 Draw::Atof(theArgVec[theArgNb - 3]),
3789 Draw::Atof(theArgVec[theArgNb - 2])),
3790 Draw::Atof(theArgVec[theArgNb - 1]));
3791 aLast = theArgNb - 4;
3794 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3797 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3798 Handle(AIS_InteractiveObject) anIObj;
3799 if (aMap.IsBound2 (theArgVec[anIdx]))
3801 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3803 if (anIObj.IsNull())
3805 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3811 // aTrsf already identity
3815 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3819 aTrsf = anIObj->LocalTransformation() * aTrsf;
3822 TopLoc_Location aLocation (aTrsf);
3823 aContext->SetLocation (anIObj, aLocation);
3829 //===============================================================================================
3830 //function : VConnect
3831 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3832 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
3833 //===============================================================================================
3835 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3836 Standard_Integer argc,
3840 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3841 if (aContext.IsNull())
3843 std::cout << "vconnect error : call vinit before\n";
3844 return 1; // TCL_ERROR
3849 std::cout << "vconnect error: expect at least 5 arguments\n";
3850 return 1; // TCL_ERROR
3854 Standard_Integer anArgIter = 1;
3855 TCollection_AsciiString aName (argv[anArgIter++]);
3856 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
3857 TCollection_AsciiString aColorString (argv[argc-1]);
3858 Standard_CString aColorName = "";
3859 Standard_Boolean hasColor = Standard_False;
3860 if (aColorString.Search ("color=") != -1)
3862 hasColor = Standard_True;
3863 aColorString.Remove (1, 6);
3864 aColorName = aColorString.ToCString();
3866 Handle(AIS_InteractiveObject) anObject;
3868 // AIS_MultipleConnectedInteractive
3869 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3870 for (Standard_Integer i = 5; i < aNbShapes; ++i)
3872 TCollection_AsciiString anOriginObjectName (argv[i]);
3873 if (aName.IsEqual (anOriginObjectName))
3875 std::cout << "vconnect error: equal names for connected objects\n";
3878 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3880 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3881 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3882 if (anObject.IsNull())
3884 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3890 Standard_CString aName = anOriginObjectName.ToCString();
3891 TopoDS_Shape aTDShape = DBRep::Get (aName);
3892 if (aTDShape.IsNull())
3894 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3897 anObject = new AIS_Shape (aTDShape);
3898 aContext->Load (anObject);
3899 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3902 if (anOriginObject.IsNull())
3904 anOriginObject = new AIS_MultipleConnectedInteractive();
3907 anOriginObject->Connect (anObject);
3909 if (anOriginObject.IsNull())
3911 std::cout << "vconect error : can't connect input objects\n";
3912 return 1; // TCL_ERROR
3915 // Get location data
3916 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3917 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3918 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3920 // Create transformation
3921 gp_Vec aTranslation (aXo, aYo, aZo);
3924 aTrsf.SetTranslationPart (aTranslation);
3925 TopLoc_Location aLocation (aTrsf);
3927 anOriginObject->SetLocalTransformation (aTrsf);
3929 // Check if there is another object with given name
3930 // and remove it from context
3931 if(GetMapOfAIS().IsBound2(aName))
3933 Handle(AIS_InteractiveObject) anObj =
3934 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3935 TheAISContext()->Remove(anObj, Standard_False);
3936 GetMapOfAIS().UnBind2(aName);
3939 // Bind connected object to its name
3940 GetMapOfAIS().Bind (anOriginObject, aName);
3942 // Display connected object
3943 TheAISContext()->Display (anOriginObject);
3948 //===============================================================================================
3949 //function : VConnectTo
3950 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3951 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
3952 //===============================================================================================
3954 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3955 Standard_Integer argc,
3959 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3960 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3961 if (aContext.IsNull())
3963 std::cout << "vconnect error : call vinit before\n";
3964 return 1; // TCL_ERROR
3967 if (argc != 6 && argc != 7)
3969 std::cout << "vconnect error: expect at least 5 arguments\n";
3970 return 1; // TCL_ERROR
3974 Standard_Integer anArgIter = 1;
3975 TCollection_AsciiString aName (argv[anArgIter++]);
3976 Handle(AIS_InteractiveObject) anOriginObject;
3978 TCollection_AsciiString anOriginObjectName(argv[5]);
3979 if (aName.IsEqual (anOriginObjectName))
3981 std::cout << "vconnect error: equal names for connected objects\n";
3982 return 1; // TCL_ERROR
3984 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3986 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3987 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3988 if (anOriginObject.IsNull())
3990 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3991 return 1; // TCL_ERROR
3996 Standard_CString aName = anOriginObjectName.ToCString();
3997 TopoDS_Shape aTDShape = DBRep::Get (aName);
3998 if (aTDShape.IsNull())
4000 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4001 return 1; // TCL_ERROR
4003 anOriginObject = new AIS_Shape (aTDShape);
4004 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4007 // Get location data
4008 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4009 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4010 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4012 // Create transformation
4013 gp_Vec aTranslation (aXo, aYo, aZo);
4016 aTrsf.SetTranslationPart (aTranslation);
4018 Handle(AIS_ConnectedInteractive) aConnected;
4020 aConnected = new AIS_ConnectedInteractive();
4022 aConnected->Connect (anOriginObject, aTrsf);
4024 // Check if there is another object with given name
4025 // and remove it from context
4026 if(GetMapOfAIS().IsBound2(aName))
4028 Handle(AIS_InteractiveObject) anObj =
4029 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
4030 TheAISContext()->Remove(anObj, Standard_False);
4031 GetMapOfAIS().UnBind2(aName);
4034 // Bind connected object to its name
4035 GetMapOfAIS().Bind (aConnected, aName);
4039 TCollection_AsciiString anArg = argv[6];
4041 if (anArg == "-nodisplay")
4044 if (!anUpdateTool.parseRedrawMode (anArg))
4046 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4050 // Display connected object
4051 TheAISContext()->Display (aConnected, Standard_False);
4056 //=======================================================================
4057 //function : VDisconnect
4059 //=======================================================================
4060 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4061 Standard_Integer argc,
4064 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4065 if (aContext.IsNull())
4067 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4073 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
4077 TCollection_AsciiString aName (argv[1]);
4078 TCollection_AsciiString anObject (argv[2]);
4079 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4082 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4083 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4084 if (!aMap.IsBound2 (aName) )
4086 std::cout << "Use 'vdisplay' before" << "\n";
4090 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4091 if (anAssembly.IsNull())
4093 di << "Not an assembly" << "\n";
4097 Handle(AIS_InteractiveObject) anIObj;
4098 if (!aMap.IsBound2 (anObject))
4100 // try to interpret second argument as child number
4101 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4103 Standard_Integer aCounter = 1;
4104 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4106 if (aCounter == anObjectNumber)
4108 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4116 std::cout << "Use 'vdisplay' before" << "\n";
4121 // if object was found by name
4122 if (anIObj.IsNull())
4124 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4127 aContext->Disconnect (anAssembly, anIObj);
4128 aContext->UpdateCurrentViewer();
4133 //=======================================================================
4134 //function : VAddConnected
4136 //=======================================================================
4137 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4138 Standard_Integer argc,
4141 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4142 if (aContext.IsNull())
4144 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4150 std::cout << argv[0] << " error: expect 5 arguments\n";
4154 TCollection_AsciiString aName (argv[1]);
4155 TCollection_AsciiString anObject (argv[5]);
4156 Standard_Real aX = Draw::Atof (argv[2]);
4157 Standard_Real aY = Draw::Atof (argv[3]);
4158 Standard_Real aZ = Draw::Atof (argv[4]);
4161 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4162 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4163 if (!aMap.IsBound2 (aName) )
4165 std::cout << "Use 'vdisplay' before" << "\n";
4169 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4170 if (anAssembly.IsNull())
4172 di << "Not an assembly" << "\n";
4176 Handle(AIS_InteractiveObject) anIObj;
4177 if (!aMap.IsBound2 (anObject))
4179 std::cout << "Use 'vdisplay' before" << "\n";
4183 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4186 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4188 anAssembly->Connect (anIObj, aTrsf);
4189 TheAISContext()->Display (anAssembly);
4190 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4191 aContext->UpdateCurrentViewer();
4196 //=======================================================================
4197 //function : VListConnected
4199 //=======================================================================
4200 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4201 Standard_Integer argc,
4204 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4205 if (aContext.IsNull())
4207 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4213 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
4217 TCollection_AsciiString aName (argv[1]);
4220 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4221 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4222 if (!aMap.IsBound2 (aName) )
4224 std::cout << "Use 'vdisplay' before" << "\n";
4228 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4229 if (anAssembly.IsNull())
4231 std::cout << "Not an assembly" << "\n";
4235 std::cout << "Children of " << aName << ":\n";
4237 Standard_Integer aCounter = 1;
4238 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4240 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4242 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
4243 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4246 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4248 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4249 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4251 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4253 std::cout << std::endl;
4263 //! Checks if theMode is already turned on for theObj.
4264 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4265 const Handle(AIS_InteractiveObject)& theObj,
4266 const Standard_Integer theMode)
4268 TColStd_ListOfInteger anActiveModes;
4269 theAISContext->ActivatedModes (theObj, anActiveModes);
4270 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4272 if (aModeIt.Value() == theMode)
4274 return Standard_True;
4277 return Standard_False;
4281 //===============================================================================================
4282 //function : VSetSelectionMode
4283 //purpose : Sets input selection mode for input object or for all displayed objects
4284 //Draw arg : vselmode [object] mode On/Off (1/0)
4285 //===============================================================================================
4286 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4287 Standard_Integer theArgc,
4288 const char** theArgv)
4291 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4292 if (anAISContext.IsNull())
4294 std::cerr << "Call vinit before!" << std::endl;
4298 // Check the arguments
4299 if (theArgc < 3 && theArgc > 5)
4301 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4302 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
4306 TCollection_AsciiString aLastArg (theArgv[theArgc - 1]);
4307 aLastArg.LowerCase();
4308 Standard_Boolean isToOpenLocalCtx = aLastArg == "-local";
4310 // get objects to change selection mode
4311 AIS_ListOfInteractive aTargetIOs;
4312 Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc;
4315 anAISContext->DisplayedObjects (aTargetIOs);
4319 // Check if there is an object with given name in context
4320 const TCollection_AsciiString aNameIO (theArgv[1]);
4321 if (GetMapOfAIS().IsBound2 (aNameIO))
4323 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4326 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
4329 aTargetIOs.Append (anIO);
4333 const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]);
4334 const Standard_Boolean toTurnOn = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]);
4335 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4337 anAISContext->CloseLocalContext();
4340 if (aSelectionMode == 0)
4344 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4346 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4347 TColStd_ListOfInteger anActiveModes;
4348 anAISContext->ActivatedModes (anIO, anActiveModes);
4349 if (!anActiveModes.IsEmpty())
4351 anAISContext->Deactivate (anIO);
4353 if (!InList (anAISContext, anIO, aSelectionMode))
4355 anAISContext->Activate (anIO);
4361 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4363 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4364 if (InList (anAISContext, anIO, aSelectionMode))
4366 anAISContext->Deactivate (anIO);
4372 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
4374 if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx)
4376 anAISContext->OpenLocalContext (Standard_False);
4379 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4381 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4382 if (InList (anAISContext, anIO, 0))
4384 anAISContext->Deactivate (anIO, 0);
4386 if (!InList (anAISContext, anIO, aSelectionMode))
4388 anAISContext->Load (anIO, -1, Standard_True);
4389 anAISContext->Activate (anIO, aSelectionMode);
4394 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4396 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4398 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4399 if (InList (anAISContext, anIO, aSelectionMode))
4401 anAISContext->Deactivate (anIO, aSelectionMode);
4409 //===============================================================================================
4410 //function : VSelectionNext
4412 //===============================================================================================
4413 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4414 Standard_Integer /*theArgsNb*/,
4415 const char** /*theArgVec*/)
4418 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4419 Handle(V3d_View) aView = ViewerTest::CurrentView();
4421 if (anAISContext.IsNull())
4423 std::cerr << "Call vinit before!" << std::endl;
4427 anAISContext->HilightNextDetected(aView);
4431 //===============================================================================================
4432 //function : VSelectionPrevious
4434 //===============================================================================================
4435 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4436 Standard_Integer /*theArgsNb*/,
4437 const char** /*theArgVec*/)
4440 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4441 Handle(V3d_View) aView = ViewerTest::CurrentView();
4443 if (anAISContext.IsNull())
4445 std::cerr << "Call vinit before!" << std::endl;
4449 anAISContext->HilightPreviousDetected(aView);
4454 //==========================================================================
4456 //purpose : creates Triangle based on AIS_InteractiveObject.
4457 // This class was implemented for testing Select3D_SensitiveTriangle
4458 //===========================================================================
4460 class Triangle: public AIS_InteractiveObject
4464 DEFINE_STANDARD_RTTI(Triangle, AIS_InteractiveObject);
4465 Triangle (const gp_Pnt& theP1,
4466 const gp_Pnt& theP2,
4467 const gp_Pnt& theP3);
4469 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4470 const Handle(Prs3d_Presentation)& thePresentation,
4471 const Standard_Integer theMode);
4473 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4474 const Standard_Integer theMode);
4482 Triangle::Triangle (const gp_Pnt& theP1,
4483 const gp_Pnt& theP2,
4484 const gp_Pnt& theP3)
4491 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4492 const Handle(Prs3d_Presentation)& thePresentation,
4493 const Standard_Integer /*theMode*/)
4495 thePresentation->Clear();
4497 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4498 anEdgeMaker2(myPoint2, myPoint3),
4499 anEdgeMaker3(myPoint3, myPoint1);
4501 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4502 anEdge2 = anEdgeMaker2.Edge(),
4503 anEdge3 = anEdgeMaker3.Edge();
4504 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4507 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4508 TopoDS_Wire aWire = aWireMaker.Wire();
4509 if(aWire.IsNull()) return;
4511 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4512 TopoDS_Face aFace = aFaceMaker.Face();
4513 if(aFace.IsNull()) return;
4515 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4518 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
4519 const Standard_Integer /*theMode*/)
4521 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4522 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4523 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4524 theSelection->Add(aSensTriangle);
4527 //===========================================================================
4528 //function : VTriangle
4529 //Draw arg : vtriangle Name PointName PointName PointName
4530 //purpose : creates and displays Triangle
4531 //===========================================================================
4534 //purpose : checks if the object with theName is AIS_Point,
4535 // if yes initialize thePoint from MapOfAIS
4536 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4537 Handle(AIS_Point)& thePoint)
4539 Handle(AIS_InteractiveObject) anObject =
4540 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4541 if(anObject.IsNull() ||
4542 anObject->Type() != AIS_KOI_Datum ||
4543 anObject->Signature() != 1)
4545 return Standard_False;
4547 thePoint = Handle(AIS_Point)::DownCast(anObject);
4548 if(thePoint.IsNull())
4549 return Standard_False;
4550 return Standard_True;
4554 //purpose: checks if thePoint1 is equal to thePoint2
4555 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4556 const Handle(Geom_CartesianPoint)& thePoint2)
4558 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4559 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4560 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4562 return Standard_True;
4564 return Standard_False;
4567 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4568 Standard_Integer argc,
4574 std::cout<<"vtriangle error: expects 4 argumnets\n";
4575 return 1; // TCL_ERROR
4578 TheAISContext()->CloseAllContexts();
4580 // Get and check values
4581 TCollection_AsciiString aName(argv[1]);
4583 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4584 if (!IsPoint(argv[2], aPoint1))
4586 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4587 return 1; // TCL_ERROR
4589 if (!IsPoint(argv[3], aPoint2))
4591 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4592 return 1; // TCL_ERROR
4594 if (!IsPoint(argv[4], aPoint3))
4596 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4597 return 1; // TCL_ERROR
4600 // Check that points are different
4601 Handle(Geom_CartesianPoint) aCartPoint1 =
4602 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4603 Handle(Geom_CartesianPoint) aCartPoint2 =
4604 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4605 // Test aPoint1 = aPoint2
4606 if (IsMatch(aCartPoint1, aCartPoint2))
4608 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4609 return 1; // TCL_ERROR
4611 // Test aPoint2 = aPoint3
4612 Handle(Geom_CartesianPoint) aCartPoint3 =
4613 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4614 if (IsMatch(aCartPoint2, aCartPoint3))
4616 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4617 return 1; // TCL_ERROR
4619 // Test aPoint3 = aPoint1
4620 if (IsMatch(aCartPoint1, aCartPoint3))
4622 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4623 return 1; // TCL_ERROR
4627 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4629 aCartPoint3->Pnt());
4631 // Check if there is an object with given name
4632 // and remove it from context
4633 if (GetMapOfAIS().IsBound2(aName))
4635 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4636 Handle(AIS_InteractiveObject) anInterObj =
4637 Handle(AIS_InteractiveObject)::DownCast(anObj);
4638 TheAISContext()->Remove(anInterObj, Standard_False);
4639 GetMapOfAIS().UnBind2(aName);
4642 // Bind triangle to its name
4643 GetMapOfAIS().Bind(aTriangle, aName);
4646 TheAISContext()->Display(aTriangle);
4650 //class : SegmentObject
4651 //purpose: creates segment based on AIS_InteractiveObject.
4652 // This class was implemented for testing Select3D_SensitiveCurve
4654 class SegmentObject: public AIS_InteractiveObject
4658 DEFINE_STANDARD_RTTI(SegmentObject, AIS_InteractiveObject);
4659 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4661 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4662 const Handle(Prs3d_Presentation)& thePresentation,
4663 const Standard_Integer theMode);
4665 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4666 const Standard_Integer theMode);
4673 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4679 void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4680 const Handle(Prs3d_Presentation) &thePresentation,
4681 const Standard_Integer /*theMode*/)
4683 thePresentation->Clear();
4684 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4685 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4686 if (anEdge.IsNull())
4688 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4689 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4692 void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
4693 const Standard_Integer /*theMode*/)
4695 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4696 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4697 anArray->SetValue(1, myPoint1);
4698 anArray->SetValue(2, myPoint2);
4699 Handle(Select3D_SensitiveCurve) aSensCurve =
4700 new Select3D_SensitiveCurve(anOwner, anArray);
4701 theSelection->Add(aSensCurve);
4704 //=======================================================================
4705 //function : VSegment
4706 //Draw args : vsegment Name PointName PointName
4707 //purpose : creates and displays Segment
4708 //=======================================================================
4709 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4710 Standard_Integer argc,
4716 std::cout<<"vsegment error: expects 3 arguments\n";
4717 return 1; // TCL_ERROR
4720 TheAISContext()->CloseAllContexts();
4722 // Get and check arguments
4723 TCollection_AsciiString aName(argv[1]);
4724 Handle(AIS_Point) aPoint1, aPoint2;
4725 if (!IsPoint(argv[2], aPoint1))
4727 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4728 return 1; // TCL_ERROR
4730 if (!IsPoint(argv[3], aPoint2))
4732 std::cout<<"vsegment error: the 3d argument should be a point\n";
4733 return 1; // TCL_ERROR
4735 //Check that points are different
4736 Handle(Geom_CartesianPoint) aCartPoint1 =
4737 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4738 Handle(Geom_CartesianPoint) aCartPoint2 =
4739 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4740 if(IsMatch(aCartPoint1, aCartPoint2))
4742 std::cout<<"vsegment error: equal points\n";
4743 return 1; // TCL_ERROR
4747 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4748 // Check if there is an object with given name
4749 // and remove it from context
4750 if (GetMapOfAIS().IsBound2(aName))
4752 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4753 Handle(AIS_InteractiveObject) anInterObj =
4754 Handle(AIS_InteractiveObject)::DownCast(anObj);
4755 TheAISContext()->Remove(anInterObj, Standard_False);
4756 GetMapOfAIS().UnBind2(aName);
4759 // Bind segment to its name
4760 GetMapOfAIS().Bind(aSegment, aName);
4763 TheAISContext()->Display(aSegment);
4767 //=======================================================================
4768 //function : VObjZLayer
4769 //purpose : Set or get z layer id for presentable object
4770 //=======================================================================
4772 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4773 Standard_Integer argc,
4776 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4777 if (aContext.IsNull())
4779 di << argv[0] << "Call 'vinit' before!\n";
4784 TCollection_AsciiString aOperation;
4786 aOperation = TCollection_AsciiString (argv [1]);
4788 // check for correct arguments
4789 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4790 !(argc == 3 && aOperation.IsEqual ("get")))
4792 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4793 di << " set - set layer id for interactive object, layerid - z layer id\n";
4794 di << " get - get layer id of interactive object\n";
4795 di << " argument layerid should be passed for set operation only\n";
4800 TCollection_AsciiString aName (argv[2]);
4801 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4802 if (!aMap.IsBound2 (aName))
4804 di << "Use 'vdisplay' before" << "\n";
4808 // find interactive object
4809 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4810 Handle(AIS_InteractiveObject) anInterObj =
4811 Handle(AIS_InteractiveObject)::DownCast (anObj);
4812 if (anInterObj.IsNull())
4814 di << "Not an AIS interactive object!\n";
4818 // process operation
4819 if (aOperation.IsEqual ("set"))
4821 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4822 aContext->SetZLayer (anInterObj, aLayerId);
4824 else if (aOperation.IsEqual ("get"))
4826 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4832 //=======================================================================
4833 //function : VPolygonOffset
4834 //purpose : Set or get polygon offset parameters
4835 //=======================================================================
4836 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4837 Standard_Integer argc,
4840 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4841 if (aContext.IsNull())
4843 std::cout << argv[0] << " Call 'vinit' before!\n";
4847 if (argc > 2 && argc != 5)
4849 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4850 "without arguments prints the default values" << std::endl;
4855 Handle(AIS_InteractiveObject) anInterObj;
4858 TCollection_AsciiString aName (argv[1]);
4859 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4860 if (!aMap.IsBound2 (aName))
4862 std::cout << "Use 'vdisplay' before" << std::endl;
4866 // find interactive object
4867 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4868 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4869 if (anInterObj.IsNull())
4871 std::cout << "Not an AIS interactive object!" << std::endl;
4876 Standard_Integer aMode;
4877 Standard_ShortReal aFactor, aUnits;
4880 aMode = Draw::Atoi(argv[2]);
4881 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4882 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4884 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4885 aContext->UpdateCurrentViewer();
4890 if (anInterObj->HasPolygonOffsets())
4892 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4893 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4894 std::cout << "\tMode: " << aMode << std::endl;
4895 std::cout << "\tFactor: " << aFactor << std::endl;
4896 std::cout << "\tUnits: " << aUnits << std::endl;
4901 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4905 std::cout << "Default polygon offset parameters:" << std::endl;
4906 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4907 std::cout << "\tMode: " << aMode << std::endl;
4908 std::cout << "\tFactor: " << aFactor << std::endl;
4909 std::cout << "\tUnits: " << aUnits << std::endl;
4914 //=======================================================================
4915 //function : VShowFaceBoundaries
4916 //purpose : Set face boundaries drawing on/off for ais object
4917 //=======================================================================
4918 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4919 Standard_Integer argc,
4922 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4923 if (aContext.IsNull ())
4925 std::cout << argv[0] << " Call 'vinit' before!\n";
4929 if ((argc != 3 && argc < 6) || argc > 8)
4931 std::cout << "Usage :\n " << argv[0]
4932 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4933 << " ObjectName - name of AIS interactive object. \n"
4934 << " if ObjectName = \"\", then set as default\n"
4935 << " settings for all newly displayed objects\n"
4936 << " isOn - flag indicating whether the boundaries\n"
4937 << " should be turned on or off (can be set\n"
4938 << " to 0 (off) or 1 (on)).\n"
4939 << " R, G, B - red, green and blue components of boundary\n"
4940 << " color in range (0 - 255).\n"
4941 << " (default is (0, 0, 0)\n"
4942 << " LineWidth - line width\n"
4943 << " (default is 1)\n"
4944 << " LineStyle - line fill style :\n"
4949 << " (default is solid)";
4953 TCollection_AsciiString aName (argv[1]);
4955 Quantity_Parameter aRed = 0.0;
4956 Quantity_Parameter aGreen = 0.0;
4957 Quantity_Parameter aBlue = 0.0;
4958 Standard_Real aWidth = 1.0;
4959 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4962 Handle(AIS_InteractiveObject) anInterObj;
4964 // if name is empty - apply attributes for default aspect
4965 if (!aName.IsEmpty ())
4967 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4968 if (!aMap.IsBound2 (aName))
4970 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4974 // find interactive object
4975 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4976 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4977 if (anInterObj.IsNull ())
4979 std::cout << "Not an AIS interactive object!" << std::endl;
4984 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4985 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4987 // turn boundaries on/off
4988 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
4989 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4991 // set boundary line color
4995 aRed = Draw::Atof (argv[3])/255.;
4996 aGreen = Draw::Atof (argv[4])/255.;
4997 aBlue = Draw::Atof (argv[5])/255.;
5003 aWidth = (Standard_Real)Draw::Atof (argv[6]);
5006 // select appropriate line type
5009 switch (Draw::Atoi (argv[7]))
5011 case 1: aLineType = Aspect_TOL_DASH; break;
5012 case 2: aLineType = Aspect_TOL_DOT; break;
5013 case 3: aLineType = Aspect_TOL_DOTDASH; break;
5015 aLineType = Aspect_TOL_SOLID;
5019 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
5021 Handle(Prs3d_LineAspect) aBoundaryAspect =
5022 new Prs3d_LineAspect (aColor, aLineType, aWidth);
5024 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
5026 TheAISContext()->Redisplay (anInterObj);
5031 // This class is used for testing markers.
5033 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5038 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5039 const Standard_Integer& thePointsOnSide,
5040 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5042 myStartPoint = theStartPoint;
5043 myPointsOnSide = thePointsOnSide;
5044 myMarkerAspect = theMarkerAspect;
5047 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
5051 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5052 const Handle(Prs3d_Presentation)& aPresentation,
5053 const Standard_Integer aMode);
5055 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5056 const Standard_Integer /*theMode*/);
5060 gp_XYZ myStartPoint;
5061 Standard_Integer myPointsOnSide;
5062 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5066 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5067 const Handle(Prs3d_Presentation)& aPresentation,
5068 const Standard_Integer /*aMode*/)
5070 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5071 if (myPointsOnSide == 1)
5073 anArray->AddVertex (myStartPoint);
5077 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5079 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5081 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5083 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5084 anArray->SetVertexColor (anArray->VertexNumber(),
5087 k / myPointsOnSide);
5093 aPresentation->Clear();
5094 if (!myMarkerAspect.IsNull())
5096 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5098 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5101 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5102 const Standard_Integer /*theMode*/)
5104 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5106 if (myPointsOnSide == 1)
5108 gp_Pnt aPoint (myStartPoint);
5109 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5110 theSelection->Add (aSensetivePoint);
5114 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5116 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5118 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5120 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5121 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5122 theSelection->Add (aSensetivePoint);
5128 //=======================================================================
5129 //function : VMarkersTest
5130 //purpose : Draws an array of markers for testing purposes.
5131 //=======================================================================
5132 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5133 Standard_Integer theArgNb,
5134 const char** theArgVec)
5136 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5137 if (aContext.IsNull())
5139 std::cerr << "Call 'vinit' before!\n";
5145 std::cerr << "Usage :\n " << theArgVec[0]
5146 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5150 Standard_Integer anArgIter = 1;
5152 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5153 TCollection_AsciiString aFileName;
5154 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5155 Atof (theArgVec[anArgIter + 1]),
5156 Atof (theArgVec[anArgIter + 2]));
5159 Standard_Integer aPointsOnSide = 10;
5160 Standard_Integer aMarkerType = -1;
5161 Standard_Real aScale = 1.0;
5162 for (; anArgIter < theArgNb; ++anArgIter)
5164 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5165 if (anArg.Search ("PointsOnSide=") > -1)
5167 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5169 else if (anArg.Search ("MarkerType=") > -1)
5171 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5173 else if (anArg.Search ("Scale=") > -1)
5175 aScale = anArg.Token ("=", 2).RealValue();
5177 else if (anArg.Search ("FileName=") > -1)
5179 aFileName = anArg.Token ("=", 2);
5183 std::cerr << "Wrong argument: " << anArg << "\n";
5188 Handle(Graphic3d_AspectMarker3d) anAspect;
5189 Handle(Image_AlienPixMap) anImage;
5190 Quantity_Color aColor (Quantity_NOC_GREEN1);
5191 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5192 && !aFileName.IsEmpty())
5194 anImage = new Image_AlienPixMap();
5195 if (!anImage->Load (aFileName))
5197 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5200 if (anImage->Format() == Image_PixMap::ImgGray)
5202 anImage->SetFormat (Image_PixMap::ImgAlpha);
5204 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5206 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5208 anAspect = new Graphic3d_AspectMarker3d (anImage);
5212 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5215 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5216 VDisplayAISObject (aName, aMarkersArray);
5221 //! Auxiliary function to parse font aspect style argument
5222 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5223 Font_FontAspect& theAspect)
5225 if (theArg == "regular"
5226 || *theArg.ToCString() == 'r')
5228 theAspect = Font_FA_Regular;
5229 return Standard_True;
5231 else if (theArg == "bolditalic")
5233 theAspect = Font_FA_BoldItalic;
5234 return Standard_True;
5236 else if (theArg == "bold"
5237 || *theArg.ToCString() == 'b')
5239 theAspect = Font_FA_Bold;
5240 return Standard_True;
5242 else if (theArg == "italic"
5243 || *theArg.ToCString() == 'i')
5245 theAspect = Font_FA_Italic;
5246 return Standard_True;
5248 return Standard_False;
5251 //! Auxiliary function
5252 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5256 case Font_FA_Regular: return "regular";
5257 case Font_FA_BoldItalic: return "bolditalic";
5258 case Font_FA_Bold: return "bold";
5259 case Font_FA_Italic: return "italic";
5260 default: return "undefined";
5264 //=======================================================================
5265 //function : TextToBrep
5266 //purpose : Tool for conversion text to occt-shapes
5267 //=======================================================================
5269 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5270 Standard_Integer theArgNb,
5271 const char** theArgVec)
5276 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5280 Standard_Integer anArgIter = 1;
5281 Standard_CString aResName = theArgVec[anArgIter++];
5282 Standard_CString aText = theArgVec[anArgIter++];
5283 Standard_CString aFontName = theArgVec[anArgIter++];
5284 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
5286 Font_BRepFont aFont;
5287 Font_FontAspect aFontAspect = Font_FA_Regular;
5288 Standard_Boolean isCompositeCurve = Standard_False;
5289 gp_Ax3 aPenAx3 (gp::XOY());
5291 while (anArgIter < theArgNb)
5293 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
5294 TCollection_AsciiString anArgCase (anArg);
5295 anArgCase.LowerCase();
5296 if (anArgCase.Search ("x=") > -1)
5298 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
5300 else if (anArgCase.Search ("y=") > -1)
5302 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
5304 else if (anArgCase.Search ("z=") > -1)
5306 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
5308 else if (anArgCase.Search ("composite=") > -1)
5310 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
5312 else if (parseFontStyle (anArgCase, aFontAspect))
5318 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5322 aFont.SetCompositeCurveMode (isCompositeCurve);
5323 if (!aFont.Init (aFontName, aFontAspect, aSize))
5325 std::cerr << "Font initialization error\n";
5329 aPenAx3.SetLocation (aPenLoc);
5330 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
5334 //=======================================================================
5336 //purpose : Font management
5337 //=======================================================================
5339 static int VFont (Draw_Interpretor& theDI,
5340 Standard_Integer theArgNb,
5341 const char** theArgVec)
5343 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5346 // just print the list of available fonts
5347 Standard_Boolean isFirst = Standard_True;
5348 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5349 anIter.More(); anIter.Next())
5351 const Handle(Font_SystemFont)& aFont = anIter.Value();
5357 theDI << aFont->FontName()->String()
5358 << " " << fontStyleString (aFont->FontAspect())
5359 << " " << aFont->FontPath()->String();
5360 isFirst = Standard_False;
5365 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5367 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5368 TCollection_AsciiString anArgCase (anArg);
5369 anArgCase.LowerCase();
5370 if (anArgCase == "find")
5372 if (++anArgIter >= theArgNb)
5374 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5378 Standard_CString aFontName = theArgVec[anArgIter];
5379 Font_FontAspect aFontAspect = Font_FA_Undefined;
5380 if (++anArgIter < theArgNb)
5382 anArgCase = theArgVec[anArgIter];
5383 anArgCase.LowerCase();
5384 if (!parseFontStyle (anArgCase, aFontAspect))
5389 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5392 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5396 theDI << aFont->FontName()->String()
5397 << " " << fontStyleString (aFont->FontAspect())
5398 << " " << aFont->FontPath()->String();
5400 else if (anArgCase == "add"
5401 || anArgCase == "register")
5403 if (++anArgIter >= theArgNb)
5405 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5408 Standard_CString aFontPath = theArgVec[anArgIter];
5409 Standard_CString aFontName = NULL;
5410 Font_FontAspect aFontAspect = Font_FA_Undefined;
5411 if (++anArgIter < theArgNb)
5413 if (!parseFontStyle (anArgCase, aFontAspect))
5415 aFontName = theArgVec[anArgIter];
5417 if (++anArgIter < theArgNb)
5419 anArgCase = theArgVec[anArgIter];
5420 anArgCase.LowerCase();
5421 if (!parseFontStyle (anArgCase, aFontAspect))
5428 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5431 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5435 if (aFontAspect != Font_FA_Undefined
5436 || aFontName != NULL)
5438 if (aFontAspect == Font_FA_Undefined)
5440 aFontAspect = aFont->FontAspect();
5442 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5443 if (aFontName != NULL)
5445 aName = new TCollection_HAsciiString (aFontName);
5447 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5450 aMgr->RegisterFont (aFont, Standard_True);
5451 theDI << aFont->FontName()->String()
5452 << " " << fontStyleString (aFont->FontAspect())
5453 << " " << aFont->FontPath()->String();
5457 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5464 //=======================================================================
5465 //function : VSetEdgeType
5466 //purpose : Edges type management
5467 //=======================================================================
5469 static int VSetEdgeType (Draw_Interpretor& theDI,
5470 Standard_Integer theArgNum,
5471 const char** theArgs)
5473 if (theArgNum < 4 || theArgNum > 9)
5475 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5476 << theArgs[0] << "' for more information.\n";
5480 Standard_Boolean isForceRedisplay = Standard_False;
5483 TCollection_AsciiString aName(theArgs[1]);
5484 if (!GetMapOfAIS().IsBound2 (aName))
5486 theDI << theArgs[0] << " error: wrong object name.\n";
5490 Handle(AIS_InteractiveObject) anObject =
5491 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5493 // Enable trianle edge mode
5494 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5497 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5499 TCollection_AsciiString aParam ((theArgs[anIt]));
5500 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5502 if (aParam.IsEqual ("-type"))
5504 if (theArgNum <= anIt + 1)
5506 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5507 << aParam.ToCString() << "'.\n";
5511 TCollection_AsciiString aType = theArgs[++anIt];
5514 if (aType.IsEqual ("SOLID"))
5516 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5518 else if (aType.IsEqual ("DASH"))
5520 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5522 else if (aType.IsEqual ("DOT"))
5524 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5526 else if (aType.IsEqual ("DOTDASH"))
5528 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5532 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5537 else if (aParam.IsEqual ("-color"))
5539 if (theArgNum <= anIt + 3)
5541 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5542 << aParam.ToCString() << "'.\n";
5546 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5547 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5548 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5549 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5550 aG > 1 ? aG / 255.0 : aG,
5551 aB > 1 ? aB / 255.0 : aB,
5554 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5556 else if (aParam.IsEqual ("-force"))
5558 isForceRedisplay = Standard_True;
5562 theDI << theArgs[0] << " error: unknown parameter '"
5563 << aParam.ToCString() << "'.\n";
5569 // Update shape presentation as aspect parameters were changed
5570 if (isForceRedisplay)
5572 ViewerTest::GetAISContext()->Redisplay (anObject);
5576 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5580 ViewerTest::CurrentView()->Redraw();
5585 //=======================================================================
5586 //function : VUnsetEdgeType
5587 //purpose : Unsets edges visibility in shading mode
5588 //=======================================================================
5590 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5591 Standard_Integer theArgNum,
5592 const char** theArgs)
5594 if (theArgNum != 2 && theArgNum != 3)
5596 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5597 << theArgs[0] << "' for more information.\n";
5601 Standard_Boolean isForceRedisplay = Standard_False;
5604 TCollection_AsciiString aName (theArgs[1]);
5605 if (!GetMapOfAIS().IsBound2 (aName))
5607 theDI << theArgs[0] << " error: wrong object name.\n";
5611 Handle(AIS_InteractiveObject) anObject =
5612 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5614 // Enable trianle edge mode
5615 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5620 TCollection_AsciiString aParam ((theArgs[2]));
5621 if (aParam.IsEqual ("-force"))
5623 isForceRedisplay = Standard_True;
5627 theDI << theArgs[0] << " error: unknown parameter '"
5628 << aParam.ToCString() << "'.\n";
5633 // Update shape presentation as aspect parameters were changed
5634 if (isForceRedisplay)
5636 ViewerTest::GetAISContext()->Redisplay (anObject);
5640 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5644 ViewerTest::CurrentView()->Redraw();
5650 //=======================================================================
5651 //function : VVertexMode
5652 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5653 //=======================================================================
5655 static int VVertexMode (Draw_Interpretor& theDI,
5656 Standard_Integer theArgNum,
5657 const char** theArgs)
5659 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5660 if (aContext.IsNull())
5662 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5666 // No arguments --> print the current default vertex draw mode
5669 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5670 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5674 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5675 TCollection_AsciiString aParam (theArgs[1]);
5676 if (aParam == "-set")
5680 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5681 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5685 TCollection_AsciiString aModeStr (theArgs[2]);
5686 Prs3d_VertexDrawMode aNewMode =
5687 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5688 (aModeStr == "all" ? Prs3d_VDM_All :
5689 Prs3d_VDM_Inherited);
5691 Standard_Boolean aRedrawNeeded = Standard_False;
5692 AIS_ListOfInteractive anObjs;
5694 // No object(s) specified -> use all displayed
5697 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5698 aContext->DisplayedObjects (anObjs);
5699 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5700 aRedrawNeeded = Standard_True;
5703 Handle(AIS_InteractiveObject) anObject;
5704 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5706 TCollection_AsciiString aName (theArgs[aCount]);
5707 if (!GetMapOfAIS().IsBound2 (aName))
5709 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5712 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5713 anObjs.Append (anObject);
5716 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5718 anObject = anIt.Value();
5719 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5720 aContext->Redisplay (anObject, Standard_False);
5721 aRedrawNeeded = Standard_True;
5725 ViewerTest::CurrentView()->Redraw();
5732 std::cout << "Error: invalid number of arguments" << std::endl;
5733 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5737 // One argument (object name) --> print the current vertex draw mode for the object
5738 Handle(AIS_InteractiveObject) anObject =
5739 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5740 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5741 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5745 //=======================================================================
5746 //function : VPointCloud
5747 //purpose : Create interactive object for arbitary set of points.
5748 //=======================================================================
5749 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5750 Standard_Integer theArgNum,
5751 const char** theArgs)
5753 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5754 if (anAISContext.IsNull())
5756 std::cerr << "Error: no active view!\n";
5760 // command to execute
5763 CloudForShape, // generate point cloud for shape
5764 CloudSphere, // generate point cloud for generic sphere
5768 // count number of non-optional command arguments
5769 Command aCmd = Unknow;
5770 Standard_Integer aCmdArgs = 0;
5771 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5773 Standard_CString anArg = theArgs[anArgIter];
5774 TCollection_AsciiString aFlag (anArg);
5776 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5783 case 2 : aCmd = CloudForShape; break;
5784 case 7 : aCmd = CloudSphere; break;
5786 std::cout << "Error: wrong number of arguments! See usage:\n";
5787 theDI.PrintHelp (theArgs[0]);
5792 Standard_Boolean toRandColors = Standard_False;
5793 Standard_Boolean hasNormals = Standard_True;
5794 Standard_Boolean isSetArgNorm = Standard_False;
5795 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5797 Standard_CString anArg = theArgs[anArgIter];
5798 TCollection_AsciiString aFlag (anArg);
5800 if (aFlag == "-randcolors"
5801 || aFlag == "-randcolor")
5803 if (isSetArgNorm && hasNormals)
5805 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5808 toRandColors = Standard_True;
5809 hasNormals = Standard_False;
5811 else if (aFlag == "-normals"
5812 || aFlag == "-normal")
5816 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5819 isSetArgNorm = Standard_True;
5820 hasNormals = Standard_True;
5822 else if (aFlag == "-nonormals"
5823 || aFlag == "-nonormal")
5825 isSetArgNorm = Standard_True;
5826 hasNormals = Standard_False;
5830 Standard_CString aName = theArgs[1];
5832 // generate arbitrary set of points
5833 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5834 if (aCmd == CloudForShape)
5836 Standard_CString aShapeName = theArgs[2];
5837 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5839 if (aShape.IsNull())
5841 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5845 // calculate number of points
5846 TopLoc_Location aLocation;
5847 Standard_Integer aNbPoints = 0;
5848 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5850 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5851 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5852 if (!aTriangulation.IsNull())
5854 aNbPoints += aTriangulation->NbNodes();
5859 std::cout << "Error: shape should be triangulated!\n";
5863 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5864 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5866 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5867 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
5868 if (aTriangulation.IsNull())
5873 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5874 const gp_Trsf& aTrsf = aLocation.Transformation();
5876 // extract normals from nodes
5877 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5880 Poly_Connect aPolyConnect (aTriangulation);
5881 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
5884 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5886 gp_Pnt aPoint = aNodes (aNodeIter);
5887 if (!aLocation.IsIdentity())
5889 aPoint.Transform (aTrsf);
5892 aNormals (aNodeIter).Transform (aTrsf);
5896 // add vertex into array of points
5897 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5900 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5901 1.0, 0.5, Quantity_TOC_HLS);
5902 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5907 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5912 else if (aCmd == CloudSphere)
5914 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5915 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5916 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5917 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5918 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5920 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5921 aDistribution.LowerCase();
5922 if ( aDistribution != "surface" && aDistribution != "volume" )
5924 std::cout << "Error: wrong arguments! See usage:\n";
5925 theDI.PrintHelp (theArgs[0]);
5928 Standard_Boolean isSurface = aDistribution == "surface";
5930 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5932 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5933 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5935 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5936 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5937 Standard_Real aDistance = isSurface ?
5938 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5940 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5942 Cos (anAlpha) * Cos (aBeta));
5943 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5945 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5948 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5949 1.0, 0.5, Quantity_TOC_HLS);
5950 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5955 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5960 // set array of points in point cloud object
5961 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5962 aPointCloud->SetPoints (anArrayPoints);
5963 VDisplayAISObject (aName, aPointCloud);
5967 //=======================================================================
5968 //function : VPriority
5969 //purpose : Prints or sets the display priority for an object
5970 //=======================================================================
5972 static int VPriority (Draw_Interpretor& theDI,
5973 Standard_Integer theArgNum,
5974 const char** theArgs)
5976 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5977 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5978 if (aContext.IsNull())
5980 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5984 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5985 Standard_Integer aPriority = -1;
5986 Standard_Integer aNbArgs = theArgNum;
5987 if (aLastArg.IsIntegerValue())
5989 aPriority = aLastArg.IntegerValue();
5991 if (aPriority < 0 || aPriority > 10)
5993 std::cout << "Error: the specified display priority value '" << aLastArg
5994 << "' is outside the valid range [0..10]" << std::endl;
6000 anUpdateTool.Invalidate();
6005 std::cout << "Error: wrong number of arguments! See usage:\n";
6006 theDI.PrintHelp (theArgs[0]);
6010 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6012 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6017 TCollection_AsciiString aName (theArgs[anArgIter]);
6018 Handle(AIS_InteractiveObject) anIObj;
6019 if (GetMapOfAIS().IsBound2 (aName))
6021 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
6024 if (anIObj.IsNull())
6026 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
6032 theDI << aContext->DisplayPriority (anIObj) << " ";
6036 aContext->SetDisplayPriority (anIObj, aPriority);
6042 //=======================================================================
6043 //function : ObjectsCommands
6045 //=======================================================================
6047 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6049 const char *group ="AISObjects";
6050 theCommands.Add("vtrihedron",
6051 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
6052 __FILE__,VTrihedron,group);
6054 theCommands.Add("vtri2d",
6055 "vtri2d Name Selection in the viewer only ",
6056 __FILE__,VTrihedron2D ,group);
6058 theCommands.Add("vplanetri",
6059 "vplanetri Name Selection in the viewer only ",
6060 __FILE__,VPlaneTrihedron ,group);
6062 theCommands.Add("vsize",
6063 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
6064 __FILE__,VSize,group);
6066 theCommands.Add("vaxis",
6067 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
6068 __FILE__,VAxisBuilder,group);
6070 theCommands.Add("vaxispara",
6072 __FILE__,VAxisBuilder,group);
6074 theCommands.Add("vaxisortho",
6076 __FILE__,VAxisBuilder,group);
6078 theCommands.Add("vpoint",
6079 "vpoint PointName [Xa] [Ya] [Za] ",
6080 __FILE__,VPointBuilder,group);
6082 theCommands.Add("vplane",
6083 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
6084 __FILE__,VPlaneBuilder,group);
6086 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6087 " vchangeplane <plane_name>"
6088 " [x=center_x y=center_y z=center_z]"
6089 " [dx=dir_x dy=dir_y dz=dir_z]"
6090 " [sx=size_x sy=size_y]"
6092 " - changes parameters of the plane:\n"
6093 " - x y z - center\n"
6094 " - dx dy dz - normal\n"
6095 " - sx sy - plane sizes\n"
6096 " - noupdate - do not update/redisplay the plane in context\n"
6097 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6098 __FILE__, VChangePlane, group);
6100 theCommands.Add("vplanepara",
6101 "vplanepara PlaneName ",
6102 __FILE__,VPlaneBuilder,group);
6104 theCommands.Add("vplaneortho",
6105 "vplaneortho PlaneName ",
6106 __FILE__,VPlaneBuilder,group);
6108 theCommands.Add("vline",
6109 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
6110 __FILE__,VLineBuilder,group);
6112 theCommands.Add("vcircle",
6113 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
6114 __FILE__,VCircleBuilder,group);
6116 theCommands.Add ("vdrawtext",
6117 "vdrawtext name text"
6118 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6119 "\n\t\t: [-color {R G B|name}=yellow]"
6120 "\n\t\t: [-halign {left|center|right}=left]"
6121 "\n\t\t: [-valign {top|center|bottom}=bottom}]"
6122 "\n\t\t: [-angle angle=0]"
6123 "\n\t\t: [-zoom {0|1}=0]"
6124 "\n\t\t: [-height height=16]"
6125 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6126 "\n\t\t: [-font font=Times]"
6128 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6129 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6130 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6131 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6132 "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}"
6133 "\n\t\t: [-subcolor {R G B|name}=white]"
6134 "\n\t\t: [-noupdate]"
6135 "\n\t\t: Display text label at specified position.",
6136 __FILE__, VDrawText, group);
6138 theCommands.Add("vdrawsphere",
6139 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6140 __FILE__,VDrawSphere,group);
6142 theCommands.Add ("vsetlocation",
6143 "vsetlocation [-noupdate|-update] name x y z"
6144 "\n\t\t: Set new location for an interactive object.",
6145 __FILE__, VSetLocation, group);
6149 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6150 __FILE__, VComputeHLR, group);
6152 theCommands.Add("vdrawparray",
6153 "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id ]",
6154 __FILE__,VDrawPArray,group);
6156 theCommands.Add("vconnect",
6157 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
6158 " Makes an assembly of object instances located in point (Xo Yo Zo).",
6159 __FILE__, VConnect, group);
6161 theCommands.Add("vconnectto",
6162 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6163 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6164 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6165 __FILE__, VConnectTo,group);
6167 theCommands.Add("vdisconnect",
6168 "vdisconnect assembly_name (object_name | object_number | 'all')"
6169 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6170 __FILE__,VDisconnect,group);
6172 theCommands.Add("vaddconnected",
6173 "vaddconnected assembly_name object_name"
6174 "Adds object to assembly.",
6175 __FILE__,VAddConnected,group);
6177 theCommands.Add("vlistconnected",
6178 "vlistconnected assembly_name"
6179 "Lists objects in assembly.",
6180 __FILE__,VListConnected,group);
6183 theCommands.Add("vselmode",
6184 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6185 " switches selection mode for the determined object or\n"
6186 " for all objects in context.\n"
6187 " mode_number is non-negative integer that has different\n"
6188 " meaning for different interactive object classes.\n"
6189 " For shapes the following mode_number values are allowed:\n"
6199 " is_turned_on is:\n"
6200 " 1 if mode is to be switched on\n"
6201 " 0 if mode is to be switched off\n",
6202 __FILE__, VSetSelectionMode, group);
6204 theCommands.Add("vselnext",
6205 "vselnext : hilight next detected",
6206 __FILE__, VSelectionNext, group);
6208 theCommands.Add("vselprev",
6209 "vselnext : hilight previous detected",
6210 __FILE__, VSelectionPrevious, group);
6212 theCommands.Add("vtriangle",
6213 "vtriangle Name PointName PointName PointName",
6214 __FILE__, VTriangle,group);
6216 theCommands.Add("vsegment",
6217 "vsegment Name PointName PointName",
6218 __FILE__, VSegment,group);
6220 theCommands.Add("vobjzlayer",
6221 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6222 __FILE__, VObjZLayer, group);
6224 theCommands.Add("vpolygonoffset",
6225 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6226 __FILE__, VPolygonOffset, group);
6228 theCommands.Add ("vshowfaceboundary",
6229 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6230 "- turns on/off drawing of face boundaries for ais object "
6231 "and defines boundary line style.",
6232 __FILE__, VShowFaceBoundary, group);
6234 theCommands.Add ("vmarkerstest",
6235 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6236 __FILE__, VMarkersTest, group);
6238 theCommands.Add ("text2brep",
6239 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
6240 __FILE__, TextToBRep, group);
6241 theCommands.Add ("vfont",
6242 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6243 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6244 __FILE__, VFont, group);
6246 theCommands.Add ("vsetedgetype",
6247 "vsetedgetype usage:\n"
6248 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6249 "\n\t\t: Sets edges type and color for input shape",
6250 __FILE__, VSetEdgeType, group);
6252 theCommands.Add ("vunsetedgetype",
6253 "vunsetedgetype usage:\n"
6254 "vunsetedgetype ShapeName [-force]"
6255 "\n\t\t: Unsets edges type and color for input shape",
6256 __FILE__, VUnsetEdgeType, group);
6258 theCommands.Add ("vvertexmode",
6259 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6260 "vvertexmode - prints the default vertex draw mode\n"
6261 "vvertexmode name - prints the vertex draw mode of the given object\n"
6262 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6263 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6264 __FILE__, VVertexMode, group);
6266 theCommands.Add ("vpointcloud",
6267 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6268 "\n\t\t: Create an interactive object for arbitary set of points"
6269 "\n\t\t: from triangulated shape."
6271 "vpointcloud name x y z r npts {surface|volume}\n"
6272 " ... [-randColor] [-normals] [-noNormals]"
6273 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6274 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6276 "\n\t\t: Additional options:"
6277 "\n\t\t: -randColor - generate random color per point"
6278 "\n\t\t: -normals - generate normal per point (default)"
6279 "\n\t\t: -noNormals - do not generate normal per point"
6281 __FILE__, VPointCloud, group);
6283 theCommands.Add("vlocreset",
6284 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6286 LocalTransformPresentation, group);
6288 theCommands.Add("vlocmove",
6289 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6291 LocalTransformPresentation, group);
6293 theCommands.Add("vloctranslate",
6294 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6296 LocalTransformPresentation, group);
6298 theCommands.Add("vlocrotate",
6299 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6301 LocalTransformPresentation, group);
6303 theCommands.Add("vlocmirror",
6304 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6306 LocalTransformPresentation, group);
6308 theCommands.Add("vlocscale",
6309 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6311 LocalTransformPresentation, group);
6313 theCommands.Add("vpriority",
6314 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",