0026272: Visualization - provide a possibility to activate selection modes without...
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-11-12
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17#include <ViewerTest.hxx>
18
7fd59977 19#include <Quantity_NameOfColor.hxx>
20#include <Draw_Interpretor.hxx>
21#include <Draw.hxx>
22#include <Draw_Appli.hxx>
23#include <DBRep.hxx>
24
b514beda 25#include <Font_BRepFont.hxx>
725ef85e 26#include <Font_FontMgr.hxx>
161c4476 27#include <OSD_Chronometer.hxx>
7fd59977 28#include <TCollection_AsciiString.hxx>
4952a30a 29#include <Visual3d_View.hxx>
7fd59977 30#include <V3d_Viewer.hxx>
31#include <V3d_View.hxx>
32#include <V3d.hxx>
33
34#include <AIS_Shape.hxx>
35#include <AIS_DisplayMode.hxx>
d33222c1 36#include <AIS_PointCloud.hxx>
7fd59977 37#include <TColStd_MapOfInteger.hxx>
38#include <AIS_MapOfInteractive.hxx>
4e18052b 39#include <ViewerTest_AutoUpdater.hxx>
7fd59977 40#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
41#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
42#include <ViewerTest_EventManager.hxx>
43
44#include <TopoDS_Solid.hxx>
45#include <BRepTools.hxx>
46#include <BRep_Builder.hxx>
47#include <TopAbs_ShapeEnum.hxx>
48
49#include <TopoDS.hxx>
50#include <BRep_Tool.hxx>
51#include <TopExp_Explorer.hxx>
52
53#include <BRepAdaptor_Curve.hxx>
54#include <BRepAdaptor_Surface.hxx>
55
56#include <TopAbs.hxx>
57#include <TopExp.hxx>
58#include <TopoDS_Vertex.hxx>
59#include <TopoDS_Shape.hxx>
60#include <TopoDS_Face.hxx>
61
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>
67
68#include <AIS_InteractiveContext.hxx>
69#include <Geom_Plane.hxx>
70#include <gp_Pln.hxx>
7fd59977 71#include <TCollection_ExtendedString.hxx>
725ef85e 72#include <TCollection_HAsciiString.hxx>
7fd59977 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>
29d43f9c
A
80#include <gp_Trsf.hxx>
81#include <TopLoc_Location.hxx>
3fc57801 82
83#include <HLRAlgo_Projector.hxx>
84#include <HLRBRep_PolyAlgo.hxx>
85#include <HLRBRep_PolyHLRToShape.hxx>
86#include <Aspect_Window.hxx>
87
9558a876
A
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>
a577aaab 97#include <Graphic3d_AspectMarker3d.hxx>
9558a876
A
98#include <Graphic3d_Group.hxx>
99#include <Standard_Real.hxx>
100
329843e2 101#include <AIS_Circle.hxx>
329843e2
A
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>
a2d5ab2e 113#include <TopoDS_Wire.hxx>
ac04d101 114
792c785c 115#include <AIS_MultipleConnectedInteractive.hxx>
0717ddc1 116#include <AIS_ConnectedInteractive.hxx>
29e2c6d2 117#include <AIS_TextLabel.hxx>
ac04d101
SA
118#include <TopLoc_Location.hxx>
119#include <TColStd_ListOfInteger.hxx>
120#include <TColStd_ListIteratorOfListOfInteger.hxx>
329843e2 121
ceae62f0
A
122#include <Select3D_SensitiveTriangle.hxx>
123#include <Select3D_SensitiveCurve.hxx>
a577aaab 124#include <Select3D_SensitivePoint.hxx>
ceae62f0
A
125#include <BRepAdaptor_Curve.hxx>
126#include <StdPrs_Curve.hxx>
127
128#include <BRepExtrema_ExtPC.hxx>
129#include <BRepExtrema_ExtPF.hxx>
130
6262338c 131#include <Prs3d_Drawer.hxx>
53b15292 132#include <Prs3d_VertexDrawMode.hxx>
a2d5ab2e 133#include <Prs3d_LineAspect.hxx>
a577aaab 134#include <Prs3d_PointAspect.hxx>
135
136#include <Image_AlienPixMap.hxx>
eb4320f2 137#include <TColStd_HArray1OfAsciiString.hxx>
a2d5ab2e 138
03155c18 139#ifdef _WIN32
140# define _CRT_SECURE_NO_DEPRECATE
141# pragma warning (disable:4996)
7fd59977 142#endif
143
144extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
9558a876
A
145extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
146 const Handle(AIS_InteractiveObject)& theAISObj,
147 Standard_Boolean theReplaceIfExists = Standard_True);
1d0a9d4d 148extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
7fd59977 149extern Handle(AIS_InteractiveContext)& TheAISContext();
150
151
152//==============================================================================
153//function : Vtrihedron 2d
154//purpose : Create a plane with a 2D trihedron from a faceselection
161c4476 155//Draw arg : vtri2d name
7fd59977 156//==============================================================================
157#include <AIS_PlaneTrihedron.hxx>
158
159
160
161static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
162
163{
164 // Verification des arguments
165 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
166
167 // Declarations
168 Standard_Integer myCurrentIndex;
161c4476 169 // Fermeture des contextes
7fd59977 170 TheAISContext()->CloseAllContexts();
171 // Ouverture d'un contexte local et recuperation de son index.
172 TheAISContext()->OpenLocalContext();
173 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
174 // On active les modes de selections faces.
175 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
176 di<<" Select a face ."<<"\n";
177
178 // Boucle d'attente waitpick.
179 Standard_Integer argccc = 5;
180 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
181 const char **argvvv = (const char **) bufff;
182 while (ViewerMainLoop( argccc, argvvv) ) { }
183 // fin de la boucle
184
185 TopoDS_Shape ShapeB;
186 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
187 ShapeB = TheAISContext()->SelectedShape();
188 }
189
190 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
191
192 // Construction du Plane
193 // recuperation des edges des faces.
194 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
195
196 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
161c4476 197 // declarations
7fd59977 198 gp_Pnt A,B,C;
199
200 // si il y a plusieurs edges
201 if (FaceExpB.More() ) {
202 FaceExpB.Next();
203 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
204 BRepAdaptor_Curve theCurveB(EdgeB);
205 BRepAdaptor_Curve theCurveC(EdgeC);
206 A=theCurveC.Value(0.1);
207 B=theCurveC.Value(0.9);
208 C=theCurveB.Value(0.5);
209 }
210 else {
211 // FaceB a 1 unique edge courbe
212 BRepAdaptor_Curve theCurveB(EdgeB);
213 A=theCurveB.Value(0.1);
214 B=theCurveB.Value(0.9);
215 C=theCurveB.Value(0.5);
216 }
217 // Construction du Geom_Plane
218 GC_MakePlane MkPlane(A,B,C);
219 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
220
221 // Construction de l'AIS_PlaneTrihedron
222 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
223
224 // Fermeture du contexte local.
225 TheAISContext()->CloseLocalContext(myCurrentIndex);
226
227 // on le display & bind
228 TheAISContext()->Display(theAISPlaneTri );
229 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
230
161c4476 231 return 0;
7fd59977 232}
233
234
235
236//==============================================================================
237//function : VTriherdron
7fd59977 238//purpose : Create a trihedron. If no arguments are set, the default
239// trihedron (Oxyz) is created.
240//Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
241//==============================================================================
242
dc9b6d23 243static int VTrihedron (Draw_Interpretor& theDi,
244 Standard_Integer theArgsNb,
245 const char** theArgVec)
7fd59977 246{
dc9b6d23 247 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
248 {
249 theDi << theArgVec[0] << " Syntax error\n";
250 return 1;
7fd59977 251 }
7fd59977 252
dc9b6d23 253 gp_Pnt anOrigin (0.0, 0.0, 0.0);
254 gp_Dir aDirZ = gp::DZ();
255 gp_Dir aDirX = gp::DX();
256 Standard_Integer anArgIter = 2; // 1st is an IO name
257 if (anArgIter < theArgsNb)
258 {
91322f44 259 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
260 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
261 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
dc9b6d23 262 if (anArgIter < theArgsNb)
263 {
91322f44 264 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
265 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
266 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
dc9b6d23 267 aDirZ.SetCoord (aX, aY, aZ);
268
91322f44 269 aX = Draw::Atof (theArgVec[anArgIter++]);
270 aY = Draw::Atof (theArgVec[anArgIter++]);
271 aZ = Draw::Atof (theArgVec[anArgIter++]);
dc9b6d23 272 aDirX.SetCoord (aX, aY, aZ);
273 }
274 }
7fd59977 275
dc9b6d23 276 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
277 {
278 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
279 return 1;
280 }
7fd59977 281
dc9b6d23 282 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
283 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
284 VDisplayAISObject (theArgVec[1], aShape);
161c4476 285 return 0;
7fd59977 286}
287
7fd59977 288//==============================================================================
289//function : VSize
290//author : ege
291//purpose : Change the size of a named or selected trihedron
292// if no name : it affects the trihedrons witch are selected otherwise nothing is donne
293// if no value, the value is set at 100 by default
294//Draw arg : vsize [name] [size]
295//==============================================================================
296
297static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
298
299{
300 // Declaration de booleens
301 Standard_Boolean ThereIsName;
302 Standard_Boolean ThereIsCurrent;
303 Standard_Real value;
161c4476 304 Standard_Boolean hascol;
1d47d8d0 305
7fd59977 306 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
7fd59977 307
308 // Verification des arguments
309 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
310
311 // Verification du nombre d'arguments
312 if (argc==1) {ThereIsName=Standard_False;value=100;}
91322f44 313 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
314 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
7fd59977 315
316 // On ferme le contexte local pour travailler dans le contexte global
161c4476 317 if(TheAISContext()->HasOpenedContext())
7fd59977 318 TheAISContext()->CloseLocalContext();
319
320 // On set le booleen ThereIsCurrent
c3282ec1 321 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
7fd59977 322 else {ThereIsCurrent=Standard_False;}
323
324
325
326 //===============================================================
327 // Il n'y a pas de nom mais des objets selectionnes
328 //===============================================================
161c4476 329 if (!ThereIsName && ThereIsCurrent)
7fd59977 330 {
331
332 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
333 it (GetMapOfAIS());
334
335 while ( it.More() ) {
336
337 Handle(AIS_InteractiveObject) aShape=
338 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
339
c3282ec1 340 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
7fd59977 341 {
342
161c4476 343 // On verifie que l'AIS InteraciveObject selectionne est bien
7fd59977 344 // un AIS_Trihedron
345 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
346
347 if (aShape->HasColor()) {
348 hascol=Standard_True;
349
350 // On recupere la couleur de aShape
351 col=aShape->Color();}
352
353 else hascol=Standard_False;
354
355 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
356 // pour lui appliquer la methode SetSize()
c5f3a425 357 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
7fd59977 358
359 // C'est bien un triedre,on chage sa valeur!
360 aTrihedron->SetSize(value);
361
362 // On donne la couleur au Trihedron
363 if(hascol) aTrihedron->SetColor(col);
364 else aTrihedron->UnsetColor();
365
366
367 // The trihedron hasn't be errased from the map
368 // so you just have to redisplay it
369 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
370
371 }
372
373 }
374
375 it.Next();
376 }
377
378 TheAISContext() ->UpdateCurrentViewer();
379 }
380
381 //===============================================================
382 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
383 //===============================================================
384
385
386
387 //===============================================================
388 // Il y a un nom de triedre passe en argument
389 //===============================================================
390 if (ThereIsName) {
391 TCollection_AsciiString name=argv[1];
392
393 // on verifie que ce nom correspond bien a une shape
394 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
395
396 if (IsBound) {
397
398 // on recupere la shape dans la map des objets displayes
399 Handle(AIS_InteractiveObject) aShape =
400 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
401
161c4476 402 // On verifie que l'AIS InteraciveObject est bien
7fd59977 403 // un AIS_Trihedron
404 if (!aShape.IsNull() &&
405 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
406 {
407
408 if (aShape->HasColor()) {
409 hascol=Standard_True;
410
411 // On recupere la couleur de aShape
412 col=aShape->Color();}
413
414 else hascol=Standard_False;
415
416 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
417 // pour lui appliquer la methode SetSize()
c5f3a425 418 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
7fd59977 419
420 // C'est bien un triedre,on chage sa valeur
421 aTrihedron->SetSize(value);
422
423 // On donne la couleur au Trihedron
424 if(hascol) aTrihedron->SetColor(col);
425 else aTrihedron->UnsetColor();
426
427 // The trihedron hasn't be errased from the map
428 // so you just have to redisplay it
429 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
430
431 TheAISContext() ->UpdateCurrentViewer();
432 }
433 }
434 }
161c4476 435 return 0;
7fd59977 436}
437
438
439//==============================================================================
440
441//==============================================================================
442//function : VPlaneTrihedron
443//purpose : Create a plane from a trihedron selection. If no arguments are set, the default
161c4476 444//Draw arg : vplanetri name
7fd59977 445//==============================================================================
446#include <AIS_Plane.hxx>
447
448
449
450static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
451
452{
453 // Verification des arguments
454 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
455
456 // Declarations
457 Standard_Integer myCurrentIndex;
458 // Fermeture des contextes locaux
459 TheAISContext()->CloseAllContexts();
460
161c4476 461 // On recupere tous les trihedrons de la GetMapOfAIS()
7fd59977 462 // et on active le mode de selection par face.
463 // =================================================
464
465 // Ouverture d'un contexte local et recuperation de son index.
466 TheAISContext()->OpenLocalContext(Standard_False);
467 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
468
469 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
470 it (GetMapOfAIS());
471 while(it.More()){
472 Handle(AIS_InteractiveObject) ShapeA =
473 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
474 // On verifie que c'est bien un trihedron
475 if (!ShapeA.IsNull() &&
476 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
477 // on le downcast
c5f3a425 478 Handle(AIS_Trihedron) TrihedronA =(Handle(AIS_Trihedron)::DownCast (ShapeA));
7fd59977 479 // on le charge dans le contexte et on active le mode Plane.
480 TheAISContext()->Load(TrihedronA,0,Standard_False);
481 TheAISContext()->Activate(TrihedronA,3);
482 }
483 it.Next();
484 }
485
486 di<<" Select a plane."<<"\n";
487 // Boucle d'attente waitpick.
488 Standard_Integer argccc = 5;
489 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
490 const char **argvvv = (const char **) bufff;
491 while (ViewerMainLoop( argccc, argvvv) ) { }
492 // fin de la boucle
493
494 Handle(AIS_InteractiveObject) theIOB;
495 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
c3282ec1 496 theIOB = TheAISContext()->SelectedInteractive();
7fd59977 497 }
498 // on le downcast
c5f3a425 499 Handle(AIS_Plane) PlaneB =(Handle(AIS_Plane)::DownCast (theIOB));
7fd59977 500
501 // Fermeture du contexte local.
502 TheAISContext()->CloseLocalContext(myCurrentIndex);
503
504 // on le display & bind
505 TheAISContext()->Display(PlaneB );
506 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
507
161c4476 508 return 0;
7fd59977 509}
510
511
512
513//==============================================================================
514// Fonction First click 2de click
161c4476 515//
7fd59977 516// vaxis vertex vertex
517// edge None
518// vaxispara edge vertex
519// vaxisortho edge Vertex
520// vaxisinter Face Face
521//==============================================================================
522
523//==============================================================================
524//function : VAxisBuilder
161c4476 525//purpose :
7fd59977 526//Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
527//==============================================================================
528#include <TopoDS_Edge.hxx>
529#include <TopoDS_Vertex.hxx>
530#include <TopExp.hxx>
531#include <Geom_Line.hxx>
532
161c4476 533static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 534{
535 // Declarations
536 Standard_Boolean HasArg;
537 TCollection_AsciiString name;
538 Standard_Integer MyCurrentIndex;
539
540 // Verification
541 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
542 if (argc==8) HasArg=Standard_True;
543 else HasArg=Standard_False;
544
545 name=argv[1];
546 // Fermeture des contextes
547 TheAISContext()->CloseAllContexts();
548
549 // Cas ou il y a des arguments
550 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
551 if (HasArg) {
552 Standard_Real coord[6];
553 for(Standard_Integer i=0;i<=5;i++){
91322f44 554 coord[i]=Draw::Atof(argv[2+i]);
7fd59977 555 }
556 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
557
558 gp_Vec myVect (p1,p2);
559 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
560 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
561 GetMapOfAIS().Bind (TheAxis,name);
562 TheAISContext()->Display(TheAxis);
563 }
564
565 // Pas d'arguments
566 else {
567 // fonction vaxis
568 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
569 if ( !strcasecmp(argv[0], "vaxis")) {
570 TheAISContext()->OpenLocalContext();
571 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
572
573 // Active le mode edge et le mode vertex
574 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
575 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
576 di<<" Select an edge or a vertex."<<"\n";
577
578 // Boucle d'attente waitpick.
579 Standard_Integer argcc = 5;
580 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
581 const char **argvv = (const char **) buff;
582 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 583 // fin de la boucle
7fd59977 584
585 // recuperation de la shape.
586 TopoDS_Shape ShapeA;
587 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
588 ShapeA = TheAISContext()->SelectedShape();
589 }
590 // recuperation de l'AIS_InteractiveObject
591 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
592 // down cast en AIS_Point si sig et type
593 // AIS_Point -> Geom_Pnt ....
594
595 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
596 // on desactive le mode edge
597 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
598 di<<" Select a different vertex."<<"\n";
599
600 TopoDS_Shape ShapeB;
601 do {
602 // Boucle d'attente waitpick.
603 Standard_Integer argccc = 5;
604 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
605 const char **argvvv = (const char **) bufff;
606 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 607 // fin de la boucle
7fd59977 608 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
609 ShapeB = TheAISContext()->SelectedShape();
610 }
611
612
613 } while(ShapeB.IsSame(ShapeA) );
614
615 // Fermeture du context local
616 TheAISContext()->CloseLocalContext(MyCurrentIndex);
617
161c4476 618 // Construction de l'axe
7fd59977 619 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
620 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
621 gp_Vec V (A,B);
622 gp_Dir D (V);
623 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
624 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
625 GetMapOfAIS().Bind (TheAxis,name);
626 TheAISContext()->Display(TheAxis);
161c4476 627 }
7fd59977 628 else {
629 // Un unique edge (ShapeA) a ete picke
630 // Fermeture du context local
631 TheAISContext()->CloseLocalContext(MyCurrentIndex);
161c4476 632 // Constuction de l'axe
7fd59977 633 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
634 TopoDS_Vertex Va,Vb;
635 TopExp::Vertices(ed,Va,Vb );
636 gp_Pnt A=BRep_Tool::Pnt(Va);
637 gp_Pnt B=BRep_Tool::Pnt(Vb);
638 gp_Vec V (A,B);
639 gp_Dir D (V);
640 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
641 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
642 GetMapOfAIS().Bind (TheAxis,name);
643 TheAISContext()->Display(TheAxis);
644 }
645
646 }
647
648 // Fonction axispara
649 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
650 else if ( !strcasecmp(argv[0], "vaxispara")) {
651
652 TheAISContext()->OpenLocalContext();
653 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
654
161c4476 655 // Active le mode edge
7fd59977 656 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
657 di<<" Select an edge."<<"\n";
658
659 // Boucle d'attente waitpick.
660 Standard_Integer argcc = 5;
661 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
662 const char **argvv = (const char **) buff;
663 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 664 // fin de la boucle
7fd59977 665
666 TopoDS_Shape ShapeA;
667 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
668 ShapeA = TheAISContext()->SelectedShape();
669 }
670 // Active le mode vertex et deactive edges
671 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
672 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
673 di<<" Select a vertex."<<"\n";
674
675 // Boucle d'attente waitpick.
676 Standard_Integer argccc = 5;
677 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
678 const char **argvvv = (const char **) bufff;
679 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 680 // fin de la boucle
7fd59977 681
682 // On peut choisir un pnt sur l'edge
683 TopoDS_Shape ShapeB;
684 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
685 ShapeB = TheAISContext()->SelectedShape();
686 }
687 // Fermeture du context local
688 TheAISContext()->CloseLocalContext(MyCurrentIndex);
689
690 // Construction de l'axe
691 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
692 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
693 TopoDS_Vertex Va,Vc;
694 TopExp::Vertices(ed,Va,Vc );
695 gp_Pnt A=BRep_Tool::Pnt(Va);
696 gp_Pnt C=BRep_Tool::Pnt(Vc);
697 gp_Vec V (A,C);
698 gp_Dir D (V);
699 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
700 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
701 GetMapOfAIS().Bind (TheAxis,name);
702 TheAISContext()->Display(TheAxis);
703
704 }
705
706 // Fonction axisortho
707 else {
708 TheAISContext()->OpenLocalContext();
709 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
710
161c4476 711 // Active le mode edge
7fd59977 712 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
713 di<<" Select an edge."<<"\n";
714
715 // Boucle d'attente waitpick.
716 Standard_Integer argcc = 5;
717 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
718 const char **argvv = (const char **) buff;
719 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 720 // fin de la boucle
7fd59977 721
722 TopoDS_Shape ShapeA;
723 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
724 ShapeA = TheAISContext()->SelectedShape();
725 }
726 // Active le mode vertex et deactive edges
727 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
728 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
729 di<<" Slect a vertex."<<"\n";
730
731 // Boucle d'attente waitpick.
732 Standard_Integer argccc = 5;
733 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
734 const char **argvvv = (const char **) bufff;
735 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 736 // fin de la boucle
7fd59977 737
738 // On peut choisir un pnt sur l'edge
739 TopoDS_Shape ShapeB;
740 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
741 ShapeB = TheAISContext()->SelectedShape();
742 }
743 // Fermeture du context local
744 TheAISContext()->CloseLocalContext(MyCurrentIndex);
745
746 // Construction de l'axe
747 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
748 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
749 TopoDS_Vertex Va,Vc;
750 TopExp::Vertices(ed,Va,Vc );
751 gp_Pnt A=BRep_Tool::Pnt(Va);
752 gp_Pnt C=BRep_Tool::Pnt(Vc);
753 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
754 gp_Vec V (A,E);
755 gp_Dir D (V);
756 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
757 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
758 GetMapOfAIS().Bind (TheAxis,name);
759 TheAISContext()->Display(TheAxis);
760
761 }
762
763 }
764 return 0;
765}
766
767
768//==============================================================================
769// Fonction First click Result
161c4476 770//
7fd59977 771// vpoint vertex AIS_Point=Vertex
772// edge AIS_Point=Middle of the edge
773//==============================================================================
774
775//==============================================================================
776//function : VPointBuilder
777//purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
778//Draw arg : vpoint PoinName [Xa] [Ya] [Za]
779//==============================================================================
780#include <TopoDS_Edge.hxx>
781#include <TopoDS_Vertex.hxx>
782#include <TopExp.hxx>
783#include <AIS_Point.hxx>
784#include <Geom_CartesianPoint.hxx>
785
161c4476 786static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 787{
788 // Declarations
789 Standard_Boolean HasArg;
790 TCollection_AsciiString name;
791 Standard_Integer myCurrentIndex;
792
793 // Verification
794 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
795 if (argc==5) HasArg=Standard_True;
796 else HasArg=Standard_False;
797
798 name=argv[1];
799 // Fermeture des contextes
800 TheAISContext()->CloseAllContexts();
801
802 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
803 if (HasArg) {
804 Standard_Real thecoord[3];
805 for(Standard_Integer i=0;i<=2;i++)
91322f44 806 thecoord[i]=Draw::Atof(argv[2+i]);
7fd59977 807 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
808 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
809 GetMapOfAIS().Bind (myAISPoint,name);
810 TheAISContext()->Display(myAISPoint);
811 }
812
813 // Il n'a pas d'arguments
814 else {
815 TheAISContext()->OpenLocalContext();
816 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
817
818 // Active le mode Vertex et Edges
819 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
820 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
821 di<<" Select a vertex or an edge(build the middle)"<<"\n";
822
823 // Boucle d'attente waitpick.
824 Standard_Integer argcc = 5;
825 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
826 const char **argvv = (const char **) buff;
827 while (ViewerMainLoop( argcc, argvv) ) { }
828 // fin de la boucle
829
830 TopoDS_Shape ShapeA;
831 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
832 ShapeA= TheAISContext()->SelectedShape();
833 }
834
835 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
836 // Un vertex a ete selectionne
837 // Fermeture du context local
838 TheAISContext()->CloseLocalContext(myCurrentIndex);
839
840 // Construction du point
841 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
842 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
843 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
844 GetMapOfAIS().Bind(myAISPoint,name);
845 TheAISContext()->Display(myAISPoint);
846 }
847 else {
848 // Un Edge a ete selectionne
849 // Fermeture du context local
850 TheAISContext()->CloseLocalContext(myCurrentIndex);
851
852 // Construction du point milieu de l'edge
853 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
854 TopoDS_Vertex myVertexA,myVertexB;
855 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
856 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
857 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
858 // M est le milieu de [AB]
859 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
860 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
861 GetMapOfAIS().Bind(myAISPointM,name);
862 TheAISContext()->Display(myAISPointM);
863 }
864
865 }
866 return 0;
867
868}
869
870//==============================================================================
ceae62f0 871// Function 1st click 2de click 3de click
7fd59977 872// vplane Vertex Vertex Vertex
873// Vertex Edge
874// Edge Vertex
875// Face
876// vplanepara Face Vertex
877// Vertex Face
878// vplaneortho Face Edge
879// Edge Face
880//==============================================================================
881
882//==============================================================================
883//function : VPlaneBuilder
ceae62f0 884//purpose : Build an AIS_Plane from selected entities or Named AIS components
9e8804b6 885//Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
886// [PointName] [PointName] [PointName] [TypeOfSensitivity]
887// [PlaneName] [PointName] [TypeOfSensitivity]
7fd59977 888//==============================================================================
889
35e08fe8 890static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
ceae62f0
A
891 Standard_Integer argc,
892 const char** argv)
7fd59977 893{
894 // Declarations
ceae62f0
A
895 Standard_Boolean hasArg;
896 TCollection_AsciiString aName;
897 Standard_Integer aCurrentIndex;
7fd59977 898
899 // Verification
9e8804b6 900 if (argc<2 || argc>6 )
ceae62f0
A
901 {
902 std::cout<<" Syntax error\n";
903 return 1;
904 }
9e8804b6 905 if (argc == 6 || argc==5 || argc==4)
ceae62f0
A
906 hasArg=Standard_True;
907 else
908 hasArg=Standard_False;
7fd59977 909
ceae62f0
A
910 aName=argv[1];
911 // Close all contexts
7fd59977 912 TheAISContext()->CloseAllContexts();
913
ceae62f0
A
914 // There are some arguments
915 if (hasArg)
916 {
917 if (!GetMapOfAIS().IsBound2(argv[2] ))
918 {
919 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
920 return 1;
921 }
922 // Get shape from map
923 Handle(AIS_InteractiveObject) aShapeA =
7fd59977 924 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
925
ceae62f0
A
926 // The first argument is an AIS_Point
927 if (!aShapeA.IsNull() &&
928 aShapeA->Type()==AIS_KOI_Datum &&
929 aShapeA->Signature()==1)
930 {
931 // The second argument must also be an AIS_Point
932 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
933 {
934 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
935 return 1;
936 }
937 // Get shape from map
938 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 939 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
940 // If B is not an AIS_Point
941 if (aShapeB.IsNull() ||
942 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 943 {
ceae62f0 944 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
7fd59977 945 return 1;
946 }
ceae62f0
A
947 // The third object is an AIS_Point
948 if (!GetMapOfAIS().IsBound2(argv[4]) )
949 {
950 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
951 return 1;
952 }
953 // Get shape from map
954 Handle(AIS_InteractiveObject) aShapeC =
7fd59977 955 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
ceae62f0
A
956 // If C is not an AIS_Point
957 if (aShapeC.IsNull() ||
958 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
7fd59977 959 {
ceae62f0 960 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
7fd59977 961 return 1;
962 }
963
ceae62f0
A
964 // Treatment of objects A, B, C
965 // Downcast an AIS_IO to AIS_Point
966 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
967 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
968 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
7fd59977 969
ceae62f0
A
970 Handle(Geom_CartesianPoint ) aCartPointA =
971 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
7fd59977 972
ceae62f0
A
973 Handle(Geom_CartesianPoint ) aCartPointB =
974 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
7fd59977 975
ceae62f0
A
976 Handle(Geom_CartesianPoint ) aCartPointC =
977 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
7fd59977 978
ceae62f0 979 // Verification that the three points are different
91322f44 980 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
981 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
982 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 983 {
7fd59977 984 // B=A
ceae62f0 985 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 986 }
91322f44 987 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
988 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
989 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 990 {
7fd59977 991 // C=A
ceae62f0 992 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 993 }
91322f44 994 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
995 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
996 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
ceae62f0 997 {
7fd59977 998 // C=B
ceae62f0 999 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 1000 }
1001
ceae62f0
A
1002 gp_Pnt A = aCartPointA->Pnt();
1003 gp_Pnt B = aCartPointB->Pnt();
1004 gp_Pnt C = aCartPointC->Pnt();
7fd59977 1005
ceae62f0 1006 // Construction of AIS_Plane
7fd59977 1007 GC_MakePlane MkPlane (A,B,C);
ceae62f0
A
1008 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1009 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1010 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1011 if (argc == 6)
1012 {
1013 Standard_Integer aType = Draw::Atoi (argv[5]);
1014 if (aType != 0 && aType != 1)
1015 {
1016 std::cout << "vplane error: wrong type of sensitivity!\n"
1017 << "Should be one of the following values:\n"
1018 << "0 - Interior\n"
1019 << "1 - Boundary"
1020 << std::endl;
1021 return 1;
1022 }
1023 else
1024 {
1025 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1026 }
1027 }
ceae62f0 1028 TheAISContext()->Display(anAISPlane);
7fd59977 1029 }
1030
ceae62f0
A
1031 // The first argument is an AIS_Axis
1032 // Creation of a plane orthogonal to the axis through a point
1033 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1034 // The second argument should be an AIS_Point
7fd59977 1035 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1036 {
ceae62f0 1037 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1038 return 1;
1039 }
ceae62f0
A
1040 // Get shape from map
1041 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1042 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1043 // If B is not an AIS_Point
1044 if (aShapeB.IsNull() ||
1045 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1046 {
ceae62f0 1047 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1048 return 1;
1049 }
1050
ceae62f0
A
1051 // Treatment of objects A and B
1052 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1053 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1054
ceae62f0
A
1055 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1056 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
7fd59977 1057
ceae62f0
A
1058 gp_Ax1 anAxis = aGeomLineA->Position();
1059 Handle(Geom_CartesianPoint) aCartPointB =
1060 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
7fd59977 1061
ceae62f0
A
1062 gp_Dir D =anAxis.Direction();
1063 gp_Pnt B = aCartPointB->Pnt();
7fd59977 1064
ceae62f0
A
1065 // Construction of AIS_Plane
1066 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1067 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1068 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1069 if (argc == 5)
1070 {
1071 Standard_Integer aType = Draw::Atoi (argv[4]);
1072 if (aType != 0 && aType != 1)
1073 {
1074 std::cout << "vplane error: wrong type of sensitivity!\n"
1075 << "Should be one of the following values:\n"
1076 << "0 - Interior\n"
1077 << "1 - Boundary"
1078 << std::endl;
1079 return 1;
1080 }
1081 else
1082 {
1083 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1084 }
1085 }
ceae62f0 1086 TheAISContext()->Display(anAISPlane);
7fd59977 1087
1088 }
ceae62f0
A
1089 // The first argumnet is an AIS_Plane
1090 // Creation of a plane parallel to the plane passing through the point
1091 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1092 {
1093 // The second argument should be an AIS_Point
1094 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1095 {
1096 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1097 return 1;
1098 }
ceae62f0
A
1099 // Get shape from map
1100 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1101 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1102 // B should be an AIS_Point
1103 if (aShapeB.IsNull() ||
1104 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1105 {
ceae62f0 1106 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1107 return 1;
1108 }
1109
ceae62f0
A
1110 // Treatment of objects A and B
1111 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1112 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1113
ceae62f0
A
1114 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1115 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
7fd59977 1116
ceae62f0
A
1117 Handle(Geom_CartesianPoint) aCartPointB =
1118 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1119 gp_Pnt B= aCartPointB->Pnt();
7fd59977 1120
ceae62f0
A
1121 // Construction of an AIS_Plane
1122 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1123 GetMapOfAIS().Bind (anAISPlane, aName);
9e8804b6 1124 if (argc == 5)
1125 {
1126 Standard_Integer aType = Draw::Atoi (argv[4]);
1127 if (aType != 0 && aType != 1)
1128 {
1129 std::cout << "vplane error: wrong type of sensitivity!\n"
1130 << "Should be one of the following values:\n"
1131 << "0 - Interior\n"
1132 << "1 - Boundary"
1133 << std::endl;
1134 return 1;
1135 }
1136 else
1137 {
1138 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1139 }
1140 }
ceae62f0
A
1141 TheAISContext()->Display(anAISPlane);
1142 }
1143 // Error
1144 else
1145 {
1146 std::cout<<"vplane: error 1st object is not an AIS\n";
1147 return 1;
7fd59977 1148 }
7fd59977 1149 }
ceae62f0
A
1150 // There are no arguments
1151 else
1152 {
1153 // Function vplane
1154 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1155 if (!strcasecmp(argv[0], "vplane"))
1156 {
7fd59977 1157 TheAISContext()->OpenLocalContext();
ceae62f0 1158 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
7fd59977 1159
ceae62f0
A
1160 // Active modes Vertex, Edge and Face
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1162 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1163 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1164 std::cout<<"Select a vertex, a face or an edge\n";
7fd59977 1165
ceae62f0 1166 // Wait for picking
7fd59977 1167 Standard_Integer argcc = 5;
1168 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1169 const char **argvv = (const char **) buff;
1170 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1171 // end of the loop
7fd59977 1172
ceae62f0
A
1173 TopoDS_Shape aShapeA;
1174 for (TheAISContext()->InitSelected();
1175 TheAISContext()->MoreSelected();
1176 TheAISContext()->NextSelected())
1177 {
1178 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1179 }
1180
ceae62f0
A
1181 // aShapeA is a Vertex
1182 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1183 {
1184 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1185 std::cout<<" Select an edge or a different vertex\n";
7fd59977 1186
ceae62f0 1187 // Wait for picking
7fd59977 1188 Standard_Integer argccc = 5;
1189 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1190 const char **argvvv = (const char **) bufff;
1191 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1192 // end of the loop
7fd59977 1193
ceae62f0
A
1194 TopoDS_Shape aShapeB;
1195 for (TheAISContext()->InitSelected();
1196 TheAISContext()->MoreSelected();
1197 TheAISContext()->NextSelected())
1198 {
1199 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1200 }
ceae62f0
A
1201 // aShapeB is a Vertex
1202 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1203 {
1204 // A and B are the same
1205 if (aShapeB.IsSame(aShapeA))
1206 {
1207 std::cout<<" vplane: error, same points selected\n";
1208 return 1;
1209 }
1210 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1211 std::cout<<" Select a different vertex\n";
7fd59977 1212
ceae62f0 1213 // Wait for picking
7fd59977 1214 Standard_Integer argcccc = 5;
1215 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1216 const char **argvvvv = (const char **) buffff;
1217 while (ViewerMainLoop( argcccc, argvvvv) ) { }
ceae62f0 1218 // end of the loop
7fd59977 1219
ceae62f0
A
1220 TopoDS_Shape aShapeC;
1221 for (TheAISContext()->InitSelected();
1222 TheAISContext()->MoreSelected();
1223 TheAISContext()->NextSelected())
1224 {
1225 aShapeC = TheAISContext()->SelectedShape();
1226 }
1227 // aShapeC is the same as A or B
1228 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1229 {
1230 std::cout<<" vplane: error, same points selected\n";
1231 return 1;
7fd59977 1232 }
7fd59977 1233
ceae62f0
A
1234 // Close the local context
1235 TheAISContext()->CloseLocalContext(aCurrentIndex);
1236
1237 // Construction of plane
1238 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1239 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1240 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1241 GC_MakePlane MkPlane(A, B, C);
1242 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1243 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1244 GetMapOfAIS().Bind (anAISPlane, aName);
1245 TheAISContext()->Display(anAISPlane);
7fd59977 1246 }
ceae62f0
A
1247 // ShapeB is an edge
1248 else
1249 {
1250 // Verify that the vertex is not on the edge ShapeB
1251 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1252 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
7fd59977 1253
ceae62f0
A
1254 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1255 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1256 {
1257 // The vertex is on the edge
1258 std::cout<<" vplane: error point is on the edge\n";
1259 return 1;
1260 }
1261 else
1262 {
1263 // Close the local context
1264 TheAISContext()->CloseLocalContext(aCurrentIndex);
1265 // Construction of plane
1266 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1267 TopoDS_Vertex aVBa, aVBb;
1268 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1269 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1270 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1271 GC_MakePlane MkPlane (A, aBa, aBb);
1272 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1273 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1274 GetMapOfAIS().Bind (anAISPlane, aName);
1275 TheAISContext()->Display(anAISPlane);
7fd59977 1276 }
7fd59977 1277 }
7fd59977 1278 }
ceae62f0
A
1279 // aShapeA is an edge
1280 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1281 {
1282 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1283 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1284 std::cout<<" Select a vertex that don't belong to the edge\n";
7fd59977 1285
ceae62f0 1286 // Wait for picking
7fd59977 1287 Standard_Integer argccc = 5;
1288 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1289 const char **argvvv = (const char **) bufff;
1290 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1291 // end of the loop
7fd59977 1292
ceae62f0
A
1293 TopoDS_Shape aShapeB;
1294 for (TheAISContext()->InitSelected();
1295 TheAISContext()->MoreSelected();
1296 TheAISContext()->NextSelected())
1297 {
1298 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1299 }
ceae62f0
A
1300 // aShapeB should be a Vertex
1301 // Check that the vertex aShapeB is not on the edge
1302 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1303 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1304
1305 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1306 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1307 {
1308 // The vertex is on the edge
1309 std::cout<<" vplane: error point is on the edge\n";
1310 return 1;
7fd59977 1311 }
ceae62f0
A
1312 else
1313 {
1314 // Close the local context
1315 TheAISContext()->CloseLocalContext(aCurrentIndex);
1316 // Construction of plane
1317 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1318 TopoDS_Vertex aVAa, aVAb;
1319 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1320 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1321 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
7fd59977 1322 GC_MakePlane MkPlane (B,Aa,Ab);
ceae62f0
A
1323 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1324 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1325 GetMapOfAIS().Bind (anAISPlane ,aName);
1326 TheAISContext()->Display(anAISPlane);
7fd59977 1327 }
7fd59977 1328 }
ceae62f0
A
1329 // aShapeA is a Face
1330 else
1331 {
1332 // Close the local context: nothing to select
1333 TheAISContext()->CloseLocalContext(aCurrentIndex);
1334 // Construction of plane
1335 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1336 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1337 if (aSurface.GetType()==GeomAbs_Plane)
1338 {
1339 gp_Pln aPlane = aSurface.Plane();
1340 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1341 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1342 GetMapOfAIS().Bind (anAISPlane, aName);
1343 TheAISContext()->Display(anAISPlane);
7fd59977 1344 }
ceae62f0
A
1345 else
1346 {
1347 std::cout<<" vplane: error\n";
1348 return 1;
7fd59977 1349 }
7fd59977 1350 }
7fd59977 1351 }
1352
ceae62f0 1353 // Function vPlanePara
7fd59977 1354 // ===================
ceae62f0
A
1355 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1356 else if (!strcasecmp(argv[0], "vplanepara"))
1357 {
7fd59977 1358 TheAISContext()->OpenLocalContext();
ceae62f0 1359 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1360
ceae62f0
A
1361 // Activate modes Vertex and Face
1362 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1363 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1364 std::cout<<" Select a vertex or a face\n";
7fd59977 1365
ceae62f0 1366 // Wait for picking
7fd59977 1367 Standard_Integer argcc = 5;
1368 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1369 const char **argvv = (const char **) buff;
1370 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1371 // end of the loop
7fd59977 1372
ceae62f0
A
1373 TopoDS_Shape aShapeA;
1374 for (TheAISContext()->InitSelected();
1375 TheAISContext()->MoreSelected();
1376 TheAISContext()->NextSelected())
1377 {
1378 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1379 }
1380
ceae62f0
A
1381 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1382 {
1383 // aShapeA is a vertex
1384 // Deactivate the mode Vertex
1385 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1386 std::cout<<" Select a face\n";
7fd59977 1387
ceae62f0 1388 // Wait for picking
7fd59977 1389 Standard_Integer argccc = 5;
1390 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1391 const char **argvvv = (const char **) bufff;
1392 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1393 // end of the loop
7fd59977 1394
ceae62f0
A
1395 TopoDS_Shape aShapeB;
1396 for (TheAISContext()->InitSelected();
1397 TheAISContext()->MoreSelected();
1398 TheAISContext()->NextSelected())
1399 {
1400 // A vertex ShapeA can be on Face ShapeB
1401 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1402 }
1403
ceae62f0
A
1404 // Close the local context
1405 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1406
ceae62f0
A
1407 // Construction of plane
1408 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1409
1410 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1411 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1412 if (aSurface.GetType()==GeomAbs_Plane )
1413 {
1414 gp_Pln aPlane = aSurface.Plane();
1415 // Construct a plane parallel to aGeomPlane through A
1416 aPlane.SetLocation(A);
1417 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1418 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1419 GetMapOfAIS().Bind (aAISPlane ,aName);
1420 TheAISContext()->Display(aAISPlane);
7fd59977 1421 }
ceae62f0
A
1422 else
1423 {
1424 std::cout<<" vplanepara: error\n";
1425 return 1;
7fd59977 1426 }
7fd59977 1427 }
ceae62f0
A
1428 else
1429 {
1430 // ShapeA is a Face
1431 // Deactive the mode Face
1432 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1433 std::cout<<" Select a vertex\n";
7fd59977 1434
ceae62f0 1435 // Wait for picking
7fd59977 1436 Standard_Integer argccc = 5;
1437 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1438 const char **argvvv = (const char **) bufff;
1439 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1440 // end of the loop
7fd59977 1441
ceae62f0
A
1442 TopoDS_Shape aShapeB;
1443 for (TheAISContext()->InitSelected();
1444 TheAISContext()->MoreSelected();
1445 TheAISContext()->NextSelected())
1446 {
1447 // A vertex ShapeB can be on Face ShapeA
1448 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1449 }
ceae62f0
A
1450 // Close the local context
1451 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1452
ceae62f0
A
1453 // Construction of plane
1454 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1455
1456 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1457 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1458 if (aSurface.GetType()==GeomAbs_Plane )
1459 {
1460 gp_Pln aPlane = aSurface.Plane();
1461 aPlane.SetLocation(B);
1462 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1463 // Construct a plane parallel to aGeomPlane through B
1464 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1465 GetMapOfAIS().Bind (anAISPlane, aName);
1466 TheAISContext()->Display(anAISPlane);
7fd59977 1467 }
ceae62f0
A
1468 else
1469 {
1470 std::cout<<" vplanepara: error"<<"\n";return 1;
7fd59977 1471 }
7fd59977 1472 }
7fd59977 1473 }
1474
ceae62f0 1475 // Function vplaneortho
7fd59977 1476 // ====================
ceae62f0
A
1477 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1478 else
1479 {
7fd59977 1480 TheAISContext()->OpenLocalContext();
ceae62f0 1481 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1482
ceae62f0
A
1483 // Activate the modes Edge and Face
1484 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1485 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1486 std::cout<<" Select a face and an edge coplanar\n";
7fd59977 1487
ceae62f0 1488 // Wait for picking
7fd59977 1489 Standard_Integer argcc = 5;
1490 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1491 const char **argvv = (const char **) buff;
1492 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1493 // end of the loop
7fd59977 1494
ceae62f0
A
1495 TopoDS_Shape aShapeA;
1496 for (TheAISContext()->InitSelected();
1497 TheAISContext()->MoreSelected();
1498 TheAISContext()->NextSelected())
1499 {
1500 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1501 }
1502
ceae62f0
A
1503 if (aShapeA.ShapeType()==TopAbs_EDGE )
1504 {
1505 // ShapeA is an edge, deactivate the mode Edge...
1506 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1507 std::cout<<" Select a face\n";
7fd59977 1508
ceae62f0 1509 // Wait for picking
7fd59977 1510 Standard_Integer argccc = 5;
1511 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1512 const char **argvvv = (const char **) bufff;
1513 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1514 // end of the loop
7fd59977 1515
ceae62f0
A
1516 TopoDS_Shape aShapeB;
1517 for (TheAISContext()->InitSelected();
1518 TheAISContext()->MoreSelected();
1519 TheAISContext()->NextSelected())
1520 {
1521 // Edge ShapeA can be on Face ShapeB
1522 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1523 }
1524
ceae62f0
A
1525 // Close the local context
1526 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1527
ceae62f0
A
1528 // Construction of plane
1529 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1530 TopoDS_Vertex aVAa, aVAb;
1531 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1532 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1533 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1534 gp_Vec ab (Aa,Ab);
7fd59977 1535
1536 gp_Dir Dab (ab);
ceae62f0
A
1537 // Creation of rotation axis
1538 gp_Ax1 aRotAxis (Aa,Dab);
1539
1540 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1541 // The edge must be parallel to the face
1542 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1543 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1544 // Compare to heights
1545 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1546 >Precision::Confusion())
1547 {
1548 // the edge is not parallel to the face
1549 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1550 return 1;
7fd59977 1551 }
ceae62f0
A
1552 // the edge is OK
1553 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1554 if (aSurface.GetType()==GeomAbs_Plane)
1555 {
1556 gp_Pln aPlane = aSurface.Plane();
1557 // It rotates a half turn round the axis of rotation
1558 aPlane.Rotate(aRotAxis , M_PI/2);
1559
1560 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1561 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1562 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1563 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1564 GetMapOfAIS().Bind (anAISPlane, aName);
1565 TheAISContext()->Display(anAISPlane);
7fd59977 1566 }
ceae62f0
A
1567 else
1568 {
1569 std::cout<<" vplaneortho: error\n";
1570 return 1;
7fd59977 1571 }
7fd59977 1572 }
ceae62f0
A
1573 else
1574 {
1575 // ShapeA is a Face, deactive the mode Face.
1576 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1577 std::cout<<" Select an edge\n";
7fd59977 1578
ceae62f0 1579 // Wait for picking
7fd59977 1580 Standard_Integer argccc = 5;
1581 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1582 const char **argvvv = (const char **) bufff;
1583 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1584 // end of the loop
7fd59977 1585
ceae62f0
A
1586 TopoDS_Shape aShapeB;
1587 for (TheAISContext()->InitSelected();
1588 TheAISContext()->MoreSelected();
1589 TheAISContext()->NextSelected())
1590 {
1591 // Edge ShapeB can be on Face ShapeA
1592 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1593 }
ceae62f0
A
1594 // Close the local context
1595 TheAISContext()->CloseLocalContext(aCurrentIndex);
1596
1597 // Construction of plane
1598 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1599 TopoDS_Vertex aVBa, aVBb;
1600 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1601 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1602 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1603 gp_Vec ab (aBa,aBb);
7fd59977 1604 gp_Dir Dab (ab);
ceae62f0
A
1605 // Creation of rotation axe
1606 gp_Ax1 aRotAxis (aBa,Dab);
1607
1608 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1609 // The edge must be parallel to the face
1610 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1611 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1612 // Comparing the two heights
1613 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1614 >Precision::Confusion())
1615 {
1616 // the edge is not parallel to the face
1617 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1618 return 1;
7fd59977 1619 }
ceae62f0
A
1620 // The edge is OK
1621 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1622 if (aSurface.GetType()==GeomAbs_Plane)
1623 {
1624 gp_Pln aPlane = aSurface.Plane();
1625 // It rotates a half turn round the axis of rotation
1626 aPlane.Rotate(aRotAxis , M_PI/2);
1627 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1628 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1629 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1630 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1631 GetMapOfAIS().Bind (anAISPlane ,aName);
1632 TheAISContext()->Display(anAISPlane);
7fd59977 1633 }
ceae62f0
A
1634 else
1635 {
1636 std::cout<<" vplaneortho: error\n";
1637 return 1;
7fd59977 1638 }
7fd59977 1639 }
7fd59977 1640 }
7fd59977 1641 }
1642 return 0;
7fd59977 1643}
1644
f3889691 1645//===============================================================================================
1646//function : VChangePlane
1647//purpose :
1648//===============================================================================================
1649static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1650{
1651 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1652 if (aContextAIS.IsNull())
1653 {
1654 std::cout << theArgVec[0] << "AIS context is not available.\n";
1655 return 1;
1656 }
1657
1658 if (theArgsNb < 3 || theArgsNb > 11)
1659 {
1660 std::cerr << theArgVec[0]
1661 << ": incorrect number of command arguments.\n"
1662 << "Type help for more information.\n";
1663 return 1;
1664 }
1665
1666 TCollection_AsciiString aName (theArgVec[1]);
1667
1668 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1669 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1670 : NULL;
1671
1672 if ( aPlane.IsNull() )
1673 {
1674 std::cout << theArgVec[0]
1675 << ": there is no interactive plane with the given name."
1676 << "Type help for more information.\n";
1677 return 1;
1678 }
1679
1680 Standard_Real aCenterX = aPlane->Center().X();
1681 Standard_Real aCenterY = aPlane->Center().Y();
1682 Standard_Real aCenterZ = aPlane->Center().Z();
1683
1684 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1685 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1686 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1687
1688 Standard_Real aSizeX = 0.0;
1689 Standard_Real aSizeY = 0.0;
1690 aPlane->Size (aSizeX, aSizeY);
1691 Standard_Boolean isUpdate = Standard_True;
1692
1693 TCollection_AsciiString aPName, aPValue;
1694 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1695 {
1696 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1697 TCollection_AsciiString anArgCase = anArg;
1698 anArgCase.UpperCase();
1699 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1700 {
1701 aPName.UpperCase();
1702 if (aPName.IsEqual ("X"))
1703 {
1704 aCenterX = aPValue.RealValue();
1705 }
1706 else if (aPName.IsEqual ("Y"))
1707 {
1708 aCenterY = aPValue.RealValue();
1709 }
1710 else if (aPName.IsEqual ("Z"))
1711 {
1712 aCenterZ = aPValue.RealValue();
1713 }
1714 else if (aPName.IsEqual ("DX"))
1715 {
1716 aDirX = aPValue.RealValue();
1717 }
1718 else if (aPName.IsEqual ("DY"))
1719 {
1720 aDirY = aPValue.RealValue();
1721 }
1722 else if (aPName.IsEqual ("DZ"))
1723 {
1724 aDirZ = aPValue.RealValue();
1725 }
1726 else if (aPName.IsEqual ("SX"))
1727 {
1728 aSizeX = aPValue.RealValue();
1729 }
1730 else if (aPName.IsEqual ("SY"))
1731 {
1732 aSizeY = aPValue.RealValue();
1733 }
1734 }
1735 else if (anArg.IsEqual ("NOUPDATE"))
1736 {
1737 isUpdate = Standard_False;
1738 }
1739 }
1740
1741 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1742 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1743 aPlane->SetCenter (aCenterPnt);
1744 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1745 aPlane->SetSize (aSizeX, aSizeY);
1746
f751596e 1747 aContextAIS->Update (aPlane, isUpdate);
f3889691 1748
1749 return 0;
1750}
7fd59977 1751
1752//==============================================================================
1753// Fonction vline
1754// --------------- Uniquement par parametre. Pas de selection dans le viewer.
1755//==============================================================================
1756
1757//==============================================================================
1758//function : VLineBuilder
161c4476 1759//purpose : Build an AIS_Line
7fd59977 1760//Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1761// [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1762//==============================================================================
1763#include <Geom_CartesianPoint.hxx>
1764#include <AIS_Line.hxx>
1765
1766
161c4476 1767static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 1768{
1769 Standard_Integer myCurrentIndex;
1770 // Verifications
1771 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1772 // Fermeture des contextes
1773 TheAISContext()->CloseAllContexts();
1774
1775 // On recupere les parametres
1776 Handle(AIS_InteractiveObject) theShapeA;
1777 Handle(AIS_InteractiveObject) theShapeB;
1778
1779 // Parametres: AIS_Point AIS_Point
1780 // ===============================
1781 if (argc==4) {
1782 theShapeA=
1783 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1784 // On verifie que c'est bien une AIS_Point
1785 if (!theShapeA.IsNull() &&
1786 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1787 // on recupere le deuxieme AIS_Point
1788 theShapeB=
1789 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1790 if (theShapeA.IsNull() ||
1791 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1792 {
1793 di <<"vline error: wrong type of 2de argument."<<"\n";
1794 return 1;
1795 }
1796 }
161c4476 1797 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
7fd59977 1798 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
c5f3a425 1799 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1800 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
7fd59977 1801
1802 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
c5f3a425 1803 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
7fd59977 1804 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1805
1806 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
c5f3a425 1807 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
7fd59977 1808 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1809
1810 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1811 // B=A
1812 di<<"vline error: same points"<<"\n";return 1;
1813 }
1814 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1815 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1816 GetMapOfAIS().Bind(theAISLine,argv[1] );
1817 TheAISContext()->Display(theAISLine );
1818
1819 }
1820
1821 // Parametres 6 Reals
1822 // ==================
1823
1824 else if (argc==8) {
161c4476 1825 // On verifie que les deux points ne sont pas confondus
7fd59977 1826
1827 Standard_Real coord[6];
1828 for(Standard_Integer i=0;i<=2;i++){
91322f44 1829 coord[i]=Draw::Atof(argv[2+i]);
1830 coord[i+3]=Draw::Atof(argv[5+i]);
7fd59977 1831 }
1832
1833 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1834 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1835
1836 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1837 GetMapOfAIS().Bind(theAISLine,argv[1] );
1838 TheAISContext()->Display(theAISLine );
1839
1840 }
1841
1842 // Pas de parametres: Selection dans le viewer.
1843 // ============================================
1844
1845 else {
1846 TheAISContext()->OpenLocalContext();
1847 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1848
1849 // Active le mode Vertex.
1850 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1851 di<<" Select a vertex "<<"\n";
1852
1853 // Boucle d'attente waitpick.
1854 Standard_Integer argcc = 5;
1855 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1856 const char **argvv = (const char **) buff;
1857 while (ViewerMainLoop( argcc, argvv) ) { }
1858 // fin de la boucle
1859
1860 TopoDS_Shape ShapeA;
1861 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1862 ShapeA = TheAISContext()->SelectedShape();
1863 }
1864
1865 // ShapeA est un Vertex
1866 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1867
1868 di<<" Select a different vertex."<<"\n";
1869
1870 TopoDS_Shape ShapeB;
1871 do {
1872
1873 // Boucle d'attente waitpick.
1874 Standard_Integer argccc = 5;
1875 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1876 const char **argvvv = (const char **) bufff;
1877 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 1878 // fin de la boucle
7fd59977 1879
1880 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1881 ShapeB = TheAISContext()->SelectedShape();
1882 }
1883
1884
1885 } while(ShapeB.IsSame(ShapeA) );
1886
1887 // Fermeture du context local
1888 TheAISContext()->CloseLocalContext(myCurrentIndex);
1889
1890 // Construction de la line
1891 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1892 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1893
1894 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1895 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1896
1897 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1898 GetMapOfAIS().Bind(theAISLine,argv[1] );
1899 TheAISContext()->Display(theAISLine );
1900
1901 }
1902 else {
1903 di<<"vline error."<<"\n";
1904 }
1905
1906 }
1907
1908 return 0;
1909}
1910
329843e2
A
1911//==============================================================================
1912// class : FilledCircle
1913// purpose : creates filled circle based on AIS_InteractiveObject
1914// and Geom_Circle.
1915// This class is used to check method Matches() of class
1916// Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1917// because none of AIS classes provides creation of
1918// Select3D_SensitiveCircle with member myFillStatus = Standard_True
1919// (look method ComputeSelection() )
1920//==============================================================================
1921
1922Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1923{
1924 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1925 gp_Circ aCirc(anAxes, theRadius);
1926 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1927 return aCircle;
1928}
1929
329843e2
A
1930class FilledCircle : public AIS_InteractiveObject
1931{
1932public:
1933 // CASCADE RTTI
ec357c5c 1934 DEFINE_STANDARD_RTTI(FilledCircle, AIS_InteractiveObject);
329843e2
A
1935
1936 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1937 FilledCircle(Handle(Geom_Circle) theCircle);
1938
1939private:
1940 TopoDS_Face ComputeFace();
1941
1942 // Virtual methods implementation
1943 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1944 const Handle(Prs3d_Presentation)& thePresentation,
1945 const Standard_Integer theMode);
1946
1947 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1948 const Standard_Integer theMode);
1949
1950protected:
1951 Handle(Geom_Circle) myCircle;
1952 Standard_Boolean myFilledStatus;
1953
1954};
1955
329843e2
A
1956
1957FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1958{
1959 myCircle = CreateCircle(theCenter, theRadius);
1960 myFilledStatus = Standard_True;
1961}
1962
1963FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1964{
1965 myCircle = theCircle;
1966 myFilledStatus = Standard_True;
1967}
1968
1969TopoDS_Face FilledCircle::ComputeFace()
1970{
1971 // Create edge from myCircle
1972 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1973 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1974
1975 // Create wire from anEdge
1976 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1977 TopoDS_Wire aWire = aWireMaker.Wire();
1978
1979 // Create face from aWire
1980 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1981 TopoDS_Face aFace = aFaceMaker.Face();
1982
1983 return aFace;
1984}
1985
857ffd5e 1986void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1987 const Handle(Prs3d_Presentation) &thePresentation,
329843e2
A
1988 const Standard_Integer theMode)
1989{
1990 thePresentation->Clear();
1991
1992 TopoDS_Face aFace = ComputeFace();
1993
1994 if (aFace.IsNull()) return;
1995 if (theMode != 0) return;
1996
1997 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
1998}
1999
857ffd5e 2000void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 2001 const Standard_Integer /*theMode*/)
329843e2
A
2002{
2003 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2004 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2005 myCircle, myFilledStatus);
2006 theSelection->Add(aSensitiveCircle);
2007}
7fd59977 2008
2009//==============================================================================
2010// Fonction vcircle
2011// ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2012//==============================================================================
2013
2014//==============================================================================
2015//function : VCircleBuilder
161c4476 2016//purpose : Build an AIS_Circle
329843e2
A
2017//Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2018// PointName PointName PointName IsFilled
7fd59977 2019//==============================================================================
329843e2
A
2020
2021void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2022 TCollection_AsciiString theName,
2023 Standard_Boolean isFilled)
2024{
2025 Handle(AIS_InteractiveObject) aCircle;
2026 if (isFilled)
2027 {
2028 aCircle = new FilledCircle(theGeomCircle);
2029 }
2030 else
2031 {
2032 aCircle = new AIS_Circle(theGeomCircle);
9e8804b6 2033 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
329843e2
A
2034 }
2035
2036 // Check if there is an object with given name
2037 // and remove it from context
2038 if (GetMapOfAIS().IsBound2(theName))
2039 {
2040 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2041 Handle(AIS_InteractiveObject) anInterObj =
2042 Handle(AIS_InteractiveObject)::DownCast(anObj);
2043 TheAISContext()->Remove(anInterObj, Standard_False);
2044 GetMapOfAIS().UnBind2(theName);
2045 }
2046
2047 // Bind the circle to its name
2048 GetMapOfAIS().Bind(aCircle, theName);
2049
2050 // Display the circle
2051 TheAISContext()->Display(aCircle);
2052
2053}
7fd59977 2054
35e08fe8 2055static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
7fd59977 2056{
2057 Standard_Integer myCurrentIndex;
329843e2
A
2058 // Verification of the arguments
2059 if (argc>6 || argc<2)
2060 {
2061 std::cout << "vcircle error: expect 4 arguments.\n";
2062 return 1; // TCL_ERROR
2063 }
7fd59977 2064 TheAISContext()->CloseAllContexts();
2065
329843e2
A
2066 // There are all arguments
2067 if (argc == 6)
2068 {
2069 // Get arguments
2070 TCollection_AsciiString aName(argv[1]);
91322f44 2071 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
329843e2 2072
7fd59977 2073 Handle(AIS_InteractiveObject) theShapeA;
2074 Handle(AIS_InteractiveObject) theShapeB;
2075
329843e2
A
2076 theShapeA =
2077 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2078 theShapeB =
2079 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2080
7fd59977 2081
2082 // Arguments: AIS_Point AIS_Point AIS_Point
2083 // ========================================
329843e2 2084 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
7fd59977 2085 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2086 {
329843e2
A
2087 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2088 {
2089 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2090 return 1; // TCL_ERROR
7fd59977 2091 }
329843e2 2092 // The third object must be a point
7fd59977 2093 Handle(AIS_InteractiveObject) theShapeC =
329843e2 2094 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
7fd59977 2095 if (theShapeC.IsNull() ||
329843e2
A
2096 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2097 {
2098 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2099 return 1; // TCL_ERROR
2100 }
7fd59977 2101 // tag
329843e2
A
2102 // Verify that the three points are different
2103 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2104 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2105 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2106
2107 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2108 Handle(Geom_CartesianPoint) myCartPointA =
2109 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2110
2111 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2112 Handle(Geom_CartesianPoint) myCartPointB =
2113 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2114
2115 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2116 Handle(Geom_CartesianPoint) myCartPointC =
2117 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
7fd59977 2118
2119 // Test A=B
91322f44 2120 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2121 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2122 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
329843e2
A
2123 {
2124 std::cout << "vcircle error: Same points.\n";
2125 return 1; // TCL_ERROR
7fd59977 2126 }
2127 // Test A=C
91322f44 2128 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2129 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2130 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2131 {
2132 std::cout << "vcircle error: Same points.\n";
2133 return 1; // TCL_ERROR
7fd59977 2134 }
2135 // Test B=C
91322f44 2136 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2137 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2138 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2139 {
2140 std::cout << "vcircle error: Same points.\n";
2141 return 1;// TCL_ERROR
7fd59977 2142 }
329843e2
A
2143 // Construction of the circle
2144 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2145 myCartPointB->Pnt(), myCartPointC->Pnt() );
2146 Handle (Geom_Circle) theGeomCircle;
2147 try
2148 {
2149 theGeomCircle = Cir.Value();
2150 }
2151 catch (StdFail_NotDone)
2152 {
2153 std::cout << "vcircle error: can't create circle\n";
2154 return -1; // TCL_ERROR
2155 }
2156
2157 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2158 }
2159
329843e2 2160 // Arguments: AIS_Plane AIS_Point Real
7fd59977 2161 // ===================================
329843e2
A
2162 else if (theShapeA->Type() == AIS_KOI_Datum &&
2163 theShapeA->Signature() == 7 )
2164 {
2165 if (theShapeB->Type() != AIS_KOI_Datum ||
2166 theShapeB->Signature() != 1 )
2167 {
2168 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2169 return 1; // TCL_ERROR
2170 }
623c29a5 2171 // Check that the radius is >= 0
91322f44 2172 if (Draw::Atof(argv[4]) <= 0 )
329843e2
A
2173 {
2174 std::cout << "vcircle error: the radius must be >=0.\n";
2175 return 1; // TCL_ERROR
7fd59977 2176 }
7fd59977 2177
329843e2
A
2178 // Recover the normal to the plane
2179 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2180 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
7fd59977 2181
329843e2
A
2182 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2183 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2184 Handle(Geom_CartesianPoint) myCartPointB =
2185 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
7fd59977 2186
2187 gp_Pln mygpPlane = myGeomPlane->Pln();
2188 gp_Ax1 thegpAxe = mygpPlane.Axis();
2189 gp_Dir theDir = thegpAxe.Direction();
329843e2 2190 gp_Pnt theCenter = myCartPointB->Pnt();
91322f44 2191 Standard_Real TheR = Draw::Atof(argv[4]);
329843e2
A
2192 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2193 Handle (Geom_Circle) theGeomCircle;
2194 try
2195 {
2196 theGeomCircle = Cir.Value();
2197 }
2198 catch (StdFail_NotDone)
2199 {
2200 std::cout << "vcircle error: can't create circle\n";
2201 return -1; // TCL_ERROR
2202 }
2203
2204 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2205
2206 }
2207
2208 // Error
329843e2
A
2209 else
2210 {
2211 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2212 return 1; // TCL_ERROR
7fd59977 2213 }
2214
2215 }
329843e2 2216 // No arguments: selection in the viewer
7fd59977 2217 // =========================================
329843e2
A
2218 else
2219 {
2220 // Get the name of the circle
2221 TCollection_AsciiString aName(argv[1]);
7fd59977 2222
2223 TheAISContext()->OpenLocalContext();
329843e2 2224 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 2225
329843e2 2226 // Activate selection mode for vertices and faces
7fd59977 2227 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2228 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2229 std::cout << " Select a vertex or a face\n";
7fd59977 2230
329843e2 2231 // Wait for picking
7fd59977 2232 Standard_Integer argcc = 5;
2233 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2234 const char **argvv = (const char **) buff;
2235 while (ViewerMainLoop( argcc, argvv) ) { }
329843e2 2236 // end of the loop
7fd59977 2237
2238 TopoDS_Shape ShapeA;
329843e2
A
2239 for(TheAISContext()->InitSelected();
2240 TheAISContext()->MoreSelected();
2241 TheAISContext()->NextSelected() )
2242 {
7fd59977 2243 ShapeA = TheAISContext()->SelectedShape();
2244 }
2245
329843e2
A
2246 // ShapeA is a Vertex
2247 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2248 {
7fd59977 2249 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2250 std::cout << " Select a different vertex\n";
7fd59977 2251
2252 TopoDS_Shape ShapeB;
329843e2
A
2253 do
2254 {
2255 // Wait for picking
7fd59977 2256 Standard_Integer argccc = 5;
2257 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2258 const char **argvvv = (const char **) bufff;
2259 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2260 // end of the loop
7fd59977 2261
329843e2
A
2262 for(TheAISContext()->InitSelected();
2263 TheAISContext()->MoreSelected();
2264 TheAISContext()->NextSelected() )
2265 {
7fd59977 2266 ShapeB = TheAISContext()->SelectedShape();
2267 }
7fd59977 2268 } while(ShapeB.IsSame(ShapeA) );
2269
329843e2 2270 // Selection of ShapeC
ceae62f0 2271 std::cout << " Select the last vertex\n";
7fd59977 2272 TopoDS_Shape ShapeC;
329843e2
A
2273 do
2274 {
2275 // Wait for picking
7fd59977 2276 Standard_Integer argcccc = 5;
2277 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2278 const char **argvvvv = (const char **) buffff;
2279 while (ViewerMainLoop( argcccc, argvvvv) ) { }
329843e2 2280 // end of the loop
7fd59977 2281
329843e2
A
2282 for(TheAISContext()->InitSelected();
2283 TheAISContext()->MoreSelected();
2284 TheAISContext()->NextSelected() )
2285 {
7fd59977 2286 ShapeC = TheAISContext()->SelectedShape();
2287 }
7fd59977 2288 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
329843e2
A
2289
2290 // Get isFilled
2291 Standard_Boolean isFilled;
2292 std::cout << "Enter filled status (0 or 1)\n";
2293 cin >> isFilled;
7fd59977 2294
329843e2 2295 // Close the local context
7fd59977 2296 TheAISContext()->CloseLocalContext(myCurrentIndex);
2297
329843e2
A
2298 // Construction of the circle
2299 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2300 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2301 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2302
2303 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2304 Handle (Geom_Circle) theGeomCircle;
2305 try
2306 {
2307 theGeomCircle = Cir.Value();
2308 }
2309 catch (StdFail_NotDone)
2310 {
2311 std::cout << "vcircle error: can't create circle\n";
2312 return -1; // TCL_ERROR
2313 }
7fd59977 2314
329843e2 2315 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2316
2317 }
329843e2 2318 // Shape is a face
ceae62f0 2319 else
329843e2 2320 {
ceae62f0 2321 std::cout << " Select a vertex (in your face)\n";
7fd59977 2322 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2323
2324 TopoDS_Shape ShapeB;
329843e2 2325 // Wait for picking
7fd59977 2326 Standard_Integer argccc = 5;
2327 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2328 const char **argvvv = (const char **) bufff;
2329 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2330 // end of the loop
7fd59977 2331
329843e2
A
2332 for(TheAISContext()->InitSelected();
2333 TheAISContext()->MoreSelected();
2334 TheAISContext()->NextSelected() )
2335 {
7fd59977 2336 ShapeB = TheAISContext()->SelectedShape();
2337 }
2338
329843e2
A
2339 // Recover the radius
2340 Standard_Real theRad;
2341 do
2342 {
2343 std::cout << " Enter the value of the radius:\n";
2344 cin >> theRad;
2345 } while (theRad <= 0);
2346
2347 // Get filled status
2348 Standard_Boolean isFilled;
2349 std::cout << "Enter filled status (0 or 1)\n";
2350 cin >> isFilled;
7fd59977 2351
329843e2 2352 // Close the local context
7fd59977 2353 TheAISContext()->CloseLocalContext(myCurrentIndex);
329843e2 2354 // Construction of the circle
7fd59977 2355
329843e2
A
2356 // Recover the normal to the plane. tag
2357 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2358 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2359 gp_Pln myPlane = mySurface.Plane();
2360 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
7fd59977 2361 gp_Pln mygpPlane = theGeomPlane->Pln();
2362 gp_Ax1 thegpAxe = mygpPlane.Axis();
2363 gp_Dir theDir = thegpAxe.Direction();
2364
329843e2
A
2365 // Recover the center
2366 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
7fd59977 2367
623c29a5 2368 // Construct the circle
329843e2
A
2369 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2370 Handle (Geom_Circle) theGeomCircle;
2371 try
2372 {
2373 theGeomCircle = Cir.Value();
2374 }
2375 catch (StdFail_NotDone)
2376 {
2377 std::cout << "vcircle error: can't create circle\n";
2378 return -1; // TCL_ERROR
2379 }
7fd59977 2380
329843e2
A
2381 DisplayCircle(theGeomCircle, aName, isFilled);
2382
7fd59977 2383 }
2384
7fd59977 2385 }
2386
2387 return 0;
2388}
2389
29e2c6d2 2390//=======================================================================
7fd59977 2391//function : VDrawText
29e2c6d2 2392//purpose :
2393//=======================================================================
2394static int VDrawText (Draw_Interpretor& theDI,
2395 Standard_Integer theArgsNb,
2396 const char** theArgVec)
7fd59977 2397{
29e2c6d2 2398 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2399 if (theArgsNb < 3)
fe551aef 2400 {
29e2c6d2 2401 std::cout << "Error: wrong number of arguments! See usage:\n";
2402 theDI.PrintHelp (theArgVec[0]);
2403 return 1;
2404 }
2405 else if (aContext.IsNull())
2406 {
2407 std::cout << "Error: no active view!\n";
2408 return 1;
fe551aef 2409 }
2410
29e2c6d2 2411 Standard_Integer anArgIt = 1;
2412 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2413 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2414 Handle(AIS_TextLabel) aTextPrs;
2415 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
7fd59977 2416
29e2c6d2 2417 if (GetMapOfAIS().IsBound2 (aName))
7fd59977 2418 {
29e2c6d2 2419 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2420 }
2421 else
2422 {
2423 aTextPrs = new AIS_TextLabel();
2424 aTextPrs->SetFont ("Courier");
7fd59977 2425 }
13a22457 2426
29e2c6d2 2427 aTextPrs->SetText (aText);
13a22457 2428
29e2c6d2 2429 for (; anArgIt < theArgsNb; ++anArgIt)
161c4476 2430 {
29e2c6d2 2431 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2432 aParam.LowerCase();
2433
2434 if (anAutoUpdater.parseRedrawMode (aParam))
13a22457 2435 {
29e2c6d2 2436 continue;
13a22457 2437 }
29e2c6d2 2438 else if (aParam == "-pos"
2439 || aParam == "-position")
2440 {
2441 if (anArgIt + 3 >= theArgsNb)
2442 {
2443 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2444 return 1;
2445 }
7fd59977 2446
29e2c6d2 2447 gp_Pnt aPos;
2448 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2449 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2450 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2451 aTextPrs->SetPosition (aPos);
2452 }
2453 else if (aParam == "-color")
2454 {
2455 if (anArgIt + 1 >= theArgsNb)
2456 {
2457 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2458 return 1;
2459 }
7fd59977 2460
29e2c6d2 2461 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2462 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2463 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2464 {
2465 anArgIt += 1;
2466 aTextPrs->SetColor (aNameOfColor);
2467 continue;
2468 }
2469 else if (anArgIt + 3 >= theArgsNb)
2470 {
2471 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2472 return 1;
2473 }
7fd59977 2474
29e2c6d2 2475 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2476 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2477 if (!aColor.IsRealValue()
2478 || !aGreen.IsRealValue()
2479 || !aBlue.IsRealValue())
2480 {
2481 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2482 return 1;
2483 }
7fd59977 2484
29e2c6d2 2485 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2486 aGreen.RealValue(),
2487 aBlue.RealValue());
7fd59977 2488
29e2c6d2 2489 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2490 anArgIt += 3;
2491 }
2492 else if (aParam == "-halign")
2493 {
2494 if (++anArgIt >= theArgsNb)
2495 {
2496 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2497 return 1;
2498 }
13a22457 2499
29e2c6d2 2500 TCollection_AsciiString aType (theArgVec[anArgIt]);
2501 aType.LowerCase();
2502 if (aType == "left")
2503 {
2504 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2505 }
2506 else if (aType == "center")
2507 {
2508 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2509 }
2510 else if (aType == "right")
2511 {
2512 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2513 }
2514 else
2515 {
2516 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2517 return 1;
2518 }
2519 }
2520 else if (aParam == "-valign")
2521 {
2522 if (++anArgIt >= theArgsNb)
2523 {
2524 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2525 return 1;
2526 }
2527
2528 TCollection_AsciiString aType (theArgVec[anArgIt]);
2529 aType.LowerCase();
2530 if (aType == "top")
2531 {
2532 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2533 }
2534 else if (aType == "center")
2535 {
2536 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2537 }
2538 else if (aType == "bottom")
2539 {
2540 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2541 }
2542 else
2543 {
2544 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2545 return 1;
2546 }
2547 }
2548 else if (aParam == "-angle")
2549 {
2550 if (++anArgIt >= theArgsNb)
2551 {
2552 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2553 return 1;
2554 }
13a22457 2555
29e2c6d2 2556 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2557 }
2558 else if (aParam == "-zoom")
2559 {
2560 if (++anArgIt >= theArgsNb)
2561 {
2562 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2563 return 1;
2564 }
13a22457 2565
29e2c6d2 2566 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2567 }
2568 else if (aParam == "-height")
2569 {
2570 if (++anArgIt >= theArgsNb)
2571 {
2572 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2573 return 1;
2574 }
13a22457 2575
29e2c6d2 2576 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2577 }
2578 else if (aParam == "-aspect")
2579 {
2580 if (++anArgIt >= theArgsNb)
2581 {
2582 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2583 return 1;
2584 }
13a22457 2585
29e2c6d2 2586 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2587 anOption.LowerCase();
2588 if (anOption.IsEqual ("regular"))
2589 {
2590 aTextPrs->SetFontAspect (Font_FA_Regular);
2591 }
2592 else if (anOption.IsEqual ("bold"))
2593 {
2594 aTextPrs->SetFontAspect (Font_FA_Bold);
2595 }
2596 else if (anOption.IsEqual ("italic"))
2597 {
2598 aTextPrs->SetFontAspect (Font_FA_Italic);
2599 }
2600 else if (anOption.IsEqual ("bolditalic"))
2601 {
2602 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2603 }
2604 }
2605 else if (aParam == "-font")
2606 {
2607 if (++anArgIt >= theArgsNb)
2608 {
2609 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2610 return 1;
2611 }
13a22457 2612
29e2c6d2 2613 aTextPrs->SetFont (theArgVec[anArgIt]);
2614 }
2615 else
2616 {
2617 std::cout << "Error: unknown argument '" << aParam << "'\n";
2618 return 1;
2619 }
13a22457
S
2620 }
2621
29e2c6d2 2622 ViewerTest::Display (aName, aTextPrs, Standard_False);
161c4476 2623 return 0;
7fd59977 2624}
2625
2626#include <math.h>
2627#include <gp_Pnt.hxx>
2628#include <Graphic3d_ArrayOfPoints.hxx>
2629#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 2630#include <Graphic3d_ArrayOfTriangles.hxx>
2631#include <Poly_Array1OfTriangle.hxx>
2632#include <Poly_Triangle.hxx>
2633#include <Poly_Triangulation.hxx>
2634#include <TColgp_Array1OfPnt.hxx>
2635#include <TShort_Array1OfShortReal.hxx>
2636#include <TShort_HArray1OfShortReal.hxx>
2637
2638#include <AIS_Triangulation.hxx>
7fd59977 2639#include <StdPrs_ToolShadedShape.hxx>
2640#include <Poly_Connect.hxx>
2641#include <TColgp_Array1OfDir.hxx>
2642#include <Graphic3d_GraphicDriver.hxx>
2643
7fd59977 2644#include <TColStd_Array1OfInteger.hxx>
2645#include <TColStd_HArray1OfInteger.hxx>
2646#include <Prs3d_ShadingAspect.hxx>
2647#include <Graphic3d_MaterialAspect.hxx>
2648#include <Graphic3d_AspectFillArea3d.hxx>
2649
2650#include <BRepPrimAPI_MakeCylinder.hxx>
2651#include <TopoDS_Shape.hxx>
2652#include <TopExp_Explorer.hxx>
2653#include <TopAbs.hxx>
2654#include <StdSelect_ShapeTypeFilter.hxx>
ec357c5c 2655#include <AIS_InteractiveObject.hxx>
7fd59977 2656
2657
2658//===============================================================================================
2659//function : CalculationOfSphere
2660//author : psn
2661//purpose : Create a Sphere
2662//===============================================================================================
2663
161c4476 2664Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
7fd59977 2665 int res ,
2666 double Radius ){
2667 double mRadius = Radius;
2668 double mCenter[3] = {X,Y,Z};
2669 int mThetaResolution;
2670 int mPhiResolution;
2671 double mStartTheta = 0;//StartTheta;
2672 double mEndTheta = 360;//EndTheta;
2673 double mStartPhi = 0;//StartPhi;
2674 double mEndPhi = 180;//EndPhi;
2675 res = res < 4 ? 4 : res;
2676
2677 mThetaResolution = res;
2678 mPhiResolution = res;
2679
2680 int i, j;
2681 int jStart, jEnd, numOffset;
7fd59977 2682 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2683 double startTheta, endTheta, startPhi, endPhi;
2684 int base, numPoles=0, thetaResolution, phiResolution;
2685
2686 int pts[3];
2687 int piece = -1;
2688 int numPieces = 1;
2689 if ( numPieces > mThetaResolution ) {
2690 numPieces = mThetaResolution;
2691 }
2692
2693 int localThetaResolution = mThetaResolution;
2694 double localStartTheta = mStartTheta;
2695 double localEndTheta = mEndTheta;
2696
2697 while ( localEndTheta < localStartTheta ) {
2698 localEndTheta += 360.0;
2699 }
2700
2701 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2702
2703 // Change the ivars based on pieces.
2704 int start, end;
2705 start = piece * localThetaResolution / numPieces;
2706 end = (piece+1) * localThetaResolution / numPieces;
2707 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2708 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2709 localThetaResolution = end - start;
2710
7fd59977 2711 // Create north pole if needed
2712 int number_point = 0;
2713 int number_pointArray = 0;
2714
2715 if ( mStartPhi <= 0.0 ) {
2716 number_pointArray++;
2717 numPoles++;
2718 }
2719 if ( mEndPhi >= 180.0 ) {
2720 number_pointArray++;
2721 numPoles++;
2722 }
161c4476 2723
7fd59977 2724 // Check data, determine increments, and convert to radians
2725 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
c6541a0c 2726 startTheta *= M_PI / 180.0;
7fd59977 2727 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
c6541a0c 2728 endTheta *= M_PI / 180.0;
7fd59977 2729
2730
2731 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
c6541a0c 2732 startPhi *= M_PI / 180.0;
7fd59977 2733 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
c6541a0c 2734 endPhi *= M_PI / 180.0;
7fd59977 2735
2736 phiResolution = mPhiResolution - numPoles;
2737 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2738 thetaResolution = localThetaResolution;
2739 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2740 ++localThetaResolution;
2741 }
2742 deltaTheta = (endTheta - startTheta) / thetaResolution;
2743
2744 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2745 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2746
2747 // Create intermediate points
2748 for ( i = 0; i < localThetaResolution; i++ ) {
2749 for ( j = jStart; j < jEnd; j++ ) {
2750 number_pointArray++;
2751 }
2752 }
2753
2754 //Generate mesh connectivity
2755 base = phiResolution * localThetaResolution;
2756
2757 int number_triangle = 0 ;
2758 if ( mStartPhi <= 0.0 ) { // around north pole
2759 number_triangle += localThetaResolution;
2760 }
161c4476 2761
7fd59977 2762 if ( mEndPhi >= 180.0 ) { // around south pole
2763 number_triangle += localThetaResolution;
2764 }
2765
2766 // bands in-between poles
2767 for ( i=0; i < localThetaResolution; i++){
2768 for ( j=0; j < (phiResolution-1); j++){
2769 number_triangle +=2;
2770 }
2771 }
2772
2773 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2774 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2775 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2776
2777 if ( mStartPhi <= 0.0 ){
2778 x[0] = mCenter[0];
2779 x[1] = mCenter[1];
2780 x[2] = mCenter[2] + mRadius;
2781 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2782 }
2783
2784 // Create south pole if needed
2785 if ( mEndPhi >= 180.0 ){
2786 x[0] = mCenter[0];
2787 x[1] = mCenter[1];
2788 x[2] = mCenter[2] - mRadius;
2789 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2790 }
2791
2792 number_point = 3;
2793 for ( i=0; i < localThetaResolution; i++){
c6541a0c 2794 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
7fd59977 2795 for ( j = jStart; j < jEnd; j++){
2796 phi = startPhi + j*deltaPhi;
2797 radius = mRadius * sin((double)phi);
2798 n[0] = radius * cos((double)theta);
2799 n[1] = radius * sin((double)theta);
2800 n[2] = mRadius * cos((double)phi);
2801 x[0] = n[0] + mCenter[0];
2802 x[1] = n[1] + mCenter[1];
2803 x[2] = n[2] + mCenter[2];
2804 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2805 number_point++;
2806 }
2807 }
2808
2809 numPoles = 3;
2810 number_triangle = 1;
2811 if ( mStartPhi <= 0.0 ){// around north pole
2812 for (i=0; i < localThetaResolution; i++){
2813 pts[0] = phiResolution*i + numPoles;
2814 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2815 pts[2] = 1;
2816 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2817 number_triangle++;
2818 }
2819 }
161c4476 2820
7fd59977 2821 if ( mEndPhi >= 180.0 ){ // around south pole
2822 numOffset = phiResolution - 1 + numPoles;
2823 for (i=0; i < localThetaResolution; i++){
2824 pts[0] = phiResolution*i + numOffset;
2825 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2826 pts[1] = numPoles - 1;
2827 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2828 number_triangle++;
2829 }
2830 }
2831
2832 // bands in-between poles
161c4476 2833
7fd59977 2834 for (i=0; i < localThetaResolution; i++){
2835 for (j=0; j < (phiResolution-1); j++){
2836 pts[0] = phiResolution*i + j + numPoles;
2837 pts[1] = pts[0] + 1;
2838 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2839 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2840 number_triangle++;
2841 pts[1] = pts[2];
2842 pts[2] = pts[1] - 1;
2843 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2844 number_triangle++;
2845 }
2846 }
2847
2848 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2849
2850 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2851
2852 Standard_Integer index[3];
2853 Standard_Real Tol = Precision::Confusion();
2854
2855 gp_Dir Nor;
2856 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2857 gp_XYZ eqPlan(0, 0, 0);
2858 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2859 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2860 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2861 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2862 gp_XYZ vv = v1^v2;
2863 Standard_Real mod = vv.Modulus();
2864 if(mod < Tol) continue;
2865 eqPlan += vv/mod;
2866 }
2867
2868 Standard_Real modmax = eqPlan.Modulus();
2869
161c4476 2870 if(modmax > Tol)
7fd59977 2871 Nor = gp_Dir(eqPlan);
161c4476 2872 else
7fd59977 2873 Nor = gp_Dir(0., 0., 1.);
2874
2875 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2876 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2877 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2878 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2879 }
2880
2881 delete pc;
2882 polyTriangulation->SetNormals(Normals);
2883
2884 return polyTriangulation;
2885}
2886
2887//===============================================================================================
2888//function : VDrawSphere
2889//author : psn
2890//purpose : Create an AIS shape.
7fd59977 2891//===============================================================================================
35e08fe8 2892static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
161c4476
K
2893{
2894 // check for errors
2895 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2896 if (aContextAIS.IsNull())
2897 {
2898 std::cout << "Call vinit before!\n";
2899 return 1;
2900 }
2901 else if (argc < 3)
2902 {
2903 std::cout << "Use: " << argv[0]
58655684 2904 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
161c4476
K
2905 return 1;
2906 }
7fd59977 2907
161c4476
K
2908 // read the arguments
2909 TCollection_AsciiString aShapeName (argv[1]);
91322f44 2910 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2911 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2912 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2913 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2914 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
b7cd4ba7 2915 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2916 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
7fd59977 2917
161c4476 2918 // remove AIS object with given name from map
208e6839 2919 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
161c4476 2920
b7cd4ba7 2921 if (toPrintInfo)
2922 std::cout << "Compute Triangulation...\n";
161c4476
K
2923 Handle(AIS_Triangulation) aShape
2924 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2925 aResolution,
2926 aRadius));
2927 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2928 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2929
161c4476
K
2930 // stupid initialization of Green color in RGBA space as integer
2931 // probably wrong for big-endian CPUs
2932 Standard_Integer aRed = 0;
2933 Standard_Integer aGreen = 255;
2934 Standard_Integer aBlue = 0;
2935 Standard_Integer anAlpha = 0; // not used
2936 Standard_Integer aColorInt = aRed;
2937 aColorInt += aGreen << 8;
2938 aColorInt += aBlue << 16;
2939 aColorInt += anAlpha << 24;
2940
2941 // setup colors array per vertex
2942 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2943 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2944 {
2945 aColorArray->SetValue (aNodeId, aColorInt);
7fd59977 2946 }
161c4476
K
2947 aShape->SetColors (aColorArray);
2948
2949 // show statistics
2950 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2951 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2952 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2953 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2954 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2955 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2956 aTotalSize >>= 20; //MB
2957 aNormalsSize >>= 20;
2958 aColorsSize >>= 20;
2959 aTrianglesSize >>= 20;
2960 aPolyConnectSize >>= 20;
b7cd4ba7 2961 if (toPrintInfo)
2962 {
2963 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2964 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2965 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2966 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2967 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2968 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2969 }
7fd59977 2970
2971 // Setting material properties, very important for desirable visual result!
161c4476
K
2972 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2973 aMat.SetAmbient (0.2);
2974 aMat.SetSpecular (0.5);
2975 Handle(Graphic3d_AspectFillArea3d) anAspect
2976 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2977 Quantity_NOC_RED,
2978 Quantity_NOC_YELLOW,
2979 Aspect_TOL_SOLID,
2980 1.0,
2981 aMat,
2982 aMat);
7fd59977 2983 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
161c4476
K
2984 if (toShowEdges)
2985 {
2986 anAspect->SetEdgeOn();
2987 }
7fd59977 2988 else
161c4476
K
2989 {
2990 anAspect->SetEdgeOff();
2991 }
2992 aShAsp->SetAspect (anAspect);
2993 aShape->Attributes()->SetShadingAspect (aShAsp);
7fd59977 2994
208e6839 2995 VDisplayAISObject (aShapeName, aShape);
7fd59977 2996 return 0;
2997}
2998
3fc57801 2999//=============================================================================
3000//function : VComputeHLR
3001//purpose :
3002//=============================================================================
3003
3004static int VComputeHLR (Draw_Interpretor& di,
3005 Standard_Integer argc,
3006 const char** argv)
3007{
3008 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3009
3010 if (aContextAIS.IsNull ())
3011 {
3012 di << "Please call vinit before\n";
3013 return 1;
3014 }
3015
3016 if ( argc != 3 && argc != 12 )
3017 {
3018 di << "Usage: " << argv[0] << " ShapeName HlrName "
3019 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3020 << " ShapeName - name of the initial shape\n"
3021 << " HlrName - result hlr object from initial shape\n"
3022 << " eye, dir are eye position and look direction\n"
3023 << " up is the look up direction vector\n"
3024 << " Use vtop to see projected hlr shape\n";
3025 return 1;
3026 }
3027
3028 // shape and new object name
3029 TCollection_AsciiString aShapeName (argv[1]);
3030 TCollection_AsciiString aHlrName (argv[2]);
3031
3032 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3033 if (aSh.IsNull())
3034 {
3035 BRep_Builder aBrepBuilder;
3036 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3037 if (aSh.IsNull ())
3038 {
3039 di << "No shape with name " << argv[1] << " found\n";
3040 return 1;
3041 }
3042 }
3043
3044 if (GetMapOfAIS ().IsBound2 (aHlrName))
3045 {
3046 di << "Presentable object with name " << argv[2] << " already exists\n";
3047 return 1;
3048 }
3049
3050 // close local context
3051 if (aContextAIS->HasOpenedContext ())
3052 aContextAIS->CloseLocalContext ();
3053
3054 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3055 HLRBRep_PolyHLRToShape aHLRToShape;
3056
3057 gp_Pnt anEye;
3058 gp_Dir aDir;
3059 gp_Ax2 aProjAx;
3060 if (argc == 9)
3061 {
3062 gp_Dir anUp;
3063
91322f44 3064 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3065 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3066 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3fc57801 3067 aProjAx.SetLocation (anEye);
3068 aProjAx.SetDirection (aDir);
3069 aProjAx.SetYDirection (anUp);
3070 }
3071 else
3072 {
3073 gp_Dir aRight;
3074
3075 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3076 Handle(V3d_View) aView = ViewerTest::CurrentView();
3077 Standard_Integer aWidth, aHeight;
3078 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3079 Standard_Real aRightX, aRightY, aRightZ;
3080 aView->Window()->Size (aWidth, aHeight);
3081
3082 aView->ConvertWithProj (aWidth, aHeight/2,
3083 aRightX, aRightY, aRightZ,
3084 aDirX, aDirY, aDirZ);
3085
3086 aView->ConvertWithProj (aWidth/2, aHeight/2,
3087 aCentX, aCentY, aCentZ,
3088 aDirX, aDirY, aDirZ);
3089
3090 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3091 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3092 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3093 aProjAx.SetLocation (anEye);
3094 aProjAx.SetDirection (aDir);
3095 aProjAx.SetXDirection (aRight);
3096 }
3097
3098 HLRAlgo_Projector aProjector (aProjAx);
3099 aPolyAlgo->Projector (aProjector);
3100 aPolyAlgo->Load (aSh);
3101 aPolyAlgo->Update ();
3102
3103 aHLRToShape.Update (aPolyAlgo);
3104
3105 // make hlr shape from input shape
3106 TopoDS_Compound aHlrShape;
3107 BRep_Builder aBuilder;
3108 aBuilder.MakeCompound (aHlrShape);
3109
3110 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3111 if (!aCompound.IsNull ())
3112 {
3113 aBuilder.Add (aHlrShape, aCompound);
3114 }
3115
3116 // extract visible outlines
3117 aCompound = aHLRToShape.OutLineVCompound();
3118 if (!aCompound.IsNull ())
3119 {
3120 aBuilder.Add (aHlrShape, aCompound);
3121 }
3122
3123 // create an AIS shape and display it
3124 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3125 GetMapOfAIS().Bind (anObject, aHlrName);
3126 aContextAIS->Display (anObject);
3127
3128 aContextAIS->UpdateCurrentViewer ();
3129
3130 return 0;
3131}
3132
9558a876
A
3133// This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3134// manipulating and displaying such an array with AIS context
c04c30b3 3135
9558a876
A
3136class MyPArrayObject : public AIS_InteractiveObject
3137{
3138
3139public:
3140
eb4320f2 3141 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
a577aaab 3142 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
9558a876 3143 {
eb4320f2 3144 myArrayDescription = theArrayDescription;
a577aaab 3145 myMarkerAspect = theMarkerAspect;
9558a876
A
3146 }
3147
ec357c5c 3148 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
9558a876
A
3149
3150private:
3151
3152 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3153 const Handle(Prs3d_Presentation)& aPresentation,
3154 const Standard_Integer aMode);
3155
a577aaab 3156 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3157 const Standard_Integer /*theMode*/);
9558a876 3158
eb4320f2 3159 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3160 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3161 Standard_Integer &theArgIndex,
3162 Standard_Integer theArgCount,
3163 Standard_Integer theMaxArgs);
3164
9558a876
A
3165protected:
3166
eb4320f2 3167 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
a577aaab 3168 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
9558a876
A
3169
3170};
3171
9558a876 3172
35e08fe8 3173void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
9558a876 3174 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 3175 const Standard_Integer /*aMode*/)
9558a876 3176{
9558a876 3177
eb4320f2 3178 // Parsing array description
9558a876 3179 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
871fa103 3180 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3181 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
9558a876 3182
eb4320f2 3183 Standard_Integer anArgIndex = 0;
3184 Standard_Integer anArgsCount = myArrayDescription->Length();
3185 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3186
9558a876 3187 TCollection_AsciiString aCommand;
eb4320f2 3188 while (anArgIndex < anArgsCount)
9558a876 3189 {
eb4320f2 3190 aCommand = myArrayDescription->Value (anArgIndex);
9558a876 3191 aCommand.LowerCase();
9558a876
A
3192
3193 // vertex command
eb4320f2 3194 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3195 {
3196 // vertex has a normal or normal with color or texel
eb4320f2 3197 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3198 hasNormals = Standard_True;
3199
3200 // vertex has a color
eb4320f2 3201 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3202 hasVColors = Standard_True;
3203
3204 // vertex has a texel
eb4320f2 3205 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
9558a876
A
3206 hasTexels = Standard_True;
3207
3208 aVertexNum++;
3209 }
3210 // bound command
eb4320f2 3211 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876
A
3212 {
3213 // bound has color
eb4320f2 3214 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3215 hasBColors = Standard_True;
3216
3217 aBoundNum++;
3218 }
3219 // edge command
eb4320f2 3220 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3221 {
9558a876
A
3222 aEdgeNum++;
3223 }
3224 // unknown command
3225 else
eb4320f2 3226 anArgIndex++;
9558a876
A
3227 }
3228
9558a876
A
3229 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3230 if (anArrayType == "points")
a577aaab 3231 {
9558a876 3232 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
a577aaab 3233 }
9558a876
A
3234 else if (anArrayType == "segments")
3235 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3236 else if (anArrayType == "polylines")
3237 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
871fa103 3238 hasVColors, hasBColors);
9558a876
A
3239 else if (anArrayType == "triangles")
3240 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
871fa103 3241 hasVColors, hasTexels);
9558a876
A
3242 else if (anArrayType == "trianglefans")
3243 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3244 hasNormals, hasVColors,
3245 hasBColors, hasTexels);
3246 else if (anArrayType == "trianglestrips")
3247 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3248 hasNormals, hasVColors,
3249 hasBColors, hasTexels);
3250 else if (anArrayType == "quads")
3251 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3252 hasNormals, hasVColors,
871fa103 3253 hasTexels);
9558a876
A
3254 else if (anArrayType == "quadstrips")
3255 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3256 hasNormals, hasVColors,
3257 hasBColors, hasTexels);
3258 else if (anArrayType == "polygons")
3259 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3260 hasNormals, hasVColors, hasBColors,
871fa103 3261 hasTexels);
9558a876 3262
eb4320f2 3263 anArgIndex = 1;
3264 while (anArgIndex < anArgsCount)
9558a876 3265 {
eb4320f2 3266 aCommand = myArrayDescription->Value (anArgIndex);
9558a876
A
3267 aCommand.LowerCase();
3268 if (!aCommand.IsAscii())
3269 break;
3270
3271 // vertex command
eb4320f2 3272 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3273 {
eb4320f2 3274 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3275 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3276 myArrayDescription->Value (anArgIndex - 1).RealValue());
871fa103 3277 const Standard_Integer aVertIndex = anArray->VertexNumber();
9558a876
A
3278
3279 // vertex has a normal or normal with color or texel
eb4320f2 3280 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3281 anArray->SetVertexNormal (aVertIndex,
eb4320f2 3282 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3283 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3284 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3285
eb4320f2 3286 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3287 anArray->SetVertexColor (aVertIndex,
eb4320f2 3288 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3289 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3290 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3291
eb4320f2 3292 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
871fa103 3293 anArray->SetVertexTexel (aVertIndex,
eb4320f2 3294 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3295 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3296 }
3297 // bounds command
eb4320f2 3298 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3299 {
eb4320f2 3300 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
9558a876 3301
eb4320f2 3302 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3303 anArray->AddBound (aVertCount,
eb4320f2 3304 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3305 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3306 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3307
3308 else
3309 anArray->AddBound (aVertCount);
3310 }
3311 // edge command
eb4320f2 3312 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3313 {
871fa103 3314 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3315 anArray->AddEdge (aVertIndex);
9558a876
A
3316 }
3317 // unknown command
3318 else
eb4320f2 3319 anArgIndex++;
3320 }
3321
3322 aPresentation->Clear();
3323 if (!myMarkerAspect.IsNull())
3324 {
3325 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3326 }
3327 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3328}
3329
3330void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3331 const Standard_Integer /*theMode*/)
3332{
3333 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3334
3335 Standard_Integer anArgIndex = 1;
3336 while (anArgIndex < myArrayDescription->Length())
3337 {
3338 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3339 {
3340 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3341 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3342 myArrayDescription->Value (anArgIndex - 1).RealValue());
3343 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3344 theSelection->Add (aSensetivePoint);
3345 }
3346 else
3347 {
3348 anArgIndex++;
3349 }
3350 }
3351}
3352
3353bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3354 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3355 Standard_Integer &theArgIndex,
3356 Standard_Integer theArgCount,
3357 Standard_Integer theMaxArgs)
3358{
3359 // check if there is more elements than expected
3360 if (theArgIndex >= theMaxArgs)
3361 return false;
3362
3363 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3364 aStrCommand.LowerCase();
3365 if (aStrCommand.Search(theCommand) != 1 ||
3366 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3367 return false;
3368
3369 // go to the first data element
3370 theArgIndex++;
3371
3372 // check data if it can be converted to numeric
3373 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3374 {
3375 aStrCommand = theArgsArray->Value (theArgIndex);
3376 if (!aStrCommand.IsRealValue())
3377 return false;
3378 }
3379
3380 return true;
3381}
3382
3383//=============================================================================
3384//function : VDrawPArray
3385//purpose : Draws primitives array from list of vertexes, bounds, edges
3386//=============================================================================
3387
3388static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3389{
3390 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3391 if (aContextAIS.IsNull())
3392 {
3393 di << "Call vinit before!\n";
3394 return 1;
3395 }
3396 else if (argc < 3)
3397 {
3398 di << "Use: " << argv[0] << " Name TypeOfArray"
3399 << " [vertex] ... [bounds] ... [edges]\n"
3400 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3401 << " trianglefans | trianglestrips | quads |\n"
3402 << " quadstrips | polygons }\n"
3403 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3404 << " [texel={ 't' tx ty }] } \n"
3405 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
871fa103 3406 << " edges={ 'e' vertex_id }\n";
eb4320f2 3407 return 1;
3408 }
3409
3410 // read the arguments
3411 Standard_Integer aArgIndex = 1;
3412 TCollection_AsciiString aName (argv[aArgIndex++]);
3413 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3414
3415 Standard_Boolean hasVertex = Standard_False;
3416
3417 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3418 anArgsArray->SetValue (0, anArrayType);
3419
3420 if (anArrayType != "points" &&
3421 anArrayType != "segments" &&
3422 anArrayType != "polylines" &&
3423 anArrayType != "triangles" &&
3424 anArrayType != "trianglefans" &&
3425 anArrayType != "trianglestrips" &&
3426 anArrayType != "quads" &&
3427 anArrayType != "quadstrips" &&
3428 anArrayType != "polygons")
3429 {
3430 di << "Unexpected type of primitives array\n";
3431 return 1;
3432 }
3433
3434 TCollection_AsciiString aCommand;
3435 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3436 {
3437 aCommand = argv[anArgIndex];
3438 aCommand.LowerCase();
3439 if (!aCommand.IsAscii())
3440 {
3441 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3442 << "should be an array element: 'v', 'b', 'e' \n";
3443 break;
3444 }
3445
3446 if (aCommand == "v")
3447 {
3448 hasVertex = Standard_True;
3449 }
3450
3451 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3452 }
3453
3454 if (!hasVertex)
3455 {
3456 di << "You should pass any verticies in the list of array elements\n";
3457 return 1;
3458 }
3459
3460 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3461 if (anArrayType == "points")
3462 {
3463 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
9558a876
A
3464 }
3465
9558a876 3466 // create primitives array object
eb4320f2 3467 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
9558a876
A
3468
3469 // register the object in map
3470 VDisplayAISObject (aName, aPObject);
3471
3472 return 0;
3473}
3474
29d43f9c
A
3475//=======================================================================
3476//function : VSetLocation
3477//purpose : Change location of AIS interactive object
3478//=======================================================================
3479
0bd2a43f 3480static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
4e18052b 3481 Standard_Integer theArgNb,
3482 const char** theArgVec)
29d43f9c
A
3483{
3484 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4e18052b 3485 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
29d43f9c
A
3486 if (aContext.IsNull())
3487 {
4e18052b 3488 std::cout << "Error: no active view!\n";
29d43f9c
A
3489 return 1;
3490 }
3491
4e18052b 3492 TCollection_AsciiString aName;
3493 gp_Vec aLocVec;
3494 Standard_Boolean isSetLoc = Standard_False;
3495
3496 Standard_Integer anArgIter = 1;
3497 for (; anArgIter < theArgNb; ++anArgIter)
29d43f9c 3498 {
4e18052b 3499 Standard_CString anArg = theArgVec[anArgIter];
3500 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3501 {
3502 continue;
3503 }
3504 else if (aName.IsEmpty())
3505 {
3506 aName = anArg;
3507 }
3508 else if (!isSetLoc)
3509 {
3510 isSetLoc = Standard_True;
3511 if (anArgIter + 1 >= theArgNb)
3512 {
3513 std::cout << "Error: syntax error at '" << anArg << "'\n";
3514 return 1;
3515 }
3516 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3517 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3518 if (anArgIter + 1 < theArgNb)
3519 {
3520 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3521 }
3522 }
3523 else
3524 {
3525 std::cout << "Error: unknown argument '" << anArg << "'\n";
3526 return 1;
3527 }
29d43f9c
A
3528 }
3529
29d43f9c 3530 // find object
4e18052b 3531 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29d43f9c 3532 Handle(AIS_InteractiveObject) anIObj;
4e18052b 3533 if (aMap.IsBound2 (aName))
29d43f9c 3534 {
4e18052b 3535 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
29d43f9c 3536 }
4e18052b 3537 if (anIObj.IsNull())
29d43f9c 3538 {
4e18052b 3539 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3540 return 1;
29d43f9c
A
3541 }
3542
4e18052b 3543 gp_Trsf aTrsf;
3544 aTrsf.SetTranslation (aLocVec);
3545 TopLoc_Location aLocation (aTrsf);
3546 aContext->SetLocation (anIObj, aLocation);
29d43f9c
A
3547 return 0;
3548}
3549
7d9e854b 3550//=======================================================================
3551//function : TransformPresentation
3552//purpose : Change transformation of AIS interactive object
3553//=======================================================================
3554static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3555 Standard_Integer theArgNb,
3556 const char** theArgVec)
3557{
3558 if (theArgNb <= 1)
3559 {
3560 std::cout << "Error: too few arguments.\n";
3561 return 1;
3562 }
3563
3564 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3565 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3566 if (aContext.IsNull())
3567 {
3568 std::cout << "Error: no active view!\n";
3569 return 1;
3570 }
3571
3572 gp_Trsf aTrsf;
3573 Standard_Integer aLast = theArgNb;
3574 const char* aName = theArgVec[0];
3575
3576 Standard_Boolean isReset = Standard_False;
3577 Standard_Boolean isMove = Standard_False;
3578
3579 // Prefix 'vloc'
3580 aName += 4;
3581
3582 if (!strcmp (aName, "reset"))
3583 {
3584 isReset = Standard_True;
3585 }
3586 else if (!strcmp (aName, "move"))
3587 {
3588 if (theArgNb < 3)
3589 {
3590 std::cout << "Error: too few arguments.\n";
3591 return 1;
3592 }
3593
3594 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3595
3596 Handle(AIS_InteractiveObject) anIObj;
3597 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3598 {
3599 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3600 }
3601
3602 if (anIObj.IsNull())
3603 {
3604 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3605 return 1;
3606 }
3607
3608 isMove = Standard_True;
3609
3610 aTrsf = anIObj->Transformation();
3611 aLast = theArgNb - 1;
3612 }
3613 else if (!strcmp (aName, "translate"))
3614 {
3615 if (theArgNb < 5)
3616 {
3617 std::cout << "Error: too few arguments.\n";
3618 return 1;
3619 }
3620 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3621 Draw::Atof (theArgVec[theArgNb - 2]),
3622 Draw::Atof (theArgVec[theArgNb - 1])));
3623 aLast = theArgNb - 3;
3624 }
3625 else if (!strcmp (aName, "rotate"))
3626 {
3627 if (theArgNb < 9)
3628 {
3629 std::cout << "Error: too few arguments.\n";
3630 return 1;
3631 }
3632
3633 aTrsf.SetRotation (
3634 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3635 Draw::Atof (theArgVec[theArgNb - 6]),
3636 Draw::Atof (theArgVec[theArgNb - 5])),
3637 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3638 Draw::Atof (theArgVec[theArgNb - 3]),
3639 Draw::Atof (theArgVec[theArgNb - 2]))),
3640 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3641
3642 aLast = theArgNb - 7;
3643 }
3644 else if (!strcmp (aName, "mirror"))
3645 {
3646 if (theArgNb < 8)
3647 {
3648 std::cout << "Error: too few arguments.\n";
3649 return 1;
3650 }
3651
3652 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3653 Draw::Atof(theArgVec[theArgNb - 5]),
3654 Draw::Atof(theArgVec[theArgNb - 4])),
3655 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3656 Draw::Atof(theArgVec[theArgNb - 2]),
3657 Draw::Atof(theArgVec[theArgNb - 1]))));
3658 aLast = theArgNb - 6;
3659 }
3660 else if (!strcmp (aName, "scale"))
3661 {
3662 if (theArgNb < 6)
3663 {
3664 std::cout << "Error: too few arguments.\n";
3665 return 1;
3666 }
3667
3668 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3669 Draw::Atof(theArgVec[theArgNb - 3]),
3670 Draw::Atof(theArgVec[theArgNb - 2])),
3671 Draw::Atof(theArgVec[theArgNb - 1]));
3672 aLast = theArgNb - 4;
3673 }
3674
3675 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3676 {
3677 // find object
3678 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3679 Handle(AIS_InteractiveObject) anIObj;
3680 if (aMap.IsBound2 (theArgVec[anIdx]))
3681 {
3682 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3683 }
3684 if (anIObj.IsNull())
3685 {
3686 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3687 return 1;
3688 }
3689
3690 if (isReset)
3691 {
3692 // aTrsf already identity
3693 }
3694 else if (isMove)
3695 {
3696 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3697 }
3698 else
3699 {
3700 aTrsf = anIObj->LocalTransformation() * aTrsf;
3701 }
3702
3703 TopLoc_Location aLocation (aTrsf);
3704 aContext->SetLocation (anIObj, aLocation);
3705 }
3706
3707 return 0;
3708}
3709
ac04d101
SA
3710//===============================================================================================
3711//function : VConnect
3712//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
0717ddc1 3713//Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
ac04d101
SA
3714//===============================================================================================
3715
0717ddc1 3716static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3717 Standard_Integer argc,
3718 const char ** argv)
ac04d101 3719{
792c785c 3720 // Check the viewer
3721 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3722 if (aContext.IsNull())
ac04d101 3723 {
792c785c 3724 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3725 return 1; // TCL_ERROR
3726 }
792c785c 3727 // Check argumnets
0717ddc1 3728 if (argc < 6)
ac04d101 3729 {
0717ddc1 3730 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3731 return 1; // TCL_ERROR
3732 }
792c785c 3733
3734 // Get values
3735 Standard_Integer anArgIter = 1;
3736 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3737 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
792c785c 3738 TCollection_AsciiString aColorString (argv[argc-1]);
1d47d8d0 3739 Standard_CString aColorName = "";
792c785c 3740 Standard_Boolean hasColor = Standard_False;
3741 if (aColorString.Search ("color=") != -1)
ac04d101 3742 {
792c785c 3743 hasColor = Standard_True;
3744 aColorString.Remove (1, 6);
3745 aColorName = aColorString.ToCString();
3746 }
3747 Handle(AIS_InteractiveObject) anObject;
3748
0717ddc1 3749 // AIS_MultipleConnectedInteractive
3750 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3751 for (Standard_Integer i = 5; i < aNbShapes; ++i)
792c785c 3752 {
0717ddc1 3753 TCollection_AsciiString anOriginObjectName (argv[i]);
792c785c 3754 if (aName.IsEqual (anOriginObjectName))
ac04d101 3755 {
0717ddc1 3756 std::cout << "vconnect error: equal names for connected objects\n";
3757 continue;
ac04d101 3758 }
792c785c 3759 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3760 {
3761 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
0717ddc1 3762 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3763 if (anObject.IsNull())
792c785c 3764 {
3765 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
0717ddc1 3766 continue;
792c785c 3767 }
3768 }
3769 else
3770 {
3771 Standard_CString aName = anOriginObjectName.ToCString();
3772 TopoDS_Shape aTDShape = DBRep::Get (aName);
3773 if (aTDShape.IsNull())
3774 {
3775 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
792c785c 3776 continue;
3777 }
0717ddc1 3778 anObject = new AIS_Shape (aTDShape);
6262338c 3779 aContext->Load (anObject);
0717ddc1 3780 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
792c785c 3781 }
0717ddc1 3782
792c785c 3783 if (anOriginObject.IsNull())
3784 {
0717ddc1 3785 anOriginObject = new AIS_MultipleConnectedInteractive();
792c785c 3786 }
0717ddc1 3787
3788 anOriginObject->Connect (anObject);
3789 }
3790 if (anOriginObject.IsNull())
3791 {
3792 std::cout << "vconect error : can't connect input objects\n";
3793 return 1; // TCL_ERROR
792c785c 3794 }
3795
ac04d101 3796 // Get location data
91322f44 3797 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3798 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3799 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3800
3801 // Create transformation
0717ddc1 3802 gp_Vec aTranslation (aXo, aYo, aZo);
3803
ac04d101 3804 gp_Trsf aTrsf;
0717ddc1 3805 aTrsf.SetTranslationPart (aTranslation);
3806 TopLoc_Location aLocation (aTrsf);
ac04d101 3807
0717ddc1 3808 anOriginObject->SetLocalTransformation (aTrsf);
ac04d101
SA
3809
3810 // Check if there is another object with given name
3811 // and remove it from context
3812 if(GetMapOfAIS().IsBound2(aName))
3813 {
3814 Handle(AIS_InteractiveObject) anObj =
3815 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3816 TheAISContext()->Remove(anObj, Standard_False);
3817 GetMapOfAIS().UnBind2(aName);
3818 }
3819
792c785c 3820 // Bind connected object to its name
0717ddc1 3821 GetMapOfAIS().Bind (anOriginObject, aName);
ac04d101
SA
3822
3823 // Display connected object
0717ddc1 3824 TheAISContext()->Display (anOriginObject);
ac04d101
SA
3825
3826 return 0;
3827}
3828
3829//===============================================================================================
0717ddc1 3830//function : VConnectTo
3831//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
d4aaad5b 3832//Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
ac04d101
SA
3833//===============================================================================================
3834
0717ddc1 3835static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3836 Standard_Integer argc,
3837 const char ** argv)
ac04d101 3838{
792c785c 3839 // Check the viewer
3840 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
d4aaad5b 3841 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
792c785c 3842 if (aContext.IsNull())
ac04d101 3843 {
0717ddc1 3844 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3845 return 1; // TCL_ERROR
3846 }
0717ddc1 3847 // Check argumnets
f751596e 3848 if (argc != 6 && argc != 7)
ac04d101 3849 {
0717ddc1 3850 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3851 return 1; // TCL_ERROR
3852 }
792c785c 3853
3854 // Get values
3855 Standard_Integer anArgIter = 1;
3856 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3857 Handle(AIS_InteractiveObject) anOriginObject;
3858
3859 TCollection_AsciiString anOriginObjectName(argv[5]);
3860 if (aName.IsEqual (anOriginObjectName))
792c785c 3861 {
0717ddc1 3862 std::cout << "vconnect error: equal names for connected objects\n";
3863 return 1; // TCL_ERROR
792c785c 3864 }
0717ddc1 3865 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
ac04d101 3866 {
0717ddc1 3867 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3868 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3869 if (anOriginObject.IsNull())
ac04d101 3870 {
0717ddc1 3871 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
792c785c 3872 return 1; // TCL_ERROR
3873 }
792c785c 3874 }
792c785c 3875 else
3876 {
0717ddc1 3877 Standard_CString aName = anOriginObjectName.ToCString();
3878 TopoDS_Shape aTDShape = DBRep::Get (aName);
3879 if (aTDShape.IsNull())
792c785c 3880 {
0717ddc1 3881 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
ac04d101
SA
3882 return 1; // TCL_ERROR
3883 }
0717ddc1 3884 anOriginObject = new AIS_Shape (aTDShape);
f751596e 3885 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
ac04d101 3886 }
0717ddc1 3887
3888 // Get location data
91322f44 3889 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3890 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3891 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3892
3893 // Create transformation
0717ddc1 3894 gp_Vec aTranslation (aXo, aYo, aZo);
ac04d101 3895
0717ddc1 3896 gp_Trsf aTrsf;
3897 aTrsf.SetTranslationPart (aTranslation);
3898
792c785c 3899 Handle(AIS_ConnectedInteractive) aConnected;
0717ddc1 3900
3901 aConnected = new AIS_ConnectedInteractive();
3902
3903 aConnected->Connect (anOriginObject, aTrsf);
ac04d101
SA
3904
3905 // Check if there is another object with given name
3906 // and remove it from context
3907 if(GetMapOfAIS().IsBound2(aName))
3908 {
3909 Handle(AIS_InteractiveObject) anObj =
3910 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3911 TheAISContext()->Remove(anObj, Standard_False);
3912 GetMapOfAIS().UnBind2(aName);
3913 }
3914
0717ddc1 3915 // Bind connected object to its name
792c785c 3916 GetMapOfAIS().Bind (aConnected, aName);
ac04d101 3917
f751596e 3918 if (argc == 7)
3919 {
3920 TCollection_AsciiString anArg = argv[6];
3921 anArg.LowerCase();
3922 if (anArg == "-nodisplay")
3923 return 0;
d4aaad5b 3924
3925 if (!anUpdateTool.parseRedrawMode (anArg))
3926 {
3927 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
3928 }
f751596e 3929 }
3930
0717ddc1 3931 // Display connected object
d4aaad5b 3932 TheAISContext()->Display (aConnected, Standard_False);
ac04d101
SA
3933
3934 return 0;
3935}
3936
0717ddc1 3937//=======================================================================
3938//function : VDisconnect
3939//purpose :
3940//=======================================================================
3941static Standard_Integer VDisconnect (Draw_Interpretor& di,
3942 Standard_Integer argc,
3943 const char ** argv)
3944{
3945 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3946 if (aContext.IsNull())
3947 {
3948 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3949 return 1;
3950 }
3951
3952 if (argc != 3)
3953 {
3954 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
3955 return 1;
3956 }
3957
3958 TCollection_AsciiString aName (argv[1]);
3959 TCollection_AsciiString anObject (argv[2]);
3960 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
3961
3962 // find objects
3963 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3964 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3965 if (!aMap.IsBound2 (aName) )
3966 {
3967 std::cout << "Use 'vdisplay' before" << "\n";
3968 return 1;
3969 }
3970
3971 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3972 if (anAssembly.IsNull())
3973 {
3974 di << "Not an assembly" << "\n";
3975 return 1;
3976 }
3977
3978 Handle(AIS_InteractiveObject) anIObj;
3979 if (!aMap.IsBound2 (anObject))
3980 {
3981 // try to interpret second argument as child number
3982 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
3983 {
3984 Standard_Integer aCounter = 1;
3985 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3986 {
3987 if (aCounter == anObjectNumber)
3988 {
3989 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
3990 break;
3991 }
3992 ++aCounter;
3993 }
3994 }
3995 else
3996 {
3997 std::cout << "Use 'vdisplay' before" << "\n";
3998 return 1;
3999 }
4000 }
4001
4002 // if object was found by name
4003 if (anIObj.IsNull())
4004 {
4005 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4006 }
4007
f751596e 4008 aContext->Disconnect (anAssembly, anIObj);
0717ddc1 4009 aContext->UpdateCurrentViewer();
4010
4011 return 0;
4012}
4013
4014//=======================================================================
4015//function : VAddConnected
4016//purpose :
4017//=======================================================================
4018static Standard_Integer VAddConnected (Draw_Interpretor& di,
4019 Standard_Integer argc,
4020 const char ** argv)
4021{
4022 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4023 if (aContext.IsNull())
4024 {
4025 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4026 return 1;
4027 }
4028
4029 if (argc != 6)
4030 {
4031 std::cout << argv[0] << " error: expect 5 arguments\n";
4032 return 1;
4033 }
4034
4035 TCollection_AsciiString aName (argv[1]);
4036 TCollection_AsciiString anObject (argv[5]);
4037 Standard_Real aX = Draw::Atof (argv[2]);
4038 Standard_Real aY = Draw::Atof (argv[3]);
4039 Standard_Real aZ = Draw::Atof (argv[4]);
4040
4041 // find object
4042 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4043 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4044 if (!aMap.IsBound2 (aName) )
4045 {
4046 std::cout << "Use 'vdisplay' before" << "\n";
4047 return 1;
4048 }
4049
4050 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4051 if (anAssembly.IsNull())
4052 {
4053 di << "Not an assembly" << "\n";
4054 return 1;
4055 }
4056
4057 Handle(AIS_InteractiveObject) anIObj;
4058 if (!aMap.IsBound2 (anObject))
4059 {
4060 std::cout << "Use 'vdisplay' before" << "\n";
4061 return 1;
4062 }
4063
4064 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4065
4066 gp_Trsf aTrsf;
4067 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4068
4069 anAssembly->Connect (anIObj, aTrsf);
4070 TheAISContext()->Display (anAssembly);
4071 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4072 aContext->UpdateCurrentViewer();
4073
4074 return 0;
4075}
4076
4077//=======================================================================
4078//function : VListConnected
4079//purpose :
4080//=======================================================================
0bd2a43f 4081static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
0717ddc1 4082 Standard_Integer argc,
4083 const char ** argv)
4084{
4085 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4086 if (aContext.IsNull())
4087 {
4088 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4089 return 1;
4090 }
4091
4092 if (argc != 2)
4093 {
4094 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
4095 return 1;
4096 }
4097
4098 TCollection_AsciiString aName (argv[1]);
4099
4100 // find object
4101 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4102 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4103 if (!aMap.IsBound2 (aName) )
4104 {
4105 std::cout << "Use 'vdisplay' before" << "\n";
4106 return 1;
4107 }
4108
4109 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4110 if (anAssembly.IsNull())
4111 {
4112 std::cout << "Not an assembly" << "\n";
4113 return 1;
4114 }
4115
4116 std::cout << "Children of " << aName << ":\n";
4117
4118 Standard_Integer aCounter = 1;
4119 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4120 {
4121 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4122 {
4123 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
4124 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4125 }
4126
4127 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4128
4129 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4130 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4131 {
4132 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4133 }
4134 std::cout << std::endl;
4135
4136 ++aCounter;
4137 }
4138
4139 return 0;
4140}
4141
9f37b47d 4142namespace
4143{
4144 //! Checks if theMode is already turned on for theObj.
4145 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4146 const Handle(AIS_InteractiveObject)& theObj,
4147 const Standard_Integer theMode)
4148 {
4149 TColStd_ListOfInteger anActiveModes;
4150 theAISContext->ActivatedModes (theObj, anActiveModes);
4151 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4152 {
4153 if (aModeIt.Value() == theMode)
4154 {
4155 return Standard_True;
4156 }
4157 }
4158 return Standard_False;
4159 }
4160};
4161
ac04d101
SA
4162//===============================================================================================
4163//function : VSetSelectionMode
4164//purpose : Sets input selection mode for input object or for all displayed objects
4165//Draw arg : vselmode [object] mode On/Off (1/0)
4166//===============================================================================================
9f37b47d 4167static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4168 Standard_Integer theArgc,
4169 const char** theArgv)
ac04d101
SA
4170{
4171 // Check errors
4172 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
9f37b47d 4173 if (anAISContext.IsNull())
ac04d101 4174 {
709e97a0 4175 std::cerr << "Call vinit before!" << std::endl;
9f37b47d 4176 return 1;
ac04d101
SA
4177 }
4178
9f37b47d 4179 // Check the arguments
c3282ec1 4180 if (theArgc < 3 && theArgc > 5)
ac04d101 4181 {
9f37b47d 4182 std::cerr << "vselmode error : expects at least 2 arguments.\n"
709e97a0 4183 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
9f37b47d 4184 return 1;
ac04d101
SA
4185 }
4186
c3282ec1 4187 TCollection_AsciiString aLastArg (theArgv[theArgc - 1]);
4188 aLastArg.LowerCase();
4189 Standard_Boolean isToOpenLocalCtx = aLastArg == "-local";
4190
9f37b47d 4191 // get objects to change selection mode
4192 AIS_ListOfInteractive aTargetIOs;
c3282ec1 4193 Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc;
4194 if (anArgNb == 3)
ac04d101 4195 {
9f37b47d 4196 anAISContext->DisplayedObjects (aTargetIOs);
4197 }
4198 else
4199 {
4200 // Check if there is an object with given name in context
4201 const TCollection_AsciiString aNameIO (theArgv[1]);
4202 if (GetMapOfAIS().IsBound2 (aNameIO))
ac04d101 4203 {
9f37b47d 4204 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4205 if (anIO.IsNull())
ac04d101 4206 {
709e97a0 4207 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
9f37b47d 4208 return 1;
ac04d101 4209 }
9f37b47d 4210 aTargetIOs.Append (anIO);
ac04d101 4211 }
9f37b47d 4212 }
ac04d101 4213
c3282ec1 4214 const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]);
4215 const Standard_Boolean toTurnOn = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]);
9f37b47d 4216 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4217 {
4218 anAISContext->CloseLocalContext();
ac04d101
SA
4219 }
4220
709e97a0 4221 if (aSelectionMode == 0)
4222 {
4223 if (toTurnOn)
4224 {
4225 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4226 {
4227 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
c3282ec1 4228 TColStd_ListOfInteger anActiveModes;
4229 anAISContext->ActivatedModes (anIO, anActiveModes);
4230 if (!anActiveModes.IsEmpty())
4231 {
4232 anAISContext->Deactivate (anIO);
4233 }
709e97a0 4234 if (!InList (anAISContext, anIO, aSelectionMode))
4235 {
4236 anAISContext->Activate (anIO);
4237 }
4238 }
4239 }
4240 else
4241 {
4242 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4243 {
4244 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4245 if (InList (anAISContext, anIO, aSelectionMode))
4246 {
4247 anAISContext->Deactivate (anIO);
4248 }
4249 }
4250 }
4251 }
4252
9f37b47d 4253 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
ac04d101 4254 {
c3282ec1 4255 if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx)
9f37b47d 4256 {
4257 anAISContext->OpenLocalContext (Standard_False);
4258 }
ac04d101 4259
9f37b47d 4260 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4261 {
9f37b47d 4262 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
c3282ec1 4263 if (InList (anAISContext, anIO, 0))
4264 {
4265 anAISContext->Deactivate (anIO, 0);
4266 }
9f37b47d 4267 if (!InList (anAISContext, anIO, aSelectionMode))
ac04d101 4268 {
9f37b47d 4269 anAISContext->Load (anIO, -1, Standard_True);
4270 anAISContext->Activate (anIO, aSelectionMode);
ac04d101
SA
4271 }
4272 }
9f37b47d 4273 }
ac04d101 4274
9f37b47d 4275 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4276 {
9f37b47d 4277 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4278 {
9f37b47d 4279 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4280 if (InList (anAISContext, anIO, aSelectionMode))
ac04d101 4281 {
9f37b47d 4282 anAISContext->Deactivate (anIO, aSelectionMode);
ac04d101
SA
4283 }
4284 }
4285 }
9f37b47d 4286
ac04d101
SA
4287 return 0;
4288}
4289
4ca4bbe8 4290//===============================================================================================
4291//function : VSelectionNext
4292//purpose :
4293//===============================================================================================
4294static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4295 Standard_Integer /*theArgsNb*/,
4296 const char** /*theArgVec*/)
4297{
4298 // Check errors
4299 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4300 Handle(V3d_View) aView = ViewerTest::CurrentView();
4301
4302 if (anAISContext.IsNull())
4303 {
4304 std::cerr << "Call vinit before!" << std::endl;
4305 return 1;
4306 }
4307
4308 anAISContext->HilightNextDetected(aView);
4309 return 0;
4310}
4311
4312//===============================================================================================
4313//function : VSelectionPrevious
4314//purpose :
4315//===============================================================================================
4316static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4317 Standard_Integer /*theArgsNb*/,
4318 const char** /*theArgVec*/)
4319{
4320 // Check errors
4321 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4322 Handle(V3d_View) aView = ViewerTest::CurrentView();
4323
4324 if (anAISContext.IsNull())
4325 {
4326 std::cerr << "Call vinit before!" << std::endl;
4327 return 1;
4328 }
4329
4330 anAISContext->HilightPreviousDetected(aView);
4331 return 0;
4332}
4333
4334
ceae62f0
A
4335//==========================================================================
4336//class : Triangle
4337//purpose : creates Triangle based on AIS_InteractiveObject.
4338// This class was implemented for testing Select3D_SensitiveTriangle
4339//===========================================================================
c04c30b3 4340
ceae62f0
A
4341class Triangle: public AIS_InteractiveObject
4342{
4343public:
4344 // CASCADE RTTI
ec357c5c 4345 DEFINE_STANDARD_RTTI(Triangle, AIS_InteractiveObject);
ceae62f0
A
4346 Triangle (const gp_Pnt& theP1,
4347 const gp_Pnt& theP2,
4348 const gp_Pnt& theP3);
4349protected:
4350 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4351 const Handle(Prs3d_Presentation)& thePresentation,
4352 const Standard_Integer theMode);
4353
4354 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4355 const Standard_Integer theMode);
4356private:
4357 gp_Pnt myPoint1;
4358 gp_Pnt myPoint2;
4359 gp_Pnt myPoint3;
4360};
ec357c5c 4361
ceae62f0
A
4362
4363Triangle::Triangle (const gp_Pnt& theP1,
4364 const gp_Pnt& theP2,
4365 const gp_Pnt& theP3)
4366{
4367 myPoint1 = theP1;
4368 myPoint2 = theP2;
4369 myPoint3 = theP3;
4370}
4371
35e08fe8 4372void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
ceae62f0 4373 const Handle(Prs3d_Presentation)& thePresentation,
35e08fe8 4374 const Standard_Integer /*theMode*/)
ceae62f0
A
4375{
4376 thePresentation->Clear();
4377
4378 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4379 anEdgeMaker2(myPoint2, myPoint3),
4380 anEdgeMaker3(myPoint3, myPoint1);
4381
4382 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4383 anEdge2 = anEdgeMaker2.Edge(),
4384 anEdge3 = anEdgeMaker3.Edge();
4385 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4386 return;
4387
4388 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4389 TopoDS_Wire aWire = aWireMaker.Wire();
4390 if(aWire.IsNull()) return;
4391
4392 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4393 TopoDS_Face aFace = aFaceMaker.Face();
4394 if(aFace.IsNull()) return;
4395
4396 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4397}
4398
4399void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
35e08fe8 4400 const Standard_Integer /*theMode*/)
ceae62f0
A
4401{
4402 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4403 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4404 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4405 theSelection->Add(aSensTriangle);
4406}
4407
4408//===========================================================================
4409//function : VTriangle
4410//Draw arg : vtriangle Name PointName PointName PointName
4411//purpose : creates and displays Triangle
4412//===========================================================================
4413
4414//function: IsPoint
4415//purpose : checks if the object with theName is AIS_Point,
4416// if yes initialize thePoint from MapOfAIS
4417Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4418 Handle(AIS_Point)& thePoint)
4419{
4420 Handle(AIS_InteractiveObject) anObject =
4421 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4422 if(anObject.IsNull() ||
4423 anObject->Type() != AIS_KOI_Datum ||
4424 anObject->Signature() != 1)
4425 {
4426 return Standard_False;
4427 }
4428 thePoint = Handle(AIS_Point)::DownCast(anObject);
4429 if(thePoint.IsNull())
4430 return Standard_False;
4431 return Standard_True;
4432}
4433
4434//function: IsMatch
4435//purpose: checks if thePoint1 is equal to thePoint2
4436Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4437 const Handle(Geom_CartesianPoint)& thePoint2)
4438{
91322f44 4439 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4440 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4441 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
ceae62f0
A
4442 {
4443 return Standard_True;
4444 }
4445 return Standard_False;
4446}
4447
35e08fe8 4448static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
ceae62f0
A
4449 Standard_Integer argc,
4450 const char ** argv)
4451{
4452 // Check arguments
4453 if (argc != 5)
4454 {
4455 std::cout<<"vtriangle error: expects 4 argumnets\n";
4456 return 1; // TCL_ERROR
4457 }
4458
4459 TheAISContext()->CloseAllContexts();
4460
4461 // Get and check values
4462 TCollection_AsciiString aName(argv[1]);
4463
4464 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4465 if (!IsPoint(argv[2], aPoint1))
4466 {
4467 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4468 return 1; // TCL_ERROR
4469 }
4470 if (!IsPoint(argv[3], aPoint2))
4471 {
4472 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4473 return 1; // TCL_ERROR
4474 }
4475 if (!IsPoint(argv[4], aPoint3))
4476 {
4477 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4478 return 1; // TCL_ERROR
4479 }
4480
4481 // Check that points are different
4482 Handle(Geom_CartesianPoint) aCartPoint1 =
4483 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4484 Handle(Geom_CartesianPoint) aCartPoint2 =
4485 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4486 // Test aPoint1 = aPoint2
4487 if (IsMatch(aCartPoint1, aCartPoint2))
4488 {
4489 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4490 return 1; // TCL_ERROR
4491 }
4492 // Test aPoint2 = aPoint3
4493 Handle(Geom_CartesianPoint) aCartPoint3 =
4494 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4495 if (IsMatch(aCartPoint2, aCartPoint3))
4496 {
4497 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4498 return 1; // TCL_ERROR
4499 }
4500 // Test aPoint3 = aPoint1
4501 if (IsMatch(aCartPoint1, aCartPoint3))
4502 {
4503 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4504 return 1; // TCL_ERROR
4505 }
4506
4507 // Create triangle
4508 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4509 aCartPoint2->Pnt(),
4510 aCartPoint3->Pnt());
4511
4512 // Check if there is an object with given name
4513 // and remove it from context
4514 if (GetMapOfAIS().IsBound2(aName))
4515 {
4516 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4517 Handle(AIS_InteractiveObject) anInterObj =
4518 Handle(AIS_InteractiveObject)::DownCast(anObj);
4519 TheAISContext()->Remove(anInterObj, Standard_False);
4520 GetMapOfAIS().UnBind2(aName);
4521 }
4522
4523 // Bind triangle to its name
4524 GetMapOfAIS().Bind(aTriangle, aName);
4525
4526 // Display triangle
4527 TheAISContext()->Display(aTriangle);
4528 return 0;
4529}
4530
4531//class : SegmentObject
4532//purpose: creates segment based on AIS_InteractiveObject.
4533// This class was implemented for testing Select3D_SensitiveCurve
c04c30b3 4534
ceae62f0
A
4535class SegmentObject: public AIS_InteractiveObject
4536{
4537public:
4538 // CASCADE RTTI
ec357c5c 4539 DEFINE_STANDARD_RTTI(SegmentObject, AIS_InteractiveObject);
ceae62f0
A
4540 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4541protected:
4542 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4543 const Handle(Prs3d_Presentation)& thePresentation,
4544 const Standard_Integer theMode);
4545
4546 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4547 const Standard_Integer theMode);
4548private:
4549 gp_Pnt myPoint1;
4550 gp_Pnt myPoint2;
4551};
ec357c5c 4552
ceae62f0
A
4553
4554SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4555{
4556 myPoint1 = thePnt1;
4557 myPoint2 = thePnt2;
4558}
4559
857ffd5e 4560void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4561 const Handle(Prs3d_Presentation) &thePresentation,
35e08fe8 4562 const Standard_Integer /*theMode*/)
ceae62f0
A
4563{
4564 thePresentation->Clear();
4565 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4566 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4567 if (anEdge.IsNull())
4568 return;
4569 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4570 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4571}
4572
857ffd5e 4573void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 4574 const Standard_Integer /*theMode*/)
ceae62f0
A
4575{
4576 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4577 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4578 anArray->SetValue(1, myPoint1);
4579 anArray->SetValue(2, myPoint2);
4580 Handle(Select3D_SensitiveCurve) aSensCurve =
4581 new Select3D_SensitiveCurve(anOwner, anArray);
4582 theSelection->Add(aSensCurve);
4583}
4584
4585//=======================================================================
4586//function : VSegment
4587//Draw args : vsegment Name PointName PointName
4588//purpose : creates and displays Segment
4589//=======================================================================
35e08fe8 4590static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
ceae62f0
A
4591 Standard_Integer argc,
4592 const char ** argv)
4593{
4594 // Check arguments
4595 if(argc!=4)
4596 {
4597 std::cout<<"vsegment error: expects 3 arguments\n";
4598 return 1; // TCL_ERROR
4599 }
4600
4601 TheAISContext()->CloseAllContexts();
4602
4603 // Get and check arguments
4604 TCollection_AsciiString aName(argv[1]);
4605 Handle(AIS_Point) aPoint1, aPoint2;
4606 if (!IsPoint(argv[2], aPoint1))
4607 {
4608 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4609 return 1; // TCL_ERROR
4610 }
4611 if (!IsPoint(argv[3], aPoint2))
4612 {
4613 std::cout<<"vsegment error: the 3d argument should be a point\n";
4614 return 1; // TCL_ERROR
4615 }
4616 //Check that points are different
4617 Handle(Geom_CartesianPoint) aCartPoint1 =
4618 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4619 Handle(Geom_CartesianPoint) aCartPoint2 =
4620 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4621 if(IsMatch(aCartPoint1, aCartPoint2))
4622 {
4623 std::cout<<"vsegment error: equal points\n";
4624 return 1; // TCL_ERROR
4625 }
4626
4627 // Create segment
4628 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4629 // Check if there is an object with given name
4630 // and remove it from context
4631 if (GetMapOfAIS().IsBound2(aName))
4632 {
4633 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4634 Handle(AIS_InteractiveObject) anInterObj =
4635 Handle(AIS_InteractiveObject)::DownCast(anObj);
4636 TheAISContext()->Remove(anInterObj, Standard_False);
4637 GetMapOfAIS().UnBind2(aName);
4638 }
4639
4640 // Bind segment to its name
4641 GetMapOfAIS().Bind(aSegment, aName);
4642
4643 // Display segment
4644 TheAISContext()->Display(aSegment);
4645 return 0;
4646}
4647
59f45b7c 4648//=======================================================================
4649//function : VObjZLayer
4650//purpose : Set or get z layer id for presentable object
4651//=======================================================================
4652
4653static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4654 Standard_Integer argc,
4655 const char ** argv)
4656{
4657 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4658 if (aContext.IsNull())
4659 {
4660 di << argv[0] << "Call 'vinit' before!\n";
4661 return 1;
4662 }
4663
4664 // get operation
4665 TCollection_AsciiString aOperation;
4666 if (argc >= 2)
4667 aOperation = TCollection_AsciiString (argv [1]);
4668
4669 // check for correct arguments
4670 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4671 !(argc == 3 && aOperation.IsEqual ("get")))
4672 {
4673 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4674 di << " set - set layer id for interactive object, layerid - z layer id\n";
4675 di << " get - get layer id of interactive object\n";
4676 di << " argument layerid should be passed for set operation only\n";
4677 return 1;
4678 }
4679
4680 // find object
4681 TCollection_AsciiString aName (argv[2]);
4682 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4683 if (!aMap.IsBound2 (aName))
4684 {
4685 di << "Use 'vdisplay' before" << "\n";
4686 return 1;
4687 }
4688
4689 // find interactive object
4690 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4691 Handle(AIS_InteractiveObject) anInterObj =
4692 Handle(AIS_InteractiveObject)::DownCast (anObj);
4693 if (anInterObj.IsNull())
4694 {
4695 di << "Not an AIS interactive object!\n";
4696 return 1;
4697 }
4698
4699 // process operation
4700 if (aOperation.IsEqual ("set"))
4701 {
91322f44 4702 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
59f45b7c 4703 aContext->SetZLayer (anInterObj, aLayerId);
4704 }
4705 else if (aOperation.IsEqual ("get"))
4706 {
4707 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4708 }
4709
4710 return 0;
4711}
4712
3ddebf91 4713//=======================================================================
4714//function : VPolygonOffset
4715//purpose : Set or get polygon offset parameters
4716//=======================================================================
35e08fe8 4717static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
3ddebf91 4718 Standard_Integer argc,
4719 const char ** argv)
4720{
4721 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4722 if (aContext.IsNull())
4723 {
4724 std::cout << argv[0] << " Call 'vinit' before!\n";
4725 return 1;
4726 }
4727
4728 if (argc > 2 && argc != 5)
4729 {
4730 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4731 "without arguments prints the default values" << std::endl;
4732 return 1;
4733 }
4734
4735 // find object
4736 Handle(AIS_InteractiveObject) anInterObj;
4737 if (argc >= 2)
4738 {
4739 TCollection_AsciiString aName (argv[1]);
4740 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4741 if (!aMap.IsBound2 (aName))
4742 {
4743 std::cout << "Use 'vdisplay' before" << std::endl;
4744 return 1;
4745 }
4746
4747 // find interactive object
4748 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4749 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4750 if (anInterObj.IsNull())
4751 {
4752 std::cout << "Not an AIS interactive object!" << std::endl;
4753 return 1;
4754 }
4755 }
4756
4757 Standard_Integer aMode;
60be1f9b 4758 Standard_ShortReal aFactor, aUnits;
3ddebf91 4759 if (argc == 5)
4760 {
91322f44 4761 aMode = Draw::Atoi(argv[2]);
4762 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4763 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
3ddebf91 4764
4765 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4766 aContext->UpdateCurrentViewer();
4767 return 0;
4768 }
4769 else if (argc == 2)
4770 {
4771 if (anInterObj->HasPolygonOffsets())
4772 {
4773 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4774 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4775 std::cout << "\tMode: " << aMode << std::endl;
4776 std::cout << "\tFactor: " << aFactor << std::endl;
4777 std::cout << "\tUnits: " << aUnits << std::endl;
4778 return 0;
4779 }
4780 else
4781 {
4782 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4783 }
4784 }
4785
4786 std::cout << "Default polygon offset parameters:" << std::endl;
4787 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4788 std::cout << "\tMode: " << aMode << std::endl;
4789 std::cout << "\tFactor: " << aFactor << std::endl;
4790 std::cout << "\tUnits: " << aUnits << std::endl;
4791
4792 return 0;
4793}
4794
a2d5ab2e 4795//=======================================================================
4796//function : VShowFaceBoundaries
4797//purpose : Set face boundaries drawing on/off for ais object
4798//=======================================================================
35e08fe8 4799static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
a2d5ab2e 4800 Standard_Integer argc,
4801 const char ** argv)
4802{
4803 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4804 if (aContext.IsNull ())
4805 {
4806 std::cout << argv[0] << " Call 'vinit' before!\n";
4807 return 1;
4808 }
4809
4810 if ((argc != 3 && argc < 6) || argc > 8)
4811 {
4812 std::cout << "Usage :\n " << argv[0]
4813 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4814 << " ObjectName - name of AIS interactive object. \n"
4815 << " if ObjectName = \"\", then set as default\n"
4816 << " settings for all newly displayed objects\n"
4817 << " isOn - flag indicating whether the boundaries\n"
4818 << " should be turned on or off (can be set\n"
4819 << " to 0 (off) or 1 (on)).\n"
4820 << " R, G, B - red, green and blue components of boundary\n"
4821 << " color in range (0 - 255).\n"
4822 << " (default is (0, 0, 0)\n"
4823 << " LineWidth - line width\n"
4824 << " (default is 1)\n"
4825 << " LineStyle - line fill style :\n"
4826 << " 0 - solid \n"
4827 << " 1 - dashed \n"
4828 << " 2 - dot \n"
4829 << " 3 - dashdot\n"
4830 << " (default is solid)";
4831 return 1;
4832 }
4833
4834 TCollection_AsciiString aName (argv[1]);
4835
4836 Quantity_Parameter aRed = 0.0;
4837 Quantity_Parameter aGreen = 0.0;
4838 Quantity_Parameter aBlue = 0.0;
4839 Standard_Real aWidth = 1.0;
4840 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4841
4842 // find object
4843 Handle(AIS_InteractiveObject) anInterObj;
4844
4845 // if name is empty - apply attributes for default aspect
4846 if (!aName.IsEmpty ())
4847 {
4848 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4849 if (!aMap.IsBound2 (aName))
4850 {
4851 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4852 return 1;
4853 }
4854
4855 // find interactive object
4856 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4857 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4858 if (anInterObj.IsNull ())
4859 {
4860 std::cout << "Not an AIS interactive object!" << std::endl;
4861 return 1;
4862 }
4863 }
4864
4865 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4866 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4867
4868 // turn boundaries on/off
91322f44 4869 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
a2d5ab2e 4870 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4871
4872 // set boundary line color
4873 if (argc >= 6)
4874 {
4875 // Text color
91322f44 4876 aRed = Draw::Atof (argv[3])/255.;
4877 aGreen = Draw::Atof (argv[4])/255.;
4878 aBlue = Draw::Atof (argv[5])/255.;
a2d5ab2e 4879 }
4880
4881 // set line width
4882 if (argc >= 7)
4883 {
91322f44 4884 aWidth = (Standard_Real)Draw::Atof (argv[6]);
a2d5ab2e 4885 }
4886
4887 // select appropriate line type
4888 if (argc == 8)
4889 {
91322f44 4890 switch (Draw::Atoi (argv[7]))
a2d5ab2e 4891 {
4892 case 1: aLineType = Aspect_TOL_DASH; break;
4893 case 2: aLineType = Aspect_TOL_DOT; break;
4894 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4895 default:
4896 aLineType = Aspect_TOL_SOLID;
4897 }
4898 }
4899
4900 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4901
4902 Handle(Prs3d_LineAspect) aBoundaryAspect =
4903 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4904
4905 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4906
4907 TheAISContext()->Redisplay (anInterObj);
4908
4909 return 0;
4910}
4911
eb4320f2 4912// This class is used for testing markers.
c04c30b3 4913
eb4320f2 4914class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4915{
4916
4917public:
4918
4919 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4920 const Standard_Integer& thePointsOnSide,
4921 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4922 {
4923 myStartPoint = theStartPoint;
4924 myPointsOnSide = thePointsOnSide;
4925 myMarkerAspect = theMarkerAspect;
4926 }
4927
ec357c5c 4928 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
eb4320f2 4929
4930private:
4931
4932 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4933 const Handle(Prs3d_Presentation)& aPresentation,
4934 const Standard_Integer aMode);
4935
4936 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4937 const Standard_Integer /*theMode*/);
4938
4939protected:
4940
4941 gp_XYZ myStartPoint;
4942 Standard_Integer myPointsOnSide;
4943 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4944};
4945
eb4320f2 4946
4947void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4948 const Handle(Prs3d_Presentation)& aPresentation,
4949 const Standard_Integer /*aMode*/)
4950{
4951 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4952 if (myPointsOnSide == 1)
4953 {
4954 anArray->AddVertex (myStartPoint);
4955 }
4956 else
4957 {
4958 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4959 {
4960 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4961 {
4962 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4963 {
4964 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4965 anArray->SetVertexColor (anArray->VertexNumber(),
4966 i / myPointsOnSide,
4967 j / myPointsOnSide,
4968 k / myPointsOnSide);
4969 }
4970 }
4971 }
4972 }
4973
4974 aPresentation->Clear();
4975 if (!myMarkerAspect.IsNull())
4976 {
4977 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4978 }
4979 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4980}
4981
4982void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4983 const Standard_Integer /*theMode*/)
4984{
4985 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4986
4987 if (myPointsOnSide == 1)
4988 {
4989 gp_Pnt aPoint (myStartPoint);
4990 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4991 theSelection->Add (aSensetivePoint);
4992 }
4993 else
4994 {
4995 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4996 {
4997 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4998 {
4999 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
5000 {
5001 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
5002 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
5003 theSelection->Add (aSensetivePoint);
5004 }
5005 }
5006 }
5007 }
5008}
a577aaab 5009//=======================================================================
5010//function : VMarkersTest
5011//purpose : Draws an array of markers for testing purposes.
5012//=======================================================================
498ce76b 5013static Standard_Integer VMarkersTest (Draw_Interpretor&,
a577aaab 5014 Standard_Integer theArgNb,
5015 const char** theArgVec)
5016{
5017 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5018 if (aContext.IsNull())
5019 {
5020 std::cerr << "Call 'vinit' before!\n";
5021 return 1;
5022 }
5023
5024 if (theArgNb < 5)
5025 {
5026 std::cerr << "Usage :\n " << theArgVec[0]
5027 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5028 return 1;
5029 }
5030
5031 Standard_Integer anArgIter = 1;
5032
5033 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5034 TCollection_AsciiString aFileName;
5035 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5036 Atof (theArgVec[anArgIter + 1]),
5037 Atof (theArgVec[anArgIter + 2]));
5038 anArgIter += 3;
5039
5040 Standard_Integer aPointsOnSide = 10;
5041 Standard_Integer aMarkerType = -1;
5042 Standard_Real aScale = 1.0;
5043 for (; anArgIter < theArgNb; ++anArgIter)
5044 {
5045 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5046 if (anArg.Search ("PointsOnSide=") > -1)
5047 {
5048 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5049 }
5050 else if (anArg.Search ("MarkerType=") > -1)
5051 {
5052 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5053 }
5054 else if (anArg.Search ("Scale=") > -1)
5055 {
5056 aScale = anArg.Token ("=", 2).RealValue();
5057 }
5058 else if (anArg.Search ("FileName=") > -1)
5059 {
5060 aFileName = anArg.Token ("=", 2);
5061 }
5062 else
5063 {
5064 std::cerr << "Wrong argument: " << anArg << "\n";
5065 return 1;
5066 }
5067 }
5068
5069 Handle(Graphic3d_AspectMarker3d) anAspect;
5070 Handle(Image_AlienPixMap) anImage;
5071 Quantity_Color aColor (Quantity_NOC_GREEN1);
5072 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5073 && !aFileName.IsEmpty())
5074 {
5075 anImage = new Image_AlienPixMap();
5076 if (!anImage->Load (aFileName))
5077 {
5078 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5079 return 1;
5080 }
076ca35c 5081 if (anImage->Format() == Image_PixMap::ImgGray)
5082 {
5083 anImage->SetFormat (Image_PixMap::ImgAlpha);
5084 }
5085 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5086 {
5087 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5088 }
a577aaab 5089 anAspect = new Graphic3d_AspectMarker3d (anImage);
5090 }
5091 else
5092 {
5093 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5094 }
5095
eb4320f2 5096 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5097 VDisplayAISObject (aName, aMarkersArray);
a577aaab 5098
5099 return 0;
5100}
5101
725ef85e 5102//! Auxiliary function to parse font aspect style argument
5103static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5104 Font_FontAspect& theAspect)
5105{
5106 if (theArg == "regular"
5107 || *theArg.ToCString() == 'r')
5108 {
5109 theAspect = Font_FA_Regular;
5110 return Standard_True;
5111 }
5112 else if (theArg == "bolditalic")
5113 {
5114 theAspect = Font_FA_BoldItalic;
5115 return Standard_True;
5116 }
5117 else if (theArg == "bold"
5118 || *theArg.ToCString() == 'b')
5119 {
5120 theAspect = Font_FA_Bold;
5121 return Standard_True;
5122 }
5123 else if (theArg == "italic"
5124 || *theArg.ToCString() == 'i')
5125 {
5126 theAspect = Font_FA_Italic;
5127 return Standard_True;
5128 }
5129 return Standard_False;
5130}
5131
5132//! Auxiliary function
5133static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5134{
5135 switch (theAspect)
5136 {
5137 case Font_FA_Regular: return "regular";
5138 case Font_FA_BoldItalic: return "bolditalic";
5139 case Font_FA_Bold: return "bold";
5140 case Font_FA_Italic: return "italic";
5141 default: return "undefined";
5142 }
5143}
5144
b514beda 5145//=======================================================================
5146//function : TextToBrep
5147//purpose : Tool for conversion text to occt-shapes
5148//=======================================================================
5149
5150static int TextToBRep (Draw_Interpretor& /*theDI*/,
5151 Standard_Integer theArgNb,
5152 const char** theArgVec)
5153{
5154 // Check arguments
5155 if (theArgNb < 5)
5156 {
5157 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5158 return 1;
5159 }
5160
5161 Standard_Integer anArgIter = 1;
5162 Standard_CString aResName = theArgVec[anArgIter++];
5163 Standard_CString aText = theArgVec[anArgIter++];
5164 Standard_CString aFontName = theArgVec[anArgIter++];
5165 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
5166
5167 Font_BRepFont aFont;
5168 Font_FontAspect aFontAspect = Font_FA_Regular;
5169 Standard_Boolean isCompositeCurve = Standard_False;
5170 gp_Ax3 aPenAx3 (gp::XOY());
5171 gp_Pnt aPenLoc;
5172 while (anArgIter < theArgNb)
5173 {
5174 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
725ef85e 5175 TCollection_AsciiString anArgCase (anArg);
5176 anArgCase.LowerCase();
5177 if (anArgCase.Search ("x=") > -1)
b514beda 5178 {
5179 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
5180 }
725ef85e 5181 else if (anArgCase.Search ("y=") > -1)
b514beda 5182 {
5183 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
5184 }
725ef85e 5185 else if (anArgCase.Search ("z=") > -1)
b514beda 5186 {
5187 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
5188 }
725ef85e 5189 else if (anArgCase.Search ("composite=") > -1)
b514beda 5190 {
5191 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
5192 }
725ef85e 5193 else if (parseFontStyle (anArgCase, aFontAspect))
b514beda 5194 {
725ef85e 5195 //
b514beda 5196 }
5197 else
5198 {
5199 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5200 }
5201 }
5202
5203 aFont.SetCompositeCurveMode (isCompositeCurve);
5204 if (!aFont.Init (aFontName, aFontAspect, aSize))
5205 {
5206 std::cerr << "Font initialization error\n";
5207 return 1;
5208 }
5209
5210 aPenAx3.SetLocation (aPenLoc);
5211 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
5212 return 0;
5213}
5214
725ef85e 5215//=======================================================================
5216//function : VFont
5217//purpose : Font management
5218//=======================================================================
5219
5220static int VFont (Draw_Interpretor& theDI,
5221 Standard_Integer theArgNb,
5222 const char** theArgVec)
5223{
5224 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5225 if (theArgNb < 2)
5226 {
5227 // just print the list of available fonts
5228 Standard_Boolean isFirst = Standard_True;
5229 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5230 anIter.More(); anIter.Next())
5231 {
5232 const Handle(Font_SystemFont)& aFont = anIter.Value();
5233 if (!isFirst)
5234 {
5235 theDI << "\n";
5236 }
5237
5238 theDI << aFont->FontName()->String()
5239 << " " << fontStyleString (aFont->FontAspect())
5240 << " " << aFont->FontPath()->String();
5241 isFirst = Standard_False;
5242 }
5243 return 0;
5244 }
5245
5246 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5247 {
5248 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5249 TCollection_AsciiString anArgCase (anArg);
5250 anArgCase.LowerCase();
5251 if (anArgCase == "find")
5252 {
5253 if (++anArgIter >= theArgNb)
5254 {
5255 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5256 return 1;
5257 }
5258
5259 Standard_CString aFontName = theArgVec[anArgIter];
5260 Font_FontAspect aFontAspect = Font_FA_Undefined;
5261 if (++anArgIter < theArgNb)
5262 {
5263 anArgCase = theArgVec[anArgIter];
5264 anArgCase.LowerCase();
5265 if (!parseFontStyle (anArgCase, aFontAspect))
5266 {
5267 --anArgIter;
5268 }
5269 }
5270 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5271 if (aFont.IsNull())
5272 {
5273 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5274 continue;
5275 }
5276
5277 theDI << aFont->FontName()->String()
5278 << " " << fontStyleString (aFont->FontAspect())
5279 << " " << aFont->FontPath()->String();
5280 }
5281 else if (anArgCase == "add"
5282 || anArgCase == "register")
5283 {
5284 if (++anArgIter >= theArgNb)
5285 {
5286 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5287 return 1;
5288 }
5289 Standard_CString aFontPath = theArgVec[anArgIter];
5290 Standard_CString aFontName = NULL;
5291 Font_FontAspect aFontAspect = Font_FA_Undefined;
5292 if (++anArgIter < theArgNb)
5293 {
5294 if (!parseFontStyle (anArgCase, aFontAspect))
5295 {
5296 aFontName = theArgVec[anArgIter];
5297 }
5298 if (++anArgIter < theArgNb)
5299 {
5300 anArgCase = theArgVec[anArgIter];
5301 anArgCase.LowerCase();
5302 if (!parseFontStyle (anArgCase, aFontAspect))
5303 {
5304 --anArgIter;
5305 }
5306 }
5307 }
5308
5309 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5310 if (aFont.IsNull())
5311 {
5312 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5313 continue;
5314 }
5315
5316 if (aFontAspect != Font_FA_Undefined
5317 || aFontName != NULL)
5318 {
5319 if (aFontAspect == Font_FA_Undefined)
5320 {
5321 aFontAspect = aFont->FontAspect();
5322 }
5323 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5324 if (aFontName != NULL)
5325 {
5326 aName = new TCollection_HAsciiString (aFontName);
5327 }
5328 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5329 }
5330
5331 aMgr->RegisterFont (aFont, Standard_True);
5332 theDI << aFont->FontName()->String()
5333 << " " << fontStyleString (aFont->FontAspect())
5334 << " " << aFont->FontPath()->String();
5335 }
5336 else
5337 {
5338 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5339 }
5340 }
5341
5342 return 0;
5343}
5344
5ad539d2 5345//=======================================================================
5346//function : VSetEdgeType
5347//purpose : Edges type management
5348//=======================================================================
5349
5350static int VSetEdgeType (Draw_Interpretor& theDI,
5351 Standard_Integer theArgNum,
5352 const char** theArgs)
5353{
5354 if (theArgNum < 4 || theArgNum > 9)
5355 {
5356 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5357 << theArgs[0] << "' for more information.\n";
5358 return 1;
5359 }
5360
5361 Standard_Boolean isForceRedisplay = Standard_False;
5362
5363 // Get shape name
5364 TCollection_AsciiString aName(theArgs[1]);
5365 if (!GetMapOfAIS().IsBound2 (aName))
5366 {
5367 theDI << theArgs[0] << " error: wrong object name.\n";
5368 return 1;
5369 }
5370
5371 Handle(AIS_InteractiveObject) anObject =
5372 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5373
5374 // Enable trianle edge mode
5375 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5376
5377 // Parse parameters
5378 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5379 {
5380 TCollection_AsciiString aParam ((theArgs[anIt]));
5381 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5382 {
5383 if (aParam.IsEqual ("-type"))
5384 {
5385 if (theArgNum <= anIt + 1)
5386 {
5387 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5388 << aParam.ToCString() << "'.\n";
5389 return 1;
5390 }
5391
5392 TCollection_AsciiString aType = theArgs[++anIt];
5393 aType.UpperCase();
5394
5395 if (aType.IsEqual ("SOLID"))
5396 {
5397 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5398 }
5399 else if (aType.IsEqual ("DASH"))
5400 {
5401 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5402 }
5403 else if (aType.IsEqual ("DOT"))
5404 {
5405 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5406 }
5407 else if (aType.IsEqual ("DOTDASH"))
5408 {
5409 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5410 }
5411 else
5412 {
5413 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5414 return 1;
5415 }
5416
5417 }
5418 else if (aParam.IsEqual ("-color"))
5419 {
5420 if (theArgNum <= anIt + 3)
5421 {
5422 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5423 << aParam.ToCString() << "'.\n";
5424 return 1;
5425 }
5426
5427 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5428 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5429 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5430 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5431 aG > 1 ? aG / 255.0 : aG,
5432 aB > 1 ? aB / 255.0 : aB,
5433 Quantity_TOC_RGB);
5434
5435 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5436 }
5437 else if (aParam.IsEqual ("-force"))
5438 {
5439 isForceRedisplay = Standard_True;
5440 }
5441 else
5442 {
5443 theDI << theArgs[0] << " error: unknown parameter '"
5444 << aParam.ToCString() << "'.\n";
5445 return 1;
5446 }
5447 }
5448 }
5449
5450 // Update shape presentation as aspect parameters were changed
5451 if (isForceRedisplay)
5452 {
5453 ViewerTest::GetAISContext()->Redisplay (anObject);
5454 }
5455 else
5456 {
5457 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5458 }
5459
5460 //Update view
5461 ViewerTest::CurrentView()->Redraw();
5462
5463 return 0;
5464}
5465
5466//=======================================================================
5467//function : VUnsetEdgeType
5468//purpose : Unsets edges visibility in shading mode
5469//=======================================================================
5470
5471static int VUnsetEdgeType (Draw_Interpretor& theDI,
5472 Standard_Integer theArgNum,
5473 const char** theArgs)
5474{
5475 if (theArgNum != 2 && theArgNum != 3)
5476 {
5477 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5478 << theArgs[0] << "' for more information.\n";
5479 return 1;
5480 }
5481
5482 Standard_Boolean isForceRedisplay = Standard_False;
5483
5484 // Get shape name
5485 TCollection_AsciiString aName (theArgs[1]);
5486 if (!GetMapOfAIS().IsBound2 (aName))
5487 {
5488 theDI << theArgs[0] << " error: wrong object name.\n";
5489 return 1;
5490 }
5491
5492 Handle(AIS_InteractiveObject) anObject =
5493 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5494
5495 // Enable trianle edge mode
5496 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5497
5498 // Parse parameters
5499 if (theArgNum == 3)
5500 {
5501 TCollection_AsciiString aParam ((theArgs[2]));
5502 if (aParam.IsEqual ("-force"))
5503 {
5504 isForceRedisplay = Standard_True;
5505 }
5506 else
5507 {
5508 theDI << theArgs[0] << " error: unknown parameter '"
5509 << aParam.ToCString() << "'.\n";
5510 return 1;
5511 }
5512 }
5513
5514 // Update shape presentation as aspect parameters were changed
5515 if (isForceRedisplay)
5516 {
5517 ViewerTest::GetAISContext()->Redisplay (anObject);
5518 }
5519 else
5520 {
5521 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5522 }
5523
5524 //Update view
5525 ViewerTest::CurrentView()->Redraw();
5526
5527 return 0;
5528}
5529
53b15292 5530
5531//=======================================================================
5532//function : VVertexMode
5533//purpose : Switches vertex display mode for AIS_Shape or displays the current value
5534//=======================================================================
5535
5536static int VVertexMode (Draw_Interpretor& theDI,
5537 Standard_Integer theArgNum,
5538 const char** theArgs)
5539{
5540 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5541 if (aContext.IsNull())
5542 {
5543 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5544 return 1;
5545 }
5546
5547 // No arguments --> print the current default vertex draw mode
5548 if (theArgNum == 1)
5549 {
5550 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5551 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5552 return 0;
5553 }
5554
5555 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5556 TCollection_AsciiString aParam (theArgs[1]);
5557 if (aParam == "-set")
5558 {
5559 if (theArgNum == 2)
5560 {
5561 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5562 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5563 return 1;
5564 }
5565
5566 TCollection_AsciiString aModeStr (theArgs[2]);
5567 Prs3d_VertexDrawMode aNewMode =
5568 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5569 (aModeStr == "all" ? Prs3d_VDM_All :
5570 Prs3d_VDM_Inherited);
5571
5572 Standard_Boolean aRedrawNeeded = Standard_False;
5573 AIS_ListOfInteractive anObjs;
5574
5575 // No object(s) specified -> use all displayed
5576 if (theArgNum == 3)
5577 {
5578 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5579 aContext->DisplayedObjects (anObjs);
5580 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5581 aRedrawNeeded = Standard_True;
5582 }
5583
5584 Handle(AIS_InteractiveObject) anObject;
5585 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5586 {
5587 TCollection_AsciiString aName (theArgs[aCount]);
5588 if (!GetMapOfAIS().IsBound2 (aName))
5589 {
5590 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5591 continue;
5592 }
5593 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5594 anObjs.Append (anObject);
5595 }
5596
5597 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5598 {
5599 anObject = anIt.Value();
5600 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5601 aContext->Redisplay (anObject, Standard_False);
5602 aRedrawNeeded = Standard_True;
5603 }
5604
5605 if (aRedrawNeeded)
5606 ViewerTest::CurrentView()->Redraw();
5607
5608 return 0;
5609 }
5610
5611 if (theArgNum > 2)
5612 {
5613 std::cout << "Error: invalid number of arguments" << std::endl;
5614 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5615 return 1;
5616 }
5617
5618 // One argument (object name) --> print the current vertex draw mode for the object
5619 Handle(AIS_InteractiveObject) anObject =
5620 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5621 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5622 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5623 return 0;
5624}
5625
d33222c1 5626//=======================================================================
5627//function : VPointCloud
5628//purpose : Create interactive object for arbitary set of points.
5629//=======================================================================
5630static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5631 Standard_Integer theArgNum,
5632 const char** theArgs)
5633{
5634 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5635 if (anAISContext.IsNull())
5636 {
5637 std::cerr << "Error: no active view!\n";
5638 return 1;
5639 }
5640
5641 // command to execute
5642 enum Command
5643 {
5644 CloudForShape, // generate point cloud for shape
5645 CloudSphere, // generate point cloud for generic sphere
5646 Unknow
5647 };
5648
5649 // count number of non-optional command arguments
5650 Command aCmd = Unknow;
5651 Standard_Integer aCmdArgs = 0;
5652 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5653 {
5654 Standard_CString anArg = theArgs[anArgIter];
5655 TCollection_AsciiString aFlag (anArg);
5656 aFlag.LowerCase();
5657 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5658 {
5659 aCmdArgs++;
5660 }
5661 }
5662 switch (aCmdArgs)
5663 {
5664 case 2 : aCmd = CloudForShape; break;
5665 case 7 : aCmd = CloudSphere; break;
5666 default :
5667 std::cout << "Error: wrong number of arguments! See usage:\n";
5668 theDI.PrintHelp (theArgs[0]);
5669 return 1;
5670 }
5671
5672 // parse options
5673 Standard_Boolean toRandColors = Standard_False;
5674 Standard_Boolean hasNormals = Standard_True;
5675 Standard_Boolean isSetArgNorm = Standard_False;
5676 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5677 {
5678 Standard_CString anArg = theArgs[anArgIter];
5679 TCollection_AsciiString aFlag (anArg);
5680 aFlag.LowerCase();
5681 if (aFlag == "-randcolors"
5682 || aFlag == "-randcolor")
5683 {
5684 if (isSetArgNorm && hasNormals)
5685 {
5686 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5687 return 1;
5688 }
5689 toRandColors = Standard_True;
5690 hasNormals = Standard_False;
5691 }
5692 else if (aFlag == "-normals"
5693 || aFlag == "-normal")
5694 {
5695 if (toRandColors)
5696 {
5697 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5698 return 1;
5699 }
5700 isSetArgNorm = Standard_True;
5701 hasNormals = Standard_True;
5702 }
5703 else if (aFlag == "-nonormals"
5704 || aFlag == "-nonormal")
5705 {
5706 isSetArgNorm = Standard_True;
5707 hasNormals = Standard_False;
5708 }
5709 }
5710
5711 Standard_CString aName = theArgs[1];
5712
5713 // generate arbitrary set of points
5714 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5715 if (aCmd == CloudForShape)
5716 {
5717 Standard_CString aShapeName = theArgs[2];
5718 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5719
5720 if (aShape.IsNull())
5721 {
5722 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5723 return 1;
5724 }
5725
5726 // calculate number of points
5727 TopLoc_Location aLocation;
5728 Standard_Integer aNbPoints = 0;
5729 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5730 {
5731 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5732 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5733 if (!aTriangulation.IsNull())
5734 {
5735 aNbPoints += aTriangulation->NbNodes();
5736 }
5737 }
5738 if (aNbPoints < 3)
5739 {
5740 std::cout << "Error: shape should be triangulated!\n";
5741 return 1;
5742 }
5743
5744 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5745 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5746 {
5747 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5748 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5749 if (aTriangulation.IsNull())
5750 {
5751 continue;
5752 }
5753
5754 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5755 const gp_Trsf& aTrsf = aLocation.Transformation();
5756
5757 // extract normals from nodes
5758 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5759 if (hasNormals)
5760 {
5761 Poly_Connect aPolyConnect (aTriangulation);
5762 StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
5763 }
5764
5765 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5766 {
5767 gp_Pnt aPoint = aNodes (aNodeIter);
5768 if (!aLocation.IsIdentity())
5769 {
5770 aPoint.Transform (aTrsf);
5771 if (hasNormals)
5772 {
5773 aNormals (aNodeIter).Transform (aTrsf);
5774 }
5775 }
5776
5777 // add vertex into array of points
5778 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5779 if (toRandColors)
5780 {
5781 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5782 1.0, 0.5, Quantity_TOC_HLS);
5783 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5784 }
5785
5786 if (hasNormals)
5787 {
5788 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5789 }
5790 }
5791 }
5792 }
5793 else if (aCmd == CloudSphere)
5794 {
5795 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5796 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5797 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5798 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5799 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5800
5801 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5802 aDistribution.LowerCase();
5803 if ( aDistribution != "surface" && aDistribution != "volume" )
5804 {
5805 std::cout << "Error: wrong arguments! See usage:\n";
5806 theDI.PrintHelp (theArgs[0]);
5807 return 1;
5808 }
5809 Standard_Boolean isSurface = aDistribution == "surface";
5810
5811 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5812
5813 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5814 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5815 {
5816 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5817 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5818 Standard_Real aDistance = isSurface ?
5819 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5820
5821 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5822 Sin (anAlpha),
5823 Cos (anAlpha) * Cos (aBeta));
5824 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5825
5826 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5827 if (toRandColors)
5828 {
5829 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5830 1.0, 0.5, Quantity_TOC_HLS);
5831 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5832 }
5833
5834 if (hasNormals)
5835 {
5836 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5837 }
5838 }
5839 }
5840
5841 // set array of points in point cloud object
5842 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5843 aPointCloud->SetPoints (anArrayPoints);
5844 VDisplayAISObject (aName, aPointCloud);
5845 return 0;
5846}
5847
a0c20252 5848//=======================================================================
5849//function : VPriority
5850//purpose : Prints or sets the display priority for an object
5851//=======================================================================
5852
5853static int VPriority (Draw_Interpretor& theDI,
5854 Standard_Integer theArgNum,
5855 const char** theArgs)
5856{
5857 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5858 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5859 if (aContext.IsNull())
5860 {
5861 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5862 return 1;
5863 }
5864
5865 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5866 Standard_Integer aPriority = -1;
5867 Standard_Integer aNbArgs = theArgNum;
5868 if (aLastArg.IsIntegerValue())
5869 {
5870 aPriority = aLastArg.IntegerValue();
5871 --aNbArgs;
5872 if (aPriority < 0 || aPriority > 10)
5873 {
5874 std::cout << "Error: the specified display priority value '" << aLastArg
5875 << "' is outside the valid range [0..10]" << std::endl;
5876 return 1;
5877 }
5878 }
5879 else
5880 {
5881 anUpdateTool.Invalidate();
5882 }
5883
5884 if (aNbArgs < 2)
5885 {
5886 std::cout << "Error: wrong number of arguments! See usage:\n";
5887 theDI.PrintHelp (theArgs[0]);
5888 return 1;
5889 }
5890
5891 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5892 {
5893 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5894 {
5895 continue;
5896 }
5897
5898 TCollection_AsciiString aName (theArgs[anArgIter]);
5899 Handle(AIS_InteractiveObject) anIObj;
5900 if (GetMapOfAIS().IsBound2 (aName))
5901 {
5902 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5903 }
5904
5905 if (anIObj.IsNull())
5906 {
5907 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5908 return 1;
5909 }
5910
5911 if (aPriority < 1)
5912 {
5913 theDI << aContext->DisplayPriority (anIObj) << " ";
5914 }
5915 else
5916 {
5917 aContext->SetDisplayPriority (anIObj, aPriority);
5918 }
5919 }
5920 return 0;
5921}
5922
7fd59977 5923//=======================================================================
5924//function : ObjectsCommands
161c4476 5925//purpose :
7fd59977 5926//=======================================================================
5927
5928void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
5929{
5930 const char *group ="AISObjects";
5931 theCommands.Add("vtrihedron",
5932 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
5933 __FILE__,VTrihedron,group);
5934
161c4476 5935 theCommands.Add("vtri2d",
7fd59977 5936 "vtri2d Name Selection in the viewer only ",
5937 __FILE__,VTrihedron2D ,group);
5938
161c4476 5939 theCommands.Add("vplanetri",
7fd59977 5940 "vplanetri Name Selection in the viewer only ",
5941 __FILE__,VPlaneTrihedron ,group);
5942
5943 theCommands.Add("vsize",
5944 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
5945 __FILE__,VSize,group);
5946
5947 theCommands.Add("vaxis",
5948 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
5949 __FILE__,VAxisBuilder,group);
5950
161c4476 5951 theCommands.Add("vaxispara",
7fd59977 5952 "vaxispara nom ",
5953 __FILE__,VAxisBuilder,group);
5954
5955 theCommands.Add("vaxisortho",
5956 "vaxisotho nom ",
5957 __FILE__,VAxisBuilder,group);
5958
5959 theCommands.Add("vpoint",
5960 "vpoint PointName [Xa] [Ya] [Za] ",
5961 __FILE__,VPointBuilder,group);
5962
5963 theCommands.Add("vplane",
9e8804b6 5964 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
7fd59977 5965 __FILE__,VPlaneBuilder,group);
5966
f3889691 5967 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
5968 " vchangeplane <plane_name>"
5969 " [x=center_x y=center_y z=center_z]"
5970 " [dx=dir_x dy=dir_y dz=dir_z]"
5971 " [sx=size_x sy=size_y]"
5972 " [noupdate]\n"
5973 " - changes parameters of the plane:\n"
5974 " - x y z - center\n"
5975 " - dx dy dz - normal\n"
5976 " - sx sy - plane sizes\n"
5977 " - noupdate - do not update/redisplay the plane in context\n"
5978 " Please enter coordinates in format \"param=value\" in arbitrary order.",
5979 __FILE__, VChangePlane, group);
5980
7fd59977 5981 theCommands.Add("vplanepara",
5982 "vplanepara PlaneName ",
5983 __FILE__,VPlaneBuilder,group);
5984
5985 theCommands.Add("vplaneortho",
5986 "vplaneortho PlaneName ",
5987 __FILE__,VPlaneBuilder,group);
5988
161c4476 5989 theCommands.Add("vline",
7fd59977 5990 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
5991 __FILE__,VLineBuilder,group);
5992
5993 theCommands.Add("vcircle",
329843e2 5994 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
7fd59977 5995 __FILE__,VCircleBuilder,group);
5996
29e2c6d2 5997 theCommands.Add ("vdrawtext",
5998 "vdrawtext name text"
5999 "\n\t\t: [-pos X=0 Y=0 Z=0]"
6000 "\n\t\t: [-color {R G B|name}=yellow]"
6001 "\n\t\t: [-halign {left|center|right}=left]"
6002 "\n\t\t: [-valign {top|center|bottom}=bottom}]"
6003 "\n\t\t: [-angle angle=0]"
6004 "\n\t\t: [-zoom {0|1}=0]"
6005 "\n\t\t: [-height height=16]"
6006 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
6007 "\n\t\t: [-font font=Times]"
6008 "\n\t\t: [-noupdate]"
6009 "\n\t\t: Display text label at specified position.",
6010 __FILE__, VDrawText, group);
7fd59977 6011
6012 theCommands.Add("vdrawsphere",
b7cd4ba7 6013 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
7fd59977 6014 __FILE__,VDrawSphere,group);
6015
29d43f9c 6016 theCommands.Add ("vsetlocation",
4e18052b 6017 "vsetlocation [-noupdate|-update] name x y z"
6018 "\n\t\t: Set new location for an interactive object.",
29d43f9c
A
6019 __FILE__, VSetLocation, group);
6020
3fc57801 6021 theCommands.Add (
6022 "vcomputehlr",
6023 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6024 __FILE__, VComputeHLR, group);
6025
9558a876 6026 theCommands.Add("vdrawparray",
871fa103 6027 "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 ]",
9558a876 6028 __FILE__,VDrawPArray,group);
ac04d101
SA
6029
6030 theCommands.Add("vconnect",
0717ddc1 6031 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
6032 " Makes an assembly of object instances located in point (Xo Yo Zo).",
ac04d101
SA
6033 __FILE__, VConnect, group);
6034
0717ddc1 6035 theCommands.Add("vconnectto",
d4aaad5b 6036 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
f751596e 6037 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6038 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
0717ddc1 6039 __FILE__, VConnectTo,group);
6040
6041 theCommands.Add("vdisconnect",
6042 "vdisconnect assembly_name (object_name | object_number | 'all')"
6043 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6044 __FILE__,VDisconnect,group);
6045
6046 theCommands.Add("vaddconnected",
6047 "vaddconnected assembly_name object_name"
6048 "Adds object to assembly.",
6049 __FILE__,VAddConnected,group);
6050
6051 theCommands.Add("vlistconnected",
6052 "vlistconnected assembly_name"
6053 "Lists objects in assembly.",
6054 __FILE__,VListConnected,group);
6055
ac04d101
SA
6056
6057 theCommands.Add("vselmode",
446e9c14 6058 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6059 " switches selection mode for the determined object or\n"
6060 " for all objects in context.\n"
6061 " mode_number is non-negative integer that has different\n"
6062 " meaning for different interactive object classes.\n"
6063 " For shapes the following mode_number values are allowed:\n"
6064 " 0 - shape\n"
6065 " 1 - vertex\n"
6066 " 2 - edge\n"
6067 " 3 - wire\n"
6068 " 4 - face\n"
6069 " 5 - shell\n"
6070 " 6 - solid\n"
6071 " 7 - compsolid\n"
6072 " 8 - compound\n"
6073 " is_turned_on is:\n"
6074 " 1 if mode is to be switched on\n"
6075 " 0 if mode is to be switched off\n",
ac04d101 6076 __FILE__, VSetSelectionMode, group);
ceae62f0 6077
4ca4bbe8 6078 theCommands.Add("vselnext",
6079 "vselnext : hilight next detected",
6080 __FILE__, VSelectionNext, group);
6081
6082 theCommands.Add("vselprev",
6083 "vselnext : hilight previous detected",
6084 __FILE__, VSelectionPrevious, group);
6085
ceae62f0
A
6086 theCommands.Add("vtriangle",
6087 "vtriangle Name PointName PointName PointName",
6088 __FILE__, VTriangle,group);
6089
6090 theCommands.Add("vsegment",
6091 "vsegment Name PointName PointName",
6092 __FILE__, VSegment,group);
59f45b7c 6093
6094 theCommands.Add("vobjzlayer",
6095 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6096 __FILE__, VObjZLayer, group);
3ddebf91 6097
6098 theCommands.Add("vpolygonoffset",
6099 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6100 __FILE__, VPolygonOffset, group);
a2d5ab2e 6101
6102 theCommands.Add ("vshowfaceboundary",
6103 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6104 "- turns on/off drawing of face boundaries for ais object "
6105 "and defines boundary line style.",
6106 __FILE__, VShowFaceBoundary, group);
a577aaab 6107
6108 theCommands.Add ("vmarkerstest",
6109 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6110 __FILE__, VMarkersTest, group);
b514beda 6111
6112 theCommands.Add ("text2brep",
6113 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
6114 __FILE__, TextToBRep, group);
725ef85e 6115 theCommands.Add ("vfont",
6116 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6117 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6118 __FILE__, VFont, group);
5ad539d2 6119
6120 theCommands.Add ("vsetedgetype",
6121 "vsetedgetype usage:\n"
6122 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6123 "\n\t\t: Sets edges type and color for input shape",
6124 __FILE__, VSetEdgeType, group);
6125
6126 theCommands.Add ("vunsetedgetype",
6127 "vunsetedgetype usage:\n"
6128 "vunsetedgetype ShapeName [-force]"
6129 "\n\t\t: Unsets edges type and color for input shape",
6130 __FILE__, VUnsetEdgeType, group);
53b15292 6131
6132 theCommands.Add ("vvertexmode",
6133 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6134 "vvertexmode - prints the default vertex draw mode\n"
6135 "vvertexmode name - prints the vertex draw mode of the given object\n"
6136 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6137 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6138 __FILE__, VVertexMode, group);
d33222c1 6139
6140 theCommands.Add ("vpointcloud",
6141 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6142 "\n\t\t: Create an interactive object for arbitary set of points"
6143 "\n\t\t: from triangulated shape."
6144 "\n"
6145 "vpointcloud name x y z r npts {surface|volume}\n"
6146 " ... [-randColor] [-normals] [-noNormals]"
6147 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6148 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6149 "\n\t\t:"
6150 "\n\t\t: Additional options:"
6151 "\n\t\t: -randColor - generate random color per point"
6152 "\n\t\t: -normals - generate normal per point (default)"
6153 "\n\t\t: -noNormals - do not generate normal per point"
6154 "\n",
6155 __FILE__, VPointCloud, group);
7d9e854b 6156
6157 theCommands.Add("vlocreset",
6158 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6159 __FILE__,
6160 LocalTransformPresentation, group);
6161
6162 theCommands.Add("vlocmove",
6163 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6164 __FILE__,
6165 LocalTransformPresentation, group);
6166
6167 theCommands.Add("vloctranslate",
6168 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6169 __FILE__,
6170 LocalTransformPresentation, group);
6171
6172 theCommands.Add("vlocrotate",
6173 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6174 __FILE__,
6175 LocalTransformPresentation, group);
6176
6177 theCommands.Add("vlocmirror",
6178 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6179 __FILE__,
6180 LocalTransformPresentation, group);
6181
6182 theCommands.Add("vlocscale",
6183 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6184 __FILE__,
6185 LocalTransformPresentation, group);
a0c20252 6186
6187 theCommands.Add("vpriority",
6188 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6189 __FILE__,
6190 VPriority, group);
7fd59977 6191}