1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <Quantity_NameOfColor.hxx>
20 #include <Draw_Interpretor.hxx>
22 #include <Draw_Appli.hxx>
25 #include <Font_BRepFont.hxx>
26 #include <Font_FontMgr.hxx>
27 #include <OSD_Chronometer.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <Visual3d_View.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_DisplayMode.hxx>
36 #include <AIS_PointCloud.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_AutoUpdater.hxx>
40 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_EventManager.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Builder.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Face.hxx>
62 #include <Draw_Window.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_DisplayMode.hxx>
66 #include <AIS_Shape.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <Geom_Plane.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <TCollection_HAsciiString.hxx>
73 #include <GC_MakePlane.hxx>
74 #include <gp_Circ.hxx>
75 #include <AIS_Axis.hxx>
76 #include <Geom_Axis2Placement.hxx>
77 #include <Geom_Axis1Placement.hxx>
78 #include <AIS_Trihedron.hxx>
79 #include <AIS_Axis.hxx>
80 #include <gp_Trsf.hxx>
81 #include <TopLoc_Location.hxx>
83 #include <HLRAlgo_Projector.hxx>
84 #include <HLRBRep_PolyAlgo.hxx>
85 #include <HLRBRep_PolyHLRToShape.hxx>
86 #include <Aspect_Window.hxx>
88 #include <Graphic3d_ArrayOfPoints.hxx>
89 #include <Graphic3d_ArrayOfSegments.hxx>
90 #include <Graphic3d_ArrayOfPolylines.hxx>
91 #include <Graphic3d_ArrayOfTriangles.hxx>
92 #include <Graphic3d_ArrayOfTriangleFans.hxx>
93 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
94 #include <Graphic3d_ArrayOfQuadrangles.hxx>
95 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
96 #include <Graphic3d_ArrayOfPolygons.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_Group.hxx>
99 #include <Standard_Real.hxx>
101 #include <AIS_Circle.hxx>
102 #include <BRepBuilderAPI_MakeEdge.hxx>
103 #include <BRepBuilderAPI_MakeFace.hxx>
104 #include <BRepBuilderAPI_MakeWire.hxx>
105 #include <Geom_Circle.hxx>
106 #include <GC_MakeCircle.hxx>
107 #include <Prs3d_Presentation.hxx>
108 #include <Select3D_SensitiveCircle.hxx>
109 #include <SelectMgr_EntityOwner.hxx>
110 #include <SelectMgr_Selection.hxx>
111 #include <StdFail_NotDone.hxx>
112 #include <StdPrs_ShadedShape.hxx>
113 #include <TopoDS_Wire.hxx>
115 #include <AIS_MultipleConnectedInteractive.hxx>
116 #include <AIS_ConnectedInteractive.hxx>
117 #include <AIS_TextLabel.hxx>
118 #include <TopLoc_Location.hxx>
119 #include <TColStd_ListOfInteger.hxx>
120 #include <TColStd_ListIteratorOfListOfInteger.hxx>
122 #include <Select3D_SensitiveTriangle.hxx>
123 #include <Select3D_SensitiveCurve.hxx>
124 #include <Select3D_SensitivePoint.hxx>
125 #include <BRepAdaptor_Curve.hxx>
126 #include <StdPrs_Curve.hxx>
128 #include <BRepExtrema_ExtPC.hxx>
129 #include <BRepExtrema_ExtPF.hxx>
131 #include <Prs3d_Drawer.hxx>
132 #include <Prs3d_VertexDrawMode.hxx>
133 #include <Prs3d_LineAspect.hxx>
134 #include <Prs3d_PointAspect.hxx>
136 #include <Image_AlienPixMap.hxx>
137 #include <TColStd_HArray1OfAsciiString.hxx>
140 # define _CRT_SECURE_NO_DEPRECATE
141 # pragma warning (disable:4996)
144 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
145 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
146 const Handle(AIS_InteractiveObject)& theAISObj,
147 Standard_Boolean theReplaceIfExists = Standard_True);
148 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
149 extern Handle(AIS_InteractiveContext)& TheAISContext();
152 //==============================================================================
153 //function : Vtrihedron 2d
154 //purpose : Create a plane with a 2D trihedron from a faceselection
155 //Draw arg : vtri2d name
156 //==============================================================================
157 #include <AIS_PlaneTrihedron.hxx>
161 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
164 // Verification des arguments
165 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
168 Standard_Integer myCurrentIndex;
169 // Fermeture des contextes
170 TheAISContext()->CloseAllContexts();
171 // Ouverture d'un contexte local et recuperation de son index.
172 TheAISContext()->OpenLocalContext();
173 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
174 // On active les modes de selections faces.
175 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
176 di<<" Select a face ."<<"\n";
178 // Boucle d'attente waitpick.
179 Standard_Integer argccc = 5;
180 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
181 const char **argvvv = (const char **) bufff;
182 while (ViewerMainLoop( argccc, argvvv) ) { }
186 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
187 ShapeB = TheAISContext()->SelectedShape();
190 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
192 // Construction du Plane
193 // recuperation des edges des faces.
194 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
196 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
200 // si il y a plusieurs edges
201 if (FaceExpB.More() ) {
203 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
204 BRepAdaptor_Curve theCurveB(EdgeB);
205 BRepAdaptor_Curve theCurveC(EdgeC);
206 A=theCurveC.Value(0.1);
207 B=theCurveC.Value(0.9);
208 C=theCurveB.Value(0.5);
211 // FaceB a 1 unique edge courbe
212 BRepAdaptor_Curve theCurveB(EdgeB);
213 A=theCurveB.Value(0.1);
214 B=theCurveB.Value(0.9);
215 C=theCurveB.Value(0.5);
217 // Construction du Geom_Plane
218 GC_MakePlane MkPlane(A,B,C);
219 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
221 // Construction de l'AIS_PlaneTrihedron
222 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
224 // Fermeture du contexte local.
225 TheAISContext()->CloseLocalContext(myCurrentIndex);
227 // on le display & bind
228 TheAISContext()->Display(theAISPlaneTri );
229 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
236 //==============================================================================
237 //function : VTriherdron
238 //purpose : Create a trihedron. If no arguments are set, the default
239 // trihedron (Oxyz) is created.
240 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
241 //==============================================================================
243 static int VTrihedron (Draw_Interpretor& theDi,
244 Standard_Integer theArgsNb,
245 const char** theArgVec)
247 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
249 theDi << theArgVec[0] << " Syntax error\n";
253 gp_Pnt anOrigin (0.0, 0.0, 0.0);
254 gp_Dir aDirZ = gp::DZ();
255 gp_Dir aDirX = gp::DX();
256 Standard_Integer anArgIter = 2; // 1st is an IO name
257 if (anArgIter < theArgsNb)
259 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
260 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
261 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
262 if (anArgIter < theArgsNb)
264 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
265 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
266 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
267 aDirZ.SetCoord (aX, aY, aZ);
269 aX = Draw::Atof (theArgVec[anArgIter++]);
270 aY = Draw::Atof (theArgVec[anArgIter++]);
271 aZ = Draw::Atof (theArgVec[anArgIter++]);
272 aDirX.SetCoord (aX, aY, aZ);
276 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
278 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
282 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
283 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
284 VDisplayAISObject (theArgVec[1], aShape);
288 //==============================================================================
291 //purpose : Change the size of a named or selected trihedron
292 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
293 // if no value, the value is set at 100 by default
294 //Draw arg : vsize [name] [size]
295 //==============================================================================
297 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
300 // Declaration de booleens
301 Standard_Boolean ThereIsName;
302 Standard_Boolean ThereIsCurrent;
304 Standard_Boolean hascol;
306 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
308 // Verification des arguments
309 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
311 // Verification du nombre d'arguments
312 if (argc==1) {ThereIsName=Standard_False;value=100;}
313 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
314 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
316 // On ferme le contexte local pour travailler dans le contexte global
317 if(TheAISContext()->HasOpenedContext())
318 TheAISContext()->CloseLocalContext();
320 // On set le booleen ThereIsCurrent
321 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
322 else {ThereIsCurrent=Standard_False;}
326 //===============================================================
327 // Il n'y a pas de nom mais des objets selectionnes
328 //===============================================================
329 if (!ThereIsName && ThereIsCurrent)
332 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
335 while ( it.More() ) {
337 Handle(AIS_InteractiveObject) aShape=
338 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
340 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
343 // On verifie que l'AIS InteraciveObject selectionne est bien
345 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
347 if (aShape->HasColor()) {
348 hascol=Standard_True;
350 // On recupere la couleur de aShape
351 col=aShape->Color();}
353 else hascol=Standard_False;
355 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
356 // pour lui appliquer la methode SetSize()
357 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
359 // C'est bien un triedre,on chage sa valeur!
360 aTrihedron->SetSize(value);
362 // On donne la couleur au Trihedron
363 if(hascol) aTrihedron->SetColor(col);
364 else aTrihedron->UnsetColor();
367 // The trihedron hasn't be errased from the map
368 // so you just have to redisplay it
369 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
378 TheAISContext() ->UpdateCurrentViewer();
381 //===============================================================
382 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
383 //===============================================================
387 //===============================================================
388 // Il y a un nom de triedre passe en argument
389 //===============================================================
391 TCollection_AsciiString name=argv[1];
393 // on verifie que ce nom correspond bien a une shape
394 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
398 // on recupere la shape dans la map des objets displayes
399 Handle(AIS_InteractiveObject) aShape =
400 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
402 // On verifie que l'AIS InteraciveObject est bien
404 if (!aShape.IsNull() &&
405 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
408 if (aShape->HasColor()) {
409 hascol=Standard_True;
411 // On recupere la couleur de aShape
412 col=aShape->Color();}
414 else hascol=Standard_False;
416 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
417 // pour lui appliquer la methode SetSize()
418 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
420 // C'est bien un triedre,on chage sa valeur
421 aTrihedron->SetSize(value);
423 // On donne la couleur au Trihedron
424 if(hascol) aTrihedron->SetColor(col);
425 else aTrihedron->UnsetColor();
427 // The trihedron hasn't be errased from the map
428 // so you just have to redisplay it
429 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
431 TheAISContext() ->UpdateCurrentViewer();
439 //==============================================================================
441 //==============================================================================
442 //function : VPlaneTrihedron
443 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
444 //Draw arg : vplanetri name
445 //==============================================================================
446 #include <AIS_Plane.hxx>
450 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
453 // Verification des arguments
454 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
457 Standard_Integer myCurrentIndex;
458 // Fermeture des contextes locaux
459 TheAISContext()->CloseAllContexts();
461 // On recupere tous les trihedrons de la GetMapOfAIS()
462 // et on active le mode de selection par face.
463 // =================================================
465 // Ouverture d'un contexte local et recuperation de son index.
466 TheAISContext()->OpenLocalContext(Standard_False);
467 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
469 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
472 Handle(AIS_InteractiveObject) ShapeA =
473 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
474 // On verifie que c'est bien un trihedron
475 if (!ShapeA.IsNull() &&
476 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
478 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
479 // on le charge dans le contexte et on active le mode Plane.
480 TheAISContext()->Load(TrihedronA,0,Standard_False);
481 TheAISContext()->Activate(TrihedronA,3);
486 di<<" Select a plane."<<"\n";
487 // Boucle d'attente waitpick.
488 Standard_Integer argccc = 5;
489 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
490 const char **argvvv = (const char **) bufff;
491 while (ViewerMainLoop( argccc, argvvv) ) { }
494 Handle(AIS_InteractiveObject) theIOB;
495 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
496 theIOB = TheAISContext()->Interactive();
499 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
501 // Fermeture du contexte local.
502 TheAISContext()->CloseLocalContext(myCurrentIndex);
504 // on le display & bind
505 TheAISContext()->Display(PlaneB );
506 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
513 //==============================================================================
514 // Fonction First click 2de click
516 // vaxis vertex vertex
518 // vaxispara edge vertex
519 // vaxisortho edge Vertex
520 // vaxisinter Face Face
521 //==============================================================================
523 //==============================================================================
524 //function : VAxisBuilder
526 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
527 //==============================================================================
528 #include <TopoDS_Edge.hxx>
529 #include <TopoDS_Vertex.hxx>
530 #include <TopExp.hxx>
531 #include <Geom_Line.hxx>
533 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
536 Standard_Boolean HasArg;
537 TCollection_AsciiString name;
538 Standard_Integer MyCurrentIndex;
541 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
542 if (argc==8) HasArg=Standard_True;
543 else HasArg=Standard_False;
546 // Fermeture des contextes
547 TheAISContext()->CloseAllContexts();
549 // Cas ou il y a des arguments
550 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
552 Standard_Real coord[6];
553 for(Standard_Integer i=0;i<=5;i++){
554 coord[i]=Draw::Atof(argv[2+i]);
556 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
558 gp_Vec myVect (p1,p2);
559 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
560 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
561 GetMapOfAIS().Bind (TheAxis,name);
562 TheAISContext()->Display(TheAxis);
568 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
569 if ( !strcasecmp(argv[0], "vaxis")) {
570 TheAISContext()->OpenLocalContext();
571 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
573 // Active le mode edge et le mode vertex
574 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
575 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
576 di<<" Select an edge or a vertex."<<"\n";
578 // Boucle d'attente waitpick.
579 Standard_Integer argcc = 5;
580 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
581 const char **argvv = (const char **) buff;
582 while (ViewerMainLoop( argcc, argvv) ) { }
585 // recuperation de la shape.
587 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
588 ShapeA = TheAISContext()->SelectedShape();
590 // recuperation de l'AIS_InteractiveObject
591 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
592 // down cast en AIS_Point si sig et type
593 // AIS_Point -> Geom_Pnt ....
595 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
596 // on desactive le mode edge
597 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
598 di<<" Select a different vertex."<<"\n";
602 // Boucle d'attente waitpick.
603 Standard_Integer argccc = 5;
604 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
605 const char **argvvv = (const char **) bufff;
606 while (ViewerMainLoop( argccc, argvvv) ) { }
608 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
609 ShapeB = TheAISContext()->SelectedShape();
613 } while(ShapeB.IsSame(ShapeA) );
615 // Fermeture du context local
616 TheAISContext()->CloseLocalContext(MyCurrentIndex);
618 // Construction de l'axe
619 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
620 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
623 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
624 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
625 GetMapOfAIS().Bind (TheAxis,name);
626 TheAISContext()->Display(TheAxis);
629 // Un unique edge (ShapeA) a ete picke
630 // Fermeture du context local
631 TheAISContext()->CloseLocalContext(MyCurrentIndex);
632 // Constuction de l'axe
633 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
635 TopExp::Vertices(ed,Va,Vb );
636 gp_Pnt A=BRep_Tool::Pnt(Va);
637 gp_Pnt B=BRep_Tool::Pnt(Vb);
640 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
641 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
642 GetMapOfAIS().Bind (TheAxis,name);
643 TheAISContext()->Display(TheAxis);
649 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
650 else if ( !strcasecmp(argv[0], "vaxispara")) {
652 TheAISContext()->OpenLocalContext();
653 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
655 // Active le mode edge
656 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
657 di<<" Select an edge."<<"\n";
659 // Boucle d'attente waitpick.
660 Standard_Integer argcc = 5;
661 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
662 const char **argvv = (const char **) buff;
663 while (ViewerMainLoop( argcc, argvv) ) { }
667 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
668 ShapeA = TheAISContext()->SelectedShape();
670 // Active le mode vertex et deactive edges
671 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
672 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
673 di<<" Select a vertex."<<"\n";
675 // Boucle d'attente waitpick.
676 Standard_Integer argccc = 5;
677 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
678 const char **argvvv = (const char **) bufff;
679 while (ViewerMainLoop( argccc, argvvv) ) { }
682 // On peut choisir un pnt sur l'edge
684 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
685 ShapeB = TheAISContext()->SelectedShape();
687 // Fermeture du context local
688 TheAISContext()->CloseLocalContext(MyCurrentIndex);
690 // Construction de l'axe
691 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
692 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
694 TopExp::Vertices(ed,Va,Vc );
695 gp_Pnt A=BRep_Tool::Pnt(Va);
696 gp_Pnt C=BRep_Tool::Pnt(Vc);
699 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
700 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
701 GetMapOfAIS().Bind (TheAxis,name);
702 TheAISContext()->Display(TheAxis);
706 // Fonction axisortho
708 TheAISContext()->OpenLocalContext();
709 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
711 // Active le mode edge
712 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
713 di<<" Select an edge."<<"\n";
715 // Boucle d'attente waitpick.
716 Standard_Integer argcc = 5;
717 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
718 const char **argvv = (const char **) buff;
719 while (ViewerMainLoop( argcc, argvv) ) { }
723 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
724 ShapeA = TheAISContext()->SelectedShape();
726 // Active le mode vertex et deactive edges
727 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
728 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
729 di<<" Slect a vertex."<<"\n";
731 // Boucle d'attente waitpick.
732 Standard_Integer argccc = 5;
733 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
734 const char **argvvv = (const char **) bufff;
735 while (ViewerMainLoop( argccc, argvvv) ) { }
738 // On peut choisir un pnt sur l'edge
740 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
741 ShapeB = TheAISContext()->SelectedShape();
743 // Fermeture du context local
744 TheAISContext()->CloseLocalContext(MyCurrentIndex);
746 // Construction de l'axe
747 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
748 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
750 TopExp::Vertices(ed,Va,Vc );
751 gp_Pnt A=BRep_Tool::Pnt(Va);
752 gp_Pnt C=BRep_Tool::Pnt(Vc);
753 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
756 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
757 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
758 GetMapOfAIS().Bind (TheAxis,name);
759 TheAISContext()->Display(TheAxis);
768 //==============================================================================
769 // Fonction First click Result
771 // vpoint vertex AIS_Point=Vertex
772 // edge AIS_Point=Middle of the edge
773 //==============================================================================
775 //==============================================================================
776 //function : VPointBuilder
777 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
778 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
779 //==============================================================================
780 #include <TopoDS_Edge.hxx>
781 #include <TopoDS_Vertex.hxx>
782 #include <TopExp.hxx>
783 #include <AIS_Point.hxx>
784 #include <Geom_CartesianPoint.hxx>
786 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
789 Standard_Boolean HasArg;
790 TCollection_AsciiString name;
791 Standard_Integer myCurrentIndex;
794 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
795 if (argc==5) HasArg=Standard_True;
796 else HasArg=Standard_False;
799 // Fermeture des contextes
800 TheAISContext()->CloseAllContexts();
802 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
804 Standard_Real thecoord[3];
805 for(Standard_Integer i=0;i<=2;i++)
806 thecoord[i]=Draw::Atof(argv[2+i]);
807 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
808 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
809 GetMapOfAIS().Bind (myAISPoint,name);
810 TheAISContext()->Display(myAISPoint);
813 // Il n'a pas d'arguments
815 TheAISContext()->OpenLocalContext();
816 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
818 // Active le mode Vertex et Edges
819 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
820 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
821 di<<" Select a vertex or an edge(build the middle)"<<"\n";
823 // Boucle d'attente waitpick.
824 Standard_Integer argcc = 5;
825 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
826 const char **argvv = (const char **) buff;
827 while (ViewerMainLoop( argcc, argvv) ) { }
831 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
832 ShapeA= TheAISContext()->SelectedShape();
835 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
836 // Un vertex a ete selectionne
837 // Fermeture du context local
838 TheAISContext()->CloseLocalContext(myCurrentIndex);
840 // Construction du point
841 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
842 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
843 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
844 GetMapOfAIS().Bind(myAISPoint,name);
845 TheAISContext()->Display(myAISPoint);
848 // Un Edge a ete selectionne
849 // Fermeture du context local
850 TheAISContext()->CloseLocalContext(myCurrentIndex);
852 // Construction du point milieu de l'edge
853 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
854 TopoDS_Vertex myVertexA,myVertexB;
855 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
856 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
857 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
858 // M est le milieu de [AB]
859 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
860 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
861 GetMapOfAIS().Bind(myAISPointM,name);
862 TheAISContext()->Display(myAISPointM);
870 //==============================================================================
871 // Function 1st click 2de click 3de click
872 // vplane Vertex Vertex Vertex
876 // vplanepara Face Vertex
878 // vplaneortho Face Edge
880 //==============================================================================
882 //==============================================================================
883 //function : VPlaneBuilder
884 //purpose : Build an AIS_Plane from selected entities or Named AIS components
885 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
886 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
887 // [PlaneName] [PointName] [TypeOfSensitivity]
888 //==============================================================================
890 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
891 Standard_Integer argc,
895 Standard_Boolean hasArg;
896 TCollection_AsciiString aName;
897 Standard_Integer aCurrentIndex;
900 if (argc<2 || argc>6 )
902 std::cout<<" Syntax error\n";
905 if (argc == 6 || argc==5 || argc==4)
906 hasArg=Standard_True;
908 hasArg=Standard_False;
911 // Close all contexts
912 TheAISContext()->CloseAllContexts();
914 // There are some arguments
917 if (!GetMapOfAIS().IsBound2(argv[2] ))
919 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
922 // Get shape from map
923 Handle(AIS_InteractiveObject) aShapeA =
924 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
926 // The first argument is an AIS_Point
927 if (!aShapeA.IsNull() &&
928 aShapeA->Type()==AIS_KOI_Datum &&
929 aShapeA->Signature()==1)
931 // The second argument must also be an AIS_Point
932 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
934 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
937 // Get shape from map
938 Handle(AIS_InteractiveObject) aShapeB =
939 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
940 // If B is not an AIS_Point
941 if (aShapeB.IsNull() ||
942 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
944 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
947 // The third object is an AIS_Point
948 if (!GetMapOfAIS().IsBound2(argv[4]) )
950 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
953 // Get shape from map
954 Handle(AIS_InteractiveObject) aShapeC =
955 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
956 // If C is not an AIS_Point
957 if (aShapeC.IsNull() ||
958 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
960 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
964 // Treatment of objects A, B, C
965 // Downcast an AIS_IO to AIS_Point
966 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
967 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
968 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
970 Handle(Geom_CartesianPoint ) aCartPointA =
971 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
973 Handle(Geom_CartesianPoint ) aCartPointB =
974 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
976 Handle(Geom_CartesianPoint ) aCartPointC =
977 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
979 // Verification that the three points are different
980 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
981 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
982 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
985 std::cout<<"vplane error: same points"<<"\n";return 1;
987 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
988 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
989 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
992 std::cout<<"vplane error: same points"<<"\n";return 1;
994 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
995 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
996 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
999 std::cout<<"vplane error: same points"<<"\n";return 1;
1002 gp_Pnt A = aCartPointA->Pnt();
1003 gp_Pnt B = aCartPointB->Pnt();
1004 gp_Pnt C = aCartPointC->Pnt();
1006 // Construction of AIS_Plane
1007 GC_MakePlane MkPlane (A,B,C);
1008 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1009 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1010 GetMapOfAIS().Bind (anAISPlane,aName );
1013 Standard_Integer aType = Draw::Atoi (argv[5]);
1014 if (aType != 0 && aType != 1)
1016 std::cout << "vplane error: wrong type of sensitivity!\n"
1017 << "Should be one of the following values:\n"
1025 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1028 TheAISContext()->Display(anAISPlane);
1031 // The first argument is an AIS_Axis
1032 // Creation of a plane orthogonal to the axis through a point
1033 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1034 // The second argument should be an AIS_Point
1035 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1037 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1040 // Get shape from map
1041 Handle(AIS_InteractiveObject) aShapeB =
1042 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1043 // If B is not an AIS_Point
1044 if (aShapeB.IsNull() ||
1045 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1047 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1051 // Treatment of objects A and B
1052 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1053 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1055 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1056 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1058 gp_Ax1 anAxis = aGeomLineA->Position();
1059 Handle(Geom_CartesianPoint) aCartPointB =
1060 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1062 gp_Dir D =anAxis.Direction();
1063 gp_Pnt B = aCartPointB->Pnt();
1065 // Construction of AIS_Plane
1066 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1067 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1068 GetMapOfAIS().Bind (anAISPlane,aName );
1071 Standard_Integer aType = Draw::Atoi (argv[4]);
1072 if (aType != 0 && aType != 1)
1074 std::cout << "vplane error: wrong type of sensitivity!\n"
1075 << "Should be one of the following values:\n"
1083 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1086 TheAISContext()->Display(anAISPlane);
1089 // The first argumnet is an AIS_Plane
1090 // Creation of a plane parallel to the plane passing through the point
1091 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1093 // The second argument should be an AIS_Point
1094 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1096 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1099 // Get shape from map
1100 Handle(AIS_InteractiveObject) aShapeB =
1101 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1102 // B should be an AIS_Point
1103 if (aShapeB.IsNull() ||
1104 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1106 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1110 // Treatment of objects A and B
1111 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1112 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1114 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1115 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1117 Handle(Geom_CartesianPoint) aCartPointB =
1118 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1119 gp_Pnt B= aCartPointB->Pnt();
1121 // Construction of an AIS_Plane
1122 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1123 GetMapOfAIS().Bind (anAISPlane, aName);
1126 Standard_Integer aType = Draw::Atoi (argv[4]);
1127 if (aType != 0 && aType != 1)
1129 std::cout << "vplane error: wrong type of sensitivity!\n"
1130 << "Should be one of the following values:\n"
1138 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1141 TheAISContext()->Display(anAISPlane);
1146 std::cout<<"vplane: error 1st object is not an AIS\n";
1150 // There are no arguments
1154 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1155 if (!strcasecmp(argv[0], "vplane"))
1157 TheAISContext()->OpenLocalContext();
1158 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1160 // Active modes Vertex, Edge and Face
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1163 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1164 std::cout<<"Select a vertex, a face or an edge\n";
1167 Standard_Integer argcc = 5;
1168 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1169 const char **argvv = (const char **) buff;
1170 while (ViewerMainLoop( argcc, argvv) ) { }
1173 TopoDS_Shape aShapeA;
1174 for (TheAISContext()->InitSelected();
1175 TheAISContext()->MoreSelected();
1176 TheAISContext()->NextSelected())
1178 aShapeA = TheAISContext()->SelectedShape();
1181 // aShapeA is a Vertex
1182 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1184 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1185 std::cout<<" Select an edge or a different vertex\n";
1188 Standard_Integer argccc = 5;
1189 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1190 const char **argvvv = (const char **) bufff;
1191 while (ViewerMainLoop( argccc, argvvv) ) { }
1194 TopoDS_Shape aShapeB;
1195 for (TheAISContext()->InitSelected();
1196 TheAISContext()->MoreSelected();
1197 TheAISContext()->NextSelected())
1199 aShapeB = TheAISContext()->SelectedShape();
1201 // aShapeB is a Vertex
1202 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1204 // A and B are the same
1205 if (aShapeB.IsSame(aShapeA))
1207 std::cout<<" vplane: error, same points selected\n";
1210 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1211 std::cout<<" Select a different vertex\n";
1214 Standard_Integer argcccc = 5;
1215 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1216 const char **argvvvv = (const char **) buffff;
1217 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1220 TopoDS_Shape aShapeC;
1221 for (TheAISContext()->InitSelected();
1222 TheAISContext()->MoreSelected();
1223 TheAISContext()->NextSelected())
1225 aShapeC = TheAISContext()->SelectedShape();
1227 // aShapeC is the same as A or B
1228 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1230 std::cout<<" vplane: error, same points selected\n";
1234 // Close the local context
1235 TheAISContext()->CloseLocalContext(aCurrentIndex);
1237 // Construction of plane
1238 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1239 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1240 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1241 GC_MakePlane MkPlane(A, B, C);
1242 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1243 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1244 GetMapOfAIS().Bind (anAISPlane, aName);
1245 TheAISContext()->Display(anAISPlane);
1247 // ShapeB is an edge
1250 // Verify that the vertex is not on the edge ShapeB
1251 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1252 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1254 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1255 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1257 // The vertex is on the edge
1258 std::cout<<" vplane: error point is on the edge\n";
1263 // Close the local context
1264 TheAISContext()->CloseLocalContext(aCurrentIndex);
1265 // Construction of plane
1266 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1267 TopoDS_Vertex aVBa, aVBb;
1268 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1269 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1270 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1271 GC_MakePlane MkPlane (A, aBa, aBb);
1272 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1273 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1274 GetMapOfAIS().Bind (anAISPlane, aName);
1275 TheAISContext()->Display(anAISPlane);
1279 // aShapeA is an edge
1280 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1282 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1283 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1284 std::cout<<" Select a vertex that don't belong to the edge\n";
1287 Standard_Integer argccc = 5;
1288 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1289 const char **argvvv = (const char **) bufff;
1290 while (ViewerMainLoop( argccc, argvvv) ) { }
1293 TopoDS_Shape aShapeB;
1294 for (TheAISContext()->InitSelected();
1295 TheAISContext()->MoreSelected();
1296 TheAISContext()->NextSelected())
1298 aShapeB = TheAISContext()->SelectedShape();
1300 // aShapeB should be a Vertex
1301 // Check that the vertex aShapeB is not on the edge
1302 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1303 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1305 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1306 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1308 // The vertex is on the edge
1309 std::cout<<" vplane: error point is on the edge\n";
1314 // Close the local context
1315 TheAISContext()->CloseLocalContext(aCurrentIndex);
1316 // Construction of plane
1317 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1318 TopoDS_Vertex aVAa, aVAb;
1319 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1320 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1321 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1322 GC_MakePlane MkPlane (B,Aa,Ab);
1323 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1324 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1325 GetMapOfAIS().Bind (anAISPlane ,aName);
1326 TheAISContext()->Display(anAISPlane);
1329 // aShapeA is a Face
1332 // Close the local context: nothing to select
1333 TheAISContext()->CloseLocalContext(aCurrentIndex);
1334 // Construction of plane
1335 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1336 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1337 if (aSurface.GetType()==GeomAbs_Plane)
1339 gp_Pln aPlane = aSurface.Plane();
1340 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1341 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1342 GetMapOfAIS().Bind (anAISPlane, aName);
1343 TheAISContext()->Display(anAISPlane);
1347 std::cout<<" vplane: error\n";
1353 // Function vPlanePara
1354 // ===================
1355 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1356 else if (!strcasecmp(argv[0], "vplanepara"))
1358 TheAISContext()->OpenLocalContext();
1359 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1361 // Activate modes Vertex and Face
1362 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1363 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1364 std::cout<<" Select a vertex or a face\n";
1367 Standard_Integer argcc = 5;
1368 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1369 const char **argvv = (const char **) buff;
1370 while (ViewerMainLoop( argcc, argvv) ) { }
1373 TopoDS_Shape aShapeA;
1374 for (TheAISContext()->InitSelected();
1375 TheAISContext()->MoreSelected();
1376 TheAISContext()->NextSelected())
1378 aShapeA = TheAISContext()->SelectedShape();
1381 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1383 // aShapeA is a vertex
1384 // Deactivate the mode Vertex
1385 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1386 std::cout<<" Select a face\n";
1389 Standard_Integer argccc = 5;
1390 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1391 const char **argvvv = (const char **) bufff;
1392 while (ViewerMainLoop( argccc, argvvv) ) { }
1395 TopoDS_Shape aShapeB;
1396 for (TheAISContext()->InitSelected();
1397 TheAISContext()->MoreSelected();
1398 TheAISContext()->NextSelected())
1400 // A vertex ShapeA can be on Face ShapeB
1401 aShapeB = TheAISContext()->SelectedShape();
1404 // Close the local context
1405 TheAISContext()->CloseLocalContext(aCurrentIndex);
1407 // Construction of plane
1408 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1410 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1411 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1412 if (aSurface.GetType()==GeomAbs_Plane )
1414 gp_Pln aPlane = aSurface.Plane();
1415 // Construct a plane parallel to aGeomPlane through A
1416 aPlane.SetLocation(A);
1417 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1418 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1419 GetMapOfAIS().Bind (aAISPlane ,aName);
1420 TheAISContext()->Display(aAISPlane);
1424 std::cout<<" vplanepara: error\n";
1431 // Deactive the mode Face
1432 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1433 std::cout<<" Select a vertex\n";
1436 Standard_Integer argccc = 5;
1437 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1438 const char **argvvv = (const char **) bufff;
1439 while (ViewerMainLoop( argccc, argvvv) ) { }
1442 TopoDS_Shape aShapeB;
1443 for (TheAISContext()->InitSelected();
1444 TheAISContext()->MoreSelected();
1445 TheAISContext()->NextSelected())
1447 // A vertex ShapeB can be on Face ShapeA
1448 aShapeB = TheAISContext()->SelectedShape();
1450 // Close the local context
1451 TheAISContext()->CloseLocalContext(aCurrentIndex);
1453 // Construction of plane
1454 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1456 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1457 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1458 if (aSurface.GetType()==GeomAbs_Plane )
1460 gp_Pln aPlane = aSurface.Plane();
1461 aPlane.SetLocation(B);
1462 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1463 // Construct a plane parallel to aGeomPlane through B
1464 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1465 GetMapOfAIS().Bind (anAISPlane, aName);
1466 TheAISContext()->Display(anAISPlane);
1470 std::cout<<" vplanepara: error"<<"\n";return 1;
1475 // Function vplaneortho
1476 // ====================
1477 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1480 TheAISContext()->OpenLocalContext();
1481 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1483 // Activate the modes Edge and Face
1484 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1485 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1486 std::cout<<" Select a face and an edge coplanar\n";
1489 Standard_Integer argcc = 5;
1490 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1491 const char **argvv = (const char **) buff;
1492 while (ViewerMainLoop( argcc, argvv) ) { }
1495 TopoDS_Shape aShapeA;
1496 for (TheAISContext()->InitSelected();
1497 TheAISContext()->MoreSelected();
1498 TheAISContext()->NextSelected())
1500 aShapeA = TheAISContext()->SelectedShape();
1503 if (aShapeA.ShapeType()==TopAbs_EDGE )
1505 // ShapeA is an edge, deactivate the mode Edge...
1506 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1507 std::cout<<" Select a face\n";
1510 Standard_Integer argccc = 5;
1511 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1512 const char **argvvv = (const char **) bufff;
1513 while (ViewerMainLoop( argccc, argvvv) ) { }
1516 TopoDS_Shape aShapeB;
1517 for (TheAISContext()->InitSelected();
1518 TheAISContext()->MoreSelected();
1519 TheAISContext()->NextSelected())
1521 // Edge ShapeA can be on Face ShapeB
1522 aShapeB = TheAISContext()->SelectedShape();
1525 // Close the local context
1526 TheAISContext()->CloseLocalContext(aCurrentIndex);
1528 // Construction of plane
1529 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1530 TopoDS_Vertex aVAa, aVAb;
1531 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1532 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1533 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1537 // Creation of rotation axis
1538 gp_Ax1 aRotAxis (Aa,Dab);
1540 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1541 // The edge must be parallel to the face
1542 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1543 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1544 // Compare to heights
1545 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1546 >Precision::Confusion())
1548 // the edge is not parallel to the face
1549 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1553 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1554 if (aSurface.GetType()==GeomAbs_Plane)
1556 gp_Pln aPlane = aSurface.Plane();
1557 // It rotates a half turn round the axis of rotation
1558 aPlane.Rotate(aRotAxis , M_PI/2);
1560 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1561 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1562 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1563 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1564 GetMapOfAIS().Bind (anAISPlane, aName);
1565 TheAISContext()->Display(anAISPlane);
1569 std::cout<<" vplaneortho: error\n";
1575 // ShapeA is a Face, deactive the mode Face.
1576 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1577 std::cout<<" Select an edge\n";
1580 Standard_Integer argccc = 5;
1581 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1582 const char **argvvv = (const char **) bufff;
1583 while (ViewerMainLoop( argccc, argvvv) ) { }
1586 TopoDS_Shape aShapeB;
1587 for (TheAISContext()->InitSelected();
1588 TheAISContext()->MoreSelected();
1589 TheAISContext()->NextSelected())
1591 // Edge ShapeB can be on Face ShapeA
1592 aShapeB = TheAISContext()->SelectedShape();
1594 // Close the local context
1595 TheAISContext()->CloseLocalContext(aCurrentIndex);
1597 // Construction of plane
1598 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1599 TopoDS_Vertex aVBa, aVBb;
1600 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1601 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1602 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1603 gp_Vec ab (aBa,aBb);
1605 // Creation of rotation axe
1606 gp_Ax1 aRotAxis (aBa,Dab);
1608 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1609 // The edge must be parallel to the face
1610 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1611 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1612 // Comparing the two heights
1613 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1614 >Precision::Confusion())
1616 // the edge is not parallel to the face
1617 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1621 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1622 if (aSurface.GetType()==GeomAbs_Plane)
1624 gp_Pln aPlane = aSurface.Plane();
1625 // It rotates a half turn round the axis of rotation
1626 aPlane.Rotate(aRotAxis , M_PI/2);
1627 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1628 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1629 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1630 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1631 GetMapOfAIS().Bind (anAISPlane ,aName);
1632 TheAISContext()->Display(anAISPlane);
1636 std::cout<<" vplaneortho: error\n";
1645 //===============================================================================================
1646 //function : VChangePlane
1648 //===============================================================================================
1649 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1651 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1652 if (aContextAIS.IsNull())
1654 std::cout << theArgVec[0] << "AIS context is not available.\n";
1658 if (theArgsNb < 3 || theArgsNb > 11)
1660 std::cerr << theArgVec[0]
1661 << ": incorrect number of command arguments.\n"
1662 << "Type help for more information.\n";
1666 TCollection_AsciiString aName (theArgVec[1]);
1668 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1669 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1672 if ( aPlane.IsNull() )
1674 std::cout << theArgVec[0]
1675 << ": there is no interactive plane with the given name."
1676 << "Type help for more information.\n";
1680 Standard_Real aCenterX = aPlane->Center().X();
1681 Standard_Real aCenterY = aPlane->Center().Y();
1682 Standard_Real aCenterZ = aPlane->Center().Z();
1684 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1685 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1686 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1688 Standard_Real aSizeX = 0.0;
1689 Standard_Real aSizeY = 0.0;
1690 aPlane->Size (aSizeX, aSizeY);
1691 Standard_Boolean isUpdate = Standard_True;
1693 TCollection_AsciiString aPName, aPValue;
1694 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1696 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1697 TCollection_AsciiString anArgCase = anArg;
1698 anArgCase.UpperCase();
1699 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1702 if (aPName.IsEqual ("X"))
1704 aCenterX = aPValue.RealValue();
1706 else if (aPName.IsEqual ("Y"))
1708 aCenterY = aPValue.RealValue();
1710 else if (aPName.IsEqual ("Z"))
1712 aCenterZ = aPValue.RealValue();
1714 else if (aPName.IsEqual ("DX"))
1716 aDirX = aPValue.RealValue();
1718 else if (aPName.IsEqual ("DY"))
1720 aDirY = aPValue.RealValue();
1722 else if (aPName.IsEqual ("DZ"))
1724 aDirZ = aPValue.RealValue();
1726 else if (aPName.IsEqual ("SX"))
1728 aSizeX = aPValue.RealValue();
1730 else if (aPName.IsEqual ("SY"))
1732 aSizeY = aPValue.RealValue();
1735 else if (anArg.IsEqual ("NOUPDATE"))
1737 isUpdate = Standard_False;
1741 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1742 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1743 aPlane->SetCenter (aCenterPnt);
1744 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1745 aPlane->SetSize (aSizeX, aSizeY);
1747 aContextAIS->Update (aPlane, isUpdate);
1752 //==============================================================================
1754 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1755 //==============================================================================
1757 //==============================================================================
1758 //function : VLineBuilder
1759 //purpose : Build an AIS_Line
1760 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1761 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1762 //==============================================================================
1763 #include <Geom_CartesianPoint.hxx>
1764 #include <AIS_Line.hxx>
1767 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1769 Standard_Integer myCurrentIndex;
1771 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1772 // Fermeture des contextes
1773 TheAISContext()->CloseAllContexts();
1775 // On recupere les parametres
1776 Handle(AIS_InteractiveObject) theShapeA;
1777 Handle(AIS_InteractiveObject) theShapeB;
1779 // Parametres: AIS_Point AIS_Point
1780 // ===============================
1783 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1784 // On verifie que c'est bien une AIS_Point
1785 if (!theShapeA.IsNull() &&
1786 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1787 // on recupere le deuxieme AIS_Point
1789 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1790 if (theShapeA.IsNull() ||
1791 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1793 di <<"vline error: wrong type of 2de argument."<<"\n";
1797 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1798 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1799 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1800 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1802 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1803 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1804 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1806 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1807 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1808 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1810 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1812 di<<"vline error: same points"<<"\n";return 1;
1814 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1815 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1816 GetMapOfAIS().Bind(theAISLine,argv[1] );
1817 TheAISContext()->Display(theAISLine );
1821 // Parametres 6 Reals
1822 // ==================
1825 // On verifie que les deux points ne sont pas confondus
1827 Standard_Real coord[6];
1828 for(Standard_Integer i=0;i<=2;i++){
1829 coord[i]=Draw::Atof(argv[2+i]);
1830 coord[i+3]=Draw::Atof(argv[5+i]);
1833 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1834 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1836 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1837 GetMapOfAIS().Bind(theAISLine,argv[1] );
1838 TheAISContext()->Display(theAISLine );
1842 // Pas de parametres: Selection dans le viewer.
1843 // ============================================
1846 TheAISContext()->OpenLocalContext();
1847 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1849 // Active le mode Vertex.
1850 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1851 di<<" Select a vertex "<<"\n";
1853 // Boucle d'attente waitpick.
1854 Standard_Integer argcc = 5;
1855 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1856 const char **argvv = (const char **) buff;
1857 while (ViewerMainLoop( argcc, argvv) ) { }
1860 TopoDS_Shape ShapeA;
1861 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1862 ShapeA = TheAISContext()->SelectedShape();
1865 // ShapeA est un Vertex
1866 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1868 di<<" Select a different vertex."<<"\n";
1870 TopoDS_Shape ShapeB;
1873 // Boucle d'attente waitpick.
1874 Standard_Integer argccc = 5;
1875 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1876 const char **argvvv = (const char **) bufff;
1877 while (ViewerMainLoop( argccc, argvvv) ) { }
1880 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1881 ShapeB = TheAISContext()->SelectedShape();
1885 } while(ShapeB.IsSame(ShapeA) );
1887 // Fermeture du context local
1888 TheAISContext()->CloseLocalContext(myCurrentIndex);
1890 // Construction de la line
1891 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1892 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1894 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1895 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1897 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1898 GetMapOfAIS().Bind(theAISLine,argv[1] );
1899 TheAISContext()->Display(theAISLine );
1903 di<<"vline error."<<"\n";
1911 //==============================================================================
1912 // class : FilledCircle
1913 // purpose : creates filled circle based on AIS_InteractiveObject
1915 // This class is used to check method Matches() of class
1916 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1917 // because none of AIS classes provides creation of
1918 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1919 // (look method ComputeSelection() )
1920 //==============================================================================
1922 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1924 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1925 gp_Circ aCirc(anAxes, theRadius);
1926 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1930 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1932 class FilledCircle : public AIS_InteractiveObject
1936 DEFINE_STANDARD_RTTI(FilledCircle);
1938 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1939 FilledCircle(Handle(Geom_Circle) theCircle);
1942 TopoDS_Face ComputeFace();
1944 // Virtual methods implementation
1945 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1946 const Handle(Prs3d_Presentation)& thePresentation,
1947 const Standard_Integer theMode);
1949 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1950 const Standard_Integer theMode);
1953 Handle(Geom_Circle) myCircle;
1954 Standard_Boolean myFilledStatus;
1958 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1959 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1961 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1963 myCircle = CreateCircle(theCenter, theRadius);
1964 myFilledStatus = Standard_True;
1967 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1969 myCircle = theCircle;
1970 myFilledStatus = Standard_True;
1973 TopoDS_Face FilledCircle::ComputeFace()
1975 // Create edge from myCircle
1976 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1977 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1979 // Create wire from anEdge
1980 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1981 TopoDS_Wire aWire = aWireMaker.Wire();
1983 // Create face from aWire
1984 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1985 TopoDS_Face aFace = aFaceMaker.Face();
1990 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1991 const Handle(Prs3d_Presentation) &thePresentation,
1992 const Standard_Integer theMode)
1994 thePresentation->Clear();
1996 TopoDS_Face aFace = ComputeFace();
1998 if (aFace.IsNull()) return;
1999 if (theMode != 0) return;
2001 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2004 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2005 const Standard_Integer /*theMode*/)
2007 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2008 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2009 myCircle, myFilledStatus);
2010 theSelection->Add(aSensitiveCircle);
2013 //==============================================================================
2015 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2016 //==============================================================================
2018 //==============================================================================
2019 //function : VCircleBuilder
2020 //purpose : Build an AIS_Circle
2021 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2022 // PointName PointName PointName IsFilled
2023 //==============================================================================
2025 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2026 TCollection_AsciiString theName,
2027 Standard_Boolean isFilled)
2029 Handle(AIS_InteractiveObject) aCircle;
2032 aCircle = new FilledCircle(theGeomCircle);
2036 aCircle = new AIS_Circle(theGeomCircle);
2037 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2040 // Check if there is an object with given name
2041 // and remove it from context
2042 if (GetMapOfAIS().IsBound2(theName))
2044 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2045 Handle(AIS_InteractiveObject) anInterObj =
2046 Handle(AIS_InteractiveObject)::DownCast(anObj);
2047 TheAISContext()->Remove(anInterObj, Standard_False);
2048 GetMapOfAIS().UnBind2(theName);
2051 // Bind the circle to its name
2052 GetMapOfAIS().Bind(aCircle, theName);
2054 // Display the circle
2055 TheAISContext()->Display(aCircle);
2059 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2061 Standard_Integer myCurrentIndex;
2062 // Verification of the arguments
2063 if (argc>6 || argc<2)
2065 std::cout << "vcircle error: expect 4 arguments.\n";
2066 return 1; // TCL_ERROR
2068 TheAISContext()->CloseAllContexts();
2070 // There are all arguments
2074 TCollection_AsciiString aName(argv[1]);
2075 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2077 Handle(AIS_InteractiveObject) theShapeA;
2078 Handle(AIS_InteractiveObject) theShapeB;
2081 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2083 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2086 // Arguments: AIS_Point AIS_Point AIS_Point
2087 // ========================================
2088 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2089 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2091 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2093 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2094 return 1; // TCL_ERROR
2096 // The third object must be a point
2097 Handle(AIS_InteractiveObject) theShapeC =
2098 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2099 if (theShapeC.IsNull() ||
2100 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2102 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2103 return 1; // TCL_ERROR
2106 // Verify that the three points are different
2107 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2108 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2109 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2111 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2112 Handle(Geom_CartesianPoint) myCartPointA =
2113 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2115 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2116 Handle(Geom_CartesianPoint) myCartPointB =
2117 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2119 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2120 Handle(Geom_CartesianPoint) myCartPointC =
2121 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2124 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2125 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2126 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2128 std::cout << "vcircle error: Same points.\n";
2129 return 1; // TCL_ERROR
2132 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2133 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2134 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2136 std::cout << "vcircle error: Same points.\n";
2137 return 1; // TCL_ERROR
2140 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2141 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2142 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2144 std::cout << "vcircle error: Same points.\n";
2145 return 1;// TCL_ERROR
2147 // Construction of the circle
2148 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2149 myCartPointB->Pnt(), myCartPointC->Pnt() );
2150 Handle (Geom_Circle) theGeomCircle;
2153 theGeomCircle = Cir.Value();
2155 catch (StdFail_NotDone)
2157 std::cout << "vcircle error: can't create circle\n";
2158 return -1; // TCL_ERROR
2161 DisplayCircle(theGeomCircle, aName, isFilled);
2164 // Arguments: AIS_Plane AIS_Point Real
2165 // ===================================
2166 else if (theShapeA->Type() == AIS_KOI_Datum &&
2167 theShapeA->Signature() == 7 )
2169 if (theShapeB->Type() != AIS_KOI_Datum ||
2170 theShapeB->Signature() != 1 )
2172 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2173 return 1; // TCL_ERROR
2175 // Check that the radius is >= 0
2176 if (Draw::Atof(argv[4]) <= 0 )
2178 std::cout << "vcircle error: the radius must be >=0.\n";
2179 return 1; // TCL_ERROR
2182 // Recover the normal to the plane
2183 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2184 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2186 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2187 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2188 Handle(Geom_CartesianPoint) myCartPointB =
2189 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2191 gp_Pln mygpPlane = myGeomPlane->Pln();
2192 gp_Ax1 thegpAxe = mygpPlane.Axis();
2193 gp_Dir theDir = thegpAxe.Direction();
2194 gp_Pnt theCenter = myCartPointB->Pnt();
2195 Standard_Real TheR = Draw::Atof(argv[4]);
2196 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2197 Handle (Geom_Circle) theGeomCircle;
2200 theGeomCircle = Cir.Value();
2202 catch (StdFail_NotDone)
2204 std::cout << "vcircle error: can't create circle\n";
2205 return -1; // TCL_ERROR
2208 DisplayCircle(theGeomCircle, aName, isFilled);
2215 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2216 return 1; // TCL_ERROR
2220 // No arguments: selection in the viewer
2221 // =========================================
2224 // Get the name of the circle
2225 TCollection_AsciiString aName(argv[1]);
2227 TheAISContext()->OpenLocalContext();
2228 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2230 // Activate selection mode for vertices and faces
2231 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2232 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2233 std::cout << " Select a vertex or a face\n";
2236 Standard_Integer argcc = 5;
2237 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2238 const char **argvv = (const char **) buff;
2239 while (ViewerMainLoop( argcc, argvv) ) { }
2242 TopoDS_Shape ShapeA;
2243 for(TheAISContext()->InitSelected();
2244 TheAISContext()->MoreSelected();
2245 TheAISContext()->NextSelected() )
2247 ShapeA = TheAISContext()->SelectedShape();
2250 // ShapeA is a Vertex
2251 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2253 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2254 std::cout << " Select a different vertex\n";
2256 TopoDS_Shape ShapeB;
2260 Standard_Integer argccc = 5;
2261 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2262 const char **argvvv = (const char **) bufff;
2263 while (ViewerMainLoop( argccc, argvvv) ) { }
2266 for(TheAISContext()->InitSelected();
2267 TheAISContext()->MoreSelected();
2268 TheAISContext()->NextSelected() )
2270 ShapeB = TheAISContext()->SelectedShape();
2272 } while(ShapeB.IsSame(ShapeA) );
2274 // Selection of ShapeC
2275 std::cout << " Select the last vertex\n";
2276 TopoDS_Shape ShapeC;
2280 Standard_Integer argcccc = 5;
2281 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2282 const char **argvvvv = (const char **) buffff;
2283 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2286 for(TheAISContext()->InitSelected();
2287 TheAISContext()->MoreSelected();
2288 TheAISContext()->NextSelected() )
2290 ShapeC = TheAISContext()->SelectedShape();
2292 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2295 Standard_Boolean isFilled;
2296 std::cout << "Enter filled status (0 or 1)\n";
2299 // Close the local context
2300 TheAISContext()->CloseLocalContext(myCurrentIndex);
2302 // Construction of the circle
2303 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2304 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2305 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2307 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2308 Handle (Geom_Circle) theGeomCircle;
2311 theGeomCircle = Cir.Value();
2313 catch (StdFail_NotDone)
2315 std::cout << "vcircle error: can't create circle\n";
2316 return -1; // TCL_ERROR
2319 DisplayCircle(theGeomCircle, aName, isFilled);
2325 std::cout << " Select a vertex (in your face)\n";
2326 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2328 TopoDS_Shape ShapeB;
2330 Standard_Integer argccc = 5;
2331 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2332 const char **argvvv = (const char **) bufff;
2333 while (ViewerMainLoop( argccc, argvvv) ) { }
2336 for(TheAISContext()->InitSelected();
2337 TheAISContext()->MoreSelected();
2338 TheAISContext()->NextSelected() )
2340 ShapeB = TheAISContext()->SelectedShape();
2343 // Recover the radius
2344 Standard_Real theRad;
2347 std::cout << " Enter the value of the radius:\n";
2349 } while (theRad <= 0);
2351 // Get filled status
2352 Standard_Boolean isFilled;
2353 std::cout << "Enter filled status (0 or 1)\n";
2356 // Close the local context
2357 TheAISContext()->CloseLocalContext(myCurrentIndex);
2358 // Construction of the circle
2360 // Recover the normal to the plane. tag
2361 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2362 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2363 gp_Pln myPlane = mySurface.Plane();
2364 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2365 gp_Pln mygpPlane = theGeomPlane->Pln();
2366 gp_Ax1 thegpAxe = mygpPlane.Axis();
2367 gp_Dir theDir = thegpAxe.Direction();
2369 // Recover the center
2370 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2372 // Construct the circle
2373 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2374 Handle (Geom_Circle) theGeomCircle;
2377 theGeomCircle = Cir.Value();
2379 catch (StdFail_NotDone)
2381 std::cout << "vcircle error: can't create circle\n";
2382 return -1; // TCL_ERROR
2385 DisplayCircle(theGeomCircle, aName, isFilled);
2394 //=======================================================================
2395 //function : VDrawText
2397 //=======================================================================
2398 static int VDrawText (Draw_Interpretor& theDI,
2399 Standard_Integer theArgsNb,
2400 const char** theArgVec)
2402 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2405 std::cout << "Error: wrong number of arguments! See usage:\n";
2406 theDI.PrintHelp (theArgVec[0]);
2409 else if (aContext.IsNull())
2411 std::cout << "Error: no active view!\n";
2415 Standard_Integer anArgIt = 1;
2416 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2417 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2418 Handle(AIS_TextLabel) aTextPrs;
2419 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2421 if (GetMapOfAIS().IsBound2 (aName))
2423 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2427 aTextPrs = new AIS_TextLabel();
2428 aTextPrs->SetFont ("Courier");
2431 aTextPrs->SetText (aText);
2433 for (; anArgIt < theArgsNb; ++anArgIt)
2435 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2438 if (anAutoUpdater.parseRedrawMode (aParam))
2442 else if (aParam == "-pos"
2443 || aParam == "-position")
2445 if (anArgIt + 3 >= theArgsNb)
2447 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2452 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2453 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2454 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2455 aTextPrs->SetPosition (aPos);
2457 else if (aParam == "-color")
2459 if (anArgIt + 1 >= theArgsNb)
2461 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2465 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2466 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2467 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2470 aTextPrs->SetColor (aNameOfColor);
2473 else if (anArgIt + 3 >= theArgsNb)
2475 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2479 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2480 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2481 if (!aColor.IsRealValue()
2482 || !aGreen.IsRealValue()
2483 || !aBlue.IsRealValue())
2485 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2489 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2493 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2496 else if (aParam == "-halign")
2498 if (++anArgIt >= theArgsNb)
2500 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2504 TCollection_AsciiString aType (theArgVec[anArgIt]);
2506 if (aType == "left")
2508 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2510 else if (aType == "center")
2512 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2514 else if (aType == "right")
2516 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2520 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2524 else if (aParam == "-valign")
2526 if (++anArgIt >= theArgsNb)
2528 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2532 TCollection_AsciiString aType (theArgVec[anArgIt]);
2536 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2538 else if (aType == "center")
2540 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2542 else if (aType == "bottom")
2544 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2548 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2552 else if (aParam == "-angle")
2554 if (++anArgIt >= theArgsNb)
2556 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2560 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2562 else if (aParam == "-zoom")
2564 if (++anArgIt >= theArgsNb)
2566 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2570 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2572 else if (aParam == "-height")
2574 if (++anArgIt >= theArgsNb)
2576 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2580 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2582 else if (aParam == "-aspect")
2584 if (++anArgIt >= theArgsNb)
2586 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2590 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2591 anOption.LowerCase();
2592 if (anOption.IsEqual ("regular"))
2594 aTextPrs->SetFontAspect (Font_FA_Regular);
2596 else if (anOption.IsEqual ("bold"))
2598 aTextPrs->SetFontAspect (Font_FA_Bold);
2600 else if (anOption.IsEqual ("italic"))
2602 aTextPrs->SetFontAspect (Font_FA_Italic);
2604 else if (anOption.IsEqual ("bolditalic"))
2606 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2609 else if (aParam == "-font")
2611 if (++anArgIt >= theArgsNb)
2613 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2617 aTextPrs->SetFont (theArgVec[anArgIt]);
2621 std::cout << "Error: unknown argument '" << aParam << "'\n";
2626 ViewerTest::Display (aName, aTextPrs, Standard_False);
2631 #include <gp_Pnt.hxx>
2632 #include <Graphic3d_ArrayOfPoints.hxx>
2633 #include <Graphic3d_ArrayOfPrimitives.hxx>
2634 #include <Graphic3d_ArrayOfTriangles.hxx>
2635 #include <Poly_Array1OfTriangle.hxx>
2636 #include <Poly_Triangle.hxx>
2637 #include <Poly_Triangulation.hxx>
2638 #include <TColgp_Array1OfPnt.hxx>
2639 #include <TShort_Array1OfShortReal.hxx>
2640 #include <TShort_HArray1OfShortReal.hxx>
2642 #include <AIS_Triangulation.hxx>
2643 #include <StdPrs_ToolShadedShape.hxx>
2644 #include <Poly_Connect.hxx>
2645 #include <TColgp_Array1OfDir.hxx>
2646 #include <Graphic3d_GraphicDriver.hxx>
2648 #include <TColStd_Array1OfInteger.hxx>
2649 #include <TColStd_HArray1OfInteger.hxx>
2650 #include <Prs3d_ShadingAspect.hxx>
2651 #include <Graphic3d_MaterialAspect.hxx>
2652 #include <Graphic3d_AspectFillArea3d.hxx>
2654 #include <BRepPrimAPI_MakeCylinder.hxx>
2655 #include <TopoDS_Shape.hxx>
2656 #include <TopExp_Explorer.hxx>
2657 #include <TopAbs.hxx>
2658 #include <StdSelect_ShapeTypeFilter.hxx>
2661 //===============================================================================================
2662 //function : CalculationOfSphere
2664 //purpose : Create a Sphere
2665 //===============================================================================================
2667 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2670 double mRadius = Radius;
2671 double mCenter[3] = {X,Y,Z};
2672 int mThetaResolution;
2674 double mStartTheta = 0;//StartTheta;
2675 double mEndTheta = 360;//EndTheta;
2676 double mStartPhi = 0;//StartPhi;
2677 double mEndPhi = 180;//EndPhi;
2678 res = res < 4 ? 4 : res;
2680 mThetaResolution = res;
2681 mPhiResolution = res;
2684 int jStart, jEnd, numOffset;
2685 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2686 double startTheta, endTheta, startPhi, endPhi;
2687 int base, numPoles=0, thetaResolution, phiResolution;
2692 if ( numPieces > mThetaResolution ) {
2693 numPieces = mThetaResolution;
2696 int localThetaResolution = mThetaResolution;
2697 double localStartTheta = mStartTheta;
2698 double localEndTheta = mEndTheta;
2700 while ( localEndTheta < localStartTheta ) {
2701 localEndTheta += 360.0;
2704 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2706 // Change the ivars based on pieces.
2708 start = piece * localThetaResolution / numPieces;
2709 end = (piece+1) * localThetaResolution / numPieces;
2710 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2711 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2712 localThetaResolution = end - start;
2714 // Create north pole if needed
2715 int number_point = 0;
2716 int number_pointArray = 0;
2718 if ( mStartPhi <= 0.0 ) {
2719 number_pointArray++;
2722 if ( mEndPhi >= 180.0 ) {
2723 number_pointArray++;
2727 // Check data, determine increments, and convert to radians
2728 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2729 startTheta *= M_PI / 180.0;
2730 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2731 endTheta *= M_PI / 180.0;
2734 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2735 startPhi *= M_PI / 180.0;
2736 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2737 endPhi *= M_PI / 180.0;
2739 phiResolution = mPhiResolution - numPoles;
2740 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2741 thetaResolution = localThetaResolution;
2742 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2743 ++localThetaResolution;
2745 deltaTheta = (endTheta - startTheta) / thetaResolution;
2747 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2748 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2750 // Create intermediate points
2751 for ( i = 0; i < localThetaResolution; i++ ) {
2752 for ( j = jStart; j < jEnd; j++ ) {
2753 number_pointArray++;
2757 //Generate mesh connectivity
2758 base = phiResolution * localThetaResolution;
2760 int number_triangle = 0 ;
2761 if ( mStartPhi <= 0.0 ) { // around north pole
2762 number_triangle += localThetaResolution;
2765 if ( mEndPhi >= 180.0 ) { // around south pole
2766 number_triangle += localThetaResolution;
2769 // bands in-between poles
2770 for ( i=0; i < localThetaResolution; i++){
2771 for ( j=0; j < (phiResolution-1); j++){
2772 number_triangle +=2;
2776 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2777 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2778 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2780 if ( mStartPhi <= 0.0 ){
2783 x[2] = mCenter[2] + mRadius;
2784 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2787 // Create south pole if needed
2788 if ( mEndPhi >= 180.0 ){
2791 x[2] = mCenter[2] - mRadius;
2792 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2796 for ( i=0; i < localThetaResolution; i++){
2797 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2798 for ( j = jStart; j < jEnd; j++){
2799 phi = startPhi + j*deltaPhi;
2800 radius = mRadius * sin((double)phi);
2801 n[0] = radius * cos((double)theta);
2802 n[1] = radius * sin((double)theta);
2803 n[2] = mRadius * cos((double)phi);
2804 x[0] = n[0] + mCenter[0];
2805 x[1] = n[1] + mCenter[1];
2806 x[2] = n[2] + mCenter[2];
2807 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2813 number_triangle = 1;
2814 if ( mStartPhi <= 0.0 ){// around north pole
2815 for (i=0; i < localThetaResolution; i++){
2816 pts[0] = phiResolution*i + numPoles;
2817 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2819 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2824 if ( mEndPhi >= 180.0 ){ // around south pole
2825 numOffset = phiResolution - 1 + numPoles;
2826 for (i=0; i < localThetaResolution; i++){
2827 pts[0] = phiResolution*i + numOffset;
2828 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2829 pts[1] = numPoles - 1;
2830 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2835 // bands in-between poles
2837 for (i=0; i < localThetaResolution; i++){
2838 for (j=0; j < (phiResolution-1); j++){
2839 pts[0] = phiResolution*i + j + numPoles;
2840 pts[1] = pts[0] + 1;
2841 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2842 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2845 pts[2] = pts[1] - 1;
2846 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2851 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2853 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2855 Standard_Integer index[3];
2856 Standard_Real Tol = Precision::Confusion();
2859 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2860 gp_XYZ eqPlan(0, 0, 0);
2861 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2862 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2863 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2864 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2866 Standard_Real mod = vv.Modulus();
2867 if(mod < Tol) continue;
2871 Standard_Real modmax = eqPlan.Modulus();
2874 Nor = gp_Dir(eqPlan);
2876 Nor = gp_Dir(0., 0., 1.);
2878 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2879 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2880 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2881 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2885 polyTriangulation->SetNormals(Normals);
2887 return polyTriangulation;
2890 //===============================================================================================
2891 //function : VDrawSphere
2893 //purpose : Create an AIS shape.
2894 //===============================================================================================
2895 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2898 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2899 if (aContextAIS.IsNull())
2901 std::cout << "Call vinit before!\n";
2906 std::cout << "Use: " << argv[0]
2907 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2911 // read the arguments
2912 TCollection_AsciiString aShapeName (argv[1]);
2913 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2914 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2915 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2916 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2917 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2918 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2919 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2921 // remove AIS object with given name from map
2922 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2925 std::cout << "Compute Triangulation...\n";
2926 Handle(AIS_Triangulation) aShape
2927 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2930 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2931 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2933 // stupid initialization of Green color in RGBA space as integer
2934 // probably wrong for big-endian CPUs
2935 Standard_Integer aRed = 0;
2936 Standard_Integer aGreen = 255;
2937 Standard_Integer aBlue = 0;
2938 Standard_Integer anAlpha = 0; // not used
2939 Standard_Integer aColorInt = aRed;
2940 aColorInt += aGreen << 8;
2941 aColorInt += aBlue << 16;
2942 aColorInt += anAlpha << 24;
2944 // setup colors array per vertex
2945 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2946 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2948 aColorArray->SetValue (aNodeId, aColorInt);
2950 aShape->SetColors (aColorArray);
2953 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2954 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2955 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2956 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2957 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2958 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2959 aTotalSize >>= 20; //MB
2960 aNormalsSize >>= 20;
2962 aTrianglesSize >>= 20;
2963 aPolyConnectSize >>= 20;
2966 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2967 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2968 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2969 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2970 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2971 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2974 // Setting material properties, very important for desirable visual result!
2975 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2976 aMat.SetAmbient (0.2);
2977 aMat.SetSpecular (0.5);
2978 Handle(Graphic3d_AspectFillArea3d) anAspect
2979 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2981 Quantity_NOC_YELLOW,
2986 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2989 anAspect->SetEdgeOn();
2993 anAspect->SetEdgeOff();
2995 aShAsp->SetAspect (anAspect);
2996 aShape->Attributes()->SetShadingAspect (aShAsp);
2998 VDisplayAISObject (aShapeName, aShape);
3002 //=============================================================================
3003 //function : VComputeHLR
3005 //=============================================================================
3007 static int VComputeHLR (Draw_Interpretor& di,
3008 Standard_Integer argc,
3011 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3013 if (aContextAIS.IsNull ())
3015 di << "Please call vinit before\n";
3019 if ( argc != 3 && argc != 12 )
3021 di << "Usage: " << argv[0] << " ShapeName HlrName "
3022 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3023 << " ShapeName - name of the initial shape\n"
3024 << " HlrName - result hlr object from initial shape\n"
3025 << " eye, dir are eye position and look direction\n"
3026 << " up is the look up direction vector\n"
3027 << " Use vtop to see projected hlr shape\n";
3031 // shape and new object name
3032 TCollection_AsciiString aShapeName (argv[1]);
3033 TCollection_AsciiString aHlrName (argv[2]);
3035 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3038 BRep_Builder aBrepBuilder;
3039 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3042 di << "No shape with name " << argv[1] << " found\n";
3047 if (GetMapOfAIS ().IsBound2 (aHlrName))
3049 di << "Presentable object with name " << argv[2] << " already exists\n";
3053 // close local context
3054 if (aContextAIS->HasOpenedContext ())
3055 aContextAIS->CloseLocalContext ();
3057 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3058 HLRBRep_PolyHLRToShape aHLRToShape;
3067 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3068 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3069 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3070 aProjAx.SetLocation (anEye);
3071 aProjAx.SetDirection (aDir);
3072 aProjAx.SetYDirection (anUp);
3078 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3079 Handle(V3d_View) aView = ViewerTest::CurrentView();
3080 Standard_Integer aWidth, aHeight;
3081 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3082 Standard_Real aRightX, aRightY, aRightZ;
3083 aView->Window()->Size (aWidth, aHeight);
3085 aView->ConvertWithProj (aWidth, aHeight/2,
3086 aRightX, aRightY, aRightZ,
3087 aDirX, aDirY, aDirZ);
3089 aView->ConvertWithProj (aWidth/2, aHeight/2,
3090 aCentX, aCentY, aCentZ,
3091 aDirX, aDirY, aDirZ);
3093 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3094 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3095 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3096 aProjAx.SetLocation (anEye);
3097 aProjAx.SetDirection (aDir);
3098 aProjAx.SetXDirection (aRight);
3101 HLRAlgo_Projector aProjector (aProjAx);
3102 aPolyAlgo->Projector (aProjector);
3103 aPolyAlgo->Load (aSh);
3104 aPolyAlgo->Update ();
3106 aHLRToShape.Update (aPolyAlgo);
3108 // make hlr shape from input shape
3109 TopoDS_Compound aHlrShape;
3110 BRep_Builder aBuilder;
3111 aBuilder.MakeCompound (aHlrShape);
3113 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3114 if (!aCompound.IsNull ())
3116 aBuilder.Add (aHlrShape, aCompound);
3119 // extract visible outlines
3120 aCompound = aHLRToShape.OutLineVCompound();
3121 if (!aCompound.IsNull ())
3123 aBuilder.Add (aHlrShape, aCompound);
3126 // create an AIS shape and display it
3127 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3128 GetMapOfAIS().Bind (anObject, aHlrName);
3129 aContextAIS->Display (anObject);
3131 aContextAIS->UpdateCurrentViewer ();
3136 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3137 // manipulating and displaying such an array with AIS context
3138 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3139 class MyPArrayObject : public AIS_InteractiveObject
3144 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3145 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3147 myArrayDescription = theArrayDescription;
3148 myMarkerAspect = theMarkerAspect;
3151 DEFINE_STANDARD_RTTI(MyPArrayObject);
3155 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3156 const Handle(Prs3d_Presentation)& aPresentation,
3157 const Standard_Integer aMode);
3159 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3160 const Standard_Integer /*theMode*/);
3162 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3163 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3164 Standard_Integer &theArgIndex,
3165 Standard_Integer theArgCount,
3166 Standard_Integer theMaxArgs);
3170 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3171 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3175 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3176 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3178 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3179 const Handle(Prs3d_Presentation)& aPresentation,
3180 const Standard_Integer /*aMode*/)
3183 // Parsing array description
3184 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3185 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3186 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3188 Standard_Integer anArgIndex = 0;
3189 Standard_Integer anArgsCount = myArrayDescription->Length();
3190 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3192 TCollection_AsciiString aCommand;
3193 while (anArgIndex < anArgsCount)
3195 aCommand = myArrayDescription->Value (anArgIndex);
3196 aCommand.LowerCase();
3199 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3201 // vertex has a normal or normal with color or texel
3202 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3203 hasNormals = Standard_True;
3205 // vertex has a color
3206 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3207 hasVColors = Standard_True;
3209 // vertex has a texel
3210 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3211 hasTexels = Standard_True;
3216 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3219 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3220 hasBColors = Standard_True;
3225 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3234 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3235 if (anArrayType == "points")
3237 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3239 else if (anArrayType == "segments")
3240 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3241 else if (anArrayType == "polylines")
3242 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3243 hasVColors, hasBColors);
3244 else if (anArrayType == "triangles")
3245 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3246 hasVColors, hasTexels);
3247 else if (anArrayType == "trianglefans")
3248 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3249 hasNormals, hasVColors,
3250 hasBColors, hasTexels);
3251 else if (anArrayType == "trianglestrips")
3252 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3253 hasNormals, hasVColors,
3254 hasBColors, hasTexels);
3255 else if (anArrayType == "quads")
3256 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3257 hasNormals, hasVColors,
3259 else if (anArrayType == "quadstrips")
3260 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3261 hasNormals, hasVColors,
3262 hasBColors, hasTexels);
3263 else if (anArrayType == "polygons")
3264 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3265 hasNormals, hasVColors, hasBColors,
3269 while (anArgIndex < anArgsCount)
3271 aCommand = myArrayDescription->Value (anArgIndex);
3272 aCommand.LowerCase();
3273 if (!aCommand.IsAscii())
3277 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3279 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3280 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3281 myArrayDescription->Value (anArgIndex - 1).RealValue());
3282 const Standard_Integer aVertIndex = anArray->VertexNumber();
3284 // vertex has a normal or normal with color or texel
3285 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3286 anArray->SetVertexNormal (aVertIndex,
3287 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3288 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3289 myArrayDescription->Value (anArgIndex - 1).RealValue());
3291 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3292 anArray->SetVertexColor (aVertIndex,
3293 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3294 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3295 myArrayDescription->Value (anArgIndex - 1).RealValue());
3297 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3298 anArray->SetVertexTexel (aVertIndex,
3299 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3300 myArrayDescription->Value (anArgIndex - 1).RealValue());
3303 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3305 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3307 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3308 anArray->AddBound (aVertCount,
3309 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3310 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3311 myArrayDescription->Value (anArgIndex - 1).RealValue());
3314 anArray->AddBound (aVertCount);
3317 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3319 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3320 anArray->AddEdge (aVertIndex);
3327 aPresentation->Clear();
3328 if (!myMarkerAspect.IsNull())
3330 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3332 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3335 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3336 const Standard_Integer /*theMode*/)
3338 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3340 Standard_Integer anArgIndex = 1;
3341 while (anArgIndex < myArrayDescription->Length())
3343 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3345 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3346 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3347 myArrayDescription->Value (anArgIndex - 1).RealValue());
3348 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3349 theSelection->Add (aSensetivePoint);
3358 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3359 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3360 Standard_Integer &theArgIndex,
3361 Standard_Integer theArgCount,
3362 Standard_Integer theMaxArgs)
3364 // check if there is more elements than expected
3365 if (theArgIndex >= theMaxArgs)
3368 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3369 aStrCommand.LowerCase();
3370 if (aStrCommand.Search(theCommand) != 1 ||
3371 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3374 // go to the first data element
3377 // check data if it can be converted to numeric
3378 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3380 aStrCommand = theArgsArray->Value (theArgIndex);
3381 if (!aStrCommand.IsRealValue())
3388 //=============================================================================
3389 //function : VDrawPArray
3390 //purpose : Draws primitives array from list of vertexes, bounds, edges
3391 //=============================================================================
3393 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3395 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3396 if (aContextAIS.IsNull())
3398 di << "Call vinit before!\n";
3403 di << "Use: " << argv[0] << " Name TypeOfArray"
3404 << " [vertex] ... [bounds] ... [edges]\n"
3405 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3406 << " trianglefans | trianglestrips | quads |\n"
3407 << " quadstrips | polygons }\n"
3408 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3409 << " [texel={ 't' tx ty }] } \n"
3410 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3411 << " edges={ 'e' vertex_id }\n";
3415 // read the arguments
3416 Standard_Integer aArgIndex = 1;
3417 TCollection_AsciiString aName (argv[aArgIndex++]);
3418 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3420 Standard_Boolean hasVertex = Standard_False;
3422 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3423 anArgsArray->SetValue (0, anArrayType);
3425 if (anArrayType != "points" &&
3426 anArrayType != "segments" &&
3427 anArrayType != "polylines" &&
3428 anArrayType != "triangles" &&
3429 anArrayType != "trianglefans" &&
3430 anArrayType != "trianglestrips" &&
3431 anArrayType != "quads" &&
3432 anArrayType != "quadstrips" &&
3433 anArrayType != "polygons")
3435 di << "Unexpected type of primitives array\n";
3439 TCollection_AsciiString aCommand;
3440 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3442 aCommand = argv[anArgIndex];
3443 aCommand.LowerCase();
3444 if (!aCommand.IsAscii())
3446 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3447 << "should be an array element: 'v', 'b', 'e' \n";
3451 if (aCommand == "v")
3453 hasVertex = Standard_True;
3456 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3461 di << "You should pass any verticies in the list of array elements\n";
3465 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3466 if (anArrayType == "points")
3468 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3471 // create primitives array object
3472 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3474 // register the object in map
3475 VDisplayAISObject (aName, aPObject);
3480 //=======================================================================
3481 //function : VSetLocation
3482 //purpose : Change location of AIS interactive object
3483 //=======================================================================
3485 static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
3486 Standard_Integer theArgNb,
3487 const char** theArgVec)
3489 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3490 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3491 if (aContext.IsNull())
3493 std::cout << "Error: no active view!\n";
3497 TCollection_AsciiString aName;
3499 Standard_Boolean isSetLoc = Standard_False;
3501 Standard_Integer anArgIter = 1;
3502 for (; anArgIter < theArgNb; ++anArgIter)
3504 Standard_CString anArg = theArgVec[anArgIter];
3505 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3509 else if (aName.IsEmpty())
3515 isSetLoc = Standard_True;
3516 if (anArgIter + 1 >= theArgNb)
3518 std::cout << "Error: syntax error at '" << anArg << "'\n";
3521 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3522 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3523 if (anArgIter + 1 < theArgNb)
3525 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3530 std::cout << "Error: unknown argument '" << anArg << "'\n";
3536 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3537 Handle(AIS_InteractiveObject) anIObj;
3538 if (aMap.IsBound2 (aName))
3540 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3542 if (anIObj.IsNull())
3544 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3549 aTrsf.SetTranslation (aLocVec);
3550 TopLoc_Location aLocation (aTrsf);
3551 aContext->SetLocation (anIObj, aLocation);
3555 //=======================================================================
3556 //function : TransformPresentation
3557 //purpose : Change transformation of AIS interactive object
3558 //=======================================================================
3559 static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3560 Standard_Integer theArgNb,
3561 const char** theArgVec)
3565 std::cout << "Error: too few arguments.\n";
3569 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3570 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3571 if (aContext.IsNull())
3573 std::cout << "Error: no active view!\n";
3578 Standard_Integer aLast = theArgNb;
3579 const char* aName = theArgVec[0];
3581 Standard_Boolean isReset = Standard_False;
3582 Standard_Boolean isMove = Standard_False;
3587 if (!strcmp (aName, "reset"))
3589 isReset = Standard_True;
3591 else if (!strcmp (aName, "move"))
3595 std::cout << "Error: too few arguments.\n";
3599 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3601 Handle(AIS_InteractiveObject) anIObj;
3602 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3604 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3607 if (anIObj.IsNull())
3609 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3613 isMove = Standard_True;
3615 aTrsf = anIObj->Transformation();
3616 aLast = theArgNb - 1;
3618 else if (!strcmp (aName, "translate"))
3622 std::cout << "Error: too few arguments.\n";
3625 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3626 Draw::Atof (theArgVec[theArgNb - 2]),
3627 Draw::Atof (theArgVec[theArgNb - 1])));
3628 aLast = theArgNb - 3;
3630 else if (!strcmp (aName, "rotate"))
3634 std::cout << "Error: too few arguments.\n";
3639 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3640 Draw::Atof (theArgVec[theArgNb - 6]),
3641 Draw::Atof (theArgVec[theArgNb - 5])),
3642 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3643 Draw::Atof (theArgVec[theArgNb - 3]),
3644 Draw::Atof (theArgVec[theArgNb - 2]))),
3645 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3647 aLast = theArgNb - 7;
3649 else if (!strcmp (aName, "mirror"))
3653 std::cout << "Error: too few arguments.\n";
3657 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3658 Draw::Atof(theArgVec[theArgNb - 5]),
3659 Draw::Atof(theArgVec[theArgNb - 4])),
3660 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3661 Draw::Atof(theArgVec[theArgNb - 2]),
3662 Draw::Atof(theArgVec[theArgNb - 1]))));
3663 aLast = theArgNb - 6;
3665 else if (!strcmp (aName, "scale"))
3669 std::cout << "Error: too few arguments.\n";
3673 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3674 Draw::Atof(theArgVec[theArgNb - 3]),
3675 Draw::Atof(theArgVec[theArgNb - 2])),
3676 Draw::Atof(theArgVec[theArgNb - 1]));
3677 aLast = theArgNb - 4;
3680 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3683 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3684 Handle(AIS_InteractiveObject) anIObj;
3685 if (aMap.IsBound2 (theArgVec[anIdx]))
3687 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3689 if (anIObj.IsNull())
3691 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3697 // aTrsf already identity
3701 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3705 aTrsf = anIObj->LocalTransformation() * aTrsf;
3708 TopLoc_Location aLocation (aTrsf);
3709 aContext->SetLocation (anIObj, aLocation);
3715 //===============================================================================================
3716 //function : VConnect
3717 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3718 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
3719 //===============================================================================================
3721 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3722 Standard_Integer argc,
3726 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3727 if (aContext.IsNull())
3729 std::cout << "vconnect error : call vinit before\n";
3730 return 1; // TCL_ERROR
3735 std::cout << "vconnect error: expect at least 5 arguments\n";
3736 return 1; // TCL_ERROR
3740 Standard_Integer anArgIter = 1;
3741 TCollection_AsciiString aName (argv[anArgIter++]);
3742 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
3743 TCollection_AsciiString aColorString (argv[argc-1]);
3744 Standard_CString aColorName = "";
3745 Standard_Boolean hasColor = Standard_False;
3746 if (aColorString.Search ("color=") != -1)
3748 hasColor = Standard_True;
3749 aColorString.Remove (1, 6);
3750 aColorName = aColorString.ToCString();
3752 Handle(AIS_InteractiveObject) anObject;
3754 // AIS_MultipleConnectedInteractive
3755 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3756 for (Standard_Integer i = 5; i < aNbShapes; ++i)
3758 TCollection_AsciiString anOriginObjectName (argv[i]);
3759 if (aName.IsEqual (anOriginObjectName))
3761 std::cout << "vconnect error: equal names for connected objects\n";
3764 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3766 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3767 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3768 if (anObject.IsNull())
3770 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3776 Standard_CString aName = anOriginObjectName.ToCString();
3777 TopoDS_Shape aTDShape = DBRep::Get (aName);
3778 if (aTDShape.IsNull())
3780 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3783 anObject = new AIS_Shape (aTDShape);
3784 aContext->Load (anObject);
3785 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3788 if (anOriginObject.IsNull())
3790 anOriginObject = new AIS_MultipleConnectedInteractive();
3793 anOriginObject->Connect (anObject);
3795 if (anOriginObject.IsNull())
3797 std::cout << "vconect error : can't connect input objects\n";
3798 return 1; // TCL_ERROR
3801 // Get location data
3802 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3803 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3804 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3806 // Create transformation
3807 gp_Vec aTranslation (aXo, aYo, aZo);
3810 aTrsf.SetTranslationPart (aTranslation);
3811 TopLoc_Location aLocation (aTrsf);
3813 anOriginObject->SetLocalTransformation (aTrsf);
3815 // Check if there is another object with given name
3816 // and remove it from context
3817 if(GetMapOfAIS().IsBound2(aName))
3819 Handle(AIS_InteractiveObject) anObj =
3820 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3821 TheAISContext()->Remove(anObj, Standard_False);
3822 GetMapOfAIS().UnBind2(aName);
3825 // Bind connected object to its name
3826 GetMapOfAIS().Bind (anOriginObject, aName);
3828 // Display connected object
3829 TheAISContext()->Display (anOriginObject);
3834 //===============================================================================================
3835 //function : VConnectTo
3836 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3837 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
3838 //===============================================================================================
3840 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3841 Standard_Integer argc,
3845 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3846 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3847 if (aContext.IsNull())
3849 std::cout << "vconnect error : call vinit before\n";
3850 return 1; // TCL_ERROR
3853 if (argc != 6 && argc != 7)
3855 std::cout << "vconnect error: expect at least 5 arguments\n";
3856 return 1; // TCL_ERROR
3860 Standard_Integer anArgIter = 1;
3861 TCollection_AsciiString aName (argv[anArgIter++]);
3862 Handle(AIS_InteractiveObject) anOriginObject;
3864 TCollection_AsciiString anOriginObjectName(argv[5]);
3865 if (aName.IsEqual (anOriginObjectName))
3867 std::cout << "vconnect error: equal names for connected objects\n";
3868 return 1; // TCL_ERROR
3870 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3872 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3873 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3874 if (anOriginObject.IsNull())
3876 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3877 return 1; // TCL_ERROR
3882 Standard_CString aName = anOriginObjectName.ToCString();
3883 TopoDS_Shape aTDShape = DBRep::Get (aName);
3884 if (aTDShape.IsNull())
3886 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3887 return 1; // TCL_ERROR
3889 anOriginObject = new AIS_Shape (aTDShape);
3890 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
3893 // Get location data
3894 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3895 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3896 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3898 // Create transformation
3899 gp_Vec aTranslation (aXo, aYo, aZo);
3902 aTrsf.SetTranslationPart (aTranslation);
3904 Handle(AIS_ConnectedInteractive) aConnected;
3906 aConnected = new AIS_ConnectedInteractive();
3908 aConnected->Connect (anOriginObject, aTrsf);
3910 // Check if there is another object with given name
3911 // and remove it from context
3912 if(GetMapOfAIS().IsBound2(aName))
3914 Handle(AIS_InteractiveObject) anObj =
3915 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3916 TheAISContext()->Remove(anObj, Standard_False);
3917 GetMapOfAIS().UnBind2(aName);
3920 // Bind connected object to its name
3921 GetMapOfAIS().Bind (aConnected, aName);
3925 TCollection_AsciiString anArg = argv[6];
3927 if (anArg == "-nodisplay")
3930 if (!anUpdateTool.parseRedrawMode (anArg))
3932 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
3936 // Display connected object
3937 TheAISContext()->Display (aConnected, Standard_False);
3942 //=======================================================================
3943 //function : VDisconnect
3945 //=======================================================================
3946 static Standard_Integer VDisconnect (Draw_Interpretor& di,
3947 Standard_Integer argc,
3950 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3951 if (aContext.IsNull())
3953 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3959 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
3963 TCollection_AsciiString aName (argv[1]);
3964 TCollection_AsciiString anObject (argv[2]);
3965 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
3968 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3969 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3970 if (!aMap.IsBound2 (aName) )
3972 std::cout << "Use 'vdisplay' before" << "\n";
3976 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3977 if (anAssembly.IsNull())
3979 di << "Not an assembly" << "\n";
3983 Handle(AIS_InteractiveObject) anIObj;
3984 if (!aMap.IsBound2 (anObject))
3986 // try to interpret second argument as child number
3987 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
3989 Standard_Integer aCounter = 1;
3990 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3992 if (aCounter == anObjectNumber)
3994 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4002 std::cout << "Use 'vdisplay' before" << "\n";
4007 // if object was found by name
4008 if (anIObj.IsNull())
4010 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4013 aContext->Disconnect (anAssembly, anIObj);
4014 aContext->UpdateCurrentViewer();
4019 //=======================================================================
4020 //function : VAddConnected
4022 //=======================================================================
4023 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4024 Standard_Integer argc,
4027 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4028 if (aContext.IsNull())
4030 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4036 std::cout << argv[0] << " error: expect 5 arguments\n";
4040 TCollection_AsciiString aName (argv[1]);
4041 TCollection_AsciiString anObject (argv[5]);
4042 Standard_Real aX = Draw::Atof (argv[2]);
4043 Standard_Real aY = Draw::Atof (argv[3]);
4044 Standard_Real aZ = Draw::Atof (argv[4]);
4047 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4048 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4049 if (!aMap.IsBound2 (aName) )
4051 std::cout << "Use 'vdisplay' before" << "\n";
4055 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4056 if (anAssembly.IsNull())
4058 di << "Not an assembly" << "\n";
4062 Handle(AIS_InteractiveObject) anIObj;
4063 if (!aMap.IsBound2 (anObject))
4065 std::cout << "Use 'vdisplay' before" << "\n";
4069 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4072 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4074 anAssembly->Connect (anIObj, aTrsf);
4075 TheAISContext()->Display (anAssembly);
4076 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4077 aContext->UpdateCurrentViewer();
4082 //=======================================================================
4083 //function : VListConnected
4085 //=======================================================================
4086 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4087 Standard_Integer argc,
4090 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4091 if (aContext.IsNull())
4093 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4099 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
4103 TCollection_AsciiString aName (argv[1]);
4106 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4107 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4108 if (!aMap.IsBound2 (aName) )
4110 std::cout << "Use 'vdisplay' before" << "\n";
4114 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4115 if (anAssembly.IsNull())
4117 std::cout << "Not an assembly" << "\n";
4121 std::cout << "Children of " << aName << ":\n";
4123 Standard_Integer aCounter = 1;
4124 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4126 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4128 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
4129 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4132 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4134 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4135 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4137 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4139 std::cout << std::endl;
4149 //! Checks if theMode is already turned on for theObj.
4150 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4151 const Handle(AIS_InteractiveObject)& theObj,
4152 const Standard_Integer theMode)
4154 TColStd_ListOfInteger anActiveModes;
4155 theAISContext->ActivatedModes (theObj, anActiveModes);
4156 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4158 if (aModeIt.Value() == theMode)
4160 return Standard_True;
4163 return Standard_False;
4167 //===============================================================================================
4168 //function : VSetSelectionMode
4169 //purpose : Sets input selection mode for input object or for all displayed objects
4170 //Draw arg : vselmode [object] mode On/Off (1/0)
4171 //===============================================================================================
4172 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4173 Standard_Integer theArgc,
4174 const char** theArgv)
4177 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4178 if (anAISContext.IsNull())
4180 std::cerr << "Call vinit before!" << std::endl;
4184 // Check the arguments
4185 if (theArgc != 3 && theArgc != 4)
4187 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4188 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
4192 // get objects to change selection mode
4193 AIS_ListOfInteractive aTargetIOs;
4196 anAISContext->DisplayedObjects (aTargetIOs);
4200 // Check if there is an object with given name in context
4201 const TCollection_AsciiString aNameIO (theArgv[1]);
4202 if (GetMapOfAIS().IsBound2 (aNameIO))
4204 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4207 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
4210 aTargetIOs.Append (anIO);
4214 const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]);
4215 const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]);
4216 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4218 anAISContext->CloseLocalContext();
4221 if (aSelectionMode == 0)
4225 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4227 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4228 if (!InList (anAISContext, anIO, aSelectionMode))
4230 anAISContext->Activate (anIO);
4236 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4238 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4239 if (InList (anAISContext, anIO, aSelectionMode))
4241 anAISContext->Deactivate (anIO);
4247 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
4249 if (!anAISContext->HasOpenedContext())
4251 anAISContext->OpenLocalContext (Standard_False);
4254 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4256 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4257 if (!InList (anAISContext, anIO, aSelectionMode))
4259 anAISContext->Load (anIO, -1, Standard_True);
4260 anAISContext->Activate (anIO, aSelectionMode);
4265 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4267 if (!anAISContext->HasOpenedContext())
4272 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4274 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4275 if (InList (anAISContext, anIO, aSelectionMode))
4277 anAISContext->Deactivate (anIO, aSelectionMode);
4285 //===============================================================================================
4286 //function : VSelectionNext
4288 //===============================================================================================
4289 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4290 Standard_Integer /*theArgsNb*/,
4291 const char** /*theArgVec*/)
4294 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4295 Handle(V3d_View) aView = ViewerTest::CurrentView();
4297 if (anAISContext.IsNull())
4299 std::cerr << "Call vinit before!" << std::endl;
4303 anAISContext->HilightNextDetected(aView);
4307 //===============================================================================================
4308 //function : VSelectionPrevious
4310 //===============================================================================================
4311 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4312 Standard_Integer /*theArgsNb*/,
4313 const char** /*theArgVec*/)
4316 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4317 Handle(V3d_View) aView = ViewerTest::CurrentView();
4319 if (anAISContext.IsNull())
4321 std::cerr << "Call vinit before!" << std::endl;
4325 anAISContext->HilightPreviousDetected(aView);
4330 //==========================================================================
4332 //purpose : creates Triangle based on AIS_InteractiveObject.
4333 // This class was implemented for testing Select3D_SensitiveTriangle
4334 //===========================================================================
4335 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4336 class Triangle: public AIS_InteractiveObject
4340 DEFINE_STANDARD_RTTI(FilledCircle);
4341 Triangle (const gp_Pnt& theP1,
4342 const gp_Pnt& theP2,
4343 const gp_Pnt& theP3);
4345 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4346 const Handle(Prs3d_Presentation)& thePresentation,
4347 const Standard_Integer theMode);
4349 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4350 const Standard_Integer theMode);
4356 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4357 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
4359 Triangle::Triangle (const gp_Pnt& theP1,
4360 const gp_Pnt& theP2,
4361 const gp_Pnt& theP3)
4368 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4369 const Handle(Prs3d_Presentation)& thePresentation,
4370 const Standard_Integer /*theMode*/)
4372 thePresentation->Clear();
4374 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4375 anEdgeMaker2(myPoint2, myPoint3),
4376 anEdgeMaker3(myPoint3, myPoint1);
4378 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4379 anEdge2 = anEdgeMaker2.Edge(),
4380 anEdge3 = anEdgeMaker3.Edge();
4381 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4384 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4385 TopoDS_Wire aWire = aWireMaker.Wire();
4386 if(aWire.IsNull()) return;
4388 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4389 TopoDS_Face aFace = aFaceMaker.Face();
4390 if(aFace.IsNull()) return;
4392 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4395 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
4396 const Standard_Integer /*theMode*/)
4398 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4399 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4400 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4401 theSelection->Add(aSensTriangle);
4404 //===========================================================================
4405 //function : VTriangle
4406 //Draw arg : vtriangle Name PointName PointName PointName
4407 //purpose : creates and displays Triangle
4408 //===========================================================================
4411 //purpose : checks if the object with theName is AIS_Point,
4412 // if yes initialize thePoint from MapOfAIS
4413 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4414 Handle(AIS_Point)& thePoint)
4416 Handle(AIS_InteractiveObject) anObject =
4417 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4418 if(anObject.IsNull() ||
4419 anObject->Type() != AIS_KOI_Datum ||
4420 anObject->Signature() != 1)
4422 return Standard_False;
4424 thePoint = Handle(AIS_Point)::DownCast(anObject);
4425 if(thePoint.IsNull())
4426 return Standard_False;
4427 return Standard_True;
4431 //purpose: checks if thePoint1 is equal to thePoint2
4432 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4433 const Handle(Geom_CartesianPoint)& thePoint2)
4435 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4436 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4437 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4439 return Standard_True;
4441 return Standard_False;
4444 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4445 Standard_Integer argc,
4451 std::cout<<"vtriangle error: expects 4 argumnets\n";
4452 return 1; // TCL_ERROR
4455 TheAISContext()->CloseAllContexts();
4457 // Get and check values
4458 TCollection_AsciiString aName(argv[1]);
4460 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4461 if (!IsPoint(argv[2], aPoint1))
4463 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4464 return 1; // TCL_ERROR
4466 if (!IsPoint(argv[3], aPoint2))
4468 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4469 return 1; // TCL_ERROR
4471 if (!IsPoint(argv[4], aPoint3))
4473 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4474 return 1; // TCL_ERROR
4477 // Check that points are different
4478 Handle(Geom_CartesianPoint) aCartPoint1 =
4479 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4480 Handle(Geom_CartesianPoint) aCartPoint2 =
4481 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4482 // Test aPoint1 = aPoint2
4483 if (IsMatch(aCartPoint1, aCartPoint2))
4485 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4486 return 1; // TCL_ERROR
4488 // Test aPoint2 = aPoint3
4489 Handle(Geom_CartesianPoint) aCartPoint3 =
4490 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4491 if (IsMatch(aCartPoint2, aCartPoint3))
4493 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4494 return 1; // TCL_ERROR
4496 // Test aPoint3 = aPoint1
4497 if (IsMatch(aCartPoint1, aCartPoint3))
4499 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4500 return 1; // TCL_ERROR
4504 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4506 aCartPoint3->Pnt());
4508 // Check if there is an object with given name
4509 // and remove it from context
4510 if (GetMapOfAIS().IsBound2(aName))
4512 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4513 Handle(AIS_InteractiveObject) anInterObj =
4514 Handle(AIS_InteractiveObject)::DownCast(anObj);
4515 TheAISContext()->Remove(anInterObj, Standard_False);
4516 GetMapOfAIS().UnBind2(aName);
4519 // Bind triangle to its name
4520 GetMapOfAIS().Bind(aTriangle, aName);
4523 TheAISContext()->Display(aTriangle);
4527 //class : SegmentObject
4528 //purpose: creates segment based on AIS_InteractiveObject.
4529 // This class was implemented for testing Select3D_SensitiveCurve
4530 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4531 class SegmentObject: public AIS_InteractiveObject
4535 DEFINE_STANDARD_RTTI(SegmentObject);
4536 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4538 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4539 const Handle(Prs3d_Presentation)& thePresentation,
4540 const Standard_Integer theMode);
4542 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4543 const Standard_Integer theMode);
4548 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4549 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4551 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4557 void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4558 const Handle(Prs3d_Presentation) &thePresentation,
4559 const Standard_Integer /*theMode*/)
4561 thePresentation->Clear();
4562 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4563 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4564 if (anEdge.IsNull())
4566 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4567 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4570 void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
4571 const Standard_Integer /*theMode*/)
4573 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4574 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4575 anArray->SetValue(1, myPoint1);
4576 anArray->SetValue(2, myPoint2);
4577 Handle(Select3D_SensitiveCurve) aSensCurve =
4578 new Select3D_SensitiveCurve(anOwner, anArray);
4579 theSelection->Add(aSensCurve);
4582 //=======================================================================
4583 //function : VSegment
4584 //Draw args : vsegment Name PointName PointName
4585 //purpose : creates and displays Segment
4586 //=======================================================================
4587 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4588 Standard_Integer argc,
4594 std::cout<<"vsegment error: expects 3 arguments\n";
4595 return 1; // TCL_ERROR
4598 TheAISContext()->CloseAllContexts();
4600 // Get and check arguments
4601 TCollection_AsciiString aName(argv[1]);
4602 Handle(AIS_Point) aPoint1, aPoint2;
4603 if (!IsPoint(argv[2], aPoint1))
4605 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4606 return 1; // TCL_ERROR
4608 if (!IsPoint(argv[3], aPoint2))
4610 std::cout<<"vsegment error: the 3d argument should be a point\n";
4611 return 1; // TCL_ERROR
4613 //Check that points are different
4614 Handle(Geom_CartesianPoint) aCartPoint1 =
4615 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4616 Handle(Geom_CartesianPoint) aCartPoint2 =
4617 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4618 if(IsMatch(aCartPoint1, aCartPoint2))
4620 std::cout<<"vsegment error: equal points\n";
4621 return 1; // TCL_ERROR
4625 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4626 // Check if there is an object with given name
4627 // and remove it from context
4628 if (GetMapOfAIS().IsBound2(aName))
4630 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4631 Handle(AIS_InteractiveObject) anInterObj =
4632 Handle(AIS_InteractiveObject)::DownCast(anObj);
4633 TheAISContext()->Remove(anInterObj, Standard_False);
4634 GetMapOfAIS().UnBind2(aName);
4637 // Bind segment to its name
4638 GetMapOfAIS().Bind(aSegment, aName);
4641 TheAISContext()->Display(aSegment);
4645 //=======================================================================
4646 //function : VObjZLayer
4647 //purpose : Set or get z layer id for presentable object
4648 //=======================================================================
4650 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4651 Standard_Integer argc,
4654 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4655 if (aContext.IsNull())
4657 di << argv[0] << "Call 'vinit' before!\n";
4662 TCollection_AsciiString aOperation;
4664 aOperation = TCollection_AsciiString (argv [1]);
4666 // check for correct arguments
4667 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4668 !(argc == 3 && aOperation.IsEqual ("get")))
4670 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4671 di << " set - set layer id for interactive object, layerid - z layer id\n";
4672 di << " get - get layer id of interactive object\n";
4673 di << " argument layerid should be passed for set operation only\n";
4678 TCollection_AsciiString aName (argv[2]);
4679 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4680 if (!aMap.IsBound2 (aName))
4682 di << "Use 'vdisplay' before" << "\n";
4686 // find interactive object
4687 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4688 Handle(AIS_InteractiveObject) anInterObj =
4689 Handle(AIS_InteractiveObject)::DownCast (anObj);
4690 if (anInterObj.IsNull())
4692 di << "Not an AIS interactive object!\n";
4696 // process operation
4697 if (aOperation.IsEqual ("set"))
4699 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4700 aContext->SetZLayer (anInterObj, aLayerId);
4702 else if (aOperation.IsEqual ("get"))
4704 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4710 //=======================================================================
4711 //function : VPolygonOffset
4712 //purpose : Set or get polygon offset parameters
4713 //=======================================================================
4714 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4715 Standard_Integer argc,
4718 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4719 if (aContext.IsNull())
4721 std::cout << argv[0] << " Call 'vinit' before!\n";
4725 if (argc > 2 && argc != 5)
4727 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4728 "without arguments prints the default values" << std::endl;
4733 Handle(AIS_InteractiveObject) anInterObj;
4736 TCollection_AsciiString aName (argv[1]);
4737 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4738 if (!aMap.IsBound2 (aName))
4740 std::cout << "Use 'vdisplay' before" << std::endl;
4744 // find interactive object
4745 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4746 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4747 if (anInterObj.IsNull())
4749 std::cout << "Not an AIS interactive object!" << std::endl;
4754 Standard_Integer aMode;
4755 Standard_ShortReal aFactor, aUnits;
4758 aMode = Draw::Atoi(argv[2]);
4759 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4760 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4762 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4763 aContext->UpdateCurrentViewer();
4768 if (anInterObj->HasPolygonOffsets())
4770 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4771 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4772 std::cout << "\tMode: " << aMode << std::endl;
4773 std::cout << "\tFactor: " << aFactor << std::endl;
4774 std::cout << "\tUnits: " << aUnits << std::endl;
4779 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4783 std::cout << "Default polygon offset parameters:" << std::endl;
4784 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4785 std::cout << "\tMode: " << aMode << std::endl;
4786 std::cout << "\tFactor: " << aFactor << std::endl;
4787 std::cout << "\tUnits: " << aUnits << std::endl;
4792 //=======================================================================
4793 //function : VShowFaceBoundaries
4794 //purpose : Set face boundaries drawing on/off for ais object
4795 //=======================================================================
4796 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4797 Standard_Integer argc,
4800 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4801 if (aContext.IsNull ())
4803 std::cout << argv[0] << " Call 'vinit' before!\n";
4807 if ((argc != 3 && argc < 6) || argc > 8)
4809 std::cout << "Usage :\n " << argv[0]
4810 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4811 << " ObjectName - name of AIS interactive object. \n"
4812 << " if ObjectName = \"\", then set as default\n"
4813 << " settings for all newly displayed objects\n"
4814 << " isOn - flag indicating whether the boundaries\n"
4815 << " should be turned on or off (can be set\n"
4816 << " to 0 (off) or 1 (on)).\n"
4817 << " R, G, B - red, green and blue components of boundary\n"
4818 << " color in range (0 - 255).\n"
4819 << " (default is (0, 0, 0)\n"
4820 << " LineWidth - line width\n"
4821 << " (default is 1)\n"
4822 << " LineStyle - line fill style :\n"
4827 << " (default is solid)";
4831 TCollection_AsciiString aName (argv[1]);
4833 Quantity_Parameter aRed = 0.0;
4834 Quantity_Parameter aGreen = 0.0;
4835 Quantity_Parameter aBlue = 0.0;
4836 Standard_Real aWidth = 1.0;
4837 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4840 Handle(AIS_InteractiveObject) anInterObj;
4842 // if name is empty - apply attributes for default aspect
4843 if (!aName.IsEmpty ())
4845 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4846 if (!aMap.IsBound2 (aName))
4848 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4852 // find interactive object
4853 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4854 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4855 if (anInterObj.IsNull ())
4857 std::cout << "Not an AIS interactive object!" << std::endl;
4862 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4863 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4865 // turn boundaries on/off
4866 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
4867 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4869 // set boundary line color
4873 aRed = Draw::Atof (argv[3])/255.;
4874 aGreen = Draw::Atof (argv[4])/255.;
4875 aBlue = Draw::Atof (argv[5])/255.;
4881 aWidth = (Standard_Real)Draw::Atof (argv[6]);
4884 // select appropriate line type
4887 switch (Draw::Atoi (argv[7]))
4889 case 1: aLineType = Aspect_TOL_DASH; break;
4890 case 2: aLineType = Aspect_TOL_DOT; break;
4891 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4893 aLineType = Aspect_TOL_SOLID;
4897 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4899 Handle(Prs3d_LineAspect) aBoundaryAspect =
4900 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4902 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4904 TheAISContext()->Redisplay (anInterObj);
4909 // This class is used for testing markers.
4910 DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4911 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4916 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4917 const Standard_Integer& thePointsOnSide,
4918 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4920 myStartPoint = theStartPoint;
4921 myPointsOnSide = thePointsOnSide;
4922 myMarkerAspect = theMarkerAspect;
4925 DEFINE_STANDARD_RTTI(MyPArrayObject);
4929 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4930 const Handle(Prs3d_Presentation)& aPresentation,
4931 const Standard_Integer aMode);
4933 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4934 const Standard_Integer /*theMode*/);
4938 gp_XYZ myStartPoint;
4939 Standard_Integer myPointsOnSide;
4940 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4943 IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4944 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4946 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4947 const Handle(Prs3d_Presentation)& aPresentation,
4948 const Standard_Integer /*aMode*/)
4950 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4951 if (myPointsOnSide == 1)
4953 anArray->AddVertex (myStartPoint);
4957 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4959 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4961 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4963 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4964 anArray->SetVertexColor (anArray->VertexNumber(),
4967 k / myPointsOnSide);
4973 aPresentation->Clear();
4974 if (!myMarkerAspect.IsNull())
4976 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4978 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4981 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4982 const Standard_Integer /*theMode*/)
4984 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4986 if (myPointsOnSide == 1)
4988 gp_Pnt aPoint (myStartPoint);
4989 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4990 theSelection->Add (aSensetivePoint);
4994 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4996 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4998 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5000 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5001 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5002 theSelection->Add (aSensetivePoint);
5008 //=======================================================================
5009 //function : VMarkersTest
5010 //purpose : Draws an array of markers for testing purposes.
5011 //=======================================================================
5012 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5013 Standard_Integer theArgNb,
5014 const char** theArgVec)
5016 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5017 if (aContext.IsNull())
5019 std::cerr << "Call 'vinit' before!\n";
5025 std::cerr << "Usage :\n " << theArgVec[0]
5026 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5030 Standard_Integer anArgIter = 1;
5032 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5033 TCollection_AsciiString aFileName;
5034 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5035 Atof (theArgVec[anArgIter + 1]),
5036 Atof (theArgVec[anArgIter + 2]));
5039 Standard_Integer aPointsOnSide = 10;
5040 Standard_Integer aMarkerType = -1;
5041 Standard_Real aScale = 1.0;
5042 for (; anArgIter < theArgNb; ++anArgIter)
5044 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5045 if (anArg.Search ("PointsOnSide=") > -1)
5047 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5049 else if (anArg.Search ("MarkerType=") > -1)
5051 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5053 else if (anArg.Search ("Scale=") > -1)
5055 aScale = anArg.Token ("=", 2).RealValue();
5057 else if (anArg.Search ("FileName=") > -1)
5059 aFileName = anArg.Token ("=", 2);
5063 std::cerr << "Wrong argument: " << anArg << "\n";
5068 Handle(Graphic3d_AspectMarker3d) anAspect;
5069 Handle(Image_AlienPixMap) anImage;
5070 Quantity_Color aColor (Quantity_NOC_GREEN1);
5071 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5072 && !aFileName.IsEmpty())
5074 anImage = new Image_AlienPixMap();
5075 if (!anImage->Load (aFileName))
5077 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5080 if (anImage->Format() == Image_PixMap::ImgGray)
5082 anImage->SetFormat (Image_PixMap::ImgAlpha);
5084 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5086 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5088 anAspect = new Graphic3d_AspectMarker3d (anImage);
5092 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5095 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5096 VDisplayAISObject (aName, aMarkersArray);
5101 //! Auxiliary function to parse font aspect style argument
5102 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5103 Font_FontAspect& theAspect)
5105 if (theArg == "regular"
5106 || *theArg.ToCString() == 'r')
5108 theAspect = Font_FA_Regular;
5109 return Standard_True;
5111 else if (theArg == "bolditalic")
5113 theAspect = Font_FA_BoldItalic;
5114 return Standard_True;
5116 else if (theArg == "bold"
5117 || *theArg.ToCString() == 'b')
5119 theAspect = Font_FA_Bold;
5120 return Standard_True;
5122 else if (theArg == "italic"
5123 || *theArg.ToCString() == 'i')
5125 theAspect = Font_FA_Italic;
5126 return Standard_True;
5128 return Standard_False;
5131 //! Auxiliary function
5132 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5136 case Font_FA_Regular: return "regular";
5137 case Font_FA_BoldItalic: return "bolditalic";
5138 case Font_FA_Bold: return "bold";
5139 case Font_FA_Italic: return "italic";
5140 default: return "undefined";
5144 //=======================================================================
5145 //function : TextToBrep
5146 //purpose : Tool for conversion text to occt-shapes
5147 //=======================================================================
5149 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5150 Standard_Integer theArgNb,
5151 const char** theArgVec)
5156 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5160 Standard_Integer anArgIter = 1;
5161 Standard_CString aResName = theArgVec[anArgIter++];
5162 Standard_CString aText = theArgVec[anArgIter++];
5163 Standard_CString aFontName = theArgVec[anArgIter++];
5164 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
5166 Font_BRepFont aFont;
5167 Font_FontAspect aFontAspect = Font_FA_Regular;
5168 Standard_Boolean isCompositeCurve = Standard_False;
5169 gp_Ax3 aPenAx3 (gp::XOY());
5171 while (anArgIter < theArgNb)
5173 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
5174 TCollection_AsciiString anArgCase (anArg);
5175 anArgCase.LowerCase();
5176 if (anArgCase.Search ("x=") > -1)
5178 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
5180 else if (anArgCase.Search ("y=") > -1)
5182 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
5184 else if (anArgCase.Search ("z=") > -1)
5186 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
5188 else if (anArgCase.Search ("composite=") > -1)
5190 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
5192 else if (parseFontStyle (anArgCase, aFontAspect))
5198 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5202 aFont.SetCompositeCurveMode (isCompositeCurve);
5203 if (!aFont.Init (aFontName, aFontAspect, aSize))
5205 std::cerr << "Font initialization error\n";
5209 aPenAx3.SetLocation (aPenLoc);
5210 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
5214 //=======================================================================
5216 //purpose : Font management
5217 //=======================================================================
5219 static int VFont (Draw_Interpretor& theDI,
5220 Standard_Integer theArgNb,
5221 const char** theArgVec)
5223 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5226 // just print the list of available fonts
5227 Standard_Boolean isFirst = Standard_True;
5228 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5229 anIter.More(); anIter.Next())
5231 const Handle(Font_SystemFont)& aFont = anIter.Value();
5237 theDI << aFont->FontName()->String()
5238 << " " << fontStyleString (aFont->FontAspect())
5239 << " " << aFont->FontPath()->String();
5240 isFirst = Standard_False;
5245 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5247 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5248 TCollection_AsciiString anArgCase (anArg);
5249 anArgCase.LowerCase();
5250 if (anArgCase == "find")
5252 if (++anArgIter >= theArgNb)
5254 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5258 Standard_CString aFontName = theArgVec[anArgIter];
5259 Font_FontAspect aFontAspect = Font_FA_Undefined;
5260 if (++anArgIter < theArgNb)
5262 anArgCase = theArgVec[anArgIter];
5263 anArgCase.LowerCase();
5264 if (!parseFontStyle (anArgCase, aFontAspect))
5269 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5272 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5276 theDI << aFont->FontName()->String()
5277 << " " << fontStyleString (aFont->FontAspect())
5278 << " " << aFont->FontPath()->String();
5280 else if (anArgCase == "add"
5281 || anArgCase == "register")
5283 if (++anArgIter >= theArgNb)
5285 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5288 Standard_CString aFontPath = theArgVec[anArgIter];
5289 Standard_CString aFontName = NULL;
5290 Font_FontAspect aFontAspect = Font_FA_Undefined;
5291 if (++anArgIter < theArgNb)
5293 if (!parseFontStyle (anArgCase, aFontAspect))
5295 aFontName = theArgVec[anArgIter];
5297 if (++anArgIter < theArgNb)
5299 anArgCase = theArgVec[anArgIter];
5300 anArgCase.LowerCase();
5301 if (!parseFontStyle (anArgCase, aFontAspect))
5308 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5311 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5315 if (aFontAspect != Font_FA_Undefined
5316 || aFontName != NULL)
5318 if (aFontAspect == Font_FA_Undefined)
5320 aFontAspect = aFont->FontAspect();
5322 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5323 if (aFontName != NULL)
5325 aName = new TCollection_HAsciiString (aFontName);
5327 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5330 aMgr->RegisterFont (aFont, Standard_True);
5331 theDI << aFont->FontName()->String()
5332 << " " << fontStyleString (aFont->FontAspect())
5333 << " " << aFont->FontPath()->String();
5337 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5344 //=======================================================================
5345 //function : VSetEdgeType
5346 //purpose : Edges type management
5347 //=======================================================================
5349 static int VSetEdgeType (Draw_Interpretor& theDI,
5350 Standard_Integer theArgNum,
5351 const char** theArgs)
5353 if (theArgNum < 4 || theArgNum > 9)
5355 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5356 << theArgs[0] << "' for more information.\n";
5360 Standard_Boolean isForceRedisplay = Standard_False;
5363 TCollection_AsciiString aName(theArgs[1]);
5364 if (!GetMapOfAIS().IsBound2 (aName))
5366 theDI << theArgs[0] << " error: wrong object name.\n";
5370 Handle(AIS_InteractiveObject) anObject =
5371 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5373 // Enable trianle edge mode
5374 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5377 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5379 TCollection_AsciiString aParam ((theArgs[anIt]));
5380 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5382 if (aParam.IsEqual ("-type"))
5384 if (theArgNum <= anIt + 1)
5386 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5387 << aParam.ToCString() << "'.\n";
5391 TCollection_AsciiString aType = theArgs[++anIt];
5394 if (aType.IsEqual ("SOLID"))
5396 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5398 else if (aType.IsEqual ("DASH"))
5400 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5402 else if (aType.IsEqual ("DOT"))
5404 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5406 else if (aType.IsEqual ("DOTDASH"))
5408 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5412 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5417 else if (aParam.IsEqual ("-color"))
5419 if (theArgNum <= anIt + 3)
5421 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5422 << aParam.ToCString() << "'.\n";
5426 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5427 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5428 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5429 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5430 aG > 1 ? aG / 255.0 : aG,
5431 aB > 1 ? aB / 255.0 : aB,
5434 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5436 else if (aParam.IsEqual ("-force"))
5438 isForceRedisplay = Standard_True;
5442 theDI << theArgs[0] << " error: unknown parameter '"
5443 << aParam.ToCString() << "'.\n";
5449 // Update shape presentation as aspect parameters were changed
5450 if (isForceRedisplay)
5452 ViewerTest::GetAISContext()->Redisplay (anObject);
5456 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5460 ViewerTest::CurrentView()->Redraw();
5465 //=======================================================================
5466 //function : VUnsetEdgeType
5467 //purpose : Unsets edges visibility in shading mode
5468 //=======================================================================
5470 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5471 Standard_Integer theArgNum,
5472 const char** theArgs)
5474 if (theArgNum != 2 && theArgNum != 3)
5476 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5477 << theArgs[0] << "' for more information.\n";
5481 Standard_Boolean isForceRedisplay = Standard_False;
5484 TCollection_AsciiString aName (theArgs[1]);
5485 if (!GetMapOfAIS().IsBound2 (aName))
5487 theDI << theArgs[0] << " error: wrong object name.\n";
5491 Handle(AIS_InteractiveObject) anObject =
5492 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5494 // Enable trianle edge mode
5495 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5500 TCollection_AsciiString aParam ((theArgs[2]));
5501 if (aParam.IsEqual ("-force"))
5503 isForceRedisplay = Standard_True;
5507 theDI << theArgs[0] << " error: unknown parameter '"
5508 << aParam.ToCString() << "'.\n";
5513 // Update shape presentation as aspect parameters were changed
5514 if (isForceRedisplay)
5516 ViewerTest::GetAISContext()->Redisplay (anObject);
5520 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5524 ViewerTest::CurrentView()->Redraw();
5530 //=======================================================================
5531 //function : VVertexMode
5532 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5533 //=======================================================================
5535 static int VVertexMode (Draw_Interpretor& theDI,
5536 Standard_Integer theArgNum,
5537 const char** theArgs)
5539 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5540 if (aContext.IsNull())
5542 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5546 // No arguments --> print the current default vertex draw mode
5549 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5550 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5554 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5555 TCollection_AsciiString aParam (theArgs[1]);
5556 if (aParam == "-set")
5560 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5561 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5565 TCollection_AsciiString aModeStr (theArgs[2]);
5566 Prs3d_VertexDrawMode aNewMode =
5567 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5568 (aModeStr == "all" ? Prs3d_VDM_All :
5569 Prs3d_VDM_Inherited);
5571 Standard_Boolean aRedrawNeeded = Standard_False;
5572 AIS_ListOfInteractive anObjs;
5574 // No object(s) specified -> use all displayed
5577 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5578 aContext->DisplayedObjects (anObjs);
5579 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5580 aRedrawNeeded = Standard_True;
5583 Handle(AIS_InteractiveObject) anObject;
5584 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5586 TCollection_AsciiString aName (theArgs[aCount]);
5587 if (!GetMapOfAIS().IsBound2 (aName))
5589 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5592 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5593 anObjs.Append (anObject);
5596 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5598 anObject = anIt.Value();
5599 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5600 aContext->Redisplay (anObject, Standard_False);
5601 aRedrawNeeded = Standard_True;
5605 ViewerTest::CurrentView()->Redraw();
5612 std::cout << "Error: invalid number of arguments" << std::endl;
5613 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5617 // One argument (object name) --> print the current vertex draw mode for the object
5618 Handle(AIS_InteractiveObject) anObject =
5619 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5620 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5621 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5625 //=======================================================================
5626 //function : VPointCloud
5627 //purpose : Create interactive object for arbitary set of points.
5628 //=======================================================================
5629 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5630 Standard_Integer theArgNum,
5631 const char** theArgs)
5633 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5634 if (anAISContext.IsNull())
5636 std::cerr << "Error: no active view!\n";
5640 // command to execute
5643 CloudForShape, // generate point cloud for shape
5644 CloudSphere, // generate point cloud for generic sphere
5648 // count number of non-optional command arguments
5649 Command aCmd = Unknow;
5650 Standard_Integer aCmdArgs = 0;
5651 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5653 Standard_CString anArg = theArgs[anArgIter];
5654 TCollection_AsciiString aFlag (anArg);
5656 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5663 case 2 : aCmd = CloudForShape; break;
5664 case 7 : aCmd = CloudSphere; break;
5666 std::cout << "Error: wrong number of arguments! See usage:\n";
5667 theDI.PrintHelp (theArgs[0]);
5672 Standard_Boolean toRandColors = Standard_False;
5673 Standard_Boolean hasNormals = Standard_True;
5674 Standard_Boolean isSetArgNorm = Standard_False;
5675 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5677 Standard_CString anArg = theArgs[anArgIter];
5678 TCollection_AsciiString aFlag (anArg);
5680 if (aFlag == "-randcolors"
5681 || aFlag == "-randcolor")
5683 if (isSetArgNorm && hasNormals)
5685 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5688 toRandColors = Standard_True;
5689 hasNormals = Standard_False;
5691 else if (aFlag == "-normals"
5692 || aFlag == "-normal")
5696 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5699 isSetArgNorm = Standard_True;
5700 hasNormals = Standard_True;
5702 else if (aFlag == "-nonormals"
5703 || aFlag == "-nonormal")
5705 isSetArgNorm = Standard_True;
5706 hasNormals = Standard_False;
5710 Standard_CString aName = theArgs[1];
5712 // generate arbitrary set of points
5713 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5714 if (aCmd == CloudForShape)
5716 Standard_CString aShapeName = theArgs[2];
5717 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5719 if (aShape.IsNull())
5721 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5725 // calculate number of points
5726 TopLoc_Location aLocation;
5727 Standard_Integer aNbPoints = 0;
5728 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5730 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5731 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5732 if (!aTriangulation.IsNull())
5734 aNbPoints += aTriangulation->NbNodes();
5739 std::cout << "Error: shape should be triangulated!\n";
5743 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5744 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5746 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5747 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5748 if (aTriangulation.IsNull())
5753 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5754 const gp_Trsf& aTrsf = aLocation.Transformation();
5756 // extract normals from nodes
5757 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5760 Poly_Connect aPolyConnect (aTriangulation);
5761 StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
5764 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5766 gp_Pnt aPoint = aNodes (aNodeIter);
5767 if (!aLocation.IsIdentity())
5769 aPoint.Transform (aTrsf);
5772 aNormals (aNodeIter).Transform (aTrsf);
5776 // add vertex into array of points
5777 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5780 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5781 1.0, 0.5, Quantity_TOC_HLS);
5782 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5787 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5792 else if (aCmd == CloudSphere)
5794 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5795 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5796 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5797 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5798 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5800 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5801 aDistribution.LowerCase();
5802 if ( aDistribution != "surface" && aDistribution != "volume" )
5804 std::cout << "Error: wrong arguments! See usage:\n";
5805 theDI.PrintHelp (theArgs[0]);
5808 Standard_Boolean isSurface = aDistribution == "surface";
5810 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5812 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5813 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5815 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5816 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5817 Standard_Real aDistance = isSurface ?
5818 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5820 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5822 Cos (anAlpha) * Cos (aBeta));
5823 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5825 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5828 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5829 1.0, 0.5, Quantity_TOC_HLS);
5830 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5835 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5840 // set array of points in point cloud object
5841 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5842 aPointCloud->SetPoints (anArrayPoints);
5843 VDisplayAISObject (aName, aPointCloud);
5847 //=======================================================================
5848 //function : VPriority
5849 //purpose : Prints or sets the display priority for an object
5850 //=======================================================================
5852 static int VPriority (Draw_Interpretor& theDI,
5853 Standard_Integer theArgNum,
5854 const char** theArgs)
5856 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5857 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5858 if (aContext.IsNull())
5860 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5864 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5865 Standard_Integer aPriority = -1;
5866 Standard_Integer aNbArgs = theArgNum;
5867 if (aLastArg.IsIntegerValue())
5869 aPriority = aLastArg.IntegerValue();
5871 if (aPriority < 0 || aPriority > 10)
5873 std::cout << "Error: the specified display priority value '" << aLastArg
5874 << "' is outside the valid range [0..10]" << std::endl;
5880 anUpdateTool.Invalidate();
5885 std::cout << "Error: wrong number of arguments! See usage:\n";
5886 theDI.PrintHelp (theArgs[0]);
5890 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5892 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5897 TCollection_AsciiString aName (theArgs[anArgIter]);
5898 Handle(AIS_InteractiveObject) anIObj;
5899 if (GetMapOfAIS().IsBound2 (aName))
5901 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5904 if (anIObj.IsNull())
5906 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5912 theDI << aContext->DisplayPriority (anIObj) << " ";
5916 aContext->SetDisplayPriority (anIObj, aPriority);
5922 //=======================================================================
5923 //function : ObjectsCommands
5925 //=======================================================================
5927 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
5929 const char *group ="AISObjects";
5930 theCommands.Add("vtrihedron",
5931 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
5932 __FILE__,VTrihedron,group);
5934 theCommands.Add("vtri2d",
5935 "vtri2d Name Selection in the viewer only ",
5936 __FILE__,VTrihedron2D ,group);
5938 theCommands.Add("vplanetri",
5939 "vplanetri Name Selection in the viewer only ",
5940 __FILE__,VPlaneTrihedron ,group);
5942 theCommands.Add("vsize",
5943 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
5944 __FILE__,VSize,group);
5946 theCommands.Add("vaxis",
5947 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
5948 __FILE__,VAxisBuilder,group);
5950 theCommands.Add("vaxispara",
5952 __FILE__,VAxisBuilder,group);
5954 theCommands.Add("vaxisortho",
5956 __FILE__,VAxisBuilder,group);
5958 theCommands.Add("vpoint",
5959 "vpoint PointName [Xa] [Ya] [Za] ",
5960 __FILE__,VPointBuilder,group);
5962 theCommands.Add("vplane",
5963 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
5964 __FILE__,VPlaneBuilder,group);
5966 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
5967 " vchangeplane <plane_name>"
5968 " [x=center_x y=center_y z=center_z]"
5969 " [dx=dir_x dy=dir_y dz=dir_z]"
5970 " [sx=size_x sy=size_y]"
5972 " - changes parameters of the plane:\n"
5973 " - x y z - center\n"
5974 " - dx dy dz - normal\n"
5975 " - sx sy - plane sizes\n"
5976 " - noupdate - do not update/redisplay the plane in context\n"
5977 " Please enter coordinates in format \"param=value\" in arbitrary order.",
5978 __FILE__, VChangePlane, group);
5980 theCommands.Add("vplanepara",
5981 "vplanepara PlaneName ",
5982 __FILE__,VPlaneBuilder,group);
5984 theCommands.Add("vplaneortho",
5985 "vplaneortho PlaneName ",
5986 __FILE__,VPlaneBuilder,group);
5988 theCommands.Add("vline",
5989 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
5990 __FILE__,VLineBuilder,group);
5992 theCommands.Add("vcircle",
5993 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
5994 __FILE__,VCircleBuilder,group);
5996 theCommands.Add ("vdrawtext",
5997 "vdrawtext name text"
5998 "\n\t\t: [-pos X=0 Y=0 Z=0]"
5999 "\n\t\t: [-color {R G B|name}=yellow]"
6000 "\n\t\t: [-halign {left|center|right}=left]"
6001 "\n\t\t: [-valign {top|center|bottom}=bottom}]"
6002 "\n\t\t: [-angle angle=0]"
6003 "\n\t\t: [-zoom {0|1}=0]"
6004 "\n\t\t: [-height height=16]"
6005 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6006 "\n\t\t: [-font font=Times]"
6007 "\n\t\t: [-noupdate]"
6008 "\n\t\t: Display text label at specified position.",
6009 __FILE__, VDrawText, group);
6011 theCommands.Add("vdrawsphere",
6012 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6013 __FILE__,VDrawSphere,group);
6015 theCommands.Add ("vsetlocation",
6016 "vsetlocation [-noupdate|-update] name x y z"
6017 "\n\t\t: Set new location for an interactive object.",
6018 __FILE__, VSetLocation, group);
6022 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6023 __FILE__, VComputeHLR, group);
6025 theCommands.Add("vdrawparray",
6026 "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 ]",
6027 __FILE__,VDrawPArray,group);
6029 theCommands.Add("vconnect",
6030 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
6031 " Makes an assembly of object instances located in point (Xo Yo Zo).",
6032 __FILE__, VConnect, group);
6034 theCommands.Add("vconnectto",
6035 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6036 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6037 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6038 __FILE__, VConnectTo,group);
6040 theCommands.Add("vdisconnect",
6041 "vdisconnect assembly_name (object_name | object_number | 'all')"
6042 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6043 __FILE__,VDisconnect,group);
6045 theCommands.Add("vaddconnected",
6046 "vaddconnected assembly_name object_name"
6047 "Adds object to assembly.",
6048 __FILE__,VAddConnected,group);
6050 theCommands.Add("vlistconnected",
6051 "vlistconnected assembly_name"
6052 "Lists objects in assembly.",
6053 __FILE__,VListConnected,group);
6056 theCommands.Add("vselmode",
6057 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6058 " switches selection mode for the determined object or\n"
6059 " for all objects in context.\n"
6060 " mode_number is non-negative integer that has different\n"
6061 " meaning for different interactive object classes.\n"
6062 " For shapes the following mode_number values are allowed:\n"
6072 " is_turned_on is:\n"
6073 " 1 if mode is to be switched on\n"
6074 " 0 if mode is to be switched off\n",
6075 __FILE__, VSetSelectionMode, group);
6077 theCommands.Add("vselnext",
6078 "vselnext : hilight next detected",
6079 __FILE__, VSelectionNext, group);
6081 theCommands.Add("vselprev",
6082 "vselnext : hilight previous detected",
6083 __FILE__, VSelectionPrevious, group);
6085 theCommands.Add("vtriangle",
6086 "vtriangle Name PointName PointName PointName",
6087 __FILE__, VTriangle,group);
6089 theCommands.Add("vsegment",
6090 "vsegment Name PointName PointName",
6091 __FILE__, VSegment,group);
6093 theCommands.Add("vobjzlayer",
6094 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6095 __FILE__, VObjZLayer, group);
6097 theCommands.Add("vpolygonoffset",
6098 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6099 __FILE__, VPolygonOffset, group);
6101 theCommands.Add ("vshowfaceboundary",
6102 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6103 "- turns on/off drawing of face boundaries for ais object "
6104 "and defines boundary line style.",
6105 __FILE__, VShowFaceBoundary, group);
6107 theCommands.Add ("vmarkerstest",
6108 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6109 __FILE__, VMarkersTest, group);
6111 theCommands.Add ("text2brep",
6112 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
6113 __FILE__, TextToBRep, group);
6114 theCommands.Add ("vfont",
6115 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6116 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6117 __FILE__, VFont, group);
6119 theCommands.Add ("vsetedgetype",
6120 "vsetedgetype usage:\n"
6121 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6122 "\n\t\t: Sets edges type and color for input shape",
6123 __FILE__, VSetEdgeType, group);
6125 theCommands.Add ("vunsetedgetype",
6126 "vunsetedgetype usage:\n"
6127 "vunsetedgetype ShapeName [-force]"
6128 "\n\t\t: Unsets edges type and color for input shape",
6129 __FILE__, VUnsetEdgeType, group);
6131 theCommands.Add ("vvertexmode",
6132 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6133 "vvertexmode - prints the default vertex draw mode\n"
6134 "vvertexmode name - prints the vertex draw mode of the given object\n"
6135 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6136 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6137 __FILE__, VVertexMode, group);
6139 theCommands.Add ("vpointcloud",
6140 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6141 "\n\t\t: Create an interactive object for arbitary set of points"
6142 "\n\t\t: from triangulated shape."
6144 "vpointcloud name x y z r npts {surface|volume}\n"
6145 " ... [-randColor] [-normals] [-noNormals]"
6146 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6147 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6149 "\n\t\t: Additional options:"
6150 "\n\t\t: -randColor - generate random color per point"
6151 "\n\t\t: -normals - generate normal per point (default)"
6152 "\n\t\t: -noNormals - do not generate normal per point"
6154 __FILE__, VPointCloud, group);
6156 theCommands.Add("vlocreset",
6157 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6159 LocalTransformPresentation, group);
6161 theCommands.Add("vlocmove",
6162 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6164 LocalTransformPresentation, group);
6166 theCommands.Add("vloctranslate",
6167 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6169 LocalTransformPresentation, group);
6171 theCommands.Add("vlocrotate",
6172 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6174 LocalTransformPresentation, group);
6176 theCommands.Add("vlocmirror",
6177 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6179 LocalTransformPresentation, group);
6181 theCommands.Add("vlocscale",
6182 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6184 LocalTransformPresentation, group);
6186 theCommands.Add("vpriority",
6187 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",