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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
19 #include <ViewerTest.hxx>
20 #include <ViewerTest_CmdParser.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>
37 #include <AIS_ColoredShape.hxx>
38 #include <AIS_InteractiveObject.hxx>
39 #include <AIS_Trihedron.hxx>
40 #include <AIS_Axis.hxx>
41 #include <AIS_Relation.hxx>
42 #include <AIS_TypeFilter.hxx>
43 #include <AIS_SignatureFilter.hxx>
44 #include <AIS_LocalContext.hxx>
45 #include <AIS_ListOfInteractive.hxx>
46 #include <AIS_ListIteratorOfListOfInteractive.hxx>
47 #include <Aspect_InteriorStyle.hxx>
48 #include <Aspect_Window.hxx>
49 #include <Graphic3d_AspectFillArea3d.hxx>
50 #include <Graphic3d_AspectLine3d.hxx>
51 #include <Graphic3d_CStructure.hxx>
52 #include <Graphic3d_Texture2Dmanual.hxx>
53 #include <Graphic3d_GraphicDriver.hxx>
54 #include <Image_AlienPixMap.hxx>
55 #include <OSD_File.hxx>
56 #include <Prs3d_Drawer.hxx>
57 #include <Prs3d_ShadingAspect.hxx>
58 #include <Prs3d_IsoAspect.hxx>
59 #include <Prs3d_PointAspect.hxx>
60 #include <Select3D_SensitiveWire.hxx>
61 #include <Select3D_SensitivePrimitiveArray.hxx>
62 #include <SelectMgr_EntityOwner.hxx>
63 #include <StdSelect_BRepOwner.hxx>
64 #include <StdSelect_ViewerSelector3d.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <ViewerTest_AutoUpdater.hxx>
70 #include <Draw_Interpretor.hxx>
71 #include <TCollection_AsciiString.hxx>
72 #include <Draw_PluginMacro.hxx>
74 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
76 #include <Quantity_Color.hxx>
77 #include <Quantity_NameOfColor.hxx>
79 #include <Graphic3d_NameOfMaterial.hxx>
81 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
82 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
83 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
85 //=======================================================================
86 //function : GetColorFromName
87 //purpose : get the Quantity_NameOfColor from a string
88 //=======================================================================
90 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
92 Quantity_NameOfColor aColor = DEFAULT_COLOR;
93 Quantity_Color::ColorFromName (theName, aColor);
97 //=======================================================================
98 //function : ParseColor
100 //=======================================================================
102 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
103 const char** theArgVec,
104 Quantity_Color& theColor)
106 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
108 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
113 else if (theArgNb >= 3)
115 const TCollection_AsciiString anRgbStr[3] =
121 if (!anRgbStr[0].IsRealValue()
122 || !anRgbStr[1].IsRealValue()
123 || !anRgbStr[2].IsRealValue())
128 Graphic3d_Vec4d anRgb;
129 anRgb.x() = anRgbStr[0].RealValue();
130 anRgb.y() = anRgbStr[1].RealValue();
131 anRgb.z() = anRgbStr[2].RealValue();
132 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
133 || anRgb.y() < 0.0 || anRgb.y() > 1.0
134 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
136 std::cout << "Error: RGB color values should be within range 0..1!\n";
140 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
147 //=======================================================================
148 //function : ParseOnOff
150 //=======================================================================
151 Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
152 Standard_Boolean& theIsOn)
154 TCollection_AsciiString aFlag(theArg);
159 theIsOn = Standard_True;
160 return Standard_True;
162 else if (aFlag == "off"
165 theIsOn = Standard_False;
166 return Standard_True;
168 return Standard_False;
171 //=======================================================================
172 //function : GetSelectedShapes
174 //=======================================================================
175 void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
177 for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
179 TopoDS_Shape aShape = GetAISContext()->SelectedShape();
180 if (!aShape.IsNull())
182 theSelectedShapes.Append (aShape);
187 //=======================================================================
188 //function : ParseLineType
190 //=======================================================================
191 Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
192 Aspect_TypeOfLine& theType)
194 TCollection_AsciiString aTypeStr (theArg);
195 aTypeStr.LowerCase();
196 if (aTypeStr == "empty")
198 theType = Aspect_TOL_EMPTY;
200 else if (aTypeStr == "solid")
202 theType = Aspect_TOL_SOLID;
204 else if (aTypeStr == "dot")
206 theType = Aspect_TOL_DOT;
208 else if (aTypeStr == "dash")
210 theType = Aspect_TOL_DASH;
212 else if (aTypeStr == "dotdash")
214 theType = Aspect_TOL_DOTDASH;
218 const int aTypeInt = Draw::Atoi (theArg);
219 if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
221 return Standard_False;
223 theType = (Aspect_TypeOfLine )aTypeInt;
225 return Standard_True;
228 //=======================================================================
229 //function : ParseMarkerType
231 //=======================================================================
232 Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
233 Aspect_TypeOfMarker& theType,
234 Handle(Image_PixMap)& theImage)
237 TCollection_AsciiString aTypeStr (theArg);
238 aTypeStr.LowerCase();
239 if (aTypeStr == "empty")
241 theType = Aspect_TOM_EMPTY;
243 else if (aTypeStr == "point"
247 theType = Aspect_TOM_POINT;
249 else if (aTypeStr == "plus"
252 theType = Aspect_TOM_PLUS;
254 else if (aTypeStr == "star"
257 theType = Aspect_TOM_STAR;
259 else if (aTypeStr == "cross"
262 theType = Aspect_TOM_X;
264 else if (aTypeStr == "circle"
267 theType = Aspect_TOM_O;
269 else if (aTypeStr == "pointincircle")
271 theType = Aspect_TOM_O_POINT;
273 else if (aTypeStr == "plusincircle")
275 theType = Aspect_TOM_O_PLUS;
277 else if (aTypeStr == "starincircle")
279 theType = Aspect_TOM_O_STAR;
281 else if (aTypeStr == "crossincircle"
282 || aTypeStr == "xcircle")
284 theType = Aspect_TOM_O_X;
286 else if (aTypeStr == "ring1")
288 theType = Aspect_TOM_RING1;
290 else if (aTypeStr == "ring2")
292 theType = Aspect_TOM_RING2;
294 else if (aTypeStr == "ring"
295 || aTypeStr == "ring3")
297 theType = Aspect_TOM_RING3;
299 else if (aTypeStr == "ball")
301 theType = Aspect_TOM_BALL;
303 else if (aTypeStr.IsIntegerValue())
305 const int aTypeInt = aTypeStr.IntegerValue();
306 if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
308 return Standard_False;
310 theType = (Aspect_TypeOfMarker )aTypeInt;
314 theType = Aspect_TOM_USERDEFINED;
315 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
316 if (!anImage->Load (theArg))
318 return Standard_False;
320 if (anImage->Format() == Image_Format_Gray)
322 anImage->SetFormat (Image_Format_Alpha);
324 else if (anImage->Format() == Image_Format_GrayF)
326 anImage->SetFormat (Image_Format_AlphaF);
330 return Standard_True;
333 //=======================================================================
334 //function : GetTypeNames
336 //=======================================================================
337 static const char** GetTypeNames()
339 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
340 "Shape","ConnectedShape","MultiConn.Shape",
341 "ConnectedInter.","MultiConn.",
342 "Constraint","Dimension"};
343 static const char** ThePointer = names;
347 //=======================================================================
348 //function : GetTypeAndSignfromString
350 //=======================================================================
351 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
353 const char ** thefullnames = GetTypeNames();
354 Standard_Integer index(-1);
356 for(Standard_Integer i=0;i<=13 && index==-1;i++)
357 if(!strcasecmp(name,thefullnames[i]))
361 TheType = AIS_KOI_None;
367 TheType = AIS_KOI_Datum;
371 TheType = AIS_KOI_Shape;
375 TheType = AIS_KOI_Object;
379 TheType = AIS_KOI_Relation;
388 #include <Draw_Interpretor.hxx>
390 #include <Draw_Appli.hxx>
394 #include <TCollection_AsciiString.hxx>
395 #include <V3d_Viewer.hxx>
396 #include <V3d_View.hxx>
399 #include <AIS_InteractiveContext.hxx>
400 #include <AIS_Shape.hxx>
401 #include <AIS_DisplayMode.hxx>
402 #include <TColStd_MapOfInteger.hxx>
403 #include <AIS_MapOfInteractive.hxx>
404 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
405 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
406 #include <ViewerTest_EventManager.hxx>
408 #include <TopoDS_Solid.hxx>
409 #include <BRepTools.hxx>
410 #include <BRep_Builder.hxx>
411 #include <TopAbs_ShapeEnum.hxx>
413 #include <TopoDS.hxx>
414 #include <BRep_Tool.hxx>
417 #include <Draw_Window.hxx>
418 #include <AIS_ListIteratorOfListOfInteractive.hxx>
419 #include <AIS_ListOfInteractive.hxx>
420 #include <AIS_DisplayMode.hxx>
421 #include <TopTools_ListOfShape.hxx>
422 #include <BRepOffsetAPI_MakeThickSolid.hxx>
424 //==============================================================================
425 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
426 //==============================================================================
427 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
428 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
432 //=======================================================================
435 //=======================================================================
436 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
437 const Handle(AIS_InteractiveObject)& theObject,
438 const Standard_Boolean theToUpdate,
439 const Standard_Boolean theReplaceIfExists)
441 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
442 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
445 std::cout << "Error: AIS context is not available.\n";
446 return Standard_False;
449 if (aMap.IsBound2 (theName))
451 if (!theReplaceIfExists)
453 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
454 << "Please use another name.\n";
455 return Standard_False;
458 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
459 if (!anOldObj.IsNull())
461 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
463 aMap.UnBind2 (theName);
466 if (theObject.IsNull())
468 // object with specified name has been already unbound
469 return Standard_True;
472 // unbind AIS object if it was bound with another name
473 aMap.UnBind1 (theObject);
475 // can be registered without rebinding
476 aMap.Bind (theObject, theName);
477 aCtx->Display (theObject, theToUpdate);
478 return Standard_True;
481 //! Alias for ViewerTest::Display(), compatibility with old code.
482 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
483 const Handle(AIS_InteractiveObject)& theObject,
484 Standard_Boolean theReplaceIfExists = Standard_True)
486 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
489 static TColStd_MapOfInteger theactivatedmodes(8);
490 static TColStd_ListOfTransient theEventMgrs;
492 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
493 const Handle(AIS_InteractiveContext)& Ctx)
495 theEventMgrs.Clear();
496 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
499 static Handle(V3d_View)& a3DView()
501 static Handle(V3d_View) Viou;
506 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
507 static Handle(AIS_InteractiveContext) aContext;
511 const Handle(V3d_View)& ViewerTest::CurrentView()
515 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
520 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
522 return TheAISContext();
525 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
527 TheAISContext() = aCtx;
528 ViewerTest::ResetEventManager();
531 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
533 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
536 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
538 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
542 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
543 theEventMgrs.Prepend(EM);
546 void ViewerTest::UnsetEventManager()
548 theEventMgrs.RemoveFirst();
552 void ViewerTest::ResetEventManager()
554 const Handle(V3d_View) aView = ViewerTest::CurrentView();
555 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
558 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
560 Handle(ViewerTest_EventManager) EM;
561 if(theEventMgrs.IsEmpty()) return EM;
562 Handle(Standard_Transient) Tr = theEventMgrs.First();
563 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
567 //=======================================================================
568 //function : Get Context and active view
570 //=======================================================================
571 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
572 Handle(V3d_View)& theView)
574 theCtx = ViewerTest::GetAISContext();
575 theView = ViewerTest::CurrentView();
579 std::cout << "Error: cannot find an active view!\n";
580 return Standard_False;
582 return Standard_True;
585 //==============================================================================
586 //function : GetShapeFromName
587 //purpose : Compute an Shape from a draw variable or a file name
588 //==============================================================================
590 static TopoDS_Shape GetShapeFromName(const char* name)
592 TopoDS_Shape S = DBRep::Get(name);
595 BRep_Builder aBuilder;
596 BRepTools::Read( S, name, aBuilder);
602 //==============================================================================
603 //function : GetAISShapeFromName
604 //purpose : Compute an AIS_Shape from a draw variable or a file name
605 //==============================================================================
606 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
608 Handle(AIS_Shape) retsh;
610 if(GetMapOfAIS().IsBound2(name)){
611 const Handle(AIS_InteractiveObject) IO =
612 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
614 if(IO->Type()==AIS_KOI_Shape) {
615 if(IO->Signature()==0){
616 retsh = Handle(AIS_Shape)::DownCast (IO);
619 cout << "an Object which is not an AIS_Shape "
620 "already has this name!!!"<<endl;
627 TopoDS_Shape S = GetShapeFromName(name);
629 retsh = new AIS_Shape(S);
635 //==============================================================================
637 //purpose : Remove all the object from the viewer
638 //==============================================================================
639 void ViewerTest::Clear()
641 if (a3DView().IsNull())
646 NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
647 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
649 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
650 if (anObj->GetContext() != TheAISContext())
655 std::cout << "Remove " << anObjIter.Key2() << std::endl;
656 TheAISContext()->Remove (anObj, Standard_False);
657 aListRemoved.Append (anObj);
660 TheAISContext()->RebuildSelectionStructs();
661 TheAISContext()->UpdateCurrentViewer();
662 if (aListRemoved.Size() == GetMapOfAIS().Extent())
664 GetMapOfAIS().Clear();
668 for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
670 GetMapOfAIS().UnBind1 (anObjIter.Value());
675 //==============================================================================
676 //function : StandardModesActivation
677 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
679 //==============================================================================
680 Standard_DISABLE_DEPRECATION_WARNINGS
681 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
683 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
685 if (TheAISContext()->HasOpenedContext())
687 aContext->CloseLocalContext();
691 if(!aContext->HasOpenedContext()) {
692 // To unhilight the preselected object
693 aContext->UnhilightSelected(Standard_False);
694 // Open a local Context in order to be able to select subshape from
695 // the selected shape if any or for all if there is no selection
696 if (!aContext->FirstSelectedObject().IsNull()){
697 aContext->OpenLocalContext(Standard_False);
699 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
700 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
705 aContext->OpenLocalContext();
709 const TopAbs_ShapeEnum aShapeType = AIS_Shape::SelectionType (mode);
710 const char* cmode = mode >= 0 && mode <= 8
711 ? TopAbs::ShapeTypeToString (aShapeType)
713 if(theactivatedmodes.Contains(mode))
715 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
716 theactivatedmodes.Remove(mode);
717 cout<<"Mode "<< cmode <<" OFF"<<endl;
721 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
722 theactivatedmodes.Add(mode);
723 cout<<"Mode "<< cmode << " ON" << endl;
727 Standard_ENABLE_DEPRECATION_WARNINGS
729 //==============================================================================
730 //function : CopyIsoAspect
731 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
732 //==============================================================================
733 static Handle(Prs3d_IsoAspect) CopyIsoAspect
734 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
735 const Standard_Integer theNbIsos)
737 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
738 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
739 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
741 Handle(Prs3d_IsoAspect) aResult =
742 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
747 //==============================================================================
749 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
750 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
751 //==============================================================================
752 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
754 if (TheAISContext().IsNull()) {
755 di << argv[0] << " Call 'vinit' before!\n";
760 di << "Current number of isos : " <<
761 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
762 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
763 di << "IsoOnPlane mode is " <<
764 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
765 di << "IsoOnTriangulation mode is " <<
766 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
770 Standard_Integer aLastInd = argc - 1;
771 Standard_Boolean isChanged = Standard_False;
772 Standard_Integer aNbUIsos = 0;
773 Standard_Integer aNbVIsos = 0;
776 Standard_Boolean isIsoOnPlane = Standard_False;
778 if (strcmp(argv[aLastInd], "1") == 0) {
779 isIsoOnPlane = Standard_True;
780 isChanged = Standard_True;
781 } else if (strcmp(argv[aLastInd], "0") == 0) {
782 isIsoOnPlane = Standard_False;
783 isChanged = Standard_True;
787 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
788 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
791 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
792 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
794 TheAISContext()->IsoOnPlane(isIsoOnPlane);
797 // If there are no shapes provided set the default numbers.
798 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
799 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
806 for (i = 1; i <= aLastInd; i++) {
807 TCollection_AsciiString name(argv[i]);
808 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
811 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
812 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
813 const Handle(AIS_InteractiveObject) aShape =
814 Handle(AIS_InteractiveObject)::DownCast (anObj);
815 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
816 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
817 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
820 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
821 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
822 TheAISContext()->SetLocalAttributes
823 (aShape, CurDrawer, Standard_False);
824 TheAISContext()->Redisplay (aShape, Standard_False);
826 di << "Number of isos for " << argv[i] << " : "
827 << aUIso->Number() << " " << aVIso->Number() << "\n";
830 di << argv[i] << ": Not an AIS interactive object!\n";
833 di << argv[i] << ": Use 'vdisplay' before\n";
838 TheAISContext()->UpdateCurrentViewer();
844 static Standard_Integer VDispSensi (Draw_Interpretor& ,
845 Standard_Integer theArgNb,
850 std::cout << "Error: wrong syntax!\n";
854 Handle(AIS_InteractiveContext) aCtx;
855 Handle(V3d_View) aView;
856 if (!getCtxAndView (aCtx, aView))
861 aCtx->DisplayActiveSensitive (aView);
866 static Standard_Integer VClearSensi (Draw_Interpretor& ,
867 Standard_Integer theArgNb,
872 std::cout << "Error: wrong syntax!\n";
876 Handle(AIS_InteractiveContext) aCtx;
877 Handle(V3d_View) aView;
878 if (!getCtxAndView (aCtx, aView))
882 aCtx->ClearActiveSensitive (aView);
886 //==============================================================================
888 //purpose : To list the displayed object with their attributes
889 //==============================================================================
890 static int VDir (Draw_Interpretor& theDI,
894 if (!a3DView().IsNull())
899 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
900 anIter.More(); anIter.Next())
902 theDI << "\t" << anIter.Key2().ToCString() << "\n";
907 //! Auxiliary enumeration
908 enum ViewerTest_StereoPair
910 ViewerTest_SP_Single,
911 ViewerTest_SP_SideBySide,
912 ViewerTest_SP_OverUnder
915 //==============================================================================
917 //purpose : To dump the active view snapshot to image file
918 //==============================================================================
919 static Standard_Integer VDump (Draw_Interpretor& theDI,
920 Standard_Integer theArgNb,
921 Standard_CString* theArgVec)
925 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
929 Standard_Integer anArgIter = 1;
930 Standard_CString aFilePath = theArgVec[anArgIter++];
931 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
932 V3d_ImageDumpOptions aParams;
933 aParams.BufferType = Graphic3d_BT_RGB;
934 aParams.StereoOptions = V3d_SDO_MONO;
935 for (; anArgIter < theArgNb; ++anArgIter)
937 TCollection_AsciiString anArg (theArgVec[anArgIter]);
939 if (anArg == "-buffer")
941 if (++anArgIter >= theArgNb)
943 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
947 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
949 if (aBufArg == "rgba")
951 aParams.BufferType = Graphic3d_BT_RGBA;
953 else if (aBufArg == "rgb")
955 aParams.BufferType = Graphic3d_BT_RGB;
957 else if (aBufArg == "depth")
959 aParams.BufferType = Graphic3d_BT_Depth;
963 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
967 else if (anArg == "-stereo")
969 if (++anArgIter >= theArgNb)
971 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
975 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
976 aStereoArg.LowerCase();
977 if (aStereoArg == "l"
978 || aStereoArg == "left")
980 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
982 else if (aStereoArg == "r"
983 || aStereoArg == "right")
985 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
987 else if (aStereoArg == "mono")
989 aParams.StereoOptions = V3d_SDO_MONO;
991 else if (aStereoArg == "blended"
992 || aStereoArg == "blend"
993 || aStereoArg == "stereo")
995 aParams.StereoOptions = V3d_SDO_BLENDED;
997 else if (aStereoArg == "sbs"
998 || aStereoArg == "sidebyside")
1000 aStereoPair = ViewerTest_SP_SideBySide;
1002 else if (aStereoArg == "ou"
1003 || aStereoArg == "overunder")
1005 aStereoPair = ViewerTest_SP_OverUnder;
1009 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
1013 else if (anArg == "-rgba"
1016 aParams.BufferType = Graphic3d_BT_RGBA;
1018 else if (anArg == "-rgb"
1021 aParams.BufferType = Graphic3d_BT_RGB;
1023 else if (anArg == "-depth"
1024 || anArg == "depth")
1026 aParams.BufferType = Graphic3d_BT_Depth;
1028 else if (anArg == "-width"
1030 || anArg == "sizex")
1032 if (aParams.Width != 0)
1034 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1037 else if (++anArgIter >= theArgNb)
1039 std::cout << "Error: integer value is expected right after 'width'\n";
1042 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
1044 else if (anArg == "-height"
1045 || anArg == "height"
1046 || anArg == "-sizey")
1048 if (aParams.Height != 0)
1050 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
1053 else if (++anArgIter >= theArgNb)
1055 std::cout << "Error: integer value is expected right after 'height'\n";
1058 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
1060 else if (anArg == "-tile"
1061 || anArg == "-tilesize")
1063 if (++anArgIter >= theArgNb)
1065 std::cout << "Error: integer value is expected right after 'tileSize'\n";
1068 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
1072 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
1076 if ((aParams.Width <= 0 && aParams.Height > 0)
1077 || (aParams.Width > 0 && aParams.Height <= 0))
1079 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
1083 Handle(V3d_View) aView = ViewerTest::CurrentView();
1086 std::cout << "Error: cannot find an active view!\n";
1090 if (aParams.Width <= 0 || aParams.Height <= 0)
1092 aView->Window()->Size (aParams.Width, aParams.Height);
1095 Image_AlienPixMap aPixMap;
1096 Image_Format aFormat = Image_Format_UNKNOWN;
1097 switch (aParams.BufferType)
1099 case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break;
1100 case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break;
1101 case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
1102 case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break;
1105 switch (aStereoPair)
1107 case ViewerTest_SP_Single:
1109 if (!aView->ToPixMap (aPixMap, aParams))
1111 theDI << "Fail: view dump failed!\n";
1114 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
1115 || aPixMap.SizeY() != Standard_Size(aParams.Height))
1117 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
1118 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
1122 case ViewerTest_SP_SideBySide:
1124 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
1126 theDI << "Fail: not enough memory for image allocation!\n";
1130 Image_PixMap aPixMapL, aPixMapR;
1131 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1132 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1133 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
1134 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1136 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1137 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1138 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1139 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1142 theDI << "Fail: view dump failed!\n";
1147 case ViewerTest_SP_OverUnder:
1149 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
1151 theDI << "Fail: not enough memory for image allocation!\n";
1155 Image_PixMap aPixMapL, aPixMapR;
1156 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1157 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1158 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
1159 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
1161 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
1162 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
1163 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
1164 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
1167 theDI << "Fail: view dump failed!\n";
1174 if (!aPixMap.Save (aFilePath))
1176 theDI << "Fail: image can not be saved!\n";
1181 enum TypeOfDispOperation
1183 TypeOfDispOperation_SetDispMode,
1184 TypeOfDispOperation_UnsetDispMode
1187 //! Displays,Erase...
1188 static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1189 const Standard_Integer theMode,
1190 const TypeOfDispOperation theType,
1191 const Standard_Boolean theToUpdate)
1193 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1196 case TypeOfDispOperation_SetDispMode:
1198 if (!thePrs.IsNull())
1200 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1204 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1208 case TypeOfDispOperation_UnsetDispMode:
1210 if (!thePrs.IsNull())
1212 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1216 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1223 //=======================================================================
1226 //=======================================================================
1227 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1232 std::cout << "Syntax error: wrong number of arguments\n";
1236 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1237 ? TypeOfDispOperation_UnsetDispMode
1238 : TypeOfDispOperation_SetDispMode;
1239 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1240 if (aType == TypeOfDispOperation_UnsetDispMode)
1244 if (aCtx->NbSelected() == 0)
1246 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1250 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1252 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1255 aCtx->UpdateCurrentViewer();
1259 TCollection_AsciiString aName = argv[1];
1260 if (GetMapOfAIS().IsBound2 (aName))
1262 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1265 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1272 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1273 if (aCtx->NbSelected() == 0
1274 && aType == TypeOfDispOperation_SetDispMode)
1276 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
1278 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1280 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
1282 aCtx->UpdateCurrentViewer();
1286 Handle(AIS_InteractiveObject) aPrs;
1287 TCollection_AsciiString aName (argv[1]);
1288 if (GetMapOfAIS().IsBound2 (aName))
1290 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1294 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1301 //=======================================================================
1304 //=======================================================================
1305 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1307 if(argc==1) return 1;
1308 Standard_Integer On = Draw::Atoi(argv[1]);
1309 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1313 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1314 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1315 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1319 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
1323 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
1327 Ctx->UpdateCurrentViewer();
1330 Handle(AIS_InteractiveObject) IO;
1331 TCollection_AsciiString name = argv[2];
1332 if(GetMapOfAIS().IsBound2(name)){
1333 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1336 Ctx->SubIntensityOn(IO, Standard_True);
1338 Ctx->SubIntensityOff(IO, Standard_True);
1346 //! Auxiliary class to iterate presentations from different collections.
1347 class ViewTest_PrsIter
1351 //! Create and initialize iterator object.
1352 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1353 : mySource (IterSource_All)
1355 NCollection_Sequence<TCollection_AsciiString> aNames;
1356 if (!theName.IsEmpty())
1357 aNames.Append (theName);
1361 //! Create and initialize iterator object.
1362 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1363 : mySource (IterSource_All)
1368 //! Initialize the iterator.
1369 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1371 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1373 mySelIter.Nullify();
1374 myCurrent.Nullify();
1375 myCurrentTrs.Nullify();
1376 if (!mySeq.IsEmpty())
1378 mySource = IterSource_List;
1379 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1381 else if (aCtx->NbSelected() > 0)
1383 mySource = IterSource_Selected;
1385 mySelIter->InitSelected();
1389 mySource = IterSource_All;
1390 myMapIter.Initialize (GetMapOfAIS());
1395 const TCollection_AsciiString& CurrentName() const
1397 return myCurrentName;
1400 const Handle(AIS_InteractiveObject)& Current() const
1405 const Handle(Standard_Transient)& CurrentTrs() const
1407 return myCurrentTrs;
1410 //! @return true if iterator points to valid object within collection
1411 Standard_Boolean More() const
1415 case IterSource_All: return myMapIter.More();
1416 case IterSource_List: return mySeqIter.More();
1417 case IterSource_Selected: return mySelIter->MoreSelected();
1419 return Standard_False;
1422 //! Go to the next item.
1425 myCurrentName.Clear();
1426 myCurrentTrs.Nullify();
1427 myCurrent.Nullify();
1430 case IterSource_All:
1435 case IterSource_List:
1440 case IterSource_Selected:
1442 mySelIter->NextSelected();
1455 case IterSource_All:
1457 if (myMapIter.More())
1459 myCurrentName = myMapIter.Key2();
1460 myCurrentTrs = myMapIter.Key1();
1461 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1465 case IterSource_List:
1467 if (mySeqIter.More())
1469 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1471 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1474 myCurrentName = mySeqIter.Value();
1475 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1476 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1480 case IterSource_Selected:
1482 if (mySelIter->MoreSelected())
1484 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1485 myCurrent = mySelIter->SelectedInteractive();
1503 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1504 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1505 NCollection_Sequence<TCollection_AsciiString> mySeq;
1506 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1508 TCollection_AsciiString myCurrentName;//!< current item name
1509 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1510 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1512 IterSource mySource; //!< iterated collection
1516 //==============================================================================
1517 //function : VInteriorStyle
1518 //purpose : sets interior style of the a selected or named or displayed shape
1519 //==============================================================================
1520 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1521 Standard_Integer theArgNb,
1522 const char** theArgVec)
1524 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1525 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1528 std::cerr << "Error: no active view!\n";
1532 Standard_Integer anArgIter = 1;
1533 for (; anArgIter < theArgNb; ++anArgIter)
1535 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1540 TCollection_AsciiString aName;
1541 if (theArgNb - anArgIter == 2)
1543 aName = theArgVec[anArgIter++];
1545 else if (theArgNb - anArgIter != 1)
1547 std::cout << "Error: wrong number of arguments! See usage:\n";
1548 theDI.PrintHelp (theArgVec[0]);
1551 Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
1552 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1553 aStyleArg.LowerCase();
1554 if (aStyleArg == "empty")
1556 anInterStyle = Aspect_IS_EMPTY;
1558 else if (aStyleArg == "hollow")
1560 anInterStyle = Aspect_IS_HOLLOW;
1562 else if (aStyleArg == "hatch")
1564 anInterStyle = Aspect_IS_HATCH;
1566 else if (aStyleArg == "solid")
1568 anInterStyle = Aspect_IS_SOLID;
1570 else if (aStyleArg == "hiddenline")
1572 anInterStyle = Aspect_IS_HIDDENLINE;
1574 else if (aStyleArg == "point")
1576 anInterStyle = Aspect_IS_POINT;
1580 const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
1581 if (anIntStyle < Aspect_IS_EMPTY
1582 || anIntStyle > Aspect_IS_POINT)
1584 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1585 << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
1588 anInterStyle = (Aspect_InteriorStyle )anIntStyle;
1591 if (!aName.IsEmpty()
1592 && !GetMapOfAIS().IsBound2 (aName))
1594 std::cout << "Error: object " << aName << " is not displayed!\n";
1598 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1600 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1603 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1604 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1605 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1606 aFillAspect->SetInteriorStyle (anInterStyle);
1607 if (anInterStyle == Aspect_IS_HATCH
1608 && aFillAspect->HatchStyle().IsNull())
1610 aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
1612 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1618 //! Auxiliary structure for VAspects
1619 struct ViewerTest_AspectsChangeSet
1621 Standard_Integer ToSetVisibility;
1622 Standard_Integer Visibility;
1624 Standard_Integer ToSetColor;
1625 Quantity_Color Color;
1627 Standard_Integer ToSetLineWidth;
1628 Standard_Real LineWidth;
1630 Standard_Integer ToSetTypeOfLine;
1631 Aspect_TypeOfLine TypeOfLine;
1633 Standard_Integer ToSetTypeOfMarker;
1634 Aspect_TypeOfMarker TypeOfMarker;
1635 Handle(Image_PixMap) MarkerImage;
1637 Standard_Integer ToSetMarkerSize;
1638 Standard_Real MarkerSize;
1640 Standard_Integer ToSetTransparency;
1641 Standard_Real Transparency;
1643 Standard_Integer ToSetMaterial;
1644 Graphic3d_NameOfMaterial Material;
1645 TCollection_AsciiString MatName;
1647 NCollection_Sequence<TopoDS_Shape> SubShapes;
1649 Standard_Integer ToSetShowFreeBoundary;
1650 Standard_Integer ToSetFreeBoundaryWidth;
1651 Standard_Real FreeBoundaryWidth;
1652 Standard_Integer ToSetFreeBoundaryColor;
1653 Quantity_Color FreeBoundaryColor;
1655 Standard_Integer ToEnableIsoOnTriangulation;
1657 Standard_Integer ToSetMaxParamValue;
1658 Standard_Real MaxParamValue;
1660 Standard_Integer ToSetSensitivity;
1661 Standard_Integer SelectionMode;
1662 Standard_Integer Sensitivity;
1664 Standard_Integer ToSetHatch;
1665 Standard_Integer StdHatchStyle;
1666 TCollection_AsciiString PathToHatchPattern;
1668 //! Empty constructor
1669 ViewerTest_AspectsChangeSet()
1670 : ToSetVisibility (0),
1673 Color (DEFAULT_COLOR),
1676 ToSetTypeOfLine (0),
1677 TypeOfLine (Aspect_TOL_SOLID),
1678 ToSetTypeOfMarker (0),
1679 TypeOfMarker (Aspect_TOM_PLUS),
1680 ToSetMarkerSize (0),
1682 ToSetTransparency (0),
1685 Material (Graphic3d_NOM_DEFAULT),
1686 ToSetShowFreeBoundary (0),
1687 ToSetFreeBoundaryWidth (0),
1688 FreeBoundaryWidth (1.0),
1689 ToSetFreeBoundaryColor (0),
1690 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1691 ToEnableIsoOnTriangulation (-1),
1692 ToSetMaxParamValue (0),
1693 MaxParamValue (500000),
1694 ToSetSensitivity (0),
1701 //! @return true if no changes have been requested
1702 Standard_Boolean IsEmpty() const
1704 return ToSetVisibility == 0
1705 && ToSetLineWidth == 0
1706 && ToSetTransparency == 0
1708 && ToSetMaterial == 0
1709 && ToSetShowFreeBoundary == 0
1710 && ToSetFreeBoundaryColor == 0
1711 && ToSetFreeBoundaryWidth == 0
1712 && ToSetMaxParamValue == 0
1713 && ToSetSensitivity == 0
1717 //! @return true if properties are valid
1718 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1720 Standard_Boolean isOk = Standard_True;
1721 if (Visibility != 0 && Visibility != 1)
1723 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1724 isOk = Standard_False;
1726 if (LineWidth <= 0.0
1727 || LineWidth > 10.0)
1729 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1730 isOk = Standard_False;
1732 if (Transparency < 0.0
1733 || Transparency > 1.0)
1735 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1736 isOk = Standard_False;
1739 && ToSetTransparency)
1741 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1742 isOk = Standard_False;
1744 if (ToSetMaterial == 1
1745 && Material == Graphic3d_NOM_DEFAULT)
1747 std::cout << "Error: unknown material " << MatName << ".\n";
1748 isOk = Standard_False;
1750 if (FreeBoundaryWidth <= 0.0
1751 || FreeBoundaryWidth > 10.0)
1753 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1754 isOk = Standard_False;
1756 if (MaxParamValue < 0.0)
1758 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1759 isOk = Standard_False;
1761 if (Sensitivity <= 0 && ToSetSensitivity)
1763 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1764 isOk = Standard_False;
1766 if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
1768 std::cout << "Error: hatch style must be specified\n";
1769 isOk = Standard_False;
1776 //==============================================================================
1777 //function : VAspects
1779 //==============================================================================
1780 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1781 Standard_Integer theArgNb,
1782 const char** theArgVec)
1784 TCollection_AsciiString aCmdName (theArgVec[0]);
1785 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1786 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1789 std::cerr << "Error: no active view!\n";
1793 Standard_Integer anArgIter = 1;
1794 Standard_Boolean isDefaults = Standard_False;
1795 NCollection_Sequence<TCollection_AsciiString> aNames;
1796 for (; anArgIter < theArgNb; ++anArgIter)
1798 TCollection_AsciiString anArg = theArgVec[anArgIter];
1799 if (anUpdateTool.parseRedrawMode (anArg))
1803 else if (!anArg.IsEmpty()
1804 && anArg.Value (1) != '-')
1806 aNames.Append (anArg);
1810 if (anArg == "-defaults")
1812 isDefaults = Standard_True;
1819 if (!aNames.IsEmpty() && isDefaults)
1821 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1825 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1826 aChanges.Append (ViewerTest_AspectsChangeSet());
1827 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1829 // parse syntax of legacy commands
1830 if (aCmdName == "vsetwidth")
1832 if (aNames.IsEmpty()
1833 || !aNames.Last().IsRealValue())
1835 std::cout << "Error: not enough arguments!\n";
1838 aChangeSet->ToSetLineWidth = 1;
1839 aChangeSet->LineWidth = aNames.Last().RealValue();
1840 aNames.Remove (aNames.Length());
1842 else if (aCmdName == "vunsetwidth")
1844 aChangeSet->ToSetLineWidth = -1;
1846 else if (aCmdName == "vsetcolor")
1848 if (aNames.IsEmpty())
1850 std::cout << "Error: not enough arguments!\n";
1853 aChangeSet->ToSetColor = 1;
1855 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1856 Standard_Boolean isOk = Standard_False;
1857 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1859 aChangeSet->Color = aColor;
1860 aNames.Remove (aNames.Length());
1861 isOk = Standard_True;
1863 else if (aNames.Length() >= 3)
1865 const TCollection_AsciiString anRgbStr[3] =
1867 aNames.Value (aNames.Upper() - 2),
1868 aNames.Value (aNames.Upper() - 1),
1869 aNames.Value (aNames.Upper() - 0)
1871 isOk = anRgbStr[0].IsRealValue()
1872 && anRgbStr[1].IsRealValue()
1873 && anRgbStr[2].IsRealValue();
1876 Graphic3d_Vec4d anRgb;
1877 anRgb.x() = anRgbStr[0].RealValue();
1878 anRgb.y() = anRgbStr[1].RealValue();
1879 anRgb.z() = anRgbStr[2].RealValue();
1880 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1881 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1882 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1884 std::cout << "Error: RGB color values should be within range 0..1!\n";
1887 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1888 aNames.Remove (aNames.Length());
1889 aNames.Remove (aNames.Length());
1890 aNames.Remove (aNames.Length());
1895 std::cout << "Error: not enough arguments!\n";
1899 else if (aCmdName == "vunsetcolor")
1901 aChangeSet->ToSetColor = -1;
1903 else if (aCmdName == "vsettransparency")
1905 if (aNames.IsEmpty()
1906 || !aNames.Last().IsRealValue())
1908 std::cout << "Error: not enough arguments!\n";
1911 aChangeSet->ToSetTransparency = 1;
1912 aChangeSet->Transparency = aNames.Last().RealValue();
1913 aNames.Remove (aNames.Length());
1915 else if (aCmdName == "vunsettransparency")
1917 aChangeSet->ToSetTransparency = -1;
1919 else if (aCmdName == "vsetmaterial")
1921 if (aNames.IsEmpty())
1923 std::cout << "Error: not enough arguments!\n";
1926 aChangeSet->ToSetMaterial = 1;
1927 aChangeSet->MatName = aNames.Last();
1928 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1929 aNames.Remove (aNames.Length());
1931 else if (aCmdName == "vunsetmaterial")
1933 aChangeSet->ToSetMaterial = -1;
1935 else if (anArgIter >= theArgNb)
1937 std::cout << "Error: not enough arguments!\n";
1941 if (!aChangeSet->IsEmpty())
1943 anArgIter = theArgNb;
1945 for (; anArgIter < theArgNb; ++anArgIter)
1947 TCollection_AsciiString anArg = theArgVec[anArgIter];
1949 if (anArg == "-setwidth"
1950 || anArg == "-setlinewidth")
1952 if (++anArgIter >= theArgNb)
1954 std::cout << "Error: wrong syntax at " << anArg << "\n";
1957 aChangeSet->ToSetLineWidth = 1;
1958 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1960 else if (anArg == "-unsetwidth"
1961 || anArg == "-unsetlinewidth")
1963 aChangeSet->ToSetLineWidth = -1;
1964 aChangeSet->LineWidth = 1.0;
1966 else if (anArg == "-settransp"
1967 || anArg == "-settransparency")
1969 if (++anArgIter >= theArgNb)
1971 std::cout << "Error: wrong syntax at " << anArg << "\n";
1974 aChangeSet->ToSetTransparency = 1;
1975 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1976 if (aChangeSet->Transparency >= 0.0
1977 && aChangeSet->Transparency <= Precision::Confusion())
1979 aChangeSet->ToSetTransparency = -1;
1980 aChangeSet->Transparency = 0.0;
1983 else if (anArg == "-setvis"
1984 || anArg == "-setvisibility")
1986 if (++anArgIter >= theArgNb)
1988 std::cout << "Error: wrong syntax at " << anArg << "\n";
1992 aChangeSet->ToSetVisibility = 1;
1993 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1995 else if (anArg == "-setalpha")
1997 if (++anArgIter >= theArgNb)
1999 std::cout << "Error: wrong syntax at " << anArg << "\n";
2002 aChangeSet->ToSetTransparency = 1;
2003 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
2004 if (aChangeSet->Transparency < 0.0
2005 || aChangeSet->Transparency > 1.0)
2007 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
2010 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
2011 if (aChangeSet->Transparency >= 0.0
2012 && aChangeSet->Transparency <= Precision::Confusion())
2014 aChangeSet->ToSetTransparency = -1;
2015 aChangeSet->Transparency = 0.0;
2018 else if (anArg == "-unsettransp"
2019 || anArg == "-unsettransparency"
2020 || anArg == "-unsetalpha"
2021 || anArg == "-opaque")
2023 aChangeSet->ToSetTransparency = -1;
2024 aChangeSet->Transparency = 0.0;
2026 else if (anArg == "-setcolor")
2028 Standard_Integer aNbComps = 0;
2029 Standard_Integer aCompIter = anArgIter + 1;
2030 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2032 if (theArgVec[aCompIter][0] == '-')
2041 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2042 Standard_CString aName = theArgVec[anArgIter + 1];
2043 if (!Quantity_Color::ColorFromName (aName, aColor))
2045 std::cout << "Error: unknown color name '" << aName << "'\n";
2048 aChangeSet->Color = aColor;
2053 Graphic3d_Vec3d anRgb;
2054 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2055 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2056 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2057 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2058 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2059 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2061 std::cout << "Error: RGB color values should be within range 0..1!\n";
2064 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2069 std::cout << "Error: wrong syntax at " << anArg << "\n";
2073 aChangeSet->ToSetColor = 1;
2074 anArgIter += aNbComps;
2076 else if (anArg == "-setlinetype")
2078 if (++anArgIter >= theArgNb)
2080 std::cout << "Error: wrong syntax at " << anArg << "\n";
2083 if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
2085 std::cout << "Error: wrong syntax at " << anArg << "\n";
2089 aChangeSet->ToSetTypeOfLine = 1;
2091 else if (anArg == "-unsetlinetype")
2093 aChangeSet->ToSetTypeOfLine = -1;
2095 else if (anArg == "-setmarkertype"
2096 || anArg == "-setpointtype")
2098 if (++anArgIter >= theArgNb)
2100 std::cout << "Error: wrong syntax at " << anArg << "\n";
2103 if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
2105 std::cout << "Error: wrong syntax at " << anArg << "\n";
2109 aChangeSet->ToSetTypeOfMarker = 1;
2111 else if (anArg == "-unsetmarkertype"
2112 || anArg == "-unsetpointtype")
2114 aChangeSet->ToSetTypeOfMarker = -1;
2116 else if (anArg == "-setmarkersize"
2117 || anArg == "-setpointsize")
2119 if (++anArgIter >= theArgNb)
2121 std::cout << "Error: wrong syntax at " << anArg << "\n";
2124 aChangeSet->ToSetMarkerSize = 1;
2125 aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
2127 else if (anArg == "-unsetmarkersize"
2128 || anArg == "-unsetpointsize")
2130 aChangeSet->ToSetMarkerSize = -1;
2131 aChangeSet->MarkerSize = 1.0;
2133 else if (anArg == "-unsetcolor")
2135 aChangeSet->ToSetColor = -1;
2136 aChangeSet->Color = DEFAULT_COLOR;
2138 else if (anArg == "-setmat"
2139 || anArg == "-setmaterial")
2141 if (++anArgIter >= theArgNb)
2143 std::cout << "Error: wrong syntax at " << anArg << "\n";
2146 aChangeSet->ToSetMaterial = 1;
2147 aChangeSet->MatName = theArgVec[anArgIter];
2148 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
2150 else if (anArg == "-unsetmat"
2151 || anArg == "-unsetmaterial")
2153 aChangeSet->ToSetMaterial = -1;
2154 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2156 else if (anArg == "-subshape"
2157 || anArg == "-subshapes")
2161 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
2165 if (aNames.IsEmpty())
2167 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
2171 aChanges.Append (ViewerTest_AspectsChangeSet());
2172 aChangeSet = &aChanges.ChangeLast();
2174 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
2176 Standard_CString aSubShapeName = theArgVec[anArgIter];
2177 if (*aSubShapeName == '-')
2183 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
2184 if (aSubShape.IsNull())
2186 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
2189 aChangeSet->SubShapes.Append (aSubShape);
2192 if (aChangeSet->SubShapes.IsEmpty())
2194 std::cerr << "Error: empty list is specified after -subshapes!\n";
2198 else if (anArg == "-freeboundary"
2201 if (++anArgIter >= theArgNb)
2203 std::cout << "Error: wrong syntax at " << anArg << "\n";
2206 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2211 aChangeSet->ToSetShowFreeBoundary = 1;
2213 else if (aValue == "off"
2216 aChangeSet->ToSetShowFreeBoundary = -1;
2220 std::cout << "Error: wrong syntax at " << anArg << "\n";
2224 else if (anArg == "-setfreeboundarywidth"
2225 || anArg == "-setfbwidth")
2227 if (++anArgIter >= theArgNb)
2229 std::cout << "Error: wrong syntax at " << anArg << "\n";
2232 aChangeSet->ToSetFreeBoundaryWidth = 1;
2233 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2235 else if (anArg == "-unsetfreeboundarywidth"
2236 || anArg == "-unsetfbwidth")
2238 aChangeSet->ToSetFreeBoundaryWidth = -1;
2239 aChangeSet->FreeBoundaryWidth = 1.0;
2241 else if (anArg == "-setfreeboundarycolor"
2242 || anArg == "-setfbcolor")
2244 Standard_Integer aNbComps = 0;
2245 Standard_Integer aCompIter = anArgIter + 1;
2246 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2248 if (theArgVec[aCompIter][0] == '-')
2257 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2258 Standard_CString aName = theArgVec[anArgIter + 1];
2259 if (!Quantity_Color::ColorFromName (aName, aColor))
2261 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2264 aChangeSet->FreeBoundaryColor = aColor;
2269 Graphic3d_Vec3d anRgb;
2270 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2271 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2272 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2273 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2274 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2275 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2277 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2280 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2285 std::cout << "Error: wrong syntax at " << anArg << "\n";
2289 aChangeSet->ToSetFreeBoundaryColor = 1;
2290 anArgIter += aNbComps;
2292 else if (anArg == "-unsetfreeboundarycolor"
2293 || anArg == "-unsetfbcolor")
2295 aChangeSet->ToSetFreeBoundaryColor = -1;
2296 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2298 else if (anArg == "-unset")
2300 aChangeSet->ToSetVisibility = 1;
2301 aChangeSet->Visibility = 1;
2302 aChangeSet->ToSetLineWidth = -1;
2303 aChangeSet->LineWidth = 1.0;
2304 aChangeSet->ToSetTypeOfLine = -1;
2305 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
2306 aChangeSet->ToSetTypeOfMarker = -1;
2307 aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
2308 aChangeSet->ToSetMarkerSize = -1;
2309 aChangeSet->MarkerSize = 1.0;
2310 aChangeSet->ToSetTransparency = -1;
2311 aChangeSet->Transparency = 0.0;
2312 aChangeSet->ToSetColor = -1;
2313 aChangeSet->Color = DEFAULT_COLOR;
2314 aChangeSet->ToSetMaterial = -1;
2315 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
2316 aChangeSet->ToSetShowFreeBoundary = -1;
2317 aChangeSet->ToSetFreeBoundaryColor = -1;
2318 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2319 aChangeSet->ToSetFreeBoundaryWidth = -1;
2320 aChangeSet->FreeBoundaryWidth = 1.0;
2321 aChangeSet->ToSetHatch = -1;
2322 aChangeSet->StdHatchStyle = -1;
2323 aChangeSet->PathToHatchPattern.Clear();
2325 else if (anArg == "-isoontriangulation"
2326 || anArg == "-isoontriang")
2328 if (++anArgIter >= theArgNb)
2330 std::cout << "Error: wrong syntax at " << anArg << "\n";
2333 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2338 aChangeSet->ToEnableIsoOnTriangulation = 1;
2340 else if (aValue == "off"
2343 aChangeSet->ToEnableIsoOnTriangulation = 0;
2347 std::cout << "Error: wrong syntax at " << anArg << "\n";
2351 else if (anArg == "-setmaxparamvalue")
2353 if (++anArgIter >= theArgNb)
2355 std::cout << "Error: wrong syntax at " << anArg << "\n";
2358 aChangeSet->ToSetMaxParamValue = 1;
2359 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2361 else if (anArg == "-setsensitivity")
2365 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2369 if (aNames.IsEmpty())
2371 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2375 if (anArgIter + 2 >= theArgNb)
2377 std::cout << "Error: wrong syntax at " << anArg << "\n";
2380 aChangeSet->ToSetSensitivity = 1;
2381 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2382 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2384 else if (anArg == "-sethatch")
2388 std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
2392 if (aNames.IsEmpty())
2394 std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
2398 aChangeSet->ToSetHatch = 1;
2399 TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
2400 if (anArgHatch.Length() <= 2)
2402 const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
2404 || anIntStyle >= Aspect_HS_NB)
2406 std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
2409 aChangeSet->StdHatchStyle = anIntStyle;
2413 aChangeSet->PathToHatchPattern = anArgHatch;
2418 std::cout << "Error: wrong syntax at " << anArg << "\n";
2423 Standard_Boolean isFirst = Standard_True;
2424 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2425 aChangesIter.More(); aChangesIter.Next())
2427 if (!aChangesIter.Value().Validate (!isFirst))
2431 isFirst = Standard_False;
2434 // special case for -defaults parameter.
2435 // all changed values will be set to DefaultDrawer.
2438 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2440 if (aChangeSet->ToSetLineWidth != 0)
2442 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2443 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2444 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2445 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2447 if (aChangeSet->ToSetColor != 0)
2449 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2450 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2451 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2452 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2453 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2454 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2456 if (aChangeSet->ToSetTypeOfLine != 0)
2458 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2459 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2460 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2461 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2462 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2464 if (aChangeSet->ToSetTypeOfMarker != 0)
2466 aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2467 aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2468 ? Handle(Graphic3d_MarkerImage)()
2469 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2471 if (aChangeSet->ToSetMarkerSize != 0)
2473 aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
2475 if (aChangeSet->ToSetTransparency != 0)
2477 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2479 if (aChangeSet->ToSetMaterial != 0)
2481 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2483 if (aChangeSet->ToSetShowFreeBoundary == 1)
2485 aDrawer->SetFreeBoundaryDraw (Standard_True);
2487 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2489 aDrawer->SetFreeBoundaryDraw (Standard_False);
2491 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2493 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2495 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2497 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2499 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2501 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2503 if (aChangeSet->ToSetMaxParamValue != 0)
2505 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2508 // redisplay all objects in context
2509 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2511 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2514 aCtx->Redisplay (aPrs, Standard_False);
2520 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2522 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2523 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2524 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2525 Handle(AIS_ColoredShape) aColoredPrs;
2526 Standard_Boolean toDisplay = Standard_False;
2527 Standard_Boolean toRedisplay = Standard_False;
2528 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2530 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2531 if (aShapePrs.IsNull())
2533 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2536 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2537 if (aColoredPrs.IsNull())
2539 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2540 if (aShapePrs->HasDisplayMode())
2542 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2544 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
2545 aCtx->Remove (aShapePrs, Standard_False);
2546 GetMapOfAIS().UnBind2 (aName);
2547 GetMapOfAIS().Bind (aColoredPrs, aName);
2548 toDisplay = Standard_True;
2549 aShapePrs = aColoredPrs;
2556 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2557 aChangeSet = &aChangesIter.ChangeValue();
2558 if (aChangeSet->ToSetVisibility == 1)
2560 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2561 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2563 else if (aChangeSet->ToSetMaterial == 1)
2565 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2567 else if (aChangeSet->ToSetMaterial == -1)
2569 aCtx->UnsetMaterial (aPrs, Standard_False);
2571 if (aChangeSet->ToSetColor == 1)
2573 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2575 else if (aChangeSet->ToSetColor == -1)
2577 aCtx->UnsetColor (aPrs, Standard_False);
2579 if (aChangeSet->ToSetTransparency == 1)
2581 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2583 else if (aChangeSet->ToSetTransparency == -1)
2585 aCtx->UnsetTransparency (aPrs, Standard_False);
2587 if (aChangeSet->ToSetLineWidth == 1)
2589 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2591 else if (aChangeSet->ToSetLineWidth == -1)
2593 aCtx->UnsetWidth (aPrs, Standard_False);
2595 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2597 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2598 toRedisplay = Standard_True;
2600 else if (aChangeSet->ToSetSensitivity != 0)
2602 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2604 if (!aDrawer.IsNull())
2606 if (aChangeSet->ToSetShowFreeBoundary == 1)
2608 aDrawer->SetFreeBoundaryDraw (Standard_True);
2609 toRedisplay = Standard_True;
2611 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2613 aDrawer->SetFreeBoundaryDraw (Standard_False);
2614 toRedisplay = Standard_True;
2616 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2618 Handle(Prs3d_LineAspect) aBoundaryAspect =
2619 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2620 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2621 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2622 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2623 toRedisplay = Standard_True;
2625 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2627 Handle(Prs3d_LineAspect) aBoundaryAspect =
2628 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2629 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2630 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2631 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2632 toRedisplay = Standard_True;
2634 if (aChangeSet->ToSetTypeOfLine != 0)
2636 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2637 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2638 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2639 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2640 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2641 toRedisplay = Standard_True;
2643 if (aChangeSet->ToSetTypeOfMarker != 0)
2645 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2646 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2647 aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
2648 aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
2649 ? Handle(Graphic3d_MarkerImage)()
2650 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
2651 aDrawer->SetPointAspect (aMarkerAspect);
2652 toRedisplay = Standard_True;
2654 if (aChangeSet->ToSetMarkerSize != 0)
2656 Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
2657 *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
2658 aMarkerAspect->SetScale (aChangeSet->MarkerSize);
2659 aDrawer->SetPointAspect (aMarkerAspect);
2660 toRedisplay = Standard_True;
2662 if (aChangeSet->ToSetMaxParamValue != 0)
2664 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2666 if (aChangeSet->ToSetHatch != 0)
2668 if (!aDrawer->HasOwnShadingAspect())
2670 aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
2671 *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
2674 Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
2675 if (aChangeSet->ToSetHatch == -1)
2677 anAsp->SetInteriorStyle (Aspect_IS_SOLID);
2681 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
2682 if (!aChangeSet->PathToHatchPattern.IsEmpty())
2684 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
2685 if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
2687 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
2691 std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
2695 else if (aChangeSet->StdHatchStyle != -1)
2697 anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
2700 toRedisplay = Standard_True;
2704 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2706 aChangeSet = &aChangesIter.ChangeValue();
2707 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2708 aSubShapeIter.More(); aSubShapeIter.Next())
2710 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2711 if (aChangeSet->ToSetVisibility == 1)
2713 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2714 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2716 if (aChangeSet->ToSetColor == 1)
2718 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2720 if (aChangeSet->ToSetLineWidth == 1)
2722 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2724 if (aChangeSet->ToSetColor == -1
2725 || aChangeSet->ToSetLineWidth == -1)
2727 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2729 if (aChangeSet->ToSetMaxParamValue != 0)
2731 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2732 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2734 if (aChangeSet->ToSetSensitivity != 0)
2736 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2742 aCtx->Display (aPrs, Standard_False);
2746 aCtx->Redisplay (aPrs, Standard_False);
2748 else if (!aColoredPrs.IsNull())
2750 aCtx->Redisplay (aColoredPrs, Standard_False);
2757 //==============================================================================
2758 //function : VDonly2
2760 //purpose : Display only a selected or named object
2761 // if there is no selected or named object s, nothing is done
2762 //==============================================================================
2763 static int VDonly2 (Draw_Interpretor& ,
2764 Standard_Integer theArgNb,
2765 const char** theArgVec)
2767 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2768 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2771 std::cerr << "Error: no active view!\n";
2775 Standard_DISABLE_DEPRECATION_WARNINGS
2776 if (aCtx->HasOpenedContext())
2778 aCtx->CloseLocalContext();
2780 Standard_ENABLE_DEPRECATION_WARNINGS
2782 Standard_Integer anArgIter = 1;
2783 for (; anArgIter < theArgNb; ++anArgIter)
2785 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2791 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2792 if (anArgIter >= theArgNb)
2794 // display only selected objects
2795 if (aCtx->NbSelected() < 1)
2800 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
2802 aDispSet.Add (aCtx->SelectedInteractive());
2807 // display only specified objects
2808 for (; anArgIter < theArgNb; ++anArgIter)
2810 TCollection_AsciiString aName = theArgVec[anArgIter];
2811 if (GetMapOfAIS().IsBound2 (aName))
2813 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2814 if (!aShape.IsNull())
2816 aCtx->Display (aShape, Standard_False);
2817 aDispSet.Add (aShape);
2823 // weed out other objects
2824 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2826 if (aDispSet.Contains (anIter.Key1()))
2831 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2832 if (aShape.IsNull())
2834 aCtx->Erase (aShape, Standard_False);
2840 //==============================================================================
2841 //function : VRemove
2842 //purpose : Removes selected or named objects.
2843 // If there is no selected or named objects,
2844 // all objects in the viewer can be removed with argument -all.
2845 // If -context is in arguments, the object is not deleted from the map of
2846 // objects (deleted only from the current context).
2847 //==============================================================================
2848 int VRemove (Draw_Interpretor& theDI,
2849 Standard_Integer theArgNb,
2850 const char** theArgVec)
2852 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2853 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2856 std::cerr << "Error: no active view!\n";
2860 Standard_Boolean isContextOnly = Standard_False;
2861 Standard_Boolean toRemoveAll = Standard_False;
2862 Standard_Boolean toPrintInfo = Standard_True;
2863 Standard_Boolean toRemoveLocal = Standard_False;
2865 Standard_Integer anArgIter = 1;
2866 for (; anArgIter < theArgNb; ++anArgIter)
2868 TCollection_AsciiString anArg = theArgVec[anArgIter];
2870 if (anArg == "-context")
2872 isContextOnly = Standard_True;
2874 else if (anArg == "-all")
2876 toRemoveAll = Standard_True;
2878 else if (anArg == "-noinfo")
2880 toPrintInfo = Standard_False;
2882 else if (anArg == "-local")
2884 toRemoveLocal = Standard_True;
2886 else if (anUpdateTool.parseRedrawMode (anArg))
2896 && anArgIter < theArgNb)
2898 std::cerr << "Error: wrong syntax!\n";
2902 Standard_DISABLE_DEPRECATION_WARNINGS
2903 if (toRemoveLocal && !aCtx->HasOpenedContext())
2905 std::cerr << "Error: local selection context is not open.\n";
2908 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2910 aCtx->CloseAllContexts (Standard_False);
2912 Standard_ENABLE_DEPRECATION_WARNINGS
2914 NCollection_List<TCollection_AsciiString> anIONameList;
2917 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2918 anIter.More(); anIter.Next())
2920 anIONameList.Append (anIter.Key2());
2923 else if (anArgIter < theArgNb) // removed objects names are in argument list
2925 for (; anArgIter < theArgNb; ++anArgIter)
2927 TCollection_AsciiString aName = theArgVec[anArgIter];
2928 if (!GetMapOfAIS().IsBound2 (aName))
2930 theDI << aName.ToCString() << " was not bound to some object.\n";
2934 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2935 if (anIO->GetContext() != aCtx)
2937 theDI << aName.ToCString() << " was not displayed in current context.\n";
2938 theDI << "Please activate view with this object displayed and try again.\n";
2942 anIONameList.Append (aName);
2946 else if (aCtx->NbSelected() > 0)
2948 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2949 anIter.More(); anIter.Next())
2951 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2952 if (!aCtx->IsSelected (anIO))
2957 anIONameList.Append (anIter.Key2());
2962 // Unbind all removed objects from the map of displayed IO.
2963 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2964 anIter.More(); anIter.Next())
2966 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2967 aCtx->Remove (anIO, Standard_False);
2970 theDI << anIter.Value().ToCString() << " was removed\n";
2974 GetMapOfAIS().UnBind2 (anIter.Value());
2978 // Close local context if it is empty
2979 TColStd_MapOfTransient aLocalIO;
2980 Standard_DISABLE_DEPRECATION_WARNINGS
2981 if (aCtx->HasOpenedContext()
2982 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2984 aCtx->CloseAllContexts (Standard_False);
2986 Standard_ENABLE_DEPRECATION_WARNINGS
2991 //==============================================================================
2993 //purpose : Erase some selected or named objects
2994 // if there is no selected or named objects, the whole viewer is erased
2995 //==============================================================================
2996 int VErase (Draw_Interpretor& theDI,
2997 Standard_Integer theArgNb,
2998 const char** theArgVec)
3000 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3001 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
3002 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
3005 std::cerr << "Error: no active view!\n";
3009 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
3011 Standard_Integer anArgIter = 1;
3012 Standard_Boolean toEraseLocal = Standard_False;
3013 Standard_Boolean toEraseInView = Standard_False;
3014 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
3015 for (; anArgIter < theArgNb; ++anArgIter)
3017 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3018 anArgCase.LowerCase();
3019 if (anUpdateTool.parseRedrawMode (anArgCase))
3023 else if (anArgCase == "-local")
3025 toEraseLocal = Standard_True;
3027 else if (anArgCase == "-view"
3028 || anArgCase == "-inview")
3030 toEraseInView = Standard_True;
3034 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
3038 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
3040 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
3044 Standard_DISABLE_DEPRECATION_WARNINGS
3045 if (toEraseLocal && !aCtx->HasOpenedContext())
3047 std::cerr << "Error: local selection context is not open.\n";
3050 else if (!toEraseLocal && aCtx->HasOpenedContext())
3052 aCtx->CloseAllContexts (Standard_False);
3054 Standard_ENABLE_DEPRECATION_WARNINGS
3056 if (!aNamesOfEraseIO.IsEmpty())
3058 // Erase named objects
3059 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
3061 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
3062 if (!GetMapOfAIS().IsBound2 (aName))
3067 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3068 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
3069 theDI << aName.ToCString() << " ";
3074 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3078 aCtx->Erase (anIO, Standard_False);
3083 else if (!toEraseAll && aCtx->NbSelected() > 0)
3085 // Erase selected objects
3086 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
3087 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3088 anIter.More(); anIter.Next())
3090 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3092 && aCtx->IsSelected (anIO))
3094 theDI << anIter.Key2().ToCString() << " ";
3097 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3099 else if (aHasOpenedContext)
3101 aCtx->Erase (anIO, Standard_False);
3108 aCtx->EraseSelected (Standard_False);
3113 // Erase all objects
3114 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3115 anIter.More(); anIter.Next())
3117 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3122 aCtx->SetViewAffinity (anIO, aView, Standard_False);
3126 aCtx->Erase (anIO, Standard_False);
3135 //==============================================================================
3136 //function : VDisplayAll
3138 //purpose : Display all the objects of the Map
3139 //==============================================================================
3140 static int VDisplayAll (Draw_Interpretor& ,
3141 Standard_Integer theArgNb,
3142 const char** theArgVec)
3145 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3146 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3149 std::cerr << "Error: no active view!\n";
3153 Standard_Integer anArgIter = 1;
3154 Standard_Boolean toDisplayLocal = Standard_False;
3155 for (; anArgIter < theArgNb; ++anArgIter)
3157 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
3158 anArgCase.LowerCase();
3159 if (anArgCase == "-local")
3161 toDisplayLocal = Standard_True;
3163 else if (anUpdateTool.parseRedrawMode (anArgCase))
3172 if (anArgIter < theArgNb)
3174 std::cout << theArgVec[0] << "Error: wrong syntax\n";
3178 Standard_DISABLE_DEPRECATION_WARNINGS
3179 if (toDisplayLocal && !aCtx->HasOpenedContext())
3181 std::cerr << "Error: local selection context is not open.\n";
3184 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3186 aCtx->CloseLocalContext (Standard_False);
3188 Standard_ENABLE_DEPRECATION_WARNINGS
3190 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3191 anIter.More(); anIter.Next())
3193 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3194 aCtx->Erase (aShape, Standard_False);
3197 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3198 anIter.More(); anIter.Next())
3200 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3201 aCtx->Display (aShape, Standard_False);
3206 //! Auxiliary method to check if presentation exists
3207 inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
3208 const Handle(AIS_InteractiveObject)& theIO,
3209 const Standard_Integer theMode)
3211 if (theIO.IsNull() || theCtx.IsNull())
3218 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
3223 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
3225 return theIO->DisplayMode();
3227 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
3229 return theCtx->DisplayMode();
3235 enum ViewerTest_BndAction
3242 //! Auxiliary method to print bounding box of presentation
3243 inline void bndPresentation (Draw_Interpretor& theDI,
3244 const Handle(PrsMgr_PresentationManager)& theMgr,
3245 const Handle(AIS_InteractiveObject)& theObj,
3246 const Standard_Integer theDispMode,
3247 const TCollection_AsciiString& theName,
3248 const ViewerTest_BndAction theAction,
3249 const Handle(Prs3d_Drawer)& theStyle)
3253 case BndAction_Hide:
3255 theMgr->Unhighlight (theObj);
3258 case BndAction_Show:
3260 theMgr->Color (theObj, theStyle, theDispMode);
3263 case BndAction_Print:
3266 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
3268 if (aPrsIter.Value().Mode() != theDispMode)
3271 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
3273 gp_Pnt aMin = aBox.CornerMin();
3274 gp_Pnt aMax = aBox.CornerMax();
3275 theDI << theName << "\n"
3276 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
3277 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
3283 //==============================================================================
3284 //function : VBounding
3286 //==============================================================================
3287 int VBounding (Draw_Interpretor& theDI,
3288 Standard_Integer theArgNb,
3289 const char** theArgVec)
3291 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3292 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3295 std::cout << "Error: no active view!\n";
3299 ViewerTest_BndAction anAction = BndAction_Show;
3300 Standard_Integer aMode = -1;
3302 Handle(Prs3d_Drawer) aStyle;
3304 Standard_Integer anArgIter = 1;
3305 for (; anArgIter < theArgNb; ++anArgIter)
3307 TCollection_AsciiString anArg (theArgVec[anArgIter]);
3309 if (anArg == "-print")
3311 anAction = BndAction_Print;
3313 else if (anArg == "-show")
3315 anAction = BndAction_Show;
3317 else if (anArg == "-hide")
3319 anAction = BndAction_Hide;
3321 else if (anArg == "-mode")
3323 if (++anArgIter >= theArgNb)
3325 std::cout << "Error: wrong syntax at " << anArg << "\n";
3328 aMode = Draw::Atoi (theArgVec[anArgIter]);
3330 else if (!anUpdateTool.parseRedrawMode (anArg))
3336 if (anAction == BndAction_Show)
3338 aStyle = new Prs3d_Drawer();
3339 aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
3340 aStyle->SetColor (Quantity_NOC_GRAY99);
3343 Standard_Integer aHighlightedMode = -1;
3344 if (anArgIter < theArgNb)
3346 // has a list of names
3347 for (; anArgIter < theArgNb; ++anArgIter)
3349 TCollection_AsciiString aName = theArgVec[anArgIter];
3350 if (!GetMapOfAIS().IsBound2 (aName))
3352 std::cout << "Error: presentation " << aName << " does not exist\n";
3356 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3357 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3358 if (aHighlightedMode == -1)
3360 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
3363 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
3366 else if (aCtx->NbSelected() > 0)
3368 // remove all currently selected objects
3369 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
3371 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
3372 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3373 if (aHighlightedMode != -1)
3375 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3376 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
3383 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3384 anIter.More(); anIter.Next())
3386 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3387 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3388 if (aHighlightedMode != -1)
3390 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
3397 //==============================================================================
3398 //function : VTexture
3400 //==============================================================================
3401 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
3403 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
3406 std::cout << "Error: no active view!\n";
3410 int toModulate = -1;
3411 bool toSetFilter = false;
3412 bool toSetAniso = false;
3413 bool toSetTrsfAngle = false;
3414 bool toSetTrsfTrans = false;
3415 bool toSetTrsfScale = false;
3416 Standard_ShortReal aTrsfRotAngle = 0.0f;
3417 Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
3418 Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
3419 Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
3420 Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
3422 Handle(AIS_Shape) aTexturedIO;
3423 Handle(Graphic3d_TextureSet) aTextureSetOld;
3424 NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
3425 bool toSetGenRepeat = false;
3426 bool toSetGenScale = false;
3427 bool toSetGenOrigin = false;
3428 bool toSetImage = false;
3429 bool toComputeUV = false;
3431 const TCollection_AsciiString aCommandName (theArgVec[0]);
3432 bool toSetDefaults = aCommandName == "vtexdefault";
3434 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3435 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
3437 const TCollection_AsciiString aName = theArgVec[anArgIter];
3438 TCollection_AsciiString aNameCase = aName;
3439 aNameCase.LowerCase();
3440 if (anUpdateTool.parseRedrawMode (aName))
3444 else if (aTexturedIO.IsNull())
3446 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3447 if (aMapOfIO.IsBound2 (aName))
3449 aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
3451 if (aTexturedIO.IsNull())
3453 std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
3457 if (aTexturedIO->Attributes()->HasOwnShadingAspect())
3459 aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
3462 else if (aNameCase == "-scale"
3463 || aNameCase == "-setscale"
3464 || aCommandName == "vtexscale")
3466 if (aCommandName != "vtexscale")
3470 if (anArgIter < theArgsNb)
3472 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3473 TCollection_AsciiString aValUCase = aValU;
3474 aValUCase.LowerCase();
3475 toSetGenScale = true;
3476 if (aValUCase == "off")
3478 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3481 else if (anArgIter + 1 < theArgsNb)
3483 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3484 if (aValU.IsRealValue()
3485 && aValV.IsRealValue())
3487 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3493 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3496 else if (aNameCase == "-origin"
3497 || aNameCase == "-setorigin"
3498 || aCommandName == "vtexorigin")
3500 if (aCommandName != "vtexorigin")
3504 if (anArgIter < theArgsNb)
3506 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3507 TCollection_AsciiString aValUCase = aValU;
3508 aValUCase.LowerCase();
3509 toSetGenOrigin = true;
3510 if (aValUCase == "off")
3512 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3515 else if (anArgIter + 1 < theArgsNb)
3517 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3518 if (aValU.IsRealValue()
3519 && aValV.IsRealValue())
3521 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3527 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3530 else if (aNameCase == "-repeat"
3531 || aNameCase == "-setrepeat"
3532 || aCommandName == "vtexrepeat")
3534 if (aCommandName != "vtexrepeat")
3538 if (anArgIter < theArgsNb)
3540 TCollection_AsciiString aValU (theArgVec[anArgIter]);
3541 TCollection_AsciiString aValUCase = aValU;
3542 aValUCase.LowerCase();
3543 toSetGenRepeat = true;
3544 if (aValUCase == "off")
3546 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3549 else if (anArgIter + 1 < theArgsNb)
3551 TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
3552 if (aValU.IsRealValue()
3553 && aValV.IsRealValue())
3555 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
3561 std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
3564 else if (aNameCase == "-modulate")
3566 bool toModulateBool = true;
3567 if (anArgIter + 1 < theArgsNb
3568 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
3572 toModulate = toModulateBool ? 1 : 0;
3574 else if ((aNameCase == "-setfilter"
3575 || aNameCase == "-filter")
3576 && anArgIter + 1 < theArgsNb)
3578 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3582 if (aValue == "nearest")
3584 aFilter = Graphic3d_TOTF_NEAREST;
3586 else if (aValue == "bilinear")
3588 aFilter = Graphic3d_TOTF_BILINEAR;
3590 else if (aValue == "trilinear")
3592 aFilter = Graphic3d_TOTF_TRILINEAR;
3596 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3600 else if ((aNameCase == "-setaniso"
3601 || aNameCase == "-setanisofilter"
3602 || aNameCase == "-aniso"
3603 || aNameCase == "-anisofilter")
3604 && anArgIter + 1 < theArgsNb)
3606 TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
3610 if (aValue == "off")
3612 anAnisoFilter = Graphic3d_LOTA_OFF;
3614 else if (aValue == "fast")
3616 anAnisoFilter = Graphic3d_LOTA_FAST;
3618 else if (aValue == "middle")
3620 anAnisoFilter = Graphic3d_LOTA_MIDDLE;
3622 else if (aValue == "quality"
3623 || aValue == "high")
3625 anAnisoFilter = Graphic3d_LOTA_QUALITY;
3629 std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
3633 else if ((aNameCase == "-rotateangle"
3634 || aNameCase == "-rotangle"
3635 || aNameCase == "-rotate"
3636 || aNameCase == "-angle"
3637 || aNameCase == "-trsfangle")
3638 && anArgIter + 1 < theArgsNb)
3640 aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3641 toSetTrsfAngle = true;
3644 else if ((aNameCase == "-trsftrans"
3645 || aNameCase == "-trsftranslate"
3646 || aNameCase == "-translate"
3647 || aNameCase == "-translation")
3648 && anArgIter + 2 < theArgsNb)
3650 aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3651 aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3652 toSetTrsfTrans = true;
3655 else if ((aNameCase == "-trsfscale")
3656 && anArgIter + 2 < theArgsNb)
3658 aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
3659 aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
3660 toSetTrsfScale = true;
3663 else if (aNameCase == "-default"
3664 || aNameCase == "-defaults")
3666 toSetDefaults = true;
3668 else if (aCommandName == "vtexture"
3669 && (aTextureVecNew.IsEmpty()
3670 || aNameCase.StartsWith ("-tex")))
3672 Standard_Integer aTexIndex = 0;
3673 TCollection_AsciiString aTexName = aName;
3674 if (aNameCase.StartsWith ("-tex"))
3676 if (anArgIter + 1 >= theArgsNb
3677 || aNameCase.Length() < 5)
3679 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3683 TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
3684 if (!aTexIndexStr.IsIntegerValue())
3686 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3690 aTexIndex = aTexIndexStr.IntegerValue();
3691 aTexName = theArgVec[anArgIter + 1];
3694 if (aTexIndex >= Graphic3d_TextureUnit_NB
3695 || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
3697 std::cout << "Error: too many textures specified\n";
3702 if (aTexName.IsIntegerValue())
3704 const Standard_Integer aValue = aTexName.IntegerValue();
3705 if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
3707 std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
3710 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
3712 else if (aTexName == "?")
3714 const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3716 theDi << "\n Files in current directory : \n\n";
3717 theDi.Eval ("glob -nocomplain *");
3719 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3720 aCmnd += aTextureFolder;
3723 theDi << "Files in " << aTextureFolder << " : \n\n";
3724 theDi.Eval (aCmnd.ToCString());
3727 else if (aTexName != "off")
3729 if (!OSD_File (aTexName).Exists())
3731 std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
3734 aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
3738 aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
3740 aTextureVecNew.ChangeValue (aTexIndex)->GetParams()->SetTextureUnit ((Graphic3d_TextureUnit )aTexIndex);
3744 std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
3751 // check if new image set is equal to already set one
3752 Standard_Integer aNbChanged = 0;
3753 Handle(Graphic3d_TextureSet) aTextureSetNew;
3754 if (!aTextureVecNew.IsEmpty())
3756 aNbChanged = aTextureVecNew.Size();
3757 aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
3758 for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
3760 Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
3761 Handle(Graphic3d_TextureRoot) aTextureOld;
3762 if (!aTextureSetOld.IsNull()
3763 && aTexIter < aTextureSetOld->Size())
3765 aTextureOld = aTextureSetOld->Value (aTexIter);
3768 if (!aTextureOld.IsNull()
3769 && !aTextureNew.IsNull())
3771 *aTextureNew->GetParams() = *aTextureOld->GetParams();
3772 if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
3774 TCollection_AsciiString aFilePathOld, aFilePathNew;
3775 aTextureOld->Path().SystemName (aFilePathOld);
3776 aTextureNew->Path().SystemName (aFilePathNew);
3777 if (aTextureNew->Name() == anOldManualTex->Name()
3778 && aFilePathOld == aFilePathNew
3779 && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
3782 aTextureNew = anOldManualTex;
3786 aTextureSetNew->SetValue (aTexIter, aTextureNew);
3790 && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
3791 || (aTextureSetOld->Size() == aTextureSetNew->Size())))
3793 aTextureSetNew = aTextureSetOld;
3796 if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
3798 aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
3799 *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
3802 toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
3803 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
3804 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
3805 aTextureSetOld.Nullify();
3810 if (toModulate != -1)
3817 aFilter = Graphic3d_TOTF_BILINEAR;
3822 anAnisoFilter = Graphic3d_LOTA_OFF;
3824 if (!toSetTrsfAngle)
3826 toSetTrsfAngle = true;
3827 aTrsfRotAngle = 0.0f;
3829 if (!toSetTrsfTrans)
3831 toSetTrsfTrans = true;
3832 aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
3834 if (!toSetTrsfScale)
3836 toSetTrsfScale = true;
3837 aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
3841 if (aCommandName == "vtexture"
3844 if (!aTextureSetOld.IsNull())
3846 //toComputeUV = true; // we can keep UV vertex attributes
3847 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
3848 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
3849 aTextureSetOld.Nullify();
3853 if (aTexturedIO->Attributes()->HasOwnShadingAspect()
3854 && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
3856 if (toModulate != -1)
3858 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
3862 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
3866 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
3870 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
3874 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
3878 aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
3882 // set default values if requested
3884 && (aCommandName == "vtexrepeat"
3887 aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
3888 toSetGenRepeat = true;
3891 && (aCommandName == "vtexorigin"
3894 aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
3895 toSetGenOrigin = true;
3898 && (aCommandName == "vtexscale"
3901 aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
3902 toSetGenScale = true;
3905 if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
3907 aTexturedIO->SetToUpdate (AIS_Shaded);
3910 if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
3911 || aCtx->DisplayMode() != AIS_Shaded)
3913 aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
3917 aCtx->Display (aTexturedIO, false);
3918 aTexturedIO->SynchronizeAspects();
3922 //! Auxiliary method to parse transformation persistence flags
3923 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3924 Graphic3d_TransModeFlags& theFlags)
3926 if (theFlagString == "zoom")
3928 theFlags = Graphic3d_TMF_ZoomPers;
3930 else if (theFlagString == "rotate")
3932 theFlags = Graphic3d_TMF_RotatePers;
3934 else if (theFlagString == "zoomrotate")
3936 theFlags = Graphic3d_TMF_ZoomRotatePers;
3938 else if (theFlagString == "trihedron"
3939 || theFlagString == "triedron")
3941 theFlags = Graphic3d_TMF_TriedronPers;
3943 else if (theFlagString == "none")
3945 theFlags = Graphic3d_TMF_None;
3949 return Standard_False;
3952 return Standard_True;
3955 //! Auxiliary method to parse transformation persistence flags
3956 inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3957 Aspect_TypeOfTriedronPosition& theCorner)
3959 TCollection_AsciiString aString (theString);
3960 aString.LowerCase();
3961 if (aString == "center")
3963 theCorner = Aspect_TOTP_CENTER;
3965 else if (aString == "top"
3966 || aString == "upper")
3968 theCorner = Aspect_TOTP_TOP;
3970 else if (aString == "bottom"
3971 || aString == "lower")
3973 theCorner = Aspect_TOTP_BOTTOM;
3975 else if (aString == "left")
3977 theCorner = Aspect_TOTP_LEFT;
3979 else if (aString == "right")
3981 theCorner = Aspect_TOTP_RIGHT;
3983 else if (aString == "topleft"
3984 || aString == "leftupper"
3985 || aString == "upperleft")
3987 theCorner = Aspect_TOTP_LEFT_UPPER;
3989 else if (aString == "bottomleft"
3990 || aString == "leftlower"
3991 || aString == "lowerleft")
3993 theCorner = Aspect_TOTP_LEFT_LOWER;
3995 else if (aString == "topright"
3996 || aString == "rightupper"
3997 || aString == "upperright")
3999 theCorner = Aspect_TOTP_RIGHT_UPPER;
4001 else if (aString == "bottomright"
4002 || aString == "lowerright"
4003 || aString == "rightlower")
4005 theCorner = Aspect_TOTP_RIGHT_LOWER;
4009 return Standard_False;
4012 return Standard_True;
4015 //==============================================================================
4016 //function : VDisplay2
4018 //purpose : Display an object from its name
4019 //==============================================================================
4020 static int VDisplay2 (Draw_Interpretor& theDI,
4021 Standard_Integer theArgNb,
4022 const char** theArgVec)
4026 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4030 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4033 ViewerTest::ViewerInit();
4034 aCtx = ViewerTest::GetAISContext();
4037 // Parse input arguments
4038 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
4039 Standard_Integer isMutable = -1;
4040 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
4041 Standard_Boolean toDisplayLocal = Standard_False;
4042 Standard_Boolean toReDisplay = Standard_False;
4043 Standard_Integer isSelectable = -1;
4044 Standard_Integer anObjDispMode = -2;
4045 Standard_Integer anObjHighMode = -2;
4046 Standard_Boolean toSetTrsfPers = Standard_False;
4047 Handle(Graphic3d_TransformPers) aTrsfPers;
4048 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
4049 AIS_DisplayStatus aDispStatus = AIS_DS_None;
4050 Standard_Integer toDisplayInView = Standard_False;
4051 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4053 const TCollection_AsciiString aName = theArgVec[anArgIter];
4054 TCollection_AsciiString aNameCase = aName;
4055 aNameCase.LowerCase();
4056 if (anUpdateTool.parseRedrawMode (aName))
4060 else if (aNameCase == "-mutable")
4064 else if (aNameCase == "-neutral")
4066 aDispStatus = AIS_DS_Displayed;
4068 else if (aNameCase == "-immediate"
4069 || aNameCase == "-top")
4071 aZLayer = Graphic3d_ZLayerId_Top;
4073 else if (aNameCase == "-topmost")
4075 aZLayer = Graphic3d_ZLayerId_Topmost;
4077 else if (aNameCase == "-osd"
4078 || aNameCase == "-toposd"
4079 || aNameCase == "-overlay")
4081 aZLayer = Graphic3d_ZLayerId_TopOSD;
4083 else if (aNameCase == "-botosd"
4084 || aNameCase == "-underlay")
4086 aZLayer = Graphic3d_ZLayerId_BotOSD;
4088 else if (aNameCase == "-select"
4089 || aNameCase == "-selectable")
4093 else if (aNameCase == "-noselect"
4094 || aNameCase == "-noselection")
4098 else if (aNameCase == "-dispmode"
4099 || aNameCase == "-displaymode")
4101 if (++anArgIter >= theArgNb)
4103 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4107 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
4109 else if (aNameCase == "-highmode"
4110 || aNameCase == "-highlightmode")
4112 if (++anArgIter >= theArgNb)
4114 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4118 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
4120 else if (aNameCase == "-3d")
4122 toSetTrsfPers = Standard_True;
4123 aTrsfPers.Nullify();
4125 else if (aNameCase == "-2d"
4126 || aNameCase == "-trihedron"
4127 || aNameCase == "-triedron")
4129 toSetTrsfPers = Standard_True;
4130 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4132 if (anArgIter + 1 < theArgNb)
4134 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
4135 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
4138 aTrsfPers->SetCorner2d (aCorner);
4140 if (anArgIter + 2 < theArgNb)
4142 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
4143 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
4144 if (anX.IsIntegerValue()
4145 && anY.IsIntegerValue())
4148 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
4154 else if (aNameCase == "-trsfpers"
4155 || aNameCase == "-pers")
4157 if (++anArgIter >= theArgNb
4158 || !aTrsfPers.IsNull())
4160 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4164 toSetTrsfPers = Standard_True;
4165 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
4166 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
4167 aPersFlags.LowerCase();
4168 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
4170 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
4174 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
4176 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
4178 else if (aTrsfPersFlags != Graphic3d_TMF_None)
4180 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
4183 else if (aNameCase == "-trsfperspos"
4184 || aNameCase == "-perspos")
4186 if (anArgIter + 2 >= theArgNb
4187 || aTrsfPers.IsNull())
4189 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4193 TCollection_AsciiString aX (theArgVec[++anArgIter]);
4194 TCollection_AsciiString aY (theArgVec[++anArgIter]);
4195 TCollection_AsciiString aZ = "0";
4196 if (!aX.IsRealValue()
4197 || !aY.IsRealValue())
4199 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4202 if (anArgIter + 1 < theArgNb)
4204 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
4205 if (aTemp.IsRealValue())
4212 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
4213 if (aTrsfPers->IsZoomOrRotate())
4215 aTrsfPers->SetAnchorPoint (aPnt);
4217 else if (aTrsfPers->IsTrihedronOr2d())
4219 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
4222 else if (aNameCase == "-layer")
4224 if (++anArgIter >= theArgNb)
4226 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4230 TCollection_AsciiString aValue (theArgVec[anArgIter]);
4231 if (!aValue.IsIntegerValue())
4233 std::cerr << "Error: wrong syntax at " << aName << ".\n";
4237 aZLayer = aValue.IntegerValue();
4239 else if (aNameCase == "-view"
4240 || aNameCase == "-inview")
4242 toDisplayInView = Standard_True;
4244 else if (aNameCase == "-local")
4246 aDispStatus = AIS_DS_Temporary;
4247 toDisplayLocal = Standard_True;
4249 else if (aNameCase == "-redisplay")
4251 toReDisplay = Standard_True;
4255 aNamesOfDisplayIO.Append (aName);
4259 if (aNamesOfDisplayIO.IsEmpty())
4261 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4265 // Prepare context for display
4266 Standard_DISABLE_DEPRECATION_WARNINGS
4267 if (toDisplayLocal && !aCtx->HasOpenedContext())
4269 aCtx->OpenLocalContext (Standard_False);
4271 else if (!toDisplayLocal && aCtx->HasOpenedContext())
4273 aCtx->CloseAllContexts (Standard_False);
4275 Standard_ENABLE_DEPRECATION_WARNINGS
4277 // Display interactive objects
4278 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
4280 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
4282 if (!GetMapOfAIS().IsBound2 (aName))
4284 // create the AIS_Shape from a name
4285 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
4286 if (!aShape.IsNull())
4288 if (isMutable != -1)
4290 aShape->SetMutable (isMutable == 1);
4292 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4294 aShape->SetZLayer (aZLayer);
4298 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4300 if (anObjDispMode != -2)
4302 aShape->SetDisplayMode (anObjDispMode);
4304 if (anObjHighMode != -2)
4306 aShape->SetHilightMode (anObjHighMode);
4308 if (!toDisplayLocal)
4309 GetMapOfAIS().Bind (aShape, aName);
4311 Standard_Integer aDispMode = aShape->HasDisplayMode()
4312 ? aShape->DisplayMode()
4313 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4314 ? aCtx->DisplayMode()
4316 Standard_Integer aSelMode = -1;
4317 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4319 aSelMode = aShape->GlobalSelectionMode();
4322 aCtx->Display (aShape, aDispMode, aSelMode,
4323 Standard_False, aShape->AcceptShapeDecomposition(),
4325 if (toDisplayInView)
4327 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
4329 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
4331 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4336 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
4341 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
4342 if (isMutable != -1)
4344 aShape->SetMutable (isMutable == 1);
4346 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
4348 aShape->SetZLayer (aZLayer);
4352 aCtx->SetTransformPersistence (aShape, aTrsfPers);
4354 if (anObjDispMode != -2)
4356 aShape->SetDisplayMode (anObjDispMode);
4358 if (anObjHighMode != -2)
4360 aShape->SetHilightMode (anObjHighMode);
4362 Standard_Integer aDispMode = aShape->HasDisplayMode()
4363 ? aShape->DisplayMode()
4364 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
4365 ? aCtx->DisplayMode()
4367 Standard_Integer aSelMode = -1;
4368 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
4370 aSelMode = aShape->GlobalSelectionMode();
4373 if (aShape->Type() == AIS_KOI_Datum)
4375 aCtx->Display (aShape, Standard_False);
4379 theDI << "Display " << aName.ToCString() << "\n";
4381 // update the Shape in the AIS_Shape
4382 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
4383 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
4384 if (!aShapePrs.IsNull())
4386 if (!aShapePrs->Shape().IsEqual (aNewShape))
4388 toReDisplay = Standard_True;
4390 aShapePrs->Set (aNewShape);
4394 aCtx->Redisplay (aShape, Standard_False);
4399 aCtx->Erase (aShape, Standard_False);
4401 aCtx->Display (aShape, aDispMode, aSelMode,
4402 Standard_False, aShape->AcceptShapeDecomposition(),
4404 if (toDisplayInView)
4406 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
4414 //=======================================================================
4415 //function : VNbDisplayed
4416 //purpose : Returns number of displayed objects
4417 //=======================================================================
4418 static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
4419 Standard_Integer theArgsNb,
4420 const char** theArgVec)
4424 theDi << "Usage : " << theArgVec[0] << "\n";
4428 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4429 if (aContextAIS.IsNull())
4431 std::cout << theArgVec[0] << "AIS context is not available.\n";
4435 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4436 if(aContext.IsNull())
4438 theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
4442 AIS_ListOfInteractive aListOfIO;
4443 aContextAIS->DisplayedObjects(aListOfIO, false);
4445 theDi << aListOfIO.Extent() << "\n";
4449 //===============================================================================================
4450 //function : VUpdate
4452 //===============================================================================================
4453 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
4455 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4456 if (aContextAIS.IsNull())
4458 std::cout << theArgVec[0] << "AIS context is not available.\n";
4464 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
4468 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
4470 AIS_ListOfInteractive aListOfIO;
4472 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
4474 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
4476 Handle(AIS_InteractiveObject) anAISObj;
4477 if (anAISMap.IsBound2 (aName))
4479 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
4482 if (anAISObj.IsNull())
4484 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
4488 aListOfIO.Append (anAISObj);
4491 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
4492 for (; anIOIt.More(); anIOIt.Next())
4494 aContextAIS->Update (anIOIt.Value(), Standard_False);
4497 aContextAIS->UpdateCurrentViewer();
4502 //==============================================================================
4503 //function : VShading
4504 //purpose : Sharpen or roughten the quality of the shading
4505 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4506 //==============================================================================
4507 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4509 Standard_Real myDevCoef;
4510 Handle(AIS_InteractiveObject) TheAisIO;
4513 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4517 myDevCoef =Draw::Atof(argv[2]);
4520 TCollection_AsciiString name=argv[1];
4521 if (GetMapOfAIS().IsBound2(name ))
4522 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
4523 if (TheAisIO.IsNull())
4524 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4527 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
4529 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4531 TheAISContext()->Redisplay (TheAisIO, Standard_True);
4534 //==============================================================================
4535 //function : HaveMode
4536 //use : VActivatedModes
4537 //==============================================================================
4538 #include <TColStd_ListIteratorOfListOfInteger.hxx>
4540 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4542 TColStd_ListOfInteger List;
4543 TheAISContext()->ActivatedModes (TheAisIO,List);
4544 TColStd_ListIteratorOfListOfInteger it;
4545 Standard_Boolean Found=Standard_False;
4546 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4547 if (it.Value()==mode ) Found=Standard_True;
4554 //==============================================================================
4555 //function : VActivatedMode
4557 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
4558 // (edges,vertex...)qui lui est propre et le mode de selection standard.
4559 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4560 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4561 // qu'un nom et qu'un mode.
4562 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4563 //==============================================================================
4564 #include <AIS_ListIteratorOfListOfInteractive.hxx>
4566 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4569 Standard_Boolean ThereIsName = Standard_False ;
4571 if(!a3DView().IsNull()){
4573 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
4574 // verification des arguments
4576 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
4577 ThereIsName = (argc == 3);
4581 Standard_DISABLE_DEPRECATION_WARNINGS
4583 if (argc>1) {di<<" Syntaxe error\n";return 1;}
4585 di<<" R.A.Z de tous les modes de selecion\n";
4586 di<<" Fermeture du Context local\n";
4587 if (TheAISContext()->HasOpenedContext())
4589 TheAISContext()->CloseLocalContext();
4592 Standard_ENABLE_DEPRECATION_WARNINGS
4595 // IL n'y a aps de nom de shape passe en argument
4596 if (HaveToSet && !ThereIsName){
4597 Standard_Integer aMode=Draw::Atoi(argv [1]);
4598 const TopAbs_ShapeEnum aShapeType = AIS_Shape::SelectionType (aMode);
4599 const char* cmode = aMode >= 0 && aMode <= 8
4600 ? TopAbs::ShapeTypeToString (aShapeType)
4602 if( !TheAISContext()->HasOpenedContext() ) {
4603 // il n'y a pas de Context local d'ouvert
4604 // on en ouvre un et on charge toutes les shapes displayees
4605 // on load tous les objets displayees et on Activate les objets de la liste
4606 AIS_ListOfInteractive ListOfIO;
4607 // on sauve dans une AISListOfInteractive tous les objets currents
4608 if (TheAISContext()->NbSelected()>0 ){
4609 TheAISContext()->UnhilightSelected(Standard_False);
4611 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4612 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
4616 Standard_DISABLE_DEPRECATION_WARNINGS
4617 TheAISContext()->OpenLocalContext(Standard_False);
4618 Standard_ENABLE_DEPRECATION_WARNINGS
4619 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4622 Handle(AIS_InteractiveObject) aIO =
4623 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4625 TheAISContext()->Load(aIO,0,Standard_False);
4628 // traitement des objets qui etaient currents dans le Contexte global
4629 if (!ListOfIO.IsEmpty() ) {
4630 // il y avait des objets currents
4631 AIS_ListIteratorOfListOfInteractive iter;
4632 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4633 Handle(AIS_InteractiveObject) aIO=iter.Value();
4634 TheAISContext()->Activate(aIO,aMode);
4635 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4639 // On applique le mode a tous les objets displayes
4640 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4641 it2 (GetMapOfAIS());
4643 Handle(AIS_InteractiveObject) aIO =
4644 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4645 if (!aIO.IsNull()) {
4646 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4647 TheAISContext()->Activate(aIO,aMode);
4656 // un Context local est deja ouvert
4657 // Traitement des objets du Context local
4658 if (TheAISContext()->NbSelected()>0 ){
4659 TheAISContext()->UnhilightSelected(Standard_False);
4660 // il y a des objets selected,on les parcourt
4661 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4662 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
4665 if (HaveMode(aIO,aMode) ) {
4666 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4667 TheAISContext()->Deactivate(aIO,aMode);
4670 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4671 TheAISContext()->Activate(aIO,aMode);
4677 // il n'y a pas d'objets selected
4678 // tous les objets diplayes sont traites
4679 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4682 Handle(AIS_InteractiveObject) aIO =
4683 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4684 if (!aIO.IsNull()) {
4685 if (HaveMode(aIO,aMode) ) {
4686 di<<" Mode: "<<cmode<<" OFF pour "
4687 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4688 TheAISContext()->Deactivate(aIO,aMode);
4691 di<<" Mode: "<<cmode<<" ON pour"
4692 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4693 TheAISContext()->Activate(aIO,aMode);
4701 else if (HaveToSet && ThereIsName){
4702 Standard_Integer aMode=Draw::Atoi(argv [2]);
4703 Handle(AIS_InteractiveObject) aIO =
4704 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4706 if (!aIO.IsNull()) {
4707 const TopAbs_ShapeEnum aShapeType = AIS_Shape::SelectionType (aMode);
4708 const char* cmode = aMode >= 0 && aMode <= 8
4709 ? TopAbs::ShapeTypeToString (aShapeType)
4711 if( !TheAISContext()->HasOpenedContext() ) {
4712 Standard_DISABLE_DEPRECATION_WARNINGS
4713 TheAISContext()->OpenLocalContext(Standard_False);
4714 Standard_ENABLE_DEPRECATION_WARNINGS
4715 // On charge tous les objets de la map
4716 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4718 Handle(AIS_InteractiveObject) aShape=
4719 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4720 if (!aShape.IsNull())
4721 TheAISContext()->Load(aShape,0,Standard_False);
4724 TheAISContext()->Activate(aIO,aMode);
4725 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4729 // un Context local est deja ouvert
4730 if (HaveMode(aIO,aMode) ) {
4731 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4732 TheAISContext()->Deactivate(aIO,aMode);
4735 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4736 TheAISContext()->Activate(aIO,aMode);
4745 //! Auxiliary method to print Interactive Object information
4746 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4747 const Handle(Standard_Transient)& theObject,
4748 Draw_Interpretor& theDI)
4750 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4753 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4757 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4758 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4759 << (theDetected.Contains (anObj) ? " Detected" : " ")
4761 if (anObj->Type() == AIS_KOI_Datum)
4764 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4765 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4766 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4767 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4768 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4769 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4770 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4773 else if (anObj->Type() == AIS_KOI_Shape
4774 && anObj->Signature() == 0)
4776 theDI << " AIS_Shape";
4778 else if (anObj->Type() == AIS_KOI_Relation)
4780 // AIS_Dimention and AIS_Relation
4781 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4782 switch (aRelation->KindOfDimension())
4784 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4785 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4786 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4787 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4788 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4789 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4790 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4791 default: theDI << " UNKNOWN dimension"; break;
4796 theDI << " UserPrs";
4798 theDI << " (" << theObject->DynamicType()->Name() << ")";
4801 //! Print information about locally selected sub-shapes
4802 template <typename T>
4803 static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
4805 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
4806 TCollection_AsciiString aPrevName;
4807 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
4809 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4810 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4811 if (aShapeIO.IsNull() || anOwner.IsNull())
4815 if (anOwner == aShapeIO->GlobalSelOwner())
4818 const TopoDS_Shape aSubShape = theContext->SelectedShape();
4819 if (aSubShape.IsNull()
4820 || aShapeIO.IsNull()
4821 || !GetMapOfAIS().IsBound1 (aShapeIO))
4826 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4827 TopTools_MapOfShape aFilter;
4828 Standard_Integer aNumber = 0;
4829 const TopoDS_Shape aShape = aShapeIO->Shape();
4830 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4831 anIter.More(); anIter.Next())
4833 if (!aFilter.Add (anIter.Current()))
4835 continue; // filter duplicates
4839 if (!anIter.Current().IsSame (aSubShape))
4844 Standard_CString aShapeName = NULL;
4845 switch (aSubShape.ShapeType())
4847 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4848 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4849 case TopAbs_SOLID: aShapeName = " Solid"; break;
4850 case TopAbs_SHELL: aShapeName = " Shell"; break;
4851 case TopAbs_FACE: aShapeName = " Face"; break;
4852 case TopAbs_WIRE: aShapeName = " Wire"; break;
4853 case TopAbs_EDGE: aShapeName = " Edge"; break;
4854 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4856 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4859 if (aParentName != aPrevName)
4861 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4862 aPrevName = aParentName;
4864 theDI << " " << aShapeName << " #" << aNumber << "\n";
4870 //==============================================================================
4873 //==============================================================================
4874 static Standard_Integer VState (Draw_Interpretor& theDI,
4875 Standard_Integer theArgNb,
4876 Standard_CString* theArgVec)
4878 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4881 std::cerr << "Error: No opened viewer!\n";
4885 Standard_Boolean toPrintEntities = Standard_False;
4886 Standard_Boolean toCheckSelected = Standard_False;
4888 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4890 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4891 anOption.LowerCase();
4892 if (anOption == "-detectedentities"
4893 || anOption == "-entities")
4895 toPrintEntities = Standard_True;
4897 else if (anOption == "-hasselected")
4899 toCheckSelected = Standard_True;
4903 if (toCheckSelected)
4905 aCtx->InitSelected();
4906 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4907 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4912 if (toPrintEntities)
4914 theDI << "Detected entities:\n";
4915 Standard_DISABLE_DEPRECATION_WARNINGS
4916 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4917 Standard_ENABLE_DEPRECATION_WARNINGS
4918 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
4919 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
4921 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4922 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
4923 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4924 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4925 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4926 aName.LeftJustify (20, ' ');
4927 char anInfoStr[512];
4929 " Depth: %g Distance: %g Point: %g %g %g",
4932 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
4933 theDI << " " << aName
4935 << " (" << anEntity->DynamicType()->Name() << ")"
4938 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4939 if (!aBRepOwner.IsNull())
4941 theDI << " Detected Shape: "
4942 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4946 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4947 if (!aWire.IsNull())
4949 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4950 theDI << " Detected Child: "
4951 << aSen->DynamicType()->Name()
4955 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4956 if (!aPrimArr.IsNull())
4958 theDI << " Detected Element: "
4959 << aPrimArr->LastDetectedElement()
4966 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4967 Standard_DISABLE_DEPRECATION_WARNINGS
4968 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4970 aDetected.Add (aCtx->DetectedCurrentObject());
4972 Standard_ENABLE_DEPRECATION_WARNINGS
4974 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4978 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4980 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4981 if (!GetMapOfAIS().IsBound2 (anObjName))
4983 theDI << anObjName << " doesn't exist!\n";
4987 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4988 TCollection_AsciiString aName = anObjName;
4989 aName.LeftJustify (20, ' ');
4990 theDI << " " << aName << " ";
4991 objInfo (aDetected, anObjTrans, theDI);
4997 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
4999 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
5000 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
5002 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
5003 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
5004 // handle whole object selection
5005 if (anOwner == anObj->GlobalSelOwner())
5007 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
5008 aName.LeftJustify (20, ' ');
5009 theDI << aName << " ";
5010 objInfo (aDetected, anObj, theDI);
5015 // process selected sub-shapes
5016 printLocalSelectionInfo (aCtx, theDI);
5021 theDI << "Neutral-point state:\n";
5022 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
5023 anObjIter.More(); anObjIter.Next())
5025 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
5031 TCollection_AsciiString aName = anObjIter.Key2();
5032 aName.LeftJustify (20, ' ');
5033 theDI << " " << aName << " ";
5034 objInfo (aDetected, anObj, theDI);
5037 printLocalSelectionInfo (aCtx, theDI);
5038 Standard_DISABLE_DEPRECATION_WARNINGS
5039 if (aCtx->HasOpenedContext())
5040 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
5041 Standard_ENABLE_DEPRECATION_WARNINGS
5045 //=======================================================================
5046 //function : PickObjects
5048 //=======================================================================
5049 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
5050 const AIS_KindOfInteractive TheType,
5051 const Standard_Integer TheSignature,
5052 const Standard_Integer MaxPick)
5054 Handle(AIS_InteractiveObject) IO;
5055 Standard_DISABLE_DEPRECATION_WARNINGS
5056 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
5057 Standard_ENABLE_DEPRECATION_WARNINGS
5059 // step 1: prepare the data
5061 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
5062 TheAISContext()->AddFilter(F1);
5065 // step 2 : wait for the selection...
5066 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
5067 Standard_Integer NbPickFail(0);
5068 Standard_Integer argccc = 5;
5069 const char *bufff[] = { "A", "B", "C","D", "E" };
5070 const char **argvvv = (const char **) bufff;
5073 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
5074 while(ViewerMainLoop(argccc,argvvv)){}
5075 Standard_Integer NbStored = TheAISContext()->NbSelected();
5076 if(NbStored != NbPickGood)
5077 NbPickGood= NbStored;
5080 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
5083 // step3 get result.
5085 if (NbPickFail >= NbToReach)
5086 return Standard_False;
5088 Standard_Integer i(0);
5089 for(TheAISContext()->InitSelected();
5090 TheAISContext()->MoreSelected();
5091 TheAISContext()->NextSelected()){
5093 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
5094 arr->SetValue(i,IO2);
5097 Standard_DISABLE_DEPRECATION_WARNINGS
5100 TheAISContext()->CloseLocalContext(curindex);
5102 Standard_ENABLE_DEPRECATION_WARNINGS
5104 return Standard_True;
5108 //=======================================================================
5109 //function : PickObject
5111 //=======================================================================
5112 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
5113 const Standard_Integer TheSignature,
5114 const Standard_Integer MaxPick)
5116 Handle(AIS_InteractiveObject) IO;
5117 Standard_DISABLE_DEPRECATION_WARNINGS
5118 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
5119 Standard_ENABLE_DEPRECATION_WARNINGS
5121 // step 1: prepare the data
5124 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
5125 TheAISContext()->AddFilter(F1);
5128 // step 2 : wait for the selection...
5129 Standard_Boolean IsGood (Standard_False);
5130 Standard_Integer NbPick(0);
5131 Standard_Integer argccc = 5;
5132 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
5133 const char **argvvv = (const char **) bufff;
5136 while(!IsGood && NbPick<= MaxPick){
5137 while(ViewerMainLoop(argccc,argvvv)){}
5138 IsGood = (TheAISContext()->NbSelected()>0) ;
5140 cout<<"Nb Pick :"<<NbPick<<endl;
5144 // step3 get result.
5146 TheAISContext()->InitSelected();
5147 IO = TheAISContext()->SelectedInteractive();
5150 Standard_DISABLE_DEPRECATION_WARNINGS
5153 TheAISContext()->CloseLocalContext(curindex);
5155 Standard_ENABLE_DEPRECATION_WARNINGS
5159 //=======================================================================
5160 //function : PickShape
5161 //purpose : First Activate the rightmode + Put Filters to be able to
5162 // pick objets that are of type <TheType>...
5163 //=======================================================================
5165 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
5166 const Standard_Integer MaxPick)
5169 // step 1: prepare the data
5170 Standard_DISABLE_DEPRECATION_WARNINGS
5171 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
5172 Standard_ENABLE_DEPRECATION_WARNINGS
5173 TopoDS_Shape result;
5175 if(TheType==TopAbs_SHAPE){
5176 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
5177 TheAISContext()->AddFilter(F1);
5180 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
5181 TheAISContext()->AddFilter(TF);
5182 Standard_DISABLE_DEPRECATION_WARNINGS
5183 TheAISContext()->ActivateStandardMode(TheType);
5184 Standard_ENABLE_DEPRECATION_WARNINGS
5188 // step 2 : wait for the selection...
5189 Standard_Boolean NoShape (Standard_True);
5190 Standard_Integer NbPick(0);
5191 Standard_Integer argccc = 5;
5192 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
5193 const char **argvvv = (const char **) bufff;
5196 while(NoShape && NbPick<= MaxPick){
5197 while(ViewerMainLoop(argccc,argvvv)){}
5198 NoShape = (TheAISContext()->NbSelected()==0) ;
5200 cout<<"Nb Pick :"<<NbPick<<endl;
5203 // step3 get result.
5207 TheAISContext()->InitSelected();
5208 if(TheAISContext()->HasSelectedShape())
5209 result = TheAISContext()->SelectedShape();
5211 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5212 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
5216 Standard_DISABLE_DEPRECATION_WARNINGS
5219 TheAISContext()->CloseLocalContext(curindex);
5221 Standard_ENABLE_DEPRECATION_WARNINGS
5227 //=======================================================================
5228 //function : PickShapes
5230 //=======================================================================
5231 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
5232 Handle(TopTools_HArray1OfShape)& thearr,
5233 const Standard_Integer MaxPick)
5236 Standard_Integer Taille = thearr->Length();
5238 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
5240 // step 1: prepare the data
5241 Standard_DISABLE_DEPRECATION_WARNINGS
5242 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
5243 Standard_ENABLE_DEPRECATION_WARNINGS
5244 if(TheType==TopAbs_SHAPE){
5245 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
5246 TheAISContext()->AddFilter(F1);
5249 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
5250 TheAISContext()->AddFilter(TF);
5251 Standard_DISABLE_DEPRECATION_WARNINGS
5252 TheAISContext()->ActivateStandardMode(TheType);
5253 Standard_ENABLE_DEPRECATION_WARNINGS
5256 // step 2 : wait for the selection...
5257 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
5258 Standard_Integer NbPickFail(0);
5259 Standard_Integer argccc = 5;
5260 const char *bufff[] = { "A", "B", "C","D", "E" };
5261 const char **argvvv = (const char **) bufff;
5264 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
5265 while(ViewerMainLoop(argccc,argvvv)){}
5266 Standard_Integer NbStored = TheAISContext()->NbSelected();
5267 if (NbStored != NbPickGood)
5268 NbPickGood= NbStored;
5271 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
5274 // step3 get result.
5276 if (NbPickFail >= NbToReach)
5277 return Standard_False;
5279 Standard_Integer i(0);
5280 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
5282 if(TheAISContext()->HasSelectedShape())
5283 thearr->SetValue(i,TheAISContext()->SelectedShape());
5285 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5286 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
5290 Standard_DISABLE_DEPRECATION_WARNINGS
5291 TheAISContext()->CloseLocalContext(curindex);
5292 Standard_ENABLE_DEPRECATION_WARNINGS
5293 return Standard_True;
5297 //=======================================================================
5298 //function : VPickShape
5300 //=======================================================================
5301 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5303 TopoDS_Shape PickSh;
5304 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
5307 theType = TopAbs_SHAPE;
5309 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
5310 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
5311 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
5312 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
5313 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
5314 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
5315 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
5318 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
5319 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
5321 TCollection_AsciiString name;
5324 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
5326 PickSh = ViewerTest::PickShape(theType);
5335 if(!PickSh.IsNull()){
5336 nbOfSub[Standard_Integer(theType)]++;
5338 name += nameType[Standard_Integer(theType)];
5339 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
5344 // si on avait une petite methode pour voir si la shape
5345 // est deja dans la Double map, ca eviterait de creer....
5346 DBRep::Set(name.ToCString(),PickSh);
5348 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
5349 GetMapOfAIS().Bind(newsh, name);
5350 TheAISContext()->Display (newsh, Standard_True);
5351 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
5354 // Plusieurs objets a picker, vite vite vite....
5357 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
5358 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
5359 if(ViewerTest::PickShapes(theType,arr)){
5360 for(Standard_Integer i=1;i<=NbToPick;i++){
5361 PickSh = arr->Value(i);
5362 if(!PickSh.IsNull()){
5364 nbOfSub[Standard_Integer(theType)]++;
5367 name += nameType[Standard_Integer(theType)];
5368 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
5376 DBRep::Set(name.ToCString(),PickSh);
5377 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
5378 GetMapOfAIS().Bind(newsh, name);
5379 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
5380 TheAISContext()->Display (newsh, Standard_False);
5383 TheAISContext()->UpdateCurrentViewer();
5389 //=======================================================================
5390 //function : VSelFilter
5392 //=======================================================================
5393 static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
5394 const char** theArgv)
5396 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5397 if (aContext.IsNull())
5399 std::cout << "Error: AIS context is not available.\n";
5403 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
5405 TCollection_AsciiString anArg (theArgv[anArgIter]);
5407 if (anArg == "-clear")
5409 aContext->RemoveFilters();
5411 else if (anArg == "-type"
5412 && anArgIter + 1 < theArgc)
5414 TCollection_AsciiString aVal (theArgv[++anArgIter]);
5415 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
5416 if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
5418 std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
5422 Handle(SelectMgr_Filter) aFilter;
5423 if (aShapeType == TopAbs_SHAPE)
5425 aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
5429 aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
5431 aContext->AddFilter (aFilter);
5435 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
5442 //=======================================================================
5443 //function : VPickSelected
5445 //=======================================================================
5446 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
5448 static Standard_Integer aCount = 0;
5449 TCollection_AsciiString aName = "PickedShape_";
5457 aName = aName + aCount++ + "_";
5460 Standard_Integer anIdx = 0;
5461 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
5463 TopoDS_Shape aShape;
5464 if (TheAISContext()->HasSelectedShape())
5466 aShape = TheAISContext()->SelectedShape();
5470 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
5471 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
5474 TCollection_AsciiString aCurrentName = aName;
5477 aCurrentName += anIdx;
5480 DBRep::Set ((aCurrentName).ToCString(), aShape);
5482 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
5483 GetMapOfAIS().Bind (aNewShape, aCurrentName);
5484 TheAISContext()->Display (aNewShape, Standard_False);
5487 TheAISContext()->UpdateCurrentViewer();
5492 //=======================================================================
5493 //function : list of known objects
5495 //=======================================================================
5496 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
5498 // 1234567890 12345678901234567 123456789
5499 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
5500 TCollection_AsciiString BlankLine(64,'_');
5501 Standard_Integer i ;
5503 di<<"/n"<<BlankLine.ToCString()<<"\n";
5506 Colum[i].Center(20,' ');
5508 di<<"|"<<Colum[i].ToCString();
5511 di<<BlankLine.ToCString()<<"\n";
5513 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
5514 const char ** names = GetTypeNames();
5516 TCollection_AsciiString curstring;
5517 TCollection_AsciiString curcolum[3];
5520 // les objets de type Datum..
5521 curcolum[1]+="Datum";
5523 curcolum[0].Clear();
5524 curcolum[0] += names[i];
5526 curcolum[2].Clear();
5527 curcolum[2]+=TCollection_AsciiString(i+1);
5529 for(Standard_Integer j =0;j<=2;j++){
5530 curcolum[j].Center(20,' ');
5531 di<<"|"<<curcolum[j].ToCString();
5535 di<<BlankLine.ToCString()<<"\n";
5537 // les objets de type shape
5538 curcolum[1].Clear();
5539 curcolum[1]+="Shape";
5540 curcolum[1].Center(20,' ');
5543 curcolum[0].Clear();
5544 curcolum[0] += names[7+i];
5545 curcolum[2].Clear();
5546 curcolum[2]+=TCollection_AsciiString(i);
5548 for(Standard_Integer j =0;j<=2;j++){
5549 curcolum[j].Center(20,' ');
5550 di<<"|"<<curcolum[j].ToCString();
5554 di<<BlankLine.ToCString()<<"\n";
5555 // les IO de type objet...
5556 curcolum[1].Clear();
5557 curcolum[1]+="Object";
5558 curcolum[1].Center(20,' ');
5560 curcolum[0].Clear();
5561 curcolum[0] += names[10+i];
5562 curcolum[2].Clear();
5563 curcolum[2]+=TCollection_AsciiString(i);
5565 for(Standard_Integer j =0;j<=2;j++){
5566 curcolum[j].Center(20,' ');
5567 di<<"|"<<curcolum[j].ToCString();
5571 di<<BlankLine.ToCString()<<"\n";
5572 // les contraintes et dimensions.
5573 // pour l'instant on separe juste contraintes et dimensions...
5574 // plus tard, on detaillera toutes les sortes...
5575 curcolum[1].Clear();
5576 curcolum[1]+="Relation";
5577 curcolum[1].Center(20,' ');
5579 curcolum[0].Clear();
5580 curcolum[0] += names[12+i];
5581 curcolum[2].Clear();
5582 curcolum[2]+=TCollection_AsciiString(i);
5584 for(Standard_Integer j =0;j<=2;j++){
5585 curcolum[j].Center(20,' ');
5586 di<<"|"<<curcolum[j].ToCString();
5590 di<<BlankLine.ToCString()<<"\n";
5597 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5599 if(argc!=2) return 1;
5601 AIS_KindOfInteractive TheType;
5602 Standard_Integer TheSign(-1);
5603 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5606 AIS_ListOfInteractive LIO;
5608 // en attendant l'amelioration ais pour les dimensions...
5610 Standard_Integer dimension_status(-1);
5611 if(TheType==AIS_KOI_Relation){
5612 dimension_status = TheSign ==1 ? 1 : 0;
5616 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5617 Handle(AIS_InteractiveObject) curio;
5618 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5621 if(dimension_status == -1)
5622 TheAISContext()->Erase(curio,Standard_False);
5624 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5625 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5626 (dimension_status==1 && KOD != AIS_KOD_NONE))
5627 TheAISContext()->Erase(curio,Standard_False);
5630 TheAISContext()->UpdateCurrentViewer();
5633 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5635 if(argc!=2) return 1;
5637 AIS_KindOfInteractive TheType;
5638 Standard_Integer TheSign(-1);
5639 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5641 // en attendant l'amelioration ais pour les dimensions...
5643 Standard_Integer dimension_status(-1);
5644 if(TheType==AIS_KOI_Relation){
5645 dimension_status = TheSign ==1 ? 1 : 0;
5649 AIS_ListOfInteractive LIO;
5650 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5651 Handle(AIS_InteractiveObject) curio;
5652 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5654 if(dimension_status == -1)
5655 TheAISContext()->Display(curio,Standard_False);
5657 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
5658 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5659 (dimension_status==1 && KOD != AIS_KOD_NONE))
5660 TheAISContext()->Display(curio,Standard_False);
5665 TheAISContext()->UpdateCurrentViewer();
5669 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5672 BRep_Builder builder;
5674 BRepTools::Read(shape, s, builder);
5675 DBRep::Set(a[1], shape);
5676 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5677 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5678 Ctx->Display (ais, Standard_True);
5682 //===============================================================================================
5685 //===============================================================================================
5686 static int VBsdf (Draw_Interpretor& theDI,
5687 Standard_Integer theArgsNb,
5688 const char** theArgVec)
5690 Handle(V3d_View) aView = ViewerTest::CurrentView();
5691 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5693 || aViewer.IsNull())
5695 std::cerr << "No active viewer!\n";
5699 ViewerTest_CmdParser aCmd;
5701 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5703 aCmd.AddOption ("print|echo|p", "Prints BSDF");
5705 aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
5707 aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF");
5708 aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
5709 aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
5710 aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
5711 aCmd.AddOption ("le", "Radiance emitted by surface");
5713 aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5714 aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
5716 aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
5717 aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
5719 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
5720 aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
5722 aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
5724 aCmd.Parse (theArgsNb, theArgVec);
5726 if (aCmd.HasOption ("help"))
5728 theDI.PrintHelp (theArgVec[0]);
5732 // check viewer update mode
5733 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
5735 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
5737 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5743 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5746 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5747 if (!aMap.IsBound2 (aName) )
5749 std::cerr << "Use 'vdisplay' before\n";
5753 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5754 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5755 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5757 if (aCmd.HasOption ("print"))
5760 << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n"
5761 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5762 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5763 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5764 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
5766 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5768 const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
5769 : aBSDF.FresnelBase.Serialize();
5771 theDI << (aLayerID < 1 ? "Coat Fresnel: "
5772 : "Base Fresnel: ");
5774 if (aFresnel.x() >= 0.f)
5776 theDI << "Schlick " << "R = " << aFresnel.r() << ", "
5777 << "G = " << aFresnel.g() << ", "
5778 << "B = " << aFresnel.b() << "\n";
5780 else if (aFresnel.x() >= -1.5f)
5782 theDI << "Constant " << aFresnel.z() << "\n";
5784 else if (aFresnel.x() >= -2.5f)
5786 theDI << "Conductor " << "N = " << aFresnel.y() << ", "
5787 << "K = " << aFresnel.z() << "\n";
5791 theDI << "Dielectric " << "N = " << aFresnel.y() << "\n";
5795 theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n"
5796 << "Base roughness: " << aBSDF.Ks.w() << "\n"
5797 << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
5798 << "Absorption color: " << aBSDF.Absorption.r() << ", "
5799 << aBSDF.Absorption.g() << ", "
5800 << aBSDF.Absorption.b() << "\n";
5805 if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
5807 aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
5810 if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
5812 aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
5815 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5817 aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
5820 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5822 const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
5824 aBSDF.Absorption.r() = aRGB.r();
5825 aBSDF.Absorption.g() = aRGB.g();
5826 aBSDF.Absorption.b() = aRGB.b();
5829 if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
5833 if (aCmd.HasOption ("kc", 3))
5835 aKc = aCmd.ArgVec3f ("kc");
5839 aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
5842 aBSDF.Kc.r() = aKc.r();
5843 aBSDF.Kc.g() = aKc.g();
5844 aBSDF.Kc.b() = aKc.b();
5847 if (aCmd.HasOption ("kd", 3))
5849 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5851 else if (aCmd.HasOption ("kd", 1, Standard_True))
5853 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5856 if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
5860 if (aCmd.HasOption ("ks", 3))
5862 aKs = aCmd.ArgVec3f ("ks");
5866 aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5869 aBSDF.Ks.r() = aKs.r();
5870 aBSDF.Ks.g() = aKs.g();
5871 aBSDF.Ks.b() = aKs.b();
5874 if (aCmd.HasOption ("kt", 3))
5876 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5878 else if (aCmd.HasOption ("kt", 1, Standard_True))
5880 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5883 if (aCmd.HasOption ("le", 3))
5885 aBSDF.Le = aCmd.ArgVec3f ("le");
5887 else if (aCmd.HasOption ("le", 1, Standard_True))
5889 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5892 const std::string aFresnelErrorMessage =
5893 "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
5895 for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
5897 const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
5900 if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
5902 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5903 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5905 if (aFresnelType == "schlick")
5907 Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
5908 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
5909 static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
5911 aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
5912 aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
5913 aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
5915 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
5919 theDI << aFresnelErrorMessage.c_str() << "\n";
5922 else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
5924 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5925 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5927 if (aFresnelType == "conductor")
5929 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5930 const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
5932 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
5936 theDI << aFresnelErrorMessage.c_str() << "\n";
5939 else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
5941 std::string aFresnelType = aCmd.Arg (aFresnel, 0);
5942 std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
5944 if (aFresnelType == "constant")
5946 const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5948 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
5950 else if (aFresnelType == "dielectric")
5952 const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
5954 (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
5958 theDI << aFresnelErrorMessage.c_str() << "\n";
5963 if (aCmd.HasOption ("normalize"))
5968 aMaterial.SetBSDF (aBSDF);
5969 anIObj->SetMaterial (aMaterial);
5974 //==============================================================================
5975 //function : VLoadSelection
5976 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5977 //==============================================================================
5978 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5979 Standard_Integer theArgNb,
5980 const char** theArgVec)
5984 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5988 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5991 ViewerTest::ViewerInit();
5992 aCtx = ViewerTest::GetAISContext();
5995 // Parse input arguments
5996 TColStd_SequenceOfAsciiString aNamesOfIO;
5997 Standard_Boolean isLocal = Standard_False;
5998 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6000 const TCollection_AsciiString aName = theArgVec[anArgIter];
6001 TCollection_AsciiString aNameCase = aName;
6002 aNameCase.LowerCase();
6003 if (aNameCase == "-local")
6005 isLocal = Standard_True;
6009 aNamesOfIO.Append (aName);
6013 if (aNamesOfIO.IsEmpty())
6015 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
6020 Standard_DISABLE_DEPRECATION_WARNINGS
6021 if (isLocal && !aCtx->HasOpenedContext())
6023 aCtx->OpenLocalContext (Standard_False);
6025 else if (!isLocal && aCtx->HasOpenedContext())
6027 aCtx->CloseAllContexts (Standard_False);
6029 Standard_ENABLE_DEPRECATION_WARNINGS
6031 // Load selection of interactive objects
6032 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
6034 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
6036 Handle(AIS_InteractiveObject) aShape;
6037 if (GetMapOfAIS().IsBound2 (aName))
6038 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
6040 aShape = GetAISShapeFromName (aName.ToCString());
6042 if (!aShape.IsNull())
6044 if (!GetMapOfAIS().IsBound2 (aName))
6046 GetMapOfAIS().Bind (aShape, aName);
6049 aCtx->Load (aShape, -1, Standard_False);
6050 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
6057 //==============================================================================
6058 //function : ViewerTest::Commands
6059 //purpose : Add all the viewer command in the Draw_Interpretor
6060 //==============================================================================
6062 void ViewerTest::Commands(Draw_Interpretor& theCommands)
6064 ViewerTest::ViewerCommands(theCommands);
6065 ViewerTest::RelationCommands(theCommands);
6066 ViewerTest::ObjectCommands(theCommands);
6067 ViewerTest::FilletCommands(theCommands);
6068 ViewerTest::OpenGlCommands(theCommands);
6070 const char *group = "AIS_Display";
6073 theCommands.Add("visos",
6074 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
6075 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
6076 __FILE__, visos, group);
6078 theCommands.Add("vdisplay",
6079 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
6080 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
6081 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
6082 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
6083 "\n\t\t: |topRight|bottomLeft|bottomRight}"
6084 "\n\t\t: [offsetX offsetY]]]"
6085 "\n\t\t: [-dispMode mode] [-highMode mode]"
6086 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
6087 "\n\t\t: [-redisplay]"
6088 "\n\t\t: name1 [name2] ... [name n]"
6089 "\n\t\t: Displays named objects."
6090 "\n\t\t: Option -local enables displaying of objects in local"
6091 "\n\t\t: selection context. Local selection context will be opened"
6092 "\n\t\t: if there is not any."
6093 "\n\t\t: -noupdate Suppresses viewer redraw call."
6094 "\n\t\t: -mutable Enables optimizations for mutable objects."
6095 "\n\t\t: -neutral Draws objects in main viewer."
6096 "\n\t\t: -layer Sets z-layer for objects."
6097 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
6098 "\n\t\t: options can be used for the default z-layers."
6099 "\n\t\t: -top Draws object on top of main presentations"
6100 "\n\t\t: but below topmost."
6101 "\n\t\t: -topmost Draws in overlay for 3D presentations."
6102 "\n\t\t: with independent Depth."
6103 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
6104 "\n\t\t: (On-Screen-Display)"
6105 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
6106 "\n\t\t: (On-Screen-Display)"
6107 "\n\t\t: -selectable|-noselect Controls selection of objects."
6108 "\n\t\t: -trsfPers Sets a transform persistence flags."
6109 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
6110 "\n\t\t: -2d Displays object in screen coordinates."
6111 "\n\t\t: (DY looks up)"
6112 "\n\t\t: -dispmode Sets display mode for objects."
6113 "\n\t\t: -highmode Sets hilight mode for objects."
6114 "\n\t\t: -redisplay Recomputes presentation of objects.",
6115 __FILE__, VDisplay2, group);
6117 theCommands.Add ("vnbdisplayed",
6119 "\n\t\t: Returns number of displayed objects",
6120 __FILE__, VNbDisplayed, group);
6122 theCommands.Add ("vupdate",
6123 "vupdate name1 [name2] ... [name n]"
6124 "\n\t\t: Updates named objects in interactive context",
6125 __FILE__, VUpdate, group);
6127 theCommands.Add("verase",
6128 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
6129 "\n\t\t: Erases selected or named objects."
6130 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
6131 "\n\t\t: Option -local enables erasing of selected or named objects without"
6132 "\n\t\t: closing local selection context.",
6133 __FILE__, VErase, group);
6135 theCommands.Add("vremove",
6136 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
6137 "or vremove [-context] -all to remove all objects"
6138 "\n\t\t: Removes selected or named objects."
6139 "\n\t\t If -context is in arguments, the objects are not deleted"
6140 "\n\t\t from the map of objects and names."
6141 "\n\t\t: Option -local enables removing of selected or named objects without"
6142 "\n\t\t: closing local selection context. Empty local selection context will be"
6144 "\n\t\t: Option -noupdate suppresses viewer redraw call."
6145 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
6146 __FILE__, VRemove, group);
6148 theCommands.Add("vdonly",
6149 "vdonly [-noupdate|-update] [name1] ... [name n]"
6150 "\n\t\t: Displays only selected or named objects",
6151 __FILE__,VDonly2,group);
6153 theCommands.Add("vdisplayall",
6154 "vidsplayall [-local]"
6155 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
6156 "\n\t\t: Option -local enables displaying of the objects in local"
6157 "\n\t\t: selection context.",
6158 __FILE__, VDisplayAll, group);
6160 theCommands.Add("veraseall",
6161 "veraseall [-local]"
6162 "\n\t\t: Erases all objects displayed in the viewer."
6163 "\n\t\t: Option -local enables erasing of the objects in local"
6164 "\n\t\t: selection context.",
6165 __FILE__, VErase, group);
6167 theCommands.Add("verasetype",
6169 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
6170 __FILE__, VEraseType, group);
6171 theCommands.Add("vbounding",
6172 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
6173 "\n\t\t: [-print] [-hide]"
6174 "\n\t\t: Temporarily display bounding box of specified Interactive"
6175 "\n\t\t: Objects, or print it to console if -print is specified."
6176 "\n\t\t: Already displayed box might be hidden by -hide option.",
6177 __FILE__,VBounding,group);
6179 theCommands.Add("vdisplaytype",
6180 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
6181 __FILE__,VDisplayType,group);
6183 theCommands.Add("vsetdispmode",
6184 "vsetdispmode [name] mode(1,2,..)"
6185 "\n\t\t: Sets display mode for all, selected or named objects.",
6186 __FILE__,VDispMode,group);
6188 theCommands.Add("vunsetdispmode",
6189 "vunsetdispmode [name]"
6190 "\n\t\t: Unsets custom display mode for selected or named objects.",
6191 __FILE__,VDispMode,group);
6193 theCommands.Add("vdir",
6194 "Lists all objects displayed in 3D viewer",
6195 __FILE__,VDir,group);
6197 #ifdef HAVE_FREEIMAGE
6198 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
6200 #define DUMP_FORMATS "{ppm}"
6202 theCommands.Add("vdump",
6203 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
6204 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
6205 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
6206 "\n\t\t: [-tileSize Size=0]"
6207 "\n\t\t: Dumps content of the active view into image file",
6208 __FILE__,VDump,group);
6210 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
6211 __FILE__,VSubInt,group);
6213 theCommands.Add("vaspects",
6214 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
6215 "\n\t\t: [-setVisibility 0|1]"
6216 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
6217 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
6218 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
6219 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
6220 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6221 "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
6222 "\n\t\t: [-unsetMarkerType]"
6223 "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"
6224 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
6225 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
6226 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
6227 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
6228 "\n\t\t: [-isoontriangulation 0|1]"
6229 "\n\t\t: [-setMaxParamValue {value}]"
6230 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
6231 "\n\t\t: [-setHatch HatchStyle]"
6232 "\n\t\t: Manage presentation properties of all, selected or named objects."
6233 "\n\t\t: When -subshapes is specified than following properties will be"
6234 "\n\t\t: assigned to specified sub-shapes."
6235 "\n\t\t: When -defaults is specified than presentation properties will be"
6236 "\n\t\t: assigned to all objects that have not their own specified properties"
6237 "\n\t\t: and to all objects to be displayed in the future."
6238 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
6239 __FILE__,VAspects,group);
6241 theCommands.Add("vsetcolor",
6242 "vsetcolor [-noupdate|-update] [name] ColorName"
6243 "\n\t\t: Sets color for all, selected or named objects."
6244 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
6245 __FILE__,VAspects,group);
6247 theCommands.Add("vunsetcolor",
6248 "vunsetcolor [-noupdate|-update] [name]"
6249 "\n\t\t: Resets color for all, selected or named objects."
6250 "\n\t\t: Alias for vaspects -unsetcolor [name].",
6251 __FILE__,VAspects,group);
6253 theCommands.Add("vsettransparency",
6254 "vsettransparency [-noupdate|-update] [name] Coefficient"
6255 "\n\t\t: Sets transparency for all, selected or named objects."
6256 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
6257 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
6258 __FILE__,VAspects,group);
6260 theCommands.Add("vunsettransparency",
6261 "vunsettransparency [-noupdate|-update] [name]"
6262 "\n\t\t: Resets transparency for all, selected or named objects."
6263 "\n\t\t: Alias for vaspects -unsettransp [name].",
6264 __FILE__,VAspects,group);
6266 theCommands.Add("vsetmaterial",
6267 "vsetmaterial [-noupdate|-update] [name] MaterialName"
6268 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
6269 __FILE__,VAspects,group);
6271 theCommands.Add("vunsetmaterial",
6272 "vunsetmaterial [-noupdate|-update] [name]"
6273 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
6274 __FILE__,VAspects,group);
6276 theCommands.Add("vsetwidth",
6277 "vsetwidth [-noupdate|-update] [name] width(0->10)"
6278 "\n\t\t: Alias for vaspects -setwidth [name] width.",
6279 __FILE__,VAspects,group);
6281 theCommands.Add("vunsetwidth",
6282 "vunsetwidth [-noupdate|-update] [name]"
6283 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
6284 __FILE__,VAspects,group);
6286 theCommands.Add("vsetinteriorstyle",
6287 "vsetinteriorstyle [-noupdate|-update] [name] style"
6288 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
6289 __FILE__,VSetInteriorStyle,group);
6291 theCommands.Add("vsensdis",
6292 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
6293 "\n\t\t: Standard entity types are those defined in Select3D package:"
6294 "\n\t\t: - sensitive box"
6295 "\n\t\t: - sensitive face"
6296 "\n\t\t: - sensitive curve"
6297 "\n\t\t: - sensitive segment"
6298 "\n\t\t: - sensitive circle"
6299 "\n\t\t: - sensitive point"
6300 "\n\t\t: - sensitive triangulation"
6301 "\n\t\t: - sensitive triangle"
6302 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
6303 __FILE__,VDispSensi,group);
6305 theCommands.Add("vsensera",
6306 "vsensera : erase active entities",
6307 __FILE__,VClearSensi,group);
6309 theCommands.Add("vsetshading",
6310 "vsetshading : vsetshading name Quality(default=0.0008) "
6311 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
6312 __FILE__,VShading,group);
6314 theCommands.Add("vunsetshading",
6315 "vunsetshading :vunsetshading name "
6316 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
6317 __FILE__,VShading,group);
6319 theCommands.Add ("vtexture",
6320 "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
6321 "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]"
6322 "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
6323 "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
6324 "\n\t\t: [-modulate {on|off}]"
6325 "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
6326 "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
6327 "\n\t\t: [-default]"
6328 "\n\t\t: The texture can be specified by filepath"
6329 "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
6330 "\n\t\t: The options are:"
6331 "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
6332 "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
6333 "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
6334 "\n\t\t: -modulate Enable or disable texture color modulation"
6335 "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
6336 "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
6337 "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
6338 "\n\t\t: -setFilter Setup texture filter"
6339 "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
6340 "\n\t\t: -default Sets texture mapping default parameters",
6341 __FILE__, VTexture, group);
6343 theCommands.Add("vtexscale",
6344 "vtexscale name ScaleU ScaleV"
6345 "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
6346 __FILE__,VTexture,group);
6348 theCommands.Add("vtexorigin",
6349 "vtexorigin name OriginU OriginV"
6350 "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
6351 __FILE__,VTexture,group);
6353 theCommands.Add("vtexrepeat",
6354 "vtexrepeat name RepeatU RepeatV"
6355 "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
6358 theCommands.Add("vtexdefault",
6360 "\n\t\t: Alias for vtexture name -default.",
6363 theCommands.Add("vsetam",
6364 "vsetam [shapename] mode"
6365 "\n\t\t: Activates selection mode for all selected or named shapes."
6366 "\n\t\t: Mod can be:"
6367 "\n\t\t: 0 - for shape itself"
6368 "\n\t\t: 1 - vertices"
6372 "\n\t\t: 5 - shells"
6373 "\n\t\t: 6 - solids"
6374 "\n\t\t: 7 - compounds"
6375 __FILE__,VActivatedMode,group);
6377 theCommands.Add("vunsetam",
6378 "vunsetam : Deactivates all selection modes for all shapes.",
6379 __FILE__,VActivatedMode,group);
6381 theCommands.Add("vstate",
6382 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
6383 "\n\t\t: Reports show/hidden state for selected or named objects"
6384 "\n\t\t: -entities - print low-level information about detected entities"
6385 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
6386 __FILE__,VState,group);
6388 theCommands.Add("vpickshapes",
6389 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
6390 __FILE__,VPickShape,group);
6392 theCommands.Add("vtypes",
6393 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
6396 theCommands.Add("vr",
6398 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
6399 __FILE__,vr, group);
6401 theCommands.Add("vselfilter",
6402 "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
6403 "\nSets selection shape type filter in context or remove all filters."
6404 "\n : Option -type set type of selection filter. Filters are applyed with Or combination."
6405 "\n : Option -clear remove all filters in context",
6406 __FILE__,VSelFilter,group);
6408 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
6409 __FILE__, VPickSelected, group);
6411 theCommands.Add ("vloadselection",
6412 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
6413 "\n\t\t: primitives for the shapes with names given without displaying them."
6414 "\n\t\t: -local - open local context before selection computation",
6415 __FILE__, VLoadSelection, group);
6417 theCommands.Add("vbsdf", "vbsdf [name] [options]"
6418 "\nAdjusts parameters of material BSDF:"
6419 "\n -help : Shows this message"
6420 "\n -print : Print BSDF"
6421 "\n -kd : Weight of the Lambertian BRDF"
6422 "\n -kr : Weight of the reflection BRDF"
6423 "\n -kt : Weight of the transmission BTDF"
6424 "\n -ks : Weight of the glossy Blinn BRDF"
6425 "\n -le : Self-emitted radiance"
6426 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
6427 "\n Schlick x y z, Dielectric x, Conductor x y"
6428 "\n -roughness : Roughness of material (Blinn's exponent)"
6429 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
6430 "\n -absorpcolor : Absorption color (only for transparent material)"
6431 "\n -normalize : Normalize BSDF coefficients",
6432 __FILE__, VBsdf, group);
6436 //=====================================================================
6437 //========================= for testing Draft and Rib =================
6438 //=====================================================================
6439 #include <BRepOffsetAPI_MakeThickSolid.hxx>
6440 #include <DBRep.hxx>
6441 #include <TopoDS_Face.hxx>
6442 #include <gp_Pln.hxx>
6443 #include <AIS_KindOfSurface.hxx>
6444 #include <BRepOffsetAPI_DraftAngle.hxx>
6445 #include <Precision.hxx>
6446 #include <BRepAlgo.hxx>
6447 #include <OSD_Environment.hxx>
6448 #include <DrawTrSurf.hxx>
6449 //#include <DbgTools.hxx>
6450 //#include <FeatAlgo_MakeLinearForm.hxx>
6455 //=======================================================================
6456 //function : IsValid
6458 //=======================================================================
6459 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
6460 const TopoDS_Shape& theResult,
6461 const Standard_Boolean closedSolid,
6462 const Standard_Boolean GeomCtrl)
6464 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
6465 TCollection_AsciiString checkValid = check.Value();
6466 Standard_Boolean ToCheck = Standard_True;
6467 if (!checkValid.IsEmpty()) {
6469 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
6471 if ( checkValid=="true" || checkValid=="TRUE" ) {
6472 ToCheck= Standard_False;
6476 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
6479 Standard_Boolean IsValid = Standard_True;
6481 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
6486 //===============================================================================
6487 // TDraft : test draft, uses AIS Viewer
6488 // Solid Face Plane Angle Reverse
6489 //===============================================================================
6490 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
6492 if (argc < 5) return 1;
6493 // argv[1] - TopoDS_Shape Solid
6494 // argv[2] - TopoDS_Shape Face
6495 // argv[3] - TopoDS_Shape Plane
6496 // argv[4] - Standard_Real Angle
6497 // argv[5] - Standard_Integer Reverse
6499 // Sprintf(prefix, argv[1]);
6500 Standard_Real anAngle = 0;
6501 Standard_Boolean Rev = Standard_False;
6502 Standard_Integer rev = 0;
6503 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
6504 TopoDS_Shape face = GetShapeFromName(argv[2]);
6505 TopoDS_Face Face = TopoDS::Face(face);
6506 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
6507 if (Plane.IsNull ()) {
6508 di << "TEST : Plane is NULL\n";
6511 anAngle = Draw::Atof(argv[4]);
6512 anAngle = 2*M_PI * anAngle / 360.0;
6514 Handle( Geom_Surface )aSurf;
6515 AIS_KindOfSurface aSurfType;
6516 Standard_Real Offset;
6518 if(argc > 4) { // == 5
6519 rev = Draw::Atoi(argv[5]);
6520 Rev = (rev)? Standard_True : Standard_False;
6523 TopoDS_Face face2 = TopoDS::Face(Plane);
6524 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
6526 di << "TEST : Can't find plane\n";
6530 aDir = aPln.Axis().Direction();
6533 if (Plane.Orientation() == TopAbs_REVERSED)
6535 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
6537 BRepOffsetAPI_DraftAngle Draft (Solid);
6539 if(Abs(anAngle)< Precision::Angular()) {
6540 di << "TEST : NULL angle\n";
6543 if(Rev) anAngle = - anAngle;
6544 Draft.Add (Face, aDir, anAngle, aPln);
6546 if (!Draft.IsDone()) {
6547 di << "TEST : Draft Not DONE \n";
6550 TopTools_ListOfShape Larg;
6552 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
6553 di << "TEST : DesignAlgo returns Not valid\n";
6557 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
6558 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
6560 if ( !ais.IsNull() ) {
6561 ais->SetColor(DEFAULT_COLOR);
6562 ais->SetMaterial(DEFAULT_MATERIAL);
6563 // Display the AIS_Shape without redraw
6564 Ctx->Display(ais, Standard_False);
6566 const char *Name = "draft1";
6567 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
6569 Handle(AIS_InteractiveObject) an_object =
6570 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
6571 if (!an_object.IsNull()) {
6572 Ctx->Remove(an_object,
6574 GetMapOfAIS().UnBind2(Name) ;
6577 GetMapOfAIS().Bind(ais, Name);
6578 // DBRep::Set("draft", ais->Shape());
6580 Ctx->Display(ais, Standard_True);
6584 //==============================================================================
6585 //function : splitParameter
6586 //purpose : Split parameter string to parameter name and parameter value
6587 //==============================================================================
6588 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
6589 TCollection_AsciiString& theName,
6590 TCollection_AsciiString& theValue)
6592 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
6594 if (aParamNameEnd == 0)
6596 return Standard_False;
6599 TCollection_AsciiString aString (theString);
6600 if (aParamNameEnd != 0)
6602 theValue = aString.Split (aParamNameEnd);
6603 aString.Split (aString.Length() - 1);
6607 return Standard_True;
6610 //============================================================================
6612 //============================================================================
6613 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
6616 DrawTrSurf::BasicCommands(theCommands);
6617 const char* group = "Check Features Operations commands";
6619 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
6621 &TDraft,group); //Draft_Modification
6624 //==============================================================================
6625 // ViewerTest::Factory
6626 //==============================================================================
6627 void ViewerTest::Factory(Draw_Interpretor& theDI)
6629 // definition of Viewer Command
6630 ViewerTest::Commands(theDI);
6633 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
6637 // Declare entry point PLUGINFACTORY