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 <AIS_Drawer.hxx>
103 #include <BRepBuilderAPI_MakeEdge.hxx>
104 #include <BRepBuilderAPI_MakeFace.hxx>
105 #include <BRepBuilderAPI_MakeWire.hxx>
106 #include <Geom_Circle.hxx>
107 #include <GC_MakeCircle.hxx>
108 #include <Prs3d_Presentation.hxx>
109 #include <Select3D_SensitiveCircle.hxx>
110 #include <SelectMgr_EntityOwner.hxx>
111 #include <SelectMgr_Selection.hxx>
112 #include <StdFail_NotDone.hxx>
113 #include <StdPrs_ShadedShape.hxx>
114 #include <TopoDS_Wire.hxx>
116 #include <AIS_MultipleConnectedInteractive.hxx>
117 #include <AIS_ConnectedInteractive.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_VertexDrawMode.hxx>
132 #include <Prs3d_LineAspect.hxx>
133 #include <Prs3d_PointAspect.hxx>
135 #include <Image_AlienPixMap.hxx>
136 #include <TColStd_HArray1OfAsciiString.hxx>
139 # define _CRT_SECURE_NO_DEPRECATE
140 # pragma warning (disable:4996)
143 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
144 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
145 const Handle(AIS_InteractiveObject)& theAISObj,
146 Standard_Boolean theReplaceIfExists = Standard_True);
147 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
148 extern Handle(AIS_InteractiveContext)& TheAISContext();
151 //==============================================================================
152 //function : Vtrihedron 2d
153 //purpose : Create a plane with a 2D trihedron from a faceselection
154 //Draw arg : vtri2d name
155 //==============================================================================
156 #include <AIS_PlaneTrihedron.hxx>
160 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
163 // Verification des arguments
164 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
167 Standard_Integer myCurrentIndex;
168 // Fermeture des contextes
169 TheAISContext()->CloseAllContexts();
170 // Ouverture d'un contexte local et recuperation de son index.
171 TheAISContext()->OpenLocalContext();
172 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
173 // On active les modes de selections faces.
174 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
175 di<<" Select a face ."<<"\n";
177 // Boucle d'attente waitpick.
178 Standard_Integer argccc = 5;
179 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
180 const char **argvvv = (const char **) bufff;
181 while (ViewerMainLoop( argccc, argvvv) ) { }
185 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
186 ShapeB = TheAISContext()->SelectedShape();
189 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
191 // Construction du Plane
192 // recuperation des edges des faces.
193 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
195 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
199 // si il y a plusieurs edges
200 if (FaceExpB.More() ) {
202 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
203 BRepAdaptor_Curve theCurveB(EdgeB);
204 BRepAdaptor_Curve theCurveC(EdgeC);
205 A=theCurveC.Value(0.1);
206 B=theCurveC.Value(0.9);
207 C=theCurveB.Value(0.5);
210 // FaceB a 1 unique edge courbe
211 BRepAdaptor_Curve theCurveB(EdgeB);
212 A=theCurveB.Value(0.1);
213 B=theCurveB.Value(0.9);
214 C=theCurveB.Value(0.5);
216 // Construction du Geom_Plane
217 GC_MakePlane MkPlane(A,B,C);
218 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
220 // Construction de l'AIS_PlaneTrihedron
221 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
223 // Fermeture du contexte local.
224 TheAISContext()->CloseLocalContext(myCurrentIndex);
226 // on le display & bind
227 TheAISContext()->Display(theAISPlaneTri );
228 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
235 //==============================================================================
236 //function : VTriherdron
237 //purpose : Create a trihedron. If no arguments are set, the default
238 // trihedron (Oxyz) is created.
239 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
240 //==============================================================================
242 static int VTrihedron (Draw_Interpretor& theDi,
243 Standard_Integer theArgsNb,
244 const char** theArgVec)
246 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
248 theDi << theArgVec[0] << " Syntax error\n";
252 gp_Pnt anOrigin (0.0, 0.0, 0.0);
253 gp_Dir aDirZ = gp::DZ();
254 gp_Dir aDirX = gp::DX();
255 Standard_Integer anArgIter = 2; // 1st is an IO name
256 if (anArgIter < theArgsNb)
258 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
259 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
260 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
261 if (anArgIter < theArgsNb)
263 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
264 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
265 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
266 aDirZ.SetCoord (aX, aY, aZ);
268 aX = Draw::Atof (theArgVec[anArgIter++]);
269 aY = Draw::Atof (theArgVec[anArgIter++]);
270 aZ = Draw::Atof (theArgVec[anArgIter++]);
271 aDirX.SetCoord (aX, aY, aZ);
275 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
277 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
281 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
282 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
283 VDisplayAISObject (theArgVec[1], aShape);
287 //==============================================================================
290 //purpose : Change the size of a named or selected trihedron
291 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
292 // if no value, the value is set at 100 by default
293 //Draw arg : vsize [name] [size]
294 //==============================================================================
296 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
299 // Declaration de booleens
300 Standard_Boolean ThereIsName;
301 Standard_Boolean ThereIsCurrent;
303 Standard_Boolean hascol;
305 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
307 // Verification des arguments
308 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
310 // Verification du nombre d'arguments
311 if (argc==1) {ThereIsName=Standard_False;value=100;}
312 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
313 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
315 // On ferme le contexte local pour travailler dans le contexte global
316 if(TheAISContext()->HasOpenedContext())
317 TheAISContext()->CloseLocalContext();
319 // On set le booleen ThereIsCurrent
320 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
321 else {ThereIsCurrent=Standard_False;}
325 //===============================================================
326 // Il n'y a pas de nom mais des objets selectionnes
327 //===============================================================
328 if (!ThereIsName && ThereIsCurrent)
331 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
334 while ( it.More() ) {
336 Handle(AIS_InteractiveObject) aShape=
337 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
339 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
342 // On verifie que l'AIS InteraciveObject selectionne est bien
344 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
346 if (aShape->HasColor()) {
347 hascol=Standard_True;
349 // On recupere la couleur de aShape
350 col=aShape->Color();}
352 else hascol=Standard_False;
354 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
355 // pour lui appliquer la methode SetSize()
356 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
358 // C'est bien un triedre,on chage sa valeur!
359 aTrihedron->SetSize(value);
361 // On donne la couleur au Trihedron
362 if(hascol) aTrihedron->SetColor(col);
363 else aTrihedron->UnsetColor();
366 // The trihedron hasn't be errased from the map
367 // so you just have to redisplay it
368 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
377 TheAISContext() ->UpdateCurrentViewer();
380 //===============================================================
381 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
382 //===============================================================
386 //===============================================================
387 // Il y a un nom de triedre passe en argument
388 //===============================================================
390 TCollection_AsciiString name=argv[1];
392 // on verifie que ce nom correspond bien a une shape
393 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
397 // on recupere la shape dans la map des objets displayes
398 Handle(AIS_InteractiveObject) aShape =
399 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
401 // On verifie que l'AIS InteraciveObject est bien
403 if (!aShape.IsNull() &&
404 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
407 if (aShape->HasColor()) {
408 hascol=Standard_True;
410 // On recupere la couleur de aShape
411 col=aShape->Color();}
413 else hascol=Standard_False;
415 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
416 // pour lui appliquer la methode SetSize()
417 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
419 // C'est bien un triedre,on chage sa valeur
420 aTrihedron->SetSize(value);
422 // On donne la couleur au Trihedron
423 if(hascol) aTrihedron->SetColor(col);
424 else aTrihedron->UnsetColor();
426 // The trihedron hasn't be errased from the map
427 // so you just have to redisplay it
428 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
430 TheAISContext() ->UpdateCurrentViewer();
438 //==============================================================================
440 //==============================================================================
441 //function : VPlaneTrihedron
442 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
443 //Draw arg : vplanetri name
444 //==============================================================================
445 #include <AIS_Plane.hxx>
449 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
452 // Verification des arguments
453 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
456 Standard_Integer myCurrentIndex;
457 // Fermeture des contextes locaux
458 TheAISContext()->CloseAllContexts();
460 // On recupere tous les trihedrons de la GetMapOfAIS()
461 // et on active le mode de selection par face.
462 // =================================================
464 // Ouverture d'un contexte local et recuperation de son index.
465 TheAISContext()->OpenLocalContext(Standard_False);
466 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
468 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
471 Handle(AIS_InteractiveObject) ShapeA =
472 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
473 // On verifie que c'est bien un trihedron
474 if (!ShapeA.IsNull() &&
475 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
477 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
478 // on le charge dans le contexte et on active le mode Plane.
479 TheAISContext()->Load(TrihedronA,0,Standard_False);
480 TheAISContext()->Activate(TrihedronA,3);
485 di<<" Select a plane."<<"\n";
486 // Boucle d'attente waitpick.
487 Standard_Integer argccc = 5;
488 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
489 const char **argvvv = (const char **) bufff;
490 while (ViewerMainLoop( argccc, argvvv) ) { }
493 Handle(AIS_InteractiveObject) theIOB;
494 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
495 theIOB = TheAISContext()->Interactive();
498 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
500 // Fermeture du contexte local.
501 TheAISContext()->CloseLocalContext(myCurrentIndex);
503 // on le display & bind
504 TheAISContext()->Display(PlaneB );
505 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
512 //==============================================================================
513 // Fonction First click 2de click
515 // vaxis vertex vertex
517 // vaxispara edge vertex
518 // vaxisortho edge Vertex
519 // vaxisinter Face Face
520 //==============================================================================
522 //==============================================================================
523 //function : VAxisBuilder
525 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
526 //==============================================================================
527 #include <TopoDS_Edge.hxx>
528 #include <TopoDS_Vertex.hxx>
529 #include <TopExp.hxx>
530 #include <Geom_Line.hxx>
532 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
535 Standard_Boolean HasArg;
536 TCollection_AsciiString name;
537 Standard_Integer MyCurrentIndex;
540 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
541 if (argc==8) HasArg=Standard_True;
542 else HasArg=Standard_False;
545 // Fermeture des contextes
546 TheAISContext()->CloseAllContexts();
548 // Cas ou il y a des arguments
549 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
551 Standard_Real coord[6];
552 for(Standard_Integer i=0;i<=5;i++){
553 coord[i]=Draw::Atof(argv[2+i]);
555 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
557 gp_Vec myVect (p1,p2);
558 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
559 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
560 GetMapOfAIS().Bind (TheAxis,name);
561 TheAISContext()->Display(TheAxis);
567 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
568 if ( !strcasecmp(argv[0], "vaxis")) {
569 TheAISContext()->OpenLocalContext();
570 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
572 // Active le mode edge et le mode vertex
573 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
574 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
575 di<<" Select an edge or a vertex."<<"\n";
577 // Boucle d'attente waitpick.
578 Standard_Integer argcc = 5;
579 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
580 const char **argvv = (const char **) buff;
581 while (ViewerMainLoop( argcc, argvv) ) { }
584 // recuperation de la shape.
586 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
587 ShapeA = TheAISContext()->SelectedShape();
589 // recuperation de l'AIS_InteractiveObject
590 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
591 // down cast en AIS_Point si sig et type
592 // AIS_Point -> Geom_Pnt ....
594 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
595 // on desactive le mode edge
596 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
597 di<<" Select a different vertex."<<"\n";
601 // Boucle d'attente waitpick.
602 Standard_Integer argccc = 5;
603 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
604 const char **argvvv = (const char **) bufff;
605 while (ViewerMainLoop( argccc, argvvv) ) { }
607 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
608 ShapeB = TheAISContext()->SelectedShape();
612 } while(ShapeB.IsSame(ShapeA) );
614 // Fermeture du context local
615 TheAISContext()->CloseLocalContext(MyCurrentIndex);
617 // Construction de l'axe
618 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
619 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
622 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
623 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
624 GetMapOfAIS().Bind (TheAxis,name);
625 TheAISContext()->Display(TheAxis);
628 // Un unique edge (ShapeA) a ete picke
629 // Fermeture du context local
630 TheAISContext()->CloseLocalContext(MyCurrentIndex);
631 // Constuction de l'axe
632 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
634 TopExp::Vertices(ed,Va,Vb );
635 gp_Pnt A=BRep_Tool::Pnt(Va);
636 gp_Pnt B=BRep_Tool::Pnt(Vb);
639 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
640 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
641 GetMapOfAIS().Bind (TheAxis,name);
642 TheAISContext()->Display(TheAxis);
648 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
649 else if ( !strcasecmp(argv[0], "vaxispara")) {
651 TheAISContext()->OpenLocalContext();
652 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
654 // Active le mode edge
655 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
656 di<<" Select an edge."<<"\n";
658 // Boucle d'attente waitpick.
659 Standard_Integer argcc = 5;
660 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
661 const char **argvv = (const char **) buff;
662 while (ViewerMainLoop( argcc, argvv) ) { }
666 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
667 ShapeA = TheAISContext()->SelectedShape();
669 // Active le mode vertex et deactive edges
670 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
671 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
672 di<<" Select a vertex."<<"\n";
674 // Boucle d'attente waitpick.
675 Standard_Integer argccc = 5;
676 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
677 const char **argvvv = (const char **) bufff;
678 while (ViewerMainLoop( argccc, argvvv) ) { }
681 // On peut choisir un pnt sur l'edge
683 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
684 ShapeB = TheAISContext()->SelectedShape();
686 // Fermeture du context local
687 TheAISContext()->CloseLocalContext(MyCurrentIndex);
689 // Construction de l'axe
690 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
691 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
693 TopExp::Vertices(ed,Va,Vc );
694 gp_Pnt A=BRep_Tool::Pnt(Va);
695 gp_Pnt C=BRep_Tool::Pnt(Vc);
698 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
699 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
700 GetMapOfAIS().Bind (TheAxis,name);
701 TheAISContext()->Display(TheAxis);
705 // Fonction axisortho
707 TheAISContext()->OpenLocalContext();
708 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
710 // Active le mode edge
711 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
712 di<<" Select an edge."<<"\n";
714 // Boucle d'attente waitpick.
715 Standard_Integer argcc = 5;
716 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
717 const char **argvv = (const char **) buff;
718 while (ViewerMainLoop( argcc, argvv) ) { }
722 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
723 ShapeA = TheAISContext()->SelectedShape();
725 // Active le mode vertex et deactive edges
726 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
727 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
728 di<<" Slect a vertex."<<"\n";
730 // Boucle d'attente waitpick.
731 Standard_Integer argccc = 5;
732 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
733 const char **argvvv = (const char **) bufff;
734 while (ViewerMainLoop( argccc, argvvv) ) { }
737 // On peut choisir un pnt sur l'edge
739 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
740 ShapeB = TheAISContext()->SelectedShape();
742 // Fermeture du context local
743 TheAISContext()->CloseLocalContext(MyCurrentIndex);
745 // Construction de l'axe
746 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
747 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
749 TopExp::Vertices(ed,Va,Vc );
750 gp_Pnt A=BRep_Tool::Pnt(Va);
751 gp_Pnt C=BRep_Tool::Pnt(Vc);
752 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
755 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
756 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
757 GetMapOfAIS().Bind (TheAxis,name);
758 TheAISContext()->Display(TheAxis);
767 //==============================================================================
768 // Fonction First click Result
770 // vpoint vertex AIS_Point=Vertex
771 // edge AIS_Point=Middle of the edge
772 //==============================================================================
774 //==============================================================================
775 //function : VPointBuilder
776 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
777 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
778 //==============================================================================
779 #include <TopoDS_Edge.hxx>
780 #include <TopoDS_Vertex.hxx>
781 #include <TopExp.hxx>
782 #include <AIS_Point.hxx>
783 #include <Geom_CartesianPoint.hxx>
785 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
788 Standard_Boolean HasArg;
789 TCollection_AsciiString name;
790 Standard_Integer myCurrentIndex;
793 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
794 if (argc==5) HasArg=Standard_True;
795 else HasArg=Standard_False;
798 // Fermeture des contextes
799 TheAISContext()->CloseAllContexts();
801 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
803 Standard_Real thecoord[3];
804 for(Standard_Integer i=0;i<=2;i++)
805 thecoord[i]=Draw::Atof(argv[2+i]);
806 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
807 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
808 GetMapOfAIS().Bind (myAISPoint,name);
809 TheAISContext()->Display(myAISPoint);
812 // Il n'a pas d'arguments
814 TheAISContext()->OpenLocalContext();
815 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
817 // Active le mode Vertex et Edges
818 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
819 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
820 di<<" Select a vertex or an edge(build the middle)"<<"\n";
822 // Boucle d'attente waitpick.
823 Standard_Integer argcc = 5;
824 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
825 const char **argvv = (const char **) buff;
826 while (ViewerMainLoop( argcc, argvv) ) { }
830 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
831 ShapeA= TheAISContext()->SelectedShape();
834 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
835 // Un vertex a ete selectionne
836 // Fermeture du context local
837 TheAISContext()->CloseLocalContext(myCurrentIndex);
839 // Construction du point
840 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
841 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
842 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
843 GetMapOfAIS().Bind(myAISPoint,name);
844 TheAISContext()->Display(myAISPoint);
847 // Un Edge a ete selectionne
848 // Fermeture du context local
849 TheAISContext()->CloseLocalContext(myCurrentIndex);
851 // Construction du point milieu de l'edge
852 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
853 TopoDS_Vertex myVertexA,myVertexB;
854 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
855 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
856 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
857 // M est le milieu de [AB]
858 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
859 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
860 GetMapOfAIS().Bind(myAISPointM,name);
861 TheAISContext()->Display(myAISPointM);
869 //==============================================================================
870 // Function 1st click 2de click 3de click
871 // vplane Vertex Vertex Vertex
875 // vplanepara Face Vertex
877 // vplaneortho Face Edge
879 //==============================================================================
881 //==============================================================================
882 //function : VPlaneBuilder
883 //purpose : Build an AIS_Plane from selected entities or Named AIS components
884 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
885 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
886 // [PlaneName] [PointName] [TypeOfSensitivity]
887 //==============================================================================
889 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
890 Standard_Integer argc,
894 Standard_Boolean hasArg;
895 TCollection_AsciiString aName;
896 Standard_Integer aCurrentIndex;
899 if (argc<2 || argc>6 )
901 std::cout<<" Syntax error\n";
904 if (argc == 6 || argc==5 || argc==4)
905 hasArg=Standard_True;
907 hasArg=Standard_False;
910 // Close all contexts
911 TheAISContext()->CloseAllContexts();
913 // There are some arguments
916 if (!GetMapOfAIS().IsBound2(argv[2] ))
918 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
921 // Get shape from map
922 Handle(AIS_InteractiveObject) aShapeA =
923 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
925 // The first argument is an AIS_Point
926 if (!aShapeA.IsNull() &&
927 aShapeA->Type()==AIS_KOI_Datum &&
928 aShapeA->Signature()==1)
930 // The second argument must also be an AIS_Point
931 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
933 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
936 // Get shape from map
937 Handle(AIS_InteractiveObject) aShapeB =
938 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
939 // If B is not an AIS_Point
940 if (aShapeB.IsNull() ||
941 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
943 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
946 // The third object is an AIS_Point
947 if (!GetMapOfAIS().IsBound2(argv[4]) )
949 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
952 // Get shape from map
953 Handle(AIS_InteractiveObject) aShapeC =
954 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
955 // If C is not an AIS_Point
956 if (aShapeC.IsNull() ||
957 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
959 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
963 // Treatment of objects A, B, C
964 // Downcast an AIS_IO to AIS_Point
965 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
966 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
967 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
969 Handle(Geom_CartesianPoint ) aCartPointA =
970 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
972 Handle(Geom_CartesianPoint ) aCartPointB =
973 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
975 Handle(Geom_CartesianPoint ) aCartPointC =
976 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
978 // Verification that the three points are different
979 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
980 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
981 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
984 std::cout<<"vplane error: same points"<<"\n";return 1;
986 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
987 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
988 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
991 std::cout<<"vplane error: same points"<<"\n";return 1;
993 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
994 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
995 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
998 std::cout<<"vplane error: same points"<<"\n";return 1;
1001 gp_Pnt A = aCartPointA->Pnt();
1002 gp_Pnt B = aCartPointB->Pnt();
1003 gp_Pnt C = aCartPointC->Pnt();
1005 // Construction of AIS_Plane
1006 GC_MakePlane MkPlane (A,B,C);
1007 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1008 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1009 GetMapOfAIS().Bind (anAISPlane,aName );
1012 Standard_Integer aType = Draw::Atoi (argv[5]);
1013 if (aType != 0 && aType != 1)
1015 std::cout << "vplane error: wrong type of sensitivity!\n"
1016 << "Should be one of the following values:\n"
1024 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1027 TheAISContext()->Display(anAISPlane);
1030 // The first argument is an AIS_Axis
1031 // Creation of a plane orthogonal to the axis through a point
1032 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1033 // The second argument should be an AIS_Point
1034 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1036 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1039 // Get shape from map
1040 Handle(AIS_InteractiveObject) aShapeB =
1041 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1042 // If B is not an AIS_Point
1043 if (aShapeB.IsNull() ||
1044 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1046 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1050 // Treatment of objects A and B
1051 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1052 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1054 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1055 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1057 gp_Ax1 anAxis = aGeomLineA->Position();
1058 Handle(Geom_CartesianPoint) aCartPointB =
1059 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1061 gp_Dir D =anAxis.Direction();
1062 gp_Pnt B = aCartPointB->Pnt();
1064 // Construction of AIS_Plane
1065 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1066 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1067 GetMapOfAIS().Bind (anAISPlane,aName );
1070 Standard_Integer aType = Draw::Atoi (argv[4]);
1071 if (aType != 0 && aType != 1)
1073 std::cout << "vplane error: wrong type of sensitivity!\n"
1074 << "Should be one of the following values:\n"
1082 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1085 TheAISContext()->Display(anAISPlane);
1088 // The first argumnet is an AIS_Plane
1089 // Creation of a plane parallel to the plane passing through the point
1090 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1092 // The second argument should be an AIS_Point
1093 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1095 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1098 // Get shape from map
1099 Handle(AIS_InteractiveObject) aShapeB =
1100 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1101 // B should be an AIS_Point
1102 if (aShapeB.IsNull() ||
1103 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1105 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1109 // Treatment of objects A and B
1110 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1111 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1113 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1114 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1116 Handle(Geom_CartesianPoint) aCartPointB =
1117 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1118 gp_Pnt B= aCartPointB->Pnt();
1120 // Construction of an AIS_Plane
1121 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1122 GetMapOfAIS().Bind (anAISPlane, aName);
1125 Standard_Integer aType = Draw::Atoi (argv[4]);
1126 if (aType != 0 && aType != 1)
1128 std::cout << "vplane error: wrong type of sensitivity!\n"
1129 << "Should be one of the following values:\n"
1137 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1140 TheAISContext()->Display(anAISPlane);
1145 std::cout<<"vplane: error 1st object is not an AIS\n";
1149 // There are no arguments
1153 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1154 if (!strcasecmp(argv[0], "vplane"))
1156 TheAISContext()->OpenLocalContext();
1157 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1159 // Active modes Vertex, Edge and Face
1160 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1163 std::cout<<"Select a vertex, a face or an edge\n";
1166 Standard_Integer argcc = 5;
1167 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1168 const char **argvv = (const char **) buff;
1169 while (ViewerMainLoop( argcc, argvv) ) { }
1172 TopoDS_Shape aShapeA;
1173 for (TheAISContext()->InitSelected();
1174 TheAISContext()->MoreSelected();
1175 TheAISContext()->NextSelected())
1177 aShapeA = TheAISContext()->SelectedShape();
1180 // aShapeA is a Vertex
1181 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1183 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1184 std::cout<<" Select an edge or a different vertex\n";
1187 Standard_Integer argccc = 5;
1188 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1189 const char **argvvv = (const char **) bufff;
1190 while (ViewerMainLoop( argccc, argvvv) ) { }
1193 TopoDS_Shape aShapeB;
1194 for (TheAISContext()->InitSelected();
1195 TheAISContext()->MoreSelected();
1196 TheAISContext()->NextSelected())
1198 aShapeB = TheAISContext()->SelectedShape();
1200 // aShapeB is a Vertex
1201 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1203 // A and B are the same
1204 if (aShapeB.IsSame(aShapeA))
1206 std::cout<<" vplane: error, same points selected\n";
1209 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1210 std::cout<<" Select a different vertex\n";
1213 Standard_Integer argcccc = 5;
1214 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1215 const char **argvvvv = (const char **) buffff;
1216 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1219 TopoDS_Shape aShapeC;
1220 for (TheAISContext()->InitSelected();
1221 TheAISContext()->MoreSelected();
1222 TheAISContext()->NextSelected())
1224 aShapeC = TheAISContext()->SelectedShape();
1226 // aShapeC is the same as A or B
1227 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1229 std::cout<<" vplane: error, same points selected\n";
1233 // Close the local context
1234 TheAISContext()->CloseLocalContext(aCurrentIndex);
1236 // Construction of plane
1237 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1238 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1239 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1240 GC_MakePlane MkPlane(A, B, C);
1241 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1242 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1243 GetMapOfAIS().Bind (anAISPlane, aName);
1244 TheAISContext()->Display(anAISPlane);
1246 // ShapeB is an edge
1249 // Verify that the vertex is not on the edge ShapeB
1250 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1251 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1253 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1254 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1256 // The vertex is on the edge
1257 std::cout<<" vplane: error point is on the edge\n";
1262 // Close the local context
1263 TheAISContext()->CloseLocalContext(aCurrentIndex);
1264 // Construction of plane
1265 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1266 TopoDS_Vertex aVBa, aVBb;
1267 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1268 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1269 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1270 GC_MakePlane MkPlane (A, aBa, aBb);
1271 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1272 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1273 GetMapOfAIS().Bind (anAISPlane, aName);
1274 TheAISContext()->Display(anAISPlane);
1278 // aShapeA is an edge
1279 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1281 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1282 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1283 std::cout<<" Select a vertex that don't belong to the edge\n";
1286 Standard_Integer argccc = 5;
1287 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1288 const char **argvvv = (const char **) bufff;
1289 while (ViewerMainLoop( argccc, argvvv) ) { }
1292 TopoDS_Shape aShapeB;
1293 for (TheAISContext()->InitSelected();
1294 TheAISContext()->MoreSelected();
1295 TheAISContext()->NextSelected())
1297 aShapeB = TheAISContext()->SelectedShape();
1299 // aShapeB should be a Vertex
1300 // Check that the vertex aShapeB is not on the edge
1301 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1302 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1304 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1305 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1307 // The vertex is on the edge
1308 std::cout<<" vplane: error point is on the edge\n";
1313 // Close the local context
1314 TheAISContext()->CloseLocalContext(aCurrentIndex);
1315 // Construction of plane
1316 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1317 TopoDS_Vertex aVAa, aVAb;
1318 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1319 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1320 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1321 GC_MakePlane MkPlane (B,Aa,Ab);
1322 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1323 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1324 GetMapOfAIS().Bind (anAISPlane ,aName);
1325 TheAISContext()->Display(anAISPlane);
1328 // aShapeA is a Face
1331 // Close the local context: nothing to select
1332 TheAISContext()->CloseLocalContext(aCurrentIndex);
1333 // Construction of plane
1334 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1335 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1336 if (aSurface.GetType()==GeomAbs_Plane)
1338 gp_Pln aPlane = aSurface.Plane();
1339 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1340 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1341 GetMapOfAIS().Bind (anAISPlane, aName);
1342 TheAISContext()->Display(anAISPlane);
1346 std::cout<<" vplane: error\n";
1352 // Function vPlanePara
1353 // ===================
1354 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1355 else if (!strcasecmp(argv[0], "vplanepara"))
1357 TheAISContext()->OpenLocalContext();
1358 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1360 // Activate modes Vertex and Face
1361 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1362 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1363 std::cout<<" Select a vertex or a face\n";
1366 Standard_Integer argcc = 5;
1367 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1368 const char **argvv = (const char **) buff;
1369 while (ViewerMainLoop( argcc, argvv) ) { }
1372 TopoDS_Shape aShapeA;
1373 for (TheAISContext()->InitSelected();
1374 TheAISContext()->MoreSelected();
1375 TheAISContext()->NextSelected())
1377 aShapeA = TheAISContext()->SelectedShape();
1380 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1382 // aShapeA is a vertex
1383 // Deactivate the mode Vertex
1384 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1385 std::cout<<" Select a face\n";
1388 Standard_Integer argccc = 5;
1389 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1390 const char **argvvv = (const char **) bufff;
1391 while (ViewerMainLoop( argccc, argvvv) ) { }
1394 TopoDS_Shape aShapeB;
1395 for (TheAISContext()->InitSelected();
1396 TheAISContext()->MoreSelected();
1397 TheAISContext()->NextSelected())
1399 // A vertex ShapeA can be on Face ShapeB
1400 aShapeB = TheAISContext()->SelectedShape();
1403 // Close the local context
1404 TheAISContext()->CloseLocalContext(aCurrentIndex);
1406 // Construction of plane
1407 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1409 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1410 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1411 if (aSurface.GetType()==GeomAbs_Plane )
1413 gp_Pln aPlane = aSurface.Plane();
1414 // Construct a plane parallel to aGeomPlane through A
1415 aPlane.SetLocation(A);
1416 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1417 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1418 GetMapOfAIS().Bind (aAISPlane ,aName);
1419 TheAISContext()->Display(aAISPlane);
1423 std::cout<<" vplanepara: error\n";
1430 // Deactive the mode Face
1431 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1432 std::cout<<" Select a vertex\n";
1435 Standard_Integer argccc = 5;
1436 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1437 const char **argvvv = (const char **) bufff;
1438 while (ViewerMainLoop( argccc, argvvv) ) { }
1441 TopoDS_Shape aShapeB;
1442 for (TheAISContext()->InitSelected();
1443 TheAISContext()->MoreSelected();
1444 TheAISContext()->NextSelected())
1446 // A vertex ShapeB can be on Face ShapeA
1447 aShapeB = TheAISContext()->SelectedShape();
1449 // Close the local context
1450 TheAISContext()->CloseLocalContext(aCurrentIndex);
1452 // Construction of plane
1453 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1455 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1456 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1457 if (aSurface.GetType()==GeomAbs_Plane )
1459 gp_Pln aPlane = aSurface.Plane();
1460 aPlane.SetLocation(B);
1461 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1462 // Construct a plane parallel to aGeomPlane through B
1463 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1464 GetMapOfAIS().Bind (anAISPlane, aName);
1465 TheAISContext()->Display(anAISPlane);
1469 std::cout<<" vplanepara: error"<<"\n";return 1;
1474 // Function vplaneortho
1475 // ====================
1476 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1479 TheAISContext()->OpenLocalContext();
1480 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1482 // Activate the modes Edge and Face
1483 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1484 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1485 std::cout<<" Select a face and an edge coplanar\n";
1488 Standard_Integer argcc = 5;
1489 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1490 const char **argvv = (const char **) buff;
1491 while (ViewerMainLoop( argcc, argvv) ) { }
1494 TopoDS_Shape aShapeA;
1495 for (TheAISContext()->InitSelected();
1496 TheAISContext()->MoreSelected();
1497 TheAISContext()->NextSelected())
1499 aShapeA = TheAISContext()->SelectedShape();
1502 if (aShapeA.ShapeType()==TopAbs_EDGE )
1504 // ShapeA is an edge, deactivate the mode Edge...
1505 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1506 std::cout<<" Select a face\n";
1509 Standard_Integer argccc = 5;
1510 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1511 const char **argvvv = (const char **) bufff;
1512 while (ViewerMainLoop( argccc, argvvv) ) { }
1515 TopoDS_Shape aShapeB;
1516 for (TheAISContext()->InitSelected();
1517 TheAISContext()->MoreSelected();
1518 TheAISContext()->NextSelected())
1520 // Edge ShapeA can be on Face ShapeB
1521 aShapeB = TheAISContext()->SelectedShape();
1524 // Close the local context
1525 TheAISContext()->CloseLocalContext(aCurrentIndex);
1527 // Construction of plane
1528 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1529 TopoDS_Vertex aVAa, aVAb;
1530 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1531 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1532 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1536 // Creation of rotation axis
1537 gp_Ax1 aRotAxis (Aa,Dab);
1539 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1540 // The edge must be parallel to the face
1541 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1542 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1543 // Compare to heights
1544 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1545 >Precision::Confusion())
1547 // the edge is not parallel to the face
1548 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1552 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1553 if (aSurface.GetType()==GeomAbs_Plane)
1555 gp_Pln aPlane = aSurface.Plane();
1556 // It rotates a half turn round the axis of rotation
1557 aPlane.Rotate(aRotAxis , M_PI/2);
1559 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1560 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1561 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1562 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1563 GetMapOfAIS().Bind (anAISPlane, aName);
1564 TheAISContext()->Display(anAISPlane);
1568 std::cout<<" vplaneortho: error\n";
1574 // ShapeA is a Face, deactive the mode Face.
1575 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1576 std::cout<<" Select an edge\n";
1579 Standard_Integer argccc = 5;
1580 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1581 const char **argvvv = (const char **) bufff;
1582 while (ViewerMainLoop( argccc, argvvv) ) { }
1585 TopoDS_Shape aShapeB;
1586 for (TheAISContext()->InitSelected();
1587 TheAISContext()->MoreSelected();
1588 TheAISContext()->NextSelected())
1590 // Edge ShapeB can be on Face ShapeA
1591 aShapeB = TheAISContext()->SelectedShape();
1593 // Close the local context
1594 TheAISContext()->CloseLocalContext(aCurrentIndex);
1596 // Construction of plane
1597 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1598 TopoDS_Vertex aVBa, aVBb;
1599 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1600 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1601 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1602 gp_Vec ab (aBa,aBb);
1604 // Creation of rotation axe
1605 gp_Ax1 aRotAxis (aBa,Dab);
1607 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1608 // The edge must be parallel to the face
1609 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1610 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1611 // Comparing the two heights
1612 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1613 >Precision::Confusion())
1615 // the edge is not parallel to the face
1616 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1620 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1621 if (aSurface.GetType()==GeomAbs_Plane)
1623 gp_Pln aPlane = aSurface.Plane();
1624 // It rotates a half turn round the axis of rotation
1625 aPlane.Rotate(aRotAxis , M_PI/2);
1626 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1627 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1628 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1629 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1630 GetMapOfAIS().Bind (anAISPlane ,aName);
1631 TheAISContext()->Display(anAISPlane);
1635 std::cout<<" vplaneortho: error\n";
1644 //===============================================================================================
1645 //function : VChangePlane
1647 //===============================================================================================
1648 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1650 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1651 if (aContextAIS.IsNull())
1653 std::cout << theArgVec[0] << "AIS context is not available.\n";
1657 if (theArgsNb < 3 || theArgsNb > 11)
1659 std::cerr << theArgVec[0]
1660 << ": incorrect number of command arguments.\n"
1661 << "Type help for more information.\n";
1665 TCollection_AsciiString aName (theArgVec[1]);
1667 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1668 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1671 if ( aPlane.IsNull() )
1673 std::cout << theArgVec[0]
1674 << ": there is no interactive plane with the given name."
1675 << "Type help for more information.\n";
1679 Standard_Real aCenterX = aPlane->Center().X();
1680 Standard_Real aCenterY = aPlane->Center().Y();
1681 Standard_Real aCenterZ = aPlane->Center().Z();
1683 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1684 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1685 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1687 Standard_Real aSizeX = 0.0;
1688 Standard_Real aSizeY = 0.0;
1689 aPlane->Size (aSizeX, aSizeY);
1690 Standard_Boolean isUpdate = Standard_True;
1692 TCollection_AsciiString aPName, aPValue;
1693 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1695 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1696 TCollection_AsciiString anArgCase = anArg;
1697 anArgCase.UpperCase();
1698 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1701 if (aPName.IsEqual ("X"))
1703 aCenterX = aPValue.RealValue();
1705 else if (aPName.IsEqual ("Y"))
1707 aCenterY = aPValue.RealValue();
1709 else if (aPName.IsEqual ("Z"))
1711 aCenterZ = aPValue.RealValue();
1713 else if (aPName.IsEqual ("DX"))
1715 aDirX = aPValue.RealValue();
1717 else if (aPName.IsEqual ("DY"))
1719 aDirY = aPValue.RealValue();
1721 else if (aPName.IsEqual ("DZ"))
1723 aDirZ = aPValue.RealValue();
1725 else if (aPName.IsEqual ("SX"))
1727 aSizeX = aPValue.RealValue();
1729 else if (aPName.IsEqual ("SY"))
1731 aSizeY = aPValue.RealValue();
1734 else if (anArg.IsEqual ("NOUPDATE"))
1736 isUpdate = Standard_False;
1740 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1741 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1742 aPlane->SetCenter (aCenterPnt);
1743 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1744 aPlane->SetSize (aSizeX, aSizeY);
1748 aContextAIS->Update (aPlane, Standard_True);
1754 //==============================================================================
1756 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1757 //==============================================================================
1759 //==============================================================================
1760 //function : VLineBuilder
1761 //purpose : Build an AIS_Line
1762 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1763 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1764 //==============================================================================
1765 #include <Geom_CartesianPoint.hxx>
1766 #include <AIS_Line.hxx>
1769 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1771 Standard_Integer myCurrentIndex;
1773 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1774 // Fermeture des contextes
1775 TheAISContext()->CloseAllContexts();
1777 // On recupere les parametres
1778 Handle(AIS_InteractiveObject) theShapeA;
1779 Handle(AIS_InteractiveObject) theShapeB;
1781 // Parametres: AIS_Point AIS_Point
1782 // ===============================
1785 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1786 // On verifie que c'est bien une AIS_Point
1787 if (!theShapeA.IsNull() &&
1788 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1789 // on recupere le deuxieme AIS_Point
1791 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1792 if (theShapeA.IsNull() ||
1793 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1795 di <<"vline error: wrong type of 2de argument."<<"\n";
1799 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1800 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1801 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1802 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1804 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1805 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1806 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1808 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1809 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1810 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1812 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1814 di<<"vline error: same points"<<"\n";return 1;
1816 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1817 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1818 GetMapOfAIS().Bind(theAISLine,argv[1] );
1819 TheAISContext()->Display(theAISLine );
1823 // Parametres 6 Reals
1824 // ==================
1827 // On verifie que les deux points ne sont pas confondus
1829 Standard_Real coord[6];
1830 for(Standard_Integer i=0;i<=2;i++){
1831 coord[i]=Draw::Atof(argv[2+i]);
1832 coord[i+3]=Draw::Atof(argv[5+i]);
1835 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1836 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1838 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1839 GetMapOfAIS().Bind(theAISLine,argv[1] );
1840 TheAISContext()->Display(theAISLine );
1844 // Pas de parametres: Selection dans le viewer.
1845 // ============================================
1848 TheAISContext()->OpenLocalContext();
1849 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1851 // Active le mode Vertex.
1852 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1853 di<<" Select a vertex "<<"\n";
1855 // Boucle d'attente waitpick.
1856 Standard_Integer argcc = 5;
1857 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1858 const char **argvv = (const char **) buff;
1859 while (ViewerMainLoop( argcc, argvv) ) { }
1862 TopoDS_Shape ShapeA;
1863 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1864 ShapeA = TheAISContext()->SelectedShape();
1867 // ShapeA est un Vertex
1868 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1870 di<<" Select a different vertex."<<"\n";
1872 TopoDS_Shape ShapeB;
1875 // Boucle d'attente waitpick.
1876 Standard_Integer argccc = 5;
1877 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1878 const char **argvvv = (const char **) bufff;
1879 while (ViewerMainLoop( argccc, argvvv) ) { }
1882 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1883 ShapeB = TheAISContext()->SelectedShape();
1887 } while(ShapeB.IsSame(ShapeA) );
1889 // Fermeture du context local
1890 TheAISContext()->CloseLocalContext(myCurrentIndex);
1892 // Construction de la line
1893 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1894 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1896 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1897 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1899 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1900 GetMapOfAIS().Bind(theAISLine,argv[1] );
1901 TheAISContext()->Display(theAISLine );
1905 di<<"vline error."<<"\n";
1913 //==============================================================================
1914 // class : FilledCircle
1915 // purpose : creates filled circle based on AIS_InteractiveObject
1917 // This class is used to check method Matches() of class
1918 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1919 // because none of AIS classes provides creation of
1920 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1921 // (look method ComputeSelection() )
1922 //==============================================================================
1924 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1926 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1927 gp_Circ aCirc(anAxes, theRadius);
1928 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1932 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1934 class FilledCircle : public AIS_InteractiveObject
1938 DEFINE_STANDARD_RTTI(FilledCircle);
1940 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1941 FilledCircle(Handle(Geom_Circle) theCircle);
1944 TopoDS_Face ComputeFace();
1946 // Virtual methods implementation
1947 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1948 const Handle(Prs3d_Presentation)& thePresentation,
1949 const Standard_Integer theMode);
1951 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1952 const Standard_Integer theMode);
1955 Handle(Geom_Circle) myCircle;
1956 Standard_Boolean myFilledStatus;
1960 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1961 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1963 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1965 myCircle = CreateCircle(theCenter, theRadius);
1966 myFilledStatus = Standard_True;
1969 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1971 myCircle = theCircle;
1972 myFilledStatus = Standard_True;
1975 TopoDS_Face FilledCircle::ComputeFace()
1977 // Create edge from myCircle
1978 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1979 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1981 // Create wire from anEdge
1982 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1983 TopoDS_Wire aWire = aWireMaker.Wire();
1985 // Create face from aWire
1986 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1987 TopoDS_Face aFace = aFaceMaker.Face();
1992 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1993 const Handle(Prs3d_Presentation) &thePresentation,
1994 const Standard_Integer theMode)
1996 thePresentation->Clear();
1998 TopoDS_Face aFace = ComputeFace();
2000 if (aFace.IsNull()) return;
2001 if (theMode != 0) return;
2003 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2006 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2007 const Standard_Integer /*theMode*/)
2009 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2010 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2011 myCircle, myFilledStatus);
2012 theSelection->Add(aSensitiveCircle);
2015 //==============================================================================
2017 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2018 //==============================================================================
2020 //==============================================================================
2021 //function : VCircleBuilder
2022 //purpose : Build an AIS_Circle
2023 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2024 // PointName PointName PointName IsFilled
2025 //==============================================================================
2027 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2028 TCollection_AsciiString theName,
2029 Standard_Boolean isFilled)
2031 Handle(AIS_InteractiveObject) aCircle;
2034 aCircle = new FilledCircle(theGeomCircle);
2038 aCircle = new AIS_Circle(theGeomCircle);
2039 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2042 // Check if there is an object with given name
2043 // and remove it from context
2044 if (GetMapOfAIS().IsBound2(theName))
2046 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2047 Handle(AIS_InteractiveObject) anInterObj =
2048 Handle(AIS_InteractiveObject)::DownCast(anObj);
2049 TheAISContext()->Remove(anInterObj, Standard_False);
2050 GetMapOfAIS().UnBind2(theName);
2053 // Bind the circle to its name
2054 GetMapOfAIS().Bind(aCircle, theName);
2056 // Display the circle
2057 TheAISContext()->Display(aCircle);
2061 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2063 Standard_Integer myCurrentIndex;
2064 // Verification of the arguments
2065 if (argc>6 || argc<2)
2067 std::cout << "vcircle error: expect 4 arguments.\n";
2068 return 1; // TCL_ERROR
2070 TheAISContext()->CloseAllContexts();
2072 // There are all arguments
2076 TCollection_AsciiString aName(argv[1]);
2077 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2079 Handle(AIS_InteractiveObject) theShapeA;
2080 Handle(AIS_InteractiveObject) theShapeB;
2083 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2085 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2088 // Arguments: AIS_Point AIS_Point AIS_Point
2089 // ========================================
2090 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2091 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2093 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2095 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2096 return 1; // TCL_ERROR
2098 // The third object must be a point
2099 Handle(AIS_InteractiveObject) theShapeC =
2100 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2101 if (theShapeC.IsNull() ||
2102 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2104 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2105 return 1; // TCL_ERROR
2108 // Verify that the three points are different
2109 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2110 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2111 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2113 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2114 Handle(Geom_CartesianPoint) myCartPointA =
2115 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2117 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2118 Handle(Geom_CartesianPoint) myCartPointB =
2119 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2121 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2122 Handle(Geom_CartesianPoint) myCartPointC =
2123 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2126 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2127 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2128 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2130 std::cout << "vcircle error: Same points.\n";
2131 return 1; // TCL_ERROR
2134 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2135 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2136 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2138 std::cout << "vcircle error: Same points.\n";
2139 return 1; // TCL_ERROR
2142 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2143 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2144 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2146 std::cout << "vcircle error: Same points.\n";
2147 return 1;// TCL_ERROR
2149 // Construction of the circle
2150 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2151 myCartPointB->Pnt(), myCartPointC->Pnt() );
2152 Handle (Geom_Circle) theGeomCircle;
2155 theGeomCircle = Cir.Value();
2157 catch (StdFail_NotDone)
2159 std::cout << "vcircle error: can't create circle\n";
2160 return -1; // TCL_ERROR
2163 DisplayCircle(theGeomCircle, aName, isFilled);
2166 // Arguments: AIS_Plane AIS_Point Real
2167 // ===================================
2168 else if (theShapeA->Type() == AIS_KOI_Datum &&
2169 theShapeA->Signature() == 7 )
2171 if (theShapeB->Type() != AIS_KOI_Datum ||
2172 theShapeB->Signature() != 1 )
2174 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2175 return 1; // TCL_ERROR
2177 // Check that the radius is >= 0
2178 if (Draw::Atof(argv[4]) <= 0 )
2180 std::cout << "vcircle error: the radius must be >=0.\n";
2181 return 1; // TCL_ERROR
2184 // Recover the normal to the plane
2185 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2186 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2188 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2189 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2190 Handle(Geom_CartesianPoint) myCartPointB =
2191 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2193 gp_Pln mygpPlane = myGeomPlane->Pln();
2194 gp_Ax1 thegpAxe = mygpPlane.Axis();
2195 gp_Dir theDir = thegpAxe.Direction();
2196 gp_Pnt theCenter = myCartPointB->Pnt();
2197 Standard_Real TheR = Draw::Atof(argv[4]);
2198 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2199 Handle (Geom_Circle) theGeomCircle;
2202 theGeomCircle = Cir.Value();
2204 catch (StdFail_NotDone)
2206 std::cout << "vcircle error: can't create circle\n";
2207 return -1; // TCL_ERROR
2210 DisplayCircle(theGeomCircle, aName, isFilled);
2217 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2218 return 1; // TCL_ERROR
2222 // No arguments: selection in the viewer
2223 // =========================================
2226 // Get the name of the circle
2227 TCollection_AsciiString aName(argv[1]);
2229 TheAISContext()->OpenLocalContext();
2230 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2232 // Activate selection mode for vertices and faces
2233 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2234 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2235 std::cout << " Select a vertex or a face\n";
2238 Standard_Integer argcc = 5;
2239 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2240 const char **argvv = (const char **) buff;
2241 while (ViewerMainLoop( argcc, argvv) ) { }
2244 TopoDS_Shape ShapeA;
2245 for(TheAISContext()->InitSelected();
2246 TheAISContext()->MoreSelected();
2247 TheAISContext()->NextSelected() )
2249 ShapeA = TheAISContext()->SelectedShape();
2252 // ShapeA is a Vertex
2253 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2255 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2256 std::cout << " Select a different vertex\n";
2258 TopoDS_Shape ShapeB;
2262 Standard_Integer argccc = 5;
2263 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2264 const char **argvvv = (const char **) bufff;
2265 while (ViewerMainLoop( argccc, argvvv) ) { }
2268 for(TheAISContext()->InitSelected();
2269 TheAISContext()->MoreSelected();
2270 TheAISContext()->NextSelected() )
2272 ShapeB = TheAISContext()->SelectedShape();
2274 } while(ShapeB.IsSame(ShapeA) );
2276 // Selection of ShapeC
2277 std::cout << " Select the last vertex\n";
2278 TopoDS_Shape ShapeC;
2282 Standard_Integer argcccc = 5;
2283 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2284 const char **argvvvv = (const char **) buffff;
2285 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2288 for(TheAISContext()->InitSelected();
2289 TheAISContext()->MoreSelected();
2290 TheAISContext()->NextSelected() )
2292 ShapeC = TheAISContext()->SelectedShape();
2294 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2297 Standard_Boolean isFilled;
2298 std::cout << "Enter filled status (0 or 1)\n";
2301 // Close the local context
2302 TheAISContext()->CloseLocalContext(myCurrentIndex);
2304 // Construction of the circle
2305 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2306 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2307 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2309 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2310 Handle (Geom_Circle) theGeomCircle;
2313 theGeomCircle = Cir.Value();
2315 catch (StdFail_NotDone)
2317 std::cout << "vcircle error: can't create circle\n";
2318 return -1; // TCL_ERROR
2321 DisplayCircle(theGeomCircle, aName, isFilled);
2327 std::cout << " Select a vertex (in your face)\n";
2328 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2330 TopoDS_Shape ShapeB;
2332 Standard_Integer argccc = 5;
2333 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2334 const char **argvvv = (const char **) bufff;
2335 while (ViewerMainLoop( argccc, argvvv) ) { }
2338 for(TheAISContext()->InitSelected();
2339 TheAISContext()->MoreSelected();
2340 TheAISContext()->NextSelected() )
2342 ShapeB = TheAISContext()->SelectedShape();
2345 // Recover the radius
2346 Standard_Real theRad;
2349 std::cout << " Enter the value of the radius:\n";
2351 } while (theRad <= 0);
2353 // Get filled status
2354 Standard_Boolean isFilled;
2355 std::cout << "Enter filled status (0 or 1)\n";
2358 // Close the local context
2359 TheAISContext()->CloseLocalContext(myCurrentIndex);
2360 // Construction of the circle
2362 // Recover the normal to the plane. tag
2363 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2364 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2365 gp_Pln myPlane = mySurface.Plane();
2366 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2367 gp_Pln mygpPlane = theGeomPlane->Pln();
2368 gp_Ax1 thegpAxe = mygpPlane.Axis();
2369 gp_Dir theDir = thegpAxe.Direction();
2371 // Recover the center
2372 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2374 // Construct the circle
2375 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2376 Handle (Geom_Circle) theGeomCircle;
2379 theGeomCircle = Cir.Value();
2381 catch (StdFail_NotDone)
2383 std::cout << "vcircle error: can't create circle\n";
2384 return -1; // TCL_ERROR
2387 DisplayCircle(theGeomCircle, aName, isFilled);
2397 //===============================================================================================
2398 //function : VDrawText
2400 //purpose : Create a text.
2401 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2402 //===============================================================================================
2403 #include <Graphic3d_Group.hxx>
2404 #include <Graphic3d_Structure.hxx>
2405 #include <Graphic3d_AspectText3d.hxx>
2406 #include <Graphic3d_AspectFillArea3d.hxx>
2407 #include <Graphic3d_StructureManager.hxx>
2408 #include <Graphic3d_VerticalTextAlignment.hxx>
2409 #include <Graphic3d_HorizontalTextAlignment.hxx>
2411 #include <Font_NameOfFont.hxx>
2413 #include <Visual3d_ViewManager.hxx>
2415 #include <Standard_DefineHandle.hxx>
2417 #include <Prs3d_Root.hxx>
2418 #include <Prs3d_Text.hxx>
2419 #include <Prs3d_TextAspect.hxx>
2420 #include <Prs3d_ShadingAspect.hxx>
2421 #include <PrsMgr_PresentationManager3d.hxx>
2423 #include <TCollection_ExtendedString.hxx>
2424 #include <TCollection_AsciiString.hxx>
2426 #include <gp_Pnt.hxx>
2427 #include <Quantity_NameOfColor.hxx>
2428 #include <Quantity_Color.hxx>
2431 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2433 class MyTextClass:public AIS_InteractiveObject
2437 DEFINE_STANDARD_RTTI(MyTextClass );
2443 const TCollection_ExtendedString& , const gp_Pnt& ,
2444 Quantity_Color color,
2445 Standard_Integer aHJust,
2446 Standard_Integer aVJust ,
2447 Standard_Real Angle ,
2448 Standard_Boolean Zoom ,
2449 Standard_Real Height,
2450 Font_FontAspect FontAspect,
2451 Standard_CString Font
2456 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2457 const Handle(Prs3d_Presentation)& aPresentation,
2458 const Standard_Integer aMode);
2460 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2461 const Standard_Integer /*aMode*/){} ;
2464 TCollection_ExtendedString aText;
2467 Standard_Real Green;
2469 Standard_Real aAngle;
2470 Standard_Real aHeight;
2471 Standard_Boolean aZoomable;
2472 Quantity_Color aColor;
2473 TCollection_AsciiString aFont;
2474 Font_FontAspect aFontAspect;
2475 Graphic3d_HorizontalTextAlignment aHJustification;
2476 Graphic3d_VerticalTextAlignment aVJustification;
2481 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2482 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2485 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2486 Quantity_Color color = Quantity_NOC_YELLOW,
2487 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2488 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2489 Standard_Real angle = 0.0 ,
2490 Standard_Boolean zoomable = Standard_True,
2491 Standard_Real height = 12.,
2492 Font_FontAspect fontAspect = Font_FA_Regular,
2493 Standard_CString font = "Courier")
2496 aPosition = position;
2497 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2498 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2500 aZoomable = zoomable;
2503 aFontAspect = fontAspect;
2509 //////////////////////////////////////////////////////////////////////////////
2510 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
2511 const Handle(Prs3d_Presentation)& aPresentation,
2512 const Standard_Integer /*aMode*/)
2515 aPresentation->Clear();
2517 if (!myDrawer->HasTextAspect())
2519 myDrawer->SetTextAspect (new Prs3d_TextAspect());
2520 *myDrawer->TextAspect()->Aspect() = *myDrawer->Link()->TextAspect()->Aspect();
2523 Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect();
2525 asp->SetFont(aFont.ToCString());
2526 asp->SetColor(aColor);
2527 asp->SetHeight(aHeight); // I am changing the myHeight value
2529 asp->SetHorizontalJustification(aHJustification);
2530 asp->SetVerticalJustification(aVJustification);
2531 asp->Aspect()->SetTextZoomable(aZoomable);
2532 asp->Aspect()->SetTextAngle(aAngle);
2533 asp->Aspect()->SetTextFontAspect(aFontAspect);
2534 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2536 /* This comment code is worked
2537 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2538 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2539 Graphic3d_Vertex vertices_text;
2540 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2541 TheGroup->SetPrimitivesAspect(aspect);
2542 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2546 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2551 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2552 di<<"Usage: type help "<<argv[0]<<"\n";
2553 return 1; //TCL_ERROR
2556 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2558 // Create 3D view if it doesn't exist
2559 if ( aContext.IsNull() )
2561 ViewerTest::ViewerInit();
2562 aContext = ViewerTest::GetAISContext();
2563 if( aContext.IsNull() )
2565 di << "Error: Cannot create a 3D view\n";
2566 return 1; //TCL_ERROR
2571 const Standard_Real X = Draw::Atof(argv[2]);
2572 const Standard_Real Y = Draw::Atof(argv[3]);
2573 const Standard_Real Z = Draw::Atof(argv[4]);
2574 const gp_Pnt pnt(X,Y,Z);
2577 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2578 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2579 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
2580 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2583 const int hor_align = Draw::Atoi(argv[8]);
2584 const int ver_align = Draw::Atoi(argv[9]);
2587 const Standard_Real angle = Draw::Atof(argv[10]);
2590 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
2593 const Standard_Real height = Draw::Atof(argv[12]);
2596 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
2599 TCollection_AsciiString font;
2601 font.AssignCat("Courier");
2603 font.AssignCat(argv[14]);
2605 // Text is multibyte
2606 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
2609 TCollection_ExtendedString name(argv[1],isMultibyte);
2613 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2614 aContext->Display(myT,Standard_True);
2621 #include <gp_Pnt.hxx>
2622 #include <Graphic3d_ArrayOfPoints.hxx>
2623 #include <Graphic3d_ArrayOfPrimitives.hxx>
2624 #include <Graphic3d_ArrayOfTriangles.hxx>
2625 #include <Poly_Array1OfTriangle.hxx>
2626 #include <Poly_Triangle.hxx>
2627 #include <Poly_Triangulation.hxx>
2628 #include <TColgp_Array1OfPnt.hxx>
2629 #include <TShort_Array1OfShortReal.hxx>
2630 #include <TShort_HArray1OfShortReal.hxx>
2632 #include <AIS_Triangulation.hxx>
2633 #include <StdPrs_ToolShadedShape.hxx>
2634 #include <Poly_Connect.hxx>
2635 #include <TColgp_Array1OfDir.hxx>
2636 #include <Graphic3d_GraphicDriver.hxx>
2638 #include <TColStd_Array1OfInteger.hxx>
2639 #include <TColStd_HArray1OfInteger.hxx>
2640 #include <Prs3d_ShadingAspect.hxx>
2641 #include <Graphic3d_MaterialAspect.hxx>
2642 #include <Graphic3d_AspectFillArea3d.hxx>
2644 #include <BRepPrimAPI_MakeCylinder.hxx>
2645 #include <TopoDS_Shape.hxx>
2646 #include <TopExp_Explorer.hxx>
2647 #include <TopAbs.hxx>
2648 #include <StdSelect_ShapeTypeFilter.hxx>
2651 //===============================================================================================
2652 //function : CalculationOfSphere
2654 //purpose : Create a Sphere
2655 //===============================================================================================
2657 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2660 double mRadius = Radius;
2661 double mCenter[3] = {X,Y,Z};
2662 int mThetaResolution;
2664 double mStartTheta = 0;//StartTheta;
2665 double mEndTheta = 360;//EndTheta;
2666 double mStartPhi = 0;//StartPhi;
2667 double mEndPhi = 180;//EndPhi;
2668 res = res < 4 ? 4 : res;
2670 mThetaResolution = res;
2671 mPhiResolution = res;
2674 int jStart, jEnd, numOffset;
2675 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2676 double startTheta, endTheta, startPhi, endPhi;
2677 int base, numPoles=0, thetaResolution, phiResolution;
2682 if ( numPieces > mThetaResolution ) {
2683 numPieces = mThetaResolution;
2686 int localThetaResolution = mThetaResolution;
2687 double localStartTheta = mStartTheta;
2688 double localEndTheta = mEndTheta;
2690 while ( localEndTheta < localStartTheta ) {
2691 localEndTheta += 360.0;
2694 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2696 // Change the ivars based on pieces.
2698 start = piece * localThetaResolution / numPieces;
2699 end = (piece+1) * localThetaResolution / numPieces;
2700 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2701 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2702 localThetaResolution = end - start;
2704 // Create north pole if needed
2705 int number_point = 0;
2706 int number_pointArray = 0;
2708 if ( mStartPhi <= 0.0 ) {
2709 number_pointArray++;
2712 if ( mEndPhi >= 180.0 ) {
2713 number_pointArray++;
2717 // Check data, determine increments, and convert to radians
2718 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2719 startTheta *= M_PI / 180.0;
2720 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2721 endTheta *= M_PI / 180.0;
2724 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2725 startPhi *= M_PI / 180.0;
2726 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2727 endPhi *= M_PI / 180.0;
2729 phiResolution = mPhiResolution - numPoles;
2730 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2731 thetaResolution = localThetaResolution;
2732 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2733 ++localThetaResolution;
2735 deltaTheta = (endTheta - startTheta) / thetaResolution;
2737 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2738 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2740 // Create intermediate points
2741 for ( i = 0; i < localThetaResolution; i++ ) {
2742 for ( j = jStart; j < jEnd; j++ ) {
2743 number_pointArray++;
2747 //Generate mesh connectivity
2748 base = phiResolution * localThetaResolution;
2750 int number_triangle = 0 ;
2751 if ( mStartPhi <= 0.0 ) { // around north pole
2752 number_triangle += localThetaResolution;
2755 if ( mEndPhi >= 180.0 ) { // around south pole
2756 number_triangle += localThetaResolution;
2759 // bands in-between poles
2760 for ( i=0; i < localThetaResolution; i++){
2761 for ( j=0; j < (phiResolution-1); j++){
2762 number_triangle +=2;
2766 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2767 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2768 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2770 if ( mStartPhi <= 0.0 ){
2773 x[2] = mCenter[2] + mRadius;
2774 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2777 // Create south pole if needed
2778 if ( mEndPhi >= 180.0 ){
2781 x[2] = mCenter[2] - mRadius;
2782 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2786 for ( i=0; i < localThetaResolution; i++){
2787 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2788 for ( j = jStart; j < jEnd; j++){
2789 phi = startPhi + j*deltaPhi;
2790 radius = mRadius * sin((double)phi);
2791 n[0] = radius * cos((double)theta);
2792 n[1] = radius * sin((double)theta);
2793 n[2] = mRadius * cos((double)phi);
2794 x[0] = n[0] + mCenter[0];
2795 x[1] = n[1] + mCenter[1];
2796 x[2] = n[2] + mCenter[2];
2797 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2803 number_triangle = 1;
2804 if ( mStartPhi <= 0.0 ){// around north pole
2805 for (i=0; i < localThetaResolution; i++){
2806 pts[0] = phiResolution*i + numPoles;
2807 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2809 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2814 if ( mEndPhi >= 180.0 ){ // around south pole
2815 numOffset = phiResolution - 1 + numPoles;
2816 for (i=0; i < localThetaResolution; i++){
2817 pts[0] = phiResolution*i + numOffset;
2818 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2819 pts[1] = numPoles - 1;
2820 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2825 // bands in-between poles
2827 for (i=0; i < localThetaResolution; i++){
2828 for (j=0; j < (phiResolution-1); j++){
2829 pts[0] = phiResolution*i + j + numPoles;
2830 pts[1] = pts[0] + 1;
2831 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2832 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2835 pts[2] = pts[1] - 1;
2836 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2841 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2843 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2845 Standard_Integer index[3];
2846 Standard_Real Tol = Precision::Confusion();
2849 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2850 gp_XYZ eqPlan(0, 0, 0);
2851 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2852 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2853 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2854 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2856 Standard_Real mod = vv.Modulus();
2857 if(mod < Tol) continue;
2861 Standard_Real modmax = eqPlan.Modulus();
2864 Nor = gp_Dir(eqPlan);
2866 Nor = gp_Dir(0., 0., 1.);
2868 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2869 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2870 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2871 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2875 polyTriangulation->SetNormals(Normals);
2877 return polyTriangulation;
2880 //===============================================================================================
2881 //function : VDrawSphere
2883 //purpose : Create an AIS shape.
2884 //===============================================================================================
2885 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2888 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2889 if (aContextAIS.IsNull())
2891 std::cout << "Call vinit before!\n";
2896 std::cout << "Use: " << argv[0]
2897 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2901 // read the arguments
2902 TCollection_AsciiString aShapeName (argv[1]);
2903 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2904 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2905 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2906 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2907 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2908 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2909 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2911 // remove AIS object with given name from map
2912 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2915 std::cout << "Compute Triangulation...\n";
2916 Handle(AIS_Triangulation) aShape
2917 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2920 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2921 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2923 // stupid initialization of Green color in RGBA space as integer
2924 // probably wrong for big-endian CPUs
2925 Standard_Integer aRed = 0;
2926 Standard_Integer aGreen = 255;
2927 Standard_Integer aBlue = 0;
2928 Standard_Integer anAlpha = 0; // not used
2929 Standard_Integer aColorInt = aRed;
2930 aColorInt += aGreen << 8;
2931 aColorInt += aBlue << 16;
2932 aColorInt += anAlpha << 24;
2934 // setup colors array per vertex
2935 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2936 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2938 aColorArray->SetValue (aNodeId, aColorInt);
2940 aShape->SetColors (aColorArray);
2943 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2944 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2945 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2946 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2947 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2948 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2949 aTotalSize >>= 20; //MB
2950 aNormalsSize >>= 20;
2952 aTrianglesSize >>= 20;
2953 aPolyConnectSize >>= 20;
2956 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2957 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2958 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2959 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2960 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2961 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2964 // Setting material properties, very important for desirable visual result!
2965 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2966 aMat.SetAmbient (0.2);
2967 aMat.SetSpecular (0.5);
2968 Handle(Graphic3d_AspectFillArea3d) anAspect
2969 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2971 Quantity_NOC_YELLOW,
2976 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2979 anAspect->SetEdgeOn();
2983 anAspect->SetEdgeOff();
2985 aShAsp->SetAspect (anAspect);
2986 aShape->Attributes()->SetShadingAspect (aShAsp);
2988 VDisplayAISObject (aShapeName, aShape);
2992 //=============================================================================
2993 //function : VComputeHLR
2995 //=============================================================================
2997 static int VComputeHLR (Draw_Interpretor& di,
2998 Standard_Integer argc,
3001 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3003 if (aContextAIS.IsNull ())
3005 di << "Please call vinit before\n";
3009 if ( argc != 3 && argc != 12 )
3011 di << "Usage: " << argv[0] << " ShapeName HlrName "
3012 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3013 << " ShapeName - name of the initial shape\n"
3014 << " HlrName - result hlr object from initial shape\n"
3015 << " eye, dir are eye position and look direction\n"
3016 << " up is the look up direction vector\n"
3017 << " Use vtop to see projected hlr shape\n";
3021 // shape and new object name
3022 TCollection_AsciiString aShapeName (argv[1]);
3023 TCollection_AsciiString aHlrName (argv[2]);
3025 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3028 BRep_Builder aBrepBuilder;
3029 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3032 di << "No shape with name " << argv[1] << " found\n";
3037 if (GetMapOfAIS ().IsBound2 (aHlrName))
3039 di << "Presentable object with name " << argv[2] << " already exists\n";
3043 // close local context
3044 if (aContextAIS->HasOpenedContext ())
3045 aContextAIS->CloseLocalContext ();
3047 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3048 HLRBRep_PolyHLRToShape aHLRToShape;
3057 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3058 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3059 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3060 aProjAx.SetLocation (anEye);
3061 aProjAx.SetDirection (aDir);
3062 aProjAx.SetYDirection (anUp);
3068 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3069 Handle(V3d_View) aView = ViewerTest::CurrentView();
3070 Standard_Integer aWidth, aHeight;
3071 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3072 Standard_Real aRightX, aRightY, aRightZ;
3073 aView->Window()->Size (aWidth, aHeight);
3075 aView->ConvertWithProj (aWidth, aHeight/2,
3076 aRightX, aRightY, aRightZ,
3077 aDirX, aDirY, aDirZ);
3079 aView->ConvertWithProj (aWidth/2, aHeight/2,
3080 aCentX, aCentY, aCentZ,
3081 aDirX, aDirY, aDirZ);
3083 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3084 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3085 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3086 aProjAx.SetLocation (anEye);
3087 aProjAx.SetDirection (aDir);
3088 aProjAx.SetXDirection (aRight);
3091 HLRAlgo_Projector aProjector (aProjAx);
3092 aPolyAlgo->Projector (aProjector);
3093 aPolyAlgo->Load (aSh);
3094 aPolyAlgo->Update ();
3096 aHLRToShape.Update (aPolyAlgo);
3098 // make hlr shape from input shape
3099 TopoDS_Compound aHlrShape;
3100 BRep_Builder aBuilder;
3101 aBuilder.MakeCompound (aHlrShape);
3103 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3104 if (!aCompound.IsNull ())
3106 aBuilder.Add (aHlrShape, aCompound);
3109 // extract visible outlines
3110 aCompound = aHLRToShape.OutLineVCompound();
3111 if (!aCompound.IsNull ())
3113 aBuilder.Add (aHlrShape, aCompound);
3116 // create an AIS shape and display it
3117 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3118 GetMapOfAIS().Bind (anObject, aHlrName);
3119 aContextAIS->Display (anObject);
3121 aContextAIS->UpdateCurrentViewer ();
3126 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3127 // manipulating and displaying such an array with AIS context
3128 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3129 class MyPArrayObject : public AIS_InteractiveObject
3134 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3135 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3137 myArrayDescription = theArrayDescription;
3138 myMarkerAspect = theMarkerAspect;
3141 DEFINE_STANDARD_RTTI(MyPArrayObject);
3145 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3146 const Handle(Prs3d_Presentation)& aPresentation,
3147 const Standard_Integer aMode);
3149 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3150 const Standard_Integer /*theMode*/);
3152 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3153 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3154 Standard_Integer &theArgIndex,
3155 Standard_Integer theArgCount,
3156 Standard_Integer theMaxArgs);
3160 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3161 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3165 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3166 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3168 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3169 const Handle(Prs3d_Presentation)& aPresentation,
3170 const Standard_Integer /*aMode*/)
3173 // Parsing array description
3174 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3175 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3176 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3178 Standard_Integer anArgIndex = 0;
3179 Standard_Integer anArgsCount = myArrayDescription->Length();
3180 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3182 TCollection_AsciiString aCommand;
3183 while (anArgIndex < anArgsCount)
3185 aCommand = myArrayDescription->Value (anArgIndex);
3186 aCommand.LowerCase();
3189 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3191 // vertex has a normal or normal with color or texel
3192 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3193 hasNormals = Standard_True;
3195 // vertex has a color
3196 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3197 hasVColors = Standard_True;
3199 // vertex has a texel
3200 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3201 hasTexels = Standard_True;
3206 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3209 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3210 hasBColors = Standard_True;
3215 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3224 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3225 if (anArrayType == "points")
3227 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3229 else if (anArrayType == "segments")
3230 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3231 else if (anArrayType == "polylines")
3232 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3233 hasVColors, hasBColors);
3234 else if (anArrayType == "triangles")
3235 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3236 hasVColors, hasTexels);
3237 else if (anArrayType == "trianglefans")
3238 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3239 hasNormals, hasVColors,
3240 hasBColors, hasTexels);
3241 else if (anArrayType == "trianglestrips")
3242 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3243 hasNormals, hasVColors,
3244 hasBColors, hasTexels);
3245 else if (anArrayType == "quads")
3246 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3247 hasNormals, hasVColors,
3249 else if (anArrayType == "quadstrips")
3250 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3251 hasNormals, hasVColors,
3252 hasBColors, hasTexels);
3253 else if (anArrayType == "polygons")
3254 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3255 hasNormals, hasVColors, hasBColors,
3259 while (anArgIndex < anArgsCount)
3261 aCommand = myArrayDescription->Value (anArgIndex);
3262 aCommand.LowerCase();
3263 if (!aCommand.IsAscii())
3267 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3269 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3270 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3271 myArrayDescription->Value (anArgIndex - 1).RealValue());
3272 const Standard_Integer aVertIndex = anArray->VertexNumber();
3274 // vertex has a normal or normal with color or texel
3275 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3276 anArray->SetVertexNormal (aVertIndex,
3277 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3278 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3279 myArrayDescription->Value (anArgIndex - 1).RealValue());
3281 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3282 anArray->SetVertexColor (aVertIndex,
3283 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3284 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3285 myArrayDescription->Value (anArgIndex - 1).RealValue());
3287 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3288 anArray->SetVertexTexel (aVertIndex,
3289 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3290 myArrayDescription->Value (anArgIndex - 1).RealValue());
3293 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3295 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3297 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3298 anArray->AddBound (aVertCount,
3299 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3300 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3301 myArrayDescription->Value (anArgIndex - 1).RealValue());
3304 anArray->AddBound (aVertCount);
3307 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3309 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3310 anArray->AddEdge (aVertIndex);
3317 aPresentation->Clear();
3318 if (!myMarkerAspect.IsNull())
3320 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3322 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3325 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3326 const Standard_Integer /*theMode*/)
3328 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3330 Standard_Integer anArgIndex = 1;
3331 while (anArgIndex < myArrayDescription->Length())
3333 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3335 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3336 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3337 myArrayDescription->Value (anArgIndex - 1).RealValue());
3338 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3339 theSelection->Add (aSensetivePoint);
3348 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3349 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3350 Standard_Integer &theArgIndex,
3351 Standard_Integer theArgCount,
3352 Standard_Integer theMaxArgs)
3354 // check if there is more elements than expected
3355 if (theArgIndex >= theMaxArgs)
3358 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3359 aStrCommand.LowerCase();
3360 if (aStrCommand.Search(theCommand) != 1 ||
3361 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3364 // go to the first data element
3367 // check data if it can be converted to numeric
3368 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3370 aStrCommand = theArgsArray->Value (theArgIndex);
3371 if (!aStrCommand.IsRealValue())
3378 //=============================================================================
3379 //function : VDrawPArray
3380 //purpose : Draws primitives array from list of vertexes, bounds, edges
3381 //=============================================================================
3383 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3385 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3386 if (aContextAIS.IsNull())
3388 di << "Call vinit before!\n";
3393 di << "Use: " << argv[0] << " Name TypeOfArray"
3394 << " [vertex] ... [bounds] ... [edges]\n"
3395 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3396 << " trianglefans | trianglestrips | quads |\n"
3397 << " quadstrips | polygons }\n"
3398 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3399 << " [texel={ 't' tx ty }] } \n"
3400 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3401 << " edges={ 'e' vertex_id }\n";
3405 // read the arguments
3406 Standard_Integer aArgIndex = 1;
3407 TCollection_AsciiString aName (argv[aArgIndex++]);
3408 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3410 Standard_Boolean hasVertex = Standard_False;
3412 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3413 anArgsArray->SetValue (0, anArrayType);
3415 if (anArrayType != "points" &&
3416 anArrayType != "segments" &&
3417 anArrayType != "polylines" &&
3418 anArrayType != "triangles" &&
3419 anArrayType != "trianglefans" &&
3420 anArrayType != "trianglestrips" &&
3421 anArrayType != "quads" &&
3422 anArrayType != "quadstrips" &&
3423 anArrayType != "polygons")
3425 di << "Unexpected type of primitives array\n";
3429 TCollection_AsciiString aCommand;
3430 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3432 aCommand = argv[anArgIndex];
3433 aCommand.LowerCase();
3434 if (!aCommand.IsAscii())
3436 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3437 << "should be an array element: 'v', 'b', 'e' \n";
3441 if (aCommand == "v")
3443 hasVertex = Standard_True;
3446 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3451 di << "You should pass any verticies in the list of array elements\n";
3455 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3456 if (anArrayType == "points")
3458 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3461 // create primitives array object
3462 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3464 // register the object in map
3465 VDisplayAISObject (aName, aPObject);
3470 //=======================================================================
3471 //function : VSetLocation
3472 //purpose : Change location of AIS interactive object
3473 //=======================================================================
3475 static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
3476 Standard_Integer theArgNb,
3477 const char** theArgVec)
3479 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3480 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3481 if (aContext.IsNull())
3483 std::cout << "Error: no active view!\n";
3487 TCollection_AsciiString aName;
3489 Standard_Boolean isSetLoc = Standard_False;
3491 Standard_Integer anArgIter = 1;
3492 for (; anArgIter < theArgNb; ++anArgIter)
3494 Standard_CString anArg = theArgVec[anArgIter];
3495 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3499 else if (aName.IsEmpty())
3505 isSetLoc = Standard_True;
3506 if (anArgIter + 1 >= theArgNb)
3508 std::cout << "Error: syntax error at '" << anArg << "'\n";
3511 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3512 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3513 if (anArgIter + 1 < theArgNb)
3515 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3520 std::cout << "Error: unknown argument '" << anArg << "'\n";
3526 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3527 Handle(AIS_InteractiveObject) anIObj;
3528 if (aMap.IsBound2 (aName))
3530 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3532 if (anIObj.IsNull())
3534 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3539 aTrsf.SetTranslation (aLocVec);
3540 TopLoc_Location aLocation (aTrsf);
3541 aContext->SetLocation (anIObj, aLocation);
3545 //=======================================================================
3546 //function : TransformPresentation
3547 //purpose : Change transformation of AIS interactive object
3548 //=======================================================================
3549 static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3550 Standard_Integer theArgNb,
3551 const char** theArgVec)
3555 std::cout << "Error: too few arguments.\n";
3559 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3560 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3561 if (aContext.IsNull())
3563 std::cout << "Error: no active view!\n";
3568 Standard_Integer aLast = theArgNb;
3569 const char* aName = theArgVec[0];
3571 Standard_Boolean isReset = Standard_False;
3572 Standard_Boolean isMove = Standard_False;
3577 if (!strcmp (aName, "reset"))
3579 isReset = Standard_True;
3581 else if (!strcmp (aName, "move"))
3585 std::cout << "Error: too few arguments.\n";
3589 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3591 Handle(AIS_InteractiveObject) anIObj;
3592 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3594 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3597 if (anIObj.IsNull())
3599 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3603 isMove = Standard_True;
3605 aTrsf = anIObj->Transformation();
3606 aLast = theArgNb - 1;
3608 else if (!strcmp (aName, "translate"))
3612 std::cout << "Error: too few arguments.\n";
3615 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3616 Draw::Atof (theArgVec[theArgNb - 2]),
3617 Draw::Atof (theArgVec[theArgNb - 1])));
3618 aLast = theArgNb - 3;
3620 else if (!strcmp (aName, "rotate"))
3624 std::cout << "Error: too few arguments.\n";
3629 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3630 Draw::Atof (theArgVec[theArgNb - 6]),
3631 Draw::Atof (theArgVec[theArgNb - 5])),
3632 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3633 Draw::Atof (theArgVec[theArgNb - 3]),
3634 Draw::Atof (theArgVec[theArgNb - 2]))),
3635 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3637 aLast = theArgNb - 7;
3639 else if (!strcmp (aName, "mirror"))
3643 std::cout << "Error: too few arguments.\n";
3647 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3648 Draw::Atof(theArgVec[theArgNb - 5]),
3649 Draw::Atof(theArgVec[theArgNb - 4])),
3650 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3651 Draw::Atof(theArgVec[theArgNb - 2]),
3652 Draw::Atof(theArgVec[theArgNb - 1]))));
3653 aLast = theArgNb - 6;
3655 else if (!strcmp (aName, "scale"))
3659 std::cout << "Error: too few arguments.\n";
3663 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3664 Draw::Atof(theArgVec[theArgNb - 3]),
3665 Draw::Atof(theArgVec[theArgNb - 2])),
3666 Draw::Atof(theArgVec[theArgNb - 1]));
3667 aLast = theArgNb - 4;
3670 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3673 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3674 Handle(AIS_InteractiveObject) anIObj;
3675 if (aMap.IsBound2 (theArgVec[anIdx]))
3677 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3679 if (anIObj.IsNull())
3681 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3687 // aTrsf already identity
3691 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3695 aTrsf = anIObj->LocalTransformation() * aTrsf;
3698 TopLoc_Location aLocation (aTrsf);
3699 aContext->SetLocation (anIObj, aLocation);
3705 //===============================================================================================
3706 //function : VConnect
3707 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3708 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
3709 //===============================================================================================
3711 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3712 Standard_Integer argc,
3716 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3717 if (aContext.IsNull())
3719 std::cout << "vconnect error : call vinit before\n";
3720 return 1; // TCL_ERROR
3725 std::cout << "vconnect error: expect at least 5 arguments\n";
3726 return 1; // TCL_ERROR
3730 Standard_Integer anArgIter = 1;
3731 TCollection_AsciiString aName (argv[anArgIter++]);
3732 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
3733 TCollection_AsciiString aColorString (argv[argc-1]);
3734 Standard_CString aColorName = "";
3735 Standard_Boolean hasColor = Standard_False;
3736 if (aColorString.Search ("color=") != -1)
3738 hasColor = Standard_True;
3739 aColorString.Remove (1, 6);
3740 aColorName = aColorString.ToCString();
3742 Handle(AIS_InteractiveObject) anObject;
3744 // AIS_MultipleConnectedInteractive
3745 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3746 for (Standard_Integer i = 5; i < aNbShapes; ++i)
3748 TCollection_AsciiString anOriginObjectName (argv[i]);
3749 if (aName.IsEqual (anOriginObjectName))
3751 std::cout << "vconnect error: equal names for connected objects\n";
3754 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3756 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3757 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3758 if (anObject.IsNull())
3760 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3766 Standard_CString aName = anOriginObjectName.ToCString();
3767 TopoDS_Shape aTDShape = DBRep::Get (aName);
3768 if (aTDShape.IsNull())
3770 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3773 anObject = new AIS_Shape (aTDShape);
3774 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3777 if (anOriginObject.IsNull())
3779 anOriginObject = new AIS_MultipleConnectedInteractive();
3782 anOriginObject->Connect (anObject);
3784 if (anOriginObject.IsNull())
3786 std::cout << "vconect error : can't connect input objects\n";
3787 return 1; // TCL_ERROR
3790 // Get location data
3791 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3792 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3793 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3795 // Create transformation
3796 gp_Vec aTranslation (aXo, aYo, aZo);
3799 aTrsf.SetTranslationPart (aTranslation);
3800 TopLoc_Location aLocation (aTrsf);
3802 anOriginObject->SetLocalTransformation (aTrsf);
3804 // Check if there is another object with given name
3805 // and remove it from context
3806 if(GetMapOfAIS().IsBound2(aName))
3808 Handle(AIS_InteractiveObject) anObj =
3809 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3810 TheAISContext()->Remove(anObj, Standard_False);
3811 GetMapOfAIS().UnBind2(aName);
3814 // Bind connected object to its name
3815 GetMapOfAIS().Bind (anOriginObject, aName);
3817 // Display connected object
3818 TheAISContext()->Display (anOriginObject);
3823 //===============================================================================================
3824 //function : VConnectTo
3825 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3826 //Draw arg : vconnectto name Xo Yo Zo object
3827 //===============================================================================================
3829 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3830 Standard_Integer argc,
3834 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3835 if (aContext.IsNull())
3837 std::cout << "vconnect error : call vinit before\n";
3838 return 1; // TCL_ERROR
3843 std::cout << "vconnect error: expect at least 5 arguments\n";
3844 return 1; // TCL_ERROR
3848 Standard_Integer anArgIter = 1;
3849 TCollection_AsciiString aName (argv[anArgIter++]);
3850 Handle(AIS_InteractiveObject) anOriginObject;
3852 TCollection_AsciiString anOriginObjectName(argv[5]);
3853 if (aName.IsEqual (anOriginObjectName))
3855 std::cout << "vconnect error: equal names for connected objects\n";
3856 return 1; // TCL_ERROR
3858 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3860 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3861 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3862 if (anOriginObject.IsNull())
3864 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3865 return 1; // TCL_ERROR
3870 Standard_CString aName = anOriginObjectName.ToCString();
3871 TopoDS_Shape aTDShape = DBRep::Get (aName);
3872 if (aTDShape.IsNull())
3874 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3875 return 1; // TCL_ERROR
3877 anOriginObject = new AIS_Shape (aTDShape);
3880 // Get location data
3881 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3882 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3883 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3885 // Create transformation
3886 gp_Vec aTranslation (aXo, aYo, aZo);
3889 aTrsf.SetTranslationPart (aTranslation);
3891 Handle(AIS_ConnectedInteractive) aConnected;
3893 aConnected = new AIS_ConnectedInteractive();
3895 aConnected->Connect (anOriginObject, aTrsf);
3897 // Check if there is another object with given name
3898 // and remove it from context
3899 if(GetMapOfAIS().IsBound2(aName))
3901 Handle(AIS_InteractiveObject) anObj =
3902 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3903 TheAISContext()->Remove(anObj, Standard_False);
3904 GetMapOfAIS().UnBind2(aName);
3907 // Bind connected object to its name
3908 GetMapOfAIS().Bind (aConnected, aName);
3910 // Display connected object
3911 TheAISContext()->Display (aConnected);
3916 //=======================================================================
3917 //function : VDisconnect
3919 //=======================================================================
3920 static Standard_Integer VDisconnect (Draw_Interpretor& di,
3921 Standard_Integer argc,
3924 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3925 if (aContext.IsNull())
3927 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3933 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
3937 TCollection_AsciiString aName (argv[1]);
3938 TCollection_AsciiString anObject (argv[2]);
3939 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
3942 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3943 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3944 if (!aMap.IsBound2 (aName) )
3946 std::cout << "Use 'vdisplay' before" << "\n";
3950 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3951 if (anAssembly.IsNull())
3953 di << "Not an assembly" << "\n";
3957 Handle(AIS_InteractiveObject) anIObj;
3958 if (!aMap.IsBound2 (anObject))
3960 // try to interpret second argument as child number
3961 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
3963 Standard_Integer aCounter = 1;
3964 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3966 if (aCounter == anObjectNumber)
3968 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
3976 std::cout << "Use 'vdisplay' before" << "\n";
3981 // if object was found by name
3982 if (anIObj.IsNull())
3984 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
3987 anAssembly->Disconnect (anIObj);
3988 aContext->UpdateCurrentViewer();
3993 //=======================================================================
3994 //function : VAddConnected
3996 //=======================================================================
3997 static Standard_Integer VAddConnected (Draw_Interpretor& di,
3998 Standard_Integer argc,
4001 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4002 if (aContext.IsNull())
4004 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4010 std::cout << argv[0] << " error: expect 5 arguments\n";
4014 TCollection_AsciiString aName (argv[1]);
4015 TCollection_AsciiString anObject (argv[5]);
4016 Standard_Real aX = Draw::Atof (argv[2]);
4017 Standard_Real aY = Draw::Atof (argv[3]);
4018 Standard_Real aZ = Draw::Atof (argv[4]);
4021 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4022 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4023 if (!aMap.IsBound2 (aName) )
4025 std::cout << "Use 'vdisplay' before" << "\n";
4029 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4030 if (anAssembly.IsNull())
4032 di << "Not an assembly" << "\n";
4036 Handle(AIS_InteractiveObject) anIObj;
4037 if (!aMap.IsBound2 (anObject))
4039 std::cout << "Use 'vdisplay' before" << "\n";
4043 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4046 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4048 anAssembly->Connect (anIObj, aTrsf);
4049 TheAISContext()->Display (anAssembly);
4050 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4051 aContext->UpdateCurrentViewer();
4056 //=======================================================================
4057 //function : VListConnected
4059 //=======================================================================
4060 static Standard_Integer VListConnected (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" << "\n";
4077 TCollection_AsciiString aName (argv[1]);
4080 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4081 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4082 if (!aMap.IsBound2 (aName) )
4084 std::cout << "Use 'vdisplay' before" << "\n";
4088 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4089 if (anAssembly.IsNull())
4091 std::cout << "Not an assembly" << "\n";
4095 std::cout << "Children of " << aName << ":\n";
4097 Standard_Integer aCounter = 1;
4098 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4100 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4102 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
4103 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4106 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4108 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4109 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4111 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4113 std::cout << std::endl;
4123 //! Checks if theMode is already turned on for theObj.
4124 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4125 const Handle(AIS_InteractiveObject)& theObj,
4126 const Standard_Integer theMode)
4128 TColStd_ListOfInteger anActiveModes;
4129 theAISContext->ActivatedModes (theObj, anActiveModes);
4130 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4132 if (aModeIt.Value() == theMode)
4134 return Standard_True;
4137 return Standard_False;
4141 //===============================================================================================
4142 //function : VSetSelectionMode
4143 //purpose : Sets input selection mode for input object or for all displayed objects
4144 //Draw arg : vselmode [object] mode On/Off (1/0)
4145 //===============================================================================================
4146 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4147 Standard_Integer theArgc,
4148 const char** theArgv)
4151 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4152 if (anAISContext.IsNull())
4154 std::cerr << "Call vinit before!" << std::endl;
4158 // Check the arguments
4159 if (theArgc != 3 && theArgc != 4)
4161 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4162 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
4166 // get objects to change selection mode
4167 AIS_ListOfInteractive aTargetIOs;
4170 anAISContext->DisplayedObjects (aTargetIOs);
4174 // Check if there is an object with given name in context
4175 const TCollection_AsciiString aNameIO (theArgv[1]);
4176 if (GetMapOfAIS().IsBound2 (aNameIO))
4178 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4181 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
4184 aTargetIOs.Append (anIO);
4188 const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]);
4189 const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]);
4190 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4192 anAISContext->CloseLocalContext();
4195 if (aSelectionMode == 0)
4199 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4201 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4202 if (!InList (anAISContext, anIO, aSelectionMode))
4204 anAISContext->Activate (anIO);
4210 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4212 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4213 if (InList (anAISContext, anIO, aSelectionMode))
4215 anAISContext->Deactivate (anIO);
4221 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
4223 if (!anAISContext->HasOpenedContext())
4225 anAISContext->OpenLocalContext (Standard_False);
4228 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4230 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4231 if (!InList (anAISContext, anIO, aSelectionMode))
4233 anAISContext->Load (anIO, -1, Standard_True);
4234 anAISContext->Activate (anIO, aSelectionMode);
4239 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4241 if (!anAISContext->HasOpenedContext())
4246 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4248 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4249 if (InList (anAISContext, anIO, aSelectionMode))
4251 anAISContext->Deactivate (anIO, aSelectionMode);
4259 //===============================================================================================
4260 //function : VSelectionNext
4262 //===============================================================================================
4263 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4264 Standard_Integer /*theArgsNb*/,
4265 const char** /*theArgVec*/)
4268 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4269 Handle(V3d_View) aView = ViewerTest::CurrentView();
4271 if (anAISContext.IsNull())
4273 std::cerr << "Call vinit before!" << std::endl;
4277 anAISContext->HilightNextDetected(aView);
4281 //===============================================================================================
4282 //function : VSelectionPrevious
4284 //===============================================================================================
4285 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4286 Standard_Integer /*theArgsNb*/,
4287 const char** /*theArgVec*/)
4290 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4291 Handle(V3d_View) aView = ViewerTest::CurrentView();
4293 if (anAISContext.IsNull())
4295 std::cerr << "Call vinit before!" << std::endl;
4299 anAISContext->HilightPreviousDetected(aView);
4304 //==========================================================================
4306 //purpose : creates Triangle based on AIS_InteractiveObject.
4307 // This class was implemented for testing Select3D_SensitiveTriangle
4308 //===========================================================================
4309 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4310 class Triangle: public AIS_InteractiveObject
4314 DEFINE_STANDARD_RTTI(FilledCircle);
4315 Triangle (const gp_Pnt& theP1,
4316 const gp_Pnt& theP2,
4317 const gp_Pnt& theP3);
4319 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4320 const Handle(Prs3d_Presentation)& thePresentation,
4321 const Standard_Integer theMode);
4323 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4324 const Standard_Integer theMode);
4330 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4331 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
4333 Triangle::Triangle (const gp_Pnt& theP1,
4334 const gp_Pnt& theP2,
4335 const gp_Pnt& theP3)
4342 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4343 const Handle(Prs3d_Presentation)& thePresentation,
4344 const Standard_Integer /*theMode*/)
4346 thePresentation->Clear();
4348 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4349 anEdgeMaker2(myPoint2, myPoint3),
4350 anEdgeMaker3(myPoint3, myPoint1);
4352 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4353 anEdge2 = anEdgeMaker2.Edge(),
4354 anEdge3 = anEdgeMaker3.Edge();
4355 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4358 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4359 TopoDS_Wire aWire = aWireMaker.Wire();
4360 if(aWire.IsNull()) return;
4362 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4363 TopoDS_Face aFace = aFaceMaker.Face();
4364 if(aFace.IsNull()) return;
4366 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4369 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
4370 const Standard_Integer /*theMode*/)
4372 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4373 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4374 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4375 theSelection->Add(aSensTriangle);
4378 //===========================================================================
4379 //function : VTriangle
4380 //Draw arg : vtriangle Name PointName PointName PointName
4381 //purpose : creates and displays Triangle
4382 //===========================================================================
4385 //purpose : checks if the object with theName is AIS_Point,
4386 // if yes initialize thePoint from MapOfAIS
4387 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4388 Handle(AIS_Point)& thePoint)
4390 Handle(AIS_InteractiveObject) anObject =
4391 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4392 if(anObject.IsNull() ||
4393 anObject->Type() != AIS_KOI_Datum ||
4394 anObject->Signature() != 1)
4396 return Standard_False;
4398 thePoint = Handle(AIS_Point)::DownCast(anObject);
4399 if(thePoint.IsNull())
4400 return Standard_False;
4401 return Standard_True;
4405 //purpose: checks if thePoint1 is equal to thePoint2
4406 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4407 const Handle(Geom_CartesianPoint)& thePoint2)
4409 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4410 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4411 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4413 return Standard_True;
4415 return Standard_False;
4418 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4419 Standard_Integer argc,
4425 std::cout<<"vtriangle error: expects 4 argumnets\n";
4426 return 1; // TCL_ERROR
4429 TheAISContext()->CloseAllContexts();
4431 // Get and check values
4432 TCollection_AsciiString aName(argv[1]);
4434 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4435 if (!IsPoint(argv[2], aPoint1))
4437 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4438 return 1; // TCL_ERROR
4440 if (!IsPoint(argv[3], aPoint2))
4442 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4443 return 1; // TCL_ERROR
4445 if (!IsPoint(argv[4], aPoint3))
4447 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4448 return 1; // TCL_ERROR
4451 // Check that points are different
4452 Handle(Geom_CartesianPoint) aCartPoint1 =
4453 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4454 Handle(Geom_CartesianPoint) aCartPoint2 =
4455 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4456 // Test aPoint1 = aPoint2
4457 if (IsMatch(aCartPoint1, aCartPoint2))
4459 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4460 return 1; // TCL_ERROR
4462 // Test aPoint2 = aPoint3
4463 Handle(Geom_CartesianPoint) aCartPoint3 =
4464 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4465 if (IsMatch(aCartPoint2, aCartPoint3))
4467 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4468 return 1; // TCL_ERROR
4470 // Test aPoint3 = aPoint1
4471 if (IsMatch(aCartPoint1, aCartPoint3))
4473 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4474 return 1; // TCL_ERROR
4478 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4480 aCartPoint3->Pnt());
4482 // Check if there is an object with given name
4483 // and remove it from context
4484 if (GetMapOfAIS().IsBound2(aName))
4486 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4487 Handle(AIS_InteractiveObject) anInterObj =
4488 Handle(AIS_InteractiveObject)::DownCast(anObj);
4489 TheAISContext()->Remove(anInterObj, Standard_False);
4490 GetMapOfAIS().UnBind2(aName);
4493 // Bind triangle to its name
4494 GetMapOfAIS().Bind(aTriangle, aName);
4497 TheAISContext()->Display(aTriangle);
4501 //class : SegmentObject
4502 //purpose: creates segment based on AIS_InteractiveObject.
4503 // This class was implemented for testing Select3D_SensitiveCurve
4504 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4505 class SegmentObject: public AIS_InteractiveObject
4509 DEFINE_STANDARD_RTTI(SegmentObject);
4510 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4512 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4513 const Handle(Prs3d_Presentation)& thePresentation,
4514 const Standard_Integer theMode);
4516 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4517 const Standard_Integer theMode);
4522 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4523 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4525 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4531 void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4532 const Handle(Prs3d_Presentation) &thePresentation,
4533 const Standard_Integer /*theMode*/)
4535 thePresentation->Clear();
4536 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4537 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4538 if (anEdge.IsNull())
4540 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4541 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4544 void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
4545 const Standard_Integer /*theMode*/)
4547 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4548 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4549 anArray->SetValue(1, myPoint1);
4550 anArray->SetValue(2, myPoint2);
4551 Handle(Select3D_SensitiveCurve) aSensCurve =
4552 new Select3D_SensitiveCurve(anOwner, anArray);
4553 theSelection->Add(aSensCurve);
4556 //=======================================================================
4557 //function : VSegment
4558 //Draw args : vsegment Name PointName PointName
4559 //purpose : creates and displays Segment
4560 //=======================================================================
4561 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4562 Standard_Integer argc,
4568 std::cout<<"vsegment error: expects 3 arguments\n";
4569 return 1; // TCL_ERROR
4572 TheAISContext()->CloseAllContexts();
4574 // Get and check arguments
4575 TCollection_AsciiString aName(argv[1]);
4576 Handle(AIS_Point) aPoint1, aPoint2;
4577 if (!IsPoint(argv[2], aPoint1))
4579 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4580 return 1; // TCL_ERROR
4582 if (!IsPoint(argv[3], aPoint2))
4584 std::cout<<"vsegment error: the 3d argument should be a point\n";
4585 return 1; // TCL_ERROR
4587 //Check that points are different
4588 Handle(Geom_CartesianPoint) aCartPoint1 =
4589 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4590 Handle(Geom_CartesianPoint) aCartPoint2 =
4591 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4592 if(IsMatch(aCartPoint1, aCartPoint2))
4594 std::cout<<"vsegment error: equal points\n";
4595 return 1; // TCL_ERROR
4599 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4600 // Check if there is an object with given name
4601 // and remove it from context
4602 if (GetMapOfAIS().IsBound2(aName))
4604 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4605 Handle(AIS_InteractiveObject) anInterObj =
4606 Handle(AIS_InteractiveObject)::DownCast(anObj);
4607 TheAISContext()->Remove(anInterObj, Standard_False);
4608 GetMapOfAIS().UnBind2(aName);
4611 // Bind segment to its name
4612 GetMapOfAIS().Bind(aSegment, aName);
4615 TheAISContext()->Display(aSegment);
4619 //=======================================================================
4620 //function : VObjZLayer
4621 //purpose : Set or get z layer id for presentable object
4622 //=======================================================================
4624 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4625 Standard_Integer argc,
4628 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4629 if (aContext.IsNull())
4631 di << argv[0] << "Call 'vinit' before!\n";
4636 TCollection_AsciiString aOperation;
4638 aOperation = TCollection_AsciiString (argv [1]);
4640 // check for correct arguments
4641 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4642 !(argc == 3 && aOperation.IsEqual ("get")))
4644 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4645 di << " set - set layer id for interactive object, layerid - z layer id\n";
4646 di << " get - get layer id of interactive object\n";
4647 di << " argument layerid should be passed for set operation only\n";
4652 TCollection_AsciiString aName (argv[2]);
4653 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4654 if (!aMap.IsBound2 (aName))
4656 di << "Use 'vdisplay' before" << "\n";
4660 // find interactive object
4661 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4662 Handle(AIS_InteractiveObject) anInterObj =
4663 Handle(AIS_InteractiveObject)::DownCast (anObj);
4664 if (anInterObj.IsNull())
4666 di << "Not an AIS interactive object!\n";
4670 // process operation
4671 if (aOperation.IsEqual ("set"))
4673 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4674 aContext->SetZLayer (anInterObj, aLayerId);
4676 else if (aOperation.IsEqual ("get"))
4678 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4684 //=======================================================================
4685 //function : VPolygonOffset
4686 //purpose : Set or get polygon offset parameters
4687 //=======================================================================
4688 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4689 Standard_Integer argc,
4692 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4693 if (aContext.IsNull())
4695 std::cout << argv[0] << " Call 'vinit' before!\n";
4699 if (argc > 2 && argc != 5)
4701 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4702 "without arguments prints the default values" << std::endl;
4707 Handle(AIS_InteractiveObject) anInterObj;
4710 TCollection_AsciiString aName (argv[1]);
4711 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4712 if (!aMap.IsBound2 (aName))
4714 std::cout << "Use 'vdisplay' before" << std::endl;
4718 // find interactive object
4719 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4720 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4721 if (anInterObj.IsNull())
4723 std::cout << "Not an AIS interactive object!" << std::endl;
4728 Standard_Integer aMode;
4729 Standard_ShortReal aFactor, aUnits;
4732 aMode = Draw::Atoi(argv[2]);
4733 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4734 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4736 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4737 aContext->UpdateCurrentViewer();
4742 if (anInterObj->HasPolygonOffsets())
4744 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4745 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4746 std::cout << "\tMode: " << aMode << std::endl;
4747 std::cout << "\tFactor: " << aFactor << std::endl;
4748 std::cout << "\tUnits: " << aUnits << std::endl;
4753 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4757 std::cout << "Default polygon offset parameters:" << std::endl;
4758 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4759 std::cout << "\tMode: " << aMode << std::endl;
4760 std::cout << "\tFactor: " << aFactor << std::endl;
4761 std::cout << "\tUnits: " << aUnits << std::endl;
4766 //=======================================================================
4767 //function : VShowFaceBoundaries
4768 //purpose : Set face boundaries drawing on/off for ais object
4769 //=======================================================================
4770 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4771 Standard_Integer argc,
4774 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4775 if (aContext.IsNull ())
4777 std::cout << argv[0] << " Call 'vinit' before!\n";
4781 if ((argc != 3 && argc < 6) || argc > 8)
4783 std::cout << "Usage :\n " << argv[0]
4784 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4785 << " ObjectName - name of AIS interactive object. \n"
4786 << " if ObjectName = \"\", then set as default\n"
4787 << " settings for all newly displayed objects\n"
4788 << " isOn - flag indicating whether the boundaries\n"
4789 << " should be turned on or off (can be set\n"
4790 << " to 0 (off) or 1 (on)).\n"
4791 << " R, G, B - red, green and blue components of boundary\n"
4792 << " color in range (0 - 255).\n"
4793 << " (default is (0, 0, 0)\n"
4794 << " LineWidth - line width\n"
4795 << " (default is 1)\n"
4796 << " LineStyle - line fill style :\n"
4801 << " (default is solid)";
4805 TCollection_AsciiString aName (argv[1]);
4807 Quantity_Parameter aRed = 0.0;
4808 Quantity_Parameter aGreen = 0.0;
4809 Quantity_Parameter aBlue = 0.0;
4810 Standard_Real aWidth = 1.0;
4811 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4814 Handle(AIS_InteractiveObject) anInterObj;
4816 // if name is empty - apply attributes for default aspect
4817 if (!aName.IsEmpty ())
4819 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4820 if (!aMap.IsBound2 (aName))
4822 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4826 // find interactive object
4827 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4828 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4829 if (anInterObj.IsNull ())
4831 std::cout << "Not an AIS interactive object!" << std::endl;
4836 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4837 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4839 // turn boundaries on/off
4840 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
4841 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4843 // set boundary line color
4847 aRed = Draw::Atof (argv[3])/255.;
4848 aGreen = Draw::Atof (argv[4])/255.;
4849 aBlue = Draw::Atof (argv[5])/255.;
4855 aWidth = (Standard_Real)Draw::Atof (argv[6]);
4858 // select appropriate line type
4861 switch (Draw::Atoi (argv[7]))
4863 case 1: aLineType = Aspect_TOL_DASH; break;
4864 case 2: aLineType = Aspect_TOL_DOT; break;
4865 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4867 aLineType = Aspect_TOL_SOLID;
4871 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4873 Handle(Prs3d_LineAspect) aBoundaryAspect =
4874 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4876 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4878 TheAISContext()->Redisplay (anInterObj);
4883 // This class is used for testing markers.
4884 DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4885 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4890 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4891 const Standard_Integer& thePointsOnSide,
4892 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4894 myStartPoint = theStartPoint;
4895 myPointsOnSide = thePointsOnSide;
4896 myMarkerAspect = theMarkerAspect;
4899 DEFINE_STANDARD_RTTI(MyPArrayObject);
4903 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4904 const Handle(Prs3d_Presentation)& aPresentation,
4905 const Standard_Integer aMode);
4907 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4908 const Standard_Integer /*theMode*/);
4912 gp_XYZ myStartPoint;
4913 Standard_Integer myPointsOnSide;
4914 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4917 IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4918 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4920 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4921 const Handle(Prs3d_Presentation)& aPresentation,
4922 const Standard_Integer /*aMode*/)
4924 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4925 if (myPointsOnSide == 1)
4927 anArray->AddVertex (myStartPoint);
4931 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4933 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4935 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4937 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4938 anArray->SetVertexColor (anArray->VertexNumber(),
4941 k / myPointsOnSide);
4947 aPresentation->Clear();
4948 if (!myMarkerAspect.IsNull())
4950 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4952 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4955 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4956 const Standard_Integer /*theMode*/)
4958 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4960 if (myPointsOnSide == 1)
4962 gp_Pnt aPoint (myStartPoint);
4963 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4964 theSelection->Add (aSensetivePoint);
4968 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4970 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4972 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4974 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4975 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4976 theSelection->Add (aSensetivePoint);
4982 //=======================================================================
4983 //function : VMarkersTest
4984 //purpose : Draws an array of markers for testing purposes.
4985 //=======================================================================
4986 static Standard_Integer VMarkersTest (Draw_Interpretor&,
4987 Standard_Integer theArgNb,
4988 const char** theArgVec)
4990 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4991 if (aContext.IsNull())
4993 std::cerr << "Call 'vinit' before!\n";
4999 std::cerr << "Usage :\n " << theArgVec[0]
5000 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5004 Standard_Integer anArgIter = 1;
5006 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5007 TCollection_AsciiString aFileName;
5008 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5009 Atof (theArgVec[anArgIter + 1]),
5010 Atof (theArgVec[anArgIter + 2]));
5013 Standard_Integer aPointsOnSide = 10;
5014 Standard_Integer aMarkerType = -1;
5015 Standard_Real aScale = 1.0;
5016 for (; anArgIter < theArgNb; ++anArgIter)
5018 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5019 if (anArg.Search ("PointsOnSide=") > -1)
5021 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5023 else if (anArg.Search ("MarkerType=") > -1)
5025 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5027 else if (anArg.Search ("Scale=") > -1)
5029 aScale = anArg.Token ("=", 2).RealValue();
5031 else if (anArg.Search ("FileName=") > -1)
5033 aFileName = anArg.Token ("=", 2);
5037 std::cerr << "Wrong argument: " << anArg << "\n";
5042 Handle(Graphic3d_AspectMarker3d) anAspect;
5043 Handle(Image_AlienPixMap) anImage;
5044 Quantity_Color aColor (Quantity_NOC_GREEN1);
5045 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5046 && !aFileName.IsEmpty())
5048 anImage = new Image_AlienPixMap();
5049 if (!anImage->Load (aFileName))
5051 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5054 anAspect = new Graphic3d_AspectMarker3d (anImage);
5058 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5061 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5062 VDisplayAISObject (aName, aMarkersArray);
5067 //! Auxiliary function to parse font aspect style argument
5068 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5069 Font_FontAspect& theAspect)
5071 if (theArg == "regular"
5072 || *theArg.ToCString() == 'r')
5074 theAspect = Font_FA_Regular;
5075 return Standard_True;
5077 else if (theArg == "bolditalic")
5079 theAspect = Font_FA_BoldItalic;
5080 return Standard_True;
5082 else if (theArg == "bold"
5083 || *theArg.ToCString() == 'b')
5085 theAspect = Font_FA_Bold;
5086 return Standard_True;
5088 else if (theArg == "italic"
5089 || *theArg.ToCString() == 'i')
5091 theAspect = Font_FA_Italic;
5092 return Standard_True;
5094 return Standard_False;
5097 //! Auxiliary function
5098 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5102 case Font_FA_Regular: return "regular";
5103 case Font_FA_BoldItalic: return "bolditalic";
5104 case Font_FA_Bold: return "bold";
5105 case Font_FA_Italic: return "italic";
5106 default: return "undefined";
5110 //=======================================================================
5111 //function : TextToBrep
5112 //purpose : Tool for conversion text to occt-shapes
5113 //=======================================================================
5115 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5116 Standard_Integer theArgNb,
5117 const char** theArgVec)
5122 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5126 Standard_Integer anArgIter = 1;
5127 Standard_CString aResName = theArgVec[anArgIter++];
5128 Standard_CString aText = theArgVec[anArgIter++];
5129 Standard_CString aFontName = theArgVec[anArgIter++];
5130 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
5132 Font_BRepFont aFont;
5133 Font_FontAspect aFontAspect = Font_FA_Regular;
5134 Standard_Boolean isCompositeCurve = Standard_False;
5135 gp_Ax3 aPenAx3 (gp::XOY());
5137 while (anArgIter < theArgNb)
5139 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
5140 TCollection_AsciiString anArgCase (anArg);
5141 anArgCase.LowerCase();
5142 if (anArgCase.Search ("x=") > -1)
5144 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
5146 else if (anArgCase.Search ("y=") > -1)
5148 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
5150 else if (anArgCase.Search ("z=") > -1)
5152 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
5154 else if (anArgCase.Search ("composite=") > -1)
5156 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
5158 else if (parseFontStyle (anArgCase, aFontAspect))
5164 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5168 aFont.SetCompositeCurveMode (isCompositeCurve);
5169 if (!aFont.Init (aFontName, aFontAspect, aSize))
5171 std::cerr << "Font initialization error\n";
5175 aPenAx3.SetLocation (aPenLoc);
5176 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
5180 //=======================================================================
5182 //purpose : Font management
5183 //=======================================================================
5185 static int VFont (Draw_Interpretor& theDI,
5186 Standard_Integer theArgNb,
5187 const char** theArgVec)
5189 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5192 // just print the list of available fonts
5193 Standard_Boolean isFirst = Standard_True;
5194 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5195 anIter.More(); anIter.Next())
5197 const Handle(Font_SystemFont)& aFont = anIter.Value();
5203 theDI << aFont->FontName()->String()
5204 << " " << fontStyleString (aFont->FontAspect())
5205 << " " << aFont->FontPath()->String();
5206 isFirst = Standard_False;
5211 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5213 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5214 TCollection_AsciiString anArgCase (anArg);
5215 anArgCase.LowerCase();
5216 if (anArgCase == "find")
5218 if (++anArgIter >= theArgNb)
5220 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5224 Standard_CString aFontName = theArgVec[anArgIter];
5225 Font_FontAspect aFontAspect = Font_FA_Undefined;
5226 if (++anArgIter < theArgNb)
5228 anArgCase = theArgVec[anArgIter];
5229 anArgCase.LowerCase();
5230 if (!parseFontStyle (anArgCase, aFontAspect))
5235 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5238 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5242 theDI << aFont->FontName()->String()
5243 << " " << fontStyleString (aFont->FontAspect())
5244 << " " << aFont->FontPath()->String();
5246 else if (anArgCase == "add"
5247 || anArgCase == "register")
5249 if (++anArgIter >= theArgNb)
5251 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5254 Standard_CString aFontPath = theArgVec[anArgIter];
5255 Standard_CString aFontName = NULL;
5256 Font_FontAspect aFontAspect = Font_FA_Undefined;
5257 if (++anArgIter < theArgNb)
5259 if (!parseFontStyle (anArgCase, aFontAspect))
5261 aFontName = theArgVec[anArgIter];
5263 if (++anArgIter < theArgNb)
5265 anArgCase = theArgVec[anArgIter];
5266 anArgCase.LowerCase();
5267 if (!parseFontStyle (anArgCase, aFontAspect))
5274 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5277 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5281 if (aFontAspect != Font_FA_Undefined
5282 || aFontName != NULL)
5284 if (aFontAspect == Font_FA_Undefined)
5286 aFontAspect = aFont->FontAspect();
5288 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5289 if (aFontName != NULL)
5291 aName = new TCollection_HAsciiString (aFontName);
5293 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5296 aMgr->RegisterFont (aFont, Standard_True);
5297 theDI << aFont->FontName()->String()
5298 << " " << fontStyleString (aFont->FontAspect())
5299 << " " << aFont->FontPath()->String();
5303 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5310 //=======================================================================
5311 //function : VSetEdgeType
5312 //purpose : Edges type management
5313 //=======================================================================
5315 static int VSetEdgeType (Draw_Interpretor& theDI,
5316 Standard_Integer theArgNum,
5317 const char** theArgs)
5319 if (theArgNum < 4 || theArgNum > 9)
5321 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5322 << theArgs[0] << "' for more information.\n";
5326 Standard_Boolean isForceRedisplay = Standard_False;
5329 TCollection_AsciiString aName(theArgs[1]);
5330 if (!GetMapOfAIS().IsBound2 (aName))
5332 theDI << theArgs[0] << " error: wrong object name.\n";
5336 Handle(AIS_InteractiveObject) anObject =
5337 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5339 // Enable trianle edge mode
5340 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5343 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5345 TCollection_AsciiString aParam ((theArgs[anIt]));
5346 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5348 if (aParam.IsEqual ("-type"))
5350 if (theArgNum <= anIt + 1)
5352 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5353 << aParam.ToCString() << "'.\n";
5357 TCollection_AsciiString aType = theArgs[++anIt];
5360 if (aType.IsEqual ("SOLID"))
5362 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5364 else if (aType.IsEqual ("DASH"))
5366 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5368 else if (aType.IsEqual ("DOT"))
5370 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5372 else if (aType.IsEqual ("DOTDASH"))
5374 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5378 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5383 else if (aParam.IsEqual ("-color"))
5385 if (theArgNum <= anIt + 3)
5387 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5388 << aParam.ToCString() << "'.\n";
5392 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5393 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5394 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5395 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5396 aG > 1 ? aG / 255.0 : aG,
5397 aB > 1 ? aB / 255.0 : aB,
5400 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5402 else if (aParam.IsEqual ("-force"))
5404 isForceRedisplay = Standard_True;
5408 theDI << theArgs[0] << " error: unknown parameter '"
5409 << aParam.ToCString() << "'.\n";
5415 // Update shape presentation as aspect parameters were changed
5416 if (isForceRedisplay)
5418 ViewerTest::GetAISContext()->Redisplay (anObject);
5422 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5426 ViewerTest::CurrentView()->Redraw();
5431 //=======================================================================
5432 //function : VUnsetEdgeType
5433 //purpose : Unsets edges visibility in shading mode
5434 //=======================================================================
5436 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5437 Standard_Integer theArgNum,
5438 const char** theArgs)
5440 if (theArgNum != 2 && theArgNum != 3)
5442 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5443 << theArgs[0] << "' for more information.\n";
5447 Standard_Boolean isForceRedisplay = Standard_False;
5450 TCollection_AsciiString aName (theArgs[1]);
5451 if (!GetMapOfAIS().IsBound2 (aName))
5453 theDI << theArgs[0] << " error: wrong object name.\n";
5457 Handle(AIS_InteractiveObject) anObject =
5458 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5460 // Enable trianle edge mode
5461 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5466 TCollection_AsciiString aParam ((theArgs[2]));
5467 if (aParam.IsEqual ("-force"))
5469 isForceRedisplay = Standard_True;
5473 theDI << theArgs[0] << " error: unknown parameter '"
5474 << aParam.ToCString() << "'.\n";
5479 // Update shape presentation as aspect parameters were changed
5480 if (isForceRedisplay)
5482 ViewerTest::GetAISContext()->Redisplay (anObject);
5486 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5490 ViewerTest::CurrentView()->Redraw();
5496 //=======================================================================
5497 //function : VVertexMode
5498 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5499 //=======================================================================
5501 static int VVertexMode (Draw_Interpretor& theDI,
5502 Standard_Integer theArgNum,
5503 const char** theArgs)
5505 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5506 if (aContext.IsNull())
5508 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5512 // No arguments --> print the current default vertex draw mode
5515 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5516 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5520 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5521 TCollection_AsciiString aParam (theArgs[1]);
5522 if (aParam == "-set")
5526 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5527 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5531 TCollection_AsciiString aModeStr (theArgs[2]);
5532 Prs3d_VertexDrawMode aNewMode =
5533 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5534 (aModeStr == "all" ? Prs3d_VDM_All :
5535 Prs3d_VDM_Inherited);
5537 Standard_Boolean aRedrawNeeded = Standard_False;
5538 AIS_ListOfInteractive anObjs;
5540 // No object(s) specified -> use all displayed
5543 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5544 aContext->DisplayedObjects (anObjs);
5545 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5546 aRedrawNeeded = Standard_True;
5549 Handle(AIS_InteractiveObject) anObject;
5550 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5552 TCollection_AsciiString aName (theArgs[aCount]);
5553 if (!GetMapOfAIS().IsBound2 (aName))
5555 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5558 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5559 anObjs.Append (anObject);
5562 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5564 anObject = anIt.Value();
5565 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5566 aContext->Redisplay (anObject, Standard_False);
5567 aRedrawNeeded = Standard_True;
5571 ViewerTest::CurrentView()->Redraw();
5578 std::cout << "Error: invalid number of arguments" << std::endl;
5579 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5583 // One argument (object name) --> print the current vertex draw mode for the object
5584 Handle(AIS_InteractiveObject) anObject =
5585 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5586 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5587 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5591 //=======================================================================
5592 //function : VPointCloud
5593 //purpose : Create interactive object for arbitary set of points.
5594 //=======================================================================
5595 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5596 Standard_Integer theArgNum,
5597 const char** theArgs)
5599 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5600 if (anAISContext.IsNull())
5602 std::cerr << "Error: no active view!\n";
5606 // command to execute
5609 CloudForShape, // generate point cloud for shape
5610 CloudSphere, // generate point cloud for generic sphere
5614 // count number of non-optional command arguments
5615 Command aCmd = Unknow;
5616 Standard_Integer aCmdArgs = 0;
5617 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5619 Standard_CString anArg = theArgs[anArgIter];
5620 TCollection_AsciiString aFlag (anArg);
5622 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5629 case 2 : aCmd = CloudForShape; break;
5630 case 7 : aCmd = CloudSphere; break;
5632 std::cout << "Error: wrong number of arguments! See usage:\n";
5633 theDI.PrintHelp (theArgs[0]);
5638 Standard_Boolean toRandColors = Standard_False;
5639 Standard_Boolean hasNormals = Standard_True;
5640 Standard_Boolean isSetArgNorm = Standard_False;
5641 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5643 Standard_CString anArg = theArgs[anArgIter];
5644 TCollection_AsciiString aFlag (anArg);
5646 if (aFlag == "-randcolors"
5647 || aFlag == "-randcolor")
5649 if (isSetArgNorm && hasNormals)
5651 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5654 toRandColors = Standard_True;
5655 hasNormals = Standard_False;
5657 else if (aFlag == "-normals"
5658 || aFlag == "-normal")
5662 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5665 isSetArgNorm = Standard_True;
5666 hasNormals = Standard_True;
5668 else if (aFlag == "-nonormals"
5669 || aFlag == "-nonormal")
5671 isSetArgNorm = Standard_True;
5672 hasNormals = Standard_False;
5676 Standard_CString aName = theArgs[1];
5678 // generate arbitrary set of points
5679 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5680 if (aCmd == CloudForShape)
5682 Standard_CString aShapeName = theArgs[2];
5683 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5685 if (aShape.IsNull())
5687 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5691 // calculate number of points
5692 TopLoc_Location aLocation;
5693 Standard_Integer aNbPoints = 0;
5694 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5696 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5697 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5698 if (!aTriangulation.IsNull())
5700 aNbPoints += aTriangulation->NbNodes();
5705 std::cout << "Error: shape should be triangulated!\n";
5709 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5710 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5712 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5713 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5714 if (aTriangulation.IsNull())
5719 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5720 const gp_Trsf& aTrsf = aLocation.Transformation();
5722 // extract normals from nodes
5723 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5726 Poly_Connect aPolyConnect (aTriangulation);
5727 StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
5730 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5732 gp_Pnt aPoint = aNodes (aNodeIter);
5733 if (!aLocation.IsIdentity())
5735 aPoint.Transform (aTrsf);
5738 aNormals (aNodeIter).Transform (aTrsf);
5742 // add vertex into array of points
5743 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5746 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5747 1.0, 0.5, Quantity_TOC_HLS);
5748 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5753 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5758 else if (aCmd == CloudSphere)
5760 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5761 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5762 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5763 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5764 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5766 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5767 aDistribution.LowerCase();
5768 if ( aDistribution != "surface" && aDistribution != "volume" )
5770 std::cout << "Error: wrong arguments! See usage:\n";
5771 theDI.PrintHelp (theArgs[0]);
5774 Standard_Boolean isSurface = aDistribution == "surface";
5776 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5778 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5779 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5781 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5782 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5783 Standard_Real aDistance = isSurface ?
5784 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5786 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5788 Cos (anAlpha) * Cos (aBeta));
5789 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5791 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5794 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5795 1.0, 0.5, Quantity_TOC_HLS);
5796 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5801 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5806 // set array of points in point cloud object
5807 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5808 aPointCloud->SetPoints (anArrayPoints);
5809 VDisplayAISObject (aName, aPointCloud);
5813 //=======================================================================
5814 //function : VPriority
5815 //purpose : Prints or sets the display priority for an object
5816 //=======================================================================
5818 static int VPriority (Draw_Interpretor& theDI,
5819 Standard_Integer theArgNum,
5820 const char** theArgs)
5822 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5823 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5824 if (aContext.IsNull())
5826 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5830 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5831 Standard_Integer aPriority = -1;
5832 Standard_Integer aNbArgs = theArgNum;
5833 if (aLastArg.IsIntegerValue())
5835 aPriority = aLastArg.IntegerValue();
5837 if (aPriority < 0 || aPriority > 10)
5839 std::cout << "Error: the specified display priority value '" << aLastArg
5840 << "' is outside the valid range [0..10]" << std::endl;
5846 anUpdateTool.Invalidate();
5851 std::cout << "Error: wrong number of arguments! See usage:\n";
5852 theDI.PrintHelp (theArgs[0]);
5856 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5858 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5863 TCollection_AsciiString aName (theArgs[anArgIter]);
5864 Handle(AIS_InteractiveObject) anIObj;
5865 if (GetMapOfAIS().IsBound2 (aName))
5867 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5870 if (anIObj.IsNull())
5872 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5878 theDI << aContext->DisplayPriority (anIObj) << " ";
5882 aContext->SetDisplayPriority (anIObj, aPriority);
5888 //=======================================================================
5889 //function : ObjectsCommands
5891 //=======================================================================
5893 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
5895 const char *group ="AISObjects";
5896 theCommands.Add("vtrihedron",
5897 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
5898 __FILE__,VTrihedron,group);
5900 theCommands.Add("vtri2d",
5901 "vtri2d Name Selection in the viewer only ",
5902 __FILE__,VTrihedron2D ,group);
5904 theCommands.Add("vplanetri",
5905 "vplanetri Name Selection in the viewer only ",
5906 __FILE__,VPlaneTrihedron ,group);
5908 theCommands.Add("vsize",
5909 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
5910 __FILE__,VSize,group);
5912 theCommands.Add("vaxis",
5913 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
5914 __FILE__,VAxisBuilder,group);
5916 theCommands.Add("vaxispara",
5918 __FILE__,VAxisBuilder,group);
5920 theCommands.Add("vaxisortho",
5922 __FILE__,VAxisBuilder,group);
5924 theCommands.Add("vpoint",
5925 "vpoint PointName [Xa] [Ya] [Za] ",
5926 __FILE__,VPointBuilder,group);
5928 theCommands.Add("vplane",
5929 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
5930 __FILE__,VPlaneBuilder,group);
5932 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
5933 " vchangeplane <plane_name>"
5934 " [x=center_x y=center_y z=center_z]"
5935 " [dx=dir_x dy=dir_y dz=dir_z]"
5936 " [sx=size_x sy=size_y]"
5938 " - changes parameters of the plane:\n"
5939 " - x y z - center\n"
5940 " - dx dy dz - normal\n"
5941 " - sx sy - plane sizes\n"
5942 " - noupdate - do not update/redisplay the plane in context\n"
5943 " Please enter coordinates in format \"param=value\" in arbitrary order.",
5944 __FILE__, VChangePlane, group);
5946 theCommands.Add("vplanepara",
5947 "vplanepara PlaneName ",
5948 __FILE__,VPlaneBuilder,group);
5950 theCommands.Add("vplaneortho",
5951 "vplaneortho PlaneName ",
5952 __FILE__,VPlaneBuilder,group);
5954 theCommands.Add("vline",
5955 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
5956 __FILE__,VLineBuilder,group);
5958 theCommands.Add("vcircle",
5959 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
5960 __FILE__,VCircleBuilder,group);
5962 theCommands.Add("vdrawtext",
5963 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
5964 __FILE__,VDrawText,group);
5966 theCommands.Add("vdrawsphere",
5967 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
5968 __FILE__,VDrawSphere,group);
5970 theCommands.Add ("vsetlocation",
5971 "vsetlocation [-noupdate|-update] name x y z"
5972 "\n\t\t: Set new location for an interactive object.",
5973 __FILE__, VSetLocation, group);
5977 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
5978 __FILE__, VComputeHLR, group);
5980 theCommands.Add("vdrawparray",
5981 "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 ]",
5982 __FILE__,VDrawPArray,group);
5984 theCommands.Add("vconnect",
5985 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
5986 " Makes an assembly of object instances located in point (Xo Yo Zo).",
5987 __FILE__, VConnect, group);
5989 theCommands.Add("vconnectto",
5990 "vconnectto : instance_name Xo Yo Zo object"
5991 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo).",
5992 __FILE__, VConnectTo,group);
5994 theCommands.Add("vdisconnect",
5995 "vdisconnect assembly_name (object_name | object_number | 'all')"
5996 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
5997 __FILE__,VDisconnect,group);
5999 theCommands.Add("vaddconnected",
6000 "vaddconnected assembly_name object_name"
6001 "Adds object to assembly.",
6002 __FILE__,VAddConnected,group);
6004 theCommands.Add("vlistconnected",
6005 "vlistconnected assembly_name"
6006 "Lists objects in assembly.",
6007 __FILE__,VListConnected,group);
6010 theCommands.Add("vselmode",
6011 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6012 " switches selection mode for the determined object or\n"
6013 " for all objects in context.\n"
6014 " mode_number is non-negative integer that has different\n"
6015 " meaning for different interactive object classes.\n"
6016 " For shapes the following mode_number values are allowed:\n"
6026 " is_turned_on is:\n"
6027 " 1 if mode is to be switched on\n"
6028 " 0 if mode is to be switched off\n",
6029 __FILE__, VSetSelectionMode, group);
6031 theCommands.Add("vselnext",
6032 "vselnext : hilight next detected",
6033 __FILE__, VSelectionNext, group);
6035 theCommands.Add("vselprev",
6036 "vselnext : hilight previous detected",
6037 __FILE__, VSelectionPrevious, group);
6039 theCommands.Add("vtriangle",
6040 "vtriangle Name PointName PointName PointName",
6041 __FILE__, VTriangle,group);
6043 theCommands.Add("vsegment",
6044 "vsegment Name PointName PointName",
6045 __FILE__, VSegment,group);
6047 theCommands.Add("vobjzlayer",
6048 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6049 __FILE__, VObjZLayer, group);
6051 theCommands.Add("vpolygonoffset",
6052 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6053 __FILE__, VPolygonOffset, group);
6055 theCommands.Add ("vshowfaceboundary",
6056 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6057 "- turns on/off drawing of face boundaries for ais object "
6058 "and defines boundary line style.",
6059 __FILE__, VShowFaceBoundary, group);
6061 theCommands.Add ("vmarkerstest",
6062 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6063 __FILE__, VMarkersTest, group);
6065 theCommands.Add ("text2brep",
6066 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
6067 __FILE__, TextToBRep, group);
6068 theCommands.Add ("vfont",
6069 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6070 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6071 __FILE__, VFont, group);
6073 theCommands.Add ("vsetedgetype",
6074 "vsetedgetype usage:\n"
6075 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6076 "\n\t\t: Sets edges type and color for input shape",
6077 __FILE__, VSetEdgeType, group);
6079 theCommands.Add ("vunsetedgetype",
6080 "vunsetedgetype usage:\n"
6081 "vunsetedgetype ShapeName [-force]"
6082 "\n\t\t: Unsets edges type and color for input shape",
6083 __FILE__, VUnsetEdgeType, group);
6085 theCommands.Add ("vvertexmode",
6086 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6087 "vvertexmode - prints the default vertex draw mode\n"
6088 "vvertexmode name - prints the vertex draw mode of the given object\n"
6089 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6090 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6091 __FILE__, VVertexMode, group);
6093 theCommands.Add ("vpointcloud",
6094 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6095 "\n\t\t: Create an interactive object for arbitary set of points"
6096 "\n\t\t: from triangulated shape."
6098 "vpointcloud name x y z r npts {surface|volume}\n"
6099 " ... [-randColor] [-normals] [-noNormals]"
6100 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6101 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6103 "\n\t\t: Additional options:"
6104 "\n\t\t: -randColor - generate random color per point"
6105 "\n\t\t: -normals - generate normal per point (default)"
6106 "\n\t\t: -noNormals - do not generate normal per point"
6108 __FILE__, VPointCloud, group);
6110 theCommands.Add("vlocreset",
6111 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6113 LocalTransformPresentation, group);
6115 theCommands.Add("vlocmove",
6116 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6118 LocalTransformPresentation, group);
6120 theCommands.Add("vloctranslate",
6121 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6123 LocalTransformPresentation, group);
6125 theCommands.Add("vlocrotate",
6126 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6128 LocalTransformPresentation, group);
6130 theCommands.Add("vlocmirror",
6131 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6133 LocalTransformPresentation, group);
6135 theCommands.Add("vlocscale",
6136 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6138 LocalTransformPresentation, group);
6140 theCommands.Add("vpriority",
6141 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",