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