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_BRepTextBuilder.hxx>
27 #include <Font_FontMgr.hxx>
28 #include <OSD_Chronometer.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_DisplayMode.hxx>
36 #include <AIS_PointCloud.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_AutoUpdater.hxx>
40 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_EventManager.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Builder.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Face.hxx>
62 #include <Draw_Window.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_DisplayMode.hxx>
66 #include <AIS_Shape.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <Geom_Plane.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <TCollection_HAsciiString.hxx>
73 #include <GC_MakePlane.hxx>
74 #include <gp_Circ.hxx>
75 #include <AIS_Axis.hxx>
76 #include <Geom_Axis2Placement.hxx>
77 #include <Geom_Axis1Placement.hxx>
78 #include <AIS_Trihedron.hxx>
79 #include <AIS_Axis.hxx>
80 #include <gp_Trsf.hxx>
81 #include <TopLoc_Location.hxx>
83 #include <HLRAlgo_Projector.hxx>
84 #include <HLRBRep_PolyAlgo.hxx>
85 #include <HLRBRep_PolyHLRToShape.hxx>
86 #include <Aspect_Window.hxx>
88 #include <Graphic3d_ArrayOfPoints.hxx>
89 #include <Graphic3d_ArrayOfSegments.hxx>
90 #include <Graphic3d_ArrayOfPolylines.hxx>
91 #include <Graphic3d_ArrayOfTriangles.hxx>
92 #include <Graphic3d_ArrayOfTriangleFans.hxx>
93 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
94 #include <Graphic3d_ArrayOfQuadrangles.hxx>
95 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
96 #include <Graphic3d_ArrayOfPolygons.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_Group.hxx>
99 #include <Standard_Real.hxx>
101 #include <AIS_Circle.hxx>
102 #include <BRepBuilderAPI_MakeEdge.hxx>
103 #include <BRepBuilderAPI_MakeFace.hxx>
104 #include <BRepBuilderAPI_MakeWire.hxx>
105 #include <Geom_Circle.hxx>
106 #include <GC_MakeCircle.hxx>
107 #include <Prs3d_Presentation.hxx>
108 #include <Select3D_SensitiveCircle.hxx>
109 #include <SelectMgr_EntityOwner.hxx>
110 #include <SelectMgr_Selection.hxx>
111 #include <StdFail_NotDone.hxx>
112 #include <StdPrs_ShadedShape.hxx>
113 #include <TopoDS_Wire.hxx>
115 #include <AIS_MultipleConnectedInteractive.hxx>
116 #include <AIS_ConnectedInteractive.hxx>
117 #include <AIS_TextLabel.hxx>
118 #include <TopLoc_Location.hxx>
119 #include <TColStd_ListOfInteger.hxx>
120 #include <TColStd_ListIteratorOfListOfInteger.hxx>
122 #include <Select3D_SensitiveTriangle.hxx>
123 #include <Select3D_SensitiveCurve.hxx>
124 #include <Select3D_SensitivePoint.hxx>
125 #include <BRepAdaptor_Curve.hxx>
126 #include <StdPrs_Curve.hxx>
128 #include <BRepExtrema_ExtPC.hxx>
129 #include <BRepExtrema_ExtPF.hxx>
131 #include <Prs3d_Drawer.hxx>
132 #include <Prs3d_VertexDrawMode.hxx>
133 #include <Prs3d_LineAspect.hxx>
134 #include <Prs3d_PointAspect.hxx>
135 #include <Prs3d_TextAspect.hxx>
137 #include <Image_AlienPixMap.hxx>
138 #include <TColStd_HArray1OfAsciiString.hxx>
141 # define _CRT_SECURE_NO_DEPRECATE
142 # pragma warning (disable:4996)
145 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
146 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
147 const Handle(AIS_InteractiveObject)& theAISObj,
148 Standard_Boolean theReplaceIfExists = Standard_True);
149 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
150 extern Handle(AIS_InteractiveContext)& TheAISContext();
153 //==============================================================================
154 //function : Vtrihedron 2d
155 //purpose : Create a plane with a 2D trihedron from a faceselection
156 //Draw arg : vtri2d name
157 //==============================================================================
158 #include <AIS_PlaneTrihedron.hxx>
162 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
165 // Verification des arguments
166 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
169 Standard_Integer myCurrentIndex;
170 // Fermeture des contextes
171 TheAISContext()->CloseAllContexts();
172 // Ouverture d'un contexte local et recuperation de son index.
173 TheAISContext()->OpenLocalContext();
174 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
175 // On active les modes de selections faces.
176 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
177 di<<" Select a face ."<<"\n";
179 // Boucle d'attente waitpick.
180 Standard_Integer argccc = 5;
181 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
182 const char **argvvv = (const char **) bufff;
183 while (ViewerMainLoop( argccc, argvvv) ) { }
187 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
188 ShapeB = TheAISContext()->SelectedShape();
191 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
193 // Construction du Plane
194 // recuperation des edges des faces.
195 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
197 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
201 // si il y a plusieurs edges
202 if (FaceExpB.More() ) {
204 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
205 BRepAdaptor_Curve theCurveB(EdgeB);
206 BRepAdaptor_Curve theCurveC(EdgeC);
207 A=theCurveC.Value(0.1);
208 B=theCurveC.Value(0.9);
209 C=theCurveB.Value(0.5);
212 // FaceB a 1 unique edge courbe
213 BRepAdaptor_Curve theCurveB(EdgeB);
214 A=theCurveB.Value(0.1);
215 B=theCurveB.Value(0.9);
216 C=theCurveB.Value(0.5);
218 // Construction du Geom_Plane
219 GC_MakePlane MkPlane(A,B,C);
220 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
222 // Construction de l'AIS_PlaneTrihedron
223 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
225 // Fermeture du contexte local.
226 TheAISContext()->CloseLocalContext(myCurrentIndex);
228 // on le display & bind
229 TheAISContext()->Display(theAISPlaneTri );
230 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
237 //==============================================================================
238 //function : VTriherdron
239 //purpose : Create a trihedron. If no arguments are set, the default
240 // trihedron (Oxyz) is created.
241 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
242 //==============================================================================
244 static int VTrihedron (Draw_Interpretor& theDi,
245 Standard_Integer theArgsNb,
246 const char** theArgVec)
248 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
250 theDi << theArgVec[0] << " Syntax error\n";
254 gp_Pnt anOrigin (0.0, 0.0, 0.0);
255 gp_Dir aDirZ = gp::DZ();
256 gp_Dir aDirX = gp::DX();
257 Standard_Integer anArgIter = 2; // 1st is an IO name
258 if (anArgIter < theArgsNb)
260 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
261 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
262 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
263 if (anArgIter < theArgsNb)
265 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
266 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
267 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
268 aDirZ.SetCoord (aX, aY, aZ);
270 aX = Draw::Atof (theArgVec[anArgIter++]);
271 aY = Draw::Atof (theArgVec[anArgIter++]);
272 aZ = Draw::Atof (theArgVec[anArgIter++]);
273 aDirX.SetCoord (aX, aY, aZ);
277 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
279 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
283 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
284 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
285 VDisplayAISObject (theArgVec[1], aShape);
289 //==============================================================================
292 //purpose : Change the size of a named or selected trihedron
293 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
294 // if no value, the value is set at 100 by default
295 //Draw arg : vsize [name] [size]
296 //==============================================================================
298 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
301 // Declaration de booleens
302 Standard_Boolean ThereIsName;
303 Standard_Boolean ThereIsCurrent;
305 Standard_Boolean hascol;
307 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
309 // Verification des arguments
310 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
312 // Verification du nombre d'arguments
313 if (argc==1) {ThereIsName=Standard_False;value=100;}
314 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
315 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
317 // On ferme le contexte local pour travailler dans le contexte global
318 if(TheAISContext()->HasOpenedContext())
319 TheAISContext()->CloseLocalContext();
321 // On set le booleen ThereIsCurrent
322 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
323 else {ThereIsCurrent=Standard_False;}
327 //===============================================================
328 // Il n'y a pas de nom mais des objets selectionnes
329 //===============================================================
330 if (!ThereIsName && ThereIsCurrent)
333 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
336 while ( it.More() ) {
338 Handle(AIS_InteractiveObject) aShape=
339 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
341 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
344 // On verifie que l'AIS InteraciveObject selectionne est bien
346 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
348 if (aShape->HasColor()) {
349 hascol=Standard_True;
351 // On recupere la couleur de aShape
352 col=aShape->Color();}
354 else hascol=Standard_False;
356 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
357 // pour lui appliquer la methode SetSize()
358 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
360 // C'est bien un triedre,on chage sa valeur!
361 aTrihedron->SetSize(value);
363 // On donne la couleur au Trihedron
364 if(hascol) aTrihedron->SetColor(col);
365 else aTrihedron->UnsetColor();
368 // The trihedron hasn't be errased from the map
369 // so you just have to redisplay it
370 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
379 TheAISContext() ->UpdateCurrentViewer();
382 //===============================================================
383 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
384 //===============================================================
388 //===============================================================
389 // Il y a un nom de triedre passe en argument
390 //===============================================================
392 TCollection_AsciiString name=argv[1];
394 // on verifie que ce nom correspond bien a une shape
395 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
399 // on recupere la shape dans la map des objets displayes
400 Handle(AIS_InteractiveObject) aShape =
401 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
403 // On verifie que l'AIS InteraciveObject est bien
405 if (!aShape.IsNull() &&
406 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
409 if (aShape->HasColor()) {
410 hascol=Standard_True;
412 // On recupere la couleur de aShape
413 col=aShape->Color();}
415 else hascol=Standard_False;
417 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
418 // pour lui appliquer la methode SetSize()
419 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
421 // C'est bien un triedre,on chage sa valeur
422 aTrihedron->SetSize(value);
424 // On donne la couleur au Trihedron
425 if(hascol) aTrihedron->SetColor(col);
426 else aTrihedron->UnsetColor();
428 // The trihedron hasn't be errased from the map
429 // so you just have to redisplay it
430 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
432 TheAISContext() ->UpdateCurrentViewer();
440 //==============================================================================
442 //==============================================================================
443 //function : VPlaneTrihedron
444 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
445 //Draw arg : vplanetri name
446 //==============================================================================
447 #include <AIS_Plane.hxx>
451 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
454 // Verification des arguments
455 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
458 Standard_Integer myCurrentIndex;
459 // Fermeture des contextes locaux
460 TheAISContext()->CloseAllContexts();
462 // On recupere tous les trihedrons de la GetMapOfAIS()
463 // et on active le mode de selection par face.
464 // =================================================
466 // Ouverture d'un contexte local et recuperation de son index.
467 TheAISContext()->OpenLocalContext(Standard_False);
468 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
470 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
473 Handle(AIS_InteractiveObject) ShapeA =
474 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
475 // On verifie que c'est bien un trihedron
476 if (!ShapeA.IsNull() &&
477 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
479 Handle(AIS_Trihedron) TrihedronA =(Handle(AIS_Trihedron)::DownCast (ShapeA));
480 // on le charge dans le contexte et on active le mode Plane.
481 TheAISContext()->Load(TrihedronA,0,Standard_False);
482 TheAISContext()->Activate(TrihedronA,3);
487 di<<" Select a plane."<<"\n";
488 // Boucle d'attente waitpick.
489 Standard_Integer argccc = 5;
490 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
491 const char **argvvv = (const char **) bufff;
492 while (ViewerMainLoop( argccc, argvvv) ) { }
495 Handle(AIS_InteractiveObject) theIOB;
496 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
497 theIOB = TheAISContext()->SelectedInteractive();
500 Handle(AIS_Plane) PlaneB =(Handle(AIS_Plane)::DownCast (theIOB));
502 // Fermeture du contexte local.
503 TheAISContext()->CloseLocalContext(myCurrentIndex);
505 // on le display & bind
506 TheAISContext()->Display(PlaneB );
507 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
514 //==============================================================================
515 // Fonction First click 2de click
517 // vaxis vertex vertex
519 // vaxispara edge vertex
520 // vaxisortho edge Vertex
521 // vaxisinter Face Face
522 //==============================================================================
524 //==============================================================================
525 //function : VAxisBuilder
527 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
528 //==============================================================================
529 #include <TopoDS_Edge.hxx>
530 #include <TopoDS_Vertex.hxx>
531 #include <TopExp.hxx>
532 #include <Geom_Line.hxx>
534 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
537 Standard_Boolean HasArg;
538 TCollection_AsciiString name;
539 Standard_Integer MyCurrentIndex;
542 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
543 if (argc==8) HasArg=Standard_True;
544 else HasArg=Standard_False;
547 // Fermeture des contextes
548 TheAISContext()->CloseAllContexts();
550 // Cas ou il y a des arguments
551 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
553 Standard_Real coord[6];
554 for(Standard_Integer i=0;i<=5;i++){
555 coord[i]=Draw::Atof(argv[2+i]);
557 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
559 gp_Vec myVect (p1,p2);
560 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
561 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
562 GetMapOfAIS().Bind (TheAxis,name);
563 TheAISContext()->Display(TheAxis);
569 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
570 if ( !strcasecmp(argv[0], "vaxis")) {
571 TheAISContext()->OpenLocalContext();
572 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
574 // Active le mode edge et le mode vertex
575 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
576 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
577 di<<" Select an edge or a vertex."<<"\n";
579 // Boucle d'attente waitpick.
580 Standard_Integer argcc = 5;
581 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
582 const char **argvv = (const char **) buff;
583 while (ViewerMainLoop( argcc, argvv) ) { }
586 // recuperation de la shape.
588 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
589 ShapeA = TheAISContext()->SelectedShape();
591 // recuperation de l'AIS_InteractiveObject
592 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
593 // down cast en AIS_Point si sig et type
594 // AIS_Point -> Geom_Pnt ....
596 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
597 // on desactive le mode edge
598 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
599 di<<" Select a different vertex."<<"\n";
603 // Boucle d'attente waitpick.
604 Standard_Integer argccc = 5;
605 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
606 const char **argvvv = (const char **) bufff;
607 while (ViewerMainLoop( argccc, argvvv) ) { }
609 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
610 ShapeB = TheAISContext()->SelectedShape();
614 } while(ShapeB.IsSame(ShapeA) );
616 // Fermeture du context local
617 TheAISContext()->CloseLocalContext(MyCurrentIndex);
619 // Construction de l'axe
620 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
621 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
624 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
625 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
626 GetMapOfAIS().Bind (TheAxis,name);
627 TheAISContext()->Display(TheAxis);
630 // Un unique edge (ShapeA) a ete picke
631 // Fermeture du context local
632 TheAISContext()->CloseLocalContext(MyCurrentIndex);
633 // Constuction de l'axe
634 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
636 TopExp::Vertices(ed,Va,Vb );
637 gp_Pnt A=BRep_Tool::Pnt(Va);
638 gp_Pnt B=BRep_Tool::Pnt(Vb);
641 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
642 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
643 GetMapOfAIS().Bind (TheAxis,name);
644 TheAISContext()->Display(TheAxis);
650 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
651 else if ( !strcasecmp(argv[0], "vaxispara")) {
653 TheAISContext()->OpenLocalContext();
654 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
656 // Active le mode edge
657 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
658 di<<" Select an edge."<<"\n";
660 // Boucle d'attente waitpick.
661 Standard_Integer argcc = 5;
662 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
663 const char **argvv = (const char **) buff;
664 while (ViewerMainLoop( argcc, argvv) ) { }
668 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
669 ShapeA = TheAISContext()->SelectedShape();
671 // Active le mode vertex et deactive edges
672 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
673 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
674 di<<" Select a vertex."<<"\n";
676 // Boucle d'attente waitpick.
677 Standard_Integer argccc = 5;
678 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
679 const char **argvvv = (const char **) bufff;
680 while (ViewerMainLoop( argccc, argvvv) ) { }
683 // On peut choisir un pnt sur l'edge
685 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
686 ShapeB = TheAISContext()->SelectedShape();
688 // Fermeture du context local
689 TheAISContext()->CloseLocalContext(MyCurrentIndex);
691 // Construction de l'axe
692 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
693 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
695 TopExp::Vertices(ed,Va,Vc );
696 gp_Pnt A=BRep_Tool::Pnt(Va);
697 gp_Pnt C=BRep_Tool::Pnt(Vc);
700 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
701 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
702 GetMapOfAIS().Bind (TheAxis,name);
703 TheAISContext()->Display(TheAxis);
707 // Fonction axisortho
709 TheAISContext()->OpenLocalContext();
710 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
712 // Active le mode edge
713 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
714 di<<" Select an edge."<<"\n";
716 // Boucle d'attente waitpick.
717 Standard_Integer argcc = 5;
718 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
719 const char **argvv = (const char **) buff;
720 while (ViewerMainLoop( argcc, argvv) ) { }
724 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
725 ShapeA = TheAISContext()->SelectedShape();
727 // Active le mode vertex et deactive edges
728 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
729 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
730 di<<" Slect a vertex."<<"\n";
732 // Boucle d'attente waitpick.
733 Standard_Integer argccc = 5;
734 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
735 const char **argvvv = (const char **) bufff;
736 while (ViewerMainLoop( argccc, argvvv) ) { }
739 // On peut choisir un pnt sur l'edge
741 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
742 ShapeB = TheAISContext()->SelectedShape();
744 // Fermeture du context local
745 TheAISContext()->CloseLocalContext(MyCurrentIndex);
747 // Construction de l'axe
748 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
749 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
751 TopExp::Vertices(ed,Va,Vc );
752 gp_Pnt A=BRep_Tool::Pnt(Va);
753 gp_Pnt C=BRep_Tool::Pnt(Vc);
754 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
757 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
758 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
759 GetMapOfAIS().Bind (TheAxis,name);
760 TheAISContext()->Display(TheAxis);
769 //==============================================================================
770 // Fonction First click Result
772 // vpoint vertex AIS_Point=Vertex
773 // edge AIS_Point=Middle of the edge
774 //==============================================================================
776 //==============================================================================
777 //function : VPointBuilder
778 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
779 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
780 //==============================================================================
781 #include <TopoDS_Edge.hxx>
782 #include <TopoDS_Vertex.hxx>
783 #include <TopExp.hxx>
784 #include <AIS_Point.hxx>
785 #include <Geom_CartesianPoint.hxx>
787 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
790 Standard_Boolean HasArg;
791 TCollection_AsciiString name;
792 Standard_Integer myCurrentIndex;
795 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
796 if (argc==5) HasArg=Standard_True;
797 else HasArg=Standard_False;
800 // Fermeture des contextes
801 TheAISContext()->CloseAllContexts();
803 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
805 Standard_Real thecoord[3];
806 for(Standard_Integer i=0;i<=2;i++)
807 thecoord[i]=Draw::Atof(argv[2+i]);
808 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
809 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
810 GetMapOfAIS().Bind (myAISPoint,name);
811 TheAISContext()->Display(myAISPoint);
814 // Il n'a pas d'arguments
816 TheAISContext()->OpenLocalContext();
817 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
819 // Active le mode Vertex et Edges
820 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
821 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
822 di<<" Select a vertex or an edge(build the middle)"<<"\n";
824 // Boucle d'attente waitpick.
825 Standard_Integer argcc = 5;
826 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
827 const char **argvv = (const char **) buff;
828 while (ViewerMainLoop( argcc, argvv) ) { }
832 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
833 ShapeA= TheAISContext()->SelectedShape();
836 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
837 // Un vertex a ete selectionne
838 // Fermeture du context local
839 TheAISContext()->CloseLocalContext(myCurrentIndex);
841 // Construction du point
842 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
843 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
844 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
845 GetMapOfAIS().Bind(myAISPoint,name);
846 TheAISContext()->Display(myAISPoint);
849 // Un Edge a ete selectionne
850 // Fermeture du context local
851 TheAISContext()->CloseLocalContext(myCurrentIndex);
853 // Construction du point milieu de l'edge
854 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
855 TopoDS_Vertex myVertexA,myVertexB;
856 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
857 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
858 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
859 // M est le milieu de [AB]
860 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
861 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
862 GetMapOfAIS().Bind(myAISPointM,name);
863 TheAISContext()->Display(myAISPointM);
871 //==============================================================================
872 // Function 1st click 2de click 3de click
873 // vplane Vertex Vertex Vertex
877 // vplanepara Face Vertex
879 // vplaneortho Face Edge
881 //==============================================================================
883 //==============================================================================
884 //function : VPlaneBuilder
885 //purpose : Build an AIS_Plane from selected entities or Named AIS components
886 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
887 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
888 // [PlaneName] [PointName] [TypeOfSensitivity]
889 //==============================================================================
891 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
892 Standard_Integer argc,
896 Standard_Boolean hasArg;
897 TCollection_AsciiString aName;
898 Standard_Integer aCurrentIndex;
901 if (argc<2 || argc>6 )
903 std::cout<<" Syntax error\n";
906 if (argc == 6 || argc==5 || argc==4)
907 hasArg=Standard_True;
909 hasArg=Standard_False;
912 // Close all contexts
913 TheAISContext()->CloseAllContexts();
915 // There are some arguments
918 if (!GetMapOfAIS().IsBound2(argv[2] ))
920 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
923 // Get shape from map
924 Handle(AIS_InteractiveObject) aShapeA =
925 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
927 // The first argument is an AIS_Point
928 if (!aShapeA.IsNull() &&
929 aShapeA->Type()==AIS_KOI_Datum &&
930 aShapeA->Signature()==1)
932 // The second argument must also be an AIS_Point
933 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
935 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
938 // Get shape from map
939 Handle(AIS_InteractiveObject) aShapeB =
940 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
941 // If B is not an AIS_Point
942 if (aShapeB.IsNull() ||
943 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
945 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
948 // The third object is an AIS_Point
949 if (!GetMapOfAIS().IsBound2(argv[4]) )
951 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
954 // Get shape from map
955 Handle(AIS_InteractiveObject) aShapeC =
956 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
957 // If C is not an AIS_Point
958 if (aShapeC.IsNull() ||
959 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
961 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
965 // Treatment of objects A, B, C
966 // Downcast an AIS_IO to AIS_Point
967 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
968 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
969 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
971 Handle(Geom_CartesianPoint ) aCartPointA =
972 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
974 Handle(Geom_CartesianPoint ) aCartPointB =
975 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
977 Handle(Geom_CartesianPoint ) aCartPointC =
978 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
980 // Verification that the three points are different
981 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
982 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
983 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
986 std::cout<<"vplane error: same points"<<"\n";return 1;
988 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
989 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
990 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
993 std::cout<<"vplane error: same points"<<"\n";return 1;
995 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
996 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
997 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1000 std::cout<<"vplane error: same points"<<"\n";return 1;
1003 gp_Pnt A = aCartPointA->Pnt();
1004 gp_Pnt B = aCartPointB->Pnt();
1005 gp_Pnt C = aCartPointC->Pnt();
1007 // Construction of AIS_Plane
1008 GC_MakePlane MkPlane (A,B,C);
1009 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1010 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1011 GetMapOfAIS().Bind (anAISPlane,aName );
1014 Standard_Integer aType = Draw::Atoi (argv[5]);
1015 if (aType != 0 && aType != 1)
1017 std::cout << "vplane error: wrong type of sensitivity!\n"
1018 << "Should be one of the following values:\n"
1026 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1029 TheAISContext()->Display(anAISPlane);
1032 // The first argument is an AIS_Axis
1033 // Creation of a plane orthogonal to the axis through a point
1034 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1035 // The second argument should be an AIS_Point
1036 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1038 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1041 // Get shape from map
1042 Handle(AIS_InteractiveObject) aShapeB =
1043 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1044 // If B is not an AIS_Point
1045 if (aShapeB.IsNull() ||
1046 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1048 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1052 // Treatment of objects A and B
1053 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1054 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1056 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1057 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1059 gp_Ax1 anAxis = aGeomLineA->Position();
1060 Handle(Geom_CartesianPoint) aCartPointB =
1061 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1063 gp_Dir D =anAxis.Direction();
1064 gp_Pnt B = aCartPointB->Pnt();
1066 // Construction of AIS_Plane
1067 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1068 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1069 GetMapOfAIS().Bind (anAISPlane,aName );
1072 Standard_Integer aType = Draw::Atoi (argv[4]);
1073 if (aType != 0 && aType != 1)
1075 std::cout << "vplane error: wrong type of sensitivity!\n"
1076 << "Should be one of the following values:\n"
1084 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1087 TheAISContext()->Display(anAISPlane);
1090 // The first argumnet is an AIS_Plane
1091 // Creation of a plane parallel to the plane passing through the point
1092 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1094 // The second argument should be an AIS_Point
1095 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1097 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1100 // Get shape from map
1101 Handle(AIS_InteractiveObject) aShapeB =
1102 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1103 // B should be an AIS_Point
1104 if (aShapeB.IsNull() ||
1105 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1107 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1111 // Treatment of objects A and B
1112 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1113 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1115 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1116 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1118 Handle(Geom_CartesianPoint) aCartPointB =
1119 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1120 gp_Pnt B= aCartPointB->Pnt();
1122 // Construction of an AIS_Plane
1123 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1124 GetMapOfAIS().Bind (anAISPlane, aName);
1127 Standard_Integer aType = Draw::Atoi (argv[4]);
1128 if (aType != 0 && aType != 1)
1130 std::cout << "vplane error: wrong type of sensitivity!\n"
1131 << "Should be one of the following values:\n"
1139 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1142 TheAISContext()->Display(anAISPlane);
1147 std::cout<<"vplane: error 1st object is not an AIS\n";
1151 // There are no arguments
1155 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1156 if (!strcasecmp(argv[0], "vplane"))
1158 TheAISContext()->OpenLocalContext();
1159 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1161 // Active modes Vertex, Edge and Face
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1163 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1164 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1165 std::cout<<"Select a vertex, a face or an edge\n";
1168 Standard_Integer argcc = 5;
1169 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1170 const char **argvv = (const char **) buff;
1171 while (ViewerMainLoop( argcc, argvv) ) { }
1174 TopoDS_Shape aShapeA;
1175 for (TheAISContext()->InitSelected();
1176 TheAISContext()->MoreSelected();
1177 TheAISContext()->NextSelected())
1179 aShapeA = TheAISContext()->SelectedShape();
1182 // aShapeA is a Vertex
1183 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1185 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1186 std::cout<<" Select an edge or a different vertex\n";
1189 Standard_Integer argccc = 5;
1190 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1191 const char **argvvv = (const char **) bufff;
1192 while (ViewerMainLoop( argccc, argvvv) ) { }
1195 TopoDS_Shape aShapeB;
1196 for (TheAISContext()->InitSelected();
1197 TheAISContext()->MoreSelected();
1198 TheAISContext()->NextSelected())
1200 aShapeB = TheAISContext()->SelectedShape();
1202 // aShapeB is a Vertex
1203 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1205 // A and B are the same
1206 if (aShapeB.IsSame(aShapeA))
1208 std::cout<<" vplane: error, same points selected\n";
1211 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1212 std::cout<<" Select a different vertex\n";
1215 Standard_Integer argcccc = 5;
1216 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1217 const char **argvvvv = (const char **) buffff;
1218 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1221 TopoDS_Shape aShapeC;
1222 for (TheAISContext()->InitSelected();
1223 TheAISContext()->MoreSelected();
1224 TheAISContext()->NextSelected())
1226 aShapeC = TheAISContext()->SelectedShape();
1228 // aShapeC is the same as A or B
1229 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1231 std::cout<<" vplane: error, same points selected\n";
1235 // Close the local context
1236 TheAISContext()->CloseLocalContext(aCurrentIndex);
1238 // Construction of plane
1239 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1240 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1241 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1242 GC_MakePlane MkPlane(A, B, C);
1243 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1244 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1245 GetMapOfAIS().Bind (anAISPlane, aName);
1246 TheAISContext()->Display(anAISPlane);
1248 // ShapeB is an edge
1251 // Verify that the vertex is not on the edge ShapeB
1252 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1253 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1255 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1256 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1258 // The vertex is on the edge
1259 std::cout<<" vplane: error point is on the edge\n";
1264 // Close the local context
1265 TheAISContext()->CloseLocalContext(aCurrentIndex);
1266 // Construction of plane
1267 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1268 TopoDS_Vertex aVBa, aVBb;
1269 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1270 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1271 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1272 GC_MakePlane MkPlane (A, aBa, aBb);
1273 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1274 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1275 GetMapOfAIS().Bind (anAISPlane, aName);
1276 TheAISContext()->Display(anAISPlane);
1280 // aShapeA is an edge
1281 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1283 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1284 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1285 std::cout<<" Select a vertex that don't belong to the edge\n";
1288 Standard_Integer argccc = 5;
1289 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1290 const char **argvvv = (const char **) bufff;
1291 while (ViewerMainLoop( argccc, argvvv) ) { }
1294 TopoDS_Shape aShapeB;
1295 for (TheAISContext()->InitSelected();
1296 TheAISContext()->MoreSelected();
1297 TheAISContext()->NextSelected())
1299 aShapeB = TheAISContext()->SelectedShape();
1301 // aShapeB should be a Vertex
1302 // Check that the vertex aShapeB is not on the edge
1303 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1304 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1306 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1307 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1309 // The vertex is on the edge
1310 std::cout<<" vplane: error point is on the edge\n";
1315 // Close the local context
1316 TheAISContext()->CloseLocalContext(aCurrentIndex);
1317 // Construction of plane
1318 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1319 TopoDS_Vertex aVAa, aVAb;
1320 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1321 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1322 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1323 GC_MakePlane MkPlane (B,Aa,Ab);
1324 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1325 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1326 GetMapOfAIS().Bind (anAISPlane ,aName);
1327 TheAISContext()->Display(anAISPlane);
1330 // aShapeA is a Face
1333 // Close the local context: nothing to select
1334 TheAISContext()->CloseLocalContext(aCurrentIndex);
1335 // Construction of plane
1336 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1337 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1338 if (aSurface.GetType()==GeomAbs_Plane)
1340 gp_Pln aPlane = aSurface.Plane();
1341 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1342 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1343 GetMapOfAIS().Bind (anAISPlane, aName);
1344 TheAISContext()->Display(anAISPlane);
1348 std::cout<<" vplane: error\n";
1354 // Function vPlanePara
1355 // ===================
1356 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1357 else if (!strcasecmp(argv[0], "vplanepara"))
1359 TheAISContext()->OpenLocalContext();
1360 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1362 // Activate modes Vertex and Face
1363 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1364 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1365 std::cout<<" Select a vertex or a face\n";
1368 Standard_Integer argcc = 5;
1369 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1370 const char **argvv = (const char **) buff;
1371 while (ViewerMainLoop( argcc, argvv) ) { }
1374 TopoDS_Shape aShapeA;
1375 for (TheAISContext()->InitSelected();
1376 TheAISContext()->MoreSelected();
1377 TheAISContext()->NextSelected())
1379 aShapeA = TheAISContext()->SelectedShape();
1382 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1384 // aShapeA is a vertex
1385 // Deactivate the mode Vertex
1386 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1387 std::cout<<" Select a face\n";
1390 Standard_Integer argccc = 5;
1391 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1392 const char **argvvv = (const char **) bufff;
1393 while (ViewerMainLoop( argccc, argvvv) ) { }
1396 TopoDS_Shape aShapeB;
1397 for (TheAISContext()->InitSelected();
1398 TheAISContext()->MoreSelected();
1399 TheAISContext()->NextSelected())
1401 // A vertex ShapeA can be on Face ShapeB
1402 aShapeB = TheAISContext()->SelectedShape();
1405 // Close the local context
1406 TheAISContext()->CloseLocalContext(aCurrentIndex);
1408 // Construction of plane
1409 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1411 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1412 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1413 if (aSurface.GetType()==GeomAbs_Plane )
1415 gp_Pln aPlane = aSurface.Plane();
1416 // Construct a plane parallel to aGeomPlane through A
1417 aPlane.SetLocation(A);
1418 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1419 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1420 GetMapOfAIS().Bind (aAISPlane ,aName);
1421 TheAISContext()->Display(aAISPlane);
1425 std::cout<<" vplanepara: error\n";
1432 // Deactive the mode Face
1433 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1434 std::cout<<" Select a vertex\n";
1437 Standard_Integer argccc = 5;
1438 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1439 const char **argvvv = (const char **) bufff;
1440 while (ViewerMainLoop( argccc, argvvv) ) { }
1443 TopoDS_Shape aShapeB;
1444 for (TheAISContext()->InitSelected();
1445 TheAISContext()->MoreSelected();
1446 TheAISContext()->NextSelected())
1448 // A vertex ShapeB can be on Face ShapeA
1449 aShapeB = TheAISContext()->SelectedShape();
1451 // Close the local context
1452 TheAISContext()->CloseLocalContext(aCurrentIndex);
1454 // Construction of plane
1455 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1457 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1458 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1459 if (aSurface.GetType()==GeomAbs_Plane )
1461 gp_Pln aPlane = aSurface.Plane();
1462 aPlane.SetLocation(B);
1463 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1464 // Construct a plane parallel to aGeomPlane through B
1465 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1466 GetMapOfAIS().Bind (anAISPlane, aName);
1467 TheAISContext()->Display(anAISPlane);
1471 std::cout<<" vplanepara: error"<<"\n";return 1;
1476 // Function vplaneortho
1477 // ====================
1478 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1481 TheAISContext()->OpenLocalContext();
1482 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1484 // Activate the modes Edge and Face
1485 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1486 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1487 std::cout<<" Select a face and an edge coplanar\n";
1490 Standard_Integer argcc = 5;
1491 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1492 const char **argvv = (const char **) buff;
1493 while (ViewerMainLoop( argcc, argvv) ) { }
1496 TopoDS_Shape aShapeA;
1497 for (TheAISContext()->InitSelected();
1498 TheAISContext()->MoreSelected();
1499 TheAISContext()->NextSelected())
1501 aShapeA = TheAISContext()->SelectedShape();
1504 if (aShapeA.ShapeType()==TopAbs_EDGE )
1506 // ShapeA is an edge, deactivate the mode Edge...
1507 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1508 std::cout<<" Select a face\n";
1511 Standard_Integer argccc = 5;
1512 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1513 const char **argvvv = (const char **) bufff;
1514 while (ViewerMainLoop( argccc, argvvv) ) { }
1517 TopoDS_Shape aShapeB;
1518 for (TheAISContext()->InitSelected();
1519 TheAISContext()->MoreSelected();
1520 TheAISContext()->NextSelected())
1522 // Edge ShapeA can be on Face ShapeB
1523 aShapeB = TheAISContext()->SelectedShape();
1526 // Close the local context
1527 TheAISContext()->CloseLocalContext(aCurrentIndex);
1529 // Construction of plane
1530 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1531 TopoDS_Vertex aVAa, aVAb;
1532 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1533 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1534 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1538 // Creation of rotation axis
1539 gp_Ax1 aRotAxis (Aa,Dab);
1541 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1542 // The edge must be parallel to the face
1543 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1544 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1545 // Compare to heights
1546 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1547 >Precision::Confusion())
1549 // the edge is not parallel to the face
1550 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1554 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1555 if (aSurface.GetType()==GeomAbs_Plane)
1557 gp_Pln aPlane = aSurface.Plane();
1558 // It rotates a half turn round the axis of rotation
1559 aPlane.Rotate(aRotAxis , M_PI/2);
1561 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1562 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1563 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1564 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1565 GetMapOfAIS().Bind (anAISPlane, aName);
1566 TheAISContext()->Display(anAISPlane);
1570 std::cout<<" vplaneortho: error\n";
1576 // ShapeA is a Face, deactive the mode Face.
1577 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1578 std::cout<<" Select an edge\n";
1581 Standard_Integer argccc = 5;
1582 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1583 const char **argvvv = (const char **) bufff;
1584 while (ViewerMainLoop( argccc, argvvv) ) { }
1587 TopoDS_Shape aShapeB;
1588 for (TheAISContext()->InitSelected();
1589 TheAISContext()->MoreSelected();
1590 TheAISContext()->NextSelected())
1592 // Edge ShapeB can be on Face ShapeA
1593 aShapeB = TheAISContext()->SelectedShape();
1595 // Close the local context
1596 TheAISContext()->CloseLocalContext(aCurrentIndex);
1598 // Construction of plane
1599 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1600 TopoDS_Vertex aVBa, aVBb;
1601 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1602 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1603 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1604 gp_Vec ab (aBa,aBb);
1606 // Creation of rotation axe
1607 gp_Ax1 aRotAxis (aBa,Dab);
1609 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1610 // The edge must be parallel to the face
1611 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1612 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1613 // Comparing the two heights
1614 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1615 >Precision::Confusion())
1617 // the edge is not parallel to the face
1618 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1622 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1623 if (aSurface.GetType()==GeomAbs_Plane)
1625 gp_Pln aPlane = aSurface.Plane();
1626 // It rotates a half turn round the axis of rotation
1627 aPlane.Rotate(aRotAxis , M_PI/2);
1628 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1629 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1630 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1631 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1632 GetMapOfAIS().Bind (anAISPlane ,aName);
1633 TheAISContext()->Display(anAISPlane);
1637 std::cout<<" vplaneortho: error\n";
1646 //===============================================================================================
1647 //function : VChangePlane
1649 //===============================================================================================
1650 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1652 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1653 if (aContextAIS.IsNull())
1655 std::cout << theArgVec[0] << "AIS context is not available.\n";
1659 if (theArgsNb < 3 || theArgsNb > 11)
1661 std::cerr << theArgVec[0]
1662 << ": incorrect number of command arguments.\n"
1663 << "Type help for more information.\n";
1667 TCollection_AsciiString aName (theArgVec[1]);
1669 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1670 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1673 if ( aPlane.IsNull() )
1675 std::cout << theArgVec[0]
1676 << ": there is no interactive plane with the given name."
1677 << "Type help for more information.\n";
1681 Standard_Real aCenterX = aPlane->Center().X();
1682 Standard_Real aCenterY = aPlane->Center().Y();
1683 Standard_Real aCenterZ = aPlane->Center().Z();
1685 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1686 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1687 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1689 Standard_Real aSizeX = 0.0;
1690 Standard_Real aSizeY = 0.0;
1691 aPlane->Size (aSizeX, aSizeY);
1692 Standard_Boolean isUpdate = Standard_True;
1694 TCollection_AsciiString aPName, aPValue;
1695 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1697 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1698 TCollection_AsciiString anArgCase = anArg;
1699 anArgCase.UpperCase();
1700 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1703 if (aPName.IsEqual ("X"))
1705 aCenterX = aPValue.RealValue();
1707 else if (aPName.IsEqual ("Y"))
1709 aCenterY = aPValue.RealValue();
1711 else if (aPName.IsEqual ("Z"))
1713 aCenterZ = aPValue.RealValue();
1715 else if (aPName.IsEqual ("DX"))
1717 aDirX = aPValue.RealValue();
1719 else if (aPName.IsEqual ("DY"))
1721 aDirY = aPValue.RealValue();
1723 else if (aPName.IsEqual ("DZ"))
1725 aDirZ = aPValue.RealValue();
1727 else if (aPName.IsEqual ("SX"))
1729 aSizeX = aPValue.RealValue();
1731 else if (aPName.IsEqual ("SY"))
1733 aSizeY = aPValue.RealValue();
1736 else if (anArg.IsEqual ("NOUPDATE"))
1738 isUpdate = Standard_False;
1742 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1743 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1744 aPlane->SetCenter (aCenterPnt);
1745 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1746 aPlane->SetSize (aSizeX, aSizeY);
1748 aContextAIS->Update (aPlane, isUpdate);
1753 //==============================================================================
1755 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1756 //==============================================================================
1758 //==============================================================================
1759 //function : VLineBuilder
1760 //purpose : Build an AIS_Line
1761 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1762 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1763 //==============================================================================
1764 #include <Geom_CartesianPoint.hxx>
1765 #include <AIS_Line.hxx>
1768 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1770 Standard_Integer myCurrentIndex;
1772 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1773 // Fermeture des contextes
1774 TheAISContext()->CloseAllContexts();
1776 // On recupere les parametres
1777 Handle(AIS_InteractiveObject) theShapeA;
1778 Handle(AIS_InteractiveObject) theShapeB;
1780 // Parametres: AIS_Point AIS_Point
1781 // ===============================
1784 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1785 // On verifie que c'est bien une AIS_Point
1786 if (!theShapeA.IsNull() &&
1787 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1788 // on recupere le deuxieme AIS_Point
1790 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1791 if (theShapeA.IsNull() ||
1792 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1794 di <<"vline error: wrong type of 2de argument."<<"\n";
1798 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1799 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1801 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1803 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1804 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1805 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1807 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1808 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1809 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1811 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1813 di<<"vline error: same points"<<"\n";return 1;
1815 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817 GetMapOfAIS().Bind(theAISLine,argv[1] );
1818 TheAISContext()->Display(theAISLine );
1822 // Parametres 6 Reals
1823 // ==================
1826 // On verifie que les deux points ne sont pas confondus
1828 Standard_Real coord[6];
1829 for(Standard_Integer i=0;i<=2;i++){
1830 coord[i]=Draw::Atof(argv[2+i]);
1831 coord[i+3]=Draw::Atof(argv[5+i]);
1834 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1837 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838 GetMapOfAIS().Bind(theAISLine,argv[1] );
1839 TheAISContext()->Display(theAISLine );
1843 // Pas de parametres: Selection dans le viewer.
1844 // ============================================
1847 TheAISContext()->OpenLocalContext();
1848 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1850 // Active le mode Vertex.
1851 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1852 di<<" Select a vertex "<<"\n";
1854 // Boucle d'attente waitpick.
1855 Standard_Integer argcc = 5;
1856 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1857 const char **argvv = (const char **) buff;
1858 while (ViewerMainLoop( argcc, argvv) ) { }
1861 TopoDS_Shape ShapeA;
1862 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1863 ShapeA = TheAISContext()->SelectedShape();
1866 // ShapeA est un Vertex
1867 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1869 di<<" Select a different vertex."<<"\n";
1871 TopoDS_Shape ShapeB;
1874 // Boucle d'attente waitpick.
1875 Standard_Integer argccc = 5;
1876 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1877 const char **argvvv = (const char **) bufff;
1878 while (ViewerMainLoop( argccc, argvvv) ) { }
1881 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1882 ShapeB = TheAISContext()->SelectedShape();
1886 } while(ShapeB.IsSame(ShapeA) );
1888 // Fermeture du context local
1889 TheAISContext()->CloseLocalContext(myCurrentIndex);
1891 // Construction de la line
1892 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1893 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1895 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1896 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1898 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1899 GetMapOfAIS().Bind(theAISLine,argv[1] );
1900 TheAISContext()->Display(theAISLine );
1904 di<<"vline error."<<"\n";
1912 //==============================================================================
1913 // class : FilledCircle
1914 // purpose : creates filled circle based on AIS_InteractiveObject
1916 // This class is used to check method Matches() of class
1917 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1918 // because none of AIS classes provides creation of
1919 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1920 // (look method ComputeSelection() )
1921 //==============================================================================
1923 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1925 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1926 gp_Circ aCirc(anAxes, theRadius);
1927 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1931 class FilledCircle : public AIS_InteractiveObject
1935 DEFINE_STANDARD_RTTI(FilledCircle, AIS_InteractiveObject);
1937 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1938 FilledCircle(Handle(Geom_Circle) theCircle);
1941 TopoDS_Face ComputeFace();
1943 // Virtual methods implementation
1944 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1945 const Handle(Prs3d_Presentation)& thePresentation,
1946 const Standard_Integer theMode);
1948 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1949 const Standard_Integer theMode);
1952 Handle(Geom_Circle) myCircle;
1953 Standard_Boolean myFilledStatus;
1958 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1960 myCircle = CreateCircle(theCenter, theRadius);
1961 myFilledStatus = Standard_True;
1964 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1966 myCircle = theCircle;
1967 myFilledStatus = Standard_True;
1970 TopoDS_Face FilledCircle::ComputeFace()
1972 // Create edge from myCircle
1973 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1974 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1976 // Create wire from anEdge
1977 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1978 TopoDS_Wire aWire = aWireMaker.Wire();
1980 // Create face from aWire
1981 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1982 TopoDS_Face aFace = aFaceMaker.Face();
1987 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1988 const Handle(Prs3d_Presentation) &thePresentation,
1989 const Standard_Integer theMode)
1991 thePresentation->Clear();
1993 TopoDS_Face aFace = ComputeFace();
1995 if (aFace.IsNull()) return;
1996 if (theMode != 0) return;
1998 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2001 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2002 const Standard_Integer /*theMode*/)
2004 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2005 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2006 myCircle, myFilledStatus);
2007 theSelection->Add(aSensitiveCircle);
2010 //==============================================================================
2012 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2013 //==============================================================================
2015 //==============================================================================
2016 //function : VCircleBuilder
2017 //purpose : Build an AIS_Circle
2018 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2019 // PointName PointName PointName IsFilled
2020 //==============================================================================
2022 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2023 TCollection_AsciiString theName,
2024 Standard_Boolean isFilled)
2026 Handle(AIS_InteractiveObject) aCircle;
2029 aCircle = new FilledCircle(theGeomCircle);
2033 aCircle = new AIS_Circle(theGeomCircle);
2034 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2037 // Check if there is an object with given name
2038 // and remove it from context
2039 if (GetMapOfAIS().IsBound2(theName))
2041 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2042 Handle(AIS_InteractiveObject) anInterObj =
2043 Handle(AIS_InteractiveObject)::DownCast(anObj);
2044 TheAISContext()->Remove(anInterObj, Standard_False);
2045 GetMapOfAIS().UnBind2(theName);
2048 // Bind the circle to its name
2049 GetMapOfAIS().Bind(aCircle, theName);
2051 // Display the circle
2052 TheAISContext()->Display(aCircle);
2056 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2058 Standard_Integer myCurrentIndex;
2059 // Verification of the arguments
2060 if (argc>6 || argc<2)
2062 std::cout << "vcircle error: expect 4 arguments.\n";
2063 return 1; // TCL_ERROR
2065 TheAISContext()->CloseAllContexts();
2067 // There are all arguments
2071 TCollection_AsciiString aName(argv[1]);
2072 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2074 Handle(AIS_InteractiveObject) theShapeA;
2075 Handle(AIS_InteractiveObject) theShapeB;
2078 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2080 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2083 // Arguments: AIS_Point AIS_Point AIS_Point
2084 // ========================================
2085 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2086 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2088 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2090 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2091 return 1; // TCL_ERROR
2093 // The third object must be a point
2094 Handle(AIS_InteractiveObject) theShapeC =
2095 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2096 if (theShapeC.IsNull() ||
2097 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2099 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2100 return 1; // TCL_ERROR
2103 // Verify that the three points are different
2104 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2105 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2106 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2108 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2109 Handle(Geom_CartesianPoint) myCartPointA =
2110 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2112 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2113 Handle(Geom_CartesianPoint) myCartPointB =
2114 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2116 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2117 Handle(Geom_CartesianPoint) myCartPointC =
2118 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2121 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2122 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2123 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2125 std::cout << "vcircle error: Same points.\n";
2126 return 1; // TCL_ERROR
2129 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2130 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2131 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2133 std::cout << "vcircle error: Same points.\n";
2134 return 1; // TCL_ERROR
2137 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2138 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2139 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2141 std::cout << "vcircle error: Same points.\n";
2142 return 1;// TCL_ERROR
2144 // Construction of the circle
2145 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2146 myCartPointB->Pnt(), myCartPointC->Pnt() );
2147 Handle (Geom_Circle) theGeomCircle;
2150 theGeomCircle = Cir.Value();
2152 catch (StdFail_NotDone)
2154 std::cout << "vcircle error: can't create circle\n";
2155 return -1; // TCL_ERROR
2158 DisplayCircle(theGeomCircle, aName, isFilled);
2161 // Arguments: AIS_Plane AIS_Point Real
2162 // ===================================
2163 else if (theShapeA->Type() == AIS_KOI_Datum &&
2164 theShapeA->Signature() == 7 )
2166 if (theShapeB->Type() != AIS_KOI_Datum ||
2167 theShapeB->Signature() != 1 )
2169 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2170 return 1; // TCL_ERROR
2172 // Check that the radius is >= 0
2173 if (Draw::Atof(argv[4]) <= 0 )
2175 std::cout << "vcircle error: the radius must be >=0.\n";
2176 return 1; // TCL_ERROR
2179 // Recover the normal to the plane
2180 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2181 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2183 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2184 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2185 Handle(Geom_CartesianPoint) myCartPointB =
2186 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2188 gp_Pln mygpPlane = myGeomPlane->Pln();
2189 gp_Ax1 thegpAxe = mygpPlane.Axis();
2190 gp_Dir theDir = thegpAxe.Direction();
2191 gp_Pnt theCenter = myCartPointB->Pnt();
2192 Standard_Real TheR = Draw::Atof(argv[4]);
2193 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2194 Handle (Geom_Circle) theGeomCircle;
2197 theGeomCircle = Cir.Value();
2199 catch (StdFail_NotDone)
2201 std::cout << "vcircle error: can't create circle\n";
2202 return -1; // TCL_ERROR
2205 DisplayCircle(theGeomCircle, aName, isFilled);
2212 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2213 return 1; // TCL_ERROR
2217 // No arguments: selection in the viewer
2218 // =========================================
2221 // Get the name of the circle
2222 TCollection_AsciiString aName(argv[1]);
2224 TheAISContext()->OpenLocalContext();
2225 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2227 // Activate selection mode for vertices and faces
2228 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2229 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2230 std::cout << " Select a vertex or a face\n";
2233 Standard_Integer argcc = 5;
2234 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2235 const char **argvv = (const char **) buff;
2236 while (ViewerMainLoop( argcc, argvv) ) { }
2239 TopoDS_Shape ShapeA;
2240 for(TheAISContext()->InitSelected();
2241 TheAISContext()->MoreSelected();
2242 TheAISContext()->NextSelected() )
2244 ShapeA = TheAISContext()->SelectedShape();
2247 // ShapeA is a Vertex
2248 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2250 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2251 std::cout << " Select a different vertex\n";
2253 TopoDS_Shape ShapeB;
2257 Standard_Integer argccc = 5;
2258 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2259 const char **argvvv = (const char **) bufff;
2260 while (ViewerMainLoop( argccc, argvvv) ) { }
2263 for(TheAISContext()->InitSelected();
2264 TheAISContext()->MoreSelected();
2265 TheAISContext()->NextSelected() )
2267 ShapeB = TheAISContext()->SelectedShape();
2269 } while(ShapeB.IsSame(ShapeA) );
2271 // Selection of ShapeC
2272 std::cout << " Select the last vertex\n";
2273 TopoDS_Shape ShapeC;
2277 Standard_Integer argcccc = 5;
2278 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2279 const char **argvvvv = (const char **) buffff;
2280 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2283 for(TheAISContext()->InitSelected();
2284 TheAISContext()->MoreSelected();
2285 TheAISContext()->NextSelected() )
2287 ShapeC = TheAISContext()->SelectedShape();
2289 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2292 Standard_Boolean isFilled;
2293 std::cout << "Enter filled status (0 or 1)\n";
2296 // Close the local context
2297 TheAISContext()->CloseLocalContext(myCurrentIndex);
2299 // Construction of the circle
2300 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2301 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2302 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2304 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2305 Handle (Geom_Circle) theGeomCircle;
2308 theGeomCircle = Cir.Value();
2310 catch (StdFail_NotDone)
2312 std::cout << "vcircle error: can't create circle\n";
2313 return -1; // TCL_ERROR
2316 DisplayCircle(theGeomCircle, aName, isFilled);
2322 std::cout << " Select a vertex (in your face)\n";
2323 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2325 TopoDS_Shape ShapeB;
2327 Standard_Integer argccc = 5;
2328 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2329 const char **argvvv = (const char **) bufff;
2330 while (ViewerMainLoop( argccc, argvvv) ) { }
2333 for(TheAISContext()->InitSelected();
2334 TheAISContext()->MoreSelected();
2335 TheAISContext()->NextSelected() )
2337 ShapeB = TheAISContext()->SelectedShape();
2340 // Recover the radius
2341 Standard_Real theRad;
2344 std::cout << " Enter the value of the radius:\n";
2346 } while (theRad <= 0);
2348 // Get filled status
2349 Standard_Boolean isFilled;
2350 std::cout << "Enter filled status (0 or 1)\n";
2353 // Close the local context
2354 TheAISContext()->CloseLocalContext(myCurrentIndex);
2355 // Construction of the circle
2357 // Recover the normal to the plane. tag
2358 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2359 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2360 gp_Pln myPlane = mySurface.Plane();
2361 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2362 gp_Pln mygpPlane = theGeomPlane->Pln();
2363 gp_Ax1 thegpAxe = mygpPlane.Axis();
2364 gp_Dir theDir = thegpAxe.Direction();
2366 // Recover the center
2367 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2369 // Construct the circle
2370 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2371 Handle (Geom_Circle) theGeomCircle;
2374 theGeomCircle = Cir.Value();
2376 catch (StdFail_NotDone)
2378 std::cout << "vcircle error: can't create circle\n";
2379 return -1; // TCL_ERROR
2382 DisplayCircle(theGeomCircle, aName, isFilled);
2391 //=======================================================================
2392 //function : VDrawText
2394 //=======================================================================
2395 static int VDrawText (Draw_Interpretor& theDI,
2396 Standard_Integer theArgsNb,
2397 const char** theArgVec)
2399 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2402 std::cout << "Error: wrong number of arguments! See usage:\n";
2403 theDI.PrintHelp (theArgVec[0]);
2406 else if (aContext.IsNull())
2408 std::cout << "Error: no active view!\n";
2412 Standard_Integer anArgIt = 1;
2413 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2414 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2415 Handle(AIS_TextLabel) aTextPrs;
2416 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2418 if (GetMapOfAIS().IsBound2 (aName))
2420 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2424 aTextPrs = new AIS_TextLabel();
2425 aTextPrs->SetFont ("Courier");
2428 aTextPrs->SetText (aText);
2430 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
2432 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2435 Standard_Boolean aHasPlane = Standard_False;
2440 for (; anArgIt < theArgsNb; ++anArgIt)
2442 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2445 if (anAutoUpdater.parseRedrawMode (aParam))
2449 else if (aParam == "-pos"
2450 || aParam == "-position")
2452 if (anArgIt + 3 >= theArgsNb)
2454 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2458 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2459 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2460 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2461 aTextPrs->SetPosition (aPos);
2463 else if (aParam == "-color")
2465 if (anArgIt + 1 >= theArgsNb)
2467 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2471 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2472 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2473 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2476 aTextPrs->SetColor (aNameOfColor);
2479 else if (anArgIt + 3 >= theArgsNb)
2481 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2485 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2486 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2487 if (!aColor.IsRealValue()
2488 || !aGreen.IsRealValue()
2489 || !aBlue.IsRealValue())
2491 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2495 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2499 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2502 else if (aParam == "-halign")
2504 if (++anArgIt >= theArgsNb)
2506 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2510 TCollection_AsciiString aType (theArgVec[anArgIt]);
2512 if (aType == "left")
2514 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2516 else if (aType == "center")
2518 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2520 else if (aType == "right")
2522 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2526 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2530 else if (aParam == "-valign")
2532 if (++anArgIt >= theArgsNb)
2534 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2538 TCollection_AsciiString aType (theArgVec[anArgIt]);
2542 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2544 else if (aType == "center")
2546 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2548 else if (aType == "bottom")
2550 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2552 else if (aType == "topfirstline")
2554 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2558 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2562 else if (aParam == "-angle")
2564 if (++anArgIt >= theArgsNb)
2566 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2570 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2572 else if (aParam == "-zoom")
2574 if (++anArgIt >= theArgsNb)
2576 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2580 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2582 else if (aParam == "-height")
2584 if (++anArgIt >= theArgsNb)
2586 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2590 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2592 else if (aParam == "-aspect")
2594 if (++anArgIt >= theArgsNb)
2596 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2600 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2601 anOption.LowerCase();
2602 if (anOption.IsEqual ("regular"))
2604 aTextPrs->SetFontAspect (Font_FA_Regular);
2606 else if (anOption.IsEqual ("bold"))
2608 aTextPrs->SetFontAspect (Font_FA_Bold);
2610 else if (anOption.IsEqual ("italic"))
2612 aTextPrs->SetFontAspect (Font_FA_Italic);
2614 else if (anOption.IsEqual ("bolditalic"))
2616 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2619 else if (aParam == "-font")
2621 if (++anArgIt >= theArgsNb)
2623 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2627 aTextPrs->SetFont (theArgVec[anArgIt]);
2629 else if (aParam == "-plane")
2631 if (anArgIt + 6 >= theArgsNb)
2633 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2637 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2638 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2639 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2640 aNormal.SetCoord (aX, aY, aZ);
2642 aX = Draw::Atof (theArgVec[++anArgIt]);
2643 aY = Draw::Atof (theArgVec[++anArgIt]);
2644 aZ = Draw::Atof (theArgVec[++anArgIt]);
2645 aDirection.SetCoord (aX, aY, aZ);
2647 aHasPlane = Standard_True;
2649 else if (aParam == "-disptype"
2650 || aParam == "-displaytype")
2652 if (++anArgIt >= theArgsNb)
2654 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2657 TCollection_AsciiString aType (theArgVec[anArgIt]);
2659 if (aType == "subtitle")
2660 aDisplayType = Aspect_TODT_SUBTITLE;
2661 else if (aType == "decal")
2662 aDisplayType = Aspect_TODT_DEKALE;
2663 else if (aType == "blend")
2664 aDisplayType = Aspect_TODT_BLEND;
2665 else if (aType == "dimension")
2666 aDisplayType = Aspect_TODT_DIMENSION;
2667 else if (aType == "normal")
2668 aDisplayType = Aspect_TODT_NORMAL;
2671 std::cout << "Error: wrong display type '" << aType << "'.\n";
2675 else if (aParam == "-subcolor"
2676 || aParam == "-subtitlecolor")
2678 if (anArgIt + 1 >= theArgsNb)
2680 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2684 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2685 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2686 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2689 aTextPrs->SetColorSubTitle (aNameOfColor);
2692 else if (anArgIt + 3 >= theArgsNb)
2694 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2698 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2699 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2700 if (!aColor.IsRealValue()
2701 || !aGreen.IsRealValue()
2702 || !aBlue.IsRealValue())
2704 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2708 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2712 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2715 else if (aParam == "-2d")
2717 aTrsfPersFlags = Graphic3d_TMF_2d;
2719 else if (aParam == "-trsfperspos"
2720 || aParam == "-perspos")
2722 if (anArgIt + 2 >= theArgsNb)
2724 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2728 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2729 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2730 TCollection_AsciiString aZ = "0";
2731 if (!aX.IsIntegerValue()
2732 || !aY.IsIntegerValue())
2734 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2737 if (anArgIt + 1 < theArgsNb)
2739 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2740 if (aTemp.IsIntegerValue())
2746 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
2750 std::cout << "Error: unknown argument '" << aParam << "'\n";
2757 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2760 if (aTrsfPersFlags != Graphic3d_TMF_None)
2762 aTextPrs->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
2763 aTextPrs->SetDisplayType (aDisplayType);
2764 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2765 if (aTextPrs->Position().Z() != 0)
2767 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2770 else if (aTrsfPersFlags != aTextPrs->TransformPersistence().Flags)
2772 aTextPrs->SetTransformPersistence (aTrsfPersFlags);
2773 aTextPrs->SetDisplayType (Aspect_TODT_NORMAL);
2775 ViewerTest::Display (aName, aTextPrs, Standard_False);
2780 #include <gp_Pnt.hxx>
2781 #include <Graphic3d_ArrayOfPoints.hxx>
2782 #include <Graphic3d_ArrayOfPrimitives.hxx>
2783 #include <Graphic3d_ArrayOfTriangles.hxx>
2784 #include <Poly_Array1OfTriangle.hxx>
2785 #include <Poly_Triangle.hxx>
2786 #include <Poly_Triangulation.hxx>
2787 #include <TColgp_Array1OfPnt.hxx>
2788 #include <TShort_Array1OfShortReal.hxx>
2789 #include <TShort_HArray1OfShortReal.hxx>
2791 #include <AIS_Triangulation.hxx>
2792 #include <StdPrs_ToolTriangulatedShape.hxx>
2793 #include <Poly_Connect.hxx>
2794 #include <TColgp_Array1OfDir.hxx>
2795 #include <Graphic3d_GraphicDriver.hxx>
2797 #include <TColStd_Array1OfInteger.hxx>
2798 #include <TColStd_HArray1OfInteger.hxx>
2799 #include <Prs3d_ShadingAspect.hxx>
2800 #include <Graphic3d_MaterialAspect.hxx>
2801 #include <Graphic3d_AspectFillArea3d.hxx>
2803 #include <BRepPrimAPI_MakeCylinder.hxx>
2804 #include <TopoDS_Shape.hxx>
2805 #include <TopExp_Explorer.hxx>
2806 #include <TopAbs.hxx>
2807 #include <StdSelect_ShapeTypeFilter.hxx>
2808 #include <AIS_InteractiveObject.hxx>
2811 //===============================================================================================
2812 //function : CalculationOfSphere
2814 //purpose : Create a Sphere
2815 //===============================================================================================
2817 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2820 double mRadius = Radius;
2821 double mCenter[3] = {X,Y,Z};
2822 int mThetaResolution;
2824 double mStartTheta = 0;//StartTheta;
2825 double mEndTheta = 360;//EndTheta;
2826 double mStartPhi = 0;//StartPhi;
2827 double mEndPhi = 180;//EndPhi;
2828 res = res < 4 ? 4 : res;
2830 mThetaResolution = res;
2831 mPhiResolution = res;
2834 int jStart, jEnd, numOffset;
2835 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2836 double startTheta, endTheta, startPhi, endPhi;
2837 int base, numPoles=0, thetaResolution, phiResolution;
2842 if ( numPieces > mThetaResolution ) {
2843 numPieces = mThetaResolution;
2846 int localThetaResolution = mThetaResolution;
2847 double localStartTheta = mStartTheta;
2848 double localEndTheta = mEndTheta;
2850 while ( localEndTheta < localStartTheta ) {
2851 localEndTheta += 360.0;
2854 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2856 // Change the ivars based on pieces.
2858 start = piece * localThetaResolution / numPieces;
2859 end = (piece+1) * localThetaResolution / numPieces;
2860 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2861 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2862 localThetaResolution = end - start;
2864 // Create north pole if needed
2865 int number_point = 0;
2866 int number_pointArray = 0;
2868 if ( mStartPhi <= 0.0 ) {
2869 number_pointArray++;
2872 if ( mEndPhi >= 180.0 ) {
2873 number_pointArray++;
2877 // Check data, determine increments, and convert to radians
2878 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2879 startTheta *= M_PI / 180.0;
2880 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2881 endTheta *= M_PI / 180.0;
2884 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2885 startPhi *= M_PI / 180.0;
2886 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2887 endPhi *= M_PI / 180.0;
2889 phiResolution = mPhiResolution - numPoles;
2890 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2891 thetaResolution = localThetaResolution;
2892 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2893 ++localThetaResolution;
2895 deltaTheta = (endTheta - startTheta) / thetaResolution;
2897 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2898 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2900 // Create intermediate points
2901 for ( i = 0; i < localThetaResolution; i++ ) {
2902 for ( j = jStart; j < jEnd; j++ ) {
2903 number_pointArray++;
2907 //Generate mesh connectivity
2908 base = phiResolution * localThetaResolution;
2910 int number_triangle = 0 ;
2911 if ( mStartPhi <= 0.0 ) { // around north pole
2912 number_triangle += localThetaResolution;
2915 if ( mEndPhi >= 180.0 ) { // around south pole
2916 number_triangle += localThetaResolution;
2919 // bands in-between poles
2920 for ( i=0; i < localThetaResolution; i++){
2921 for ( j=0; j < (phiResolution-1); j++){
2922 number_triangle +=2;
2926 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2927 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2928 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2930 if ( mStartPhi <= 0.0 ){
2933 x[2] = mCenter[2] + mRadius;
2934 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2937 // Create south pole if needed
2938 if ( mEndPhi >= 180.0 ){
2941 x[2] = mCenter[2] - mRadius;
2942 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2946 for ( i=0; i < localThetaResolution; i++){
2947 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2948 for ( j = jStart; j < jEnd; j++){
2949 phi = startPhi + j*deltaPhi;
2950 radius = mRadius * sin((double)phi);
2951 n[0] = radius * cos((double)theta);
2952 n[1] = radius * sin((double)theta);
2953 n[2] = mRadius * cos((double)phi);
2954 x[0] = n[0] + mCenter[0];
2955 x[1] = n[1] + mCenter[1];
2956 x[2] = n[2] + mCenter[2];
2957 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2963 number_triangle = 1;
2964 if ( mStartPhi <= 0.0 ){// around north pole
2965 for (i=0; i < localThetaResolution; i++){
2966 pts[0] = phiResolution*i + numPoles;
2967 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2969 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2974 if ( mEndPhi >= 180.0 ){ // around south pole
2975 numOffset = phiResolution - 1 + numPoles;
2976 for (i=0; i < localThetaResolution; i++){
2977 pts[0] = phiResolution*i + numOffset;
2978 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2979 pts[1] = numPoles - 1;
2980 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2985 // bands in-between poles
2987 for (i=0; i < localThetaResolution; i++){
2988 for (j=0; j < (phiResolution-1); j++){
2989 pts[0] = phiResolution*i + j + numPoles;
2990 pts[1] = pts[0] + 1;
2991 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2992 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2995 pts[2] = pts[1] - 1;
2996 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
3001 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
3003 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
3005 Standard_Integer index[3];
3006 Standard_Real Tol = Precision::Confusion();
3009 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
3010 gp_XYZ eqPlan(0, 0, 0);
3011 for ( pc->Initialize(i); pc->More(); pc->Next()) {
3012 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
3013 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
3014 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
3016 Standard_Real mod = vv.Modulus();
3017 if(mod < Tol) continue;
3021 Standard_Real modmax = eqPlan.Modulus();
3024 Nor = gp_Dir(eqPlan);
3026 Nor = gp_Dir(0., 0., 1.);
3028 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
3029 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
3030 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
3031 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
3035 polyTriangulation->SetNormals(Normals);
3037 return polyTriangulation;
3040 //===============================================================================================
3041 //function : VDrawSphere
3043 //purpose : Create an AIS shape.
3044 //===============================================================================================
3045 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
3048 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3049 if (aContextAIS.IsNull())
3051 std::cout << "Call vinit before!\n";
3056 std::cout << "Use: " << argv[0]
3057 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
3061 // read the arguments
3062 TCollection_AsciiString aShapeName (argv[1]);
3063 Standard_Integer aResolution = Draw::Atoi (argv[2]);
3064 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
3065 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
3066 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3067 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
3068 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3069 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
3071 // remove AIS object with given name from map
3072 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
3075 std::cout << "Compute Triangulation...\n";
3076 Handle(AIS_Triangulation) aShape
3077 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3080 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3081 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3083 // stupid initialization of Green color in RGBA space as integer
3084 // probably wrong for big-endian CPUs
3085 Standard_Integer aRed = 0;
3086 Standard_Integer aGreen = 255;
3087 Standard_Integer aBlue = 0;
3088 Standard_Integer anAlpha = 0; // not used
3089 Standard_Integer aColorInt = aRed;
3090 aColorInt += aGreen << 8;
3091 aColorInt += aBlue << 16;
3092 aColorInt += anAlpha << 24;
3094 // setup colors array per vertex
3095 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3096 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3098 aColorArray->SetValue (aNodeId, aColorInt);
3100 aShape->SetColors (aColorArray);
3103 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3104 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3105 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3106 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3107 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3108 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3109 aTotalSize >>= 20; //MB
3110 aNormalsSize >>= 20;
3112 aTrianglesSize >>= 20;
3113 aPolyConnectSize >>= 20;
3116 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3117 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3118 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3119 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3120 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3121 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3124 // Setting material properties, very important for desirable visual result!
3125 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3126 aMat.SetAmbient (0.2);
3127 aMat.SetSpecular (0.5);
3128 Handle(Graphic3d_AspectFillArea3d) anAspect
3129 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3131 Quantity_NOC_YELLOW,
3136 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3139 anAspect->SetEdgeOn();
3143 anAspect->SetEdgeOff();
3145 aShAsp->SetAspect (anAspect);
3146 aShape->Attributes()->SetShadingAspect (aShAsp);
3148 VDisplayAISObject (aShapeName, aShape);
3152 //=============================================================================
3153 //function : VComputeHLR
3155 //=============================================================================
3157 static int VComputeHLR (Draw_Interpretor& di,
3158 Standard_Integer argc,
3161 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3163 if (aContextAIS.IsNull ())
3165 di << "Please call vinit before\n";
3169 if ( argc != 3 && argc != 12 )
3171 di << "Usage: " << argv[0] << " ShapeName HlrName "
3172 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3173 << " ShapeName - name of the initial shape\n"
3174 << " HlrName - result hlr object from initial shape\n"
3175 << " eye, dir are eye position and look direction\n"
3176 << " up is the look up direction vector\n"
3177 << " Use vtop to see projected hlr shape\n";
3181 // shape and new object name
3182 TCollection_AsciiString aShapeName (argv[1]);
3183 TCollection_AsciiString aHlrName (argv[2]);
3185 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3188 BRep_Builder aBrepBuilder;
3189 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3192 di << "No shape with name " << argv[1] << " found\n";
3197 if (GetMapOfAIS ().IsBound2 (aHlrName))
3199 di << "Presentable object with name " << argv[2] << " already exists\n";
3203 // close local context
3204 if (aContextAIS->HasOpenedContext ())
3205 aContextAIS->CloseLocalContext ();
3207 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3208 HLRBRep_PolyHLRToShape aHLRToShape;
3217 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3218 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3219 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3220 aProjAx.SetLocation (anEye);
3221 aProjAx.SetDirection (aDir);
3222 aProjAx.SetYDirection (anUp);
3228 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3229 Handle(V3d_View) aView = ViewerTest::CurrentView();
3230 Standard_Integer aWidth, aHeight;
3231 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3232 Standard_Real aRightX, aRightY, aRightZ;
3233 aView->Window()->Size (aWidth, aHeight);
3235 aView->ConvertWithProj (aWidth, aHeight/2,
3236 aRightX, aRightY, aRightZ,
3237 aDirX, aDirY, aDirZ);
3239 aView->ConvertWithProj (aWidth/2, aHeight/2,
3240 aCentX, aCentY, aCentZ,
3241 aDirX, aDirY, aDirZ);
3243 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3244 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3245 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3246 aProjAx.SetLocation (anEye);
3247 aProjAx.SetDirection (aDir);
3248 aProjAx.SetXDirection (aRight);
3251 HLRAlgo_Projector aProjector (aProjAx);
3252 aPolyAlgo->Projector (aProjector);
3253 aPolyAlgo->Load (aSh);
3254 aPolyAlgo->Update ();
3256 aHLRToShape.Update (aPolyAlgo);
3258 // make hlr shape from input shape
3259 TopoDS_Compound aHlrShape;
3260 BRep_Builder aBuilder;
3261 aBuilder.MakeCompound (aHlrShape);
3263 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3264 if (!aCompound.IsNull ())
3266 aBuilder.Add (aHlrShape, aCompound);
3269 // extract visible outlines
3270 aCompound = aHLRToShape.OutLineVCompound();
3271 if (!aCompound.IsNull ())
3273 aBuilder.Add (aHlrShape, aCompound);
3276 // create an AIS shape and display it
3277 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3278 GetMapOfAIS().Bind (anObject, aHlrName);
3279 aContextAIS->Display (anObject);
3281 aContextAIS->UpdateCurrentViewer ();
3286 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3287 // manipulating and displaying such an array with AIS context
3289 class MyPArrayObject : public AIS_InteractiveObject
3294 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3295 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3297 myArrayDescription = theArrayDescription;
3298 myMarkerAspect = theMarkerAspect;
3301 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
3305 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3306 const Handle(Prs3d_Presentation)& aPresentation,
3307 const Standard_Integer aMode);
3309 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3310 const Standard_Integer /*theMode*/);
3312 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3313 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3314 Standard_Integer &theArgIndex,
3315 Standard_Integer theArgCount,
3316 Standard_Integer theMaxArgs);
3320 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3321 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3326 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3327 const Handle(Prs3d_Presentation)& aPresentation,
3328 const Standard_Integer /*aMode*/)
3331 // Parsing array description
3332 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3333 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3334 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3336 Standard_Integer anArgIndex = 0;
3337 Standard_Integer anArgsCount = myArrayDescription->Length();
3338 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3340 TCollection_AsciiString aCommand;
3341 while (anArgIndex < anArgsCount)
3343 aCommand = myArrayDescription->Value (anArgIndex);
3344 aCommand.LowerCase();
3347 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3349 // vertex has a normal or normal with color or texel
3350 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3351 hasNormals = Standard_True;
3353 // vertex has a color
3354 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3355 hasVColors = Standard_True;
3357 // vertex has a texel
3358 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3359 hasTexels = Standard_True;
3364 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3367 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3368 hasBColors = Standard_True;
3373 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3382 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3383 if (anArrayType == "points")
3385 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3387 else if (anArrayType == "segments")
3388 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3389 else if (anArrayType == "polylines")
3390 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3391 hasVColors, hasBColors);
3392 else if (anArrayType == "triangles")
3393 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3394 hasVColors, hasTexels);
3395 else if (anArrayType == "trianglefans")
3396 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3397 hasNormals, hasVColors,
3398 hasBColors, hasTexels);
3399 else if (anArrayType == "trianglestrips")
3400 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3401 hasNormals, hasVColors,
3402 hasBColors, hasTexels);
3403 else if (anArrayType == "quads")
3404 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3405 hasNormals, hasVColors,
3407 else if (anArrayType == "quadstrips")
3408 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3409 hasNormals, hasVColors,
3410 hasBColors, hasTexels);
3411 else if (anArrayType == "polygons")
3412 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3413 hasNormals, hasVColors, hasBColors,
3417 while (anArgIndex < anArgsCount)
3419 aCommand = myArrayDescription->Value (anArgIndex);
3420 aCommand.LowerCase();
3421 if (!aCommand.IsAscii())
3425 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3427 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3428 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3429 myArrayDescription->Value (anArgIndex - 1).RealValue());
3430 const Standard_Integer aVertIndex = anArray->VertexNumber();
3432 // vertex has a normal or normal with color or texel
3433 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3434 anArray->SetVertexNormal (aVertIndex,
3435 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3436 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3437 myArrayDescription->Value (anArgIndex - 1).RealValue());
3439 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3440 anArray->SetVertexColor (aVertIndex,
3441 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3442 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3443 myArrayDescription->Value (anArgIndex - 1).RealValue());
3445 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3446 anArray->SetVertexTexel (aVertIndex,
3447 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3448 myArrayDescription->Value (anArgIndex - 1).RealValue());
3451 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3453 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3455 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3456 anArray->AddBound (aVertCount,
3457 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3458 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3459 myArrayDescription->Value (anArgIndex - 1).RealValue());
3462 anArray->AddBound (aVertCount);
3465 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3467 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3468 anArray->AddEdge (aVertIndex);
3475 aPresentation->Clear();
3476 if (!myMarkerAspect.IsNull())
3478 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3480 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3483 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3484 const Standard_Integer /*theMode*/)
3486 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3488 Standard_Integer anArgIndex = 1;
3489 while (anArgIndex < myArrayDescription->Length())
3491 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3493 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3494 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3495 myArrayDescription->Value (anArgIndex - 1).RealValue());
3496 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3497 theSelection->Add (aSensetivePoint);
3506 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3507 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3508 Standard_Integer &theArgIndex,
3509 Standard_Integer theArgCount,
3510 Standard_Integer theMaxArgs)
3512 // check if there is more elements than expected
3513 if (theArgIndex >= theMaxArgs)
3516 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3517 aStrCommand.LowerCase();
3518 if (aStrCommand.Search(theCommand) != 1 ||
3519 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3522 // go to the first data element
3525 // check data if it can be converted to numeric
3526 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3528 aStrCommand = theArgsArray->Value (theArgIndex);
3529 if (!aStrCommand.IsRealValue())
3536 //=============================================================================
3537 //function : VDrawPArray
3538 //purpose : Draws primitives array from list of vertexes, bounds, edges
3539 //=============================================================================
3541 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3543 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3544 if (aContextAIS.IsNull())
3546 di << "Call vinit before!\n";
3551 di << "Use: " << argv[0] << " Name TypeOfArray"
3552 << " [vertex] ... [bounds] ... [edges]\n"
3553 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3554 << " trianglefans | trianglestrips | quads |\n"
3555 << " quadstrips | polygons }\n"
3556 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3557 << " [texel={ 't' tx ty }] } \n"
3558 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3559 << " edges={ 'e' vertex_id }\n";
3563 // read the arguments
3564 Standard_Integer aArgIndex = 1;
3565 TCollection_AsciiString aName (argv[aArgIndex++]);
3566 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3568 Standard_Boolean hasVertex = Standard_False;
3570 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3571 anArgsArray->SetValue (0, anArrayType);
3573 if (anArrayType != "points" &&
3574 anArrayType != "segments" &&
3575 anArrayType != "polylines" &&
3576 anArrayType != "triangles" &&
3577 anArrayType != "trianglefans" &&
3578 anArrayType != "trianglestrips" &&
3579 anArrayType != "quads" &&
3580 anArrayType != "quadstrips" &&
3581 anArrayType != "polygons")
3583 di << "Unexpected type of primitives array\n";
3587 TCollection_AsciiString aCommand;
3588 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3590 aCommand = argv[anArgIndex];
3591 aCommand.LowerCase();
3592 if (!aCommand.IsAscii())
3594 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3595 << "should be an array element: 'v', 'b', 'e' \n";
3599 if (aCommand == "v")
3601 hasVertex = Standard_True;
3604 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3609 di << "You should pass any verticies in the list of array elements\n";
3613 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3614 if (anArrayType == "points")
3616 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3619 // create primitives array object
3620 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3622 // register the object in map
3623 VDisplayAISObject (aName, aPObject);
3628 //=======================================================================
3629 //function : VSetLocation
3630 //purpose : Change location of AIS interactive object
3631 //=======================================================================
3633 static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
3634 Standard_Integer theArgNb,
3635 const char** theArgVec)
3637 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3638 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3639 if (aContext.IsNull())
3641 std::cout << "Error: no active view!\n";
3645 TCollection_AsciiString aName;
3647 Standard_Boolean isSetLoc = Standard_False;
3649 Standard_Integer anArgIter = 1;
3650 for (; anArgIter < theArgNb; ++anArgIter)
3652 Standard_CString anArg = theArgVec[anArgIter];
3653 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3657 else if (aName.IsEmpty())
3663 isSetLoc = Standard_True;
3664 if (anArgIter + 1 >= theArgNb)
3666 std::cout << "Error: syntax error at '" << anArg << "'\n";
3669 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3670 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3671 if (anArgIter + 1 < theArgNb)
3673 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3678 std::cout << "Error: unknown argument '" << anArg << "'\n";
3684 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3685 Handle(AIS_InteractiveObject) anIObj;
3686 if (aMap.IsBound2 (aName))
3688 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3690 if (anIObj.IsNull())
3692 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3697 aTrsf.SetTranslation (aLocVec);
3698 TopLoc_Location aLocation (aTrsf);
3699 aContext->SetLocation (anIObj, aLocation);
3703 //=======================================================================
3704 //function : TransformPresentation
3705 //purpose : Change transformation of AIS interactive object
3706 //=======================================================================
3707 static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3708 Standard_Integer theArgNb,
3709 const char** theArgVec)
3713 std::cout << "Error: too few arguments.\n";
3717 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3718 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3719 if (aContext.IsNull())
3721 std::cout << "Error: no active view!\n";
3726 Standard_Integer aLast = theArgNb;
3727 const char* aName = theArgVec[0];
3729 Standard_Boolean isReset = Standard_False;
3730 Standard_Boolean isMove = Standard_False;
3735 if (!strcmp (aName, "reset"))
3737 isReset = Standard_True;
3739 else if (!strcmp (aName, "move"))
3743 std::cout << "Error: too few arguments.\n";
3747 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3749 Handle(AIS_InteractiveObject) anIObj;
3750 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3752 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3755 if (anIObj.IsNull())
3757 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3761 isMove = Standard_True;
3763 aTrsf = anIObj->Transformation();
3764 aLast = theArgNb - 1;
3766 else if (!strcmp (aName, "translate"))
3770 std::cout << "Error: too few arguments.\n";
3773 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3774 Draw::Atof (theArgVec[theArgNb - 2]),
3775 Draw::Atof (theArgVec[theArgNb - 1])));
3776 aLast = theArgNb - 3;
3778 else if (!strcmp (aName, "rotate"))
3782 std::cout << "Error: too few arguments.\n";
3787 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3788 Draw::Atof (theArgVec[theArgNb - 6]),
3789 Draw::Atof (theArgVec[theArgNb - 5])),
3790 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3791 Draw::Atof (theArgVec[theArgNb - 3]),
3792 Draw::Atof (theArgVec[theArgNb - 2]))),
3793 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3795 aLast = theArgNb - 7;
3797 else if (!strcmp (aName, "mirror"))
3801 std::cout << "Error: too few arguments.\n";
3805 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3806 Draw::Atof(theArgVec[theArgNb - 5]),
3807 Draw::Atof(theArgVec[theArgNb - 4])),
3808 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3809 Draw::Atof(theArgVec[theArgNb - 2]),
3810 Draw::Atof(theArgVec[theArgNb - 1]))));
3811 aLast = theArgNb - 6;
3813 else if (!strcmp (aName, "scale"))
3817 std::cout << "Error: too few arguments.\n";
3821 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3822 Draw::Atof(theArgVec[theArgNb - 3]),
3823 Draw::Atof(theArgVec[theArgNb - 2])),
3824 Draw::Atof(theArgVec[theArgNb - 1]));
3825 aLast = theArgNb - 4;
3828 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3831 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3832 Handle(AIS_InteractiveObject) anIObj;
3833 if (aMap.IsBound2 (theArgVec[anIdx]))
3835 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3837 if (anIObj.IsNull())
3839 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3845 // aTrsf already identity
3849 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3853 aTrsf = anIObj->LocalTransformation() * aTrsf;
3856 TopLoc_Location aLocation (aTrsf);
3857 aContext->SetLocation (anIObj, aLocation);
3863 //===============================================================================================
3864 //function : VConnect
3865 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3866 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
3867 //===============================================================================================
3869 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3870 Standard_Integer argc,
3874 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3875 if (aContext.IsNull())
3877 std::cout << "vconnect error : call vinit before\n";
3878 return 1; // TCL_ERROR
3883 std::cout << "vconnect error: expect at least 5 arguments\n";
3884 return 1; // TCL_ERROR
3888 Standard_Integer anArgIter = 1;
3889 TCollection_AsciiString aName (argv[anArgIter++]);
3890 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
3891 TCollection_AsciiString aColorString (argv[argc-1]);
3892 Standard_CString aColorName = "";
3893 Standard_Boolean hasColor = Standard_False;
3894 if (aColorString.Search ("color=") != -1)
3896 hasColor = Standard_True;
3897 aColorString.Remove (1, 6);
3898 aColorName = aColorString.ToCString();
3900 Handle(AIS_InteractiveObject) anObject;
3902 // AIS_MultipleConnectedInteractive
3903 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3904 for (Standard_Integer i = 5; i < aNbShapes; ++i)
3906 TCollection_AsciiString anOriginObjectName (argv[i]);
3907 if (aName.IsEqual (anOriginObjectName))
3909 std::cout << "vconnect error: equal names for connected objects\n";
3912 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3914 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3915 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3916 if (anObject.IsNull())
3918 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3924 Standard_CString aOriginName = anOriginObjectName.ToCString();
3925 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
3926 if (aTDShape.IsNull())
3928 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3931 anObject = new AIS_Shape (aTDShape);
3932 aContext->Load (anObject);
3933 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3936 if (anOriginObject.IsNull())
3938 anOriginObject = new AIS_MultipleConnectedInteractive();
3941 anOriginObject->Connect (anObject);
3943 if (anOriginObject.IsNull())
3945 std::cout << "vconect error : can't connect input objects\n";
3946 return 1; // TCL_ERROR
3949 // Get location data
3950 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3951 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3952 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3954 // Create transformation
3955 gp_Vec aTranslation (aXo, aYo, aZo);
3958 aTrsf.SetTranslationPart (aTranslation);
3959 TopLoc_Location aLocation (aTrsf);
3961 anOriginObject->SetLocalTransformation (aTrsf);
3963 // Check if there is another object with given name
3964 // and remove it from context
3965 if(GetMapOfAIS().IsBound2(aName))
3967 Handle(AIS_InteractiveObject) anObj =
3968 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3969 TheAISContext()->Remove(anObj, Standard_False);
3970 GetMapOfAIS().UnBind2(aName);
3973 // Bind connected object to its name
3974 GetMapOfAIS().Bind (anOriginObject, aName);
3976 // Display connected object
3977 TheAISContext()->Display (anOriginObject);
3982 //===============================================================================================
3983 //function : VConnectTo
3984 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3985 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
3986 //===============================================================================================
3988 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3989 Standard_Integer argc,
3993 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3994 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3995 if (aContext.IsNull())
3997 std::cout << "vconnect error : call vinit before\n";
3998 return 1; // TCL_ERROR
4001 if (argc != 6 && argc != 7)
4003 std::cout << "vconnect error: expect at least 5 arguments\n";
4004 return 1; // TCL_ERROR
4008 Standard_Integer anArgIter = 1;
4009 TCollection_AsciiString aName (argv[anArgIter++]);
4010 Handle(AIS_InteractiveObject) anOriginObject;
4012 TCollection_AsciiString anOriginObjectName(argv[5]);
4013 if (aName.IsEqual (anOriginObjectName))
4015 std::cout << "vconnect error: equal names for connected objects\n";
4016 return 1; // TCL_ERROR
4018 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
4020 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
4021 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
4022 if (anOriginObject.IsNull())
4024 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4025 return 1; // TCL_ERROR
4030 Standard_CString aOriginName = anOriginObjectName.ToCString();
4031 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4032 if (aTDShape.IsNull())
4034 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4035 return 1; // TCL_ERROR
4037 anOriginObject = new AIS_Shape (aTDShape);
4038 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4041 // Get location data
4042 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4043 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4044 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4046 // Create transformation
4047 gp_Vec aTranslation (aXo, aYo, aZo);
4050 aTrsf.SetTranslationPart (aTranslation);
4052 Handle(AIS_ConnectedInteractive) aConnected;
4054 aConnected = new AIS_ConnectedInteractive();
4056 aConnected->Connect (anOriginObject, aTrsf);
4058 // Check if there is another object with given name
4059 // and remove it from context
4060 if(GetMapOfAIS().IsBound2(aName))
4062 Handle(AIS_InteractiveObject) anObj =
4063 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
4064 TheAISContext()->Remove(anObj, Standard_False);
4065 GetMapOfAIS().UnBind2(aName);
4068 // Bind connected object to its name
4069 GetMapOfAIS().Bind (aConnected, aName);
4073 TCollection_AsciiString anArg = argv[6];
4075 if (anArg == "-nodisplay")
4078 if (!anUpdateTool.parseRedrawMode (anArg))
4080 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4084 // Display connected object
4085 TheAISContext()->Display (aConnected, Standard_False);
4090 //=======================================================================
4091 //function : VDisconnect
4093 //=======================================================================
4094 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4095 Standard_Integer argc,
4098 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4099 if (aContext.IsNull())
4101 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4107 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
4111 TCollection_AsciiString aName (argv[1]);
4112 TCollection_AsciiString anObject (argv[2]);
4113 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4116 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4117 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4118 if (!aMap.IsBound2 (aName) )
4120 std::cout << "Use 'vdisplay' before" << "\n";
4124 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4125 if (anAssembly.IsNull())
4127 di << "Not an assembly" << "\n";
4131 Handle(AIS_InteractiveObject) anIObj;
4132 if (!aMap.IsBound2 (anObject))
4134 // try to interpret second argument as child number
4135 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4137 Standard_Integer aCounter = 1;
4138 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4140 if (aCounter == anObjectNumber)
4142 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4150 std::cout << "Use 'vdisplay' before" << "\n";
4155 // if object was found by name
4156 if (anIObj.IsNull())
4158 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4161 aContext->Disconnect (anAssembly, anIObj);
4162 aContext->UpdateCurrentViewer();
4167 //=======================================================================
4168 //function : VAddConnected
4170 //=======================================================================
4171 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4172 Standard_Integer argc,
4175 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4176 if (aContext.IsNull())
4178 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4184 std::cout << argv[0] << " error: expect 5 arguments\n";
4188 TCollection_AsciiString aName (argv[1]);
4189 TCollection_AsciiString anObject (argv[5]);
4190 Standard_Real aX = Draw::Atof (argv[2]);
4191 Standard_Real aY = Draw::Atof (argv[3]);
4192 Standard_Real aZ = Draw::Atof (argv[4]);
4195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4196 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4197 if (!aMap.IsBound2 (aName) )
4199 std::cout << "Use 'vdisplay' before" << "\n";
4203 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4204 if (anAssembly.IsNull())
4206 di << "Not an assembly" << "\n";
4210 Handle(AIS_InteractiveObject) anIObj;
4211 if (!aMap.IsBound2 (anObject))
4213 std::cout << "Use 'vdisplay' before" << "\n";
4217 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4220 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4222 anAssembly->Connect (anIObj, aTrsf);
4223 TheAISContext()->Display (anAssembly);
4224 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4225 aContext->UpdateCurrentViewer();
4230 //=======================================================================
4231 //function : VListConnected
4233 //=======================================================================
4234 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4235 Standard_Integer argc,
4238 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4239 if (aContext.IsNull())
4241 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4247 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
4251 TCollection_AsciiString aName (argv[1]);
4254 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4255 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4256 if (!aMap.IsBound2 (aName) )
4258 std::cout << "Use 'vdisplay' before" << "\n";
4262 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4263 if (anAssembly.IsNull())
4265 std::cout << "Not an assembly" << "\n";
4269 std::cout << "Children of " << aName << ":\n";
4271 Standard_Integer aCounter = 1;
4272 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4274 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4276 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anIter.Value());
4277 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4280 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4282 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4283 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4285 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4287 std::cout << std::endl;
4297 //! Checks if theMode is already turned on for theObj.
4298 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4299 const Handle(AIS_InteractiveObject)& theObj,
4300 const Standard_Integer theMode)
4302 TColStd_ListOfInteger anActiveModes;
4303 theAISContext->ActivatedModes (theObj, anActiveModes);
4304 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4306 if (aModeIt.Value() == theMode)
4308 return Standard_True;
4311 return Standard_False;
4315 //===============================================================================================
4316 //function : VSetSelectionMode
4317 //purpose : Sets input selection mode for input object or for all displayed objects
4318 //Draw arg : vselmode [object] mode On/Off (1/0)
4319 //===============================================================================================
4320 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4321 Standard_Integer theArgc,
4322 const char** theArgv)
4325 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4326 if (anAISContext.IsNull())
4328 std::cerr << "Call vinit before!" << std::endl;
4332 // Check the arguments
4333 if (theArgc < 3 && theArgc > 5)
4335 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4336 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
4340 TCollection_AsciiString aLastArg (theArgv[theArgc - 1]);
4341 aLastArg.LowerCase();
4342 Standard_Boolean isToOpenLocalCtx = aLastArg == "-local";
4344 // get objects to change selection mode
4345 AIS_ListOfInteractive aTargetIOs;
4346 Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc;
4349 anAISContext->DisplayedObjects (aTargetIOs);
4353 // Check if there is an object with given name in context
4354 const TCollection_AsciiString aNameIO (theArgv[1]);
4355 if (GetMapOfAIS().IsBound2 (aNameIO))
4357 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4360 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
4363 aTargetIOs.Append (anIO);
4367 const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]);
4368 const Standard_Boolean toTurnOn = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]);
4369 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4371 anAISContext->CloseLocalContext();
4374 if (aSelectionMode == 0)
4378 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4380 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4381 TColStd_ListOfInteger anActiveModes;
4382 anAISContext->ActivatedModes (anIO, anActiveModes);
4383 if (!anActiveModes.IsEmpty())
4385 anAISContext->Deactivate (anIO);
4387 if (!InList (anAISContext, anIO, aSelectionMode))
4389 anAISContext->Activate (anIO);
4395 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4397 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4398 if (InList (anAISContext, anIO, aSelectionMode))
4400 anAISContext->Deactivate (anIO);
4406 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
4408 if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx)
4410 anAISContext->OpenLocalContext (Standard_False);
4413 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4415 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4416 if (InList (anAISContext, anIO, 0))
4418 anAISContext->Deactivate (anIO, 0);
4420 if (!InList (anAISContext, anIO, aSelectionMode))
4422 anAISContext->Load (anIO, -1, Standard_True);
4423 anAISContext->Activate (anIO, aSelectionMode);
4428 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4430 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4432 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4433 if (InList (anAISContext, anIO, aSelectionMode))
4435 anAISContext->Deactivate (anIO, aSelectionMode);
4443 //===============================================================================================
4444 //function : VSelectionNext
4446 //===============================================================================================
4447 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4448 Standard_Integer /*theArgsNb*/,
4449 const char** /*theArgVec*/)
4452 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4453 Handle(V3d_View) aView = ViewerTest::CurrentView();
4455 if (anAISContext.IsNull())
4457 std::cerr << "Call vinit before!" << std::endl;
4461 anAISContext->HilightNextDetected(aView);
4465 //===============================================================================================
4466 //function : VSelectionPrevious
4468 //===============================================================================================
4469 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4470 Standard_Integer /*theArgsNb*/,
4471 const char** /*theArgVec*/)
4474 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4475 Handle(V3d_View) aView = ViewerTest::CurrentView();
4477 if (anAISContext.IsNull())
4479 std::cerr << "Call vinit before!" << std::endl;
4483 anAISContext->HilightPreviousDetected(aView);
4488 //==========================================================================
4490 //purpose : creates Triangle based on AIS_InteractiveObject.
4491 // This class was implemented for testing Select3D_SensitiveTriangle
4492 //===========================================================================
4494 class Triangle: public AIS_InteractiveObject
4498 DEFINE_STANDARD_RTTI(Triangle, AIS_InteractiveObject);
4499 Triangle (const gp_Pnt& theP1,
4500 const gp_Pnt& theP2,
4501 const gp_Pnt& theP3);
4503 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4504 const Handle(Prs3d_Presentation)& thePresentation,
4505 const Standard_Integer theMode);
4507 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4508 const Standard_Integer theMode);
4516 Triangle::Triangle (const gp_Pnt& theP1,
4517 const gp_Pnt& theP2,
4518 const gp_Pnt& theP3)
4525 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4526 const Handle(Prs3d_Presentation)& thePresentation,
4527 const Standard_Integer /*theMode*/)
4529 thePresentation->Clear();
4531 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4532 anEdgeMaker2(myPoint2, myPoint3),
4533 anEdgeMaker3(myPoint3, myPoint1);
4535 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4536 anEdge2 = anEdgeMaker2.Edge(),
4537 anEdge3 = anEdgeMaker3.Edge();
4538 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4541 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4542 TopoDS_Wire aWire = aWireMaker.Wire();
4543 if(aWire.IsNull()) return;
4545 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4546 TopoDS_Face aFace = aFaceMaker.Face();
4547 if(aFace.IsNull()) return;
4549 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4552 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
4553 const Standard_Integer /*theMode*/)
4555 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4556 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4557 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4558 theSelection->Add(aSensTriangle);
4561 //===========================================================================
4562 //function : VTriangle
4563 //Draw arg : vtriangle Name PointName PointName PointName
4564 //purpose : creates and displays Triangle
4565 //===========================================================================
4568 //purpose : checks if the object with theName is AIS_Point,
4569 // if yes initialize thePoint from MapOfAIS
4570 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4571 Handle(AIS_Point)& thePoint)
4573 Handle(AIS_InteractiveObject) anObject =
4574 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4575 if(anObject.IsNull() ||
4576 anObject->Type() != AIS_KOI_Datum ||
4577 anObject->Signature() != 1)
4579 return Standard_False;
4581 thePoint = Handle(AIS_Point)::DownCast(anObject);
4582 if(thePoint.IsNull())
4583 return Standard_False;
4584 return Standard_True;
4588 //purpose: checks if thePoint1 is equal to thePoint2
4589 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4590 const Handle(Geom_CartesianPoint)& thePoint2)
4592 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4593 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4594 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4596 return Standard_True;
4598 return Standard_False;
4601 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4602 Standard_Integer argc,
4608 std::cout<<"vtriangle error: expects 4 argumnets\n";
4609 return 1; // TCL_ERROR
4612 TheAISContext()->CloseAllContexts();
4614 // Get and check values
4615 TCollection_AsciiString aName(argv[1]);
4617 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4618 if (!IsPoint(argv[2], aPoint1))
4620 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4621 return 1; // TCL_ERROR
4623 if (!IsPoint(argv[3], aPoint2))
4625 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4626 return 1; // TCL_ERROR
4628 if (!IsPoint(argv[4], aPoint3))
4630 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4631 return 1; // TCL_ERROR
4634 // Check that points are different
4635 Handle(Geom_CartesianPoint) aCartPoint1 =
4636 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4637 Handle(Geom_CartesianPoint) aCartPoint2 =
4638 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4639 // Test aPoint1 = aPoint2
4640 if (IsMatch(aCartPoint1, aCartPoint2))
4642 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4643 return 1; // TCL_ERROR
4645 // Test aPoint2 = aPoint3
4646 Handle(Geom_CartesianPoint) aCartPoint3 =
4647 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4648 if (IsMatch(aCartPoint2, aCartPoint3))
4650 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4651 return 1; // TCL_ERROR
4653 // Test aPoint3 = aPoint1
4654 if (IsMatch(aCartPoint1, aCartPoint3))
4656 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4657 return 1; // TCL_ERROR
4661 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4663 aCartPoint3->Pnt());
4665 // Check if there is an object with given name
4666 // and remove it from context
4667 if (GetMapOfAIS().IsBound2(aName))
4669 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4670 Handle(AIS_InteractiveObject) anInterObj =
4671 Handle(AIS_InteractiveObject)::DownCast(anObj);
4672 TheAISContext()->Remove(anInterObj, Standard_False);
4673 GetMapOfAIS().UnBind2(aName);
4676 // Bind triangle to its name
4677 GetMapOfAIS().Bind(aTriangle, aName);
4680 TheAISContext()->Display(aTriangle);
4684 //class : SegmentObject
4685 //purpose: creates segment based on AIS_InteractiveObject.
4686 // This class was implemented for testing Select3D_SensitiveCurve
4688 class SegmentObject: public AIS_InteractiveObject
4692 DEFINE_STANDARD_RTTI(SegmentObject, AIS_InteractiveObject);
4693 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4695 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4696 const Handle(Prs3d_Presentation)& thePresentation,
4697 const Standard_Integer theMode);
4699 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4700 const Standard_Integer theMode);
4707 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4713 void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4714 const Handle(Prs3d_Presentation) &thePresentation,
4715 const Standard_Integer /*theMode*/)
4717 thePresentation->Clear();
4718 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4719 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4720 if (anEdge.IsNull())
4722 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4723 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4726 void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
4727 const Standard_Integer /*theMode*/)
4729 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4730 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4731 anArray->SetValue(1, myPoint1);
4732 anArray->SetValue(2, myPoint2);
4733 Handle(Select3D_SensitiveCurve) aSensCurve =
4734 new Select3D_SensitiveCurve(anOwner, anArray);
4735 theSelection->Add(aSensCurve);
4738 //=======================================================================
4739 //function : VSegment
4740 //Draw args : vsegment Name PointName PointName
4741 //purpose : creates and displays Segment
4742 //=======================================================================
4743 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4744 Standard_Integer argc,
4750 std::cout<<"vsegment error: expects 3 arguments\n";
4751 return 1; // TCL_ERROR
4754 TheAISContext()->CloseAllContexts();
4756 // Get and check arguments
4757 TCollection_AsciiString aName(argv[1]);
4758 Handle(AIS_Point) aPoint1, aPoint2;
4759 if (!IsPoint(argv[2], aPoint1))
4761 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4762 return 1; // TCL_ERROR
4764 if (!IsPoint(argv[3], aPoint2))
4766 std::cout<<"vsegment error: the 3d argument should be a point\n";
4767 return 1; // TCL_ERROR
4769 //Check that points are different
4770 Handle(Geom_CartesianPoint) aCartPoint1 =
4771 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4772 Handle(Geom_CartesianPoint) aCartPoint2 =
4773 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4774 if(IsMatch(aCartPoint1, aCartPoint2))
4776 std::cout<<"vsegment error: equal points\n";
4777 return 1; // TCL_ERROR
4781 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4782 // Check if there is an object with given name
4783 // and remove it from context
4784 if (GetMapOfAIS().IsBound2(aName))
4786 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4787 Handle(AIS_InteractiveObject) anInterObj =
4788 Handle(AIS_InteractiveObject)::DownCast(anObj);
4789 TheAISContext()->Remove(anInterObj, Standard_False);
4790 GetMapOfAIS().UnBind2(aName);
4793 // Bind segment to its name
4794 GetMapOfAIS().Bind(aSegment, aName);
4797 TheAISContext()->Display(aSegment);
4801 //=======================================================================
4802 //function : VObjZLayer
4803 //purpose : Set or get z layer id for presentable object
4804 //=======================================================================
4806 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4807 Standard_Integer argc,
4810 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4811 if (aContext.IsNull())
4813 di << argv[0] << "Call 'vinit' before!\n";
4818 TCollection_AsciiString aOperation;
4820 aOperation = TCollection_AsciiString (argv [1]);
4822 // check for correct arguments
4823 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4824 !(argc == 3 && aOperation.IsEqual ("get")))
4826 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4827 di << " set - set layer id for interactive object, layerid - z layer id\n";
4828 di << " get - get layer id of interactive object\n";
4829 di << " argument layerid should be passed for set operation only\n";
4834 TCollection_AsciiString aName (argv[2]);
4835 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4836 if (!aMap.IsBound2 (aName))
4838 di << "Use 'vdisplay' before" << "\n";
4842 // find interactive object
4843 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4844 Handle(AIS_InteractiveObject) anInterObj =
4845 Handle(AIS_InteractiveObject)::DownCast (anObj);
4846 if (anInterObj.IsNull())
4848 di << "Not an AIS interactive object!\n";
4852 // process operation
4853 if (aOperation.IsEqual ("set"))
4855 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4856 aContext->SetZLayer (anInterObj, aLayerId);
4858 else if (aOperation.IsEqual ("get"))
4860 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4866 //=======================================================================
4867 //function : VPolygonOffset
4868 //purpose : Set or get polygon offset parameters
4869 //=======================================================================
4870 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4871 Standard_Integer argc,
4874 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4875 if (aContext.IsNull())
4877 std::cout << argv[0] << " Call 'vinit' before!\n";
4881 if (argc > 2 && argc != 5)
4883 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4884 "without arguments prints the default values" << std::endl;
4889 Handle(AIS_InteractiveObject) anInterObj;
4892 TCollection_AsciiString aName (argv[1]);
4893 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4894 if (!aMap.IsBound2 (aName))
4896 std::cout << "Use 'vdisplay' before" << std::endl;
4900 // find interactive object
4901 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4902 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4903 if (anInterObj.IsNull())
4905 std::cout << "Not an AIS interactive object!" << std::endl;
4910 Standard_Integer aMode;
4911 Standard_ShortReal aFactor, aUnits;
4914 aMode = Draw::Atoi(argv[2]);
4915 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4916 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4918 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4919 aContext->UpdateCurrentViewer();
4924 if (anInterObj->HasPolygonOffsets())
4926 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4927 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4928 std::cout << "\tMode: " << aMode << std::endl;
4929 std::cout << "\tFactor: " << aFactor << std::endl;
4930 std::cout << "\tUnits: " << aUnits << std::endl;
4935 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4939 std::cout << "Default polygon offset parameters:" << std::endl;
4940 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4941 std::cout << "\tMode: " << aMode << std::endl;
4942 std::cout << "\tFactor: " << aFactor << std::endl;
4943 std::cout << "\tUnits: " << aUnits << std::endl;
4948 //=======================================================================
4949 //function : VShowFaceBoundaries
4950 //purpose : Set face boundaries drawing on/off for ais object
4951 //=======================================================================
4952 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4953 Standard_Integer argc,
4956 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4957 if (aContext.IsNull ())
4959 std::cout << argv[0] << " Call 'vinit' before!\n";
4963 if ((argc != 3 && argc < 6) || argc > 8)
4965 std::cout << "Usage :\n " << argv[0]
4966 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4967 << " ObjectName - name of AIS interactive object. \n"
4968 << " if ObjectName = \"\", then set as default\n"
4969 << " settings for all newly displayed objects\n"
4970 << " isOn - flag indicating whether the boundaries\n"
4971 << " should be turned on or off (can be set\n"
4972 << " to 0 (off) or 1 (on)).\n"
4973 << " R, G, B - red, green and blue components of boundary\n"
4974 << " color in range (0 - 255).\n"
4975 << " (default is (0, 0, 0)\n"
4976 << " LineWidth - line width\n"
4977 << " (default is 1)\n"
4978 << " LineStyle - line fill style :\n"
4983 << " (default is solid)";
4987 TCollection_AsciiString aName (argv[1]);
4989 Quantity_Parameter aRed = 0.0;
4990 Quantity_Parameter aGreen = 0.0;
4991 Quantity_Parameter aBlue = 0.0;
4992 Standard_Real aWidth = 1.0;
4993 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4996 Handle(AIS_InteractiveObject) anInterObj;
4998 // if name is empty - apply attributes for default aspect
4999 if (!aName.IsEmpty ())
5001 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
5002 if (!aMap.IsBound2 (aName))
5004 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
5008 // find interactive object
5009 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
5010 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
5011 if (anInterObj.IsNull ())
5013 std::cout << "Not an AIS interactive object!" << std::endl;
5018 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
5019 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
5021 // turn boundaries on/off
5022 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
5023 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
5025 // set boundary line color
5029 aRed = Draw::Atof (argv[3])/255.;
5030 aGreen = Draw::Atof (argv[4])/255.;
5031 aBlue = Draw::Atof (argv[5])/255.;
5037 aWidth = (Standard_Real)Draw::Atof (argv[6]);
5040 // select appropriate line type
5043 switch (Draw::Atoi (argv[7]))
5045 case 1: aLineType = Aspect_TOL_DASH; break;
5046 case 2: aLineType = Aspect_TOL_DOT; break;
5047 case 3: aLineType = Aspect_TOL_DOTDASH; break;
5049 aLineType = Aspect_TOL_SOLID;
5053 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
5055 Handle(Prs3d_LineAspect) aBoundaryAspect =
5056 new Prs3d_LineAspect (aColor, aLineType, aWidth);
5058 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
5060 TheAISContext()->Redisplay (anInterObj);
5065 // This class is used for testing markers.
5067 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5072 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5073 const Standard_Integer& thePointsOnSide,
5074 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5076 myStartPoint = theStartPoint;
5077 myPointsOnSide = thePointsOnSide;
5078 myMarkerAspect = theMarkerAspect;
5081 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
5085 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5086 const Handle(Prs3d_Presentation)& aPresentation,
5087 const Standard_Integer aMode);
5089 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5090 const Standard_Integer /*theMode*/);
5094 gp_XYZ myStartPoint;
5095 Standard_Integer myPointsOnSide;
5096 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5100 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5101 const Handle(Prs3d_Presentation)& aPresentation,
5102 const Standard_Integer /*aMode*/)
5104 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5105 if (myPointsOnSide == 1)
5107 anArray->AddVertex (myStartPoint);
5111 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5113 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5115 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5117 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5118 anArray->SetVertexColor (anArray->VertexNumber(),
5121 k / myPointsOnSide);
5127 aPresentation->Clear();
5128 if (!myMarkerAspect.IsNull())
5130 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5132 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5135 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5136 const Standard_Integer /*theMode*/)
5138 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5140 if (myPointsOnSide == 1)
5142 gp_Pnt aPoint (myStartPoint);
5143 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5144 theSelection->Add (aSensetivePoint);
5148 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5150 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5152 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5154 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5155 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5156 theSelection->Add (aSensetivePoint);
5162 //=======================================================================
5163 //function : VMarkersTest
5164 //purpose : Draws an array of markers for testing purposes.
5165 //=======================================================================
5166 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5167 Standard_Integer theArgNb,
5168 const char** theArgVec)
5170 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5171 if (aContext.IsNull())
5173 std::cerr << "Call 'vinit' before!\n";
5179 std::cerr << "Usage :\n " << theArgVec[0]
5180 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5184 Standard_Integer anArgIter = 1;
5186 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5187 TCollection_AsciiString aFileName;
5188 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5189 Atof (theArgVec[anArgIter + 1]),
5190 Atof (theArgVec[anArgIter + 2]));
5193 Standard_Integer aPointsOnSide = 10;
5194 Standard_Integer aMarkerType = -1;
5195 Standard_Real aScale = 1.0;
5196 for (; anArgIter < theArgNb; ++anArgIter)
5198 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5199 if (anArg.Search ("PointsOnSide=") > -1)
5201 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5203 else if (anArg.Search ("MarkerType=") > -1)
5205 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5207 else if (anArg.Search ("Scale=") > -1)
5209 aScale = anArg.Token ("=", 2).RealValue();
5211 else if (anArg.Search ("FileName=") > -1)
5213 aFileName = anArg.Token ("=", 2);
5217 std::cerr << "Wrong argument: " << anArg << "\n";
5222 Handle(Graphic3d_AspectMarker3d) anAspect;
5223 Handle(Image_AlienPixMap) anImage;
5224 Quantity_Color aColor (Quantity_NOC_GREEN1);
5225 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5226 && !aFileName.IsEmpty())
5228 anImage = new Image_AlienPixMap();
5229 if (!anImage->Load (aFileName))
5231 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5234 if (anImage->Format() == Image_PixMap::ImgGray)
5236 anImage->SetFormat (Image_PixMap::ImgAlpha);
5238 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5240 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5242 anAspect = new Graphic3d_AspectMarker3d (anImage);
5246 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5249 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5250 VDisplayAISObject (aName, aMarkersArray);
5255 //! Auxiliary function to parse font aspect style argument
5256 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5257 Font_FontAspect& theAspect)
5259 if (theArg == "regular"
5260 || *theArg.ToCString() == 'r')
5262 theAspect = Font_FA_Regular;
5263 return Standard_True;
5265 else if (theArg == "bolditalic")
5267 theAspect = Font_FA_BoldItalic;
5268 return Standard_True;
5270 else if (theArg == "bold"
5271 || *theArg.ToCString() == 'b')
5273 theAspect = Font_FA_Bold;
5274 return Standard_True;
5276 else if (theArg == "italic"
5277 || *theArg.ToCString() == 'i')
5279 theAspect = Font_FA_Italic;
5280 return Standard_True;
5282 return Standard_False;
5285 //! Auxiliary function
5286 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5290 case Font_FA_Regular: return "regular";
5291 case Font_FA_BoldItalic: return "bolditalic";
5292 case Font_FA_Bold: return "bold";
5293 case Font_FA_Italic: return "italic";
5294 default: return "undefined";
5298 //=======================================================================
5299 //function : TextToBrep
5300 //purpose : Tool for conversion text to occt-shapes
5301 //=======================================================================
5302 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5303 Standard_Integer theArgNb,
5304 const char** theArgVec)
5309 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5313 Standard_Integer anArgIt = 1;
5314 Standard_CString aName = theArgVec[anArgIt++];
5315 Standard_CString aText = theArgVec[anArgIt++];
5317 Font_BRepFont aFont;
5318 TCollection_AsciiString aFontName ("Courier");
5319 Standard_Real aTextHeight = 16.0;
5320 Font_FontAspect aFontAspect = Font_FA_Regular;
5321 Standard_Boolean anIsCompositeCurve = Standard_False;
5322 gp_Ax3 aPenAx3 (gp::XOY());
5323 gp_Dir aNormal (0.0, 0.0, 1.0);
5324 gp_Dir aDirection (1.0, 0.0, 0.0);
5327 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5328 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5330 for (; anArgIt < theArgNb; ++anArgIt)
5332 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5335 if (aParam == "-pos"
5336 || aParam == "-position")
5338 if (anArgIt + 3 >= theArgNb)
5340 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5344 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5345 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5346 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5348 else if (aParam == "-halign")
5350 if (++anArgIt >= theArgNb)
5352 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5356 TCollection_AsciiString aType (theArgVec[anArgIt]);
5358 if (aType == "left")
5360 aHJustification = Graphic3d_HTA_LEFT;
5362 else if (aType == "center")
5364 aHJustification = Graphic3d_HTA_CENTER;
5366 else if (aType == "right")
5368 aHJustification = Graphic3d_HTA_RIGHT;
5372 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5376 else if (aParam == "-valign")
5378 if (++anArgIt >= theArgNb)
5380 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5384 TCollection_AsciiString aType (theArgVec[anArgIt]);
5388 aVJustification = Graphic3d_VTA_TOP;
5390 else if (aType == "center")
5392 aVJustification = Graphic3d_VTA_CENTER;
5394 else if (aType == "bottom")
5396 aVJustification = Graphic3d_VTA_BOTTOM;
5398 else if (aType == "topfirstline")
5400 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5404 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5408 else if (aParam == "-height")
5410 if (++anArgIt >= theArgNb)
5412 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5416 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5418 else if (aParam == "-aspect")
5420 if (++anArgIt >= theArgNb)
5422 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5426 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5427 anOption.LowerCase();
5429 if (anOption.IsEqual ("regular"))
5431 aFontAspect = Font_FA_Regular;
5433 else if (anOption.IsEqual ("bold"))
5435 aFontAspect = Font_FA_Bold;
5437 else if (anOption.IsEqual ("italic"))
5439 aFontAspect = Font_FA_Italic;
5441 else if (anOption.IsEqual ("bolditalic"))
5443 aFontAspect = Font_FA_BoldItalic;
5447 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5451 else if (aParam == "-font")
5453 if (++anArgIt >= theArgNb)
5455 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5459 aFontName = theArgVec[anArgIt];
5461 else if (aParam == "-composite")
5463 if (++anArgIt >= theArgNb)
5465 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5469 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5471 else if (aParam == "-plane")
5473 if (anArgIt + 6 >= theArgNb)
5475 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5479 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5480 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5481 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5482 aNormal.SetCoord (aX, aY, aZ);
5484 aX = Draw::Atof (theArgVec[++anArgIt]);
5485 aY = Draw::Atof (theArgVec[++anArgIt]);
5486 aZ = Draw::Atof (theArgVec[++anArgIt]);
5487 aDirection.SetCoord (aX, aY, aZ);
5491 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5495 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5496 if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
5498 std::cerr << "Font initialization error\n";
5502 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5504 Font_BRepTextBuilder aBuilder;
5505 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5509 //=======================================================================
5511 //purpose : Font management
5512 //=======================================================================
5514 static int VFont (Draw_Interpretor& theDI,
5515 Standard_Integer theArgNb,
5516 const char** theArgVec)
5518 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5521 // just print the list of available fonts
5522 Standard_Boolean isFirst = Standard_True;
5523 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5524 anIter.More(); anIter.Next())
5526 const Handle(Font_SystemFont)& aFont = anIter.Value();
5532 theDI << aFont->FontName()->String()
5533 << " " << fontStyleString (aFont->FontAspect())
5534 << " " << aFont->FontPath()->String();
5535 isFirst = Standard_False;
5540 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5542 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5543 TCollection_AsciiString anArgCase (anArg);
5544 anArgCase.LowerCase();
5545 if (anArgCase == "find")
5547 if (++anArgIter >= theArgNb)
5549 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5553 Standard_CString aFontName = theArgVec[anArgIter];
5554 Font_FontAspect aFontAspect = Font_FA_Undefined;
5555 if (++anArgIter < theArgNb)
5557 anArgCase = theArgVec[anArgIter];
5558 anArgCase.LowerCase();
5559 if (!parseFontStyle (anArgCase, aFontAspect))
5564 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5567 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5571 theDI << aFont->FontName()->String()
5572 << " " << fontStyleString (aFont->FontAspect())
5573 << " " << aFont->FontPath()->String();
5575 else if (anArgCase == "add"
5576 || anArgCase == "register")
5578 if (++anArgIter >= theArgNb)
5580 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5583 Standard_CString aFontPath = theArgVec[anArgIter];
5584 Standard_CString aFontName = NULL;
5585 Font_FontAspect aFontAspect = Font_FA_Undefined;
5586 if (++anArgIter < theArgNb)
5588 if (!parseFontStyle (anArgCase, aFontAspect))
5590 aFontName = theArgVec[anArgIter];
5592 if (++anArgIter < theArgNb)
5594 anArgCase = theArgVec[anArgIter];
5595 anArgCase.LowerCase();
5596 if (!parseFontStyle (anArgCase, aFontAspect))
5603 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5606 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5610 if (aFontAspect != Font_FA_Undefined
5611 || aFontName != NULL)
5613 if (aFontAspect == Font_FA_Undefined)
5615 aFontAspect = aFont->FontAspect();
5617 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5618 if (aFontName != NULL)
5620 aName = new TCollection_HAsciiString (aFontName);
5622 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5625 aMgr->RegisterFont (aFont, Standard_True);
5626 theDI << aFont->FontName()->String()
5627 << " " << fontStyleString (aFont->FontAspect())
5628 << " " << aFont->FontPath()->String();
5632 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5639 //=======================================================================
5640 //function : VSetEdgeType
5641 //purpose : Edges type management
5642 //=======================================================================
5644 static int VSetEdgeType (Draw_Interpretor& theDI,
5645 Standard_Integer theArgNum,
5646 const char** theArgs)
5648 if (theArgNum < 4 || theArgNum > 9)
5650 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5651 << theArgs[0] << "' for more information.\n";
5655 Standard_Boolean isForceRedisplay = Standard_False;
5658 TCollection_AsciiString aName(theArgs[1]);
5659 if (!GetMapOfAIS().IsBound2 (aName))
5661 theDI << theArgs[0] << " error: wrong object name.\n";
5665 Handle(AIS_InteractiveObject) anObject =
5666 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5668 // Enable trianle edge mode
5669 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5672 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5674 TCollection_AsciiString aParam ((theArgs[anIt]));
5675 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5677 if (aParam.IsEqual ("-type"))
5679 if (theArgNum <= anIt + 1)
5681 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5682 << aParam.ToCString() << "'.\n";
5686 TCollection_AsciiString aType = theArgs[++anIt];
5689 if (aType.IsEqual ("SOLID"))
5691 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5693 else if (aType.IsEqual ("DASH"))
5695 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5697 else if (aType.IsEqual ("DOT"))
5699 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5701 else if (aType.IsEqual ("DOTDASH"))
5703 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5707 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5712 else if (aParam.IsEqual ("-color"))
5714 if (theArgNum <= anIt + 3)
5716 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5717 << aParam.ToCString() << "'.\n";
5721 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5722 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5723 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5724 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5725 aG > 1 ? aG / 255.0 : aG,
5726 aB > 1 ? aB / 255.0 : aB,
5729 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5731 else if (aParam.IsEqual ("-force"))
5733 isForceRedisplay = Standard_True;
5737 theDI << theArgs[0] << " error: unknown parameter '"
5738 << aParam.ToCString() << "'.\n";
5744 // Update shape presentation as aspect parameters were changed
5745 if (isForceRedisplay)
5747 ViewerTest::GetAISContext()->Redisplay (anObject);
5751 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5755 ViewerTest::CurrentView()->Redraw();
5760 //=======================================================================
5761 //function : VUnsetEdgeType
5762 //purpose : Unsets edges visibility in shading mode
5763 //=======================================================================
5765 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5766 Standard_Integer theArgNum,
5767 const char** theArgs)
5769 if (theArgNum != 2 && theArgNum != 3)
5771 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5772 << theArgs[0] << "' for more information.\n";
5776 Standard_Boolean isForceRedisplay = Standard_False;
5779 TCollection_AsciiString aName (theArgs[1]);
5780 if (!GetMapOfAIS().IsBound2 (aName))
5782 theDI << theArgs[0] << " error: wrong object name.\n";
5786 Handle(AIS_InteractiveObject) anObject =
5787 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5789 // Enable trianle edge mode
5790 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5795 TCollection_AsciiString aParam ((theArgs[2]));
5796 if (aParam.IsEqual ("-force"))
5798 isForceRedisplay = Standard_True;
5802 theDI << theArgs[0] << " error: unknown parameter '"
5803 << aParam.ToCString() << "'.\n";
5808 // Update shape presentation as aspect parameters were changed
5809 if (isForceRedisplay)
5811 ViewerTest::GetAISContext()->Redisplay (anObject);
5815 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5819 ViewerTest::CurrentView()->Redraw();
5825 //=======================================================================
5826 //function : VVertexMode
5827 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5828 //=======================================================================
5830 static int VVertexMode (Draw_Interpretor& theDI,
5831 Standard_Integer theArgNum,
5832 const char** theArgs)
5834 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5835 if (aContext.IsNull())
5837 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5841 // No arguments --> print the current default vertex draw mode
5844 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5845 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5849 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5850 TCollection_AsciiString aParam (theArgs[1]);
5851 if (aParam == "-set")
5855 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5856 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5860 TCollection_AsciiString aModeStr (theArgs[2]);
5861 Prs3d_VertexDrawMode aNewMode =
5862 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5863 (aModeStr == "all" ? Prs3d_VDM_All :
5864 Prs3d_VDM_Inherited);
5866 Standard_Boolean aRedrawNeeded = Standard_False;
5867 AIS_ListOfInteractive anObjs;
5869 // No object(s) specified -> use all displayed
5872 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5873 aContext->DisplayedObjects (anObjs);
5874 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5875 aRedrawNeeded = Standard_True;
5878 Handle(AIS_InteractiveObject) anObject;
5879 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5881 TCollection_AsciiString aName (theArgs[aCount]);
5882 if (!GetMapOfAIS().IsBound2 (aName))
5884 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5887 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5888 anObjs.Append (anObject);
5891 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5893 anObject = anIt.Value();
5894 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5895 aContext->Redisplay (anObject, Standard_False);
5896 aRedrawNeeded = Standard_True;
5900 ViewerTest::CurrentView()->Redraw();
5907 std::cout << "Error: invalid number of arguments" << std::endl;
5908 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5912 // One argument (object name) --> print the current vertex draw mode for the object
5913 Handle(AIS_InteractiveObject) anObject =
5914 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5915 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5916 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5920 //=======================================================================
5921 //function : VPointCloud
5922 //purpose : Create interactive object for arbitary set of points.
5923 //=======================================================================
5924 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5925 Standard_Integer theArgNum,
5926 const char** theArgs)
5928 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5929 if (anAISContext.IsNull())
5931 std::cerr << "Error: no active view!\n";
5935 // command to execute
5938 CloudForShape, // generate point cloud for shape
5939 CloudSphere, // generate point cloud for generic sphere
5943 // count number of non-optional command arguments
5944 Command aCmd = Unknow;
5945 Standard_Integer aCmdArgs = 0;
5946 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5948 Standard_CString anArg = theArgs[anArgIter];
5949 TCollection_AsciiString aFlag (anArg);
5951 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5958 case 2 : aCmd = CloudForShape; break;
5959 case 7 : aCmd = CloudSphere; break;
5961 std::cout << "Error: wrong number of arguments! See usage:\n";
5962 theDI.PrintHelp (theArgs[0]);
5967 Standard_Boolean toRandColors = Standard_False;
5968 Standard_Boolean hasNormals = Standard_True;
5969 Standard_Boolean isSetArgNorm = Standard_False;
5970 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5972 Standard_CString anArg = theArgs[anArgIter];
5973 TCollection_AsciiString aFlag (anArg);
5975 if (aFlag == "-randcolors"
5976 || aFlag == "-randcolor")
5978 if (isSetArgNorm && hasNormals)
5980 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5983 toRandColors = Standard_True;
5984 hasNormals = Standard_False;
5986 else if (aFlag == "-normals"
5987 || aFlag == "-normal")
5991 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5994 isSetArgNorm = Standard_True;
5995 hasNormals = Standard_True;
5997 else if (aFlag == "-nonormals"
5998 || aFlag == "-nonormal")
6000 isSetArgNorm = Standard_True;
6001 hasNormals = Standard_False;
6005 Standard_CString aName = theArgs[1];
6007 // generate arbitrary set of points
6008 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
6009 if (aCmd == CloudForShape)
6011 Standard_CString aShapeName = theArgs[2];
6012 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6014 if (aShape.IsNull())
6016 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
6020 // calculate number of points
6021 TopLoc_Location aLocation;
6022 Standard_Integer aNbPoints = 0;
6023 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6025 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6026 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6027 if (!aTriangulation.IsNull())
6029 aNbPoints += aTriangulation->NbNodes();
6034 std::cout << "Error: shape should be triangulated!\n";
6038 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
6039 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6041 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6042 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6043 if (aTriangulation.IsNull())
6048 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
6049 const gp_Trsf& aTrsf = aLocation.Transformation();
6051 // extract normals from nodes
6052 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
6055 Poly_Connect aPolyConnect (aTriangulation);
6056 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
6059 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
6061 gp_Pnt aPoint = aNodes (aNodeIter);
6062 if (!aLocation.IsIdentity())
6064 aPoint.Transform (aTrsf);
6067 aNormals (aNodeIter).Transform (aTrsf);
6071 // add vertex into array of points
6072 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6075 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
6076 1.0, 0.5, Quantity_TOC_HLS);
6077 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6082 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
6087 else if (aCmd == CloudSphere)
6089 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
6090 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
6091 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
6092 Standard_Real aRadius = Draw::Atof (theArgs[5]);
6093 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
6095 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
6096 aDistribution.LowerCase();
6097 if ( aDistribution != "surface" && aDistribution != "volume" )
6099 std::cout << "Error: wrong arguments! See usage:\n";
6100 theDI.PrintHelp (theArgs[0]);
6103 Standard_Boolean isSurface = aDistribution == "surface";
6105 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
6107 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
6108 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
6110 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6111 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6112 Standard_Real aDistance = isSurface ?
6113 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
6115 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
6117 Cos (anAlpha) * Cos (aBeta));
6118 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
6120 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6123 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
6124 1.0, 0.5, Quantity_TOC_HLS);
6125 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6130 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6135 // set array of points in point cloud object
6136 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6137 aPointCloud->SetPoints (anArrayPoints);
6138 VDisplayAISObject (aName, aPointCloud);
6142 //=======================================================================
6143 //function : VPriority
6144 //purpose : Prints or sets the display priority for an object
6145 //=======================================================================
6147 static int VPriority (Draw_Interpretor& theDI,
6148 Standard_Integer theArgNum,
6149 const char** theArgs)
6151 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6152 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6153 if (aContext.IsNull())
6155 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
6159 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6160 Standard_Integer aPriority = -1;
6161 Standard_Integer aNbArgs = theArgNum;
6162 if (aLastArg.IsIntegerValue())
6164 aPriority = aLastArg.IntegerValue();
6166 if (aPriority < 0 || aPriority > 10)
6168 std::cout << "Error: the specified display priority value '" << aLastArg
6169 << "' is outside the valid range [0..10]" << std::endl;
6175 anUpdateTool.Invalidate();
6180 std::cout << "Error: wrong number of arguments! See usage:\n";
6181 theDI.PrintHelp (theArgs[0]);
6185 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6187 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6192 TCollection_AsciiString aName (theArgs[anArgIter]);
6193 Handle(AIS_InteractiveObject) anIObj;
6194 if (GetMapOfAIS().IsBound2 (aName))
6196 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
6199 if (anIObj.IsNull())
6201 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
6207 theDI << aContext->DisplayPriority (anIObj) << " ";
6211 aContext->SetDisplayPriority (anIObj, aPriority);
6217 //=======================================================================
6218 //function : ObjectsCommands
6220 //=======================================================================
6222 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6224 const char *group ="AISObjects";
6225 theCommands.Add("vtrihedron",
6226 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] "
6227 "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created.",
6228 __FILE__,VTrihedron,group);
6230 theCommands.Add("vtri2d",
6232 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6233 __FILE__,VTrihedron2D ,group);
6235 theCommands.Add("vplanetri",
6237 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6238 __FILE__,VPlaneTrihedron ,group);
6240 theCommands.Add("vsize",
6241 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6242 "\n\t\t: Changes the size of a named or selected trihedron."
6243 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6244 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6245 __FILE__,VSize,group);
6247 theCommands.Add("vaxis",
6248 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6249 "\n\t\t: Creates an axis. If the values are not defined, an axis is created by interactive selection of two vertices or one edge",
6250 __FILE__,VAxisBuilder,group);
6252 theCommands.Add("vaxispara",
6254 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6255 __FILE__,VAxisBuilder,group);
6257 theCommands.Add("vaxisortho",
6259 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6260 __FILE__,VAxisBuilder,group);
6262 theCommands.Add("vpoint",
6263 "vpoint PointName [Xa] [Ya] [Za] "
6264 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6265 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6266 __FILE__,VPointBuilder,group);
6268 theCommands.Add("vplane",
6269 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6270 "\n\t\t: Creates a plane from named or interactively selected entities."
6271 "\n\t\t: TypeOfSensitivity:"
6272 "\n\t\t: 0 - Interior"
6273 "\n\t\t: 1 - Boundary",
6274 __FILE__,VPlaneBuilder,group);
6276 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6277 " vchangeplane <plane_name>"
6278 " [x=center_x y=center_y z=center_z]"
6279 " [dx=dir_x dy=dir_y dz=dir_z]"
6280 " [sx=size_x sy=size_y]"
6282 " - changes parameters of the plane:\n"
6283 " - x y z - center\n"
6284 " - dx dy dz - normal\n"
6285 " - sx sy - plane sizes\n"
6286 " - noupdate - do not update/redisplay the plane in context\n"
6287 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6288 __FILE__, VChangePlane, group);
6290 theCommands.Add("vplanepara",
6291 "vplanepara PlaneName "
6292 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6293 __FILE__,VPlaneBuilder,group);
6295 theCommands.Add("vplaneortho",
6296 "vplaneortho PlaneName "
6297 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6298 __FILE__,VPlaneBuilder,group);
6300 theCommands.Add("vline",
6301 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6302 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6303 __FILE__,VLineBuilder,group);
6305 theCommands.Add("vcircle",
6306 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6307 "\n\t\t: Creates a circle from named or interactively selected entities."
6308 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6309 __FILE__,VCircleBuilder,group);
6311 theCommands.Add ("vdrawtext",
6312 "vdrawtext name text"
6313 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6314 "\n\t\t: [-color {R G B|name}=yellow]"
6315 "\n\t\t: [-halign {left|center|right}=left]"
6316 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6317 "\n\t\t: [-angle angle=0]"
6318 "\n\t\t: [-zoom {0|1}=0]"
6319 "\n\t\t: [-height height=16]"
6320 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6321 "\n\t\t: [-font font=Times]"
6323 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6324 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6325 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6326 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6327 "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}"
6328 "\n\t\t: [-subcolor {R G B|name}=white]"
6329 "\n\t\t: [-noupdate]"
6330 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6331 "\n\t\t: Display text label at specified position.",
6332 __FILE__, VDrawText, group);
6334 theCommands.Add("vdrawsphere",
6335 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6336 __FILE__,VDrawSphere,group);
6338 theCommands.Add ("vsetlocation",
6339 "vsetlocation [-noupdate|-update] name x y z"
6340 "\n\t\t: Set new location for an interactive object.",
6341 __FILE__, VSetLocation, group);
6345 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6346 __FILE__, VComputeHLR, group);
6348 theCommands.Add("vdrawparray",
6349 "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 ]",
6350 __FILE__,VDrawPArray,group);
6352 theCommands.Add("vconnect",
6353 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6354 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6355 __FILE__, VConnect, group);
6357 theCommands.Add("vconnectto",
6358 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6359 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6360 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6361 __FILE__, VConnectTo,group);
6363 theCommands.Add("vdisconnect",
6364 "vdisconnect assembly_name (object_name | object_number | 'all')"
6365 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6366 __FILE__,VDisconnect,group);
6368 theCommands.Add("vaddconnected",
6369 "vaddconnected assembly_name object_name"
6370 "Adds object to assembly.",
6371 __FILE__,VAddConnected,group);
6373 theCommands.Add("vlistconnected",
6374 "vlistconnected assembly_name"
6375 "Lists objects in assembly.",
6376 __FILE__,VListConnected,group);
6379 theCommands.Add("vselmode",
6380 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6381 " switches selection mode for the determined object or\n"
6382 " for all objects in context.\n"
6383 " mode_number is non-negative integer that has different\n"
6384 " meaning for different interactive object classes.\n"
6385 " For shapes the following mode_number values are allowed:\n"
6395 " is_turned_on is:\n"
6396 " 1 if mode is to be switched on\n"
6397 " 0 if mode is to be switched off\n",
6398 __FILE__, VSetSelectionMode, group);
6400 theCommands.Add("vselnext",
6401 "vselnext : hilight next detected",
6402 __FILE__, VSelectionNext, group);
6404 theCommands.Add("vselprev",
6405 "vselnext : hilight previous detected",
6406 __FILE__, VSelectionPrevious, group);
6408 theCommands.Add("vtriangle",
6409 "vtriangle Name PointName PointName PointName"
6410 "\n\t\t: Creates and displays a filled triangle from named points.",
6411 __FILE__, VTriangle,group);
6413 theCommands.Add("vsegment",
6414 "vsegment Name PointName PointName"
6415 "\n\t\t: Creates and displays a segment from named points.",
6416 __FILE__, VSegment,group);
6418 theCommands.Add("vobjzlayer",
6419 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6420 __FILE__, VObjZLayer, group);
6422 theCommands.Add("vpolygonoffset",
6423 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6424 __FILE__, VPolygonOffset, group);
6426 theCommands.Add ("vshowfaceboundary",
6427 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6428 "- turns on/off drawing of face boundaries for ais object "
6429 "and defines boundary line style.",
6430 __FILE__, VShowFaceBoundary, group);
6432 theCommands.Add ("vmarkerstest",
6433 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6434 __FILE__, VMarkersTest, group);
6436 theCommands.Add ("text2brep",
6437 "text2brep: name text"
6438 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6439 "\n\t\t: [-halign {left|center|right}=left]"
6440 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6441 "\n\t\t: [-height height=16]"
6442 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6443 "\n\t\t: [-font font=Courier]"
6444 "\n\t\t: [-composite {on|off}=off]"
6445 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6446 __FILE__, TextToBRep, group);
6447 theCommands.Add ("vfont",
6448 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6449 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6450 __FILE__, VFont, group);
6452 theCommands.Add ("vsetedgetype",
6453 "vsetedgetype usage:\n"
6454 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6455 "\n\t\t: Sets edges type and color for input shape",
6456 __FILE__, VSetEdgeType, group);
6458 theCommands.Add ("vunsetedgetype",
6459 "vunsetedgetype usage:\n"
6460 "vunsetedgetype ShapeName [-force]"
6461 "\n\t\t: Unsets edges type and color for input shape",
6462 __FILE__, VUnsetEdgeType, group);
6464 theCommands.Add ("vvertexmode",
6465 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6466 "vvertexmode - prints the default vertex draw mode\n"
6467 "vvertexmode name - prints the vertex draw mode of the given object\n"
6468 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6469 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6470 __FILE__, VVertexMode, group);
6472 theCommands.Add ("vpointcloud",
6473 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6474 "\n\t\t: Create an interactive object for arbitary set of points"
6475 "\n\t\t: from triangulated shape."
6477 "vpointcloud name x y z r npts {surface|volume}\n"
6478 " ... [-randColor] [-normals] [-noNormals]"
6479 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6480 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6482 "\n\t\t: Additional options:"
6483 "\n\t\t: -randColor - generate random color per point"
6484 "\n\t\t: -normals - generate normal per point (default)"
6485 "\n\t\t: -noNormals - do not generate normal per point"
6487 __FILE__, VPointCloud, group);
6489 theCommands.Add("vlocreset",
6490 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6492 LocalTransformPresentation, group);
6494 theCommands.Add("vlocmove",
6495 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6497 LocalTransformPresentation, group);
6499 theCommands.Add("vloctranslate",
6500 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6502 LocalTransformPresentation, group);
6504 theCommands.Add("vlocrotate",
6505 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6507 LocalTransformPresentation, group);
6509 theCommands.Add("vlocmirror",
6510 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6512 LocalTransformPresentation, group);
6514 theCommands.Add("vlocscale",
6515 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6517 LocalTransformPresentation, group);
6519 theCommands.Add("vpriority",
6520 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",