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 <Graphic3d_AspectFillArea3d.hxx>
52 #include <Graphic3d_AspectLine3d.hxx>
53 #include <Graphic3d_TextureRoot.hxx>
54 #include <Image_AlienPixMap.hxx>
55 #include <Prs3d_ShadingAspect.hxx>
56 #include <Prs3d_IsoAspect.hxx>
57 #include <TopTools_MapOfShape.hxx>
67 #include <Draw_Interpretor.hxx>
68 #include <TCollection_AsciiString.hxx>
69 #include <Draw_PluginMacro.hxx>
70 #include <ViewerTest.hxx>
72 // avoid warnings on 'extern "C"' functions returning C++ classes
74 #define _CRT_SECURE_NO_DEPRECATE
75 #pragma warning(4:4190)
76 #pragma warning (disable:4996)
79 #include <NIS_InteractiveContext.hxx>
80 #include <NIS_Triangulated.hxx>
81 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
83 #include <Quantity_Color.hxx>
84 #include <Quantity_NameOfColor.hxx>
86 #include <Graphic3d_NameOfMaterial.hxx>
88 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
89 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
91 enum ViewerTest_RedrawMode
93 ViewerTest_RM_Auto = -1,
94 ViewerTest_RM_RedrawForce,
95 ViewerTest_RM_RedrawSuppress
98 //! Auxiliary method to parse redraw mode argument
99 static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
100 ViewerTest_RedrawMode& theMode)
102 TCollection_AsciiString anArgCase (theArg);
103 anArgCase.LowerCase();
104 if (anArgCase == "-update"
105 || anArgCase == "-redraw")
107 theMode = ViewerTest_RM_RedrawForce;
108 return Standard_True;
110 else if (anArgCase == "-noupdate"
111 || anArgCase == "-noredraw")
113 theMode = ViewerTest_RM_RedrawSuppress;
114 return Standard_True;
116 return Standard_False;
119 //=======================================================================
120 //function : GetColorFromName
121 //purpose : get the Quantity_NameOfColor from a string
122 //=======================================================================
124 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
126 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
128 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
129 if (strcasecmp (theName, aColorName) == 0)
131 return Quantity_NameOfColor (anIter);
135 return DEFAULT_COLOR;
138 //=======================================================================
139 //function : GetMaterialFromName
140 //purpose : get the Graphic3d_NameOfMaterial from a string
141 //=======================================================================
143 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
145 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
147 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
148 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
149 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
150 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
151 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
152 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
153 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
154 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
155 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
156 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
157 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
158 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
159 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
160 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
161 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
162 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
163 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
164 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
165 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
170 //=======================================================================
171 //function : GetTypeNames
173 //=======================================================================
174 static const char** GetTypeNames()
176 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
177 "Shape","ConnectedShape","MultiConn.Shape",
178 "ConnectedInter.","MultiConn.",
179 "Constraint","Dimension"};
180 static const char** ThePointer = names;
184 //=======================================================================
185 //function : GetTypeAndSignfromString
187 //=======================================================================
188 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
190 const char ** thefullnames = GetTypeNames();
191 Standard_Integer index(-1);
193 for(Standard_Integer i=0;i<=13 && index==-1;i++)
194 if(!strcasecmp(name,thefullnames[i]))
198 TheType = AIS_KOI_None;
204 TheType = AIS_KOI_Datum;
208 TheType = AIS_KOI_Shape;
212 TheType = AIS_KOI_Object;
216 TheType = AIS_KOI_Relation;
225 #include <Draw_Interpretor.hxx>
227 #include <Draw_Appli.hxx>
231 #include <TCollection_AsciiString.hxx>
232 #include <V3d_Viewer.hxx>
233 #include <V3d_View.hxx>
236 #include <AIS_InteractiveContext.hxx>
237 #include <AIS_Shape.hxx>
238 #include <AIS_TexturedShape.hxx>
239 #include <AIS_DisplayMode.hxx>
240 #include <TColStd_MapOfInteger.hxx>
241 #include <AIS_MapOfInteractive.hxx>
242 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
243 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
244 #include <ViewerTest_EventManager.hxx>
246 #include <TopoDS_Solid.hxx>
247 #include <BRepTools.hxx>
248 #include <BRep_Builder.hxx>
249 #include <TopAbs_ShapeEnum.hxx>
251 #include <TopoDS.hxx>
252 #include <BRep_Tool.hxx>
255 #include <Draw_Window.hxx>
256 #include <AIS_ListIteratorOfListOfInteractive.hxx>
257 #include <AIS_ListOfInteractive.hxx>
258 #include <AIS_DisplayMode.hxx>
259 #include <TopTools_ListOfShape.hxx>
260 #include <BRepOffsetAPI_MakeThickSolid.hxx>
261 #include <BRepOffset.hxx>
263 //==============================================================================
264 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
265 //==============================================================================
266 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
267 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
272 //==============================================================================
273 //function : VDisplayAISObject
274 //purpose : register interactive object in the map of AIS objects;
275 // if other object with such name already registered, it will be kept
276 // or replaced depending on value of <theReplaceIfExists>,
277 // if "true" - the old object will be cleared from AIS context;
278 // returns Standard_True if <theAISObj> registered in map;
279 //==============================================================================
280 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
281 const Handle(AIS_InteractiveObject)& theAISObj,
282 Standard_Boolean theReplaceIfExists = Standard_True)
284 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
285 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
286 if (aContextAIS.IsNull())
288 std::cout << "AIS context is not available.\n";
289 return Standard_False;
292 if (aMap.IsBound2 (theName))
294 if (!theReplaceIfExists)
296 std::cout << "Other interactive object has been already "
297 << "registered with name: " << theName << ".\n"
298 << "Please use another name.\n";
299 return Standard_False;
302 // stop displaying object
303 Handle(AIS_InteractiveObject) anOldObj =
304 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
306 if (!anOldObj.IsNull())
307 aContextAIS->Clear (anOldObj, Standard_True);
309 // remove name and old object from map
310 aMap.UnBind2 (theName);
313 if (theAISObj.IsNull())
315 // object with specified name already unbound
316 return Standard_True;
319 // unbind AIS object if was bound with another name
320 aMap.UnBind1 (theAISObj);
322 // can be registered without rebinding
323 aMap.Bind (theAISObj, theName);
324 aContextAIS->Display (theAISObj, Standard_True);
325 return Standard_True;
328 static TColStd_MapOfInteger theactivatedmodes(8);
329 static TColStd_ListOfTransient theEventMgrs;
331 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
332 const Handle(AIS_InteractiveContext)& Ctx)
334 theEventMgrs.Clear();
335 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
338 static Handle(V3d_View)& a3DView()
340 static Handle(V3d_View) Viou;
345 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
346 static Handle(AIS_InteractiveContext) aContext;
350 const Handle(V3d_View)& ViewerTest::CurrentView()
354 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
359 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
361 static Handle(NIS_InteractiveContext) aContext;
362 if (aContext.IsNull()) {
363 aContext = new NIS_InteractiveContext;
364 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
369 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
371 return TheAISContext();
374 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
376 TheAISContext() = aCtx;
377 ViewerTest::ResetEventManager();
380 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
382 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
385 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
387 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
391 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
392 theEventMgrs.Prepend(EM);
395 void ViewerTest::UnsetEventManager()
397 theEventMgrs.RemoveFirst();
401 void ViewerTest::ResetEventManager()
403 const Handle(NIS_View) aView =
404 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
405 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
408 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
410 Handle(ViewerTest_EventManager) EM;
411 if(theEventMgrs.IsEmpty()) return EM;
412 Handle(Standard_Transient) Tr = theEventMgrs.First();
413 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
418 //=======================================================================
419 //function : Get Context and active viou..
421 //=======================================================================
422 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
423 Handle(V3d_View)& Viou)
425 Ctx = ViewerTest::GetAISContext();
428 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
429 Vwr->InitActiveViews();
430 if(Vwr->MoreActiveViews())
431 Viou = Vwr->ActiveView();
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,...
691 //purpose : Redraw the view
693 //==============================================================================
694 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
697 Handle(AIS_InteractiveContext) Ctx;
698 Handle(V3d_View) Viou;
699 GetCtxAndView(Ctx,Viou);
700 Ctx->DisplayActiveAreas(Viou);
703 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
705 Handle(AIS_InteractiveContext) Ctx;
706 Handle(V3d_View) Viou;
707 GetCtxAndView(Ctx,Viou);
708 Ctx->ClearActiveAreas(Viou);
712 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
714 Handle(AIS_InteractiveContext) Ctx;
715 Handle(V3d_View) Viou;
716 GetCtxAndView(Ctx,Viou);
717 Ctx->DisplayActiveSensitive(Viou);
721 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
723 Handle(AIS_InteractiveContext) Ctx;
724 Handle(V3d_View) Viou;
725 GetCtxAndView(Ctx,Viou);
726 Ctx->ClearActiveSensitive(Viou);
730 //==============================================================================
732 //purpose : To list the displayed object with their attributes
733 //==============================================================================
734 static int VDir (Draw_Interpretor& theDI,
738 if (!a3DView().IsNull())
743 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
744 anIter.More(); anIter.Next())
746 theDI << "\t" << anIter.Key2().ToCString() << "\n";
751 //==============================================================================
752 //function : VSelPrecision
753 //purpose : To set the selection precision mode and tolerance value
754 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
755 // value (integer number of pixel for window mode, double value of
756 // sensitivity for view mode). Without arguments the function just
757 // prints the current precision mode and the corresponding tolerance.
758 //==============================================================================
759 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
763 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
767 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
768 if( aContext.IsNull() )
773 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
774 if( aMode == StdSelect_SM_WINDOW )
776 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
777 di << "Precision mode : 0 (window)\n";
778 di << "Pixel tolerance : " << aPixelTolerance << "\n";
780 else if( aMode == StdSelect_SM_VIEW )
782 Standard_Real aSensitivity = aContext->Sensitivity();
783 di << "Precision mode : 1 (view)\n";
784 di << "Sensitivity : " << aSensitivity << "\n";
789 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
790 aContext->SetSensitivityMode( aMode );
793 if( aMode == StdSelect_SM_WINDOW )
795 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
796 aContext->SetPixelTolerance( aPixelTolerance );
798 else if( aMode == StdSelect_SM_VIEW )
800 Standard_Real aSensitivity = Draw::Atof( argv[2] );
801 aContext->SetSensitivity( aSensitivity );
808 //==============================================================================
810 //purpose : To dump the active view snapshot to image file
811 //Draw arg : Picture file name with extension corresponding to desired format
812 //==============================================================================
813 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
817 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]\n";
821 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
824 const char* aBuffTypeStr = argv[2];
825 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
827 aBufferType = Graphic3d_BT_RGB;
829 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
831 aBufferType = Graphic3d_BT_RGBA;
833 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
835 aBufferType = Graphic3d_BT_Depth;
839 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
840 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
842 TCollection_AsciiString aStereoProj ((argc > 5) ? argv[5] : "");
844 Handle(AIS_InteractiveContext) IC;
845 Handle(V3d_View) view;
846 GetCtxAndView (IC, view);
849 di << "Cannot find an active viewer/view\n";
853 if (aWidth <= 0 || aHeight <= 0)
855 if (!view->Dump (argv[1], aBufferType))
857 di << "Dumping failed!\n";
863 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
865 if (!aStereoProj.IsEmpty())
867 aStereoProj.UpperCase();
868 if (aStereoProj == "L")
870 aStereoOpts = V3d_SDO_LEFT_EYE;
873 if (aStereoProj == "R")
875 aStereoOpts = V3d_SDO_RIGHT_EYE;
879 Image_AlienPixMap aPixMap;
880 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
882 di << "Dumping failed!\n";
886 if (aPixMap.SizeX() != Standard_Size(aWidth)
887 || aPixMap.SizeY() != Standard_Size(aHeight))
889 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
890 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
892 if (!aPixMap.Save (argv[1]))
894 di << "Saving image failed!\n";
901 //==============================================================================
902 //function : Displays,Erase...
905 //==============================================================================
906 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
907 const Standard_Integer Mode,
908 const Standard_Integer TypeOfOperation,
909 const Standard_Boolean Upd)
911 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
913 switch(TypeOfOperation){
915 Ctx->Display(IO,Mode,Upd);
923 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
925 Ctx->SetDisplayMode(IO,Mode,Upd);
930 Ctx->SetDisplayMode(0,Upd);
932 Ctx->UnsetDisplayMode(IO,Upd);
939 //=======================================================================
942 //=======================================================================
943 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
946 TCollection_AsciiString name;
949 // display others presentations
950 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
951 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
952 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
953 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
955 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
957 //unset displaymode.. comportement particulier...
958 if(TypeOfOperation==4){
960 if(Ctx->NbCurrents()==0 ||
961 Ctx->NbSelected()==0){
962 Handle(AIS_InteractiveObject) IO;
963 VwrTst_DispErase(IO,-1,4,Standard_False);
965 else if(!Ctx->HasOpenedContext()){
966 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
967 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
970 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
971 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
972 Ctx->UpdateCurrentViewer();
975 Handle(AIS_InteractiveObject) IO;
977 if(GetMapOfAIS().IsBound2(name)){
978 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
980 VwrTst_DispErase(IO,-1,4,Standard_True);
985 Standard_Integer Dmode = Draw::Atoi(argv[1]);
986 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
987 Handle(AIS_InteractiveObject) IO;
988 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
990 if(!Ctx->HasOpenedContext()){
991 // set/unset display mode sur le Contexte...
992 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
993 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
995 Ctx->UpdateCurrentViewer();
998 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
999 Ctx->Display(Ctx->Interactive(),Dmode);
1003 Handle(AIS_InteractiveObject) IO;
1005 if(GetMapOfAIS().IsBound2(name))
1006 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1008 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1014 //=======================================================================
1017 //=======================================================================
1018 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1020 if(argc==1) return 1;
1021 Standard_Integer On = Draw::Atoi(argv[1]);
1022 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1026 if(!Ctx->HasOpenedContext()){
1027 di<<"sub intensite ";
1030 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1031 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1033 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1035 di <<"passage dans off"<<"\n";
1036 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1041 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1043 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1045 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1048 Ctx->UpdateCurrentViewer();
1051 Handle(AIS_InteractiveObject) IO;
1052 TCollection_AsciiString name = argv[2];
1053 if(GetMapOfAIS().IsBound2(name)){
1054 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1057 Ctx->SubIntensityOn(IO);
1059 Ctx->SubIntensityOff(IO);
1067 //==============================================================================
1068 //function : VColor2
1070 //purpose : change the color of a selected or named or displayed shape
1071 //Draw arg : vcolor2 [name] color
1072 //==============================================================================
1073 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1076 Standard_Boolean ThereIsCurrent;
1077 Standard_Boolean ThereIsArgument;
1078 Standard_Boolean IsBound = Standard_False ;
1080 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1082 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1083 ThereIsArgument = (argc != 2);
1086 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1087 ThereIsArgument = (argc == 2);
1090 if ( !a3DView().IsNull() ) {
1091 TCollection_AsciiString name;
1092 if (ThereIsArgument) {
1094 IsBound= GetMapOfAIS().IsBound2(name);
1096 if (TheAISContext()->HasOpenedContext())
1097 TheAISContext()->CloseLocalContext();
1099 // On set le Booleen There is current
1100 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1101 else ThereIsCurrent =Standard_False;
1103 //=======================================================================
1104 // Il y a un argument
1105 //=======================================================================
1106 if ( ThereIsArgument && IsBound ) {
1107 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1108 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1109 Handle(AIS_InteractiveObject) ashape =
1110 Handle(AIS_InteractiveObject)::DownCast (anObj);
1113 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1115 di << "HaveToSet 0\n";
1119 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1121 TheAISContext()->UnsetColor(ashape);
1122 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1123 Handle(NIS_Triangulated) ashape =
1124 Handle(NIS_Triangulated)::DownCast (anObj);
1125 if (!ashape.IsNull())
1126 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1131 //=======================================================================
1132 // Il n'y a pas d'arguments
1133 // Mais un ou plusieurs objets on des current representation
1134 //=======================================================================
1135 if (ThereIsCurrent && !ThereIsArgument) {
1136 for (TheAISContext() -> InitCurrent() ;
1137 TheAISContext() -> MoreCurrent() ;
1138 TheAISContext() ->NextCurrent() )
1140 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1141 if (ashape.IsNull())
1145 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1147 di << "HaveToSet 0\n";
1150 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1152 TheAISContext()->UnsetColor(ashape,Standard_False);
1155 TheAISContext()->UpdateCurrentViewer();
1158 //=======================================================================
1159 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1160 // on impose a tous les objets du viewer la couleur passee
1161 //=======================================================================
1162 else if (!ThereIsCurrent && !ThereIsArgument){
1163 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1164 while ( it.More() ) {
1165 const Handle(AIS_InteractiveObject) ashape =
1166 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1167 if (!ashape.IsNull()) {
1169 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1171 TheAISContext()->UnsetColor(ashape,Standard_False);
1175 TheAISContext()->UpdateCurrentViewer();
1181 //==============================================================================
1182 //function : VTransparency
1184 //purpose : change the transparency of a selected or named or displayed shape
1185 //Draw arg : vtransparency [name] TransparencyCoeficient
1186 //==============================================================================
1188 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1191 Standard_Boolean ThereIsCurrent;
1192 Standard_Boolean ThereIsArgument;
1193 Standard_Boolean IsBound = Standard_False ;
1195 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1197 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1198 ThereIsArgument = (argc != 2);
1201 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1202 ThereIsArgument = (argc == 2);
1205 if ( !a3DView().IsNull() ) {
1206 TCollection_AsciiString name;
1207 if (ThereIsArgument) {
1209 IsBound= GetMapOfAIS().IsBound2(name);
1211 if (TheAISContext()->HasOpenedContext())
1212 TheAISContext()->CloseLocalContext();
1214 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1215 else ThereIsCurrent = Standard_False;
1217 //=======================================================================
1218 // Il y a des arguments: un nom et une couleur
1219 //=======================================================================
1220 if ( ThereIsArgument && IsBound ) {
1221 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1222 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1223 const Handle(AIS_InteractiveObject) ashape =
1224 Handle(AIS_InteractiveObject)::DownCast(anObj);
1226 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1228 TheAISContext()->UnsetTransparency(ashape);
1229 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1230 const Handle(NIS_InteractiveObject) ashape =
1231 Handle(NIS_InteractiveObject)::DownCast(anObj);
1233 ashape->SetTransparency(Draw::Atof(argv[2]) );
1235 ashape->UnsetTransparency();
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 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1249 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1251 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1254 TheAISContext()->UpdateCurrentViewer();
1256 //=======================================================================
1257 // Il n'y a pas d'arguments ET aucun objet courrant
1258 //=======================================================================
1259 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1260 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1262 while ( it.More() ) {
1263 Handle(AIS_InteractiveObject) ashape =
1264 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1265 if (!ashape.IsNull()) {
1267 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1269 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1273 TheAISContext()->UpdateCurrentViewer();
1280 //==============================================================================
1281 //function : VMaterial
1283 //purpose : change the Material of a selected or named or displayed shape
1284 //Draw arg : vmaterial [Name] Material
1285 //==============================================================================
1286 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1289 Standard_Boolean ThereIsCurrent;
1290 Standard_Boolean ThereIsName;
1291 Standard_Boolean IsBound = Standard_False ;
1293 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1295 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1296 ThereIsName = (argc != 2);
1299 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1300 ThereIsName = (argc == 2);
1303 if ( !a3DView().IsNull() ) {
1304 TCollection_AsciiString name;
1307 IsBound= GetMapOfAIS().IsBound2(name);
1309 if (TheAISContext()->HasOpenedContext())
1310 TheAISContext()->CloseLocalContext();
1311 if (TheAISContext() -> NbCurrents() > 0 )
1312 ThereIsCurrent =Standard_True;
1314 ThereIsCurrent =Standard_False;
1316 //=======================================================================
1317 // Ther is a name of shape and a material name
1318 //=======================================================================
1319 if ( ThereIsName && IsBound ) {
1320 Handle(AIS_InteractiveObject) ashape =
1321 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1322 if (!ashape.IsNull()) {
1324 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1326 TheAISContext()->UnsetMaterial(ashape);
1329 //=======================================================================
1330 // Il n'y a pas de nom de shape
1331 // Mais un ou plusieurs objets on des current representation
1332 //=======================================================================
1333 if (ThereIsCurrent && !ThereIsName) {
1334 for (TheAISContext() -> InitCurrent() ;
1335 TheAISContext() -> MoreCurrent() ;
1336 TheAISContext() ->NextCurrent() )
1338 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1340 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1342 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1344 TheAISContext()->UpdateCurrentViewer();
1347 //=======================================================================
1348 // Il n'y a pas de noms de shape ET aucun objet courrant
1349 // On impose a tous les objets du viewer le material passe en argument
1350 //=======================================================================
1351 else if (!ThereIsCurrent && !ThereIsName){
1352 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1354 while ( it.More() ) {
1355 Handle(AIS_InteractiveObject) ashape =
1356 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1357 if (!ashape.IsNull()) {
1359 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1361 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1365 TheAISContext()->UpdateCurrentViewer();
1373 //==============================================================================
1376 //purpose : change the width of the edges of a selected or named or displayed shape
1377 //Draw arg : vwidth [Name] WidthValue(1->10)
1378 //==============================================================================
1379 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1382 Standard_Boolean ThereIsCurrent;
1383 Standard_Boolean ThereIsArgument;
1384 Standard_Boolean IsBound = Standard_False ;
1386 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1388 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1389 ThereIsArgument = (argc != 2);
1392 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1393 ThereIsArgument = (argc == 2);
1395 if ( !a3DView().IsNull() ) {
1396 TCollection_AsciiString name;
1397 if (ThereIsArgument) {
1399 IsBound= GetMapOfAIS().IsBound2(name);
1401 if (TheAISContext()->HasOpenedContext())
1402 TheAISContext()->CloseLocalContext();
1404 if (TheAISContext() -> NbCurrents() > 0 )
1405 ThereIsCurrent =Standard_True;
1407 ThereIsCurrent =Standard_False;
1409 if ( ThereIsArgument && IsBound ) {
1410 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1411 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1412 const Handle(AIS_InteractiveObject) ashape =
1413 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1415 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1417 TheAISContext()->UnsetWidth (ashape);
1418 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1419 const Handle(NIS_Triangulated) ashape =
1420 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1421 if (HaveToSet && !ashape.IsNull())
1422 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1426 //=======================================================================
1427 // Il n'y a pas d'arguments
1428 // Mais un ou plusieurs objets on des current representation
1429 //=======================================================================
1430 if (ThereIsCurrent && !ThereIsArgument) {
1431 for (TheAISContext() -> InitCurrent() ;
1432 TheAISContext() -> MoreCurrent() ;
1433 TheAISContext() ->NextCurrent() )
1435 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1437 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1439 TheAISContext()->UnsetWidth(ashape,Standard_False);
1441 TheAISContext()->UpdateCurrentViewer();
1443 //=======================================================================
1444 // Il n'y a pas d'arguments ET aucun objet courrant
1445 //=======================================================================
1446 else if (!ThereIsCurrent && !ThereIsArgument){
1447 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1449 while ( it.More() ) {
1450 Handle(AIS_InteractiveObject) ashape =
1451 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1452 if (!ashape.IsNull()) {
1454 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1456 TheAISContext()->UnsetWidth(ashape,Standard_False);
1460 TheAISContext()->UpdateCurrentViewer();
1466 //==============================================================================
1467 //function : VInteriorStyle
1468 //purpose : sets interior style of the a selected or named or displayed shape
1469 //Draw arg : vsetinteriorstyle [shape] style
1470 //==============================================================================
1471 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1472 const Standard_Integer theStyle,
1473 Draw_Interpretor& di)
1475 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1476 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1477 " (Aspect_IS_HIDDENLINE)]\n";
1480 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1481 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1482 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1483 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1484 aFillAspect->SetInteriorStyle (aStyle);
1485 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1488 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1490 if (argc < 2 || argc > 3) {
1491 di << argv[0] << " requires 2 or 3 arguments\n";
1492 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1493 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1494 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1498 Standard_Boolean ThereIsCurrent;
1499 Standard_Boolean ThereIsArgument;
1500 Standard_Boolean IsBound = Standard_False ;
1502 ThereIsArgument = (argc > 2);
1503 if ( !a3DView().IsNull() ) {
1504 TCollection_AsciiString name;
1505 if (ThereIsArgument) {
1507 IsBound= GetMapOfAIS().IsBound2(name);
1509 if (TheAISContext()->HasOpenedContext())
1510 TheAISContext()->CloseLocalContext();
1512 if (TheAISContext() -> NbCurrents() > 0 )
1513 ThereIsCurrent =Standard_True;
1515 ThereIsCurrent =Standard_False;
1517 if ( ThereIsArgument && IsBound ) {
1518 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1519 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1520 const Handle(AIS_InteractiveObject) ashape =
1521 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1522 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1525 //=======================================================================
1526 // No arguments specified
1527 // But there are one or more selected objects
1528 //=======================================================================
1529 if (ThereIsCurrent && !ThereIsArgument) {
1530 for (TheAISContext() -> InitCurrent() ;
1531 TheAISContext() -> MoreCurrent() ;
1532 TheAISContext() ->NextCurrent() )
1534 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1535 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1538 //=======================================================================
1539 // No arguments specified and there are no selected objects
1540 //=======================================================================
1541 else if (!ThereIsCurrent && !ThereIsArgument){
1542 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1544 while ( it.More() ) {
1545 Handle(AIS_InteractiveObject) ashape =
1546 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1547 if (!ashape.IsNull())
1548 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1552 TheAISContext()->UpdateCurrentViewer();
1557 //==============================================================================
1558 //function : VDonly2
1560 //purpose : Display only a selected or named object
1561 // if there is no selected or named object s, nothing is done
1562 //==============================================================================
1563 static int VDonly2 (Draw_Interpretor& ,
1564 Standard_Integer theArgNb,
1565 const char** theArgVec)
1567 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1570 std::cerr << "Error: no active view!\n";
1574 if (aCtx->HasOpenedContext())
1576 aCtx->CloseLocalContext();
1578 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1580 Standard_Integer anArgIter = 1;
1581 for (; anArgIter < theArgNb; ++anArgIter)
1583 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1589 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1590 if (anArgIter >= theArgNb)
1592 // display only selected objects
1593 if (aCtx->NbCurrents() < 1)
1598 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1600 aDispSet.Add (aCtx->Current());
1605 // display only specified objects
1606 for (; anArgIter < theArgNb; ++anArgIter)
1608 TCollection_AsciiString aName = theArgVec[anArgIter];
1609 if (GetMapOfAIS().IsBound2 (aName))
1611 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1612 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1614 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1615 aCtx->Display (aShape, Standard_False);
1617 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1619 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1620 TheNISContext()->Display (aShape);
1622 aDispSet.Add (anObj);
1627 // weed out other objects
1628 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1630 if (aDispSet.Contains (anIter.Key1()))
1635 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1637 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1638 aCtx->Erase (aShape, Standard_False);
1640 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1642 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1643 TheNISContext()->Erase (aShape);
1647 // update the screen and redraw the view
1648 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1649 a3DView()->SetImmediateUpdate (isAutoUpdate);
1650 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1651 || aToUpdate == ViewerTest_RM_RedrawForce)
1653 TheAISContext()->UpdateCurrentViewer();
1659 //==============================================================================
1660 //function : VRemove
1661 //purpose : Removes selected or named objects.
1662 // If there is no selected or named objects,
1663 // all objects in the viewer can be removed with argument -all.
1664 // If -context is in arguments, the object is not deleted from the map of
1665 // objects (deleted only from the current context).
1666 //==============================================================================
1667 int VRemove (Draw_Interpretor& theDI,
1668 Standard_Integer theArgNb,
1669 const char** theArgVec)
1671 if (a3DView().IsNull())
1673 std::cout << "Error: wrong syntax!\n";
1677 TheAISContext()->CloseAllContexts (Standard_False);
1679 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1680 Standard_Boolean isContextOnly = Standard_False;
1681 Standard_Boolean toRemoveAll = Standard_False;
1683 Standard_Integer anArgIter = 1;
1684 for (; anArgIter < theArgNb; ++anArgIter)
1686 TCollection_AsciiString anArg = theArgVec[anArgIter];
1688 if (anArg == "-context")
1690 isContextOnly = Standard_True;
1692 else if (anArg == "-all")
1694 toRemoveAll = Standard_True;
1696 else if (!parseRedrawMode (anArg, aToUpdate))
1702 && anArgIter < theArgNb)
1704 std::cout << "Error: wrong syntax!\n";
1708 NCollection_List<TCollection_AsciiString> anIONameList;
1711 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1712 anIter.More(); anIter.Next())
1714 anIONameList.Append (anIter.Key2());
1717 else if (anArgIter < theArgNb) // removed objects names are in argument list
1719 for (; anArgIter < theArgNb; ++anArgIter)
1721 TCollection_AsciiString aName = theArgVec[anArgIter];
1722 if (!GetMapOfAIS().IsBound2 (aName))
1724 theDI << aName.ToCString() << " was not bound to some object.\n";
1728 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
1730 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
1733 if (anIO->GetContext() != TheAISContext())
1735 theDI << aName.ToCString() << " was not displayed in current context.\n";
1736 theDI << "Please activate view with this object displayed and try again.\n";
1740 anIONameList.Append (aName);
1744 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
1745 if (!aNisIO.IsNull())
1747 anIONameList.Append (aName);
1751 else if (TheAISContext()->NbCurrents() > 0
1752 || TheNISContext()->GetSelected().Extent() > 0)
1754 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1755 anIter.More(); anIter.Next())
1757 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1760 if (!TheAISContext()->IsCurrent (anIO))
1765 anIONameList.Append (anIter.Key2());
1769 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1770 if (!aNisIO.IsNull())
1772 if (!TheNISContext()->IsSelected (aNisIO))
1777 anIONameList.Append (anIter.Key2());
1782 // Unbind all removed objects from the map of displayed IO.
1783 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
1784 anIter.More(); anIter.Next())
1786 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1790 TheAISContext()->Remove (anIO, Standard_False);
1791 theDI << anIter.Value().ToCString() << " was removed\n";
1795 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1796 if (!aNisIO.IsNull())
1798 TheNISContext()->Remove (aNisIO);
1799 theDI << anIter.Value().ToCString() << " was removed\n";
1805 GetMapOfAIS().UnBind2 (anIter.Value());
1809 // update the screen and redraw the view
1810 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1811 a3DView()->SetImmediateUpdate (isAutoUpdate);
1812 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1813 || aToUpdate == ViewerTest_RM_RedrawForce)
1815 TheAISContext()->UpdateCurrentViewer();
1821 //==============================================================================
1823 //purpose : Erase some selected or named objects
1824 // if there is no selected or named objects, the whole viewer is erased
1825 //==============================================================================
1826 int VErase (Draw_Interpretor& theDI,
1827 Standard_Integer theArgNb,
1828 const char** theArgVec)
1830 if (a3DView().IsNull())
1832 std::cout << "Error: no active view!\n";
1835 TheAISContext()->CloseAllContexts (Standard_False);
1837 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1838 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
1840 Standard_Integer anArgIter = 1;
1841 for (; anArgIter < theArgNb; ++anArgIter)
1843 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1849 if (anArgIter < theArgNb)
1853 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
1857 // has a list of names
1858 for (; anArgIter < theArgNb; ++anArgIter)
1860 TCollection_AsciiString aName = theArgVec[anArgIter];
1861 if (!GetMapOfAIS().IsBound2 (aName))
1866 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1867 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1868 theDI << aName.ToCString() << " ";
1871 TheAISContext()->Erase (anIO, Standard_False);
1875 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1876 if (!aNisIO.IsNull())
1878 TheNISContext()->Erase (aNisIO);
1883 else if (!toEraseAll
1884 && TheAISContext()->NbCurrents() > 0)
1886 // remove all currently selected objects
1887 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1888 anIter.More(); anIter.Next())
1890 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1892 && TheAISContext()->IsCurrent (anIO))
1894 theDI << anIter.Key2().ToCString() << " ";
1895 TheAISContext()->Erase (anIO, Standard_False);
1901 // erase entire viewer
1902 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1903 anIter.More(); anIter.Next())
1905 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1908 TheAISContext()->Erase (anIO, Standard_False);
1912 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1913 if (!aNisIO.IsNull())
1915 TheNISContext()->Erase (aNisIO);
1921 // update the screen and redraw the view
1922 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
1923 a3DView()->SetImmediateUpdate (isAutoUpdate);
1924 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
1925 || aToUpdate == ViewerTest_RM_RedrawForce)
1927 TheAISContext()->UpdateCurrentViewer();
1933 //==============================================================================
1934 //function : VDisplayAll
1936 //purpose : Display all the objects of the Map
1937 //==============================================================================
1938 static int VDisplayAll (Draw_Interpretor& ,
1939 Standard_Integer theArgNb,
1940 const char** theArgVec)
1943 if (a3DView().IsNull())
1945 std::cout << "Error: no active view!\n";
1949 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
1951 Standard_Integer anArgIter = 1;
1952 for (; anArgIter < theArgNb; ++anArgIter)
1954 if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
1959 if (anArgIter < theArgNb)
1961 std::cout << theArgVec[0] << "Error: wrong syntax\n";
1965 if (TheAISContext()->HasOpenedContext())
1967 TheAISContext()->CloseLocalContext();
1970 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1971 anIter.More(); anIter.Next())
1973 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1975 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1976 TheAISContext()->Erase (aShape, Standard_False);
1978 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
1980 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1981 TheNISContext()->Erase (aShape);
1985 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1986 anIter.More(); anIter.Next())
1988 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1990 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1991 TheAISContext()->Display (aShape, Standard_False);
1993 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1995 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1996 TheNISContext()->Display (aShape);
2000 // update the screen and redraw the view
2001 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2002 a3DView()->SetImmediateUpdate (isAutoUpdate);
2003 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2004 || aToUpdate == ViewerTest_RM_RedrawForce)
2006 TheAISContext()->UpdateCurrentViewer();
2012 //#######################################################################################################
2016 //#######################################################################################################
2018 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
2020 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
2021 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
2022 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
2023 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
2024 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
2026 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
2027 if(myAISContext.IsNull())
2029 di << "use 'vinit' command before " << argv[0] << "\n";
2033 Handle(AIS_InteractiveObject) TheAisIO;
2034 Handle(AIS_TexturedShape) myShape;
2035 Standard_Integer myPreviousMode = 0;
2037 if (argc<2 || !argv[1])
2039 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
2043 TCollection_AsciiString name = argv[1];
2044 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
2046 if (GetMapOfAIS().IsBound2(name))
2047 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
2048 (GetMapOfAIS().Find2(name));
2049 if (TheAisIO.IsNull())
2051 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
2055 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
2057 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
2058 myPreviousMode = myShape->DisplayMode() ;
2062 myAISContext->Clear(TheAisIO,Standard_False);
2063 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
2064 GetMapOfAIS().UnBind1(TheAisIO);
2065 GetMapOfAIS().UnBind2(name);
2066 GetMapOfAIS().Bind(myShape, name);
2070 case 1: // vtexture : we only map a texture on the shape
2073 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2076 if (argc>2 && argv[2])
2078 if(strcasecmp(argv[2],"?")==0)
2080 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
2081 di<<"\n Files in current directory : \n"<<"\n";
2082 TCollection_AsciiString Cmnd ("glob -nocomplain *");
2083 di.Eval(Cmnd.ToCString());
2085 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
2088 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
2089 di.Eval(Cmnd.ToCString());
2094 myShape->SetTextureFileName(argv[2]);
2098 di <<"Texture mapping disabled \n \
2099 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
2101 myAISContext->SetDisplayMode(myShape,1,Standard_False);
2102 if (myPreviousMode == 3 )
2103 myAISContext->RecomputePrsOnly(myShape);
2104 myAISContext->Display(myShape, Standard_True);
2109 case 2: // vtexscale : we change the scaling factor of the texture
2113 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2117 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
2118 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
2119 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
2122 case 3: // vtexorigin : we change the origin of the texture on the shape
2125 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2128 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
2129 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
2130 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
2133 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
2136 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2139 if (argc>2 && argv[2])
2141 di <<"Texture repeat enabled"<<"\n";
2142 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
2146 di <<"Texture repeat disabled"<<"\n";
2147 myShape->SetTextureRepeat(Standard_False);
2151 case 5: // vtexdefault : default texture mapping
2152 // ScaleU = ScaleV = 100.0
2153 // URepeat = VRepeat = 1.0
2154 // Uorigin = VOrigin = 0.0
2158 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2161 myShape->SetTextureRepeat(Standard_False);
2162 myShape->SetTextureOrigin(Standard_False);
2163 myShape->SetTextureScale (Standard_False);
2167 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
2168 myAISContext->RecomputePrsOnly(myShape);
2171 myAISContext->SetDisplayMode(myShape,3,Standard_False);
2172 myAISContext->Display(myShape, Standard_True);
2173 myAISContext->Update(myShape,Standard_True);
2178 //==============================================================================
2179 //function : VDisplay2
2181 //purpose : Display an object from its name
2182 //==============================================================================
2183 static int VDisplay2 (Draw_Interpretor& theDI,
2184 Standard_Integer theArgNb,
2185 const char** theArgVec)
2189 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2192 else if (a3DView().IsNull())
2194 ViewerTest::ViewerInit();
2195 std::cout << "Command vinit should be called before!\n";
2199 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2200 if (aCtx->HasOpenedContext())
2202 aCtx->CloseLocalContext();
2205 ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
2206 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2208 const TCollection_AsciiString aName = theArgVec[anArgIter];
2209 if (parseRedrawMode (aName, aToUpdate))
2213 else if (!GetMapOfAIS().IsBound2 (aName))
2215 // create the AIS_Shape from a name
2216 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2217 if (!aShape.IsNull())
2219 GetMapOfAIS().Bind (aShape, aName);
2220 aCtx->Display (aShape, Standard_False);
2225 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2226 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2228 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2229 if (aShape->Type() == AIS_KOI_Datum)
2231 aCtx->Display (aShape, Standard_False);
2235 theDI << "Display " << aName.ToCString() << "\n";
2236 // get the Shape from a name
2237 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2239 // update the Shape in the AIS_Shape
2240 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2241 if (!aShapePrs.IsNull())
2243 aShapePrs->Set (aNewShape);
2245 aCtx->Redisplay (aShape, Standard_False);
2246 aCtx->Display (aShape, Standard_False);
2250 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2252 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2253 TheNISContext()->Display (aShape);
2257 const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
2258 a3DView()->SetImmediateUpdate (isAutoUpdate);
2259 if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
2260 || aToUpdate == ViewerTest_RM_RedrawForce)
2262 // update the screen and redraw the view
2263 aCtx->UpdateCurrentViewer();
2268 //===============================================================================================
2269 //function : VUpdate
2271 //===============================================================================================
2272 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2274 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2275 if (aContextAIS.IsNull())
2277 std::cout << theArgVec[0] << "AIS context is not available.\n";
2283 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2287 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2289 AIS_ListOfInteractive aListOfIO;
2291 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2293 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2295 Handle(AIS_InteractiveObject) anAISObj;
2296 if (anAISMap.IsBound2 (aName))
2298 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2301 if (anAISObj.IsNull())
2303 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2307 aListOfIO.Append (anAISObj);
2310 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2311 for (; anIOIt.More(); anIOIt.Next())
2313 aContextAIS->Update (anIOIt.Value(), Standard_False);
2316 aContextAIS->UpdateCurrentViewer();
2321 //==============================================================================
2323 //purpose : Test the annimation of an object along a
2324 // predifined trajectory
2325 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2326 //==============================================================================
2328 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2331 if (TheAISContext()->HasOpenedContext())
2332 TheAISContext()->CloseLocalContext();
2334 Standard_Real Step=4*M_PI/180;
2335 Standard_Real Angle=0;
2337 Handle(AIS_InteractiveObject) aIO;
2338 if (GetMapOfAIS().IsBound2(argv[1]))
2339 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2343 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2347 if (Draw::Atoi(argv[3])==1 ) {
2348 di<<" Primitives sensibles OFF"<<"\n";
2349 TheAISContext()->Deactivate(aIO);
2352 di<<" Primitives sensibles ON"<<"\n";
2354 // Movement par transformation
2355 if(Draw::Atoi(argv[2]) ==1) {
2356 di<<" Calcul par Transformation"<<"\n";
2357 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2361 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2362 TheAISContext()->SetLocation(aShape,myTransfo);
2363 TheAISContext() ->UpdateCurrentViewer();
2368 di<<" Calcul par Locations"<<"\n";
2369 gp_Trsf myAngleTrsf;
2370 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2371 TopLoc_Location myDeltaAngle (myAngleTrsf);
2372 TopLoc_Location myTrueLoc;
2374 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2377 myTrueLoc=myTrueLoc*myDeltaAngle;
2378 TheAISContext()->SetLocation(aShape,myTrueLoc );
2379 TheAISContext() ->UpdateCurrentViewer();
2382 if (Draw::Atoi(argv[3])==1 ){
2383 // On reactive la selection des primitives sensibles
2384 TheAISContext()->Activate(aIO,0);
2386 a3DView() -> Redraw();
2388 di<<" Temps ecoule "<<"\n";
2394 //==================================================================================
2395 // Function : VAnimation
2396 //==================================================================================
2397 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2399 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2403 Standard_Real thread = 4;
2404 Standard_Real angleA=0;
2405 Standard_Real angleB;
2407 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2410 TopoDS_Shape CrankArm;
2411 TopoDS_Shape CylinderHead;
2412 TopoDS_Shape Propeller;
2413 TopoDS_Shape EngineBlock;
2415 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2416 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2417 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2418 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2419 BRepTools::Read(CrankArm,argv[1],B);
2420 BRepTools::Read(CylinderHead,argv[2],B);
2421 BRepTools::Read(Propeller,argv[3],B);
2422 BRepTools::Read(EngineBlock,argv[4],B);
2424 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2430 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2431 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2432 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2433 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2435 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2436 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2437 GetMapOfAIS().Bind(myAisCrankArm,"c");
2438 GetMapOfAIS().Bind(myAisPropeller,"d");
2440 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2441 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2442 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2444 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2445 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2446 TheAISContext()->Display(myAisCrankArm,Standard_False );
2447 TheAISContext()->Display(myAisPropeller,Standard_False);
2449 TheAISContext()->Deactivate(myAisCylinderHead);
2450 TheAISContext()->Deactivate(myAisEngineBlock );
2451 TheAISContext()->Deactivate(myAisCrankArm );
2452 TheAISContext()->Deactivate(myAisPropeller );
2454 // Boucle de mouvement
2455 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2457 angleA = thread*myAngle*M_PI/180;
2458 X = Sin(angleA)*3/8;
2459 angleB = atan(X / Sqrt(-X * X + 1));
2460 Standard_Real decal(25*0.6);
2463 //Build a transformation on the display
2464 gp_Trsf aPropellerTrsf;
2465 aPropellerTrsf.SetRotation(Ax1,angleA);
2466 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2468 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));
2469 gp_Trsf aCrankArmTrsf;
2470 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2471 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2473 TheAISContext()->UpdateCurrentViewer();
2476 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2477 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2479 myAisCrankArm ->ResetLocation();
2480 myAisPropeller->ResetLocation();
2482 myAisCrankArm -> Set(myNewCrankArm );
2483 myAisPropeller -> Set(myNewPropeller);
2485 TheAISContext()->Activate(myAisCylinderHead,0);
2486 TheAISContext()->Activate(myAisEngineBlock,0 );
2487 TheAISContext()->Activate(myAisCrankArm ,0 );
2488 TheAISContext()->Activate(myAisPropeller ,0 );
2494 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2495 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2497 TheAISContext()->UpdateCurrentViewer();
2498 a3DView()->Redraw();
2507 //==============================================================================
2508 //function : VShading
2509 //purpose : Sharpen or roughten the quality of the shading
2510 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2511 //==============================================================================
2512 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2514 Standard_Real myDevCoef;
2515 Handle(AIS_InteractiveObject) TheAisIO;
2518 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2520 if (TheAISContext()->HasOpenedContext())
2521 TheAISContext()->CloseLocalContext();
2526 myDevCoef =Draw::Atof(argv[2]);
2529 TCollection_AsciiString name=argv[1];
2530 if (GetMapOfAIS().IsBound2(name ))
2531 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2532 if (TheAisIO.IsNull())
2533 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2536 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2538 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2540 TheAISContext()->Redisplay(TheAisIO);
2543 //==============================================================================
2544 //function : HaveMode
2545 //use : VActivatedModes
2546 //==============================================================================
2547 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2549 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2551 TColStd_ListOfInteger List;
2552 TheAISContext()->ActivatedModes (TheAisIO,List);
2553 TColStd_ListIteratorOfListOfInteger it;
2554 Standard_Boolean Found=Standard_False;
2555 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2556 if (it.Value()==mode ) Found=Standard_True;
2563 //==============================================================================
2564 //function : VActivatedMode
2566 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2567 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2568 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2569 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2570 // qu'un nom et qu'un mode.
2571 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2572 //==============================================================================
2573 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2575 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2578 Standard_Boolean ThereIsName = Standard_False ;
2580 if(!a3DView().IsNull()){
2582 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2583 // verification des arguments
2585 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2586 ThereIsName = (argc == 3);
2590 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2592 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2593 di<<" Fermeture du Context local"<<"\n";
2594 if (TheAISContext()->HasOpenedContext())
2595 TheAISContext()->CloseLocalContext();
2599 // IL n'y a aps de nom de shape passe en argument
2600 if (HaveToSet && !ThereIsName){
2601 Standard_Integer aMode=Draw::Atoi(argv [1]);
2603 const char *cmode="???";
2605 case 0: cmode = "Shape"; break;
2606 case 1: cmode = "Vertex"; break;
2607 case 2: cmode = "Edge"; break;
2608 case 3: cmode = "Wire"; break;
2609 case 4: cmode = "Face"; break;
2610 case 5: cmode = "Shell"; break;
2611 case 6: cmode = "Solid"; break;
2612 case 7: cmode = "Compound"; break;
2615 if( !TheAISContext()->HasOpenedContext() ) {
2616 // il n'y a pas de Context local d'ouvert
2617 // on en ouvre un et on charge toutes les shapes displayees
2618 // on load tous les objets displayees et on Activate les objets de la liste
2619 AIS_ListOfInteractive ListOfIO;
2620 // on sauve dans une AISListOfInteractive tous les objets currents
2621 if (TheAISContext()->NbCurrents()>0 ){
2622 TheAISContext()->UnhilightCurrents(Standard_False);
2624 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2625 ListOfIO.Append(TheAISContext()->Current() );
2629 TheAISContext()->OpenLocalContext(Standard_False);
2630 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2633 Handle(AIS_InteractiveObject) aIO =
2634 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2636 TheAISContext()->Load(aIO,0,Standard_False);
2639 // traitement des objets qui etaient currents dans le Contexte global
2640 if (!ListOfIO.IsEmpty() ) {
2641 // il y avait des objets currents
2642 AIS_ListIteratorOfListOfInteractive iter;
2643 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2644 Handle(AIS_InteractiveObject) aIO=iter.Value();
2645 TheAISContext()->Activate(aIO,aMode);
2646 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2650 // On applique le mode a tous les objets displayes
2651 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2652 it2 (GetMapOfAIS());
2654 Handle(AIS_InteractiveObject) aIO =
2655 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2656 if (!aIO.IsNull()) {
2657 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2658 TheAISContext()->Activate(aIO,aMode);
2667 // un Context local est deja ouvert
2668 // Traitement des objets du Context local
2669 if (TheAISContext()->NbSelected()>0 ){
2670 TheAISContext()->UnhilightSelected(Standard_False);
2671 // il y a des objets selected,on les parcourt
2672 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2673 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2676 if (HaveMode(aIO,aMode) ) {
2677 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2678 TheAISContext()->Deactivate(aIO,aMode);
2681 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2682 TheAISContext()->Activate(aIO,aMode);
2688 // il n'y a pas d'objets selected
2689 // tous les objets diplayes sont traites
2690 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2693 Handle(AIS_InteractiveObject) aIO =
2694 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2695 if (!aIO.IsNull()) {
2696 if (HaveMode(aIO,aMode) ) {
2697 di<<" Mode: "<<cmode<<" OFF pour "
2698 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2699 TheAISContext()->Deactivate(aIO,aMode);
2702 di<<" Mode: "<<cmode<<" ON pour"
2703 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2704 TheAISContext()->Activate(aIO,aMode);
2712 else if (HaveToSet && ThereIsName){
2713 Standard_Integer aMode=Draw::Atoi(argv [2]);
2714 Handle(AIS_InteractiveObject) aIO =
2715 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2717 if (!aIO.IsNull()) {
2718 const char *cmode="???";
2721 case 0: cmode = "Shape"; break;
2722 case 1: cmode = "Vertex"; break;
2723 case 2: cmode = "Edge"; break;
2724 case 3: cmode = "Wire"; break;
2725 case 4: cmode = "Face"; break;
2726 case 5: cmode = "Shell"; break;
2727 case 6: cmode = "Solid"; break;
2728 case 7: cmode = "Compound"; break;
2731 if( !TheAISContext()->HasOpenedContext() ) {
2732 TheAISContext()->OpenLocalContext(Standard_False);
2733 // On charge tous les objets de la map
2734 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2736 Handle(AIS_InteractiveObject) aShape=
2737 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2738 if (!aShape.IsNull())
2739 TheAISContext()->Load(aShape,0,Standard_False);
2742 TheAISContext()->Activate(aIO,aMode);
2743 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2747 // un Context local est deja ouvert
2748 if (HaveMode(aIO,aMode) ) {
2749 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2750 TheAISContext()->Deactivate(aIO,aMode);
2753 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2754 TheAISContext()->Activate(aIO,aMode);
2763 //! Auxiliary method to print Interactive Object information
2764 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
2765 const Handle(Standard_Transient)& theObject,
2766 Draw_Interpretor& theDI)
2768 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
2771 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
2775 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
2776 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
2777 << (theDetected.Contains (anObj) ? " Detected" : " ")
2779 if (anObj->Type() == AIS_KOI_Datum)
2782 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
2783 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
2784 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
2785 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
2786 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
2787 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
2788 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
2791 else if (anObj->Type() == AIS_KOI_Shape
2792 && anObj->Signature() == 0)
2794 theDI << " AIS_Shape";
2796 else if (anObj->Type() == AIS_KOI_Relation)
2798 // AIS_Dimention and AIS_Relation
2799 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
2800 switch (aRelation->KindOfDimension())
2802 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
2803 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
2804 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
2805 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
2806 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
2807 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
2808 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
2809 default: theDI << " UNKNOWN dimension"; break;
2814 theDI << " UserPrs";
2816 theDI << " (" << theObject->DynamicType()->Name() << ")";
2819 //! Print information about locally selected sub-shapes
2820 static void localCtxInfo (Draw_Interpretor& theDI)
2822 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2823 if (!aCtx->HasOpenedContext())
2828 TCollection_AsciiString aPrevName;
2829 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
2830 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
2832 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
2833 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
2834 if (aSubShape.IsNull()
2835 || aShapeIO.IsNull()
2836 || !GetMapOfAIS().IsBound1 (aShapeIO))
2841 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
2842 TopTools_MapOfShape aFilter;
2843 Standard_Integer aNumber = 0;
2844 const TopoDS_Shape aShape = aShapeIO->Shape();
2845 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
2846 anIter.More(); anIter.Next())
2848 if (!aFilter.Add (anIter.Current()))
2850 continue; // filter duplicates
2854 if (!anIter.Current().IsSame (aSubShape))
2859 Standard_CString aShapeName = NULL;
2860 switch (aSubShape.ShapeType())
2862 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
2863 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
2864 case TopAbs_SOLID: aShapeName = " Solid"; break;
2865 case TopAbs_SHELL: aShapeName = " Shell"; break;
2866 case TopAbs_FACE: aShapeName = " Face"; break;
2867 case TopAbs_WIRE: aShapeName = " Wire"; break;
2868 case TopAbs_EDGE: aShapeName = " Edge"; break;
2869 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
2871 case TopAbs_SHAPE: aShapeName = " Shape"; break;
2874 if (aParentName != aPrevName)
2876 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
2877 aPrevName = aParentName;
2879 theDI << " " << aShapeName << " #" << aNumber << "\n";
2885 //==============================================================================
2888 //Draw arg : vstate [nameA] ... [nameN]
2889 //==============================================================================
2890 static Standard_Integer VState (Draw_Interpretor& theDI,
2891 Standard_Integer theArgNb,
2892 Standard_CString* theArgVec)
2894 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2897 std::cerr << "Error: No opened viewer!\n";
2901 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
2902 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
2904 aDetected.Add (aCtx->DetectedCurrentObject());
2907 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
2911 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2913 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
2914 if (!GetMapOfAIS().IsBound2 (anObjName))
2916 theDI << anObjName << " doesn't exist!\n";
2920 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
2921 TCollection_AsciiString aName = anObjName;
2922 aName.LeftJustify (20, ' ');
2923 theDI << " " << aName << " ";
2924 objInfo (aDetected, anObjTrans, theDI);
2930 if (aCtx->NbCurrents() > 0
2933 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2935 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
2936 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
2937 aName.LeftJustify (20, ' ');
2938 theDI << aName << " ";
2939 objInfo (aDetected, anObj, theDI);
2945 theDI << "Neutral-point state:\n";
2946 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
2947 anObjIter.More(); anObjIter.Next())
2949 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
2955 TCollection_AsciiString aName = anObjIter.Key2();
2956 aName.LeftJustify (20, ' ');
2957 theDI << " " << aName << " ";
2958 objInfo (aDetected, anObj, theDI);
2961 localCtxInfo (theDI);
2965 //=======================================================================
2966 //function : PickObjects
2968 //=======================================================================
2969 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2970 const AIS_KindOfInteractive TheType,
2971 const Standard_Integer TheSignature,
2972 const Standard_Integer MaxPick)
2974 Handle(AIS_InteractiveObject) IO;
2975 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2977 // step 1: prepare the data
2979 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2980 TheAISContext()->AddFilter(F1);
2983 // step 2 : wait for the selection...
2984 // Standard_Boolean IsGood (Standard_False);
2985 // Standard_Integer NbPick(0);
2986 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2987 Standard_Integer NbPickFail(0);
2988 Standard_Integer argccc = 5;
2989 const char *bufff[] = { "A", "B", "C","D", "E" };
2990 const char **argvvv = (const char **) bufff;
2993 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2994 while(ViewerMainLoop(argccc,argvvv)){}
2995 Standard_Integer NbStored = TheAISContext()->NbSelected();
2996 if((unsigned int ) NbStored != NbPickGood)
2997 NbPickGood= NbStored;
3000 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3003 // step3 get result.
3005 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3007 Standard_Integer i(0);
3008 for(TheAISContext()->InitSelected();
3009 TheAISContext()->MoreSelected();
3010 TheAISContext()->NextSelected()){
3012 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3013 arr->SetValue(i,IO2);
3018 TheAISContext()->CloseLocalContext(curindex);
3020 return Standard_True;
3024 //=======================================================================
3025 //function : PickObject
3027 //=======================================================================
3028 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3029 const Standard_Integer TheSignature,
3030 const Standard_Integer MaxPick)
3032 Handle(AIS_InteractiveObject) IO;
3033 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3035 // step 1: prepare the data
3038 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3039 TheAISContext()->AddFilter(F1);
3042 // step 2 : wait for the selection...
3043 Standard_Boolean IsGood (Standard_False);
3044 Standard_Integer NbPick(0);
3045 Standard_Integer argccc = 5;
3046 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3047 const char **argvvv = (const char **) bufff;
3050 while(!IsGood && NbPick<= MaxPick){
3051 while(ViewerMainLoop(argccc,argvvv)){}
3052 IsGood = (TheAISContext()->NbSelected()>0) ;
3054 cout<<"Nb Pick :"<<NbPick<<endl;
3058 // step3 get result.
3060 TheAISContext()->InitSelected();
3061 IO = TheAISContext()->SelectedInteractive();
3065 TheAISContext()->CloseLocalContext(curindex);
3069 //=======================================================================
3070 //function : PickShape
3071 //purpose : First Activate the rightmode + Put Filters to be able to
3072 // pick objets that are of type <TheType>...
3073 //=======================================================================
3075 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3076 const Standard_Integer MaxPick)
3079 // step 1: prepare the data
3081 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3082 TopoDS_Shape result;
3084 if(TheType==TopAbs_SHAPE){
3085 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3086 TheAISContext()->AddFilter(F1);
3089 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3090 TheAISContext()->AddFilter(TF);
3091 TheAISContext()->ActivateStandardMode(TheType);
3096 // step 2 : wait for the selection...
3097 Standard_Boolean NoShape (Standard_True);
3098 Standard_Integer NbPick(0);
3099 Standard_Integer argccc = 5;
3100 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3101 const char **argvvv = (const char **) bufff;
3104 while(NoShape && NbPick<= MaxPick){
3105 while(ViewerMainLoop(argccc,argvvv)){}
3106 NoShape = (TheAISContext()->NbSelected()==0) ;
3108 cout<<"Nb Pick :"<<NbPick<<endl;
3111 // step3 get result.
3115 TheAISContext()->InitSelected();
3116 if(TheAISContext()->HasSelectedShape())
3117 result = TheAISContext()->SelectedShape();
3119 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3120 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3125 TheAISContext()->CloseLocalContext(curindex);
3131 //=======================================================================
3132 //function : PickShapes
3134 //=======================================================================
3135 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3136 Handle(TopTools_HArray1OfShape)& thearr,
3137 const Standard_Integer MaxPick)
3140 Standard_Integer Taille = thearr->Length();
3142 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3144 // step 1: prepare the data
3145 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3146 if(TheType==TopAbs_SHAPE){
3147 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3148 TheAISContext()->AddFilter(F1);
3151 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3152 TheAISContext()->AddFilter(TF);
3153 TheAISContext()->ActivateStandardMode(TheType);
3157 // step 2 : wait for the selection...
3159 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3160 Standard_Integer NbPickFail(0);
3161 Standard_Integer argccc = 5;
3162 const char *bufff[] = { "A", "B", "C","D", "E" };
3163 const char **argvvv = (const char **) bufff;
3166 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3167 while(ViewerMainLoop(argccc,argvvv)){}
3168 Standard_Integer NbStored = TheAISContext()->NbSelected();
3169 if((unsigned int ) NbStored != NbPickGood)
3170 NbPickGood= NbStored;
3173 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3176 // step3 get result.
3178 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3180 Standard_Integer i(0);
3181 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3183 if(TheAISContext()->HasSelectedShape())
3184 thearr->SetValue(i,TheAISContext()->SelectedShape());
3186 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3187 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3191 TheAISContext()->CloseLocalContext(curindex);
3192 return Standard_True;
3196 //=======================================================================
3197 //function : VPickShape
3199 //=======================================================================
3200 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3202 TopoDS_Shape PickSh;
3203 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3206 theType = TopAbs_SHAPE;
3208 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3209 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3210 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3211 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3212 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3213 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3214 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3217 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3218 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3220 TCollection_AsciiString name;
3223 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3225 PickSh = ViewerTest::PickShape(theType);
3234 if(!PickSh.IsNull()){
3235 nbOfSub[Standard_Integer(theType)]++;
3237 name += nameType[Standard_Integer(theType)];
3238 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3243 // si on avait une petite methode pour voir si la shape
3244 // est deja dans la Double map, ca eviterait de creer....
3245 DBRep::Set(name.ToCString(),PickSh);
3247 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3248 GetMapOfAIS().Bind(newsh, name);
3249 TheAISContext()->Display(newsh);
3250 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3253 // Plusieurs objets a picker, vite vite vite....
3256 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3257 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3258 if(ViewerTest::PickShapes(theType,arr)){
3259 for(Standard_Integer i=1;i<=NbToPick;i++){
3260 PickSh = arr->Value(i);
3261 if(!PickSh.IsNull()){
3263 nbOfSub[Standard_Integer(theType)]++;
3266 name += nameType[Standard_Integer(theType)];
3267 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3275 DBRep::Set(name.ToCString(),PickSh);
3276 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3277 GetMapOfAIS().Bind(newsh, name);
3278 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3279 TheAISContext()->Display(newsh);
3287 //=======================================================================
3288 //function : list of known objects
3290 //=======================================================================
3291 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3293 // 1234567890 12345678901234567 123456789
3294 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3295 TCollection_AsciiString BlankLine(64,'_');
3296 Standard_Integer i ;
3298 di<<"/n"<<BlankLine.ToCString()<<"\n";
3301 Colum[i].Center(20,' ');
3303 di<<"|"<<Colum[i].ToCString();
3306 di<<BlankLine.ToCString()<<"\n";
3308 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3309 const char ** names = GetTypeNames();
3311 TCollection_AsciiString curstring;
3312 TCollection_AsciiString curcolum[3];
3315 // les objets de type Datum..
3316 curcolum[1]+="Datum";
3318 curcolum[0].Clear();
3319 curcolum[0] += names[i];
3321 curcolum[2].Clear();
3322 curcolum[2]+=TCollection_AsciiString(i+1);
3324 for(Standard_Integer j =0;j<=2;j++){
3325 curcolum[j].Center(20,' ');
3326 di<<"|"<<curcolum[j].ToCString();
3330 di<<BlankLine.ToCString()<<"\n";
3332 // les objets de type shape
3333 curcolum[1].Clear();
3334 curcolum[1]+="Shape";
3335 curcolum[1].Center(20,' ');
3338 curcolum[0].Clear();
3339 curcolum[0] += names[7+i];
3340 curcolum[2].Clear();
3341 curcolum[2]+=TCollection_AsciiString(i);
3343 for(Standard_Integer j =0;j<=2;j++){
3344 curcolum[j].Center(20,' ');
3345 di<<"|"<<curcolum[j].ToCString();
3349 di<<BlankLine.ToCString()<<"\n";
3350 // les IO de type objet...
3351 curcolum[1].Clear();
3352 curcolum[1]+="Object";
3353 curcolum[1].Center(20,' ');
3355 curcolum[0].Clear();
3356 curcolum[0] += names[10+i];
3357 curcolum[2].Clear();
3358 curcolum[2]+=TCollection_AsciiString(i);
3360 for(Standard_Integer j =0;j<=2;j++){
3361 curcolum[j].Center(20,' ');
3362 di<<"|"<<curcolum[j].ToCString();
3366 di<<BlankLine.ToCString()<<"\n";
3367 // les contraintes et dimensions.
3368 // pour l'instant on separe juste contraintes et dimensions...
3369 // plus tard, on detaillera toutes les sortes...
3370 curcolum[1].Clear();
3371 curcolum[1]+="Relation";
3372 curcolum[1].Center(20,' ');
3374 curcolum[0].Clear();
3375 curcolum[0] += names[12+i];
3376 curcolum[2].Clear();
3377 curcolum[2]+=TCollection_AsciiString(i);
3379 for(Standard_Integer j =0;j<=2;j++){
3380 curcolum[j].Center(20,' ');
3381 di<<"|"<<curcolum[j].ToCString();
3385 di<<BlankLine.ToCString()<<"\n";
3392 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3394 if(argc!=2) return 1;
3396 AIS_KindOfInteractive TheType;
3397 Standard_Integer TheSign(-1);
3398 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3401 AIS_ListOfInteractive LIO;
3403 // en attendant l'amelioration ais pour les dimensions...
3405 Standard_Integer dimension_status(-1);
3406 if(TheType==AIS_KOI_Relation){
3407 dimension_status = TheSign ==1 ? 1 : 0;
3411 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3412 Handle(AIS_InteractiveObject) curio;
3413 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3416 if(dimension_status == -1)
3417 TheAISContext()->Erase(curio,Standard_False);
3419 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3420 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3421 (dimension_status==1 && KOD != AIS_KOD_NONE))
3422 TheAISContext()->Erase(curio,Standard_False);
3425 TheAISContext()->UpdateCurrentViewer();
3428 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3430 if(argc!=2) return 1;
3432 AIS_KindOfInteractive TheType;
3433 Standard_Integer TheSign(-1);
3434 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3436 // en attendant l'amelioration ais pour les dimensions...
3438 Standard_Integer dimension_status(-1);
3439 if(TheType==AIS_KOI_Relation){
3440 dimension_status = TheSign ==1 ? 1 : 0;
3444 AIS_ListOfInteractive LIO;
3445 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3446 Handle(AIS_InteractiveObject) curio;
3447 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3449 if(dimension_status == -1)
3450 TheAISContext()->Display(curio,Standard_False);
3452 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3453 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3454 (dimension_status==1 && KOD != AIS_KOD_NONE))
3455 TheAISContext()->Display(curio,Standard_False);
3460 TheAISContext()->UpdateCurrentViewer();
3464 //==============================================================================
3465 //function : VSetTransMode
3467 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3468 //==============================================================================
3470 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3471 // Verification des arguments
3472 if ( a3DView().IsNull() ) {
3473 ViewerTest::ViewerInit();
3474 di << "La commande vinit n'a pas ete appele avant" << "\n";
3477 if ( argc < 3 || argc > 8 ) {
3478 di << argv[0] << " Invalid number of arguments" << "\n";
3482 TCollection_AsciiString shapeName;
3483 shapeName = argv[1];
3484 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3485 Standard_Integer persFlag2 = 0;
3486 Standard_Integer persFlag3 = 0;
3487 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3488 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3489 persFlag2 = Draw::Atoi(argv[3]);
3491 if ( argc == 5 || argc == 8 ) {
3492 persFlag3 = Draw::Atoi(argv[4]);
3495 origin.SetX( Draw::Atof(argv[argc - 3]) );
3496 origin.SetY( Draw::Atof(argv[argc - 2]) );
3497 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3500 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3501 Handle(Standard_Transient) anObj;
3503 anObj = GetMapOfAIS().Find2(shapeName);
3504 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3505 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3506 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3507 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3508 di << argv[0] << " All persistence modifiers were removed" << "\n";
3511 di << argv[0] << " Wrong object type" << "\n";
3514 } else { // Create the AIS_Shape from a name
3515 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3516 if ( !aShape.IsNull() ) {
3517 GetMapOfAIS().Bind( aShape, shapeName );
3518 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3519 TheAISContext()->Display( aShape, Standard_False );
3521 di << argv[0] << " Object not found" << "\n";
3526 // Upadate the screen and redraw the view
3527 TheAISContext()->UpdateCurrentViewer();
3531 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3534 BRep_Builder builder;
3536 BRepTools::Read(shape, s, builder);
3537 DBRep::Set(a[1], shape);
3538 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3539 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3544 //==============================================================================
3545 //function : ViewerTest::Commands
3546 //purpose : Add all the viewer command in the Draw_Interpretor
3547 //==============================================================================
3549 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3551 ViewerTest::ViewerCommands(theCommands);
3552 ViewerTest::RelationCommands(theCommands);
3553 ViewerTest::ObjectCommands(theCommands);
3554 ViewerTest::FilletCommands(theCommands);
3555 ViewerTest::VoxelCommands(theCommands);
3556 ViewerTest::OpenGlCommands(theCommands);
3558 const char *group = "AIS_Display";
3561 theCommands.Add("visos",
3562 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3563 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3564 __FILE__, visos, group);
3566 theCommands.Add("vdisplay",
3567 "vdisplay [-noupdate|-update] name1 [name2] ... [name n]"
3568 "\n\t\t: Displays named objects."
3569 "\n\t\t: Option -noupdate suppresses viewer redraw call."
3570 __FILE__,VDisplay2,group);
3572 theCommands.Add ("vupdate",
3573 "vupdate name1 [name2] ... [name n]"
3574 "\n\t\t: Updates named objects in interactive context",
3575 __FILE__, VUpdate, group);
3577 theCommands.Add("verase",
3578 "verase [-noupdate|-update] [name1] ... [name n]"
3579 "\n\t\t: Erases selected or named objects."
3580 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3581 __FILE__, VErase, group);
3583 theCommands.Add("vremove",
3584 "vremove [-noupdate|-update] [-context] [-all] [name1] ... [name n]"
3585 "or vremove [-context] -all to remove all objects"
3586 "\n\t\t: Removes selected or named objects."
3587 "\n\t\t If -context is in arguments, the objects are not deleted"
3588 "\n\t\t from the map of objects and names."
3589 "\n\t\t: Option -noupdate suppresses viewer redraw call.",
3590 __FILE__, VRemove, group);
3592 theCommands.Add("vdonly",
3593 "vdonly [-noupdate|-update] [name1] ... [name n]"
3594 "\n\t\t: Displays only selected or named objects",
3595 __FILE__,VDonly2,group);
3597 theCommands.Add("vdisplayall",
3598 "Displays all erased interactive objects (see vdir and vstate)",
3599 __FILE__,VDisplayAll,group);
3601 theCommands.Add("veraseall",
3602 "Erases all objects displayed in the viewer",
3603 __FILE__, VErase, group);
3605 theCommands.Add("verasetype",
3607 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3608 __FILE__,VEraseType,group);
3610 theCommands.Add("vdisplaytype",
3611 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3612 __FILE__,VDisplayType,group);
3614 theCommands.Add("vdisplaymode",
3615 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3616 __FILE__,VDispMode,group);
3618 theCommands.Add("verasemode",
3619 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3620 __FILE__,VDispMode,group);
3622 theCommands.Add("vsetdispmode",
3623 "vsetdispmode [name] mode(1,2,..)"
3624 "\n\t\t: Sets display mode for all, selected or named objects.",
3625 __FILE__,VDispMode,group);
3627 theCommands.Add("vunsetdispmode",
3628 "vunsetdispmode [name]"
3629 "\n\t\t: Unsets custom display mode for selected or named objects.",
3630 __FILE__,VDispMode,group);
3632 theCommands.Add("vdir",
3633 "Lists all objects displayed in 3D viewer",
3634 __FILE__,VDir,group);
3636 theCommands.Add("vdump",
3637 #ifdef HAVE_FREEIMAGE
3638 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]"
3639 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3641 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]"
3642 "\n\t\t: Dumps contents of viewer window to PPM image file",
3644 __FILE__,VDump,group);
3646 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3647 __FILE__,VSubInt,group);
3649 theCommands.Add("vsetcolor",
3650 "vsetcolor [name] ColorName"
3651 "\n\t\t: Sets color for all, selected or named objects.",
3652 __FILE__,VColor2,group);
3654 theCommands.Add("vunsetcolor",
3655 "vunsetcolor [name]"
3656 "\n\t\t: Resets color for all, selected or named objects.",
3657 __FILE__,VColor2,group);
3659 theCommands.Add("vsettransparency",
3660 "vsettransparency [name] Coefficient"
3661 "\n\t\t: Sets transparency for all, selected or named objects."
3662 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3663 __FILE__,VTransparency,group);
3665 theCommands.Add("vunsettransparency",
3666 "vunsettransparency [name]"
3667 "\n\t\t: Resets transparency for all, selected or named objects.",
3668 __FILE__,VTransparency,group);
3670 theCommands.Add("vsetmaterial",
3671 "vmaterial : vmaterial [name of shape] MaterialName",
3672 __FILE__,VMaterial,group);
3674 theCommands.Add("vunsetmaterial",
3675 "vmaterial : vmaterial [name of shape]",
3676 __FILE__,VMaterial,group);
3678 theCommands.Add("vsetwidth",
3679 "vsetwidth : vwidth [name of shape] width(0->10)",
3680 __FILE__,VWidth,group);
3682 theCommands.Add("vunsetwidth",
3683 "vunsetwidth : vwidth [name of shape]",
3684 __FILE__,VWidth,group);
3686 theCommands.Add("vsetinteriorstyle",
3687 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3688 __FILE__,VInteriorStyle,group);
3690 theCommands.Add("vardis",
3691 "vardis : display activeareas",
3692 __FILE__,VDispAreas,group);
3694 theCommands.Add("varera",
3695 "varera : erase activeareas",
3696 __FILE__,VClearAreas,group);
3698 theCommands.Add("vsensdis",
3699 "vardisp : display active entities",
3700 __FILE__,VDispSensi,group);
3701 theCommands.Add("vsensera",
3702 "vardisp : erase active entities",
3703 __FILE__,VClearSensi,group);
3705 theCommands.Add("vselprecision",
3706 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3707 __FILE__,VSelPrecision,group);
3709 theCommands.Add("vperf",
3710 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3711 __FILE__,VPerf,group);
3713 theCommands.Add("vanimation",
3714 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3715 __FILE__,VAnimation,group);
3717 theCommands.Add("vsetshading",
3718 "vsetshading : vsetshading name Quality(default=0.0008) ",
3719 __FILE__,VShading,group);
3721 theCommands.Add("vunsetshading",
3722 "vunsetshading :vunsetshading name ",
3723 __FILE__,VShading,group);
3725 theCommands.Add("vtexture",
3726 "'vtexture NameOfShape TextureFile' \n \
3727 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3728 or 'vtexture NameOfShape ?' to list available textures\n \
3729 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3730 __FILE__,VTexture,group);
3732 theCommands.Add("vtexscale",
3733 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3734 or 'vtexscale NameOfShape ScaleUV' \n \
3735 or 'vtexscale NameOfShape' to disable scaling\n ",
3736 __FILE__,VTexture,group);
3738 theCommands.Add("vtexorigin",
3739 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3740 or 'vtexorigin NameOfShape UVOrigin' \n \
3741 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3742 __FILE__,VTexture,group);
3744 theCommands.Add("vtexrepeat",
3745 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3746 or 'vtexrepeat NameOfShape UVRepeat \n \
3747 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3750 theCommands.Add("vtexdefault",
3751 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3754 theCommands.Add("vsetam",
3755 "vsetActivatedModes: vsetam mode(1->7) ",
3756 __FILE__,VActivatedMode,group);
3758 theCommands.Add("vunsetam",
3759 "vunsetActivatedModes: vunsetam ",
3760 __FILE__,VActivatedMode,group);
3762 theCommands.Add("vstate",
3763 "vstate [name1] ... [nameN]"
3764 "\n\t\t: Reports show/hidden state for selected or named objects",
3765 __FILE__,VState,group);
3767 theCommands.Add("vpickshapes",
3768 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3769 __FILE__,VPickShape,group);
3771 theCommands.Add("vtypes",
3772 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3775 theCommands.Add("vsettransmode",
3776 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3777 __FILE__,VSetTransMode,group);
3779 theCommands.Add("vr", "vr : reading of the shape",
3780 __FILE__,vr, group);
3784 //=====================================================================
3785 //========================= for testing Draft and Rib =================
3786 //=====================================================================
3787 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3788 #include <DBRep.hxx>
3789 #include <TopoDS_Face.hxx>
3790 #include <gp_Pln.hxx>
3791 #include <AIS_KindOfSurface.hxx>
3792 #include <BRepOffsetAPI_DraftAngle.hxx>
3793 #include <Precision.hxx>
3794 #include <BRepAlgo.hxx>
3795 #include <OSD_Environment.hxx>
3796 #include <DrawTrSurf.hxx>
3797 //#include <DbgTools.hxx>
3798 //#include <FeatAlgo_MakeLinearForm.hxx>
3803 //=======================================================================
3804 //function : IsValid
3806 //=======================================================================
3807 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3808 const TopoDS_Shape& theResult,
3809 const Standard_Boolean closedSolid,
3810 const Standard_Boolean GeomCtrl)
3812 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3813 TCollection_AsciiString checkValid = check.Value();
3814 Standard_Boolean ToCheck = Standard_True;
3815 if (!checkValid.IsEmpty()) {
3817 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3819 if ( checkValid=="true" || checkValid=="TRUE" ) {
3820 ToCheck= Standard_False;
3824 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3827 Standard_Boolean IsValid = Standard_True;
3829 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3834 //===============================================================================
3835 // TDraft : test draft, uses AIS Viewer
3836 // Solid Face Plane Angle Reverse
3837 //===============================================================================
3838 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3840 if (argc < 5) return 1;
3841 // argv[1] - TopoDS_Shape Solid
3842 // argv[2] - TopoDS_Shape Face
3843 // argv[3] - TopoDS_Shape Plane
3844 // argv[4] - Standard_Real Angle
3845 // argv[5] - Standard_Integer Reverse
3847 // Sprintf(prefix, argv[1]);
3848 Standard_Real anAngle = 0;
3849 Standard_Boolean Rev = Standard_False;
3850 Standard_Integer rev = 0;
3851 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3852 TopoDS_Shape face = GetShapeFromName(argv[2]);
3853 TopoDS_Face Face = TopoDS::Face(face);
3854 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3855 if (Plane.IsNull ()) {
3856 di << "TEST : Plane is NULL" << "\n";
3859 anAngle = Draw::Atof(argv[4]);
3860 anAngle = 2*M_PI * anAngle / 360.0;
3862 Handle( Geom_Surface )aSurf;
3863 AIS_KindOfSurface aSurfType;
3864 Standard_Real Offset;
3866 if(argc > 4) { // == 5
3867 rev = Draw::Atoi(argv[5]);
3868 Rev = (rev)? Standard_True : Standard_False;
3871 TopoDS_Face face2 = TopoDS::Face(Plane);
3872 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3874 di << "TEST : Can't find plane" << "\n";
3878 aDir = aPln.Axis().Direction();
3881 if (Plane.Orientation() == TopAbs_REVERSED)
3883 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3885 BRepOffsetAPI_DraftAngle Draft (Solid);
3887 if(Abs(anAngle)< Precision::Angular()) {
3888 di << "TEST : NULL angle" << "\n";
3891 if(Rev) anAngle = - anAngle;
3892 Draft.Add (Face, aDir, anAngle, aPln);
3894 if (!Draft.IsDone()) {
3895 di << "TEST : Draft Not DONE " << "\n";
3898 TopTools_ListOfShape Larg;
3900 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3901 di << "TEST : DesignAlgo returns Not valid" << "\n";
3905 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3906 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3908 if ( !ais.IsNull() ) {
3909 ais->SetColor(DEFAULT_COLOR);
3910 ais->SetMaterial(DEFAULT_MATERIAL);
3911 // Display the AIS_Shape without redraw
3912 Ctx->Display(ais, Standard_False);
3914 const char *Name = "draft1";
3915 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3917 Handle(AIS_InteractiveObject) an_object =
3918 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3919 if (!an_object.IsNull()) {
3920 Ctx->Remove(an_object,
3922 GetMapOfAIS().UnBind2(Name) ;
3925 GetMapOfAIS().Bind(ais, Name);
3926 // DBRep::Set("draft", ais->Shape());
3928 Ctx->Display(ais, Standard_True);
3932 //==============================================================================
3933 //function : splitParameter
3934 //purpose : Split parameter string to parameter name and parameter value
3935 //==============================================================================
3936 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
3937 TCollection_AsciiString& theName,
3938 TCollection_AsciiString& theValue)
3940 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
3942 if (aParamNameEnd == 0)
3944 return Standard_False;
3947 TCollection_AsciiString aString (theString);
3948 if (aParamNameEnd != 0)
3950 theValue = aString.Split (aParamNameEnd);
3951 aString.Split (aString.Length() - 1);
3955 return Standard_True;
3958 //============================================================================
3960 //============================================================================
3961 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3964 DrawTrSurf::BasicCommands(theCommands);
3965 const char* group = "Check Features Operations commands";
3967 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3969 &TDraft,group); //Draft_Modification
3972 //==============================================================================
3973 // ViewerTest::Factory
3974 //==============================================================================
3975 void ViewerTest::Factory(Draw_Interpretor& theDI)
3977 // definition of Viewer Command
3978 ViewerTest::Commands(theDI);
3979 ViewerTest::AviCommands(theDI);
3982 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3986 // Declare entry point PLUGINFACTORY