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