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 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by Robert Coublanc [nov 16-17-18 1998]
19 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 // ViewerTest_ObjectCommands.cxx
21 // ViewerTest_RelationCommands.cxx
22 // -add Functions and commands for interactive selection of shapes and objects
23 // in AIS Viewers. (PickShape(s), PickObject(s),
25 #include <Standard_Stream.hxx>
27 #include <ViewerTest.hxx>
28 #include <ViewerTest_CmdParser.hxx>
30 #include <TopLoc_Location.hxx>
31 #include <TopTools_HArray1OfShape.hxx>
32 #include <TColStd_HArray1OfTransient.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
34 #include <TColStd_HSequenceOfAsciiString.hxx>
35 #include <TColStd_MapOfTransient.hxx>
36 #include <OSD_Timer.hxx>
37 #include <Geom_Axis2Placement.hxx>
38 #include <Geom_Axis1Placement.hxx>
39 #include <gp_Trsf.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <BRepAdaptor_Curve.hxx>
42 #include <StdSelect_ShapeTypeFilter.hxx>
44 #include <AIS_ColoredShape.hxx>
45 #include <AIS_InteractiveObject.hxx>
46 #include <AIS_Trihedron.hxx>
47 #include <AIS_Axis.hxx>
48 #include <AIS_Relation.hxx>
49 #include <AIS_TypeFilter.hxx>
50 #include <AIS_SignatureFilter.hxx>
51 #include <AIS_LocalContext.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Aspect_InteriorStyle.hxx>
55 #include <Aspect_Window.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_AspectLine3d.hxx>
58 #include <Graphic3d_CStructure.hxx>
59 #include <Graphic3d_TextureRoot.hxx>
60 #include <Image_AlienPixMap.hxx>
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_ShadingAspect.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64 #include <Prs3d_PointAspect.hxx>
65 #include <Select3D_SensitiveWire.hxx>
66 #include <SelectMgr_EntityOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
68 #include <StdSelect_ViewerSelector3d.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <ViewerTest_AutoUpdater.hxx>
74 #include <Draw_Interpretor.hxx>
75 #include <TCollection_AsciiString.hxx>
76 #include <Draw_PluginMacro.hxx>
78 // avoid warnings on 'extern "C"' functions returning C++ classes
80 #define _CRT_SECURE_NO_DEPRECATE
81 #pragma warning(4:4190)
82 #pragma warning (disable:4996)
85 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
94 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
96 //=======================================================================
97 //function : GetColorFromName
98 //purpose : get the Quantity_NameOfColor from a string
99 //=======================================================================
101 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103 Quantity_NameOfColor aColor = DEFAULT_COLOR;
104 Quantity_Color::ColorFromName (theName, aColor);
108 //=======================================================================
109 //function : ParseColor
111 //=======================================================================
113 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
114 const char** theArgVec,
115 Quantity_Color& theColor)
117 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
119 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
124 else if (theArgNb >= 3)
126 const TCollection_AsciiString anRgbStr[3] =
132 if (!anRgbStr[0].IsRealValue()
133 || !anRgbStr[1].IsRealValue()
134 || !anRgbStr[2].IsRealValue())
139 Graphic3d_Vec4d anRgb;
140 anRgb.x() = anRgbStr[0].RealValue();
141 anRgb.y() = anRgbStr[1].RealValue();
142 anRgb.z() = anRgbStr[2].RealValue();
143 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
144 || anRgb.y() < 0.0 || anRgb.y() > 1.0
145 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
147 std::cout << "Error: RGB color values should be within range 0..1!\n";
151 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
158 //=======================================================================
159 //function : GetTypeNames
161 //=======================================================================
162 static const char** GetTypeNames()
164 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
165 "Shape","ConnectedShape","MultiConn.Shape",
166 "ConnectedInter.","MultiConn.",
167 "Constraint","Dimension"};
168 static const char** ThePointer = names;
172 //=======================================================================
173 //function : GetTypeAndSignfromString
175 //=======================================================================
176 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
178 const char ** thefullnames = GetTypeNames();
179 Standard_Integer index(-1);
181 for(Standard_Integer i=0;i<=13 && index==-1;i++)
182 if(!strcasecmp(name,thefullnames[i]))
186 TheType = AIS_KOI_None;
192 TheType = AIS_KOI_Datum;
196 TheType = AIS_KOI_Shape;
200 TheType = AIS_KOI_Object;
204 TheType = AIS_KOI_Relation;
213 #include <Draw_Interpretor.hxx>
215 #include <Draw_Appli.hxx>
219 #include <TCollection_AsciiString.hxx>
220 #include <V3d_Viewer.hxx>
221 #include <V3d_View.hxx>
224 #include <AIS_InteractiveContext.hxx>
225 #include <AIS_Shape.hxx>
226 #include <AIS_TexturedShape.hxx>
227 #include <AIS_DisplayMode.hxx>
228 #include <TColStd_MapOfInteger.hxx>
229 #include <AIS_MapOfInteractive.hxx>
230 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
231 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
232 #include <ViewerTest_EventManager.hxx>
234 #include <TopoDS_Solid.hxx>
235 #include <BRepTools.hxx>
236 #include <BRep_Builder.hxx>
237 #include <TopAbs_ShapeEnum.hxx>
239 #include <TopoDS.hxx>
240 #include <BRep_Tool.hxx>
243 #include <Draw_Window.hxx>
244 #include <AIS_ListIteratorOfListOfInteractive.hxx>
245 #include <AIS_ListOfInteractive.hxx>
246 #include <AIS_DisplayMode.hxx>
247 #include <TopTools_ListOfShape.hxx>
248 #include <BRepOffsetAPI_MakeThickSolid.hxx>
249 #include <BRepOffset.hxx>
251 //==============================================================================
252 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
253 //==============================================================================
254 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
255 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
259 //=======================================================================
262 //=======================================================================
263 Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
264 const Handle(AIS_InteractiveObject)& theObject,
265 const Standard_Boolean theToUpdate,
266 const Standard_Boolean theReplaceIfExists)
268 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
269 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
272 std::cout << "Error: AIS context is not available.\n";
273 return Standard_False;
276 if (aMap.IsBound2 (theName))
278 if (!theReplaceIfExists)
280 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
281 << "Please use another name.\n";
282 return Standard_False;
285 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
286 if (!anOldObj.IsNull())
288 aCtx->Remove (anOldObj, Standard_True);
290 aMap.UnBind2 (theName);
293 if (theObject.IsNull())
295 // object with specified name has been already unbound
296 return Standard_True;
299 // unbind AIS object if it was bound with another name
300 aMap.UnBind1 (theObject);
302 // can be registered without rebinding
303 aMap.Bind (theObject, theName);
304 aCtx->Display (theObject, theToUpdate);
305 return Standard_True;
308 //! Alias for ViewerTest::Display(), compatibility with old code.
309 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
310 const Handle(AIS_InteractiveObject)& theObject,
311 Standard_Boolean theReplaceIfExists = Standard_True)
313 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
316 static TColStd_MapOfInteger theactivatedmodes(8);
317 static TColStd_ListOfTransient theEventMgrs;
319 static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
320 const Handle(AIS_InteractiveContext)& Ctx)
322 theEventMgrs.Clear();
323 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
326 static Handle(V3d_View)& a3DView()
328 static Handle(V3d_View) Viou;
333 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
334 static Handle(AIS_InteractiveContext) aContext;
338 const Handle(V3d_View)& ViewerTest::CurrentView()
342 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
347 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
349 return TheAISContext();
352 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
354 TheAISContext() = aCtx;
355 ViewerTest::ResetEventManager();
358 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
360 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
363 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
365 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
369 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
370 theEventMgrs.Prepend(EM);
373 void ViewerTest::UnsetEventManager()
375 theEventMgrs.RemoveFirst();
379 void ViewerTest::ResetEventManager()
381 const Handle(V3d_View) aView = ViewerTest::CurrentView();
382 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
385 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
387 Handle(ViewerTest_EventManager) EM;
388 if(theEventMgrs.IsEmpty()) return EM;
389 Handle(Standard_Transient) Tr = theEventMgrs.First();
390 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
394 //=======================================================================
395 //function : Get Context and active view
397 //=======================================================================
398 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
399 Handle(V3d_View)& theView)
401 theCtx = ViewerTest::GetAISContext();
402 theView = ViewerTest::CurrentView();
406 std::cout << "Error: cannot find an active view!\n";
407 return Standard_False;
409 return Standard_True;
412 //==============================================================================
413 //function : GetShapeFromName
414 //purpose : Compute an Shape from a draw variable or a file name
415 //==============================================================================
417 static TopoDS_Shape GetShapeFromName(const char* name)
419 TopoDS_Shape S = DBRep::Get(name);
422 BRep_Builder aBuilder;
423 BRepTools::Read( S, name, aBuilder);
429 //==============================================================================
430 //function : GetAISShapeFromName
431 //purpose : Compute an AIS_Shape from a draw variable or a file name
432 //==============================================================================
433 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
435 Handle(AIS_Shape) retsh;
437 if(GetMapOfAIS().IsBound2(name)){
438 const Handle(AIS_InteractiveObject) IO =
439 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
441 if(IO->Type()==AIS_KOI_Shape) {
442 if(IO->Signature()==0){
443 retsh = *((Handle(AIS_Shape)*)&IO);
446 cout << "an Object which is not an AIS_Shape "
447 "already has this name!!!"<<endl;
454 TopoDS_Shape S = GetShapeFromName(name);
456 retsh = new AIS_Shape(S);
462 //==============================================================================
464 //purpose : Remove all the object from the viewer
465 //==============================================================================
466 void ViewerTest::Clear()
468 if ( !a3DView().IsNull() ) {
469 if (TheAISContext()->HasOpenedContext())
470 TheAISContext()->CloseLocalContext();
471 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
472 while ( it.More() ) {
473 cout << "Remove " << it.Key2() << endl;
474 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
475 TheAISContext()->Remove(anObj,Standard_False);
478 TheAISContext()->RebuildSelectionStructs();
479 TheAISContext()->UpdateCurrentViewer();
480 GetMapOfAIS().Clear();
484 //==============================================================================
485 //function : StandardModesActivation
486 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
488 //==============================================================================
489 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
491 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
493 if (TheAISContext()->HasOpenedContext())
494 aContext->CloseLocalContext();
497 if(!aContext->HasOpenedContext()) {
498 // To unhilight the preselected object
499 aContext->UnhilightCurrents(Standard_False);
500 // Open a local Context in order to be able to select subshape from
501 // the selected shape if any or for all if there is no selection
502 if (!aContext->FirstCurrentObject().IsNull()){
503 aContext->OpenLocalContext(Standard_False);
505 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
506 aContext->Load( aContext->Current(),-1,Standard_True);
510 aContext->OpenLocalContext();
513 const char *cmode="???";
516 case 0: cmode = "Shape"; break;
517 case 1: cmode = "Vertex"; break;
518 case 2: cmode = "Edge"; break;
519 case 3: cmode = "Wire"; break;
520 case 4: cmode = "Face"; break;
521 case 5: cmode = "Shell"; break;
522 case 6: cmode = "Solid"; break;
523 case 7: cmode = "Compsolid"; break;
524 case 8: cmode = "Compound"; break;
527 if(theactivatedmodes.Contains(mode))
529 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
530 theactivatedmodes.Remove(mode);
531 cout<<"Mode "<< cmode <<" OFF"<<endl;
535 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
536 theactivatedmodes.Add(mode);
537 cout<<"Mode "<< cmode << " ON" << endl;
542 //==============================================================================
543 //function : CopyIsoAspect
544 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
545 //==============================================================================
546 static Handle(Prs3d_IsoAspect) CopyIsoAspect
547 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
548 const Standard_Integer theNbIsos)
550 Quantity_Color aColor;
551 Aspect_TypeOfLine aType;
552 Standard_Real aWidth;
554 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
556 Handle(Prs3d_IsoAspect) aResult =
557 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
562 //==============================================================================
564 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
565 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
566 //==============================================================================
567 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
569 if (TheAISContext().IsNull()) {
570 di << argv[0] << " Call 'vinit' before!\n";
575 di << "Current number of isos : " <<
576 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
577 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
578 di << "IsoOnPlane mode is " <<
579 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
584 Standard_Integer aLastInd = argc - 1;
585 Standard_Boolean isChanged = Standard_False;
586 Standard_Integer aNbUIsos = 0;
587 Standard_Integer aNbVIsos = 0;
590 Standard_Boolean isIsoOnPlane = Standard_False;
592 if (strcmp(argv[aLastInd], "1") == 0) {
593 isIsoOnPlane = Standard_True;
594 isChanged = Standard_True;
595 } else if (strcmp(argv[aLastInd], "0") == 0) {
596 isIsoOnPlane = Standard_False;
597 isChanged = Standard_True;
601 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
602 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
605 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
606 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
608 TheAISContext()->IsoOnPlane(isIsoOnPlane);
611 // If there are no shapes provided set the default numbers.
612 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
613 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
620 for (i = 1; i <= aLastInd; i++) {
621 TCollection_AsciiString name(argv[i]);
622 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
625 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
626 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
627 const Handle(AIS_InteractiveObject) aShape =
628 Handle(AIS_InteractiveObject)::DownCast (anObj);
629 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
630 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
631 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
634 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
635 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
636 TheAISContext()->SetLocalAttributes
637 (aShape, CurDrawer, Standard_False);
638 TheAISContext()->Redisplay(aShape);
640 di << "Number of isos for " << argv[i] << " : "
641 << aUIso->Number() << " " << aVIso->Number() << "\n";
644 di << argv[i] << ": Not an AIS interactive object!\n";
647 di << argv[i] << ": Use 'vdisplay' before\n";
652 TheAISContext()->UpdateCurrentViewer();
658 static Standard_Integer VDispSensi (Draw_Interpretor& ,
659 Standard_Integer theArgNb,
664 std::cout << "Error: wrong syntax!\n";
668 Handle(AIS_InteractiveContext) aCtx;
669 Handle(V3d_View) aView;
670 if (!getCtxAndView (aCtx, aView))
675 aCtx->DisplayActiveSensitive (aView);
680 static Standard_Integer VClearSensi (Draw_Interpretor& ,
681 Standard_Integer theArgNb,
686 std::cout << "Error: wrong syntax!\n";
690 Handle(AIS_InteractiveContext) aCtx;
691 Handle(V3d_View) aView;
692 if (!getCtxAndView (aCtx, aView))
696 aCtx->ClearActiveSensitive (aView);
700 //==============================================================================
702 //purpose : To list the displayed object with their attributes
703 //==============================================================================
704 static int VDir (Draw_Interpretor& theDI,
708 if (!a3DView().IsNull())
713 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
714 anIter.More(); anIter.Next())
716 theDI << "\t" << anIter.Key2().ToCString() << "\n";
721 //==============================================================================
722 //function : VSelPrecision
723 //purpose : To set the selection tolerance value
724 //Draw arg : Selection tolerance value (real value determining the width and
725 // height of selecting frustum bases). Without arguments the function
726 // just prints current tolerance.
727 //==============================================================================
728 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
732 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
736 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
737 if( aContext.IsNull() )
742 Standard_Real aPixelTolerance = aContext->PixelTolerance();
743 di << "Pixel tolerance : " << aPixelTolerance << "\n";
747 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
749 if (anArg == "-unset")
751 aContext->SetPixelTolerance (-1.0);
755 aContext->SetPixelTolerance (anArg.RealValue());
762 //==============================================================================
764 //purpose : To dump the active view snapshot to image file
765 //==============================================================================
766 static Standard_Integer VDump (Draw_Interpretor& theDI,
767 Standard_Integer theArgNb,
768 Standard_CString* theArgVec)
772 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
776 Standard_Integer anArgIter = 1;
777 Standard_CString aFilePath = theArgVec[anArgIter++];
778 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
779 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
780 Standard_Integer aWidth = 0;
781 Standard_Integer aHeight = 0;
782 for (; anArgIter < theArgNb; ++anArgIter)
784 TCollection_AsciiString anArg (theArgVec[anArgIter]);
788 aBufferType = Graphic3d_BT_RGBA;
790 else if (anArg == "rgb")
792 aBufferType = Graphic3d_BT_RGB;
794 else if (anArg == "depth")
796 aBufferType = Graphic3d_BT_Depth;
798 else if (anArg == "l"
801 aStereoOpts = V3d_SDO_LEFT_EYE;
803 else if (anArg == "r"
806 aStereoOpts = V3d_SDO_RIGHT_EYE;
808 else if (anArg == "mono")
810 aStereoOpts = V3d_SDO_MONO;
812 else if (anArg == "w"
817 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
820 else if (++anArgIter >= theArgNb)
822 std::cout << "Error: integer value is expected right after 'width'\n";
825 aWidth = Draw::Atoi (theArgVec[anArgIter]);
827 else if (anArg == "h"
828 || anArg == "height")
832 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
835 if (++anArgIter >= theArgNb)
837 std::cout << "Error: integer value is expected right after 'height'\n";
840 aHeight = Draw::Atoi (theArgVec[anArgIter]);
842 else if (anArg.IsIntegerValue())
844 // compatibility with old syntax
848 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
851 else if (++anArgIter >= theArgNb)
853 std::cout << "Error: height value is expected right after width\n";
856 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
857 aHeight = Draw::Atoi (theArgVec[anArgIter]);
861 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
865 if ((aWidth <= 0 && aHeight > 0)
866 || (aWidth > 0 && aHeight <= 0))
868 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
872 Handle(V3d_View) aView = ViewerTest::CurrentView();
875 std::cout << "Error: cannot find an active view!\n";
879 if (aWidth <= 0 || aHeight <= 0)
881 if (aStereoOpts != V3d_SDO_MONO)
883 aView->Window()->Size (aWidth, aHeight);
887 if (!aView->Dump (aFilePath, aBufferType))
889 theDI << "Fail: view dump failed!\n";
895 Image_AlienPixMap aPixMap;
896 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
898 theDI << "Fail: view dump failed!\n";
902 if (aPixMap.SizeX() != Standard_Size(aWidth)
903 || aPixMap.SizeY() != Standard_Size(aHeight))
905 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
906 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
908 if (!aPixMap.Save (aFilePath))
910 theDI << "Fail: image can not be saved!\n";
916 //==============================================================================
917 //function : Displays,Erase...
920 //==============================================================================
921 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
922 const Standard_Integer Mode,
923 const Standard_Integer TypeOfOperation,
924 const Standard_Boolean Upd)
926 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
928 switch(TypeOfOperation){
930 Ctx->Display(IO,Mode,Upd);
938 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
940 Ctx->SetDisplayMode(IO,Mode,Upd);
945 Ctx->SetDisplayMode(0,Upd);
947 Ctx->UnsetDisplayMode(IO,Upd);
954 //=======================================================================
957 //=======================================================================
958 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
961 TCollection_AsciiString name;
964 // display others presentations
965 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
966 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
967 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
968 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
970 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
972 //unset displaymode.. comportement particulier...
973 if(TypeOfOperation==4){
975 if(Ctx->NbCurrents()==0 ||
976 Ctx->NbSelected()==0){
977 Handle(AIS_InteractiveObject) IO;
978 VwrTst_DispErase(IO,-1,4,Standard_False);
980 else if(!Ctx->HasOpenedContext()){
981 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
982 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
985 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
986 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
987 Ctx->UpdateCurrentViewer();
990 Handle(AIS_InteractiveObject) IO;
992 if(GetMapOfAIS().IsBound2(name)){
993 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
995 VwrTst_DispErase(IO,-1,4,Standard_True);
1000 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1001 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1002 Handle(AIS_InteractiveObject) IO;
1003 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1005 if(!Ctx->HasOpenedContext()){
1006 // set/unset display mode sur le Contexte...
1007 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1008 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1010 Ctx->UpdateCurrentViewer();
1013 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1014 Ctx->Display(Ctx->Interactive(),Dmode);
1018 Handle(AIS_InteractiveObject) IO;
1020 if(GetMapOfAIS().IsBound2(name))
1021 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1023 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1029 //=======================================================================
1032 //=======================================================================
1033 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1035 if(argc==1) return 1;
1036 Standard_Integer On = Draw::Atoi(argv[1]);
1037 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1041 if(!Ctx->HasOpenedContext()){
1042 di<<"sub intensite ";
1045 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1046 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1048 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1050 di <<"passage dans off"<<"\n";
1051 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1056 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1058 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1060 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1063 Ctx->UpdateCurrentViewer();
1066 Handle(AIS_InteractiveObject) IO;
1067 TCollection_AsciiString name = argv[2];
1068 if(GetMapOfAIS().IsBound2(name)){
1069 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1072 Ctx->SubIntensityOn(IO);
1074 Ctx->SubIntensityOff(IO);
1082 //! Auxiliary class to iterate presentations from different collections.
1083 class ViewTest_PrsIter
1087 //! Create and initialize iterator object.
1088 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1089 : mySource (IterSource_All)
1091 NCollection_Sequence<TCollection_AsciiString> aNames;
1092 if (!theName.IsEmpty())
1093 aNames.Append (theName);
1097 //! Create and initialize iterator object.
1098 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1099 : mySource (IterSource_All)
1104 //! Initialize the iterator.
1105 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1107 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1109 mySelIter.Nullify();
1110 myCurrent.Nullify();
1111 myCurrentTrs.Nullify();
1112 if (!mySeq.IsEmpty())
1114 mySource = IterSource_List;
1115 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1117 else if (aCtx->NbCurrents() > 0)
1119 mySource = IterSource_Selected;
1121 mySelIter->InitCurrent();
1125 mySource = IterSource_All;
1126 myMapIter.Initialize (GetMapOfAIS());
1131 const TCollection_AsciiString& CurrentName() const
1133 return myCurrentName;
1136 const Handle(AIS_InteractiveObject)& Current() const
1141 const Handle(Standard_Transient)& CurrentTrs() const
1143 return myCurrentTrs;
1146 //! @return true if iterator points to valid object within collection
1147 Standard_Boolean More() const
1151 case IterSource_All: return myMapIter.More();
1152 case IterSource_List: return mySeqIter.More();
1153 case IterSource_Selected: return mySelIter->MoreCurrent();
1155 return Standard_False;
1158 //! Go to the next item.
1161 myCurrentName.Clear();
1162 myCurrentTrs.Nullify();
1163 myCurrent.Nullify();
1166 case IterSource_All:
1171 case IterSource_List:
1176 case IterSource_Selected:
1178 mySelIter->NextCurrent();
1191 case IterSource_All:
1193 if (myMapIter.More())
1195 myCurrentName = myMapIter.Key2();
1196 myCurrentTrs = myMapIter.Key1();
1197 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1201 case IterSource_List:
1203 if (mySeqIter.More())
1205 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1207 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1210 myCurrentName = mySeqIter.Value();
1211 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1212 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1216 case IterSource_Selected:
1218 if (mySelIter->MoreCurrent())
1220 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1221 myCurrent = mySelIter->Current();
1239 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1240 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1241 NCollection_Sequence<TCollection_AsciiString> mySeq;
1242 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1244 TCollection_AsciiString myCurrentName;//!< current item name
1245 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1246 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1248 IterSource mySource; //!< iterated collection
1252 //==============================================================================
1253 //function : VInteriorStyle
1254 //purpose : sets interior style of the a selected or named or displayed shape
1255 //==============================================================================
1256 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1257 Standard_Integer theArgNb,
1258 const char** theArgVec)
1260 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1261 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1264 std::cerr << "Error: no active view!\n";
1268 Standard_Integer anArgIter = 1;
1269 for (; anArgIter < theArgNb; ++anArgIter)
1271 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1276 TCollection_AsciiString aName;
1277 if (theArgNb - anArgIter == 2)
1279 aName = theArgVec[anArgIter++];
1281 else if (theArgNb - anArgIter != 1)
1283 std::cout << "Error: wrong number of arguments! See usage:\n";
1284 theDI.PrintHelp (theArgVec[0]);
1287 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1288 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1289 aStyleArg.LowerCase();
1290 if (aStyleArg == "empty")
1294 else if (aStyleArg == "hollow")
1298 else if (aStyleArg == "hatch")
1302 else if (aStyleArg == "solid")
1306 else if (aStyleArg == "hiddenline")
1312 anInterStyle = aStyleArg.IntegerValue();
1314 if (anInterStyle < Aspect_IS_EMPTY
1315 || anInterStyle > Aspect_IS_HIDDENLINE)
1317 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1318 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1322 if (!aName.IsEmpty()
1323 && !GetMapOfAIS().IsBound2 (aName))
1325 std::cout << "Error: object " << aName << " is not displayed!\n";
1329 if (aCtx->HasOpenedContext())
1331 aCtx->CloseLocalContext();
1333 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1335 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1338 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1339 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1340 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1341 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1342 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1348 //! Auxiliary structure for VAspects
1349 struct ViewerTest_AspectsChangeSet
1351 Standard_Integer ToSetVisibility;
1352 Standard_Integer Visibility;
1354 Standard_Integer ToSetColor;
1355 Quantity_Color Color;
1357 Standard_Integer ToSetLineWidth;
1358 Standard_Real LineWidth;
1360 Standard_Integer ToSetTransparency;
1361 Standard_Real Transparency;
1363 Standard_Integer ToSetMaterial;
1364 Graphic3d_NameOfMaterial Material;
1365 TCollection_AsciiString MatName;
1367 NCollection_Sequence<TopoDS_Shape> SubShapes;
1369 Standard_Integer ToSetShowFreeBoundary;
1370 Standard_Integer ToSetFreeBoundaryWidth;
1371 Standard_Real FreeBoundaryWidth;
1372 Standard_Integer ToSetFreeBoundaryColor;
1373 Quantity_Color FreeBoundaryColor;
1375 //! Empty constructor
1376 ViewerTest_AspectsChangeSet()
1377 : ToSetVisibility (0),
1380 Color (DEFAULT_COLOR),
1383 ToSetTransparency (0),
1386 Material (Graphic3d_NOM_DEFAULT),
1387 ToSetShowFreeBoundary (0),
1388 ToSetFreeBoundaryWidth (0),
1389 FreeBoundaryWidth (1.0),
1390 ToSetFreeBoundaryColor (0),
1391 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
1393 //! @return true if no changes have been requested
1394 Standard_Boolean IsEmpty() const
1396 return ToSetVisibility == 0
1397 && ToSetLineWidth == 0
1398 && ToSetTransparency == 0
1400 && ToSetMaterial == 0
1401 && ToSetShowFreeBoundary == 0
1402 && ToSetFreeBoundaryColor == 0
1403 && ToSetFreeBoundaryWidth == 0;
1406 //! @return true if properties are valid
1407 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1409 Standard_Boolean isOk = Standard_True;
1410 if (Visibility != 0 && Visibility != 1)
1412 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1413 isOk = Standard_False;
1415 if (LineWidth <= 0.0
1416 || LineWidth > 10.0)
1418 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1419 isOk = Standard_False;
1421 if (Transparency < 0.0
1422 || Transparency > 1.0)
1424 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1425 isOk = Standard_False;
1428 && ToSetTransparency)
1430 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1431 isOk = Standard_False;
1433 if (ToSetMaterial == 1
1434 && Material == Graphic3d_NOM_DEFAULT)
1436 std::cout << "Error: unknown material " << MatName << ".\n";
1437 isOk = Standard_False;
1439 if (FreeBoundaryWidth <= 0.0
1440 || FreeBoundaryWidth > 10.0)
1442 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1443 isOk = Standard_False;
1450 //==============================================================================
1451 //function : VAspects
1453 //==============================================================================
1454 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1455 Standard_Integer theArgNb,
1456 const char** theArgVec)
1458 TCollection_AsciiString aCmdName (theArgVec[0]);
1459 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1460 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1463 std::cerr << "Error: no active view!\n";
1467 Standard_Integer anArgIter = 1;
1468 Standard_Boolean isDefaults = Standard_False;
1469 NCollection_Sequence<TCollection_AsciiString> aNames;
1470 for (; anArgIter < theArgNb; ++anArgIter)
1472 TCollection_AsciiString anArg = theArgVec[anArgIter];
1473 if (anUpdateTool.parseRedrawMode (anArg))
1477 else if (!anArg.IsEmpty()
1478 && anArg.Value (1) != '-')
1480 aNames.Append (anArg);
1484 if (anArg == "-defaults")
1486 isDefaults = Standard_True;
1493 if (!aNames.IsEmpty() && isDefaults)
1495 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1499 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1500 aChanges.Append (ViewerTest_AspectsChangeSet());
1501 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1503 // parse syntax of legacy commands
1504 if (aCmdName == "vsetwidth")
1506 if (aNames.IsEmpty()
1507 || !aNames.Last().IsRealValue())
1509 std::cout << "Error: not enough arguments!\n";
1512 aChangeSet->ToSetLineWidth = 1;
1513 aChangeSet->LineWidth = aNames.Last().RealValue();
1514 aNames.Remove (aNames.Length());
1516 else if (aCmdName == "vunsetwidth")
1518 aChangeSet->ToSetLineWidth = -1;
1520 else if (aCmdName == "vsetcolor")
1522 if (aNames.IsEmpty())
1524 std::cout << "Error: not enough arguments!\n";
1527 aChangeSet->ToSetColor = 1;
1529 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1530 Standard_Boolean isOk = Standard_False;
1531 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1533 aChangeSet->Color = aColor;
1534 aNames.Remove (aNames.Length());
1535 isOk = Standard_True;
1537 else if (aNames.Length() >= 3)
1539 const TCollection_AsciiString anRgbStr[3] =
1541 aNames.Value (aNames.Upper() - 2),
1542 aNames.Value (aNames.Upper() - 1),
1543 aNames.Value (aNames.Upper() - 0)
1545 isOk = anRgbStr[0].IsRealValue()
1546 && anRgbStr[1].IsRealValue()
1547 && anRgbStr[2].IsRealValue();
1550 Graphic3d_Vec4d anRgb;
1551 anRgb.x() = anRgbStr[0].RealValue();
1552 anRgb.y() = anRgbStr[1].RealValue();
1553 anRgb.z() = anRgbStr[2].RealValue();
1554 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1555 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1556 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1558 std::cout << "Error: RGB color values should be within range 0..1!\n";
1561 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1562 aNames.Remove (aNames.Length());
1563 aNames.Remove (aNames.Length());
1564 aNames.Remove (aNames.Length());
1569 std::cout << "Error: not enough arguments!\n";
1573 else if (aCmdName == "vunsetcolor")
1575 aChangeSet->ToSetColor = -1;
1577 else if (aCmdName == "vsettransparency")
1579 if (aNames.IsEmpty()
1580 || !aNames.Last().IsRealValue())
1582 std::cout << "Error: not enough arguments!\n";
1585 aChangeSet->ToSetTransparency = 1;
1586 aChangeSet->Transparency = aNames.Last().RealValue();
1587 aNames.Remove (aNames.Length());
1589 else if (aCmdName == "vunsettransparency")
1591 aChangeSet->ToSetTransparency = -1;
1593 else if (aCmdName == "vsetmaterial")
1595 if (aNames.IsEmpty())
1597 std::cout << "Error: not enough arguments!\n";
1600 aChangeSet->ToSetMaterial = 1;
1601 aChangeSet->MatName = aNames.Last();
1602 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1603 aNames.Remove (aNames.Length());
1605 else if (aCmdName == "vunsetmaterial")
1607 aChangeSet->ToSetMaterial = -1;
1609 else if (anArgIter >= theArgNb)
1611 std::cout << "Error: not enough arguments!\n";
1615 if (!aChangeSet->IsEmpty())
1617 anArgIter = theArgNb;
1619 for (; anArgIter < theArgNb; ++anArgIter)
1621 TCollection_AsciiString anArg = theArgVec[anArgIter];
1623 if (anArg == "-setwidth"
1624 || anArg == "-setlinewidth")
1626 if (++anArgIter >= theArgNb)
1628 std::cout << "Error: wrong syntax at " << anArg << "\n";
1631 aChangeSet->ToSetLineWidth = 1;
1632 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1634 else if (anArg == "-unsetwidth"
1635 || anArg == "-unsetlinewidth")
1637 aChangeSet->ToSetLineWidth = -1;
1638 aChangeSet->LineWidth = 1.0;
1640 else if (anArg == "-settransp"
1641 || anArg == "-settransparency")
1643 if (++anArgIter >= theArgNb)
1645 std::cout << "Error: wrong syntax at " << anArg << "\n";
1648 aChangeSet->ToSetTransparency = 1;
1649 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1650 if (aChangeSet->Transparency >= 0.0
1651 && aChangeSet->Transparency <= Precision::Confusion())
1653 aChangeSet->ToSetTransparency = -1;
1654 aChangeSet->Transparency = 0.0;
1657 else if (anArg == "-setvis"
1658 || anArg == "-setvisibility")
1660 if (++anArgIter >= theArgNb)
1662 std::cout << "Error: wrong syntax at " << anArg << "\n";
1666 aChangeSet->ToSetVisibility = 1;
1667 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1669 else if (anArg == "-setalpha")
1671 if (++anArgIter >= theArgNb)
1673 std::cout << "Error: wrong syntax at " << anArg << "\n";
1676 aChangeSet->ToSetTransparency = 1;
1677 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1678 if (aChangeSet->Transparency < 0.0
1679 || aChangeSet->Transparency > 1.0)
1681 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1684 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1685 if (aChangeSet->Transparency >= 0.0
1686 && aChangeSet->Transparency <= Precision::Confusion())
1688 aChangeSet->ToSetTransparency = -1;
1689 aChangeSet->Transparency = 0.0;
1692 else if (anArg == "-unsettransp"
1693 || anArg == "-unsettransparency"
1694 || anArg == "-unsetalpha"
1695 || anArg == "-opaque")
1697 aChangeSet->ToSetTransparency = -1;
1698 aChangeSet->Transparency = 0.0;
1700 else if (anArg == "-setcolor")
1702 Standard_Integer aNbComps = 0;
1703 Standard_Integer aCompIter = anArgIter + 1;
1704 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1706 if (theArgVec[aCompIter][0] == '-')
1715 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1716 Standard_CString aName = theArgVec[anArgIter + 1];
1717 if (!Quantity_Color::ColorFromName (aName, aColor))
1719 std::cout << "Error: unknown color name '" << aName << "'\n";
1722 aChangeSet->Color = aColor;
1727 Graphic3d_Vec3d anRgb;
1728 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1729 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1730 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1731 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1732 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1733 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1735 std::cout << "Error: RGB color values should be within range 0..1!\n";
1738 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1743 std::cout << "Error: wrong syntax at " << anArg << "\n";
1747 aChangeSet->ToSetColor = 1;
1748 anArgIter += aNbComps;
1750 else if (anArg == "-unsetcolor")
1752 aChangeSet->ToSetColor = -1;
1753 aChangeSet->Color = DEFAULT_COLOR;
1755 else if (anArg == "-setmat"
1756 || anArg == "-setmaterial")
1758 if (++anArgIter >= theArgNb)
1760 std::cout << "Error: wrong syntax at " << anArg << "\n";
1763 aChangeSet->ToSetMaterial = 1;
1764 aChangeSet->MatName = theArgVec[anArgIter];
1765 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1767 else if (anArg == "-unsetmat"
1768 || anArg == "-unsetmaterial")
1770 aChangeSet->ToSetMaterial = -1;
1771 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1773 else if (anArg == "-subshape"
1774 || anArg == "-subshapes")
1778 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1782 if (aNames.IsEmpty())
1784 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1788 aChanges.Append (ViewerTest_AspectsChangeSet());
1789 aChangeSet = &aChanges.ChangeLast();
1791 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1793 Standard_CString aSubShapeName = theArgVec[anArgIter];
1794 if (*aSubShapeName == '-')
1800 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1801 if (aSubShape.IsNull())
1803 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1806 aChangeSet->SubShapes.Append (aSubShape);
1809 if (aChangeSet->SubShapes.IsEmpty())
1811 std::cerr << "Error: empty list is specified after -subshapes!\n";
1815 else if (anArg == "-freeboundary"
1818 if (++anArgIter >= theArgNb)
1820 std::cout << "Error: wrong syntax at " << anArg << "\n";
1823 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1828 aChangeSet->ToSetShowFreeBoundary = 1;
1830 else if (aValue == "off"
1833 aChangeSet->ToSetShowFreeBoundary = -1;
1837 std::cout << "Error: wrong syntax at " << anArg << "\n";
1841 else if (anArg == "-setfreeboundarywidth"
1842 || anArg == "-setfbwidth")
1844 if (++anArgIter >= theArgNb)
1846 std::cout << "Error: wrong syntax at " << anArg << "\n";
1849 aChangeSet->ToSetFreeBoundaryWidth = 1;
1850 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1852 else if (anArg == "-unsetfreeboundarywidth"
1853 || anArg == "-unsetfbwidth")
1855 aChangeSet->ToSetFreeBoundaryWidth = -1;
1856 aChangeSet->FreeBoundaryWidth = 1.0;
1858 else if (anArg == "-setfreeboundarycolor"
1859 || anArg == "-setfbcolor")
1861 Standard_Integer aNbComps = 0;
1862 Standard_Integer aCompIter = anArgIter + 1;
1863 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1865 if (theArgVec[aCompIter][0] == '-')
1874 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1875 Standard_CString aName = theArgVec[anArgIter + 1];
1876 if (!Quantity_Color::ColorFromName (aName, aColor))
1878 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1881 aChangeSet->FreeBoundaryColor = aColor;
1886 Graphic3d_Vec3d anRgb;
1887 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1888 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1889 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1890 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1891 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1892 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1894 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1897 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1902 std::cout << "Error: wrong syntax at " << anArg << "\n";
1906 aChangeSet->ToSetFreeBoundaryColor = 1;
1907 anArgIter += aNbComps;
1909 else if (anArg == "-unsetfreeboundarycolor"
1910 || anArg == "-unsetfbcolor")
1912 aChangeSet->ToSetFreeBoundaryColor = -1;
1913 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1915 else if (anArg == "-unset")
1917 aChangeSet->ToSetVisibility = 1;
1918 aChangeSet->Visibility = 1;
1919 aChangeSet->ToSetLineWidth = -1;
1920 aChangeSet->LineWidth = 1.0;
1921 aChangeSet->ToSetTransparency = -1;
1922 aChangeSet->Transparency = 0.0;
1923 aChangeSet->ToSetColor = -1;
1924 aChangeSet->Color = DEFAULT_COLOR;
1925 aChangeSet->ToSetMaterial = -1;
1926 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1927 aChangeSet->ToSetShowFreeBoundary = -1;
1928 aChangeSet->ToSetFreeBoundaryColor = -1;
1929 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1930 aChangeSet->ToSetFreeBoundaryWidth = -1;
1931 aChangeSet->FreeBoundaryWidth = 1.0;
1935 std::cout << "Error: wrong syntax at " << anArg << "\n";
1940 Standard_Boolean isFirst = Standard_True;
1941 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1942 aChangesIter.More(); aChangesIter.Next())
1944 if (!aChangesIter.Value().Validate (!isFirst))
1948 isFirst = Standard_False;
1951 if (aCtx->HasOpenedContext())
1953 aCtx->CloseLocalContext();
1956 // special case for -defaults parameter.
1957 // all changed values will be set to DefaultDrawer.
1960 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
1962 if (aChangeSet->ToSetLineWidth != 0)
1964 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
1965 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
1966 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
1967 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
1969 if (aChangeSet->ToSetColor != 0)
1971 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
1972 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
1973 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
1974 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
1975 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
1976 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
1978 if (aChangeSet->ToSetTransparency != 0)
1980 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
1982 if (aChangeSet->ToSetMaterial != 0)
1984 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
1986 if (aChangeSet->ToSetShowFreeBoundary == 1)
1988 aDrawer->SetFreeBoundaryDraw (Standard_True);
1990 else if (aChangeSet->ToSetShowFreeBoundary == -1)
1992 aDrawer->SetFreeBoundaryDraw (Standard_False);
1994 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
1996 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
1998 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2000 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2003 // redisplay all objects in context
2004 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2006 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2009 aCtx->Redisplay (aPrs, Standard_False);
2015 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2017 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2018 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2019 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2020 Handle(AIS_ColoredShape) aColoredPrs;
2021 Standard_Boolean toDisplay = Standard_False;
2022 Standard_Boolean toRedisplay = Standard_False;
2023 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2025 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2026 if (aShapePrs.IsNull())
2028 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2031 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2032 if (aColoredPrs.IsNull())
2034 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2035 aCtx->Remove (aShapePrs, Standard_False);
2036 GetMapOfAIS().UnBind2 (aName);
2037 GetMapOfAIS().Bind (aColoredPrs, aName);
2038 toDisplay = Standard_True;
2039 aShapePrs = aColoredPrs;
2046 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2047 aChangeSet = &aChangesIter.ChangeValue();
2048 if (aChangeSet->ToSetVisibility == 1)
2050 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2051 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2053 else if (aChangeSet->ToSetMaterial == 1)
2055 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2057 else if (aChangeSet->ToSetMaterial == -1)
2059 aCtx->UnsetMaterial (aPrs, Standard_False);
2061 if (aChangeSet->ToSetColor == 1)
2063 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2065 else if (aChangeSet->ToSetColor == -1)
2067 aCtx->UnsetColor (aPrs, Standard_False);
2069 if (aChangeSet->ToSetTransparency == 1)
2071 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2073 else if (aChangeSet->ToSetTransparency == -1)
2075 aCtx->UnsetTransparency (aPrs, Standard_False);
2077 if (aChangeSet->ToSetLineWidth == 1)
2079 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2081 else if (aChangeSet->ToSetLineWidth == -1)
2083 aCtx->UnsetWidth (aPrs, Standard_False);
2085 if (!aDrawer.IsNull())
2087 if (aChangeSet->ToSetShowFreeBoundary == 1)
2089 aDrawer->SetFreeBoundaryDraw (Standard_True);
2090 toRedisplay = Standard_True;
2092 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2094 aDrawer->SetFreeBoundaryDraw (Standard_False);
2095 toRedisplay = Standard_True;
2097 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2099 Handle(Prs3d_LineAspect) aBoundaryAspect =
2100 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2101 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2102 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2103 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2104 toRedisplay = Standard_True;
2106 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2108 Handle(Prs3d_LineAspect) aBoundaryAspect =
2109 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2110 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2111 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2112 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2113 toRedisplay = Standard_True;
2117 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2119 aChangeSet = &aChangesIter.ChangeValue();
2120 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2121 aSubShapeIter.More(); aSubShapeIter.Next())
2123 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2124 if (aChangeSet->ToSetVisibility == 1)
2126 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2127 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2129 if (aChangeSet->ToSetColor == 1)
2131 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2133 if (aChangeSet->ToSetLineWidth == 1)
2135 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2137 if (aChangeSet->ToSetColor == -1
2138 || aChangeSet->ToSetLineWidth == -1)
2140 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2146 aCtx->Display (aPrs, Standard_False);
2150 aCtx->Redisplay (aPrs, Standard_False);
2152 else if (!aColoredPrs.IsNull())
2154 aCtx->Redisplay (aColoredPrs, Standard_False);
2161 //==============================================================================
2162 //function : VDonly2
2164 //purpose : Display only a selected or named object
2165 // if there is no selected or named object s, nothing is done
2166 //==============================================================================
2167 static int VDonly2 (Draw_Interpretor& ,
2168 Standard_Integer theArgNb,
2169 const char** theArgVec)
2171 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2172 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2175 std::cerr << "Error: no active view!\n";
2179 if (aCtx->HasOpenedContext())
2181 aCtx->CloseLocalContext();
2184 Standard_Integer anArgIter = 1;
2185 for (; anArgIter < theArgNb; ++anArgIter)
2187 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2193 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2194 if (anArgIter >= theArgNb)
2196 // display only selected objects
2197 if (aCtx->NbCurrents() < 1)
2202 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2204 aDispSet.Add (aCtx->Current());
2209 // display only specified objects
2210 for (; anArgIter < theArgNb; ++anArgIter)
2212 TCollection_AsciiString aName = theArgVec[anArgIter];
2213 if (GetMapOfAIS().IsBound2 (aName))
2215 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2216 if (!aShape.IsNull())
2218 aCtx->Display (aShape, Standard_False);
2219 aDispSet.Add (aShape);
2225 // weed out other objects
2226 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2228 if (aDispSet.Contains (anIter.Key1()))
2233 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2234 if (aShape.IsNull())
2236 aCtx->Erase (aShape, Standard_False);
2242 //==============================================================================
2243 //function : VRemove
2244 //purpose : Removes selected or named objects.
2245 // If there is no selected or named objects,
2246 // all objects in the viewer can be removed with argument -all.
2247 // If -context is in arguments, the object is not deleted from the map of
2248 // objects (deleted only from the current context).
2249 //==============================================================================
2250 int VRemove (Draw_Interpretor& theDI,
2251 Standard_Integer theArgNb,
2252 const char** theArgVec)
2254 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2255 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2258 std::cerr << "Error: no active view!\n";
2262 Standard_Boolean isContextOnly = Standard_False;
2263 Standard_Boolean toRemoveAll = Standard_False;
2264 Standard_Boolean toPrintInfo = Standard_True;
2265 Standard_Boolean toRemoveLocal = Standard_False;
2267 Standard_Integer anArgIter = 1;
2268 for (; anArgIter < theArgNb; ++anArgIter)
2270 TCollection_AsciiString anArg = theArgVec[anArgIter];
2272 if (anArg == "-context")
2274 isContextOnly = Standard_True;
2276 else if (anArg == "-all")
2278 toRemoveAll = Standard_True;
2280 else if (anArg == "-noinfo")
2282 toPrintInfo = Standard_False;
2284 else if (anArg == "-local")
2286 toRemoveLocal = Standard_True;
2288 else if (anUpdateTool.parseRedrawMode (anArg))
2298 && anArgIter < theArgNb)
2300 std::cerr << "Error: wrong syntax!\n";
2304 if (toRemoveLocal && !aCtx->HasOpenedContext())
2306 std::cerr << "Error: local selection context is not open.\n";
2309 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2311 aCtx->CloseAllContexts (Standard_False);
2314 NCollection_List<TCollection_AsciiString> anIONameList;
2317 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2318 anIter.More(); anIter.Next())
2320 anIONameList.Append (anIter.Key2());
2323 else if (anArgIter < theArgNb) // removed objects names are in argument list
2325 for (; anArgIter < theArgNb; ++anArgIter)
2327 TCollection_AsciiString aName = theArgVec[anArgIter];
2328 if (!GetMapOfAIS().IsBound2 (aName))
2330 theDI << aName.ToCString() << " was not bound to some object.\n";
2334 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2335 if (anIO->GetContext() != aCtx)
2337 theDI << aName.ToCString() << " was not displayed in current context.\n";
2338 theDI << "Please activate view with this object displayed and try again.\n";
2342 anIONameList.Append (aName);
2346 else if (aCtx->NbCurrents() > 0)
2348 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2349 anIter.More(); anIter.Next())
2351 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2352 if (!aCtx->IsCurrent (anIO))
2357 anIONameList.Append (anIter.Key2());
2362 // Unbind all removed objects from the map of displayed IO.
2363 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2364 anIter.More(); anIter.Next())
2366 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2367 aCtx->Remove (anIO, Standard_False);
2370 theDI << anIter.Value().ToCString() << " was removed\n";
2374 GetMapOfAIS().UnBind2 (anIter.Value());
2378 // Close local context if it is empty
2379 TColStd_MapOfTransient aLocalIO;
2380 if (aCtx->HasOpenedContext()
2381 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2383 aCtx->CloseAllContexts (Standard_False);
2389 //==============================================================================
2391 //purpose : Erase some selected or named objects
2392 // if there is no selected or named objects, the whole viewer is erased
2393 //==============================================================================
2394 int VErase (Draw_Interpretor& theDI,
2395 Standard_Integer theArgNb,
2396 const char** theArgVec)
2398 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2399 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2400 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2403 std::cerr << "Error: no active view!\n";
2407 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2409 Standard_Integer anArgIter = 1;
2410 Standard_Boolean toEraseLocal = Standard_False;
2411 Standard_Boolean toEraseInView = Standard_False;
2412 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2413 for (; anArgIter < theArgNb; ++anArgIter)
2415 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2416 anArgCase.LowerCase();
2417 if (anUpdateTool.parseRedrawMode (anArgCase))
2421 else if (anArgCase == "-local")
2423 toEraseLocal = Standard_True;
2425 else if (anArgCase == "-view"
2426 || anArgCase == "-inview")
2428 toEraseInView = Standard_True;
2432 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2436 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2438 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2442 if (toEraseLocal && !aCtx->HasOpenedContext())
2444 std::cerr << "Error: local selection context is not open.\n";
2447 else if (!toEraseLocal && aCtx->HasOpenedContext())
2449 aCtx->CloseAllContexts (Standard_False);
2452 if (!aNamesOfEraseIO.IsEmpty())
2454 // Erase named objects
2455 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2457 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2458 if (!GetMapOfAIS().IsBound2 (aName))
2463 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2464 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2465 theDI << aName.ToCString() << " ";
2470 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2474 aCtx->Erase (anIO, Standard_False);
2479 else if (!toEraseAll && aCtx->NbCurrents() > 0)
2481 // Erase selected objects
2482 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2483 anIter.More(); anIter.Next())
2485 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2487 && aCtx->IsCurrent (anIO))
2489 theDI << anIter.Key2().ToCString() << " ";
2492 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2496 aCtx->Erase (anIO, Standard_False);
2503 // Erase all objects
2504 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2505 anIter.More(); anIter.Next())
2507 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2512 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2516 aCtx->Erase (anIO, Standard_False);
2525 //==============================================================================
2526 //function : VDisplayAll
2528 //purpose : Display all the objects of the Map
2529 //==============================================================================
2530 static int VDisplayAll (Draw_Interpretor& ,
2531 Standard_Integer theArgNb,
2532 const char** theArgVec)
2535 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2536 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2539 std::cerr << "Error: no active view!\n";
2543 Standard_Integer anArgIter = 1;
2544 Standard_Boolean toDisplayLocal = Standard_False;
2545 for (; anArgIter < theArgNb; ++anArgIter)
2547 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2548 anArgCase.LowerCase();
2549 if (anArgCase == "-local")
2551 toDisplayLocal = Standard_True;
2553 else if (anUpdateTool.parseRedrawMode (anArgCase))
2562 if (anArgIter < theArgNb)
2564 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2568 if (toDisplayLocal && !aCtx->HasOpenedContext())
2570 std::cerr << "Error: local selection context is not open.\n";
2573 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2575 aCtx->CloseLocalContext (Standard_False);
2578 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2579 anIter.More(); anIter.Next())
2581 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2582 aCtx->Erase (aShape, Standard_False);
2585 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2586 anIter.More(); anIter.Next())
2588 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2589 aCtx->Display (aShape, Standard_False);
2594 //! Auxiliary method to find presentation
2595 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2596 const Handle(AIS_InteractiveObject)& theIO,
2597 const Standard_Integer theMode)
2601 return Handle(PrsMgr_Presentation)();
2606 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2608 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2611 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2613 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2615 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2617 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2619 return Handle(PrsMgr_Presentation)();
2622 enum ViewerTest_BndAction
2629 //! Auxiliary method to print bounding box of presentation
2630 inline void bndPresentation (Draw_Interpretor& theDI,
2631 const Handle(PrsMgr_Presentation)& thePrs,
2632 const TCollection_AsciiString& theName,
2633 const ViewerTest_BndAction theAction)
2637 case BndAction_Hide:
2639 thePrs->Presentation()->GraphicUnHighlight();
2642 case BndAction_Show:
2644 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2645 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2646 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2647 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2648 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2651 case BndAction_Print:
2653 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2654 gp_Pnt aMin = aBox.CornerMin();
2655 gp_Pnt aMax = aBox.CornerMax();
2656 theDI << theName << "\n"
2657 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2658 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2664 //==============================================================================
2665 //function : VBounding
2667 //==============================================================================
2668 int VBounding (Draw_Interpretor& theDI,
2669 Standard_Integer theArgNb,
2670 const char** theArgVec)
2672 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2673 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2676 std::cout << "Error: no active view!\n";
2680 ViewerTest_BndAction anAction = BndAction_Show;
2681 Standard_Integer aMode = -1;
2683 Standard_Integer anArgIter = 1;
2684 for (; anArgIter < theArgNb; ++anArgIter)
2686 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2688 if (anArg == "-print")
2690 anAction = BndAction_Print;
2692 else if (anArg == "-show")
2694 anAction = BndAction_Show;
2696 else if (anArg == "-hide")
2698 anAction = BndAction_Hide;
2700 else if (anArg == "-mode")
2702 if (++anArgIter >= theArgNb)
2704 std::cout << "Error: wrong syntax at " << anArg << "\n";
2707 aMode = Draw::Atoi (theArgVec[anArgIter]);
2709 else if (!anUpdateTool.parseRedrawMode (anArg))
2715 if (anArgIter < theArgNb)
2717 // has a list of names
2718 for (; anArgIter < theArgNb; ++anArgIter)
2720 TCollection_AsciiString aName = theArgVec[anArgIter];
2721 if (!GetMapOfAIS().IsBound2 (aName))
2723 std::cout << "Error: presentation " << aName << " does not exist\n";
2727 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2728 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2731 std::cout << "Error: presentation " << aName << " does not exist\n";
2734 bndPresentation (theDI, aPrs, aName, anAction);
2737 else if (aCtx->NbCurrents() > 0)
2739 // remove all currently selected objects
2740 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2742 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2743 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2746 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2753 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2754 anIter.More(); anIter.Next())
2756 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2757 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2760 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2767 //==============================================================================
2768 //function : VTexture
2770 //==============================================================================
2771 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2773 TCollection_AsciiString aCommandName (theArgv[0]);
2775 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2776 if (aCommandName == "vtexture")
2780 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2781 std::cout << "Type help for more information.\n";
2785 // look for options of vtexture command
2786 TCollection_AsciiString aParseKey;
2787 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2789 TCollection_AsciiString anArg (theArgv [anArgIt]);
2792 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2795 aParseKey.Remove (1);
2796 aParseKey.UpperCase();
2797 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2801 if (aParseKey.IsEmpty())
2806 aMapOfArgs(aParseKey)->Append (anArg);
2809 else if (aCommandName == "vtexscale"
2810 || aCommandName == "vtexorigin"
2811 || aCommandName == "vtexrepeat")
2813 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2814 // equal to -scale, -origin, -repeat options of vtexture command
2815 if (theArgsNb < 2 || theArgsNb > 4)
2817 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2818 std::cout << "Type help for more information.\n";
2822 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2825 anArgs->Append ("OFF");
2827 else if (theArgsNb == 4)
2829 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2830 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2833 TCollection_AsciiString anArgKey;
2834 if (aCommandName == "vtexscale")
2838 else if (aCommandName == "vtexorigin")
2840 anArgKey = "ORIGIN";
2844 anArgKey = "REPEAT";
2847 aMapOfArgs.Bind (anArgKey, anArgs);
2849 else if (aCommandName == "vtexdefault")
2851 // scan for parameters of vtexdefault command
2852 // equal to -default option of vtexture command
2853 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2856 // Check arguments for validity
2857 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2858 for (; aMapIt.More(); aMapIt.Next())
2860 const TCollection_AsciiString& aKey = aMapIt.Key();
2861 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2863 // -scale, -origin, -repeat: one argument "off", or two real values
2864 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2865 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2866 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2871 // -modulate: single argument "on" / "off"
2872 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2877 // -default: no arguments
2878 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2883 TCollection_AsciiString aLowerKey;
2886 aLowerKey.LowerCase();
2887 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2888 std::cout << "Type help for more information.\n";
2892 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2893 if (anAISContext.IsNull())
2895 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2899 Standard_Integer aPreviousMode = 0;
2901 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2903 TCollection_AsciiString aShapeName (theArgv[1]);
2904 Handle(AIS_InteractiveObject) anIO;
2906 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2907 if (aMapOfIO.IsBound2 (aShapeName))
2909 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2914 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2918 Handle(AIS_TexturedShape) aTexturedIO;
2919 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2921 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2922 aPreviousMode = aTexturedIO->DisplayMode();
2926 anAISContext->Remove (anIO, Standard_False);
2927 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2928 GetMapOfAIS().UnBind1 (anIO);
2929 GetMapOfAIS().UnBind2 (aShapeName);
2930 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2933 // -------------------------------------------
2934 // Turn texturing on/off - only for vtexture
2935 // -------------------------------------------
2937 if (aCommandName == "vtexture")
2939 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2941 if (aTextureArg.IsEmpty())
2943 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2944 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2946 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2947 if (aPreviousMode == 3)
2949 anAISContext->RecomputePrsOnly (aTexturedIO);
2952 anAISContext->Display (aTexturedIO, Standard_True);
2955 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2957 if (aTextureArg == "?")
2959 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2961 theDi << "\n Files in current directory : \n" << "\n";
2962 theDi.Eval ("glob -nocomplain *");
2964 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2965 aCmnd += aTextureFolder;
2968 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2969 theDi.Eval (aCmnd.ToCString());
2974 aTexturedIO->SetTextureFileName (aTextureArg);
2979 // ------------------------------------
2980 // Process other options and commands
2981 // ------------------------------------
2983 Handle(TColStd_HSequenceOfAsciiString) aValues;
2984 if (aMapOfArgs.Find ("DEFAULT", aValues))
2986 aTexturedIO->SetTextureRepeat (Standard_False);
2987 aTexturedIO->SetTextureOrigin (Standard_False);
2988 aTexturedIO->SetTextureScale (Standard_False);
2989 aTexturedIO->EnableTextureModulate();
2993 if (aMapOfArgs.Find ("SCALE", aValues))
2995 if (aValues->Value(1) != "OFF")
2997 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3001 aTexturedIO->SetTextureScale (Standard_False);
3005 if (aMapOfArgs.Find ("ORIGIN", aValues))
3007 if (aValues->Value(1) != "OFF")
3009 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3013 aTexturedIO->SetTextureOrigin (Standard_False);
3017 if (aMapOfArgs.Find ("REPEAT", aValues))
3019 if (aValues->Value(1) != "OFF")
3021 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3025 aTexturedIO->SetTextureRepeat (Standard_False);
3029 if (aMapOfArgs.Find ("MODULATE", aValues))
3031 if (aValues->Value(1) == "ON")
3033 aTexturedIO->EnableTextureModulate();
3037 aTexturedIO->DisableTextureModulate();
3042 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3044 anAISContext->RecomputePrsOnly (aTexturedIO);
3048 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3049 anAISContext->Display (aTexturedIO, Standard_True);
3050 anAISContext->Update (aTexturedIO,Standard_True);
3056 //! Auxiliary method to parse transformation persistence flags
3057 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3058 Standard_Integer& theFlags)
3060 if (theFlagString == "pan")
3062 theFlags |= Graphic3d_TMF_PanPers;
3064 else if (theFlagString == "zoom")
3066 theFlags |= Graphic3d_TMF_ZoomPers;
3068 else if (theFlagString == "rotate")
3070 theFlags |= Graphic3d_TMF_RotatePers;
3072 else if (theFlagString == "trihedron")
3074 theFlags = Graphic3d_TMF_TriedronPers;
3076 else if (theFlagString == "full")
3078 theFlags = Graphic3d_TMF_FullPers;
3080 else if (theFlagString == "none")
3082 theFlags = Graphic3d_TMF_None;
3086 return Standard_False;
3089 return Standard_True;
3092 //==============================================================================
3093 //function : VDisplay2
3095 //purpose : Display an object from its name
3096 //==============================================================================
3097 static int VDisplay2 (Draw_Interpretor& theDI,
3098 Standard_Integer theArgNb,
3099 const char** theArgVec)
3103 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3107 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3110 ViewerTest::ViewerInit();
3111 aCtx = ViewerTest::GetAISContext();
3114 // Parse input arguments
3115 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3116 Standard_Integer isMutable = -1;
3117 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3118 Standard_Boolean toDisplayLocal = Standard_False;
3119 Standard_Boolean toReDisplay = Standard_False;
3120 Standard_Integer isSelectable = -1;
3121 Standard_Integer anObjDispMode = -2;
3122 Standard_Integer anObjHighMode = -2;
3123 Standard_Boolean toSetTrsfPers = Standard_False;
3124 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3126 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3127 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3128 Standard_Integer toDisplayInView = Standard_False;
3129 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3131 const TCollection_AsciiString aName = theArgVec[anArgIter];
3132 TCollection_AsciiString aNameCase = aName;
3133 aNameCase.LowerCase();
3134 if (anUpdateTool.parseRedrawMode (aName))
3138 else if (aNameCase == "-mutable")
3142 else if (aNameCase == "-neutral")
3144 aDispStatus = AIS_DS_Displayed;
3146 else if (aNameCase == "-immediate"
3147 || aNameCase == "-top")
3149 aZLayer = Graphic3d_ZLayerId_Top;
3151 else if (aNameCase == "-topmost")
3153 aZLayer = Graphic3d_ZLayerId_Topmost;
3155 else if (aNameCase == "-osd"
3156 || aNameCase == "-toposd"
3157 || aNameCase == "-overlay")
3159 aZLayer = Graphic3d_ZLayerId_TopOSD;
3161 else if (aNameCase == "-botosd"
3162 || aNameCase == "-underlay")
3164 aZLayer = Graphic3d_ZLayerId_BotOSD;
3166 else if (aNameCase == "-select"
3167 || aNameCase == "-selectable")
3171 else if (aNameCase == "-noselect"
3172 || aNameCase == "-noselection")
3176 else if (aNameCase == "-dispmode"
3177 || aNameCase == "-displaymode")
3179 if (++anArgIter >= theArgNb)
3181 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3185 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3187 else if (aNameCase == "-highmode"
3188 || aNameCase == "-highlightmode")
3190 if (++anArgIter >= theArgNb)
3192 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3196 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3198 else if (aNameCase == "-3d")
3200 toSetTrsfPers = Standard_True;
3201 aTrsfPersFlags = Graphic3d_TMF_None;
3203 else if (aNameCase == "-2d")
3205 toSetTrsfPers = Standard_True;
3206 aTrsfPersFlags = Graphic3d_TMF_2d;
3208 else if (aNameCase == "-2dtopdown")
3210 toSetTrsfPers = Standard_True;
3211 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3213 else if (aNameCase == "-trsfpers"
3214 || aNameCase == "-pers")
3216 if (++anArgIter >= theArgNb)
3218 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3222 toSetTrsfPers = Standard_True;
3223 aTrsfPersFlags = Graphic3d_TMF_None;
3224 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3225 aPersFlags.LowerCase();
3226 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3228 if (aParserPos == -1)
3230 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3232 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3238 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3239 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3241 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3244 aPersFlags = anOtherFlags;
3247 else if (aNameCase == "-trsfperspos"
3248 || aNameCase == "-perspos")
3250 if (anArgIter + 2 >= theArgNb)
3252 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3256 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3257 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3258 TCollection_AsciiString aZ = "0";
3259 if (!aX.IsIntegerValue()
3260 || !aY.IsIntegerValue())
3262 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3265 if (anArgIter + 1 < theArgNb)
3267 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3268 if (aTemp.IsIntegerValue())
3274 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3276 else if (aNameCase == "-layer")
3278 if (++anArgIter >= theArgNb)
3280 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3284 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3285 if (!aValue.IsIntegerValue())
3287 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3291 aZLayer = aValue.IntegerValue();
3293 else if (aNameCase == "-view"
3294 || aNameCase == "-inview")
3296 toDisplayInView = Standard_True;
3298 else if (aNameCase == "-local")
3300 aDispStatus = AIS_DS_Temporary;
3301 toDisplayLocal = Standard_True;
3303 else if (aNameCase == "-redisplay")
3305 toReDisplay = Standard_True;
3309 aNamesOfDisplayIO.Append (aName);
3313 if (aNamesOfDisplayIO.IsEmpty())
3315 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3319 // Prepare context for display
3320 if (toDisplayLocal && !aCtx->HasOpenedContext())
3322 aCtx->OpenLocalContext (Standard_False);
3324 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3326 aCtx->CloseAllContexts (Standard_False);
3329 // Display interactive objects
3330 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3332 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3334 if (!GetMapOfAIS().IsBound2 (aName))
3336 // create the AIS_Shape from a name
3337 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3338 if (!aShape.IsNull())
3340 if (isMutable != -1)
3342 aShape->SetMutable (isMutable == 1);
3344 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3346 aShape->SetZLayer (aZLayer);
3350 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3352 if (anObjDispMode != -2)
3354 aShape->SetDisplayMode (anObjDispMode);
3356 if (anObjHighMode != -2)
3358 aShape->SetHilightMode (anObjHighMode);
3360 if (!toDisplayLocal)
3361 GetMapOfAIS().Bind (aShape, aName);
3363 Standard_Integer aDispMode = aShape->HasDisplayMode()
3364 ? aShape->DisplayMode()
3365 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3366 ? aCtx->DisplayMode()
3368 Standard_Integer aSelMode = -1;
3369 if ( isSelectable == 1
3370 || (isSelectable == -1
3371 && aCtx->GetAutoActivateSelection()
3372 && aShape->GetTransformPersistenceMode() == 0))
3374 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3377 aCtx->Display (aShape, aDispMode, aSelMode,
3378 Standard_False, aShape->AcceptShapeDecomposition(),
3380 if (toDisplayInView)
3382 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3384 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3386 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3391 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3396 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3397 if (isMutable != -1)
3399 aShape->SetMutable (isMutable == 1);
3401 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3403 aShape->SetZLayer (aZLayer);
3407 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3409 if (anObjDispMode != -2)
3411 aShape->SetDisplayMode (anObjDispMode);
3413 if (anObjHighMode != -2)
3415 aShape->SetHilightMode (anObjHighMode);
3417 Standard_Integer aDispMode = aShape->HasDisplayMode()
3418 ? aShape->DisplayMode()
3419 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3420 ? aCtx->DisplayMode()
3422 Standard_Integer aSelMode = -1;
3423 if ( isSelectable == 1
3424 || (isSelectable == -1
3425 && aCtx->GetAutoActivateSelection()
3426 && aShape->GetTransformPersistenceMode() == 0))
3428 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3431 if (aShape->Type() == AIS_KOI_Datum)
3433 aCtx->Display (aShape, Standard_False);
3437 theDI << "Display " << aName.ToCString() << "\n";
3439 // update the Shape in the AIS_Shape
3440 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3441 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3442 if (!aShapePrs.IsNull())
3444 if (!aShapePrs->Shape().IsEqual (aNewShape))
3446 toReDisplay = Standard_True;
3448 aShapePrs->Set (aNewShape);
3452 aCtx->Redisplay (aShape, Standard_False);
3457 aCtx->Erase (aShape);
3459 aCtx->Display (aShape, aDispMode, aSelMode,
3460 Standard_False, aShape->AcceptShapeDecomposition(),
3462 if (toDisplayInView)
3464 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3472 //===============================================================================================
3473 //function : VUpdate
3475 //===============================================================================================
3476 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3478 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3479 if (aContextAIS.IsNull())
3481 std::cout << theArgVec[0] << "AIS context is not available.\n";
3487 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3491 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3493 AIS_ListOfInteractive aListOfIO;
3495 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3497 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3499 Handle(AIS_InteractiveObject) anAISObj;
3500 if (anAISMap.IsBound2 (aName))
3502 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3505 if (anAISObj.IsNull())
3507 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3511 aListOfIO.Append (anAISObj);
3514 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3515 for (; anIOIt.More(); anIOIt.Next())
3517 aContextAIS->Update (anIOIt.Value(), Standard_False);
3520 aContextAIS->UpdateCurrentViewer();
3525 //==============================================================================
3527 //purpose : Test the annimation of an object along a
3528 // predifined trajectory
3529 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3530 //==============================================================================
3532 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3535 if (TheAISContext()->HasOpenedContext())
3536 TheAISContext()->CloseLocalContext();
3538 Standard_Real Step=4*M_PI/180;
3539 Standard_Real Angle=0;
3541 Handle(AIS_InteractiveObject) aIO;
3542 if (GetMapOfAIS().IsBound2(argv[1]))
3543 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3547 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3551 if (Draw::Atoi(argv[3])==1 ) {
3552 di<<" Primitives sensibles OFF"<<"\n";
3553 TheAISContext()->Deactivate(aIO);
3556 di<<" Primitives sensibles ON"<<"\n";
3558 // Movement par transformation
3559 if(Draw::Atoi(argv[2]) ==1) {
3560 di<<" Calcul par Transformation"<<"\n";
3561 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3565 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3566 TheAISContext()->SetLocation(aShape,myTransfo);
3567 TheAISContext() ->UpdateCurrentViewer();
3572 di<<" Calcul par Locations"<<"\n";
3573 gp_Trsf myAngleTrsf;
3574 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3575 TopLoc_Location myDeltaAngle (myAngleTrsf);
3576 TopLoc_Location myTrueLoc;
3578 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3581 myTrueLoc=myTrueLoc*myDeltaAngle;
3582 TheAISContext()->SetLocation(aShape,myTrueLoc );
3583 TheAISContext() ->UpdateCurrentViewer();
3586 if (Draw::Atoi(argv[3])==1 ){
3587 // On reactive la selection des primitives sensibles
3588 TheAISContext()->Activate(aIO,0);
3590 a3DView() -> Redraw();
3592 di<<" Temps ecoule "<<"\n";
3598 //==================================================================================
3599 // Function : VAnimation
3600 //==================================================================================
3601 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3603 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3607 Standard_Real thread = 4;
3608 Standard_Real angleA=0;
3609 Standard_Real angleB;
3611 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3614 TopoDS_Shape CrankArm;
3615 TopoDS_Shape CylinderHead;
3616 TopoDS_Shape Propeller;
3617 TopoDS_Shape EngineBlock;
3619 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3620 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3621 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3622 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3623 BRepTools::Read(CrankArm,argv[1],B);
3624 BRepTools::Read(CylinderHead,argv[2],B);
3625 BRepTools::Read(Propeller,argv[3],B);
3626 BRepTools::Read(EngineBlock,argv[4],B);
3628 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3634 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3635 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3636 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3637 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3639 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3640 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3641 GetMapOfAIS().Bind(myAisCrankArm,"c");
3642 GetMapOfAIS().Bind(myAisPropeller,"d");
3644 myAisCylinderHead->SetMutable (Standard_True);
3645 myAisEngineBlock ->SetMutable (Standard_True);
3646 myAisCrankArm ->SetMutable (Standard_True);
3647 myAisPropeller ->SetMutable (Standard_True);
3649 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3650 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3651 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3653 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3654 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3655 TheAISContext()->Display (myAisCrankArm, Standard_False);
3656 TheAISContext()->Display (myAisPropeller, Standard_False);
3658 TheAISContext()->Deactivate(myAisCylinderHead);
3659 TheAISContext()->Deactivate(myAisEngineBlock );
3660 TheAISContext()->Deactivate(myAisCrankArm );
3661 TheAISContext()->Deactivate(myAisPropeller );
3663 // Boucle de mouvement
3664 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3666 angleA = thread*myAngle*M_PI/180;
3667 X = Sin(angleA)*3/8;
3668 angleB = atan(X / Sqrt(-X * X + 1));
3669 Standard_Real decal(25*0.6);
3672 //Build a transformation on the display
3673 gp_Trsf aPropellerTrsf;
3674 aPropellerTrsf.SetRotation(Ax1,angleA);
3675 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3677 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
3678 gp_Trsf aCrankArmTrsf;
3679 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3680 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3682 TheAISContext()->UpdateCurrentViewer();
3685 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3686 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3688 myAisCrankArm ->ResetTransformation();
3689 myAisPropeller->ResetTransformation();
3691 myAisCrankArm -> Set(myNewCrankArm );
3692 myAisPropeller -> Set(myNewPropeller);
3694 TheAISContext()->Activate(myAisCylinderHead,0);
3695 TheAISContext()->Activate(myAisEngineBlock,0 );
3696 TheAISContext()->Activate(myAisCrankArm ,0 );
3697 TheAISContext()->Activate(myAisPropeller ,0 );
3703 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3704 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3706 TheAISContext()->UpdateCurrentViewer();
3707 a3DView()->Redraw();
3716 //==============================================================================
3717 //function : VShading
3718 //purpose : Sharpen or roughten the quality of the shading
3719 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3720 //==============================================================================
3721 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3723 Standard_Real myDevCoef;
3724 Handle(AIS_InteractiveObject) TheAisIO;
3727 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3729 if (TheAISContext()->HasOpenedContext())
3730 TheAISContext()->CloseLocalContext();
3735 myDevCoef =Draw::Atof(argv[2]);
3738 TCollection_AsciiString name=argv[1];
3739 if (GetMapOfAIS().IsBound2(name ))
3740 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3741 if (TheAisIO.IsNull())
3742 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3745 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3747 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3749 TheAISContext()->Redisplay(TheAisIO);
3752 //==============================================================================
3753 //function : HaveMode
3754 //use : VActivatedModes
3755 //==============================================================================
3756 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3758 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3760 TColStd_ListOfInteger List;
3761 TheAISContext()->ActivatedModes (TheAisIO,List);
3762 TColStd_ListIteratorOfListOfInteger it;
3763 Standard_Boolean Found=Standard_False;
3764 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3765 if (it.Value()==mode ) Found=Standard_True;
3772 //==============================================================================
3773 //function : VActivatedMode
3775 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3776 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3777 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3778 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3779 // qu'un nom et qu'un mode.
3780 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3781 //==============================================================================
3782 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3784 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3787 Standard_Boolean ThereIsName = Standard_False ;
3789 if(!a3DView().IsNull()){
3791 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3792 // verification des arguments
3794 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3795 ThereIsName = (argc == 3);
3799 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3801 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3802 di<<" Fermeture du Context local"<<"\n";
3803 if (TheAISContext()->HasOpenedContext())
3804 TheAISContext()->CloseLocalContext();
3808 // IL n'y a aps de nom de shape passe en argument
3809 if (HaveToSet && !ThereIsName){
3810 Standard_Integer aMode=Draw::Atoi(argv [1]);
3812 const char *cmode="???";
3814 case 0: cmode = "Shape"; break;
3815 case 1: cmode = "Vertex"; break;
3816 case 2: cmode = "Edge"; break;
3817 case 3: cmode = "Wire"; break;
3818 case 4: cmode = "Face"; break;
3819 case 5: cmode = "Shell"; break;
3820 case 6: cmode = "Solid"; break;
3821 case 7: cmode = "Compound"; break;
3824 if( !TheAISContext()->HasOpenedContext() ) {
3825 // il n'y a pas de Context local d'ouvert
3826 // on en ouvre un et on charge toutes les shapes displayees
3827 // on load tous les objets displayees et on Activate les objets de la liste
3828 AIS_ListOfInteractive ListOfIO;
3829 // on sauve dans une AISListOfInteractive tous les objets currents
3830 if (TheAISContext()->NbCurrents()>0 ){
3831 TheAISContext()->UnhilightCurrents(Standard_False);
3833 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3834 ListOfIO.Append(TheAISContext()->Current() );
3838 TheAISContext()->OpenLocalContext(Standard_False);
3839 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3842 Handle(AIS_InteractiveObject) aIO =
3843 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3845 TheAISContext()->Load(aIO,0,Standard_False);
3848 // traitement des objets qui etaient currents dans le Contexte global
3849 if (!ListOfIO.IsEmpty() ) {
3850 // il y avait des objets currents
3851 AIS_ListIteratorOfListOfInteractive iter;
3852 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3853 Handle(AIS_InteractiveObject) aIO=iter.Value();
3854 TheAISContext()->Activate(aIO,aMode);
3855 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3859 // On applique le mode a tous les objets displayes
3860 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3861 it2 (GetMapOfAIS());
3863 Handle(AIS_InteractiveObject) aIO =
3864 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3865 if (!aIO.IsNull()) {
3866 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3867 TheAISContext()->Activate(aIO,aMode);
3876 // un Context local est deja ouvert
3877 // Traitement des objets du Context local
3878 if (TheAISContext()->NbSelected()>0 ){
3879 TheAISContext()->UnhilightSelected(Standard_False);
3880 // il y a des objets selected,on les parcourt
3881 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3882 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3885 if (HaveMode(aIO,aMode) ) {
3886 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3887 TheAISContext()->Deactivate(aIO,aMode);
3890 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3891 TheAISContext()->Activate(aIO,aMode);
3897 // il n'y a pas d'objets selected
3898 // tous les objets diplayes sont traites
3899 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3902 Handle(AIS_InteractiveObject) aIO =
3903 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3904 if (!aIO.IsNull()) {
3905 if (HaveMode(aIO,aMode) ) {
3906 di<<" Mode: "<<cmode<<" OFF pour "
3907 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3908 TheAISContext()->Deactivate(aIO,aMode);
3911 di<<" Mode: "<<cmode<<" ON pour"
3912 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3913 TheAISContext()->Activate(aIO,aMode);
3921 else if (HaveToSet && ThereIsName){
3922 Standard_Integer aMode=Draw::Atoi(argv [2]);
3923 Handle(AIS_InteractiveObject) aIO =
3924 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3926 if (!aIO.IsNull()) {
3927 const char *cmode="???";
3930 case 0: cmode = "Shape"; break;
3931 case 1: cmode = "Vertex"; break;
3932 case 2: cmode = "Edge"; break;
3933 case 3: cmode = "Wire"; break;
3934 case 4: cmode = "Face"; break;
3935 case 5: cmode = "Shell"; break;
3936 case 6: cmode = "Solid"; break;
3937 case 7: cmode = "Compound"; break;
3940 if( !TheAISContext()->HasOpenedContext() ) {
3941 TheAISContext()->OpenLocalContext(Standard_False);
3942 // On charge tous les objets de la map
3943 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3945 Handle(AIS_InteractiveObject) aShape=
3946 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3947 if (!aShape.IsNull())
3948 TheAISContext()->Load(aShape,0,Standard_False);
3951 TheAISContext()->Activate(aIO,aMode);
3952 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3956 // un Context local est deja ouvert
3957 if (HaveMode(aIO,aMode) ) {
3958 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3959 TheAISContext()->Deactivate(aIO,aMode);
3962 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3963 TheAISContext()->Activate(aIO,aMode);
3972 //! Auxiliary method to print Interactive Object information
3973 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3974 const Handle(Standard_Transient)& theObject,
3975 Draw_Interpretor& theDI)
3977 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3980 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3984 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3985 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3986 << (theDetected.Contains (anObj) ? " Detected" : " ")
3988 if (anObj->Type() == AIS_KOI_Datum)
3991 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3992 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3993 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3994 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3995 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3996 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3997 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4000 else if (anObj->Type() == AIS_KOI_Shape
4001 && anObj->Signature() == 0)
4003 theDI << " AIS_Shape";
4005 else if (anObj->Type() == AIS_KOI_Relation)
4007 // AIS_Dimention and AIS_Relation
4008 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4009 switch (aRelation->KindOfDimension())
4011 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4012 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4013 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4014 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4015 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4016 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4017 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4018 default: theDI << " UNKNOWN dimension"; break;
4023 theDI << " UserPrs";
4025 theDI << " (" << theObject->DynamicType()->Name() << ")";
4028 //! Print information about locally selected sub-shapes
4029 static void localCtxInfo (Draw_Interpretor& theDI)
4031 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4032 if (!aCtx->HasOpenedContext())
4037 TCollection_AsciiString aPrevName;
4038 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
4039 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
4041 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
4042 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
4043 if (aSubShape.IsNull()
4044 || aShapeIO.IsNull()
4045 || !GetMapOfAIS().IsBound1 (aShapeIO))
4050 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4051 TopTools_MapOfShape aFilter;
4052 Standard_Integer aNumber = 0;
4053 const TopoDS_Shape aShape = aShapeIO->Shape();
4054 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4055 anIter.More(); anIter.Next())
4057 if (!aFilter.Add (anIter.Current()))
4059 continue; // filter duplicates
4063 if (!anIter.Current().IsSame (aSubShape))
4068 Standard_CString aShapeName = NULL;
4069 switch (aSubShape.ShapeType())
4071 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4072 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4073 case TopAbs_SOLID: aShapeName = " Solid"; break;
4074 case TopAbs_SHELL: aShapeName = " Shell"; break;
4075 case TopAbs_FACE: aShapeName = " Face"; break;
4076 case TopAbs_WIRE: aShapeName = " Wire"; break;
4077 case TopAbs_EDGE: aShapeName = " Edge"; break;
4078 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4080 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4083 if (aParentName != aPrevName)
4085 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4086 aPrevName = aParentName;
4088 theDI << " " << aShapeName << " #" << aNumber << "\n";
4094 //==============================================================================
4097 //==============================================================================
4098 static Standard_Integer VState (Draw_Interpretor& theDI,
4099 Standard_Integer theArgNb,
4100 Standard_CString* theArgVec)
4102 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4105 std::cerr << "Error: No opened viewer!\n";
4109 Standard_Boolean toPrintEntities = Standard_False;
4110 Standard_Boolean toCheckSelected = Standard_False;
4112 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4114 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4115 anOption.LowerCase();
4116 if (anOption == "-detectedentities"
4117 || anOption == "-entities")
4119 toPrintEntities = Standard_True;
4121 else if (anOption == "-hasselected")
4123 toCheckSelected = Standard_True;
4127 if (toCheckSelected)
4129 aCtx->InitSelected();
4130 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4131 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4136 if (toPrintEntities)
4138 theDI << "Detected entities:\n";
4139 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4140 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
4142 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
4143 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4144 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4145 SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
4146 : aSelector->GetManager();
4147 SelectBasics_PickResult aResult;
4148 anEntity->Matches (aMgr, aResult);
4149 NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
4151 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4152 aName.LeftJustify (20, ' ');
4153 char anInfoStr[512];
4155 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4157 aResult.DistToGeomCenter(),
4158 aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
4159 theDI << " " << aName
4161 << " (" << anEntity->DynamicType()->Name() << ")"
4164 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4165 if (!aBRepOwner.IsNull())
4167 theDI << " Detected Shape: "
4168 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4172 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4173 if (!aWire.IsNull())
4175 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4176 theDI << " Detected Child: "
4177 << aSen->DynamicType()->Name()
4184 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4185 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4187 aDetected.Add (aCtx->DetectedCurrentObject());
4190 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4194 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4196 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4197 if (!GetMapOfAIS().IsBound2 (anObjName))
4199 theDI << anObjName << " doesn't exist!\n";
4203 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4204 TCollection_AsciiString aName = anObjName;
4205 aName.LeftJustify (20, ' ');
4206 theDI << " " << aName << " ";
4207 objInfo (aDetected, anObjTrans, theDI);
4213 if (aCtx->NbCurrents() > 0
4216 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
4218 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
4219 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4220 aName.LeftJustify (20, ' ');
4221 theDI << aName << " ";
4222 objInfo (aDetected, anObj, theDI);
4228 theDI << "Neutral-point state:\n";
4229 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4230 anObjIter.More(); anObjIter.Next())
4232 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4238 TCollection_AsciiString aName = anObjIter.Key2();
4239 aName.LeftJustify (20, ' ');
4240 theDI << " " << aName << " ";
4241 objInfo (aDetected, anObj, theDI);
4244 localCtxInfo (theDI);
4248 //=======================================================================
4249 //function : PickObjects
4251 //=======================================================================
4252 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4253 const AIS_KindOfInteractive TheType,
4254 const Standard_Integer TheSignature,
4255 const Standard_Integer MaxPick)
4257 Handle(AIS_InteractiveObject) IO;
4258 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4260 // step 1: prepare the data
4262 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4263 TheAISContext()->AddFilter(F1);
4266 // step 2 : wait for the selection...
4267 // Standard_Boolean IsGood (Standard_False);
4268 // Standard_Integer NbPick(0);
4269 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4270 Standard_Integer NbPickFail(0);
4271 Standard_Integer argccc = 5;
4272 const char *bufff[] = { "A", "B", "C","D", "E" };
4273 const char **argvvv = (const char **) bufff;
4276 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4277 while(ViewerMainLoop(argccc,argvvv)){}
4278 Standard_Integer NbStored = TheAISContext()->NbSelected();
4279 if((unsigned int ) NbStored != NbPickGood)
4280 NbPickGood= NbStored;
4283 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4286 // step3 get result.
4288 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4290 Standard_Integer i(0);
4291 for(TheAISContext()->InitSelected();
4292 TheAISContext()->MoreSelected();
4293 TheAISContext()->NextSelected()){
4295 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4296 arr->SetValue(i,IO2);
4301 TheAISContext()->CloseLocalContext(curindex);
4303 return Standard_True;
4307 //=======================================================================
4308 //function : PickObject
4310 //=======================================================================
4311 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4312 const Standard_Integer TheSignature,
4313 const Standard_Integer MaxPick)
4315 Handle(AIS_InteractiveObject) IO;
4316 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4318 // step 1: prepare the data
4321 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4322 TheAISContext()->AddFilter(F1);
4325 // step 2 : wait for the selection...
4326 Standard_Boolean IsGood (Standard_False);
4327 Standard_Integer NbPick(0);
4328 Standard_Integer argccc = 5;
4329 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4330 const char **argvvv = (const char **) bufff;
4333 while(!IsGood && NbPick<= MaxPick){
4334 while(ViewerMainLoop(argccc,argvvv)){}
4335 IsGood = (TheAISContext()->NbSelected()>0) ;
4337 cout<<"Nb Pick :"<<NbPick<<endl;
4341 // step3 get result.
4343 TheAISContext()->InitSelected();
4344 IO = TheAISContext()->SelectedInteractive();
4348 TheAISContext()->CloseLocalContext(curindex);
4352 //=======================================================================
4353 //function : PickShape
4354 //purpose : First Activate the rightmode + Put Filters to be able to
4355 // pick objets that are of type <TheType>...
4356 //=======================================================================
4358 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4359 const Standard_Integer MaxPick)
4362 // step 1: prepare the data
4364 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4365 TopoDS_Shape result;
4367 if(TheType==TopAbs_SHAPE){
4368 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4369 TheAISContext()->AddFilter(F1);
4372 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4373 TheAISContext()->AddFilter(TF);
4374 TheAISContext()->ActivateStandardMode(TheType);
4379 // step 2 : wait for the selection...
4380 Standard_Boolean NoShape (Standard_True);
4381 Standard_Integer NbPick(0);
4382 Standard_Integer argccc = 5;
4383 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4384 const char **argvvv = (const char **) bufff;
4387 while(NoShape && NbPick<= MaxPick){
4388 while(ViewerMainLoop(argccc,argvvv)){}
4389 NoShape = (TheAISContext()->NbSelected()==0) ;
4391 cout<<"Nb Pick :"<<NbPick<<endl;
4394 // step3 get result.
4398 TheAISContext()->InitSelected();
4399 if(TheAISContext()->HasSelectedShape())
4400 result = TheAISContext()->SelectedShape();
4402 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4403 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
4408 TheAISContext()->CloseLocalContext(curindex);
4414 //=======================================================================
4415 //function : PickShapes
4417 //=======================================================================
4418 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4419 Handle(TopTools_HArray1OfShape)& thearr,
4420 const Standard_Integer MaxPick)
4423 Standard_Integer Taille = thearr->Length();
4425 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4427 // step 1: prepare the data
4428 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4429 if(TheType==TopAbs_SHAPE){
4430 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4431 TheAISContext()->AddFilter(F1);
4434 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4435 TheAISContext()->AddFilter(TF);
4436 TheAISContext()->ActivateStandardMode(TheType);
4440 // step 2 : wait for the selection...
4442 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4443 Standard_Integer NbPickFail(0);
4444 Standard_Integer argccc = 5;
4445 const char *bufff[] = { "A", "B", "C","D", "E" };
4446 const char **argvvv = (const char **) bufff;
4449 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4450 while(ViewerMainLoop(argccc,argvvv)){}
4451 Standard_Integer NbStored = TheAISContext()->NbSelected();
4452 if((unsigned int ) NbStored != NbPickGood)
4453 NbPickGood= NbStored;
4456 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4459 // step3 get result.
4461 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4463 Standard_Integer i(0);
4464 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4466 if(TheAISContext()->HasSelectedShape())
4467 thearr->SetValue(i,TheAISContext()->SelectedShape());
4469 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4470 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
4474 TheAISContext()->CloseLocalContext(curindex);
4475 return Standard_True;
4479 //=======================================================================
4480 //function : VPickShape
4482 //=======================================================================
4483 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4485 TopoDS_Shape PickSh;
4486 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4489 theType = TopAbs_SHAPE;
4491 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4492 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4493 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4494 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4495 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4496 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4497 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4500 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4501 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4503 TCollection_AsciiString name;
4506 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4508 PickSh = ViewerTest::PickShape(theType);
4517 if(!PickSh.IsNull()){
4518 nbOfSub[Standard_Integer(theType)]++;
4520 name += nameType[Standard_Integer(theType)];
4521 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4526 // si on avait une petite methode pour voir si la shape
4527 // est deja dans la Double map, ca eviterait de creer....
4528 DBRep::Set(name.ToCString(),PickSh);
4530 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4531 GetMapOfAIS().Bind(newsh, name);
4532 TheAISContext()->Display(newsh);
4533 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4536 // Plusieurs objets a picker, vite vite vite....
4539 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4540 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4541 if(ViewerTest::PickShapes(theType,arr)){
4542 for(Standard_Integer i=1;i<=NbToPick;i++){
4543 PickSh = arr->Value(i);
4544 if(!PickSh.IsNull()){
4546 nbOfSub[Standard_Integer(theType)]++;
4549 name += nameType[Standard_Integer(theType)];
4550 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4558 DBRep::Set(name.ToCString(),PickSh);
4559 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4560 GetMapOfAIS().Bind(newsh, name);
4561 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4562 TheAISContext()->Display(newsh);
4570 //=======================================================================
4571 //function : VPickSelected
4573 //=======================================================================
4574 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4576 static Standard_Integer aCount = 0;
4577 TCollection_AsciiString aName = "PickedShape_";
4585 aName = aName + aCount++ + "_";
4588 Standard_Integer anIdx = 0;
4589 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4591 TopoDS_Shape aShape;
4592 if (TheAISContext()->HasSelectedShape())
4594 aShape = TheAISContext()->SelectedShape();
4598 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4599 aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
4602 TCollection_AsciiString aCurrentName = aName;
4605 aCurrentName += anIdx;
4608 DBRep::Set ((aCurrentName).ToCString(), aShape);
4610 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4611 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4612 TheAISContext()->Display (aNewShape);
4618 //=======================================================================
4619 //function : list of known objects
4621 //=======================================================================
4622 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4624 // 1234567890 12345678901234567 123456789
4625 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4626 TCollection_AsciiString BlankLine(64,'_');
4627 Standard_Integer i ;
4629 di<<"/n"<<BlankLine.ToCString()<<"\n";
4632 Colum[i].Center(20,' ');
4634 di<<"|"<<Colum[i].ToCString();
4637 di<<BlankLine.ToCString()<<"\n";
4639 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4640 const char ** names = GetTypeNames();
4642 TCollection_AsciiString curstring;
4643 TCollection_AsciiString curcolum[3];
4646 // les objets de type Datum..
4647 curcolum[1]+="Datum";
4649 curcolum[0].Clear();
4650 curcolum[0] += names[i];
4652 curcolum[2].Clear();
4653 curcolum[2]+=TCollection_AsciiString(i+1);
4655 for(Standard_Integer j =0;j<=2;j++){
4656 curcolum[j].Center(20,' ');
4657 di<<"|"<<curcolum[j].ToCString();
4661 di<<BlankLine.ToCString()<<"\n";
4663 // les objets de type shape
4664 curcolum[1].Clear();
4665 curcolum[1]+="Shape";
4666 curcolum[1].Center(20,' ');
4669 curcolum[0].Clear();
4670 curcolum[0] += names[7+i];
4671 curcolum[2].Clear();
4672 curcolum[2]+=TCollection_AsciiString(i);
4674 for(Standard_Integer j =0;j<=2;j++){
4675 curcolum[j].Center(20,' ');
4676 di<<"|"<<curcolum[j].ToCString();
4680 di<<BlankLine.ToCString()<<"\n";
4681 // les IO de type objet...
4682 curcolum[1].Clear();
4683 curcolum[1]+="Object";
4684 curcolum[1].Center(20,' ');
4686 curcolum[0].Clear();
4687 curcolum[0] += names[10+i];
4688 curcolum[2].Clear();
4689 curcolum[2]+=TCollection_AsciiString(i);
4691 for(Standard_Integer j =0;j<=2;j++){
4692 curcolum[j].Center(20,' ');
4693 di<<"|"<<curcolum[j].ToCString();
4697 di<<BlankLine.ToCString()<<"\n";
4698 // les contraintes et dimensions.
4699 // pour l'instant on separe juste contraintes et dimensions...
4700 // plus tard, on detaillera toutes les sortes...
4701 curcolum[1].Clear();
4702 curcolum[1]+="Relation";
4703 curcolum[1].Center(20,' ');
4705 curcolum[0].Clear();
4706 curcolum[0] += names[12+i];
4707 curcolum[2].Clear();
4708 curcolum[2]+=TCollection_AsciiString(i);
4710 for(Standard_Integer j =0;j<=2;j++){
4711 curcolum[j].Center(20,' ');
4712 di<<"|"<<curcolum[j].ToCString();
4716 di<<BlankLine.ToCString()<<"\n";
4723 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4725 if(argc!=2) return 1;
4727 AIS_KindOfInteractive TheType;
4728 Standard_Integer TheSign(-1);
4729 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4732 AIS_ListOfInteractive LIO;
4734 // en attendant l'amelioration ais pour les dimensions...
4736 Standard_Integer dimension_status(-1);
4737 if(TheType==AIS_KOI_Relation){
4738 dimension_status = TheSign ==1 ? 1 : 0;
4742 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4743 Handle(AIS_InteractiveObject) curio;
4744 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4747 if(dimension_status == -1)
4748 TheAISContext()->Erase(curio,Standard_False);
4750 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4751 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4752 (dimension_status==1 && KOD != AIS_KOD_NONE))
4753 TheAISContext()->Erase(curio,Standard_False);
4756 TheAISContext()->UpdateCurrentViewer();
4759 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4761 if(argc!=2) return 1;
4763 AIS_KindOfInteractive TheType;
4764 Standard_Integer TheSign(-1);
4765 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4767 // en attendant l'amelioration ais pour les dimensions...
4769 Standard_Integer dimension_status(-1);
4770 if(TheType==AIS_KOI_Relation){
4771 dimension_status = TheSign ==1 ? 1 : 0;
4775 AIS_ListOfInteractive LIO;
4776 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4777 Handle(AIS_InteractiveObject) curio;
4778 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4780 if(dimension_status == -1)
4781 TheAISContext()->Display(curio,Standard_False);
4783 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4784 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4785 (dimension_status==1 && KOD != AIS_KOD_NONE))
4786 TheAISContext()->Display(curio,Standard_False);
4791 TheAISContext()->UpdateCurrentViewer();
4795 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4798 BRep_Builder builder;
4800 BRepTools::Read(shape, s, builder);
4801 DBRep::Set(a[1], shape);
4802 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4803 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4808 //===============================================================================================
4811 //===============================================================================================
4812 static int VBsdf (Draw_Interpretor& theDi,
4813 Standard_Integer theArgsNb,
4814 const char** theArgVec)
4816 Handle(V3d_View) aView = ViewerTest::CurrentView();
4817 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4819 || aViewer.IsNull())
4821 std::cerr << "No active viewer!\n";
4825 ViewerTest_CmdParser aCmd;
4827 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
4828 aCmd.AddOption ("print|echo|p", "Print BSDF");
4830 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
4831 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
4832 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
4833 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
4834 aCmd.AddOption ("le", "Self-emitted radiance");
4836 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
4838 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
4839 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
4840 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
4842 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
4844 aCmd.Parse (theArgsNb, theArgVec);
4846 if (aCmd.HasOption ("help"))
4848 theDi.PrintHelp (theArgVec[0]);
4852 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
4855 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4856 if (!aMap.IsBound2 (aName) )
4858 std::cerr << "Use 'vdisplay' before" << "\n";
4862 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
4863 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
4864 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
4866 if (aCmd.HasOption ("print"))
4868 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
4871 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
4872 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
4873 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
4874 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
4875 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
4878 if (aFresnel.x() >= 0.f)
4881 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
4883 else if (aFresnel.x() >= -1.5f)
4886 << "|Constant| " << aFresnel.z() << "\n";
4888 else if (aFresnel.x() >= -2.5f)
4891 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
4896 << "|Dielectric| " << aFresnel.y() << "\n";
4901 << "Roughness: " << aBSDF.Roughness << "\n"
4902 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
4903 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
4904 << aBSDF.AbsorptionColor.g() << ", "
4905 << aBSDF.AbsorptionColor.b() << "\n";
4910 if (aCmd.HasOption ("roughness", 1, Standard_True))
4912 aCmd.Arg ("roughness", 0);
4913 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
4916 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
4918 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
4921 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
4923 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
4926 if (aCmd.HasOption ("kd", 3))
4928 aBSDF.Kd = aCmd.ArgVec3f ("kd");
4930 else if (aCmd.HasOption ("kd", 1, Standard_True))
4932 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
4935 if (aCmd.HasOption ("kr", 3))
4937 aBSDF.Kr = aCmd.ArgVec3f ("kr");
4939 else if (aCmd.HasOption ("kr", 1, Standard_True))
4941 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
4944 if (aCmd.HasOption ("kt", 3))
4946 aBSDF.Kt = aCmd.ArgVec3f ("kt");
4948 else if (aCmd.HasOption ("kt", 1, Standard_True))
4950 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
4953 if (aCmd.HasOption ("ks", 3))
4955 aBSDF.Ks = aCmd.ArgVec3f ("ks");
4957 else if (aCmd.HasOption ("ks", 1, Standard_True))
4959 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
4962 if (aCmd.HasOption ("le", 3))
4964 aBSDF.Le = aCmd.ArgVec3f ("le");
4966 else if (aCmd.HasOption ("le", 1, Standard_True))
4968 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
4971 const std::string aFresnelErrorMessage =
4972 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
4974 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
4976 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
4977 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
4979 if (aFresnelType == "schlick")
4981 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
4982 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
4983 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
4984 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
4988 std::cout << aFresnelErrorMessage;
4991 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
4993 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
4994 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
4996 if (aFresnelType == "conductor")
4998 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
4999 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5000 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5004 std::cout << aFresnelErrorMessage;
5007 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5009 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5010 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5012 if (aFresnelType == "dielectric")
5014 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5015 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5017 else if (aFresnelType == "constant")
5019 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5020 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5024 std::cout << aFresnelErrorMessage;
5028 if (aCmd.HasOption ("normalize"))
5033 aMaterial.SetBSDF (aBSDF);
5034 anIObj->SetMaterial (aMaterial);
5041 //==============================================================================
5042 //function : VLoadSelection
5043 //purpose : Adds given objects to map of AIS and loads selection primitives for them
5044 //==============================================================================
5045 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5046 Standard_Integer theArgNb,
5047 const char** theArgVec)
5051 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5055 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5058 ViewerTest::ViewerInit();
5059 aCtx = ViewerTest::GetAISContext();
5062 // Parse input arguments
5063 TColStd_SequenceOfAsciiString aNamesOfIO;
5064 Standard_Boolean isLocal = Standard_False;
5065 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5067 const TCollection_AsciiString aName = theArgVec[anArgIter];
5068 TCollection_AsciiString aNameCase = aName;
5069 aNameCase.LowerCase();
5070 if (aNameCase == "-local")
5072 isLocal = Standard_True;
5076 aNamesOfIO.Append (aName);
5080 if (aNamesOfIO.IsEmpty())
5082 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5087 if (isLocal && !aCtx->HasOpenedContext())
5089 aCtx->OpenLocalContext (Standard_False);
5091 else if (!isLocal && aCtx->HasOpenedContext())
5093 aCtx->CloseAllContexts (Standard_False);
5096 // Load selection of interactive objects
5097 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5099 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5101 const Handle(AIS_InteractiveObject)& aShape = GetMapOfAIS().IsBound2 (aName) ?
5102 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)) : GetAISShapeFromName (aName.ToCString());
5104 if (!aShape.IsNull())
5106 if (!GetMapOfAIS().IsBound2 (aName))
5108 GetMapOfAIS().Bind (aShape, aName);
5111 aCtx->Load (aShape, -1, Standard_False);
5112 aCtx->Activate (aShape, aShape->SelectionMode(), Standard_True);
5119 //==============================================================================
5120 //function : VAutoActivateSelection
5121 //purpose : Activates or deactivates auto computation of selection
5122 //==============================================================================
5123 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5124 Standard_Integer theArgNb,
5125 const char** theArgVec)
5130 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5134 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5137 ViewerTest::ViewerInit();
5138 aCtx = ViewerTest::GetAISContext();
5143 TCollection_AsciiString aSelActivationString;
5144 if (aCtx->GetAutoActivateSelection())
5146 aSelActivationString.Copy ("ON");
5150 aSelActivationString.Copy ("OFF");
5153 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5157 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5158 aCtx->SetAutoActivateSelection (toActivate);
5164 //==============================================================================
5165 //function : ViewerTest::Commands
5166 //purpose : Add all the viewer command in the Draw_Interpretor
5167 //==============================================================================
5169 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5171 ViewerTest::ViewerCommands(theCommands);
5172 ViewerTest::RelationCommands(theCommands);
5173 ViewerTest::ObjectCommands(theCommands);
5174 ViewerTest::FilletCommands(theCommands);
5175 ViewerTest::VoxelCommands(theCommands);
5176 ViewerTest::OpenGlCommands(theCommands);
5178 const char *group = "AIS_Display";
5181 theCommands.Add("visos",
5182 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5183 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5184 __FILE__, visos, group);
5186 theCommands.Add("vdisplay",
5187 "vdisplay [-noupdate|-update] [-local] [-mutable] [-overlay|-underlay]"
5188 "\n\t\t: [-trsfPers flags] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
5189 "\n\t\t: [-dispMode mode] [-highMode mode]"
5190 "\n\t\t: name1 [name2] ... [name n]"
5191 "\n\t\t: Displays named objects."
5192 "\n\t\t: Option -local enables displaying of objects in local"
5193 "\n\t\t: selection context. Local selection context will be opened"
5194 "\n\t\t: if there is not any."
5195 "\n\t\t: -noupdate suppresses viewer redraw call."
5196 "\n\t\t: -mutable enables optimizations for mutable objects."
5197 "\n\t\t: -overlay draws objects in overlay."
5198 "\n\t\t: -underlay draws objects in underlay."
5199 "\n\t\t: -selectable|-noselect controls selection of objects."
5200 "\n\t\t: -trsfPers sets a transform persistence flags."
5201 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5202 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates.",
5203 __FILE__, VDisplay2, group);
5205 theCommands.Add ("vupdate",
5206 "vupdate name1 [name2] ... [name n]"
5207 "\n\t\t: Updates named objects in interactive context",
5208 __FILE__, VUpdate, group);
5210 theCommands.Add("verase",
5211 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5212 "\n\t\t: Erases selected or named objects."
5213 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5214 "\n\t\t: Option -local enables erasing of selected or named objects without"
5215 "\n\t\t: closing local selection context.",
5216 __FILE__, VErase, group);
5218 theCommands.Add("vremove",
5219 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5220 "or vremove [-context] -all to remove all objects"
5221 "\n\t\t: Removes selected or named objects."
5222 "\n\t\t If -context is in arguments, the objects are not deleted"
5223 "\n\t\t from the map of objects and names."
5224 "\n\t\t: Option -local enables removing of selected or named objects without"
5225 "\n\t\t: closing local selection context. Empty local selection context will be"
5227 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5228 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5229 __FILE__, VRemove, group);
5231 theCommands.Add("vdonly",
5232 "vdonly [-noupdate|-update] [name1] ... [name n]"
5233 "\n\t\t: Displays only selected or named objects",
5234 __FILE__,VDonly2,group);
5236 theCommands.Add("vdisplayall",
5237 "vidsplayall [-local]"
5238 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5239 "\n\t\t: Option -local enables displaying of the objects in local"
5240 "\n\t\t: selection context.",
5241 __FILE__, VDisplayAll, group);
5243 theCommands.Add("veraseall",
5244 "veraseall [-local]"
5245 "\n\t\t: Erases all objects displayed in the viewer."
5246 "\n\t\t: Option -local enables erasing of the objects in local"
5247 "\n\t\t: selection context.",
5248 __FILE__, VErase, group);
5250 theCommands.Add("verasetype",
5252 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5253 __FILE__, VEraseType, group);
5254 theCommands.Add("vbounding",
5255 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5256 "\n\t\t: [-print] [-hide]"
5257 "\n\t\t: Temporarily display bounding box of specified Interactive"
5258 "\n\t\t: Objects, or print it to console if -print is specified."
5259 "\n\t\t: Already displayed box might be hidden by -hide option.",
5260 __FILE__,VBounding,group);
5262 theCommands.Add("vdisplaytype",
5263 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5264 __FILE__,VDisplayType,group);
5266 theCommands.Add("vdisplaymode",
5267 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5268 __FILE__,VDispMode,group);
5270 theCommands.Add("verasemode",
5271 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5272 __FILE__,VDispMode,group);
5274 theCommands.Add("vsetdispmode",
5275 "vsetdispmode [name] mode(1,2,..)"
5276 "\n\t\t: Sets display mode for all, selected or named objects.",
5277 __FILE__,VDispMode,group);
5279 theCommands.Add("vunsetdispmode",
5280 "vunsetdispmode [name]"
5281 "\n\t\t: Unsets custom display mode for selected or named objects.",
5282 __FILE__,VDispMode,group);
5284 theCommands.Add("vdir",
5285 "Lists all objects displayed in 3D viewer",
5286 __FILE__,VDir,group);
5288 theCommands.Add("vdump",
5289 #ifdef HAVE_FREEIMAGE
5290 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5291 "\n\t\t: [width Width=0 height Height=0]"
5292 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
5294 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5295 "\n\t\t: [width Width=0 height Height=0]"
5296 "\n\t\t: Dumps content of the active view into PPM image file",
5298 __FILE__,VDump,group);
5300 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5301 __FILE__,VSubInt,group);
5303 theCommands.Add("vaspects",
5304 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5305 "\n\t\t: [-setvisibility 0|1]"
5306 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
5307 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
5308 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
5309 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
5310 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5311 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5312 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5313 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5314 "\n\t\t: Manage presentation properties of all, selected or named objects."
5315 "\n\t\t: When -subshapes is specified than following properties will be"
5316 "\n\t\t: assigned to specified sub-shapes."
5317 "\n\t\t: When -defaults is specified than presentation properties will be"
5318 "\n\t\t: assigned to all objects that have not their own specified properties"
5319 "\n\t\t: and to all objects to be displayed in the future."
5320 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5321 __FILE__,VAspects,group);
5323 theCommands.Add("vsetcolor",
5324 "vsetcolor [-noupdate|-update] [name] ColorName"
5325 "\n\t\t: Sets color for all, selected or named objects."
5326 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5327 __FILE__,VAspects,group);
5329 theCommands.Add("vunsetcolor",
5330 "vunsetcolor [-noupdate|-update] [name]"
5331 "\n\t\t: Resets color for all, selected or named objects."
5332 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5333 __FILE__,VAspects,group);
5335 theCommands.Add("vsettransparency",
5336 "vsettransparency [-noupdate|-update] [name] Coefficient"
5337 "\n\t\t: Sets transparency for all, selected or named objects."
5338 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5339 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5340 __FILE__,VAspects,group);
5342 theCommands.Add("vunsettransparency",
5343 "vunsettransparency [-noupdate|-update] [name]"
5344 "\n\t\t: Resets transparency for all, selected or named objects."
5345 "\n\t\t: Alias for vaspects -unsettransp [name].",
5346 __FILE__,VAspects,group);
5348 theCommands.Add("vsetmaterial",
5349 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5350 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5351 __FILE__,VAspects,group);
5353 theCommands.Add("vunsetmaterial",
5354 "vunsetmaterial [-noupdate|-update] [name]"
5355 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5356 __FILE__,VAspects,group);
5358 theCommands.Add("vsetwidth",
5359 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5360 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5361 __FILE__,VAspects,group);
5363 theCommands.Add("vunsetwidth",
5364 "vunsetwidth [-noupdate|-update] [name]"
5365 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5366 __FILE__,VAspects,group);
5368 theCommands.Add("vsetinteriorstyle",
5369 "vsetinteriorstyle [-noupdate|-update] [name] style"
5370 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5371 __FILE__,VSetInteriorStyle,group);
5373 theCommands.Add("vsensdis",
5374 "vardisp : display active entities",
5375 __FILE__,VDispSensi,group);
5376 theCommands.Add("vsensera",
5377 "vardisp : erase active entities",
5378 __FILE__,VClearSensi,group);
5380 theCommands.Add("vselprecision",
5381 "vselprecision [-unset] [tolerance_value]"
5382 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5383 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
5384 __FILE__,VSelPrecision,group);
5386 theCommands.Add("vperf",
5387 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
5388 __FILE__,VPerf,group);
5390 theCommands.Add("vanimation",
5391 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5392 __FILE__,VAnimation,group);
5394 theCommands.Add("vsetshading",
5395 "vsetshading : vsetshading name Quality(default=0.0008) ",
5396 __FILE__,VShading,group);
5398 theCommands.Add("vunsetshading",
5399 "vunsetshading :vunsetshading name ",
5400 __FILE__,VShading,group);
5402 theCommands.Add ("vtexture",
5403 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5404 " [-scale u v] [-scale off]\n"
5405 " [-origin u v] [-origin off]\n"
5406 " [-repeat u v] [-repeat off]\n"
5407 " [-modulate {on | off}]"
5409 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5410 " specifying one of the predefined textures.\n"
5411 " The options are: \n"
5412 " -scale u v : enable texture scaling and set scale factors\n"
5413 " -scale off : disable texture scaling\n"
5414 " -origin u v : enable texture origin positioning and set the origin\n"
5415 " -origin off : disable texture origin positioning\n"
5416 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5417 " -repeat off : disable texture repeat\n"
5418 " -modulate {on | off} : enable or disable texture modulation\n"
5419 " -default : sets texture mapping default parameters\n"
5420 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5421 "or 'vtexture NameOfShape ?' to list available textures\n",
5422 __FILE__, VTexture, group);
5424 theCommands.Add("vtexscale",
5425 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5426 or 'vtexscale NameOfShape ScaleUV' \n \
5427 or 'vtexscale NameOfShape' to disable scaling\n ",
5428 __FILE__,VTexture,group);
5430 theCommands.Add("vtexorigin",
5431 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5432 or 'vtexorigin NameOfShape UVOrigin' \n \
5433 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5434 __FILE__,VTexture,group);
5436 theCommands.Add("vtexrepeat",
5437 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5438 or 'vtexrepeat NameOfShape UVRepeat \n \
5439 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5442 theCommands.Add("vtexdefault",
5443 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5446 theCommands.Add("vsetam",
5447 "vsetActivatedModes: vsetam mode(1->7) ",
5448 __FILE__,VActivatedMode,group);
5450 theCommands.Add("vunsetam",
5451 "vunsetActivatedModes: vunsetam ",
5452 __FILE__,VActivatedMode,group);
5454 theCommands.Add("vstate",
5455 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5456 "\n\t\t: Reports show/hidden state for selected or named objects"
5457 "\n\t\t: -entities - print low-level information about detected entities"
5458 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5459 __FILE__,VState,group);
5461 theCommands.Add("vpickshapes",
5462 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5463 __FILE__,VPickShape,group);
5465 theCommands.Add("vtypes",
5466 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5469 theCommands.Add("vr", "vr : reading of the shape",
5470 __FILE__,vr, group);
5472 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5473 __FILE__, VPickSelected, group);
5475 theCommands.Add ("vloadselection",
5476 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5477 "\n\t\t: primitives for the shapes with names given without displaying them."
5478 "\n\t\t: -local - open local context before selection computation",
5479 __FILE__, VLoadSelection, group);
5481 theCommands.Add ("vautoactivatesel",
5482 "vautoactivatesel [0|1] : manage or display the option to automatically"
5483 "\n\t\t: activate selection for newly displayed objects"
5484 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5485 __FILE__, VAutoActivateSelection, group);
5487 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5488 "\nAdjusts parameters of material BSDF:"
5489 "\n -help : Shows this message"
5490 "\n -print : Print BSDF"
5491 "\n -kd : Weight of the Lambertian BRDF"
5492 "\n -kr : Weight of the reflection BRDF"
5493 "\n -kt : Weight of the transmission BTDF"
5494 "\n -ks : Weight of the glossy Blinn BRDF"
5495 "\n -le : Self-emitted radiance"
5496 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5497 "\n Schlick x y z, Dielectric x, Conductor x y"
5498 "\n -roughness : Roughness of material (Blinn's exponent)"
5499 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5500 "\n -absorpcolor : Absorption color (only for transparent material)"
5501 "\n -normalize : Normalize BSDF coefficients",
5502 __FILE__, VBsdf, group);
5506 //=====================================================================
5507 //========================= for testing Draft and Rib =================
5508 //=====================================================================
5509 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5510 #include <DBRep.hxx>
5511 #include <TopoDS_Face.hxx>
5512 #include <gp_Pln.hxx>
5513 #include <AIS_KindOfSurface.hxx>
5514 #include <BRepOffsetAPI_DraftAngle.hxx>
5515 #include <Precision.hxx>
5516 #include <BRepAlgo.hxx>
5517 #include <OSD_Environment.hxx>
5518 #include <DrawTrSurf.hxx>
5519 //#include <DbgTools.hxx>
5520 //#include <FeatAlgo_MakeLinearForm.hxx>
5525 //=======================================================================
5526 //function : IsValid
5528 //=======================================================================
5529 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5530 const TopoDS_Shape& theResult,
5531 const Standard_Boolean closedSolid,
5532 const Standard_Boolean GeomCtrl)
5534 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5535 TCollection_AsciiString checkValid = check.Value();
5536 Standard_Boolean ToCheck = Standard_True;
5537 if (!checkValid.IsEmpty()) {
5539 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5541 if ( checkValid=="true" || checkValid=="TRUE" ) {
5542 ToCheck= Standard_False;
5546 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
5549 Standard_Boolean IsValid = Standard_True;
5551 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5556 //===============================================================================
5557 // TDraft : test draft, uses AIS Viewer
5558 // Solid Face Plane Angle Reverse
5559 //===============================================================================
5560 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5562 if (argc < 5) return 1;
5563 // argv[1] - TopoDS_Shape Solid
5564 // argv[2] - TopoDS_Shape Face
5565 // argv[3] - TopoDS_Shape Plane
5566 // argv[4] - Standard_Real Angle
5567 // argv[5] - Standard_Integer Reverse
5569 // Sprintf(prefix, argv[1]);
5570 Standard_Real anAngle = 0;
5571 Standard_Boolean Rev = Standard_False;
5572 Standard_Integer rev = 0;
5573 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5574 TopoDS_Shape face = GetShapeFromName(argv[2]);
5575 TopoDS_Face Face = TopoDS::Face(face);
5576 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5577 if (Plane.IsNull ()) {
5578 di << "TEST : Plane is NULL" << "\n";
5581 anAngle = Draw::Atof(argv[4]);
5582 anAngle = 2*M_PI * anAngle / 360.0;
5584 Handle( Geom_Surface )aSurf;
5585 AIS_KindOfSurface aSurfType;
5586 Standard_Real Offset;
5588 if(argc > 4) { // == 5
5589 rev = Draw::Atoi(argv[5]);
5590 Rev = (rev)? Standard_True : Standard_False;
5593 TopoDS_Face face2 = TopoDS::Face(Plane);
5594 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5596 di << "TEST : Can't find plane" << "\n";
5600 aDir = aPln.Axis().Direction();
5603 if (Plane.Orientation() == TopAbs_REVERSED)
5605 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5607 BRepOffsetAPI_DraftAngle Draft (Solid);
5609 if(Abs(anAngle)< Precision::Angular()) {
5610 di << "TEST : NULL angle" << "\n";
5613 if(Rev) anAngle = - anAngle;
5614 Draft.Add (Face, aDir, anAngle, aPln);
5616 if (!Draft.IsDone()) {
5617 di << "TEST : Draft Not DONE " << "\n";
5620 TopTools_ListOfShape Larg;
5622 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5623 di << "TEST : DesignAlgo returns Not valid" << "\n";
5627 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5628 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5630 if ( !ais.IsNull() ) {
5631 ais->SetColor(DEFAULT_COLOR);
5632 ais->SetMaterial(DEFAULT_MATERIAL);
5633 // Display the AIS_Shape without redraw
5634 Ctx->Display(ais, Standard_False);
5636 const char *Name = "draft1";
5637 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5639 Handle(AIS_InteractiveObject) an_object =
5640 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5641 if (!an_object.IsNull()) {
5642 Ctx->Remove(an_object,
5644 GetMapOfAIS().UnBind2(Name) ;
5647 GetMapOfAIS().Bind(ais, Name);
5648 // DBRep::Set("draft", ais->Shape());
5650 Ctx->Display(ais, Standard_True);
5654 //==============================================================================
5655 //function : splitParameter
5656 //purpose : Split parameter string to parameter name and parameter value
5657 //==============================================================================
5658 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5659 TCollection_AsciiString& theName,
5660 TCollection_AsciiString& theValue)
5662 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5664 if (aParamNameEnd == 0)
5666 return Standard_False;
5669 TCollection_AsciiString aString (theString);
5670 if (aParamNameEnd != 0)
5672 theValue = aString.Split (aParamNameEnd);
5673 aString.Split (aString.Length() - 1);
5677 return Standard_True;
5680 //============================================================================
5682 //============================================================================
5683 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5686 DrawTrSurf::BasicCommands(theCommands);
5687 const char* group = "Check Features Operations commands";
5689 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5691 &TDraft,group); //Draft_Modification
5694 //==============================================================================
5695 // ViewerTest::Factory
5696 //==============================================================================
5697 void ViewerTest::Factory(Draw_Interpretor& theDI)
5699 // definition of Viewer Command
5700 ViewerTest::Commands(theDI);
5701 ViewerTest::AviCommands(theDI);
5704 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
5708 // Declare entry point PLUGINFACTORY