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