1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 //===============================================
24 // AIS Objects Creation : Datums (axis,trihedrons,lines,planes)
25 //===============================================
31 #include <ViewerTest.hxx>
35 #include <Quantity_NameOfColor.hxx>
36 #include <Draw_Interpretor.hxx>
38 #include <Draw_Appli.hxx>
41 #include <OSD_Chronometer.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <Visual3d_View.hxx>
44 #include <V3d_Viewer.hxx>
45 #include <V3d_View.hxx>
46 #include <V3d_Plane.hxx>
49 #include <AIS_Shape.hxx>
50 #include <AIS_DisplayMode.hxx>
51 #include <TColStd_MapOfInteger.hxx>
52 #include <AIS_MapOfInteractive.hxx>
53 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
54 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
55 #include <ViewerTest_EventManager.hxx>
57 #include <TopoDS_Solid.hxx>
58 #include <BRepTools.hxx>
59 #include <BRep_Builder.hxx>
60 #include <TopAbs_ShapeEnum.hxx>
63 #include <BRep_Tool.hxx>
64 #include <TopExp_Explorer.hxx>
66 #include <BRepAdaptor_Curve.hxx>
67 #include <BRepAdaptor_Surface.hxx>
71 #include <TopoDS_Vertex.hxx>
72 #include <TopoDS_Shape.hxx>
73 #include <TopoDS_Face.hxx>
75 #include <Draw_Window.hxx>
76 #include <AIS_ListIteratorOfListOfInteractive.hxx>
77 #include <AIS_ListOfInteractive.hxx>
78 #include <AIS_DisplayMode.hxx>
79 #include <AIS_Shape.hxx>
81 #include <AIS_InteractiveContext.hxx>
82 #include <Geom_Plane.hxx>
84 #include <AIS_AngleDimension.hxx>
85 #include <TCollection_ExtendedString.hxx>
86 #include <GC_MakePlane.hxx>
87 #include <gp_Circ.hxx>
88 #include <AIS_Axis.hxx>
89 #include <Geom_Axis2Placement.hxx>
90 #include <Geom_Axis1Placement.hxx>
91 #include <AIS_Trihedron.hxx>
92 #include <AIS_Axis.hxx>
93 #include <gp_Trsf.hxx>
94 #include <TopLoc_Location.hxx>
96 #include <HLRAlgo_Projector.hxx>
97 #include <HLRBRep_PolyAlgo.hxx>
98 #include <HLRBRep_PolyHLRToShape.hxx>
99 #include <Aspect_Window.hxx>
101 #include <Graphic3d_ArrayOfPoints.hxx>
102 #include <Graphic3d_ArrayOfSegments.hxx>
103 #include <Graphic3d_ArrayOfPolylines.hxx>
104 #include <Graphic3d_ArrayOfTriangles.hxx>
105 #include <Graphic3d_ArrayOfTriangleFans.hxx>
106 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
107 #include <Graphic3d_ArrayOfQuadrangles.hxx>
108 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
109 #include <Graphic3d_ArrayOfPolygons.hxx>
110 #include <Graphic3d_Group.hxx>
111 #include <Standard_Real.hxx>
113 #include <AIS_Circle.hxx>
114 #include <AIS_Drawer.hxx>
115 #include <BRepBuilderAPI_MakeEdge.hxx>
116 #include <BRepBuilderAPI_MakeFace.hxx>
117 #include <BRepBuilderAPI_MakeWire.hxx>
118 #include <Geom_Circle.hxx>
119 #include <GC_MakeCircle.hxx>
120 #include <Prs3d_Presentation.hxx>
121 #include <Select3D_SensitiveCircle.hxx>
122 #include <SelectMgr_EntityOwner.hxx>
123 #include <SelectMgr_Selection.hxx>
124 #include <StdFail_NotDone.hxx>
125 #include <StdPrs_ShadedShape.hxx>
126 #include <TopoDS_Wire.hxx>
128 #include <AIS_ConnectedShape.hxx>
129 #include <TopLoc_Location.hxx>
130 #include <TColStd_ListOfInteger.hxx>
131 #include <TColStd_ListIteratorOfListOfInteger.hxx>
133 #include <Select3D_SensitiveTriangle.hxx>
134 #include <Select3D_SensitiveCurve.hxx>
135 #include <BRepAdaptor_Curve.hxx>
136 #include <StdPrs_Curve.hxx>
138 #include <BRepExtrema_ExtPC.hxx>
139 #include <BRepExtrema_ExtPF.hxx>
141 #ifdef HAVE_STRINGS_H
146 #define _CRT_SECURE_NO_DEPRECATE
147 #pragma warning (disable:4996)
150 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
151 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
152 const Handle(AIS_InteractiveObject)& theAISObj,
153 Standard_Boolean theReplaceIfExists = Standard_True);
154 Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
155 extern Handle(AIS_InteractiveContext)& TheAISContext();
158 //==============================================================================
159 //function : Vtrihedron 2d
160 //purpose : Create a plane with a 2D trihedron from a faceselection
161 //Draw arg : vtri2d name
162 //==============================================================================
163 #include <AIS_PlaneTrihedron.hxx>
167 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
170 // Verification des arguments
171 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
174 Standard_Integer myCurrentIndex;
175 // Fermeture des contextes
176 TheAISContext()->CloseAllContexts();
177 // Ouverture d'un contexte local et recuperation de son index.
178 TheAISContext()->OpenLocalContext();
179 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
180 // On active les modes de selections faces.
181 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
182 di<<" Select a face ."<<"\n";
184 // Boucle d'attente waitpick.
185 Standard_Integer argccc = 5;
186 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
187 const char **argvvv = (const char **) bufff;
188 while (ViewerMainLoop( argccc, argvvv) ) { }
192 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
193 ShapeB = TheAISContext()->SelectedShape();
196 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
198 // Construction du Plane
199 // recuperation des edges des faces.
200 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
202 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
206 // si il y a plusieurs edges
207 if (FaceExpB.More() ) {
209 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
210 BRepAdaptor_Curve theCurveB(EdgeB);
211 BRepAdaptor_Curve theCurveC(EdgeC);
212 A=theCurveC.Value(0.1);
213 B=theCurveC.Value(0.9);
214 C=theCurveB.Value(0.5);
217 // FaceB a 1 unique edge courbe
218 BRepAdaptor_Curve theCurveB(EdgeB);
219 A=theCurveB.Value(0.1);
220 B=theCurveB.Value(0.9);
221 C=theCurveB.Value(0.5);
223 // Construction du Geom_Plane
224 GC_MakePlane MkPlane(A,B,C);
225 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
227 // Construction de l'AIS_PlaneTrihedron
228 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
230 // Fermeture du contexte local.
231 TheAISContext()->CloseLocalContext(myCurrentIndex);
233 // on le display & bind
234 TheAISContext()->Display(theAISPlaneTri );
235 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
242 //==============================================================================
243 //function : VTriherdron
245 //purpose : Create a trihedron. If no arguments are set, the default
246 // trihedron (Oxyz) is created.
247 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
248 //==============================================================================
250 static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
253 // Verification des arguments
254 if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
256 // Declarations et creation des objets par default
257 TCollection_AsciiString name=argv[1];
259 if(argc > 5 && argc!=11)
260 {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
262 // Cas ou il y a des arguments
263 Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.};
267 coord[i]= atof(argv[2+i]);
271 coord[3+i] = atof(argv[6+i]);
272 coord[6+i] = atof(argv[8+i]);
276 gp_Pnt ThePoint(coord[0],coord[1],coord[2]);
277 gp_Dir TheZVector(coord[3],coord[4],coord[5]);
278 gp_Dir TheXVector(coord[6],coord[7],coord[8]);
280 if ( !TheZVector.IsNormal(TheXVector,M_PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;}
282 Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector);
284 // Creation du triedre
285 Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii);
286 GetMapOfAIS().Bind(aShape,name);
287 TheAISContext()->Display(aShape);
295 //==============================================================================
298 //purpose : Change the size of a named or selected trihedron
299 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
300 // if no value, the value is set at 100 by default
301 //Draw arg : vsize [name] [size]
302 //==============================================================================
304 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
307 // Declaration de booleens
308 Standard_Boolean ThereIsName;
309 Standard_Boolean ThereIsCurrent;
311 Standard_Boolean hascol;
313 Quantity_NameOfColor col;
315 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
318 // Verification des arguments
319 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
321 // Verification du nombre d'arguments
322 if (argc==1) {ThereIsName=Standard_False;value=100;}
323 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
324 else {ThereIsName=Standard_True;value=atof(argv[2]);}
326 // On ferme le contexte local pour travailler dans le contexte global
327 if(TheAISContext()->HasOpenedContext())
328 TheAISContext()->CloseLocalContext();
330 // On set le booleen ThereIsCurrent
331 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
332 else {ThereIsCurrent=Standard_False;}
336 //===============================================================
337 // Il n'y a pas de nom mais des objets selectionnes
338 //===============================================================
339 if (!ThereIsName && ThereIsCurrent)
342 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
345 while ( it.More() ) {
347 Handle(AIS_InteractiveObject) aShape=
348 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
350 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
353 // On verifie que l'AIS InteraciveObject selectionne est bien
355 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
357 if (aShape->HasColor()) {
358 hascol=Standard_True;
360 // On recupere la couleur de aShape
361 col=aShape->Color();}
363 else hascol=Standard_False;
365 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
366 // pour lui appliquer la methode SetSize()
367 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
369 // C'est bien un triedre,on chage sa valeur!
370 aTrihedron->SetSize(value);
372 // On donne la couleur au Trihedron
373 if(hascol) aTrihedron->SetColor(col);
374 else aTrihedron->UnsetColor();
377 // The trihedron hasn't be errased from the map
378 // so you just have to redisplay it
379 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
388 TheAISContext() ->UpdateCurrentViewer();
391 //===============================================================
392 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
393 //===============================================================
397 //===============================================================
398 // Il y a un nom de triedre passe en argument
399 //===============================================================
401 TCollection_AsciiString name=argv[1];
403 // on verifie que ce nom correspond bien a une shape
404 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
408 // on recupere la shape dans la map des objets displayes
409 Handle(AIS_InteractiveObject) aShape =
410 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
412 // On verifie que l'AIS InteraciveObject est bien
414 if (!aShape.IsNull() &&
415 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
418 if (aShape->HasColor()) {
419 hascol=Standard_True;
421 // On recupere la couleur de aShape
422 col=aShape->Color();}
424 else hascol=Standard_False;
426 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
427 // pour lui appliquer la methode SetSize()
428 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
430 // C'est bien un triedre,on chage sa valeur
431 aTrihedron->SetSize(value);
433 // On donne la couleur au Trihedron
434 if(hascol) aTrihedron->SetColor(col);
435 else aTrihedron->UnsetColor();
437 // The trihedron hasn't be errased from the map
438 // so you just have to redisplay it
439 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
441 TheAISContext() ->UpdateCurrentViewer();
449 //==============================================================================
451 //==============================================================================
452 //function : VPlaneTrihedron
453 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
454 //Draw arg : vplanetri name
455 //==============================================================================
456 #include <AIS_Plane.hxx>
460 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
463 // Verification des arguments
464 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
467 Standard_Integer myCurrentIndex;
468 // Fermeture des contextes locaux
469 TheAISContext()->CloseAllContexts();
471 // On recupere tous les trihedrons de la GetMapOfAIS()
472 // et on active le mode de selection par face.
473 // =================================================
475 // Ouverture d'un contexte local et recuperation de son index.
476 TheAISContext()->OpenLocalContext(Standard_False);
477 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
479 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
482 Handle(AIS_InteractiveObject) ShapeA =
483 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
484 // On verifie que c'est bien un trihedron
485 if (!ShapeA.IsNull() &&
486 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
488 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
489 // on le charge dans le contexte et on active le mode Plane.
490 TheAISContext()->Load(TrihedronA,0,Standard_False);
491 TheAISContext()->Activate(TrihedronA,3);
496 di<<" Select a plane."<<"\n";
497 // Boucle d'attente waitpick.
498 Standard_Integer argccc = 5;
499 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
500 const char **argvvv = (const char **) bufff;
501 while (ViewerMainLoop( argccc, argvvv) ) { }
504 Handle(AIS_InteractiveObject) theIOB;
505 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
506 theIOB = TheAISContext()->Interactive();
509 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
511 // Fermeture du contexte local.
512 TheAISContext()->CloseLocalContext(myCurrentIndex);
514 // on le display & bind
515 TheAISContext()->Display(PlaneB );
516 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
523 //==============================================================================
524 // Fonction First click 2de click
526 // vaxis vertex vertex
528 // vaxispara edge vertex
529 // vaxisortho edge Vertex
530 // vaxisinter Face Face
531 //==============================================================================
533 //==============================================================================
534 //function : VAxisBuilder
536 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
537 //==============================================================================
538 #include <TopoDS_Edge.hxx>
539 #include <TopoDS_Vertex.hxx>
540 #include <TopExp.hxx>
541 #include <Geom_Line.hxx>
543 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
546 Standard_Boolean HasArg;
547 TCollection_AsciiString name;
548 Standard_Integer MyCurrentIndex;
551 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
552 if (argc==8) HasArg=Standard_True;
553 else HasArg=Standard_False;
556 // Fermeture des contextes
557 TheAISContext()->CloseAllContexts();
559 // Cas ou il y a des arguments
560 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
562 Standard_Real coord[6];
563 for(Standard_Integer i=0;i<=5;i++){
564 coord[i]=atof(argv[2+i]);
566 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
568 gp_Vec myVect (p1,p2);
569 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
570 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
571 GetMapOfAIS().Bind (TheAxis,name);
572 TheAISContext()->Display(TheAxis);
578 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
579 if ( !strcasecmp(argv[0], "vaxis")) {
580 TheAISContext()->OpenLocalContext();
581 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
583 // Active le mode edge et le mode vertex
584 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
585 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
586 di<<" Select an edge or a vertex."<<"\n";
588 // Boucle d'attente waitpick.
589 Standard_Integer argcc = 5;
590 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
591 const char **argvv = (const char **) buff;
592 while (ViewerMainLoop( argcc, argvv) ) { }
595 // recuperation de la shape.
597 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
598 ShapeA = TheAISContext()->SelectedShape();
600 // recuperation de l'AIS_InteractiveObject
601 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
602 // down cast en AIS_Point si sig et type
603 // AIS_Point -> Geom_Pnt ....
605 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
606 // on desactive le mode edge
607 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
608 di<<" Select a different vertex."<<"\n";
612 // Boucle d'attente waitpick.
613 Standard_Integer argccc = 5;
614 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
615 const char **argvvv = (const char **) bufff;
616 while (ViewerMainLoop( argccc, argvvv) ) { }
618 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
619 ShapeB = TheAISContext()->SelectedShape();
623 } while(ShapeB.IsSame(ShapeA) );
625 // Fermeture du context local
626 TheAISContext()->CloseLocalContext(MyCurrentIndex);
628 // Construction de l'axe
629 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
630 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
633 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
634 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
635 GetMapOfAIS().Bind (TheAxis,name);
636 TheAISContext()->Display(TheAxis);
639 // Un unique edge (ShapeA) a ete picke
640 // Fermeture du context local
641 TheAISContext()->CloseLocalContext(MyCurrentIndex);
642 // Constuction de l'axe
643 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
645 TopExp::Vertices(ed,Va,Vb );
646 gp_Pnt A=BRep_Tool::Pnt(Va);
647 gp_Pnt B=BRep_Tool::Pnt(Vb);
650 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
651 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
652 GetMapOfAIS().Bind (TheAxis,name);
653 TheAISContext()->Display(TheAxis);
659 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
660 else if ( !strcasecmp(argv[0], "vaxispara")) {
662 TheAISContext()->OpenLocalContext();
663 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
665 // Active le mode edge
666 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
667 di<<" Select an edge."<<"\n";
669 // Boucle d'attente waitpick.
670 Standard_Integer argcc = 5;
671 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
672 const char **argvv = (const char **) buff;
673 while (ViewerMainLoop( argcc, argvv) ) { }
677 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
678 ShapeA = TheAISContext()->SelectedShape();
680 // Active le mode vertex et deactive edges
681 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
682 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
683 di<<" Select a vertex."<<"\n";
685 // Boucle d'attente waitpick.
686 Standard_Integer argccc = 5;
687 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
688 const char **argvvv = (const char **) bufff;
689 while (ViewerMainLoop( argccc, argvvv) ) { }
692 // On peut choisir un pnt sur l'edge
694 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
695 ShapeB = TheAISContext()->SelectedShape();
697 // Fermeture du context local
698 TheAISContext()->CloseLocalContext(MyCurrentIndex);
700 // Construction de l'axe
701 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
702 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
704 TopExp::Vertices(ed,Va,Vc );
705 gp_Pnt A=BRep_Tool::Pnt(Va);
706 gp_Pnt C=BRep_Tool::Pnt(Vc);
709 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
710 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
711 GetMapOfAIS().Bind (TheAxis,name);
712 TheAISContext()->Display(TheAxis);
716 // Fonction axisortho
718 TheAISContext()->OpenLocalContext();
719 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
721 // Active le mode edge
722 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
723 di<<" Select an edge."<<"\n";
725 // Boucle d'attente waitpick.
726 Standard_Integer argcc = 5;
727 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
728 const char **argvv = (const char **) buff;
729 while (ViewerMainLoop( argcc, argvv) ) { }
733 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
734 ShapeA = TheAISContext()->SelectedShape();
736 // Active le mode vertex et deactive edges
737 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
738 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
739 di<<" Slect a vertex."<<"\n";
741 // Boucle d'attente waitpick.
742 Standard_Integer argccc = 5;
743 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
744 const char **argvvv = (const char **) bufff;
745 while (ViewerMainLoop( argccc, argvvv) ) { }
748 // On peut choisir un pnt sur l'edge
750 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
751 ShapeB = TheAISContext()->SelectedShape();
753 // Fermeture du context local
754 TheAISContext()->CloseLocalContext(MyCurrentIndex);
756 // Construction de l'axe
757 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
758 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
760 TopExp::Vertices(ed,Va,Vc );
761 gp_Pnt A=BRep_Tool::Pnt(Va);
762 gp_Pnt C=BRep_Tool::Pnt(Vc);
763 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
766 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
767 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
768 GetMapOfAIS().Bind (TheAxis,name);
769 TheAISContext()->Display(TheAxis);
778 //==============================================================================
779 // Fonction First click Result
781 // vpoint vertex AIS_Point=Vertex
782 // edge AIS_Point=Middle of the edge
783 //==============================================================================
785 //==============================================================================
786 //function : VPointBuilder
787 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
788 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
789 //==============================================================================
790 #include <TopoDS_Edge.hxx>
791 #include <TopoDS_Vertex.hxx>
792 #include <TopExp.hxx>
793 #include <AIS_Point.hxx>
794 #include <Geom_CartesianPoint.hxx>
796 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
799 Standard_Boolean HasArg;
800 TCollection_AsciiString name;
801 Standard_Integer myCurrentIndex;
804 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
805 if (argc==5) HasArg=Standard_True;
806 else HasArg=Standard_False;
809 // Fermeture des contextes
810 TheAISContext()->CloseAllContexts();
812 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
814 Standard_Real thecoord[3];
815 for(Standard_Integer i=0;i<=2;i++)
816 thecoord[i]=atof(argv[2+i]);
817 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
818 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
819 GetMapOfAIS().Bind (myAISPoint,name);
820 TheAISContext()->Display(myAISPoint);
823 // Il n'a pas d'arguments
825 TheAISContext()->OpenLocalContext();
826 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
828 // Active le mode Vertex et Edges
829 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
830 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
831 di<<" Select a vertex or an edge(build the middle)"<<"\n";
833 // Boucle d'attente waitpick.
834 Standard_Integer argcc = 5;
835 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
836 const char **argvv = (const char **) buff;
837 while (ViewerMainLoop( argcc, argvv) ) { }
841 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
842 ShapeA= TheAISContext()->SelectedShape();
845 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
846 // Un vertex a ete selectionne
847 // Fermeture du context local
848 TheAISContext()->CloseLocalContext(myCurrentIndex);
850 // Construction du point
851 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
852 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
853 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
854 GetMapOfAIS().Bind(myAISPoint,name);
855 TheAISContext()->Display(myAISPoint);
858 // Un Edge a ete selectionne
859 // Fermeture du context local
860 TheAISContext()->CloseLocalContext(myCurrentIndex);
862 // Construction du point milieu de l'edge
863 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
864 TopoDS_Vertex myVertexA,myVertexB;
865 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
866 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
867 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
868 // M est le milieu de [AB]
869 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
870 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
871 GetMapOfAIS().Bind(myAISPointM,name);
872 TheAISContext()->Display(myAISPointM);
880 //==============================================================================
881 // Function 1st click 2de click 3de click
882 // vplane Vertex Vertex Vertex
886 // vplanepara Face Vertex
888 // vplaneortho Face Edge
890 //==============================================================================
892 //==============================================================================
893 //function : VPlaneBuilder
894 //purpose : Build an AIS_Plane from selected entities or Named AIS components
895 //Draw arg : vplane PlaneName [AxisName] [PointName]
896 // [PointName] [PointName] [PointName]
897 // [PlaneName] [PointName]
898 //==============================================================================
900 static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
901 Standard_Integer argc,
905 Standard_Boolean hasArg;
906 TCollection_AsciiString aName;
907 Standard_Integer aCurrentIndex;
910 if (argc<2 || argc>5 )
912 std::cout<<" Syntax error\n";
915 if (argc==5 || argc==4)
916 hasArg=Standard_True;
918 hasArg=Standard_False;
921 // Close all contexts
922 TheAISContext()->CloseAllContexts();
924 // There are some arguments
927 if (!GetMapOfAIS().IsBound2(argv[2] ))
929 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
932 // Get shape from map
933 Handle(AIS_InteractiveObject) aShapeA =
934 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
936 // The first argument is an AIS_Point
937 if (!aShapeA.IsNull() &&
938 aShapeA->Type()==AIS_KOI_Datum &&
939 aShapeA->Signature()==1)
941 // The second argument must also be an AIS_Point
942 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
944 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
947 // Get shape from map
948 Handle(AIS_InteractiveObject) aShapeB =
949 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
950 // If B is not an AIS_Point
951 if (aShapeB.IsNull() ||
952 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
954 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
957 // The third object is an AIS_Point
958 if (!GetMapOfAIS().IsBound2(argv[4]) )
960 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
963 // Get shape from map
964 Handle(AIS_InteractiveObject) aShapeC =
965 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
966 // If C is not an AIS_Point
967 if (aShapeC.IsNull() ||
968 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
970 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
974 // Treatment of objects A, B, C
975 // Downcast an AIS_IO to AIS_Point
976 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
977 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
978 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
980 Handle(Geom_CartesianPoint ) aCartPointA =
981 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
983 Handle(Geom_CartesianPoint ) aCartPointB =
984 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
986 Handle(Geom_CartesianPoint ) aCartPointC =
987 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
989 // Verification that the three points are different
990 if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
991 abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
992 abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
995 std::cout<<"vplane error: same points"<<"\n";return 1;
997 if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
998 abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
999 abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1002 std::cout<<"vplane error: same points"<<"\n";return 1;
1004 if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1005 abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1006 abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1009 std::cout<<"vplane error: same points"<<"\n";return 1;
1012 gp_Pnt A = aCartPointA->Pnt();
1013 gp_Pnt B = aCartPointB->Pnt();
1014 gp_Pnt C = aCartPointC->Pnt();
1016 // Construction of AIS_Plane
1017 GC_MakePlane MkPlane (A,B,C);
1018 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1019 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1020 GetMapOfAIS().Bind (anAISPlane,aName );
1021 TheAISContext()->Display(anAISPlane);
1024 // The first argument is an AIS_Axis
1025 // Creation of a plane orthogonal to the axis through a point
1026 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1027 // The second argument should be an AIS_Point
1028 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1030 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1033 // Get shape from map
1034 Handle(AIS_InteractiveObject) aShapeB =
1035 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1036 // If B is not an AIS_Point
1037 if (aShapeB.IsNull() ||
1038 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1040 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1044 // Treatment of objects A and B
1045 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1046 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1048 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1049 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1051 gp_Ax1 anAxis = aGeomLineA->Position();
1052 Handle(Geom_CartesianPoint) aCartPointB =
1053 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1055 gp_Dir D =anAxis.Direction();
1056 gp_Pnt B = aCartPointB->Pnt();
1058 // Construction of AIS_Plane
1059 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1060 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1061 GetMapOfAIS().Bind (anAISPlane,aName );
1062 TheAISContext()->Display(anAISPlane);
1065 // The first argumnet is an AIS_Plane
1066 // Creation of a plane parallel to the plane passing through the point
1067 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1069 // The second argument should be an AIS_Point
1070 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1072 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1075 // Get shape from map
1076 Handle(AIS_InteractiveObject) aShapeB =
1077 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1078 // B should be an AIS_Point
1079 if (aShapeB.IsNull() ||
1080 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1082 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1086 // Treatment of objects A and B
1087 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1088 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1090 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1091 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1093 Handle(Geom_CartesianPoint) aCartPointB =
1094 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1095 gp_Pnt B= aCartPointB->Pnt();
1097 // Construction of an AIS_Plane
1098 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1099 GetMapOfAIS().Bind (anAISPlane, aName);
1100 TheAISContext()->Display(anAISPlane);
1105 std::cout<<"vplane: error 1st object is not an AIS\n";
1109 // There are no arguments
1113 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1114 if (!strcasecmp(argv[0], "vplane"))
1116 TheAISContext()->OpenLocalContext();
1117 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1119 // Active modes Vertex, Edge and Face
1120 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1121 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1122 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1123 std::cout<<"Select a vertex, a face or an edge\n";
1126 Standard_Integer argcc = 5;
1127 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1128 const char **argvv = (const char **) buff;
1129 while (ViewerMainLoop( argcc, argvv) ) { }
1132 TopoDS_Shape aShapeA;
1133 for (TheAISContext()->InitSelected();
1134 TheAISContext()->MoreSelected();
1135 TheAISContext()->NextSelected())
1137 aShapeA = TheAISContext()->SelectedShape();
1140 // aShapeA is a Vertex
1141 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1143 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1144 std::cout<<" Select an edge or a different vertex\n";
1147 Standard_Integer argccc = 5;
1148 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1149 const char **argvvv = (const char **) bufff;
1150 while (ViewerMainLoop( argccc, argvvv) ) { }
1153 TopoDS_Shape aShapeB;
1154 for (TheAISContext()->InitSelected();
1155 TheAISContext()->MoreSelected();
1156 TheAISContext()->NextSelected())
1158 aShapeB = TheAISContext()->SelectedShape();
1160 // aShapeB is a Vertex
1161 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1163 // A and B are the same
1164 if (aShapeB.IsSame(aShapeA))
1166 std::cout<<" vplane: error, same points selected\n";
1169 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1170 std::cout<<" Select a different vertex\n";
1173 Standard_Integer argcccc = 5;
1174 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1175 const char **argvvvv = (const char **) buffff;
1176 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1179 TopoDS_Shape aShapeC;
1180 for (TheAISContext()->InitSelected();
1181 TheAISContext()->MoreSelected();
1182 TheAISContext()->NextSelected())
1184 aShapeC = TheAISContext()->SelectedShape();
1186 // aShapeC is the same as A or B
1187 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1189 std::cout<<" vplane: error, same points selected\n";
1193 // Close the local context
1194 TheAISContext()->CloseLocalContext(aCurrentIndex);
1196 // Construction of plane
1197 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1198 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1199 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1200 GC_MakePlane MkPlane(A, B, C);
1201 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1202 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1203 GetMapOfAIS().Bind (anAISPlane, aName);
1204 TheAISContext()->Display(anAISPlane);
1206 // ShapeB is an edge
1209 // Verify that the vertex is not on the edge ShapeB
1210 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1211 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1213 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1214 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1216 // The vertex is on the edge
1217 std::cout<<" vplane: error point is on the edge\n";
1222 // Close the local context
1223 TheAISContext()->CloseLocalContext(aCurrentIndex);
1224 // Construction of plane
1225 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1226 TopoDS_Vertex aVBa, aVBb;
1227 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1228 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1229 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1230 GC_MakePlane MkPlane (A, aBa, aBb);
1231 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1232 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1233 GetMapOfAIS().Bind (anAISPlane, aName);
1234 TheAISContext()->Display(anAISPlane);
1238 // aShapeA is an edge
1239 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1241 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1242 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1243 std::cout<<" Select a vertex that don't belong to the edge\n";
1246 Standard_Integer argccc = 5;
1247 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1248 const char **argvvv = (const char **) bufff;
1249 while (ViewerMainLoop( argccc, argvvv) ) { }
1252 TopoDS_Shape aShapeB;
1253 for (TheAISContext()->InitSelected();
1254 TheAISContext()->MoreSelected();
1255 TheAISContext()->NextSelected())
1257 aShapeB = TheAISContext()->SelectedShape();
1259 // aShapeB should be a Vertex
1260 // Check that the vertex aShapeB is not on the edge
1261 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1262 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1264 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1265 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1267 // The vertex is on the edge
1268 std::cout<<" vplane: error point is on the edge\n";
1273 // Close the local context
1274 TheAISContext()->CloseLocalContext(aCurrentIndex);
1275 // Construction of plane
1276 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1277 TopoDS_Vertex aVAa, aVAb;
1278 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1279 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1280 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1281 GC_MakePlane MkPlane (B,Aa,Ab);
1282 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1283 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1284 GetMapOfAIS().Bind (anAISPlane ,aName);
1285 TheAISContext()->Display(anAISPlane);
1288 // aShapeA is a Face
1291 // Close the local context: nothing to select
1292 TheAISContext()->CloseLocalContext(aCurrentIndex);
1293 // Construction of plane
1294 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1295 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1296 if (aSurface.GetType()==GeomAbs_Plane)
1298 gp_Pln aPlane = aSurface.Plane();
1299 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1300 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1301 GetMapOfAIS().Bind (anAISPlane, aName);
1302 TheAISContext()->Display(anAISPlane);
1306 std::cout<<" vplane: error\n";
1312 // Function vPlanePara
1313 // ===================
1314 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1315 else if (!strcasecmp(argv[0], "vplanepara"))
1317 TheAISContext()->OpenLocalContext();
1318 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1320 // Activate modes Vertex and Face
1321 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1322 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1323 std::cout<<" Select a vertex or a face\n";
1326 Standard_Integer argcc = 5;
1327 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1328 const char **argvv = (const char **) buff;
1329 while (ViewerMainLoop( argcc, argvv) ) { }
1332 TopoDS_Shape aShapeA;
1333 for (TheAISContext()->InitSelected();
1334 TheAISContext()->MoreSelected();
1335 TheAISContext()->NextSelected())
1337 aShapeA = TheAISContext()->SelectedShape();
1340 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1342 // aShapeA is a vertex
1343 // Deactivate the mode Vertex
1344 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1345 std::cout<<" Select a face\n";
1348 Standard_Integer argccc = 5;
1349 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1350 const char **argvvv = (const char **) bufff;
1351 while (ViewerMainLoop( argccc, argvvv) ) { }
1354 TopoDS_Shape aShapeB;
1355 for (TheAISContext()->InitSelected();
1356 TheAISContext()->MoreSelected();
1357 TheAISContext()->NextSelected())
1359 // A vertex ShapeA can be on Face ShapeB
1360 aShapeB = TheAISContext()->SelectedShape();
1363 // Close the local context
1364 TheAISContext()->CloseLocalContext(aCurrentIndex);
1366 // Construction of plane
1367 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1369 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1370 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1371 if (aSurface.GetType()==GeomAbs_Plane )
1373 gp_Pln aPlane = aSurface.Plane();
1374 // Construct a plane parallel to aGeomPlane through A
1375 aPlane.SetLocation(A);
1376 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1377 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1378 GetMapOfAIS().Bind (aAISPlane ,aName);
1379 TheAISContext()->Display(aAISPlane);
1383 std::cout<<" vplanepara: error\n";
1390 // Deactive the mode Face
1391 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1392 std::cout<<" Select a vertex\n";
1395 Standard_Integer argccc = 5;
1396 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1397 const char **argvvv = (const char **) bufff;
1398 while (ViewerMainLoop( argccc, argvvv) ) { }
1401 TopoDS_Shape aShapeB;
1402 for (TheAISContext()->InitSelected();
1403 TheAISContext()->MoreSelected();
1404 TheAISContext()->NextSelected())
1406 // A vertex ShapeB can be on Face ShapeA
1407 aShapeB = TheAISContext()->SelectedShape();
1409 // Close the local context
1410 TheAISContext()->CloseLocalContext(aCurrentIndex);
1412 // Construction of plane
1413 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1415 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1416 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1417 if (aSurface.GetType()==GeomAbs_Plane )
1419 gp_Pln aPlane = aSurface.Plane();
1420 aPlane.SetLocation(B);
1421 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1422 // Construct a plane parallel to aGeomPlane through B
1423 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1424 GetMapOfAIS().Bind (anAISPlane, aName);
1425 TheAISContext()->Display(anAISPlane);
1429 std::cout<<" vplanepara: error"<<"\n";return 1;
1434 // Function vplaneortho
1435 // ====================
1436 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1439 TheAISContext()->OpenLocalContext();
1440 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1442 // Activate the modes Edge and Face
1443 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1444 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1445 std::cout<<" Select a face and an edge coplanar\n";
1448 Standard_Integer argcc = 5;
1449 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1450 const char **argvv = (const char **) buff;
1451 while (ViewerMainLoop( argcc, argvv) ) { }
1454 TopoDS_Shape aShapeA;
1455 for (TheAISContext()->InitSelected();
1456 TheAISContext()->MoreSelected();
1457 TheAISContext()->NextSelected())
1459 aShapeA = TheAISContext()->SelectedShape();
1462 if (aShapeA.ShapeType()==TopAbs_EDGE )
1464 // ShapeA is an edge, deactivate the mode Edge...
1465 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1466 std::cout<<" Select a face\n";
1469 Standard_Integer argccc = 5;
1470 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1471 const char **argvvv = (const char **) bufff;
1472 while (ViewerMainLoop( argccc, argvvv) ) { }
1475 TopoDS_Shape aShapeB;
1476 for (TheAISContext()->InitSelected();
1477 TheAISContext()->MoreSelected();
1478 TheAISContext()->NextSelected())
1480 // Edge ShapeA can be on Face ShapeB
1481 aShapeB = TheAISContext()->SelectedShape();
1484 // Close the local context
1485 TheAISContext()->CloseLocalContext(aCurrentIndex);
1487 // Construction of plane
1488 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1489 TopoDS_Vertex aVAa, aVAb;
1490 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1491 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1492 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1496 // Creation of rotation axis
1497 gp_Ax1 aRotAxis (Aa,Dab);
1499 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1500 // The edge must be parallel to the face
1501 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1502 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1503 // Compare to heights
1504 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1505 >Precision::Confusion())
1507 // the edge is not parallel to the face
1508 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1512 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1513 if (aSurface.GetType()==GeomAbs_Plane)
1515 gp_Pln aPlane = aSurface.Plane();
1516 // It rotates a half turn round the axis of rotation
1517 aPlane.Rotate(aRotAxis , M_PI/2);
1519 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1520 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1521 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1522 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1523 GetMapOfAIS().Bind (anAISPlane, aName);
1524 TheAISContext()->Display(anAISPlane);
1528 std::cout<<" vplaneortho: error\n";
1534 // ShapeA is a Face, deactive the mode Face.
1535 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1536 std::cout<<" Select an edge\n";
1539 Standard_Integer argccc = 5;
1540 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1541 const char **argvvv = (const char **) bufff;
1542 while (ViewerMainLoop( argccc, argvvv) ) { }
1545 TopoDS_Shape aShapeB;
1546 for (TheAISContext()->InitSelected();
1547 TheAISContext()->MoreSelected();
1548 TheAISContext()->NextSelected())
1550 // Edge ShapeB can be on Face ShapeA
1551 aShapeB = TheAISContext()->SelectedShape();
1553 // Close the local context
1554 TheAISContext()->CloseLocalContext(aCurrentIndex);
1556 // Construction of plane
1557 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1558 TopoDS_Vertex aVBa, aVBb;
1559 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1560 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1561 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1562 gp_Vec ab (aBa,aBb);
1564 // Creation of rotation axe
1565 gp_Ax1 aRotAxis (aBa,Dab);
1567 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1568 // The edge must be parallel to the face
1569 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1570 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1571 // Comparing the two heights
1572 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1573 >Precision::Confusion())
1575 // the edge is not parallel to the face
1576 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1580 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1581 if (aSurface.GetType()==GeomAbs_Plane)
1583 gp_Pln aPlane = aSurface.Plane();
1584 // It rotates a half turn round the axis of rotation
1585 aPlane.Rotate(aRotAxis , M_PI/2);
1586 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1587 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1588 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1589 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1590 GetMapOfAIS().Bind (anAISPlane ,aName);
1591 TheAISContext()->Display(anAISPlane);
1595 std::cout<<" vplaneortho: error\n";
1605 //==============================================================================
1607 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1608 //==============================================================================
1610 //==============================================================================
1611 //function : VLineBuilder
1612 //purpose : Build an AIS_Line
1613 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1614 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1615 //==============================================================================
1616 #include <Geom_CartesianPoint.hxx>
1617 #include <AIS_Line.hxx>
1620 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1622 Standard_Integer myCurrentIndex;
1624 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1625 // Fermeture des contextes
1626 TheAISContext()->CloseAllContexts();
1628 // On recupere les parametres
1629 Handle(AIS_InteractiveObject) theShapeA;
1630 Handle(AIS_InteractiveObject) theShapeB;
1632 // Parametres: AIS_Point AIS_Point
1633 // ===============================
1636 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1637 // On verifie que c'est bien une AIS_Point
1638 if (!theShapeA.IsNull() &&
1639 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1640 // on recupere le deuxieme AIS_Point
1642 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1643 if (theShapeA.IsNull() ||
1644 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1646 di <<"vline error: wrong type of 2de argument."<<"\n";
1650 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1651 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1652 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1653 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1655 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1656 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1657 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1659 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1660 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1661 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1663 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1665 di<<"vline error: same points"<<"\n";return 1;
1667 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1668 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1669 GetMapOfAIS().Bind(theAISLine,argv[1] );
1670 TheAISContext()->Display(theAISLine );
1674 // Parametres 6 Reals
1675 // ==================
1678 // On verifie que les deux points ne sont pas confondus
1680 Standard_Real coord[6];
1681 for(Standard_Integer i=0;i<=2;i++){
1682 coord[i]=atof(argv[2+i]);
1683 coord[i+3]=atof(argv[5+i]);
1686 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1687 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1689 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1690 GetMapOfAIS().Bind(theAISLine,argv[1] );
1691 TheAISContext()->Display(theAISLine );
1695 // Pas de parametres: Selection dans le viewer.
1696 // ============================================
1699 TheAISContext()->OpenLocalContext();
1700 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1702 // Active le mode Vertex.
1703 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1704 di<<" Select a vertex "<<"\n";
1706 // Boucle d'attente waitpick.
1707 Standard_Integer argcc = 5;
1708 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1709 const char **argvv = (const char **) buff;
1710 while (ViewerMainLoop( argcc, argvv) ) { }
1713 TopoDS_Shape ShapeA;
1714 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1715 ShapeA = TheAISContext()->SelectedShape();
1718 // ShapeA est un Vertex
1719 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1721 di<<" Select a different vertex."<<"\n";
1723 TopoDS_Shape ShapeB;
1726 // Boucle d'attente waitpick.
1727 Standard_Integer argccc = 5;
1728 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1729 const char **argvvv = (const char **) bufff;
1730 while (ViewerMainLoop( argccc, argvvv) ) { }
1733 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1734 ShapeB = TheAISContext()->SelectedShape();
1738 } while(ShapeB.IsSame(ShapeA) );
1740 // Fermeture du context local
1741 TheAISContext()->CloseLocalContext(myCurrentIndex);
1743 // Construction de la line
1744 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1745 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1747 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1748 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1750 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1751 GetMapOfAIS().Bind(theAISLine,argv[1] );
1752 TheAISContext()->Display(theAISLine );
1756 di<<"vline error."<<"\n";
1764 //==============================================================================
1765 // class : FilledCircle
1766 // purpose : creates filled circle based on AIS_InteractiveObject
1768 // This class is used to check method Matches() of class
1769 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1770 // because none of AIS classes provides creation of
1771 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1772 // (look method ComputeSelection() )
1773 //==============================================================================
1775 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1777 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1778 gp_Circ aCirc(anAxes, theRadius);
1779 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1783 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1785 class FilledCircle : public AIS_InteractiveObject
1789 DEFINE_STANDARD_RTTI(FilledCircle);
1791 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1792 FilledCircle(Handle(Geom_Circle) theCircle);
1795 TopoDS_Face ComputeFace();
1797 // Virtual methods implementation
1798 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1799 const Handle(Prs3d_Presentation)& thePresentation,
1800 const Standard_Integer theMode);
1802 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1803 const Standard_Integer theMode);
1806 Handle(Geom_Circle) myCircle;
1807 Standard_Boolean myFilledStatus;
1811 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1812 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1814 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1816 myCircle = CreateCircle(theCenter, theRadius);
1817 myFilledStatus = Standard_True;
1820 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1822 myCircle = theCircle;
1823 myFilledStatus = Standard_True;
1826 TopoDS_Face FilledCircle::ComputeFace()
1828 // Create edge from myCircle
1829 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1830 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1832 // Create wire from anEdge
1833 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1834 TopoDS_Wire aWire = aWireMaker.Wire();
1836 // Create face from aWire
1837 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1838 TopoDS_Face aFace = aFaceMaker.Face();
1843 void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
1844 const Handle_Prs3d_Presentation &thePresentation,
1845 const Standard_Integer theMode)
1847 thePresentation->Clear();
1849 TopoDS_Face aFace = ComputeFace();
1851 if (aFace.IsNull()) return;
1852 if (theMode != 0) return;
1854 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1857 void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection,
1858 const Standard_Integer theMode)
1860 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1861 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1862 myCircle, myFilledStatus);
1863 theSelection->Add(aSensitiveCircle);
1866 //==============================================================================
1868 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1869 //==============================================================================
1871 //==============================================================================
1872 //function : VCircleBuilder
1873 //purpose : Build an AIS_Circle
1874 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1875 // PointName PointName PointName IsFilled
1876 //==============================================================================
1878 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1879 TCollection_AsciiString theName,
1880 Standard_Boolean isFilled)
1882 Handle(AIS_InteractiveObject) aCircle;
1885 aCircle = new FilledCircle(theGeomCircle);
1889 aCircle = new AIS_Circle(theGeomCircle);
1892 // Check if there is an object with given name
1893 // and remove it from context
1894 if (GetMapOfAIS().IsBound2(theName))
1896 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
1897 Handle(AIS_InteractiveObject) anInterObj =
1898 Handle(AIS_InteractiveObject)::DownCast(anObj);
1899 TheAISContext()->Remove(anInterObj, Standard_False);
1900 GetMapOfAIS().UnBind2(theName);
1903 // Bind the circle to its name
1904 GetMapOfAIS().Bind(aCircle, theName);
1906 // Display the circle
1907 TheAISContext()->Display(aCircle);
1911 static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1913 Standard_Integer myCurrentIndex;
1914 // Verification of the arguments
1915 if (argc>6 || argc<2)
1917 std::cout << "vcircle error: expect 4 arguments.\n";
1918 return 1; // TCL_ERROR
1920 TheAISContext()->CloseAllContexts();
1922 // There are all arguments
1926 TCollection_AsciiString aName(argv[1]);
1927 Standard_Boolean isFilled = (Standard_Boolean)atoi(argv[5]);
1929 Handle(AIS_InteractiveObject) theShapeA;
1930 Handle(AIS_InteractiveObject) theShapeB;
1933 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
1935 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
1938 // Arguments: AIS_Point AIS_Point AIS_Point
1939 // ========================================
1940 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
1941 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1943 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
1945 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
1946 return 1; // TCL_ERROR
1948 // The third object must be a point
1949 Handle(AIS_InteractiveObject) theShapeC =
1950 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
1951 if (theShapeC.IsNull() ||
1952 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
1954 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
1955 return 1; // TCL_ERROR
1958 // Verify that the three points are different
1959 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
1960 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
1961 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
1963 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
1964 Handle(Geom_CartesianPoint) myCartPointA =
1965 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
1967 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
1968 Handle(Geom_CartesianPoint) myCartPointB =
1969 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
1971 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
1972 Handle(Geom_CartesianPoint) myCartPointC =
1973 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
1976 if (abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
1977 abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
1978 abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
1980 std::cout << "vcircle error: Same points.\n";
1981 return 1; // TCL_ERROR
1984 if (abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
1985 abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1986 abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1988 std::cout << "vcircle error: Same points.\n";
1989 return 1; // TCL_ERROR
1992 if (abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
1993 abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1994 abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1996 std::cout << "vcircle error: Same points.\n";
1997 return 1;// TCL_ERROR
1999 // Construction of the circle
2000 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2001 myCartPointB->Pnt(), myCartPointC->Pnt() );
2002 Handle (Geom_Circle) theGeomCircle;
2005 theGeomCircle = Cir.Value();
2007 catch (StdFail_NotDone)
2009 std::cout << "vcircle error: can't create circle\n";
2010 return -1; // TCL_ERROR
2013 DisplayCircle(theGeomCircle, aName, isFilled);
2016 // Arguments: AIS_Plane AIS_Point Real
2017 // ===================================
2018 else if (theShapeA->Type() == AIS_KOI_Datum &&
2019 theShapeA->Signature() == 7 )
2021 if (theShapeB->Type() != AIS_KOI_Datum ||
2022 theShapeB->Signature() != 1 )
2024 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2025 return 1; // TCL_ERROR
2027 // Ñheck that the radius is >= 0
2028 if (atof(argv[4]) <= 0 )
2030 std::cout << "vcircle error: the radius must be >=0.\n";
2031 return 1; // TCL_ERROR
2034 // Recover the normal to the plane
2035 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2036 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2038 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2039 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2040 Handle(Geom_CartesianPoint) myCartPointB =
2041 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2043 gp_Pln mygpPlane = myGeomPlane->Pln();
2044 gp_Ax1 thegpAxe = mygpPlane.Axis();
2045 gp_Dir theDir = thegpAxe.Direction();
2046 gp_Pnt theCenter = myCartPointB->Pnt();
2047 Standard_Real TheR = atof(argv[4]);
2048 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2049 Handle (Geom_Circle) theGeomCircle;
2052 theGeomCircle = Cir.Value();
2054 catch (StdFail_NotDone)
2056 std::cout << "vcircle error: can't create circle\n";
2057 return -1; // TCL_ERROR
2060 DisplayCircle(theGeomCircle, aName, isFilled);
2067 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2068 return 1; // TCL_ERROR
2072 // No arguments: selection in the viewer
2073 // =========================================
2076 // Get the name of the circle
2077 TCollection_AsciiString aName(argv[1]);
2079 TheAISContext()->OpenLocalContext();
2080 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2082 // Activate selection mode for vertices and faces
2083 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2084 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2085 std::cout << " Select a vertex or a face\n";
2088 Standard_Integer argcc = 5;
2089 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2090 const char **argvv = (const char **) buff;
2091 while (ViewerMainLoop( argcc, argvv) ) { }
2094 TopoDS_Shape ShapeA;
2095 for(TheAISContext()->InitSelected();
2096 TheAISContext()->MoreSelected();
2097 TheAISContext()->NextSelected() )
2099 ShapeA = TheAISContext()->SelectedShape();
2102 // ShapeA is a Vertex
2103 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2105 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2106 std::cout << " Select a different vertex\n";
2108 TopoDS_Shape ShapeB;
2112 Standard_Integer argccc = 5;
2113 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2114 const char **argvvv = (const char **) bufff;
2115 while (ViewerMainLoop( argccc, argvvv) ) { }
2118 for(TheAISContext()->InitSelected();
2119 TheAISContext()->MoreSelected();
2120 TheAISContext()->NextSelected() )
2122 ShapeB = TheAISContext()->SelectedShape();
2124 } while(ShapeB.IsSame(ShapeA) );
2126 // Selection of ShapeC
2127 std::cout << " Select the last vertex\n";
2128 TopoDS_Shape ShapeC;
2132 Standard_Integer argcccc = 5;
2133 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2134 const char **argvvvv = (const char **) buffff;
2135 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2138 for(TheAISContext()->InitSelected();
2139 TheAISContext()->MoreSelected();
2140 TheAISContext()->NextSelected() )
2142 ShapeC = TheAISContext()->SelectedShape();
2144 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2147 Standard_Boolean isFilled;
2148 std::cout << "Enter filled status (0 or 1)\n";
2151 // Close the local context
2152 TheAISContext()->CloseLocalContext(myCurrentIndex);
2154 // Construction of the circle
2155 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2156 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2157 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2159 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2160 Handle (Geom_Circle) theGeomCircle;
2163 theGeomCircle = Cir.Value();
2165 catch (StdFail_NotDone)
2167 std::cout << "vcircle error: can't create circle\n";
2168 return -1; // TCL_ERROR
2171 DisplayCircle(theGeomCircle, aName, isFilled);
2177 std::cout << " Select a vertex (in your face)\n";
2178 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2180 TopoDS_Shape ShapeB;
2182 Standard_Integer argccc = 5;
2183 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2184 const char **argvvv = (const char **) bufff;
2185 while (ViewerMainLoop( argccc, argvvv) ) { }
2188 for(TheAISContext()->InitSelected();
2189 TheAISContext()->MoreSelected();
2190 TheAISContext()->NextSelected() )
2192 ShapeB = TheAISContext()->SelectedShape();
2195 // Recover the radius
2196 Standard_Real theRad;
2199 std::cout << " Enter the value of the radius:\n";
2201 } while (theRad <= 0);
2203 // Get filled status
2204 Standard_Boolean isFilled;
2205 std::cout << "Enter filled status (0 or 1)\n";
2208 // Close the local context
2209 TheAISContext()->CloseLocalContext(myCurrentIndex);
2210 // Construction of the circle
2212 // Recover the normal to the plane. tag
2213 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2214 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2215 gp_Pln myPlane = mySurface.Plane();
2216 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2217 gp_Pln mygpPlane = theGeomPlane->Pln();
2218 gp_Ax1 thegpAxe = mygpPlane.Axis();
2219 gp_Dir theDir = thegpAxe.Direction();
2221 // Recover the center
2222 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2224 // Ñonstruct the circle
2225 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2226 Handle (Geom_Circle) theGeomCircle;
2229 theGeomCircle = Cir.Value();
2231 catch (StdFail_NotDone)
2233 std::cout << "vcircle error: can't create circle\n";
2234 return -1; // TCL_ERROR
2237 DisplayCircle(theGeomCircle, aName, isFilled);
2247 //===============================================================================================
2248 //function : VDrawText
2250 //purpose : Create a text.
2251 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2252 //===============================================================================================
2253 #include <Graphic3d_Group.hxx>
2254 #include <Graphic3d_Structure.hxx>
2255 #include <Graphic3d_NameOfFont.hxx>
2256 #include <Graphic3d_AspectText3d.hxx>
2257 #include <Graphic2d_GraphicObject.hxx>
2258 #include <Graphic3d_Array1OfVertex.hxx>
2259 #include <Graphic3d_AspectFillArea3d.hxx>
2260 #include <Graphic3d_StructureManager.hxx>
2261 #include <Graphic3d_VerticalTextAlignment.hxx>
2262 #include <Graphic3d_HorizontalTextAlignment.hxx>
2264 #include <Visual3d_ViewManager.hxx>
2265 #include <ViewerTest_Tool.ixx>
2267 #include <Standard_DefineHandle.hxx>
2269 #include <Prs3d_Root.hxx>
2270 #include <Prs3d_Text.hxx>
2271 #include <Prs3d_TextAspect.hxx>
2272 #include <Prs3d_ShadingAspect.hxx>
2273 #include <PrsMgr_PresentationManager3d.hxx>
2275 #include <TCollection_ExtendedString.hxx>
2276 #include <TCollection_AsciiString.hxx>
2278 #include <gp_Pnt.hxx>
2279 #include <Quantity_NameOfColor.hxx>
2280 #include <Quantity_Color.hxx>
2283 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2285 class MyTextClass:public AIS_InteractiveObject
2289 DEFINE_STANDARD_RTTI(MyTextClass );
2295 const TCollection_ExtendedString& , const gp_Pnt& ,
2296 Quantity_Color color,
2297 Standard_Integer aHJust,
2298 Standard_Integer aVJust ,
2299 Standard_Real Angle ,
2300 Standard_Boolean Zoom ,
2301 Standard_Real Height,
2302 OSD_FontAspect FontAspect,
2303 Standard_CString Font
2308 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2309 const Handle(Prs3d_Presentation)& aPresentation,
2310 const Standard_Integer aMode);
2312 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
2313 const Standard_Integer aMode){} ;
2316 TCollection_ExtendedString aText;
2319 Standard_Real Green;
2321 Standard_Real aAngle;
2322 Standard_Real aHeight;
2323 Standard_Boolean aZoomable;
2324 Quantity_Color aColor;
2325 Standard_CString aFont;
2326 OSD_FontAspect aFontAspect;
2327 Graphic3d_HorizontalTextAlignment aHJustification;
2328 Graphic3d_VerticalTextAlignment aVJustification;
2333 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2334 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2337 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2338 Quantity_Color color = Quantity_NOC_YELLOW,
2339 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2340 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2341 Standard_Real angle = 0.0 ,
2342 Standard_Boolean zoomable = Standard_True,
2343 Standard_Real height = 12.,
2344 OSD_FontAspect fontAspect = OSD_FA_Regular,
2345 Standard_CString font = "Courier")
2348 aPosition = position;
2349 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2350 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2352 aZoomable = zoomable;
2355 aFontAspect = fontAspect;
2361 //////////////////////////////////////////////////////////////////////////////
2362 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2363 const Handle(Prs3d_Presentation)& aPresentation,
2364 const Standard_Integer aMode)
2367 aPresentation->Clear();
2369 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2371 asp->SetFont(aFont);
2372 asp->SetColor(aColor);
2373 asp->SetHeight(aHeight); // I am changing the myHeight value
2375 asp->SetHorizontalJustification(aHJustification);
2376 asp->SetVerticalJustification(aVJustification);
2377 asp->Aspect()->SetTextZoomable(aZoomable);
2378 asp->Aspect()->SetTextAngle(aAngle);
2379 asp->Aspect()->SetTextFontAspect(aFontAspect);
2380 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2382 /* This comment code is worked
2383 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2384 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2385 Graphic3d_Vertex vertices_text;
2386 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2387 TheGroup->SetPrimitivesAspect(aspect);
2388 TheGroup->BeginPrimitives();
2389 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2390 TheGroup->EndPrimitives();
2394 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2399 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2400 di<<"Usage: type help "<<argv[0]<<"\n";
2401 return 1; //TCL_ERROR
2404 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2406 // Create 3D view if it doesn't exist
2407 if ( aContext.IsNull() )
2409 ViewerTest::ViewerInit();
2410 aContext = ViewerTest::GetAISContext();
2411 if( aContext.IsNull() )
2413 di << "Error: Cannot create a 3D view\n";
2414 return 1; //TCL_ERROR
2419 const Standard_Real X = atof(argv[2]);
2420 const Standard_Real Y = atof(argv[3]);
2421 const Standard_Real Z = atof(argv[4]);
2422 const gp_Pnt pnt(X,Y,Z);
2425 const Quantity_Parameter R = atof(argv[5])/255.;
2426 const Quantity_Parameter G = atof(argv[6])/255.;
2427 const Quantity_Parameter B = atof(argv[7])/255.;
2428 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2431 const int hor_align = atoi(argv[8]);
2432 const int ver_align = atoi(argv[9]);
2435 const Standard_Real angle = atof(argv[10]);
2438 const Standard_Boolean zoom = atoi(argv[11]);
2441 const Standard_Real height = atof(argv[12]);
2444 const OSD_FontAspect aspect = OSD_FontAspect(atoi(argv[13]));
2447 TCollection_AsciiString font;
2449 font.AssignCat("Courier");
2451 font.AssignCat(argv[14]);
2453 // Text is multibyte
2454 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (atoi(argv[15]) != 0);
2457 TCollection_ExtendedString name;
2460 const char *str = argv[1];
2461 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2462 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2464 unsigned short c1 = *str++;
2465 unsigned short c2 = *str++;
2467 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2477 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2478 aContext->Display(myT,Standard_True);
2485 #include <gp_Pnt.hxx>
2486 #include <Graphic3d_ArrayOfPoints.hxx>
2487 #include <Graphic3d_ArrayOfPrimitives.hxx>
2488 #include <Graphic3d_Array1OfVertex.hxx>
2489 #include <Graphic3d_ArrayOfTriangles.hxx>
2490 #include <Poly_Array1OfTriangle.hxx>
2491 #include <Poly_Triangle.hxx>
2492 #include <Poly_Triangulation.hxx>
2493 #include <TColgp_Array1OfPnt.hxx>
2494 #include <TShort_Array1OfShortReal.hxx>
2495 #include <TShort_HArray1OfShortReal.hxx>
2497 #include <AIS_Triangulation.hxx>
2498 #include <Aspect_GraphicDevice.hxx>
2499 #include <StdPrs_ToolShadedShape.hxx>
2500 #include <Poly_Connect.hxx>
2501 #include <TColgp_Array1OfDir.hxx>
2502 #include <Graphic3d_GraphicDriver.hxx>
2504 #include <TColStd_Array1OfInteger.hxx>
2505 #include <TColStd_HArray1OfInteger.hxx>
2506 #include <Prs3d_ShadingAspect.hxx>
2507 #include <Graphic3d_MaterialAspect.hxx>
2508 #include <Graphic3d_AspectFillArea3d.hxx>
2510 #include <BRepPrimAPI_MakeCylinder.hxx>
2511 #include <TopoDS_Shape.hxx>
2512 #include <TopExp_Explorer.hxx>
2513 #include <TopAbs.hxx>
2514 #include <StdSelect_ShapeTypeFilter.hxx>
2517 //===============================================================================================
2518 //function : CalculationOfSphere
2520 //purpose : Create a Sphere
2521 //===============================================================================================
2523 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2526 double mRadius = Radius;
2527 double mCenter[3] = {X,Y,Z};
2528 int mThetaResolution;
2530 double mStartTheta = 0;//StartTheta;
2531 double mEndTheta = 360;//EndTheta;
2532 double mStartPhi = 0;//StartPhi;
2533 double mEndPhi = 180;//EndPhi;
2534 res = res < 4 ? 4 : res;
2536 mThetaResolution = res;
2537 mPhiResolution = res;
2540 int jStart, jEnd, numOffset;
2541 int numPts, numPolys;
2542 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2543 double startTheta, endTheta, startPhi, endPhi;
2544 int base, numPoles=0, thetaResolution, phiResolution;
2549 if ( numPieces > mThetaResolution ) {
2550 numPieces = mThetaResolution;
2553 int localThetaResolution = mThetaResolution;
2554 double localStartTheta = mStartTheta;
2555 double localEndTheta = mEndTheta;
2557 while ( localEndTheta < localStartTheta ) {
2558 localEndTheta += 360.0;
2561 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2563 // Change the ivars based on pieces.
2565 start = piece * localThetaResolution / numPieces;
2566 end = (piece+1) * localThetaResolution / numPieces;
2567 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2568 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2569 localThetaResolution = end - start;
2571 numPts = mPhiResolution * localThetaResolution + 2;
2572 numPolys = mPhiResolution * 2 * localThetaResolution;
2574 // Create north pole if needed
2575 int number_point = 0;
2576 int number_pointArray = 0;
2578 if ( mStartPhi <= 0.0 ) {
2579 number_pointArray++;
2582 if ( mEndPhi >= 180.0 ) {
2583 number_pointArray++;
2587 // Check data, determine increments, and convert to radians
2588 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2589 startTheta *= M_PI / 180.0;
2590 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2591 endTheta *= M_PI / 180.0;
2594 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2595 startPhi *= M_PI / 180.0;
2596 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2597 endPhi *= M_PI / 180.0;
2599 phiResolution = mPhiResolution - numPoles;
2600 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2601 thetaResolution = localThetaResolution;
2602 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2603 ++localThetaResolution;
2605 deltaTheta = (endTheta - startTheta) / thetaResolution;
2607 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2608 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2610 // Create intermediate points
2611 for ( i = 0; i < localThetaResolution; i++ ) {
2612 for ( j = jStart; j < jEnd; j++ ) {
2613 number_pointArray++;
2617 //Generate mesh connectivity
2618 base = phiResolution * localThetaResolution;
2620 int number_triangle = 0 ;
2621 if ( mStartPhi <= 0.0 ) { // around north pole
2622 number_triangle += localThetaResolution;
2625 if ( mEndPhi >= 180.0 ) { // around south pole
2626 number_triangle += localThetaResolution;
2629 // bands in-between poles
2630 for ( i=0; i < localThetaResolution; i++){
2631 for ( j=0; j < (phiResolution-1); j++){
2632 number_triangle +=2;
2636 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2637 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2638 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2640 if ( mStartPhi <= 0.0 ){
2643 x[2] = mCenter[2] + mRadius;
2644 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2647 // Create south pole if needed
2648 if ( mEndPhi >= 180.0 ){
2651 x[2] = mCenter[2] - mRadius;
2652 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2656 for ( i=0; i < localThetaResolution; i++){
2657 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2658 for ( j = jStart; j < jEnd; j++){
2659 phi = startPhi + j*deltaPhi;
2660 radius = mRadius * sin((double)phi);
2661 n[0] = radius * cos((double)theta);
2662 n[1] = radius * sin((double)theta);
2663 n[2] = mRadius * cos((double)phi);
2664 x[0] = n[0] + mCenter[0];
2665 x[1] = n[1] + mCenter[1];
2666 x[2] = n[2] + mCenter[2];
2667 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2673 number_triangle = 1;
2674 if ( mStartPhi <= 0.0 ){// around north pole
2675 for (i=0; i < localThetaResolution; i++){
2676 pts[0] = phiResolution*i + numPoles;
2677 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2679 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2684 if ( mEndPhi >= 180.0 ){ // around south pole
2685 numOffset = phiResolution - 1 + numPoles;
2686 for (i=0; i < localThetaResolution; i++){
2687 pts[0] = phiResolution*i + numOffset;
2688 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2689 pts[1] = numPoles - 1;
2690 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2695 // bands in-between poles
2697 for (i=0; i < localThetaResolution; i++){
2698 for (j=0; j < (phiResolution-1); j++){
2699 pts[0] = phiResolution*i + j + numPoles;
2700 pts[1] = pts[0] + 1;
2701 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2702 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2705 pts[2] = pts[1] - 1;
2706 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2711 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2713 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2715 Standard_Integer index[3];
2716 Standard_Real Tol = Precision::Confusion();
2719 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2720 gp_XYZ eqPlan(0, 0, 0);
2721 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2722 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2723 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2724 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2726 Standard_Real mod = vv.Modulus();
2727 if(mod < Tol) continue;
2731 Standard_Real modmax = eqPlan.Modulus();
2734 Nor = gp_Dir(eqPlan);
2736 Nor = gp_Dir(0., 0., 1.);
2738 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2739 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2740 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2741 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2745 polyTriangulation->SetNormals(Normals);
2747 return polyTriangulation;
2750 //===============================================================================================
2751 //function : VDrawSphere
2753 //purpose : Create an AIS shape.
2754 //===============================================================================================
2755 static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2758 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2759 if (aContextAIS.IsNull())
2761 std::cout << "Call vinit before!\n";
2766 std::cout << "Use: " << argv[0]
2767 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
2771 // read the arguments
2772 TCollection_AsciiString aShapeName (argv[1]);
2773 Standard_Integer aResolution = atoi (argv[2]);
2774 Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0;
2775 Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
2776 Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
2777 Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
2778 Standard_Boolean toShowEdges = (argc > 7) ? atoi (argv[7]) : Standard_False;
2780 // remove AIS object with given name from map
2781 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2783 std::cout << "Compute Triangulation...\n";
2784 Handle(AIS_Triangulation) aShape
2785 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2788 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2789 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2791 // stupid initialization of Green color in RGBA space as integer
2792 // probably wrong for big-endian CPUs
2793 Standard_Integer aRed = 0;
2794 Standard_Integer aGreen = 255;
2795 Standard_Integer aBlue = 0;
2796 Standard_Integer anAlpha = 0; // not used
2797 Standard_Integer aColorInt = aRed;
2798 aColorInt += aGreen << 8;
2799 aColorInt += aBlue << 16;
2800 aColorInt += anAlpha << 24;
2802 // setup colors array per vertex
2803 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2804 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2806 aColorArray->SetValue (aNodeId, aColorInt);
2808 aShape->SetColors (aColorArray);
2811 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2812 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2813 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2814 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2815 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2816 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2817 aTotalSize >>= 20; //MB
2818 aNormalsSize >>= 20;
2820 aTrianglesSize >>= 20;
2821 aPolyConnectSize >>= 20;
2822 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2823 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2824 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2825 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2826 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2827 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2829 // Setting material properties, very important for desirable visual result!
2830 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2831 aMat.SetAmbient (0.2);
2832 aMat.SetSpecular (0.5);
2833 Handle(Graphic3d_AspectFillArea3d) anAspect
2834 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2836 Quantity_NOC_YELLOW,
2841 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2844 anAspect->SetEdgeOn();
2848 anAspect->SetEdgeOff();
2850 aShAsp->SetAspect (anAspect);
2851 aShape->Attributes()->SetShadingAspect (aShAsp);
2853 VDisplayAISObject (aShapeName, aShape);
2857 //===============================================================================================
2858 //function : VClipPlane
2860 //===============================================================================================
2861 static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2863 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2864 Handle(V3d_View) aView = ViewerTest::CurrentView();
2865 Standard_Real coeffA, coeffB, coeffC, coeffD;
2866 if (aViewer.IsNull() || aView.IsNull())
2868 std::cout << "Viewer not initialized!\n";
2872 // count an active planes count
2873 Standard_Integer aNewPlaneId = 1;
2874 Standard_Integer anActivePlanes = 0;
2875 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
2877 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2878 if (aView->IsActivePlane (aPlaneV3d))
2886 // just show info about existing planes
2887 Standard_Integer aPlaneId = 1;
2888 std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
2889 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2891 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2892 aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
2893 gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
2894 const gp_Pnt& aLoc = aPlane.Location();
2895 const gp_Dir& aNor = aPlane.Axis().Direction();
2896 Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
2897 std::cout << "Plane #" << aPlaneId
2898 << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
2899 << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
2900 << (isActive ? " on" : " off")
2901 << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
2906 std::cout << "No defined clipping planes\n";
2910 else if (argc == 2 || argc == 3)
2912 Standard_Integer aPlaneIdToOff = (argc == 3) ? atoi (argv[1]) : 1;
2913 Standard_Boolean toIterateAll = (argc == 2);
2914 TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
2915 isOnOffStr.LowerCase();
2916 Standard_Integer aPlaneId = 1;
2917 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2919 if (aPlaneIdToOff == aPlaneId || toIterateAll)
2921 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2922 if (isOnOffStr.Search ("off") >= 0)
2924 aView->SetPlaneOff (aPlaneV3d);
2925 std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
2927 else if (isOnOffStr.Search ("on") >= 0)
2929 // avoid z-fighting glitches
2931 if (!aView->IsActivePlane (aPlaneV3d))
2933 if (anActivePlanes < aView->View()->PlaneLimit())
2935 aView->SetPlaneOn (aPlaneV3d);
2936 std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
2940 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2941 << "You should disable or remove some existing plane to activate this one\n";
2946 std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
2949 else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
2951 aPlaneV3d->Erase(); // not performed on destructor!!!
2952 aView->SetPlaneOff (aPlaneV3d);
2953 aViewer->DelPlane (aPlaneV3d);
2954 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2957 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
2959 aPlaneV3d = aViewer->DefinedPlane();
2960 aPlaneV3d->Erase(); // not performed on destructor!!!
2961 aView->SetPlaneOff (aPlaneV3d);
2962 aViewer->DelPlane (aPlaneV3d);
2963 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2972 else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
2974 // avoid z-fighting glitches
2975 aView->SetPlaneOff (aPlaneV3d);
2976 aPlaneV3d->Display (aView);
2977 std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
2979 else if (isOnOffStr.Search ("hide") >= 0)
2982 std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
2986 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2991 if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
2993 std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
3001 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
3005 Standard_Real aLocX = atof (argv[1]);
3006 Standard_Real aLocY = atof (argv[2]);
3007 Standard_Real aLocZ = atof (argv[3]);
3008 Standard_Real aNormDX = atof (argv[4]);
3009 Standard_Real aNormDY = atof (argv[5]);
3010 Standard_Real aNormDZ = atof (argv[6]);
3012 Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
3013 gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
3014 aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
3015 aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
3017 aViewer->AddPlane (aPlaneV3d); // add to defined planes list
3018 std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
3019 if (anActivePlanes < aView->View()->PlaneLimit())
3021 aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
3026 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
3027 << "You should disable or remove some existing plane to activate the new one\n";
3032 //=============================================================================
3033 //function : VComputeHLR
3035 //=============================================================================
3037 static int VComputeHLR (Draw_Interpretor& di,
3038 Standard_Integer argc,
3041 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3043 if (aContextAIS.IsNull ())
3045 di << "Please call vinit before\n";
3049 if ( argc != 3 && argc != 12 )
3051 di << "Usage: " << argv[0] << " ShapeName HlrName "
3052 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3053 << " ShapeName - name of the initial shape\n"
3054 << " HlrName - result hlr object from initial shape\n"
3055 << " eye, dir are eye position and look direction\n"
3056 << " up is the look up direction vector\n"
3057 << " Use vtop to see projected hlr shape\n";
3061 // shape and new object name
3062 TCollection_AsciiString aShapeName (argv[1]);
3063 TCollection_AsciiString aHlrName (argv[2]);
3065 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3068 BRep_Builder aBrepBuilder;
3069 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3072 di << "No shape with name " << argv[1] << " found\n";
3077 if (GetMapOfAIS ().IsBound2 (aHlrName))
3079 di << "Presentable object with name " << argv[2] << " already exists\n";
3083 // close local context
3084 if (aContextAIS->HasOpenedContext ())
3085 aContextAIS->CloseLocalContext ();
3087 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3088 HLRBRep_PolyHLRToShape aHLRToShape;
3097 anEye.SetCoord (atof (argv[3]), atof (argv[4]), atof (argv[5]));
3098 aDir.SetCoord (atof (argv[6]), atof (argv[7]), atof (argv[8]));
3099 anUp.SetCoord (atof (argv[9]), atof (argv[10]), atof (argv[11]));
3100 aProjAx.SetLocation (anEye);
3101 aProjAx.SetDirection (aDir);
3102 aProjAx.SetYDirection (anUp);
3108 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3109 Handle(V3d_View) aView = ViewerTest::CurrentView();
3110 Standard_Integer aWidth, aHeight;
3111 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3112 Standard_Real aRightX, aRightY, aRightZ;
3113 aView->Window()->Size (aWidth, aHeight);
3115 aView->ConvertWithProj (aWidth, aHeight/2,
3116 aRightX, aRightY, aRightZ,
3117 aDirX, aDirY, aDirZ);
3119 aView->ConvertWithProj (aWidth/2, aHeight/2,
3120 aCentX, aCentY, aCentZ,
3121 aDirX, aDirY, aDirZ);
3123 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3124 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3125 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3126 aProjAx.SetLocation (anEye);
3127 aProjAx.SetDirection (aDir);
3128 aProjAx.SetXDirection (aRight);
3131 HLRAlgo_Projector aProjector (aProjAx);
3132 aPolyAlgo->Projector (aProjector);
3133 aPolyAlgo->Load (aSh);
3134 aPolyAlgo->Update ();
3136 aHLRToShape.Update (aPolyAlgo);
3138 // make hlr shape from input shape
3139 TopoDS_Compound aHlrShape;
3140 BRep_Builder aBuilder;
3141 aBuilder.MakeCompound (aHlrShape);
3143 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3144 if (!aCompound.IsNull ())
3146 aBuilder.Add (aHlrShape, aCompound);
3149 // extract visible outlines
3150 aCompound = aHLRToShape.OutLineVCompound();
3151 if (!aCompound.IsNull ())
3153 aBuilder.Add (aHlrShape, aCompound);
3156 // create an AIS shape and display it
3157 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3158 GetMapOfAIS().Bind (anObject, aHlrName);
3159 aContextAIS->Display (anObject);
3161 aContextAIS->UpdateCurrentViewer ();
3166 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3167 // manipulating and displaying such an array with AIS context
3168 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3169 class MyPArrayObject : public AIS_InteractiveObject
3174 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray)
3179 DEFINE_STANDARD_RTTI(MyPArrayObject);
3183 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3184 const Handle(Prs3d_Presentation)& aPresentation,
3185 const Standard_Integer aMode);
3187 void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
3188 const Standard_Integer aMode) {};
3192 Handle(Graphic3d_ArrayOfPrimitives) myArray;
3196 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3197 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3199 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3200 const Handle(Prs3d_Presentation)& aPresentation,
3201 const Standard_Integer aMode)
3203 aPresentation->Clear();
3205 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
3206 aGroup->BeginPrimitives ();
3207 aGroup->AddPrimitiveArray (myArray);
3208 aGroup->EndPrimitives ();
3211 static bool CheckInputCommand (const TCollection_AsciiString theCommand,
3212 const char **theArgStr, int &theArgIndex,
3213 int theArgCount, int theMaxArgs)
3215 // check if there is more elements than expected
3216 if (theArgIndex >= theMaxArgs)
3219 TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
3220 aStrCommand.LowerCase();
3221 if (aStrCommand.Search(theCommand) != 1 ||
3222 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3225 // go to the first data element
3228 // check data if it can be converted to numeric
3229 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3231 aStrCommand = theArgStr[theArgIndex];
3232 if (!aStrCommand.IsRealValue())
3239 //=============================================================================
3240 //function : VDrawPArray
3241 //purpose : Draws primitives array from list of vertexes, bounds, edges
3242 //=============================================================================
3244 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3246 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3247 if (aContextAIS.IsNull())
3249 di << "Call vinit before!\n";
3254 di << "Use: " << argv[0] << " Name TypeOfArray"
3255 << " [vertex] ... [bounds] ... [edges]\n"
3256 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3257 << " trianglefans | trianglestrips | quads |\n"
3258 << " quadstrips | polygons }\n"
3259 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3260 << " [texel={ 't' tx ty }] } \n"
3261 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3262 << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
3266 // read the arguments
3267 Standard_Integer aArgIndex = 1;
3268 TCollection_AsciiString aName (argv[aArgIndex++]);
3269 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3270 const Standard_Integer anArgsFrom = aArgIndex;
3272 // parse number of verticies, bounds, edges
3273 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3274 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3275 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3277 TCollection_AsciiString aCommand;
3278 while (aArgIndex < argc)
3280 aCommand = argv[aArgIndex];
3281 aCommand.LowerCase();
3282 if (!aCommand.IsAscii())
3284 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3285 << "should be an array element: 'v', 'b', 'e' \n";
3290 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3292 // vertex has a normal or normal with color or texel
3293 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3294 hasNormals = Standard_True;
3296 // vertex has a color
3297 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3298 hasVColors = Standard_True;
3300 // vertex has a texel
3301 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3302 hasTexels = Standard_True;
3307 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3310 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3311 hasBColors = Standard_True;
3316 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3318 // edge has a hide flag
3319 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3320 hasInfos = Standard_True;
3329 if (aVertexNum == 0)
3331 di << "You should pass any verticies in the list of array elements\n";
3335 // create an array of primitives by types
3336 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3337 if (anArrayType == "points")
3338 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3339 else if (anArrayType == "segments")
3340 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3341 else if (anArrayType == "polylines")
3342 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3343 hasVColors, hasBColors, hasInfos);
3344 else if (anArrayType == "triangles")
3345 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3346 hasVColors, hasTexels, hasInfos);
3347 else if (anArrayType == "trianglefans")
3348 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3349 hasNormals, hasVColors,
3350 hasBColors, hasTexels);
3351 else if (anArrayType == "trianglestrips")
3352 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3353 hasNormals, hasVColors,
3354 hasBColors, hasTexels);
3355 else if (anArrayType == "quads")
3356 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3357 hasNormals, hasVColors,
3358 hasTexels, hasInfos);
3359 else if (anArrayType == "quadstrips")
3360 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3361 hasNormals, hasVColors,
3362 hasBColors, hasTexels);
3363 else if (anArrayType == "polygons")
3364 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3365 hasNormals, hasVColors, hasBColors,
3366 hasTexels, hasInfos);
3369 di << "Unexpected type of primitiives array\n";
3373 // parse an array of primitives
3374 aArgIndex = anArgsFrom;
3375 while (aArgIndex < argc)
3377 aCommand = argv[aArgIndex];
3378 aCommand.LowerCase();
3379 if (!aCommand.IsAscii())
3383 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3385 anArray->AddVertex (atof (argv[aArgIndex - 3]),
3386 atof (argv[aArgIndex - 2]),
3387 atof (argv[aArgIndex - 1]));
3389 // vertex has a normal or normal with color or texel
3390 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3391 anArray->SetVertexNormal (anArray->VertexNumber (),
3392 atof (argv[aArgIndex - 3]),
3393 atof (argv[aArgIndex - 2]),
3394 atof (argv[aArgIndex - 1]));
3396 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3397 anArray->SetVertexColor (anArray->VertexNumber (),
3398 atof (argv[aArgIndex - 3]),
3399 atof (argv[aArgIndex - 2]),
3400 atof (argv[aArgIndex - 1]));
3402 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3403 anArray->SetVertexTexel (anArray->VertexNumber (),
3404 atof (argv[aArgIndex - 2]),
3405 atof (argv[aArgIndex - 1]));
3408 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3410 Standard_Integer aVertCount = atoi (argv[aArgIndex - 1]);
3412 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3413 anArray->AddBound (aVertCount,
3414 atof (argv[aArgIndex - 3]),
3415 atof (argv[aArgIndex - 2]),
3416 atof (argv[aArgIndex - 1]));
3419 anArray->AddBound (aVertCount);
3422 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3424 Standard_Integer aVertIndex = atoi (argv[aArgIndex - 1]);
3426 // edge has/hasn't hide flag
3427 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3428 anArray->AddEdge (aVertIndex, Standard_False);
3430 anArray->AddEdge (aVertIndex, Standard_True);
3437 // create primitives array object
3438 Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
3440 // register the object in map
3441 VDisplayAISObject (aName, aPObject);
3446 //=======================================================================
3447 //function : VSetLocation
3448 //purpose : Change location of AIS interactive object
3449 //=======================================================================
3451 static Standard_Integer VSetLocation (Draw_Interpretor& di,
3452 Standard_Integer argc,
3455 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3456 if (aContext.IsNull())
3458 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3464 di << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
3468 TCollection_AsciiString aName (argv[1]);
3469 Standard_Real aX = atof (argv[2]);
3470 Standard_Real aY = atof (argv[3]);
3471 Standard_Real aZ = atof (argv[4]);
3474 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3475 Handle(AIS_InteractiveObject) anIObj;
3476 if (!aMap.IsBound2 (aName))
3478 di << "Use 'vdisplay' before" << "\n";
3483 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3485 // not an AIS_InteractiveObject
3486 if (anIObj.IsNull())
3488 di << argv[1] << " : Not an AIS interactive object" << "\n";
3493 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
3494 TopLoc_Location aLocation (aTrsf);
3495 aContext->SetLocation (anIObj, aLocation);
3496 aContext->UpdateCurrentViewer();
3502 //===============================================================================================
3503 //function : VConnect
3504 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3505 //Draw arg : vconnect name object Xo Yo Zo Xu Xv Xw Zu Zv Zw
3506 //===============================================================================================
3508 static Standard_Integer VConnect(Draw_Interpretor& di,
3509 Standard_Integer argc,
3515 std::cout << "vconnect error: expect 11 argumnets\n";
3516 return 1; // TCL_ERROR
3519 TCollection_AsciiString aName(argv[1]);
3520 TCollection_AsciiString anOriginObjectName(argv[2]);
3521 if(aName.IsEqual(anOriginObjectName))
3523 std::cout << "vconnect error: equal names for connected objects\n";
3524 return 1; // TCL_ERROR
3526 // Check if the origin shape is not null
3527 Handle(AIS_InteractiveObject) anOriginObject;
3528 if(GetMapOfAIS().IsBound2(anOriginObjectName))
3530 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginObjectName);
3531 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3532 if(anOriginObject.IsNull())
3534 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n!";
3535 return 1; // TCL_ERROR
3539 // Get location data
3540 Standard_Real aXo = atof(argv[3]);
3541 Standard_Real aYo = atof(argv[4]);
3542 Standard_Real aZo = atof(argv[5]);
3543 Standard_Real aXu = atof(argv[6]);
3544 Standard_Real aXv = atof(argv[7]);
3545 Standard_Real aXw = atof(argv[8]);
3546 Standard_Real aZu = atof(argv[9]);
3547 Standard_Real aZv = atof(argv[10]);
3548 Standard_Real aZw = atof(argv[11]);
3550 // Create transformation
3551 gp_Pnt aPoint(aXo, aYo, aZo);
3552 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3553 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3555 std::cout << "vconnect error : XDir expects to be normal to ZDir\n";
3556 return 1; // TCL_ERROR
3558 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3560 aTrsf.SetTransformation(anAx3);
3561 TopLoc_Location aLocation(aTrsf);
3563 // Create connected object
3564 Handle(AIS_ConnectedInteractive) aConnectedObject = new AIS_ConnectedInteractive();
3565 aConnectedObject->Connect(anOriginObject, aLocation);
3567 // Check if there is another object with given name
3568 // and remove it from context
3569 if(GetMapOfAIS().IsBound2(aName))
3571 Handle(AIS_InteractiveObject) anObj =
3572 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3573 TheAISContext()->Remove(anObj, Standard_False);
3574 GetMapOfAIS().UnBind2(aName);
3577 // Bind connected object to its name
3578 GetMapOfAIS().Bind(aConnectedObject, aName);
3580 // Display connected object
3581 TheAISContext()->Display(aConnectedObject);
3586 //===============================================================================================
3587 //function : VConnectShape
3588 //purpose : Creates and displays AIS_ConnectedShape from input shape and location
3589 //Draw arg : vconnectsh name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw
3590 //===============================================================================================
3592 static Standard_Integer VConnectShape(Draw_Interpretor& di,
3593 Standard_Integer argc,
3599 std::cout << "vconnectsh error: expect 11 argumnets\n";
3600 return 1; // TCL_ERROR
3603 TCollection_AsciiString aName(argv[1]);
3604 TCollection_AsciiString anOriginShapeName(argv[2]);
3605 if(aName.IsEqual(anOriginShapeName))
3607 std::cout << "vconnectsh error: equal names for connected shapes\n";
3608 return 1; // TCL_ERROR
3610 // Check if the origin shape is not null
3611 Handle(AIS_InteractiveObject) anOriginShape;
3612 if(GetMapOfAIS().IsBound2(anOriginShapeName))
3614 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginShapeName);
3615 anOriginShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3616 if(anOriginShape.IsNull())
3618 std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
3619 return 1; // TCL_ERROR
3623 // Get location data
3624 Standard_Real aXo = atof(argv[3]);
3625 Standard_Real aYo = atof(argv[4]);
3626 Standard_Real aZo = atof(argv[5]);
3627 Standard_Real aXu = atof(argv[6]);
3628 Standard_Real aXv = atof(argv[7]);
3629 Standard_Real aXw = atof(argv[8]);
3630 Standard_Real aZu = atof(argv[9]);
3631 Standard_Real aZv = atof(argv[10]);
3632 Standard_Real aZw = atof(argv[11]);
3634 // Create transformation
3635 gp_Pnt aPoint(aXo, aYo, aZo);
3636 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3637 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3639 std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n";
3640 return 1; // TCL_ERROR
3642 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3644 aTrsf.SetTransformation(anAx3);
3645 TopLoc_Location aLocation(aTrsf);
3647 // Create connected shape
3648 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anOriginShape);
3649 Handle(AIS_ConnectedShape) aConnectedShape = new AIS_ConnectedShape(aShape);
3650 aConnectedShape->Connect(anOriginShape, aLocation);
3652 // Check if there is another object with given name
3653 // and remove it from context
3654 if(GetMapOfAIS().IsBound2(aName))
3656 Handle(AIS_InteractiveObject) anObj =
3657 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3658 TheAISContext()->Remove(anObj, Standard_False);
3659 GetMapOfAIS().UnBind2(aName);
3662 // Bind connected shape to its name
3663 GetMapOfAIS().Bind(aConnectedShape, aName);
3665 // Display connected shape
3666 TheAISContext()->Display(aConnectedShape);
3671 //===============================================================================================
3672 //function : VSetSelectionMode
3673 //purpose : Sets input selection mode for input object or for all displayed objects
3674 //Draw arg : vselmode [object] mode On/Off (1/0)
3675 //===============================================================================================
3677 // function : InList
3678 // purpose : checks if theMode is already turned on for theObj
3679 Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext,
3680 Handle(AIS_InteractiveObject) theObj,
3681 Standard_Integer theMode)
3683 TColStd_ListOfInteger anArray;
3684 theAISContext->ActivatedModes(theObj, anArray);
3685 TColStd_ListIteratorOfListOfInteger anIt(anArray);
3686 for(; anIt.More(); anIt.Next())
3688 if(anIt.Value() == theMode)
3689 return Standard_True;
3691 return Standard_False;
3694 static Standard_Integer VSetSelectionMode(Draw_Interpretor& di,
3695 Standard_Integer argc,
3699 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3700 if(anAISContext.IsNull())
3702 std::cout << "Call vinit before!\n";
3703 return 1; // TCL_ERROR
3706 // Check the arguments
3707 if(argc != 3 && argc != 4)
3709 std::cout << "vselmode error : expects at least 2 arguments\n";
3710 return 1; // TCL_ERROR
3713 Handle(AIS_InteractiveObject) anObj;
3715 // Set new selection mode for all objects in context
3719 Standard_Integer aMode = atoi(argv[1]);
3720 Standard_Boolean isTurnOn = atoi(argv[2]);
3722 // Get all displayed objects
3723 AIS_ListOfInteractive anObjList;
3724 anAISContext->DisplayedObjects(anObjList);
3725 AIS_ListIteratorOfListOfInteractive anObjIter;
3729 if(anAISContext->HasOpenedContext())
3730 anAISContext->CloseLocalContext();
3734 if(aMode != 0 && isTurnOn)
3736 if(!anAISContext->HasOpenedContext())
3738 anAISContext->OpenLocalContext();
3739 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3741 anAISContext->Activate(anObjIter.Value(), aMode);
3746 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3748 anObj = anObjIter.Value();
3749 if(!InList(anAISContext, anObj, aMode))
3750 anAISContext->Activate(anObj, aMode);
3756 if(aMode != 0 && !isTurnOn)
3758 if(anAISContext->HasOpenedContext())
3760 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3762 anObj = anObjIter.Value();
3763 if(InList(anAISContext, anObj, aMode))
3764 anAISContext->Deactivate(anObj, aMode);
3770 // Set new selection mode for named object
3774 Standard_Integer aMode = atoi(argv[2]);
3775 Standard_Boolean isTurnOn = atoi(argv[3]);
3776 TCollection_AsciiString aName(argv[1]);
3778 // Check if there is an object with given name in context
3779 if(GetMapOfAIS().IsBound2(aName))
3781 anObj = Handle(AIS_InteractiveObject)::
3782 DownCast(GetMapOfAIS().Find2(aName));
3785 std::cout << "vselmode error : object name is used for non AIS viewer\n";
3786 return 1; // TCL_ERROR
3792 if(anAISContext->HasOpenedContext())
3793 anAISContext->CloseLocalContext();
3796 if(aMode != 0 && isTurnOn)
3798 if(!anAISContext->HasOpenedContext())
3800 anAISContext->OpenLocalContext();
3801 anAISContext->Activate(anObj, aMode);
3805 if(!InList(anAISContext, anObj, aMode))
3806 anAISContext->Activate(anObj, aMode);
3811 if(aMode != 0 && !isTurnOn)
3813 if(anAISContext->HasOpenedContext())
3815 if(InList(anAISContext, anObj, aMode))
3816 anAISContext->Deactivate(anObj, aMode);
3823 //==========================================================================
3825 //purpose : creates Triangle based on AIS_InteractiveObject.
3826 // This class was implemented for testing Select3D_SensitiveTriangle
3827 //===========================================================================
3828 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3829 class Triangle: public AIS_InteractiveObject
3833 DEFINE_STANDARD_RTTI(FilledCircle);
3834 Triangle (const gp_Pnt& theP1,
3835 const gp_Pnt& theP2,
3836 const gp_Pnt& theP3);
3838 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3839 const Handle(Prs3d_Presentation)& thePresentation,
3840 const Standard_Integer theMode);
3842 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
3843 const Standard_Integer theMode);
3849 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3850 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
3852 Triangle::Triangle (const gp_Pnt& theP1,
3853 const gp_Pnt& theP2,
3854 const gp_Pnt& theP3)
3861 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3862 const Handle(Prs3d_Presentation)& thePresentation,
3863 const Standard_Integer theMode)
3865 thePresentation->Clear();
3867 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
3868 anEdgeMaker2(myPoint2, myPoint3),
3869 anEdgeMaker3(myPoint3, myPoint1);
3871 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
3872 anEdge2 = anEdgeMaker2.Edge(),
3873 anEdge3 = anEdgeMaker3.Edge();
3874 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
3877 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
3878 TopoDS_Wire aWire = aWireMaker.Wire();
3879 if(aWire.IsNull()) return;
3881 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
3882 TopoDS_Face aFace = aFaceMaker.Face();
3883 if(aFace.IsNull()) return;
3885 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
3888 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
3889 const Standard_Integer theMode)
3891 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
3892 Handle(Select3D_SensitiveTriangle) aSensTriangle =
3893 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
3894 theSelection->Add(aSensTriangle);
3897 //===========================================================================
3898 //function : VTriangle
3899 //Draw arg : vtriangle Name PointName PointName PointName
3900 //purpose : creates and displays Triangle
3901 //===========================================================================
3904 //purpose : checks if the object with theName is AIS_Point,
3905 // if yes initialize thePoint from MapOfAIS
3906 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
3907 Handle(AIS_Point)& thePoint)
3909 Handle(AIS_InteractiveObject) anObject =
3910 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
3911 if(anObject.IsNull() ||
3912 anObject->Type() != AIS_KOI_Datum ||
3913 anObject->Signature() != 1)
3915 return Standard_False;
3917 thePoint = Handle(AIS_Point)::DownCast(anObject);
3918 if(thePoint.IsNull())
3919 return Standard_False;
3920 return Standard_True;
3924 //purpose: checks if thePoint1 is equal to thePoint2
3925 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
3926 const Handle(Geom_CartesianPoint)& thePoint2)
3928 if(abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
3929 abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
3930 abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
3932 return Standard_True;
3934 return Standard_False;
3937 static Standard_Integer VTriangle (Draw_Interpretor& di,
3938 Standard_Integer argc,
3944 std::cout<<"vtriangle error: expects 4 argumnets\n";
3945 return 1; // TCL_ERROR
3948 TheAISContext()->CloseAllContexts();
3950 // Get and check values
3951 TCollection_AsciiString aName(argv[1]);
3953 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
3954 if (!IsPoint(argv[2], aPoint1))
3956 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
3957 return 1; // TCL_ERROR
3959 if (!IsPoint(argv[3], aPoint2))
3961 std::cout<<"vtriangle error: the 3d argument must be a point\n";
3962 return 1; // TCL_ERROR
3964 if (!IsPoint(argv[4], aPoint3))
3966 std::cout<<"vtriangle error: the 4th argument must be a point\n";
3967 return 1; // TCL_ERROR
3970 // Check that points are different
3971 Handle(Geom_CartesianPoint) aCartPoint1 =
3972 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
3973 Handle(Geom_CartesianPoint) aCartPoint2 =
3974 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
3975 // Test aPoint1 = aPoint2
3976 if (IsMatch(aCartPoint1, aCartPoint2))
3978 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
3979 return 1; // TCL_ERROR
3981 // Test aPoint2 = aPoint3
3982 Handle(Geom_CartesianPoint) aCartPoint3 =
3983 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
3984 if (IsMatch(aCartPoint2, aCartPoint3))
3986 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
3987 return 1; // TCL_ERROR
3989 // Test aPoint3 = aPoint1
3990 if (IsMatch(aCartPoint1, aCartPoint3))
3992 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
3993 return 1; // TCL_ERROR
3997 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
3999 aCartPoint3->Pnt());
4001 // Check if there is an object with given name
4002 // and remove it from context
4003 if (GetMapOfAIS().IsBound2(aName))
4005 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4006 Handle(AIS_InteractiveObject) anInterObj =
4007 Handle(AIS_InteractiveObject)::DownCast(anObj);
4008 TheAISContext()->Remove(anInterObj, Standard_False);
4009 GetMapOfAIS().UnBind2(aName);
4012 // Bind triangle to its name
4013 GetMapOfAIS().Bind(aTriangle, aName);
4016 TheAISContext()->Display(aTriangle);
4020 //class : SegmentObject
4021 //purpose: creates segment based on AIS_InteractiveObject.
4022 // This class was implemented for testing Select3D_SensitiveCurve
4023 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4024 class SegmentObject: public AIS_InteractiveObject
4028 DEFINE_STANDARD_RTTI(SegmentObject);
4029 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4031 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4032 const Handle(Prs3d_Presentation)& thePresentation,
4033 const Standard_Integer theMode);
4035 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4036 const Standard_Integer theMode);
4041 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4042 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4044 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4050 void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
4051 const Handle_Prs3d_Presentation &thePresentation,
4052 const Standard_Integer theMode)
4054 thePresentation->Clear();
4055 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4056 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4057 if (anEdge.IsNull())
4059 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4060 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4063 void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
4064 const Standard_Integer theMode)
4066 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4067 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4068 anArray->SetValue(1, myPoint1);
4069 anArray->SetValue(2, myPoint2);
4070 Handle(Select3D_SensitiveCurve) aSensCurve =
4071 new Select3D_SensitiveCurve(anOwner, anArray);
4072 theSelection->Add(aSensCurve);
4075 //=======================================================================
4076 //function : VSegment
4077 //Draw args : vsegment Name PointName PointName
4078 //purpose : creates and displays Segment
4079 //=======================================================================
4080 static Standard_Integer VSegment (Draw_Interpretor& di,
4081 Standard_Integer argc,
4087 std::cout<<"vsegment error: expects 3 arguments\n";
4088 return 1; // TCL_ERROR
4091 TheAISContext()->CloseAllContexts();
4093 // Get and check arguments
4094 TCollection_AsciiString aName(argv[1]);
4095 Handle(AIS_Point) aPoint1, aPoint2;
4096 if (!IsPoint(argv[2], aPoint1))
4098 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4099 return 1; // TCL_ERROR
4101 if (!IsPoint(argv[3], aPoint2))
4103 std::cout<<"vsegment error: the 3d argument should be a point\n";
4104 return 1; // TCL_ERROR
4106 //Check that points are different
4107 Handle(Geom_CartesianPoint) aCartPoint1 =
4108 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4109 Handle(Geom_CartesianPoint) aCartPoint2 =
4110 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4111 if(IsMatch(aCartPoint1, aCartPoint2))
4113 std::cout<<"vsegment error: equal points\n";
4114 return 1; // TCL_ERROR
4118 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4119 // Check if there is an object with given name
4120 // and remove it from context
4121 if (GetMapOfAIS().IsBound2(aName))
4123 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4124 Handle(AIS_InteractiveObject) anInterObj =
4125 Handle(AIS_InteractiveObject)::DownCast(anObj);
4126 TheAISContext()->Remove(anInterObj, Standard_False);
4127 GetMapOfAIS().UnBind2(aName);
4130 // Bind segment to its name
4131 GetMapOfAIS().Bind(aSegment, aName);
4134 TheAISContext()->Display(aSegment);
4138 //=======================================================================
4139 //function : VObjZLayer
4140 //purpose : Set or get z layer id for presentable object
4141 //=======================================================================
4143 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4144 Standard_Integer argc,
4147 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4148 if (aContext.IsNull())
4150 di << argv[0] << "Call 'vinit' before!\n";
4155 TCollection_AsciiString aOperation;
4157 aOperation = TCollection_AsciiString (argv [1]);
4159 // check for correct arguments
4160 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4161 !(argc == 3 && aOperation.IsEqual ("get")))
4163 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4164 di << " set - set layer id for interactive object, layerid - z layer id\n";
4165 di << " get - get layer id of interactive object\n";
4166 di << " argument layerid should be passed for set operation only\n";
4171 TCollection_AsciiString aName (argv[2]);
4172 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4173 if (!aMap.IsBound2 (aName))
4175 di << "Use 'vdisplay' before" << "\n";
4179 // find interactive object
4180 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4181 Handle(AIS_InteractiveObject) anInterObj =
4182 Handle(AIS_InteractiveObject)::DownCast (anObj);
4183 if (anInterObj.IsNull())
4185 di << "Not an AIS interactive object!\n";
4189 // process operation
4190 if (aOperation.IsEqual ("set"))
4192 Standard_Integer aLayerId = atoi (argv [3]);
4193 aContext->SetZLayer (anInterObj, aLayerId);
4195 else if (aOperation.IsEqual ("get"))
4197 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4203 //=======================================================================
4204 //function : VPolygonOffset
4205 //purpose : Set or get polygon offset parameters
4206 //=======================================================================
4207 static Standard_Integer VPolygonOffset(Draw_Interpretor& di,
4208 Standard_Integer argc,
4211 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4212 if (aContext.IsNull())
4214 std::cout << argv[0] << " Call 'vinit' before!\n";
4218 if (argc > 2 && argc != 5)
4220 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4221 "without arguments prints the default values" << std::endl;
4226 Handle(AIS_InteractiveObject) anInterObj;
4229 TCollection_AsciiString aName (argv[1]);
4230 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4231 if (!aMap.IsBound2 (aName))
4233 std::cout << "Use 'vdisplay' before" << std::endl;
4237 // find interactive object
4238 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4239 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4240 if (anInterObj.IsNull())
4242 std::cout << "Not an AIS interactive object!" << std::endl;
4247 Standard_Integer aMode;
4248 Standard_ShortReal aFactor, aUnits;
4251 aMode = atoi(argv[2]);
4252 aFactor = (Standard_ShortReal) atof(argv[3]);
4253 aUnits = (Standard_ShortReal) atof(argv[4]);
4255 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4256 aContext->UpdateCurrentViewer();
4261 if (anInterObj->HasPolygonOffsets())
4263 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4264 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4265 std::cout << "\tMode: " << aMode << std::endl;
4266 std::cout << "\tFactor: " << aFactor << std::endl;
4267 std::cout << "\tUnits: " << aUnits << std::endl;
4272 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4276 std::cout << "Default polygon offset parameters:" << std::endl;
4277 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4278 std::cout << "\tMode: " << aMode << std::endl;
4279 std::cout << "\tFactor: " << aFactor << std::endl;
4280 std::cout << "\tUnits: " << aUnits << std::endl;
4285 //=======================================================================
4286 //function : ObjectsCommands
4288 //=======================================================================
4290 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
4292 const char *group ="AISObjects";
4293 theCommands.Add("vtrihedron",
4294 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
4295 __FILE__,VTrihedron,group);
4297 theCommands.Add("vtri2d",
4298 "vtri2d Name Selection in the viewer only ",
4299 __FILE__,VTrihedron2D ,group);
4301 theCommands.Add("vplanetri",
4302 "vplanetri Name Selection in the viewer only ",
4303 __FILE__,VPlaneTrihedron ,group);
4305 theCommands.Add("vsize",
4306 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
4307 __FILE__,VSize,group);
4309 theCommands.Add("vaxis",
4310 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
4311 __FILE__,VAxisBuilder,group);
4313 theCommands.Add("vaxispara",
4315 __FILE__,VAxisBuilder,group);
4317 theCommands.Add("vaxisortho",
4319 __FILE__,VAxisBuilder,group);
4321 theCommands.Add("vpoint",
4322 "vpoint PointName [Xa] [Ya] [Za] ",
4323 __FILE__,VPointBuilder,group);
4325 theCommands.Add("vplane",
4326 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
4327 __FILE__,VPlaneBuilder,group);
4329 theCommands.Add("vplanepara",
4330 "vplanepara PlaneName ",
4331 __FILE__,VPlaneBuilder,group);
4333 theCommands.Add("vplaneortho",
4334 "vplaneortho PlaneName ",
4335 __FILE__,VPlaneBuilder,group);
4337 theCommands.Add("vline",
4338 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
4339 __FILE__,VLineBuilder,group);
4341 theCommands.Add("vcircle",
4342 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
4343 __FILE__,VCircleBuilder,group);
4345 theCommands.Add("vdrawtext",
4346 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
4347 __FILE__,VDrawText,group);
4349 theCommands.Add("vdrawsphere",
4350 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n",
4351 __FILE__,VDrawSphere,group);
4353 theCommands.Add("vclipplane",
4354 "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
4355 __FILE__,VClipPlane,group);
4357 theCommands.Add ("vsetlocation",
4358 "vsetlocation : name x y z; set new location for an interactive object",
4359 __FILE__, VSetLocation, group);
4363 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
4364 __FILE__, VComputeHLR, group);
4366 theCommands.Add("vdrawparray",
4367 "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]",
4368 __FILE__,VDrawPArray,group);
4370 theCommands.Add("vconnect",
4371 "vconnect : name object Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4372 __FILE__, VConnect, group);
4374 theCommands.Add("vconnectsh",
4375 "vconnectsh : name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4376 __FILE__, VConnectShape, group);
4378 theCommands.Add("vselmode",
4379 "vselmode : [object] mode On/Off (1/0)",
4380 __FILE__, VSetSelectionMode, group);
4382 theCommands.Add("vtriangle",
4383 "vtriangle Name PointName PointName PointName",
4384 __FILE__, VTriangle,group);
4386 theCommands.Add("vsegment",
4387 "vsegment Name PointName PointName",
4388 __FILE__, VSegment,group);
4390 theCommands.Add("vobjzlayer",
4391 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
4392 __FILE__, VObjZLayer, group);
4394 theCommands.Add("vpolygonoffset",
4395 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
4396 __FILE__, VPolygonOffset, group);