0027793: Visualization - object drifts at zoom within Graphic3d_TMF_TriedronPers...
[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
109//=======================================================================
536d98e2 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
159//=======================================================================
a5565a3c 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
183//=======================================================================
7fd59977 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
567//==============================================================================
1c88cbaf 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
745//==============================================================================
3c982548 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
3c982548 794//==============================================================================
7fd59977 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
7fd59977 1046//==============================================================================
1047//function : Displays,Erase...
1048//purpose :
1049//Draw arg :
1050//==============================================================================
1051static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1052 const Standard_Integer Mode,
1053 const Standard_Integer TypeOfOperation,
1054 const Standard_Boolean Upd)
1055{
1056 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1057
1058 switch(TypeOfOperation){
1059 case 1:
1060 Ctx->Display(IO,Mode,Upd);
1061 break;
1062 case 2:{
eb4320f2 1063 Ctx->Erase(IO,Upd);
7fd59977 1064 break;
1065 }
1066 case 3:{
1067 if(IO.IsNull())
1068 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1069 else
1070 Ctx->SetDisplayMode(IO,Mode,Upd);
1071 break;
1072 }
1073 case 4:{
1074 if(IO.IsNull())
1075 Ctx->SetDisplayMode(0,Upd);
1076 else
1077 Ctx->UnsetDisplayMode(IO,Upd);
1078 break;
1079 }
1080 }
1081 return 0;
1082}
1083
1084//=======================================================================
1085//function :
1086//purpose :
1087//=======================================================================
1088static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1089{
1090
1091 TCollection_AsciiString name;
1092 if(argc>3)
1093 return 1;
1094 // display others presentations
1095 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1096 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1097 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1098 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1099
1100 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1101
1102 //unset displaymode.. comportement particulier...
1103 if(TypeOfOperation==4){
1104 if(argc==1){
c3282ec1 1105 if(Ctx->NbSelected()==0){
7fd59977 1106 Handle(AIS_InteractiveObject) IO;
1107 VwrTst_DispErase(IO,-1,4,Standard_False);
1108 }
7fd59977 1109 else{
1110 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1111 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
7fd59977 1112 Ctx->UpdateCurrentViewer();
1113 }
1114 else{
1115 Handle(AIS_InteractiveObject) IO;
1116 name = argv[1];
1117 if(GetMapOfAIS().IsBound2(name)){
1118 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1119 if (!IO.IsNull())
1120 VwrTst_DispErase(IO,-1,4,Standard_True);
1121 }
1122 }
1123 }
1124 else if(argc==2){
91322f44 1125 Standard_Integer Dmode = Draw::Atoi(argv[1]);
c3282ec1 1126 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
7fd59977 1127 Handle(AIS_InteractiveObject) IO;
1128 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1129 }
1130 if(!Ctx->HasOpenedContext()){
1131 // set/unset display mode sur le Contexte...
c3282ec1 1132 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1133 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
7fd59977 1134 }
1135 Ctx->UpdateCurrentViewer();
1136 }
1137 else{
1138 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1139 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
7fd59977 1140 }
1141 }
1142 else{
1143 Handle(AIS_InteractiveObject) IO;
1144 name = argv[1];
1145 if(GetMapOfAIS().IsBound2(name))
1146 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1147 if (!IO.IsNull())
91322f44 1148 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1149 }
1150 return 0;
1151}
1152
1153
1154//=======================================================================
1155//function :
1156//purpose :
1157//=======================================================================
1158static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1159{
1160 if(argc==1) return 1;
91322f44 1161 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1162 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1163
c3282ec1 1164 if(argc==2)
1165 {
1166 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1167 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1168 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1169 {
1170 if(On==1)
1171 {
1172 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1173 }
c3282ec1 1174 else
1175 {
1176 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1177 }
1178 }
c3282ec1 1179
7fd59977 1180 Ctx->UpdateCurrentViewer();
1181 }
1182 else {
1183 Handle(AIS_InteractiveObject) IO;
1184 TCollection_AsciiString name = argv[2];
1185 if(GetMapOfAIS().IsBound2(name)){
1186 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1187 if (!IO.IsNull()) {
7fd59977 1188 if(On==1)
1189 Ctx->SubIntensityOn(IO);
1190 else
1191 Ctx->SubIntensityOff(IO);
eafb234b 1192 }
7fd59977 1193 }
1194 else return 1;
1195 }
1196 return 0;
7fd59977 1197}
7fd59977 1198
ad3217cd 1199//! Auxiliary class to iterate presentations from different collections.
1200class ViewTest_PrsIter
1201{
1202public:
7fd59977 1203
ad3217cd 1204 //! Create and initialize iterator object.
1205 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1206 : mySource (IterSource_All)
1207 {
1208 NCollection_Sequence<TCollection_AsciiString> aNames;
1209 if (!theName.IsEmpty())
1210 aNames.Append (theName);
1211 Init (aNames);
7fd59977 1212 }
ad3217cd 1213
1214 //! Create and initialize iterator object.
1215 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1216 : mySource (IterSource_All)
1217 {
1218 Init (theNames);
7fd59977 1219 }
1220
ad3217cd 1221 //! Initialize the iterator.
1222 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1223 {
1224 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1225 mySeq = theNames;
1226 mySelIter.Nullify();
1227 myCurrent.Nullify();
1228 myCurrentTrs.Nullify();
1229 if (!mySeq.IsEmpty())
1230 {
1231 mySource = IterSource_List;
1232 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1233 }
c3282ec1 1234 else if (aCtx->NbSelected() > 0)
ad3217cd 1235 {
1236 mySource = IterSource_Selected;
1237 mySelIter = aCtx;
c3282ec1 1238 mySelIter->InitSelected();
ad3217cd 1239 }
1240 else
1241 {
1242 mySource = IterSource_All;
1243 myMapIter.Initialize (GetMapOfAIS());
1244 }
1245 initCurrent();
1246 }
7fd59977 1247
ad3217cd 1248 const TCollection_AsciiString& CurrentName() const
1249 {
1250 return myCurrentName;
1251 }
7fd59977 1252
ad3217cd 1253 const Handle(AIS_InteractiveObject)& Current() const
1254 {
1255 return myCurrent;
1256 }
7fd59977 1257
ad3217cd 1258 const Handle(Standard_Transient)& CurrentTrs() const
1259 {
1260 return myCurrentTrs;
1261 }
1262
1263 //! @return true if iterator points to valid object within collection
1264 Standard_Boolean More() const
1265 {
1266 switch (mySource)
1267 {
1268 case IterSource_All: return myMapIter.More();
1269 case IterSource_List: return mySeqIter.More();
c3282ec1 1270 case IterSource_Selected: return mySelIter->MoreSelected();
ad3217cd 1271 }
1272 return Standard_False;
1273 }
1274
1275 //! Go to the next item.
1276 void Next()
1277 {
1278 myCurrentName.Clear();
1279 myCurrentTrs.Nullify();
1280 myCurrent.Nullify();
1281 switch (mySource)
1282 {
1283 case IterSource_All:
1284 {
1285 myMapIter.Next();
1286 break;
1287 }
1288 case IterSource_List:
1289 {
1290 mySeqIter.Next();
1291 break;
1292 }
1293 case IterSource_Selected:
1294 {
c3282ec1 1295 mySelIter->NextSelected();
ad3217cd 1296 break;
7fd59977 1297 }
1298 }
ad3217cd 1299 initCurrent();
1300 }
7fd59977 1301
ad3217cd 1302private:
7fd59977 1303
ad3217cd 1304 void initCurrent()
1305 {
1306 switch (mySource)
1307 {
1308 case IterSource_All:
7fd59977 1309 {
ad3217cd 1310 if (myMapIter.More())
1311 {
1312 myCurrentName = myMapIter.Key2();
1313 myCurrentTrs = myMapIter.Key1();
1314 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1315 }
ad3217cd 1316 break;
1317 }
1318 case IterSource_List:
1319 {
1320 if (mySeqIter.More())
1321 {
1322 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1323 {
1324 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1325 return;
1326 }
1327 myCurrentName = mySeqIter.Value();
1328 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1329 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1330 }
1331 break;
1332 }
1333 case IterSource_Selected:
1334 {
c3282ec1 1335 if (mySelIter->MoreSelected())
ad3217cd 1336 {
c3282ec1 1337 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1338 myCurrent = mySelIter->SelectedInteractive();
ad3217cd 1339 }
1340 break;
7fd59977 1341 }
7fd59977 1342 }
1343 }
ad3217cd 1344
1345private:
1346
1347 enum IterSource
1348 {
1349 IterSource_All,
1350 IterSource_List,
1351 IterSource_Selected
1352 };
1353
1354private:
1355
1356 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1357 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1358 NCollection_Sequence<TCollection_AsciiString> mySeq;
1359 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1360
1361 TCollection_AsciiString myCurrentName;//!< current item name
1362 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1363 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1364
1365 IterSource mySource; //!< iterated collection
1366
1367};
7fd59977 1368
1369//==============================================================================
ad3217cd 1370//function : VInteriorStyle
1371//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1372//==============================================================================
ad3217cd 1373static int VSetInteriorStyle (Draw_Interpretor& theDI,
1374 Standard_Integer theArgNb,
1375 const char** theArgVec)
7fd59977 1376{
ad3217cd 1377 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1378 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1379 if (aCtx.IsNull())
1380 {
1381 std::cerr << "Error: no active view!\n";
1382 return 1;
1383 }
7fd59977 1384
4e18052b 1385 Standard_Integer anArgIter = 1;
ad3217cd 1386 for (; anArgIter < theArgNb; ++anArgIter)
1387 {
4e18052b 1388 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1389 {
1390 break;
1391 }
7fd59977 1392 }
ad3217cd 1393 TCollection_AsciiString aName;
1394 if (theArgNb - anArgIter == 2)
1395 {
1396 aName = theArgVec[anArgIter++];
1397 }
1398 else if (theArgNb - anArgIter != 1)
1399 {
1400 std::cout << "Error: wrong number of arguments! See usage:\n";
1401 theDI.PrintHelp (theArgVec[0]);
1402 return 1;
1403 }
1404 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1405 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1406 aStyleArg.LowerCase();
1407 if (aStyleArg == "empty")
1408 {
1409 anInterStyle = 0;
1410 }
1411 else if (aStyleArg == "hollow")
1412 {
1413 anInterStyle = 1;
1414 }
1415 else if (aStyleArg == "hatch")
1416 {
1417 anInterStyle = 2;
1418 }
1419 else if (aStyleArg == "solid")
1420 {
1421 anInterStyle = 3;
1422 }
1423 else if (aStyleArg == "hiddenline")
1424 {
1425 anInterStyle = 4;
1426 }
1427 else
1428 {
1429 anInterStyle = aStyleArg.IntegerValue();
1430 }
1431 if (anInterStyle < Aspect_IS_EMPTY
1432 || anInterStyle > Aspect_IS_HIDDENLINE)
1433 {
1434 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1435 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1436 return 1;
7fd59977 1437 }
1438
ad3217cd 1439 if (!aName.IsEmpty()
1440 && !GetMapOfAIS().IsBound2 (aName))
1441 {
1442 std::cout << "Error: object " << aName << " is not displayed!\n";
1443 return 1;
1444 }
1445
1446 if (aCtx->HasOpenedContext())
1447 {
1448 aCtx->CloseLocalContext();
1449 }
1450 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1451 {
1452 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1453 if (!anIO.IsNull())
1454 {
1455 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1456 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1457 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1458 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1459 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1460 }
ad3217cd 1461 }
ad3217cd 1462 return 0;
1463}
7fd59977 1464
ad3217cd 1465//! Auxiliary structure for VAspects
1466struct ViewerTest_AspectsChangeSet
1467{
5bffb882 1468 Standard_Integer ToSetVisibility;
1469 Standard_Integer Visibility;
1470
ad3217cd 1471 Standard_Integer ToSetColor;
1472 Quantity_Color Color;
1473
1474 Standard_Integer ToSetLineWidth;
1475 Standard_Real LineWidth;
1476
ac116c22 1477 Standard_Integer ToSetTypeOfLine;
1478 Aspect_TypeOfLine TypeOfLine;
1479
ad3217cd 1480 Standard_Integer ToSetTransparency;
1481 Standard_Real Transparency;
1482
1483 Standard_Integer ToSetMaterial;
1484 Graphic3d_NameOfMaterial Material;
1485 TCollection_AsciiString MatName;
1486
1487 NCollection_Sequence<TopoDS_Shape> SubShapes;
1488
6262338c 1489 Standard_Integer ToSetShowFreeBoundary;
1490 Standard_Integer ToSetFreeBoundaryWidth;
1491 Standard_Real FreeBoundaryWidth;
1492 Standard_Integer ToSetFreeBoundaryColor;
1493 Quantity_Color FreeBoundaryColor;
1494
5ad8c033 1495 Standard_Integer ToEnableIsoOnTriangulation;
1496
1497 Standard_Integer ToSetMaxParamValue;
1498 Standard_Real MaxParamValue;
1499
8a1170ad 1500 Standard_Integer ToSetSensitivity;
1501 Standard_Integer SelectionMode;
1502 Standard_Integer Sensitivity;
1503
ad3217cd 1504 //! Empty constructor
1505 ViewerTest_AspectsChangeSet()
5bffb882 1506 : ToSetVisibility (0),
1507 Visibility (1),
1508 ToSetColor (0),
ad3217cd 1509 Color (DEFAULT_COLOR),
1510 ToSetLineWidth (0),
1511 LineWidth (1.0),
ac116c22 1512 ToSetTypeOfLine (0),
1513 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1514 ToSetTransparency (0),
1515 Transparency (0.0),
1516 ToSetMaterial (0),
6262338c 1517 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1518 ToSetShowFreeBoundary (0),
1519 ToSetFreeBoundaryWidth (0),
1520 FreeBoundaryWidth (1.0),
1521 ToSetFreeBoundaryColor (0),
1522 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1523 ToEnableIsoOnTriangulation (-1),
1524 ToSetMaxParamValue (0),
8a1170ad 1525 MaxParamValue (500000),
1526 ToSetSensitivity (0),
1527 SelectionMode (-1),
1528 Sensitivity (-1) {}
ad3217cd 1529
1530 //! @return true if no changes have been requested
1531 Standard_Boolean IsEmpty() const
1532 {
6262338c 1533 return ToSetVisibility == 0
1534 && ToSetLineWidth == 0
1535 && ToSetTransparency == 0
1536 && ToSetColor == 0
1537 && ToSetMaterial == 0
1538 && ToSetShowFreeBoundary == 0
1539 && ToSetFreeBoundaryColor == 0
5ad8c033 1540 && ToSetFreeBoundaryWidth == 0
8a1170ad 1541 && ToSetMaxParamValue == 0
1542 && ToSetSensitivity == 0;
ad3217cd 1543 }
1544
1545 //! @return true if properties are valid
1546 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1547 {
1548 Standard_Boolean isOk = Standard_True;
5bffb882 1549 if (Visibility != 0 && Visibility != 1)
1550 {
1551 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1552 isOk = Standard_False;
1553 }
ad3217cd 1554 if (LineWidth <= 0.0
1555 || LineWidth > 10.0)
1556 {
1557 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1558 isOk = Standard_False;
7fd59977 1559 }
ad3217cd 1560 if (Transparency < 0.0
1561 || Transparency > 1.0)
1562 {
1563 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1564 isOk = Standard_False;
1565 }
1566 if (theIsSubPart
1567 && ToSetTransparency)
1568 {
1569 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1570 isOk = Standard_False;
7fd59977 1571 }
ad3217cd 1572 if (ToSetMaterial == 1
1573 && Material == Graphic3d_NOM_DEFAULT)
1574 {
1575 std::cout << "Error: unknown material " << MatName << ".\n";
1576 isOk = Standard_False;
1577 }
6262338c 1578 if (FreeBoundaryWidth <= 0.0
1579 || FreeBoundaryWidth > 10.0)
1580 {
1581 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1582 isOk = Standard_False;
1583 }
5ad8c033 1584 if (MaxParamValue < 0.0)
1585 {
1586 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1587 isOk = Standard_False;
1588 }
8a1170ad 1589 if (Sensitivity <= 0 && ToSetSensitivity)
1590 {
1591 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1592 isOk = Standard_False;
1593 }
ad3217cd 1594 return isOk;
7fd59977 1595 }
7fd59977 1596
ad3217cd 1597};
7fd59977 1598
1599//==============================================================================
ad3217cd 1600//function : VAspects
1601//purpose :
7fd59977 1602//==============================================================================
ad3217cd 1603static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1604 Standard_Integer theArgNb,
1605 const char** theArgVec)
7fd59977 1606{
ad3217cd 1607 TCollection_AsciiString aCmdName (theArgVec[0]);
1608 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1609 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1610 if (aCtx.IsNull())
1611 {
1612 std::cerr << "Error: no active view!\n";
1613 return 1;
1614 }
7fd59977 1615
4e18052b 1616 Standard_Integer anArgIter = 1;
6262338c 1617 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1618 NCollection_Sequence<TCollection_AsciiString> aNames;
1619 for (; anArgIter < theArgNb; ++anArgIter)
1620 {
1621 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1622 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1623 {
1624 continue;
1625 }
1626 else if (!anArg.IsEmpty()
1627 && anArg.Value (1) != '-')
1628 {
1629 aNames.Append (anArg);
1630 }
1631 else
1632 {
6262338c 1633 if (anArg == "-defaults")
1634 {
1635 isDefaults = Standard_True;
1636 ++anArgIter;
1637 }
ad3217cd 1638 break;
1639 }
1640 }
1641
6262338c 1642 if (!aNames.IsEmpty() && isDefaults)
1643 {
1644 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1645 return 1;
1646 }
1647
ad3217cd 1648 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1649 aChanges.Append (ViewerTest_AspectsChangeSet());
1650 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1651
ad3217cd 1652 // parse syntax of legacy commands
1653 if (aCmdName == "vsetwidth")
1654 {
1655 if (aNames.IsEmpty()
1656 || !aNames.Last().IsRealValue())
1657 {
1658 std::cout << "Error: not enough arguments!\n";
1659 return 1;
1660 }
1661 aChangeSet->ToSetLineWidth = 1;
1662 aChangeSet->LineWidth = aNames.Last().RealValue();
1663 aNames.Remove (aNames.Length());
7fd59977 1664 }
ad3217cd 1665 else if (aCmdName == "vunsetwidth")
1666 {
1667 aChangeSet->ToSetLineWidth = -1;
1668 }
1669 else if (aCmdName == "vsetcolor")
1670 {
1671 if (aNames.IsEmpty())
1672 {
1673 std::cout << "Error: not enough arguments!\n";
1674 return 1;
1675 }
1676 aChangeSet->ToSetColor = 1;
8316c618 1677
1678 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1679 Standard_Boolean isOk = Standard_False;
1680 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1681 {
1682 aChangeSet->Color = aColor;
1683 aNames.Remove (aNames.Length());
1684 isOk = Standard_True;
1685 }
1686 else if (aNames.Length() >= 3)
1687 {
1688 const TCollection_AsciiString anRgbStr[3] =
1689 {
1690 aNames.Value (aNames.Upper() - 2),
1691 aNames.Value (aNames.Upper() - 1),
1692 aNames.Value (aNames.Upper() - 0)
1693 };
1694 isOk = anRgbStr[0].IsRealValue()
1695 && anRgbStr[1].IsRealValue()
1696 && anRgbStr[2].IsRealValue();
1697 if (isOk)
1698 {
1699 Graphic3d_Vec4d anRgb;
1700 anRgb.x() = anRgbStr[0].RealValue();
1701 anRgb.y() = anRgbStr[1].RealValue();
1702 anRgb.z() = anRgbStr[2].RealValue();
1703 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1704 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1705 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1706 {
1707 std::cout << "Error: RGB color values should be within range 0..1!\n";
1708 return 1;
1709 }
1710 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1711 aNames.Remove (aNames.Length());
1712 aNames.Remove (aNames.Length());
1713 aNames.Remove (aNames.Length());
1714 }
1715 }
1716 if (!isOk)
1717 {
1718 std::cout << "Error: not enough arguments!\n";
1719 return 1;
1720 }
ad3217cd 1721 }
1722 else if (aCmdName == "vunsetcolor")
1723 {
1724 aChangeSet->ToSetColor = -1;
1725 }
1726 else if (aCmdName == "vsettransparency")
1727 {
1728 if (aNames.IsEmpty()
1729 || !aNames.Last().IsRealValue())
1730 {
1731 std::cout << "Error: not enough arguments!\n";
1732 return 1;
1733 }
1734 aChangeSet->ToSetTransparency = 1;
1735 aChangeSet->Transparency = aNames.Last().RealValue();
1736 aNames.Remove (aNames.Length());
1737 }
1738 else if (aCmdName == "vunsettransparency")
1739 {
1740 aChangeSet->ToSetTransparency = -1;
1741 }
1742 else if (aCmdName == "vsetmaterial")
1743 {
1744 if (aNames.IsEmpty())
1745 {
1746 std::cout << "Error: not enough arguments!\n";
1747 return 1;
1748 }
1749 aChangeSet->ToSetMaterial = 1;
1750 aChangeSet->MatName = aNames.Last();
1751 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1752 aNames.Remove (aNames.Length());
1753 }
1754 else if (aCmdName == "vunsetmaterial")
1755 {
1756 aChangeSet->ToSetMaterial = -1;
1757 }
1758 else if (anArgIter >= theArgNb)
1759 {
1760 std::cout << "Error: not enough arguments!\n";
1761 return 1;
7fd59977 1762 }
1763
ad3217cd 1764 if (!aChangeSet->IsEmpty())
1765 {
1766 anArgIter = theArgNb;
1767 }
1768 for (; anArgIter < theArgNb; ++anArgIter)
1769 {
1770 TCollection_AsciiString anArg = theArgVec[anArgIter];
1771 anArg.LowerCase();
1772 if (anArg == "-setwidth"
1773 || anArg == "-setlinewidth")
1774 {
1775 if (++anArgIter >= theArgNb)
1776 {
1777 std::cout << "Error: wrong syntax at " << anArg << "\n";
1778 return 1;
1779 }
1780 aChangeSet->ToSetLineWidth = 1;
1781 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1782 }
ad3217cd 1783 else if (anArg == "-unsetwidth"
1784 || anArg == "-unsetlinewidth")
1785 {
1786 aChangeSet->ToSetLineWidth = -1;
1787 aChangeSet->LineWidth = 1.0;
1788 }
1789 else if (anArg == "-settransp"
0ae61cf3 1790 || anArg == "-settransparency")
ad3217cd 1791 {
1792 if (++anArgIter >= theArgNb)
1793 {
1794 std::cout << "Error: wrong syntax at " << anArg << "\n";
1795 return 1;
1796 }
1797 aChangeSet->ToSetTransparency = 1;
1798 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1799 if (aChangeSet->Transparency >= 0.0
1800 && aChangeSet->Transparency <= Precision::Confusion())
1801 {
1802 aChangeSet->ToSetTransparency = -1;
1803 aChangeSet->Transparency = 0.0;
eafb234b 1804 }
7fd59977 1805 }
5bffb882 1806 else if (anArg == "-setvis"
1807 || anArg == "-setvisibility")
1808 {
1809 if (++anArgIter >= theArgNb)
1810 {
1811 std::cout << "Error: wrong syntax at " << anArg << "\n";
1812 return 1;
1813 }
1814
1815 aChangeSet->ToSetVisibility = 1;
1816 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1817 }
ad3217cd 1818 else if (anArg == "-setalpha")
1819 {
1820 if (++anArgIter >= theArgNb)
7fd59977 1821 {
ad3217cd 1822 std::cout << "Error: wrong syntax at " << anArg << "\n";
1823 return 1;
1824 }
1825 aChangeSet->ToSetTransparency = 1;
1826 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1827 if (aChangeSet->Transparency < 0.0
1828 || aChangeSet->Transparency > 1.0)
1829 {
1830 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1831 return 1;
1832 }
1833 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1834 if (aChangeSet->Transparency >= 0.0
1835 && aChangeSet->Transparency <= Precision::Confusion())
1836 {
1837 aChangeSet->ToSetTransparency = -1;
1838 aChangeSet->Transparency = 0.0;
7fd59977 1839 }
7fd59977 1840 }
ad3217cd 1841 else if (anArg == "-unsettransp"
0ae61cf3 1842 || anArg == "-unsettransparency"
ad3217cd 1843 || anArg == "-unsetalpha"
1844 || anArg == "-opaque")
1845 {
1846 aChangeSet->ToSetTransparency = -1;
1847 aChangeSet->Transparency = 0.0;
1848 }
1849 else if (anArg == "-setcolor")
1850 {
8316c618 1851 Standard_Integer aNbComps = 0;
1852 Standard_Integer aCompIter = anArgIter + 1;
1853 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1854 {
8316c618 1855 if (theArgVec[aCompIter][0] == '-')
1856 {
1857 break;
1858 }
1859 }
1860 switch (aNbComps)
1861 {
1862 case 1:
1863 {
1864 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1865 Standard_CString aName = theArgVec[anArgIter + 1];
1866 if (!Quantity_Color::ColorFromName (aName, aColor))
1867 {
1868 std::cout << "Error: unknown color name '" << aName << "'\n";
1869 return 1;
1870 }
1871 aChangeSet->Color = aColor;
1872 break;
1873 }
1874 case 3:
1875 {
1876 Graphic3d_Vec3d anRgb;
1877 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1878 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1879 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1880 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1881 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1882 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1883 {
1884 std::cout << "Error: RGB color values should be within range 0..1!\n";
1885 return 1;
1886 }
1887 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1888 break;
1889 }
1890 default:
1891 {
1892 std::cout << "Error: wrong syntax at " << anArg << "\n";
1893 return 1;
1894 }
7fd59977 1895 }
ad3217cd 1896 aChangeSet->ToSetColor = 1;
8316c618 1897 anArgIter += aNbComps;
7fd59977 1898 }
ac116c22 1899 else if (anArg == "-setlinetype")
1900 {
1901 if (++anArgIter >= theArgNb)
1902 {
1903 std::cout << "Error: wrong syntax at " << anArg << "\n";
1904 return 1;
1905 }
1906
1907 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1908 aValue.LowerCase();
1909
1910 if (aValue.IsEqual ("solid"))
1911 {
1912 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1913 }
1914 else if (aValue.IsEqual ("dot"))
1915 {
1916 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1917 }
1918 else if (aValue.IsEqual ("dash"))
1919 {
1920 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1921 }
1922 else if (aValue.IsEqual ("dotdash"))
1923 {
1924 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1925 }
1926 else
1927 {
1928 std::cout << "Error: wrong syntax at " << anArg << "\n";
1929 return 1;
1930 }
1931
1932 aChangeSet->ToSetTypeOfLine = 1;
1933 }
1934 else if (anArg == "-unsetlinetype")
1935 {
1936 aChangeSet->ToSetTypeOfLine = -1;
1937 }
ad3217cd 1938 else if (anArg == "-unsetcolor")
1939 {
1940 aChangeSet->ToSetColor = -1;
1941 aChangeSet->Color = DEFAULT_COLOR;
1942 }
1943 else if (anArg == "-setmat"
1944 || anArg == "-setmaterial")
1945 {
1946 if (++anArgIter >= theArgNb)
1947 {
1948 std::cout << "Error: wrong syntax at " << anArg << "\n";
1949 return 1;
1950 }
1951 aChangeSet->ToSetMaterial = 1;
1952 aChangeSet->MatName = theArgVec[anArgIter];
1953 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1954 }
1955 else if (anArg == "-unsetmat"
1956 || anArg == "-unsetmaterial")
1957 {
1958 aChangeSet->ToSetMaterial = -1;
1959 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1960 }
1961 else if (anArg == "-subshape"
1962 || anArg == "-subshapes")
1963 {
6262338c 1964 if (isDefaults)
1965 {
1966 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1967 return 1;
1968 }
1969
ad3217cd 1970 if (aNames.IsEmpty())
1971 {
1972 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1973 return 1;
1974 }
7fd59977 1975
ad3217cd 1976 aChanges.Append (ViewerTest_AspectsChangeSet());
1977 aChangeSet = &aChanges.ChangeLast();
7fd59977 1978
ad3217cd 1979 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1980 {
1981 Standard_CString aSubShapeName = theArgVec[anArgIter];
1982 if (*aSubShapeName == '-')
1983 {
1984 --anArgIter;
1985 break;
1986 }
7fd59977 1987
ad3217cd 1988 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1989 if (aSubShape.IsNull())
1990 {
1991 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1992 return 1;
1993 }
1994 aChangeSet->SubShapes.Append (aSubShape);
1995 }
7fd59977 1996
ad3217cd 1997 if (aChangeSet->SubShapes.IsEmpty())
1998 {
1999 std::cerr << "Error: empty list is specified after -subshapes!\n";
2000 return 1;
2001 }
2002 }
6262338c 2003 else if (anArg == "-freeboundary"
2004 || anArg == "-fb")
2005 {
2006 if (++anArgIter >= theArgNb)
2007 {
2008 std::cout << "Error: wrong syntax at " << anArg << "\n";
2009 return 1;
2010 }
2011 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2012 aValue.LowerCase();
2013 if (aValue == "on"
2014 || aValue == "1")
2015 {
2016 aChangeSet->ToSetShowFreeBoundary = 1;
2017 }
2018 else if (aValue == "off"
2019 || aValue == "0")
2020 {
2021 aChangeSet->ToSetShowFreeBoundary = -1;
2022 }
2023 else
2024 {
2025 std::cout << "Error: wrong syntax at " << anArg << "\n";
2026 return 1;
2027 }
2028 }
2029 else if (anArg == "-setfreeboundarywidth"
2030 || anArg == "-setfbwidth")
2031 {
2032 if (++anArgIter >= theArgNb)
2033 {
2034 std::cout << "Error: wrong syntax at " << anArg << "\n";
2035 return 1;
2036 }
2037 aChangeSet->ToSetFreeBoundaryWidth = 1;
2038 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2039 }
2040 else if (anArg == "-unsetfreeboundarywidth"
2041 || anArg == "-unsetfbwidth")
2042 {
2043 aChangeSet->ToSetFreeBoundaryWidth = -1;
2044 aChangeSet->FreeBoundaryWidth = 1.0;
2045 }
2046 else if (anArg == "-setfreeboundarycolor"
2047 || anArg == "-setfbcolor")
2048 {
2049 Standard_Integer aNbComps = 0;
2050 Standard_Integer aCompIter = anArgIter + 1;
2051 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2052 {
2053 if (theArgVec[aCompIter][0] == '-')
2054 {
2055 break;
2056 }
2057 }
2058 switch (aNbComps)
2059 {
2060 case 1:
2061 {
2062 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2063 Standard_CString aName = theArgVec[anArgIter + 1];
2064 if (!Quantity_Color::ColorFromName (aName, aColor))
2065 {
2066 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2067 return 1;
2068 }
2069 aChangeSet->FreeBoundaryColor = aColor;
2070 break;
2071 }
2072 case 3:
2073 {
2074 Graphic3d_Vec3d anRgb;
2075 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2076 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2077 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2078 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2079 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2080 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2081 {
2082 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2083 return 1;
2084 }
2085 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2086 break;
2087 }
2088 default:
2089 {
2090 std::cout << "Error: wrong syntax at " << anArg << "\n";
2091 return 1;
2092 }
2093 }
2094 aChangeSet->ToSetFreeBoundaryColor = 1;
2095 anArgIter += aNbComps;
2096 }
2097 else if (anArg == "-unsetfreeboundarycolor"
2098 || anArg == "-unsetfbcolor")
2099 {
2100 aChangeSet->ToSetFreeBoundaryColor = -1;
2101 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2102 }
ad3217cd 2103 else if (anArg == "-unset")
2104 {
5bffb882 2105 aChangeSet->ToSetVisibility = 1;
2106 aChangeSet->Visibility = 1;
ad3217cd 2107 aChangeSet->ToSetLineWidth = -1;
2108 aChangeSet->LineWidth = 1.0;
ac116c22 2109 aChangeSet->ToSetTypeOfLine = -1;
2110 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 2111 aChangeSet->ToSetTransparency = -1;
2112 aChangeSet->Transparency = 0.0;
2113 aChangeSet->ToSetColor = -1;
2114 aChangeSet->Color = DEFAULT_COLOR;
2115 aChangeSet->ToSetMaterial = -1;
2116 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 2117 aChangeSet->ToSetShowFreeBoundary = -1;
2118 aChangeSet->ToSetFreeBoundaryColor = -1;
2119 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2120 aChangeSet->ToSetFreeBoundaryWidth = -1;
2121 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 2122 }
5ad8c033 2123 else if (anArg == "-isoontriangulation"
2124 || anArg == "-isoontriang")
2125 {
2126 if (++anArgIter >= theArgNb)
2127 {
2128 std::cout << "Error: wrong syntax at " << anArg << "\n";
2129 return 1;
2130 }
2131 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2132 aValue.LowerCase();
2133 if (aValue == "on"
2134 || aValue == "1")
2135 {
2136 aChangeSet->ToEnableIsoOnTriangulation = 1;
2137 }
2138 else if (aValue == "off"
2139 || aValue == "0")
2140 {
2141 aChangeSet->ToEnableIsoOnTriangulation = 0;
2142 }
2143 else
2144 {
2145 std::cout << "Error: wrong syntax at " << anArg << "\n";
2146 return 1;
2147 }
2148 }
2149 else if (anArg == "-setmaxparamvalue")
2150 {
2151 if (++anArgIter >= theArgNb)
2152 {
2153 std::cout << "Error: wrong syntax at " << anArg << "\n";
2154 return 1;
2155 }
2156 aChangeSet->ToSetMaxParamValue = 1;
2157 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2158 }
8a1170ad 2159 else if (anArg == "-setsensitivity")
2160 {
2161 if (isDefaults)
2162 {
2163 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2164 return 1;
2165 }
2166
2167 if (aNames.IsEmpty())
2168 {
2169 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2170 return 1;
2171 }
2172
2173 if (anArgIter + 2 >= theArgNb)
2174 {
2175 std::cout << "Error: wrong syntax at " << anArg << "\n";
2176 return 1;
2177 }
2178 aChangeSet->ToSetSensitivity = 1;
2179 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2180 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2181 }
7fd59977 2182 else
ad3217cd 2183 {
2184 std::cout << "Error: wrong syntax at " << anArg << "\n";
2185 return 1;
2186 }
7fd59977 2187 }
99c56d44 2188
ad3217cd 2189 Standard_Boolean isFirst = Standard_True;
2190 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2191 aChangesIter.More(); aChangesIter.Next())
2192 {
2193 if (!aChangesIter.Value().Validate (!isFirst))
2194 {
2195 return 1;
2196 }
2197 isFirst = Standard_False;
99c56d44 2198 }
99c56d44 2199
ad3217cd 2200 if (aCtx->HasOpenedContext())
2201 {
2202 aCtx->CloseLocalContext();
99c56d44 2203 }
6262338c 2204
2205 // special case for -defaults parameter.
2206 // all changed values will be set to DefaultDrawer.
2207 if (isDefaults)
2208 {
2209 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2210
2211 if (aChangeSet->ToSetLineWidth != 0)
2212 {
2213 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2214 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2215 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2216 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2217 }
2218 if (aChangeSet->ToSetColor != 0)
2219 {
2220 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2221 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2222 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2223 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2224 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2225 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2226 }
ac116c22 2227 if (aChangeSet->ToSetTypeOfLine != 0)
2228 {
2229 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2230 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2231 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2232 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2233 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2234 }
6262338c 2235 if (aChangeSet->ToSetTransparency != 0)
2236 {
2237 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2238 }
2239 if (aChangeSet->ToSetMaterial != 0)
2240 {
2241 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2242 }
2243 if (aChangeSet->ToSetShowFreeBoundary == 1)
2244 {
2245 aDrawer->SetFreeBoundaryDraw (Standard_True);
2246 }
2247 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2248 {
2249 aDrawer->SetFreeBoundaryDraw (Standard_False);
2250 }
2251 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2252 {
2253 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2254 }
2255 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2256 {
2257 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2258 }
5ad8c033 2259 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2260 {
2261 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2262 }
2263 if (aChangeSet->ToSetMaxParamValue != 0)
2264 {
2265 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2266 }
6262338c 2267
2268 // redisplay all objects in context
2269 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2270 {
2271 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2272 if (!aPrs.IsNull())
2273 {
2274 aCtx->Redisplay (aPrs, Standard_False);
2275 }
2276 }
2277 return 0;
2278 }
2279
ad3217cd 2280 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2281 {
6262338c 2282 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2283 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2284 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2285 Handle(AIS_ColoredShape) aColoredPrs;
2286 Standard_Boolean toDisplay = Standard_False;
6262338c 2287 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2288 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2289 {
2290 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2291 if (aShapePrs.IsNull())
2292 {
2293 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2294 return 1;
2295 }
2296 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2297 if (aColoredPrs.IsNull())
2298 {
2299 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3e05329c 2300 if (aShapePrs->HasDisplayMode())
2301 {
2302 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2303 }
2304 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
ad3217cd 2305 aCtx->Remove (aShapePrs, Standard_False);
2306 GetMapOfAIS().UnBind2 (aName);
2307 GetMapOfAIS().Bind (aColoredPrs, aName);
2308 toDisplay = Standard_True;
2309 aShapePrs = aColoredPrs;
2310 aPrs = aColoredPrs;
2311 }
2312 }
99c56d44 2313
ad3217cd 2314 if (!aPrs.IsNull())
2315 {
2316 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2317 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2318 if (aChangeSet->ToSetVisibility == 1)
2319 {
2320 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2321 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2322 }
2323 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2324 {
2325 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2326 }
2327 else if (aChangeSet->ToSetMaterial == -1)
2328 {
2329 aCtx->UnsetMaterial (aPrs, Standard_False);
2330 }
2331 if (aChangeSet->ToSetColor == 1)
2332 {
2333 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2334 }
2335 else if (aChangeSet->ToSetColor == -1)
2336 {
2337 aCtx->UnsetColor (aPrs, Standard_False);
2338 }
2339 if (aChangeSet->ToSetTransparency == 1)
2340 {
2341 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2342 }
2343 else if (aChangeSet->ToSetTransparency == -1)
2344 {
2345 aCtx->UnsetTransparency (aPrs, Standard_False);
2346 }
2347 if (aChangeSet->ToSetLineWidth == 1)
2348 {
2349 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2350 }
2351 else if (aChangeSet->ToSetLineWidth == -1)
2352 {
2353 aCtx->UnsetWidth (aPrs, Standard_False);
2354 }
5ad8c033 2355 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2356 {
2357 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2358 toRedisplay = Standard_True;
2359 }
8a1170ad 2360 else if (aChangeSet->ToSetSensitivity != 0)
2361 {
2362 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2363 }
6262338c 2364 if (!aDrawer.IsNull())
2365 {
2366 if (aChangeSet->ToSetShowFreeBoundary == 1)
2367 {
2368 aDrawer->SetFreeBoundaryDraw (Standard_True);
2369 toRedisplay = Standard_True;
2370 }
2371 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2372 {
2373 aDrawer->SetFreeBoundaryDraw (Standard_False);
2374 toRedisplay = Standard_True;
2375 }
2376 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2377 {
2378 Handle(Prs3d_LineAspect) aBoundaryAspect =
2379 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2380 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2381 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2382 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2383 toRedisplay = Standard_True;
2384 }
2385 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2386 {
2387 Handle(Prs3d_LineAspect) aBoundaryAspect =
2388 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2389 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2390 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2391 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2392 toRedisplay = Standard_True;
2393 }
ac116c22 2394 if (aChangeSet->ToSetTypeOfLine != 0)
2395 {
2396 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2397 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2398 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2399 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2400 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2401 toRedisplay = Standard_True;
2402 }
5ad8c033 2403 if (aChangeSet->ToSetMaxParamValue != 0)
2404 {
2405 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2406 }
6262338c 2407 }
99c56d44 2408
ad3217cd 2409 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2410 {
2411 aChangeSet = &aChangesIter.ChangeValue();
2412 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2413 aSubShapeIter.More(); aSubShapeIter.Next())
2414 {
2415 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2416 if (aChangeSet->ToSetVisibility == 1)
2417 {
2418 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2419 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2420 }
ad3217cd 2421 if (aChangeSet->ToSetColor == 1)
2422 {
2423 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2424 }
2425 if (aChangeSet->ToSetLineWidth == 1)
2426 {
2427 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2428 }
2429 if (aChangeSet->ToSetColor == -1
2430 || aChangeSet->ToSetLineWidth == -1)
2431 {
2432 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2433 }
5ad8c033 2434 if (aChangeSet->ToSetMaxParamValue != 0)
2435 {
2436 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2437 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2438 }
8a1170ad 2439 if (aChangeSet->ToSetSensitivity != 0)
2440 {
2441 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2442 }
ad3217cd 2443 }
2444 }
2445 if (toDisplay)
2446 {
2447 aCtx->Display (aPrs, Standard_False);
2448 }
6262338c 2449 if (toRedisplay)
2450 {
2451 aCtx->Redisplay (aPrs, Standard_False);
2452 }
ad3217cd 2453 else if (!aColoredPrs.IsNull())
2454 {
36132a2e 2455 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2456 }
99c56d44 2457 }
ad3217cd 2458 }
99c56d44 2459 return 0;
2460}
2461
7fd59977 2462//==============================================================================
2463//function : VDonly2
2464//author : ege
2465//purpose : Display only a selected or named object
519d35d8 2466// if there is no selected or named object s, nothing is done
7fd59977 2467//==============================================================================
519d35d8 2468static int VDonly2 (Draw_Interpretor& ,
2469 Standard_Integer theArgNb,
2470 const char** theArgVec)
7fd59977 2471{
519d35d8 2472 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2473 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2474 if (aCtx.IsNull())
2475 {
2476 std::cerr << "Error: no active view!\n";
7fd59977 2477 return 1;
519d35d8 2478 }
7fd59977 2479
519d35d8 2480 if (aCtx->HasOpenedContext())
2481 {
2482 aCtx->CloseLocalContext();
2483 }
7fd59977 2484
519d35d8 2485 Standard_Integer anArgIter = 1;
2486 for (; anArgIter < theArgNb; ++anArgIter)
2487 {
4e18052b 2488 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2489 {
2490 break;
2491 }
2492 }
7fd59977 2493
519d35d8 2494 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2495 if (anArgIter >= theArgNb)
2496 {
2497 // display only selected objects
c3282ec1 2498 if (aCtx->NbSelected() < 1)
519d35d8 2499 {
2500 return 0;
7fd59977 2501 }
2502
c3282ec1 2503 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2504 {
c3282ec1 2505 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2506 }
2507 }
2508 else
2509 {
2510 // display only specified objects
2511 for (; anArgIter < theArgNb; ++anArgIter)
2512 {
2513 TCollection_AsciiString aName = theArgVec[anArgIter];
2514 if (GetMapOfAIS().IsBound2 (aName))
2515 {
d09dda09 2516 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2517 if (!aShape.IsNull())
519d35d8 2518 {
519d35d8 2519 aCtx->Display (aShape, Standard_False);
d09dda09 2520 aDispSet.Add (aShape);
519d35d8 2521 }
7fd59977 2522 }
2523 }
7fd59977 2524 }
519d35d8 2525
2526 // weed out other objects
2527 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2528 {
2529 if (aDispSet.Contains (anIter.Key1()))
2530 {
2531 continue;
2532 }
2533
d09dda09 2534 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2535 if (aShape.IsNull())
519d35d8 2536 {
519d35d8 2537 aCtx->Erase (aShape, Standard_False);
2538 }
519d35d8 2539 }
7fd59977 2540 return 0;
2541}
2542
2543//==============================================================================
eef7fc64 2544//function : VRemove
2545//purpose : Removes selected or named objects.
2546// If there is no selected or named objects,
2547// all objects in the viewer can be removed with argument -all.
2548// If -context is in arguments, the object is not deleted from the map of
2549// objects (deleted only from the current context).
2550//==============================================================================
2551int VRemove (Draw_Interpretor& theDI,
519d35d8 2552 Standard_Integer theArgNb,
2553 const char** theArgVec)
eef7fc64 2554{
4e18052b 2555 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2556 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2557 if (aCtx.IsNull())
eef7fc64 2558 {
b6d587e3 2559 std::cerr << "Error: no active view!\n";
eef7fc64 2560 return 1;
2561 }
2562
4e18052b 2563 Standard_Boolean isContextOnly = Standard_False;
2564 Standard_Boolean toRemoveAll = Standard_False;
2565 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2566 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2567
2568 Standard_Integer anArgIter = 1;
2569 for (; anArgIter < theArgNb; ++anArgIter)
2570 {
2571 TCollection_AsciiString anArg = theArgVec[anArgIter];
2572 anArg.LowerCase();
2573 if (anArg == "-context")
2574 {
2575 isContextOnly = Standard_True;
2576 }
2577 else if (anArg == "-all")
2578 {
2579 toRemoveAll = Standard_True;
2580 }
b7cd4ba7 2581 else if (anArg == "-noinfo")
2582 {
2583 toPrintInfo = Standard_False;
2584 }
b6d587e3 2585 else if (anArg == "-local")
2586 {
2587 toRemoveLocal = Standard_True;
2588 }
2589 else if (anUpdateTool.parseRedrawMode (anArg))
2590 {
2591 continue;
2592 }
2593 else
519d35d8 2594 {
2595 break;
2596 }
2597 }
2598 if (toRemoveAll
2599 && anArgIter < theArgNb)
2600 {
b6d587e3 2601 std::cerr << "Error: wrong syntax!\n";
2602 return 1;
2603 }
2604
2605 if (toRemoveLocal && !aCtx->HasOpenedContext())
2606 {
2607 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2608 return 1;
2609 }
b6d587e3 2610 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2611 {
2612 aCtx->CloseAllContexts (Standard_False);
2613 }
519d35d8 2614
eef7fc64 2615 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2616 if (toRemoveAll)
eef7fc64 2617 {
2618 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2619 anIter.More(); anIter.Next())
2620 {
2621 anIONameList.Append (anIter.Key2());
2622 }
2623 }
519d35d8 2624 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2625 {
519d35d8 2626 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2627 {
519d35d8 2628 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2629 if (!GetMapOfAIS().IsBound2 (aName))
2630 {
2631 theDI << aName.ToCString() << " was not bound to some object.\n";
2632 continue;
2633 }
2634
d09dda09 2635 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2636 if (anIO->GetContext() != aCtx)
eef7fc64 2637 {
d09dda09 2638 theDI << aName.ToCString() << " was not displayed in current context.\n";
2639 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2640 continue;
2641 }
2642
d09dda09 2643 anIONameList.Append (aName);
2644 continue;
eef7fc64 2645 }
2646 }
c3282ec1 2647 else if (aCtx->NbSelected() > 0)
eef7fc64 2648 {
2649 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2650 anIter.More(); anIter.Next())
2651 {
2652 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2653 if (!aCtx->IsSelected (anIO))
eef7fc64 2654 {
eef7fc64 2655 continue;
2656 }
2657
d09dda09 2658 anIONameList.Append (anIter.Key2());
2659 continue;
eef7fc64 2660 }
2661 }
2662
2663 // Unbind all removed objects from the map of displayed IO.
2664 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2665 anIter.More(); anIter.Next())
2666 {
519d35d8 2667 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2668 aCtx->Remove (anIO, Standard_False);
2669 if (toPrintInfo)
519d35d8 2670 {
d09dda09 2671 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2672 }
519d35d8 2673 if (!isContextOnly)
2674 {
2675 GetMapOfAIS().UnBind2 (anIter.Value());
2676 }
2677 }
b6d587e3 2678
2679 // Close local context if it is empty
2680 TColStd_MapOfTransient aLocalIO;
2681 if (aCtx->HasOpenedContext()
2682 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2683 {
2684 aCtx->CloseAllContexts (Standard_False);
2685 }
2686
eef7fc64 2687 return 0;
2688}
2689
2690//==============================================================================
b514beda 2691//function : VErase
2692//purpose : Erase some selected or named objects
7fd59977 2693// if there is no selected or named objects, the whole viewer is erased
7fd59977 2694//==============================================================================
b514beda 2695int VErase (Draw_Interpretor& theDI,
2696 Standard_Integer theArgNb,
2697 const char** theArgVec)
7fd59977 2698{
a1954302 2699 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2700 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2701 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2702 if (aCtx.IsNull())
b514beda 2703 {
b6d587e3 2704 std::cerr << "Error: no active view!\n";
7fd59977 2705 return 1;
b514beda 2706 }
519d35d8 2707
519d35d8 2708 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2709
2710 Standard_Integer anArgIter = 1;
a272ed94 2711 Standard_Boolean toEraseLocal = Standard_False;
2712 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2713 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2714 for (; anArgIter < theArgNb; ++anArgIter)
2715 {
b6d587e3 2716 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2717 anArgCase.LowerCase();
2718 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2719 {
b6d587e3 2720 continue;
2721 }
2722 else if (anArgCase == "-local")
2723 {
2724 toEraseLocal = Standard_True;
2725 }
a272ed94 2726 else if (anArgCase == "-view"
2727 || anArgCase == "-inview")
2728 {
2729 toEraseInView = Standard_True;
2730 }
b6d587e3 2731 else
2732 {
2733 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2734 }
2735 }
2736
b6d587e3 2737 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2738 {
b6d587e3 2739 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2740 return 1;
2741 }
7fd59977 2742
b6d587e3 2743 if (toEraseLocal && !aCtx->HasOpenedContext())
2744 {
2745 std::cerr << "Error: local selection context is not open.\n";
2746 return 1;
2747 }
2748 else if (!toEraseLocal && aCtx->HasOpenedContext())
2749 {
2750 aCtx->CloseAllContexts (Standard_False);
2751 }
2752
2753 if (!aNamesOfEraseIO.IsEmpty())
2754 {
2755 // Erase named objects
2756 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2757 {
b6d587e3 2758 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2759 if (!GetMapOfAIS().IsBound2 (aName))
2760 {
2761 continue;
2762 }
7fd59977 2763
b514beda 2764 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2765 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2766 theDI << aName.ToCString() << " ";
2767 if (!anIO.IsNull())
2768 {
a272ed94 2769 if (toEraseInView)
2770 {
2771 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2772 }
2773 else
2774 {
2775 aCtx->Erase (anIO, Standard_False);
2776 }
b514beda 2777 }
7fd59977 2778 }
7fd59977 2779 }
c3282ec1 2780 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2781 {
b6d587e3 2782 // Erase selected objects
671b6fe0 2783 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
b514beda 2784 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2785 anIter.More(); anIter.Next())
2786 {
2787 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2788 if (!anIO.IsNull()
c3282ec1 2789 && aCtx->IsSelected (anIO))
b514beda 2790 {
2791 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2792 if (toEraseInView)
2793 {
2794 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2795 }
671b6fe0 2796 else if (aHasOpenedContext)
a272ed94 2797 {
2798 aCtx->Erase (anIO, Standard_False);
2799 }
7fd59977 2800 }
2801 }
671b6fe0 2802
2803 if (!toEraseInView)
2804 {
2805 aCtx->EraseSelected (Standard_False);
2806 }
b514beda 2807 }
519d35d8 2808 else
b514beda 2809 {
b6d587e3 2810 // Erase all objects
519d35d8 2811 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2812 anIter.More(); anIter.Next())
b514beda 2813 {
519d35d8 2814 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2815 if (!anIO.IsNull())
2816 {
a272ed94 2817 if (toEraseInView)
2818 {
2819 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2820 }
2821 else
2822 {
2823 aCtx->Erase (anIO, Standard_False);
2824 }
519d35d8 2825 }
7fd59977 2826 }
7fd59977 2827 }
b6d587e3 2828
7fd59977 2829 return 0;
2830}
2831
7fd59977 2832//==============================================================================
2833//function : VDisplayAll
2834//author : ege
2835//purpose : Display all the objects of the Map
7fd59977 2836//==============================================================================
519d35d8 2837static int VDisplayAll (Draw_Interpretor& ,
2838 Standard_Integer theArgNb,
2839 const char** theArgVec)
7fd59977 2840
2841{
4e18052b 2842 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2843 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2844 if (aCtx.IsNull())
519d35d8 2845 {
b6d587e3 2846 std::cerr << "Error: no active view!\n";
519d35d8 2847 return 1;
2848 }
2849
519d35d8 2850 Standard_Integer anArgIter = 1;
b6d587e3 2851 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2852 for (; anArgIter < theArgNb; ++anArgIter)
2853 {
b6d587e3 2854 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2855 anArgCase.LowerCase();
2856 if (anArgCase == "-local")
2857 {
2858 toDisplayLocal = Standard_True;
2859 }
2860 else if (anUpdateTool.parseRedrawMode (anArgCase))
2861 {
2862 continue;
2863 }
2864 else
519d35d8 2865 {
2866 break;
7fd59977 2867 }
519d35d8 2868 }
2869 if (anArgIter < theArgNb)
2870 {
2871 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2872 return 1;
2873 }
2874
b6d587e3 2875 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2876 {
b6d587e3 2877 std::cerr << "Error: local selection context is not open.\n";
2878 return 1;
2879 }
2880 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2881 {
2882 aCtx->CloseLocalContext (Standard_False);
519d35d8 2883 }
2884
2885 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2886 anIter.More(); anIter.Next())
2887 {
d09dda09 2888 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2889 aCtx->Erase (aShape, Standard_False);
519d35d8 2890 }
2891
2892 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2893 anIter.More(); anIter.Next())
2894 {
d09dda09 2895 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2896 aCtx->Display (aShape, Standard_False);
7fd59977 2897 }
2898 return 0;
2899}
2900
c2a388f8 2901//! Auxiliary method to find presentation
2902inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2903 const Handle(AIS_InteractiveObject)& theIO,
2904 const Standard_Integer theMode)
2905{
2906 if (theIO.IsNull())
2907 {
2908 return Handle(PrsMgr_Presentation)();
2909 }
2910
2911 if (theMode != -1)
2912 {
2913 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2914 {
2915 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2916 }
2917 }
2918 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2919 {
2920 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2921 }
2922 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2923 {
2924 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2925 }
2926 return Handle(PrsMgr_Presentation)();
2927}
2928
2929enum ViewerTest_BndAction
2930{
2931 BndAction_Hide,
2932 BndAction_Show,
2933 BndAction_Print
2934};
2935
2936//! Auxiliary method to print bounding box of presentation
2937inline void bndPresentation (Draw_Interpretor& theDI,
2938 const Handle(PrsMgr_Presentation)& thePrs,
2939 const TCollection_AsciiString& theName,
2940 const ViewerTest_BndAction theAction)
2941{
2942 switch (theAction)
2943 {
2944 case BndAction_Hide:
2945 {
2946 thePrs->Presentation()->GraphicUnHighlight();
2947 break;
2948 }
2949 case BndAction_Show:
2950 {
5b111128 2951 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
b6472664 2952 aPrs->CStructure()->HighlightColor = Quantity_NOC_GRAY99;
a1954302 2953 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2954 break;
2955 }
2956 case BndAction_Print:
2957 {
ed063270 2958 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2959 gp_Pnt aMin = aBox.CornerMin();
2960 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2961 theDI << theName << "\n"
ed063270 2962 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2963 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2964 break;
2965 }
2966 }
2967}
2968
2969//==============================================================================
2970//function : VBounding
2971//purpose :
2972//==============================================================================
2973int VBounding (Draw_Interpretor& theDI,
2974 Standard_Integer theArgNb,
2975 const char** theArgVec)
2976{
2977 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2978 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2979 if (aCtx.IsNull())
2980 {
2981 std::cout << "Error: no active view!\n";
2982 return 1;
2983 }
2984
4e18052b 2985 ViewerTest_BndAction anAction = BndAction_Show;
2986 Standard_Integer aMode = -1;
c2a388f8 2987
2988 Standard_Integer anArgIter = 1;
2989 for (; anArgIter < theArgNb; ++anArgIter)
2990 {
2991 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2992 anArg.LowerCase();
2993 if (anArg == "-print")
2994 {
2995 anAction = BndAction_Print;
2996 }
2997 else if (anArg == "-show")
2998 {
2999 anAction = BndAction_Show;
3000 }
3001 else if (anArg == "-hide")
3002 {
3003 anAction = BndAction_Hide;
3004 }
3005 else if (anArg == "-mode")
3006 {
3007 if (++anArgIter >= theArgNb)
3008 {
3009 std::cout << "Error: wrong syntax at " << anArg << "\n";
3010 return 1;
3011 }
3012 aMode = Draw::Atoi (theArgVec[anArgIter]);
3013 }
4e18052b 3014 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3015 {
3016 break;
3017 }
3018 }
3019
3020 if (anArgIter < theArgNb)
3021 {
3022 // has a list of names
3023 for (; anArgIter < theArgNb; ++anArgIter)
3024 {
3025 TCollection_AsciiString aName = theArgVec[anArgIter];
3026 if (!GetMapOfAIS().IsBound2 (aName))
3027 {
3028 std::cout << "Error: presentation " << aName << " does not exist\n";
3029 return 1;
3030 }
3031
3032 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3033 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3034 if (aPrs.IsNull())
3035 {
3036 std::cout << "Error: presentation " << aName << " does not exist\n";
3037 return 1;
3038 }
3039 bndPresentation (theDI, aPrs, aName, anAction);
3040 }
3041 }
c3282ec1 3042 else if (aCtx->NbSelected() > 0)
c2a388f8 3043 {
3044 // remove all currently selected objects
c3282ec1 3045 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3046 {
c3282ec1 3047 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
c2a388f8 3048 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3049 if (!aPrs.IsNull())
3050 {
3051 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3052 }
3053 }
3054 }
3055 else
3056 {
3057 // all objects
3058 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3059 anIter.More(); anIter.Next())
3060 {
3061 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3062 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3063 if (!aPrs.IsNull())
3064 {
3065 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3066 }
3067 }
3068 }
c2a388f8 3069 return 0;
3070}
3071
d399d3c3 3072//==============================================================================
3073//function : VTexture
3074//purpose :
3075//==============================================================================
3076Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3077{
d399d3c3 3078 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3079
900f7229 3080 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3081 if (aCommandName == "vtexture")
3082 {
3083 if (theArgsNb < 2)
7fd59977 3084 {
586db386 3085 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3086 std::cout << "Type help for more information.\n";
31160f80 3087 return 1;
7fd59977 3088 }
3089
d399d3c3 3090 // look for options of vtexture command
3091 TCollection_AsciiString aParseKey;
3092 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3093 {
3094 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3095
d399d3c3 3096 anArg.UpperCase();
3097 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3098 {
3099 aParseKey = anArg;
3100 aParseKey.Remove (1);
3101 aParseKey.UpperCase();
900f7229 3102 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3103 continue;
3104 }
3105
3106 if (aParseKey.IsEmpty())
3107 {
3108 continue;
3109 }
3110
900f7229 3111 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3112 }
3113 }
3114 else if (aCommandName == "vtexscale"
3115 || aCommandName == "vtexorigin"
3116 || aCommandName == "vtexrepeat")
3117 {
3118 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3119 // equal to -scale, -origin, -repeat options of vtexture command
3120 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3121 {
586db386 3122 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3123 std::cout << "Type help for more information.\n";
31160f80 3124 return 1;
7fd59977 3125 }
3126
900f7229 3127 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3128 if (theArgsNb == 2)
3129 {
900f7229 3130 anArgs->Append ("OFF");
d399d3c3 3131 }
3132 else if (theArgsNb == 4)
3133 {
900f7229 3134 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3135 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3136 }
7fd59977 3137
d399d3c3 3138 TCollection_AsciiString anArgKey;
3139 if (aCommandName == "vtexscale")
3140 {
3141 anArgKey = "SCALE";
3142 }
3143 else if (aCommandName == "vtexorigin")
3144 {
3145 anArgKey = "ORIGIN";
3146 }
3147 else
3148 {
3149 anArgKey = "REPEAT";
3150 }
3151
3152 aMapOfArgs.Bind (anArgKey, anArgs);
3153 }
3154 else if (aCommandName == "vtexdefault")
7fd59977 3155 {
d399d3c3 3156 // scan for parameters of vtexdefault command
3157 // equal to -default option of vtexture command
900f7229 3158 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3159 }
3160
d399d3c3 3161 // Check arguments for validity
900f7229 3162 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3163 for (; aMapIt.More(); aMapIt.Next())
3164 {
3165 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3166 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3167
3168 // -scale, -origin, -repeat: one argument "off", or two real values
3169 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3170 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3171 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3172 {
d399d3c3 3173 continue;
7fd59977 3174 }
d399d3c3 3175
3176 // -modulate: single argument "on" / "off"
900f7229 3177 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3178 {
3179 continue;
3180 }
3181
3182 // -default: no arguments
900f7229 3183 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3184 {
3185 continue;
3186 }
3187
3188 TCollection_AsciiString aLowerKey;
3189 aLowerKey = "-";
3190 aLowerKey += aKey;
3191 aLowerKey.LowerCase();
3192 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3193 std::cout << "Type help for more information.\n";
3194 return 1;
3195 }
3196
3197 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3198 if (anAISContext.IsNull())
3199 {
586db386 3200 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
d399d3c3 3201 return 1;
3202 }
3203
3204 Standard_Integer aPreviousMode = 0;
3205
d399d3c3 3206 TCollection_AsciiString aShapeName (theArgv[1]);
3207 Handle(AIS_InteractiveObject) anIO;
3208
3209 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3210 if (aMapOfIO.IsBound2 (aShapeName))
3211 {
3212 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3213 }
3214
3215 if (anIO.IsNull())
3216 {
3217 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3218 return 1;
3219 }
3220
3221 Handle(AIS_TexturedShape) aTexturedIO;
3222 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3223 {
3224 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3225 aPreviousMode = aTexturedIO->DisplayMode();
3226 }
7fd59977 3227 else
d399d3c3 3228 {
d399d3c3 3229 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
16420da1 3230
3231 if (anIO->HasTransformation())
3232 {
3233 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3234 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3235 }
3236
3237 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3238 GetMapOfAIS().UnBind1 (anIO);
3239 GetMapOfAIS().UnBind2 (aShapeName);
3240 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3241 }
3242
3243 // -------------------------------------------
3244 // Turn texturing on/off - only for vtexture
3245 // -------------------------------------------
3246
3247 if (aCommandName == "vtexture")
3248 {
3249 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3250
3251 if (aTextureArg.IsEmpty())
7fd59977 3252 {
586db386 3253 std::cout << aCommandName << ": Texture mapping disabled.\n";
3254 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
d399d3c3 3255
3256 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3257 if (aPreviousMode == 3)
3258 {
3259 anAISContext->RecomputePrsOnly (aTexturedIO);
3260 }
3261
3262 anAISContext->Display (aTexturedIO, Standard_True);
3263 return 0;
7fd59977 3264 }
d399d3c3 3265 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3266 {
d399d3c3 3267 if (aTextureArg == "?")
3268 {
3269 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3270
586db386 3271 theDi << "\n Files in current directory : \n\n";
d399d3c3 3272 theDi.Eval ("glob -nocomplain *");
7fd59977 3273
d399d3c3 3274 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3275 aCmnd += aTextureFolder;
3276 aCmnd += "/* ";
7fd59977 3277
586db386 3278 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
d399d3c3 3279 theDi.Eval (aCmnd.ToCString());
3280 return 0;
3281 }
3282 else
3283 {
3284 aTexturedIO->SetTextureFileName (aTextureArg);
3285 }
3286 }
3287 }
7fd59977 3288
d399d3c3 3289 // ------------------------------------
3290 // Process other options and commands
3291 // ------------------------------------
7fd59977 3292
900f7229 3293 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3294 if (aMapOfArgs.Find ("DEFAULT", aValues))
3295 {
3296 aTexturedIO->SetTextureRepeat (Standard_False);
3297 aTexturedIO->SetTextureOrigin (Standard_False);
3298 aTexturedIO->SetTextureScale (Standard_False);
3299 aTexturedIO->EnableTextureModulate();
3300 }
3301 else
3302 {
3303 if (aMapOfArgs.Find ("SCALE", aValues))
3304 {
900f7229 3305 if (aValues->Value(1) != "OFF")
d399d3c3 3306 {
900f7229 3307 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3308 }
7fd59977 3309 else
d399d3c3 3310 {
3311 aTexturedIO->SetTextureScale (Standard_False);
3312 }
3313 }
7fd59977 3314
d399d3c3 3315 if (aMapOfArgs.Find ("ORIGIN", aValues))
3316 {
900f7229 3317 if (aValues->Value(1) != "OFF")
d399d3c3 3318 {
900f7229 3319 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3320 }
3321 else
3322 {
3323 aTexturedIO->SetTextureOrigin (Standard_False);
3324 }
3325 }
7fd59977 3326
d399d3c3 3327 if (aMapOfArgs.Find ("REPEAT", aValues))
3328 {
900f7229 3329 if (aValues->Value(1) != "OFF")
d399d3c3 3330 {
900f7229 3331 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3332 }
3333 else
3334 {
3335 aTexturedIO->SetTextureRepeat (Standard_False);
3336 }
7fd59977 3337 }
3338
d399d3c3 3339 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3340 {
900f7229 3341 if (aValues->Value(1) == "ON")
d399d3c3 3342 {
3343 aTexturedIO->EnableTextureModulate();
3344 }
3345 else
3346 {
3347 aTexturedIO->DisableTextureModulate();
3348 }
7fd59977 3349 }
d399d3c3 3350 }
3351
3352 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3353 {
3354 anAISContext->RecomputePrsOnly (aTexturedIO);
3355 }
3356 else
3357 {
3358 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3359 anAISContext->Display (aTexturedIO, Standard_True);
3360 anAISContext->Update (aTexturedIO,Standard_True);
3361 }
3362
31160f80 3363 return 0;
7fd59977 3364}
3365
af65fb19 3366//! Auxiliary method to parse transformation persistence flags
3367inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3368 Standard_Integer& theFlags)
3369{
3370 if (theFlagString == "pan")
3371 {
3372 theFlags |= Graphic3d_TMF_PanPers;
3373 }
3374 else if (theFlagString == "zoom")
3375 {
3376 theFlags |= Graphic3d_TMF_ZoomPers;
3377 }
3378 else if (theFlagString == "rotate")
3379 {
3380 theFlags |= Graphic3d_TMF_RotatePers;
3381 }
3382 else if (theFlagString == "trihedron")
3383 {
3384 theFlags = Graphic3d_TMF_TriedronPers;
3385 }
3386 else if (theFlagString == "full")
3387 {
3388 theFlags = Graphic3d_TMF_FullPers;
3389 }
3390 else if (theFlagString == "none")
3391 {
3392 theFlags = Graphic3d_TMF_None;
3393 }
3394 else
3395 {
3396 return Standard_False;
3397 }
3398
3399 return Standard_True;
3400}
3401
7fd59977 3402//==============================================================================
3403//function : VDisplay2
3404//author : ege
3405//purpose : Display an object from its name
7fd59977 3406//==============================================================================
519d35d8 3407static int VDisplay2 (Draw_Interpretor& theDI,
3408 Standard_Integer theArgNb,
3409 const char** theArgVec)
7fd59977 3410{
519d35d8 3411 if (theArgNb < 2)
3412 {
b6d587e3 3413 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3414 return 1;
3415 }
b6d587e3 3416
3417 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3418 if (aCtx.IsNull())
519d35d8 3419 {
7fd59977 3420 ViewerTest::ViewerInit();
4e18052b 3421 aCtx = ViewerTest::GetAISContext();
7fd59977 3422 }
3423
b6d587e3 3424 // Parse input arguments
4e18052b 3425 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3426 Standard_Integer isMutable = -1;
3427 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3428 Standard_Boolean toDisplayLocal = Standard_False;
3429 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3430 Standard_Integer isSelectable = -1;
3431 Standard_Integer anObjDispMode = -2;
3432 Standard_Integer anObjHighMode = -2;
3433 Standard_Boolean toSetTrsfPers = Standard_False;
3434 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3435 gp_Pnt aTPPosition;
b6d587e3 3436 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3437 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94