0028175: Bad result of curve-curve extrema
[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
640d5fe2 1481 Standard_Integer ToSetHatch;
1482 Standard_Integer StdHatchStyle;
1483 TCollection_AsciiString PathToHatchPattern;
1484
ad3217cd 1485 //! Empty constructor
1486 ViewerTest_AspectsChangeSet()
5bffb882 1487 : ToSetVisibility (0),
1488 Visibility (1),
1489 ToSetColor (0),
ad3217cd 1490 Color (DEFAULT_COLOR),
1491 ToSetLineWidth (0),
1492 LineWidth (1.0),
ac116c22 1493 ToSetTypeOfLine (0),
1494 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1495 ToSetTransparency (0),
1496 Transparency (0.0),
1497 ToSetMaterial (0),
6262338c 1498 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1499 ToSetShowFreeBoundary (0),
1500 ToSetFreeBoundaryWidth (0),
1501 FreeBoundaryWidth (1.0),
1502 ToSetFreeBoundaryColor (0),
1503 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1504 ToEnableIsoOnTriangulation (-1),
1505 ToSetMaxParamValue (0),
8a1170ad 1506 MaxParamValue (500000),
1507 ToSetSensitivity (0),
1508 SelectionMode (-1),
640d5fe2 1509 Sensitivity (-1),
1510 ToSetHatch (0),
1511 StdHatchStyle (-1)
1512 {}
ad3217cd 1513
1514 //! @return true if no changes have been requested
1515 Standard_Boolean IsEmpty() const
1516 {
6262338c 1517 return ToSetVisibility == 0
1518 && ToSetLineWidth == 0
1519 && ToSetTransparency == 0
1520 && ToSetColor == 0
1521 && ToSetMaterial == 0
1522 && ToSetShowFreeBoundary == 0
1523 && ToSetFreeBoundaryColor == 0
5ad8c033 1524 && ToSetFreeBoundaryWidth == 0
8a1170ad 1525 && ToSetMaxParamValue == 0
640d5fe2 1526 && ToSetSensitivity == 0
1527 && ToSetHatch == 0;
ad3217cd 1528 }
1529
1530 //! @return true if properties are valid
1531 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1532 {
1533 Standard_Boolean isOk = Standard_True;
5bffb882 1534 if (Visibility != 0 && Visibility != 1)
1535 {
1536 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1537 isOk = Standard_False;
1538 }
ad3217cd 1539 if (LineWidth <= 0.0
1540 || LineWidth > 10.0)
1541 {
1542 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1543 isOk = Standard_False;
7fd59977 1544 }
ad3217cd 1545 if (Transparency < 0.0
1546 || Transparency > 1.0)
1547 {
1548 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1549 isOk = Standard_False;
1550 }
1551 if (theIsSubPart
1552 && ToSetTransparency)
1553 {
1554 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1555 isOk = Standard_False;
7fd59977 1556 }
ad3217cd 1557 if (ToSetMaterial == 1
1558 && Material == Graphic3d_NOM_DEFAULT)
1559 {
1560 std::cout << "Error: unknown material " << MatName << ".\n";
1561 isOk = Standard_False;
1562 }
6262338c 1563 if (FreeBoundaryWidth <= 0.0
1564 || FreeBoundaryWidth > 10.0)
1565 {
1566 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1567 isOk = Standard_False;
1568 }
5ad8c033 1569 if (MaxParamValue < 0.0)
1570 {
1571 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1572 isOk = Standard_False;
1573 }
8a1170ad 1574 if (Sensitivity <= 0 && ToSetSensitivity)
1575 {
1576 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1577 isOk = Standard_False;
1578 }
640d5fe2 1579 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1580 {
1581 std::cout << "Error: hatch style must be specified\n";
1582 isOk = Standard_False;
1583 }
ad3217cd 1584 return isOk;
7fd59977 1585 }
7fd59977 1586
ad3217cd 1587};
7fd59977 1588
1589//==============================================================================
ad3217cd 1590//function : VAspects
1591//purpose :
7fd59977 1592//==============================================================================
ad3217cd 1593static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1594 Standard_Integer theArgNb,
1595 const char** theArgVec)
7fd59977 1596{
ad3217cd 1597 TCollection_AsciiString aCmdName (theArgVec[0]);
1598 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1599 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1600 if (aCtx.IsNull())
1601 {
1602 std::cerr << "Error: no active view!\n";
1603 return 1;
1604 }
7fd59977 1605
4e18052b 1606 Standard_Integer anArgIter = 1;
6262338c 1607 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1608 NCollection_Sequence<TCollection_AsciiString> aNames;
1609 for (; anArgIter < theArgNb; ++anArgIter)
1610 {
1611 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1612 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1613 {
1614 continue;
1615 }
1616 else if (!anArg.IsEmpty()
1617 && anArg.Value (1) != '-')
1618 {
1619 aNames.Append (anArg);
1620 }
1621 else
1622 {
6262338c 1623 if (anArg == "-defaults")
1624 {
1625 isDefaults = Standard_True;
1626 ++anArgIter;
1627 }
ad3217cd 1628 break;
1629 }
1630 }
1631
6262338c 1632 if (!aNames.IsEmpty() && isDefaults)
1633 {
1634 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1635 return 1;
1636 }
1637
ad3217cd 1638 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1639 aChanges.Append (ViewerTest_AspectsChangeSet());
1640 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1641
ad3217cd 1642 // parse syntax of legacy commands
1643 if (aCmdName == "vsetwidth")
1644 {
1645 if (aNames.IsEmpty()
1646 || !aNames.Last().IsRealValue())
1647 {
1648 std::cout << "Error: not enough arguments!\n";
1649 return 1;
1650 }
1651 aChangeSet->ToSetLineWidth = 1;
1652 aChangeSet->LineWidth = aNames.Last().RealValue();
1653 aNames.Remove (aNames.Length());
7fd59977 1654 }
ad3217cd 1655 else if (aCmdName == "vunsetwidth")
1656 {
1657 aChangeSet->ToSetLineWidth = -1;
1658 }
1659 else if (aCmdName == "vsetcolor")
1660 {
1661 if (aNames.IsEmpty())
1662 {
1663 std::cout << "Error: not enough arguments!\n";
1664 return 1;
1665 }
1666 aChangeSet->ToSetColor = 1;
8316c618 1667
1668 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1669 Standard_Boolean isOk = Standard_False;
1670 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1671 {
1672 aChangeSet->Color = aColor;
1673 aNames.Remove (aNames.Length());
1674 isOk = Standard_True;
1675 }
1676 else if (aNames.Length() >= 3)
1677 {
1678 const TCollection_AsciiString anRgbStr[3] =
1679 {
1680 aNames.Value (aNames.Upper() - 2),
1681 aNames.Value (aNames.Upper() - 1),
1682 aNames.Value (aNames.Upper() - 0)
1683 };
1684 isOk = anRgbStr[0].IsRealValue()
1685 && anRgbStr[1].IsRealValue()
1686 && anRgbStr[2].IsRealValue();
1687 if (isOk)
1688 {
1689 Graphic3d_Vec4d anRgb;
1690 anRgb.x() = anRgbStr[0].RealValue();
1691 anRgb.y() = anRgbStr[1].RealValue();
1692 anRgb.z() = anRgbStr[2].RealValue();
1693 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1694 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1695 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1696 {
1697 std::cout << "Error: RGB color values should be within range 0..1!\n";
1698 return 1;
1699 }
1700 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1701 aNames.Remove (aNames.Length());
1702 aNames.Remove (aNames.Length());
1703 aNames.Remove (aNames.Length());
1704 }
1705 }
1706 if (!isOk)
1707 {
1708 std::cout << "Error: not enough arguments!\n";
1709 return 1;
1710 }
ad3217cd 1711 }
1712 else if (aCmdName == "vunsetcolor")
1713 {
1714 aChangeSet->ToSetColor = -1;
1715 }
1716 else if (aCmdName == "vsettransparency")
1717 {
1718 if (aNames.IsEmpty()
1719 || !aNames.Last().IsRealValue())
1720 {
1721 std::cout << "Error: not enough arguments!\n";
1722 return 1;
1723 }
1724 aChangeSet->ToSetTransparency = 1;
1725 aChangeSet->Transparency = aNames.Last().RealValue();
1726 aNames.Remove (aNames.Length());
1727 }
1728 else if (aCmdName == "vunsettransparency")
1729 {
1730 aChangeSet->ToSetTransparency = -1;
1731 }
1732 else if (aCmdName == "vsetmaterial")
1733 {
1734 if (aNames.IsEmpty())
1735 {
1736 std::cout << "Error: not enough arguments!\n";
1737 return 1;
1738 }
1739 aChangeSet->ToSetMaterial = 1;
1740 aChangeSet->MatName = aNames.Last();
1741 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1742 aNames.Remove (aNames.Length());
1743 }
1744 else if (aCmdName == "vunsetmaterial")
1745 {
1746 aChangeSet->ToSetMaterial = -1;
1747 }
1748 else if (anArgIter >= theArgNb)
1749 {
1750 std::cout << "Error: not enough arguments!\n";
1751 return 1;
7fd59977 1752 }
1753
ad3217cd 1754 if (!aChangeSet->IsEmpty())
1755 {
1756 anArgIter = theArgNb;
1757 }
1758 for (; anArgIter < theArgNb; ++anArgIter)
1759 {
1760 TCollection_AsciiString anArg = theArgVec[anArgIter];
1761 anArg.LowerCase();
1762 if (anArg == "-setwidth"
1763 || anArg == "-setlinewidth")
1764 {
1765 if (++anArgIter >= theArgNb)
1766 {
1767 std::cout << "Error: wrong syntax at " << anArg << "\n";
1768 return 1;
1769 }
1770 aChangeSet->ToSetLineWidth = 1;
1771 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1772 }
ad3217cd 1773 else if (anArg == "-unsetwidth"
1774 || anArg == "-unsetlinewidth")
1775 {
1776 aChangeSet->ToSetLineWidth = -1;
1777 aChangeSet->LineWidth = 1.0;
1778 }
1779 else if (anArg == "-settransp"
0ae61cf3 1780 || anArg == "-settransparency")
ad3217cd 1781 {
1782 if (++anArgIter >= theArgNb)
1783 {
1784 std::cout << "Error: wrong syntax at " << anArg << "\n";
1785 return 1;
1786 }
1787 aChangeSet->ToSetTransparency = 1;
1788 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1789 if (aChangeSet->Transparency >= 0.0
1790 && aChangeSet->Transparency <= Precision::Confusion())
1791 {
1792 aChangeSet->ToSetTransparency = -1;
1793 aChangeSet->Transparency = 0.0;
eafb234b 1794 }
7fd59977 1795 }
5bffb882 1796 else if (anArg == "-setvis"
1797 || anArg == "-setvisibility")
1798 {
1799 if (++anArgIter >= theArgNb)
1800 {
1801 std::cout << "Error: wrong syntax at " << anArg << "\n";
1802 return 1;
1803 }
1804
1805 aChangeSet->ToSetVisibility = 1;
1806 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1807 }
ad3217cd 1808 else if (anArg == "-setalpha")
1809 {
1810 if (++anArgIter >= theArgNb)
7fd59977 1811 {
ad3217cd 1812 std::cout << "Error: wrong syntax at " << anArg << "\n";
1813 return 1;
1814 }
1815 aChangeSet->ToSetTransparency = 1;
1816 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1817 if (aChangeSet->Transparency < 0.0
1818 || aChangeSet->Transparency > 1.0)
1819 {
1820 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1821 return 1;
1822 }
1823 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1824 if (aChangeSet->Transparency >= 0.0
1825 && aChangeSet->Transparency <= Precision::Confusion())
1826 {
1827 aChangeSet->ToSetTransparency = -1;
1828 aChangeSet->Transparency = 0.0;
7fd59977 1829 }
7fd59977 1830 }
ad3217cd 1831 else if (anArg == "-unsettransp"
0ae61cf3 1832 || anArg == "-unsettransparency"
ad3217cd 1833 || anArg == "-unsetalpha"
1834 || anArg == "-opaque")
1835 {
1836 aChangeSet->ToSetTransparency = -1;
1837 aChangeSet->Transparency = 0.0;
1838 }
1839 else if (anArg == "-setcolor")
1840 {
8316c618 1841 Standard_Integer aNbComps = 0;
1842 Standard_Integer aCompIter = anArgIter + 1;
1843 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1844 {
8316c618 1845 if (theArgVec[aCompIter][0] == '-')
1846 {
1847 break;
1848 }
1849 }
1850 switch (aNbComps)
1851 {
1852 case 1:
1853 {
1854 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1855 Standard_CString aName = theArgVec[anArgIter + 1];
1856 if (!Quantity_Color::ColorFromName (aName, aColor))
1857 {
1858 std::cout << "Error: unknown color name '" << aName << "'\n";
1859 return 1;
1860 }
1861 aChangeSet->Color = aColor;
1862 break;
1863 }
1864 case 3:
1865 {
1866 Graphic3d_Vec3d anRgb;
1867 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1868 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1869 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1870 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1871 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1872 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1873 {
1874 std::cout << "Error: RGB color values should be within range 0..1!\n";
1875 return 1;
1876 }
1877 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1878 break;
1879 }
1880 default:
1881 {
1882 std::cout << "Error: wrong syntax at " << anArg << "\n";
1883 return 1;
1884 }
7fd59977 1885 }
ad3217cd 1886 aChangeSet->ToSetColor = 1;
8316c618 1887 anArgIter += aNbComps;
7fd59977 1888 }
ac116c22 1889 else if (anArg == "-setlinetype")
1890 {
1891 if (++anArgIter >= theArgNb)
1892 {
1893 std::cout << "Error: wrong syntax at " << anArg << "\n";
1894 return 1;
1895 }
1896
1897 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1898 aValue.LowerCase();
1899
1900 if (aValue.IsEqual ("solid"))
1901 {
1902 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1903 }
1904 else if (aValue.IsEqual ("dot"))
1905 {
1906 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1907 }
1908 else if (aValue.IsEqual ("dash"))
1909 {
1910 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1911 }
1912 else if (aValue.IsEqual ("dotdash"))
1913 {
1914 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1915 }
1916 else
1917 {
1918 std::cout << "Error: wrong syntax at " << anArg << "\n";
1919 return 1;
1920 }
1921
1922 aChangeSet->ToSetTypeOfLine = 1;
1923 }
1924 else if (anArg == "-unsetlinetype")
1925 {
1926 aChangeSet->ToSetTypeOfLine = -1;
1927 }
ad3217cd 1928 else if (anArg == "-unsetcolor")
1929 {
1930 aChangeSet->ToSetColor = -1;
1931 aChangeSet->Color = DEFAULT_COLOR;
1932 }
1933 else if (anArg == "-setmat"
1934 || anArg == "-setmaterial")
1935 {
1936 if (++anArgIter >= theArgNb)
1937 {
1938 std::cout << "Error: wrong syntax at " << anArg << "\n";
1939 return 1;
1940 }
1941 aChangeSet->ToSetMaterial = 1;
1942 aChangeSet->MatName = theArgVec[anArgIter];
1943 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1944 }
1945 else if (anArg == "-unsetmat"
1946 || anArg == "-unsetmaterial")
1947 {
1948 aChangeSet->ToSetMaterial = -1;
1949 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1950 }
1951 else if (anArg == "-subshape"
1952 || anArg == "-subshapes")
1953 {
6262338c 1954 if (isDefaults)
1955 {
1956 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1957 return 1;
1958 }
1959
ad3217cd 1960 if (aNames.IsEmpty())
1961 {
1962 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1963 return 1;
1964 }
7fd59977 1965
ad3217cd 1966 aChanges.Append (ViewerTest_AspectsChangeSet());
1967 aChangeSet = &aChanges.ChangeLast();
7fd59977 1968
ad3217cd 1969 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1970 {
1971 Standard_CString aSubShapeName = theArgVec[anArgIter];
1972 if (*aSubShapeName == '-')
1973 {
1974 --anArgIter;
1975 break;
1976 }
7fd59977 1977
ad3217cd 1978 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1979 if (aSubShape.IsNull())
1980 {
1981 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1982 return 1;
1983 }
1984 aChangeSet->SubShapes.Append (aSubShape);
1985 }
7fd59977 1986
ad3217cd 1987 if (aChangeSet->SubShapes.IsEmpty())
1988 {
1989 std::cerr << "Error: empty list is specified after -subshapes!\n";
1990 return 1;
1991 }
1992 }
6262338c 1993 else if (anArg == "-freeboundary"
1994 || anArg == "-fb")
1995 {
1996 if (++anArgIter >= theArgNb)
1997 {
1998 std::cout << "Error: wrong syntax at " << anArg << "\n";
1999 return 1;
2000 }
2001 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2002 aValue.LowerCase();
2003 if (aValue == "on"
2004 || aValue == "1")
2005 {
2006 aChangeSet->ToSetShowFreeBoundary = 1;
2007 }
2008 else if (aValue == "off"
2009 || aValue == "0")
2010 {
2011 aChangeSet->ToSetShowFreeBoundary = -1;
2012 }
2013 else
2014 {
2015 std::cout << "Error: wrong syntax at " << anArg << "\n";
2016 return 1;
2017 }
2018 }
2019 else if (anArg == "-setfreeboundarywidth"
2020 || anArg == "-setfbwidth")
2021 {
2022 if (++anArgIter >= theArgNb)
2023 {
2024 std::cout << "Error: wrong syntax at " << anArg << "\n";
2025 return 1;
2026 }
2027 aChangeSet->ToSetFreeBoundaryWidth = 1;
2028 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2029 }
2030 else if (anArg == "-unsetfreeboundarywidth"
2031 || anArg == "-unsetfbwidth")
2032 {
2033 aChangeSet->ToSetFreeBoundaryWidth = -1;
2034 aChangeSet->FreeBoundaryWidth = 1.0;
2035 }
2036 else if (anArg == "-setfreeboundarycolor"
2037 || anArg == "-setfbcolor")
2038 {
2039 Standard_Integer aNbComps = 0;
2040 Standard_Integer aCompIter = anArgIter + 1;
2041 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2042 {
2043 if (theArgVec[aCompIter][0] == '-')
2044 {
2045 break;
2046 }
2047 }
2048 switch (aNbComps)
2049 {
2050 case 1:
2051 {
2052 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2053 Standard_CString aName = theArgVec[anArgIter + 1];
2054 if (!Quantity_Color::ColorFromName (aName, aColor))
2055 {
2056 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2057 return 1;
2058 }
2059 aChangeSet->FreeBoundaryColor = aColor;
2060 break;
2061 }
2062 case 3:
2063 {
2064 Graphic3d_Vec3d anRgb;
2065 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2066 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2067 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2068 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2069 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2070 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2071 {
2072 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2073 return 1;
2074 }
2075 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2076 break;
2077 }
2078 default:
2079 {
2080 std::cout << "Error: wrong syntax at " << anArg << "\n";
2081 return 1;
2082 }
2083 }
2084 aChangeSet->ToSetFreeBoundaryColor = 1;
2085 anArgIter += aNbComps;
2086 }
2087 else if (anArg == "-unsetfreeboundarycolor"
2088 || anArg == "-unsetfbcolor")
2089 {
2090 aChangeSet->ToSetFreeBoundaryColor = -1;
2091 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2092 }
ad3217cd 2093 else if (anArg == "-unset")
2094 {
5bffb882 2095 aChangeSet->ToSetVisibility = 1;
2096 aChangeSet->Visibility = 1;
ad3217cd 2097 aChangeSet->ToSetLineWidth = -1;
2098 aChangeSet->LineWidth = 1.0;
ac116c22 2099 aChangeSet->ToSetTypeOfLine = -1;
2100 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 2101 aChangeSet->ToSetTransparency = -1;
2102 aChangeSet->Transparency = 0.0;
2103 aChangeSet->ToSetColor = -1;
2104 aChangeSet->Color = DEFAULT_COLOR;
2105 aChangeSet->ToSetMaterial = -1;
2106 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 2107 aChangeSet->ToSetShowFreeBoundary = -1;
2108 aChangeSet->ToSetFreeBoundaryColor = -1;
2109 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2110 aChangeSet->ToSetFreeBoundaryWidth = -1;
2111 aChangeSet->FreeBoundaryWidth = 1.0;
640d5fe2 2112 aChangeSet->ToSetHatch = -1;
2113 aChangeSet->StdHatchStyle = -1;
2114 aChangeSet->PathToHatchPattern.Clear();
7fd59977 2115 }
5ad8c033 2116 else if (anArg == "-isoontriangulation"
2117 || anArg == "-isoontriang")
2118 {
2119 if (++anArgIter >= theArgNb)
2120 {
2121 std::cout << "Error: wrong syntax at " << anArg << "\n";
2122 return 1;
2123 }
2124 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2125 aValue.LowerCase();
2126 if (aValue == "on"
2127 || aValue == "1")
2128 {
2129 aChangeSet->ToEnableIsoOnTriangulation = 1;
2130 }
2131 else if (aValue == "off"
2132 || aValue == "0")
2133 {
2134 aChangeSet->ToEnableIsoOnTriangulation = 0;
2135 }
2136 else
2137 {
2138 std::cout << "Error: wrong syntax at " << anArg << "\n";
2139 return 1;
2140 }
2141 }
2142 else if (anArg == "-setmaxparamvalue")
2143 {
2144 if (++anArgIter >= theArgNb)
2145 {
2146 std::cout << "Error: wrong syntax at " << anArg << "\n";
2147 return 1;
2148 }
2149 aChangeSet->ToSetMaxParamValue = 1;
2150 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2151 }
8a1170ad 2152 else if (anArg == "-setsensitivity")
2153 {
2154 if (isDefaults)
2155 {
2156 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2157 return 1;
2158 }
2159
2160 if (aNames.IsEmpty())
2161 {
2162 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2163 return 1;
2164 }
2165
2166 if (anArgIter + 2 >= theArgNb)
2167 {
2168 std::cout << "Error: wrong syntax at " << anArg << "\n";
2169 return 1;
2170 }
2171 aChangeSet->ToSetSensitivity = 1;
2172 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2173 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2174 }
640d5fe2 2175 else if (anArg == "-sethatch")
2176 {
2177 if (isDefaults)
2178 {
2179 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2180 return 1;
2181 }
2182
2183 if (aNames.IsEmpty())
2184 {
2185 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2186 return 1;
2187 }
2188
2189 aChangeSet->ToSetHatch = 1;
2190 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
2191 if (anArg.Length() <= 2)
2192 {
2193 aChangeSet->StdHatchStyle = Draw::Atoi (anArg.ToCString());
2194 }
2195 else
2196 {
2197 aChangeSet->PathToHatchPattern = anArg;
2198 }
2199 }
7fd59977 2200 else
ad3217cd 2201 {
2202 std::cout << "Error: wrong syntax at " << anArg << "\n";
2203 return 1;
2204 }
7fd59977 2205 }
99c56d44 2206
ad3217cd 2207 Standard_Boolean isFirst = Standard_True;
2208 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2209 aChangesIter.More(); aChangesIter.Next())
2210 {
2211 if (!aChangesIter.Value().Validate (!isFirst))
2212 {
2213 return 1;
2214 }
2215 isFirst = Standard_False;
99c56d44 2216 }
99c56d44 2217
ad3217cd 2218 if (aCtx->HasOpenedContext())
2219 {
2220 aCtx->CloseLocalContext();
99c56d44 2221 }
6262338c 2222
2223 // special case for -defaults parameter.
2224 // all changed values will be set to DefaultDrawer.
2225 if (isDefaults)
2226 {
2227 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2228
2229 if (aChangeSet->ToSetLineWidth != 0)
2230 {
2231 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2232 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2233 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2234 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2235 }
2236 if (aChangeSet->ToSetColor != 0)
2237 {
2238 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2239 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2240 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2241 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2242 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2243 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2244 }
ac116c22 2245 if (aChangeSet->ToSetTypeOfLine != 0)
2246 {
2247 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2248 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2249 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2250 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2251 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2252 }
6262338c 2253 if (aChangeSet->ToSetTransparency != 0)
2254 {
2255 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2256 }
2257 if (aChangeSet->ToSetMaterial != 0)
2258 {
2259 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2260 }
2261 if (aChangeSet->ToSetShowFreeBoundary == 1)
2262 {
2263 aDrawer->SetFreeBoundaryDraw (Standard_True);
2264 }
2265 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2266 {
2267 aDrawer->SetFreeBoundaryDraw (Standard_False);
2268 }
2269 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2270 {
2271 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2272 }
2273 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2274 {
2275 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2276 }
5ad8c033 2277 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2278 {
2279 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2280 }
2281 if (aChangeSet->ToSetMaxParamValue != 0)
2282 {
2283 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2284 }
6262338c 2285
2286 // redisplay all objects in context
2287 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2288 {
2289 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2290 if (!aPrs.IsNull())
2291 {
2292 aCtx->Redisplay (aPrs, Standard_False);
2293 }
2294 }
2295 return 0;
2296 }
2297
ad3217cd 2298 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2299 {
6262338c 2300 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2301 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2302 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2303 Handle(AIS_ColoredShape) aColoredPrs;
2304 Standard_Boolean toDisplay = Standard_False;
6262338c 2305 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2306 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2307 {
2308 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2309 if (aShapePrs.IsNull())
2310 {
2311 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2312 return 1;
2313 }
2314 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2315 if (aColoredPrs.IsNull())
2316 {
2317 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3e05329c 2318 if (aShapePrs->HasDisplayMode())
2319 {
2320 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2321 }
2322 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
ad3217cd 2323 aCtx->Remove (aShapePrs, Standard_False);
2324 GetMapOfAIS().UnBind2 (aName);
2325 GetMapOfAIS().Bind (aColoredPrs, aName);
2326 toDisplay = Standard_True;
2327 aShapePrs = aColoredPrs;
2328 aPrs = aColoredPrs;
2329 }
2330 }
99c56d44 2331
ad3217cd 2332 if (!aPrs.IsNull())
2333 {
2334 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2335 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2336 if (aChangeSet->ToSetVisibility == 1)
2337 {
2338 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2339 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2340 }
2341 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2342 {
2343 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2344 }
2345 else if (aChangeSet->ToSetMaterial == -1)
2346 {
2347 aCtx->UnsetMaterial (aPrs, Standard_False);
2348 }
2349 if (aChangeSet->ToSetColor == 1)
2350 {
2351 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2352 }
2353 else if (aChangeSet->ToSetColor == -1)
2354 {
2355 aCtx->UnsetColor (aPrs, Standard_False);
2356 }
2357 if (aChangeSet->ToSetTransparency == 1)
2358 {
2359 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2360 }
2361 else if (aChangeSet->ToSetTransparency == -1)
2362 {
2363 aCtx->UnsetTransparency (aPrs, Standard_False);
2364 }
2365 if (aChangeSet->ToSetLineWidth == 1)
2366 {
2367 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2368 }
2369 else if (aChangeSet->ToSetLineWidth == -1)
2370 {
2371 aCtx->UnsetWidth (aPrs, Standard_False);
2372 }
5ad8c033 2373 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2374 {
2375 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2376 toRedisplay = Standard_True;
2377 }
8a1170ad 2378 else if (aChangeSet->ToSetSensitivity != 0)
2379 {
2380 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2381 }
6262338c 2382 if (!aDrawer.IsNull())
2383 {
2384 if (aChangeSet->ToSetShowFreeBoundary == 1)
2385 {
2386 aDrawer->SetFreeBoundaryDraw (Standard_True);
2387 toRedisplay = Standard_True;
2388 }
2389 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2390 {
2391 aDrawer->SetFreeBoundaryDraw (Standard_False);
2392 toRedisplay = Standard_True;
2393 }
2394 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2395 {
2396 Handle(Prs3d_LineAspect) aBoundaryAspect =
2397 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2398 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2399 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2400 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2401 toRedisplay = Standard_True;
2402 }
2403 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2404 {
2405 Handle(Prs3d_LineAspect) aBoundaryAspect =
2406 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2407 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2408 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2409 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2410 toRedisplay = Standard_True;
2411 }
ac116c22 2412 if (aChangeSet->ToSetTypeOfLine != 0)
2413 {
2414 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2415 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2416 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2417 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2418 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2419 toRedisplay = Standard_True;
2420 }
5ad8c033 2421 if (aChangeSet->ToSetMaxParamValue != 0)
2422 {
2423 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2424 }
640d5fe2 2425 if (aChangeSet->ToSetHatch != 0)
2426 {
2427 if (!aDrawer->HasOwnShadingAspect())
2428 {
2429 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2430 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2431 }
2432
2433 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2434 if (aChangeSet->ToSetHatch == -1)
2435 {
2436 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2437 }
2438 else
2439 {
2440 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2441 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2442 {
2443 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2444 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2445 {
2446 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2447 }
2448 else
2449 {
2450 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2451 return 1;
2452 }
2453 }
2454 else if (aChangeSet->StdHatchStyle != -1)
2455 {
2456 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2457 }
2458 }
2459 toRedisplay = Standard_True;
2460 }
6262338c 2461 }
99c56d44 2462
ad3217cd 2463 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2464 {
2465 aChangeSet = &aChangesIter.ChangeValue();
2466 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2467 aSubShapeIter.More(); aSubShapeIter.Next())
2468 {
2469 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2470 if (aChangeSet->ToSetVisibility == 1)
2471 {
2472 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2473 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2474 }
ad3217cd 2475 if (aChangeSet->ToSetColor == 1)
2476 {
2477 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2478 }
2479 if (aChangeSet->ToSetLineWidth == 1)
2480 {
2481 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2482 }
2483 if (aChangeSet->ToSetColor == -1
2484 || aChangeSet->ToSetLineWidth == -1)
2485 {
2486 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2487 }
5ad8c033 2488 if (aChangeSet->ToSetMaxParamValue != 0)
2489 {
2490 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2491 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2492 }
8a1170ad 2493 if (aChangeSet->ToSetSensitivity != 0)
2494 {
2495 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2496 }
ad3217cd 2497 }
2498 }
2499 if (toDisplay)
2500 {
2501 aCtx->Display (aPrs, Standard_False);
2502 }
6262338c 2503 if (toRedisplay)
2504 {
2505 aCtx->Redisplay (aPrs, Standard_False);
2506 }
ad3217cd 2507 else if (!aColoredPrs.IsNull())
2508 {
36132a2e 2509 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2510 }
99c56d44 2511 }
ad3217cd 2512 }
99c56d44 2513 return 0;
2514}
2515
7fd59977 2516//==============================================================================
2517//function : VDonly2
2518//author : ege
2519//purpose : Display only a selected or named object
519d35d8 2520// if there is no selected or named object s, nothing is done
7fd59977 2521//==============================================================================
519d35d8 2522static int VDonly2 (Draw_Interpretor& ,
2523 Standard_Integer theArgNb,
2524 const char** theArgVec)
7fd59977 2525{
519d35d8 2526 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2527 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2528 if (aCtx.IsNull())
2529 {
2530 std::cerr << "Error: no active view!\n";
7fd59977 2531 return 1;
519d35d8 2532 }
7fd59977 2533
519d35d8 2534 if (aCtx->HasOpenedContext())
2535 {
2536 aCtx->CloseLocalContext();
2537 }
7fd59977 2538
519d35d8 2539 Standard_Integer anArgIter = 1;
2540 for (; anArgIter < theArgNb; ++anArgIter)
2541 {
4e18052b 2542 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2543 {
2544 break;
2545 }
2546 }
7fd59977 2547
519d35d8 2548 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2549 if (anArgIter >= theArgNb)
2550 {
2551 // display only selected objects
c3282ec1 2552 if (aCtx->NbSelected() < 1)
519d35d8 2553 {
2554 return 0;
7fd59977 2555 }
2556
c3282ec1 2557 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2558 {
c3282ec1 2559 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2560 }
2561 }
2562 else
2563 {
2564 // display only specified objects
2565 for (; anArgIter < theArgNb; ++anArgIter)
2566 {
2567 TCollection_AsciiString aName = theArgVec[anArgIter];
2568 if (GetMapOfAIS().IsBound2 (aName))
2569 {
d09dda09 2570 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2571 if (!aShape.IsNull())
519d35d8 2572 {
519d35d8 2573 aCtx->Display (aShape, Standard_False);
d09dda09 2574 aDispSet.Add (aShape);
519d35d8 2575 }
7fd59977 2576 }
2577 }
7fd59977 2578 }
519d35d8 2579
2580 // weed out other objects
2581 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2582 {
2583 if (aDispSet.Contains (anIter.Key1()))
2584 {
2585 continue;
2586 }
2587
d09dda09 2588 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2589 if (aShape.IsNull())
519d35d8 2590 {
519d35d8 2591 aCtx->Erase (aShape, Standard_False);
2592 }
519d35d8 2593 }
7fd59977 2594 return 0;
2595}
2596
eef7fc64 2597//==============================================================================
2598//function : VRemove
2599//purpose : Removes selected or named objects.
2600// If there is no selected or named objects,
2601// all objects in the viewer can be removed with argument -all.
2602// If -context is in arguments, the object is not deleted from the map of
2603// objects (deleted only from the current context).
2604//==============================================================================
2605int VRemove (Draw_Interpretor& theDI,
519d35d8 2606 Standard_Integer theArgNb,
2607 const char** theArgVec)
eef7fc64 2608{
4e18052b 2609 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2610 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2611 if (aCtx.IsNull())
eef7fc64 2612 {
b6d587e3 2613 std::cerr << "Error: no active view!\n";
eef7fc64 2614 return 1;
2615 }
2616
4e18052b 2617 Standard_Boolean isContextOnly = Standard_False;
2618 Standard_Boolean toRemoveAll = Standard_False;
2619 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2620 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2621
2622 Standard_Integer anArgIter = 1;
2623 for (; anArgIter < theArgNb; ++anArgIter)
2624 {
2625 TCollection_AsciiString anArg = theArgVec[anArgIter];
2626 anArg.LowerCase();
2627 if (anArg == "-context")
2628 {
2629 isContextOnly = Standard_True;
2630 }
2631 else if (anArg == "-all")
2632 {
2633 toRemoveAll = Standard_True;
2634 }
b7cd4ba7 2635 else if (anArg == "-noinfo")
2636 {
2637 toPrintInfo = Standard_False;
2638 }
b6d587e3 2639 else if (anArg == "-local")
2640 {
2641 toRemoveLocal = Standard_True;
2642 }
2643 else if (anUpdateTool.parseRedrawMode (anArg))
2644 {
2645 continue;
2646 }
2647 else
519d35d8 2648 {
2649 break;
2650 }
2651 }
2652 if (toRemoveAll
2653 && anArgIter < theArgNb)
2654 {
b6d587e3 2655 std::cerr << "Error: wrong syntax!\n";
2656 return 1;
2657 }
2658
2659 if (toRemoveLocal && !aCtx->HasOpenedContext())
2660 {
2661 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2662 return 1;
2663 }
b6d587e3 2664 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2665 {
2666 aCtx->CloseAllContexts (Standard_False);
2667 }
519d35d8 2668
eef7fc64 2669 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2670 if (toRemoveAll)
eef7fc64 2671 {
2672 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2673 anIter.More(); anIter.Next())
2674 {
2675 anIONameList.Append (anIter.Key2());
2676 }
2677 }
519d35d8 2678 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2679 {
519d35d8 2680 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2681 {
519d35d8 2682 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2683 if (!GetMapOfAIS().IsBound2 (aName))
2684 {
2685 theDI << aName.ToCString() << " was not bound to some object.\n";
2686 continue;
2687 }
2688
d09dda09 2689 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2690 if (anIO->GetContext() != aCtx)
eef7fc64 2691 {
d09dda09 2692 theDI << aName.ToCString() << " was not displayed in current context.\n";
2693 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2694 continue;
2695 }
2696
d09dda09 2697 anIONameList.Append (aName);
2698 continue;
eef7fc64 2699 }
2700 }
c3282ec1 2701 else if (aCtx->NbSelected() > 0)
eef7fc64 2702 {
2703 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2704 anIter.More(); anIter.Next())
2705 {
2706 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2707 if (!aCtx->IsSelected (anIO))
eef7fc64 2708 {
eef7fc64 2709 continue;
2710 }
2711
d09dda09 2712 anIONameList.Append (anIter.Key2());
2713 continue;
eef7fc64 2714 }
2715 }
2716
2717 // Unbind all removed objects from the map of displayed IO.
2718 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2719 anIter.More(); anIter.Next())
2720 {
519d35d8 2721 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2722 aCtx->Remove (anIO, Standard_False);
2723 if (toPrintInfo)
519d35d8 2724 {
d09dda09 2725 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2726 }
519d35d8 2727 if (!isContextOnly)
2728 {
2729 GetMapOfAIS().UnBind2 (anIter.Value());
2730 }
2731 }
b6d587e3 2732
2733 // Close local context if it is empty
2734 TColStd_MapOfTransient aLocalIO;
2735 if (aCtx->HasOpenedContext()
2736 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2737 {
2738 aCtx->CloseAllContexts (Standard_False);
2739 }
2740
eef7fc64 2741 return 0;
2742}
2743
7fd59977 2744//==============================================================================
b514beda 2745//function : VErase
2746//purpose : Erase some selected or named objects
7fd59977 2747// if there is no selected or named objects, the whole viewer is erased
7fd59977 2748//==============================================================================
b514beda 2749int VErase (Draw_Interpretor& theDI,
2750 Standard_Integer theArgNb,
2751 const char** theArgVec)
7fd59977 2752{
a1954302 2753 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2754 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2755 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2756 if (aCtx.IsNull())
b514beda 2757 {
b6d587e3 2758 std::cerr << "Error: no active view!\n";
7fd59977 2759 return 1;
b514beda 2760 }
519d35d8 2761
519d35d8 2762 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2763
2764 Standard_Integer anArgIter = 1;
a272ed94 2765 Standard_Boolean toEraseLocal = Standard_False;
2766 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2767 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2768 for (; anArgIter < theArgNb; ++anArgIter)
2769 {
b6d587e3 2770 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2771 anArgCase.LowerCase();
2772 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2773 {
b6d587e3 2774 continue;
2775 }
2776 else if (anArgCase == "-local")
2777 {
2778 toEraseLocal = Standard_True;
2779 }
a272ed94 2780 else if (anArgCase == "-view"
2781 || anArgCase == "-inview")
2782 {
2783 toEraseInView = Standard_True;
2784 }
b6d587e3 2785 else
2786 {
2787 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2788 }
2789 }
2790
b6d587e3 2791 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2792 {
b6d587e3 2793 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2794 return 1;
2795 }
7fd59977 2796
b6d587e3 2797 if (toEraseLocal && !aCtx->HasOpenedContext())
2798 {
2799 std::cerr << "Error: local selection context is not open.\n";
2800 return 1;
2801 }
2802 else if (!toEraseLocal && aCtx->HasOpenedContext())
2803 {
2804 aCtx->CloseAllContexts (Standard_False);
2805 }
2806
2807 if (!aNamesOfEraseIO.IsEmpty())
2808 {
2809 // Erase named objects
2810 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2811 {
b6d587e3 2812 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2813 if (!GetMapOfAIS().IsBound2 (aName))
2814 {
2815 continue;
2816 }
7fd59977 2817
b514beda 2818 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2819 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2820 theDI << aName.ToCString() << " ";
2821 if (!anIO.IsNull())
2822 {
a272ed94 2823 if (toEraseInView)
2824 {
2825 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2826 }
2827 else
2828 {
2829 aCtx->Erase (anIO, Standard_False);
2830 }
b514beda 2831 }
7fd59977 2832 }
7fd59977 2833 }
c3282ec1 2834 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2835 {
b6d587e3 2836 // Erase selected objects
671b6fe0 2837 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
b514beda 2838 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2839 anIter.More(); anIter.Next())
2840 {
2841 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2842 if (!anIO.IsNull()
c3282ec1 2843 && aCtx->IsSelected (anIO))
b514beda 2844 {
2845 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2846 if (toEraseInView)
2847 {
2848 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2849 }
671b6fe0 2850 else if (aHasOpenedContext)
a272ed94 2851 {
2852 aCtx->Erase (anIO, Standard_False);
2853 }
7fd59977 2854 }
2855 }
671b6fe0 2856
2857 if (!toEraseInView)
2858 {
2859 aCtx->EraseSelected (Standard_False);
2860 }
b514beda 2861 }
519d35d8 2862 else
b514beda 2863 {
b6d587e3 2864 // Erase all objects
519d35d8 2865 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2866 anIter.More(); anIter.Next())
b514beda 2867 {
519d35d8 2868 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2869 if (!anIO.IsNull())
2870 {
a272ed94 2871 if (toEraseInView)
2872 {
2873 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2874 }
2875 else
2876 {
2877 aCtx->Erase (anIO, Standard_False);
2878 }
519d35d8 2879 }
7fd59977 2880 }
7fd59977 2881 }
b6d587e3 2882
7fd59977 2883 return 0;
2884}
2885
7fd59977 2886//==============================================================================
2887//function : VDisplayAll
2888//author : ege
2889//purpose : Display all the objects of the Map
7fd59977 2890//==============================================================================
519d35d8 2891static int VDisplayAll (Draw_Interpretor& ,
2892 Standard_Integer theArgNb,
2893 const char** theArgVec)
7fd59977 2894
2895{
4e18052b 2896 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2897 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2898 if (aCtx.IsNull())
519d35d8 2899 {
b6d587e3 2900 std::cerr << "Error: no active view!\n";
519d35d8 2901 return 1;
2902 }
2903
519d35d8 2904 Standard_Integer anArgIter = 1;
b6d587e3 2905 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2906 for (; anArgIter < theArgNb; ++anArgIter)
2907 {
b6d587e3 2908 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2909 anArgCase.LowerCase();
2910 if (anArgCase == "-local")
2911 {
2912 toDisplayLocal = Standard_True;
2913 }
2914 else if (anUpdateTool.parseRedrawMode (anArgCase))
2915 {
2916 continue;
2917 }
2918 else
519d35d8 2919 {
2920 break;
7fd59977 2921 }
519d35d8 2922 }
2923 if (anArgIter < theArgNb)
2924 {
2925 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2926 return 1;
2927 }
2928
b6d587e3 2929 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2930 {
b6d587e3 2931 std::cerr << "Error: local selection context is not open.\n";
2932 return 1;
2933 }
2934 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2935 {
2936 aCtx->CloseLocalContext (Standard_False);
519d35d8 2937 }
2938
2939 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2940 anIter.More(); anIter.Next())
2941 {
d09dda09 2942 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2943 aCtx->Erase (aShape, Standard_False);
519d35d8 2944 }
2945
2946 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2947 anIter.More(); anIter.Next())
2948 {
d09dda09 2949 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2950 aCtx->Display (aShape, Standard_False);
7fd59977 2951 }
2952 return 0;
2953}
2954
8e5fb5ea 2955//! Auxiliary method to check if presentation exists
2956inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
2957 const Handle(AIS_InteractiveObject)& theIO,
2958 const Standard_Integer theMode)
c2a388f8 2959{
8e5fb5ea 2960 if (theIO.IsNull() || theCtx.IsNull())
c2a388f8 2961 {
8e5fb5ea 2962 return -1;
c2a388f8 2963 }
2964
2965 if (theMode != -1)
2966 {
2967 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2968 {
8e5fb5ea 2969 return theMode;
c2a388f8 2970 }
2971 }
2972 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2973 {
8e5fb5ea 2974 return theIO->DisplayMode();
c2a388f8 2975 }
2976 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2977 {
8e5fb5ea 2978 return theCtx->DisplayMode();
c2a388f8 2979 }
8e5fb5ea 2980
2981 return -1;
c2a388f8 2982}
2983
2984enum ViewerTest_BndAction
2985{
2986 BndAction_Hide,
2987 BndAction_Show,
2988 BndAction_Print
2989};
2990
2991//! Auxiliary method to print bounding box of presentation
8e5fb5ea 2992inline void bndPresentation (Draw_Interpretor& theDI,
2993 const Handle(PrsMgr_PresentationManager)& theMgr,
2994 const Handle(AIS_InteractiveObject)& theObj,
2995 const Standard_Integer theDispMode,
2996 const TCollection_AsciiString& theName,
2997 const ViewerTest_BndAction theAction,
2998 const Handle(Graphic3d_HighlightStyle)& theStyle)
c2a388f8 2999{
3000 switch (theAction)
3001 {
3002 case BndAction_Hide:
3003 {
8e5fb5ea 3004 theMgr->Unhighlight (theObj, theDispMode);
c2a388f8 3005 break;
3006 }
3007 case BndAction_Show:
3008 {
8e5fb5ea 3009 theMgr->Color (theObj, theStyle, theDispMode);
c2a388f8 3010 break;
3011 }
3012 case BndAction_Print:
3013 {
8e5fb5ea 3014 Bnd_Box aBox;
3015 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3016 {
3017 if (aPrsIter.Value().Mode() != theDispMode)
3018 continue;
3019
3020 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3021 }
ed063270 3022 gp_Pnt aMin = aBox.CornerMin();
3023 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 3024 theDI << theName << "\n"
ed063270 3025 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3026 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 3027 break;
3028 }
3029 }
3030}
3031
3032//==============================================================================
3033//function : VBounding
3034//purpose :
3035//==============================================================================
3036int VBounding (Draw_Interpretor& theDI,
3037 Standard_Integer theArgNb,
3038 const char** theArgVec)
3039{
3040 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 3041 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 3042 if (aCtx.IsNull())
3043 {
3044 std::cout << "Error: no active view!\n";
3045 return 1;
3046 }
3047
4e18052b 3048 ViewerTest_BndAction anAction = BndAction_Show;
3049 Standard_Integer aMode = -1;
c2a388f8 3050
8e5fb5ea 3051 Handle(Graphic3d_HighlightStyle) aStyle;
3052
c2a388f8 3053 Standard_Integer anArgIter = 1;
3054 for (; anArgIter < theArgNb; ++anArgIter)
3055 {
3056 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3057 anArg.LowerCase();
3058 if (anArg == "-print")
3059 {
3060 anAction = BndAction_Print;
3061 }
3062 else if (anArg == "-show")
3063 {
3064 anAction = BndAction_Show;
3065 }
3066 else if (anArg == "-hide")
3067 {
3068 anAction = BndAction_Hide;
3069 }
3070 else if (anArg == "-mode")
3071 {
3072 if (++anArgIter >= theArgNb)
3073 {
3074 std::cout << "Error: wrong syntax at " << anArg << "\n";
3075 return 1;
3076 }
3077 aMode = Draw::Atoi (theArgVec[anArgIter]);
3078 }
4e18052b 3079 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3080 {
3081 break;
3082 }
3083 }
3084
8e5fb5ea 3085 if (anAction == BndAction_Show)
3086 aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
3087
3088 Standard_Integer aHighlightedMode = -1;
c2a388f8 3089 if (anArgIter < theArgNb)
3090 {
3091 // has a list of names
3092 for (; anArgIter < theArgNb; ++anArgIter)
3093 {
3094 TCollection_AsciiString aName = theArgVec[anArgIter];
3095 if (!GetMapOfAIS().IsBound2 (aName))
3096 {
3097 std::cout << "Error: presentation " << aName << " does not exist\n";
3098 return 1;
3099 }
3100
3101 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
8e5fb5ea 3102 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3103 if (aHighlightedMode == -1)
c2a388f8 3104 {
8e5fb5ea 3105 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
c2a388f8 3106 return 1;
3107 }
8e5fb5ea 3108 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
c2a388f8 3109 }
3110 }
c3282ec1 3111 else if (aCtx->NbSelected() > 0)
c2a388f8 3112 {
3113 // remove all currently selected objects
c3282ec1 3114 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3115 {
c3282ec1 3116 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
8e5fb5ea 3117 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3118 if (aHighlightedMode != -1)
c2a388f8 3119 {
8e5fb5ea 3120 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3121 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
c2a388f8 3122 }
3123 }
3124 }
3125 else
3126 {
3127 // all objects
3128 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3129 anIter.More(); anIter.Next())
3130 {
3131 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
8e5fb5ea 3132 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3133 if (aHighlightedMode != -1)
c2a388f8 3134 {
8e5fb5ea 3135 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
c2a388f8 3136 }
3137 }
3138 }
c2a388f8 3139 return 0;
3140}
3141
d399d3c3 3142//==============================================================================
3143//function : VTexture
3144//purpose :
3145//==============================================================================
3146Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3147{
d399d3c3 3148 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3149
900f7229 3150 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3151 if (aCommandName == "vtexture")
3152 {
3153 if (theArgsNb < 2)
7fd59977 3154 {
586db386 3155 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3156 std::cout << "Type help for more information.\n";
31160f80 3157 return 1;
7fd59977 3158 }
3159
d399d3c3 3160 // look for options of vtexture command
3161 TCollection_AsciiString aParseKey;
3162 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3163 {
3164 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3165
d399d3c3 3166 anArg.UpperCase();
3167 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3168 {
3169 aParseKey = anArg;
3170 aParseKey.Remove (1);
3171 aParseKey.UpperCase();
900f7229 3172 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3173 continue;
3174 }
3175
3176 if (aParseKey.IsEmpty())
3177 {
3178 continue;
3179 }
3180
900f7229 3181 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3182 }
3183 }
3184 else if (aCommandName == "vtexscale"
3185 || aCommandName == "vtexorigin"
3186 || aCommandName == "vtexrepeat")
3187 {
3188 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3189 // equal to -scale, -origin, -repeat options of vtexture command
3190 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3191 {
586db386 3192 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3193 std::cout << "Type help for more information.\n";
31160f80 3194 return 1;
7fd59977 3195 }
3196
900f7229 3197 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3198 if (theArgsNb == 2)
3199 {
900f7229 3200 anArgs->Append ("OFF");
d399d3c3 3201 }
3202 else if (theArgsNb == 4)
3203 {
900f7229 3204 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3205 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3206 }
7fd59977 3207
d399d3c3 3208 TCollection_AsciiString anArgKey;
3209 if (aCommandName == "vtexscale")
3210 {
3211 anArgKey = "SCALE";
3212 }
3213 else if (aCommandName == "vtexorigin")
3214 {
3215 anArgKey = "ORIGIN";
3216 }
3217 else
3218 {
3219 anArgKey = "REPEAT";
3220 }
3221
3222 aMapOfArgs.Bind (anArgKey, anArgs);
3223 }
3224 else if (aCommandName == "vtexdefault")
7fd59977 3225 {
d399d3c3 3226 // scan for parameters of vtexdefault command
3227 // equal to -default option of vtexture command
900f7229 3228 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3229 }
3230
d399d3c3 3231 // Check arguments for validity
900f7229 3232 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3233 for (; aMapIt.More(); aMapIt.Next())
3234 {
3235 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3236 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3237
3238 // -scale, -origin, -repeat: one argument "off", or two real values
3239 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3240 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3241 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3242 {
d399d3c3 3243 continue;
7fd59977 3244 }
d399d3c3 3245
3246 // -modulate: single argument "on" / "off"
900f7229 3247 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3248 {
3249 continue;
3250 }
3251
3252 // -default: no arguments
900f7229 3253 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3254 {
3255 continue;
3256 }
3257
3258 TCollection_AsciiString aLowerKey;
3259 aLowerKey = "-";
3260 aLowerKey += aKey;
3261 aLowerKey.LowerCase();
3262 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3263 std::cout << "Type help for more information.\n";
3264 return 1;
3265 }
3266
3267 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3268 if (anAISContext.IsNull())
3269 {
586db386 3270 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
d399d3c3 3271 return 1;
3272 }
3273
3274 Standard_Integer aPreviousMode = 0;
3275
d399d3c3 3276 TCollection_AsciiString aShapeName (theArgv[1]);
3277 Handle(AIS_InteractiveObject) anIO;
3278
3279 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3280 if (aMapOfIO.IsBound2 (aShapeName))
3281 {
3282 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3283 }
3284
3285 if (anIO.IsNull())
3286 {
3287 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3288 return 1;
3289 }
3290
3291 Handle(AIS_TexturedShape) aTexturedIO;
3292 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3293 {
3294 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3295 aPreviousMode = aTexturedIO->DisplayMode();
3296 }
7fd59977 3297 else
d399d3c3 3298 {
d399d3c3 3299 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
16420da1 3300
3301 if (anIO->HasTransformation())
3302 {
3303 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3304 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3305 }
3306
3307 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3308 GetMapOfAIS().UnBind1 (anIO);
3309 GetMapOfAIS().UnBind2 (aShapeName);
3310 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3311 }
3312
3313 // -------------------------------------------
3314 // Turn texturing on/off - only for vtexture
3315 // -------------------------------------------
3316
3317 if (aCommandName == "vtexture")
3318 {
3319 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3320
3321 if (aTextureArg.IsEmpty())
7fd59977 3322 {
586db386 3323 std::cout << aCommandName << ": Texture mapping disabled.\n";
3324 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
d399d3c3 3325
3326 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3327 if (aPreviousMode == 3)
3328 {
3329 anAISContext->RecomputePrsOnly (aTexturedIO);
3330 }
3331
3332 anAISContext->Display (aTexturedIO, Standard_True);
3333 return 0;
7fd59977 3334 }
d399d3c3 3335 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3336 {
d399d3c3 3337 if (aTextureArg == "?")
3338 {
3339 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3340
586db386 3341 theDi << "\n Files in current directory : \n\n";
d399d3c3 3342 theDi.Eval ("glob -nocomplain *");
7fd59977 3343
d399d3c3 3344 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3345 aCmnd += aTextureFolder;
3346 aCmnd += "/* ";
7fd59977 3347
586db386 3348 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
d399d3c3 3349 theDi.Eval (aCmnd.ToCString());
3350 return 0;
3351 }
3352 else
3353 {
3354 aTexturedIO->SetTextureFileName (aTextureArg);
3355 }
3356 }
3357 }
7fd59977 3358
d399d3c3 3359 // ------------------------------------
3360 // Process other options and commands
3361 // ------------------------------------
7fd59977 3362
900f7229 3363 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3364 if (aMapOfArgs.Find ("DEFAULT", aValues))
3365 {
3366 aTexturedIO->SetTextureRepeat (Standard_False);
3367 aTexturedIO->SetTextureOrigin (Standard_False);
3368 aTexturedIO->SetTextureScale (Standard_False);
3369 aTexturedIO->EnableTextureModulate();
3370 }
3371 else
3372 {
3373 if (aMapOfArgs.Find ("SCALE", aValues))
3374 {
900f7229 3375 if (aValues->Value(1) != "OFF")
d399d3c3 3376 {
900f7229 3377 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3378 }
7fd59977 3379 else
d399d3c3 3380 {
3381 aTexturedIO->SetTextureScale (Standard_False);
3382 }
3383 }
7fd59977 3384
d399d3c3 3385 if (aMapOfArgs.Find ("ORIGIN", aValues))
3386 {
900f7229 3387 if (aValues->Value(1) != "OFF")
d399d3c3 3388 {
900f7229 3389 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3390 }
3391 else
3392 {
3393 aTexturedIO->SetTextureOrigin (Standard_False);
3394 }
3395 }
7fd59977 3396
d399d3c3 3397 if (aMapOfArgs.Find ("REPEAT", aValues))
3398 {
900f7229 3399 if (aValues->Value(1) != "OFF")
d399d3c3 3400 {
900f7229 3401 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3402 }
3403 else
3404 {
3405 aTexturedIO->SetTextureRepeat (Standard_False);
3406 }
7fd59977 3407 }
3408
d399d3c3 3409 if (aMapOfArgs.Find ("MODULATE", aValues))