0030638: Visualization, TKOpenGl - load OpenGL 4.5 functions within OpenGl_Context
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17#include <Standard_Stream.hxx>
18
19#include <ViewerTest.hxx>
189f85a3 20#include <ViewerTest_CmdParser.hxx>
4e18052b 21
3a4a3962 22#include <Draw.hxx>
7fd59977 23#include <TopLoc_Location.hxx>
24#include <TopTools_HArray1OfShape.hxx>
25#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 26#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 27#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 28#include <TColStd_MapOfTransient.hxx>
7fd59977 29#include <OSD_Timer.hxx>
30#include <Geom_Axis2Placement.hxx>
31#include <Geom_Axis1Placement.hxx>
32#include <gp_Trsf.hxx>
33#include <TopExp_Explorer.hxx>
34#include <BRepAdaptor_Curve.hxx>
35#include <StdSelect_ShapeTypeFilter.hxx>
36#include <AIS.hxx>
ad3217cd 37#include <AIS_ColoredShape.hxx>
7fd59977 38#include <AIS_InteractiveObject.hxx>
39#include <AIS_Trihedron.hxx>
40#include <AIS_Axis.hxx>
41#include <AIS_Relation.hxx>
42#include <AIS_TypeFilter.hxx>
43#include <AIS_SignatureFilter.hxx>
44#include <AIS_ListOfInteractive.hxx>
45#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 46#include <Aspect_InteriorStyle.hxx>
34db9c00 47#include <Aspect_Window.hxx>
99c56d44 48#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 49#include <Graphic3d_AspectLine3d.hxx>
a1954302 50#include <Graphic3d_CStructure.hxx>
a6dee93d 51#include <Graphic3d_Texture2Dmanual.hxx>
cc8cbabe 52#include <Graphic3d_GraphicDriver.hxx>
692613e5 53#include <Image_AlienPixMap.hxx>
a6dee93d 54#include <OSD_File.hxx>
6262338c 55#include <Prs3d_Drawer.hxx>
99c56d44 56#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 57#include <Prs3d_IsoAspect.hxx>
6262338c 58#include <Prs3d_PointAspect.hxx>
8e7c8ccf 59#include <Select3D_SensitiveWire.hxx>
8b9a309b 60#include <Select3D_SensitivePrimitiveArray.hxx>
8e7c8ccf 61#include <SelectMgr_EntityOwner.hxx>
62#include <StdSelect_BRepOwner.hxx>
63#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 64#include <TopTools_MapOfShape.hxx>
4e18052b 65#include <ViewerTest_AutoUpdater.hxx>
7fd59977 66
7fd59977 67#include <stdio.h>
7fd59977 68
69#include <Draw_Interpretor.hxx>
70#include <TCollection_AsciiString.hxx>
71#include <Draw_PluginMacro.hxx>
7fd59977 72
7fd59977 73extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
74
7fd59977 75#include <Quantity_Color.hxx>
76#include <Quantity_NameOfColor.hxx>
77
78#include <Graphic3d_NameOfMaterial.hxx>
79
6262338c 80#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
81#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
82#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 83
792c785c 84//=======================================================================
85//function : GetColorFromName
86//purpose : get the Quantity_NameOfColor from a string
87//=======================================================================
7fd59977 88
792c785c 89Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
90{
8316c618 91 Quantity_NameOfColor aColor = DEFAULT_COLOR;
92 Quantity_Color::ColorFromName (theName, aColor);
93 return aColor;
7fd59977 94}
95
2a332745 96
536d98e2 97//=======================================================================
2a332745 98//function : parseColor
536d98e2 99//purpose :
100//=======================================================================
2a332745 101Standard_Integer ViewerTest::parseColor (Standard_Integer theArgNb,
536d98e2 102 const char** theArgVec,
2a332745 103 Quantity_ColorRGBA& theColor,
104 bool theToParseAlpha)
536d98e2 105{
106 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
107 if (theArgNb >= 1
108 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
109 {
2a332745 110 theColor = Quantity_ColorRGBA (aColor);
111 if (theArgNb >= 2
112 && theToParseAlpha)
113 {
114 const TCollection_AsciiString anAlphaStr (theArgVec[1]);
115 if (anAlphaStr.IsRealValue())
116 {
117 float anAlpha = (float )anAlphaStr.RealValue();
118 if (anAlpha < 0.0f || anAlpha > 1.0f)
119 {
120 std::cout << "Syntax error: alpha should be within range 0..1!\n";
121 return 0;
122 }
123 return 2;
124 }
125 }
536d98e2 126 return 1;
127 }
128 else if (theArgNb >= 3)
129 {
bf5f0ca2 130 Graphic3d_Vec4 anRgba (0.0f, 0.0f, 0.0f, 1.0f);
2a332745 131 Standard_Integer aNbComps = Min (theArgNb, theToParseAlpha ? 4 : 3);
132 for (int aCompIter = 0; aCompIter < aNbComps; ++aCompIter)
536d98e2 133 {
2a332745 134 const TCollection_AsciiString anRgbaStr (theArgVec[aCompIter]);
135 if (!anRgbaStr.IsRealValue())
136 {
137 if (aCompIter == 3)
138 {
139 anRgba.a() = 1.0f;
140 aNbComps = 3;
141 break;
142 }
143 return 0;
144 }
536d98e2 145
2a332745 146 anRgba[aCompIter] = (float )anRgbaStr.RealValue();
147 if (anRgba[aCompIter] < 0.0 || anRgba[aCompIter] > 1.0)
148 {
149 std::cout << "Error: RGBA color values should be within range 0..1!\n";
150 return 0;
151 }
536d98e2 152 }
2a332745 153 theColor = Quantity_ColorRGBA (anRgba);
154 return aNbComps;
536d98e2 155 }
156
157 return 0;
158}
159
a5565a3c 160//=======================================================================
161//function : ParseOnOff
162//purpose :
163//=======================================================================
164Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
165 Standard_Boolean& theIsOn)
166{
167 TCollection_AsciiString aFlag(theArg);
168 aFlag.LowerCase();
169 if (aFlag == "on"
170 || aFlag == "1")
171 {
172 theIsOn = Standard_True;
173 return Standard_True;
174 }
175 else if (aFlag == "off"
176 || aFlag == "0")
177 {
178 theIsOn = Standard_False;
179 return Standard_True;
180 }
181 return Standard_False;
182}
183
404c8936 184//=======================================================================
185//function : GetSelectedShapes
186//purpose :
187//=======================================================================
188void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
189{
190 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
191 {
192 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
193 if (!aShape.IsNull())
194 {
195 theSelectedShapes.Append (aShape);
196 }
197 }
198}
199
3a4a3962 200//=======================================================================
201//function : ParseLineType
202//purpose :
203//=======================================================================
204Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
205 Aspect_TypeOfLine& theType)
206{
207 TCollection_AsciiString aTypeStr (theArg);
208 aTypeStr.LowerCase();
209 if (aTypeStr == "empty")
210 {
211 theType = Aspect_TOL_EMPTY;
212 }
213 else if (aTypeStr == "solid")
214 {
215 theType = Aspect_TOL_SOLID;
216 }
217 else if (aTypeStr == "dot")
218 {
219 theType = Aspect_TOL_DOT;
220 }
221 else if (aTypeStr == "dash")
222 {
223 theType = Aspect_TOL_DASH;
224 }
225 else if (aTypeStr == "dotdash")
226 {
227 theType = Aspect_TOL_DOTDASH;
228 }
2a332745 229 else if (aTypeStr.IsIntegerValue())
3a4a3962 230 {
2a332745 231 const int aTypeInt = aTypeStr.IntegerValue();
3a4a3962 232 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
233 {
234 return Standard_False;
235 }
236 theType = (Aspect_TypeOfLine )aTypeInt;
237 }
2a332745 238 else
239 {
240 return Standard_False;
241 }
3a4a3962 242 return Standard_True;
243}
244
33cc703b 245//=======================================================================
246//function : ParseMarkerType
247//purpose :
248//=======================================================================
249Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
250 Aspect_TypeOfMarker& theType,
251 Handle(Image_PixMap)& theImage)
252{
253 theImage.Nullify();
254 TCollection_AsciiString aTypeStr (theArg);
255 aTypeStr.LowerCase();
256 if (aTypeStr == "empty")
257 {
258 theType = Aspect_TOM_EMPTY;
259 }
260 else if (aTypeStr == "point"
261 || aTypeStr == "dot"
262 || aTypeStr == ".")
263 {
264 theType = Aspect_TOM_POINT;
265 }
266 else if (aTypeStr == "plus"
267 || aTypeStr == "+")
268 {
269 theType = Aspect_TOM_PLUS;
270 }
271 else if (aTypeStr == "star"
272 || aTypeStr == "*")
273 {
274 theType = Aspect_TOM_STAR;
275 }
276 else if (aTypeStr == "cross"
277 || aTypeStr == "x")
278 {
279 theType = Aspect_TOM_X;
280 }
281 else if (aTypeStr == "circle"
282 || aTypeStr == "o")
283 {
284 theType = Aspect_TOM_O;
285 }
286 else if (aTypeStr == "pointincircle")
287 {
288 theType = Aspect_TOM_O_POINT;
289 }
290 else if (aTypeStr == "plusincircle")
291 {
292 theType = Aspect_TOM_O_PLUS;
293 }
294 else if (aTypeStr == "starincircle")
295 {
296 theType = Aspect_TOM_O_STAR;
297 }
298 else if (aTypeStr == "crossincircle"
299 || aTypeStr == "xcircle")
300 {
301 theType = Aspect_TOM_O_X;
302 }
303 else if (aTypeStr == "ring1")
304 {
305 theType = Aspect_TOM_RING1;
306 }
307 else if (aTypeStr == "ring2")
308 {
309 theType = Aspect_TOM_RING2;
310 }
311 else if (aTypeStr == "ring"
312 || aTypeStr == "ring3")
313 {
314 theType = Aspect_TOM_RING3;
315 }
316 else if (aTypeStr == "ball")
317 {
318 theType = Aspect_TOM_BALL;
319 }
320 else if (aTypeStr.IsIntegerValue())
321 {
322 const int aTypeInt = aTypeStr.IntegerValue();
323 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
324 {
325 return Standard_False;
326 }
327 theType = (Aspect_TypeOfMarker )aTypeInt;
328 }
329 else
330 {
331 theType = Aspect_TOM_USERDEFINED;
332 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
333 if (!anImage->Load (theArg))
334 {
335 return Standard_False;
336 }
337 if (anImage->Format() == Image_Format_Gray)
338 {
339 anImage->SetFormat (Image_Format_Alpha);
340 }
341 else if (anImage->Format() == Image_Format_GrayF)
342 {
343 anImage->SetFormat (Image_Format_AlphaF);
344 }
345 theImage = anImage;
346 }
347 return Standard_True;
348}
349
dc89236f 350//=======================================================================
351//function : ParseShadingModel
352//purpose :
353//=======================================================================
354Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
355 Graphic3d_TypeOfShadingModel& theModel)
356{
357 TCollection_AsciiString aTypeStr (theArg);
358 aTypeStr.LowerCase();
359 if (aTypeStr == "unlit"
360 || aTypeStr == "color"
361 || aTypeStr == "none")
362 {
363 theModel = Graphic3d_TOSM_UNLIT;
364 }
365 else if (aTypeStr == "flat"
366 || aTypeStr == "facet")
367 {
368 theModel = Graphic3d_TOSM_FACET;
369 }
370 else if (aTypeStr == "gouraud"
371 || aTypeStr == "vertex"
372 || aTypeStr == "vert")
373 {
374 theModel = Graphic3d_TOSM_VERTEX;
375 }
376 else if (aTypeStr == "phong"
377 || aTypeStr == "fragment"
378 || aTypeStr == "frag"
379 || aTypeStr == "pixel")
380 {
381 theModel = Graphic3d_TOSM_FRAGMENT;
382 }
383 else if (aTypeStr == "default"
384 || aTypeStr == "def")
385 {
386 theModel = Graphic3d_TOSM_DEFAULT;
387 }
388 else if (aTypeStr.IsIntegerValue())
389 {
390 const int aTypeInt = aTypeStr.IntegerValue();
391 if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
392 {
393 return Standard_False;
394 }
395 theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
396 }
397 else
398 {
399 return Standard_False;
400 }
401 return Standard_True;
402}
403
55c8f0f7
BB
404//=======================================================================
405//function : parseZLayer
406//purpose :
407//=======================================================================
408Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
409 Standard_Boolean theToAllowInteger,
410 Graphic3d_ZLayerId& theLayer)
411{
412 TCollection_AsciiString aName (theArg);
413 aName.LowerCase();
414 if (aName == "default"
415 || aName == "def")
416 {
417 theLayer = Graphic3d_ZLayerId_Default;
418 }
419 else if (aName == "top")
420 {
421 theLayer = Graphic3d_ZLayerId_Top;
422 }
423 else if (aName == "topmost")
424 {
425 theLayer = Graphic3d_ZLayerId_Topmost;
426 }
427 else if (aName == "overlay"
428 || aName == "toposd")
429 {
430 theLayer = Graphic3d_ZLayerId_TopOSD;
431 }
432 else if (aName == "underlay"
433 || aName == "botosd")
434 {
435 theLayer = Graphic3d_ZLayerId_BotOSD;
436 }
437 else if (aName == "undefined")
438 {
439 theLayer = Graphic3d_ZLayerId_UNKNOWN;
440 }
441 else if (!GetAISContext().IsNull())
442 {
443 const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
444 TColStd_SequenceOfInteger aLayers;
445 aViewer->GetAllZLayers (aLayers);
446 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
447 {
448 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
449 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
450 {
451 theLayer = aLayeriter.Value();
452 return true;
453 }
454 }
455
456 if (!theToAllowInteger
457 || !aName.IsIntegerValue())
458 {
459 return false;
460 }
461 Graphic3d_ZLayerId aLayer = aName.IntegerValue();
462 if (aLayer == Graphic3d_ZLayerId_UNKNOWN
463 || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
464 {
465 theLayer = aLayer;
466 return true;
467 }
468 return false;
469 }
470 return true;
471}
472
7fd59977 473//=======================================================================
474//function : GetTypeNames
475//purpose :
476//=======================================================================
477static const char** GetTypeNames()
478{
479 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
480 "Shape","ConnectedShape","MultiConn.Shape",
481 "ConnectedInter.","MultiConn.",
482 "Constraint","Dimension"};
483 static const char** ThePointer = names;
484 return ThePointer;
485}
486
487//=======================================================================
488//function : GetTypeAndSignfromString
489//purpose :
490//=======================================================================
491void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
492{
493 const char ** thefullnames = GetTypeNames();
494 Standard_Integer index(-1);
495
496 for(Standard_Integer i=0;i<=13 && index==-1;i++)
497 if(!strcasecmp(name,thefullnames[i]))
498 index = i;
499
500 if(index ==-1){
501 TheType = AIS_KOI_None;
502 TheSign = -1;
503 return;
504 }
505
506 if(index<=6){
507 TheType = AIS_KOI_Datum;
508 TheSign = index+1;
509 }
510 else if (index <=9){
511 TheType = AIS_KOI_Shape;
512 TheSign = index-7;
513 }
514 else if(index<=11){
515 TheType = AIS_KOI_Object;
516 TheSign = index-10;
517 }
518 else{
519 TheType = AIS_KOI_Relation;
520 TheSign = index-12;
521 }
522
523}
524
525
526
527#include <string.h>
528#include <Draw_Interpretor.hxx>
529#include <Draw.hxx>
530#include <Draw_Appli.hxx>
531#include <DBRep.hxx>
532
533
534#include <TCollection_AsciiString.hxx>
535#include <V3d_Viewer.hxx>
536#include <V3d_View.hxx>
537#include <V3d.hxx>
538
539#include <AIS_InteractiveContext.hxx>
540#include <AIS_Shape.hxx>
7fd59977 541#include <AIS_DisplayMode.hxx>
542#include <TColStd_MapOfInteger.hxx>
543#include <AIS_MapOfInteractive.hxx>
544#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
545#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
546#include <ViewerTest_EventManager.hxx>
547
548#include <TopoDS_Solid.hxx>
549#include <BRepTools.hxx>
550#include <BRep_Builder.hxx>
551#include <TopAbs_ShapeEnum.hxx>
552
553#include <TopoDS.hxx>
554#include <BRep_Tool.hxx>
555
556
557#include <Draw_Window.hxx>
558#include <AIS_ListIteratorOfListOfInteractive.hxx>
559#include <AIS_ListOfInteractive.hxx>
560#include <AIS_DisplayMode.hxx>
561#include <TopTools_ListOfShape.hxx>
562#include <BRepOffsetAPI_MakeThickSolid.hxx>
7fd59977 563
7fd59977 564//==============================================================================
565// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
566//==============================================================================
567Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
568 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
569 return TheMap;
570}
571
29e2c6d2 572//=======================================================================
573//function : Display
574//purpose :
575//=======================================================================
576Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
577 const Handle(AIS_InteractiveObject)& theObject,
578 const Standard_Boolean theToUpdate,
579 const Standard_Boolean theReplaceIfExists)
9558a876
A
580{
581 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 582 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
583 if (aCtx.IsNull())
9558a876 584 {
29e2c6d2 585 std::cout << "Error: AIS context is not available.\n";
9558a876
A
586 return Standard_False;
587 }
588
589 if (aMap.IsBound2 (theName))
590 {
591 if (!theReplaceIfExists)
592 {
29e2c6d2 593 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
594 << "Please use another name.\n";
595 return Standard_False;
596 }
597
8f521168 598 if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName))
29e2c6d2 599 {
1beb58d7 600 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
29e2c6d2 601 }
9558a876
A
602 aMap.UnBind2 (theName);
603 }
604
29e2c6d2 605 if (theObject.IsNull())
208e6839 606 {
29e2c6d2 607 // object with specified name has been already unbound
208e6839 608 return Standard_True;
609 }
610
29e2c6d2 611 // unbind AIS object if it was bound with another name
612 aMap.UnBind1 (theObject);
9558a876
A
613
614 // can be registered without rebinding
29e2c6d2 615 aMap.Bind (theObject, theName);
616 aCtx->Display (theObject, theToUpdate);
9558a876
A
617 return Standard_True;
618}
619
29e2c6d2 620//! Alias for ViewerTest::Display(), compatibility with old code.
621Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
622 const Handle(AIS_InteractiveObject)& theObject,
623 Standard_Boolean theReplaceIfExists = Standard_True)
624{
625 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
626}
627
7fd59977 628static TColStd_MapOfInteger theactivatedmodes(8);
629static TColStd_ListOfTransient theEventMgrs;
630
d09dda09 631static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
7fd59977 632 const Handle(AIS_InteractiveContext)& Ctx)
633{
634 theEventMgrs.Clear();
635 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
636}
637
24de79c3 638static Handle(V3d_View)& a3DView()
639{
7fd59977 640 static Handle(V3d_View) Viou;
641 return Viou;
642}
643
24de79c3 644
7fd59977 645Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
646 static Handle(AIS_InteractiveContext) aContext;
647 return aContext;
648}
649
24de79c3 650const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 651{
652 return a3DView();
653}
654void ViewerTest::CurrentView(const Handle(V3d_View)& V)
655{
656 a3DView() = V;
657}
658
24de79c3 659const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 660{
661 return TheAISContext();
662}
663
664void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
665{
666 TheAISContext() = aCtx;
667 ViewerTest::ResetEventManager();
668}
669
670Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
671{
4952a30a 672 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 673}
674
675Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
676{
4952a30a 677 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 678}
679
680
681void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
682 theEventMgrs.Prepend(EM);
683}
684
685void ViewerTest::UnsetEventManager()
686{
687 theEventMgrs.RemoveFirst();
688}
689
690
691void ViewerTest::ResetEventManager()
692{
d09dda09 693 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 694 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
695}
696
697Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
698{
699 Handle(ViewerTest_EventManager) EM;
700 if(theEventMgrs.IsEmpty()) return EM;
701 Handle(Standard_Transient) Tr = theEventMgrs.First();
c5f3a425 702 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
7fd59977 703 return EM;
704}
705
7fd59977 706//=======================================================================
34db9c00 707//function : Get Context and active view
7fd59977 708//purpose :
709//=======================================================================
34db9c00 710static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
711 Handle(V3d_View)& theView)
7fd59977 712{
34db9c00 713 theCtx = ViewerTest::GetAISContext();
714 theView = ViewerTest::CurrentView();
715 if (theCtx.IsNull()
716 || theView.IsNull())
7fd59977 717 {
34db9c00 718 std::cout << "Error: cannot find an active view!\n";
719 return Standard_False;
7fd59977 720 }
34db9c00 721 return Standard_True;
7fd59977 722}
723
7fd59977 724//==============================================================================
725//function : Clear
726//purpose : Remove all the object from the viewer
727//==============================================================================
728void ViewerTest::Clear()
729{
851dacdb 730 if (a3DView().IsNull())
731 {
732 return;
733 }
734
735 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
736 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
737 {
8f521168 738 const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1();
851dacdb 739 if (anObj->GetContext() != TheAISContext())
740 {
741 continue;
7fd59977 742 }
851dacdb 743
744 std::cout << "Remove " << anObjIter.Key2() << std::endl;
745 TheAISContext()->Remove (anObj, Standard_False);
746 aListRemoved.Append (anObj);
747 }
748
749 TheAISContext()->RebuildSelectionStructs();
750 TheAISContext()->UpdateCurrentViewer();
751 if (aListRemoved.Size() == GetMapOfAIS().Extent())
752 {
7fd59977 753 GetMapOfAIS().Clear();
754 }
851dacdb 755 else
756 {
757 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
758 {
759 GetMapOfAIS().UnBind1 (anObjIter.Value());
760 }
761 }
7fd59977 762}
763
1c88cbaf 764//==============================================================================
765//function : CopyIsoAspect
766//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
767//==============================================================================
768static Handle(Prs3d_IsoAspect) CopyIsoAspect
769 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
770 const Standard_Integer theNbIsos)
771{
b6472664 772 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
773 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
774 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
1c88cbaf 775
776 Handle(Prs3d_IsoAspect) aResult =
777 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
778
779 return aResult;
780}
781
782//==============================================================================
783//function : visos
784//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
785//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
786//==============================================================================
787static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
788{
789 if (TheAISContext().IsNull()) {
790 di << argv[0] << " Call 'vinit' before!\n";
791 return 1;
792 }
793
794 if (argc <= 1) {
795 di << "Current number of isos : " <<
796 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
797 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
798 di << "IsoOnPlane mode is " <<
799 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
5ad8c033 800 di << "IsoOnTriangulation mode is " <<
801 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
1c88cbaf 802 return 0;
803 }
804
805 Standard_Integer aLastInd = argc - 1;
806 Standard_Boolean isChanged = Standard_False;
1d47d8d0 807 Standard_Integer aNbUIsos = 0;
808 Standard_Integer aNbVIsos = 0;
1c88cbaf 809
810 if (aLastInd >= 3) {
811 Standard_Boolean isIsoOnPlane = Standard_False;
812
813 if (strcmp(argv[aLastInd], "1") == 0) {
814 isIsoOnPlane = Standard_True;
815 isChanged = Standard_True;
816 } else if (strcmp(argv[aLastInd], "0") == 0) {
817 isIsoOnPlane = Standard_False;
818 isChanged = Standard_True;
819 }
820
821 if (isChanged) {
822 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
823 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
824 aLastInd -= 3;
825
826 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
827 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
828
829 TheAISContext()->IsoOnPlane(isIsoOnPlane);
830
831 if (aLastInd == 0) {
832 // If there are no shapes provided set the default numbers.
833 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
834 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
835 }
836 }
837 }
838
839 Standard_Integer i;
840
8f521168 841 for (i = 1; i <= aLastInd; i++)
842 {
1c88cbaf 843 TCollection_AsciiString name(argv[i]);
8f521168 844 Handle(AIS_InteractiveObject) aShape;
845 GetMapOfAIS().Find2(name, aShape);
846 if (aShape.IsNull())
847 {
848 std::cout << "Syntax error: object '" << name << "' is not found\n";
849 return 1;
850 }
851
852 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
853 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
854 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
855 if (isChanged)
856 {
857 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
858 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
859 TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False);
860 TheAISContext()->Redisplay (aShape, Standard_False);
861 }
862 else
863 {
864 di << "Number of isos for " << argv[i] << " : "
865 << aUIso->Number() << " " << aVIso->Number() << "\n";
1c88cbaf 866 }
867 }
868
869 if (isChanged) {
870 TheAISContext()->UpdateCurrentViewer();
871 }
872
873 return 0;
874}
875
34db9c00 876static Standard_Integer VDispSensi (Draw_Interpretor& ,
877 Standard_Integer theArgNb,
878 Standard_CString* )
7fd59977 879{
34db9c00 880 if (theArgNb > 1)
881 {
882 std::cout << "Error: wrong syntax!\n";
883 return 1;
884 }
885
886 Handle(AIS_InteractiveContext) aCtx;
887 Handle(V3d_View) aView;
888 if (!getCtxAndView (aCtx, aView))
889 {
890 return 1;
891 }
892
893 aCtx->DisplayActiveSensitive (aView);
7fd59977 894 return 0;
895
896}
34db9c00 897
898static Standard_Integer VClearSensi (Draw_Interpretor& ,
899 Standard_Integer theArgNb,
900 Standard_CString* )
7fd59977 901{
34db9c00 902 if (theArgNb > 1)
903 {
904 std::cout << "Error: wrong syntax!\n";
905 return 1;
906 }
907
908 Handle(AIS_InteractiveContext) aCtx;
909 Handle(V3d_View) aView;
910 if (!getCtxAndView (aCtx, aView))
911 {
912 return 1;
913 }
914 aCtx->ClearActiveSensitive (aView);
7fd59977 915 return 0;
916}
917
918//==============================================================================
519d35d8 919//function : VDir
7fd59977 920//purpose : To list the displayed object with their attributes
7fd59977 921//==============================================================================
519d35d8 922static int VDir (Draw_Interpretor& theDI,
923 Standard_Integer ,
924 const char** )
925{
519d35d8 926 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
927 anIter.More(); anIter.Next())
928 {
a2fb712b 929 theDI << "\t" << anIter.Key2() << "\n";
519d35d8 930 }
7fd59977 931 return 0;
932}
933
f978241f 934//! Auxiliary enumeration
935enum ViewerTest_StereoPair
936{
937 ViewerTest_SP_Single,
938 ViewerTest_SP_SideBySide,
939 ViewerTest_SP_OverUnder
940};
941
7fd59977 942//==============================================================================
943//function : VDump
944//purpose : To dump the active view snapshot to image file
7fd59977 945//==============================================================================
34db9c00 946static Standard_Integer VDump (Draw_Interpretor& theDI,
947 Standard_Integer theArgNb,
948 Standard_CString* theArgVec)
7fd59977 949{
34db9c00 950 if (theArgNb < 2)
7fd59977 951 {
34db9c00 952 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 953 return 1;
954 }
955
34db9c00 956 Standard_Integer anArgIter = 1;
957 Standard_CString aFilePath = theArgVec[anArgIter++];
f978241f 958 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
3bffef55 959 V3d_ImageDumpOptions aParams;
960 aParams.BufferType = Graphic3d_BT_RGB;
961 aParams.StereoOptions = V3d_SDO_MONO;
34db9c00 962 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 963 {
34db9c00 964 TCollection_AsciiString anArg (theArgVec[anArgIter]);
965 anArg.LowerCase();
f978241f 966 if (anArg == "-buffer")
7fd59977 967 {
f978241f 968 if (++anArgIter >= theArgNb)
969 {
970 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
971 return 1;
972 }
973
974 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
975 aBufArg.LowerCase();
976 if (aBufArg == "rgba")
977 {
3bffef55 978 aParams.BufferType = Graphic3d_BT_RGBA;
f978241f 979 }
980 else if (aBufArg == "rgb")
981 {
3bffef55 982 aParams.BufferType = Graphic3d_BT_RGB;
f978241f 983 }
984 else if (aBufArg == "depth")
985 {
3bffef55 986 aParams.BufferType = Graphic3d_BT_Depth;
f978241f 987 }
988 else
989 {
990 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
991 return 1;
992 }
7fd59977 993 }
f978241f 994 else if (anArg == "-stereo")
7fd59977 995 {
f978241f 996 if (++anArgIter >= theArgNb)
997 {
998 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
999 return 1;
1000 }
1001
1002 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
1003 aStereoArg.LowerCase();
1004 if (aStereoArg == "l"
1005 || aStereoArg == "left")
1006 {
3bffef55 1007 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
f978241f 1008 }
1009 else if (aStereoArg == "r"
1010 || aStereoArg == "right")
1011 {
3bffef55 1012 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
f978241f 1013 }
1014 else if (aStereoArg == "mono")
1015 {
3bffef55 1016 aParams.StereoOptions = V3d_SDO_MONO;
f978241f 1017 }
1018 else if (aStereoArg == "blended"
1019 || aStereoArg == "blend"
1020 || aStereoArg == "stereo")
1021 {
3bffef55 1022 aParams.StereoOptions = V3d_SDO_BLENDED;
f978241f 1023 }
1024 else if (aStereoArg == "sbs"
1025 || aStereoArg == "sidebyside")
1026 {
1027 aStereoPair = ViewerTest_SP_SideBySide;
1028 }
1029 else if (aStereoArg == "ou"
1030 || aStereoArg == "overunder")
1031 {
1032 aStereoPair = ViewerTest_SP_OverUnder;
1033 }
1034 else
1035 {
1036 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1037 return 1;
1038 }
7fd59977 1039 }
f978241f 1040 else if (anArg == "-rgba"
1041 || anArg == "rgba")
34db9c00 1042 {
3bffef55 1043 aParams.BufferType = Graphic3d_BT_RGBA;
34db9c00 1044 }
f978241f 1045 else if (anArg == "-rgb"
1046 || anArg == "rgb")
34db9c00 1047 {
3bffef55 1048 aParams.BufferType = Graphic3d_BT_RGB;
34db9c00 1049 }
f978241f 1050 else if (anArg == "-depth"
1051 || anArg == "depth")
34db9c00 1052 {
3bffef55 1053 aParams.BufferType = Graphic3d_BT_Depth;
34db9c00 1054 }
f978241f 1055 else if (anArg == "-width"
1056 || anArg == "width"
1057 || anArg == "sizex")
34db9c00 1058 {
3bffef55 1059 if (aParams.Width != 0)
34db9c00 1060 {
1061 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1062 return 1;
1063 }
1064 else if (++anArgIter >= theArgNb)
1065 {
1066 std::cout << "Error: integer value is expected right after 'width'\n";
1067 return 1;
1068 }
3bffef55 1069 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
34db9c00 1070 }
f978241f 1071 else if (anArg == "-height"
1072 || anArg == "height"
1073 || anArg == "-sizey")
34db9c00 1074 {
3bffef55 1075 if (aParams.Height != 0)
34db9c00 1076 {
1077 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1078 return 1;
1079 }
34db9c00 1080 else if (++anArgIter >= theArgNb)
1081 {
f978241f 1082 std::cout << "Error: integer value is expected right after 'height'\n";
34db9c00 1083 return 1;
1084 }
3bffef55 1085 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1086 }
1087 else if (anArg == "-tile"
1088 || anArg == "-tilesize")
1089 {
1090 if (++anArgIter >= theArgNb)
1091 {
1092 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1093 return 1;
1094 }
1095 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
34db9c00 1096 }
1097 else
1098 {
1099 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1100 return 1;
1101 }
7fd59977 1102 }
3bffef55 1103 if ((aParams.Width <= 0 && aParams.Height > 0)
1104 || (aParams.Width > 0 && aParams.Height <= 0))
7fd59977 1105 {
3bffef55 1106 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
85e096c3 1107 return 1;
1108 }
1109
34db9c00 1110 Handle(V3d_View) aView = ViewerTest::CurrentView();
1111 if (aView.IsNull())
85e096c3 1112 {
34db9c00 1113 std::cout << "Error: cannot find an active view!\n";
1114 return 1;
7fd59977 1115 }
85e096c3 1116
3bffef55 1117 if (aParams.Width <= 0 || aParams.Height <= 0)
b5ac8292 1118 {
3bffef55 1119 aView->Window()->Size (aParams.Width, aParams.Height);
f978241f 1120 }
1121
1122 Image_AlienPixMap aPixMap;
dc858f4c 1123 Image_Format aFormat = Image_Format_UNKNOWN;
3bffef55 1124 switch (aParams.BufferType)
f978241f 1125 {
38d90bb3 1126 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1127 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1128 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1129 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
f978241f 1130 }
1131
1132 switch (aStereoPair)
1133 {
1134 case ViewerTest_SP_Single:
b5ac8292 1135 {
3bffef55 1136 if (!aView->ToPixMap (aPixMap, aParams))
f978241f 1137 {
1138 theDI << "Fail: view dump failed!\n";
1139 return 0;
1140 }
3bffef55 1141 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1142 || aPixMap.SizeY() != Standard_Size(aParams.Height))
f978241f 1143 {
1144 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
3bffef55 1145 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
f978241f 1146 }
1147 break;
b5ac8292 1148 }
f978241f 1149 case ViewerTest_SP_SideBySide:
b5ac8292 1150 {
3bffef55 1151 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
f978241f 1152 {
1153 theDI << "Fail: not enough memory for image allocation!\n";
1154 return 0;
1155 }
1156
1157 Image_PixMap aPixMapL, aPixMapR;
1158 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
3bffef55 1159 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1160 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1161 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1162
1163 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1164 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1165 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1166 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1167 if (!isOk)
34db9c00 1168 {
1169 theDI << "Fail: view dump failed!\n";
f978241f 1170 return 0;
34db9c00 1171 }
f978241f 1172 break;
b5ac8292 1173 }
f978241f 1174 case ViewerTest_SP_OverUnder:
1175 {
3bffef55 1176 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
f978241f 1177 {
1178 theDI << "Fail: not enough memory for image allocation!\n";
1179 return 0;
1180 }
b5ac8292 1181
f978241f 1182 Image_PixMap aPixMapL, aPixMapR;
f9f740d6 1183 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
3bffef55 1184 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
f9f740d6 1185 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
3bffef55 1186 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1187
1188 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1189 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1190 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1191 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1192 if (!isOk)
f978241f 1193 {
1194 theDI << "Fail: view dump failed!\n";
1195 return 0;
1196 }
1197 break;
1198 }
7fd59977 1199 }
85e096c3 1200
34db9c00 1201 if (!aPixMap.Save (aFilePath))
85e096c3 1202 {
34db9c00 1203 theDI << "Fail: image can not be saved!\n";
85e096c3 1204 }
1205 return 0;
7fd59977 1206}
1207
dde68833 1208enum TypeOfDispOperation
7fd59977 1209{
dde68833 1210 TypeOfDispOperation_SetDispMode,
1211 TypeOfDispOperation_UnsetDispMode
1212};
7fd59977 1213
dde68833 1214//! Displays,Erase...
1215static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1216 const Standard_Integer theMode,
1217 const TypeOfDispOperation theType,
1218 const Standard_Boolean theToUpdate)
1219{
1220 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1221 switch (theType)
1222 {
1223 case TypeOfDispOperation_SetDispMode:
1224 {
1225 if (!thePrs.IsNull())
1226 {
1227 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1228 }
1229 else
1230 {
1231 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1232 }
1233 break;
1234 }
1235 case TypeOfDispOperation_UnsetDispMode:
1236 {
1237 if (!thePrs.IsNull())
1238 {
1239 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1240 }
1241 else
1242 {
1243 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1244 }
1245 break;
1246 }
7fd59977 1247 }
7fd59977 1248}
1249
1250//=======================================================================
1251//function :
1252//purpose :
1253//=======================================================================
1254static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1255{
dde68833 1256 if (argc < 1
1257 || argc > 3)
1258 {
1259 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 1260 return 1;
dde68833 1261 }
7fd59977 1262
dde68833 1263 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1264 ? TypeOfDispOperation_UnsetDispMode
1265 : TypeOfDispOperation_SetDispMode;
1266 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1267 if (aType == TypeOfDispOperation_UnsetDispMode)
1268 {
1269 if (argc == 1)
1270 {
1271 if (aCtx->NbSelected() == 0)
1272 {
1273 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1274 }
1275 else
1276 {
1277 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1278 {
1279 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1280 }
7fd59977 1281 }
dde68833 1282 aCtx->UpdateCurrentViewer();
7fd59977 1283 }
dde68833 1284 else
1285 {
1286 TCollection_AsciiString aName = argv[1];
8f521168 1287 Handle(AIS_InteractiveObject) aPrs;
1288 if (GetMapOfAIS().Find2 (aName, aPrs)
1289 && !aPrs.IsNull())
dde68833 1290 {
8f521168 1291 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
7fd59977 1292 }
1293 }
1294 }
dde68833 1295 else if (argc == 2)
1296 {
1297 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1298 if (aCtx->NbSelected() == 0
1299 && aType == TypeOfDispOperation_SetDispMode)
1300 {
1301 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
7fd59977 1302 }
dde68833 1303 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1304 {
1305 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
7fd59977 1306 }
dde68833 1307 aCtx->UpdateCurrentViewer();
7fd59977 1308 }
dde68833 1309 else
1310 {
1311 Handle(AIS_InteractiveObject) aPrs;
1312 TCollection_AsciiString aName (argv[1]);
8f521168 1313 if (GetMapOfAIS().Find2 (aName, aPrs)
1314 && !aPrs.IsNull())
dde68833 1315 {
1316 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1317 }
7fd59977 1318 }
1319 return 0;
1320}
1321
1322
1323//=======================================================================
1324//function :
1325//purpose :
1326//=======================================================================
1327static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1328{
1329 if(argc==1) return 1;
91322f44 1330 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1331 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1332
c3282ec1 1333 if(argc==2)
1334 {
1335 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1336 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1337 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1338 {
1339 if(On==1)
1340 {
1341 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1342 }
c3282ec1 1343 else
1344 {
1345 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1346 }
1347 }
c3282ec1 1348
7fd59977 1349 Ctx->UpdateCurrentViewer();
1350 }
1351 else {
1352 Handle(AIS_InteractiveObject) IO;
1353 TCollection_AsciiString name = argv[2];
8f521168 1354 if (GetMapOfAIS().Find2 (name, IO)
1355 && !IO.IsNull())
1356 {
1357 if(On==1)
1358 Ctx->SubIntensityOn(IO, Standard_True);
1359 else
1360 Ctx->SubIntensityOff(IO, Standard_True);
7fd59977 1361 }
1362 else return 1;
1363 }
1364 return 0;
7fd59977 1365}
7fd59977 1366
ad3217cd 1367//! Auxiliary class to iterate presentations from different collections.
1368class ViewTest_PrsIter
1369{
1370public:
7fd59977 1371
ad3217cd 1372 //! Create and initialize iterator object.
1373 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1374 : mySource (IterSource_All)
1375 {
1376 NCollection_Sequence<TCollection_AsciiString> aNames;
1377 if (!theName.IsEmpty())
1378 aNames.Append (theName);
1379 Init (aNames);
7fd59977 1380 }
ad3217cd 1381
1382 //! Create and initialize iterator object.
1383 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1384 : mySource (IterSource_All)
1385 {
1386 Init (theNames);
7fd59977 1387 }
1388
ad3217cd 1389 //! Initialize the iterator.
1390 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1391 {
1392 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1393 mySeq = theNames;
1394 mySelIter.Nullify();
1395 myCurrent.Nullify();
1396 myCurrentTrs.Nullify();
1397 if (!mySeq.IsEmpty())
1398 {
1399 mySource = IterSource_List;
1400 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1401 }
c3282ec1 1402 else if (aCtx->NbSelected() > 0)
ad3217cd 1403 {
1404 mySource = IterSource_Selected;
1405 mySelIter = aCtx;
c3282ec1 1406 mySelIter->InitSelected();
ad3217cd 1407 }
1408 else
1409 {
1410 mySource = IterSource_All;
1411 myMapIter.Initialize (GetMapOfAIS());
1412 }
1413 initCurrent();
1414 }
7fd59977 1415
ad3217cd 1416 const TCollection_AsciiString& CurrentName() const
1417 {
1418 return myCurrentName;
1419 }
7fd59977 1420
ad3217cd 1421 const Handle(AIS_InteractiveObject)& Current() const
1422 {
1423 return myCurrent;
1424 }
7fd59977 1425
ad3217cd 1426 const Handle(Standard_Transient)& CurrentTrs() const
1427 {
1428 return myCurrentTrs;
1429 }
1430
1431 //! @return true if iterator points to valid object within collection
1432 Standard_Boolean More() const
1433 {
1434 switch (mySource)
1435 {
1436 case IterSource_All: return myMapIter.More();
1437 case IterSource_List: return mySeqIter.More();
c3282ec1 1438 case IterSource_Selected: return mySelIter->MoreSelected();
ad3217cd 1439 }
1440 return Standard_False;
1441 }
1442
1443 //! Go to the next item.
1444 void Next()
1445 {
1446 myCurrentName.Clear();
1447 myCurrentTrs.Nullify();
1448 myCurrent.Nullify();
1449 switch (mySource)
1450 {
1451 case IterSource_All:
1452 {
1453 myMapIter.Next();
1454 break;
1455 }
1456 case IterSource_List:
1457 {
1458 mySeqIter.Next();
1459 break;
1460 }
1461 case IterSource_Selected:
1462 {
c3282ec1 1463 mySelIter->NextSelected();
ad3217cd 1464 break;
7fd59977 1465 }
1466 }
ad3217cd 1467 initCurrent();
1468 }
7fd59977 1469
ad3217cd 1470private:
7fd59977 1471
ad3217cd 1472 void initCurrent()
1473 {
1474 switch (mySource)
1475 {
1476 case IterSource_All:
7fd59977 1477 {
ad3217cd 1478 if (myMapIter.More())
1479 {
1480 myCurrentName = myMapIter.Key2();
1481 myCurrentTrs = myMapIter.Key1();
1482 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1483 }
ad3217cd 1484 break;
1485 }
1486 case IterSource_List:
1487 {
1488 if (mySeqIter.More())
1489 {
1490 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1491 {
1492 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1493 return;
1494 }
1495 myCurrentName = mySeqIter.Value();
1496 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1497 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1498 }
1499 break;
1500 }
1501 case IterSource_Selected:
1502 {
c3282ec1 1503 if (mySelIter->MoreSelected())
ad3217cd 1504 {
c3282ec1 1505 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1506 myCurrent = mySelIter->SelectedInteractive();
ad3217cd 1507 }
1508 break;
7fd59977 1509 }
7fd59977 1510 }
1511 }
ad3217cd 1512
1513private:
1514
1515 enum IterSource
1516 {
1517 IterSource_All,
1518 IterSource_List,
1519 IterSource_Selected
1520 };
1521
1522private:
1523
1524 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1525 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1526 NCollection_Sequence<TCollection_AsciiString> mySeq;
1527 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1528
1529 TCollection_AsciiString myCurrentName;//!< current item name
1530 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1531 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1532
1533 IterSource mySource; //!< iterated collection
1534
1535};
7fd59977 1536
2a332745 1537//! Parse interior style name.
1538static bool parseInteriorStyle (const TCollection_AsciiString& theArg,
1539 Aspect_InteriorStyle& theStyle)
7fd59977 1540{
2a332745 1541 TCollection_AsciiString anArg (theArg);
1542 anArg.LowerCase();
1543 if (anArg == "empty")
ad3217cd 1544 {
2a332745 1545 theStyle = Aspect_IS_EMPTY;
ad3217cd 1546 }
2a332745 1547 else if (anArg == "hollow")
ad3217cd 1548 {
2a332745 1549 theStyle = Aspect_IS_HOLLOW;
ad3217cd 1550 }
2a332745 1551 else if (anArg == "solid")
ad3217cd 1552 {
2a332745 1553 theStyle = Aspect_IS_SOLID;
ad3217cd 1554 }
2a332745 1555 else if (anArg == "hatch")
ad3217cd 1556 {
2a332745 1557 theStyle = Aspect_IS_HATCH;
ad3217cd 1558 }
2a332745 1559 else if (anArg == "hiddenline"
1560 || anArg == "hidden-line"
1561 || anArg == "hidden_line")
ad3217cd 1562 {
2a332745 1563 theStyle = Aspect_IS_HIDDENLINE;
ad3217cd 1564 }
2a332745 1565 else if (anArg == "point")
ad3217cd 1566 {
2a332745 1567 theStyle = Aspect_IS_POINT;
ad3217cd 1568 }
2a332745 1569 else if (theArg.IsIntegerValue())
ad3217cd 1570 {
2a332745 1571 const Standard_Integer anIntStyle = theArg.IntegerValue();
1572 if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
ec7c343f 1573 {
2a332745 1574 return false;
ec7c343f 1575 }
2a332745 1576 theStyle = (Aspect_InteriorStyle)anIntStyle;
7fd59977 1577 }
2a332745 1578 else
ad3217cd 1579 {
2a332745 1580 return false;
ad3217cd 1581 }
2a332745 1582 return true;
ad3217cd 1583}
7fd59977 1584
ad3217cd 1585//! Auxiliary structure for VAspects
1586struct ViewerTest_AspectsChangeSet
1587{
dc89236f 1588 Standard_Integer ToSetVisibility;
1589 Standard_Integer Visibility;
5bffb882 1590
dc89236f 1591 Standard_Integer ToSetColor;
1592 Quantity_Color Color;
ad3217cd 1593
dc89236f 1594 Standard_Integer ToSetLineWidth;
1595 Standard_Real LineWidth;
ad3217cd 1596
dc89236f 1597 Standard_Integer ToSetTypeOfLine;
1598 Aspect_TypeOfLine TypeOfLine;
ac116c22 1599
dc89236f 1600 Standard_Integer ToSetTypeOfMarker;
1601 Aspect_TypeOfMarker TypeOfMarker;
1602 Handle(Image_PixMap) MarkerImage;
33cc703b 1603
dc89236f 1604 Standard_Integer ToSetMarkerSize;
1605 Standard_Real MarkerSize;
33cc703b 1606
dc89236f 1607 Standard_Integer ToSetTransparency;
1608 Standard_Real Transparency;
ad3217cd 1609
c40eb6b9 1610 Standard_Integer ToSetAlphaMode;
1611 Graphic3d_AlphaMode AlphaMode;
1612 Standard_ShortReal AlphaCutoff;
1613
dc89236f 1614 Standard_Integer ToSetMaterial;
1615 Graphic3d_NameOfMaterial Material;
1616 TCollection_AsciiString MatName;
ad3217cd 1617
1618 NCollection_Sequence<TopoDS_Shape> SubShapes;
1619
dc89236f 1620 Standard_Integer ToSetShowFreeBoundary;
1621 Standard_Integer ToSetFreeBoundaryWidth;
1622 Standard_Real FreeBoundaryWidth;
1623 Standard_Integer ToSetFreeBoundaryColor;
1624 Quantity_Color FreeBoundaryColor;
6262338c 1625
dc89236f 1626 Standard_Integer ToEnableIsoOnTriangulation;
5ad8c033 1627
0493ffd0 1628 Standard_Integer ToSetFaceBoundaryDraw;
1629 Standard_Integer ToSetFaceBoundaryUpperContinuity;
1630 GeomAbs_Shape FaceBoundaryUpperContinuity;
1631
1632 Standard_Integer ToSetFaceBoundaryColor;
1633 Quantity_Color FaceBoundaryColor;
1634
1635 Standard_Integer ToSetFaceBoundaryWidth;
1636 Standard_Real FaceBoundaryWidth;
1637
1638 Standard_Integer ToSetTypeOfFaceBoundaryLine;
1639 Aspect_TypeOfLine TypeOfFaceBoundaryLine;
1640
dc89236f 1641 Standard_Integer ToSetMaxParamValue;
1642 Standard_Real MaxParamValue;
5ad8c033 1643
dc89236f 1644 Standard_Integer ToSetSensitivity;
1645 Standard_Integer SelectionMode;
1646 Standard_Integer Sensitivity;
8a1170ad 1647
dc89236f 1648 Standard_Integer ToSetHatch;
1649 Standard_Integer StdHatchStyle;
1650 TCollection_AsciiString PathToHatchPattern;
1651
1652 Standard_Integer ToSetShadingModel;
1653 Graphic3d_TypeOfShadingModel ShadingModel;
1654 TCollection_AsciiString ShadingModelName;
640d5fe2 1655
2a332745 1656 Standard_Integer ToSetInterior;
1657 Aspect_InteriorStyle InteriorStyle;
1658
6ef0d6f1 1659 Standard_Integer ToSetDrawSilhouette;
1660
2a332745 1661 Standard_Integer ToSetDrawEdges;
1662 Standard_Integer ToSetQuadEdges;
1663
1664 Standard_Integer ToSetEdgeColor;
1665 Quantity_ColorRGBA EdgeColor;
1666
1667 Standard_Integer ToSetEdgeWidth;
1668 Standard_Real EdgeWidth;
1669
1670 Standard_Integer ToSetTypeOfEdge;
1671 Aspect_TypeOfLine TypeOfEdge;
1672
ad3217cd 1673 //! Empty constructor
1674 ViewerTest_AspectsChangeSet()
5bffb882 1675 : ToSetVisibility (0),
1676 Visibility (1),
1677 ToSetColor (0),
ad3217cd 1678 Color (DEFAULT_COLOR),
1679 ToSetLineWidth (0),
1680 LineWidth (1.0),
ac116c22 1681 ToSetTypeOfLine (0),
1682 TypeOfLine (Aspect_TOL_SOLID),
33cc703b 1683 ToSetTypeOfMarker (0),
1684 TypeOfMarker (Aspect_TOM_PLUS),
1685 ToSetMarkerSize (0),
1686 MarkerSize (1.0),
ad3217cd 1687 ToSetTransparency (0),
1688 Transparency (0.0),
c40eb6b9 1689 ToSetAlphaMode (0),
1690 AlphaMode (Graphic3d_AlphaMode_BlendAuto),
1691 AlphaCutoff (0.5f),
ad3217cd 1692 ToSetMaterial (0),
6262338c 1693 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1694 ToSetShowFreeBoundary (0),
1695 ToSetFreeBoundaryWidth (0),
1696 FreeBoundaryWidth (1.0),
1697 ToSetFreeBoundaryColor (0),
1698 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
0493ffd0 1699 ToEnableIsoOnTriangulation (0),
1700 //
1701 ToSetFaceBoundaryDraw (0),
1702 ToSetFaceBoundaryUpperContinuity (0),
1703 FaceBoundaryUpperContinuity(GeomAbs_CN),
1704 ToSetFaceBoundaryColor (0),
1705 FaceBoundaryColor (Quantity_NOC_BLACK),
1706 ToSetFaceBoundaryWidth (0),
1707 FaceBoundaryWidth (1.0f),
1708 ToSetTypeOfFaceBoundaryLine(0),
1709 TypeOfFaceBoundaryLine (Aspect_TOL_SOLID),
1710 //
dc89236f 1711 ToSetMaxParamValue (0),
1712 MaxParamValue (500000),
1713 ToSetSensitivity (0),
1714 SelectionMode (-1),
1715 Sensitivity (-1),
1716 ToSetHatch (0),
1717 StdHatchStyle (-1),
1718 ToSetShadingModel (0),
2a332745 1719 ShadingModel (Graphic3d_TOSM_DEFAULT),
1720 ToSetInterior (0),
1721 InteriorStyle (Aspect_IS_SOLID),
6ef0d6f1 1722 ToSetDrawSilhouette (0),
2a332745 1723 ToSetDrawEdges (0),
1724 ToSetQuadEdges (0),
1725 ToSetEdgeColor (0),
1726 ToSetEdgeWidth (0),
1727 EdgeWidth (1.0),
1728 ToSetTypeOfEdge (0),
1729 TypeOfEdge (Aspect_TOL_SOLID)
640d5fe2 1730 {}
ad3217cd 1731
1732 //! @return true if no changes have been requested
1733 Standard_Boolean IsEmpty() const
1734 {
6262338c 1735 return ToSetVisibility == 0
1736 && ToSetLineWidth == 0
1737 && ToSetTransparency == 0
c40eb6b9 1738 && ToSetAlphaMode == 0
6262338c 1739 && ToSetColor == 0
1740 && ToSetMaterial == 0
1741 && ToSetShowFreeBoundary == 0
1742 && ToSetFreeBoundaryColor == 0
5ad8c033 1743 && ToSetFreeBoundaryWidth == 0
0493ffd0 1744 && ToEnableIsoOnTriangulation == 0
1745 && ToSetFaceBoundaryDraw == 0
1746 && ToSetFaceBoundaryUpperContinuity == 0
1747 && ToSetFaceBoundaryColor == 0
1748 && ToSetFaceBoundaryWidth == 0
1749 && ToSetTypeOfFaceBoundaryLine == 0
8a1170ad 1750 && ToSetMaxParamValue == 0
640d5fe2 1751 && ToSetSensitivity == 0
dc89236f 1752 && ToSetHatch == 0
2a332745 1753 && ToSetShadingModel == 0
1754 && ToSetInterior == 0
6ef0d6f1 1755 && ToSetDrawSilhouette == 0
2a332745 1756 && ToSetDrawEdges == 0
1757 && ToSetQuadEdges == 0
1758 && ToSetEdgeColor == 0
1759 && ToSetEdgeWidth == 0
1760 && ToSetTypeOfEdge == 0;
ad3217cd 1761 }
1762
1763 //! @return true if properties are valid
c1197a15 1764 Standard_Boolean Validate() const
ad3217cd 1765 {
1766 Standard_Boolean isOk = Standard_True;
5bffb882 1767 if (Visibility != 0 && Visibility != 1)
1768 {
1769 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1770 isOk = Standard_False;
1771 }
ad3217cd 1772 if (LineWidth <= 0.0
1773 || LineWidth > 10.0)
1774 {
1775 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1776 isOk = Standard_False;
7fd59977 1777 }
ad3217cd 1778 if (Transparency < 0.0
1779 || Transparency > 1.0)
1780 {
1781 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1782 isOk = Standard_False;
1783 }
c40eb6b9 1784 if (ToSetAlphaMode == 1
1785 && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
1786 {
1787 std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
1788 isOk = Standard_False;
1789 }
ad3217cd 1790 if (ToSetMaterial == 1
1791 && Material == Graphic3d_NOM_DEFAULT)
1792 {
1793 std::cout << "Error: unknown material " << MatName << ".\n";
1794 isOk = Standard_False;
1795 }
6262338c 1796 if (FreeBoundaryWidth <= 0.0
1797 || FreeBoundaryWidth > 10.0)
1798 {
1799 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1800 isOk = Standard_False;
1801 }
5ad8c033 1802 if (MaxParamValue < 0.0)
1803 {
1804 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1805 isOk = Standard_False;
1806 }
8a1170ad 1807 if (Sensitivity <= 0 && ToSetSensitivity)
1808 {
1809 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1810 isOk = Standard_False;
1811 }
640d5fe2 1812 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1813 {
1814 std::cout << "Error: hatch style must be specified\n";
1815 isOk = Standard_False;
1816 }
dc89236f 1817 if (ToSetShadingModel == 1
1818 && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
1819 {
1820 std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
1821 isOk = Standard_False;
1822 }
ad3217cd 1823 return isOk;
7fd59977 1824 }
7fd59977 1825
2a332745 1826 //! Apply aspects to specified drawer.
1827 bool Apply (const Handle(Prs3d_Drawer)& theDrawer)
1828 {
1829 bool toRecompute = false;
1830 const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer();
1831 if (ToSetShowFreeBoundary != 0)
1832 {
1833 theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1);
1834 toRecompute = true;
1835 }
1836 if (ToSetFreeBoundaryWidth != 0)
1837 {
1838 if (ToSetFreeBoundaryWidth != -1
1839 || theDrawer->HasOwnFreeBoundaryAspect())
1840 {
1841 if (!theDrawer->HasOwnFreeBoundaryAspect())
1842 {
1843 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1844 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1845 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1846 toRecompute = true;
1847 }
1848 theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth);
1849 }
1850 }
1851 if (ToSetFreeBoundaryColor != 0)
1852 {
1853 Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
1854 *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect();
1855 aBoundaryAspect->SetColor (FreeBoundaryColor);
1856 theDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
1857 toRecompute = true;
1858 }
1859 if (ToSetTypeOfLine != 0)
1860 {
1861 if (ToSetTypeOfLine != -1
1862 || theDrawer->HasOwnLineAspect()
1863 || theDrawer->HasOwnWireAspect()
1864 || theDrawer->HasOwnFreeBoundaryAspect()
1865 || theDrawer->HasOwnUnFreeBoundaryAspect()
1866 || theDrawer->HasOwnSeenLineAspect())
1867 {
1868 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
1869 theDrawer->LineAspect()->SetTypeOfLine (TypeOfLine);
1870 theDrawer->WireAspect()->SetTypeOfLine (TypeOfLine);
1871 theDrawer->FreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
1872 theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
1873 theDrawer->SeenLineAspect()->SetTypeOfLine (TypeOfLine);
1874 }
1875 }
1876 if (ToSetTypeOfMarker != 0)
1877 {
1878 if (ToSetTypeOfMarker != -1
1879 || theDrawer->HasOwnPointAspect())
1880 {
1881 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1882 theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker);
1883 theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage));
1884 }
1885 }
1886 if (ToSetMarkerSize != 0)
1887 {
1888 if (ToSetMarkerSize != -1
1889 || theDrawer->HasOwnPointAspect())
1890 {
1891 toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute;
1892 theDrawer->PointAspect()->SetScale (MarkerSize);
1893 toRecompute = true;
1894 }
1895 }
1896 if (ToSetMaxParamValue != 0)
1897 {
1898 if (ToSetMaxParamValue != -1
1899 || theDrawer->HasOwnMaximalParameterValue())
1900 {
1901 theDrawer->SetMaximalParameterValue (MaxParamValue);
1902 toRecompute = true;
1903 }
1904 }
0493ffd0 1905 if (ToSetFaceBoundaryDraw != 0)
1906 {
1907 if (ToSetFaceBoundaryDraw != -1
1908 || theDrawer->HasOwnFaceBoundaryDraw())
1909 {
1910 toRecompute = true;
1911 theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1);
1912 }
1913 }
1914 if (ToSetFaceBoundaryUpperContinuity != 0)
1915 {
1916 if (ToSetFaceBoundaryUpperContinuity != -1
1917 || theDrawer->HasOwnFaceBoundaryUpperContinuity())
1918 {
1919 toRecompute = true;
1920 if (ToSetFaceBoundaryUpperContinuity == -1)
1921 {
1922 theDrawer->UnsetFaceBoundaryUpperContinuity();
1923 }
1924 else
1925 {
1926 theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity);
1927 }
1928 }
1929 }
1930 if (ToSetFaceBoundaryColor != 0)
1931 {
1932 if (ToSetFaceBoundaryColor != -1
1933 || theDrawer->HasOwnFaceBoundaryAspect())
1934 {
1935 if (ToSetFaceBoundaryColor == -1)
1936 {
1937 toRecompute = true;
1938 theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
1939 }
1940 else
1941 {
1942 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1943 theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor);
1944 }
1945 }
1946 }
1947 if (ToSetFaceBoundaryWidth != 0)
1948 {
1949 if (ToSetFaceBoundaryWidth != -1
1950 || theDrawer->HasOwnFaceBoundaryAspect())
1951 {
1952 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1953 theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth);
1954 }
1955 }
1956 if (ToSetTypeOfFaceBoundaryLine != 0)
1957 {
1958 if (ToSetTypeOfFaceBoundaryLine != -1
1959 || theDrawer->HasOwnFaceBoundaryAspect())
1960 {
1961 toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute;
1962 theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine);
1963 }
1964 }
2a332745 1965 if (ToSetShadingModel != 0)
1966 {
1967 if (ToSetShadingModel != -1
1968 || theDrawer->HasOwnShadingAspect())
1969 {
1970 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1971 theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
1972 }
1973 }
1974 if (ToSetAlphaMode != 0)
1975 {
1976 if (ToSetAlphaMode != -1
1977 || theDrawer->HasOwnShadingAspect())
1978 {
1979 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
1980 theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff);
1981 }
1982 }
1983 if (ToSetHatch != 0)
1984 {
1985 if (ToSetHatch != -1
1986 || theDrawer->HasOwnShadingAspect())
1987 {
1988 theDrawer->SetupOwnShadingAspect (aDefDrawer);
1989 Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
1990 if (ToSetHatch == -1)
1991 {
1992 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
1993 }
1994 else
1995 {
1996 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
1997 if (!PathToHatchPattern.IsEmpty())
1998 {
1999 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2000 if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString())))
2001 {
2002 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2003 }
2004 else
2005 {
2006 std::cout << "Error: cannot load the following image: " << PathToHatchPattern << "\n";
2007 }
2008 }
2009 else if (StdHatchStyle != -1)
2010 {
2011 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle));
2012 }
2013 }
2014 toRecompute = true;
2015 }
2016 }
2017 if (ToSetInterior != 0)
2018 {
2019 if (ToSetInterior != -1
2020 || theDrawer->HasOwnShadingAspect())
2021 {
2022 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2023 theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle);
2024 if (InteriorStyle == Aspect_IS_HATCH
2025 && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull())
2026 {
2027 theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL);
2028 }
2029 }
2030 }
6ef0d6f1 2031 if (ToSetDrawSilhouette != 0)
2032 {
2033 if (ToSetDrawSilhouette != -1
2034 || theDrawer->HasOwnShadingAspect())
2035 {
2036 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2037 theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1);
2038 }
2039 }
2a332745 2040 if (ToSetDrawEdges != 0)
2041 {
2042 if (ToSetDrawEdges != -1
2043 || theDrawer->HasOwnShadingAspect())
2044 {
2045 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2046 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1);
2047 }
2048 }
2049 if (ToSetQuadEdges != 0)
2050 {
2051 if (ToSetQuadEdges != -1
2052 || theDrawer->HasOwnShadingAspect())
2053 {
2054 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2055 theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1);
2056 }
2057 }
2058 if (ToSetEdgeWidth != 0)
2059 {
2060 if (ToSetEdgeWidth != -1
2061 || theDrawer->HasOwnShadingAspect())
2062 {
2063 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2064 theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth);
2065 }
2066 }
2067 if (ToSetTypeOfEdge != 0)
2068 {
2069 if (ToSetTypeOfEdge != -1
2070 || theDrawer->HasOwnShadingAspect())
2071 {
2072 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2073 theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge);
2074 if (ToSetInterior == 0)
2075 {
2076 theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1
2077 && TypeOfEdge != Aspect_TOL_EMPTY);
2078 }
2079 }
2080 }
2081 if (ToSetEdgeColor != 0)
2082 {
2083 if (ToSetEdgeColor != -1
2084 || theDrawer->HasOwnShadingAspect())
2085 {
2086 toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
2087 if (ToSetEdgeColor == -1)
2088 {
2089 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor());
2090 }
2091 else
2092 {
2093 theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor);
2094 }
2095 }
2096 }
2097 return toRecompute;
2098 }
ad3217cd 2099};
7fd59977 2100
2101//==============================================================================
ad3217cd 2102//function : VAspects
2103//purpose :
7fd59977 2104//==============================================================================
ad3217cd 2105static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
2106 Standard_Integer theArgNb,
2107 const char** theArgVec)
7fd59977 2108{
ad3217cd 2109 TCollection_AsciiString aCmdName (theArgVec[0]);
2110 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2111 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 2112 if (aCtx.IsNull())
2113 {
2114 std::cerr << "Error: no active view!\n";
2115 return 1;
2116 }
7fd59977 2117
4e18052b 2118 Standard_Integer anArgIter = 1;
6262338c 2119 Standard_Boolean isDefaults = Standard_False;
ad3217cd 2120 NCollection_Sequence<TCollection_AsciiString> aNames;
2121 for (; anArgIter < theArgNb; ++anArgIter)
2122 {
2123 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 2124 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 2125 {
2126 continue;
2127 }
2128 else if (!anArg.IsEmpty()
2129 && anArg.Value (1) != '-')
2130 {
2131 aNames.Append (anArg);
2132 }
2133 else
2134 {
6262338c 2135 if (anArg == "-defaults")
2136 {
2137 isDefaults = Standard_True;
2138 ++anArgIter;
2139 }
ad3217cd 2140 break;
2141 }
2142 }
2143
6262338c 2144 if (!aNames.IsEmpty() && isDefaults)
2145 {
2146 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
2147 return 1;
2148 }
2149
ad3217cd 2150 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
2151 aChanges.Append (ViewerTest_AspectsChangeSet());
2152 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 2153
ad3217cd 2154 // parse syntax of legacy commands
2a332745 2155 bool toParseAliasArgs = false;
ad3217cd 2156 if (aCmdName == "vsetwidth")
2157 {
2158 if (aNames.IsEmpty()
2159 || !aNames.Last().IsRealValue())
2160 {
2161 std::cout << "Error: not enough arguments!\n";
2162 return 1;
2163 }
2164 aChangeSet->ToSetLineWidth = 1;
2165 aChangeSet->LineWidth = aNames.Last().RealValue();
2166 aNames.Remove (aNames.Length());
7fd59977 2167 }
ad3217cd 2168 else if (aCmdName == "vunsetwidth")
2169 {
2170 aChangeSet->ToSetLineWidth = -1;
2171 }
2172 else if (aCmdName == "vsetcolor")
2173 {
2174 if (aNames.IsEmpty())
2175 {
2176 std::cout << "Error: not enough arguments!\n";
2177 return 1;
2178 }
2179 aChangeSet->ToSetColor = 1;
8316c618 2180
2181 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2182 Standard_Boolean isOk = Standard_False;
2183 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
2184 {
2185 aChangeSet->Color = aColor;
2186 aNames.Remove (aNames.Length());
2187 isOk = Standard_True;
2188 }
2189 else if (aNames.Length() >= 3)
2190 {
2a332745 2191 const char* anArgVec[3] =
8316c618 2192 {
2a332745 2193 aNames.Value (aNames.Upper() - 2).ToCString(),
2194 aNames.Value (aNames.Upper() - 1).ToCString(),
2195 aNames.Value (aNames.Upper() - 0).ToCString(),
8316c618 2196 };
2a332745 2197
2198 Standard_Integer aNbParsed = ViewerTest::ParseColor (3, anArgVec, aChangeSet->Color);
2199 isOk = aNbParsed == 3;
2200 aNames.Remove (aNames.Length());
2201 aNames.Remove (aNames.Length());
2202 aNames.Remove (aNames.Length());
8316c618 2203 }
2204 if (!isOk)
2205 {
2206 std::cout << "Error: not enough arguments!\n";
2207 return 1;
2208 }
ad3217cd 2209 }
2210 else if (aCmdName == "vunsetcolor")
2211 {
2212 aChangeSet->ToSetColor = -1;
2213 }
2214 else if (aCmdName == "vsettransparency")
2215 {
2216 if (aNames.IsEmpty()
2217 || !aNames.Last().IsRealValue())
2218 {
2219 std::cout << "Error: not enough arguments!\n";
2220 return 1;
2221 }
2222 aChangeSet->ToSetTransparency = 1;
2223 aChangeSet->Transparency = aNames.Last().RealValue();
2224 aNames.Remove (aNames.Length());
2225 }
2226 else if (aCmdName == "vunsettransparency")
2227 {
2228 aChangeSet->ToSetTransparency = -1;
2229 }
2230 else if (aCmdName == "vsetmaterial")
2231 {
2232 if (aNames.IsEmpty())
2233 {
2234 std::cout << "Error: not enough arguments!\n";
2235 return 1;
2236 }
2237 aChangeSet->ToSetMaterial = 1;
2238 aChangeSet->MatName = aNames.Last();
2239 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2240 aNames.Remove (aNames.Length());
2241 }
2242 else if (aCmdName == "vunsetmaterial")
2243 {
2244 aChangeSet->ToSetMaterial = -1;
2245 }
2a332745 2246 else if (aCmdName == "vsetinteriorstyle")
2247 {
2248 if (aNames.IsEmpty()
2249 || !aNames.Last().IsRealValue())
2250 {
2251 std::cout << "Error: not enough arguments!\n";
2252 return 1;
2253 }
2254 aChangeSet->ToSetInterior = 1;
2255 if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle))
2256 {
2257 std::cout << "Error: wrong syntax at " << aNames.Last() << "\n";
2258 return 1;
2259 }
2260 aNames.Remove (aNames.Length());
2261 }
2262 else if (aCmdName == "vsetedgetype")
2263 {
2264 aChangeSet->ToSetDrawEdges = 1;
2265 toParseAliasArgs = true;
2266 }
2267 else if (aCmdName == "vunsetedgetype")
2268 {
2269 aChangeSet->ToSetDrawEdges = -1;
2270 aChangeSet->ToSetEdgeColor = -1;
2271 aChangeSet->ToSetTypeOfEdge = -1;
2272 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
2273 }
0493ffd0 2274 else if (aCmdName == "vshowfaceboundary")
2275 {
2276 aChangeSet->ToSetFaceBoundaryDraw = 1;
2277 toParseAliasArgs = true;
2278 if (aNames.Size() >= 2
2279 && aNames.Value (2).IsIntegerValue())
2280 {
2281 if (aNames.Size() == 7)
2282 {
2283 if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine))
2284 {
2285 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2286 aNames.Remove (7);
2287 }
2288 }
2289 if (aNames.Size() == 6
2290 && aNames.Value (6).IsRealValue())
2291 {
2292 aChangeSet->ToSetFaceBoundaryWidth = 1;
2293 aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue();
2294 aNames.Remove (6);
2295 }
2296 if (aNames.Size() == 5
2297 && aNames.Value (3).IsIntegerValue()
2298 && aNames.Value (4).IsIntegerValue()
2299 && aNames.Value (5).IsIntegerValue())
2300 {
2301 aChangeSet->ToSetFaceBoundaryColor = 1;
2302 aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
2303 aNames.Value (4).IntegerValue() / 255.0,
2304 aNames.Value (5).IntegerValue() / 255.0,
2305 Quantity_TOC_RGB);
2306 aNames.Remove (5);
2307 aNames.Remove (4);
2308 aNames.Remove (3);
2309 }
2310 if (aNames.Size() == 2)
2311 {
2312 toParseAliasArgs = false;
2313 aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1;
2314 aNames.Remove (2);
2315 }
2316 }
2317 }
ad3217cd 2318 else if (anArgIter >= theArgNb)
2319 {
2320 std::cout << "Error: not enough arguments!\n";
2321 return 1;
7fd59977 2322 }
2323
2a332745 2324 if (!aChangeSet->IsEmpty()
2325 && !toParseAliasArgs)
ad3217cd 2326 {
2327 anArgIter = theArgNb;
2328 }
2329 for (; anArgIter < theArgNb; ++anArgIter)
2330 {
2331 TCollection_AsciiString anArg = theArgVec[anArgIter];
2332 anArg.LowerCase();
2333 if (anArg == "-setwidth"
2a332745 2334 || anArg == "-width"
2335 || anArg == "-setlinewidth"
2336 || anArg == "-linewidth"
2337 || anArg == "-setedgewidth"
2338 || anArg == "-setedgeswidth"
2339 || anArg == "-edgewidth"
0493ffd0 2340 || anArg == "-edgeswidth"
2341 || anArg == "-setfaceboundarywidth"
2342 || anArg == "-setboundarywidth"
2343 || anArg == "-faceboundarywidth"
2344 || anArg == "-boundarywidth")
ad3217cd 2345 {
2346 if (++anArgIter >= theArgNb)
2347 {
2348 std::cout << "Error: wrong syntax at " << anArg << "\n";
2349 return 1;
2350 }
0493ffd0 2351
2352 const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]);
2a332745 2353 if (anArg == "-setedgewidth"
2354 || anArg == "-setedgeswidth"
2355 || anArg == "-edgewidth"
2356 || anArg == "-edgeswidth"
2357 || aCmdName == "vsetedgetype")
2358 {
2359 aChangeSet->ToSetEdgeWidth = 1;
0493ffd0 2360 aChangeSet->EdgeWidth = aWidth;
2361 }
2362 else if (anArg == "-setfaceboundarywidth"
2363 || anArg == "-setboundarywidth"
2364 || anArg == "-faceboundarywidth"
2365 || anArg == "-boundarywidth"
2366 || aCmdName == "vshowfaceboundary")
2367 {
2368 aChangeSet->ToSetFaceBoundaryWidth = 1;
2369 aChangeSet->FaceBoundaryWidth = aWidth;
2a332745 2370 }
2371 else
2372 {
2373 aChangeSet->ToSetLineWidth = 1;
0493ffd0 2374 aChangeSet->LineWidth = aWidth;
2a332745 2375 }
7fd59977 2376 }
ad3217cd 2377 else if (anArg == "-unsetwidth"
2a332745 2378 || anArg == "-unsetlinewidth"
2379 || anArg == "-unsetedgewidth")
ad3217cd 2380 {
2a332745 2381 if (anArg == "-unsetedgewidth")
2382 {
2383 aChangeSet->ToSetEdgeWidth = -1;
2384 aChangeSet->EdgeWidth = 1.0;
2385 }
2386 else
2387 {
2388 aChangeSet->ToSetLineWidth = -1;
2389 aChangeSet->LineWidth = 1.0;
2390 }
ad3217cd 2391 }
2392 else if (anArg == "-settransp"
2a332745 2393 || anArg == "-settransparency"
2394 || anArg == "-transparency"
2395 || anArg == "-transp")
ad3217cd 2396 {
2397 if (++anArgIter >= theArgNb)
2398 {
2399 std::cout << "Error: wrong syntax at " << anArg << "\n";
2400 return 1;
2401 }
2402 aChangeSet->ToSetTransparency = 1;
2403 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2404 if (aChangeSet->Transparency >= 0.0
2405 && aChangeSet->Transparency <= Precision::Confusion())
2406 {
2407 aChangeSet->ToSetTransparency = -1;
2408 aChangeSet->Transparency = 0.0;
eafb234b 2409 }
7fd59977 2410 }
2a332745 2411 else if (anArg == "-setalphamode"
2412 || anArg == "-alphamode")
c40eb6b9 2413 {
2414 if (++anArgIter >= theArgNb)
2415 {
2416 std::cout << "Error: wrong syntax at " << anArg << "\n";
2417 return 1;
2418 }
2419 aChangeSet->ToSetAlphaMode = 1;
2420 aChangeSet->AlphaCutoff = 0.5f;
2421 {
2422 TCollection_AsciiString aParam (theArgVec[anArgIter]);
2423 aParam.LowerCase();
2424 if (aParam == "opaque")
2425 {
2426 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
2427 }
2428 else if (aParam == "mask")
2429 {
2430 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
2431 }
2432 else if (aParam == "blend")
2433 {
2434 aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
2435 }
2436 else if (aParam == "blendauto"
2437 || aParam == "auto")
2438 {
2439 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
2440 }
2441 else
2442 {
2443 std::cout << "Error: wrong syntax at " << aParam << "\n";
2444 return 1;
2445 }
2446 }
2447
2448 if (anArgIter + 1 < theArgNb
2449 && theArgVec[anArgIter + 1][0] != '-')
2450 {
2451 TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
2452 if (aParam2.IsRealValue())
2453 {
2454 aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
2455 ++anArgIter;
2456 }
2457 }
2458 }
5bffb882 2459 else if (anArg == "-setvis"
2a332745 2460 || anArg == "-setvisibility"
2461 || anArg == "-visibility")
5bffb882 2462 {
2463 if (++anArgIter >= theArgNb)
2464 {
2465 std::cout << "Error: wrong syntax at " << anArg << "\n";
2466 return 1;
2467 }
2468
2469 aChangeSet->ToSetVisibility = 1;
2470 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
2471 }
2a332745 2472 else if (anArg == "-setalpha"
2473 || anArg == "-alpha")
ad3217cd 2474 {
2475 if (++anArgIter >= theArgNb)
7fd59977 2476 {
ad3217cd 2477 std::cout << "Error: wrong syntax at " << anArg << "\n";
2478 return 1;
2479 }
2480 aChangeSet->ToSetTransparency = 1;
2481 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2482 if (aChangeSet->Transparency < 0.0
2483 || aChangeSet->Transparency > 1.0)
2484 {
2485 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2486 return 1;
2487 }
2488 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2489 if (aChangeSet->Transparency >= 0.0
2490 && aChangeSet->Transparency <= Precision::Confusion())
2491 {
2492 aChangeSet->ToSetTransparency = -1;
2493 aChangeSet->Transparency = 0.0;
7fd59977 2494 }
7fd59977 2495 }
ad3217cd 2496 else if (anArg == "-unsettransp"
0ae61cf3 2497 || anArg == "-unsettransparency"
ad3217cd 2498 || anArg == "-unsetalpha"
2499 || anArg == "-opaque")
2500 {
2501 aChangeSet->ToSetTransparency = -1;
2502 aChangeSet->Transparency = 0.0;
2503 }
2a332745 2504 else if (anArg == "-setcolor"
0493ffd0 2505 || anArg == "-color"
2506 || anArg == "-setfaceboundarycolor"
2507 || anArg == "-setboundarycolor"
2508 || anArg == "-faceboundarycolor"
2509 || anArg == "-boundarycolor")
ad3217cd 2510 {
2a332745 2511 Quantity_Color aColor;
2512 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2513 theArgVec + anArgIter + 1,
2514 aColor);
2515 if (aNbParsed == 0)
ad3217cd 2516 {
2a332745 2517 std::cout << "Syntax error at '" << anArg << "'\n";
2518 return 1;
8316c618 2519 }
2a332745 2520 anArgIter += aNbParsed;
2521 if (aCmdName == "vsetedgetype")
8316c618 2522 {
2a332745 2523 aChangeSet->ToSetEdgeColor = 1;
2524 aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor);
2525 }
0493ffd0 2526 else if (aCmdName == "vshowfaceboundary"
2527 || anArg == "-setfaceboundarycolor"
2528 || anArg == "-setboundarycolor"
2529 || anArg == "-faceboundarycolor"
2530 || anArg == "-boundarycolor")
2531 {
2532 aChangeSet->ToSetFaceBoundaryColor = 1;
2533 aChangeSet->FaceBoundaryColor = aColor;
2534 }
2a332745 2535 else
2536 {
2537 aChangeSet->ToSetColor = 1;
2538 aChangeSet->Color = aColor;
7fd59977 2539 }
7fd59977 2540 }
2a332745 2541 else if (anArg == "-setlinetype"
2542 || anArg == "-linetype"
2543 || anArg == "-setedgetype"
2544 || anArg == "-setedgestype"
2545 || anArg == "-edgetype"
2546 || anArg == "-edgestype"
0493ffd0 2547 || anArg == "-setfaceboundarystyle"
2548 || anArg == "-faceboundarystyle"
2549 || anArg == "-boundarystyle"
2550 || anArg == "-setfaceboundarytype"
2551 || anArg == "-faceboundarytype"
2552 || anArg == "-setboundarytype"
2553 || anArg == "-boundarytype"
2a332745 2554 || anArg == "-type")
ac116c22 2555 {
2556 if (++anArgIter >= theArgNb)
2557 {
2558 std::cout << "Error: wrong syntax at " << anArg << "\n";
2559 return 1;
2560 }
2a332745 2561 Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
2562 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
ac116c22 2563 {
2564 std::cout << "Error: wrong syntax at " << anArg << "\n";
2565 return 1;
2566 }
2a332745 2567 if (anArg == "-setedgetype"
2568 || anArg == "-setedgestype"
2569 || anArg == "-edgetype"
2570 || anArg == "-edgestype"
2571 || aCmdName == "vsetedgetype")
2572 {
2573 aChangeSet->TypeOfEdge = aLineType;
2574 aChangeSet->ToSetTypeOfEdge = 1;
2575 }
0493ffd0 2576 else if (anArg == "-setfaceboundarystyle"
2577 || anArg == "-faceboundarystyle"
2578 || anArg == "-boundarystyle"
2579 || anArg == "-setfaceboundarytype"
2580 || anArg == "-faceboundarytype"
2581 || anArg == "-setboundarytype"
2582 || anArg == "-boundarytype"
2583 || aCmdName == "vshowfaceboundary")
2584 {
2585 aChangeSet->TypeOfFaceBoundaryLine = aLineType;
2586 aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
2587 }
2a332745 2588 else
2589 {
2590 aChangeSet->TypeOfLine = aLineType;
2591 aChangeSet->ToSetTypeOfLine = 1;
2592 }
ac116c22 2593 }
2a332745 2594 else if (anArg == "-unsetlinetype"
2595 || anArg == "-unsetedgetype"
2596 || anArg == "-unsetedgestype")
ac116c22 2597 {
2a332745 2598 if (anArg == "-unsetedgetype"
2599 || anArg == "-unsetedgestype")
2600 {
2601 aChangeSet->ToSetTypeOfEdge = -1;
2602 }
2603 else
2604 {
2605 aChangeSet->ToSetTypeOfLine = -1;
2606 }
ac116c22 2607 }
33cc703b 2608 else if (anArg == "-setmarkertype"
2a332745 2609 || anArg == "-markertype"
2610 || anArg == "-setpointtype"
2611 || anArg == "-pointtype")
33cc703b 2612 {
2613 if (++anArgIter >= theArgNb)
2614 {
2615 std::cout << "Error: wrong syntax at " << anArg << "\n";
2616 return 1;
2617 }
2618 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2619 {
2620 std::cout << "Error: wrong syntax at " << anArg << "\n";
2621 return 1;
2622 }
2623
2624 aChangeSet->ToSetTypeOfMarker = 1;
2625 }
2626 else if (anArg == "-unsetmarkertype"
2627 || anArg == "-unsetpointtype")
2628 {
2629 aChangeSet->ToSetTypeOfMarker = -1;
2630 }
2631 else if (anArg == "-setmarkersize"
2a332745 2632 || anArg == "-markersize"
2633 || anArg == "-setpointsize"
2634 || anArg == "-pointsize")
33cc703b 2635 {
2636 if (++anArgIter >= theArgNb)
2637 {
2638 std::cout << "Error: wrong syntax at " << anArg << "\n";
2639 return 1;
2640 }
2641 aChangeSet->ToSetMarkerSize = 1;
2642 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2643 }
2644 else if (anArg == "-unsetmarkersize"
2645 || anArg == "-unsetpointsize")
2646 {
2647 aChangeSet->ToSetMarkerSize = -1;
2648 aChangeSet->MarkerSize = 1.0;
2649 }
ad3217cd 2650 else if (anArg == "-unsetcolor")
2651 {
2652 aChangeSet->ToSetColor = -1;
2653 aChangeSet->Color = DEFAULT_COLOR;
2654 }
2655 else if (anArg == "-setmat"
2a332745 2656 || anArg == "-mat"
2657 || anArg == "-setmaterial"
2658 || anArg == "-material")
ad3217cd 2659 {
2660 if (++anArgIter >= theArgNb)
2661 {
2662 std::cout << "Error: wrong syntax at " << anArg << "\n";
2663 return 1;
2664 }
2665 aChangeSet->ToSetMaterial = 1;
2666 aChangeSet->MatName = theArgVec[anArgIter];
2667 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2668 }
2669 else if (anArg == "-unsetmat"
2670 || anArg == "-unsetmaterial")
2671 {
2672 aChangeSet->ToSetMaterial = -1;
2673 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2674 }
2675 else if (anArg == "-subshape"
2676 || anArg == "-subshapes")
2677 {
6262338c 2678 if (isDefaults)
2679 {
2680 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2681 return 1;
2682 }
2683
ad3217cd 2684 if (aNames.IsEmpty())
2685 {
2686 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2687 return 1;
2688 }
7fd59977 2689
ad3217cd 2690 aChanges.Append (ViewerTest_AspectsChangeSet());
2691 aChangeSet = &aChanges.ChangeLast();
7fd59977 2692
ad3217cd 2693 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2694 {
2695 Standard_CString aSubShapeName = theArgVec[anArgIter];
2696 if (*aSubShapeName == '-')
2697 {
2698 --anArgIter;
2699 break;
2700 }
7fd59977 2701
ad3217cd 2702 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2703 if (aSubShape.IsNull())
2704 {
2705 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2706 return 1;
2707 }
2708 aChangeSet->SubShapes.Append (aSubShape);
2709 }
7fd59977 2710
ad3217cd 2711 if (aChangeSet->SubShapes.IsEmpty())
2712 {
2713 std::cerr << "Error: empty list is specified after -subshapes!\n";
2714 return 1;
2715 }
2716 }
2a332745 2717 else if (anArg == "-setfreeboundary"
2718 || anArg == "-freeboundary"
2719 || anArg == "-setfb"
6262338c 2720 || anArg == "-fb")
2721 {
0493ffd0 2722 bool toEnable = true;
2723 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
6262338c 2724 {
2725 std::cout << "Error: wrong syntax at " << anArg << "\n";
2726 return 1;
2727 }
0493ffd0 2728 ++anArgIter;
2729 aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1;
6262338c 2730 }
2731 else if (anArg == "-setfreeboundarywidth"
2a332745 2732 || anArg == "-freeboundarywidth"
2733 || anArg == "-setfbwidth"
2734 || anArg == "-fbwidth")
6262338c 2735 {
2736 if (++anArgIter >= theArgNb)
2737 {
2738 std::cout << "Error: wrong syntax at " << anArg << "\n";
2739 return 1;
2740 }
2741 aChangeSet->ToSetFreeBoundaryWidth = 1;
2742 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2743 }
2744 else if (anArg == "-unsetfreeboundarywidth"
2745 || anArg == "-unsetfbwidth")
2746 {
2747 aChangeSet->ToSetFreeBoundaryWidth = -1;
2748 aChangeSet->FreeBoundaryWidth = 1.0;
2749 }
2750 else if (anArg == "-setfreeboundarycolor"
2a332745 2751 || anArg == "-freeboundarycolor"
2752 || anArg == "-setfbcolor"
2753 || anArg == "-fbcolor")
6262338c 2754 {
2a332745 2755 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
2756 theArgVec + anArgIter + 1,
2757 aChangeSet->FreeBoundaryColor);
2758 if (aNbParsed == 0)
6262338c 2759 {
2a332745 2760 std::cout << "Syntax error at '" << anArg << "'\n";
2761 return 1;
6262338c 2762 }
2a332745 2763 anArgIter += aNbParsed;
6262338c 2764 aChangeSet->ToSetFreeBoundaryColor = 1;
6262338c 2765 }
2766 else if (anArg == "-unsetfreeboundarycolor"
2767 || anArg == "-unsetfbcolor")
2768 {
2769 aChangeSet->ToSetFreeBoundaryColor = -1;
2770 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2771 }
2a332745 2772 else if (anArg == "-setisoontriangulation"
2773 || anArg == "-isoontriangulation"
2774 || anArg == "-setisoontriang"
5ad8c033 2775 || anArg == "-isoontriang")
2776 {
0493ffd0 2777 bool toEnable = true;
2778 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
5ad8c033 2779 {
2780 std::cout << "Error: wrong syntax at " << anArg << "\n";
2781 return 1;
2782 }
0493ffd0 2783 ++anArgIter;
2784 aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1;
2785 }
2786 else if (anArg == "-setfaceboundarydraw"
2787 || anArg == "-setdrawfaceboundary"
2788 || anArg == "-setdrawfaceboundaries"
2789 || anArg == "-setshowfaceboundary"
2790 || anArg == "-setshowfaceboundaries"
2791 || anArg == "-setdrawfaceedges"
2792 || anArg == "-faceboundarydraw"
2793 || anArg == "-drawfaceboundary"
2794 || anArg == "-drawfaceboundaries"
2795 || anArg == "-showfaceboundary"
2796 || anArg == "-showfaceboundaries"
2797 || anArg == "-drawfaceedges"
2798 || anArg == "-faceboundary"
2799 || anArg == "-faceboundaries"
2800 || anArg == "-faceedges")
2801 {
2802 bool toEnable = true;
2803 if (!ViewerTest::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable))
2804 {
2805 std::cout << "Error: wrong syntax at " << anArg << "\n";
2806 return 1;
2807 }
2808 ++anArgIter;
2809 aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1;
2810 }
2811 else if (anArg == "-unsetfaceboundary"
2812 || anArg == "-unsetboundary")
2813 {
2814 aChangeSet->ToSetFaceBoundaryDraw = -1;
2815 aChangeSet->ToSetFaceBoundaryColor = -1;
2816 }
2817 else if (anArg == "-setmostcontinuity"
2818 || anArg == "-mostcontinuity")
2819 {
2820 TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "");
2821 aClassArg.LowerCase();
2822 GeomAbs_Shape aClass = GeomAbs_CN;
2823 if (aClassArg == "c0"
2824 || aClassArg == "0")
5ad8c033 2825 {
0493ffd0 2826 aClass = GeomAbs_C0;
5ad8c033 2827 }
0493ffd0 2828 else if (aClassArg == "c1"
2829 || aClassArg == "1")
5ad8c033 2830 {
0493ffd0 2831 aClass = GeomAbs_C1;
2832 }
2833 else if (aClassArg == "c2"
2834 || aClassArg == "2")
2835 {
2836 aClass = GeomAbs_C2;
2837 }
2838 else if (aClassArg == "c3"
2839 || aClassArg == "3")
2840 {
2841 aClass = GeomAbs_C3;
2842 }
2843 else if (aClassArg == "cn"
2844 || aClassArg == "n")
2845 {
2846 aClass = GeomAbs_CN;
5ad8c033 2847 }
2848 else
2849 {
0493ffd0 2850 std::cout << "Syntax error at '" << anArg << "'\n";
5ad8c033 2851 return 1;
2852 }
0493ffd0 2853
2854 ++anArgIter;
2855 aChangeSet->ToSetFaceBoundaryUpperContinuity = 1;
2856 aChangeSet->FaceBoundaryUpperContinuity = aClass;
5ad8c033 2857 }
2a332745 2858 else if (anArg == "-setmaxparamvalue"
2859 || anArg == "-maxparamvalue")
5ad8c033 2860 {
2861 if (++anArgIter >= theArgNb)
2862 {
2863 std::cout << "Error: wrong syntax at " << anArg << "\n";
2864 return 1;
2865 }
2866 aChangeSet->ToSetMaxParamValue = 1;
2867 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2868 }
2a332745 2869 else if (anArg == "-setsensitivity"
2870 || anArg == "-sensitivity")
8a1170ad 2871 {
2872 if (isDefaults)
2873 {
2874 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2875 return 1;
2876 }
2877
2878 if (aNames.IsEmpty())
2879 {
2880 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2881 return 1;
2882 }
2883
2884 if (anArgIter + 2 >= theArgNb)
2885 {
2886 std::cout << "Error: wrong syntax at " << anArg << "\n";
2887 return 1;
2888 }
2889 aChangeSet->ToSetSensitivity = 1;
2890 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2891 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2892 }
2a332745 2893 else if (anArg == "-sethatch"
2894 || anArg == "-hatch")
640d5fe2 2895 {
2896 if (isDefaults)
2897 {
2898 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2899 return 1;
2900 }
2901
2902 if (aNames.IsEmpty())
2903 {
2904 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2905 return 1;
2906 }
2907
2908 aChangeSet->ToSetHatch = 1;
eadea5ea 2909 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2910 if (anArgHatch.Length() <= 2)
640d5fe2 2911 {
ec7c343f 2912 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2913 if (anIntStyle < 0
2914 || anIntStyle >= Aspect_HS_NB)
2915 {
2916 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2917 return 1;
2918 }
2919 aChangeSet->StdHatchStyle = anIntStyle;
640d5fe2 2920 }
2921 else
2922 {
eadea5ea 2923 aChangeSet->PathToHatchPattern = anArgHatch;
640d5fe2 2924 }
2925 }
2a332745 2926 else if (anArg == "-setshadingmodel"
2927 || anArg == "-setshading"
2928 || anArg == "-shadingmodel"
2929 || anArg == "-shading")
dc89236f 2930 {
2931 if (++anArgIter >= theArgNb)
2932 {
2933 std::cout << "Error: wrong syntax at " << anArg << "\n";
2934 return 1;
2935 }
2936 aChangeSet->ToSetShadingModel = 1;
2937 aChangeSet->ShadingModelName = theArgVec[anArgIter];
2938 if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
2939 {
2940 std::cout << "Error: wrong syntax at " << anArg << "\n";
2941 return 1;
2942 }
2943 }
2944 else if (anArg == "-unsetshadingmodel")
2945 {
2946 aChangeSet->ToSetShadingModel = -1;
2947 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
2948 }
2a332745 2949 else if (anArg == "-setinterior"
2950 || anArg == "-setinteriorstyle"
2951 || anArg == "-interior"
2952 || anArg == "-interiorstyle")
2953 {
2954 if (++anArgIter >= theArgNb)
2955 {
2956 std::cout << "Error: wrong syntax at " << anArg << "\n";
2957 return 1;
2958 }
2959 aChangeSet->ToSetInterior = 1;
2960 if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle))
2961 {
2962 std::cout << "Error: wrong syntax at " << anArg << "\n";
2963 return 1;
2964 }
2965 }
2966 else if (anArg == "-unsetinterior")
2967 {
2968 aChangeSet->ToSetInterior = -1;
2969 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
2970 }
6ef0d6f1 2971 else if (anArg == "-setdrawoutline"
2972 || anArg == "-setdrawsilhouette"
2973 || anArg == "-setoutline"
2974 || anArg == "-setsilhouette"
2975 || anArg == "-outline"
2976 || anArg == "-outlined"
2977 || anArg == "-silhouette")
2978 {
2979 bool toDrawOutline = true;
2980 if (anArgIter + 1 < theArgNb
2981 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline))
2982 {
2983 ++anArgIter;
2984 }
2985 aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1;
2986 }
2a332745 2987 else if (anArg == "-setdrawedges"
2988 || anArg == "-setdrawedge"
2989 || anArg == "-drawedges"
2990 || anArg == "-drawedge"
2991 || anArg == "-edges")
2992 {
2993 bool toDrawEdges = true;
2994 if (anArgIter + 1 < theArgNb
2995 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges))
2996 {
2997 ++anArgIter;
2998 }
2999 aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1;
3000 }
3001 else if (anArg == "-setquadedges"
3002 || anArg == "-setquads"
3003 || anArg == "-quads"
3004 || anArg == "-skipfirstedge")
3005 {
3006 bool isQuadMode = true;
3007 if (anArgIter + 1 < theArgNb
3008 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode))
3009 {
3010 ++anArgIter;
3011 }
3012 aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1;
3013 }
3014 else if (anArg == "-setedgecolor"
3015 || anArg == "-setedgescolor"
3016 || anArg == "-edgecolor"
3017 || anArg == "-edgescolor")
3018 {
3019 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3020 theArgVec + anArgIter + 1,
3021 aChangeSet->EdgeColor);
3022 if (aNbParsed == 0)
3023 {
3024 std::cout << "Syntax error at '" << anArg << "'\n";
3025 return 1;
3026 }
3027 anArgIter += aNbParsed;
3028 aChangeSet->ToSetEdgeColor = 1;
3029 }
3030 else if (anArg == "-unset")
3031 {
3032 aChangeSet->ToSetVisibility = 1;
3033 aChangeSet->Visibility = 1;
3034 aChangeSet->ToSetLineWidth = -1;
3035 aChangeSet->LineWidth = 1.0;
3036 aChangeSet->ToSetTypeOfLine = -1;
3037 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
3038 aChangeSet->ToSetTypeOfMarker = -1;
3039 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
3040 aChangeSet->ToSetMarkerSize = -1;
3041 aChangeSet->MarkerSize = 1.0;
3042 aChangeSet->ToSetTransparency = -1;
3043 aChangeSet->Transparency = 0.0;
3044 aChangeSet->ToSetAlphaMode = -1;
3045 aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
3046 aChangeSet->AlphaCutoff = 0.5f;
3047 aChangeSet->ToSetColor = -1;
3048 aChangeSet->Color = DEFAULT_COLOR;
3049 aChangeSet->ToSetMaterial = -1;
3050 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
3051 aChangeSet->ToSetShowFreeBoundary = -1;
3052 aChangeSet->ToSetFreeBoundaryColor = -1;
3053 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
3054 aChangeSet->ToSetFreeBoundaryWidth = -1;
3055 aChangeSet->FreeBoundaryWidth = 1.0;
0493ffd0 3056 aChangeSet->ToEnableIsoOnTriangulation = -1;
3057 //
3058 aChangeSet->ToSetFaceBoundaryDraw = -1;
3059 aChangeSet->ToSetFaceBoundaryUpperContinuity = -1;
3060 aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN;
3061 aChangeSet->ToSetFaceBoundaryColor = -1;
3062 aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK;
3063 aChangeSet->ToSetFaceBoundaryWidth = -1;
3064 aChangeSet->FaceBoundaryWidth = 1.0f;
3065 aChangeSet->ToSetTypeOfFaceBoundaryLine = -1;
3066 aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID;
3067 //
2a332745 3068 aChangeSet->ToSetHatch = -1;
3069 aChangeSet->StdHatchStyle = -1;
3070 aChangeSet->PathToHatchPattern.Clear();
3071 aChangeSet->ToSetShadingModel = -1;
3072 aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
3073 aChangeSet->ToSetInterior = -1;
3074 aChangeSet->InteriorStyle = Aspect_IS_SOLID;
6ef0d6f1 3075 aChangeSet->ToSetDrawSilhouette = -1;
2a332745 3076 aChangeSet->ToSetDrawEdges = -1;
3077 aChangeSet->ToSetQuadEdges = -1;
3078 aChangeSet->ToSetEdgeColor = -1;
3079 aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR);
3080 aChangeSet->ToSetEdgeWidth = -1;
3081 aChangeSet->EdgeWidth = 1.0;
3082 aChangeSet->ToSetTypeOfEdge = -1;
3083 aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
3084 }
7fd59977 3085 else
ad3217cd 3086 {
3087 std::cout << "Error: wrong syntax at " << anArg << "\n";
3088 return 1;
3089 }
7fd59977 3090 }
99c56d44 3091
ad3217cd 3092 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3093 aChangesIter.More(); aChangesIter.Next())
3094 {
c1197a15 3095 if (!aChangesIter.Value().Validate())
ad3217cd 3096 {
3097 return 1;
3098 }
99c56d44 3099 }
99c56d44 3100
6262338c 3101 // special case for -defaults parameter.
3102 // all changed values will be set to DefaultDrawer.
3103 if (isDefaults)
3104 {
3105 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2a332745 3106 aChangeSet->Apply (aDrawer);
6262338c 3107 if (aChangeSet->ToSetLineWidth != 0)
3108 {
3109 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
3110 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
3111 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
3112 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
3113 }
3114 if (aChangeSet->ToSetColor != 0)
3115 {
3116 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
3117 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
3118 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
3119 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
3120 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
3121 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
3122 }
3123 if (aChangeSet->ToSetTransparency != 0)
3124 {
3125 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
3126 }
3127 if (aChangeSet->ToSetMaterial != 0)
3128 {
3129 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
3130 }
0493ffd0 3131 if (aChangeSet->ToEnableIsoOnTriangulation != 0)
5ad8c033 3132 {
3133 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
3134 }
6262338c 3135
3136 // redisplay all objects in context
3137 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3138 {
3139 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3140 if (!aPrs.IsNull())
3141 {
3142 aCtx->Redisplay (aPrs, Standard_False);
3143 }
3144 }
3145 return 0;
3146 }
3147
ad3217cd 3148 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
3149 {
25c35042 3150 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
3151 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
3152 if (aPrs.IsNull())
3153 {
3154 return 1;
3155 }
3156
6262338c 3157 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 3158 Handle(AIS_ColoredShape) aColoredPrs;
3159 Standard_Boolean toDisplay = Standard_False;
6262338c 3160 Standard_Boolean toRedisplay = Standard_False;
5bffb882 3161 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 3162 {
3163 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
3164 if (aShapePrs.IsNull())
3165 {
3166 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
3167 return 1;
3168 }
3169 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
3170 if (aColoredPrs.IsNull())
3171 {
3172 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3e05329c 3173 if (aShapePrs->HasDisplayMode())
3174 {
3175 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
3176 }
3177 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
ad3217cd 3178 aCtx->Remove (aShapePrs, Standard_False);
3179 GetMapOfAIS().UnBind2 (aName);
3180 GetMapOfAIS().Bind (aColoredPrs, aName);
3181 toDisplay = Standard_True;
3182 aShapePrs = aColoredPrs;
3183 aPrs = aColoredPrs;
3184 }
3185 }
99c56d44 3186
ad3217cd 3187 if (!aPrs.IsNull())
3188 {
3189 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
3190 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 3191 if (aChangeSet->ToSetVisibility == 1)
3192 {
3193 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
3194 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
3195 }
3196 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 3197 {
3198 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
3199 }
3200 else if (aChangeSet->ToSetMaterial == -1)
3201 {
3202 aCtx->UnsetMaterial (aPrs, Standard_False);
3203 }
3204 if (aChangeSet->ToSetColor == 1)
3205 {
3206 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
3207 }
3208 else if (aChangeSet->ToSetColor == -1)
3209 {
3210 aCtx->UnsetColor (aPrs, Standard_False);
3211 }
3212 if (aChangeSet->ToSetTransparency == 1)
3213 {
3214 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
3215 }
3216 else if (aChangeSet->ToSetTransparency == -1)
3217 {
3218 aCtx->UnsetTransparency (aPrs, Standard_False);
3219 }
3220 if (aChangeSet->ToSetLineWidth == 1)
3221 {
3222 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
3223 }
3224 else if (aChangeSet->ToSetLineWidth == -1)
3225 {
3226 aCtx->UnsetWidth (aPrs, Standard_False);
3227 }
0493ffd0 3228 else if (aChangeSet->ToEnableIsoOnTriangulation != 0)
5ad8c033 3229 {
3230 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
3231 toRedisplay = Standard_True;
3232 }
8a1170ad 3233 else if (aChangeSet->ToSetSensitivity != 0)
3234 {
3235 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3236 }
6262338c 3237 if (!aDrawer.IsNull())
3238 {
2a332745 3239 toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay;
6262338c 3240 }
99c56d44 3241
ad3217cd 3242 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
3243 {
3244 aChangeSet = &aChangesIter.ChangeValue();
3245 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
3246 aSubShapeIter.More(); aSubShapeIter.Next())
3247 {
3248 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2a332745 3249 if (!aChangeSet->IsEmpty())
3250 {
3251 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3252 aChangeSet->Apply (aCurColDrawer);
3253 }
5bffb882 3254 if (aChangeSet->ToSetVisibility == 1)
3255 {
3256 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
3257 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
3258 }
ad3217cd 3259 if (aChangeSet->ToSetColor == 1)
3260 {
3261 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
3262 }
c1197a15 3263 if (aChangeSet->ToSetTransparency == 1)
3264 {
3265 aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency);
3266 }
ad3217cd 3267 if (aChangeSet->ToSetLineWidth == 1)
3268 {
3269 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
3270 }
3271 if (aChangeSet->ToSetColor == -1
3272 || aChangeSet->ToSetLineWidth == -1)
3273 {
3274 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
3275 }
8a1170ad 3276 if (aChangeSet->ToSetSensitivity != 0)
3277 {
3278 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
3279 }
ad3217cd 3280 }
3281 }
3282 if (toDisplay)
3283 {
3284 aCtx->Display (aPrs, Standard_False);
3285 }
6262338c 3286 if (toRedisplay)
3287 {
3288 aCtx->Redisplay (aPrs, Standard_False);
3289 }
ad3217cd 3290 else if (!aColoredPrs.IsNull())
3291 {
36132a2e 3292 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 3293 }
2a332745 3294 else
3295 {
3296 aPrs->SynchronizeAspects();
3297 }
99c56d44 3298 }
ad3217cd 3299 }
99c56d44 3300 return 0;
3301}
3302
7fd59977 3303//==============================================================================
3304//function : VDonly2
3305//author : ege
3306//purpose : Display only a selected or named object
519d35d8 3307// if there is no selected or named object s, nothing is done
7fd59977 3308//==============================================================================
519d35d8 3309static int VDonly2 (Draw_Interpretor& ,
3310 Standard_Integer theArgNb,
3311 const char** theArgVec)
7fd59977 3312{
519d35d8 3313 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 3314 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 3315 if (aCtx.IsNull())
3316 {
3317 std::cerr << "Error: no active view!\n";
7fd59977 3318 return 1;
519d35d8 3319 }
7fd59977 3320
519d35d8 3321 Standard_Integer anArgIter = 1;
3322 for (; anArgIter < theArgNb; ++anArgIter)
3323 {
4e18052b 3324 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 3325 {
3326 break;
3327 }
3328 }
7fd59977 3329
519d35d8 3330 NCollection_Map<Handle(Standard_Transient)> aDispSet;
3331 if (anArgIter >= theArgNb)
3332 {
3333 // display only selected objects
c3282ec1 3334 if (aCtx->NbSelected() < 1)
519d35d8 3335 {
3336 return 0;
7fd59977 3337 }
3338
c3282ec1 3339 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 3340 {
c3282ec1 3341 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 3342 }
3343 }
3344 else
3345 {
3346 // display only specified objects
3347 for (; anArgIter < theArgNb; ++anArgIter)
3348 {
3349 TCollection_AsciiString aName = theArgVec[anArgIter];
8f521168 3350 Handle(AIS_InteractiveObject) aShape;
3351 if (GetMapOfAIS().Find2 (aName, aShape)
3352 && !aShape.IsNull())
519d35d8 3353 {
8f521168 3354 aCtx->Display (aShape, Standard_False);
3355 aDispSet.Add (aShape);
7fd59977 3356 }
3357 }
7fd59977 3358 }
519d35d8 3359
3360 // weed out other objects
3361 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
3362 {
3363 if (aDispSet.Contains (anIter.Key1()))
3364 {
3365 continue;
3366 }
3367
8f521168 3368 if (Handle(AIS_InteractiveObject) aShape = anIter.Key1())
519d35d8 3369 {
519d35d8 3370 aCtx->Erase (aShape, Standard_False);
3371 }
519d35d8 3372 }
7fd59977 3373 return 0;
3374}
3375
eef7fc64 3376//==============================================================================
3377//function : VRemove
3378//purpose : Removes selected or named objects.
3379// If there is no selected or named objects,
3380// all objects in the viewer can be removed with argument -all.
3381// If -context is in arguments, the object is not deleted from the map of
3382// objects (deleted only from the current context).
3383//==============================================================================
3384int VRemove (Draw_Interpretor& theDI,
519d35d8 3385 Standard_Integer theArgNb,
3386 const char** theArgVec)
eef7fc64 3387{
4e18052b 3388 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3389 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3390 if (aCtx.IsNull())
eef7fc64 3391 {
b6d587e3 3392 std::cerr << "Error: no active view!\n";
eef7fc64 3393 return 1;
3394 }
3395
4e18052b 3396 Standard_Boolean isContextOnly = Standard_False;
3397 Standard_Boolean toRemoveAll = Standard_False;
3398 Standard_Boolean toPrintInfo = Standard_True;
519d35d8 3399
3400 Standard_Integer anArgIter = 1;
3401 for (; anArgIter < theArgNb; ++anArgIter)
3402 {
3403 TCollection_AsciiString anArg = theArgVec[anArgIter];
3404 anArg.LowerCase();
3405 if (anArg == "-context")
3406 {
3407 isContextOnly = Standard_True;
3408 }
3409 else if (anArg == "-all")
3410 {
3411 toRemoveAll = Standard_True;
3412 }
b7cd4ba7 3413 else if (anArg == "-noinfo")
3414 {
3415 toPrintInfo = Standard_False;
3416 }
b6d587e3 3417 else if (anUpdateTool.parseRedrawMode (anArg))
3418 {
3419 continue;
3420 }
3421 else
519d35d8 3422 {
3423 break;
3424 }
3425 }
3426 if (toRemoveAll
3427 && anArgIter < theArgNb)
3428 {
b6d587e3 3429 std::cerr << "Error: wrong syntax!\n";
3430 return 1;
3431 }
3432
eef7fc64 3433 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 3434 if (toRemoveAll)
eef7fc64 3435 {
3436 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3437 anIter.More(); anIter.Next())
3438 {
3439 anIONameList.Append (anIter.Key2());
3440 }
3441 }
519d35d8 3442 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 3443 {
519d35d8 3444 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 3445 {
519d35d8 3446 TCollection_AsciiString aName = theArgVec[anArgIter];
8f521168 3447 Handle(AIS_InteractiveObject) anIO;
3448 if (!GetMapOfAIS().Find2 (aName, anIO))
eef7fc64 3449 {
8f521168 3450 theDI << aName << " was not bound to some object.\n";
eef7fc64 3451 continue;
3452 }
3453
d09dda09 3454 if (anIO->GetContext() != aCtx)
eef7fc64 3455 {
8f521168 3456 theDI << aName << " was not displayed in current context.\n";
d09dda09 3457 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 3458 continue;
3459 }
3460
d09dda09 3461 anIONameList.Append (aName);
3462 continue;
eef7fc64 3463 }
3464 }
c3282ec1 3465 else if (aCtx->NbSelected() > 0)
eef7fc64 3466 {
3467 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3468 anIter.More(); anIter.Next())
3469 {
8f521168 3470 if (!aCtx->IsSelected (anIter.Key1()))
eef7fc64 3471 {
eef7fc64 3472 continue;
3473 }
3474
d09dda09 3475 anIONameList.Append (anIter.Key2());
3476 continue;
eef7fc64 3477 }
3478 }
3479
3480 // Unbind all removed objects from the map of displayed IO.
3481 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
3482 anIter.More(); anIter.Next())
3483 {
8f521168 3484 const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value());
d09dda09 3485 aCtx->Remove (anIO, Standard_False);
3486 if (toPrintInfo)
519d35d8 3487 {
8f521168 3488 theDI << anIter.Value() << " was removed\n";
519d35d8 3489 }
519d35d8 3490 if (!isContextOnly)
3491 {
3492 GetMapOfAIS().UnBind2 (anIter.Value());
3493 }
3494 }
eef7fc64 3495 return 0;
3496}
3497
7fd59977 3498//==============================================================================
b514beda 3499//function : VErase
3500//purpose : Erase some selected or named objects
7fd59977 3501// if there is no selected or named objects, the whole viewer is erased
7fd59977 3502//==============================================================================
b514beda 3503int VErase (Draw_Interpretor& theDI,
3504 Standard_Integer theArgNb,
3505 const char** theArgVec)
7fd59977 3506{
a1954302 3507 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3508 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3509 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 3510 if (aCtx.IsNull())
b514beda 3511 {
b6d587e3 3512 std::cerr << "Error: no active view!\n";
7fd59977 3513 return 1;
b514beda 3514 }
519d35d8 3515
519d35d8 3516 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3517
3518 Standard_Integer anArgIter = 1;
a272ed94 3519 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 3520 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 3521 for (; anArgIter < theArgNb; ++anArgIter)
3522 {
b6d587e3 3523 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3524 anArgCase.LowerCase();
3525 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 3526 {
b6d587e3 3527 continue;
3528 }
a272ed94 3529 else if (anArgCase == "-view"
3530 || anArgCase == "-inview")
3531 {
3532 toEraseInView = Standard_True;
3533 }
b6d587e3 3534 else
3535 {
3536 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 3537 }
3538 }
3539
b6d587e3 3540 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 3541 {
b6d587e3 3542 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3543 return 1;
3544 }
7fd59977 3545
b6d587e3 3546 if (!aNamesOfEraseIO.IsEmpty())
3547 {
3548 // Erase named objects
3549 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 3550 {
b6d587e3 3551 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
8f521168 3552 Handle(AIS_InteractiveObject) anIO;
3553 if (!GetMapOfAIS().Find2 (aName, anIO))
b514beda 3554 {
3555 continue;
3556 }
7fd59977 3557
8f521168 3558 theDI << aName << " ";
b514beda 3559 if (!anIO.IsNull())
3560 {
a272ed94 3561 if (toEraseInView)
3562 {
3563 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3564 }
3565 else
3566 {
3567 aCtx->Erase (anIO, Standard_False);
3568 }
b514beda 3569 }
7fd59977 3570 }
7fd59977 3571 }
c3282ec1 3572 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 3573 {
b6d587e3 3574 // Erase selected objects
b514beda 3575 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3576 anIter.More(); anIter.Next())
3577 {
8f521168 3578 const Handle(AIS_InteractiveObject) anIO = anIter.Key1();
b514beda 3579 if (!anIO.IsNull()
c3282ec1 3580 && aCtx->IsSelected (anIO))
b514beda 3581 {
8f521168 3582 theDI << anIter.Key2() << " ";
a272ed94 3583 if (toEraseInView)
3584 {
3585 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3586 }
7fd59977 3587 }
3588 }
671b6fe0 3589
3590 if (!toEraseInView)
3591 {
3592 aCtx->EraseSelected (Standard_False);
3593 }
b514beda 3594 }
519d35d8 3595 else
b514beda 3596 {
b6d587e3 3597 // Erase all objects
519d35d8 3598 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3599 anIter.More(); anIter.Next())
b514beda 3600 {
8f521168 3601 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
519d35d8 3602 if (!anIO.IsNull())
3603 {
a272ed94 3604 if (toEraseInView)
3605 {
3606 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3607 }
3608 else
3609 {
3610 aCtx->Erase (anIO, Standard_False);
3611 }
519d35d8 3612 }
7fd59977 3613 }
7fd59977 3614 }
b6d587e3 3615
7fd59977 3616 return 0;
3617}
3618
7fd59977 3619//==============================================================================
3620//function : VDisplayAll
7fd59977 3621//purpose : Display all the objects of the Map
7fd59977 3622//==============================================================================
519d35d8 3623static int VDisplayAll (Draw_Interpretor& ,
3624 Standard_Integer theArgNb,
3625 const char** theArgVec)
7fd59977 3626
3627{
4e18052b 3628 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3629 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3630 if (aCtx.IsNull())
519d35d8 3631 {
b6d587e3 3632 std::cerr << "Error: no active view!\n";
519d35d8 3633 return 1;
3634 }
3635
519d35d8 3636 Standard_Integer anArgIter = 1;
3637 for (; anArgIter < theArgNb; ++anArgIter)
3638 {
b6d587e3 3639 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3640 anArgCase.LowerCase();
68dcee02 3641 if (anUpdateTool.parseRedrawMode (anArgCase))
b6d587e3 3642 {
3643 continue;
3644 }
3645 else
519d35d8 3646 {
3647 break;
7fd59977 3648 }
519d35d8 3649 }
3650 if (anArgIter < theArgNb)
3651 {
3652 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3653 return 1;
3654 }
3655
519d35d8 3656 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3657 anIter.More(); anIter.Next())
3658 {
8f521168 3659 aCtx->Erase (anIter.Key1(), Standard_False);
519d35d8 3660 }
3661
3662 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3663 anIter.More(); anIter.Next())
3664 {
8f521168 3665 aCtx->Display (anIter.Key1(), Standard_False);
7fd59977 3666 }
3667 return 0;
3668}
3669
8e5fb5ea 3670//! Auxiliary method to check if presentation exists
3671inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3672 const Handle(AIS_InteractiveObject)& theIO,
3673 const Standard_Integer theMode)
c2a388f8 3674{
8e5fb5ea 3675 if (theIO.IsNull() || theCtx.IsNull())
c2a388f8 3676 {
8e5fb5ea 3677 return -1;
c2a388f8 3678 }
3679
3680 if (theMode != -1)
3681 {
3682 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3683 {
8e5fb5ea 3684 return theMode;
c2a388f8 3685 }
3686 }
3687 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3688 {
8e5fb5ea 3689 return theIO->DisplayMode();
c2a388f8 3690 }
3691 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3692 {
8e5fb5ea 3693 return theCtx->DisplayMode();
c2a388f8 3694 }
8e5fb5ea 3695
3696 return -1;
c2a388f8 3697}
3698
3699enum ViewerTest_BndAction
3700{
3701 BndAction_Hide,
3702 BndAction_Show,
3703 BndAction_Print
3704};
3705
3706//! Auxiliary method to print bounding box of presentation
8e5fb5ea 3707inline void bndPresentation (Draw_Interpretor& theDI,
3708 const Handle(PrsMgr_PresentationManager)& theMgr,
3709 const Handle(AIS_InteractiveObject)& theObj,
3710 const Standard_Integer theDispMode,
3711 const TCollection_AsciiString& theName,
3712 const ViewerTest_BndAction theAction,
f838dac4 3713 const Handle(Prs3d_Drawer)& theStyle)
c2a388f8 3714{
3715 switch (theAction)
3716 {
3717 case BndAction_Hide:
3718 {
f838dac4 3719 theMgr->Unhighlight (theObj);
c2a388f8 3720 break;
3721 }
3722 case BndAction_Show:
3723 {
8e5fb5ea 3724 theMgr->Color (theObj, theStyle, theDispMode);
c2a388f8 3725 break;
3726 }
3727 case BndAction_Print:
3728 {
8e5fb5ea 3729 Bnd_Box aBox;
3730 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3731 {
3732 if (aPrsIter.Value().Mode() != theDispMode)
3733 continue;
3734
3735 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3736 }
ed063270 3737 gp_Pnt aMin = aBox.CornerMin();
3738 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 3739 theDI << theName << "\n"
ed063270 3740 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3741 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 3742 break;
3743 }
3744 }
3745}
3746
3747//==============================================================================
3748//function : VBounding
3749//purpose :
3750//==============================================================================
3751int VBounding (Draw_Interpretor& theDI,
3752 Standard_Integer theArgNb,
3753 const char** theArgVec)
3754{
3755 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 3756 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 3757 if (aCtx.IsNull())
3758 {
3759 std::cout << "Error: no active view!\n";
3760 return 1;
3761 }
3762
4e18052b 3763 ViewerTest_BndAction anAction = BndAction_Show;
3764 Standard_Integer aMode = -1;
c2a388f8 3765
f838dac4 3766 Handle(Prs3d_Drawer) aStyle;
8e5fb5ea 3767
c2a388f8 3768 Standard_Integer anArgIter = 1;
3769 for (; anArgIter < theArgNb; ++anArgIter)
3770 {
3771 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3772 anArg.LowerCase();
3773 if (anArg == "-print")
3774 {
3775 anAction = BndAction_Print;
3776 }
3777 else if (anArg == "-show")
3778 {
3779 anAction = BndAction_Show;
3780 }
3781 else if (anArg == "-hide")
3782 {
3783 anAction = BndAction_Hide;
3784 }
3785 else if (anArg == "-mode")
3786 {
3787 if (++anArgIter >= theArgNb)
3788 {
3789 std::cout << "Error: wrong syntax at " << anArg << "\n";
3790 return 1;
3791 }
3792 aMode = Draw::Atoi (theArgVec[anArgIter]);
3793 }
4e18052b 3794 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3795 {
3796 break;
3797 }
3798 }
3799
8e5fb5ea 3800 if (anAction == BndAction_Show)
f838dac4 3801 {
3802 aStyle = new Prs3d_Drawer();
3803 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3804 aStyle->SetColor (Quantity_NOC_GRAY99);
3805 }
8e5fb5ea 3806
3807 Standard_Integer aHighlightedMode = -1;
c2a388f8 3808 if (anArgIter < theArgNb)
3809 {
3810 // has a list of names
3811 for (; anArgIter < theArgNb; ++anArgIter)
3812 {
3813 TCollection_AsciiString aName = theArgVec[anArgIter];
8f521168 3814 Handle(AIS_InteractiveObject) anIO;
3815 if (!GetMapOfAIS().Find2 (aName, anIO))
c2a388f8 3816 {
3817 std::cout << "Error: presentation " << aName << " does not exist\n";
3818 return 1;
3819 }
3820
8e5fb5ea 3821 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3822 if (aHighlightedMode == -1)
c2a388f8 3823 {
8e5fb5ea 3824 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
c2a388f8 3825 return 1;
3826 }
8e5fb5ea 3827 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
c2a388f8 3828 }
3829 }
c3282ec1 3830 else if (aCtx->NbSelected() > 0)
c2a388f8 3831 {
3832 // remove all currently selected objects
c3282ec1 3833 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3834 {
c3282ec1 3835 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
8e5fb5ea 3836 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3837 if (aHighlightedMode != -1)
c2a388f8 3838 {
8e5fb5ea 3839 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3840 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
c2a388f8 3841 }
3842 }
3843 }
3844 else
3845 {
3846 // all objects
3847 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3848 anIter.More(); anIter.Next())
3849 {
8f521168 3850 Handle(AIS_InteractiveObject) anIO = anIter.Key1();
8e5fb5ea 3851 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3852 if (aHighlightedMode != -1)
c2a388f8 3853 {
8e5fb5ea 3854 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
c2a388f8 3855 }
3856 }
3857 }
c2a388f8 3858 return 0;
3859}
3860
d399d3c3 3861//==============================================================================
3862//function : VTexture
3863//purpose :
3864//==============================================================================
a6dee93d 3865Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7fd59977 3866{
a6dee93d 3867 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3868 if (aCtx.IsNull())
3869 {
3870 std::cout << "Error: no active view!\n";
3871 return 1;
3872 }
3873
3874 int toModulate = -1;
3875 bool toSetFilter = false;
3876 bool toSetAniso = false;
3877 bool toSetTrsfAngle = false;
3878 bool toSetTrsfTrans = false;
3879 bool toSetTrsfScale = false;
3880 Standard_ShortReal aTrsfRotAngle = 0.0f;
3881 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3882 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3883 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3884 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3885
c84c2ef7 3886 Handle(AIS_InteractiveObject) aTexturedIO;
3887 Handle(AIS_Shape) aTexturedShape;
cc8cbabe 3888 Handle(Graphic3d_TextureSet) aTextureSetOld;
3889 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
a6dee93d 3890 bool toSetGenRepeat = false;
3891 bool toSetGenScale = false;
3892 bool toSetGenOrigin = false;
3893 bool toSetImage = false;
cc8cbabe 3894 bool toComputeUV = false;
a6dee93d 3895
3896 const TCollection_AsciiString aCommandName (theArgVec[0]);
3897 bool toSetDefaults = aCommandName == "vtexdefault";
7fd59977 3898
a6dee93d 3899 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3900 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
d399d3c3 3901 {
a6dee93d 3902 const TCollection_AsciiString aName = theArgVec[anArgIter];
3903 TCollection_AsciiString aNameCase = aName;
3904 aNameCase.LowerCase();
3905 if (anUpdateTool.parseRedrawMode (aName))
7fd59977 3906 {
a6dee93d 3907 continue;
7fd59977 3908 }
a6dee93d 3909 else if (aTexturedIO.IsNull())
d399d3c3 3910 {
a6dee93d 3911 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3912 if (aMapOfIO.IsBound2 (aName))
d399d3c3 3913 {
c84c2ef7 3914 aTexturedIO = aMapOfIO.Find2 (aName);
3915 aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO);
d399d3c3 3916 }
a6dee93d 3917 if (aTexturedIO.IsNull())
d399d3c3 3918 {
a6dee93d 3919 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3920 return 1;
d399d3c3 3921 }
3922
a6dee93d 3923 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3924 {
cc8cbabe 3925 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
a6dee93d 3926 }
d399d3c3 3927 }
c84c2ef7 3928 else if (!aTexturedShape.IsNull()
3929 && (aNameCase == "-scale"
3930 || aNameCase == "-setscale"
3931 || aCommandName == "vtexscale"))
7fd59977 3932 {
a6dee93d 3933 if (aCommandName != "vtexscale")
3934 {
3935 ++anArgIter;
3936 }
3937 if (anArgIter < theArgsNb)
3938 {
3939 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3940 TCollection_AsciiString aValUCase = aValU;
3941 aValUCase.LowerCase();
3942 toSetGenScale = true;
3943 if (aValUCase == "off")
3944 {
c84c2ef7 3945 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
a6dee93d 3946 continue;
3947 }
3948 else if (anArgIter + 1 < theArgsNb)
3949 {
3950 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3951 if (aValU.IsRealValue()
3952 && aValV.IsRealValue())
3953 {
c84c2ef7 3954 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
a6dee93d 3955 ++anArgIter;
3956 continue;
3957 }
3958 }
3959 }
3960 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
31160f80 3961 return 1;
7fd59977 3962 }
c84c2ef7 3963 else if (!aTexturedShape.IsNull()
3964 && (aNameCase == "-origin"
3965 || aNameCase == "-setorigin"
3966 || aCommandName == "vtexorigin"))
d399d3c3 3967 {
a6dee93d 3968 if (aCommandName != "vtexorigin")
3969 {
3970 ++anArgIter;
3971 }
3972 if (anArgIter < theArgsNb)
3973 {
3974 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3975 TCollection_AsciiString aValUCase = aValU;
3976 aValUCase.LowerCase();
3977 toSetGenOrigin = true;
3978 if (aValUCase == "off")
3979 {
c84c2ef7 3980 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
a6dee93d 3981 continue;
3982 }
3983 else if (anArgIter + 1 < theArgsNb)
3984 {
3985 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3986 if (aValU.IsRealValue()
3987 && aValV.IsRealValue())
3988 {
c84c2ef7 3989 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
a6dee93d 3990 ++anArgIter;
3991 continue;
3992 }
3993 }
3994 }
3995 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3996 return 1;
d399d3c3 3997 }
c84c2ef7 3998 else if (!aTexturedShape.IsNull()
3999 && (aNameCase == "-repeat"
4000 || aNameCase == "-setrepeat"
4001 || aCommandName == "vtexrepeat"))
d399d3c3 4002 {
a6dee93d 4003 if (aCommandName != "vtexrepeat")
4004 {
4005 ++anArgIter;
4006 }
4007 if (anArgIter < theArgsNb)
4008 {
4009 TCollection_AsciiString aValU (theArgVec[anArgIter]);
4010 TCollection_AsciiString aValUCase = aValU;
4011 aValUCase.LowerCase();
4012 toSetGenRepeat = true;
4013 if (aValUCase == "off")
4014 {
c84c2ef7 4015 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
a6dee93d 4016 continue;
4017 }
4018 else if (anArgIter + 1 < theArgsNb)
4019 {
4020 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
4021 if (aValU.IsRealValue()
4022 && aValV.IsRealValue())
4023 {
c84c2ef7 4024 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
a6dee93d 4025 ++anArgIter;
4026 continue;
4027 }
4028 }
4029 }
4030 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
4031 return 1;
d399d3c3 4032 }
a6dee93d 4033 else if (aNameCase == "-modulate")
d399d3c3 4034 {
a6dee93d 4035 bool toModulateBool = true;
4036 if (anArgIter + 1 < theArgsNb
4037 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
4038 {
4039 ++anArgIter;
4040 }
4041 toModulate = toModulateBool ? 1 : 0;
d399d3c3 4042 }
a6dee93d 4043 else if ((aNameCase == "-setfilter"
4044 || aNameCase == "-filter")
4045 && anArgIter + 1 < theArgsNb)
d399d3c3 4046 {
a6dee93d 4047 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4048 aValue.LowerCase();
4049 ++anArgIter;
4050 toSetFilter = true;
4051 if (aValue == "nearest")
4052 {
4053 aFilter = Graphic3d_TOTF_NEAREST;
4054 }
4055 else if (aValue == "bilinear")
4056 {
4057 aFilter = Graphic3d_TOTF_BILINEAR;
4058 }
4059 else if (aValue == "trilinear")
4060 {
4061 aFilter = Graphic3d_TOTF_TRILINEAR;
4062 }
4063 else
4064 {
4065 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4066 return 1;
4067 }
d399d3c3 4068 }
a6dee93d 4069 else if ((aNameCase == "-setaniso"
4070 || aNameCase == "-setanisofilter"
4071 || aNameCase == "-aniso"
4072 || aNameCase == "-anisofilter")
4073 && anArgIter + 1 < theArgsNb)
d399d3c3 4074 {
a6dee93d 4075 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
4076 aValue.LowerCase();
4077 ++anArgIter;
4078 toSetAniso = true;
4079 if (aValue == "off")
4080 {
4081 anAnisoFilter = Graphic3d_LOTA_OFF;
4082 }
4083 else if (aValue == "fast")
4084 {
4085 anAnisoFilter = Graphic3d_LOTA_FAST;
4086 }
4087 else if (aValue == "middle")
4088 {
4089 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
4090 }
4091 else if (aValue == "quality"
4092 || aValue == "high")
4093 {
4094 anAnisoFilter = Graphic3d_LOTA_QUALITY;
4095 }
4096 else
4097 {
4098 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
4099 return 1;
4100 }
d399d3c3 4101 }
a6dee93d 4102 else if ((aNameCase == "-rotateangle"
4103 || aNameCase == "-rotangle"
4104 || aNameCase == "-rotate"
4105 || aNameCase == "-angle"
4106 || aNameCase == "-trsfangle")
4107 && anArgIter + 1 < theArgsNb)
7fd59977 4108 {
a6dee93d 4109 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4110 toSetTrsfAngle = true;
4111 ++anArgIter;
7fd59977 4112 }
a6dee93d 4113 else if ((aNameCase == "-trsftrans"
4114 || aNameCase == "-trsftranslate"
4115 || aNameCase == "-translate"
4116 || aNameCase == "-translation")
4117 && anArgIter + 2 < theArgsNb)
d399d3c3 4118 {
a6dee93d 4119 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4120 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4121 toSetTrsfTrans = true;
4122 anArgIter += 2;
d399d3c3 4123 }
a6dee93d 4124 else if ((aNameCase == "-trsfscale")
4125 && anArgIter + 2 < theArgsNb)
d399d3c3 4126 {
a6dee93d 4127 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
4128 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
4129 toSetTrsfScale = true;
4130 anArgIter += 2;
d399d3c3 4131 }
a6dee93d 4132 else if (aNameCase == "-default"
4133 || aNameCase == "-defaults")
16420da1 4134 {
a6dee93d 4135 toSetDefaults = true;
16420da1 4136 }
cc8cbabe 4137 else if (aCommandName == "vtexture"
4138 && (aTextureVecNew.IsEmpty()
4139 || aNameCase.StartsWith ("-tex")))
7fd59977 4140 {
cc8cbabe 4141 Standard_Integer aTexIndex = 0;
4142 TCollection_AsciiString aTexName = aName;
4143 if (aNameCase.StartsWith ("-tex"))
4144 {
4145 if (anArgIter + 1 >= theArgsNb
4146 || aNameCase.Length() < 5)
4147 {
4148 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4149 return 1;
4150 }
4151
4152 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
4153 if (!aTexIndexStr.IsIntegerValue())
4154 {
4155 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4156 return 1;
4157 }
4158
4159 aTexIndex = aTexIndexStr.IntegerValue();
4160 aTexName = theArgVec[anArgIter + 1];
4161 ++anArgIter;
4162 }
4163 if (aTexIndex >= Graphic3d_TextureUnit_NB
4164 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
4165 {
4166 std::cout << "Error: too many textures specified\n";
4167 return 1;
4168 }
4169
a6dee93d 4170 toSetImage = true;
cc8cbabe 4171 if (aTexName.IsIntegerValue())
d399d3c3 4172 {
cc8cbabe 4173 const Standard_Integer aValue = aTexName.IntegerValue();
a6dee93d 4174 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
4175 {
4176 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
4177 return 1;
4178 }
cc8cbabe 4179 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
d399d3c3 4180 }
cc8cbabe 4181 else if (aTexName == "?")
d399d3c3 4182 {
a6dee93d 4183 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 4184
586db386 4185 theDi << "\n Files in current directory : \n\n";
d399d3c3 4186 theDi.Eval ("glob -nocomplain *");
7fd59977 4187
d399d3c3 4188 TCollection_AsciiString aCmnd ("glob -nocomplain ");
4189 aCmnd += aTextureFolder;
4190 aCmnd += "/* ";
7fd59977 4191
a6dee93d 4192 theDi << "Files in " << aTextureFolder << " : \n\n";
d399d3c3 4193 theDi.Eval (aCmnd.ToCString());
4194 return 0;
4195 }
cc8cbabe 4196 else if (aTexName != "off")
d399d3c3 4197 {
cc8cbabe 4198 if (!OSD_File (aTexName).Exists())
a6dee93d 4199 {
cc8cbabe 4200 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
a6dee93d 4201 return 1;
4202 }
cc8cbabe 4203 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
4204 }
4205 else
4206 {
4207 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
d399d3c3 4208 }
7373e19f 4209
4210 if (aTextureVecNew.Value (aTexIndex))
4211 {
4212 aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
4213 }
cc8cbabe 4214 }
4215 else
4216 {
4217 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
4218 return 1;
4219 }
4220 }
7fd59977 4221
cc8cbabe 4222 if (toSetImage)
4223 {
4224 // check if new image set is equal to already set one
4225 Standard_Integer aNbChanged = 0;
4226 Handle(Graphic3d_TextureSet) aTextureSetNew;
4227 if (!aTextureVecNew.IsEmpty())
4228 {
4229 aNbChanged = aTextureVecNew.Size();
4230 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
4231 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
d399d3c3 4232 {
cc8cbabe 4233 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
4234 Handle(Graphic3d_TextureRoot) aTextureOld;
4235 if (!aTextureSetOld.IsNull()
4236 && aTexIter < aTextureSetOld->Size())
4237 {
4238 aTextureOld = aTextureSetOld->Value (aTexIter);
4239 }
4240
4241 if (!aTextureOld.IsNull()
4242 && !aTextureNew.IsNull())
a6dee93d 4243 {
4244 *aTextureNew->GetParams() = *aTextureOld->GetParams();
4245 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
4246 {
4247 TCollection_AsciiString aFilePathOld, aFilePathNew;
4248 aTextureOld->Path().SystemName (aFilePathOld);
4249 aTextureNew->Path().SystemName (aFilePathNew);
4250 if (aTextureNew->Name() == anOldManualTex->Name()
4251 && aFilePathOld == aFilePathNew
4252 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
4253 {
cc8cbabe 4254 --aNbChanged;
a6dee93d 4255 aTextureNew = anOldManualTex;
4256 }
4257 }
4258 }
cc8cbabe 4259 aTextureSetNew->SetValue (aTexIter, aTextureNew);
d399d3c3 4260 }
4261 }
cc8cbabe 4262 if (aNbChanged == 0
4263 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
4264 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
a6dee93d 4265 {
cc8cbabe 4266 aTextureSetNew = aTextureSetOld;
4267 }
4268
2a332745 4269 if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
4270 && aTexturedShape.IsNull())
cc8cbabe 4271 {
2a332745 4272 aTexturedIO->SetToUpdate();
a6dee93d 4273 }
cc8cbabe 4274
4275 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
4276 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
4277 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
4278 aTextureSetOld.Nullify();
a6dee93d 4279 }
7fd59977 4280
a6dee93d 4281 if (toSetDefaults)
4282 {
4283 if (toModulate != -1)
d399d3c3 4284 {
a6dee93d 4285 toModulate = 1;
7fd59977 4286 }
a6dee93d 4287 if (!toSetFilter)
4288 {
4289 toSetFilter = true;
4290 aFilter = Graphic3d_TOTF_BILINEAR;
4291 }
4292 if (!toSetAniso)
4293 {
4294 toSetAniso = true;
4295 anAnisoFilter = Graphic3d_LOTA_OFF;
4296 }
4297 if (!toSetTrsfAngle)
4298 {
4299 toSetTrsfAngle = true;
4300 aTrsfRotAngle = 0.0f;
4301 }
4302 if (!toSetTrsfTrans)
4303 {
4304 toSetTrsfTrans = true;
4305 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
4306 }
4307 if (!toSetTrsfScale)
4308 {
4309 toSetTrsfScale = true;
4310 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
4311 }
4312 }
7fd59977 4313
a6dee93d 4314 if (aCommandName == "vtexture"
4315 && theArgsNb == 2)
4316 {
cc8cbabe 4317 if (!aTextureSetOld.IsNull())
7fd59977 4318 {
cc8cbabe 4319 //toComputeUV = true; // we can keep UV vertex attributes
a6dee93d 4320 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
cc8cbabe 4321 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
4322 aTextureSetOld.Nullify();
7fd59977 4323 }
d399d3c3 4324 }
4325
a6dee93d 4326 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
4327 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
d399d3c3 4328 {
a6dee93d 4329 if (toModulate != -1)
4330 {
4331 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
4332 }
4333 if (toSetTrsfAngle)
4334 {
4335 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
4336 }
4337 if (toSetTrsfTrans)
4338 {
4339 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
4340 }
4341 if (toSetTrsfScale)
4342 {
4343 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
4344 }
4345 if (toSetFilter)
4346 {
4347 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
4348 }
4349 if (toSetAniso)
4350 {
4351 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
4352 }
d399d3c3 4353 }
a6dee93d 4354
4355 // set default values if requested
4356 if (!toSetGenRepeat
4357 && (aCommandName == "vtexrepeat"
4358 || toSetDefaults))
4359 {
c84c2ef7 4360 if (!aTexturedShape.IsNull())
4361 {
4362 aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
4363 }
a6dee93d 4364 toSetGenRepeat = true;
4365 }
4366 if (!toSetGenOrigin
4367 && (aCommandName == "vtexorigin"
4368 || toSetDefaults))
4369 {
c84c2ef7 4370 if (!aTexturedShape.IsNull())
4371 {
4372 aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
4373 }
a6dee93d 4374 toSetGenOrigin = true;
4375 }
4376 if (!toSetGenScale
4377 && (aCommandName == "vtexscale"
4378 || toSetDefaults))
d399d3c3 4379 {
c84c2ef7 4380 if (!aTexturedShape.IsNull())
4381 {
4382 aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
4383 }
a6dee93d 4384 toSetGenScale = true;
d399d3c3 4385 }
4386
cc8cbabe 4387 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
a6dee93d 4388 {
c84c2ef7 4389 if (!aTexturedShape.IsNull())
a6dee93d 4390 {
c84c2ef7 4391 aTexturedShape->SetToUpdate (AIS_Shaded);
4392 if (toSetImage)
a6dee93d 4393 {
c84c2ef7 4394 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
4395 || aCtx->DisplayMode() != AIS_Shaded)
4396 {
4397 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
4398 }
a6dee93d 4399 }
4400 }
4401 }
4402 aCtx->Display (aTexturedIO, false);
4403 aTexturedIO->SynchronizeAspects();
31160f80 4404 return 0;
7fd59977 4405}
4406
af65fb19 4407//! Auxiliary method to parse transformation persistence flags
4408inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
778cd667 4409 Graphic3d_TransModeFlags& theFlags)
af65fb19 4410{
778cd667 4411 if (theFlagString == "zoom")
af65fb19 4412 {
778cd667 4413 theFlags = Graphic3d_TMF_ZoomPers;
af65fb19 4414 }
4415 else if (theFlagString == "rotate")
4416 {
778cd667 4417 theFlags = Graphic3d_TMF_RotatePers;
af65fb19 4418 }
778cd667 4419 else if (theFlagString == "zoomrotate")
af65fb19 4420 {
778cd667 4421 theFlags = Graphic3d_TMF_ZoomRotatePers;
af65fb19 4422 }
778cd667 4423 else if (theFlagString == "trihedron"
4424 || theFlagString == "triedron")
af65fb19 4425 {
778cd667 4426 theFlags = Graphic3d_TMF_TriedronPers;
af65fb19 4427 }
4428 else if (theFlagString == "none")
4429 {
4430 theFlags = Graphic3d_TMF_None;
4431 }
4432 else
4433 {
4434 return Standard_False;
4435 }
4436
4437 return Standard_True;
4438}
4439
778cd667 4440//! Auxiliary method to parse transformation persistence flags
4441inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
4442 Aspect_TypeOfTriedronPosition& theCorner)
4443{
4444 TCollection_AsciiString aString (theString);
4445 aString.LowerCase();
4446 if (aString == "center")
4447 {
4448 theCorner = Aspect_TOTP_CENTER;
4449 }
4450 else if (aString == "top"
4451 || aString == "upper")
4452 {
4453 theCorner = Aspect_TOTP_TOP;
4454 }
4455 else if (aString == "bottom"
4456 || aString == "lower")
4457 {
4458 theCorner = Aspect_TOTP_BOTTOM;
4459 }
4460 else if (aString == "left")
4461 {
4462 theCorner = Aspect_TOTP_LEFT;
4463 }
4464 else if (aString == "right")
4465 {
4466 theCorner = Aspect_TOTP_RIGHT;
4467 }
4468 else if (aString == "topleft"
4469 || aString == "leftupper"
4470 || aString == "upperleft")
4471 {
4472 theCorner = Aspect_TOTP_LEFT_UPPER;
4473 }
4474 else if (aString == "bottomleft"
4475 || aString == "leftlower"
4476 || aString == "lowerleft")
4477 {
4478 theCorner = Aspect_TOTP_LEFT_LOWER;
4479 }
4480 else if (aString == "topright"
4481 || aString == "rightupper"
4482 || aString == "upperright")
4483 {
4484 theCorner = Aspect_TOTP_RIGHT_UPPER;
4485 }
4486 else if (aString == "bottomright"
4487 || aString == "lowerright"
4488 || aString == "rightlower")
4489 {
4490 theCorner = Aspect_TOTP_RIGHT_LOWER;
4491 }
4492 else
4493 {
4494 return Standard_False;
4495 }
4496
4497 return Standard_True;
4498}
4499
7fd59977 4500//==============================================================================
4501//function : VDisplay2
4502//author : ege
4503//purpose : Display an object from its name
7fd59977 4504//==============================================================================
519d35d8 4505static int VDisplay2 (Draw_Interpretor& theDI,
4506 Standard_Integer theArgNb,
4507 const char** theArgVec)
7fd59977 4508{
519d35d8 4509 if (theArgNb < 2)
4510 {
b6d587e3 4511 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 4512 return 1;
4513 }
b6d587e3 4514
4515 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4516 if (aCtx.IsNull())
519d35d8 4517 {
7fd59977 4518 ViewerTest::ViewerInit();
4e18052b 4519 aCtx = ViewerTest::GetAISContext();
7fd59977 4520 }
4521
b6d587e3 4522 // Parse input arguments
4e18052b 4523 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 4524 Standard_Integer isMutable = -1;
4525 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
a1954302 4526 Standard_Boolean toReDisplay = Standard_False;
af65fb19 4527 Standard_Integer isSelectable = -1;
4528 Standard_Integer anObjDispMode = -2;
4529 Standard_Integer anObjHighMode = -2;
4530 Standard_Boolean toSetTrsfPers = Standard_False;
778cd667 4531 Handle(Graphic3d_TransformPers) aTrsfPers;
b6d587e3 4532 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 4533 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 4534 Standard_Integer toDisplayInView = Standard_False;
519d35d8 4535 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4536 {
b7cd4ba7 4537 const TCollection_AsciiString aName = theArgVec[anArgIter];
4538 TCollection_AsciiString aNameCase = aName;
4539 aNameCase.LowerCase();
4e18052b 4540 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 4541 {
4542 continue;
4543 }
b7cd4ba7 4544 else if (aNameCase == "-mutable")
4545 {
4546 isMutable = 1;
b7cd4ba7 4547 }
a1954302 4548 else if (aNameCase == "-neutral")
4549 {
4550 aDispStatus = AIS_DS_Displayed;
4551 }
4552 else if (aNameCase == "-immediate"
4553 || aNameCase == "-top")
4554 {
4555 aZLayer = Graphic3d_ZLayerId_Top;
4556 }
4557 else if (aNameCase == "-topmost")
4558 {
4559 aZLayer = Graphic3d_ZLayerId_Topmost;
4560 }
4561 else if (aNameCase == "-osd"
af65fb19 4562 || aNameCase == "-toposd"
4563 || aNameCase == "-overlay")
a1954302 4564 {
4565 aZLayer = Graphic3d_ZLayerId_TopOSD;
4566 }
af65fb19 4567 else if (aNameCase == "-botosd"
4568 || aNameCase == "-underlay")
4569 {
4570 aZLayer = Graphic3d_ZLayerId_BotOSD;
4571 }
4572 else if (aNameCase == "-select"
4573 || aNameCase == "-selectable")
4574 {
4575 isSelectable = 1;
4576 }
4577 else if (aNameCase == "-noselect"
4578 || aNameCase == "-noselection")
4579 {
4580 isSelectable = 0;
4581 }
4582 else if (aNameCase == "-dispmode"
4583 || aNameCase == "-displaymode")
4584 {
4585 if (++anArgIter >= theArgNb)
4586 {
4587 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4588 return 1;
4589 }
4590
4591 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4592 }
4593 else if (aNameCase == "-highmode"
4594 || aNameCase == "-highlightmode")
4595 {
4596 if (++anArgIter >= theArgNb)
4597 {
4598 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4599 return 1;
4600 }
4601
4602 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4603 }
4604 else if (aNameCase == "-3d")
4605 {
4606 toSetTrsfPers = Standard_True;
778cd667 4607 aTrsfPers.Nullify();
af65fb19 4608 }
778cd667 4609 else if (aNameCase == "-2d"
4610 || aNameCase == "-trihedron"
4611 || aNameCase == "-triedron")
af65fb19 4612 {
4613 toSetTrsfPers = Standard_True;
778cd667 4614 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4615
4616 if (anArgIter + 1 < theArgNb)
4617 {
4618 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4619 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4620 {
4621 ++anArgIter;
4622 aTrsfPers->SetCorner2d (aCorner);
4623
4624 if (anArgIter + 2 < theArgNb)
4625 {
4626 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4627 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4628 if (anX.IsIntegerValue()
4629 && anY.IsIntegerValue())
4630 {
4631 anArgIter += 2;
4632 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4633 }
4634 }
4635 }
4636 }
af65fb19 4637 }
af65fb19 4638 else if (aNameCase == "-trsfpers"
4639 || aNameCase == "-pers")
4640 {
778cd667 4641 if (++anArgIter >= theArgNb
4642 || !aTrsfPers.IsNull())
af65fb19 4643 {
4644 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4645 return 1;
4646 }
4647
4648 toSetTrsfPers = Standard_True;
778cd667 4649 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
af65fb19 4650 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4651 aPersFlags.LowerCase();
778cd667 4652 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
af65fb19 4653 {
778cd667 4654 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4655 return 1;
4656 }
af65fb19 4657
778cd667 4658 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4659 {
4660 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4661 }
4662 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4663 {
4664 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
af65fb19 4665 }
4666 }
4667 else if (aNameCase == "-trsfperspos"
4668 || aNameCase == "-perspos")
4669 {
778cd667 4670 if (anArgIter + 2 >= theArgNb
4671 || aTrsfPers.IsNull())
af65fb19 4672 {
4673 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4674 return 1;
4675 }
4676
4677 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4678 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4679 TCollection_AsciiString aZ = "0";
778cd667 4680 if (!aX.IsRealValue()
4681 || !aY.IsRealValue())
af65fb19 4682 {
4683 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4684 return 1;
4685 }
4686 if (anArgIter + 1 < theArgNb)
4687 {
4688 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
778cd667 4689 if (aTemp.IsRealValue())
af65fb19 4690 {
4691 aZ = aTemp;
4692 ++anArgIter;
4693 }
4694 }
778cd667 4695
4696 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4697 if (aTrsfPers->IsZoomOrRotate())
4698 {
4699 aTrsfPers->SetAnchorPoint (aPnt);
4700 }
4701 else if (aTrsfPers->IsTrihedronOr2d())
4702 {
4703 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4704 }
af65fb19 4705 }
55c8f0f7
BB
4706 else if (aNameCase == "-layer"
4707 || aNameCase == "-zlayer")
a1954302 4708 {
55c8f0f7
BB
4709 ++anArgIter;
4710 if (anArgIter >= theArgNb
4711 || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
4712 || aZLayer == Graphic3d_ZLayerId_UNKNOWN)
a1954302 4713 {
4714 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4715 return 1;
4716 }
a1954302 4717 }
a272ed94 4718 else if (aNameCase == "-view"
4719 || aNameCase == "-inview")
4720 {
4721 toDisplayInView = Standard_True;
4722 }
a1954302 4723 else if (aNameCase == "-redisplay")
4724 {
4725 toReDisplay = Standard_True;
4726 }
6194ee76 4727 else if (aNameCase == "-erased"
4728 || aNameCase == "-load")
4729 {
4730 aDispStatus = AIS_DS_Erased;
4731 }
b6d587e3 4732 else
4733 {
4734 aNamesOfDisplayIO.Append (aName);
4735 }
4736 }
4737
4738 if (aNamesOfDisplayIO.IsEmpty())
4739 {
4740 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4741 return 1;
4742 }
4743
b6d587e3 4744 // Display interactive objects
4745 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4746 {
1c8fc6be 4747 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter);
8f521168 4748 Handle(AIS_InteractiveObject) aShape;
4749 if (!GetMapOfAIS().Find2 (aName, aShape))
519d35d8 4750 {
4751 // create the AIS_Shape from a name
1c8fc6be 4752 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
4753 if (!aDrawShape.IsNull())
519d35d8 4754 {
1c8fc6be 4755 aShape = new AIS_Shape (aDrawShape);
b7cd4ba7 4756 if (isMutable != -1)
4757 {
4758 aShape->SetMutable (isMutable == 1);
4759 }
a1954302 4760 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4761 {
4762 aShape->SetZLayer (aZLayer);
4763 }
af65fb19 4764 if (toSetTrsfPers)
4765 {
778cd667 4766 aCtx->SetTransformPersistence (aShape, aTrsfPers);
af65fb19 4767 }
4768 if (anObjDispMode != -2)
4769 {
4770 aShape->SetDisplayMode (anObjDispMode);
4771 }
4772 if (anObjHighMode != -2)
4773 {
4774 aShape->SetHilightMode (anObjHighMode);
4775 }
a1954302 4776
68dcee02 4777 GetMapOfAIS().Bind (aShape, aName);
a1954302 4778 Standard_Integer aDispMode = aShape->HasDisplayMode()
4779 ? aShape->DisplayMode()
4780 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4781 ? aCtx->DisplayMode()
4782 : 0);
af65fb19 4783 Standard_Integer aSelMode = -1;
825aa485 4784 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
af65fb19 4785 {
c3282ec1 4786 aSelMode = aShape->GlobalSelectionMode();
af65fb19 4787 }
a1954302 4788
68dcee02 4789 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
a272ed94 4790 if (toDisplayInView)
4791 {
6a24c6de 4792 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
a272ed94 4793 {
6a24c6de 4794 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
a272ed94 4795 }
4796 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4797 }
519d35d8 4798 }
af65fb19 4799 else
4800 {
4801 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4802 }
519d35d8 4803 continue;
4804 }
7fd59977 4805
d09dda09 4806 if (isMutable != -1)
519d35d8 4807 {
d09dda09 4808 aShape->SetMutable (isMutable == 1);
4809 }
4810 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4811 {
4812 aShape->SetZLayer (aZLayer);
4813 }
4814 if (toSetTrsfPers)
4815 {
778cd667 4816 aCtx->SetTransformPersistence (aShape, aTrsfPers);
d09dda09 4817 }
4818 if (anObjDispMode != -2)
4819 {
4820 aShape->SetDisplayMode (anObjDispMode);
4821 }
4822 if (anObjHighMode != -2)
4823 {
4824 aShape->SetHilightMode (anObjHighMode);
4825 }
4826 Standard_Integer aDispMode = aShape->HasDisplayMode()
4827 ? aShape->DisplayMode()
4828 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4829 ? aCtx->DisplayMode()
4830 : 0);
4831 Standard_Integer aSelMode = -1;
825aa485 4832 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
d09dda09 4833 {
c3282ec1 4834 aSelMode = aShape->GlobalSelectionMode();
d09dda09 4835 }
4836
4837 if (aShape->Type() == AIS_KOI_Datum)
4838 {
4839 aCtx->Display (aShape, Standard_False);
4840 }
4841 else
4842 {
1c8fc6be 4843 theDI << "Display " << aName << "\n";
d09dda09 4844
4845 // update the Shape in the AIS_Shape
1c8fc6be 4846 TopoDS_Shape aNewShape = DBRep::GetExisting (aName);
d09dda09 4847 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4848 if (!aShapePrs.IsNull())
af65fb19 4849 {
d09dda09 4850 if (!aShapePrs->Shape().IsEqual (aNewShape))
4851 {
4852 toReDisplay = Standard_True;
4853 }
4854 aShapePrs->Set (aNewShape);
af65fb19 4855 }
d09dda09 4856 if (toReDisplay)
af65fb19 4857 {
d09dda09 4858 aCtx->Redisplay (aShape, Standard_False);
af65fb19 4859 }
b7cd4ba7 4860
d09dda09 4861 if (aSelMode == -1)
519d35d8 4862 {
0577ae8c 4863 aCtx->Erase (aShape, Standard_False);
519d35d8 4864 }
68dcee02 4865 aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus);
d09dda09 4866 if (toDisplayInView)
519d35d8 4867 {
d09dda09 4868 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
7fd59977 4869 }
4870 }
7fd59977 4871 }
b6d587e3 4872
7fd59977 4873 return 0;
4874}
4875
bc001a40 4876//=======================================================================
4877//function : VNbDisplayed
4878//purpose : Returns number of displayed objects
4879//=======================================================================
4880static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4881 Standard_Integer theArgsNb,
4882 const char** theArgVec)
4883{
4884 if(theArgsNb != 1)
4885 {
4886 theDi << "Usage : " << theArgVec[0] << "\n";
4887 return 1;
4888 }
4889
4890 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4891 if (aContextAIS.IsNull())
4892 {
4893 std::cout << theArgVec[0] << "AIS context is not available.\n";
4894 return 1;
4895 }
4896
4897 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4898 if(aContext.IsNull())
4899 {
4900 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4901 return 1;
4902 }
4903
4904 AIS_ListOfInteractive aListOfIO;
68dcee02 4905 aContextAIS->DisplayedObjects (aListOfIO);
bc001a40 4906
4907 theDi << aListOfIO.Extent() << "\n";
4908 return 0;
4909}
4910
f3889691 4911//===============================================================================================
4912//function : VUpdate
4913//purpose :
4914//===============================================================================================
4915static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4916{
4917 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4918 if (aContextAIS.IsNull())
4919 {
4920 std::cout << theArgVec[0] << "AIS context is not available.\n";
4921 return 1;
4922 }
4923
4924 if (theArgsNb < 2)
4925 {
4926 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4927 return 1;
4928 }
4929
f3889691 4930 AIS_ListOfInteractive aListOfIO;
f3889691 4931 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4932 {
4933 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4934
4935 Handle(AIS_InteractiveObject) anAISObj;
8f521168 4936 GetMapOfAIS().Find2 (aName, anAISObj);
f3889691 4937 if (anAISObj.IsNull())
4938 {
4939 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4940 return 1;
4941 }
4942
4943 aListOfIO.Append (anAISObj);
4944 }
4945
4946 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4947 for (; anIOIt.More(); anIOIt.Next())
4948 {
4949 aContextAIS->Update (anIOIt.Value(), Standard_False);
4950 }
4951
4952 aContextAIS->UpdateCurrentViewer();
4953
4954 return 0;
4955}
4956
7fd59977 4957//==============================================================================
4958//function : VShading
4959//purpose : Sharpen or roughten the quality of the shading
4960//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4961//==============================================================================
5cbef0fe
S
4962static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4963{
7fd59977 4964 Standard_Real myDevCoef;
4965 Handle(AIS_InteractiveObject) TheAisIO;
4966
4967 // Verifications
5cbef0fe 4968 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
7fd59977 4969 if (argc < 3) {
4970 myDevCoef = 0.0008;
4971 } else {
91322f44 4972 myDevCoef =Draw::Atof(argv[2]);
7fd59977 4973 }
4974
7fd59977 4975 TCollection_AsciiString name=argv[1];
8f521168 4976 GetMapOfAIS().Find2(name, TheAisIO);
7fd59977 4977 if (TheAisIO.IsNull())
1c8fc6be 4978 {
4979 TopoDS_Shape aDrawShape = DBRep::GetExisting (name);
4980 if (!aDrawShape.IsNull())
4981 {
4982 TheAisIO = new AIS_Shape (aDrawShape);
4983 }
4984 }
7fd59977 4985
5cbef0fe 4986 if (HaveToSet)
7fd59977 4987 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 4988 else
7fd59977 4989 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4990
0577ae8c 4991 TheAISContext()->Redisplay (TheAisIO, Standard_True);
7fd59977 4992 return 0;
4993}
7fd59977 4994
cb78155f 4995//! Auxiliary method to print Interactive Object information
4996static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
8f521168 4997 const Handle(AIS_InteractiveObject)& theObj,
cb78155f 4998 Draw_Interpretor& theDI)
4999{
8f521168 5000 if (theObj.IsNull())
cb78155f 5001 {
8f521168 5002 theDI << "NULL presentation\n";
cb78155f 5003 return;
5004 }
7fd59977 5005
8f521168 5006 theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ")
5007 << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ")
5008 << (theDetected.Contains (theObj) ? " Detected" : " ")
cb78155f 5009 << " Type: ";
8f521168 5010 if (theObj->Type() == AIS_KOI_Datum)
cb78155f 5011 {
5012 // AIS_Datum
8f521168 5013 if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
5014 else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; }
5015 else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; }
5016 else if (theObj->Signature() == 5) { theDI << " AIS_Line"; }
5017 else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; }
5018 else if (theObj->Signature() == 1) { theDI << " AIS_Point"; }
5019 else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 5020 }
5021 // AIS_Shape
8f521168 5022 else if (theObj->Type() == AIS_KOI_Shape
5023 && theObj->Signature() == 0)
cb78155f 5024 {
5025 theDI << " AIS_Shape";
7fd59977 5026 }
8f521168 5027 else if (theObj->Type() == AIS_KOI_Relation)
cb78155f 5028 {
5029 // AIS_Dimention and AIS_Relation
8f521168 5030 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
cb78155f 5031 switch (aRelation->KindOfDimension())
5032 {
5033 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
5034 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
5035 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
5036 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
5037 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
5038 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
5039 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
5040 default: theDI << " UNKNOWN dimension"; break;
5041 }
5042 }
5043 else
5044 {
5045 theDI << " UserPrs";
5046 }
8f521168 5047 theDI << " (" << theObj->DynamicType()->Name() << ")";
7fd59977 5048}
5049
cb78155f 5050//! Print information about locally selected sub-shapes
23963a92 5051template <typename T>
5052static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
cb78155f 5053{
a9dde4a3 5054 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
cb78155f 5055 TCollection_AsciiString aPrevName;
23963a92 5056 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
cb78155f 5057 {
23963a92 5058 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
5059 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
5060 if (aShapeIO.IsNull() || anOwner.IsNull())
5061 continue;
5062 if (isGlobalCtx)
5063 {
5064 if (anOwner == aShapeIO->GlobalSelOwner())
5065 continue;
5066 }
5067 const TopoDS_Shape aSubShape = theContext->SelectedShape();
cb78155f 5068 if (aSubShape.IsNull()
5069 || aShapeIO.IsNull()
5070 || !GetMapOfAIS().IsBound1 (aShapeIO))
5071 {
5072 continue;
5073 }
5074
5075 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
5076 TopTools_MapOfShape aFilter;
5077 Standard_Integer aNumber = 0;
5078 const TopoDS_Shape aShape = aShapeIO->Shape();
5079 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
5080 anIter.More(); anIter.Next())
5081 {
5082 if (!aFilter.Add (anIter.Current()))
5083 {
5084 continue; // filter duplicates
5085 }
5086
5087 ++aNumber;
5088 if (!anIter.Current().IsSame (aSubShape))
5089 {
5090 continue;
5091 }
5092
5093 Standard_CString aShapeName = NULL;
5094 switch (aSubShape.ShapeType())
5095 {
5096 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
5097 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
5098 case TopAbs_SOLID: aShapeName = " Solid"; break;
5099 case TopAbs_SHELL: aShapeName = " Shell"; break;
5100 case TopAbs_FACE: aShapeName = " Face"; break;
5101 case TopAbs_WIRE: aShapeName = " Wire"; break;
5102 case TopAbs_EDGE: aShapeName = " Edge"; break;
5103 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
5104 default:
5105 case TopAbs_SHAPE: aShapeName = " Shape"; break;
5106 }
5107
5108 if (aParentName != aPrevName)
5109 {
5110 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
5111 aPrevName = aParentName;
5112 }
5113 theDI << " " << aShapeName << " #" << aNumber << "\n";
5114 break;
5115 }
5116 }
5117}
7fd59977 5118
5119//==============================================================================
5120//function : VState
5121//purpose :
7fd59977 5122//==============================================================================
cb78155f 5123static Standard_Integer VState (Draw_Interpretor& theDI,
5124 Standard_Integer theArgNb,
5125 Standard_CString* theArgVec)
7fd59977 5126{
cb78155f 5127 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
5128 if (aCtx.IsNull())
5129 {
5130 std::cerr << "Error: No opened viewer!\n";
5131 return 1;
7fd59977 5132 }
cb78155f 5133
51023771 5134 Standard_Boolean toPrintEntities = Standard_False;
5135 Standard_Boolean toCheckSelected = Standard_False;
5136
5137 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
5138 {
5139 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
5140 anOption.LowerCase();
5141 if (anOption == "-detectedentities"
5142 || anOption == "-entities")
5143 {
5144 toPrintEntities = Standard_True;
5145 }
5146 else if (anOption == "-hasselected")
5147 {
5148 toCheckSelected = Standard_True;
5149 }
5150 }
5151
5152 if (toCheckSelected)
5153 {
5154 aCtx->InitSelected();
5155 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
5156 theDI << "Check if context has selected shape: " << hasSelected << "\n";
5157
5158 return 0;
5159 }
5160
5161 if (toPrintEntities)
8e7c8ccf 5162 {
5163 theDI << "Detected entities:\n";
68dcee02 5164 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector();
5165
7479f643 5166 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
aa75c0cf 5167 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
8e7c8ccf 5168 {
aa75c0cf 5169 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
5170 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
8e7c8ccf 5171 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
5172 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
8e7c8ccf 5173 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
5174 aName.LeftJustify (20, ' ');
5175 char anInfoStr[512];
f751596e 5176 Sprintf (anInfoStr,
949c9b7f 5177 " Depth: %g Distance: %g Point: %g %g %g",
aa75c0cf 5178 aPickData.Depth,
5179 aPickData.MinDist,
5180 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
8e7c8ccf 5181 theDI << " " << aName
5182 << anInfoStr
5183 << " (" << anEntity->DynamicType()->Name() << ")"
5184 << "\n";
5185
5186 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5187 if (!aBRepOwner.IsNull())
5188 {
5189 theDI << " Detected Shape: "
5190 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
5191 << "\n";
5192 }
5193
5194 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
5195 if (!aWire.IsNull())
5196 {
5197 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
5198 theDI << " Detected Child: "
5199 << aSen->DynamicType()->Name()
5200 << "\n";
5201 }
8b9a309b 5202
5203 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
5204 if (!aPrimArr.IsNull())
5205 {
5206 theDI << " Detected Element: "
5207 << aPrimArr->LastDetectedElement()
5208 << "\n";
5209 }
8e7c8ccf 5210 }
5211 return 0;
5212 }
5213
cb78155f 5214 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
5215 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5216 {
68dcee02 5217 aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable()));
cb78155f 5218 }
5219
5220 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
5221 if (theArgNb >= 2
5222 && !toShowAll)
5223 {
5224 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 5225 {
cb78155f 5226 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
8f521168 5227 Handle(AIS_InteractiveObject) anObj;
5228 if (!GetMapOfAIS().Find2 (anObjName, anObj))
cb78155f 5229 {
5230 theDI << anObjName << " doesn't exist!\n";
5231 continue;
7fd59977 5232 }
5233
cb78155f 5234 TCollection_AsciiString aName = anObjName;
5235 aName.LeftJustify (20, ' ');
5236 theDI << " " << aName << " ";
8f521168 5237 objInfo (aDetected, anObj, theDI);
cb78155f 5238 theDI << "\n";
7fd59977 5239 }
cb78155f 5240 return 0;
7fd59977 5241 }
cb78155f 5242
68dcee02 5243 if (aCtx->NbSelected() > 0 && !toShowAll)
cb78155f 5244 {
23963a92 5245 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
c3282ec1 5246 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
cb78155f 5247 {
23963a92 5248 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5249 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5250 // handle whole object selection
5251 if (anOwner == anObj->GlobalSelOwner())
5252 {
5253 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
5254 aName.LeftJustify (20, ' ');
5255 theDI << aName << " ";
5256 objInfo (aDetected, anObj, theDI);
5257 theDI << "\n";
5258 }
7fd59977 5259 }
23963a92 5260
5261 // process selected sub-shapes
5262 printLocalSelectionInfo (aCtx, theDI);
5263
cb78155f 5264 return 0;
7fd59977 5265 }
5266
cb78155f 5267 theDI << "Neutral-point state:\n";
5268 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5269 anObjIter.More(); anObjIter.Next())
5270 {
8f521168 5271 if (anObjIter.Key1().IsNull())
cb78155f 5272 {
5273 continue;
5274 }
5275
5276 TCollection_AsciiString aName = anObjIter.Key2();
5277 aName.LeftJustify (20, ' ');
5278 theDI << " " << aName << " ";
8f521168 5279 objInfo (aDetected, anObjIter.Key1(), theDI);
cb78155f 5280 theDI << "\n";
5281 }
23963a92 5282 printLocalSelectionInfo (aCtx, theDI);
7fd59977 5283 return 0;
5284}
5285
7fd59977 5286//=======================================================================
5287//function : PickShape
5288//purpose : First Activate the rightmode + Put Filters to be able to
5289// pick objets that are of type <TheType>...
5290//=======================================================================
5291
8c088c52 5292TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
5293 const Standard_Integer theMaxPick)
7fd59977 5294{
8c088c52 5295 Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
5296 PickShapes (theShapeType, aResArray, theMaxPick);
5297 return aResArray->First();
7fd59977 5298}
5299
7fd59977 5300//=======================================================================
5301//function : PickShapes
5302//purpose :
5303//=======================================================================
8c088c52 5304Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
5305 Handle(TopTools_HArray1OfShape)& theResArray,
5306 const Standard_Integer theMaxPick)
7fd59977 5307{
8c088c52 5308 const Standard_Integer aNbToReach = theResArray->Length();
5309 if (aNbToReach > 1)
5310 {
5311 std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5312 }
7fd59977 5313
5314 // step 1: prepare the data
8c088c52 5315 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5316 aCtx->RemoveFilters();
5317 AIS_ListOfInteractive aDispObjects;
5318 aCtx->DisplayedObjects (aDispObjects);
5319 if (theShapeType == TopAbs_SHAPE)
5320 {
5321 aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
7fd59977 5322 }
8c088c52 5323 else
5324 {
5325 aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
5326 }
5327
5328 const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
5329 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5330 {
5331 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5332 {
5333 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5334 }
7fd59977 5335 }
5336
5337 // step 2 : wait for the selection...
8c088c52 5338 Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
7fd59977 5339 Standard_Integer argccc = 5;
8c088c52 5340 const char *bufff[] = { "A", "B", "C", "D", "E" };
5341 const char **argvvv = (const char** )bufff;
5342 for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
5343 {
5344 while (ViewerMainLoop (argccc, argvvv)) {}
5345 Standard_Integer aNbStored = aCtx->NbSelected();
5346 if (aNbStored != aNbPickGood)
5347 {
5348 aNbPickGood = aNbStored;
5349 }
7fd59977 5350 else
8c088c52 5351 {
5352 ++aNbPickFail;
5353 }
5354 std::cout << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail << "\n";
7fd59977 5355 }
5356
5357 // step3 get result.
8c088c52 5358 if (aNbPickFail >= aNbToReach)
5359 {
76363522 5360 return Standard_False;
8c088c52 5361 }
7fd59977 5362
8c088c52 5363 Standard_Integer anIndex = theResArray->Lower();
5364 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
5365 {
5366 if (aCtx->HasSelectedShape())
5367 {
5368 theResArray->SetValue (anIndex, aCtx->SelectedShape());
5369 }
5370 else
5371 {
5372 Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
5373 theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
7fd59977 5374 }
5375 }
5376
8c088c52 5377 aCtx->RemoveFilters();
5378 if (theShapeType != TopAbs_SHAPE)
5379 {
5380 for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
5381 {
5382 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
5383 {
5384 aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
5385 }
5386 }
5387 }
7fd59977 5388 return Standard_True;
5389}
5390
7fd59977 5391//=======================================================================
5392//function : VPickShape
5393//purpose :
5394//=======================================================================
5395static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5396{
8c088c52 5397 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
5398 if (argc != 1)
5399 {
5400 TCollection_AsciiString aShapeArg (argv[1]);
5401 aShapeArg.LowerCase();
5402 aShapeType = TopAbs_COMPOUND;
5403 if (aShapeArg == "v"
5404 || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
5405 else if (aShapeArg == "e"
5406 || aShapeArg == "edge") aShapeType = TopAbs_EDGE;
5407 else if (aShapeArg == "w"
5408 || aShapeArg == "wire") aShapeType = TopAbs_WIRE;
5409 else if (aShapeArg == "f"
5410 || aShapeArg == "face") aShapeType = TopAbs_FACE;
5411 else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE;
5412 else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL;
5413 else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID;
5414 else
5415 {
5416 std::cout << "Syntax error at '" << argv[1] << "'\n";
5417 return 1;
5418 }
7fd59977 5419 }
5420
8c088c52 5421 static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
5422 static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
7fd59977 5423
8c088c52 5424 const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
5425 if (aNbToPick == 1)
5426 {
5427 TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
5428 if (aPickedShape.IsNull())
5429 {
7fd59977 5430 return 1;
7fd59977 5431 }
7fd59977 5432
8c088c52 5433 TCollection_AsciiString aName;
5434 if (argc > 2)
5435 {
5436 aName = argv[2];
5437 }
5438 else
5439 {
5440 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5441 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
7fd59977 5442 }
7fd59977 5443
8c088c52 5444 DBRep::Set (aName.ToCString(), aPickedShape);
5445 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5446 ViewerTest::Display (aName, aShapePrs, false, true);
5447 di << "Name of picked shape: " << aName <<"\n";
7fd59977 5448 }
8c088c52 5449 else
5450 {
5451 TCollection_AsciiString aName (argv[2]);
5452 aName.LowerCase();
5453 const Standard_Boolean isAutoNaming = aName == ".";
5454 Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
5455 if (ViewerTest::PickShapes (aShapeType, aPickedArray))
5456 {
5457 for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
5458 {
5459 TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
5460 aName.Clear();
5461 if (!aPickedShape.IsNull()
5462 && isAutoNaming)
5463 {
5464 const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
5465 aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
5466 }
5467 else
5468 {
5469 aName = argv[1 + aPickedIter];
5470 }
7fd59977 5471
8c088c52 5472 DBRep::Set (aName.ToCString(), aPickedShape);
5473 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
5474 di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
5475 ViewerTest::Display (aName, aShapePrs, false, true);
5476 }
7fd59977 5477 }
5478 }
8c088c52 5479 TheAISContext()->UpdateCurrentViewer();
7fd59977 5480 return 0;
7fd59977 5481}
7fd59977 5482
4d901cde 5483//=======================================================================
d2e60688 5484//function : VSelFilter
4d901cde 5485//purpose :
5486//=======================================================================
d2e60688 5487static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
4d901cde 5488 const char** theArgv)
5489{
4d901cde 5490 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5491 if (aContext.IsNull())
5492 {
5493 std::cout << "Error: AIS context is not available.\n";
5494 return 1;
5495 }
5496
d2e60688 5497 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5498 {
5499 TCollection_AsciiString anArg (theArgv[anArgIter]);
5500 anArg.LowerCase();
5501 if (anArg == "-clear")
5502 {
5503 aContext->RemoveFilters();
4d901cde 5504 }
d2e60688 5505 else if (anArg == "-type"
5506 && anArgIter + 1 < theArgc)
5507 {
5508 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5509 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5510 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5511 {
5512 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5513 return 1;
5514 }
4d901cde 5515
d2e60688 5516 Handle(SelectMgr_Filter) aFilter;
5517 if (aShapeType == TopAbs_SHAPE)
5518 {
5519 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5520 }
5521 else
5522 {
5523 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5524 }
5525 aContext->AddFilter (aFilter);
4d901cde 5526 }
d2e60688 5527 else
5528 {
5529 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5530 return 1;
4d901cde 5531 }
5532 }
5533 return 0;
5534}
5535
d8110103 5536//=======================================================================
5537//function : VPickSelected
5538//purpose :
5539//=======================================================================
5540static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5541{
5542 static Standard_Integer aCount = 0;
5543 TCollection_AsciiString aName = "PickedShape_";
5544
5545 if (theArgNb > 1)
5546 {
5547 aName = theArgs[1];
5548 }
5549 else
5550 {
5551 aName = aName + aCount++ + "_";
5552 }
5553
5554 Standard_Integer anIdx = 0;
5555 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5556 {
5557 TopoDS_Shape aShape;
5558 if (TheAISContext()->HasSelectedShape())
5559 {
5560 aShape = TheAISContext()->SelectedShape();
5561 }
5562 else
5563 {
5564 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 5565 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
d8110103 5566 }
5567
5568 TCollection_AsciiString aCurrentName = aName;
5569 if (anIdx > 0)
5570 {
5571 aCurrentName += anIdx;
5572 }
5573
5574 DBRep::Set ((aCurrentName).ToCString(), aShape);
5575
5576 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5577 GetMapOfAIS().Bind (aNewShape, aCurrentName);
0577ae8c 5578 TheAISContext()->Display (aNewShape, Standard_False);
d8110103 5579 }
5580
0577ae8c 5581 TheAISContext()->UpdateCurrentViewer();
5582
d8110103 5583 return 0;
5584}
5585
7fd59977 5586//=======================================================================
5587//function : list of known objects
5588//purpose :
5589//=======================================================================
5590static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5591{
5592 // 1234567890 12345678901234567 123456789
5593 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5594 TCollection_AsciiString BlankLine(64,'_');
5595 Standard_Integer i ;
5596
5597 di<<"/n"<<BlankLine.ToCString()<<"\n";
5598
5599 for( i =0;i<=2;i++)
5600 Colum[i].Center(20,' ');
5601 for(i=0;i<=2;i++)
5602 di<<"|"<<Colum[i].ToCString();
586db386 5603 di<<"|\n";
7fd59977 5604
5605 di<<BlankLine.ToCString()<<"\n";
5606
5607 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5608 const char ** names = GetTypeNames();
5609
5610 TCollection_AsciiString curstring;
5611 TCollection_AsciiString curcolum[3];
5612
5613
5614 // les objets de type Datum..
5615 curcolum[1]+="Datum";
5616 for(i =0;i<=6;i++){
5617 curcolum[0].Clear();
5618 curcolum[0] += names[i];
5619
5620 curcolum[2].Clear();
5621 curcolum[2]+=TCollection_AsciiString(i+1);
5622
5623 for(Standard_Integer j =0;j<=2;j++){
5624 curcolum[j].Center(20,' ');
5625 di<<"|"<<curcolum[j].ToCString();
5626 }
586db386 5627 di<<"|\n";
7fd59977 5628 }
5629 di<<BlankLine.ToCString()<<"\n";
5630
5631 // les objets de type shape
5632 curcolum[1].Clear();
5633 curcolum[1]+="Shape";
5634 curcolum[1].Center(20,' ');
5635
5636 for(i=0;i<=2;i++){
5637 curcolum[0].Clear();
5638 curcolum[0] += names[7+i];
5639 curcolum[2].Clear();
5640 curcolum[2]+=TCollection_AsciiString(i);
5641
5642 for(Standard_Integer j =0;j<=2;j++){
5643 curcolum[j].Center(20,' ');
5644 di<<"|"<<curcolum[j].ToCString();
5645 }
586db386 5646 di<<"|\n";
7fd59977 5647 }
5648 di<<BlankLine.ToCString()<<"\n";
5649 // les IO de type objet...
5650 curcolum[1].Clear();
5651 curcolum[1]+="Object";
5652 curcolum[1].Center(20,' ');
5653 for(i=0;i<=1;i++){
5654 curcolum[0].Clear();
5655 curcolum[0] += names[10+i];
5656 curcolum[2].Clear();
5657 curcolum[2]+=TCollection_AsciiString(i);
5658
5659 for(Standard_Integer j =0;j<=2;j++){
5660 curcolum[j].Center(20,' ');
5661 di<<"|"<<curcolum[j].ToCString();
5662 }
586db386 5663 di<<"|\n";
7fd59977 5664 }
5665 di<<BlankLine.ToCString()<<"\n";
5666 // les contraintes et dimensions.
5667 // pour l'instant on separe juste contraintes et dimensions...
5668 // plus tard, on detaillera toutes les sortes...
5669 curcolum[1].Clear();
5670 curcolum[1]+="Relation";
5671 curcolum[1].Center(20,' ');
5672 for(i=0;i<=1;i++){
5673 curcolum[0].Clear();
5674 curcolum[0] += names[12+i];
5675 curcolum[2].Clear();
5676 curcolum[2]+=TCollection_AsciiString(i);
5677
5678 for(Standard_Integer j =0;j<=2;j++){
5679 curcolum[j].Center(20,' ');
5680 di<<"|"<<curcolum[j].ToCString();
5681 }
586db386 5682 di<<"|\n";
7fd59977 5683 }
5684 di<<BlankLine.ToCString()<<"\n";
5685
5686
5687 return 0;
5688}
5689
5690
5691static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5692{
4952a30a 5693 if(argc!=2) return 1;
7fd59977 5694
5695 AIS_KindOfInteractive TheType;
5696 Standard_Integer TheSign(-1);
5697 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5698
5699
5700 AIS_ListOfInteractive LIO;
5701
5702 // en attendant l'amelioration ais pour les dimensions...
5703 //
5704 Standard_Integer dimension_status(-1);
5705 if(TheType==AIS_KOI_Relation){
5706 dimension_status = TheSign ==1 ? 1 : 0;
5707 TheSign=-1;
5708 }
5709
5710 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5711 Handle(AIS_InteractiveObject) curio;
5712 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5713 curio = it.Value();
5714
5715 if(dimension_status == -1)
5716 TheAISContext()->Erase(curio,Standard_False);
5717 else {
c5f3a425 5718 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5719 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5720 (dimension_status==1 && KOD != AIS_KOD_NONE))
5721 TheAISContext()->Erase(curio,Standard_False);
5722 }
5723 }
5724 TheAISContext()->UpdateCurrentViewer();
5725 return 0;
5726}
5727static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5728{
5729 if(argc!=2) return 1;
5730
5731 AIS_KindOfInteractive TheType;
5732 Standard_Integer TheSign(-1);
5733 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5734
5735 // en attendant l'amelioration ais pour les dimensions...
5736 //
5737 Standard_Integer dimension_status(-1);
5738 if(TheType==AIS_KOI_Relation){
5739 dimension_status = TheSign ==1 ? 1 : 0;
5740 TheSign=-1;
5741 }
5742
5743 AIS_ListOfInteractive LIO;
5744 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5745 Handle(AIS_InteractiveObject) curio;
5746 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5747 curio = it.Value();
5748 if(dimension_status == -1)
5749 TheAISContext()->Display(curio,Standard_False);
5750 else {
c5f3a425 5751 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5752 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5753 (dimension_status==1 && KOD != AIS_KOD_NONE))
5754 TheAISContext()->Display(curio,Standard_False);
5755 }
5756
5757 }
5758
5759 TheAISContext()->UpdateCurrentViewer();
5760 return 0;
5761}
5762
7fd59977 5763static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5764{
5765 ifstream s(a[1]);
5766 BRep_Builder builder;
5767 TopoDS_Shape shape;
5768 BRepTools::Read(shape, s, builder);
5769 DBRep::Set(a[1], shape);
5770 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5771 Handle(AIS_Shape) ais = new AIS_Shape(shape);
0577ae8c 5772 Ctx->Display (ais, Standard_True);
7fd59977 5773 return 0;
5774}
7fd59977 5775
189f85a3 5776//===============================================================================================
5777//function : VBsdf
5778//purpose :
5779//===============================================================================================
05aa616d 5780static int VBsdf (Draw_Interpretor& theDI,
189f85a3 5781 Standard_Integer theArgsNb,
5782 const char** theArgVec)
5783{
5784 Handle(V3d_View) aView = ViewerTest::CurrentView();
5785 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5786 if (aView.IsNull()
5787 || aViewer.IsNull())
5788 {
5789 std::cerr << "No active viewer!\n";
5790 return 1;
5791 }
5792
5793 ViewerTest_CmdParser aCmd;
5794
5795 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
189f85a3 5796
05aa616d 5797 aCmd.AddOption ("print|echo|p", "Prints BSDF");
189f85a3 5798
05aa616d 5799 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
189f85a3 5800
05aa616d 5801 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5802 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5803 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5804 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5805 aCmd.AddOption ("le", "Radiance emitted by surface");
189f85a3 5806
05aa616d 5807 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5808 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5809
5810 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5811 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5812
5813 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5814 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5815
5816 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
189f85a3 5817
5818 aCmd.Parse (theArgsNb, theArgVec);
5819
5820 if (aCmd.HasOption ("help"))
5821 {
05aa616d 5822 theDI.PrintHelp (theArgVec[0]);
189f85a3 5823 return 0;
5824 }
5825
05aa616d 5826 // check viewer update mode
5827 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
05aa616d 5828 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5829 {
5830 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5831 {
5832 break;
5833 }
5834 }
5835
189f85a3 5836 // find object
8f521168 5837 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5838 Handle(AIS_InteractiveObject) anIObj;
5839 if (!GetMapOfAIS().Find2 (aName, anIObj))
189f85a3 5840 {
586db386 5841 std::cerr << "Use 'vdisplay' before\n";
189f85a3 5842 return 1;
5843 }
5844
189f85a3 5845 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5846 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5847
5848 if (aCmd.HasOption ("print"))
5849 {
05aa616d 5850 theDI << "\n"
5851 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
189f85a3 5852 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
189f85a3 5853 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
05aa616d 5854 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5855 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
189f85a3 5856
05aa616d 5857 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
189f85a3 5858 {
05aa616d 5859 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5860 : aBSDF.FresnelBase.Serialize();
189f85a3 5861
05aa616d 5862 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5863 : "Base Fresnel: ");
5864
5865 if (aFresnel.x() >= 0.f)
5866 {
5867 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5868 << "G = " << aFresnel.g() << ", "
5869 << "B = " << aFresnel.b() << "\n";
5870 }
5871 else if (aFresnel.x() >= -1.5f)
5872 {
5873 theDI << "Constant " << aFresnel.z() << "\n";
5874 }
5875 else if (aFresnel.x() >= -2.5f)
5876 {
5877 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5878 << "K = " << aFresnel.z() << "\n";
5879 }
5880 else
5881 {
5882 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5883 }
5884 }
189f85a3 5885
05aa616d 5886 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5887 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5888 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5889 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5890 << aBSDF.Absorption.g() << ", "
5891 << aBSDF.Absorption.b() << "\n";
189f85a3 5892
5893 return 0;
5894 }
5895
05aa616d 5896 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5897 {
5898 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5899 }
5900
5901 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
189f85a3 5902 {
05aa616d 5903 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
189f85a3 5904 }
5905
5906 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5907 {
05aa616d 5908 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
189f85a3 5909 }
5910
5911 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5912 {
05aa616d 5913 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5914
5915 aBSDF.Absorption.r() = aRGB.r();
5916 aBSDF.Absorption.g() = aRGB.g();
5917 aBSDF.Absorption.b() = aRGB.b();
5918 }
5919
5920 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5921 {
5922 Graphic3d_Vec3 aKc;
5923
5924 if (aCmd.HasOption ("kc", 3))
5925 {
5926 aKc = aCmd.ArgVec3f ("kc");
5927 }
5928 else
5929 {
5930 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5931 }
5932
5933 aBSDF.Kc.r() = aKc.r();
5934 aBSDF.Kc.g() = aKc.g();
5935 aBSDF.Kc.b() = aKc.b();
189f85a3 5936 }
5937
5938 if (aCmd.HasOption ("kd", 3))
5939 {
5940 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5941 }
5942 else if (aCmd.HasOption ("kd", 1, Standard_True))
5943 {
5944 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5945 }
5946
05aa616d 5947 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
189f85a3 5948 {
05aa616d 5949 Graphic3d_Vec3 aKs;
5950
5951 if (aCmd.HasOption ("ks", 3))
5952 {
5953 aKs = aCmd.ArgVec3f ("ks");
5954 }
5955 else
5956 {
5957 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5958 }
5959
5960 aBSDF.Ks.r() = aKs.r();
5961 aBSDF.Ks.g() = aKs.g();
5962 aBSDF.Ks.b() = aKs.b();
189f85a3 5963 }
5964
5965 if (aCmd.HasOption ("kt", 3))
5966 {
5967 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5968 }
5969 else if (aCmd.HasOption ("kt", 1, Standard_True))
5970 {
5971 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5972 }
5973
189f85a3 5974 if (aCmd.HasOption ("le", 3))
5975 {
5976 aBSDF.Le = aCmd.ArgVec3f ("le");
5977 }
5978 else if (aCmd.HasOption ("le", 1, Standard_True))
5979 {
5980 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5981 }
5982
5983 const std::string aFresnelErrorMessage =
05aa616d 5984 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
189f85a3 5985
05aa616d 5986 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
189f85a3 5987 {
05aa616d 5988 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5989 : "coatFresnel";
189f85a3 5990
05aa616d 5991 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
189f85a3 5992 {
05aa616d 5993 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
d6cda17a 5994 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
189f85a3 5995
05aa616d 5996 if (aFresnelType == "schlick")
5997 {
5998 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5999 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
6000 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
189f85a3 6001
05aa616d 6002 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
6003 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
6004 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
6005
6006 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
6007 }
6008 else
6009 {
6010 theDI << aFresnelErrorMessage.c_str() << "\n";
6011 }
189f85a3 6012 }
05aa616d 6013 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
189f85a3 6014 {
05aa616d 6015 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
d6cda17a 6016 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
05aa616d 6017
6018 if (aFresnelType == "conductor")
6019 {
6020 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6021 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
6022
6023 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
6024 }
6025 else
6026 {
6027 theDI << aFresnelErrorMessage.c_str() << "\n";
6028 }
189f85a3 6029 }
05aa616d 6030 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
189f85a3 6031 {
05aa616d 6032 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
d6cda17a 6033 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
05aa616d 6034
6035 if (aFresnelType == "constant")
6036 {
6037 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6038
6039 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
6040 }
6041 else if (aFresnelType == "dielectric")
6042 {
6043 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
6044
6045 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
6046 }
6047 else
6048 {
6049 theDI << aFresnelErrorMessage.c_str() << "\n";
6050 }
189f85a3 6051 }
6052 }
6053
6054 if (aCmd.HasOption ("normalize"))
6055 {
6056 aBSDF.Normalize();
6057 }
6058
6059 aMaterial.SetBSDF (aBSDF);
6060 anIObj->SetMaterial (aMaterial);
6061
189f85a3 6062 return 0;
6063}
6064
f751596e 6065//==============================================================================
6066//function : VLoadSelection
6067//purpose : Adds given objects to map of AIS and loads selection primitives for them
6068//==============================================================================
6069static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
6070 Standard_Integer theArgNb,
6071 const char** theArgVec)
6072{
6073 if (theArgNb < 2)
6074 {
6075 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6076 return 1;
6077 }
6078
6079 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6080 if (aCtx.IsNull())
6081 {
6082 ViewerTest::ViewerInit();
6083 aCtx = ViewerTest::GetAISContext();
6084 }
6085
6086 // Parse input arguments
f751596e 6087 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6088 {
68dcee02 6089 const TCollection_AsciiString aName = theArgVec[anArgIter];
5b111128 6090 Handle(AIS_InteractiveObject) aShape;
8f521168 6091 if (!GetMapOfAIS().Find2 (aName, aShape))
6092 {
1c8fc6be 6093 TopoDS_Shape aDrawShape = DBRep::GetExisting (aName);
6094 if (!aDrawShape.IsNull())
f751596e 6095 {
1c8fc6be 6096 aShape = new AIS_Shape (aDrawShape);
f751596e 6097 GetMapOfAIS().Bind (aShape, aName);
6098 }
f751596e 6099 }
1c8fc6be 6100 if (aShape.IsNull())
6101 {
6102 std::cout << "Syntax error: presentation '" << aName << "' not found\n";
6103 return 1;
6104 }
f751596e 6105
1c8fc6be 6106 aCtx->Load (aShape, -1);
6107 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6108 }
f751596e 6109 return 0;
6110}
6111
7fd59977 6112//==============================================================================
6113//function : ViewerTest::Commands
6114//purpose : Add all the viewer command in the Draw_Interpretor
6115//==============================================================================
6116
6117void ViewerTest::Commands(Draw_Interpretor& theCommands)
6118{
6119 ViewerTest::ViewerCommands(theCommands);
6120 ViewerTest::RelationCommands(theCommands);
6121 ViewerTest::ObjectCommands(theCommands);
6122 ViewerTest::FilletCommands(theCommands);
3946774d 6123 ViewerTest::OpenGlCommands(theCommands);
7fd59977 6124
6125 const char *group = "AIS_Display";
6126
6127 // display
1c88cbaf 6128 theCommands.Add("visos",
b6d587e3 6129 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6130 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6131 __FILE__, visos, group);
7fd59977 6132
6133 theCommands.Add("vdisplay",
faea8b40 6134 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
778cd667 6135 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6136 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6137 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6138 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6139 "\n\t\t: [offsetX offsetY]]]"
af65fb19 6140 "\n\t\t: [-dispMode mode] [-highMode mode]"
faea8b40 6141 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6194ee76 6142 "\n\t\t: [-redisplay] [-erased]"
af65fb19 6143 "\n\t\t: name1 [name2] ... [name n]"
519d35d8 6144 "\n\t\t: Displays named objects."
b6d587e3 6145 "\n\t\t: Option -local enables displaying of objects in local"
6146 "\n\t\t: selection context. Local selection context will be opened"
6147 "\n\t\t: if there is not any."
778cd667 6148 "\n\t\t: -noupdate Suppresses viewer redraw call."
6149 "\n\t\t: -mutable Enables optimizations for mutable objects."
6150 "\n\t\t: -neutral Draws objects in main viewer."
6194ee76 6151 "\n\t\t: -erased Loads the object into context, but does not display it."
778cd667 6152 "\n\t\t: -layer Sets z-layer for objects."
6153 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6154 "\n\t\t: options can be used for the default z-layers."
6155 "\n\t\t: -top Draws object on top of main presentations"
6156 "\n\t\t: but below topmost."
6157 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6158 "\n\t\t: with independent Depth."
6159 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6160 "\n\t\t: (On-Screen-Display)"
6161 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6162 "\n\t\t: (On-Screen-Display)"
6163 "\n\t\t: -selectable|-noselect Controls selection of objects."
6164 "\n\t\t: -trsfPers Sets a transform persistence flags."
6165 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6166 "\n\t\t: -2d Displays object in screen coordinates."
6167 "\n\t\t: (DY looks up)"
6168 "\n\t\t: -dispmode Sets display mode for objects."
6169 "\n\t\t: -highmode Sets hilight mode for objects."
6170 "\n\t\t: -redisplay Recomputes presentation of objects.",
b6d587e3 6171 __FILE__, VDisplay2, group);
7fd59977 6172
bc001a40 6173 theCommands.Add ("vnbdisplayed",
6174 "vnbdisplayed"
6175 "\n\t\t: Returns number of displayed objects",
6176 __FILE__, VNbDisplayed, group);
6177
f3889691 6178 theCommands.Add ("vupdate",
6179 "vupdate name1 [name2] ... [name n]"
6180 "\n\t\t: Updates named objects in interactive context",
6181 __FILE__, VUpdate, group);
6182
7fd59977 6183 theCommands.Add("verase",
b6d587e3 6184 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
ac4aaa98 6185 "\n\t\t: Erases selected or named objects."
b6d587e3 6186 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6187 "\n\t\t: Option -local enables erasing of selected or named objects without"
6188 "\n\t\t: closing local selection context.",
6189 __FILE__, VErase, group);
7fd59977 6190
eef7fc64 6191 theCommands.Add("vremove",
b6d587e3 6192 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
6193 "or vremove [-context] -all to remove all objects"
eef7fc64 6194 "\n\t\t: Removes selected or named objects."
6195 "\n\t\t If -context is in arguments, the objects are not deleted"
519d35d8 6196 "\n\t\t from the map of objects and names."
b6d587e3 6197 "\n\t\t: Option -local enables removing of selected or named objects without"
6198 "\n\t\t: closing local selection context. Empty local selection context will be"
6199 "\n\t\t: closed."
b7cd4ba7 6200 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6201 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
eef7fc64 6202 __FILE__, VRemove, group);
6203
7fd59977 6204 theCommands.Add("vdonly",
519d35d8 6205 "vdonly [-noupdate|-update] [name1] ... [name n]"
ac4aaa98 6206 "\n\t\t: Displays only selected or named objects",
7fd59977 6207 __FILE__,VDonly2,group);
6208
6209 theCommands.Add("vdisplayall",
68dcee02 6210 "vdisplayall"
6211 "\n\t\t: Displays all erased interactive objects (see vdir and vstate).",
b6d587e3 6212 __FILE__, VDisplayAll, group);
7fd59977 6213
6214 theCommands.Add("veraseall",
68dcee02 6215 "veraseall"
6216 "\n\t\t: Erases all objects displayed in the viewer.",
b6d587e3 6217 __FILE__, VErase, group);
7fd59977 6218
6219 theCommands.Add("verasetype",
b6d587e3 6220 "verasetype <Type>"
ac4aaa98 6221 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
b6d587e3 6222 __FILE__, VEraseType, group);
c2a388f8 6223 theCommands.Add("vbounding",
6224 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6225 "\n\t\t: [-print] [-hide]"
6226 "\n\t\t: Temporarily display bounding box of specified Interactive"
6227 "\n\t\t: Objects, or print it to console if -print is specified."
6228 "\n\t\t: Already displayed box might be hidden by -hide option.",
6229 __FILE__,VBounding,group);
6230
7fd59977 6231 theCommands.Add("vdisplaytype",
6232 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6233 __FILE__,VDisplayType,group);
6234
7fd59977 6235 theCommands.Add("vsetdispmode",
ac4aaa98 6236 "vsetdispmode [name] mode(1,2,..)"
6237 "\n\t\t: Sets display mode for all, selected or named objects.",
7fd59977 6238 __FILE__,VDispMode,group);
6239
6240 theCommands.Add("vunsetdispmode",
ac4aaa98 6241 "vunsetdispmode [name]"
6242 "\n\t\t: Unsets custom display mode for selected or named objects.",
7fd59977 6243 __FILE__,VDispMode,group);
6244
6245 theCommands.Add("vdir",
ac4aaa98 6246 "Lists all objects displayed in 3D viewer",
519d35d8 6247 __FILE__,VDir,group);
7fd59977 6248
f978241f 6249#ifdef HAVE_FREEIMAGE
6250 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6251#else
6252 #define DUMP_FORMATS "{ppm}"
6253#endif
7fd59977 6254 theCommands.Add("vdump",
f978241f 6255 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6256 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6257 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
3bffef55 6258 "\n\t\t: [-tileSize Size=0]"
f978241f 6259 "\n\t\t: Dumps content of the active view into image file",
7fd59977 6260 __FILE__,VDump,group);
6261
6262 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6263 __FILE__,VSubInt,group);
6264
ad3217cd 6265 theCommands.Add("vaspects",
6262338c 6266 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
ac116c22 6267 "\n\t\t: [-setVisibility 0|1]"
6268 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6269 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6270 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6271 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6272 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
33cc703b 6273 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6274 "\n\t\t: [-unsetMarkerType]"
6275 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6262338c 6276 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6277 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6278 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
ad3217cd 6279 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5ad8c033 6280 "\n\t\t: [-isoontriangulation 0|1]"
6281 "\n\t\t: [-setMaxParamValue {value}]"
8a1170ad 6282 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
dc89236f 6283 "\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
6284 "\n\t\t: [-unsetShadingModel]"
2a332745 6285 "\n\t\t: [-setInterior {solid|hatch|hidenline|point}]"
6286 "\n\t\t: [-unsetInterior] [-setHatch HatchStyle]"
0493ffd0 6287 "\n\t\t: [-setFaceBoundaryDraw {0|1}] [-setMostContinuity {c0|c1|c2|c3|cn}"
6288 "\n\t\t: [-setFaceBoundaryWidth LineWidth] [-setFaceBoundaryColor R G B] [-setFaceBoundaryType LineType]"
2a332745 6289 "\n\t\t: [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
6ef0d6f1 6290 "\n\t\t: [-setDrawSilhouette {0|1}]"
c40eb6b9 6291 "\n\t\t: [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
ad3217cd 6292 "\n\t\t: Manage presentation properties of all, selected or named objects."
6293 "\n\t\t: When -subshapes is specified than following properties will be"
6262338c 6294 "\n\t\t: assigned to specified sub-shapes."
6295 "\n\t\t: When -defaults is specified than presentation properties will be"
6296 "\n\t\t: assigned to all objects that have not their own specified properties"
6297 "\n\t\t: and to all objects to be displayed in the future."
6298 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
ad3217cd 6299 __FILE__,VAspects,group);
6300
7fd59977 6301 theCommands.Add("vsetcolor",
ad3217cd 6302 "vsetcolor [-noupdate|-update] [name] ColorName"
6303 "\n\t\t: Sets color for all, selected or named objects."
6304 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6305 __FILE__,VAspects,group);
7fd59977 6306
6307 theCommands.Add("vunsetcolor",
ad3217cd 6308 "vunsetcolor [-noupdate|-update] [name]"
6309 "\n\t\t: Resets color for all, selected or named objects."
6310 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6311 __FILE__,VAspects,group);
7fd59977 6312
6313 theCommands.Add("vsettransparency",
ad3217cd 6314 "vsettransparency [-noupdate|-update] [name] Coefficient"
ac4aaa98 6315 "\n\t\t: Sets transparency for all, selected or named objects."
ad3217cd 6316 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6317 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6318 __FILE__,VAspects,group);
7fd59977 6319
6320 theCommands.Add("vunsettransparency",
ad3217cd 6321 "vunsettransparency [-noupdate|-update] [name]"
6322 "\n\t\t: Resets transparency for all, selected or named objects."
6323 "\n\t\t: Alias for vaspects -unsettransp [name].",
6324 __FILE__,VAspects,group);
7fd59977 6325
6326 theCommands.Add("vsetmaterial",
ad3217cd 6327 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6328 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6329 __FILE__,VAspects,group);
7fd59977 6330
6331 theCommands.Add("vunsetmaterial",
ad3217cd 6332 "vunsetmaterial [-noupdate|-update] [name]"
6333 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6334 __FILE__,VAspects,group);
7fd59977 6335
6336 theCommands.Add("vsetwidth",
ad3217cd 6337 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6338 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6339 __FILE__,VAspects,group);
7fd59977 6340
6341 theCommands.Add("vunsetwidth",
ad3217cd 6342 "vunsetwidth [-noupdate|-update] [name]"
2a332745 6343 "\n\t\t: Alias for vaspects -unsetwidth [name].",
ad3217cd 6344 __FILE__,VAspects,group);
7fd59977 6345
99c56d44 6346 theCommands.Add("vsetinteriorstyle",
2a332745 6347 "vsetinteriorstyle [-noupdate|-update] [name] Style"
6348 "\n\t\t: Alias for vaspects -setInterior [name] Style.",
6349 __FILE__,VAspects,group);
6350
6351 theCommands.Add ("vsetedgetype",
6352 "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]"
6353 "\n\t\t: Alias for vaspects [name] -setEdgeType Type.",
6354 __FILE__, VAspects, group);
6355
6356 theCommands.Add ("vunsetedgetype",
6357 "vunsetedgetype [name]"
6358 "\n\t\t: Alias for vaspects [name] -unsetEdgeType.",
6359 __FILE__, VAspects, group);
99c56d44 6360
0493ffd0 6361 theCommands.Add ("vshowfaceboundary",
6362 "vshowfaceboundary [name]"
6363 "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on",
6364 __FILE__, VAspects, group);
6365
7fd59977 6366 theCommands.Add("vsensdis",
faea8b40 6367 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6368 "\n\t\t: Standard entity types are those defined in Select3D package:"
6369 "\n\t\t: - sensitive box"
6370 "\n\t\t: - sensitive face"
6371 "\n\t\t: - sensitive curve"
6372 "\n\t\t: - sensitive segment"
6373 "\n\t\t: - sensitive circle"
6374 "\n\t\t: - sensitive point"
6375 "\n\t\t: - sensitive triangulation"
6376 "\n\t\t: - sensitive triangle"
6377 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6378 __FILE__,VDispSensi,group);
6379
7fd59977 6380 theCommands.Add("vsensera",
faea8b40 6381 "vsensera : erase active entities",
6382 __FILE__,VClearSensi,group);
7fd59977 6383
7fd59977 6384 theCommands.Add("vsetshading",
faea8b40 6385 "vsetshading : vsetshading name Quality(default=0.0008) "
f2139a7f 6386 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
faea8b40 6387 __FILE__,VShading,group);
7fd59977 6388
6389 theCommands.Add("vunsetshading",
faea8b40 6390 "vunsetshading :vunsetshading name "
f2139a7f 6391 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
faea8b40 6392 __FILE__,VShading,group);
7fd59977 6393
d399d3c3 6394 theCommands.Add ("vtexture",
a6dee93d 6395 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
cc8cbabe 6396 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
a6dee93d 6397 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6398 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6399 "\n\t\t: [-modulate {on|off}]"
6400 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6401 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6402 "\n\t\t: [-default]"
6403 "\n\t\t: The texture can be specified by filepath"
6404 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6405 "\n\t\t: The options are:"
6406 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6407 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6408 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6409 "\n\t\t: -modulate Enable or disable texture color modulation"
6410 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6411 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6412 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6413 "\n\t\t: -setFilter Setup texture filter"
6414 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6415 "\n\t\t: -default Sets texture mapping default parameters",
d399d3c3 6416 __FILE__, VTexture, group);
7fd59977 6417
6418 theCommands.Add("vtexscale",
a6dee93d 6419 "vtexscale name ScaleU ScaleV"
6420 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
7fd59977 6421 __FILE__,VTexture,group);
6422
6423 theCommands.Add("vtexorigin",
a6dee93d 6424 "vtexorigin name OriginU OriginV"
6425 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
7fd59977 6426 __FILE__,VTexture,group);
6427
6428 theCommands.Add("vtexrepeat",
a6dee93d 6429 "vtexrepeat name RepeatU RepeatV"
6430 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
7fd59977 6431 VTexture,group);
6432
6433 theCommands.Add("vtexdefault",
a6dee93d 6434 "vtexdefault name"
6435 "\n\t\t: Alias for vtexture name -default.",
7fd59977 6436 VTexture,group);
6437
ac4aaa98 6438 theCommands.Add("vstate",
51023771 6439 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
8e7c8ccf 6440 "\n\t\t: Reports show/hidden state for selected or named objects"
51023771 6441 "\n\t\t: -entities - print low-level information about detected entities"
6442 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
7fd59977 6443 __FILE__,VState,group);
6444
6445 theCommands.Add("vpickshapes",
8c088c52 6446 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
6447 "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
6448 "\n\t\t: Hold also Shift for multiple selection.",
6449 __FILE__, VPickShape, group);
7fd59977 6450
6451 theCommands.Add("vtypes",
6452 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6453 VIOTypes,group);
6454
faea8b40 6455 theCommands.Add("vr",
6456 "vr filename"
6457 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
7fd59977 6458 __FILE__,vr, group);
6459
d2e60688 6460 theCommands.Add("vselfilter",
6461 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
4d901cde 6462 "\nSets selection shape type filter in context or remove all filters."
6463 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6464 "\n : Option -clear remove all filters in context",
d2e60688 6465 __FILE__,VSelFilter,group);
4d901cde 6466
d8110103 6467 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6468 __FILE__, VPickSelected, group);
6469
f751596e 6470 theCommands.Add ("vloadselection",
6471 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
68dcee02 6472 "\n\t\t: primitives for the shapes with names given without displaying them.",
f751596e 6473 __FILE__, VLoadSelection, group);
6474
189f85a3 6475 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6476 "\nAdjusts parameters of material BSDF:"
6477 "\n -help : Shows this message"
6478 "\n -print : Print BSDF"
6479 "\n -kd : Weight of the Lambertian BRDF"
6480 "\n -kr : Weight of the reflection BRDF"
6481 "\n -kt : Weight of the transmission BTDF"
6482 "\n -ks : Weight of the glossy Blinn BRDF"
6483 "\n -le : Self-emitted radiance"
6484 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6485 "\n Schlick x y z, Dielectric x, Conductor x y"
6486 "\n -roughness : Roughness of material (Blinn's exponent)"
6487 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6488 "\n -absorpcolor : Absorption color (only for transparent material)"
6489 "\n -normalize : Normalize BSDF coefficients",
6490 __FILE__, VBsdf, group);
6491
7fd59977 6492}
6493
6494//=====================================================================
6495//========================= for testing Draft and Rib =================
6496//=====================================================================
6497#include <BRepOffsetAPI_MakeThickSolid.hxx>
6498#include <DBRep.hxx>
6499#include <TopoDS_Face.hxx>
6500#include <gp_Pln.hxx>
6501#include <AIS_KindOfSurface.hxx>
6502#include <BRepOffsetAPI_DraftAngle.hxx>
6503#include <Precision.hxx>
6504#include <BRepAlgo.hxx>
6505#include <OSD_Environment.hxx>
6506#include <DrawTrSurf.hxx>
6507//#include <DbgTools.hxx>
6508//#include <FeatAlgo_MakeLinearForm.hxx>
6509
6510
6511
6512
6513//=======================================================================
6514//function : IsValid
6515//purpose :
6516//=======================================================================
6517static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6518 const TopoDS_Shape& theResult,
6519 const Standard_Boolean closedSolid,
6520 const Standard_Boolean GeomCtrl)
6521{
6522 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6523 TCollection_AsciiString checkValid = check.Value();
6524 Standard_Boolean ToCheck = Standard_True;
6525 if (!checkValid.IsEmpty()) {
0797d9d3 6526#ifdef OCCT_DEBUG
7fd59977 6527 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6528#endif
6529 if ( checkValid=="true" || checkValid=="TRUE" ) {
6530 ToCheck= Standard_False;
6531 }
6532 } else {
0797d9d3 6533#ifdef OCCT_DEBUG
586db386 6534 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
7fd59977 6535#endif
6536 }
6537 Standard_Boolean IsValid = Standard_True;
6538 if (ToCheck)
6539 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6540 return IsValid;
6541
6542}
6543
6544//===============================================================================
6545// TDraft : test draft, uses AIS Viewer
6546// Solid Face Plane Angle Reverse
6547//===============================================================================
6548static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6549{
6550 if (argc < 5) return 1;
6551// argv[1] - TopoDS_Shape Solid
6552// argv[2] - TopoDS_Shape Face
6553// argv[3] - TopoDS_Shape Plane
6554// argv[4] - Standard_Real Angle
6555// argv[5] - Standard_Integer Reverse
6556
91322f44 6557// Sprintf(prefix, argv[1]);
7fd59977 6558 Standard_Real anAngle = 0;
6559 Standard_Boolean Rev = Standard_False;
6560 Standard_Integer rev = 0;
1c8fc6be 6561 TopoDS_Shape Solid = DBRep::Get (argv[1]);
6562 TopoDS_Shape face = DBRep::Get (argv[2]);
7fd59977 6563 TopoDS_Face Face = TopoDS::Face(face);
1c8fc6be 6564 TopoDS_Shape Plane = DBRep::Get (argv[3]);
7fd59977 6565 if (Plane.IsNull ()) {
586db386 6566 di << "TEST : Plane is NULL\n";
7fd59977 6567 return 1;
6568 }
91322f44 6569 anAngle = Draw::Atof(argv[4]);
c6541a0c 6570 anAngle = 2*M_PI * anAngle / 360.0;
7fd59977 6571 gp_Pln aPln;
6572 Handle( Geom_Surface )aSurf;
6573 AIS_KindOfSurface aSurfType;
6574 Standard_Real Offset;
6575 gp_Dir aDir;
6576 if(argc > 4) { // == 5
91322f44 6577 rev = Draw::Atoi(argv[5]);
7fd59977 6578 Rev = (rev)? Standard_True : Standard_False;
6579 }
6580
6581 TopoDS_Face face2 = TopoDS::Face(Plane);
6582 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6583 {
586db386 6584 di << "TEST : Can't find plane\n";
7fd59977 6585 return 1;
6586 }
6587
6588 aDir = aPln.Axis().Direction();
6589 if (!aPln.Direct())
6590 aDir.Reverse();
6591 if (Plane.Orientation() == TopAbs_REVERSED)
6592 aDir.Reverse();
6593 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6594
6595 BRepOffsetAPI_DraftAngle Draft (Solid);
6596
6597 if(Abs(anAngle)< Precision::Angular()) {
586db386 6598 di << "TEST : NULL angle\n";
7fd59977 6599 return 1;}
6600
6601 if(Rev) anAngle = - anAngle;
6602 Draft.Add (Face, aDir, anAngle, aPln);
6603 Draft.Build ();
6604 if (!Draft.IsDone()) {
586db386 6605 di << "TEST : Draft Not DONE \n";
7fd59977 6606 return 1;
6607 }
6608 TopTools_ListOfShape Larg;
6609 Larg.Append(Solid);
6610 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
586db386 6611 di << "TEST : DesignAlgo returns Not valid\n";
7fd59977 6612 return 1;
6613 }
6614
6615 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6616 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6617
6618 if ( !ais.IsNull() ) {
6619 ais->SetColor(DEFAULT_COLOR);
6620 ais->SetMaterial(DEFAULT_MATERIAL);
6621 // Display the AIS_Shape without redraw
6622 Ctx->Display(ais, Standard_False);
6623
6624 const char *Name = "draft1";
8f521168 6625 Handle(AIS_InteractiveObject) an_object;
6626 if (GetMapOfAIS().Find2(Name, an_object))
6627 {
6628 if (!an_object.IsNull())
6629 {
6630 Ctx->Remove (an_object, Standard_True);
7fd59977 6631 }
8f521168 6632 GetMapOfAIS().UnBind2 (Name);
7fd59977 6633 }
6634 GetMapOfAIS().Bind(ais, Name);
6635// DBRep::Set("draft", ais->Shape());
6636 }
6637 Ctx->Display(ais, Standard_True);
6638 return 0;
6639}
6640
1d7ca641 6641//==============================================================================
6642//function : splitParameter
197ac94e 6643//purpose : Split parameter string to parameter name and parameter value
1d7ca641 6644//==============================================================================
6645Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6646 TCollection_AsciiString& theName,
6647 TCollection_AsciiString& theValue)
6648{
6649 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6650
6651 if (aParamNameEnd == 0)
6652 {
6653 return Standard_False;
6654 }
6655
6656 TCollection_AsciiString aString (theString);
6657 if (aParamNameEnd != 0)
6658 {
6659 theValue = aString.Split (aParamNameEnd);
6660 aString.Split (aString.Length() - 1);
6661 theName = aString;
6662 }
7fd59977 6663
1d7ca641 6664 return Standard_True;
6665}
7fd59977 6666
6667//============================================================================
6668// MyCommands
6669//============================================================================
6670void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6671{
6672
6673 DrawTrSurf::BasicCommands(theCommands);
6674 const char* group = "Check Features Operations commands";
6675
6676 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6677 __FILE__,
6678 &TDraft,group); //Draft_Modification
6679}
6680
6681//==============================================================================
6682// ViewerTest::Factory
6683//==============================================================================
6684void ViewerTest::Factory(Draw_Interpretor& theDI)
6685{
6686 // definition of Viewer Command
128cc8df 6687 ViewerTest::Commands(theDI);
128cc8df 6688
0797d9d3 6689#ifdef OCCT_DEBUG
586db386 6690 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7fd59977 6691#endif
6692}
6693
6694// Declare entry point PLUGINFACTORY
6695DPLUGIN(ViewerTest)