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