1 // File: ViewerTest_ObjectsCommands.cxx
2 // Created: Thu Nov 12 15:50:42 1998
3 // Author: Robert COUBLANC
4 // Copyright: OPEN CASCADE 1998
7 //===============================================
9 // AIS Objects Creation : Datums (axis,trihedrons,lines,planes)
11 //===============================================
17 #include <ViewerTest.hxx>
21 #include <Quantity_NameOfColor.hxx>
22 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
27 #include <OSD_Chronometer.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <Visual3d_View.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
32 #include <V3d_Plane.hxx>
35 #include <AIS_Shape.hxx>
36 #include <AIS_DisplayMode.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
40 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_EventManager.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <BRepTools.hxx>
45 #include <BRep_Builder.hxx>
46 #include <TopAbs_ShapeEnum.hxx>
49 #include <BRep_Tool.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <BRepAdaptor_Curve.hxx>
53 #include <BRepAdaptor_Surface.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopoDS_Face.hxx>
61 #include <Draw_Window.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 #include <AIS_ListOfInteractive.hxx>
64 #include <AIS_DisplayMode.hxx>
65 #include <AIS_Shape.hxx>
67 #include <AIS_InteractiveContext.hxx>
68 #include <Geom_Plane.hxx>
70 #include <AIS_AngleDimension.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <GC_MakePlane.hxx>
73 #include <gp_Circ.hxx>
74 #include <AIS_Axis.hxx>
75 #include <Geom_Axis2Placement.hxx>
76 #include <Geom_Axis1Placement.hxx>
77 #include <AIS_Trihedron.hxx>
78 #include <AIS_Axis.hxx>
79 #include <gp_Trsf.hxx>
80 #include <TopLoc_Location.hxx>
82 #include <HLRAlgo_Projector.hxx>
83 #include <HLRBRep_PolyAlgo.hxx>
84 #include <HLRBRep_PolyHLRToShape.hxx>
85 #include <Aspect_Window.hxx>
87 #include <Graphic3d_ArrayOfPoints.hxx>
88 #include <Graphic3d_ArrayOfSegments.hxx>
89 #include <Graphic3d_ArrayOfPolylines.hxx>
90 #include <Graphic3d_ArrayOfTriangles.hxx>
91 #include <Graphic3d_ArrayOfTriangleFans.hxx>
92 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
93 #include <Graphic3d_ArrayOfQuadrangles.hxx>
94 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
95 #include <Graphic3d_ArrayOfPolygons.hxx>
96 #include <Graphic3d_Group.hxx>
97 #include <Standard_Real.hxx>
99 #include <AIS_Circle.hxx>
100 #include <AIS_Drawer.hxx>
101 #include <BRepBuilderAPI_MakeEdge.hxx>
102 #include <BRepBuilderAPI_MakeFace.hxx>
103 #include <BRepBuilderAPI_MakeWire.hxx>
104 #include <Geom_Circle.hxx>
105 #include <GC_MakeCircle.hxx>
106 #include <Prs3d_Presentation.hxx>
107 #include <Select3D_SensitiveCircle.hxx>
108 #include <SelectMgr_EntityOwner.hxx>
109 #include <SelectMgr_Selection.hxx>
110 #include <StdFail_NotDone.hxx>
111 #include <StdPrs_ShadedShape.hxx>
112 #include <TopoDS_Wire.hxx>
114 #include <AIS_ConnectedShape.hxx>
115 #include <TopLoc_Location.hxx>
116 #include <TColStd_ListOfInteger.hxx>
117 #include <TColStd_ListIteratorOfListOfInteger.hxx>
119 #include <Select3D_SensitiveTriangle.hxx>
120 #include <Select3D_SensitiveCurve.hxx>
121 #include <BRepAdaptor_Curve.hxx>
122 #include <StdPrs_Curve.hxx>
124 #include <BRepExtrema_ExtPC.hxx>
125 #include <BRepExtrema_ExtPF.hxx>
127 #ifdef HAVE_STRINGS_H
132 #define _CRT_SECURE_NO_DEPRECATE
133 #pragma warning (disable:4996)
136 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
137 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
138 const Handle(AIS_InteractiveObject)& theAISObj,
139 Standard_Boolean theReplaceIfExists = Standard_True);
140 Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
141 extern Handle(AIS_InteractiveContext)& TheAISContext();
144 //==============================================================================
145 //function : Vtrihedron 2d
146 //purpose : Create a plane with a 2D trihedron from a faceselection
147 //Draw arg : vtri2d name
148 //==============================================================================
149 #include <AIS_PlaneTrihedron.hxx>
153 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
156 // Verification des arguments
157 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
160 Standard_Integer myCurrentIndex;
161 // Fermeture des contextes
162 TheAISContext()->CloseAllContexts();
163 // Ouverture d'un contexte local et recuperation de son index.
164 TheAISContext()->OpenLocalContext();
165 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
166 // On active les modes de selections faces.
167 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
168 di<<" Select a face ."<<"\n";
170 // Boucle d'attente waitpick.
171 Standard_Integer argccc = 5;
172 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
173 const char **argvvv = (const char **) bufff;
174 while (ViewerMainLoop( argccc, argvvv) ) { }
178 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
179 ShapeB = TheAISContext()->SelectedShape();
182 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
184 // Construction du Plane
185 // recuperation des edges des faces.
186 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
188 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
192 // si il y a plusieurs edges
193 if (FaceExpB.More() ) {
195 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
196 BRepAdaptor_Curve theCurveB(EdgeB);
197 BRepAdaptor_Curve theCurveC(EdgeC);
198 A=theCurveC.Value(0.1);
199 B=theCurveC.Value(0.9);
200 C=theCurveB.Value(0.5);
203 // FaceB a 1 unique edge courbe
204 BRepAdaptor_Curve theCurveB(EdgeB);
205 A=theCurveB.Value(0.1);
206 B=theCurveB.Value(0.9);
207 C=theCurveB.Value(0.5);
209 // Construction du Geom_Plane
210 GC_MakePlane MkPlane(A,B,C);
211 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
213 // Construction de l'AIS_PlaneTrihedron
214 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
216 // Fermeture du contexte local.
217 TheAISContext()->CloseLocalContext(myCurrentIndex);
219 // on le display & bind
220 TheAISContext()->Display(theAISPlaneTri );
221 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
228 //==============================================================================
229 //function : VTriherdron
231 //purpose : Create a trihedron. If no arguments are set, the default
232 // trihedron (Oxyz) is created.
233 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
234 //==============================================================================
236 static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
239 // Verification des arguments
240 if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
242 // Declarations et creation des objets par default
243 TCollection_AsciiString name=argv[1];
245 if(argc > 5 && argc!=11)
246 {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
248 // Cas ou il y a des arguments
249 Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.};
253 coord[i]= atof(argv[2+i]);
257 coord[3+i] = atof(argv[6+i]);
258 coord[6+i] = atof(argv[8+i]);
262 gp_Pnt ThePoint(coord[0],coord[1],coord[2]);
263 gp_Dir TheZVector(coord[3],coord[4],coord[5]);
264 gp_Dir TheXVector(coord[6],coord[7],coord[8]);
266 if ( !TheZVector.IsNormal(TheXVector,M_PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;}
268 Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector);
270 // Creation du triedre
271 Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii);
272 GetMapOfAIS().Bind(aShape,name);
273 TheAISContext()->Display(aShape);
281 //==============================================================================
284 //purpose : Change the size of a named or selected trihedron
285 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
286 // if no value, the value is set at 100 by default
287 //Draw arg : vsize [name] [size]
288 //==============================================================================
290 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
293 // Declaration de booleens
294 Standard_Boolean ThereIsName;
295 Standard_Boolean ThereIsCurrent;
297 Standard_Boolean hascol;
299 Quantity_NameOfColor col;
301 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
304 // Verification des arguments
305 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
307 // Verification du nombre d'arguments
308 if (argc==1) {ThereIsName=Standard_False;value=100;}
309 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
310 else {ThereIsName=Standard_True;value=atof(argv[2]);}
312 // On ferme le contexte local pour travailler dans le contexte global
313 if(TheAISContext()->HasOpenedContext())
314 TheAISContext()->CloseLocalContext();
316 // On set le booleen ThereIsCurrent
317 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
318 else {ThereIsCurrent=Standard_False;}
322 //===============================================================
323 // Il n'y a pas de nom mais des objets selectionnes
324 //===============================================================
325 if (!ThereIsName && ThereIsCurrent)
328 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
331 while ( it.More() ) {
333 Handle(AIS_InteractiveObject) aShape=
334 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
336 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
339 // On verifie que l'AIS InteraciveObject selectionne est bien
341 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
343 if (aShape->HasColor()) {
344 hascol=Standard_True;
346 // On recupere la couleur de aShape
347 col=aShape->Color();}
349 else hascol=Standard_False;
351 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
352 // pour lui appliquer la methode SetSize()
353 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
355 // C'est bien un triedre,on chage sa valeur!
356 aTrihedron->SetSize(value);
358 // On donne la couleur au Trihedron
359 if(hascol) aTrihedron->SetColor(col);
360 else aTrihedron->UnsetColor();
363 // The trihedron hasn't be errased from the map
364 // so you just have to redisplay it
365 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
374 TheAISContext() ->UpdateCurrentViewer();
377 //===============================================================
378 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
379 //===============================================================
383 //===============================================================
384 // Il y a un nom de triedre passe en argument
385 //===============================================================
387 TCollection_AsciiString name=argv[1];
389 // on verifie que ce nom correspond bien a une shape
390 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
394 // on recupere la shape dans la map des objets displayes
395 Handle(AIS_InteractiveObject) aShape =
396 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
398 // On verifie que l'AIS InteraciveObject est bien
400 if (!aShape.IsNull() &&
401 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
404 if (aShape->HasColor()) {
405 hascol=Standard_True;
407 // On recupere la couleur de aShape
408 col=aShape->Color();}
410 else hascol=Standard_False;
412 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
413 // pour lui appliquer la methode SetSize()
414 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
416 // C'est bien un triedre,on chage sa valeur
417 aTrihedron->SetSize(value);
419 // On donne la couleur au Trihedron
420 if(hascol) aTrihedron->SetColor(col);
421 else aTrihedron->UnsetColor();
423 // The trihedron hasn't be errased from the map
424 // so you just have to redisplay it
425 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
427 TheAISContext() ->UpdateCurrentViewer();
435 //==============================================================================
437 //==============================================================================
438 //function : VPlaneTrihedron
439 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
440 //Draw arg : vplanetri name
441 //==============================================================================
442 #include <AIS_Plane.hxx>
446 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
449 // Verification des arguments
450 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
453 Standard_Integer myCurrentIndex;
454 // Fermeture des contextes locaux
455 TheAISContext()->CloseAllContexts();
457 // On recupere tous les trihedrons de la GetMapOfAIS()
458 // et on active le mode de selection par face.
459 // =================================================
461 // Ouverture d'un contexte local et recuperation de son index.
462 TheAISContext()->OpenLocalContext(Standard_False);
463 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
465 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
468 Handle(AIS_InteractiveObject) ShapeA =
469 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
470 // On verifie que c'est bien un trihedron
471 if (!ShapeA.IsNull() &&
472 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
474 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
475 // on le charge dans le contexte et on active le mode Plane.
476 TheAISContext()->Load(TrihedronA,0,Standard_False);
477 TheAISContext()->Activate(TrihedronA,3);
482 di<<" Select a plane."<<"\n";
483 // Boucle d'attente waitpick.
484 Standard_Integer argccc = 5;
485 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
486 const char **argvvv = (const char **) bufff;
487 while (ViewerMainLoop( argccc, argvvv) ) { }
490 Handle(AIS_InteractiveObject) theIOB;
491 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
492 theIOB = TheAISContext()->Interactive();
495 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
497 // Fermeture du contexte local.
498 TheAISContext()->CloseLocalContext(myCurrentIndex);
500 // on le display & bind
501 TheAISContext()->Display(PlaneB );
502 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
509 //==============================================================================
510 // Fonction First click 2de click
512 // vaxis vertex vertex
514 // vaxispara edge vertex
515 // vaxisortho edge Vertex
516 // vaxisinter Face Face
517 //==============================================================================
519 //==============================================================================
520 //function : VAxisBuilder
522 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
523 //==============================================================================
524 #include <TopoDS_Edge.hxx>
525 #include <TopoDS_Vertex.hxx>
526 #include <TopExp.hxx>
527 #include <Geom_Line.hxx>
529 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
532 Standard_Boolean HasArg;
533 TCollection_AsciiString name;
534 Standard_Integer MyCurrentIndex;
537 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
538 if (argc==8) HasArg=Standard_True;
539 else HasArg=Standard_False;
542 // Fermeture des contextes
543 TheAISContext()->CloseAllContexts();
545 // Cas ou il y a des arguments
546 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
548 Standard_Real coord[6];
549 for(Standard_Integer i=0;i<=5;i++){
550 coord[i]=atof(argv[2+i]);
552 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
554 gp_Vec myVect (p1,p2);
555 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
556 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
557 GetMapOfAIS().Bind (TheAxis,name);
558 TheAISContext()->Display(TheAxis);
564 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
565 if ( !strcasecmp(argv[0], "vaxis")) {
566 TheAISContext()->OpenLocalContext();
567 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
569 // Active le mode edge et le mode vertex
570 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
571 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
572 di<<" Select an edge or a vertex."<<"\n";
574 // Boucle d'attente waitpick.
575 Standard_Integer argcc = 5;
576 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
577 const char **argvv = (const char **) buff;
578 while (ViewerMainLoop( argcc, argvv) ) { }
581 // recuperation de la shape.
583 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
584 ShapeA = TheAISContext()->SelectedShape();
586 // recuperation de l'AIS_InteractiveObject
587 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
588 // down cast en AIS_Point si sig et type
589 // AIS_Point -> Geom_Pnt ....
591 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
592 // on desactive le mode edge
593 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
594 di<<" Select a different vertex."<<"\n";
598 // Boucle d'attente waitpick.
599 Standard_Integer argccc = 5;
600 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
601 const char **argvvv = (const char **) bufff;
602 while (ViewerMainLoop( argccc, argvvv) ) { }
604 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
605 ShapeB = TheAISContext()->SelectedShape();
609 } while(ShapeB.IsSame(ShapeA) );
611 // Fermeture du context local
612 TheAISContext()->CloseLocalContext(MyCurrentIndex);
614 // Construction de l'axe
615 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
616 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
619 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
620 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
621 GetMapOfAIS().Bind (TheAxis,name);
622 TheAISContext()->Display(TheAxis);
625 // Un unique edge (ShapeA) a ete picke
626 // Fermeture du context local
627 TheAISContext()->CloseLocalContext(MyCurrentIndex);
628 // Constuction de l'axe
629 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
631 TopExp::Vertices(ed,Va,Vb );
632 gp_Pnt A=BRep_Tool::Pnt(Va);
633 gp_Pnt B=BRep_Tool::Pnt(Vb);
636 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
637 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
638 GetMapOfAIS().Bind (TheAxis,name);
639 TheAISContext()->Display(TheAxis);
645 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
646 else if ( !strcasecmp(argv[0], "vaxispara")) {
648 TheAISContext()->OpenLocalContext();
649 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
651 // Active le mode edge
652 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
653 di<<" Select an edge."<<"\n";
655 // Boucle d'attente waitpick.
656 Standard_Integer argcc = 5;
657 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
658 const char **argvv = (const char **) buff;
659 while (ViewerMainLoop( argcc, argvv) ) { }
663 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
664 ShapeA = TheAISContext()->SelectedShape();
666 // Active le mode vertex et deactive edges
667 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
668 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
669 di<<" Select a vertex."<<"\n";
671 // Boucle d'attente waitpick.
672 Standard_Integer argccc = 5;
673 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
674 const char **argvvv = (const char **) bufff;
675 while (ViewerMainLoop( argccc, argvvv) ) { }
678 // On peut choisir un pnt sur l'edge
680 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
681 ShapeB = TheAISContext()->SelectedShape();
683 // Fermeture du context local
684 TheAISContext()->CloseLocalContext(MyCurrentIndex);
686 // Construction de l'axe
687 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
688 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
690 TopExp::Vertices(ed,Va,Vc );
691 gp_Pnt A=BRep_Tool::Pnt(Va);
692 gp_Pnt C=BRep_Tool::Pnt(Vc);
695 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
696 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
697 GetMapOfAIS().Bind (TheAxis,name);
698 TheAISContext()->Display(TheAxis);
702 // Fonction axisortho
704 TheAISContext()->OpenLocalContext();
705 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
707 // Active le mode edge
708 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
709 di<<" Select an edge."<<"\n";
711 // Boucle d'attente waitpick.
712 Standard_Integer argcc = 5;
713 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
714 const char **argvv = (const char **) buff;
715 while (ViewerMainLoop( argcc, argvv) ) { }
719 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
720 ShapeA = TheAISContext()->SelectedShape();
722 // Active le mode vertex et deactive edges
723 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
724 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
725 di<<" Slect a vertex."<<"\n";
727 // Boucle d'attente waitpick.
728 Standard_Integer argccc = 5;
729 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
730 const char **argvvv = (const char **) bufff;
731 while (ViewerMainLoop( argccc, argvvv) ) { }
734 // On peut choisir un pnt sur l'edge
736 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
737 ShapeB = TheAISContext()->SelectedShape();
739 // Fermeture du context local
740 TheAISContext()->CloseLocalContext(MyCurrentIndex);
742 // Construction de l'axe
743 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
744 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
746 TopExp::Vertices(ed,Va,Vc );
747 gp_Pnt A=BRep_Tool::Pnt(Va);
748 gp_Pnt C=BRep_Tool::Pnt(Vc);
749 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
752 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
753 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
754 GetMapOfAIS().Bind (TheAxis,name);
755 TheAISContext()->Display(TheAxis);
764 //==============================================================================
765 // Fonction First click Result
767 // vpoint vertex AIS_Point=Vertex
768 // edge AIS_Point=Middle of the edge
769 //==============================================================================
771 //==============================================================================
772 //function : VPointBuilder
773 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
774 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
775 //==============================================================================
776 #include <TopoDS_Edge.hxx>
777 #include <TopoDS_Vertex.hxx>
778 #include <TopExp.hxx>
779 #include <AIS_Point.hxx>
780 #include <Geom_CartesianPoint.hxx>
782 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
785 Standard_Boolean HasArg;
786 TCollection_AsciiString name;
787 Standard_Integer myCurrentIndex;
790 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
791 if (argc==5) HasArg=Standard_True;
792 else HasArg=Standard_False;
795 // Fermeture des contextes
796 TheAISContext()->CloseAllContexts();
798 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
800 Standard_Real thecoord[3];
801 for(Standard_Integer i=0;i<=2;i++)
802 thecoord[i]=atof(argv[2+i]);
803 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
804 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
805 GetMapOfAIS().Bind (myAISPoint,name);
806 TheAISContext()->Display(myAISPoint);
809 // Il n'a pas d'arguments
811 TheAISContext()->OpenLocalContext();
812 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
814 // Active le mode Vertex et Edges
815 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
816 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
817 di<<" Select a vertex or an edge(build the middle)"<<"\n";
819 // Boucle d'attente waitpick.
820 Standard_Integer argcc = 5;
821 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
822 const char **argvv = (const char **) buff;
823 while (ViewerMainLoop( argcc, argvv) ) { }
827 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
828 ShapeA= TheAISContext()->SelectedShape();
831 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
832 // Un vertex a ete selectionne
833 // Fermeture du context local
834 TheAISContext()->CloseLocalContext(myCurrentIndex);
836 // Construction du point
837 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
838 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
839 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
840 GetMapOfAIS().Bind(myAISPoint,name);
841 TheAISContext()->Display(myAISPoint);
844 // Un Edge a ete selectionne
845 // Fermeture du context local
846 TheAISContext()->CloseLocalContext(myCurrentIndex);
848 // Construction du point milieu de l'edge
849 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
850 TopoDS_Vertex myVertexA,myVertexB;
851 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
852 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
853 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
854 // M est le milieu de [AB]
855 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
856 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
857 GetMapOfAIS().Bind(myAISPointM,name);
858 TheAISContext()->Display(myAISPointM);
866 //==============================================================================
867 // Function 1st click 2de click 3de click
868 // vplane Vertex Vertex Vertex
872 // vplanepara Face Vertex
874 // vplaneortho Face Edge
876 //==============================================================================
878 //==============================================================================
879 //function : VPlaneBuilder
880 //purpose : Build an AIS_Plane from selected entities or Named AIS components
881 //Draw arg : vplane PlaneName [AxisName] [PointName]
882 // [PointName] [PointName] [PointName]
883 // [PlaneName] [PointName]
884 //==============================================================================
886 static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
887 Standard_Integer argc,
891 Standard_Boolean hasArg;
892 TCollection_AsciiString aName;
893 Standard_Integer aCurrentIndex;
896 if (argc<2 || argc>5 )
898 std::cout<<" Syntax error\n";
901 if (argc==5 || argc==4)
902 hasArg=Standard_True;
904 hasArg=Standard_False;
907 // Close all contexts
908 TheAISContext()->CloseAllContexts();
910 // There are some arguments
913 if (!GetMapOfAIS().IsBound2(argv[2] ))
915 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
918 // Get shape from map
919 Handle(AIS_InteractiveObject) aShapeA =
920 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
922 // The first argument is an AIS_Point
923 if (!aShapeA.IsNull() &&
924 aShapeA->Type()==AIS_KOI_Datum &&
925 aShapeA->Signature()==1)
927 // The second argument must also be an AIS_Point
928 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
930 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
933 // Get shape from map
934 Handle(AIS_InteractiveObject) aShapeB =
935 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
936 // If B is not an AIS_Point
937 if (aShapeB.IsNull() ||
938 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
940 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
943 // The third object is an AIS_Point
944 if (!GetMapOfAIS().IsBound2(argv[4]) )
946 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
949 // Get shape from map
950 Handle(AIS_InteractiveObject) aShapeC =
951 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
952 // If C is not an AIS_Point
953 if (aShapeC.IsNull() ||
954 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
956 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
960 // Treatment of objects A, B, C
961 // Downcast an AIS_IO to AIS_Point
962 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
963 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
964 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
966 Handle(Geom_CartesianPoint ) aCartPointA =
967 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
969 Handle(Geom_CartesianPoint ) aCartPointB =
970 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
972 Handle(Geom_CartesianPoint ) aCartPointC =
973 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
975 // Verification that the three points are different
976 if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
977 abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
978 abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
981 std::cout<<"vplane error: same points"<<"\n";return 1;
983 if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
984 abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
985 abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
988 std::cout<<"vplane error: same points"<<"\n";return 1;
990 if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
991 abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
992 abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
995 std::cout<<"vplane error: same points"<<"\n";return 1;
998 gp_Pnt A = aCartPointA->Pnt();
999 gp_Pnt B = aCartPointB->Pnt();
1000 gp_Pnt C = aCartPointC->Pnt();
1002 // Construction of AIS_Plane
1003 GC_MakePlane MkPlane (A,B,C);
1004 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1005 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1006 GetMapOfAIS().Bind (anAISPlane,aName );
1007 TheAISContext()->Display(anAISPlane);
1010 // The first argument is an AIS_Axis
1011 // Creation of a plane orthogonal to the axis through a point
1012 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1013 // The second argument should be an AIS_Point
1014 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1016 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1019 // Get shape from map
1020 Handle(AIS_InteractiveObject) aShapeB =
1021 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1022 // If B is not an AIS_Point
1023 if (aShapeB.IsNull() ||
1024 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1026 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1030 // Treatment of objects A and B
1031 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1032 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1034 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1035 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1037 gp_Ax1 anAxis = aGeomLineA->Position();
1038 Handle(Geom_CartesianPoint) aCartPointB =
1039 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1041 gp_Dir D =anAxis.Direction();
1042 gp_Pnt B = aCartPointB->Pnt();
1044 // Construction of AIS_Plane
1045 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1046 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1047 GetMapOfAIS().Bind (anAISPlane,aName );
1048 TheAISContext()->Display(anAISPlane);
1051 // The first argumnet is an AIS_Plane
1052 // Creation of a plane parallel to the plane passing through the point
1053 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1055 // The second argument should be an AIS_Point
1056 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1058 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1061 // Get shape from map
1062 Handle(AIS_InteractiveObject) aShapeB =
1063 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1064 // B should be an AIS_Point
1065 if (aShapeB.IsNull() ||
1066 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1068 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1072 // Treatment of objects A and B
1073 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1074 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1076 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1077 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1079 Handle(Geom_CartesianPoint) aCartPointB =
1080 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1081 gp_Pnt B= aCartPointB->Pnt();
1083 // Construction of an AIS_Plane
1084 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1085 GetMapOfAIS().Bind (anAISPlane, aName);
1086 TheAISContext()->Display(anAISPlane);
1091 std::cout<<"vplane: error 1st object is not an AIS\n";
1095 // There are no arguments
1099 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1100 if (!strcasecmp(argv[0], "vplane"))
1102 TheAISContext()->OpenLocalContext();
1103 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1105 // Active modes Vertex, Edge and Face
1106 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1107 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1108 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1109 std::cout<<"Select a vertex, a face or an edge\n";
1112 Standard_Integer argcc = 5;
1113 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1114 const char **argvv = (const char **) buff;
1115 while (ViewerMainLoop( argcc, argvv) ) { }
1118 TopoDS_Shape aShapeA;
1119 for (TheAISContext()->InitSelected();
1120 TheAISContext()->MoreSelected();
1121 TheAISContext()->NextSelected())
1123 aShapeA = TheAISContext()->SelectedShape();
1126 // aShapeA is a Vertex
1127 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1129 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1130 std::cout<<" Select an edge or a different vertex\n";
1133 Standard_Integer argccc = 5;
1134 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1135 const char **argvvv = (const char **) bufff;
1136 while (ViewerMainLoop( argccc, argvvv) ) { }
1139 TopoDS_Shape aShapeB;
1140 for (TheAISContext()->InitSelected();
1141 TheAISContext()->MoreSelected();
1142 TheAISContext()->NextSelected())
1144 aShapeB = TheAISContext()->SelectedShape();
1146 // aShapeB is a Vertex
1147 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1149 // A and B are the same
1150 if (aShapeB.IsSame(aShapeA))
1152 std::cout<<" vplane: error, same points selected\n";
1155 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1156 std::cout<<" Select a different vertex\n";
1159 Standard_Integer argcccc = 5;
1160 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1161 const char **argvvvv = (const char **) buffff;
1162 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1165 TopoDS_Shape aShapeC;
1166 for (TheAISContext()->InitSelected();
1167 TheAISContext()->MoreSelected();
1168 TheAISContext()->NextSelected())
1170 aShapeC = TheAISContext()->SelectedShape();
1172 // aShapeC is the same as A or B
1173 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1175 std::cout<<" vplane: error, same points selected\n";
1179 // Close the local context
1180 TheAISContext()->CloseLocalContext(aCurrentIndex);
1182 // Construction of plane
1183 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1184 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1185 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1186 GC_MakePlane MkPlane(A, B, C);
1187 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1188 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1189 GetMapOfAIS().Bind (anAISPlane, aName);
1190 TheAISContext()->Display(anAISPlane);
1192 // ShapeB is an edge
1195 // Verify that the vertex is not on the edge ShapeB
1196 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1197 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1199 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1200 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1202 // The vertex is on the edge
1203 std::cout<<" vplane: error point is on the edge\n";
1208 // Close the local context
1209 TheAISContext()->CloseLocalContext(aCurrentIndex);
1210 // Construction of plane
1211 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1212 TopoDS_Vertex aVBa, aVBb;
1213 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1214 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1215 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1216 GC_MakePlane MkPlane (A, aBa, aBb);
1217 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1218 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1219 GetMapOfAIS().Bind (anAISPlane, aName);
1220 TheAISContext()->Display(anAISPlane);
1224 // aShapeA is an edge
1225 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1227 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1228 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1229 std::cout<<" Select a vertex that don't belong to the edge\n";
1232 Standard_Integer argccc = 5;
1233 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1234 const char **argvvv = (const char **) bufff;
1235 while (ViewerMainLoop( argccc, argvvv) ) { }
1238 TopoDS_Shape aShapeB;
1239 for (TheAISContext()->InitSelected();
1240 TheAISContext()->MoreSelected();
1241 TheAISContext()->NextSelected())
1243 aShapeB = TheAISContext()->SelectedShape();
1245 // aShapeB should be a Vertex
1246 // Check that the vertex aShapeB is not on the edge
1247 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1248 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1250 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1251 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1253 // The vertex is on the edge
1254 std::cout<<" vplane: error point is on the edge\n";
1259 // Close the local context
1260 TheAISContext()->CloseLocalContext(aCurrentIndex);
1261 // Construction of plane
1262 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1263 TopoDS_Vertex aVAa, aVAb;
1264 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1265 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1266 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1267 GC_MakePlane MkPlane (B,Aa,Ab);
1268 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1269 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1270 GetMapOfAIS().Bind (anAISPlane ,aName);
1271 TheAISContext()->Display(anAISPlane);
1274 // aShapeA is a Face
1277 // Close the local context: nothing to select
1278 TheAISContext()->CloseLocalContext(aCurrentIndex);
1279 // Construction of plane
1280 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1281 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1282 if (aSurface.GetType()==GeomAbs_Plane)
1284 gp_Pln aPlane = aSurface.Plane();
1285 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1286 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1287 GetMapOfAIS().Bind (anAISPlane, aName);
1288 TheAISContext()->Display(anAISPlane);
1292 std::cout<<" vplane: error\n";
1298 // Function vPlanePara
1299 // ===================
1300 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1301 else if (!strcasecmp(argv[0], "vplanepara"))
1303 TheAISContext()->OpenLocalContext();
1304 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1306 // Activate modes Vertex and Face
1307 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1308 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1309 std::cout<<" Select a vertex or a face\n";
1312 Standard_Integer argcc = 5;
1313 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1314 const char **argvv = (const char **) buff;
1315 while (ViewerMainLoop( argcc, argvv) ) { }
1318 TopoDS_Shape aShapeA;
1319 for (TheAISContext()->InitSelected();
1320 TheAISContext()->MoreSelected();
1321 TheAISContext()->NextSelected())
1323 aShapeA = TheAISContext()->SelectedShape();
1326 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1328 // aShapeA is a vertex
1329 // Deactivate the mode Vertex
1330 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1331 std::cout<<" Select a face\n";
1334 Standard_Integer argccc = 5;
1335 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1336 const char **argvvv = (const char **) bufff;
1337 while (ViewerMainLoop( argccc, argvvv) ) { }
1340 TopoDS_Shape aShapeB;
1341 for (TheAISContext()->InitSelected();
1342 TheAISContext()->MoreSelected();
1343 TheAISContext()->NextSelected())
1345 // A vertex ShapeA can be on Face ShapeB
1346 aShapeB = TheAISContext()->SelectedShape();
1349 // Close the local context
1350 TheAISContext()->CloseLocalContext(aCurrentIndex);
1352 // Construction of plane
1353 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1355 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1356 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1357 if (aSurface.GetType()==GeomAbs_Plane )
1359 gp_Pln aPlane = aSurface.Plane();
1360 // Construct a plane parallel to aGeomPlane through A
1361 aPlane.SetLocation(A);
1362 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1363 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1364 GetMapOfAIS().Bind (aAISPlane ,aName);
1365 TheAISContext()->Display(aAISPlane);
1369 std::cout<<" vplanepara: error\n";
1376 // Deactive the mode Face
1377 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1378 std::cout<<" Select a vertex\n";
1381 Standard_Integer argccc = 5;
1382 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1383 const char **argvvv = (const char **) bufff;
1384 while (ViewerMainLoop( argccc, argvvv) ) { }
1387 TopoDS_Shape aShapeB;
1388 for (TheAISContext()->InitSelected();
1389 TheAISContext()->MoreSelected();
1390 TheAISContext()->NextSelected())
1392 // A vertex ShapeB can be on Face ShapeA
1393 aShapeB = TheAISContext()->SelectedShape();
1395 // Close the local context
1396 TheAISContext()->CloseLocalContext(aCurrentIndex);
1398 // Construction of plane
1399 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1401 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1402 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1403 if (aSurface.GetType()==GeomAbs_Plane )
1405 gp_Pln aPlane = aSurface.Plane();
1406 aPlane.SetLocation(B);
1407 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1408 // Construct a plane parallel to aGeomPlane through B
1409 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1410 GetMapOfAIS().Bind (anAISPlane, aName);
1411 TheAISContext()->Display(anAISPlane);
1415 std::cout<<" vplanepara: error"<<"\n";return 1;
1420 // Function vplaneortho
1421 // ====================
1422 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1425 TheAISContext()->OpenLocalContext();
1426 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1428 // Activate the modes Edge and Face
1429 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1430 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1431 std::cout<<" Select a face and an edge coplanar\n";
1434 Standard_Integer argcc = 5;
1435 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1436 const char **argvv = (const char **) buff;
1437 while (ViewerMainLoop( argcc, argvv) ) { }
1440 TopoDS_Shape aShapeA;
1441 for (TheAISContext()->InitSelected();
1442 TheAISContext()->MoreSelected();
1443 TheAISContext()->NextSelected())
1445 aShapeA = TheAISContext()->SelectedShape();
1448 if (aShapeA.ShapeType()==TopAbs_EDGE )
1450 // ShapeA is an edge, deactivate the mode Edge...
1451 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1452 std::cout<<" Select a face\n";
1455 Standard_Integer argccc = 5;
1456 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1457 const char **argvvv = (const char **) bufff;
1458 while (ViewerMainLoop( argccc, argvvv) ) { }
1461 TopoDS_Shape aShapeB;
1462 for (TheAISContext()->InitSelected();
1463 TheAISContext()->MoreSelected();
1464 TheAISContext()->NextSelected())
1466 // Edge ShapeA can be on Face ShapeB
1467 aShapeB = TheAISContext()->SelectedShape();
1470 // Close the local context
1471 TheAISContext()->CloseLocalContext(aCurrentIndex);
1473 // Construction of plane
1474 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1475 TopoDS_Vertex aVAa, aVAb;
1476 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1477 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1478 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1482 // Creation of rotation axis
1483 gp_Ax1 aRotAxis (Aa,Dab);
1485 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1486 // The edge must be parallel to the face
1487 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1488 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1489 // Compare to heights
1490 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1491 >Precision::Confusion())
1493 // the edge is not parallel to the face
1494 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1498 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1499 if (aSurface.GetType()==GeomAbs_Plane)
1501 gp_Pln aPlane = aSurface.Plane();
1502 // It rotates a half turn round the axis of rotation
1503 aPlane.Rotate(aRotAxis , M_PI/2);
1505 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1506 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1507 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1508 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1509 GetMapOfAIS().Bind (anAISPlane, aName);
1510 TheAISContext()->Display(anAISPlane);
1514 std::cout<<" vplaneortho: error\n";
1520 // ShapeA is a Face, deactive the mode Face.
1521 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1522 std::cout<<" Select an edge\n";
1525 Standard_Integer argccc = 5;
1526 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1527 const char **argvvv = (const char **) bufff;
1528 while (ViewerMainLoop( argccc, argvvv) ) { }
1531 TopoDS_Shape aShapeB;
1532 for (TheAISContext()->InitSelected();
1533 TheAISContext()->MoreSelected();
1534 TheAISContext()->NextSelected())
1536 // Edge ShapeB can be on Face ShapeA
1537 aShapeB = TheAISContext()->SelectedShape();
1539 // Close the local context
1540 TheAISContext()->CloseLocalContext(aCurrentIndex);
1542 // Construction of plane
1543 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1544 TopoDS_Vertex aVBa, aVBb;
1545 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1546 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1547 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1548 gp_Vec ab (aBa,aBb);
1550 // Creation of rotation axe
1551 gp_Ax1 aRotAxis (aBa,Dab);
1553 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1554 // The edge must be parallel to the face
1555 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1556 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1557 // Comparing the two heights
1558 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1559 >Precision::Confusion())
1561 // the edge is not parallel to the face
1562 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1566 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1567 if (aSurface.GetType()==GeomAbs_Plane)
1569 gp_Pln aPlane = aSurface.Plane();
1570 // It rotates a half turn round the axis of rotation
1571 aPlane.Rotate(aRotAxis , M_PI/2);
1572 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1573 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1574 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1575 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1576 GetMapOfAIS().Bind (anAISPlane ,aName);
1577 TheAISContext()->Display(anAISPlane);
1581 std::cout<<" vplaneortho: error\n";
1591 //==============================================================================
1593 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1594 //==============================================================================
1596 //==============================================================================
1597 //function : VLineBuilder
1598 //purpose : Build an AIS_Line
1599 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1600 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1601 //==============================================================================
1602 #include <Geom_CartesianPoint.hxx>
1603 #include <AIS_Line.hxx>
1606 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1608 Standard_Integer myCurrentIndex;
1610 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1611 // Fermeture des contextes
1612 TheAISContext()->CloseAllContexts();
1614 // On recupere les parametres
1615 Handle(AIS_InteractiveObject) theShapeA;
1616 Handle(AIS_InteractiveObject) theShapeB;
1618 // Parametres: AIS_Point AIS_Point
1619 // ===============================
1622 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1623 // On verifie que c'est bien une AIS_Point
1624 if (!theShapeA.IsNull() &&
1625 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1626 // on recupere le deuxieme AIS_Point
1628 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1629 if (theShapeA.IsNull() ||
1630 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1632 di <<"vline error: wrong type of 2de argument."<<"\n";
1636 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1637 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1638 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1639 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1641 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1642 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1643 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1645 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1646 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1647 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1649 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1651 di<<"vline error: same points"<<"\n";return 1;
1653 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1654 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1655 GetMapOfAIS().Bind(theAISLine,argv[1] );
1656 TheAISContext()->Display(theAISLine );
1660 // Parametres 6 Reals
1661 // ==================
1664 // On verifie que les deux points ne sont pas confondus
1666 Standard_Real coord[6];
1667 for(Standard_Integer i=0;i<=2;i++){
1668 coord[i]=atof(argv[2+i]);
1669 coord[i+3]=atof(argv[5+i]);
1672 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1673 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1675 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1676 GetMapOfAIS().Bind(theAISLine,argv[1] );
1677 TheAISContext()->Display(theAISLine );
1681 // Pas de parametres: Selection dans le viewer.
1682 // ============================================
1685 TheAISContext()->OpenLocalContext();
1686 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1688 // Active le mode Vertex.
1689 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1690 di<<" Select a vertex "<<"\n";
1692 // Boucle d'attente waitpick.
1693 Standard_Integer argcc = 5;
1694 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1695 const char **argvv = (const char **) buff;
1696 while (ViewerMainLoop( argcc, argvv) ) { }
1699 TopoDS_Shape ShapeA;
1700 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1701 ShapeA = TheAISContext()->SelectedShape();
1704 // ShapeA est un Vertex
1705 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1707 di<<" Select a different vertex."<<"\n";
1709 TopoDS_Shape ShapeB;
1712 // Boucle d'attente waitpick.
1713 Standard_Integer argccc = 5;
1714 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1715 const char **argvvv = (const char **) bufff;
1716 while (ViewerMainLoop( argccc, argvvv) ) { }
1719 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1720 ShapeB = TheAISContext()->SelectedShape();
1724 } while(ShapeB.IsSame(ShapeA) );
1726 // Fermeture du context local
1727 TheAISContext()->CloseLocalContext(myCurrentIndex);
1729 // Construction de la line
1730 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1731 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1733 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1734 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1736 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1737 GetMapOfAIS().Bind(theAISLine,argv[1] );
1738 TheAISContext()->Display(theAISLine );
1742 di<<"vline error."<<"\n";
1750 //==============================================================================
1751 // class : FilledCircle
1752 // purpose : creates filled circle based on AIS_InteractiveObject
1754 // This class is used to check method Matches() of class
1755 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1756 // because none of AIS classes provides creation of
1757 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1758 // (look method ComputeSelection() )
1759 //==============================================================================
1761 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1763 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1764 gp_Circ aCirc(anAxes, theRadius);
1765 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1769 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1771 class FilledCircle : public AIS_InteractiveObject
1775 DEFINE_STANDARD_RTTI(FilledCircle);
1777 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1778 FilledCircle(Handle(Geom_Circle) theCircle);
1781 TopoDS_Face ComputeFace();
1783 // Virtual methods implementation
1784 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1785 const Handle(Prs3d_Presentation)& thePresentation,
1786 const Standard_Integer theMode);
1788 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1789 const Standard_Integer theMode);
1792 Handle(Geom_Circle) myCircle;
1793 Standard_Boolean myFilledStatus;
1797 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1798 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1800 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1802 myCircle = CreateCircle(theCenter, theRadius);
1803 myFilledStatus = Standard_True;
1806 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1808 myCircle = theCircle;
1809 myFilledStatus = Standard_True;
1812 TopoDS_Face FilledCircle::ComputeFace()
1814 // Create edge from myCircle
1815 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1816 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1818 // Create wire from anEdge
1819 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1820 TopoDS_Wire aWire = aWireMaker.Wire();
1822 // Create face from aWire
1823 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1824 TopoDS_Face aFace = aFaceMaker.Face();
1829 void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
1830 const Handle_Prs3d_Presentation &thePresentation,
1831 const Standard_Integer theMode)
1833 thePresentation->Clear();
1835 TopoDS_Face aFace = ComputeFace();
1837 if (aFace.IsNull()) return;
1838 if (theMode != 0) return;
1840 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1843 void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection,
1844 const Standard_Integer theMode)
1846 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1847 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1848 myCircle, myFilledStatus);
1849 theSelection->Add(aSensitiveCircle);
1852 //==============================================================================
1854 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1855 //==============================================================================
1857 //==============================================================================
1858 //function : VCircleBuilder
1859 //purpose : Build an AIS_Circle
1860 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1861 // PointName PointName PointName IsFilled
1862 //==============================================================================
1864 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1865 TCollection_AsciiString theName,
1866 Standard_Boolean isFilled)
1868 Handle(AIS_InteractiveObject) aCircle;
1871 aCircle = new FilledCircle(theGeomCircle);
1875 aCircle = new AIS_Circle(theGeomCircle);
1878 // Check if there is an object with given name
1879 // and remove it from context
1880 if (GetMapOfAIS().IsBound2(theName))
1882 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
1883 Handle(AIS_InteractiveObject) anInterObj =
1884 Handle(AIS_InteractiveObject)::DownCast(anObj);
1885 TheAISContext()->Remove(anInterObj, Standard_False);
1886 GetMapOfAIS().UnBind2(theName);
1889 // Bind the circle to its name
1890 GetMapOfAIS().Bind(aCircle, theName);
1892 // Display the circle
1893 TheAISContext()->Display(aCircle);
1897 static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1899 Standard_Integer myCurrentIndex;
1900 // Verification of the arguments
1901 if (argc>6 || argc<2)
1903 std::cout << "vcircle error: expect 4 arguments.\n";
1904 return 1; // TCL_ERROR
1906 TheAISContext()->CloseAllContexts();
1908 // There are all arguments
1912 TCollection_AsciiString aName(argv[1]);
1913 Standard_Boolean isFilled = (Standard_Boolean)atoi(argv[5]);
1915 Handle(AIS_InteractiveObject) theShapeA;
1916 Handle(AIS_InteractiveObject) theShapeB;
1919 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
1921 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
1924 // Arguments: AIS_Point AIS_Point AIS_Point
1925 // ========================================
1926 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
1927 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1929 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
1931 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
1932 return 1; // TCL_ERROR
1934 // The third object must be a point
1935 Handle(AIS_InteractiveObject) theShapeC =
1936 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
1937 if (theShapeC.IsNull() ||
1938 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
1940 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
1941 return 1; // TCL_ERROR
1944 // Verify that the three points are different
1945 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
1946 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
1947 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
1949 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
1950 Handle(Geom_CartesianPoint) myCartPointA =
1951 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
1953 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
1954 Handle(Geom_CartesianPoint) myCartPointB =
1955 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
1957 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
1958 Handle(Geom_CartesianPoint) myCartPointC =
1959 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
1962 if (abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
1963 abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
1964 abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
1966 std::cout << "vcircle error: Same points.\n";
1967 return 1; // TCL_ERROR
1970 if (abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
1971 abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1972 abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1974 std::cout << "vcircle error: Same points.\n";
1975 return 1; // TCL_ERROR
1978 if (abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
1979 abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1980 abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1982 std::cout << "vcircle error: Same points.\n";
1983 return 1;// TCL_ERROR
1985 // Construction of the circle
1986 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
1987 myCartPointB->Pnt(), myCartPointC->Pnt() );
1988 Handle (Geom_Circle) theGeomCircle;
1991 theGeomCircle = Cir.Value();
1993 catch (StdFail_NotDone)
1995 std::cout << "vcircle error: can't create circle\n";
1996 return -1; // TCL_ERROR
1999 DisplayCircle(theGeomCircle, aName, isFilled);
2002 // Arguments: AIS_Plane AIS_Point Real
2003 // ===================================
2004 else if (theShapeA->Type() == AIS_KOI_Datum &&
2005 theShapeA->Signature() == 7 )
2007 if (theShapeB->Type() != AIS_KOI_Datum ||
2008 theShapeB->Signature() != 1 )
2010 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2011 return 1; // TCL_ERROR
2013 // Ñheck that the radius is >= 0
2014 if (atof(argv[4]) <= 0 )
2016 std::cout << "vcircle error: the radius must be >=0.\n";
2017 return 1; // TCL_ERROR
2020 // Recover the normal to the plane
2021 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2022 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2024 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2025 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2026 Handle(Geom_CartesianPoint) myCartPointB =
2027 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2029 gp_Pln mygpPlane = myGeomPlane->Pln();
2030 gp_Ax1 thegpAxe = mygpPlane.Axis();
2031 gp_Dir theDir = thegpAxe.Direction();
2032 gp_Pnt theCenter = myCartPointB->Pnt();
2033 Standard_Real TheR = atof(argv[4]);
2034 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2035 Handle (Geom_Circle) theGeomCircle;
2038 theGeomCircle = Cir.Value();
2040 catch (StdFail_NotDone)
2042 std::cout << "vcircle error: can't create circle\n";
2043 return -1; // TCL_ERROR
2046 DisplayCircle(theGeomCircle, aName, isFilled);
2053 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2054 return 1; // TCL_ERROR
2058 // No arguments: selection in the viewer
2059 // =========================================
2062 // Get the name of the circle
2063 TCollection_AsciiString aName(argv[1]);
2065 TheAISContext()->OpenLocalContext();
2066 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2068 // Activate selection mode for vertices and faces
2069 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2070 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2071 std::cout << " Select a vertex or a face\n";
2074 Standard_Integer argcc = 5;
2075 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2076 const char **argvv = (const char **) buff;
2077 while (ViewerMainLoop( argcc, argvv) ) { }
2080 TopoDS_Shape ShapeA;
2081 for(TheAISContext()->InitSelected();
2082 TheAISContext()->MoreSelected();
2083 TheAISContext()->NextSelected() )
2085 ShapeA = TheAISContext()->SelectedShape();
2088 // ShapeA is a Vertex
2089 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2091 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2092 std::cout << " Select a different vertex\n";
2094 TopoDS_Shape ShapeB;
2098 Standard_Integer argccc = 5;
2099 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2100 const char **argvvv = (const char **) bufff;
2101 while (ViewerMainLoop( argccc, argvvv) ) { }
2104 for(TheAISContext()->InitSelected();
2105 TheAISContext()->MoreSelected();
2106 TheAISContext()->NextSelected() )
2108 ShapeB = TheAISContext()->SelectedShape();
2110 } while(ShapeB.IsSame(ShapeA) );
2112 // Selection of ShapeC
2113 std::cout << " Select the last vertex\n";
2114 TopoDS_Shape ShapeC;
2118 Standard_Integer argcccc = 5;
2119 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2120 const char **argvvvv = (const char **) buffff;
2121 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2124 for(TheAISContext()->InitSelected();
2125 TheAISContext()->MoreSelected();
2126 TheAISContext()->NextSelected() )
2128 ShapeC = TheAISContext()->SelectedShape();
2130 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2133 Standard_Boolean isFilled;
2134 std::cout << "Enter filled status (0 or 1)\n";
2137 // Close the local context
2138 TheAISContext()->CloseLocalContext(myCurrentIndex);
2140 // Construction of the circle
2141 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2142 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2143 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2145 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2146 Handle (Geom_Circle) theGeomCircle;
2149 theGeomCircle = Cir.Value();
2151 catch (StdFail_NotDone)
2153 std::cout << "vcircle error: can't create circle\n";
2154 return -1; // TCL_ERROR
2157 DisplayCircle(theGeomCircle, aName, isFilled);
2163 std::cout << " Select a vertex (in your face)\n";
2164 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2166 TopoDS_Shape ShapeB;
2168 Standard_Integer argccc = 5;
2169 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2170 const char **argvvv = (const char **) bufff;
2171 while (ViewerMainLoop( argccc, argvvv) ) { }
2174 for(TheAISContext()->InitSelected();
2175 TheAISContext()->MoreSelected();
2176 TheAISContext()->NextSelected() )
2178 ShapeB = TheAISContext()->SelectedShape();
2181 // Recover the radius
2182 Standard_Real theRad;
2185 std::cout << " Enter the value of the radius:\n";
2187 } while (theRad <= 0);
2189 // Get filled status
2190 Standard_Boolean isFilled;
2191 std::cout << "Enter filled status (0 or 1)\n";
2194 // Close the local context
2195 TheAISContext()->CloseLocalContext(myCurrentIndex);
2196 // Construction of the circle
2198 // Recover the normal to the plane. tag
2199 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2200 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2201 gp_Pln myPlane = mySurface.Plane();
2202 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2203 gp_Pln mygpPlane = theGeomPlane->Pln();
2204 gp_Ax1 thegpAxe = mygpPlane.Axis();
2205 gp_Dir theDir = thegpAxe.Direction();
2207 // Recover the center
2208 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2210 // Ñonstruct the circle
2211 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2212 Handle (Geom_Circle) theGeomCircle;
2215 theGeomCircle = Cir.Value();
2217 catch (StdFail_NotDone)
2219 std::cout << "vcircle error: can't create circle\n";
2220 return -1; // TCL_ERROR
2223 DisplayCircle(theGeomCircle, aName, isFilled);
2233 //===============================================================================================
2234 //function : VDrawText
2236 //purpose : Create a text.
2237 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2238 //===============================================================================================
2239 #include <Graphic3d_Group.hxx>
2240 #include <Graphic3d_Structure.hxx>
2241 #include <Graphic3d_NameOfFont.hxx>
2242 #include <Graphic3d_AspectText3d.hxx>
2243 #include <Graphic2d_GraphicObject.hxx>
2244 #include <Graphic3d_Array1OfVertex.hxx>
2245 #include <Graphic3d_AspectFillArea3d.hxx>
2246 #include <Graphic3d_StructureManager.hxx>
2247 #include <Graphic3d_VerticalTextAlignment.hxx>
2248 #include <Graphic3d_HorizontalTextAlignment.hxx>
2250 #include <Visual3d_ViewManager.hxx>
2251 #include <ViewerTest_Tool.ixx>
2253 #include <Standard_DefineHandle.hxx>
2255 #include <Prs3d_Root.hxx>
2256 #include <Prs3d_Text.hxx>
2257 #include <Prs3d_TextAspect.hxx>
2258 #include <Prs3d_ShadingAspect.hxx>
2259 #include <PrsMgr_PresentationManager3d.hxx>
2261 #include <TCollection_ExtendedString.hxx>
2262 #include <TCollection_AsciiString.hxx>
2264 #include <gp_Pnt.hxx>
2265 #include <Quantity_NameOfColor.hxx>
2266 #include <Quantity_Color.hxx>
2269 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2271 class MyTextClass:public AIS_InteractiveObject
2275 DEFINE_STANDARD_RTTI(MyTextClass );
2281 const TCollection_ExtendedString& , const gp_Pnt& ,
2282 Quantity_Color color,
2283 Standard_Integer aHJust,
2284 Standard_Integer aVJust ,
2285 Standard_Real Angle ,
2286 Standard_Boolean Zoom ,
2287 Standard_Real Height,
2288 OSD_FontAspect FontAspect,
2289 Standard_CString Font
2294 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2295 const Handle(Prs3d_Presentation)& aPresentation,
2296 const Standard_Integer aMode);
2298 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
2299 const Standard_Integer aMode){} ;
2302 TCollection_ExtendedString aText;
2305 Standard_Real Green;
2307 Standard_Real aAngle;
2308 Standard_Real aHeight;
2309 Standard_Boolean aZoomable;
2310 Quantity_Color aColor;
2311 Standard_CString aFont;
2312 OSD_FontAspect aFontAspect;
2313 Graphic3d_HorizontalTextAlignment aHJustification;
2314 Graphic3d_VerticalTextAlignment aVJustification;
2319 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2320 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2323 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2324 Quantity_Color color = Quantity_NOC_YELLOW,
2325 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2326 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2327 Standard_Real angle = 0.0 ,
2328 Standard_Boolean zoomable = Standard_True,
2329 Standard_Real height = 12.,
2330 OSD_FontAspect fontAspect = OSD_FA_Regular,
2331 Standard_CString font = "Courier")
2334 aPosition = position;
2335 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2336 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2338 aZoomable = zoomable;
2341 aFontAspect = fontAspect;
2347 //////////////////////////////////////////////////////////////////////////////
2348 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2349 const Handle(Prs3d_Presentation)& aPresentation,
2350 const Standard_Integer aMode)
2353 aPresentation->Clear();
2355 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2357 asp->SetFont(aFont);
2358 asp->SetColor(aColor);
2359 asp->SetHeight(aHeight); // I am changing the myHeight value
2361 asp->SetHorizontalJustification(aHJustification);
2362 asp->SetVerticalJustification(aVJustification);
2363 asp->Aspect()->SetTextZoomable(aZoomable);
2364 asp->Aspect()->SetTextAngle(aAngle);
2365 asp->Aspect()->SetTextFontAspect(aFontAspect);
2366 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2368 /* This comment code is worked
2369 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2370 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2371 Graphic3d_Vertex vertices_text;
2372 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2373 TheGroup->SetPrimitivesAspect(aspect);
2374 TheGroup->BeginPrimitives();
2375 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2376 TheGroup->EndPrimitives();
2380 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2385 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2386 di<<"Usage: type help "<<argv[0]<<"\n";
2387 return 1; //TCL_ERROR
2390 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2392 // Create 3D view if it doesn't exist
2393 if ( aContext.IsNull() )
2395 ViewerTest::ViewerInit();
2396 aContext = ViewerTest::GetAISContext();
2397 if( aContext.IsNull() )
2399 di << "Error: Cannot create a 3D view\n";
2400 return 1; //TCL_ERROR
2405 const Standard_Real X = atof(argv[2]);
2406 const Standard_Real Y = atof(argv[3]);
2407 const Standard_Real Z = atof(argv[4]);
2408 const gp_Pnt pnt(X,Y,Z);
2411 const Quantity_Parameter R = atof(argv[5])/255.;
2412 const Quantity_Parameter G = atof(argv[6])/255.;
2413 const Quantity_Parameter B = atof(argv[7])/255.;
2414 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2417 const int hor_align = atoi(argv[8]);
2418 const int ver_align = atoi(argv[9]);
2421 const Standard_Real angle = atof(argv[10]);
2424 const Standard_Boolean zoom = atoi(argv[11]);
2427 const Standard_Real height = atof(argv[12]);
2430 const OSD_FontAspect aspect = OSD_FontAspect(atoi(argv[13]));
2433 TCollection_AsciiString font;
2435 font.AssignCat("Courier");
2437 font.AssignCat(argv[14]);
2439 // Text is multibyte
2440 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (atoi(argv[15]) != 0);
2443 TCollection_ExtendedString name;
2446 const char *str = argv[1];
2447 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2448 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2450 unsigned short c1 = *str++;
2451 unsigned short c2 = *str++;
2453 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2463 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2464 aContext->Display(myT,Standard_True);
2471 #include <gp_Pnt.hxx>
2472 #include <Graphic3d_ArrayOfPoints.hxx>
2473 #include <Graphic3d_ArrayOfPrimitives.hxx>
2474 #include <Graphic3d_Array1OfVertex.hxx>
2475 #include <Graphic3d_ArrayOfTriangles.hxx>
2476 #include <Poly_Array1OfTriangle.hxx>
2477 #include <Poly_Triangle.hxx>
2478 #include <Poly_Triangulation.hxx>
2479 #include <TColgp_Array1OfPnt.hxx>
2480 #include <TShort_Array1OfShortReal.hxx>
2481 #include <TShort_HArray1OfShortReal.hxx>
2483 #include <AIS_Triangulation.hxx>
2484 #include <Aspect_GraphicDevice.hxx>
2485 #include <StdPrs_ToolShadedShape.hxx>
2486 #include <Poly_Connect.hxx>
2487 #include <TColgp_Array1OfDir.hxx>
2488 #include <Graphic3d_GraphicDriver.hxx>
2490 #include <TColStd_Array1OfInteger.hxx>
2491 #include <TColStd_HArray1OfInteger.hxx>
2492 #include <Prs3d_ShadingAspect.hxx>
2493 #include <Graphic3d_MaterialAspect.hxx>
2494 #include <Graphic3d_AspectFillArea3d.hxx>
2496 #include <BRepPrimAPI_MakeCylinder.hxx>
2497 #include <TopoDS_Shape.hxx>
2498 #include <TopExp_Explorer.hxx>
2499 #include <TopAbs.hxx>
2500 #include <StdSelect_ShapeTypeFilter.hxx>
2503 //===============================================================================================
2504 //function : CalculationOfSphere
2506 //purpose : Create a Sphere
2507 //===============================================================================================
2509 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2512 double mRadius = Radius;
2513 double mCenter[3] = {X,Y,Z};
2514 int mThetaResolution;
2516 double mStartTheta = 0;//StartTheta;
2517 double mEndTheta = 360;//EndTheta;
2518 double mStartPhi = 0;//StartPhi;
2519 double mEndPhi = 180;//EndPhi;
2520 res = res < 4 ? 4 : res;
2522 mThetaResolution = res;
2523 mPhiResolution = res;
2526 int jStart, jEnd, numOffset;
2527 int numPts, numPolys;
2528 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2529 double startTheta, endTheta, startPhi, endPhi;
2530 int base, numPoles=0, thetaResolution, phiResolution;
2535 if ( numPieces > mThetaResolution ) {
2536 numPieces = mThetaResolution;
2539 int localThetaResolution = mThetaResolution;
2540 double localStartTheta = mStartTheta;
2541 double localEndTheta = mEndTheta;
2543 while ( localEndTheta < localStartTheta ) {
2544 localEndTheta += 360.0;
2547 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2549 // Change the ivars based on pieces.
2551 start = piece * localThetaResolution / numPieces;
2552 end = (piece+1) * localThetaResolution / numPieces;
2553 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2554 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2555 localThetaResolution = end - start;
2557 numPts = mPhiResolution * localThetaResolution + 2;
2558 numPolys = mPhiResolution * 2 * localThetaResolution;
2560 // Create north pole if needed
2561 int number_point = 0;
2562 int number_pointArray = 0;
2564 if ( mStartPhi <= 0.0 ) {
2565 number_pointArray++;
2568 if ( mEndPhi >= 180.0 ) {
2569 number_pointArray++;
2573 // Check data, determine increments, and convert to radians
2574 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2575 startTheta *= M_PI / 180.0;
2576 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2577 endTheta *= M_PI / 180.0;
2580 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2581 startPhi *= M_PI / 180.0;
2582 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2583 endPhi *= M_PI / 180.0;
2585 phiResolution = mPhiResolution - numPoles;
2586 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2587 thetaResolution = localThetaResolution;
2588 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2589 ++localThetaResolution;
2591 deltaTheta = (endTheta - startTheta) / thetaResolution;
2593 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2594 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2596 // Create intermediate points
2597 for ( i = 0; i < localThetaResolution; i++ ) {
2598 for ( j = jStart; j < jEnd; j++ ) {
2599 number_pointArray++;
2603 //Generate mesh connectivity
2604 base = phiResolution * localThetaResolution;
2606 int number_triangle = 0 ;
2607 if ( mStartPhi <= 0.0 ) { // around north pole
2608 number_triangle += localThetaResolution;
2611 if ( mEndPhi >= 180.0 ) { // around south pole
2612 number_triangle += localThetaResolution;
2615 // bands in-between poles
2616 for ( i=0; i < localThetaResolution; i++){
2617 for ( j=0; j < (phiResolution-1); j++){
2618 number_triangle +=2;
2622 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2623 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2624 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2626 if ( mStartPhi <= 0.0 ){
2629 x[2] = mCenter[2] + mRadius;
2630 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2633 // Create south pole if needed
2634 if ( mEndPhi >= 180.0 ){
2637 x[2] = mCenter[2] - mRadius;
2638 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2642 for ( i=0; i < localThetaResolution; i++){
2643 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2644 for ( j = jStart; j < jEnd; j++){
2645 phi = startPhi + j*deltaPhi;
2646 radius = mRadius * sin((double)phi);
2647 n[0] = radius * cos((double)theta);
2648 n[1] = radius * sin((double)theta);
2649 n[2] = mRadius * cos((double)phi);
2650 x[0] = n[0] + mCenter[0];
2651 x[1] = n[1] + mCenter[1];
2652 x[2] = n[2] + mCenter[2];
2653 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2659 number_triangle = 1;
2660 if ( mStartPhi <= 0.0 ){// around north pole
2661 for (i=0; i < localThetaResolution; i++){
2662 pts[0] = phiResolution*i + numPoles;
2663 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2665 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2670 if ( mEndPhi >= 180.0 ){ // around south pole
2671 numOffset = phiResolution - 1 + numPoles;
2672 for (i=0; i < localThetaResolution; i++){
2673 pts[0] = phiResolution*i + numOffset;
2674 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2675 pts[1] = numPoles - 1;
2676 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2681 // bands in-between poles
2683 for (i=0; i < localThetaResolution; i++){
2684 for (j=0; j < (phiResolution-1); j++){
2685 pts[0] = phiResolution*i + j + numPoles;
2686 pts[1] = pts[0] + 1;
2687 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2688 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2691 pts[2] = pts[1] - 1;
2692 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2697 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2699 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2701 Standard_Integer index[3];
2702 Standard_Real Tol = Precision::Confusion();
2705 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2706 gp_XYZ eqPlan(0, 0, 0);
2707 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2708 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2709 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2710 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2712 Standard_Real mod = vv.Modulus();
2713 if(mod < Tol) continue;
2717 Standard_Real modmax = eqPlan.Modulus();
2720 Nor = gp_Dir(eqPlan);
2722 Nor = gp_Dir(0., 0., 1.);
2724 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2725 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2726 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2727 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2731 polyTriangulation->SetNormals(Normals);
2733 return polyTriangulation;
2736 //===============================================================================================
2737 //function : VDrawSphere
2739 //purpose : Create an AIS shape.
2740 //===============================================================================================
2741 static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2744 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2745 if (aContextAIS.IsNull())
2747 std::cout << "Call vinit before!\n";
2752 std::cout << "Use: " << argv[0]
2753 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
2757 // read the arguments
2758 TCollection_AsciiString aShapeName (argv[1]);
2759 Standard_Integer aResolution = atoi (argv[2]);
2760 Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0;
2761 Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
2762 Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
2763 Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
2764 Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True;
2765 Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1;
2766 Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False;
2768 if (aRedrawsNb <= 0)
2773 // remove AIS object with given name from map
2774 if (GetMapOfAIS().IsBound2 (aShapeName))
2776 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aShapeName);
2777 Handle(AIS_InteractiveObject) anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
2778 if (anInterObj.IsNull())
2780 std::cout << "Shape name was used for non AIS viewer\n!";
2783 aContextAIS->Remove (anInterObj, Standard_False);
2784 GetMapOfAIS().UnBind2 (aShapeName);
2787 // enable/disable VBO
2788 Handle(Graphic3d_GraphicDriver) aDriver =
2789 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2790 if (!aDriver.IsNull())
2792 aDriver->EnableVBO (isVBOEnabled);
2795 std::cout << "Compute Triangulation...\n";
2796 Handle(AIS_Triangulation) aShape
2797 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2800 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2801 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2803 // register the object in map
2804 GetMapOfAIS().Bind (aShape, aShapeName);
2806 // stupid initialization of Green color in RGBA space as integer
2807 // probably wrong for big-endian CPUs
2808 Standard_Integer aRed = 0;
2809 Standard_Integer aGreen = 255;
2810 Standard_Integer aBlue = 0;
2811 Standard_Integer anAlpha = 0; // not used
2812 Standard_Integer aColorInt = aRed;
2813 aColorInt += aGreen << 8;
2814 aColorInt += aBlue << 16;
2815 aColorInt += anAlpha << 24;
2817 // setup colors array per vertex
2818 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2819 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2821 aColorArray->SetValue (aNodeId, aColorInt);
2823 aShape->SetColors (aColorArray);
2826 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2827 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2828 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2829 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2830 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2831 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2832 aTotalSize >>= 20; //MB
2833 aNormalsSize >>= 20;
2835 aTrianglesSize >>= 20;
2836 aPolyConnectSize >>= 20;
2837 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2838 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2839 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2840 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2841 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2842 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2844 // Setting material properties, very important for desirable visual result!
2845 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2846 aMat.SetAmbient (0.2);
2847 aMat.SetSpecular (0.5);
2848 Handle(Graphic3d_AspectFillArea3d) anAspect
2849 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2851 Quantity_NOC_YELLOW,
2856 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2859 anAspect->SetEdgeOn();
2863 anAspect->SetEdgeOff();
2865 aShAsp->SetAspect (anAspect);
2866 aShape->Attributes()->SetShadingAspect (aShAsp);
2868 aContextAIS->Display (aShape, Standard_False);
2870 // Two viewer updates are needed in order to measure time spent on
2871 // loading triangulation to graphic card memory + redrawing (1st update) and
2872 // time spent on redrawing itself (2nd and all further updates)
2873 OSD_Chronometer aTimer;
2874 Standard_Real aUserSeconds, aSystemSeconds;
2876 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2877 for (Standard_Integer anInteration = 0; anInteration < aRedrawsNb; ++anInteration)
2879 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
2881 if (anInteration == 0)
2883 aViewer->ActiveView()->Update();
2887 aViewer->ActiveView()->Redraw();
2891 aTimer.Show (aUserSeconds, aSystemSeconds);
2893 std::cout << "Number of scene redrawings: " << aRedrawsNb << "\n"
2894 << "CPU user time: "
2895 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aUserSeconds
2897 << "CPU system time: "
2898 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aSystemSeconds
2900 << "CPU average time of scene redrawing: "
2901 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * (aUserSeconds / (Standard_Real )aRedrawsNb)
2906 //===============================================================================================
2907 //function : VClipPlane
2909 //===============================================================================================
2910 static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2912 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2913 Handle(V3d_View) aView = ViewerTest::CurrentView();
2914 Standard_Real coeffA, coeffB, coeffC, coeffD;
2915 if (aViewer.IsNull() || aView.IsNull())
2917 std::cout << "Viewer not initialized!\n";
2921 // count an active planes count
2922 Standard_Integer aNewPlaneId = 1;
2923 Standard_Integer anActivePlanes = 0;
2924 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
2926 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2927 if (aView->IsActivePlane (aPlaneV3d))
2935 // just show info about existing planes
2936 Standard_Integer aPlaneId = 1;
2937 std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
2938 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2940 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2941 aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
2942 gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
2943 const gp_Pnt& aLoc = aPlane.Location();
2944 const gp_Dir& aNor = aPlane.Axis().Direction();
2945 Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
2946 std::cout << "Plane #" << aPlaneId
2947 << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
2948 << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
2949 << (isActive ? " on" : " off")
2950 << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
2955 std::cout << "No defined clipping planes\n";
2959 else if (argc == 2 || argc == 3)
2961 Standard_Integer aPlaneIdToOff = (argc == 3) ? atoi (argv[1]) : 1;
2962 Standard_Boolean toIterateAll = (argc == 2);
2963 TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
2964 isOnOffStr.LowerCase();
2965 Standard_Integer aPlaneId = 1;
2966 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2968 if (aPlaneIdToOff == aPlaneId || toIterateAll)
2970 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2971 if (isOnOffStr.Search ("off") >= 0)
2973 aView->SetPlaneOff (aPlaneV3d);
2974 std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
2976 else if (isOnOffStr.Search ("on") >= 0)
2978 // avoid z-fighting glitches
2980 if (!aView->IsActivePlane (aPlaneV3d))
2982 if (anActivePlanes < aView->View()->PlaneLimit())
2984 aView->SetPlaneOn (aPlaneV3d);
2985 std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
2989 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2990 << "You should disable or remove some existing plane to activate this one\n";
2995 std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
2998 else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
3000 aPlaneV3d->Erase(); // not performed on destructor!!!
3001 aView->SetPlaneOff (aPlaneV3d);
3002 aViewer->DelPlane (aPlaneV3d);
3003 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
3006 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
3008 aPlaneV3d = aViewer->DefinedPlane();
3009 aPlaneV3d->Erase(); // not performed on destructor!!!
3010 aView->SetPlaneOff (aPlaneV3d);
3011 aViewer->DelPlane (aPlaneV3d);
3012 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
3021 else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
3023 // avoid z-fighting glitches
3024 aView->SetPlaneOff (aPlaneV3d);
3025 aPlaneV3d->Display (aView);
3026 std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
3028 else if (isOnOffStr.Search ("hide") >= 0)
3031 std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
3035 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
3040 if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
3042 std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
3050 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
3054 Standard_Real aLocX = atof (argv[1]);
3055 Standard_Real aLocY = atof (argv[2]);
3056 Standard_Real aLocZ = atof (argv[3]);
3057 Standard_Real aNormDX = atof (argv[4]);
3058 Standard_Real aNormDY = atof (argv[5]);
3059 Standard_Real aNormDZ = atof (argv[6]);
3061 Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
3062 gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
3063 aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
3064 aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
3066 aViewer->AddPlane (aPlaneV3d); // add to defined planes list
3067 std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
3068 if (anActivePlanes < aView->View()->PlaneLimit())
3070 aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
3075 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
3076 << "You should disable or remove some existing plane to activate the new one\n";
3081 //=============================================================================
3082 //function : VComputeHLR
3084 //=============================================================================
3086 static int VComputeHLR (Draw_Interpretor& di,
3087 Standard_Integer argc,
3090 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3092 if (aContextAIS.IsNull ())
3094 di << "Please call vinit before\n";
3098 if ( argc != 3 && argc != 12 )
3100 di << "Usage: " << argv[0] << " ShapeName HlrName "
3101 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3102 << " ShapeName - name of the initial shape\n"
3103 << " HlrName - result hlr object from initial shape\n"
3104 << " eye, dir are eye position and look direction\n"
3105 << " up is the look up direction vector\n"
3106 << " Use vtop to see projected hlr shape\n";
3110 // shape and new object name
3111 TCollection_AsciiString aShapeName (argv[1]);
3112 TCollection_AsciiString aHlrName (argv[2]);
3114 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3117 BRep_Builder aBrepBuilder;
3118 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3121 di << "No shape with name " << argv[1] << " found\n";
3126 if (GetMapOfAIS ().IsBound2 (aHlrName))
3128 di << "Presentable object with name " << argv[2] << " already exists\n";
3132 // close local context
3133 if (aContextAIS->HasOpenedContext ())
3134 aContextAIS->CloseLocalContext ();
3136 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3137 HLRBRep_PolyHLRToShape aHLRToShape;
3146 anEye.SetCoord (atof (argv[3]), atof (argv[4]), atof (argv[5]));
3147 aDir.SetCoord (atof (argv[6]), atof (argv[7]), atof (argv[8]));
3148 anUp.SetCoord (atof (argv[9]), atof (argv[10]), atof (argv[11]));
3149 aProjAx.SetLocation (anEye);
3150 aProjAx.SetDirection (aDir);
3151 aProjAx.SetYDirection (anUp);
3157 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3158 Handle(V3d_View) aView = ViewerTest::CurrentView();
3159 Standard_Integer aWidth, aHeight;
3160 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3161 Standard_Real aRightX, aRightY, aRightZ;
3162 aView->Window()->Size (aWidth, aHeight);
3164 aView->ConvertWithProj (aWidth, aHeight/2,
3165 aRightX, aRightY, aRightZ,
3166 aDirX, aDirY, aDirZ);
3168 aView->ConvertWithProj (aWidth/2, aHeight/2,
3169 aCentX, aCentY, aCentZ,
3170 aDirX, aDirY, aDirZ);
3172 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3173 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3174 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3175 aProjAx.SetLocation (anEye);
3176 aProjAx.SetDirection (aDir);
3177 aProjAx.SetXDirection (aRight);
3180 HLRAlgo_Projector aProjector (aProjAx);
3181 aPolyAlgo->Projector (aProjector);
3182 aPolyAlgo->Load (aSh);
3183 aPolyAlgo->Update ();
3185 aHLRToShape.Update (aPolyAlgo);
3187 // make hlr shape from input shape
3188 TopoDS_Compound aHlrShape;
3189 BRep_Builder aBuilder;
3190 aBuilder.MakeCompound (aHlrShape);
3192 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3193 if (!aCompound.IsNull ())
3195 aBuilder.Add (aHlrShape, aCompound);
3198 // extract visible outlines
3199 aCompound = aHLRToShape.OutLineVCompound();
3200 if (!aCompound.IsNull ())
3202 aBuilder.Add (aHlrShape, aCompound);
3205 // create an AIS shape and display it
3206 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3207 GetMapOfAIS().Bind (anObject, aHlrName);
3208 aContextAIS->Display (anObject);
3210 aContextAIS->UpdateCurrentViewer ();
3215 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3216 // manipulating and displaying such an array with AIS context
3217 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3218 class MyPArrayObject : public AIS_InteractiveObject
3223 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray)
3228 DEFINE_STANDARD_RTTI(MyPArrayObject);
3232 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3233 const Handle(Prs3d_Presentation)& aPresentation,
3234 const Standard_Integer aMode);
3236 void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
3237 const Standard_Integer aMode) {};
3241 Handle(Graphic3d_ArrayOfPrimitives) myArray;
3245 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3246 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3248 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3249 const Handle(Prs3d_Presentation)& aPresentation,
3250 const Standard_Integer aMode)
3252 aPresentation->Clear();
3254 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
3255 aGroup->BeginPrimitives ();
3256 aGroup->AddPrimitiveArray (myArray);
3257 aGroup->EndPrimitives ();
3260 static bool CheckInputCommand (const TCollection_AsciiString theCommand,
3261 const char **theArgStr, int &theArgIndex,
3262 int theArgCount, int theMaxArgs)
3264 // check if there is more elements than expected
3265 if (theArgIndex >= theMaxArgs)
3268 TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
3269 aStrCommand.LowerCase();
3270 if (aStrCommand.Search(theCommand) != 1 ||
3271 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3274 // go to the first data element
3277 // check data if it can be converted to numeric
3278 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3280 aStrCommand = theArgStr[theArgIndex];
3281 if (!aStrCommand.IsRealValue())
3288 //=============================================================================
3289 //function : VDrawPArray
3290 //purpose : Draws primitives array from list of vertexes, bounds, edges
3291 //=============================================================================
3293 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3295 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3296 if (aContextAIS.IsNull())
3298 di << "Call vinit before!\n";
3303 di << "Use: " << argv[0] << " Name TypeOfArray [EnableVBO={0 | 1}]"
3304 << " [vertex] ... [bounds] ... [edges]\n"
3305 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3306 << " trianglefan | trianglestrips | quads |\n"
3307 << " quadstrips | polygons }\n"
3308 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3309 << " [texel={ 't' tx ty }] } \n"
3310 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3311 << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
3315 // read the arguments
3316 TCollection_AsciiString aName (argv[1]);
3317 TCollection_AsciiString anArrayType (argv[2]);
3319 // is argument list has an vbo flag
3320 Standard_Boolean hasFlagVbo = Standard_False;
3321 if (isdigit (argv[3][0]) && atoi (argv[3]) >= 0 && atoi (argv[3]) <= 1)
3322 hasFlagVbo = Standard_True;
3324 // parse number of verticies, bounds, edges
3325 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3326 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3327 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3329 Standard_Integer aArgIndex = (hasFlagVbo) ? 4 : 3;
3330 TCollection_AsciiString aCommand;
3331 while (aArgIndex < argc)
3333 aCommand = argv[aArgIndex];
3334 aCommand.LowerCase();
3335 if (!aCommand.IsAscii())
3337 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3338 << "should be an array element: 'v', 'b', 'e' \n";
3343 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3345 // vertex has a normal or normal with color or texel
3346 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3347 hasNormals = Standard_True;
3349 // vertex has a color
3350 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3351 hasVColors = Standard_True;
3353 // vertex has a texel
3354 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3355 hasTexels = Standard_True;
3360 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3363 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3364 hasBColors = Standard_True;
3369 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3371 // edge has a hide flag
3372 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3373 hasInfos = Standard_True;
3382 if (aVertexNum == 0)
3384 di << "You should pass any verticies in the list of array elements\n";
3388 // create an array of primitives by types
3389 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3390 if (anArrayType == "points")
3391 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3392 else if (anArrayType == "segments")
3393 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3394 else if (anArrayType == "polylines")
3395 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3396 hasVColors, hasBColors, hasInfos);
3397 else if (anArrayType == "triangles")
3398 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3399 hasVColors, hasTexels, hasInfos);
3400 else if (anArrayType == "trianglefans")
3401 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3402 hasNormals, hasVColors,
3403 hasBColors, hasTexels);
3404 else if (anArrayType == "trianglestrips")
3405 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3406 hasNormals, hasVColors,
3407 hasBColors, hasTexels);
3408 else if (anArrayType == "quads")
3409 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3410 hasNormals, hasVColors,
3411 hasTexels, hasInfos);
3412 else if (anArrayType == "quadstrips")
3413 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3414 hasNormals, hasVColors,
3415 hasBColors, hasTexels);
3416 else if (anArrayType == "polygons")
3417 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3418 hasNormals, hasVColors, hasBColors,
3419 hasTexels, hasInfos);
3422 di << "Unexpected type of primitiives array\n";
3426 // parse an array of primitives
3427 aArgIndex = (hasFlagVbo) ? 4 : 3;
3428 while (aArgIndex < argc)
3430 aCommand = argv[aArgIndex];
3431 aCommand.LowerCase();
3432 if (!aCommand.IsAscii())
3436 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3438 anArray->AddVertex (atof (argv[aArgIndex - 3]),
3439 atof (argv[aArgIndex - 2]),
3440 atof (argv[aArgIndex - 1]));
3442 // vertex has a normal or normal with color or texel
3443 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3444 anArray->SetVertexNormal (anArray->VertexNumber (),
3445 atof (argv[aArgIndex - 3]),
3446 atof (argv[aArgIndex - 2]),
3447 atof (argv[aArgIndex - 1]));
3449 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3450 anArray->SetVertexColor (anArray->VertexNumber (),
3451 atof (argv[aArgIndex - 3]),
3452 atof (argv[aArgIndex - 2]),
3453 atof (argv[aArgIndex - 1]));
3455 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3456 anArray->SetVertexTexel (anArray->VertexNumber (),
3457 atof (argv[aArgIndex - 2]),
3458 atof (argv[aArgIndex - 1]));
3461 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3463 Standard_Integer aVertCount = atoi (argv[aArgIndex - 1]);
3465 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3466 anArray->AddBound (aVertCount,
3467 atof (argv[aArgIndex - 3]),
3468 atof (argv[aArgIndex - 2]),
3469 atof (argv[aArgIndex - 1]));
3472 anArray->AddBound (aVertCount);
3475 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3477 Standard_Integer aVertIndex = atoi (argv[aArgIndex - 1]);
3479 // edge has/hasn't hide flag
3480 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3481 anArray->AddEdge (aVertIndex, Standard_False);
3483 anArray->AddEdge (aVertIndex, Standard_True);
3492 // enable / disable vbo
3493 Handle(Graphic3d_GraphicDriver) aDriver =
3494 Handle(Graphic3d_GraphicDriver)::DownCast (
3495 aContextAIS->CurrentViewer()->Device()->GraphicDriver());
3497 if (!aDriver.IsNull())
3498 aDriver->EnableVBO ((Standard_Boolean) atoi (argv[3]));
3501 // create primitives array object
3502 Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
3504 // register the object in map
3505 VDisplayAISObject (aName, aPObject);
3510 //=======================================================================
3511 //function : VSetLocation
3512 //purpose : Change location of AIS interactive object
3513 //=======================================================================
3515 static Standard_Integer VSetLocation (Draw_Interpretor& di,
3516 Standard_Integer argc,
3519 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3520 if (aContext.IsNull())
3522 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3528 di << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
3532 TCollection_AsciiString aName (argv[1]);
3533 Standard_Real aX = atof (argv[2]);
3534 Standard_Real aY = atof (argv[3]);
3535 Standard_Real aZ = atof (argv[4]);
3538 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3539 Handle(AIS_InteractiveObject) anIObj;
3540 if (!aMap.IsBound2 (aName))
3542 di << "Use 'vdisplay' before" << "\n";
3547 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3549 // not an AIS_InteractiveObject
3550 if (anIObj.IsNull())
3552 di << argv[1] << " : Not an AIS interactive object" << "\n";
3557 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
3558 TopLoc_Location aLocation (aTrsf);
3559 aContext->SetLocation (anIObj, aLocation);
3560 aContext->UpdateCurrentViewer();
3566 //===============================================================================================
3567 //function : VConnect
3568 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3569 //Draw arg : vconnect name object Xo Yo Zo Xu Xv Xw Zu Zv Zw
3570 //===============================================================================================
3572 static Standard_Integer VConnect(Draw_Interpretor& di,
3573 Standard_Integer argc,
3579 std::cout << "vconnect error: expect 11 argumnets\n";
3580 return 1; // TCL_ERROR
3583 TCollection_AsciiString aName(argv[1]);
3584 TCollection_AsciiString anOriginObjectName(argv[2]);
3585 if(aName.IsEqual(anOriginObjectName))
3587 std::cout << "vconnect error: equal names for connected objects\n";
3588 return 1; // TCL_ERROR
3590 // Check if the origin shape is not null
3591 Handle(AIS_InteractiveObject) anOriginObject;
3592 if(GetMapOfAIS().IsBound2(anOriginObjectName))
3594 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginObjectName);
3595 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3596 if(anOriginObject.IsNull())
3598 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n!";
3599 return 1; // TCL_ERROR
3603 // Get location data
3604 Standard_Real aXo = atof(argv[3]);
3605 Standard_Real aYo = atof(argv[4]);
3606 Standard_Real aZo = atof(argv[5]);
3607 Standard_Real aXu = atof(argv[6]);
3608 Standard_Real aXv = atof(argv[7]);
3609 Standard_Real aXw = atof(argv[8]);
3610 Standard_Real aZu = atof(argv[9]);
3611 Standard_Real aZv = atof(argv[10]);
3612 Standard_Real aZw = atof(argv[11]);
3614 // Create transformation
3615 gp_Pnt aPoint(aXo, aYo, aZo);
3616 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3617 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3619 std::cout << "vconnect error : XDir expects to be normal to ZDir\n";
3620 return 1; // TCL_ERROR
3622 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3624 aTrsf.SetTransformation(anAx3);
3625 TopLoc_Location aLocation(aTrsf);
3627 // Create connected object
3628 Handle(AIS_ConnectedInteractive) aConnectedObject = new AIS_ConnectedInteractive();
3629 aConnectedObject->Connect(anOriginObject, aLocation);
3631 // Check if there is another object with given name
3632 // and remove it from context
3633 if(GetMapOfAIS().IsBound2(aName))
3635 Handle(AIS_InteractiveObject) anObj =
3636 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3637 TheAISContext()->Remove(anObj, Standard_False);
3638 GetMapOfAIS().UnBind2(aName);
3641 // Bind connected object to its name
3642 GetMapOfAIS().Bind(aConnectedObject, aName);
3644 // Display connected object
3645 TheAISContext()->Display(aConnectedObject);
3650 //===============================================================================================
3651 //function : VConnectShape
3652 //purpose : Creates and displays AIS_ConnectedShape from input shape and location
3653 //Draw arg : vconnectsh name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw
3654 //===============================================================================================
3656 static Standard_Integer VConnectShape(Draw_Interpretor& di,
3657 Standard_Integer argc,
3663 std::cout << "vconnectsh error: expect 11 argumnets\n";
3664 return 1; // TCL_ERROR
3667 TCollection_AsciiString aName(argv[1]);
3668 TCollection_AsciiString anOriginShapeName(argv[2]);
3669 if(aName.IsEqual(anOriginShapeName))
3671 std::cout << "vconnectsh error: equal names for connected shapes\n";
3672 return 1; // TCL_ERROR
3674 // Check if the origin shape is not null
3675 Handle(AIS_InteractiveObject) anOriginShape;
3676 if(GetMapOfAIS().IsBound2(anOriginShapeName))
3678 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginShapeName);
3679 anOriginShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3680 if(anOriginShape.IsNull())
3682 std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
3683 return 1; // TCL_ERROR
3687 // Get location data
3688 Standard_Real aXo = atof(argv[3]);
3689 Standard_Real aYo = atof(argv[4]);
3690 Standard_Real aZo = atof(argv[5]);
3691 Standard_Real aXu = atof(argv[6]);
3692 Standard_Real aXv = atof(argv[7]);
3693 Standard_Real aXw = atof(argv[8]);
3694 Standard_Real aZu = atof(argv[9]);
3695 Standard_Real aZv = atof(argv[10]);
3696 Standard_Real aZw = atof(argv[11]);
3698 // Create transformation
3699 gp_Pnt aPoint(aXo, aYo, aZo);
3700 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3701 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3703 std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n";
3704 return 1; // TCL_ERROR
3706 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3708 aTrsf.SetTransformation(anAx3);
3709 TopLoc_Location aLocation(aTrsf);
3711 // Create connected shape
3712 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anOriginShape);
3713 Handle(AIS_ConnectedShape) aConnectedShape = new AIS_ConnectedShape(aShape);
3714 aConnectedShape->Connect(anOriginShape, aLocation);
3716 // Check if there is another object with given name
3717 // and remove it from context
3718 if(GetMapOfAIS().IsBound2(aName))
3720 Handle(AIS_InteractiveObject) anObj =
3721 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3722 TheAISContext()->Remove(anObj, Standard_False);
3723 GetMapOfAIS().UnBind2(aName);
3726 // Bind connected shape to its name
3727 GetMapOfAIS().Bind(aConnectedShape, aName);
3729 // Display connected shape
3730 TheAISContext()->Display(aConnectedShape);
3735 //===============================================================================================
3736 //function : VSetSelectionMode
3737 //purpose : Sets input selection mode for input object or for all displayed objects
3738 //Draw arg : vselmode [object] mode On/Off (1/0)
3739 //===============================================================================================
3741 // function : InList
3742 // purpose : checks if theMode is already turned on for theObj
3743 Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext,
3744 Handle(AIS_InteractiveObject) theObj,
3745 Standard_Integer theMode)
3747 TColStd_ListOfInteger anArray;
3748 theAISContext->ActivatedModes(theObj, anArray);
3749 TColStd_ListIteratorOfListOfInteger anIt(anArray);
3750 for(; anIt.More(); anIt.Next())
3752 if(anIt.Value() == theMode)
3753 return Standard_True;
3755 return Standard_False;
3758 static Standard_Integer VSetSelectionMode(Draw_Interpretor& di,
3759 Standard_Integer argc,
3763 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3764 if(anAISContext.IsNull())
3766 std::cout << "Call vinit before!\n";
3767 return 1; // TCL_ERROR
3770 // Check the arguments
3771 if(argc != 3 && argc != 4)
3773 std::cout << "vselmode error : expects at least 2 arguments\n";
3774 return 1; // TCL_ERROR
3777 Handle(AIS_InteractiveObject) anObj;
3779 // Set new selection mode for all objects in context
3783 Standard_Integer aMode = atoi(argv[1]);
3784 Standard_Boolean isTurnOn = atoi(argv[2]);
3786 // Get all displayed objects
3787 AIS_ListOfInteractive anObjList;
3788 anAISContext->DisplayedObjects(anObjList);
3789 AIS_ListIteratorOfListOfInteractive anObjIter;
3793 if(anAISContext->HasOpenedContext())
3794 anAISContext->CloseLocalContext();
3798 if(aMode != 0 && isTurnOn)
3800 if(!anAISContext->HasOpenedContext())
3802 anAISContext->OpenLocalContext();
3803 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3805 anAISContext->Activate(anObjIter.Value(), aMode);
3810 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3812 anObj = anObjIter.Value();
3813 if(!InList(anAISContext, anObj, aMode))
3814 anAISContext->Activate(anObj, aMode);
3820 if(aMode != 0 && !isTurnOn)
3822 if(anAISContext->HasOpenedContext())
3824 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3826 anObj = anObjIter.Value();
3827 if(InList(anAISContext, anObj, aMode))
3828 anAISContext->Deactivate(anObj, aMode);
3834 // Set new selection mode for named object
3838 Standard_Integer aMode = atoi(argv[2]);
3839 Standard_Boolean isTurnOn = atoi(argv[3]);
3840 TCollection_AsciiString aName(argv[1]);
3842 // Check if there is an object with given name in context
3843 if(GetMapOfAIS().IsBound2(aName))
3845 anObj = Handle(AIS_InteractiveObject)::
3846 DownCast(GetMapOfAIS().Find2(aName));
3849 std::cout << "vselmode error : object name is used for non AIS viewer\n";
3850 return 1; // TCL_ERROR
3856 if(anAISContext->HasOpenedContext())
3857 anAISContext->CloseLocalContext();
3860 if(aMode != 0 && isTurnOn)
3862 if(!anAISContext->HasOpenedContext())
3864 anAISContext->OpenLocalContext();
3865 anAISContext->Activate(anObj, aMode);
3869 if(!InList(anAISContext, anObj, aMode))
3870 anAISContext->Activate(anObj, aMode);
3875 if(aMode != 0 && !isTurnOn)
3877 if(anAISContext->HasOpenedContext())
3879 if(InList(anAISContext, anObj, aMode))
3880 anAISContext->Deactivate(anObj, aMode);
3887 //==========================================================================
3889 //purpose : creates Triangle based on AIS_InteractiveObject.
3890 // This class was implemented for testing Select3D_SensitiveTriangle
3891 //===========================================================================
3892 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3893 class Triangle: public AIS_InteractiveObject
3897 DEFINE_STANDARD_RTTI(FilledCircle);
3898 Triangle (const gp_Pnt& theP1,
3899 const gp_Pnt& theP2,
3900 const gp_Pnt& theP3);
3902 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3903 const Handle(Prs3d_Presentation)& thePresentation,
3904 const Standard_Integer theMode);
3906 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
3907 const Standard_Integer theMode);
3913 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3914 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
3916 Triangle::Triangle (const gp_Pnt& theP1,
3917 const gp_Pnt& theP2,
3918 const gp_Pnt& theP3)
3925 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3926 const Handle(Prs3d_Presentation)& thePresentation,
3927 const Standard_Integer theMode)
3929 thePresentation->Clear();
3931 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
3932 anEdgeMaker2(myPoint2, myPoint3),
3933 anEdgeMaker3(myPoint3, myPoint1);
3935 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
3936 anEdge2 = anEdgeMaker2.Edge(),
3937 anEdge3 = anEdgeMaker3.Edge();
3938 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
3941 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
3942 TopoDS_Wire aWire = aWireMaker.Wire();
3943 if(aWire.IsNull()) return;
3945 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
3946 TopoDS_Face aFace = aFaceMaker.Face();
3947 if(aFace.IsNull()) return;
3949 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
3952 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
3953 const Standard_Integer theMode)
3955 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
3956 Handle(Select3D_SensitiveTriangle) aSensTriangle =
3957 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
3958 theSelection->Add(aSensTriangle);
3961 //===========================================================================
3962 //function : VTriangle
3963 //Draw arg : vtriangle Name PointName PointName PointName
3964 //purpose : creates and displays Triangle
3965 //===========================================================================
3968 //purpose : checks if the object with theName is AIS_Point,
3969 // if yes initialize thePoint from MapOfAIS
3970 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
3971 Handle(AIS_Point)& thePoint)
3973 Handle(AIS_InteractiveObject) anObject =
3974 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
3975 if(anObject.IsNull() ||
3976 anObject->Type() != AIS_KOI_Datum ||
3977 anObject->Signature() != 1)
3979 return Standard_False;
3981 thePoint = Handle(AIS_Point)::DownCast(anObject);
3982 if(thePoint.IsNull())
3983 return Standard_False;
3984 return Standard_True;
3988 //purpose: checks if thePoint1 is equal to thePoint2
3989 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
3990 const Handle(Geom_CartesianPoint)& thePoint2)
3992 if(abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
3993 abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
3994 abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
3996 return Standard_True;
3998 return Standard_False;
4001 static Standard_Integer VTriangle (Draw_Interpretor& di,
4002 Standard_Integer argc,
4008 std::cout<<"vtriangle error: expects 4 argumnets\n";
4009 return 1; // TCL_ERROR
4012 TheAISContext()->CloseAllContexts();
4014 // Get and check values
4015 TCollection_AsciiString aName(argv[1]);
4017 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4018 if (!IsPoint(argv[2], aPoint1))
4020 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4021 return 1; // TCL_ERROR
4023 if (!IsPoint(argv[3], aPoint2))
4025 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4026 return 1; // TCL_ERROR
4028 if (!IsPoint(argv[4], aPoint3))
4030 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4031 return 1; // TCL_ERROR
4034 // Check that points are different
4035 Handle(Geom_CartesianPoint) aCartPoint1 =
4036 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4037 Handle(Geom_CartesianPoint) aCartPoint2 =
4038 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4039 // Test aPoint1 = aPoint2
4040 if (IsMatch(aCartPoint1, aCartPoint2))
4042 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4043 return 1; // TCL_ERROR
4045 // Test aPoint2 = aPoint3
4046 Handle(Geom_CartesianPoint) aCartPoint3 =
4047 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4048 if (IsMatch(aCartPoint2, aCartPoint3))
4050 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4051 return 1; // TCL_ERROR
4053 // Test aPoint3 = aPoint1
4054 if (IsMatch(aCartPoint1, aCartPoint3))
4056 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4057 return 1; // TCL_ERROR
4061 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4063 aCartPoint3->Pnt());
4065 // Check if there is an object with given name
4066 // and remove it from context
4067 if (GetMapOfAIS().IsBound2(aName))
4069 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4070 Handle(AIS_InteractiveObject) anInterObj =
4071 Handle(AIS_InteractiveObject)::DownCast(anObj);
4072 TheAISContext()->Remove(anInterObj, Standard_False);
4073 GetMapOfAIS().UnBind2(aName);
4076 // Bind triangle to its name
4077 GetMapOfAIS().Bind(aTriangle, aName);
4080 TheAISContext()->Display(aTriangle);
4084 //class : SegmentObject
4085 //purpose: creates segment based on AIS_InteractiveObject.
4086 // This class was implemented for testing Select3D_SensitiveCurve
4087 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4088 class SegmentObject: public AIS_InteractiveObject
4092 DEFINE_STANDARD_RTTI(SegmentObject);
4093 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4095 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4096 const Handle(Prs3d_Presentation)& thePresentation,
4097 const Standard_Integer theMode);
4099 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4100 const Standard_Integer theMode);
4105 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4106 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4108 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4114 void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
4115 const Handle_Prs3d_Presentation &thePresentation,
4116 const Standard_Integer theMode)
4118 thePresentation->Clear();
4119 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4120 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4121 if (anEdge.IsNull())
4123 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4124 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4127 void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
4128 const Standard_Integer theMode)
4130 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4131 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4132 anArray->SetValue(1, myPoint1);
4133 anArray->SetValue(2, myPoint2);
4134 Handle(Select3D_SensitiveCurve) aSensCurve =
4135 new Select3D_SensitiveCurve(anOwner, anArray);
4136 theSelection->Add(aSensCurve);
4139 //=======================================================================
4140 //function : VSegment
4141 //Draw args : vsegment Name PointName PointName
4142 //purpose : creates and displays Segment
4143 //=======================================================================
4144 static Standard_Integer VSegment (Draw_Interpretor& di,
4145 Standard_Integer argc,
4151 std::cout<<"vsegment error: expects 3 arguments\n";
4152 return 1; // TCL_ERROR
4155 TheAISContext()->CloseAllContexts();
4157 // Get and check arguments
4158 TCollection_AsciiString aName(argv[1]);
4159 Handle(AIS_Point) aPoint1, aPoint2;
4160 if (!IsPoint(argv[2], aPoint1))
4162 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4163 return 1; // TCL_ERROR
4165 if (!IsPoint(argv[3], aPoint2))
4167 std::cout<<"vsegment error: the 3d argument should be a point\n";
4168 return 1; // TCL_ERROR
4170 //Check that points are different
4171 Handle(Geom_CartesianPoint) aCartPoint1 =
4172 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4173 Handle(Geom_CartesianPoint) aCartPoint2 =
4174 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4175 if(IsMatch(aCartPoint1, aCartPoint2))
4177 std::cout<<"vsegment error: equal points\n";
4178 return 1; // TCL_ERROR
4182 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4183 // Check if there is an object with given name
4184 // and remove it from context
4185 if (GetMapOfAIS().IsBound2(aName))
4187 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4188 Handle(AIS_InteractiveObject) anInterObj =
4189 Handle(AIS_InteractiveObject)::DownCast(anObj);
4190 TheAISContext()->Remove(anInterObj, Standard_False);
4191 GetMapOfAIS().UnBind2(aName);
4194 // Bind segment to its name
4195 GetMapOfAIS().Bind(aSegment, aName);
4198 TheAISContext()->Display(aSegment);
4202 //=======================================================================
4203 //function : VObjZLayer
4204 //purpose : Set or get z layer id for presentable object
4205 //=======================================================================
4207 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4208 Standard_Integer argc,
4211 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4212 if (aContext.IsNull())
4214 di << argv[0] << "Call 'vinit' before!\n";
4219 TCollection_AsciiString aOperation;
4221 aOperation = TCollection_AsciiString (argv [1]);
4223 // check for correct arguments
4224 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4225 !(argc == 3 && aOperation.IsEqual ("get")))
4227 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4228 di << " set - set layer id for interactive object, layerid - z layer id\n";
4229 di << " get - get layer id of interactive object\n";
4230 di << " argument layerid should be passed for set operation only\n";
4235 TCollection_AsciiString aName (argv[2]);
4236 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4237 if (!aMap.IsBound2 (aName))
4239 di << "Use 'vdisplay' before" << "\n";
4243 // find interactive object
4244 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4245 Handle(AIS_InteractiveObject) anInterObj =
4246 Handle(AIS_InteractiveObject)::DownCast (anObj);
4247 if (anInterObj.IsNull())
4249 di << "Not an AIS interactive object!\n";
4253 // process operation
4254 if (aOperation.IsEqual ("set"))
4256 Standard_Integer aLayerId = atoi (argv [3]);
4257 aContext->SetZLayer (anInterObj, aLayerId);
4259 else if (aOperation.IsEqual ("get"))
4261 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4267 //=======================================================================
4268 //function : ObjectsCommands
4270 //=======================================================================
4272 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
4274 const char *group ="AISObjects";
4275 theCommands.Add("vtrihedron",
4276 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
4277 __FILE__,VTrihedron,group);
4279 theCommands.Add("vtri2d",
4280 "vtri2d Name Selection in the viewer only ",
4281 __FILE__,VTrihedron2D ,group);
4283 theCommands.Add("vplanetri",
4284 "vplanetri Name Selection in the viewer only ",
4285 __FILE__,VPlaneTrihedron ,group);
4287 theCommands.Add("vsize",
4288 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
4289 __FILE__,VSize,group);
4291 theCommands.Add("vaxis",
4292 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
4293 __FILE__,VAxisBuilder,group);
4295 theCommands.Add("vaxispara",
4297 __FILE__,VAxisBuilder,group);
4299 theCommands.Add("vaxisortho",
4301 __FILE__,VAxisBuilder,group);
4303 theCommands.Add("vpoint",
4304 "vpoint PointName [Xa] [Ya] [Za] ",
4305 __FILE__,VPointBuilder,group);
4307 theCommands.Add("vplane",
4308 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
4309 __FILE__,VPlaneBuilder,group);
4311 theCommands.Add("vplanepara",
4312 "vplanepara PlaneName ",
4313 __FILE__,VPlaneBuilder,group);
4315 theCommands.Add("vplaneortho",
4316 "vplaneortho PlaneName ",
4317 __FILE__,VPlaneBuilder,group);
4319 theCommands.Add("vline",
4320 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
4321 __FILE__,VLineBuilder,group);
4323 theCommands.Add("vcircle",
4324 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
4325 __FILE__,VCircleBuilder,group);
4327 theCommands.Add("vdrawtext",
4328 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
4329 __FILE__,VDrawText,group);
4331 theCommands.Add("vdrawsphere",
4332 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n",
4333 __FILE__,VDrawSphere,group);
4335 theCommands.Add("vclipplane",
4336 "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
4337 __FILE__,VClipPlane,group);
4339 theCommands.Add ("vsetlocation",
4340 "vsetlocation : name x y z; set new location for an interactive object",
4341 __FILE__, VSetLocation, group);
4345 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
4346 __FILE__, VComputeHLR, group);
4348 theCommands.Add("vdrawparray",
4349 "vdrawparray : vdrawparray Name TypeOfArray [EnableVbo=1] [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 [edge_hidden = { 'h' }] ]",
4350 __FILE__,VDrawPArray,group);
4352 theCommands.Add("vconnect",
4353 "vconnect : name object Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4354 __FILE__, VConnect, group);
4356 theCommands.Add("vconnectsh",
4357 "vconnectsh : name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4358 __FILE__, VConnectShape, group);
4360 theCommands.Add("vselmode",
4361 "vselmode : [object] mode On/Off (1/0)",
4362 __FILE__, VSetSelectionMode, group);
4364 theCommands.Add("vtriangle",
4365 "vtriangle Name PointName PointName PointName",
4366 __FILE__, VTriangle,group);
4368 theCommands.Add("vsegment",
4369 "vsegment Name PointName PointName",
4370 __FILE__, VSegment,group);
4372 theCommands.Add("vobjzlayer",
4373 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
4374 __FILE__, VObjZLayer, group);