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