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