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