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>
29 #include <TopLoc_Location.hxx>
30 #include <TopTools_HArray1OfShape.hxx>
31 #include <TColStd_HArray1OfTransient.hxx>
32 #include <TColStd_SequenceOfAsciiString.hxx>
33 #include <TColStd_HSequenceOfAsciiString.hxx>
34 #include <TColStd_MapOfTransient.hxx>
35 #include <OSD_Timer.hxx>
36 #include <Geom_Axis2Placement.hxx>
37 #include <Geom_Axis1Placement.hxx>
38 #include <gp_Trsf.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <BRepAdaptor_Curve.hxx>
41 #include <StdSelect_ShapeTypeFilter.hxx>
43 #include <AIS_ColoredShape.hxx>
44 #include <AIS_InteractiveObject.hxx>
45 #include <AIS_Trihedron.hxx>
46 #include <AIS_Axis.hxx>
47 #include <AIS_Relation.hxx>
48 #include <AIS_TypeFilter.hxx>
49 #include <AIS_SignatureFilter.hxx>
50 #include <AIS_LocalContext.hxx>
51 #include <AIS_ListOfInteractive.hxx>
52 #include <AIS_ListIteratorOfListOfInteractive.hxx>
53 #include <Aspect_InteriorStyle.hxx>
54 #include <Aspect_Window.hxx>
55 #include <Graphic3d_AspectFillArea3d.hxx>
56 #include <Graphic3d_AspectLine3d.hxx>
57 #include <Graphic3d_CStructure.hxx>
58 #include <Graphic3d_TextureRoot.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Prs3d_Drawer.hxx>
61 #include <Prs3d_ShadingAspect.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <Prs3d_PointAspect.hxx>
64 #include <Select3D_SensitiveWire.hxx>
65 #include <SelectMgr_EntityOwner.hxx>
66 #include <StdSelect_BRepOwner.hxx>
67 #include <StdSelect_ViewerSelector3d.hxx>
68 #include <Select3D_Projector.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 #include <NIS_InteractiveContext.hxx>
86 #include <NIS_Triangulated.hxx>
87 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
89 #include <Quantity_Color.hxx>
90 #include <Quantity_NameOfColor.hxx>
92 #include <Graphic3d_NameOfMaterial.hxx>
94 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
95 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
96 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
98 //=======================================================================
99 //function : GetColorFromName
100 //purpose : get the Quantity_NameOfColor from a string
101 //=======================================================================
103 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
105 Quantity_NameOfColor aColor = DEFAULT_COLOR;
106 Quantity_Color::ColorFromName (theName, aColor);
110 //=======================================================================
111 //function : GetTypeNames
113 //=======================================================================
114 static const char** GetTypeNames()
116 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
117 "Shape","ConnectedShape","MultiConn.Shape",
118 "ConnectedInter.","MultiConn.",
119 "Constraint","Dimension"};
120 static const char** ThePointer = names;
124 //=======================================================================
125 //function : GetTypeAndSignfromString
127 //=======================================================================
128 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
130 const char ** thefullnames = GetTypeNames();
131 Standard_Integer index(-1);
133 for(Standard_Integer i=0;i<=13 && index==-1;i++)
134 if(!strcasecmp(name,thefullnames[i]))
138 TheType = AIS_KOI_None;
144 TheType = AIS_KOI_Datum;
148 TheType = AIS_KOI_Shape;
152 TheType = AIS_KOI_Object;
156 TheType = AIS_KOI_Relation;
165 #include <Draw_Interpretor.hxx>
167 #include <Draw_Appli.hxx>
171 #include <TCollection_AsciiString.hxx>
172 #include <V3d_Viewer.hxx>
173 #include <V3d_View.hxx>
176 #include <AIS_InteractiveContext.hxx>
177 #include <AIS_Shape.hxx>
178 #include <AIS_TexturedShape.hxx>
179 #include <AIS_DisplayMode.hxx>
180 #include <TColStd_MapOfInteger.hxx>
181 #include <AIS_MapOfInteractive.hxx>
182 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
183 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
184 #include <ViewerTest_EventManager.hxx>
186 #include <TopoDS_Solid.hxx>
187 #include <BRepTools.hxx>
188 #include <BRep_Builder.hxx>
189 #include <TopAbs_ShapeEnum.hxx>
191 #include <TopoDS.hxx>
192 #include <BRep_Tool.hxx>
195 #include <Draw_Window.hxx>
196 #include <AIS_ListIteratorOfListOfInteractive.hxx>
197 #include <AIS_ListOfInteractive.hxx>
198 #include <AIS_DisplayMode.hxx>
199 #include <TopTools_ListOfShape.hxx>
200 #include <BRepOffsetAPI_MakeThickSolid.hxx>
201 #include <BRepOffset.hxx>
203 //==============================================================================
204 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
205 //==============================================================================
206 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
207 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
212 //==============================================================================
213 //function : VDisplayAISObject
214 //purpose : register interactive object in the map of AIS objects;
215 // if other object with such name already registered, it will be kept
216 // or replaced depending on value of <theReplaceIfExists>,
217 // if "true" - the old object will be cleared from AIS context;
218 // returns Standard_True if <theAISObj> registered in map;
219 //==============================================================================
220 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
221 const Handle(AIS_InteractiveObject)& theAISObj,
222 Standard_Boolean theReplaceIfExists = Standard_True)
224 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
225 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
226 if (aContextAIS.IsNull())
228 std::cout << "AIS context is not available.\n";
229 return Standard_False;
232 if (aMap.IsBound2 (theName))
234 if (!theReplaceIfExists)
236 std::cout << "Other interactive object has been already "
237 << "registered with name: " << theName << ".\n"
238 << "Please use another name.\n";
239 return Standard_False;
242 // stop displaying object
243 Handle(AIS_InteractiveObject) anOldObj =
244 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
246 if (!anOldObj.IsNull())
247 aContextAIS->Remove (anOldObj, Standard_True);
249 // remove name and old object from map
250 aMap.UnBind2 (theName);
253 if (theAISObj.IsNull())
255 // object with specified name already unbound
256 return Standard_True;
259 // unbind AIS object if was bound with another name
260 aMap.UnBind1 (theAISObj);
262 // can be registered without rebinding
263 aMap.Bind (theAISObj, theName);
264 aContextAIS->Display (theAISObj, Standard_True);
265 return Standard_True;
268 static TColStd_MapOfInteger theactivatedmodes(8);
269 static TColStd_ListOfTransient theEventMgrs;
271 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
272 const Handle(AIS_InteractiveContext)& Ctx)
274 theEventMgrs.Clear();
275 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
278 static Handle(V3d_View)& a3DView()
280 static Handle(V3d_View) Viou;
285 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
286 static Handle(AIS_InteractiveContext) aContext;
290 const Handle(V3d_View)& ViewerTest::CurrentView()
294 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
299 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
301 static Handle(NIS_InteractiveContext) aContext;
302 if (aContext.IsNull()) {
303 aContext = new NIS_InteractiveContext;
304 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
309 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
311 return TheAISContext();
314 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
316 TheAISContext() = aCtx;
317 ViewerTest::ResetEventManager();
320 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
322 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
325 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
327 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
331 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
332 theEventMgrs.Prepend(EM);
335 void ViewerTest::UnsetEventManager()
337 theEventMgrs.RemoveFirst();
341 void ViewerTest::ResetEventManager()
343 const Handle(NIS_View) aView =
344 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
345 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
348 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
350 Handle(ViewerTest_EventManager) EM;
351 if(theEventMgrs.IsEmpty()) return EM;
352 Handle(Standard_Transient) Tr = theEventMgrs.First();
353 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
357 //=======================================================================
358 //function : Get Context and active view
360 //=======================================================================
361 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
362 Handle(V3d_View)& theView)
364 theCtx = ViewerTest::GetAISContext();
365 theView = ViewerTest::CurrentView();
369 std::cout << "Error: cannot find an active view!\n";
370 return Standard_False;
372 return Standard_True;
375 //==============================================================================
376 //function : GetShapeFromName
377 //purpose : Compute an Shape from a draw variable or a file name
378 //==============================================================================
380 static TopoDS_Shape GetShapeFromName(const char* name)
382 TopoDS_Shape S = DBRep::Get(name);
385 BRep_Builder aBuilder;
386 BRepTools::Read( S, name, aBuilder);
392 //==============================================================================
393 //function : GetAISShapeFromName
394 //purpose : Compute an AIS_Shape from a draw variable or a file name
395 //==============================================================================
396 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
398 Handle(AIS_Shape) retsh;
400 if(GetMapOfAIS().IsBound2(name)){
401 const Handle(AIS_InteractiveObject) IO =
402 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
404 if(IO->Type()==AIS_KOI_Shape) {
405 if(IO->Signature()==0){
406 retsh = *((Handle(AIS_Shape)*)&IO);
409 cout << "an Object which is not an AIS_Shape "
410 "already has this name!!!"<<endl;
417 TopoDS_Shape S = GetShapeFromName(name);
419 retsh = new AIS_Shape(S);
425 //==============================================================================
427 //purpose : Remove all the object from the viewer
428 //==============================================================================
429 void ViewerTest::Clear()
431 if ( !a3DView().IsNull() ) {
432 if (TheAISContext()->HasOpenedContext())
433 TheAISContext()->CloseLocalContext();
434 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
435 while ( it.More() ) {
436 cout << "Remove " << it.Key2() << endl;
437 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
438 const Handle(AIS_InteractiveObject) anObj =
439 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
440 TheAISContext()->Remove(anObj,Standard_False);
441 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
442 const Handle(NIS_InteractiveObject) anObj =
443 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
444 TheNISContext()->Remove(anObj);
448 TheAISContext()->UpdateCurrentViewer();
449 // TheNISContext()->UpdateViews();
450 GetMapOfAIS().Clear();
454 //==============================================================================
455 //function : StandardModesActivation
456 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
458 //==============================================================================
459 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
461 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
463 if (TheAISContext()->HasOpenedContext())
464 aContext->CloseLocalContext();
467 if(!aContext->HasOpenedContext()) {
468 // To unhilight the preselected object
469 aContext->UnhilightCurrents(Standard_False);
470 // Open a local Context in order to be able to select subshape from
471 // the selected shape if any or for all if there is no selection
472 if (!aContext->FirstCurrentObject().IsNull()){
473 aContext->OpenLocalContext(Standard_False);
475 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
476 aContext->Load( aContext->Current(),-1,Standard_True);
480 aContext->OpenLocalContext();
483 const char *cmode="???";
486 case 0: cmode = "Shape"; break;
487 case 1: cmode = "Vertex"; break;
488 case 2: cmode = "Edge"; break;
489 case 3: cmode = "Wire"; break;
490 case 4: cmode = "Face"; break;
491 case 5: cmode = "Shell"; break;
492 case 6: cmode = "Solid"; break;
493 case 7: cmode = "Compsolid"; break;
494 case 8: cmode = "Compound"; break;
497 if(theactivatedmodes.Contains(mode))
499 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
500 theactivatedmodes.Remove(mode);
501 cout<<"Mode "<< cmode <<" OFF"<<endl;
505 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
506 theactivatedmodes.Add(mode);
507 cout<<"Mode "<< cmode << " ON" << endl;
512 //==============================================================================
513 //function : CopyIsoAspect
514 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
515 //==============================================================================
516 static Handle(Prs3d_IsoAspect) CopyIsoAspect
517 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
518 const Standard_Integer theNbIsos)
520 Quantity_Color aColor;
521 Aspect_TypeOfLine aType;
522 Standard_Real aWidth;
524 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
526 Handle(Prs3d_IsoAspect) aResult =
527 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
532 //==============================================================================
534 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
535 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
536 //==============================================================================
537 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
539 if (TheAISContext().IsNull()) {
540 di << argv[0] << " Call 'vinit' before!\n";
545 di << "Current number of isos : " <<
546 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
547 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
548 di << "IsoOnPlane mode is " <<
549 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
554 Standard_Integer aLastInd = argc - 1;
555 Standard_Boolean isChanged = Standard_False;
556 Standard_Integer aNbUIsos = 0;
557 Standard_Integer aNbVIsos = 0;
560 Standard_Boolean isIsoOnPlane = Standard_False;
562 if (strcmp(argv[aLastInd], "1") == 0) {
563 isIsoOnPlane = Standard_True;
564 isChanged = Standard_True;
565 } else if (strcmp(argv[aLastInd], "0") == 0) {
566 isIsoOnPlane = Standard_False;
567 isChanged = Standard_True;
571 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
572 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
575 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
576 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
578 TheAISContext()->IsoOnPlane(isIsoOnPlane);
581 // If there are no shapes provided set the default numbers.
582 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
583 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
590 for (i = 1; i <= aLastInd; i++) {
591 TCollection_AsciiString name(argv[i]);
592 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
595 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
596 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
597 const Handle(AIS_InteractiveObject) aShape =
598 Handle(AIS_InteractiveObject)::DownCast (anObj);
599 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
600 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
601 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
604 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
605 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
606 TheAISContext()->SetLocalAttributes
607 (aShape, CurDrawer, Standard_False);
608 TheAISContext()->Redisplay(aShape);
610 di << "Number of isos for " << argv[i] << " : "
611 << aUIso->Number() << " " << aVIso->Number() << "\n";
614 di << argv[i] << ": Not an AIS interactive object!\n";
617 di << argv[i] << ": Use 'vdisplay' before\n";
622 TheAISContext()->UpdateCurrentViewer();
628 //==============================================================================
629 //function : VDispAreas,VDispSensitive,...
631 //==============================================================================
632 static Standard_Integer VDispAreas (Draw_Interpretor& ,
633 Standard_Integer theArgNb,
638 std::cout << "Error: wrong syntax!\n";
642 Handle(AIS_InteractiveContext) aCtx;
643 Handle(V3d_View) aView;
644 if (!getCtxAndView (aCtx, aView))
649 aCtx->DisplayActiveAreas (aView);
652 static Standard_Integer VClearAreas (Draw_Interpretor& ,
653 Standard_Integer theArgNb,
658 std::cout << "Error: wrong syntax!\n";
662 Handle(AIS_InteractiveContext) aCtx;
663 Handle(V3d_View) aView;
664 if (!getCtxAndView (aCtx, aView))
669 aCtx->ClearActiveAreas (aView);
673 static Standard_Integer VDispSensi (Draw_Interpretor& ,
674 Standard_Integer theArgNb,
679 std::cout << "Error: wrong syntax!\n";
683 Handle(AIS_InteractiveContext) aCtx;
684 Handle(V3d_View) aView;
685 if (!getCtxAndView (aCtx, aView))
690 aCtx->DisplayActiveSensitive (aView);
695 static Standard_Integer VClearSensi (Draw_Interpretor& ,
696 Standard_Integer theArgNb,
701 std::cout << "Error: wrong syntax!\n";
705 Handle(AIS_InteractiveContext) aCtx;
706 Handle(V3d_View) aView;
707 if (!getCtxAndView (aCtx, aView))
711 aCtx->ClearActiveSensitive (aView);
715 //==============================================================================
717 //purpose : To list the displayed object with their attributes
718 //==============================================================================
719 static int VDir (Draw_Interpretor& theDI,
723 if (!a3DView().IsNull())
728 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
729 anIter.More(); anIter.Next())
731 theDI << "\t" << anIter.Key2().ToCString() << "\n";
736 //==============================================================================
737 //function : VSelPrecision
738 //purpose : To set the selection precision mode and tolerance value
739 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
740 // value (integer number of pixel for window mode, double value of
741 // sensitivity for view mode). Without arguments the function just
742 // prints the current precision mode and the corresponding tolerance.
743 //==============================================================================
744 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
748 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
752 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
753 if( aContext.IsNull() )
758 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
759 if( aMode == StdSelect_SM_WINDOW )
761 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
762 di << "Precision mode : 0 (window)\n";
763 di << "Pixel tolerance : " << aPixelTolerance << "\n";
765 else if( aMode == StdSelect_SM_VIEW )
767 Standard_Real aSensitivity = aContext->Sensitivity();
768 di << "Precision mode : 1 (view)\n";
769 di << "Sensitivity : " << aSensitivity << "\n";
774 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
775 aContext->SetSensitivityMode( aMode );
778 if( aMode == StdSelect_SM_WINDOW )
780 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
781 aContext->SetPixelTolerance( aPixelTolerance );
783 else if( aMode == StdSelect_SM_VIEW )
785 Standard_Real aSensitivity = Draw::Atof( argv[2] );
786 aContext->SetSensitivity( aSensitivity );
793 //==============================================================================
795 //purpose : To dump the active view snapshot to image file
796 //==============================================================================
797 static Standard_Integer VDump (Draw_Interpretor& theDI,
798 Standard_Integer theArgNb,
799 Standard_CString* theArgVec)
803 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
807 Standard_Integer anArgIter = 1;
808 Standard_CString aFilePath = theArgVec[anArgIter++];
809 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
810 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
811 Standard_Integer aWidth = 0;
812 Standard_Integer aHeight = 0;
813 for (; anArgIter < theArgNb; ++anArgIter)
815 TCollection_AsciiString anArg (theArgVec[anArgIter]);
819 aBufferType = Graphic3d_BT_RGBA;
821 else if (anArg == "rgb")
823 aBufferType = Graphic3d_BT_RGB;
825 else if (anArg == "depth")
827 aBufferType = Graphic3d_BT_Depth;
829 else if (anArg == "l"
832 aStereoOpts = V3d_SDO_LEFT_EYE;
834 else if (anArg == "r"
837 aStereoOpts = V3d_SDO_RIGHT_EYE;
839 else if (anArg == "mono")
841 aStereoOpts = V3d_SDO_MONO;
843 else if (anArg == "w"
848 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
851 else if (++anArgIter >= theArgNb)
853 std::cout << "Error: integer value is expected right after 'width'\n";
856 aWidth = Draw::Atoi (theArgVec[anArgIter]);
858 else if (anArg == "h"
859 || anArg == "height")
863 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
866 if (++anArgIter >= theArgNb)
868 std::cout << "Error: integer value is expected right after 'height'\n";
871 aHeight = Draw::Atoi (theArgVec[anArgIter]);
873 else if (anArg.IsIntegerValue())
875 // compatibility with old syntax
879 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
882 else if (++anArgIter >= theArgNb)
884 std::cout << "Error: height value is expected right after width\n";
887 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
888 aHeight = Draw::Atoi (theArgVec[anArgIter]);
892 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
896 if ((aWidth <= 0 && aHeight > 0)
897 || (aWidth > 0 && aHeight <= 0))
899 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
903 Handle(V3d_View) aView = ViewerTest::CurrentView();
906 std::cout << "Error: cannot find an active view!\n";
910 if (aWidth <= 0 || aHeight <= 0)
912 if (aStereoOpts != V3d_SDO_MONO)
914 aView->Window()->Size (aWidth, aHeight);
918 if (!aView->Dump (aFilePath, aBufferType))
920 theDI << "Fail: view dump failed!\n";
926 Image_AlienPixMap aPixMap;
927 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
929 theDI << "Fail: view dump failed!\n";
933 if (aPixMap.SizeX() != Standard_Size(aWidth)
934 || aPixMap.SizeY() != Standard_Size(aHeight))
936 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
937 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
939 if (!aPixMap.Save (aFilePath))
941 theDI << "Fail: image can not be saved!\n";
947 //==============================================================================
948 //function : Displays,Erase...
951 //==============================================================================
952 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
953 const Standard_Integer Mode,
954 const Standard_Integer TypeOfOperation,
955 const Standard_Boolean Upd)
957 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
959 switch(TypeOfOperation){
961 Ctx->Display(IO,Mode,Upd);
969 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
971 Ctx->SetDisplayMode(IO,Mode,Upd);
976 Ctx->SetDisplayMode(0,Upd);
978 Ctx->UnsetDisplayMode(IO,Upd);
985 //=======================================================================
988 //=======================================================================
989 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
992 TCollection_AsciiString name;
995 // display others presentations
996 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
997 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
998 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
999 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1001 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1003 //unset displaymode.. comportement particulier...
1004 if(TypeOfOperation==4){
1006 if(Ctx->NbCurrents()==0 ||
1007 Ctx->NbSelected()==0){
1008 Handle(AIS_InteractiveObject) IO;
1009 VwrTst_DispErase(IO,-1,4,Standard_False);
1011 else if(!Ctx->HasOpenedContext()){
1012 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1013 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1016 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1017 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1018 Ctx->UpdateCurrentViewer();
1021 Handle(AIS_InteractiveObject) IO;
1023 if(GetMapOfAIS().IsBound2(name)){
1024 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1026 VwrTst_DispErase(IO,-1,4,Standard_True);
1031 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1032 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1033 Handle(AIS_InteractiveObject) IO;
1034 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1036 if(!Ctx->HasOpenedContext()){
1037 // set/unset display mode sur le Contexte...
1038 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1039 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1041 Ctx->UpdateCurrentViewer();
1044 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1045 Ctx->Display(Ctx->Interactive(),Dmode);
1049 Handle(AIS_InteractiveObject) IO;
1051 if(GetMapOfAIS().IsBound2(name))
1052 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1054 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1060 //=======================================================================
1063 //=======================================================================
1064 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1066 if(argc==1) return 1;
1067 Standard_Integer On = Draw::Atoi(argv[1]);
1068 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1072 if(!Ctx->HasOpenedContext()){
1073 di<<"sub intensite ";
1076 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1077 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1079 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1081 di <<"passage dans off"<<"\n";
1082 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1087 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1089 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1091 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1094 Ctx->UpdateCurrentViewer();
1097 Handle(AIS_InteractiveObject) IO;
1098 TCollection_AsciiString name = argv[2];
1099 if(GetMapOfAIS().IsBound2(name)){
1100 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1103 Ctx->SubIntensityOn(IO);
1105 Ctx->SubIntensityOff(IO);
1113 //! Auxiliary class to iterate presentations from different collections.
1114 class ViewTest_PrsIter
1118 //! Create and initialize iterator object.
1119 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1120 : mySource (IterSource_All)
1122 NCollection_Sequence<TCollection_AsciiString> aNames;
1123 if (!theName.IsEmpty())
1124 aNames.Append (theName);
1128 //! Create and initialize iterator object.
1129 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1130 : mySource (IterSource_All)
1135 //! Initialize the iterator.
1136 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1138 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1140 mySelIter.Nullify();
1141 myCurrent.Nullify();
1142 myCurrentTrs.Nullify();
1143 if (!mySeq.IsEmpty())
1145 mySource = IterSource_List;
1146 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1148 else if (aCtx->NbCurrents() > 0)
1150 mySource = IterSource_Selected;
1152 mySelIter->InitCurrent();
1156 mySource = IterSource_All;
1157 myMapIter.Initialize (GetMapOfAIS());
1162 const TCollection_AsciiString& CurrentName() const
1164 return myCurrentName;
1167 const Handle(AIS_InteractiveObject)& Current() const
1172 const Handle(Standard_Transient)& CurrentTrs() const
1174 return myCurrentTrs;
1177 //! @return true if iterator points to valid object within collection
1178 Standard_Boolean More() const
1182 case IterSource_All: return myMapIter.More();
1183 case IterSource_List: return mySeqIter.More();
1184 case IterSource_Selected: return mySelIter->MoreCurrent();
1186 return Standard_False;
1189 //! Go to the next item.
1192 myCurrentName.Clear();
1193 myCurrentTrs.Nullify();
1194 myCurrent.Nullify();
1197 case IterSource_All:
1202 case IterSource_List:
1207 case IterSource_Selected:
1209 mySelIter->NextCurrent();
1222 case IterSource_All:
1224 if (myMapIter.More())
1226 myCurrentName = myMapIter.Key2();
1227 myCurrentTrs = myMapIter.Key1();
1228 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1232 case IterSource_List:
1234 if (mySeqIter.More())
1236 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1238 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1241 myCurrentName = mySeqIter.Value();
1242 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1243 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1247 case IterSource_Selected:
1249 if (mySelIter->MoreCurrent())
1251 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1252 myCurrent = mySelIter->Current();
1270 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1271 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1272 NCollection_Sequence<TCollection_AsciiString> mySeq;
1273 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1275 TCollection_AsciiString myCurrentName;//!< current item name
1276 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1277 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1279 IterSource mySource; //!< iterated collection
1283 //==============================================================================
1284 //function : VInteriorStyle
1285 //purpose : sets interior style of the a selected or named or displayed shape
1286 //==============================================================================
1287 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1288 Standard_Integer theArgNb,
1289 const char** theArgVec)
1291 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1292 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1295 std::cerr << "Error: no active view!\n";
1299 Standard_Integer anArgIter = 1;
1300 for (; anArgIter < theArgNb; ++anArgIter)
1302 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1307 TCollection_AsciiString aName;
1308 if (theArgNb - anArgIter == 2)
1310 aName = theArgVec[anArgIter++];
1312 else if (theArgNb - anArgIter != 1)
1314 std::cout << "Error: wrong number of arguments! See usage:\n";
1315 theDI.PrintHelp (theArgVec[0]);
1318 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1319 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1320 aStyleArg.LowerCase();
1321 if (aStyleArg == "empty")
1325 else if (aStyleArg == "hollow")
1329 else if (aStyleArg == "hatch")
1333 else if (aStyleArg == "solid")
1337 else if (aStyleArg == "hiddenline")
1343 anInterStyle = aStyleArg.IntegerValue();
1345 if (anInterStyle < Aspect_IS_EMPTY
1346 || anInterStyle > Aspect_IS_HIDDENLINE)
1348 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1349 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1353 if (!aName.IsEmpty()
1354 && !GetMapOfAIS().IsBound2 (aName))
1356 std::cout << "Error: object " << aName << " is not displayed!\n";
1360 if (aCtx->HasOpenedContext())
1362 aCtx->CloseLocalContext();
1364 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1366 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1369 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1370 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1371 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1372 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1373 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1379 //! Auxiliary structure for VAspects
1380 struct ViewerTest_AspectsChangeSet
1382 Standard_Integer ToSetVisibility;
1383 Standard_Integer Visibility;
1385 Standard_Integer ToSetColor;
1386 Quantity_Color Color;
1388 Standard_Integer ToSetLineWidth;
1389 Standard_Real LineWidth;
1391 Standard_Integer ToSetTransparency;
1392 Standard_Real Transparency;
1394 Standard_Integer ToSetMaterial;
1395 Graphic3d_NameOfMaterial Material;
1396 TCollection_AsciiString MatName;
1398 NCollection_Sequence<TopoDS_Shape> SubShapes;
1400 Standard_Integer ToSetShowFreeBoundary;
1401 Standard_Integer ToSetFreeBoundaryWidth;
1402 Standard_Real FreeBoundaryWidth;
1403 Standard_Integer ToSetFreeBoundaryColor;
1404 Quantity_Color FreeBoundaryColor;
1406 //! Empty constructor
1407 ViewerTest_AspectsChangeSet()
1408 : ToSetVisibility (0),
1411 Color (DEFAULT_COLOR),
1414 ToSetTransparency (0),
1417 Material (Graphic3d_NOM_DEFAULT),
1418 ToSetShowFreeBoundary (0),
1419 ToSetFreeBoundaryWidth (0),
1420 FreeBoundaryWidth (1.0),
1421 ToSetFreeBoundaryColor (0),
1422 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
1424 //! @return true if no changes have been requested
1425 Standard_Boolean IsEmpty() const
1427 return ToSetVisibility == 0
1428 && ToSetLineWidth == 0
1429 && ToSetTransparency == 0
1431 && ToSetMaterial == 0
1432 && ToSetShowFreeBoundary == 0
1433 && ToSetFreeBoundaryColor == 0
1434 && ToSetFreeBoundaryWidth == 0;
1437 //! @return true if properties are valid
1438 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1440 Standard_Boolean isOk = Standard_True;
1441 if (Visibility != 0 && Visibility != 1)
1443 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1444 isOk = Standard_False;
1446 if (LineWidth <= 0.0
1447 || LineWidth > 10.0)
1449 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1450 isOk = Standard_False;
1452 if (Transparency < 0.0
1453 || Transparency > 1.0)
1455 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1456 isOk = Standard_False;
1459 && ToSetTransparency)
1461 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1462 isOk = Standard_False;
1464 if (ToSetMaterial == 1
1465 && Material == Graphic3d_NOM_DEFAULT)
1467 std::cout << "Error: unknown material " << MatName << ".\n";
1468 isOk = Standard_False;
1470 if (FreeBoundaryWidth <= 0.0
1471 || FreeBoundaryWidth > 10.0)
1473 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1474 isOk = Standard_False;
1481 //==============================================================================
1482 //function : VAspects
1484 //==============================================================================
1485 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1486 Standard_Integer theArgNb,
1487 const char** theArgVec)
1489 TCollection_AsciiString aCmdName (theArgVec[0]);
1490 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1491 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1494 std::cerr << "Error: no active view!\n";
1498 Standard_Integer anArgIter = 1;
1499 Standard_Boolean isDefaults = Standard_False;
1500 NCollection_Sequence<TCollection_AsciiString> aNames;
1501 for (; anArgIter < theArgNb; ++anArgIter)
1503 TCollection_AsciiString anArg = theArgVec[anArgIter];
1504 if (anUpdateTool.parseRedrawMode (anArg))
1508 else if (!anArg.IsEmpty()
1509 && anArg.Value (1) != '-')
1511 aNames.Append (anArg);
1515 if (anArg == "-defaults")
1517 isDefaults = Standard_True;
1524 if (!aNames.IsEmpty() && isDefaults)
1526 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1530 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1531 aChanges.Append (ViewerTest_AspectsChangeSet());
1532 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1534 // parse syntax of legacy commands
1535 if (aCmdName == "vsetwidth")
1537 if (aNames.IsEmpty()
1538 || !aNames.Last().IsRealValue())
1540 std::cout << "Error: not enough arguments!\n";
1543 aChangeSet->ToSetLineWidth = 1;
1544 aChangeSet->LineWidth = aNames.Last().RealValue();
1545 aNames.Remove (aNames.Length());
1547 else if (aCmdName == "vunsetwidth")
1549 aChangeSet->ToSetLineWidth = -1;
1551 else if (aCmdName == "vsetcolor")
1553 if (aNames.IsEmpty())
1555 std::cout << "Error: not enough arguments!\n";
1558 aChangeSet->ToSetColor = 1;
1560 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1561 Standard_Boolean isOk = Standard_False;
1562 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1564 aChangeSet->Color = aColor;
1565 aNames.Remove (aNames.Length());
1566 isOk = Standard_True;
1568 else if (aNames.Length() >= 3)
1570 const TCollection_AsciiString anRgbStr[3] =
1572 aNames.Value (aNames.Upper() - 2),
1573 aNames.Value (aNames.Upper() - 1),
1574 aNames.Value (aNames.Upper() - 0)
1576 isOk = anRgbStr[0].IsRealValue()
1577 && anRgbStr[1].IsRealValue()
1578 && anRgbStr[2].IsRealValue();
1581 Graphic3d_Vec4d anRgb;
1582 anRgb.x() = anRgbStr[0].RealValue();
1583 anRgb.y() = anRgbStr[1].RealValue();
1584 anRgb.z() = anRgbStr[2].RealValue();
1585 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1586 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1587 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1589 std::cout << "Error: RGB color values should be within range 0..1!\n";
1592 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1593 aNames.Remove (aNames.Length());
1594 aNames.Remove (aNames.Length());
1595 aNames.Remove (aNames.Length());
1600 std::cout << "Error: not enough arguments!\n";
1604 else if (aCmdName == "vunsetcolor")
1606 aChangeSet->ToSetColor = -1;
1608 else if (aCmdName == "vsettransparency")
1610 if (aNames.IsEmpty()
1611 || !aNames.Last().IsRealValue())
1613 std::cout << "Error: not enough arguments!\n";
1616 aChangeSet->ToSetTransparency = 1;
1617 aChangeSet->Transparency = aNames.Last().RealValue();
1618 aNames.Remove (aNames.Length());
1620 else if (aCmdName == "vunsettransparency")
1622 aChangeSet->ToSetTransparency = -1;
1624 else if (aCmdName == "vsetmaterial")
1626 if (aNames.IsEmpty())
1628 std::cout << "Error: not enough arguments!\n";
1631 aChangeSet->ToSetMaterial = 1;
1632 aChangeSet->MatName = aNames.Last();
1633 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1634 aNames.Remove (aNames.Length());
1636 else if (aCmdName == "vunsetmaterial")
1638 aChangeSet->ToSetMaterial = -1;
1640 else if (anArgIter >= theArgNb)
1642 std::cout << "Error: not enough arguments!\n";
1646 if (!aChangeSet->IsEmpty())
1648 anArgIter = theArgNb;
1650 for (; anArgIter < theArgNb; ++anArgIter)
1652 TCollection_AsciiString anArg = theArgVec[anArgIter];
1654 if (anArg == "-setwidth"
1655 || anArg == "-setlinewidth")
1657 if (++anArgIter >= theArgNb)
1659 std::cout << "Error: wrong syntax at " << anArg << "\n";
1662 aChangeSet->ToSetLineWidth = 1;
1663 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1665 else if (anArg == "-unsetwidth"
1666 || anArg == "-unsetlinewidth")
1668 aChangeSet->ToSetLineWidth = -1;
1669 aChangeSet->LineWidth = 1.0;
1671 else if (anArg == "-settransp"
1672 || anArg == "-settransparency")
1674 if (++anArgIter >= theArgNb)
1676 std::cout << "Error: wrong syntax at " << anArg << "\n";
1679 aChangeSet->ToSetTransparency = 1;
1680 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1681 if (aChangeSet->Transparency >= 0.0
1682 && aChangeSet->Transparency <= Precision::Confusion())
1684 aChangeSet->ToSetTransparency = -1;
1685 aChangeSet->Transparency = 0.0;
1688 else if (anArg == "-setvis"
1689 || anArg == "-setvisibility")
1691 if (++anArgIter >= theArgNb)
1693 std::cout << "Error: wrong syntax at " << anArg << "\n";
1697 aChangeSet->ToSetVisibility = 1;
1698 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1700 else if (anArg == "-setalpha")
1702 if (++anArgIter >= theArgNb)
1704 std::cout << "Error: wrong syntax at " << anArg << "\n";
1707 aChangeSet->ToSetTransparency = 1;
1708 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1709 if (aChangeSet->Transparency < 0.0
1710 || aChangeSet->Transparency > 1.0)
1712 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1715 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1716 if (aChangeSet->Transparency >= 0.0
1717 && aChangeSet->Transparency <= Precision::Confusion())
1719 aChangeSet->ToSetTransparency = -1;
1720 aChangeSet->Transparency = 0.0;
1723 else if (anArg == "-unsettransp"
1724 || anArg == "-unsettransparency"
1725 || anArg == "-unsetalpha"
1726 || anArg == "-opaque")
1728 aChangeSet->ToSetTransparency = -1;
1729 aChangeSet->Transparency = 0.0;
1731 else if (anArg == "-setcolor")
1733 Standard_Integer aNbComps = 0;
1734 Standard_Integer aCompIter = anArgIter + 1;
1735 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1737 if (theArgVec[aCompIter][0] == '-')
1746 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1747 Standard_CString aName = theArgVec[anArgIter + 1];
1748 if (!Quantity_Color::ColorFromName (aName, aColor))
1750 std::cout << "Error: unknown color name '" << aName << "'\n";
1753 aChangeSet->Color = aColor;
1758 Graphic3d_Vec3d anRgb;
1759 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1760 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1761 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1762 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1763 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1764 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1766 std::cout << "Error: RGB color values should be within range 0..1!\n";
1769 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1774 std::cout << "Error: wrong syntax at " << anArg << "\n";
1778 aChangeSet->ToSetColor = 1;
1779 anArgIter += aNbComps;
1781 else if (anArg == "-unsetcolor")
1783 aChangeSet->ToSetColor = -1;
1784 aChangeSet->Color = DEFAULT_COLOR;
1786 else if (anArg == "-setmat"
1787 || anArg == "-setmaterial")
1789 if (++anArgIter >= theArgNb)
1791 std::cout << "Error: wrong syntax at " << anArg << "\n";
1794 aChangeSet->ToSetMaterial = 1;
1795 aChangeSet->MatName = theArgVec[anArgIter];
1796 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1798 else if (anArg == "-unsetmat"
1799 || anArg == "-unsetmaterial")
1801 aChangeSet->ToSetMaterial = -1;
1802 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1804 else if (anArg == "-subshape"
1805 || anArg == "-subshapes")
1809 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1813 if (aNames.IsEmpty())
1815 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1819 aChanges.Append (ViewerTest_AspectsChangeSet());
1820 aChangeSet = &aChanges.ChangeLast();
1822 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1824 Standard_CString aSubShapeName = theArgVec[anArgIter];
1825 if (*aSubShapeName == '-')
1831 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1832 if (aSubShape.IsNull())
1834 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1837 aChangeSet->SubShapes.Append (aSubShape);
1840 if (aChangeSet->SubShapes.IsEmpty())
1842 std::cerr << "Error: empty list is specified after -subshapes!\n";
1846 else if (anArg == "-freeboundary"
1849 if (++anArgIter >= theArgNb)
1851 std::cout << "Error: wrong syntax at " << anArg << "\n";
1854 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1859 aChangeSet->ToSetShowFreeBoundary = 1;
1861 else if (aValue == "off"
1864 aChangeSet->ToSetShowFreeBoundary = -1;
1868 std::cout << "Error: wrong syntax at " << anArg << "\n";
1872 else if (anArg == "-setfreeboundarywidth"
1873 || anArg == "-setfbwidth")
1875 if (++anArgIter >= theArgNb)
1877 std::cout << "Error: wrong syntax at " << anArg << "\n";
1880 aChangeSet->ToSetFreeBoundaryWidth = 1;
1881 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1883 else if (anArg == "-unsetfreeboundarywidth"
1884 || anArg == "-unsetfbwidth")
1886 aChangeSet->ToSetFreeBoundaryWidth = -1;
1887 aChangeSet->FreeBoundaryWidth = 1.0;
1889 else if (anArg == "-setfreeboundarycolor"
1890 || anArg == "-setfbcolor")
1892 Standard_Integer aNbComps = 0;
1893 Standard_Integer aCompIter = anArgIter + 1;
1894 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1896 if (theArgVec[aCompIter][0] == '-')
1905 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1906 Standard_CString aName = theArgVec[anArgIter + 1];
1907 if (!Quantity_Color::ColorFromName (aName, aColor))
1909 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1912 aChangeSet->FreeBoundaryColor = aColor;
1917 Graphic3d_Vec3d anRgb;
1918 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1919 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1920 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1921 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1922 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1923 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1925 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1928 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1933 std::cout << "Error: wrong syntax at " << anArg << "\n";
1937 aChangeSet->ToSetFreeBoundaryColor = 1;
1938 anArgIter += aNbComps;
1940 else if (anArg == "-unsetfreeboundarycolor"
1941 || anArg == "-unsetfbcolor")
1943 aChangeSet->ToSetFreeBoundaryColor = -1;
1944 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1946 else if (anArg == "-unset")
1948 aChangeSet->ToSetVisibility = 1;
1949 aChangeSet->Visibility = 1;
1950 aChangeSet->ToSetLineWidth = -1;
1951 aChangeSet->LineWidth = 1.0;
1952 aChangeSet->ToSetTransparency = -1;
1953 aChangeSet->Transparency = 0.0;
1954 aChangeSet->ToSetColor = -1;
1955 aChangeSet->Color = DEFAULT_COLOR;
1956 aChangeSet->ToSetMaterial = -1;
1957 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1958 aChangeSet->ToSetShowFreeBoundary = -1;
1959 aChangeSet->ToSetFreeBoundaryColor = -1;
1960 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1961 aChangeSet->ToSetFreeBoundaryWidth = -1;
1962 aChangeSet->FreeBoundaryWidth = 1.0;
1966 std::cout << "Error: wrong syntax at " << anArg << "\n";
1971 Standard_Boolean isFirst = Standard_True;
1972 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1973 aChangesIter.More(); aChangesIter.Next())
1975 if (!aChangesIter.Value().Validate (!isFirst))
1979 isFirst = Standard_False;
1982 if (aCtx->HasOpenedContext())
1984 aCtx->CloseLocalContext();
1987 // special case for -defaults parameter.
1988 // all changed values will be set to DefaultDrawer.
1991 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
1993 if (aChangeSet->ToSetLineWidth != 0)
1995 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
1996 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
1997 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
1998 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2000 if (aChangeSet->ToSetColor != 0)
2002 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2003 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2004 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2005 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2006 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2007 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2009 if (aChangeSet->ToSetTransparency != 0)
2011 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2013 if (aChangeSet->ToSetMaterial != 0)
2015 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2017 if (aChangeSet->ToSetShowFreeBoundary == 1)
2019 aDrawer->SetFreeBoundaryDraw (Standard_True);
2021 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2023 aDrawer->SetFreeBoundaryDraw (Standard_False);
2025 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2027 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2029 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2031 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2034 // redisplay all objects in context
2035 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2037 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2040 aCtx->Redisplay (aPrs, Standard_False);
2046 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2048 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2049 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2050 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2051 Handle(AIS_ColoredShape) aColoredPrs;
2052 Standard_Boolean toDisplay = Standard_False;
2053 Standard_Boolean toRedisplay = Standard_False;
2054 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2056 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2057 if (aShapePrs.IsNull())
2059 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2062 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2063 if (aColoredPrs.IsNull())
2065 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2066 aCtx->Remove (aShapePrs, Standard_False);
2067 GetMapOfAIS().UnBind2 (aName);
2068 GetMapOfAIS().Bind (aColoredPrs, aName);
2069 toDisplay = Standard_True;
2070 aShapePrs = aColoredPrs;
2077 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2078 aChangeSet = &aChangesIter.ChangeValue();
2079 if (aChangeSet->ToSetVisibility == 1)
2081 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2082 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2084 else if (aChangeSet->ToSetMaterial == 1)
2086 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2088 else if (aChangeSet->ToSetMaterial == -1)
2090 aCtx->UnsetMaterial (aPrs, Standard_False);
2092 if (aChangeSet->ToSetColor == 1)
2094 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2096 else if (aChangeSet->ToSetColor == -1)
2098 aCtx->UnsetColor (aPrs, Standard_False);
2100 if (aChangeSet->ToSetTransparency == 1)
2102 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2104 else if (aChangeSet->ToSetTransparency == -1)
2106 aCtx->UnsetTransparency (aPrs, Standard_False);
2108 if (aChangeSet->ToSetLineWidth == 1)
2110 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2112 else if (aChangeSet->ToSetLineWidth == -1)
2114 aCtx->UnsetWidth (aPrs, Standard_False);
2116 if (!aDrawer.IsNull())
2118 if (aChangeSet->ToSetShowFreeBoundary == 1)
2120 aDrawer->SetFreeBoundaryDraw (Standard_True);
2121 toRedisplay = Standard_True;
2123 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2125 aDrawer->SetFreeBoundaryDraw (Standard_False);
2126 toRedisplay = Standard_True;
2128 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2130 Handle(Prs3d_LineAspect) aBoundaryAspect =
2131 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2132 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2133 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2134 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2135 toRedisplay = Standard_True;
2137 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2139 Handle(Prs3d_LineAspect) aBoundaryAspect =
2140 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2141 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2142 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2143 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2144 toRedisplay = Standard_True;
2148 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2150 aChangeSet = &aChangesIter.ChangeValue();
2151 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2152 aSubShapeIter.More(); aSubShapeIter.Next())
2154 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2155 if (aChangeSet->ToSetVisibility == 1)
2157 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2158 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2160 if (aChangeSet->ToSetColor == 1)
2162 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2164 if (aChangeSet->ToSetLineWidth == 1)
2166 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2168 if (aChangeSet->ToSetColor == -1
2169 || aChangeSet->ToSetLineWidth == -1)
2171 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2177 aCtx->Display (aPrs, Standard_False);
2181 aCtx->Redisplay (aPrs, Standard_False);
2183 else if (!aColoredPrs.IsNull())
2185 aCtx->Redisplay (aColoredPrs, Standard_False);
2190 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
2191 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
2192 if (!aNisObj.IsNull())
2194 if (aChangeSet->ToSetTransparency != 0)
2196 aNisObj->SetTransparency (aChangeSet->Transparency);
2199 if (!aNisTri.IsNull())
2201 if (aChangeSet->ToSetColor != 0)
2203 aNisTri->SetColor (aChangeSet->Color);
2205 if (aChangeSet->ToSetLineWidth != 0)
2207 aNisTri->SetLineWidth (aChangeSet->LineWidth);
2215 //==============================================================================
2216 //function : VDonly2
2218 //purpose : Display only a selected or named object
2219 // if there is no selected or named object s, nothing is done
2220 //==============================================================================
2221 static int VDonly2 (Draw_Interpretor& ,
2222 Standard_Integer theArgNb,
2223 const char** theArgVec)
2225 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2226 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2229 std::cerr << "Error: no active view!\n";
2233 if (aCtx->HasOpenedContext())
2235 aCtx->CloseLocalContext();
2238 Standard_Integer anArgIter = 1;
2239 for (; anArgIter < theArgNb; ++anArgIter)
2241 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2247 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2248 if (anArgIter >= theArgNb)
2250 // display only selected objects
2251 if (aCtx->NbCurrents() < 1)
2256 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2258 aDispSet.Add (aCtx->Current());
2263 // display only specified objects
2264 for (; anArgIter < theArgNb; ++anArgIter)
2266 TCollection_AsciiString aName = theArgVec[anArgIter];
2267 if (GetMapOfAIS().IsBound2 (aName))
2269 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2270 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2272 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2273 aCtx->Display (aShape, Standard_False);
2275 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2277 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2278 TheNISContext()->Display (aShape);
2280 aDispSet.Add (anObj);
2285 // weed out other objects
2286 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2288 if (aDispSet.Contains (anIter.Key1()))
2293 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2295 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2296 aCtx->Erase (aShape, Standard_False);
2298 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2300 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2301 TheNISContext()->Erase (aShape);
2307 //==============================================================================
2308 //function : VRemove
2309 //purpose : Removes selected or named objects.
2310 // If there is no selected or named objects,
2311 // all objects in the viewer can be removed with argument -all.
2312 // If -context is in arguments, the object is not deleted from the map of
2313 // objects (deleted only from the current context).
2314 //==============================================================================
2315 int VRemove (Draw_Interpretor& theDI,
2316 Standard_Integer theArgNb,
2317 const char** theArgVec)
2319 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2320 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2323 std::cerr << "Error: no active view!\n";
2327 Standard_Boolean isContextOnly = Standard_False;
2328 Standard_Boolean toRemoveAll = Standard_False;
2329 Standard_Boolean toPrintInfo = Standard_True;
2330 Standard_Boolean toRemoveLocal = Standard_False;
2332 Standard_Integer anArgIter = 1;
2333 for (; anArgIter < theArgNb; ++anArgIter)
2335 TCollection_AsciiString anArg = theArgVec[anArgIter];
2337 if (anArg == "-context")
2339 isContextOnly = Standard_True;
2341 else if (anArg == "-all")
2343 toRemoveAll = Standard_True;
2345 else if (anArg == "-noinfo")
2347 toPrintInfo = Standard_False;
2349 else if (anArg == "-local")
2351 toRemoveLocal = Standard_True;
2353 else if (anUpdateTool.parseRedrawMode (anArg))
2363 && anArgIter < theArgNb)
2365 std::cerr << "Error: wrong syntax!\n";
2369 if (toRemoveLocal && !aCtx->HasOpenedContext())
2371 std::cerr << "Error: local selection context is not open.\n";
2374 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2376 aCtx->CloseAllContexts (Standard_False);
2379 NCollection_List<TCollection_AsciiString> anIONameList;
2382 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2383 anIter.More(); anIter.Next())
2385 anIONameList.Append (anIter.Key2());
2388 else if (anArgIter < theArgNb) // removed objects names are in argument list
2390 for (; anArgIter < theArgNb; ++anArgIter)
2392 TCollection_AsciiString aName = theArgVec[anArgIter];
2393 if (!GetMapOfAIS().IsBound2 (aName))
2395 theDI << aName.ToCString() << " was not bound to some object.\n";
2399 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2401 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2404 if (anIO->GetContext() != aCtx)
2406 theDI << aName.ToCString() << " was not displayed in current context.\n";
2407 theDI << "Please activate view with this object displayed and try again.\n";
2411 anIONameList.Append (aName);
2415 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2416 if (!aNisIO.IsNull())
2418 anIONameList.Append (aName);
2422 else if (aCtx->NbCurrents() > 0
2423 || TheNISContext()->GetSelected().Extent() > 0)
2425 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2426 anIter.More(); anIter.Next())
2428 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2431 if (!aCtx->IsCurrent (anIO))
2436 anIONameList.Append (anIter.Key2());
2440 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2441 if (!aNisIO.IsNull())
2443 if (!TheNISContext()->IsSelected (aNisIO))
2448 anIONameList.Append (anIter.Key2());
2453 // Unbind all removed objects from the map of displayed IO.
2454 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2455 anIter.More(); anIter.Next())
2457 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2460 aCtx->Remove (anIO, Standard_False);
2463 theDI << anIter.Value().ToCString() << " was removed\n";
2468 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2469 if (!aNisIO.IsNull())
2471 TheNISContext()->Remove (aNisIO);
2474 theDI << anIter.Value().ToCString() << " was removed\n";
2480 GetMapOfAIS().UnBind2 (anIter.Value());
2484 // Close local context if it is empty
2485 TColStd_MapOfTransient aLocalIO;
2486 if (aCtx->HasOpenedContext()
2487 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2489 aCtx->CloseAllContexts (Standard_False);
2495 //==============================================================================
2497 //purpose : Erase some selected or named objects
2498 // if there is no selected or named objects, the whole viewer is erased
2499 //==============================================================================
2500 int VErase (Draw_Interpretor& theDI,
2501 Standard_Integer theArgNb,
2502 const char** theArgVec)
2504 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2505 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2506 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2509 std::cerr << "Error: no active view!\n";
2513 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2515 Standard_Integer anArgIter = 1;
2516 Standard_Boolean toEraseLocal = Standard_False;
2517 Standard_Boolean toEraseInView = Standard_False;
2518 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2519 for (; anArgIter < theArgNb; ++anArgIter)
2521 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2522 anArgCase.LowerCase();
2523 if (anUpdateTool.parseRedrawMode (anArgCase))
2527 else if (anArgCase == "-local")
2529 toEraseLocal = Standard_True;
2531 else if (anArgCase == "-view"
2532 || anArgCase == "-inview")
2534 toEraseInView = Standard_True;
2538 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2542 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2544 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2548 if (toEraseLocal && !aCtx->HasOpenedContext())
2550 std::cerr << "Error: local selection context is not open.\n";
2553 else if (!toEraseLocal && aCtx->HasOpenedContext())
2555 aCtx->CloseAllContexts (Standard_False);
2558 if (!aNamesOfEraseIO.IsEmpty())
2560 // Erase named objects
2561 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2563 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2564 if (!GetMapOfAIS().IsBound2 (aName))
2569 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2570 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2571 theDI << aName.ToCString() << " ";
2576 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2580 aCtx->Erase (anIO, Standard_False);
2585 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2586 if (!aNisIO.IsNull())
2588 TheNISContext()->Erase (aNisIO);
2593 else if (!toEraseAll && aCtx->NbCurrents() > 0)
2595 // Erase selected objects
2596 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2597 anIter.More(); anIter.Next())
2599 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2601 && aCtx->IsCurrent (anIO))
2603 theDI << anIter.Key2().ToCString() << " ";
2606 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2610 aCtx->Erase (anIO, Standard_False);
2617 // Erase all objects
2618 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2619 anIter.More(); anIter.Next())
2621 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2626 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2630 aCtx->Erase (anIO, Standard_False);
2635 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2636 if (!aNisIO.IsNull())
2638 TheNISContext()->Erase (aNisIO);
2647 //==============================================================================
2648 //function : VDisplayAll
2650 //purpose : Display all the objects of the Map
2651 //==============================================================================
2652 static int VDisplayAll (Draw_Interpretor& ,
2653 Standard_Integer theArgNb,
2654 const char** theArgVec)
2657 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2658 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2661 std::cerr << "Error: no active view!\n";
2665 Standard_Integer anArgIter = 1;
2666 Standard_Boolean toDisplayLocal = Standard_False;
2667 for (; anArgIter < theArgNb; ++anArgIter)
2669 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2670 anArgCase.LowerCase();
2671 if (anArgCase == "-local")
2673 toDisplayLocal = Standard_True;
2675 else if (anUpdateTool.parseRedrawMode (anArgCase))
2684 if (anArgIter < theArgNb)
2686 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2690 if (toDisplayLocal && !aCtx->HasOpenedContext())
2692 std::cerr << "Error: local selection context is not open.\n";
2695 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2697 aCtx->CloseLocalContext (Standard_False);
2700 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2701 anIter.More(); anIter.Next())
2703 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2705 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2706 aCtx->Erase (aShape, Standard_False);
2708 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2710 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2711 TheNISContext()->Erase (aShape);
2715 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2716 anIter.More(); anIter.Next())
2718 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2720 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2721 aCtx->Display (aShape, Standard_False);
2723 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2725 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2726 TheNISContext()->Display (aShape);
2732 //! Auxiliary method to find presentation
2733 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2734 const Handle(AIS_InteractiveObject)& theIO,
2735 const Standard_Integer theMode)
2739 return Handle(PrsMgr_Presentation)();
2744 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2746 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2749 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2751 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2753 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2755 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2757 return Handle(PrsMgr_Presentation)();
2760 enum ViewerTest_BndAction
2767 //! Auxiliary method to print bounding box of presentation
2768 inline void bndPresentation (Draw_Interpretor& theDI,
2769 const Handle(PrsMgr_Presentation)& thePrs,
2770 const TCollection_AsciiString& theName,
2771 const ViewerTest_BndAction theAction)
2775 case BndAction_Hide:
2777 thePrs->Presentation()->GraphicUnHighlight();
2780 case BndAction_Show:
2782 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2783 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2784 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2785 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2786 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2789 case BndAction_Print:
2791 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2792 gp_Pnt aMin = aBox.CornerMin();
2793 gp_Pnt aMax = aBox.CornerMax();
2794 theDI << theName << "\n"
2795 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2796 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2802 //==============================================================================
2803 //function : VBounding
2805 //==============================================================================
2806 int VBounding (Draw_Interpretor& theDI,
2807 Standard_Integer theArgNb,
2808 const char** theArgVec)
2810 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2811 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2814 std::cout << "Error: no active view!\n";
2818 ViewerTest_BndAction anAction = BndAction_Show;
2819 Standard_Integer aMode = -1;
2821 Standard_Integer anArgIter = 1;
2822 for (; anArgIter < theArgNb; ++anArgIter)
2824 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2826 if (anArg == "-print")
2828 anAction = BndAction_Print;
2830 else if (anArg == "-show")
2832 anAction = BndAction_Show;
2834 else if (anArg == "-hide")
2836 anAction = BndAction_Hide;
2838 else if (anArg == "-mode")
2840 if (++anArgIter >= theArgNb)
2842 std::cout << "Error: wrong syntax at " << anArg << "\n";
2845 aMode = Draw::Atoi (theArgVec[anArgIter]);
2847 else if (!anUpdateTool.parseRedrawMode (anArg))
2853 if (anArgIter < theArgNb)
2855 // has a list of names
2856 for (; anArgIter < theArgNb; ++anArgIter)
2858 TCollection_AsciiString aName = theArgVec[anArgIter];
2859 if (!GetMapOfAIS().IsBound2 (aName))
2861 std::cout << "Error: presentation " << aName << " does not exist\n";
2865 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2866 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2869 std::cout << "Error: presentation " << aName << " does not exist\n";
2872 bndPresentation (theDI, aPrs, aName, anAction);
2875 else if (aCtx->NbCurrents() > 0)
2877 // remove all currently selected objects
2878 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2880 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2881 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2884 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2891 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2892 anIter.More(); anIter.Next())
2894 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2895 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2898 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2905 //==============================================================================
2906 //function : VTexture
2908 //==============================================================================
2909 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2911 TCollection_AsciiString aCommandName (theArgv[0]);
2913 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2914 if (aCommandName == "vtexture")
2918 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2919 std::cout << "Type help for more information.\n";
2923 // look for options of vtexture command
2924 TCollection_AsciiString aParseKey;
2925 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2927 TCollection_AsciiString anArg (theArgv [anArgIt]);
2930 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2933 aParseKey.Remove (1);
2934 aParseKey.UpperCase();
2935 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2939 if (aParseKey.IsEmpty())
2944 aMapOfArgs(aParseKey)->Append (anArg);
2947 else if (aCommandName == "vtexscale"
2948 || aCommandName == "vtexorigin"
2949 || aCommandName == "vtexrepeat")
2951 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2952 // equal to -scale, -origin, -repeat options of vtexture command
2953 if (theArgsNb < 2 || theArgsNb > 4)
2955 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2956 std::cout << "Type help for more information.\n";
2960 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2963 anArgs->Append ("OFF");
2965 else if (theArgsNb == 4)
2967 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2968 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2971 TCollection_AsciiString anArgKey;
2972 if (aCommandName == "vtexscale")
2976 else if (aCommandName == "vtexorigin")
2978 anArgKey = "ORIGIN";
2982 anArgKey = "REPEAT";
2985 aMapOfArgs.Bind (anArgKey, anArgs);
2987 else if (aCommandName == "vtexdefault")
2989 // scan for parameters of vtexdefault command
2990 // equal to -default option of vtexture command
2991 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2994 // Check arguments for validity
2995 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2996 for (; aMapIt.More(); aMapIt.Next())
2998 const TCollection_AsciiString& aKey = aMapIt.Key();
2999 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3001 // -scale, -origin, -repeat: one argument "off", or two real values
3002 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
3003 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3004 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
3009 // -modulate: single argument "on" / "off"
3010 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
3015 // -default: no arguments
3016 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3021 TCollection_AsciiString aLowerKey;
3024 aLowerKey.LowerCase();
3025 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3026 std::cout << "Type help for more information.\n";
3030 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3031 if (anAISContext.IsNull())
3033 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3037 Standard_Integer aPreviousMode = 0;
3039 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3041 TCollection_AsciiString aShapeName (theArgv[1]);
3042 Handle(AIS_InteractiveObject) anIO;
3044 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3045 if (aMapOfIO.IsBound2 (aShapeName))
3047 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3052 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3056 Handle(AIS_TexturedShape) aTexturedIO;
3057 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3059 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3060 aPreviousMode = aTexturedIO->DisplayMode();
3064 anAISContext->Remove (anIO, Standard_False);
3065 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3066 GetMapOfAIS().UnBind1 (anIO);
3067 GetMapOfAIS().UnBind2 (aShapeName);
3068 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3071 // -------------------------------------------
3072 // Turn texturing on/off - only for vtexture
3073 // -------------------------------------------
3075 if (aCommandName == "vtexture")
3077 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3079 if (aTextureArg.IsEmpty())
3081 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3082 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3084 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3085 if (aPreviousMode == 3)
3087 anAISContext->RecomputePrsOnly (aTexturedIO);
3090 anAISContext->Display (aTexturedIO, Standard_True);
3093 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3095 if (aTextureArg == "?")
3097 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3099 theDi << "\n Files in current directory : \n" << "\n";
3100 theDi.Eval ("glob -nocomplain *");
3102 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3103 aCmnd += aTextureFolder;
3106 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3107 theDi.Eval (aCmnd.ToCString());
3112 aTexturedIO->SetTextureFileName (aTextureArg);
3117 // ------------------------------------
3118 // Process other options and commands
3119 // ------------------------------------
3121 Handle(TColStd_HSequenceOfAsciiString) aValues;
3122 if (aMapOfArgs.Find ("DEFAULT", aValues))
3124 aTexturedIO->SetTextureRepeat (Standard_False);
3125 aTexturedIO->SetTextureOrigin (Standard_False);
3126 aTexturedIO->SetTextureScale (Standard_False);
3127 aTexturedIO->EnableTextureModulate();
3131 if (aMapOfArgs.Find ("SCALE", aValues))
3133 if (aValues->Value(1) != "OFF")
3135 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3139 aTexturedIO->SetTextureScale (Standard_False);
3143 if (aMapOfArgs.Find ("ORIGIN", aValues))
3145 if (aValues->Value(1) != "OFF")
3147 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3151 aTexturedIO->SetTextureOrigin (Standard_False);
3155 if (aMapOfArgs.Find ("REPEAT", aValues))
3157 if (aValues->Value(1) != "OFF")
3159 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3163 aTexturedIO->SetTextureRepeat (Standard_False);
3167 if (aMapOfArgs.Find ("MODULATE", aValues))
3169 if (aValues->Value(1) == "ON")
3171 aTexturedIO->EnableTextureModulate();
3175 aTexturedIO->DisableTextureModulate();
3180 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3182 anAISContext->RecomputePrsOnly (aTexturedIO);
3186 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3187 anAISContext->Display (aTexturedIO, Standard_True);
3188 anAISContext->Update (aTexturedIO,Standard_True);
3194 //==============================================================================
3195 //function : VDisplay2
3197 //purpose : Display an object from its name
3198 //==============================================================================
3199 static int VDisplay2 (Draw_Interpretor& theDI,
3200 Standard_Integer theArgNb,
3201 const char** theArgVec)
3205 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3209 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3212 ViewerTest::ViewerInit();
3213 aCtx = ViewerTest::GetAISContext();
3216 // Parse input arguments
3217 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3218 Standard_Integer isMutable = -1;
3219 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3220 Standard_Boolean toDisplayLocal = Standard_False;
3221 Standard_Boolean toReDisplay = Standard_False;
3222 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3223 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3224 Standard_Integer toDisplayInView = Standard_False;
3225 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3227 const TCollection_AsciiString aName = theArgVec[anArgIter];
3228 TCollection_AsciiString aNameCase = aName;
3229 aNameCase.LowerCase();
3230 if (anUpdateTool.parseRedrawMode (aName))
3234 else if (aNameCase == "-mutable")
3238 else if (aNameCase == "-neutral")
3240 aDispStatus = AIS_DS_Displayed;
3242 else if (aNameCase == "-immediate"
3243 || aNameCase == "-top")
3245 aZLayer = Graphic3d_ZLayerId_Top;
3247 else if (aNameCase == "-topmost")
3249 aZLayer = Graphic3d_ZLayerId_Topmost;
3251 else if (aNameCase == "-osd"
3252 || aNameCase == "-toposd")
3254 aZLayer = Graphic3d_ZLayerId_TopOSD;
3256 else if (aNameCase == "-layer")
3258 if (++anArgIter >= theArgNb)
3260 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3264 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3265 if (!aValue.IsIntegerValue())
3267 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3271 aZLayer = aValue.IntegerValue();
3273 else if (aNameCase == "-view"
3274 || aNameCase == "-inview")
3276 toDisplayInView = Standard_True;
3278 else if (aNameCase == "-local")
3280 aDispStatus = AIS_DS_Temporary;
3281 toDisplayLocal = Standard_True;
3283 else if (aNameCase == "-redisplay")
3285 toReDisplay = Standard_True;
3289 aNamesOfDisplayIO.Append (aName);
3293 if (aNamesOfDisplayIO.IsEmpty())
3295 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3299 // Prepare context for display
3300 if (toDisplayLocal && !aCtx->HasOpenedContext())
3302 aCtx->OpenLocalContext (Standard_False);
3304 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3306 aCtx->CloseAllContexts (Standard_False);
3309 // Display interactive objects
3310 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3312 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3314 if (!GetMapOfAIS().IsBound2 (aName))
3316 // create the AIS_Shape from a name
3317 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3318 if (!aShape.IsNull())
3320 if (isMutable != -1)
3322 aShape->SetMutable (isMutable == 1);
3324 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3326 aShape->SetZLayer (aZLayer);
3328 GetMapOfAIS().Bind (aShape, aName);
3330 Standard_Integer aDispMode = aShape->HasDisplayMode()
3331 ? aShape->DisplayMode()
3332 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3333 ? aCtx->DisplayMode()
3335 Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection()
3336 ? aShape->SelectionMode() : -1;
3338 aCtx->Display (aShape, aDispMode, aSelMode,
3339 Standard_False, aShape->AcceptShapeDecomposition(),
3341 if (toDisplayInView)
3343 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3345 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3347 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3353 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3354 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
3356 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
3357 if (isMutable != -1)
3359 aShape->SetMutable (isMutable == 1);
3361 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3363 aShape->SetZLayer (aZLayer);
3366 Standard_Integer aDispMode = aShape->HasDisplayMode()
3367 ? aShape->DisplayMode()
3368 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3369 ? aCtx->DisplayMode()
3371 Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection()
3372 ? aShape->SelectionMode() : -1;
3374 if (aShape->Type() == AIS_KOI_Datum)
3376 aCtx->Display (aShape, Standard_False);
3380 theDI << "Display " << aName.ToCString() << "\n";
3382 // update the Shape in the AIS_Shape
3383 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3384 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3385 if (!aShapePrs.IsNull())
3387 if (!aShapePrs->Shape().IsEqual (aNewShape))
3389 toReDisplay = Standard_True;
3391 aShapePrs->Set (aNewShape);
3395 aCtx->Redisplay (aShape, Standard_False);
3398 aCtx->Display (aShape, aDispMode, aSelMode,
3399 Standard_False, aShape->AcceptShapeDecomposition(),
3401 if (toDisplayInView)
3403 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3407 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
3409 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
3410 TheNISContext()->Display (aShape);
3417 //===============================================================================================
3418 //function : VUpdate
3420 //===============================================================================================
3421 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3423 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3424 if (aContextAIS.IsNull())
3426 std::cout << theArgVec[0] << "AIS context is not available.\n";
3432 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3436 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3438 AIS_ListOfInteractive aListOfIO;
3440 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3442 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3444 Handle(AIS_InteractiveObject) anAISObj;
3445 if (anAISMap.IsBound2 (aName))
3447 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3450 if (anAISObj.IsNull())
3452 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3456 aListOfIO.Append (anAISObj);
3459 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3460 for (; anIOIt.More(); anIOIt.Next())
3462 aContextAIS->Update (anIOIt.Value(), Standard_False);
3465 aContextAIS->UpdateCurrentViewer();
3470 //==============================================================================
3472 //purpose : Test the annimation of an object along a
3473 // predifined trajectory
3474 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3475 //==============================================================================
3477 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3480 if (TheAISContext()->HasOpenedContext())
3481 TheAISContext()->CloseLocalContext();
3483 Standard_Real Step=4*M_PI/180;
3484 Standard_Real Angle=0;
3486 Handle(AIS_InteractiveObject) aIO;
3487 if (GetMapOfAIS().IsBound2(argv[1]))
3488 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3492 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3496 if (Draw::Atoi(argv[3])==1 ) {
3497 di<<" Primitives sensibles OFF"<<"\n";
3498 TheAISContext()->Deactivate(aIO);
3501 di<<" Primitives sensibles ON"<<"\n";
3503 // Movement par transformation
3504 if(Draw::Atoi(argv[2]) ==1) {
3505 di<<" Calcul par Transformation"<<"\n";
3506 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3510 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3511 TheAISContext()->SetLocation(aShape,myTransfo);
3512 TheAISContext() ->UpdateCurrentViewer();
3517 di<<" Calcul par Locations"<<"\n";
3518 gp_Trsf myAngleTrsf;
3519 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3520 TopLoc_Location myDeltaAngle (myAngleTrsf);
3521 TopLoc_Location myTrueLoc;
3523 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3526 myTrueLoc=myTrueLoc*myDeltaAngle;
3527 TheAISContext()->SetLocation(aShape,myTrueLoc );
3528 TheAISContext() ->UpdateCurrentViewer();
3531 if (Draw::Atoi(argv[3])==1 ){
3532 // On reactive la selection des primitives sensibles
3533 TheAISContext()->Activate(aIO,0);
3535 a3DView() -> Redraw();
3537 di<<" Temps ecoule "<<"\n";
3543 //==================================================================================
3544 // Function : VAnimation
3545 //==================================================================================
3546 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3548 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3552 Standard_Real thread = 4;
3553 Standard_Real angleA=0;
3554 Standard_Real angleB;
3556 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3559 TopoDS_Shape CrankArm;
3560 TopoDS_Shape CylinderHead;
3561 TopoDS_Shape Propeller;
3562 TopoDS_Shape EngineBlock;
3564 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3565 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3566 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3567 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3568 BRepTools::Read(CrankArm,argv[1],B);
3569 BRepTools::Read(CylinderHead,argv[2],B);
3570 BRepTools::Read(Propeller,argv[3],B);
3571 BRepTools::Read(EngineBlock,argv[4],B);
3573 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3579 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3580 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3581 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3582 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3584 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3585 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3586 GetMapOfAIS().Bind(myAisCrankArm,"c");
3587 GetMapOfAIS().Bind(myAisPropeller,"d");
3589 myAisCylinderHead->SetMutable (Standard_True);
3590 myAisEngineBlock ->SetMutable (Standard_True);
3591 myAisCrankArm ->SetMutable (Standard_True);
3592 myAisPropeller ->SetMutable (Standard_True);
3594 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3595 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3596 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3598 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3599 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3600 TheAISContext()->Display (myAisCrankArm, Standard_False);
3601 TheAISContext()->Display (myAisPropeller, Standard_False);
3603 TheAISContext()->Deactivate(myAisCylinderHead);
3604 TheAISContext()->Deactivate(myAisEngineBlock );
3605 TheAISContext()->Deactivate(myAisCrankArm );
3606 TheAISContext()->Deactivate(myAisPropeller );
3608 // Boucle de mouvement
3609 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3611 angleA = thread*myAngle*M_PI/180;
3612 X = Sin(angleA)*3/8;
3613 angleB = atan(X / Sqrt(-X * X + 1));
3614 Standard_Real decal(25*0.6);
3617 //Build a transformation on the display
3618 gp_Trsf aPropellerTrsf;
3619 aPropellerTrsf.SetRotation(Ax1,angleA);
3620 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3622 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));
3623 gp_Trsf aCrankArmTrsf;
3624 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3625 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3627 TheAISContext()->UpdateCurrentViewer();
3630 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3631 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3633 myAisCrankArm ->ResetTransformation();
3634 myAisPropeller->ResetTransformation();
3636 myAisCrankArm -> Set(myNewCrankArm );
3637 myAisPropeller -> Set(myNewPropeller);
3639 TheAISContext()->Activate(myAisCylinderHead,0);
3640 TheAISContext()->Activate(myAisEngineBlock,0 );
3641 TheAISContext()->Activate(myAisCrankArm ,0 );
3642 TheAISContext()->Activate(myAisPropeller ,0 );
3648 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3649 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3651 TheAISContext()->UpdateCurrentViewer();
3652 a3DView()->Redraw();
3661 //==============================================================================
3662 //function : VShading
3663 //purpose : Sharpen or roughten the quality of the shading
3664 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3665 //==============================================================================
3666 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3668 Standard_Real myDevCoef;
3669 Handle(AIS_InteractiveObject) TheAisIO;
3672 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3674 if (TheAISContext()->HasOpenedContext())
3675 TheAISContext()->CloseLocalContext();
3680 myDevCoef =Draw::Atof(argv[2]);
3683 TCollection_AsciiString name=argv[1];
3684 if (GetMapOfAIS().IsBound2(name ))
3685 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3686 if (TheAisIO.IsNull())
3687 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3690 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3692 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3694 TheAISContext()->Redisplay(TheAisIO);
3697 //==============================================================================
3698 //function : HaveMode
3699 //use : VActivatedModes
3700 //==============================================================================
3701 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3703 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3705 TColStd_ListOfInteger List;
3706 TheAISContext()->ActivatedModes (TheAisIO,List);
3707 TColStd_ListIteratorOfListOfInteger it;
3708 Standard_Boolean Found=Standard_False;
3709 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3710 if (it.Value()==mode ) Found=Standard_True;
3717 //==============================================================================
3718 //function : VActivatedMode
3720 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3721 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3722 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3723 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3724 // qu'un nom et qu'un mode.
3725 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3726 //==============================================================================
3727 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3729 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3732 Standard_Boolean ThereIsName = Standard_False ;
3734 if(!a3DView().IsNull()){
3736 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3737 // verification des arguments
3739 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3740 ThereIsName = (argc == 3);
3744 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3746 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3747 di<<" Fermeture du Context local"<<"\n";
3748 if (TheAISContext()->HasOpenedContext())
3749 TheAISContext()->CloseLocalContext();
3753 // IL n'y a aps de nom de shape passe en argument
3754 if (HaveToSet && !ThereIsName){
3755 Standard_Integer aMode=Draw::Atoi(argv [1]);
3757 const char *cmode="???";
3759 case 0: cmode = "Shape"; break;
3760 case 1: cmode = "Vertex"; break;
3761 case 2: cmode = "Edge"; break;
3762 case 3: cmode = "Wire"; break;
3763 case 4: cmode = "Face"; break;
3764 case 5: cmode = "Shell"; break;
3765 case 6: cmode = "Solid"; break;
3766 case 7: cmode = "Compound"; break;
3769 if( !TheAISContext()->HasOpenedContext() ) {
3770 // il n'y a pas de Context local d'ouvert
3771 // on en ouvre un et on charge toutes les shapes displayees
3772 // on load tous les objets displayees et on Activate les objets de la liste
3773 AIS_ListOfInteractive ListOfIO;
3774 // on sauve dans une AISListOfInteractive tous les objets currents
3775 if (TheAISContext()->NbCurrents()>0 ){
3776 TheAISContext()->UnhilightCurrents(Standard_False);
3778 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3779 ListOfIO.Append(TheAISContext()->Current() );
3783 TheAISContext()->OpenLocalContext(Standard_False);
3784 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3787 Handle(AIS_InteractiveObject) aIO =
3788 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3790 TheAISContext()->Load(aIO,0,Standard_False);
3793 // traitement des objets qui etaient currents dans le Contexte global
3794 if (!ListOfIO.IsEmpty() ) {
3795 // il y avait des objets currents
3796 AIS_ListIteratorOfListOfInteractive iter;
3797 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3798 Handle(AIS_InteractiveObject) aIO=iter.Value();
3799 TheAISContext()->Activate(aIO,aMode);
3800 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3804 // On applique le mode a tous les objets displayes
3805 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3806 it2 (GetMapOfAIS());
3808 Handle(AIS_InteractiveObject) aIO =
3809 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3810 if (!aIO.IsNull()) {
3811 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3812 TheAISContext()->Activate(aIO,aMode);
3821 // un Context local est deja ouvert
3822 // Traitement des objets du Context local
3823 if (TheAISContext()->NbSelected()>0 ){
3824 TheAISContext()->UnhilightSelected(Standard_False);
3825 // il y a des objets selected,on les parcourt
3826 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3827 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3830 if (HaveMode(aIO,aMode) ) {
3831 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3832 TheAISContext()->Deactivate(aIO,aMode);
3835 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3836 TheAISContext()->Activate(aIO,aMode);
3842 // il n'y a pas d'objets selected
3843 // tous les objets diplayes sont traites
3844 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3847 Handle(AIS_InteractiveObject) aIO =
3848 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3849 if (!aIO.IsNull()) {
3850 if (HaveMode(aIO,aMode) ) {
3851 di<<" Mode: "<<cmode<<" OFF pour "
3852 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3853 TheAISContext()->Deactivate(aIO,aMode);
3856 di<<" Mode: "<<cmode<<" ON pour"
3857 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3858 TheAISContext()->Activate(aIO,aMode);
3866 else if (HaveToSet && ThereIsName){
3867 Standard_Integer aMode=Draw::Atoi(argv [2]);
3868 Handle(AIS_InteractiveObject) aIO =
3869 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3871 if (!aIO.IsNull()) {
3872 const char *cmode="???";
3875 case 0: cmode = "Shape"; break;
3876 case 1: cmode = "Vertex"; break;
3877 case 2: cmode = "Edge"; break;
3878 case 3: cmode = "Wire"; break;
3879 case 4: cmode = "Face"; break;
3880 case 5: cmode = "Shell"; break;
3881 case 6: cmode = "Solid"; break;
3882 case 7: cmode = "Compound"; break;
3885 if( !TheAISContext()->HasOpenedContext() ) {
3886 TheAISContext()->OpenLocalContext(Standard_False);
3887 // On charge tous les objets de la map
3888 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3890 Handle(AIS_InteractiveObject) aShape=
3891 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3892 if (!aShape.IsNull())
3893 TheAISContext()->Load(aShape,0,Standard_False);
3896 TheAISContext()->Activate(aIO,aMode);
3897 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3901 // un Context local est deja ouvert
3902 if (HaveMode(aIO,aMode) ) {
3903 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3904 TheAISContext()->Deactivate(aIO,aMode);
3907 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3908 TheAISContext()->Activate(aIO,aMode);
3917 //! Auxiliary method to print Interactive Object information
3918 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3919 const Handle(Standard_Transient)& theObject,
3920 Draw_Interpretor& theDI)
3922 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3925 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3929 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3930 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3931 << (theDetected.Contains (anObj) ? " Detected" : " ")
3933 if (anObj->Type() == AIS_KOI_Datum)
3936 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3937 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3938 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3939 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3940 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3941 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3942 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3945 else if (anObj->Type() == AIS_KOI_Shape
3946 && anObj->Signature() == 0)
3948 theDI << " AIS_Shape";
3950 else if (anObj->Type() == AIS_KOI_Relation)
3952 // AIS_Dimention and AIS_Relation
3953 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3954 switch (aRelation->KindOfDimension())
3956 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3957 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3958 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3959 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3960 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3961 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3962 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3963 default: theDI << " UNKNOWN dimension"; break;
3968 theDI << " UserPrs";
3970 theDI << " (" << theObject->DynamicType()->Name() << ")";
3973 //! Print information about locally selected sub-shapes
3974 static void localCtxInfo (Draw_Interpretor& theDI)
3976 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3977 if (!aCtx->HasOpenedContext())
3982 TCollection_AsciiString aPrevName;
3983 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3984 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3986 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3987 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3988 if (aSubShape.IsNull()
3989 || aShapeIO.IsNull()
3990 || !GetMapOfAIS().IsBound1 (aShapeIO))
3995 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3996 TopTools_MapOfShape aFilter;
3997 Standard_Integer aNumber = 0;
3998 const TopoDS_Shape aShape = aShapeIO->Shape();
3999 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4000 anIter.More(); anIter.Next())
4002 if (!aFilter.Add (anIter.Current()))
4004 continue; // filter duplicates
4008 if (!anIter.Current().IsSame (aSubShape))
4013 Standard_CString aShapeName = NULL;
4014 switch (aSubShape.ShapeType())
4016 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4017 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4018 case TopAbs_SOLID: aShapeName = " Solid"; break;
4019 case TopAbs_SHELL: aShapeName = " Shell"; break;
4020 case TopAbs_FACE: aShapeName = " Face"; break;
4021 case TopAbs_WIRE: aShapeName = " Wire"; break;
4022 case TopAbs_EDGE: aShapeName = " Edge"; break;
4023 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4025 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4028 if (aParentName != aPrevName)
4030 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4031 aPrevName = aParentName;
4033 theDI << " " << aShapeName << " #" << aNumber << "\n";
4039 //==============================================================================
4042 //==============================================================================
4043 static Standard_Integer VState (Draw_Interpretor& theDI,
4044 Standard_Integer theArgNb,
4045 Standard_CString* theArgVec)
4047 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4050 std::cerr << "Error: No opened viewer!\n";
4054 Standard_Boolean toPrintEntities = Standard_False;
4055 Standard_Boolean toCheckSelected = Standard_False;
4057 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4059 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4060 anOption.LowerCase();
4061 if (anOption == "-detectedentities"
4062 || anOption == "-entities")
4064 toPrintEntities = Standard_True;
4066 else if (anOption == "-hasselected")
4068 toCheckSelected = Standard_True;
4072 if (toCheckSelected)
4074 aCtx->InitSelected();
4075 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4076 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4081 if (toPrintEntities)
4083 theDI << "Detected entities:\n";
4084 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4085 for (aSelector->Init(); aSelector->More(); aSelector->Next())
4087 Handle(SelectBasics_SensitiveEntity) anEntity = aSelector->Primitive (0);
4088 Standard_Real aMatchDMin = 0.0;
4089 Standard_Real aMatchDepth = Precision::Infinite();
4090 anEntity->Matches (aSelector->LastPickingArguments(), aMatchDMin, aMatchDepth);
4092 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4093 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4095 const gp_Lin aLine = aSelector->LastPickingArguments().PickLine();
4096 const gp_Pnt aPnt = aLine.Location().Translated (gp_Vec (aLine.Direction()) * aMatchDepth);
4098 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4099 aName.LeftJustify (20, ' ');
4100 char anInfoStr[512];
4101 Sprintf (anInfoStr, " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f", aMatchDepth, aMatchDMin, aPnt.X(), aPnt.Y(), aPnt.Z());
4102 theDI << " " << aName
4104 << " (" << anEntity->DynamicType()->Name() << ")"
4107 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4108 if (!aBRepOwner.IsNull())
4110 theDI << " Detected Shape: "
4111 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4115 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4116 if (!aWire.IsNull())
4118 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4119 theDI << " Detected Child: "
4120 << aSen->DynamicType()->Name()
4127 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4128 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4130 aDetected.Add (aCtx->DetectedCurrentObject());
4133 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4137 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4139 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4140 if (!GetMapOfAIS().IsBound2 (anObjName))
4142 theDI << anObjName << " doesn't exist!\n";
4146 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4147 TCollection_AsciiString aName = anObjName;
4148 aName.LeftJustify (20, ' ');
4149 theDI << " " << aName << " ";
4150 objInfo (aDetected, anObjTrans, theDI);
4156 if (aCtx->NbCurrents() > 0
4159 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
4161 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
4162 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4163 aName.LeftJustify (20, ' ');
4164 theDI << aName << " ";
4165 objInfo (aDetected, anObj, theDI);
4171 theDI << "Neutral-point state:\n";
4172 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4173 anObjIter.More(); anObjIter.Next())
4175 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4181 TCollection_AsciiString aName = anObjIter.Key2();
4182 aName.LeftJustify (20, ' ');
4183 theDI << " " << aName << " ";
4184 objInfo (aDetected, anObj, theDI);
4187 localCtxInfo (theDI);
4191 //=======================================================================
4192 //function : PickObjects
4194 //=======================================================================
4195 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4196 const AIS_KindOfInteractive TheType,
4197 const Standard_Integer TheSignature,
4198 const Standard_Integer MaxPick)
4200 Handle(AIS_InteractiveObject) IO;
4201 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4203 // step 1: prepare the data
4205 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4206 TheAISContext()->AddFilter(F1);
4209 // step 2 : wait for the selection...
4210 // Standard_Boolean IsGood (Standard_False);
4211 // Standard_Integer NbPick(0);
4212 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4213 Standard_Integer NbPickFail(0);
4214 Standard_Integer argccc = 5;
4215 const char *bufff[] = { "A", "B", "C","D", "E" };
4216 const char **argvvv = (const char **) bufff;
4219 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4220 while(ViewerMainLoop(argccc,argvvv)){}
4221 Standard_Integer NbStored = TheAISContext()->NbSelected();
4222 if((unsigned int ) NbStored != NbPickGood)
4223 NbPickGood= NbStored;
4226 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4229 // step3 get result.
4231 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4233 Standard_Integer i(0);
4234 for(TheAISContext()->InitSelected();
4235 TheAISContext()->MoreSelected();
4236 TheAISContext()->NextSelected()){
4238 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4239 arr->SetValue(i,IO2);
4244 TheAISContext()->CloseLocalContext(curindex);
4246 return Standard_True;
4250 //=======================================================================
4251 //function : PickObject
4253 //=======================================================================
4254 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4255 const Standard_Integer TheSignature,
4256 const Standard_Integer MaxPick)
4258 Handle(AIS_InteractiveObject) IO;
4259 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4261 // step 1: prepare the data
4264 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4265 TheAISContext()->AddFilter(F1);
4268 // step 2 : wait for the selection...
4269 Standard_Boolean IsGood (Standard_False);
4270 Standard_Integer NbPick(0);
4271 Standard_Integer argccc = 5;
4272 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4273 const char **argvvv = (const char **) bufff;
4276 while(!IsGood && NbPick<= MaxPick){
4277 while(ViewerMainLoop(argccc,argvvv)){}
4278 IsGood = (TheAISContext()->NbSelected()>0) ;
4280 cout<<"Nb Pick :"<<NbPick<<endl;
4284 // step3 get result.
4286 TheAISContext()->InitSelected();
4287 IO = TheAISContext()->SelectedInteractive();
4291 TheAISContext()->CloseLocalContext(curindex);
4295 //=======================================================================
4296 //function : PickShape
4297 //purpose : First Activate the rightmode + Put Filters to be able to
4298 // pick objets that are of type <TheType>...
4299 //=======================================================================
4301 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4302 const Standard_Integer MaxPick)
4305 // step 1: prepare the data
4307 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4308 TopoDS_Shape result;
4310 if(TheType==TopAbs_SHAPE){
4311 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4312 TheAISContext()->AddFilter(F1);
4315 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4316 TheAISContext()->AddFilter(TF);
4317 TheAISContext()->ActivateStandardMode(TheType);
4322 // step 2 : wait for the selection...
4323 Standard_Boolean NoShape (Standard_True);
4324 Standard_Integer NbPick(0);
4325 Standard_Integer argccc = 5;
4326 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4327 const char **argvvv = (const char **) bufff;
4330 while(NoShape && NbPick<= MaxPick){
4331 while(ViewerMainLoop(argccc,argvvv)){}
4332 NoShape = (TheAISContext()->NbSelected()==0) ;
4334 cout<<"Nb Pick :"<<NbPick<<endl;
4337 // step3 get result.
4341 TheAISContext()->InitSelected();
4342 if(TheAISContext()->HasSelectedShape())
4343 result = TheAISContext()->SelectedShape();
4345 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4346 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
4351 TheAISContext()->CloseLocalContext(curindex);
4357 //=======================================================================
4358 //function : PickShapes
4360 //=======================================================================
4361 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4362 Handle(TopTools_HArray1OfShape)& thearr,
4363 const Standard_Integer MaxPick)
4366 Standard_Integer Taille = thearr->Length();
4368 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4370 // step 1: prepare the data
4371 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4372 if(TheType==TopAbs_SHAPE){
4373 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4374 TheAISContext()->AddFilter(F1);
4377 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4378 TheAISContext()->AddFilter(TF);
4379 TheAISContext()->ActivateStandardMode(TheType);
4383 // step 2 : wait for the selection...
4385 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4386 Standard_Integer NbPickFail(0);
4387 Standard_Integer argccc = 5;
4388 const char *bufff[] = { "A", "B", "C","D", "E" };
4389 const char **argvvv = (const char **) bufff;
4392 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4393 while(ViewerMainLoop(argccc,argvvv)){}
4394 Standard_Integer NbStored = TheAISContext()->NbSelected();
4395 if((unsigned int ) NbStored != NbPickGood)
4396 NbPickGood= NbStored;
4399 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4402 // step3 get result.
4404 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4406 Standard_Integer i(0);
4407 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4409 if(TheAISContext()->HasSelectedShape())
4410 thearr->SetValue(i,TheAISContext()->SelectedShape());
4412 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4413 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
4417 TheAISContext()->CloseLocalContext(curindex);
4418 return Standard_True;
4422 //=======================================================================
4423 //function : VPickShape
4425 //=======================================================================
4426 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4428 TopoDS_Shape PickSh;
4429 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4432 theType = TopAbs_SHAPE;
4434 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4435 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4436 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4437 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4438 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4439 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4440 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4443 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4444 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4446 TCollection_AsciiString name;
4449 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4451 PickSh = ViewerTest::PickShape(theType);
4460 if(!PickSh.IsNull()){
4461 nbOfSub[Standard_Integer(theType)]++;
4463 name += nameType[Standard_Integer(theType)];
4464 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4469 // si on avait une petite methode pour voir si la shape
4470 // est deja dans la Double map, ca eviterait de creer....
4471 DBRep::Set(name.ToCString(),PickSh);
4473 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4474 GetMapOfAIS().Bind(newsh, name);
4475 TheAISContext()->Display(newsh);
4476 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4479 // Plusieurs objets a picker, vite vite vite....
4482 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4483 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4484 if(ViewerTest::PickShapes(theType,arr)){
4485 for(Standard_Integer i=1;i<=NbToPick;i++){
4486 PickSh = arr->Value(i);
4487 if(!PickSh.IsNull()){
4489 nbOfSub[Standard_Integer(theType)]++;
4492 name += nameType[Standard_Integer(theType)];
4493 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4501 DBRep::Set(name.ToCString(),PickSh);
4502 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4503 GetMapOfAIS().Bind(newsh, name);
4504 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4505 TheAISContext()->Display(newsh);
4513 //=======================================================================
4514 //function : VPickSelected
4516 //=======================================================================
4517 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4519 static Standard_Integer aCount = 0;
4520 TCollection_AsciiString aName = "PickedShape_";
4528 aName = aName + aCount++ + "_";
4531 Standard_Integer anIdx = 0;
4532 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4534 TopoDS_Shape aShape;
4535 if (TheAISContext()->HasSelectedShape())
4537 aShape = TheAISContext()->SelectedShape();
4541 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4542 aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
4545 TCollection_AsciiString aCurrentName = aName;
4548 aCurrentName += anIdx;
4551 DBRep::Set ((aCurrentName).ToCString(), aShape);
4553 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4554 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4555 TheAISContext()->Display (aNewShape);
4561 //=======================================================================
4562 //function : list of known objects
4564 //=======================================================================
4565 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4567 // 1234567890 12345678901234567 123456789
4568 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4569 TCollection_AsciiString BlankLine(64,'_');
4570 Standard_Integer i ;
4572 di<<"/n"<<BlankLine.ToCString()<<"\n";
4575 Colum[i].Center(20,' ');
4577 di<<"|"<<Colum[i].ToCString();
4580 di<<BlankLine.ToCString()<<"\n";
4582 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4583 const char ** names = GetTypeNames();
4585 TCollection_AsciiString curstring;
4586 TCollection_AsciiString curcolum[3];
4589 // les objets de type Datum..
4590 curcolum[1]+="Datum";
4592 curcolum[0].Clear();
4593 curcolum[0] += names[i];
4595 curcolum[2].Clear();
4596 curcolum[2]+=TCollection_AsciiString(i+1);
4598 for(Standard_Integer j =0;j<=2;j++){
4599 curcolum[j].Center(20,' ');
4600 di<<"|"<<curcolum[j].ToCString();
4604 di<<BlankLine.ToCString()<<"\n";
4606 // les objets de type shape
4607 curcolum[1].Clear();
4608 curcolum[1]+="Shape";
4609 curcolum[1].Center(20,' ');
4612 curcolum[0].Clear();
4613 curcolum[0] += names[7+i];
4614 curcolum[2].Clear();
4615 curcolum[2]+=TCollection_AsciiString(i);
4617 for(Standard_Integer j =0;j<=2;j++){
4618 curcolum[j].Center(20,' ');
4619 di<<"|"<<curcolum[j].ToCString();
4623 di<<BlankLine.ToCString()<<"\n";
4624 // les IO de type objet...
4625 curcolum[1].Clear();
4626 curcolum[1]+="Object";
4627 curcolum[1].Center(20,' ');
4629 curcolum[0].Clear();
4630 curcolum[0] += names[10+i];
4631 curcolum[2].Clear();
4632 curcolum[2]+=TCollection_AsciiString(i);
4634 for(Standard_Integer j =0;j<=2;j++){
4635 curcolum[j].Center(20,' ');
4636 di<<"|"<<curcolum[j].ToCString();
4640 di<<BlankLine.ToCString()<<"\n";
4641 // les contraintes et dimensions.
4642 // pour l'instant on separe juste contraintes et dimensions...
4643 // plus tard, on detaillera toutes les sortes...
4644 curcolum[1].Clear();
4645 curcolum[1]+="Relation";
4646 curcolum[1].Center(20,' ');
4648 curcolum[0].Clear();
4649 curcolum[0] += names[12+i];
4650 curcolum[2].Clear();
4651 curcolum[2]+=TCollection_AsciiString(i);
4653 for(Standard_Integer j =0;j<=2;j++){
4654 curcolum[j].Center(20,' ');
4655 di<<"|"<<curcolum[j].ToCString();
4659 di<<BlankLine.ToCString()<<"\n";
4666 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4668 if(argc!=2) return 1;
4670 AIS_KindOfInteractive TheType;
4671 Standard_Integer TheSign(-1);
4672 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4675 AIS_ListOfInteractive LIO;
4677 // en attendant l'amelioration ais pour les dimensions...
4679 Standard_Integer dimension_status(-1);
4680 if(TheType==AIS_KOI_Relation){
4681 dimension_status = TheSign ==1 ? 1 : 0;
4685 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4686 Handle(AIS_InteractiveObject) curio;
4687 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4690 if(dimension_status == -1)
4691 TheAISContext()->Erase(curio,Standard_False);
4693 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4694 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4695 (dimension_status==1 && KOD != AIS_KOD_NONE))
4696 TheAISContext()->Erase(curio,Standard_False);
4699 TheAISContext()->UpdateCurrentViewer();
4702 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4704 if(argc!=2) return 1;
4706 AIS_KindOfInteractive TheType;
4707 Standard_Integer TheSign(-1);
4708 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4710 // en attendant l'amelioration ais pour les dimensions...
4712 Standard_Integer dimension_status(-1);
4713 if(TheType==AIS_KOI_Relation){
4714 dimension_status = TheSign ==1 ? 1 : 0;
4718 AIS_ListOfInteractive LIO;
4719 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4720 Handle(AIS_InteractiveObject) curio;
4721 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4723 if(dimension_status == -1)
4724 TheAISContext()->Display(curio,Standard_False);
4726 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4727 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4728 (dimension_status==1 && KOD != AIS_KOD_NONE))
4729 TheAISContext()->Display(curio,Standard_False);
4734 TheAISContext()->UpdateCurrentViewer();
4738 //==============================================================================
4739 //function : VSetTransMode
4741 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4742 //==============================================================================
4744 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4745 // Verification des arguments
4746 if ( a3DView().IsNull() ) {
4747 ViewerTest::ViewerInit();
4748 di << "La commande vinit n'a pas ete appele avant" << "\n";
4751 if ( argc < 3 || argc > 8 ) {
4752 di << argv[0] << " Invalid number of arguments" << "\n";
4756 TCollection_AsciiString shapeName;
4757 shapeName = argv[1];
4758 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4759 Standard_Integer persFlag2 = 0;
4760 Standard_Integer persFlag3 = 0;
4761 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4762 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4763 persFlag2 = Draw::Atoi(argv[3]);
4765 if ( argc == 5 || argc == 8 ) {
4766 persFlag3 = Draw::Atoi(argv[4]);
4769 origin.SetX( Draw::Atof(argv[argc - 3]) );
4770 origin.SetY( Draw::Atof(argv[argc - 2]) );
4771 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4774 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4775 Handle(Standard_Transient) anObj;
4777 anObj = GetMapOfAIS().Find2(shapeName);
4778 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4779 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4780 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4781 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4782 di << argv[0] << " All persistence modifiers were removed" << "\n";
4785 di << argv[0] << " Wrong object type" << "\n";
4788 } else { // Create the AIS_Shape from a name
4789 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4790 if ( !aShape.IsNull() ) {
4791 GetMapOfAIS().Bind( aShape, shapeName );
4792 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4793 TheAISContext()->Display( aShape, Standard_False );
4795 di << argv[0] << " Object not found" << "\n";
4800 // Upadate the screen and redraw the view
4801 TheAISContext()->UpdateCurrentViewer();
4805 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4808 BRep_Builder builder;
4810 BRepTools::Read(shape, s, builder);
4811 DBRep::Set(a[1], shape);
4812 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4813 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4818 //==============================================================================
4819 //function : ViewerTest::Commands
4820 //purpose : Add all the viewer command in the Draw_Interpretor
4821 //==============================================================================
4823 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4825 ViewerTest::ViewerCommands(theCommands);
4826 ViewerTest::RelationCommands(theCommands);
4827 ViewerTest::ObjectCommands(theCommands);
4828 ViewerTest::FilletCommands(theCommands);
4829 ViewerTest::VoxelCommands(theCommands);
4830 ViewerTest::OpenGlCommands(theCommands);
4832 const char *group = "AIS_Display";
4835 theCommands.Add("visos",
4836 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4837 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4838 __FILE__, visos, group);
4840 theCommands.Add("vdisplay",
4841 "vdisplay [-noupdate|-update] [-local] [-mutable] name1 [name2] ... [name n]"
4842 "\n\t\t: Displays named objects."
4843 "\n\t\t: Option -local enables displaying of objects in local"
4844 "\n\t\t: selection context. Local selection context will be opened"
4845 "\n\t\t: if there is not any."
4846 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4847 "\n\t\t: Option -mutable enables optimizations for mutable objects.",
4848 __FILE__, VDisplay2, group);
4850 theCommands.Add ("vupdate",
4851 "vupdate name1 [name2] ... [name n]"
4852 "\n\t\t: Updates named objects in interactive context",
4853 __FILE__, VUpdate, group);
4855 theCommands.Add("verase",
4856 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
4857 "\n\t\t: Erases selected or named objects."
4858 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
4859 "\n\t\t: Option -local enables erasing of selected or named objects without"
4860 "\n\t\t: closing local selection context.",
4861 __FILE__, VErase, group);
4863 theCommands.Add("vremove",
4864 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4865 "or vremove [-context] -all to remove all objects"
4866 "\n\t\t: Removes selected or named objects."
4867 "\n\t\t If -context is in arguments, the objects are not deleted"
4868 "\n\t\t from the map of objects and names."
4869 "\n\t\t: Option -local enables removing of selected or named objects without"
4870 "\n\t\t: closing local selection context. Empty local selection context will be"
4872 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4873 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4874 __FILE__, VRemove, group);
4876 theCommands.Add("vdonly",
4877 "vdonly [-noupdate|-update] [name1] ... [name n]"
4878 "\n\t\t: Displays only selected or named objects",
4879 __FILE__,VDonly2,group);
4881 theCommands.Add("vdisplayall",
4882 "vidsplayall [-local]"
4883 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
4884 "\n\t\t: Option -local enables displaying of the objects in local"
4885 "\n\t\t: selection context.",
4886 __FILE__, VDisplayAll, group);
4888 theCommands.Add("veraseall",
4889 "veraseall [-local]"
4890 "\n\t\t: Erases all objects displayed in the viewer."
4891 "\n\t\t: Option -local enables erasing of the objects in local"
4892 "\n\t\t: selection context.",
4893 __FILE__, VErase, group);
4895 theCommands.Add("verasetype",
4897 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4898 __FILE__, VEraseType, group);
4899 theCommands.Add("vbounding",
4900 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4901 "\n\t\t: [-print] [-hide]"
4902 "\n\t\t: Temporarily display bounding box of specified Interactive"
4903 "\n\t\t: Objects, or print it to console if -print is specified."
4904 "\n\t\t: Already displayed box might be hidden by -hide option.",
4905 __FILE__,VBounding,group);
4907 theCommands.Add("vdisplaytype",
4908 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4909 __FILE__,VDisplayType,group);
4911 theCommands.Add("vdisplaymode",
4912 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4913 __FILE__,VDispMode,group);
4915 theCommands.Add("verasemode",
4916 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4917 __FILE__,VDispMode,group);
4919 theCommands.Add("vsetdispmode",
4920 "vsetdispmode [name] mode(1,2,..)"
4921 "\n\t\t: Sets display mode for all, selected or named objects.",
4922 __FILE__,VDispMode,group);
4924 theCommands.Add("vunsetdispmode",
4925 "vunsetdispmode [name]"
4926 "\n\t\t: Unsets custom display mode for selected or named objects.",
4927 __FILE__,VDispMode,group);
4929 theCommands.Add("vdir",
4930 "Lists all objects displayed in 3D viewer",
4931 __FILE__,VDir,group);
4933 theCommands.Add("vdump",
4934 #ifdef HAVE_FREEIMAGE
4935 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4936 "\n\t\t: [width Width=0 height Height=0]"
4937 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4939 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4940 "\n\t\t: [width Width=0 height Height=0]"
4941 "\n\t\t: Dumps content of the active view into PPM image file",
4943 __FILE__,VDump,group);
4945 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4946 __FILE__,VSubInt,group);
4948 theCommands.Add("vaspects",
4949 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
4950 "\n\t\t: [-setvisibility 0|1]"
4951 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
4952 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4953 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4954 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4955 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
4956 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
4957 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
4958 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4959 "\n\t\t: Manage presentation properties of all, selected or named objects."
4960 "\n\t\t: When -subshapes is specified than following properties will be"
4961 "\n\t\t: assigned to specified sub-shapes."
4962 "\n\t\t: When -defaults is specified than presentation properties will be"
4963 "\n\t\t: assigned to all objects that have not their own specified properties"
4964 "\n\t\t: and to all objects to be displayed in the future."
4965 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
4966 __FILE__,VAspects,group);
4968 theCommands.Add("vsetcolor",
4969 "vsetcolor [-noupdate|-update] [name] ColorName"
4970 "\n\t\t: Sets color for all, selected or named objects."
4971 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4972 __FILE__,VAspects,group);
4974 theCommands.Add("vunsetcolor",
4975 "vunsetcolor [-noupdate|-update] [name]"
4976 "\n\t\t: Resets color for all, selected or named objects."
4977 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4978 __FILE__,VAspects,group);
4980 theCommands.Add("vsettransparency",
4981 "vsettransparency [-noupdate|-update] [name] Coefficient"
4982 "\n\t\t: Sets transparency for all, selected or named objects."
4983 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4984 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4985 __FILE__,VAspects,group);
4987 theCommands.Add("vunsettransparency",
4988 "vunsettransparency [-noupdate|-update] [name]"
4989 "\n\t\t: Resets transparency for all, selected or named objects."
4990 "\n\t\t: Alias for vaspects -unsettransp [name].",
4991 __FILE__,VAspects,group);
4993 theCommands.Add("vsetmaterial",
4994 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4995 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4996 __FILE__,VAspects,group);
4998 theCommands.Add("vunsetmaterial",
4999 "vunsetmaterial [-noupdate|-update] [name]"
5000 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5001 __FILE__,VAspects,group);
5003 theCommands.Add("vsetwidth",
5004 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5005 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5006 __FILE__,VAspects,group);
5008 theCommands.Add("vunsetwidth",
5009 "vunsetwidth [-noupdate|-update] [name]"
5010 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5011 __FILE__,VAspects,group);
5013 theCommands.Add("vsetinteriorstyle",
5014 "vsetinteriorstyle [-noupdate|-update] [name] style"
5015 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5016 __FILE__,VSetInteriorStyle,group);
5018 theCommands.Add("vardis",
5019 "vardis : display activeareas",
5020 __FILE__,VDispAreas,group);
5022 theCommands.Add("varera",
5023 "varera : erase activeareas",
5024 __FILE__,VClearAreas,group);
5026 theCommands.Add("vsensdis",
5027 "vardisp : display active entities",
5028 __FILE__,VDispSensi,group);
5029 theCommands.Add("vsensera",
5030 "vardisp : erase active entities",
5031 __FILE__,VClearSensi,group);
5033 theCommands.Add("vselprecision",
5034 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
5035 __FILE__,VSelPrecision,group);
5037 theCommands.Add("vperf",
5038 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
5039 __FILE__,VPerf,group);
5041 theCommands.Add("vanimation",
5042 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5043 __FILE__,VAnimation,group);
5045 theCommands.Add("vsetshading",
5046 "vsetshading : vsetshading name Quality(default=0.0008) ",
5047 __FILE__,VShading,group);
5049 theCommands.Add("vunsetshading",
5050 "vunsetshading :vunsetshading name ",
5051 __FILE__,VShading,group);
5053 theCommands.Add ("vtexture",
5054 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5055 " [-scale u v] [-scale off]\n"
5056 " [-origin u v] [-origin off]\n"
5057 " [-repeat u v] [-repeat off]\n"
5058 " [-modulate {on | off}]"
5060 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5061 " specifying one of the predefined textures.\n"
5062 " The options are: \n"
5063 " -scale u v : enable texture scaling and set scale factors\n"
5064 " -scale off : disable texture scaling\n"
5065 " -origin u v : enable texture origin positioning and set the origin\n"
5066 " -origin off : disable texture origin positioning\n"
5067 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5068 " -repeat off : disable texture repeat\n"
5069 " -modulate {on | off} : enable or disable texture modulation\n"
5070 " -default : sets texture mapping default parameters\n"
5071 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5072 "or 'vtexture NameOfShape ?' to list available textures\n",
5073 __FILE__, VTexture, group);
5075 theCommands.Add("vtexscale",
5076 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5077 or 'vtexscale NameOfShape ScaleUV' \n \
5078 or 'vtexscale NameOfShape' to disable scaling\n ",
5079 __FILE__,VTexture,group);
5081 theCommands.Add("vtexorigin",
5082 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5083 or 'vtexorigin NameOfShape UVOrigin' \n \
5084 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5085 __FILE__,VTexture,group);
5087 theCommands.Add("vtexrepeat",
5088 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5089 or 'vtexrepeat NameOfShape UVRepeat \n \
5090 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5093 theCommands.Add("vtexdefault",
5094 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5097 theCommands.Add("vsetam",
5098 "vsetActivatedModes: vsetam mode(1->7) ",
5099 __FILE__,VActivatedMode,group);
5101 theCommands.Add("vunsetam",
5102 "vunsetActivatedModes: vunsetam ",
5103 __FILE__,VActivatedMode,group);
5105 theCommands.Add("vstate",
5106 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5107 "\n\t\t: Reports show/hidden state for selected or named objects"
5108 "\n\t\t: -entities - print low-level information about detected entities"
5109 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5110 __FILE__,VState,group);
5112 theCommands.Add("vpickshapes",
5113 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5114 __FILE__,VPickShape,group);
5116 theCommands.Add("vtypes",
5117 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5120 theCommands.Add("vsettransmode",
5121 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
5122 __FILE__,VSetTransMode,group);
5124 theCommands.Add("vr", "vr : reading of the shape",
5125 __FILE__,vr, group);
5127 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5128 __FILE__, VPickSelected, group);
5132 //=====================================================================
5133 //========================= for testing Draft and Rib =================
5134 //=====================================================================
5135 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5136 #include <DBRep.hxx>
5137 #include <TopoDS_Face.hxx>
5138 #include <gp_Pln.hxx>
5139 #include <AIS_KindOfSurface.hxx>
5140 #include <BRepOffsetAPI_DraftAngle.hxx>
5141 #include <Precision.hxx>
5142 #include <BRepAlgo.hxx>
5143 #include <OSD_Environment.hxx>
5144 #include <DrawTrSurf.hxx>
5145 //#include <DbgTools.hxx>
5146 //#include <FeatAlgo_MakeLinearForm.hxx>
5151 //=======================================================================
5152 //function : IsValid
5154 //=======================================================================
5155 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5156 const TopoDS_Shape& theResult,
5157 const Standard_Boolean closedSolid,
5158 const Standard_Boolean GeomCtrl)
5160 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5161 TCollection_AsciiString checkValid = check.Value();
5162 Standard_Boolean ToCheck = Standard_True;
5163 if (!checkValid.IsEmpty()) {
5165 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5167 if ( checkValid=="true" || checkValid=="TRUE" ) {
5168 ToCheck= Standard_False;
5172 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
5175 Standard_Boolean IsValid = Standard_True;
5177 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5182 //===============================================================================
5183 // TDraft : test draft, uses AIS Viewer
5184 // Solid Face Plane Angle Reverse
5185 //===============================================================================
5186 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5188 if (argc < 5) return 1;
5189 // argv[1] - TopoDS_Shape Solid
5190 // argv[2] - TopoDS_Shape Face
5191 // argv[3] - TopoDS_Shape Plane
5192 // argv[4] - Standard_Real Angle
5193 // argv[5] - Standard_Integer Reverse
5195 // Sprintf(prefix, argv[1]);
5196 Standard_Real anAngle = 0;
5197 Standard_Boolean Rev = Standard_False;
5198 Standard_Integer rev = 0;
5199 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5200 TopoDS_Shape face = GetShapeFromName(argv[2]);
5201 TopoDS_Face Face = TopoDS::Face(face);
5202 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5203 if (Plane.IsNull ()) {
5204 di << "TEST : Plane is NULL" << "\n";
5207 anAngle = Draw::Atof(argv[4]);
5208 anAngle = 2*M_PI * anAngle / 360.0;
5210 Handle( Geom_Surface )aSurf;
5211 AIS_KindOfSurface aSurfType;
5212 Standard_Real Offset;
5214 if(argc > 4) { // == 5
5215 rev = Draw::Atoi(argv[5]);
5216 Rev = (rev)? Standard_True : Standard_False;
5219 TopoDS_Face face2 = TopoDS::Face(Plane);
5220 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5222 di << "TEST : Can't find plane" << "\n";
5226 aDir = aPln.Axis().Direction();
5229 if (Plane.Orientation() == TopAbs_REVERSED)
5231 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5233 BRepOffsetAPI_DraftAngle Draft (Solid);
5235 if(Abs(anAngle)< Precision::Angular()) {
5236 di << "TEST : NULL angle" << "\n";
5239 if(Rev) anAngle = - anAngle;
5240 Draft.Add (Face, aDir, anAngle, aPln);
5242 if (!Draft.IsDone()) {
5243 di << "TEST : Draft Not DONE " << "\n";
5246 TopTools_ListOfShape Larg;
5248 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5249 di << "TEST : DesignAlgo returns Not valid" << "\n";
5253 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5254 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5256 if ( !ais.IsNull() ) {
5257 ais->SetColor(DEFAULT_COLOR);
5258 ais->SetMaterial(DEFAULT_MATERIAL);
5259 // Display the AIS_Shape without redraw
5260 Ctx->Display(ais, Standard_False);
5262 const char *Name = "draft1";
5263 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5265 Handle(AIS_InteractiveObject) an_object =
5266 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5267 if (!an_object.IsNull()) {
5268 Ctx->Remove(an_object,
5270 GetMapOfAIS().UnBind2(Name) ;
5273 GetMapOfAIS().Bind(ais, Name);
5274 // DBRep::Set("draft", ais->Shape());
5276 Ctx->Display(ais, Standard_True);
5280 //==============================================================================
5281 //function : splitParameter
5282 //purpose : Split parameter string to parameter name and parameter value
5283 //==============================================================================
5284 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5285 TCollection_AsciiString& theName,
5286 TCollection_AsciiString& theValue)
5288 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5290 if (aParamNameEnd == 0)
5292 return Standard_False;
5295 TCollection_AsciiString aString (theString);
5296 if (aParamNameEnd != 0)
5298 theValue = aString.Split (aParamNameEnd);
5299 aString.Split (aString.Length() - 1);
5303 return Standard_True;
5306 //============================================================================
5308 //============================================================================
5309 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5312 DrawTrSurf::BasicCommands(theCommands);
5313 const char* group = "Check Features Operations commands";
5315 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5317 &TDraft,group); //Draft_Modification
5320 //==============================================================================
5321 // ViewerTest::Factory
5322 //==============================================================================
5323 void ViewerTest::Factory(Draw_Interpretor& theDI)
5325 // definition of Viewer Command
5326 ViewerTest::Commands(theDI);
5327 ViewerTest::AviCommands(theDI);
5330 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
5334 // Declare entry point PLUGINFACTORY