1 // File: ViewerTest_ObjectsCommands.cxx
2 // Created: Thu Nov 12 15:50:42 1998
3 // Author: Robert COUBLANC
4 // <rob@robox.paris1.matra-dtv.fr>
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>
84 #define _CRT_SECURE_NO_DEPRECATE
85 #pragma warning (disable:4996)
88 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
89 Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
90 extern Handle(AIS_InteractiveContext)& TheAISContext();
93 //==============================================================================
94 //function : Vtrihedron 2d
95 //purpose : Create a plane with a 2D trihedron from a faceselection
96 //Draw arg : vtri2d name
97 //==============================================================================
98 #include <AIS_PlaneTrihedron.hxx>
102 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
105 // Verification des arguments
106 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
109 Standard_Integer myCurrentIndex;
110 // Fermeture des contextes
111 TheAISContext()->CloseAllContexts();
112 // Ouverture d'un contexte local et recuperation de son index.
113 TheAISContext()->OpenLocalContext();
114 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
115 // On active les modes de selections faces.
116 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
117 di<<" Select a face ."<<"\n";
119 // Boucle d'attente waitpick.
120 Standard_Integer argccc = 5;
121 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
122 const char **argvvv = (const char **) bufff;
123 while (ViewerMainLoop( argccc, argvvv) ) { }
127 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
128 ShapeB = TheAISContext()->SelectedShape();
131 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
133 // Construction du Plane
134 // recuperation des edges des faces.
135 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
137 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
141 // si il y a plusieurs edges
142 if (FaceExpB.More() ) {
144 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
145 BRepAdaptor_Curve theCurveB(EdgeB);
146 BRepAdaptor_Curve theCurveC(EdgeC);
147 A=theCurveC.Value(0.1);
148 B=theCurveC.Value(0.9);
149 C=theCurveB.Value(0.5);
152 // FaceB a 1 unique edge courbe
153 BRepAdaptor_Curve theCurveB(EdgeB);
154 A=theCurveB.Value(0.1);
155 B=theCurveB.Value(0.9);
156 C=theCurveB.Value(0.5);
158 // Construction du Geom_Plane
159 GC_MakePlane MkPlane(A,B,C);
160 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
162 // Construction de l'AIS_PlaneTrihedron
163 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
165 // Fermeture du contexte local.
166 TheAISContext()->CloseLocalContext(myCurrentIndex);
168 // on le display & bind
169 TheAISContext()->Display(theAISPlaneTri );
170 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
177 //==============================================================================
178 //function : VTriherdron
180 //purpose : Create a trihedron. If no arguments are set, the default
181 // trihedron (Oxyz) is created.
182 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
183 //==============================================================================
185 static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
188 // Verification des arguments
189 if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
191 // Declarations et creation des objets par default
192 TCollection_AsciiString name=argv[1];
194 if(argc > 5 && argc!=11)
195 {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
197 // Cas ou il y a des arguments
198 Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.};
202 coord[i]= atof(argv[2+i]);
206 coord[3+i] = atof(argv[6+i]);
207 coord[6+i] = atof(argv[8+i]);
211 gp_Pnt ThePoint(coord[0],coord[1],coord[2]);
212 gp_Dir TheZVector(coord[3],coord[4],coord[5]);
213 gp_Dir TheXVector(coord[6],coord[7],coord[8]);
215 if ( !TheZVector.IsNormal(TheXVector,PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;}
217 Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector);
219 // Creation du triedre
220 Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii);
221 GetMapOfAIS().Bind(aShape,name);
222 TheAISContext()->Display(aShape);
230 //==============================================================================
233 //purpose : Change the size of a named or selected trihedron
234 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
235 // if no value, the value is set at 100 by default
236 //Draw arg : vsize [name] [size]
237 //==============================================================================
239 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
242 // Declaration de booleens
243 Standard_Boolean ThereIsName;
244 Standard_Boolean ThereIsCurrent;
246 Standard_Boolean hascol;
248 Quantity_NameOfColor col;
250 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
253 // Verification des arguments
254 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
256 // Verification du nombre d'arguments
257 if (argc==1) {ThereIsName=Standard_False;value=100;}
258 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
259 else {ThereIsName=Standard_True;value=atof(argv[2]);}
261 // On ferme le contexte local pour travailler dans le contexte global
262 if(TheAISContext()->HasOpenedContext())
263 TheAISContext()->CloseLocalContext();
265 // On set le booleen ThereIsCurrent
266 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
267 else {ThereIsCurrent=Standard_False;}
271 //===============================================================
272 // Il n'y a pas de nom mais des objets selectionnes
273 //===============================================================
274 if (!ThereIsName && ThereIsCurrent)
277 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
280 while ( it.More() ) {
282 Handle(AIS_InteractiveObject) aShape=
283 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
285 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
288 // On verifie que l'AIS InteraciveObject selectionne est bien
290 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
292 if (aShape->HasColor()) {
293 hascol=Standard_True;
295 // On recupere la couleur de aShape
296 col=aShape->Color();}
298 else hascol=Standard_False;
300 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
301 // pour lui appliquer la methode SetSize()
302 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
304 // C'est bien un triedre,on chage sa valeur!
305 aTrihedron->SetSize(value);
307 // On donne la couleur au Trihedron
308 if(hascol) aTrihedron->SetColor(col);
309 else aTrihedron->UnsetColor();
312 // The trihedron hasn't be errased from the map
313 // so you just have to redisplay it
314 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
323 TheAISContext() ->UpdateCurrentViewer();
326 //===============================================================
327 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
328 //===============================================================
332 //===============================================================
333 // Il y a un nom de triedre passe en argument
334 //===============================================================
336 TCollection_AsciiString name=argv[1];
338 // on verifie que ce nom correspond bien a une shape
339 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
343 // on recupere la shape dans la map des objets displayes
344 Handle(AIS_InteractiveObject) aShape =
345 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
347 // On verifie que l'AIS InteraciveObject est bien
349 if (!aShape.IsNull() &&
350 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
353 if (aShape->HasColor()) {
354 hascol=Standard_True;
356 // On recupere la couleur de aShape
357 col=aShape->Color();}
359 else hascol=Standard_False;
361 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
362 // pour lui appliquer la methode SetSize()
363 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
365 // C'est bien un triedre,on chage sa valeur
366 aTrihedron->SetSize(value);
368 // On donne la couleur au Trihedron
369 if(hascol) aTrihedron->SetColor(col);
370 else aTrihedron->UnsetColor();
372 // The trihedron hasn't be errased from the map
373 // so you just have to redisplay it
374 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
376 TheAISContext() ->UpdateCurrentViewer();
384 //==============================================================================
386 //==============================================================================
387 //function : VPlaneTrihedron
388 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
389 //Draw arg : vplanetri name
390 //==============================================================================
391 #include <AIS_Plane.hxx>
395 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
398 // Verification des arguments
399 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
402 Standard_Integer myCurrentIndex;
403 // Fermeture des contextes locaux
404 TheAISContext()->CloseAllContexts();
406 // On recupere tous les trihedrons de la GetMapOfAIS()
407 // et on active le mode de selection par face.
408 // =================================================
410 // Ouverture d'un contexte local et recuperation de son index.
411 TheAISContext()->OpenLocalContext(Standard_False);
412 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
414 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
417 Handle(AIS_InteractiveObject) ShapeA =
418 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
419 // On verifie que c'est bien un trihedron
420 if (!ShapeA.IsNull() &&
421 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
423 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
424 // on le charge dans le contexte et on active le mode Plane.
425 TheAISContext()->Load(TrihedronA,0,Standard_False);
426 TheAISContext()->Activate(TrihedronA,3);
431 di<<" Select a plane."<<"\n";
432 // Boucle d'attente waitpick.
433 Standard_Integer argccc = 5;
434 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
435 const char **argvvv = (const char **) bufff;
436 while (ViewerMainLoop( argccc, argvvv) ) { }
439 Handle(AIS_InteractiveObject) theIOB;
440 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
441 theIOB = TheAISContext()->Interactive();
444 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
446 // Fermeture du contexte local.
447 TheAISContext()->CloseLocalContext(myCurrentIndex);
449 // on le display & bind
450 TheAISContext()->Display(PlaneB );
451 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
458 //==============================================================================
459 // Fonction First click 2de click
461 // vaxis vertex vertex
463 // vaxispara edge vertex
464 // vaxisortho edge Vertex
465 // vaxisinter Face Face
466 //==============================================================================
468 //==============================================================================
469 //function : VAxisBuilder
471 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
472 //==============================================================================
473 #include <TopoDS_Edge.hxx>
474 #include <TopoDS_Vertex.hxx>
475 #include <TopExp.hxx>
476 #include <Geom_Line.hxx>
478 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
481 Standard_Boolean HasArg;
482 TCollection_AsciiString name;
483 Standard_Integer MyCurrentIndex;
486 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
487 if (argc==8) HasArg=Standard_True;
488 else HasArg=Standard_False;
491 // Fermeture des contextes
492 TheAISContext()->CloseAllContexts();
494 // Cas ou il y a des arguments
495 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
497 Standard_Real coord[6];
498 for(Standard_Integer i=0;i<=5;i++){
499 coord[i]=atof(argv[2+i]);
501 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
503 gp_Vec myVect (p1,p2);
504 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
505 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
506 GetMapOfAIS().Bind (TheAxis,name);
507 TheAISContext()->Display(TheAxis);
513 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
514 if ( !strcasecmp(argv[0], "vaxis")) {
515 TheAISContext()->OpenLocalContext();
516 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
518 // Active le mode edge et le mode vertex
519 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
520 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
521 di<<" Select an edge or a vertex."<<"\n";
523 // Boucle d'attente waitpick.
524 Standard_Integer argcc = 5;
525 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
526 const char **argvv = (const char **) buff;
527 while (ViewerMainLoop( argcc, argvv) ) { }
530 // recuperation de la shape.
532 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
533 ShapeA = TheAISContext()->SelectedShape();
535 // recuperation de l'AIS_InteractiveObject
536 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
537 // down cast en AIS_Point si sig et type
538 // AIS_Point -> Geom_Pnt ....
540 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
541 // on desactive le mode edge
542 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
543 di<<" Select a different vertex."<<"\n";
547 // Boucle d'attente waitpick.
548 Standard_Integer argccc = 5;
549 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
550 const char **argvvv = (const char **) bufff;
551 while (ViewerMainLoop( argccc, argvvv) ) { }
553 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
554 ShapeB = TheAISContext()->SelectedShape();
558 } while(ShapeB.IsSame(ShapeA) );
560 // Fermeture du context local
561 TheAISContext()->CloseLocalContext(MyCurrentIndex);
563 // Construction de l'axe
564 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
565 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
568 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
569 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
570 GetMapOfAIS().Bind (TheAxis,name);
571 TheAISContext()->Display(TheAxis);
574 // Un unique edge (ShapeA) a ete picke
575 // Fermeture du context local
576 TheAISContext()->CloseLocalContext(MyCurrentIndex);
577 // Constuction de l'axe
578 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
580 TopExp::Vertices(ed,Va,Vb );
581 gp_Pnt A=BRep_Tool::Pnt(Va);
582 gp_Pnt B=BRep_Tool::Pnt(Vb);
585 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
586 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
587 GetMapOfAIS().Bind (TheAxis,name);
588 TheAISContext()->Display(TheAxis);
594 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
595 else if ( !strcasecmp(argv[0], "vaxispara")) {
597 TheAISContext()->OpenLocalContext();
598 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
600 // Active le mode edge
601 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
602 di<<" Select an edge."<<"\n";
604 // Boucle d'attente waitpick.
605 Standard_Integer argcc = 5;
606 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
607 const char **argvv = (const char **) buff;
608 while (ViewerMainLoop( argcc, argvv) ) { }
612 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
613 ShapeA = TheAISContext()->SelectedShape();
615 // Active le mode vertex et deactive edges
616 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
617 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
618 di<<" Select a vertex."<<"\n";
620 // Boucle d'attente waitpick.
621 Standard_Integer argccc = 5;
622 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
623 const char **argvvv = (const char **) bufff;
624 while (ViewerMainLoop( argccc, argvvv) ) { }
627 // On peut choisir un pnt sur l'edge
629 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
630 ShapeB = TheAISContext()->SelectedShape();
632 // Fermeture du context local
633 TheAISContext()->CloseLocalContext(MyCurrentIndex);
635 // Construction de l'axe
636 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
637 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
639 TopExp::Vertices(ed,Va,Vc );
640 gp_Pnt A=BRep_Tool::Pnt(Va);
641 gp_Pnt C=BRep_Tool::Pnt(Vc);
644 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
645 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
646 GetMapOfAIS().Bind (TheAxis,name);
647 TheAISContext()->Display(TheAxis);
651 // Fonction axisortho
653 TheAISContext()->OpenLocalContext();
654 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
656 // Active le mode edge
657 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
658 di<<" Select an edge."<<"\n";
660 // Boucle d'attente waitpick.
661 Standard_Integer argcc = 5;
662 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
663 const char **argvv = (const char **) buff;
664 while (ViewerMainLoop( argcc, argvv) ) { }
668 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
669 ShapeA = TheAISContext()->SelectedShape();
671 // Active le mode vertex et deactive edges
672 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
673 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
674 di<<" Slect a vertex."<<"\n";
676 // Boucle d'attente waitpick.
677 Standard_Integer argccc = 5;
678 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
679 const char **argvvv = (const char **) bufff;
680 while (ViewerMainLoop( argccc, argvvv) ) { }
683 // On peut choisir un pnt sur l'edge
685 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
686 ShapeB = TheAISContext()->SelectedShape();
688 // Fermeture du context local
689 TheAISContext()->CloseLocalContext(MyCurrentIndex);
691 // Construction de l'axe
692 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
693 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
695 TopExp::Vertices(ed,Va,Vc );
696 gp_Pnt A=BRep_Tool::Pnt(Va);
697 gp_Pnt C=BRep_Tool::Pnt(Vc);
698 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
701 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
702 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
703 GetMapOfAIS().Bind (TheAxis,name);
704 TheAISContext()->Display(TheAxis);
713 //==============================================================================
714 // Fonction First click Result
716 // vpoint vertex AIS_Point=Vertex
717 // edge AIS_Point=Middle of the edge
718 //==============================================================================
720 //==============================================================================
721 //function : VPointBuilder
722 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
723 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
724 //==============================================================================
725 #include <TopoDS_Edge.hxx>
726 #include <TopoDS_Vertex.hxx>
727 #include <TopExp.hxx>
728 #include <AIS_Point.hxx>
729 #include <Geom_CartesianPoint.hxx>
731 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
734 Standard_Boolean HasArg;
735 TCollection_AsciiString name;
736 Standard_Integer myCurrentIndex;
739 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
740 if (argc==5) HasArg=Standard_True;
741 else HasArg=Standard_False;
744 // Fermeture des contextes
745 TheAISContext()->CloseAllContexts();
747 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
749 Standard_Real thecoord[3];
750 for(Standard_Integer i=0;i<=2;i++)
751 thecoord[i]=atof(argv[2+i]);
752 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
753 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
754 GetMapOfAIS().Bind (myAISPoint,name);
755 TheAISContext()->Display(myAISPoint);
758 // Il n'a pas d'arguments
760 TheAISContext()->OpenLocalContext();
761 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
763 // Active le mode Vertex et Edges
764 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
765 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
766 di<<" Select a vertex or an edge(build the middle)"<<"\n";
768 // Boucle d'attente waitpick.
769 Standard_Integer argcc = 5;
770 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
771 const char **argvv = (const char **) buff;
772 while (ViewerMainLoop( argcc, argvv) ) { }
776 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
777 ShapeA= TheAISContext()->SelectedShape();
780 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
781 // Un vertex a ete selectionne
782 // Fermeture du context local
783 TheAISContext()->CloseLocalContext(myCurrentIndex);
785 // Construction du point
786 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
787 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
788 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
789 GetMapOfAIS().Bind(myAISPoint,name);
790 TheAISContext()->Display(myAISPoint);
793 // Un Edge a ete selectionne
794 // Fermeture du context local
795 TheAISContext()->CloseLocalContext(myCurrentIndex);
797 // Construction du point milieu de l'edge
798 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
799 TopoDS_Vertex myVertexA,myVertexB;
800 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
801 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
802 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
803 // M est le milieu de [AB]
804 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
805 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
806 GetMapOfAIS().Bind(myAISPointM,name);
807 TheAISContext()->Display(myAISPointM);
815 //==============================================================================
816 // Fonction 1st click 2de click 3de click
817 // vplane Vertex Vertex Vertex
821 // vplanepara Face Vertex
823 // vplaneortho Face Edge
825 //==============================================================================
827 //==============================================================================
828 //function : VPlaneBuilder
829 //purpose : Build an AIS_Plane from selected entities or Named AIs components
830 //Draw arg : vplane PlaneName [AxisName] [PointName]
831 // [PointName] [PointName] [PointName]
832 // [PlaneName] [PointName]
833 //==============================================================================
835 #include <TopoDS_Edge.hxx>
836 #include <TopoDS_Vertex.hxx>
837 #include <TopoDS_Face.hxx>
838 #include <TopExp.hxx>
839 #include <AIS_Plane.hxx>
840 #include <Geom_CartesianPoint.hxx>
841 #include <Geom_Plane.hxx>
842 #include <BRepExtrema_ExtPC.hxx>
843 #include <BRepExtrema_ExtPF.hxx>
844 #include <BRepAdaptor_Surface.hxx>
845 #include <gp_Pln.hxx>
846 #include <GC_MakePlane.hxx>
848 static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
851 Standard_Boolean HasArg;
852 TCollection_AsciiString name;
853 Standard_Integer myCurrentIndex;
856 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
857 if (argc==5 || argc==4) HasArg=Standard_True;
858 else HasArg=Standard_False;
861 // Fermeture des contextes
862 TheAISContext()->CloseAllContexts();
865 // Il y a des arguments
867 if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
868 // on recupere la shape dans la map
869 Handle(AIS_InteractiveObject) theShapeA =
870 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
872 // Le premier argument est un AIS_Point 1
873 if (!theShapeA.IsNull() &&
874 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
875 // le deuxieme argument doit etre un AIS_Point aussi
876 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
877 // on recupere la shape dans la map
878 Handle(AIS_InteractiveObject) theShapeB =
879 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
880 // si B n'est pas un AIS_Point
881 if (theShapeB.IsNull() ||
882 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
884 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
887 // le troisieme objet est un AIS_Point
888 if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; }
889 // on recupere la shape dans la map
890 Handle(AIS_InteractiveObject) theShapeC =
891 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
892 // si C n'est pas un AIS_Point
893 if (theShapeC.IsNull() ||
894 (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1)))
896 di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n";
900 // Traitement des objets A,B,C
901 // Downcaste de AIS_IO en AIS_Point
902 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
903 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
904 Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
906 Handle(Geom_Point ) myGeomPointA= theAISPointA->Component();
907 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA);
908 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
910 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
911 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
912 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
914 Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component();
915 Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC);
916 // Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ;
918 // Verification que les 3 points sont bien differents.
919 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
921 di<<"vplane error: same points"<<"\n";return 1;
923 if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) {
925 di<<"vplane error: same points"<<"\n";return 1;
927 if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) {
929 di<<"vplane error: same points"<<"\n";return 1;
932 gp_Pnt A= myCartPointA->Pnt();
933 gp_Pnt B= myCartPointB->Pnt();
934 gp_Pnt C= myCartPointC->Pnt();
936 // Construction de l'AIS_Plane
937 GC_MakePlane MkPlane (A,B,C);
938 Handle(Geom_Plane) myGeomPlane = MkPlane.Value();
939 Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane );
940 GetMapOfAIS().Bind (myAISPlane,name );
941 TheAISContext()->Display(myAISPlane);
944 // si le premier argument est un AIS_Axis 2
945 // creation d'un plan orthogonal a l'axe passant par un point
946 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) {
947 // le deuxieme argument doit etre un AIS_Point
948 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
950 di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
953 // on recupere la shape dans la map
954 Handle(AIS_InteractiveObject) theShapeB =
955 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
956 // si B n'est pas un AIS_Point
957 if (theShapeB.IsNull() ||
958 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
960 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
964 // Traitement des objets A et B
965 Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA;
966 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
968 Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component();
969 Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
971 gp_Ax1 myAxis= myGeomLineA->Position();
972 Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
974 // Pas de moyens de verifier que le point B n'est pas sur l'axe
976 gp_Dir D=myAxis.Direction();
977 gp_Pnt B= myCartPointB->Pnt();
979 // Construction de l'AIS_Plane
980 Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D);
981 Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane,B );
982 GetMapOfAIS().Bind (myAISPlane,name );
983 TheAISContext()->Display(myAISPlane);
986 // Si le premier argument est un AIS_Plane 7
987 // Creation d'un Plan parallele a ce plan passant par le point
988 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
989 // le deuxieme argument doit etre un AISPoint
990 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) {
991 di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
994 // on recupere la shape dans la map
995 Handle(AIS_InteractiveObject) theShapeB =
996 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
997 // si B n'est pas un AIS_Point
998 if (theShapeB.IsNull() ||
999 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1001 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
1005 // Traitement des objets A et B
1006 Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA;
1007 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1009 Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component();
1010 Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
1012 Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
1013 gp_Pnt B= myCartPointB->Pnt();
1015 // Construction de l'AIS_Plane
1016 Handle(AIS_Plane) myAISPlane = new AIS_Plane(theNewGeomPlane,B );
1017 GetMapOfAIS().Bind (myAISPlane,name );
1018 TheAISContext()->Display(myAISPlane);
1022 else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;}
1026 // Il n'y a pas d'arguments
1030 // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1031 if (!strcasecmp(argv[0] ,"vplane" ) ) {
1032 TheAISContext()->OpenLocalContext();
1033 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1035 // Active les modes Vertex, Edge et Face
1036 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1037 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1038 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1039 di<<"Select a vertex, a face or an edge. "<<"\n";
1041 // Boucle d'attente waitpick.
1042 Standard_Integer argcc = 5;
1043 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1044 const char **argvv = (const char **) buff;
1045 while (ViewerMainLoop( argcc, argvv) ) { }
1048 TopoDS_Shape ShapeA;
1049 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1050 ShapeA = TheAISContext()->SelectedShape();
1053 // ShapeA est un Vertex
1054 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1055 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1056 di<<" Select an edge or a different vertex."<<"\n";
1058 // Boucle d'attente waitpick.
1059 Standard_Integer argccc = 5;
1060 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1061 const char **argvvv = (const char **) bufff;
1062 while (ViewerMainLoop( argccc, argvvv) ) { }
1065 TopoDS_Shape ShapeB;
1066 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1067 ShapeB = TheAISContext()->SelectedShape();
1069 // ShapeB est un Vertex
1070 if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1071 // Si A et B sont le meme point
1072 if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
1073 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1074 di<<" Select a different vertex."<<"\n";
1076 // Boucle d'attente waitpick.
1077 Standard_Integer argcccc = 5;
1078 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1079 const char **argvvvv = (const char **) buffff;
1080 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1083 TopoDS_Shape ShapeC;
1084 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1085 ShapeC = TheAISContext()->SelectedShape();
1087 // ShapeC est aussi un vertex...
1088 if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
1090 // Fermeture du contexte local
1091 TheAISContext()->CloseLocalContext(myCurrentIndex);
1093 // Construction du plane
1094 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
1095 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
1096 gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC ) );
1097 GC_MakePlane MkPlane(A,B,C);
1098 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1099 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1100 GetMapOfAIS().Bind (myAISPlane ,name );
1101 TheAISContext()->Display(myAISPlane);
1104 // ShapeB est un edge
1106 // il s'agit de verifier que le vertex ShapeA n'est pas sur l'edge ShapeB
1107 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1108 TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA);
1110 BRepExtrema_ExtPC OrthoProj (VertA, EdgeB );
1111 if (OrthoProj.SquareDistance(1)<1e-6 ) {
1112 // Le vertex est sur l'edge
1113 di<<" vplane: error point is on the edge."<<"\n";return 1;
1116 // le vertex n'appartient pes a l'edge on peut construire le plane
1117 // Fermeture du contexte local
1118 TheAISContext()->CloseLocalContext(myCurrentIndex);
1119 // Construction du plane
1120 gp_Pnt A=BRep_Tool::Pnt(VertA );
1121 TopoDS_Vertex VBa,VBb;
1122 TopExp::Vertices(EdgeB ,VBa ,VBb );
1123 gp_Pnt Ba=BRep_Tool::Pnt(VBa);
1124 gp_Pnt Bb=BRep_Tool::Pnt(VBb);
1125 GC_MakePlane MkPlane (A,Ba,Bb);
1126 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1127 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1128 GetMapOfAIS().Bind (myAISPlane ,name );
1129 TheAISContext()->Display(myAISPlane);
1136 // ShapeA est un edge
1137 else if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1139 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1140 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1141 di<<" Select a vertex that don't belong to the edge."<<"\n";
1143 // Boucle d'attente waitpick.
1144 Standard_Integer argccc = 5;
1145 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1146 const char **argvvv = (const char **) bufff;
1147 while (ViewerMainLoop( argccc, argvvv) ) { }
1150 TopoDS_Shape ShapeB;
1151 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1152 ShapeB = TheAISContext()->SelectedShape();
1154 // ShapeB est forcement un Vertex
1155 // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA
1156 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1157 TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB);
1159 BRepExtrema_ExtPC OrthoProj (VertB,EdgeA );
1160 if (OrthoProj.SquareDistance(1)<1e-6) {
1161 // Le vertex est sur l'edge
1162 di<<" vplane: error point is on the edge."<<"\n";return 1;
1165 // le vertex n'appartient pas a l'edge on peut construire le plane
1166 // Fermeture du contexte local
1167 TheAISContext()->CloseLocalContext(myCurrentIndex);
1168 // Construction du plane
1169 gp_Pnt B=BRep_Tool::Pnt(VertB );
1170 TopoDS_Vertex VAa,VAb;
1171 TopExp::Vertices(EdgeA ,VAa ,VAb );
1172 gp_Pnt Aa=BRep_Tool::Pnt(VAa);
1173 gp_Pnt Ab=BRep_Tool::Pnt(VAb);
1174 GC_MakePlane MkPlane (B,Aa,Ab);
1175 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1176 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1177 GetMapOfAIS().Bind (myAISPlane ,name );
1178 TheAISContext()->Display(myAISPlane);
1184 // ShapeA est une Face
1186 // Fermeture du contexte local: Plus rien a selectionner
1187 TheAISContext()->CloseLocalContext(myCurrentIndex);
1188 // Construction du plane
1189 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1190 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1191 if (mySurface.GetType()==GeomAbs_Plane ) {
1192 gp_Pln myPlane=mySurface.Plane();
1193 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1194 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1195 GetMapOfAIS().Bind (myAISPlane ,name );
1196 TheAISContext()->Display(myAISPlane);
1200 di<<" vplane: error"<<"\n";return 1;
1207 // Fonction vPlanePara
1208 // ===================
1209 // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt )
1210 else if (!strcasecmp(argv[0] ,"vplanepara" )) {
1212 TheAISContext()->OpenLocalContext();
1213 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1215 // Active les modes Vertex et Face
1216 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1217 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1218 di<<" Select a vertex or a face."<<"\n";
1220 // Boucle d'attente waitpick.
1221 Standard_Integer argcc = 5;
1222 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1223 const char **argvv = (const char **) buff;
1224 while (ViewerMainLoop( argcc, argvv) ) { }
1227 TopoDS_Shape ShapeA;
1228 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1229 ShapeA = TheAISContext()->SelectedShape();
1232 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1233 // ShapeA est un vertex
1234 // On desactive le mode Vertex
1235 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
1236 di<<" Select a face."<<"\n";
1238 // Boucle d'attente waitpick.
1239 Standard_Integer argccc = 5;
1240 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1241 const char **argvvv = (const char **) bufff;
1242 while (ViewerMainLoop( argccc, argvvv) ) { }
1245 TopoDS_Shape ShapeB;
1246 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1247 // Le vertex ShapeA peut etre dans la Face ShapeB
1248 ShapeB = TheAISContext()->SelectedShape();
1251 // Fermeture du context local
1252 TheAISContext()->CloseLocalContext(myCurrentIndex);
1254 // Construction du plane
1255 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
1257 TopoDS_Face myFace=TopoDS::Face(ShapeB);
1258 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1259 if (mySurface.GetType()==GeomAbs_Plane ) {
1260 gp_Pln myPlane=mySurface.Plane();
1261 // construit un plan parallele a theGeomPlane passant par A
1262 myPlane.SetLocation(A);
1263 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1264 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A );
1265 GetMapOfAIS().Bind (myAISPlane ,name );
1266 TheAISContext()->Display(myAISPlane);
1270 di<<" vplane: error"<<"\n";return 1;
1275 // ShapeA est une Face
1276 // On desactive le mode Face
1277 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1278 di<<" Select a vertex."<<"\n";
1280 // Boucle d'attente waitpick.
1281 Standard_Integer argccc = 5;
1282 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1283 const char **argvvv = (const char **) bufff;
1284 while (ViewerMainLoop( argccc, argvvv) ) { }
1287 TopoDS_Shape ShapeB;
1288 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1289 // Le vertex ShapeB peut etre dans la Face ShapeA
1290 ShapeB = TheAISContext()->SelectedShape();
1292 // Fermeture du context local
1293 TheAISContext()->CloseLocalContext(myCurrentIndex);
1295 // Construction du plane
1296 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
1298 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1299 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1300 if (mySurface.GetType()==GeomAbs_Plane ) {
1301 gp_Pln myPlane=mySurface.Plane();
1302 myPlane.SetLocation(B);
1303 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1304 // construit un plan parallele a theGeomPlane passant par B
1305 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B );
1306 GetMapOfAIS().Bind (myAISPlane ,name );
1307 TheAISContext()->Display(myAISPlane);
1311 di<<" vplane: error"<<"\n";return 1;
1318 // Fonction vplaneortho
1319 // ====================
1320 // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1323 TheAISContext()->OpenLocalContext();
1324 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1326 // Active les modes Edge et Face
1327 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1328 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1329 di<<" Select a face and an edge coplanar."<<"\n";
1331 // Boucle d'attente waitpick.
1332 Standard_Integer argcc = 5;
1333 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1334 const char **argvv = (const char **) buff;
1335 while (ViewerMainLoop( argcc, argvv) ) { }
1338 TopoDS_Shape ShapeA;
1339 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1340 ShapeA = TheAISContext()->SelectedShape();
1343 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1344 // ShapeA est un edge, on desactive le mode edge...
1345 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1346 di<<" Select a face."<<"\n";
1348 // Boucle d'attente waitpick.
1349 Standard_Integer argccc = 5;
1350 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1351 const char **argvvv = (const char **) bufff;
1352 while (ViewerMainLoop( argccc, argvvv) ) { }
1355 TopoDS_Shape ShapeB;
1356 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1357 // L'edge ShapeA peut etre dans la Face ShapeB
1358 ShapeB = TheAISContext()->SelectedShape();
1361 // Fermeture du context local
1362 TheAISContext()->CloseLocalContext(myCurrentIndex);
1364 // Construction du plane
1365 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1366 TopoDS_Vertex VAa,VAb;
1368 TopExp::Vertices(EdgeA ,VAa ,VAb );
1369 gp_Pnt Aa=BRep_Tool::Pnt(VAa);
1370 gp_Pnt Ab=BRep_Tool::Pnt(VAb);
1374 // Creation de mon axe de rotation
1375 gp_Ax1 myRotAxis (Aa,Dab);
1377 TopoDS_Face myFace=TopoDS::Face(ShapeB);
1378 // Il faut imperativement que l'edge soit parallele a la face
1380 BRepExtrema_ExtPF myHauteurA (VAa , myFace );
1381 BRepExtrema_ExtPF myHauteurB (VAb , myFace );
1382 // on compare les deux hauteurs a la tolerance pres
1383 if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) {
1384 // l'edge n'est pas parallele a la face
1385 di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
1388 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1389 if (mySurface.GetType()==GeomAbs_Plane ) {
1390 gp_Pln myPlane=mySurface.Plane();
1391 // On effectue une rotation d'1/2 tour autour de l'axe de rotation
1392 myPlane.Rotate(myRotAxis , PI/2 );
1394 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1395 // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
1396 gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1397 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
1398 GetMapOfAIS().Bind (myAISPlane ,name );
1399 TheAISContext()->Display(myAISPlane);
1403 di<<" vplaneOrtho: error"<<"\n";return 1;
1409 // ShapeA est une Face, on desactive le mode face.
1410 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1411 di<<" Select an edge."<<"\n";
1413 // Boucle d'attente waitpick.
1414 Standard_Integer argccc = 5;
1415 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1416 const char **argvvv = (const char **) bufff;
1417 while (ViewerMainLoop( argccc, argvvv) ) { }
1420 TopoDS_Shape ShapeB;
1421 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1422 // L'edge ShapeB peut etre dans la Face ShapeA
1423 ShapeB = TheAISContext()->SelectedShape();
1426 // Fermeture du context local
1427 TheAISContext()->CloseLocalContext(myCurrentIndex);
1429 // Construction du plane
1430 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1431 TopoDS_Vertex VBa,VBb;
1432 TopExp::Vertices(EdgeB ,VBa ,VBb );
1433 gp_Pnt Ba=BRep_Tool::Pnt(VBa);
1434 gp_Pnt Bb=BRep_Tool::Pnt(VBb);
1437 // Creation de mon axe de rotation
1438 gp_Ax1 myRotAxis (Ba,Dab);
1440 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1441 // Il faut imperativement que l'edge soit parallele a la face
1442 BRepExtrema_ExtPF myHauteurA (VBa , myFace );
1443 BRepExtrema_ExtPF myHauteurB (VBb , myFace );
1444 // on compare les deux hauteurs a la tolerance pres
1445 if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) {
1446 // l'edge n'est pas parallele a la face
1447 di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
1450 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1451 if (mySurface.GetType()==GeomAbs_Plane ) {
1452 gp_Pln myPlane=mySurface.Plane();
1453 // On effectue une rotation d'1/2 tour autour de l'axe de rotation
1454 myPlane.Rotate(myRotAxis , PI/2 );
1455 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1456 // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
1457 gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 );
1458 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
1459 GetMapOfAIS().Bind (myAISPlane ,name );
1460 TheAISContext()->Display(myAISPlane);
1464 di<<" vplaneOrtho: error"<<"\n";return 1;
1477 //==============================================================================
1479 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1480 //==============================================================================
1482 //==============================================================================
1483 //function : VLineBuilder
1484 //purpose : Build an AIS_Line
1485 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1486 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1487 //==============================================================================
1488 #include <Geom_CartesianPoint.hxx>
1489 #include <AIS_Line.hxx>
1492 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1494 Standard_Integer myCurrentIndex;
1496 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1497 // Fermeture des contextes
1498 TheAISContext()->CloseAllContexts();
1500 // On recupere les parametres
1501 Handle(AIS_InteractiveObject) theShapeA;
1502 Handle(AIS_InteractiveObject) theShapeB;
1504 // Parametres: AIS_Point AIS_Point
1505 // ===============================
1508 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1509 // On verifie que c'est bien une AIS_Point
1510 if (!theShapeA.IsNull() &&
1511 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1512 // on recupere le deuxieme AIS_Point
1514 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1515 if (theShapeA.IsNull() ||
1516 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1518 di <<"vline error: wrong type of 2de argument."<<"\n";
1522 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1523 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1524 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1525 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1527 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1528 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1529 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1531 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1532 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1533 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1535 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1537 di<<"vline error: same points"<<"\n";return 1;
1539 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1540 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1541 GetMapOfAIS().Bind(theAISLine,argv[1] );
1542 TheAISContext()->Display(theAISLine );
1546 // Parametres 6 Reals
1547 // ==================
1550 // On verifie que les deux points ne sont pas confondus
1552 Standard_Real coord[6];
1553 for(Standard_Integer i=0;i<=2;i++){
1554 coord[i]=atof(argv[2+i]);
1555 coord[i+3]=atof(argv[5+i]);
1558 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1559 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1561 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1562 GetMapOfAIS().Bind(theAISLine,argv[1] );
1563 TheAISContext()->Display(theAISLine );
1567 // Pas de parametres: Selection dans le viewer.
1568 // ============================================
1571 TheAISContext()->OpenLocalContext();
1572 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1574 // Active le mode Vertex.
1575 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1576 di<<" Select a vertex "<<"\n";
1578 // Boucle d'attente waitpick.
1579 Standard_Integer argcc = 5;
1580 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1581 const char **argvv = (const char **) buff;
1582 while (ViewerMainLoop( argcc, argvv) ) { }
1585 TopoDS_Shape ShapeA;
1586 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1587 ShapeA = TheAISContext()->SelectedShape();
1590 // ShapeA est un Vertex
1591 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1593 di<<" Select a different vertex."<<"\n";
1595 TopoDS_Shape ShapeB;
1598 // Boucle d'attente waitpick.
1599 Standard_Integer argccc = 5;
1600 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1601 const char **argvvv = (const char **) bufff;
1602 while (ViewerMainLoop( argccc, argvvv) ) { }
1605 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1606 ShapeB = TheAISContext()->SelectedShape();
1610 } while(ShapeB.IsSame(ShapeA) );
1612 // Fermeture du context local
1613 TheAISContext()->CloseLocalContext(myCurrentIndex);
1615 // Construction de la line
1616 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1617 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1619 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1620 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1622 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1623 GetMapOfAIS().Bind(theAISLine,argv[1] );
1624 TheAISContext()->Display(theAISLine );
1628 di<<"vline error."<<"\n";
1637 //==============================================================================
1639 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1640 //==============================================================================
1642 //==============================================================================
1643 //function : VCircleBuilder
1644 //purpose : Build an AIS_Circle
1645 //Draw arg : vcircle CircleName PlaneName PointName Radius
1646 // PointName PointName PointName
1647 //==============================================================================
1648 #include <Geom_CartesianPoint.hxx>
1649 #include <Geom_Circle.hxx>
1650 #include <AIS_Circle.hxx>
1651 #include <GC_MakeCircle.hxx>
1652 #include <Geom_Plane.hxx>
1653 #include <gp_Pln.hxx>
1655 static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1657 Standard_Integer myCurrentIndex;
1658 // verification of the arguments
1659 if (argc>5 || argc<2 ) {di<<"vcircle error: expect 3 arguments."<<"\n";return 1; }
1660 TheAISContext()->CloseAllContexts();
1662 // Il y a des arguments
1664 Handle(AIS_InteractiveObject) theShapeA;
1665 Handle(AIS_InteractiveObject) theShapeB;
1668 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1670 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1672 // Arguments: AIS_Point AIS_Point AIS_Point
1673 // ========================================
1674 if (!theShapeA.IsNull() && theShapeB.IsNull() &&
1675 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1677 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) {
1678 di<<"vcircle error: 2de argument is unexpected to be a point."<<"\n";
1681 // Le troisieme objet doit etre un point
1682 Handle(AIS_InteractiveObject) theShapeC =
1683 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
1684 if (theShapeC.IsNull() ||
1685 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) {
1686 di<<"vcircle error: 3de argument is unexpected to be a point."<<"\n";
1690 // On verifie que les 3 points sont differents.
1691 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1692 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1693 Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
1695 Handle(Geom_Point ) myGeomPointA= theAISPointA->Component();
1696 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA);
1698 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
1699 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
1701 Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component();
1702 Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC);
1705 if (myCartPointA->X()==myCartPointB->X() && myCartPointA->Y()==myCartPointB->Y() && myCartPointA->Z()==myCartPointB->Z() ) {
1706 di<<"vcircle error: Same points."<<"\n";return 1;
1709 if (myCartPointA->X()==myCartPointC->X() && myCartPointA->Y()==myCartPointC->Y() && myCartPointA->Z()==myCartPointC->Z() ) {
1710 di<<"vcircle error: Same points."<<"\n";return 1;
1713 if (myCartPointB->X()==myCartPointC->X() && myCartPointB->Y()==myCartPointC->Y() && myCartPointB->Z()==myCartPointC->Z() ) {
1714 di<<"vcircle error: Same points."<<"\n";return 1;
1716 // Construction du cercle
1717 GC_MakeCircle Cir=GC_MakeCircle (myCartPointA->Pnt(),myCartPointB->Pnt(),myCartPointC->Pnt() );
1718 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1719 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1720 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1721 TheAISContext()->Display(theAISCircle );
1725 // Arguments: ASI_Plane AIS_Point Real
1726 // ===================================
1727 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
1728 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) {
1729 di<<"vcircle error: 2de element is a unexpected to be a point."<<"\n";return 1;
1731 // On verifie que le rayon est bien >=0
1732 if (atof(argv[4])<=0 ) {di<<"vcircle error: the radius must be >=0."<<"\n";return 1; }
1734 // On recupere la normale au Plane.
1735 Handle(AIS_Plane) theAISPlane= *(Handle(AIS_Plane)*)& theShapeA;
1736 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1739 // Handle(Geom_Plane ) myGeomPlane= *(Handle(Geom_Plane)*)& (theAISPlane->Component() );
1740 Handle(Geom_Plane ) myGeomPlane= theAISPlane->Component();
1741 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
1742 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
1744 gp_Pln mygpPlane = myGeomPlane->Pln();
1745 gp_Ax1 thegpAxe = mygpPlane.Axis();
1746 gp_Dir theDir = thegpAxe.Direction();
1747 gp_Pnt theCenter=myCartPointB->Pnt();
1748 Standard_Real TheR = atof(argv[4]);
1749 GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,TheR);
1750 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1751 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1752 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1753 TheAISContext()->Display(theAISCircle );
1759 di<<"vcircle error: !st argument is a unexpected type."<<"\n";return 1;
1763 // Pas d'arguments: selection dans le viewer
1764 // =========================================
1767 TheAISContext()->OpenLocalContext();
1768 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1770 // Active le mode Vertex et face.
1771 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1772 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1773 di<<" Select a vertex or a face."<<"\n";
1775 // Boucle d'attente waitpick.
1776 Standard_Integer argcc = 5;
1777 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1778 const char **argvv = (const char **) buff;
1779 while (ViewerMainLoop( argcc, argvv) ) { }
1782 TopoDS_Shape ShapeA;
1783 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1784 ShapeA = TheAISContext()->SelectedShape();
1787 // ShapeA est un Vertex
1788 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1789 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1790 di<<" Select a different vertex."<<"\n";
1792 TopoDS_Shape ShapeB;
1795 // Boucle d'attente waitpick.
1796 Standard_Integer argccc = 5;
1797 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1798 const char **argvvv = (const char **) bufff;
1799 while (ViewerMainLoop( argccc, argvvv) ) { }
1802 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1803 ShapeB = TheAISContext()->SelectedShape();
1807 } while(ShapeB.IsSame(ShapeA) );
1809 // Selection de ShapeC
1810 di<<" Select the last vertex."<<"\n";
1811 TopoDS_Shape ShapeC;
1814 // Boucle d'attente waitpick.
1815 Standard_Integer argcccc = 5;
1816 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1817 const char **argvvvv = (const char **) buffff;
1818 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1821 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1822 ShapeC = TheAISContext()->SelectedShape();
1826 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
1828 // Fermeture du context local
1829 TheAISContext()->CloseLocalContext(myCurrentIndex);
1831 // Construction du cercle
1832 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1833 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1834 gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC) );
1836 GC_MakeCircle Cir=GC_MakeCircle (A,B,C );
1837 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1838 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1839 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1840 TheAISContext()->Display(theAISCircle );
1843 // ShapeA est une face.
1845 di<<" Select a vertex (in your face)."<<"\n";
1846 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1848 TopoDS_Shape ShapeB;
1849 // Boucle d'attente waitpick.
1850 Standard_Integer argccc = 5;
1851 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1852 const char **argvvv = (const char **) bufff;
1853 while (ViewerMainLoop( argccc, argvvv) ) { }
1856 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1857 ShapeB = TheAISContext()->SelectedShape();
1860 // Recuperation du rayon.
1861 Standard_Integer theRad;
1863 di<<" Enter the value of the radius:"<<"\n";
1865 } while (theRad<=0);
1867 // Fermeture du context local
1868 TheAISContext()->CloseLocalContext(myCurrentIndex);
1869 // Construction du cercle.
1871 // On recupere la normale au Plane. tag
1872 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1873 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1874 gp_Pln myPlane=mySurface.Plane();
1875 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1876 gp_Pln mygpPlane = theGeomPlane->Pln();
1877 gp_Ax1 thegpAxe = mygpPlane.Axis();
1878 gp_Dir theDir = thegpAxe.Direction();
1880 // On recupere le centre.
1881 gp_Pnt theCenter=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1883 // On construit l'AIS_Circle
1884 GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,theRad );
1885 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1886 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1887 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1888 TheAISContext()->Display(theAISCircle );
1899 //===============================================================================================
1900 //function : VDrawText
1902 //purpose : Create a text.
1903 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
1904 //===============================================================================================
1905 #include <Graphic3d_Group.hxx>
1906 #include <Graphic3d_Structure.hxx>
1907 #include <Graphic3d_NameOfFont.hxx>
1908 #include <Graphic3d_AspectText3d.hxx>
1909 #include <Graphic2d_GraphicObject.hxx>
1910 #include <Graphic3d_Array1OfVertex.hxx>
1911 #include <Graphic3d_AspectFillArea3d.hxx>
1912 #include <Graphic3d_StructureManager.hxx>
1913 #include <Graphic3d_VerticalTextAlignment.hxx>
1914 #include <Graphic3d_HorizontalTextAlignment.hxx>
1916 #include <Visual3d_ViewManager.hxx>
1917 #include <ViewerTest_Tool.ixx>
1919 #include <Standard_DefineHandle.hxx>
1921 #include <AIS_Drawer.hxx>
1923 #include <Prs3d_Root.hxx>
1924 #include <Prs3d_Text.hxx>
1925 #include <Prs3d_TextAspect.hxx>
1926 #include <Prs3d_Presentation.hxx>
1927 #include <Prs3d_ShadingAspect.hxx>
1928 #include <PrsMgr_PresentationManager3d.hxx>
1930 #include <TCollection_ExtendedString.hxx>
1931 #include <TCollection_AsciiString.hxx>
1933 #include <gp_Pnt.hxx>
1934 #include <Quantity_NameOfColor.hxx>
1935 #include <Quantity_Color.hxx>
1938 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
1940 class MyTextClass:public AIS_InteractiveObject{
1944 DEFINE_STANDARD_RTTI(MyTextClass );
1950 const TCollection_ExtendedString& , const gp_Pnt& ,
1951 Quantity_Color color,
1952 Standard_Integer aHJust,
1953 Standard_Integer aVJust ,
1954 Standard_Real Angle ,
1955 Standard_Boolean Zoom ,
1956 Standard_Real Height,
1957 OSD_FontAspect FontAspect,
1958 Standard_CString Font
1963 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
1964 const Handle(Prs3d_Presentation)& aPresentation,
1965 const Standard_Integer aMode);
1967 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
1968 const Standard_Integer aMode){} ;
1971 TCollection_ExtendedString aText;
1974 Standard_Real Green;
1976 Standard_Real aAngle;
1977 Standard_Real aHeight;
1978 Standard_Boolean aZoomable;
1979 Quantity_Color aColor;
1980 Standard_CString aFont;
1981 OSD_FontAspect aFontAspect;
1982 Graphic3d_HorizontalTextAlignment aHJustification;
1983 Graphic3d_VerticalTextAlignment aVJustification;
1988 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
1989 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
1993 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
1994 Quantity_Color color = Quantity_NOC_YELLOW,
1995 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
1996 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
1997 Standard_Real angle = 0.0 ,
1998 Standard_Boolean zoomable = Standard_True,
1999 Standard_Real height = 12.,
2000 OSD_FontAspect fontAspect = OSD_FA_Regular,
2001 Standard_CString font = "Courier")
2004 aPosition = position;
2005 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2006 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2008 aZoomable = zoomable;
2011 aFontAspect = fontAspect;
2017 //////////////////////////////////////////////////////////////////////////////
2018 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2019 const Handle(Prs3d_Presentation)& aPresentation,
2020 const Standard_Integer aMode)
2023 aPresentation->Clear();
2025 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2027 asp->SetFont(aFont);
2028 asp->SetColor(aColor);
2029 asp->SetHeight(aHeight); // I am changing the myHeight value
2031 asp->SetHorizontalJustification(aHJustification);
2032 asp->SetVerticalJustification(aVJustification);
2033 asp->Aspect()->SetTextZoomable(aZoomable);
2034 asp->Aspect()->SetTextAngle(aAngle);
2035 asp->Aspect()->SetTextFontAspect(aFontAspect);
2036 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2038 /* This comment code is worked
2039 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2040 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2041 Graphic3d_Vertex vertices_text;
2042 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2043 TheGroup->SetPrimitivesAspect(aspect);
2044 TheGroup->BeginPrimitives();
2045 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2046 TheGroup->EndPrimitives();
2050 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2052 // Verification des arguments
2053 if ( argc > 17 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
2054 Quantity_Parameter R, G, B;
2055 Quantity_Color aColor;
2056 Standard_Real angle;
2057 Standard_Real height;
2058 Standard_Boolean zoom;
2059 OSD_FontAspect aspect;
2060 TCollection_AsciiString font;
2064 TCollection_AsciiString aFont;
2065 TCollection_AsciiString name = argv[1];
2067 //Declarations et creation des objets par default
2068 Standard_Real X,Y,Z;
2072 pnt.SetCoord(X,Y,Z);
2074 R = atof(argv[5])/255.;
2075 G = atof(argv[6])/255.;
2076 B = atof(argv[7])/255.;
2078 hor_align = atoi(argv[8]);
2079 ver_align = atoi(argv[9]);
2081 angle = atof(argv[10]);
2083 zoom = atoi(argv[11]);
2085 height = atof(argv[12]);
2087 aspect = OSD_FontAspect(atoi(argv[13]));
2090 font.AssignCat("Courier");
2092 font.AssignCat(argv[14]);
2095 font.AssignCat(argv[14]);
2096 font.AssignCat(" ");
2097 font.AssignCat(argv[15]);
2101 font.AssignCat(argv[14]);
2102 font.AssignCat(" ");
2103 font.AssignCat(argv[15]);
2104 font.AssignCat(" ");
2105 font.AssignCat(argv[16]);
2108 aColor.SetValues( R, G, B, Quantity_TOC_RGB );
2110 Handle(AIS_InteractiveContext) aContext= ViewerTest::GetAISContext();
2112 Handle(MyTextClass) my=new MyTextClass(argv[1],pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2114 aContext->Display(my,Standard_True);
2116 if(aContext.IsNull())
2118 di << "use 'vinit' command before " << argv[0] << "\n";
2125 #include <gp_Pnt.hxx>
2126 #include <Graphic3d_ArrayOfPoints.hxx>
2127 #include <Graphic3d_ArrayOfPrimitives.hxx>
2128 #include <Graphic3d_Array1OfVertex.hxx>
2129 #include <Graphic3d_ArrayOfTriangles.hxx>
2130 #include <Poly_Array1OfTriangle.hxx>
2131 #include <Poly_Triangle.hxx>
2132 #include <Poly_Triangulation.hxx>
2133 #include <TColgp_Array1OfPnt.hxx>
2134 #include <TShort_Array1OfShortReal.hxx>
2135 #include <TShort_HArray1OfShortReal.hxx>
2137 #include <AIS_Triangulation.hxx>
2138 #include <Aspect_GraphicDevice.hxx>
2139 #include <StdPrs_ToolShadedShape.hxx>
2140 #include <Poly_Connect.hxx>
2141 #include <TColgp_Array1OfDir.hxx>
2142 #include <Graphic3d_GraphicDriver.hxx>
2144 #include <AIS_Drawer.hxx>
2145 #include <TColStd_Array1OfInteger.hxx>
2146 #include <TColStd_HArray1OfInteger.hxx>
2147 #include <Prs3d_ShadingAspect.hxx>
2148 #include <Graphic3d_MaterialAspect.hxx>
2149 #include <Graphic3d_AspectFillArea3d.hxx>
2151 #include <BRepPrimAPI_MakeCylinder.hxx>
2152 #include <TopoDS_Shape.hxx>
2153 #include <TopExp_Explorer.hxx>
2154 #include <TopAbs.hxx>
2155 #include <StdSelect_ShapeTypeFilter.hxx>
2158 //===============================================================================================
2159 //function : CalculationOfSphere
2161 //purpose : Create a Sphere
2162 //===============================================================================================
2164 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2167 double mRadius = Radius;
2168 double mCenter[3] = {X,Y,Z};
2169 int mThetaResolution;
2171 double mStartTheta = 0;//StartTheta;
2172 double mEndTheta = 360;//EndTheta;
2173 double mStartPhi = 0;//StartPhi;
2174 double mEndPhi = 180;//EndPhi;
2175 res = res < 4 ? 4 : res;
2177 mThetaResolution = res;
2178 mPhiResolution = res;
2181 int jStart, jEnd, numOffset;
2182 int numPts, numPolys;
2183 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2184 double startTheta, endTheta, startPhi, endPhi;
2185 int base, numPoles=0, thetaResolution, phiResolution;
2190 if ( numPieces > mThetaResolution ) {
2191 numPieces = mThetaResolution;
2194 int localThetaResolution = mThetaResolution;
2195 double localStartTheta = mStartTheta;
2196 double localEndTheta = mEndTheta;
2198 while ( localEndTheta < localStartTheta ) {
2199 localEndTheta += 360.0;
2202 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2204 // Change the ivars based on pieces.
2206 start = piece * localThetaResolution / numPieces;
2207 end = (piece+1) * localThetaResolution / numPieces;
2208 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2209 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2210 localThetaResolution = end - start;
2212 numPts = mPhiResolution * localThetaResolution + 2;
2213 numPolys = mPhiResolution * 2 * localThetaResolution;
2215 // Create north pole if needed
2216 int number_point = 0;
2217 int number_pointArray = 0;
2219 if ( mStartPhi <= 0.0 ) {
2220 number_pointArray++;
2223 if ( mEndPhi >= 180.0 ) {
2224 number_pointArray++;
2228 // Check data, determine increments, and convert to radians
2229 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2230 startTheta *= Standard_PI / 180.0;
2231 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2232 endTheta *= Standard_PI / 180.0;
2235 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2236 startPhi *= Standard_PI / 180.0;
2237 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2238 endPhi *= Standard_PI / 180.0;
2240 phiResolution = mPhiResolution - numPoles;
2241 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2242 thetaResolution = localThetaResolution;
2243 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2244 ++localThetaResolution;
2246 deltaTheta = (endTheta - startTheta) / thetaResolution;
2248 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2249 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2251 // Create intermediate points
2252 for ( i = 0; i < localThetaResolution; i++ ) {
2253 for ( j = jStart; j < jEnd; j++ ) {
2254 number_pointArray++;
2258 //Generate mesh connectivity
2259 base = phiResolution * localThetaResolution;
2261 int number_triangle = 0 ;
2262 if ( mStartPhi <= 0.0 ) { // around north pole
2263 number_triangle += localThetaResolution;
2266 if ( mEndPhi >= 180.0 ) { // around south pole
2267 number_triangle += localThetaResolution;
2270 // bands in-between poles
2271 for ( i=0; i < localThetaResolution; i++){
2272 for ( j=0; j < (phiResolution-1); j++){
2273 number_triangle +=2;
2277 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2278 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2279 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2281 if ( mStartPhi <= 0.0 ){
2284 x[2] = mCenter[2] + mRadius;
2285 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2288 // Create south pole if needed
2289 if ( mEndPhi >= 180.0 ){
2292 x[2] = mCenter[2] - mRadius;
2293 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2297 for ( i=0; i < localThetaResolution; i++){
2298 theta = localStartTheta * Standard_PI / 180.0 + i*deltaTheta;
2299 for ( j = jStart; j < jEnd; j++){
2300 phi = startPhi + j*deltaPhi;
2301 radius = mRadius * sin((double)phi);
2302 n[0] = radius * cos((double)theta);
2303 n[1] = radius * sin((double)theta);
2304 n[2] = mRadius * cos((double)phi);
2305 x[0] = n[0] + mCenter[0];
2306 x[1] = n[1] + mCenter[1];
2307 x[2] = n[2] + mCenter[2];
2308 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2314 number_triangle = 1;
2315 if ( mStartPhi <= 0.0 ){// around north pole
2316 for (i=0; i < localThetaResolution; i++){
2317 pts[0] = phiResolution*i + numPoles;
2318 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2320 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2325 if ( mEndPhi >= 180.0 ){ // around south pole
2326 numOffset = phiResolution - 1 + numPoles;
2327 for (i=0; i < localThetaResolution; i++){
2328 pts[0] = phiResolution*i + numOffset;
2329 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2330 pts[1] = numPoles - 1;
2331 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2336 // bands in-between poles
2338 for (i=0; i < localThetaResolution; i++){
2339 for (j=0; j < (phiResolution-1); j++){
2340 pts[0] = phiResolution*i + j + numPoles;
2341 pts[1] = pts[0] + 1;
2342 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2343 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2346 pts[2] = pts[1] - 1;
2347 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2352 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2354 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2356 Standard_Integer index[3];
2357 Standard_Real Tol = Precision::Confusion();
2360 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2361 gp_XYZ eqPlan(0, 0, 0);
2362 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2363 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2364 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2365 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2367 Standard_Real mod = vv.Modulus();
2368 if(mod < Tol) continue;
2372 Standard_Real modmax = eqPlan.Modulus();
2375 Nor = gp_Dir(eqPlan);
2377 Nor = gp_Dir(0., 0., 1.);
2379 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2380 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2381 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2382 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2386 polyTriangulation->SetNormals(Normals);
2388 return polyTriangulation;
2391 //===============================================================================================
2392 //function : VDrawSphere
2394 //purpose : Create an AIS shape.
2395 //===============================================================================================
2396 static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2399 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2400 if (aContextAIS.IsNull())
2402 std::cout << "Call vinit before!\n";
2407 std::cout << "Use: " << argv[0]
2408 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
2412 // read the arguments
2413 TCollection_AsciiString aShapeName (argv[1]);
2414 Standard_Integer aResolution = atoi (argv[2]);
2415 Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0;
2416 Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
2417 Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
2418 Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
2419 Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True;
2420 Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1;
2421 Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False;
2423 if (aRedrawsNb <= 0)
2428 // remove AIS object with given name from map
2429 if (GetMapOfAIS().IsBound2 (aShapeName))
2431 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aShapeName);
2432 Handle(AIS_InteractiveObject) anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
2433 if (anInterObj.IsNull())
2435 std::cout << "Shape name was used for non AIS viewer\n!";
2438 aContextAIS->Remove (anInterObj, Standard_False);
2439 GetMapOfAIS().UnBind2 (aShapeName);
2442 // enable/disable VBO
2443 Handle(Graphic3d_GraphicDriver) aDriver =
2444 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2445 if (!aDriver.IsNull())
2447 aDriver->EnableVBO (isVBOEnabled);
2450 std::cout << "Compute Triangulation...\n";
2451 Handle(AIS_Triangulation) aShape
2452 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2455 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2456 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2458 // register the object in map
2459 GetMapOfAIS().Bind (aShape, aShapeName);
2461 // stupid initialization of Green color in RGBA space as integer
2462 // probably wrong for big-endian CPUs
2463 Standard_Integer aRed = 0;
2464 Standard_Integer aGreen = 255;
2465 Standard_Integer aBlue = 0;
2466 Standard_Integer anAlpha = 0; // not used
2467 Standard_Integer aColorInt = aRed;
2468 aColorInt += aGreen << 8;
2469 aColorInt += aBlue << 16;
2470 aColorInt += anAlpha << 24;
2472 // setup colors array per vertex
2473 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2474 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2476 aColorArray->SetValue (aNodeId, aColorInt);
2478 aShape->SetColors (aColorArray);
2481 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2482 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2483 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2484 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2485 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2486 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2487 aTotalSize >>= 20; //MB
2488 aNormalsSize >>= 20;
2490 aTrianglesSize >>= 20;
2491 aPolyConnectSize >>= 20;
2492 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2493 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2494 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2495 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2496 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2497 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2499 // Setting material properties, very important for desirable visual result!
2500 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2501 aMat.SetAmbient (0.2);
2502 aMat.SetSpecular (0.5);
2503 Handle(Graphic3d_AspectFillArea3d) anAspect
2504 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2506 Quantity_NOC_YELLOW,
2511 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2514 anAspect->SetEdgeOn();
2518 anAspect->SetEdgeOff();
2520 aShAsp->SetAspect (anAspect);
2521 aShape->Attributes()->SetShadingAspect (aShAsp);
2523 aContextAIS->Display (aShape, Standard_False);
2525 // Two viewer updates are needed in order to measure time spent on
2526 // loading triangulation to graphic card memory + redrawing (1st update) and
2527 // time spent on redrawing itself (2nd and all further updates)
2528 OSD_Chronometer aTimer;
2529 Standard_Real aUserSeconds, aSystemSeconds;
2531 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2532 for (Standard_Integer anInteration = 0; anInteration < aRedrawsNb; ++anInteration)
2534 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
2536 if (anInteration == 0)
2538 aViewer->ActiveView()->Update();
2542 aViewer->ActiveView()->Redraw();
2546 aTimer.Show (aUserSeconds, aSystemSeconds);
2548 std::cout << "Number of scene redrawings: " << aRedrawsNb << "\n"
2549 << "CPU user time: "
2550 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aUserSeconds
2552 << "CPU system time: "
2553 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aSystemSeconds
2555 << "CPU average time of scene redrawing: "
2556 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * (aUserSeconds / (Standard_Real )aRedrawsNb)
2561 //===============================================================================================
2562 //function : VClipPlane
2564 //===============================================================================================
2565 static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2567 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2568 Handle(V3d_View) aView = ViewerTest::CurrentView();
2569 Standard_Real coeffA, coeffB, coeffC, coeffD;
2570 if (aViewer.IsNull() || aView.IsNull())
2572 std::cout << "Viewer not initialized!\n";
2576 // count an active planes count
2577 Standard_Integer aNewPlaneId = 1;
2578 Standard_Integer anActivePlanes = 0;
2579 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
2581 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2582 if (aView->IsActivePlane (aPlaneV3d))
2590 // just show info about existing planes
2591 Standard_Integer aPlaneId = 1;
2592 std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
2593 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2595 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2596 aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
2597 gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
2598 const gp_Pnt& aLoc = aPlane.Location();
2599 const gp_Dir& aNor = aPlane.Axis().Direction();
2600 Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
2601 std::cout << "Plane #" << aPlaneId
2602 << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
2603 << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
2604 << (isActive ? " on" : " off")
2605 << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
2610 std::cout << "No defined clipping planes\n";
2614 else if (argc == 2 || argc == 3)
2616 Standard_Integer aPlaneIdToOff = (argc == 3) ? atoi (argv[1]) : 1;
2617 Standard_Boolean toIterateAll = (argc == 2);
2618 TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
2619 isOnOffStr.LowerCase();
2620 Standard_Integer aPlaneId = 1;
2621 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2623 if (aPlaneIdToOff == aPlaneId || toIterateAll)
2625 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2626 if (isOnOffStr.Search ("off") >= 0)
2628 aView->SetPlaneOff (aPlaneV3d);
2629 std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
2631 else if (isOnOffStr.Search ("on") >= 0)
2633 // avoid z-fighting glitches
2635 if (!aView->IsActivePlane (aPlaneV3d))
2637 if (anActivePlanes < aView->View()->PlaneLimit())
2639 aView->SetPlaneOn (aPlaneV3d);
2640 std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
2644 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2645 << "You should disable or remove some existing plane to activate this one\n";
2650 std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
2653 else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
2655 aPlaneV3d->Erase(); // not performed on destructor!!!
2656 aView->SetPlaneOff (aPlaneV3d);
2657 aViewer->DelPlane (aPlaneV3d);
2658 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2661 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
2663 aPlaneV3d = aViewer->DefinedPlane();
2664 aPlaneV3d->Erase(); // not performed on destructor!!!
2665 aView->SetPlaneOff (aPlaneV3d);
2666 aViewer->DelPlane (aPlaneV3d);
2667 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2676 else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
2678 // avoid z-fighting glitches
2679 aView->SetPlaneOff (aPlaneV3d);
2680 aPlaneV3d->Display (aView);
2681 std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
2683 else if (isOnOffStr.Search ("hide") >= 0)
2686 std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
2690 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2695 if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
2697 std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
2705 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2709 Standard_Real aLocX = atof (argv[1]);
2710 Standard_Real aLocY = atof (argv[2]);
2711 Standard_Real aLocZ = atof (argv[3]);
2712 Standard_Real aNormDX = atof (argv[4]);
2713 Standard_Real aNormDY = atof (argv[5]);
2714 Standard_Real aNormDZ = atof (argv[6]);
2716 Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
2717 gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
2718 aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
2719 aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
2721 aViewer->AddPlane (aPlaneV3d); // add to defined planes list
2722 std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
2723 if (anActivePlanes < aView->View()->PlaneLimit())
2725 aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
2730 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2731 << "You should disable or remove some existing plane to activate the new one\n";
2736 //=======================================================================
2737 //function : ObjectsCommands
2739 //=======================================================================
2741 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
2743 const char *group ="AISObjects";
2744 theCommands.Add("vtrihedron",
2745 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
2746 __FILE__,VTrihedron,group);
2748 theCommands.Add("vtri2d",
2749 "vtri2d Name Selection in the viewer only ",
2750 __FILE__,VTrihedron2D ,group);
2752 theCommands.Add("vplanetri",
2753 "vplanetri Name Selection in the viewer only ",
2754 __FILE__,VPlaneTrihedron ,group);
2756 theCommands.Add("vsize",
2757 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
2758 __FILE__,VSize,group);
2760 theCommands.Add("vaxis",
2761 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
2762 __FILE__,VAxisBuilder,group);
2764 theCommands.Add("vaxispara",
2766 __FILE__,VAxisBuilder,group);
2768 theCommands.Add("vaxisortho",
2770 __FILE__,VAxisBuilder,group);
2772 theCommands.Add("vpoint",
2773 "vpoint PointName [Xa] [Ya] [Za] ",
2774 __FILE__,VPointBuilder,group);
2776 theCommands.Add("vplane",
2777 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
2778 __FILE__,VPlaneBuilder,group);
2780 theCommands.Add("vplanepara",
2781 "vplanepara PlaneName ",
2782 __FILE__,VPlaneBuilder,group);
2784 theCommands.Add("vplaneortho",
2785 "vplaneortho PlaneName ",
2786 __FILE__,VPlaneBuilder,group);
2788 theCommands.Add("vline",
2789 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
2790 __FILE__,VLineBuilder,group);
2792 theCommands.Add("vcircle",
2793 "vcircle CircleName [PointName/PlaneName] [PointName] [Radius] ",
2794 __FILE__,VCircleBuilder,group);
2796 theCommands.Add("vdrawtext",
2797 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect FONT ",
2798 __FILE__,VDrawText,group);
2800 theCommands.Add("vdrawsphere",
2801 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n",
2802 __FILE__,VDrawSphere,group);
2804 theCommands.Add("vclipplane",
2805 "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
2806 __FILE__,VClipPlane,group);