0024947: Redesign OCCT legacy type system -- automatic
[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
321 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
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
340 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
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()
357 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
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()
418 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
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
478 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
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() ) {
496 theIOB = TheAISContext()->Interactive();
497 }
498 // on le downcast
499 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
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
1799 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1800 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1801
1802 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1803 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1804 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1805
1806 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1807 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
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
1930DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1931
1932class FilledCircle : public AIS_InteractiveObject
1933{
1934public:
1935 // CASCADE RTTI
ec357c5c 1936 DEFINE_STANDARD_RTTI(FilledCircle, AIS_InteractiveObject);
329843e2
A
1937
1938 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1939 FilledCircle(Handle(Geom_Circle) theCircle);
1940
1941private:
1942 TopoDS_Face ComputeFace();
1943
1944 // Virtual methods implementation
1945 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1946 const Handle(Prs3d_Presentation)& thePresentation,
1947 const Standard_Integer theMode);
1948
1949 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1950 const Standard_Integer theMode);
1951
1952protected:
1953 Handle(Geom_Circle) myCircle;
1954 Standard_Boolean myFilledStatus;
1955
1956};
1957
329843e2
A
1958
1959FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1960{
1961 myCircle = CreateCircle(theCenter, theRadius);
1962 myFilledStatus = Standard_True;
1963}
1964
1965FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1966{
1967 myCircle = theCircle;
1968 myFilledStatus = Standard_True;
1969}
1970
1971TopoDS_Face FilledCircle::ComputeFace()
1972{
1973 // Create edge from myCircle
1974 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1975 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1976
1977 // Create wire from anEdge
1978 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1979 TopoDS_Wire aWire = aWireMaker.Wire();
1980
1981 // Create face from aWire
1982 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1983 TopoDS_Face aFace = aFaceMaker.Face();
1984
1985 return aFace;
1986}
1987
857ffd5e 1988void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1989 const Handle(Prs3d_Presentation) &thePresentation,
329843e2
A
1990 const Standard_Integer theMode)
1991{
1992 thePresentation->Clear();
1993
1994 TopoDS_Face aFace = ComputeFace();
1995
1996 if (aFace.IsNull()) return;
1997 if (theMode != 0) return;
1998
1999 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2000}
2001
857ffd5e 2002void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 2003 const Standard_Integer /*theMode*/)
329843e2
A
2004{
2005 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2006 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2007 myCircle, myFilledStatus);
2008 theSelection->Add(aSensitiveCircle);
2009}
7fd59977 2010
2011//==============================================================================
2012// Fonction vcircle
2013// ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2014//==============================================================================
2015
2016//==============================================================================
2017//function : VCircleBuilder
161c4476 2018//purpose : Build an AIS_Circle
329843e2
A
2019//Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2020// PointName PointName PointName IsFilled
7fd59977 2021//==============================================================================
329843e2
A
2022
2023void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2024 TCollection_AsciiString theName,
2025 Standard_Boolean isFilled)
2026{
2027 Handle(AIS_InteractiveObject) aCircle;
2028 if (isFilled)
2029 {
2030 aCircle = new FilledCircle(theGeomCircle);
2031 }
2032 else
2033 {
2034 aCircle = new AIS_Circle(theGeomCircle);
9e8804b6 2035 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
329843e2
A
2036 }
2037
2038 // Check if there is an object with given name
2039 // and remove it from context
2040 if (GetMapOfAIS().IsBound2(theName))
2041 {
2042 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2043 Handle(AIS_InteractiveObject) anInterObj =
2044 Handle(AIS_InteractiveObject)::DownCast(anObj);
2045 TheAISContext()->Remove(anInterObj, Standard_False);
2046 GetMapOfAIS().UnBind2(theName);
2047 }
2048
2049 // Bind the circle to its name
2050 GetMapOfAIS().Bind(aCircle, theName);
2051
2052 // Display the circle
2053 TheAISContext()->Display(aCircle);
2054
2055}
7fd59977 2056
35e08fe8 2057static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
7fd59977 2058{
2059 Standard_Integer myCurrentIndex;
329843e2
A
2060 // Verification of the arguments
2061 if (argc>6 || argc<2)
2062 {
2063 std::cout << "vcircle error: expect 4 arguments.\n";
2064 return 1; // TCL_ERROR
2065 }
7fd59977 2066 TheAISContext()->CloseAllContexts();
2067
329843e2
A
2068 // There are all arguments
2069 if (argc == 6)
2070 {
2071 // Get arguments
2072 TCollection_AsciiString aName(argv[1]);
91322f44 2073 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
329843e2 2074
7fd59977 2075 Handle(AIS_InteractiveObject) theShapeA;
2076 Handle(AIS_InteractiveObject) theShapeB;
2077
329843e2
A
2078 theShapeA =
2079 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2080 theShapeB =
2081 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2082
7fd59977 2083
2084 // Arguments: AIS_Point AIS_Point AIS_Point
2085 // ========================================
329843e2 2086 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
7fd59977 2087 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2088 {
329843e2
A
2089 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2090 {
2091 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2092 return 1; // TCL_ERROR
7fd59977 2093 }
329843e2 2094 // The third object must be a point
7fd59977 2095 Handle(AIS_InteractiveObject) theShapeC =
329843e2 2096 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
7fd59977 2097 if (theShapeC.IsNull() ||
329843e2
A
2098 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2099 {
2100 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2101 return 1; // TCL_ERROR
2102 }
7fd59977 2103 // tag
329843e2
A
2104 // Verify that the three points are different
2105 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2106 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2107 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2108
2109 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2110 Handle(Geom_CartesianPoint) myCartPointA =
2111 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2112
2113 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2114 Handle(Geom_CartesianPoint) myCartPointB =
2115 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2116
2117 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2118 Handle(Geom_CartesianPoint) myCartPointC =
2119 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
7fd59977 2120
2121 // Test A=B
91322f44 2122 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2123 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2124 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
329843e2
A
2125 {
2126 std::cout << "vcircle error: Same points.\n";
2127 return 1; // TCL_ERROR
7fd59977 2128 }
2129 // Test A=C
91322f44 2130 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2131 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2132 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2133 {
2134 std::cout << "vcircle error: Same points.\n";
2135 return 1; // TCL_ERROR
7fd59977 2136 }
2137 // Test B=C
91322f44 2138 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2139 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2140 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2141 {
2142 std::cout << "vcircle error: Same points.\n";
2143 return 1;// TCL_ERROR
7fd59977 2144 }
329843e2
A
2145 // Construction of the circle
2146 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2147 myCartPointB->Pnt(), myCartPointC->Pnt() );
2148 Handle (Geom_Circle) theGeomCircle;
2149 try
2150 {
2151 theGeomCircle = Cir.Value();
2152 }
2153 catch (StdFail_NotDone)
2154 {
2155 std::cout << "vcircle error: can't create circle\n";
2156 return -1; // TCL_ERROR
2157 }
2158
2159 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2160 }
2161
329843e2 2162 // Arguments: AIS_Plane AIS_Point Real
7fd59977 2163 // ===================================
329843e2
A
2164 else if (theShapeA->Type() == AIS_KOI_Datum &&
2165 theShapeA->Signature() == 7 )
2166 {
2167 if (theShapeB->Type() != AIS_KOI_Datum ||
2168 theShapeB->Signature() != 1 )
2169 {
2170 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2171 return 1; // TCL_ERROR
2172 }
623c29a5 2173 // Check that the radius is >= 0
91322f44 2174 if (Draw::Atof(argv[4]) <= 0 )
329843e2
A
2175 {
2176 std::cout << "vcircle error: the radius must be >=0.\n";
2177 return 1; // TCL_ERROR
7fd59977 2178 }
7fd59977 2179
329843e2
A
2180 // Recover the normal to the plane
2181 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2182 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
7fd59977 2183
329843e2
A
2184 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2185 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2186 Handle(Geom_CartesianPoint) myCartPointB =
2187 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
7fd59977 2188
2189 gp_Pln mygpPlane = myGeomPlane->Pln();
2190 gp_Ax1 thegpAxe = mygpPlane.Axis();
2191 gp_Dir theDir = thegpAxe.Direction();
329843e2 2192 gp_Pnt theCenter = myCartPointB->Pnt();
91322f44 2193 Standard_Real TheR = Draw::Atof(argv[4]);
329843e2
A
2194 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2195 Handle (Geom_Circle) theGeomCircle;
2196 try
2197 {
2198 theGeomCircle = Cir.Value();
2199 }
2200 catch (StdFail_NotDone)
2201 {
2202 std::cout << "vcircle error: can't create circle\n";
2203 return -1; // TCL_ERROR
2204 }
2205
2206 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2207
2208 }
2209
2210 // Error
329843e2
A
2211 else
2212 {
2213 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2214 return 1; // TCL_ERROR
7fd59977 2215 }
2216
2217 }
329843e2 2218 // No arguments: selection in the viewer
7fd59977 2219 // =========================================
329843e2
A
2220 else
2221 {
2222 // Get the name of the circle
2223 TCollection_AsciiString aName(argv[1]);
7fd59977 2224
2225 TheAISContext()->OpenLocalContext();
329843e2 2226 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 2227
329843e2 2228 // Activate selection mode for vertices and faces
7fd59977 2229 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2230 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2231 std::cout << " Select a vertex or a face\n";
7fd59977 2232
329843e2 2233 // Wait for picking
7fd59977 2234 Standard_Integer argcc = 5;
2235 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2236 const char **argvv = (const char **) buff;
2237 while (ViewerMainLoop( argcc, argvv) ) { }
329843e2 2238 // end of the loop
7fd59977 2239
2240 TopoDS_Shape ShapeA;
329843e2
A
2241 for(TheAISContext()->InitSelected();
2242 TheAISContext()->MoreSelected();
2243 TheAISContext()->NextSelected() )
2244 {
7fd59977 2245 ShapeA = TheAISContext()->SelectedShape();
2246 }
2247
329843e2
A
2248 // ShapeA is a Vertex
2249 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2250 {
7fd59977 2251 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2252 std::cout << " Select a different vertex\n";
7fd59977 2253
2254 TopoDS_Shape ShapeB;
329843e2
A
2255 do
2256 {
2257 // Wait for picking
7fd59977 2258 Standard_Integer argccc = 5;
2259 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2260 const char **argvvv = (const char **) bufff;
2261 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2262 // end of the loop
7fd59977 2263
329843e2
A
2264 for(TheAISContext()->InitSelected();
2265 TheAISContext()->MoreSelected();
2266 TheAISContext()->NextSelected() )
2267 {
7fd59977 2268 ShapeB = TheAISContext()->SelectedShape();
2269 }
7fd59977 2270 } while(ShapeB.IsSame(ShapeA) );
2271
329843e2 2272 // Selection of ShapeC
ceae62f0 2273 std::cout << " Select the last vertex\n";
7fd59977 2274 TopoDS_Shape ShapeC;
329843e2
A
2275 do
2276 {
2277 // Wait for picking
7fd59977 2278 Standard_Integer argcccc = 5;
2279 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2280 const char **argvvvv = (const char **) buffff;
2281 while (ViewerMainLoop( argcccc, argvvvv) ) { }
329843e2 2282 // end of the loop
7fd59977 2283
329843e2
A
2284 for(TheAISContext()->InitSelected();
2285 TheAISContext()->MoreSelected();
2286 TheAISContext()->NextSelected() )
2287 {
7fd59977 2288 ShapeC = TheAISContext()->SelectedShape();
2289 }
7fd59977 2290 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
329843e2
A
2291
2292 // Get isFilled
2293 Standard_Boolean isFilled;
2294 std::cout << "Enter filled status (0 or 1)\n";
2295 cin >> isFilled;
7fd59977 2296
329843e2 2297 // Close the local context
7fd59977 2298 TheAISContext()->CloseLocalContext(myCurrentIndex);
2299
329843e2
A
2300 // Construction of the circle
2301 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2302 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2303 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2304
2305 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2306 Handle (Geom_Circle) theGeomCircle;
2307 try
2308 {
2309 theGeomCircle = Cir.Value();
2310 }
2311 catch (StdFail_NotDone)
2312 {
2313 std::cout << "vcircle error: can't create circle\n";
2314 return -1; // TCL_ERROR
2315 }
7fd59977 2316
329843e2 2317 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2318
2319 }
329843e2 2320 // Shape is a face
ceae62f0 2321 else
329843e2 2322 {
ceae62f0 2323 std::cout << " Select a vertex (in your face)\n";
7fd59977 2324 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2325
2326 TopoDS_Shape ShapeB;
329843e2 2327 // Wait for picking
7fd59977 2328 Standard_Integer argccc = 5;
2329 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2330 const char **argvvv = (const char **) bufff;
2331 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2332 // end of the loop
7fd59977 2333
329843e2
A
2334 for(TheAISContext()->InitSelected();
2335 TheAISContext()->MoreSelected();
2336 TheAISContext()->NextSelected() )
2337 {
7fd59977 2338 ShapeB = TheAISContext()->SelectedShape();
2339 }
2340
329843e2
A
2341 // Recover the radius
2342 Standard_Real theRad;
2343 do
2344 {
2345 std::cout << " Enter the value of the radius:\n";
2346 cin >> theRad;
2347 } while (theRad <= 0);
2348
2349 // Get filled status
2350 Standard_Boolean isFilled;
2351 std::cout << "Enter filled status (0 or 1)\n";
2352 cin >> isFilled;
7fd59977 2353
329843e2 2354 // Close the local context
7fd59977 2355 TheAISContext()->CloseLocalContext(myCurrentIndex);
329843e2 2356 // Construction of the circle
7fd59977 2357
329843e2
A
2358 // Recover the normal to the plane. tag
2359 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2360 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2361 gp_Pln myPlane = mySurface.Plane();
2362 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
7fd59977 2363 gp_Pln mygpPlane = theGeomPlane->Pln();
2364 gp_Ax1 thegpAxe = mygpPlane.Axis();
2365 gp_Dir theDir = thegpAxe.Direction();
2366
329843e2
A
2367 // Recover the center
2368 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
7fd59977 2369
623c29a5 2370 // Construct the circle
329843e2
A
2371 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2372 Handle (Geom_Circle) theGeomCircle;
2373 try
2374 {
2375 theGeomCircle = Cir.Value();
2376 }
2377 catch (StdFail_NotDone)
2378 {
2379 std::cout << "vcircle error: can't create circle\n";
2380 return -1; // TCL_ERROR
2381 }
7fd59977 2382
329843e2
A
2383 DisplayCircle(theGeomCircle, aName, isFilled);
2384
7fd59977 2385 }
2386
7fd59977 2387 }
2388
2389 return 0;
2390}
2391
29e2c6d2 2392//=======================================================================
7fd59977 2393//function : VDrawText
29e2c6d2 2394//purpose :
2395//=======================================================================
2396static int VDrawText (Draw_Interpretor& theDI,
2397 Standard_Integer theArgsNb,
2398 const char** theArgVec)
7fd59977 2399{
29e2c6d2 2400 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2401 if (theArgsNb < 3)
fe551aef 2402 {
29e2c6d2 2403 std::cout << "Error: wrong number of arguments! See usage:\n";
2404 theDI.PrintHelp (theArgVec[0]);
2405 return 1;
2406 }
2407 else if (aContext.IsNull())
2408 {
2409 std::cout << "Error: no active view!\n";
2410 return 1;
fe551aef 2411 }
2412
29e2c6d2 2413 Standard_Integer anArgIt = 1;
2414 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2415 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2416 Handle(AIS_TextLabel) aTextPrs;
2417 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
7fd59977 2418
29e2c6d2 2419 if (GetMapOfAIS().IsBound2 (aName))
7fd59977 2420 {
29e2c6d2 2421 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
2422 }
2423 else
2424 {
2425 aTextPrs = new AIS_TextLabel();
2426 aTextPrs->SetFont ("Courier");
7fd59977 2427 }
13a22457 2428
29e2c6d2 2429 aTextPrs->SetText (aText);
13a22457 2430
29e2c6d2 2431 for (; anArgIt < theArgsNb; ++anArgIt)
161c4476 2432 {
29e2c6d2 2433 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2434 aParam.LowerCase();
2435
2436 if (anAutoUpdater.parseRedrawMode (aParam))
13a22457 2437 {
29e2c6d2 2438 continue;
13a22457 2439 }
29e2c6d2 2440 else if (aParam == "-pos"
2441 || aParam == "-position")
2442 {
2443 if (anArgIt + 3 >= theArgsNb)
2444 {
2445 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2446 return 1;
2447 }
7fd59977 2448
29e2c6d2 2449 gp_Pnt aPos;
2450 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2451 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2452 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2453 aTextPrs->SetPosition (aPos);
2454 }
2455 else if (aParam == "-color")
2456 {
2457 if (anArgIt + 1 >= theArgsNb)
2458 {
2459 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2460 return 1;
2461 }
7fd59977 2462
29e2c6d2 2463 TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
2464 Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
2465 if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
2466 {
2467 anArgIt += 1;
2468 aTextPrs->SetColor (aNameOfColor);
2469 continue;
2470 }
2471 else if (anArgIt + 3 >= theArgsNb)
2472 {
2473 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2474 return 1;
2475 }
7fd59977 2476
29e2c6d2 2477 TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
2478 TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
2479 if (!aColor.IsRealValue()
2480 || !aGreen.IsRealValue()
2481 || !aBlue.IsRealValue())
2482 {
2483 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2484 return 1;
2485 }
7fd59977 2486
29e2c6d2 2487 const Graphic3d_Vec3d anRGB (aColor.RealValue(),
2488 aGreen.RealValue(),
2489 aBlue.RealValue());
7fd59977 2490
29e2c6d2 2491 aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
2492 anArgIt += 3;
2493 }
2494 else if (aParam == "-halign")
2495 {
2496 if (++anArgIt >= theArgsNb)
2497 {
2498 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2499 return 1;
2500 }
13a22457 2501
29e2c6d2 2502 TCollection_AsciiString aType (theArgVec[anArgIt]);
2503 aType.LowerCase();
2504 if (aType == "left")
2505 {
2506 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2507 }
2508 else if (aType == "center")
2509 {
2510 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2511 }
2512 else if (aType == "right")
2513 {
2514 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2515 }
2516 else
2517 {
2518 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2519 return 1;
2520 }
2521 }
2522 else if (aParam == "-valign")
2523 {
2524 if (++anArgIt >= theArgsNb)
2525 {
2526 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2527 return 1;
2528 }
2529
2530 TCollection_AsciiString aType (theArgVec[anArgIt]);
2531 aType.LowerCase();
2532 if (aType == "top")
2533 {
2534 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2535 }
2536 else if (aType == "center")
2537 {
2538 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2539 }
2540 else if (aType == "bottom")
2541 {
2542 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2543 }
2544 else
2545 {
2546 std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
2547 return 1;
2548 }
2549 }
2550 else if (aParam == "-angle")
2551 {
2552 if (++anArgIt >= theArgsNb)
2553 {
2554 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2555 return 1;
2556 }
13a22457 2557
29e2c6d2 2558 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2559 }
2560 else if (aParam == "-zoom")
2561 {
2562 if (++anArgIt >= theArgsNb)
2563 {
2564 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2565 return 1;
2566 }
13a22457 2567
29e2c6d2 2568 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2569 }
2570 else if (aParam == "-height")
2571 {
2572 if (++anArgIt >= theArgsNb)
2573 {
2574 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2575 return 1;
2576 }
13a22457 2577
29e2c6d2 2578 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2579 }
2580 else if (aParam == "-aspect")
2581 {
2582 if (++anArgIt >= theArgsNb)
2583 {
2584 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2585 return 1;
2586 }
13a22457 2587
29e2c6d2 2588 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2589 anOption.LowerCase();
2590 if (anOption.IsEqual ("regular"))
2591 {
2592 aTextPrs->SetFontAspect (Font_FA_Regular);
2593 }
2594 else if (anOption.IsEqual ("bold"))
2595 {
2596 aTextPrs->SetFontAspect (Font_FA_Bold);
2597 }
2598 else if (anOption.IsEqual ("italic"))
2599 {
2600 aTextPrs->SetFontAspect (Font_FA_Italic);
2601 }
2602 else if (anOption.IsEqual ("bolditalic"))
2603 {
2604 aTextPrs->SetFontAspect (Font_FA_BoldItalic);
2605 }
2606 }
2607 else if (aParam == "-font")
2608 {
2609 if (++anArgIt >= theArgsNb)
2610 {
2611 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2612 return 1;
2613 }
13a22457 2614
29e2c6d2 2615 aTextPrs->SetFont (theArgVec[anArgIt]);
2616 }
2617 else
2618 {
2619 std::cout << "Error: unknown argument '" << aParam << "'\n";
2620 return 1;
2621 }
13a22457
S
2622 }
2623
29e2c6d2 2624 ViewerTest::Display (aName, aTextPrs, Standard_False);
161c4476 2625 return 0;
7fd59977 2626}
2627
2628#include <math.h>
2629#include <gp_Pnt.hxx>
2630#include <Graphic3d_ArrayOfPoints.hxx>
2631#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 2632#include <Graphic3d_ArrayOfTriangles.hxx>
2633#include <Poly_Array1OfTriangle.hxx>
2634#include <Poly_Triangle.hxx>
2635#include <Poly_Triangulation.hxx>
2636#include <TColgp_Array1OfPnt.hxx>
2637#include <TShort_Array1OfShortReal.hxx>
2638#include <TShort_HArray1OfShortReal.hxx>
2639
2640#include <AIS_Triangulation.hxx>
7fd59977 2641#include <StdPrs_ToolShadedShape.hxx>
2642#include <Poly_Connect.hxx>
2643#include <TColgp_Array1OfDir.hxx>
2644#include <Graphic3d_GraphicDriver.hxx>
2645
7fd59977 2646#include <TColStd_Array1OfInteger.hxx>
2647#include <TColStd_HArray1OfInteger.hxx>
2648#include <Prs3d_ShadingAspect.hxx>
2649#include <Graphic3d_MaterialAspect.hxx>
2650#include <Graphic3d_AspectFillArea3d.hxx>
2651
2652#include <BRepPrimAPI_MakeCylinder.hxx>
2653#include <TopoDS_Shape.hxx>
2654#include <TopExp_Explorer.hxx>
2655#include <TopAbs.hxx>
2656#include <StdSelect_ShapeTypeFilter.hxx>
ec357c5c 2657#include <AIS_InteractiveObject.hxx>
7fd59977 2658
2659
2660//===============================================================================================
2661//function : CalculationOfSphere
2662//author : psn
2663//purpose : Create a Sphere
2664//===============================================================================================
2665
161c4476 2666Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
7fd59977 2667 int res ,
2668 double Radius ){
2669 double mRadius = Radius;
2670 double mCenter[3] = {X,Y,Z};
2671 int mThetaResolution;
2672 int mPhiResolution;
2673 double mStartTheta = 0;//StartTheta;
2674 double mEndTheta = 360;//EndTheta;
2675 double mStartPhi = 0;//StartPhi;
2676 double mEndPhi = 180;//EndPhi;
2677 res = res < 4 ? 4 : res;
2678
2679 mThetaResolution = res;
2680 mPhiResolution = res;
2681
2682 int i, j;
2683 int jStart, jEnd, numOffset;
7fd59977 2684 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2685 double startTheta, endTheta, startPhi, endPhi;
2686 int base, numPoles=0, thetaResolution, phiResolution;
2687
2688 int pts[3];
2689 int piece = -1;
2690 int numPieces = 1;
2691 if ( numPieces > mThetaResolution ) {
2692 numPieces = mThetaResolution;
2693 }
2694
2695 int localThetaResolution = mThetaResolution;
2696 double localStartTheta = mStartTheta;
2697 double localEndTheta = mEndTheta;
2698
2699 while ( localEndTheta < localStartTheta ) {
2700 localEndTheta += 360.0;
2701 }
2702
2703 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2704
2705 // Change the ivars based on pieces.
2706 int start, end;
2707 start = piece * localThetaResolution / numPieces;
2708 end = (piece+1) * localThetaResolution / numPieces;
2709 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2710 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2711 localThetaResolution = end - start;
2712
7fd59977 2713 // Create north pole if needed
2714 int number_point = 0;
2715 int number_pointArray = 0;
2716
2717 if ( mStartPhi <= 0.0 ) {
2718 number_pointArray++;
2719 numPoles++;
2720 }
2721 if ( mEndPhi >= 180.0 ) {
2722 number_pointArray++;
2723 numPoles++;
2724 }
161c4476 2725
7fd59977 2726 // Check data, determine increments, and convert to radians
2727 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
c6541a0c 2728 startTheta *= M_PI / 180.0;
7fd59977 2729 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
c6541a0c 2730 endTheta *= M_PI / 180.0;
7fd59977 2731
2732
2733 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
c6541a0c 2734 startPhi *= M_PI / 180.0;
7fd59977 2735 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
c6541a0c 2736 endPhi *= M_PI / 180.0;
7fd59977 2737
2738 phiResolution = mPhiResolution - numPoles;
2739 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2740 thetaResolution = localThetaResolution;
2741 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2742 ++localThetaResolution;
2743 }
2744 deltaTheta = (endTheta - startTheta) / thetaResolution;
2745
2746 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2747 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2748
2749 // Create intermediate points
2750 for ( i = 0; i < localThetaResolution; i++ ) {
2751 for ( j = jStart; j < jEnd; j++ ) {
2752 number_pointArray++;
2753 }
2754 }
2755
2756 //Generate mesh connectivity
2757 base = phiResolution * localThetaResolution;
2758
2759 int number_triangle = 0 ;
2760 if ( mStartPhi <= 0.0 ) { // around north pole
2761 number_triangle += localThetaResolution;
2762 }
161c4476 2763
7fd59977 2764 if ( mEndPhi >= 180.0 ) { // around south pole
2765 number_triangle += localThetaResolution;
2766 }
2767
2768 // bands in-between poles
2769 for ( i=0; i < localThetaResolution; i++){
2770 for ( j=0; j < (phiResolution-1); j++){
2771 number_triangle +=2;
2772 }
2773 }
2774
2775 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2776 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2777 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2778
2779 if ( mStartPhi <= 0.0 ){
2780 x[0] = mCenter[0];
2781 x[1] = mCenter[1];
2782 x[2] = mCenter[2] + mRadius;
2783 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2784 }
2785
2786 // Create south pole if needed
2787 if ( mEndPhi >= 180.0 ){
2788 x[0] = mCenter[0];
2789 x[1] = mCenter[1];
2790 x[2] = mCenter[2] - mRadius;
2791 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2792 }
2793
2794 number_point = 3;
2795 for ( i=0; i < localThetaResolution; i++){
c6541a0c 2796 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
7fd59977 2797 for ( j = jStart; j < jEnd; j++){
2798 phi = startPhi + j*deltaPhi;
2799 radius = mRadius * sin((double)phi);
2800 n[0] = radius * cos((double)theta);
2801 n[1] = radius * sin((double)theta);
2802 n[2] = mRadius * cos((double)phi);
2803 x[0] = n[0] + mCenter[0];
2804 x[1] = n[1] + mCenter[1];
2805 x[2] = n[2] + mCenter[2];
2806 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2807 number_point++;
2808 }
2809 }
2810
2811 numPoles = 3;
2812 number_triangle = 1;
2813 if ( mStartPhi <= 0.0 ){// around north pole
2814 for (i=0; i < localThetaResolution; i++){
2815 pts[0] = phiResolution*i + numPoles;
2816 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2817 pts[2] = 1;
2818 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2819 number_triangle++;
2820 }
2821 }
161c4476 2822
7fd59977 2823 if ( mEndPhi >= 180.0 ){ // around south pole
2824 numOffset = phiResolution - 1 + numPoles;
2825 for (i=0; i < localThetaResolution; i++){
2826 pts[0] = phiResolution*i + numOffset;
2827 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2828 pts[1] = numPoles - 1;
2829 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2830 number_triangle++;
2831 }
2832 }
2833
2834 // bands in-between poles
161c4476 2835
7fd59977 2836 for (i=0; i < localThetaResolution; i++){
2837 for (j=0; j < (phiResolution-1); j++){
2838 pts[0] = phiResolution*i + j + numPoles;
2839 pts[1] = pts[0] + 1;
2840 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2841 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2842 number_triangle++;
2843 pts[1] = pts[2];
2844 pts[2] = pts[1] - 1;
2845 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2846 number_triangle++;
2847 }
2848 }
2849
2850 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2851
2852 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2853
2854 Standard_Integer index[3];
2855 Standard_Real Tol = Precision::Confusion();
2856
2857 gp_Dir Nor;
2858 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2859 gp_XYZ eqPlan(0, 0, 0);
2860 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2861 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2862 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2863 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2864 gp_XYZ vv = v1^v2;
2865 Standard_Real mod = vv.Modulus();
2866 if(mod < Tol) continue;
2867 eqPlan += vv/mod;
2868 }
2869
2870 Standard_Real modmax = eqPlan.Modulus();
2871
161c4476 2872 if(modmax > Tol)
7fd59977 2873 Nor = gp_Dir(eqPlan);
161c4476 2874 else
7fd59977 2875 Nor = gp_Dir(0., 0., 1.);
2876
2877 Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
2878 Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
2879 Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
2880 Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
2881 }
2882
2883 delete pc;
2884 polyTriangulation->SetNormals(Normals);
2885
2886 return polyTriangulation;
2887}
2888
2889//===============================================================================================
2890//function : VDrawSphere
2891//author : psn
2892//purpose : Create an AIS shape.
7fd59977 2893//===============================================================================================
35e08fe8 2894static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
161c4476
K
2895{
2896 // check for errors
2897 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2898 if (aContextAIS.IsNull())
2899 {
2900 std::cout << "Call vinit before!\n";
2901 return 1;
2902 }
2903 else if (argc < 3)
2904 {
2905 std::cout << "Use: " << argv[0]
58655684 2906 << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
161c4476
K
2907 return 1;
2908 }
7fd59977 2909
161c4476
K
2910 // read the arguments
2911 TCollection_AsciiString aShapeName (argv[1]);
91322f44 2912 Standard_Integer aResolution = Draw::Atoi (argv[2]);
2913 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
2914 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
2915 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
2916 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
b7cd4ba7 2917 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
2918 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
7fd59977 2919
161c4476 2920 // remove AIS object with given name from map
208e6839 2921 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
161c4476 2922
b7cd4ba7 2923 if (toPrintInfo)
2924 std::cout << "Compute Triangulation...\n";
161c4476
K
2925 Handle(AIS_Triangulation) aShape
2926 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
2927 aResolution,
2928 aRadius));
2929 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
2930 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
2931
161c4476
K
2932 // stupid initialization of Green color in RGBA space as integer
2933 // probably wrong for big-endian CPUs
2934 Standard_Integer aRed = 0;
2935 Standard_Integer aGreen = 255;
2936 Standard_Integer aBlue = 0;
2937 Standard_Integer anAlpha = 0; // not used
2938 Standard_Integer aColorInt = aRed;
2939 aColorInt += aGreen << 8;
2940 aColorInt += aBlue << 16;
2941 aColorInt += anAlpha << 24;
2942
2943 // setup colors array per vertex
2944 Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
2945 for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
2946 {
2947 aColorArray->SetValue (aNodeId, aColorInt);
7fd59977 2948 }
161c4476
K
2949 aShape->SetColors (aColorArray);
2950
2951 // show statistics
2952 Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2953 Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat
2954 Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha
2955 Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint
2956 Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4;
2957 Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize;
2958 aTotalSize >>= 20; //MB
2959 aNormalsSize >>= 20;
2960 aColorsSize >>= 20;
2961 aTrianglesSize >>= 20;
2962 aPolyConnectSize >>= 20;
b7cd4ba7 2963 if (toPrintInfo)
2964 {
2965 std::cout << "NumberOfPoints: " << aNumberPoints << "\n"
2966 << "NumberOfTriangles: " << aNumberTriangles << "\n"
2967 << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
2968 << "Amount of memory for colors: " << aColorsSize << " Mb\n"
2969 << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
2970 << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
2971 }
7fd59977 2972
2973 // Setting material properties, very important for desirable visual result!
161c4476
K
2974 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
2975 aMat.SetAmbient (0.2);
2976 aMat.SetSpecular (0.5);
2977 Handle(Graphic3d_AspectFillArea3d) anAspect
2978 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
2979 Quantity_NOC_RED,
2980 Quantity_NOC_YELLOW,
2981 Aspect_TOL_SOLID,
2982 1.0,
2983 aMat,
2984 aMat);
7fd59977 2985 Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect();
161c4476
K
2986 if (toShowEdges)
2987 {
2988 anAspect->SetEdgeOn();
2989 }
7fd59977 2990 else
161c4476
K
2991 {
2992 anAspect->SetEdgeOff();
2993 }
2994 aShAsp->SetAspect (anAspect);
2995 aShape->Attributes()->SetShadingAspect (aShAsp);
7fd59977 2996
208e6839 2997 VDisplayAISObject (aShapeName, aShape);
7fd59977 2998 return 0;
2999}
3000
3fc57801 3001//=============================================================================
3002//function : VComputeHLR
3003//purpose :
3004//=============================================================================
3005
3006static int VComputeHLR (Draw_Interpretor& di,
3007 Standard_Integer argc,
3008 const char** argv)
3009{
3010 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3011
3012 if (aContextAIS.IsNull ())
3013 {
3014 di << "Please call vinit before\n";
3015 return 1;
3016 }
3017
3018 if ( argc != 3 && argc != 12 )
3019 {
3020 di << "Usage: " << argv[0] << " ShapeName HlrName "
3021 << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
3022 << " ShapeName - name of the initial shape\n"
3023 << " HlrName - result hlr object from initial shape\n"
3024 << " eye, dir are eye position and look direction\n"
3025 << " up is the look up direction vector\n"
3026 << " Use vtop to see projected hlr shape\n";
3027 return 1;
3028 }
3029
3030 // shape and new object name
3031 TCollection_AsciiString aShapeName (argv[1]);
3032 TCollection_AsciiString aHlrName (argv[2]);
3033
3034 TopoDS_Shape aSh = DBRep::Get (argv[1]);
3035 if (aSh.IsNull())
3036 {
3037 BRep_Builder aBrepBuilder;
3038 BRepTools::Read (aSh, argv[1], aBrepBuilder);
3039 if (aSh.IsNull ())
3040 {
3041 di << "No shape with name " << argv[1] << " found\n";
3042 return 1;
3043 }
3044 }
3045
3046 if (GetMapOfAIS ().IsBound2 (aHlrName))
3047 {
3048 di << "Presentable object with name " << argv[2] << " already exists\n";
3049 return 1;
3050 }
3051
3052 // close local context
3053 if (aContextAIS->HasOpenedContext ())
3054 aContextAIS->CloseLocalContext ();
3055
3056 Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
3057 HLRBRep_PolyHLRToShape aHLRToShape;
3058
3059 gp_Pnt anEye;
3060 gp_Dir aDir;
3061 gp_Ax2 aProjAx;
3062 if (argc == 9)
3063 {
3064 gp_Dir anUp;
3065
91322f44 3066 anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5]));
3067 aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8]));
3068 anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11]));
3fc57801 3069 aProjAx.SetLocation (anEye);
3070 aProjAx.SetDirection (aDir);
3071 aProjAx.SetYDirection (anUp);
3072 }
3073 else
3074 {
3075 gp_Dir aRight;
3076
3077 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3078 Handle(V3d_View) aView = ViewerTest::CurrentView();
3079 Standard_Integer aWidth, aHeight;
3080 Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ;
3081 Standard_Real aRightX, aRightY, aRightZ;
3082 aView->Window()->Size (aWidth, aHeight);
3083
3084 aView->ConvertWithProj (aWidth, aHeight/2,
3085 aRightX, aRightY, aRightZ,
3086 aDirX, aDirY, aDirZ);
3087
3088 aView->ConvertWithProj (aWidth/2, aHeight/2,
3089 aCentX, aCentY, aCentZ,
3090 aDirX, aDirY, aDirZ);
3091
3092 anEye.SetCoord (-aCentX, -aCentY, -aCentZ);
3093 aDir.SetCoord (-aDirX, -aDirY, -aDirZ);
3094 aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ);
3095 aProjAx.SetLocation (anEye);
3096 aProjAx.SetDirection (aDir);
3097 aProjAx.SetXDirection (aRight);
3098 }
3099
3100 HLRAlgo_Projector aProjector (aProjAx);
3101 aPolyAlgo->Projector (aProjector);
3102 aPolyAlgo->Load (aSh);
3103 aPolyAlgo->Update ();
3104
3105 aHLRToShape.Update (aPolyAlgo);
3106
3107 // make hlr shape from input shape
3108 TopoDS_Compound aHlrShape;
3109 BRep_Builder aBuilder;
3110 aBuilder.MakeCompound (aHlrShape);
3111
3112 TopoDS_Shape aCompound = aHLRToShape.VCompound();
3113 if (!aCompound.IsNull ())
3114 {
3115 aBuilder.Add (aHlrShape, aCompound);
3116 }
3117
3118 // extract visible outlines
3119 aCompound = aHLRToShape.OutLineVCompound();
3120 if (!aCompound.IsNull ())
3121 {
3122 aBuilder.Add (aHlrShape, aCompound);
3123 }
3124
3125 // create an AIS shape and display it
3126 Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
3127 GetMapOfAIS().Bind (anObject, aHlrName);
3128 aContextAIS->Display (anObject);
3129
3130 aContextAIS->UpdateCurrentViewer ();
3131
3132 return 0;
3133}
3134
9558a876
A
3135// This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
3136// manipulating and displaying such an array with AIS context
3137DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3138class MyPArrayObject : public AIS_InteractiveObject
3139{
3140
3141public:
3142
eb4320f2 3143 MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
a577aaab 3144 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
9558a876 3145 {
eb4320f2 3146 myArrayDescription = theArrayDescription;
a577aaab 3147 myMarkerAspect = theMarkerAspect;
9558a876
A
3148 }
3149
ec357c5c 3150 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
9558a876
A
3151
3152private:
3153
3154 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
3155 const Handle(Prs3d_Presentation)& aPresentation,
3156 const Standard_Integer aMode);
3157
a577aaab 3158 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3159 const Standard_Integer /*theMode*/);
9558a876 3160
eb4320f2 3161 bool CheckInputCommand (const TCollection_AsciiString theCommand,
3162 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3163 Standard_Integer &theArgIndex,
3164 Standard_Integer theArgCount,
3165 Standard_Integer theMaxArgs);
3166
9558a876
A
3167protected:
3168
eb4320f2 3169 Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
a577aaab 3170 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
9558a876
A
3171
3172};
3173
9558a876 3174
35e08fe8 3175void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
9558a876 3176 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 3177 const Standard_Integer /*aMode*/)
9558a876 3178{
9558a876 3179
eb4320f2 3180 // Parsing array description
9558a876 3181 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
871fa103 3182 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3183 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
9558a876 3184
eb4320f2 3185 Standard_Integer anArgIndex = 0;
3186 Standard_Integer anArgsCount = myArrayDescription->Length();
3187 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3188
9558a876 3189 TCollection_AsciiString aCommand;
eb4320f2 3190 while (anArgIndex < anArgsCount)
9558a876 3191 {
eb4320f2 3192 aCommand = myArrayDescription->Value (anArgIndex);
9558a876 3193 aCommand.LowerCase();
9558a876
A
3194
3195 // vertex command
eb4320f2 3196 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3197 {
3198 // vertex has a normal or normal with color or texel
eb4320f2 3199 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3200 hasNormals = Standard_True;
3201
3202 // vertex has a color
eb4320f2 3203 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3204 hasVColors = Standard_True;
3205
3206 // vertex has a texel
eb4320f2 3207 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
9558a876
A
3208 hasTexels = Standard_True;
3209
3210 aVertexNum++;
3211 }
3212 // bound command
eb4320f2 3213 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876
A
3214 {
3215 // bound has color
eb4320f2 3216 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3217 hasBColors = Standard_True;
3218
3219 aBoundNum++;
3220 }
3221 // edge command
eb4320f2 3222 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3223 {
9558a876
A
3224 aEdgeNum++;
3225 }
3226 // unknown command
3227 else
eb4320f2 3228 anArgIndex++;
9558a876
A
3229 }
3230
9558a876
A
3231 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3232 if (anArrayType == "points")
a577aaab 3233 {
9558a876 3234 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
a577aaab 3235 }
9558a876
A
3236 else if (anArrayType == "segments")
3237 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3238 else if (anArrayType == "polylines")
3239 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
871fa103 3240 hasVColors, hasBColors);
9558a876
A
3241 else if (anArrayType == "triangles")
3242 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
871fa103 3243 hasVColors, hasTexels);
9558a876
A
3244 else if (anArrayType == "trianglefans")
3245 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3246 hasNormals, hasVColors,
3247 hasBColors, hasTexels);
3248 else if (anArrayType == "trianglestrips")
3249 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3250 hasNormals, hasVColors,
3251 hasBColors, hasTexels);
3252 else if (anArrayType == "quads")
3253 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3254 hasNormals, hasVColors,
871fa103 3255 hasTexels);
9558a876
A
3256 else if (anArrayType == "quadstrips")
3257 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3258 hasNormals, hasVColors,
3259 hasBColors, hasTexels);
3260 else if (anArrayType == "polygons")
3261 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3262 hasNormals, hasVColors, hasBColors,
871fa103 3263 hasTexels);
9558a876 3264
eb4320f2 3265 anArgIndex = 1;
3266 while (anArgIndex < anArgsCount)
9558a876 3267 {
eb4320f2 3268 aCommand = myArrayDescription->Value (anArgIndex);
9558a876
A
3269 aCommand.LowerCase();
3270 if (!aCommand.IsAscii())
3271 break;
3272
3273 // vertex command
eb4320f2 3274 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3275 {
eb4320f2 3276 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3277 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3278 myArrayDescription->Value (anArgIndex - 1).RealValue());
871fa103 3279 const Standard_Integer aVertIndex = anArray->VertexNumber();
9558a876
A
3280
3281 // vertex has a normal or normal with color or texel
eb4320f2 3282 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3283 anArray->SetVertexNormal (aVertIndex,
eb4320f2 3284 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3285 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3286 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3287
eb4320f2 3288 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3289 anArray->SetVertexColor (aVertIndex,
eb4320f2 3290 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3291 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3292 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3293
eb4320f2 3294 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
871fa103 3295 anArray->SetVertexTexel (aVertIndex,
eb4320f2 3296 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3297 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3298 }
3299 // bounds command
eb4320f2 3300 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3301 {
eb4320f2 3302 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
9558a876 3303
eb4320f2 3304 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3305 anArray->AddBound (aVertCount,
eb4320f2 3306 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3307 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3308 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3309
3310 else
3311 anArray->AddBound (aVertCount);
3312 }
3313 // edge command
eb4320f2 3314 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3315 {
871fa103 3316 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3317 anArray->AddEdge (aVertIndex);
9558a876
A
3318 }
3319 // unknown command
3320 else
eb4320f2 3321 anArgIndex++;
3322 }
3323
3324 aPresentation->Clear();
3325 if (!myMarkerAspect.IsNull())
3326 {
3327 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3328 }
3329 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3330}
3331
3332void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3333 const Standard_Integer /*theMode*/)
3334{
3335 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3336
3337 Standard_Integer anArgIndex = 1;
3338 while (anArgIndex < myArrayDescription->Length())
3339 {
3340 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3341 {
3342 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3343 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3344 myArrayDescription->Value (anArgIndex - 1).RealValue());
3345 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3346 theSelection->Add (aSensetivePoint);
3347 }
3348 else
3349 {
3350 anArgIndex++;
3351 }
3352 }
3353}
3354
3355bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3356 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3357 Standard_Integer &theArgIndex,
3358 Standard_Integer theArgCount,
3359 Standard_Integer theMaxArgs)
3360{
3361 // check if there is more elements than expected
3362 if (theArgIndex >= theMaxArgs)
3363 return false;
3364
3365 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3366 aStrCommand.LowerCase();
3367 if (aStrCommand.Search(theCommand) != 1 ||
3368 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3369 return false;
3370
3371 // go to the first data element
3372 theArgIndex++;
3373
3374 // check data if it can be converted to numeric
3375 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3376 {
3377 aStrCommand = theArgsArray->Value (theArgIndex);
3378 if (!aStrCommand.IsRealValue())
3379 return false;
3380 }
3381
3382 return true;
3383}
3384
3385//=============================================================================
3386//function : VDrawPArray
3387//purpose : Draws primitives array from list of vertexes, bounds, edges
3388//=============================================================================
3389
3390static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3391{
3392 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3393 if (aContextAIS.IsNull())
3394 {
3395 di << "Call vinit before!\n";
3396 return 1;
3397 }
3398 else if (argc < 3)
3399 {
3400 di << "Use: " << argv[0] << " Name TypeOfArray"
3401 << " [vertex] ... [bounds] ... [edges]\n"
3402 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3403 << " trianglefans | trianglestrips | quads |\n"
3404 << " quadstrips | polygons }\n"
3405 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3406 << " [texel={ 't' tx ty }] } \n"
3407 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
871fa103 3408 << " edges={ 'e' vertex_id }\n";
eb4320f2 3409 return 1;
3410 }
3411
3412 // read the arguments
3413 Standard_Integer aArgIndex = 1;
3414 TCollection_AsciiString aName (argv[aArgIndex++]);
3415 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3416
3417 Standard_Boolean hasVertex = Standard_False;
3418
3419 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3420 anArgsArray->SetValue (0, anArrayType);
3421
3422 if (anArrayType != "points" &&
3423 anArrayType != "segments" &&
3424 anArrayType != "polylines" &&
3425 anArrayType != "triangles" &&
3426 anArrayType != "trianglefans" &&
3427 anArrayType != "trianglestrips" &&
3428 anArrayType != "quads" &&
3429 anArrayType != "quadstrips" &&
3430 anArrayType != "polygons")
3431 {
3432 di << "Unexpected type of primitives array\n";
3433 return 1;
3434 }
3435
3436 TCollection_AsciiString aCommand;
3437 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3438 {
3439 aCommand = argv[anArgIndex];
3440 aCommand.LowerCase();
3441 if (!aCommand.IsAscii())
3442 {
3443 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3444 << "should be an array element: 'v', 'b', 'e' \n";
3445 break;
3446 }
3447
3448 if (aCommand == "v")
3449 {
3450 hasVertex = Standard_True;
3451 }
3452
3453 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3454 }
3455
3456 if (!hasVertex)
3457 {
3458 di << "You should pass any verticies in the list of array elements\n";
3459 return 1;
3460 }
3461
3462 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3463 if (anArrayType == "points")
3464 {
3465 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
9558a876
A
3466 }
3467
9558a876 3468 // create primitives array object
eb4320f2 3469 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
9558a876
A
3470
3471 // register the object in map
3472 VDisplayAISObject (aName, aPObject);
3473
3474 return 0;
3475}
3476
29d43f9c
A
3477//=======================================================================
3478//function : VSetLocation
3479//purpose : Change location of AIS interactive object
3480//=======================================================================
3481
0bd2a43f 3482static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
4e18052b 3483 Standard_Integer theArgNb,
3484 const char** theArgVec)
29d43f9c
A
3485{
3486 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4e18052b 3487 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
29d43f9c
A
3488 if (aContext.IsNull())
3489 {
4e18052b 3490 std::cout << "Error: no active view!\n";
29d43f9c
A
3491 return 1;
3492 }
3493
4e18052b 3494 TCollection_AsciiString aName;
3495 gp_Vec aLocVec;
3496 Standard_Boolean isSetLoc = Standard_False;
3497
3498 Standard_Integer anArgIter = 1;
3499 for (; anArgIter < theArgNb; ++anArgIter)
29d43f9c 3500 {
4e18052b 3501 Standard_CString anArg = theArgVec[anArgIter];
3502 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3503 {
3504 continue;
3505 }
3506 else if (aName.IsEmpty())
3507 {
3508 aName = anArg;
3509 }
3510 else if (!isSetLoc)
3511 {
3512 isSetLoc = Standard_True;
3513 if (anArgIter + 1 >= theArgNb)
3514 {
3515 std::cout << "Error: syntax error at '" << anArg << "'\n";
3516 return 1;
3517 }
3518 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3519 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3520 if (anArgIter + 1 < theArgNb)
3521 {
3522 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3523 }
3524 }
3525 else
3526 {
3527 std::cout << "Error: unknown argument '" << anArg << "'\n";
3528 return 1;
3529 }
29d43f9c
A
3530 }
3531
29d43f9c 3532 // find object
4e18052b 3533 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29d43f9c 3534 Handle(AIS_InteractiveObject) anIObj;
4e18052b 3535 if (aMap.IsBound2 (aName))
29d43f9c 3536 {
4e18052b 3537 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
29d43f9c 3538 }
4e18052b 3539 if (anIObj.IsNull())
29d43f9c 3540 {
4e18052b 3541 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3542 return 1;
29d43f9c
A
3543 }
3544
4e18052b 3545 gp_Trsf aTrsf;
3546 aTrsf.SetTranslation (aLocVec);
3547 TopLoc_Location aLocation (aTrsf);
3548 aContext->SetLocation (anIObj, aLocation);
29d43f9c
A
3549 return 0;
3550}
3551
7d9e854b 3552//=======================================================================
3553//function : TransformPresentation
3554//purpose : Change transformation of AIS interactive object
3555//=======================================================================
3556static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
3557 Standard_Integer theArgNb,
3558 const char** theArgVec)
3559{
3560 if (theArgNb <= 1)
3561 {
3562 std::cout << "Error: too few arguments.\n";
3563 return 1;
3564 }
3565
3566 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3567 ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
3568 if (aContext.IsNull())
3569 {
3570 std::cout << "Error: no active view!\n";
3571 return 1;
3572 }
3573
3574 gp_Trsf aTrsf;
3575 Standard_Integer aLast = theArgNb;
3576 const char* aName = theArgVec[0];
3577
3578 Standard_Boolean isReset = Standard_False;
3579 Standard_Boolean isMove = Standard_False;
3580
3581 // Prefix 'vloc'
3582 aName += 4;
3583
3584 if (!strcmp (aName, "reset"))
3585 {
3586 isReset = Standard_True;
3587 }
3588 else if (!strcmp (aName, "move"))
3589 {
3590 if (theArgNb < 3)
3591 {
3592 std::cout << "Error: too few arguments.\n";
3593 return 1;
3594 }
3595
3596 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3597
3598 Handle(AIS_InteractiveObject) anIObj;
3599 if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
3600 {
3601 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
3602 }
3603
3604 if (anIObj.IsNull())
3605 {
3606 std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
3607 return 1;
3608 }
3609
3610 isMove = Standard_True;
3611
3612 aTrsf = anIObj->Transformation();
3613 aLast = theArgNb - 1;
3614 }
3615 else if (!strcmp (aName, "translate"))
3616 {
3617 if (theArgNb < 5)
3618 {
3619 std::cout << "Error: too few arguments.\n";
3620 return 1;
3621 }
3622 aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
3623 Draw::Atof (theArgVec[theArgNb - 2]),
3624 Draw::Atof (theArgVec[theArgNb - 1])));
3625 aLast = theArgNb - 3;
3626 }
3627 else if (!strcmp (aName, "rotate"))
3628 {
3629 if (theArgNb < 9)
3630 {
3631 std::cout << "Error: too few arguments.\n";
3632 return 1;
3633 }
3634
3635 aTrsf.SetRotation (
3636 gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
3637 Draw::Atof (theArgVec[theArgNb - 6]),
3638 Draw::Atof (theArgVec[theArgNb - 5])),
3639 gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
3640 Draw::Atof (theArgVec[theArgNb - 3]),
3641 Draw::Atof (theArgVec[theArgNb - 2]))),
3642 Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
3643
3644 aLast = theArgNb - 7;
3645 }
3646 else if (!strcmp (aName, "mirror"))
3647 {
3648 if (theArgNb < 8)
3649 {
3650 std::cout << "Error: too few arguments.\n";
3651 return 1;
3652 }
3653
3654 aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
3655 Draw::Atof(theArgVec[theArgNb - 5]),
3656 Draw::Atof(theArgVec[theArgNb - 4])),
3657 gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
3658 Draw::Atof(theArgVec[theArgNb - 2]),
3659 Draw::Atof(theArgVec[theArgNb - 1]))));
3660 aLast = theArgNb - 6;
3661 }
3662 else if (!strcmp (aName, "scale"))
3663 {
3664 if (theArgNb < 6)
3665 {
3666 std::cout << "Error: too few arguments.\n";
3667 return 1;
3668 }
3669
3670 aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
3671 Draw::Atof(theArgVec[theArgNb - 3]),
3672 Draw::Atof(theArgVec[theArgNb - 2])),
3673 Draw::Atof(theArgVec[theArgNb - 1]));
3674 aLast = theArgNb - 4;
3675 }
3676
3677 for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
3678 {
3679 // find object
3680 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3681 Handle(AIS_InteractiveObject) anIObj;
3682 if (aMap.IsBound2 (theArgVec[anIdx]))
3683 {
3684 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
3685 }
3686 if (anIObj.IsNull())
3687 {
3688 std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
3689 return 1;
3690 }
3691
3692 if (isReset)
3693 {
3694 // aTrsf already identity
3695 }
3696 else if (isMove)
3697 {
3698 aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
3699 }
3700 else
3701 {
3702 aTrsf = anIObj->LocalTransformation() * aTrsf;
3703 }
3704
3705 TopLoc_Location aLocation (aTrsf);
3706 aContext->SetLocation (anIObj, aLocation);
3707 }
3708
3709 return 0;
3710}
3711
ac04d101
SA
3712//===============================================================================================
3713//function : VConnect
3714//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
0717ddc1 3715//Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
ac04d101
SA
3716//===============================================================================================
3717
0717ddc1 3718static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3719 Standard_Integer argc,
3720 const char ** argv)
ac04d101 3721{
792c785c 3722 // Check the viewer
3723 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3724 if (aContext.IsNull())
ac04d101 3725 {
792c785c 3726 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3727 return 1; // TCL_ERROR
3728 }
792c785c 3729 // Check argumnets
0717ddc1 3730 if (argc < 6)
ac04d101 3731 {
0717ddc1 3732 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3733 return 1; // TCL_ERROR
3734 }
792c785c 3735
3736 // Get values
3737 Standard_Integer anArgIter = 1;
3738 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3739 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
792c785c 3740 TCollection_AsciiString aColorString (argv[argc-1]);
1d47d8d0 3741 Standard_CString aColorName = "";
792c785c 3742 Standard_Boolean hasColor = Standard_False;
3743 if (aColorString.Search ("color=") != -1)
ac04d101 3744 {
792c785c 3745 hasColor = Standard_True;
3746 aColorString.Remove (1, 6);
3747 aColorName = aColorString.ToCString();
3748 }
3749 Handle(AIS_InteractiveObject) anObject;
3750
0717ddc1 3751 // AIS_MultipleConnectedInteractive
3752 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3753 for (Standard_Integer i = 5; i < aNbShapes; ++i)
792c785c 3754 {
0717ddc1 3755 TCollection_AsciiString anOriginObjectName (argv[i]);
792c785c 3756 if (aName.IsEqual (anOriginObjectName))
ac04d101 3757 {
0717ddc1 3758 std::cout << "vconnect error: equal names for connected objects\n";
3759 continue;
ac04d101 3760 }
792c785c 3761 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3762 {
3763 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
0717ddc1 3764 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3765 if (anObject.IsNull())
792c785c 3766 {
3767 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
0717ddc1 3768 continue;
792c785c 3769 }
3770 }
3771 else
3772 {
3773 Standard_CString aName = anOriginObjectName.ToCString();
3774 TopoDS_Shape aTDShape = DBRep::Get (aName);
3775 if (aTDShape.IsNull())
3776 {
3777 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
792c785c 3778 continue;
3779 }
0717ddc1 3780 anObject = new AIS_Shape (aTDShape);
6262338c 3781 aContext->Load (anObject);
0717ddc1 3782 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
792c785c 3783 }
0717ddc1 3784
792c785c 3785 if (anOriginObject.IsNull())
3786 {
0717ddc1 3787 anOriginObject = new AIS_MultipleConnectedInteractive();
792c785c 3788 }
0717ddc1 3789
3790 anOriginObject->Connect (anObject);
3791 }
3792 if (anOriginObject.IsNull())
3793 {
3794 std::cout << "vconect error : can't connect input objects\n";
3795 return 1; // TCL_ERROR
792c785c 3796 }
3797
ac04d101 3798 // Get location data
91322f44 3799 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3800 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3801 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3802
3803 // Create transformation
0717ddc1 3804 gp_Vec aTranslation (aXo, aYo, aZo);
3805
ac04d101 3806 gp_Trsf aTrsf;
0717ddc1 3807 aTrsf.SetTranslationPart (aTranslation);
3808 TopLoc_Location aLocation (aTrsf);
ac04d101 3809
0717ddc1 3810 anOriginObject->SetLocalTransformation (aTrsf);
ac04d101
SA
3811
3812 // Check if there is another object with given name
3813 // and remove it from context
3814 if(GetMapOfAIS().IsBound2(aName))
3815 {
3816 Handle(AIS_InteractiveObject) anObj =
3817 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3818 TheAISContext()->Remove(anObj, Standard_False);
3819 GetMapOfAIS().UnBind2(aName);
3820 }
3821
792c785c 3822 // Bind connected object to its name
0717ddc1 3823 GetMapOfAIS().Bind (anOriginObject, aName);
ac04d101
SA
3824
3825 // Display connected object
0717ddc1 3826 TheAISContext()->Display (anOriginObject);
ac04d101
SA
3827
3828 return 0;
3829}
3830
3831//===============================================================================================
0717ddc1 3832//function : VConnectTo
3833//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
d4aaad5b 3834//Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
ac04d101
SA
3835//===============================================================================================
3836
0717ddc1 3837static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3838 Standard_Integer argc,
3839 const char ** argv)
ac04d101 3840{
792c785c 3841 // Check the viewer
3842 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
d4aaad5b 3843 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
792c785c 3844 if (aContext.IsNull())
ac04d101 3845 {
0717ddc1 3846 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3847 return 1; // TCL_ERROR
3848 }
0717ddc1 3849 // Check argumnets
f751596e 3850 if (argc != 6 && argc != 7)
ac04d101 3851 {
0717ddc1 3852 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3853 return 1; // TCL_ERROR
3854 }
792c785c 3855
3856 // Get values
3857 Standard_Integer anArgIter = 1;
3858 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3859 Handle(AIS_InteractiveObject) anOriginObject;
3860
3861 TCollection_AsciiString anOriginObjectName(argv[5]);
3862 if (aName.IsEqual (anOriginObjectName))
792c785c 3863 {
0717ddc1 3864 std::cout << "vconnect error: equal names for connected objects\n";
3865 return 1; // TCL_ERROR
792c785c 3866 }
0717ddc1 3867 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
ac04d101 3868 {
0717ddc1 3869 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3870 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3871 if (anOriginObject.IsNull())
ac04d101 3872 {
0717ddc1 3873 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
792c785c 3874 return 1; // TCL_ERROR
3875 }
792c785c 3876 }
792c785c 3877 else
3878 {
0717ddc1 3879 Standard_CString aName = anOriginObjectName.ToCString();
3880 TopoDS_Shape aTDShape = DBRep::Get (aName);
3881 if (aTDShape.IsNull())
792c785c 3882 {
0717ddc1 3883 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
ac04d101
SA
3884 return 1; // TCL_ERROR
3885 }
0717ddc1 3886 anOriginObject = new AIS_Shape (aTDShape);
f751596e 3887 GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
ac04d101 3888 }
0717ddc1 3889
3890 // Get location data
91322f44 3891 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3892 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3893 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3894
3895 // Create transformation
0717ddc1 3896 gp_Vec aTranslation (aXo, aYo, aZo);
ac04d101 3897
0717ddc1 3898 gp_Trsf aTrsf;
3899 aTrsf.SetTranslationPart (aTranslation);
3900
792c785c 3901 Handle(AIS_ConnectedInteractive) aConnected;
0717ddc1 3902
3903 aConnected = new AIS_ConnectedInteractive();
3904
3905 aConnected->Connect (anOriginObject, aTrsf);
ac04d101
SA
3906
3907 // Check if there is another object with given name
3908 // and remove it from context
3909 if(GetMapOfAIS().IsBound2(aName))
3910 {
3911 Handle(AIS_InteractiveObject) anObj =
3912 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3913 TheAISContext()->Remove(anObj, Standard_False);
3914 GetMapOfAIS().UnBind2(aName);
3915 }
3916
0717ddc1 3917 // Bind connected object to its name
792c785c 3918 GetMapOfAIS().Bind (aConnected, aName);
ac04d101 3919
f751596e 3920 if (argc == 7)
3921 {
3922 TCollection_AsciiString anArg = argv[6];
3923 anArg.LowerCase();
3924 if (anArg == "-nodisplay")
3925 return 0;
d4aaad5b 3926
3927 if (!anUpdateTool.parseRedrawMode (anArg))
3928 {
3929 std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
3930 }
f751596e 3931 }
3932
0717ddc1 3933 // Display connected object
d4aaad5b 3934 TheAISContext()->Display (aConnected, Standard_False);
ac04d101
SA
3935
3936 return 0;
3937}
3938
0717ddc1 3939//=======================================================================
3940//function : VDisconnect
3941//purpose :
3942//=======================================================================
3943static Standard_Integer VDisconnect (Draw_Interpretor& di,
3944 Standard_Integer argc,
3945 const char ** argv)
3946{
3947 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3948 if (aContext.IsNull())
3949 {
3950 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3951 return 1;
3952 }
3953
3954 if (argc != 3)
3955 {
3956 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
3957 return 1;
3958 }
3959
3960 TCollection_AsciiString aName (argv[1]);
3961 TCollection_AsciiString anObject (argv[2]);
3962 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
3963
3964 // find objects
3965 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3966 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3967 if (!aMap.IsBound2 (aName) )
3968 {
3969 std::cout << "Use 'vdisplay' before" << "\n";
3970 return 1;
3971 }
3972
3973 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3974 if (anAssembly.IsNull())
3975 {
3976 di << "Not an assembly" << "\n";
3977 return 1;
3978 }
3979
3980 Handle(AIS_InteractiveObject) anIObj;
3981 if (!aMap.IsBound2 (anObject))
3982 {
3983 // try to interpret second argument as child number
3984 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
3985 {
3986 Standard_Integer aCounter = 1;
3987 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3988 {
3989 if (aCounter == anObjectNumber)
3990 {
3991 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
3992 break;
3993 }
3994 ++aCounter;
3995 }
3996 }
3997 else
3998 {
3999 std::cout << "Use 'vdisplay' before" << "\n";
4000 return 1;
4001 }
4002 }
4003
4004 // if object was found by name
4005 if (anIObj.IsNull())
4006 {
4007 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4008 }
4009
f751596e 4010 aContext->Disconnect (anAssembly, anIObj);
0717ddc1 4011 aContext->UpdateCurrentViewer();
4012
4013 return 0;
4014}
4015
4016//=======================================================================
4017//function : VAddConnected
4018//purpose :
4019//=======================================================================
4020static Standard_Integer VAddConnected (Draw_Interpretor& di,
4021 Standard_Integer argc,
4022 const char ** argv)
4023{
4024 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4025 if (aContext.IsNull())
4026 {
4027 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
4028 return 1;
4029 }
4030
4031 if (argc != 6)
4032 {
4033 std::cout << argv[0] << " error: expect 5 arguments\n";
4034 return 1;
4035 }
4036
4037 TCollection_AsciiString aName (argv[1]);
4038 TCollection_AsciiString anObject (argv[5]);
4039 Standard_Real aX = Draw::Atof (argv[2]);
4040 Standard_Real aY = Draw::Atof (argv[3]);
4041 Standard_Real aZ = Draw::Atof (argv[4]);
4042
4043 // find object
4044 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4045 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4046 if (!aMap.IsBound2 (aName) )
4047 {
4048 std::cout << "Use 'vdisplay' before" << "\n";
4049 return 1;
4050 }
4051
4052 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4053 if (anAssembly.IsNull())
4054 {
4055 di << "Not an assembly" << "\n";
4056 return 1;
4057 }
4058
4059 Handle(AIS_InteractiveObject) anIObj;
4060 if (!aMap.IsBound2 (anObject))
4061 {
4062 std::cout << "Use 'vdisplay' before" << "\n";
4063 return 1;
4064 }
4065
4066 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
4067
4068 gp_Trsf aTrsf;
4069 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
4070
4071 anAssembly->Connect (anIObj, aTrsf);
4072 TheAISContext()->Display (anAssembly);
4073 TheAISContext()->RecomputeSelectionOnly (anAssembly);
4074 aContext->UpdateCurrentViewer();
4075
4076 return 0;
4077}
4078
4079//=======================================================================
4080//function : VListConnected
4081//purpose :
4082//=======================================================================
0bd2a43f 4083static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
0717ddc1 4084 Standard_Integer argc,
4085 const char ** argv)
4086{
4087 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4088 if (aContext.IsNull())
4089 {
4090 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
4091 return 1;
4092 }
4093
4094 if (argc != 2)
4095 {
4096 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
4097 return 1;
4098 }
4099
4100 TCollection_AsciiString aName (argv[1]);
4101
4102 // find object
4103 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4104 Handle(AIS_MultipleConnectedInteractive) anAssembly;
4105 if (!aMap.IsBound2 (aName) )
4106 {
4107 std::cout << "Use 'vdisplay' before" << "\n";
4108 return 1;
4109 }
4110
4111 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
4112 if (anAssembly.IsNull())
4113 {
4114 std::cout << "Not an assembly" << "\n";
4115 return 1;
4116 }
4117
4118 std::cout << "Children of " << aName << ":\n";
4119
4120 Standard_Integer aCounter = 1;
4121 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
4122 {
4123 if (GetMapOfAIS().IsBound1 (anIter.Value()))
4124 {
4125 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
4126 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
4127 }
4128
4129 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
4130
4131 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
4132 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
4133 {
4134 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
4135 }
4136 std::cout << std::endl;
4137
4138 ++aCounter;
4139 }
4140
4141 return 0;
4142}
4143
9f37b47d 4144namespace
4145{
4146 //! Checks if theMode is already turned on for theObj.
4147 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
4148 const Handle(AIS_InteractiveObject)& theObj,
4149 const Standard_Integer theMode)
4150 {
4151 TColStd_ListOfInteger anActiveModes;
4152 theAISContext->ActivatedModes (theObj, anActiveModes);
4153 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
4154 {
4155 if (aModeIt.Value() == theMode)
4156 {
4157 return Standard_True;
4158 }
4159 }
4160 return Standard_False;
4161 }
4162};
4163
ac04d101
SA
4164//===============================================================================================
4165//function : VSetSelectionMode
4166//purpose : Sets input selection mode for input object or for all displayed objects
4167//Draw arg : vselmode [object] mode On/Off (1/0)
4168//===============================================================================================
9f37b47d 4169static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
4170 Standard_Integer theArgc,
4171 const char** theArgv)
ac04d101
SA
4172{
4173 // Check errors
4174 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
9f37b47d 4175 if (anAISContext.IsNull())
ac04d101 4176 {
709e97a0 4177 std::cerr << "Call vinit before!" << std::endl;
9f37b47d 4178 return 1;
ac04d101
SA
4179 }
4180
9f37b47d 4181 // Check the arguments
4182 if (theArgc != 3 && theArgc != 4)
ac04d101 4183 {
9f37b47d 4184 std::cerr << "vselmode error : expects at least 2 arguments.\n"
709e97a0 4185 << "Type help "<< theArgv[0] <<" for more information." << std::endl;
9f37b47d 4186 return 1;
ac04d101
SA
4187 }
4188
9f37b47d 4189 // get objects to change selection mode
4190 AIS_ListOfInteractive aTargetIOs;
4191 if (theArgc == 3)
ac04d101 4192 {
9f37b47d 4193 anAISContext->DisplayedObjects (aTargetIOs);
4194 }
4195 else
4196 {
4197 // Check if there is an object with given name in context
4198 const TCollection_AsciiString aNameIO (theArgv[1]);
4199 if (GetMapOfAIS().IsBound2 (aNameIO))
ac04d101 4200 {
9f37b47d 4201 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4202 if (anIO.IsNull())
ac04d101 4203 {
709e97a0 4204 std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
9f37b47d 4205 return 1;
ac04d101 4206 }
9f37b47d 4207 aTargetIOs.Append (anIO);
ac04d101 4208 }
9f37b47d 4209 }
ac04d101 4210
9f37b47d 4211 const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]);
4212 const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]);
4213 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4214 {
4215 anAISContext->CloseLocalContext();
ac04d101
SA
4216 }
4217
709e97a0 4218 if (aSelectionMode == 0)
4219 {
4220 if (toTurnOn)
4221 {
4222 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4223 {
4224 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4225 if (!InList (anAISContext, anIO, aSelectionMode))
4226 {
4227 anAISContext->Activate (anIO);
4228 }
4229 }
4230 }
4231 else
4232 {
4233 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
4234 {
4235 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4236 if (InList (anAISContext, anIO, aSelectionMode))
4237 {
4238 anAISContext->Deactivate (anIO);
4239 }
4240 }
4241 }
4242 }
4243
9f37b47d 4244 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
ac04d101 4245 {
9f37b47d 4246 if (!anAISContext->HasOpenedContext())
4247 {
4248 anAISContext->OpenLocalContext (Standard_False);
4249 }
ac04d101 4250
9f37b47d 4251 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4252 {
9f37b47d 4253 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4254 if (!InList (anAISContext, anIO, aSelectionMode))
ac04d101 4255 {
9f37b47d 4256 anAISContext->Load (anIO, -1, Standard_True);
4257 anAISContext->Activate (anIO, aSelectionMode);
ac04d101
SA
4258 }
4259 }
9f37b47d 4260 }
ac04d101 4261
9f37b47d 4262 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4263 {
4264 if (!anAISContext->HasOpenedContext())
ac04d101 4265 {
9f37b47d 4266 return 0;
ac04d101
SA
4267 }
4268
9f37b47d 4269 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4270 {
9f37b47d 4271 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4272 if (InList (anAISContext, anIO, aSelectionMode))
ac04d101 4273 {
9f37b47d 4274 anAISContext->Deactivate (anIO, aSelectionMode);
ac04d101
SA
4275 }
4276 }
4277 }
9f37b47d 4278
ac04d101
SA
4279 return 0;
4280}
4281
4ca4bbe8 4282//===============================================================================================
4283//function : VSelectionNext
4284//purpose :
4285//===============================================================================================
4286static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
4287 Standard_Integer /*theArgsNb*/,
4288 const char** /*theArgVec*/)
4289{
4290 // Check errors
4291 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4292 Handle(V3d_View) aView = ViewerTest::CurrentView();
4293
4294 if (anAISContext.IsNull())
4295 {
4296 std::cerr << "Call vinit before!" << std::endl;
4297 return 1;
4298 }
4299
4300 anAISContext->HilightNextDetected(aView);
4301 return 0;
4302}
4303
4304//===============================================================================================
4305//function : VSelectionPrevious
4306//purpose :
4307//===============================================================================================
4308static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
4309 Standard_Integer /*theArgsNb*/,
4310 const char** /*theArgVec*/)
4311{
4312 // Check errors
4313 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4314 Handle(V3d_View) aView = ViewerTest::CurrentView();
4315
4316 if (anAISContext.IsNull())
4317 {
4318 std::cerr << "Call vinit before!" << std::endl;
4319 return 1;
4320 }
4321
4322 anAISContext->HilightPreviousDetected(aView);
4323 return 0;
4324}
4325
4326
ceae62f0
A
4327//==========================================================================
4328//class : Triangle
4329//purpose : creates Triangle based on AIS_InteractiveObject.
4330// This class was implemented for testing Select3D_SensitiveTriangle
4331//===========================================================================
4332DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4333class Triangle: public AIS_InteractiveObject
4334{
4335public:
4336 // CASCADE RTTI
ec357c5c 4337 DEFINE_STANDARD_RTTI(Triangle, AIS_InteractiveObject);
ceae62f0
A
4338 Triangle (const gp_Pnt& theP1,
4339 const gp_Pnt& theP2,
4340 const gp_Pnt& theP3);
4341protected:
4342 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4343 const Handle(Prs3d_Presentation)& thePresentation,
4344 const Standard_Integer theMode);
4345
4346 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4347 const Standard_Integer theMode);
4348private:
4349 gp_Pnt myPoint1;
4350 gp_Pnt myPoint2;
4351 gp_Pnt myPoint3;
4352};
ec357c5c 4353
ceae62f0
A
4354
4355Triangle::Triangle (const gp_Pnt& theP1,
4356 const gp_Pnt& theP2,
4357 const gp_Pnt& theP3)
4358{
4359 myPoint1 = theP1;
4360 myPoint2 = theP2;
4361 myPoint3 = theP3;
4362}
4363
35e08fe8 4364void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
ceae62f0 4365 const Handle(Prs3d_Presentation)& thePresentation,
35e08fe8 4366 const Standard_Integer /*theMode*/)
ceae62f0
A
4367{
4368 thePresentation->Clear();
4369
4370 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4371 anEdgeMaker2(myPoint2, myPoint3),
4372 anEdgeMaker3(myPoint3, myPoint1);
4373
4374 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4375 anEdge2 = anEdgeMaker2.Edge(),
4376 anEdge3 = anEdgeMaker3.Edge();
4377 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4378 return;
4379
4380 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4381 TopoDS_Wire aWire = aWireMaker.Wire();
4382 if(aWire.IsNull()) return;
4383
4384 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4385 TopoDS_Face aFace = aFaceMaker.Face();
4386 if(aFace.IsNull()) return;
4387
4388 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4389}
4390
4391void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
35e08fe8 4392 const Standard_Integer /*theMode*/)
ceae62f0
A
4393{
4394 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4395 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4396 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4397 theSelection->Add(aSensTriangle);
4398}
4399
4400//===========================================================================
4401//function : VTriangle
4402//Draw arg : vtriangle Name PointName PointName PointName
4403//purpose : creates and displays Triangle
4404//===========================================================================
4405
4406//function: IsPoint
4407//purpose : checks if the object with theName is AIS_Point,
4408// if yes initialize thePoint from MapOfAIS
4409Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4410 Handle(AIS_Point)& thePoint)
4411{
4412 Handle(AIS_InteractiveObject) anObject =
4413 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4414 if(anObject.IsNull() ||
4415 anObject->Type() != AIS_KOI_Datum ||
4416 anObject->Signature() != 1)
4417 {
4418 return Standard_False;
4419 }
4420 thePoint = Handle(AIS_Point)::DownCast(anObject);
4421 if(thePoint.IsNull())
4422 return Standard_False;
4423 return Standard_True;
4424}
4425
4426//function: IsMatch
4427//purpose: checks if thePoint1 is equal to thePoint2
4428Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4429 const Handle(Geom_CartesianPoint)& thePoint2)
4430{
91322f44 4431 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4432 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4433 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
ceae62f0
A
4434 {
4435 return Standard_True;
4436 }
4437 return Standard_False;
4438}
4439
35e08fe8 4440static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
ceae62f0
A
4441 Standard_Integer argc,
4442 const char ** argv)
4443{
4444 // Check arguments
4445 if (argc != 5)
4446 {
4447 std::cout<<"vtriangle error: expects 4 argumnets\n";
4448 return 1; // TCL_ERROR
4449 }
4450
4451 TheAISContext()->CloseAllContexts();
4452
4453 // Get and check values
4454 TCollection_AsciiString aName(argv[1]);
4455
4456 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4457 if (!IsPoint(argv[2], aPoint1))
4458 {
4459 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4460 return 1; // TCL_ERROR
4461 }
4462 if (!IsPoint(argv[3], aPoint2))
4463 {
4464 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4465 return 1; // TCL_ERROR
4466 }
4467 if (!IsPoint(argv[4], aPoint3))
4468 {
4469 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4470 return 1; // TCL_ERROR
4471 }
4472
4473 // Check that points are different
4474 Handle(Geom_CartesianPoint) aCartPoint1 =
4475 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4476 Handle(Geom_CartesianPoint) aCartPoint2 =
4477 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4478 // Test aPoint1 = aPoint2
4479 if (IsMatch(aCartPoint1, aCartPoint2))
4480 {
4481 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4482 return 1; // TCL_ERROR
4483 }
4484 // Test aPoint2 = aPoint3
4485 Handle(Geom_CartesianPoint) aCartPoint3 =
4486 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4487 if (IsMatch(aCartPoint2, aCartPoint3))
4488 {
4489 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4490 return 1; // TCL_ERROR
4491 }
4492 // Test aPoint3 = aPoint1
4493 if (IsMatch(aCartPoint1, aCartPoint3))
4494 {
4495 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4496 return 1; // TCL_ERROR
4497 }
4498
4499 // Create triangle
4500 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4501 aCartPoint2->Pnt(),
4502 aCartPoint3->Pnt());
4503
4504 // Check if there is an object with given name
4505 // and remove it from context
4506 if (GetMapOfAIS().IsBound2(aName))
4507 {
4508 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4509 Handle(AIS_InteractiveObject) anInterObj =
4510 Handle(AIS_InteractiveObject)::DownCast(anObj);
4511 TheAISContext()->Remove(anInterObj, Standard_False);
4512 GetMapOfAIS().UnBind2(aName);
4513 }
4514
4515 // Bind triangle to its name
4516 GetMapOfAIS().Bind(aTriangle, aName);
4517
4518 // Display triangle
4519 TheAISContext()->Display(aTriangle);
4520 return 0;
4521}
4522
4523//class : SegmentObject
4524//purpose: creates segment based on AIS_InteractiveObject.
4525// This class was implemented for testing Select3D_SensitiveCurve
4526DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4527class SegmentObject: public AIS_InteractiveObject
4528{
4529public:
4530 // CASCADE RTTI
ec357c5c 4531 DEFINE_STANDARD_RTTI(SegmentObject, AIS_InteractiveObject);
ceae62f0
A
4532 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4533protected:
4534 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4535 const Handle(Prs3d_Presentation)& thePresentation,
4536 const Standard_Integer theMode);
4537
4538 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4539 const Standard_Integer theMode);
4540private:
4541 gp_Pnt myPoint1;
4542 gp_Pnt myPoint2;
4543};
ec357c5c 4544
ceae62f0
A
4545
4546SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4547{
4548 myPoint1 = thePnt1;
4549 myPoint2 = thePnt2;
4550}
4551
857ffd5e 4552void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4553 const Handle(Prs3d_Presentation) &thePresentation,
35e08fe8 4554 const Standard_Integer /*theMode*/)
ceae62f0
A
4555{
4556 thePresentation->Clear();
4557 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4558 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4559 if (anEdge.IsNull())
4560 return;
4561 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4562 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4563}
4564
857ffd5e 4565void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 4566 const Standard_Integer /*theMode*/)
ceae62f0
A
4567{
4568 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4569 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4570 anArray->SetValue(1, myPoint1);
4571 anArray->SetValue(2, myPoint2);
4572 Handle(Select3D_SensitiveCurve) aSensCurve =
4573 new Select3D_SensitiveCurve(anOwner, anArray);
4574 theSelection->Add(aSensCurve);
4575}
4576
4577//=======================================================================
4578//function : VSegment
4579//Draw args : vsegment Name PointName PointName
4580//purpose : creates and displays Segment
4581//=======================================================================
35e08fe8 4582static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
ceae62f0
A
4583 Standard_Integer argc,
4584 const char ** argv)
4585{
4586 // Check arguments
4587 if(argc!=4)
4588 {
4589 std::cout<<"vsegment error: expects 3 arguments\n";
4590 return 1; // TCL_ERROR
4591 }
4592
4593 TheAISContext()->CloseAllContexts();
4594
4595 // Get and check arguments
4596 TCollection_AsciiString aName(argv[1]);
4597 Handle(AIS_Point) aPoint1, aPoint2;
4598 if (!IsPoint(argv[2], aPoint1))
4599 {
4600 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4601 return 1; // TCL_ERROR
4602 }
4603 if (!IsPoint(argv[3], aPoint2))
4604 {
4605 std::cout<<"vsegment error: the 3d argument should be a point\n";
4606 return 1; // TCL_ERROR
4607 }
4608 //Check that points are different
4609 Handle(Geom_CartesianPoint) aCartPoint1 =
4610 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4611 Handle(Geom_CartesianPoint) aCartPoint2 =
4612 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4613 if(IsMatch(aCartPoint1, aCartPoint2))
4614 {
4615 std::cout<<"vsegment error: equal points\n";
4616 return 1; // TCL_ERROR
4617 }
4618
4619 // Create segment
4620 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4621 // Check if there is an object with given name
4622 // and remove it from context
4623 if (GetMapOfAIS().IsBound2(aName))
4624 {
4625 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4626 Handle(AIS_InteractiveObject) anInterObj =
4627 Handle(AIS_InteractiveObject)::DownCast(anObj);
4628 TheAISContext()->Remove(anInterObj, Standard_False);
4629 GetMapOfAIS().UnBind2(aName);
4630 }
4631
4632 // Bind segment to its name
4633 GetMapOfAIS().Bind(aSegment, aName);
4634
4635 // Display segment
4636 TheAISContext()->Display(aSegment);
4637 return 0;
4638}
4639
59f45b7c 4640//=======================================================================
4641//function : VObjZLayer
4642//purpose : Set or get z layer id for presentable object
4643//=======================================================================
4644
4645static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4646 Standard_Integer argc,
4647 const char ** argv)
4648{
4649 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4650 if (aContext.IsNull())
4651 {
4652 di << argv[0] << "Call 'vinit' before!\n";
4653 return 1;
4654 }
4655
4656 // get operation
4657 TCollection_AsciiString aOperation;
4658 if (argc >= 2)
4659 aOperation = TCollection_AsciiString (argv [1]);
4660
4661 // check for correct arguments
4662 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4663 !(argc == 3 && aOperation.IsEqual ("get")))
4664 {
4665 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4666 di << " set - set layer id for interactive object, layerid - z layer id\n";
4667 di << " get - get layer id of interactive object\n";
4668 di << " argument layerid should be passed for set operation only\n";
4669 return 1;
4670 }
4671
4672 // find object
4673 TCollection_AsciiString aName (argv[2]);
4674 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4675 if (!aMap.IsBound2 (aName))
4676 {
4677 di << "Use 'vdisplay' before" << "\n";
4678 return 1;
4679 }
4680
4681 // find interactive object
4682 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4683 Handle(AIS_InteractiveObject) anInterObj =
4684 Handle(AIS_InteractiveObject)::DownCast (anObj);
4685 if (anInterObj.IsNull())
4686 {
4687 di << "Not an AIS interactive object!\n";
4688 return 1;
4689 }
4690
4691 // process operation
4692 if (aOperation.IsEqual ("set"))
4693 {
91322f44 4694 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
59f45b7c 4695 aContext->SetZLayer (anInterObj, aLayerId);
4696 }
4697 else if (aOperation.IsEqual ("get"))
4698 {
4699 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4700 }
4701
4702 return 0;
4703}
4704
3ddebf91 4705//=======================================================================
4706//function : VPolygonOffset
4707//purpose : Set or get polygon offset parameters
4708//=======================================================================
35e08fe8 4709static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
3ddebf91 4710 Standard_Integer argc,
4711 const char ** argv)
4712{
4713 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4714 if (aContext.IsNull())
4715 {
4716 std::cout << argv[0] << " Call 'vinit' before!\n";
4717 return 1;
4718 }
4719
4720 if (argc > 2 && argc != 5)
4721 {
4722 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4723 "without arguments prints the default values" << std::endl;
4724 return 1;
4725 }
4726
4727 // find object
4728 Handle(AIS_InteractiveObject) anInterObj;
4729 if (argc >= 2)
4730 {
4731 TCollection_AsciiString aName (argv[1]);
4732 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4733 if (!aMap.IsBound2 (aName))
4734 {
4735 std::cout << "Use 'vdisplay' before" << std::endl;
4736 return 1;
4737 }
4738
4739 // find interactive object
4740 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4741 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4742 if (anInterObj.IsNull())
4743 {
4744 std::cout << "Not an AIS interactive object!" << std::endl;
4745 return 1;
4746 }
4747 }
4748
4749 Standard_Integer aMode;
60be1f9b 4750 Standard_ShortReal aFactor, aUnits;
3ddebf91 4751 if (argc == 5)
4752 {
91322f44 4753 aMode = Draw::Atoi(argv[2]);
4754 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4755 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
3ddebf91 4756
4757 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4758 aContext->UpdateCurrentViewer();
4759 return 0;
4760 }
4761 else if (argc == 2)
4762 {
4763 if (anInterObj->HasPolygonOffsets())
4764 {
4765 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4766 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4767 std::cout << "\tMode: " << aMode << std::endl;
4768 std::cout << "\tFactor: " << aFactor << std::endl;
4769 std::cout << "\tUnits: " << aUnits << std::endl;
4770 return 0;
4771 }
4772 else
4773 {
4774 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4775 }
4776 }
4777
4778 std::cout << "Default polygon offset parameters:" << std::endl;
4779 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4780 std::cout << "\tMode: " << aMode << std::endl;
4781 std::cout << "\tFactor: " << aFactor << std::endl;
4782 std::cout << "\tUnits: " << aUnits << std::endl;
4783
4784 return 0;
4785}
4786
a2d5ab2e 4787//=======================================================================
4788//function : VShowFaceBoundaries
4789//purpose : Set face boundaries drawing on/off for ais object
4790//=======================================================================
35e08fe8 4791static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
a2d5ab2e 4792 Standard_Integer argc,
4793 const char ** argv)
4794{
4795 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4796 if (aContext.IsNull ())
4797 {
4798 std::cout << argv[0] << " Call 'vinit' before!\n";
4799 return 1;
4800 }
4801
4802 if ((argc != 3 && argc < 6) || argc > 8)
4803 {
4804 std::cout << "Usage :\n " << argv[0]
4805 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4806 << " ObjectName - name of AIS interactive object. \n"
4807 << " if ObjectName = \"\", then set as default\n"
4808 << " settings for all newly displayed objects\n"
4809 << " isOn - flag indicating whether the boundaries\n"
4810 << " should be turned on or off (can be set\n"
4811 << " to 0 (off) or 1 (on)).\n"
4812 << " R, G, B - red, green and blue components of boundary\n"
4813 << " color in range (0 - 255).\n"
4814 << " (default is (0, 0, 0)\n"
4815 << " LineWidth - line width\n"
4816 << " (default is 1)\n"
4817 << " LineStyle - line fill style :\n"
4818 << " 0 - solid \n"
4819 << " 1 - dashed \n"
4820 << " 2 - dot \n"
4821 << " 3 - dashdot\n"
4822 << " (default is solid)";
4823 return 1;
4824 }
4825
4826 TCollection_AsciiString aName (argv[1]);
4827
4828 Quantity_Parameter aRed = 0.0;
4829 Quantity_Parameter aGreen = 0.0;
4830 Quantity_Parameter aBlue = 0.0;
4831 Standard_Real aWidth = 1.0;
4832 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4833
4834 // find object
4835 Handle(AIS_InteractiveObject) anInterObj;
4836
4837 // if name is empty - apply attributes for default aspect
4838 if (!aName.IsEmpty ())
4839 {
4840 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4841 if (!aMap.IsBound2 (aName))
4842 {
4843 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4844 return 1;
4845 }
4846
4847 // find interactive object
4848 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4849 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4850 if (anInterObj.IsNull ())
4851 {
4852 std::cout << "Not an AIS interactive object!" << std::endl;
4853 return 1;
4854 }
4855 }
4856
4857 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4858 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4859
4860 // turn boundaries on/off
91322f44 4861 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
a2d5ab2e 4862 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4863
4864 // set boundary line color
4865 if (argc >= 6)
4866 {
4867 // Text color
91322f44 4868 aRed = Draw::Atof (argv[3])/255.;
4869 aGreen = Draw::Atof (argv[4])/255.;
4870 aBlue = Draw::Atof (argv[5])/255.;
a2d5ab2e 4871 }
4872
4873 // set line width
4874 if (argc >= 7)
4875 {
91322f44 4876 aWidth = (Standard_Real)Draw::Atof (argv[6]);
a2d5ab2e 4877 }
4878
4879 // select appropriate line type
4880 if (argc == 8)
4881 {
91322f44 4882 switch (Draw::Atoi (argv[7]))
a2d5ab2e 4883 {
4884 case 1: aLineType = Aspect_TOL_DASH; break;
4885 case 2: aLineType = Aspect_TOL_DOT; break;
4886 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4887 default:
4888 aLineType = Aspect_TOL_SOLID;
4889 }
4890 }
4891
4892 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4893
4894 Handle(Prs3d_LineAspect) aBoundaryAspect =
4895 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4896
4897 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4898
4899 TheAISContext()->Redisplay (anInterObj);
4900
4901 return 0;
4902}
4903
eb4320f2 4904// This class is used for testing markers.
4905DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4906class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4907{
4908
4909public:
4910
4911 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4912 const Standard_Integer& thePointsOnSide,
4913 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4914 {
4915 myStartPoint = theStartPoint;
4916 myPointsOnSide = thePointsOnSide;
4917 myMarkerAspect = theMarkerAspect;
4918 }
4919
ec357c5c 4920 DEFINE_STANDARD_RTTI(MyPArrayObject, AIS_InteractiveObject);
eb4320f2 4921
4922private:
4923
4924 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4925 const Handle(Prs3d_Presentation)& aPresentation,
4926 const Standard_Integer aMode);
4927
4928 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4929 const Standard_Integer /*theMode*/);
4930
4931protected:
4932
4933 gp_XYZ myStartPoint;
4934 Standard_Integer myPointsOnSide;
4935 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4936};
4937
eb4320f2 4938
4939void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4940 const Handle(Prs3d_Presentation)& aPresentation,
4941 const Standard_Integer /*aMode*/)
4942{
4943 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4944 if (myPointsOnSide == 1)
4945 {
4946 anArray->AddVertex (myStartPoint);
4947 }
4948 else
4949 {
4950 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4951 {
4952 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4953 {
4954 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4955 {
4956 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4957 anArray->SetVertexColor (anArray->VertexNumber(),
4958 i / myPointsOnSide,
4959 j / myPointsOnSide,
4960 k / myPointsOnSide);
4961 }
4962 }
4963 }
4964 }
4965
4966 aPresentation->Clear();
4967 if (!myMarkerAspect.IsNull())
4968 {
4969 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4970 }
4971 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4972}
4973
4974void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4975 const Standard_Integer /*theMode*/)
4976{
4977 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4978
4979 if (myPointsOnSide == 1)
4980 {
4981 gp_Pnt aPoint (myStartPoint);
4982 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4983 theSelection->Add (aSensetivePoint);
4984 }
4985 else
4986 {
4987 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4988 {
4989 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4990 {
4991 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4992 {
4993 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4994 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4995 theSelection->Add (aSensetivePoint);
4996 }
4997 }
4998 }
4999 }
5000}
a577aaab 5001//=======================================================================
5002//function : VMarkersTest
5003//purpose : Draws an array of markers for testing purposes.
5004//=======================================================================
498ce76b 5005static Standard_Integer VMarkersTest (Draw_Interpretor&,
a577aaab 5006 Standard_Integer theArgNb,
5007 const char** theArgVec)
5008{
5009 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5010 if (aContext.IsNull())
5011 {
5012 std::cerr << "Call 'vinit' before!\n";
5013 return 1;
5014 }
5015
5016 if (theArgNb < 5)
5017 {
5018 std::cerr << "Usage :\n " << theArgVec[0]
5019 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
5020 return 1;
5021 }
5022
5023 Standard_Integer anArgIter = 1;
5024
5025 TCollection_AsciiString aName (theArgVec[anArgIter++]);
5026 TCollection_AsciiString aFileName;
5027 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
5028 Atof (theArgVec[anArgIter + 1]),
5029 Atof (theArgVec[anArgIter + 2]));
5030 anArgIter += 3;
5031
5032 Standard_Integer aPointsOnSide = 10;
5033 Standard_Integer aMarkerType = -1;
5034 Standard_Real aScale = 1.0;
5035 for (; anArgIter < theArgNb; ++anArgIter)
5036 {
5037 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5038 if (anArg.Search ("PointsOnSide=") > -1)
5039 {
5040 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
5041 }
5042 else if (anArg.Search ("MarkerType=") > -1)
5043 {
5044 aMarkerType = anArg.Token ("=", 2).IntegerValue();
5045 }
5046 else if (anArg.Search ("Scale=") > -1)
5047 {
5048 aScale = anArg.Token ("=", 2).RealValue();
5049 }
5050 else if (anArg.Search ("FileName=") > -1)
5051 {
5052 aFileName = anArg.Token ("=", 2);
5053 }
5054 else
5055 {
5056 std::cerr << "Wrong argument: " << anArg << "\n";
5057 return 1;
5058 }
5059 }
5060
5061 Handle(Graphic3d_AspectMarker3d) anAspect;
5062 Handle(Image_AlienPixMap) anImage;
5063 Quantity_Color aColor (Quantity_NOC_GREEN1);
5064 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
5065 && !aFileName.IsEmpty())
5066 {
5067 anImage = new Image_AlienPixMap();
5068 if (!anImage->Load (aFileName))
5069 {
5070 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
5071 return 1;
5072 }
076ca35c 5073 if (anImage->Format() == Image_PixMap::ImgGray)
5074 {
5075 anImage->SetFormat (Image_PixMap::ImgAlpha);
5076 }
5077 else if (anImage->Format() == Image_PixMap::ImgGrayF)
5078 {
5079 anImage->SetFormat (Image_PixMap::ImgAlphaF);
5080 }
a577aaab 5081 anAspect = new Graphic3d_AspectMarker3d (anImage);
5082 }
5083 else
5084 {
5085 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
5086 }
5087
eb4320f2 5088 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
5089 VDisplayAISObject (aName, aMarkersArray);
a577aaab 5090
5091 return 0;
5092}
5093
725ef85e 5094//! Auxiliary function to parse font aspect style argument
5095static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
5096 Font_FontAspect& theAspect)
5097{
5098 if (theArg == "regular"
5099 || *theArg.ToCString() == 'r')
5100 {
5101 theAspect = Font_FA_Regular;
5102 return Standard_True;
5103 }
5104 else if (theArg == "bolditalic")
5105 {
5106 theAspect = Font_FA_BoldItalic;
5107 return Standard_True;
5108 }
5109 else if (theArg == "bold"
5110 || *theArg.ToCString() == 'b')
5111 {
5112 theAspect = Font_FA_Bold;
5113 return Standard_True;
5114 }
5115 else if (theArg == "italic"
5116 || *theArg.ToCString() == 'i')
5117 {
5118 theAspect = Font_FA_Italic;
5119 return Standard_True;
5120 }
5121 return Standard_False;
5122}
5123
5124//! Auxiliary function
5125static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
5126{
5127 switch (theAspect)
5128 {
5129 case Font_FA_Regular: return "regular";
5130 case Font_FA_BoldItalic: return "bolditalic";
5131 case Font_FA_Bold: return "bold";
5132 case Font_FA_Italic: return "italic";
5133 default: return "undefined";
5134 }
5135}
5136
b514beda 5137//=======================================================================
5138//function : TextToBrep
5139//purpose : Tool for conversion text to occt-shapes
5140//=======================================================================
5141
5142static int TextToBRep (Draw_Interpretor& /*theDI*/,
5143 Standard_Integer theArgNb,
5144 const char** theArgVec)
5145{
5146 // Check arguments
5147 if (theArgNb < 5)
5148 {
5149 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
5150 return 1;
5151 }
5152
5153 Standard_Integer anArgIter = 1;
5154 Standard_CString aResName = theArgVec[anArgIter++];
5155 Standard_CString aText = theArgVec[anArgIter++];
5156 Standard_CString aFontName = theArgVec[anArgIter++];
5157 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
5158
5159 Font_BRepFont aFont;
5160 Font_FontAspect aFontAspect = Font_FA_Regular;
5161 Standard_Boolean isCompositeCurve = Standard_False;
5162 gp_Ax3 aPenAx3 (gp::XOY());
5163 gp_Pnt aPenLoc;
5164 while (anArgIter < theArgNb)
5165 {
5166 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
725ef85e 5167 TCollection_AsciiString anArgCase (anArg);
5168 anArgCase.LowerCase();
5169 if (anArgCase.Search ("x=") > -1)
b514beda 5170 {
5171 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
5172 }
725ef85e 5173 else if (anArgCase.Search ("y=") > -1)
b514beda 5174 {
5175 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
5176 }
725ef85e 5177 else if (anArgCase.Search ("z=") > -1)
b514beda 5178 {
5179 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
5180 }
725ef85e 5181 else if (anArgCase.Search ("composite=") > -1)
b514beda 5182 {
5183 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
5184 }
725ef85e 5185 else if (parseFontStyle (anArgCase, aFontAspect))
b514beda 5186 {
725ef85e 5187 //
b514beda 5188 }
5189 else
5190 {
5191 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5192 }
5193 }
5194
5195 aFont.SetCompositeCurveMode (isCompositeCurve);
5196 if (!aFont.Init (aFontName, aFontAspect, aSize))
5197 {
5198 std::cerr << "Font initialization error\n";
5199 return 1;
5200 }
5201
5202 aPenAx3.SetLocation (aPenLoc);
5203 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
5204 return 0;
5205}
5206
725ef85e 5207//=======================================================================
5208//function : VFont
5209//purpose : Font management
5210//=======================================================================
5211
5212static int VFont (Draw_Interpretor& theDI,
5213 Standard_Integer theArgNb,
5214 const char** theArgVec)
5215{
5216 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
5217 if (theArgNb < 2)
5218 {
5219 // just print the list of available fonts
5220 Standard_Boolean isFirst = Standard_True;
5221 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
5222 anIter.More(); anIter.Next())
5223 {
5224 const Handle(Font_SystemFont)& aFont = anIter.Value();
5225 if (!isFirst)
5226 {
5227 theDI << "\n";
5228 }
5229
5230 theDI << aFont->FontName()->String()
5231 << " " << fontStyleString (aFont->FontAspect())
5232 << " " << aFont->FontPath()->String();
5233 isFirst = Standard_False;
5234 }
5235 return 0;
5236 }
5237
5238 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5239 {
5240 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
5241 TCollection_AsciiString anArgCase (anArg);
5242 anArgCase.LowerCase();
5243 if (anArgCase == "find")
5244 {
5245 if (++anArgIter >= theArgNb)
5246 {
5247 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5248 return 1;
5249 }
5250
5251 Standard_CString aFontName = theArgVec[anArgIter];
5252 Font_FontAspect aFontAspect = Font_FA_Undefined;
5253 if (++anArgIter < theArgNb)
5254 {
5255 anArgCase = theArgVec[anArgIter];
5256 anArgCase.LowerCase();
5257 if (!parseFontStyle (anArgCase, aFontAspect))
5258 {
5259 --anArgIter;
5260 }
5261 }
5262 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5263 if (aFont.IsNull())
5264 {
5265 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5266 continue;
5267 }
5268
5269 theDI << aFont->FontName()->String()
5270 << " " << fontStyleString (aFont->FontAspect())
5271 << " " << aFont->FontPath()->String();
5272 }
5273 else if (anArgCase == "add"
5274 || anArgCase == "register")
5275 {
5276 if (++anArgIter >= theArgNb)
5277 {
5278 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5279 return 1;
5280 }
5281 Standard_CString aFontPath = theArgVec[anArgIter];
5282 Standard_CString aFontName = NULL;
5283 Font_FontAspect aFontAspect = Font_FA_Undefined;
5284 if (++anArgIter < theArgNb)
5285 {
5286 if (!parseFontStyle (anArgCase, aFontAspect))
5287 {
5288 aFontName = theArgVec[anArgIter];
5289 }
5290 if (++anArgIter < theArgNb)
5291 {
5292 anArgCase = theArgVec[anArgIter];
5293 anArgCase.LowerCase();
5294 if (!parseFontStyle (anArgCase, aFontAspect))
5295 {
5296 --anArgIter;
5297 }
5298 }
5299 }
5300
5301 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5302 if (aFont.IsNull())
5303 {
5304 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5305 continue;
5306 }
5307
5308 if (aFontAspect != Font_FA_Undefined
5309 || aFontName != NULL)
5310 {
5311 if (aFontAspect == Font_FA_Undefined)
5312 {
5313 aFontAspect = aFont->FontAspect();
5314 }
5315 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5316 if (aFontName != NULL)
5317 {
5318 aName = new TCollection_HAsciiString (aFontName);
5319 }
5320 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5321 }
5322
5323 aMgr->RegisterFont (aFont, Standard_True);
5324 theDI << aFont->FontName()->String()
5325 << " " << fontStyleString (aFont->FontAspect())
5326 << " " << aFont->FontPath()->String();
5327 }
5328 else
5329 {
5330 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5331 }
5332 }
5333
5334 return 0;
5335}
5336
5ad539d2 5337//=======================================================================
5338//function : VSetEdgeType
5339//purpose : Edges type management
5340//=======================================================================
5341
5342static int VSetEdgeType (Draw_Interpretor& theDI,
5343 Standard_Integer theArgNum,
5344 const char** theArgs)
5345{
5346 if (theArgNum < 4 || theArgNum > 9)
5347 {
5348 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5349 << theArgs[0] << "' for more information.\n";
5350 return 1;
5351 }
5352
5353 Standard_Boolean isForceRedisplay = Standard_False;
5354
5355 // Get shape name
5356 TCollection_AsciiString aName(theArgs[1]);
5357 if (!GetMapOfAIS().IsBound2 (aName))
5358 {
5359 theDI << theArgs[0] << " error: wrong object name.\n";
5360 return 1;
5361 }
5362
5363 Handle(AIS_InteractiveObject) anObject =
5364 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5365
5366 // Enable trianle edge mode
5367 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5368
5369 // Parse parameters
5370 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5371 {
5372 TCollection_AsciiString aParam ((theArgs[anIt]));
5373 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5374 {
5375 if (aParam.IsEqual ("-type"))
5376 {
5377 if (theArgNum <= anIt + 1)
5378 {
5379 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5380 << aParam.ToCString() << "'.\n";
5381 return 1;
5382 }
5383
5384 TCollection_AsciiString aType = theArgs[++anIt];
5385 aType.UpperCase();
5386
5387 if (aType.IsEqual ("SOLID"))
5388 {
5389 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5390 }
5391 else if (aType.IsEqual ("DASH"))
5392 {
5393 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5394 }
5395 else if (aType.IsEqual ("DOT"))
5396 {
5397 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5398 }
5399 else if (aType.IsEqual ("DOTDASH"))
5400 {
5401 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5402 }
5403 else
5404 {
5405 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5406 return 1;
5407 }
5408
5409 }
5410 else if (aParam.IsEqual ("-color"))
5411 {
5412 if (theArgNum <= anIt + 3)
5413 {
5414 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5415 << aParam.ToCString() << "'.\n";
5416 return 1;
5417 }
5418
5419 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5420 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5421 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5422 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5423 aG > 1 ? aG / 255.0 : aG,
5424 aB > 1 ? aB / 255.0 : aB,
5425 Quantity_TOC_RGB);
5426
5427 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5428 }
5429 else if (aParam.IsEqual ("-force"))
5430 {
5431 isForceRedisplay = Standard_True;
5432 }
5433 else
5434 {
5435 theDI << theArgs[0] << " error: unknown parameter '"
5436 << aParam.ToCString() << "'.\n";
5437 return 1;
5438 }
5439 }
5440 }
5441
5442 // Update shape presentation as aspect parameters were changed
5443 if (isForceRedisplay)
5444 {
5445 ViewerTest::GetAISContext()->Redisplay (anObject);
5446 }
5447 else
5448 {
5449 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5450 }
5451
5452 //Update view
5453 ViewerTest::CurrentView()->Redraw();
5454
5455 return 0;
5456}
5457
5458//=======================================================================
5459//function : VUnsetEdgeType
5460//purpose : Unsets edges visibility in shading mode
5461//=======================================================================
5462
5463static int VUnsetEdgeType (Draw_Interpretor& theDI,
5464 Standard_Integer theArgNum,
5465 const char** theArgs)
5466{
5467 if (theArgNum != 2 && theArgNum != 3)
5468 {
5469 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5470 << theArgs[0] << "' for more information.\n";
5471 return 1;
5472 }
5473
5474 Standard_Boolean isForceRedisplay = Standard_False;
5475
5476 // Get shape name
5477 TCollection_AsciiString aName (theArgs[1]);
5478 if (!GetMapOfAIS().IsBound2 (aName))
5479 {
5480 theDI << theArgs[0] << " error: wrong object name.\n";
5481 return 1;
5482 }
5483
5484 Handle(AIS_InteractiveObject) anObject =
5485 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5486
5487 // Enable trianle edge mode
5488 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5489
5490 // Parse parameters
5491 if (theArgNum == 3)
5492 {
5493 TCollection_AsciiString aParam ((theArgs[2]));
5494 if (aParam.IsEqual ("-force"))
5495 {
5496 isForceRedisplay = Standard_True;
5497 }
5498 else
5499 {
5500 theDI << theArgs[0] << " error: unknown parameter '"
5501 << aParam.ToCString() << "'.\n";
5502 return 1;
5503 }
5504 }
5505
5506 // Update shape presentation as aspect parameters were changed
5507 if (isForceRedisplay)
5508 {
5509 ViewerTest::GetAISContext()->Redisplay (anObject);
5510 }
5511 else
5512 {
5513 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5514 }
5515
5516 //Update view
5517 ViewerTest::CurrentView()->Redraw();
5518
5519 return 0;
5520}
5521
53b15292 5522
5523//=======================================================================
5524//function : VVertexMode
5525//purpose : Switches vertex display mode for AIS_Shape or displays the current value
5526//=======================================================================
5527
5528static int VVertexMode (Draw_Interpretor& theDI,
5529 Standard_Integer theArgNum,
5530 const char** theArgs)
5531{
5532 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5533 if (aContext.IsNull())
5534 {
5535 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5536 return 1;
5537 }
5538
5539 // No arguments --> print the current default vertex draw mode
5540 if (theArgNum == 1)
5541 {
5542 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5543 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5544 return 0;
5545 }
5546
5547 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5548 TCollection_AsciiString aParam (theArgs[1]);
5549 if (aParam == "-set")
5550 {
5551 if (theArgNum == 2)
5552 {
5553 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5554 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5555 return 1;
5556 }
5557
5558 TCollection_AsciiString aModeStr (theArgs[2]);
5559 Prs3d_VertexDrawMode aNewMode =
5560 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5561 (aModeStr == "all" ? Prs3d_VDM_All :
5562 Prs3d_VDM_Inherited);
5563
5564 Standard_Boolean aRedrawNeeded = Standard_False;
5565 AIS_ListOfInteractive anObjs;
5566
5567 // No object(s) specified -> use all displayed
5568 if (theArgNum == 3)
5569 {
5570 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5571 aContext->DisplayedObjects (anObjs);
5572 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5573 aRedrawNeeded = Standard_True;
5574 }
5575
5576 Handle(AIS_InteractiveObject) anObject;
5577 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5578 {
5579 TCollection_AsciiString aName (theArgs[aCount]);
5580 if (!GetMapOfAIS().IsBound2 (aName))
5581 {
5582 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5583 continue;
5584 }
5585 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5586 anObjs.Append (anObject);
5587 }
5588
5589 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5590 {
5591 anObject = anIt.Value();
5592 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5593 aContext->Redisplay (anObject, Standard_False);
5594 aRedrawNeeded = Standard_True;
5595 }
5596
5597 if (aRedrawNeeded)
5598 ViewerTest::CurrentView()->Redraw();
5599
5600 return 0;
5601 }
5602
5603 if (theArgNum > 2)
5604 {
5605 std::cout << "Error: invalid number of arguments" << std::endl;
5606 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5607 return 1;
5608 }
5609
5610 // One argument (object name) --> print the current vertex draw mode for the object
5611 Handle(AIS_InteractiveObject) anObject =
5612 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5613 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5614 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5615 return 0;
5616}
5617
d33222c1 5618//=======================================================================
5619//function : VPointCloud
5620//purpose : Create interactive object for arbitary set of points.
5621//=======================================================================
5622static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
5623 Standard_Integer theArgNum,
5624 const char** theArgs)
5625{
5626 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5627 if (anAISContext.IsNull())
5628 {
5629 std::cerr << "Error: no active view!\n";
5630 return 1;
5631 }
5632
5633 // command to execute
5634 enum Command
5635 {
5636 CloudForShape, // generate point cloud for shape
5637 CloudSphere, // generate point cloud for generic sphere
5638 Unknow
5639 };
5640
5641 // count number of non-optional command arguments
5642 Command aCmd = Unknow;
5643 Standard_Integer aCmdArgs = 0;
5644 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5645 {
5646 Standard_CString anArg = theArgs[anArgIter];
5647 TCollection_AsciiString aFlag (anArg);
5648 aFlag.LowerCase();
5649 if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
5650 {
5651 aCmdArgs++;
5652 }
5653 }
5654 switch (aCmdArgs)
5655 {
5656 case 2 : aCmd = CloudForShape; break;
5657 case 7 : aCmd = CloudSphere; break;
5658 default :
5659 std::cout << "Error: wrong number of arguments! See usage:\n";
5660 theDI.PrintHelp (theArgs[0]);
5661 return 1;
5662 }
5663
5664 // parse options
5665 Standard_Boolean toRandColors = Standard_False;
5666 Standard_Boolean hasNormals = Standard_True;
5667 Standard_Boolean isSetArgNorm = Standard_False;
5668 for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
5669 {
5670 Standard_CString anArg = theArgs[anArgIter];
5671 TCollection_AsciiString aFlag (anArg);
5672 aFlag.LowerCase();
5673 if (aFlag == "-randcolors"
5674 || aFlag == "-randcolor")
5675 {
5676 if (isSetArgNorm && hasNormals)
5677 {
5678 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5679 return 1;
5680 }
5681 toRandColors = Standard_True;
5682 hasNormals = Standard_False;
5683 }
5684 else if (aFlag == "-normals"
5685 || aFlag == "-normal")
5686 {
5687 if (toRandColors)
5688 {
5689 std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
5690 return 1;
5691 }
5692 isSetArgNorm = Standard_True;
5693 hasNormals = Standard_True;
5694 }
5695 else if (aFlag == "-nonormals"
5696 || aFlag == "-nonormal")
5697 {
5698 isSetArgNorm = Standard_True;
5699 hasNormals = Standard_False;
5700 }
5701 }
5702
5703 Standard_CString aName = theArgs[1];
5704
5705 // generate arbitrary set of points
5706 Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
5707 if (aCmd == CloudForShape)
5708 {
5709 Standard_CString aShapeName = theArgs[2];
5710 TopoDS_Shape aShape = DBRep::Get (aShapeName);
5711
5712 if (aShape.IsNull())
5713 {
5714 std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
5715 return 1;
5716 }
5717
5718 // calculate number of points
5719 TopLoc_Location aLocation;
5720 Standard_Integer aNbPoints = 0;
5721 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5722 {
5723 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5724 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5725 if (!aTriangulation.IsNull())
5726 {
5727 aNbPoints += aTriangulation->NbNodes();
5728 }
5729 }
5730 if (aNbPoints < 3)
5731 {
5732 std::cout << "Error: shape should be triangulated!\n";
5733 return 1;
5734 }
5735
5736 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5737 for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
5738 {
5739 const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
5740 Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation);
5741 if (aTriangulation.IsNull())
5742 {
5743 continue;
5744 }
5745
5746 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
5747 const gp_Trsf& aTrsf = aLocation.Transformation();
5748
5749 // extract normals from nodes
5750 TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
5751 if (hasNormals)
5752 {
5753 Poly_Connect aPolyConnect (aTriangulation);
5754 StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
5755 }
5756
5757 for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
5758 {
5759 gp_Pnt aPoint = aNodes (aNodeIter);
5760 if (!aLocation.IsIdentity())
5761 {
5762 aPoint.Transform (aTrsf);
5763 if (hasNormals)
5764 {
5765 aNormals (aNodeIter).Transform (aTrsf);
5766 }
5767 }
5768
5769 // add vertex into array of points
5770 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5771 if (toRandColors)
5772 {
5773 Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
5774 1.0, 0.5, Quantity_TOC_HLS);
5775 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5776 }
5777
5778 if (hasNormals)
5779 {
5780 anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
5781 }
5782 }
5783 }
5784 }
5785 else if (aCmd == CloudSphere)
5786 {
5787 Standard_Real aCenterX = Draw::Atof (theArgs[2]);
5788 Standard_Real aCenterY = Draw::Atof (theArgs[3]);
5789 Standard_Real aCenterZ = Draw::Atof (theArgs[4]);
5790 Standard_Real aRadius = Draw::Atof (theArgs[5]);
5791 Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]);
5792
5793 TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
5794 aDistribution.LowerCase();
5795 if ( aDistribution != "surface" && aDistribution != "volume" )
5796 {
5797 std::cout << "Error: wrong arguments! See usage:\n";
5798 theDI.PrintHelp (theArgs[0]);
5799 return 1;
5800 }
5801 Standard_Boolean isSurface = aDistribution == "surface";
5802
5803 gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
5804
5805 anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
5806 for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
5807 {
5808 Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5809 Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
5810 Standard_Real aDistance = isSurface ?
5811 aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
5812
5813 gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
5814 Sin (anAlpha),
5815 Cos (anAlpha) * Cos (aBeta));
5816 gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
5817
5818 const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
5819 if (toRandColors)
5820 {
5821 Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
5822 1.0, 0.5, Quantity_TOC_HLS);
5823 anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
5824 }
5825
5826 if (hasNormals)
5827 {
5828 anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
5829 }
5830 }
5831 }
5832
5833 // set array of points in point cloud object
5834 Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
5835 aPointCloud->SetPoints (anArrayPoints);
5836 VDisplayAISObject (aName, aPointCloud);
5837 return 0;
5838}
5839
a0c20252 5840//=======================================================================
5841//function : VPriority
5842//purpose : Prints or sets the display priority for an object
5843//=======================================================================
5844
5845static int VPriority (Draw_Interpretor& theDI,
5846 Standard_Integer theArgNum,
5847 const char** theArgs)
5848{
5849 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5850 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5851 if (aContext.IsNull())
5852 {
5853 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5854 return 1;
5855 }
5856
5857 TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
5858 Standard_Integer aPriority = -1;
5859 Standard_Integer aNbArgs = theArgNum;
5860 if (aLastArg.IsIntegerValue())
5861 {
5862 aPriority = aLastArg.IntegerValue();
5863 --aNbArgs;
5864 if (aPriority < 0 || aPriority > 10)
5865 {
5866 std::cout << "Error: the specified display priority value '" << aLastArg
5867 << "' is outside the valid range [0..10]" << std::endl;
5868 return 1;
5869 }
5870 }
5871 else
5872 {
5873 anUpdateTool.Invalidate();
5874 }
5875
5876 if (aNbArgs < 2)
5877 {
5878 std::cout << "Error: wrong number of arguments! See usage:\n";
5879 theDI.PrintHelp (theArgs[0]);
5880 return 1;
5881 }
5882
5883 for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
5884 {
5885 if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
5886 {
5887 continue;
5888 }
5889
5890 TCollection_AsciiString aName (theArgs[anArgIter]);
5891 Handle(AIS_InteractiveObject) anIObj;
5892 if (GetMapOfAIS().IsBound2 (aName))
5893 {
5894 anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5895 }
5896
5897 if (anIObj.IsNull())
5898 {
5899 std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
5900 return 1;
5901 }
5902
5903 if (aPriority < 1)
5904 {
5905 theDI << aContext->DisplayPriority (anIObj) << " ";
5906 }
5907 else
5908 {
5909 aContext->SetDisplayPriority (anIObj, aPriority);
5910 }
5911 }
5912 return 0;
5913}
5914
7fd59977 5915//=======================================================================
5916//function : ObjectsCommands
161c4476 5917//purpose :
7fd59977 5918//=======================================================================
5919
5920void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
5921{
5922 const char *group ="AISObjects";
5923 theCommands.Add("vtrihedron",
5924 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
5925 __FILE__,VTrihedron,group);
5926
161c4476 5927 theCommands.Add("vtri2d",
7fd59977 5928 "vtri2d Name Selection in the viewer only ",
5929 __FILE__,VTrihedron2D ,group);
5930
161c4476 5931 theCommands.Add("vplanetri",
7fd59977 5932 "vplanetri Name Selection in the viewer only ",
5933 __FILE__,VPlaneTrihedron ,group);
5934
5935 theCommands.Add("vsize",
5936 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
5937 __FILE__,VSize,group);
5938
5939 theCommands.Add("vaxis",
5940 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
5941 __FILE__,VAxisBuilder,group);
5942
161c4476 5943 theCommands.Add("vaxispara",
7fd59977 5944 "vaxispara nom ",
5945 __FILE__,VAxisBuilder,group);
5946
5947 theCommands.Add("vaxisortho",
5948 "vaxisotho nom ",
5949 __FILE__,VAxisBuilder,group);
5950
5951 theCommands.Add("vpoint",
5952 "vpoint PointName [Xa] [Ya] [Za] ",
5953 __FILE__,VPointBuilder,group);
5954
5955 theCommands.Add("vplane",
9e8804b6 5956 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
7fd59977 5957 __FILE__,VPlaneBuilder,group);
5958
f3889691 5959 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
5960 " vchangeplane <plane_name>"
5961 " [x=center_x y=center_y z=center_z]"
5962 " [dx=dir_x dy=dir_y dz=dir_z]"
5963 " [sx=size_x sy=size_y]"
5964 " [noupdate]\n"
5965 " - changes parameters of the plane:\n"
5966 " - x y z - center\n"
5967 " - dx dy dz - normal\n"
5968 " - sx sy - plane sizes\n"
5969 " - noupdate - do not update/redisplay the plane in context\n"
5970 " Please enter coordinates in format \"param=value\" in arbitrary order.",
5971 __FILE__, VChangePlane, group);
5972
7fd59977 5973 theCommands.Add("vplanepara",
5974 "vplanepara PlaneName ",
5975 __FILE__,VPlaneBuilder,group);
5976
5977 theCommands.Add("vplaneortho",
5978 "vplaneortho PlaneName ",
5979 __FILE__,VPlaneBuilder,group);
5980
161c4476 5981 theCommands.Add("vline",
7fd59977 5982 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
5983 __FILE__,VLineBuilder,group);
5984
5985 theCommands.Add("vcircle",
329843e2 5986 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
7fd59977 5987 __FILE__,VCircleBuilder,group);
5988
29e2c6d2 5989 theCommands.Add ("vdrawtext",
5990 "vdrawtext name text"
5991 "\n\t\t: [-pos X=0 Y=0 Z=0]"
5992 "\n\t\t: [-color {R G B|name}=yellow]"
5993 "\n\t\t: [-halign {left|center|right}=left]"
5994 "\n\t\t: [-valign {top|center|bottom}=bottom}]"
5995 "\n\t\t: [-angle angle=0]"
5996 "\n\t\t: [-zoom {0|1}=0]"
5997 "\n\t\t: [-height height=16]"
5998 "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
5999 "\n\t\t: [-font font=Times]"
6000 "\n\t\t: [-noupdate]"
6001 "\n\t\t: Display text label at specified position.",
6002 __FILE__, VDrawText, group);
7fd59977 6003
6004 theCommands.Add("vdrawsphere",
b7cd4ba7 6005 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
7fd59977 6006 __FILE__,VDrawSphere,group);
6007
29d43f9c 6008 theCommands.Add ("vsetlocation",
4e18052b 6009 "vsetlocation [-noupdate|-update] name x y z"
6010 "\n\t\t: Set new location for an interactive object.",
29d43f9c
A
6011 __FILE__, VSetLocation, group);
6012
3fc57801 6013 theCommands.Add (
6014 "vcomputehlr",
6015 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
6016 __FILE__, VComputeHLR, group);
6017
9558a876 6018 theCommands.Add("vdrawparray",
871fa103 6019 "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 6020 __FILE__,VDrawPArray,group);
ac04d101
SA
6021
6022 theCommands.Add("vconnect",
0717ddc1 6023 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
6024 " Makes an assembly of object instances located in point (Xo Yo Zo).",
ac04d101
SA
6025 __FILE__, VConnect, group);
6026
0717ddc1 6027 theCommands.Add("vconnectto",
d4aaad5b 6028 "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
f751596e 6029 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
6030 "\n\t\t: -nodisplay - only creates interactive object, but not displays it",
0717ddc1 6031 __FILE__, VConnectTo,group);
6032
6033 theCommands.Add("vdisconnect",
6034 "vdisconnect assembly_name (object_name | object_number | 'all')"
6035 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
6036 __FILE__,VDisconnect,group);
6037
6038 theCommands.Add("vaddconnected",
6039 "vaddconnected assembly_name object_name"
6040 "Adds object to assembly.",
6041 __FILE__,VAddConnected,group);
6042
6043 theCommands.Add("vlistconnected",
6044 "vlistconnected assembly_name"
6045 "Lists objects in assembly.",
6046 __FILE__,VListConnected,group);
6047
ac04d101
SA
6048
6049 theCommands.Add("vselmode",
446e9c14 6050 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
6051 " switches selection mode for the determined object or\n"
6052 " for all objects in context.\n"
6053 " mode_number is non-negative integer that has different\n"
6054 " meaning for different interactive object classes.\n"
6055 " For shapes the following mode_number values are allowed:\n"
6056 " 0 - shape\n"
6057 " 1 - vertex\n"
6058 " 2 - edge\n"
6059 " 3 - wire\n"
6060 " 4 - face\n"
6061 " 5 - shell\n"
6062 " 6 - solid\n"
6063 " 7 - compsolid\n"
6064 " 8 - compound\n"
6065 " is_turned_on is:\n"
6066 " 1 if mode is to be switched on\n"
6067 " 0 if mode is to be switched off\n",
ac04d101 6068 __FILE__, VSetSelectionMode, group);
ceae62f0 6069
4ca4bbe8 6070 theCommands.Add("vselnext",
6071 "vselnext : hilight next detected",
6072 __FILE__, VSelectionNext, group);
6073
6074 theCommands.Add("vselprev",
6075 "vselnext : hilight previous detected",
6076 __FILE__, VSelectionPrevious, group);
6077
ceae62f0
A
6078 theCommands.Add("vtriangle",
6079 "vtriangle Name PointName PointName PointName",
6080 __FILE__, VTriangle,group);
6081
6082 theCommands.Add("vsegment",
6083 "vsegment Name PointName PointName",
6084 __FILE__, VSegment,group);
59f45b7c 6085
6086 theCommands.Add("vobjzlayer",
6087 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
6088 __FILE__, VObjZLayer, group);
3ddebf91 6089
6090 theCommands.Add("vpolygonoffset",
6091 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
6092 __FILE__, VPolygonOffset, group);
a2d5ab2e 6093
6094 theCommands.Add ("vshowfaceboundary",
6095 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
6096 "- turns on/off drawing of face boundaries for ais object "
6097 "and defines boundary line style.",
6098 __FILE__, VShowFaceBoundary, group);
a577aaab 6099
6100 theCommands.Add ("vmarkerstest",
6101 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
6102 __FILE__, VMarkersTest, group);
b514beda 6103
6104 theCommands.Add ("text2brep",
6105 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
6106 __FILE__, TextToBRep, group);
725ef85e 6107 theCommands.Add ("vfont",
6108 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
6109 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
6110 __FILE__, VFont, group);
5ad539d2 6111
6112 theCommands.Add ("vsetedgetype",
6113 "vsetedgetype usage:\n"
6114 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
6115 "\n\t\t: Sets edges type and color for input shape",
6116 __FILE__, VSetEdgeType, group);
6117
6118 theCommands.Add ("vunsetedgetype",
6119 "vunsetedgetype usage:\n"
6120 "vunsetedgetype ShapeName [-force]"
6121 "\n\t\t: Unsets edges type and color for input shape",
6122 __FILE__, VUnsetEdgeType, group);
53b15292 6123
6124 theCommands.Add ("vvertexmode",
6125 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
6126 "vvertexmode - prints the default vertex draw mode\n"
6127 "vvertexmode name - prints the vertex draw mode of the given object\n"
6128 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
6129 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
6130 __FILE__, VVertexMode, group);
d33222c1 6131
6132 theCommands.Add ("vpointcloud",
6133 "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
6134 "\n\t\t: Create an interactive object for arbitary set of points"
6135 "\n\t\t: from triangulated shape."
6136 "\n"
6137 "vpointcloud name x y z r npts {surface|volume}\n"
6138 " ... [-randColor] [-normals] [-noNormals]"
6139 "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
6140 "\n\t\t: on spheric surface or within spheric volume (x y z r)."
6141 "\n\t\t:"
6142 "\n\t\t: Additional options:"
6143 "\n\t\t: -randColor - generate random color per point"
6144 "\n\t\t: -normals - generate normal per point (default)"
6145 "\n\t\t: -noNormals - do not generate normal per point"
6146 "\n",
6147 __FILE__, VPointCloud, group);
7d9e854b 6148
6149 theCommands.Add("vlocreset",
6150 "vlocreset name1 name2 ...\n\t\t remove object local transformation",
6151 __FILE__,
6152 LocalTransformPresentation, group);
6153
6154 theCommands.Add("vlocmove",
6155 "vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
6156 __FILE__,
6157 LocalTransformPresentation, group);
6158
6159 theCommands.Add("vloctranslate",
6160 "vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
6161 __FILE__,
6162 LocalTransformPresentation, group);
6163
6164 theCommands.Add("vlocrotate",
6165 "vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
6166 __FILE__,
6167 LocalTransformPresentation, group);
6168
6169 theCommands.Add("vlocmirror",
6170 "vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
6171 __FILE__,
6172 LocalTransformPresentation, group);
6173
6174 theCommands.Add("vlocscale",
6175 "vlocscale name x y z scale\n\t\t applies scale to local transformation",
6176 __FILE__,
6177 LocalTransformPresentation, group);
a0c20252 6178
6179 theCommands.Add("vpriority",
6180 "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
6181 __FILE__,
6182 VPriority, group);
7fd59977 6183}