1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by Robert Coublanc [nov 16-17-18 1998]
19 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 // ViewerTest_ObjectCommands.cxx
21 // ViewerTest_RelationCommands.cxx
22 // -add Functions and commands for interactive selection of shapes and objects
23 // in AIS Viewers. (PickShape(s), PickObject(s),
25 #include <Standard_Stream.hxx>
27 #include <ViewerTest.hxx>
28 #include <TopLoc_Location.hxx>
29 #include <TopTools_HArray1OfShape.hxx>
30 #include <TColStd_HArray1OfTransient.hxx>
31 #include <TColStd_SequenceOfAsciiString.hxx>
32 #include <OSD_Timer.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <Geom_Axis1Placement.hxx>
35 #include <gp_Trsf.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <StdSelect_ShapeTypeFilter.hxx>
40 #include <AIS_Drawer.hxx>
41 #include <AIS_InteractiveObject.hxx>
42 #include <AIS_Trihedron.hxx>
43 #include <AIS_Axis.hxx>
44 #include <AIS_Relation.hxx>
45 #include <AIS_TypeFilter.hxx>
46 #include <AIS_SignatureFilter.hxx>
47 #include <AIS_LocalContext.hxx>
48 #include <AIS_ListOfInteractive.hxx>
49 #include <AIS_ListIteratorOfListOfInteractive.hxx>
50 #include <Aspect_InteriorStyle.hxx>
51 #include <Aspect_Window.hxx>
52 #include <Graphic3d_AspectFillArea3d.hxx>
53 #include <Graphic3d_AspectLine3d.hxx>
54 #include <Graphic3d_TextureRoot.hxx>
55 #include <Image_AlienPixMap.hxx>
56 #include <Prs3d_ShadingAspect.hxx>
57 #include <Prs3d_IsoAspect.hxx>
58 #include <TopTools_MapOfShape.hxx>
68 #include <Draw_Interpretor.hxx>
69 #include <TCollection_AsciiString.hxx>
70 #include <Draw_PluginMacro.hxx>
71 #include <ViewerTest.hxx>
73 // avoid warnings on 'extern "C"' functions returning C++ classes
75 #define _CRT_SECURE_NO_DEPRECATE
76 #pragma warning(4:4190)
77 #pragma warning (disable:4996)
80 #include <NIS_InteractiveContext.hxx>
81 #include <NIS_Triangulated.hxx>
82 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
84 #include <Quantity_Color.hxx>
85 #include <Quantity_NameOfColor.hxx>
87 #include <Graphic3d_NameOfMaterial.hxx>
89 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
90 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
92 enum ViewerTest_RedrawMode
94 ViewerTest_RM_Auto = -1,
95 ViewerTest_RM_RedrawForce,
96 ViewerTest_RM_RedrawSuppress
99 //! Auxiliary method to parse redraw mode argument
100 static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
101 ViewerTest_RedrawMode& theMode)
103 TCollection_AsciiString anArgCase (theArg);
104 anArgCase.LowerCase();
105 if (anArgCase == "-update"
106 || anArgCase == "-redraw")
108 theMode = ViewerTest_RM_RedrawForce;
109 return Standard_True;
111 else if (anArgCase == "-noupdate"
112 || anArgCase == "-noredraw")
114 theMode = ViewerTest_RM_RedrawSuppress;
115 return Standard_True;
117 return Standard_False;
120 //=======================================================================
121 //function : GetColorFromName
122 //purpose : get the Quantity_NameOfColor from a string
123 //=======================================================================
125 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
127 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
129 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
130 if (strcasecmp (theName, aColorName) == 0)
132 return Quantity_NameOfColor (anIter);
136 return DEFAULT_COLOR;
139 //=======================================================================
140 //function : GetMaterialFromName
141 //purpose : get the Graphic3d_NameOfMaterial from a string
142 //=======================================================================
144 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
146 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
148 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
149 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
150 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
151 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
152 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
153 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
154 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
155 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
156 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
157 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
158 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
159 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
160 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
161 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
162 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
163 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
164 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
165 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
166 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
171 //=======================================================================
172 //function : GetTypeNames
174 //=======================================================================
175 static const char** GetTypeNames()
177 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
178 "Shape","ConnectedShape","MultiConn.Shape",
179 "ConnectedInter.","MultiConn.",
180 "Constraint","Dimension"};
181 static const char** ThePointer = names;
185 //=======================================================================
186 //function : GetTypeAndSignfromString
188 //=======================================================================
189 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
191 const char ** thefullnames = GetTypeNames();
192 Standard_Integer index(-1);
194 for(Standard_Integer i=0;i<=13 && index==-1;i++)
195 if(!strcasecmp(name,thefullnames[i]))
199 TheType = AIS_KOI_None;
205 TheType = AIS_KOI_Datum;
209 TheType = AIS_KOI_Shape;
213 TheType = AIS_KOI_Object;
217 TheType = AIS_KOI_Relation;
226 #include <Draw_Interpretor.hxx>
228 #include <Draw_Appli.hxx>
232 #include <TCollection_AsciiString.hxx>
233 #include <V3d_Viewer.hxx>
234 #include <V3d_View.hxx>
237 #include <AIS_InteractiveContext.hxx>
238 #include <AIS_Shape.hxx>
239 #include <AIS_TexturedShape.hxx>
240 #include <AIS_DisplayMode.hxx>
241 #include <TColStd_MapOfInteger.hxx>
242 #include <AIS_MapOfInteractive.hxx>
243 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
244 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
245 #include <ViewerTest_EventManager.hxx>
247 #include <TopoDS_Solid.hxx>
248 #include <BRepTools.hxx>
249 #include <BRep_Builder.hxx>
250 #include <TopAbs_ShapeEnum.hxx>
252 #include <TopoDS.hxx>
253 #include <BRep_Tool.hxx>
256 #include <Draw_Window.hxx>
257 #include <AIS_ListIteratorOfListOfInteractive.hxx>
258 #include <AIS_ListOfInteractive.hxx>
259 #include <AIS_DisplayMode.hxx>
260 #include <TopTools_ListOfShape.hxx>
261 #include <BRepOffsetAPI_MakeThickSolid.hxx>
262 #include <BRepOffset.hxx>
264 //==============================================================================
265 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
266 //==============================================================================
267 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
268 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
273 //==============================================================================
274 //function : VDisplayAISObject
275 //purpose : register interactive object in the map of AIS objects;
276 // if other object with such name already registered, it will be kept
277 // or replaced depending on value of <theReplaceIfExists>,
278 // if "true" - the old object will be cleared from AIS context;
279 // returns Standard_True if <theAISObj> registered in map;
280 //==============================================================================
281 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
282 const Handle(AIS_InteractiveObject)& theAISObj,
283 Standard_Boolean theReplaceIfExists = Standard_True)
285 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
286 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
287 if (aContextAIS.IsNull())
289 std::cout << "AIS context is not available.\n";
290 return Standard_False;
293 if (aMap.IsBound2 (theName))
295 if (!theReplaceIfExists)
297 std::cout << "Other interactive object has been already "
298 << "registered with name: " << theName << ".\n"
299 << "Please use another name.\n";
300 return Standard_False;
303 // stop displaying object
304 Handle(AIS_InteractiveObject) anOldObj =
305 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
307 if (!anOldObj.IsNull())
308 aContextAIS->Clear (anOldObj, Standard_True);
310 // remove name and old object from map
311 aMap.UnBind2 (theName);
314 if (theAISObj.IsNull())
316 // object with specified name already unbound
317 return Standard_True;
320 // unbind AIS object if was bound with another name
321 aMap.UnBind1 (theAISObj);
323 // can be registered without rebinding
324 aMap.Bind (theAISObj, theName);
325 aContextAIS->Display (theAISObj, Standard_True);
326 return Standard_True;
329 static TColStd_MapOfInteger theactivatedmodes(8);
330 static TColStd_ListOfTransient theEventMgrs;
332 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
333 const Handle(AIS_InteractiveContext)& Ctx)
335 theEventMgrs.Clear();
336 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
339 static Handle(V3d_View)& a3DView()
341 static Handle(V3d_View) Viou;
346 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
347 static Handle(AIS_InteractiveContext) aContext;
351 const Handle(V3d_View)& ViewerTest::CurrentView()
355 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
360 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
362 static Handle(NIS_InteractiveContext) aContext;
363 if (aContext.IsNull()) {
364 aContext = new NIS_InteractiveContext;
365 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
370 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
372 return TheAISContext();
375 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
377 TheAISContext() = aCtx;
378 ViewerTest::ResetEventManager();
381 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
383 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
386 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
388 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
392 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
393 theEventMgrs.Prepend(EM);
396 void ViewerTest::UnsetEventManager()
398 theEventMgrs.RemoveFirst();
402 void ViewerTest::ResetEventManager()
404 const Handle(NIS_View) aView =
405 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
406 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
409 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
411 Handle(ViewerTest_EventManager) EM;
412 if(theEventMgrs.IsEmpty()) return EM;
413 Handle(Standard_Transient) Tr = theEventMgrs.First();
414 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
418 //=======================================================================
419 //function : Get Context and active view
421 //=======================================================================
422 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
423 Handle(V3d_View)& theView)
425 theCtx = ViewerTest::GetAISContext();
426 theView = ViewerTest::CurrentView();
430 std::cout << "Error: cannot find an active view!\n";
431 return Standard_False;
433 return Standard_True;
436 //==============================================================================
437 //function : GetShapeFromName
438 //purpose : Compute an Shape from a draw variable or a file name
439 //==============================================================================
441 static TopoDS_Shape GetShapeFromName(const char* name)
443 TopoDS_Shape S = DBRep::Get(name);
446 BRep_Builder aBuilder;
447 BRepTools::Read( S, name, aBuilder);
453 //==============================================================================
454 //function : GetAISShapeFromName
455 //purpose : Compute an AIS_Shape from a draw variable or a file name
456 //==============================================================================
457 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
459 Handle(AIS_Shape) retsh;
461 if(GetMapOfAIS().IsBound2(name)){
462 const Handle(AIS_InteractiveObject) IO =
463 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
465 if(IO->Type()==AIS_KOI_Shape) {
466 if(IO->Signature()==0){
467 retsh = *((Handle(AIS_Shape)*)&IO);
470 cout << "an Object which is not an AIS_Shape "
471 "already has this name!!!"<<endl;
478 TopoDS_Shape S = GetShapeFromName(name);
480 retsh = new AIS_Shape(S);
486 //==============================================================================
488 //purpose : Remove all the object from the viewer
489 //==============================================================================
490 void ViewerTest::Clear()
492 if ( !a3DView().IsNull() ) {
493 if (TheAISContext()->HasOpenedContext())
494 TheAISContext()->CloseLocalContext();
495 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
496 while ( it.More() ) {
497 cout << "Remove " << it.Key2() << endl;
498 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
499 const Handle(AIS_InteractiveObject) anObj =
500 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
501 TheAISContext()->Remove(anObj,Standard_False);
502 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
503 const Handle(NIS_InteractiveObject) anObj =
504 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
505 TheNISContext()->Remove(anObj);
509 TheAISContext()->UpdateCurrentViewer();
510 // TheNISContext()->UpdateViews();
511 GetMapOfAIS().Clear();
515 //==============================================================================
516 //function : StandardModesActivation
517 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
519 //==============================================================================
520 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
522 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
524 if (TheAISContext()->HasOpenedContext())
525 aContext->CloseLocalContext();
528 if(!aContext->HasOpenedContext()) {
529 // To unhilight the preselected object
530 aContext->UnhilightCurrents(Standard_False);
531 // Open a local Context in order to be able to select subshape from
532 // the selected shape if any or for all if there is no selection
533 if (!aContext->FirstCurrentObject().IsNull()){
534 aContext->OpenLocalContext(Standard_False);
536 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
537 aContext->Load( aContext->Current(),-1,Standard_True);
541 aContext->OpenLocalContext();
544 const char *cmode="???";
547 case 0: cmode = "Shape"; break;
548 case 1: cmode = "Vertex"; break;
549 case 2: cmode = "Edge"; break;
550 case 3: cmode = "Wire"; break;
551 case 4: cmode = "Face"; break;
552 case 5: cmode = "Shell"; break;
553 case 6: cmode = "Solid"; break;
554 case 7: cmode = "Compsolid"; break;
555 case 8: cmode = "Compound"; break;
558 if(theactivatedmodes.Contains(mode))
560 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
561 theactivatedmodes.Remove(mode);
562 cout<<"Mode "<< cmode <<" OFF"<<endl;
566 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
567 theactivatedmodes.Add(mode);
568 cout<<"Mode "<< cmode << " ON" << endl;
573 //==============================================================================
574 //function : CopyIsoAspect
575 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
576 //==============================================================================
577 static Handle(Prs3d_IsoAspect) CopyIsoAspect
578 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
579 const Standard_Integer theNbIsos)
581 Quantity_Color aColor;
582 Aspect_TypeOfLine aType;
583 Standard_Real aWidth;
585 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
587 Handle(Prs3d_IsoAspect) aResult =
588 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
593 //==============================================================================
595 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
596 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
597 //==============================================================================
598 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
600 if (TheAISContext().IsNull()) {
601 di << argv[0] << " Call 'vinit' before!\n";
606 di << "Current number of isos : " <<
607 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
608 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
609 di << "IsoOnPlane mode is " <<
610 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
615 Standard_Integer aLastInd = argc - 1;
616 Standard_Boolean isChanged = Standard_False;
617 Standard_Integer aNbUIsos = 0;
618 Standard_Integer aNbVIsos = 0;
621 Standard_Boolean isIsoOnPlane = Standard_False;
623 if (strcmp(argv[aLastInd], "1") == 0) {
624 isIsoOnPlane = Standard_True;
625 isChanged = Standard_True;
626 } else if (strcmp(argv[aLastInd], "0") == 0) {
627 isIsoOnPlane = Standard_False;
628 isChanged = Standard_True;
632 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
633 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
636 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
637 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
639 TheAISContext()->IsoOnPlane(isIsoOnPlane);
642 // If there are no shapes provided set the default numbers.
643 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
644 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
651 for (i = 1; i <= aLastInd; i++) {
652 TCollection_AsciiString name(argv[i]);
653 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
656 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
657 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
658 const Handle(AIS_InteractiveObject) aShape =
659 Handle(AIS_InteractiveObject)::DownCast (anObj);
660 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
661 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
662 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
665 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
666 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
667 TheAISContext()->SetLocalAttributes
668 (aShape, CurDrawer, Standard_False);
669 TheAISContext()->Redisplay(aShape);
671 di << "Number of isos for " << argv[i] << " : "
672 << aUIso->Number() << " " << aVIso->Number() << "\n";
675 di << argv[i] << ": Not an AIS interactive object!\n";
678 di << argv[i] << ": Use 'vdisplay' before\n";
683 TheAISContext()->UpdateCurrentViewer();
689 //==============================================================================
690 //function : VDispAreas,VDispSensitive,...
692 //==============================================================================
693 static Standard_Integer VDispAreas (Draw_Interpretor& ,
694 Standard_Integer theArgNb,
699 std::cout << "Error: wrong syntax!\n";
703 Handle(AIS_InteractiveContext) aCtx;
704 Handle(V3d_View) aView;
705 if (!getCtxAndView (aCtx, aView))
710 aCtx->DisplayActiveAreas (aView);
713 static Standard_Integer VClearAreas (Draw_Interpretor& ,
714 Standard_Integer theArgNb,
719 std::cout << "Error: wrong syntax!\n";
723 Handle(AIS_InteractiveContext) aCtx;
724 Handle(V3d_View) aView;
725 if (!getCtxAndView (aCtx, aView))
730 aCtx->ClearActiveAreas (aView);
734 static Standard_Integer VDispSensi (Draw_Interpretor& ,
735 Standard_Integer theArgNb,
740 std::cout << "Error: wrong syntax!\n";
744 Handle(AIS_InteractiveContext) aCtx;
745 Handle(V3d_View) aView;
746 if (!getCtxAndView (aCtx, aView))
751 aCtx->DisplayActiveSensitive (aView);
756 static Standard_Integer VClearSensi (Draw_Interpretor& ,
757 Standard_Integer theArgNb,
762 std::cout << "Error: wrong syntax!\n";
766 Handle(AIS_InteractiveContext) aCtx;
767 Handle(V3d_View) aView;
768 if (!getCtxAndView (aCtx, aView))
772 aCtx->ClearActiveSensitive (aView);
776 //==============================================================================
778 //purpose : To list the displayed object with their attributes
779 //==============================================================================
780 static int VDir (Draw_Interpretor& theDI,
784 if (!a3DView().IsNull())
789 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
790 anIter.More(); anIter.Next())
792 theDI << "\t" << anIter.Key2().ToCString() << "\n";
797 //==============================================================================
798 //function : VSelPrecision
799 //purpose : To set the selection precision mode and tolerance value
800 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
801 // value (integer number of pixel for window mode, double value of
802 // sensitivity for view mode). Without arguments the function just
803 // prints the current precision mode and the corresponding tolerance.
804 //==============================================================================
805 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
809 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
813 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
814 if( aContext.IsNull() )
819 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
820 if( aMode == StdSelect_SM_WINDOW )
822 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
823 di << "Precision mode : 0 (window)\n";
824 di << "Pixel tolerance : " << aPixelTolerance << "\n";
826 else if( aMode == StdSelect_SM_VIEW )
828 Standard_Real aSensitivity = aContext->Sensitivity();
829 di << "Precision mode : 1 (view)\n";
830 di << "Sensitivity : " << aSensitivity << "\n";
835 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
836 aContext->SetSensitivityMode( aMode );
839 if( aMode == StdSelect_SM_WINDOW )
841 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
842 aContext->SetPixelTolerance( aPixelTolerance );
844 else if( aMode == StdSelect_SM_VIEW )
846 Standard_Real aSensitivity = Draw::Atof( argv[2] );
847 aContext->SetSensitivity( aSensitivity );
854 //==============================================================================
856 //purpose : To dump the active view snapshot to image file
857 //==============================================================================
858 static Standard_Integer VDump (Draw_Interpretor& theDI,
859 Standard_Integer theArgNb,
860 Standard_CString* theArgVec)
864 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
868 Standard_Integer anArgIter = 1;
869 Standard_CString aFilePath = theArgVec[anArgIter++];
870 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
871 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
872 Standard_Integer aWidth = 0;
873 Standard_Integer aHeight = 0;
874 for (; anArgIter < theArgNb; ++anArgIter)
876 TCollection_AsciiString anArg (theArgVec[anArgIter]);
880 aBufferType = Graphic3d_BT_RGBA;
882 else if (anArg == "rgb")
884 aBufferType = Graphic3d_BT_RGB;
886 else if (anArg == "depth")
888 aBufferType = Graphic3d_BT_Depth;
890 else if (anArg == "l"
893 aStereoOpts = V3d_SDO_LEFT_EYE;
895 else if (anArg == "r"
898 aStereoOpts = V3d_SDO_RIGHT_EYE;
900 else if (anArg == "mono")
902 aStereoOpts = V3d_SDO_MONO;
904 else if (anArg == "w"
909 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
912 else if (++anArgIter >= theArgNb)
914 std::cout << "Error: integer value is expected right after 'width'\n";
917 aWidth = Draw::Atoi (theArgVec[anArgIter]);
919 else if (anArg == "h"
920 || anArg == "height")
924 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
927 if (++anArgIter >= theArgNb)
929 std::cout << "Error: integer value is expected right after 'height'\n";
932 aHeight = Draw::Atoi (theArgVec[anArgIter]);
934 else if (anArg.IsIntegerValue())
936 // compatibility with old syntax
940 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
943 else if (++anArgIter >= theArgNb)
945 std::cout << "Error: height value is expected right after width\n";
948 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
949 aHeight = Draw::Atoi (theArgVec[anArgIter]);
953 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
957 if ((aWidth <= 0 && aHeight > 0)
958 || (aWidth > 0 && aHeight <= 0))
960 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
964 Handle(V3d_View) aView = ViewerTest::CurrentView();
967 std::cout << "Error: cannot find an active view!\n";
971 if (aWidth <= 0 || aHeight <= 0)
973 if (aStereoOpts != V3d_SDO_MONO)
975 aView->Window()->Size (aWidth, aHeight);
979 if (!aView->Dump (aFilePath, aBufferType))
981 theDI << "Fail: view dump failed!\n";
987 Image_AlienPixMap aPixMap;
988 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
990 theDI << "Fail: view dump failed!\n";
994 if (aPixMap.SizeX() != Standard_Size(aWidth)
995 || aPixMap.SizeY() != Standard_Size(aHeight))
997 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
998 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
1000 if (!aPixMap.Save (aFilePath))
1002 theDI << "Fail: image can not be saved!\n";
1008 //==============================================================================
1009 //function : Displays,Erase...
1012 //==============================================================================
1013 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1014 const Standard_Integer Mode,
1015 const Standard_Integer TypeOfOperation,
1016 const Standard_Boolean Upd)
1018 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1020 switch(TypeOfOperation){
1022 Ctx->Display(IO,Mode,Upd);
1030 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1032 Ctx->SetDisplayMode(IO,Mode,Upd);
1037 Ctx->SetDisplayMode(0,Upd);
1039 Ctx->UnsetDisplayMode(IO,Upd);
1046 //=======================================================================
1049 //=======================================================================
1050 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1053 TCollection_AsciiString name;
1056 // display others presentations
1057 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1058 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1059 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1060 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1062 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1064 //unset displaymode.. comportement particulier...
1065 if(TypeOfOperation==4){
1067 if(Ctx->NbCurrents()==0 ||
1068 Ctx->NbSelected()==0){
1069 Handle(AIS_InteractiveObject) IO;
1070 VwrTst_DispErase(IO,-1,4,Standard_False);
1072 else if(!Ctx->HasOpenedContext()){
1073 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1074 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1077 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1078 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1079 Ctx->UpdateCurrentViewer();
1082 Handle(AIS_InteractiveObject) IO;
1084 if(GetMapOfAIS().IsBound2(name)){
1085 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1087 VwrTst_DispErase(IO,-1,4,Standard_True);
1092 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1093 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1094 Handle(AIS_InteractiveObject) IO;
1095 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1097 if(!Ctx->HasOpenedContext()){
1098 // set/unset display mode sur le Contexte...
1099 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1100 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1102 Ctx->UpdateCurrentViewer();
1105 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1106 Ctx->Display(Ctx->Interactive(),Dmode);
1110 Handle(AIS_InteractiveObject) IO;
1112 if(GetMapOfAIS().IsBound2(name))
1113 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1115 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1121 //=======================================================================
1124 //=======================================================================
1125 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1127 if(argc==1) return 1;
1128 Standard_Integer On = Draw::Atoi(argv[1]);
1129 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1133 if(!Ctx->HasOpenedContext()){
1134 di<<"sub intensite ";
1137 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1138 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1140 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1142 di <<"passage dans off"<<"\n";
1143 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1148 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1150 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1152 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1155 Ctx->UpdateCurrentViewer();
1158 Handle(AIS_InteractiveObject) IO;
1159 TCollection_AsciiString name = argv[2];
1160 if(GetMapOfAIS().IsBound2(name)){
1161 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1164 Ctx->SubIntensityOn(IO);
1166 Ctx->SubIntensityOff(IO);
1174 //==============================================================================
1175 //function : VColor2
1177 //purpose : change the color of a selected or named or displayed shape
1178 //Draw arg : vcolor2 [name] color
1179 //==============================================================================
1180 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1183 Standard_Boolean ThereIsCurrent;
1184 Standard_Boolean ThereIsArgument;
1185 Standard_Boolean IsBound = Standard_False ;
1187 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1189 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1190 ThereIsArgument = (argc != 2);
1193 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1194 ThereIsArgument = (argc == 2);
1197 if ( !a3DView().IsNull() ) {
1198 TCollection_AsciiString name;
1199 if (ThereIsArgument) {
1201 IsBound= GetMapOfAIS().IsBound2(name);
1203 if (TheAISContext()->HasOpenedContext())
1204 TheAISContext()->CloseLocalContext();
1206 // On set le Booleen There is current
1207 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1208 else ThereIsCurrent =Standard_False;
1210 //=======================================================================
1211 // Il y a un argument
1212 //=======================================================================
1213 if ( ThereIsArgument && IsBound ) {
1214 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1215 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1216 Handle(AIS_InteractiveObject) ashape =
1217 Handle(AIS_InteractiveObject)::DownCast (anObj);
1220 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1222 di << "HaveToSet 0\n";
1226 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1228 TheAISContext()->UnsetColor(ashape);
1229 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1230 Handle(NIS_Triangulated) ashape =
1231 Handle(NIS_Triangulated)::DownCast (anObj);
1232 if (!ashape.IsNull())
1233 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1238 //=======================================================================
1239 // Il n'y a pas d'arguments
1240 // Mais un ou plusieurs objets on des current representation
1241 //=======================================================================
1242 if (ThereIsCurrent && !ThereIsArgument) {
1243 for (TheAISContext() -> InitCurrent() ;
1244 TheAISContext() -> MoreCurrent() ;
1245 TheAISContext() ->NextCurrent() )
1247 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1248 if (ashape.IsNull())
1252 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1254 di << "HaveToSet 0\n";
1257 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1259 TheAISContext()->UnsetColor(ashape,Standard_False);
1262 TheAISContext()->UpdateCurrentViewer();
1265 //=======================================================================
1266 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1267 // on impose a tous les objets du viewer la couleur passee
1268 //=======================================================================
1269 else if (!ThereIsCurrent && !ThereIsArgument){
1270 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1271 while ( it.More() ) {
1272 const Handle(AIS_InteractiveObject) ashape =
1273 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1274 if (!ashape.IsNull()) {
1276 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1278 TheAISContext()->UnsetColor(ashape,Standard_False);
1282 TheAISContext()->UpdateCurrentViewer();
1288 //==============================================================================
1289 //function : VTransparency
1291 //purpose : change the transparency of a selected or named or displayed shape
1292 //Draw arg : vtransparency [name] TransparencyCoeficient
1293 //==============================================================================
1295 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1298 Standard_Boolean ThereIsCurrent;
1299 Standard_Boolean ThereIsArgument;
1300 Standard_Boolean IsBound = Standard_False ;
1302 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1304 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1305 ThereIsArgument = (argc != 2);
1308 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1309 ThereIsArgument = (argc == 2);
1312 if ( !a3DView().IsNull() ) {
1313 TCollection_AsciiString name;
1314 if (ThereIsArgument) {
1316 IsBound= GetMapOfAIS().IsBound2(name);
1318 if (TheAISContext()->HasOpenedContext())
1319 TheAISContext()->CloseLocalContext();
1321 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1322 else ThereIsCurrent = Standard_False;
1324 //=======================================================================
1325 // Il y a des arguments: un nom et une couleur
1326 //=======================================================================
1327 if ( ThereIsArgument && IsBound ) {
1328 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1329 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1330 const Handle(AIS_InteractiveObject) ashape =
1331 Handle(AIS_InteractiveObject)::DownCast(anObj);
1333 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1335 TheAISContext()->UnsetTransparency(ashape);
1336 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1337 const Handle(NIS_InteractiveObject) ashape =
1338 Handle(NIS_InteractiveObject)::DownCast(anObj);
1340 ashape->SetTransparency(Draw::Atof(argv[2]) );
1342 ashape->UnsetTransparency();
1345 //=======================================================================
1346 // Il n'y a pas d'arguments
1347 // Mais un ou plusieurs objets on des current representation
1348 //=======================================================================
1349 if (ThereIsCurrent && !ThereIsArgument) {
1350 for (TheAISContext() -> InitCurrent() ;
1351 TheAISContext() -> MoreCurrent() ;
1352 TheAISContext() ->NextCurrent() )
1354 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1356 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1358 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1361 TheAISContext()->UpdateCurrentViewer();
1363 //=======================================================================
1364 // Il n'y a pas d'arguments ET aucun objet courrant
1365 //=======================================================================
1366 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1367 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1369 while ( it.More() ) {
1370 Handle(AIS_InteractiveObject) ashape =
1371 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1372 if (!ashape.IsNull()) {
1374 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1376 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1380 TheAISContext()->UpdateCurrentViewer();
1387 //==============================================================================
1388 //function : VMaterial
1390 //purpose : change the Material of a selected or named or displayed shape
1391 //Draw arg : vmaterial [Name] Material
1392 //==============================================================================
1393 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1396 Standard_Boolean ThereIsCurrent;
1397 Standard_Boolean ThereIsName;
1398 Standard_Boolean IsBound = Standard_False ;
1400 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1402 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1403 ThereIsName = (argc != 2);
1406 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1407 ThereIsName = (argc == 2);
1410 if ( !a3DView().IsNull() ) {
1411 TCollection_AsciiString name;
1414 IsBound= GetMapOfAIS().IsBound2(name);
1416 if (TheAISContext()->HasOpenedContext())
1417 TheAISContext()->CloseLocalContext();
1418 if (TheAISContext() -> NbCurrents() > 0 )
1419 ThereIsCurrent =Standard_True;
1421 ThereIsCurrent =Standard_False;
1423 //=======================================================================
1424 // Ther is a name of shape and a material name
1425 //=======================================================================
1426 if ( ThereIsName && IsBound ) {
1427 Handle(AIS_InteractiveObject) ashape =
1428 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1429 if (!ashape.IsNull()) {
1431 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1433 TheAISContext()->UnsetMaterial(ashape);
1436 //=======================================================================
1437 // Il n'y a pas de nom de shape
1438 // Mais un ou plusieurs objets on des current representation
1439 //=======================================================================
1440 if (ThereIsCurrent && !ThereIsName) {
1441 for (TheAISContext() -> InitCurrent() ;
1442 TheAISContext() -> MoreCurrent() ;
1443 TheAISContext() ->NextCurrent() )
1445 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1447 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1449 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1451 TheAISContext()->UpdateCurrentViewer();
1454 //=======================================================================
1455 // Il n'y a pas de noms de shape ET aucun objet courrant
1456 // On impose a tous les objets du viewer le material passe en argument
1457 //=======================================================================
1458 else if (!ThereIsCurrent && !ThereIsName){
1459 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1461 while ( it.More() ) {
1462 Handle(AIS_InteractiveObject) ashape =
1463 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1464 if (!ashape.IsNull()) {
1466 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1468 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1472 TheAISContext()->UpdateCurrentViewer();
1480 //==============================================================================
1483 //purpose : change the width of the edges of a selected or named or displayed shape
1484 //Draw arg : vwidth [Name] WidthValue(1->10)
1485 //==============================================================================
1486 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1489 Standard_Boolean ThereIsCurrent;
1490 Standard_Boolean ThereIsArgument;
1491 Standard_Boolean IsBound = Standard_False ;
1493 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1495 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1496 ThereIsArgument = (argc != 2);
1499 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1500 ThereIsArgument = (argc == 2);
1502 if ( !a3DView().IsNull() ) {
1503 TCollection_AsciiString name;
1504 if (ThereIsArgument) {
1506 IsBound= GetMapOfAIS().IsBound2(name);
1508 if (TheAISContext()->HasOpenedContext())
1509 TheAISContext()->CloseLocalContext();
1511 if (TheAISContext() -> NbCurrents() > 0 )
1512 ThereIsCurrent =Standard_True;
1514 ThereIsCurrent =Standard_False;
1516 if ( ThereIsArgument && IsBound ) {
1517 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1518 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1519 const Handle(AIS_InteractiveObject) ashape =
1520 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1522 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1524 TheAISContext()->UnsetWidth (ashape);
1525 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1526 const Handle(NIS_Triangulated) ashape =
1527 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1528 if (HaveToSet && !ashape.IsNull())
1529 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1533 //=======================================================================
1534 // Il n'y a pas d'arguments
1535 // Mais un ou plusieurs objets on des current representation
1536 //=======================================================================
1537 if (ThereIsCurrent && !ThereIsArgument) {
1538 for (TheAISContext() -> InitCurrent() ;
1539 TheAISContext() -> MoreCurrent() ;
1540 TheAISContext() ->NextCurrent() )
1542 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1544 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1546 TheAISContext()->UnsetWidth(ashape,Standard_False);
1548 TheAISContext()->UpdateCurrentViewer();
1550 //=======================================================================
1551 // Il n'y a pas d'arguments ET aucun objet courrant
1552 //=======================================================================
1553 else if (!ThereIsCurrent && !ThereIsArgument){
1554 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1556 while ( it.More() ) {
1557 Handle(AIS_InteractiveObject) ashape =
1558 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1559 if (!ashape.IsNull()) {
1561 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1563 TheAISContext()->UnsetWidth(ashape,Standard_False);
1567 TheAISContext()->UpdateCurrentViewer();
1573 //==============================================================================
1574 //function : VInteriorStyle
1575 //purpose : sets interior style of the a selected or named or displayed shape
1576 //Draw arg : vsetinteriorstyle [shape] style
1577 //==============================================================================
1578 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1579 const Standard_Integer theStyle,
1580 Draw_Interpretor& di)
1582 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1583 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1584 " (Aspect_IS_HIDDENLINE)]\n";
1587 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1588 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1589 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1590 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1591 aFillAspect->SetInteriorStyle (aStyle);
1592 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1595 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1597 if (argc < 2 || argc > 3) {
1598 di << argv[0] << " requires 2 or 3 arguments\n";
1599 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1600 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1601 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1605 Standard_Boolean ThereIsCurrent;
1606 Standard_Boolean ThereIsArgument;
1607 Standard_Boolean IsBound = Standard_False ;
1609 ThereIsArgument = (argc > 2);
1610 if ( !a3DView().IsNull() ) {
1611 TCollection_AsciiString name;
1612 if (ThereIsArgument) {
1614 IsBound= GetMapOfAIS().IsBound2(name);
1616 if (TheAISContext()->HasOpenedContext())
1617 TheAISContext()->CloseLocalContext();
1619 if (TheAISContext() -> NbCurrents() > 0 )
1620 ThereIsCurrent =Standard_True;
1622 ThereIsCurrent =Standard_False;
1624 if ( ThereIsArgument && IsBound ) {
1625 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1626 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1627 const Handle(AIS_InteractiveObject) ashape =
1628 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1629 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1632 //=======================================================================
1633 // No arguments specified
1634 // But there are one or more selected objects
1635 //=======================================================================
1636 if (ThereIsCurrent && !ThereIsArgument) {
1637 for (TheAISContext() -> InitCurrent() ;
1638 TheAISContext() -> MoreCurrent() ;
1639 TheAISContext() ->NextCurrent() )
1641 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1642 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1645 //=======================================================================
1646 // No arguments specified and there are no selected objects
1647 //=======================================================================
1648 else if (!ThereIsCurrent && !ThereIsArgument){
1649 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1651 while ( it.More() ) {
1652 Handle(AIS_InteractiveObject) ashape =
1653 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1654 if (!ashape.IsNull())
1655 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1659 TheAISContext()->UpdateCurrentViewer();
1664 //==============================================================================
1665 //function : VDonly2
1667 //purpose : Display only a selected or named object
1668 // if there is no selected or named object s, nothing is done
1669 //==============================================================================
1670 static int VDonly2 (Draw_Interpretor& ,
1671 Standard_Integer theArgNb,
1672 const char** theArgVec)
1674 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1677 std::cerr << "Error: no active view!\n";
1681 if (aCtx->HasOpenedContext())
1683 aCtx->CloseLocalContext();
1685 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1687 Standard_Integer anArgIter = 1;
1688 for (; anArgIter < theArgNb; ++anArgIter)
1690 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1696 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1697 if (anArgIter >= theArgNb)
1699 // display only selected objects
1700 if (aCtx->NbCurrents() < 1)
1705 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1707 aDispSet.Add (aCtx->Current());
1712 // display only specified objects
1713 for (; anArgIter < theArgNb; ++anArgIter)
1715 TCollection_AsciiString aName = theArgVec[anArgIter];
1716 if (GetMapOfAIS().IsBound2 (aName))
1718 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1719 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1721 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1722 aCtx->Display (aShape, Standard_False);
1724 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1726 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1727 TheNISContext()->Display (aShape);
1729 aDispSet.Add (anObj);
1734 // weed out other objects
1735 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1737 if (aDispSet.Contains (anIter.Key1()))
1742 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1744 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1745 aCtx->Erase (aShape, Standard_False);
1747 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1749 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1750 TheNISContext()->Erase (aShape);
1754 // update the screen and redraw the view
1755 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1756 a3DView()->SetImmediateUpdate (isAutoUpdate);
1757 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1758 || aToUpdate == ViewerTest_RM_RedrawForce)
1760 TheAISContext()->UpdateCurrentViewer();
1766 //==============================================================================
1767 //function : VRemove
1768 //purpose : Removes selected or named objects.
1769 // If there is no selected or named objects,
1770 // all objects in the viewer can be removed with argument -all.
1771 // If -context is in arguments, the object is not deleted from the map of
1772 // objects (deleted only from the current context).
1773 //==============================================================================
1774 int VRemove (Draw_Interpretor& theDI,
1775 Standard_Integer theArgNb,
1776 const char** theArgVec)
1778 if (a3DView().IsNull())
1780 std::cout << "Error: wrong syntax!\n";
1784 TheAISContext()->CloseAllContexts (Standard_False);
1786 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1787 Standard_Boolean isContextOnly = Standard_False;
1788 Standard_Boolean toRemoveAll = Standard_False;
1790 Standard_Integer anArgIter = 1;
1791 for (; anArgIter < theArgNb; ++anArgIter)
1793 TCollection_AsciiString anArg = theArgVec[anArgIter];
1795 if (anArg == "-context")
1797 isContextOnly = Standard_True;
1799 else if (anArg == "-all")
1801 toRemoveAll = Standard_True;
1803 else if (!parseRedrawMode (anArg, aToUpdate))
1809 && anArgIter < theArgNb)
1811 std::cout << "Error: wrong syntax!\n";
1815 NCollection_List<TCollection_AsciiString> anIONameList;
1818 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1819 anIter.More(); anIter.Next())
1821 anIONameList.Append (anIter.Key2());
1824 else if (anArgIter < theArgNb) // removed objects names are in argument list
1826 for (; anArgIter < theArgNb; ++anArgIter)
1828 TCollection_AsciiString aName = theArgVec[anArgIter];
1829 if (!GetMapOfAIS().IsBound2 (aName))
1831 theDI << aName.ToCString() << " was not bound to some object.\n";
1835 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
1837 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
1840 if (anIO->GetContext() != TheAISContext())
1842 theDI << aName.ToCString() << " was not displayed in current context.\n";
1843 theDI << "Please activate view with this object displayed and try again.\n";
1847 anIONameList.Append (aName);
1851 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
1852 if (!aNisIO.IsNull())
1854 anIONameList.Append (aName);
1858 else if (TheAISContext()->NbCurrents() > 0
1859 || TheNISContext()->GetSelected().Extent() > 0)
1861 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1862 anIter.More(); anIter.Next())
1864 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1867 if (!TheAISContext()->IsCurrent (anIO))
1872 anIONameList.Append (anIter.Key2());
1876 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1877 if (!aNisIO.IsNull())
1879 if (!TheNISContext()->IsSelected (aNisIO))
1884 anIONameList.Append (anIter.Key2());
1889 // Unbind all removed objects from the map of displayed IO.
1890 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
1891 anIter.More(); anIter.Next())
1893 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1897 TheAISContext()->Remove (anIO, Standard_False);
1898 theDI << anIter.Value().ToCString() << " was removed\n";
1902 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1903 if (!aNisIO.IsNull())
1905 TheNISContext()->Remove (aNisIO);
1906 theDI << anIter.Value().ToCString() << " was removed\n";
1912 GetMapOfAIS().UnBind2 (anIter.Value());
1916 // update the screen and redraw the view
1917 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1918 a3DView()->SetImmediateUpdate (isAutoUpdate);
1919 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1920 || aToUpdate == ViewerTest_RM_RedrawForce)
1922 TheAISContext()->UpdateCurrentViewer();
1928 //==============================================================================
1930 //purpose : Erase some selected or named objects
1931 // if there is no selected or named objects, the whole viewer is erased
1932 //==============================================================================
1933 int VErase (Draw_Interpretor& theDI,
1934 Standard_Integer theArgNb,
1935 const char** theArgVec)
1937 if (a3DView().IsNull())
1939 std::cout << "Error: no active view!\n";
1942 TheAISContext()->CloseAllContexts (Standard_False);
1944 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1945 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
1947 Standard_Integer anArgIter = 1;
1948 for (; anArgIter < theArgNb; ++anArgIter)
1950 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1956 if (anArgIter < theArgNb)
1960 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
1964 // has a list of names
1965 for (; anArgIter < theArgNb; ++anArgIter)
1967 TCollection_AsciiString aName = theArgVec[anArgIter];
1968 if (!GetMapOfAIS().IsBound2 (aName))
1973 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1974 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1975 theDI << aName.ToCString() << " ";
1978 TheAISContext()->Erase (anIO, Standard_False);
1982 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1983 if (!aNisIO.IsNull())
1985 TheNISContext()->Erase (aNisIO);
1990 else if (!toEraseAll
1991 && TheAISContext()->NbCurrents() > 0)
1993 // remove all currently selected objects
1994 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1995 anIter.More(); anIter.Next())
1997 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1999 && TheAISContext()->IsCurrent (anIO))
2001 theDI << anIter.Key2().ToCString() << " ";
2002 TheAISContext()->Erase (anIO, Standard_False);
2008 // erase entire viewer
2009 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2010 anIter.More(); anIter.Next())
2012 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2015 TheAISContext()->Erase (anIO, Standard_False);
2019 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2020 if (!aNisIO.IsNull())
2022 TheNISContext()->Erase (aNisIO);
2028 // update the screen and redraw the view
2029 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2030 a3DView()->SetImmediateUpdate (isAutoUpdate);
2031 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2032 || aToUpdate == ViewerTest_RM_RedrawForce)
2034 TheAISContext()->UpdateCurrentViewer();
2040 //==============================================================================
2041 //function : VDisplayAll
2043 //purpose : Display all the objects of the Map
2044 //==============================================================================
2045 static int VDisplayAll (Draw_Interpretor& ,
2046 Standard_Integer theArgNb,
2047 const char** theArgVec)
2050 if (a3DView().IsNull())
2052 std::cout << "Error: no active view!\n";
2056 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2058 Standard_Integer anArgIter = 1;
2059 for (; anArgIter < theArgNb; ++anArgIter)
2061 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
2066 if (anArgIter < theArgNb)
2068 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2072 if (TheAISContext()->HasOpenedContext())
2074 TheAISContext()->CloseLocalContext();
2077 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2078 anIter.More(); anIter.Next())
2080 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2082 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2083 TheAISContext()->Erase (aShape, Standard_False);
2085 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2087 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2088 TheNISContext()->Erase (aShape);
2092 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2093 anIter.More(); anIter.Next())
2095 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2097 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2098 TheAISContext()->Display (aShape, Standard_False);
2100 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2102 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2103 TheNISContext()->Display (aShape);
2107 // update the screen and redraw the view
2108 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2109 a3DView()->SetImmediateUpdate (isAutoUpdate);
2110 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2111 || aToUpdate == ViewerTest_RM_RedrawForce)
2113 TheAISContext()->UpdateCurrentViewer();
2119 //==============================================================================
2120 //function : VTexture
2122 //==============================================================================
2123 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2125 TCollection_AsciiString aCommandName (theArgv[0]);
2127 NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString> aMapOfArgs;
2128 if (aCommandName == "vtexture")
2132 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2133 std::cout << "Type help for more information.\n";
2137 // look for options of vtexture command
2138 TCollection_AsciiString aParseKey;
2139 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2141 TCollection_AsciiString anArg (theArgv [anArgIt]);
2144 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2147 aParseKey.Remove (1);
2148 aParseKey.UpperCase();
2149 aMapOfArgs.Bind (aParseKey, TColStd_SequenceOfAsciiString());
2153 if (aParseKey.IsEmpty())
2158 aMapOfArgs.ChangeFind (aParseKey).Append (anArg);
2161 else if (aCommandName == "vtexscale"
2162 || aCommandName == "vtexorigin"
2163 || aCommandName == "vtexrepeat")
2165 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2166 // equal to -scale, -origin, -repeat options of vtexture command
2167 if (theArgsNb < 2 || theArgsNb > 4)
2169 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2170 std::cout << "Type help for more information.\n";
2174 TColStd_SequenceOfAsciiString anArgs;
2177 anArgs.Append ("OFF");
2179 else if (theArgsNb == 4)
2181 anArgs.Append (TCollection_AsciiString (theArgv[2]));
2182 anArgs.Append (TCollection_AsciiString (theArgv[3]));
2185 TCollection_AsciiString anArgKey;
2186 if (aCommandName == "vtexscale")
2190 else if (aCommandName == "vtexorigin")
2192 anArgKey = "ORIGIN";
2196 anArgKey = "REPEAT";
2199 aMapOfArgs.Bind (anArgKey, anArgs);
2201 else if (aCommandName == "vtexdefault")
2203 // scan for parameters of vtexdefault command
2204 // equal to -default option of vtexture command
2205 aMapOfArgs.Bind ("DEFAULT", TColStd_SequenceOfAsciiString());
2208 // Check arguments for validity
2209 NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString>::Iterator aMapIt (aMapOfArgs);
2210 for (; aMapIt.More(); aMapIt.Next())
2212 const TCollection_AsciiString& aKey = aMapIt.Key();
2213 const TColStd_SequenceOfAsciiString& anArgs = aMapIt.Value();
2215 // -scale, -origin, -repeat: one argument "off", or two real values
2216 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2217 && ((anArgs.Length() == 1 && anArgs (1) == "OFF")
2218 || (anArgs.Length() == 2 && anArgs (1).IsRealValue() && anArgs (2).IsRealValue())))
2223 // -modulate: single argument "on" / "off"
2224 if (aKey.IsEqual ("MODULATE") && anArgs.Length() == 1 && (anArgs (1) == "OFF" || anArgs (1) == "ON"))
2229 // -default: no arguments
2230 if (aKey.IsEqual ("DEFAULT") && anArgs.IsEmpty())
2235 TCollection_AsciiString aLowerKey;
2238 aLowerKey.LowerCase();
2239 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2240 std::cout << "Type help for more information.\n";
2244 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2245 if (anAISContext.IsNull())
2247 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2251 Standard_Integer aPreviousMode = 0;
2253 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2255 TCollection_AsciiString aShapeName (theArgv[1]);
2256 Handle(AIS_InteractiveObject) anIO;
2258 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2259 if (aMapOfIO.IsBound2 (aShapeName))
2261 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2266 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2270 Handle(AIS_TexturedShape) aTexturedIO;
2271 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2273 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2274 aPreviousMode = aTexturedIO->DisplayMode();
2278 anAISContext->Clear (anIO, Standard_False);
2279 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2280 GetMapOfAIS().UnBind1 (anIO);
2281 GetMapOfAIS().UnBind2 (aShapeName);
2282 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2285 // -------------------------------------------
2286 // Turn texturing on/off - only for vtexture
2287 // -------------------------------------------
2289 if (aCommandName == "vtexture")
2291 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2293 if (aTextureArg.IsEmpty())
2295 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2296 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2298 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2299 if (aPreviousMode == 3)
2301 anAISContext->RecomputePrsOnly (aTexturedIO);
2304 anAISContext->Display (aTexturedIO, Standard_True);
2307 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2309 if (aTextureArg == "?")
2311 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2313 theDi << "\n Files in current directory : \n" << "\n";
2314 theDi.Eval ("glob -nocomplain *");
2316 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2317 aCmnd += aTextureFolder;
2320 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2321 theDi.Eval (aCmnd.ToCString());
2326 aTexturedIO->SetTextureFileName (aTextureArg);
2331 // ------------------------------------
2332 // Process other options and commands
2333 // ------------------------------------
2335 TColStd_SequenceOfAsciiString aValues;
2336 if (aMapOfArgs.Find ("DEFAULT", aValues))
2338 aTexturedIO->SetTextureRepeat (Standard_False);
2339 aTexturedIO->SetTextureOrigin (Standard_False);
2340 aTexturedIO->SetTextureScale (Standard_False);
2341 aTexturedIO->EnableTextureModulate();
2345 if (aMapOfArgs.Find ("SCALE", aValues))
2347 if (aValues (1) != "OFF")
2349 aTexturedIO->SetTextureScale (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
2353 aTexturedIO->SetTextureScale (Standard_False);
2357 if (aMapOfArgs.Find ("ORIGIN", aValues))
2359 if (aValues (1) != "OFF")
2361 aTexturedIO->SetTextureOrigin (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
2365 aTexturedIO->SetTextureOrigin (Standard_False);
2369 if (aMapOfArgs.Find ("REPEAT", aValues))
2371 if (aValues (1) != "OFF")
2373 aTexturedIO->SetTextureRepeat (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
2377 aTexturedIO->SetTextureRepeat (Standard_False);
2381 if (aMapOfArgs.Find ("MODULATE", aValues))
2383 if (aValues (1) == "ON")
2385 aTexturedIO->EnableTextureModulate();
2389 aTexturedIO->DisableTextureModulate();
2394 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2396 anAISContext->RecomputePrsOnly (aTexturedIO);
2400 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2401 anAISContext->Display (aTexturedIO, Standard_True);
2402 anAISContext->Update (aTexturedIO,Standard_True);
2408 //==============================================================================
2409 //function : VDisplay2
2411 //purpose : Display an object from its name
2412 //==============================================================================
2413 static int VDisplay2 (Draw_Interpretor& theDI,
2414 Standard_Integer theArgNb,
2415 const char** theArgVec)
2419 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2422 else if (a3DView().IsNull())
2424 ViewerTest::ViewerInit();
2425 std::cout << "Command vinit should be called before!\n";
2429 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2430 if (aCtx->HasOpenedContext())
2432 aCtx->CloseLocalContext();
2435 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2436 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2438 const TCollection_AsciiString aName = theArgVec[anArgIter];
2439 if (parseRedrawMode (aName, aToUpdate))
2443 else if (!GetMapOfAIS().IsBound2 (aName))
2445 // create the AIS_Shape from a name
2446 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2447 if (!aShape.IsNull())
2449 GetMapOfAIS().Bind (aShape, aName);
2450 aCtx->Display (aShape, Standard_False);
2455 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2456 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2458 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2459 if (aShape->Type() == AIS_KOI_Datum)
2461 aCtx->Display (aShape, Standard_False);
2465 theDI << "Display " << aName.ToCString() << "\n";
2466 // get the Shape from a name
2467 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2469 // update the Shape in the AIS_Shape
2470 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2471 if (!aShapePrs.IsNull())
2473 aShapePrs->Set (aNewShape);
2475 aCtx->Redisplay (aShape, Standard_False);
2476 aCtx->Display (aShape, Standard_False);
2480 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2482 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2483 TheNISContext()->Display (aShape);
2487 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2488 a3DView()->SetImmediateUpdate (isAutoUpdate);
2489 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2490 || aToUpdate == ViewerTest_RM_RedrawForce)
2492 // update the screen and redraw the view
2493 aCtx->UpdateCurrentViewer();
2498 //===============================================================================================
2499 //function : VUpdate
2501 //===============================================================================================
2502 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2504 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2505 if (aContextAIS.IsNull())
2507 std::cout << theArgVec[0] << "AIS context is not available.\n";
2513 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2517 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2519 AIS_ListOfInteractive aListOfIO;
2521 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2523 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2525 Handle(AIS_InteractiveObject) anAISObj;
2526 if (anAISMap.IsBound2 (aName))
2528 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2531 if (anAISObj.IsNull())
2533 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2537 aListOfIO.Append (anAISObj);
2540 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2541 for (; anIOIt.More(); anIOIt.Next())
2543 aContextAIS->Update (anIOIt.Value(), Standard_False);
2546 aContextAIS->UpdateCurrentViewer();
2551 //==============================================================================
2553 //purpose : Test the annimation of an object along a
2554 // predifined trajectory
2555 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2556 //==============================================================================
2558 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2561 if (TheAISContext()->HasOpenedContext())
2562 TheAISContext()->CloseLocalContext();
2564 Standard_Real Step=4*M_PI/180;
2565 Standard_Real Angle=0;
2567 Handle(AIS_InteractiveObject) aIO;
2568 if (GetMapOfAIS().IsBound2(argv[1]))
2569 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2573 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2577 if (Draw::Atoi(argv[3])==1 ) {
2578 di<<" Primitives sensibles OFF"<<"\n";
2579 TheAISContext()->Deactivate(aIO);
2582 di<<" Primitives sensibles ON"<<"\n";
2584 // Movement par transformation
2585 if(Draw::Atoi(argv[2]) ==1) {
2586 di<<" Calcul par Transformation"<<"\n";
2587 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2591 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2592 TheAISContext()->SetLocation(aShape,myTransfo);
2593 TheAISContext() ->UpdateCurrentViewer();
2598 di<<" Calcul par Locations"<<"\n";
2599 gp_Trsf myAngleTrsf;
2600 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2601 TopLoc_Location myDeltaAngle (myAngleTrsf);
2602 TopLoc_Location myTrueLoc;
2604 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2607 myTrueLoc=myTrueLoc*myDeltaAngle;
2608 TheAISContext()->SetLocation(aShape,myTrueLoc );
2609 TheAISContext() ->UpdateCurrentViewer();
2612 if (Draw::Atoi(argv[3])==1 ){
2613 // On reactive la selection des primitives sensibles
2614 TheAISContext()->Activate(aIO,0);
2616 a3DView() -> Redraw();
2618 di<<" Temps ecoule "<<"\n";
2624 //==================================================================================
2625 // Function : VAnimation
2626 //==================================================================================
2627 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2629 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2633 Standard_Real thread = 4;
2634 Standard_Real angleA=0;
2635 Standard_Real angleB;
2637 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2640 TopoDS_Shape CrankArm;
2641 TopoDS_Shape CylinderHead;
2642 TopoDS_Shape Propeller;
2643 TopoDS_Shape EngineBlock;
2645 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2646 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2647 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2648 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2649 BRepTools::Read(CrankArm,argv[1],B);
2650 BRepTools::Read(CylinderHead,argv[2],B);
2651 BRepTools::Read(Propeller,argv[3],B);
2652 BRepTools::Read(EngineBlock,argv[4],B);
2654 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2660 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2661 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2662 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2663 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2665 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2666 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2667 GetMapOfAIS().Bind(myAisCrankArm,"c");
2668 GetMapOfAIS().Bind(myAisPropeller,"d");
2670 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2671 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2672 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2674 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2675 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2676 TheAISContext()->Display(myAisCrankArm,Standard_False );
2677 TheAISContext()->Display(myAisPropeller,Standard_False);
2679 TheAISContext()->Deactivate(myAisCylinderHead);
2680 TheAISContext()->Deactivate(myAisEngineBlock );
2681 TheAISContext()->Deactivate(myAisCrankArm );
2682 TheAISContext()->Deactivate(myAisPropeller );
2684 // Boucle de mouvement
2685 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2687 angleA = thread*myAngle*M_PI/180;
2688 X = Sin(angleA)*3/8;
2689 angleB = atan(X / Sqrt(-X * X + 1));
2690 Standard_Real decal(25*0.6);
2693 //Build a transformation on the display
2694 gp_Trsf aPropellerTrsf;
2695 aPropellerTrsf.SetRotation(Ax1,angleA);
2696 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2698 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));
2699 gp_Trsf aCrankArmTrsf;
2700 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2701 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2703 TheAISContext()->UpdateCurrentViewer();
2706 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2707 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2709 myAisCrankArm ->ResetLocation();
2710 myAisPropeller->ResetLocation();
2712 myAisCrankArm -> Set(myNewCrankArm );
2713 myAisPropeller -> Set(myNewPropeller);
2715 TheAISContext()->Activate(myAisCylinderHead,0);
2716 TheAISContext()->Activate(myAisEngineBlock,0 );
2717 TheAISContext()->Activate(myAisCrankArm ,0 );
2718 TheAISContext()->Activate(myAisPropeller ,0 );
2724 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2725 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2727 TheAISContext()->UpdateCurrentViewer();
2728 a3DView()->Redraw();
2737 //==============================================================================
2738 //function : VShading
2739 //purpose : Sharpen or roughten the quality of the shading
2740 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2741 //==============================================================================
2742 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2744 Standard_Real myDevCoef;
2745 Handle(AIS_InteractiveObject) TheAisIO;
2748 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2750 if (TheAISContext()->HasOpenedContext())
2751 TheAISContext()->CloseLocalContext();
2756 myDevCoef =Draw::Atof(argv[2]);
2759 TCollection_AsciiString name=argv[1];
2760 if (GetMapOfAIS().IsBound2(name ))
2761 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2762 if (TheAisIO.IsNull())
2763 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2766 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2768 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2770 TheAISContext()->Redisplay(TheAisIO);
2773 //==============================================================================
2774 //function : HaveMode
2775 //use : VActivatedModes
2776 //==============================================================================
2777 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2779 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2781 TColStd_ListOfInteger List;
2782 TheAISContext()->ActivatedModes (TheAisIO,List);
2783 TColStd_ListIteratorOfListOfInteger it;
2784 Standard_Boolean Found=Standard_False;
2785 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2786 if (it.Value()==mode ) Found=Standard_True;
2793 //==============================================================================
2794 //function : VActivatedMode
2796 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2797 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2798 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2799 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2800 // qu'un nom et qu'un mode.
2801 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2802 //==============================================================================
2803 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2805 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2808 Standard_Boolean ThereIsName = Standard_False ;
2810 if(!a3DView().IsNull()){
2812 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2813 // verification des arguments
2815 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2816 ThereIsName = (argc == 3);
2820 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2822 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2823 di<<" Fermeture du Context local"<<"\n";
2824 if (TheAISContext()->HasOpenedContext())
2825 TheAISContext()->CloseLocalContext();
2829 // IL n'y a aps de nom de shape passe en argument
2830 if (HaveToSet && !ThereIsName){
2831 Standard_Integer aMode=Draw::Atoi(argv [1]);
2833 const char *cmode="???";
2835 case 0: cmode = "Shape"; break;
2836 case 1: cmode = "Vertex"; break;
2837 case 2: cmode = "Edge"; break;
2838 case 3: cmode = "Wire"; break;
2839 case 4: cmode = "Face"; break;
2840 case 5: cmode = "Shell"; break;
2841 case 6: cmode = "Solid"; break;
2842 case 7: cmode = "Compound"; break;
2845 if( !TheAISContext()->HasOpenedContext() ) {
2846 // il n'y a pas de Context local d'ouvert
2847 // on en ouvre un et on charge toutes les shapes displayees
2848 // on load tous les objets displayees et on Activate les objets de la liste
2849 AIS_ListOfInteractive ListOfIO;
2850 // on sauve dans une AISListOfInteractive tous les objets currents
2851 if (TheAISContext()->NbCurrents()>0 ){
2852 TheAISContext()->UnhilightCurrents(Standard_False);
2854 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2855 ListOfIO.Append(TheAISContext()->Current() );
2859 TheAISContext()->OpenLocalContext(Standard_False);
2860 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2863 Handle(AIS_InteractiveObject) aIO =
2864 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2866 TheAISContext()->Load(aIO,0,Standard_False);
2869 // traitement des objets qui etaient currents dans le Contexte global
2870 if (!ListOfIO.IsEmpty() ) {
2871 // il y avait des objets currents
2872 AIS_ListIteratorOfListOfInteractive iter;
2873 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2874 Handle(AIS_InteractiveObject) aIO=iter.Value();
2875 TheAISContext()->Activate(aIO,aMode);
2876 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2880 // On applique le mode a tous les objets displayes
2881 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2882 it2 (GetMapOfAIS());
2884 Handle(AIS_InteractiveObject) aIO =
2885 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2886 if (!aIO.IsNull()) {
2887 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2888 TheAISContext()->Activate(aIO,aMode);
2897 // un Context local est deja ouvert
2898 // Traitement des objets du Context local
2899 if (TheAISContext()->NbSelected()>0 ){
2900 TheAISContext()->UnhilightSelected(Standard_False);
2901 // il y a des objets selected,on les parcourt
2902 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2903 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2906 if (HaveMode(aIO,aMode) ) {
2907 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2908 TheAISContext()->Deactivate(aIO,aMode);
2911 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2912 TheAISContext()->Activate(aIO,aMode);
2918 // il n'y a pas d'objets selected
2919 // tous les objets diplayes sont traites
2920 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2923 Handle(AIS_InteractiveObject) aIO =
2924 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2925 if (!aIO.IsNull()) {
2926 if (HaveMode(aIO,aMode) ) {
2927 di<<" Mode: "<<cmode<<" OFF pour "
2928 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2929 TheAISContext()->Deactivate(aIO,aMode);
2932 di<<" Mode: "<<cmode<<" ON pour"
2933 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2934 TheAISContext()->Activate(aIO,aMode);
2942 else if (HaveToSet && ThereIsName){
2943 Standard_Integer aMode=Draw::Atoi(argv [2]);
2944 Handle(AIS_InteractiveObject) aIO =
2945 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2947 if (!aIO.IsNull()) {
2948 const char *cmode="???";
2951 case 0: cmode = "Shape"; break;
2952 case 1: cmode = "Vertex"; break;
2953 case 2: cmode = "Edge"; break;
2954 case 3: cmode = "Wire"; break;
2955 case 4: cmode = "Face"; break;
2956 case 5: cmode = "Shell"; break;
2957 case 6: cmode = "Solid"; break;
2958 case 7: cmode = "Compound"; break;
2961 if( !TheAISContext()->HasOpenedContext() ) {
2962 TheAISContext()->OpenLocalContext(Standard_False);
2963 // On charge tous les objets de la map
2964 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2966 Handle(AIS_InteractiveObject) aShape=
2967 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2968 if (!aShape.IsNull())
2969 TheAISContext()->Load(aShape,0,Standard_False);
2972 TheAISContext()->Activate(aIO,aMode);
2973 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2977 // un Context local est deja ouvert
2978 if (HaveMode(aIO,aMode) ) {
2979 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2980 TheAISContext()->Deactivate(aIO,aMode);
2983 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2984 TheAISContext()->Activate(aIO,aMode);
2993 //! Auxiliary method to print Interactive Object information
2994 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
2995 const Handle(Standard_Transient)& theObject,
2996 Draw_Interpretor& theDI)
2998 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3001 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3005 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3006 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3007 << (theDetected.Contains (anObj) ? " Detected" : " ")
3009 if (anObj->Type() == AIS_KOI_Datum)
3012 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3013 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3014 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3015 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3016 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3017 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3018 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3021 else if (anObj->Type() == AIS_KOI_Shape
3022 && anObj->Signature() == 0)
3024 theDI << " AIS_Shape";
3026 else if (anObj->Type() == AIS_KOI_Relation)
3028 // AIS_Dimention and AIS_Relation
3029 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3030 switch (aRelation->KindOfDimension())
3032 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3033 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3034 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3035 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3036 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3037 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3038 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3039 default: theDI << " UNKNOWN dimension"; break;
3044 theDI << " UserPrs";
3046 theDI << " (" << theObject->DynamicType()->Name() << ")";
3049 //! Print information about locally selected sub-shapes
3050 static void localCtxInfo (Draw_Interpretor& theDI)
3052 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3053 if (!aCtx->HasOpenedContext())
3058 TCollection_AsciiString aPrevName;
3059 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3060 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3062 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3063 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3064 if (aSubShape.IsNull()
3065 || aShapeIO.IsNull()
3066 || !GetMapOfAIS().IsBound1 (aShapeIO))
3071 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3072 TopTools_MapOfShape aFilter;
3073 Standard_Integer aNumber = 0;
3074 const TopoDS_Shape aShape = aShapeIO->Shape();
3075 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3076 anIter.More(); anIter.Next())
3078 if (!aFilter.Add (anIter.Current()))
3080 continue; // filter duplicates
3084 if (!anIter.Current().IsSame (aSubShape))
3089 Standard_CString aShapeName = NULL;
3090 switch (aSubShape.ShapeType())
3092 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3093 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3094 case TopAbs_SOLID: aShapeName = " Solid"; break;
3095 case TopAbs_SHELL: aShapeName = " Shell"; break;
3096 case TopAbs_FACE: aShapeName = " Face"; break;
3097 case TopAbs_WIRE: aShapeName = " Wire"; break;
3098 case TopAbs_EDGE: aShapeName = " Edge"; break;
3099 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3101 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3104 if (aParentName != aPrevName)
3106 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3107 aPrevName = aParentName;
3109 theDI << " " << aShapeName << " #" << aNumber << "\n";
3115 //==============================================================================
3118 //Draw arg : vstate [nameA] ... [nameN]
3119 //==============================================================================
3120 static Standard_Integer VState (Draw_Interpretor& theDI,
3121 Standard_Integer theArgNb,
3122 Standard_CString* theArgVec)
3124 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3127 std::cerr << "Error: No opened viewer!\n";
3131 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3132 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3134 aDetected.Add (aCtx->DetectedCurrentObject());
3137 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3141 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3143 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3144 if (!GetMapOfAIS().IsBound2 (anObjName))
3146 theDI << anObjName << " doesn't exist!\n";
3150 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3151 TCollection_AsciiString aName = anObjName;
3152 aName.LeftJustify (20, ' ');
3153 theDI << " " << aName << " ";
3154 objInfo (aDetected, anObjTrans, theDI);
3160 if (aCtx->NbCurrents() > 0
3163 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3165 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3166 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3167 aName.LeftJustify (20, ' ');
3168 theDI << aName << " ";
3169 objInfo (aDetected, anObj, theDI);
3175 theDI << "Neutral-point state:\n";
3176 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3177 anObjIter.More(); anObjIter.Next())
3179 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3185 TCollection_AsciiString aName = anObjIter.Key2();
3186 aName.LeftJustify (20, ' ');
3187 theDI << " " << aName << " ";
3188 objInfo (aDetected, anObj, theDI);
3191 localCtxInfo (theDI);
3195 //=======================================================================
3196 //function : PickObjects
3198 //=======================================================================
3199 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3200 const AIS_KindOfInteractive TheType,
3201 const Standard_Integer TheSignature,
3202 const Standard_Integer MaxPick)
3204 Handle(AIS_InteractiveObject) IO;
3205 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3207 // step 1: prepare the data
3209 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3210 TheAISContext()->AddFilter(F1);
3213 // step 2 : wait for the selection...
3214 // Standard_Boolean IsGood (Standard_False);
3215 // Standard_Integer NbPick(0);
3216 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3217 Standard_Integer NbPickFail(0);
3218 Standard_Integer argccc = 5;
3219 const char *bufff[] = { "A", "B", "C","D", "E" };
3220 const char **argvvv = (const char **) bufff;
3223 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3224 while(ViewerMainLoop(argccc,argvvv)){}
3225 Standard_Integer NbStored = TheAISContext()->NbSelected();
3226 if((unsigned int ) NbStored != NbPickGood)
3227 NbPickGood= NbStored;
3230 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3233 // step3 get result.
3235 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3237 Standard_Integer i(0);
3238 for(TheAISContext()->InitSelected();
3239 TheAISContext()->MoreSelected();
3240 TheAISContext()->NextSelected()){
3242 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3243 arr->SetValue(i,IO2);
3248 TheAISContext()->CloseLocalContext(curindex);
3250 return Standard_True;
3254 //=======================================================================
3255 //function : PickObject
3257 //=======================================================================
3258 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3259 const Standard_Integer TheSignature,
3260 const Standard_Integer MaxPick)
3262 Handle(AIS_InteractiveObject) IO;
3263 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3265 // step 1: prepare the data
3268 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3269 TheAISContext()->AddFilter(F1);
3272 // step 2 : wait for the selection...
3273 Standard_Boolean IsGood (Standard_False);
3274 Standard_Integer NbPick(0);
3275 Standard_Integer argccc = 5;
3276 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3277 const char **argvvv = (const char **) bufff;
3280 while(!IsGood && NbPick<= MaxPick){
3281 while(ViewerMainLoop(argccc,argvvv)){}
3282 IsGood = (TheAISContext()->NbSelected()>0) ;
3284 cout<<"Nb Pick :"<<NbPick<<endl;
3288 // step3 get result.
3290 TheAISContext()->InitSelected();
3291 IO = TheAISContext()->SelectedInteractive();
3295 TheAISContext()->CloseLocalContext(curindex);
3299 //=======================================================================
3300 //function : PickShape
3301 //purpose : First Activate the rightmode + Put Filters to be able to
3302 // pick objets that are of type <TheType>...
3303 //=======================================================================
3305 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3306 const Standard_Integer MaxPick)
3309 // step 1: prepare the data
3311 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3312 TopoDS_Shape result;
3314 if(TheType==TopAbs_SHAPE){
3315 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3316 TheAISContext()->AddFilter(F1);
3319 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3320 TheAISContext()->AddFilter(TF);
3321 TheAISContext()->ActivateStandardMode(TheType);
3326 // step 2 : wait for the selection...
3327 Standard_Boolean NoShape (Standard_True);
3328 Standard_Integer NbPick(0);
3329 Standard_Integer argccc = 5;
3330 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3331 const char **argvvv = (const char **) bufff;
3334 while(NoShape && NbPick<= MaxPick){
3335 while(ViewerMainLoop(argccc,argvvv)){}
3336 NoShape = (TheAISContext()->NbSelected()==0) ;
3338 cout<<"Nb Pick :"<<NbPick<<endl;
3341 // step3 get result.
3345 TheAISContext()->InitSelected();
3346 if(TheAISContext()->HasSelectedShape())
3347 result = TheAISContext()->SelectedShape();
3349 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3350 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3355 TheAISContext()->CloseLocalContext(curindex);
3361 //=======================================================================
3362 //function : PickShapes
3364 //=======================================================================
3365 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3366 Handle(TopTools_HArray1OfShape)& thearr,
3367 const Standard_Integer MaxPick)
3370 Standard_Integer Taille = thearr->Length();
3372 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3374 // step 1: prepare the data
3375 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3376 if(TheType==TopAbs_SHAPE){
3377 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3378 TheAISContext()->AddFilter(F1);
3381 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3382 TheAISContext()->AddFilter(TF);
3383 TheAISContext()->ActivateStandardMode(TheType);
3387 // step 2 : wait for the selection...
3389 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3390 Standard_Integer NbPickFail(0);
3391 Standard_Integer argccc = 5;
3392 const char *bufff[] = { "A", "B", "C","D", "E" };
3393 const char **argvvv = (const char **) bufff;
3396 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3397 while(ViewerMainLoop(argccc,argvvv)){}
3398 Standard_Integer NbStored = TheAISContext()->NbSelected();
3399 if((unsigned int ) NbStored != NbPickGood)
3400 NbPickGood= NbStored;
3403 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3406 // step3 get result.
3408 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3410 Standard_Integer i(0);
3411 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3413 if(TheAISContext()->HasSelectedShape())
3414 thearr->SetValue(i,TheAISContext()->SelectedShape());
3416 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3417 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3421 TheAISContext()->CloseLocalContext(curindex);
3422 return Standard_True;
3426 //=======================================================================
3427 //function : VPickShape
3429 //=======================================================================
3430 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3432 TopoDS_Shape PickSh;
3433 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3436 theType = TopAbs_SHAPE;
3438 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3439 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3440 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3441 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3442 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3443 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3444 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3447 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3448 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3450 TCollection_AsciiString name;
3453 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3455 PickSh = ViewerTest::PickShape(theType);
3464 if(!PickSh.IsNull()){
3465 nbOfSub[Standard_Integer(theType)]++;
3467 name += nameType[Standard_Integer(theType)];
3468 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3473 // si on avait une petite methode pour voir si la shape
3474 // est deja dans la Double map, ca eviterait de creer....
3475 DBRep::Set(name.ToCString(),PickSh);
3477 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3478 GetMapOfAIS().Bind(newsh, name);
3479 TheAISContext()->Display(newsh);
3480 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3483 // Plusieurs objets a picker, vite vite vite....
3486 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3487 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3488 if(ViewerTest::PickShapes(theType,arr)){
3489 for(Standard_Integer i=1;i<=NbToPick;i++){
3490 PickSh = arr->Value(i);
3491 if(!PickSh.IsNull()){
3493 nbOfSub[Standard_Integer(theType)]++;
3496 name += nameType[Standard_Integer(theType)];
3497 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3505 DBRep::Set(name.ToCString(),PickSh);
3506 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3507 GetMapOfAIS().Bind(newsh, name);
3508 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3509 TheAISContext()->Display(newsh);
3517 //=======================================================================
3518 //function : list of known objects
3520 //=======================================================================
3521 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3523 // 1234567890 12345678901234567 123456789
3524 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3525 TCollection_AsciiString BlankLine(64,'_');
3526 Standard_Integer i ;
3528 di<<"/n"<<BlankLine.ToCString()<<"\n";
3531 Colum[i].Center(20,' ');
3533 di<<"|"<<Colum[i].ToCString();
3536 di<<BlankLine.ToCString()<<"\n";
3538 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3539 const char ** names = GetTypeNames();
3541 TCollection_AsciiString curstring;
3542 TCollection_AsciiString curcolum[3];
3545 // les objets de type Datum..
3546 curcolum[1]+="Datum";
3548 curcolum[0].Clear();
3549 curcolum[0] += names[i];
3551 curcolum[2].Clear();
3552 curcolum[2]+=TCollection_AsciiString(i+1);
3554 for(Standard_Integer j =0;j<=2;j++){
3555 curcolum[j].Center(20,' ');
3556 di<<"|"<<curcolum[j].ToCString();
3560 di<<BlankLine.ToCString()<<"\n";
3562 // les objets de type shape
3563 curcolum[1].Clear();
3564 curcolum[1]+="Shape";
3565 curcolum[1].Center(20,' ');
3568 curcolum[0].Clear();
3569 curcolum[0] += names[7+i];
3570 curcolum[2].Clear();
3571 curcolum[2]+=TCollection_AsciiString(i);
3573 for(Standard_Integer j =0;j<=2;j++){
3574 curcolum[j].Center(20,' ');
3575 di<<"|"<<curcolum[j].ToCString();
3579 di<<BlankLine.ToCString()<<"\n";
3580 // les IO de type objet...
3581 curcolum[1].Clear();
3582 curcolum[1]+="Object";
3583 curcolum[1].Center(20,' ');
3585 curcolum[0].Clear();
3586 curcolum[0] += names[10+i];
3587 curcolum[2].Clear();
3588 curcolum[2]+=TCollection_AsciiString(i);
3590 for(Standard_Integer j =0;j<=2;j++){
3591 curcolum[j].Center(20,' ');
3592 di<<"|"<<curcolum[j].ToCString();
3596 di<<BlankLine.ToCString()<<"\n";
3597 // les contraintes et dimensions.
3598 // pour l'instant on separe juste contraintes et dimensions...
3599 // plus tard, on detaillera toutes les sortes...
3600 curcolum[1].Clear();
3601 curcolum[1]+="Relation";
3602 curcolum[1].Center(20,' ');
3604 curcolum[0].Clear();
3605 curcolum[0] += names[12+i];
3606 curcolum[2].Clear();
3607 curcolum[2]+=TCollection_AsciiString(i);
3609 for(Standard_Integer j =0;j<=2;j++){
3610 curcolum[j].Center(20,' ');
3611 di<<"|"<<curcolum[j].ToCString();
3615 di<<BlankLine.ToCString()<<"\n";
3622 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3624 if(argc!=2) return 1;
3626 AIS_KindOfInteractive TheType;
3627 Standard_Integer TheSign(-1);
3628 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3631 AIS_ListOfInteractive LIO;
3633 // en attendant l'amelioration ais pour les dimensions...
3635 Standard_Integer dimension_status(-1);
3636 if(TheType==AIS_KOI_Relation){
3637 dimension_status = TheSign ==1 ? 1 : 0;
3641 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3642 Handle(AIS_InteractiveObject) curio;
3643 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3646 if(dimension_status == -1)
3647 TheAISContext()->Erase(curio,Standard_False);
3649 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3650 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3651 (dimension_status==1 && KOD != AIS_KOD_NONE))
3652 TheAISContext()->Erase(curio,Standard_False);
3655 TheAISContext()->UpdateCurrentViewer();
3658 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3660 if(argc!=2) return 1;
3662 AIS_KindOfInteractive TheType;
3663 Standard_Integer TheSign(-1);
3664 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3666 // en attendant l'amelioration ais pour les dimensions...
3668 Standard_Integer dimension_status(-1);
3669 if(TheType==AIS_KOI_Relation){
3670 dimension_status = TheSign ==1 ? 1 : 0;
3674 AIS_ListOfInteractive LIO;
3675 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3676 Handle(AIS_InteractiveObject) curio;
3677 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3679 if(dimension_status == -1)
3680 TheAISContext()->Display(curio,Standard_False);
3682 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3683 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3684 (dimension_status==1 && KOD != AIS_KOD_NONE))
3685 TheAISContext()->Display(curio,Standard_False);
3690 TheAISContext()->UpdateCurrentViewer();
3694 //==============================================================================
3695 //function : VSetTransMode
3697 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3698 //==============================================================================
3700 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3701 // Verification des arguments
3702 if ( a3DView().IsNull() ) {
3703 ViewerTest::ViewerInit();
3704 di << "La commande vinit n'a pas ete appele avant" << "\n";
3707 if ( argc < 3 || argc > 8 ) {
3708 di << argv[0] << " Invalid number of arguments" << "\n";
3712 TCollection_AsciiString shapeName;
3713 shapeName = argv[1];
3714 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3715 Standard_Integer persFlag2 = 0;
3716 Standard_Integer persFlag3 = 0;
3717 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3718 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3719 persFlag2 = Draw::Atoi(argv[3]);
3721 if ( argc == 5 || argc == 8 ) {
3722 persFlag3 = Draw::Atoi(argv[4]);
3725 origin.SetX( Draw::Atof(argv[argc - 3]) );
3726 origin.SetY( Draw::Atof(argv[argc - 2]) );
3727 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3730 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3731 Handle(Standard_Transient) anObj;
3733 anObj = GetMapOfAIS().Find2(shapeName);
3734 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3735 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3736 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3737 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3738 di << argv[0] << " All persistence modifiers were removed" << "\n";
3741 di << argv[0] << " Wrong object type" << "\n";
3744 } else { // Create the AIS_Shape from a name
3745 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3746 if ( !aShape.IsNull() ) {
3747 GetMapOfAIS().Bind( aShape, shapeName );
3748 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3749 TheAISContext()->Display( aShape, Standard_False );
3751 di << argv[0] << " Object not found" << "\n";
3756 // Upadate the screen and redraw the view
3757 TheAISContext()->UpdateCurrentViewer();
3761 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3764 BRep_Builder builder;
3766 BRepTools::Read(shape, s, builder);
3767 DBRep::Set(a[1], shape);
3768 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3769 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3774 //==============================================================================
3775 //function : ViewerTest::Commands
3776 //purpose : Add all the viewer command in the Draw_Interpretor
3777 //==============================================================================
3779 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3781 ViewerTest::ViewerCommands(theCommands);
3782 ViewerTest::RelationCommands(theCommands);
3783 ViewerTest::ObjectCommands(theCommands);
3784 ViewerTest::FilletCommands(theCommands);
3785 ViewerTest::VoxelCommands(theCommands);
3786 ViewerTest::OpenGlCommands(theCommands);
3788 const char *group = "AIS_Display";
3791 theCommands.Add("visos",
3792 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3793 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3794 __FILE__, visos, group);
3796 theCommands.Add("vdisplay",
3797 "vdisplay [-noupdate|-update] name1 [name2] ... [name n]"
3798 "\n\t\t: Displays named objects."
3799 "\n\t\t: Option -noupdate suppresses viewer redraw call."
3800 __FILE__,VDisplay2,group);
3802 theCommands.Add ("vupdate",
3803 "vupdate name1 [name2] ... [name n]"
3804 "\n\t\t: Updates named objects in interactive context",
3805 __FILE__, VUpdate, group);
3807 theCommands.Add("verase",
3808 "verase [-noupdate|-update] [name1] ... [name n]"
3809 "\n\t\t: Erases selected or named objects."
3810 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3811 __FILE__, VErase, group);
3813 theCommands.Add("vremove",
3814 "vremove [-noupdate|-update] [-context] [-all] [name1] ... [name n]"
3815 "or vremove [-context] -all to remove all objects"
3816 "\n\t\t: Removes selected or named objects."
3817 "\n\t\t If -context is in arguments, the objects are not deleted"
3818 "\n\t\t from the map of objects and names."
3819 "\n\t\t: Option -noupdate suppresses viewer redraw call.",
3820 __FILE__, VRemove, group);
3822 theCommands.Add("vdonly",
3823 "vdonly [-noupdate|-update] [name1] ... [name n]"
3824 "\n\t\t: Displays only selected or named objects",
3825 __FILE__,VDonly2,group);
3827 theCommands.Add("vdisplayall",
3828 "Displays all erased interactive objects (see vdir and vstate)",
3829 __FILE__,VDisplayAll,group);
3831 theCommands.Add("veraseall",
3832 "Erases all objects displayed in the viewer",
3833 __FILE__, VErase, group);
3835 theCommands.Add("verasetype",
3837 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3838 __FILE__,VEraseType,group);
3840 theCommands.Add("vdisplaytype",
3841 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3842 __FILE__,VDisplayType,group);
3844 theCommands.Add("vdisplaymode",
3845 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3846 __FILE__,VDispMode,group);
3848 theCommands.Add("verasemode",
3849 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3850 __FILE__,VDispMode,group);
3852 theCommands.Add("vsetdispmode",
3853 "vsetdispmode [name] mode(1,2,..)"
3854 "\n\t\t: Sets display mode for all, selected or named objects.",
3855 __FILE__,VDispMode,group);
3857 theCommands.Add("vunsetdispmode",
3858 "vunsetdispmode [name]"
3859 "\n\t\t: Unsets custom display mode for selected or named objects.",
3860 __FILE__,VDispMode,group);
3862 theCommands.Add("vdir",
3863 "Lists all objects displayed in 3D viewer",
3864 __FILE__,VDir,group);
3866 theCommands.Add("vdump",
3867 #ifdef HAVE_FREEIMAGE
3868 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
3869 "\n\t\t: [width Width=0 height Height=0]"
3870 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
3872 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
3873 "\n\t\t: [width Width=0 height Height=0]"
3874 "\n\t\t: Dumps content of the active view into PPM image file",
3876 __FILE__,VDump,group);
3878 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3879 __FILE__,VSubInt,group);
3881 theCommands.Add("vsetcolor",
3882 "vsetcolor [name] ColorName"
3883 "\n\t\t: Sets color for all, selected or named objects.",
3884 __FILE__,VColor2,group);
3886 theCommands.Add("vunsetcolor",
3887 "vunsetcolor [name]"
3888 "\n\t\t: Resets color for all, selected or named objects.",
3889 __FILE__,VColor2,group);
3891 theCommands.Add("vsettransparency",
3892 "vsettransparency [name] Coefficient"
3893 "\n\t\t: Sets transparency for all, selected or named objects."
3894 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3895 __FILE__,VTransparency,group);
3897 theCommands.Add("vunsettransparency",
3898 "vunsettransparency [name]"
3899 "\n\t\t: Resets transparency for all, selected or named objects.",
3900 __FILE__,VTransparency,group);
3902 theCommands.Add("vsetmaterial",
3903 "vmaterial : vmaterial [name of shape] MaterialName",
3904 __FILE__,VMaterial,group);
3906 theCommands.Add("vunsetmaterial",
3907 "vmaterial : vmaterial [name of shape]",
3908 __FILE__,VMaterial,group);
3910 theCommands.Add("vsetwidth",
3911 "vsetwidth : vwidth [name of shape] width(0->10)",
3912 __FILE__,VWidth,group);
3914 theCommands.Add("vunsetwidth",
3915 "vunsetwidth : vwidth [name of shape]",
3916 __FILE__,VWidth,group);
3918 theCommands.Add("vsetinteriorstyle",
3919 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3920 __FILE__,VInteriorStyle,group);
3922 theCommands.Add("vardis",
3923 "vardis : display activeareas",
3924 __FILE__,VDispAreas,group);
3926 theCommands.Add("varera",
3927 "varera : erase activeareas",
3928 __FILE__,VClearAreas,group);
3930 theCommands.Add("vsensdis",
3931 "vardisp : display active entities",
3932 __FILE__,VDispSensi,group);
3933 theCommands.Add("vsensera",
3934 "vardisp : erase active entities",
3935 __FILE__,VClearSensi,group);
3937 theCommands.Add("vselprecision",
3938 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3939 __FILE__,VSelPrecision,group);
3941 theCommands.Add("vperf",
3942 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3943 __FILE__,VPerf,group);
3945 theCommands.Add("vanimation",
3946 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3947 __FILE__,VAnimation,group);
3949 theCommands.Add("vsetshading",
3950 "vsetshading : vsetshading name Quality(default=0.0008) ",
3951 __FILE__,VShading,group);
3953 theCommands.Add("vunsetshading",
3954 "vunsetshading :vunsetshading name ",
3955 __FILE__,VShading,group);
3957 theCommands.Add ("vtexture",
3958 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
3959 " [-scale u v] [-scale off]\n"
3960 " [-origin u v] [-origin off]\n"
3961 " [-repeat u v] [-repeat off]\n"
3962 " [-modulate {on | off}]"
3964 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
3965 " specifying one of the predefined textures.\n"
3966 " The options are: \n"
3967 " -scale u v : enable texture scaling and set scale factors\n"
3968 " -scale off : disable texture scaling\n"
3969 " -origin u v : enable texture origin positioning and set the origin\n"
3970 " -origin off : disable texture origin positioning\n"
3971 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
3972 " -repeat off : disable texture repeat\n"
3973 " -modulate {on | off} : enable or disable texture modulation\n"
3974 " -default : sets texture mapping default parameters\n"
3975 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
3976 "or 'vtexture NameOfShape ?' to list available textures\n",
3977 __FILE__, VTexture, group);
3979 theCommands.Add("vtexscale",
3980 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3981 or 'vtexscale NameOfShape ScaleUV' \n \
3982 or 'vtexscale NameOfShape' to disable scaling\n ",
3983 __FILE__,VTexture,group);
3985 theCommands.Add("vtexorigin",
3986 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3987 or 'vtexorigin NameOfShape UVOrigin' \n \
3988 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3989 __FILE__,VTexture,group);
3991 theCommands.Add("vtexrepeat",
3992 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3993 or 'vtexrepeat NameOfShape UVRepeat \n \
3994 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3997 theCommands.Add("vtexdefault",
3998 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4001 theCommands.Add("vsetam",
4002 "vsetActivatedModes: vsetam mode(1->7) ",
4003 __FILE__,VActivatedMode,group);
4005 theCommands.Add("vunsetam",
4006 "vunsetActivatedModes: vunsetam ",
4007 __FILE__,VActivatedMode,group);
4009 theCommands.Add("vstate",
4010 "vstate [name1] ... [nameN]"
4011 "\n\t\t: Reports show/hidden state for selected or named objects",
4012 __FILE__,VState,group);
4014 theCommands.Add("vpickshapes",
4015 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4016 __FILE__,VPickShape,group);
4018 theCommands.Add("vtypes",
4019 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4022 theCommands.Add("vsettransmode",
4023 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4024 __FILE__,VSetTransMode,group);
4026 theCommands.Add("vr", "vr : reading of the shape",
4027 __FILE__,vr, group);
4031 //=====================================================================
4032 //========================= for testing Draft and Rib =================
4033 //=====================================================================
4034 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4035 #include <DBRep.hxx>
4036 #include <TopoDS_Face.hxx>
4037 #include <gp_Pln.hxx>
4038 #include <AIS_KindOfSurface.hxx>
4039 #include <BRepOffsetAPI_DraftAngle.hxx>
4040 #include <Precision.hxx>
4041 #include <BRepAlgo.hxx>
4042 #include <OSD_Environment.hxx>
4043 #include <DrawTrSurf.hxx>
4044 //#include <DbgTools.hxx>
4045 //#include <FeatAlgo_MakeLinearForm.hxx>
4050 //=======================================================================
4051 //function : IsValid
4053 //=======================================================================
4054 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4055 const TopoDS_Shape& theResult,
4056 const Standard_Boolean closedSolid,
4057 const Standard_Boolean GeomCtrl)
4059 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4060 TCollection_AsciiString checkValid = check.Value();
4061 Standard_Boolean ToCheck = Standard_True;
4062 if (!checkValid.IsEmpty()) {
4064 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4066 if ( checkValid=="true" || checkValid=="TRUE" ) {
4067 ToCheck= Standard_False;
4071 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4074 Standard_Boolean IsValid = Standard_True;
4076 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4081 //===============================================================================
4082 // TDraft : test draft, uses AIS Viewer
4083 // Solid Face Plane Angle Reverse
4084 //===============================================================================
4085 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4087 if (argc < 5) return 1;
4088 // argv[1] - TopoDS_Shape Solid
4089 // argv[2] - TopoDS_Shape Face
4090 // argv[3] - TopoDS_Shape Plane
4091 // argv[4] - Standard_Real Angle
4092 // argv[5] - Standard_Integer Reverse
4094 // Sprintf(prefix, argv[1]);
4095 Standard_Real anAngle = 0;
4096 Standard_Boolean Rev = Standard_False;
4097 Standard_Integer rev = 0;
4098 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4099 TopoDS_Shape face = GetShapeFromName(argv[2]);
4100 TopoDS_Face Face = TopoDS::Face(face);
4101 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4102 if (Plane.IsNull ()) {
4103 di << "TEST : Plane is NULL" << "\n";
4106 anAngle = Draw::Atof(argv[4]);
4107 anAngle = 2*M_PI * anAngle / 360.0;
4109 Handle( Geom_Surface )aSurf;
4110 AIS_KindOfSurface aSurfType;
4111 Standard_Real Offset;
4113 if(argc > 4) { // == 5
4114 rev = Draw::Atoi(argv[5]);
4115 Rev = (rev)? Standard_True : Standard_False;
4118 TopoDS_Face face2 = TopoDS::Face(Plane);
4119 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4121 di << "TEST : Can't find plane" << "\n";
4125 aDir = aPln.Axis().Direction();
4128 if (Plane.Orientation() == TopAbs_REVERSED)
4130 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4132 BRepOffsetAPI_DraftAngle Draft (Solid);
4134 if(Abs(anAngle)< Precision::Angular()) {
4135 di << "TEST : NULL angle" << "\n";
4138 if(Rev) anAngle = - anAngle;
4139 Draft.Add (Face, aDir, anAngle, aPln);
4141 if (!Draft.IsDone()) {
4142 di << "TEST : Draft Not DONE " << "\n";
4145 TopTools_ListOfShape Larg;
4147 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4148 di << "TEST : DesignAlgo returns Not valid" << "\n";
4152 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4153 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4155 if ( !ais.IsNull() ) {
4156 ais->SetColor(DEFAULT_COLOR);
4157 ais->SetMaterial(DEFAULT_MATERIAL);
4158 // Display the AIS_Shape without redraw
4159 Ctx->Display(ais, Standard_False);
4161 const char *Name = "draft1";
4162 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4164 Handle(AIS_InteractiveObject) an_object =
4165 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4166 if (!an_object.IsNull()) {
4167 Ctx->Remove(an_object,
4169 GetMapOfAIS().UnBind2(Name) ;
4172 GetMapOfAIS().Bind(ais, Name);
4173 // DBRep::Set("draft", ais->Shape());
4175 Ctx->Display(ais, Standard_True);
4179 //==============================================================================
4180 //function : splitParameter
4181 //purpose : Split parameter string to parameter name and parameter value
4182 //==============================================================================
4183 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4184 TCollection_AsciiString& theName,
4185 TCollection_AsciiString& theValue)
4187 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4189 if (aParamNameEnd == 0)
4191 return Standard_False;
4194 TCollection_AsciiString aString (theString);
4195 if (aParamNameEnd != 0)
4197 theValue = aString.Split (aParamNameEnd);
4198 aString.Split (aString.Length() - 1);
4202 return Standard_True;
4205 //============================================================================
4207 //============================================================================
4208 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4211 DrawTrSurf::BasicCommands(theCommands);
4212 const char* group = "Check Features Operations commands";
4214 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4216 &TDraft,group); //Draft_Modification
4219 //==============================================================================
4220 // ViewerTest::Factory
4221 //==============================================================================
4222 void ViewerTest::Factory(Draw_Interpretor& theDI)
4224 // definition of Viewer Command
4225 ViewerTest::Commands(theDI);
4226 ViewerTest::AviCommands(theDI);
4229 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4233 // Declare entry point PLUGINFACTORY