0025198: Draw Harness - add -noupdate option to vsetlocation command
[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>
36#include <TColStd_MapOfInteger.hxx>
37#include <AIS_MapOfInteractive.hxx>
4e18052b 38#include <ViewerTest_AutoUpdater.hxx>
7fd59977 39#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
40#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
41#include <ViewerTest_EventManager.hxx>
42
43#include <TopoDS_Solid.hxx>
44#include <BRepTools.hxx>
45#include <BRep_Builder.hxx>
46#include <TopAbs_ShapeEnum.hxx>
47
48#include <TopoDS.hxx>
49#include <BRep_Tool.hxx>
50#include <TopExp_Explorer.hxx>
51
52#include <BRepAdaptor_Curve.hxx>
53#include <BRepAdaptor_Surface.hxx>
54
55#include <TopAbs.hxx>
56#include <TopExp.hxx>
57#include <TopoDS_Vertex.hxx>
58#include <TopoDS_Shape.hxx>
59#include <TopoDS_Face.hxx>
60
61#include <Draw_Window.hxx>
62#include <AIS_ListIteratorOfListOfInteractive.hxx>
63#include <AIS_ListOfInteractive.hxx>
64#include <AIS_DisplayMode.hxx>
65#include <AIS_Shape.hxx>
66
67#include <AIS_InteractiveContext.hxx>
68#include <Geom_Plane.hxx>
69#include <gp_Pln.hxx>
7fd59977 70#include <TCollection_ExtendedString.hxx>
725ef85e 71#include <TCollection_HAsciiString.hxx>
7fd59977 72#include <GC_MakePlane.hxx>
73#include <gp_Circ.hxx>
74#include <AIS_Axis.hxx>
75#include <Geom_Axis2Placement.hxx>
76#include <Geom_Axis1Placement.hxx>
77#include <AIS_Trihedron.hxx>
78#include <AIS_Axis.hxx>
29d43f9c
A
79#include <gp_Trsf.hxx>
80#include <TopLoc_Location.hxx>
3fc57801 81
82#include <HLRAlgo_Projector.hxx>
83#include <HLRBRep_PolyAlgo.hxx>
84#include <HLRBRep_PolyHLRToShape.hxx>
85#include <Aspect_Window.hxx>
86
9558a876
A
87#include <Graphic3d_ArrayOfPoints.hxx>
88#include <Graphic3d_ArrayOfSegments.hxx>
89#include <Graphic3d_ArrayOfPolylines.hxx>
90#include <Graphic3d_ArrayOfTriangles.hxx>
91#include <Graphic3d_ArrayOfTriangleFans.hxx>
92#include <Graphic3d_ArrayOfTriangleStrips.hxx>
93#include <Graphic3d_ArrayOfQuadrangles.hxx>
94#include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
95#include <Graphic3d_ArrayOfPolygons.hxx>
a577aaab 96#include <Graphic3d_AspectMarker3d.hxx>
9558a876
A
97#include <Graphic3d_Group.hxx>
98#include <Standard_Real.hxx>
99
329843e2
A
100#include <AIS_Circle.hxx>
101#include <AIS_Drawer.hxx>
102#include <BRepBuilderAPI_MakeEdge.hxx>
103#include <BRepBuilderAPI_MakeFace.hxx>
104#include <BRepBuilderAPI_MakeWire.hxx>
105#include <Geom_Circle.hxx>
106#include <GC_MakeCircle.hxx>
107#include <Prs3d_Presentation.hxx>
108#include <Select3D_SensitiveCircle.hxx>
109#include <SelectMgr_EntityOwner.hxx>
110#include <SelectMgr_Selection.hxx>
111#include <StdFail_NotDone.hxx>
112#include <StdPrs_ShadedShape.hxx>
a2d5ab2e 113#include <TopoDS_Wire.hxx>
ac04d101 114
792c785c 115#include <AIS_MultipleConnectedInteractive.hxx>
0717ddc1 116#include <AIS_ConnectedInteractive.hxx>
ac04d101
SA
117#include <TopLoc_Location.hxx>
118#include <TColStd_ListOfInteger.hxx>
119#include <TColStd_ListIteratorOfListOfInteger.hxx>
329843e2 120
ceae62f0
A
121#include <Select3D_SensitiveTriangle.hxx>
122#include <Select3D_SensitiveCurve.hxx>
a577aaab 123#include <Select3D_SensitivePoint.hxx>
ceae62f0
A
124#include <BRepAdaptor_Curve.hxx>
125#include <StdPrs_Curve.hxx>
126
127#include <BRepExtrema_ExtPC.hxx>
128#include <BRepExtrema_ExtPF.hxx>
129
53b15292 130#include <Prs3d_VertexDrawMode.hxx>
a2d5ab2e 131#include <Prs3d_LineAspect.hxx>
a577aaab 132#include <Prs3d_PointAspect.hxx>
133
134#include <Image_AlienPixMap.hxx>
eb4320f2 135#include <TColStd_HArray1OfAsciiString.hxx>
a2d5ab2e 136
03155c18 137#ifdef _WIN32
138# define _CRT_SECURE_NO_DEPRECATE
139# pragma warning (disable:4996)
7fd59977 140#endif
141
142extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
9558a876
A
143extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
144 const Handle(AIS_InteractiveObject)& theAISObj,
145 Standard_Boolean theReplaceIfExists = Standard_True);
1d0a9d4d 146extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
7fd59977 147extern Handle(AIS_InteractiveContext)& TheAISContext();
148
149
150//==============================================================================
151//function : Vtrihedron 2d
152//purpose : Create a plane with a 2D trihedron from a faceselection
161c4476 153//Draw arg : vtri2d name
7fd59977 154//==============================================================================
155#include <AIS_PlaneTrihedron.hxx>
156
157
158
159static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
160
161{
162 // Verification des arguments
163 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
164
165 // Declarations
166 Standard_Integer myCurrentIndex;
161c4476 167 // Fermeture des contextes
7fd59977 168 TheAISContext()->CloseAllContexts();
169 // Ouverture d'un contexte local et recuperation de son index.
170 TheAISContext()->OpenLocalContext();
171 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
172 // On active les modes de selections faces.
173 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
174 di<<" Select a face ."<<"\n";
175
176 // Boucle d'attente waitpick.
177 Standard_Integer argccc = 5;
178 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
179 const char **argvvv = (const char **) bufff;
180 while (ViewerMainLoop( argccc, argvvv) ) { }
181 // fin de la boucle
182
183 TopoDS_Shape ShapeB;
184 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
185 ShapeB = TheAISContext()->SelectedShape();
186 }
187
188 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
189
190 // Construction du Plane
191 // recuperation des edges des faces.
192 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
193
194 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
161c4476 195 // declarations
7fd59977 196 gp_Pnt A,B,C;
197
198 // si il y a plusieurs edges
199 if (FaceExpB.More() ) {
200 FaceExpB.Next();
201 TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
202 BRepAdaptor_Curve theCurveB(EdgeB);
203 BRepAdaptor_Curve theCurveC(EdgeC);
204 A=theCurveC.Value(0.1);
205 B=theCurveC.Value(0.9);
206 C=theCurveB.Value(0.5);
207 }
208 else {
209 // FaceB a 1 unique edge courbe
210 BRepAdaptor_Curve theCurveB(EdgeB);
211 A=theCurveB.Value(0.1);
212 B=theCurveB.Value(0.9);
213 C=theCurveB.Value(0.5);
214 }
215 // Construction du Geom_Plane
216 GC_MakePlane MkPlane(A,B,C);
217 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
218
219 // Construction de l'AIS_PlaneTrihedron
220 Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
221
222 // Fermeture du contexte local.
223 TheAISContext()->CloseLocalContext(myCurrentIndex);
224
225 // on le display & bind
226 TheAISContext()->Display(theAISPlaneTri );
227 GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
228
161c4476 229 return 0;
7fd59977 230}
231
232
233
234//==============================================================================
235//function : VTriherdron
7fd59977 236//purpose : Create a trihedron. If no arguments are set, the default
237// trihedron (Oxyz) is created.
238//Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
239//==============================================================================
240
dc9b6d23 241static int VTrihedron (Draw_Interpretor& theDi,
242 Standard_Integer theArgsNb,
243 const char** theArgVec)
7fd59977 244{
dc9b6d23 245 if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
246 {
247 theDi << theArgVec[0] << " Syntax error\n";
248 return 1;
7fd59977 249 }
7fd59977 250
dc9b6d23 251 gp_Pnt anOrigin (0.0, 0.0, 0.0);
252 gp_Dir aDirZ = gp::DZ();
253 gp_Dir aDirX = gp::DX();
254 Standard_Integer anArgIter = 2; // 1st is an IO name
255 if (anArgIter < theArgsNb)
256 {
91322f44 257 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
258 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
259 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
dc9b6d23 260 if (anArgIter < theArgsNb)
261 {
91322f44 262 Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
263 Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
264 Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
dc9b6d23 265 aDirZ.SetCoord (aX, aY, aZ);
266
91322f44 267 aX = Draw::Atof (theArgVec[anArgIter++]);
268 aY = Draw::Atof (theArgVec[anArgIter++]);
269 aZ = Draw::Atof (theArgVec[anArgIter++]);
dc9b6d23 270 aDirX.SetCoord (aX, aY, aZ);
271 }
272 }
7fd59977 273
dc9b6d23 274 if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
275 {
276 theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
277 return 1;
278 }
7fd59977 279
dc9b6d23 280 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
281 Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
282 VDisplayAISObject (theArgVec[1], aShape);
161c4476 283 return 0;
7fd59977 284}
285
7fd59977 286//==============================================================================
287//function : VSize
288//author : ege
289//purpose : Change the size of a named or selected trihedron
290// if no name : it affects the trihedrons witch are selected otherwise nothing is donne
291// if no value, the value is set at 100 by default
292//Draw arg : vsize [name] [size]
293//==============================================================================
294
295static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
296
297{
298 // Declaration de booleens
299 Standard_Boolean ThereIsName;
300 Standard_Boolean ThereIsCurrent;
301 Standard_Real value;
161c4476 302 Standard_Boolean hascol;
1d47d8d0 303
7fd59977 304 Quantity_NameOfColor col = Quantity_NOC_BLACK ;
7fd59977 305
306 // Verification des arguments
307 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
308
309 // Verification du nombre d'arguments
310 if (argc==1) {ThereIsName=Standard_False;value=100;}
91322f44 311 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
312 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
7fd59977 313
314 // On ferme le contexte local pour travailler dans le contexte global
161c4476 315 if(TheAISContext()->HasOpenedContext())
7fd59977 316 TheAISContext()->CloseLocalContext();
317
318 // On set le booleen ThereIsCurrent
319 if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
320 else {ThereIsCurrent=Standard_False;}
321
322
323
324 //===============================================================
325 // Il n'y a pas de nom mais des objets selectionnes
326 //===============================================================
161c4476 327 if (!ThereIsName && ThereIsCurrent)
7fd59977 328 {
329
330 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
331 it (GetMapOfAIS());
332
333 while ( it.More() ) {
334
335 Handle(AIS_InteractiveObject) aShape=
336 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
337
338 if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) )
339 {
340
161c4476 341 // On verifie que l'AIS InteraciveObject selectionne est bien
7fd59977 342 // un AIS_Trihedron
343 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
344
345 if (aShape->HasColor()) {
346 hascol=Standard_True;
347
348 // On recupere la couleur de aShape
349 col=aShape->Color();}
350
351 else hascol=Standard_False;
352
353 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
354 // pour lui appliquer la methode SetSize()
355 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
356
357 // C'est bien un triedre,on chage sa valeur!
358 aTrihedron->SetSize(value);
359
360 // On donne la couleur au Trihedron
361 if(hascol) aTrihedron->SetColor(col);
362 else aTrihedron->UnsetColor();
363
364
365 // The trihedron hasn't be errased from the map
366 // so you just have to redisplay it
367 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
368
369 }
370
371 }
372
373 it.Next();
374 }
375
376 TheAISContext() ->UpdateCurrentViewer();
377 }
378
379 //===============================================================
380 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
381 //===============================================================
382
383
384
385 //===============================================================
386 // Il y a un nom de triedre passe en argument
387 //===============================================================
388 if (ThereIsName) {
389 TCollection_AsciiString name=argv[1];
390
391 // on verifie que ce nom correspond bien a une shape
392 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
393
394 if (IsBound) {
395
396 // on recupere la shape dans la map des objets displayes
397 Handle(AIS_InteractiveObject) aShape =
398 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
399
161c4476 400 // On verifie que l'AIS InteraciveObject est bien
7fd59977 401 // un AIS_Trihedron
402 if (!aShape.IsNull() &&
403 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
404 {
405
406 if (aShape->HasColor()) {
407 hascol=Standard_True;
408
409 // On recupere la couleur de aShape
410 col=aShape->Color();}
411
412 else hascol=Standard_False;
413
414 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
415 // pour lui appliquer la methode SetSize()
416 Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
417
418 // C'est bien un triedre,on chage sa valeur
419 aTrihedron->SetSize(value);
420
421 // On donne la couleur au Trihedron
422 if(hascol) aTrihedron->SetColor(col);
423 else aTrihedron->UnsetColor();
424
425 // The trihedron hasn't be errased from the map
426 // so you just have to redisplay it
427 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
428
429 TheAISContext() ->UpdateCurrentViewer();
430 }
431 }
432 }
161c4476 433 return 0;
7fd59977 434}
435
436
437//==============================================================================
438
439//==============================================================================
440//function : VPlaneTrihedron
441//purpose : Create a plane from a trihedron selection. If no arguments are set, the default
161c4476 442//Draw arg : vplanetri name
7fd59977 443//==============================================================================
444#include <AIS_Plane.hxx>
445
446
447
448static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
449
450{
451 // Verification des arguments
452 if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
453
454 // Declarations
455 Standard_Integer myCurrentIndex;
456 // Fermeture des contextes locaux
457 TheAISContext()->CloseAllContexts();
458
161c4476 459 // On recupere tous les trihedrons de la GetMapOfAIS()
7fd59977 460 // et on active le mode de selection par face.
461 // =================================================
462
463 // Ouverture d'un contexte local et recuperation de son index.
464 TheAISContext()->OpenLocalContext(Standard_False);
465 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
466
467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
468 it (GetMapOfAIS());
469 while(it.More()){
470 Handle(AIS_InteractiveObject) ShapeA =
471 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
472 // On verifie que c'est bien un trihedron
473 if (!ShapeA.IsNull() &&
474 ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) {
475 // on le downcast
476 Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
477 // on le charge dans le contexte et on active le mode Plane.
478 TheAISContext()->Load(TrihedronA,0,Standard_False);
479 TheAISContext()->Activate(TrihedronA,3);
480 }
481 it.Next();
482 }
483
484 di<<" Select a plane."<<"\n";
485 // Boucle d'attente waitpick.
486 Standard_Integer argccc = 5;
487 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
488 const char **argvvv = (const char **) bufff;
489 while (ViewerMainLoop( argccc, argvvv) ) { }
490 // fin de la boucle
491
492 Handle(AIS_InteractiveObject) theIOB;
493 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
494 theIOB = TheAISContext()->Interactive();
495 }
496 // on le downcast
497 Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
498
499 // Fermeture du contexte local.
500 TheAISContext()->CloseLocalContext(myCurrentIndex);
501
502 // on le display & bind
503 TheAISContext()->Display(PlaneB );
504 GetMapOfAIS().Bind ( PlaneB ,argv[1]);
505
161c4476 506 return 0;
7fd59977 507}
508
509
510
511//==============================================================================
512// Fonction First click 2de click
161c4476 513//
7fd59977 514// vaxis vertex vertex
515// edge None
516// vaxispara edge vertex
517// vaxisortho edge Vertex
518// vaxisinter Face Face
519//==============================================================================
520
521//==============================================================================
522//function : VAxisBuilder
161c4476 523//purpose :
7fd59977 524//Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
525//==============================================================================
526#include <TopoDS_Edge.hxx>
527#include <TopoDS_Vertex.hxx>
528#include <TopExp.hxx>
529#include <Geom_Line.hxx>
530
161c4476 531static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 532{
533 // Declarations
534 Standard_Boolean HasArg;
535 TCollection_AsciiString name;
536 Standard_Integer MyCurrentIndex;
537
538 // Verification
539 if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
540 if (argc==8) HasArg=Standard_True;
541 else HasArg=Standard_False;
542
543 name=argv[1];
544 // Fermeture des contextes
545 TheAISContext()->CloseAllContexts();
546
547 // Cas ou il y a des arguments
548 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
549 if (HasArg) {
550 Standard_Real coord[6];
551 for(Standard_Integer i=0;i<=5;i++){
91322f44 552 coord[i]=Draw::Atof(argv[2+i]);
7fd59977 553 }
554 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
555
556 gp_Vec myVect (p1,p2);
557 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
558 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
559 GetMapOfAIS().Bind (TheAxis,name);
560 TheAISContext()->Display(TheAxis);
561 }
562
563 // Pas d'arguments
564 else {
565 // fonction vaxis
566 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
567 if ( !strcasecmp(argv[0], "vaxis")) {
568 TheAISContext()->OpenLocalContext();
569 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
570
571 // Active le mode edge et le mode vertex
572 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
573 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
574 di<<" Select an edge or a vertex."<<"\n";
575
576 // Boucle d'attente waitpick.
577 Standard_Integer argcc = 5;
578 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
579 const char **argvv = (const char **) buff;
580 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 581 // fin de la boucle
7fd59977 582
583 // recuperation de la shape.
584 TopoDS_Shape ShapeA;
585 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
586 ShapeA = TheAISContext()->SelectedShape();
587 }
588 // recuperation de l'AIS_InteractiveObject
589 //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
590 // down cast en AIS_Point si sig et type
591 // AIS_Point -> Geom_Pnt ....
592
593 if (ShapeA.ShapeType()==TopAbs_VERTEX) {
594 // on desactive le mode edge
595 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
596 di<<" Select a different vertex."<<"\n";
597
598 TopoDS_Shape ShapeB;
599 do {
600 // Boucle d'attente waitpick.
601 Standard_Integer argccc = 5;
602 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
603 const char **argvvv = (const char **) bufff;
604 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 605 // fin de la boucle
7fd59977 606 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
607 ShapeB = TheAISContext()->SelectedShape();
608 }
609
610
611 } while(ShapeB.IsSame(ShapeA) );
612
613 // Fermeture du context local
614 TheAISContext()->CloseLocalContext(MyCurrentIndex);
615
161c4476 616 // Construction de l'axe
7fd59977 617 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
618 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
619 gp_Vec V (A,B);
620 gp_Dir D (V);
621 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
622 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
623 GetMapOfAIS().Bind (TheAxis,name);
624 TheAISContext()->Display(TheAxis);
161c4476 625 }
7fd59977 626 else {
627 // Un unique edge (ShapeA) a ete picke
628 // Fermeture du context local
629 TheAISContext()->CloseLocalContext(MyCurrentIndex);
161c4476 630 // Constuction de l'axe
7fd59977 631 TopoDS_Edge ed =TopoDS::Edge(ShapeA);
632 TopoDS_Vertex Va,Vb;
633 TopExp::Vertices(ed,Va,Vb );
634 gp_Pnt A=BRep_Tool::Pnt(Va);
635 gp_Pnt B=BRep_Tool::Pnt(Vb);
636 gp_Vec V (A,B);
637 gp_Dir D (V);
638 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
639 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
640 GetMapOfAIS().Bind (TheAxis,name);
641 TheAISContext()->Display(TheAxis);
642 }
643
644 }
645
646 // Fonction axispara
647 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
648 else if ( !strcasecmp(argv[0], "vaxispara")) {
649
650 TheAISContext()->OpenLocalContext();
651 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
652
161c4476 653 // Active le mode edge
7fd59977 654 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
655 di<<" Select an edge."<<"\n";
656
657 // Boucle d'attente waitpick.
658 Standard_Integer argcc = 5;
659 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
660 const char **argvv = (const char **) buff;
661 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 662 // fin de la boucle
7fd59977 663
664 TopoDS_Shape ShapeA;
665 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
666 ShapeA = TheAISContext()->SelectedShape();
667 }
668 // Active le mode vertex et deactive edges
669 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
670 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
671 di<<" Select a vertex."<<"\n";
672
673 // Boucle d'attente waitpick.
674 Standard_Integer argccc = 5;
675 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
676 const char **argvvv = (const char **) bufff;
677 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 678 // fin de la boucle
7fd59977 679
680 // On peut choisir un pnt sur l'edge
681 TopoDS_Shape ShapeB;
682 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
683 ShapeB = TheAISContext()->SelectedShape();
684 }
685 // Fermeture du context local
686 TheAISContext()->CloseLocalContext(MyCurrentIndex);
687
688 // Construction de l'axe
689 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
690 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
691 TopoDS_Vertex Va,Vc;
692 TopExp::Vertices(ed,Va,Vc );
693 gp_Pnt A=BRep_Tool::Pnt(Va);
694 gp_Pnt C=BRep_Tool::Pnt(Vc);
695 gp_Vec V (A,C);
696 gp_Dir D (V);
697 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
698 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
699 GetMapOfAIS().Bind (TheAxis,name);
700 TheAISContext()->Display(TheAxis);
701
702 }
703
704 // Fonction axisortho
705 else {
706 TheAISContext()->OpenLocalContext();
707 MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
708
161c4476 709 // Active le mode edge
7fd59977 710 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
711 di<<" Select an edge."<<"\n";
712
713 // Boucle d'attente waitpick.
714 Standard_Integer argcc = 5;
715 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
716 const char **argvv = (const char **) buff;
717 while (ViewerMainLoop( argcc, argvv) ) { }
161c4476 718 // fin de la boucle
7fd59977 719
720 TopoDS_Shape ShapeA;
721 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
722 ShapeA = TheAISContext()->SelectedShape();
723 }
724 // Active le mode vertex et deactive edges
725 TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
726 TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
727 di<<" Slect a vertex."<<"\n";
728
729 // Boucle d'attente waitpick.
730 Standard_Integer argccc = 5;
731 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
732 const char **argvvv = (const char **) bufff;
733 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 734 // fin de la boucle
7fd59977 735
736 // On peut choisir un pnt sur l'edge
737 TopoDS_Shape ShapeB;
738 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
739 ShapeB = TheAISContext()->SelectedShape();
740 }
741 // Fermeture du context local
742 TheAISContext()->CloseLocalContext(MyCurrentIndex);
743
744 // Construction de l'axe
745 TopoDS_Edge ed=TopoDS::Edge(ShapeA) ;
746 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
747 TopoDS_Vertex Va,Vc;
748 TopExp::Vertices(ed,Va,Vc );
749 gp_Pnt A=BRep_Tool::Pnt(Va);
750 gp_Pnt C=BRep_Tool::Pnt(Vc);
751 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
752 gp_Vec V (A,E);
753 gp_Dir D (V);
754 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
755 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
756 GetMapOfAIS().Bind (TheAxis,name);
757 TheAISContext()->Display(TheAxis);
758
759 }
760
761 }
762 return 0;
763}
764
765
766//==============================================================================
767// Fonction First click Result
161c4476 768//
7fd59977 769// vpoint vertex AIS_Point=Vertex
770// edge AIS_Point=Middle of the edge
771//==============================================================================
772
773//==============================================================================
774//function : VPointBuilder
775//purpose : Build an AIS_Point from coordinates or with a selected vertex or edge
776//Draw arg : vpoint PoinName [Xa] [Ya] [Za]
777//==============================================================================
778#include <TopoDS_Edge.hxx>
779#include <TopoDS_Vertex.hxx>
780#include <TopExp.hxx>
781#include <AIS_Point.hxx>
782#include <Geom_CartesianPoint.hxx>
783
161c4476 784static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 785{
786 // Declarations
787 Standard_Boolean HasArg;
788 TCollection_AsciiString name;
789 Standard_Integer myCurrentIndex;
790
791 // Verification
792 if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
793 if (argc==5) HasArg=Standard_True;
794 else HasArg=Standard_False;
795
796 name=argv[1];
797 // Fermeture des contextes
798 TheAISContext()->CloseAllContexts();
799
800 // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
801 if (HasArg) {
802 Standard_Real thecoord[3];
803 for(Standard_Integer i=0;i<=2;i++)
91322f44 804 thecoord[i]=Draw::Atof(argv[2+i]);
7fd59977 805 Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
806 Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint );
807 GetMapOfAIS().Bind (myAISPoint,name);
808 TheAISContext()->Display(myAISPoint);
809 }
810
811 // Il n'a pas d'arguments
812 else {
813 TheAISContext()->OpenLocalContext();
814 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
815
816 // Active le mode Vertex et Edges
817 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
818 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
819 di<<" Select a vertex or an edge(build the middle)"<<"\n";
820
821 // Boucle d'attente waitpick.
822 Standard_Integer argcc = 5;
823 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
824 const char **argvv = (const char **) buff;
825 while (ViewerMainLoop( argcc, argvv) ) { }
826 // fin de la boucle
827
828 TopoDS_Shape ShapeA;
829 for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
830 ShapeA= TheAISContext()->SelectedShape();
831 }
832
833 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
834 // Un vertex a ete selectionne
835 // Fermeture du context local
836 TheAISContext()->CloseLocalContext(myCurrentIndex);
837
838 // Construction du point
839 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
840 Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
841 Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint );
842 GetMapOfAIS().Bind(myAISPoint,name);
843 TheAISContext()->Display(myAISPoint);
844 }
845 else {
846 // Un Edge a ete selectionne
847 // Fermeture du context local
848 TheAISContext()->CloseLocalContext(myCurrentIndex);
849
850 // Construction du point milieu de l'edge
851 TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
852 TopoDS_Vertex myVertexA,myVertexB;
853 TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
854 gp_Pnt A=BRep_Tool::Pnt(myVertexA );
855 gp_Pnt B=BRep_Tool::Pnt(myVertexB );
856 // M est le milieu de [AB]
857 Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 );
858 Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM );
859 GetMapOfAIS().Bind(myAISPointM,name);
860 TheAISContext()->Display(myAISPointM);
861 }
862
863 }
864 return 0;
865
866}
867
868//==============================================================================
ceae62f0 869// Function 1st click 2de click 3de click
7fd59977 870// vplane Vertex Vertex Vertex
871// Vertex Edge
872// Edge Vertex
873// Face
874// vplanepara Face Vertex
875// Vertex Face
876// vplaneortho Face Edge
877// Edge Face
878//==============================================================================
879
880//==============================================================================
881//function : VPlaneBuilder
ceae62f0 882//purpose : Build an AIS_Plane from selected entities or Named AIS components
9e8804b6 883//Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
884// [PointName] [PointName] [PointName] [TypeOfSensitivity]
885// [PlaneName] [PointName] [TypeOfSensitivity]
7fd59977 886//==============================================================================
887
35e08fe8 888static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
ceae62f0
A
889 Standard_Integer argc,
890 const char** argv)
7fd59977 891{
892 // Declarations
ceae62f0
A
893 Standard_Boolean hasArg;
894 TCollection_AsciiString aName;
895 Standard_Integer aCurrentIndex;
7fd59977 896
897 // Verification
9e8804b6 898 if (argc<2 || argc>6 )
ceae62f0
A
899 {
900 std::cout<<" Syntax error\n";
901 return 1;
902 }
9e8804b6 903 if (argc == 6 || argc==5 || argc==4)
ceae62f0
A
904 hasArg=Standard_True;
905 else
906 hasArg=Standard_False;
7fd59977 907
ceae62f0
A
908 aName=argv[1];
909 // Close all contexts
7fd59977 910 TheAISContext()->CloseAllContexts();
911
ceae62f0
A
912 // There are some arguments
913 if (hasArg)
914 {
915 if (!GetMapOfAIS().IsBound2(argv[2] ))
916 {
917 std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
918 return 1;
919 }
920 // Get shape from map
921 Handle(AIS_InteractiveObject) aShapeA =
7fd59977 922 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
923
ceae62f0
A
924 // The first argument is an AIS_Point
925 if (!aShapeA.IsNull() &&
926 aShapeA->Type()==AIS_KOI_Datum &&
927 aShapeA->Signature()==1)
928 {
929 // The second argument must also be an AIS_Point
930 if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
931 {
932 std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
933 return 1;
934 }
935 // Get shape from map
936 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 937 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
938 // If B is not an AIS_Point
939 if (aShapeB.IsNull() ||
940 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 941 {
ceae62f0 942 std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
7fd59977 943 return 1;
944 }
ceae62f0
A
945 // The third object is an AIS_Point
946 if (!GetMapOfAIS().IsBound2(argv[4]) )
947 {
948 std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
949 return 1;
950 }
951 // Get shape from map
952 Handle(AIS_InteractiveObject) aShapeC =
7fd59977 953 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
ceae62f0
A
954 // If C is not an AIS_Point
955 if (aShapeC.IsNull() ||
956 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
7fd59977 957 {
ceae62f0 958 std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
7fd59977 959 return 1;
960 }
961
ceae62f0
A
962 // Treatment of objects A, B, C
963 // Downcast an AIS_IO to AIS_Point
964 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
965 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
966 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
7fd59977 967
ceae62f0
A
968 Handle(Geom_CartesianPoint ) aCartPointA =
969 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
7fd59977 970
ceae62f0
A
971 Handle(Geom_CartesianPoint ) aCartPointB =
972 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
7fd59977 973
ceae62f0
A
974 Handle(Geom_CartesianPoint ) aCartPointC =
975 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
7fd59977 976
ceae62f0 977 // Verification that the three points are different
91322f44 978 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
979 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
980 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 981 {
7fd59977 982 // B=A
ceae62f0 983 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 984 }
91322f44 985 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
986 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
987 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 988 {
7fd59977 989 // C=A
ceae62f0 990 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 991 }
91322f44 992 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
993 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
994 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
ceae62f0 995 {
7fd59977 996 // C=B
ceae62f0 997 std::cout<<"vplane error: same points"<<"\n";return 1;
7fd59977 998 }
999
ceae62f0
A
1000 gp_Pnt A = aCartPointA->Pnt();
1001 gp_Pnt B = aCartPointB->Pnt();
1002 gp_Pnt C = aCartPointC->Pnt();
7fd59977 1003
ceae62f0 1004 // Construction of AIS_Plane
7fd59977 1005 GC_MakePlane MkPlane (A,B,C);
ceae62f0
A
1006 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1007 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1008 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1009 if (argc == 6)
1010 {
1011 Standard_Integer aType = Draw::Atoi (argv[5]);
1012 if (aType != 0 && aType != 1)
1013 {
1014 std::cout << "vplane error: wrong type of sensitivity!\n"
1015 << "Should be one of the following values:\n"
1016 << "0 - Interior\n"
1017 << "1 - Boundary"
1018 << std::endl;
1019 return 1;
1020 }
1021 else
1022 {
1023 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1024 }
1025 }
ceae62f0 1026 TheAISContext()->Display(anAISPlane);
7fd59977 1027 }
1028
ceae62f0
A
1029 // The first argument is an AIS_Axis
1030 // Creation of a plane orthogonal to the axis through a point
1031 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1032 // The second argument should be an AIS_Point
7fd59977 1033 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
1034 {
ceae62f0 1035 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1036 return 1;
1037 }
ceae62f0
A
1038 // Get shape from map
1039 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1040 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1041 // If B is not an AIS_Point
1042 if (aShapeB.IsNull() ||
1043 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1044 {
ceae62f0 1045 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1046 return 1;
1047 }
1048
ceae62f0
A
1049 // Treatment of objects A and B
1050 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1051 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1052
ceae62f0
A
1053 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1054 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
7fd59977 1055
ceae62f0
A
1056 gp_Ax1 anAxis = aGeomLineA->Position();
1057 Handle(Geom_CartesianPoint) aCartPointB =
1058 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
7fd59977 1059
ceae62f0
A
1060 gp_Dir D =anAxis.Direction();
1061 gp_Pnt B = aCartPointB->Pnt();
7fd59977 1062
ceae62f0
A
1063 // Construction of AIS_Plane
1064 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1065 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1066 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1067 if (argc == 5)
1068 {
1069 Standard_Integer aType = Draw::Atoi (argv[4]);
1070 if (aType != 0 && aType != 1)
1071 {
1072 std::cout << "vplane error: wrong type of sensitivity!\n"
1073 << "Should be one of the following values:\n"
1074 << "0 - Interior\n"
1075 << "1 - Boundary"
1076 << std::endl;
1077 return 1;
1078 }
1079 else
1080 {
1081 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1082 }
1083 }
ceae62f0 1084 TheAISContext()->Display(anAISPlane);
7fd59977 1085
1086 }
ceae62f0
A
1087 // The first argumnet is an AIS_Plane
1088 // Creation of a plane parallel to the plane passing through the point
1089 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1090 {
1091 // The second argument should be an AIS_Point
1092 if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
1093 {
1094 std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
7fd59977 1095 return 1;
1096 }
ceae62f0
A
1097 // Get shape from map
1098 Handle(AIS_InteractiveObject) aShapeB =
7fd59977 1099 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
ceae62f0
A
1100 // B should be an AIS_Point
1101 if (aShapeB.IsNull() ||
1102 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1103 {
ceae62f0 1104 std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
7fd59977 1105 return 1;
1106 }
1107
ceae62f0
A
1108 // Treatment of objects A and B
1109 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1110 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1111
ceae62f0
A
1112 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1113 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
7fd59977 1114
ceae62f0
A
1115 Handle(Geom_CartesianPoint) aCartPointB =
1116 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1117 gp_Pnt B= aCartPointB->Pnt();
7fd59977 1118
ceae62f0
A
1119 // Construction of an AIS_Plane
1120 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1121 GetMapOfAIS().Bind (anAISPlane, aName);
9e8804b6 1122 if (argc == 5)
1123 {
1124 Standard_Integer aType = Draw::Atoi (argv[4]);
1125 if (aType != 0 && aType != 1)
1126 {
1127 std::cout << "vplane error: wrong type of sensitivity!\n"
1128 << "Should be one of the following values:\n"
1129 << "0 - Interior\n"
1130 << "1 - Boundary"
1131 << std::endl;
1132 return 1;
1133 }
1134 else
1135 {
1136 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1137 }
1138 }
ceae62f0
A
1139 TheAISContext()->Display(anAISPlane);
1140 }
1141 // Error
1142 else
1143 {
1144 std::cout<<"vplane: error 1st object is not an AIS\n";
1145 return 1;
7fd59977 1146 }
7fd59977 1147 }
ceae62f0
A
1148 // There are no arguments
1149 else
1150 {
1151 // Function vplane
1152 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1153 if (!strcasecmp(argv[0], "vplane"))
1154 {
7fd59977 1155 TheAISContext()->OpenLocalContext();
ceae62f0 1156 aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
7fd59977 1157
ceae62f0
A
1158 // Active modes Vertex, Edge and Face
1159 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1160 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1161 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1162 std::cout<<"Select a vertex, a face or an edge\n";
7fd59977 1163
ceae62f0 1164 // Wait for picking
7fd59977 1165 Standard_Integer argcc = 5;
1166 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1167 const char **argvv = (const char **) buff;
1168 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1169 // end of the loop
7fd59977 1170
ceae62f0
A
1171 TopoDS_Shape aShapeA;
1172 for (TheAISContext()->InitSelected();
1173 TheAISContext()->MoreSelected();
1174 TheAISContext()->NextSelected())
1175 {
1176 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1177 }
1178
ceae62f0
A
1179 // aShapeA is a Vertex
1180 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1181 {
1182 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1183 std::cout<<" Select an edge or a different vertex\n";
7fd59977 1184
ceae62f0 1185 // Wait for picking
7fd59977 1186 Standard_Integer argccc = 5;
1187 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1188 const char **argvvv = (const char **) bufff;
1189 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1190 // end of the loop
7fd59977 1191
ceae62f0
A
1192 TopoDS_Shape aShapeB;
1193 for (TheAISContext()->InitSelected();
1194 TheAISContext()->MoreSelected();
1195 TheAISContext()->NextSelected())
1196 {
1197 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1198 }
ceae62f0
A
1199 // aShapeB is a Vertex
1200 if (aShapeB.ShapeType()==TopAbs_VERTEX)
1201 {
1202 // A and B are the same
1203 if (aShapeB.IsSame(aShapeA))
1204 {
1205 std::cout<<" vplane: error, same points selected\n";
1206 return 1;
1207 }
1208 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1209 std::cout<<" Select a different vertex\n";
7fd59977 1210
ceae62f0 1211 // Wait for picking
7fd59977 1212 Standard_Integer argcccc = 5;
1213 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1214 const char **argvvvv = (const char **) buffff;
1215 while (ViewerMainLoop( argcccc, argvvvv) ) { }
ceae62f0 1216 // end of the loop
7fd59977 1217
ceae62f0
A
1218 TopoDS_Shape aShapeC;
1219 for (TheAISContext()->InitSelected();
1220 TheAISContext()->MoreSelected();
1221 TheAISContext()->NextSelected())
1222 {
1223 aShapeC = TheAISContext()->SelectedShape();
1224 }
1225 // aShapeC is the same as A or B
1226 if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
1227 {
1228 std::cout<<" vplane: error, same points selected\n";
1229 return 1;
7fd59977 1230 }
7fd59977 1231
ceae62f0
A
1232 // Close the local context
1233 TheAISContext()->CloseLocalContext(aCurrentIndex);
1234
1235 // Construction of plane
1236 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1237 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1238 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1239 GC_MakePlane MkPlane(A, B, C);
1240 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1241 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1242 GetMapOfAIS().Bind (anAISPlane, aName);
1243 TheAISContext()->Display(anAISPlane);
7fd59977 1244 }
ceae62f0
A
1245 // ShapeB is an edge
1246 else
1247 {
1248 // Verify that the vertex is not on the edge ShapeB
1249 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1250 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
7fd59977 1251
ceae62f0
A
1252 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1253 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1254 {
1255 // The vertex is on the edge
1256 std::cout<<" vplane: error point is on the edge\n";
1257 return 1;
1258 }
1259 else
1260 {
1261 // Close the local context
1262 TheAISContext()->CloseLocalContext(aCurrentIndex);
1263 // Construction of plane
1264 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1265 TopoDS_Vertex aVBa, aVBb;
1266 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1267 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1268 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1269 GC_MakePlane MkPlane (A, aBa, aBb);
1270 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1271 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1272 GetMapOfAIS().Bind (anAISPlane, aName);
1273 TheAISContext()->Display(anAISPlane);
7fd59977 1274 }
7fd59977 1275 }
7fd59977 1276 }
ceae62f0
A
1277 // aShapeA is an edge
1278 else if (aShapeA.ShapeType()==TopAbs_EDGE)
1279 {
1280 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1281 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1282 std::cout<<" Select a vertex that don't belong to the edge\n";
7fd59977 1283
ceae62f0 1284 // Wait for picking
7fd59977 1285 Standard_Integer argccc = 5;
1286 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1287 const char **argvvv = (const char **) bufff;
1288 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1289 // end of the loop
7fd59977 1290
ceae62f0
A
1291 TopoDS_Shape aShapeB;
1292 for (TheAISContext()->InitSelected();
1293 TheAISContext()->MoreSelected();
1294 TheAISContext()->NextSelected())
1295 {
1296 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1297 }
ceae62f0
A
1298 // aShapeB should be a Vertex
1299 // Check that the vertex aShapeB is not on the edge
1300 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1301 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1302
1303 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1304 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1305 {
1306 // The vertex is on the edge
1307 std::cout<<" vplane: error point is on the edge\n";
1308 return 1;
7fd59977 1309 }
ceae62f0
A
1310 else
1311 {
1312 // Close the local context
1313 TheAISContext()->CloseLocalContext(aCurrentIndex);
1314 // Construction of plane
1315 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1316 TopoDS_Vertex aVAa, aVAb;
1317 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1318 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1319 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
7fd59977 1320 GC_MakePlane MkPlane (B,Aa,Ab);
ceae62f0
A
1321 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1322 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1323 GetMapOfAIS().Bind (anAISPlane ,aName);
1324 TheAISContext()->Display(anAISPlane);
7fd59977 1325 }
7fd59977 1326 }
ceae62f0
A
1327 // aShapeA is a Face
1328 else
1329 {
1330 // Close the local context: nothing to select
1331 TheAISContext()->CloseLocalContext(aCurrentIndex);
1332 // Construction of plane
1333 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1334 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1335 if (aSurface.GetType()==GeomAbs_Plane)
1336 {
1337 gp_Pln aPlane = aSurface.Plane();
1338 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1339 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1340 GetMapOfAIS().Bind (anAISPlane, aName);
1341 TheAISContext()->Display(anAISPlane);
7fd59977 1342 }
ceae62f0
A
1343 else
1344 {
1345 std::cout<<" vplane: error\n";
1346 return 1;
7fd59977 1347 }
7fd59977 1348 }
7fd59977 1349 }
1350
ceae62f0 1351 // Function vPlanePara
7fd59977 1352 // ===================
ceae62f0
A
1353 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1354 else if (!strcasecmp(argv[0], "vplanepara"))
1355 {
7fd59977 1356 TheAISContext()->OpenLocalContext();
ceae62f0 1357 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1358
ceae62f0
A
1359 // Activate modes Vertex and Face
1360 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1361 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1362 std::cout<<" Select a vertex or a face\n";
7fd59977 1363
ceae62f0 1364 // Wait for picking
7fd59977 1365 Standard_Integer argcc = 5;
1366 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1367 const char **argvv = (const char **) buff;
1368 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1369 // end of the loop
7fd59977 1370
ceae62f0
A
1371 TopoDS_Shape aShapeA;
1372 for (TheAISContext()->InitSelected();
1373 TheAISContext()->MoreSelected();
1374 TheAISContext()->NextSelected())
1375 {
1376 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1377 }
1378
ceae62f0
A
1379 if (aShapeA.ShapeType()==TopAbs_VERTEX )
1380 {
1381 // aShapeA is a vertex
1382 // Deactivate the mode Vertex
1383 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
1384 std::cout<<" Select a face\n";
7fd59977 1385
ceae62f0 1386 // Wait for picking
7fd59977 1387 Standard_Integer argccc = 5;
1388 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1389 const char **argvvv = (const char **) bufff;
1390 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1391 // end of the loop
7fd59977 1392
ceae62f0
A
1393 TopoDS_Shape aShapeB;
1394 for (TheAISContext()->InitSelected();
1395 TheAISContext()->MoreSelected();
1396 TheAISContext()->NextSelected())
1397 {
1398 // A vertex ShapeA can be on Face ShapeB
1399 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1400 }
1401
ceae62f0
A
1402 // Close the local context
1403 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1404
ceae62f0
A
1405 // Construction of plane
1406 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1407
1408 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1409 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1410 if (aSurface.GetType()==GeomAbs_Plane )
1411 {
1412 gp_Pln aPlane = aSurface.Plane();
1413 // Construct a plane parallel to aGeomPlane through A
1414 aPlane.SetLocation(A);
1415 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1416 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1417 GetMapOfAIS().Bind (aAISPlane ,aName);
1418 TheAISContext()->Display(aAISPlane);
7fd59977 1419 }
ceae62f0
A
1420 else
1421 {
1422 std::cout<<" vplanepara: error\n";
1423 return 1;
7fd59977 1424 }
7fd59977 1425 }
ceae62f0
A
1426 else
1427 {
1428 // ShapeA is a Face
1429 // Deactive the mode Face
1430 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1431 std::cout<<" Select a vertex\n";
7fd59977 1432
ceae62f0 1433 // Wait for picking
7fd59977 1434 Standard_Integer argccc = 5;
1435 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1436 const char **argvvv = (const char **) bufff;
1437 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1438 // end of the loop
7fd59977 1439
ceae62f0
A
1440 TopoDS_Shape aShapeB;
1441 for (TheAISContext()->InitSelected();
1442 TheAISContext()->MoreSelected();
1443 TheAISContext()->NextSelected())
1444 {
1445 // A vertex ShapeB can be on Face ShapeA
1446 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1447 }
ceae62f0
A
1448 // Close the local context
1449 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1450
ceae62f0
A
1451 // Construction of plane
1452 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1453
1454 TopoDS_Face aFace=TopoDS::Face(aShapeA);
1455 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1456 if (aSurface.GetType()==GeomAbs_Plane )
1457 {
1458 gp_Pln aPlane = aSurface.Plane();
1459 aPlane.SetLocation(B);
1460 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1461 // Construct a plane parallel to aGeomPlane through B
1462 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
1463 GetMapOfAIS().Bind (anAISPlane, aName);
1464 TheAISContext()->Display(anAISPlane);
7fd59977 1465 }
ceae62f0
A
1466 else
1467 {
1468 std::cout<<" vplanepara: error"<<"\n";return 1;
7fd59977 1469 }
7fd59977 1470 }
7fd59977 1471 }
1472
ceae62f0 1473 // Function vplaneortho
7fd59977 1474 // ====================
ceae62f0
A
1475 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1476 else
1477 {
7fd59977 1478 TheAISContext()->OpenLocalContext();
ceae62f0 1479 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 1480
ceae62f0
A
1481 // Activate the modes Edge and Face
1482 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1483 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1484 std::cout<<" Select a face and an edge coplanar\n";
7fd59977 1485
ceae62f0 1486 // Wait for picking
7fd59977 1487 Standard_Integer argcc = 5;
1488 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1489 const char **argvv = (const char **) buff;
1490 while (ViewerMainLoop( argcc, argvv) ) { }
ceae62f0 1491 // end of the loop
7fd59977 1492
ceae62f0
A
1493 TopoDS_Shape aShapeA;
1494 for (TheAISContext()->InitSelected();
1495 TheAISContext()->MoreSelected();
1496 TheAISContext()->NextSelected())
1497 {
1498 aShapeA = TheAISContext()->SelectedShape();
7fd59977 1499 }
1500
ceae62f0
A
1501 if (aShapeA.ShapeType()==TopAbs_EDGE )
1502 {
1503 // ShapeA is an edge, deactivate the mode Edge...
1504 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
1505 std::cout<<" Select a face\n";
7fd59977 1506
ceae62f0 1507 // Wait for picking
7fd59977 1508 Standard_Integer argccc = 5;
1509 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1510 const char **argvvv = (const char **) bufff;
1511 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1512 // end of the loop
7fd59977 1513
ceae62f0
A
1514 TopoDS_Shape aShapeB;
1515 for (TheAISContext()->InitSelected();
1516 TheAISContext()->MoreSelected();
1517 TheAISContext()->NextSelected())
1518 {
1519 // Edge ShapeA can be on Face ShapeB
1520 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1521 }
1522
ceae62f0
A
1523 // Close the local context
1524 TheAISContext()->CloseLocalContext(aCurrentIndex);
7fd59977 1525
ceae62f0
A
1526 // Construction of plane
1527 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1528 TopoDS_Vertex aVAa, aVAb;
1529 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1530 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1531 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1532 gp_Vec ab (Aa,Ab);
7fd59977 1533
1534 gp_Dir Dab (ab);
ceae62f0
A
1535 // Creation of rotation axis
1536 gp_Ax1 aRotAxis (Aa,Dab);
1537
1538 TopoDS_Face aFace = TopoDS::Face(aShapeB);
1539 // The edge must be parallel to the face
1540 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1541 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1542 // Compare to heights
1543 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1544 >Precision::Confusion())
1545 {
1546 // the edge is not parallel to the face
1547 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1548 return 1;
7fd59977 1549 }
ceae62f0
A
1550 // the edge is OK
1551 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1552 if (aSurface.GetType()==GeomAbs_Plane)
1553 {
1554 gp_Pln aPlane = aSurface.Plane();
1555 // It rotates a half turn round the axis of rotation
1556 aPlane.Rotate(aRotAxis , M_PI/2);
1557
1558 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1559 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1560 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1561 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1562 GetMapOfAIS().Bind (anAISPlane, aName);
1563 TheAISContext()->Display(anAISPlane);
7fd59977 1564 }
ceae62f0
A
1565 else
1566 {
1567 std::cout<<" vplaneortho: error\n";
1568 return 1;
7fd59977 1569 }
7fd59977 1570 }
ceae62f0
A
1571 else
1572 {
1573 // ShapeA is a Face, deactive the mode Face.
1574 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
1575 std::cout<<" Select an edge\n";
7fd59977 1576
ceae62f0 1577 // Wait for picking
7fd59977 1578 Standard_Integer argccc = 5;
1579 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1580 const char **argvvv = (const char **) bufff;
1581 while (ViewerMainLoop( argccc, argvvv) ) { }
ceae62f0 1582 // end of the loop
7fd59977 1583
ceae62f0
A
1584 TopoDS_Shape aShapeB;
1585 for (TheAISContext()->InitSelected();
1586 TheAISContext()->MoreSelected();
1587 TheAISContext()->NextSelected())
1588 {
1589 // Edge ShapeB can be on Face ShapeA
1590 aShapeB = TheAISContext()->SelectedShape();
7fd59977 1591 }
ceae62f0
A
1592 // Close the local context
1593 TheAISContext()->CloseLocalContext(aCurrentIndex);
1594
1595 // Construction of plane
1596 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1597 TopoDS_Vertex aVBa, aVBb;
1598 TopExp::Vertices(anEdgeB, aVBa, aVBb);
1599 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1600 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1601 gp_Vec ab (aBa,aBb);
7fd59977 1602 gp_Dir Dab (ab);
ceae62f0
A
1603 // Creation of rotation axe
1604 gp_Ax1 aRotAxis (aBa,Dab);
1605
1606 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1607 // The edge must be parallel to the face
1608 BRepExtrema_ExtPF aHeightA (aVBa, aFace);
1609 BRepExtrema_ExtPF aHeightB (aVBb, aFace);
1610 // Comparing the two heights
1611 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1612 >Precision::Confusion())
1613 {
1614 // the edge is not parallel to the face
1615 std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
1616 return 1;
7fd59977 1617 }
ceae62f0
A
1618 // The edge is OK
1619 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1620 if (aSurface.GetType()==GeomAbs_Plane)
1621 {
1622 gp_Pln aPlane = aSurface.Plane();
1623 // It rotates a half turn round the axis of rotation
1624 aPlane.Rotate(aRotAxis , M_PI/2);
1625 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1626 // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
1627 gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
1628 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1629 GetMapOfAIS().Bind (anAISPlane ,aName);
1630 TheAISContext()->Display(anAISPlane);
7fd59977 1631 }
ceae62f0
A
1632 else
1633 {
1634 std::cout<<" vplaneortho: error\n";
1635 return 1;
7fd59977 1636 }
7fd59977 1637 }
7fd59977 1638 }
7fd59977 1639 }
1640 return 0;
7fd59977 1641}
1642
f3889691 1643//===============================================================================================
1644//function : VChangePlane
1645//purpose :
1646//===============================================================================================
1647static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1648{
1649 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1650 if (aContextAIS.IsNull())
1651 {
1652 std::cout << theArgVec[0] << "AIS context is not available.\n";
1653 return 1;
1654 }
1655
1656 if (theArgsNb < 3 || theArgsNb > 11)
1657 {
1658 std::cerr << theArgVec[0]
1659 << ": incorrect number of command arguments.\n"
1660 << "Type help for more information.\n";
1661 return 1;
1662 }
1663
1664 TCollection_AsciiString aName (theArgVec[1]);
1665
1666 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1667 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1668 : NULL;
1669
1670 if ( aPlane.IsNull() )
1671 {
1672 std::cout << theArgVec[0]
1673 << ": there is no interactive plane with the given name."
1674 << "Type help for more information.\n";
1675 return 1;
1676 }
1677
1678 Standard_Real aCenterX = aPlane->Center().X();
1679 Standard_Real aCenterY = aPlane->Center().Y();
1680 Standard_Real aCenterZ = aPlane->Center().Z();
1681
1682 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1683 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1684 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1685
1686 Standard_Real aSizeX = 0.0;
1687 Standard_Real aSizeY = 0.0;
1688 aPlane->Size (aSizeX, aSizeY);
1689 Standard_Boolean isUpdate = Standard_True;
1690
1691 TCollection_AsciiString aPName, aPValue;
1692 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1693 {
1694 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1695 TCollection_AsciiString anArgCase = anArg;
1696 anArgCase.UpperCase();
1697 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1698 {
1699 aPName.UpperCase();
1700 if (aPName.IsEqual ("X"))
1701 {
1702 aCenterX = aPValue.RealValue();
1703 }
1704 else if (aPName.IsEqual ("Y"))
1705 {
1706 aCenterY = aPValue.RealValue();
1707 }
1708 else if (aPName.IsEqual ("Z"))
1709 {
1710 aCenterZ = aPValue.RealValue();
1711 }
1712 else if (aPName.IsEqual ("DX"))
1713 {
1714 aDirX = aPValue.RealValue();
1715 }
1716 else if (aPName.IsEqual ("DY"))
1717 {
1718 aDirY = aPValue.RealValue();
1719 }
1720 else if (aPName.IsEqual ("DZ"))
1721 {
1722 aDirZ = aPValue.RealValue();
1723 }
1724 else if (aPName.IsEqual ("SX"))
1725 {
1726 aSizeX = aPValue.RealValue();
1727 }
1728 else if (aPName.IsEqual ("SY"))
1729 {
1730 aSizeY = aPValue.RealValue();
1731 }
1732 }
1733 else if (anArg.IsEqual ("NOUPDATE"))
1734 {
1735 isUpdate = Standard_False;
1736 }
1737 }
1738
1739 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1740 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1741 aPlane->SetCenter (aCenterPnt);
1742 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1743 aPlane->SetSize (aSizeX, aSizeY);
1744
1745 if (isUpdate)
1746 {
1747 aContextAIS->Update (aPlane, Standard_True);
1748 }
1749
1750 return 0;
1751}
7fd59977 1752
1753//==============================================================================
1754// Fonction vline
1755// --------------- Uniquement par parametre. Pas de selection dans le viewer.
1756//==============================================================================
1757
1758//==============================================================================
1759//function : VLineBuilder
161c4476 1760//purpose : Build an AIS_Line
7fd59977 1761//Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1762// [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1763//==============================================================================
1764#include <Geom_CartesianPoint.hxx>
1765#include <AIS_Line.hxx>
1766
1767
161c4476 1768static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 1769{
1770 Standard_Integer myCurrentIndex;
1771 // Verifications
1772 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
1773 // Fermeture des contextes
1774 TheAISContext()->CloseAllContexts();
1775
1776 // On recupere les parametres
1777 Handle(AIS_InteractiveObject) theShapeA;
1778 Handle(AIS_InteractiveObject) theShapeB;
1779
1780 // Parametres: AIS_Point AIS_Point
1781 // ===============================
1782 if (argc==4) {
1783 theShapeA=
1784 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2]));
1785 // On verifie que c'est bien une AIS_Point
1786 if (!theShapeA.IsNull() &&
1787 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1788 // on recupere le deuxieme AIS_Point
1789 theShapeB=
1790 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
1791 if (theShapeA.IsNull() ||
1792 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1793 {
1794 di <<"vline error: wrong type of 2de argument."<<"\n";
1795 return 1;
1796 }
1797 }
161c4476 1798 else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
7fd59977 1799 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
1800 Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
1801 Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
1802
1803 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
1804 Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA);
1805 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1806
1807 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
1808 Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB);
1809 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1810
1811 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1812 // B=A
1813 di<<"vline error: same points"<<"\n";return 1;
1814 }
1815 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1816 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1817 GetMapOfAIS().Bind(theAISLine,argv[1] );
1818 TheAISContext()->Display(theAISLine );
1819
1820 }
1821
1822 // Parametres 6 Reals
1823 // ==================
1824
1825 else if (argc==8) {
161c4476 1826 // On verifie que les deux points ne sont pas confondus
7fd59977 1827
1828 Standard_Real coord[6];
1829 for(Standard_Integer i=0;i<=2;i++){
91322f44 1830 coord[i]=Draw::Atof(argv[2+i]);
1831 coord[i+3]=Draw::Atof(argv[5+i]);
7fd59977 1832 }
1833
1834 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1835 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1836
1837 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1838 GetMapOfAIS().Bind(theAISLine,argv[1] );
1839 TheAISContext()->Display(theAISLine );
1840
1841 }
1842
1843 // Pas de parametres: Selection dans le viewer.
1844 // ============================================
1845
1846 else {
1847 TheAISContext()->OpenLocalContext();
1848 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1849
1850 // Active le mode Vertex.
1851 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1852 di<<" Select a vertex "<<"\n";
1853
1854 // Boucle d'attente waitpick.
1855 Standard_Integer argcc = 5;
1856 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1857 const char **argvv = (const char **) buff;
1858 while (ViewerMainLoop( argcc, argvv) ) { }
1859 // fin de la boucle
1860
1861 TopoDS_Shape ShapeA;
1862 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1863 ShapeA = TheAISContext()->SelectedShape();
1864 }
1865
1866 // ShapeA est un Vertex
1867 if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1868
1869 di<<" Select a different vertex."<<"\n";
1870
1871 TopoDS_Shape ShapeB;
1872 do {
1873
1874 // Boucle d'attente waitpick.
1875 Standard_Integer argccc = 5;
1876 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1877 const char **argvvv = (const char **) bufff;
1878 while (ViewerMainLoop( argccc, argvvv) ) { }
161c4476 1879 // fin de la boucle
7fd59977 1880
1881 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1882 ShapeB = TheAISContext()->SelectedShape();
1883 }
1884
1885
1886 } while(ShapeB.IsSame(ShapeA) );
1887
1888 // Fermeture du context local
1889 TheAISContext()->CloseLocalContext(myCurrentIndex);
1890
1891 // Construction de la line
1892 gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1893 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1894
1895 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1896 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
1897
1898 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1899 GetMapOfAIS().Bind(theAISLine,argv[1] );
1900 TheAISContext()->Display(theAISLine );
1901
1902 }
1903 else {
1904 di<<"vline error."<<"\n";
1905 }
1906
1907 }
1908
1909 return 0;
1910}
1911
329843e2
A
1912//==============================================================================
1913// class : FilledCircle
1914// purpose : creates filled circle based on AIS_InteractiveObject
1915// and Geom_Circle.
1916// This class is used to check method Matches() of class
1917// Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1918// because none of AIS classes provides creation of
1919// Select3D_SensitiveCircle with member myFillStatus = Standard_True
1920// (look method ComputeSelection() )
1921//==============================================================================
1922
1923Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1924{
1925 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1926 gp_Circ aCirc(anAxes, theRadius);
1927 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1928 return aCircle;
1929}
1930
1931DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1932
1933class FilledCircle : public AIS_InteractiveObject
1934{
1935public:
1936 // CASCADE RTTI
1937 DEFINE_STANDARD_RTTI(FilledCircle);
1938
1939 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1940 FilledCircle(Handle(Geom_Circle) theCircle);
1941
1942private:
1943 TopoDS_Face ComputeFace();
1944
1945 // Virtual methods implementation
1946 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1947 const Handle(Prs3d_Presentation)& thePresentation,
1948 const Standard_Integer theMode);
1949
1950 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
1951 const Standard_Integer theMode);
1952
1953protected:
1954 Handle(Geom_Circle) myCircle;
1955 Standard_Boolean myFilledStatus;
1956
1957};
1958
1959IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
1960IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
1961
1962FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1963{
1964 myCircle = CreateCircle(theCenter, theRadius);
1965 myFilledStatus = Standard_True;
1966}
1967
1968FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1969{
1970 myCircle = theCircle;
1971 myFilledStatus = Standard_True;
1972}
1973
1974TopoDS_Face FilledCircle::ComputeFace()
1975{
1976 // Create edge from myCircle
1977 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
1978 TopoDS_Edge anEdge = anEdgeMaker.Edge();
1979
1980 // Create wire from anEdge
1981 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
1982 TopoDS_Wire aWire = aWireMaker.Wire();
1983
1984 // Create face from aWire
1985 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
1986 TopoDS_Face aFace = aFaceMaker.Face();
1987
1988 return aFace;
1989}
1990
857ffd5e 1991void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
1992 const Handle(Prs3d_Presentation) &thePresentation,
329843e2
A
1993 const Standard_Integer theMode)
1994{
1995 thePresentation->Clear();
1996
1997 TopoDS_Face aFace = ComputeFace();
1998
1999 if (aFace.IsNull()) return;
2000 if (theMode != 0) return;
2001
2002 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2003}
2004
857ffd5e 2005void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 2006 const Standard_Integer /*theMode*/)
329843e2
A
2007{
2008 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
2009 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner,
2010 myCircle, myFilledStatus);
2011 theSelection->Add(aSensitiveCircle);
2012}
7fd59977 2013
2014//==============================================================================
2015// Fonction vcircle
2016// ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2017//==============================================================================
2018
2019//==============================================================================
2020//function : VCircleBuilder
161c4476 2021//purpose : Build an AIS_Circle
329843e2
A
2022//Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2023// PointName PointName PointName IsFilled
7fd59977 2024//==============================================================================
329843e2
A
2025
2026void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2027 TCollection_AsciiString theName,
2028 Standard_Boolean isFilled)
2029{
2030 Handle(AIS_InteractiveObject) aCircle;
2031 if (isFilled)
2032 {
2033 aCircle = new FilledCircle(theGeomCircle);
2034 }
2035 else
2036 {
2037 aCircle = new AIS_Circle(theGeomCircle);
9e8804b6 2038 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
329843e2
A
2039 }
2040
2041 // Check if there is an object with given name
2042 // and remove it from context
2043 if (GetMapOfAIS().IsBound2(theName))
2044 {
2045 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName);
2046 Handle(AIS_InteractiveObject) anInterObj =
2047 Handle(AIS_InteractiveObject)::DownCast(anObj);
2048 TheAISContext()->Remove(anInterObj, Standard_False);
2049 GetMapOfAIS().UnBind2(theName);
2050 }
2051
2052 // Bind the circle to its name
2053 GetMapOfAIS().Bind(aCircle, theName);
2054
2055 // Display the circle
2056 TheAISContext()->Display(aCircle);
2057
2058}
7fd59977 2059
35e08fe8 2060static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
7fd59977 2061{
2062 Standard_Integer myCurrentIndex;
329843e2
A
2063 // Verification of the arguments
2064 if (argc>6 || argc<2)
2065 {
2066 std::cout << "vcircle error: expect 4 arguments.\n";
2067 return 1; // TCL_ERROR
2068 }
7fd59977 2069 TheAISContext()->CloseAllContexts();
2070
329843e2
A
2071 // There are all arguments
2072 if (argc == 6)
2073 {
2074 // Get arguments
2075 TCollection_AsciiString aName(argv[1]);
91322f44 2076 Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
329843e2 2077
7fd59977 2078 Handle(AIS_InteractiveObject) theShapeA;
2079 Handle(AIS_InteractiveObject) theShapeB;
2080
329843e2
A
2081 theShapeA =
2082 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2]));
2083 theShapeB =
2084 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3]));
2085
7fd59977 2086
2087 // Arguments: AIS_Point AIS_Point AIS_Point
2088 // ========================================
329843e2 2089 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
7fd59977 2090 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2091 {
329843e2
A
2092 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2093 {
2094 std::cout << "vcircle error: 2d argument is unexpected to be a point.\n";
2095 return 1; // TCL_ERROR
7fd59977 2096 }
329843e2 2097 // The third object must be a point
7fd59977 2098 Handle(AIS_InteractiveObject) theShapeC =
329843e2 2099 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4]));
7fd59977 2100 if (theShapeC.IsNull() ||
329843e2
A
2101 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2102 {
2103 std::cout << "vcircle error: 3d argument is unexpected to be a point.\n";
2104 return 1; // TCL_ERROR
2105 }
7fd59977 2106 // tag
329843e2
A
2107 // Verify that the three points are different
2108 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2109 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2110 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2111
2112 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2113 Handle(Geom_CartesianPoint) myCartPointA =
2114 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2115
2116 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2117 Handle(Geom_CartesianPoint) myCartPointB =
2118 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2119
2120 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2121 Handle(Geom_CartesianPoint) myCartPointC =
2122 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
7fd59977 2123
2124 // Test A=B
91322f44 2125 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2126 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2127 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
329843e2
A
2128 {
2129 std::cout << "vcircle error: Same points.\n";
2130 return 1; // TCL_ERROR
7fd59977 2131 }
2132 // Test A=C
91322f44 2133 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2134 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2135 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2136 {
2137 std::cout << "vcircle error: Same points.\n";
2138 return 1; // TCL_ERROR
7fd59977 2139 }
2140 // Test B=C
91322f44 2141 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2142 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2143 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2
A
2144 {
2145 std::cout << "vcircle error: Same points.\n";
2146 return 1;// TCL_ERROR
7fd59977 2147 }
329843e2
A
2148 // Construction of the circle
2149 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2150 myCartPointB->Pnt(), myCartPointC->Pnt() );
2151 Handle (Geom_Circle) theGeomCircle;
2152 try
2153 {
2154 theGeomCircle = Cir.Value();
2155 }
2156 catch (StdFail_NotDone)
2157 {
2158 std::cout << "vcircle error: can't create circle\n";
2159 return -1; // TCL_ERROR
2160 }
2161
2162 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2163 }
2164
329843e2 2165 // Arguments: AIS_Plane AIS_Point Real
7fd59977 2166 // ===================================
329843e2
A
2167 else if (theShapeA->Type() == AIS_KOI_Datum &&
2168 theShapeA->Signature() == 7 )
2169 {
2170 if (theShapeB->Type() != AIS_KOI_Datum ||
2171 theShapeB->Signature() != 1 )
2172 {
2173 std::cout << "vcircle error: 2d element is a unexpected to be a point.\n";
2174 return 1; // TCL_ERROR
2175 }
623c29a5 2176 // Check that the radius is >= 0
91322f44 2177 if (Draw::Atof(argv[4]) <= 0 )
329843e2
A
2178 {
2179 std::cout << "vcircle error: the radius must be >=0.\n";
2180 return 1; // TCL_ERROR
7fd59977 2181 }
7fd59977 2182
329843e2
A
2183 // Recover the normal to the plane
2184 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2185 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
7fd59977 2186
329843e2
A
2187 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2188 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2189 Handle(Geom_CartesianPoint) myCartPointB =
2190 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
7fd59977 2191
2192 gp_Pln mygpPlane = myGeomPlane->Pln();
2193 gp_Ax1 thegpAxe = mygpPlane.Axis();
2194 gp_Dir theDir = thegpAxe.Direction();
329843e2 2195 gp_Pnt theCenter = myCartPointB->Pnt();
91322f44 2196 Standard_Real TheR = Draw::Atof(argv[4]);
329843e2
A
2197 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2198 Handle (Geom_Circle) theGeomCircle;
2199 try
2200 {
2201 theGeomCircle = Cir.Value();
2202 }
2203 catch (StdFail_NotDone)
2204 {
2205 std::cout << "vcircle error: can't create circle\n";
2206 return -1; // TCL_ERROR
2207 }
2208
2209 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2210
2211 }
2212
2213 // Error
329843e2
A
2214 else
2215 {
2216 std::cout << "vcircle error: 1st argument is a unexpected type.\n";
2217 return 1; // TCL_ERROR
7fd59977 2218 }
2219
2220 }
329843e2 2221 // No arguments: selection in the viewer
7fd59977 2222 // =========================================
329843e2
A
2223 else
2224 {
2225 // Get the name of the circle
2226 TCollection_AsciiString aName(argv[1]);
7fd59977 2227
2228 TheAISContext()->OpenLocalContext();
329843e2 2229 myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 2230
329843e2 2231 // Activate selection mode for vertices and faces
7fd59977 2232 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2233 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2234 std::cout << " Select a vertex or a face\n";
7fd59977 2235
329843e2 2236 // Wait for picking
7fd59977 2237 Standard_Integer argcc = 5;
2238 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2239 const char **argvv = (const char **) buff;
2240 while (ViewerMainLoop( argcc, argvv) ) { }
329843e2 2241 // end of the loop
7fd59977 2242
2243 TopoDS_Shape ShapeA;
329843e2
A
2244 for(TheAISContext()->InitSelected();
2245 TheAISContext()->MoreSelected();
2246 TheAISContext()->NextSelected() )
2247 {
7fd59977 2248 ShapeA = TheAISContext()->SelectedShape();
2249 }
2250
329843e2
A
2251 // ShapeA is a Vertex
2252 if (ShapeA.ShapeType() == TopAbs_VERTEX )
2253 {
7fd59977 2254 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
ceae62f0 2255 std::cout << " Select a different vertex\n";
7fd59977 2256
2257 TopoDS_Shape ShapeB;
329843e2
A
2258 do
2259 {
2260 // Wait for picking
7fd59977 2261 Standard_Integer argccc = 5;
2262 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2263 const char **argvvv = (const char **) bufff;
2264 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2265 // end of the loop
7fd59977 2266
329843e2
A
2267 for(TheAISContext()->InitSelected();
2268 TheAISContext()->MoreSelected();
2269 TheAISContext()->NextSelected() )
2270 {
7fd59977 2271 ShapeB = TheAISContext()->SelectedShape();
2272 }
7fd59977 2273 } while(ShapeB.IsSame(ShapeA) );
2274
329843e2 2275 // Selection of ShapeC
ceae62f0 2276 std::cout << " Select the last vertex\n";
7fd59977 2277 TopoDS_Shape ShapeC;
329843e2
A
2278 do
2279 {
2280 // Wait for picking
7fd59977 2281 Standard_Integer argcccc = 5;
2282 const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2283 const char **argvvvv = (const char **) buffff;
2284 while (ViewerMainLoop( argcccc, argvvvv) ) { }
329843e2 2285 // end of the loop
7fd59977 2286
329843e2
A
2287 for(TheAISContext()->InitSelected();
2288 TheAISContext()->MoreSelected();
2289 TheAISContext()->NextSelected() )
2290 {
7fd59977 2291 ShapeC = TheAISContext()->SelectedShape();
2292 }
7fd59977 2293 } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
329843e2
A
2294
2295 // Get isFilled
2296 Standard_Boolean isFilled;
2297 std::cout << "Enter filled status (0 or 1)\n";
2298 cin >> isFilled;
7fd59977 2299
329843e2 2300 // Close the local context
7fd59977 2301 TheAISContext()->CloseLocalContext(myCurrentIndex);
2302
329843e2
A
2303 // Construction of the circle
2304 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
2305 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
2306 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
2307
2308 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2309 Handle (Geom_Circle) theGeomCircle;
2310 try
2311 {
2312 theGeomCircle = Cir.Value();
2313 }
2314 catch (StdFail_NotDone)
2315 {
2316 std::cout << "vcircle error: can't create circle\n";
2317 return -1; // TCL_ERROR
2318 }
7fd59977 2319
329843e2 2320 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2321
2322 }
329843e2 2323 // Shape is a face
ceae62f0 2324 else
329843e2 2325 {
ceae62f0 2326 std::cout << " Select a vertex (in your face)\n";
7fd59977 2327 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2328
2329 TopoDS_Shape ShapeB;
329843e2 2330 // Wait for picking
7fd59977 2331 Standard_Integer argccc = 5;
2332 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2333 const char **argvvv = (const char **) bufff;
2334 while (ViewerMainLoop( argccc, argvvv) ) { }
329843e2 2335 // end of the loop
7fd59977 2336
329843e2
A
2337 for(TheAISContext()->InitSelected();
2338 TheAISContext()->MoreSelected();
2339 TheAISContext()->NextSelected() )
2340 {
7fd59977 2341 ShapeB = TheAISContext()->SelectedShape();
2342 }
2343
329843e2
A
2344 // Recover the radius
2345 Standard_Real theRad;
2346 do
2347 {
2348 std::cout << " Enter the value of the radius:\n";
2349 cin >> theRad;
2350 } while (theRad <= 0);
2351
2352 // Get filled status
2353 Standard_Boolean isFilled;
2354 std::cout << "Enter filled status (0 or 1)\n";
2355 cin >> isFilled;
7fd59977 2356
329843e2 2357 // Close the local context
7fd59977 2358 TheAISContext()->CloseLocalContext(myCurrentIndex);
329843e2 2359 // Construction of the circle
7fd59977 2360
329843e2
A
2361 // Recover the normal to the plane. tag
2362 TopoDS_Face myFace = TopoDS::Face(ShapeA);
2363 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2364 gp_Pln myPlane = mySurface.Plane();
2365 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
7fd59977 2366 gp_Pln mygpPlane = theGeomPlane->Pln();
2367 gp_Ax1 thegpAxe = mygpPlane.Axis();
2368 gp_Dir theDir = thegpAxe.Direction();
2369
329843e2
A
2370 // Recover the center
2371 gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
7fd59977 2372
623c29a5 2373 // Construct the circle
329843e2
A
2374 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2375 Handle (Geom_Circle) theGeomCircle;
2376 try
2377 {
2378 theGeomCircle = Cir.Value();
2379 }
2380 catch (StdFail_NotDone)
2381 {
2382 std::cout << "vcircle error: can't create circle\n";
2383 return -1; // TCL_ERROR
2384 }
7fd59977 2385
329843e2
A
2386 DisplayCircle(theGeomCircle, aName, isFilled);
2387
7fd59977 2388 }
2389
7fd59977 2390 }
2391
2392 return 0;
2393}
2394
ceae62f0 2395
7fd59977 2396//===============================================================================================
2397//function : VDrawText
2398//author : psn
2399//purpose : Create a text.
2400//Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
2401//===============================================================================================
2402#include <Graphic3d_Group.hxx>
2403#include <Graphic3d_Structure.hxx>
7fd59977 2404#include <Graphic3d_AspectText3d.hxx>
161c4476 2405#include <Graphic3d_AspectFillArea3d.hxx>
7fd59977 2406#include <Graphic3d_StructureManager.hxx>
2407#include <Graphic3d_VerticalTextAlignment.hxx>
2408#include <Graphic3d_HorizontalTextAlignment.hxx>
2409
aff395a3 2410#include <Font_NameOfFont.hxx>
2411
7fd59977 2412#include <Visual3d_ViewManager.hxx>
7fd59977 2413
2414#include <Standard_DefineHandle.hxx>
2415
7fd59977 2416#include <Prs3d_Root.hxx>
2417#include <Prs3d_Text.hxx>
2418#include <Prs3d_TextAspect.hxx>
7fd59977 2419#include <Prs3d_ShadingAspect.hxx>
2420#include <PrsMgr_PresentationManager3d.hxx>
2421
2422#include <TCollection_ExtendedString.hxx>
2423#include <TCollection_AsciiString.hxx>
2424
2425#include <gp_Pnt.hxx>
2426#include <Quantity_NameOfColor.hxx>
161c4476 2427#include <Quantity_Color.hxx>
7fd59977 2428
2429
2430DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
2431
13a22457
S
2432class MyTextClass:public AIS_InteractiveObject
2433{
7fd59977 2434public:
2435 // CASCADE RTTI
2436 DEFINE_STANDARD_RTTI(MyTextClass );
2437
2438 MyTextClass(){};
2439
161c4476 2440 MyTextClass
7fd59977 2441 (
2442 const TCollection_ExtendedString& , const gp_Pnt& ,
161c4476
K
2443 Quantity_Color color,
2444 Standard_Integer aHJust,
7fd59977 2445 Standard_Integer aVJust ,
161c4476
K
2446 Standard_Real Angle ,
2447 Standard_Boolean Zoom ,
2448 Standard_Real Height,
eeaaaefb 2449 Font_FontAspect FontAspect,
7fd59977 2450 Standard_CString Font
2451 );
2452
2453private:
2454
2455 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2456 const Handle(Prs3d_Presentation)& aPresentation,
2457 const Standard_Integer aMode);
2458
35e08fe8 2459 void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/,
2460 const Standard_Integer /*aMode*/){} ;
7fd59977 2461
2462protected:
2463 TCollection_ExtendedString aText;
2464 gp_Pnt aPosition;
2465 Standard_Real Red;
2466 Standard_Real Green;
2467 Standard_Real Blue;
2468 Standard_Real aAngle;
161c4476 2469 Standard_Real aHeight;
7fd59977 2470 Standard_Boolean aZoomable;
2471 Quantity_Color aColor;
eb4320f2 2472 TCollection_AsciiString aFont;
eeaaaefb 2473 Font_FontAspect aFontAspect;
7fd59977 2474 Graphic3d_HorizontalTextAlignment aHJustification;
2475 Graphic3d_VerticalTextAlignment aVJustification;
2476};
2477
2478
2479
2480IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
161c4476 2481IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
7fd59977 2482
2483
161c4476
K
2484MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
2485 Quantity_Color color = Quantity_NOC_YELLOW,
2486 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
7fd59977 2487 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
2488 Standard_Real angle = 0.0 ,
2489 Standard_Boolean zoomable = Standard_True,
2490 Standard_Real height = 12.,
eeaaaefb 2491 Font_FontAspect fontAspect = Font_FA_Regular,
7fd59977 2492 Standard_CString font = "Courier")
2493{
2494 aText = text;
161c4476 2495 aPosition = position;
7fd59977 2496 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
2497 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
2498 aAngle = angle;
161c4476
K
2499 aZoomable = zoomable;
2500 aHeight = height;
7fd59977 2501 aColor = color;
2502 aFontAspect = fontAspect;
2503 aFont = font;
2504};
2505
2506
2507
2508//////////////////////////////////////////////////////////////////////////////
35e08fe8 2509void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
7fd59977 2510 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 2511 const Standard_Integer /*aMode*/)
7fd59977 2512{
2513
2514 aPresentation->Clear();
2515
857ffd5e 2516 Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect();
7fd59977 2517
eb4320f2 2518 asp->SetFont(aFont.ToCString());
7fd59977 2519 asp->SetColor(aColor);
2520 asp->SetHeight(aHeight); // I am changing the myHeight value
2521
2522 asp->SetHorizontalJustification(aHJustification);
161c4476 2523 asp->SetVerticalJustification(aVJustification);
7fd59977 2524 asp->Aspect()->SetTextZoomable(aZoomable);
2525 asp->Aspect()->SetTextAngle(aAngle);
2526 asp->Aspect()->SetTextFontAspect(aFontAspect);
2527 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
161c4476 2528
7fd59977 2529 /* This comment code is worked
2530 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
2531 Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
2532 Graphic3d_Vertex vertices_text;
2533 vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
2534 TheGroup->SetPrimitivesAspect(aspect);
7fd59977 2535 TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
7fd59977 2536 */
2537};
2538
2539static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2540{
13a22457
S
2541 // Check arguments
2542 if (argc < 14)
7fd59977 2543 {
13a22457
S
2544 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2545 di<<"Usage: type help "<<argv[0]<<"\n";
2546 return 1; //TCL_ERROR
7fd59977 2547 }
13a22457
S
2548
2549 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2550
2551 // Create 3D view if it doesn't exist
2552 if ( aContext.IsNull() )
161c4476 2553 {
13a22457
S
2554 ViewerTest::ViewerInit();
2555 aContext = ViewerTest::GetAISContext();
2556 if( aContext.IsNull() )
2557 {
2558 di << "Error: Cannot create a 3D view\n";
2559 return 1; //TCL_ERROR
2560 }
7fd59977 2561 }
2562
13a22457 2563 // Text position
91322f44 2564 const Standard_Real X = Draw::Atof(argv[2]);
2565 const Standard_Real Y = Draw::Atof(argv[3]);
2566 const Standard_Real Z = Draw::Atof(argv[4]);
13a22457 2567 const gp_Pnt pnt(X,Y,Z);
7fd59977 2568
13a22457 2569 // Text color
91322f44 2570 const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
2571 const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
2572 const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
13a22457 2573 const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
7fd59977 2574
13a22457 2575 // Text alignment
91322f44 2576 const int hor_align = Draw::Atoi(argv[8]);
2577 const int ver_align = Draw::Atoi(argv[9]);
7fd59977 2578
13a22457 2579 // Text angle
91322f44 2580 const Standard_Real angle = Draw::Atof(argv[10]);
7fd59977 2581
13a22457 2582 // Text zooming
91322f44 2583 const Standard_Boolean zoom = Draw::Atoi(argv[11]);
13a22457
S
2584
2585 // Text height
91322f44 2586 const Standard_Real height = Draw::Atof(argv[12]);
13a22457
S
2587
2588 // Text aspect
91322f44 2589 const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
13a22457
S
2590
2591 // Text font
2592 TCollection_AsciiString font;
2593 if(argc < 15)
2594 font.AssignCat("Courier");
2595 else
2596 font.AssignCat(argv[14]);
2597
2598 // Text is multibyte
91322f44 2599 const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
13a22457
S
2600
2601 // Read text string
2602 TCollection_ExtendedString name;
2603 if (isMultibyte)
161c4476 2604 {
13a22457 2605 const char *str = argv[1];
f3f08423 2606 while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
2607 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
13a22457
S
2608 {
2609 unsigned short c1 = *str++;
2610 unsigned short c2 = *str++;
f3f08423 2611 if (!c2) break;
13a22457
S
2612 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2613 }
7fd59977 2614 }
13a22457
S
2615 else
2616 {
2617 name += argv[1];
2618 }
2619
2620 if (name.Length())
2621 {
2622 Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
2623 aContext->Display(myT,Standard_True);
2624 }
2625
161c4476 2626 return 0;
7fd59977 2627}
2628
2629#include <math.h>
2630#include <gp_Pnt.hxx>
2631#include <Graphic3d_ArrayOfPoints.hxx>
2632#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 2633#include <Graphic3d_ArrayOfTriangles.hxx>
2634#include <Poly_Array1OfTriangle.hxx>
2635#include <Poly_Triangle.hxx>
2636#include <Poly_Triangulation.hxx>
2637#include <TColgp_Array1OfPnt.hxx>
2638#include <TShort_Array1OfShortReal.hxx>
2639#include <TShort_HArray1OfShortReal.hxx>
2640
2641#include <AIS_Triangulation.hxx>
7fd59977 2642#include <StdPrs_ToolShadedShape.hxx>
2643#include <Poly_Connect.hxx>
2644#include <TColgp_Array1OfDir.hxx>
2645#include <Graphic3d_GraphicDriver.hxx>
2646
7fd59977 2647#include <TColStd_Array1OfInteger.hxx>
2648#include <TColStd_HArray1OfInteger.hxx>
2649#include <Prs3d_ShadingAspect.hxx>
2650#include <Graphic3d_MaterialAspect.hxx>
2651#include <Graphic3d_AspectFillArea3d.hxx>
2652
2653#include <BRepPrimAPI_MakeCylinder.hxx>
2654#include <TopoDS_Shape.hxx>
2655#include <TopExp_Explorer.hxx>
2656#include <TopAbs.hxx>
2657#include <StdSelect_ShapeTypeFilter.hxx>
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
3150 DEFINE_STANDARD_RTTI(MyPArrayObject);
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
3174IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
3175IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
3176
35e08fe8 3177void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
9558a876 3178 const Handle(Prs3d_Presentation)& aPresentation,
35e08fe8 3179 const Standard_Integer /*aMode*/)
9558a876 3180{
9558a876 3181
eb4320f2 3182 // Parsing array description
9558a876 3183 Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
871fa103 3184 Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
3185 hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
9558a876 3186
eb4320f2 3187 Standard_Integer anArgIndex = 0;
3188 Standard_Integer anArgsCount = myArrayDescription->Length();
3189 TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
3190
9558a876 3191 TCollection_AsciiString aCommand;
eb4320f2 3192 while (anArgIndex < anArgsCount)
9558a876 3193 {
eb4320f2 3194 aCommand = myArrayDescription->Value (anArgIndex);
9558a876 3195 aCommand.LowerCase();
9558a876
A
3196
3197 // vertex command
eb4320f2 3198 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3199 {
3200 // vertex has a normal or normal with color or texel
eb4320f2 3201 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3202 hasNormals = Standard_True;
3203
3204 // vertex has a color
eb4320f2 3205 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3206 hasVColors = Standard_True;
3207
3208 // vertex has a texel
eb4320f2 3209 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
9558a876
A
3210 hasTexels = Standard_True;
3211
3212 aVertexNum++;
3213 }
3214 // bound command
eb4320f2 3215 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876
A
3216 {
3217 // bound has color
eb4320f2 3218 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876
A
3219 hasBColors = Standard_True;
3220
3221 aBoundNum++;
3222 }
3223 // edge command
eb4320f2 3224 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3225 {
9558a876
A
3226 aEdgeNum++;
3227 }
3228 // unknown command
3229 else
eb4320f2 3230 anArgIndex++;
9558a876
A
3231 }
3232
9558a876
A
3233 Handle(Graphic3d_ArrayOfPrimitives) anArray;
3234 if (anArrayType == "points")
a577aaab 3235 {
9558a876 3236 anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
a577aaab 3237 }
9558a876
A
3238 else if (anArrayType == "segments")
3239 anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
3240 else if (anArrayType == "polylines")
3241 anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
871fa103 3242 hasVColors, hasBColors);
9558a876
A
3243 else if (anArrayType == "triangles")
3244 anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
871fa103 3245 hasVColors, hasTexels);
9558a876
A
3246 else if (anArrayType == "trianglefans")
3247 anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
3248 hasNormals, hasVColors,
3249 hasBColors, hasTexels);
3250 else if (anArrayType == "trianglestrips")
3251 anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
3252 hasNormals, hasVColors,
3253 hasBColors, hasTexels);
3254 else if (anArrayType == "quads")
3255 anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
3256 hasNormals, hasVColors,
871fa103 3257 hasTexels);
9558a876
A
3258 else if (anArrayType == "quadstrips")
3259 anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
3260 hasNormals, hasVColors,
3261 hasBColors, hasTexels);
3262 else if (anArrayType == "polygons")
3263 anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
3264 hasNormals, hasVColors, hasBColors,
871fa103 3265 hasTexels);
9558a876 3266
eb4320f2 3267 anArgIndex = 1;
3268 while (anArgIndex < anArgsCount)
9558a876 3269 {
eb4320f2 3270 aCommand = myArrayDescription->Value (anArgIndex);
9558a876
A
3271 aCommand.LowerCase();
3272 if (!aCommand.IsAscii())
3273 break;
3274
3275 // vertex command
eb4320f2 3276 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3277 {
eb4320f2 3278 anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3279 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3280 myArrayDescription->Value (anArgIndex - 1).RealValue());
871fa103 3281 const Standard_Integer aVertIndex = anArray->VertexNumber();
9558a876
A
3282
3283 // vertex has a normal or normal with color or texel
eb4320f2 3284 if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3285 anArray->SetVertexNormal (aVertIndex,
eb4320f2 3286 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3287 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3288 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3289
eb4320f2 3290 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
871fa103 3291 anArray->SetVertexColor (aVertIndex,
eb4320f2 3292 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3293 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3294 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876 3295
eb4320f2 3296 if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
871fa103 3297 anArray->SetVertexTexel (aVertIndex,
eb4320f2 3298 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3299 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3300 }
3301 // bounds command
eb4320f2 3302 else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3303 {
eb4320f2 3304 Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
9558a876 3305
eb4320f2 3306 if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
9558a876 3307 anArray->AddBound (aVertCount,
eb4320f2 3308 myArrayDescription->Value (anArgIndex - 3).RealValue(),
3309 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3310 myArrayDescription->Value (anArgIndex - 1).RealValue());
9558a876
A
3311
3312 else
3313 anArray->AddBound (aVertCount);
3314 }
3315 // edge command
eb4320f2 3316 else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
9558a876 3317 {
871fa103 3318 const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
3319 anArray->AddEdge (aVertIndex);
9558a876
A
3320 }
3321 // unknown command
3322 else
eb4320f2 3323 anArgIndex++;
3324 }
3325
3326 aPresentation->Clear();
3327 if (!myMarkerAspect.IsNull())
3328 {
3329 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
3330 }
3331 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
3332}
3333
3334void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
3335 const Standard_Integer /*theMode*/)
3336{
3337 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
3338
3339 Standard_Integer anArgIndex = 1;
3340 while (anArgIndex < myArrayDescription->Length())
3341 {
3342 if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
3343 {
3344 gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
3345 myArrayDescription->Value (anArgIndex - 2).RealValue(),
3346 myArrayDescription->Value (anArgIndex - 1).RealValue());
3347 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
3348 theSelection->Add (aSensetivePoint);
3349 }
3350 else
3351 {
3352 anArgIndex++;
3353 }
3354 }
3355}
3356
3357bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
3358 const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
3359 Standard_Integer &theArgIndex,
3360 Standard_Integer theArgCount,
3361 Standard_Integer theMaxArgs)
3362{
3363 // check if there is more elements than expected
3364 if (theArgIndex >= theMaxArgs)
3365 return false;
3366
3367 TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
3368 aStrCommand.LowerCase();
3369 if (aStrCommand.Search(theCommand) != 1 ||
3370 theArgIndex + (theArgCount - 1) >= theMaxArgs)
3371 return false;
3372
3373 // go to the first data element
3374 theArgIndex++;
3375
3376 // check data if it can be converted to numeric
3377 for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
3378 {
3379 aStrCommand = theArgsArray->Value (theArgIndex);
3380 if (!aStrCommand.IsRealValue())
3381 return false;
3382 }
3383
3384 return true;
3385}
3386
3387//=============================================================================
3388//function : VDrawPArray
3389//purpose : Draws primitives array from list of vertexes, bounds, edges
3390//=============================================================================
3391
3392static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3393{
3394 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3395 if (aContextAIS.IsNull())
3396 {
3397 di << "Call vinit before!\n";
3398 return 1;
3399 }
3400 else if (argc < 3)
3401 {
3402 di << "Use: " << argv[0] << " Name TypeOfArray"
3403 << " [vertex] ... [bounds] ... [edges]\n"
3404 << " TypeOfArray={ points | segments | polylines | triangles |\n"
3405 << " trianglefans | trianglestrips | quads |\n"
3406 << " quadstrips | polygons }\n"
3407 << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
3408 << " [texel={ 't' tx ty }] } \n"
3409 << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
871fa103 3410 << " edges={ 'e' vertex_id }\n";
eb4320f2 3411 return 1;
3412 }
3413
3414 // read the arguments
3415 Standard_Integer aArgIndex = 1;
3416 TCollection_AsciiString aName (argv[aArgIndex++]);
3417 TCollection_AsciiString anArrayType (argv[aArgIndex++]);
3418
3419 Standard_Boolean hasVertex = Standard_False;
3420
3421 Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
3422 anArgsArray->SetValue (0, anArrayType);
3423
3424 if (anArrayType != "points" &&
3425 anArrayType != "segments" &&
3426 anArrayType != "polylines" &&
3427 anArrayType != "triangles" &&
3428 anArrayType != "trianglefans" &&
3429 anArrayType != "trianglestrips" &&
3430 anArrayType != "quads" &&
3431 anArrayType != "quadstrips" &&
3432 anArrayType != "polygons")
3433 {
3434 di << "Unexpected type of primitives array\n";
3435 return 1;
3436 }
3437
3438 TCollection_AsciiString aCommand;
3439 for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
3440 {
3441 aCommand = argv[anArgIndex];
3442 aCommand.LowerCase();
3443 if (!aCommand.IsAscii())
3444 {
3445 di << "Unexpected argument: #" << aArgIndex - 1 << " , "
3446 << "should be an array element: 'v', 'b', 'e' \n";
3447 break;
3448 }
3449
3450 if (aCommand == "v")
3451 {
3452 hasVertex = Standard_True;
3453 }
3454
3455 anArgsArray->SetValue (anArgIndex - 2, aCommand);
3456 }
3457
3458 if (!hasVertex)
3459 {
3460 di << "You should pass any verticies in the list of array elements\n";
3461 return 1;
3462 }
3463
3464 Handle(Graphic3d_AspectMarker3d) anAspPoints;
3465 if (anArrayType == "points")
3466 {
3467 anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
9558a876
A
3468 }
3469
9558a876 3470 // create primitives array object
eb4320f2 3471 Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
9558a876
A
3472
3473 // register the object in map
3474 VDisplayAISObject (aName, aPObject);
3475
3476 return 0;
3477}
3478
29d43f9c
A
3479//=======================================================================
3480//function : VSetLocation
3481//purpose : Change location of AIS interactive object
3482//=======================================================================
3483
0bd2a43f 3484static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
4e18052b 3485 Standard_Integer theArgNb,
3486 const char** theArgVec)
29d43f9c
A
3487{
3488 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4e18052b 3489 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
29d43f9c
A
3490 if (aContext.IsNull())
3491 {
4e18052b 3492 std::cout << "Error: no active view!\n";
29d43f9c
A
3493 return 1;
3494 }
3495
4e18052b 3496 TCollection_AsciiString aName;
3497 gp_Vec aLocVec;
3498 Standard_Boolean isSetLoc = Standard_False;
3499
3500 Standard_Integer anArgIter = 1;
3501 for (; anArgIter < theArgNb; ++anArgIter)
29d43f9c 3502 {
4e18052b 3503 Standard_CString anArg = theArgVec[anArgIter];
3504 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
3505 {
3506 continue;
3507 }
3508 else if (aName.IsEmpty())
3509 {
3510 aName = anArg;
3511 }
3512 else if (!isSetLoc)
3513 {
3514 isSetLoc = Standard_True;
3515 if (anArgIter + 1 >= theArgNb)
3516 {
3517 std::cout << "Error: syntax error at '" << anArg << "'\n";
3518 return 1;
3519 }
3520 aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
3521 aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
3522 if (anArgIter + 1 < theArgNb)
3523 {
3524 aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
3525 }
3526 }
3527 else
3528 {
3529 std::cout << "Error: unknown argument '" << anArg << "'\n";
3530 return 1;
3531 }
29d43f9c
A
3532 }
3533
29d43f9c 3534 // find object
4e18052b 3535 const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29d43f9c 3536 Handle(AIS_InteractiveObject) anIObj;
4e18052b 3537 if (aMap.IsBound2 (aName))
29d43f9c 3538 {
4e18052b 3539 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
29d43f9c 3540 }
4e18052b 3541 if (anIObj.IsNull())
29d43f9c 3542 {
4e18052b 3543 std::cout << "Error: object '" << aName << "' is not displayed!\n";
3544 return 1;
29d43f9c
A
3545 }
3546
4e18052b 3547 gp_Trsf aTrsf;
3548 aTrsf.SetTranslation (aLocVec);
3549 TopLoc_Location aLocation (aTrsf);
3550 aContext->SetLocation (anIObj, aLocation);
29d43f9c
A
3551 return 0;
3552}
3553
ac04d101
SA
3554//===============================================================================================
3555//function : VConnect
3556//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
0717ddc1 3557//Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
ac04d101
SA
3558//===============================================================================================
3559
0717ddc1 3560static Standard_Integer VConnect (Draw_Interpretor& /*di*/,
3561 Standard_Integer argc,
3562 const char ** argv)
ac04d101 3563{
792c785c 3564 // Check the viewer
3565 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3566 if (aContext.IsNull())
ac04d101 3567 {
792c785c 3568 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3569 return 1; // TCL_ERROR
3570 }
792c785c 3571 // Check argumnets
0717ddc1 3572 if (argc < 6)
ac04d101 3573 {
0717ddc1 3574 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3575 return 1; // TCL_ERROR
3576 }
792c785c 3577
3578 // Get values
3579 Standard_Integer anArgIter = 1;
3580 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3581 Handle(AIS_MultipleConnectedInteractive) anOriginObject;
792c785c 3582 TCollection_AsciiString aColorString (argv[argc-1]);
1d47d8d0 3583 Standard_CString aColorName = "";
792c785c 3584 Standard_Boolean hasColor = Standard_False;
3585 if (aColorString.Search ("color=") != -1)
ac04d101 3586 {
792c785c 3587 hasColor = Standard_True;
3588 aColorString.Remove (1, 6);
3589 aColorName = aColorString.ToCString();
3590 }
3591 Handle(AIS_InteractiveObject) anObject;
3592
0717ddc1 3593 // AIS_MultipleConnectedInteractive
3594 const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
3595 for (Standard_Integer i = 5; i < aNbShapes; ++i)
792c785c 3596 {
0717ddc1 3597 TCollection_AsciiString anOriginObjectName (argv[i]);
792c785c 3598 if (aName.IsEqual (anOriginObjectName))
ac04d101 3599 {
0717ddc1 3600 std::cout << "vconnect error: equal names for connected objects\n";
3601 continue;
ac04d101 3602 }
792c785c 3603 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
3604 {
3605 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
0717ddc1 3606 anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3607 if (anObject.IsNull())
792c785c 3608 {
3609 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
0717ddc1 3610 continue;
792c785c 3611 }
3612 }
3613 else
3614 {
3615 Standard_CString aName = anOriginObjectName.ToCString();
3616 TopoDS_Shape aTDShape = DBRep::Get (aName);
3617 if (aTDShape.IsNull())
3618 {
3619 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
792c785c 3620 continue;
3621 }
0717ddc1 3622 anObject = new AIS_Shape (aTDShape);
3623 anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
792c785c 3624 }
0717ddc1 3625
792c785c 3626 if (anOriginObject.IsNull())
3627 {
0717ddc1 3628 anOriginObject = new AIS_MultipleConnectedInteractive();
792c785c 3629 }
0717ddc1 3630
3631 anOriginObject->Connect (anObject);
3632 }
3633 if (anOriginObject.IsNull())
3634 {
3635 std::cout << "vconect error : can't connect input objects\n";
3636 return 1; // TCL_ERROR
792c785c 3637 }
3638
ac04d101 3639 // Get location data
91322f44 3640 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3641 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3642 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3643
3644 // Create transformation
0717ddc1 3645 gp_Vec aTranslation (aXo, aYo, aZo);
3646
ac04d101 3647 gp_Trsf aTrsf;
0717ddc1 3648 aTrsf.SetTranslationPart (aTranslation);
3649 TopLoc_Location aLocation (aTrsf);
ac04d101 3650
0717ddc1 3651 anOriginObject->SetLocalTransformation (aTrsf);
ac04d101
SA
3652
3653 // Check if there is another object with given name
3654 // and remove it from context
3655 if(GetMapOfAIS().IsBound2(aName))
3656 {
3657 Handle(AIS_InteractiveObject) anObj =
3658 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3659 TheAISContext()->Remove(anObj, Standard_False);
3660 GetMapOfAIS().UnBind2(aName);
3661 }
3662
792c785c 3663 // Bind connected object to its name
0717ddc1 3664 GetMapOfAIS().Bind (anOriginObject, aName);
ac04d101
SA
3665
3666 // Display connected object
0717ddc1 3667 TheAISContext()->Display (anOriginObject);
ac04d101
SA
3668
3669 return 0;
3670}
3671
3672//===============================================================================================
0717ddc1 3673//function : VConnectTo
3674//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
3675//Draw arg : vconnectto name Xo Yo Zo object
ac04d101
SA
3676//===============================================================================================
3677
0717ddc1 3678static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/,
3679 Standard_Integer argc,
3680 const char ** argv)
ac04d101 3681{
792c785c 3682 // Check the viewer
3683 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3684 if (aContext.IsNull())
ac04d101 3685 {
0717ddc1 3686 std::cout << "vconnect error : call vinit before\n";
ac04d101
SA
3687 return 1; // TCL_ERROR
3688 }
0717ddc1 3689 // Check argumnets
3690 if (argc != 6)
ac04d101 3691 {
0717ddc1 3692 std::cout << "vconnect error: expect at least 5 arguments\n";
ac04d101
SA
3693 return 1; // TCL_ERROR
3694 }
792c785c 3695
3696 // Get values
3697 Standard_Integer anArgIter = 1;
3698 TCollection_AsciiString aName (argv[anArgIter++]);
0717ddc1 3699 Handle(AIS_InteractiveObject) anOriginObject;
3700
3701 TCollection_AsciiString anOriginObjectName(argv[5]);
3702 if (aName.IsEqual (anOriginObjectName))
792c785c 3703 {
0717ddc1 3704 std::cout << "vconnect error: equal names for connected objects\n";
3705 return 1; // TCL_ERROR
792c785c 3706 }
0717ddc1 3707 if (GetMapOfAIS().IsBound2 (anOriginObjectName))
ac04d101 3708 {
0717ddc1 3709 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
3710 anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
3711 if (anOriginObject.IsNull())
ac04d101 3712 {
0717ddc1 3713 std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
792c785c 3714 return 1; // TCL_ERROR
3715 }
792c785c 3716 }
792c785c 3717 else
3718 {
0717ddc1 3719 Standard_CString aName = anOriginObjectName.ToCString();
3720 TopoDS_Shape aTDShape = DBRep::Get (aName);
3721 if (aTDShape.IsNull())
792c785c 3722 {
0717ddc1 3723 std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
ac04d101
SA
3724 return 1; // TCL_ERROR
3725 }
0717ddc1 3726 anOriginObject = new AIS_Shape (aTDShape);
ac04d101 3727 }
0717ddc1 3728
3729 // Get location data
91322f44 3730 Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
3731 Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
3732 Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
ac04d101
SA
3733
3734 // Create transformation
0717ddc1 3735 gp_Vec aTranslation (aXo, aYo, aZo);
ac04d101 3736
0717ddc1 3737 gp_Trsf aTrsf;
3738 aTrsf.SetTranslationPart (aTranslation);
3739
792c785c 3740 Handle(AIS_ConnectedInteractive) aConnected;
0717ddc1 3741
3742 aConnected = new AIS_ConnectedInteractive();
3743
3744 aConnected->Connect (anOriginObject, aTrsf);
ac04d101
SA
3745
3746 // Check if there is another object with given name
3747 // and remove it from context
3748 if(GetMapOfAIS().IsBound2(aName))
3749 {
3750 Handle(AIS_InteractiveObject) anObj =
3751 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
3752 TheAISContext()->Remove(anObj, Standard_False);
3753 GetMapOfAIS().UnBind2(aName);
3754 }
3755
0717ddc1 3756 // Bind connected object to its name
792c785c 3757 GetMapOfAIS().Bind (aConnected, aName);
ac04d101 3758
0717ddc1 3759 // Display connected object
792c785c 3760 TheAISContext()->Display (aConnected);
ac04d101
SA
3761
3762 return 0;
3763}
3764
0717ddc1 3765//=======================================================================
3766//function : VDisconnect
3767//purpose :
3768//=======================================================================
3769static Standard_Integer VDisconnect (Draw_Interpretor& di,
3770 Standard_Integer argc,
3771 const char ** argv)
3772{
3773 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3774 if (aContext.IsNull())
3775 {
3776 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3777 return 1;
3778 }
3779
3780 if (argc != 3)
3781 {
3782 std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n";
3783 return 1;
3784 }
3785
3786 TCollection_AsciiString aName (argv[1]);
3787 TCollection_AsciiString anObject (argv[2]);
3788 Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
3789
3790 // find objects
3791 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3792 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3793 if (!aMap.IsBound2 (aName) )
3794 {
3795 std::cout << "Use 'vdisplay' before" << "\n";
3796 return 1;
3797 }
3798
3799 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3800 if (anAssembly.IsNull())
3801 {
3802 di << "Not an assembly" << "\n";
3803 return 1;
3804 }
3805
3806 Handle(AIS_InteractiveObject) anIObj;
3807 if (!aMap.IsBound2 (anObject))
3808 {
3809 // try to interpret second argument as child number
3810 if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
3811 {
3812 Standard_Integer aCounter = 1;
3813 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3814 {
3815 if (aCounter == anObjectNumber)
3816 {
3817 anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
3818 break;
3819 }
3820 ++aCounter;
3821 }
3822 }
3823 else
3824 {
3825 std::cout << "Use 'vdisplay' before" << "\n";
3826 return 1;
3827 }
3828 }
3829
3830 // if object was found by name
3831 if (anIObj.IsNull())
3832 {
3833 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
3834 }
3835
3836 anAssembly->Disconnect (anIObj);
3837 aContext->UpdateCurrentViewer();
3838
3839 return 0;
3840}
3841
3842//=======================================================================
3843//function : VAddConnected
3844//purpose :
3845//=======================================================================
3846static Standard_Integer VAddConnected (Draw_Interpretor& di,
3847 Standard_Integer argc,
3848 const char ** argv)
3849{
3850 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3851 if (aContext.IsNull())
3852 {
3853 std::cout << argv[0] << "error : use 'vinit' command before " << "\n";
3854 return 1;
3855 }
3856
3857 if (argc != 6)
3858 {
3859 std::cout << argv[0] << " error: expect 5 arguments\n";
3860 return 1;
3861 }
3862
3863 TCollection_AsciiString aName (argv[1]);
3864 TCollection_AsciiString anObject (argv[5]);
3865 Standard_Real aX = Draw::Atof (argv[2]);
3866 Standard_Real aY = Draw::Atof (argv[3]);
3867 Standard_Real aZ = Draw::Atof (argv[4]);
3868
3869 // find object
3870 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3871 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3872 if (!aMap.IsBound2 (aName) )
3873 {
3874 std::cout << "Use 'vdisplay' before" << "\n";
3875 return 1;
3876 }
3877
3878 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3879 if (anAssembly.IsNull())
3880 {
3881 di << "Not an assembly" << "\n";
3882 return 1;
3883 }
3884
3885 Handle(AIS_InteractiveObject) anIObj;
3886 if (!aMap.IsBound2 (anObject))
3887 {
3888 std::cout << "Use 'vdisplay' before" << "\n";
3889 return 1;
3890 }
3891
3892 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
3893
3894 gp_Trsf aTrsf;
3895 aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
3896
3897 anAssembly->Connect (anIObj, aTrsf);
3898 TheAISContext()->Display (anAssembly);
3899 TheAISContext()->RecomputeSelectionOnly (anAssembly);
3900 aContext->UpdateCurrentViewer();
3901
3902 return 0;
3903}
3904
3905//=======================================================================
3906//function : VListConnected
3907//purpose :
3908//=======================================================================
0bd2a43f 3909static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
0717ddc1 3910 Standard_Integer argc,
3911 const char ** argv)
3912{
3913 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3914 if (aContext.IsNull())
3915 {
3916 std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n";
3917 return 1;
3918 }
3919
3920 if (argc != 2)
3921 {
3922 std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n";
3923 return 1;
3924 }
3925
3926 TCollection_AsciiString aName (argv[1]);
3927
3928 // find object
3929 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3930 Handle(AIS_MultipleConnectedInteractive) anAssembly;
3931 if (!aMap.IsBound2 (aName) )
3932 {
3933 std::cout << "Use 'vdisplay' before" << "\n";
3934 return 1;
3935 }
3936
3937 anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
3938 if (anAssembly.IsNull())
3939 {
3940 std::cout << "Not an assembly" << "\n";
3941 return 1;
3942 }
3943
3944 std::cout << "Children of " << aName << ":\n";
3945
3946 Standard_Integer aCounter = 1;
3947 for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
3948 {
3949 if (GetMapOfAIS().IsBound1 (anIter.Value()))
3950 {
3951 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value());
3952 std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")";
3953 }
3954
3955 std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name();
3956
3957 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
3958 if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
3959 {
3960 std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
3961 }
3962 std::cout << std::endl;
3963
3964 ++aCounter;
3965 }
3966
3967 return 0;
3968}
3969
9f37b47d 3970namespace
3971{
3972 //! Checks if theMode is already turned on for theObj.
3973 static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
3974 const Handle(AIS_InteractiveObject)& theObj,
3975 const Standard_Integer theMode)
3976 {
3977 TColStd_ListOfInteger anActiveModes;
3978 theAISContext->ActivatedModes (theObj, anActiveModes);
3979 for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
3980 {
3981 if (aModeIt.Value() == theMode)
3982 {
3983 return Standard_True;
3984 }
3985 }
3986 return Standard_False;
3987 }
3988};
3989
ac04d101
SA
3990//===============================================================================================
3991//function : VSetSelectionMode
3992//purpose : Sets input selection mode for input object or for all displayed objects
3993//Draw arg : vselmode [object] mode On/Off (1/0)
3994//===============================================================================================
9f37b47d 3995static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
3996 Standard_Integer theArgc,
3997 const char** theArgv)
ac04d101
SA
3998{
3999 // Check errors
4000 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
9f37b47d 4001 if (anAISContext.IsNull())
ac04d101 4002 {
9f37b47d 4003 std::cerr << "Call vinit before!\n";
4004 return 1;
ac04d101
SA
4005 }
4006
9f37b47d 4007 // Check the arguments
4008 if (theArgc != 3 && theArgc != 4)
ac04d101 4009 {
9f37b47d 4010 std::cerr << "vselmode error : expects at least 2 arguments.\n"
4011 << "Type help "<< theArgv[0] <<" for more information.";
4012 return 1;
ac04d101
SA
4013 }
4014
9f37b47d 4015 // get objects to change selection mode
4016 AIS_ListOfInteractive aTargetIOs;
4017 if (theArgc == 3)
ac04d101 4018 {
9f37b47d 4019 anAISContext->DisplayedObjects (aTargetIOs);
4020 }
4021 else
4022 {
4023 // Check if there is an object with given name in context
4024 const TCollection_AsciiString aNameIO (theArgv[1]);
4025 if (GetMapOfAIS().IsBound2 (aNameIO))
ac04d101 4026 {
9f37b47d 4027 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
4028 if (anIO.IsNull())
ac04d101 4029 {
9f37b47d 4030 std::cerr << "vselmode error : object name is used for non AIS viewer\n";
4031 return 1;
ac04d101 4032 }
9f37b47d 4033 aTargetIOs.Append (anIO);
ac04d101 4034 }
9f37b47d 4035 }
ac04d101 4036
9f37b47d 4037 const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]);
4038 const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]);
4039 if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
4040 {
4041 anAISContext->CloseLocalContext();
ac04d101
SA
4042 }
4043
9f37b47d 4044 if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
ac04d101 4045 {
9f37b47d 4046 if (!anAISContext->HasOpenedContext())
4047 {
4048 anAISContext->OpenLocalContext (Standard_False);
4049 }
ac04d101 4050
9f37b47d 4051 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4052 {
9f37b47d 4053 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4054 if (!InList (anAISContext, anIO, aSelectionMode))
ac04d101 4055 {
9f37b47d 4056 anAISContext->Load (anIO, -1, Standard_True);
4057 anAISContext->Activate (anIO, aSelectionMode);
ac04d101
SA
4058 }
4059 }
9f37b47d 4060 }
ac04d101 4061
9f37b47d 4062 if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
4063 {
4064 if (!anAISContext->HasOpenedContext())
ac04d101 4065 {
9f37b47d 4066 return 0;
ac04d101
SA
4067 }
4068
9f37b47d 4069 for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
ac04d101 4070 {
9f37b47d 4071 const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
4072 if (InList (anAISContext, anIO, aSelectionMode))
ac04d101 4073 {
9f37b47d 4074 anAISContext->Deactivate (anIO, aSelectionMode);
ac04d101
SA
4075 }
4076 }
4077 }
9f37b47d 4078
ac04d101
SA
4079 return 0;
4080}
4081
ceae62f0
A
4082//==========================================================================
4083//class : Triangle
4084//purpose : creates Triangle based on AIS_InteractiveObject.
4085// This class was implemented for testing Select3D_SensitiveTriangle
4086//===========================================================================
4087DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4088class Triangle: public AIS_InteractiveObject
4089{
4090public:
4091 // CASCADE RTTI
4092 DEFINE_STANDARD_RTTI(FilledCircle);
4093 Triangle (const gp_Pnt& theP1,
4094 const gp_Pnt& theP2,
4095 const gp_Pnt& theP3);
4096protected:
4097 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4098 const Handle(Prs3d_Presentation)& thePresentation,
4099 const Standard_Integer theMode);
4100
4101 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
4102 const Standard_Integer theMode);
4103private:
4104 gp_Pnt myPoint1;
4105 gp_Pnt myPoint2;
4106 gp_Pnt myPoint3;
4107};
4108IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
4109IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
4110
4111Triangle::Triangle (const gp_Pnt& theP1,
4112 const gp_Pnt& theP2,
4113 const gp_Pnt& theP3)
4114{
4115 myPoint1 = theP1;
4116 myPoint2 = theP2;
4117 myPoint3 = theP3;
4118}
4119
35e08fe8 4120void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
ceae62f0 4121 const Handle(Prs3d_Presentation)& thePresentation,
35e08fe8 4122 const Standard_Integer /*theMode*/)
ceae62f0
A
4123{
4124 thePresentation->Clear();
4125
4126 BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
4127 anEdgeMaker2(myPoint2, myPoint3),
4128 anEdgeMaker3(myPoint3, myPoint1);
4129
4130 TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
4131 anEdge2 = anEdgeMaker2.Edge(),
4132 anEdge3 = anEdgeMaker3.Edge();
4133 if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
4134 return;
4135
4136 BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
4137 TopoDS_Wire aWire = aWireMaker.Wire();
4138 if(aWire.IsNull()) return;
4139
4140 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
4141 TopoDS_Face aFace = aFaceMaker.Face();
4142 if(aFace.IsNull()) return;
4143
4144 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
4145}
4146
4147void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
35e08fe8 4148 const Standard_Integer /*theMode*/)
ceae62f0
A
4149{
4150 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
4151 Handle(Select3D_SensitiveTriangle) aSensTriangle =
4152 new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
4153 theSelection->Add(aSensTriangle);
4154}
4155
4156//===========================================================================
4157//function : VTriangle
4158//Draw arg : vtriangle Name PointName PointName PointName
4159//purpose : creates and displays Triangle
4160//===========================================================================
4161
4162//function: IsPoint
4163//purpose : checks if the object with theName is AIS_Point,
4164// if yes initialize thePoint from MapOfAIS
4165Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
4166 Handle(AIS_Point)& thePoint)
4167{
4168 Handle(AIS_InteractiveObject) anObject =
4169 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
4170 if(anObject.IsNull() ||
4171 anObject->Type() != AIS_KOI_Datum ||
4172 anObject->Signature() != 1)
4173 {
4174 return Standard_False;
4175 }
4176 thePoint = Handle(AIS_Point)::DownCast(anObject);
4177 if(thePoint.IsNull())
4178 return Standard_False;
4179 return Standard_True;
4180}
4181
4182//function: IsMatch
4183//purpose: checks if thePoint1 is equal to thePoint2
4184Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
4185 const Handle(Geom_CartesianPoint)& thePoint2)
4186{
91322f44 4187 if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
4188 Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
4189 Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
ceae62f0
A
4190 {
4191 return Standard_True;
4192 }
4193 return Standard_False;
4194}
4195
35e08fe8 4196static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
ceae62f0
A
4197 Standard_Integer argc,
4198 const char ** argv)
4199{
4200 // Check arguments
4201 if (argc != 5)
4202 {
4203 std::cout<<"vtriangle error: expects 4 argumnets\n";
4204 return 1; // TCL_ERROR
4205 }
4206
4207 TheAISContext()->CloseAllContexts();
4208
4209 // Get and check values
4210 TCollection_AsciiString aName(argv[1]);
4211
4212 Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
4213 if (!IsPoint(argv[2], aPoint1))
4214 {
4215 std::cout<<"vtriangle error: the 2nd argument must be a point\n";
4216 return 1; // TCL_ERROR
4217 }
4218 if (!IsPoint(argv[3], aPoint2))
4219 {
4220 std::cout<<"vtriangle error: the 3d argument must be a point\n";
4221 return 1; // TCL_ERROR
4222 }
4223 if (!IsPoint(argv[4], aPoint3))
4224 {
4225 std::cout<<"vtriangle error: the 4th argument must be a point\n";
4226 return 1; // TCL_ERROR
4227 }
4228
4229 // Check that points are different
4230 Handle(Geom_CartesianPoint) aCartPoint1 =
4231 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4232 Handle(Geom_CartesianPoint) aCartPoint2 =
4233 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4234 // Test aPoint1 = aPoint2
4235 if (IsMatch(aCartPoint1, aCartPoint2))
4236 {
4237 std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
4238 return 1; // TCL_ERROR
4239 }
4240 // Test aPoint2 = aPoint3
4241 Handle(Geom_CartesianPoint) aCartPoint3 =
4242 Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
4243 if (IsMatch(aCartPoint2, aCartPoint3))
4244 {
4245 std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
4246 return 1; // TCL_ERROR
4247 }
4248 // Test aPoint3 = aPoint1
4249 if (IsMatch(aCartPoint1, aCartPoint3))
4250 {
4251 std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
4252 return 1; // TCL_ERROR
4253 }
4254
4255 // Create triangle
4256 Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
4257 aCartPoint2->Pnt(),
4258 aCartPoint3->Pnt());
4259
4260 // Check if there is an object with given name
4261 // and remove it from context
4262 if (GetMapOfAIS().IsBound2(aName))
4263 {
4264 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4265 Handle(AIS_InteractiveObject) anInterObj =
4266 Handle(AIS_InteractiveObject)::DownCast(anObj);
4267 TheAISContext()->Remove(anInterObj, Standard_False);
4268 GetMapOfAIS().UnBind2(aName);
4269 }
4270
4271 // Bind triangle to its name
4272 GetMapOfAIS().Bind(aTriangle, aName);
4273
4274 // Display triangle
4275 TheAISContext()->Display(aTriangle);
4276 return 0;
4277}
4278
4279//class : SegmentObject
4280//purpose: creates segment based on AIS_InteractiveObject.
4281// This class was implemented for testing Select3D_SensitiveCurve
4282DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4283class SegmentObject: public AIS_InteractiveObject
4284{
4285public:
4286 // CASCADE RTTI
4287 DEFINE_STANDARD_RTTI(SegmentObject);
4288 SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
4289protected:
4290 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4291 const Handle(Prs3d_Presentation)& thePresentation,
4292 const Standard_Integer theMode);
4293
4294 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4295 const Standard_Integer theMode);
4296private:
4297 gp_Pnt myPoint1;
4298 gp_Pnt myPoint2;
4299};
4300IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
4301IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
4302
4303SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
4304{
4305 myPoint1 = thePnt1;
4306 myPoint2 = thePnt2;
4307}
4308
857ffd5e 4309void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
4310 const Handle(Prs3d_Presentation) &thePresentation,
35e08fe8 4311 const Standard_Integer /*theMode*/)
ceae62f0
A
4312{
4313 thePresentation->Clear();
4314 BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
4315 TopoDS_Edge anEdge = anEdgeMaker.Edge();
4316 if (anEdge.IsNull())
4317 return;
4318 BRepAdaptor_Curve aCurveAdaptor(anEdge);
4319 StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
4320}
4321
857ffd5e 4322void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 4323 const Standard_Integer /*theMode*/)
ceae62f0
A
4324{
4325 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
4326 Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
4327 anArray->SetValue(1, myPoint1);
4328 anArray->SetValue(2, myPoint2);
4329 Handle(Select3D_SensitiveCurve) aSensCurve =
4330 new Select3D_SensitiveCurve(anOwner, anArray);
4331 theSelection->Add(aSensCurve);
4332}
4333
4334//=======================================================================
4335//function : VSegment
4336//Draw args : vsegment Name PointName PointName
4337//purpose : creates and displays Segment
4338//=======================================================================
35e08fe8 4339static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
ceae62f0
A
4340 Standard_Integer argc,
4341 const char ** argv)
4342{
4343 // Check arguments
4344 if(argc!=4)
4345 {
4346 std::cout<<"vsegment error: expects 3 arguments\n";
4347 return 1; // TCL_ERROR
4348 }
4349
4350 TheAISContext()->CloseAllContexts();
4351
4352 // Get and check arguments
4353 TCollection_AsciiString aName(argv[1]);
4354 Handle(AIS_Point) aPoint1, aPoint2;
4355 if (!IsPoint(argv[2], aPoint1))
4356 {
4357 std::cout<<"vsegment error: the 2nd argument should be a point\n";
4358 return 1; // TCL_ERROR
4359 }
4360 if (!IsPoint(argv[3], aPoint2))
4361 {
4362 std::cout<<"vsegment error: the 3d argument should be a point\n";
4363 return 1; // TCL_ERROR
4364 }
4365 //Check that points are different
4366 Handle(Geom_CartesianPoint) aCartPoint1 =
4367 Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
4368 Handle(Geom_CartesianPoint) aCartPoint2 =
4369 Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
4370 if(IsMatch(aCartPoint1, aCartPoint2))
4371 {
4372 std::cout<<"vsegment error: equal points\n";
4373 return 1; // TCL_ERROR
4374 }
4375
4376 // Create segment
4377 Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
4378 // Check if there is an object with given name
4379 // and remove it from context
4380 if (GetMapOfAIS().IsBound2(aName))
4381 {
4382 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
4383 Handle(AIS_InteractiveObject) anInterObj =
4384 Handle(AIS_InteractiveObject)::DownCast(anObj);
4385 TheAISContext()->Remove(anInterObj, Standard_False);
4386 GetMapOfAIS().UnBind2(aName);
4387 }
4388
4389 // Bind segment to its name
4390 GetMapOfAIS().Bind(aSegment, aName);
4391
4392 // Display segment
4393 TheAISContext()->Display(aSegment);
4394 return 0;
4395}
4396
59f45b7c 4397//=======================================================================
4398//function : VObjZLayer
4399//purpose : Set or get z layer id for presentable object
4400//=======================================================================
4401
4402static Standard_Integer VObjZLayer (Draw_Interpretor& di,
4403 Standard_Integer argc,
4404 const char ** argv)
4405{
4406 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4407 if (aContext.IsNull())
4408 {
4409 di << argv[0] << "Call 'vinit' before!\n";
4410 return 1;
4411 }
4412
4413 // get operation
4414 TCollection_AsciiString aOperation;
4415 if (argc >= 2)
4416 aOperation = TCollection_AsciiString (argv [1]);
4417
4418 // check for correct arguments
4419 if (!(argc == 4 && aOperation.IsEqual ("set")) &&
4420 !(argc == 3 && aOperation.IsEqual ("get")))
4421 {
4422 di << "Usage : " << argv[0] << " set/get object [layerid]\n";
4423 di << " set - set layer id for interactive object, layerid - z layer id\n";
4424 di << " get - get layer id of interactive object\n";
4425 di << " argument layerid should be passed for set operation only\n";
4426 return 1;
4427 }
4428
4429 // find object
4430 TCollection_AsciiString aName (argv[2]);
4431 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4432 if (!aMap.IsBound2 (aName))
4433 {
4434 di << "Use 'vdisplay' before" << "\n";
4435 return 1;
4436 }
4437
4438 // find interactive object
4439 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4440 Handle(AIS_InteractiveObject) anInterObj =
4441 Handle(AIS_InteractiveObject)::DownCast (anObj);
4442 if (anInterObj.IsNull())
4443 {
4444 di << "Not an AIS interactive object!\n";
4445 return 1;
4446 }
4447
4448 // process operation
4449 if (aOperation.IsEqual ("set"))
4450 {
91322f44 4451 Standard_Integer aLayerId = Draw::Atoi (argv [3]);
59f45b7c 4452 aContext->SetZLayer (anInterObj, aLayerId);
4453 }
4454 else if (aOperation.IsEqual ("get"))
4455 {
4456 di << "Z layer id: " << aContext->GetZLayer (anInterObj);
4457 }
4458
4459 return 0;
4460}
4461
3ddebf91 4462//=======================================================================
4463//function : VPolygonOffset
4464//purpose : Set or get polygon offset parameters
4465//=======================================================================
35e08fe8 4466static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
3ddebf91 4467 Standard_Integer argc,
4468 const char ** argv)
4469{
4470 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4471 if (aContext.IsNull())
4472 {
4473 std::cout << argv[0] << " Call 'vinit' before!\n";
4474 return 1;
4475 }
4476
4477 if (argc > 2 && argc != 5)
4478 {
4479 std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
4480 "without arguments prints the default values" << std::endl;
4481 return 1;
4482 }
4483
4484 // find object
4485 Handle(AIS_InteractiveObject) anInterObj;
4486 if (argc >= 2)
4487 {
4488 TCollection_AsciiString aName (argv[1]);
4489 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4490 if (!aMap.IsBound2 (aName))
4491 {
4492 std::cout << "Use 'vdisplay' before" << std::endl;
4493 return 1;
4494 }
4495
4496 // find interactive object
4497 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
4498 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4499 if (anInterObj.IsNull())
4500 {
4501 std::cout << "Not an AIS interactive object!" << std::endl;
4502 return 1;
4503 }
4504 }
4505
4506 Standard_Integer aMode;
60be1f9b 4507 Standard_ShortReal aFactor, aUnits;
3ddebf91 4508 if (argc == 5)
4509 {
91322f44 4510 aMode = Draw::Atoi(argv[2]);
4511 aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
4512 aUnits = (Standard_ShortReal) Draw::Atof(argv[4]);
3ddebf91 4513
4514 anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
4515 aContext->UpdateCurrentViewer();
4516 return 0;
4517 }
4518 else if (argc == 2)
4519 {
4520 if (anInterObj->HasPolygonOffsets())
4521 {
4522 anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
4523 std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
4524 std::cout << "\tMode: " << aMode << std::endl;
4525 std::cout << "\tFactor: " << aFactor << std::endl;
4526 std::cout << "\tUnits: " << aUnits << std::endl;
4527 return 0;
4528 }
4529 else
4530 {
4531 std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
4532 }
4533 }
4534
4535 std::cout << "Default polygon offset parameters:" << std::endl;
4536 aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
4537 std::cout << "\tMode: " << aMode << std::endl;
4538 std::cout << "\tFactor: " << aFactor << std::endl;
4539 std::cout << "\tUnits: " << aUnits << std::endl;
4540
4541 return 0;
4542}
4543
a2d5ab2e 4544//=======================================================================
4545//function : VShowFaceBoundaries
4546//purpose : Set face boundaries drawing on/off for ais object
4547//=======================================================================
35e08fe8 4548static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
a2d5ab2e 4549 Standard_Integer argc,
4550 const char ** argv)
4551{
4552 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
4553 if (aContext.IsNull ())
4554 {
4555 std::cout << argv[0] << " Call 'vinit' before!\n";
4556 return 1;
4557 }
4558
4559 if ((argc != 3 && argc < 6) || argc > 8)
4560 {
4561 std::cout << "Usage :\n " << argv[0]
4562 << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
4563 << " ObjectName - name of AIS interactive object. \n"
4564 << " if ObjectName = \"\", then set as default\n"
4565 << " settings for all newly displayed objects\n"
4566 << " isOn - flag indicating whether the boundaries\n"
4567 << " should be turned on or off (can be set\n"
4568 << " to 0 (off) or 1 (on)).\n"
4569 << " R, G, B - red, green and blue components of boundary\n"
4570 << " color in range (0 - 255).\n"
4571 << " (default is (0, 0, 0)\n"
4572 << " LineWidth - line width\n"
4573 << " (default is 1)\n"
4574 << " LineStyle - line fill style :\n"
4575 << " 0 - solid \n"
4576 << " 1 - dashed \n"
4577 << " 2 - dot \n"
4578 << " 3 - dashdot\n"
4579 << " (default is solid)";
4580 return 1;
4581 }
4582
4583 TCollection_AsciiString aName (argv[1]);
4584
4585 Quantity_Parameter aRed = 0.0;
4586 Quantity_Parameter aGreen = 0.0;
4587 Quantity_Parameter aBlue = 0.0;
4588 Standard_Real aWidth = 1.0;
4589 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4590
4591 // find object
4592 Handle(AIS_InteractiveObject) anInterObj;
4593
4594 // if name is empty - apply attributes for default aspect
4595 if (!aName.IsEmpty ())
4596 {
4597 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
4598 if (!aMap.IsBound2 (aName))
4599 {
4600 std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
4601 return 1;
4602 }
4603
4604 // find interactive object
4605 Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
4606 anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
4607 if (anInterObj.IsNull ())
4608 {
4609 std::cout << "Not an AIS interactive object!" << std::endl;
4610 return 1;
4611 }
4612 }
4613
4614 const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
4615 TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
4616
4617 // turn boundaries on/off
91322f44 4618 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
a2d5ab2e 4619 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
4620
4621 // set boundary line color
4622 if (argc >= 6)
4623 {
4624 // Text color
91322f44 4625 aRed = Draw::Atof (argv[3])/255.;
4626 aGreen = Draw::Atof (argv[4])/255.;
4627 aBlue = Draw::Atof (argv[5])/255.;
a2d5ab2e 4628 }
4629
4630 // set line width
4631 if (argc >= 7)
4632 {
91322f44 4633 aWidth = (Standard_Real)Draw::Atof (argv[6]);
a2d5ab2e 4634 }
4635
4636 // select appropriate line type
4637 if (argc == 8)
4638 {
91322f44 4639 switch (Draw::Atoi (argv[7]))
a2d5ab2e 4640 {
4641 case 1: aLineType = Aspect_TOL_DASH; break;
4642 case 2: aLineType = Aspect_TOL_DOT; break;
4643 case 3: aLineType = Aspect_TOL_DOTDASH; break;
4644 default:
4645 aLineType = Aspect_TOL_SOLID;
4646 }
4647 }
4648
4649 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
4650
4651 Handle(Prs3d_LineAspect) aBoundaryAspect =
4652 new Prs3d_LineAspect (aColor, aLineType, aWidth);
4653
4654 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
4655
4656 TheAISContext()->Redisplay (anInterObj);
4657
4658 return 0;
4659}
4660
eb4320f2 4661// This class is used for testing markers.
4662DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4663class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
4664{
4665
4666public:
4667
4668 ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
4669 const Standard_Integer& thePointsOnSide,
4670 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
4671 {
4672 myStartPoint = theStartPoint;
4673 myPointsOnSide = thePointsOnSide;
4674 myMarkerAspect = theMarkerAspect;
4675 }
4676
4677 DEFINE_STANDARD_RTTI(MyPArrayObject);
4678
4679private:
4680
4681 void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
4682 const Handle(Prs3d_Presentation)& aPresentation,
4683 const Standard_Integer aMode);
4684
4685 void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4686 const Standard_Integer /*theMode*/);
4687
4688protected:
4689
4690 gp_XYZ myStartPoint;
4691 Standard_Integer myPointsOnSide;
4692 Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
4693};
4694
4695IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4696IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
4697
4698void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
4699 const Handle(Prs3d_Presentation)& aPresentation,
4700 const Standard_Integer /*aMode*/)
4701{
4702 Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
4703 if (myPointsOnSide == 1)
4704 {
4705 anArray->AddVertex (myStartPoint);
4706 }
4707 else
4708 {
4709 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4710 {
4711 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4712 {
4713 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4714 {
4715 anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4716 anArray->SetVertexColor (anArray->VertexNumber(),
4717 i / myPointsOnSide,
4718 j / myPointsOnSide,
4719 k / myPointsOnSide);
4720 }
4721 }
4722 }
4723 }
4724
4725 aPresentation->Clear();
4726 if (!myMarkerAspect.IsNull())
4727 {
4728 Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
4729 }
4730 Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
4731}
4732
4733void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
4734 const Standard_Integer /*theMode*/)
4735{
4736 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
4737
4738 if (myPointsOnSide == 1)
4739 {
4740 gp_Pnt aPoint (myStartPoint);
4741 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4742 theSelection->Add (aSensetivePoint);
4743 }
4744 else
4745 {
4746 for (Standard_Real i = 1; i <= myPointsOnSide; i++)
4747 {
4748 for (Standard_Real j = 1; j <= myPointsOnSide; j++)
4749 {
4750 for (Standard_Real k = 1; k <= myPointsOnSide; k++)
4751 {
4752 gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
4753 Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
4754 theSelection->Add (aSensetivePoint);
4755 }
4756 }
4757 }
4758 }
4759}
a577aaab 4760//=======================================================================
4761//function : VMarkersTest
4762//purpose : Draws an array of markers for testing purposes.
4763//=======================================================================
498ce76b 4764static Standard_Integer VMarkersTest (Draw_Interpretor&,
a577aaab 4765 Standard_Integer theArgNb,
4766 const char** theArgVec)
4767{
4768 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4769 if (aContext.IsNull())
4770 {
4771 std::cerr << "Call 'vinit' before!\n";
4772 return 1;
4773 }
4774
4775 if (theArgNb < 5)
4776 {
4777 std::cerr << "Usage :\n " << theArgVec[0]
4778 << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
4779 return 1;
4780 }
4781
4782 Standard_Integer anArgIter = 1;
4783
4784 TCollection_AsciiString aName (theArgVec[anArgIter++]);
4785 TCollection_AsciiString aFileName;
4786 gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
4787 Atof (theArgVec[anArgIter + 1]),
4788 Atof (theArgVec[anArgIter + 2]));
4789 anArgIter += 3;
4790
4791 Standard_Integer aPointsOnSide = 10;
4792 Standard_Integer aMarkerType = -1;
4793 Standard_Real aScale = 1.0;
4794 for (; anArgIter < theArgNb; ++anArgIter)
4795 {
4796 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4797 if (anArg.Search ("PointsOnSide=") > -1)
4798 {
4799 aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
4800 }
4801 else if (anArg.Search ("MarkerType=") > -1)
4802 {
4803 aMarkerType = anArg.Token ("=", 2).IntegerValue();
4804 }
4805 else if (anArg.Search ("Scale=") > -1)
4806 {
4807 aScale = anArg.Token ("=", 2).RealValue();
4808 }
4809 else if (anArg.Search ("FileName=") > -1)
4810 {
4811 aFileName = anArg.Token ("=", 2);
4812 }
4813 else
4814 {
4815 std::cerr << "Wrong argument: " << anArg << "\n";
4816 return 1;
4817 }
4818 }
4819
4820 Handle(Graphic3d_AspectMarker3d) anAspect;
4821 Handle(Image_AlienPixMap) anImage;
4822 Quantity_Color aColor (Quantity_NOC_GREEN1);
4823 if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
4824 && !aFileName.IsEmpty())
4825 {
4826 anImage = new Image_AlienPixMap();
4827 if (!anImage->Load (aFileName))
4828 {
4829 std::cerr << "Could not load image from file '" << aFileName << "'!\n";
4830 return 1;
4831 }
4832 anAspect = new Graphic3d_AspectMarker3d (anImage);
4833 }
4834 else
4835 {
4836 anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
4837 }
4838
eb4320f2 4839 Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
4840 VDisplayAISObject (aName, aMarkersArray);
a577aaab 4841
4842 return 0;
4843}
4844
725ef85e 4845//! Auxiliary function to parse font aspect style argument
4846static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
4847 Font_FontAspect& theAspect)
4848{
4849 if (theArg == "regular"
4850 || *theArg.ToCString() == 'r')
4851 {
4852 theAspect = Font_FA_Regular;
4853 return Standard_True;
4854 }
4855 else if (theArg == "bolditalic")
4856 {
4857 theAspect = Font_FA_BoldItalic;
4858 return Standard_True;
4859 }
4860 else if (theArg == "bold"
4861 || *theArg.ToCString() == 'b')
4862 {
4863 theAspect = Font_FA_Bold;
4864 return Standard_True;
4865 }
4866 else if (theArg == "italic"
4867 || *theArg.ToCString() == 'i')
4868 {
4869 theAspect = Font_FA_Italic;
4870 return Standard_True;
4871 }
4872 return Standard_False;
4873}
4874
4875//! Auxiliary function
4876static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
4877{
4878 switch (theAspect)
4879 {
4880 case Font_FA_Regular: return "regular";
4881 case Font_FA_BoldItalic: return "bolditalic";
4882 case Font_FA_Bold: return "bold";
4883 case Font_FA_Italic: return "italic";
4884 default: return "undefined";
4885 }
4886}
4887
b514beda 4888//=======================================================================
4889//function : TextToBrep
4890//purpose : Tool for conversion text to occt-shapes
4891//=======================================================================
4892
4893static int TextToBRep (Draw_Interpretor& /*theDI*/,
4894 Standard_Integer theArgNb,
4895 const char** theArgVec)
4896{
4897 // Check arguments
4898 if (theArgNb < 5)
4899 {
4900 std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
4901 return 1;
4902 }
4903
4904 Standard_Integer anArgIter = 1;
4905 Standard_CString aResName = theArgVec[anArgIter++];
4906 Standard_CString aText = theArgVec[anArgIter++];
4907 Standard_CString aFontName = theArgVec[anArgIter++];
4908 const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
4909
4910 Font_BRepFont aFont;
4911 Font_FontAspect aFontAspect = Font_FA_Regular;
4912 Standard_Boolean isCompositeCurve = Standard_False;
4913 gp_Ax3 aPenAx3 (gp::XOY());
4914 gp_Pnt aPenLoc;
4915 while (anArgIter < theArgNb)
4916 {
4917 const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
725ef85e 4918 TCollection_AsciiString anArgCase (anArg);
4919 anArgCase.LowerCase();
4920 if (anArgCase.Search ("x=") > -1)
b514beda 4921 {
4922 aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
4923 }
725ef85e 4924 else if (anArgCase.Search ("y=") > -1)
b514beda 4925 {
4926 aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
4927 }
725ef85e 4928 else if (anArgCase.Search ("z=") > -1)
b514beda 4929 {
4930 aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
4931 }
725ef85e 4932 else if (anArgCase.Search ("composite=") > -1)
b514beda 4933 {
4934 isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
4935 }
725ef85e 4936 else if (parseFontStyle (anArgCase, aFontAspect))
b514beda 4937 {
725ef85e 4938 //
b514beda 4939 }
4940 else
4941 {
4942 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
4943 }
4944 }
4945
4946 aFont.SetCompositeCurveMode (isCompositeCurve);
4947 if (!aFont.Init (aFontName, aFontAspect, aSize))
4948 {
4949 std::cerr << "Font initialization error\n";
4950 return 1;
4951 }
4952
4953 aPenAx3.SetLocation (aPenLoc);
4954 DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
4955 return 0;
4956}
4957
725ef85e 4958//=======================================================================
4959//function : VFont
4960//purpose : Font management
4961//=======================================================================
4962
4963static int VFont (Draw_Interpretor& theDI,
4964 Standard_Integer theArgNb,
4965 const char** theArgVec)
4966{
4967 Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
4968 if (theArgNb < 2)
4969 {
4970 // just print the list of available fonts
4971 Standard_Boolean isFirst = Standard_True;
4972 for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
4973 anIter.More(); anIter.Next())
4974 {
4975 const Handle(Font_SystemFont)& aFont = anIter.Value();
4976 if (!isFirst)
4977 {
4978 theDI << "\n";
4979 }
4980
4981 theDI << aFont->FontName()->String()
4982 << " " << fontStyleString (aFont->FontAspect())
4983 << " " << aFont->FontPath()->String();
4984 isFirst = Standard_False;
4985 }
4986 return 0;
4987 }
4988
4989 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4990 {
4991 const TCollection_AsciiString anArg (theArgVec[anArgIter]);
4992 TCollection_AsciiString anArgCase (anArg);
4993 anArgCase.LowerCase();
4994 if (anArgCase == "find")
4995 {
4996 if (++anArgIter >= theArgNb)
4997 {
4998 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
4999 return 1;
5000 }
5001
5002 Standard_CString aFontName = theArgVec[anArgIter];
5003 Font_FontAspect aFontAspect = Font_FA_Undefined;
5004 if (++anArgIter < theArgNb)
5005 {
5006 anArgCase = theArgVec[anArgIter];
5007 anArgCase.LowerCase();
5008 if (!parseFontStyle (anArgCase, aFontAspect))
5009 {
5010 --anArgIter;
5011 }
5012 }
5013 Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
5014 if (aFont.IsNull())
5015 {
5016 std::cerr << "Error: font '" << aFontName << "' is not found!\n";
5017 continue;
5018 }
5019
5020 theDI << aFont->FontName()->String()
5021 << " " << fontStyleString (aFont->FontAspect())
5022 << " " << aFont->FontPath()->String();
5023 }
5024 else if (anArgCase == "add"
5025 || anArgCase == "register")
5026 {
5027 if (++anArgIter >= theArgNb)
5028 {
5029 std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
5030 return 1;
5031 }
5032 Standard_CString aFontPath = theArgVec[anArgIter];
5033 Standard_CString aFontName = NULL;
5034 Font_FontAspect aFontAspect = Font_FA_Undefined;
5035 if (++anArgIter < theArgNb)
5036 {
5037 if (!parseFontStyle (anArgCase, aFontAspect))
5038 {
5039 aFontName = theArgVec[anArgIter];
5040 }
5041 if (++anArgIter < theArgNb)
5042 {
5043 anArgCase = theArgVec[anArgIter];
5044 anArgCase.LowerCase();
5045 if (!parseFontStyle (anArgCase, aFontAspect))
5046 {
5047 --anArgIter;
5048 }
5049 }
5050 }
5051
5052 Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
5053 if (aFont.IsNull())
5054 {
5055 std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
5056 continue;
5057 }
5058
5059 if (aFontAspect != Font_FA_Undefined
5060 || aFontName != NULL)
5061 {
5062 if (aFontAspect == Font_FA_Undefined)
5063 {
5064 aFontAspect = aFont->FontAspect();
5065 }
5066 Handle(TCollection_HAsciiString) aName = aFont->FontName();
5067 if (aFontName != NULL)
5068 {
5069 aName = new TCollection_HAsciiString (aFontName);
5070 }
5071 aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
5072 }
5073
5074 aMgr->RegisterFont (aFont, Standard_True);
5075 theDI << aFont->FontName()->String()
5076 << " " << fontStyleString (aFont->FontAspect())
5077 << " " << aFont->FontPath()->String();
5078 }
5079 else
5080 {
5081 std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
5082 }
5083 }
5084
5085 return 0;
5086}
5087
5ad539d2 5088//=======================================================================
5089//function : VSetEdgeType
5090//purpose : Edges type management
5091//=======================================================================
5092
5093static int VSetEdgeType (Draw_Interpretor& theDI,
5094 Standard_Integer theArgNum,
5095 const char** theArgs)
5096{
5097 if (theArgNum < 4 || theArgNum > 9)
5098 {
5099 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5100 << theArgs[0] << "' for more information.\n";
5101 return 1;
5102 }
5103
5104 Standard_Boolean isForceRedisplay = Standard_False;
5105
5106 // Get shape name
5107 TCollection_AsciiString aName(theArgs[1]);
5108 if (!GetMapOfAIS().IsBound2 (aName))
5109 {
5110 theDI << theArgs[0] << " error: wrong object name.\n";
5111 return 1;
5112 }
5113
5114 Handle(AIS_InteractiveObject) anObject =
5115 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
5116
5117 // Enable trianle edge mode
5118 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn();
5119
5120 // Parse parameters
5121 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
5122 {
5123 TCollection_AsciiString aParam ((theArgs[anIt]));
5124 if (aParam.Value (1) == '-' && !aParam.IsRealValue())
5125 {
5126 if (aParam.IsEqual ("-type"))
5127 {
5128 if (theArgNum <= anIt + 1)
5129 {
5130 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5131 << aParam.ToCString() << "'.\n";
5132 return 1;
5133 }
5134
5135 TCollection_AsciiString aType = theArgs[++anIt];
5136 aType.UpperCase();
5137
5138 if (aType.IsEqual ("SOLID"))
5139 {
5140 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID);
5141 }
5142 else if (aType.IsEqual ("DASH"))
5143 {
5144 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH);
5145 }
5146 else if (aType.IsEqual ("DOT"))
5147 {
5148 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT);
5149 }
5150 else if (aType.IsEqual ("DOTDASH"))
5151 {
5152 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH);
5153 }
5154 else
5155 {
5156 theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n";
5157 return 1;
5158 }
5159
5160 }
5161 else if (aParam.IsEqual ("-color"))
5162 {
5163 if (theArgNum <= anIt + 3)
5164 {
5165 theDI << theArgs[0] << " error: wrong number of values for parameter '"
5166 << aParam.ToCString() << "'.\n";
5167 return 1;
5168 }
5169
5170 Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
5171 Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
5172 Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
5173 Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
5174 aG > 1 ? aG / 255.0 : aG,
5175 aB > 1 ? aB / 255.0 : aB,
5176 Quantity_TOC_RGB);
5177
5178 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor);
5179 }
5180 else if (aParam.IsEqual ("-force"))
5181 {
5182 isForceRedisplay = Standard_True;
5183 }
5184 else
5185 {
5186 theDI << theArgs[0] << " error: unknown parameter '"
5187 << aParam.ToCString() << "'.\n";
5188 return 1;
5189 }
5190 }
5191 }
5192
5193 // Update shape presentation as aspect parameters were changed
5194 if (isForceRedisplay)
5195 {
5196 ViewerTest::GetAISContext()->Redisplay (anObject);
5197 }
5198 else
5199 {
5200 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5201 }
5202
5203 //Update view
5204 ViewerTest::CurrentView()->Redraw();
5205
5206 return 0;
5207}
5208
5209//=======================================================================
5210//function : VUnsetEdgeType
5211//purpose : Unsets edges visibility in shading mode
5212//=======================================================================
5213
5214static int VUnsetEdgeType (Draw_Interpretor& theDI,
5215 Standard_Integer theArgNum,
5216 const char** theArgs)
5217{
5218 if (theArgNum != 2 && theArgNum != 3)
5219 {
5220 theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
5221 << theArgs[0] << "' for more information.\n";
5222 return 1;
5223 }
5224
5225 Standard_Boolean isForceRedisplay = Standard_False;
5226
5227 // Get shape name
5228 TCollection_AsciiString aName (theArgs[1]);
5229 if (!GetMapOfAIS().IsBound2 (aName))
5230 {
5231 theDI << theArgs[0] << " error: wrong object name.\n";
5232 return 1;
5233 }
5234
5235 Handle(AIS_InteractiveObject) anObject =
5236 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5237
5238 // Enable trianle edge mode
5239 anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
5240
5241 // Parse parameters
5242 if (theArgNum == 3)
5243 {
5244 TCollection_AsciiString aParam ((theArgs[2]));
5245 if (aParam.IsEqual ("-force"))
5246 {
5247 isForceRedisplay = Standard_True;
5248 }
5249 else
5250 {
5251 theDI << theArgs[0] << " error: unknown parameter '"
5252 << aParam.ToCString() << "'.\n";
5253 return 1;
5254 }
5255 }
5256
5257 // Update shape presentation as aspect parameters were changed
5258 if (isForceRedisplay)
5259 {
5260 ViewerTest::GetAISContext()->Redisplay (anObject);
5261 }
5262 else
5263 {
5264 anObject->SetAspect (anObject->Attributes()->ShadingAspect());
5265 }
5266
5267 //Update view
5268 ViewerTest::CurrentView()->Redraw();
5269
5270 return 0;
5271}
5272
53b15292 5273
5274//=======================================================================
5275//function : VVertexMode
5276//purpose : Switches vertex display mode for AIS_Shape or displays the current value
5277//=======================================================================
5278
5279static int VVertexMode (Draw_Interpretor& theDI,
5280 Standard_Integer theArgNum,
5281 const char** theArgs)
5282{
5283 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5284 if (aContext.IsNull())
5285 {
5286 std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5287 return 1;
5288 }
5289
5290 // No arguments --> print the current default vertex draw mode
5291 if (theArgNum == 1)
5292 {
5293 Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
5294 theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5295 return 0;
5296 }
5297
5298 // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
5299 TCollection_AsciiString aParam (theArgs[1]);
5300 if (aParam == "-set")
5301 {
5302 if (theArgNum == 2)
5303 {
5304 std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
5305 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5306 return 1;
5307 }
5308
5309 TCollection_AsciiString aModeStr (theArgs[2]);
5310 Prs3d_VertexDrawMode aNewMode =
5311 aModeStr == "isolated" ? Prs3d_VDM_Isolated :
5312 (aModeStr == "all" ? Prs3d_VDM_All :
5313 Prs3d_VDM_Inherited);
5314
5315 Standard_Boolean aRedrawNeeded = Standard_False;
5316 AIS_ListOfInteractive anObjs;
5317
5318 // No object(s) specified -> use all displayed
5319 if (theArgNum == 3)
5320 {
5321 theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
5322 aContext->DisplayedObjects (anObjs);
5323 aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
5324 aRedrawNeeded = Standard_True;
5325 }
5326
5327 Handle(AIS_InteractiveObject) anObject;
5328 for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
5329 {
5330 TCollection_AsciiString aName (theArgs[aCount]);
5331 if (!GetMapOfAIS().IsBound2 (aName))
5332 {
5333 theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
5334 continue;
5335 }
5336 anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
5337 anObjs.Append (anObject);
5338 }
5339
5340 for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
5341 {
5342 anObject = anIt.Value();
5343 anObject->Attributes()->SetVertexDrawMode (aNewMode);
5344 aContext->Redisplay (anObject, Standard_False);
5345 aRedrawNeeded = Standard_True;
5346 }
5347
5348 if (aRedrawNeeded)
5349 ViewerTest::CurrentView()->Redraw();
5350
5351 return 0;
5352 }
5353
5354 if (theArgNum > 2)
5355 {
5356 std::cout << "Error: invalid number of arguments" << std::endl;
5357 std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
5358 return 1;
5359 }
5360
5361 // One argument (object name) --> print the current vertex draw mode for the object
5362 Handle(AIS_InteractiveObject) anObject =
5363 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
5364 Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
5365 theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
5366 return 0;
5367}
5368
7fd59977 5369//=======================================================================
5370//function : ObjectsCommands
161c4476 5371//purpose :
7fd59977 5372//=======================================================================
5373
5374void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
5375{
5376 const char *group ="AISObjects";
5377 theCommands.Add("vtrihedron",
5378 "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
5379 __FILE__,VTrihedron,group);
5380
161c4476 5381 theCommands.Add("vtri2d",
7fd59977 5382 "vtri2d Name Selection in the viewer only ",
5383 __FILE__,VTrihedron2D ,group);
5384
161c4476 5385 theCommands.Add("vplanetri",
7fd59977 5386 "vplanetri Name Selection in the viewer only ",
5387 __FILE__,VPlaneTrihedron ,group);
5388
5389 theCommands.Add("vsize",
5390 "vsize : vsize [name(Default=Current)] [size(Default=100)] ",
5391 __FILE__,VSize,group);
5392
5393 theCommands.Add("vaxis",
5394 "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
5395 __FILE__,VAxisBuilder,group);
5396
161c4476 5397 theCommands.Add("vaxispara",
7fd59977 5398 "vaxispara nom ",
5399 __FILE__,VAxisBuilder,group);
5400
5401 theCommands.Add("vaxisortho",
5402 "vaxisotho nom ",
5403 __FILE__,VAxisBuilder,group);
5404
5405 theCommands.Add("vpoint",
5406 "vpoint PointName [Xa] [Ya] [Za] ",
5407 __FILE__,VPointBuilder,group);
5408
5409 theCommands.Add("vplane",
9e8804b6 5410 "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]",
7fd59977 5411 __FILE__,VPlaneBuilder,group);
5412
f3889691 5413 theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
5414 " vchangeplane <plane_name>"
5415 " [x=center_x y=center_y z=center_z]"
5416 " [dx=dir_x dy=dir_y dz=dir_z]"
5417 " [sx=size_x sy=size_y]"
5418 " [noupdate]\n"
5419 " - changes parameters of the plane:\n"
5420 " - x y z - center\n"
5421 " - dx dy dz - normal\n"
5422 " - sx sy - plane sizes\n"
5423 " - noupdate - do not update/redisplay the plane in context\n"
5424 " Please enter coordinates in format \"param=value\" in arbitrary order.",
5425 __FILE__, VChangePlane, group);
5426
7fd59977 5427 theCommands.Add("vplanepara",
5428 "vplanepara PlaneName ",
5429 __FILE__,VPlaneBuilder,group);
5430
5431 theCommands.Add("vplaneortho",
5432 "vplaneortho PlaneName ",
5433 __FILE__,VPlaneBuilder,group);
5434
161c4476 5435 theCommands.Add("vline",
7fd59977 5436 "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ",
5437 __FILE__,VLineBuilder,group);
5438
5439 theCommands.Add("vcircle",
329843e2 5440 "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
7fd59977 5441 __FILE__,VCircleBuilder,group);
5442
5443 theCommands.Add("vdrawtext",
13a22457 5444 "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
7fd59977 5445 __FILE__,VDrawText,group);
5446
5447 theCommands.Add("vdrawsphere",
b7cd4ba7 5448 "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
7fd59977 5449 __FILE__,VDrawSphere,group);
5450
29d43f9c 5451 theCommands.Add ("vsetlocation",
4e18052b 5452 "vsetlocation [-noupdate|-update] name x y z"
5453 "\n\t\t: Set new location for an interactive object.",
29d43f9c
A
5454 __FILE__, VSetLocation, group);
5455
3fc57801 5456 theCommands.Add (
5457 "vcomputehlr",
5458 "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]",
5459 __FILE__, VComputeHLR, group);
5460
9558a876 5461 theCommands.Add("vdrawparray",
871fa103 5462 "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 5463 __FILE__,VDrawPArray,group);
ac04d101
SA
5464
5465 theCommands.Add("vconnect",
0717ddc1 5466 "vconnect : assembly_name Xo Yo Zo object1 object2 ..."
5467 " Makes an assembly of object instances located in point (Xo Yo Zo).",
ac04d101
SA
5468 __FILE__, VConnect, group);
5469
0717ddc1 5470 theCommands.Add("vconnectto",
5471 "vconnectto : instance_name Xo Yo Zo object"
5472 " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo).",
5473 __FILE__, VConnectTo,group);
5474
5475 theCommands.Add("vdisconnect",
5476 "vdisconnect assembly_name (object_name | object_number | 'all')"
5477 " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
5478 __FILE__,VDisconnect,group);
5479
5480 theCommands.Add("vaddconnected",
5481 "vaddconnected assembly_name object_name"
5482 "Adds object to assembly.",
5483 __FILE__,VAddConnected,group);
5484
5485 theCommands.Add("vlistconnected",
5486 "vlistconnected assembly_name"
5487 "Lists objects in assembly.",
5488 __FILE__,VListConnected,group);
5489
ac04d101
SA
5490
5491 theCommands.Add("vselmode",
446e9c14 5492 "vselmode : [object] mode_number is_turned_on=(1|0)\n"
5493 " switches selection mode for the determined object or\n"
5494 " for all objects in context.\n"
5495 " mode_number is non-negative integer that has different\n"
5496 " meaning for different interactive object classes.\n"
5497 " For shapes the following mode_number values are allowed:\n"
5498 " 0 - shape\n"
5499 " 1 - vertex\n"
5500 " 2 - edge\n"
5501 " 3 - wire\n"
5502 " 4 - face\n"
5503 " 5 - shell\n"
5504 " 6 - solid\n"
5505 " 7 - compsolid\n"
5506 " 8 - compound\n"
5507 " is_turned_on is:\n"
5508 " 1 if mode is to be switched on\n"
5509 " 0 if mode is to be switched off\n",
ac04d101 5510 __FILE__, VSetSelectionMode, group);
ceae62f0
A
5511
5512 theCommands.Add("vtriangle",
5513 "vtriangle Name PointName PointName PointName",
5514 __FILE__, VTriangle,group);
5515
5516 theCommands.Add("vsegment",
5517 "vsegment Name PointName PointName",
5518 __FILE__, VSegment,group);
59f45b7c 5519
5520 theCommands.Add("vobjzlayer",
5521 "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object",
5522 __FILE__, VObjZLayer, group);
3ddebf91 5523
5524 theCommands.Add("vpolygonoffset",
5525 "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values",
5526 __FILE__, VPolygonOffset, group);
a2d5ab2e 5527
5528 theCommands.Add ("vshowfaceboundary",
5529 "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]"
5530 "- turns on/off drawing of face boundaries for ais object "
5531 "and defines boundary line style.",
5532 __FILE__, VShowFaceBoundary, group);
a577aaab 5533
5534 theCommands.Add ("vmarkerstest",
5535 "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
5536 __FILE__, VMarkersTest, group);
b514beda 5537
5538 theCommands.Add ("text2brep",
5539 "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
5540 __FILE__, TextToBRep, group);
725ef85e 5541 theCommands.Add ("vfont",
5542 "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
5543 "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]",
5544 __FILE__, VFont, group);
5ad539d2 5545
5546 theCommands.Add ("vsetedgetype",
5547 "vsetedgetype usage:\n"
5548 "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
5549 "\n\t\t: Sets edges type and color for input shape",
5550 __FILE__, VSetEdgeType, group);
5551
5552 theCommands.Add ("vunsetedgetype",
5553 "vunsetedgetype usage:\n"
5554 "vunsetedgetype ShapeName [-force]"
5555 "\n\t\t: Unsets edges type and color for input shape",
5556 __FILE__, VUnsetEdgeType, group);
53b15292 5557
5558 theCommands.Add ("vvertexmode",
5559 "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
5560 "vvertexmode - prints the default vertex draw mode\n"
5561 "vvertexmode name - prints the vertex draw mode of the given object\n"
5562 "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
5563 "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
5564 __FILE__, VVertexMode, group);
7fd59977 5565}