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>
80 #include <HLRAlgo_Projector.hxx>
81 #include <HLRBRep_PolyAlgo.hxx>
82 #include <HLRBRep_PolyHLRToShape.hxx>
83 #include <Aspect_Window.hxx>
85 #include <Graphic3d_ArrayOfPoints.hxx>
86 #include <Graphic3d_ArrayOfSegments.hxx>
87 #include <Graphic3d_ArrayOfPolylines.hxx>
88 #include <Graphic3d_ArrayOfTriangles.hxx>
89 #include <Graphic3d_ArrayOfTriangleFans.hxx>
90 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
91 #include <Graphic3d_ArrayOfQuadrangles.hxx>
92 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
93 #include <Graphic3d_ArrayOfPolygons.hxx>
94 #include <Graphic3d_Group.hxx>
95 #include <Standard_Real.hxx>
102 #define _CRT_SECURE_NO_DEPRECATE
103 #pragma warning (disable:4996)
106 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
107 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
108 const Handle(AIS_InteractiveObject)& theAISObj,
109 Standard_Boolean theReplaceIfExists = Standard_True);
110 Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
111 extern Handle(AIS_InteractiveContext)& TheAISContext();
114 //==============================================================================
115 //function : Vtrihedron 2d
116 //purpose : Create a plane with a 2D trihedron from a faceselection
117 //Draw arg : vtri2d name
118 //==============================================================================
119 #include <AIS_PlaneTrihedron.hxx>
123 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
126 // Verification des arguments
127 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
130 Standard_Integer myCurrentIndex;
131 // Fermeture des contextes
132 TheAISContext()->CloseAllContexts();
133 // Ouverture d'un contexte local et recuperation de son index.
134 TheAISContext()->OpenLocalContext();
135 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
136 // On active les modes de selections faces.
137 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
138 di<<" Select a face ."<<"\n";
140 // Boucle d'attente waitpick.
141 Standard_Integer argccc = 5;
142 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
143 const char **argvvv = (const char **) bufff;
144 while (ViewerMainLoop( argccc, argvvv) ) { }
148 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
149 ShapeB = TheAISContext()->SelectedShape();
152 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
154 // Construction du Plane
155 // recuperation des edges des faces.
156 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
158 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
162 // si il y a plusieurs edges
163 if (FaceExpB.More() ) {
165 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
166 BRepAdaptor_Curve theCurveB(EdgeB);
167 BRepAdaptor_Curve theCurveC(EdgeC);
168 A=theCurveC.Value(0.1);
169 B=theCurveC.Value(0.9);
170 C=theCurveB.Value(0.5);
173 // FaceB a 1 unique edge courbe
174 BRepAdaptor_Curve theCurveB(EdgeB);
175 A=theCurveB.Value(0.1);
176 B=theCurveB.Value(0.9);
177 C=theCurveB.Value(0.5);
179 // Construction du Geom_Plane
180 GC_MakePlane MkPlane(A,B,C);
181 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
183 // Construction de l'AIS_PlaneTrihedron
184 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
186 // Fermeture du contexte local.
187 TheAISContext()->CloseLocalContext(myCurrentIndex);
189 // on le display & bind
190 TheAISContext()->Display(theAISPlaneTri );
191 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
198 //==============================================================================
199 //function : VTriherdron
201 //purpose : Create a trihedron. If no arguments are set, the default
202 // trihedron (Oxyz) is created.
203 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
204 //==============================================================================
206 static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
209 // Verification des arguments
210 if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
212 // Declarations et creation des objets par default
213 TCollection_AsciiString name=argv[1];
215 if(argc > 5 && argc!=11)
216 {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
218 // Cas ou il y a des arguments
219 Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.};
223 coord[i]= atof(argv[2+i]);
227 coord[3+i] = atof(argv[6+i]);
228 coord[6+i] = atof(argv[8+i]);
232 gp_Pnt ThePoint(coord[0],coord[1],coord[2]);
233 gp_Dir TheZVector(coord[3],coord[4],coord[5]);
234 gp_Dir TheXVector(coord[6],coord[7],coord[8]);
236 if ( !TheZVector.IsNormal(TheXVector,PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;}
238 Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector);
240 // Creation du triedre
241 Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii);
242 GetMapOfAIS().Bind(aShape,name);
243 TheAISContext()->Display(aShape);
251 //==============================================================================
254 //purpose : Change the size of a named or selected trihedron
255 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
256 // if no value, the value is set at 100 by default
257 //Draw arg : vsize [name] [size]
258 //==============================================================================
260 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
263 // Declaration de booleens
264 Standard_Boolean ThereIsName;
265 Standard_Boolean ThereIsCurrent;
267 Standard_Boolean hascol;
269 Quantity_NameOfColor col;
271 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
274 // Verification des arguments
275 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
277 // Verification du nombre d'arguments
278 if (argc==1) {ThereIsName=Standard_False;value=100;}
279 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
280 else {ThereIsName=Standard_True;value=atof(argv[2]);}
282 // On ferme le contexte local pour travailler dans le contexte global
283 if(TheAISContext()->HasOpenedContext())
284 TheAISContext()->CloseLocalContext();
286 // On set le booleen ThereIsCurrent
287 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
288 else {ThereIsCurrent=Standard_False;}
292 //===============================================================
293 // Il n'y a pas de nom mais des objets selectionnes
294 //===============================================================
295 if (!ThereIsName && ThereIsCurrent)
298 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
301 while ( it.More() ) {
303 Handle(AIS_InteractiveObject) aShape=
304 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
306 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
309 // On verifie que l'AIS InteraciveObject selectionne est bien
311 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
313 if (aShape->HasColor()) {
314 hascol=Standard_True;
316 // On recupere la couleur de aShape
317 col=aShape->Color();}
319 else hascol=Standard_False;
321 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
322 // pour lui appliquer la methode SetSize()
323 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
325 // C'est bien un triedre,on chage sa valeur!
326 aTrihedron->SetSize(value);
328 // On donne la couleur au Trihedron
329 if(hascol) aTrihedron->SetColor(col);
330 else aTrihedron->UnsetColor();
333 // The trihedron hasn't be errased from the map
334 // so you just have to redisplay it
335 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
344 TheAISContext() ->UpdateCurrentViewer();
347 //===============================================================
348 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
349 //===============================================================
353 //===============================================================
354 // Il y a un nom de triedre passe en argument
355 //===============================================================
357 TCollection_AsciiString name=argv[1];
359 // on verifie que ce nom correspond bien a une shape
360 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
364 // on recupere la shape dans la map des objets displayes
365 Handle(AIS_InteractiveObject) aShape =
366 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
368 // On verifie que l'AIS InteraciveObject est bien
370 if (!aShape.IsNull() &&
371 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
374 if (aShape->HasColor()) {
375 hascol=Standard_True;
377 // On recupere la couleur de aShape
378 col=aShape->Color();}
380 else hascol=Standard_False;
382 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
383 // pour lui appliquer la methode SetSize()
384 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
386 // C'est bien un triedre,on chage sa valeur
387 aTrihedron->SetSize(value);
389 // On donne la couleur au Trihedron
390 if(hascol) aTrihedron->SetColor(col);
391 else aTrihedron->UnsetColor();
393 // The trihedron hasn't be errased from the map
394 // so you just have to redisplay it
395 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
397 TheAISContext() ->UpdateCurrentViewer();
405 //==============================================================================
407 //==============================================================================
408 //function : VPlaneTrihedron
409 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
410 //Draw arg : vplanetri name
411 //==============================================================================
412 #include <AIS_Plane.hxx>
416 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
419 // Verification des arguments
420 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
423 Standard_Integer myCurrentIndex;
424 // Fermeture des contextes locaux
425 TheAISContext()->CloseAllContexts();
427 // On recupere tous les trihedrons de la GetMapOfAIS()
428 // et on active le mode de selection par face.
429 // =================================================
431 // Ouverture d'un contexte local et recuperation de son index.
432 TheAISContext()->OpenLocalContext(Standard_False);
433 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
435 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
438 Handle(AIS_InteractiveObject) ShapeA =
439 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
440 // On verifie que c'est bien un trihedron
441 if (!ShapeA.IsNull() &&
442 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
444 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
445 // on le charge dans le contexte et on active le mode Plane.
446 TheAISContext()->Load(TrihedronA,0,Standard_False);
447 TheAISContext()->Activate(TrihedronA,3);
452 di<<" Select a plane."<<"\n";
453 // Boucle d'attente waitpick.
454 Standard_Integer argccc = 5;
455 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
456 const char **argvvv = (const char **) bufff;
457 while (ViewerMainLoop( argccc, argvvv) ) { }
460 Handle(AIS_InteractiveObject) theIOB;
461 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
462 theIOB = TheAISContext()->Interactive();
465 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
467 // Fermeture du contexte local.
468 TheAISContext()->CloseLocalContext(myCurrentIndex);
470 // on le display & bind
471 TheAISContext()->Display(PlaneB );
472 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
479 //==============================================================================
480 // Fonction First click 2de click
482 // vaxis vertex vertex
484 // vaxispara edge vertex
485 // vaxisortho edge Vertex
486 // vaxisinter Face Face
487 //==============================================================================
489 //==============================================================================
490 //function : VAxisBuilder
492 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
493 //==============================================================================
494 #include <TopoDS_Edge.hxx>
495 #include <TopoDS_Vertex.hxx>
496 #include <TopExp.hxx>
497 #include <Geom_Line.hxx>
499 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
502 Standard_Boolean HasArg;
503 TCollection_AsciiString name;
504 Standard_Integer MyCurrentIndex;
507 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
508 if (argc==8) HasArg=Standard_True;
509 else HasArg=Standard_False;
512 // Fermeture des contextes
513 TheAISContext()->CloseAllContexts();
515 // Cas ou il y a des arguments
516 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
518 Standard_Real coord[6];
519 for(Standard_Integer i=0;i<=5;i++){
520 coord[i]=atof(argv[2+i]);
522 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
524 gp_Vec myVect (p1,p2);
525 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
526 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
527 GetMapOfAIS().Bind (TheAxis,name);
528 TheAISContext()->Display(TheAxis);
534 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
535 if ( !strcasecmp(argv[0], "vaxis")) {
536 TheAISContext()->OpenLocalContext();
537 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
539 // Active le mode edge et le mode vertex
540 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
541 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
542 di<<" Select an edge or a vertex."<<"\n";
544 // Boucle d'attente waitpick.
545 Standard_Integer argcc = 5;
546 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
547 const char **argvv = (const char **) buff;
548 while (ViewerMainLoop( argcc, argvv) ) { }
551 // recuperation de la shape.
553 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
554 ShapeA = TheAISContext()->SelectedShape();
556 // recuperation de l'AIS_InteractiveObject
557 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
558 // down cast en AIS_Point si sig et type
559 // AIS_Point -> Geom_Pnt ....
561 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
562 // on desactive le mode edge
563 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
564 di<<" Select a different vertex."<<"\n";
568 // Boucle d'attente waitpick.
569 Standard_Integer argccc = 5;
570 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
571 const char **argvvv = (const char **) bufff;
572 while (ViewerMainLoop( argccc, argvvv) ) { }
574 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
575 ShapeB = TheAISContext()->SelectedShape();
579 } while(ShapeB.IsSame(ShapeA) );
581 // Fermeture du context local
582 TheAISContext()->CloseLocalContext(MyCurrentIndex);
584 // Construction de l'axe
585 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
586 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
589 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
590 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
591 GetMapOfAIS().Bind (TheAxis,name);
592 TheAISContext()->Display(TheAxis);
595 // Un unique edge (ShapeA) a ete picke
596 // Fermeture du context local
597 TheAISContext()->CloseLocalContext(MyCurrentIndex);
598 // Constuction de l'axe
599 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
601 TopExp::Vertices(ed,Va,Vb );
602 gp_Pnt A=BRep_Tool::Pnt(Va);
603 gp_Pnt B=BRep_Tool::Pnt(Vb);
606 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
607 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
608 GetMapOfAIS().Bind (TheAxis,name);
609 TheAISContext()->Display(TheAxis);
615 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
616 else if ( !strcasecmp(argv[0], "vaxispara")) {
618 TheAISContext()->OpenLocalContext();
619 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
621 // Active le mode edge
622 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
623 di<<" Select an edge."<<"\n";
625 // Boucle d'attente waitpick.
626 Standard_Integer argcc = 5;
627 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
628 const char **argvv = (const char **) buff;
629 while (ViewerMainLoop( argcc, argvv) ) { }
633 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
634 ShapeA = TheAISContext()->SelectedShape();
636 // Active le mode vertex et deactive edges
637 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
638 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
639 di<<" Select a vertex."<<"\n";
641 // Boucle d'attente waitpick.
642 Standard_Integer argccc = 5;
643 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
644 const char **argvvv = (const char **) bufff;
645 while (ViewerMainLoop( argccc, argvvv) ) { }
648 // On peut choisir un pnt sur l'edge
650 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
651 ShapeB = TheAISContext()->SelectedShape();
653 // Fermeture du context local
654 TheAISContext()->CloseLocalContext(MyCurrentIndex);
656 // Construction de l'axe
657 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
658 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
660 TopExp::Vertices(ed,Va,Vc );
661 gp_Pnt A=BRep_Tool::Pnt(Va);
662 gp_Pnt C=BRep_Tool::Pnt(Vc);
665 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
666 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
667 GetMapOfAIS().Bind (TheAxis,name);
668 TheAISContext()->Display(TheAxis);
672 // Fonction axisortho
674 TheAISContext()->OpenLocalContext();
675 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
677 // Active le mode edge
678 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
679 di<<" Select an edge."<<"\n";
681 // Boucle d'attente waitpick.
682 Standard_Integer argcc = 5;
683 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
684 const char **argvv = (const char **) buff;
685 while (ViewerMainLoop( argcc, argvv) ) { }
689 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
690 ShapeA = TheAISContext()->SelectedShape();
692 // Active le mode vertex et deactive edges
693 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
694 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
695 di<<" Slect a vertex."<<"\n";
697 // Boucle d'attente waitpick.
698 Standard_Integer argccc = 5;
699 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
700 const char **argvvv = (const char **) bufff;
701 while (ViewerMainLoop( argccc, argvvv) ) { }
704 // On peut choisir un pnt sur l'edge
706 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
707 ShapeB = TheAISContext()->SelectedShape();
709 // Fermeture du context local
710 TheAISContext()->CloseLocalContext(MyCurrentIndex);
712 // Construction de l'axe
713 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
714 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
716 TopExp::Vertices(ed,Va,Vc );
717 gp_Pnt A=BRep_Tool::Pnt(Va);
718 gp_Pnt C=BRep_Tool::Pnt(Vc);
719 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
722 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
723 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
724 GetMapOfAIS().Bind (TheAxis,name);
725 TheAISContext()->Display(TheAxis);
734 //==============================================================================
735 // Fonction First click Result
737 // vpoint vertex AIS_Point=Vertex
738 // edge AIS_Point=Middle of the edge
739 //==============================================================================
741 //==============================================================================
742 //function : VPointBuilder
743 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
744 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
745 //==============================================================================
746 #include <TopoDS_Edge.hxx>
747 #include <TopoDS_Vertex.hxx>
748 #include <TopExp.hxx>
749 #include <AIS_Point.hxx>
750 #include <Geom_CartesianPoint.hxx>
752 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
755 Standard_Boolean HasArg;
756 TCollection_AsciiString name;
757 Standard_Integer myCurrentIndex;
760 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
761 if (argc==5) HasArg=Standard_True;
762 else HasArg=Standard_False;
765 // Fermeture des contextes
766 TheAISContext()->CloseAllContexts();
768 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
770 Standard_Real thecoord[3];
771 for(Standard_Integer i=0;i<=2;i++)
772 thecoord[i]=atof(argv[2+i]);
773 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
774 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
775 GetMapOfAIS().Bind (myAISPoint,name);
776 TheAISContext()->Display(myAISPoint);
779 // Il n'a pas d'arguments
781 TheAISContext()->OpenLocalContext();
782 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
784 // Active le mode Vertex et Edges
785 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
786 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
787 di<<" Select a vertex or an edge(build the middle)"<<"\n";
789 // Boucle d'attente waitpick.
790 Standard_Integer argcc = 5;
791 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
792 const char **argvv = (const char **) buff;
793 while (ViewerMainLoop( argcc, argvv) ) { }
797 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
798 ShapeA= TheAISContext()->SelectedShape();
801 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
802 // Un vertex a ete selectionne
803 // Fermeture du context local
804 TheAISContext()->CloseLocalContext(myCurrentIndex);
806 // Construction du point
807 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
808 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
809 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
810 GetMapOfAIS().Bind(myAISPoint,name);
811 TheAISContext()->Display(myAISPoint);
814 // Un Edge a ete selectionne
815 // Fermeture du context local
816 TheAISContext()->CloseLocalContext(myCurrentIndex);
818 // Construction du point milieu de l'edge
819 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
820 TopoDS_Vertex myVertexA,myVertexB;
821 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
822 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
823 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
824 // M est le milieu de [AB]
825 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
826 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
827 GetMapOfAIS().Bind(myAISPointM,name);
828 TheAISContext()->Display(myAISPointM);
836 //==============================================================================
837 // Fonction 1st click 2de click 3de click
838 // vplane Vertex Vertex Vertex
842 // vplanepara Face Vertex
844 // vplaneortho Face Edge
846 //==============================================================================
848 //==============================================================================
849 //function : VPlaneBuilder
850 //purpose : Build an AIS_Plane from selected entities or Named AIs components
851 //Draw arg : vplane PlaneName [AxisName] [PointName]
852 // [PointName] [PointName] [PointName]
853 // [PlaneName] [PointName]
854 //==============================================================================
856 #include <TopoDS_Edge.hxx>
857 #include <TopoDS_Vertex.hxx>
858 #include <TopoDS_Face.hxx>
859 #include <TopExp.hxx>
860 #include <AIS_Plane.hxx>
861 #include <Geom_CartesianPoint.hxx>
862 #include <Geom_Plane.hxx>
863 #include <BRepExtrema_ExtPC.hxx>
864 #include <BRepExtrema_ExtPF.hxx>
865 #include <BRepAdaptor_Surface.hxx>
866 #include <gp_Pln.hxx>
867 #include <GC_MakePlane.hxx>
869 static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
872 Standard_Boolean HasArg;
873 TCollection_AsciiString name;
874 Standard_Integer myCurrentIndex;
877 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
878 if (argc==5 || argc==4) HasArg=Standard_True;
879 else HasArg=Standard_False;
882 // Fermeture des contextes
883 TheAISContext()->CloseAllContexts();
886 // Il y a des arguments
888 if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
889 // on recupere la shape dans la map
890 Handle(AIS_InteractiveObject) theShapeA =
891 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
893 // Le premier argument est un AIS_Point 1
894 if (!theShapeA.IsNull() &&
895 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
896 // le deuxieme argument doit etre un AIS_Point aussi
897 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
898 // on recupere la shape dans la map
899 Handle(AIS_InteractiveObject) theShapeB =
900 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
901 // si B n'est pas un AIS_Point
902 if (theShapeB.IsNull() ||
903 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
905 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
908 // le troisieme objet est un AIS_Point
909 if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; }
910 // on recupere la shape dans la map
911 Handle(AIS_InteractiveObject) theShapeC =
912 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
913 // si C n'est pas un AIS_Point
914 if (theShapeC.IsNull() ||
915 (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1)))
917 di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n";
921 // Traitement des objets A,B,C
922 // Downcaste de AIS_IO en AIS_Point
923 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
924 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
925 Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
927 Handle(Geom_Point ) myGeomPointA= theAISPointA->Component();
928 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA);
929 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
931 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
932 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
933 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
935 Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component();
936 Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC);
937 // Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ;
939 // Verification que les 3 points sont bien differents.
940 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
942 di<<"vplane error: same points"<<"\n";return 1;
944 if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) {
946 di<<"vplane error: same points"<<"\n";return 1;
948 if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) {
950 di<<"vplane error: same points"<<"\n";return 1;
953 gp_Pnt A= myCartPointA->Pnt();
954 gp_Pnt B= myCartPointB->Pnt();
955 gp_Pnt C= myCartPointC->Pnt();
957 // Construction de l'AIS_Plane
958 GC_MakePlane MkPlane (A,B,C);
959 Handle(Geom_Plane) myGeomPlane = MkPlane.Value();
960 Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane );
961 GetMapOfAIS().Bind (myAISPlane,name );
962 TheAISContext()->Display(myAISPlane);
965 // si le premier argument est un AIS_Axis 2
966 // creation d'un plan orthogonal a l'axe passant par un point
967 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) {
968 // le deuxieme argument doit etre un AIS_Point
969 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
971 di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
974 // on recupere la shape dans la map
975 Handle(AIS_InteractiveObject) theShapeB =
976 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
977 // si B n'est pas un AIS_Point
978 if (theShapeB.IsNull() ||
979 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
981 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
985 // Traitement des objets A et B
986 Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA;
987 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
989 Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component();
990 Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
992 gp_Ax1 myAxis= myGeomLineA->Position();
993 Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
995 // Pas de moyens de verifier que le point B n'est pas sur l'axe
997 gp_Dir D=myAxis.Direction();
998 gp_Pnt B= myCartPointB->Pnt();
1000 // Construction de l'AIS_Plane
1001 Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D);
1002 Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane,B );
1003 GetMapOfAIS().Bind (myAISPlane,name );
1004 TheAISContext()->Display(myAISPlane);
1007 // Si le premier argument est un AIS_Plane 7
1008 // Creation d'un Plan parallele a ce plan passant par le point
1009 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
1010 // le deuxieme argument doit etre un AISPoint
1011 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) {
1012 di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
1015 // on recupere la shape dans la map
1016 Handle(AIS_InteractiveObject) theShapeB =
1017 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1018 // si B n'est pas un AIS_Point
1019 if (theShapeB.IsNull() ||
1020 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1022 di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
1026 // Traitement des objets A et B
1027 Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA;
1028 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1030 Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component();
1031 Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
1033 Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
1034 gp_Pnt B= myCartPointB->Pnt();
1036 // Construction de l'AIS_Plane
1037 Handle(AIS_Plane) myAISPlane = new AIS_Plane(theNewGeomPlane,B );
1038 GetMapOfAIS().Bind (myAISPlane,name );
1039 TheAISContext()->Display(myAISPlane);
1043 else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;}
1047 // Il n'y a pas d'arguments
1051 // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1052 if (!strcasecmp(argv[0] ,"vplane" ) ) {
1053 TheAISContext()->OpenLocalContext();
1054 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1056 // Active les modes Vertex, Edge et Face
1057 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1058 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1059 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1060 di<<"Select a vertex, a face or an edge. "<<"\n";
1062 // Boucle d'attente waitpick.
1063 Standard_Integer argcc = 5;
1064 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1065 const char **argvv = (const char **) buff;
1066 while (ViewerMainLoop( argcc, argvv) ) { }
1069 TopoDS_Shape ShapeA;
1070 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1071 ShapeA = TheAISContext()->SelectedShape();
1074 // ShapeA est un Vertex
1075 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1076 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1077 di<<" Select an edge or a different vertex."<<"\n";
1079 // Boucle d'attente waitpick.
1080 Standard_Integer argccc = 5;
1081 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1082 const char **argvvv = (const char **) bufff;
1083 while (ViewerMainLoop( argccc, argvvv) ) { }
1086 TopoDS_Shape ShapeB;
1087 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1088 ShapeB = TheAISContext()->SelectedShape();
1090 // ShapeB est un Vertex
1091 if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1092 // Si A et B sont le meme point
1093 if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
1094 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1095 di<<" Select a different vertex."<<"\n";
1097 // Boucle d'attente waitpick.
1098 Standard_Integer argcccc = 5;
1099 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1100 const char **argvvvv = (const char **) buffff;
1101 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1104 TopoDS_Shape ShapeC;
1105 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1106 ShapeC = TheAISContext()->SelectedShape();
1108 // ShapeC est aussi un vertex...
1109 if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
1111 // Fermeture du contexte local
1112 TheAISContext()->CloseLocalContext(myCurrentIndex);
1114 // Construction du plane
1115 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
1116 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
1117 gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC ) );
1118 GC_MakePlane MkPlane(A,B,C);
1119 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1120 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1121 GetMapOfAIS().Bind (myAISPlane ,name );
1122 TheAISContext()->Display(myAISPlane);
1125 // ShapeB est un edge
1127 // il s'agit de verifier que le vertex ShapeA n'est pas sur l'edge ShapeB
1128 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1129 TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA);
1131 BRepExtrema_ExtPC OrthoProj (VertA, EdgeB );
1132 if (OrthoProj.SquareDistance(1)<1e-6 ) {
1133 // Le vertex est sur l'edge
1134 di<<" vplane: error point is on the edge."<<"\n";return 1;
1137 // le vertex n'appartient pes a l'edge on peut construire le plane
1138 // Fermeture du contexte local
1139 TheAISContext()->CloseLocalContext(myCurrentIndex);
1140 // Construction du plane
1141 gp_Pnt A=BRep_Tool::Pnt(VertA );
1142 TopoDS_Vertex VBa,VBb;
1143 TopExp::Vertices(EdgeB ,VBa ,VBb );
1144 gp_Pnt Ba=BRep_Tool::Pnt(VBa);
1145 gp_Pnt Bb=BRep_Tool::Pnt(VBb);
1146 GC_MakePlane MkPlane (A,Ba,Bb);
1147 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1148 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1149 GetMapOfAIS().Bind (myAISPlane ,name );
1150 TheAISContext()->Display(myAISPlane);
1157 // ShapeA est un edge
1158 else if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1160 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1161 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1162 di<<" Select a vertex that don't belong to the edge."<<"\n";
1164 // Boucle d'attente waitpick.
1165 Standard_Integer argccc = 5;
1166 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1167 const char **argvvv = (const char **) bufff;
1168 while (ViewerMainLoop( argccc, argvvv) ) { }
1171 TopoDS_Shape ShapeB;
1172 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1173 ShapeB = TheAISContext()->SelectedShape();
1175 // ShapeB est forcement un Vertex
1176 // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA
1177 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1178 TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB);
1180 BRepExtrema_ExtPC OrthoProj (VertB,EdgeA );
1181 if (OrthoProj.SquareDistance(1)<1e-6) {
1182 // Le vertex est sur l'edge
1183 di<<" vplane: error point is on the edge."<<"\n";return 1;
1186 // le vertex n'appartient pas a l'edge on peut construire le plane
1187 // Fermeture du contexte local
1188 TheAISContext()->CloseLocalContext(myCurrentIndex);
1189 // Construction du plane
1190 gp_Pnt B=BRep_Tool::Pnt(VertB );
1191 TopoDS_Vertex VAa,VAb;
1192 TopExp::Vertices(EdgeA ,VAa ,VAb );
1193 gp_Pnt Aa=BRep_Tool::Pnt(VAa);
1194 gp_Pnt Ab=BRep_Tool::Pnt(VAb);
1195 GC_MakePlane MkPlane (B,Aa,Ab);
1196 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1197 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1198 GetMapOfAIS().Bind (myAISPlane ,name );
1199 TheAISContext()->Display(myAISPlane);
1205 // ShapeA est une Face
1207 // Fermeture du contexte local: Plus rien a selectionner
1208 TheAISContext()->CloseLocalContext(myCurrentIndex);
1209 // Construction du plane
1210 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1211 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1212 if (mySurface.GetType()==GeomAbs_Plane ) {
1213 gp_Pln myPlane=mySurface.Plane();
1214 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1215 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
1216 GetMapOfAIS().Bind (myAISPlane ,name );
1217 TheAISContext()->Display(myAISPlane);
1221 di<<" vplane: error"<<"\n";return 1;
1228 // Fonction vPlanePara
1229 // ===================
1230 // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt )
1231 else if (!strcasecmp(argv[0] ,"vplanepara" )) {
1233 TheAISContext()->OpenLocalContext();
1234 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1236 // Active les modes Vertex et Face
1237 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1238 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1239 di<<" Select a vertex or a face."<<"\n";
1241 // Boucle d'attente waitpick.
1242 Standard_Integer argcc = 5;
1243 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1244 const char **argvv = (const char **) buff;
1245 while (ViewerMainLoop( argcc, argvv) ) { }
1248 TopoDS_Shape ShapeA;
1249 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1250 ShapeA = TheAISContext()->SelectedShape();
1253 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1254 // ShapeA est un vertex
1255 // On desactive le mode Vertex
1256 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
1257 di<<" Select a face."<<"\n";
1259 // Boucle d'attente waitpick.
1260 Standard_Integer argccc = 5;
1261 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1262 const char **argvvv = (const char **) bufff;
1263 while (ViewerMainLoop( argccc, argvvv) ) { }
1266 TopoDS_Shape ShapeB;
1267 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1268 // Le vertex ShapeA peut etre dans la Face ShapeB
1269 ShapeB = TheAISContext()->SelectedShape();
1272 // Fermeture du context local
1273 TheAISContext()->CloseLocalContext(myCurrentIndex);
1275 // Construction du plane
1276 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
1278 TopoDS_Face myFace=TopoDS::Face(ShapeB);
1279 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1280 if (mySurface.GetType()==GeomAbs_Plane ) {
1281 gp_Pln myPlane=mySurface.Plane();
1282 // construit un plan parallele a theGeomPlane passant par A
1283 myPlane.SetLocation(A);
1284 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1285 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A );
1286 GetMapOfAIS().Bind (myAISPlane ,name );
1287 TheAISContext()->Display(myAISPlane);
1291 di<<" vplane: error"<<"\n";return 1;
1296 // ShapeA est une Face
1297 // On desactive le mode Face
1298 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1299 di<<" Select a vertex."<<"\n";
1301 // Boucle d'attente waitpick.
1302 Standard_Integer argccc = 5;
1303 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1304 const char **argvvv = (const char **) bufff;
1305 while (ViewerMainLoop( argccc, argvvv) ) { }
1308 TopoDS_Shape ShapeB;
1309 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1310 // Le vertex ShapeB peut etre dans la Face ShapeA
1311 ShapeB = TheAISContext()->SelectedShape();
1313 // Fermeture du context local
1314 TheAISContext()->CloseLocalContext(myCurrentIndex);
1316 // Construction du plane
1317 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
1319 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1320 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1321 if (mySurface.GetType()==GeomAbs_Plane ) {
1322 gp_Pln myPlane=mySurface.Plane();
1323 myPlane.SetLocation(B);
1324 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1325 // construit un plan parallele a theGeomPlane passant par B
1326 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B );
1327 GetMapOfAIS().Bind (myAISPlane ,name );
1328 TheAISContext()->Display(myAISPlane);
1332 di<<" vplane: error"<<"\n";return 1;
1339 // Fonction vplaneortho
1340 // ====================
1341 // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1344 TheAISContext()->OpenLocalContext();
1345 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1347 // Active les modes Edge et Face
1348 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1349 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1350 di<<" Select a face and an edge coplanar."<<"\n";
1352 // Boucle d'attente waitpick.
1353 Standard_Integer argcc = 5;
1354 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1355 const char **argvv = (const char **) buff;
1356 while (ViewerMainLoop( argcc, argvv) ) { }
1359 TopoDS_Shape ShapeA;
1360 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1361 ShapeA = TheAISContext()->SelectedShape();
1364 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1365 // ShapeA est un edge, on desactive le mode edge...
1366 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1367 di<<" Select a face."<<"\n";
1369 // Boucle d'attente waitpick.
1370 Standard_Integer argccc = 5;
1371 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1372 const char **argvvv = (const char **) bufff;
1373 while (ViewerMainLoop( argccc, argvvv) ) { }
1376 TopoDS_Shape ShapeB;
1377 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1378 // L'edge ShapeA peut etre dans la Face ShapeB
1379 ShapeB = TheAISContext()->SelectedShape();
1382 // Fermeture du context local
1383 TheAISContext()->CloseLocalContext(myCurrentIndex);
1385 // Construction du plane
1386 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1387 TopoDS_Vertex VAa,VAb;
1389 TopExp::Vertices(EdgeA ,VAa ,VAb );
1390 gp_Pnt Aa=BRep_Tool::Pnt(VAa);
1391 gp_Pnt Ab=BRep_Tool::Pnt(VAb);
1395 // Creation de mon axe de rotation
1396 gp_Ax1 myRotAxis (Aa,Dab);
1398 TopoDS_Face myFace=TopoDS::Face(ShapeB);
1399 // Il faut imperativement que l'edge soit parallele a la face
1401 BRepExtrema_ExtPF myHauteurA (VAa , myFace );
1402 BRepExtrema_ExtPF myHauteurB (VAb , myFace );
1403 // on compare les deux hauteurs a la tolerance pres
1404 if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) {
1405 // l'edge n'est pas parallele a la face
1406 di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
1409 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1410 if (mySurface.GetType()==GeomAbs_Plane ) {
1411 gp_Pln myPlane=mySurface.Plane();
1412 // On effectue une rotation d'1/2 tour autour de l'axe de rotation
1413 myPlane.Rotate(myRotAxis , PI/2 );
1415 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1416 // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
1417 gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1418 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
1419 GetMapOfAIS().Bind (myAISPlane ,name );
1420 TheAISContext()->Display(myAISPlane);
1424 di<<" vplaneOrtho: error"<<"\n";return 1;
1430 // ShapeA est une Face, on desactive le mode face.
1431 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1432 di<<" Select an edge."<<"\n";
1434 // Boucle d'attente waitpick.
1435 Standard_Integer argccc = 5;
1436 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1437 const char **argvvv = (const char **) bufff;
1438 while (ViewerMainLoop( argccc, argvvv) ) { }
1441 TopoDS_Shape ShapeB;
1442 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1443 // L'edge ShapeB peut etre dans la Face ShapeA
1444 ShapeB = TheAISContext()->SelectedShape();
1447 // Fermeture du context local
1448 TheAISContext()->CloseLocalContext(myCurrentIndex);
1450 // Construction du plane
1451 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1452 TopoDS_Vertex VBa,VBb;
1453 TopExp::Vertices(EdgeB ,VBa ,VBb );
1454 gp_Pnt Ba=BRep_Tool::Pnt(VBa);
1455 gp_Pnt Bb=BRep_Tool::Pnt(VBb);
1458 // Creation de mon axe de rotation
1459 gp_Ax1 myRotAxis (Ba,Dab);
1461 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1462 // Il faut imperativement que l'edge soit parallele a la face
1463 BRepExtrema_ExtPF myHauteurA (VBa , myFace );
1464 BRepExtrema_ExtPF myHauteurB (VBb , myFace );
1465 // on compare les deux hauteurs a la tolerance pres
1466 if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) {
1467 // l'edge n'est pas parallele a la face
1468 di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
1471 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1472 if (mySurface.GetType()==GeomAbs_Plane ) {
1473 gp_Pln myPlane=mySurface.Plane();
1474 // On effectue une rotation d'1/2 tour autour de l'axe de rotation
1475 myPlane.Rotate(myRotAxis , PI/2 );
1476 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1477 // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
1478 gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 );
1479 Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
1480 GetMapOfAIS().Bind (myAISPlane ,name );
1481 TheAISContext()->Display(myAISPlane);
1485 di<<" vplaneOrtho: error"<<"\n";return 1;
1498 //==============================================================================
1500 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1501 //==============================================================================
1503 //==============================================================================
1504 //function : VLineBuilder
1505 //purpose : Build an AIS_Line
1506 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1507 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1508 //==============================================================================
1509 #include <Geom_CartesianPoint.hxx>
1510 #include <AIS_Line.hxx>
1513 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1515 Standard_Integer myCurrentIndex;
1517 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1518 // Fermeture des contextes
1519 TheAISContext()->CloseAllContexts();
1521 // On recupere les parametres
1522 Handle(AIS_InteractiveObject) theShapeA;
1523 Handle(AIS_InteractiveObject) theShapeB;
1525 // Parametres: AIS_Point AIS_Point
1526 // ===============================
1529 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1530 // On verifie que c'est bien une AIS_Point
1531 if (!theShapeA.IsNull() &&
1532 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1533 // on recupere le deuxieme AIS_Point
1535 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1536 if (theShapeA.IsNull() ||
1537 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1539 di <<"vline error: wrong type of 2de argument."<<"\n";
1543 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1544 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1545 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1546 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1548 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1549 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1550 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1552 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1553 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1554 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1556 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1558 di<<"vline error: same points"<<"\n";return 1;
1560 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1561 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1562 GetMapOfAIS().Bind(theAISLine,argv[1] );
1563 TheAISContext()->Display(theAISLine );
1567 // Parametres 6 Reals
1568 // ==================
1571 // On verifie que les deux points ne sont pas confondus
1573 Standard_Real coord[6];
1574 for(Standard_Integer i=0;i<=2;i++){
1575 coord[i]=atof(argv[2+i]);
1576 coord[i+3]=atof(argv[5+i]);
1579 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1580 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1582 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1583 GetMapOfAIS().Bind(theAISLine,argv[1] );
1584 TheAISContext()->Display(theAISLine );
1588 // Pas de parametres: Selection dans le viewer.
1589 // ============================================
1592 TheAISContext()->OpenLocalContext();
1593 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1595 // Active le mode Vertex.
1596 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1597 di<<" Select a vertex "<<"\n";
1599 // Boucle d'attente waitpick.
1600 Standard_Integer argcc = 5;
1601 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1602 const char **argvv = (const char **) buff;
1603 while (ViewerMainLoop( argcc, argvv) ) { }
1606 TopoDS_Shape ShapeA;
1607 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1608 ShapeA = TheAISContext()->SelectedShape();
1611 // ShapeA est un Vertex
1612 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1614 di<<" Select a different vertex."<<"\n";
1616 TopoDS_Shape ShapeB;
1619 // Boucle d'attente waitpick.
1620 Standard_Integer argccc = 5;
1621 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1622 const char **argvvv = (const char **) bufff;
1623 while (ViewerMainLoop( argccc, argvvv) ) { }
1626 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1627 ShapeB = TheAISContext()->SelectedShape();
1631 } while(ShapeB.IsSame(ShapeA) );
1633 // Fermeture du context local
1634 TheAISContext()->CloseLocalContext(myCurrentIndex);
1636 // Construction de la line
1637 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1638 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1640 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1641 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1643 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1644 GetMapOfAIS().Bind(theAISLine,argv[1] );
1645 TheAISContext()->Display(theAISLine );
1649 di<<"vline error."<<"\n";
1658 //==============================================================================
1660 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1661 //==============================================================================
1663 //==============================================================================
1664 //function : VCircleBuilder
1665 //purpose : Build an AIS_Circle
1666 //Draw arg : vcircle CircleName PlaneName PointName Radius
1667 // PointName PointName PointName
1668 //==============================================================================
1669 #include <Geom_CartesianPoint.hxx>
1670 #include <Geom_Circle.hxx>
1671 #include <AIS_Circle.hxx>
1672 #include <GC_MakeCircle.hxx>
1673 #include <Geom_Plane.hxx>
1674 #include <gp_Pln.hxx>
1676 static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1678 Standard_Integer myCurrentIndex;
1679 // verification of the arguments
1680 if (argc>5 || argc<2 ) {di<<"vcircle error: expect 3 arguments."<<"\n";return 1; }
1681 TheAISContext()->CloseAllContexts();
1683 // Il y a des arguments
1685 Handle(AIS_InteractiveObject) theShapeA;
1686 Handle(AIS_InteractiveObject) theShapeB;
1689 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1691 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1693 // Arguments: AIS_Point AIS_Point AIS_Point
1694 // ========================================
1695 if (!theShapeA.IsNull() && theShapeB.IsNull() &&
1696 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1698 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) {
1699 di<<"vcircle error: 2de argument is unexpected to be a point."<<"\n";
1702 // Le troisieme objet doit etre un point
1703 Handle(AIS_InteractiveObject) theShapeC =
1704 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
1705 if (theShapeC.IsNull() ||
1706 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) {
1707 di<<"vcircle error: 3de argument is unexpected to be a point."<<"\n";
1711 // On verifie que les 3 points sont differents.
1712 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1713 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1714 Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
1716 Handle(Geom_Point ) myGeomPointA= theAISPointA->Component();
1717 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA);
1719 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
1720 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
1722 Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component();
1723 Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC);
1726 if (myCartPointA->X()==myCartPointB->X() && myCartPointA->Y()==myCartPointB->Y() && myCartPointA->Z()==myCartPointB->Z() ) {
1727 di<<"vcircle error: Same points."<<"\n";return 1;
1730 if (myCartPointA->X()==myCartPointC->X() && myCartPointA->Y()==myCartPointC->Y() && myCartPointA->Z()==myCartPointC->Z() ) {
1731 di<<"vcircle error: Same points."<<"\n";return 1;
1734 if (myCartPointB->X()==myCartPointC->X() && myCartPointB->Y()==myCartPointC->Y() && myCartPointB->Z()==myCartPointC->Z() ) {
1735 di<<"vcircle error: Same points."<<"\n";return 1;
1737 // Construction du cercle
1738 GC_MakeCircle Cir=GC_MakeCircle (myCartPointA->Pnt(),myCartPointB->Pnt(),myCartPointC->Pnt() );
1739 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1740 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1741 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1742 TheAISContext()->Display(theAISCircle );
1746 // Arguments: ASI_Plane AIS_Point Real
1747 // ===================================
1748 else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
1749 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) {
1750 di<<"vcircle error: 2de element is a unexpected to be a point."<<"\n";return 1;
1752 // On verifie que le rayon est bien >=0
1753 if (atof(argv[4])<=0 ) {di<<"vcircle error: the radius must be >=0."<<"\n";return 1; }
1755 // On recupere la normale au Plane.
1756 Handle(AIS_Plane) theAISPlane= *(Handle(AIS_Plane)*)& theShapeA;
1757 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1760 // Handle(Geom_Plane ) myGeomPlane= *(Handle(Geom_Plane)*)& (theAISPlane->Component() );
1761 Handle(Geom_Plane ) myGeomPlane= theAISPlane->Component();
1762 Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
1763 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
1765 gp_Pln mygpPlane = myGeomPlane->Pln();
1766 gp_Ax1 thegpAxe = mygpPlane.Axis();
1767 gp_Dir theDir = thegpAxe.Direction();
1768 gp_Pnt theCenter=myCartPointB->Pnt();
1769 Standard_Real TheR = atof(argv[4]);
1770 GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,TheR);
1771 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1772 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1773 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1774 TheAISContext()->Display(theAISCircle );
1780 di<<"vcircle error: !st argument is a unexpected type."<<"\n";return 1;
1784 // Pas d'arguments: selection dans le viewer
1785 // =========================================
1788 TheAISContext()->OpenLocalContext();
1789 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1791 // Active le mode Vertex et face.
1792 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1793 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1794 di<<" Select a vertex or a face."<<"\n";
1796 // Boucle d'attente waitpick.
1797 Standard_Integer argcc = 5;
1798 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1799 const char **argvv = (const char **) buff;
1800 while (ViewerMainLoop( argcc, argvv) ) { }
1803 TopoDS_Shape ShapeA;
1804 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1805 ShapeA = TheAISContext()->SelectedShape();
1808 // ShapeA est un Vertex
1809 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1810 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1811 di<<" Select a different vertex."<<"\n";
1813 TopoDS_Shape ShapeB;
1816 // Boucle d'attente waitpick.
1817 Standard_Integer argccc = 5;
1818 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1819 const char **argvvv = (const char **) bufff;
1820 while (ViewerMainLoop( argccc, argvvv) ) { }
1823 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1824 ShapeB = TheAISContext()->SelectedShape();
1828 } while(ShapeB.IsSame(ShapeA) );
1830 // Selection de ShapeC
1831 di<<" Select the last vertex."<<"\n";
1832 TopoDS_Shape ShapeC;
1835 // Boucle d'attente waitpick.
1836 Standard_Integer argcccc = 5;
1837 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1838 const char **argvvvv = (const char **) buffff;
1839 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1842 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1843 ShapeC = TheAISContext()->SelectedShape();
1847 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
1849 // Fermeture du context local
1850 TheAISContext()->CloseLocalContext(myCurrentIndex);
1852 // Construction du cercle
1853 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1854 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1855 gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC) );
1857 GC_MakeCircle Cir=GC_MakeCircle (A,B,C );
1858 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1859 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1860 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1861 TheAISContext()->Display(theAISCircle );
1864 // ShapeA est une face.
1866 di<<" Select a vertex (in your face)."<<"\n";
1867 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1869 TopoDS_Shape ShapeB;
1870 // Boucle d'attente waitpick.
1871 Standard_Integer argccc = 5;
1872 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1873 const char **argvvv = (const char **) bufff;
1874 while (ViewerMainLoop( argccc, argvvv) ) { }
1877 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1878 ShapeB = TheAISContext()->SelectedShape();
1881 // Recuperation du rayon.
1882 Standard_Integer theRad;
1884 di<<" Enter the value of the radius:"<<"\n";
1886 } while (theRad<=0);
1888 // Fermeture du context local
1889 TheAISContext()->CloseLocalContext(myCurrentIndex);
1890 // Construction du cercle.
1892 // On recupere la normale au Plane. tag
1893 TopoDS_Face myFace=TopoDS::Face(ShapeA);
1894 BRepAdaptor_Surface mySurface (myFace, Standard_False );
1895 gp_Pln myPlane=mySurface.Plane();
1896 Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
1897 gp_Pln mygpPlane = theGeomPlane->Pln();
1898 gp_Ax1 thegpAxe = mygpPlane.Axis();
1899 gp_Dir theDir = thegpAxe.Direction();
1901 // On recupere le centre.
1902 gp_Pnt theCenter=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1904 // On construit l'AIS_Circle
1905 GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,theRad );
1906 Handle (Geom_Circle) theGeomCircle=Cir.Value();
1907 Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle );
1908 GetMapOfAIS().Bind(theAISCircle,argv[1] );
1909 TheAISContext()->Display(theAISCircle );
1920 //===============================================================================================
1921 //function : VDrawText
1923 //purpose : Create a text.
1924 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
1925 //===============================================================================================
1926 #include <Graphic3d_Group.hxx>
1927 #include <Graphic3d_Structure.hxx>
1928 #include <Graphic3d_NameOfFont.hxx>
1929 #include <Graphic3d_AspectText3d.hxx>
1930 #include <Graphic2d_GraphicObject.hxx>
1931 #include <Graphic3d_Array1OfVertex.hxx>
1932 #include <Graphic3d_AspectFillArea3d.hxx>
1933 #include <Graphic3d_StructureManager.hxx>
1934 #include <Graphic3d_VerticalTextAlignment.hxx>
1935 #include <Graphic3d_HorizontalTextAlignment.hxx>
1937 #include <Visual3d_ViewManager.hxx>
1938 #include <ViewerTest_Tool.ixx>
1940 #include <Standard_DefineHandle.hxx>
1942 #include <AIS_Drawer.hxx>
1944 #include <Prs3d_Root.hxx>
1945 #include <Prs3d_Text.hxx>
1946 #include <Prs3d_TextAspect.hxx>
1947 #include <Prs3d_Presentation.hxx>
1948 #include <Prs3d_ShadingAspect.hxx>
1949 #include <PrsMgr_PresentationManager3d.hxx>
1951 #include <TCollection_ExtendedString.hxx>
1952 #include <TCollection_AsciiString.hxx>
1954 #include <gp_Pnt.hxx>
1955 #include <Quantity_NameOfColor.hxx>
1956 #include <Quantity_Color.hxx>
1959 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
1961 class MyTextClass:public AIS_InteractiveObject
1965 DEFINE_STANDARD_RTTI(MyTextClass );
1971 const TCollection_ExtendedString& , const gp_Pnt& ,
1972 Quantity_Color color,
1973 Standard_Integer aHJust,
1974 Standard_Integer aVJust ,
1975 Standard_Real Angle ,
1976 Standard_Boolean Zoom ,
1977 Standard_Real Height,
1978 OSD_FontAspect FontAspect,
1979 Standard_CString Font
1984 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
1985 const Handle(Prs3d_Presentation)& aPresentation,
1986 const Standard_Integer aMode);
1988 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
1989 const Standard_Integer aMode){} ;
1992 TCollection_ExtendedString aText;
1995 Standard_Real Green;
1997 Standard_Real aAngle;
1998 Standard_Real aHeight;
1999 Standard_Boolean aZoomable;
2000 Quantity_Color aColor;
2001 Standard_CString aFont;
2002 OSD_FontAspect aFontAspect;
2003 Graphic3d_HorizontalTextAlignment aHJustification;
2004 Graphic3d_VerticalTextAlignment aVJustification;
2009 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2010 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2013 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2014 Quantity_Color color = Quantity_NOC_YELLOW,
2015 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2016 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2017 Standard_Real angle = 0.0 ,
2018 Standard_Boolean zoomable = Standard_True,
2019 Standard_Real height = 12.,
2020 OSD_FontAspect fontAspect = OSD_FA_Regular,
2021 Standard_CString font = "Courier")
2024 aPosition = position;
2025 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2026 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2028 aZoomable = zoomable;
2031 aFontAspect = fontAspect;
2037 //////////////////////////////////////////////////////////////////////////////
2038 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2039 const Handle(Prs3d_Presentation)& aPresentation,
2040 const Standard_Integer aMode)
2043 aPresentation->Clear();
2045 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2047 asp->SetFont(aFont);
2048 asp->SetColor(aColor);
2049 asp->SetHeight(aHeight); // I am changing the myHeight value
2051 asp->SetHorizontalJustification(aHJustification);
2052 asp->SetVerticalJustification(aVJustification);
2053 asp->Aspect()->SetTextZoomable(aZoomable);
2054 asp->Aspect()->SetTextAngle(aAngle);
2055 asp->Aspect()->SetTextFontAspect(aFontAspect);
2056 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2058 /* This comment code is worked
2059 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2060 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2061 Graphic3d_Vertex vertices_text;
2062 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2063 TheGroup->SetPrimitivesAspect(aspect);
2064 TheGroup->BeginPrimitives();
2065 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2066 TheGroup->EndPrimitives();
2070 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2075 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2076 di<<"Usage: type help "<<argv[0]<<"\n";
2077 return 1; //TCL_ERROR
2080 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2082 // Create 3D view if it doesn't exist
2083 if ( aContext.IsNull() )
2085 ViewerTest::ViewerInit();
2086 aContext = ViewerTest::GetAISContext();
2087 if( aContext.IsNull() )
2089 di << "Error: Cannot create a 3D view\n";
2090 return 1; //TCL_ERROR
2095 const Standard_Real X = atof(argv[2]);
2096 const Standard_Real Y = atof(argv[3]);
2097 const Standard_Real Z = atof(argv[4]);
2098 const gp_Pnt pnt(X,Y,Z);
2101 const Quantity_Parameter R = atof(argv[5])/255.;
2102 const Quantity_Parameter G = atof(argv[6])/255.;
2103 const Quantity_Parameter B = atof(argv[7])/255.;
2104 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2107 const int hor_align = atoi(argv[8]);
2108 const int ver_align = atoi(argv[9]);
2111 const Standard_Real angle = atof(argv[10]);
2114 const Standard_Boolean zoom = atoi(argv[11]);
2117 const Standard_Real height = atof(argv[12]);
2120 const OSD_FontAspect aspect = OSD_FontAspect(atoi(argv[13]));
2123 TCollection_AsciiString font;
2125 font.AssignCat("Courier");
2127 font.AssignCat(argv[14]);
2129 // Text is multibyte
2130 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (atoi(argv[15]) != 0);
2133 TCollection_ExtendedString name;
2136 const char *str = argv[1];
2139 unsigned short c1 = *str++;
2140 unsigned short c2 = *str++;
2141 if (!c1 || !c2) break;
2142 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2152 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2153 aContext->Display(myT,Standard_True);
2160 #include <gp_Pnt.hxx>
2161 #include <Graphic3d_ArrayOfPoints.hxx>
2162 #include <Graphic3d_ArrayOfPrimitives.hxx>
2163 #include <Graphic3d_Array1OfVertex.hxx>
2164 #include <Graphic3d_ArrayOfTriangles.hxx>
2165 #include <Poly_Array1OfTriangle.hxx>
2166 #include <Poly_Triangle.hxx>
2167 #include <Poly_Triangulation.hxx>
2168 #include <TColgp_Array1OfPnt.hxx>
2169 #include <TShort_Array1OfShortReal.hxx>
2170 #include <TShort_HArray1OfShortReal.hxx>
2172 #include <AIS_Triangulation.hxx>
2173 #include <Aspect_GraphicDevice.hxx>
2174 #include <StdPrs_ToolShadedShape.hxx>
2175 #include <Poly_Connect.hxx>
2176 #include <TColgp_Array1OfDir.hxx>
2177 #include <Graphic3d_GraphicDriver.hxx>
2179 #include <AIS_Drawer.hxx>
2180 #include <TColStd_Array1OfInteger.hxx>
2181 #include <TColStd_HArray1OfInteger.hxx>
2182 #include <Prs3d_ShadingAspect.hxx>
2183 #include <Graphic3d_MaterialAspect.hxx>
2184 #include <Graphic3d_AspectFillArea3d.hxx>
2186 #include <BRepPrimAPI_MakeCylinder.hxx>
2187 #include <TopoDS_Shape.hxx>
2188 #include <TopExp_Explorer.hxx>
2189 #include <TopAbs.hxx>
2190 #include <StdSelect_ShapeTypeFilter.hxx>
2193 //===============================================================================================
2194 //function : CalculationOfSphere
2196 //purpose : Create a Sphere
2197 //===============================================================================================
2199 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2202 double mRadius = Radius;
2203 double mCenter[3] = {X,Y,Z};
2204 int mThetaResolution;
2206 double mStartTheta = 0;//StartTheta;
2207 double mEndTheta = 360;//EndTheta;
2208 double mStartPhi = 0;//StartPhi;
2209 double mEndPhi = 180;//EndPhi;
2210 res = res < 4 ? 4 : res;
2212 mThetaResolution = res;
2213 mPhiResolution = res;
2216 int jStart, jEnd, numOffset;
2217 int numPts, numPolys;
2218 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2219 double startTheta, endTheta, startPhi, endPhi;
2220 int base, numPoles=0, thetaResolution, phiResolution;
2225 if ( numPieces > mThetaResolution ) {
2226 numPieces = mThetaResolution;
2229 int localThetaResolution = mThetaResolution;
2230 double localStartTheta = mStartTheta;
2231 double localEndTheta = mEndTheta;
2233 while ( localEndTheta < localStartTheta ) {
2234 localEndTheta += 360.0;
2237 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2239 // Change the ivars based on pieces.
2241 start = piece * localThetaResolution / numPieces;
2242 end = (piece+1) * localThetaResolution / numPieces;
2243 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2244 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2245 localThetaResolution = end - start;
2247 numPts = mPhiResolution * localThetaResolution + 2;
2248 numPolys = mPhiResolution * 2 * localThetaResolution;
2250 // Create north pole if needed
2251 int number_point = 0;
2252 int number_pointArray = 0;
2254 if ( mStartPhi <= 0.0 ) {
2255 number_pointArray++;
2258 if ( mEndPhi >= 180.0 ) {
2259 number_pointArray++;
2263 // Check data, determine increments, and convert to radians
2264 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2265 startTheta *= Standard_PI / 180.0;
2266 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2267 endTheta *= Standard_PI / 180.0;
2270 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2271 startPhi *= Standard_PI / 180.0;
2272 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2273 endPhi *= Standard_PI / 180.0;
2275 phiResolution = mPhiResolution - numPoles;
2276 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2277 thetaResolution = localThetaResolution;
2278 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2279 ++localThetaResolution;
2281 deltaTheta = (endTheta - startTheta) / thetaResolution;
2283 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2284 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2286 // Create intermediate points
2287 for ( i = 0; i < localThetaResolution; i++ ) {
2288 for ( j = jStart; j < jEnd; j++ ) {
2289 number_pointArray++;
2293 //Generate mesh connectivity
2294 base = phiResolution * localThetaResolution;
2296 int number_triangle = 0 ;
2297 if ( mStartPhi <= 0.0 ) { // around north pole
2298 number_triangle += localThetaResolution;
2301 if ( mEndPhi >= 180.0 ) { // around south pole
2302 number_triangle += localThetaResolution;
2305 // bands in-between poles
2306 for ( i=0; i < localThetaResolution; i++){
2307 for ( j=0; j < (phiResolution-1); j++){
2308 number_triangle +=2;
2312 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2313 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2314 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2316 if ( mStartPhi <= 0.0 ){
2319 x[2] = mCenter[2] + mRadius;
2320 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2323 // Create south pole if needed
2324 if ( mEndPhi >= 180.0 ){
2327 x[2] = mCenter[2] - mRadius;
2328 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2332 for ( i=0; i < localThetaResolution; i++){
2333 theta = localStartTheta * Standard_PI / 180.0 + i*deltaTheta;
2334 for ( j = jStart; j < jEnd; j++){
2335 phi = startPhi + j*deltaPhi;
2336 radius = mRadius * sin((double)phi);
2337 n[0] = radius * cos((double)theta);
2338 n[1] = radius * sin((double)theta);
2339 n[2] = mRadius * cos((double)phi);
2340 x[0] = n[0] + mCenter[0];
2341 x[1] = n[1] + mCenter[1];
2342 x[2] = n[2] + mCenter[2];
2343 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2349 number_triangle = 1;
2350 if ( mStartPhi <= 0.0 ){// around north pole
2351 for (i=0; i < localThetaResolution; i++){
2352 pts[0] = phiResolution*i + numPoles;
2353 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2355 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2360 if ( mEndPhi >= 180.0 ){ // around south pole
2361 numOffset = phiResolution - 1 + numPoles;
2362 for (i=0; i < localThetaResolution; i++){
2363 pts[0] = phiResolution*i + numOffset;
2364 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2365 pts[1] = numPoles - 1;
2366 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2371 // bands in-between poles
2373 for (i=0; i < localThetaResolution; i++){
2374 for (j=0; j < (phiResolution-1); j++){
2375 pts[0] = phiResolution*i + j + numPoles;
2376 pts[1] = pts[0] + 1;
2377 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2378 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2381 pts[2] = pts[1] - 1;
2382 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2387 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2389 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2391 Standard_Integer index[3];
2392 Standard_Real Tol = Precision::Confusion();
2395 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2396 gp_XYZ eqPlan(0, 0, 0);
2397 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2398 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2399 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2400 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2402 Standard_Real mod = vv.Modulus();
2403 if(mod < Tol) continue;
2407 Standard_Real modmax = eqPlan.Modulus();
2410 Nor = gp_Dir(eqPlan);
2412 Nor = gp_Dir(0., 0., 1.);
2414 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2415 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2416 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2417 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2421 polyTriangulation->SetNormals(Normals);
2423 return polyTriangulation;
2426 //===============================================================================================
2427 //function : VDrawSphere
2429 //purpose : Create an AIS shape.
2430 //===============================================================================================
2431 static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2434 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2435 if (aContextAIS.IsNull())
2437 std::cout << "Call vinit before!\n";
2442 std::cout << "Use: " << argv[0]
2443 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
2447 // read the arguments
2448 TCollection_AsciiString aShapeName (argv[1]);
2449 Standard_Integer aResolution = atoi (argv[2]);
2450 Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0;
2451 Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
2452 Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
2453 Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
2454 Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True;
2455 Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1;
2456 Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False;
2458 if (aRedrawsNb <= 0)
2463 // remove AIS object with given name from map
2464 if (GetMapOfAIS().IsBound2 (aShapeName))
2466 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aShapeName);
2467 Handle(AIS_InteractiveObject) anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
2468 if (anInterObj.IsNull())
2470 std::cout << "Shape name was used for non AIS viewer\n!";
2473 aContextAIS->Remove (anInterObj, Standard_False);
2474 GetMapOfAIS().UnBind2 (aShapeName);
2477 // enable/disable VBO
2478 Handle(Graphic3d_GraphicDriver) aDriver =
2479 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2480 if (!aDriver.IsNull())
2482 aDriver->EnableVBO (isVBOEnabled);
2485 std::cout << "Compute Triangulation...\n";
2486 Handle(AIS_Triangulation) aShape
2487 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2490 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2491 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2493 // register the object in map
2494 GetMapOfAIS().Bind (aShape, aShapeName);
2496 // stupid initialization of Green color in RGBA space as integer
2497 // probably wrong for big-endian CPUs
2498 Standard_Integer aRed = 0;
2499 Standard_Integer aGreen = 255;
2500 Standard_Integer aBlue = 0;
2501 Standard_Integer anAlpha = 0; // not used
2502 Standard_Integer aColorInt = aRed;
2503 aColorInt += aGreen << 8;
2504 aColorInt += aBlue << 16;
2505 aColorInt += anAlpha << 24;
2507 // setup colors array per vertex
2508 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2509 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2511 aColorArray->SetValue (aNodeId, aColorInt);
2513 aShape->SetColors (aColorArray);
2516 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2517 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2518 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2519 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2520 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2521 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2522 aTotalSize >>= 20; //MB
2523 aNormalsSize >>= 20;
2525 aTrianglesSize >>= 20;
2526 aPolyConnectSize >>= 20;
2527 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2528 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2529 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2530 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2531 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2532 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2534 // Setting material properties, very important for desirable visual result!
2535 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2536 aMat.SetAmbient (0.2);
2537 aMat.SetSpecular (0.5);
2538 Handle(Graphic3d_AspectFillArea3d) anAspect
2539 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2541 Quantity_NOC_YELLOW,
2546 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2549 anAspect->SetEdgeOn();
2553 anAspect->SetEdgeOff();
2555 aShAsp->SetAspect (anAspect);
2556 aShape->Attributes()->SetShadingAspect (aShAsp);
2558 aContextAIS->Display (aShape, Standard_False);
2560 // Two viewer updates are needed in order to measure time spent on
2561 // loading triangulation to graphic card memory + redrawing (1st update) and
2562 // time spent on redrawing itself (2nd and all further updates)
2563 OSD_Chronometer aTimer;
2564 Standard_Real aUserSeconds, aSystemSeconds;
2566 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2567 for (Standard_Integer anInteration = 0; anInteration < aRedrawsNb; ++anInteration)
2569 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
2571 if (anInteration == 0)
2573 aViewer->ActiveView()->Update();
2577 aViewer->ActiveView()->Redraw();
2581 aTimer.Show (aUserSeconds, aSystemSeconds);
2583 std::cout << "Number of scene redrawings: " << aRedrawsNb << "\n"
2584 << "CPU user time: "
2585 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aUserSeconds
2587 << "CPU system time: "
2588 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aSystemSeconds
2590 << "CPU average time of scene redrawing: "
2591 << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * (aUserSeconds / (Standard_Real )aRedrawsNb)
2596 //===============================================================================================
2597 //function : VClipPlane
2599 //===============================================================================================
2600 static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2602 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2603 Handle(V3d_View) aView = ViewerTest::CurrentView();
2604 Standard_Real coeffA, coeffB, coeffC, coeffD;
2605 if (aViewer.IsNull() || aView.IsNull())
2607 std::cout << "Viewer not initialized!\n";
2611 // count an active planes count
2612 Standard_Integer aNewPlaneId = 1;
2613 Standard_Integer anActivePlanes = 0;
2614 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
2616 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2617 if (aView->IsActivePlane (aPlaneV3d))
2625 // just show info about existing planes
2626 Standard_Integer aPlaneId = 1;
2627 std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
2628 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2630 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2631 aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
2632 gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
2633 const gp_Pnt& aLoc = aPlane.Location();
2634 const gp_Dir& aNor = aPlane.Axis().Direction();
2635 Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
2636 std::cout << "Plane #" << aPlaneId
2637 << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
2638 << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
2639 << (isActive ? " on" : " off")
2640 << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
2645 std::cout << "No defined clipping planes\n";
2649 else if (argc == 2 || argc == 3)
2651 Standard_Integer aPlaneIdToOff = (argc == 3) ? atoi (argv[1]) : 1;
2652 Standard_Boolean toIterateAll = (argc == 2);
2653 TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
2654 isOnOffStr.LowerCase();
2655 Standard_Integer aPlaneId = 1;
2656 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2658 if (aPlaneIdToOff == aPlaneId || toIterateAll)
2660 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2661 if (isOnOffStr.Search ("off") >= 0)
2663 aView->SetPlaneOff (aPlaneV3d);
2664 std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
2666 else if (isOnOffStr.Search ("on") >= 0)
2668 // avoid z-fighting glitches
2670 if (!aView->IsActivePlane (aPlaneV3d))
2672 if (anActivePlanes < aView->View()->PlaneLimit())
2674 aView->SetPlaneOn (aPlaneV3d);
2675 std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
2679 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2680 << "You should disable or remove some existing plane to activate this one\n";
2685 std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
2688 else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
2690 aPlaneV3d->Erase(); // not performed on destructor!!!
2691 aView->SetPlaneOff (aPlaneV3d);
2692 aViewer->DelPlane (aPlaneV3d);
2693 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2696 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
2698 aPlaneV3d = aViewer->DefinedPlane();
2699 aPlaneV3d->Erase(); // not performed on destructor!!!
2700 aView->SetPlaneOff (aPlaneV3d);
2701 aViewer->DelPlane (aPlaneV3d);
2702 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2711 else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
2713 // avoid z-fighting glitches
2714 aView->SetPlaneOff (aPlaneV3d);
2715 aPlaneV3d->Display (aView);
2716 std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
2718 else if (isOnOffStr.Search ("hide") >= 0)
2721 std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
2725 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2730 if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
2732 std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
2740 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2744 Standard_Real aLocX = atof (argv[1]);
2745 Standard_Real aLocY = atof (argv[2]);
2746 Standard_Real aLocZ = atof (argv[3]);
2747 Standard_Real aNormDX = atof (argv[4]);
2748 Standard_Real aNormDY = atof (argv[5]);
2749 Standard_Real aNormDZ = atof (argv[6]);
2751 Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
2752 gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
2753 aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
2754 aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
2756 aViewer->AddPlane (aPlaneV3d); // add to defined planes list
2757 std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
2758 if (anActivePlanes < aView->View()->PlaneLimit())
2760 aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
2765 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2766 << "You should disable or remove some existing plane to activate the new one\n";
2771 //=============================================================================
2772 //function : VComputeHLR
2774 //=============================================================================
2776 static int VComputeHLR (Draw_Interpretor& di,
2777 Standard_Integer argc,
2780 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2782 if (aContextAIS.IsNull ())
2784 di << "Please call vinit before\n";
2788 if ( argc != 3 && argc != 12 )
2790 di << "Usage: " << argv[0] << " ShapeName HlrName "
2791 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
2792 << " ShapeName - name of the initial shape\n"
2793 << " HlrName - result hlr object from initial shape\n"
2794 << " eye, dir are eye position and look direction\n"
2795 << " up is the look up direction vector\n"
2796 << " Use vtop to see projected hlr shape\n";
2800 // shape and new object name
2801 TCollection_AsciiString aShapeName (argv[1]);
2802 TCollection_AsciiString aHlrName (argv[2]);
2804 TopoDS_Shape aSh = DBRep::Get (argv[1]);
2807 BRep_Builder aBrepBuilder;
2808 BRepTools::Read (aSh, argv[1], aBrepBuilder);
2811 di << "No shape with name " << argv[1] << " found\n";
2816 if (GetMapOfAIS ().IsBound2 (aHlrName))
2818 di << "Presentable object with name " << argv[2] << " already exists\n";
2822 // close local context
2823 if (aContextAIS->HasOpenedContext ())
2824 aContextAIS->CloseLocalContext ();
2826 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
2827 HLRBRep_PolyHLRToShape aHLRToShape;
2836 anEye.SetCoord (atof (argv[3]), atof (argv[4]), atof (argv[5]));
2837 aDir.SetCoord (atof (argv[6]), atof (argv[7]), atof (argv[8]));
2838 anUp.SetCoord (atof (argv[9]), atof (argv[10]), atof (argv[11]));
2839 aProjAx.SetLocation (anEye);
2840 aProjAx.SetDirection (aDir);
2841 aProjAx.SetYDirection (anUp);
2847 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2848 Handle(V3d_View) aView = ViewerTest::CurrentView();
2849 Standard_Integer aWidth, aHeight;
2850 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
2851 Standard_Real aRightX, aRightY, aRightZ;
2852 aView->Window()->Size (aWidth, aHeight);
2854 aView->ConvertWithProj (aWidth, aHeight/2,
2855 aRightX, aRightY, aRightZ,
2856 aDirX, aDirY, aDirZ);
2858 aView->ConvertWithProj (aWidth/2, aHeight/2,
2859 aCentX, aCentY, aCentZ,
2860 aDirX, aDirY, aDirZ);
2862 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
2863 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
2864 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
2865 aProjAx.SetLocation (anEye);
2866 aProjAx.SetDirection (aDir);
2867 aProjAx.SetXDirection (aRight);
2870 HLRAlgo_Projector aProjector (aProjAx);
2871 aPolyAlgo->Projector (aProjector);
2872 aPolyAlgo->Load (aSh);
2873 aPolyAlgo->Update ();
2875 aHLRToShape.Update (aPolyAlgo);
2877 // make hlr shape from input shape
2878 TopoDS_Compound aHlrShape;
2879 BRep_Builder aBuilder;
2880 aBuilder.MakeCompound (aHlrShape);
2882 TopoDS_Shape aCompound = aHLRToShape.VCompound();
2883 if (!aCompound.IsNull ())
2885 aBuilder.Add (aHlrShape, aCompound);
2888 // extract visible outlines
2889 aCompound = aHLRToShape.OutLineVCompound();
2890 if (!aCompound.IsNull ())
2892 aBuilder.Add (aHlrShape, aCompound);
2895 // create an AIS shape and display it
2896 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
2897 GetMapOfAIS().Bind (anObject, aHlrName);
2898 aContextAIS->Display (anObject);
2900 aContextAIS->UpdateCurrentViewer ();
2905 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
2906 // manipulating and displaying such an array with AIS context
2907 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
2908 class MyPArrayObject : public AIS_InteractiveObject
2913 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray)
2918 DEFINE_STANDARD_RTTI(MyPArrayObject);
2922 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2923 const Handle(Prs3d_Presentation)& aPresentation,
2924 const Standard_Integer aMode);
2926 void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
2927 const Standard_Integer aMode) {};
2931 Handle(Graphic3d_ArrayOfPrimitives) myArray;
2935 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
2936 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
2938 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2939 const Handle(Prs3d_Presentation)& aPresentation,
2940 const Standard_Integer aMode)
2942 aPresentation->Clear();
2944 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
2945 aGroup->BeginPrimitives ();
2946 aGroup->AddPrimitiveArray (myArray);
2947 aGroup->EndPrimitives ();
2950 static bool CheckInputCommand (const TCollection_AsciiString theCommand,
2951 const char **theArgStr, int &theArgIndex,
2952 int theArgCount, int theMaxArgs)
2954 // check if there is more elements than expected
2955 if (theArgIndex >= theMaxArgs)
2958 TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
2959 aStrCommand.LowerCase();
2960 if (aStrCommand.Search(theCommand) != 1 ||
2961 theArgIndex + (theArgCount - 1) >= theMaxArgs)
2964 // go to the first data element
2967 // check data if it can be converted to numeric
2968 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
2970 aStrCommand = theArgStr[theArgIndex];
2971 if (!aStrCommand.IsRealValue())
2978 //=============================================================================
2979 //function : VDrawPArray
2980 //purpose : Draws primitives array from list of vertexes, bounds, edges
2981 //=============================================================================
2983 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2985 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2986 if (aContextAIS.IsNull())
2988 di << "Call vinit before!\n";
2993 di << "Use: " << argv[0] << " Name TypeOfArray [EnableVBO={0 | 1}]"
2994 << " [vertex] ... [bounds] ... [edges]\n"
2995 << " TypeOfArray={ points | segments | polylines | triangles |\n"
2996 << " trianglefan | trianglestrips | quads |\n"
2997 << " quadstrips | polygons }\n"
2998 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
2999 << " [texel={ 't' tx ty }] } \n"
3000 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3001 << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
3005 // read the arguments
3006 TCollection_AsciiString aName (argv[1]);
3007 TCollection_AsciiString anArrayType (argv[2]);
3009 // is argument list has an vbo flag
3010 Standard_Boolean hasFlagVbo = Standard_False;
3011 if (isdigit (argv[3][0]) && atoi (argv[3]) >= 0 && atoi (argv[3]) <= 1)
3012 hasFlagVbo = Standard_True;
3014 // parse number of verticies, bounds, edges
3015 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3016 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3017 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3019 Standard_Integer aArgIndex = (hasFlagVbo) ? 4 : 3;
3020 TCollection_AsciiString aCommand;
3021 while (aArgIndex < argc)
3023 aCommand = argv[aArgIndex];
3024 aCommand.LowerCase();
3025 if (!aCommand.IsAscii())
3027 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3028 << "should be an array element: 'v', 'b', 'e' \n";
3033 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3035 // vertex has a normal or normal with color or texel
3036 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3037 hasNormals = Standard_True;
3039 // vertex has a color
3040 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3041 hasVColors = Standard_True;
3043 // vertex has a texel
3044 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3045 hasTexels = Standard_True;
3050 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3053 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3054 hasBColors = Standard_True;
3059 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3061 // edge has a hide flag
3062 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3063 hasInfos = Standard_True;
3072 if (aVertexNum == 0)
3074 di << "You should pass any verticies in the list of array elements\n";
3078 // create an array of primitives by types
3079 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3080 if (anArrayType == "points")
3081 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3082 else if (anArrayType == "segments")
3083 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3084 else if (anArrayType == "polylines")
3085 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3086 hasVColors, hasBColors, hasInfos);
3087 else if (anArrayType == "triangles")
3088 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3089 hasVColors, hasTexels, hasInfos);
3090 else if (anArrayType == "trianglefans")
3091 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3092 hasNormals, hasVColors,
3093 hasBColors, hasTexels);
3094 else if (anArrayType == "trianglestrips")
3095 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3096 hasNormals, hasVColors,
3097 hasBColors, hasTexels);
3098 else if (anArrayType == "quads")
3099 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3100 hasNormals, hasVColors,
3101 hasTexels, hasInfos);
3102 else if (anArrayType == "quadstrips")
3103 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3104 hasNormals, hasVColors,
3105 hasBColors, hasTexels);
3106 else if (anArrayType == "polygons")
3107 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3108 hasNormals, hasVColors, hasBColors,
3109 hasTexels, hasInfos);
3112 di << "Unexpected type of primitiives array\n";
3116 // parse an array of primitives
3117 aArgIndex = (hasFlagVbo) ? 4 : 3;
3118 while (aArgIndex < argc)
3120 aCommand = argv[aArgIndex];
3121 aCommand.LowerCase();
3122 if (!aCommand.IsAscii())
3126 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3128 anArray->AddVertex (atof (argv[aArgIndex - 3]),
3129 atof (argv[aArgIndex - 2]),
3130 atof (argv[aArgIndex - 1]));
3132 // vertex has a normal or normal with color or texel
3133 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3134 anArray->SetVertexNormal (anArray->VertexNumber (),
3135 atof (argv[aArgIndex - 3]),
3136 atof (argv[aArgIndex - 2]),
3137 atof (argv[aArgIndex - 1]));
3139 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3140 anArray->SetVertexColor (anArray->VertexNumber (),
3141 atof (argv[aArgIndex - 3]),
3142 atof (argv[aArgIndex - 2]),
3143 atof (argv[aArgIndex - 1]));
3145 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3146 anArray->SetVertexTexel (anArray->VertexNumber (),
3147 atof (argv[aArgIndex - 2]),
3148 atof (argv[aArgIndex - 1]));
3151 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3153 Standard_Integer aVertCount = atoi (argv[aArgIndex - 1]);
3155 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3156 anArray->AddBound (aVertCount,
3157 atof (argv[aArgIndex - 3]),
3158 atof (argv[aArgIndex - 2]),
3159 atof (argv[aArgIndex - 1]));
3162 anArray->AddBound (aVertCount);
3165 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3167 Standard_Integer aVertIndex = atoi (argv[aArgIndex - 1]);
3169 // edge has/hasn't hide flag
3170 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3171 anArray->AddEdge (aVertIndex, Standard_False);
3173 anArray->AddEdge (aVertIndex, Standard_True);
3182 // enable / disable vbo
3183 Handle(Graphic3d_GraphicDriver) aDriver =
3184 Handle(Graphic3d_GraphicDriver)::DownCast (
3185 aContextAIS->CurrentViewer()->Device()->GraphicDriver());
3187 if (!aDriver.IsNull())
3188 aDriver->EnableVBO ((Standard_Boolean) atoi (argv[3]));
3191 // create primitives array object
3192 Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
3194 // register the object in map
3195 VDisplayAISObject (aName, aPObject);
3200 //=======================================================================
3201 //function : ObjectsCommands
3203 //=======================================================================
3205 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
3207 const char *group ="AISObjects";
3208 theCommands.Add("vtrihedron",
3209 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
3210 __FILE__,VTrihedron,group);
3212 theCommands.Add("vtri2d",
3213 "vtri2d Name Selection in the viewer only ",
3214 __FILE__,VTrihedron2D ,group);
3216 theCommands.Add("vplanetri",
3217 "vplanetri Name Selection in the viewer only ",
3218 __FILE__,VPlaneTrihedron ,group);
3220 theCommands.Add("vsize",
3221 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
3222 __FILE__,VSize,group);
3224 theCommands.Add("vaxis",
3225 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
3226 __FILE__,VAxisBuilder,group);
3228 theCommands.Add("vaxispara",
3230 __FILE__,VAxisBuilder,group);
3232 theCommands.Add("vaxisortho",
3234 __FILE__,VAxisBuilder,group);
3236 theCommands.Add("vpoint",
3237 "vpoint PointName [Xa] [Ya] [Za] ",
3238 __FILE__,VPointBuilder,group);
3240 theCommands.Add("vplane",
3241 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
3242 __FILE__,VPlaneBuilder,group);
3244 theCommands.Add("vplanepara",
3245 "vplanepara PlaneName ",
3246 __FILE__,VPlaneBuilder,group);
3248 theCommands.Add("vplaneortho",
3249 "vplaneortho PlaneName ",
3250 __FILE__,VPlaneBuilder,group);
3252 theCommands.Add("vline",
3253 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
3254 __FILE__,VLineBuilder,group);
3256 theCommands.Add("vcircle",
3257 "vcircle CircleName [PointName/PlaneName] [PointName] [Radius] ",
3258 __FILE__,VCircleBuilder,group);
3260 theCommands.Add("vdrawtext",
3261 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
3262 __FILE__,VDrawText,group);
3264 theCommands.Add("vdrawsphere",
3265 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n",
3266 __FILE__,VDrawSphere,group);
3268 theCommands.Add("vclipplane",
3269 "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
3270 __FILE__,VClipPlane,group);
3274 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
3275 __FILE__, VComputeHLR, group);
3277 theCommands.Add("vdrawparray",
3278 "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' }] ]",
3279 __FILE__,VDrawPArray,group);