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