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_BRepTextBuilder.hxx>
27 #include <Font_FontMgr.hxx>
28 #include <OSD_Chronometer.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <V3d_View.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_DisplayMode.hxx>
36 #include <AIS_PointCloud.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <AIS_MapOfInteractive.hxx>
39 #include <ViewerTest_AutoUpdater.hxx>
40 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42 #include <ViewerTest_EventManager.hxx>
44 #include <TopoDS_Solid.hxx>
45 #include <BRepTools.hxx>
46 #include <BRep_Builder.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
58 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Face.hxx>
62 #include <Draw_Window.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_DisplayMode.hxx>
66 #include <AIS_Shape.hxx>
68 #include <AIS_InteractiveContext.hxx>
69 #include <Geom_Plane.hxx>
71 #include <TCollection_ExtendedString.hxx>
72 #include <TCollection_HAsciiString.hxx>
73 #include <GC_MakePlane.hxx>
74 #include <gp_Circ.hxx>
75 #include <AIS_Axis.hxx>
76 #include <Geom_Axis2Placement.hxx>
77 #include <Geom_Axis1Placement.hxx>
78 #include <AIS_Trihedron.hxx>
79 #include <AIS_Axis.hxx>
80 #include <gp_Trsf.hxx>
81 #include <TopLoc_Location.hxx>
83 #include <HLRAlgo_Projector.hxx>
84 #include <HLRBRep_PolyAlgo.hxx>
85 #include <HLRBRep_PolyHLRToShape.hxx>
86 #include <Aspect_Window.hxx>
88 #include <Graphic3d_ArrayOfPoints.hxx>
89 #include <Graphic3d_ArrayOfSegments.hxx>
90 #include <Graphic3d_ArrayOfPolylines.hxx>
91 #include <Graphic3d_ArrayOfTriangles.hxx>
92 #include <Graphic3d_ArrayOfTriangleFans.hxx>
93 #include <Graphic3d_ArrayOfTriangleStrips.hxx>
94 #include <Graphic3d_ArrayOfQuadrangles.hxx>
95 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
96 #include <Graphic3d_ArrayOfPolygons.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_Group.hxx>
99 #include <Standard_Real.hxx>
101 #include <AIS_Circle.hxx>
102 #include <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 <AIS_TextLabel.hxx>
118 #include <TopLoc_Location.hxx>
119 #include <TColStd_ListOfInteger.hxx>
120 #include <TColStd_ListIteratorOfListOfInteger.hxx>
122 #include <Select3D_SensitiveTriangle.hxx>
123 #include <Select3D_SensitiveCurve.hxx>
124 #include <Select3D_SensitivePoint.hxx>
125 #include <BRepAdaptor_Curve.hxx>
126 #include <StdPrs_Curve.hxx>
128 #include <BRepExtrema_ExtPC.hxx>
129 #include <BRepExtrema_ExtPF.hxx>
131 #include <Prs3d_DatumAspect.hxx>
132 #include <Prs3d_Drawer.hxx>
133 #include <Prs3d_VertexDrawMode.hxx>
134 #include <Prs3d_LineAspect.hxx>
135 #include <Prs3d_PointAspect.hxx>
136 #include <Prs3d_TextAspect.hxx>
138 #include <Image_AlienPixMap.hxx>
139 #include <TColStd_HArray1OfAsciiString.hxx>
140 #include <TColStd_HSequenceOfAsciiString.hxx>
142 #if defined(_MSC_VER)
143 # define _CRT_SECURE_NO_DEPRECATE
144 # pragma warning (disable:4996)
147 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
148 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
149 const Handle(AIS_InteractiveObject)& theAISObj,
150 Standard_Boolean theReplaceIfExists = Standard_True);
151 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
152 extern Handle(AIS_InteractiveContext)& TheAISContext();
155 //==============================================================================
156 //function : Vtrihedron 2d
157 //purpose : Create a plane with a 2D trihedron from a faceselection
158 //Draw arg : vtri2d name
159 //==============================================================================
160 #include <AIS_PlaneTrihedron.hxx>
164 static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
167 // Verification des arguments
168 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
171 Standard_Integer myCurrentIndex;
172 // Fermeture des contextes
173 TheAISContext()->CloseAllContexts();
174 // Ouverture d'un contexte local et recuperation de son index.
175 TheAISContext()->OpenLocalContext();
176 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
177 // On active les modes de selections faces.
178 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
179 di<<" Select a face .\n";
181 // Boucle d'attente waitpick.
182 Standard_Integer argccc = 5;
183 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
184 const char **argvvv = (const char **) bufff;
185 while (ViewerMainLoop( argccc, argvvv) ) { }
189 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
190 ShapeB = TheAISContext()->SelectedShape();
193 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
195 // Construction du Plane
196 // recuperation des edges des faces.
197 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
199 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
203 // si il y a plusieurs edges
204 if (FaceExpB.More() ) {
206 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
207 BRepAdaptor_Curve theCurveB(EdgeB);
208 BRepAdaptor_Curve theCurveC(EdgeC);
209 A=theCurveC.Value(0.1);
210 B=theCurveC.Value(0.9);
211 C=theCurveB.Value(0.5);
214 // FaceB a 1 unique edge courbe
215 BRepAdaptor_Curve theCurveB(EdgeB);
216 A=theCurveB.Value(0.1);
217 B=theCurveB.Value(0.9);
218 C=theCurveB.Value(0.5);
220 // Construction du Geom_Plane
221 GC_MakePlane MkPlane(A,B,C);
222 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
224 // Construction de l'AIS_PlaneTrihedron
225 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
227 // Fermeture du contexte local.
228 TheAISContext()->CloseLocalContext(myCurrentIndex);
230 // on le display & bind
231 TheAISContext()->Display(theAISPlaneTri );
232 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
239 //==============================================================================
240 //function : VTriherdron
241 //purpose : Create a trihedron. If no arguments are set, the default
242 // trihedron (Oxyz) is created.
243 //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
244 //==============================================================================
246 static int VTrihedron (Draw_Interpretor& /*theDi*/,
247 Standard_Integer theArgsNb,
248 const char** theArgVec)
250 if (theArgsNb < 2 || theArgsNb > 11)
252 std::cout << theArgVec[0] << " syntax error\n";
257 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
258 TCollection_AsciiString aParseKey;
259 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
261 TCollection_AsciiString anArg (theArgVec [anArgIt]);
263 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
266 aParseKey.Remove (1);
267 aParseKey.LowerCase();
268 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
272 if (aParseKey.IsEmpty())
277 aMapOfArgs(aParseKey)->Append (anArg);
281 if ( (aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
282 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")) )
284 std::cout << theArgVec[0] << " error: -xaxis and -yaxis parameters are to set together.\n";
288 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
289 aMapIt.More(); aMapIt.Next())
291 const TCollection_AsciiString& aKey = aMapIt.Key();
292 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
294 // Bool key, without arguments
295 if (aKey.IsEqual ("hidelabels") && anArgs->IsEmpty())
300 if ( (aKey.IsEqual ("xaxis") || aKey.IsEqual ("zaxis") || aKey.IsEqual ("origin")) && anArgs->Length() == 3
301 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue() && anArgs->Value(3).IsRealValue() )
307 // Process parameters
308 gp_Pnt anOrigin (0.0, 0.0, 0.0);
309 gp_Dir aDirZ = gp::DZ();
310 gp_Dir aDirX = gp::DX();
312 Handle(TColStd_HSequenceOfAsciiString) aValues;
314 if (aMapOfArgs.Find ("origin", aValues))
316 anOrigin.SetX (aValues->Value(1).RealValue());
317 anOrigin.SetY (aValues->Value(2).RealValue());
318 anOrigin.SetZ (aValues->Value(3).RealValue());
321 Handle(TColStd_HSequenceOfAsciiString) aValues2;
322 if (aMapOfArgs.Find ("xaxis", aValues) && aMapOfArgs.Find ("zaxis", aValues2))
324 Standard_Real aX = aValues->Value(1).RealValue();
325 Standard_Real aY = aValues->Value(2).RealValue();
326 Standard_Real aZ = aValues->Value(3).RealValue();
327 aDirX.SetCoord (aX, aY, aZ);
329 aX = aValues->Value(1).RealValue();
330 aY = aValues->Value(2).RealValue();
331 aZ = aValues->Value(3).RealValue();
332 aDirZ.SetCoord (aX, aY, aZ);
335 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
337 std::cout << theArgVec[0] << " error - VectorX is not normal to VectorZ\n";
341 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
342 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
344 if (aMapOfArgs.Find ("hidelabels", aValues))
346 const Handle(Prs3d_Drawer)& aDrawer = aShape->Attributes();
348 if(!aDrawer->HasOwnDatumAspect())
350 Handle(Prs3d_DatumAspect) aDefAspect = ViewerTest::GetAISContext()->DefaultDrawer()->DatumAspect();
352 Handle(Prs3d_DatumAspect) aDatumAspect = new Prs3d_DatumAspect();
353 aDatumAspect->FirstAxisAspect()->SetAspect (aDefAspect->FirstAxisAspect()->Aspect());
354 aDatumAspect->SecondAxisAspect()->SetAspect (aDefAspect->SecondAxisAspect()->Aspect());
355 aDatumAspect->ThirdAxisAspect()->SetAspect (aDefAspect->ThirdAxisAspect()->Aspect());
356 aDatumAspect->SetAxisLength (aDefAspect->FirstAxisLength(),
357 aDefAspect->SecondAxisLength(),
358 aDefAspect->ThirdAxisLength());
360 aDrawer->SetDatumAspect (aDatumAspect);
363 aDrawer->DatumAspect()->SetToDrawLabels (Standard_False);
366 VDisplayAISObject (theArgVec[1], aShape);
370 //==============================================================================
373 //purpose : Change the size of a named or selected trihedron
374 // if no name : it affects the trihedrons witch are selected otherwise nothing is donne
375 // if no value, the value is set at 100 by default
376 //Draw arg : vsize [name] [size]
377 //==============================================================================
379 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
382 // Declaration de booleens
383 Standard_Boolean ThereIsName;
384 Standard_Boolean ThereIsCurrent;
386 Standard_Boolean hascol;
388 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
390 // Verification des arguments
391 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
393 // Verification du nombre d'arguments
394 if (argc==1) {ThereIsName=Standard_False;value=100;}
395 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
396 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
398 // On ferme le contexte local pour travailler dans le contexte global
399 if(TheAISContext()->HasOpenedContext())
400 TheAISContext()->CloseLocalContext();
402 // On set le booleen ThereIsCurrent
403 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
404 else {ThereIsCurrent=Standard_False;}
408 //===============================================================
409 // Il n'y a pas de nom mais des objets selectionnes
410 //===============================================================
411 if (!ThereIsName && ThereIsCurrent)
414 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
417 while ( it.More() ) {
419 Handle(AIS_InteractiveObject) aShape=
420 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
422 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
425 // On verifie que l'AIS InteraciveObject selectionne est bien
427 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
429 if (aShape->HasColor()) {
430 hascol=Standard_True;
432 // On recupere la couleur de aShape
433 col=aShape->Color();}
435 else hascol=Standard_False;
437 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
438 // pour lui appliquer la methode SetSize()
439 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
441 // C'est bien un triedre,on chage sa valeur!
442 aTrihedron->SetSize(value);
444 // On donne la couleur au Trihedron
445 if(hascol) aTrihedron->SetColor(col);
446 else aTrihedron->UnsetColor();
449 // The trihedron hasn't be errased from the map
450 // so you just have to redisplay it
451 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
460 TheAISContext() ->UpdateCurrentViewer();
463 //===============================================================
464 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
465 //===============================================================
469 //===============================================================
470 // Il y a un nom de triedre passe en argument
471 //===============================================================
473 TCollection_AsciiString name=argv[1];
475 // on verifie que ce nom correspond bien a une shape
476 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
480 // on recupere la shape dans la map des objets displayes
481 Handle(AIS_InteractiveObject) aShape =
482 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
484 // On verifie que l'AIS InteraciveObject est bien
486 if (!aShape.IsNull() &&
487 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
490 if (aShape->HasColor()) {
491 hascol=Standard_True;
493 // On recupere la couleur de aShape
494 col=aShape->Color();}
496 else hascol=Standard_False;
498 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
499 // pour lui appliquer la methode SetSize()
500 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
502 // C'est bien un triedre,on chage sa valeur
503 aTrihedron->SetSize(value);
505 // On donne la couleur au Trihedron
506 if(hascol) aTrihedron->SetColor(col);
507 else aTrihedron->UnsetColor();
509 // The trihedron hasn't be errased from the map
510 // so you just have to redisplay it
511 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
513 TheAISContext() ->UpdateCurrentViewer();
521 //==============================================================================
523 //==============================================================================
524 //function : VPlaneTrihedron
525 //purpose : Create a plane from a trihedron selection. If no arguments are set, the default
526 //Draw arg : vplanetri name
527 //==============================================================================
528 #include <AIS_Plane.hxx>
532 static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
535 // Verification des arguments
536 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
539 Standard_Integer myCurrentIndex;
540 // Fermeture des contextes locaux
541 TheAISContext()->CloseAllContexts();
543 // On recupere tous les trihedrons de la GetMapOfAIS()
544 // et on active le mode de selection par face.
545 // =================================================
547 // Ouverture d'un contexte local et recuperation de son index.
548 TheAISContext()->OpenLocalContext(Standard_False);
549 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
551 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
554 Handle(AIS_InteractiveObject) ShapeA =
555 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
556 // On verifie que c'est bien un trihedron
557 if (!ShapeA.IsNull() &&
558 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
560 Handle(AIS_Trihedron) TrihedronA =(Handle(AIS_Trihedron)::DownCast (ShapeA));
561 // on le charge dans le contexte et on active le mode Plane.
562 TheAISContext()->Load(TrihedronA,0,Standard_False);
563 TheAISContext()->Activate(TrihedronA,3);
568 di<<" Select a plane.\n";
569 // Boucle d'attente waitpick.
570 Standard_Integer argccc = 5;
571 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
572 const char **argvvv = (const char **) bufff;
573 while (ViewerMainLoop( argccc, argvvv) ) { }
576 Handle(AIS_InteractiveObject) theIOB;
577 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
578 theIOB = TheAISContext()->SelectedInteractive();
581 Handle(AIS_Plane) PlaneB =(Handle(AIS_Plane)::DownCast (theIOB));
583 // Fermeture du contexte local.
584 TheAISContext()->CloseLocalContext(myCurrentIndex);
586 // on le display & bind
587 TheAISContext()->Display(PlaneB );
588 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
595 //==============================================================================
596 // Fonction First click 2de click
598 // vaxis vertex vertex
600 // vaxispara edge vertex
601 // vaxisortho edge Vertex
602 // vaxisinter Face Face
603 //==============================================================================
605 //==============================================================================
606 //function : VAxisBuilder
608 //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
609 //==============================================================================
610 #include <TopoDS_Edge.hxx>
611 #include <TopoDS_Vertex.hxx>
612 #include <TopExp.hxx>
613 #include <Geom_Line.hxx>
615 static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
618 Standard_Boolean HasArg;
619 TCollection_AsciiString name;
620 Standard_Integer MyCurrentIndex;
623 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
624 if (argc==8) HasArg=Standard_True;
625 else HasArg=Standard_False;
628 // Fermeture des contextes
629 TheAISContext()->CloseAllContexts();
631 // Cas ou il y a des arguments
632 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
634 Standard_Real coord[6];
635 for(Standard_Integer i=0;i<=5;i++){
636 coord[i]=Draw::Atof(argv[2+i]);
638 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
640 gp_Vec myVect (p1,p2);
641 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
642 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
643 GetMapOfAIS().Bind (TheAxis,name);
644 TheAISContext()->Display(TheAxis);
650 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
651 if ( !strcasecmp(argv[0], "vaxis")) {
652 TheAISContext()->OpenLocalContext();
653 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
655 // Active le mode edge et le mode vertex
656 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
657 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
658 di<<" Select an edge or a vertex.\n";
660 // Boucle d'attente waitpick.
661 Standard_Integer argcc = 5;
662 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
663 const char **argvv = (const char **) buff;
664 while (ViewerMainLoop( argcc, argvv) ) { }
667 // recuperation de la shape.
669 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
670 ShapeA = TheAISContext()->SelectedShape();
672 // recuperation de l'AIS_InteractiveObject
673 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
674 // down cast en AIS_Point si sig et type
675 // AIS_Point -> Geom_Pnt ....
677 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
678 // on desactive le mode edge
679 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
680 di<<" Select a different vertex.\n";
684 // Boucle d'attente waitpick.
685 Standard_Integer argccc = 5;
686 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
687 const char **argvvv = (const char **) bufff;
688 while (ViewerMainLoop( argccc, argvvv) ) { }
690 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
691 ShapeB = TheAISContext()->SelectedShape();
695 } while(ShapeB.IsSame(ShapeA) );
697 // Fermeture du context local
698 TheAISContext()->CloseLocalContext(MyCurrentIndex);
700 // Construction de l'axe
701 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
702 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
705 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
706 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
707 GetMapOfAIS().Bind (TheAxis,name);
708 TheAISContext()->Display(TheAxis);
711 // Un unique edge (ShapeA) a ete picke
712 // Fermeture du context local
713 TheAISContext()->CloseLocalContext(MyCurrentIndex);
714 // Constuction de l'axe
715 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
717 TopExp::Vertices(ed,Va,Vb );
718 gp_Pnt A=BRep_Tool::Pnt(Va);
719 gp_Pnt B=BRep_Tool::Pnt(Vb);
722 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
723 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
724 GetMapOfAIS().Bind (TheAxis,name);
725 TheAISContext()->Display(TheAxis);
731 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
732 else if ( !strcasecmp(argv[0], "vaxispara")) {
734 TheAISContext()->OpenLocalContext();
735 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
737 // Active le mode edge
738 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
739 di<<" Select an edge.\n";
741 // Boucle d'attente waitpick.
742 Standard_Integer argcc = 5;
743 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
744 const char **argvv = (const char **) buff;
745 while (ViewerMainLoop( argcc, argvv) ) { }
749 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
750 ShapeA = TheAISContext()->SelectedShape();
752 // Active le mode vertex et deactive edges
753 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
754 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
755 di<<" Select a vertex.\n";
757 // Boucle d'attente waitpick.
758 Standard_Integer argccc = 5;
759 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
760 const char **argvvv = (const char **) bufff;
761 while (ViewerMainLoop( argccc, argvvv) ) { }
764 // On peut choisir un pnt sur l'edge
766 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
767 ShapeB = TheAISContext()->SelectedShape();
769 // Fermeture du context local
770 TheAISContext()->CloseLocalContext(MyCurrentIndex);
772 // Construction de l'axe
773 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
774 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
776 TopExp::Vertices(ed,Va,Vc );
777 gp_Pnt A=BRep_Tool::Pnt(Va);
778 gp_Pnt C=BRep_Tool::Pnt(Vc);
781 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
782 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
783 GetMapOfAIS().Bind (TheAxis,name);
784 TheAISContext()->Display(TheAxis);
788 // Fonction axisortho
790 TheAISContext()->OpenLocalContext();
791 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
793 // Active le mode edge
794 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
795 di<<" Select an edge.\n";
797 // Boucle d'attente waitpick.
798 Standard_Integer argcc = 5;
799 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
800 const char **argvv = (const char **) buff;
801 while (ViewerMainLoop( argcc, argvv) ) { }
805 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
806 ShapeA = TheAISContext()->SelectedShape();
808 // Active le mode vertex et deactive edges
809 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
810 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
811 di<<" Slect a vertex.\n";
813 // Boucle d'attente waitpick.
814 Standard_Integer argccc = 5;
815 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
816 const char **argvvv = (const char **) bufff;
817 while (ViewerMainLoop( argccc, argvvv) ) { }
820 // On peut choisir un pnt sur l'edge
822 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
823 ShapeB = TheAISContext()->SelectedShape();
825 // Fermeture du context local
826 TheAISContext()->CloseLocalContext(MyCurrentIndex);
828 // Construction de l'axe
829 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
830 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
832 TopExp::Vertices(ed,Va,Vc );
833 gp_Pnt A=BRep_Tool::Pnt(Va);
834 gp_Pnt C=BRep_Tool::Pnt(Vc);
835 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
838 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
839 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
840 GetMapOfAIS().Bind (TheAxis,name);
841 TheAISContext()->Display(TheAxis);
850 //==============================================================================
851 // Fonction First click Result
853 // vpoint vertex AIS_Point=Vertex
854 // edge AIS_Point=Middle of the edge
855 //==============================================================================
857 //==============================================================================
858 //function : VPointBuilder
859 //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
860 //Draw arg : vpoint PoinName [Xa] [Ya] [Za]
861 //==============================================================================
862 #include <TopoDS_Edge.hxx>
863 #include <TopoDS_Vertex.hxx>
864 #include <TopExp.hxx>
865 #include <AIS_Point.hxx>
866 #include <Geom_CartesianPoint.hxx>
868 static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
871 Standard_Boolean HasArg;
872 TCollection_AsciiString name;
873 Standard_Integer myCurrentIndex;
876 if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
877 if (argc==5) HasArg=Standard_True;
878 else HasArg=Standard_False;
881 // Fermeture des contextes
882 TheAISContext()->CloseAllContexts();
884 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
886 Standard_Real thecoord[3];
887 for(Standard_Integer i=0;i<=2;i++)
888 thecoord[i]=Draw::Atof(argv[2+i]);
889 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
890 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
891 GetMapOfAIS().Bind (myAISPoint,name);
892 TheAISContext()->Display(myAISPoint);
895 // Il n'a pas d'arguments
897 TheAISContext()->OpenLocalContext();
898 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
900 // Active le mode Vertex et Edges
901 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
902 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
903 di<<" Select a vertex or an edge(build the middle)\n";
905 // Boucle d'attente waitpick.
906 Standard_Integer argcc = 5;
907 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
908 const char **argvv = (const char **) buff;
909 while (ViewerMainLoop( argcc, argvv) ) { }
913 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
914 ShapeA= TheAISContext()->SelectedShape();
917 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
918 // Un vertex a ete selectionne
919 // Fermeture du context local
920 TheAISContext()->CloseLocalContext(myCurrentIndex);
922 // Construction du point
923 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
924 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
925 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
926 GetMapOfAIS().Bind(myAISPoint,name);
927 TheAISContext()->Display(myAISPoint);
930 // Un Edge a ete selectionne
931 // Fermeture du context local
932 TheAISContext()->CloseLocalContext(myCurrentIndex);
934 // Construction du point milieu de l'edge
935 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
936 TopoDS_Vertex myVertexA,myVertexB;
937 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
938 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
939 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
940 // M est le milieu de [AB]
941 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
942 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
943 GetMapOfAIS().Bind(myAISPointM,name);
944 TheAISContext()->Display(myAISPointM);
952 //==============================================================================
953 // Function 1st click 2de click 3de click
954 // vplane Vertex Vertex Vertex
958 // vplanepara Face Vertex
960 // vplaneortho Face Edge
962 //==============================================================================
964 //==============================================================================
965 //function : VPlaneBuilder
966 //purpose : Build an AIS_Plane from selected entities or Named AIS components
967 //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
968 // [PointName] [PointName] [PointName] [TypeOfSensitivity]
969 // [PlaneName] [PointName] [TypeOfSensitivity]
970 //==============================================================================
972 static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
973 Standard_Integer argc,
977 Standard_Boolean hasArg;
978 TCollection_AsciiString aName;
979 Standard_Integer aCurrentIndex;
982 if (argc<2 || argc>6 )
984 std::cout<<" Syntax error\n";
987 if (argc == 6 || argc==5 || argc==4)
988 hasArg=Standard_True;
990 hasArg=Standard_False;
993 // Close all contexts
994 TheAISContext()->CloseAllContexts();
996 // There are some arguments
999 if (!GetMapOfAIS().IsBound2(argv[2] ))
1001 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
1004 // Get shape from map
1005 Handle(AIS_InteractiveObject) aShapeA =
1006 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
1008 // The first argument is an AIS_Point
1009 if (!aShapeA.IsNull() &&
1010 aShapeA->Type()==AIS_KOI_Datum &&
1011 aShapeA->Signature()==1)
1013 // The second argument must also be an AIS_Point
1014 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
1016 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
1019 // Get shape from map
1020 Handle(AIS_InteractiveObject) aShapeB =
1021 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1022 // If B is not an AIS_Point
1023 if (aShapeB.IsNull() ||
1024 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1026 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
1029 // The third object is an AIS_Point
1030 if (!GetMapOfAIS().IsBound2(argv[4]) )
1032 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
1035 // Get shape from map
1036 Handle(AIS_InteractiveObject) aShapeC =
1037 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
1038 // If C is not an AIS_Point
1039 if (aShapeC.IsNull() ||
1040 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
1042 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
1046 // Treatment of objects A, B, C
1047 // Downcast an AIS_IO to AIS_Point
1048 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1049 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1050 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
1052 Handle(Geom_CartesianPoint ) aCartPointA =
1053 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
1055 Handle(Geom_CartesianPoint ) aCartPointB =
1056 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
1058 Handle(Geom_CartesianPoint ) aCartPointC =
1059 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
1061 // Verification that the three points are different
1062 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1063 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1064 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
1067 std::cout<<"vplane error: same points\n";return 1;
1069 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1070 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1071 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
1074 std::cout<<"vplane error: same points\n";return 1;
1076 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1077 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1078 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
1081 std::cout<<"vplane error: same points\n";return 1;
1084 gp_Pnt A = aCartPointA->Pnt();
1085 gp_Pnt B = aCartPointB->Pnt();
1086 gp_Pnt C = aCartPointC->Pnt();
1088 // Construction of AIS_Plane
1089 GC_MakePlane MkPlane (A,B,C);
1090 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1091 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1092 GetMapOfAIS().Bind (anAISPlane,aName );
1095 Standard_Integer aType = Draw::Atoi (argv[5]);
1096 if (aType != 0 && aType != 1)
1098 std::cout << "vplane error: wrong type of sensitivity!\n"
1099 << "Should be one of the following values:\n"
1107 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1110 TheAISContext()->Display(anAISPlane);
1113 // The first argument is an AIS_Axis
1114 // Creation of a plane orthogonal to the axis through a point
1115 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1116 // The second argument should be an AIS_Point
1117 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1119 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1122 // Get shape from map
1123 Handle(AIS_InteractiveObject) aShapeB =
1124 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1125 // If B is not an AIS_Point
1126 if (aShapeB.IsNull() ||
1127 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1129 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1133 // Treatment of objects A and B
1134 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1135 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1137 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1138 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
1140 gp_Ax1 anAxis = aGeomLineA->Position();
1141 Handle(Geom_CartesianPoint) aCartPointB =
1142 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1144 gp_Dir D =anAxis.Direction();
1145 gp_Pnt B = aCartPointB->Pnt();
1147 // Construction of AIS_Plane
1148 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1149 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1150 GetMapOfAIS().Bind (anAISPlane,aName );
1153 Standard_Integer aType = Draw::Atoi (argv[4]);
1154 if (aType != 0 && aType != 1)
1156 std::cout << "vplane error: wrong type of sensitivity!\n"
1157 << "Should be one of the following values:\n"
1165 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1168 TheAISContext()->Display(anAISPlane);
1171 // The first argumnet is an AIS_Plane
1172 // Creation of a plane parallel to the plane passing through the point
1173 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1175 // The second argument should be an AIS_Point
1176 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1178 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
1181 // Get shape from map
1182 Handle(AIS_InteractiveObject) aShapeB =
1183 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1184 // B should be an AIS_Point
1185 if (aShapeB.IsNull() ||
1186 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
1188 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
1192 // Treatment of objects A and B
1193 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1194 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
1196 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1197 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
1199 Handle(Geom_CartesianPoint) aCartPointB =
1200 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1201 gp_Pnt B= aCartPointB->Pnt();
1203 // Construction of an AIS_Plane
1204 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1205 GetMapOfAIS().Bind (anAISPlane, aName);
1208 Standard_Integer aType = Draw::Atoi (argv[4]);
1209 if (aType != 0 && aType != 1)
1211 std::cout << "vplane error: wrong type of sensitivity!\n"
1212 << "Should be one of the following values:\n"
1220 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1223 TheAISContext()->Display(anAISPlane);
1228 std::cout<<"vplane: error 1st object is not an AIS\n";
1232 // There are no arguments
1236 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1237 if (!strcasecmp(argv[0], "vplane"))
1239 TheAISContext()->OpenLocalContext();
1240 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1242 // Active modes Vertex, Edge and Face
1243 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1244 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1245 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1246 std::cout<<"Select a vertex, a face or an edge\n";
1249 Standard_Integer argcc = 5;
1250 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1251 const char **argvv = (const char **) buff;
1252 while (ViewerMainLoop( argcc, argvv) ) { }
1255 TopoDS_Shape aShapeA;
1256 for (TheAISContext()->InitSelected();
1257 TheAISContext()->MoreSelected();
1258 TheAISContext()->NextSelected())
1260 aShapeA = TheAISContext()->SelectedShape();
1263 // aShapeA is a Vertex
1264 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1266 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1267 std::cout<<" Select an edge or a different vertex\n";
1270 Standard_Integer argccc = 5;
1271 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1272 const char **argvvv = (const char **) bufff;
1273 while (ViewerMainLoop( argccc, argvvv) ) { }
1276 TopoDS_Shape aShapeB;
1277 for (TheAISContext()->InitSelected();
1278 TheAISContext()->MoreSelected();
1279 TheAISContext()->NextSelected())
1281 aShapeB = TheAISContext()->SelectedShape();
1283 // aShapeB is a Vertex
1284 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1286 // A and B are the same
1287 if (aShapeB.IsSame(aShapeA))
1289 std::cout<<" vplane: error, same points selected\n";
1292 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1293 std::cout<<" Select a different vertex\n";
1296 Standard_Integer argcccc = 5;
1297 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1298 const char **argvvvv = (const char **) buffff;
1299 while (ViewerMainLoop( argcccc, argvvvv) ) { }
1302 TopoDS_Shape aShapeC;
1303 for (TheAISContext()->InitSelected();
1304 TheAISContext()->MoreSelected();
1305 TheAISContext()->NextSelected())
1307 aShapeC = TheAISContext()->SelectedShape();
1309 // aShapeC is the same as A or B
1310 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1312 std::cout<<" vplane: error, same points selected\n";
1316 // Close the local context
1317 TheAISContext()->CloseLocalContext(aCurrentIndex);
1319 // Construction of plane
1320 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1321 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1322 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1323 GC_MakePlane MkPlane(A, B, C);
1324 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1325 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1326 GetMapOfAIS().Bind (anAISPlane, aName);
1327 TheAISContext()->Display(anAISPlane);
1329 // ShapeB is an edge
1332 // Verify that the vertex is not on the edge ShapeB
1333 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1334 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
1336 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1337 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1339 // The vertex is on the edge
1340 std::cout<<" vplane: error point is on the edge\n";
1345 // Close the local context
1346 TheAISContext()->CloseLocalContext(aCurrentIndex);
1347 // Construction of plane
1348 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1349 TopoDS_Vertex aVBa, aVBb;
1350 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1351 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1352 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1353 GC_MakePlane MkPlane (A, aBa, aBb);
1354 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1355 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1356 GetMapOfAIS().Bind (anAISPlane, aName);
1357 TheAISContext()->Display(anAISPlane);
1361 // aShapeA is an edge
1362 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1364 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1365 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1366 std::cout<<" Select a vertex that don't belong to the edge\n";
1369 Standard_Integer argccc = 5;
1370 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1371 const char **argvvv = (const char **) bufff;
1372 while (ViewerMainLoop( argccc, argvvv) ) { }
1375 TopoDS_Shape aShapeB;
1376 for (TheAISContext()->InitSelected();
1377 TheAISContext()->MoreSelected();
1378 TheAISContext()->NextSelected())
1380 aShapeB = TheAISContext()->SelectedShape();
1382 // aShapeB should be a Vertex
1383 // Check that the vertex aShapeB is not on the edge
1384 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1385 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1387 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1388 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1390 // The vertex is on the edge
1391 std::cout<<" vplane: error point is on the edge\n";
1396 // Close the local context
1397 TheAISContext()->CloseLocalContext(aCurrentIndex);
1398 // Construction of plane
1399 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1400 TopoDS_Vertex aVAa, aVAb;
1401 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1402 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1403 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1404 GC_MakePlane MkPlane (B,Aa,Ab);
1405 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1406 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1407 GetMapOfAIS().Bind (anAISPlane ,aName);
1408 TheAISContext()->Display(anAISPlane);
1411 // aShapeA is a Face
1414 // Close the local context: nothing to select
1415 TheAISContext()->CloseLocalContext(aCurrentIndex);
1416 // Construction of plane
1417 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1418 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1419 if (aSurface.GetType()==GeomAbs_Plane)
1421 gp_Pln aPlane = aSurface.Plane();
1422 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1423 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1424 GetMapOfAIS().Bind (anAISPlane, aName);
1425 TheAISContext()->Display(anAISPlane);
1429 std::cout<<" vplane: error\n";
1435 // Function vPlanePara
1436 // ===================
1437 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1438 else if (!strcasecmp(argv[0], "vplanepara"))
1440 TheAISContext()->OpenLocalContext();
1441 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1443 // Activate modes Vertex and Face
1444 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1445 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1446 std::cout<<" Select a vertex or a face\n";
1449 Standard_Integer argcc = 5;
1450 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1451 const char **argvv = (const char **) buff;
1452 while (ViewerMainLoop( argcc, argvv) ) { }
1455 TopoDS_Shape aShapeA;
1456 for (TheAISContext()->InitSelected();
1457 TheAISContext()->MoreSelected();
1458 TheAISContext()->NextSelected())
1460 aShapeA = TheAISContext()->SelectedShape();
1463 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1465 // aShapeA is a vertex
1466 // Deactivate the mode Vertex
1467 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1468 std::cout<<" Select a face\n";
1471 Standard_Integer argccc = 5;
1472 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1473 const char **argvvv = (const char **) bufff;
1474 while (ViewerMainLoop( argccc, argvvv) ) { }
1477 TopoDS_Shape aShapeB;
1478 for (TheAISContext()->InitSelected();
1479 TheAISContext()->MoreSelected();
1480 TheAISContext()->NextSelected())
1482 // A vertex ShapeA can be on Face ShapeB
1483 aShapeB = TheAISContext()->SelectedShape();
1486 // Close the local context
1487 TheAISContext()->CloseLocalContext(aCurrentIndex);
1489 // Construction of plane
1490 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1492 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1493 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1494 if (aSurface.GetType()==GeomAbs_Plane )
1496 gp_Pln aPlane = aSurface.Plane();
1497 // Construct a plane parallel to aGeomPlane through A
1498 aPlane.SetLocation(A);
1499 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1500 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1501 GetMapOfAIS().Bind (aAISPlane ,aName);
1502 TheAISContext()->Display(aAISPlane);
1506 std::cout<<" vplanepara: error\n";
1513 // Deactive the mode Face
1514 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1515 std::cout<<" Select a vertex\n";
1518 Standard_Integer argccc = 5;
1519 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1520 const char **argvvv = (const char **) bufff;
1521 while (ViewerMainLoop( argccc, argvvv) ) { }
1524 TopoDS_Shape aShapeB;
1525 for (TheAISContext()->InitSelected();
1526 TheAISContext()->MoreSelected();
1527 TheAISContext()->NextSelected())
1529 // A vertex ShapeB can be on Face ShapeA
1530 aShapeB = TheAISContext()->SelectedShape();
1532 // Close the local context
1533 TheAISContext()->CloseLocalContext(aCurrentIndex);
1535 // Construction of plane
1536 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1538 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1539 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1540 if (aSurface.GetType()==GeomAbs_Plane )
1542 gp_Pln aPlane = aSurface.Plane();
1543 aPlane.SetLocation(B);
1544 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1545 // Construct a plane parallel to aGeomPlane through B
1546 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1547 GetMapOfAIS().Bind (anAISPlane, aName);
1548 TheAISContext()->Display(anAISPlane);
1552 std::cout<<" vplanepara: error\n";return 1;
1557 // Function vplaneortho
1558 // ====================
1559 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1562 TheAISContext()->OpenLocalContext();
1563 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1565 // Activate the modes Edge and Face
1566 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1567 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1568 std::cout<<" Select a face and an edge coplanar\n";
1571 Standard_Integer argcc = 5;
1572 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1573 const char **argvv = (const char **) buff;
1574 while (ViewerMainLoop( argcc, argvv) ) { }
1577 TopoDS_Shape aShapeA;
1578 for (TheAISContext()->InitSelected();
1579 TheAISContext()->MoreSelected();
1580 TheAISContext()->NextSelected())
1582 aShapeA = TheAISContext()->SelectedShape();
1585 if (aShapeA.ShapeType()==TopAbs_EDGE )
1587 // ShapeA is an edge, deactivate the mode Edge...
1588 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1589 std::cout<<" Select a face\n";
1592 Standard_Integer argccc = 5;
1593 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1594 const char **argvvv = (const char **) bufff;
1595 while (ViewerMainLoop( argccc, argvvv) ) { }
1598 TopoDS_Shape aShapeB;
1599 for (TheAISContext()->InitSelected();
1600 TheAISContext()->MoreSelected();
1601 TheAISContext()->NextSelected())
1603 // Edge ShapeA can be on Face ShapeB
1604 aShapeB = TheAISContext()->SelectedShape();
1607 // Close the local context
1608 TheAISContext()->CloseLocalContext(aCurrentIndex);
1610 // Construction of plane
1611 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1612 TopoDS_Vertex aVAa, aVAb;
1613 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1614 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1615 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1619 // Creation of rotation axis
1620 gp_Ax1 aRotAxis (Aa,Dab);
1622 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1623 // The edge must be parallel to the face
1624 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1625 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1626 // Compare to heights
1627 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1628 >Precision::Confusion())
1630 // the edge is not parallel to the face
1631 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1635 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1636 if (aSurface.GetType()==GeomAbs_Plane)
1638 gp_Pln aPlane = aSurface.Plane();
1639 // It rotates a half turn round the axis of rotation
1640 aPlane.Rotate(aRotAxis , M_PI/2);
1642 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1643 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1644 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1645 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1646 GetMapOfAIS().Bind (anAISPlane, aName);
1647 TheAISContext()->Display(anAISPlane);
1651 std::cout<<" vplaneortho: error\n";
1657 // ShapeA is a Face, deactive the mode Face.
1658 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1659 std::cout<<" Select an edge\n";
1662 Standard_Integer argccc = 5;
1663 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1664 const char **argvvv = (const char **) bufff;
1665 while (ViewerMainLoop( argccc, argvvv) ) { }
1668 TopoDS_Shape aShapeB;
1669 for (TheAISContext()->InitSelected();
1670 TheAISContext()->MoreSelected();
1671 TheAISContext()->NextSelected())
1673 // Edge ShapeB can be on Face ShapeA
1674 aShapeB = TheAISContext()->SelectedShape();
1676 // Close the local context
1677 TheAISContext()->CloseLocalContext(aCurrentIndex);
1679 // Construction of plane
1680 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1681 TopoDS_Vertex aVBa, aVBb;
1682 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1683 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1684 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1685 gp_Vec ab (aBa,aBb);
1687 // Creation of rotation axe
1688 gp_Ax1 aRotAxis (aBa,Dab);
1690 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1691 // The edge must be parallel to the face
1692 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1693 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1694 // Comparing the two heights
1695 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1696 >Precision::Confusion())
1698 // the edge is not parallel to the face
1699 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1703 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1704 if (aSurface.GetType()==GeomAbs_Plane)
1706 gp_Pln aPlane = aSurface.Plane();
1707 // It rotates a half turn round the axis of rotation
1708 aPlane.Rotate(aRotAxis , M_PI/2);
1709 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1710 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1711 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1712 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1713 GetMapOfAIS().Bind (anAISPlane ,aName);
1714 TheAISContext()->Display(anAISPlane);
1718 std::cout<<" vplaneortho: error\n";
1727 //===============================================================================================
1728 //function : VChangePlane
1730 //===============================================================================================
1731 static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1733 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1734 if (aContextAIS.IsNull())
1736 std::cout << theArgVec[0] << "AIS context is not available.\n";
1740 if (theArgsNb < 3 || theArgsNb > 11)
1742 std::cerr << theArgVec[0]
1743 << ": incorrect number of command arguments.\n"
1744 << "Type help for more information.\n";
1748 TCollection_AsciiString aName (theArgVec[1]);
1750 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1751 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1754 if ( aPlane.IsNull() )
1756 std::cout << theArgVec[0]
1757 << ": there is no interactive plane with the given name."
1758 << "Type help for more information.\n";
1762 Standard_Real aCenterX = aPlane->Center().X();
1763 Standard_Real aCenterY = aPlane->Center().Y();
1764 Standard_Real aCenterZ = aPlane->Center().Z();
1766 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1767 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1768 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1770 Standard_Real aSizeX = 0.0;
1771 Standard_Real aSizeY = 0.0;
1772 aPlane->Size (aSizeX, aSizeY);
1773 Standard_Boolean isUpdate = Standard_True;
1775 TCollection_AsciiString aPName, aPValue;
1776 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1778 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1779 TCollection_AsciiString anArgCase = anArg;
1780 anArgCase.UpperCase();
1781 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1784 if (aPName.IsEqual ("X"))
1786 aCenterX = aPValue.RealValue();
1788 else if (aPName.IsEqual ("Y"))
1790 aCenterY = aPValue.RealValue();
1792 else if (aPName.IsEqual ("Z"))
1794 aCenterZ = aPValue.RealValue();
1796 else if (aPName.IsEqual ("DX"))
1798 aDirX = aPValue.RealValue();
1800 else if (aPName.IsEqual ("DY"))
1802 aDirY = aPValue.RealValue();
1804 else if (aPName.IsEqual ("DZ"))
1806 aDirZ = aPValue.RealValue();
1808 else if (aPName.IsEqual ("SX"))
1810 aSizeX = aPValue.RealValue();
1812 else if (aPName.IsEqual ("SY"))
1814 aSizeY = aPValue.RealValue();
1817 else if (anArg.IsEqual ("NOUPDATE"))
1819 isUpdate = Standard_False;
1823 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1824 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1825 aPlane->SetCenter (aCenterPnt);
1826 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1827 aPlane->SetSize (aSizeX, aSizeY);
1829 aContextAIS->Update (aPlane, isUpdate);
1834 //==============================================================================
1836 // --------------- Uniquement par parametre. Pas de selection dans le viewer.
1837 //==============================================================================
1839 //==============================================================================
1840 //function : VLineBuilder
1841 //purpose : Build an AIS_Line
1842 //Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1843 // [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1844 //==============================================================================
1845 #include <Geom_CartesianPoint.hxx>
1846 #include <AIS_Line.hxx>
1849 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1851 Standard_Integer myCurrentIndex;
1853 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
1854 // Fermeture des contextes
1855 TheAISContext()->CloseAllContexts();
1857 // On recupere les parametres
1858 Handle(AIS_InteractiveObject) theShapeA;
1859 Handle(AIS_InteractiveObject) theShapeB;
1861 // Parametres: AIS_Point AIS_Point
1862 // ===============================
1865 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1866 // On verifie que c'est bien une AIS_Point
1867 if (!theShapeA.IsNull() &&
1868 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1869 // on recupere le deuxieme AIS_Point
1871 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1872 if (theShapeA.IsNull() ||
1873 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1875 di <<"vline error: wrong type of 2de argument.\n";
1879 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
1880 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1881 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1882 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
1884 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1885 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
1886 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1888 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1889 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
1890 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1892 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1894 di<<"vline error: same points\n";return 1;
1896 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1897 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1898 GetMapOfAIS().Bind(theAISLine,argv[1] );
1899 TheAISContext()->Display(theAISLine );
1903 // Parametres 6 Reals
1904 // ==================
1907 // On verifie que les deux points ne sont pas confondus
1909 Standard_Real coord[6];
1910 for(Standard_Integer i=0;i<=2;i++){
1911 coord[i]=Draw::Atof(argv[2+i]);
1912 coord[i+3]=Draw::Atof(argv[5+i]);
1915 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1916 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1918 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1919 GetMapOfAIS().Bind(theAISLine,argv[1] );
1920 TheAISContext()->Display(theAISLine );
1924 // Pas de parametres: Selection dans le viewer.
1925 // ============================================
1928 TheAISContext()->OpenLocalContext();
1929 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1931 // Active le mode Vertex.
1932 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1933 di<<" Select a vertex \n";
1935 // Boucle d'attente waitpick.
1936 Standard_Integer argcc = 5;
1937 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1938 const char **argvv = (const char **) buff;
1939 while (ViewerMainLoop( argcc, argvv) ) { }
1942 TopoDS_Shape ShapeA;
1943 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1944 ShapeA = TheAISContext()->SelectedShape();
1947 // ShapeA est un Vertex
1948 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1950 di<<" Select a different vertex.\n";
1952 TopoDS_Shape ShapeB;
1955 // Boucle d'attente waitpick.
1956 Standard_Integer argccc = 5;
1957 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1958 const char **argvvv = (const char **) bufff;
1959 while (ViewerMainLoop( argccc, argvvv) ) { }
1962 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1963 ShapeB = TheAISContext()->SelectedShape();
1967 } while(ShapeB.IsSame(ShapeA) );
1969 // Fermeture du context local
1970 TheAISContext()->CloseLocalContext(myCurrentIndex);
1972 // Construction de la line
1973 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1974 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1976 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1977 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1979 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1980 GetMapOfAIS().Bind(theAISLine,argv[1] );
1981 TheAISContext()->Display(theAISLine );
1985 di<<"vline error.\n";
1993 //==============================================================================
1994 // class : FilledCircle
1995 // purpose : creates filled circle based on AIS_InteractiveObject
1997 // This class is used to check method Matches() of class
1998 // Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1999 // because none of AIS classes provides creation of
2000 // Select3D_SensitiveCircle with member myFillStatus = Standard_True
2001 // (look method ComputeSelection() )
2002 //==============================================================================
2004 Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
2006 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
2007 gp_Circ aCirc(anAxes, theRadius);
2008 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
2012 class FilledCircle : public AIS_InteractiveObject
2016 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
2018 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
2019 FilledCircle(Handle(Geom_Circle) theCircle);
2022 TopoDS_Face ComputeFace();
2024 // Virtual methods implementation
2025 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
2026 const Handle(Prs3d_Presentation)& thePresentation,
2027 const Standard_Integer theMode) Standard_OVERRIDE;
2029 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
2030 const Standard_Integer theMode) Standard_OVERRIDE;
2033 Handle(Geom_Circle) myCircle;
2034 Standard_Boolean myFilledStatus;
2039 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
2041 myCircle = CreateCircle(theCenter, theRadius);
2042 myFilledStatus = Standard_True;
2045 FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
2047 myCircle = theCircle;
2048 myFilledStatus = Standard_True;
2051 TopoDS_Face FilledCircle::ComputeFace()
2053 // Create edge from myCircle
2054 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
2055 TopoDS_Edge anEdge = anEdgeMaker.Edge();
2057 // Create wire from anEdge
2058 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
2059 TopoDS_Wire aWire = aWireMaker.Wire();
2061 // Create face from aWire
2062 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
2063 TopoDS_Face aFace = aFaceMaker.Face();
2068 void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
2069 const Handle(Prs3d_Presentation) &thePresentation,
2070 const Standard_Integer theMode)
2072 thePresentation->Clear();
2074 TopoDS_Face aFace = ComputeFace();
2076 if (aFace.IsNull()) return;
2077 if (theMode != 0) return;
2079 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2082 void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
2083 const Standard_Integer /*theMode*/)
2085 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2086 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2087 myCircle, myFilledStatus);
2088 theSelection->Add(aSensitiveCircle);
2091 //==============================================================================
2093 // ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2094 //==============================================================================
2096 //==============================================================================
2097 //function : VCircleBuilder
2098 //purpose : Build an AIS_Circle
2099 //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2100 // PointName PointName PointName IsFilled
2101 //==============================================================================
2103 void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2104 TCollection_AsciiString theName,
2105 Standard_Boolean isFilled)
2107 Handle(AIS_InteractiveObject) aCircle;
2110 aCircle = new FilledCircle(theGeomCircle);
2114 aCircle = new AIS_Circle(theGeomCircle);
2115 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
2118 // Check if there is an object with given name
2119 // and remove it from context
2120 if (GetMapOfAIS().IsBound2(theName))
2122 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2123 Handle(AIS_InteractiveObject) anInterObj =
2124 Handle(AIS_InteractiveObject)::DownCast(anObj);
2125 TheAISContext()->Remove(anInterObj, Standard_False);
2126 GetMapOfAIS().UnBind2(theName);
2129 // Bind the circle to its name
2130 GetMapOfAIS().Bind(aCircle, theName);
2132 // Display the circle
2133 TheAISContext()->Display(aCircle);
2137 static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
2139 Standard_Integer myCurrentIndex;
2140 // Verification of the arguments
2141 if (argc>6 || argc<2)
2143 std::cout << "vcircle error: expect 4 arguments.\n";
2144 return 1; // TCL_ERROR
2146 TheAISContext()->CloseAllContexts();
2148 // There are all arguments
2152 TCollection_AsciiString aName(argv[1]);
2153 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
2155 Handle(AIS_InteractiveObject) theShapeA;
2156 Handle(AIS_InteractiveObject) theShapeB;
2159 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2161 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2164 // Arguments: AIS_Point AIS_Point AIS_Point
2165 // ========================================
2166 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
2167 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2169 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2171 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2172 return 1; // TCL_ERROR
2174 // The third object must be a point
2175 Handle(AIS_InteractiveObject) theShapeC =
2176 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
2177 if (theShapeC.IsNull() ||
2178 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2180 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2181 return 1; // TCL_ERROR
2184 // Verify that the three points are different
2185 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2186 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2187 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2189 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2190 Handle(Geom_CartesianPoint) myCartPointA =
2191 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2193 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2194 Handle(Geom_CartesianPoint) myCartPointB =
2195 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2197 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2198 Handle(Geom_CartesianPoint) myCartPointC =
2199 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
2202 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2203 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2204 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
2206 std::cout << "vcircle error: Same points.\n";
2207 return 1; // TCL_ERROR
2210 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2211 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2212 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2214 std::cout << "vcircle error: Same points.\n";
2215 return 1; // TCL_ERROR
2218 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2219 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2220 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
2222 std::cout << "vcircle error: Same points.\n";
2223 return 1;// TCL_ERROR
2225 // Construction of the circle
2226 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2227 myCartPointB->Pnt(), myCartPointC->Pnt() );
2228 Handle (Geom_Circle) theGeomCircle;
2231 theGeomCircle = Cir.Value();
2233 catch (StdFail_NotDone)
2235 std::cout << "vcircle error: can't create circle\n";
2236 return -1; // TCL_ERROR
2239 DisplayCircle(theGeomCircle, aName, isFilled);
2242 // Arguments: AIS_Plane AIS_Point Real
2243 // ===================================
2244 else if (theShapeA->Type() == AIS_KOI_Datum &&
2245 theShapeA->Signature() == 7 )
2247 if (theShapeB->Type() != AIS_KOI_Datum ||
2248 theShapeB->Signature() != 1 )
2250 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2251 return 1; // TCL_ERROR
2253 // Check that the radius is >= 0
2254 if (Draw::Atof(argv[4]) <= 0 )
2256 std::cout << "vcircle error: the radius must be >=0.\n";
2257 return 1; // TCL_ERROR
2260 // Recover the normal to the plane
2261 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2262 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2264 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2265 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2266 Handle(Geom_CartesianPoint) myCartPointB =
2267 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2269 gp_Pln mygpPlane = myGeomPlane->Pln();
2270 gp_Ax1 thegpAxe = mygpPlane.Axis();
2271 gp_Dir theDir = thegpAxe.Direction();
2272 gp_Pnt theCenter = myCartPointB->Pnt();
2273 Standard_Real TheR = Draw::Atof(argv[4]);
2274 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2275 Handle (Geom_Circle) theGeomCircle;
2278 theGeomCircle = Cir.Value();
2280 catch (StdFail_NotDone)
2282 std::cout << "vcircle error: can't create circle\n";
2283 return -1; // TCL_ERROR
2286 DisplayCircle(theGeomCircle, aName, isFilled);
2293 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2294 return 1; // TCL_ERROR
2298 // No arguments: selection in the viewer
2299 // =========================================
2302 // Get the name of the circle
2303 TCollection_AsciiString aName(argv[1]);
2305 TheAISContext()->OpenLocalContext();
2306 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
2308 // Activate selection mode for vertices and faces
2309 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2310 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2311 std::cout << " Select a vertex or a face\n";
2314 Standard_Integer argcc = 5;
2315 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2316 const char **argvv = (const char **) buff;
2317 while (ViewerMainLoop( argcc, argvv) ) { }
2320 TopoDS_Shape ShapeA;
2321 for(TheAISContext()->InitSelected();
2322 TheAISContext()->MoreSelected();
2323 TheAISContext()->NextSelected() )
2325 ShapeA = TheAISContext()->SelectedShape();
2328 // ShapeA is a Vertex
2329 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2331 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2332 std::cout << " Select a different vertex\n";
2334 TopoDS_Shape ShapeB;
2338 Standard_Integer argccc = 5;
2339 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2340 const char **argvvv = (const char **) bufff;
2341 while (ViewerMainLoop( argccc, argvvv) ) { }
2344 for(TheAISContext()->InitSelected();
2345 TheAISContext()->MoreSelected();
2346 TheAISContext()->NextSelected() )
2348 ShapeB = TheAISContext()->SelectedShape();
2350 } while(ShapeB.IsSame(ShapeA) );
2352 // Selection of ShapeC
2353 std::cout << " Select the last vertex\n";
2354 TopoDS_Shape ShapeC;
2358 Standard_Integer argcccc = 5;
2359 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2360 const char **argvvvv = (const char **) buffff;
2361 while (ViewerMainLoop( argcccc, argvvvv) ) { }
2364 for(TheAISContext()->InitSelected();
2365 TheAISContext()->MoreSelected();
2366 TheAISContext()->NextSelected() )
2368 ShapeC = TheAISContext()->SelectedShape();
2370 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
2373 Standard_Boolean isFilled;
2374 std::cout << "Enter filled status (0 or 1)\n";
2377 // Close the local context
2378 TheAISContext()->CloseLocalContext(myCurrentIndex);
2380 // Construction of the circle
2381 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2382 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2383 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2385 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2386 Handle (Geom_Circle) theGeomCircle;
2389 theGeomCircle = Cir.Value();
2391 catch (StdFail_NotDone)
2393 std::cout << "vcircle error: can't create circle\n";
2394 return -1; // TCL_ERROR
2397 DisplayCircle(theGeomCircle, aName, isFilled);
2403 std::cout << " Select a vertex (in your face)\n";
2404 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2406 TopoDS_Shape ShapeB;
2408 Standard_Integer argccc = 5;
2409 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2410 const char **argvvv = (const char **) bufff;
2411 while (ViewerMainLoop( argccc, argvvv) ) { }
2414 for(TheAISContext()->InitSelected();
2415 TheAISContext()->MoreSelected();
2416 TheAISContext()->NextSelected() )
2418 ShapeB = TheAISContext()->SelectedShape();
2421 // Recover the radius
2422 Standard_Real theRad;
2425 std::cout << " Enter the value of the radius:\n";
2427 } while (theRad <= 0);
2429 // Get filled status
2430 Standard_Boolean isFilled;
2431 std::cout << "Enter filled status (0 or 1)\n";
2434 // Close the local context
2435 TheAISContext()->CloseLocalContext(myCurrentIndex);
2436 // Construction of the circle
2438 // Recover the normal to the plane. tag
2439 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2440 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2441 gp_Pln myPlane = mySurface.Plane();
2442 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
2443 gp_Pln mygpPlane = theGeomPlane->Pln();
2444 gp_Ax1 thegpAxe = mygpPlane.Axis();
2445 gp_Dir theDir = thegpAxe.Direction();
2447 // Recover the center
2448 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2450 // Construct the circle
2451 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2452 Handle (Geom_Circle) theGeomCircle;
2455 theGeomCircle = Cir.Value();
2457 catch (StdFail_NotDone)
2459 std::cout << "vcircle error: can't create circle\n";
2460 return -1; // TCL_ERROR
2463 DisplayCircle(theGeomCircle, aName, isFilled);
2472 //=======================================================================
2473 //function : VDrawText
2475 //=======================================================================
2476 static int VDrawText (Draw_Interpretor& theDI,
2477 Standard_Integer theArgsNb,
2478 const char** theArgVec)
2480 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2483 std::cout << "Error: wrong number of arguments! See usage:\n";
2484 theDI.PrintHelp (theArgVec[0]);
2487 else if (aContext.IsNull())
2489 std::cout << "Error: no active view!\n";
2493 Standard_Integer anArgIt = 1;
2494 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2495 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2496 Handle(AIS_TextLabel) aTextPrs;
2497 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
2499 if (GetMapOfAIS().IsBound2 (aName))
2501 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2505 aTextPrs = new AIS_TextLabel();
2506 aTextPrs->SetFont ("Courier");
2509 aTextPrs->SetText (aText);
2511 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
2513 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2516 Standard_Boolean aHasPlane = Standard_False;
2521 for (; anArgIt < theArgsNb; ++anArgIt)
2523 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2526 if (anAutoUpdater.parseRedrawMode (aParam))
2530 else if (aParam == "-pos"
2531 || aParam == "-position")
2533 if (anArgIt + 3 >= theArgsNb)
2535 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2539 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2540 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2541 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2542 aTextPrs->SetPosition (aPos);
2544 else if (aParam == "-color")
2546 if (anArgIt + 1 >= theArgsNb)
2548 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2552 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2553 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2554 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2557 aTextPrs->SetColor (aNameOfColor);
2560 else if (anArgIt + 3 >= theArgsNb)
2562 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2566 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2567 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2568 if (!aColor.IsRealValue()
2569 || !aGreen.IsRealValue()
2570 || !aBlue.IsRealValue())
2572 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2576 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2580 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2583 else if (aParam == "-halign")
2585 if (++anArgIt >= theArgsNb)
2587 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2591 TCollection_AsciiString aType (theArgVec[anArgIt]);
2593 if (aType == "left")
2595 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2597 else if (aType == "center")
2599 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2601 else if (aType == "right")
2603 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2607 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2611 else if (aParam == "-valign")
2613 if (++anArgIt >= theArgsNb)
2615 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2619 TCollection_AsciiString aType (theArgVec[anArgIt]);
2623 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2625 else if (aType == "center")
2627 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2629 else if (aType == "bottom")
2631 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2633 else if (aType == "topfirstline")
2635 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2639 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2643 else if (aParam == "-angle")
2645 if (++anArgIt >= theArgsNb)
2647 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2651 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2653 else if (aParam == "-zoom")
2655 if (++anArgIt >= theArgsNb)
2657 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2661 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2663 else if (aParam == "-height")
2665 if (++anArgIt >= theArgsNb)
2667 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2671 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2673 else if (aParam == "-aspect")
2675 if (++anArgIt >= theArgsNb)
2677 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2681 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2682 anOption.LowerCase();
2683 if (anOption.IsEqual ("regular"))
2685 aTextPrs->SetFontAspect (Font_FA_Regular);
2687 else if (anOption.IsEqual ("bold"))
2689 aTextPrs->SetFontAspect (Font_FA_Bold);
2691 else if (anOption.IsEqual ("italic"))
2693 aTextPrs->SetFontAspect (Font_FA_Italic);
2695 else if (anOption.IsEqual ("bolditalic"))
2697 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2700 else if (aParam == "-font")
2702 if (++anArgIt >= theArgsNb)
2704 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2708 aTextPrs->SetFont (theArgVec[anArgIt]);
2710 else if (aParam == "-plane")
2712 if (anArgIt + 6 >= theArgsNb)
2714 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2718 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2719 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2720 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2721 aNormal.SetCoord (aX, aY, aZ);
2723 aX = Draw::Atof (theArgVec[++anArgIt]);
2724 aY = Draw::Atof (theArgVec[++anArgIt]);
2725 aZ = Draw::Atof (theArgVec[++anArgIt]);
2726 aDirection.SetCoord (aX, aY, aZ);
2728 aHasPlane = Standard_True;
2730 else if (aParam == "-flipping")
2732 aTextPrs->SetFlipping (Standard_True);
2734 else if (aParam == "-disptype"
2735 || aParam == "-displaytype")
2737 if (++anArgIt >= theArgsNb)
2739 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2742 TCollection_AsciiString aType (theArgVec[anArgIt]);
2744 if (aType == "subtitle")
2745 aDisplayType = Aspect_TODT_SUBTITLE;
2746 else if (aType == "decal")
2747 aDisplayType = Aspect_TODT_DEKALE;
2748 else if (aType == "blend")
2749 aDisplayType = Aspect_TODT_BLEND;
2750 else if (aType == "dimension")
2751 aDisplayType = Aspect_TODT_DIMENSION;
2752 else if (aType == "normal")
2753 aDisplayType = Aspect_TODT_NORMAL;
2756 std::cout << "Error: wrong display type '" << aType << "'.\n";
2760 else if (aParam == "-subcolor"
2761 || aParam == "-subtitlecolor")
2763 if (anArgIt + 1 >= theArgsNb)
2765 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2769 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2770 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2771 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2774 aTextPrs->SetColorSubTitle (aNameOfColor);
2777 else if (anArgIt + 3 >= theArgsNb)
2779 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2783 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2784 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2785 if (!aColor.IsRealValue()
2786 || !aGreen.IsRealValue()
2787 || !aBlue.IsRealValue())
2789 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2793 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2797 aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2800 else if (aParam == "-2d")
2802 aTrsfPersFlags = Graphic3d_TMF_2d;
2804 else if (aParam == "-trsfperspos"
2805 || aParam == "-perspos")
2807 if (anArgIt + 2 >= theArgsNb)
2809 std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2813 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2814 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2815 TCollection_AsciiString aZ = "0";
2816 if (!aX.IsIntegerValue()
2817 || !aY.IsIntegerValue())
2819 std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
2822 if (anArgIt + 1 < theArgsNb)
2824 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2825 if (aTemp.IsIntegerValue())
2831 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
2835 std::cout << "Error: unknown argument '" << aParam << "'\n";
2842 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2845 if (aTrsfPersFlags != Graphic3d_TMF_None)
2847 aTextPrs->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
2848 aTextPrs->SetDisplayType (aDisplayType);
2849 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
2850 if (aTextPrs->Position().Z() != 0)
2852 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
2855 else if (aTrsfPersFlags != aTextPrs->TransformPersistence().Flags)
2857 aTextPrs->SetTransformPersistence (aTrsfPersFlags);
2858 aTextPrs->SetDisplayType (Aspect_TODT_NORMAL);
2860 ViewerTest::Display (aName, aTextPrs, Standard_False);
2865 #include <gp_Pnt.hxx>
2866 #include <Graphic3d_ArrayOfPoints.hxx>
2867 #include <Graphic3d_ArrayOfPrimitives.hxx>
2868 #include <Graphic3d_ArrayOfTriangles.hxx>
2869 #include <Poly_Array1OfTriangle.hxx>
2870 #include <Poly_Triangle.hxx>
2871 #include <Poly_Triangulation.hxx>
2872 #include <TColgp_Array1OfPnt.hxx>
2873 #include <TShort_Array1OfShortReal.hxx>
2874 #include <TShort_HArray1OfShortReal.hxx>
2876 #include <AIS_Triangulation.hxx>
2877 #include <StdPrs_ToolTriangulatedShape.hxx>
2878 #include <Poly_Connect.hxx>
2879 #include <TColgp_Array1OfDir.hxx>
2880 #include <Graphic3d_GraphicDriver.hxx>
2882 #include <TColStd_Array1OfInteger.hxx>
2883 #include <TColStd_HArray1OfInteger.hxx>
2884 #include <Prs3d_ShadingAspect.hxx>
2885 #include <Graphic3d_MaterialAspect.hxx>
2886 #include <Graphic3d_AspectFillArea3d.hxx>
2888 #include <BRepPrimAPI_MakeCylinder.hxx>
2889 #include <TopoDS_Shape.hxx>
2890 #include <TopExp_Explorer.hxx>
2891 #include <TopAbs.hxx>
2892 #include <StdSelect_ShapeTypeFilter.hxx>
2893 #include <AIS_InteractiveObject.hxx>
2896 //===============================================================================================
2897 //function : CalculationOfSphere
2899 //purpose : Create a Sphere
2900 //===============================================================================================
2902 Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
2905 double mRadius = Radius;
2906 double mCenter[3] = {X,Y,Z};
2907 int mThetaResolution;
2909 double mStartTheta = 0;//StartTheta;
2910 double mEndTheta = 360;//EndTheta;
2911 double mStartPhi = 0;//StartPhi;
2912 double mEndPhi = 180;//EndPhi;
2913 res = res < 4 ? 4 : res;
2915 mThetaResolution = res;
2916 mPhiResolution = res;
2919 int jStart, jEnd, numOffset;
2920 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2921 double startTheta, endTheta, startPhi, endPhi;
2922 int base, numPoles=0, thetaResolution, phiResolution;
2927 if ( numPieces > mThetaResolution ) {
2928 numPieces = mThetaResolution;
2931 int localThetaResolution = mThetaResolution;
2932 double localStartTheta = mStartTheta;
2933 double localEndTheta = mEndTheta;
2935 while ( localEndTheta < localStartTheta ) {
2936 localEndTheta += 360.0;
2939 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2941 // Change the ivars based on pieces.
2943 start = piece * localThetaResolution / numPieces;
2944 end = (piece+1) * localThetaResolution / numPieces;
2945 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2946 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2947 localThetaResolution = end - start;
2949 // Create north pole if needed
2950 int number_point = 0;
2951 int number_pointArray = 0;
2953 if ( mStartPhi <= 0.0 ) {
2954 number_pointArray++;
2957 if ( mEndPhi >= 180.0 ) {
2958 number_pointArray++;
2962 // Check data, determine increments, and convert to radians
2963 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
2964 startTheta *= M_PI / 180.0;
2965 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
2966 endTheta *= M_PI / 180.0;
2969 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
2970 startPhi *= M_PI / 180.0;
2971 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
2972 endPhi *= M_PI / 180.0;
2974 phiResolution = mPhiResolution - numPoles;
2975 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2976 thetaResolution = localThetaResolution;
2977 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2978 ++localThetaResolution;
2980 deltaTheta = (endTheta - startTheta) / thetaResolution;
2982 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2983 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2985 // Create intermediate points
2986 for ( i = 0; i < localThetaResolution; i++ ) {
2987 for ( j = jStart; j < jEnd; j++ ) {
2988 number_pointArray++;
2992 //Generate mesh connectivity
2993 base = phiResolution * localThetaResolution;
2995 int number_triangle = 0 ;
2996 if ( mStartPhi <= 0.0 ) { // around north pole
2997 number_triangle += localThetaResolution;
3000 if ( mEndPhi >= 180.0 ) { // around south pole
3001 number_triangle += localThetaResolution;
3004 // bands in-between poles
3005 for ( i=0; i < localThetaResolution; i++){
3006 for ( j=0; j < (phiResolution-1); j++){
3007 number_triangle +=2;
3011 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
3012 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
3013 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
3015 if ( mStartPhi <= 0.0 ){
3018 x[2] = mCenter[2] + mRadius;
3019 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
3022 // Create south pole if needed
3023 if ( mEndPhi >= 180.0 ){
3026 x[2] = mCenter[2] - mRadius;
3027 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
3031 for ( i=0; i < localThetaResolution; i++){
3032 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
3033 for ( j = jStart; j < jEnd; j++){
3034 phi = startPhi + j*deltaPhi;
3035 radius = mRadius * sin((double)phi);
3036 n[0] = radius * cos((double)theta);
3037 n[1] = radius * sin((double)theta);
3038 n[2] = mRadius * cos((double)phi);
3039 x[0] = n[0] + mCenter[0];
3040 x[1] = n[1] + mCenter[1];
3041 x[2] = n[2] + mCenter[2];
3042 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
3048 number_triangle = 1;
3049 if ( mStartPhi <= 0.0 ){// around north pole
3050 for (i=0; i < localThetaResolution; i++){
3051 pts[0] = phiResolution*i + numPoles;
3052 pts[1] = (phiResolution*(i+1) % base) + numPoles;
3054 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
3059 if ( mEndPhi >= 180.0 ){ // around south pole
3060 numOffset = phiResolution - 1 + numPoles;
3061 for (i=0; i < localThetaResolution; i++){
3062 pts[0] = phiResolution*i + numOffset;
3063 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
3064 pts[1] = numPoles - 1;
3065 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
3070 // bands in-between poles
3072 for (i=0; i < localThetaResolution; i++){
3073 for (j=0; j < (phiResolution-1); j++){
3074 pts[0] = phiResolution*i + j + numPoles;
3075 pts[1] = pts[0] + 1;
3076 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
3077 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
3080 pts[2] = pts[1] - 1;
3081 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
3086 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
3088 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
3090 Standard_Integer index[3];
3091 Standard_Real Tol = Precision::Confusion();
3094 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
3095 gp_XYZ eqPlan(0, 0, 0);
3096 for ( pc->Initialize(i); pc->More(); pc->Next()) {
3097 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
3098 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
3099 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
3101 Standard_Real mod = vv.Modulus();
3102 if(mod < Tol) continue;
3106 Standard_Real modmax = eqPlan.Modulus();
3109 Nor = gp_Dir(eqPlan);
3111 Nor = gp_Dir(0., 0., 1.);
3113 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
3114 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
3115 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
3116 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
3120 polyTriangulation->SetNormals(Normals);
3122 return polyTriangulation;
3125 //===============================================================================================
3126 //function : VDrawSphere
3128 //purpose : Create an AIS shape.
3129 //===============================================================================================
3130 static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
3133 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3134 if (aContextAIS.IsNull())
3136 std::cout << "Call vinit before!\n";
3141 std::cout << "Use: " << argv[0]
3142 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
3146 // read the arguments
3147 TCollection_AsciiString aShapeName (argv[1]);
3148 Standard_Integer aResolution = Draw::Atoi (argv[2]);
3149 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
3150 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
3151 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3152 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
3153 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3154 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
3156 // remove AIS object with given name from map
3157 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
3160 std::cout << "Compute Triangulation...\n";
3161 Handle(AIS_Triangulation) aShape
3162 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3165 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3166 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3168 // stupid initialization of Green color in RGBA space as integer
3169 // probably wrong for big-endian CPUs
3170 Standard_Integer aRed = 0;
3171 Standard_Integer aGreen = 255;
3172 Standard_Integer aBlue = 0;
3173 Standard_Integer anAlpha = 0; // not used
3174 Standard_Integer aColorInt = aRed;
3175 aColorInt += aGreen << 8;
3176 aColorInt += aBlue << 16;
3177 aColorInt += anAlpha << 24;
3179 // setup colors array per vertex
3180 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
3181 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
3183 aColorArray->SetValue (aNodeId, aColorInt);
3185 aShape->SetColors (aColorArray);
3188 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3189 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
3190 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
3191 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
3192 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
3193 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
3194 aTotalSize >>= 20; //MB
3195 aNormalsSize >>= 20;
3197 aTrianglesSize >>= 20;
3198 aPolyConnectSize >>= 20;
3201 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
3202 << "NumberOfTriangles: " << aNumberTriangles << "\n"
3203 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
3204 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
3205 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
3206 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
3209 // Setting material properties, very important for desirable visual result!
3210 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
3211 aMat.SetAmbient (0.2);
3212 aMat.SetSpecular (0.5);
3213 Handle(Graphic3d_AspectFillArea3d) anAspect
3214 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
3216 Quantity_NOC_YELLOW,
3221 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
3224 anAspect->SetEdgeOn();
3228 anAspect->SetEdgeOff();
3230 aShAsp->SetAspect (anAspect);
3231 aShape->Attributes()->SetShadingAspect (aShAsp);
3233 VDisplayAISObject (aShapeName, aShape);
3237 //=============================================================================
3238 //function : VComputeHLR
3240 //=============================================================================
3242 static int VComputeHLR (Draw_Interpretor& di,
3243 Standard_Integer argc,
3246 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3248 if (aContextAIS.IsNull ())
3250 di << "Please call vinit before\n";
3254 if ( argc != 3 && argc != 12 )
3256 di << "Usage: " << argv[0] << " ShapeName HlrName "
3257 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]\n"
3258 << " ShapeName - name of the initial shape\n"
3259 << " HlrName - result hlr object from initial shape\n"
3260 << " eye, dir are eye position and look direction\n"
3261 << " up is the look up direction vector\n"
3262 << " Use vtop to see projected hlr shape\n";
3266 // shape and new object name
3267 TCollection_AsciiString aShapeName (argv[1]);
3268 TCollection_AsciiString aHlrName (argv[2]);
3270 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3273 BRep_Builder aBrepBuilder;
3274 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3277 di << "No shape with name " << argv[1] << " found\n";
3282 if (GetMapOfAIS ().IsBound2 (aHlrName))
3284 di << "Presentable object with name " << argv[2] << " already exists\n";
3288 // close local context
3289 if (aContextAIS->HasOpenedContext ())
3290 aContextAIS->CloseLocalContext ();
3292 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3293 HLRBRep_PolyHLRToShape aHLRToShape;
3302 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3303 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3304 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3305 aProjAx.SetLocation (anEye);
3306 aProjAx.SetDirection (aDir);
3307 aProjAx.SetYDirection (anUp);
3313 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3314 Handle(V3d_View) aView = ViewerTest::CurrentView();
3315 Standard_Integer aWidth, aHeight;
3316 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3317 Standard_Real aRightX, aRightY, aRightZ;
3318 aView->Window()->Size (aWidth, aHeight);
3320 aView->ConvertWithProj (aWidth, aHeight/2,
3321 aRightX, aRightY, aRightZ,
3322 aDirX, aDirY, aDirZ);
3324 aView->ConvertWithProj (aWidth/2, aHeight/2,
3325 aCentX, aCentY, aCentZ,
3326 aDirX, aDirY, aDirZ);
3328 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3329 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3330 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3331 aProjAx.SetLocation (anEye);
3332 aProjAx.SetDirection (aDir);
3333 aProjAx.SetXDirection (aRight);
3336 HLRAlgo_Projector aProjector (aProjAx);
3337 aPolyAlgo->Projector (aProjector);
3338 aPolyAlgo->Load (aSh);
3339 aPolyAlgo->Update ();
3341 aHLRToShape.Update (aPolyAlgo);
3343 // make hlr shape from input shape
3344 TopoDS_Compound aHlrShape;
3345 BRep_Builder aBuilder;
3346 aBuilder.MakeCompound (aHlrShape);
3348 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3349 if (!aCompound.IsNull ())
3351 aBuilder.Add (aHlrShape, aCompound);
3354 // extract visible outlines
3355 aCompound = aHLRToShape.OutLineVCompound();
3356 if (!aCompound.IsNull ())
3358 aBuilder.Add (aHlrShape, aCompound);
3361 // create an AIS shape and display it
3362 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3363 GetMapOfAIS().Bind (anObject, aHlrName);
3364 aContextAIS->Display (anObject);
3366 aContextAIS->UpdateCurrentViewer ();
3371 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3372 // manipulating and displaying such an array with AIS context
3374 class MyPArrayObject : public AIS_InteractiveObject
3379 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
3380 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
3382 myArrayDescription = theArrayDescription;
3383 myMarkerAspect = theMarkerAspect;
3386 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
3390 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3391 const Handle(Prs3d_Presentation)& aPresentation,
3392 const Standard_Integer aMode) Standard_OVERRIDE;
3394 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3395 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
3397 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3398 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3399 Standard_Integer &theArgIndex,
3400 Standard_Integer theArgCount,
3401 Standard_Integer theMaxArgs);
3405 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
3406 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
3411 void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
3412 const Handle(Prs3d_Presentation)& aPresentation,
3413 const Standard_Integer /*aMode*/)
3416 // Parsing array description
3417 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
3418 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3419 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
3421 Standard_Integer anArgIndex = 0;
3422 Standard_Integer anArgsCount = myArrayDescription->Length();
3423 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3425 TCollection_AsciiString aCommand;
3426 while (anArgIndex < anArgsCount)
3428 aCommand = myArrayDescription->Value (anArgIndex);
3429 aCommand.LowerCase();
3432 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3434 // vertex has a normal or normal with color or texel
3435 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3436 hasNormals = Standard_True;
3438 // vertex has a color
3439 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3440 hasVColors = Standard_True;
3442 // vertex has a texel
3443 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3444 hasTexels = Standard_True;
3449 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3452 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3453 hasBColors = Standard_True;
3458 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3467 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3468 if (anArrayType == "points")
3470 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
3472 else if (anArrayType == "segments")
3473 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3474 else if (anArrayType == "polylines")
3475 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
3476 hasVColors, hasBColors);
3477 else if (anArrayType == "triangles")
3478 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
3479 hasVColors, hasTexels);
3480 else if (anArrayType == "trianglefans")
3481 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3482 hasNormals, hasVColors,
3483 hasBColors, hasTexels);
3484 else if (anArrayType == "trianglestrips")
3485 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3486 hasNormals, hasVColors,
3487 hasBColors, hasTexels);
3488 else if (anArrayType == "quads")
3489 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3490 hasNormals, hasVColors,
3492 else if (anArrayType == "quadstrips")
3493 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3494 hasNormals, hasVColors,
3495 hasBColors, hasTexels);
3496 else if (anArrayType == "polygons")
3497 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3498 hasNormals, hasVColors, hasBColors,
3502 while (anArgIndex < anArgsCount)
3504 aCommand = myArrayDescription->Value (anArgIndex);
3505 aCommand.LowerCase();
3506 if (!aCommand.IsAscii())
3510 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
3512 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3513 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3514 myArrayDescription->Value (anArgIndex - 1).RealValue());
3515 const Standard_Integer aVertIndex = anArray->VertexNumber();
3517 // vertex has a normal or normal with color or texel
3518 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
3519 anArray->SetVertexNormal (aVertIndex,
3520 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3521 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3522 myArrayDescription->Value (anArgIndex - 1).RealValue());
3524 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3525 anArray->SetVertexColor (aVertIndex,
3526 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3527 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3528 myArrayDescription->Value (anArgIndex - 1).RealValue());
3530 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
3531 anArray->SetVertexTexel (aVertIndex,
3532 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3533 myArrayDescription->Value (anArgIndex - 1).RealValue());
3536 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
3538 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3540 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
3541 anArray->AddBound (aVertCount,
3542 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3543 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3544 myArrayDescription->Value (anArgIndex - 1).RealValue());
3547 anArray->AddBound (aVertCount);
3550 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
3552 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3553 anArray->AddEdge (aVertIndex);
3560 aPresentation->Clear();
3561 if (!myMarkerAspect.IsNull())
3563 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3565 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3568 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3569 const Standard_Integer /*theMode*/)
3571 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3573 Standard_Integer anArgIndex = 1;
3574 while (anArgIndex < myArrayDescription->Length())
3576 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3578 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3579 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3580 myArrayDescription->Value (anArgIndex - 1).RealValue());
3581 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3582 theSelection->Add (aSensetivePoint);
3591 bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3592 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3593 Standard_Integer &theArgIndex,
3594 Standard_Integer theArgCount,
3595 Standard_Integer theMaxArgs)
3597 // check if there is more elements than expected
3598 if (theArgIndex >= theMaxArgs)
3601 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3602 aStrCommand.LowerCase();
3603 if (aStrCommand.Search(theCommand) != 1 ||
3604 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3607 // go to the first data element
3610 // check data if it can be converted to numeric
3611 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3613 aStrCommand = theArgsArray->Value (theArgIndex);
3614 if (!aStrCommand.IsRealValue())
3621 //=============================================================================
3622 //function : VDrawPArray
3623 //purpose : Draws primitives array from list of vertexes, bounds, edges
3624 //=============================================================================
3626 static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3628 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3629 if (aContextAIS.IsNull())
3631 di << "Call vinit before!\n";
3636 di << "Use: " << argv[0] << " Name TypeOfArray"
3637 << " [vertex] ... [bounds] ... [edges]\n"
3638 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3639 << " trianglefans | trianglestrips | quads |\n"
3640 << " quadstrips | polygons }\n"
3641 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3642 << " [texel={ 't' tx ty }] } \n"
3643 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
3644 << " edges={ 'e' vertex_id }\n";
3648 // read the arguments
3649 Standard_Integer aArgIndex = 1;
3650 TCollection_AsciiString aName (argv[aArgIndex++]);
3651 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3653 Standard_Boolean hasVertex = Standard_False;
3655 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3656 anArgsArray->SetValue (0, anArrayType);
3658 if (anArrayType != "points" &&
3659 anArrayType != "segments" &&
3660 anArrayType != "polylines" &&
3661 anArrayType != "triangles" &&
3662 anArrayType != "trianglefans" &&
3663 anArrayType != "trianglestrips" &&
3664 anArrayType != "quads" &&
3665 anArrayType != "quadstrips" &&
3666 anArrayType != "polygons")
3668 di << "Unexpected type of primitives array\n";
3672 TCollection_AsciiString aCommand;
3673 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3675 aCommand = argv[anArgIndex];
3676 aCommand.LowerCase();
3677 if (!aCommand.IsAscii())
3679 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3680 << "should be an array element: 'v', 'b', 'e' \n";
3684 if (aCommand == "v")
3686 hasVertex = Standard_True;
3689 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3694 di << "You should pass any verticies in the list of array elements\n";
3698 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3699 if (anArrayType == "points")
3701 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
3704 // create primitives array object
3705 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
3707 // register the object in map
3708 VDisplayAISObject (aName, aPObject);
3713 //=======================================================================
3714 //function : VSetLocation
3715 //purpose : Change location of AIS interactive object
3716 //=======================================================================
3718 static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
3719 Standard_Integer theArgNb,
3720 const char** theArgVec)
3722 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3723 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
3724 if (aContext.IsNull())
3726 std::cout << "Error: no active view!\n";
3730 TCollection_AsciiString aName;
3732 Standard_Boolean isSetLoc = Standard_False;
3734 Standard_Integer anArgIter = 1;
3735 for (; anArgIter < theArgNb; ++anArgIter)
3737 Standard_CString anArg = theArgVec[anArgIter];
3738 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3742 else if (aName.IsEmpty())
3748 isSetLoc = Standard_True;
3749 if (anArgIter + 1 >= theArgNb)
3751 std::cout << "Error: syntax error at '" << anArg << "'\n";
3754 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3755 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3756 if (anArgIter + 1 < theArgNb)
3758 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3763 std::cout << "Error: unknown argument '" << anArg << "'\n";
3769 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3770 Handle(AIS_InteractiveObject) anIObj;
3771 if (aMap.IsBound2 (aName))
3773 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
3775 if (anIObj.IsNull())
3777 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3782 aTrsf.SetTranslation (aLocVec);
3783 TopLoc_Location aLocation (aTrsf);
3784 aContext->SetLocation (anIObj, aLocation);
3788 //=======================================================================
3789 //function : TransformPresentation
3790 //purpose : Change transformation of AIS interactive object
3791 //=======================================================================
3792 static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3793 Standard_Integer theArgNb,
3794 const char** theArgVec)
3798 std::cout << "Error: too few arguments.\n";
3802 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3803 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3804 if (aContext.IsNull())
3806 std::cout << "Error: no active view!\n";
3811 Standard_Integer aLast = theArgNb;
3812 const char* aName = theArgVec[0];
3814 Standard_Boolean isReset = Standard_False;
3815 Standard_Boolean isMove = Standard_False;
3820 if (!strcmp (aName, "reset"))
3822 isReset = Standard_True;
3824 else if (!strcmp (aName, "move"))
3828 std::cout << "Error: too few arguments.\n";
3832 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3834 Handle(AIS_InteractiveObject) anIObj;
3835 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3837 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3840 if (anIObj.IsNull())
3842 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3846 isMove = Standard_True;
3848 aTrsf = anIObj->Transformation();
3849 aLast = theArgNb - 1;
3851 else if (!strcmp (aName, "translate"))
3855 std::cout << "Error: too few arguments.\n";
3858 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3859 Draw::Atof (theArgVec[theArgNb - 2]),
3860 Draw::Atof (theArgVec[theArgNb - 1])));
3861 aLast = theArgNb - 3;
3863 else if (!strcmp (aName, "rotate"))
3867 std::cout << "Error: too few arguments.\n";
3872 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3873 Draw::Atof (theArgVec[theArgNb - 6]),
3874 Draw::Atof (theArgVec[theArgNb - 5])),
3875 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3876 Draw::Atof (theArgVec[theArgNb - 3]),
3877 Draw::Atof (theArgVec[theArgNb - 2]))),
3878 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3880 aLast = theArgNb - 7;
3882 else if (!strcmp (aName, "mirror"))
3886 std::cout << "Error: too few arguments.\n";
3890 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3891 Draw::Atof(theArgVec[theArgNb - 5]),
3892 Draw::Atof(theArgVec[theArgNb - 4])),
3893 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3894 Draw::Atof(theArgVec[theArgNb - 2]),
3895 Draw::Atof(theArgVec[theArgNb - 1]))));
3896 aLast = theArgNb - 6;
3898 else if (!strcmp (aName, "scale"))
3902 std::cout << "Error: too few arguments.\n";
3906 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3907 Draw::Atof(theArgVec[theArgNb - 3]),
3908 Draw::Atof(theArgVec[theArgNb - 2])),
3909 Draw::Atof(theArgVec[theArgNb - 1]));
3910 aLast = theArgNb - 4;
3913 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3916 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3917 Handle(AIS_InteractiveObject) anIObj;
3918 if (aMap.IsBound2 (theArgVec[anIdx]))
3920 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3922 if (anIObj.IsNull())
3924 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3930 // aTrsf already identity
3934 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3938 aTrsf = anIObj->LocalTransformation() * aTrsf;
3941 TopLoc_Location aLocation (aTrsf);
3942 aContext->SetLocation (anIObj, aLocation);
3948 //===============================================================================================
3949 //function : VConnect
3950 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3951 //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
3952 //===============================================================================================
3954 static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3955 Standard_Integer argc,
3959 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3960 if (aContext.IsNull())
3962 std::cout << "vconnect error : call vinit before\n";
3963 return 1; // TCL_ERROR
3968 std::cout << "vconnect error: expect at least 5 arguments\n";
3969 return 1; // TCL_ERROR
3973 Standard_Integer anArgIter = 1;
3974 TCollection_AsciiString aName (argv[anArgIter++]);
3975 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
3976 TCollection_AsciiString aColorString (argv[argc-1]);
3977 Standard_CString aColorName = "";
3978 Standard_Boolean hasColor = Standard_False;
3979 if (aColorString.Search ("color=") != -1)
3981 hasColor = Standard_True;
3982 aColorString.Remove (1, 6);
3983 aColorName = aColorString.ToCString();
3985 Handle(AIS_InteractiveObject) anObject;
3987 // AIS_MultipleConnectedInteractive
3988 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3989 for (Standard_Integer i = 5; i < aNbShapes; ++i)
3991 TCollection_AsciiString anOriginObjectName (argv[i]);
3992 if (aName.IsEqual (anOriginObjectName))
3994 std::cout << "vconnect error: equal names for connected objects\n";
3997 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3999 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
4000 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
4001 if (anObject.IsNull())
4003 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4009 Standard_CString aOriginName = anOriginObjectName.ToCString();
4010 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4011 if (aTDShape.IsNull())
4013 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4016 anObject = new AIS_Shape (aTDShape);
4017 aContext->Load (anObject);
4018 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
4021 if (anOriginObject.IsNull())
4023 anOriginObject = new AIS_MultipleConnectedInteractive();
4026 anOriginObject->Connect (anObject);
4028 if (anOriginObject.IsNull())
4030 std::cout << "vconect error : can't connect input objects\n";
4031 return 1; // TCL_ERROR
4034 // Get location data
4035 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4036 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4037 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4039 // Create transformation
4040 gp_Vec aTranslation (aXo, aYo, aZo);
4043 aTrsf.SetTranslationPart (aTranslation);
4044 TopLoc_Location aLocation (aTrsf);
4046 anOriginObject->SetLocalTransformation (aTrsf);
4048 // Check if there is another object with given name
4049 // and remove it from context
4050 if(GetMapOfAIS().IsBound2(aName))
4052 Handle(AIS_InteractiveObject) anObj =
4053 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
4054 TheAISContext()->Remove(anObj, Standard_False);
4055 GetMapOfAIS().UnBind2(aName);
4058 // Bind connected object to its name
4059 GetMapOfAIS().Bind (anOriginObject, aName);
4061 // Display connected object
4062 TheAISContext()->Display (anOriginObject);
4067 //===============================================================================================
4068 //function : VConnectTo
4069 //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
4070 //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
4071 //===============================================================================================
4073 static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
4074 Standard_Integer argc,
4078 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4079 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4080 if (aContext.IsNull())
4082 std::cout << "vconnect error : call vinit before\n";
4083 return 1; // TCL_ERROR
4086 if (argc != 6 && argc != 7)
4088 std::cout << "vconnect error: expect at least 5 arguments\n";
4089 return 1; // TCL_ERROR
4093 Standard_Integer anArgIter = 1;
4094 TCollection_AsciiString aName (argv[anArgIter++]);
4095 Handle(AIS_InteractiveObject) anOriginObject;
4097 TCollection_AsciiString anOriginObjectName(argv[5]);
4098 if (aName.IsEqual (anOriginObjectName))
4100 std::cout << "vconnect error: equal names for connected objects\n";
4101 return 1; // TCL_ERROR
4103 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
4105 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
4106 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
4107 if (anOriginObject.IsNull())
4109 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
4110 return 1; // TCL_ERROR
4115 Standard_CString aOriginName = anOriginObjectName.ToCString();
4116 TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
4117 if (aTDShape.IsNull())
4119 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
4120 return 1; // TCL_ERROR
4122 anOriginObject = new AIS_Shape (aTDShape);
4123 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
4126 // Get location data
4127 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
4128 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
4129 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
4131 // Create transformation
4132 gp_Vec aTranslation (aXo, aYo, aZo);
4135 aTrsf.SetTranslationPart (aTranslation);
4137 Handle(AIS_ConnectedInteractive) aConnected;
4139 aConnected = new AIS_ConnectedInteractive();
4141 aConnected->Connect (anOriginObject, aTrsf);
4143 // Check if there is another object with given name
4144 // and remove it from context
4145 if(GetMapOfAIS().IsBound2(aName))
4147 Handle(AIS_InteractiveObject) anObj =
4148 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
4149 TheAISContext()->Remove(anObj, Standard_False);
4150 GetMapOfAIS().UnBind2(aName);
4153 // Bind connected object to its name
4154 GetMapOfAIS().Bind (aConnected, aName);
4158 TCollection_AsciiString anArg = argv[6];
4160 if (anArg == "-nodisplay")
4163 if (!anUpdateTool.parseRedrawMode (anArg))
4165 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
4169 // Display connected object
4170 TheAISContext()->Display (aConnected, Standard_False);
4175 //=======================================================================
4176 //function : VDisconnect
4178 //=======================================================================
4179 static Standard_Integer VDisconnect (Draw_Interpretor& di,
4180 Standard_Integer argc,
4183 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4184 if (aContext.IsNull())
4186 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4192 std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
4196 TCollection_AsciiString aName (argv[1]);
4197 TCollection_AsciiString anObject (argv[2]);
4198 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
4201 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4202 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4203 if (!aMap.IsBound2 (aName) )
4205 std::cout << "Use 'vdisplay' before\n";
4209 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4210 if (anAssembly.IsNull())
4212 di << "Not an assembly\n";
4216 Handle(AIS_InteractiveObject) anIObj;
4217 if (!aMap.IsBound2 (anObject))
4219 // try to interpret second argument as child number
4220 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
4222 Standard_Integer aCounter = 1;
4223 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4225 if (aCounter == anObjectNumber)
4227 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
4235 std::cout << "Use 'vdisplay' before\n";
4240 // if object was found by name
4241 if (anIObj.IsNull())
4243 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4246 aContext->Disconnect (anAssembly, anIObj);
4247 aContext->UpdateCurrentViewer();
4252 //=======================================================================
4253 //function : VAddConnected
4255 //=======================================================================
4256 static Standard_Integer VAddConnected (Draw_Interpretor& di,
4257 Standard_Integer argc,
4260 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4261 if (aContext.IsNull())
4263 std::cout << argv[0] << "error : use 'vinit' command before \n";
4269 std::cout << argv[0] << " error: expect 5 arguments\n";
4273 TCollection_AsciiString aName (argv[1]);
4274 TCollection_AsciiString anObject (argv[5]);
4275 Standard_Real aX = Draw::Atof (argv[2]);
4276 Standard_Real aY = Draw::Atof (argv[3]);
4277 Standard_Real aZ = Draw::Atof (argv[4]);
4280 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4281 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4282 if (!aMap.IsBound2 (aName) )
4284 std::cout << "Use 'vdisplay' before\n";
4288 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4289 if (anAssembly.IsNull())
4291 di << "Not an assembly\n";
4295 Handle(AIS_InteractiveObject) anIObj;
4296 if (!aMap.IsBound2 (anObject))
4298 std::cout << "Use 'vdisplay' before\n";
4302 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4305 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4307 anAssembly->Connect (anIObj, aTrsf);
4308 TheAISContext()->Display (anAssembly);
4309 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4310 aContext->UpdateCurrentViewer();
4315 //=======================================================================
4316 //function : VListConnected
4318 //=======================================================================
4319 static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
4320 Standard_Integer argc,
4323 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4324 if (aContext.IsNull())
4326 std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
4332 std::cout << "ERROR : Usage : " << argv[0] << " name\n";
4336 TCollection_AsciiString aName (argv[1]);
4339 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4340 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4341 if (!aMap.IsBound2 (aName) )
4343 std::cout << "Use 'vdisplay' before\n";
4347 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4348 if (anAssembly.IsNull())
4350 std::cout << "Not an assembly\n";
4354 std::cout << "Children of " << aName << ":\n";
4356 Standard_Integer aCounter = 1;
4357 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4359 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4361 TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anIter.Value());
4362 std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4365 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4367 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4368 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4370 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4372 std::cout << std::endl;
4382 //! Checks if theMode is already turned on for theObj.
4383 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4384 const Handle(AIS_InteractiveObject)& theObj,
4385 const Standard_Integer theMode)
4387 TColStd_ListOfInteger anActiveModes;
4388 theAISContext->ActivatedModes (theObj, anActiveModes);
4389 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4391 if (aModeIt.Value() == theMode)
4393 return Standard_True;
4396 return Standard_False;
4400 //===============================================================================================
4401 //function : VSetSelectionMode
4402 //purpose : Sets input selection mode for input object or for all displayed objects
4403 //Draw arg : vselmode [object] mode On/Off (1/0)
4404 //===============================================================================================
4405 static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4406 Standard_Integer theArgc,
4407 const char** theArgv)
4410 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4411 if (anAISContext.IsNull())
4413 std::cerr << "Call vinit before!" << std::endl;
4417 // Check the arguments
4418 if (theArgc < 3 && theArgc > 5)
4420 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4421 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
4425 TCollection_AsciiString aLastArg (theArgv[theArgc - 1]);
4426 aLastArg.LowerCase();
4427 Standard_Boolean isToOpenLocalCtx = aLastArg == "-local";
4429 // get objects to change selection mode
4430 AIS_ListOfInteractive aTargetIOs;
4431 Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc;
4434 anAISContext->DisplayedObjects (aTargetIOs);
4438 // Check if there is an object with given name in context
4439 const TCollection_AsciiString aNameIO (theArgv[1]);
4440 if (GetMapOfAIS().IsBound2 (aNameIO))
4442 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4445 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
4448 aTargetIOs.Append (anIO);
4452 const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]);
4453 const Standard_Boolean toTurnOn = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]);
4454 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4456 anAISContext->CloseLocalContext();
4459 if (aSelectionMode == 0)
4463 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4465 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4466 TColStd_ListOfInteger anActiveModes;
4467 anAISContext->ActivatedModes (anIO, anActiveModes);
4468 if (!anActiveModes.IsEmpty())
4470 anAISContext->Deactivate (anIO);
4472 if (!InList (anAISContext, anIO, aSelectionMode))
4474 anAISContext->Activate (anIO);
4480 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4482 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4483 if (InList (anAISContext, anIO, aSelectionMode))
4485 anAISContext->Deactivate (anIO);
4491 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
4493 if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx)
4495 anAISContext->OpenLocalContext (Standard_False);
4498 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4500 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4501 if (InList (anAISContext, anIO, 0))
4503 anAISContext->Deactivate (anIO, 0);
4505 if (!InList (anAISContext, anIO, aSelectionMode))
4507 anAISContext->Load (anIO, -1, Standard_True);
4508 anAISContext->Activate (anIO, aSelectionMode);
4513 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4515 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4517 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4518 if (InList (anAISContext, anIO, aSelectionMode))
4520 anAISContext->Deactivate (anIO, aSelectionMode);
4528 //===============================================================================================
4529 //function : VSelectionNext
4531 //===============================================================================================
4532 static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4533 Standard_Integer /*theArgsNb*/,
4534 const char** /*theArgVec*/)
4537 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4538 Handle(V3d_View) aView = ViewerTest::CurrentView();
4540 if (anAISContext.IsNull())
4542 std::cerr << "Call vinit before!" << std::endl;
4546 anAISContext->HilightNextDetected(aView);
4550 //===============================================================================================
4551 //function : VSelectionPrevious
4553 //===============================================================================================
4554 static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4555 Standard_Integer /*theArgsNb*/,
4556 const char** /*theArgVec*/)
4559 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4560 Handle(V3d_View) aView = ViewerTest::CurrentView();
4562 if (anAISContext.IsNull())
4564 std::cerr << "Call vinit before!" << std::endl;
4568 anAISContext->HilightPreviousDetected(aView);
4573 //==========================================================================
4575 //purpose : creates Triangle based on AIS_InteractiveObject.
4576 // This class was implemented for testing Select3D_SensitiveTriangle
4577 //===========================================================================
4579 class Triangle: public AIS_InteractiveObject
4583 DEFINE_STANDARD_RTTI_INLINE(Triangle,AIS_InteractiveObject);
4584 Triangle (const gp_Pnt& theP1,
4585 const gp_Pnt& theP2,
4586 const gp_Pnt& theP3);
4588 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4589 const Handle(Prs3d_Presentation)& thePresentation,
4590 const Standard_Integer theMode) Standard_OVERRIDE;
4592 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4593 const Standard_Integer theMode) Standard_OVERRIDE;
4601 Triangle::Triangle (const gp_Pnt& theP1,
4602 const gp_Pnt& theP2,
4603 const gp_Pnt& theP3)
4610 void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4611 const Handle(Prs3d_Presentation)& thePresentation,
4612 const Standard_Integer /*theMode*/)
4614 thePresentation->Clear();
4616 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4617 anEdgeMaker2(myPoint2, myPoint3),
4618 anEdgeMaker3(myPoint3, myPoint1);
4620 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4621 anEdge2 = anEdgeMaker2.Edge(),
4622 anEdge3 = anEdgeMaker3.Edge();
4623 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4626 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4627 TopoDS_Wire aWire = aWireMaker.Wire();
4628 if(aWire.IsNull()) return;
4630 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4631 TopoDS_Face aFace = aFaceMaker.Face();
4632 if(aFace.IsNull()) return;
4634 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4637 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
4638 const Standard_Integer /*theMode*/)
4640 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4641 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4642 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4643 theSelection->Add(aSensTriangle);
4646 //===========================================================================
4647 //function : VTriangle
4648 //Draw arg : vtriangle Name PointName PointName PointName
4649 //purpose : creates and displays Triangle
4650 //===========================================================================
4653 //purpose : checks if the object with theName is AIS_Point,
4654 // if yes initialize thePoint from MapOfAIS
4655 Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4656 Handle(AIS_Point)& thePoint)
4658 Handle(AIS_InteractiveObject) anObject =
4659 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4660 if(anObject.IsNull() ||
4661 anObject->Type() != AIS_KOI_Datum ||
4662 anObject->Signature() != 1)
4664 return Standard_False;
4666 thePoint = Handle(AIS_Point)::DownCast(anObject);
4667 if(thePoint.IsNull())
4668 return Standard_False;
4669 return Standard_True;
4673 //purpose: checks if thePoint1 is equal to thePoint2
4674 Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4675 const Handle(Geom_CartesianPoint)& thePoint2)
4677 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4678 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4679 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
4681 return Standard_True;
4683 return Standard_False;
4686 static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
4687 Standard_Integer argc,
4693 std::cout<<"vtriangle error: expects 4 argumnets\n";
4694 return 1; // TCL_ERROR
4697 TheAISContext()->CloseAllContexts();
4699 // Get and check values
4700 TCollection_AsciiString aName(argv[1]);
4702 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4703 if (!IsPoint(argv[2], aPoint1))
4705 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4706 return 1; // TCL_ERROR
4708 if (!IsPoint(argv[3], aPoint2))
4710 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4711 return 1; // TCL_ERROR
4713 if (!IsPoint(argv[4], aPoint3))
4715 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4716 return 1; // TCL_ERROR
4719 // Check that points are different
4720 Handle(Geom_CartesianPoint) aCartPoint1 =
4721 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4722 Handle(Geom_CartesianPoint) aCartPoint2 =
4723 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4724 // Test aPoint1 = aPoint2
4725 if (IsMatch(aCartPoint1, aCartPoint2))
4727 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4728 return 1; // TCL_ERROR
4730 // Test aPoint2 = aPoint3
4731 Handle(Geom_CartesianPoint) aCartPoint3 =
4732 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4733 if (IsMatch(aCartPoint2, aCartPoint3))
4735 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4736 return 1; // TCL_ERROR
4738 // Test aPoint3 = aPoint1
4739 if (IsMatch(aCartPoint1, aCartPoint3))
4741 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4742 return 1; // TCL_ERROR
4746 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4748 aCartPoint3->Pnt());
4750 // Check if there is an object with given name
4751 // and remove it from context
4752 if (GetMapOfAIS().IsBound2(aName))
4754 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4755 Handle(AIS_InteractiveObject) anInterObj =
4756 Handle(AIS_InteractiveObject)::DownCast(anObj);
4757 TheAISContext()->Remove(anInterObj, Standard_False);
4758 GetMapOfAIS().UnBind2(aName);
4761 // Bind triangle to its name
4762 GetMapOfAIS().Bind(aTriangle, aName);
4765 TheAISContext()->Display(aTriangle);
4769 //class : SegmentObject
4770 //purpose: creates segment based on AIS_InteractiveObject.
4771 // This class was implemented for testing Select3D_SensitiveCurve
4773 class SegmentObject: public AIS_InteractiveObject
4777 DEFINE_STANDARD_RTTI_INLINE(SegmentObject,AIS_InteractiveObject);
4778 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4780 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4781 const Handle(Prs3d_Presentation)& thePresentation,
4782 const Standard_Integer theMode) Standard_OVERRIDE;
4784 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4785 const Standard_Integer theMode) Standard_OVERRIDE;
4792 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4798 void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4799 const Handle(Prs3d_Presentation) &thePresentation,
4800 const Standard_Integer /*theMode*/)
4802 thePresentation->Clear();
4803 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4804 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4805 if (anEdge.IsNull())
4807 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4808 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4811 void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
4812 const Standard_Integer /*theMode*/)
4814 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4815 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4816 anArray->SetValue(1, myPoint1);
4817 anArray->SetValue(2, myPoint2);
4818 Handle(Select3D_SensitiveCurve) aSensCurve =
4819 new Select3D_SensitiveCurve(anOwner, anArray);
4820 theSelection->Add(aSensCurve);
4823 //=======================================================================
4824 //function : VSegment
4825 //Draw args : vsegment Name PointName PointName
4826 //purpose : creates and displays Segment
4827 //=======================================================================
4828 static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
4829 Standard_Integer argc,
4835 std::cout<<"vsegment error: expects 3 arguments\n";
4836 return 1; // TCL_ERROR
4839 TheAISContext()->CloseAllContexts();
4841 // Get and check arguments
4842 TCollection_AsciiString aName(argv[1]);
4843 Handle(AIS_Point) aPoint1, aPoint2;
4844 if (!IsPoint(argv[2], aPoint1))
4846 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4847 return 1; // TCL_ERROR
4849 if (!IsPoint(argv[3], aPoint2))
4851 std::cout<<"vsegment error: the 3d argument should be a point\n";
4852 return 1; // TCL_ERROR
4854 //Check that points are different
4855 Handle(Geom_CartesianPoint) aCartPoint1 =
4856 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4857 Handle(Geom_CartesianPoint) aCartPoint2 =
4858 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4859 if(IsMatch(aCartPoint1, aCartPoint2))
4861 std::cout<<"vsegment error: equal points\n";
4862 return 1; // TCL_ERROR
4866 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4867 // Check if there is an object with given name
4868 // and remove it from context
4869 if (GetMapOfAIS().IsBound2(aName))
4871 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4872 Handle(AIS_InteractiveObject) anInterObj =
4873 Handle(AIS_InteractiveObject)::DownCast(anObj);
4874 TheAISContext()->Remove(anInterObj, Standard_False);
4875 GetMapOfAIS().UnBind2(aName);
4878 // Bind segment to its name
4879 GetMapOfAIS().Bind(aSegment, aName);
4882 TheAISContext()->Display(aSegment);
4886 //=======================================================================
4887 //function : VObjZLayer
4888 //purpose : Set or get z layer id for presentable object
4889 //=======================================================================
4891 static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4892 Standard_Integer argc,
4895 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4896 if (aContext.IsNull())
4898 di << argv[0] << "Call 'vinit' before!\n";
4903 TCollection_AsciiString aOperation;
4905 aOperation = TCollection_AsciiString (argv [1]);
4907 // check for correct arguments
4908 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4909 !(argc == 3 && aOperation.IsEqual ("get")))
4911 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4912 di << " set - set layer id for interactive object, layerid - z layer id\n";
4913 di << " get - get layer id of interactive object\n";
4914 di << " argument layerid should be passed for set operation only\n";
4919 TCollection_AsciiString aName (argv[2]);
4920 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4921 if (!aMap.IsBound2 (aName))
4923 di << "Use 'vdisplay' before\n";
4927 // find interactive object
4928 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4929 Handle(AIS_InteractiveObject) anInterObj =
4930 Handle(AIS_InteractiveObject)::DownCast (anObj);
4931 if (anInterObj.IsNull())
4933 di << "Not an AIS interactive object!\n";
4937 // process operation
4938 if (aOperation.IsEqual ("set"))
4940 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
4941 aContext->SetZLayer (anInterObj, aLayerId);
4943 else if (aOperation.IsEqual ("get"))
4945 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4951 //=======================================================================
4952 //function : VPolygonOffset
4953 //purpose : Set or get polygon offset parameters
4954 //=======================================================================
4955 static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
4956 Standard_Integer argc,
4959 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4960 if (aContext.IsNull())
4962 std::cout << argv[0] << " Call 'vinit' before!\n";
4966 if (argc > 2 && argc != 5)
4968 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4969 "without arguments prints the default values" << std::endl;
4974 Handle(AIS_InteractiveObject) anInterObj;
4977 TCollection_AsciiString aName (argv[1]);
4978 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4979 if (!aMap.IsBound2 (aName))
4981 std::cout << "Use 'vdisplay' before" << std::endl;
4985 // find interactive object
4986 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4987 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4988 if (anInterObj.IsNull())
4990 std::cout << "Not an AIS interactive object!" << std::endl;
4995 Standard_Integer aMode;
4996 Standard_ShortReal aFactor, aUnits;
4999 aMode = Draw::Atoi(argv[2]);
5000 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
5001 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
5003 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
5004 aContext->UpdateCurrentViewer();
5009 if (anInterObj->HasPolygonOffsets())
5011 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
5012 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
5013 std::cout << "\tMode: " << aMode << std::endl;
5014 std::cout << "\tFactor: " << aFactor << std::endl;
5015 std::cout << "\tUnits: " << aUnits << std::endl;
5020 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
5024 std::cout << "Default polygon offset parameters:" << std::endl;
5025 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
5026 std::cout << "\tMode: " << aMode << std::endl;
5027 std::cout << "\tFactor: " << aFactor << std::endl;
5028 std::cout << "\tUnits: " << aUnits << std::endl;
5033 //=======================================================================
5034 //function : VShowFaceBoundaries
5035 //purpose : Set face boundaries drawing on/off for ais object
5036 //=======================================================================
5037 static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
5038 Standard_Integer argc,
5041 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
5042 if (aContext.IsNull ())
5044 std::cout << argv[0] << " Call 'vinit' before!\n";
5048 if ((argc != 3 && argc < 6) || argc > 8)
5050 std::cout << "Usage :\n " << argv[0]
5051 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
5052 << " ObjectName - name of AIS interactive object. \n"
5053 << " if ObjectName = \"\", then set as default\n"
5054 << " settings for all newly displayed objects\n"
5055 << " isOn - flag indicating whether the boundaries\n"
5056 << " should be turned on or off (can be set\n"
5057 << " to 0 (off) or 1 (on)).\n"
5058 << " R, G, B - red, green and blue components of boundary\n"
5059 << " color in range (0 - 255).\n"
5060 << " (default is (0, 0, 0)\n"
5061 << " LineWidth - line width\n"
5062 << " (default is 1)\n"
5063 << " LineStyle - line fill style :\n"
5068 << " (default is solid)";
5072 TCollection_AsciiString aName (argv[1]);
5074 Quantity_Parameter aRed = 0.0;
5075 Quantity_Parameter aGreen = 0.0;
5076 Quantity_Parameter aBlue = 0.0;
5077 Standard_Real aWidth = 1.0;
5078 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5081 Handle(AIS_InteractiveObject) anInterObj;
5083 // if name is empty - apply attributes for default aspect
5084 if (!aName.IsEmpty ())
5086 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
5087 if (!aMap.IsBound2 (aName))
5089 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
5093 // find interactive object
5094 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
5095 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
5096 if (anInterObj.IsNull ())
5098 std::cout << "Not an AIS interactive object!" << std::endl;
5103 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
5104 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
5106 // turn boundaries on/off
5107 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
5108 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
5110 // set boundary line color
5114 aRed = Draw::Atof (argv[3])/255.;
5115 aGreen = Draw::Atof (argv[4])/255.;
5116 aBlue = Draw::Atof (argv[5])/255.;
5122 aWidth = (Standard_Real)Draw::Atof (argv[6]);
5125 // select appropriate line type
5128 switch (Draw::Atoi (argv[7]))
5130 case 1: aLineType = Aspect_TOL_DASH; break;
5131 case 2: aLineType = Aspect_TOL_DOT; break;
5132 case 3: aLineType = Aspect_TOL_DOTDASH; break;
5134 aLineType = Aspect_TOL_SOLID;
5138 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
5140 Handle(Prs3d_LineAspect) aBoundaryAspect =
5141 new Prs3d_LineAspect (aColor, aLineType, aWidth);
5143 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
5145 TheAISContext()->Redisplay (anInterObj);
5150 // This class is used for testing markers.
5152 class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
5157 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
5158 const Standard_Integer& thePointsOnSide,
5159 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
5161 myStartPoint = theStartPoint;
5162 myPointsOnSide = thePointsOnSide;
5163 myMarkerAspect = theMarkerAspect;
5166 DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
5170 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
5171 const Handle(Prs3d_Presentation)& aPresentation,
5172 const Standard_Integer aMode) Standard_OVERRIDE;
5174 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5175 const Standard_Integer /*theMode*/) Standard_OVERRIDE;
5179 gp_XYZ myStartPoint;
5180 Standard_Integer myPointsOnSide;
5181 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
5185 void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5186 const Handle(Prs3d_Presentation)& aPresentation,
5187 const Standard_Integer /*aMode*/)
5189 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
5190 if (myPointsOnSide == 1)
5192 anArray->AddVertex (myStartPoint);
5196 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5198 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5200 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5202 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5203 anArray->SetVertexColor (anArray->VertexNumber(),
5206 k / myPointsOnSide);
5212 aPresentation->Clear();
5213 if (!myMarkerAspect.IsNull())
5215 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
5217 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
5220 void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
5221 const Standard_Integer /*theMode*/)
5223 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
5225 if (myPointsOnSide == 1)
5227 gp_Pnt aPoint (myStartPoint);
5228 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5229 theSelection->Add (aSensetivePoint);
5233 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
5235 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
5237 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5239 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5240 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5241 theSelection->Add (aSensetivePoint);
5247 //=======================================================================
5248 //function : VMarkersTest
5249 //purpose : Draws an array of markers for testing purposes.
5250 //=======================================================================
5251 static Standard_Integer VMarkersTest (Draw_Interpretor&,
5252 Standard_Integer theArgNb,
5253 const char** theArgVec)
5255 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5256 if (aContext.IsNull())
5258 std::cerr << "Call 'vinit' before!\n";
5264 std::cerr << "Usage :\n " << theArgVec[0]
5265 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5269 Standard_Integer anArgIter = 1;
5271 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5272 TCollection_AsciiString aFileName;
5273 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5274 Atof (theArgVec[anArgIter + 1]),
5275 Atof (theArgVec[anArgIter + 2]));
5278 Standard_Integer aPointsOnSide = 10;
5279 Standard_Integer aMarkerType = -1;
5280 Standard_Real aScale = 1.0;
5281 for (; anArgIter < theArgNb; ++anArgIter)
5283 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5284 if (anArg.Search ("PointsOnSide=") > -1)
5286 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5288 else if (anArg.Search ("MarkerType=") > -1)
5290 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5292 else if (anArg.Search ("Scale=") > -1)
5294 aScale = anArg.Token ("=", 2).RealValue();
5296 else if (anArg.Search ("FileName=") > -1)
5298 aFileName = anArg.Token ("=", 2);
5302 std::cerr << "Wrong argument: " << anArg << "\n";
5307 Handle(Graphic3d_AspectMarker3d) anAspect;
5308 Handle(Image_AlienPixMap) anImage;
5309 Quantity_Color aColor (Quantity_NOC_GREEN1);
5310 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5311 && !aFileName.IsEmpty())
5313 anImage = new Image_AlienPixMap();
5314 if (!anImage->Load (aFileName))
5316 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5319 if (anImage->Format() == Image_PixMap::ImgGray)
5321 anImage->SetFormat (Image_PixMap::ImgAlpha);
5323 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5325 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5327 anAspect = new Graphic3d_AspectMarker3d (anImage);
5331 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5334 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5335 VDisplayAISObject (aName, aMarkersArray);
5340 //! Auxiliary function to parse font aspect style argument
5341 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5342 Font_FontAspect& theAspect)
5344 if (theArg == "regular"
5345 || *theArg.ToCString() == 'r')
5347 theAspect = Font_FA_Regular;
5348 return Standard_True;
5350 else if (theArg == "bolditalic")
5352 theAspect = Font_FA_BoldItalic;
5353 return Standard_True;
5355 else if (theArg == "bold"
5356 || *theArg.ToCString() == 'b')
5358 theAspect = Font_FA_Bold;
5359 return Standard_True;
5361 else if (theArg == "italic"
5362 || *theArg.ToCString() == 'i')
5364 theAspect = Font_FA_Italic;
5365 return Standard_True;
5367 return Standard_False;
5370 //! Auxiliary function
5371 static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5375 case Font_FA_Regular: return "regular";
5376 case Font_FA_BoldItalic: return "bolditalic";
5377 case Font_FA_Bold: return "bold";
5378 case Font_FA_Italic: return "italic";
5379 default: return "undefined";
5383 //=======================================================================
5384 //function : TextToBrep
5385 //purpose : Tool for conversion text to occt-shapes
5386 //=======================================================================
5387 static int TextToBRep (Draw_Interpretor& /*theDI*/,
5388 Standard_Integer theArgNb,
5389 const char** theArgVec)
5394 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5398 Standard_Integer anArgIt = 1;
5399 Standard_CString aName = theArgVec[anArgIt++];
5400 Standard_CString aText = theArgVec[anArgIt++];
5402 Font_BRepFont aFont;
5403 TCollection_AsciiString aFontName ("Courier");
5404 Standard_Real aTextHeight = 16.0;
5405 Font_FontAspect aFontAspect = Font_FA_Regular;
5406 Standard_Boolean anIsCompositeCurve = Standard_False;
5407 gp_Ax3 aPenAx3 (gp::XOY());
5408 gp_Dir aNormal (0.0, 0.0, 1.0);
5409 gp_Dir aDirection (1.0, 0.0, 0.0);
5412 Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
5413 Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM;
5415 for (; anArgIt < theArgNb; ++anArgIt)
5417 TCollection_AsciiString aParam (theArgVec[anArgIt]);
5420 if (aParam == "-pos"
5421 || aParam == "-position")
5423 if (anArgIt + 3 >= theArgNb)
5425 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5429 aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
5430 aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
5431 aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
5433 else if (aParam == "-halign")
5435 if (++anArgIt >= theArgNb)
5437 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5441 TCollection_AsciiString aType (theArgVec[anArgIt]);
5443 if (aType == "left")
5445 aHJustification = Graphic3d_HTA_LEFT;
5447 else if (aType == "center")
5449 aHJustification = Graphic3d_HTA_CENTER;
5451 else if (aType == "right")
5453 aHJustification = Graphic3d_HTA_RIGHT;
5457 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5461 else if (aParam == "-valign")
5463 if (++anArgIt >= theArgNb)
5465 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5469 TCollection_AsciiString aType (theArgVec[anArgIt]);
5473 aVJustification = Graphic3d_VTA_TOP;
5475 else if (aType == "center")
5477 aVJustification = Graphic3d_VTA_CENTER;
5479 else if (aType == "bottom")
5481 aVJustification = Graphic3d_VTA_BOTTOM;
5483 else if (aType == "topfirstline")
5485 aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
5489 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5493 else if (aParam == "-height")
5495 if (++anArgIt >= theArgNb)
5497 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5501 aTextHeight = Draw::Atof(theArgVec[anArgIt]);
5503 else if (aParam == "-aspect")
5505 if (++anArgIt >= theArgNb)
5507 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5511 TCollection_AsciiString anOption (theArgVec[anArgIt]);
5512 anOption.LowerCase();
5514 if (anOption.IsEqual ("regular"))
5516 aFontAspect = Font_FA_Regular;
5518 else if (anOption.IsEqual ("bold"))
5520 aFontAspect = Font_FA_Bold;
5522 else if (anOption.IsEqual ("italic"))
5524 aFontAspect = Font_FA_Italic;
5526 else if (anOption.IsEqual ("bolditalic"))
5528 aFontAspect = Font_FA_BoldItalic;
5532 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
5536 else if (aParam == "-font")
5538 if (++anArgIt >= theArgNb)
5540 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5544 aFontName = theArgVec[anArgIt];
5546 else if (aParam == "-composite")
5548 if (++anArgIt >= theArgNb)
5550 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5554 ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
5556 else if (aParam == "-plane")
5558 if (anArgIt + 6 >= theArgNb)
5560 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
5564 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
5565 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
5566 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
5567 aNormal.SetCoord (aX, aY, aZ);
5569 aX = Draw::Atof (theArgVec[++anArgIt]);
5570 aY = Draw::Atof (theArgVec[++anArgIt]);
5571 aZ = Draw::Atof (theArgVec[++anArgIt]);
5572 aDirection.SetCoord (aX, aY, aZ);
5576 std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
5580 aFont.SetCompositeCurveMode (anIsCompositeCurve);
5581 if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
5583 std::cerr << "Font initialization error\n";
5587 aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
5589 Font_BRepTextBuilder aBuilder;
5590 DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
5594 //=======================================================================
5596 //purpose : Font management
5597 //=======================================================================
5599 static int VFont (Draw_Interpretor& theDI,
5600 Standard_Integer theArgNb,
5601 const char** theArgVec)
5603 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5606 // just print the list of available fonts
5607 Standard_Boolean isFirst = Standard_True;
5608 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5609 anIter.More(); anIter.Next())
5611 const Handle(Font_SystemFont)& aFont = anIter.Value();
5617 theDI << aFont->FontName()->String()
5618 << " " << fontStyleString (aFont->FontAspect())
5619 << " " << aFont->FontPath()->String();
5620 isFirst = Standard_False;
5625 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5627 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5628 TCollection_AsciiString anArgCase (anArg);
5629 anArgCase.LowerCase();
5630 if (anArgCase == "find")
5632 if (++anArgIter >= theArgNb)
5634 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5638 Standard_CString aFontName = theArgVec[anArgIter];
5639 Font_FontAspect aFontAspect = Font_FA_Undefined;
5640 if (++anArgIter < theArgNb)
5642 anArgCase = theArgVec[anArgIter];
5643 anArgCase.LowerCase();
5644 if (!parseFontStyle (anArgCase, aFontAspect))
5649 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5652 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5656 theDI << aFont->FontName()->String()
5657 << " " << fontStyleString (aFont->FontAspect())
5658 << " " << aFont->FontPath()->String();
5660 else if (anArgCase == "add"
5661 || anArgCase == "register")
5663 if (++anArgIter >= theArgNb)
5665 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5668 Standard_CString aFontPath = theArgVec[anArgIter];
5669 Standard_CString aFontName = NULL;
5670 Font_FontAspect aFontAspect = Font_FA_Undefined;
5671 if (++anArgIter < theArgNb)
5673 if (!parseFontStyle (anArgCase, aFontAspect))
5675 aFontName = theArgVec[anArgIter];
5677 if (++anArgIter < theArgNb)
5679 anArgCase = theArgVec[anArgIter];
5680 anArgCase.LowerCase();
5681 if (!parseFontStyle (anArgCase, aFontAspect))
5688 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5691 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5695 if (aFontAspect != Font_FA_Undefined
5696 || aFontName != NULL)
5698 if (aFontAspect == Font_FA_Undefined)
5700 aFontAspect = aFont->FontAspect();
5702 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5703 if (aFontName != NULL)
5705 aName = new TCollection_HAsciiString (aFontName);
5707 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5710 aMgr->RegisterFont (aFont, Standard_True);
5711 theDI << aFont->FontName()->String()
5712 << " " << fontStyleString (aFont->FontAspect())
5713 << " " << aFont->FontPath()->String();
5717 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5724 //=======================================================================
5725 //function : VSetEdgeType
5726 //purpose : Edges type management
5727 //=======================================================================
5729 static int VSetEdgeType (Draw_Interpretor& theDI,
5730 Standard_Integer theArgNum,
5731 const char** theArgs)
5733 if (theArgNum < 4 || theArgNum > 9)
5735 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5736 << theArgs[0] << "' for more information.\n";
5740 Standard_Boolean isForceRedisplay = Standard_False;
5743 TCollection_AsciiString aName(theArgs[1]);
5744 if (!GetMapOfAIS().IsBound2 (aName))
5746 theDI << theArgs[0] << " error: wrong object name.\n";
5750 Handle(AIS_InteractiveObject) anObject =
5751 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5753 // Enable trianle edge mode
5754 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5757 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5759 TCollection_AsciiString aParam ((theArgs[anIt]));
5760 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5762 if (aParam.IsEqual ("-type"))
5764 if (theArgNum <= anIt + 1)
5766 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5767 << aParam.ToCString() << "'.\n";
5771 TCollection_AsciiString aType = theArgs[++anIt];
5774 if (aType.IsEqual ("SOLID"))
5776 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5778 else if (aType.IsEqual ("DASH"))
5780 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5782 else if (aType.IsEqual ("DOT"))
5784 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5786 else if (aType.IsEqual ("DOTDASH"))
5788 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5792 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5797 else if (aParam.IsEqual ("-color"))
5799 if (theArgNum <= anIt + 3)
5801 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5802 << aParam.ToCString() << "'.\n";
5806 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5807 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5808 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5809 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5810 aG > 1 ? aG / 255.0 : aG,
5811 aB > 1 ? aB / 255.0 : aB,
5814 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5816 else if (aParam.IsEqual ("-force"))
5818 isForceRedisplay = Standard_True;
5822 theDI << theArgs[0] << " error: unknown parameter '"
5823 << aParam.ToCString() << "'.\n";
5829 // Update shape presentation as aspect parameters were changed
5830 if (isForceRedisplay)
5832 ViewerTest::GetAISContext()->Redisplay (anObject);
5836 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5840 ViewerTest::CurrentView()->Redraw();
5845 //=======================================================================
5846 //function : VUnsetEdgeType
5847 //purpose : Unsets edges visibility in shading mode
5848 //=======================================================================
5850 static int VUnsetEdgeType (Draw_Interpretor& theDI,
5851 Standard_Integer theArgNum,
5852 const char** theArgs)
5854 if (theArgNum != 2 && theArgNum != 3)
5856 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5857 << theArgs[0] << "' for more information.\n";
5861 Standard_Boolean isForceRedisplay = Standard_False;
5864 TCollection_AsciiString aName (theArgs[1]);
5865 if (!GetMapOfAIS().IsBound2 (aName))
5867 theDI << theArgs[0] << " error: wrong object name.\n";
5871 Handle(AIS_InteractiveObject) anObject =
5872 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5874 // Enable trianle edge mode
5875 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5880 TCollection_AsciiString aParam ((theArgs[2]));
5881 if (aParam.IsEqual ("-force"))
5883 isForceRedisplay = Standard_True;
5887 theDI << theArgs[0] << " error: unknown parameter '"
5888 << aParam.ToCString() << "'.\n";
5893 // Update shape presentation as aspect parameters were changed
5894 if (isForceRedisplay)
5896 ViewerTest::GetAISContext()->Redisplay (anObject);
5900 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5904 ViewerTest::CurrentView()->Redraw();
5910 //=======================================================================
5911 //function : VVertexMode
5912 //purpose : Switches vertex display mode for AIS_Shape or displays the current value
5913 //=======================================================================
5915 static int VVertexMode (Draw_Interpretor& theDI,
5916 Standard_Integer theArgNum,
5917 const char** theArgs)
5919 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5920 if (aContext.IsNull())
5922 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5926 // No arguments --> print the current default vertex draw mode
5929 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5930 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5934 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5935 TCollection_AsciiString aParam (theArgs[1]);
5936 if (aParam == "-set")
5940 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5941 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5945 TCollection_AsciiString aModeStr (theArgs[2]);
5946 Prs3d_VertexDrawMode aNewMode =
5947 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5948 (aModeStr == "all" ? Prs3d_VDM_All :
5949 Prs3d_VDM_Inherited);
5951 Standard_Boolean aRedrawNeeded = Standard_False;
5952 AIS_ListOfInteractive anObjs;
5954 // No object(s) specified -> use all displayed
5957 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5958 aContext->DisplayedObjects (anObjs);
5959 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5960 aRedrawNeeded = Standard_True;
5963 Handle(AIS_InteractiveObject) anObject;
5964 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5966 TCollection_AsciiString aName (theArgs[aCount]);
5967 if (!GetMapOfAIS().IsBound2 (aName))
5969 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5972 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5973 anObjs.Append (anObject);
5976 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5978 anObject = anIt.Value();
5979 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5980 aContext->Redisplay (anObject, Standard_False);
5981 aRedrawNeeded = Standard_True;
5985 ViewerTest::CurrentView()->Redraw();
5992 std::cout << "Error: invalid number of arguments" << std::endl;
5993 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5997 // One argument (object name) --> print the current vertex draw mode for the object
5998 Handle(AIS_InteractiveObject) anObject =
5999 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
6000 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
6001 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
6005 //=======================================================================
6006 //function : VPointCloud
6007 //purpose : Create interactive object for arbitary set of points.
6008 //=======================================================================
6009 static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
6010 Standard_Integer theArgNum,
6011 const char** theArgs)
6013 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
6014 if (anAISContext.IsNull())
6016 std::cerr << "Error: no active view!\n";
6020 // command to execute
6023 CloudForShape, // generate point cloud for shape
6024 CloudSphere, // generate point cloud for generic sphere
6028 // count number of non-optional command arguments
6029 Command aCmd = Unknow;
6030 Standard_Integer aCmdArgs = 0;
6031 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
6033 Standard_CString anArg = theArgs[anArgIter];
6034 TCollection_AsciiString aFlag (anArg);
6036 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
6043 case 2 : aCmd = CloudForShape; break;
6044 case 7 : aCmd = CloudSphere; break;
6046 std::cout << "Error: wrong number of arguments! See usage:\n";
6047 theDI.PrintHelp (theArgs[0]);
6052 Standard_Boolean toRandColors = Standard_False;
6053 Standard_Boolean hasNormals = Standard_True;
6054 Standard_Boolean isSetArgNorm = Standard_False;
6055 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
6057 Standard_CString anArg = theArgs[anArgIter];
6058 TCollection_AsciiString aFlag (anArg);
6060 if (aFlag == "-randcolors"
6061 || aFlag == "-randcolor")
6063 if (isSetArgNorm && hasNormals)
6065 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
6068 toRandColors = Standard_True;
6069 hasNormals = Standard_False;
6071 else if (aFlag == "-normals"
6072 || aFlag == "-normal")
6076 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
6079 isSetArgNorm = Standard_True;
6080 hasNormals = Standard_True;
6082 else if (aFlag == "-nonormals"
6083 || aFlag == "-nonormal")
6085 isSetArgNorm = Standard_True;
6086 hasNormals = Standard_False;
6090 Standard_CString aName = theArgs[1];
6092 // generate arbitrary set of points
6093 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
6094 if (aCmd == CloudForShape)
6096 Standard_CString aShapeName = theArgs[2];
6097 TopoDS_Shape aShape = DBRep::Get (aShapeName);
6099 if (aShape.IsNull())
6101 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
6105 // calculate number of points
6106 TopLoc_Location aLocation;
6107 Standard_Integer aNbPoints = 0;
6108 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6110 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6111 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6112 if (!aTriangulation.IsNull())
6114 aNbPoints += aTriangulation->NbNodes();
6119 std::cout << "Error: shape should be triangulated!\n";
6123 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
6124 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
6126 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
6127 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
6128 if (aTriangulation.IsNull())
6133 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
6134 const gp_Trsf& aTrsf = aLocation.Transformation();
6136 // extract normals from nodes
6137 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
6140 Poly_Connect aPolyConnect (aTriangulation);
6141 StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
6144 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
6146 gp_Pnt aPoint = aNodes (aNodeIter);
6147 if (!aLocation.IsIdentity())
6149 aPoint.Transform (aTrsf);
6152 aNormals (aNodeIter).Transform (aTrsf);
6156 // add vertex into array of points
6157 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6160 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
6161 1.0, 0.5, Quantity_TOC_HLS);
6162 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6167 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
6172 else if (aCmd == CloudSphere)
6174 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
6175 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
6176 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
6177 Standard_Real aRadius = Draw::Atof (theArgs[5]);
6178 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
6180 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
6181 aDistribution.LowerCase();
6182 if ( aDistribution != "surface" && aDistribution != "volume" )
6184 std::cout << "Error: wrong arguments! See usage:\n";
6185 theDI.PrintHelp (theArgs[0]);
6188 Standard_Boolean isSurface = aDistribution == "surface";
6190 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
6192 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
6193 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
6195 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6196 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
6197 Standard_Real aDistance = isSurface ?
6198 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
6200 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
6202 Cos (anAlpha) * Cos (aBeta));
6203 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
6205 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
6208 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
6209 1.0, 0.5, Quantity_TOC_HLS);
6210 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
6215 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
6220 // set array of points in point cloud object
6221 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
6222 aPointCloud->SetPoints (anArrayPoints);
6223 VDisplayAISObject (aName, aPointCloud);
6227 //=======================================================================
6228 //function : VPriority
6229 //purpose : Prints or sets the display priority for an object
6230 //=======================================================================
6232 static int VPriority (Draw_Interpretor& theDI,
6233 Standard_Integer theArgNum,
6234 const char** theArgs)
6236 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6237 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6238 if (aContext.IsNull())
6240 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
6244 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
6245 Standard_Integer aPriority = -1;
6246 Standard_Integer aNbArgs = theArgNum;
6247 if (aLastArg.IsIntegerValue())
6249 aPriority = aLastArg.IntegerValue();
6251 if (aPriority < 0 || aPriority > 10)
6253 std::cout << "Error: the specified display priority value '" << aLastArg
6254 << "' is outside the valid range [0..10]" << std::endl;
6260 anUpdateTool.Invalidate();
6265 std::cout << "Error: wrong number of arguments! See usage:\n";
6266 theDI.PrintHelp (theArgs[0]);
6270 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
6272 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
6277 TCollection_AsciiString aName (theArgs[anArgIter]);
6278 Handle(AIS_InteractiveObject) anIObj;
6279 if (GetMapOfAIS().IsBound2 (aName))
6281 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
6284 if (anIObj.IsNull())
6286 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
6292 theDI << aContext->DisplayPriority (anIObj) << " ";
6296 aContext->SetDisplayPriority (anIObj, aPriority);
6302 //=======================================================================
6303 //function : ObjectsCommands
6305 //=======================================================================
6307 void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
6309 const char *group ="AISObjects";
6310 theCommands.Add("vtrihedron",
6311 "vtrihedron : vtrihedron name [ -origin x y z ] [ -zaxis u v w -xaxis u v w ] [ -hidelabels ]"
6312 "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created."
6313 "\n\t\t: -hidelabels allows to draw trihedron without axes labels. By default, they are displayed.",
6314 __FILE__,VTrihedron,group);
6316 theCommands.Add("vtri2d",
6318 "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
6319 __FILE__,VTrihedron2D ,group);
6321 theCommands.Add("vplanetri",
6323 "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
6324 __FILE__,VPlaneTrihedron ,group);
6326 theCommands.Add("vsize",
6327 "vsize : vsize [name(Default=Current)] [size(Default=100)] "
6328 "\n\t\t: Changes the size of a named or selected trihedron."
6329 "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
6330 "\n\t\t: If the value is not defined: it is set to 100 by default.",
6331 __FILE__,VSize,group);
6333 theCommands.Add("vaxis",
6334 "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
6335 "\n\t\t: Creates an axis. If the values are not defined, an axis is created by interactive selection of two vertices or one edge",
6336 __FILE__,VAxisBuilder,group);
6338 theCommands.Add("vaxispara",
6340 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
6341 __FILE__,VAxisBuilder,group);
6343 theCommands.Add("vaxisortho",
6345 "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
6346 __FILE__,VAxisBuilder,group);
6348 theCommands.Add("vpoint",
6349 "vpoint PointName [Xa] [Ya] [Za] "
6350 "\n\t\t: Creates a point from coordinates. If the values are not defined,"
6351 "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
6352 __FILE__,VPointBuilder,group);
6354 theCommands.Add("vplane",
6355 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
6356 "\n\t\t: Creates a plane from named or interactively selected entities."
6357 "\n\t\t: TypeOfSensitivity:"
6358 "\n\t\t: 0 - Interior"
6359 "\n\t\t: 1 - Boundary",
6360 __FILE__,VPlaneBuilder,group);
6362 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
6363 " vchangeplane <plane_name>"
6364 " [x=center_x y=center_y z=center_z]"
6365 " [dx=dir_x dy=dir_y dz=dir_z]"
6366 " [sx=size_x sy=size_y]"
6368 " - changes parameters of the plane:\n"
6369 " - x y z - center\n"
6370 " - dx dy dz - normal\n"
6371 " - sx sy - plane sizes\n"
6372 " - noupdate - do not update/redisplay the plane in context\n"
6373 " Please enter coordinates in format \"param=value\" in arbitrary order.",
6374 __FILE__, VChangePlane, group);
6376 theCommands.Add("vplanepara",
6377 "vplanepara PlaneName "
6378 "\n\t\t: Creates a plane from interactively selected vertex and face.",
6379 __FILE__,VPlaneBuilder,group);
6381 theCommands.Add("vplaneortho",
6382 "vplaneortho PlaneName "
6383 "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
6384 __FILE__,VPlaneBuilder,group);
6386 theCommands.Add("vline",
6387 "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] "
6388 "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
6389 __FILE__,VLineBuilder,group);
6391 theCommands.Add("vcircle",
6392 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
6393 "\n\t\t: Creates a circle from named or interactively selected entities."
6394 "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
6395 __FILE__,VCircleBuilder,group);
6397 theCommands.Add ("vdrawtext",
6398 "vdrawtext name text"
6399 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6400 "\n\t\t: [-color {R G B|name}=yellow]"
6401 "\n\t\t: [-halign {left|center|right}=left]"
6402 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6403 "\n\t\t: [-angle angle=0]"
6404 "\n\t\t: [-zoom {0|1}=0]"
6405 "\n\t\t: [-height height=16]"
6406 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6407 "\n\t\t: [-font font=Times]"
6409 "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
6410 "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
6411 "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
6412 "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
6413 "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}"
6414 "\n\t\t: [-subcolor {R G B|name}=white]"
6415 "\n\t\t: [-noupdate]"
6416 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
6417 "\n\t\t: [-flipping]"
6418 "\n\t\t: Display text label at specified position.",
6419 __FILE__, VDrawText, group);
6421 theCommands.Add("vdrawsphere",
6422 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
6423 __FILE__,VDrawSphere,group);
6425 theCommands.Add ("vsetlocation",
6426 "vsetlocation [-noupdate|-update] name x y z"
6427 "\n\t\t: Set new location for an interactive object.",
6428 __FILE__, VSetLocation, group);
6432 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6433 __FILE__, VComputeHLR, group);
6435 theCommands.Add("vdrawparray",
6436 "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id ]",
6437 __FILE__,VDrawPArray,group);
6439 theCommands.Add("vconnect",
6440 "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
6441 "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
6442 __FILE__, VConnect, group);
6444 theCommands.Add("vconnectto",
6445 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
6446 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6447 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
6448 __FILE__, VConnectTo,group);
6450 theCommands.Add("vdisconnect",
6451 "vdisconnect assembly_name (object_name | object_number | 'all')"
6452 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6453 __FILE__,VDisconnect,group);
6455 theCommands.Add("vaddconnected",
6456 "vaddconnected assembly_name object_name"
6457 "Adds object to assembly.",
6458 __FILE__,VAddConnected,group);
6460 theCommands.Add("vlistconnected",
6461 "vlistconnected assembly_name"
6462 "Lists objects in assembly.",
6463 __FILE__,VListConnected,group);
6466 theCommands.Add("vselmode",
6467 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6468 " switches selection mode for the determined object or\n"
6469 " for all objects in context.\n"
6470 " mode_number is non-negative integer that has different\n"
6471 " meaning for different interactive object classes.\n"
6472 " For shapes the following mode_number values are allowed:\n"
6482 " is_turned_on is:\n"
6483 " 1 if mode is to be switched on\n"
6484 " 0 if mode is to be switched off\n",
6485 __FILE__, VSetSelectionMode, group);
6487 theCommands.Add("vselnext",
6488 "vselnext : hilight next detected",
6489 __FILE__, VSelectionNext, group);
6491 theCommands.Add("vselprev",
6492 "vselnext : hilight previous detected",
6493 __FILE__, VSelectionPrevious, group);
6495 theCommands.Add("vtriangle",
6496 "vtriangle Name PointName PointName PointName"
6497 "\n\t\t: Creates and displays a filled triangle from named points.",
6498 __FILE__, VTriangle,group);
6500 theCommands.Add("vsegment",
6501 "vsegment Name PointName PointName"
6502 "\n\t\t: Creates and displays a segment from named points.",
6503 __FILE__, VSegment,group);
6505 theCommands.Add("vobjzlayer",
6506 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6507 __FILE__, VObjZLayer, group);
6509 theCommands.Add("vpolygonoffset",
6510 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6511 __FILE__, VPolygonOffset, group);
6513 theCommands.Add ("vshowfaceboundary",
6514 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6515 "- turns on/off drawing of face boundaries for ais object "
6516 "and defines boundary line style.",
6517 __FILE__, VShowFaceBoundary, group);
6519 theCommands.Add ("vmarkerstest",
6520 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6521 __FILE__, VMarkersTest, group);
6523 theCommands.Add ("text2brep",
6524 "text2brep: name text"
6525 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6526 "\n\t\t: [-halign {left|center|right}=left]"
6527 "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
6528 "\n\t\t: [-height height=16]"
6529 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6530 "\n\t\t: [-font font=Courier]"
6531 "\n\t\t: [-composite {on|off}=off]"
6532 "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
6533 __FILE__, TextToBRep, group);
6534 theCommands.Add ("vfont",
6535 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6536 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6537 __FILE__, VFont, group);
6539 theCommands.Add ("vsetedgetype",
6540 "vsetedgetype usage:\n"
6541 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6542 "\n\t\t: Sets edges type and color for input shape",
6543 __FILE__, VSetEdgeType, group);
6545 theCommands.Add ("vunsetedgetype",
6546 "vunsetedgetype usage:\n"
6547 "vunsetedgetype ShapeName [-force]"
6548 "\n\t\t: Unsets edges type and color for input shape",
6549 __FILE__, VUnsetEdgeType, group);
6551 theCommands.Add ("vvertexmode",
6552 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6553 "vvertexmode - prints the default vertex draw mode\n"
6554 "vvertexmode name - prints the vertex draw mode of the given object\n"
6555 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6556 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6557 __FILE__, VVertexMode, group);
6559 theCommands.Add ("vpointcloud",
6560 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6561 "\n\t\t: Create an interactive object for arbitary set of points"
6562 "\n\t\t: from triangulated shape."
6564 "vpointcloud name x y z r npts {surface|volume}\n"
6565 " ... [-randColor] [-normals] [-noNormals]"
6566 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6567 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6569 "\n\t\t: Additional options:"
6570 "\n\t\t: -randColor - generate random color per point"
6571 "\n\t\t: -normals - generate normal per point (default)"
6572 "\n\t\t: -noNormals - do not generate normal per point"
6574 __FILE__, VPointCloud, group);
6576 theCommands.Add("vlocreset",
6577 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6579 LocalTransformPresentation, group);
6581 theCommands.Add("vlocmove",
6582 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6584 LocalTransformPresentation, group);
6586 theCommands.Add("vloctranslate",
6587 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6589 LocalTransformPresentation, group);
6591 theCommands.Add("vlocrotate",
6592 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6594 LocalTransformPresentation, group);
6596 theCommands.Add("vlocmirror",
6597 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6599 LocalTransformPresentation, group);
6601 theCommands.Add("vlocscale",
6602 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6604 LocalTransformPresentation, group);
6606 theCommands.Add("vpriority",
6607 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",