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.
25 #include <ViewerTest.hxx>
29 #include <Quantity_NameOfColor.hxx>
30 #include <Draw_Interpretor.hxx>
32 #include <Draw_Appli.hxx>
35 #include <Font_BRepFont.hxx>
36 #include <OSD_Chronometer.hxx>
37 #include <TCollection_AsciiString.hxx>
38 #include <Visual3d_View.hxx>
39 #include <V3d_Viewer.hxx>
40 #include <V3d_View.hxx>
43 #include <AIS_Shape.hxx>
44 #include <AIS_DisplayMode.hxx>
45 #include <TColStd_MapOfInteger.hxx>
46 #include <AIS_MapOfInteractive.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
49 #include <ViewerTest_EventManager.hxx>
51 #include <TopoDS_Solid.hxx>
52 #include <BRepTools.hxx>
53 #include <BRep_Builder.hxx>
54 #include <TopAbs_ShapeEnum.hxx>
57 #include <BRep_Tool.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <BRepAdaptor_Curve.hxx>
61 #include <BRepAdaptor_Surface.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Face.hxx>
69 #include <Draw_Window.hxx>
70 #include <AIS_ListIteratorOfListOfInteractive.hxx>
71 #include <AIS_ListOfInteractive.hxx>
72 #include <AIS_DisplayMode.hxx>
73 #include <AIS_Shape.hxx>
75 #include <AIS_InteractiveContext.hxx>
76 #include <Geom_Plane.hxx>
78 #include <TCollection_ExtendedString.hxx>
79 #include <GC_MakePlane.hxx>
80 #include <gp_Circ.hxx>
81 #include <AIS_Axis.hxx>
82 #include <Geom_Axis2Placement.hxx>
83 #include <Geom_Axis1Placement.hxx>
84 #include <AIS_Trihedron.hxx>
85 #include <AIS_Axis.hxx>
86 #include <gp_Trsf.hxx>
87 #include <TopLoc_Location.hxx>
89 #include <HLRAlgo_Projector.hxx>
90 #include <HLRBRep_PolyAlgo.hxx>
91 #include <HLRBRep_PolyHLRToShape.hxx>
92 #include <Aspect_Window.hxx>
94 #include <Graphic3d_ArrayOfPoints.hxx>
95 #include <Graphic3d_ArrayOfSegments.hxx>
96 #include <Graphic3d_ArrayOfPolylines.hxx>
97 #include <Graphic3d_ArrayOfTriangles.hxx>
98 #include <Graphic3d_ArrayOfTriangleFans.hxx>
99 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
100 #include <Graphic3d_ArrayOfQuadrangles.hxx>
101 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
102 #include <Graphic3d_ArrayOfPolygons.hxx>
103 #include <Graphic3d_AspectMarker3d.hxx>
104 #include <Graphic3d_Group.hxx>
105 #include <Standard_Real.hxx>
107 #include <AIS_Circle.hxx>
108 #include <AIS_Drawer.hxx>
109 #include <BRepBuilderAPI_MakeEdge.hxx>
110 #include <BRepBuilderAPI_MakeFace.hxx>
111 #include <BRepBuilderAPI_MakeWire.hxx>
112 #include <Geom_Circle.hxx>
113 #include <GC_MakeCircle.hxx>
114 #include <Prs3d_Presentation.hxx>
115 #include <Select3D_SensitiveCircle.hxx>
116 #include <SelectMgr_EntityOwner.hxx>
117 #include <SelectMgr_Selection.hxx>
118 #include <StdFail_NotDone.hxx>
119 #include <StdPrs_ShadedShape.hxx>
120 #include <TopoDS_Wire.hxx>
122 #include <AIS_ConnectedShape.hxx>
123 #include <AIS_MultipleConnectedInteractive.hxx>
124 #include <AIS_MultipleConnectedShape.hxx>
125 #include <TopLoc_Location.hxx>
126 #include <TColStd_ListOfInteger.hxx>
127 #include <TColStd_ListIteratorOfListOfInteger.hxx>
129 #include <Select3D_SensitiveTriangle.hxx>
130 #include <Select3D_SensitiveCurve.hxx>
131 #include <Select3D_SensitivePoint.hxx>
132 #include <BRepAdaptor_Curve.hxx>
133 #include <StdPrs_Curve.hxx>
135 #include <BRepExtrema_ExtPC.hxx>
136 #include <BRepExtrema_ExtPF.hxx>
138 #include <Prs3d_LineAspect.hxx>
139 #include <Prs3d_PointAspect.hxx>
141 #include <Image_AlienPixMap.hxx>
142 #include <TColStd_HArray1OfAsciiString.hxx>
144 #ifdef HAVE_STRINGS_H
149 #define _CRT_SECURE_NO_DEPRECATE
150 #pragma warning (disable:4996)
153 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
154 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
155 const Handle(AIS_InteractiveObject)& theAISObj,
156 Standard_Boolean theReplaceIfExists = Standard_True);
157 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
158 extern Handle(AIS_InteractiveContext)& TheAISContext();
161 //==============================================================================
162 //function : Vtrihedron 2d
163 //purpose : Create a plane with a 2D trihedron from a faceselection
164 //Draw arg : vtri2d name
165 //==============================================================================
166 #include <AIS_PlaneTrihedron.hxx>
170 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
173 // Verification des arguments
174 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
177 Standard_Integer myCurrentIndex;
178 // Fermeture des contextes
179 TheAISContext()->CloseAllContexts();
180 // Ouverture d'un contexte local et recuperation de son index.
181 TheAISContext()->OpenLocalContext();
182 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
183 // On active les modes de selections faces.
184 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
185 di<<" Select a face ."<<"\n";
187 // Boucle d'attente waitpick.
188 Standard_Integer argccc = 5;
189 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
190 const char **argvvv = (const char **) bufff;
191 while (ViewerMainLoop( argccc, argvvv) ) { }
195 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
196 ShapeB = TheAISContext()->SelectedShape();
199 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
201 // Construction du Plane
202 // recuperation des edges des faces.
203 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
205 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
209 // si il y a plusieurs edges
210 if (FaceExpB.More() ) {
212 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
213 BRepAdaptor_Curve theCurveB(EdgeB);
214 BRepAdaptor_Curve theCurveC(EdgeC);
215 A=theCurveC.Value(0.1);
216 B=theCurveC.Value(0.9);
217 C=theCurveB.Value(0.5);
220 // FaceB a 1 unique edge courbe
221 BRepAdaptor_Curve theCurveB(EdgeB);
222 A=theCurveB.Value(0.1);
223 B=theCurveB.Value(0.9);
224 C=theCurveB.Value(0.5);
226 // Construction du Geom_Plane
227 GC_MakePlane MkPlane(A,B,C);
228 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
230 // Construction de l'AIS_PlaneTrihedron
231 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
233 // Fermeture du contexte local.
234 TheAISContext()->CloseLocalContext(myCurrentIndex);
236 // on le display & bind
237 TheAISContext()->Display(theAISPlaneTri );
238 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
245 //==============================================================================
246 //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& theDi,
253 Standard_Integer theArgsNb,
254 const char** theArgVec)
256 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
258 theDi << theArgVec[0] << " Syntax error\n";
262 gp_Pnt anOrigin (0.0, 0.0, 0.0);
263 gp_Dir aDirZ = gp::DZ();
264 gp_Dir aDirX = gp::DX();
265 Standard_Integer anArgIter = 2; // 1st is an IO name
266 if (anArgIter < theArgsNb)
268 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
269 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
270 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
271 if (anArgIter < theArgsNb)
273 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
274 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
275 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
276 aDirZ.SetCoord (aX, aY, aZ);
278 aX = Draw::Atof (theArgVec[anArgIter++]);
279 aY = Draw::Atof (theArgVec[anArgIter++]);
280 aZ = Draw::Atof (theArgVec[anArgIter++]);
281 aDirX.SetCoord (aX, aY, aZ);
285 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
287 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
291 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
292 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
293 VDisplayAISObject (theArgVec[1], 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 = Quantity_NOC_BLACK ;
317 // Verification des arguments
318 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
320 // Verification du nombre d'arguments
321 if (argc==1) {ThereIsName=Standard_False;value=100;}
322 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
323 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
325 // On ferme le contexte local pour travailler dans le contexte global
326 if(TheAISContext()->HasOpenedContext())
327 TheAISContext()->CloseLocalContext();
329 // On set le booleen ThereIsCurrent
330 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
331 else {ThereIsCurrent=Standard_False;}
335 //===============================================================
336 // Il n'y a pas de nom mais des objets selectionnes
337 //===============================================================
338 if (!ThereIsName && ThereIsCurrent)
341 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
344 while ( it.More() ) {
346 Handle(AIS_InteractiveObject) aShape=
347 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
349 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
352 // On verifie que l'AIS InteraciveObject selectionne est bien
354 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
356 if (aShape->HasColor()) {
357 hascol=Standard_True;
359 // On recupere la couleur de aShape
360 col=aShape->Color();}
362 else hascol=Standard_False;
364 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
365 // pour lui appliquer la methode SetSize()
366 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
368 // C'est bien un triedre,on chage sa valeur!
369 aTrihedron->SetSize(value);
371 // On donne la couleur au Trihedron
372 if(hascol) aTrihedron->SetColor(col);
373 else aTrihedron->UnsetColor();
376 // The trihedron hasn't be errased from the map
377 // so you just have to redisplay it
378 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
387 TheAISContext() ->UpdateCurrentViewer();
390 //===============================================================
391 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
392 //===============================================================
396 //===============================================================
397 // Il y a un nom de triedre passe en argument
398 //===============================================================
400 TCollection_AsciiString name=argv[1];
402 // on verifie que ce nom correspond bien a une shape
403 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
407 // on recupere la shape dans la map des objets displayes
408 Handle(AIS_InteractiveObject) aShape =
409 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
411 // On verifie que l'AIS InteraciveObject est bien
413 if (!aShape.IsNull() &&
414 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
417 if (aShape->HasColor()) {
418 hascol=Standard_True;
420 // On recupere la couleur de aShape
421 col=aShape->Color();}
423 else hascol=Standard_False;
425 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
426 // pour lui appliquer la methode SetSize()
427 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
429 // C'est bien un triedre,on chage sa valeur
430 aTrihedron->SetSize(value);
432 // On donne la couleur au Trihedron
433 if(hascol) aTrihedron->SetColor(col);
434 else aTrihedron->UnsetColor();
436 // The trihedron hasn't be errased from the map
437 // so you just have to redisplay it
438 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
440 TheAISContext() ->UpdateCurrentViewer();
448 //==============================================================================
450 //==============================================================================
451 //function : VPlaneTrihedron
452 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
453 //Draw arg : vplanetri name
454 //==============================================================================
455 #include <AIS_Plane.hxx>
459 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
462 // Verification des arguments
463 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
466 Standard_Integer myCurrentIndex;
467 // Fermeture des contextes locaux
468 TheAISContext()->CloseAllContexts();
470 // On recupere tous les trihedrons de la GetMapOfAIS()
471 // et on active le mode de selection par face.
472 // =================================================
474 // Ouverture d'un contexte local et recuperation de son index.
475 TheAISContext()->OpenLocalContext(Standard_False);
476 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
478 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
481 Handle(AIS_InteractiveObject) ShapeA =
482 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
483 // On verifie que c'est bien un trihedron
484 if (!ShapeA.IsNull() &&
485 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
487 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
488 // on le charge dans le contexte et on active le mode Plane.
489 TheAISContext()->Load(TrihedronA,0,Standard_False);
490 TheAISContext()->Activate(TrihedronA,3);
495 di<<" Select a plane."<<"\n";
496 // Boucle d'attente waitpick.
497 Standard_Integer argccc = 5;
498 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
499 const char **argvvv = (const char **) bufff;
500 while (ViewerMainLoop( argccc, argvvv) ) { }
503 Handle(AIS_InteractiveObject) theIOB;
504 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
505 theIOB = TheAISContext()->Interactive();
508 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
510 // Fermeture du contexte local.
511 TheAISContext()->CloseLocalContext(myCurrentIndex);
513 // on le display & bind
514 TheAISContext()->Display(PlaneB );
515 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
522 //==============================================================================
523 // Fonction First click 2de click
525 // vaxis vertex vertex
527 // vaxispara edge vertex
528 // vaxisortho edge Vertex
529 // vaxisinter Face Face
530 //==============================================================================
532 //==============================================================================
533 //function : VAxisBuilder
535 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
536 //==============================================================================
537 #include <TopoDS_Edge.hxx>
538 #include <TopoDS_Vertex.hxx>
539 #include <TopExp.hxx>
540 #include <Geom_Line.hxx>
542 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
545 Standard_Boolean HasArg;
546 TCollection_AsciiString name;
547 Standard_Integer MyCurrentIndex;
550 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
551 if (argc==8) HasArg=Standard_True;
552 else HasArg=Standard_False;
555 // Fermeture des contextes
556 TheAISContext()->CloseAllContexts();
558 // Cas ou il y a des arguments
559 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
561 Standard_Real coord[6];
562 for(Standard_Integer i=0;i<=5;i++){
563 coord[i]=Draw::Atof(argv[2+i]);
565 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
567 gp_Vec myVect (p1,p2);
568 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
569 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
570 GetMapOfAIS().Bind (TheAxis,name);
571 TheAISContext()->Display(TheAxis);
577 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
578 if ( !strcasecmp(argv[0], "vaxis")) {
579 TheAISContext()->OpenLocalContext();
580 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
582 // Active le mode edge et le mode vertex
583 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
584 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
585 di<<" Select an edge or a vertex."<<"\n";
587 // Boucle d'attente waitpick.
588 Standard_Integer argcc = 5;
589 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
590 const char **argvv = (const char **) buff;
591 while (ViewerMainLoop( argcc, argvv) ) { }
594 // recuperation de la shape.
596 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
597 ShapeA = TheAISContext()->SelectedShape();
599 // recuperation de l'AIS_InteractiveObject
600 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
601 // down cast en AIS_Point si sig et type
602 // AIS_Point -> Geom_Pnt ....
604 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
605 // on desactive le mode edge
606 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
607 di<<" Select a different vertex."<<"\n";
611 // Boucle d'attente waitpick.
612 Standard_Integer argccc = 5;
613 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
614 const char **argvvv = (const char **) bufff;
615 while (ViewerMainLoop( argccc, argvvv) ) { }
617 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
618 ShapeB = TheAISContext()->SelectedShape();
622 } while(ShapeB.IsSame(ShapeA) );
624 // Fermeture du context local
625 TheAISContext()->CloseLocalContext(MyCurrentIndex);
627 // Construction de l'axe
628 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
629 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
632 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
633 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
634 GetMapOfAIS().Bind (TheAxis,name);
635 TheAISContext()->Display(TheAxis);
638 // Un unique edge (ShapeA) a ete picke
639 // Fermeture du context local
640 TheAISContext()->CloseLocalContext(MyCurrentIndex);
641 // Constuction de l'axe
642 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
644 TopExp::Vertices(ed,Va,Vb );
645 gp_Pnt A=BRep_Tool::Pnt(Va);
646 gp_Pnt B=BRep_Tool::Pnt(Vb);
649 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
650 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
651 GetMapOfAIS().Bind (TheAxis,name);
652 TheAISContext()->Display(TheAxis);
658 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
659 else if ( !strcasecmp(argv[0], "vaxispara")) {
661 TheAISContext()->OpenLocalContext();
662 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
664 // Active le mode edge
665 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
666 di<<" Select an edge."<<"\n";
668 // Boucle d'attente waitpick.
669 Standard_Integer argcc = 5;
670 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
671 const char **argvv = (const char **) buff;
672 while (ViewerMainLoop( argcc, argvv) ) { }
676 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
677 ShapeA = TheAISContext()->SelectedShape();
679 // Active le mode vertex et deactive edges
680 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
681 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
682 di<<" Select a vertex."<<"\n";
684 // Boucle d'attente waitpick.
685 Standard_Integer argccc = 5;
686 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
687 const char **argvvv = (const char **) bufff;
688 while (ViewerMainLoop( argccc, argvvv) ) { }
691 // On peut choisir un pnt sur l'edge
693 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
694 ShapeB = TheAISContext()->SelectedShape();
696 // Fermeture du context local
697 TheAISContext()->CloseLocalContext(MyCurrentIndex);
699 // Construction de l'axe
700 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
701 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
703 TopExp::Vertices(ed,Va,Vc );
704 gp_Pnt A=BRep_Tool::Pnt(Va);
705 gp_Pnt C=BRep_Tool::Pnt(Vc);
708 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
709 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
710 GetMapOfAIS().Bind (TheAxis,name);
711 TheAISContext()->Display(TheAxis);
715 // Fonction axisortho
717 TheAISContext()->OpenLocalContext();
718 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
720 // Active le mode edge
721 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
722 di<<" Select an edge."<<"\n";
724 // Boucle d'attente waitpick.
725 Standard_Integer argcc = 5;
726 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
727 const char **argvv = (const char **) buff;
728 while (ViewerMainLoop( argcc, argvv) ) { }
732 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
733 ShapeA = TheAISContext()->SelectedShape();
735 // Active le mode vertex et deactive edges
736 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
737 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
738 di<<" Slect a vertex."<<"\n";
740 // Boucle d'attente waitpick.
741 Standard_Integer argccc = 5;
742 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
743 const char **argvvv = (const char **) bufff;
744 while (ViewerMainLoop( argccc, argvvv) ) { }
747 // On peut choisir un pnt sur l'edge
749 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
750 ShapeB = TheAISContext()->SelectedShape();
752 // Fermeture du context local
753 TheAISContext()->CloseLocalContext(MyCurrentIndex);
755 // Construction de l'axe
756 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
757 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
759 TopExp::Vertices(ed,Va,Vc );
760 gp_Pnt A=BRep_Tool::Pnt(Va);
761 gp_Pnt C=BRep_Tool::Pnt(Vc);
762 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
765 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
766 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
767 GetMapOfAIS().Bind (TheAxis,name);
768 TheAISContext()->Display(TheAxis);
777 //==============================================================================
778 // Fonction First click Result
780 // vpoint vertex AIS_Point=Vertex
781 // edge AIS_Point=Middle of the edge
782 //==============================================================================
784 //==============================================================================
785 //function : VPointBuilder
786 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
787 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
788 //==============================================================================
789 #include <TopoDS_Edge.hxx>
790 #include <TopoDS_Vertex.hxx>
791 #include <TopExp.hxx>
792 #include <AIS_Point.hxx>
793 #include <Geom_CartesianPoint.hxx>
795 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
798 Standard_Boolean HasArg;
799 TCollection_AsciiString name;
800 Standard_Integer myCurrentIndex;
803 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
804 if (argc==5) HasArg=Standard_True;
805 else HasArg=Standard_False;
808 // Fermeture des contextes
809 TheAISContext()->CloseAllContexts();
811 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
813 Standard_Real thecoord[3];
814 for(Standard_Integer i=0;i<=2;i++)
815 thecoord[i]=Draw::Atof(argv[2+i]);
816 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
817 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
818 GetMapOfAIS().Bind (myAISPoint,name);
819 TheAISContext()->Display(myAISPoint);
822 // Il n'a pas d'arguments
824 TheAISContext()->OpenLocalContext();
825 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
827 // Active le mode Vertex et Edges
828 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
829 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
830 di<<" Select a vertex or an edge(build the middle)"<<"\n";
832 // Boucle d'attente waitpick.
833 Standard_Integer argcc = 5;
834 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
835 const char **argvv = (const char **) buff;
836 while (ViewerMainLoop( argcc, argvv) ) { }
840 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
841 ShapeA= TheAISContext()->SelectedShape();
844 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
845 // Un vertex a ete selectionne
846 // Fermeture du context local
847 TheAISContext()->CloseLocalContext(myCurrentIndex);
849 // Construction du point
850 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
851 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
852 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
853 GetMapOfAIS().Bind(myAISPoint,name);
854 TheAISContext()->Display(myAISPoint);
857 // Un Edge a ete selectionne
858 // Fermeture du context local
859 TheAISContext()->CloseLocalContext(myCurrentIndex);
861 // Construction du point milieu de l'edge
862 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
863 TopoDS_Vertex myVertexA,myVertexB;
864 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
865 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
866 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
867 // M est le milieu de [AB]
868 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
869 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
870 GetMapOfAIS().Bind(myAISPointM,name);
871 TheAISContext()->Display(myAISPointM);
879 //==============================================================================
880 // Function 1st click 2de click 3de click
881 // vplane Vertex Vertex Vertex
885 // vplanepara Face Vertex
887 // vplaneortho Face Edge
889 //==============================================================================
891 //==============================================================================
892 //function : VPlaneBuilder
893 //purpose : Build an AIS_Plane from selected entities or Named AIS components
894 //Draw arg : vplane PlaneName [AxisName] [PointName]
895 // [PointName] [PointName] [PointName]
896 // [PlaneName] [PointName]
897 //==============================================================================
899 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
900 Standard_Integer argc,
904 Standard_Boolean hasArg;
905 TCollection_AsciiString aName;
906 Standard_Integer aCurrentIndex;
909 if (argc<2 || argc>5 )
911 std::cout<<" Syntax error\n";
914 if (argc==5 || argc==4)
915 hasArg=Standard_True;
917 hasArg=Standard_False;
920 // Close all contexts
921 TheAISContext()->CloseAllContexts();
923 // There are some arguments
926 if (!GetMapOfAIS().IsBound2(argv[2] ))
928 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
931 // Get shape from map
932 Handle(AIS_InteractiveObject) aShapeA =
933 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
935 // The first argument is an AIS_Point
936 if (!aShapeA.IsNull() &&
937 aShapeA->Type()==AIS_KOI_Datum &&
938 aShapeA->Signature()==1)
940 // The second argument must also be an AIS_Point
941 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
943 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
946 // Get shape from map
947 Handle(AIS_InteractiveObject) aShapeB =
948 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
949 // If B is not an AIS_Point
950 if (aShapeB.IsNull() ||
951 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
953 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
956 // The third object is an AIS_Point
957 if (!GetMapOfAIS().IsBound2(argv[4]) )
959 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
962 // Get shape from map
963 Handle(AIS_InteractiveObject) aShapeC =
964 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
965 // If C is not an AIS_Point
966 if (aShapeC.IsNull() ||
967 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
969 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
973 // Treatment of objects A, B, C
974 // Downcast an AIS_IO to AIS_Point
975 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
976 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
977 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
979 Handle(Geom_CartesianPoint ) aCartPointA =
980 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
982 Handle(Geom_CartesianPoint ) aCartPointB =
983 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
985 Handle(Geom_CartesianPoint ) aCartPointC =
986 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
988 // Verification that the three points are different
989 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
990 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
991 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
994 std::cout<<"vplane error: same points"<<"\n";return 1;
996 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
997 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
998 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1001 std::cout<<"vplane error: same points"<<"\n";return 1;
1003 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1004 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1005 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1008 std::cout<<"vplane error: same points"<<"\n";return 1;
1011 gp_Pnt A = aCartPointA->Pnt();
1012 gp_Pnt B = aCartPointB->Pnt();
1013 gp_Pnt C = aCartPointC->Pnt();
1015 // Construction of AIS_Plane
1016 GC_MakePlane MkPlane (A,B,C);
1017 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1018 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1019 GetMapOfAIS().Bind (anAISPlane,aName );
1020 TheAISContext()->Display(anAISPlane);
1023 // The first argument is an AIS_Axis
1024 // Creation of a plane orthogonal to the axis through a point
1025 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1026 // The second argument should be an AIS_Point
1027 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1029 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1032 // Get shape from map
1033 Handle(AIS_InteractiveObject) aShapeB =
1034 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1035 // If B is not an AIS_Point
1036 if (aShapeB.IsNull() ||
1037 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1039 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1043 // Treatment of objects A and B
1044 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1045 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1047 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1048 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1050 gp_Ax1 anAxis = aGeomLineA->Position();
1051 Handle(Geom_CartesianPoint) aCartPointB =
1052 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1054 gp_Dir D =anAxis.Direction();
1055 gp_Pnt B = aCartPointB->Pnt();
1057 // Construction of AIS_Plane
1058 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1059 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1060 GetMapOfAIS().Bind (anAISPlane,aName );
1061 TheAISContext()->Display(anAISPlane);
1064 // The first argumnet is an AIS_Plane
1065 // Creation of a plane parallel to the plane passing through the point
1066 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1068 // The second argument should be an AIS_Point
1069 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1071 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1074 // Get shape from map
1075 Handle(AIS_InteractiveObject) aShapeB =
1076 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1077 // B should be an AIS_Point
1078 if (aShapeB.IsNull() ||
1079 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1081 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1085 // Treatment of objects A and B
1086 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1087 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1089 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1090 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1092 Handle(Geom_CartesianPoint) aCartPointB =
1093 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1094 gp_Pnt B= aCartPointB->Pnt();
1096 // Construction of an AIS_Plane
1097 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1098 GetMapOfAIS().Bind (anAISPlane, aName);
1099 TheAISContext()->Display(anAISPlane);
1104 std::cout<<"vplane: error 1st object is not an AIS\n";
1108 // There are no arguments
1112 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1113 if (!strcasecmp(argv[0], "vplane"))
1115 TheAISContext()->OpenLocalContext();
1116 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1118 // Active modes Vertex, Edge and Face
1119 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1120 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1121 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1122 std::cout<<"Select a vertex, a face or an edge\n";
1125 Standard_Integer argcc = 5;
1126 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1127 const char **argvv = (const char **) buff;
1128 while (ViewerMainLoop( argcc, argvv) ) { }
1131 TopoDS_Shape aShapeA;
1132 for (TheAISContext()->InitSelected();
1133 TheAISContext()->MoreSelected();
1134 TheAISContext()->NextSelected())
1136 aShapeA = TheAISContext()->SelectedShape();
1139 // aShapeA is a Vertex
1140 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1142 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1143 std::cout<<" Select an edge or a different vertex\n";
1146 Standard_Integer argccc = 5;
1147 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1148 const char **argvvv = (const char **) bufff;
1149 while (ViewerMainLoop( argccc, argvvv) ) { }
1152 TopoDS_Shape aShapeB;
1153 for (TheAISContext()->InitSelected();
1154 TheAISContext()->MoreSelected();
1155 TheAISContext()->NextSelected())
1157 aShapeB = TheAISContext()->SelectedShape();
1159 // aShapeB is a Vertex
1160 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1162 // A and B are the same
1163 if (aShapeB.IsSame(aShapeA))
1165 std::cout<<" vplane: error, same points selected\n";
1168 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1169 std::cout<<" Select a different vertex\n";
1172 Standard_Integer argcccc = 5;
1173 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1174 const char **argvvvv = (const char **) buffff;
1175 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1178 TopoDS_Shape aShapeC;
1179 for (TheAISContext()->InitSelected();
1180 TheAISContext()->MoreSelected();
1181 TheAISContext()->NextSelected())
1183 aShapeC = TheAISContext()->SelectedShape();
1185 // aShapeC is the same as A or B
1186 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1188 std::cout<<" vplane: error, same points selected\n";
1192 // Close the local context
1193 TheAISContext()->CloseLocalContext(aCurrentIndex);
1195 // Construction of plane
1196 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1197 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1198 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1199 GC_MakePlane MkPlane(A, B, C);
1200 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1201 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1202 GetMapOfAIS().Bind (anAISPlane, aName);
1203 TheAISContext()->Display(anAISPlane);
1205 // ShapeB is an edge
1208 // Verify that the vertex is not on the edge ShapeB
1209 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1210 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1212 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1213 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1215 // The vertex is on the edge
1216 std::cout<<" vplane: error point is on the edge\n";
1221 // Close the local context
1222 TheAISContext()->CloseLocalContext(aCurrentIndex);
1223 // Construction of plane
1224 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1225 TopoDS_Vertex aVBa, aVBb;
1226 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1227 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1228 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1229 GC_MakePlane MkPlane (A, aBa, aBb);
1230 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1231 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1232 GetMapOfAIS().Bind (anAISPlane, aName);
1233 TheAISContext()->Display(anAISPlane);
1237 // aShapeA is an edge
1238 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1240 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1241 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1242 std::cout<<" Select a vertex that don't belong to the edge\n";
1245 Standard_Integer argccc = 5;
1246 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1247 const char **argvvv = (const char **) bufff;
1248 while (ViewerMainLoop( argccc, argvvv) ) { }
1251 TopoDS_Shape aShapeB;
1252 for (TheAISContext()->InitSelected();
1253 TheAISContext()->MoreSelected();
1254 TheAISContext()->NextSelected())
1256 aShapeB = TheAISContext()->SelectedShape();
1258 // aShapeB should be a Vertex
1259 // Check that the vertex aShapeB is not on the edge
1260 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1261 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1263 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1264 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1266 // The vertex is on the edge
1267 std::cout<<" vplane: error point is on the edge\n";
1272 // Close the local context
1273 TheAISContext()->CloseLocalContext(aCurrentIndex);
1274 // Construction of plane
1275 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1276 TopoDS_Vertex aVAa, aVAb;
1277 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1278 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1279 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1280 GC_MakePlane MkPlane (B,Aa,Ab);
1281 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1282 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1283 GetMapOfAIS().Bind (anAISPlane ,aName);
1284 TheAISContext()->Display(anAISPlane);
1287 // aShapeA is a Face
1290 // Close the local context: nothing to select
1291 TheAISContext()->CloseLocalContext(aCurrentIndex);
1292 // Construction of plane
1293 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1294 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1295 if (aSurface.GetType()==GeomAbs_Plane)
1297 gp_Pln aPlane = aSurface.Plane();
1298 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1299 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1300 GetMapOfAIS().Bind (anAISPlane, aName);
1301 TheAISContext()->Display(anAISPlane);
1305 std::cout<<" vplane: error\n";
1311 // Function vPlanePara
1312 // ===================
1313 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1314 else if (!strcasecmp(argv[0], "vplanepara"))
1316 TheAISContext()->OpenLocalContext();
1317 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1319 // Activate modes Vertex and Face
1320 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1321 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1322 std::cout<<" Select a vertex or a face\n";
1325 Standard_Integer argcc = 5;
1326 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1327 const char **argvv = (const char **) buff;
1328 while (ViewerMainLoop( argcc, argvv) ) { }
1331 TopoDS_Shape aShapeA;
1332 for (TheAISContext()->InitSelected();
1333 TheAISContext()->MoreSelected();
1334 TheAISContext()->NextSelected())
1336 aShapeA = TheAISContext()->SelectedShape();
1339 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1341 // aShapeA is a vertex
1342 // Deactivate the mode Vertex
1343 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1344 std::cout<<" Select a face\n";
1347 Standard_Integer argccc = 5;
1348 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1349 const char **argvvv = (const char **) bufff;
1350 while (ViewerMainLoop( argccc, argvvv) ) { }
1353 TopoDS_Shape aShapeB;
1354 for (TheAISContext()->InitSelected();
1355 TheAISContext()->MoreSelected();
1356 TheAISContext()->NextSelected())
1358 // A vertex ShapeA can be on Face ShapeB
1359 aShapeB = TheAISContext()->SelectedShape();
1362 // Close the local context
1363 TheAISContext()->CloseLocalContext(aCurrentIndex);
1365 // Construction of plane
1366 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1368 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1369 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1370 if (aSurface.GetType()==GeomAbs_Plane )
1372 gp_Pln aPlane = aSurface.Plane();
1373 // Construct a plane parallel to aGeomPlane through A
1374 aPlane.SetLocation(A);
1375 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1376 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1377 GetMapOfAIS().Bind (aAISPlane ,aName);
1378 TheAISContext()->Display(aAISPlane);
1382 std::cout<<" vplanepara: error\n";
1389 // Deactive the mode Face
1390 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1391 std::cout<<" Select a vertex\n";
1394 Standard_Integer argccc = 5;
1395 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1396 const char **argvvv = (const char **) bufff;
1397 while (ViewerMainLoop( argccc, argvvv) ) { }
1400 TopoDS_Shape aShapeB;
1401 for (TheAISContext()->InitSelected();
1402 TheAISContext()->MoreSelected();
1403 TheAISContext()->NextSelected())
1405 // A vertex ShapeB can be on Face ShapeA
1406 aShapeB = TheAISContext()->SelectedShape();
1408 // Close the local context
1409 TheAISContext()->CloseLocalContext(aCurrentIndex);
1411 // Construction of plane
1412 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1414 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1415 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1416 if (aSurface.GetType()==GeomAbs_Plane )
1418 gp_Pln aPlane = aSurface.Plane();
1419 aPlane.SetLocation(B);
1420 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1421 // Construct a plane parallel to aGeomPlane through B
1422 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1423 GetMapOfAIS().Bind (anAISPlane, aName);
1424 TheAISContext()->Display(anAISPlane);
1428 std::cout<<" vplanepara: error"<<"\n";return 1;
1433 // Function vplaneortho
1434 // ====================
1435 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1438 TheAISContext()->OpenLocalContext();
1439 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1441 // Activate the modes Edge and Face
1442 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1443 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1444 std::cout<<" Select a face and an edge coplanar\n";
1447 Standard_Integer argcc = 5;
1448 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1449 const char **argvv = (const char **) buff;
1450 while (ViewerMainLoop( argcc, argvv) ) { }
1453 TopoDS_Shape aShapeA;
1454 for (TheAISContext()->InitSelected();
1455 TheAISContext()->MoreSelected();
1456 TheAISContext()->NextSelected())
1458 aShapeA = TheAISContext()->SelectedShape();
1461 if (aShapeA.ShapeType()==TopAbs_EDGE )
1463 // ShapeA is an edge, deactivate the mode Edge...
1464 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1465 std::cout<<" Select a face\n";
1468 Standard_Integer argccc = 5;
1469 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1470 const char **argvvv = (const char **) bufff;
1471 while (ViewerMainLoop( argccc, argvvv) ) { }
1474 TopoDS_Shape aShapeB;
1475 for (TheAISContext()->InitSelected();
1476 TheAISContext()->MoreSelected();
1477 TheAISContext()->NextSelected())
1479 // Edge ShapeA can be on Face ShapeB
1480 aShapeB = TheAISContext()->SelectedShape();
1483 // Close the local context
1484 TheAISContext()->CloseLocalContext(aCurrentIndex);
1486 // Construction of plane
1487 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1488 TopoDS_Vertex aVAa, aVAb;
1489 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1490 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1491 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1495 // Creation of rotation axis
1496 gp_Ax1 aRotAxis (Aa,Dab);
1498 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1499 // The edge must be parallel to the face
1500 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1501 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1502 // Compare to heights
1503 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1504 >Precision::Confusion())
1506 // the edge is not parallel to the face
1507 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1511 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1512 if (aSurface.GetType()==GeomAbs_Plane)
1514 gp_Pln aPlane = aSurface.Plane();
1515 // It rotates a half turn round the axis of rotation
1516 aPlane.Rotate(aRotAxis , M_PI/2);
1518 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1519 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1520 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1521 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1522 GetMapOfAIS().Bind (anAISPlane, aName);
1523 TheAISContext()->Display(anAISPlane);
1527 std::cout<<" vplaneortho: error\n";
1533 // ShapeA is a Face, deactive the mode Face.
1534 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1535 std::cout<<" Select an edge\n";
1538 Standard_Integer argccc = 5;
1539 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1540 const char **argvvv = (const char **) bufff;
1541 while (ViewerMainLoop( argccc, argvvv) ) { }
1544 TopoDS_Shape aShapeB;
1545 for (TheAISContext()->InitSelected();
1546 TheAISContext()->MoreSelected();
1547 TheAISContext()->NextSelected())
1549 // Edge ShapeB can be on Face ShapeA
1550 aShapeB = TheAISContext()->SelectedShape();
1552 // Close the local context
1553 TheAISContext()->CloseLocalContext(aCurrentIndex);
1555 // Construction of plane
1556 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1557 TopoDS_Vertex aVBa, aVBb;
1558 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1559 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1560 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1561 gp_Vec ab (aBa,aBb);
1563 // Creation of rotation axe
1564 gp_Ax1 aRotAxis (aBa,Dab);
1566 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1567 // The edge must be parallel to the face
1568 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1569 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1570 // Comparing the two heights
1571 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1572 >Precision::Confusion())
1574 // the edge is not parallel to the face
1575 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1579 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1580 if (aSurface.GetType()==GeomAbs_Plane)
1582 gp_Pln aPlane = aSurface.Plane();
1583 // It rotates a half turn round the axis of rotation
1584 aPlane.Rotate(aRotAxis , M_PI/2);
1585 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1586 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1587 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1588 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1589 GetMapOfAIS().Bind (anAISPlane ,aName);
1590 TheAISContext()->Display(anAISPlane);
1594 std::cout<<" vplaneortho: error\n";
1604 //==============================================================================
1606 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1607 //==============================================================================
1609 //==============================================================================
1610 //function : VLineBuilder
1611 //purpose : Build an AIS_Line
1612 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1613 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1614 //==============================================================================
1615 #include <Geom_CartesianPoint.hxx>
1616 #include <AIS_Line.hxx>
1619 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1621 Standard_Integer myCurrentIndex;
1623 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1624 // Fermeture des contextes
1625 TheAISContext()->CloseAllContexts();
1627 // On recupere les parametres
1628 Handle(AIS_InteractiveObject) theShapeA;
1629 Handle(AIS_InteractiveObject) theShapeB;
1631 // Parametres: AIS_Point AIS_Point
1632 // ===============================
1635 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1636 // On verifie que c'est bien une AIS_Point
1637 if (!theShapeA.IsNull() &&
1638 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1639 // on recupere le deuxieme AIS_Point
1641 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1642 if (theShapeA.IsNull() ||
1643 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1645 di <<"vline error: wrong type of 2de argument."<<"\n";
1649 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1650 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1651 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1652 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1654 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1655 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1656 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1658 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1659 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1660 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1662 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1664 di<<"vline error: same points"<<"\n";return 1;
1666 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1667 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1668 GetMapOfAIS().Bind(theAISLine,argv[1] );
1669 TheAISContext()->Display(theAISLine );
1673 // Parametres 6 Reals
1674 // ==================
1677 // On verifie que les deux points ne sont pas confondus
1679 Standard_Real coord[6];
1680 for(Standard_Integer i=0;i<=2;i++){
1681 coord[i]=Draw::Atof(argv[2+i]);
1682 coord[i+3]=Draw::Atof(argv[5+i]);
1685 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1686 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1688 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1689 GetMapOfAIS().Bind(theAISLine,argv[1] );
1690 TheAISContext()->Display(theAISLine );
1694 // Pas de parametres: Selection dans le viewer.
1695 // ============================================
1698 TheAISContext()->OpenLocalContext();
1699 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1701 // Active le mode Vertex.
1702 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1703 di<<" Select a vertex "<<"\n";
1705 // Boucle d'attente waitpick.
1706 Standard_Integer argcc = 5;
1707 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1708 const char **argvv = (const char **) buff;
1709 while (ViewerMainLoop( argcc, argvv) ) { }
1712 TopoDS_Shape ShapeA;
1713 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1714 ShapeA = TheAISContext()->SelectedShape();
1717 // ShapeA est un Vertex
1718 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1720 di<<" Select a different vertex."<<"\n";
1722 TopoDS_Shape ShapeB;
1725 // Boucle d'attente waitpick.
1726 Standard_Integer argccc = 5;
1727 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1728 const char **argvvv = (const char **) bufff;
1729 while (ViewerMainLoop( argccc, argvvv) ) { }
1732 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1733 ShapeB = TheAISContext()->SelectedShape();
1737 } while(ShapeB.IsSame(ShapeA) );
1739 // Fermeture du context local
1740 TheAISContext()->CloseLocalContext(myCurrentIndex);
1742 // Construction de la line
1743 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1744 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1746 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1747 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1749 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1750 GetMapOfAIS().Bind(theAISLine,argv[1] );
1751 TheAISContext()->Display(theAISLine );
1755 di<<"vline error."<<"\n";
1763 //==============================================================================
1764 // class : FilledCircle
1765 // purpose : creates filled circle based on AIS_InteractiveObject
1767 // This class is used to check method Matches() of class
1768 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1769 // because none of AIS classes provides creation of
1770 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1771 // (look method ComputeSelection() )
1772 //==============================================================================
1774 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1776 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1777 gp_Circ aCirc(anAxes, theRadius);
1778 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1782 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1784 class FilledCircle : public AIS_InteractiveObject
1788 DEFINE_STANDARD_RTTI(FilledCircle);
1790 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1791 FilledCircle(Handle(Geom_Circle) theCircle);
1794 TopoDS_Face ComputeFace();
1796 // Virtual methods implementation
1797 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1798 const Handle(Prs3d_Presentation)& thePresentation,
1799 const Standard_Integer theMode);
1801 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1802 const Standard_Integer theMode);
1805 Handle(Geom_Circle) myCircle;
1806 Standard_Boolean myFilledStatus;
1810 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1811 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1813 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1815 myCircle = CreateCircle(theCenter, theRadius);
1816 myFilledStatus = Standard_True;
1819 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1821 myCircle = theCircle;
1822 myFilledStatus = Standard_True;
1825 TopoDS_Face FilledCircle::ComputeFace()
1827 // Create edge from myCircle
1828 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1829 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1831 // Create wire from anEdge
1832 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1833 TopoDS_Wire aWire = aWireMaker.Wire();
1835 // Create face from aWire
1836 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1837 TopoDS_Face aFace = aFaceMaker.Face();
1842 void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &/*thePresentationManager*/,
1843 const Handle_Prs3d_Presentation &thePresentation,
1844 const Standard_Integer theMode)
1846 thePresentation->Clear();
1848 TopoDS_Face aFace = ComputeFace();
1850 if (aFace.IsNull()) return;
1851 if (theMode != 0) return;
1853 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1856 void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection,
1857 const Standard_Integer /*theMode*/)
1859 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
1860 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
1861 myCircle, myFilledStatus);
1862 theSelection->Add(aSensitiveCircle);
1865 //==============================================================================
1867 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
1868 //==============================================================================
1870 //==============================================================================
1871 //function : VCircleBuilder
1872 //purpose : Build an AIS_Circle
1873 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
1874 // PointName PointName PointName IsFilled
1875 //==============================================================================
1877 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
1878 TCollection_AsciiString theName,
1879 Standard_Boolean isFilled)
1881 Handle(AIS_InteractiveObject) aCircle;
1884 aCircle = new FilledCircle(theGeomCircle);
1888 aCircle = new AIS_Circle(theGeomCircle);
1891 // Check if there is an object with given name
1892 // and remove it from context
1893 if (GetMapOfAIS().IsBound2(theName))
1895 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
1896 Handle(AIS_InteractiveObject) anInterObj =
1897 Handle(AIS_InteractiveObject)::DownCast(anObj);
1898 TheAISContext()->Remove(anInterObj, Standard_False);
1899 GetMapOfAIS().UnBind2(theName);
1902 // Bind the circle to its name
1903 GetMapOfAIS().Bind(aCircle, theName);
1905 // Display the circle
1906 TheAISContext()->Display(aCircle);
1910 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
1912 Standard_Integer myCurrentIndex;
1913 // Verification of the arguments
1914 if (argc>6 || argc<2)
1916 std::cout << "vcircle error: expect 4 arguments.\n";
1917 return 1; // TCL_ERROR
1919 TheAISContext()->CloseAllContexts();
1921 // There are all arguments
1925 TCollection_AsciiString aName(argv[1]);
1926 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
1928 Handle(AIS_InteractiveObject) theShapeA;
1929 Handle(AIS_InteractiveObject) theShapeB;
1932 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
1934 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
1937 // Arguments: AIS_Point AIS_Point AIS_Point
1938 // ========================================
1939 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
1940 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
1942 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
1944 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
1945 return 1; // TCL_ERROR
1947 // The third object must be a point
1948 Handle(AIS_InteractiveObject) theShapeC =
1949 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
1950 if (theShapeC.IsNull() ||
1951 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
1953 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
1954 return 1; // TCL_ERROR
1957 // Verify that the three points are different
1958 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
1959 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
1960 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
1962 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
1963 Handle(Geom_CartesianPoint) myCartPointA =
1964 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
1966 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
1967 Handle(Geom_CartesianPoint) myCartPointB =
1968 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
1970 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
1971 Handle(Geom_CartesianPoint) myCartPointC =
1972 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
1975 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
1976 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
1977 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
1979 std::cout << "vcircle error: Same points.\n";
1980 return 1; // TCL_ERROR
1983 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
1984 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1985 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1987 std::cout << "vcircle error: Same points.\n";
1988 return 1; // TCL_ERROR
1991 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
1992 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
1993 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
1995 std::cout << "vcircle error: Same points.\n";
1996 return 1;// TCL_ERROR
1998 // Construction of the circle
1999 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2000 myCartPointB->Pnt(), myCartPointC->Pnt() );
2001 Handle (Geom_Circle) theGeomCircle;
2004 theGeomCircle = Cir.Value();
2006 catch (StdFail_NotDone)
2008 std::cout << "vcircle error: can't create circle\n";
2009 return -1; // TCL_ERROR
2012 DisplayCircle(theGeomCircle, aName, isFilled);
2015 // Arguments: AIS_Plane AIS_Point Real
2016 // ===================================
2017 else if (theShapeA->Type() == AIS_KOI_Datum &&
2018 theShapeA->Signature() == 7 )
2020 if (theShapeB->Type() != AIS_KOI_Datum ||
2021 theShapeB->Signature() != 1 )
2023 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2024 return 1; // TCL_ERROR
2026 // Ñheck that the radius is >= 0
2027 if (Draw::Atof(argv[4]) <= 0 )
2029 std::cout << "vcircle error: the radius must be >=0.\n";
2030 return 1; // TCL_ERROR
2033 // Recover the normal to the plane
2034 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2035 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2037 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2038 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2039 Handle(Geom_CartesianPoint) myCartPointB =
2040 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2042 gp_Pln mygpPlane = myGeomPlane->Pln();
2043 gp_Ax1 thegpAxe = mygpPlane.Axis();
2044 gp_Dir theDir = thegpAxe.Direction();
2045 gp_Pnt theCenter = myCartPointB->Pnt();
2046 Standard_Real TheR = Draw::Atof(argv[4]);
2047 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2048 Handle (Geom_Circle) theGeomCircle;
2051 theGeomCircle = Cir.Value();
2053 catch (StdFail_NotDone)
2055 std::cout << "vcircle error: can't create circle\n";
2056 return -1; // TCL_ERROR
2059 DisplayCircle(theGeomCircle, aName, isFilled);
2066 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2067 return 1; // TCL_ERROR
2071 // No arguments: selection in the viewer
2072 // =========================================
2075 // Get the name of the circle
2076 TCollection_AsciiString aName(argv[1]);
2078 TheAISContext()->OpenLocalContext();
2079 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2081 // Activate selection mode for vertices and faces
2082 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2083 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2084 std::cout << " Select a vertex or a face\n";
2087 Standard_Integer argcc = 5;
2088 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2089 const char **argvv = (const char **) buff;
2090 while (ViewerMainLoop( argcc, argvv) ) { }
2093 TopoDS_Shape ShapeA;
2094 for(TheAISContext()->InitSelected();
2095 TheAISContext()->MoreSelected();
2096 TheAISContext()->NextSelected() )
2098 ShapeA = TheAISContext()->SelectedShape();
2101 // ShapeA is a Vertex
2102 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2104 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2105 std::cout << " Select a different vertex\n";
2107 TopoDS_Shape ShapeB;
2111 Standard_Integer argccc = 5;
2112 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2113 const char **argvvv = (const char **) bufff;
2114 while (ViewerMainLoop( argccc, argvvv) ) { }
2117 for(TheAISContext()->InitSelected();
2118 TheAISContext()->MoreSelected();
2119 TheAISContext()->NextSelected() )
2121 ShapeB = TheAISContext()->SelectedShape();
2123 } while(ShapeB.IsSame(ShapeA) );
2125 // Selection of ShapeC
2126 std::cout << " Select the last vertex\n";
2127 TopoDS_Shape ShapeC;
2131 Standard_Integer argcccc = 5;
2132 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2133 const char **argvvvv = (const char **) buffff;
2134 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2137 for(TheAISContext()->InitSelected();
2138 TheAISContext()->MoreSelected();
2139 TheAISContext()->NextSelected() )
2141 ShapeC = TheAISContext()->SelectedShape();
2143 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2146 Standard_Boolean isFilled;
2147 std::cout << "Enter filled status (0 or 1)\n";
2150 // Close the local context
2151 TheAISContext()->CloseLocalContext(myCurrentIndex);
2153 // Construction of the circle
2154 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2155 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2156 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2158 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2159 Handle (Geom_Circle) theGeomCircle;
2162 theGeomCircle = Cir.Value();
2164 catch (StdFail_NotDone)
2166 std::cout << "vcircle error: can't create circle\n";
2167 return -1; // TCL_ERROR
2170 DisplayCircle(theGeomCircle, aName, isFilled);
2176 std::cout << " Select a vertex (in your face)\n";
2177 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2179 TopoDS_Shape ShapeB;
2181 Standard_Integer argccc = 5;
2182 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2183 const char **argvvv = (const char **) bufff;
2184 while (ViewerMainLoop( argccc, argvvv) ) { }
2187 for(TheAISContext()->InitSelected();
2188 TheAISContext()->MoreSelected();
2189 TheAISContext()->NextSelected() )
2191 ShapeB = TheAISContext()->SelectedShape();
2194 // Recover the radius
2195 Standard_Real theRad;
2198 std::cout << " Enter the value of the radius:\n";
2200 } while (theRad <= 0);
2202 // Get filled status
2203 Standard_Boolean isFilled;
2204 std::cout << "Enter filled status (0 or 1)\n";
2207 // Close the local context
2208 TheAISContext()->CloseLocalContext(myCurrentIndex);
2209 // Construction of the circle
2211 // Recover the normal to the plane. tag
2212 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2213 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2214 gp_Pln myPlane = mySurface.Plane();
2215 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2216 gp_Pln mygpPlane = theGeomPlane->Pln();
2217 gp_Ax1 thegpAxe = mygpPlane.Axis();
2218 gp_Dir theDir = thegpAxe.Direction();
2220 // Recover the center
2221 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2223 // Ñonstruct the circle
2224 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2225 Handle (Geom_Circle) theGeomCircle;
2228 theGeomCircle = Cir.Value();
2230 catch (StdFail_NotDone)
2232 std::cout << "vcircle error: can't create circle\n";
2233 return -1; // TCL_ERROR
2236 DisplayCircle(theGeomCircle, aName, isFilled);
2246 //===============================================================================================
2247 //function : VDrawText
2249 //purpose : Create a text.
2250 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2251 //===============================================================================================
2252 #include <Graphic3d_Group.hxx>
2253 #include <Graphic3d_Structure.hxx>
2254 #include <Graphic3d_AspectText3d.hxx>
2255 #include <Graphic3d_AspectFillArea3d.hxx>
2256 #include <Graphic3d_StructureManager.hxx>
2257 #include <Graphic3d_VerticalTextAlignment.hxx>
2258 #include <Graphic3d_HorizontalTextAlignment.hxx>
2260 #include <Font_NameOfFont.hxx>
2262 #include <Visual3d_ViewManager.hxx>
2263 #include <ViewerTest_Tool.ixx>
2265 #include <Standard_DefineHandle.hxx>
2267 #include <Prs3d_Root.hxx>
2268 #include <Prs3d_Text.hxx>
2269 #include <Prs3d_TextAspect.hxx>
2270 #include <Prs3d_ShadingAspect.hxx>
2271 #include <PrsMgr_PresentationManager3d.hxx>
2273 #include <TCollection_ExtendedString.hxx>
2274 #include <TCollection_AsciiString.hxx>
2276 #include <gp_Pnt.hxx>
2277 #include <Quantity_NameOfColor.hxx>
2278 #include <Quantity_Color.hxx>
2281 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2283 class MyTextClass:public AIS_InteractiveObject
2287 DEFINE_STANDARD_RTTI(MyTextClass );
2293 const TCollection_ExtendedString& , const gp_Pnt& ,
2294 Quantity_Color color,
2295 Standard_Integer aHJust,
2296 Standard_Integer aVJust ,
2297 Standard_Real Angle ,
2298 Standard_Boolean Zoom ,
2299 Standard_Real Height,
2300 Font_FontAspect FontAspect,
2301 Standard_CString Font
2306 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2307 const Handle(Prs3d_Presentation)& aPresentation,
2308 const Standard_Integer aMode);
2310 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2311 const Standard_Integer /*aMode*/){} ;
2314 TCollection_ExtendedString aText;
2317 Standard_Real Green;
2319 Standard_Real aAngle;
2320 Standard_Real aHeight;
2321 Standard_Boolean aZoomable;
2322 Quantity_Color aColor;
2323 TCollection_AsciiString aFont;
2324 Font_FontAspect aFontAspect;
2325 Graphic3d_HorizontalTextAlignment aHJustification;
2326 Graphic3d_VerticalTextAlignment aVJustification;
2331 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2332 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2335 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2336 Quantity_Color color = Quantity_NOC_YELLOW,
2337 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2338 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2339 Standard_Real angle = 0.0 ,
2340 Standard_Boolean zoomable = Standard_True,
2341 Standard_Real height = 12.,
2342 Font_FontAspect fontAspect = Font_FA_Regular,
2343 Standard_CString font = "Courier")
2346 aPosition = position;
2347 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2348 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2350 aZoomable = zoomable;
2353 aFontAspect = fontAspect;
2359 //////////////////////////////////////////////////////////////////////////////
2360 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
2361 const Handle(Prs3d_Presentation)& aPresentation,
2362 const Standard_Integer /*aMode*/)
2365 aPresentation->Clear();
2367 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
2369 asp->SetFont(aFont.ToCString());
2370 asp->SetColor(aColor);
2371 asp->SetHeight(aHeight); // I am changing the myHeight value
2373 asp->SetHorizontalJustification(aHJustification);
2374 asp->SetVerticalJustification(aVJustification);
2375 asp->Aspect()->SetTextZoomable(aZoomable);
2376 asp->Aspect()->SetTextAngle(aAngle);
2377 asp->Aspect()->SetTextFontAspect(aFontAspect);
2378 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2380 /* This comment code is worked
2381 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2382 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2383 Graphic3d_Vertex vertices_text;
2384 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2385 TheGroup->SetPrimitivesAspect(aspect);
2386 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2390 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2395 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2396 di<<"Usage: type help "<<argv[0]<<"\n";
2397 return 1; //TCL_ERROR
2400 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2402 // Create 3D view if it doesn't exist
2403 if ( aContext.IsNull() )
2405 ViewerTest::ViewerInit();
2406 aContext = ViewerTest::GetAISContext();
2407 if( aContext.IsNull() )
2409 di << "Error: Cannot create a 3D view\n";
2410 return 1; //TCL_ERROR
2415 const Standard_Real X = Draw::Atof(argv[2]);
2416 const Standard_Real Y = Draw::Atof(argv[3]);
2417 const Standard_Real Z = Draw::Atof(argv[4]);
2418 const gp_Pnt pnt(X,Y,Z);
2421 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2422 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2423 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
2424 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2427 const int hor_align = Draw::Atoi(argv[8]);
2428 const int ver_align = Draw::Atoi(argv[9]);
2431 const Standard_Real angle = Draw::Atof(argv[10]);
2434 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
2437 const Standard_Real height = Draw::Atof(argv[12]);
2440 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
2443 TCollection_AsciiString font;
2445 font.AssignCat("Courier");
2447 font.AssignCat(argv[14]);
2449 // Text is multibyte
2450 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
2453 TCollection_ExtendedString name;
2456 const char *str = argv[1];
2457 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2458 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2460 unsigned short c1 = *str++;
2461 unsigned short c2 = *str++;
2463 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2473 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2474 aContext->Display(myT,Standard_True);
2481 #include <gp_Pnt.hxx>
2482 #include <Graphic3d_ArrayOfPoints.hxx>
2483 #include <Graphic3d_ArrayOfPrimitives.hxx>
2484 #include <Graphic3d_ArrayOfTriangles.hxx>
2485 #include <Poly_Array1OfTriangle.hxx>
2486 #include <Poly_Triangle.hxx>
2487 #include <Poly_Triangulation.hxx>
2488 #include <TColgp_Array1OfPnt.hxx>
2489 #include <TShort_Array1OfShortReal.hxx>
2490 #include <TShort_HArray1OfShortReal.hxx>
2492 #include <AIS_Triangulation.hxx>
2493 #include <StdPrs_ToolShadedShape.hxx>
2494 #include <Poly_Connect.hxx>
2495 #include <TColgp_Array1OfDir.hxx>
2496 #include <Graphic3d_GraphicDriver.hxx>
2498 #include <TColStd_Array1OfInteger.hxx>
2499 #include <TColStd_HArray1OfInteger.hxx>
2500 #include <Prs3d_ShadingAspect.hxx>
2501 #include <Graphic3d_MaterialAspect.hxx>
2502 #include <Graphic3d_AspectFillArea3d.hxx>
2504 #include <BRepPrimAPI_MakeCylinder.hxx>
2505 #include <TopoDS_Shape.hxx>
2506 #include <TopExp_Explorer.hxx>
2507 #include <TopAbs.hxx>
2508 #include <StdSelect_ShapeTypeFilter.hxx>
2511 //===============================================================================================
2512 //function : CalculationOfSphere
2514 //purpose : Create a Sphere
2515 //===============================================================================================
2517 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2520 double mRadius = Radius;
2521 double mCenter[3] = {X,Y,Z};
2522 int mThetaResolution;
2524 double mStartTheta = 0;//StartTheta;
2525 double mEndTheta = 360;//EndTheta;
2526 double mStartPhi = 0;//StartPhi;
2527 double mEndPhi = 180;//EndPhi;
2528 res = res < 4 ? 4 : res;
2530 mThetaResolution = res;
2531 mPhiResolution = res;
2534 int jStart, jEnd, numOffset;
2535 int numPts, numPolys;
2536 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2537 double startTheta, endTheta, startPhi, endPhi;
2538 int base, numPoles=0, thetaResolution, phiResolution;
2543 if ( numPieces > mThetaResolution ) {
2544 numPieces = mThetaResolution;
2547 int localThetaResolution = mThetaResolution;
2548 double localStartTheta = mStartTheta;
2549 double localEndTheta = mEndTheta;
2551 while ( localEndTheta < localStartTheta ) {
2552 localEndTheta += 360.0;
2555 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2557 // Change the ivars based on pieces.
2559 start = piece * localThetaResolution / numPieces;
2560 end = (piece+1) * localThetaResolution / numPieces;
2561 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2562 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2563 localThetaResolution = end - start;
2565 numPts = mPhiResolution * localThetaResolution + 2;
2566 numPolys = mPhiResolution * 2 * localThetaResolution;
2568 // Create north pole if needed
2569 int number_point = 0;
2570 int number_pointArray = 0;
2572 if ( mStartPhi <= 0.0 ) {
2573 number_pointArray++;
2576 if ( mEndPhi >= 180.0 ) {
2577 number_pointArray++;
2581 // Check data, determine increments, and convert to radians
2582 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2583 startTheta *= M_PI / 180.0;
2584 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2585 endTheta *= M_PI / 180.0;
2588 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2589 startPhi *= M_PI / 180.0;
2590 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2591 endPhi *= M_PI / 180.0;
2593 phiResolution = mPhiResolution - numPoles;
2594 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2595 thetaResolution = localThetaResolution;
2596 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2597 ++localThetaResolution;
2599 deltaTheta = (endTheta - startTheta) / thetaResolution;
2601 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2602 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2604 // Create intermediate points
2605 for ( i = 0; i < localThetaResolution; i++ ) {
2606 for ( j = jStart; j < jEnd; j++ ) {
2607 number_pointArray++;
2611 //Generate mesh connectivity
2612 base = phiResolution * localThetaResolution;
2614 int number_triangle = 0 ;
2615 if ( mStartPhi <= 0.0 ) { // around north pole
2616 number_triangle += localThetaResolution;
2619 if ( mEndPhi >= 180.0 ) { // around south pole
2620 number_triangle += localThetaResolution;
2623 // bands in-between poles
2624 for ( i=0; i < localThetaResolution; i++){
2625 for ( j=0; j < (phiResolution-1); j++){
2626 number_triangle +=2;
2630 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2631 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2632 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2634 if ( mStartPhi <= 0.0 ){
2637 x[2] = mCenter[2] + mRadius;
2638 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2641 // Create south pole if needed
2642 if ( mEndPhi >= 180.0 ){
2645 x[2] = mCenter[2] - mRadius;
2646 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2650 for ( i=0; i < localThetaResolution; i++){
2651 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2652 for ( j = jStart; j < jEnd; j++){
2653 phi = startPhi + j*deltaPhi;
2654 radius = mRadius * sin((double)phi);
2655 n[0] = radius * cos((double)theta);
2656 n[1] = radius * sin((double)theta);
2657 n[2] = mRadius * cos((double)phi);
2658 x[0] = n[0] + mCenter[0];
2659 x[1] = n[1] + mCenter[1];
2660 x[2] = n[2] + mCenter[2];
2661 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2667 number_triangle = 1;
2668 if ( mStartPhi <= 0.0 ){// around north pole
2669 for (i=0; i < localThetaResolution; i++){
2670 pts[0] = phiResolution*i + numPoles;
2671 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2673 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2678 if ( mEndPhi >= 180.0 ){ // around south pole
2679 numOffset = phiResolution - 1 + numPoles;
2680 for (i=0; i < localThetaResolution; i++){
2681 pts[0] = phiResolution*i + numOffset;
2682 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2683 pts[1] = numPoles - 1;
2684 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2689 // bands in-between poles
2691 for (i=0; i < localThetaResolution; i++){
2692 for (j=0; j < (phiResolution-1); j++){
2693 pts[0] = phiResolution*i + j + numPoles;
2694 pts[1] = pts[0] + 1;
2695 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2696 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2699 pts[2] = pts[1] - 1;
2700 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2705 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2707 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2709 Standard_Integer index[3];
2710 Standard_Real Tol = Precision::Confusion();
2713 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2714 gp_XYZ eqPlan(0, 0, 0);
2715 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2716 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2717 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2718 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2720 Standard_Real mod = vv.Modulus();
2721 if(mod < Tol) continue;
2725 Standard_Real modmax = eqPlan.Modulus();
2728 Nor = gp_Dir(eqPlan);
2730 Nor = gp_Dir(0., 0., 1.);
2732 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2733 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2734 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2735 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2739 polyTriangulation->SetNormals(Normals);
2741 return polyTriangulation;
2744 //===============================================================================================
2745 //function : VDrawSphere
2747 //purpose : Create an AIS shape.
2748 //===============================================================================================
2749 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2752 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2753 if (aContextAIS.IsNull())
2755 std::cout << "Call vinit before!\n";
2760 std::cout << "Use: " << argv[0]
2761 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2765 // read the arguments
2766 TCollection_AsciiString aShapeName (argv[1]);
2767 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2768 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2769 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2770 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2771 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2772 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) : Standard_False;
2774 // remove AIS object with given name from map
2775 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2777 std::cout << "Compute Triangulation...\n";
2778 Handle(AIS_Triangulation) aShape
2779 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2782 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2783 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2785 // stupid initialization of Green color in RGBA space as integer
2786 // probably wrong for big-endian CPUs
2787 Standard_Integer aRed = 0;
2788 Standard_Integer aGreen = 255;
2789 Standard_Integer aBlue = 0;
2790 Standard_Integer anAlpha = 0; // not used
2791 Standard_Integer aColorInt = aRed;
2792 aColorInt += aGreen << 8;
2793 aColorInt += aBlue << 16;
2794 aColorInt += anAlpha << 24;
2796 // setup colors array per vertex
2797 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2798 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2800 aColorArray->SetValue (aNodeId, aColorInt);
2802 aShape->SetColors (aColorArray);
2805 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2806 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2807 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2808 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2809 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2810 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2811 aTotalSize >>= 20; //MB
2812 aNormalsSize >>= 20;
2814 aTrianglesSize >>= 20;
2815 aPolyConnectSize >>= 20;
2816 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2817 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2818 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2819 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2820 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2821 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2823 // Setting material properties, very important for desirable visual result!
2824 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2825 aMat.SetAmbient (0.2);
2826 aMat.SetSpecular (0.5);
2827 Handle(Graphic3d_AspectFillArea3d) anAspect
2828 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2830 Quantity_NOC_YELLOW,
2835 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2838 anAspect->SetEdgeOn();
2842 anAspect->SetEdgeOff();
2844 aShAsp->SetAspect (anAspect);
2845 aShape->Attributes()->SetShadingAspect (aShAsp);
2847 VDisplayAISObject (aShapeName, aShape);
2851 //=============================================================================
2852 //function : VComputeHLR
2854 //=============================================================================
2856 static int VComputeHLR (Draw_Interpretor& di,
2857 Standard_Integer argc,
2860 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2862 if (aContextAIS.IsNull ())
2864 di << "Please call vinit before\n";
2868 if ( argc != 3 && argc != 12 )
2870 di << "Usage: " << argv[0] << " ShapeName HlrName "
2871 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
2872 << " ShapeName - name of the initial shape\n"
2873 << " HlrName - result hlr object from initial shape\n"
2874 << " eye, dir are eye position and look direction\n"
2875 << " up is the look up direction vector\n"
2876 << " Use vtop to see projected hlr shape\n";
2880 // shape and new object name
2881 TCollection_AsciiString aShapeName (argv[1]);
2882 TCollection_AsciiString aHlrName (argv[2]);
2884 TopoDS_Shape aSh = DBRep::Get (argv[1]);
2887 BRep_Builder aBrepBuilder;
2888 BRepTools::Read (aSh, argv[1], aBrepBuilder);
2891 di << "No shape with name " << argv[1] << " found\n";
2896 if (GetMapOfAIS ().IsBound2 (aHlrName))
2898 di << "Presentable object with name " << argv[2] << " already exists\n";
2902 // close local context
2903 if (aContextAIS->HasOpenedContext ())
2904 aContextAIS->CloseLocalContext ();
2906 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
2907 HLRBRep_PolyHLRToShape aHLRToShape;
2916 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
2917 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
2918 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
2919 aProjAx.SetLocation (anEye);
2920 aProjAx.SetDirection (aDir);
2921 aProjAx.SetYDirection (anUp);
2927 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2928 Handle(V3d_View) aView = ViewerTest::CurrentView();
2929 Standard_Integer aWidth, aHeight;
2930 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
2931 Standard_Real aRightX, aRightY, aRightZ;
2932 aView->Window()->Size (aWidth, aHeight);
2934 aView->ConvertWithProj (aWidth, aHeight/2,
2935 aRightX, aRightY, aRightZ,
2936 aDirX, aDirY, aDirZ);
2938 aView->ConvertWithProj (aWidth/2, aHeight/2,
2939 aCentX, aCentY, aCentZ,
2940 aDirX, aDirY, aDirZ);
2942 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
2943 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
2944 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
2945 aProjAx.SetLocation (anEye);
2946 aProjAx.SetDirection (aDir);
2947 aProjAx.SetXDirection (aRight);
2950 HLRAlgo_Projector aProjector (aProjAx);
2951 aPolyAlgo->Projector (aProjector);
2952 aPolyAlgo->Load (aSh);
2953 aPolyAlgo->Update ();
2955 aHLRToShape.Update (aPolyAlgo);
2957 // make hlr shape from input shape
2958 TopoDS_Compound aHlrShape;
2959 BRep_Builder aBuilder;
2960 aBuilder.MakeCompound (aHlrShape);
2962 TopoDS_Shape aCompound = aHLRToShape.VCompound();
2963 if (!aCompound.IsNull ())
2965 aBuilder.Add (aHlrShape, aCompound);
2968 // extract visible outlines
2969 aCompound = aHLRToShape.OutLineVCompound();
2970 if (!aCompound.IsNull ())
2972 aBuilder.Add (aHlrShape, aCompound);
2975 // create an AIS shape and display it
2976 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
2977 GetMapOfAIS().Bind (anObject, aHlrName);
2978 aContextAIS->Display (anObject);
2980 aContextAIS->UpdateCurrentViewer ();
2985 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
2986 // manipulating and displaying such an array with AIS context
2987 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
2988 class MyPArrayObject : public AIS_InteractiveObject
2993 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
2994 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
2996 myArrayDescription = theArrayDescription;
2997 myMarkerAspect = theMarkerAspect;
3000 DEFINE_STANDARD_RTTI(MyPArrayObject);
3004 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3005 const Handle(Prs3d_Presentation)& aPresentation,
3006 const Standard_Integer aMode);
3008 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3009 const Standard_Integer /*theMode*/);
3011 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3012 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3013 Standard_Integer &theArgIndex,
3014 Standard_Integer theArgCount,
3015 Standard_Integer theMaxArgs);
3019 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3020 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3024 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3025 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3027 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3028 const Handle(Prs3d_Presentation)& aPresentation,
3029 const Standard_Integer /*aMode*/)
3032 // Parsing array description
3033 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3034 Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
3035 hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
3037 Standard_Integer anArgIndex = 0;
3038 Standard_Integer anArgsCount = myArrayDescription->Length();
3039 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3041 TCollection_AsciiString aCommand;
3042 while (anArgIndex < anArgsCount)
3044 aCommand = myArrayDescription->Value (anArgIndex);
3045 aCommand.LowerCase();
3048 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3050 // vertex has a normal or normal with color or texel
3051 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3052 hasNormals = Standard_True;
3054 // vertex has a color
3055 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3056 hasVColors = Standard_True;
3058 // vertex has a texel
3059 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3060 hasTexels = Standard_True;
3065 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3068 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3069 hasBColors = Standard_True;
3074 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3076 // edge has a hide flag
3077 if (CheckInputCommand ("h", myArrayDescription, anArgIndex, 0, anArgsCount))
3078 hasInfos = Standard_True;
3087 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3088 if (anArrayType == "points")
3090 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3092 else if (anArrayType == "segments")
3093 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3094 else if (anArrayType == "polylines")
3095 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3096 hasVColors, hasBColors, hasInfos);
3097 else if (anArrayType == "triangles")
3098 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3099 hasVColors, hasTexels, hasInfos);
3100 else if (anArrayType == "trianglefans")
3101 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3102 hasNormals, hasVColors,
3103 hasBColors, hasTexels);
3104 else if (anArrayType == "trianglestrips")
3105 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3106 hasNormals, hasVColors,
3107 hasBColors, hasTexels);
3108 else if (anArrayType == "quads")
3109 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3110 hasNormals, hasVColors,
3111 hasTexels, hasInfos);
3112 else if (anArrayType == "quadstrips")
3113 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3114 hasNormals, hasVColors,
3115 hasBColors, hasTexels);
3116 else if (anArrayType == "polygons")
3117 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3118 hasNormals, hasVColors, hasBColors,
3119 hasTexels, hasInfos);
3122 while (anArgIndex < anArgsCount)
3124 aCommand = myArrayDescription->Value (anArgIndex);
3125 aCommand.LowerCase();
3126 if (!aCommand.IsAscii())
3130 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3132 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3133 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3134 myArrayDescription->Value (anArgIndex - 1).RealValue());
3136 // vertex has a normal or normal with color or texel
3137 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3138 anArray->SetVertexNormal (anArray->VertexNumber (),
3139 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3140 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3141 myArrayDescription->Value (anArgIndex - 1).RealValue());
3143 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3144 anArray->SetVertexColor (anArray->VertexNumber (),
3145 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3146 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3147 myArrayDescription->Value (anArgIndex - 1).RealValue());
3149 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3150 anArray->SetVertexTexel (anArray->VertexNumber (),
3151 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3152 myArrayDescription->Value (anArgIndex - 1).RealValue());
3155 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3157 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3159 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3160 anArray->AddBound (aVertCount,
3161 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3162 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3163 myArrayDescription->Value (anArgIndex - 1).RealValue());
3166 anArray->AddBound (aVertCount);
3169 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3171 Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3173 // edge has/hasn't hide flag
3174 if (CheckInputCommand ("h", myArrayDescription, anArgIndex, 0, anArgsCount))
3175 anArray->AddEdge (aVertIndex, Standard_False);
3177 anArray->AddEdge (aVertIndex, Standard_True);
3184 aPresentation->Clear();
3185 if (!myMarkerAspect.IsNull())
3187 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3189 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3192 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3193 const Standard_Integer /*theMode*/)
3195 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3197 Standard_Integer anArgIndex = 1;
3198 while (anArgIndex < myArrayDescription->Length())
3200 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3202 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3203 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3204 myArrayDescription->Value (anArgIndex - 1).RealValue());
3205 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3206 theSelection->Add (aSensetivePoint);
3215 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3216 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3217 Standard_Integer &theArgIndex,
3218 Standard_Integer theArgCount,
3219 Standard_Integer theMaxArgs)
3221 // check if there is more elements than expected
3222 if (theArgIndex >= theMaxArgs)
3225 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3226 aStrCommand.LowerCase();
3227 if (aStrCommand.Search(theCommand) != 1 ||
3228 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3231 // go to the first data element
3234 // check data if it can be converted to numeric
3235 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3237 aStrCommand = theArgsArray->Value (theArgIndex);
3238 if (!aStrCommand.IsRealValue())
3245 //=============================================================================
3246 //function : VDrawPArray
3247 //purpose : Draws primitives array from list of vertexes, bounds, edges
3248 //=============================================================================
3250 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3252 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3253 if (aContextAIS.IsNull())
3255 di << "Call vinit before!\n";
3260 di << "Use: " << argv[0] << " Name TypeOfArray"
3261 << " [vertex] ... [bounds] ... [edges]\n"
3262 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3263 << " trianglefans | trianglestrips | quads |\n"
3264 << " quadstrips | polygons }\n"
3265 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3266 << " [texel={ 't' tx ty }] } \n"
3267 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3268 << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
3272 // read the arguments
3273 Standard_Integer aArgIndex = 1;
3274 TCollection_AsciiString aName (argv[aArgIndex++]);
3275 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3277 Standard_Boolean hasVertex = Standard_False;
3279 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3280 anArgsArray->SetValue (0, anArrayType);
3282 if (anArrayType != "points" &&
3283 anArrayType != "segments" &&
3284 anArrayType != "polylines" &&
3285 anArrayType != "triangles" &&
3286 anArrayType != "trianglefans" &&
3287 anArrayType != "trianglestrips" &&
3288 anArrayType != "quads" &&
3289 anArrayType != "quadstrips" &&
3290 anArrayType != "polygons")
3292 di << "Unexpected type of primitives array\n";
3296 TCollection_AsciiString aCommand;
3297 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3299 aCommand = argv[anArgIndex];
3300 aCommand.LowerCase();
3301 if (!aCommand.IsAscii())
3303 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3304 << "should be an array element: 'v', 'b', 'e' \n";
3308 if (aCommand == "v")
3310 hasVertex = Standard_True;
3313 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3318 di << "You should pass any verticies in the list of array elements\n";
3322 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3323 if (anArrayType == "points")
3325 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3328 // create primitives array object
3329 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3331 // register the object in map
3332 VDisplayAISObject (aName, aPObject);
3337 //=======================================================================
3338 //function : VSetLocation
3339 //purpose : Change location of AIS interactive object
3340 //=======================================================================
3342 static Standard_Integer VSetLocation (Draw_Interpretor& di,
3343 Standard_Integer argc,
3346 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3347 if (aContext.IsNull())
3349 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3355 di << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
3359 TCollection_AsciiString aName (argv[1]);
3360 Standard_Real aX = Draw::Atof (argv[2]);
3361 Standard_Real aY = Draw::Atof (argv[3]);
3362 Standard_Real aZ = Draw::Atof (argv[4]);
3365 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3366 Handle(AIS_InteractiveObject) anIObj;
3367 if (!aMap.IsBound2 (aName))
3369 di << "Use 'vdisplay' before" << "\n";
3374 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3376 // not an AIS_InteractiveObject
3377 if (anIObj.IsNull())
3379 di << argv[1] << " : Not an AIS interactive object" << "\n";
3384 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
3385 TopLoc_Location aLocation (aTrsf);
3386 aContext->SetLocation (anIObj, aLocation);
3387 aContext->UpdateCurrentViewer();
3393 //===============================================================================================
3394 //function : VConnect
3395 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3396 //Draw arg : vconnect name Xo Yo Zo Xu Xv Xw Zu Zv Zw object1 object2 ... [color=NAME]
3397 //===============================================================================================
3399 static Standard_Integer VConnect(Draw_Interpretor& /*di*/,
3400 Standard_Integer argc,
3404 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3405 if (aContext.IsNull())
3407 std::cout << "vconnect error : call vinit before\n";
3408 return 1; // TCL_ERROR
3413 std::cout << "vconnect error: expect at least 11 arguments\n";
3414 return 1; // TCL_ERROR
3418 Standard_Integer anArgIter = 1;
3419 TCollection_AsciiString aName (argv[anArgIter++]);
3420 Handle(AIS_InteractiveObject) anOriginObject;
3421 TCollection_AsciiString aColorString (argv[argc-1]);
3422 Standard_CString aColorName = "";
3423 Standard_Boolean hasColor = Standard_False;
3424 if (aColorString.Search ("color=") != -1)
3426 hasColor = Standard_True;
3427 aColorString.Remove (1, 6);
3428 aColorName = aColorString.ToCString();
3430 Handle(AIS_InteractiveObject) anObject;
3432 // AIS_ConnectedInteractive
3433 if (argc == 12 || (argc == 13 && hasColor))
3435 TCollection_AsciiString anOriginObjectName(argv[11]);
3436 if (aName.IsEqual (anOriginObjectName))
3438 std::cout << "vconnect error: equal names for connected objects\n";
3439 return 1; // TCL_ERROR
3441 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3443 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3444 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3445 if (anOriginObject.IsNull())
3447 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3448 return 1; // TCL_ERROR
3453 Standard_CString aName = anOriginObjectName.ToCString();
3454 TopoDS_Shape aTDShape = DBRep::Get (aName);
3455 if (aTDShape.IsNull())
3457 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3458 return 1; // TCL_ERROR
3460 anOriginObject = new AIS_Shape (aTDShape);
3463 anOriginObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3467 // AIS_MultipleConnectedInteractive
3470 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3471 for (Standard_Integer i = 11; i < aNbShapes; ++i)
3473 TCollection_AsciiString anOriginObjectName (argv[i]);
3474 if (aName.IsEqual (anOriginObjectName))
3476 std::cout << "vconnect error: equal names for connected objects\n";
3479 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3481 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3482 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3483 if (anObject.IsNull())
3485 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
3491 Standard_CString aName = anOriginObjectName.ToCString();
3492 TopoDS_Shape aTDShape = DBRep::Get (aName);
3493 if (aTDShape.IsNull())
3495 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
3498 anObject = new AIS_Shape (aTDShape);
3499 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
3501 if (anOriginObject.IsNull())
3503 anOriginObject = new AIS_MultipleConnectedInteractive();
3504 Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject)->Connect (anObject);
3508 Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject)->Connect (anObject);
3511 if (anOriginObject.IsNull())
3513 std::cout << "vconect error : can't connect input objects\n";
3514 return 1; // TCL_ERROR
3518 // Get location data
3519 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3520 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3521 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3522 Standard_Real aXu = Draw::Atof (argv[anArgIter++]);
3523 Standard_Real aXv = Draw::Atof (argv[anArgIter++]);
3524 Standard_Real aXw = Draw::Atof (argv[anArgIter++]);
3525 Standard_Real aZu = Draw::Atof (argv[anArgIter++]);
3526 Standard_Real aZv = Draw::Atof (argv[anArgIter++]);
3527 Standard_Real aZw = Draw::Atof (argv[anArgIter++]);
3529 // Create transformation
3530 gp_Pnt aPoint(aXo, aYo, aZo);
3531 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3532 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3534 std::cout << "vconnect error : XDir expects to be normal to ZDir\n";
3535 return 1; // TCL_ERROR
3537 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3539 aTrsf.SetTransformation(anAx3);
3540 TopLoc_Location aLocation(aTrsf);
3542 // Create connected object
3543 Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
3544 Handle(AIS_MultipleConnectedInteractive) anOrigin = Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject);
3545 if (anOrigin.IsNull())
3547 aConnected->Connect (anOriginObject, aLocation);
3551 aConnected->Connect (anOrigin, aLocation);
3554 // Check if there is another object with given name
3555 // and remove it from context
3556 if(GetMapOfAIS().IsBound2(aName))
3558 Handle(AIS_InteractiveObject) anObj =
3559 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3560 TheAISContext()->Remove(anObj, Standard_False);
3561 GetMapOfAIS().UnBind2(aName);
3564 // Bind connected object to its name
3565 GetMapOfAIS().Bind (aConnected, aName);
3567 // Display connected object
3568 TheAISContext()->Display (aConnected);
3573 //===============================================================================================
3574 //function : VConnectShape
3575 //purpose : Creates and displays AIS_ConnectedShape from input shape and location
3576 //Draw arg : vconnectsh name Xo Yo Zo Xu Xv Xw Zu Zv Zw shape1 shape2 ... [color=NAME]
3577 //===============================================================================================
3579 static Standard_Integer VConnectShape(Draw_Interpretor& /*di*/,
3580 Standard_Integer argc,
3584 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3585 if (aContext.IsNull())
3587 std::cout << "vconnectsh error : call vinit before\n";
3588 return 1; // TCL_ERROR
3593 std::cout << "vconnectsh error: expect at least 11 arguments\n";
3594 return 1; // TCL_ERROR
3598 Standard_Integer anArgIter = 1;
3599 TCollection_AsciiString aName (argv[anArgIter++]);
3600 Handle(AIS_InteractiveObject) anOriginShape;
3601 TCollection_AsciiString aColorString(argv[argc-1]);
3602 Standard_CString aColorName = "";
3603 Standard_Boolean hasColor = Standard_False;
3604 if (aColorString.Search ("color=") != -1)
3606 hasColor = Standard_True;
3607 aColorString.Remove (1, 6);
3608 aColorName = aColorString.ToCString();
3610 Handle(AIS_Shape) aShape;
3612 // AIS_ConnectedShape
3613 if (argc == 12 || (argc == 13 && hasColor))
3615 TCollection_AsciiString anOriginShapeName (argv[11]);
3616 if (aName.IsEqual (anOriginShapeName))
3618 std::cout << "vconnectsh error: equal names for connected shapes\n";
3619 return 1; // TCL_ERROR
3621 if (GetMapOfAIS().IsBound2 (anOriginShapeName))
3623 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginShapeName);
3624 anOriginShape = Handle(AIS_Shape)::DownCast(anObj);
3625 if (anOriginShape.IsNull())
3627 std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
3628 return 1; // TCL_ERROR
3633 Standard_CString aName = anOriginShapeName.ToCString();
3634 TopoDS_Shape aTDShape = DBRep::Get (aName);
3635 if (aTDShape.IsNull())
3637 std::cout << "vconnectsh error: object " << anOriginShapeName << " doesn't exist\n";
3638 return 1; // TCL_ERROR
3640 anOriginShape = new AIS_Shape (aTDShape);
3643 anOriginShape->SetColor (ViewerTest::GetColorFromName (aColorName));
3647 // AIS_MultipleConnectedShape
3650 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3651 for (Standard_Integer i = 11; i < aNbShapes; ++i)
3653 TCollection_AsciiString anOriginShapeName (argv[i]);
3654 if (aName.IsEqual (anOriginShapeName))
3656 std::cout << "vconnectsh error: equal names for connected shapes\n";
3659 if (GetMapOfAIS().IsBound2 (anOriginShapeName))
3661 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginShapeName);
3662 aShape = Handle(AIS_Shape)::DownCast(anObj);
3663 if (aShape.IsNull())
3665 std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n";
3671 Standard_CString aName = anOriginShapeName.ToCString();
3672 TopoDS_Shape aTDShape = DBRep::Get (aName);
3673 if (aTDShape.IsNull())
3675 std::cout << "vconnectsh error: object " << anOriginShapeName << " doesn't exist\n";
3678 aShape = new AIS_Shape (aTDShape);
3681 aShape->SetColor (ViewerTest::GetColorFromName (aColorName));
3684 if (anOriginShape.IsNull())
3686 anOriginShape = new AIS_MultipleConnectedShape (aShape->Shape());
3687 Handle(AIS_MultipleConnectedShape)::DownCast(anOriginShape)->Connect (aShape);
3691 Handle(AIS_MultipleConnectedShape)::DownCast(anOriginShape)->Connect (aShape);
3694 if (anOriginShape.IsNull())
3696 std::cout << "vconectsh error : can't connect input objects\n";
3697 return 1; // TCL_ERROR
3701 // Get location data
3702 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3703 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3704 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
3705 Standard_Real aXu = Draw::Atof (argv[anArgIter++]);
3706 Standard_Real aXv = Draw::Atof (argv[anArgIter++]);
3707 Standard_Real aXw = Draw::Atof (argv[anArgIter++]);
3708 Standard_Real aZu = Draw::Atof (argv[anArgIter++]);
3709 Standard_Real aZv = Draw::Atof (argv[anArgIter++]);
3710 Standard_Real aZw = Draw::Atof (argv[anArgIter++]);
3712 // Create transformation
3713 gp_Pnt aPoint(aXo, aYo, aZo);
3714 gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
3715 if(!anXDir.IsNormal(aZDir, Precision::Angular()))
3717 std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n";
3718 return 1; // TCL_ERROR
3720 gp_Ax3 anAx3(aPoint, aZDir, anXDir);
3722 aTrsf.SetTransformation(anAx3);
3723 TopLoc_Location aLocation(aTrsf);
3725 // Create connected shape
3726 Handle(AIS_ConnectedInteractive) aConnected;
3727 Handle(AIS_Shape) anOrigin = Handle(AIS_Shape)::DownCast(anOriginShape);
3728 if (!anOrigin.IsNull())
3730 aConnected = new AIS_ConnectedShape (anOrigin);
3731 aConnected->Connect (anOrigin, aLocation);
3735 aConnected = new AIS_ConnectedInteractive();
3736 aConnected->Connect (anOriginShape, aLocation);
3739 // Check if there is another object with given name
3740 // and remove it from context
3741 if(GetMapOfAIS().IsBound2(aName))
3743 Handle(AIS_InteractiveObject) anObj =
3744 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3745 TheAISContext()->Remove(anObj, Standard_False);
3746 GetMapOfAIS().UnBind2(aName);
3749 // Bind connected shape to its name
3750 GetMapOfAIS().Bind (aConnected, aName);
3752 // Display connected shape
3753 TheAISContext()->Display (aConnected);
3758 //===============================================================================================
3759 //function : VSetSelectionMode
3760 //purpose : Sets input selection mode for input object or for all displayed objects
3761 //Draw arg : vselmode [object] mode On/Off (1/0)
3762 //===============================================================================================
3764 // function : InList
3765 // purpose : checks if theMode is already turned on for theObj
3766 Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext,
3767 Handle(AIS_InteractiveObject) theObj,
3768 Standard_Integer theMode)
3770 TColStd_ListOfInteger anArray;
3771 theAISContext->ActivatedModes(theObj, anArray);
3772 TColStd_ListIteratorOfListOfInteger anIt(anArray);
3773 for(; anIt.More(); anIt.Next())
3775 if(anIt.Value() == theMode)
3776 return Standard_True;
3778 return Standard_False;
3781 static Standard_Integer VSetSelectionMode(Draw_Interpretor& /*di*/,
3782 Standard_Integer argc,
3786 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3787 if(anAISContext.IsNull())
3789 std::cout << "Call vinit before!\n";
3790 return 1; // TCL_ERROR
3793 // Check the arguments
3794 if(argc != 3 && argc != 4)
3796 std::cout << "vselmode error : expects at least 2 arguments.\n"
3797 << "Type help "<< argv[0] <<" for more information.";
3798 return 1; // TCL_ERROR
3801 Handle(AIS_InteractiveObject) anObj;
3803 // Set new selection mode for all objects in context
3807 Standard_Integer aMode = Draw::Atoi(argv[1]);
3808 Standard_Boolean isTurnOn = Draw::Atoi(argv[2]);
3810 // Get all displayed objects
3811 AIS_ListOfInteractive anObjList;
3812 anAISContext->DisplayedObjects(anObjList);
3813 AIS_ListIteratorOfListOfInteractive anObjIter;
3817 if(anAISContext->HasOpenedContext())
3818 anAISContext->CloseLocalContext();
3822 if(aMode != 0 && isTurnOn)
3824 if(!anAISContext->HasOpenedContext())
3826 anAISContext->OpenLocalContext();
3827 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3829 anAISContext->Activate(anObjIter.Value(), aMode);
3834 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3836 anObj = anObjIter.Value();
3837 if(!InList(anAISContext, anObj, aMode))
3838 anAISContext->Activate(anObj, aMode);
3844 if(aMode != 0 && !isTurnOn)
3846 if(anAISContext->HasOpenedContext())
3848 for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
3850 anObj = anObjIter.Value();
3851 if(InList(anAISContext, anObj, aMode))
3852 anAISContext->Deactivate(anObj, aMode);
3858 // Set new selection mode for named object
3862 Standard_Integer aMode = Draw::Atoi(argv[2]);
3863 Standard_Boolean isTurnOn = Draw::Atoi(argv[3]);
3864 TCollection_AsciiString aName(argv[1]);
3866 // Check if there is an object with given name in context
3867 if(GetMapOfAIS().IsBound2(aName))
3869 anObj = Handle(AIS_InteractiveObject)::
3870 DownCast(GetMapOfAIS().Find2(aName));
3873 std::cout << "vselmode error : object name is used for non AIS viewer\n";
3874 return 1; // TCL_ERROR
3880 if(anAISContext->HasOpenedContext())
3881 anAISContext->CloseLocalContext();
3884 if(aMode != 0 && isTurnOn)
3886 if(!anAISContext->HasOpenedContext())
3888 anAISContext->OpenLocalContext();
3889 anAISContext->Activate(anObj, aMode);
3893 if(!InList(anAISContext, anObj, aMode))
3894 anAISContext->Activate(anObj, aMode);
3899 if(aMode != 0 && !isTurnOn)
3901 if(anAISContext->HasOpenedContext())
3903 if(InList(anAISContext, anObj, aMode))
3904 anAISContext->Deactivate(anObj, aMode);
3911 //==========================================================================
3913 //purpose : creates Triangle based on AIS_InteractiveObject.
3914 // This class was implemented for testing Select3D_SensitiveTriangle
3915 //===========================================================================
3916 DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3917 class Triangle: public AIS_InteractiveObject
3921 DEFINE_STANDARD_RTTI(FilledCircle);
3922 Triangle (const gp_Pnt& theP1,
3923 const gp_Pnt& theP2,
3924 const gp_Pnt& theP3);
3926 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
3927 const Handle(Prs3d_Presentation)& thePresentation,
3928 const Standard_Integer theMode);
3930 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
3931 const Standard_Integer theMode);
3937 IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
3938 IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
3940 Triangle::Triangle (const gp_Pnt& theP1,
3941 const gp_Pnt& theP2,
3942 const gp_Pnt& theP3)
3949 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
3950 const Handle(Prs3d_Presentation)& thePresentation,
3951 const Standard_Integer /*theMode*/)
3953 thePresentation->Clear();
3955 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
3956 anEdgeMaker2(myPoint2, myPoint3),
3957 anEdgeMaker3(myPoint3, myPoint1);
3959 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
3960 anEdge2 = anEdgeMaker2.Edge(),
3961 anEdge3 = anEdgeMaker3.Edge();
3962 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
3965 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
3966 TopoDS_Wire aWire = aWireMaker.Wire();
3967 if(aWire.IsNull()) return;
3969 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
3970 TopoDS_Face aFace = aFaceMaker.Face();
3971 if(aFace.IsNull()) return;
3973 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
3976 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
3977 const Standard_Integer /*theMode*/)
3979 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
3980 Handle(Select3D_SensitiveTriangle) aSensTriangle =
3981 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
3982 theSelection->Add(aSensTriangle);
3985 //===========================================================================
3986 //function : VTriangle
3987 //Draw arg : vtriangle Name PointName PointName PointName
3988 //purpose : creates and displays Triangle
3989 //===========================================================================
3992 //purpose : checks if the object with theName is AIS_Point,
3993 // if yes initialize thePoint from MapOfAIS
3994 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
3995 Handle(AIS_Point)& thePoint)
3997 Handle(AIS_InteractiveObject) anObject =
3998 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
3999 if(anObject.IsNull() ||
4000 anObject->Type() != AIS_KOI_Datum ||
4001 anObject->Signature() != 1)
4003 return Standard_False;
4005 thePoint = Handle(AIS_Point)::DownCast(anObject);
4006 if(thePoint.IsNull())
4007 return Standard_False;
4008 return Standard_True;
4012 //purpose: checks if thePoint1 is equal to thePoint2
4013 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4014 const Handle(Geom_CartesianPoint)& thePoint2)
4016 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4017 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4018 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4020 return Standard_True;
4022 return Standard_False;
4025 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4026 Standard_Integer argc,
4032 std::cout<<"vtriangle error: expects 4 argumnets\n";
4033 return 1; // TCL_ERROR
4036 TheAISContext()->CloseAllContexts();
4038 // Get and check values
4039 TCollection_AsciiString aName(argv[1]);
4041 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4042 if (!IsPoint(argv[2], aPoint1))
4044 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4045 return 1; // TCL_ERROR
4047 if (!IsPoint(argv[3], aPoint2))
4049 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4050 return 1; // TCL_ERROR
4052 if (!IsPoint(argv[4], aPoint3))
4054 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4055 return 1; // TCL_ERROR
4058 // Check that points are different
4059 Handle(Geom_CartesianPoint) aCartPoint1 =
4060 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4061 Handle(Geom_CartesianPoint) aCartPoint2 =
4062 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4063 // Test aPoint1 = aPoint2
4064 if (IsMatch(aCartPoint1, aCartPoint2))
4066 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4067 return 1; // TCL_ERROR
4069 // Test aPoint2 = aPoint3
4070 Handle(Geom_CartesianPoint) aCartPoint3 =
4071 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4072 if (IsMatch(aCartPoint2, aCartPoint3))
4074 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4075 return 1; // TCL_ERROR
4077 // Test aPoint3 = aPoint1
4078 if (IsMatch(aCartPoint1, aCartPoint3))
4080 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4081 return 1; // TCL_ERROR
4085 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4087 aCartPoint3->Pnt());
4089 // Check if there is an object with given name
4090 // and remove it from context
4091 if (GetMapOfAIS().IsBound2(aName))
4093 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4094 Handle(AIS_InteractiveObject) anInterObj =
4095 Handle(AIS_InteractiveObject)::DownCast(anObj);
4096 TheAISContext()->Remove(anInterObj, Standard_False);
4097 GetMapOfAIS().UnBind2(aName);
4100 // Bind triangle to its name
4101 GetMapOfAIS().Bind(aTriangle, aName);
4104 TheAISContext()->Display(aTriangle);
4108 //class : SegmentObject
4109 //purpose: creates segment based on AIS_InteractiveObject.
4110 // This class was implemented for testing Select3D_SensitiveCurve
4111 DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4112 class SegmentObject: public AIS_InteractiveObject
4116 DEFINE_STANDARD_RTTI(SegmentObject);
4117 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4119 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4120 const Handle(Prs3d_Presentation)& thePresentation,
4121 const Standard_Integer theMode);
4123 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4124 const Standard_Integer theMode);
4129 IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4130 IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4132 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4138 void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &/*thePresentationManager*/,
4139 const Handle_Prs3d_Presentation &thePresentation,
4140 const Standard_Integer /*theMode*/)
4142 thePresentation->Clear();
4143 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4144 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4145 if (anEdge.IsNull())
4147 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4148 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4151 void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
4152 const Standard_Integer /*theMode*/)
4154 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4155 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4156 anArray->SetValue(1, myPoint1);
4157 anArray->SetValue(2, myPoint2);
4158 Handle(Select3D_SensitiveCurve) aSensCurve =
4159 new Select3D_SensitiveCurve(anOwner, anArray);
4160 theSelection->Add(aSensCurve);
4163 //=======================================================================
4164 //function : VSegment
4165 //Draw args : vsegment Name PointName PointName
4166 //purpose : creates and displays Segment
4167 //=======================================================================
4168 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4169 Standard_Integer argc,
4175 std::cout<<"vsegment error: expects 3 arguments\n";
4176 return 1; // TCL_ERROR
4179 TheAISContext()->CloseAllContexts();
4181 // Get and check arguments
4182 TCollection_AsciiString aName(argv[1]);
4183 Handle(AIS_Point) aPoint1, aPoint2;
4184 if (!IsPoint(argv[2], aPoint1))
4186 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4187 return 1; // TCL_ERROR
4189 if (!IsPoint(argv[3], aPoint2))
4191 std::cout<<"vsegment error: the 3d argument should be a point\n";
4192 return 1; // TCL_ERROR
4194 //Check that points are different
4195 Handle(Geom_CartesianPoint) aCartPoint1 =
4196 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4197 Handle(Geom_CartesianPoint) aCartPoint2 =
4198 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4199 if(IsMatch(aCartPoint1, aCartPoint2))
4201 std::cout<<"vsegment error: equal points\n";
4202 return 1; // TCL_ERROR
4206 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4207 // Check if there is an object with given name
4208 // and remove it from context
4209 if (GetMapOfAIS().IsBound2(aName))
4211 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4212 Handle(AIS_InteractiveObject) anInterObj =
4213 Handle(AIS_InteractiveObject)::DownCast(anObj);
4214 TheAISContext()->Remove(anInterObj, Standard_False);
4215 GetMapOfAIS().UnBind2(aName);
4218 // Bind segment to its name
4219 GetMapOfAIS().Bind(aSegment, aName);
4222 TheAISContext()->Display(aSegment);
4226 //=======================================================================
4227 //function : VObjZLayer
4228 //purpose : Set or get z layer id for presentable object
4229 //=======================================================================
4231 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4232 Standard_Integer argc,
4235 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4236 if (aContext.IsNull())
4238 di << argv[0] << "Call 'vinit' before!\n";
4243 TCollection_AsciiString aOperation;
4245 aOperation = TCollection_AsciiString (argv [1]);
4247 // check for correct arguments
4248 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4249 !(argc == 3 && aOperation.IsEqual ("get")))
4251 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4252 di << " set - set layer id for interactive object, layerid - z layer id\n";
4253 di << " get - get layer id of interactive object\n";
4254 di << " argument layerid should be passed for set operation only\n";
4259 TCollection_AsciiString aName (argv[2]);
4260 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4261 if (!aMap.IsBound2 (aName))
4263 di << "Use 'vdisplay' before" << "\n";
4267 // find interactive object
4268 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4269 Handle(AIS_InteractiveObject) anInterObj =
4270 Handle(AIS_InteractiveObject)::DownCast (anObj);
4271 if (anInterObj.IsNull())
4273 di << "Not an AIS interactive object!\n";
4277 // process operation
4278 if (aOperation.IsEqual ("set"))
4280 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4281 aContext->SetZLayer (anInterObj, aLayerId);
4283 else if (aOperation.IsEqual ("get"))
4285 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4291 //=======================================================================
4292 //function : VPolygonOffset
4293 //purpose : Set or get polygon offset parameters
4294 //=======================================================================
4295 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4296 Standard_Integer argc,
4299 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4300 if (aContext.IsNull())
4302 std::cout << argv[0] << " Call 'vinit' before!\n";
4306 if (argc > 2 && argc != 5)
4308 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4309 "without arguments prints the default values" << std::endl;
4314 Handle(AIS_InteractiveObject) anInterObj;
4317 TCollection_AsciiString aName (argv[1]);
4318 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4319 if (!aMap.IsBound2 (aName))
4321 std::cout << "Use 'vdisplay' before" << std::endl;
4325 // find interactive object
4326 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4327 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4328 if (anInterObj.IsNull())
4330 std::cout << "Not an AIS interactive object!" << std::endl;
4335 Standard_Integer aMode;
4336 Standard_ShortReal aFactor, aUnits;
4339 aMode = Draw::Atoi(argv[2]);
4340 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4341 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
4343 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4344 aContext->UpdateCurrentViewer();
4349 if (anInterObj->HasPolygonOffsets())
4351 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4352 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4353 std::cout << "\tMode: " << aMode << std::endl;
4354 std::cout << "\tFactor: " << aFactor << std::endl;
4355 std::cout << "\tUnits: " << aUnits << std::endl;
4360 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4364 std::cout << "Default polygon offset parameters:" << std::endl;
4365 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4366 std::cout << "\tMode: " << aMode << std::endl;
4367 std::cout << "\tFactor: " << aFactor << std::endl;
4368 std::cout << "\tUnits: " << aUnits << std::endl;
4373 //=======================================================================
4374 //function : VShowFaceBoundaries
4375 //purpose : Set face boundaries drawing on/off for ais object
4376 //=======================================================================
4377 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
4378 Standard_Integer argc,
4381 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4382 if (aContext.IsNull ())
4384 std::cout << argv[0] << " Call 'vinit' before!\n";
4388 if ((argc != 3 && argc < 6) || argc > 8)
4390 std::cout << "Usage :\n " << argv[0]
4391 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4392 << " ObjectName - name of AIS interactive object. \n"
4393 << " if ObjectName = \"\", then set as default\n"
4394 << " settings for all newly displayed objects\n"
4395 << " isOn - flag indicating whether the boundaries\n"
4396 << " should be turned on or off (can be set\n"
4397 << " to 0 (off) or 1 (on)).\n"
4398 << " R, G, B - red, green and blue components of boundary\n"
4399 << " color in range (0 - 255).\n"
4400 << " (default is (0, 0, 0)\n"
4401 << " LineWidth - line width\n"
4402 << " (default is 1)\n"
4403 << " LineStyle - line fill style :\n"
4408 << " (default is solid)";
4412 TCollection_AsciiString aName (argv[1]);
4414 Quantity_Parameter aRed = 0.0;
4415 Quantity_Parameter aGreen = 0.0;
4416 Quantity_Parameter aBlue = 0.0;
4417 Standard_Real aWidth = 1.0;
4418 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4421 Handle(AIS_InteractiveObject) anInterObj;
4423 // if name is empty - apply attributes for default aspect
4424 if (!aName.IsEmpty ())
4426 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4427 if (!aMap.IsBound2 (aName))
4429 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4433 // find interactive object
4434 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4435 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4436 if (anInterObj.IsNull ())
4438 std::cout << "Not an AIS interactive object!" << std::endl;
4443 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4444 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4446 // turn boundaries on/off
4447 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
4448 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4450 // set boundary line color
4454 aRed = Draw::Atof (argv[3])/255.;
4455 aGreen = Draw::Atof (argv[4])/255.;
4456 aBlue = Draw::Atof (argv[5])/255.;
4462 aWidth = (Standard_Real)Draw::Atof (argv[6]);
4465 // select appropriate line type
4468 switch (Draw::Atoi (argv[7]))
4470 case 1: aLineType = Aspect_TOL_DASH; break;
4471 case 2: aLineType = Aspect_TOL_DOT; break;
4472 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4474 aLineType = Aspect_TOL_SOLID;
4478 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4480 Handle(Prs3d_LineAspect) aBoundaryAspect =
4481 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4483 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4485 TheAISContext()->Redisplay (anInterObj);
4490 // This class is used for testing markers.
4491 DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4492 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4497 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4498 const Standard_Integer& thePointsOnSide,
4499 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4501 myStartPoint = theStartPoint;
4502 myPointsOnSide = thePointsOnSide;
4503 myMarkerAspect = theMarkerAspect;
4506 DEFINE_STANDARD_RTTI(MyPArrayObject);
4510 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4511 const Handle(Prs3d_Presentation)& aPresentation,
4512 const Standard_Integer aMode);
4514 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4515 const Standard_Integer /*theMode*/);
4519 gp_XYZ myStartPoint;
4520 Standard_Integer myPointsOnSide;
4521 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4524 IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4525 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4527 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4528 const Handle(Prs3d_Presentation)& aPresentation,
4529 const Standard_Integer /*aMode*/)
4531 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4532 if (myPointsOnSide == 1)
4534 anArray->AddVertex (myStartPoint);
4538 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4540 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4542 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4544 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4545 anArray->SetVertexColor (anArray->VertexNumber(),
4548 k / myPointsOnSide);
4554 aPresentation->Clear();
4555 if (!myMarkerAspect.IsNull())
4557 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4559 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4562 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4563 const Standard_Integer /*theMode*/)
4565 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4567 if (myPointsOnSide == 1)
4569 gp_Pnt aPoint (myStartPoint);
4570 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4571 theSelection->Add (aSensetivePoint);
4575 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4577 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4579 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4581 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4582 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4583 theSelection->Add (aSensetivePoint);
4589 //=======================================================================
4590 //function : VMarkersTest
4591 //purpose : Draws an array of markers for testing purposes.
4592 //=======================================================================
4593 static Standard_Integer VMarkersTest (Draw_Interpretor&,
4594 Standard_Integer theArgNb,
4595 const char** theArgVec)
4597 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4598 if (aContext.IsNull())
4600 std::cerr << "Call 'vinit' before!\n";
4606 std::cerr << "Usage :\n " << theArgVec[0]
4607 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
4611 Standard_Integer anArgIter = 1;
4613 TCollection_AsciiString aName (theArgVec[anArgIter++]);
4614 TCollection_AsciiString aFileName;
4615 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
4616 Atof (theArgVec[anArgIter + 1]),
4617 Atof (theArgVec[anArgIter + 2]));
4620 Standard_Integer aPointsOnSide = 10;
4621 Standard_Integer aMarkerType = -1;
4622 Standard_Real aScale = 1.0;
4623 for (; anArgIter < theArgNb; ++anArgIter)
4625 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4626 if (anArg.Search ("PointsOnSide=") > -1)
4628 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
4630 else if (anArg.Search ("MarkerType=") > -1)
4632 aMarkerType = anArg.Token ("=", 2).IntegerValue();
4634 else if (anArg.Search ("Scale=") > -1)
4636 aScale = anArg.Token ("=", 2).RealValue();
4638 else if (anArg.Search ("FileName=") > -1)
4640 aFileName = anArg.Token ("=", 2);
4644 std::cerr << "Wrong argument: " << anArg << "\n";
4649 Handle(Graphic3d_AspectMarker3d) anAspect;
4650 Handle(Image_AlienPixMap) anImage;
4651 Quantity_Color aColor (Quantity_NOC_GREEN1);
4652 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
4653 && !aFileName.IsEmpty())
4655 anImage = new Image_AlienPixMap();
4656 if (!anImage->Load (aFileName))
4658 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
4661 anAspect = new Graphic3d_AspectMarker3d (anImage);
4665 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
4668 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
4669 VDisplayAISObject (aName, aMarkersArray);
4674 //=======================================================================
4675 //function : TextToBrep
4676 //purpose : Tool for conversion text to occt-shapes
4677 //=======================================================================
4679 static int TextToBRep (Draw_Interpretor& /*theDI*/,
4680 Standard_Integer theArgNb,
4681 const char** theArgVec)
4686 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
4690 Standard_Integer anArgIter = 1;
4691 Standard_CString aResName = theArgVec[anArgIter++];
4692 Standard_CString aText = theArgVec[anArgIter++];
4693 Standard_CString aFontName = theArgVec[anArgIter++];
4694 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
4696 Font_BRepFont aFont;
4697 Font_FontAspect aFontAspect = Font_FA_Regular;
4698 Standard_Boolean isCompositeCurve = Standard_False;
4699 gp_Ax3 aPenAx3 (gp::XOY());
4701 while (anArgIter < theArgNb)
4703 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
4704 if (anArg.Search ("x=") > -1)
4706 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
4708 else if (anArg.Search ("y=") > -1)
4710 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
4712 else if (anArg.Search ("z=") > -1)
4714 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
4716 else if (anArg.Search ("composite=") > -1)
4718 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
4720 else if (anArg.Search ("regular") > -1)
4722 aFontAspect = Font_FA_Regular;
4724 else if (anArg.Search ("bolditalic") > -1)
4726 aFontAspect = Font_FA_BoldItalic;
4728 else if (anArg.Search ("bold") > -1)
4730 aFontAspect = Font_FA_Bold;
4732 else if (anArg.Search ("italic") > -1)
4734 aFontAspect = Font_FA_Italic;
4738 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
4742 aFont.SetCompositeCurveMode (isCompositeCurve);
4743 if (!aFont.Init (aFontName, aFontAspect, aSize))
4745 std::cerr << "Font initialization error\n";
4749 aPenAx3.SetLocation (aPenLoc);
4750 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
4754 //=======================================================================
4755 //function : ObjectsCommands
4757 //=======================================================================
4759 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
4761 const char *group ="AISObjects";
4762 theCommands.Add("vtrihedron",
4763 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
4764 __FILE__,VTrihedron,group);
4766 theCommands.Add("vtri2d",
4767 "vtri2d Name Selection in the viewer only ",
4768 __FILE__,VTrihedron2D ,group);
4770 theCommands.Add("vplanetri",
4771 "vplanetri Name Selection in the viewer only ",
4772 __FILE__,VPlaneTrihedron ,group);
4774 theCommands.Add("vsize",
4775 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
4776 __FILE__,VSize,group);
4778 theCommands.Add("vaxis",
4779 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
4780 __FILE__,VAxisBuilder,group);
4782 theCommands.Add("vaxispara",
4784 __FILE__,VAxisBuilder,group);
4786 theCommands.Add("vaxisortho",
4788 __FILE__,VAxisBuilder,group);
4790 theCommands.Add("vpoint",
4791 "vpoint PointName [Xa] [Ya] [Za] ",
4792 __FILE__,VPointBuilder,group);
4794 theCommands.Add("vplane",
4795 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
4796 __FILE__,VPlaneBuilder,group);
4798 theCommands.Add("vplanepara",
4799 "vplanepara PlaneName ",
4800 __FILE__,VPlaneBuilder,group);
4802 theCommands.Add("vplaneortho",
4803 "vplaneortho PlaneName ",
4804 __FILE__,VPlaneBuilder,group);
4806 theCommands.Add("vline",
4807 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
4808 __FILE__,VLineBuilder,group);
4810 theCommands.Add("vcircle",
4811 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
4812 __FILE__,VCircleBuilder,group);
4814 theCommands.Add("vdrawtext",
4815 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
4816 __FILE__,VDrawText,group);
4818 theCommands.Add("vdrawsphere",
4819 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n",
4820 __FILE__,VDrawSphere,group);
4822 theCommands.Add ("vsetlocation",
4823 "vsetlocation : name x y z; set new location for an interactive object",
4824 __FILE__, VSetLocation, group);
4828 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
4829 __FILE__, VComputeHLR, group);
4831 theCommands.Add("vdrawparray",
4832 "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' }] ]",
4833 __FILE__,VDrawPArray,group);
4835 theCommands.Add("vconnect",
4836 "vconnect : name Xo Yo Zo Xu Xv Xw Zu Zv Zw object1 object2 ... [color=NAME]",
4837 __FILE__, VConnect, group);
4839 theCommands.Add("vconnectsh",
4840 "vconnectsh : name Xo Yo Zo Xu Xv Xw Zu Zv Zw shape1 shape2 ... [color=NAME]",
4841 __FILE__, VConnectShape, group);
4843 theCommands.Add("vselmode",
4844 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
4845 " switches selection mode for the determined object or\n"
4846 " for all objects in context.\n"
4847 " mode_number is non-negative integer that has different\n"
4848 " meaning for different interactive object classes.\n"
4849 " For shapes the following mode_number values are allowed:\n"
4859 " is_turned_on is:\n"
4860 " 1 if mode is to be switched on\n"
4861 " 0 if mode is to be switched off\n",
4862 __FILE__, VSetSelectionMode, group);
4864 theCommands.Add("vtriangle",
4865 "vtriangle Name PointName PointName PointName",
4866 __FILE__, VTriangle,group);
4868 theCommands.Add("vsegment",
4869 "vsegment Name PointName PointName",
4870 __FILE__, VSegment,group);
4872 theCommands.Add("vobjzlayer",
4873 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
4874 __FILE__, VObjZLayer, group);
4876 theCommands.Add("vpolygonoffset",
4877 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
4878 __FILE__, VPolygonOffset, group);
4880 theCommands.Add ("vshowfaceboundary",
4881 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
4882 "- turns on/off drawing of face boundaries for ais object "
4883 "and defines boundary line style.",
4884 __FILE__, VShowFaceBoundary, group);
4886 theCommands.Add ("vmarkerstest",
4887 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
4888 __FILE__, VMarkersTest, group);
4890 theCommands.Add ("text2brep",
4891 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
4892 __FILE__, TextToBRep, group);