0030497: [REGRESSION] Mesh - wrong Poly_Polygon3D within local selection of located...
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17#include <Standard_Stream.hxx>
18
19#include <ViewerTest.hxx>
189f85a3 20#include <ViewerTest_CmdParser.hxx>
4e18052b 21
3a4a3962 22#include <Draw.hxx>
7fd59977 23#include <TopLoc_Location.hxx>
24#include <TopTools_HArray1OfShape.hxx>
25#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 26#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 27#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 28#include <TColStd_MapOfTransient.hxx>
7fd59977 29#include <OSD_Timer.hxx>
30#include <Geom_Axis2Placement.hxx>
31#include <Geom_Axis1Placement.hxx>
32#include <gp_Trsf.hxx>
33#include <TopExp_Explorer.hxx>
34#include <BRepAdaptor_Curve.hxx>
35#include <StdSelect_ShapeTypeFilter.hxx>
36#include <AIS.hxx>
ad3217cd 37#include <AIS_ColoredShape.hxx>
7fd59977 38#include <AIS_InteractiveObject.hxx>
39#include <AIS_Trihedron.hxx>
40#include <AIS_Axis.hxx>
41#include <AIS_Relation.hxx>
42#include <AIS_TypeFilter.hxx>
43#include <AIS_SignatureFilter.hxx>
44#include <AIS_ListOfInteractive.hxx>
45#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 46#include <Aspect_InteriorStyle.hxx>
34db9c00 47#include <Aspect_Window.hxx>
99c56d44 48#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 49#include <Graphic3d_AspectLine3d.hxx>
a1954302 50#include <Graphic3d_CStructure.hxx>
a6dee93d 51#include <Graphic3d_Texture2Dmanual.hxx>
cc8cbabe 52#include <Graphic3d_GraphicDriver.hxx>
692613e5 53#include <Image_AlienPixMap.hxx>
a6dee93d 54#include <OSD_File.hxx>
6262338c 55#include <Prs3d_Drawer.hxx>
99c56d44 56#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 57#include <Prs3d_IsoAspect.hxx>
6262338c 58#include <Prs3d_PointAspect.hxx>
8e7c8ccf 59#include <Select3D_SensitiveWire.hxx>
8b9a309b 60#include <Select3D_SensitivePrimitiveArray.hxx>
8e7c8ccf 61#include <SelectMgr_EntityOwner.hxx>
62#include <StdSelect_BRepOwner.hxx>
63#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 64#include <TopTools_MapOfShape.hxx>
4e18052b 65#include <ViewerTest_AutoUpdater.hxx>
7fd59977 66
7fd59977 67#include <stdio.h>
7fd59977 68
69#include <Draw_Interpretor.hxx>
70#include <TCollection_AsciiString.hxx>
71#include <Draw_PluginMacro.hxx>
7fd59977 72
7fd59977 73extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
74
7fd59977 75#include <Quantity_Color.hxx>
76#include <Quantity_NameOfColor.hxx>
77
78#include <Graphic3d_NameOfMaterial.hxx>
79
6262338c 80#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
81#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
82#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 83
792c785c 84//=======================================================================
85//function : GetColorFromName
86//purpose : get the Quantity_NameOfColor from a string
87//=======================================================================
7fd59977 88
792c785c 89Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
90{
8316c618 91 Quantity_NameOfColor aColor = DEFAULT_COLOR;
92 Quantity_Color::ColorFromName (theName, aColor);
93 return aColor;
7fd59977 94}
95
2a332745 96
536d98e2 97//=======================================================================
2a332745 98//function : parseColor
536d98e2 99//purpose :
100//=======================================================================
2a332745 101Standard_Integer ViewerTest::parseColor (Standard_Integer theArgNb,
536d98e2 102 const char** theArgVec,
2a332745 103 Quantity_ColorRGBA& theColor,
104 bool theToParseAlpha)
536d98e2 105{
106 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
107 if (theArgNb >= 1
108 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
109 {
2a332745 110 theColor = Quantity_ColorRGBA (aColor);
111 if (theArgNb >= 2
112 && theToParseAlpha)
113 {
114 const TCollection_AsciiString anAlphaStr (theArgVec[1]);
115 if (anAlphaStr.IsRealValue())
116 {
117 float anAlpha = (float )anAlphaStr.RealValue();
118 if (anAlpha < 0.0f || anAlpha > 1.0f)
119 {
120 std::cout << "Syntax error: alpha should be within range 0..1!\n";
121 return 0;
122 }
123 return 2;
124 }
125 }
536d98e2 126 return 1;
127 }
128 else if (theArgNb >= 3)
129 {
2a332745 130 Graphic3d_Vec4 anRgba;
131 Standard_Integer aNbComps = Min (theArgNb, theToParseAlpha ? 4 : 3);
132 for (int aCompIter = 0; aCompIter < aNbComps; ++aCompIter)
536d98e2 133 {
2a332745 134 const TCollection_AsciiString anRgbaStr (theArgVec[aCompIter]);
135 if (!anRgbaStr.IsRealValue())
136 {
137 if (aCompIter == 3)
138 {
139 anRgba.a() = 1.0f;
140 aNbComps = 3;
141 break;
142 }
143 return 0;
144 }
536d98e2 145
2a332745 146 anRgba[aCompIter] = (float )anRgbaStr.RealValue();
147 if (anRgba[aCompIter] < 0.0 || anRgba[aCompIter] > 1.0)
148 {
149 std::cout << "Error: RGBA color values should be within range 0..1!\n";
150 return 0;
151 }
536d98e2 152 }
2a332745 153 theColor = Quantity_ColorRGBA (anRgba);
154 return aNbComps;
536d98e2 155 }
156
157 return 0;
158}
159
a5565a3c 160//=======================================================================
161//function : ParseOnOff
162//purpose :
163//=======================================================================
164Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
165 Standard_Boolean& theIsOn)
166{
167 TCollection_AsciiString aFlag(theArg);
168 aFlag.LowerCase();
169 if (aFlag == "on"
170 || aFlag == "1")
171 {
172 theIsOn = Standard_True;
173 return Standard_True;
174 }
175 else if (aFlag == "off"
176 || aFlag == "0")
177 {
178 theIsOn = Standard_False;
179 return Standard_True;
180 }
181 return Standard_False;
182}
183
404c8936 184//=======================================================================
185//function : GetSelectedShapes
186//purpose :
187//=======================================================================
188void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
189{
190 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
191 {
192 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
193 if (!aShape.IsNull())
194 {
195 theSelectedShapes.Append (aShape);
196 }
197 }
198}
199
3a4a3962 200//=======================================================================
201//function : ParseLineType
202//purpose :
203//=======================================================================
204Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
205 Aspect_TypeOfLine& theType)
206{
207 TCollection_AsciiString aTypeStr (theArg);
208 aTypeStr.LowerCase();
209 if (aTypeStr == "empty")
210 {
211 theType = Aspect_TOL_EMPTY;
212 }
213 else if (aTypeStr == "solid")
214 {
215 theType = Aspect_TOL_SOLID;
216 }
217 else if (aTypeStr == "dot")
218 {
219 theType = Aspect_TOL_DOT;
220 }
221 else if (aTypeStr == "dash")
222 {
223 theType = Aspect_TOL_DASH;
224 }
225 else if (aTypeStr == "dotdash")
226 {
227 theType = Aspect_TOL_DOTDASH;
228 }
2a332745 229 else if (aTypeStr.IsIntegerValue())
3a4a3962 230 {
2a332745 231 const int aTypeInt = aTypeStr.IntegerValue();
3a4a3962 232 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
233 {
234 return Standard_False;
235 }
236 theType = (Aspect_TypeOfLine )aTypeInt;
237 }
2a332745 238 else
239 {
240 return Standard_False;
241 }
3a4a3962 242 return Standard_True;
243}
244
33cc703b 245//=======================================================================
246//function : ParseMarkerType
247//purpose :
248//=======================================================================
249Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
250 Aspect_TypeOfMarker& theType,
251 Handle(Image_PixMap)& theImage)
252{
253 theImage.Nullify();
254 TCollection_AsciiString aTypeStr (theArg);
255 aTypeStr.LowerCase();
256 if (aTypeStr == "empty")
257 {
258 theType = Aspect_TOM_EMPTY;
259 }
260 else if (aTypeStr == "point"
261 || aTypeStr == "dot"
262 || aTypeStr == ".")
263 {
264 theType = Aspect_TOM_POINT;
265 }
266 else if (aTypeStr == "plus"
267 || aTypeStr == "+")
268 {
269 theType = Aspect_TOM_PLUS;
270 }
271 else if (aTypeStr == "star"
272 || aTypeStr == "*")
273 {
274 theType = Aspect_TOM_STAR;
275 }
276 else if (aTypeStr == "cross"
277 || aTypeStr == "x")
278 {
279 theType = Aspect_TOM_X;
280 }
281 else if (aTypeStr == "circle"
282 || aTypeStr == "o")
283 {
284 theType = Aspect_TOM_O;
285 }
286 else if (aTypeStr == "pointincircle")
287 {
288 theType = Aspect_TOM_O_POINT;
289 }
290 else if (aTypeStr == "plusincircle")
291 {
292 theType = Aspect_TOM_O_PLUS;
293 }
294 else if (aTypeStr == "starincircle")
295 {
296 theType = Aspect_TOM_O_STAR;
297 }
298 else if (aTypeStr == "crossincircle"
299 || aTypeStr == "xcircle")
300 {
301 theType = Aspect_TOM_O_X;
302 }
303 else if (aTypeStr == "ring1")
304 {
305 theType = Aspect_TOM_RING1;
306 }
307 else if (aTypeStr == "ring2")
308 {
309 theType = Aspect_TOM_RING2;
310 }
311 else if (aTypeStr == "ring"
312 || aTypeStr == "ring3")
313 {
314 theType = Aspect_TOM_RING3;
315 }
316 else if (aTypeStr == "ball")
317 {
318 theType = Aspect_TOM_BALL;
319 }
320 else if (aTypeStr.IsIntegerValue())
321 {
322 const int aTypeInt = aTypeStr.IntegerValue();
323 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
324 {
325 return Standard_False;
326 }
327 theType = (Aspect_TypeOfMarker )aTypeInt;
328 }
329 else
330 {
331 theType = Aspect_TOM_USERDEFINED;
332 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
333 if (!anImage->Load (theArg))
334 {
335 return Standard_False;
336 }
337 if (anImage->Format() == Image_Format_Gray)
338 {
339 anImage->SetFormat (Image_Format_Alpha);
340 }
341 else if (anImage->Format() == Image_Format_GrayF)
342 {
343 anImage->SetFormat (Image_Format_AlphaF);
344 }
345 theImage = anImage;
346 }
347 return Standard_True;
348}
349
dc89236f 350//=======================================================================
351//function : ParseShadingModel
352//purpose :
353//=======================================================================
354Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
355 Graphic3d_TypeOfShadingModel& theModel)
356{
357 TCollection_AsciiString aTypeStr (theArg);
358 aTypeStr.LowerCase();
359 if (aTypeStr == "unlit"
360 || aTypeStr == "color"
361 || aTypeStr == "none")
362 {
363 theModel = Graphic3d_TOSM_UNLIT;
364 }
365 else if (aTypeStr == "flat"
366 || aTypeStr == "facet")
367 {
368 theModel = Graphic3d_TOSM_FACET;
369 }
370 else if (aTypeStr == "gouraud"
371 || aTypeStr == "vertex"
372 || aTypeStr == "vert")
373 {
374 theModel = Graphic3d_TOSM_VERTEX;
375 }
376 else if (aTypeStr == "phong"
377 || aTypeStr == "fragment"
378 || aTypeStr == "frag"
379 || aTypeStr == "pixel")
380 {
381 theModel = Graphic3d_TOSM_FRAGMENT;
382 }
383 else if (aTypeStr == "default"
384 || aTypeStr == "def")
385 {
386 theModel = Graphic3d_TOSM_DEFAULT;
387 }
388 else if (aTypeStr.IsIntegerValue())
389 {
390 const int aTypeInt = aTypeStr.IntegerValue();
391 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
392 {
393 return Standard_False;
394 }
395 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
396 }
397 else
398 {
399 return Standard_False;
400 }
401 return Standard_True;
402}
403
7fd59977 404//=======================================================================
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//==============================================================================
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
1c88cbaf 695//==============================================================================
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
7fd59977 873//==============================================================================
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
1590 Standard_Integer ToSetDrawEdges;
1591 Standard_Integer ToSetQuadEdges;
1592
1593 Standard_Integer ToSetEdgeColor;
1594 Quantity_ColorRGBA EdgeColor;
1595
1596 Standard_Integer ToSetEdgeWidth;
1597 Standard_Real EdgeWidth;
1598
1599 Standard_Integer ToSetTypeOfEdge;
1600 Aspect_TypeOfLine TypeOfEdge;
1601
ad3217cd 1602 //! Empty constructor
1603 ViewerTest_AspectsChangeSet()
5bffb882 1604 : ToSetVisibility (0),
1605 Visibility (1),
1606 ToSetColor (0),
ad3217cd 1607 Color (DEFAULT_COLOR),
1608 ToSetLineWidth (0),
1609 LineWidth (1.0),
ac116c22 1610 ToSetTypeOfLine (0),
1611 TypeOfLine (Aspect_TOL_SOLID),
33cc703b 1612 ToSetTypeOfMarker (0),
1613 TypeOfMarker (Aspect_TOM_PLUS),
1614 ToSetMarkerSize (0),
1615 MarkerSize (1.0),
ad3217cd 1616 ToSetTransparency (0),
1617 Transparency (0.0),
c40eb6b9 1618 ToSetAlphaMode (0),
1619 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1620 AlphaCutoff (0.5f),
ad3217cd 1621 ToSetMaterial (0),
6262338c 1622 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1623 ToSetShowFreeBoundary (0),
1624 ToSetFreeBoundaryWidth (0),
1625 FreeBoundaryWidth (1.0),
1626 ToSetFreeBoundaryColor (0),
1627 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
0493ffd0 1628 ToEnableIsoOnTriangulation (0),
1629 //
1630 ToSetFaceBoundaryDraw (0),
1631 ToSetFaceBoundaryUpperContinuity (0),
1632 FaceBoundaryUpperContinuity(GeomAbs_CN),
1633 ToSetFaceBoundaryColor (0),
1634 FaceBoundaryColor (Quantity_NOC_BLACK),
1635 ToSetFaceBoundaryWidth (0),
1636 FaceBoundaryWidth (1.0f),
1637 ToSetTypeOfFaceBoundaryLine(0),
1638 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1639 //
dc89236f 1640 ToSetMaxParamValue (0),
1641 MaxParamValue (500000),
1642 ToSetSensitivity (0),
1643 SelectionMode (-1),
1644 Sensitivity (-1),
1645 ToSetHatch (0),
1646 StdHatchStyle (-1),
1647 ToSetShadingModel (0),
2a332745 1648 ShadingModel (Graphic3d_TOSM_DEFAULT),
1649 ToSetInterior (0),
1650 InteriorStyle (Aspect_IS_SOLID),
1651 ToSetDrawEdges (0),
1652 ToSetQuadEdges (0),
1653 ToSetEdgeColor (0),
1654 ToSetEdgeWidth (0),
1655 EdgeWidth (1.0),
1656 ToSetTypeOfEdge (0),
1657 TypeOfEdge (Aspect_TOL_SOLID)
640d5fe2 1658 {}
ad3217cd 1659
1660 //! @return true if no changes have been requested
1661 Standard_Boolean IsEmpty() const
1662 {
6262338c 1663 return ToSetVisibility == 0
1664 && ToSetLineWidth == 0
1665 && ToSetTransparency == 0
c40eb6b9 1666 && ToSetAlphaMode == 0
6262338c 1667 && ToSetColor == 0
1668 && ToSetMaterial == 0
1669 && ToSetShowFreeBoundary == 0
1670 && ToSetFreeBoundaryColor == 0
5ad8c033 1671 && ToSetFreeBoundaryWidth == 0
0493ffd0 1672 && ToEnableIsoOnTriangulation == 0
1673 && ToSetFaceBoundaryDraw == 0
1674 && ToSetFaceBoundaryUpperContinuity == 0
1675 && ToSetFaceBoundaryColor == 0
1676 && ToSetFaceBoundaryWidth == 0
1677 && ToSetTypeOfFaceBoundaryLine == 0
8a1170ad 1678 && ToSetMaxParamValue == 0
640d5fe2 1679 && ToSetSensitivity == 0
dc89236f 1680 && ToSetHatch == 0
2a332745 1681 && ToSetShadingModel == 0
1682 && ToSetInterior == 0
1683 && ToSetDrawEdges == 0
1684 && ToSetQuadEdges == 0
1685 && ToSetEdgeColor == 0
1686 && ToSetEdgeWidth == 0
1687 && ToSetTypeOfEdge == 0;
ad3217cd 1688 }
1689
1690 //! @return true if properties are valid
c1197a15 1691 Standard_Boolean Validate() const
ad3217cd 1692 {
1693 Standard_Boolean isOk = Standard_True;
5bffb882 1694 if (Visibility != 0 && Visibility != 1)
1695 {
1696 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1697 isOk = Standard_False;
1698 }
ad3217cd 1699 if (LineWidth <= 0.0
1700 || LineWidth > 10.0)
1701 {
1702 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1703 isOk = Standard_False;
7fd59977 1704 }
ad3217cd 1705 if (Transparency < 0.0
1706 || Transparency > 1.0)
1707 {
1708 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1709 isOk = Standard_False;
1710 }
c40eb6b9 1711 if (ToSetAlphaMode == 1
1712 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1713 {
1714 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1715 isOk = Standard_False;
1716 }
ad3217cd 1717 if (ToSetMaterial == 1
1718 && Material == Graphic3d_NOM_DEFAULT)
1719 {
1720 std::cout << "Error: unknown material " << MatName << ".\n";
1721 isOk = Standard_False;
1722 }
6262338c 1723 if (FreeBoundaryWidth <= 0.0
1724 || FreeBoundaryWidth > 10.0)
1725 {
1726 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1727 isOk = Standard_False;
1728 }
5ad8c033 1729 if (MaxParamValue < 0.0)
1730 {
1731 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1732 isOk = Standard_False;
1733 }
8a1170ad 1734 if (Sensitivity <= 0 && ToSetSensitivity)
1735 {
1736 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1737 isOk = Standard_False;
1738 }
640d5fe2 1739 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1740 {
1741 std::cout << "Error: hatch style must be specified\n";
1742 isOk = Standard_False;
1743 }
dc89236f 1744 if (ToSetShadingModel == 1
1745 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1746 {
1747 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1748 isOk = Standard_False;
1749 }
ad3217cd 1750 return isOk;
7fd59977 1751 }
7fd59977 1752
2a332745 1753 //! Apply aspects to specified drawer.
1754 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1755 {
1756 bool toRecompute = false;
1757 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1758 if (ToSetShowFreeBoundary != 0)
1759 {
1760 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
1761 toRecompute = true;
1762 }
1763 if (ToSetFreeBoundaryWidth != 0)
1764 {
1765 if (ToSetFreeBoundaryWidth != -1
1766 || theDrawer->HasOwnFreeBoundaryAspect())
1767 {
1768 if (!theDrawer->HasOwnFreeBoundaryAspect())
1769 {
1770 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1771 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1772 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1773 toRecompute = true;
1774 }
1775 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
1776 }
1777 }
1778 if (ToSetFreeBoundaryColor != 0)
1779 {
1780 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1781 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1782 aBoundaryAspect->SetColor (FreeBoundaryColor);
1783 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1784 toRecompute = true;
1785 }
1786 if (ToSetTypeOfLine != 0)
1787 {
1788 if (ToSetTypeOfLine != -1
1789 || theDrawer->HasOwnLineAspect()
1790 || theDrawer->HasOwnWireAspect()
1791 || theDrawer->HasOwnFreeBoundaryAspect()
1792 || theDrawer->HasOwnUnFreeBoundaryAspect()
1793 || theDrawer->HasOwnSeenLineAspect())
1794 {
1795 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
1796 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
1797 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
1798 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
1799 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
1800 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
1801 }
1802 }
1803 if (ToSetTypeOfMarker != 0)
1804 {
1805 if (ToSetTypeOfMarker != -1
1806 || theDrawer->HasOwnPointAspect())
1807 {
1808 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1809 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
1810 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
1811 }
1812 }
1813 if (ToSetMarkerSize != 0)
1814 {
1815 if (ToSetMarkerSize != -1
1816 || theDrawer->HasOwnPointAspect())
1817 {
1818 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1819 theDrawer->PointAspect()->SetScale (MarkerSize);
1820 toRecompute = true;
1821 }
1822 }
1823 if (ToSetMaxParamValue != 0)
1824 {
1825 if (ToSetMaxParamValue != -1
1826 || theDrawer->HasOwnMaximalParameterValue())
1827 {
1828 theDrawer->SetMaximalParameterValue (MaxParamValue);
1829 toRecompute = true;
1830 }
1831 }
0493ffd0 1832 if (ToSetFaceBoundaryDraw != 0)
1833 {
1834 if (ToSetFaceBoundaryDraw != -1
1835 || theDrawer->HasOwnFaceBoundaryDraw())
1836 {
1837 toRecompute = true;
1838 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
1839 }
1840 }
1841 if (ToSetFaceBoundaryUpperContinuity != 0)
1842 {
1843 if (ToSetFaceBoundaryUpperContinuity != -1
1844 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
1845 {
1846 toRecompute = true;
1847 if (ToSetFaceBoundaryUpperContinuity == -1)
1848 {
1849 theDrawer->UnsetFaceBoundaryUpperContinuity();
1850 }
1851 else
1852 {
1853 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
1854 }
1855 }
1856 }
1857 if (ToSetFaceBoundaryColor != 0)
1858 {
1859 if (ToSetFaceBoundaryColor != -1
1860 || theDrawer->HasOwnFaceBoundaryAspect())
1861 {
1862 if (ToSetFaceBoundaryColor == -1)
1863 {
1864 toRecompute = true;
1865 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
1866 }
1867 else
1868 {
1869 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1870 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
1871 }
1872 }
1873 }
1874 if (ToSetFaceBoundaryWidth != 0)
1875 {
1876 if (ToSetFaceBoundaryWidth != -1
1877 || theDrawer->HasOwnFaceBoundaryAspect())
1878 {
1879 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1880 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
1881 }
1882 }
1883 if (ToSetTypeOfFaceBoundaryLine != 0)
1884 {
1885 if (ToSetTypeOfFaceBoundaryLine != -1
1886 || theDrawer->HasOwnFaceBoundaryAspect())
1887 {
1888 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1889 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
1890 }
1891 }
2a332745 1892 if (ToSetShadingModel != 0)
1893 {
1894 if (ToSetShadingModel != -1
1895 || theDrawer->HasOwnShadingAspect())
1896 {
1897 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1898 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
1899 }
1900 }
1901 if (ToSetAlphaMode != 0)
1902 {
1903 if (ToSetAlphaMode != -1
1904 || theDrawer->HasOwnShadingAspect())
1905 {
1906 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1907 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
1908 }
1909 }
1910 if (ToSetHatch != 0)
1911 {
1912 if (ToSetHatch != -1
1913 || theDrawer->HasOwnShadingAspect())
1914 {
1915 theDrawer->SetupOwnShadingAspect (aDefDrawer);
1916 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
1917 if (ToSetHatch == -1)
1918 {
1919 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
1920 }
1921 else
1922 {
1923 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
1924 if (!PathToHatchPattern.IsEmpty())
1925 {
1926 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
1927 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
1928 {
1929 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
1930 }
1931 else
1932 {
1933 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
1934 }
1935 }
1936 else if (StdHatchStyle != -1)
1937 {
1938 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
1939 }
1940 }
1941 toRecompute = true;
1942 }
1943 }
1944 if (ToSetInterior != 0)
1945 {
1946 if (ToSetInterior != -1
1947 || theDrawer->HasOwnShadingAspect())
1948 {
1949 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1950 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
1951 if (InteriorStyle == Aspect_IS_HATCH
1952 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
1953 {
1954 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
1955 }
1956 }
1957 }
1958 if (ToSetDrawEdges != 0)
1959 {
1960 if (ToSetDrawEdges != -1
1961 || theDrawer->HasOwnShadingAspect())
1962 {
1963 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1964 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
1965 }
1966 }
1967 if (ToSetQuadEdges != 0)
1968 {
1969 if (ToSetQuadEdges != -1
1970 || theDrawer->HasOwnShadingAspect())
1971 {
1972 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1973 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
1974 }
1975 }
1976 if (ToSetEdgeWidth != 0)
1977 {
1978 if (ToSetEdgeWidth != -1
1979 || theDrawer->HasOwnShadingAspect())
1980 {
1981 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1982 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
1983 }
1984 }
1985 if (ToSetTypeOfEdge != 0)
1986 {
1987 if (ToSetTypeOfEdge != -1
1988 || theDrawer->HasOwnShadingAspect())
1989 {
1990 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1991 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
1992 if (ToSetInterior == 0)
1993 {
1994 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
1995 && TypeOfEdge != Aspect_TOL_EMPTY);
1996 }
1997 }
1998 }
1999 if (ToSetEdgeColor != 0)
2000 {
2001 if (ToSetEdgeColor != -1
2002 || theDrawer->HasOwnShadingAspect())
2003 {
2004 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2005 if (ToSetEdgeColor == -1)
2006 {
2007 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2008 }
2009 else
2010 {
2011 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2012 }
2013 }
2014 }
2015 return toRecompute;
2016 }
ad3217cd 2017};
7fd59977 2018
2019//==============================================================================
ad3217cd 2020//function : VAspects
2021//purpose :
7fd59977 2022//==============================================================================
ad3217cd 2023static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
2024 Standard_Integer theArgNb,
2025 const char** theArgVec)
7fd59977 2026{
ad3217cd 2027 TCollection_AsciiString aCmdName (theArgVec[0]);
2028 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2029 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 2030 if (aCtx.IsNull())
2031 {
2032 std::cerr << "Error: no active view!\n";
2033 return 1;
2034 }
7fd59977 2035
4e18052b 2036 Standard_Integer anArgIter = 1;
6262338c 2037 Standard_Boolean isDefaults = Standard_False;
ad3217cd 2038 NCollection_Sequence<TCollection_AsciiString> aNames;
2039 for (; anArgIter < theArgNb; ++anArgIter)
2040 {
2041 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 2042 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 2043 {
2044 continue;
2045 }
2046 else if (!anArg.IsEmpty()
2047 && anArg.Value (1) != '-')
2048 {
2049 aNames.Append (anArg);
2050 }
2051 else
2052 {
6262338c 2053 if (anArg == "-defaults")
2054 {
2055 isDefaults = Standard_True;
2056 ++anArgIter;
2057 }
ad3217cd 2058 break;
2059 }
2060 }
2061
6262338c 2062 if (!aNames.IsEmpty() && isDefaults)
2063 {
2064 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2065 return 1;
2066 }
2067
ad3217cd 2068 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2069 aChanges.Append (ViewerTest_AspectsChangeSet());
2070 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 2071
ad3217cd 2072 // parse syntax of legacy commands
2a332745 2073 bool toParseAliasArgs = false;
ad3217cd 2074 if (aCmdName == "vsetwidth")
2075 {
2076 if (aNames.IsEmpty()
2077 || !aNames.Last().IsRealValue())
2078 {
2079 std::cout << "Error: not enough arguments!\n";
2080 return 1;
2081 }
2082 aChangeSet->ToSetLineWidth = 1;
2083 aChangeSet->LineWidth = aNames.Last().RealValue();
2084 aNames.Remove (aNames.Length());
7fd59977 2085 }
ad3217cd 2086 else if (aCmdName == "vunsetwidth")
2087 {
2088 aChangeSet->ToSetLineWidth = -1;
2089 }
2090 else if (aCmdName == "vsetcolor")
2091 {
2092 if (aNames.IsEmpty())
2093 {
2094 std::cout << "Error: not enough arguments!\n";
2095 return 1;
2096 }
2097 aChangeSet->ToSetColor = 1;
8316c618 2098
2099 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2100 Standard_Boolean isOk = Standard_False;
2101 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2102 {
2103 aChangeSet->Color = aColor;
2104 aNames.Remove (aNames.Length());
2105 isOk = Standard_True;
2106 }
2107 else if (aNames.Length() >= 3)
2108 {
2a332745 2109 const char* anArgVec[3] =
8316c618 2110 {
2a332745 2111 aNames.Value (aNames.Upper() - 2).ToCString(),
2112 aNames.Value (aNames.Upper() - 1).ToCString(),
2113 aNames.Value (aNames.Upper() - 0).ToCString(),
8316c618 2114 };
2a332745 2115
2116 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2117 isOk = aNbParsed == 3;
2118 aNames.Remove (aNames.Length());
2119 aNames.Remove (aNames.Length());
2120 aNames.Remove (aNames.Length());
8316c618 2121 }
2122 if (!isOk)
2123 {
2124 std::cout << "Error: not enough arguments!\n";
2125 return 1;
2126 }
ad3217cd 2127 }
2128 else if (aCmdName == "vunsetcolor")
2129 {
2130 aChangeSet->ToSetColor = -1;
2131 }
2132 else if (aCmdName == "vsettransparency")
2133 {
2134 if (aNames.IsEmpty()
2135 || !aNames.Last().IsRealValue())
2136 {
2137 std::cout << "Error: not enough arguments!\n";
2138 return 1;
2139 }
2140 aChangeSet->ToSetTransparency = 1;
2141 aChangeSet->Transparency = aNames.Last().RealValue();
2142 aNames.Remove (aNames.Length());
2143 }
2144 else if (aCmdName == "vunsettransparency")
2145 {
2146 aChangeSet->ToSetTransparency = -1;
2147 }
2148 else if (aCmdName == "vsetmaterial")
2149 {
2150 if (aNames.IsEmpty())
2151 {
2152 std::cout << "Error: not enough arguments!\n";
2153 return 1;
2154 }
2155 aChangeSet->ToSetMaterial = 1;
2156 aChangeSet->MatName = aNames.Last();
2157 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2158 aNames.Remove (aNames.Length());
2159 }
2160 else if (aCmdName == "vunsetmaterial")
2161 {
2162 aChangeSet->ToSetMaterial = -1;
2163 }
2a332745 2164 else if (aCmdName == "vsetinteriorstyle")
2165 {
2166 if (aNames.IsEmpty()
2167 || !aNames.Last().IsRealValue())
2168 {
2169 std::cout << "Error: not enough arguments!\n";
2170 return 1;
2171 }
2172 aChangeSet->ToSetInterior = 1;
2173 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2174 {
2175 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2176 return 1;
2177 }
2178 aNames.Remove (aNames.Length());
2179 }
2180 else if (aCmdName == "vsetedgetype")
2181 {
2182 aChangeSet->ToSetDrawEdges = 1;
2183 toParseAliasArgs = true;
2184 }
2185 else if (aCmdName == "vunsetedgetype")
2186 {
2187 aChangeSet->ToSetDrawEdges = -1;
2188 aChangeSet->ToSetEdgeColor = -1;
2189 aChangeSet->ToSetTypeOfEdge = -1;
2190 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2191 }
0493ffd0 2192 else if (aCmdName == "vshowfaceboundary")
2193 {
2194 aChangeSet->ToSetFaceBoundaryDraw = 1;
2195 toParseAliasArgs = true;
2196 if (aNames.Size() >= 2
2197 && aNames.Value (2).IsIntegerValue())
2198 {
2199 if (aNames.Size() == 7)
2200 {
2201 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2202 {
2203 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2204 aNames.Remove (7);
2205 }
2206 }
2207 if (aNames.Size() == 6
2208 && aNames.Value (6).IsRealValue())
2209 {
2210 aChangeSet->ToSetFaceBoundaryWidth = 1;
2211 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2212 aNames.Remove (6);
2213 }
2214 if (aNames.Size() == 5
2215 && aNames.Value (3).IsIntegerValue()
2216 && aNames.Value (4).IsIntegerValue()
2217 && aNames.Value (5).IsIntegerValue())
2218 {
2219 aChangeSet->ToSetFaceBoundaryColor = 1;
2220 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2221 aNames.Value (4).IntegerValue() / 255.0,
2222 aNames.Value (5).IntegerValue() / 255.0,
2223 Quantity_TOC_RGB);
2224 aNames.Remove (5);
2225 aNames.Remove (4);
2226 aNames.Remove (3);
2227 }
2228 if (aNames.Size() == 2)
2229 {
2230 toParseAliasArgs = false;
2231 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2232 aNames.Remove (2);
2233 }
2234 }
2235 }
ad3217cd 2236 else if (anArgIter >= theArgNb)
2237 {
2238 std::cout << "Error: not enough arguments!\n";
2239 return 1;
7fd59977 2240 }
2241
2a332745 2242 if (!aChangeSet->IsEmpty()
2243 && !toParseAliasArgs)
ad3217cd 2244 {
2245 anArgIter = theArgNb;
2246 }
2247 for (; anArgIter < theArgNb; ++anArgIter)
2248 {
2249 TCollection_AsciiString anArg = theArgVec[anArgIter];
2250 anArg.LowerCase();
2251 if (anArg == "-setwidth"
2a332745 2252 || anArg == "-width"
2253 || anArg == "-setlinewidth"
2254 || anArg == "-linewidth"
2255 || anArg == "-setedgewidth"
2256 || anArg == "-setedgeswidth"
2257 || anArg == "-edgewidth"
0493ffd0 2258 || anArg == "-edgeswidth"
2259 || anArg == "-setfaceboundarywidth"
2260 || anArg == "-setboundarywidth"
2261 || anArg == "-faceboundarywidth"
2262 || anArg == "-boundarywidth")
ad3217cd 2263 {
2264 if (++anArgIter >= theArgNb)
2265 {
2266 std::cout << "Error: wrong syntax at " << anArg << "\n";
2267 return 1;
2268 }
0493ffd0 2269
2270 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2a332745 2271 if (anArg == "-setedgewidth"
2272 || anArg == "-setedgeswidth"
2273 || anArg == "-edgewidth"
2274 || anArg == "-edgeswidth"
2275 || aCmdName == "vsetedgetype")
2276 {
2277 aChangeSet->ToSetEdgeWidth = 1;
0493ffd0 2278 aChangeSet->EdgeWidth = aWidth;
2279 }
2280 else if (anArg == "-setfaceboundarywidth"
2281 || anArg == "-setboundarywidth"
2282 || anArg == "-faceboundarywidth"
2283 || anArg == "-boundarywidth"
2284 || aCmdName == "vshowfaceboundary")
2285 {
2286 aChangeSet->ToSetFaceBoundaryWidth = 1;
2287 aChangeSet->FaceBoundaryWidth = aWidth;
2a332745 2288 }
2289 else
2290 {
2291 aChangeSet->ToSetLineWidth = 1;
0493ffd0 2292 aChangeSet->LineWidth = aWidth;
2a332745 2293 }
7fd59977 2294 }
ad3217cd 2295 else if (anArg == "-unsetwidth"
2a332745 2296 || anArg == "-unsetlinewidth"
2297 || anArg == "-unsetedgewidth")
ad3217cd 2298 {
2a332745 2299 if (anArg == "-unsetedgewidth")
2300 {
2301 aChangeSet->ToSetEdgeWidth = -1;
2302 aChangeSet->EdgeWidth = 1.0;
2303 }
2304 else
2305 {
2306 aChangeSet->ToSetLineWidth = -1;
2307 aChangeSet->LineWidth = 1.0;
2308 }
ad3217cd 2309 }
2310 else if (anArg == "-settransp"
2a332745 2311 || anArg == "-settransparency"
2312 || anArg == "-transparency"
2313 || anArg == "-transp")
ad3217cd 2314 {
2315 if (++anArgIter >= theArgNb)
2316 {
2317 std::cout << "Error: wrong syntax at " << anArg << "\n";
2318 return 1;
2319 }
2320 aChangeSet->ToSetTransparency = 1;
2321 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2322 if (aChangeSet->Transparency >= 0.0
2323 && aChangeSet->Transparency <= Precision::Confusion())
2324 {
2325 aChangeSet->ToSetTransparency = -1;
2326 aChangeSet->Transparency = 0.0;
eafb234b 2327 }
7fd59977 2328 }
2a332745 2329 else if (anArg == "-setalphamode"
2330 || anArg == "-alphamode")
c40eb6b9 2331 {
2332 if (++anArgIter >= theArgNb)
2333 {
2334 std::cout << "Error: wrong syntax at " << anArg << "\n";
2335 return 1;
2336 }
2337 aChangeSet->ToSetAlphaMode = 1;
2338 aChangeSet->AlphaCutoff = 0.5f;
2339 {
2340 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2341 aParam.LowerCase();
2342 if (aParam == "opaque")
2343 {
2344 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2345 }
2346 else if (aParam == "mask")
2347 {
2348 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2349 }
2350 else if (aParam == "blend")
2351 {
2352 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2353 }
2354 else if (aParam == "blendauto"
2355 || aParam == "auto")
2356 {
2357 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2358 }
2359 else
2360 {
2361 std::cout << "Error: wrong syntax at " << aParam << "\n";
2362 return 1;
2363 }
2364 }
2365
2366 if (anArgIter + 1 < theArgNb
2367 && theArgVec[anArgIter + 1][0] != '-')
2368 {
2369 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2370 if (aParam2.IsRealValue())
2371 {
2372 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2373 ++anArgIter;
2374 }
2375 }
2376 }
5bffb882 2377 else if (anArg == "-setvis"
2a332745 2378 || anArg == "-setvisibility"
2379 || anArg == "-visibility")
5bffb882 2380 {
2381 if (++anArgIter >= theArgNb)
2382 {
2383 std::cout << "Error: wrong syntax at " << anArg << "\n";
2384 return 1;
2385 }
2386
2387 aChangeSet->ToSetVisibility = 1;
2388 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2389 }
2a332745 2390 else if (anArg == "-setalpha"
2391 || anArg == "-alpha")
ad3217cd 2392 {
2393 if (++anArgIter >= theArgNb)
7fd59977 2394 {
ad3217cd 2395 std::cout << "Error: wrong syntax at " << anArg << "\n";
2396 return 1;
2397 }
2398 aChangeSet->ToSetTransparency = 1;
2399 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2400 if (aChangeSet->Transparency < 0.0
2401 || aChangeSet->Transparency > 1.0)
2402 {
2403 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2404 return 1;
2405 }
2406 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2407 if (aChangeSet->Transparency >= 0.0
2408 && aChangeSet->Transparency <= Precision::Confusion())
2409 {
2410 aChangeSet->ToSetTransparency = -1;
2411 aChangeSet->Transparency = 0.0;
7fd59977 2412 }
7fd59977 2413 }
ad3217cd 2414 else if (anArg == "-unsettransp"
0ae61cf3 2415 || anArg == "-unsettransparency"
ad3217cd 2416 || anArg == "-unsetalpha"
2417 || anArg == "-opaque")
2418 {
2419 aChangeSet->ToSetTransparency = -1;
2420 aChangeSet->Transparency = 0.0;
2421 }
2a332745 2422 else if (anArg == "-setcolor"
0493ffd0 2423 || anArg == "-color"
2424 || anArg == "-setfaceboundarycolor"
2425 || anArg == "-setboundarycolor"
2426 || anArg == "-faceboundarycolor"
2427 || anArg == "-boundarycolor")
ad3217cd 2428 {
2a332745 2429 Quantity_Color aColor;
2430 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2431 theArgVec + anArgIter + 1,
2432 aColor);
2433 if (aNbParsed == 0)
ad3217cd 2434 {
2a332745 2435 std::cout << "Syntax error at '" << anArg << "'\n";
2436 return 1;
8316c618 2437 }
2a332745 2438 anArgIter += aNbParsed;
2439 if (aCmdName == "vsetedgetype")
8316c618 2440 {
2a332745 2441 aChangeSet->ToSetEdgeColor = 1;
2442 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2443 }
0493ffd0 2444 else if (aCmdName == "vshowfaceboundary"
2445 || anArg == "-setfaceboundarycolor"
2446 || anArg == "-setboundarycolor"
2447 || anArg == "-faceboundarycolor"
2448 || anArg == "-boundarycolor")
2449 {
2450 aChangeSet->ToSetFaceBoundaryColor = 1;
2451 aChangeSet->FaceBoundaryColor = aColor;
2452 }
2a332745 2453 else
2454 {
2455 aChangeSet->ToSetColor = 1;
2456 aChangeSet->Color = aColor;
7fd59977 2457 }
7fd59977 2458 }
2a332745 2459 else if (anArg == "-setlinetype"
2460 || anArg == "-linetype"
2461 || anArg == "-setedgetype"
2462 || anArg == "-setedgestype"
2463 || anArg == "-edgetype"
2464 || anArg == "-edgestype"
0493ffd0 2465 || anArg == "-setfaceboundarystyle"
2466 || anArg == "-faceboundarystyle"
2467 || anArg == "-boundarystyle"
2468 || anArg == "-setfaceboundarytype"
2469 || anArg == "-faceboundarytype"
2470 || anArg == "-setboundarytype"
2471 || anArg == "-boundarytype"
2a332745 2472 || anArg == "-type")
ac116c22 2473 {
2474 if (++anArgIter >= theArgNb)
2475 {
2476 std::cout << "Error: wrong syntax at " << anArg << "\n";
2477 return 1;
2478 }
2a332745 2479 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2480 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
ac116c22 2481 {
2482 std::cout << "Error: wrong syntax at " << anArg << "\n";
2483 return 1;
2484 }
2a332745 2485 if (anArg == "-setedgetype"
2486 || anArg == "-setedgestype"
2487 || anArg == "-edgetype"
2488 || anArg == "-edgestype"
2489 || aCmdName == "vsetedgetype")
2490 {
2491 aChangeSet->TypeOfEdge = aLineType;
2492 aChangeSet->ToSetTypeOfEdge = 1;
2493 }
0493ffd0 2494 else if (anArg == "-setfaceboundarystyle"
2495 || anArg == "-faceboundarystyle"
2496 || anArg == "-boundarystyle"
2497 || anArg == "-setfaceboundarytype"
2498 || anArg == "-faceboundarytype"
2499 || anArg == "-setboundarytype"
2500 || anArg == "-boundarytype"
2501 || aCmdName == "vshowfaceboundary")
2502 {
2503 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2504 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2505 }
2a332745 2506 else
2507 {
2508 aChangeSet->TypeOfLine = aLineType;
2509 aChangeSet->ToSetTypeOfLine = 1;
2510 }
ac116c22 2511 }
2a332745 2512 else if (anArg == "-unsetlinetype"
2513 || anArg == "-unsetedgetype"
2514 || anArg == "-unsetedgestype")
ac116c22 2515 {
2a332745 2516 if (anArg == "-unsetedgetype"
2517 || anArg == "-unsetedgestype")
2518 {
2519 aChangeSet->ToSetTypeOfEdge = -1;
2520 }
2521 else
2522 {
2523 aChangeSet->ToSetTypeOfLine = -1;
2524 }
ac116c22 2525 }
33cc703b 2526 else if (anArg == "-setmarkertype"
2a332745 2527 || anArg == "-markertype"
2528 || anArg == "-setpointtype"
2529 || anArg == "-pointtype")
33cc703b 2530 {
2531 if (++anArgIter >= theArgNb)
2532 {
2533 std::cout << "Error: wrong syntax at " << anArg << "\n";
2534 return 1;
2535 }
2536 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2537 {
2538 std::cout << "Error: wrong syntax at " << anArg << "\n";
2539 return 1;
2540 }
2541
2542 aChangeSet->ToSetTypeOfMarker = 1;
2543 }
2544 else if (anArg == "-unsetmarkertype"
2545 || anArg == "-unsetpointtype")
2546 {
2547 aChangeSet->ToSetTypeOfMarker = -1;
2548 }
2549 else if (anArg == "-setmarkersize"
2a332745 2550 || anArg == "-markersize"
2551 || anArg == "-setpointsize"
2552 || anArg == "-pointsize")
33cc703b 2553 {
2554 if (++anArgIter >= theArgNb)
2555 {
2556 std::cout << "Error: wrong syntax at " << anArg << "\n";
2557 return 1;
2558 }
2559 aChangeSet->ToSetMarkerSize = 1;
2560 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2561 }
2562 else if (anArg == "-unsetmarkersize"
2563 || anArg == "-unsetpointsize")
2564 {
2565 aChangeSet->ToSetMarkerSize = -1;
2566 aChangeSet->MarkerSize = 1.0;
2567 }
ad3217cd 2568 else if (anArg == "-unsetcolor")
2569 {
2570 aChangeSet->ToSetColor = -1;
2571 aChangeSet->Color = DEFAULT_COLOR;
2572 }
2573 else if (anArg == "-setmat"
2a332745 2574 || anArg == "-mat"
2575 || anArg == "-setmaterial"
2576 || anArg == "-material")
ad3217cd 2577 {
2578 if (++anArgIter >= theArgNb)
2579 {
2580 std::cout << "Error: wrong syntax at " << anArg << "\n";
2581 return 1;
2582 }
2583 aChangeSet->ToSetMaterial = 1;
2584 aChangeSet->MatName = theArgVec[anArgIter];
2585 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2586 }
2587 else if (anArg == "-unsetmat"
2588 || anArg == "-unsetmaterial")
2589 {
2590 aChangeSet->ToSetMaterial = -1;
2591 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2592 }
2593 else if (anArg == "-subshape"
2594 || anArg == "-subshapes")
2595 {
6262338c 2596 if (isDefaults)
2597 {
2598 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2599 return 1;
2600 }
2601
ad3217cd 2602 if (aNames.IsEmpty())
2603 {
2604 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2605 return 1;
2606 }
7fd59977 2607
ad3217cd 2608 aChanges.Append (ViewerTest_AspectsChangeSet());
2609 aChangeSet = &aChanges.ChangeLast();
7fd59977 2610
ad3217cd 2611 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2612 {
2613 Standard_CString aSubShapeName = theArgVec[anArgIter];
2614 if (*aSubShapeName == '-')
2615 {
2616 --anArgIter;
2617 break;
2618 }
7fd59977 2619
ad3217cd 2620 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2621 if (aSubShape.IsNull())
2622 {
2623 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2624 return 1;
2625 }
2626 aChangeSet->SubShapes.Append (aSubShape);
2627 }
7fd59977 2628
ad3217cd 2629 if (aChangeSet->SubShapes.IsEmpty())
2630 {
2631 std::cerr << "Error: empty list is specified after -subshapes!\n";
2632 return 1;
2633 }
2634 }
2a332745 2635 else if (anArg == "-setfreeboundary"
2636 || anArg == "-freeboundary"
2637 || anArg == "-setfb"
6262338c 2638 || anArg == "-fb")
2639 {
0493ffd0 2640 bool toEnable = true;
2641 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
6262338c 2642 {
2643 std::cout << "Error: wrong syntax at " << anArg << "\n";
2644 return 1;
2645 }
0493ffd0 2646 ++anArgIter;
2647 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
6262338c 2648 }
2649 else if (anArg == "-setfreeboundarywidth"
2a332745 2650 || anArg == "-freeboundarywidth"
2651 || anArg == "-setfbwidth"
2652 || anArg == "-fbwidth")
6262338c 2653 {
2654 if (++anArgIter >= theArgNb)
2655 {
2656 std::cout << "Error: wrong syntax at " << anArg << "\n";
2657 return 1;
2658 }
2659 aChangeSet->ToSetFreeBoundaryWidth = 1;
2660 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2661 }
2662 else if (anArg == "-unsetfreeboundarywidth"
2663 || anArg == "-unsetfbwidth")
2664 {
2665 aChangeSet->ToSetFreeBoundaryWidth = -1;
2666 aChangeSet->FreeBoundaryWidth = 1.0;
2667 }
2668 else if (anArg == "-setfreeboundarycolor"
2a332745 2669 || anArg == "-freeboundarycolor"
2670 || anArg == "-setfbcolor"
2671 || anArg == "-fbcolor")
6262338c 2672 {
2a332745 2673 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2674 theArgVec + anArgIter + 1,
2675 aChangeSet->FreeBoundaryColor);
2676 if (aNbParsed == 0)
6262338c 2677 {
2a332745 2678 std::cout << "Syntax error at '" << anArg << "'\n";
2679 return 1;
6262338c 2680 }
2a332745 2681 anArgIter += aNbParsed;
6262338c 2682 aChangeSet->ToSetFreeBoundaryColor = 1;
6262338c 2683 }
2684 else if (anArg == "-unsetfreeboundarycolor"
2685 || anArg == "-unsetfbcolor")
2686 {
2687 aChangeSet->ToSetFreeBoundaryColor = -1;
2688 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2689 }
2a332745 2690 else if (anArg == "-setisoontriangulation"
2691 || anArg == "-isoontriangulation"
2692 || anArg == "-setisoontriang"
5ad8c033 2693 || anArg == "-isoontriang")
2694 {
0493ffd0 2695 bool toEnable = true;
2696 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
5ad8c033 2697 {
2698 std::cout << "Error: wrong syntax at " << anArg << "\n";
2699 return 1;
2700 }
0493ffd0 2701 ++anArgIter;
2702 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2703 }
2704 else if (anArg == "-setfaceboundarydraw"
2705 || anArg == "-setdrawfaceboundary"
2706 || anArg == "-setdrawfaceboundaries"
2707 || anArg == "-setshowfaceboundary"
2708 || anArg == "-setshowfaceboundaries"
2709 || anArg == "-setdrawfaceedges"
2710 || anArg == "-faceboundarydraw"
2711 || anArg == "-drawfaceboundary"
2712 || anArg == "-drawfaceboundaries"
2713 || anArg == "-showfaceboundary"
2714 || anArg == "-showfaceboundaries"
2715 || anArg == "-drawfaceedges"
2716 || anArg == "-faceboundary"
2717 || anArg == "-faceboundaries"
2718 || anArg == "-faceedges")
2719 {
2720 bool toEnable = true;
2721 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2722 {
2723 std::cout << "Error: wrong syntax at " << anArg << "\n";
2724 return 1;
2725 }
2726 ++anArgIter;
2727 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
2728 }
2729 else if (anArg == "-unsetfaceboundary"
2730 || anArg == "-unsetboundary")
2731 {
2732 aChangeSet->ToSetFaceBoundaryDraw = -1;
2733 aChangeSet->ToSetFaceBoundaryColor = -1;
2734 }
2735 else if (anArg == "-setmostcontinuity"
2736 || anArg == "-mostcontinuity")
2737 {
2738 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
2739 aClassArg.LowerCase();
2740 GeomAbs_Shape aClass = GeomAbs_CN;
2741 if (aClassArg == "c0"
2742 || aClassArg == "0")
5ad8c033 2743 {
0493ffd0 2744 aClass = GeomAbs_C0;
5ad8c033 2745 }
0493ffd0 2746 else if (aClassArg == "c1"
2747 || aClassArg == "1")
5ad8c033 2748 {
0493ffd0 2749 aClass = GeomAbs_C1;
2750 }
2751 else if (aClassArg == "c2"
2752 || aClassArg == "2")
2753 {
2754 aClass = GeomAbs_C2;
2755 }
2756 else if (aClassArg == "c3"
2757 || aClassArg == "3")
2758 {
2759 aClass = GeomAbs_C3;
2760 }
2761 else if (aClassArg == "cn"
2762 || aClassArg == "n")
2763 {
2764 aClass = GeomAbs_CN;
5ad8c033 2765 }
2766 else
2767 {
0493ffd0 2768 std::cout << "Syntax error at '" << anArg << "'\n";
5ad8c033 2769 return 1;
2770 }
0493ffd0 2771
2772 ++anArgIter;
2773 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
2774 aChangeSet->FaceBoundaryUpperContinuity = aClass;
5ad8c033 2775 }
2a332745 2776 else if (anArg == "-setmaxparamvalue"
2777 || anArg == "-maxparamvalue")
5ad8c033 2778 {
2779 if (++anArgIter >= theArgNb)
2780 {
2781 std::cout << "Error: wrong syntax at " << anArg << "\n";
2782 return 1;
2783 }
2784 aChangeSet->ToSetMaxParamValue = 1;
2785 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2786 }
2a332745 2787 else if (anArg == "-setsensitivity"
2788 || anArg == "-sensitivity")
8a1170ad 2789 {
2790 if (isDefaults)
2791 {
2792 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2793 return 1;
2794 }
2795
2796 if (aNames.IsEmpty())
2797 {
2798 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2799 return 1;
2800 }
2801
2802 if (anArgIter + 2 >= theArgNb)
2803 {
2804 std::cout << "Error: wrong syntax at " << anArg << "\n";
2805 return 1;
2806 }
2807 aChangeSet->ToSetSensitivity = 1;
2808 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2809 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2810 }
2a332745 2811 else if (anArg == "-sethatch"
2812 || anArg == "-hatch")
640d5fe2 2813 {
2814 if (isDefaults)
2815 {
2816 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2817 return 1;
2818 }
2819
2820 if (aNames.IsEmpty())
2821 {
2822 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2823 return 1;
2824 }
2825
2826 aChangeSet->ToSetHatch = 1;
eadea5ea 2827 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2828 if (anArgHatch.Length() <= 2)
640d5fe2 2829 {
ec7c343f 2830 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2831 if (anIntStyle < 0
2832 || anIntStyle >= Aspect_HS_NB)
2833 {
2834 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2835 return 1;
2836 }
2837 aChangeSet->StdHatchStyle = anIntStyle;
640d5fe2 2838 }
2839 else
2840 {
eadea5ea 2841 aChangeSet->PathToHatchPattern = anArgHatch;
640d5fe2 2842 }
2843 }
2a332745 2844 else if (anArg == "-setshadingmodel"
2845 || anArg == "-setshading"
2846 || anArg == "-shadingmodel"
2847 || anArg == "-shading")
dc89236f 2848 {
2849 if (++anArgIter >= theArgNb)
2850 {
2851 std::cout << "Error: wrong syntax at " << anArg << "\n";
2852 return 1;
2853 }
2854 aChangeSet->ToSetShadingModel = 1;
2855 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2856 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2857 {
2858 std::cout << "Error: wrong syntax at " << anArg << "\n";
2859 return 1;
2860 }
2861 }
2862 else if (anArg == "-unsetshadingmodel")
2863 {
2864 aChangeSet->ToSetShadingModel = -1;
2865 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2866 }
2a332745 2867 else if (anArg == "-setinterior"
2868 || anArg == "-setinteriorstyle"
2869 || anArg == "-interior"
2870 || anArg == "-interiorstyle")
2871 {
2872 if (++anArgIter >= theArgNb)
2873 {
2874 std::cout << "Error: wrong syntax at " << anArg << "\n";
2875 return 1;
2876 }
2877 aChangeSet->ToSetInterior = 1;
2878 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
2879 {
2880 std::cout << "Error: wrong syntax at " << anArg << "\n";
2881 return 1;
2882 }
2883 }
2884 else if (anArg == "-unsetinterior")
2885 {
2886 aChangeSet->ToSetInterior = -1;
2887 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
2888 }
2889 else if (anArg == "-setdrawedges"
2890 || anArg == "-setdrawedge"
2891 || anArg == "-drawedges"
2892 || anArg == "-drawedge"
2893 || anArg == "-edges")
2894 {
2895 bool toDrawEdges = true;
2896 if (anArgIter + 1 < theArgNb
2897 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
2898 {
2899 ++anArgIter;
2900 }
2901 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
2902 }
2903 else if (anArg == "-setquadedges"
2904 || anArg == "-setquads"
2905 || anArg == "-quads"
2906 || anArg == "-skipfirstedge")
2907 {
2908 bool isQuadMode = true;
2909 if (anArgIter + 1 < theArgNb
2910 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
2911 {
2912 ++anArgIter;
2913 }
2914 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
2915 }
2916 else if (anArg == "-setedgecolor"
2917 || anArg == "-setedgescolor"
2918 || anArg == "-edgecolor"
2919 || anArg == "-edgescolor")
2920 {
2921 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2922 theArgVec + anArgIter + 1,
2923 aChangeSet->EdgeColor);
2924 if (aNbParsed == 0)
2925 {
2926 std::cout << "Syntax error at '" << anArg << "'\n";
2927 return 1;
2928 }
2929 anArgIter += aNbParsed;
2930 aChangeSet->ToSetEdgeColor = 1;
2931 }
2932 else if (anArg == "-unset")
2933 {
2934 aChangeSet->ToSetVisibility = 1;
2935 aChangeSet->Visibility = 1;
2936 aChangeSet->ToSetLineWidth = -1;
2937 aChangeSet->LineWidth = 1.0;
2938 aChangeSet->ToSetTypeOfLine = -1;
2939 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2940 aChangeSet->ToSetTypeOfMarker = -1;
2941 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2942 aChangeSet->ToSetMarkerSize = -1;
2943 aChangeSet->MarkerSize = 1.0;
2944 aChangeSet->ToSetTransparency = -1;
2945 aChangeSet->Transparency = 0.0;
2946 aChangeSet->ToSetAlphaMode = -1;
2947 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2948 aChangeSet->AlphaCutoff = 0.5f;
2949 aChangeSet->ToSetColor = -1;
2950 aChangeSet->Color = DEFAULT_COLOR;
2951 aChangeSet->ToSetMaterial = -1;
2952 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2953 aChangeSet->ToSetShowFreeBoundary = -1;
2954 aChangeSet->ToSetFreeBoundaryColor = -1;
2955 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2956 aChangeSet->ToSetFreeBoundaryWidth = -1;
2957 aChangeSet->FreeBoundaryWidth = 1.0;
0493ffd0 2958 aChangeSet->ToEnableIsoOnTriangulation = -1;
2959 //
2960 aChangeSet->ToSetFaceBoundaryDraw = -1;
2961 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
2962 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
2963 aChangeSet->ToSetFaceBoundaryColor = -1;
2964 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
2965 aChangeSet->ToSetFaceBoundaryWidth = -1;
2966 aChangeSet->FaceBoundaryWidth = 1.0f;
2967 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
2968 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
2969 //
2a332745 2970 aChangeSet->ToSetHatch = -1;
2971 aChangeSet->StdHatchStyle = -1;
2972 aChangeSet->PathToHatchPattern.Clear();
2973 aChangeSet->ToSetShadingModel = -1;
2974 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2975 aChangeSet->ToSetInterior = -1;
2976 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
2977 aChangeSet->ToSetDrawEdges = -1;
2978 aChangeSet->ToSetQuadEdges = -1;
2979 aChangeSet->ToSetEdgeColor = -1;
2980 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
2981 aChangeSet->ToSetEdgeWidth = -1;
2982 aChangeSet->EdgeWidth = 1.0;
2983 aChangeSet->ToSetTypeOfEdge = -1;
2984 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2985 }
7fd59977 2986 else
ad3217cd 2987 {
2988 std::cout << "Error: wrong syntax at " << anArg << "\n";
2989 return 1;
2990 }
7fd59977 2991 }
99c56d44 2992
ad3217cd 2993 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2994 aChangesIter.More(); aChangesIter.Next())
2995 {
c1197a15 2996 if (!aChangesIter.Value().Validate())
ad3217cd 2997 {
2998 return 1;
2999 }
99c56d44 3000 }
99c56d44 3001
6262338c 3002 // special case for -defaults parameter.
3003 // all changed values will be set to DefaultDrawer.
3004 if (isDefaults)
3005 {
3006 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2a332745 3007 aChangeSet->Apply (aDrawer);
6262338c 3008 if (aChangeSet->ToSetLineWidth != 0)
3009 {
3010 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3011 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3012 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3013 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3014 }
3015 if (aChangeSet->ToSetColor != 0)
3016 {
3017 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3018 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3019 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3020 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3021 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3022 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3023 }
3024 if (aChangeSet->ToSetTransparency != 0)
3025 {
3026 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3027 }
3028 if (aChangeSet->ToSetMaterial != 0)
3029 {
3030 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3031 }
0493ffd0 3032 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
5ad8c033 3033 {
3034 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3035 }
6262338c 3036
3037 // redisplay all objects in context
3038 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3039 {
3040 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3041 if (!aPrs.IsNull())
3042 {
3043 aCtx->Redisplay (aPrs, Standard_False);
3044 }
3045 }
3046 return 0;
3047 }
3048
ad3217cd 3049 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3050 {
25c35042 3051 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3052 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3053 if (aPrs.IsNull())
3054 {
3055 return 1;
3056 }
3057
6262338c 3058 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 3059 Handle(AIS_ColoredShape) aColoredPrs;
3060 Standard_Boolean toDisplay = Standard_False;
6262338c 3061 Standard_Boolean toRedisplay = Standard_False;
5bffb882 3062 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 3063 {
3064 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3065 if (aShapePrs.IsNull())
3066 {
3067 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3068 return 1;
3069 }
3070 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3071 if (aColoredPrs.IsNull())
3072 {
3073 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3e05329c 3074 if (aShapePrs->HasDisplayMode())
3075 {
3076 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3077 }
3078 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
ad3217cd 3079 aCtx->Remove (aShapePrs, Standard_False);
3080 GetMapOfAIS().UnBind2 (aName);
3081 GetMapOfAIS().Bind (aColoredPrs, aName);
3082 toDisplay = Standard_True;
3083 aShapePrs = aColoredPrs;
3084 aPrs = aColoredPrs;
3085 }
3086 }
99c56d44 3087
ad3217cd 3088 if (!aPrs.IsNull())
3089 {
3090 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3091 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 3092 if (aChangeSet->ToSetVisibility == 1)
3093 {
3094 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3095 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3096 }
3097 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 3098 {
3099 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3100 }
3101 else if (aChangeSet->ToSetMaterial == -1)
3102 {
3103 aCtx->UnsetMaterial (aPrs, Standard_False);
3104 }
3105 if (aChangeSet->ToSetColor == 1)
3106 {
3107 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3108 }
3109 else if (aChangeSet->ToSetColor == -1)
3110 {
3111 aCtx->UnsetColor (aPrs, Standard_False);
3112 }
3113 if (aChangeSet->ToSetTransparency == 1)
3114 {
3115 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3116 }
3117 else if (aChangeSet->ToSetTransparency == -1)
3118 {
3119 aCtx->UnsetTransparency (aPrs, Standard_False);
3120 }
3121 if (aChangeSet->ToSetLineWidth == 1)
3122 {
3123 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3124 }
3125 else if (aChangeSet->ToSetLineWidth == -1)
3126 {
3127 aCtx->UnsetWidth (aPrs, Standard_False);
3128 }
0493ffd0 3129 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
5ad8c033 3130 {
3131 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3132 toRedisplay = Standard_True;
3133 }
8a1170ad 3134 else if (aChangeSet->ToSetSensitivity != 0)
3135 {
3136 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3137 }
6262338c 3138 if (!aDrawer.IsNull())
3139 {
2a332745 3140 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
6262338c 3141 }
99c56d44 3142
ad3217cd 3143 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3144 {
3145 aChangeSet = &aChangesIter.ChangeValue();
3146 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3147 aSubShapeIter.More(); aSubShapeIter.Next())
3148 {
3149 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2a332745 3150 if (!aChangeSet->IsEmpty())
3151 {
3152 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3153 aChangeSet->Apply (aCurColDrawer);
3154 }
5bffb882 3155 if (aChangeSet->ToSetVisibility == 1)
3156 {
3157 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3158 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3159 }
ad3217cd 3160 if (aChangeSet->ToSetColor == 1)
3161 {
3162 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3163 }
c1197a15 3164 if (aChangeSet->ToSetTransparency == 1)
3165 {
3166 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3167 }
ad3217cd 3168 if (aChangeSet->ToSetLineWidth == 1)
3169 {
3170 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3171 }
3172 if (aChangeSet->ToSetColor == -1
3173 || aChangeSet->ToSetLineWidth == -1)
3174 {
3175 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3176 }
8a1170ad 3177 if (aChangeSet->ToSetSensitivity != 0)
3178 {
3179 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3180 }
ad3217cd 3181 }
3182 }
3183 if (toDisplay)
3184 {
3185 aCtx->Display (aPrs, Standard_False);
3186 }
6262338c 3187 if (toRedisplay)
3188 {
3189 aCtx->Redisplay (aPrs, Standard_False);
3190 }
ad3217cd 3191 else if (!aColoredPrs.IsNull())
3192 {
36132a2e 3193 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 3194 }
2a332745 3195 else
3196 {
3197 aPrs->SynchronizeAspects();
3198 }
99c56d44 3199 }
ad3217cd 3200 }
99c56d44 3201 return 0;
3202}
3203
7fd59977 3204//==============================================================================
3205//function : VDonly2
3206//author : ege
3207//purpose : Display only a selected or named object
519d35d8 3208// if there is no selected or named object s, nothing is done
7fd59977 3209//==============================================================================
519d35d8 3210static int VDonly2 (Draw_Interpretor& ,
3211 Standard_Integer theArgNb,
3212 const char** theArgVec)
7fd59977 3213{
519d35d8 3214 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 3215 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 3216 if (aCtx.IsNull())
3217 {
3218 std::cerr << "Error: no active view!\n";
7fd59977 3219 return 1;
519d35d8 3220 }
7fd59977 3221
519d35d8 3222 Standard_Integer anArgIter = 1;
3223 for (; anArgIter < theArgNb; ++anArgIter)
3224 {
4e18052b 3225 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 3226 {
3227 break;
3228 }
3229 }
7fd59977 3230
519d35d8 3231 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3232 if (anArgIter >= theArgNb)
3233 {
3234 // display only selected objects
c3282ec1 3235 if (aCtx->NbSelected() < 1)
519d35d8 3236 {
3237 return 0;
7fd59977 3238 }
3239
c3282ec1 3240 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 3241 {
c3282ec1 3242 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 3243 }
3244 }
3245 else
3246 {
3247 // display only specified objects
3248 for (; anArgIter < theArgNb; ++anArgIter)
3249 {
3250 TCollection_AsciiString aName = theArgVec[anArgIter];
8f521168 3251 Handle(AIS_InteractiveObject) aShape;
3252 if (GetMapOfAIS().Find2 (aName, aShape)
3253 && !aShape.IsNull())
519d35d8 3254 {
8f521168 3255 aCtx->Display (aShape, Standard_False);
3256 aDispSet.Add (aShape);
7fd59977 3257 }
3258 }
7fd59977 3259 }
519d35d8 3260
3261 // weed out other objects
3262 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3263 {
3264 if (aDispSet.Contains (anIter.Key1()))
3265 {
3266 continue;
3267 }
3268
8f521168 3269 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
519d35d8 3270 {
519d35d8 3271 aCtx->Erase (aShape, Standard_False);
3272 }
519d35d8 3273 }
7fd59977 3274 return 0;
3275}
3276
eef7fc64 3277//==============================================================================
3278//function : VRemove
3279//purpose : Removes selected or named objects.
3280// If there is no selected or named objects,
3281// all objects in the viewer can be removed with argument -all.
3282// If -context is in arguments, the object is not deleted from the map of
3283// objects (deleted only from the current context).
3284//==============================================================================
3285int VRemove (Draw_Interpretor& theDI,
519d35d8 3286 Standard_Integer theArgNb,
3287 const char** theArgVec)
eef7fc64 3288{
4e18052b 3289 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3290 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3291 if (aCtx.IsNull())
eef7fc64 3292 {
b6d587e3 3293 std::cerr << "Error: no active view!\n";
eef7fc64 3294 return 1;
3295 }
3296
4e18052b 3297 Standard_Boolean isContextOnly = Standard_False;
3298 Standard_Boolean toRemoveAll = Standard_False;
3299 Standard_Boolean toPrintInfo = Standard_True;
519d35d8 3300
3301 Standard_Integer anArgIter = 1;
3302 for (; anArgIter < theArgNb; ++anArgIter)
3303 {
3304 TCollection_AsciiString anArg = theArgVec[anArgIter];
3305 anArg.LowerCase();
3306 if (anArg == "-context")
3307 {
3308 isContextOnly = Standard_True;
3309 }
3310 else if (anArg == "-all")
3311 {
3312 toRemoveAll = Standard_True;
3313 }
b7cd4ba7 3314 else if (anArg == "-noinfo")
3315 {
3316 toPrintInfo = Standard_False;
3317 }
b6d587e3 3318 else if (anUpdateTool.parseRedrawMode (anArg))
3319 {
3320 continue;
3321 }
3322 else
519d35d8 3323 {
3324 break;
3325 }
3326 }
3327 if (toRemoveAll
3328 && anArgIter < theArgNb)
3329 {
b6d587e3 3330 std::cerr << "Error: wrong syntax!\n";
3331 return 1;
3332 }
3333
eef7fc64 3334 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 3335 if (toRemoveAll)
eef7fc64 3336 {
3337 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3338 anIter.More(); anIter.Next())
3339 {
3340 anIONameList.Append (anIter.Key2());
3341 }
3342 }
519d35d8 3343 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 3344 {
519d35d8 3345 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 3346 {
519d35d8 3347 TCollection_AsciiString aName = theArgVec[anArgIter];
8f521168 3348 Handle(AIS_InteractiveObject) anIO;
3349 if (!GetMapOfAIS().Find2 (aName, anIO))
eef7fc64 3350 {
8f521168 3351 theDI << aName << " was not bound to some object.\n";
eef7fc64 3352 continue;
3353 }
3354
d09dda09 3355 if (anIO->GetContext() != aCtx)
eef7fc64 3356 {
8f521168 3357 theDI << aName << " was not displayed in current context.\n";
d09dda09 3358 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 3359 continue;
3360 }
3361
d09dda09 3362 anIONameList.Append (aName);
3363 continue;
eef7fc64 3364 }
3365 }
c3282ec1 3366 else if (aCtx->NbSelected() > 0)
eef7fc64 3367 {
3368 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3369 anIter.More(); anIter.Next())
3370 {
8f521168 3371 if (!aCtx->IsSelected (anIter.Key1()))
eef7fc64 3372 {
eef7fc64 3373 continue;
3374 }
3375
d09dda09 3376 anIONameList.Append (anIter.Key2());
3377 continue;
eef7fc64 3378 }
3379 }
3380
3381 // Unbind all removed objects from the map of displayed IO.
3382 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3383 anIter.More(); anIter.Next())
3384 {
8f521168 3385 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
d09dda09 3386 aCtx->Remove (anIO, Standard_False);
3387 if (toPrintInfo)
519d35d8 3388 {
8f521168 3389 theDI << anIter.Value() << " was removed\n";
519d35d8 3390 }
519d35d8 3391 if (!isContextOnly)
3392 {
3393 GetMapOfAIS().UnBind2 (anIter.Value());
3394 }
3395 }
eef7fc64 3396 return 0;
3397}
3398
7fd59977 3399//==============================================================================
b514beda 3400//function : VErase
3401//purpose : Erase some selected or named objects
7fd59977 3402// if there is no selected or named objects, the whole viewer is erased
7fd59977 3403//==============================================================================
b514beda 3404int VErase (Draw_Interpretor& theDI,
3405 Standard_Integer theArgNb,
3406 const char** theArgVec)
7fd59977 3407{
a1954302 3408 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3409 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3410 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 3411 if (aCtx.IsNull())
b514beda 3412 {
b6d587e3 3413 std::cerr << "Error: no active view!\n";
7fd59977 3414 return 1;
b514beda 3415 }
519d35d8 3416
519d35d8 3417 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3418
3419 Standard_Integer anArgIter = 1;
a272ed94 3420 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 3421 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 3422 for (; anArgIter < theArgNb; ++anArgIter)
3423 {
b6d587e3 3424 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3425 anArgCase.LowerCase();
3426 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 3427 {
b6d587e3 3428 continue;
3429 }
a272ed94 3430 else if (anArgCase == "-view"
3431 || anArgCase == "-inview")
3432 {
3433 toEraseInView = Standard_True;
3434 }
b6d587e3 3435 else
3436 {
3437 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 3438 }
3439 }
3440
b6d587e3 3441 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 3442 {