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