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_HSequenceOfAsciiString.hxx>
33 #include <OSD_Timer.hxx>
34 #include <Geom_Axis2Placement.hxx>
35 #include <Geom_Axis1Placement.hxx>
36 #include <gp_Trsf.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <BRepAdaptor_Curve.hxx>
39 #include <StdSelect_ShapeTypeFilter.hxx>
41 #include <AIS_Drawer.hxx>
42 #include <AIS_ColoredShape.hxx>
43 #include <AIS_InteractiveObject.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Relation.hxx>
47 #include <AIS_TypeFilter.hxx>
48 #include <AIS_SignatureFilter.hxx>
49 #include <AIS_LocalContext.hxx>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <Aspect_InteriorStyle.hxx>
53 #include <Aspect_Window.hxx>
54 #include <Graphic3d_AspectFillArea3d.hxx>
55 #include <Graphic3d_AspectLine3d.hxx>
56 #include <Graphic3d_TextureRoot.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_IsoAspect.hxx>
60 #include <Select3D_SensitiveWire.hxx>
61 #include <SelectMgr_EntityOwner.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_ViewerSelector3d.hxx>
64 #include <Select3D_Projector.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <ViewerTest_AutoUpdater.hxx>
70 #include <Draw_Interpretor.hxx>
71 #include <TCollection_AsciiString.hxx>
72 #include <Draw_PluginMacro.hxx>
74 // avoid warnings on 'extern "C"' functions returning C++ classes
76 #define _CRT_SECURE_NO_DEPRECATE
77 #pragma warning(4:4190)
78 #pragma warning (disable:4996)
81 #include <NIS_InteractiveContext.hxx>
82 #include <NIS_Triangulated.hxx>
83 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
85 #include <Quantity_Color.hxx>
86 #include <Quantity_NameOfColor.hxx>
88 #include <Graphic3d_NameOfMaterial.hxx>
90 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
91 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
93 //=======================================================================
94 //function : GetColorFromName
95 //purpose : get the Quantity_NameOfColor from a string
96 //=======================================================================
98 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
100 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
102 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
103 if (strcasecmp (theName, aColorName) == 0)
105 return Quantity_NameOfColor (anIter);
109 return DEFAULT_COLOR;
112 //=======================================================================
113 //function : GetTypeNames
115 //=======================================================================
116 static const char** GetTypeNames()
118 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
119 "Shape","ConnectedShape","MultiConn.Shape",
120 "ConnectedInter.","MultiConn.",
121 "Constraint","Dimension"};
122 static const char** ThePointer = names;
126 //=======================================================================
127 //function : GetTypeAndSignfromString
129 //=======================================================================
130 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
132 const char ** thefullnames = GetTypeNames();
133 Standard_Integer index(-1);
135 for(Standard_Integer i=0;i<=13 && index==-1;i++)
136 if(!strcasecmp(name,thefullnames[i]))
140 TheType = AIS_KOI_None;
146 TheType = AIS_KOI_Datum;
150 TheType = AIS_KOI_Shape;
154 TheType = AIS_KOI_Object;
158 TheType = AIS_KOI_Relation;
167 #include <Draw_Interpretor.hxx>
169 #include <Draw_Appli.hxx>
173 #include <TCollection_AsciiString.hxx>
174 #include <V3d_Viewer.hxx>
175 #include <V3d_View.hxx>
178 #include <AIS_InteractiveContext.hxx>
179 #include <AIS_Shape.hxx>
180 #include <AIS_TexturedShape.hxx>
181 #include <AIS_DisplayMode.hxx>
182 #include <TColStd_MapOfInteger.hxx>
183 #include <AIS_MapOfInteractive.hxx>
184 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
185 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
186 #include <ViewerTest_EventManager.hxx>
188 #include <TopoDS_Solid.hxx>
189 #include <BRepTools.hxx>
190 #include <BRep_Builder.hxx>
191 #include <TopAbs_ShapeEnum.hxx>
193 #include <TopoDS.hxx>
194 #include <BRep_Tool.hxx>
197 #include <Draw_Window.hxx>
198 #include <AIS_ListIteratorOfListOfInteractive.hxx>
199 #include <AIS_ListOfInteractive.hxx>
200 #include <AIS_DisplayMode.hxx>
201 #include <TopTools_ListOfShape.hxx>
202 #include <BRepOffsetAPI_MakeThickSolid.hxx>
203 #include <BRepOffset.hxx>
205 //==============================================================================
206 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
207 //==============================================================================
208 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
209 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
214 //==============================================================================
215 //function : VDisplayAISObject
216 //purpose : register interactive object in the map of AIS objects;
217 // if other object with such name already registered, it will be kept
218 // or replaced depending on value of <theReplaceIfExists>,
219 // if "true" - the old object will be cleared from AIS context;
220 // returns Standard_True if <theAISObj> registered in map;
221 //==============================================================================
222 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
223 const Handle(AIS_InteractiveObject)& theAISObj,
224 Standard_Boolean theReplaceIfExists = Standard_True)
226 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
227 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
228 if (aContextAIS.IsNull())
230 std::cout << "AIS context is not available.\n";
231 return Standard_False;
234 if (aMap.IsBound2 (theName))
236 if (!theReplaceIfExists)
238 std::cout << "Other interactive object has been already "
239 << "registered with name: " << theName << ".\n"
240 << "Please use another name.\n";
241 return Standard_False;
244 // stop displaying object
245 Handle(AIS_InteractiveObject) anOldObj =
246 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
248 if (!anOldObj.IsNull())
249 aContextAIS->Clear (anOldObj, Standard_True);
251 // remove name and old object from map
252 aMap.UnBind2 (theName);
255 if (theAISObj.IsNull())
257 // object with specified name already unbound
258 return Standard_True;
261 // unbind AIS object if was bound with another name
262 aMap.UnBind1 (theAISObj);
264 // can be registered without rebinding
265 aMap.Bind (theAISObj, theName);
266 aContextAIS->Display (theAISObj, Standard_True);
267 return Standard_True;
270 static TColStd_MapOfInteger theactivatedmodes(8);
271 static TColStd_ListOfTransient theEventMgrs;
273 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
274 const Handle(AIS_InteractiveContext)& Ctx)
276 theEventMgrs.Clear();
277 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
280 static Handle(V3d_View)& a3DView()
282 static Handle(V3d_View) Viou;
287 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
288 static Handle(AIS_InteractiveContext) aContext;
292 const Handle(V3d_View)& ViewerTest::CurrentView()
296 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
301 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
303 static Handle(NIS_InteractiveContext) aContext;
304 if (aContext.IsNull()) {
305 aContext = new NIS_InteractiveContext;
306 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
311 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
313 return TheAISContext();
316 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
318 TheAISContext() = aCtx;
319 ViewerTest::ResetEventManager();
322 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
324 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
327 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
329 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
333 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
334 theEventMgrs.Prepend(EM);
337 void ViewerTest::UnsetEventManager()
339 theEventMgrs.RemoveFirst();
343 void ViewerTest::ResetEventManager()
345 const Handle(NIS_View) aView =
346 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
347 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
350 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
352 Handle(ViewerTest_EventManager) EM;
353 if(theEventMgrs.IsEmpty()) return EM;
354 Handle(Standard_Transient) Tr = theEventMgrs.First();
355 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
359 //=======================================================================
360 //function : Get Context and active view
362 //=======================================================================
363 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
364 Handle(V3d_View)& theView)
366 theCtx = ViewerTest::GetAISContext();
367 theView = ViewerTest::CurrentView();
371 std::cout << "Error: cannot find an active view!\n";
372 return Standard_False;
374 return Standard_True;
377 //==============================================================================
378 //function : GetShapeFromName
379 //purpose : Compute an Shape from a draw variable or a file name
380 //==============================================================================
382 static TopoDS_Shape GetShapeFromName(const char* name)
384 TopoDS_Shape S = DBRep::Get(name);
387 BRep_Builder aBuilder;
388 BRepTools::Read( S, name, aBuilder);
394 //==============================================================================
395 //function : GetAISShapeFromName
396 //purpose : Compute an AIS_Shape from a draw variable or a file name
397 //==============================================================================
398 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
400 Handle(AIS_Shape) retsh;
402 if(GetMapOfAIS().IsBound2(name)){
403 const Handle(AIS_InteractiveObject) IO =
404 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
406 if(IO->Type()==AIS_KOI_Shape) {
407 if(IO->Signature()==0){
408 retsh = *((Handle(AIS_Shape)*)&IO);
411 cout << "an Object which is not an AIS_Shape "
412 "already has this name!!!"<<endl;
419 TopoDS_Shape S = GetShapeFromName(name);
421 retsh = new AIS_Shape(S);
427 //==============================================================================
429 //purpose : Remove all the object from the viewer
430 //==============================================================================
431 void ViewerTest::Clear()
433 if ( !a3DView().IsNull() ) {
434 if (TheAISContext()->HasOpenedContext())
435 TheAISContext()->CloseLocalContext();
436 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
437 while ( it.More() ) {
438 cout << "Remove " << it.Key2() << endl;
439 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
440 const Handle(AIS_InteractiveObject) anObj =
441 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
442 TheAISContext()->Remove(anObj,Standard_False);
443 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
444 const Handle(NIS_InteractiveObject) anObj =
445 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
446 TheNISContext()->Remove(anObj);
450 TheAISContext()->UpdateCurrentViewer();
451 // TheNISContext()->UpdateViews();
452 GetMapOfAIS().Clear();
456 //==============================================================================
457 //function : StandardModesActivation
458 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
460 //==============================================================================
461 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
463 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
465 if (TheAISContext()->HasOpenedContext())
466 aContext->CloseLocalContext();
469 if(!aContext->HasOpenedContext()) {
470 // To unhilight the preselected object
471 aContext->UnhilightCurrents(Standard_False);
472 // Open a local Context in order to be able to select subshape from
473 // the selected shape if any or for all if there is no selection
474 if (!aContext->FirstCurrentObject().IsNull()){
475 aContext->OpenLocalContext(Standard_False);
477 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
478 aContext->Load( aContext->Current(),-1,Standard_True);
482 aContext->OpenLocalContext();
485 const char *cmode="???";
488 case 0: cmode = "Shape"; break;
489 case 1: cmode = "Vertex"; break;
490 case 2: cmode = "Edge"; break;
491 case 3: cmode = "Wire"; break;
492 case 4: cmode = "Face"; break;
493 case 5: cmode = "Shell"; break;
494 case 6: cmode = "Solid"; break;
495 case 7: cmode = "Compsolid"; break;
496 case 8: cmode = "Compound"; break;
499 if(theactivatedmodes.Contains(mode))
501 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
502 theactivatedmodes.Remove(mode);
503 cout<<"Mode "<< cmode <<" OFF"<<endl;
507 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
508 theactivatedmodes.Add(mode);
509 cout<<"Mode "<< cmode << " ON" << endl;
514 //==============================================================================
515 //function : CopyIsoAspect
516 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
517 //==============================================================================
518 static Handle(Prs3d_IsoAspect) CopyIsoAspect
519 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
520 const Standard_Integer theNbIsos)
522 Quantity_Color aColor;
523 Aspect_TypeOfLine aType;
524 Standard_Real aWidth;
526 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
528 Handle(Prs3d_IsoAspect) aResult =
529 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
534 //==============================================================================
536 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
537 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
538 //==============================================================================
539 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
541 if (TheAISContext().IsNull()) {
542 di << argv[0] << " Call 'vinit' before!\n";
547 di << "Current number of isos : " <<
548 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
549 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
550 di << "IsoOnPlane mode is " <<
551 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
556 Standard_Integer aLastInd = argc - 1;
557 Standard_Boolean isChanged = Standard_False;
558 Standard_Integer aNbUIsos = 0;
559 Standard_Integer aNbVIsos = 0;
562 Standard_Boolean isIsoOnPlane = Standard_False;
564 if (strcmp(argv[aLastInd], "1") == 0) {
565 isIsoOnPlane = Standard_True;
566 isChanged = Standard_True;
567 } else if (strcmp(argv[aLastInd], "0") == 0) {
568 isIsoOnPlane = Standard_False;
569 isChanged = Standard_True;
573 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
574 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
577 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
578 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
580 TheAISContext()->IsoOnPlane(isIsoOnPlane);
583 // If there are no shapes provided set the default numbers.
584 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
585 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
592 for (i = 1; i <= aLastInd; i++) {
593 TCollection_AsciiString name(argv[i]);
594 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
597 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
598 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
599 const Handle(AIS_InteractiveObject) aShape =
600 Handle(AIS_InteractiveObject)::DownCast (anObj);
601 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
602 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
603 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
606 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
607 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
608 TheAISContext()->SetLocalAttributes
609 (aShape, CurDrawer, Standard_False);
610 TheAISContext()->Redisplay(aShape);
612 di << "Number of isos for " << argv[i] << " : "
613 << aUIso->Number() << " " << aVIso->Number() << "\n";
616 di << argv[i] << ": Not an AIS interactive object!\n";
619 di << argv[i] << ": Use 'vdisplay' before\n";
624 TheAISContext()->UpdateCurrentViewer();
630 //==============================================================================
631 //function : VDispAreas,VDispSensitive,...
633 //==============================================================================
634 static Standard_Integer VDispAreas (Draw_Interpretor& ,
635 Standard_Integer theArgNb,
640 std::cout << "Error: wrong syntax!\n";
644 Handle(AIS_InteractiveContext) aCtx;
645 Handle(V3d_View) aView;
646 if (!getCtxAndView (aCtx, aView))
651 aCtx->DisplayActiveAreas (aView);
654 static Standard_Integer VClearAreas (Draw_Interpretor& ,
655 Standard_Integer theArgNb,
660 std::cout << "Error: wrong syntax!\n";
664 Handle(AIS_InteractiveContext) aCtx;
665 Handle(V3d_View) aView;
666 if (!getCtxAndView (aCtx, aView))
671 aCtx->ClearActiveAreas (aView);
675 static Standard_Integer VDispSensi (Draw_Interpretor& ,
676 Standard_Integer theArgNb,
681 std::cout << "Error: wrong syntax!\n";
685 Handle(AIS_InteractiveContext) aCtx;
686 Handle(V3d_View) aView;
687 if (!getCtxAndView (aCtx, aView))
692 aCtx->DisplayActiveSensitive (aView);
697 static Standard_Integer VClearSensi (Draw_Interpretor& ,
698 Standard_Integer theArgNb,
703 std::cout << "Error: wrong syntax!\n";
707 Handle(AIS_InteractiveContext) aCtx;
708 Handle(V3d_View) aView;
709 if (!getCtxAndView (aCtx, aView))
713 aCtx->ClearActiveSensitive (aView);
717 //==============================================================================
719 //purpose : To list the displayed object with their attributes
720 //==============================================================================
721 static int VDir (Draw_Interpretor& theDI,
725 if (!a3DView().IsNull())
730 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
731 anIter.More(); anIter.Next())
733 theDI << "\t" << anIter.Key2().ToCString() << "\n";
738 //==============================================================================
739 //function : VSelPrecision
740 //purpose : To set the selection precision mode and tolerance value
741 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
742 // value (integer number of pixel for window mode, double value of
743 // sensitivity for view mode). Without arguments the function just
744 // prints the current precision mode and the corresponding tolerance.
745 //==============================================================================
746 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
750 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
754 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
755 if( aContext.IsNull() )
760 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
761 if( aMode == StdSelect_SM_WINDOW )
763 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
764 di << "Precision mode : 0 (window)\n";
765 di << "Pixel tolerance : " << aPixelTolerance << "\n";
767 else if( aMode == StdSelect_SM_VIEW )
769 Standard_Real aSensitivity = aContext->Sensitivity();
770 di << "Precision mode : 1 (view)\n";
771 di << "Sensitivity : " << aSensitivity << "\n";
776 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
777 aContext->SetSensitivityMode( aMode );
780 if( aMode == StdSelect_SM_WINDOW )
782 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
783 aContext->SetPixelTolerance( aPixelTolerance );
785 else if( aMode == StdSelect_SM_VIEW )
787 Standard_Real aSensitivity = Draw::Atof( argv[2] );
788 aContext->SetSensitivity( aSensitivity );
795 //==============================================================================
797 //purpose : To dump the active view snapshot to image file
798 //==============================================================================
799 static Standard_Integer VDump (Draw_Interpretor& theDI,
800 Standard_Integer theArgNb,
801 Standard_CString* theArgVec)
805 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
809 Standard_Integer anArgIter = 1;
810 Standard_CString aFilePath = theArgVec[anArgIter++];
811 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
812 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
813 Standard_Integer aWidth = 0;
814 Standard_Integer aHeight = 0;
815 for (; anArgIter < theArgNb; ++anArgIter)
817 TCollection_AsciiString anArg (theArgVec[anArgIter]);
821 aBufferType = Graphic3d_BT_RGBA;
823 else if (anArg == "rgb")
825 aBufferType = Graphic3d_BT_RGB;
827 else if (anArg == "depth")
829 aBufferType = Graphic3d_BT_Depth;
831 else if (anArg == "l"
834 aStereoOpts = V3d_SDO_LEFT_EYE;
836 else if (anArg == "r"
839 aStereoOpts = V3d_SDO_RIGHT_EYE;
841 else if (anArg == "mono")
843 aStereoOpts = V3d_SDO_MONO;
845 else if (anArg == "w"
850 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
853 else if (++anArgIter >= theArgNb)
855 std::cout << "Error: integer value is expected right after 'width'\n";
858 aWidth = Draw::Atoi (theArgVec[anArgIter]);
860 else if (anArg == "h"
861 || anArg == "height")
865 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
868 if (++anArgIter >= theArgNb)
870 std::cout << "Error: integer value is expected right after 'height'\n";
873 aHeight = Draw::Atoi (theArgVec[anArgIter]);
875 else if (anArg.IsIntegerValue())
877 // compatibility with old syntax
881 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
884 else if (++anArgIter >= theArgNb)
886 std::cout << "Error: height value is expected right after width\n";
889 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
890 aHeight = Draw::Atoi (theArgVec[anArgIter]);
894 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
898 if ((aWidth <= 0 && aHeight > 0)
899 || (aWidth > 0 && aHeight <= 0))
901 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
905 Handle(V3d_View) aView = ViewerTest::CurrentView();
908 std::cout << "Error: cannot find an active view!\n";
912 if (aWidth <= 0 || aHeight <= 0)
914 if (aStereoOpts != V3d_SDO_MONO)
916 aView->Window()->Size (aWidth, aHeight);
920 if (!aView->Dump (aFilePath, aBufferType))
922 theDI << "Fail: view dump failed!\n";
928 Image_AlienPixMap aPixMap;
929 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
931 theDI << "Fail: view dump failed!\n";
935 if (aPixMap.SizeX() != Standard_Size(aWidth)
936 || aPixMap.SizeY() != Standard_Size(aHeight))
938 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
939 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
941 if (!aPixMap.Save (aFilePath))
943 theDI << "Fail: image can not be saved!\n";
949 //==============================================================================
950 //function : Displays,Erase...
953 //==============================================================================
954 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
955 const Standard_Integer Mode,
956 const Standard_Integer TypeOfOperation,
957 const Standard_Boolean Upd)
959 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
961 switch(TypeOfOperation){
963 Ctx->Display(IO,Mode,Upd);
971 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
973 Ctx->SetDisplayMode(IO,Mode,Upd);
978 Ctx->SetDisplayMode(0,Upd);
980 Ctx->UnsetDisplayMode(IO,Upd);
987 //=======================================================================
990 //=======================================================================
991 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
994 TCollection_AsciiString name;
997 // display others presentations
998 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
999 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1000 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1001 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1003 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1005 //unset displaymode.. comportement particulier...
1006 if(TypeOfOperation==4){
1008 if(Ctx->NbCurrents()==0 ||
1009 Ctx->NbSelected()==0){
1010 Handle(AIS_InteractiveObject) IO;
1011 VwrTst_DispErase(IO,-1,4,Standard_False);
1013 else if(!Ctx->HasOpenedContext()){
1014 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1015 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1018 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1019 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1020 Ctx->UpdateCurrentViewer();
1023 Handle(AIS_InteractiveObject) IO;
1025 if(GetMapOfAIS().IsBound2(name)){
1026 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1028 VwrTst_DispErase(IO,-1,4,Standard_True);
1033 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1034 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1035 Handle(AIS_InteractiveObject) IO;
1036 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1038 if(!Ctx->HasOpenedContext()){
1039 // set/unset display mode sur le Contexte...
1040 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1041 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1043 Ctx->UpdateCurrentViewer();
1046 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1047 Ctx->Display(Ctx->Interactive(),Dmode);
1051 Handle(AIS_InteractiveObject) IO;
1053 if(GetMapOfAIS().IsBound2(name))
1054 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1056 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1062 //=======================================================================
1065 //=======================================================================
1066 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1068 if(argc==1) return 1;
1069 Standard_Integer On = Draw::Atoi(argv[1]);
1070 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1074 if(!Ctx->HasOpenedContext()){
1075 di<<"sub intensite ";
1078 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1079 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1081 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1083 di <<"passage dans off"<<"\n";
1084 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1089 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1091 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1093 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1096 Ctx->UpdateCurrentViewer();
1099 Handle(AIS_InteractiveObject) IO;
1100 TCollection_AsciiString name = argv[2];
1101 if(GetMapOfAIS().IsBound2(name)){
1102 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1105 Ctx->SubIntensityOn(IO);
1107 Ctx->SubIntensityOff(IO);
1115 //! Auxiliary class to iterate presentations from different collections.
1116 class ViewTest_PrsIter
1120 //! Create and initialize iterator object.
1121 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1122 : mySource (IterSource_All)
1124 NCollection_Sequence<TCollection_AsciiString> aNames;
1125 if (!theName.IsEmpty())
1126 aNames.Append (theName);
1130 //! Create and initialize iterator object.
1131 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1132 : mySource (IterSource_All)
1137 //! Initialize the iterator.
1138 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1140 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1142 mySelIter.Nullify();
1143 myCurrent.Nullify();
1144 myCurrentTrs.Nullify();
1145 if (!mySeq.IsEmpty())
1147 mySource = IterSource_List;
1148 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1150 else if (aCtx->NbCurrents() > 0)
1152 mySource = IterSource_Selected;
1154 mySelIter->InitCurrent();
1158 mySource = IterSource_All;
1159 myMapIter.Initialize (GetMapOfAIS());
1164 const TCollection_AsciiString& CurrentName() const
1166 return myCurrentName;
1169 const Handle(AIS_InteractiveObject)& Current() const
1174 const Handle(Standard_Transient)& CurrentTrs() const
1176 return myCurrentTrs;
1179 //! @return true if iterator points to valid object within collection
1180 Standard_Boolean More() const
1184 case IterSource_All: return myMapIter.More();
1185 case IterSource_List: return mySeqIter.More();
1186 case IterSource_Selected: return mySelIter->MoreCurrent();
1188 return Standard_False;
1191 //! Go to the next item.
1194 myCurrentName.Clear();
1195 myCurrentTrs.Nullify();
1196 myCurrent.Nullify();
1199 case IterSource_All:
1204 case IterSource_List:
1209 case IterSource_Selected:
1211 mySelIter->NextCurrent();
1224 case IterSource_All:
1226 if (myMapIter.More())
1228 myCurrentName = myMapIter.Key2();
1229 myCurrentTrs = myMapIter.Key1();
1230 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1234 case IterSource_List:
1236 if (mySeqIter.More())
1238 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1240 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1243 myCurrentName = mySeqIter.Value();
1244 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1245 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1249 case IterSource_Selected:
1251 if (mySelIter->MoreCurrent())
1253 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1254 myCurrent = mySelIter->Current();
1272 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1273 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1274 NCollection_Sequence<TCollection_AsciiString> mySeq;
1275 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1277 TCollection_AsciiString myCurrentName;//!< current item name
1278 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1279 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1281 IterSource mySource; //!< iterated collection
1285 //==============================================================================
1286 //function : VInteriorStyle
1287 //purpose : sets interior style of the a selected or named or displayed shape
1288 //==============================================================================
1289 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1290 Standard_Integer theArgNb,
1291 const char** theArgVec)
1293 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1294 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1297 std::cerr << "Error: no active view!\n";
1301 Standard_Integer anArgIter = 1;
1302 for (; anArgIter < theArgNb; ++anArgIter)
1304 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1309 TCollection_AsciiString aName;
1310 if (theArgNb - anArgIter == 2)
1312 aName = theArgVec[anArgIter++];
1314 else if (theArgNb - anArgIter != 1)
1316 std::cout << "Error: wrong number of arguments! See usage:\n";
1317 theDI.PrintHelp (theArgVec[0]);
1320 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1321 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1322 aStyleArg.LowerCase();
1323 if (aStyleArg == "empty")
1327 else if (aStyleArg == "hollow")
1331 else if (aStyleArg == "hatch")
1335 else if (aStyleArg == "solid")
1339 else if (aStyleArg == "hiddenline")
1345 anInterStyle = aStyleArg.IntegerValue();
1347 if (anInterStyle < Aspect_IS_EMPTY
1348 || anInterStyle > Aspect_IS_HIDDENLINE)
1350 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1351 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1355 if (!aName.IsEmpty()
1356 && !GetMapOfAIS().IsBound2 (aName))
1358 std::cout << "Error: object " << aName << " is not displayed!\n";
1362 if (aCtx->HasOpenedContext())
1364 aCtx->CloseLocalContext();
1366 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1368 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1371 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1372 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1373 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1374 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1375 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1381 //! Auxiliary structure for VAspects
1382 struct ViewerTest_AspectsChangeSet
1384 Standard_Integer ToSetColor;
1385 Quantity_Color Color;
1387 Standard_Integer ToSetLineWidth;
1388 Standard_Real LineWidth;
1390 Standard_Integer ToSetTransparency;
1391 Standard_Real Transparency;
1393 Standard_Integer ToSetMaterial;
1394 Graphic3d_NameOfMaterial Material;
1395 TCollection_AsciiString MatName;
1397 NCollection_Sequence<TopoDS_Shape> SubShapes;
1399 //! Empty constructor
1400 ViewerTest_AspectsChangeSet()
1402 Color (DEFAULT_COLOR),
1405 ToSetTransparency (0),
1408 Material (Graphic3d_NOM_DEFAULT) {}
1410 //! @return true if no changes have been requested
1411 Standard_Boolean IsEmpty() const
1413 return ToSetLineWidth == 0
1414 && ToSetTransparency == 0
1416 && ToSetMaterial == 0;
1419 //! @return true if properties are valid
1420 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1422 Standard_Boolean isOk = Standard_True;
1423 if (LineWidth <= 0.0
1424 || LineWidth > 10.0)
1426 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1427 isOk = Standard_False;
1429 if (Transparency < 0.0
1430 || Transparency > 1.0)
1432 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1433 isOk = Standard_False;
1436 && ToSetTransparency)
1438 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1439 isOk = Standard_False;
1441 if (ToSetMaterial == 1
1442 && Material == Graphic3d_NOM_DEFAULT)
1444 std::cout << "Error: unknown material " << MatName << ".\n";
1445 isOk = Standard_False;
1452 //==============================================================================
1453 //function : VAspects
1455 //==============================================================================
1456 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1457 Standard_Integer theArgNb,
1458 const char** theArgVec)
1460 TCollection_AsciiString aCmdName (theArgVec[0]);
1461 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1462 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1465 std::cerr << "Error: no active view!\n";
1469 Standard_Integer anArgIter = 1;
1470 NCollection_Sequence<TCollection_AsciiString> aNames;
1471 for (; anArgIter < theArgNb; ++anArgIter)
1473 TCollection_AsciiString anArg = theArgVec[anArgIter];
1474 if (anUpdateTool.parseRedrawMode (anArg))
1478 else if (!anArg.IsEmpty()
1479 && anArg.Value (1) != '-')
1481 aNames.Append (anArg);
1489 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1490 aChanges.Append (ViewerTest_AspectsChangeSet());
1491 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1493 // parse syntax of legacy commands
1494 if (aCmdName == "vsetwidth")
1496 if (aNames.IsEmpty()
1497 || !aNames.Last().IsRealValue())
1499 std::cout << "Error: not enough arguments!\n";
1502 aChangeSet->ToSetLineWidth = 1;
1503 aChangeSet->LineWidth = aNames.Last().RealValue();
1504 aNames.Remove (aNames.Length());
1506 else if (aCmdName == "vunsetwidth")
1508 aChangeSet->ToSetLineWidth = -1;
1510 else if (aCmdName == "vsetcolor")
1512 if (aNames.IsEmpty())
1514 std::cout << "Error: not enough arguments!\n";
1517 aChangeSet->ToSetColor = 1;
1518 aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString());
1519 aNames.Remove (aNames.Length());
1521 else if (aCmdName == "vunsetcolor")
1523 aChangeSet->ToSetColor = -1;
1525 else if (aCmdName == "vsettransparency")
1527 if (aNames.IsEmpty()
1528 || !aNames.Last().IsRealValue())
1530 std::cout << "Error: not enough arguments!\n";
1533 aChangeSet->ToSetTransparency = 1;
1534 aChangeSet->Transparency = aNames.Last().RealValue();
1535 aNames.Remove (aNames.Length());
1537 else if (aCmdName == "vunsettransparency")
1539 aChangeSet->ToSetTransparency = -1;
1541 else if (aCmdName == "vsetmaterial")
1543 if (aNames.IsEmpty())
1545 std::cout << "Error: not enough arguments!\n";
1548 aChangeSet->ToSetMaterial = 1;
1549 aChangeSet->MatName = aNames.Last();
1550 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1551 aNames.Remove (aNames.Length());
1553 else if (aCmdName == "vunsetmaterial")
1555 aChangeSet->ToSetMaterial = -1;
1557 else if (anArgIter >= theArgNb)
1559 std::cout << "Error: not enough arguments!\n";
1563 if (!aChangeSet->IsEmpty())
1565 anArgIter = theArgNb;
1567 for (; anArgIter < theArgNb; ++anArgIter)
1569 TCollection_AsciiString anArg = theArgVec[anArgIter];
1571 if (anArg == "-setwidth"
1572 || anArg == "-setlinewidth")
1574 if (++anArgIter >= theArgNb)
1576 std::cout << "Error: wrong syntax at " << anArg << "\n";
1579 aChangeSet->ToSetLineWidth = 1;
1580 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1582 else if (anArg == "-unsetwidth"
1583 || anArg == "-unsetlinewidth")
1585 aChangeSet->ToSetLineWidth = -1;
1586 aChangeSet->LineWidth = 1.0;
1588 else if (anArg == "-settransp"
1589 || anArg == "-settransparency")
1591 if (++anArgIter >= theArgNb)
1593 std::cout << "Error: wrong syntax at " << anArg << "\n";
1596 aChangeSet->ToSetTransparency = 1;
1597 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1598 if (aChangeSet->Transparency >= 0.0
1599 && aChangeSet->Transparency <= Precision::Confusion())
1601 aChangeSet->ToSetTransparency = -1;
1602 aChangeSet->Transparency = 0.0;
1605 else if (anArg == "-setalpha")
1607 if (++anArgIter >= theArgNb)
1609 std::cout << "Error: wrong syntax at " << anArg << "\n";
1612 aChangeSet->ToSetTransparency = 1;
1613 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1614 if (aChangeSet->Transparency < 0.0
1615 || aChangeSet->Transparency > 1.0)
1617 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1620 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1621 if (aChangeSet->Transparency >= 0.0
1622 && aChangeSet->Transparency <= Precision::Confusion())
1624 aChangeSet->ToSetTransparency = -1;
1625 aChangeSet->Transparency = 0.0;
1628 else if (anArg == "-unsettransp"
1629 || anArg == "-unsettransparency"
1630 || anArg == "-unsetalpha"
1631 || anArg == "-opaque")
1633 aChangeSet->ToSetTransparency = -1;
1634 aChangeSet->Transparency = 0.0;
1636 else if (anArg == "-setcolor")
1638 if (++anArgIter >= theArgNb)
1640 std::cout << "Error: wrong syntax at " << anArg << "\n";
1643 aChangeSet->ToSetColor = 1;
1644 aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
1646 else if (anArg == "-unsetcolor")
1648 aChangeSet->ToSetColor = -1;
1649 aChangeSet->Color = DEFAULT_COLOR;
1651 else if (anArg == "-setmat"
1652 || anArg == "-setmaterial")
1654 if (++anArgIter >= theArgNb)
1656 std::cout << "Error: wrong syntax at " << anArg << "\n";
1659 aChangeSet->ToSetMaterial = 1;
1660 aChangeSet->MatName = theArgVec[anArgIter];
1661 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1663 else if (anArg == "-unsetmat"
1664 || anArg == "-unsetmaterial")
1666 aChangeSet->ToSetMaterial = -1;
1667 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1669 else if (anArg == "-subshape"
1670 || anArg == "-subshapes")
1672 if (aNames.IsEmpty())
1674 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1678 aChanges.Append (ViewerTest_AspectsChangeSet());
1679 aChangeSet = &aChanges.ChangeLast();
1681 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1683 Standard_CString aSubShapeName = theArgVec[anArgIter];
1684 if (*aSubShapeName == '-')
1690 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1691 if (aSubShape.IsNull())
1693 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1696 aChangeSet->SubShapes.Append (aSubShape);
1699 if (aChangeSet->SubShapes.IsEmpty())
1701 std::cerr << "Error: empty list is specified after -subshapes!\n";
1705 else if (anArg == "-unset")
1707 aChangeSet->ToSetLineWidth = -1;
1708 aChangeSet->LineWidth = 1.0;
1709 aChangeSet->ToSetTransparency = -1;
1710 aChangeSet->Transparency = 0.0;
1711 aChangeSet->ToSetColor = -1;
1712 aChangeSet->Color = DEFAULT_COLOR;
1713 aChangeSet->ToSetMaterial = -1;
1714 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1718 std::cout << "Error: wrong syntax at " << anArg << "\n";
1723 Standard_Boolean isFirst = Standard_True;
1724 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1725 aChangesIter.More(); aChangesIter.Next())
1727 if (!aChangesIter.Value().Validate (!isFirst))
1731 isFirst = Standard_False;
1734 if (aCtx->HasOpenedContext())
1736 aCtx->CloseLocalContext();
1738 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1740 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1741 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1742 Handle(AIS_ColoredShape) aColoredPrs;
1743 Standard_Boolean toDisplay = Standard_False;
1744 if (aChanges.Length() > 1)
1746 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1747 if (aShapePrs.IsNull())
1749 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1752 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1753 if (aColoredPrs.IsNull())
1755 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1756 aCtx->Remove (aShapePrs, Standard_False);
1757 GetMapOfAIS().UnBind2 (aName);
1758 GetMapOfAIS().Bind (aColoredPrs, aName);
1759 toDisplay = Standard_True;
1760 aShapePrs = aColoredPrs;
1767 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1768 aChangeSet = &aChangesIter.ChangeValue();
1769 if (aChangeSet->ToSetMaterial == 1)
1771 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1773 else if (aChangeSet->ToSetMaterial == -1)
1775 aCtx->UnsetMaterial (aPrs, Standard_False);
1777 if (aChangeSet->ToSetColor == 1)
1779 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1781 else if (aChangeSet->ToSetColor == -1)
1783 aCtx->UnsetColor (aPrs, Standard_False);
1785 if (aChangeSet->ToSetTransparency == 1)
1787 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1789 else if (aChangeSet->ToSetTransparency == -1)
1791 aCtx->UnsetTransparency (aPrs, Standard_False);
1793 if (aChangeSet->ToSetLineWidth == 1)
1795 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1797 else if (aChangeSet->ToSetLineWidth == -1)
1799 aCtx->UnsetWidth (aPrs, Standard_False);
1802 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1804 aChangeSet = &aChangesIter.ChangeValue();
1805 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1806 aSubShapeIter.More(); aSubShapeIter.Next())
1808 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1809 if (aChangeSet->ToSetColor == 1)
1811 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1813 if (aChangeSet->ToSetLineWidth == 1)
1815 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1817 if (aChangeSet->ToSetColor == -1
1818 || aChangeSet->ToSetLineWidth == -1)
1820 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1826 aCtx->Display (aPrs, Standard_False);
1828 else if (!aColoredPrs.IsNull())
1830 aColoredPrs->Redisplay();
1835 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1836 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1837 if (!aNisObj.IsNull())
1839 if (aChangeSet->ToSetTransparency != 0)
1841 aNisObj->SetTransparency (aChangeSet->Transparency);
1844 if (!aNisTri.IsNull())
1846 if (aChangeSet->ToSetColor != 0)
1848 aNisTri->SetColor (aChangeSet->Color);
1850 if (aChangeSet->ToSetLineWidth != 0)
1852 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1860 //==============================================================================
1861 //function : VDonly2
1863 //purpose : Display only a selected or named object
1864 // if there is no selected or named object s, nothing is done
1865 //==============================================================================
1866 static int VDonly2 (Draw_Interpretor& ,
1867 Standard_Integer theArgNb,
1868 const char** theArgVec)
1870 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1871 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1874 std::cerr << "Error: no active view!\n";
1878 if (aCtx->HasOpenedContext())
1880 aCtx->CloseLocalContext();
1883 Standard_Integer anArgIter = 1;
1884 for (; anArgIter < theArgNb; ++anArgIter)
1886 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1892 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1893 if (anArgIter >= theArgNb)
1895 // display only selected objects
1896 if (aCtx->NbCurrents() < 1)
1901 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1903 aDispSet.Add (aCtx->Current());
1908 // display only specified objects
1909 for (; anArgIter < theArgNb; ++anArgIter)
1911 TCollection_AsciiString aName = theArgVec[anArgIter];
1912 if (GetMapOfAIS().IsBound2 (aName))
1914 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1915 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1917 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1918 aCtx->Display (aShape, Standard_False);
1920 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1922 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1923 TheNISContext()->Display (aShape);
1925 aDispSet.Add (anObj);
1930 // weed out other objects
1931 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1933 if (aDispSet.Contains (anIter.Key1()))
1938 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1940 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1941 aCtx->Erase (aShape, Standard_False);
1943 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1945 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1946 TheNISContext()->Erase (aShape);
1952 //==============================================================================
1953 //function : VRemove
1954 //purpose : Removes selected or named objects.
1955 // If there is no selected or named objects,
1956 // all objects in the viewer can be removed with argument -all.
1957 // If -context is in arguments, the object is not deleted from the map of
1958 // objects (deleted only from the current context).
1959 //==============================================================================
1960 int VRemove (Draw_Interpretor& theDI,
1961 Standard_Integer theArgNb,
1962 const char** theArgVec)
1964 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1965 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1968 std::cout << "Error: no active view!\n";
1972 aCtx->CloseAllContexts (Standard_False);
1974 Standard_Boolean isContextOnly = Standard_False;
1975 Standard_Boolean toRemoveAll = Standard_False;
1976 Standard_Boolean toPrintInfo = Standard_True;
1978 Standard_Integer anArgIter = 1;
1979 for (; anArgIter < theArgNb; ++anArgIter)
1981 TCollection_AsciiString anArg = theArgVec[anArgIter];
1983 if (anArg == "-context")
1985 isContextOnly = Standard_True;
1987 else if (anArg == "-all")
1989 toRemoveAll = Standard_True;
1991 else if (anArg == "-noinfo")
1993 toPrintInfo = Standard_False;
1995 else if (!anUpdateTool.parseRedrawMode (anArg))
2001 && anArgIter < theArgNb)
2003 std::cout << "Error: wrong syntax!\n";
2007 NCollection_List<TCollection_AsciiString> anIONameList;
2010 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2011 anIter.More(); anIter.Next())
2013 anIONameList.Append (anIter.Key2());
2016 else if (anArgIter < theArgNb) // removed objects names are in argument list
2018 for (; anArgIter < theArgNb; ++anArgIter)
2020 TCollection_AsciiString aName = theArgVec[anArgIter];
2021 if (!GetMapOfAIS().IsBound2 (aName))
2023 theDI << aName.ToCString() << " was not bound to some object.\n";
2027 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2029 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2032 if (anIO->GetContext() != aCtx)
2034 theDI << aName.ToCString() << " was not displayed in current context.\n";
2035 theDI << "Please activate view with this object displayed and try again.\n";
2039 anIONameList.Append (aName);
2043 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2044 if (!aNisIO.IsNull())
2046 anIONameList.Append (aName);
2050 else if (aCtx->NbCurrents() > 0
2051 || TheNISContext()->GetSelected().Extent() > 0)
2053 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2054 anIter.More(); anIter.Next())
2056 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2059 if (!aCtx->IsCurrent (anIO))
2064 anIONameList.Append (anIter.Key2());
2068 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2069 if (!aNisIO.IsNull())
2071 if (!TheNISContext()->IsSelected (aNisIO))
2076 anIONameList.Append (anIter.Key2());
2081 // Unbind all removed objects from the map of displayed IO.
2082 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2083 anIter.More(); anIter.Next())
2085 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2088 aCtx->Remove (anIO, Standard_False);
2091 theDI << anIter.Value().ToCString() << " was removed\n";
2096 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2097 if (!aNisIO.IsNull())
2099 TheNISContext()->Remove (aNisIO);
2102 theDI << anIter.Value().ToCString() << " was removed\n";
2108 GetMapOfAIS().UnBind2 (anIter.Value());
2114 //==============================================================================
2116 //purpose : Erase some selected or named objects
2117 // if there is no selected or named objects, the whole viewer is erased
2118 //==============================================================================
2119 int VErase (Draw_Interpretor& theDI,
2120 Standard_Integer theArgNb,
2121 const char** theArgVec)
2123 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2124 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2127 std::cout << "Error: no active view!\n";
2130 aCtx->CloseAllContexts (Standard_False);
2132 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2134 Standard_Integer anArgIter = 1;
2135 for (; anArgIter < theArgNb; ++anArgIter)
2137 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2143 if (anArgIter < theArgNb)
2147 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2151 // has a list of names
2152 for (; anArgIter < theArgNb; ++anArgIter)
2154 TCollection_AsciiString aName = theArgVec[anArgIter];
2155 if (!GetMapOfAIS().IsBound2 (aName))
2160 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2161 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2162 theDI << aName.ToCString() << " ";
2165 aCtx->Erase (anIO, Standard_False);
2169 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2170 if (!aNisIO.IsNull())
2172 TheNISContext()->Erase (aNisIO);
2177 else if (!toEraseAll
2178 && aCtx->NbCurrents() > 0)
2180 // remove all currently selected objects
2181 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2182 anIter.More(); anIter.Next())
2184 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2186 && aCtx->IsCurrent (anIO))
2188 theDI << anIter.Key2().ToCString() << " ";
2189 aCtx->Erase (anIO, Standard_False);
2195 // erase entire viewer
2196 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2197 anIter.More(); anIter.Next())
2199 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2202 aCtx->Erase (anIO, Standard_False);
2206 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2207 if (!aNisIO.IsNull())
2209 TheNISContext()->Erase (aNisIO);
2217 //==============================================================================
2218 //function : VDisplayAll
2220 //purpose : Display all the objects of the Map
2221 //==============================================================================
2222 static int VDisplayAll (Draw_Interpretor& ,
2223 Standard_Integer theArgNb,
2224 const char** theArgVec)
2227 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2228 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2231 std::cout << "Error: no active view!\n";
2235 Standard_Integer anArgIter = 1;
2236 for (; anArgIter < theArgNb; ++anArgIter)
2238 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2243 if (anArgIter < theArgNb)
2245 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2249 if (aCtx->HasOpenedContext())
2251 aCtx->CloseLocalContext();
2254 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2255 anIter.More(); anIter.Next())
2257 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2259 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2260 aCtx->Erase (aShape, Standard_False);
2262 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2264 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2265 TheNISContext()->Erase (aShape);
2269 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2270 anIter.More(); anIter.Next())
2272 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2274 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2275 aCtx->Display (aShape, Standard_False);
2277 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2279 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2280 TheNISContext()->Display (aShape);
2286 //! Auxiliary method to find presentation
2287 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2288 const Handle(AIS_InteractiveObject)& theIO,
2289 const Standard_Integer theMode)
2293 return Handle(PrsMgr_Presentation)();
2298 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2300 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2303 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2305 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2307 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2309 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2311 return Handle(PrsMgr_Presentation)();
2314 enum ViewerTest_BndAction
2321 //! Auxiliary method to print bounding box of presentation
2322 inline void bndPresentation (Draw_Interpretor& theDI,
2323 const Handle(PrsMgr_Presentation)& thePrs,
2324 const TCollection_AsciiString& theName,
2325 const ViewerTest_BndAction theAction)
2329 case BndAction_Hide:
2331 thePrs->Presentation()->GraphicUnHighlight();
2334 case BndAction_Show:
2336 thePrs->Presentation()->BoundBox();
2339 case BndAction_Print:
2341 Graphic3d_Vec3d aMin, aMax;
2342 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2343 aMax.x(), aMax.y(), aMax.z());
2344 theDI << theName << "\n"
2345 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2346 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2352 //==============================================================================
2353 //function : VBounding
2355 //==============================================================================
2356 int VBounding (Draw_Interpretor& theDI,
2357 Standard_Integer theArgNb,
2358 const char** theArgVec)
2360 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2361 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2364 std::cout << "Error: no active view!\n";
2368 ViewerTest_BndAction anAction = BndAction_Show;
2369 Standard_Integer aMode = -1;
2371 Standard_Integer anArgIter = 1;
2372 for (; anArgIter < theArgNb; ++anArgIter)
2374 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2376 if (anArg == "-print")
2378 anAction = BndAction_Print;
2380 else if (anArg == "-show")
2382 anAction = BndAction_Show;
2384 else if (anArg == "-hide")
2386 anAction = BndAction_Hide;
2388 else if (anArg == "-mode")
2390 if (++anArgIter >= theArgNb)
2392 std::cout << "Error: wrong syntax at " << anArg << "\n";
2395 aMode = Draw::Atoi (theArgVec[anArgIter]);
2397 else if (!anUpdateTool.parseRedrawMode (anArg))
2403 if (anArgIter < theArgNb)
2405 // has a list of names
2406 for (; anArgIter < theArgNb; ++anArgIter)
2408 TCollection_AsciiString aName = theArgVec[anArgIter];
2409 if (!GetMapOfAIS().IsBound2 (aName))
2411 std::cout << "Error: presentation " << aName << " does not exist\n";
2415 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2416 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2419 std::cout << "Error: presentation " << aName << " does not exist\n";
2422 bndPresentation (theDI, aPrs, aName, anAction);
2425 else if (aCtx->NbCurrents() > 0)
2427 // remove all currently selected objects
2428 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2430 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2431 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2434 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2441 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2442 anIter.More(); anIter.Next())
2444 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2445 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2448 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2455 //==============================================================================
2456 //function : VTexture
2458 //==============================================================================
2459 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2461 TCollection_AsciiString aCommandName (theArgv[0]);
2463 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2464 if (aCommandName == "vtexture")
2468 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2469 std::cout << "Type help for more information.\n";
2473 // look for options of vtexture command
2474 TCollection_AsciiString aParseKey;
2475 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2477 TCollection_AsciiString anArg (theArgv [anArgIt]);
2480 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2483 aParseKey.Remove (1);
2484 aParseKey.UpperCase();
2485 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2489 if (aParseKey.IsEmpty())
2494 aMapOfArgs(aParseKey)->Append (anArg);
2497 else if (aCommandName == "vtexscale"
2498 || aCommandName == "vtexorigin"
2499 || aCommandName == "vtexrepeat")
2501 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2502 // equal to -scale, -origin, -repeat options of vtexture command
2503 if (theArgsNb < 2 || theArgsNb > 4)
2505 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2506 std::cout << "Type help for more information.\n";
2510 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2513 anArgs->Append ("OFF");
2515 else if (theArgsNb == 4)
2517 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2518 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2521 TCollection_AsciiString anArgKey;
2522 if (aCommandName == "vtexscale")
2526 else if (aCommandName == "vtexorigin")
2528 anArgKey = "ORIGIN";
2532 anArgKey = "REPEAT";
2535 aMapOfArgs.Bind (anArgKey, anArgs);
2537 else if (aCommandName == "vtexdefault")
2539 // scan for parameters of vtexdefault command
2540 // equal to -default option of vtexture command
2541 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2544 // Check arguments for validity
2545 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2546 for (; aMapIt.More(); aMapIt.Next())
2548 const TCollection_AsciiString& aKey = aMapIt.Key();
2549 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2551 // -scale, -origin, -repeat: one argument "off", or two real values
2552 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2553 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2554 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2559 // -modulate: single argument "on" / "off"
2560 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2565 // -default: no arguments
2566 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2571 TCollection_AsciiString aLowerKey;
2574 aLowerKey.LowerCase();
2575 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2576 std::cout << "Type help for more information.\n";
2580 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2581 if (anAISContext.IsNull())
2583 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2587 Standard_Integer aPreviousMode = 0;
2589 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2591 TCollection_AsciiString aShapeName (theArgv[1]);
2592 Handle(AIS_InteractiveObject) anIO;
2594 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2595 if (aMapOfIO.IsBound2 (aShapeName))
2597 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2602 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2606 Handle(AIS_TexturedShape) aTexturedIO;
2607 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2609 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2610 aPreviousMode = aTexturedIO->DisplayMode();
2614 anAISContext->Clear (anIO, Standard_False);
2615 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2616 GetMapOfAIS().UnBind1 (anIO);
2617 GetMapOfAIS().UnBind2 (aShapeName);
2618 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2621 // -------------------------------------------
2622 // Turn texturing on/off - only for vtexture
2623 // -------------------------------------------
2625 if (aCommandName == "vtexture")
2627 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2629 if (aTextureArg.IsEmpty())
2631 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2632 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2634 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2635 if (aPreviousMode == 3)
2637 anAISContext->RecomputePrsOnly (aTexturedIO);
2640 anAISContext->Display (aTexturedIO, Standard_True);
2643 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2645 if (aTextureArg == "?")
2647 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2649 theDi << "\n Files in current directory : \n" << "\n";
2650 theDi.Eval ("glob -nocomplain *");
2652 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2653 aCmnd += aTextureFolder;
2656 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2657 theDi.Eval (aCmnd.ToCString());
2662 aTexturedIO->SetTextureFileName (aTextureArg);
2667 // ------------------------------------
2668 // Process other options and commands
2669 // ------------------------------------
2671 Handle(TColStd_HSequenceOfAsciiString) aValues;
2672 if (aMapOfArgs.Find ("DEFAULT", aValues))
2674 aTexturedIO->SetTextureRepeat (Standard_False);
2675 aTexturedIO->SetTextureOrigin (Standard_False);
2676 aTexturedIO->SetTextureScale (Standard_False);
2677 aTexturedIO->EnableTextureModulate();
2681 if (aMapOfArgs.Find ("SCALE", aValues))
2683 if (aValues->Value(1) != "OFF")
2685 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2689 aTexturedIO->SetTextureScale (Standard_False);
2693 if (aMapOfArgs.Find ("ORIGIN", aValues))
2695 if (aValues->Value(1) != "OFF")
2697 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2701 aTexturedIO->SetTextureOrigin (Standard_False);
2705 if (aMapOfArgs.Find ("REPEAT", aValues))
2707 if (aValues->Value(1) != "OFF")
2709 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2713 aTexturedIO->SetTextureRepeat (Standard_False);
2717 if (aMapOfArgs.Find ("MODULATE", aValues))
2719 if (aValues->Value(1) == "ON")
2721 aTexturedIO->EnableTextureModulate();
2725 aTexturedIO->DisableTextureModulate();
2730 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2732 anAISContext->RecomputePrsOnly (aTexturedIO);
2736 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2737 anAISContext->Display (aTexturedIO, Standard_True);
2738 anAISContext->Update (aTexturedIO,Standard_True);
2744 //==============================================================================
2745 //function : VDisplay2
2747 //purpose : Display an object from its name
2748 //==============================================================================
2749 static int VDisplay2 (Draw_Interpretor& theDI,
2750 Standard_Integer theArgNb,
2751 const char** theArgVec)
2753 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2756 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2759 else if (aCtx.IsNull())
2761 ViewerTest::ViewerInit();
2762 std::cout << "Command vinit should be called before!\n";
2764 aCtx = ViewerTest::GetAISContext();
2767 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2768 if (aCtx->HasOpenedContext())
2770 aCtx->CloseLocalContext();
2773 Standard_Integer isMutable = -1;
2774 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2776 const TCollection_AsciiString aName = theArgVec[anArgIter];
2777 TCollection_AsciiString aNameCase = aName;
2778 aNameCase.LowerCase();
2779 if (anUpdateTool.parseRedrawMode (aName))
2783 else if (aNameCase == "-mutable")
2788 else if (!GetMapOfAIS().IsBound2 (aName))
2790 // create the AIS_Shape from a name
2791 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2792 if (!aShape.IsNull())
2794 if (isMutable != -1)
2796 aShape->SetMutable (isMutable == 1);
2798 GetMapOfAIS().Bind (aShape, aName);
2799 aCtx->Display (aShape, Standard_False);
2804 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2805 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2807 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2808 if (isMutable != -1)
2810 aShape->SetMutable (isMutable == 1);
2813 if (aShape->Type() == AIS_KOI_Datum)
2815 aCtx->Display (aShape, Standard_False);
2819 theDI << "Display " << aName.ToCString() << "\n";
2820 // get the Shape from a name
2821 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2823 // update the Shape in the AIS_Shape
2824 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2825 if (!aShapePrs.IsNull())
2827 aShapePrs->Set (aNewShape);
2829 aCtx->Redisplay (aShape, Standard_False);
2830 aCtx->Display (aShape, Standard_False);
2833 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2835 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2836 TheNISContext()->Display (aShape);
2842 //===============================================================================================
2843 //function : VUpdate
2845 //===============================================================================================
2846 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2848 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2849 if (aContextAIS.IsNull())
2851 std::cout << theArgVec[0] << "AIS context is not available.\n";
2857 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2861 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2863 AIS_ListOfInteractive aListOfIO;
2865 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2867 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2869 Handle(AIS_InteractiveObject) anAISObj;
2870 if (anAISMap.IsBound2 (aName))
2872 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2875 if (anAISObj.IsNull())
2877 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2881 aListOfIO.Append (anAISObj);
2884 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2885 for (; anIOIt.More(); anIOIt.Next())
2887 aContextAIS->Update (anIOIt.Value(), Standard_False);
2890 aContextAIS->UpdateCurrentViewer();
2895 //==============================================================================
2897 //purpose : Test the annimation of an object along a
2898 // predifined trajectory
2899 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2900 //==============================================================================
2902 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2905 if (TheAISContext()->HasOpenedContext())
2906 TheAISContext()->CloseLocalContext();
2908 Standard_Real Step=4*M_PI/180;
2909 Standard_Real Angle=0;
2911 Handle(AIS_InteractiveObject) aIO;
2912 if (GetMapOfAIS().IsBound2(argv[1]))
2913 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2917 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2921 if (Draw::Atoi(argv[3])==1 ) {
2922 di<<" Primitives sensibles OFF"<<"\n";
2923 TheAISContext()->Deactivate(aIO);
2926 di<<" Primitives sensibles ON"<<"\n";
2928 // Movement par transformation
2929 if(Draw::Atoi(argv[2]) ==1) {
2930 di<<" Calcul par Transformation"<<"\n";
2931 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2935 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2936 TheAISContext()->SetLocation(aShape,myTransfo);
2937 TheAISContext() ->UpdateCurrentViewer();
2942 di<<" Calcul par Locations"<<"\n";
2943 gp_Trsf myAngleTrsf;
2944 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2945 TopLoc_Location myDeltaAngle (myAngleTrsf);
2946 TopLoc_Location myTrueLoc;
2948 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2951 myTrueLoc=myTrueLoc*myDeltaAngle;
2952 TheAISContext()->SetLocation(aShape,myTrueLoc );
2953 TheAISContext() ->UpdateCurrentViewer();
2956 if (Draw::Atoi(argv[3])==1 ){
2957 // On reactive la selection des primitives sensibles
2958 TheAISContext()->Activate(aIO,0);
2960 a3DView() -> Redraw();
2962 di<<" Temps ecoule "<<"\n";
2968 //==================================================================================
2969 // Function : VAnimation
2970 //==================================================================================
2971 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2973 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2977 Standard_Real thread = 4;
2978 Standard_Real angleA=0;
2979 Standard_Real angleB;
2981 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2984 TopoDS_Shape CrankArm;
2985 TopoDS_Shape CylinderHead;
2986 TopoDS_Shape Propeller;
2987 TopoDS_Shape EngineBlock;
2989 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2990 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2991 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2992 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2993 BRepTools::Read(CrankArm,argv[1],B);
2994 BRepTools::Read(CylinderHead,argv[2],B);
2995 BRepTools::Read(Propeller,argv[3],B);
2996 BRepTools::Read(EngineBlock,argv[4],B);
2998 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3004 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3005 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3006 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3007 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3009 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3010 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3011 GetMapOfAIS().Bind(myAisCrankArm,"c");
3012 GetMapOfAIS().Bind(myAisPropeller,"d");
3014 myAisCylinderHead->SetMutable (Standard_True);
3015 myAisEngineBlock ->SetMutable (Standard_True);
3016 myAisCrankArm ->SetMutable (Standard_True);
3017 myAisPropeller ->SetMutable (Standard_True);
3019 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3020 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3021 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3023 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3024 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3025 TheAISContext()->Display (myAisCrankArm, Standard_False);
3026 TheAISContext()->Display (myAisPropeller, Standard_False);
3028 TheAISContext()->Deactivate(myAisCylinderHead);
3029 TheAISContext()->Deactivate(myAisEngineBlock );
3030 TheAISContext()->Deactivate(myAisCrankArm );
3031 TheAISContext()->Deactivate(myAisPropeller );
3033 // Boucle de mouvement
3034 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3036 angleA = thread*myAngle*M_PI/180;
3037 X = Sin(angleA)*3/8;
3038 angleB = atan(X / Sqrt(-X * X + 1));
3039 Standard_Real decal(25*0.6);
3042 //Build a transformation on the display
3043 gp_Trsf aPropellerTrsf;
3044 aPropellerTrsf.SetRotation(Ax1,angleA);
3045 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3047 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));
3048 gp_Trsf aCrankArmTrsf;
3049 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3050 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3052 TheAISContext()->UpdateCurrentViewer();
3055 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3056 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3058 myAisCrankArm ->ResetTransformation();
3059 myAisPropeller->ResetTransformation();
3061 myAisCrankArm -> Set(myNewCrankArm );
3062 myAisPropeller -> Set(myNewPropeller);
3064 TheAISContext()->Activate(myAisCylinderHead,0);
3065 TheAISContext()->Activate(myAisEngineBlock,0 );
3066 TheAISContext()->Activate(myAisCrankArm ,0 );
3067 TheAISContext()->Activate(myAisPropeller ,0 );
3073 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3074 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3076 TheAISContext()->UpdateCurrentViewer();
3077 a3DView()->Redraw();
3086 //==============================================================================
3087 //function : VShading
3088 //purpose : Sharpen or roughten the quality of the shading
3089 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3090 //==============================================================================
3091 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3093 Standard_Real myDevCoef;
3094 Handle(AIS_InteractiveObject) TheAisIO;
3097 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3099 if (TheAISContext()->HasOpenedContext())
3100 TheAISContext()->CloseLocalContext();
3105 myDevCoef =Draw::Atof(argv[2]);
3108 TCollection_AsciiString name=argv[1];
3109 if (GetMapOfAIS().IsBound2(name ))
3110 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3111 if (TheAisIO.IsNull())
3112 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3115 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3117 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3119 TheAISContext()->Redisplay(TheAisIO);
3122 //==============================================================================
3123 //function : HaveMode
3124 //use : VActivatedModes
3125 //==============================================================================
3126 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3128 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3130 TColStd_ListOfInteger List;
3131 TheAISContext()->ActivatedModes (TheAisIO,List);
3132 TColStd_ListIteratorOfListOfInteger it;
3133 Standard_Boolean Found=Standard_False;
3134 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3135 if (it.Value()==mode ) Found=Standard_True;
3142 //==============================================================================
3143 //function : VActivatedMode
3145 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3146 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3147 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3148 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3149 // qu'un nom et qu'un mode.
3150 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3151 //==============================================================================
3152 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3154 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3157 Standard_Boolean ThereIsName = Standard_False ;
3159 if(!a3DView().IsNull()){
3161 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3162 // verification des arguments
3164 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3165 ThereIsName = (argc == 3);
3169 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3171 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3172 di<<" Fermeture du Context local"<<"\n";
3173 if (TheAISContext()->HasOpenedContext())
3174 TheAISContext()->CloseLocalContext();
3178 // IL n'y a aps de nom de shape passe en argument
3179 if (HaveToSet && !ThereIsName){
3180 Standard_Integer aMode=Draw::Atoi(argv [1]);
3182 const char *cmode="???";
3184 case 0: cmode = "Shape"; break;
3185 case 1: cmode = "Vertex"; break;
3186 case 2: cmode = "Edge"; break;
3187 case 3: cmode = "Wire"; break;
3188 case 4: cmode = "Face"; break;
3189 case 5: cmode = "Shell"; break;
3190 case 6: cmode = "Solid"; break;
3191 case 7: cmode = "Compound"; break;
3194 if( !TheAISContext()->HasOpenedContext() ) {
3195 // il n'y a pas de Context local d'ouvert
3196 // on en ouvre un et on charge toutes les shapes displayees
3197 // on load tous les objets displayees et on Activate les objets de la liste
3198 AIS_ListOfInteractive ListOfIO;
3199 // on sauve dans une AISListOfInteractive tous les objets currents
3200 if (TheAISContext()->NbCurrents()>0 ){
3201 TheAISContext()->UnhilightCurrents(Standard_False);
3203 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3204 ListOfIO.Append(TheAISContext()->Current() );
3208 TheAISContext()->OpenLocalContext(Standard_False);
3209 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3212 Handle(AIS_InteractiveObject) aIO =
3213 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3215 TheAISContext()->Load(aIO,0,Standard_False);
3218 // traitement des objets qui etaient currents dans le Contexte global
3219 if (!ListOfIO.IsEmpty() ) {
3220 // il y avait des objets currents
3221 AIS_ListIteratorOfListOfInteractive iter;
3222 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3223 Handle(AIS_InteractiveObject) aIO=iter.Value();
3224 TheAISContext()->Activate(aIO,aMode);
3225 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3229 // On applique le mode a tous les objets displayes
3230 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3231 it2 (GetMapOfAIS());
3233 Handle(AIS_InteractiveObject) aIO =
3234 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3235 if (!aIO.IsNull()) {
3236 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3237 TheAISContext()->Activate(aIO,aMode);
3246 // un Context local est deja ouvert
3247 // Traitement des objets du Context local
3248 if (TheAISContext()->NbSelected()>0 ){
3249 TheAISContext()->UnhilightSelected(Standard_False);
3250 // il y a des objets selected,on les parcourt
3251 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3252 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3255 if (HaveMode(aIO,aMode) ) {
3256 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3257 TheAISContext()->Deactivate(aIO,aMode);
3260 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3261 TheAISContext()->Activate(aIO,aMode);
3267 // il n'y a pas d'objets selected
3268 // tous les objets diplayes sont traites
3269 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3272 Handle(AIS_InteractiveObject) aIO =
3273 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3274 if (!aIO.IsNull()) {
3275 if (HaveMode(aIO,aMode) ) {
3276 di<<" Mode: "<<cmode<<" OFF pour "
3277 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3278 TheAISContext()->Deactivate(aIO,aMode);
3281 di<<" Mode: "<<cmode<<" ON pour"
3282 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3283 TheAISContext()->Activate(aIO,aMode);
3291 else if (HaveToSet && ThereIsName){
3292 Standard_Integer aMode=Draw::Atoi(argv [2]);
3293 Handle(AIS_InteractiveObject) aIO =
3294 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3296 if (!aIO.IsNull()) {
3297 const char *cmode="???";
3300 case 0: cmode = "Shape"; break;
3301 case 1: cmode = "Vertex"; break;
3302 case 2: cmode = "Edge"; break;
3303 case 3: cmode = "Wire"; break;
3304 case 4: cmode = "Face"; break;
3305 case 5: cmode = "Shell"; break;
3306 case 6: cmode = "Solid"; break;
3307 case 7: cmode = "Compound"; break;
3310 if( !TheAISContext()->HasOpenedContext() ) {
3311 TheAISContext()->OpenLocalContext(Standard_False);
3312 // On charge tous les objets de la map
3313 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3315 Handle(AIS_InteractiveObject) aShape=
3316 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3317 if (!aShape.IsNull())
3318 TheAISContext()->Load(aShape,0,Standard_False);
3321 TheAISContext()->Activate(aIO,aMode);
3322 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3326 // un Context local est deja ouvert
3327 if (HaveMode(aIO,aMode) ) {
3328 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3329 TheAISContext()->Deactivate(aIO,aMode);
3332 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3333 TheAISContext()->Activate(aIO,aMode);
3342 //! Auxiliary method to print Interactive Object information
3343 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3344 const Handle(Standard_Transient)& theObject,
3345 Draw_Interpretor& theDI)
3347 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3350 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3354 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3355 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3356 << (theDetected.Contains (anObj) ? " Detected" : " ")
3358 if (anObj->Type() == AIS_KOI_Datum)
3361 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3362 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3363 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3364 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3365 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3366 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3367 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3370 else if (anObj->Type() == AIS_KOI_Shape
3371 && anObj->Signature() == 0)
3373 theDI << " AIS_Shape";
3375 else if (anObj->Type() == AIS_KOI_Relation)
3377 // AIS_Dimention and AIS_Relation
3378 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3379 switch (aRelation->KindOfDimension())
3381 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3382 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3383 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3384 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3385 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3386 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3387 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3388 default: theDI << " UNKNOWN dimension"; break;
3393 theDI << " UserPrs";
3395 theDI << " (" << theObject->DynamicType()->Name() << ")";
3398 //! Print information about locally selected sub-shapes
3399 static void localCtxInfo (Draw_Interpretor& theDI)
3401 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3402 if (!aCtx->HasOpenedContext())
3407 TCollection_AsciiString aPrevName;
3408 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3409 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3411 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3412 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3413 if (aSubShape.IsNull()
3414 || aShapeIO.IsNull()
3415 || !GetMapOfAIS().IsBound1 (aShapeIO))
3420 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3421 TopTools_MapOfShape aFilter;
3422 Standard_Integer aNumber = 0;
3423 const TopoDS_Shape aShape = aShapeIO->Shape();
3424 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3425 anIter.More(); anIter.Next())
3427 if (!aFilter.Add (anIter.Current()))
3429 continue; // filter duplicates
3433 if (!anIter.Current().IsSame (aSubShape))
3438 Standard_CString aShapeName = NULL;
3439 switch (aSubShape.ShapeType())
3441 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3442 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3443 case TopAbs_SOLID: aShapeName = " Solid"; break;
3444 case TopAbs_SHELL: aShapeName = " Shell"; break;
3445 case TopAbs_FACE: aShapeName = " Face"; break;
3446 case TopAbs_WIRE: aShapeName = " Wire"; break;
3447 case TopAbs_EDGE: aShapeName = " Edge"; break;
3448 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3450 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3453 if (aParentName != aPrevName)
3455 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3456 aPrevName = aParentName;
3458 theDI << " " << aShapeName << " #" << aNumber << "\n";
3464 //==============================================================================
3467 //==============================================================================
3468 static Standard_Integer VState (Draw_Interpretor& theDI,
3469 Standard_Integer theArgNb,
3470 Standard_CString* theArgVec)
3472 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3475 std::cerr << "Error: No opened viewer!\n";
3479 TCollection_AsciiString anOption (theArgNb >= 2 ? theArgVec[1] : "");
3480 anOption.LowerCase();
3481 if (anOption == "-detectedEntities"
3482 || anOption == "-entities")
3484 theDI << "Detected entities:\n";
3485 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
3486 for (aSelector->Init(); aSelector->More(); aSelector->Next())
3488 Handle(SelectBasics_SensitiveEntity) anEntity = aSelector->Primitive (0);
3489 Standard_Real aMatchDMin = 0.0;
3490 Standard_Real aMatchDepth = Precision::Infinite();
3491 anEntity->Matches (aSelector->LastPickingArguments(), aMatchDMin, aMatchDepth);
3493 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3494 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3496 const gp_Lin aLine = aSelector->LastPickingArguments().PickLine();
3497 const gp_Pnt aPnt = aLine.Location().Translated (gp_Vec (aLine.Direction()) * aMatchDepth);
3499 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3500 aName.LeftJustify (20, ' ');
3501 char anInfoStr[512];
3502 Sprintf (anInfoStr, " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f", aMatchDepth, aMatchDMin, aPnt.X(), aPnt.Y(), aPnt.Z());
3503 theDI << " " << aName
3505 << " (" << anEntity->DynamicType()->Name() << ")"
3508 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
3509 if (!aBRepOwner.IsNull())
3511 theDI << " Detected Shape: "
3512 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
3516 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
3517 if (!aWire.IsNull())
3519 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
3520 theDI << " Detected Child: "
3521 << aSen->DynamicType()->Name()
3528 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3529 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3531 aDetected.Add (aCtx->DetectedCurrentObject());
3534 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3538 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3540 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3541 if (!GetMapOfAIS().IsBound2 (anObjName))
3543 theDI << anObjName << " doesn't exist!\n";
3547 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3548 TCollection_AsciiString aName = anObjName;
3549 aName.LeftJustify (20, ' ');
3550 theDI << " " << aName << " ";
3551 objInfo (aDetected, anObjTrans, theDI);
3557 if (aCtx->NbCurrents() > 0
3560 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3562 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3563 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3564 aName.LeftJustify (20, ' ');
3565 theDI << aName << " ";
3566 objInfo (aDetected, anObj, theDI);
3572 theDI << "Neutral-point state:\n";
3573 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3574 anObjIter.More(); anObjIter.Next())
3576 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3582 TCollection_AsciiString aName = anObjIter.Key2();
3583 aName.LeftJustify (20, ' ');
3584 theDI << " " << aName << " ";
3585 objInfo (aDetected, anObj, theDI);
3588 localCtxInfo (theDI);
3592 //=======================================================================
3593 //function : PickObjects
3595 //=======================================================================
3596 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3597 const AIS_KindOfInteractive TheType,
3598 const Standard_Integer TheSignature,
3599 const Standard_Integer MaxPick)
3601 Handle(AIS_InteractiveObject) IO;
3602 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3604 // step 1: prepare the data
3606 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3607 TheAISContext()->AddFilter(F1);
3610 // step 2 : wait for the selection...
3611 // Standard_Boolean IsGood (Standard_False);
3612 // Standard_Integer NbPick(0);
3613 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3614 Standard_Integer NbPickFail(0);
3615 Standard_Integer argccc = 5;
3616 const char *bufff[] = { "A", "B", "C","D", "E" };
3617 const char **argvvv = (const char **) bufff;
3620 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3621 while(ViewerMainLoop(argccc,argvvv)){}
3622 Standard_Integer NbStored = TheAISContext()->NbSelected();
3623 if((unsigned int ) NbStored != NbPickGood)
3624 NbPickGood= NbStored;
3627 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3630 // step3 get result.
3632 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3634 Standard_Integer i(0);
3635 for(TheAISContext()->InitSelected();
3636 TheAISContext()->MoreSelected();
3637 TheAISContext()->NextSelected()){
3639 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3640 arr->SetValue(i,IO2);
3645 TheAISContext()->CloseLocalContext(curindex);
3647 return Standard_True;
3651 //=======================================================================
3652 //function : PickObject
3654 //=======================================================================
3655 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3656 const Standard_Integer TheSignature,
3657 const Standard_Integer MaxPick)
3659 Handle(AIS_InteractiveObject) IO;
3660 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3662 // step 1: prepare the data
3665 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3666 TheAISContext()->AddFilter(F1);
3669 // step 2 : wait for the selection...
3670 Standard_Boolean IsGood (Standard_False);
3671 Standard_Integer NbPick(0);
3672 Standard_Integer argccc = 5;
3673 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3674 const char **argvvv = (const char **) bufff;
3677 while(!IsGood && NbPick<= MaxPick){
3678 while(ViewerMainLoop(argccc,argvvv)){}
3679 IsGood = (TheAISContext()->NbSelected()>0) ;
3681 cout<<"Nb Pick :"<<NbPick<<endl;
3685 // step3 get result.
3687 TheAISContext()->InitSelected();
3688 IO = TheAISContext()->SelectedInteractive();
3692 TheAISContext()->CloseLocalContext(curindex);
3696 //=======================================================================
3697 //function : PickShape
3698 //purpose : First Activate the rightmode + Put Filters to be able to
3699 // pick objets that are of type <TheType>...
3700 //=======================================================================
3702 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3703 const Standard_Integer MaxPick)
3706 // step 1: prepare the data
3708 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3709 TopoDS_Shape result;
3711 if(TheType==TopAbs_SHAPE){
3712 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3713 TheAISContext()->AddFilter(F1);
3716 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3717 TheAISContext()->AddFilter(TF);
3718 TheAISContext()->ActivateStandardMode(TheType);
3723 // step 2 : wait for the selection...
3724 Standard_Boolean NoShape (Standard_True);
3725 Standard_Integer NbPick(0);
3726 Standard_Integer argccc = 5;
3727 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3728 const char **argvvv = (const char **) bufff;
3731 while(NoShape && NbPick<= MaxPick){
3732 while(ViewerMainLoop(argccc,argvvv)){}
3733 NoShape = (TheAISContext()->NbSelected()==0) ;
3735 cout<<"Nb Pick :"<<NbPick<<endl;
3738 // step3 get result.
3742 TheAISContext()->InitSelected();
3743 if(TheAISContext()->HasSelectedShape())
3744 result = TheAISContext()->SelectedShape();
3746 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3747 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3752 TheAISContext()->CloseLocalContext(curindex);
3758 //=======================================================================
3759 //function : PickShapes
3761 //=======================================================================
3762 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3763 Handle(TopTools_HArray1OfShape)& thearr,
3764 const Standard_Integer MaxPick)
3767 Standard_Integer Taille = thearr->Length();
3769 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3771 // step 1: prepare the data
3772 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3773 if(TheType==TopAbs_SHAPE){
3774 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3775 TheAISContext()->AddFilter(F1);
3778 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3779 TheAISContext()->AddFilter(TF);
3780 TheAISContext()->ActivateStandardMode(TheType);
3784 // step 2 : wait for the selection...
3786 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3787 Standard_Integer NbPickFail(0);
3788 Standard_Integer argccc = 5;
3789 const char *bufff[] = { "A", "B", "C","D", "E" };
3790 const char **argvvv = (const char **) bufff;
3793 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3794 while(ViewerMainLoop(argccc,argvvv)){}
3795 Standard_Integer NbStored = TheAISContext()->NbSelected();
3796 if((unsigned int ) NbStored != NbPickGood)
3797 NbPickGood= NbStored;
3800 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3803 // step3 get result.
3805 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3807 Standard_Integer i(0);
3808 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3810 if(TheAISContext()->HasSelectedShape())
3811 thearr->SetValue(i,TheAISContext()->SelectedShape());
3813 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3814 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3818 TheAISContext()->CloseLocalContext(curindex);
3819 return Standard_True;
3823 //=======================================================================
3824 //function : VPickShape
3826 //=======================================================================
3827 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3829 TopoDS_Shape PickSh;
3830 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3833 theType = TopAbs_SHAPE;
3835 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3836 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3837 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3838 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3839 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3840 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3841 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3844 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3845 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3847 TCollection_AsciiString name;
3850 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3852 PickSh = ViewerTest::PickShape(theType);
3861 if(!PickSh.IsNull()){
3862 nbOfSub[Standard_Integer(theType)]++;
3864 name += nameType[Standard_Integer(theType)];
3865 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3870 // si on avait une petite methode pour voir si la shape
3871 // est deja dans la Double map, ca eviterait de creer....
3872 DBRep::Set(name.ToCString(),PickSh);
3874 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3875 GetMapOfAIS().Bind(newsh, name);
3876 TheAISContext()->Display(newsh);
3877 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3880 // Plusieurs objets a picker, vite vite vite....
3883 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3884 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3885 if(ViewerTest::PickShapes(theType,arr)){
3886 for(Standard_Integer i=1;i<=NbToPick;i++){
3887 PickSh = arr->Value(i);
3888 if(!PickSh.IsNull()){
3890 nbOfSub[Standard_Integer(theType)]++;
3893 name += nameType[Standard_Integer(theType)];
3894 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3902 DBRep::Set(name.ToCString(),PickSh);
3903 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3904 GetMapOfAIS().Bind(newsh, name);
3905 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3906 TheAISContext()->Display(newsh);
3914 //=======================================================================
3915 //function : list of known objects
3917 //=======================================================================
3918 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3920 // 1234567890 12345678901234567 123456789
3921 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3922 TCollection_AsciiString BlankLine(64,'_');
3923 Standard_Integer i ;
3925 di<<"/n"<<BlankLine.ToCString()<<"\n";
3928 Colum[i].Center(20,' ');
3930 di<<"|"<<Colum[i].ToCString();
3933 di<<BlankLine.ToCString()<<"\n";
3935 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3936 const char ** names = GetTypeNames();
3938 TCollection_AsciiString curstring;
3939 TCollection_AsciiString curcolum[3];
3942 // les objets de type Datum..
3943 curcolum[1]+="Datum";
3945 curcolum[0].Clear();
3946 curcolum[0] += names[i];
3948 curcolum[2].Clear();
3949 curcolum[2]+=TCollection_AsciiString(i+1);
3951 for(Standard_Integer j =0;j<=2;j++){
3952 curcolum[j].Center(20,' ');
3953 di<<"|"<<curcolum[j].ToCString();
3957 di<<BlankLine.ToCString()<<"\n";
3959 // les objets de type shape
3960 curcolum[1].Clear();
3961 curcolum[1]+="Shape";
3962 curcolum[1].Center(20,' ');
3965 curcolum[0].Clear();
3966 curcolum[0] += names[7+i];
3967 curcolum[2].Clear();
3968 curcolum[2]+=TCollection_AsciiString(i);
3970 for(Standard_Integer j =0;j<=2;j++){
3971 curcolum[j].Center(20,' ');
3972 di<<"|"<<curcolum[j].ToCString();
3976 di<<BlankLine.ToCString()<<"\n";
3977 // les IO de type objet...
3978 curcolum[1].Clear();
3979 curcolum[1]+="Object";
3980 curcolum[1].Center(20,' ');
3982 curcolum[0].Clear();
3983 curcolum[0] += names[10+i];
3984 curcolum[2].Clear();
3985 curcolum[2]+=TCollection_AsciiString(i);
3987 for(Standard_Integer j =0;j<=2;j++){
3988 curcolum[j].Center(20,' ');
3989 di<<"|"<<curcolum[j].ToCString();
3993 di<<BlankLine.ToCString()<<"\n";
3994 // les contraintes et dimensions.
3995 // pour l'instant on separe juste contraintes et dimensions...
3996 // plus tard, on detaillera toutes les sortes...
3997 curcolum[1].Clear();
3998 curcolum[1]+="Relation";
3999 curcolum[1].Center(20,' ');
4001 curcolum[0].Clear();
4002 curcolum[0] += names[12+i];
4003 curcolum[2].Clear();
4004 curcolum[2]+=TCollection_AsciiString(i);
4006 for(Standard_Integer j =0;j<=2;j++){
4007 curcolum[j].Center(20,' ');
4008 di<<"|"<<curcolum[j].ToCString();
4012 di<<BlankLine.ToCString()<<"\n";
4019 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4021 if(argc!=2) return 1;
4023 AIS_KindOfInteractive TheType;
4024 Standard_Integer TheSign(-1);
4025 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4028 AIS_ListOfInteractive LIO;
4030 // en attendant l'amelioration ais pour les dimensions...
4032 Standard_Integer dimension_status(-1);
4033 if(TheType==AIS_KOI_Relation){
4034 dimension_status = TheSign ==1 ? 1 : 0;
4038 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4039 Handle(AIS_InteractiveObject) curio;
4040 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4043 if(dimension_status == -1)
4044 TheAISContext()->Erase(curio,Standard_False);
4046 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4047 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4048 (dimension_status==1 && KOD != AIS_KOD_NONE))
4049 TheAISContext()->Erase(curio,Standard_False);
4052 TheAISContext()->UpdateCurrentViewer();
4055 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4057 if(argc!=2) return 1;
4059 AIS_KindOfInteractive TheType;
4060 Standard_Integer TheSign(-1);
4061 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4063 // en attendant l'amelioration ais pour les dimensions...
4065 Standard_Integer dimension_status(-1);
4066 if(TheType==AIS_KOI_Relation){
4067 dimension_status = TheSign ==1 ? 1 : 0;
4071 AIS_ListOfInteractive LIO;
4072 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4073 Handle(AIS_InteractiveObject) curio;
4074 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4076 if(dimension_status == -1)
4077 TheAISContext()->Display(curio,Standard_False);
4079 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4080 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4081 (dimension_status==1 && KOD != AIS_KOD_NONE))
4082 TheAISContext()->Display(curio,Standard_False);
4087 TheAISContext()->UpdateCurrentViewer();
4091 //==============================================================================
4092 //function : VSetTransMode
4094 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4095 //==============================================================================
4097 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4098 // Verification des arguments
4099 if ( a3DView().IsNull() ) {
4100 ViewerTest::ViewerInit();
4101 di << "La commande vinit n'a pas ete appele avant" << "\n";
4104 if ( argc < 3 || argc > 8 ) {
4105 di << argv[0] << " Invalid number of arguments" << "\n";
4109 TCollection_AsciiString shapeName;
4110 shapeName = argv[1];
4111 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4112 Standard_Integer persFlag2 = 0;
4113 Standard_Integer persFlag3 = 0;
4114 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4115 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4116 persFlag2 = Draw::Atoi(argv[3]);
4118 if ( argc == 5 || argc == 8 ) {
4119 persFlag3 = Draw::Atoi(argv[4]);
4122 origin.SetX( Draw::Atof(argv[argc - 3]) );
4123 origin.SetY( Draw::Atof(argv[argc - 2]) );
4124 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4127 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4128 Handle(Standard_Transient) anObj;
4130 anObj = GetMapOfAIS().Find2(shapeName);
4131 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4132 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4133 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4134 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4135 di << argv[0] << " All persistence modifiers were removed" << "\n";
4138 di << argv[0] << " Wrong object type" << "\n";
4141 } else { // Create the AIS_Shape from a name
4142 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4143 if ( !aShape.IsNull() ) {
4144 GetMapOfAIS().Bind( aShape, shapeName );
4145 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4146 TheAISContext()->Display( aShape, Standard_False );
4148 di << argv[0] << " Object not found" << "\n";
4153 // Upadate the screen and redraw the view
4154 TheAISContext()->UpdateCurrentViewer();
4158 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4161 BRep_Builder builder;
4163 BRepTools::Read(shape, s, builder);
4164 DBRep::Set(a[1], shape);
4165 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4166 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4171 //==============================================================================
4172 //function : ViewerTest::Commands
4173 //purpose : Add all the viewer command in the Draw_Interpretor
4174 //==============================================================================
4176 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4178 ViewerTest::ViewerCommands(theCommands);
4179 ViewerTest::RelationCommands(theCommands);
4180 ViewerTest::ObjectCommands(theCommands);
4181 ViewerTest::FilletCommands(theCommands);
4182 ViewerTest::VoxelCommands(theCommands);
4183 ViewerTest::OpenGlCommands(theCommands);
4185 const char *group = "AIS_Display";
4188 theCommands.Add("visos",
4189 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4190 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4191 __FILE__, visos, group);
4193 theCommands.Add("vdisplay",
4194 "vdisplay [-noupdate|-update] [-mutable] name1 [name2] ... [name n]"
4195 "\n\t\t: Displays named objects."
4196 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4197 "\n\t\t: Option -mutable enables optimizations for mutable objects."
4198 __FILE__,VDisplay2,group);
4200 theCommands.Add ("vupdate",
4201 "vupdate name1 [name2] ... [name n]"
4202 "\n\t\t: Updates named objects in interactive context",
4203 __FILE__, VUpdate, group);
4205 theCommands.Add("verase",
4206 "verase [-noupdate|-update] [name1] ... [name n]"
4207 "\n\t\t: Erases selected or named objects."
4208 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
4209 __FILE__, VErase, group);
4211 theCommands.Add("vremove",
4212 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4213 "or vremove [-context] -all to remove all objects"
4214 "\n\t\t: Removes selected or named objects."
4215 "\n\t\t If -context is in arguments, the objects are not deleted"
4216 "\n\t\t from the map of objects and names."
4217 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4218 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4219 __FILE__, VRemove, group);
4221 theCommands.Add("vdonly",
4222 "vdonly [-noupdate|-update] [name1] ... [name n]"
4223 "\n\t\t: Displays only selected or named objects",
4224 __FILE__,VDonly2,group);
4226 theCommands.Add("vdisplayall",
4227 "Displays all erased interactive objects (see vdir and vstate)",
4228 __FILE__,VDisplayAll,group);
4230 theCommands.Add("veraseall",
4231 "Erases all objects displayed in the viewer",
4232 __FILE__, VErase, group);
4234 theCommands.Add("verasetype",
4236 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4237 __FILE__,VEraseType,group);
4239 theCommands.Add("vbounding",
4240 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4241 "\n\t\t: [-print] [-hide]"
4242 "\n\t\t: Temporarily display bounding box of specified Interactive"
4243 "\n\t\t: Objects, or print it to console if -print is specified."
4244 "\n\t\t: Already displayed box might be hidden by -hide option.",
4245 __FILE__,VBounding,group);
4247 theCommands.Add("vdisplaytype",
4248 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4249 __FILE__,VDisplayType,group);
4251 theCommands.Add("vdisplaymode",
4252 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4253 __FILE__,VDispMode,group);
4255 theCommands.Add("verasemode",
4256 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4257 __FILE__,VDispMode,group);
4259 theCommands.Add("vsetdispmode",
4260 "vsetdispmode [name] mode(1,2,..)"
4261 "\n\t\t: Sets display mode for all, selected or named objects.",
4262 __FILE__,VDispMode,group);
4264 theCommands.Add("vunsetdispmode",
4265 "vunsetdispmode [name]"
4266 "\n\t\t: Unsets custom display mode for selected or named objects.",
4267 __FILE__,VDispMode,group);
4269 theCommands.Add("vdir",
4270 "Lists all objects displayed in 3D viewer",
4271 __FILE__,VDir,group);
4273 theCommands.Add("vdump",
4274 #ifdef HAVE_FREEIMAGE
4275 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4276 "\n\t\t: [width Width=0 height Height=0]"
4277 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4279 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4280 "\n\t\t: [width Width=0 height Height=0]"
4281 "\n\t\t: Dumps content of the active view into PPM image file",
4283 __FILE__,VDump,group);
4285 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4286 __FILE__,VSubInt,group);
4288 theCommands.Add("vaspects",
4289 "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4290 "\n\t\t: [-setcolor ColorName] [-unsetcolor]"
4291 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4292 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4293 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4294 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4295 "\n\t\t: Manage presentation properties of all, selected or named objects."
4296 "\n\t\t: When -subshapes is specified than following properties will be"
4297 "\n\t\t: assigned to specified sub-shapes.",
4298 __FILE__,VAspects,group);
4300 theCommands.Add("vsetcolor",
4301 "vsetcolor [-noupdate|-update] [name] ColorName"
4302 "\n\t\t: Sets color for all, selected or named objects."
4303 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4304 __FILE__,VAspects,group);
4306 theCommands.Add("vunsetcolor",
4307 "vunsetcolor [-noupdate|-update] [name]"
4308 "\n\t\t: Resets color for all, selected or named objects."
4309 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4310 __FILE__,VAspects,group);
4312 theCommands.Add("vsettransparency",
4313 "vsettransparency [-noupdate|-update] [name] Coefficient"
4314 "\n\t\t: Sets transparency for all, selected or named objects."
4315 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4316 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4317 __FILE__,VAspects,group);
4319 theCommands.Add("vunsettransparency",
4320 "vunsettransparency [-noupdate|-update] [name]"
4321 "\n\t\t: Resets transparency for all, selected or named objects."
4322 "\n\t\t: Alias for vaspects -unsettransp [name].",
4323 __FILE__,VAspects,group);
4325 theCommands.Add("vsetmaterial",
4326 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4327 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4328 __FILE__,VAspects,group);
4330 theCommands.Add("vunsetmaterial",
4331 "vunsetmaterial [-noupdate|-update] [name]"
4332 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4333 __FILE__,VAspects,group);
4335 theCommands.Add("vsetwidth",
4336 "vsetwidth [-noupdate|-update] [name] width(0->10)"
4337 "\n\t\t: Alias for vaspects -setwidth [name] width.",
4338 __FILE__,VAspects,group);
4340 theCommands.Add("vunsetwidth",
4341 "vunsetwidth [-noupdate|-update] [name]"
4342 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4343 __FILE__,VAspects,group);
4345 theCommands.Add("vsetinteriorstyle",
4346 "vsetinteriorstyle [-noupdate|-update] [name] style"
4347 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4348 __FILE__,VSetInteriorStyle,group);
4350 theCommands.Add("vardis",
4351 "vardis : display activeareas",
4352 __FILE__,VDispAreas,group);
4354 theCommands.Add("varera",
4355 "varera : erase activeareas",
4356 __FILE__,VClearAreas,group);
4358 theCommands.Add("vsensdis",
4359 "vardisp : display active entities",
4360 __FILE__,VDispSensi,group);
4361 theCommands.Add("vsensera",
4362 "vardisp : erase active entities",
4363 __FILE__,VClearSensi,group);
4365 theCommands.Add("vselprecision",
4366 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4367 __FILE__,VSelPrecision,group);
4369 theCommands.Add("vperf",
4370 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4371 __FILE__,VPerf,group);
4373 theCommands.Add("vanimation",
4374 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4375 __FILE__,VAnimation,group);
4377 theCommands.Add("vsetshading",
4378 "vsetshading : vsetshading name Quality(default=0.0008) ",
4379 __FILE__,VShading,group);
4381 theCommands.Add("vunsetshading",
4382 "vunsetshading :vunsetshading name ",
4383 __FILE__,VShading,group);
4385 theCommands.Add ("vtexture",
4386 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4387 " [-scale u v] [-scale off]\n"
4388 " [-origin u v] [-origin off]\n"
4389 " [-repeat u v] [-repeat off]\n"
4390 " [-modulate {on | off}]"
4392 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4393 " specifying one of the predefined textures.\n"
4394 " The options are: \n"
4395 " -scale u v : enable texture scaling and set scale factors\n"
4396 " -scale off : disable texture scaling\n"
4397 " -origin u v : enable texture origin positioning and set the origin\n"
4398 " -origin off : disable texture origin positioning\n"
4399 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4400 " -repeat off : disable texture repeat\n"
4401 " -modulate {on | off} : enable or disable texture modulation\n"
4402 " -default : sets texture mapping default parameters\n"
4403 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4404 "or 'vtexture NameOfShape ?' to list available textures\n",
4405 __FILE__, VTexture, group);
4407 theCommands.Add("vtexscale",
4408 "'vtexscale NameOfShape ScaleU ScaleV' \n \
4409 or 'vtexscale NameOfShape ScaleUV' \n \
4410 or 'vtexscale NameOfShape' to disable scaling\n ",
4411 __FILE__,VTexture,group);
4413 theCommands.Add("vtexorigin",
4414 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4415 or 'vtexorigin NameOfShape UVOrigin' \n \
4416 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4417 __FILE__,VTexture,group);
4419 theCommands.Add("vtexrepeat",
4420 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
4421 or 'vtexrepeat NameOfShape UVRepeat \n \
4422 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4425 theCommands.Add("vtexdefault",
4426 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4429 theCommands.Add("vsetam",
4430 "vsetActivatedModes: vsetam mode(1->7) ",
4431 __FILE__,VActivatedMode,group);
4433 theCommands.Add("vunsetam",
4434 "vunsetActivatedModes: vunsetam ",
4435 __FILE__,VActivatedMode,group);
4437 theCommands.Add("vstate",
4438 "vstate [-entities] [name1] ... [nameN]"
4439 "\n\t\t: Reports show/hidden state for selected or named objects"
4440 "\n\t\t: -entities - print low-level information about detected entities",
4441 __FILE__,VState,group);
4443 theCommands.Add("vpickshapes",
4444 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4445 __FILE__,VPickShape,group);
4447 theCommands.Add("vtypes",
4448 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4451 theCommands.Add("vsettransmode",
4452 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4453 __FILE__,VSetTransMode,group);
4455 theCommands.Add("vr", "vr : reading of the shape",
4456 __FILE__,vr, group);
4460 //=====================================================================
4461 //========================= for testing Draft and Rib =================
4462 //=====================================================================
4463 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4464 #include <DBRep.hxx>
4465 #include <TopoDS_Face.hxx>
4466 #include <gp_Pln.hxx>
4467 #include <AIS_KindOfSurface.hxx>
4468 #include <BRepOffsetAPI_DraftAngle.hxx>
4469 #include <Precision.hxx>
4470 #include <BRepAlgo.hxx>
4471 #include <OSD_Environment.hxx>
4472 #include <DrawTrSurf.hxx>
4473 //#include <DbgTools.hxx>
4474 //#include <FeatAlgo_MakeLinearForm.hxx>
4479 //=======================================================================
4480 //function : IsValid
4482 //=======================================================================
4483 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4484 const TopoDS_Shape& theResult,
4485 const Standard_Boolean closedSolid,
4486 const Standard_Boolean GeomCtrl)
4488 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4489 TCollection_AsciiString checkValid = check.Value();
4490 Standard_Boolean ToCheck = Standard_True;
4491 if (!checkValid.IsEmpty()) {
4493 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4495 if ( checkValid=="true" || checkValid=="TRUE" ) {
4496 ToCheck= Standard_False;
4500 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4503 Standard_Boolean IsValid = Standard_True;
4505 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4510 //===============================================================================
4511 // TDraft : test draft, uses AIS Viewer
4512 // Solid Face Plane Angle Reverse
4513 //===============================================================================
4514 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4516 if (argc < 5) return 1;
4517 // argv[1] - TopoDS_Shape Solid
4518 // argv[2] - TopoDS_Shape Face
4519 // argv[3] - TopoDS_Shape Plane
4520 // argv[4] - Standard_Real Angle
4521 // argv[5] - Standard_Integer Reverse
4523 // Sprintf(prefix, argv[1]);
4524 Standard_Real anAngle = 0;
4525 Standard_Boolean Rev = Standard_False;
4526 Standard_Integer rev = 0;
4527 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4528 TopoDS_Shape face = GetShapeFromName(argv[2]);
4529 TopoDS_Face Face = TopoDS::Face(face);
4530 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4531 if (Plane.IsNull ()) {
4532 di << "TEST : Plane is NULL" << "\n";
4535 anAngle = Draw::Atof(argv[4]);
4536 anAngle = 2*M_PI * anAngle / 360.0;
4538 Handle( Geom_Surface )aSurf;
4539 AIS_KindOfSurface aSurfType;
4540 Standard_Real Offset;
4542 if(argc > 4) { // == 5
4543 rev = Draw::Atoi(argv[5]);
4544 Rev = (rev)? Standard_True : Standard_False;
4547 TopoDS_Face face2 = TopoDS::Face(Plane);
4548 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4550 di << "TEST : Can't find plane" << "\n";
4554 aDir = aPln.Axis().Direction();
4557 if (Plane.Orientation() == TopAbs_REVERSED)
4559 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4561 BRepOffsetAPI_DraftAngle Draft (Solid);
4563 if(Abs(anAngle)< Precision::Angular()) {
4564 di << "TEST : NULL angle" << "\n";
4567 if(Rev) anAngle = - anAngle;
4568 Draft.Add (Face, aDir, anAngle, aPln);
4570 if (!Draft.IsDone()) {
4571 di << "TEST : Draft Not DONE " << "\n";
4574 TopTools_ListOfShape Larg;
4576 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4577 di << "TEST : DesignAlgo returns Not valid" << "\n";
4581 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4582 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4584 if ( !ais.IsNull() ) {
4585 ais->SetColor(DEFAULT_COLOR);
4586 ais->SetMaterial(DEFAULT_MATERIAL);
4587 // Display the AIS_Shape without redraw
4588 Ctx->Display(ais, Standard_False);
4590 const char *Name = "draft1";
4591 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4593 Handle(AIS_InteractiveObject) an_object =
4594 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4595 if (!an_object.IsNull()) {
4596 Ctx->Remove(an_object,
4598 GetMapOfAIS().UnBind2(Name) ;
4601 GetMapOfAIS().Bind(ais, Name);
4602 // DBRep::Set("draft", ais->Shape());
4604 Ctx->Display(ais, Standard_True);
4608 //==============================================================================
4609 //function : splitParameter
4610 //purpose : Split parameter string to parameter name and parameter value
4611 //==============================================================================
4612 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4613 TCollection_AsciiString& theName,
4614 TCollection_AsciiString& theValue)
4616 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4618 if (aParamNameEnd == 0)
4620 return Standard_False;
4623 TCollection_AsciiString aString (theString);
4624 if (aParamNameEnd != 0)
4626 theValue = aString.Split (aParamNameEnd);
4627 aString.Split (aString.Length() - 1);
4631 return Standard_True;
4634 //============================================================================
4636 //============================================================================
4637 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4640 DrawTrSurf::BasicCommands(theCommands);
4641 const char* group = "Check Features Operations commands";
4643 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4645 &TDraft,group); //Draft_Modification
4648 //==============================================================================
4649 // ViewerTest::Factory
4650 //==============================================================================
4651 void ViewerTest::Factory(Draw_Interpretor& theDI)
4653 // definition of Viewer Command
4654 ViewerTest::Commands(theDI);
4655 ViewerTest::AviCommands(theDI);
4658 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4662 // Declare entry point PLUGINFACTORY