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 <TColStd_MapOfInteger.hxx>
37 #include <AIS_MapOfInteractive.hxx>
38 #include <ViewerTest_AutoUpdater.hxx>
39 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
40 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_EventManager.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <BRepTools.hxx>
45 #include <BRep_Builder.hxx>
46 #include <TopAbs_ShapeEnum.hxx>
49 #include <BRep_Tool.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <BRepAdaptor_Curve.hxx>
53 #include <BRepAdaptor_Surface.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopoDS_Face.hxx>
61 #include <Draw_Window.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 #include <AIS_ListOfInteractive.hxx>
64 #include <AIS_DisplayMode.hxx>
65 #include <AIS_Shape.hxx>
67 #include <AIS_InteractiveContext.hxx>
68 #include <Geom_Plane.hxx>
70 #include <TCollection_ExtendedString.hxx>
71 #include <TCollection_HAsciiString.hxx>
72 #include <GC_MakePlane.hxx>
73 #include <gp_Circ.hxx>
74 #include <AIS_Axis.hxx>
75 #include <Geom_Axis2Placement.hxx>
76 #include <Geom_Axis1Placement.hxx>
77 #include <AIS_Trihedron.hxx>
78 #include <AIS_Axis.hxx>
79 #include <gp_Trsf.hxx>
80 #include <TopLoc_Location.hxx>
82 #include <HLRAlgo_Projector.hxx>
83 #include <HLRBRep_PolyAlgo.hxx>
84 #include <HLRBRep_PolyHLRToShape.hxx>
85 #include <Aspect_Window.hxx>
87 #include <Graphic3d_ArrayOfPoints.hxx>
88 #include <Graphic3d_ArrayOfSegments.hxx>
89 #include <Graphic3d_ArrayOfPolylines.hxx>
90 #include <Graphic3d_ArrayOfTriangles.hxx>
91 #include <Graphic3d_ArrayOfTriangleFans.hxx>
92 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
93 #include <Graphic3d_ArrayOfQuadrangles.hxx>
94 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
95 #include <Graphic3d_ArrayOfPolygons.hxx>
96 #include <Graphic3d_AspectMarker3d.hxx>
97 #include <Graphic3d_Group.hxx>
98 #include <Standard_Real.hxx>
100 #include <AIS_Circle.hxx>
101 #include <AIS_Drawer.hxx>
102 #include <BRepBuilderAPI_MakeEdge.hxx>
103 #include <BRepBuilderAPI_MakeFace.hxx>
104 #include <BRepBuilderAPI_MakeWire.hxx>
105 #include <Geom_Circle.hxx>
106 #include <GC_MakeCircle.hxx>
107 #include <Prs3d_Presentation.hxx>
108 #include <Select3D_SensitiveCircle.hxx>
109 #include <SelectMgr_EntityOwner.hxx>
110 #include <SelectMgr_Selection.hxx>
111 #include <StdFail_NotDone.hxx>
112 #include <StdPrs_ShadedShape.hxx>
113 #include <TopoDS_Wire.hxx>
115 #include <AIS_MultipleConnectedInteractive.hxx>
116 #include <AIS_ConnectedInteractive.hxx>
117 #include <TopLoc_Location.hxx>
118 #include <TColStd_ListOfInteger.hxx>
119 #include <TColStd_ListIteratorOfListOfInteger.hxx>
121 #include <Select3D_SensitiveTriangle.hxx>
122 #include <Select3D_SensitiveCurve.hxx>
123 #include <Select3D_SensitivePoint.hxx>
124 #include <BRepAdaptor_Curve.hxx>
125 #include <StdPrs_Curve.hxx>
127 #include <BRepExtrema_ExtPC.hxx>
128 #include <BRepExtrema_ExtPF.hxx>
130 #include <Prs3d_VertexDrawMode.hxx>
131 #include <Prs3d_LineAspect.hxx>
132 #include <Prs3d_PointAspect.hxx>
134 #include <Image_AlienPixMap.hxx>
135 #include <TColStd_HArray1OfAsciiString.hxx>
138 # define _CRT_SECURE_NO_DEPRECATE
139 # pragma warning (disable:4996)
142 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
143 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
144 const Handle(AIS_InteractiveObject)& theAISObj,
145 Standard_Boolean theReplaceIfExists = Standard_True);
146 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
147 extern Handle(AIS_InteractiveContext)& TheAISContext();
150 //==============================================================================
151 //function : Vtrihedron 2d
152 //purpose : Create a plane with a 2D trihedron from a faceselection
153 //Draw arg : vtri2d name
154 //==============================================================================
155 #include <AIS_PlaneTrihedron.hxx>
159 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
162 // Verification des arguments
163 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
166 Standard_Integer myCurrentIndex;
167 // Fermeture des contextes
168 TheAISContext()->CloseAllContexts();
169 // Ouverture d'un contexte local et recuperation de son index.
170 TheAISContext()->OpenLocalContext();
171 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
172 // On active les modes de selections faces.
173 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
174 di<<" Select a face ."<<"\n";
176 // Boucle d'attente waitpick.
177 Standard_Integer argccc = 5;
178 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
179 const char **argvvv = (const char **) bufff;
180 while (ViewerMainLoop( argccc, argvvv) ) { }
184 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
185 ShapeB = TheAISContext()->SelectedShape();
188 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
190 // Construction du Plane
191 // recuperation des edges des faces.
192 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
194 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
198 // si il y a plusieurs edges
199 if (FaceExpB.More() ) {
201 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
202 BRepAdaptor_Curve theCurveB(EdgeB);
203 BRepAdaptor_Curve theCurveC(EdgeC);
204 A=theCurveC.Value(0.1);
205 B=theCurveC.Value(0.9);
206 C=theCurveB.Value(0.5);
209 // FaceB a 1 unique edge courbe
210 BRepAdaptor_Curve theCurveB(EdgeB);
211 A=theCurveB.Value(0.1);
212 B=theCurveB.Value(0.9);
213 C=theCurveB.Value(0.5);
215 // Construction du Geom_Plane
216 GC_MakePlane MkPlane(A,B,C);
217 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
219 // Construction de l'AIS_PlaneTrihedron
220 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
222 // Fermeture du contexte local.
223 TheAISContext()->CloseLocalContext(myCurrentIndex);
225 // on le display & bind
226 TheAISContext()->Display(theAISPlaneTri );
227 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
234 //==============================================================================
235 //function : VTriherdron
236 //purpose : Create a trihedron. If no arguments are set, the default
237 // trihedron (Oxyz) is created.
238 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
239 //==============================================================================
241 static int VTrihedron (Draw_Interpretor& theDi,
242 Standard_Integer theArgsNb,
243 const char** theArgVec)
245 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
247 theDi << theArgVec[0] << " Syntax error\n";
251 gp_Pnt anOrigin (0.0, 0.0, 0.0);
252 gp_Dir aDirZ = gp::DZ();
253 gp_Dir aDirX = gp::DX();
254 Standard_Integer anArgIter = 2; // 1st is an IO name
255 if (anArgIter < theArgsNb)
257 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
258 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
259 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
260 if (anArgIter < theArgsNb)
262 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
263 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
264 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
265 aDirZ.SetCoord (aX, aY, aZ);
267 aX = Draw::Atof (theArgVec[anArgIter++]);
268 aY = Draw::Atof (theArgVec[anArgIter++]);
269 aZ = Draw::Atof (theArgVec[anArgIter++]);
270 aDirX.SetCoord (aX, aY, aZ);
274 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
276 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
280 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
281 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
282 VDisplayAISObject (theArgVec[1], aShape);
286 //==============================================================================
289 //purpose : Change the size of a named or selected trihedron
290 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
291 // if no value, the value is set at 100 by default
292 //Draw arg : vsize [name] [size]
293 //==============================================================================
295 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
298 // Declaration de booleens
299 Standard_Boolean ThereIsName;
300 Standard_Boolean ThereIsCurrent;
302 Standard_Boolean hascol;
304 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
306 // Verification des arguments
307 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
309 // Verification du nombre d'arguments
310 if (argc==1) {ThereIsName=Standard_False;value=100;}
311 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
312 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
314 // On ferme le contexte local pour travailler dans le contexte global
315 if(TheAISContext()->HasOpenedContext())
316 TheAISContext()->CloseLocalContext();
318 // On set le booleen ThereIsCurrent
319 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
320 else {ThereIsCurrent=Standard_False;}
324 //===============================================================
325 // Il n'y a pas de nom mais des objets selectionnes
326 //===============================================================
327 if (!ThereIsName && ThereIsCurrent)
330 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
333 while ( it.More() ) {
335 Handle(AIS_InteractiveObject) aShape=
336 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
338 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
341 // On verifie que l'AIS InteraciveObject selectionne est bien
343 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
345 if (aShape->HasColor()) {
346 hascol=Standard_True;
348 // On recupere la couleur de aShape
349 col=aShape->Color();}
351 else hascol=Standard_False;
353 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
354 // pour lui appliquer la methode SetSize()
355 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
357 // C'est bien un triedre,on chage sa valeur!
358 aTrihedron->SetSize(value);
360 // On donne la couleur au Trihedron
361 if(hascol) aTrihedron->SetColor(col);
362 else aTrihedron->UnsetColor();
365 // The trihedron hasn't be errased from the map
366 // so you just have to redisplay it
367 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
376 TheAISContext() ->UpdateCurrentViewer();
379 //===============================================================
380 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
381 //===============================================================
385 //===============================================================
386 // Il y a un nom de triedre passe en argument
387 //===============================================================
389 TCollection_AsciiString name=argv[1];
391 // on verifie que ce nom correspond bien a une shape
392 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
396 // on recupere la shape dans la map des objets displayes
397 Handle(AIS_InteractiveObject) aShape =
398 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
400 // On verifie que l'AIS InteraciveObject est bien
402 if (!aShape.IsNull() &&
403 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
406 if (aShape->HasColor()) {
407 hascol=Standard_True;
409 // On recupere la couleur de aShape
410 col=aShape->Color();}
412 else hascol=Standard_False;
414 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
415 // pour lui appliquer la methode SetSize()
416 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
418 // C'est bien un triedre,on chage sa valeur
419 aTrihedron->SetSize(value);
421 // On donne la couleur au Trihedron
422 if(hascol) aTrihedron->SetColor(col);
423 else aTrihedron->UnsetColor();
425 // The trihedron hasn't be errased from the map
426 // so you just have to redisplay it
427 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
429 TheAISContext() ->UpdateCurrentViewer();
437 //==============================================================================
439 //==============================================================================
440 //function : VPlaneTrihedron
441 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
442 //Draw arg : vplanetri name
443 //==============================================================================
444 #include <AIS_Plane.hxx>
448 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
451 // Verification des arguments
452 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
455 Standard_Integer myCurrentIndex;
456 // Fermeture des contextes locaux
457 TheAISContext()->CloseAllContexts();
459 // On recupere tous les trihedrons de la GetMapOfAIS()
460 // et on active le mode de selection par face.
461 // =================================================
463 // Ouverture d'un contexte local et recuperation de son index.
464 TheAISContext()->OpenLocalContext(Standard_False);
465 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
470 Handle(AIS_InteractiveObject) ShapeA =
471 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
472 // On verifie que c'est bien un trihedron
473 if (!ShapeA.IsNull() &&
474 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
476 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
477 // on le charge dans le contexte et on active le mode Plane.
478 TheAISContext()->Load(TrihedronA,0,Standard_False);
479 TheAISContext()->Activate(TrihedronA,3);
484 di<<" Select a plane."<<"\n";
485 // Boucle d'attente waitpick.
486 Standard_Integer argccc = 5;
487 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
488 const char **argvvv = (const char **) bufff;
489 while (ViewerMainLoop( argccc, argvvv) ) { }
492 Handle(AIS_InteractiveObject) theIOB;
493 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
494 theIOB = TheAISContext()->Interactive();
497 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
499 // Fermeture du contexte local.
500 TheAISContext()->CloseLocalContext(myCurrentIndex);
502 // on le display & bind
503 TheAISContext()->Display(PlaneB );
504 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
511 //==============================================================================
512 // Fonction First click 2de click
514 // vaxis vertex vertex
516 // vaxispara edge vertex
517 // vaxisortho edge Vertex
518 // vaxisinter Face Face
519 //==============================================================================
521 //==============================================================================
522 //function : VAxisBuilder
524 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
525 //==============================================================================
526 #include <TopoDS_Edge.hxx>
527 #include <TopoDS_Vertex.hxx>
528 #include <TopExp.hxx>
529 #include <Geom_Line.hxx>
531 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
534 Standard_Boolean HasArg;
535 TCollection_AsciiString name;
536 Standard_Integer MyCurrentIndex;
539 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
540 if (argc==8) HasArg=Standard_True;
541 else HasArg=Standard_False;
544 // Fermeture des contextes
545 TheAISContext()->CloseAllContexts();
547 // Cas ou il y a des arguments
548 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
550 Standard_Real coord[6];
551 for(Standard_Integer i=0;i<=5;i++){
552 coord[i]=Draw::Atof(argv[2+i]);
554 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
556 gp_Vec myVect (p1,p2);
557 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
558 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
559 GetMapOfAIS().Bind (TheAxis,name);
560 TheAISContext()->Display(TheAxis);
566 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
567 if ( !strcasecmp(argv[0], "vaxis")) {
568 TheAISContext()->OpenLocalContext();
569 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
571 // Active le mode edge et le mode vertex
572 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
573 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
574 di<<" Select an edge or a vertex."<<"\n";
576 // Boucle d'attente waitpick.
577 Standard_Integer argcc = 5;
578 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
579 const char **argvv = (const char **) buff;
580 while (ViewerMainLoop( argcc, argvv) ) { }
583 // recuperation de la shape.
585 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
586 ShapeA = TheAISContext()->SelectedShape();
588 // recuperation de l'AIS_InteractiveObject
589 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
590 // down cast en AIS_Point si sig et type
591 // AIS_Point -> Geom_Pnt ....
593 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
594 // on desactive le mode edge
595 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
596 di<<" Select a different vertex."<<"\n";
600 // Boucle d'attente waitpick.
601 Standard_Integer argccc = 5;
602 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
603 const char **argvvv = (const char **) bufff;
604 while (ViewerMainLoop( argccc, argvvv) ) { }
606 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
607 ShapeB = TheAISContext()->SelectedShape();
611 } while(ShapeB.IsSame(ShapeA) );
613 // Fermeture du context local
614 TheAISContext()->CloseLocalContext(MyCurrentIndex);
616 // Construction de l'axe
617 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
618 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
621 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
622 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
623 GetMapOfAIS().Bind (TheAxis,name);
624 TheAISContext()->Display(TheAxis);
627 // Un unique edge (ShapeA) a ete picke
628 // Fermeture du context local
629 TheAISContext()->CloseLocalContext(MyCurrentIndex);
630 // Constuction de l'axe
631 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
633 TopExp::Vertices(ed,Va,Vb );
634 gp_Pnt A=BRep_Tool::Pnt(Va);
635 gp_Pnt B=BRep_Tool::Pnt(Vb);
638 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
639 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
640 GetMapOfAIS().Bind (TheAxis,name);
641 TheAISContext()->Display(TheAxis);
647 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
648 else if ( !strcasecmp(argv[0], "vaxispara")) {
650 TheAISContext()->OpenLocalContext();
651 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
653 // Active le mode edge
654 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
655 di<<" Select an edge."<<"\n";
657 // Boucle d'attente waitpick.
658 Standard_Integer argcc = 5;
659 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
660 const char **argvv = (const char **) buff;
661 while (ViewerMainLoop( argcc, argvv) ) { }
665 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
666 ShapeA = TheAISContext()->SelectedShape();
668 // Active le mode vertex et deactive edges
669 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
670 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
671 di<<" Select a vertex."<<"\n";
673 // Boucle d'attente waitpick.
674 Standard_Integer argccc = 5;
675 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
676 const char **argvvv = (const char **) bufff;
677 while (ViewerMainLoop( argccc, argvvv) ) { }
680 // On peut choisir un pnt sur l'edge
682 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
683 ShapeB = TheAISContext()->SelectedShape();
685 // Fermeture du context local
686 TheAISContext()->CloseLocalContext(MyCurrentIndex);
688 // Construction de l'axe
689 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
690 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
692 TopExp::Vertices(ed,Va,Vc );
693 gp_Pnt A=BRep_Tool::Pnt(Va);
694 gp_Pnt C=BRep_Tool::Pnt(Vc);
697 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
698 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
699 GetMapOfAIS().Bind (TheAxis,name);
700 TheAISContext()->Display(TheAxis);
704 // Fonction axisortho
706 TheAISContext()->OpenLocalContext();
707 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
709 // Active le mode edge
710 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
711 di<<" Select an edge."<<"\n";
713 // Boucle d'attente waitpick.
714 Standard_Integer argcc = 5;
715 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
716 const char **argvv = (const char **) buff;
717 while (ViewerMainLoop( argcc, argvv) ) { }
721 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
722 ShapeA = TheAISContext()->SelectedShape();
724 // Active le mode vertex et deactive edges
725 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
726 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
727 di<<" Slect a vertex."<<"\n";
729 // Boucle d'attente waitpick.
730 Standard_Integer argccc = 5;
731 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
732 const char **argvvv = (const char **) bufff;
733 while (ViewerMainLoop( argccc, argvvv) ) { }
736 // On peut choisir un pnt sur l'edge
738 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
739 ShapeB = TheAISContext()->SelectedShape();
741 // Fermeture du context local
742 TheAISContext()->CloseLocalContext(MyCurrentIndex);
744 // Construction de l'axe
745 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
746 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
748 TopExp::Vertices(ed,Va,Vc );
749 gp_Pnt A=BRep_Tool::Pnt(Va);
750 gp_Pnt C=BRep_Tool::Pnt(Vc);
751 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
754 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
755 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
756 GetMapOfAIS().Bind (TheAxis,name);
757 TheAISContext()->Display(TheAxis);
766 //==============================================================================
767 // Fonction First click Result
769 // vpoint vertex AIS_Point=Vertex
770 // edge AIS_Point=Middle of the edge
771 //==============================================================================
773 //==============================================================================
774 //function : VPointBuilder
775 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
776 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
777 //==============================================================================
778 #include <TopoDS_Edge.hxx>
779 #include <TopoDS_Vertex.hxx>
780 #include <TopExp.hxx>
781 #include <AIS_Point.hxx>
782 #include <Geom_CartesianPoint.hxx>
784 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
787 Standard_Boolean HasArg;
788 TCollection_AsciiString name;
789 Standard_Integer myCurrentIndex;
792 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
793 if (argc==5) HasArg=Standard_True;
794 else HasArg=Standard_False;
797 // Fermeture des contextes
798 TheAISContext()->CloseAllContexts();
800 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
802 Standard_Real thecoord[3];
803 for(Standard_Integer i=0;i<=2;i++)
804 thecoord[i]=Draw::Atof(argv[2+i]);
805 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
806 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
807 GetMapOfAIS().Bind (myAISPoint,name);
808 TheAISContext()->Display(myAISPoint);
811 // Il n'a pas d'arguments
813 TheAISContext()->OpenLocalContext();
814 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
816 // Active le mode Vertex et Edges
817 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
818 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
819 di<<" Select a vertex or an edge(build the middle)"<<"\n";
821 // Boucle d'attente waitpick.
822 Standard_Integer argcc = 5;
823 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
824 const char **argvv = (const char **) buff;
825 while (ViewerMainLoop( argcc, argvv) ) { }
829 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
830 ShapeA= TheAISContext()->SelectedShape();
833 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
834 // Un vertex a ete selectionne
835 // Fermeture du context local
836 TheAISContext()->CloseLocalContext(myCurrentIndex);
838 // Construction du point
839 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
840 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
841 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
842 GetMapOfAIS().Bind(myAISPoint,name);
843 TheAISContext()->Display(myAISPoint);
846 // Un Edge a ete selectionne
847 // Fermeture du context local
848 TheAISContext()->CloseLocalContext(myCurrentIndex);
850 // Construction du point milieu de l'edge
851 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
852 TopoDS_Vertex myVertexA,myVertexB;
853 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
854 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
855 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
856 // M est le milieu de [AB]
857 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
858 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
859 GetMapOfAIS().Bind(myAISPointM,name);
860 TheAISContext()->Display(myAISPointM);
868 //==============================================================================
869 // Function 1st click 2de click 3de click
870 // vplane Vertex Vertex Vertex
874 // vplanepara Face Vertex
876 // vplaneortho Face Edge
878 //==============================================================================
880 //==============================================================================
881 //function : VPlaneBuilder
882 //purpose : Build an AIS_Plane from selected entities or Named AIS components
883 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
884 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
885 // [PlaneName] [PointName] [TypeOfSensitivity]
886 //==============================================================================
888 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
889 Standard_Integer argc,
893 Standard_Boolean hasArg;
894 TCollection_AsciiString aName;
895 Standard_Integer aCurrentIndex;
898 if (argc<2 || argc>6 )
900 std::cout<<" Syntax error\n";
903 if (argc == 6 || argc==5 || argc==4)
904 hasArg=Standard_True;
906 hasArg=Standard_False;
909 // Close all contexts
910 TheAISContext()->CloseAllContexts();
912 // There are some arguments
915 if (!GetMapOfAIS().IsBound2(argv[2] ))
917 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
920 // Get shape from map
921 Handle(AIS_InteractiveObject) aShapeA =
922 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
924 // The first argument is an AIS_Point
925 if (!aShapeA.IsNull() &&
926 aShapeA->Type()==AIS_KOI_Datum &&
927 aShapeA->Signature()==1)
929 // The second argument must also be an AIS_Point
930 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
932 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
935 // Get shape from map
936 Handle(AIS_InteractiveObject) aShapeB =
937 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
938 // If B is not an AIS_Point
939 if (aShapeB.IsNull() ||
940 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
942 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
945 // The third object is an AIS_Point
946 if (!GetMapOfAIS().IsBound2(argv[4]) )
948 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
951 // Get shape from map
952 Handle(AIS_InteractiveObject) aShapeC =
953 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
954 // If C is not an AIS_Point
955 if (aShapeC.IsNull() ||
956 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
958 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
962 // Treatment of objects A, B, C
963 // Downcast an AIS_IO to AIS_Point
964 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
965 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
966 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
968 Handle(Geom_CartesianPoint ) aCartPointA =
969 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
971 Handle(Geom_CartesianPoint ) aCartPointB =
972 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
974 Handle(Geom_CartesianPoint ) aCartPointC =
975 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
977 // Verification that the three points are different
978 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
979 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
980 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
983 std::cout<<"vplane error: same points"<<"\n";return 1;
985 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
986 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
987 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
990 std::cout<<"vplane error: same points"<<"\n";return 1;
992 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
993 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
994 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
997 std::cout<<"vplane error: same points"<<"\n";return 1;
1000 gp_Pnt A = aCartPointA->Pnt();
1001 gp_Pnt B = aCartPointB->Pnt();
1002 gp_Pnt C = aCartPointC->Pnt();
1004 // Construction of AIS_Plane
1005 GC_MakePlane MkPlane (A,B,C);
1006 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1007 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1008 GetMapOfAIS().Bind (anAISPlane,aName );
1011 Standard_Integer aType = Draw::Atoi (argv[5]);
1012 if (aType != 0 && aType != 1)
1014 std::cout << "vplane error: wrong type of sensitivity!\n"
1015 << "Should be one of the following values:\n"
1023 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1026 TheAISContext()->Display(anAISPlane);
1029 // The first argument is an AIS_Axis
1030 // Creation of a plane orthogonal to the axis through a point
1031 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1032 // The second argument should be an AIS_Point
1033 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1035 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1038 // Get shape from map
1039 Handle(AIS_InteractiveObject) aShapeB =
1040 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1041 // If B is not an AIS_Point
1042 if (aShapeB.IsNull() ||
1043 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1045 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1049 // Treatment of objects A and B
1050 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1051 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1053 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1054 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1056 gp_Ax1 anAxis = aGeomLineA->Position();
1057 Handle(Geom_CartesianPoint) aCartPointB =
1058 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1060 gp_Dir D =anAxis.Direction();
1061 gp_Pnt B = aCartPointB->Pnt();
1063 // Construction of AIS_Plane
1064 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1065 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1066 GetMapOfAIS().Bind (anAISPlane,aName );
1069 Standard_Integer aType = Draw::Atoi (argv[4]);
1070 if (aType != 0 && aType != 1)
1072 std::cout << "vplane error: wrong type of sensitivity!\n"
1073 << "Should be one of the following values:\n"
1081 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1084 TheAISContext()->Display(anAISPlane);
1087 // The first argumnet is an AIS_Plane
1088 // Creation of a plane parallel to the plane passing through the point
1089 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1091 // The second argument should be an AIS_Point
1092 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1094 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1097 // Get shape from map
1098 Handle(AIS_InteractiveObject) aShapeB =
1099 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1100 // B should be an AIS_Point
1101 if (aShapeB.IsNull() ||
1102 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1104 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1108 // Treatment of objects A and B
1109 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1110 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1112 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1113 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1115 Handle(Geom_CartesianPoint) aCartPointB =
1116 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1117 gp_Pnt B= aCartPointB->Pnt();
1119 // Construction of an AIS_Plane
1120 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1121 GetMapOfAIS().Bind (anAISPlane, aName);
1124 Standard_Integer aType = Draw::Atoi (argv[4]);
1125 if (aType != 0 && aType != 1)
1127 std::cout << "vplane error: wrong type of sensitivity!\n"
1128 << "Should be one of the following values:\n"
1136 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1139 TheAISContext()->Display(anAISPlane);
1144 std::cout<<"vplane: error 1st object is not an AIS\n";
1148 // There are no arguments
1152 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1153 if (!strcasecmp(argv[0], "vplane"))
1155 TheAISContext()->OpenLocalContext();
1156 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1158 // Active modes Vertex, Edge and Face
1159 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1160 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1162 std::cout<<"Select a vertex, a face or an edge\n";
1165 Standard_Integer argcc = 5;
1166 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1167 const char **argvv = (const char **) buff;
1168 while (ViewerMainLoop( argcc, argvv) ) { }
1171 TopoDS_Shape aShapeA;
1172 for (TheAISContext()->InitSelected();
1173 TheAISContext()->MoreSelected();
1174 TheAISContext()->NextSelected())
1176 aShapeA = TheAISContext()->SelectedShape();
1179 // aShapeA is a Vertex
1180 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1182 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1183 std::cout<<" Select an edge or a different vertex\n";
1186 Standard_Integer argccc = 5;
1187 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1188 const char **argvvv = (const char **) bufff;
1189 while (ViewerMainLoop( argccc, argvvv) ) { }
1192 TopoDS_Shape aShapeB;
1193 for (TheAISContext()->InitSelected();
1194 TheAISContext()->MoreSelected();
1195 TheAISContext()->NextSelected())
1197 aShapeB = TheAISContext()->SelectedShape();
1199 // aShapeB is a Vertex
1200 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1202 // A and B are the same
1203 if (aShapeB.IsSame(aShapeA))
1205 std::cout<<" vplane: error, same points selected\n";
1208 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1209 std::cout<<" Select a different vertex\n";
1212 Standard_Integer argcccc = 5;
1213 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1214 const char **argvvvv = (const char **) buffff;
1215 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1218 TopoDS_Shape aShapeC;
1219 for (TheAISContext()->InitSelected();
1220 TheAISContext()->MoreSelected();
1221 TheAISContext()->NextSelected())
1223 aShapeC = TheAISContext()->SelectedShape();
1225 // aShapeC is the same as A or B
1226 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1228 std::cout<<" vplane: error, same points selected\n";
1232 // Close the local context
1233 TheAISContext()->CloseLocalContext(aCurrentIndex);
1235 // Construction of plane
1236 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1237 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1238 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1239 GC_MakePlane MkPlane(A, B, C);
1240 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1241 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1242 GetMapOfAIS().Bind (anAISPlane, aName);
1243 TheAISContext()->Display(anAISPlane);
1245 // ShapeB is an edge
1248 // Verify that the vertex is not on the edge ShapeB
1249 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1250 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1252 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1253 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1255 // The vertex is on the edge
1256 std::cout<<" vplane: error point is on the edge\n";
1261 // Close the local context
1262 TheAISContext()->CloseLocalContext(aCurrentIndex);
1263 // Construction of plane
1264 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1265 TopoDS_Vertex aVBa, aVBb;
1266 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1267 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1268 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1269 GC_MakePlane MkPlane (A, aBa, aBb);
1270 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1271 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1272 GetMapOfAIS().Bind (anAISPlane, aName);
1273 TheAISContext()->Display(anAISPlane);
1277 // aShapeA is an edge
1278 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1280 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1281 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1282 std::cout<<" Select a vertex that don't belong to the edge\n";
1285 Standard_Integer argccc = 5;
1286 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1287 const char **argvvv = (const char **) bufff;
1288 while (ViewerMainLoop( argccc, argvvv) ) { }
1291 TopoDS_Shape aShapeB;
1292 for (TheAISContext()->InitSelected();
1293 TheAISContext()->MoreSelected();
1294 TheAISContext()->NextSelected())
1296 aShapeB = TheAISContext()->SelectedShape();
1298 // aShapeB should be a Vertex
1299 // Check that the vertex aShapeB is not on the edge
1300 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1301 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1303 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1304 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1306 // The vertex is on the edge
1307 std::cout<<" vplane: error point is on the edge\n";
1312 // Close the local context
1313 TheAISContext()->CloseLocalContext(aCurrentIndex);
1314 // Construction of plane
1315 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1316 TopoDS_Vertex aVAa, aVAb;
1317 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1318 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1319 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1320 GC_MakePlane MkPlane (B,Aa,Ab);
1321 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1322 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1323 GetMapOfAIS().Bind (anAISPlane ,aName);
1324 TheAISContext()->Display(anAISPlane);
1327 // aShapeA is a Face
1330 // Close the local context: nothing to select
1331 TheAISContext()->CloseLocalContext(aCurrentIndex);
1332 // Construction of plane
1333 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1334 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1335 if (aSurface.GetType()==GeomAbs_Plane)
1337 gp_Pln aPlane = aSurface.Plane();
1338 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1339 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1340 GetMapOfAIS().Bind (anAISPlane, aName);
1341 TheAISContext()->Display(anAISPlane);
1345 std::cout<<" vplane: error\n";
1351 // Function vPlanePara
1352 // ===================
1353 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1354 else if (!strcasecmp(argv[0], "vplanepara"))
1356 TheAISContext()->OpenLocalContext();
1357 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1359 // Activate modes Vertex and Face
1360 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1361 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1362 std::cout<<" Select a vertex or a face\n";
1365 Standard_Integer argcc = 5;
1366 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1367 const char **argvv = (const char **) buff;
1368 while (ViewerMainLoop( argcc, argvv) ) { }
1371 TopoDS_Shape aShapeA;
1372 for (TheAISContext()->InitSelected();
1373 TheAISContext()->MoreSelected();
1374 TheAISContext()->NextSelected())
1376 aShapeA = TheAISContext()->SelectedShape();
1379 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1381 // aShapeA is a vertex
1382 // Deactivate the mode Vertex
1383 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1384 std::cout<<" Select a face\n";
1387 Standard_Integer argccc = 5;
1388 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1389 const char **argvvv = (const char **) bufff;
1390 while (ViewerMainLoop( argccc, argvvv) ) { }
1393 TopoDS_Shape aShapeB;
1394 for (TheAISContext()->InitSelected();
1395 TheAISContext()->MoreSelected();
1396 TheAISContext()->NextSelected())
1398 // A vertex ShapeA can be on Face ShapeB
1399 aShapeB = TheAISContext()->SelectedShape();
1402 // Close the local context
1403 TheAISContext()->CloseLocalContext(aCurrentIndex);
1405 // Construction of plane
1406 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1408 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1409 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1410 if (aSurface.GetType()==GeomAbs_Plane )
1412 gp_Pln aPlane = aSurface.Plane();
1413 // Construct a plane parallel to aGeomPlane through A
1414 aPlane.SetLocation(A);
1415 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1416 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1417 GetMapOfAIS().Bind (aAISPlane ,aName);
1418 TheAISContext()->Display(aAISPlane);
1422 std::cout<<" vplanepara: error\n";
1429 // Deactive the mode Face
1430 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1431 std::cout<<" Select a vertex\n";
1434 Standard_Integer argccc = 5;
1435 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1436 const char **argvvv = (const char **) bufff;
1437 while (ViewerMainLoop( argccc, argvvv) ) { }
1440 TopoDS_Shape aShapeB;
1441 for (TheAISContext()->InitSelected();
1442 TheAISContext()->MoreSelected();
1443 TheAISContext()->NextSelected())
1445 // A vertex ShapeB can be on Face ShapeA
1446 aShapeB = TheAISContext()->SelectedShape();
1448 // Close the local context
1449 TheAISContext()->CloseLocalContext(aCurrentIndex);
1451 // Construction of plane
1452 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1454 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1455 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1456 if (aSurface.GetType()==GeomAbs_Plane )
1458 gp_Pln aPlane = aSurface.Plane();
1459 aPlane.SetLocation(B);
1460 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1461 // Construct a plane parallel to aGeomPlane through B
1462 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1463 GetMapOfAIS().Bind (anAISPlane, aName);
1464 TheAISContext()->Display(anAISPlane);
1468 std::cout<<" vplanepara: error"<<"\n";return 1;
1473 // Function vplaneortho
1474 // ====================
1475 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1478 TheAISContext()->OpenLocalContext();
1479 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1481 // Activate the modes Edge and Face
1482 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1483 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1484 std::cout<<" Select a face and an edge coplanar\n";
1487 Standard_Integer argcc = 5;
1488 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1489 const char **argvv = (const char **) buff;
1490 while (ViewerMainLoop( argcc, argvv) ) { }
1493 TopoDS_Shape aShapeA;
1494 for (TheAISContext()->InitSelected();
1495 TheAISContext()->MoreSelected();
1496 TheAISContext()->NextSelected())
1498 aShapeA = TheAISContext()->SelectedShape();
1501 if (aShapeA.ShapeType()==TopAbs_EDGE )
1503 // ShapeA is an edge, deactivate the mode Edge...
1504 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1505 std::cout<<" Select a face\n";
1508 Standard_Integer argccc = 5;
1509 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1510 const char **argvvv = (const char **) bufff;
1511 while (ViewerMainLoop( argccc, argvvv) ) { }
1514 TopoDS_Shape aShapeB;
1515 for (TheAISContext()->InitSelected();
1516 TheAISContext()->MoreSelected();
1517 TheAISContext()->NextSelected())
1519 // Edge ShapeA can be on Face ShapeB
1520 aShapeB = TheAISContext()->SelectedShape();
1523 // Close the local context
1524 TheAISContext()->CloseLocalContext(aCurrentIndex);
1526 // Construction of plane
1527 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1528 TopoDS_Vertex aVAa, aVAb;
1529 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1530 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1531 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1535 // Creation of rotation axis
1536 gp_Ax1 aRotAxis (Aa,Dab);
1538 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1539 // The edge must be parallel to the face
1540 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1541 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1542 // Compare to heights
1543 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1544 >Precision::Confusion())
1546 // the edge is not parallel to the face
1547 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1551 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1552 if (aSurface.GetType()==GeomAbs_Plane)
1554 gp_Pln aPlane = aSurface.Plane();
1555 // It rotates a half turn round the axis of rotation
1556 aPlane.Rotate(aRotAxis , M_PI/2);
1558 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1559 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1560 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1561 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1562 GetMapOfAIS().Bind (anAISPlane, aName);
1563 TheAISContext()->Display(anAISPlane);
1567 std::cout<<" vplaneortho: error\n";
1573 // ShapeA is a Face, deactive the mode Face.
1574 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1575 std::cout<<" Select an edge\n";
1578 Standard_Integer argccc = 5;
1579 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1580 const char **argvvv = (const char **) bufff;
1581 while (ViewerMainLoop( argccc, argvvv) ) { }
1584 TopoDS_Shape aShapeB;
1585 for (TheAISContext()->InitSelected();
1586 TheAISContext()->MoreSelected();
1587 TheAISContext()->NextSelected())
1589 // Edge ShapeB can be on Face ShapeA
1590 aShapeB = TheAISContext()->SelectedShape();
1592 // Close the local context
1593 TheAISContext()->CloseLocalContext(aCurrentIndex);
1595 // Construction of plane
1596 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1597 TopoDS_Vertex aVBa, aVBb;
1598 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1599 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1600 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1601 gp_Vec ab (aBa,aBb);
1603 // Creation of rotation axe
1604 gp_Ax1 aRotAxis (aBa,Dab);
1606 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1607 // The edge must be parallel to the face
1608 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1609 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1610 // Comparing the two heights
1611 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1612 >Precision::Confusion())
1614 // the edge is not parallel to the face
1615 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1619 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1620 if (aSurface.GetType()==GeomAbs_Plane)
1622 gp_Pln aPlane = aSurface.Plane();
1623 // It rotates a half turn round the axis of rotation
1624 aPlane.Rotate(aRotAxis , M_PI/2);
1625 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1626 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1627 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1628 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1629 GetMapOfAIS().Bind (anAISPlane ,aName);
1630 TheAISContext()->Display(anAISPlane);
1634 std::cout<<" vplaneortho: error\n";
1643 //===============================================================================================
1644 //function : VChangePlane
1646 //===============================================================================================
1647 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1649 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1650 if (aContextAIS.IsNull())
1652 std::cout << theArgVec[0] << "AIS context is not available.\n";
1656 if (theArgsNb < 3 || theArgsNb > 11)
1658 std::cerr << theArgVec[0]
1659 << ": incorrect number of command arguments.\n"
1660 << "Type help for more information.\n";
1664 TCollection_AsciiString aName (theArgVec[1]);
1666 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1667 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1670 if ( aPlane.IsNull() )
1672 std::cout << theArgVec[0]
1673 << ": there is no interactive plane with the given name."
1674 << "Type help for more information.\n";
1678 Standard_Real aCenterX = aPlane->Center().X();
1679 Standard_Real aCenterY = aPlane->Center().Y();
1680 Standard_Real aCenterZ = aPlane->Center().Z();
1682 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1683 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1684 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1686 Standard_Real aSizeX = 0.0;
1687 Standard_Real aSizeY = 0.0;
1688 aPlane->Size (aSizeX, aSizeY);
1689 Standard_Boolean isUpdate = Standard_True;
1691 TCollection_AsciiString aPName, aPValue;
1692 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1694 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1695 TCollection_AsciiString anArgCase = anArg;
1696 anArgCase.UpperCase();
1697 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1700 if (aPName.IsEqual ("X"))
1702 aCenterX = aPValue.RealValue();
1704 else if (aPName.IsEqual ("Y"))
1706 aCenterY = aPValue.RealValue();
1708 else if (aPName.IsEqual ("Z"))
1710 aCenterZ = aPValue.RealValue();
1712 else if (aPName.IsEqual ("DX"))
1714 aDirX = aPValue.RealValue();
1716 else if (aPName.IsEqual ("DY"))
1718 aDirY = aPValue.RealValue();
1720 else if (aPName.IsEqual ("DZ"))
1722 aDirZ = aPValue.RealValue();
1724 else if (aPName.IsEqual ("SX"))
1726 aSizeX = aPValue.RealValue();
1728 else if (aPName.IsEqual ("SY"))
1730 aSizeY = aPValue.RealValue();
1733 else if (anArg.IsEqual ("NOUPDATE"))
1735 isUpdate = Standard_False;
1739 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1740 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1741 aPlane->SetCenter (aCenterPnt);
1742 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1743 aPlane->SetSize (aSizeX, aSizeY);
1747 aContextAIS->Update (aPlane, Standard_True);
1753 //==============================================================================
1755 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1756 //==============================================================================
1758 //==============================================================================
1759 //function : VLineBuilder
1760 //purpose : Build an AIS_Line
1761 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1762 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1763 //==============================================================================
1764 #include <Geom_CartesianPoint.hxx>
1765 #include <AIS_Line.hxx>
1768 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1770 Standard_Integer myCurrentIndex;
1772 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1773 // Fermeture des contextes
1774 TheAISContext()->CloseAllContexts();
1776 // On recupere les parametres
1777 Handle(AIS_InteractiveObject) theShapeA;
1778 Handle(AIS_InteractiveObject) theShapeB;
1780 // Parametres: AIS_Point AIS_Point
1781 // ===============================
1784 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1785 // On verifie que c'est bien une AIS_Point
1786 if (!theShapeA.IsNull() &&
1787 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1788 // on recupere le deuxieme AIS_Point
1790 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1791 if (theShapeA.IsNull() ||
1792 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1794 di <<"vline error: wrong type of 2de argument."<<"\n";
1798 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
1799 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1801 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1803 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1804 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1805 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1807 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1808 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1809 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1811 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1813 di<<"vline error: same points"<<"\n";return 1;
1815 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817 GetMapOfAIS().Bind(theAISLine,argv[1] );
1818 TheAISContext()->Display(theAISLine );
1822 // Parametres 6 Reals
1823 // ==================
1826 // On verifie que les deux points ne sont pas confondus
1828 Standard_Real coord[6];
1829 for(Standard_Integer i=0;i<=2;i++){
1830 coord[i]=Draw::Atof(argv[2+i]);
1831 coord[i+3]=Draw::Atof(argv[5+i]);
1834 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1837 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838 GetMapOfAIS().Bind(theAISLine,argv[1] );
1839 TheAISContext()->Display(theAISLine );
1843 // Pas de parametres: Selection dans le viewer.
1844 // ============================================
1847 TheAISContext()->OpenLocalContext();
1848 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1850 // Active le mode Vertex.
1851 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1852 di<<" Select a vertex "<<"\n";
1854 // Boucle d'attente waitpick.
1855 Standard_Integer argcc = 5;
1856 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1857 const char **argvv = (const char **) buff;
1858 while (ViewerMainLoop( argcc, argvv) ) { }
1861 TopoDS_Shape ShapeA;
1862 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1863 ShapeA = TheAISContext()->SelectedShape();
1866 // ShapeA est un Vertex
1867 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1869 di<<" Select a different vertex."<<"\n";
1871 TopoDS_Shape ShapeB;
1874 // Boucle d'attente waitpick.
1875 Standard_Integer argccc = 5;
1876 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1877 const char **argvvv = (const char **) bufff;
1878 while (ViewerMainLoop( argccc, argvvv) ) { }
1881 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1882 ShapeB = TheAISContext()->SelectedShape();
1886 } while(ShapeB.IsSame(ShapeA) );
1888 // Fermeture du context local
1889 TheAISContext()->CloseLocalContext(myCurrentIndex);
1891 // Construction de la line
1892 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1893 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1895 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1896 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1898 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1899 GetMapOfAIS().Bind(theAISLine,argv[1] );
1900 TheAISContext()->Display(theAISLine );
1904 di<<"vline error."<<"\n";
1912 //==============================================================================
1913 // class : FilledCircle
1914 // purpose : creates filled circle based on AIS_InteractiveObject
1916 // This class is used to check method Matches() of class
1917 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1918 // because none of AIS classes provides creation of
1919 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
1920 // (look method ComputeSelection() )
1921 //==============================================================================
1923 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1925 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1926 gp_Circ aCirc(anAxes, theRadius);
1927 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1931 DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1933 class FilledCircle : public AIS_InteractiveObject
1937 DEFINE_STANDARD_RTTI(FilledCircle);
1939 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1940 FilledCircle(Handle(Geom_Circle) theCircle);
1943 TopoDS_Face ComputeFace();
1945 // Virtual methods implementation
1946 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1947 const Handle(Prs3d_Presentation)& thePresentation,
1948 const Standard_Integer theMode);
1950 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1951 const Standard_Integer theMode);
1954 Handle(Geom_Circle) myCircle;
1955 Standard_Boolean myFilledStatus;
1959 IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1960 IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1962 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1964 myCircle = CreateCircle(theCenter, theRadius);
1965 myFilledStatus = Standard_True;
1968 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1970 myCircle = theCircle;
1971 myFilledStatus = Standard_True;
1974 TopoDS_Face FilledCircle::ComputeFace()
1976 // Create edge from myCircle
1977 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1978 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1980 // Create wire from anEdge
1981 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1982 TopoDS_Wire aWire = aWireMaker.Wire();
1984 // Create face from aWire
1985 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1986 TopoDS_Face aFace = aFaceMaker.Face();
1991 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1992 const Handle(Prs3d_Presentation) &thePresentation,
1993 const Standard_Integer theMode)
1995 thePresentation->Clear();
1997 TopoDS_Face aFace = ComputeFace();
1999 if (aFace.IsNull()) return;
2000 if (theMode != 0) return;
2002 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2005 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2006 const Standard_Integer /*theMode*/)
2008 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2009 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2010 myCircle, myFilledStatus);
2011 theSelection->Add(aSensitiveCircle);
2014 //==============================================================================
2016 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2017 //==============================================================================
2019 //==============================================================================
2020 //function : VCircleBuilder
2021 //purpose : Build an AIS_Circle
2022 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2023 // PointName PointName PointName IsFilled
2024 //==============================================================================
2026 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2027 TCollection_AsciiString theName,
2028 Standard_Boolean isFilled)
2030 Handle(AIS_InteractiveObject) aCircle;
2033 aCircle = new FilledCircle(theGeomCircle);
2037 aCircle = new AIS_Circle(theGeomCircle);
2038 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2041 // Check if there is an object with given name
2042 // and remove it from context
2043 if (GetMapOfAIS().IsBound2(theName))
2045 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2046 Handle(AIS_InteractiveObject) anInterObj =
2047 Handle(AIS_InteractiveObject)::DownCast(anObj);
2048 TheAISContext()->Remove(anInterObj, Standard_False);
2049 GetMapOfAIS().UnBind2(theName);
2052 // Bind the circle to its name
2053 GetMapOfAIS().Bind(aCircle, theName);
2055 // Display the circle
2056 TheAISContext()->Display(aCircle);
2060 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2062 Standard_Integer myCurrentIndex;
2063 // Verification of the arguments
2064 if (argc>6 || argc<2)
2066 std::cout << "vcircle error: expect 4 arguments.\n";
2067 return 1; // TCL_ERROR
2069 TheAISContext()->CloseAllContexts();
2071 // There are all arguments
2075 TCollection_AsciiString aName(argv[1]);
2076 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2078 Handle(AIS_InteractiveObject) theShapeA;
2079 Handle(AIS_InteractiveObject) theShapeB;
2082 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2084 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2087 // Arguments: AIS_Point AIS_Point AIS_Point
2088 // ========================================
2089 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2090 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2092 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2094 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2095 return 1; // TCL_ERROR
2097 // The third object must be a point
2098 Handle(AIS_InteractiveObject) theShapeC =
2099 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2100 if (theShapeC.IsNull() ||
2101 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2103 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2104 return 1; // TCL_ERROR
2107 // Verify that the three points are different
2108 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2109 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2110 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2112 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2113 Handle(Geom_CartesianPoint) myCartPointA =
2114 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2116 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2117 Handle(Geom_CartesianPoint) myCartPointB =
2118 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2120 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2121 Handle(Geom_CartesianPoint) myCartPointC =
2122 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2125 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2126 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2127 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2129 std::cout << "vcircle error: Same points.\n";
2130 return 1; // TCL_ERROR
2133 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2134 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2135 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2137 std::cout << "vcircle error: Same points.\n";
2138 return 1; // TCL_ERROR
2141 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2142 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2143 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2145 std::cout << "vcircle error: Same points.\n";
2146 return 1;// TCL_ERROR
2148 // Construction of the circle
2149 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2150 myCartPointB->Pnt(), myCartPointC->Pnt() );
2151 Handle (Geom_Circle) theGeomCircle;
2154 theGeomCircle = Cir.Value();
2156 catch (StdFail_NotDone)
2158 std::cout << "vcircle error: can't create circle\n";
2159 return -1; // TCL_ERROR
2162 DisplayCircle(theGeomCircle, aName, isFilled);
2165 // Arguments: AIS_Plane AIS_Point Real
2166 // ===================================
2167 else if (theShapeA->Type() == AIS_KOI_Datum &&
2168 theShapeA->Signature() == 7 )
2170 if (theShapeB->Type() != AIS_KOI_Datum ||
2171 theShapeB->Signature() != 1 )
2173 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2174 return 1; // TCL_ERROR
2176 // Check that the radius is >= 0
2177 if (Draw::Atof(argv[4]) <= 0 )
2179 std::cout << "vcircle error: the radius must be >=0.\n";
2180 return 1; // TCL_ERROR
2183 // Recover the normal to the plane
2184 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2185 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2187 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2188 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2189 Handle(Geom_CartesianPoint) myCartPointB =
2190 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2192 gp_Pln mygpPlane = myGeomPlane->Pln();
2193 gp_Ax1 thegpAxe = mygpPlane.Axis();
2194 gp_Dir theDir = thegpAxe.Direction();
2195 gp_Pnt theCenter = myCartPointB->Pnt();
2196 Standard_Real TheR = Draw::Atof(argv[4]);
2197 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2198 Handle (Geom_Circle) theGeomCircle;
2201 theGeomCircle = Cir.Value();
2203 catch (StdFail_NotDone)
2205 std::cout << "vcircle error: can't create circle\n";
2206 return -1; // TCL_ERROR
2209 DisplayCircle(theGeomCircle, aName, isFilled);
2216 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2217 return 1; // TCL_ERROR
2221 // No arguments: selection in the viewer
2222 // =========================================
2225 // Get the name of the circle
2226 TCollection_AsciiString aName(argv[1]);
2228 TheAISContext()->OpenLocalContext();
2229 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2231 // Activate selection mode for vertices and faces
2232 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2233 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2234 std::cout << " Select a vertex or a face\n";
2237 Standard_Integer argcc = 5;
2238 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2239 const char **argvv = (const char **) buff;
2240 while (ViewerMainLoop( argcc, argvv) ) { }
2243 TopoDS_Shape ShapeA;
2244 for(TheAISContext()->InitSelected();
2245 TheAISContext()->MoreSelected();
2246 TheAISContext()->NextSelected() )
2248 ShapeA = TheAISContext()->SelectedShape();
2251 // ShapeA is a Vertex
2252 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2254 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2255 std::cout << " Select a different vertex\n";
2257 TopoDS_Shape ShapeB;
2261 Standard_Integer argccc = 5;
2262 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2263 const char **argvvv = (const char **) bufff;
2264 while (ViewerMainLoop( argccc, argvvv) ) { }
2267 for(TheAISContext()->InitSelected();
2268 TheAISContext()->MoreSelected();
2269 TheAISContext()->NextSelected() )
2271 ShapeB = TheAISContext()->SelectedShape();
2273 } while(ShapeB.IsSame(ShapeA) );
2275 // Selection of ShapeC
2276 std::cout << " Select the last vertex\n";
2277 TopoDS_Shape ShapeC;
2281 Standard_Integer argcccc = 5;
2282 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2283 const char **argvvvv = (const char **) buffff;
2284 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2287 for(TheAISContext()->InitSelected();
2288 TheAISContext()->MoreSelected();
2289 TheAISContext()->NextSelected() )
2291 ShapeC = TheAISContext()->SelectedShape();
2293 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2296 Standard_Boolean isFilled;
2297 std::cout << "Enter filled status (0 or 1)\n";
2300 // Close the local context
2301 TheAISContext()->CloseLocalContext(myCurrentIndex);
2303 // Construction of the circle
2304 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2305 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2306 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2308 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2309 Handle (Geom_Circle) theGeomCircle;
2312 theGeomCircle = Cir.Value();
2314 catch (StdFail_NotDone)
2316 std::cout << "vcircle error: can't create circle\n";
2317 return -1; // TCL_ERROR
2320 DisplayCircle(theGeomCircle, aName, isFilled);
2326 std::cout << " Select a vertex (in your face)\n";
2327 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2329 TopoDS_Shape ShapeB;
2331 Standard_Integer argccc = 5;
2332 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2333 const char **argvvv = (const char **) bufff;
2334 while (ViewerMainLoop( argccc, argvvv) ) { }
2337 for(TheAISContext()->InitSelected();
2338 TheAISContext()->MoreSelected();
2339 TheAISContext()->NextSelected() )
2341 ShapeB = TheAISContext()->SelectedShape();
2344 // Recover the radius
2345 Standard_Real theRad;
2348 std::cout << " Enter the value of the radius:\n";
2350 } while (theRad <= 0);
2352 // Get filled status
2353 Standard_Boolean isFilled;
2354 std::cout << "Enter filled status (0 or 1)\n";
2357 // Close the local context
2358 TheAISContext()->CloseLocalContext(myCurrentIndex);
2359 // Construction of the circle
2361 // Recover the normal to the plane. tag
2362 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2363 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2364 gp_Pln myPlane = mySurface.Plane();
2365 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2366 gp_Pln mygpPlane = theGeomPlane->Pln();
2367 gp_Ax1 thegpAxe = mygpPlane.Axis();
2368 gp_Dir theDir = thegpAxe.Direction();
2370 // Recover the center
2371 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2373 // Construct the circle
2374 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2375 Handle (Geom_Circle) theGeomCircle;
2378 theGeomCircle = Cir.Value();
2380 catch (StdFail_NotDone)
2382 std::cout << "vcircle error: can't create circle\n";
2383 return -1; // TCL_ERROR
2386 DisplayCircle(theGeomCircle, aName, isFilled);
2396 //===============================================================================================
2397 //function : VDrawText
2399 //purpose : Create a text.
2400 //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2401 //===============================================================================================
2402 #include <Graphic3d_Group.hxx>
2403 #include <Graphic3d_Structure.hxx>
2404 #include <Graphic3d_AspectText3d.hxx>
2405 #include <Graphic3d_AspectFillArea3d.hxx>
2406 #include <Graphic3d_StructureManager.hxx>
2407 #include <Graphic3d_VerticalTextAlignment.hxx>
2408 #include <Graphic3d_HorizontalTextAlignment.hxx>
2410 #include <Font_NameOfFont.hxx>
2412 #include <Visual3d_ViewManager.hxx>
2414 #include <Standard_DefineHandle.hxx>
2416 #include <Prs3d_Root.hxx>
2417 #include <Prs3d_Text.hxx>
2418 #include <Prs3d_TextAspect.hxx>
2419 #include <Prs3d_ShadingAspect.hxx>
2420 #include <PrsMgr_PresentationManager3d.hxx>
2422 #include <TCollection_ExtendedString.hxx>
2423 #include <TCollection_AsciiString.hxx>
2425 #include <gp_Pnt.hxx>
2426 #include <Quantity_NameOfColor.hxx>
2427 #include <Quantity_Color.hxx>
2430 DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2432 class MyTextClass:public AIS_InteractiveObject
2436 DEFINE_STANDARD_RTTI(MyTextClass );
2442 const TCollection_ExtendedString& , const gp_Pnt& ,
2443 Quantity_Color color,
2444 Standard_Integer aHJust,
2445 Standard_Integer aVJust ,
2446 Standard_Real Angle ,
2447 Standard_Boolean Zoom ,
2448 Standard_Real Height,
2449 Font_FontAspect FontAspect,
2450 Standard_CString Font
2455 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2456 const Handle(Prs3d_Presentation)& aPresentation,
2457 const Standard_Integer aMode);
2459 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2460 const Standard_Integer /*aMode*/){} ;
2463 TCollection_ExtendedString aText;
2466 Standard_Real Green;
2468 Standard_Real aAngle;
2469 Standard_Real aHeight;
2470 Standard_Boolean aZoomable;
2471 Quantity_Color aColor;
2472 TCollection_AsciiString aFont;
2473 Font_FontAspect aFontAspect;
2474 Graphic3d_HorizontalTextAlignment aHJustification;
2475 Graphic3d_VerticalTextAlignment aVJustification;
2480 IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2481 IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
2484 MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2485 Quantity_Color color = Quantity_NOC_YELLOW,
2486 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
2487 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2488 Standard_Real angle = 0.0 ,
2489 Standard_Boolean zoomable = Standard_True,
2490 Standard_Real height = 12.,
2491 Font_FontAspect fontAspect = Font_FA_Regular,
2492 Standard_CString font = "Courier")
2495 aPosition = position;
2496 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2497 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2499 aZoomable = zoomable;
2502 aFontAspect = fontAspect;
2508 //////////////////////////////////////////////////////////////////////////////
2509 void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
2510 const Handle(Prs3d_Presentation)& aPresentation,
2511 const Standard_Integer /*aMode*/)
2514 aPresentation->Clear();
2516 Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect();
2518 asp->SetFont(aFont.ToCString());
2519 asp->SetColor(aColor);
2520 asp->SetHeight(aHeight); // I am changing the myHeight value
2522 asp->SetHorizontalJustification(aHJustification);
2523 asp->SetVerticalJustification(aVJustification);
2524 asp->Aspect()->SetTextZoomable(aZoomable);
2525 asp->Aspect()->SetTextAngle(aAngle);
2526 asp->Aspect()->SetTextFontAspect(aFontAspect);
2527 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
2529 /* This comment code is worked
2530 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2531 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2532 Graphic3d_Vertex vertices_text;
2533 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2534 TheGroup->SetPrimitivesAspect(aspect);
2535 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
2539 static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2544 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2545 di<<"Usage: type help "<<argv[0]<<"\n";
2546 return 1; //TCL_ERROR
2549 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2551 // Create 3D view if it doesn't exist
2552 if ( aContext.IsNull() )
2554 ViewerTest::ViewerInit();
2555 aContext = ViewerTest::GetAISContext();
2556 if( aContext.IsNull() )
2558 di << "Error: Cannot create a 3D view\n";
2559 return 1; //TCL_ERROR
2564 const Standard_Real X = Draw::Atof(argv[2]);
2565 const Standard_Real Y = Draw::Atof(argv[3]);
2566 const Standard_Real Z = Draw::Atof(argv[4]);
2567 const gp_Pnt pnt(X,Y,Z);
2570 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2571 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2572 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
2573 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
2576 const int hor_align = Draw::Atoi(argv[8]);
2577 const int ver_align = Draw::Atoi(argv[9]);
2580 const Standard_Real angle = Draw::Atof(argv[10]);
2583 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
2586 const Standard_Real height = Draw::Atof(argv[12]);
2589 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
2592 TCollection_AsciiString font;
2594 font.AssignCat("Courier");
2596 font.AssignCat(argv[14]);
2598 // Text is multibyte
2599 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
2602 TCollection_ExtendedString name;
2605 const char *str = argv[1];
2606 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2607 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
2609 unsigned short c1 = *str++;
2610 unsigned short c2 = *str++;
2612 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2622 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2623 aContext->Display(myT,Standard_True);
2630 #include <gp_Pnt.hxx>
2631 #include <Graphic3d_ArrayOfPoints.hxx>
2632 #include <Graphic3d_ArrayOfPrimitives.hxx>
2633 #include <Graphic3d_ArrayOfTriangles.hxx>
2634 #include <Poly_Array1OfTriangle.hxx>
2635 #include <Poly_Triangle.hxx>
2636 #include <Poly_Triangulation.hxx>
2637 #include <TColgp_Array1OfPnt.hxx>
2638 #include <TShort_Array1OfShortReal.hxx>
2639 #include <TShort_HArray1OfShortReal.hxx>
2641 #include <AIS_Triangulation.hxx>
2642 #include <StdPrs_ToolShadedShape.hxx>
2643 #include <Poly_Connect.hxx>
2644 #include <TColgp_Array1OfDir.hxx>
2645 #include <Graphic3d_GraphicDriver.hxx>
2647 #include <TColStd_Array1OfInteger.hxx>
2648 #include <TColStd_HArray1OfInteger.hxx>
2649 #include <Prs3d_ShadingAspect.hxx>
2650 #include <Graphic3d_MaterialAspect.hxx>
2651 #include <Graphic3d_AspectFillArea3d.hxx>
2653 #include <BRepPrimAPI_MakeCylinder.hxx>
2654 #include <TopoDS_Shape.hxx>
2655 #include <TopExp_Explorer.hxx>
2656 #include <TopAbs.hxx>
2657 #include <StdSelect_ShapeTypeFilter.hxx>
2660 //===============================================================================================
2661 //function : CalculationOfSphere
2663 //purpose : Create a Sphere
2664 //===============================================================================================
2666 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2669 double mRadius = Radius;
2670 double mCenter[3] = {X,Y,Z};
2671 int mThetaResolution;
2673 double mStartTheta = 0;//StartTheta;
2674 double mEndTheta = 360;//EndTheta;
2675 double mStartPhi = 0;//StartPhi;
2676 double mEndPhi = 180;//EndPhi;
2677 res = res < 4 ? 4 : res;
2679 mThetaResolution = res;
2680 mPhiResolution = res;
2683 int jStart, jEnd, numOffset;
2684 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2685 double startTheta, endTheta, startPhi, endPhi;
2686 int base, numPoles=0, thetaResolution, phiResolution;
2691 if ( numPieces > mThetaResolution ) {
2692 numPieces = mThetaResolution;
2695 int localThetaResolution = mThetaResolution;
2696 double localStartTheta = mStartTheta;
2697 double localEndTheta = mEndTheta;
2699 while ( localEndTheta < localStartTheta ) {
2700 localEndTheta += 360.0;
2703 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2705 // Change the ivars based on pieces.
2707 start = piece * localThetaResolution / numPieces;
2708 end = (piece+1) * localThetaResolution / numPieces;
2709 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2710 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2711 localThetaResolution = end - start;
2713 // Create north pole if needed
2714 int number_point = 0;
2715 int number_pointArray = 0;
2717 if ( mStartPhi <= 0.0 ) {
2718 number_pointArray++;
2721 if ( mEndPhi >= 180.0 ) {
2722 number_pointArray++;
2726 // Check data, determine increments, and convert to radians
2727 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2728 startTheta *= M_PI / 180.0;
2729 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2730 endTheta *= M_PI / 180.0;
2733 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2734 startPhi *= M_PI / 180.0;
2735 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2736 endPhi *= M_PI / 180.0;
2738 phiResolution = mPhiResolution - numPoles;
2739 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2740 thetaResolution = localThetaResolution;
2741 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2742 ++localThetaResolution;
2744 deltaTheta = (endTheta - startTheta) / thetaResolution;
2746 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2747 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2749 // Create intermediate points
2750 for ( i = 0; i < localThetaResolution; i++ ) {
2751 for ( j = jStart; j < jEnd; j++ ) {
2752 number_pointArray++;
2756 //Generate mesh connectivity
2757 base = phiResolution * localThetaResolution;
2759 int number_triangle = 0 ;
2760 if ( mStartPhi <= 0.0 ) { // around north pole
2761 number_triangle += localThetaResolution;
2764 if ( mEndPhi >= 180.0 ) { // around south pole
2765 number_triangle += localThetaResolution;
2768 // bands in-between poles
2769 for ( i=0; i < localThetaResolution; i++){
2770 for ( j=0; j < (phiResolution-1); j++){
2771 number_triangle +=2;
2775 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2776 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2777 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2779 if ( mStartPhi <= 0.0 ){
2782 x[2] = mCenter[2] + mRadius;
2783 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2786 // Create south pole if needed
2787 if ( mEndPhi >= 180.0 ){
2790 x[2] = mCenter[2] - mRadius;
2791 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2795 for ( i=0; i < localThetaResolution; i++){
2796 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
2797 for ( j = jStart; j < jEnd; j++){
2798 phi = startPhi + j*deltaPhi;
2799 radius = mRadius * sin((double)phi);
2800 n[0] = radius * cos((double)theta);
2801 n[1] = radius * sin((double)theta);
2802 n[2] = mRadius * cos((double)phi);
2803 x[0] = n[0] + mCenter[0];
2804 x[1] = n[1] + mCenter[1];
2805 x[2] = n[2] + mCenter[2];
2806 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2812 number_triangle = 1;
2813 if ( mStartPhi <= 0.0 ){// around north pole
2814 for (i=0; i < localThetaResolution; i++){
2815 pts[0] = phiResolution*i + numPoles;
2816 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2818 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2823 if ( mEndPhi >= 180.0 ){ // around south pole
2824 numOffset = phiResolution - 1 + numPoles;
2825 for (i=0; i < localThetaResolution; i++){
2826 pts[0] = phiResolution*i + numOffset;
2827 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2828 pts[1] = numPoles - 1;
2829 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2834 // bands in-between poles
2836 for (i=0; i < localThetaResolution; i++){
2837 for (j=0; j < (phiResolution-1); j++){
2838 pts[0] = phiResolution*i + j + numPoles;
2839 pts[1] = pts[0] + 1;
2840 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2841 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2844 pts[2] = pts[1] - 1;
2845 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2850 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2852 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2854 Standard_Integer index[3];
2855 Standard_Real Tol = Precision::Confusion();
2858 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2859 gp_XYZ eqPlan(0, 0, 0);
2860 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2861 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2862 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2863 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2865 Standard_Real mod = vv.Modulus();
2866 if(mod < Tol) continue;
2870 Standard_Real modmax = eqPlan.Modulus();
2873 Nor = gp_Dir(eqPlan);
2875 Nor = gp_Dir(0., 0., 1.);
2877 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2878 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2879 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2880 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2884 polyTriangulation->SetNormals(Normals);
2886 return polyTriangulation;
2889 //===============================================================================================
2890 //function : VDrawSphere
2892 //purpose : Create an AIS shape.
2893 //===============================================================================================
2894 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2897 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2898 if (aContextAIS.IsNull())
2900 std::cout << "Call vinit before!\n";
2905 std::cout << "Use: " << argv[0]
2906 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
2910 // read the arguments
2911 TCollection_AsciiString aShapeName (argv[1]);
2912 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2913 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2914 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2915 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2916 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
2917 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2918 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
2920 // remove AIS object with given name from map
2921 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
2924 std::cout << "Compute Triangulation...\n";
2925 Handle(AIS_Triangulation) aShape
2926 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2929 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2930 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2932 // stupid initialization of Green color in RGBA space as integer
2933 // probably wrong for big-endian CPUs
2934 Standard_Integer aRed = 0;
2935 Standard_Integer aGreen = 255;
2936 Standard_Integer aBlue = 0;
2937 Standard_Integer anAlpha = 0; // not used
2938 Standard_Integer aColorInt = aRed;
2939 aColorInt += aGreen << 8;
2940 aColorInt += aBlue << 16;
2941 aColorInt += anAlpha << 24;
2943 // setup colors array per vertex
2944 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2945 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2947 aColorArray->SetValue (aNodeId, aColorInt);
2949 aShape->SetColors (aColorArray);
2952 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2953 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2954 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2955 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2956 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2957 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2958 aTotalSize >>= 20; //MB
2959 aNormalsSize >>= 20;
2961 aTrianglesSize >>= 20;
2962 aPolyConnectSize >>= 20;
2965 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2966 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2967 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2968 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2969 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2970 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2973 // Setting material properties, very important for desirable visual result!
2974 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2975 aMat.SetAmbient (0.2);
2976 aMat.SetSpecular (0.5);
2977 Handle(Graphic3d_AspectFillArea3d) anAspect
2978 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2980 Quantity_NOC_YELLOW,
2985 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
2988 anAspect->SetEdgeOn();
2992 anAspect->SetEdgeOff();
2994 aShAsp->SetAspect (anAspect);
2995 aShape->Attributes()->SetShadingAspect (aShAsp);
2997 VDisplayAISObject (aShapeName, aShape);
3001 //=============================================================================
3002 //function : VComputeHLR
3004 //=============================================================================
3006 static int VComputeHLR (Draw_Interpretor& di,
3007 Standard_Integer argc,
3010 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3012 if (aContextAIS.IsNull ())
3014 di << "Please call vinit before\n";
3018 if ( argc != 3 && argc != 12 )
3020 di << "Usage: " << argv[0] << " ShapeName HlrName "
3021 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3022 << " ShapeName - name of the initial shape\n"
3023 << " HlrName - result hlr object from initial shape\n"
3024 << " eye, dir are eye position and look direction\n"
3025 << " up is the look up direction vector\n"
3026 << " Use vtop to see projected hlr shape\n";
3030 // shape and new object name
3031 TCollection_AsciiString aShapeName (argv[1]);
3032 TCollection_AsciiString aHlrName (argv[2]);
3034 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3037 BRep_Builder aBrepBuilder;
3038 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3041 di << "No shape with name " << argv[1] << " found\n";
3046 if (GetMapOfAIS ().IsBound2 (aHlrName))
3048 di << "Presentable object with name " << argv[2] << " already exists\n";
3052 // close local context
3053 if (aContextAIS->HasOpenedContext ())
3054 aContextAIS->CloseLocalContext ();
3056 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3057 HLRBRep_PolyHLRToShape aHLRToShape;
3066 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3067 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3068 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3069 aProjAx.SetLocation (anEye);
3070 aProjAx.SetDirection (aDir);
3071 aProjAx.SetYDirection (anUp);
3077 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3078 Handle(V3d_View) aView = ViewerTest::CurrentView();
3079 Standard_Integer aWidth, aHeight;
3080 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3081 Standard_Real aRightX, aRightY, aRightZ;
3082 aView->Window()->Size (aWidth, aHeight);
3084 aView->ConvertWithProj (aWidth, aHeight/2,
3085 aRightX, aRightY, aRightZ,
3086 aDirX, aDirY, aDirZ);
3088 aView->ConvertWithProj (aWidth/2, aHeight/2,
3089 aCentX, aCentY, aCentZ,
3090 aDirX, aDirY, aDirZ);
3092 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3093 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3094 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3095 aProjAx.SetLocation (anEye);
3096 aProjAx.SetDirection (aDir);
3097 aProjAx.SetXDirection (aRight);
3100 HLRAlgo_Projector aProjector (aProjAx);
3101 aPolyAlgo->Projector (aProjector);
3102 aPolyAlgo->Load (aSh);
3103 aPolyAlgo->Update ();
3105 aHLRToShape.Update (aPolyAlgo);
3107 // make hlr shape from input shape
3108 TopoDS_Compound aHlrShape;
3109 BRep_Builder aBuilder;
3110 aBuilder.MakeCompound (aHlrShape);
3112 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3113 if (!aCompound.IsNull ())
3115 aBuilder.Add (aHlrShape, aCompound);
3118 // extract visible outlines
3119 aCompound = aHLRToShape.OutLineVCompound();
3120 if (!aCompound.IsNull ())
3122 aBuilder.Add (aHlrShape, aCompound);
3125 // create an AIS shape and display it
3126 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3127 GetMapOfAIS().Bind (anObject, aHlrName);
3128 aContextAIS->Display (anObject);
3130 aContextAIS->UpdateCurrentViewer ();
3135 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3136 // manipulating and displaying such an array with AIS context
3137 DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3138 class MyPArrayObject : public AIS_InteractiveObject
3143 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3144 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3146 myArrayDescription = theArrayDescription;
3147 myMarkerAspect = theMarkerAspect;
3150 DEFINE_STANDARD_RTTI(MyPArrayObject);
3154 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3155 const Handle(Prs3d_Presentation)& aPresentation,
3156 const Standard_Integer aMode);
3158 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3159 const Standard_Integer /*theMode*/);
3161 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3162 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3163 Standard_Integer &theArgIndex,
3164 Standard_Integer theArgCount,
3165 Standard_Integer theMaxArgs);
3169 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3170 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3174 IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3175 IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3177 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3178 const Handle(Prs3d_Presentation)& aPresentation,
3179 const Standard_Integer /*aMode*/)
3182 // Parsing array description
3183 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3184 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3185 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3187 Standard_Integer anArgIndex = 0;
3188 Standard_Integer anArgsCount = myArrayDescription->Length();
3189 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3191 TCollection_AsciiString aCommand;
3192 while (anArgIndex < anArgsCount)
3194 aCommand = myArrayDescription->Value (anArgIndex);
3195 aCommand.LowerCase();
3198 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3200 // vertex has a normal or normal with color or texel
3201 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3202 hasNormals = Standard_True;
3204 // vertex has a color
3205 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3206 hasVColors = Standard_True;
3208 // vertex has a texel
3209 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3210 hasTexels = Standard_True;
3215 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3218 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3219 hasBColors = Standard_True;
3224 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3233 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3234 if (anArrayType == "points")
3236 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3238 else if (anArrayType == "segments")
3239 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3240 else if (anArrayType == "polylines")
3241 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3242 hasVColors, hasBColors);
3243 else if (anArrayType == "triangles")
3244 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3245 hasVColors, hasTexels);
3246 else if (anArrayType == "trianglefans")
3247 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3248 hasNormals, hasVColors,
3249 hasBColors, hasTexels);
3250 else if (anArrayType == "trianglestrips")
3251 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3252 hasNormals, hasVColors,
3253 hasBColors, hasTexels);
3254 else if (anArrayType == "quads")
3255 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3256 hasNormals, hasVColors,
3258 else if (anArrayType == "quadstrips")
3259 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3260 hasNormals, hasVColors,
3261 hasBColors, hasTexels);
3262 else if (anArrayType == "polygons")
3263 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3264 hasNormals, hasVColors, hasBColors,
3268 while (anArgIndex < anArgsCount)
3270 aCommand = myArrayDescription->Value (anArgIndex);
3271 aCommand.LowerCase();
3272 if (!aCommand.IsAscii())
3276 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3278 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3279 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3280 myArrayDescription->Value (anArgIndex - 1).RealValue());
3281 const Standard_Integer aVertIndex = anArray->VertexNumber();
3283 // vertex has a normal or normal with color or texel
3284 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3285 anArray->SetVertexNormal (aVertIndex,
3286 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3287 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3288 myArrayDescription->Value (anArgIndex - 1).RealValue());
3290 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3291 anArray->SetVertexColor (aVertIndex,
3292 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3293 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3294 myArrayDescription->Value (anArgIndex - 1).RealValue());
3296 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3297 anArray->SetVertexTexel (aVertIndex,
3298 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3299 myArrayDescription->Value (anArgIndex - 1).RealValue());
3302 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3304 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3306 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3307 anArray->AddBound (aVertCount,
3308 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3309 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3310 myArrayDescription->Value (anArgIndex - 1).RealValue());
3313 anArray->AddBound (aVertCount);
3316 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3318 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3319 anArray->AddEdge (aVertIndex);
3326 aPresentation->Clear();
3327 if (!myMarkerAspect.IsNull())
3329 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3331 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3334 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3335 const Standard_Integer /*theMode*/)
3337 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3339 Standard_Integer anArgIndex = 1;
3340 while (anArgIndex < myArrayDescription->Length())
3342 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3344 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3345 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3346 myArrayDescription->Value (anArgIndex - 1).RealValue());
3347 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3348 theSelection->Add (aSensetivePoint);
3357 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3358 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3359 Standard_Integer &theArgIndex,
3360 Standard_Integer theArgCount,
3361 Standard_Integer theMaxArgs)
3363 // check if there is more elements than expected
3364 if (theArgIndex >= theMaxArgs)
3367 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3368 aStrCommand.LowerCase();
3369 if (aStrCommand.Search(theCommand) != 1 ||
3370 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3373 // go to the first data element
3376 // check data if it can be converted to numeric
3377 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3379 aStrCommand = theArgsArray->Value (theArgIndex);
3380 if (!aStrCommand.IsRealValue())
3387 //=============================================================================