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 #include <Prs3d_LineAspect.hxx>
143 #ifdef HAVE_STRINGS_H
148 #define _CRT_SECURE_NO_DEPRECATE
149 #pragma warning (disable:4996)
152 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
153 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
154 const Handle(AIS_InteractiveObject)& theAISObj,
155 Standard_Boolean theReplaceIfExists = Standard_True);
156 Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv);
157 extern Handle(AIS_InteractiveContext)& TheAISContext();
160 //==============================================================================
161 //function : Vtrihedron 2d
162 //purpose : Create a plane with a 2D trihedron from a faceselection
163 //Draw arg : vtri2d name
164 //==============================================================================
165 #include <AIS_PlaneTrihedron.hxx>
169 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
172 // Verification des arguments
173 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
176 Standard_Integer myCurrentIndex;
177 // Fermeture des contextes
178 TheAISContext()->CloseAllContexts();
179 // Ouverture d'un contexte local et recuperation de son index.
180 TheAISContext()->OpenLocalContext();
181 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
182 // On active les modes de selections faces.
183 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
184 di<<" Select a face ."<<"\n";
186 // Boucle d'attente waitpick.
187 Standard_Integer argccc = 5;
188 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
189 const char **argvvv = (const char **) bufff;
190 while (ViewerMainLoop( argccc, argvvv) ) { }
194 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
195 ShapeB = TheAISContext()->SelectedShape();
198 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
200 // Construction du Plane
201 // recuperation des edges des faces.
202 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
204 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
208 // si il y a plusieurs edges
209 if (FaceExpB.More() ) {
211 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
212 BRepAdaptor_Curve theCurveB(EdgeB);
213 BRepAdaptor_Curve theCurveC(EdgeC);
214 A=theCurveC.Value(0.1);
215 B=theCurveC.Value(0.9);
216 C=theCurveB.Value(0.5);
219 // FaceB a 1 unique edge courbe
220 BRepAdaptor_Curve theCurveB(EdgeB);
221 A=theCurveB.Value(0.1);
222 B=theCurveB.Value(0.9);
223 C=theCurveB.Value(0.5);
225 // Construction du Geom_Plane
226 GC_MakePlane MkPlane(A,B,C);
227 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
229 // Construction de l'AIS_PlaneTrihedron
230 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
232 // Fermeture du contexte local.
233 TheAISContext()->CloseLocalContext(myCurrentIndex);
235 // on le display & bind
236 TheAISContext()->Display(theAISPlaneTri );
237 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
244 //==============================================================================
245 //function : VTriherdron
247 //purpose : Create a trihedron. If no arguments are set, the default
248 // trihedron (Oxyz) is created.
249 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
250 //==============================================================================
252 static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
255 // Verification des arguments
256 if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
258 // Declarations et creation des objets par default
259 TCollection_AsciiString name=argv[1];
261 if(argc > 5 && argc!=11)
262 {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
264 // Cas ou il y a des arguments
265 Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.};
269 coord[i]= atof(argv[2+i]);
273 coord[3+i] = atof(argv[6+i]);
274 coord[6+i] = atof(argv[8+i]);
278 gp_Pnt ThePoint(coord[0],coord[1],coord[2]);
279 gp_Dir TheZVector(coord[3],coord[4],coord[5]);
280 gp_Dir TheXVector(coord[6],coord[7],coord[8]);
282 if ( !TheZVector.IsNormal(TheXVector,M_PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;}
284 Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector);
286 // Creation du triedre
287 Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii);
288 GetMapOfAIS().Bind(aShape,name);
289 TheAISContext()->Display(aShape);
297 //==============================================================================
300 //purpose : Change the size of a named or selected trihedron
301 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
302 // if no value, the value is set at 100 by default
303 //Draw arg : vsize [name] [size]
304 //==============================================================================
306 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
309 // Declaration de booleens
310 Standard_Boolean ThereIsName;
311 Standard_Boolean ThereIsCurrent;
313 Standard_Boolean hascol;
315 Quantity_NameOfColor col;
317 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
320 // Verification des arguments
321 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
323 // Verification du nombre d'arguments
324 if (argc==1) {ThereIsName=Standard_False;value=100;}
325 else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);}
326 else {ThereIsName=Standard_True;value=atof(argv[2]);}
328 // On ferme le contexte local pour travailler dans le contexte global
329 if(TheAISContext()->HasOpenedContext())
330 TheAISContext()->CloseLocalContext();
332 // On set le booleen ThereIsCurrent
333 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
334 else {ThereIsCurrent=Standard_False;}
338 //===============================================================
339 // Il n'y a pas de nom mais des objets selectionnes
340 //===============================================================
341 if (!ThereIsName && ThereIsCurrent)
344 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
347 while ( it.More() ) {
349 Handle(AIS_InteractiveObject) aShape=
350 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
352 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
355 // On verifie que l'AIS InteraciveObject selectionne est bien
357 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
359 if (aShape->HasColor()) {
360 hascol=Standard_True;
362 // On recupere la couleur de aShape
363 col=aShape->Color();}
365 else hascol=Standard_False;
367 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
368 // pour lui appliquer la methode SetSize()
369 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
371 // C'est bien un triedre,on chage sa valeur!
372 aTrihedron->SetSize(value);
374 // On donne la couleur au Trihedron
375 if(hascol) aTrihedron->SetColor(col);
376 else aTrihedron->UnsetColor();
379 // The trihedron hasn't be errased from the map
380 // so you just have to redisplay it
381 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
390 TheAISContext() ->UpdateCurrentViewer();
393 //===============================================================
394 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
395 //===============================================================
399 //===============================================================
400 // Il y a un nom de triedre passe en argument
401 //===============================================================
403 TCollection_AsciiString name=argv[1];
405 // on verifie que ce nom correspond bien a une shape
406 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
410 // on recupere la shape dans la map des objets displayes
411 Handle(AIS_InteractiveObject) aShape =
412 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
414 // On verifie que l'AIS InteraciveObject est bien
416 if (!aShape.IsNull() &&
417 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
420 if (aShape->HasColor()) {
421 hascol=Standard_True;
423 // On recupere la couleur de aShape
424 col=aShape->Color();}
426 else hascol=Standard_False;
428 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
429 // pour lui appliquer la methode SetSize()
430 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
432 // C'est bien un triedre,on chage sa valeur
433 aTrihedron->SetSize(value);
435 // On donne la couleur au Trihedron
436 if(hascol) aTrihedron->SetColor(col);
437 else aTrihedron->UnsetColor();
439 // The trihedron hasn't be errased from the map
440 // so you just have to redisplay it
441 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
443 TheAISContext() ->UpdateCurrentViewer();
451 //==============================================================================
453 //==============================================================================
454 //function : VPlaneTrihedron
455 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
456 //Draw arg : vplanetri name
457 //==============================================================================
458 #include <AIS_Plane.hxx>
462 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
465 // Verification des arguments
466 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
469 Standard_Integer myCurrentIndex;
470 // Fermeture des contextes locaux
471 TheAISContext()->CloseAllContexts();
473 // On recupere tous les trihedrons de la GetMapOfAIS()
474 // et on active le mode de selection par face.
475 // =================================================
477 // Ouverture d'un contexte local et recuperation de son index.
478 TheAISContext()->OpenLocalContext(Standard_False);
479 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
481 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
484 Handle(AIS_InteractiveObject) ShapeA =
485 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
486 // On verifie que c'est bien un trihedron
487 if (!ShapeA.IsNull() &&
488 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
490 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
491 // on le charge dans le contexte et on active le mode Plane.
492 TheAISContext()->Load(TrihedronA,0,Standard_False);
493 TheAISContext()->Activate(TrihedronA,3);
498 di<<" Select a plane."<<"\n";
499 // Boucle d'attente waitpick.
500 Standard_Integer argccc = 5;
501 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
502 const char **argvvv = (const char **) bufff;
503 while (ViewerMainLoop( argccc, argvvv) ) { }
506 Handle(AIS_InteractiveObject) theIOB;
507 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
508 theIOB = TheAISContext()->Interactive();
511 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
513 // Fermeture du contexte local.
514 TheAISContext()->CloseLocalContext(myCurrentIndex);
516 // on le display & bind
517 TheAISContext()->Display(PlaneB );
518 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
525 //==============================================================================
526 // Fonction First click 2de click
528 // vaxis vertex vertex
530 // vaxispara edge vertex
531 // vaxisortho edge Vertex
532 // vaxisinter Face Face
533 //==============================================================================
535 //==============================================================================
536 //function : VAxisBuilder
538 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
539 //==============================================================================
540 #include <TopoDS_Edge.hxx>
541 #include <TopoDS_Vertex.hxx>
542 #include <TopExp.hxx>
543 #include <Geom_Line.hxx>
545 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
548 Standard_Boolean HasArg;
549 TCollection_AsciiString name;
550 Standard_Integer MyCurrentIndex;
553 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
554 if (argc==8) HasArg=Standard_True;
555 else HasArg=Standard_False;
558 // Fermeture des contextes
559 TheAISContext()->CloseAllContexts();
561 // Cas ou il y a des arguments
562 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
564 Standard_Real coord[6];
565 for(Standard_Integer i=0;i<=5;i++){
566 coord[i]=atof(argv[2+i]);
568 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
570 gp_Vec myVect (p1,p2);
571 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
572 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
573 GetMapOfAIS().Bind (TheAxis,name);
574 TheAISContext()->Display(TheAxis);
580 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
581 if ( !strcasecmp(argv[0], "vaxis")) {
582 TheAISContext()->OpenLocalContext();
583 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
585 // Active le mode edge et le mode vertex
586 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
587 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
588 di<<" Select an edge or a vertex."<<"\n";
590 // Boucle d'attente waitpick.
591 Standard_Integer argcc = 5;
592 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
593 const char **argvv = (const char **) buff;
594 while (ViewerMainLoop( argcc, argvv) ) { }
597 // recuperation de la shape.
599 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
600 ShapeA = TheAISContext()->SelectedShape();
602 // recuperation de l'AIS_InteractiveObject
603 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
604 // down cast en AIS_Point si sig et type
605 // AIS_Point -> Geom_Pnt ....
607 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
608 // on desactive le mode edge
609 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
610 di<<" Select a different vertex."<<"\n";
614 // Boucle d'attente waitpick.
615 Standard_Integer argccc = 5;
616 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
617 const char **argvvv = (const char **) bufff;
618 while (ViewerMainLoop( argccc, argvvv) ) { }
620 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
621 ShapeB = TheAISContext()->SelectedShape();
625 } while(ShapeB.IsSame(ShapeA) );
627 // Fermeture du context local
628 TheAISContext()->CloseLocalContext(MyCurrentIndex);
630 // Construction de l'axe
631 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
632 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
635 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
636 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
637 GetMapOfAIS().Bind (TheAxis,name);
638 TheAISContext()->Display(TheAxis);
641 // Un unique edge (ShapeA) a ete picke
642 // Fermeture du context local
643 TheAISContext()->CloseLocalContext(MyCurrentIndex);
644 // Constuction de l'axe
645 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
647 TopExp::Vertices(ed,Va,Vb );
648 gp_Pnt A=BRep_Tool::Pnt(Va);
649 gp_Pnt B=BRep_Tool::Pnt(Vb);
652 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
653 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
654 GetMapOfAIS().Bind (TheAxis,name);
655 TheAISContext()->Display(TheAxis);
661 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
662 else if ( !strcasecmp(argv[0], "vaxispara")) {
664 TheAISContext()->OpenLocalContext();
665 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
667 // Active le mode edge
668 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
669 di<<" Select an edge."<<"\n";
671 // Boucle d'attente waitpick.
672 Standard_Integer argcc = 5;
673 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
674 const char **argvv = (const char **) buff;
675 while (ViewerMainLoop( argcc, argvv) ) { }
679 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
680 ShapeA = TheAISContext()->SelectedShape();
682 // Active le mode vertex et deactive edges
683 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
684 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
685 di<<" Select a vertex."<<"\n";
687 // Boucle d'attente waitpick.
688 Standard_Integer argccc = 5;
689 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
690 const char **argvvv = (const char **) bufff;
691 while (ViewerMainLoop( argccc, argvvv) ) { }
694 // On peut choisir un pnt sur l'edge
696 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
697 ShapeB = TheAISContext()->SelectedShape();
699 // Fermeture du context local
700 TheAISContext()->CloseLocalContext(MyCurrentIndex);
702 // Construction de l'axe
703 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
704 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
706 TopExp::Vertices(ed,Va,Vc );
707 gp_Pnt A=BRep_Tool::Pnt(Va);
708 gp_Pnt C=BRep_Tool::Pnt(Vc);
711 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
712 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
713 GetMapOfAIS().Bind (TheAxis,name);
714 TheAISContext()->Display(TheAxis);
718 // Fonction axisortho
720 TheAISContext()->OpenLocalContext();
721 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
723 // Active le mode edge
724 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
725 di<<" Select an edge."<<"\n";
727 // Boucle d'attente waitpick.
728 Standard_Integer argcc = 5;
729 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
730 const char **argvv = (const char **) buff;
731 while (ViewerMainLoop( argcc, argvv) ) { }
735 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
736 ShapeA = TheAISContext()->SelectedShape();
738 // Active le mode vertex et deactive edges
739 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
740 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
741 di<<" Slect a vertex."<<"\n";
743 // Boucle d'attente waitpick.
744 Standard_Integer argccc = 5;
745 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
746 const char **argvvv = (const char **) bufff;
747 while (ViewerMainLoop( argccc, argvvv) ) { }
750 // On peut choisir un pnt sur l'edge
752 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
753 ShapeB = TheAISContext()->SelectedShape();
755 // Fermeture du context local
756 TheAISContext()->CloseLocalContext(MyCurrentIndex);
758 // Construction de l'axe
759 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
760 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
762 TopExp::Vertices(ed,Va,Vc );
763 gp_Pnt A=BRep_Tool::Pnt(Va);
764 gp_Pnt C=BRep_Tool::Pnt(Vc);
765 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
768 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
769 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
770 GetMapOfAIS().Bind (TheAxis,name);
771 TheAISContext()->Display(TheAxis);
780 //==============================================================================
781 // Fonction First click Result
783 // vpoint vertex AIS_Point=Vertex
784 // edge AIS_Point=Middle of the edge
785 //==============================================================================
787 //==============================================================================
788 //function : VPointBuilder
789 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
790 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
791 //==============================================================================
792 #include <TopoDS_Edge.hxx>
793 #include <TopoDS_Vertex.hxx>
794 #include <TopExp.hxx>
795 #include <AIS_Point.hxx>
796 #include <Geom_CartesianPoint.hxx>
798 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
801 Standard_Boolean HasArg;
802 TCollection_AsciiString name;
803 Standard_Integer myCurrentIndex;
806 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
807 if (argc==5) HasArg=Standard_True;
808 else HasArg=Standard_False;
811 // Fermeture des contextes
812 TheAISContext()->CloseAllContexts();
814 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
816 Standard_Real thecoord[3];
817 for(Standard_Integer i=0;i<=2;i++)
818 thecoord[i]=atof(argv[2+i]);
819 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
820 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
821 GetMapOfAIS().Bind (myAISPoint,name);
822 TheAISContext()->Display(myAISPoint);
825 // Il n'a pas d'arguments
827 TheAISContext()->OpenLocalContext();
828 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
830 // Active le mode Vertex et Edges
831 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
832 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
833 di<<" Select a vertex or an edge(build the middle)"<<"\n";
835 // Boucle d'attente waitpick.
836 Standard_Integer argcc = 5;
837 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
838 const char **argvv = (const char **) buff;
839 while (ViewerMainLoop( argcc, argvv) ) { }
843 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
844 ShapeA= TheAISContext()->SelectedShape();
847 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
848 // Un vertex a ete selectionne
849 // Fermeture du context local
850 TheAISContext()->CloseLocalContext(myCurrentIndex);
852 // Construction du point
853 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
854 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
855 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
856 GetMapOfAIS().Bind(myAISPoint,name);
857 TheAISContext()->Display(myAISPoint);
860 // Un Edge a ete selectionne
861 // Fermeture du context local
862 TheAISContext()->CloseLocalContext(myCurrentIndex);
864 // Construction du point milieu de l'edge
865 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
866 TopoDS_Vertex myVertexA,myVertexB;
867 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
868 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
869 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
870 // M est le milieu de [AB]
871 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
872 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
873 GetMapOfAIS().Bind(myAISPointM,name);
874 TheAISContext()->Display(myAISPointM);
882 //==============================================================================
883 // Function 1st click 2de click 3de click
884 // vplane Vertex Vertex Vertex
888 // vplanepara Face Vertex
890 // vplaneortho Face Edge
892 //==============================================================================
894 //==============================================================================
895 //function : VPlaneBuilder
896 //purpose : Build an AIS_Plane from selected entities or Named AIS components
897 //Draw arg : vplane PlaneName [AxisName] [PointName]
898 // [PointName] [PointName] [PointName]
899 // [PlaneName] [PointName]
900 //==============================================================================
902 static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
903 Standard_Integer argc,
907 Standard_Boolean hasArg;
908 TCollection_AsciiString aName;
909 Standard_Integer aCurrentIndex;
912 if (argc<2 || argc>5 )
914 std::cout<<" Syntax error\n";
917 if (argc==5 || argc==4)
918 hasArg=Standard_True;
920 hasArg=Standard_False;
923 // Close all contexts
924 TheAISContext()->CloseAllContexts();
926 // There are some arguments
929 if (!GetMapOfAIS().IsBound2(argv[2] ))
931 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
934 // Get shape from map
935 Handle(AIS_InteractiveObject) aShapeA =
936 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
938 // The first argument is an AIS_Point
939 if (!aShapeA.IsNull() &&
940 aShapeA->Type()==AIS_KOI_Datum &&
941 aShapeA->Signature()==1)
943 // The second argument must also be an AIS_Point
944 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
946 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
949 // Get shape from map
950 Handle(AIS_InteractiveObject) aShapeB =
951 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
952 // If B is not an AIS_Point
953 if (aShapeB.IsNull() ||
954 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
956 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
959 // The third object is an AIS_Point
960 if (!GetMapOfAIS().IsBound2(argv[4]) )
962 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
965 // Get shape from map
966 Handle(AIS_InteractiveObject) aShapeC =
967 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
968 // If C is not an AIS_Point
969 if (aShapeC.IsNull() ||
970 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
972 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
976 // Treatment of objects A, B, C
977 // Downcast an AIS_IO to AIS_Point
978 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
979 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
980 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
982 Handle(Geom_CartesianPoint ) aCartPointA =
983 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
985 Handle(Geom_CartesianPoint ) aCartPointB =
986 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
988 Handle(Geom_CartesianPoint ) aCartPointC =
989 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
991 // Verification that the three points are different
992 if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
993 abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
994 abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
997 std::cout<<"vplane error: same points"<<"\n";return 1;
999 if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1000 abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1001 abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1004 std::cout<<"vplane error: same points"<<"\n";return 1;
1006 if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1007 abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1008 abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1011 std::cout<<"vplane error: same points"<<"\n";return 1;
1014 gp_Pnt A = aCartPointA->Pnt();
1015 gp_Pnt B = aCartPointB->Pnt();
1016 gp_Pnt C = aCartPointC->Pnt();
1018 // Construction of AIS_Plane
1019 GC_MakePlane MkPlane (A,B,C);
1020 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1021 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1022 GetMapOfAIS().Bind (anAISPlane,aName );
1023 TheAISContext()->Display(anAISPlane);
1026 // The first argument is an AIS_Axis
1027 // Creation of a plane orthogonal to the axis through a point
1028 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1029 // The second argument should be an AIS_Point
1030 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1032 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1035 // Get shape from map
1036 Handle(AIS_InteractiveObject) aShapeB =
1037 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1038 // If B is not an AIS_Point
1039 if (aShapeB.IsNull() ||
1040 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1042 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1046 // Treatment of objects A and B
1047 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1048 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1050 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1051 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1053 gp_Ax1 anAxis = aGeomLineA->Position();
1054 Handle(Geom_CartesianPoint) aCartPointB =
1055 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1057 gp_Dir D =anAxis.Direction();
1058 gp_Pnt B = aCartPointB->Pnt();
1060 // Construction of AIS_Plane
1061 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1062 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1063 GetMapOfAIS().Bind (anAISPlane,aName );
1064 TheAISContext()->Display(anAISPlane);
1067 // The first argumnet is an AIS_Plane
1068 // Creation of a plane parallel to the plane passing through the point
1069 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1071 // The second argument should be an AIS_Point
1072 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1074 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1077 // Get shape from map
1078 Handle(AIS_InteractiveObject) aShapeB =
1079 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1080 // B should be an AIS_Point
1081 if (aShapeB.IsNull() ||
1082 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1084 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1088 // Treatment of objects A and B
1089 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1090 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1092 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1093 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1095 Handle(Geom_CartesianPoint) aCartPointB =
1096 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1097 gp_Pnt B= aCartPointB->Pnt();
1099 // Construction of an AIS_Plane
1100 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1101 GetMapOfAIS().Bind (anAISPlane, aName);
1102 TheAISContext()->Display(anAISPlane);
1107 std::cout<<"vplane: error 1st object is not an AIS\n";
1111 // There are no arguments
1115 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1116 if (!strcasecmp(argv[0], "vplane"))
1118 TheAISContext()->OpenLocalContext();
1119 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1121 // Active modes Vertex, Edge and Face
1122 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1123 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1124 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1125 std::cout<<"Select a vertex, a face or an edge\n";
1128 Standard_Integer argcc = 5;
1129 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1130 const char **argvv = (const char **) buff;
1131 while (ViewerMainLoop( argcc, argvv) ) { }
1134 TopoDS_Shape aShapeA;
1135 for (TheAISContext()->InitSelected();
1136 TheAISContext()->MoreSelected();
1137 TheAISContext()->NextSelected())
1139 aShapeA = TheAISContext()->SelectedShape();
1142 // aShapeA is a Vertex
1143 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1145 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1146 std::cout<<" Select an edge or a different vertex\n";
1149 Standard_Integer argccc = 5;
1150 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1151 const char **argvvv = (const char **) bufff;
1152 while (ViewerMainLoop( argccc, argvvv) ) { }
1155 TopoDS_Shape aShapeB;
1156 for (TheAISContext()->InitSelected();
1157 TheAISContext()->MoreSelected();
1158 TheAISContext()->NextSelected())
1160 aShapeB = TheAISContext()->SelectedShape();
1162 // aShapeB is a Vertex
1163 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1165 // A and B are the same
1166 if (aShapeB.IsSame(aShapeA))
1168 std::cout<<" vplane: error, same points selected\n";
1171 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1172 std::cout<<" Select a different vertex\n";
1175 Standard_Integer argcccc = 5;
1176 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1177 const char **argvvvv = (const char **) buffff;
1178 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1181 TopoDS_Shape aShapeC;
1182 for (TheAISContext()->InitSelected();
1183 TheAISContext()->MoreSelected();
1184 TheAISContext()->NextSelected())
1186 aShapeC = TheAISContext()->SelectedShape();
1188 // aShapeC is the same as A or B
1189 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1191 std::cout<<" vplane: error, same points selected\n";
1195 // Close the local context
1196 TheAISContext()->CloseLocalContext(aCurrentIndex);
1198 // Construction of plane
1199 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1200 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1201 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1202 GC_MakePlane MkPlane(A, B, C);
1203 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1204 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1205 GetMapOfAIS().Bind (anAISPlane, aName);
1206 TheAISContext()->Display(anAISPlane);
1208 // ShapeB is an edge
1211 // Verify that the vertex is not on the edge ShapeB
1212 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1213 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1215 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1216 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1218 // The vertex is on the edge
1219 std::cout<<" vplane: error point is on the edge\n";
1224 // Close the local context
1225 TheAISContext()->CloseLocalContext(aCurrentIndex);
1226 // Construction of plane
1227 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1228 TopoDS_Vertex aVBa, aVBb;
1229 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1230 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1231 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1232 GC_MakePlane MkPlane (A, aBa, aBb);
1233 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1234 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1235 GetMapOfAIS().Bind (anAISPlane, aName);
1236 TheAISContext()->Display(anAISPlane);
1240 // aShapeA is an edge
1241 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1243 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1244 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1245 std::cout<<" Select a vertex that don't belong to the edge\n";
1248 Standard_Integer argccc = 5;
1249 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1250 const char **argvvv = (const char **) bufff;
1251 while (ViewerMainLoop( argccc, argvvv) ) { }
1254 TopoDS_Shape aShapeB;
1255 for (TheAISContext()->InitSelected();
1256 TheAISContext()->MoreSelected();
1257 TheAISContext()->NextSelected())
1259 aShapeB = TheAISContext()->SelectedShape();
1261 // aShapeB should be a Vertex
1262 // Check that the vertex aShapeB is not on the edge
1263 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1264 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1266 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1267 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1269 // The vertex is on the edge
1270 std::cout<<" vplane: error point is on the edge\n";
1275 // Close the local context
1276 TheAISContext()->CloseLocalContext(aCurrentIndex);
1277 // Construction of plane
1278 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1279 TopoDS_Vertex aVAa, aVAb;
1280 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1281 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1282 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1283 GC_MakePlane MkPlane (B,Aa,Ab);
1284 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1285 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1286 GetMapOfAIS().Bind (anAISPlane ,aName);
1287 TheAISContext()->Display(anAISPlane);
1290 // aShapeA is a Face
1293 // Close the local context: nothing to select
1294 TheAISContext()->CloseLocalContext(aCurrentIndex);
1295 // Construction of plane
1296 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1297 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1298 if (aSurface.GetType()==GeomAbs_Plane)
1300 gp_Pln aPlane = aSurface.Plane();
1301 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1302 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1303 GetMapOfAIS().Bind (anAISPlane, aName);
1304 TheAISContext()->Display(anAISPlane);
1308 std::cout<<" vplane: error\n";
1314 // Function vPlanePara
1315 // ===================
1316 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1317 else if (!strcasecmp(argv[0], "vplanepara"))
1319 TheAISContext()->OpenLocalContext();
1320 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1322 // Activate modes Vertex and Face
1323 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1324 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1325 std::cout<<" Select a vertex or a face\n";
1328 Standard_Integer argcc = 5;
1329 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1330 const char **argvv = (const char **) buff;
1331 while (ViewerMainLoop( argcc, argvv) ) { }
1334 TopoDS_Shape aShapeA;
1335 for (TheAISContext()->InitSelected();
1336 TheAISContext()->MoreSelected();
1337 TheAISContext()->NextSelected())
1339 aShapeA = TheAISContext()->SelectedShape();
1342 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1344 // aShapeA is a vertex
1345 // Deactivate the mode Vertex
1346 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1347 std::cout<<" Select a face\n";
1350 Standard_Integer argccc = 5;
1351 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1352 const char **argvvv = (const char **) bufff;
1353 while (ViewerMainLoop( argccc, argvvv) ) { }
1356 TopoDS_Shape aShapeB;
1357 for (TheAISContext()->InitSelected();
1358 TheAISContext()->MoreSelected();
1359 TheAISContext()->NextSelected())
1361 // A vertex ShapeA can be on Face ShapeB
1362 aShapeB = TheAISContext()->SelectedShape();
1365 // Close the local context
1366 TheAISContext()->CloseLocalContext(aCurrentIndex);
1368 // Construction of plane
1369 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1371 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1372 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1373 if (aSurface.GetType()==GeomAbs_Plane )
1375 gp_Pln aPlane = aSurface.Plane();
1376 // Construct a plane parallel to aGeomPlane through A
1377 aPlane.SetLocation(A);
1378 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1379 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1380 GetMapOfAIS().Bind (aAISPlane ,aName);
1381 TheAISContext()->Display(aAISPlane);
1385 std::cout<<" vplanepara: error\n";
1392 // Deactive the mode Face
1393 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1394 std::cout<<" Select a vertex\n";
1397 Standard_Integer argccc = 5;
1398 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1399 const char **argvvv = (const char **) bufff;
1400 while (ViewerMainLoop( argccc, argvvv) ) { }
1403 TopoDS_Shape aShapeB;
1404 for (TheAISContext()->InitSelected();
1405 TheAISContext()->MoreSelected();
1406 TheAISContext()->NextSelected())
1408 // A vertex ShapeB can be on Face ShapeA
1409 aShapeB = TheAISContext()->SelectedShape();
1411 // Close the local context
1412 TheAISContext()->CloseLocalContext(aCurrentIndex);
1414 // Construction of plane
1415 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1417 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1418 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1419 if (aSurface.GetType()==GeomAbs_Plane )
1421 gp_Pln aPlane = aSurface.Plane();
1422 aPlane.SetLocation(B);
1423 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1424 // Construct a plane parallel to aGeomPlane through B
1425 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1426 GetMapOfAIS().Bind (anAISPlane, aName);
1427 TheAISContext()->Display(anAISPlane);
1431 std::cout<<" vplanepara: error"<<"\n";return 1;
1436 // Function vplaneortho
1437 // ====================
1438 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1441 TheAISContext()->OpenLocalContext();
1442 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1444 // Activate the modes Edge and Face
1445 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1446 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1447 std::cout<<" Select a face and an edge coplanar\n";
1450 Standard_Integer argcc = 5;
1451 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1452 const char **argvv = (const char **) buff;
1453 while (ViewerMainLoop( argcc, argvv) ) { }
1456 TopoDS_Shape aShapeA;
1457 for (TheAISContext()->InitSelected();
1458 TheAISContext()->MoreSelected();
1459 TheAISContext()->NextSelected())
1461 aShapeA = TheAISContext()->SelectedShape();
1464 if (aShapeA.ShapeType()==TopAbs_EDGE )
1466 // ShapeA is an edge, deactivate the mode Edge...
1467 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1468 std::cout<<" Select a face\n";
1471 Standard_Integer argccc = 5;
1472 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1473 const char **argvvv = (const char **) bufff;
1474 while (ViewerMainLoop( argccc, argvvv) ) { }
1477 TopoDS_Shape aShapeB;
1478 for (TheAISContext()->InitSelected();
1479 TheAISContext()->MoreSelected();
1480 TheAISContext()->NextSelected())
1482 // Edge ShapeA can be on Face ShapeB
1483 aShapeB = TheAISContext()->SelectedShape();
1486 // Close the local context
1487 TheAISContext()->CloseLocalContext(aCurrentIndex);
1489 // Construction of plane
1490 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1491 TopoDS_Vertex aVAa, aVAb;
1492 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1493 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1494 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1498 // Creation of rotation axis
1499 gp_Ax1 aRotAxis (Aa,Dab);
1501 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1502 // The edge must be parallel to the face
1503 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1504 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1505 // Compare to heights
1506 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1507 >Precision::Confusion())
1509 // the edge is not parallel to the face
1510 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1514 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1515 if (aSurface.GetType()==GeomAbs_Plane)
1517 gp_Pln aPlane = aSurface.Plane();
1518 // It rotates a half turn round the axis of rotation
1519 aPlane.Rotate(aRotAxis , M_PI/2);
1521 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1522 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1523 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1524 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1525 GetMapOfAIS().Bind (anAISPlane, aName);
1526 TheAISContext()->Display(anAISPlane);
1530 std::cout<<" vplaneortho: error\n";
1536 // ShapeA is a Face, deactive the mode Face.
1537 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1538 std::cout<<" Select an edge\n";
1541 Standard_Integer argccc = 5;
1542 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1543 const char **argvvv = (const char **) bufff;
1544 while (ViewerMainLoop( argccc, argvvv) ) { }
1547 TopoDS_Shape aShapeB;
1548 for (TheAISContext()->InitSelected();
1549 TheAISContext()->MoreSelected();
1550 TheAISContext()->NextSelected())
1552 // Edge ShapeB can be on Face ShapeA
1553 aShapeB = TheAISContext()->SelectedShape();
1555 // Close the local context
1556 TheAISContext()->CloseLocalContext(aCurrentIndex);
1558 // Construction of plane
1559 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1560 TopoDS_Vertex aVBa, aVBb;
1561 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1562 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1563 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1564 gp_Vec ab (aBa,aBb);
1566 // Creation of rotation axe
1567 gp_Ax1 aRotAxis (aBa,Dab);
1569 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1570 // The edge must be parallel to the face
1571 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1572 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1573 // Comparing the two heights
1574 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1575 >Precision::Confusion())
1577 // the edge is not parallel to the face
1578 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1582 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1583 if (aSurface.GetType()==GeomAbs_Plane)
1585 gp_Pln aPlane = aSurface.Plane();
1586 // It rotates a half turn round the axis of rotation
1587 aPlane.Rotate(aRotAxis , M_PI/2);
1588 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1589 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1590 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1591 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1592 GetMapOfAIS().Bind (anAISPlane ,aName);
1593 TheAISContext()->Display(anAISPlane);
1597 std::cout<<" vplaneortho: error\n";
1607 //==============================================================================
1609 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1610 //==============================================================================
1612 //==============================================================================
1613 //function : VLineBuilder
1614 //purpose : Build an AIS_Line
1615 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1616 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1617 //==============================================================================
1618 #include <Geom_CartesianPoint.hxx>
1619 #include <AIS_Line.hxx>
1622 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1624 Standard_Integer myCurrentIndex;
1626 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1627 // Fermeture des contextes
1628 TheAISContext()->CloseAllContexts();
1630 // On recupere les parametres
1631 Handle(AIS_InteractiveObject) theShapeA;
1632 Handle(AIS_InteractiveObject) theShapeB;
1634 // Parametres: AIS_Point AIS_Point
1635 // ===============================
1638 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1639 // On verifie que c'est bien une AIS_Point
1640 if (!theShapeA.IsNull() &&
1641 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1642 // on recupere le deuxieme AIS_Point
1644 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1645 if (theShapeA.IsNull() ||
1646 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1648 di <<"vline error: wrong type of 2de argument."<<"\n";
1652 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1653 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1654 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1655 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1657 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1658 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1659 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1661 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1662 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1663 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1665 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1667 di<<"vline error: same points"<<"\n";return 1;
1669 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1670 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1671 GetMapOfAIS().Bind(theAISLine,argv[1] );
1672 TheAISContext()->Display(theAISLine );
1676 // Parametres 6 Reals
1677 // ==================
1680 // On verifie que les deux points ne sont pas confondus
1682 Standard_Real coord[6];
1683 for(Standard_Integer i=0;i<=2;i++){
1684 coord[i]=atof(argv[2+i]);
1685 coord[i+3]=atof(argv[5+i]);
1688 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1689 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1691 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1692 GetMapOfAIS().Bind(theAISLine,argv[1] );
1693 TheAISContext()->Display(theAISLine );
1697 // Pas de parametres: Selection dans le viewer.
1698 // ============================================
1701 TheAISContext()->OpenLocalContext();
1702 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1704 // Active le mode Vertex.
1705 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1706 di<<" Select a vertex "<<"\n";
1708 // Boucle d'attente waitpick.
1709 Standard_Integer argcc = 5;
1710 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1711 const char **argvv = (const char **) buff;
1712 while (ViewerMainLoop( argcc, argvv) ) { }
1715 TopoDS_Shape ShapeA;
1716 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1717 ShapeA = TheAISContext()->SelectedShape();
1720 // ShapeA est un Vertex
1721 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1723 di<<" Select a different vertex."<<"\n";
1725 TopoDS_Shape ShapeB;
1728 // Boucle d'attente waitpick.
1729 Standard_Integer argccc = 5;
1730 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1731 const char **argvvv = (const char **) bufff;
1732 while (ViewerMainLoop( argccc, argvvv) ) { }
1735 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1736 ShapeB = TheAISContext()->SelectedShape();
1740 } while(ShapeB.IsSame(ShapeA) );
1742 // Fermeture du context local
1743 TheAISContext()->CloseLocalContext(myCurrentIndex);
1745 // Construction de la line
1746 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1747 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1749 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1750 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1752 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1753 GetMapOfAIS().Bind(theAISLine,argv[1] );
1754 TheAISContext()->Display(theAISLine );
1758 di<<"vline error."<<"\n";
1766 //==============================================================================
1767 // class : FilledCircle
1768 // purpose : creates filled circle based on AIS_InteractiveObject
1770 // This class is used to check method Matches() of class
1771 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1772 // because none of AIS classes provides creation of
1773 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1774 // (look method ComputeSelection() )
1775 //==============================================================================
1777 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1779 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1780 gp_Circ aCirc(anAxes, theRadius);
1781 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1785 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1787 class FilledCircle : public AIS_InteractiveObject
1791 DEFINE_STANDARD_RTTI(FilledCircle);
1793 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1794 FilledCircle(Handle(Geom_Circle) theCircle);
1797 TopoDS_Face ComputeFace();
1799 // Virtual methods implementation
1800 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1801 const Handle(Prs3d_Presentation)& thePresentation,
1802 const Standard_Integer theMode);
1804 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1805 const Standard_Integer theMode);
1808 Handle(Geom_Circle) myCircle;
1809 Standard_Boolean myFilledStatus;
1813 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1814 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1816 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1818 myCircle = CreateCircle(theCenter, theRadius);
1819 myFilledStatus = Standard_True;
1822 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1824 myCircle = theCircle;
1825 myFilledStatus = Standard_True;
1828 TopoDS_Face FilledCircle::ComputeFace()
1830 // Create edge from myCircle
1831 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1832 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1834 // Create wire from anEdge
1835 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1836 TopoDS_Wire aWire = aWireMaker.Wire();
1838 // Create face from aWire
1839 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1840 TopoDS_Face aFace = aFaceMaker.Face();
1845 void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
1846 const Handle_Prs3d_Presentation &thePresentation,
1847 const Standard_Integer theMode)
1849 thePresentation->Clear();
1851 TopoDS_Face aFace = ComputeFace();
1853 if (aFace.IsNull()) return;
1854 if (theMode != 0) return;
1856 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1859 void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection,
1860 const Standard_Integer theMode)
1862 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1863 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1864 myCircle, myFilledStatus);
1865 theSelection->Add(aSensitiveCircle);
1868 //==============================================================================
1870 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1871 //==============================================================================
1873 //==============================================================================
1874 //function : VCircleBuilder
1875 //purpose : Build an AIS_Circle
1876 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1877 // PointName PointName PointName IsFilled
1878 //==============================================================================
1880 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1881 TCollection_AsciiString theName,
1882 Standard_Boolean isFilled)
1884 Handle(AIS_InteractiveObject) aCircle;
1887 aCircle = new FilledCircle(theGeomCircle);
1891 aCircle = new AIS_Circle(theGeomCircle);
1894 // Check if there is an object with given name
1895 // and remove it from context
1896 if (GetMapOfAIS().IsBound2(theName))
1898 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
1899 Handle(AIS_InteractiveObject) anInterObj =
1900 Handle(AIS_InteractiveObject)::DownCast(anObj);
1901 TheAISContext()->Remove(anInterObj, Standard_False);
1902 GetMapOfAIS().UnBind2(theName);
1905 // Bind the circle to its name
1906 GetMapOfAIS().Bind(aCircle, theName);
1908 // Display the circle
1909 TheAISContext()->Display(aCircle);
1913 static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1915 Standard_Integer myCurrentIndex;
1916 // Verification of the arguments
1917 if (argc>6 || argc<2)
1919 std::cout << "vcircle error: expect 4 arguments.\n";
1920 return 1; // TCL_ERROR
1922 TheAISContext()->CloseAllContexts();
1924 // There are all arguments
1928 TCollection_AsciiString aName(argv[1]);
1929 Standard_Boolean isFilled = (Standard_Boolean)atoi(argv[5]);
1931 Handle(AIS_InteractiveObject) theShapeA;
1932 Handle(AIS_InteractiveObject) theShapeB;
1935 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
1937 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
1940 // Arguments: AIS_Point AIS_Point AIS_Point
1941 // ========================================
1942 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
1943 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1945 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
1947 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
1948 return 1; // TCL_ERROR
1950 // The third object must be a point
1951 Handle(AIS_InteractiveObject) theShapeC =
1952 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
1953 if (theShapeC.IsNull() ||
1954 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
1956 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
1957 return 1; // TCL_ERROR
1960 // Verify that the three points are different
1961 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
1962 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
1963 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
1965 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
1966 Handle(Geom_CartesianPoint) myCartPointA =
1967 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
1969 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
1970 Handle(Geom_CartesianPoint) myCartPointB =
1971 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
1973 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
1974 Handle(Geom_CartesianPoint) myCartPointC =
1975 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
1978 if (abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
1979 abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
1980 abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
1982 std::cout << "vcircle error: Same points.\n";
1983 return 1; // TCL_ERROR
1986 if (abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
1987 abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1988 abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1990 std::cout << "vcircle error: Same points.\n";
1991 return 1; // TCL_ERROR
1994 if (abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
1995 abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1996 abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1998 std::cout << "vcircle error: Same points.\n";
1999 return 1;// TCL_ERROR
2001 // Construction of the circle
2002 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2003 myCartPointB->Pnt(), myCartPointC->Pnt() );
2004 Handle (Geom_Circle) theGeomCircle;
2007 theGeomCircle = Cir.Value();
2009 catch (StdFail_NotDone)
2011 std::cout << "vcircle error: can't create circle\n";
2012 return -1; // TCL_ERROR
2015 DisplayCircle(theGeomCircle, aName, isFilled);
2018 // Arguments: AIS_Plane AIS_Point Real
2019 // ===================================
2020 else if (theShapeA->Type() == AIS_KOI_Datum &&
2021 theShapeA->Signature() == 7 )
2023 if (theShapeB->Type() != AIS_KOI_Datum ||
2024 theShapeB->Signature() != 1 )
2026 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2027 return 1; // TCL_ERROR
2029 // Ñheck that the radius is >= 0
2030 if (atof(argv[4]) <= 0 )
2032 std::cout << "vcircle error: the radius must be >=0.\n";
2033 return 1; // TCL_ERROR
2036 // Recover the normal to the plane
2037 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2038 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2040 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2041 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2042 Handle(Geom_CartesianPoint) myCartPointB =
2043 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2045 gp_Pln mygpPlane = myGeomPlane->Pln();
2046 gp_Ax1 thegpAxe = mygpPlane.Axis();
2047 gp_Dir theDir = thegpAxe.Direction();
2048 gp_Pnt theCenter = myCartPointB->Pnt();
2049 Standard_Real TheR = atof(argv[4]);
2050 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2051 Handle (Geom_Circle) theGeomCircle;
2054 theGeomCircle = Cir.Value();
2056 catch (StdFail_NotDone)
2058 std::cout << "vcircle error: can't create circle\n";
2059 return -1; // TCL_ERROR
2062 DisplayCircle(theGeomCircle, aName, isFilled);
2069 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2070 return 1; // TCL_ERROR
2074 // No arguments: selection in the viewer
2075 // =========================================
2078 // Get the name of the circle
2079 TCollection_AsciiString aName(argv[1]);
2081 TheAISContext()->OpenLocalContext();
2082 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2084 // Activate selection mode for vertices and faces
2085 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2086 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2087 std::cout << " Select a vertex or a face\n";
2090 Standard_Integer argcc = 5;
2091 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2092 const char **argvv = (const char **) buff;
2093 while (ViewerMainLoop( argcc, argvv) ) { }
2096 TopoDS_Shape ShapeA;
2097 for(TheAISContext()->InitSelected();
2098 TheAISContext()->MoreSelected();
2099 TheAISContext()->NextSelected() )
2101 ShapeA = TheAISContext()->SelectedShape();
2104 // ShapeA is a Vertex
2105 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2107 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2108 std::cout << " Select a different vertex\n";
2110 TopoDS_Shape ShapeB;
2114 Standard_Integer argccc = 5;
2115 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2116 const char **argvvv = (const char **) bufff;
2117 while (ViewerMainLoop( argccc, argvvv) ) { }
2120 for(TheAISContext()->InitSelected();
2121 TheAISContext()->MoreSelected();
2122 TheAISContext()->NextSelected() )
2124 ShapeB = TheAISContext()->SelectedShape();
2126 } while(ShapeB.IsSame(ShapeA) );
2128 // Selection of ShapeC
2129 std::cout << " Select the last vertex\n";
2130 TopoDS_Shape ShapeC;
2134 Standard_Integer argcccc = 5;
2135 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2136 const char **argvvvv = (const char **) buffff;
2137 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2140 for(TheAISContext()->InitSelected();
2141 TheAISContext()->MoreSelected();
2142 TheAISContext()->NextSelected() )
2144 ShapeC = TheAISContext()->SelectedShape();
2146 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2149 Standard_Boolean isFilled;
2150 std::cout << "Enter filled status (0 or 1)\n";
2153 // Close the local context
2154 TheAISContext()->CloseLocalContext(myCurrentIndex);
2156 // Construction of the circle
2157 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2158 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2159 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2161 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2162 Handle (Geom_Circle) theGeomCircle;
2165 theGeomCircle = Cir.Value();
2167 catch (StdFail_NotDone)
2169 std::cout << "vcircle error: can't create circle\n";
2170 return -1; // TCL_ERROR
2173 DisplayCircle(theGeomCircle, aName, isFilled);
2179 std::cout << " Select a vertex (in your face)\n";
2180 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2182 TopoDS_Shape ShapeB;
2184 Standard_Integer argccc = 5;
2185 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2186 const char **argvvv = (const char **) bufff;
2187 while (ViewerMainLoop( argccc, argvvv) ) { }
2190 for(TheAISContext()->InitSelected();
2191 TheAISContext()->MoreSelected();
2192 TheAISContext()->NextSelected() )
2194 ShapeB = TheAISContext()->SelectedShape();
2197 // Recover the radius
2198 Standard_Real theRad;
2201 std::cout << " Enter the value of the radius:\n";
2203 } while (theRad <= 0);
2205 // Get filled status
2206 Standard_Boolean isFilled;
2207 std::cout << "Enter filled status (0 or 1)\n";
2210 // Close the local context
2211 TheAISContext()->CloseLocalContext(myCurrentIndex);
2212 // Construction of the circle
2214 // Recover the normal to the plane. tag
2215 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2216 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2217 gp_Pln myPlane = mySurface.Plane();
2218 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2219 gp_Pln mygpPlane = theGeomPlane->Pln();
2220 gp_Ax1 thegpAxe = mygpPlane.Axis();
2221 gp_Dir theDir = thegpAxe.Direction();
2223 // Recover the center
2224 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2226 // Ñonstruct the circle
2227 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2228 Handle (Geom_Circle) theGeomCircle;
2231 theGeomCircle = Cir.Value();
2233 catch (StdFail_NotDone)
2235 std::cout << "vcircle error: can't create circle\n";
2236 return -1; // TCL_ERROR
2239 DisplayCircle(theGeomCircle, aName, isFilled);
2249 //===============================================================================================
2250 //function : VDrawText
2252 //purpose : Create a text.
2253 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2254 //===============================================================================================
2255 #include <Graphic3d_Group.hxx>
2256 #include <Graphic3d_Structure.hxx>
2257 #include <Graphic3d_NameOfFont.hxx>
2258 #include <Graphic3d_AspectText3d.hxx>
2259 #include <Graphic2d_GraphicObject.hxx>
2260 #include <Graphic3d_Array1OfVertex.hxx>
2261 #include <Graphic3d_AspectFillArea3d.hxx>
2262 #include <Graphic3d_StructureManager.hxx>
2263 #include <Graphic3d_VerticalTextAlignment.hxx>
2264 #include <Graphic3d_HorizontalTextAlignment.hxx>
2266 #include <Visual3d_ViewManager.hxx>
2267 #include <ViewerTest_Tool.ixx>
2269 #include <Standard_DefineHandle.hxx>
2271 #include <Prs3d_Root.hxx>
2272 #include <Prs3d_Text.hxx>
2273 #include <Prs3d_TextAspect.hxx>
2274 #include <Prs3d_ShadingAspect.hxx>
2275 #include <PrsMgr_PresentationManager3d.hxx>
2277 #include <TCollection_ExtendedString.hxx>
2278 #include <TCollection_AsciiString.hxx>
2280 #include <gp_Pnt.hxx>
2281 #include <Quantity_NameOfColor.hxx>
2282 #include <Quantity_Color.hxx>
2285 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2287 class MyTextClass:public AIS_InteractiveObject
2291 DEFINE_STANDARD_RTTI(MyTextClass );
2297 const TCollection_ExtendedString& , const gp_Pnt& ,
2298 Quantity_Color color,
2299 Standard_Integer aHJust,
2300 Standard_Integer aVJust ,
2301 Standard_Real Angle ,
2302 Standard_Boolean Zoom ,
2303 Standard_Real Height,
2304 OSD_FontAspect FontAspect,
2305 Standard_CString Font
2310 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2311 const Handle(Prs3d_Presentation)& aPresentation,
2312 const Standard_Integer aMode);
2314 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
2315 const Standard_Integer aMode){} ;
2318 TCollection_ExtendedString aText;
2321 Standard_Real Green;
2323 Standard_Real aAngle;
2324 Standard_Real aHeight;
2325 Standard_Boolean aZoomable;
2326 Quantity_Color aColor;
2327 Standard_CString aFont;
2328 OSD_FontAspect aFontAspect;
2329 Graphic3d_HorizontalTextAlignment aHJustification;
2330 Graphic3d_VerticalTextAlignment aVJustification;
2335 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2336 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2339 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2340 Quantity_Color color = Quantity_NOC_YELLOW,
2341 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2342 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2343 Standard_Real angle = 0.0 ,
2344 Standard_Boolean zoomable = Standard_True,
2345 Standard_Real height = 12.,
2346 OSD_FontAspect fontAspect = OSD_FA_Regular,
2347 Standard_CString font = "Courier")
2350 aPosition = position;
2351 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2352 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2354 aZoomable = zoomable;
2357 aFontAspect = fontAspect;
2363 //////////////////////////////////////////////////////////////////////////////
2364 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2365 const Handle(Prs3d_Presentation)& aPresentation,
2366 const Standard_Integer aMode)
2369 aPresentation->Clear();
2371 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2373 asp->SetFont(aFont);
2374 asp->SetColor(aColor);
2375 asp->SetHeight(aHeight); // I am changing the myHeight value
2377 asp->SetHorizontalJustification(aHJustification);
2378 asp->SetVerticalJustification(aVJustification);
2379 asp->Aspect()->SetTextZoomable(aZoomable);
2380 asp->Aspect()->SetTextAngle(aAngle);
2381 asp->Aspect()->SetTextFontAspect(aFontAspect);
2382 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2384 /* This comment code is worked
2385 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2386 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2387 Graphic3d_Vertex vertices_text;
2388 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2389 TheGroup->SetPrimitivesAspect(aspect);
2390 TheGroup->BeginPrimitives();
2391 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2392 TheGroup->EndPrimitives();
2396 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2401 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2402 di<<"Usage: type help "<<argv[0]<<"\n";
2403 return 1; //TCL_ERROR
2406 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2408 // Create 3D view if it doesn't exist
2409 if ( aContext.IsNull() )
2411 ViewerTest::ViewerInit();
2412 aContext = ViewerTest::GetAISContext();
2413 if( aContext.IsNull() )
2415 di << "Error: Cannot create a 3D view\n";
2416 return 1; //TCL_ERROR
2421 const Standard_Real X = atof(argv[2]);
2422 const Standard_Real Y = atof(argv[3]);
2423 const Standard_Real Z = atof(argv[4]);
2424 const gp_Pnt pnt(X,Y,Z);
2427 const Quantity_Parameter R = atof(argv[5])/255.;
2428 const Quantity_Parameter G = atof(argv[6])/255.;
2429 const Quantity_Parameter B = atof(argv[7])/255.;
2430 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2433 const int hor_align = atoi(argv[8]);
2434 const int ver_align = atoi(argv[9]);
2437 const Standard_Real angle = atof(argv[10]);
2440 const Standard_Boolean zoom = atoi(argv[11]);
2443 const Standard_Real height = atof(argv[12]);
2446 const OSD_FontAspect aspect = OSD_FontAspect(atoi(argv[13]));
2449 TCollection_AsciiString font;
2451 font.AssignCat("Courier");
2453 font.AssignCat(argv[14]);
2455 // Text is multibyte
2456 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (atoi(argv[15]) != 0);
2459 TCollection_ExtendedString name;
2462 const char *str = argv[1];
2463 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2464 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2466 unsigned short c1 = *str++;
2467 unsigned short c2 = *str++;
2469 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2479 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2480 aContext->Display(myT,Standard_True);
2487 #include <gp_Pnt.hxx>
2488 #include <Graphic3d_ArrayOfPoints.hxx>
2489 #include <Graphic3d_ArrayOfPrimitives.hxx>
2490 #include <Graphic3d_Array1OfVertex.hxx>
2491 #include <Graphic3d_ArrayOfTriangles.hxx>
2492 #include <Poly_Array1OfTriangle.hxx>
2493 #include <Poly_Triangle.hxx>
2494 #include <Poly_Triangulation.hxx>
2495 #include <TColgp_Array1OfPnt.hxx>
2496 #include <TShort_Array1OfShortReal.hxx>
2497 #include <TShort_HArray1OfShortReal.hxx>
2499 #include <AIS_Triangulation.hxx>
2500 #include <Aspect_GraphicDevice.hxx>
2501 #include <StdPrs_ToolShadedShape.hxx>
2502 #include <Poly_Connect.hxx>
2503 #include <TColgp_Array1OfDir.hxx>
2504 #include <Graphic3d_GraphicDriver.hxx>
2506 #include <TColStd_Array1OfInteger.hxx>
2507 #include <TColStd_HArray1OfInteger.hxx>
2508 #include <Prs3d_ShadingAspect.hxx>
2509 #include <Graphic3d_MaterialAspect.hxx>
2510 #include <Graphic3d_AspectFillArea3d.hxx>
2512 #include <BRepPrimAPI_MakeCylinder.hxx>
2513 #include <TopoDS_Shape.hxx>
2514 #include <TopExp_Explorer.hxx>
2515 #include <TopAbs.hxx>
2516 #include <StdSelect_ShapeTypeFilter.hxx>
2519 //===============================================================================================
2520 //function : CalculationOfSphere
2522 //purpose : Create a Sphere
2523 //===============================================================================================
2525 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2528 double mRadius = Radius;
2529 double mCenter[3] = {X,Y,Z};
2530 int mThetaResolution;
2532 double mStartTheta = 0;//StartTheta;
2533 double mEndTheta = 360;//EndTheta;
2534 double mStartPhi = 0;//StartPhi;
2535 double mEndPhi = 180;//EndPhi;
2536 res = res < 4 ? 4 : res;
2538 mThetaResolution = res;
2539 mPhiResolution = res;
2542 int jStart, jEnd, numOffset;
2543 int numPts, numPolys;
2544 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2545 double startTheta, endTheta, startPhi, endPhi;
2546 int base, numPoles=0, thetaResolution, phiResolution;
2551 if ( numPieces > mThetaResolution ) {
2552 numPieces = mThetaResolution;
2555 int localThetaResolution = mThetaResolution;
2556 double localStartTheta = mStartTheta;
2557 double localEndTheta = mEndTheta;
2559 while ( localEndTheta < localStartTheta ) {
2560 localEndTheta += 360.0;
2563 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2565 // Change the ivars based on pieces.
2567 start = piece * localThetaResolution / numPieces;
2568 end = (piece+1) * localThetaResolution / numPieces;
2569 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2570 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2571 localThetaResolution = end - start;
2573 numPts = mPhiResolution * localThetaResolution + 2;
2574 numPolys = mPhiResolution * 2 * localThetaResolution;
2576 // Create north pole if needed
2577 int number_point = 0;
2578 int number_pointArray = 0;
2580 if ( mStartPhi <= 0.0 ) {
2581 number_pointArray++;
2584 if ( mEndPhi >= 180.0 ) {
2585 number_pointArray++;
2589 // Check data, determine increments, and convert to radians
2590 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2591 startTheta *= M_PI / 180.0;
2592 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2593 endTheta *= M_PI / 180.0;
2596 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2597 startPhi *= M_PI / 180.0;
2598 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2599 endPhi *= M_PI / 180.0;
2601 phiResolution = mPhiResolution - numPoles;
2602 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2603 thetaResolution = localThetaResolution;
2604 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2605 ++localThetaResolution;
2607 deltaTheta = (endTheta - startTheta) / thetaResolution;
2609 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2610 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2612 // Create intermediate points
2613 for ( i = 0; i < localThetaResolution; i++ ) {
2614 for ( j = jStart; j < jEnd; j++ ) {
2615 number_pointArray++;
2619 //Generate mesh connectivity
2620 base = phiResolution * localThetaResolution;
2622 int number_triangle = 0 ;
2623 if ( mStartPhi <= 0.0 ) { // around north pole
2624 number_triangle += localThetaResolution;
2627 if ( mEndPhi >= 180.0 ) { // around south pole
2628 number_triangle += localThetaResolution;
2631 // bands in-between poles
2632 for ( i=0; i < localThetaResolution; i++){
2633 for ( j=0; j < (phiResolution-1); j++){
2634 number_triangle +=2;
2638 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2639 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2640 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2642 if ( mStartPhi <= 0.0 ){
2645 x[2] = mCenter[2] + mRadius;
2646 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2649 // Create south pole if needed
2650 if ( mEndPhi >= 180.0 ){
2653 x[2] = mCenter[2] - mRadius;
2654 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2658 for ( i=0; i < localThetaResolution; i++){
2659 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2660 for ( j = jStart; j < jEnd; j++){
2661 phi = startPhi + j*deltaPhi;
2662 radius = mRadius * sin((double)phi);
2663 n[0] = radius * cos((double)theta);
2664 n[1] = radius * sin((double)theta);
2665 n[2] = mRadius * cos((double)phi);
2666 x[0] = n[0] + mCenter[0];
2667 x[1] = n[1] + mCenter[1];
2668 x[2] = n[2] + mCenter[2];
2669 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2675 number_triangle = 1;
2676 if ( mStartPhi <= 0.0 ){// around north pole
2677 for (i=0; i < localThetaResolution; i++){
2678 pts[0] = phiResolution*i + numPoles;
2679 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2681 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2686 if ( mEndPhi >= 180.0 ){ // around south pole
2687 numOffset = phiResolution - 1 + numPoles;
2688 for (i=0; i < localThetaResolution; i++){
2689 pts[0] = phiResolution*i + numOffset;
2690 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2691 pts[1] = numPoles - 1;
2692 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2697 // bands in-between poles
2699 for (i=0; i < localThetaResolution; i++){
2700 for (j=0; j < (phiResolution-1); j++){
2701 pts[0] = phiResolution*i + j + numPoles;
2702 pts[1] = pts[0] + 1;
2703 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2704 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2707 pts[2] = pts[1] - 1;
2708 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2713 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2715 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2717 Standard_Integer index[3];
2718 Standard_Real Tol = Precision::Confusion();
2721 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2722 gp_XYZ eqPlan(0, 0, 0);
2723 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2724 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2725 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2726 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2728 Standard_Real mod = vv.Modulus();
2729 if(mod < Tol) continue;
2733 Standard_Real modmax = eqPlan.Modulus();
2736 Nor = gp_Dir(eqPlan);
2738 Nor = gp_Dir(0., 0., 1.);
2740 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2741 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2742 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2743 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2747 polyTriangulation->SetNormals(Normals);
2749 return polyTriangulation;
2752 //===============================================================================================
2753 //function : VDrawSphere
2755 //purpose : Create an AIS shape.
2756 //===============================================================================================
2757 static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2760 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2761 if (aContextAIS.IsNull())
2763 std::cout << "Call vinit before!\n";
2768 std::cout << "Use: " << argv[0]
2769 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
2773 // read the arguments
2774 TCollection_AsciiString aShapeName (argv[1]);
2775 Standard_Integer aResolution = atoi (argv[2]);
2776 Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0;
2777 Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0;
2778 Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0;
2779 Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0;
2780 Standard_Boolean toShowEdges = (argc > 7) ? atoi (argv[7]) : Standard_False;
2782 // remove AIS object with given name from map
2783 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2785 std::cout << "Compute Triangulation...\n";
2786 Handle(AIS_Triangulation) aShape
2787 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2790 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2791 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2793 // stupid initialization of Green color in RGBA space as integer
2794 // probably wrong for big-endian CPUs
2795 Standard_Integer aRed = 0;
2796 Standard_Integer aGreen = 255;
2797 Standard_Integer aBlue = 0;
2798 Standard_Integer anAlpha = 0; // not used
2799 Standard_Integer aColorInt = aRed;
2800 aColorInt += aGreen << 8;
2801 aColorInt += aBlue << 16;
2802 aColorInt += anAlpha << 24;
2804 // setup colors array per vertex
2805 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2806 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2808 aColorArray->SetValue (aNodeId, aColorInt);
2810 aShape->SetColors (aColorArray);
2813 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2814 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2815 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2816 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2817 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2818 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2819 aTotalSize >>= 20; //MB
2820 aNormalsSize >>= 20;
2822 aTrianglesSize >>= 20;
2823 aPolyConnectSize >>= 20;
2824 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2825 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2826 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2827 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2828 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2829 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2831 // Setting material properties, very important for desirable visual result!
2832 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2833 aMat.SetAmbient (0.2);
2834 aMat.SetSpecular (0.5);
2835 Handle(Graphic3d_AspectFillArea3d) anAspect
2836 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2838 Quantity_NOC_YELLOW,
2843 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2846 anAspect->SetEdgeOn();
2850 anAspect->SetEdgeOff();
2852 aShAsp->SetAspect (anAspect);
2853 aShape->Attributes()->SetShadingAspect (aShAsp);
2855 VDisplayAISObject (aShapeName, aShape);
2859 //===============================================================================================
2860 //function : VClipPlane
2862 //===============================================================================================
2863 static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2865 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2866 Handle(V3d_View) aView = ViewerTest::CurrentView();
2867 Standard_Real coeffA, coeffB, coeffC, coeffD;
2868 if (aViewer.IsNull() || aView.IsNull())
2870 std::cout << "Viewer not initialized!\n";
2874 // count an active planes count
2875 Standard_Integer aNewPlaneId = 1;
2876 Standard_Integer anActivePlanes = 0;
2877 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
2879 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2880 if (aView->IsActivePlane (aPlaneV3d))
2888 // just show info about existing planes
2889 Standard_Integer aPlaneId = 1;
2890 std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
2891 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2893 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2894 aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
2895 gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
2896 const gp_Pnt& aLoc = aPlane.Location();
2897 const gp_Dir& aNor = aPlane.Axis().Direction();
2898 Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
2899 std::cout << "Plane #" << aPlaneId
2900 << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
2901 << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
2902 << (isActive ? " on" : " off")
2903 << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
2908 std::cout << "No defined clipping planes\n";
2912 else if (argc == 2 || argc == 3)
2914 Standard_Integer aPlaneIdToOff = (argc == 3) ? atoi (argv[1]) : 1;
2915 Standard_Boolean toIterateAll = (argc == 2);
2916 TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
2917 isOnOffStr.LowerCase();
2918 Standard_Integer aPlaneId = 1;
2919 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
2921 if (aPlaneIdToOff == aPlaneId || toIterateAll)
2923 Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
2924 if (isOnOffStr.Search ("off") >= 0)
2926 aView->SetPlaneOff (aPlaneV3d);
2927 std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
2929 else if (isOnOffStr.Search ("on") >= 0)
2931 // avoid z-fighting glitches
2933 if (!aView->IsActivePlane (aPlaneV3d))
2935 if (anActivePlanes < aView->View()->PlaneLimit())
2937 aView->SetPlaneOn (aPlaneV3d);
2938 std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
2942 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
2943 << "You should disable or remove some existing plane to activate this one\n";
2948 std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
2951 else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
2953 aPlaneV3d->Erase(); // not performed on destructor!!!
2954 aView->SetPlaneOff (aPlaneV3d);
2955 aViewer->DelPlane (aPlaneV3d);
2956 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2959 for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
2961 aPlaneV3d = aViewer->DefinedPlane();
2962 aPlaneV3d->Erase(); // not performed on destructor!!!
2963 aView->SetPlaneOff (aPlaneV3d);
2964 aViewer->DelPlane (aPlaneV3d);
2965 std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
2974 else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
2976 // avoid z-fighting glitches
2977 aView->SetPlaneOff (aPlaneV3d);
2978 aPlaneV3d->Display (aView);
2979 std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
2981 else if (isOnOffStr.Search ("hide") >= 0)
2984 std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
2988 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
2993 if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
2995 std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
3003 std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
3007 Standard_Real aLocX = atof (argv[1]);
3008 Standard_Real aLocY = atof (argv[2]);
3009 Standard_Real aLocZ = atof (argv[3]);
3010 Standard_Real aNormDX = atof (argv[4]);
3011 Standard_Real aNormDY = atof (argv[5]);
3012 Standard_Real aNormDZ = atof (argv[6]);
3014 Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
3015 gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
3016 aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
3017 aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
3019 aViewer->AddPlane (aPlaneV3d); // add to defined planes list
3020 std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
3021 if (anActivePlanes < aView->View()->PlaneLimit())
3023 aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
3028 std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
3029 << "You should disable or remove some existing plane to activate the new one\n";
3034 //=============================================================================
3035 //function : VComputeHLR
3037 //=============================================================================
3039 static int VComputeHLR (Draw_Interpretor& di,
3040 Standard_Integer argc,
3043 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3045 if (aContextAIS.IsNull ())
3047 di << "Please call vinit before\n";
3051 if ( argc != 3 && argc != 12 )
3053 di << "Usage: " << argv[0] << " ShapeName HlrName "
3054 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3055 << " ShapeName - name of the initial shape\n"
3056 << " HlrName - result hlr object from initial shape\n"
3057 << " eye, dir are eye position and look direction\n"
3058 << " up is the look up direction vector\n"
3059 << " Use vtop to see projected hlr shape\n";
3063 // shape and new object name
3064 TCollection_AsciiString aShapeName (argv[1]);
3065 TCollection_AsciiString aHlrName (argv[2]);
3067 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3070 BRep_Builder aBrepBuilder;
3071 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3074 di << "No shape with name " << argv[1] << " found\n";
3079 if (GetMapOfAIS ().IsBound2 (aHlrName))
3081 di << "Presentable object with name " << argv[2] << " already exists\n";
3085 // close local context
3086 if (aContextAIS->HasOpenedContext ())
3087 aContextAIS->CloseLocalContext ();
3089 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3090 HLRBRep_PolyHLRToShape aHLRToShape;
3099 anEye.SetCoord (atof (argv[3]), atof (argv[4]), atof (argv[5]));
3100 aDir.SetCoord (atof (argv[6]), atof (argv[7]), atof (argv[8]));
3101 anUp.SetCoord (atof (argv[9]), atof (argv[10]), atof (argv[11]));
3102 aProjAx.SetLocation (anEye);
3103 aProjAx.SetDirection (aDir);
3104 aProjAx.SetYDirection (anUp);
3110 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3111 Handle(V3d_View) aView = ViewerTest::CurrentView();
3112 Standard_Integer aWidth, aHeight;
3113 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3114 Standard_Real aRightX, aRightY, aRightZ;
3115 aView->Window()->Size (aWidth, aHeight);
3117 aView->ConvertWithProj (aWidth, aHeight/2,
3118 aRightX, aRightY, aRightZ,
3119 aDirX, aDirY, aDirZ);
3121 aView->ConvertWithProj (aWidth/2, aHeight/2,
3122 aCentX, aCentY, aCentZ,
3123 aDirX, aDirY, aDirZ);
3125 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3126 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3127 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3128 aProjAx.SetLocation (anEye);
3129 aProjAx.SetDirection (aDir);
3130 aProjAx.SetXDirection (aRight);
3133 HLRAlgo_Projector aProjector (aProjAx);
3134 aPolyAlgo->Projector (aProjector);
3135 aPolyAlgo->Load (aSh);
3136 aPolyAlgo->Update ();
3138 aHLRToShape.Update (aPolyAlgo);
3140 // make hlr shape from input shape
3141 TopoDS_Compound aHlrShape;
3142 BRep_Builder aBuilder;
3143 aBuilder.MakeCompound (aHlrShape);
3145 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3146 if (!aCompound.IsNull ())
3148 aBuilder.Add (aHlrShape, aCompound);
3151 // extract visible outlines
3152 aCompound = aHLRToShape.OutLineVCompound();
3153 if (!aCompound.IsNull ())
3155 aBuilder.Add (aHlrShape, aCompound);
3158 // create an AIS shape and display it
3159 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3160 GetMapOfAIS().Bind (anObject, aHlrName);
3161 aContextAIS->Display (anObject);
3163 aContextAIS->UpdateCurrentViewer ();
3168 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3169 // manipulating and displaying such an array with AIS context
3170 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3171 class MyPArrayObject : public AIS_InteractiveObject
3176 MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray)
3181 DEFINE_STANDARD_RTTI(MyPArrayObject);
3185 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3186 const Handle(Prs3d_Presentation)& aPresentation,
3187 const Standard_Integer aMode);
3189 void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
3190 const Standard_Integer aMode) {};
3194 Handle(Graphic3d_ArrayOfPrimitives) myArray;
3198 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3199 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3201 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3202 const Handle(Prs3d_Presentation)& aPresentation,
3203 const Standard_Integer aMode)
3205 aPresentation->Clear();
3207 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
3208 aGroup->BeginPrimitives ();
3209 aGroup->AddPrimitiveArray (myArray);
3210 aGroup->EndPrimitives ();
3213 static bool CheckInputCommand (const TCollection_AsciiString theCommand,
3214 const char **theArgStr, int &theArgIndex,
3215 int theArgCount, int theMaxArgs)
3217 // check if there is more elements than expected
3218 if (theArgIndex >= theMaxArgs)
3221 TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
3222 aStrCommand.LowerCase();
3223 if (aStrCommand.Search(theCommand) != 1 ||
3224 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3227 // go to the first data element
3230 // check data if it can be converted to numeric
3231 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3233 aStrCommand = theArgStr[theArgIndex];
3234 if (!aStrCommand.IsRealValue())
3241 //=============================================================================
3242 //function : VDrawPArray
3243 //purpose : Draws primitives array from list of vertexes, bounds, edges
3244 //=============================================================================
3246 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3248 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3249 if (aContextAIS.IsNull())
3251 di << "Call vinit before!\n";
3256 di << "Use: " << argv[0] << " Name TypeOfArray"
3257 << " [vertex] ... [bounds] ... [edges]\n"
3258 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3259 << " trianglefans | trianglestrips | quads |\n"
3260 << " quadstrips | polygons }\n"
3261 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3262 << " [texel={ 't' tx ty }] } \n"
3263 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3264 << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
3268 // read the arguments
3269 Standard_Integer aArgIndex = 1;
3270 TCollection_AsciiString aName (argv[aArgIndex++]);
3271 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3272 const Standard_Integer anArgsFrom = aArgIndex;
3274 // parse number of verticies, bounds, edges
3275 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3276 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3277 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3279 TCollection_AsciiString aCommand;
3280 while (aArgIndex < argc)
3282 aCommand = argv[aArgIndex];
3283 aCommand.LowerCase();
3284 if (!aCommand.IsAscii())
3286 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3287 << "should be an array element: 'v', 'b', 'e' \n";
3292 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3294 // vertex has a normal or normal with color or texel
3295 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3296 hasNormals = Standard_True;
3298 // vertex has a color
3299 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3300 hasVColors = Standard_True;
3302 // vertex has a texel
3303 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3304 hasTexels = Standard_True;
3309 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3312 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3313 hasBColors = Standard_True;
3318 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3320 // edge has a hide flag
3321 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3322 hasInfos = Standard_True;
3331 if (aVertexNum == 0)
3333 di << "You should pass any verticies in the list of array elements\n";
3337 // create an array of primitives by types
3338 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3339 if (anArrayType == "points")
3340 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3341 else if (anArrayType == "segments")
3342 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3343 else if (anArrayType == "polylines")
3344 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3345 hasVColors, hasBColors, hasInfos);
3346 else if (anArrayType == "triangles")
3347 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3348 hasVColors, hasTexels, hasInfos);
3349 else if (anArrayType == "trianglefans")
3350 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3351 hasNormals, hasVColors,
3352 hasBColors, hasTexels);
3353 else if (anArrayType == "trianglestrips")
3354 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3355 hasNormals, hasVColors,
3356 hasBColors, hasTexels);
3357 else if (anArrayType == "quads")
3358 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3359 hasNormals, hasVColors,
3360 hasTexels, hasInfos);
3361 else if (anArrayType == "quadstrips")
3362 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3363 hasNormals, hasVColors,
3364 hasBColors, hasTexels);
3365 else if (anArrayType == "polygons")
3366 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3367 hasNormals, hasVColors, hasBColors,
3368 hasTexels, hasInfos);
3371 di << "Unexpected type of primitiives array\n";
3375 // parse an array of primitives
3376 aArgIndex = anArgsFrom;
3377 while (aArgIndex < argc)
3379 aCommand = argv[aArgIndex];
3380 aCommand.LowerCase();
3381 if (!aCommand.IsAscii())
3385 if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
3387 anArray->AddVertex (atof (argv[aArgIndex - 3]),
3388 atof (argv[aArgIndex - 2]),
3389 atof (argv[aArgIndex - 1]));
3391 // vertex has a normal or normal with color or texel
3392 if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
3393 anArray->SetVertexNormal (anArray->VertexNumber (),
3394 atof (argv[aArgIndex - 3]),
3395 atof (argv[aArgIndex - 2]),
3396 atof (argv[aArgIndex - 1]));
3398 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3399 anArray->SetVertexColor (anArray->VertexNumber (),
3400 atof (argv[aArgIndex - 3]),
3401 atof (argv[aArgIndex - 2]),
3402 atof (argv[aArgIndex - 1]));
3404 if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
3405 anArray->SetVertexTexel (anArray->VertexNumber (),
3406 atof (argv[aArgIndex - 2]),
3407 atof (argv[aArgIndex - 1]));
3410 else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
3412 Standard_Integer aVertCount = atoi (argv[aArgIndex - 1]);
3414 if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
3415 anArray->AddBound (aVertCount,
3416 atof (argv[aArgIndex - 3]),
3417 atof (argv[aArgIndex - 2]),
3418 atof (argv[aArgIndex - 1]));
3421 anArray->AddBound (aVertCount);
3424 else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
3426 Standard_Integer aVertIndex = atoi (argv[aArgIndex - 1]);
3428 // edge has/hasn't hide flag
3429 if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
3430 anArray->AddEdge (aVertIndex, Standard_False);
3432 anArray->AddEdge (aVertIndex, Standard_True);
3439 // create primitives array object
3440 Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
3442 // register the object in map
3443 VDisplayAISObject (aName, aPObject);
3448 //=======================================================================
3449 //function : VSetLocation
3450 //purpose : Change location of AIS interactive object
3451 //=======================================================================
3453 static Standard_Integer VSetLocation (Draw_Interpretor& di,
3454 Standard_Integer argc,
3457 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3458 if (aContext.IsNull())
3460 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3466 di << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
3470 TCollection_AsciiString aName (argv[1]);
3471 Standard_Real aX = atof (argv[2]);
3472 Standard_Real aY = atof (argv[3]);
3473 Standard_Real aZ = atof (argv[4]);
3476 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3477 Handle(AIS_InteractiveObject) anIObj;
3478 if (!aMap.IsBound2 (aName))
3480 di << "Use 'vdisplay' before" << "\n";
3485 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3487 // not an AIS_InteractiveObject
3488 if (anIObj.IsNull())
3490 di << argv[1] << " : Not an AIS interactive object" << "\n";
3495 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
3496 TopLoc_Location aLocation (aTrsf);
3497 aContext->SetLocation (anIObj, aLocation);
3498 aContext->UpdateCurrentViewer();
3504 //===============================================================================================
3505 //function : VConnect
3506 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3507 //Draw arg : vconnect name object Xo Yo Zo Xu Xv Xw Zu Zv Zw
3508 //===============================================================================================
3510 static Standard_Integer VConnect(Draw_Interpretor& di,
3511 Standard_Integer argc,
3517 std::cout << "vconnect error: expect 11 argumnets\n";
3518 return 1; // TCL_ERROR
3521 TCollection_AsciiString aName(argv[1]);
3522 TCollection_AsciiString anOriginObjectName(argv[2]);
3523 if(aName.IsEqual(anOriginObjectName))
3525 std::cout << "vconnect error: equal names for connected objects\n";
3526 return 1; // TCL_ERROR
3528 // Check if the origin shape is not null
3529 Handle(AIS_InteractiveObject) anOriginObject;
3530 if(GetMapOfAIS().IsBound2(anOriginObjectName))
3532 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginObjectName);
3533 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3534 if(anOriginObject.IsNull())
3536 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n!";
3537 return 1; // TCL_ERROR
3541 // Get location data
3542 Standard_Real aXo = atof(argv[3]);
3543 Standard_Real aYo = atof(argv[4]);
3544 Standard_Real aZo = atof(argv[5]);
3545 Standard_Real aXu = atof(argv[6]);
3546 Standard_Real aXv = atof(argv[7]);
3547 Standard_Real aXw = atof(argv[8]);
3548 Standard_Real aZu = atof(argv[9]);
3549 Standard_Real aZv = atof(argv[10]);
3550 Standard_Real aZw = atof(argv[11]);
3552 // Create transformation
3553 gp_Pnt aPoint(aXo, aYo, aZo);
3554 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3555 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3557 std::cout << "vconnect error : XDir expects to be normal to ZDir\n";
3558 return 1; // TCL_ERROR
3560 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3562 aTrsf.SetTransformation(anAx3);
3563 TopLoc_Location aLocation(aTrsf);
3565 // Create connected object
3566 Handle(AIS_ConnectedInteractive) aConnectedObject = new AIS_ConnectedInteractive();
3567 aConnectedObject->Connect(anOriginObject, aLocation);
3569 // Check if there is another object with given name
3570 // and remove it from context
3571 if(GetMapOfAIS().IsBound2(aName))
3573 Handle(AIS_InteractiveObject) anObj =
3574 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3575 TheAISContext()->Remove(anObj, Standard_False);
3576 GetMapOfAIS().UnBind2(aName);
3579 // Bind connected object to its name
3580 GetMapOfAIS().Bind(aConnectedObject, aName);
3582 // Display connected object
3583 TheAISContext()->Display(aConnectedObject);
3588 //===============================================================================================
3589 //function : VConnectShape
3590 //purpose : Creates and displays AIS_ConnectedShape from input shape and location
3591 //Draw arg : vconnectsh name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw
3592 //===============================================================================================
3594 static Standard_Integer VConnectShape(Draw_Interpretor& di,
3595 Standard_Integer argc,
3601 std::cout << "vconnectsh error: expect 11 argumnets\n";
3602 return 1; // TCL_ERROR
3605 TCollection_AsciiString aName(argv[1]);
3606 TCollection_AsciiString anOriginShapeName(argv[2]);
3607 if(aName.IsEqual(anOriginShapeName))
3609 std::cout << "vconnectsh error: equal names for connected shapes\n";
3610 return 1; // TCL_ERROR
3612 // Check if the origin shape is not null
3613 Handle(AIS_InteractiveObject) anOriginShape;
3614 if(GetMapOfAIS().IsBound2(anOriginShapeName))
3616 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginShapeName);
3617 anOriginShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3618 if(anOriginShape.IsNull())
3620 std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
3621 return 1; // TCL_ERROR
3625 // Get location data
3626 Standard_Real aXo = atof(argv[3]);
3627 Standard_Real aYo = atof(argv[4]);
3628 Standard_Real aZo = atof(argv[5]);
3629 Standard_Real aXu = atof(argv[6]);
3630 Standard_Real aXv = atof(argv[7]);
3631 Standard_Real aXw = atof(argv[8]);
3632 Standard_Real aZu = atof(argv[9]);
3633 Standard_Real aZv = atof(argv[10]);
3634 Standard_Real aZw = atof(argv[11]);
3636 // Create transformation
3637 gp_Pnt aPoint(aXo, aYo, aZo);
3638 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3639 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3641 std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n";
3642 return 1; // TCL_ERROR
3644 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3646 aTrsf.SetTransformation(anAx3);
3647 TopLoc_Location aLocation(aTrsf);
3649 // Create connected shape
3650 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anOriginShape);
3651 Handle(AIS_ConnectedShape) aConnectedShape = new AIS_ConnectedShape(aShape);
3652 aConnectedShape->Connect(anOriginShape, aLocation);
3654 // Check if there is another object with given name
3655 // and remove it from context
3656 if(GetMapOfAIS().IsBound2(aName))
3658 Handle(AIS_InteractiveObject) anObj =
3659 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3660 TheAISContext()->Remove(anObj, Standard_False);
3661 GetMapOfAIS().UnBind2(aName);
3664 // Bind connected shape to its name
3665 GetMapOfAIS().Bind(aConnectedShape, aName);
3667 // Display connected shape
3668 TheAISContext()->Display(aConnectedShape);
3673 //===============================================================================================
3674 //function : VSetSelectionMode
3675 //purpose : Sets input selection mode for input object or for all displayed objects
3676 //Draw arg : vselmode [object] mode On/Off (1/0)
3677 //===============================================================================================
3679 // function : InList
3680 // purpose : checks if theMode is already turned on for theObj
3681 Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext,
3682 Handle(AIS_InteractiveObject) theObj,
3683 Standard_Integer theMode)
3685 TColStd_ListOfInteger anArray;
3686 theAISContext->ActivatedModes(theObj, anArray);
3687 TColStd_ListIteratorOfListOfInteger anIt(anArray);
3688 for(; anIt.More(); anIt.Next())
3690 if(anIt.Value() == theMode)
3691 return Standard_True;
3693 return Standard_False;
3696 static Standard_Integer VSetSelectionMode(Draw_Interpretor& di,
3697 Standard_Integer argc,
3701 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3702 if(anAISContext.IsNull())
3704 std::cout << "Call vinit before!\n";
3705 return 1; // TCL_ERROR
3708 // Check the arguments
3709 if(argc != 3 && argc != 4)
3711 std::cout << "vselmode error : expects at least 2 arguments\n";
3712 return 1; // TCL_ERROR
3715 Handle(AIS_InteractiveObject) anObj;
3717 // Set new selection mode for all objects in context
3721 Standard_Integer aMode = atoi(argv[1]);
3722 Standard_Boolean isTurnOn = atoi(argv[2]);
3724 // Get all displayed objects
3725 AIS_ListOfInteractive anObjList;
3726 anAISContext->DisplayedObjects(anObjList);
3727 AIS_ListIteratorOfListOfInteractive anObjIter;
3731 if(anAISContext->HasOpenedContext())
3732 anAISContext->CloseLocalContext();
3736 if(aMode != 0 && isTurnOn)
3738 if(!anAISContext->HasOpenedContext())
3740 anAISContext->OpenLocalContext();
3741 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3743 anAISContext->Activate(anObjIter.Value(), aMode);
3748 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3750 anObj = anObjIter.Value();
3751 if(!InList(anAISContext, anObj, aMode))
3752 anAISContext->Activate(anObj, aMode);
3758 if(aMode != 0 && !isTurnOn)
3760 if(anAISContext->HasOpenedContext())
3762 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3764 anObj = anObjIter.Value();
3765 if(InList(anAISContext, anObj, aMode))
3766 anAISContext->Deactivate(anObj, aMode);
3772 // Set new selection mode for named object
3776 Standard_Integer aMode = atoi(argv[2]);
3777 Standard_Boolean isTurnOn = atoi(argv[3]);
3778 TCollection_AsciiString aName(argv[1]);
3780 // Check if there is an object with given name in context
3781 if(GetMapOfAIS().IsBound2(aName))
3783 anObj = Handle(AIS_InteractiveObject)::
3784 DownCast(GetMapOfAIS().Find2(aName));
3787 std::cout << "vselmode error : object name is used for non AIS viewer\n";
3788 return 1; // TCL_ERROR
3794 if(anAISContext->HasOpenedContext())
3795 anAISContext->CloseLocalContext();
3798 if(aMode != 0 && isTurnOn)
3800 if(!anAISContext->HasOpenedContext())
3802 anAISContext->OpenLocalContext();
3803 anAISContext->Activate(anObj, aMode);
3807 if(!InList(anAISContext, anObj, aMode))
3808 anAISContext->Activate(anObj, aMode);
3813 if(aMode != 0 && !isTurnOn)
3815 if(anAISContext->HasOpenedContext())
3817 if(InList(anAISContext, anObj, aMode))
3818 anAISContext->Deactivate(anObj, aMode);
3825 //==========================================================================
3827 //purpose : creates Triangle based on AIS_InteractiveObject.
3828 // This class was implemented for testing Select3D_SensitiveTriangle
3829 //===========================================================================
3830 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3831 class Triangle: public AIS_InteractiveObject
3835 DEFINE_STANDARD_RTTI(FilledCircle);
3836 Triangle (const gp_Pnt& theP1,
3837 const gp_Pnt& theP2,
3838 const gp_Pnt& theP3);
3840 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3841 const Handle(Prs3d_Presentation)& thePresentation,
3842 const Standard_Integer theMode);
3844 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
3845 const Standard_Integer theMode);
3851 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3852 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
3854 Triangle::Triangle (const gp_Pnt& theP1,
3855 const gp_Pnt& theP2,
3856 const gp_Pnt& theP3)
3863 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3864 const Handle(Prs3d_Presentation)& thePresentation,
3865 const Standard_Integer theMode)
3867 thePresentation->Clear();
3869 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
3870 anEdgeMaker2(myPoint2, myPoint3),
3871 anEdgeMaker3(myPoint3, myPoint1);
3873 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
3874 anEdge2 = anEdgeMaker2.Edge(),
3875 anEdge3 = anEdgeMaker3.Edge();
3876 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
3879 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
3880 TopoDS_Wire aWire = aWireMaker.Wire();
3881 if(aWire.IsNull()) return;
3883 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
3884 TopoDS_Face aFace = aFaceMaker.Face();
3885 if(aFace.IsNull()) return;
3887 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
3890 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
3891 const Standard_Integer theMode)
3893 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
3894 Handle(Select3D_SensitiveTriangle) aSensTriangle =
3895 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
3896 theSelection->Add(aSensTriangle);
3899 //===========================================================================
3900 //function : VTriangle
3901 //Draw arg : vtriangle Name PointName PointName PointName
3902 //purpose : creates and displays Triangle
3903 //===========================================================================
3906 //purpose : checks if the object with theName is AIS_Point,
3907 // if yes initialize thePoint from MapOfAIS
3908 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
3909 Handle(AIS_Point)& thePoint)
3911 Handle(AIS_InteractiveObject) anObject =
3912 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
3913 if(anObject.IsNull() ||
3914 anObject->Type() != AIS_KOI_Datum ||
3915 anObject->Signature() != 1)
3917 return Standard_False;
3919 thePoint = Handle(AIS_Point)::DownCast(anObject);
3920 if(thePoint.IsNull())
3921 return Standard_False;
3922 return Standard_True;
3926 //purpose: checks if thePoint1 is equal to thePoint2
3927 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
3928 const Handle(Geom_CartesianPoint)& thePoint2)
3930 if(abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
3931 abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
3932 abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
3934 return Standard_True;
3936 return Standard_False;
3939 static Standard_Integer VTriangle (Draw_Interpretor& di,
3940 Standard_Integer argc,
3946 std::cout<<"vtriangle error: expects 4 argumnets\n";
3947 return 1; // TCL_ERROR
3950 TheAISContext()->CloseAllContexts();
3952 // Get and check values
3953 TCollection_AsciiString aName(argv[1]);
3955 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
3956 if (!IsPoint(argv[2], aPoint1))
3958 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
3959 return 1; // TCL_ERROR
3961 if (!IsPoint(argv[3], aPoint2))
3963 std::cout<<"vtriangle error: the 3d argument must be a point\n";
3964 return 1; // TCL_ERROR
3966 if (!IsPoint(argv[4], aPoint3))
3968 std::cout<<"vtriangle error: the 4th argument must be a point\n";
3969 return 1; // TCL_ERROR
3972 // Check that points are different
3973 Handle(Geom_CartesianPoint) aCartPoint1 =
3974 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
3975 Handle(Geom_CartesianPoint) aCartPoint2 =
3976 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
3977 // Test aPoint1 = aPoint2
3978 if (IsMatch(aCartPoint1, aCartPoint2))
3980 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
3981 return 1; // TCL_ERROR
3983 // Test aPoint2 = aPoint3
3984 Handle(Geom_CartesianPoint) aCartPoint3 =
3985 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
3986 if (IsMatch(aCartPoint2, aCartPoint3))
3988 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
3989 return 1; // TCL_ERROR
3991 // Test aPoint3 = aPoint1
3992 if (IsMatch(aCartPoint1, aCartPoint3))
3994 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
3995 return 1; // TCL_ERROR
3999 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4001 aCartPoint3->Pnt());
4003 // Check if there is an object with given name
4004 // and remove it from context
4005 if (GetMapOfAIS().IsBound2(aName))
4007 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4008 Handle(AIS_InteractiveObject) anInterObj =
4009 Handle(AIS_InteractiveObject)::DownCast(anObj);
4010 TheAISContext()->Remove(anInterObj, Standard_False);
4011 GetMapOfAIS().UnBind2(aName);
4014 // Bind triangle to its name
4015 GetMapOfAIS().Bind(aTriangle, aName);
4018 TheAISContext()->Display(aTriangle);
4022 //class : SegmentObject
4023 //purpose: creates segment based on AIS_InteractiveObject.
4024 // This class was implemented for testing Select3D_SensitiveCurve
4025 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4026 class SegmentObject: public AIS_InteractiveObject
4030 DEFINE_STANDARD_RTTI(SegmentObject);
4031 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4033 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4034 const Handle(Prs3d_Presentation)& thePresentation,
4035 const Standard_Integer theMode);
4037 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4038 const Standard_Integer theMode);
4043 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4044 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4046 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4052 void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
4053 const Handle_Prs3d_Presentation &thePresentation,
4054 const Standard_Integer theMode)
4056 thePresentation->Clear();
4057 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4058 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4059 if (anEdge.IsNull())
4061 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4062 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4065 void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
4066 const Standard_Integer theMode)
4068 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4069 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4070 anArray->SetValue(1, myPoint1);
4071 anArray->SetValue(2, myPoint2);
4072 Handle(Select3D_SensitiveCurve) aSensCurve =
4073 new Select3D_SensitiveCurve(anOwner, anArray);
4074 theSelection->Add(aSensCurve);
4077 //=======================================================================
4078 //function : VSegment
4079 //Draw args : vsegment Name PointName PointName
4080 //purpose : creates and displays Segment
4081 //=======================================================================
4082 static Standard_Integer VSegment (Draw_Interpretor& di,
4083 Standard_Integer argc,
4089 std::cout<<"vsegment error: expects 3 arguments\n";
4090 return 1; // TCL_ERROR
4093 TheAISContext()->CloseAllContexts();
4095 // Get and check arguments
4096 TCollection_AsciiString aName(argv[1]);
4097 Handle(AIS_Point) aPoint1, aPoint2;
4098 if (!IsPoint(argv[2], aPoint1))
4100 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4101 return 1; // TCL_ERROR
4103 if (!IsPoint(argv[3], aPoint2))
4105 std::cout<<"vsegment error: the 3d argument should be a point\n";
4106 return 1; // TCL_ERROR
4108 //Check that points are different
4109 Handle(Geom_CartesianPoint) aCartPoint1 =
4110 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4111 Handle(Geom_CartesianPoint) aCartPoint2 =
4112 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4113 if(IsMatch(aCartPoint1, aCartPoint2))
4115 std::cout<<"vsegment error: equal points\n";
4116 return 1; // TCL_ERROR
4120 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4121 // Check if there is an object with given name
4122 // and remove it from context
4123 if (GetMapOfAIS().IsBound2(aName))
4125 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4126 Handle(AIS_InteractiveObject) anInterObj =
4127 Handle(AIS_InteractiveObject)::DownCast(anObj);
4128 TheAISContext()->Remove(anInterObj, Standard_False);
4129 GetMapOfAIS().UnBind2(aName);
4132 // Bind segment to its name
4133 GetMapOfAIS().Bind(aSegment, aName);
4136 TheAISContext()->Display(aSegment);
4140 //=======================================================================
4141 //function : VObjZLayer
4142 //purpose : Set or get z layer id for presentable object
4143 //=======================================================================
4145 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4146 Standard_Integer argc,
4149 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4150 if (aContext.IsNull())
4152 di << argv[0] << "Call 'vinit' before!\n";
4157 TCollection_AsciiString aOperation;
4159 aOperation = TCollection_AsciiString (argv [1]);
4161 // check for correct arguments
4162 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4163 !(argc == 3 && aOperation.IsEqual ("get")))
4165 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4166 di << " set - set layer id for interactive object, layerid - z layer id\n";
4167 di << " get - get layer id of interactive object\n";
4168 di << " argument layerid should be passed for set operation only\n";
4173 TCollection_AsciiString aName (argv[2]);
4174 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4175 if (!aMap.IsBound2 (aName))
4177 di << "Use 'vdisplay' before" << "\n";
4181 // find interactive object
4182 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4183 Handle(AIS_InteractiveObject) anInterObj =
4184 Handle(AIS_InteractiveObject)::DownCast (anObj);
4185 if (anInterObj.IsNull())
4187 di << "Not an AIS interactive object!\n";
4191 // process operation
4192 if (aOperation.IsEqual ("set"))
4194 Standard_Integer aLayerId = atoi (argv [3]);
4195 aContext->SetZLayer (anInterObj, aLayerId);
4197 else if (aOperation.IsEqual ("get"))
4199 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4205 //=======================================================================
4206 //function : VPolygonOffset
4207 //purpose : Set or get polygon offset parameters
4208 //=======================================================================
4209 static Standard_Integer VPolygonOffset(Draw_Interpretor& di,
4210 Standard_Integer argc,
4213 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4214 if (aContext.IsNull())
4216 std::cout << argv[0] << " Call 'vinit' before!\n";
4220 if (argc > 2 && argc != 5)
4222 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4223 "without arguments prints the default values" << std::endl;
4228 Handle(AIS_InteractiveObject) anInterObj;
4231 TCollection_AsciiString aName (argv[1]);
4232 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4233 if (!aMap.IsBound2 (aName))
4235 std::cout << "Use 'vdisplay' before" << std::endl;
4239 // find interactive object
4240 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4241 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4242 if (anInterObj.IsNull())
4244 std::cout << "Not an AIS interactive object!" << std::endl;
4249 Standard_Integer aMode;
4250 Standard_ShortReal aFactor, aUnits;
4253 aMode = atoi(argv[2]);
4254 aFactor = (Standard_ShortReal) atof(argv[3]);
4255 aUnits = (Standard_ShortReal) atof(argv[4]);
4257 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4258 aContext->UpdateCurrentViewer();
4263 if (anInterObj->HasPolygonOffsets())
4265 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4266 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4267 std::cout << "\tMode: " << aMode << std::endl;
4268 std::cout << "\tFactor: " << aFactor << std::endl;
4269 std::cout << "\tUnits: " << aUnits << std::endl;
4274 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4278 std::cout << "Default polygon offset parameters:" << std::endl;
4279 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4280 std::cout << "\tMode: " << aMode << std::endl;
4281 std::cout << "\tFactor: " << aFactor << std::endl;
4282 std::cout << "\tUnits: " << aUnits << std::endl;
4287 //=======================================================================
4288 //function : VShowFaceBoundaries
4289 //purpose : Set face boundaries drawing on/off for ais object
4290 //=======================================================================
4291 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& di,
4292 Standard_Integer argc,
4295 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4296 if (aContext.IsNull ())
4298 std::cout << argv[0] << " Call 'vinit' before!\n";
4302 if ((argc != 3 && argc < 6) || argc > 8)
4304 std::cout << "Usage :\n " << argv[0]
4305 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4306 << " ObjectName - name of AIS interactive object. \n"
4307 << " if ObjectName = \"\", then set as default\n"
4308 << " settings for all newly displayed objects\n"
4309 << " isOn - flag indicating whether the boundaries\n"
4310 << " should be turned on or off (can be set\n"
4311 << " to 0 (off) or 1 (on)).\n"
4312 << " R, G, B - red, green and blue components of boundary\n"
4313 << " color in range (0 - 255).\n"
4314 << " (default is (0, 0, 0)\n"
4315 << " LineWidth - line width\n"
4316 << " (default is 1)\n"
4317 << " LineStyle - line fill style :\n"
4322 << " (default is solid)";
4326 TCollection_AsciiString aName (argv[1]);
4328 Quantity_Parameter aRed = 0.0;
4329 Quantity_Parameter aGreen = 0.0;
4330 Quantity_Parameter aBlue = 0.0;
4331 Standard_Real aWidth = 1.0;
4332 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4335 Handle(AIS_InteractiveObject) anInterObj;
4337 // if name is empty - apply attributes for default aspect
4338 if (!aName.IsEmpty ())
4340 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4341 if (!aMap.IsBound2 (aName))
4343 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4347 // find interactive object
4348 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4349 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4350 if (anInterObj.IsNull ())
4352 std::cout << "Not an AIS interactive object!" << std::endl;
4357 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4358 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4360 // turn boundaries on/off
4361 Standard_Boolean isBoundaryDraw = (atoi (argv[2]) == 1);
4362 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4364 // set boundary line color
4368 aRed = atof (argv[3])/255.;
4369 aGreen = atof (argv[4])/255.;
4370 aBlue = atof (argv[5])/255.;
4376 aWidth = (Standard_Real)atof (argv[6]);
4379 // select appropriate line type
4382 switch (atoi (argv[7]))
4384 case 1: aLineType = Aspect_TOL_DASH; break;
4385 case 2: aLineType = Aspect_TOL_DOT; break;
4386 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4388 aLineType = Aspect_TOL_SOLID;
4392 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4394 Handle(Prs3d_LineAspect) aBoundaryAspect =
4395 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4397 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4399 TheAISContext()->Redisplay (anInterObj);
4404 //=======================================================================
4405 //function : ObjectsCommands
4407 //=======================================================================
4409 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
4411 const char *group ="AISObjects";
4412 theCommands.Add("vtrihedron",
4413 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
4414 __FILE__,VTrihedron,group);
4416 theCommands.Add("vtri2d",
4417 "vtri2d Name Selection in the viewer only ",
4418 __FILE__,VTrihedron2D ,group);
4420 theCommands.Add("vplanetri",
4421 "vplanetri Name Selection in the viewer only ",
4422 __FILE__,VPlaneTrihedron ,group);
4424 theCommands.Add("vsize",
4425 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
4426 __FILE__,VSize,group);
4428 theCommands.Add("vaxis",
4429 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
4430 __FILE__,VAxisBuilder,group);
4432 theCommands.Add("vaxispara",
4434 __FILE__,VAxisBuilder,group);
4436 theCommands.Add("vaxisortho",
4438 __FILE__,VAxisBuilder,group);
4440 theCommands.Add("vpoint",
4441 "vpoint PointName [Xa] [Ya] [Za] ",
4442 __FILE__,VPointBuilder,group);
4444 theCommands.Add("vplane",
4445 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
4446 __FILE__,VPlaneBuilder,group);
4448 theCommands.Add("vplanepara",
4449 "vplanepara PlaneName ",
4450 __FILE__,VPlaneBuilder,group);
4452 theCommands.Add("vplaneortho",
4453 "vplaneortho PlaneName ",
4454 __FILE__,VPlaneBuilder,group);
4456 theCommands.Add("vline",
4457 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
4458 __FILE__,VLineBuilder,group);
4460 theCommands.Add("vcircle",
4461 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
4462 __FILE__,VCircleBuilder,group);
4464 theCommands.Add("vdrawtext",
4465 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
4466 __FILE__,VDrawText,group);
4468 theCommands.Add("vdrawsphere",
4469 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n",
4470 __FILE__,VDrawSphere,group);
4472 theCommands.Add("vclipplane",
4473 "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
4474 __FILE__,VClipPlane,group);
4476 theCommands.Add ("vsetlocation",
4477 "vsetlocation : name x y z; set new location for an interactive object",
4478 __FILE__, VSetLocation, group);
4482 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
4483 __FILE__, VComputeHLR, group);
4485 theCommands.Add("vdrawparray",
4486 "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' }] ]",
4487 __FILE__,VDrawPArray,group);
4489 theCommands.Add("vconnect",
4490 "vconnect : name object Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4491 __FILE__, VConnect, group);
4493 theCommands.Add("vconnectsh",
4494 "vconnectsh : name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw",
4495 __FILE__, VConnectShape, group);
4497 theCommands.Add("vselmode",
4498 "vselmode : [object] mode On/Off (1/0)",
4499 __FILE__, VSetSelectionMode, group);
4501 theCommands.Add("vtriangle",
4502 "vtriangle Name PointName PointName PointName",
4503 __FILE__, VTriangle,group);
4505 theCommands.Add("vsegment",
4506 "vsegment Name PointName PointName",
4507 __FILE__, VSegment,group);
4509 theCommands.Add("vobjzlayer",
4510 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
4511 __FILE__, VObjZLayer, group);
4513 theCommands.Add("vpolygonoffset",
4514 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
4515 __FILE__, VPolygonOffset, group);
4517 theCommands.Add ("vshowfaceboundary",
4518 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
4519 "- turns on/off drawing of face boundaries for ais object "
4520 "and defines boundary line style.",
4521 __FILE__, VShowFaceBoundary, group);