1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
19 #include <Quantity_NameOfColor.hxx>
20 #include <Draw_Interpretor.hxx>
22 #include <Draw_Appli.hxx>
25 #include <Font_BRepFont.hxx>
26 #include <Font_FontMgr.hxx>
27 #include <OSD_Chronometer.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <Visual3d_View.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_DisplayMode.hxx>
36 #include <AIS_PointCloud.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_AutoUpdater.hxx>
40 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_EventManager.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Builder.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Face.hxx>
62 #include <Draw_Window.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_DisplayMode.hxx>
66 #include <AIS_Shape.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <Geom_Plane.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <TCollection_HAsciiString.hxx>
73 #include <GC_MakePlane.hxx>
74 #include <gp_Circ.hxx>
75 #include <AIS_Axis.hxx>
76 #include <Geom_Axis2Placement.hxx>
77 #include <Geom_Axis1Placement.hxx>
78 #include <AIS_Trihedron.hxx>
79 #include <AIS_Axis.hxx>
80 #include <gp_Trsf.hxx>
81 #include <TopLoc_Location.hxx>
83 #include <HLRAlgo_Projector.hxx>
84 #include <HLRBRep_PolyAlgo.hxx>
85 #include <HLRBRep_PolyHLRToShape.hxx>
86 #include <Aspect_Window.hxx>
88 #include <Graphic3d_ArrayOfPoints.hxx>
89 #include <Graphic3d_ArrayOfSegments.hxx>
90 #include <Graphic3d_ArrayOfPolylines.hxx>
91 #include <Graphic3d_ArrayOfTriangles.hxx>
92 #include <Graphic3d_ArrayOfTriangleFans.hxx>
93 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
94 #include <Graphic3d_ArrayOfQuadrangles.hxx>
95 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
96 #include <Graphic3d_ArrayOfPolygons.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_Group.hxx>
99 #include <Standard_Real.hxx>
101 #include <AIS_Circle.hxx>
102 #include <AIS_Drawer.hxx>
103 #include <BRepBuilderAPI_MakeEdge.hxx>
104 #include <BRepBuilderAPI_MakeFace.hxx>
105 #include <BRepBuilderAPI_MakeWire.hxx>
106 #include <Geom_Circle.hxx>
107 #include <GC_MakeCircle.hxx>
108 #include <Prs3d_Presentation.hxx>
109 #include <Select3D_SensitiveCircle.hxx>
110 #include <SelectMgr_EntityOwner.hxx>
111 #include <SelectMgr_Selection.hxx>
112 #include <StdFail_NotDone.hxx>
113 #include <StdPrs_ShadedShape.hxx>
114 #include <TopoDS_Wire.hxx>
116 #include <AIS_MultipleConnectedInteractive.hxx>
117 #include <AIS_ConnectedInteractive.hxx>
118 #include <TopLoc_Location.hxx>
119 #include <TColStd_ListOfInteger.hxx>
120 #include <TColStd_ListIteratorOfListOfInteger.hxx>
122 #include <Select3D_SensitiveTriangle.hxx>
123 #include <Select3D_SensitiveCurve.hxx>
124 #include <Select3D_SensitivePoint.hxx>
125 #include <BRepAdaptor_Curve.hxx>
126 #include <StdPrs_Curve.hxx>
128 #include <BRepExtrema_ExtPC.hxx>
129 #include <BRepExtrema_ExtPF.hxx>
131 #include <Prs3d_VertexDrawMode.hxx>
132 #include <Prs3d_LineAspect.hxx>
133 #include <Prs3d_PointAspect.hxx>
135 #include <Image_AlienPixMap.hxx>
136 #include <TColStd_HArray1OfAsciiString.hxx>
139 # define _CRT_SECURE_NO_DEPRECATE
140 # pragma warning (disable:4996)
143 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
144 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
145 const Handle(AIS_InteractiveObject)& theAISObj,
146 Standard_Boolean theReplaceIfExists = Standard_True);
147 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
148 extern Handle(AIS_InteractiveContext)& TheAISContext();
151 //==============================================================================
152 //function : Vtrihedron 2d
153 //purpose : Create a plane with a 2D trihedron from a faceselection
154 //Draw arg : vtri2d name
155 //==============================================================================
156 #include <AIS_PlaneTrihedron.hxx>
160 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
163 // Verification des arguments
164 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
167 Standard_Integer myCurrentIndex;
168 // Fermeture des contextes
169 TheAISContext()->CloseAllContexts();
170 // Ouverture d'un contexte local et recuperation de son index.
171 TheAISContext()->OpenLocalContext();
172 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
173 // On active les modes de selections faces.
174 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
175 di<<" Select a face ."<<"\n";
177 // Boucle d'attente waitpick.
178 Standard_Integer argccc = 5;
179 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
180 const char **argvvv = (const char **) bufff;
181 while (ViewerMainLoop( argccc, argvvv) ) { }
185 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
186 ShapeB = TheAISContext()->SelectedShape();
189 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
191 // Construction du Plane
192 // recuperation des edges des faces.
193 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
195 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
199 // si il y a plusieurs edges
200 if (FaceExpB.More() ) {
202 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
203 BRepAdaptor_Curve theCurveB(EdgeB);
204 BRepAdaptor_Curve theCurveC(EdgeC);
205 A=theCurveC.Value(0.1);
206 B=theCurveC.Value(0.9);
207 C=theCurveB.Value(0.5);
210 // FaceB a 1 unique edge courbe
211 BRepAdaptor_Curve theCurveB(EdgeB);
212 A=theCurveB.Value(0.1);
213 B=theCurveB.Value(0.9);
214 C=theCurveB.Value(0.5);
216 // Construction du Geom_Plane
217 GC_MakePlane MkPlane(A,B,C);
218 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
220 // Construction de l'AIS_PlaneTrihedron
221 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
223 // Fermeture du contexte local.
224 TheAISContext()->CloseLocalContext(myCurrentIndex);
226 // on le display & bind
227 TheAISContext()->Display(theAISPlaneTri );
228 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
235 //==============================================================================
236 //function : VTriherdron
237 //purpose : Create a trihedron. If no arguments are set, the default
238 // trihedron (Oxyz) is created.
239 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
240 //==============================================================================
242 static int VTrihedron (Draw_Interpretor& theDi,
243 Standard_Integer theArgsNb,
244 const char** theArgVec)
246 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
248 theDi << theArgVec[0] << " Syntax error\n";
252 gp_Pnt anOrigin (0.0, 0.0, 0.0);
253 gp_Dir aDirZ = gp::DZ();
254 gp_Dir aDirX = gp::DX();
255 Standard_Integer anArgIter = 2; // 1st is an IO name
256 if (anArgIter < theArgsNb)
258 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
259 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
260 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
261 if (anArgIter < theArgsNb)
263 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
264 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
265 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
266 aDirZ.SetCoord (aX, aY, aZ);
268 aX = Draw::Atof (theArgVec[anArgIter++]);
269 aY = Draw::Atof (theArgVec[anArgIter++]);
270 aZ = Draw::Atof (theArgVec[anArgIter++]);
271 aDirX.SetCoord (aX, aY, aZ);
275 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
277 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
281 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
282 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
283 VDisplayAISObject (theArgVec[1], aShape);
287 //==============================================================================
290 //purpose : Change the size of a named or selected trihedron
291 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
292 // if no value, the value is set at 100 by default
293 //Draw arg : vsize [name] [size]
294 //==============================================================================
296 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
299 // Declaration de booleens
300 Standard_Boolean ThereIsName;
301 Standard_Boolean ThereIsCurrent;
303 Standard_Boolean hascol;
305 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
307 // Verification des arguments
308 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
310 // Verification du nombre d'arguments
311 if (argc==1) {ThereIsName=Standard_False;value=100;}
312 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
313 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
315 // On ferme le contexte local pour travailler dans le contexte global
316 if(TheAISContext()->HasOpenedContext())
317 TheAISContext()->CloseLocalContext();
319 // On set le booleen ThereIsCurrent
320 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
321 else {ThereIsCurrent=Standard_False;}
325 //===============================================================
326 // Il n'y a pas de nom mais des objets selectionnes
327 //===============================================================
328 if (!ThereIsName && ThereIsCurrent)
331 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
334 while ( it.More() ) {
336 Handle(AIS_InteractiveObject) aShape=
337 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
339 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
342 // On verifie que l'AIS InteraciveObject selectionne est bien
344 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
346 if (aShape->HasColor()) {
347 hascol=Standard_True;
349 // On recupere la couleur de aShape
350 col=aShape->Color();}
352 else hascol=Standard_False;
354 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
355 // pour lui appliquer la methode SetSize()
356 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
358 // C'est bien un triedre,on chage sa valeur!
359 aTrihedron->SetSize(value);
361 // On donne la couleur au Trihedron
362 if(hascol) aTrihedron->SetColor(col);
363 else aTrihedron->UnsetColor();
366 // The trihedron hasn't be errased from the map
367 // so you just have to redisplay it
368 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
377 TheAISContext() ->UpdateCurrentViewer();
380 //===============================================================
381 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
382 //===============================================================
386 //===============================================================
387 // Il y a un nom de triedre passe en argument
388 //===============================================================
390 TCollection_AsciiString name=argv[1];
392 // on verifie que ce nom correspond bien a une shape
393 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
397 // on recupere la shape dans la map des objets displayes
398 Handle(AIS_InteractiveObject) aShape =
399 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
401 // On verifie que l'AIS InteraciveObject est bien
403 if (!aShape.IsNull() &&
404 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
407 if (aShape->HasColor()) {
408 hascol=Standard_True;
410 // On recupere la couleur de aShape
411 col=aShape->Color();}
413 else hascol=Standard_False;
415 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
416 // pour lui appliquer la methode SetSize()
417 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
419 // C'est bien un triedre,on chage sa valeur
420 aTrihedron->SetSize(value);
422 // On donne la couleur au Trihedron
423 if(hascol) aTrihedron->SetColor(col);
424 else aTrihedron->UnsetColor();
426 // The trihedron hasn't be errased from the map
427 // so you just have to redisplay it
428 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
430 TheAISContext() ->UpdateCurrentViewer();
438 //==============================================================================
440 //==============================================================================
441 //function : VPlaneTrihedron
442 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
443 //Draw arg : vplanetri name
444 //==============================================================================
445 #include <AIS_Plane.hxx>
449 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
452 // Verification des arguments
453 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
456 Standard_Integer myCurrentIndex;
457 // Fermeture des contextes locaux
458 TheAISContext()->CloseAllContexts();
460 // On recupere tous les trihedrons de la GetMapOfAIS()
461 // et on active le mode de selection par face.
462 // =================================================
464 // Ouverture d'un contexte local et recuperation de son index.
465 TheAISContext()->OpenLocalContext(Standard_False);
466 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
468 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
471 Handle(AIS_InteractiveObject) ShapeA =
472 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
473 // On verifie que c'est bien un trihedron
474 if (!ShapeA.IsNull() &&
475 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
477 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
478 // on le charge dans le contexte et on active le mode Plane.
479 TheAISContext()->Load(TrihedronA,0,Standard_False);
480 TheAISContext()->Activate(TrihedronA,3);
485 di<<" Select a plane."<<"\n";
486 // Boucle d'attente waitpick.
487 Standard_Integer argccc = 5;
488 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
489 const char **argvvv = (const char **) bufff;
490 while (ViewerMainLoop( argccc, argvvv) ) { }
493 Handle(AIS_InteractiveObject) theIOB;
494 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
495 theIOB = TheAISContext()->Interactive();
498 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
500 // Fermeture du contexte local.
501 TheAISContext()->CloseLocalContext(myCurrentIndex);
503 // on le display & bind
504 TheAISContext()->Display(PlaneB );
505 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
512 //==============================================================================
513 // Fonction First click 2de click
515 // vaxis vertex vertex
517 // vaxispara edge vertex
518 // vaxisortho edge Vertex
519 // vaxisinter Face Face
520 //==============================================================================
522 //==============================================================================
523 //function : VAxisBuilder
525 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
526 //==============================================================================
527 #include <TopoDS_Edge.hxx>
528 #include <TopoDS_Vertex.hxx>
529 #include <TopExp.hxx>
530 #include <Geom_Line.hxx>
532 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
535 Standard_Boolean HasArg;
536 TCollection_AsciiString name;
537 Standard_Integer MyCurrentIndex;
540 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
541 if (argc==8) HasArg=Standard_True;
542 else HasArg=Standard_False;
545 // Fermeture des contextes
546 TheAISContext()->CloseAllContexts();
548 // Cas ou il y a des arguments
549 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
551 Standard_Real coord[6];
552 for(Standard_Integer i=0;i<=5;i++){
553 coord[i]=Draw::Atof(argv[2+i]);
555 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
557 gp_Vec myVect (p1,p2);
558 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
559 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
560 GetMapOfAIS().Bind (TheAxis,name);
561 TheAISContext()->Display(TheAxis);
567 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
568 if ( !strcasecmp(argv[0], "vaxis")) {
569 TheAISContext()->OpenLocalContext();
570 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
572 // Active le mode edge et le mode vertex
573 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
574 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
575 di<<" Select an edge or a vertex."<<"\n";
577 // Boucle d'attente waitpick.
578 Standard_Integer argcc = 5;
579 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
580 const char **argvv = (const char **) buff;
581 while (ViewerMainLoop( argcc, argvv) ) { }
584 // recuperation de la shape.
586 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
587 ShapeA = TheAISContext()->SelectedShape();
589 // recuperation de l'AIS_InteractiveObject
590 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
591 // down cast en AIS_Point si sig et type
592 // AIS_Point -> Geom_Pnt ....
594 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
595 // on desactive le mode edge
596 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
597 di<<" Select a different vertex."<<"\n";
601 // Boucle d'attente waitpick.
602 Standard_Integer argccc = 5;
603 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
604 const char **argvvv = (const char **) bufff;
605 while (ViewerMainLoop( argccc, argvvv) ) { }
607 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
608 ShapeB = TheAISContext()->SelectedShape();
612 } while(ShapeB.IsSame(ShapeA) );
614 // Fermeture du context local
615 TheAISContext()->CloseLocalContext(MyCurrentIndex);
617 // Construction de l'axe
618 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
619 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
622 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
623 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
624 GetMapOfAIS().Bind (TheAxis,name);
625 TheAISContext()->Display(TheAxis);
628 // Un unique edge (ShapeA) a ete picke
629 // Fermeture du context local
630 TheAISContext()->CloseLocalContext(MyCurrentIndex);
631 // Constuction de l'axe
632 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
634 TopExp::Vertices(ed,Va,Vb );
635 gp_Pnt A=BRep_Tool::Pnt(Va);
636 gp_Pnt B=BRep_Tool::Pnt(Vb);
639 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
640 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
641 GetMapOfAIS().Bind (TheAxis,name);
642 TheAISContext()->Display(TheAxis);
648 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
649 else if ( !strcasecmp(argv[0], "vaxispara")) {
651 TheAISContext()->OpenLocalContext();
652 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
654 // Active le mode edge
655 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
656 di<<" Select an edge."<<"\n";
658 // Boucle d'attente waitpick.
659 Standard_Integer argcc = 5;
660 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
661 const char **argvv = (const char **) buff;
662 while (ViewerMainLoop( argcc, argvv) ) { }
666 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
667 ShapeA = TheAISContext()->SelectedShape();
669 // Active le mode vertex et deactive edges
670 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
671 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
672 di<<" Select a vertex."<<"\n";
674 // Boucle d'attente waitpick.
675 Standard_Integer argccc = 5;
676 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
677 const char **argvvv = (const char **) bufff;
678 while (ViewerMainLoop( argccc, argvvv) ) { }
681 // On peut choisir un pnt sur l'edge
683 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
684 ShapeB = TheAISContext()->SelectedShape();
686 // Fermeture du context local
687 TheAISContext()->CloseLocalContext(MyCurrentIndex);
689 // Construction de l'axe
690 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
691 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
693 TopExp::Vertices(ed,Va,Vc );
694 gp_Pnt A=BRep_Tool::Pnt(Va);
695 gp_Pnt C=BRep_Tool::Pnt(Vc);
698 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
699 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
700 GetMapOfAIS().Bind (TheAxis,name);
701 TheAISContext()->Display(TheAxis);
705 // Fonction axisortho
707 TheAISContext()->OpenLocalContext();
708 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
710 // Active le mode edge
711 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
712 di<<" Select an edge."<<"\n";
714 // Boucle d'attente waitpick.
715 Standard_Integer argcc = 5;
716 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
717 const char **argvv = (const char **) buff;
718 while (ViewerMainLoop( argcc, argvv) ) { }
722 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
723 ShapeA = TheAISContext()->SelectedShape();
725 // Active le mode vertex et deactive edges
726 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
727 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
728 di<<" Slect a vertex."<<"\n";
730 // Boucle d'attente waitpick.
731 Standard_Integer argccc = 5;
732 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
733 const char **argvvv = (const char **) bufff;
734 while (ViewerMainLoop( argccc, argvvv) ) { }
737 // On peut choisir un pnt sur l'edge
739 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
740 ShapeB = TheAISContext()->SelectedShape();
742 // Fermeture du context local
743 TheAISContext()->CloseLocalContext(MyCurrentIndex);
745 // Construction de l'axe
746 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
747 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
749 TopExp::Vertices(ed,Va,Vc );
750 gp_Pnt A=BRep_Tool::Pnt(Va);
751 gp_Pnt C=BRep_Tool::Pnt(Vc);
752 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
755 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
756 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
757 GetMapOfAIS().Bind (TheAxis,name);
758 TheAISContext()->Display(TheAxis);
767 //==============================================================================
768 // Fonction First click Result
770 // vpoint vertex AIS_Point=Vertex
771 // edge AIS_Point=Middle of the edge
772 //==============================================================================
774 //==============================================================================
775 //function : VPointBuilder
776 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
777 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
778 //==============================================================================
779 #include <TopoDS_Edge.hxx>
780 #include <TopoDS_Vertex.hxx>
781 #include <TopExp.hxx>
782 #include <AIS_Point.hxx>
783 #include <Geom_CartesianPoint.hxx>
785 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
788 Standard_Boolean HasArg;
789 TCollection_AsciiString name;
790 Standard_Integer myCurrentIndex;
793 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
794 if (argc==5) HasArg=Standard_True;
795 else HasArg=Standard_False;
798 // Fermeture des contextes
799 TheAISContext()->CloseAllContexts();
801 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
803 Standard_Real thecoord[3];
804 for(Standard_Integer i=0;i<=2;i++)
805 thecoord[i]=Draw::Atof(argv[2+i]);
806 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
807 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
808 GetMapOfAIS().Bind (myAISPoint,name);
809 TheAISContext()->Display(myAISPoint);
812 // Il n'a pas d'arguments
814 TheAISContext()->OpenLocalContext();
815 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
817 // Active le mode Vertex et Edges
818 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
819 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
820 di<<" Select a vertex or an edge(build the middle)"<<"\n";
822 // Boucle d'attente waitpick.
823 Standard_Integer argcc = 5;
824 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
825 const char **argvv = (const char **) buff;
826 while (ViewerMainLoop( argcc, argvv) ) { }
830 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
831 ShapeA= TheAISContext()->SelectedShape();
834 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
835 // Un vertex a ete selectionne
836 // Fermeture du context local
837 TheAISContext()->CloseLocalContext(myCurrentIndex);
839 // Construction du point
840 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
841 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
842 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
843 GetMapOfAIS().Bind(myAISPoint,name);
844 TheAISContext()->Display(myAISPoint);
847 // Un Edge a ete selectionne
848 // Fermeture du context local
849 TheAISContext()->CloseLocalContext(myCurrentIndex);
851 // Construction du point milieu de l'edge
852 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
853 TopoDS_Vertex myVertexA,myVertexB;
854 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
855 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
856 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
857 // M est le milieu de [AB]
858 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
859 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
860 GetMapOfAIS().Bind(myAISPointM,name);
861 TheAISContext()->Display(myAISPointM);
869 //==============================================================================
870 // Function 1st click 2de click 3de click
871 // vplane Vertex Vertex Vertex
875 // vplanepara Face Vertex
877 // vplaneortho Face Edge
879 //==============================================================================
881 //==============================================================================
882 //function : VPlaneBuilder
883 //purpose : Build an AIS_Plane from selected entities or Named AIS components
884 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
885 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
886 // [PlaneName] [PointName] [TypeOfSensitivity]
887 //==============================================================================
889 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
890 Standard_Integer argc,
894 Standard_Boolean hasArg;
895 TCollection_AsciiString aName;
896 Standard_Integer aCurrentIndex;
899 if (argc<2 || argc>6 )
901 std::cout<<" Syntax error\n";
904 if (argc == 6 || argc==5 || argc==4)
905 hasArg=Standard_True;
907 hasArg=Standard_False;
910 // Close all contexts
911 TheAISContext()->CloseAllContexts();
913 // There are some arguments
916 if (!GetMapOfAIS().IsBound2(argv[2] ))
918 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
921 // Get shape from map
922 Handle(AIS_InteractiveObject) aShapeA =
923 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
925 // The first argument is an AIS_Point
926 if (!aShapeA.IsNull() &&
927 aShapeA->Type()==AIS_KOI_Datum &&
928 aShapeA->Signature()==1)
930 // The second argument must also be an AIS_Point
931 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
933 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
936 // Get shape from map
937 Handle(AIS_InteractiveObject) aShapeB =
938 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
939 // If B is not an AIS_Point
940 if (aShapeB.IsNull() ||
941 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
943 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
946 // The third object is an AIS_Point
947 if (!GetMapOfAIS().IsBound2(argv[4]) )
949 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
952 // Get shape from map
953 Handle(AIS_InteractiveObject) aShapeC =
954 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
955 // If C is not an AIS_Point
956 if (aShapeC.IsNull() ||
957 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
959 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
963 // Treatment of objects A, B, C
964 // Downcast an AIS_IO to AIS_Point
965 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
966 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
967 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
969 Handle(Geom_CartesianPoint ) aCartPointA =
970 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
972 Handle(Geom_CartesianPoint ) aCartPointB =
973 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
975 Handle(Geom_CartesianPoint ) aCartPointC =
976 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
978 // Verification that the three points are different
979 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
980 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
981 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
984 std::cout<<"vplane error: same points"<<"\n";return 1;
986 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
987 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
988 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
991 std::cout<<"vplane error: same points"<<"\n";return 1;
993 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
994 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
995 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
998 std::cout<<"vplane error: same points"<<"\n";return 1;
1001 gp_Pnt A = aCartPointA->Pnt();
1002 gp_Pnt B = aCartPointB->Pnt();
1003 gp_Pnt C = aCartPointC->Pnt();
1005 // Construction of AIS_Plane
1006 GC_MakePlane MkPlane (A,B,C);
1007 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1008 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1009 GetMapOfAIS().Bind (anAISPlane,aName );
1012 Standard_Integer aType = Draw::Atoi (argv[5]);
1013 if (aType != 0 && aType != 1)
1015 std::cout << "vplane error: wrong type of sensitivity!\n"
1016 << "Should be one of the following values:\n"
1024 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1027 TheAISContext()->Display(anAISPlane);
1030 // The first argument is an AIS_Axis
1031 // Creation of a plane orthogonal to the axis through a point
1032 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1033 // The second argument should be an AIS_Point
1034 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1036 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1039 // Get shape from map
1040 Handle(AIS_InteractiveObject) aShapeB =
1041 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1042 // If B is not an AIS_Point
1043 if (aShapeB.IsNull() ||
1044 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1046 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1050 // Treatment of objects A and B
1051 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1052 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1054 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1055 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1057 gp_Ax1 anAxis = aGeomLineA->Position();
1058 Handle(Geom_CartesianPoint) aCartPointB =
1059 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1061 gp_Dir D =anAxis.Direction();
1062 gp_Pnt B = aCartPointB->Pnt();
1064 // Construction of AIS_Plane
1065 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1066 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1067 GetMapOfAIS().Bind (anAISPlane,aName );
1070 Standard_Integer aType = Draw::Atoi (argv[4]);
1071 if (aType != 0 && aType != 1)
1073 std::cout << "vplane error: wrong type of sensitivity!\n"
1074 << "Should be one of the following values:\n"
1082 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1085 TheAISContext()->Display(anAISPlane);
1088 // The first argumnet is an AIS_Plane
1089 // Creation of a plane parallel to the plane passing through the point
1090 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1092 // The second argument should be an AIS_Point
1093 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1095 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1098 // Get shape from map
1099 Handle(AIS_InteractiveObject) aShapeB =
1100 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1101 // B should be an AIS_Point
1102 if (aShapeB.IsNull() ||
1103 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1105 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1109 // Treatment of objects A and B
1110 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1111 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1113 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1114 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1116 Handle(Geom_CartesianPoint) aCartPointB =
1117 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1118 gp_Pnt B= aCartPointB->Pnt();
1120 // Construction of an AIS_Plane
1121 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1122 GetMapOfAIS().Bind (anAISPlane, aName);
1125 Standard_Integer aType = Draw::Atoi (argv[4]);
1126 if (aType != 0 && aType != 1)
1128 std::cout << "vplane error: wrong type of sensitivity!\n"
1129 << "Should be one of the following values:\n"
1137 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1140 TheAISContext()->Display(anAISPlane);
1145 std::cout<<"vplane: error 1st object is not an AIS\n";
1149 // There are no arguments
1153 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1154 if (!strcasecmp(argv[0], "vplane"))
1156 TheAISContext()->OpenLocalContext();
1157 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1159 // Active modes Vertex, Edge and Face
1160 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1163 std::cout<<"Select a vertex, a face or an edge\n";
1166 Standard_Integer argcc = 5;
1167 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1168 const char **argvv = (const char **) buff;
1169 while (ViewerMainLoop( argcc, argvv) ) { }
1172 TopoDS_Shape aShapeA;
1173 for (TheAISContext()->InitSelected();
1174 TheAISContext()->MoreSelected();
1175 TheAISContext()->NextSelected())
1177 aShapeA = TheAISContext()->SelectedShape();
1180 // aShapeA is a Vertex
1181 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1183 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1184 std::cout<<" Select an edge or a different vertex\n";
1187 Standard_Integer argccc = 5;
1188 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1189 const char **argvvv = (const char **) bufff;
1190 while (ViewerMainLoop( argccc, argvvv) ) { }
1193 TopoDS_Shape aShapeB;
1194 for (TheAISContext()->InitSelected();
1195 TheAISContext()->MoreSelected();
1196 TheAISContext()->NextSelected())
1198 aShapeB = TheAISContext()->SelectedShape();
1200 // aShapeB is a Vertex
1201 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1203 // A and B are the same
1204 if (aShapeB.IsSame(aShapeA))
1206 std::cout<<" vplane: error, same points selected\n";
1209 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1210 std::cout<<" Select a different vertex\n";
1213 Standard_Integer argcccc = 5;
1214 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1215 const char **argvvvv = (const char **) buffff;
1216 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1219 TopoDS_Shape aShapeC;
1220 for (TheAISContext()->InitSelected();
1221 TheAISContext()->MoreSelected();
1222 TheAISContext()->NextSelected())
1224 aShapeC = TheAISContext()->SelectedShape();
1226 // aShapeC is the same as A or B
1227 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1229 std::cout<<" vplane: error, same points selected\n";
1233 // Close the local context
1234 TheAISContext()->CloseLocalContext(aCurrentIndex);
1236 // Construction of plane
1237 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1238 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1239 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1240 GC_MakePlane MkPlane(A, B, C);
1241 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1242 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1243 GetMapOfAIS().Bind (anAISPlane, aName);
1244 TheAISContext()->Display(anAISPlane);
1246 // ShapeB is an edge
1249 // Verify that the vertex is not on the edge ShapeB
1250 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1251 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1253 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1254 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1256 // The vertex is on the edge
1257 std::cout<<" vplane: error point is on the edge\n";
1262 // Close the local context
1263 TheAISContext()->CloseLocalContext(aCurrentIndex);
1264 // Construction of plane
1265 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1266 TopoDS_Vertex aVBa, aVBb;
1267 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1268 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1269 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1270 GC_MakePlane MkPlane (A, aBa, aBb);
1271 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1272 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1273 GetMapOfAIS().Bind (anAISPlane, aName);
1274 TheAISContext()->Display(anAISPlane);
1278 // aShapeA is an edge
1279 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1281 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1282 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1283 std::cout<<" Select a vertex that don't belong to the edge\n";
1286 Standard_Integer argccc = 5;
1287 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1288 const char **argvvv = (const char **) bufff;
1289 while (ViewerMainLoop( argccc, argvvv) ) { }
1292 TopoDS_Shape aShapeB;
1293 for (TheAISContext()->InitSelected();
1294 TheAISContext()->MoreSelected();
1295 TheAISContext()->NextSelected())
1297 aShapeB = TheAISContext()->SelectedShape();
1299 // aShapeB should be a Vertex
1300 // Check that the vertex aShapeB is not on the edge
1301 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1302 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1304 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1305 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1307 // The vertex is on the edge
1308 std::cout<<" vplane: error point is on the edge\n";
1313 // Close the local context
1314 TheAISContext()->CloseLocalContext(aCurrentIndex);
1315 // Construction of plane
1316 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1317 TopoDS_Vertex aVAa, aVAb;
1318 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1319 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1320 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1321 GC_MakePlane MkPlane (B,Aa,Ab);
1322 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1323 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1324 GetMapOfAIS().Bind (anAISPlane ,aName);
1325 TheAISContext()->Display(anAISPlane);
1328 // aShapeA is a Face
1331 // Close the local context: nothing to select
1332 TheAISContext()->CloseLocalContext(aCurrentIndex);
1333 // Construction of plane
1334 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1335 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1336 if (aSurface.GetType()==GeomAbs_Plane)
1338 gp_Pln aPlane = aSurface.Plane();
1339 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1340 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1341 GetMapOfAIS().Bind (anAISPlane, aName);
1342 TheAISContext()->Display(anAISPlane);
1346 std::cout<<" vplane: error\n";
1352 // Function vPlanePara
1353 // ===================
1354 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1355 else if (!strcasecmp(argv[0], "vplanepara"))
1357 TheAISContext()->OpenLocalContext();
1358 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1360 // Activate modes Vertex and Face
1361 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1362 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1363 std::cout<<" Select a vertex or a face\n";
1366 Standard_Integer argcc = 5;
1367 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1368 const char **argvv = (const char **) buff;
1369 while (ViewerMainLoop( argcc, argvv) ) { }
1372 TopoDS_Shape aShapeA;
1373 for (TheAISContext()->InitSelected();
1374 TheAISContext()->MoreSelected();
1375 TheAISContext()->NextSelected())
1377 aShapeA = TheAISContext()->SelectedShape();
1380 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1382 // aShapeA is a vertex
1383 // Deactivate the mode Vertex
1384 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1385 std::cout<<" Select a face\n";
1388 Standard_Integer argccc = 5;
1389 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1390 const char **argvvv = (const char **) bufff;
1391 while (ViewerMainLoop( argccc, argvvv) ) { }
1394 TopoDS_Shape aShapeB;
1395 for (TheAISContext()->InitSelected();
1396 TheAISContext()->MoreSelected();
1397 TheAISContext()->NextSelected())
1399 // A vertex ShapeA can be on Face ShapeB
1400 aShapeB = TheAISContext()->SelectedShape();
1403 // Close the local context
1404 TheAISContext()->CloseLocalContext(aCurrentIndex);
1406 // Construction of plane
1407 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1409 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1410 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1411 if (aSurface.GetType()==GeomAbs_Plane )
1413 gp_Pln aPlane = aSurface.Plane();
1414 // Construct a plane parallel to aGeomPlane through A
1415 aPlane.SetLocation(A);
1416 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1417 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1418 GetMapOfAIS().Bind (aAISPlane ,aName);
1419 TheAISContext()->Display(aAISPlane);
1423 std::cout<<" vplanepara: error\n";
1430 // Deactive the mode Face
1431 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1432 std::cout<<" Select a vertex\n";
1435 Standard_Integer argccc = 5;
1436 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1437 const char **argvvv = (const char **) bufff;
1438 while (ViewerMainLoop( argccc, argvvv) ) { }
1441 TopoDS_Shape aShapeB;
1442 for (TheAISContext()->InitSelected();
1443 TheAISContext()->MoreSelected();
1444 TheAISContext()->NextSelected())
1446 // A vertex ShapeB can be on Face ShapeA
1447 aShapeB = TheAISContext()->SelectedShape();
1449 // Close the local context
1450 TheAISContext()->CloseLocalContext(aCurrentIndex);
1452 // Construction of plane
1453 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1455 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1456 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1457 if (aSurface.GetType()==GeomAbs_Plane )
1459 gp_Pln aPlane = aSurface.Plane();
1460 aPlane.SetLocation(B);
1461 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1462 // Construct a plane parallel to aGeomPlane through B
1463 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1464 GetMapOfAIS().Bind (anAISPlane, aName);
1465 TheAISContext()->Display(anAISPlane);
1469 std::cout<<" vplanepara: error"<<"\n";return 1;
1474 // Function vplaneortho
1475 // ====================
1476 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1479 TheAISContext()->OpenLocalContext();
1480 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1482 // Activate the modes Edge and Face
1483 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1484 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1485 std::cout<<" Select a face and an edge coplanar\n";
1488 Standard_Integer argcc = 5;
1489 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1490 const char **argvv = (const char **) buff;
1491 while (ViewerMainLoop( argcc, argvv) ) { }
1494 TopoDS_Shape aShapeA;
1495 for (TheAISContext()->InitSelected();
1496 TheAISContext()->MoreSelected();
1497 TheAISContext()->NextSelected())
1499 aShapeA = TheAISContext()->SelectedShape();
1502 if (aShapeA.ShapeType()==TopAbs_EDGE )
1504 // ShapeA is an edge, deactivate the mode Edge...
1505 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1506 std::cout<<" Select a face\n";
1509 Standard_Integer argccc = 5;
1510 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1511 const char **argvvv = (const char **) bufff;
1512 while (ViewerMainLoop( argccc, argvvv) ) { }
1515 TopoDS_Shape aShapeB;
1516 for (TheAISContext()->InitSelected();
1517 TheAISContext()->MoreSelected();
1518 TheAISContext()->NextSelected())
1520 // Edge ShapeA can be on Face ShapeB
1521 aShapeB = TheAISContext()->SelectedShape();
1524 // Close the local context
1525 TheAISContext()->CloseLocalContext(aCurrentIndex);
1527 // Construction of plane
1528 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1529 TopoDS_Vertex aVAa, aVAb;
1530 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1531 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1532 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1536 // Creation of rotation axis
1537 gp_Ax1 aRotAxis (Aa,Dab);
1539 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1540 // The edge must be parallel to the face
1541 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1542 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1543 // Compare to heights
1544 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1545 >Precision::Confusion())
1547 // the edge is not parallel to the face
1548 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1552 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1553 if (aSurface.GetType()==GeomAbs_Plane)
1555 gp_Pln aPlane = aSurface.Plane();
1556 // It rotates a half turn round the axis of rotation
1557 aPlane.Rotate(aRotAxis , M_PI/2);
1559 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1560 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1561 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1562 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1563 GetMapOfAIS().Bind (anAISPlane, aName);
1564 TheAISContext()->Display(anAISPlane);
1568 std::cout<<" vplaneortho: error\n";
1574 // ShapeA is a Face, deactive the mode Face.
1575 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1576 std::cout<<" Select an edge\n";
1579 Standard_Integer argccc = 5;
1580 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1581 const char **argvvv = (const char **) bufff;
1582 while (ViewerMainLoop( argccc, argvvv) ) { }
1585 TopoDS_Shape aShapeB;
1586 for (TheAISContext()->InitSelected();
1587 TheAISContext()->MoreSelected();
1588 TheAISContext()->NextSelected())
1590 // Edge ShapeB can be on Face ShapeA
1591 aShapeB = TheAISContext()->SelectedShape();
1593 // Close the local context
1594 TheAISContext()->CloseLocalContext(aCurrentIndex);
1596 // Construction of plane
1597 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1598 TopoDS_Vertex aVBa, aVBb;
1599 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1600 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1601 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1602 gp_Vec ab (aBa,aBb);
1604 // Creation of rotation axe
1605 gp_Ax1 aRotAxis (aBa,Dab);
1607 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1608 // The edge must be parallel to the face
1609 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1610 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1611 // Comparing the two heights
1612 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1613 >Precision::Confusion())
1615 // the edge is not parallel to the face
1616 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1620 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1621 if (aSurface.GetType()==GeomAbs_Plane)
1623 gp_Pln aPlane = aSurface.Plane();
1624 // It rotates a half turn round the axis of rotation
1625 aPlane.Rotate(aRotAxis , M_PI/2);
1626 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1627 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1628 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1629 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1630 GetMapOfAIS().Bind (anAISPlane ,aName);
1631 TheAISContext()->Display(anAISPlane);
1635 std::cout<<" vplaneortho: error\n";
1644 //===============================================================================================
1645 //function : VChangePlane
1647 //===============================================================================================
1648 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1650 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1651 if (aContextAIS.IsNull())
1653 std::cout << theArgVec[0] << "AIS context is not available.\n";
1657 if (theArgsNb < 3 || theArgsNb > 11)
1659 std::cerr << theArgVec[0]
1660 << ": incorrect number of command arguments.\n"
1661 << "Type help for more information.\n";
1665 TCollection_AsciiString aName (theArgVec[1]);
1667 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1668 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1671 if ( aPlane.IsNull() )
1673 std::cout << theArgVec[0]
1674 << ": there is no interactive plane with the given name."
1675 << "Type help for more information.\n";
1679 Standard_Real aCenterX = aPlane->Center().X();
1680 Standard_Real aCenterY = aPlane->Center().Y();
1681 Standard_Real aCenterZ = aPlane->Center().Z();
1683 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1684 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1685 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1687 Standard_Real aSizeX = 0.0;
1688 Standard_Real aSizeY = 0.0;
1689 aPlane->Size (aSizeX, aSizeY);
1690 Standard_Boolean isUpdate = Standard_True;
1692 TCollection_AsciiString aPName, aPValue;
1693 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1695 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1696 TCollection_AsciiString anArgCase = anArg;
1697 anArgCase.UpperCase();
1698 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1701 if (aPName.IsEqual ("X"))
1703 aCenterX = aPValue.RealValue();
1705 else if (aPName.IsEqual ("Y"))
1707 aCenterY = aPValue.RealValue();
1709 else if (aPName.IsEqual ("Z"))
1711 aCenterZ = aPValue.RealValue();
1713 else if (aPName.IsEqual ("DX"))
1715 aDirX = aPValue.RealValue();
1717 else if (aPName.IsEqual ("DY"))
1719 aDirY = aPValue.RealValue();
1721 else if (aPName.IsEqual ("DZ"))
1723 aDirZ = aPValue.RealValue();
1725 else if (aPName.IsEqual ("SX"))
1727 aSizeX = aPValue.RealValue();
1729 else if (aPName.IsEqual ("SY"))
1731 aSizeY = aPValue.RealValue();
1734 else if (anArg.IsEqual ("NOUPDATE"))
1736 isUpdate = Standard_False;
1740 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1741 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1742 aPlane->SetCenter (aCenterPnt);
1743 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1744 aPlane->SetSize (aSizeX, aSizeY);
1748 aContextAIS->Update (aPlane, Standard_True);
1754 //==============================================================================
1756 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1757 //==============================================================================
1759 //==============================================================================
1760 //function : VLineBuilder
1761 //purpose : Build an AIS_Line
1762 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1763 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1764 //==============================================================================
1765 #include <Geom_CartesianPoint.hxx>
1766 #include <AIS_Line.hxx>
1769 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1771 Standard_Integer myCurrentIndex;
1773 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1774 // Fermeture des contextes
1775 TheAISContext()->CloseAllContexts();
1777 // On recupere les parametres
1778 Handle(AIS_InteractiveObject) theShapeA;
1779 Handle(AIS_InteractiveObject) theShapeB;
1781 // Parametres: AIS_Point AIS_Point
1782 // ===============================
1785 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1786 // On verifie que c'est bien une AIS_Point
1787 if (!theShapeA.IsNull() &&
1788 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1789 // on recupere le deuxieme AIS_Point
1791 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1792 if (theShapeA.IsNull() ||
1793 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1795 di <<"vline error: wrong type of 2de argument."<<"\n";
1799 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1800 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1801 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1802 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1804 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1805 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1806 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1808 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1809 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1810 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1812 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1814 di<<"vline error: same points"<<"\n";return 1;
1816 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1817 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1818 GetMapOfAIS().Bind(theAISLine,argv[1] );
1819 TheAISContext()->Display(theAISLine );
1823 // Parametres 6 Reals
1824 // ==================
1827 // On verifie que les deux points ne sont pas confondus
1829 Standard_Real coord[6];
1830 for(Standard_Integer i=0;i<=2;i++){
1831 coord[i]=Draw::Atof(argv[2+i]);
1832 coord[i+3]=Draw::Atof(argv[5+i]);
1835 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1836 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1838 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1839 GetMapOfAIS().Bind(theAISLine,argv[1] );
1840 TheAISContext()->Display(theAISLine );
1844 // Pas de parametres: Selection dans le viewer.
1845 // ============================================
1848 TheAISContext()->OpenLocalContext();
1849 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1851 // Active le mode Vertex.
1852 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1853 di<<" Select a vertex "<<"\n";
1855 // Boucle d'attente waitpick.
1856 Standard_Integer argcc = 5;
1857 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1858 const char **argvv = (const char **) buff;
1859 while (ViewerMainLoop( argcc, argvv) ) { }
1862 TopoDS_Shape ShapeA;
1863 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1864 ShapeA = TheAISContext()->SelectedShape();
1867 // ShapeA est un Vertex
1868 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1870 di<<" Select a different vertex."<<"\n";
1872 TopoDS_Shape ShapeB;
1875 // Boucle d'attente waitpick.
1876 Standard_Integer argccc = 5;
1877 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1878 const char **argvvv = (const char **) bufff;
1879 while (ViewerMainLoop( argccc, argvvv) ) { }
1882 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1883 ShapeB = TheAISContext()->SelectedShape();
1887 } while(ShapeB.IsSame(ShapeA) );
1889 // Fermeture du context local
1890 TheAISContext()->CloseLocalContext(myCurrentIndex);
1892 // Construction de la line
1893 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1894 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1896 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1897 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1899 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1900 GetMapOfAIS().Bind(theAISLine,argv[1] );
1901 TheAISContext()->Display(theAISLine );
1905 di<<"vline error."<<"\n";
1913 //==============================================================================
1914 // class : FilledCircle
1915 // purpose : creates filled circle based on AIS_InteractiveObject
1917 // This class is used to check method Matches() of class
1918 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1919 // because none of AIS classes provides creation of
1920 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1921 // (look method ComputeSelection() )
1922 //==============================================================================
1924 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1926 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1927 gp_Circ aCirc(anAxes, theRadius);
1928 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1932 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1934 class FilledCircle : public AIS_InteractiveObject
1938 DEFINE_STANDARD_RTTI(FilledCircle);
1940 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1941 FilledCircle(Handle(Geom_Circle) theCircle);
1944 TopoDS_Face ComputeFace();
1946 // Virtual methods implementation
1947 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1948 const Handle(Prs3d_Presentation)& thePresentation,
1949 const Standard_Integer theMode);
1951 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1952 const Standard_Integer theMode);
1955 Handle(Geom_Circle) myCircle;
1956 Standard_Boolean myFilledStatus;
1960 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1961 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1963 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1965 myCircle = CreateCircle(theCenter, theRadius);
1966 myFilledStatus = Standard_True;
1969 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1971 myCircle = theCircle;
1972 myFilledStatus = Standard_True;
1975 TopoDS_Face FilledCircle::ComputeFace()
1977 // Create edge from myCircle
1978 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1979 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1981 // Create wire from anEdge
1982 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1983 TopoDS_Wire aWire = aWireMaker.Wire();
1985 // Create face from aWire
1986 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1987 TopoDS_Face aFace = aFaceMaker.Face();
1992 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1993 const Handle(Prs3d_Presentation) &thePresentation,
1994 const Standard_Integer theMode)
1996 thePresentation->Clear();
1998 TopoDS_Face aFace = ComputeFace();
2000 if (aFace.IsNull()) return;
2001 if (theMode != 0) return;
2003 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2006 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2007 const Standard_Integer /*theMode*/)
2009 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2010 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2011 myCircle, myFilledStatus);
2012 theSelection->Add(aSensitiveCircle);
2015 //==============================================================================
2017 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2018 //==============================================================================
2020 //==============================================================================
2021 //function : VCircleBuilder
2022 //purpose : Build an AIS_Circle
2023 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2024 // PointName PointName PointName IsFilled
2025 //==============================================================================
2027 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2028 TCollection_AsciiString theName,
2029 Standard_Boolean isFilled)
2031 Handle(AIS_InteractiveObject) aCircle;
2034 aCircle = new FilledCircle(theGeomCircle);
2038 aCircle = new AIS_Circle(theGeomCircle);
2039 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2042 // Check if there is an object with given name
2043 // and remove it from context
2044 if (GetMapOfAIS().IsBound2(theName))
2046 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2047 Handle(AIS_InteractiveObject) anInterObj =
2048 Handle(AIS_InteractiveObject)::DownCast(anObj);
2049 TheAISContext()->Remove(anInterObj, Standard_False);
2050 GetMapOfAIS().UnBind2(theName);
2053 // Bind the circle to its name
2054 GetMapOfAIS().Bind(aCircle, theName);
2056 // Display the circle
2057 TheAISContext()->Display(aCircle);
2061 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2063 Standard_Integer myCurrentIndex;
2064 // Verification of the arguments
2065 if (argc>6 || argc<2)
2067 std::cout << "vcircle error: expect 4 arguments.\n";
2068 return 1; // TCL_ERROR
2070 TheAISContext()->CloseAllContexts();
2072 // There are all arguments
2076 TCollection_AsciiString aName(argv[1]);
2077 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2079 Handle(AIS_InteractiveObject) theShapeA;
2080 Handle(AIS_InteractiveObject) theShapeB;
2083 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2085 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2088 // Arguments: AIS_Point AIS_Point AIS_Point
2089 // ========================================
2090 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2091 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2093 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2095 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2096 return 1; // TCL_ERROR
2098 // The third object must be a point
2099 Handle(AIS_InteractiveObject) theShapeC =
2100 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2101 if (theShapeC.IsNull() ||
2102 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2104 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2105 return 1; // TCL_ERROR
2108 // Verify that the three points are different
2109 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2110 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2111 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2113 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2114 Handle(Geom_CartesianPoint) myCartPointA =
2115 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2117 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2118 Handle(Geom_CartesianPoint) myCartPointB =
2119 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2121 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2122 Handle(Geom_CartesianPoint) myCartPointC =
2123 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2126 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2127 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2128 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2130 std::cout << "vcircle error: Same points.\n";
2131 return 1; // TCL_ERROR
2134 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2135 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2136 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2138 std::cout << "vcircle error: Same points.\n";
2139 return 1; // TCL_ERROR
2142 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2143 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2144 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2146 std::cout << "vcircle error: Same points.\n";
2147 return 1;// TCL_ERROR
2149 // Construction of the circle
2150 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2151 myCartPointB->Pnt(), myCartPointC->Pnt() );
2152 Handle (Geom_Circle) theGeomCircle;
2155 theGeomCircle = Cir.Value();
2157 catch (StdFail_NotDone)
2159 std::cout << "vcircle error: can't create circle\n";
2160 return -1; // TCL_ERROR
2163 DisplayCircle(theGeomCircle, aName, isFilled);
2166 // Arguments: AIS_Plane AIS_Point Real
2167 // ===================================
2168 else if (theShapeA->Type() == AIS_KOI_Datum &&
2169 theShapeA->Signature() == 7 )
2171 if (theShapeB->Type() != AIS_KOI_Datum ||
2172 theShapeB->Signature() != 1 )
2174 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2175 return 1; // TCL_ERROR
2177 // Check that the radius is >= 0
2178 if (Draw::Atof(argv[4]) <= 0 )
2180 std::cout << "vcircle error: the radius must be >=0.\n";
2181 return 1; // TCL_ERROR
2184 // Recover the normal to the plane
2185 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2186 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2188 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2189 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2190 Handle(Geom_CartesianPoint) myCartPointB =
2191 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2193 gp_Pln mygpPlane = myGeomPlane->Pln();
2194 gp_Ax1 thegpAxe = mygpPlane.Axis();
2195 gp_Dir theDir = thegpAxe.Direction();
2196 gp_Pnt theCenter = myCartPointB->Pnt();
2197 Standard_Real TheR = Draw::Atof(argv[4]);
2198 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2199 Handle (Geom_Circle) theGeomCircle;
2202 theGeomCircle = Cir.Value();
2204 catch (StdFail_NotDone)
2206 std::cout << "vcircle error: can't create circle\n";
2207 return -1; // TCL_ERROR
2210 DisplayCircle(theGeomCircle, aName, isFilled);
2217 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2218 return 1; // TCL_ERROR
2222 // No arguments: selection in the viewer
2223 // =========================================
2226 // Get the name of the circle
2227 TCollection_AsciiString aName(argv[1]);
2229 TheAISContext()->OpenLocalContext();
2230 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2232 // Activate selection mode for vertices and faces
2233 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2234 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2235 std::cout << " Select a vertex or a face\n";
2238 Standard_Integer argcc = 5;
2239 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2240 const char **argvv = (const char **) buff;
2241 while (ViewerMainLoop( argcc, argvv) ) { }
2244 TopoDS_Shape ShapeA;
2245 for(TheAISContext()->InitSelected();
2246 TheAISContext()->MoreSelected();
2247 TheAISContext()->NextSelected() )
2249 ShapeA = TheAISContext()->SelectedShape();
2252 // ShapeA is a Vertex
2253 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2255 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2256 std::cout << " Select a different vertex\n";
2258 TopoDS_Shape ShapeB;
2262 Standard_Integer argccc = 5;
2263 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2264 const char **argvvv = (const char **) bufff;
2265 while (ViewerMainLoop( argccc, argvvv) ) { }
2268 for(TheAISContext()->InitSelected();
2269 TheAISContext()->MoreSelected();
2270 TheAISContext()->NextSelected() )
2272 ShapeB = TheAISContext()->SelectedShape();
2274 } while(ShapeB.IsSame(ShapeA) );
2276 // Selection of ShapeC
2277 std::cout << " Select the last vertex\n";
2278 TopoDS_Shape ShapeC;
2282 Standard_Integer argcccc = 5;
2283 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2284 const char **argvvvv = (const char **) buffff;
2285 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2288 for(TheAISContext()->InitSelected();
2289 TheAISContext()->MoreSelected();
2290 TheAISContext()->NextSelected() )
2292 ShapeC = TheAISContext()->SelectedShape();
2294 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2297 Standard_Boolean isFilled;
2298 std::cout << "Enter filled status (0 or 1)\n";
2301 // Close the local context
2302 TheAISContext()->CloseLocalContext(myCurrentIndex);
2304 // Construction of the circle
2305 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2306 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2307 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2309 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2310 Handle (Geom_Circle) theGeomCircle;
2313 theGeomCircle = Cir.Value();
2315 catch (StdFail_NotDone)
2317 std::cout << "vcircle error: can't create circle\n";
2318 return -1; // TCL_ERROR
2321 DisplayCircle(theGeomCircle, aName, isFilled);
2327 std::cout << " Select a vertex (in your face)\n";
2328 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2330 TopoDS_Shape ShapeB;
2332 Standard_Integer argccc = 5;
2333 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2334 const char **argvvv = (const char **) bufff;
2335 while (ViewerMainLoop( argccc, argvvv) ) { }
2338 for(TheAISContext()->InitSelected();
2339 TheAISContext()->MoreSelected();
2340 TheAISContext()->NextSelected() )
2342 ShapeB = TheAISContext()->SelectedShape();
2345 // Recover the radius
2346 Standard_Real theRad;
2349 std::cout << " Enter the value of the radius:\n";
2351 } while (theRad <= 0);
2353 // Get filled status
2354 Standard_Boolean isFilled;
2355 std::cout << "Enter filled status (0 or 1)\n";
2358 // Close the local context
2359 TheAISContext()->CloseLocalContext(myCurrentIndex);
2360 // Construction of the circle
2362 // Recover the normal to the plane. tag
2363 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2364 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2365 gp_Pln myPlane = mySurface.Plane();
2366 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2367 gp_Pln mygpPlane = theGeomPlane->Pln();
2368 gp_Ax1 thegpAxe = mygpPlane.Axis();
2369 gp_Dir theDir = thegpAxe.Direction();
2371 // Recover the center
2372 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2374 // Construct the circle
2375 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2376 Handle (Geom_Circle) theGeomCircle;
2379 theGeomCircle = Cir.Value();
2381 catch (StdFail_NotDone)
2383 std::cout << "vcircle error: can't create circle\n";
2384 return -1; // TCL_ERROR
2387 DisplayCircle(theGeomCircle, aName, isFilled);
2397 //===============================================================================================
2398 //function : VDrawText
2400 //purpose : Create a text.
2401 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2402 //===============================================================================================
2403 #include <Graphic3d_Group.hxx>
2404 #include <Graphic3d_Structure.hxx>
2405 #include <Graphic3d_AspectText3d.hxx>
2406 #include <Graphic3d_AspectFillArea3d.hxx>
2407 #include <Graphic3d_StructureManager.hxx>
2408 #include <Graphic3d_VerticalTextAlignment.hxx>
2409 #include <Graphic3d_HorizontalTextAlignment.hxx>
2411 #include <Font_NameOfFont.hxx>
2413 #include <Visual3d_ViewManager.hxx>
2415 #include <Standard_DefineHandle.hxx>
2417 #include <Prs3d_Root.hxx>
2418 #include <Prs3d_Text.hxx>
2419 #include <Prs3d_TextAspect.hxx>
2420 #include <Prs3d_ShadingAspect.hxx>
2421 #include <PrsMgr_PresentationManager3d.hxx>
2423 #include <TCollection_ExtendedString.hxx>
2424 #include <TCollection_AsciiString.hxx>
2426 #include <gp_Pnt.hxx>
2427 #include <Quantity_NameOfColor.hxx>
2428 #include <Quantity_Color.hxx>
2431 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2433 class MyTextClass:public AIS_InteractiveObject
2437 DEFINE_STANDARD_RTTI(MyTextClass );
2443 const TCollection_ExtendedString& , const gp_Pnt& ,
2444 Quantity_Color color,
2445 Standard_Integer aHJust,
2446 Standard_Integer aVJust ,
2447 Standard_Real Angle ,
2448 Standard_Boolean Zoom ,
2449 Standard_Real Height,
2450 Font_FontAspect FontAspect,
2451 Standard_CString Font
2456 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2457 const Handle(Prs3d_Presentation)& aPresentation,
2458 const Standard_Integer aMode);
2460 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2461 const Standard_Integer /*aMode*/){} ;
2464 TCollection_ExtendedString aText;
2467 Standard_Real Green;
2469 Standard_Real aAngle;
2470 Standard_Real aHeight;
2471 Standard_Boolean aZoomable;
2472 Quantity_Color aColor;
2473 TCollection_AsciiString aFont;
2474 Font_FontAspect aFontAspect;
2475 Graphic3d_HorizontalTextAlignment aHJustification;
2476 Graphic3d_VerticalTextAlignment aVJustification;
2481 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2482 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2485 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2486 Quantity_Color color = Quantity_NOC_YELLOW,
2487 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2488 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2489 Standard_Real angle = 0.0 ,
2490 Standard_Boolean zoomable = Standard_True,
2491 Standard_Real height = 12.,
2492 Font_FontAspect fontAspect = Font_FA_Regular,
2493 Standard_CString font = "Courier")
2496 aPosition = position;
2497 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2498 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2500 aZoomable = zoomable;
2503 aFontAspect = fontAspect;
2509 //////////////////////////////////////////////////////////////////////////////
2510 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
2511 const Handle(Prs3d_Presentation)& aPresentation,
2512 const Standard_Integer /*aMode*/)
2515 aPresentation->Clear();
2517 Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect();
2519 asp->SetFont(aFont.ToCString());
2520 asp->SetColor(aColor);
2521 asp->SetHeight(aHeight); // I am changing the myHeight value
2523 asp->SetHorizontalJustification(aHJustification);
2524 asp->SetVerticalJustification(aVJustification);
2525 asp->Aspect()->SetTextZoomable(aZoomable);
2526 asp->Aspect()->SetTextAngle(aAngle);
2527 asp->Aspect()->SetTextFontAspect(aFontAspect);
2528 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2530 /* This comment code is worked
2531 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2532 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2533 Graphic3d_Vertex vertices_text;
2534 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2535 TheGroup->SetPrimitivesAspect(aspect);
2536 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2540 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2545 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2546 di<<"Usage: type help "<<argv[0]<<"\n";
2547 return 1; //TCL_ERROR
2550 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2552 // Create 3D view if it doesn't exist
2553 if ( aContext.IsNull() )
2555 ViewerTest::ViewerInit();
2556 aContext = ViewerTest::GetAISContext();
2557 if( aContext.IsNull() )
2559 di << "Error: Cannot create a 3D view\n";
2560 return 1; //TCL_ERROR
2565 const Standard_Real X = Draw::Atof(argv[2]);
2566 const Standard_Real Y = Draw::Atof(argv[3]);
2567 const Standard_Real Z = Draw::Atof(argv[4]);
2568 const gp_Pnt pnt(X,Y,Z);
2571 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2572 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2573 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
2574 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2577 const int hor_align = Draw::Atoi(argv[8]);
2578 const int ver_align = Draw::Atoi(argv[9]);
2581 const Standard_Real angle = Draw::Atof(argv[10]);
2584 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
2587 const Standard_Real height = Draw::Atof(argv[12]);
2590 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
2593 TCollection_AsciiString font;
2595 font.AssignCat("Courier");
2597 font.AssignCat(argv[14]);
2599 // Text is multibyte
2600 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
2603 TCollection_ExtendedString name;
2606 const char *str = argv[1];
2607 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2608 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2610 unsigned short c1 = *str++;
2611 unsigned short c2 = *str++;
2613 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2623 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2624 aContext->Display(myT,Standard_True);
2631 #include <gp_Pnt.hxx>
2632 #include <Graphic3d_ArrayOfPoints.hxx>
2633 #include <Graphic3d_ArrayOfPrimitives.hxx>
2634 #include <Graphic3d_ArrayOfTriangles.hxx>
2635 #include <Poly_Array1OfTriangle.hxx>
2636 #include <Poly_Triangle.hxx>
2637 #include <Poly_Triangulation.hxx>
2638 #include <TColgp_Array1OfPnt.hxx>
2639 #include <TShort_Array1OfShortReal.hxx>
2640 #include <TShort_HArray1OfShortReal.hxx>
2642 #include <AIS_Triangulation.hxx>
2643 #include <StdPrs_ToolShadedShape.hxx>
2644 #include <Poly_Connect.hxx>
2645 #include <TColgp_Array1OfDir.hxx>
2646 #include <Graphic3d_GraphicDriver.hxx>
2648 #include <TColStd_Array1OfInteger.hxx>
2649 #include <TColStd_HArray1OfInteger.hxx>
2650 #include <Prs3d_ShadingAspect.hxx>
2651 #include <Graphic3d_MaterialAspect.hxx>
2652 #include <Graphic3d_AspectFillArea3d.hxx>
2654 #include <BRepPrimAPI_MakeCylinder.hxx>
2655 #include <TopoDS_Shape.hxx>
2656 #include <TopExp_Explorer.hxx>
2657 #include <TopAbs.hxx>
2658 #include <StdSelect_ShapeTypeFilter.hxx>
2661 //===============================================================================================
2662 //function : CalculationOfSphere
2664 //purpose : Create a Sphere
2665 //===============================================================================================
2667 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2670 double mRadius = Radius;
2671 double mCenter[3] = {X,Y,Z};
2672 int mThetaResolution;
2674 double mStartTheta = 0;//StartTheta;
2675 double mEndTheta = 360;//EndTheta;
2676 double mStartPhi = 0;//StartPhi;
2677 double mEndPhi = 180;//EndPhi;
2678 res = res < 4 ? 4 : res;
2680 mThetaResolution = res;
2681 mPhiResolution = res;
2684 int jStart, jEnd, numOffset;
2685 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2686 double startTheta, endTheta, startPhi, endPhi;
2687 int base, numPoles=0, thetaResolution, phiResolution;
2692 if ( numPieces > mThetaResolution ) {
2693 numPieces = mThetaResolution;
2696 int localThetaResolution = mThetaResolution;
2697 double localStartTheta = mStartTheta;
2698 double localEndTheta = mEndTheta;
2700 while ( localEndTheta < localStartTheta ) {
2701 localEndTheta += 360.0;
2704 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2706 // Change the ivars based on pieces.
2708 start = piece * localThetaResolution / numPieces;
2709 end = (piece+1) * localThetaResolution / numPieces;
2710 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2711 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2712 localThetaResolution = end - start;
2714 // Create north pole if needed
2715 int number_point = 0;
2716 int number_pointArray = 0;
2718 if ( mStartPhi <= 0.0 ) {
2719 number_pointArray++;
2722 if ( mEndPhi >= 180.0 ) {
2723 number_pointArray++;
2727 // Check data, determine increments, and convert to radians
2728 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2729 startTheta *= M_PI / 180.0;
2730 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2731 endTheta *= M_PI / 180.0;
2734 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2735 startPhi *= M_PI / 180.0;
2736 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2737 endPhi *= M_PI / 180.0;
2739 phiResolution = mPhiResolution - numPoles;
2740 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2741 thetaResolution = localThetaResolution;
2742 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2743 ++localThetaResolution;
2745 deltaTheta = (endTheta - startTheta) / thetaResolution;
2747 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2748 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2750 // Create intermediate points
2751 for ( i = 0; i < localThetaResolution; i++ ) {
2752 for ( j = jStart; j < jEnd; j++ ) {
2753 number_pointArray++;
2757 //Generate mesh connectivity
2758 base = phiResolution * localThetaResolution;
2760 int number_triangle = 0 ;
2761 if ( mStartPhi <= 0.0 ) { // around north pole
2762 number_triangle += localThetaResolution;
2765 if ( mEndPhi >= 180.0 ) { // around south pole
2766 number_triangle += localThetaResolution;
2769 // bands in-between poles
2770 for ( i=0; i < localThetaResolution; i++){
2771 for ( j=0; j < (phiResolution-1); j++){
2772 number_triangle +=2;
2776 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2777 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2778 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2780 if ( mStartPhi <= 0.0 ){
2783 x[2] = mCenter[2] + mRadius;
2784 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2787 // Create south pole if needed
2788 if ( mEndPhi >= 180.0 ){
2791 x[2] = mCenter[2] - mRadius;
2792 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2796 for ( i=0; i < localThetaResolution; i++){
2797 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2798 for ( j = jStart; j < jEnd; j++){
2799 phi = startPhi + j*deltaPhi;
2800 radius = mRadius * sin((double)phi);
2801 n[0] = radius * cos((double)theta);
2802 n[1] = radius * sin((double)theta);
2803 n[2] = mRadius * cos((double)phi);
2804 x[0] = n[0] + mCenter[0];
2805 x[1] = n[1] + mCenter[1];
2806 x[2] = n[2] + mCenter[2];
2807 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2813 number_triangle = 1;
2814 if ( mStartPhi <= 0.0 ){// around north pole
2815 for (i=0; i < localThetaResolution; i++){
2816 pts[0] = phiResolution*i + numPoles;
2817 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2819 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2824 if ( mEndPhi >= 180.0 ){ // around south pole
2825 numOffset = phiResolution - 1 + numPoles;
2826 for (i=0; i < localThetaResolution; i++){
2827 pts[0] = phiResolution*i + numOffset;
2828 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2829 pts[1] = numPoles - 1;
2830 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2835 // bands in-between poles
2837 for (i=0; i < localThetaResolution; i++){
2838 for (j=0; j < (phiResolution-1); j++){
2839 pts[0] = phiResolution*i + j + numPoles;
2840 pts[1] = pts[0] + 1;
2841 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2842 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2845 pts[2] = pts[1] - 1;
2846 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2851 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2853 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2855 Standard_Integer index[3];
2856 Standard_Real Tol = Precision::Confusion();
2859 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2860 gp_XYZ eqPlan(0, 0, 0);
2861 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2862 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2863 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2864 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2866 Standard_Real mod = vv.Modulus();
2867 if(mod < Tol) continue;
2871 Standard_Real modmax = eqPlan.Modulus();
2874 Nor = gp_Dir(eqPlan);
2876 Nor = gp_Dir(0., 0., 1.);
2878 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2879 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2880 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2881 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2885 polyTriangulation->SetNormals(Normals);
2887 return polyTriangulation;
2890 //===============================================================================================
2891 //function : VDrawSphere
2893 //purpose : Create an AIS shape.
2894 //===============================================================================================
2895 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2898 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2899 if (aContextAIS.IsNull())
2901 std::cout << "Call vinit before!\n";
2906 std::cout << "Use: " << argv[0]
2907 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2911 // read the arguments
2912 TCollection_AsciiString aShapeName (argv[1]);
2913 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2914 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2915 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2916 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2917 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2918 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2919 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2921 // remove AIS object with given name from map
2922 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2925 std::cout << "Compute Triangulation...\n";
2926 Handle(AIS_Triangulation) aShape
2927 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2930 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2931 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2933 // stupid initialization of Green color in RGBA space as integer
2934 // probably wrong for big-endian CPUs
2935 Standard_Integer aRed = 0;
2936 Standard_Integer aGreen = 255;
2937 Standard_Integer aBlue = 0;
2938 Standard_Integer anAlpha = 0; // not used
2939 Standard_Integer aColorInt = aRed;
2940 aColorInt += aGreen << 8;
2941 aColorInt += aBlue << 16;
2942 aColorInt += anAlpha << 24;
2944 // setup colors array per vertex
2945 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2946 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2948 aColorArray->SetValue (aNodeId, aColorInt);
2950 aShape->SetColors (aColorArray);
2953 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2954 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2955 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2956 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2957 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2958 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2959 aTotalSize >>= 20; //MB
2960 aNormalsSize >>= 20;
2962 aTrianglesSize >>= 20;
2963 aPolyConnectSize >>= 20;
2966 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2967 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2968 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2969 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2970 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2971 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2974 // Setting material properties, very important for desirable visual result!
2975 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2976 aMat.SetAmbient (0.2);
2977 aMat.SetSpecular (0.5);
2978 Handle(Graphic3d_AspectFillArea3d) anAspect
2979 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2981 Quantity_NOC_YELLOW,
2986 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2989 anAspect->SetEdgeOn();
2993 anAspect->SetEdgeOff();
2995 aShAsp->SetAspect (anAspect);
2996 aShape->Attributes()->SetShadingAspect (aShAsp);
2998 VDisplayAISObject (aShapeName, aShape);
3002 //=============================================================================
3003 //function : VComputeHLR
3005 //=============================================================================
3007 static int VComputeHLR (Draw_Interpretor& di,
3008 Standard_Integer argc,
3011 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3013 if (aContextAIS.IsNull ())
3015 di << "Please call vinit before\n";
3019 if ( argc != 3 && argc != 12 )
3021 di << "Usage: " << argv[0] << " ShapeName HlrName "
3022 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3023 << " ShapeName - name of the initial shape\n"
3024 << " HlrName - result hlr object from initial shape\n"
3025 << " eye, dir are eye position and look direction\n"
3026 << " up is the look up direction vector\n"
3027 << " Use vtop to see projected hlr shape\n";
3031 // shape and new object name
3032 TCollection_AsciiString aShapeName (argv[1]);
3033 TCollection_AsciiString aHlrName (argv[2]);
3035 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3038 BRep_Builder aBrepBuilder;
3039 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3042 di << "No shape with name " << argv[1] << " found\n";
3047 if (GetMapOfAIS ().IsBound2 (aHlrName))
3049 di << "Presentable object with name " << argv[2] << " already exists\n";
3053 // close local context
3054 if (aContextAIS->HasOpenedContext ())
3055 aContextAIS->CloseLocalContext ();
3057 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3058 HLRBRep_PolyHLRToShape aHLRToShape;
3067 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3068 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3069 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3070 aProjAx.SetLocation (anEye);
3071 aProjAx.SetDirection (aDir);
3072 aProjAx.SetYDirection (anUp);
3078 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3079 Handle(V3d_View) aView = ViewerTest::CurrentView();
3080 Standard_Integer aWidth, aHeight;
3081 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3082 Standard_Real aRightX, aRightY, aRightZ;
3083 aView->Window()->Size (aWidth, aHeight);
3085 aView->ConvertWithProj (aWidth, aHeight/2,
3086 aRightX, aRightY, aRightZ,
3087 aDirX, aDirY, aDirZ);
3089 aView->ConvertWithProj (aWidth/2, aHeight/2,
3090 aCentX, aCentY, aCentZ,
3091 aDirX, aDirY, aDirZ);
3093 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3094 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3095 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3096 aProjAx.SetLocation (anEye);
3097 aProjAx.SetDirection (aDir);
3098 aProjAx.SetXDirection (aRight);
3101 HLRAlgo_Projector aProjector (aProjAx);
3102 aPolyAlgo->Projector (aProjector);
3103 aPolyAlgo->Load (aSh);
3104 aPolyAlgo->Update ();
3106 aHLRToShape.Update (aPolyAlgo);
3108 // make hlr shape from input shape
3109 TopoDS_Compound aHlrShape;
3110 BRep_Builder aBuilder;
3111 aBuilder.MakeCompound (aHlrShape);
3113 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3114 if (!aCompound.IsNull ())
3116 aBuilder.Add (aHlrShape, aCompound);
3119 // extract visible outlines
3120 aCompound = aHLRToShape.OutLineVCompound();
3121 if (!aCompound.IsNull ())
3123 aBuilder.Add (aHlrShape, aCompound);
3126 // create an AIS shape and display it
3127 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3128 GetMapOfAIS().Bind (anObject, aHlrName);
3129 aContextAIS->Display (anObject);
3131 aContextAIS->UpdateCurrentViewer ();
3136 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3137 // manipulating and displaying such an array with AIS context
3138 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3139 class MyPArrayObject : public AIS_InteractiveObject
3144 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3145 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3147 myArrayDescription = theArrayDescription;
3148 myMarkerAspect = theMarkerAspect;
3151 DEFINE_STANDARD_RTTI(MyPArrayObject);
3155 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3156 const Handle(Prs3d_Presentation)& aPresentation,
3157 const Standard_Integer aMode);
3159 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3160 const Standard_Integer /*theMode*/);
3162 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3163 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3164 Standard_Integer &theArgIndex,
3165 Standard_Integer theArgCount,
3166 Standard_Integer theMaxArgs);
3170 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3171 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3175 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3176 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3178 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3179 const Handle(Prs3d_Presentation)& aPresentation,
3180 const Standard_Integer /*aMode*/)
3183 // Parsing array description
3184 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3185 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3186 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3188 Standard_Integer anArgIndex = 0;
3189 Standard_Integer anArgsCount = myArrayDescription->Length();
3190 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3192 TCollection_AsciiString aCommand;
3193 while (anArgIndex < anArgsCount)
3195 aCommand = myArrayDescription->Value (anArgIndex);
3196 aCommand.LowerCase();
3199 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3201 // vertex has a normal or normal with color or texel
3202 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3203 hasNormals = Standard_True;
3205 // vertex has a color
3206 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3207 hasVColors = Standard_True;
3209 // vertex has a texel
3210 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3211 hasTexels = Standard_True;
3216 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3219 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3220 hasBColors = Standard_True;
3225 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3234 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3235 if (anArrayType == "points")
3237 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3239 else if (anArrayType == "segments")
3240 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3241 else if (anArrayType == "polylines")
3242 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3243 hasVColors, hasBColors);
3244 else if (anArrayType == "triangles")
3245 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3246 hasVColors, hasTexels);
3247 else if (anArrayType == "trianglefans")
3248 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3249 hasNormals, hasVColors,
3250 hasBColors, hasTexels);
3251 else if (anArrayType == "trianglestrips")
3252 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3253 hasNormals, hasVColors,
3254 hasBColors, hasTexels);
3255 else if (anArrayType == "quads")
3256 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3257 hasNormals, hasVColors,
3259 else if (anArrayType == "quadstrips")
3260 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3261 hasNormals, hasVColors,
3262 hasBColors, hasTexels);
3263 else if (anArrayType == "polygons")
3264 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3265 hasNormals, hasVColors, hasBColors,
3269 while (anArgIndex < anArgsCount)
3271 aCommand = myArrayDescription->Value (anArgIndex);
3272 aCommand.LowerCase();
3273 if (!aCommand.IsAscii())
3277 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3279 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3280 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3281 myArrayDescription->Value (anArgIndex - 1).RealValue());
3282 const Standard_Integer aVertIndex = anArray->VertexNumber();
3284 // vertex has a normal or normal with color or texel
3285 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3286 anArray->SetVertexNormal (aVertIndex,
3287 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3288 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3289 myArrayDescription->Value (anArgIndex - 1).RealValue());
3291 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3292 anArray->SetVertexColor (aVertIndex,
3293 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3294 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3295 myArrayDescription->Value (anArgIndex - 1).RealValue());
3297 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3298 anArray->SetVertexTexel (aVertIndex,
3299 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3300 myArrayDescription->Value (anArgIndex - 1).RealValue());
3303 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3305 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3307 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3308 anArray->AddBound (aVertCount,
3309 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3310 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3311 myArrayDescription->Value (anArgIndex - 1).RealValue());
3314 anArray->AddBound (aVertCount);
3317 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3319 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3320 anArray->AddEdge (aVertIndex);
3327 aPresentation->Clear();
3328 if (!myMarkerAspect.IsNull())
3330 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3332 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3335 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3336 const Standard_Integer /*theMode*/)
3338 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3340 Standard_Integer anArgIndex = 1;
3341 while (anArgIndex < myArrayDescription->Length())
3343 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3345 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3346 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3347 myArrayDescription->Value (anArgIndex - 1).RealValue());
3348 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3349 theSelection->Add (aSensetivePoint);
3358 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3359 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3360 Standard_Integer &theArgIndex,
3361 Standard_Integer theArgCount,
3362 Standard_Integer theMaxArgs)
3364 // check if there is more elements than expected
3365 if (theArgIndex >= theMaxArgs)
3368 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3369 aStrCommand.LowerCase();
3370 if (aStrCommand.Search(theCommand) != 1 ||
3371 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3374 // go to the first data element
3377 // check data if it can be converted to numeric
3378 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3380 aStrCommand = theArgsArray->Value (theArgIndex);
3381 if (!aStrCommand.IsRealValue())
3388 //=============================================================================
3389 //function : VDrawPArray
3390 //purpose : Draws primitives array from list of vertexes, bounds, edges
3391 //=============================================================================