0024552: Convertation of the generic classes to the non-generic (BndLib).
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
17// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7fd59977 18// Modified by Robert Coublanc [nov 16-17-18 1998]
19// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20// ViewerTest_ObjectCommands.cxx
21// ViewerTest_RelationCommands.cxx
22// -add Functions and commands for interactive selection of shapes and objects
23// in AIS Viewers. (PickShape(s), PickObject(s),
24
25#include <Standard_Stream.hxx>
26
27#include <ViewerTest.hxx>
28#include <TopLoc_Location.hxx>
29#include <TopTools_HArray1OfShape.hxx>
30#include <TColStd_HArray1OfTransient.hxx>
7fd59977 31#include <OSD_Timer.hxx>
32#include <Geom_Axis2Placement.hxx>
33#include <Geom_Axis1Placement.hxx>
34#include <gp_Trsf.hxx>
35#include <TopExp_Explorer.hxx>
36#include <BRepAdaptor_Curve.hxx>
37#include <StdSelect_ShapeTypeFilter.hxx>
38#include <AIS.hxx>
99c56d44 39#include <AIS_Drawer.hxx>
7fd59977 40#include <AIS_InteractiveObject.hxx>
41#include <AIS_Trihedron.hxx>
42#include <AIS_Axis.hxx>
43#include <AIS_Relation.hxx>
44#include <AIS_TypeFilter.hxx>
45#include <AIS_SignatureFilter.hxx>
cb78155f 46#include <AIS_LocalContext.hxx>
7fd59977 47#include <AIS_ListOfInteractive.hxx>
48#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 49#include <Aspect_InteriorStyle.hxx>
50#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 51#include <Graphic3d_AspectLine3d.hxx>
392ac980 52#include <Graphic3d_TextureRoot.hxx>
692613e5 53#include <Image_AlienPixMap.hxx>
99c56d44 54#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 55#include <Prs3d_IsoAspect.hxx>
cb78155f 56#include <TopTools_MapOfShape.hxx>
7fd59977 57
58#ifdef HAVE_CONFIG_H
59# include <config.h>
60#endif
61#include <stdio.h>
62#ifdef HAVE_STRINGS_H
63# include <strings.h>
64#endif
65
66#include <Draw_Interpretor.hxx>
67#include <TCollection_AsciiString.hxx>
68#include <Draw_PluginMacro.hxx>
69#include <ViewerTest.hxx>
7fd59977 70
71// avoid warnings on 'extern "C"' functions returning C++ classes
72#ifdef WNT
73#define _CRT_SECURE_NO_DEPRECATE
74#pragma warning(4:4190)
75#pragma warning (disable:4996)
76#endif
77
78#include <NIS_InteractiveContext.hxx>
79#include <NIS_Triangulated.hxx>
80extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
81
7fd59977 82#include <Quantity_Color.hxx>
83#include <Quantity_NameOfColor.hxx>
84
85#include <Graphic3d_NameOfMaterial.hxx>
86
87#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
88#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
89
1c88cbaf 90
792c785c 91//=======================================================================
92//function : GetColorFromName
93//purpose : get the Quantity_NameOfColor from a string
94//=======================================================================
7fd59977 95
792c785c 96Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
97{
98 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
99 {
100 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
101 if (strcasecmp (theName, aColorName) == 0)
7fd59977 102 {
792c785c 103 return Quantity_NameOfColor (anIter);
7fd59977 104 }
792c785c 105 }
7fd59977 106
792c785c 107 return DEFAULT_COLOR;
7fd59977 108}
109
110//=======================================================================
111//function : GetMaterialFromName
112//purpose : get the Graphic3d_NameOfMaterial from a string
113//=======================================================================
114
115static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
116{
117 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
118
119 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
120 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
121 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
122 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
123 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
124 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
125 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
126 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
127 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
128 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
129 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
7fd59977 130 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
131 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
132 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
133 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
134 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
135 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
136 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
137 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
138
139 return mat;
140}
141
142//=======================================================================
143//function : GetTypeNames
144//purpose :
145//=======================================================================
146static const char** GetTypeNames()
147{
148 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
149 "Shape","ConnectedShape","MultiConn.Shape",
150 "ConnectedInter.","MultiConn.",
151 "Constraint","Dimension"};
152 static const char** ThePointer = names;
153 return ThePointer;
154}
155
156//=======================================================================
157//function : GetTypeAndSignfromString
158//purpose :
159//=======================================================================
160void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
161{
162 const char ** thefullnames = GetTypeNames();
163 Standard_Integer index(-1);
164
165 for(Standard_Integer i=0;i<=13 && index==-1;i++)
166 if(!strcasecmp(name,thefullnames[i]))
167 index = i;
168
169 if(index ==-1){
170 TheType = AIS_KOI_None;
171 TheSign = -1;
172 return;
173 }
174
175 if(index<=6){
176 TheType = AIS_KOI_Datum;
177 TheSign = index+1;
178 }
179 else if (index <=9){
180 TheType = AIS_KOI_Shape;
181 TheSign = index-7;
182 }
183 else if(index<=11){
184 TheType = AIS_KOI_Object;
185 TheSign = index-10;
186 }
187 else{
188 TheType = AIS_KOI_Relation;
189 TheSign = index-12;
190 }
191
192}
193
194
195
196#include <string.h>
197#include <Draw_Interpretor.hxx>
198#include <Draw.hxx>
199#include <Draw_Appli.hxx>
200#include <DBRep.hxx>
201
202
203#include <TCollection_AsciiString.hxx>
204#include <V3d_Viewer.hxx>
205#include <V3d_View.hxx>
206#include <V3d.hxx>
207
208#include <AIS_InteractiveContext.hxx>
209#include <AIS_Shape.hxx>
210#include <AIS_TexturedShape.hxx>
211#include <AIS_DisplayMode.hxx>
212#include <TColStd_MapOfInteger.hxx>
213#include <AIS_MapOfInteractive.hxx>
214#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
215#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
216#include <ViewerTest_EventManager.hxx>
217
218#include <TopoDS_Solid.hxx>
219#include <BRepTools.hxx>
220#include <BRep_Builder.hxx>
221#include <TopAbs_ShapeEnum.hxx>
222
223#include <TopoDS.hxx>
224#include <BRep_Tool.hxx>
225
226
227#include <Draw_Window.hxx>
228#include <AIS_ListIteratorOfListOfInteractive.hxx>
229#include <AIS_ListOfInteractive.hxx>
230#include <AIS_DisplayMode.hxx>
231#include <TopTools_ListOfShape.hxx>
232#include <BRepOffsetAPI_MakeThickSolid.hxx>
233#include <BRepOffset.hxx>
234
7fd59977 235//==============================================================================
236// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
237//==============================================================================
238Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
239 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
240 return TheMap;
241}
242
9558a876
A
243
244//==============================================================================
245//function : VDisplayAISObject
246//purpose : register interactive object in the map of AIS objects;
247// if other object with such name already registered, it will be kept
248// or replaced depending on value of <theReplaceIfExists>,
249// if "true" - the old object will be cleared from AIS context;
250// returns Standard_True if <theAISObj> registered in map;
251//==============================================================================
252Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
253 const Handle(AIS_InteractiveObject)& theAISObj,
254 Standard_Boolean theReplaceIfExists = Standard_True)
255{
256 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
257 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
258 if (aContextAIS.IsNull())
259 {
260 std::cout << "AIS context is not available.\n";
261 return Standard_False;
262 }
263
264 if (aMap.IsBound2 (theName))
265 {
266 if (!theReplaceIfExists)
267 {
268 std::cout << "Other interactive object has been already "
269 << "registered with name: " << theName << ".\n"
270 << "Please use another name.\n";
271 return Standard_False;
272 }
273
274 // stop displaying object
275 Handle(AIS_InteractiveObject) anOldObj =
276 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
277
278 if (!anOldObj.IsNull())
279 aContextAIS->Clear (anOldObj, Standard_True);
280
281 // remove name and old object from map
282 aMap.UnBind2 (theName);
283 }
284
208e6839 285 if (theAISObj.IsNull())
286 {
287 // object with specified name already unbound
288 return Standard_True;
289 }
290
9558a876
A
291 // unbind AIS object if was bound with another name
292 aMap.UnBind1 (theAISObj);
293
294 // can be registered without rebinding
295 aMap.Bind (theAISObj, theName);
296 aContextAIS->Display (theAISObj, Standard_True);
297 return Standard_True;
298}
299
7fd59977 300static TColStd_MapOfInteger theactivatedmodes(8);
301static TColStd_ListOfTransient theEventMgrs;
302
303static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
304 const Handle(AIS_InteractiveContext)& Ctx)
305{
306 theEventMgrs.Clear();
307 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
308}
309
24de79c3 310static Handle(V3d_View)& a3DView()
311{
7fd59977 312 static Handle(V3d_View) Viou;
313 return Viou;
314}
315
24de79c3 316
7fd59977 317Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
318 static Handle(AIS_InteractiveContext) aContext;
319 return aContext;
320}
321
24de79c3 322const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 323{
324 return a3DView();
325}
326void ViewerTest::CurrentView(const Handle(V3d_View)& V)
327{
328 a3DView() = V;
329}
330
331Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
332{
333 static Handle(NIS_InteractiveContext) aContext;
334 if (aContext.IsNull()) {
335 aContext = new NIS_InteractiveContext;
336 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
337 }
338 return aContext;
339}
340
24de79c3 341const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 342{
343 return TheAISContext();
344}
345
346void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
347{
348 TheAISContext() = aCtx;
349 ViewerTest::ResetEventManager();
350}
351
352Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
353{
4952a30a 354 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 355}
356
357Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
358{
4952a30a 359 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 360}
361
362
363void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
364 theEventMgrs.Prepend(EM);
365}
366
367void ViewerTest::UnsetEventManager()
368{
369 theEventMgrs.RemoveFirst();
370}
371
372
373void ViewerTest::ResetEventManager()
374{
375 const Handle(NIS_View) aView =
376 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
377 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
378}
379
380Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
381{
382 Handle(ViewerTest_EventManager) EM;
383 if(theEventMgrs.IsEmpty()) return EM;
384 Handle(Standard_Transient) Tr = theEventMgrs.First();
385 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
386 return EM;
387}
388
389
390//=======================================================================
391//function : Get Context and active viou..
392//purpose :
393//=======================================================================
394void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
395 Handle(V3d_View)& Viou)
396{
397 Ctx = ViewerTest::GetAISContext();
398 if (!Ctx.IsNull())
399 {
400 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
401 Vwr->InitActiveViews();
402 if(Vwr->MoreActiveViews())
403 Viou = Vwr->ActiveView();
404 }
405}
406
407
408//==============================================================================
409//function : GetShapeFromName
410//purpose : Compute an Shape from a draw variable or a file name
411//==============================================================================
412
413static TopoDS_Shape GetShapeFromName(const char* name)
414{
415 TopoDS_Shape S = DBRep::Get(name);
416
417 if ( S.IsNull() ) {
418 BRep_Builder aBuilder;
419 BRepTools::Read( S, name, aBuilder);
420 }
421
422 return S;
423}
4e18e72a 424
7fd59977 425//==============================================================================
426//function : GetAISShapeFromName
427//purpose : Compute an AIS_Shape from a draw variable or a file name
428//==============================================================================
429Handle(AIS_Shape) GetAISShapeFromName(const char* name)
430{
431 Handle(AIS_Shape) retsh;
432
433 if(GetMapOfAIS().IsBound2(name)){
434 const Handle(AIS_InteractiveObject) IO =
435 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
436 if (!IO.IsNull()) {
eafb234b 437 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 438 if(IO->Signature()==0){
439 retsh = *((Handle(AIS_Shape)*)&IO);
440 }
441 else
442 cout << "an Object which is not an AIS_Shape "
443 "already has this name!!!"<<endl;
eafb234b 444 }
7fd59977 445 }
446 return retsh;
447 }
448
449
450 TopoDS_Shape S = GetShapeFromName(name);
451 if ( !S.IsNull() ) {
452 retsh = new AIS_Shape(S);
453 }
454 return retsh;
455}
456
457
458//==============================================================================
459//function : Clear
460//purpose : Remove all the object from the viewer
461//==============================================================================
462void ViewerTest::Clear()
463{
464 if ( !a3DView().IsNull() ) {
465 if (TheAISContext()->HasOpenedContext())
466 TheAISContext()->CloseLocalContext();
467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
468 while ( it.More() ) {
469 cout << "Remove " << it.Key2() << endl;
470 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
471 const Handle(AIS_InteractiveObject) anObj =
472 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
473 TheAISContext()->Remove(anObj,Standard_False);
474 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
475 const Handle(NIS_InteractiveObject) anObj =
476 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
ffe2bea7 477 TheNISContext()->Remove(anObj);
7fd59977 478 }
479 it.Next();
480 }
481 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 482// TheNISContext()->UpdateViews();
7fd59977 483 GetMapOfAIS().Clear();
484 }
485}
486
487//==============================================================================
488//function : StandardModesActivation
489//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
490// Context
491//==============================================================================
492void ViewerTest::StandardModeActivation(const Standard_Integer mode )
493{
494 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
495 if(mode==0) {
496 if (TheAISContext()->HasOpenedContext())
497 aContext->CloseLocalContext();
498 } else {
499
500 if(!aContext->HasOpenedContext()) {
501 // To unhilight the preselected object
502 aContext->UnhilightCurrents(Standard_False);
503 // Open a local Context in order to be able to select subshape from
504 // the selected shape if any or for all if there is no selection
505 if (!aContext->FirstCurrentObject().IsNull()){
506 aContext->OpenLocalContext(Standard_False);
507
508 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
509 aContext->Load( aContext->Current(),-1,Standard_True);
510 }
511 }
512 else
513 aContext->OpenLocalContext();
514 }
515
516 const char *cmode="???";
517
518 switch (mode) {
519 case 0: cmode = "Shape"; break;
520 case 1: cmode = "Vertex"; break;
521 case 2: cmode = "Edge"; break;
522 case 3: cmode = "Wire"; break;
523 case 4: cmode = "Face"; break;
524 case 5: cmode = "Shell"; break;
525 case 6: cmode = "Solid"; break;
4754e164 526 case 7: cmode = "Compsolid"; break;
527 case 8: cmode = "Compound"; break;
7fd59977 528 }
529
530 if(theactivatedmodes.Contains(mode))
531 { // Desactivate
532 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
533 theactivatedmodes.Remove(mode);
534 cout<<"Mode "<< cmode <<" OFF"<<endl;
535 }
536 else
537 { // Activate
538 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
539 theactivatedmodes.Add(mode);
540 cout<<"Mode "<< cmode << " ON" << endl;
541 }
542 }
543}
544
545//==============================================================================
1c88cbaf 546//function : CopyIsoAspect
547//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
548//==============================================================================
549static Handle(Prs3d_IsoAspect) CopyIsoAspect
550 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
551 const Standard_Integer theNbIsos)
552{
553 Quantity_Color aColor;
554 Aspect_TypeOfLine aType;
555 Standard_Real aWidth;
556
557 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
558
559 Handle(Prs3d_IsoAspect) aResult =
560 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
561
562 return aResult;
563}
564
565//==============================================================================
566//function : visos
567//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
568//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
569//==============================================================================
570static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
571{
572 if (TheAISContext().IsNull()) {
573 di << argv[0] << " Call 'vinit' before!\n";
574 return 1;
575 }
576
577 if (argc <= 1) {
578 di << "Current number of isos : " <<
579 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
580 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
581 di << "IsoOnPlane mode is " <<
582 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
583
584 return 0;
585 }
586
587 Standard_Integer aLastInd = argc - 1;
588 Standard_Boolean isChanged = Standard_False;
1d47d8d0 589 Standard_Integer aNbUIsos = 0;
590 Standard_Integer aNbVIsos = 0;
1c88cbaf 591
592 if (aLastInd >= 3) {
593 Standard_Boolean isIsoOnPlane = Standard_False;
594
595 if (strcmp(argv[aLastInd], "1") == 0) {
596 isIsoOnPlane = Standard_True;
597 isChanged = Standard_True;
598 } else if (strcmp(argv[aLastInd], "0") == 0) {
599 isIsoOnPlane = Standard_False;
600 isChanged = Standard_True;
601 }
602
603 if (isChanged) {
604 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
605 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
606 aLastInd -= 3;
607
608 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
609 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
610
611 TheAISContext()->IsoOnPlane(isIsoOnPlane);
612
613 if (aLastInd == 0) {
614 // If there are no shapes provided set the default numbers.
615 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
616 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
617 }
618 }
619 }
620
621 Standard_Integer i;
622
623 for (i = 1; i <= aLastInd; i++) {
624 TCollection_AsciiString name(argv[i]);
625 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
626
627 if (IsBound) {
628 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
629 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
630 const Handle(AIS_InteractiveObject) aShape =
631 Handle(AIS_InteractiveObject)::DownCast (anObj);
632 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
633 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
634 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
635
636 if (isChanged) {
637 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
638 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
639 TheAISContext()->SetLocalAttributes
640 (aShape, CurDrawer, Standard_False);
641 TheAISContext()->Redisplay(aShape);
642 } else {
643 di << "Number of isos for " << argv[i] << " : "
644 << aUIso->Number() << " " << aVIso->Number() << "\n";
645 }
646 } else {
647 di << argv[i] << ": Not an AIS interactive object!\n";
648 }
649 } else {
650 di << argv[i] << ": Use 'vdisplay' before\n";
651 }
652 }
653
654 if (isChanged) {
655 TheAISContext()->UpdateCurrentViewer();
656 }
657
658 return 0;
659}
660
661//==============================================================================
7fd59977 662//function : VDispAreas,VDispSensitive,...
663//purpose : Redraw the view
664//Draw arg : No args
665//==============================================================================
666static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
667{
668
669 Handle(AIS_InteractiveContext) Ctx;
670 Handle(V3d_View) Viou;
671 GetCtxAndView(Ctx,Viou);
672 Ctx->DisplayActiveAreas(Viou);
673 return 0;
674}
675static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
676{
677 Handle(AIS_InteractiveContext) Ctx;
678 Handle(V3d_View) Viou;
679 GetCtxAndView(Ctx,Viou);
680 Ctx->ClearActiveAreas(Viou);
681 return 0;
682
683}
684static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
685{
686 Handle(AIS_InteractiveContext) Ctx;
687 Handle(V3d_View) Viou;
688 GetCtxAndView(Ctx,Viou);
689 Ctx->DisplayActiveSensitive(Viou);
690 return 0;
691
692}
693static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
694{
695 Handle(AIS_InteractiveContext) Ctx;
696 Handle(V3d_View) Viou;
697 GetCtxAndView(Ctx,Viou);
698 Ctx->ClearActiveSensitive(Viou);
699 return 0;
700}
701
702//==============================================================================
703//function : VDebug
704//purpose : To list the displayed object with their attributes
705//Draw arg : No args
706//==============================================================================
707static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
708{ if ( !a3DView().IsNull() ) {
709 di << "List of object in the viewer :" << "\n";
710
711 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
712
713 while ( it.More() ) {
714 di << "\t" << it.Key2().ToCString() << "\n";
715 it.Next();
716 }
717 }
718
719 return 0;
720}
721
722//==============================================================================
3c982548 723//function : VSelPrecision
724//purpose : To set the selection precision mode and tolerance value
725//Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
726// value (integer number of pixel for window mode, double value of
727// sensitivity for view mode). Without arguments the function just
728// prints the current precision mode and the corresponding tolerance.
729//==============================================================================
730static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
731{
732 if( argc > 3 )
733 {
734 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
735 return 1;
736 }
737
738 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
739 if( aContext.IsNull() )
740 return 1;
741
742 if( argc == 1 )
743 {
744 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
745 if( aMode == StdSelect_SM_WINDOW )
746 {
747 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
748 di << "Precision mode : 0 (window)\n";
749 di << "Pixel tolerance : " << aPixelTolerance << "\n";
750 }
751 else if( aMode == StdSelect_SM_VIEW )
752 {
753 Standard_Real aSensitivity = aContext->Sensitivity();
754 di << "Precision mode : 1 (view)\n";
755 di << "Sensitivity : " << aSensitivity << "\n";
756 }
757 }
758 else if( argc > 1 )
759 {
91322f44 760 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
3c982548 761 aContext->SetSensitivityMode( aMode );
762 if( argc > 2 )
763 {
764 if( aMode == StdSelect_SM_WINDOW )
765 {
91322f44 766 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
3c982548 767 aContext->SetPixelTolerance( aPixelTolerance );
768 }
769 else if( aMode == StdSelect_SM_VIEW )
770 {
91322f44 771 Standard_Real aSensitivity = Draw::Atof( argv[2] );
3c982548 772 aContext->SetSensitivity( aSensitivity );
773 }
774 }
775 }
776 return 0;
777}
778
779//==============================================================================
7fd59977 780//function : VDump
781//purpose : To dump the active view snapshot to image file
782//Draw arg : Picture file name with extension corresponding to desired format
783//==============================================================================
784static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
785{
786 if (argc < 2)
787 {
788 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
789 return 1;
790 }
791
692613e5 792 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
7fd59977 793 if (argc > 2)
794 {
29cb310a 795 const char* aBuffTypeStr = argv[2];
796 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
7fd59977 797 {
692613e5 798 aBufferType = Graphic3d_BT_RGB;
7fd59977 799 }
29cb310a 800 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
7fd59977 801 {
692613e5 802 aBufferType = Graphic3d_BT_RGBA;
7fd59977 803 }
29cb310a 804 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
7fd59977 805 {
692613e5 806 aBufferType = Graphic3d_BT_Depth;
7fd59977 807 }
808 }
809
91322f44 810 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
811 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
7fd59977 812
813 Handle(AIS_InteractiveContext) IC;
814 Handle(V3d_View) view;
815 GetCtxAndView (IC, view);
85e096c3 816 if (view.IsNull())
7fd59977 817 {
85e096c3 818 di << "Cannot find an active viewer/view\n";
819 return 1;
820 }
821
822 if (aWidth <= 0 || aHeight <= 0)
823 {
824 if (!view->Dump (argv[1], aBufferType))
7fd59977 825 {
85e096c3 826 di << "Dumping failed!\n";
827 return 1;
7fd59977 828 }
85e096c3 829 return 0;
7fd59977 830 }
85e096c3 831
692613e5 832 Image_AlienPixMap aPixMap;
833 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
7fd59977 834 {
85e096c3 835 di << "Dumping failed!\n";
7fd59977 836 return 1;
837 }
85e096c3 838
692613e5 839 if (aPixMap.SizeX() != Standard_Size(aWidth)
840 || aPixMap.SizeY() != Standard_Size(aHeight))
85e096c3 841 {
692613e5 842 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
843 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
85e096c3 844 }
692613e5 845 if (!aPixMap.Save (argv[1]))
85e096c3 846 {
847 di << "Saving image failed!\n";
848 return 1;
849 }
850 return 0;
7fd59977 851}
852
853
854//==============================================================================
855//function : Displays,Erase...
856//purpose :
857//Draw arg :
858//==============================================================================
859static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
860 const Standard_Integer Mode,
861 const Standard_Integer TypeOfOperation,
862 const Standard_Boolean Upd)
863{
864 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
865
866 switch(TypeOfOperation){
867 case 1:
868 Ctx->Display(IO,Mode,Upd);
869 break;
870 case 2:{
eb4320f2 871 Ctx->Erase(IO,Upd);
7fd59977 872 break;
873 }
874 case 3:{
875 if(IO.IsNull())
876 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
877 else
878 Ctx->SetDisplayMode(IO,Mode,Upd);
879 break;
880 }
881 case 4:{
882 if(IO.IsNull())
883 Ctx->SetDisplayMode(0,Upd);
884 else
885 Ctx->UnsetDisplayMode(IO,Upd);
886 break;
887 }
888 }
889 return 0;
890}
891
892//=======================================================================
893//function :
894//purpose :
895//=======================================================================
896static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
897{
898
899 TCollection_AsciiString name;
900 if(argc>3)
901 return 1;
902 // display others presentations
903 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
904 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
905 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
906 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
907
908 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
909
910 //unset displaymode.. comportement particulier...
911 if(TypeOfOperation==4){
912 if(argc==1){
913 if(Ctx->NbCurrents()==0 ||
914 Ctx->NbSelected()==0){
915 Handle(AIS_InteractiveObject) IO;
916 VwrTst_DispErase(IO,-1,4,Standard_False);
917 }
918 else if(!Ctx->HasOpenedContext()){
919 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
920 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
921 }
922 else{
923 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
924 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
925 Ctx->UpdateCurrentViewer();
926 }
927 else{
928 Handle(AIS_InteractiveObject) IO;
929 name = argv[1];
930 if(GetMapOfAIS().IsBound2(name)){
931 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
932 if (!IO.IsNull())
933 VwrTst_DispErase(IO,-1,4,Standard_True);
934 }
935 }
936 }
937 else if(argc==2){
91322f44 938 Standard_Integer Dmode = Draw::Atoi(argv[1]);
7fd59977 939 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
940 Handle(AIS_InteractiveObject) IO;
941 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
942 }
943 if(!Ctx->HasOpenedContext()){
944 // set/unset display mode sur le Contexte...
945 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
946 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
947 }
948 Ctx->UpdateCurrentViewer();
949 }
950 else{
951 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
952 Ctx->Display(Ctx->Interactive(),Dmode);
953 }
954 }
955 else{
956 Handle(AIS_InteractiveObject) IO;
957 name = argv[1];
958 if(GetMapOfAIS().IsBound2(name))
959 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
960 if (!IO.IsNull())
91322f44 961 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 962 }
963 return 0;
964}
965
966
967//=======================================================================
968//function :
969//purpose :
970//=======================================================================
971static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
972{
973 if(argc==1) return 1;
91322f44 974 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 975 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
976
977 if(argc==2){
978
979 if(!Ctx->HasOpenedContext()){
980 di<<"sub intensite ";
981 if(On==1) di<<"On";
982 else di<<"Off";
983 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
984 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
985 if(On==1){
986 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
987 else{
988 di <<"passage dans off"<<"\n";
989 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
990 }
991 }
992 }
993 else{
994 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
995 if(On==1){
996 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
997 else{
998 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
999 }
1000 }
1001 Ctx->UpdateCurrentViewer();
1002 }
1003 else {
1004 Handle(AIS_InteractiveObject) IO;
1005 TCollection_AsciiString name = argv[2];
1006 if(GetMapOfAIS().IsBound2(name)){
1007 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1008 if (!IO.IsNull()) {
7fd59977 1009 if(On==1)
1010 Ctx->SubIntensityOn(IO);
1011 else
1012 Ctx->SubIntensityOff(IO);
eafb234b 1013 }
7fd59977 1014 }
1015 else return 1;
1016 }
1017 return 0;
1018
1019}
1020//==============================================================================
1021//function : VColor2
1022//Author : ege
1023//purpose : change the color of a selected or named or displayed shape
1024//Draw arg : vcolor2 [name] color
1025//==============================================================================
1026static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1027{
1028
1029 Standard_Boolean ThereIsCurrent;
1030 Standard_Boolean ThereIsArgument;
1031 Standard_Boolean IsBound = Standard_False ;
7fd59977 1032
5cbef0fe 1033 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
7fd59977 1034 if (HaveToSet) {
5cbef0fe
S
1035 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1036 ThereIsArgument = (argc != 2);
7fd59977 1037 }
1038 else {
5cbef0fe
S
1039 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1040 ThereIsArgument = (argc == 2);
7fd59977 1041 }
1042
1043 if ( !a3DView().IsNull() ) {
1044 TCollection_AsciiString name;
1045 if (ThereIsArgument) {
1046 name = argv[1];
1047 IsBound= GetMapOfAIS().IsBound2(name);
1048 }
1049 if (TheAISContext()->HasOpenedContext())
1050 TheAISContext()->CloseLocalContext();
1051
1052 // On set le Booleen There is current
1053 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1054 else ThereIsCurrent =Standard_False;
1055
1056 //=======================================================================
1057 // Il y a un argument
1058 //=======================================================================
1059 if ( ThereIsArgument && IsBound ) {
1060 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1061 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1062 Handle(AIS_InteractiveObject) ashape =
1063 Handle(AIS_InteractiveObject)::DownCast (anObj);
1064#ifdef DEB
7fd59977 1065 if (HaveToSet)
792c785c 1066 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
7fd59977 1067 else
5cbef0fe 1068 di << "HaveToSet 0\n";
7fd59977 1069#endif
1070
5cbef0fe 1071 if(HaveToSet)
792c785c 1072 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
7fd59977 1073 else
1074 TheAISContext()->UnsetColor(ashape);
1075 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1076 Handle(NIS_Triangulated) ashape =
1077 Handle(NIS_Triangulated)::DownCast (anObj);
5cbef0fe 1078 if (!ashape.IsNull())
792c785c 1079 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
7fd59977 1080 }
1081 }
1082
1083
1084 //=======================================================================
1085 // Il n'y a pas d'arguments
1086 // Mais un ou plusieurs objets on des current representation
1087 //=======================================================================
1088 if (ThereIsCurrent && !ThereIsArgument) {
1089 for (TheAISContext() -> InitCurrent() ;
1090 TheAISContext() -> MoreCurrent() ;
1091 TheAISContext() ->NextCurrent() )
1092 {
5cbef0fe 1093 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
7fd59977 1094 if (ashape.IsNull())
1095 continue;
1096#ifdef DEB
5cbef0fe 1097 if (HaveToSet)
792c785c 1098 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
5cbef0fe
S
1099 else
1100 di << "HaveToSet 0\n";
7fd59977 1101#endif
5cbef0fe 1102 if(HaveToSet)
792c785c 1103 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
5cbef0fe
S
1104 else
1105 TheAISContext()->UnsetColor(ashape,Standard_False);
7fd59977 1106 }
1107
1108 TheAISContext()->UpdateCurrentViewer();
1109 }
1110
1111 //=======================================================================
1112 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1113 // on impose a tous les objets du viewer la couleur passee
1114 //=======================================================================
1115 else if (!ThereIsCurrent && !ThereIsArgument){
1116 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1117 while ( it.More() ) {
5cbef0fe 1118 const Handle(AIS_InteractiveObject) ashape =
7fd59977 1119 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
eafb234b 1120 if (!ashape.IsNull()) {
7fd59977 1121 if(HaveToSet)
792c785c 1122 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
7fd59977 1123 else
1124 TheAISContext()->UnsetColor(ashape,Standard_False);
eafb234b 1125 }
5cbef0fe 1126 it.Next();
7fd59977 1127 }
1128 TheAISContext()->UpdateCurrentViewer();
1129 }
1130 }
1131 return 0;
1132}
1133
1134//==============================================================================
1135//function : VTransparency
1136//Author : ege
1137//purpose : change the transparency of a selected or named or displayed shape
1138//Draw arg : vtransparency [name] TransparencyCoeficient
1139//==============================================================================
1140
7fd59977 1141static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1142 const char** argv)
1143{
1144 Standard_Boolean ThereIsCurrent;
1145 Standard_Boolean ThereIsArgument;
1146 Standard_Boolean IsBound = Standard_False ;
7fd59977 1147
5cbef0fe 1148 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
7fd59977 1149 if (HaveToSet) {
1150 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1151 ThereIsArgument = (argc != 2);
7fd59977 1152 }
1153 else{
1154 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
5cbef0fe 1155 ThereIsArgument = (argc == 2);
7fd59977 1156 }
1157
1158 if ( !a3DView().IsNull() ) {
1159 TCollection_AsciiString name;
1160 if (ThereIsArgument) {
1161 name = argv[1];
1162 IsBound= GetMapOfAIS().IsBound2(name);
1163 }
1164 if (TheAISContext()->HasOpenedContext())
1165 TheAISContext()->CloseLocalContext();
1166
1167 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1168 else ThereIsCurrent = Standard_False;
1169
1170 //=======================================================================
1171 // Il y a des arguments: un nom et une couleur
1172 //=======================================================================
1173 if ( ThereIsArgument && IsBound ) {
1174 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1175 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1176 const Handle(AIS_InteractiveObject) ashape =
1177 Handle(AIS_InteractiveObject)::DownCast(anObj);
1178 if(HaveToSet)
91322f44 1179 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
7fd59977 1180 else
1181 TheAISContext()->UnsetTransparency(ashape);
5cbef0fe 1182 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
7fd59977 1183 const Handle(NIS_InteractiveObject) ashape =
1184 Handle(NIS_InteractiveObject)::DownCast(anObj);
1185 if(HaveToSet)
91322f44 1186 ashape->SetTransparency(Draw::Atof(argv[2]) );
7fd59977 1187 else
1188 ashape->UnsetTransparency();
1189 }
1190 }
1191 //=======================================================================
1192 // Il n'y a pas d'arguments
1193 // Mais un ou plusieurs objets on des current representation
1194 //=======================================================================
1195 if (ThereIsCurrent && !ThereIsArgument) {
1196 for (TheAISContext() -> InitCurrent() ;
1197 TheAISContext() -> MoreCurrent() ;
1198 TheAISContext() ->NextCurrent() )
1199 {
5cbef0fe
S
1200 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1201 if(HaveToSet)
91322f44 1202 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
5cbef0fe
S
1203 else
1204 TheAISContext()->UnsetTransparency(ashape,Standard_False);
7fd59977 1205 }
1206
1207 TheAISContext()->UpdateCurrentViewer();
1208 }
1209 //=======================================================================
1210 // Il n'y a pas d'arguments ET aucun objet courrant
1211 //=======================================================================
1212 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1213 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1214 it(GetMapOfAIS());
1215 while ( it.More() ) {
5cbef0fe 1216 Handle(AIS_InteractiveObject) ashape =
7fd59977 1217 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
eafb234b 1218 if (!ashape.IsNull()) {
7fd59977 1219 if(HaveToSet)
91322f44 1220 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
7fd59977 1221 else
1222 TheAISContext()->UnsetTransparency(ashape,Standard_False);
eafb234b 1223 }
5cbef0fe 1224 it.Next();
7fd59977 1225 }
1226 TheAISContext()->UpdateCurrentViewer();
1227 }
1228 }
1229 return 0;
1230}
1231
1232
1233//==============================================================================
1234//function : VMaterial
1235//Author : ege
1236//purpose : change the Material of a selected or named or displayed shape
1237//Draw arg : vmaterial [Name] Material
1238//==============================================================================
1239static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1240{
1241
1242 Standard_Boolean ThereIsCurrent;
1243 Standard_Boolean ThereIsName;
1244 Standard_Boolean IsBound = Standard_False ;
1245
5cbef0fe 1246 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
7fd59977 1247 if (HaveToSet) {
1248 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1249 ThereIsName = (argc != 2);
7fd59977 1250 }
1251 else {
1252 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
5cbef0fe 1253 ThereIsName = (argc == 2);
7fd59977 1254 }
1255
1256 if ( !a3DView().IsNull() ) {
1257 TCollection_AsciiString name;
1258 if (ThereIsName) {
1259 name = argv[1];
1260 IsBound= GetMapOfAIS().IsBound2(name);
1261 }
1262 if (TheAISContext()->HasOpenedContext())
1263 TheAISContext()->CloseLocalContext();
1264 if (TheAISContext() -> NbCurrents() > 0 )
1265 ThereIsCurrent =Standard_True;
1266 else
1267 ThereIsCurrent =Standard_False;
1268
1269 //=======================================================================
1270 // Ther is a name of shape and a material name
1271 //=======================================================================
1272 if ( ThereIsName && IsBound ) {
1273 Handle(AIS_InteractiveObject) ashape =
1274 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
eafb234b 1275 if (!ashape.IsNull()) {
7fd59977 1276 if (HaveToSet)
5cbef0fe 1277 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
7fd59977 1278 else
1279 TheAISContext()->UnsetMaterial(ashape);
eafb234b 1280 }
7fd59977 1281 }
1282 //=======================================================================
1283 // Il n'y a pas de nom de shape
1284 // Mais un ou plusieurs objets on des current representation
1285 //=======================================================================
1286 if (ThereIsCurrent && !ThereIsName) {
1287 for (TheAISContext() -> InitCurrent() ;
1288 TheAISContext() -> MoreCurrent() ;
1289 TheAISContext() ->NextCurrent() )
1290 {
5cbef0fe
S
1291 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1292 if (HaveToSet)
1293 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1294 else
1295 TheAISContext()->UnsetMaterial(ashape,Standard_False);
7fd59977 1296 }
1297 TheAISContext()->UpdateCurrentViewer();
1298 }
1299
1300 //=======================================================================
1301 // Il n'y a pas de noms de shape ET aucun objet courrant
1302 // On impose a tous les objets du viewer le material passe en argument
1303 //=======================================================================
1304 else if (!ThereIsCurrent && !ThereIsName){
1305 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1306 it(GetMapOfAIS());
1307 while ( it.More() ) {
5cbef0fe 1308 Handle(AIS_InteractiveObject) ashape =
7fd59977 1309 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
eafb234b 1310 if (!ashape.IsNull()) {
7fd59977 1311 if (HaveToSet)
5cbef0fe 1312 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
7fd59977 1313 else
1314 TheAISContext()->UnsetMaterial(ashape,Standard_False);
eafb234b 1315 }
5cbef0fe 1316 it.Next();
7fd59977 1317 }
1318 TheAISContext()->UpdateCurrentViewer();
1319 }
1320 }
1321 return 0;
1322}
1323
1324
1325
1326//==============================================================================
1327//function : VWidth
1328//Author : ege
1329//purpose : change the width of the edges of a selected or named or displayed shape
1330//Draw arg : vwidth [Name] WidthValue(1->10)
1331//==============================================================================
1332static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1333{
1334
1335 Standard_Boolean ThereIsCurrent;
1336 Standard_Boolean ThereIsArgument;
1337 Standard_Boolean IsBound = Standard_False ;
1338
5cbef0fe 1339 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
7fd59977 1340 if (HaveToSet) {
1341 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
5cbef0fe 1342 ThereIsArgument = (argc != 2);
7fd59977 1343 }
1344 else {
1345 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
5cbef0fe 1346 ThereIsArgument = (argc == 2);
7fd59977 1347 }
1348 if ( !a3DView().IsNull() ) {
1349 TCollection_AsciiString name;
1350 if (ThereIsArgument) {
1351 name = argv[1];
1352 IsBound= GetMapOfAIS().IsBound2(name);
1353 }
1354 if (TheAISContext()->HasOpenedContext())
1355 TheAISContext()->CloseLocalContext();
1356
1357 if (TheAISContext() -> NbCurrents() > 0 )
1358 ThereIsCurrent =Standard_True;
1359 else
1360 ThereIsCurrent =Standard_False;
1361
1362 if ( ThereIsArgument && IsBound ) {
1363 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1364 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1365 const Handle(AIS_InteractiveObject) ashape =
1366 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1367 if (HaveToSet)
91322f44 1368 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
7fd59977 1369 else
1370 TheAISContext()->UnsetWidth (ashape);
1371 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1372 const Handle(NIS_Triangulated) ashape =
1373 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1374 if (HaveToSet && !ashape.IsNull())
91322f44 1375 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
7fd59977 1376 }
1377 }
1378
1379 //=======================================================================
1380 // Il n'y a pas d'arguments
1381 // Mais un ou plusieurs objets on des current representation
1382 //=======================================================================
1383 if (ThereIsCurrent && !ThereIsArgument) {
1384 for (TheAISContext() -> InitCurrent() ;
1385 TheAISContext() -> MoreCurrent() ;
1386 TheAISContext() ->NextCurrent() )
1387 {
5cbef0fe
S
1388 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1389 if (HaveToSet)
91322f44 1390 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
5cbef0fe
S
1391 else
1392 TheAISContext()->UnsetWidth(ashape,Standard_False);
7fd59977 1393 }
1394 TheAISContext()->UpdateCurrentViewer();
1395 }
1396 //=======================================================================
1397 // Il n'y a pas d'arguments ET aucun objet courrant
1398 //=======================================================================
1399 else if (!ThereIsCurrent && !ThereIsArgument){
1400 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1401 it(GetMapOfAIS());
eafb234b 1402 while ( it.More() ) {
1403 Handle(AIS_InteractiveObject) ashape =
1404 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1405 if (!ashape.IsNull()) {
1406 if (HaveToSet)
1407 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1408 else
1409 TheAISContext()->UnsetWidth(ashape,Standard_False);
1410 }
1411 it.Next();
7fd59977 1412 }
1413 TheAISContext()->UpdateCurrentViewer();
1414 }
1415 }
1416 return 0;
1417}
99c56d44 1418
1419//==============================================================================
1420//function : VInteriorStyle
1421//purpose : sets interior style of the a selected or named or displayed shape
1422//Draw arg : vsetinteriorstyle [shape] style
1423//==============================================================================
1424static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1425 const Standard_Integer theStyle,
1426 Draw_Interpretor& di)
1427{
1428 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1429 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1430 " (Aspect_IS_HIDDENLINE)]\n";
1431 return;
1432 }
1433 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1434 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1435 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1436 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1437 aFillAspect->SetInteriorStyle (aStyle);
1438 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1439}
1440
1441static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1442{
1443 if (argc < 2 || argc > 3) {
1444 di << argv[0] << " requires 2 or 3 arguments\n";
1445 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1446 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1447 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1448 return 1;
1449 }
1450
1451 Standard_Boolean ThereIsCurrent;
1452 Standard_Boolean ThereIsArgument;
1453 Standard_Boolean IsBound = Standard_False ;
1454
1455 ThereIsArgument = (argc > 2);
1456 if ( !a3DView().IsNull() ) {
1457 TCollection_AsciiString name;
1458 if (ThereIsArgument) {
1459 name = argv[1];
1460 IsBound= GetMapOfAIS().IsBound2(name);
1461 }
1462 if (TheAISContext()->HasOpenedContext())
1463 TheAISContext()->CloseLocalContext();
1464
1465 if (TheAISContext() -> NbCurrents() > 0 )
1466 ThereIsCurrent =Standard_True;
1467 else
1468 ThereIsCurrent =Standard_False;
1469
1470 if ( ThereIsArgument && IsBound ) {
1471 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1472 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1473 const Handle(AIS_InteractiveObject) ashape =
1474 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
91322f44 1475 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
99c56d44 1476 }
1477 }
1478 //=======================================================================
1479 // No arguments specified
1480 // But there are one or more selected objects
1481 //=======================================================================
1482 if (ThereIsCurrent && !ThereIsArgument) {
1483 for (TheAISContext() -> InitCurrent() ;
1484 TheAISContext() -> MoreCurrent() ;
1485 TheAISContext() ->NextCurrent() )
1486 {
1487 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
91322f44 1488 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
99c56d44 1489 }
1490 }
1491 //=======================================================================
1492 // No arguments specified and there are no selected objects
1493 //=======================================================================
1494 else if (!ThereIsCurrent && !ThereIsArgument){
1495 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1496 it(GetMapOfAIS());
1497 while ( it.More() ) {
1498 Handle(AIS_InteractiveObject) ashape =
1499 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1500 if (!ashape.IsNull())
91322f44 1501 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
99c56d44 1502 it.Next();
1503 }
1504 }
1505 TheAISContext()->UpdateCurrentViewer();
1506 }
1507 return 0;
1508}
1509
7fd59977 1510//==============================================================================
1511//function : VDonly2
1512//author : ege
1513//purpose : Display only a selected or named object
1514// if there is no selected or named object s, nothing is donne
1515//Draw arg : vdonly2 [name1] ... [name n]
1516//==============================================================================
1517static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1518
1519{
1520 if ( a3DView().IsNull() )
1521 return 1;
1522
1523 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1524 Standard_Boolean ThereIsArgument= argc>1;
1525
1526 if (TheAISContext()->HasOpenedContext())
1527 TheAISContext()->CloseLocalContext();
1528
1529 //===============================================================
1530 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1531 // dans le viewer
1532 //===============================================================
1533 if (!ThereIsArgument && ThereIsCurrent) {
1534
1535#ifdef DEB
1536 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1537 it (GetMapOfAIS());
1538#endif
1539 for(TheAISContext()->InitCurrent();
1540 TheAISContext()->MoreCurrent();
1541 TheAISContext()->NextCurrent()){
1542 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1543 TheAISContext()->Erase(aShape,Standard_False);}
1544 }
1545 TheAISContext() ->UpdateCurrentViewer();
1546 //===============================================================
1547 // Il y a des arguments
1548 //===============================================================
1549 if (ThereIsArgument) {
1550 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1551 it (GetMapOfAIS());
1552 while ( it.More() ) {
1553 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1554 const Handle(AIS_InteractiveObject) aShape =
1555 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1556 TheAISContext()->Erase(aShape,Standard_False);
1557 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1558 const Handle(NIS_InteractiveObject) aShape =
1559 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1560 TheNISContext()->Erase(aShape);
7fd59977 1561 }
1562 it.Next();
1563 }
1564
1565 // On display les objets passes par parametre
1566 for (int i=1; i<argc ; i++) {
1567 TCollection_AsciiString name=argv[i];
1568 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1569 if (IsBound) {
1570 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1571 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1572 const Handle(AIS_InteractiveObject) aShape =
1573 Handle(AIS_InteractiveObject)::DownCast (anObj);
1574 TheAISContext()->Display(aShape, Standard_False);
1575 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
ffe2bea7 1576 Handle(NIS_InteractiveObject) aShape =
7fd59977 1577 Handle(NIS_InteractiveObject)::DownCast (anObj);
ffe2bea7 1578 TheNISContext()->Display(aShape);
7fd59977 1579 }
1580 }
1581 }
1582 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1583// TheNISContext() ->UpdateViews();
7fd59977 1584 }
1585 return 0;
1586}
1587
1588//==============================================================================
eef7fc64 1589//function : VRemove
1590//purpose : Removes selected or named objects.
1591// If there is no selected or named objects,
1592// all objects in the viewer can be removed with argument -all.
1593// If -context is in arguments, the object is not deleted from the map of
1594// objects (deleted only from the current context).
1595//==============================================================================
1596int VRemove (Draw_Interpretor& theDI,
1597 Standard_Integer theArgNb,
1598 const char** theArgVec)
1599{
1600 if (a3DView().IsNull())
1601 {
1602 return 1;
1603 }
1604
1605 TheAISContext()->CloseAllContexts (Standard_False);
1606
1607 //Standard_Boolean isStayedInMap = Standard_False;
1608 TCollection_AsciiString aContextOnlyStr ("-context");
1609 TCollection_AsciiString aRemoveAllStr ("-all");
1610
1611 Standard_Boolean isContextOnly = (theArgNb > 1 && TCollection_AsciiString (theArgVec[1]) == aContextOnlyStr);
1612
1613 Standard_Boolean isRemoveAll = (theArgNb == 3 && TCollection_AsciiString (theArgVec[2]) == aRemoveAllStr) ||
1614 (theArgNb == 2 && TCollection_AsciiString (theArgVec[1]) == aRemoveAllStr);
1615
1616 NCollection_List<TCollection_AsciiString> anIONameList;
1617
1618 if (isRemoveAll)
1619 {
1620 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1621 anIter.More(); anIter.Next())
1622 {
1623 anIONameList.Append (anIter.Key2());
1624 }
1625 }
1626 else if (isContextOnly ? theArgNb > 2 : theArgNb > 1) // removed objects names are in argument list
1627 {
1628 for (Standard_Integer anIt = isContextOnly ? 2 : 1; anIt < theArgNb; ++anIt)
1629 {
1630 TCollection_AsciiString aName = theArgVec[anIt];
1631
1632 if (!GetMapOfAIS().IsBound2 (aName))
1633 {
1634 theDI << aName.ToCString() << " was not bound to some object.\n";
1635 continue;
1636 }
1637
1638 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
1639
1640 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
1641 if (!anIO.IsNull())
1642 {
1643 if (anIO->GetContext() != TheAISContext())
1644 {
1645 theDI << aName.ToCString() << " was not displayed in current context.\n";
1646 theDI << "Please activate view with this object displayed and try again.\n";
1647 continue;
1648 }
1649
1650 anIONameList.Append (aName);
1651 continue;
1652 }
1653
1654 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
1655 if (!aNisIO.IsNull())
1656 {
1657 anIONameList.Append (aName);
1658 }
1659 }
1660 }
1661 else if (TheAISContext()->NbCurrents() > 0
1662 || TheNISContext()->GetSelected().Extent() > 0)
1663 {
1664 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1665 anIter.More(); anIter.Next())
1666 {
1667 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1668 if (!anIO.IsNull())
1669 {
1670 if (!TheAISContext()->IsCurrent (anIO))
1671 {
1672 continue;
1673 }
1674
1675 anIONameList.Append (anIter.Key2());
1676 continue;
1677 }
1678
1679 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1680 if (!aNisIO.IsNull())
1681 {
1682 if (!TheNISContext()->IsSelected (aNisIO))
1683 {
1684 continue;
1685 }
1686
1687 anIONameList.Append (anIter.Key2());
1688 }
1689 }
1690 }
1691
1692 // Unbind all removed objects from the map of displayed IO.
1693 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
1694 anIter.More(); anIter.Next())
1695 {
1696 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1697
1698 if (!anIO.IsNull())
1699 {
1700 TheAISContext()->Remove (anIO, Standard_False);
1701 theDI << anIter.Value().ToCString() << " was removed\n";
1702 }
1703 else
1704 {
1705 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1706 if (!aNisIO.IsNull())
1707 {
1708 TheNISContext()->Remove (aNisIO);
1709 theDI << anIter.Value().ToCString() << " was removed\n";
1710 }
1711 }
1712
1713 if (!isContextOnly)
1714 {
1715 GetMapOfAIS().UnBind2 (anIter.Value());
1716 }
1717 }
1718
1719 TheAISContext()->UpdateCurrentViewer();
1720 return 0;
1721}
1722
1723//==============================================================================
b514beda 1724//function : VErase
1725//purpose : Erase some selected or named objects
7fd59977 1726// if there is no selected or named objects, the whole viewer is erased
7fd59977 1727//==============================================================================
b514beda 1728int VErase (Draw_Interpretor& theDI,
1729 Standard_Integer theArgNb,
1730 const char** theArgVec)
7fd59977 1731{
b514beda 1732 if (a3DView().IsNull())
1733 {
7fd59977 1734 return 1;
b514beda 1735 }
7fd59977 1736
b514beda 1737 TheAISContext()->CloseAllContexts (Standard_False);
1738 const Standard_Boolean isEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "").IsEqual ("veraseall");
1739 if (theArgNb > 1)
1740 {
1741 if (isEraseAll)
1742 {
1743 std::cerr << " Syntax error: " << theArgVec[0] << " too much arguments.\n";
1744 return 1;
7fd59977 1745 }
1746
b514beda 1747 // has a list of names
1748 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1749 {
1750 TCollection_AsciiString aName = theArgVec[anArgIter];
1751 if (!GetMapOfAIS().IsBound2 (aName))
1752 {
1753 continue;
1754 }
7fd59977 1755
b514beda 1756 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1757 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1758 theDI << aName.ToCString() << " ";
1759 if (!anIO.IsNull())
1760 {
1761 TheAISContext()->Erase (anIO, Standard_False);
1762 }
1763 else
1764 {
1765 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1766 if (!aNisIO.IsNull())
1767 {
1768 TheNISContext()->Erase (aNisIO);
1769 }
7fd59977 1770 }
7fd59977 1771 }
b514beda 1772 TheAISContext()->UpdateCurrentViewer();
1773 return 0;
7fd59977 1774 }
1775
b514beda 1776 if (!isEraseAll
1777 && TheAISContext()->NbCurrents() > 0)
1778 {
1779 // remove all currently selected objects
1780 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1781 anIter.More(); anIter.Next())
1782 {
1783 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1784 if (!anIO.IsNull()
1785 && TheAISContext()->IsCurrent (anIO))
1786 {
1787 theDI << anIter.Key2().ToCString() << " ";
1788 TheAISContext()->Erase (anIO, Standard_False);
7fd59977 1789 }
1790 }
7fd59977 1791
b514beda 1792 TheAISContext()->UpdateCurrentViewer();
1793 return 0;
1794 }
7fd59977 1795
b514beda 1796 // erase entire viewer
1797 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1798 anIter.More(); anIter.Next())
1799 {
1800 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1801 if (!anIO.IsNull())
1802 {
1803 TheAISContext()->Erase (anIO, Standard_False);
1804 }
1805 else
1806 {
1807 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1808 if (!aNisIO.IsNull())
1809 {
1810 TheNISContext()->Erase (aNisIO);
1811 }
7fd59977 1812 }
7fd59977 1813 }
b514beda 1814 TheAISContext()->UpdateCurrentViewer();
7fd59977 1815 return 0;
1816}
1817
7fd59977 1818//==============================================================================
1819//function : VDisplayAll
1820//author : ege
1821//purpose : Display all the objects of the Map
1822//Draw arg : vdisplayall
1823//==============================================================================
1824static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1825
1826{
1827 if (! a3DView().IsNull() ) {
1828 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1829 if (TheAISContext()->HasOpenedContext())
1830 TheAISContext()->CloseLocalContext();
1831 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1832 it (GetMapOfAIS());
1833 while ( it.More() ) {
1834 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1835 const Handle(AIS_InteractiveObject) aShape =
1836 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1837 TheAISContext()->Erase(aShape,Standard_False);
1838 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1839 const Handle(NIS_InteractiveObject) aShape =
1840 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1841 TheNISContext()->Erase(aShape);
7fd59977 1842 }
1843 it.Next();
1844 }
1845 it.Reset();
1846 while ( it.More() ) {
1847 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1848 const Handle(AIS_InteractiveObject) aShape =
1849 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1850 TheAISContext()->Display(aShape, Standard_False);
1851 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
ffe2bea7 1852 Handle(NIS_InteractiveObject) aShape =
7fd59977 1853 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
ffe2bea7 1854 TheNISContext()->Display(aShape);
7fd59977 1855 }
1856 it.Next();
1857 }
1858 TheAISContext() ->UpdateCurrentViewer();
ffe2bea7 1859// TheNISContext() ->UpdateViews();
7fd59977 1860 }
1861 return 0;
1862}
1863
7fd59977 1864//#######################################################################################################
1865
1866//## VTexture
1867
1868//#######################################################################################################
1869
1870Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1871{
1872 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1873 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1874 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1875 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1876 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1877
1878 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1879 if(myAISContext.IsNull())
1880 {
1881 di << "use 'vinit' command before " << argv[0] << "\n";
31160f80 1882 return 1;
7fd59977 1883 }
1884
1885 Handle(AIS_InteractiveObject) TheAisIO;
1886 Handle(AIS_TexturedShape) myShape;
1887 Standard_Integer myPreviousMode = 0;
1888
31160f80 1889 if (argc<2 || !argv[1])
7fd59977 1890 {
1891 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
31160f80 1892 return 1;
7fd59977 1893 }
1894
1895 TCollection_AsciiString name = argv[1];
1896 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1897
1898 if (GetMapOfAIS().IsBound2(name))
1899 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1900 (GetMapOfAIS().Find2(name));
1901 if (TheAisIO.IsNull())
1902 {
1903 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
31160f80 1904 return 1;
7fd59977 1905 }
1906
1907 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1908 {
1909 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1910 myPreviousMode = myShape->DisplayMode() ;
1911 }
1912 else
1913 {
31160f80 1914 myAISContext->Clear(TheAisIO,Standard_False);
7fd59977 1915 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1916 GetMapOfAIS().UnBind1(TheAisIO);
1917 GetMapOfAIS().UnBind2(name);
1918 GetMapOfAIS().Bind(myShape, name);
1919 }
1920 switch (command)
1921 {
1922 case 1: // vtexture : we only map a texture on the shape
1923 if(argc<=1)
1924 {
1925 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1926 return 1;
7fd59977 1927 }
31160f80 1928 if (argc>2 && argv[2])
7fd59977 1929 {
1930 if(strcasecmp(argv[2],"?")==0)
1931 {
bf75be98 1932 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 1933 di<<"\n Files in current directory : \n"<<"\n";
1934 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1935 di.Eval(Cmnd.ToCString());
1936
1937 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1938 Cmnd += monPath ;
1939 Cmnd += "/* " ;
1940 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1941 di.Eval(Cmnd.ToCString());
1942
1943 return 0;
1944 }
1945 else
1946 myShape->SetTextureFileName(argv[2]);
1947 }
1948 else
1949 {
1950 di <<"Texture mapping disabled \n \
1951 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1952
1953 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1954 if (myPreviousMode == 3 )
1955 myAISContext->RecomputePrsOnly(myShape);
1956 myAISContext->Display(myShape, Standard_True);
1957 return 0;
1958 }
1959 break;
1960
1961 case 2: // vtexscale : we change the scaling factor of the texture
1962
1963 if(argc<2)
1964 {
1965 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1966 return 1;
7fd59977 1967 }
1968
1969 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
91322f44 1970 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1971 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
7fd59977 1972 break;
1973
1974 case 3: // vtexorigin : we change the origin of the texture on the shape
1975 if(argc<2)
1976 {
1977 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1978 return 1;
7fd59977 1979 }
1980 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
91322f44 1981 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1982 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
7fd59977 1983 break;
1984
1985 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1986 if(argc<2)
1987 {
1988 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 1989 return 1;
7fd59977 1990 }
31160f80 1991 if (argc>2 && argv[2])
7fd59977 1992 {
1993 di <<"Texture repeat enabled"<<"\n";
91322f44 1994 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
7fd59977 1995 }
1996 else
1997 {
1998 di <<"Texture repeat disabled"<<"\n";
1999 myShape->SetTextureRepeat(Standard_False);
2000 }
2001 break;
2002
2003 case 5: // vtexdefault : default texture mapping
2004 // ScaleU = ScaleV = 100.0
2005 // URepeat = VRepeat = 1.0
2006 // Uorigin = VOrigin = 0.0
2007
2008 if(argc<2)
2009 {
2010 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
31160f80 2011 return 1;
7fd59977 2012 }
2013 myShape->SetTextureRepeat(Standard_False);
2014 myShape->SetTextureOrigin(Standard_False);
2015 myShape->SetTextureScale (Standard_False);
2016 break;
2017 }
2018
2019 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
2020 myAISContext->RecomputePrsOnly(myShape);
2021 else
2022 {
2023 myAISContext->SetDisplayMode(myShape,3,Standard_False);
2024 myAISContext->Display(myShape, Standard_True);
2025 myAISContext->Update(myShape,Standard_True);
2026 }
31160f80 2027 return 0;
7fd59977 2028}
2029
2030//==============================================================================
2031//function : VDisplay2
2032//author : ege
2033//purpose : Display an object from its name
2034//Draw arg : vdisplay name1 [name2] ... [name n]
2035//==============================================================================
2036static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2037
2038{
2039 // Verification des arguments
2040 if ( a3DView().IsNull() ) {
2041
2042 ViewerTest::ViewerInit();
2043 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
2044 // return 1;
2045 }
2046
2047 if ( argc<2) {
2048 di<<argv[0]<<" Syntaxe error"<<"\n";
2049 return 1;
2050 }
2051
2052
2053 TCollection_AsciiString name;
2054 if (TheAISContext()->HasOpenedContext())
2055 TheAISContext()->CloseLocalContext();
2056
2057 for ( int i = 1; i < argc; i++ ) {
2058 name = argv[i];
2059 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
2060 Standard_Boolean IsDatum = Standard_False;
2061 Handle(Standard_Transient) anObj;
2062 if ( IsBound ) {
2063 anObj = GetMapOfAIS().Find2(name);
2064 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
2065 Handle(AIS_InteractiveObject) aShape =
2066 Handle(AIS_InteractiveObject)::DownCast(anObj);
2067 if (aShape->Type()==AIS_KOI_Datum) {
2068 IsDatum = Standard_True;
2069 TheAISContext()->Display(aShape, Standard_False);
2070 }
2071 if (!IsDatum) {
2072 di << "Display " << name.ToCString() << "\n";
2073 // Get the Shape from a name
2074 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2075
2076 // Update the Shape in the AIS_Shape
2077 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2078 if(!TheRealSh.IsNull())
2079 TheRealSh->Set(NewShape);
2080 TheAISContext()->Redisplay(aShape, Standard_False);
2081 TheAISContext()->Display(aShape, Standard_False);
2082 }
2083 aShape.Nullify();
2084 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2085 Handle(NIS_InteractiveObject) aShape =
2086 Handle(NIS_InteractiveObject)::DownCast(anObj);
ffe2bea7 2087 TheNISContext()->Display(aShape);
7fd59977 2088 }
2089 }
2090 else { // Create the AIS_Shape from a name
2091 const Handle(AIS_InteractiveObject) aShape =
2092 GetAISShapeFromName((const char *)name.ToCString());
2093 if ( !aShape.IsNull() ) {
2094 GetMapOfAIS().Bind(aShape, name);
2095 TheAISContext()->Display(aShape, Standard_False);
2096 }
2097 }
2098 }
2099 // Upadate the screen and redraw the view
2100 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 2101// TheNISContext()->UpdateViews();
7fd59977 2102 return 0;
2103}
2104
2105//==============================================================================
7fd59977 2106//function : VPerf
2107//purpose : Test the annimation of an object along a
2108// predifined trajectory
2109//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2110//==============================================================================
2111
2112static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2113
2114 OSD_Timer myTimer;
2115 if (TheAISContext()->HasOpenedContext())
2116 TheAISContext()->CloseLocalContext();
2117
c6541a0c 2118 Standard_Real Step=4*M_PI/180;
7fd59977 2119 Standard_Real Angle=0;
2120
2121 Handle(AIS_InteractiveObject) aIO;
2122 if (GetMapOfAIS().IsBound2(argv[1]))
2123 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2124 if (aIO.IsNull())
2125 return 1;
2126
2127 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2128
2129 myTimer.Start();
2130
91322f44 2131 if (Draw::Atoi(argv[3])==1 ) {
7fd59977 2132 di<<" Primitives sensibles OFF"<<"\n";
2133 TheAISContext()->Deactivate(aIO);
2134 }
2135 else {
2136 di<<" Primitives sensibles ON"<<"\n";
2137 }
2138 // Movement par transformation
91322f44 2139 if(Draw::Atoi(argv[2]) ==1) {
7fd59977 2140 di<<" Calcul par Transformation"<<"\n";
c6541a0c 2141 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2142
2143 Angle=Step*myAngle;
2144 gp_Trsf myTransfo;
2145 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2146 TheAISContext()->SetLocation(aShape,myTransfo);
2147 TheAISContext() ->UpdateCurrentViewer();
2148
2149 }
2150 }
2151 else {
2152 di<<" Calcul par Locations"<<"\n";
2153 gp_Trsf myAngleTrsf;
2154 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2155 TopLoc_Location myDeltaAngle (myAngleTrsf);
2156 TopLoc_Location myTrueLoc;
2157
c6541a0c 2158 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 2159
2160 Angle=Step*myAngle;
2161 myTrueLoc=myTrueLoc*myDeltaAngle;
2162 TheAISContext()->SetLocation(aShape,myTrueLoc );
2163 TheAISContext() ->UpdateCurrentViewer();
2164 }
2165 }
91322f44 2166 if (Draw::Atoi(argv[3])==1 ){
7fd59977 2167 // On reactive la selection des primitives sensibles
2168 TheAISContext()->Activate(aIO,0);
2169 }
2170 a3DView() -> Redraw();
2171 myTimer.Stop();
2172 di<<" Temps ecoule "<<"\n";
2173 myTimer.Show();
2174 return 0;
2175}
2176
2177
2178//==================================================================================
2179// Function : VAnimation
2180//==================================================================================
2181static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
31160f80 2182 if (argc != 5) {
7fd59977 2183 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2184 return 1;
2185 }
2186
2187 Standard_Real thread = 4;
2188 Standard_Real angleA=0;
2189 Standard_Real angleB;
2190 Standard_Real X;
2191 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2192
2193 BRep_Builder B;
2194 TopoDS_Shape CrankArm;
2195 TopoDS_Shape CylinderHead;
2196 TopoDS_Shape Propeller;
2197 TopoDS_Shape EngineBlock;
2198
2199 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2200 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2201 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2202 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2203 BRepTools::Read(CrankArm,argv[1],B);
2204 BRepTools::Read(CylinderHead,argv[2],B);
2205 BRepTools::Read(Propeller,argv[3],B);
2206 BRepTools::Read(EngineBlock,argv[4],B);
2207
2208 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2209
2210
2211 OSD_Timer myTimer;
2212 myTimer.Start();
2213
2214 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2215 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2216 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2217 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2218
2219 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2220 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2221 GetMapOfAIS().Bind(myAisCrankArm,"c");
2222 GetMapOfAIS().Bind(myAisPropeller,"d");
2223
2224 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2225 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2226 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2227
2228 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2229 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2230 TheAISContext()->Display(myAisCrankArm,Standard_False );
2231 TheAISContext()->Display(myAisPropeller,Standard_False);
2232
2233 TheAISContext()->Deactivate(myAisCylinderHead);
2234 TheAISContext()->Deactivate(myAisEngineBlock );
2235 TheAISContext()->Deactivate(myAisCrankArm );
2236 TheAISContext()->Deactivate(myAisPropeller );
2237
2238 // Boucle de mouvement
c6541a0c 2239 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
7fd59977 2240
c6541a0c 2241 angleA = thread*myAngle*M_PI/180;
7fd59977 2242 X = Sin(angleA)*3/8;
2243 angleB = atan(X / Sqrt(-X * X + 1));
2244 Standard_Real decal(25*0.6);
2245
2246
2247 //Build a transformation on the display
2248 gp_Trsf aPropellerTrsf;
2249 aPropellerTrsf.SetRotation(Ax1,angleA);
2250 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2251
2252 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
2253 gp_Trsf aCrankArmTrsf;
2254 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2255 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2256
2257 TheAISContext()->UpdateCurrentViewer();
2258 }
2259
2260 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2261 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2262
2263 myAisCrankArm ->ResetLocation();
2264 myAisPropeller->ResetLocation();
2265
2266 myAisCrankArm -> Set(myNewCrankArm );
2267 myAisPropeller -> Set(myNewPropeller);
2268
2269 TheAISContext()->Activate(myAisCylinderHead,0);
2270 TheAISContext()->Activate(myAisEngineBlock,0 );
2271 TheAISContext()->Activate(myAisCrankArm ,0 );
2272 TheAISContext()->Activate(myAisPropeller ,0 );
2273
2274 myTimer.Stop();
2275 myTimer.Show();
2276 myTimer.Start();
2277
2278 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2279 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2280
2281 TheAISContext()->UpdateCurrentViewer();
2282 a3DView()->Redraw();
2283
2284 myTimer.Stop();
2285 myTimer.Show();
2286
2287 return 0;
2288
2289}
2290
2291//==============================================================================
2292//function : VShading
2293//purpose : Sharpen or roughten the quality of the shading
2294//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2295//==============================================================================
5cbef0fe
S
2296static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2297{
7fd59977 2298 Standard_Real myDevCoef;
2299 Handle(AIS_InteractiveObject) TheAisIO;
2300
2301 // Verifications
5cbef0fe
S
2302 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2303
7fd59977 2304 if (TheAISContext()->HasOpenedContext())
2305 TheAISContext()->CloseLocalContext();
2306
2307 if (argc < 3) {
2308 myDevCoef = 0.0008;
2309 } else {
91322f44 2310 myDevCoef =Draw::Atof(argv[2]);
7fd59977 2311 }
2312
7fd59977 2313 TCollection_AsciiString name=argv[1];
2314 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 2315 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 2316 if (TheAisIO.IsNull())
2317 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2318
5cbef0fe 2319 if (HaveToSet)
7fd59977 2320 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 2321 else
7fd59977 2322 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2323
7fd59977 2324 TheAISContext()->Redisplay(TheAisIO);
2325 return 0;
2326}
2327//==============================================================================
2328//function : HaveMode
2329//use : VActivatedModes
2330//==============================================================================
2331#include <TColStd_ListIteratorOfListOfInteger.hxx>
2332
2333Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2334{
2335 TColStd_ListOfInteger List;
2336 TheAISContext()->ActivatedModes (TheAisIO,List);
2337 TColStd_ListIteratorOfListOfInteger it;
2338 Standard_Boolean Found=Standard_False;
2339 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2340 if (it.Value()==mode ) Found=Standard_True;
2341 }
2342 return Found;
2343}
2344
2345
2346
2347//==============================================================================
2348//function : VActivatedMode
2349//author : ege
2350//purpose : permet d'attribuer a chacune des shapes un mode d'activation
2351// (edges,vertex...)qui lui est propre et le mode de selection standard.
2352// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2353// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2354// qu'un nom et qu'un mode.
2355//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2356//==============================================================================
2357#include <AIS_ListIteratorOfListOfInteractive.hxx>
2358
2359static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2360
2361{
7fd59977 2362 Standard_Boolean ThereIsName = Standard_False ;
2363
2364 if(!a3DView().IsNull()){
2365
5cbef0fe 2366 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 2367 // verification des arguments
2368 if (HaveToSet) {
2369 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
5cbef0fe 2370 ThereIsName = (argc == 3);
7fd59977 2371 }
2372 else {
2373 // vunsetam
2374 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2375 else {
5cbef0fe
S
2376 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2377 di<<" Fermeture du Context local"<<"\n";
7fd59977 2378 if (TheAISContext()->HasOpenedContext())
2379 TheAISContext()->CloseLocalContext();
2380 }
7fd59977 2381 }
2382
7fd59977 2383 // IL n'y a aps de nom de shape passe en argument
2384 if (HaveToSet && !ThereIsName){
91322f44 2385 Standard_Integer aMode=Draw::Atoi(argv [1]);
7fd59977 2386
2387 const char *cmode="???";
7fd59977 2388 switch (aMode) {
2389 case 0: cmode = "Shape"; break;
2390 case 1: cmode = "Vertex"; break;
2391 case 2: cmode = "Edge"; break;
2392 case 3: cmode = "Wire"; break;
2393 case 4: cmode = "Face"; break;
2394 case 5: cmode = "Shell"; break;
2395 case 6: cmode = "Solid"; break;
2396 case 7: cmode = "Compound"; break;
2397 }
2398
2399 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
2400 // il n'y a pas de Context local d'ouvert
2401 // on en ouvre un et on charge toutes les shapes displayees
2402 // on load tous les objets displayees et on Activate les objets de la liste
2403 AIS_ListOfInteractive ListOfIO;
2404 // on sauve dans une AISListOfInteractive tous les objets currents
2405 if (TheAISContext()->NbCurrents()>0 ){
2406 TheAISContext()->UnhilightCurrents(Standard_False);
2407
2408 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2409 ListOfIO.Append(TheAISContext()->Current() );
7fd59977 2410 }
2411 }
2412
2413 TheAISContext()->OpenLocalContext(Standard_False);
2414 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2415 it (GetMapOfAIS());
2416 while(it.More()){
2417 Handle(AIS_InteractiveObject) aIO =
2418 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2419 if (!aIO.IsNull())
2420 TheAISContext()->Load(aIO,0,Standard_False);
2421 it.Next();
2422 }
2423 // traitement des objets qui etaient currents dans le Contexte global
2424 if (!ListOfIO.IsEmpty() ) {
2425 // il y avait des objets currents
2426 AIS_ListIteratorOfListOfInteractive iter;
2427 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2428 Handle(AIS_InteractiveObject) aIO=iter.Value();
2429 TheAISContext()->Activate(aIO,aMode);
2430 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2431 }
2432 }
2433 else {
2434 // On applique le mode a tous les objets displayes
2435 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2436 it2 (GetMapOfAIS());
2437 while(it2.More()){
2438 Handle(AIS_InteractiveObject) aIO =
2439 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2440 if (!aIO.IsNull()) {
2441 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2442 TheAISContext()->Activate(aIO,aMode);
2443 }
2444 it2.Next();
2445 }
2446 }
2447
2448 }
2449
2450 else {
2451 // un Context local est deja ouvert
2452 // Traitement des objets du Context local
2453 if (TheAISContext()->NbSelected()>0 ){
2454 TheAISContext()->UnhilightSelected(Standard_False);
2455 // il y a des objets selected,on les parcourt
2456 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2457 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2458
2459
2460 if (HaveMode(aIO,aMode) ) {
2461 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2462 TheAISContext()->Deactivate(aIO,aMode);
2463 }
2464 else{
2465 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2466 TheAISContext()->Activate(aIO,aMode);
2467 }
2468
2469 }
2470 }
2471 else{
2472 // il n'y a pas d'objets selected
2473 // tous les objets diplayes sont traites
2474 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2475 it (GetMapOfAIS());
2476 while(it.More()){
2477 Handle(AIS_InteractiveObject) aIO =
2478 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2479 if (!aIO.IsNull()) {
2480 if (HaveMode(aIO,aMode) ) {
2481 di<<" Mode: "<<cmode<<" OFF pour "
2482 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2483 TheAISContext()->Deactivate(aIO,aMode);
2484 }
2485 else{
2486 di<<" Mode: "<<cmode<<" ON pour"
2487 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2488 TheAISContext()->Activate(aIO,aMode);
2489 }
2490 }
2491 it.Next();
2492 }
2493 }
2494 }
2495 }
2496 else if (HaveToSet && ThereIsName){
91322f44 2497 Standard_Integer aMode=Draw::Atoi(argv [2]);
7fd59977 2498 Handle(AIS_InteractiveObject) aIO =
2499 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2500
2501 if (!aIO.IsNull()) {
2502 const char *cmode="???";
2503
2504 switch (aMode) {
2505 case 0: cmode = "Shape"; break;
2506 case 1: cmode = "Vertex"; break;
2507 case 2: cmode = "Edge"; break;
2508 case 3: cmode = "Wire"; break;
2509 case 4: cmode = "Face"; break;
2510 case 5: cmode = "Shell"; break;
2511 case 6: cmode = "Solid"; break;
2512 case 7: cmode = "Compound"; break;
2513 }
2514
2515 if( !TheAISContext()->HasOpenedContext() ) {
2516 TheAISContext()->OpenLocalContext(Standard_False);
2517 // On charge tous les objets de la map
2518 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2519 while(it.More()){
2520 Handle(AIS_InteractiveObject) aShape=
2521 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2522 if (!aShape.IsNull())
2523 TheAISContext()->Load(aShape,0,Standard_False);
2524 it.Next();
2525 }
2526 TheAISContext()->Activate(aIO,aMode);
2527 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2528 }
2529
2530 else {
2531 // un Context local est deja ouvert
2532 if (HaveMode(aIO,aMode) ) {
2533 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2534 TheAISContext()->Deactivate(aIO,aMode);
2535 }
2536 else{
2537 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2538 TheAISContext()->Activate(aIO,aMode);
2539 }
2540 }
2541 }
2542 }
2543 }
2544 return 0;
7fd59977 2545}
2546
cb78155f 2547//! Auxiliary method to print Interactive Object information
2548static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
2549 const Handle(Standard_Transient)& theObject,
2550 Draw_Interpretor& theDI)
2551{
2552 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
2553 if (anObj.IsNull())
2554 {
2555 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
2556 return;
2557 }
7fd59977 2558
cb78155f 2559 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
2560 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
2561 << (theDetected.Contains (anObj) ? " Detected" : " ")
2562 << " Type: ";
2563 if (anObj->Type() == AIS_KOI_Datum)
2564 {
2565 // AIS_Datum
2566 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
2567 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
2568 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
2569 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
2570 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
2571 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
2572 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 2573 }
2574 // AIS_Shape
cb78155f 2575 else if (anObj->Type() == AIS_KOI_Shape
2576 && anObj->Signature() == 0)
2577 {
2578 theDI << " AIS_Shape";
7fd59977 2579 }
cb78155f 2580 else if (anObj->Type() == AIS_KOI_Relation)
2581 {
2582 // AIS_Dimention and AIS_Relation
2583 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
2584 switch (aRelation->KindOfDimension())
2585 {
2586 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
2587 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
2588 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
2589 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
2590 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
2591 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
2592 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
2593 default: theDI << " UNKNOWN dimension"; break;
2594 }
2595 }
2596 else
2597 {
2598 theDI << " UserPrs";
2599 }
2600 theDI << " (" << theObject->DynamicType()->Name() << ")";
7fd59977 2601}
2602
cb78155f 2603//! Print information about locally selected sub-shapes
2604static void localCtxInfo (Draw_Interpretor& theDI)
2605{
2606 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2607 if (!aCtx->HasOpenedContext())
2608 {
2609 return;
2610 }
7fd59977 2611
cb78155f 2612 TCollection_AsciiString aPrevName;
2613 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
2614 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
2615 {
2616 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
2617 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
2618 if (aSubShape.IsNull()
2619 || aShapeIO.IsNull()
2620 || !GetMapOfAIS().IsBound1 (aShapeIO))
2621 {
2622 continue;
2623 }
2624
2625 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
2626 TopTools_MapOfShape aFilter;
2627 Standard_Integer aNumber = 0;
2628 const TopoDS_Shape aShape = aShapeIO->Shape();
2629 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
2630 anIter.More(); anIter.Next())
2631 {
2632 if (!aFilter.Add (anIter.Current()))
2633 {
2634 continue; // filter duplicates
2635 }
2636
2637 ++aNumber;
2638 if (!anIter.Current().IsSame (aSubShape))
2639 {
2640 continue;
2641 }
2642
2643 Standard_CString aShapeName = NULL;
2644 switch (aSubShape.ShapeType())
2645 {
2646 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
2647 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
2648 case TopAbs_SOLID: aShapeName = " Solid"; break;
2649 case TopAbs_SHELL: aShapeName = " Shell"; break;
2650 case TopAbs_FACE: aShapeName = " Face"; break;
2651 case TopAbs_WIRE: aShapeName = " Wire"; break;
2652 case TopAbs_EDGE: aShapeName = " Edge"; break;
2653 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
2654 default:
2655 case TopAbs_SHAPE: aShapeName = " Shape"; break;
2656 }
2657
2658 if (aParentName != aPrevName)
2659 {
2660 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
2661 aPrevName = aParentName;
2662 }
2663 theDI << " " << aShapeName << " #" << aNumber << "\n";
2664 break;
2665 }
2666 }
2667}
7fd59977 2668
2669//==============================================================================
2670//function : VState
2671//purpose :
2672//Draw arg : vstate [nameA] ... [nameN]
2673//==============================================================================
cb78155f 2674static Standard_Integer VState (Draw_Interpretor& theDI,
2675 Standard_Integer theArgNb,
2676 Standard_CString* theArgVec)
7fd59977 2677{
cb78155f 2678 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2679 if (aCtx.IsNull())
2680 {
2681 std::cerr << "Error: No opened viewer!\n";
2682 return 1;
7fd59977 2683 }
cb78155f 2684
2685 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
2686 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
2687 {
2688 aDetected.Add (aCtx->DetectedCurrentObject());
2689 }
2690
2691 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
2692 if (theArgNb >= 2
2693 && !toShowAll)
2694 {
2695 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 2696 {
cb78155f 2697 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
2698 if (!GetMapOfAIS().IsBound2 (anObjName))
2699 {
2700 theDI << anObjName << " doesn't exist!\n";
2701 continue;
7fd59977 2702 }
2703
cb78155f 2704 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
2705 TCollection_AsciiString aName = anObjName;
2706 aName.LeftJustify (20, ' ');
2707 theDI << " " << aName << " ";
2708 objInfo (aDetected, anObjTrans, theDI);
2709 theDI << "\n";
7fd59977 2710 }
cb78155f 2711 return 0;
7fd59977 2712 }
cb78155f 2713
2714 if (aCtx->NbCurrents() > 0
2715 && !toShowAll)
2716 {
2717 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2718 {
2719 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
2720 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
2721 aName.LeftJustify (20, ' ');
2722 theDI << aName << " ";
2723 objInfo (aDetected, anObj, theDI);
2724 theDI << "\n";
7fd59977 2725 }
cb78155f 2726 return 0;
7fd59977 2727 }
2728
cb78155f 2729 theDI << "Neutral-point state:\n";
2730 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
2731 anObjIter.More(); anObjIter.Next())
2732 {
2733 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
2734 if (anObj.IsNull())
2735 {
2736 continue;
2737 }
2738
2739 TCollection_AsciiString aName = anObjIter.Key2();
2740 aName.LeftJustify (20, ' ');
2741 theDI << " " << aName << " ";
2742 objInfo (aDetected, anObj, theDI);
2743 theDI << "\n";
2744 }
2745 localCtxInfo (theDI);
7fd59977 2746 return 0;
2747}
2748
7fd59977 2749//=======================================================================
2750//function : PickObjects
2751//purpose :
2752//=======================================================================
2753Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2754 const AIS_KindOfInteractive TheType,
2755 const Standard_Integer TheSignature,
2756 const Standard_Integer MaxPick)
2757{
2758 Handle(AIS_InteractiveObject) IO;
2759 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2760
2761 // step 1: prepare the data
4952a30a 2762 if(curindex !=0){
7fd59977 2763 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2764 TheAISContext()->AddFilter(F1);
2765 }
2766
2767 // step 2 : wait for the selection...
2768// Standard_Boolean IsGood (Standard_False);
2769// Standard_Integer NbPick(0);
2770 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2771 Standard_Integer NbPickFail(0);
2772 Standard_Integer argccc = 5;
2773 const char *bufff[] = { "A", "B", "C","D", "E" };
2774 const char **argvvv = (const char **) bufff;
2775
2776
2777 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2778 while(ViewerMainLoop(argccc,argvvv)){}
2779 Standard_Integer NbStored = TheAISContext()->NbSelected();
2780 if((unsigned int ) NbStored != NbPickGood)
2781 NbPickGood= NbStored;
2782 else
2783 NbPickFail++;
2784 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2785 }
2786
2787 // step3 get result.
2788
2789 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2790
2791 Standard_Integer i(0);
2792 for(TheAISContext()->InitSelected();
2793 TheAISContext()->MoreSelected();
2794 TheAISContext()->NextSelected()){
2795 i++;
2796 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2797 arr->SetValue(i,IO2);
2798 }
2799
2800
2801 if(curindex>0)
2802 TheAISContext()->CloseLocalContext(curindex);
2803
2804 return Standard_True;
2805}
2806
2807
2808//=======================================================================
2809//function : PickObject
2810//purpose :
2811//=======================================================================
2812Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2813 const Standard_Integer TheSignature,
2814 const Standard_Integer MaxPick)
2815{
2816 Handle(AIS_InteractiveObject) IO;
2817 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2818
2819 // step 1: prepare the data
2820
4952a30a 2821 if(curindex !=0){
7fd59977 2822 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2823 TheAISContext()->AddFilter(F1);
2824 }
2825
2826 // step 2 : wait for the selection...
2827 Standard_Boolean IsGood (Standard_False);
2828 Standard_Integer NbPick(0);
2829 Standard_Integer argccc = 5;
2830 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2831 const char **argvvv = (const char **) bufff;
2832
2833
2834 while(!IsGood && NbPick<= MaxPick){
2835 while(ViewerMainLoop(argccc,argvvv)){}
2836 IsGood = (TheAISContext()->NbSelected()>0) ;
2837 NbPick++;
2838 cout<<"Nb Pick :"<<NbPick<<endl;
2839 }
2840
2841
2842 // step3 get result.
2843 if(IsGood){
2844 TheAISContext()->InitSelected();
2845 IO = TheAISContext()->SelectedInteractive();
2846 }
2847
4952a30a 2848 if(curindex!=0)
7fd59977 2849 TheAISContext()->CloseLocalContext(curindex);
2850 return IO;
2851}
2852
2853//=======================================================================
2854//function : PickShape
2855//purpose : First Activate the rightmode + Put Filters to be able to
2856// pick objets that are of type <TheType>...
2857//=======================================================================
2858
2859TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2860 const Standard_Integer MaxPick)
2861{
2862
2863 // step 1: prepare the data
2864
2865 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2866 TopoDS_Shape result;
2867
2868 if(TheType==TopAbs_SHAPE){
2869 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2870 TheAISContext()->AddFilter(F1);
2871 }
2872 else{
2873 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2874 TheAISContext()->AddFilter(TF);
2875 TheAISContext()->ActivateStandardMode(TheType);
2876
2877 }
2878
2879
2880 // step 2 : wait for the selection...
2881 Standard_Boolean NoShape (Standard_True);
2882 Standard_Integer NbPick(0);
2883 Standard_Integer argccc = 5;
2884 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2885 const char **argvvv = (const char **) bufff;
2886
2887
2888 while(NoShape && NbPick<= MaxPick){
2889 while(ViewerMainLoop(argccc,argvvv)){}
2890 NoShape = (TheAISContext()->NbSelected()==0) ;
2891 NbPick++;
2892 cout<<"Nb Pick :"<<NbPick<<endl;
2893 }
2894
2895 // step3 get result.
2896
2897 if(!NoShape){
2898
2899 TheAISContext()->InitSelected();
2900 if(TheAISContext()->HasSelectedShape())
2901 result = TheAISContext()->SelectedShape();
2902 else{
2903 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2904 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2905 }
2906 }
2907
2908 if(curindex>0)
2909 TheAISContext()->CloseLocalContext(curindex);
2910
2911 return result;
2912}
2913
2914
2915//=======================================================================
2916//function : PickShapes
2917//purpose :
2918//=======================================================================
2919Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2920 Handle(TopTools_HArray1OfShape)& thearr,
2921 const Standard_Integer MaxPick)
2922{
2923
2924 Standard_Integer Taille = thearr->Length();
2925 if(Taille>1)
2926 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2927
2928 // step 1: prepare the data
2929 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2930 if(TheType==TopAbs_SHAPE){
2931 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2932 TheAISContext()->AddFilter(F1);
2933 }
2934 else{
2935 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2936 TheAISContext()->AddFilter(TF);
2937 TheAISContext()->ActivateStandardMode(TheType);
2938
2939 }
2940
2941 // step 2 : wait for the selection...
2942
2943 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2944 Standard_Integer NbPickFail(0);
2945 Standard_Integer argccc = 5;
2946 const char *bufff[] = { "A", "B", "C","D", "E" };
2947 const char **argvvv = (const char **) bufff;
2948
2949
2950 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2951 while(ViewerMainLoop(argccc,argvvv)){}
2952 Standard_Integer NbStored = TheAISContext()->NbSelected();
2953 if((unsigned int ) NbStored != NbPickGood)
2954 NbPickGood= NbStored;
2955 else
2956 NbPickFail++;
2957 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2958 }
2959
2960 // step3 get result.
2961
2962 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2963
2964 Standard_Integer i(0);
2965 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2966 i++;
2967 if(TheAISContext()->HasSelectedShape())
2968 thearr->SetValue(i,TheAISContext()->SelectedShape());
2969 else{
2970 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2971 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2972 }
2973 }
2974
2975 TheAISContext()->CloseLocalContext(curindex);
2976 return Standard_True;
2977}
2978
2979
2980//=======================================================================
2981//function : VPickShape
2982//purpose :
2983//=======================================================================
2984static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2985{
2986 TopoDS_Shape PickSh;
2987 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2988
2989 if(argc==1)
2990 theType = TopAbs_SHAPE;
2991 else{
2992 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2993 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2994 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2995 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2996 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2997 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2998 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2999 }
3000
3001 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3002 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3003
3004 TCollection_AsciiString name;
3005
3006
3007 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3008 if(NbToPick==1){
3009 PickSh = ViewerTest::PickShape(theType);
3010
3011 if(PickSh.IsNull())
3012 return 1;
3013 if(argc>2){
3014 name += argv[2];
3015 }
3016 else{
3017
3018 if(!PickSh.IsNull()){
3019 nbOfSub[Standard_Integer(theType)]++;
3020 name += "Picked_";
3021 name += nameType[Standard_Integer(theType)];
3022 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3023 name +="_";
3024 name+=indxstring;
3025 }
3026 }
3027 // si on avait une petite methode pour voir si la shape
3028 // est deja dans la Double map, ca eviterait de creer....
3029 DBRep::Set(name.ToCString(),PickSh);
3030
3031 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3032 GetMapOfAIS().Bind(newsh, name);
3033 TheAISContext()->Display(newsh);
3034 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3035 }
3036
3037 // Plusieurs objets a picker, vite vite vite....
3038 //
3039 else{
3040 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3041 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3042 if(ViewerTest::PickShapes(theType,arr)){
3043 for(Standard_Integer i=1;i<=NbToPick;i++){
3044 PickSh = arr->Value(i);
3045 if(!PickSh.IsNull()){
3046 if(autonaming){
3047 nbOfSub[Standard_Integer(theType)]++;
3048 name.Clear();
3049 name += "Picked_";
3050 name += nameType[Standard_Integer(theType)];
3051 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3052 name +="_";
3053 name+=indxstring;
3054 }
3055 }
3056 else
3057 name = argv[1+i];
3058
3059 DBRep::Set(name.ToCString(),PickSh);
3060 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3061 GetMapOfAIS().Bind(newsh, name);
3062 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3063 TheAISContext()->Display(newsh);
3064
3065 }
3066 }
3067 }
3068 return 0;
7fd59977 3069}
7fd59977 3070
3071//=======================================================================
3072//function : list of known objects
3073//purpose :
3074//=======================================================================
3075static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3076{
3077 // 1234567890 12345678901234567 123456789
3078 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3079 TCollection_AsciiString BlankLine(64,'_');
3080 Standard_Integer i ;
3081
3082 di<<"/n"<<BlankLine.ToCString()<<"\n";
3083
3084 for( i =0;i<=2;i++)
3085 Colum[i].Center(20,' ');
3086 for(i=0;i<=2;i++)
3087 di<<"|"<<Colum[i].ToCString();
3088 di<<"|"<<"\n";
3089
3090 di<<BlankLine.ToCString()<<"\n";
3091
3092 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3093 const char ** names = GetTypeNames();
3094
3095 TCollection_AsciiString curstring;
3096 TCollection_AsciiString curcolum[3];
3097
3098
3099 // les objets de type Datum..
3100 curcolum[1]+="Datum";
3101 for(i =0;i<=6;i++){
3102 curcolum[0].Clear();
3103 curcolum[0] += names[i];
3104
3105 curcolum[2].Clear();
3106 curcolum[2]+=TCollection_AsciiString(i+1);
3107
3108 for(Standard_Integer j =0;j<=2;j++){
3109 curcolum[j].Center(20,' ');
3110 di<<"|"<<curcolum[j].ToCString();
3111 }
3112 di<<"|"<<"\n";
3113 }
3114 di<<BlankLine.ToCString()<<"\n";
3115
3116 // les objets de type shape
3117 curcolum[1].Clear();
3118 curcolum[1]+="Shape";
3119 curcolum[1].Center(20,' ');
3120
3121 for(i=0;i<=2;i++){
3122 curcolum[0].Clear();
3123 curcolum[0] += names[7+i];
3124 curcolum[2].Clear();
3125 curcolum[2]+=TCollection_AsciiString(i);
3126
3127 for(Standard_Integer j =0;j<=2;j++){
3128 curcolum[j].Center(20,' ');
3129 di<<"|"<<curcolum[j].ToCString();
3130 }
3131 di<<"|"<<"\n";
3132 }
3133 di<<BlankLine.ToCString()<<"\n";
3134 // les IO de type objet...
3135 curcolum[1].Clear();
3136 curcolum[1]+="Object";
3137 curcolum[1].Center(20,' ');
3138 for(i=0;i<=1;i++){
3139 curcolum[0].Clear();
3140 curcolum[0] += names[10+i];
3141 curcolum[2].Clear();
3142 curcolum[2]+=TCollection_AsciiString(i);
3143
3144 for(Standard_Integer j =0;j<=2;j++){
3145 curcolum[j].Center(20,' ');
3146 di<<"|"<<curcolum[j].ToCString();
3147 }
3148 di<<"|"<<"\n";
3149 }
3150 di<<BlankLine.ToCString()<<"\n";
3151 // les contraintes et dimensions.
3152 // pour l'instant on separe juste contraintes et dimensions...
3153 // plus tard, on detaillera toutes les sortes...
3154 curcolum[1].Clear();
3155 curcolum[1]+="Relation";
3156 curcolum[1].Center(20,' ');
3157 for(i=0;i<=1;i++){
3158 curcolum[0].Clear();
3159 curcolum[0] += names[12+i];
3160 curcolum[2].Clear();
3161 curcolum[2]+=TCollection_AsciiString(i);
3162
3163 for(Standard_Integer j =0;j<=2;j++){
3164 curcolum[j].Center(20,' ');
3165 di<<"|"<<curcolum[j].ToCString();
3166 }
3167 di<<"|"<<"\n";
3168 }
3169 di<<BlankLine.ToCString()<<"\n";
3170
3171
3172 return 0;
3173}
3174
3175
3176static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3177{
4952a30a 3178 if(argc!=2) return 1;
7fd59977 3179
3180 AIS_KindOfInteractive TheType;
3181 Standard_Integer TheSign(-1);
3182 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3183
3184
3185 AIS_ListOfInteractive LIO;
3186
3187 // en attendant l'amelioration ais pour les dimensions...
3188 //
3189 Standard_Integer dimension_status(-1);
3190 if(TheType==AIS_KOI_Relation){
3191 dimension_status = TheSign ==1 ? 1 : 0;
3192 TheSign=-1;
3193 }
3194
3195 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3196 Handle(AIS_InteractiveObject) curio;
3197 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3198 curio = it.Value();
3199
3200 if(dimension_status == -1)
3201 TheAISContext()->Erase(curio,Standard_False);
3202 else {
3203 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3204 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3205 (dimension_status==1 && KOD != AIS_KOD_NONE))
3206 TheAISContext()->Erase(curio,Standard_False);
3207 }
3208 }
3209 TheAISContext()->UpdateCurrentViewer();
3210 return 0;
3211}
3212static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3213{
3214 if(argc!=2) return 1;
3215
3216 AIS_KindOfInteractive TheType;
3217 Standard_Integer TheSign(-1);
3218 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3219
3220 // en attendant l'amelioration ais pour les dimensions...
3221 //
3222 Standard_Integer dimension_status(-1);
3223 if(TheType==AIS_KOI_Relation){
3224 dimension_status = TheSign ==1 ? 1 : 0;
3225 TheSign=-1;
3226 }
3227
3228 AIS_ListOfInteractive LIO;
3229 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3230 Handle(AIS_InteractiveObject) curio;
3231 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3232 curio = it.Value();
3233 if(dimension_status == -1)
3234 TheAISContext()->Display(curio,Standard_False);
3235 else {
3236 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3237 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3238 (dimension_status==1 && KOD != AIS_KOD_NONE))
3239 TheAISContext()->Display(curio,Standard_False);
3240 }
3241
3242 }
3243
3244 TheAISContext()->UpdateCurrentViewer();
3245 return 0;
3246}
3247
3248//==============================================================================
3249//function : VSetTransMode
3250//purpose :
3251//Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3252//==============================================================================
3253
3254static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3255 // Verification des arguments
3256 if ( a3DView().IsNull() ) {
3257 ViewerTest::ViewerInit();
3258 di << "La commande vinit n'a pas ete appele avant" << "\n";
3259 }
3260
3261 if ( argc < 3 || argc > 8 ) {
3262 di << argv[0] << " Invalid number of arguments" << "\n";
3263 return 1;
3264 }
3265
3266 TCollection_AsciiString shapeName;
3267 shapeName = argv[1];
91322f44 3268 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
7fd59977 3269 Standard_Integer persFlag2 = 0;
3270 Standard_Integer persFlag3 = 0;
3271 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3272 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
91322f44 3273 persFlag2 = Draw::Atoi(argv[3]);
7fd59977 3274 }
3275 if ( argc == 5 || argc == 8 ) {
91322f44 3276 persFlag3 = Draw::Atoi(argv[4]);
7fd59977 3277 }
3278 if ( argc >= 6 ) {
91322f44 3279 origin.SetX( Draw::Atof(argv[argc - 3]) );
3280 origin.SetY( Draw::Atof(argv[argc - 2]) );
3281 origin.SetZ( Draw::Atof(argv[argc - 1]) );
7fd59977 3282 }
3283
3284 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
7fd59977 3285 Handle(Standard_Transient) anObj;
3286 if ( IsBound ) {
3287 anObj = GetMapOfAIS().Find2(shapeName);
3288 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3289 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3290 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3291 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3292 di << argv[0] << " All persistence modifiers were removed" << "\n";
3293 }
3294 } else {
3295 di << argv[0] << " Wrong object type" << "\n";
3296 return 1;
3297 }
3298 } else { // Create the AIS_Shape from a name
3299 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3300 if ( !aShape.IsNull() ) {
3301 GetMapOfAIS().Bind( aShape, shapeName );
3302 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3303 TheAISContext()->Display( aShape, Standard_False );
3304 } else {
3305 di << argv[0] << " Object not found" << "\n";
3306 return 1;
3307 }
3308 }
3309
3310 // Upadate the screen and redraw the view
3311 TheAISContext()->UpdateCurrentViewer();
3312 return 0;
3313}
3314
3315static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3316{
3317 ifstream s(a[1]);
3318 BRep_Builder builder;
3319 TopoDS_Shape shape;
3320 BRepTools::Read(shape, s, builder);
3321 DBRep::Set(a[1], shape);
3322 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3323 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3324 Ctx->Display(ais);
3325 return 0;
3326}
7fd59977 3327
3328//==============================================================================
3329//function : ViewerTest::Commands
3330//purpose : Add all the viewer command in the Draw_Interpretor
3331//==============================================================================
3332
3333void ViewerTest::Commands(Draw_Interpretor& theCommands)
3334{
3335 ViewerTest::ViewerCommands(theCommands);
3336 ViewerTest::RelationCommands(theCommands);
3337 ViewerTest::ObjectCommands(theCommands);
3338 ViewerTest::FilletCommands(theCommands);
3339 ViewerTest::VoxelCommands(theCommands);
3946774d 3340 ViewerTest::OpenGlCommands(theCommands);
7fd59977 3341
3342 const char *group = "AIS_Display";
3343
3344 // display
1c88cbaf 3345 theCommands.Add("visos",
3346 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3347 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3348 __FILE__, visos, group);
7fd59977 3349
3350 theCommands.Add("vdisplay",
ac4aaa98 3351 "vdisplay name1 [name2] ... [name n]"
3352 "\n\t\t: Displays named objects",
7fd59977 3353 __FILE__,VDisplay2,group);
3354
3355 theCommands.Add("verase",
ac4aaa98 3356 "verase [name1] ... [name n]"
3357 "\n\t\t: Erases selected or named objects."
3358 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
b514beda 3359 __FILE__, VErase, group);
7fd59977 3360
eef7fc64 3361 theCommands.Add("vremove",
3362 "vremove [-context] [name1] ... [name n]"
3363 "or vremove [-context] -all to remove all objects"
3364 "\n\t\t: Removes selected or named objects."
3365 "\n\t\t If -context is in arguments, the objects are not deleted"
3366 "\n\t\t from the map of objects and names.",
3367 __FILE__, VRemove, group);
3368
7fd59977 3369 theCommands.Add("vdonly",
ac4aaa98 3370 "vdonly [name1] ... [name n]"
3371 "\n\t\t: Displays only selected or named objects",
7fd59977 3372 __FILE__,VDonly2,group);
3373
3374 theCommands.Add("vdisplayall",
ac4aaa98 3375 "Displays all erased interactive objects (see vdir and vstate)",
7fd59977 3376 __FILE__,VDisplayAll,group);
3377
3378 theCommands.Add("veraseall",
ac4aaa98 3379 "Erases all objects displayed in the viewer",
b514beda 3380 __FILE__, VErase, group);
7fd59977 3381
3382 theCommands.Add("verasetype",
ac4aaa98 3383 "verasetype <Type>"
3384 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
7fd59977 3385 __FILE__,VEraseType,group);
3386
3387 theCommands.Add("vdisplaytype",
3388 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3389 __FILE__,VDisplayType,group);
3390
3391 theCommands.Add("vdisplaymode",
3392 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3393 __FILE__,VDispMode,group);
3394
3395 theCommands.Add("verasemode",
3396 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3397 __FILE__,VDispMode,group);
3398
3399 theCommands.Add("vsetdispmode",
ac4aaa98 3400 "vsetdispmode [name] mode(1,2,..)"
3401 "\n\t\t: Sets display mode for all, selected or named objects.",
7fd59977 3402 __FILE__,VDispMode,group);
3403
3404 theCommands.Add("vunsetdispmode",
ac4aaa98 3405 "vunsetdispmode [name]"
3406 "\n\t\t: Unsets custom display mode for selected or named objects.",
7fd59977 3407 __FILE__,VDispMode,group);
3408
3409 theCommands.Add("vdir",
ac4aaa98 3410 "Lists all objects displayed in 3D viewer",
7fd59977 3411 __FILE__,VDebug,group);
3412
3413 theCommands.Add("vdump",
ac4aaa98 3414 #ifdef HAVE_FREEIMAGE
3415 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]"
3416 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3417 #else
3418 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height]"
3419 "\n\t\t: Dumps contents of viewer window to PPM image file",
3420 #endif
7fd59977 3421 __FILE__,VDump,group);
3422
3423 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3424 __FILE__,VSubInt,group);
3425
3426 theCommands.Add("vsetcolor",
ac4aaa98 3427 "vsetcolor [name] ColorName"
3428 "\n\t\t: Sets color for all, selected or named objects.",
7fd59977 3429 __FILE__,VColor2,group);
3430
3431 theCommands.Add("vunsetcolor",
ac4aaa98 3432 "vunsetcolor [name]"
3433 "\n\t\t: Resets color for all, selected or named objects.",
7fd59977 3434 __FILE__,VColor2,group);
3435
3436 theCommands.Add("vsettransparency",
ac4aaa98 3437 "vsettransparency [name] Coefficient"
3438 "\n\t\t: Sets transparency for all, selected or named objects."
3439 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
7fd59977 3440 __FILE__,VTransparency,group);
3441
3442 theCommands.Add("vunsettransparency",
ac4aaa98 3443 "vunsettransparency [name]"
3444 "\n\t\t: Resets transparency for all, selected or named objects.",
7fd59977 3445 __FILE__,VTransparency,group);
3446
3447 theCommands.Add("vsetmaterial",
3448 "vmaterial : vmaterial [name of shape] MaterialName",
3449 __FILE__,VMaterial,group);
3450
3451 theCommands.Add("vunsetmaterial",
3452 "vmaterial : vmaterial [name of shape]",
3453 __FILE__,VMaterial,group);
3454
3455 theCommands.Add("vsetwidth",
3456 "vsetwidth : vwidth [name of shape] width(0->10)",
3457 __FILE__,VWidth,group);
3458
3459 theCommands.Add("vunsetwidth",
3460 "vunsetwidth : vwidth [name of shape]",
3461 __FILE__,VWidth,group);
3462
99c56d44 3463 theCommands.Add("vsetinteriorstyle",
3464 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3465 __FILE__,VInteriorStyle,group);
3466
7fd59977 3467 theCommands.Add("vardis",
3468 "vardis : display activeareas",
3469 __FILE__,VDispAreas,group);
3470
3471 theCommands.Add("varera",
3472 "varera : erase activeareas",
3473 __FILE__,VClearAreas,group);
3474
3475 theCommands.Add("vsensdis",
3476 "vardisp : display active entities",
3477 __FILE__,VDispSensi,group);
3478 theCommands.Add("vsensera",
3479 "vardisp : erase active entities",
3480 __FILE__,VClearSensi,group);
3481
3c982548 3482 theCommands.Add("vselprecision",
3483 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3484 __FILE__,VSelPrecision,group);
3485
7fd59977 3486 theCommands.Add("vperf",
3487 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3488 __FILE__,VPerf,group);
3489
3490 theCommands.Add("vanimation",
3491 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3492 __FILE__,VAnimation,group);
3493
3494 theCommands.Add("vsetshading",
3495 "vsetshading : vsetshading name Quality(default=0.0008) ",
3496 __FILE__,VShading,group);
3497
3498 theCommands.Add("vunsetshading",
3499 "vunsetshading :vunsetshading name ",
3500 __FILE__,VShading,group);
3501
3502 theCommands.Add("vtexture",
3503 "'vtexture NameOfShape TextureFile' \n \
3504 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3505 or 'vtexture NameOfShape ?' to list available textures\n \
3506 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3507 __FILE__,VTexture,group);
3508
3509 theCommands.Add("vtexscale",
3510 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3511 or 'vtexscale NameOfShape ScaleUV' \n \
3512 or 'vtexscale NameOfShape' to disable scaling\n ",
3513 __FILE__,VTexture,group);
3514
3515 theCommands.Add("vtexorigin",
3516 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3517 or 'vtexorigin NameOfShape UVOrigin' \n \
3518 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3519 __FILE__,VTexture,group);
3520
3521 theCommands.Add("vtexrepeat",
3522 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3523 or 'vtexrepeat NameOfShape UVRepeat \n \
3524 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3525 VTexture,group);
3526
3527 theCommands.Add("vtexdefault",
3528 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3529 VTexture,group);
3530
3531 theCommands.Add("vsetam",
3532 "vsetActivatedModes: vsetam mode(1->7) ",
3533 __FILE__,VActivatedMode,group);
3534
3535 theCommands.Add("vunsetam",
3536 "vunsetActivatedModes: vunsetam ",
3537 __FILE__,VActivatedMode,group);
3538
ac4aaa98 3539 theCommands.Add("vstate",
3540 "vstate [name1] ... [nameN]"
3541 "\n\t\t: Reports show/hidden state for selected or named objects",
7fd59977 3542 __FILE__,VState,group);
3543
3544 theCommands.Add("vpickshapes",
3545 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3546 __FILE__,VPickShape,group);
3547
3548 theCommands.Add("vtypes",
3549 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3550 VIOTypes,group);
3551
3552 theCommands.Add("