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