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