0025991: Cyclic dependency in OCCT detected by WOK compiler
[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//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
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>
4e18052b 28
7fd59977 29#include <TopLoc_Location.hxx>
30#include <TopTools_HArray1OfShape.hxx>
31#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 32#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 33#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 34#include <TColStd_MapOfTransient.hxx>
7fd59977 35#include <OSD_Timer.hxx>
36#include <Geom_Axis2Placement.hxx>
37#include <Geom_Axis1Placement.hxx>
38#include <gp_Trsf.hxx>
39#include <TopExp_Explorer.hxx>
40#include <BRepAdaptor_Curve.hxx>
41#include <StdSelect_ShapeTypeFilter.hxx>
42#include <AIS.hxx>
ad3217cd 43#include <AIS_ColoredShape.hxx>
7fd59977 44#include <AIS_InteractiveObject.hxx>
45#include <AIS_Trihedron.hxx>
46#include <AIS_Axis.hxx>
47#include <AIS_Relation.hxx>
48#include <AIS_TypeFilter.hxx>
49#include <AIS_SignatureFilter.hxx>
cb78155f 50#include <AIS_LocalContext.hxx>
7fd59977 51#include <AIS_ListOfInteractive.hxx>
52#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 53#include <Aspect_InteriorStyle.hxx>
34db9c00 54#include <Aspect_Window.hxx>
99c56d44 55#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 56#include <Graphic3d_AspectLine3d.hxx>
a1954302 57#include <Graphic3d_CStructure.hxx>
392ac980 58#include <Graphic3d_TextureRoot.hxx>
692613e5 59#include <Image_AlienPixMap.hxx>
6262338c 60#include <Prs3d_Drawer.hxx>
99c56d44 61#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 62#include <Prs3d_IsoAspect.hxx>
6262338c 63#include <Prs3d_PointAspect.hxx>
8e7c8ccf 64#include <Select3D_SensitiveWire.hxx>
65#include <SelectMgr_EntityOwner.hxx>
66#include <StdSelect_BRepOwner.hxx>
67#include <StdSelect_ViewerSelector3d.hxx>
68#include <Select3D_Projector.hxx>
cb78155f 69#include <TopTools_MapOfShape.hxx>
4e18052b 70#include <ViewerTest_AutoUpdater.hxx>
7fd59977 71
7fd59977 72#include <stdio.h>
7fd59977 73
74#include <Draw_Interpretor.hxx>
75#include <TCollection_AsciiString.hxx>
76#include <Draw_PluginMacro.hxx>
7fd59977 77
78// avoid warnings on 'extern "C"' functions returning C++ classes
79#ifdef WNT
80#define _CRT_SECURE_NO_DEPRECATE
81#pragma warning(4:4190)
82#pragma warning (disable:4996)
83#endif
84
85#include <NIS_InteractiveContext.hxx>
86#include <NIS_Triangulated.hxx>
87extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
88
7fd59977 89#include <Quantity_Color.hxx>
90#include <Quantity_NameOfColor.hxx>
91
92#include <Graphic3d_NameOfMaterial.hxx>
93
6262338c 94#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
95#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
96#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 97
792c785c 98//=======================================================================
99//function : GetColorFromName
100//purpose : get the Quantity_NameOfColor from a string
101//=======================================================================
7fd59977 102
792c785c 103Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
104{
8316c618 105 Quantity_NameOfColor aColor = DEFAULT_COLOR;
106 Quantity_Color::ColorFromName (theName, aColor);
107 return aColor;
7fd59977 108}
109
110//=======================================================================
7fd59977 111//function : GetTypeNames
112//purpose :
113//=======================================================================
114static const char** GetTypeNames()
115{
116 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
117 "Shape","ConnectedShape","MultiConn.Shape",
118 "ConnectedInter.","MultiConn.",
119 "Constraint","Dimension"};
120 static const char** ThePointer = names;
121 return ThePointer;
122}
123
124//=======================================================================
125//function : GetTypeAndSignfromString
126//purpose :
127//=======================================================================
128void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
129{
130 const char ** thefullnames = GetTypeNames();
131 Standard_Integer index(-1);
132
133 for(Standard_Integer i=0;i<=13 && index==-1;i++)
134 if(!strcasecmp(name,thefullnames[i]))
135 index = i;
136
137 if(index ==-1){
138 TheType = AIS_KOI_None;
139 TheSign = -1;
140 return;
141 }
142
143 if(index<=6){
144 TheType = AIS_KOI_Datum;
145 TheSign = index+1;
146 }
147 else if (index <=9){
148 TheType = AIS_KOI_Shape;
149 TheSign = index-7;
150 }
151 else if(index<=11){
152 TheType = AIS_KOI_Object;
153 TheSign = index-10;
154 }
155 else{
156 TheType = AIS_KOI_Relation;
157 TheSign = index-12;
158 }
159
160}
161
162
163
164#include <string.h>
165#include <Draw_Interpretor.hxx>
166#include <Draw.hxx>
167#include <Draw_Appli.hxx>
168#include <DBRep.hxx>
169
170
171#include <TCollection_AsciiString.hxx>
172#include <V3d_Viewer.hxx>
173#include <V3d_View.hxx>
174#include <V3d.hxx>
175
176#include <AIS_InteractiveContext.hxx>
177#include <AIS_Shape.hxx>
178#include <AIS_TexturedShape.hxx>
179#include <AIS_DisplayMode.hxx>
180#include <TColStd_MapOfInteger.hxx>
181#include <AIS_MapOfInteractive.hxx>
182#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
183#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
184#include <ViewerTest_EventManager.hxx>
185
186#include <TopoDS_Solid.hxx>
187#include <BRepTools.hxx>
188#include <BRep_Builder.hxx>
189#include <TopAbs_ShapeEnum.hxx>
190
191#include <TopoDS.hxx>
192#include <BRep_Tool.hxx>
193
194
195#include <Draw_Window.hxx>
196#include <AIS_ListIteratorOfListOfInteractive.hxx>
197#include <AIS_ListOfInteractive.hxx>
198#include <AIS_DisplayMode.hxx>
199#include <TopTools_ListOfShape.hxx>
200#include <BRepOffsetAPI_MakeThickSolid.hxx>
201#include <BRepOffset.hxx>
202
7fd59977 203//==============================================================================
204// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
205//==============================================================================
206Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
207 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
208 return TheMap;
209}
210
9558a876
A
211
212//==============================================================================
213//function : VDisplayAISObject
214//purpose : register interactive object in the map of AIS objects;
215// if other object with such name already registered, it will be kept
216// or replaced depending on value of <theReplaceIfExists>,
217// if "true" - the old object will be cleared from AIS context;
218// returns Standard_True if <theAISObj> registered in map;
219//==============================================================================
220Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
221 const Handle(AIS_InteractiveObject)& theAISObj,
222 Standard_Boolean theReplaceIfExists = Standard_True)
223{
224 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
225 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
226 if (aContextAIS.IsNull())
227 {
228 std::cout << "AIS context is not available.\n";
229 return Standard_False;
230 }
231
232 if (aMap.IsBound2 (theName))
233 {
234 if (!theReplaceIfExists)
235 {
236 std::cout << "Other interactive object has been already "
237 << "registered with name: " << theName << ".\n"
238 << "Please use another name.\n";
239 return Standard_False;
240 }
241
242 // stop displaying object
243 Handle(AIS_InteractiveObject) anOldObj =
244 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
245
246 if (!anOldObj.IsNull())
2195ab96 247 aContextAIS->Remove (anOldObj, Standard_True);
9558a876
A
248
249 // remove name and old object from map
250 aMap.UnBind2 (theName);
251 }
252
208e6839 253 if (theAISObj.IsNull())
254 {
255 // object with specified name already unbound
256 return Standard_True;
257 }
258
9558a876
A
259 // unbind AIS object if was bound with another name
260 aMap.UnBind1 (theAISObj);
261
262 // can be registered without rebinding
263 aMap.Bind (theAISObj, theName);
264 aContextAIS->Display (theAISObj, Standard_True);
265 return Standard_True;
266}
267
7fd59977 268static TColStd_MapOfInteger theactivatedmodes(8);
269static TColStd_ListOfTransient theEventMgrs;
270
271static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
272 const Handle(AIS_InteractiveContext)& Ctx)
273{
274 theEventMgrs.Clear();
275 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
276}
277
24de79c3 278static Handle(V3d_View)& a3DView()
279{
7fd59977 280 static Handle(V3d_View) Viou;
281 return Viou;
282}
283
24de79c3 284
7fd59977 285Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
286 static Handle(AIS_InteractiveContext) aContext;
287 return aContext;
288}
289
24de79c3 290const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 291{
292 return a3DView();
293}
294void ViewerTest::CurrentView(const Handle(V3d_View)& V)
295{
296 a3DView() = V;
297}
298
299Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
300{
301 static Handle(NIS_InteractiveContext) aContext;
302 if (aContext.IsNull()) {
303 aContext = new NIS_InteractiveContext;
304 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
305 }
306 return aContext;
307}
308
24de79c3 309const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 310{
311 return TheAISContext();
312}
313
314void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
315{
316 TheAISContext() = aCtx;
317 ViewerTest::ResetEventManager();
318}
319
320Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
321{
4952a30a 322 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 323}
324
325Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
326{
4952a30a 327 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 328}
329
330
331void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
332 theEventMgrs.Prepend(EM);
333}
334
335void ViewerTest::UnsetEventManager()
336{
337 theEventMgrs.RemoveFirst();
338}
339
340
341void ViewerTest::ResetEventManager()
342{
343 const Handle(NIS_View) aView =
344 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
345 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
346}
347
348Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
349{
350 Handle(ViewerTest_EventManager) EM;
351 if(theEventMgrs.IsEmpty()) return EM;
352 Handle(Standard_Transient) Tr = theEventMgrs.First();
353 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
354 return EM;
355}
356
7fd59977 357//=======================================================================
34db9c00 358//function : Get Context and active view
7fd59977 359//purpose :
360//=======================================================================
34db9c00 361static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
362 Handle(V3d_View)& theView)
7fd59977 363{
34db9c00 364 theCtx = ViewerTest::GetAISContext();
365 theView = ViewerTest::CurrentView();
366 if (theCtx.IsNull()
367 || theView.IsNull())
7fd59977 368 {
34db9c00 369 std::cout << "Error: cannot find an active view!\n";
370 return Standard_False;
7fd59977 371 }
34db9c00 372 return Standard_True;
7fd59977 373}
374
7fd59977 375//==============================================================================
376//function : GetShapeFromName
377//purpose : Compute an Shape from a draw variable or a file name
378//==============================================================================
379
380static TopoDS_Shape GetShapeFromName(const char* name)
381{
382 TopoDS_Shape S = DBRep::Get(name);
383
384 if ( S.IsNull() ) {
385 BRep_Builder aBuilder;
386 BRepTools::Read( S, name, aBuilder);
387 }
388
389 return S;
390}
4e18e72a 391
7fd59977 392//==============================================================================
393//function : GetAISShapeFromName
394//purpose : Compute an AIS_Shape from a draw variable or a file name
395//==============================================================================
396Handle(AIS_Shape) GetAISShapeFromName(const char* name)
397{
398 Handle(AIS_Shape) retsh;
399
400 if(GetMapOfAIS().IsBound2(name)){
401 const Handle(AIS_InteractiveObject) IO =
402 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
403 if (!IO.IsNull()) {
eafb234b 404 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 405 if(IO->Signature()==0){
406 retsh = *((Handle(AIS_Shape)*)&IO);
407 }
408 else
409 cout << "an Object which is not an AIS_Shape "
410 "already has this name!!!"<<endl;
eafb234b 411 }
7fd59977 412 }
413 return retsh;
414 }
415
416
417 TopoDS_Shape S = GetShapeFromName(name);
418 if ( !S.IsNull() ) {
419 retsh = new AIS_Shape(S);
420 }
421 return retsh;
422}
423
424
425//==============================================================================
426//function : Clear
427//purpose : Remove all the object from the viewer
428//==============================================================================
429void ViewerTest::Clear()
430{
431 if ( !a3DView().IsNull() ) {
432 if (TheAISContext()->HasOpenedContext())
433 TheAISContext()->CloseLocalContext();
434 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
435 while ( it.More() ) {
436 cout << "Remove " << it.Key2() << endl;
437 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
438 const Handle(AIS_InteractiveObject) anObj =
439 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
440 TheAISContext()->Remove(anObj,Standard_False);
441 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
442 const Handle(NIS_InteractiveObject) anObj =
443 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
ffe2bea7 444 TheNISContext()->Remove(anObj);
7fd59977 445 }
446 it.Next();
447 }
448 TheAISContext()->UpdateCurrentViewer();
ffe2bea7 449// TheNISContext()->UpdateViews();
7fd59977 450 GetMapOfAIS().Clear();
451 }
452}
453
454//==============================================================================
455//function : StandardModesActivation
456//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
457// Context
458//==============================================================================
459void ViewerTest::StandardModeActivation(const Standard_Integer mode )
460{
461 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
462 if(mode==0) {
463 if (TheAISContext()->HasOpenedContext())
464 aContext->CloseLocalContext();
465 } else {
466
467 if(!aContext->HasOpenedContext()) {
468 // To unhilight the preselected object
469 aContext->UnhilightCurrents(Standard_False);
470 // Open a local Context in order to be able to select subshape from
471 // the selected shape if any or for all if there is no selection
472 if (!aContext->FirstCurrentObject().IsNull()){
473 aContext->OpenLocalContext(Standard_False);
474
475 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
476 aContext->Load( aContext->Current(),-1,Standard_True);
477 }
478 }
479 else
480 aContext->OpenLocalContext();
481 }
482
483 const char *cmode="???";
484
485 switch (mode) {
486 case 0: cmode = "Shape"; break;
487 case 1: cmode = "Vertex"; break;
488 case 2: cmode = "Edge"; break;
489 case 3: cmode = "Wire"; break;
490 case 4: cmode = "Face"; break;
491 case 5: cmode = "Shell"; break;
492 case 6: cmode = "Solid"; break;
4754e164 493 case 7: cmode = "Compsolid"; break;
494 case 8: cmode = "Compound"; break;
7fd59977 495 }
496
497 if(theactivatedmodes.Contains(mode))
498 { // Desactivate
499 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
500 theactivatedmodes.Remove(mode);
501 cout<<"Mode "<< cmode <<" OFF"<<endl;
502 }
503 else
504 { // Activate
505 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
506 theactivatedmodes.Add(mode);
507 cout<<"Mode "<< cmode << " ON" << endl;
508 }
509 }
510}
511
512//==============================================================================
1c88cbaf 513//function : CopyIsoAspect
514//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
515//==============================================================================
516static Handle(Prs3d_IsoAspect) CopyIsoAspect
517 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
518 const Standard_Integer theNbIsos)
519{
520 Quantity_Color aColor;
521 Aspect_TypeOfLine aType;
522 Standard_Real aWidth;
523
524 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
525
526 Handle(Prs3d_IsoAspect) aResult =
527 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
528
529 return aResult;
530}
531
532//==============================================================================
533//function : visos
534//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
535//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
536//==============================================================================
537static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
538{
539 if (TheAISContext().IsNull()) {
540 di << argv[0] << " Call 'vinit' before!\n";
541 return 1;
542 }
543
544 if (argc <= 1) {
545 di << "Current number of isos : " <<
546 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
547 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
548 di << "IsoOnPlane mode is " <<
549 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
550
551 return 0;
552 }
553
554 Standard_Integer aLastInd = argc - 1;
555 Standard_Boolean isChanged = Standard_False;
1d47d8d0 556 Standard_Integer aNbUIsos = 0;
557 Standard_Integer aNbVIsos = 0;
1c88cbaf 558
559 if (aLastInd >= 3) {
560 Standard_Boolean isIsoOnPlane = Standard_False;
561
562 if (strcmp(argv[aLastInd], "1") == 0) {
563 isIsoOnPlane = Standard_True;
564 isChanged = Standard_True;
565 } else if (strcmp(argv[aLastInd], "0") == 0) {
566 isIsoOnPlane = Standard_False;
567 isChanged = Standard_True;
568 }
569
570 if (isChanged) {
571 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
572 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
573 aLastInd -= 3;
574
575 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
576 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
577
578 TheAISContext()->IsoOnPlane(isIsoOnPlane);
579
580 if (aLastInd == 0) {
581 // If there are no shapes provided set the default numbers.
582 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
583 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
584 }
585 }
586 }
587
588 Standard_Integer i;
589
590 for (i = 1; i <= aLastInd; i++) {
591 TCollection_AsciiString name(argv[i]);
592 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
593
594 if (IsBound) {
595 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
596 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
597 const Handle(AIS_InteractiveObject) aShape =
598 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 599 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 600 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
601 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
602
603 if (isChanged) {
604 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
605 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
606 TheAISContext()->SetLocalAttributes
607 (aShape, CurDrawer, Standard_False);
608 TheAISContext()->Redisplay(aShape);
609 } else {
610 di << "Number of isos for " << argv[i] << " : "
611 << aUIso->Number() << " " << aVIso->Number() << "\n";
612 }
613 } else {
614 di << argv[i] << ": Not an AIS interactive object!\n";
615 }
616 } else {
617 di << argv[i] << ": Use 'vdisplay' before\n";
618 }
619 }
620
621 if (isChanged) {
622 TheAISContext()->UpdateCurrentViewer();
623 }
624
625 return 0;
626}
627
628//==============================================================================
7fd59977 629//function : VDispAreas,VDispSensitive,...
34db9c00 630//purpose :
7fd59977 631//==============================================================================
34db9c00 632static Standard_Integer VDispAreas (Draw_Interpretor& ,
633 Standard_Integer theArgNb,
634 Standard_CString* )
7fd59977 635{
34db9c00 636 if (theArgNb > 1)
637 {
638 std::cout << "Error: wrong syntax!\n";
639 return 1;
640 }
641
642 Handle(AIS_InteractiveContext) aCtx;
643 Handle(V3d_View) aView;
644 if (!getCtxAndView (aCtx, aView))
645 {
646 return 1;
647 }
7fd59977 648
34db9c00 649 aCtx->DisplayActiveAreas (aView);
7fd59977 650 return 0;
651}
34db9c00 652static Standard_Integer VClearAreas (Draw_Interpretor& ,
653 Standard_Integer theArgNb,
654 Standard_CString* )
7fd59977 655{
34db9c00 656 if (theArgNb > 1)
657 {
658 std::cout << "Error: wrong syntax!\n";
659 return 1;
660 }
661
662 Handle(AIS_InteractiveContext) aCtx;
663 Handle(V3d_View) aView;
664 if (!getCtxAndView (aCtx, aView))
665 {
666 return 1;
667 }
668
669 aCtx->ClearActiveAreas (aView);
7fd59977 670 return 0;
671
672}
34db9c00 673static Standard_Integer VDispSensi (Draw_Interpretor& ,
674 Standard_Integer theArgNb,
675 Standard_CString* )
7fd59977 676{
34db9c00 677 if (theArgNb > 1)
678 {
679 std::cout << "Error: wrong syntax!\n";
680 return 1;
681 }
682
683 Handle(AIS_InteractiveContext) aCtx;
684 Handle(V3d_View) aView;
685 if (!getCtxAndView (aCtx, aView))
686 {
687 return 1;
688 }
689
690 aCtx->DisplayActiveSensitive (aView);
7fd59977 691 return 0;
692
693}
34db9c00 694
695static Standard_Integer VClearSensi (Draw_Interpretor& ,
696 Standard_Integer theArgNb,
697 Standard_CString* )
7fd59977 698{
34db9c00 699 if (theArgNb > 1)
700 {
701 std::cout << "Error: wrong syntax!\n";
702 return 1;
703 }
704
705 Handle(AIS_InteractiveContext) aCtx;
706 Handle(V3d_View) aView;
707 if (!getCtxAndView (aCtx, aView))
708 {
709 return 1;
710 }
711 aCtx->ClearActiveSensitive (aView);
7fd59977 712 return 0;
713}
714
715//==============================================================================
519d35d8 716//function : VDir
7fd59977 717//purpose : To list the displayed object with their attributes
7fd59977 718//==============================================================================
519d35d8 719static int VDir (Draw_Interpretor& theDI,
720 Standard_Integer ,
721 const char** )
722{
723 if (!a3DView().IsNull())
724 {
725 return 0;
7fd59977 726 }
727
519d35d8 728 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
729 anIter.More(); anIter.Next())
730 {
731 theDI << "\t" << anIter.Key2().ToCString() << "\n";
732 }
7fd59977 733 return 0;
734}
735
736//==============================================================================
3c982548 737//function : VSelPrecision
738//purpose : To set the selection precision mode and tolerance value
739//Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
740// value (integer number of pixel for window mode, double value of
741// sensitivity for view mode). Without arguments the function just
742// prints the current precision mode and the corresponding tolerance.
743//==============================================================================
744static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
745{
746 if( argc > 3 )
747 {
748 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
749 return 1;
750 }
751
752 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
753 if( aContext.IsNull() )
754 return 1;
755
756 if( argc == 1 )
757 {
758 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
759 if( aMode == StdSelect_SM_WINDOW )
760 {
761 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
762 di << "Precision mode : 0 (window)\n";
763 di << "Pixel tolerance : " << aPixelTolerance << "\n";
764 }
765 else if( aMode == StdSelect_SM_VIEW )
766 {
767 Standard_Real aSensitivity = aContext->Sensitivity();
768 di << "Precision mode : 1 (view)\n";
769 di << "Sensitivity : " << aSensitivity << "\n";
770 }
771 }
772 else if( argc > 1 )
773 {
91322f44 774 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
3c982548 775 aContext->SetSensitivityMode( aMode );
776 if( argc > 2 )
777 {
778 if( aMode == StdSelect_SM_WINDOW )
779 {
91322f44 780 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
3c982548 781 aContext->SetPixelTolerance( aPixelTolerance );
782 }
783 else if( aMode == StdSelect_SM_VIEW )
784 {
91322f44 785 Standard_Real aSensitivity = Draw::Atof( argv[2] );
3c982548 786 aContext->SetSensitivity( aSensitivity );
787 }
788 }
789 }
790 return 0;
791}
792
793//==============================================================================
7fd59977 794//function : VDump
795//purpose : To dump the active view snapshot to image file
7fd59977 796//==============================================================================
34db9c00 797static Standard_Integer VDump (Draw_Interpretor& theDI,
798 Standard_Integer theArgNb,
799 Standard_CString* theArgVec)
7fd59977 800{
34db9c00 801 if (theArgNb < 2)
7fd59977 802 {
34db9c00 803 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 804 return 1;
805 }
806
34db9c00 807 Standard_Integer anArgIter = 1;
808 Standard_CString aFilePath = theArgVec[anArgIter++];
809 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
810 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
811 Standard_Integer aWidth = 0;
812 Standard_Integer aHeight = 0;
813 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 814 {
34db9c00 815 TCollection_AsciiString anArg (theArgVec[anArgIter]);
816 anArg.LowerCase();
817 if (anArg == "rgba")
7fd59977 818 {
34db9c00 819 aBufferType = Graphic3d_BT_RGBA;
7fd59977 820 }
34db9c00 821 else if (anArg == "rgb")
7fd59977 822 {
34db9c00 823 aBufferType = Graphic3d_BT_RGB;
7fd59977 824 }
34db9c00 825 else if (anArg == "depth")
7fd59977 826 {
692613e5 827 aBufferType = Graphic3d_BT_Depth;
7fd59977 828 }
34db9c00 829 else if (anArg == "l"
830 || anArg == "left")
831 {
832 aStereoOpts = V3d_SDO_LEFT_EYE;
833 }
834 else if (anArg == "r"
835 || anArg == "right")
836 {
837 aStereoOpts = V3d_SDO_RIGHT_EYE;
838 }
839 else if (anArg == "mono")
840 {
841 aStereoOpts = V3d_SDO_MONO;
842 }
843 else if (anArg == "w"
844 || anArg == "width")
845 {
846 if (aWidth != 0)
847 {
848 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
849 return 1;
850 }
851 else if (++anArgIter >= theArgNb)
852 {
853 std::cout << "Error: integer value is expected right after 'width'\n";
854 return 1;
855 }
856 aWidth = Draw::Atoi (theArgVec[anArgIter]);
857 }
858 else if (anArg == "h"
859 || anArg == "height")
860 {
861 if (aHeight != 0)
862 {
863 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
864 return 1;
865 }
866 if (++anArgIter >= theArgNb)
867 {
868 std::cout << "Error: integer value is expected right after 'height'\n";
869 return 1;
870 }
871 aHeight = Draw::Atoi (theArgVec[anArgIter]);
872 }
873 else if (anArg.IsIntegerValue())
874 {
875 // compatibility with old syntax
876 if (aWidth != 0
877 || aHeight != 0)
878 {
879 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
880 return 1;
881 }
882 else if (++anArgIter >= theArgNb)
883 {
884 std::cout << "Error: height value is expected right after width\n";
885 return 1;
886 }
887 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
888 aHeight = Draw::Atoi (theArgVec[anArgIter]);
889 }
890 else
891 {
892 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
893 return 1;
894 }
7fd59977 895 }
34db9c00 896 if ((aWidth <= 0 && aHeight > 0)
897 || (aWidth > 0 && aHeight <= 0))
7fd59977 898 {
34db9c00 899 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 900 return 1;
901 }
902
34db9c00 903 Handle(V3d_View) aView = ViewerTest::CurrentView();
904 if (aView.IsNull())
85e096c3 905 {
34db9c00 906 std::cout << "Error: cannot find an active view!\n";
907 return 1;
7fd59977 908 }
85e096c3 909
34db9c00 910 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 911 {
34db9c00 912 if (aStereoOpts != V3d_SDO_MONO)
b5ac8292 913 {
34db9c00 914 aView->Window()->Size (aWidth, aHeight);
b5ac8292 915 }
34db9c00 916 else
b5ac8292 917 {
34db9c00 918 if (!aView->Dump (aFilePath, aBufferType))
919 {
920 theDI << "Fail: view dump failed!\n";
921 }
922 return 0;
b5ac8292 923 }
924 }
925
692613e5 926 Image_AlienPixMap aPixMap;
34db9c00 927 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
7fd59977 928 {
34db9c00 929 theDI << "Fail: view dump failed!\n";
930 return 0;
7fd59977 931 }
85e096c3 932
692613e5 933 if (aPixMap.SizeX() != Standard_Size(aWidth)
934 || aPixMap.SizeY() != Standard_Size(aHeight))
85e096c3 935 {
34db9c00 936 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
937 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
85e096c3 938 }
34db9c00 939 if (!aPixMap.Save (aFilePath))
85e096c3 940 {
34db9c00 941 theDI << "Fail: image can not be saved!\n";
85e096c3 942 }
943 return 0;
7fd59977 944}
945
946
947//==============================================================================
948//function : Displays,Erase...
949//purpose :
950//Draw arg :
951//==============================================================================
952static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
953 const Standard_Integer Mode,
954 const Standard_Integer TypeOfOperation,
955 const Standard_Boolean Upd)
956{
957 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
958
959 switch(TypeOfOperation){
960 case 1:
961 Ctx->Display(IO,Mode,Upd);
962 break;
963 case 2:{
eb4320f2 964 Ctx->Erase(IO,Upd);
7fd59977 965 break;
966 }
967 case 3:{
968 if(IO.IsNull())
969 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
970 else
971 Ctx->SetDisplayMode(IO,Mode,Upd);
972 break;
973 }
974 case 4:{
975 if(IO.IsNull())
976 Ctx->SetDisplayMode(0,Upd);
977 else
978 Ctx->UnsetDisplayMode(IO,Upd);
979 break;
980 }
981 }
982 return 0;
983}
984
985//=======================================================================
986//function :
987//purpose :
988//=======================================================================
989static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
990{
991
992 TCollection_AsciiString name;
993 if(argc>3)
994 return 1;
995 // display others presentations
996 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
997 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
998 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
999 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1000
1001 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1002
1003 //unset displaymode.. comportement particulier...
1004 if(TypeOfOperation==4){
1005 if(argc==1){
1006 if(Ctx->NbCurrents()==0 ||
1007 Ctx->NbSelected()==0){
1008 Handle(AIS_InteractiveObject) IO;
1009 VwrTst_DispErase(IO,-1,4,Standard_False);
1010 }
1011 else if(!Ctx->HasOpenedContext()){
1012 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1013 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1014 }
1015 else{
1016 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1017 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1018 Ctx->UpdateCurrentViewer();
1019 }
1020 else{
1021 Handle(AIS_InteractiveObject) IO;
1022 name = argv[1];
1023 if(GetMapOfAIS().IsBound2(name)){
1024 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1025 if (!IO.IsNull())
1026 VwrTst_DispErase(IO,-1,4,Standard_True);
1027 }
1028 }
1029 }
1030 else if(argc==2){
91322f44 1031 Standard_Integer Dmode = Draw::Atoi(argv[1]);
7fd59977 1032 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1033 Handle(AIS_InteractiveObject) IO;
1034 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1035 }
1036 if(!Ctx->HasOpenedContext()){
1037 // set/unset display mode sur le Contexte...
1038 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1039 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1040 }
1041 Ctx->UpdateCurrentViewer();
1042 }
1043 else{
1044 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1045 Ctx->Display(Ctx->Interactive(),Dmode);
1046 }
1047 }
1048 else{
1049 Handle(AIS_InteractiveObject) IO;
1050 name = argv[1];
1051 if(GetMapOfAIS().IsBound2(name))
1052 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1053 if (!IO.IsNull())
91322f44 1054 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1055 }
1056 return 0;
1057}
1058
1059
1060//=======================================================================
1061//function :
1062//purpose :
1063//=======================================================================
1064static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1065{
1066 if(argc==1) return 1;
91322f44 1067 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1068 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1069
1070 if(argc==2){
1071
1072 if(!Ctx->HasOpenedContext()){
1073 di<<"sub intensite ";
1074 if(On==1) di<<"On";
1075 else di<<"Off";
1076 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1077 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1078 if(On==1){
1079 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1080 else{
1081 di <<"passage dans off"<<"\n";
1082 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1083 }
1084 }
1085 }
1086 else{
1087 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1088 if(On==1){
1089 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1090 else{
1091 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1092 }
1093 }
1094 Ctx->UpdateCurrentViewer();
1095 }
1096 else {
1097 Handle(AIS_InteractiveObject) IO;
1098 TCollection_AsciiString name = argv[2];
1099 if(GetMapOfAIS().IsBound2(name)){
1100 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1101 if (!IO.IsNull()) {
7fd59977 1102 if(On==1)
1103 Ctx->SubIntensityOn(IO);
1104 else
1105 Ctx->SubIntensityOff(IO);
eafb234b 1106 }
7fd59977 1107 }
1108 else return 1;
1109 }
1110 return 0;
7fd59977 1111}
7fd59977 1112
ad3217cd 1113//! Auxiliary class to iterate presentations from different collections.
1114class ViewTest_PrsIter
1115{
1116public:
7fd59977 1117
ad3217cd 1118 //! Create and initialize iterator object.
1119 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1120 : mySource (IterSource_All)
1121 {
1122 NCollection_Sequence<TCollection_AsciiString> aNames;
1123 if (!theName.IsEmpty())
1124 aNames.Append (theName);
1125 Init (aNames);
7fd59977 1126 }
ad3217cd 1127
1128 //! Create and initialize iterator object.
1129 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1130 : mySource (IterSource_All)
1131 {
1132 Init (theNames);
7fd59977 1133 }
1134
ad3217cd 1135 //! Initialize the iterator.
1136 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1137 {
1138 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1139 mySeq = theNames;
1140 mySelIter.Nullify();
1141 myCurrent.Nullify();
1142 myCurrentTrs.Nullify();
1143 if (!mySeq.IsEmpty())
1144 {
1145 mySource = IterSource_List;
1146 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1147 }
ad3217cd 1148 else if (aCtx->NbCurrents() > 0)
1149 {
1150 mySource = IterSource_Selected;
1151 mySelIter = aCtx;
1152 mySelIter->InitCurrent();
1153 }
1154 else
1155 {
1156 mySource = IterSource_All;
1157 myMapIter.Initialize (GetMapOfAIS());
1158 }
1159 initCurrent();
1160 }
7fd59977 1161
ad3217cd 1162 const TCollection_AsciiString& CurrentName() const
1163 {
1164 return myCurrentName;
1165 }
7fd59977 1166
ad3217cd 1167 const Handle(AIS_InteractiveObject)& Current() const
1168 {
1169 return myCurrent;
1170 }
7fd59977 1171
ad3217cd 1172 const Handle(Standard_Transient)& CurrentTrs() const
1173 {
1174 return myCurrentTrs;
1175 }
1176
1177 //! @return true if iterator points to valid object within collection
1178 Standard_Boolean More() const
1179 {
1180 switch (mySource)
1181 {
1182 case IterSource_All: return myMapIter.More();
1183 case IterSource_List: return mySeqIter.More();
1184 case IterSource_Selected: return mySelIter->MoreCurrent();
1185 }
1186 return Standard_False;
1187 }
1188
1189 //! Go to the next item.
1190 void Next()
1191 {
1192 myCurrentName.Clear();
1193 myCurrentTrs.Nullify();
1194 myCurrent.Nullify();
1195 switch (mySource)
1196 {
1197 case IterSource_All:
1198 {
1199 myMapIter.Next();
1200 break;
1201 }
1202 case IterSource_List:
1203 {
1204 mySeqIter.Next();
1205 break;
1206 }
1207 case IterSource_Selected:
1208 {
1209 mySelIter->NextCurrent();
1210 break;
7fd59977 1211 }
1212 }
ad3217cd 1213 initCurrent();
1214 }
7fd59977 1215
ad3217cd 1216private:
7fd59977 1217
ad3217cd 1218 void initCurrent()
1219 {
1220 switch (mySource)
1221 {
1222 case IterSource_All:
7fd59977 1223 {
ad3217cd 1224 if (myMapIter.More())
1225 {
1226 myCurrentName = myMapIter.Key2();
1227 myCurrentTrs = myMapIter.Key1();
1228 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1229 }
ad3217cd 1230 break;
1231 }
1232 case IterSource_List:
1233 {
1234 if (mySeqIter.More())
1235 {
1236 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1237 {
1238 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1239 return;
1240 }
1241 myCurrentName = mySeqIter.Value();
1242 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1243 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1244 }
1245 break;
1246 }
1247 case IterSource_Selected:
1248 {
1249 if (mySelIter->MoreCurrent())
1250 {
1251 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1252 myCurrent = mySelIter->Current();
1253 }
1254 break;
7fd59977 1255 }
7fd59977 1256 }
1257 }
ad3217cd 1258
1259private:
1260
1261 enum IterSource
1262 {
1263 IterSource_All,
1264 IterSource_List,
1265 IterSource_Selected
1266 };
1267
1268private:
1269
1270 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1271 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1272 NCollection_Sequence<TCollection_AsciiString> mySeq;
1273 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1274
1275 TCollection_AsciiString myCurrentName;//!< current item name
1276 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1277 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1278
1279 IterSource mySource; //!< iterated collection
1280
1281};
7fd59977 1282
1283//==============================================================================
ad3217cd 1284//function : VInteriorStyle
1285//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1286//==============================================================================
ad3217cd 1287static int VSetInteriorStyle (Draw_Interpretor& theDI,
1288 Standard_Integer theArgNb,
1289 const char** theArgVec)
7fd59977 1290{
ad3217cd 1291 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1292 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1293 if (aCtx.IsNull())
1294 {
1295 std::cerr << "Error: no active view!\n";
1296 return 1;
1297 }
7fd59977 1298
4e18052b 1299 Standard_Integer anArgIter = 1;
ad3217cd 1300 for (; anArgIter < theArgNb; ++anArgIter)
1301 {
4e18052b 1302 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1303 {
1304 break;
1305 }
7fd59977 1306 }
ad3217cd 1307 TCollection_AsciiString aName;
1308 if (theArgNb - anArgIter == 2)
1309 {
1310 aName = theArgVec[anArgIter++];
1311 }
1312 else if (theArgNb - anArgIter != 1)
1313 {
1314 std::cout << "Error: wrong number of arguments! See usage:\n";
1315 theDI.PrintHelp (theArgVec[0]);
1316 return 1;
1317 }
1318 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1319 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1320 aStyleArg.LowerCase();
1321 if (aStyleArg == "empty")
1322 {
1323 anInterStyle = 0;
1324 }
1325 else if (aStyleArg == "hollow")
1326 {
1327 anInterStyle = 1;
1328 }
1329 else if (aStyleArg == "hatch")
1330 {
1331 anInterStyle = 2;
1332 }
1333 else if (aStyleArg == "solid")
1334 {
1335 anInterStyle = 3;
1336 }
1337 else if (aStyleArg == "hiddenline")
1338 {
1339 anInterStyle = 4;
1340 }
1341 else
1342 {
1343 anInterStyle = aStyleArg.IntegerValue();
1344 }
1345 if (anInterStyle < Aspect_IS_EMPTY
1346 || anInterStyle > Aspect_IS_HIDDENLINE)
1347 {
1348 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1349 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1350 return 1;
7fd59977 1351 }
1352
ad3217cd 1353 if (!aName.IsEmpty()
1354 && !GetMapOfAIS().IsBound2 (aName))
1355 {
1356 std::cout << "Error: object " << aName << " is not displayed!\n";
1357 return 1;
1358 }
1359
1360 if (aCtx->HasOpenedContext())
1361 {
1362 aCtx->CloseLocalContext();
1363 }
1364 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1365 {
1366 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1367 if (!anIO.IsNull())
1368 {
1369 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1370 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1371 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1372 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1373 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1374 }
ad3217cd 1375 }
ad3217cd 1376 return 0;
1377}
7fd59977 1378
ad3217cd 1379//! Auxiliary structure for VAspects
1380struct ViewerTest_AspectsChangeSet
1381{
5bffb882 1382 Standard_Integer ToSetVisibility;
1383 Standard_Integer Visibility;
1384
ad3217cd 1385 Standard_Integer ToSetColor;
1386 Quantity_Color Color;
1387
1388 Standard_Integer ToSetLineWidth;
1389 Standard_Real LineWidth;
1390
1391 Standard_Integer ToSetTransparency;
1392 Standard_Real Transparency;
1393
1394 Standard_Integer ToSetMaterial;
1395 Graphic3d_NameOfMaterial Material;
1396 TCollection_AsciiString MatName;
1397
1398 NCollection_Sequence<TopoDS_Shape> SubShapes;
1399
6262338c 1400 Standard_Integer ToSetShowFreeBoundary;
1401 Standard_Integer ToSetFreeBoundaryWidth;
1402 Standard_Real FreeBoundaryWidth;
1403 Standard_Integer ToSetFreeBoundaryColor;
1404 Quantity_Color FreeBoundaryColor;
1405
ad3217cd 1406 //! Empty constructor
1407 ViewerTest_AspectsChangeSet()
5bffb882 1408 : ToSetVisibility (0),
1409 Visibility (1),
1410 ToSetColor (0),
ad3217cd 1411 Color (DEFAULT_COLOR),
1412 ToSetLineWidth (0),
1413 LineWidth (1.0),
1414 ToSetTransparency (0),
1415 Transparency (0.0),
1416 ToSetMaterial (0),
6262338c 1417 Material (Graphic3d_NOM_DEFAULT),
1418 ToSetShowFreeBoundary (0),
1419 ToSetFreeBoundaryWidth (0),
1420 FreeBoundaryWidth (1.0),
1421 ToSetFreeBoundaryColor (0),
1422 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
ad3217cd 1423
1424 //! @return true if no changes have been requested
1425 Standard_Boolean IsEmpty() const
1426 {
6262338c 1427 return ToSetVisibility == 0
1428 && ToSetLineWidth == 0
1429 && ToSetTransparency == 0
1430 && ToSetColor == 0
1431 && ToSetMaterial == 0
1432 && ToSetShowFreeBoundary == 0
1433 && ToSetFreeBoundaryColor == 0
1434 && ToSetFreeBoundaryWidth == 0;
ad3217cd 1435 }
1436
1437 //! @return true if properties are valid
1438 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1439 {
1440 Standard_Boolean isOk = Standard_True;
5bffb882 1441 if (Visibility != 0 && Visibility != 1)
1442 {
1443 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1444 isOk = Standard_False;
1445 }
ad3217cd 1446 if (LineWidth <= 0.0
1447 || LineWidth > 10.0)
1448 {
1449 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1450 isOk = Standard_False;
7fd59977 1451 }
ad3217cd 1452 if (Transparency < 0.0
1453 || Transparency > 1.0)
1454 {
1455 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1456 isOk = Standard_False;
1457 }
1458 if (theIsSubPart
1459 && ToSetTransparency)
1460 {
1461 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1462 isOk = Standard_False;
7fd59977 1463 }
ad3217cd 1464 if (ToSetMaterial == 1
1465 && Material == Graphic3d_NOM_DEFAULT)
1466 {
1467 std::cout << "Error: unknown material " << MatName << ".\n";
1468 isOk = Standard_False;
1469 }
6262338c 1470 if (FreeBoundaryWidth <= 0.0
1471 || FreeBoundaryWidth > 10.0)
1472 {
1473 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1474 isOk = Standard_False;
1475 }
ad3217cd 1476 return isOk;
7fd59977 1477 }
7fd59977 1478
ad3217cd 1479};
7fd59977 1480
1481//==============================================================================
ad3217cd 1482//function : VAspects
1483//purpose :
7fd59977 1484//==============================================================================
ad3217cd 1485static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1486 Standard_Integer theArgNb,
1487 const char** theArgVec)
7fd59977 1488{
ad3217cd 1489 TCollection_AsciiString aCmdName (theArgVec[0]);
1490 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1491 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1492 if (aCtx.IsNull())
1493 {
1494 std::cerr << "Error: no active view!\n";
1495 return 1;
1496 }
7fd59977 1497
4e18052b 1498 Standard_Integer anArgIter = 1;
6262338c 1499 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1500 NCollection_Sequence<TCollection_AsciiString> aNames;
1501 for (; anArgIter < theArgNb; ++anArgIter)
1502 {
1503 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1504 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1505 {
1506 continue;
1507 }
1508 else if (!anArg.IsEmpty()
1509 && anArg.Value (1) != '-')
1510 {
1511 aNames.Append (anArg);
1512 }
1513 else
1514 {
6262338c 1515 if (anArg == "-defaults")
1516 {
1517 isDefaults = Standard_True;
1518 ++anArgIter;
1519 }
ad3217cd 1520 break;
1521 }
1522 }
1523
6262338c 1524 if (!aNames.IsEmpty() && isDefaults)
1525 {
1526 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1527 return 1;
1528 }
1529
ad3217cd 1530 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1531 aChanges.Append (ViewerTest_AspectsChangeSet());
1532 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1533
ad3217cd 1534 // parse syntax of legacy commands
1535 if (aCmdName == "vsetwidth")
1536 {
1537 if (aNames.IsEmpty()
1538 || !aNames.Last().IsRealValue())
1539 {
1540 std::cout << "Error: not enough arguments!\n";
1541 return 1;
1542 }
1543 aChangeSet->ToSetLineWidth = 1;
1544 aChangeSet->LineWidth = aNames.Last().RealValue();
1545 aNames.Remove (aNames.Length());
7fd59977 1546 }
ad3217cd 1547 else if (aCmdName == "vunsetwidth")
1548 {
1549 aChangeSet->ToSetLineWidth = -1;
1550 }
1551 else if (aCmdName == "vsetcolor")
1552 {
1553 if (aNames.IsEmpty())
1554 {
1555 std::cout << "Error: not enough arguments!\n";
1556 return 1;
1557 }
1558 aChangeSet->ToSetColor = 1;
8316c618 1559
1560 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1561 Standard_Boolean isOk = Standard_False;
1562 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1563 {
1564 aChangeSet->Color = aColor;
1565 aNames.Remove (aNames.Length());
1566 isOk = Standard_True;
1567 }
1568 else if (aNames.Length() >= 3)
1569 {
1570 const TCollection_AsciiString anRgbStr[3] =
1571 {
1572 aNames.Value (aNames.Upper() - 2),
1573 aNames.Value (aNames.Upper() - 1),
1574 aNames.Value (aNames.Upper() - 0)
1575 };
1576 isOk = anRgbStr[0].IsRealValue()
1577 && anRgbStr[1].IsRealValue()
1578 && anRgbStr[2].IsRealValue();
1579 if (isOk)
1580 {
1581 Graphic3d_Vec4d anRgb;
1582 anRgb.x() = anRgbStr[0].RealValue();
1583 anRgb.y() = anRgbStr[1].RealValue();
1584 anRgb.z() = anRgbStr[2].RealValue();
1585 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1586 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1587 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1588 {
1589 std::cout << "Error: RGB color values should be within range 0..1!\n";
1590 return 1;
1591 }
1592 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1593 aNames.Remove (aNames.Length());
1594 aNames.Remove (aNames.Length());
1595 aNames.Remove (aNames.Length());
1596 }
1597 }
1598 if (!isOk)
1599 {
1600 std::cout << "Error: not enough arguments!\n";
1601 return 1;
1602 }
ad3217cd 1603 }
1604 else if (aCmdName == "vunsetcolor")
1605 {
1606 aChangeSet->ToSetColor = -1;
1607 }
1608 else if (aCmdName == "vsettransparency")
1609 {
1610 if (aNames.IsEmpty()
1611 || !aNames.Last().IsRealValue())
1612 {
1613 std::cout << "Error: not enough arguments!\n";
1614 return 1;
1615 }
1616 aChangeSet->ToSetTransparency = 1;
1617 aChangeSet->Transparency = aNames.Last().RealValue();
1618 aNames.Remove (aNames.Length());
1619 }
1620 else if (aCmdName == "vunsettransparency")
1621 {
1622 aChangeSet->ToSetTransparency = -1;
1623 }
1624 else if (aCmdName == "vsetmaterial")
1625 {
1626 if (aNames.IsEmpty())
1627 {
1628 std::cout << "Error: not enough arguments!\n";
1629 return 1;
1630 }
1631 aChangeSet->ToSetMaterial = 1;
1632 aChangeSet->MatName = aNames.Last();
1633 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1634 aNames.Remove (aNames.Length());
1635 }
1636 else if (aCmdName == "vunsetmaterial")
1637 {
1638 aChangeSet->ToSetMaterial = -1;
1639 }
1640 else if (anArgIter >= theArgNb)
1641 {
1642 std::cout << "Error: not enough arguments!\n";
1643 return 1;
7fd59977 1644 }
1645
ad3217cd 1646 if (!aChangeSet->IsEmpty())
1647 {
1648 anArgIter = theArgNb;
1649 }
1650 for (; anArgIter < theArgNb; ++anArgIter)
1651 {
1652 TCollection_AsciiString anArg = theArgVec[anArgIter];
1653 anArg.LowerCase();
1654 if (anArg == "-setwidth"
1655 || anArg == "-setlinewidth")
1656 {
1657 if (++anArgIter >= theArgNb)
1658 {
1659 std::cout << "Error: wrong syntax at " << anArg << "\n";
1660 return 1;
1661 }
1662 aChangeSet->ToSetLineWidth = 1;
1663 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1664 }
ad3217cd 1665 else if (anArg == "-unsetwidth"
1666 || anArg == "-unsetlinewidth")
1667 {
1668 aChangeSet->ToSetLineWidth = -1;
1669 aChangeSet->LineWidth = 1.0;
1670 }
1671 else if (anArg == "-settransp"
0ae61cf3 1672 || anArg == "-settransparency")
ad3217cd 1673 {
1674 if (++anArgIter >= theArgNb)
1675 {
1676 std::cout << "Error: wrong syntax at " << anArg << "\n";
1677 return 1;
1678 }
1679 aChangeSet->ToSetTransparency = 1;
1680 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1681 if (aChangeSet->Transparency >= 0.0
1682 && aChangeSet->Transparency <= Precision::Confusion())
1683 {
1684 aChangeSet->ToSetTransparency = -1;
1685 aChangeSet->Transparency = 0.0;
eafb234b 1686 }
7fd59977 1687 }
5bffb882 1688 else if (anArg == "-setvis"
1689 || anArg == "-setvisibility")
1690 {
1691 if (++anArgIter >= theArgNb)
1692 {
1693 std::cout << "Error: wrong syntax at " << anArg << "\n";
1694 return 1;
1695 }
1696
1697 aChangeSet->ToSetVisibility = 1;
1698 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1699 }
ad3217cd 1700 else if (anArg == "-setalpha")
1701 {
1702 if (++anArgIter >= theArgNb)
7fd59977 1703 {
ad3217cd 1704 std::cout << "Error: wrong syntax at " << anArg << "\n";
1705 return 1;
1706 }
1707 aChangeSet->ToSetTransparency = 1;
1708 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1709 if (aChangeSet->Transparency < 0.0
1710 || aChangeSet->Transparency > 1.0)
1711 {
1712 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1713 return 1;
1714 }
1715 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1716 if (aChangeSet->Transparency >= 0.0
1717 && aChangeSet->Transparency <= Precision::Confusion())
1718 {
1719 aChangeSet->ToSetTransparency = -1;
1720 aChangeSet->Transparency = 0.0;
7fd59977 1721 }
7fd59977 1722 }
ad3217cd 1723 else if (anArg == "-unsettransp"
0ae61cf3 1724 || anArg == "-unsettransparency"
ad3217cd 1725 || anArg == "-unsetalpha"
1726 || anArg == "-opaque")
1727 {
1728 aChangeSet->ToSetTransparency = -1;
1729 aChangeSet->Transparency = 0.0;
1730 }
1731 else if (anArg == "-setcolor")
1732 {
8316c618 1733 Standard_Integer aNbComps = 0;
1734 Standard_Integer aCompIter = anArgIter + 1;
1735 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1736 {
8316c618 1737 if (theArgVec[aCompIter][0] == '-')
1738 {
1739 break;
1740 }
1741 }
1742 switch (aNbComps)
1743 {
1744 case 1:
1745 {
1746 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1747 Standard_CString aName = theArgVec[anArgIter + 1];
1748 if (!Quantity_Color::ColorFromName (aName, aColor))
1749 {
1750 std::cout << "Error: unknown color name '" << aName << "'\n";
1751 return 1;
1752 }
1753 aChangeSet->Color = aColor;
1754 break;
1755 }
1756 case 3:
1757 {
1758 Graphic3d_Vec3d anRgb;
1759 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1760 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1761 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1762 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1763 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1764 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1765 {
1766 std::cout << "Error: RGB color values should be within range 0..1!\n";
1767 return 1;
1768 }
1769 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1770 break;
1771 }
1772 default:
1773 {
1774 std::cout << "Error: wrong syntax at " << anArg << "\n";
1775 return 1;
1776 }
7fd59977 1777 }
ad3217cd 1778 aChangeSet->ToSetColor = 1;
8316c618 1779 anArgIter += aNbComps;
7fd59977 1780 }
ad3217cd 1781 else if (anArg == "-unsetcolor")
1782 {
1783 aChangeSet->ToSetColor = -1;
1784 aChangeSet->Color = DEFAULT_COLOR;
1785 }
1786 else if (anArg == "-setmat"
1787 || anArg == "-setmaterial")
1788 {
1789 if (++anArgIter >= theArgNb)
1790 {
1791 std::cout << "Error: wrong syntax at " << anArg << "\n";
1792 return 1;
1793 }
1794 aChangeSet->ToSetMaterial = 1;
1795 aChangeSet->MatName = theArgVec[anArgIter];
1796 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1797 }
1798 else if (anArg == "-unsetmat"
1799 || anArg == "-unsetmaterial")
1800 {
1801 aChangeSet->ToSetMaterial = -1;
1802 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1803 }
1804 else if (anArg == "-subshape"
1805 || anArg == "-subshapes")
1806 {
6262338c 1807 if (isDefaults)
1808 {
1809 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1810 return 1;
1811 }
1812
ad3217cd 1813 if (aNames.IsEmpty())
1814 {
1815 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1816 return 1;
1817 }
7fd59977 1818
ad3217cd 1819 aChanges.Append (ViewerTest_AspectsChangeSet());
1820 aChangeSet = &aChanges.ChangeLast();
7fd59977 1821
ad3217cd 1822 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1823 {
1824 Standard_CString aSubShapeName = theArgVec[anArgIter];
1825 if (*aSubShapeName == '-')
1826 {
1827 --anArgIter;
1828 break;
1829 }
7fd59977 1830
ad3217cd 1831 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1832 if (aSubShape.IsNull())
1833 {
1834 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1835 return 1;
1836 }
1837 aChangeSet->SubShapes.Append (aSubShape);
1838 }
7fd59977 1839
ad3217cd 1840 if (aChangeSet->SubShapes.IsEmpty())
1841 {
1842 std::cerr << "Error: empty list is specified after -subshapes!\n";
1843 return 1;
1844 }
1845 }
6262338c 1846 else if (anArg == "-freeboundary"
1847 || anArg == "-fb")
1848 {
1849 if (++anArgIter >= theArgNb)
1850 {
1851 std::cout << "Error: wrong syntax at " << anArg << "\n";
1852 return 1;
1853 }
1854 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1855 aValue.LowerCase();
1856 if (aValue == "on"
1857 || aValue == "1")
1858 {
1859 aChangeSet->ToSetShowFreeBoundary = 1;
1860 }
1861 else if (aValue == "off"
1862 || aValue == "0")
1863 {
1864 aChangeSet->ToSetShowFreeBoundary = -1;
1865 }
1866 else
1867 {
1868 std::cout << "Error: wrong syntax at " << anArg << "\n";
1869 return 1;
1870 }
1871 }
1872 else if (anArg == "-setfreeboundarywidth"
1873 || anArg == "-setfbwidth")
1874 {
1875 if (++anArgIter >= theArgNb)
1876 {
1877 std::cout << "Error: wrong syntax at " << anArg << "\n";
1878 return 1;
1879 }
1880 aChangeSet->ToSetFreeBoundaryWidth = 1;
1881 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1882 }
1883 else if (anArg == "-unsetfreeboundarywidth"
1884 || anArg == "-unsetfbwidth")
1885 {
1886 aChangeSet->ToSetFreeBoundaryWidth = -1;
1887 aChangeSet->FreeBoundaryWidth = 1.0;
1888 }
1889 else if (anArg == "-setfreeboundarycolor"
1890 || anArg == "-setfbcolor")
1891 {
1892 Standard_Integer aNbComps = 0;
1893 Standard_Integer aCompIter = anArgIter + 1;
1894 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1895 {
1896 if (theArgVec[aCompIter][0] == '-')
1897 {
1898 break;
1899 }
1900 }
1901 switch (aNbComps)
1902 {
1903 case 1:
1904 {
1905 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1906 Standard_CString aName = theArgVec[anArgIter + 1];
1907 if (!Quantity_Color::ColorFromName (aName, aColor))
1908 {
1909 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1910 return 1;
1911 }
1912 aChangeSet->FreeBoundaryColor = aColor;
1913 break;
1914 }
1915 case 3:
1916 {
1917 Graphic3d_Vec3d anRgb;
1918 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1919 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1920 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1921 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1922 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1923 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1924 {
1925 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1926 return 1;
1927 }
1928 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1929 break;
1930 }
1931 default:
1932 {
1933 std::cout << "Error: wrong syntax at " << anArg << "\n";
1934 return 1;
1935 }
1936 }
1937 aChangeSet->ToSetFreeBoundaryColor = 1;
1938 anArgIter += aNbComps;
1939 }
1940 else if (anArg == "-unsetfreeboundarycolor"
1941 || anArg == "-unsetfbcolor")
1942 {
1943 aChangeSet->ToSetFreeBoundaryColor = -1;
1944 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1945 }
ad3217cd 1946 else if (anArg == "-unset")
1947 {
5bffb882 1948 aChangeSet->ToSetVisibility = 1;
1949 aChangeSet->Visibility = 1;
ad3217cd 1950 aChangeSet->ToSetLineWidth = -1;
1951 aChangeSet->LineWidth = 1.0;
1952 aChangeSet->ToSetTransparency = -1;
1953 aChangeSet->Transparency = 0.0;
1954 aChangeSet->ToSetColor = -1;
1955 aChangeSet->Color = DEFAULT_COLOR;
1956 aChangeSet->ToSetMaterial = -1;
1957 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 1958 aChangeSet->ToSetShowFreeBoundary = -1;
1959 aChangeSet->ToSetFreeBoundaryColor = -1;
1960 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1961 aChangeSet->ToSetFreeBoundaryWidth = -1;
1962 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 1963 }
7fd59977 1964 else
ad3217cd 1965 {
1966 std::cout << "Error: wrong syntax at " << anArg << "\n";
1967 return 1;
1968 }
7fd59977 1969 }
99c56d44 1970
ad3217cd 1971 Standard_Boolean isFirst = Standard_True;
1972 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1973 aChangesIter.More(); aChangesIter.Next())
1974 {
1975 if (!aChangesIter.Value().Validate (!isFirst))
1976 {
1977 return 1;
1978 }
1979 isFirst = Standard_False;
99c56d44 1980 }
99c56d44 1981
ad3217cd 1982 if (aCtx->HasOpenedContext())
1983 {
1984 aCtx->CloseLocalContext();
99c56d44 1985 }
6262338c 1986
1987 // special case for -defaults parameter.
1988 // all changed values will be set to DefaultDrawer.
1989 if (isDefaults)
1990 {
1991 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
1992
1993 if (aChangeSet->ToSetLineWidth != 0)
1994 {
1995 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
1996 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
1997 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
1998 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
1999 }
2000 if (aChangeSet->ToSetColor != 0)
2001 {
2002 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2003 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2004 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2005 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2006 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2007 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2008 }
2009 if (aChangeSet->ToSetTransparency != 0)
2010 {
2011 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2012 }
2013 if (aChangeSet->ToSetMaterial != 0)
2014 {
2015 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2016 }
2017 if (aChangeSet->ToSetShowFreeBoundary == 1)
2018 {
2019 aDrawer->SetFreeBoundaryDraw (Standard_True);
2020 }
2021 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2022 {
2023 aDrawer->SetFreeBoundaryDraw (Standard_False);
2024 }
2025 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2026 {
2027 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2028 }
2029 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2030 {
2031 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2032 }
2033
2034 // redisplay all objects in context
2035 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2036 {
2037 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2038 if (!aPrs.IsNull())
2039 {
2040 aCtx->Redisplay (aPrs, Standard_False);
2041 }
2042 }
2043 return 0;
2044 }
2045
ad3217cd 2046 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2047 {
6262338c 2048 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2049 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2050 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2051 Handle(AIS_ColoredShape) aColoredPrs;
2052 Standard_Boolean toDisplay = Standard_False;
6262338c 2053 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2054 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2055 {
2056 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2057 if (aShapePrs.IsNull())
2058 {
2059 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2060 return 1;
2061 }
2062 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2063 if (aColoredPrs.IsNull())
2064 {
2065 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2066 aCtx->Remove (aShapePrs, Standard_False);
2067 GetMapOfAIS().UnBind2 (aName);
2068 GetMapOfAIS().Bind (aColoredPrs, aName);
2069 toDisplay = Standard_True;
2070 aShapePrs = aColoredPrs;
2071 aPrs = aColoredPrs;
2072 }
2073 }
99c56d44 2074
ad3217cd 2075 if (!aPrs.IsNull())
2076 {
2077 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2078 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2079 if (aChangeSet->ToSetVisibility == 1)
2080 {
2081 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2082 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2083 }
2084 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2085 {
2086 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2087 }
2088 else if (aChangeSet->ToSetMaterial == -1)
2089 {
2090 aCtx->UnsetMaterial (aPrs, Standard_False);
2091 }
2092 if (aChangeSet->ToSetColor == 1)
2093 {
2094 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2095 }
2096 else if (aChangeSet->ToSetColor == -1)
2097 {
2098 aCtx->UnsetColor (aPrs, Standard_False);
2099 }
2100 if (aChangeSet->ToSetTransparency == 1)
2101 {
2102 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2103 }
2104 else if (aChangeSet->ToSetTransparency == -1)
2105 {
2106 aCtx->UnsetTransparency (aPrs, Standard_False);
2107 }
2108 if (aChangeSet->ToSetLineWidth == 1)
2109 {
2110 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2111 }
2112 else if (aChangeSet->ToSetLineWidth == -1)
2113 {
2114 aCtx->UnsetWidth (aPrs, Standard_False);
2115 }
6262338c 2116 if (!aDrawer.IsNull())
2117 {
2118 if (aChangeSet->ToSetShowFreeBoundary == 1)
2119 {
2120 aDrawer->SetFreeBoundaryDraw (Standard_True);
2121 toRedisplay = Standard_True;
2122 }
2123 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2124 {
2125 aDrawer->SetFreeBoundaryDraw (Standard_False);
2126 toRedisplay = Standard_True;
2127 }
2128 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2129 {
2130 Handle(Prs3d_LineAspect) aBoundaryAspect =
2131 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2132 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2133 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2134 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2135 toRedisplay = Standard_True;
2136 }
2137 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2138 {
2139 Handle(Prs3d_LineAspect) aBoundaryAspect =
2140 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2141 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2142 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2143 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2144 toRedisplay = Standard_True;
2145 }
2146 }
99c56d44 2147
ad3217cd 2148 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2149 {
2150 aChangeSet = &aChangesIter.ChangeValue();
2151 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2152 aSubShapeIter.More(); aSubShapeIter.Next())
2153 {
2154 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2155 if (aChangeSet->ToSetVisibility == 1)
2156 {
2157 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2158 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2159 }
ad3217cd 2160 if (aChangeSet->ToSetColor == 1)
2161 {
2162 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2163 }
2164 if (aChangeSet->ToSetLineWidth == 1)
2165 {
2166 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2167 }
2168 if (aChangeSet->ToSetColor == -1
2169 || aChangeSet->ToSetLineWidth == -1)
2170 {
2171 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2172 }
2173 }
2174 }
2175 if (toDisplay)
2176 {
2177 aCtx->Display (aPrs, Standard_False);
2178 }
6262338c 2179 if (toRedisplay)
2180 {
2181 aCtx->Redisplay (aPrs, Standard_False);
2182 }
ad3217cd 2183 else if (!aColoredPrs.IsNull())
2184 {
36132a2e 2185 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2186 }
99c56d44 2187 }
99c56d44 2188 else
ad3217cd 2189 {
2190 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
2191 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
2192 if (!aNisObj.IsNull())
2193 {
2194 if (aChangeSet->ToSetTransparency != 0)
2195 {
2196 aNisObj->SetTransparency (aChangeSet->Transparency);
2197 }
2198 }
2199 if (!aNisTri.IsNull())
2200 {
2201 if (aChangeSet->ToSetColor != 0)
2202 {
2203 aNisTri->SetColor (aChangeSet->Color);
2204 }
2205 if (aChangeSet->ToSetLineWidth != 0)
2206 {
2207 aNisTri->SetLineWidth (aChangeSet->LineWidth);
2208 }
99c56d44 2209 }
2210 }
ad3217cd 2211 }
99c56d44 2212 return 0;
2213}
2214
7fd59977 2215//==============================================================================
2216//function : VDonly2
2217//author : ege
2218//purpose : Display only a selected or named object
519d35d8 2219// if there is no selected or named object s, nothing is done
7fd59977 2220//==============================================================================
519d35d8 2221static int VDonly2 (Draw_Interpretor& ,
2222 Standard_Integer theArgNb,
2223 const char** theArgVec)
7fd59977 2224{
519d35d8 2225 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2226 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2227 if (aCtx.IsNull())
2228 {
2229 std::cerr << "Error: no active view!\n";
7fd59977 2230 return 1;
519d35d8 2231 }
7fd59977 2232
519d35d8 2233 if (aCtx->HasOpenedContext())
2234 {
2235 aCtx->CloseLocalContext();
2236 }
7fd59977 2237
519d35d8 2238 Standard_Integer anArgIter = 1;
2239 for (; anArgIter < theArgNb; ++anArgIter)
2240 {
4e18052b 2241 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2242 {
2243 break;
2244 }
2245 }
7fd59977 2246
519d35d8 2247 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2248 if (anArgIter >= theArgNb)
2249 {
2250 // display only selected objects
2251 if (aCtx->NbCurrents() < 1)
2252 {
2253 return 0;
7fd59977 2254 }
2255
519d35d8 2256 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2257 {
2258 aDispSet.Add (aCtx->Current());
2259 }
2260 }
2261 else
2262 {
2263 // display only specified objects
2264 for (; anArgIter < theArgNb; ++anArgIter)
2265 {
2266 TCollection_AsciiString aName = theArgVec[anArgIter];
2267 if (GetMapOfAIS().IsBound2 (aName))
2268 {
2269 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2270 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2271 {
2272 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2273 aCtx->Display (aShape, Standard_False);
2274 }
2275 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2276 {
2277 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2278 TheNISContext()->Display (aShape);
7fd59977 2279 }
519d35d8 2280 aDispSet.Add (anObj);
7fd59977 2281 }
2282 }
7fd59977 2283 }
519d35d8 2284
2285 // weed out other objects
2286 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2287 {
2288 if (aDispSet.Contains (anIter.Key1()))
2289 {
2290 continue;
2291 }
2292
2293 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2294 {
2295 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2296 aCtx->Erase (aShape, Standard_False);
2297 }
2298 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2299 {
2300 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2301 TheNISContext()->Erase (aShape);
2302 }
2303 }
7fd59977 2304 return 0;
2305}
2306
2307//==============================================================================
eef7fc64 2308//function : VRemove
2309//purpose : Removes selected or named objects.
2310// If there is no selected or named objects,
2311// all objects in the viewer can be removed with argument -all.
2312// If -context is in arguments, the object is not deleted from the map of
2313// objects (deleted only from the current context).
2314//==============================================================================
2315int VRemove (Draw_Interpretor& theDI,
519d35d8 2316 Standard_Integer theArgNb,
2317 const char** theArgVec)
eef7fc64 2318{
4e18052b 2319 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2320 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2321 if (aCtx.IsNull())
eef7fc64 2322 {
b6d587e3 2323 std::cerr << "Error: no active view!\n";
eef7fc64 2324 return 1;
2325 }
2326
4e18052b 2327 Standard_Boolean isContextOnly = Standard_False;
2328 Standard_Boolean toRemoveAll = Standard_False;
2329 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2330 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2331
2332 Standard_Integer anArgIter = 1;
2333 for (; anArgIter < theArgNb; ++anArgIter)
2334 {
2335 TCollection_AsciiString anArg = theArgVec[anArgIter];
2336 anArg.LowerCase();
2337 if (anArg == "-context")
2338 {
2339 isContextOnly = Standard_True;
2340 }
2341 else if (anArg == "-all")
2342 {
2343 toRemoveAll = Standard_True;
2344 }
b7cd4ba7 2345 else if (anArg == "-noinfo")
2346 {
2347 toPrintInfo = Standard_False;
2348 }
b6d587e3 2349 else if (anArg == "-local")
2350 {
2351 toRemoveLocal = Standard_True;
2352 }
2353 else if (anUpdateTool.parseRedrawMode (anArg))
2354 {
2355 continue;
2356 }
2357 else
519d35d8 2358 {
2359 break;
2360 }
2361 }
2362 if (toRemoveAll
2363 && anArgIter < theArgNb)
2364 {
b6d587e3 2365 std::cerr << "Error: wrong syntax!\n";
2366 return 1;
2367 }
2368
2369 if (toRemoveLocal && !aCtx->HasOpenedContext())
2370 {
2371 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2372 return 1;
2373 }
b6d587e3 2374 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2375 {
2376 aCtx->CloseAllContexts (Standard_False);
2377 }
519d35d8 2378
eef7fc64 2379 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2380 if (toRemoveAll)
eef7fc64 2381 {
2382 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2383 anIter.More(); anIter.Next())
2384 {
2385 anIONameList.Append (anIter.Key2());
2386 }
2387 }
519d35d8 2388 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2389 {
519d35d8 2390 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2391 {
519d35d8 2392 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2393 if (!GetMapOfAIS().IsBound2 (aName))
2394 {
2395 theDI << aName.ToCString() << " was not bound to some object.\n";
2396 continue;
2397 }
2398
2399 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2400
2401 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2402 if (!anIO.IsNull())
2403 {
4e18052b 2404 if (anIO->GetContext() != aCtx)
eef7fc64 2405 {
2406 theDI << aName.ToCString() << " was not displayed in current context.\n";
2407 theDI << "Please activate view with this object displayed and try again.\n";
2408 continue;
2409 }
2410
2411 anIONameList.Append (aName);
2412 continue;
2413 }
2414
2415 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2416 if (!aNisIO.IsNull())
2417 {
2418 anIONameList.Append (aName);
2419 }
2420 }
2421 }
4e18052b 2422 else if (aCtx->NbCurrents() > 0
eef7fc64 2423 || TheNISContext()->GetSelected().Extent() > 0)
2424 {
2425 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2426 anIter.More(); anIter.Next())
2427 {
2428 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2429 if (!anIO.IsNull())
2430 {
4e18052b 2431 if (!aCtx->IsCurrent (anIO))
eef7fc64 2432 {
2433 continue;
2434 }
2435
2436 anIONameList.Append (anIter.Key2());
2437 continue;
2438 }
2439
2440 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2441 if (!aNisIO.IsNull())
2442 {
2443 if (!TheNISContext()->IsSelected (aNisIO))
2444 {
2445 continue;
2446 }
2447
2448 anIONameList.Append (anIter.Key2());
2449 }
2450 }
2451 }
2452
2453 // Unbind all removed objects from the map of displayed IO.
2454 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2455 anIter.More(); anIter.Next())
2456 {
519d35d8 2457 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
519d35d8 2458 if (!anIO.IsNull())
2459 {
4e18052b 2460 aCtx->Remove (anIO, Standard_False);
b7cd4ba7 2461 if (toPrintInfo)
2462 {
2463 theDI << anIter.Value().ToCString() << " was removed\n";
2464 }
519d35d8 2465 }
2466 else
2467 {
2468 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2469 if (!aNisIO.IsNull())
eef7fc64 2470 {
519d35d8 2471 TheNISContext()->Remove (aNisIO);
b7cd4ba7 2472 if (toPrintInfo)
2473 {
2474 theDI << anIter.Value().ToCString() << " was removed\n";
2475 }
eef7fc64 2476 }
519d35d8 2477 }
519d35d8 2478 if (!isContextOnly)
2479 {
2480 GetMapOfAIS().UnBind2 (anIter.Value());
2481 }
2482 }
b6d587e3 2483
2484 // Close local context if it is empty
2485 TColStd_MapOfTransient aLocalIO;
2486 if (aCtx->HasOpenedContext()
2487 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2488 {
2489 aCtx->CloseAllContexts (Standard_False);
2490 }
2491
eef7fc64 2492 return 0;
2493}
2494
2495//==============================================================================
b514beda 2496//function : VErase
2497//purpose : Erase some selected or named objects
7fd59977 2498// if there is no selected or named objects, the whole viewer is erased
7fd59977 2499//==============================================================================
b514beda 2500int VErase (Draw_Interpretor& theDI,
2501 Standard_Integer theArgNb,
2502 const char** theArgVec)
7fd59977 2503{
a1954302 2504 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2505 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2506 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2507 if (aCtx.IsNull())
b514beda 2508 {
b6d587e3 2509 std::cerr << "Error: no active view!\n";
7fd59977 2510 return 1;
b514beda 2511 }
519d35d8 2512
519d35d8 2513 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2514
2515 Standard_Integer anArgIter = 1;
a272ed94 2516 Standard_Boolean toEraseLocal = Standard_False;
2517 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2518 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2519 for (; anArgIter < theArgNb; ++anArgIter)
2520 {
b6d587e3 2521 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2522 anArgCase.LowerCase();
2523 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2524 {
b6d587e3 2525 continue;
2526 }
2527 else if (anArgCase == "-local")
2528 {
2529 toEraseLocal = Standard_True;
2530 }
a272ed94 2531 else if (anArgCase == "-view"
2532 || anArgCase == "-inview")
2533 {
2534 toEraseInView = Standard_True;
2535 }
b6d587e3 2536 else
2537 {
2538 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2539 }
2540 }
2541
b6d587e3 2542 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2543 {
b6d587e3 2544 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2545 return 1;
2546 }
7fd59977 2547
b6d587e3 2548 if (toEraseLocal && !aCtx->HasOpenedContext())
2549 {
2550 std::cerr << "Error: local selection context is not open.\n";
2551 return 1;
2552 }
2553 else if (!toEraseLocal && aCtx->HasOpenedContext())
2554 {
2555 aCtx->CloseAllContexts (Standard_False);
2556 }
2557
2558 if (!aNamesOfEraseIO.IsEmpty())
2559 {
2560 // Erase named objects
2561 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2562 {
b6d587e3 2563 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2564 if (!GetMapOfAIS().IsBound2 (aName))
2565 {
2566 continue;
2567 }
7fd59977 2568
b514beda 2569 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2570 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2571 theDI << aName.ToCString() << " ";
2572 if (!anIO.IsNull())
2573 {
a272ed94 2574 if (toEraseInView)
2575 {
2576 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2577 }
2578 else
2579 {
2580 aCtx->Erase (anIO, Standard_False);
2581 }
b514beda 2582 }
2583 else
2584 {
2585 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2586 if (!aNisIO.IsNull())
2587 {
2588 TheNISContext()->Erase (aNisIO);
2589 }
7fd59977 2590 }
7fd59977 2591 }
7fd59977 2592 }
b6d587e3 2593 else if (!toEraseAll && aCtx->NbCurrents() > 0)
b514beda 2594 {
b6d587e3 2595 // Erase selected objects
b514beda 2596 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2597 anIter.More(); anIter.Next())
2598 {
2599 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2600 if (!anIO.IsNull()
4e18052b 2601 && aCtx->IsCurrent (anIO))
b514beda 2602 {
2603 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2604 if (toEraseInView)
2605 {
2606 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2607 }
2608 else
2609 {
2610 aCtx->Erase (anIO, Standard_False);
2611 }
7fd59977 2612 }
2613 }
b514beda 2614 }
519d35d8 2615 else
b514beda 2616 {
b6d587e3 2617 // Erase all objects
519d35d8 2618 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2619 anIter.More(); anIter.Next())
b514beda 2620 {
519d35d8 2621 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2622 if (!anIO.IsNull())
2623 {
a272ed94 2624 if (toEraseInView)
2625 {
2626 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2627 }
2628 else
2629 {
2630 aCtx->Erase (anIO, Standard_False);
2631 }
519d35d8 2632 }
2633 else
b514beda 2634 {
519d35d8 2635 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2636 if (!aNisIO.IsNull())
2637 {
2638 TheNISContext()->Erase (aNisIO);
2639 }
b514beda 2640 }
7fd59977 2641 }
7fd59977 2642 }
b6d587e3 2643
7fd59977 2644 return 0;
2645}
2646
7fd59977 2647//==============================================================================
2648//function : VDisplayAll
2649//author : ege
2650//purpose : Display all the objects of the Map
7fd59977 2651//==============================================================================
519d35d8 2652static int VDisplayAll (Draw_Interpretor& ,
2653 Standard_Integer theArgNb,
2654 const char** theArgVec)
7fd59977 2655
2656{
4e18052b 2657 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2658 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2659 if (aCtx.IsNull())
519d35d8 2660 {
b6d587e3 2661 std::cerr << "Error: no active view!\n";
519d35d8 2662 return 1;
2663 }
2664
519d35d8 2665 Standard_Integer anArgIter = 1;
b6d587e3 2666 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2667 for (; anArgIter < theArgNb; ++anArgIter)
2668 {
b6d587e3 2669 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2670 anArgCase.LowerCase();
2671 if (anArgCase == "-local")
2672 {
2673 toDisplayLocal = Standard_True;
2674 }
2675 else if (anUpdateTool.parseRedrawMode (anArgCase))
2676 {
2677 continue;
2678 }
2679 else
519d35d8 2680 {
2681 break;
7fd59977 2682 }
519d35d8 2683 }
2684 if (anArgIter < theArgNb)
2685 {
2686 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2687 return 1;
2688 }
2689
b6d587e3 2690 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2691 {
b6d587e3 2692 std::cerr << "Error: local selection context is not open.\n";
2693 return 1;
2694 }
2695 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2696 {
2697 aCtx->CloseLocalContext (Standard_False);
519d35d8 2698 }
2699
2700 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2701 anIter.More(); anIter.Next())
2702 {
2703 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2704 {
2705 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2706 aCtx->Erase (aShape, Standard_False);
519d35d8 2707 }
2708 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2709 {
2710 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2711 TheNISContext()->Erase (aShape);
2712 }
2713 }
2714
2715 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2716 anIter.More(); anIter.Next())
2717 {
2718 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2719 {
2720 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
4e18052b 2721 aCtx->Display (aShape, Standard_False);
519d35d8 2722 }
2723 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2724 {
2725 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2726 TheNISContext()->Display (aShape);
7fd59977 2727 }
7fd59977 2728 }
2729 return 0;
2730}
2731
c2a388f8 2732//! Auxiliary method to find presentation
2733inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2734 const Handle(AIS_InteractiveObject)& theIO,
2735 const Standard_Integer theMode)
2736{
2737 if (theIO.IsNull())
2738 {
2739 return Handle(PrsMgr_Presentation)();
2740 }
2741
2742 if (theMode != -1)
2743 {
2744 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2745 {
2746 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2747 }
2748 }
2749 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2750 {
2751 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2752 }
2753 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2754 {
2755 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2756 }
2757 return Handle(PrsMgr_Presentation)();
2758}
2759
2760enum ViewerTest_BndAction
2761{
2762 BndAction_Hide,
2763 BndAction_Show,
2764 BndAction_Print
2765};
2766
2767//! Auxiliary method to print bounding box of presentation
2768inline void bndPresentation (Draw_Interpretor& theDI,
2769 const Handle(PrsMgr_Presentation)& thePrs,
2770 const TCollection_AsciiString& theName,
2771 const ViewerTest_BndAction theAction)
2772{
2773 switch (theAction)
2774 {
2775 case BndAction_Hide:
2776 {
2777 thePrs->Presentation()->GraphicUnHighlight();
2778 break;
2779 }
2780 case BndAction_Show:
2781 {
a1954302 2782 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2783 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2784 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2785 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2786 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2787 break;
2788 }
2789 case BndAction_Print:
2790 {
ed063270 2791 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2792 gp_Pnt aMin = aBox.CornerMin();
2793 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2794 theDI << theName << "\n"
ed063270 2795 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2796 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2797 break;
2798 }
2799 }
2800}
2801
2802//==============================================================================
2803//function : VBounding
2804//purpose :
2805//==============================================================================
2806int VBounding (Draw_Interpretor& theDI,
2807 Standard_Integer theArgNb,
2808 const char** theArgVec)
2809{
2810 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2811 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2812 if (aCtx.IsNull())
2813 {
2814 std::cout << "Error: no active view!\n";
2815 return 1;
2816 }
2817
4e18052b 2818 ViewerTest_BndAction anAction = BndAction_Show;
2819 Standard_Integer aMode = -1;
c2a388f8 2820
2821 Standard_Integer anArgIter = 1;
2822 for (; anArgIter < theArgNb; ++anArgIter)
2823 {
2824 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2825 anArg.LowerCase();
2826 if (anArg == "-print")
2827 {
2828 anAction = BndAction_Print;
2829 }
2830 else if (anArg == "-show")
2831 {
2832 anAction = BndAction_Show;
2833 }
2834 else if (anArg == "-hide")
2835 {
2836 anAction = BndAction_Hide;
2837 }
2838 else if (anArg == "-mode")
2839 {
2840 if (++anArgIter >= theArgNb)
2841 {
2842 std::cout << "Error: wrong syntax at " << anArg << "\n";
2843 return 1;
2844 }
2845 aMode = Draw::Atoi (theArgVec[anArgIter]);
2846 }
4e18052b 2847 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 2848 {
2849 break;
2850 }
2851 }
2852
2853 if (anArgIter < theArgNb)
2854 {
2855 // has a list of names
2856 for (; anArgIter < theArgNb; ++anArgIter)
2857 {
2858 TCollection_AsciiString aName = theArgVec[anArgIter];
2859 if (!GetMapOfAIS().IsBound2 (aName))
2860 {
2861 std::cout << "Error: presentation " << aName << " does not exist\n";
2862 return 1;
2863 }
2864
2865 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2866 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2867 if (aPrs.IsNull())
2868 {
2869 std::cout << "Error: presentation " << aName << " does not exist\n";
2870 return 1;
2871 }
2872 bndPresentation (theDI, aPrs, aName, anAction);
2873 }
2874 }
4e18052b 2875 else if (aCtx->NbCurrents() > 0)
c2a388f8 2876 {
2877 // remove all currently selected objects
2878 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2879 {
2880 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2881 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2882 if (!aPrs.IsNull())
2883 {
2884 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2885 }
2886 }
2887 }
2888 else
2889 {
2890 // all objects
2891 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2892 anIter.More(); anIter.Next())
2893 {
2894 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2895 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2896 if (!aPrs.IsNull())
2897 {
2898 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2899 }
2900 }
2901 }
c2a388f8 2902 return 0;
2903}
2904
d399d3c3 2905//==============================================================================
2906//function : VTexture
2907//purpose :
2908//==============================================================================
2909Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 2910{
d399d3c3 2911 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 2912
900f7229 2913 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 2914 if (aCommandName == "vtexture")
2915 {
2916 if (theArgsNb < 2)
7fd59977 2917 {
d399d3c3 2918 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2919 std::cout << "Type help for more information.\n";
31160f80 2920 return 1;
7fd59977 2921 }
2922
d399d3c3 2923 // look for options of vtexture command
2924 TCollection_AsciiString aParseKey;
2925 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2926 {
2927 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 2928
d399d3c3 2929 anArg.UpperCase();
2930 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2931 {
2932 aParseKey = anArg;
2933 aParseKey.Remove (1);
2934 aParseKey.UpperCase();
900f7229 2935 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 2936 continue;
2937 }
2938
2939 if (aParseKey.IsEmpty())
2940 {
2941 continue;
2942 }
2943
900f7229 2944 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 2945 }
2946 }
2947 else if (aCommandName == "vtexscale"
2948 || aCommandName == "vtexorigin"
2949 || aCommandName == "vtexrepeat")
2950 {
2951 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2952 // equal to -scale, -origin, -repeat options of vtexture command
2953 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 2954 {
d399d3c3 2955 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2956 std::cout << "Type help for more information.\n";
31160f80 2957 return 1;
7fd59977 2958 }
2959
900f7229 2960 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 2961 if (theArgsNb == 2)
2962 {
900f7229 2963 anArgs->Append ("OFF");
d399d3c3 2964 }
2965 else if (theArgsNb == 4)
2966 {
900f7229 2967 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2968 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 2969 }
7fd59977 2970
d399d3c3 2971 TCollection_AsciiString anArgKey;
2972 if (aCommandName == "vtexscale")
2973 {
2974 anArgKey = "SCALE";
2975 }
2976 else if (aCommandName == "vtexorigin")
2977 {
2978 anArgKey = "ORIGIN";
2979 }
2980 else
2981 {
2982 anArgKey = "REPEAT";
2983 }
2984
2985 aMapOfArgs.Bind (anArgKey, anArgs);
2986 }
2987 else if (aCommandName == "vtexdefault")
7fd59977 2988 {
d399d3c3 2989 // scan for parameters of vtexdefault command
2990 // equal to -default option of vtexture command
900f7229 2991 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 2992 }
2993
d399d3c3 2994 // Check arguments for validity
900f7229 2995 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 2996 for (; aMapIt.More(); aMapIt.Next())
2997 {
2998 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 2999 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3000
3001 // -scale, -origin, -repeat: one argument "off", or two real values
3002 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3003 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3004 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3005 {
d399d3c3 3006 continue;
7fd59977 3007 }
d399d3c3 3008
3009 // -modulate: single argument "on" / "off"
900f7229 3010 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3011 {
3012 continue;
3013 }
3014
3015 // -default: no arguments
900f7229 3016 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3017 {
3018 continue;
3019 }
3020
3021 TCollection_AsciiString aLowerKey;
3022 aLowerKey = "-";
3023 aLowerKey += aKey;
3024 aLowerKey.LowerCase();
3025 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3026 std::cout << "Type help for more information.\n";
3027 return 1;
3028 }
3029
3030 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3031 if (anAISContext.IsNull())
3032 {
3033 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3034 return 1;
3035 }
3036
3037 Standard_Integer aPreviousMode = 0;
3038
3039 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3040
3041 TCollection_AsciiString aShapeName (theArgv[1]);
3042 Handle(AIS_InteractiveObject) anIO;
3043
3044 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3045 if (aMapOfIO.IsBound2 (aShapeName))
3046 {
3047 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3048 }
3049
3050 if (anIO.IsNull())
3051 {
3052 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3053 return 1;
3054 }
3055
3056 Handle(AIS_TexturedShape) aTexturedIO;
3057 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3058 {
3059 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3060 aPreviousMode = aTexturedIO->DisplayMode();
3061 }
7fd59977 3062 else
d399d3c3 3063 {
2195ab96 3064 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3065 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3066 GetMapOfAIS().UnBind1 (anIO);
3067 GetMapOfAIS().UnBind2 (aShapeName);
3068 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3069 }
3070
3071 // -------------------------------------------
3072 // Turn texturing on/off - only for vtexture
3073 // -------------------------------------------
3074
3075 if (aCommandName == "vtexture")
3076 {
3077 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3078
3079 if (aTextureArg.IsEmpty())
7fd59977 3080 {
d399d3c3 3081 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3082 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3083
3084 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3085 if (aPreviousMode == 3)
3086 {
3087 anAISContext->RecomputePrsOnly (aTexturedIO);
3088 }
3089
3090 anAISContext->Display (aTexturedIO, Standard_True);
3091 return 0;
7fd59977 3092 }
d399d3c3 3093 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3094 {
d399d3c3 3095 if (aTextureArg == "?")
3096 {
3097 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3098
d399d3c3 3099 theDi << "\n Files in current directory : \n" << "\n";
3100 theDi.Eval ("glob -nocomplain *");
7fd59977 3101
d399d3c3 3102 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3103 aCmnd += aTextureFolder;
3104 aCmnd += "/* ";
7fd59977 3105
d399d3c3 3106 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3107 theDi.Eval (aCmnd.ToCString());
3108 return 0;
3109 }
3110 else
3111 {
3112 aTexturedIO->SetTextureFileName (aTextureArg);
3113 }
3114 }
3115 }
7fd59977 3116
d399d3c3 3117 // ------------------------------------
3118 // Process other options and commands
3119 // ------------------------------------
7fd59977 3120
900f7229 3121 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3122 if (aMapOfArgs.Find ("DEFAULT", aValues))
3123 {
3124 aTexturedIO->SetTextureRepeat (Standard_False);
3125 aTexturedIO->SetTextureOrigin (Standard_False);
3126 aTexturedIO->SetTextureScale (Standard_False);
3127 aTexturedIO->EnableTextureModulate();
3128 }
3129 else
3130 {
3131 if (aMapOfArgs.Find ("SCALE", aValues))
3132 {
900f7229 3133 if (aValues->Value(1) != "OFF")
d399d3c3 3134 {
900f7229 3135 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3136 }
7fd59977 3137 else
d399d3c3 3138 {
3139 aTexturedIO->SetTextureScale (Standard_False);
3140 }
3141 }
7fd59977 3142
d399d3c3 3143 if (aMapOfArgs.Find ("ORIGIN", aValues))
3144 {
900f7229 3145 if (aValues->Value(1) != "OFF")
d399d3c3 3146 {
900f7229 3147 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3148 }
3149 else
3150 {
3151 aTexturedIO->SetTextureOrigin (Standard_False);
3152 }
3153 }
7fd59977 3154
d399d3c3 3155 if (aMapOfArgs.Find ("REPEAT", aValues))
3156 {
900f7229 3157 if (aValues->Value(1) != "OFF")
d399d3c3 3158 {
900f7229 3159 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3160 }
3161 else
3162 {
3163 aTexturedIO->SetTextureRepeat (Standard_False);
3164 }
7fd59977 3165 }
3166
d399d3c3 3167 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3168 {
900f7229 3169 if (aValues->Value(1) == "ON")
d399d3c3 3170 {
3171 aTexturedIO->EnableTextureModulate();
3172 }
3173 else
3174 {
3175 aTexturedIO->DisableTextureModulate();
3176 }
7fd59977 3177 }
d399d3c3 3178 }
3179
3180 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3181 {
3182 anAISContext->RecomputePrsOnly (aTexturedIO);
3183 }
3184 else
3185 {
3186 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3187 anAISContext->Display (aTexturedIO, Standard_True);
3188 anAISContext->Update (aTexturedIO,Standard_True);
3189 }
3190
31160f80 3191 return 0;
7fd59977 3192}
3193
3194//==============================================================================
3195//function : VDisplay2
3196//author : ege
3197//purpose : Display an object from its name
7fd59977 3198//==============================================================================
519d35d8 3199static int VDisplay2 (Draw_Interpretor& theDI,
3200 Standard_Integer theArgNb,
3201 const char** theArgVec)
7fd59977 3202{
519d35d8 3203 if (theArgNb < 2)
3204 {
b6d587e3 3205 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3206 return 1;
3207 }
b6d587e3 3208
3209 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3210 if (aCtx.IsNull())
519d35d8 3211 {
7fd59977 3212 ViewerTest::ViewerInit();
4e18052b 3213 aCtx = ViewerTest::GetAISContext();
7fd59977 3214 }
3215
b6d587e3 3216 // Parse input arguments
4e18052b 3217 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3218 Standard_Integer isMutable = -1;
3219 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3220 Standard_Boolean toDisplayLocal = Standard_False;
3221 Standard_Boolean toReDisplay = Standard_False;
b6d587e3 3222 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3223 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3224 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3225 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3226 {
b7cd4ba7 3227 const TCollection_AsciiString aName = theArgVec[anArgIter];
3228 TCollection_AsciiString aNameCase = aName;
3229 aNameCase.LowerCase();
4e18052b 3230 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3231 {
3232 continue;
3233 }
b7cd4ba7 3234 else if (aNameCase == "-mutable")
3235 {
3236 isMutable = 1;
b7cd4ba7 3237 }
a1954302 3238 else if (aNameCase == "-neutral")
3239 {
3240 aDispStatus = AIS_DS_Displayed;
3241 }
3242 else if (aNameCase == "-immediate"
3243 || aNameCase == "-top")
3244 {
3245 aZLayer = Graphic3d_ZLayerId_Top;
3246 }
3247 else if (aNameCase == "-topmost")
3248 {
3249 aZLayer = Graphic3d_ZLayerId_Topmost;
3250 }
3251 else if (aNameCase == "-osd"
3252 || aNameCase == "-toposd")
3253 {
3254 aZLayer = Graphic3d_ZLayerId_TopOSD;
3255 }
3256 else if (aNameCase == "-layer")
3257 {
3258 if (++anArgIter >= theArgNb)
3259 {
3260 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3261 return 1;
3262 }
3263
3264 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3265 if (!aValue.IsIntegerValue())
3266 {
3267 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3268 return 1;
3269 }
3270
3271 aZLayer = aValue.IntegerValue();
3272 }
a272ed94 3273 else if (aNameCase == "-view"
3274 || aNameCase == "-inview")
3275 {
3276 toDisplayInView = Standard_True;
3277 }
b6d587e3 3278 else if (aNameCase == "-local")
3279 {
a1954302 3280 aDispStatus = AIS_DS_Temporary;
b6d587e3 3281 toDisplayLocal = Standard_True;
3282 }
a1954302 3283 else if (aNameCase == "-redisplay")
3284 {
3285 toReDisplay = Standard_True;
3286 }
b6d587e3 3287 else
3288 {
3289 aNamesOfDisplayIO.Append (aName);
3290 }
3291 }
3292
3293 if (aNamesOfDisplayIO.IsEmpty())
3294 {
3295 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3296 return 1;
3297 }
3298
3299 // Prepare context for display
3300 if (toDisplayLocal && !aCtx->HasOpenedContext())
3301 {
3302 aCtx->OpenLocalContext (Standard_False);
3303 }
3304 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3305 {
3306 aCtx->CloseAllContexts (Standard_False);
3307 }
3308
3309 // Display interactive objects
3310 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3311 {
3312 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3313
3314 if (!GetMapOfAIS().IsBound2 (aName))
519d35d8 3315 {
3316 // create the AIS_Shape from a name
3317 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3318 if (!aShape.IsNull())
3319 {
b7cd4ba7 3320 if (isMutable != -1)
3321 {
3322 aShape->SetMutable (isMutable == 1);
3323 }
a1954302 3324 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3325 {
3326 aShape->SetZLayer (aZLayer);
3327 }
519d35d8 3328 GetMapOfAIS().Bind (aShape, aName);
a1954302 3329
3330 Standard_Integer aDispMode = aShape->HasDisplayMode()
3331 ? aShape->DisplayMode()
3332 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3333 ? aCtx->DisplayMode()
3334 : 0);
3335 Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection()
3336 ? aShape->SelectionMode() : -1;
3337
3338 aCtx->Display (aShape, aDispMode, aSelMode,
3339 Standard_False, aShape->AcceptShapeDecomposition(),
3340 aDispStatus);
a272ed94 3341 if (toDisplayInView)
3342 {
3343 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3344 {
3345 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3346 }
3347 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3348 }
519d35d8 3349 }
3350 continue;
3351 }
7fd59977 3352
519d35d8 3353 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3354 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
3355 {
3356 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
b7cd4ba7 3357 if (isMutable != -1)
3358 {
3359 aShape->SetMutable (isMutable == 1);
3360 }
a1954302 3361 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3362 {
3363 aShape->SetZLayer (aZLayer);
3364 }
3365
3366 Standard_Integer aDispMode = aShape->HasDisplayMode()
3367 ? aShape->DisplayMode()
3368 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3369 ? aCtx->DisplayMode()
3370 : 0);
3371 Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection()
3372 ? aShape->SelectionMode() : -1;
b7cd4ba7 3373
519d35d8 3374 if (aShape->Type() == AIS_KOI_Datum)
3375 {
3376 aCtx->Display (aShape, Standard_False);
3377 }
3378 else
3379 {
3380 theDI << "Display " << aName.ToCString() << "\n";
7fd59977 3381
519d35d8 3382 // update the Shape in the AIS_Shape
a1954302 3383 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
519d35d8 3384 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3385 if (!aShapePrs.IsNull())
3386 {
a1954302 3387 if (!aShapePrs->Shape().IsEqual (aNewShape))
3388 {
3389 toReDisplay = Standard_True;
3390 }
519d35d8 3391 aShapePrs->Set (aNewShape);
7fd59977 3392 }
a1954302 3393 if (toReDisplay)
3394 {
3395 aCtx->Redisplay (aShape, Standard_False);
3396 }
3397
3398 aCtx->Display (aShape, aDispMode, aSelMode,
3399 Standard_False, aShape->AcceptShapeDecomposition(),
3400 aDispStatus);
a272ed94 3401 if (toDisplayInView)
3402 {
3403 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3404 }
7fd59977 3405 }
3406 }
519d35d8 3407 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
3408 {
3409 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
3410 TheNISContext()->Display (aShape);
7fd59977 3411 }
3412 }
b6d587e3 3413
7fd59977 3414 return 0;
3415}
3416
f3889691 3417//===============================================================================================
3418//function : VUpdate
3419//purpose :
3420//===============================================================================================
3421static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3422{
3423 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3424 if (aContextAIS.IsNull())
3425 {
3426 std::cout << theArgVec[0] << "AIS context is not available.\n";
3427 return 1;
3428 }
3429
3430 if (theArgsNb < 2)
3431 {
3432 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3433 return 1;
3434 }
3435
3436 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3437
3438 AIS_ListOfInteractive aListOfIO;
3439
3440 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3441 {
3442 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3443
3444 Handle(AIS_InteractiveObject) anAISObj;
3445 if (anAISMap.IsBound2 (aName))
3446 {
3447 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3448 }
3449
3450 if (anAISObj.IsNull())
3451 {
3452 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3453 return 1;
3454 }
3455
3456 aListOfIO.Append (anAISObj);
3457 }
3458
3459 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3460 for (; anIOIt.More(); anIOIt.Next())
3461 {
3462 aContextAIS->Update (anIOIt.Value(), Standard_False);
3463 }
3464
3465 aContextAIS->UpdateCurrentViewer();
3466
3467 return 0;
3468}
3469
7fd59977 3470//==============================================================================
7fd59977 3471//function : VPerf
3472//purpose : Test the annimation of an object along a
3473// predifined trajectory
3474//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3475//==============================================================================
3476
3477static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3478
3479 OSD_Timer myTimer;
3480 if (TheAISContext()->HasOpenedContext())
3481 TheAISContext()->CloseLocalContext();
3482
c6541a0c 3483 Standard_Real Step=4*M_PI/180;
7fd59977 3484 Standard_Real Angle=0;
3485
3486 Handle(AIS_InteractiveObject) aIO;
3487 if (GetMapOfAIS().IsBound2(argv[1]))
3488 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3489 if (aIO.IsNull())
3490 return 1;
3491
3492 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3493
3494 myTimer.Start();
3495
91322f44 3496 if (Draw::Atoi(argv[3])==1 ) {
7fd59977 3497 di<<" Primitives sensibles OFF"<<"\n";
3498 TheAISContext()->Deactivate(aIO);
3499 }
3500 else {
3501 di<<" Primitives sensibles ON"<<"\n";
3502 }
3503 // Movement par transformation
91322f44 3504 if(Draw::Atoi(argv[2]) ==1) {
7fd59977 3505 di<<" Calcul par Transformation"<<"\n";
c6541a0c 3506 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3507
3508 Angle=Step*myAngle;
3509