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