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 //=======================================================================
92 //function : GetColorFromName
93 //purpose : get the Quantity_NameOfColor from a string
94 //=======================================================================
96 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
98 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
100 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
101 if (strcasecmp (theName, aColorName) == 0)
103 return Quantity_NameOfColor (anIter);
107 return DEFAULT_COLOR;
110 //=======================================================================
111 //function : GetMaterialFromName
112 //purpose : get the Graphic3d_NameOfMaterial from a string
113 //=======================================================================
115 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
117 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
119 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
120 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
121 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
122 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
123 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
124 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
125 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
126 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
127 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
128 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
129 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
130 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
131 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
132 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
133 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
134 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
135 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
136 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
137 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
142 //=======================================================================
143 //function : GetTypeNames
145 //=======================================================================
146 static const char** GetTypeNames()
148 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
149 "Shape","ConnectedShape","MultiConn.Shape",
150 "ConnectedInter.","MultiConn.",
151 "Constraint","Dimension"};
152 static const char** ThePointer = names;
156 //=======================================================================
157 //function : GetTypeAndSignfromString
159 //=======================================================================
160 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
162 const char ** thefullnames = GetTypeNames();
163 Standard_Integer index(-1);
165 for(Standard_Integer i=0;i<=13 && index==-1;i++)
166 if(!strcasecmp(name,thefullnames[i]))
170 TheType = AIS_KOI_None;
176 TheType = AIS_KOI_Datum;
180 TheType = AIS_KOI_Shape;
184 TheType = AIS_KOI_Object;
188 TheType = AIS_KOI_Relation;
197 #include <Draw_Interpretor.hxx>
199 #include <Draw_Appli.hxx>
203 #include <TCollection_AsciiString.hxx>
204 #include <V3d_Viewer.hxx>
205 #include <V3d_View.hxx>
208 #include <AIS_InteractiveContext.hxx>
209 #include <AIS_Shape.hxx>
210 #include <AIS_TexturedShape.hxx>
211 #include <AIS_DisplayMode.hxx>
212 #include <TColStd_MapOfInteger.hxx>
213 #include <AIS_MapOfInteractive.hxx>
214 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
215 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
216 #include <ViewerTest_EventManager.hxx>
218 #include <TopoDS_Solid.hxx>
219 #include <BRepTools.hxx>
220 #include <BRep_Builder.hxx>
221 #include <TopAbs_ShapeEnum.hxx>
223 #include <TopoDS.hxx>
224 #include <BRep_Tool.hxx>
227 #include <Draw_Window.hxx>
228 #include <AIS_ListIteratorOfListOfInteractive.hxx>
229 #include <AIS_ListOfInteractive.hxx>
230 #include <AIS_DisplayMode.hxx>
231 #include <TopTools_ListOfShape.hxx>
232 #include <BRepOffsetAPI_MakeThickSolid.hxx>
233 #include <BRepOffset.hxx>
235 //==============================================================================
236 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
237 //==============================================================================
238 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
239 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
244 //==============================================================================
245 //function : VDisplayAISObject
246 //purpose : register interactive object in the map of AIS objects;
247 // if other object with such name already registered, it will be kept
248 // or replaced depending on value of <theReplaceIfExists>,
249 // if "true" - the old object will be cleared from AIS context;
250 // returns Standard_True if <theAISObj> registered in map;
251 //==============================================================================
252 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
253 const Handle(AIS_InteractiveObject)& theAISObj,
254 Standard_Boolean theReplaceIfExists = Standard_True)
256 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
257 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
258 if (aContextAIS.IsNull())
260 std::cout << "AIS context is not available.\n";
261 return Standard_False;
264 if (aMap.IsBound2 (theName))
266 if (!theReplaceIfExists)
268 std::cout << "Other interactive object has been already "
269 << "registered with name: " << theName << ".\n"
270 << "Please use another name.\n";
271 return Standard_False;
274 // stop displaying object
275 Handle(AIS_InteractiveObject) anOldObj =
276 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
278 if (!anOldObj.IsNull())
279 aContextAIS->Clear (anOldObj, Standard_True);
281 // remove name and old object from map
282 aMap.UnBind2 (theName);
285 if (theAISObj.IsNull())
287 // object with specified name already unbound
288 return Standard_True;
291 // unbind AIS object if was bound with another name
292 aMap.UnBind1 (theAISObj);
294 // can be registered without rebinding
295 aMap.Bind (theAISObj, theName);
296 aContextAIS->Display (theAISObj, Standard_True);
297 return Standard_True;
300 static TColStd_MapOfInteger theactivatedmodes(8);
301 static TColStd_ListOfTransient theEventMgrs;
303 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
304 const Handle(AIS_InteractiveContext)& Ctx)
306 theEventMgrs.Clear();
307 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
310 static Handle(V3d_View)& a3DView()
312 static Handle(V3d_View) Viou;
317 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
318 static Handle(AIS_InteractiveContext) aContext;
322 const Handle(V3d_View)& ViewerTest::CurrentView()
326 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
331 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
333 static Handle(NIS_InteractiveContext) aContext;
334 if (aContext.IsNull()) {
335 aContext = new NIS_InteractiveContext;
336 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
341 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
343 return TheAISContext();
346 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
348 TheAISContext() = aCtx;
349 ViewerTest::ResetEventManager();
352 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
354 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
357 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
359 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
363 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
364 theEventMgrs.Prepend(EM);
367 void ViewerTest::UnsetEventManager()
369 theEventMgrs.RemoveFirst();
373 void ViewerTest::ResetEventManager()
375 const Handle(NIS_View) aView =
376 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
377 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
380 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
382 Handle(ViewerTest_EventManager) EM;
383 if(theEventMgrs.IsEmpty()) return EM;
384 Handle(Standard_Transient) Tr = theEventMgrs.First();
385 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
390 //=======================================================================
391 //function : Get Context and active viou..
393 //=======================================================================
394 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
395 Handle(V3d_View)& Viou)
397 Ctx = ViewerTest::GetAISContext();
400 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
401 Vwr->InitActiveViews();
402 if(Vwr->MoreActiveViews())
403 Viou = Vwr->ActiveView();
408 //==============================================================================
409 //function : GetShapeFromName
410 //purpose : Compute an Shape from a draw variable or a file name
411 //==============================================================================
413 static TopoDS_Shape GetShapeFromName(const char* name)
415 TopoDS_Shape S = DBRep::Get(name);
418 BRep_Builder aBuilder;
419 BRepTools::Read( S, name, aBuilder);
425 //==============================================================================
426 //function : GetAISShapeFromName
427 //purpose : Compute an AIS_Shape from a draw variable or a file name
428 //==============================================================================
429 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
431 Handle(AIS_Shape) retsh;
433 if(GetMapOfAIS().IsBound2(name)){
434 const Handle(AIS_InteractiveObject) IO =
435 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
437 if(IO->Type()==AIS_KOI_Shape) {
438 if(IO->Signature()==0){
439 retsh = *((Handle(AIS_Shape)*)&IO);
442 cout << "an Object which is not an AIS_Shape "
443 "already has this name!!!"<<endl;
450 TopoDS_Shape S = GetShapeFromName(name);
452 retsh = new AIS_Shape(S);
458 //==============================================================================
460 //purpose : Remove all the object from the viewer
461 //==============================================================================
462 void ViewerTest::Clear()
464 if ( !a3DView().IsNull() ) {
465 if (TheAISContext()->HasOpenedContext())
466 TheAISContext()->CloseLocalContext();
467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
468 while ( it.More() ) {
469 cout << "Remove " << it.Key2() << endl;
470 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
471 const Handle(AIS_InteractiveObject) anObj =
472 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
473 TheAISContext()->Remove(anObj,Standard_False);
474 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
475 const Handle(NIS_InteractiveObject) anObj =
476 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
477 TheNISContext()->Remove(anObj);
481 TheAISContext()->UpdateCurrentViewer();
482 // TheNISContext()->UpdateViews();
483 GetMapOfAIS().Clear();
487 //==============================================================================
488 //function : StandardModesActivation
489 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
491 //==============================================================================
492 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
494 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
496 if (TheAISContext()->HasOpenedContext())
497 aContext->CloseLocalContext();
500 if(!aContext->HasOpenedContext()) {
501 // To unhilight the preselected object
502 aContext->UnhilightCurrents(Standard_False);
503 // Open a local Context in order to be able to select subshape from
504 // the selected shape if any or for all if there is no selection
505 if (!aContext->FirstCurrentObject().IsNull()){
506 aContext->OpenLocalContext(Standard_False);
508 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
509 aContext->Load( aContext->Current(),-1,Standard_True);
513 aContext->OpenLocalContext();
516 const char *cmode="???";
519 case 0: cmode = "Shape"; break;
520 case 1: cmode = "Vertex"; break;
521 case 2: cmode = "Edge"; break;
522 case 3: cmode = "Wire"; break;
523 case 4: cmode = "Face"; break;
524 case 5: cmode = "Shell"; break;
525 case 6: cmode = "Solid"; break;
526 case 7: cmode = "Compsolid"; break;
527 case 8: cmode = "Compound"; break;
530 if(theactivatedmodes.Contains(mode))
532 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
533 theactivatedmodes.Remove(mode);
534 cout<<"Mode "<< cmode <<" OFF"<<endl;
538 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
539 theactivatedmodes.Add(mode);
540 cout<<"Mode "<< cmode << " ON" << endl;
545 //==============================================================================
546 //function : CopyIsoAspect
547 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
548 //==============================================================================
549 static Handle(Prs3d_IsoAspect) CopyIsoAspect
550 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
551 const Standard_Integer theNbIsos)
553 Quantity_Color aColor;
554 Aspect_TypeOfLine aType;
555 Standard_Real aWidth;
557 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
559 Handle(Prs3d_IsoAspect) aResult =
560 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
565 //==============================================================================
567 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
568 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
569 //==============================================================================
570 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
572 if (TheAISContext().IsNull()) {
573 di << argv[0] << " Call 'vinit' before!\n";
578 di << "Current number of isos : " <<
579 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
580 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
581 di << "IsoOnPlane mode is " <<
582 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
587 Standard_Integer aLastInd = argc - 1;
588 Standard_Boolean isChanged = Standard_False;
589 Standard_Integer aNbUIsos = 0;
590 Standard_Integer aNbVIsos = 0;
593 Standard_Boolean isIsoOnPlane = Standard_False;
595 if (strcmp(argv[aLastInd], "1") == 0) {
596 isIsoOnPlane = Standard_True;
597 isChanged = Standard_True;
598 } else if (strcmp(argv[aLastInd], "0") == 0) {
599 isIsoOnPlane = Standard_False;
600 isChanged = Standard_True;
604 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
605 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
608 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
609 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
611 TheAISContext()->IsoOnPlane(isIsoOnPlane);
614 // If there are no shapes provided set the default numbers.
615 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
616 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
623 for (i = 1; i <= aLastInd; i++) {
624 TCollection_AsciiString name(argv[i]);
625 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
628 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
629 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
630 const Handle(AIS_InteractiveObject) aShape =
631 Handle(AIS_InteractiveObject)::DownCast (anObj);
632 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
633 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
634 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
637 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
638 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
639 TheAISContext()->SetLocalAttributes
640 (aShape, CurDrawer, Standard_False);
641 TheAISContext()->Redisplay(aShape);
643 di << "Number of isos for " << argv[i] << " : "
644 << aUIso->Number() << " " << aVIso->Number() << "\n";
647 di << argv[i] << ": Not an AIS interactive object!\n";
650 di << argv[i] << ": Use 'vdisplay' before\n";
655 TheAISContext()->UpdateCurrentViewer();
661 //==============================================================================
662 //function : VDispAreas,VDispSensitive,...
663 //purpose : Redraw the view
665 //==============================================================================
666 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
669 Handle(AIS_InteractiveContext) Ctx;
670 Handle(V3d_View) Viou;
671 GetCtxAndView(Ctx,Viou);
672 Ctx->DisplayActiveAreas(Viou);
675 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
677 Handle(AIS_InteractiveContext) Ctx;
678 Handle(V3d_View) Viou;
679 GetCtxAndView(Ctx,Viou);
680 Ctx->ClearActiveAreas(Viou);
684 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
686 Handle(AIS_InteractiveContext) Ctx;
687 Handle(V3d_View) Viou;
688 GetCtxAndView(Ctx,Viou);
689 Ctx->DisplayActiveSensitive(Viou);
693 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
695 Handle(AIS_InteractiveContext) Ctx;
696 Handle(V3d_View) Viou;
697 GetCtxAndView(Ctx,Viou);
698 Ctx->ClearActiveSensitive(Viou);
702 //==============================================================================
704 //purpose : To list the displayed object with their attributes
706 //==============================================================================
707 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
708 { if ( !a3DView().IsNull() ) {
709 di << "List of object in the viewer :" << "\n";
711 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
713 while ( it.More() ) {
714 di << "\t" << it.Key2().ToCString() << "\n";
722 //==============================================================================
723 //function : VSelPrecision
724 //purpose : To set the selection precision mode and tolerance value
725 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
726 // value (integer number of pixel for window mode, double value of
727 // sensitivity for view mode). Without arguments the function just
728 // prints the current precision mode and the corresponding tolerance.
729 //==============================================================================
730 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
734 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
738 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
739 if( aContext.IsNull() )
744 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
745 if( aMode == StdSelect_SM_WINDOW )
747 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
748 di << "Precision mode : 0 (window)\n";
749 di << "Pixel tolerance : " << aPixelTolerance << "\n";
751 else if( aMode == StdSelect_SM_VIEW )
753 Standard_Real aSensitivity = aContext->Sensitivity();
754 di << "Precision mode : 1 (view)\n";
755 di << "Sensitivity : " << aSensitivity << "\n";
760 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
761 aContext->SetSensitivityMode( aMode );
764 if( aMode == StdSelect_SM_WINDOW )
766 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
767 aContext->SetPixelTolerance( aPixelTolerance );
769 else if( aMode == StdSelect_SM_VIEW )
771 Standard_Real aSensitivity = Draw::Atof( argv[2] );
772 aContext->SetSensitivity( aSensitivity );
779 //==============================================================================
781 //purpose : To dump the active view snapshot to image file
782 //Draw arg : Picture file name with extension corresponding to desired format
783 //==============================================================================
784 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
788 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]\n";
792 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
795 const char* aBuffTypeStr = argv[2];
796 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
798 aBufferType = Graphic3d_BT_RGB;
800 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
802 aBufferType = Graphic3d_BT_RGBA;
804 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
806 aBufferType = Graphic3d_BT_Depth;
810 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
811 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
813 TCollection_AsciiString aStereoProj ((argc > 5) ? argv[5] : "");
815 Handle(AIS_InteractiveContext) IC;
816 Handle(V3d_View) view;
817 GetCtxAndView (IC, view);
820 di << "Cannot find an active viewer/view\n";
824 if (aWidth <= 0 || aHeight <= 0)
826 if (!view->Dump (argv[1], aBufferType))
828 di << "Dumping failed!\n";
834 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
836 if (!aStereoProj.IsEmpty())
838 aStereoProj.UpperCase();
839 if (aStereoProj == "L")
841 aStereoOpts = V3d_SDO_LEFT_EYE;
844 if (aStereoProj == "R")
846 aStereoOpts = V3d_SDO_RIGHT_EYE;
850 Image_AlienPixMap aPixMap;
851 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
853 di << "Dumping failed!\n";
857 if (aPixMap.SizeX() != Standard_Size(aWidth)
858 || aPixMap.SizeY() != Standard_Size(aHeight))
860 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
861 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
863 if (!aPixMap.Save (argv[1]))
865 di << "Saving image failed!\n";
872 //==============================================================================
873 //function : Displays,Erase...
876 //==============================================================================
877 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
878 const Standard_Integer Mode,
879 const Standard_Integer TypeOfOperation,
880 const Standard_Boolean Upd)
882 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
884 switch(TypeOfOperation){
886 Ctx->Display(IO,Mode,Upd);
894 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
896 Ctx->SetDisplayMode(IO,Mode,Upd);
901 Ctx->SetDisplayMode(0,Upd);
903 Ctx->UnsetDisplayMode(IO,Upd);
910 //=======================================================================
913 //=======================================================================
914 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
917 TCollection_AsciiString name;
920 // display others presentations
921 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
922 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
923 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
924 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
926 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
928 //unset displaymode.. comportement particulier...
929 if(TypeOfOperation==4){
931 if(Ctx->NbCurrents()==0 ||
932 Ctx->NbSelected()==0){
933 Handle(AIS_InteractiveObject) IO;
934 VwrTst_DispErase(IO,-1,4,Standard_False);
936 else if(!Ctx->HasOpenedContext()){
937 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
938 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
941 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
942 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
943 Ctx->UpdateCurrentViewer();
946 Handle(AIS_InteractiveObject) IO;
948 if(GetMapOfAIS().IsBound2(name)){
949 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
951 VwrTst_DispErase(IO,-1,4,Standard_True);
956 Standard_Integer Dmode = Draw::Atoi(argv[1]);
957 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
958 Handle(AIS_InteractiveObject) IO;
959 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
961 if(!Ctx->HasOpenedContext()){
962 // set/unset display mode sur le Contexte...
963 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
964 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
966 Ctx->UpdateCurrentViewer();
969 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
970 Ctx->Display(Ctx->Interactive(),Dmode);
974 Handle(AIS_InteractiveObject) IO;
976 if(GetMapOfAIS().IsBound2(name))
977 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
979 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
985 //=======================================================================
988 //=======================================================================
989 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
991 if(argc==1) return 1;
992 Standard_Integer On = Draw::Atoi(argv[1]);
993 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
997 if(!Ctx->HasOpenedContext()){
998 di<<"sub intensite ";
1001 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1002 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1004 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1006 di <<"passage dans off"<<"\n";
1007 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1012 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1014 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1016 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1019 Ctx->UpdateCurrentViewer();
1022 Handle(AIS_InteractiveObject) IO;
1023 TCollection_AsciiString name = argv[2];
1024 if(GetMapOfAIS().IsBound2(name)){
1025 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1028 Ctx->SubIntensityOn(IO);
1030 Ctx->SubIntensityOff(IO);
1038 //==============================================================================
1039 //function : VColor2
1041 //purpose : change the color of a selected or named or displayed shape
1042 //Draw arg : vcolor2 [name] color
1043 //==============================================================================
1044 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1047 Standard_Boolean ThereIsCurrent;
1048 Standard_Boolean ThereIsArgument;
1049 Standard_Boolean IsBound = Standard_False ;
1051 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1053 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1054 ThereIsArgument = (argc != 2);
1057 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1058 ThereIsArgument = (argc == 2);
1061 if ( !a3DView().IsNull() ) {
1062 TCollection_AsciiString name;
1063 if (ThereIsArgument) {
1065 IsBound= GetMapOfAIS().IsBound2(name);
1067 if (TheAISContext()->HasOpenedContext())
1068 TheAISContext()->CloseLocalContext();
1070 // On set le Booleen There is current
1071 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1072 else ThereIsCurrent =Standard_False;
1074 //=======================================================================
1075 // Il y a un argument
1076 //=======================================================================
1077 if ( ThereIsArgument && IsBound ) {
1078 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1079 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1080 Handle(AIS_InteractiveObject) ashape =
1081 Handle(AIS_InteractiveObject)::DownCast (anObj);
1084 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1086 di << "HaveToSet 0\n";
1090 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1092 TheAISContext()->UnsetColor(ashape);
1093 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1094 Handle(NIS_Triangulated) ashape =
1095 Handle(NIS_Triangulated)::DownCast (anObj);
1096 if (!ashape.IsNull())
1097 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1102 //=======================================================================
1103 // Il n'y a pas d'arguments
1104 // Mais un ou plusieurs objets on des current representation
1105 //=======================================================================
1106 if (ThereIsCurrent && !ThereIsArgument) {
1107 for (TheAISContext() -> InitCurrent() ;
1108 TheAISContext() -> MoreCurrent() ;
1109 TheAISContext() ->NextCurrent() )
1111 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1112 if (ashape.IsNull())
1116 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1118 di << "HaveToSet 0\n";
1121 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1123 TheAISContext()->UnsetColor(ashape,Standard_False);
1126 TheAISContext()->UpdateCurrentViewer();
1129 //=======================================================================
1130 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1131 // on impose a tous les objets du viewer la couleur passee
1132 //=======================================================================
1133 else if (!ThereIsCurrent && !ThereIsArgument){
1134 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1135 while ( it.More() ) {
1136 const Handle(AIS_InteractiveObject) ashape =
1137 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1138 if (!ashape.IsNull()) {
1140 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1142 TheAISContext()->UnsetColor(ashape,Standard_False);
1146 TheAISContext()->UpdateCurrentViewer();
1152 //==============================================================================
1153 //function : VTransparency
1155 //purpose : change the transparency of a selected or named or displayed shape
1156 //Draw arg : vtransparency [name] TransparencyCoeficient
1157 //==============================================================================
1159 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1162 Standard_Boolean ThereIsCurrent;
1163 Standard_Boolean ThereIsArgument;
1164 Standard_Boolean IsBound = Standard_False ;
1166 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1168 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1169 ThereIsArgument = (argc != 2);
1172 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1173 ThereIsArgument = (argc == 2);
1176 if ( !a3DView().IsNull() ) {
1177 TCollection_AsciiString name;
1178 if (ThereIsArgument) {
1180 IsBound= GetMapOfAIS().IsBound2(name);
1182 if (TheAISContext()->HasOpenedContext())
1183 TheAISContext()->CloseLocalContext();
1185 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1186 else ThereIsCurrent = Standard_False;
1188 //=======================================================================
1189 // Il y a des arguments: un nom et une couleur
1190 //=======================================================================
1191 if ( ThereIsArgument && IsBound ) {
1192 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1193 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1194 const Handle(AIS_InteractiveObject) ashape =
1195 Handle(AIS_InteractiveObject)::DownCast(anObj);
1197 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1199 TheAISContext()->UnsetTransparency(ashape);
1200 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1201 const Handle(NIS_InteractiveObject) ashape =
1202 Handle(NIS_InteractiveObject)::DownCast(anObj);
1204 ashape->SetTransparency(Draw::Atof(argv[2]) );
1206 ashape->UnsetTransparency();
1209 //=======================================================================
1210 // Il n'y a pas d'arguments
1211 // Mais un ou plusieurs objets on des current representation
1212 //=======================================================================
1213 if (ThereIsCurrent && !ThereIsArgument) {
1214 for (TheAISContext() -> InitCurrent() ;
1215 TheAISContext() -> MoreCurrent() ;
1216 TheAISContext() ->NextCurrent() )
1218 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1220 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1222 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1225 TheAISContext()->UpdateCurrentViewer();
1227 //=======================================================================
1228 // Il n'y a pas d'arguments ET aucun objet courrant
1229 //=======================================================================
1230 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1231 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1233 while ( it.More() ) {
1234 Handle(AIS_InteractiveObject) ashape =
1235 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1236 if (!ashape.IsNull()) {
1238 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1240 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1244 TheAISContext()->UpdateCurrentViewer();
1251 //==============================================================================
1252 //function : VMaterial
1254 //purpose : change the Material of a selected or named or displayed shape
1255 //Draw arg : vmaterial [Name] Material
1256 //==============================================================================
1257 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1260 Standard_Boolean ThereIsCurrent;
1261 Standard_Boolean ThereIsName;
1262 Standard_Boolean IsBound = Standard_False ;
1264 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1266 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1267 ThereIsName = (argc != 2);
1270 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1271 ThereIsName = (argc == 2);
1274 if ( !a3DView().IsNull() ) {
1275 TCollection_AsciiString name;
1278 IsBound= GetMapOfAIS().IsBound2(name);
1280 if (TheAISContext()->HasOpenedContext())
1281 TheAISContext()->CloseLocalContext();
1282 if (TheAISContext() -> NbCurrents() > 0 )
1283 ThereIsCurrent =Standard_True;
1285 ThereIsCurrent =Standard_False;
1287 //=======================================================================
1288 // Ther is a name of shape and a material name
1289 //=======================================================================
1290 if ( ThereIsName && IsBound ) {
1291 Handle(AIS_InteractiveObject) ashape =
1292 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1293 if (!ashape.IsNull()) {
1295 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1297 TheAISContext()->UnsetMaterial(ashape);
1300 //=======================================================================
1301 // Il n'y a pas de nom de shape
1302 // Mais un ou plusieurs objets on des current representation
1303 //=======================================================================
1304 if (ThereIsCurrent && !ThereIsName) {
1305 for (TheAISContext() -> InitCurrent() ;
1306 TheAISContext() -> MoreCurrent() ;
1307 TheAISContext() ->NextCurrent() )
1309 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1311 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1313 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1315 TheAISContext()->UpdateCurrentViewer();
1318 //=======================================================================
1319 // Il n'y a pas de noms de shape ET aucun objet courrant
1320 // On impose a tous les objets du viewer le material passe en argument
1321 //=======================================================================
1322 else if (!ThereIsCurrent && !ThereIsName){
1323 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1325 while ( it.More() ) {
1326 Handle(AIS_InteractiveObject) ashape =
1327 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1328 if (!ashape.IsNull()) {
1330 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1332 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1336 TheAISContext()->UpdateCurrentViewer();
1344 //==============================================================================
1347 //purpose : change the width of the edges of a selected or named or displayed shape
1348 //Draw arg : vwidth [Name] WidthValue(1->10)
1349 //==============================================================================
1350 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1353 Standard_Boolean ThereIsCurrent;
1354 Standard_Boolean ThereIsArgument;
1355 Standard_Boolean IsBound = Standard_False ;
1357 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1359 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1360 ThereIsArgument = (argc != 2);
1363 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1364 ThereIsArgument = (argc == 2);
1366 if ( !a3DView().IsNull() ) {
1367 TCollection_AsciiString name;
1368 if (ThereIsArgument) {
1370 IsBound= GetMapOfAIS().IsBound2(name);
1372 if (TheAISContext()->HasOpenedContext())
1373 TheAISContext()->CloseLocalContext();
1375 if (TheAISContext() -> NbCurrents() > 0 )
1376 ThereIsCurrent =Standard_True;
1378 ThereIsCurrent =Standard_False;
1380 if ( ThereIsArgument && IsBound ) {
1381 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1382 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1383 const Handle(AIS_InteractiveObject) ashape =
1384 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1386 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1388 TheAISContext()->UnsetWidth (ashape);
1389 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1390 const Handle(NIS_Triangulated) ashape =
1391 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1392 if (HaveToSet && !ashape.IsNull())
1393 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1397 //=======================================================================
1398 // Il n'y a pas d'arguments
1399 // Mais un ou plusieurs objets on des current representation
1400 //=======================================================================
1401 if (ThereIsCurrent && !ThereIsArgument) {
1402 for (TheAISContext() -> InitCurrent() ;
1403 TheAISContext() -> MoreCurrent() ;
1404 TheAISContext() ->NextCurrent() )
1406 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1408 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1410 TheAISContext()->UnsetWidth(ashape,Standard_False);
1412 TheAISContext()->UpdateCurrentViewer();
1414 //=======================================================================
1415 // Il n'y a pas d'arguments ET aucun objet courrant
1416 //=======================================================================
1417 else if (!ThereIsCurrent && !ThereIsArgument){
1418 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1420 while ( it.More() ) {
1421 Handle(AIS_InteractiveObject) ashape =
1422 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1423 if (!ashape.IsNull()) {
1425 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1427 TheAISContext()->UnsetWidth(ashape,Standard_False);
1431 TheAISContext()->UpdateCurrentViewer();
1437 //==============================================================================
1438 //function : VInteriorStyle
1439 //purpose : sets interior style of the a selected or named or displayed shape
1440 //Draw arg : vsetinteriorstyle [shape] style
1441 //==============================================================================
1442 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1443 const Standard_Integer theStyle,
1444 Draw_Interpretor& di)
1446 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1447 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1448 " (Aspect_IS_HIDDENLINE)]\n";
1451 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1452 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1453 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1454 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1455 aFillAspect->SetInteriorStyle (aStyle);
1456 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1459 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1461 if (argc < 2 || argc > 3) {
1462 di << argv[0] << " requires 2 or 3 arguments\n";
1463 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1464 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1465 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1469 Standard_Boolean ThereIsCurrent;
1470 Standard_Boolean ThereIsArgument;
1471 Standard_Boolean IsBound = Standard_False ;
1473 ThereIsArgument = (argc > 2);
1474 if ( !a3DView().IsNull() ) {
1475 TCollection_AsciiString name;
1476 if (ThereIsArgument) {
1478 IsBound= GetMapOfAIS().IsBound2(name);
1480 if (TheAISContext()->HasOpenedContext())
1481 TheAISContext()->CloseLocalContext();
1483 if (TheAISContext() -> NbCurrents() > 0 )
1484 ThereIsCurrent =Standard_True;
1486 ThereIsCurrent =Standard_False;
1488 if ( ThereIsArgument && IsBound ) {
1489 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1490 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1491 const Handle(AIS_InteractiveObject) ashape =
1492 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1493 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1496 //=======================================================================
1497 // No arguments specified
1498 // But there are one or more selected objects
1499 //=======================================================================
1500 if (ThereIsCurrent && !ThereIsArgument) {
1501 for (TheAISContext() -> InitCurrent() ;
1502 TheAISContext() -> MoreCurrent() ;
1503 TheAISContext() ->NextCurrent() )
1505 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1506 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1509 //=======================================================================
1510 // No arguments specified and there are no selected objects
1511 //=======================================================================
1512 else if (!ThereIsCurrent && !ThereIsArgument){
1513 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1515 while ( it.More() ) {
1516 Handle(AIS_InteractiveObject) ashape =
1517 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1518 if (!ashape.IsNull())
1519 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1523 TheAISContext()->UpdateCurrentViewer();
1528 //==============================================================================
1529 //function : VDonly2
1531 //purpose : Display only a selected or named object
1532 // if there is no selected or named object s, nothing is donne
1533 //Draw arg : vdonly2 [name1] ... [name n]
1534 //==============================================================================
1535 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1538 if ( a3DView().IsNull() )
1541 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1542 Standard_Boolean ThereIsArgument= argc>1;
1544 if (TheAISContext()->HasOpenedContext())
1545 TheAISContext()->CloseLocalContext();
1547 //===============================================================
1548 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1550 //===============================================================
1551 if (!ThereIsArgument && ThereIsCurrent) {
1554 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1557 for(TheAISContext()->InitCurrent();
1558 TheAISContext()->MoreCurrent();
1559 TheAISContext()->NextCurrent()){
1560 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1561 TheAISContext()->Erase(aShape,Standard_False);}
1563 TheAISContext() ->UpdateCurrentViewer();
1564 //===============================================================
1565 // Il y a des arguments
1566 //===============================================================
1567 if (ThereIsArgument) {
1568 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1570 while ( it.More() ) {
1571 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1572 const Handle(AIS_InteractiveObject) aShape =
1573 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1574 TheAISContext()->Erase(aShape,Standard_False);
1575 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1576 const Handle(NIS_InteractiveObject) aShape =
1577 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1578 TheNISContext()->Erase(aShape);
1583 // On display les objets passes par parametre
1584 for (int i=1; i<argc ; i++) {
1585 TCollection_AsciiString name=argv[i];
1586 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1588 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1589 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1590 const Handle(AIS_InteractiveObject) aShape =
1591 Handle(AIS_InteractiveObject)::DownCast (anObj);
1592 TheAISContext()->Display(aShape, Standard_False);
1593 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1594 Handle(NIS_InteractiveObject) aShape =
1595 Handle(NIS_InteractiveObject)::DownCast (anObj);
1596 TheNISContext()->Display(aShape);
1600 TheAISContext() ->UpdateCurrentViewer();
1601 // TheNISContext() ->UpdateViews();
1606 //==============================================================================
1607 //function : VRemove
1608 //purpose : Removes selected or named objects.
1609 // If there is no selected or named objects,
1610 // all objects in the viewer can be removed with argument -all.
1611 // If -context is in arguments, the object is not deleted from the map of
1612 // objects (deleted only from the current context).
1613 //==============================================================================
1614 int VRemove (Draw_Interpretor& theDI,
1615 Standard_Integer theArgNb,
1616 const char** theArgVec)
1618 if (a3DView().IsNull())
1623 TheAISContext()->CloseAllContexts (Standard_False);
1625 //Standard_Boolean isStayedInMap = Standard_False;
1626 TCollection_AsciiString aContextOnlyStr ("-context");
1627 TCollection_AsciiString aRemoveAllStr ("-all");
1629 Standard_Boolean isContextOnly = (theArgNb > 1 && TCollection_AsciiString (theArgVec[1]) == aContextOnlyStr);
1631 Standard_Boolean isRemoveAll = (theArgNb == 3 && TCollection_AsciiString (theArgVec[2]) == aRemoveAllStr) ||
1632 (theArgNb == 2 && TCollection_AsciiString (theArgVec[1]) == aRemoveAllStr);
1634 NCollection_List<TCollection_AsciiString> anIONameList;
1638 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1639 anIter.More(); anIter.Next())
1641 anIONameList.Append (anIter.Key2());
1644 else if (isContextOnly ? theArgNb > 2 : theArgNb > 1) // removed objects names are in argument list
1646 for (Standard_Integer anIt = isContextOnly ? 2 : 1; anIt < theArgNb; ++anIt)
1648 TCollection_AsciiString aName = theArgVec[anIt];
1650 if (!GetMapOfAIS().IsBound2 (aName))
1652 theDI << aName.ToCString() << " was not bound to some object.\n";
1656 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
1658 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
1661 if (anIO->GetContext() != TheAISContext())
1663 theDI << aName.ToCString() << " was not displayed in current context.\n";
1664 theDI << "Please activate view with this object displayed and try again.\n";
1668 anIONameList.Append (aName);
1672 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
1673 if (!aNisIO.IsNull())
1675 anIONameList.Append (aName);
1679 else if (TheAISContext()->NbCurrents() > 0
1680 || TheNISContext()->GetSelected().Extent() > 0)
1682 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1683 anIter.More(); anIter.Next())
1685 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1688 if (!TheAISContext()->IsCurrent (anIO))
1693 anIONameList.Append (anIter.Key2());
1697 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1698 if (!aNisIO.IsNull())
1700 if (!TheNISContext()->IsSelected (aNisIO))
1705 anIONameList.Append (anIter.Key2());
1710 // Unbind all removed objects from the map of displayed IO.
1711 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
1712 anIter.More(); anIter.Next())
1714 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1718 TheAISContext()->Remove (anIO, Standard_False);
1719 theDI << anIter.Value().ToCString() << " was removed\n";
1723 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1724 if (!aNisIO.IsNull())
1726 TheNISContext()->Remove (aNisIO);
1727 theDI << anIter.Value().ToCString() << " was removed\n";
1733 GetMapOfAIS().UnBind2 (anIter.Value());
1737 TheAISContext()->UpdateCurrentViewer();
1741 //==============================================================================
1743 //purpose : Erase some selected or named objects
1744 // if there is no selected or named objects, the whole viewer is erased
1745 //==============================================================================
1746 int VErase (Draw_Interpretor& theDI,
1747 Standard_Integer theArgNb,
1748 const char** theArgVec)
1750 if (a3DView().IsNull())
1755 TheAISContext()->CloseAllContexts (Standard_False);
1756 const Standard_Boolean isEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "").IsEqual ("veraseall");
1761 std::cerr << " Syntax error: " << theArgVec[0] << " too much arguments.\n";
1765 // has a list of names
1766 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1768 TCollection_AsciiString aName = theArgVec[anArgIter];
1769 if (!GetMapOfAIS().IsBound2 (aName))
1774 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1775 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1776 theDI << aName.ToCString() << " ";
1779 TheAISContext()->Erase (anIO, Standard_False);
1783 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1784 if (!aNisIO.IsNull())
1786 TheNISContext()->Erase (aNisIO);
1790 TheAISContext()->UpdateCurrentViewer();
1795 && TheAISContext()->NbCurrents() > 0)
1797 // remove all currently selected objects
1798 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1799 anIter.More(); anIter.Next())
1801 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1803 && TheAISContext()->IsCurrent (anIO))
1805 theDI << anIter.Key2().ToCString() << " ";
1806 TheAISContext()->Erase (anIO, Standard_False);
1810 TheAISContext()->UpdateCurrentViewer();
1814 // erase entire viewer
1815 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1816 anIter.More(); anIter.Next())
1818 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1821 TheAISContext()->Erase (anIO, Standard_False);
1825 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1826 if (!aNisIO.IsNull())
1828 TheNISContext()->Erase (aNisIO);
1832 TheAISContext()->UpdateCurrentViewer();
1836 //==============================================================================
1837 //function : VDisplayAll
1839 //purpose : Display all the objects of the Map
1840 //Draw arg : vdisplayall
1841 //==============================================================================
1842 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1845 if (! a3DView().IsNull() ) {
1846 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1847 if (TheAISContext()->HasOpenedContext())
1848 TheAISContext()->CloseLocalContext();
1849 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1851 while ( it.More() ) {
1852 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1853 const Handle(AIS_InteractiveObject) aShape =
1854 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1855 TheAISContext()->Erase(aShape,Standard_False);
1856 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1857 const Handle(NIS_InteractiveObject) aShape =
1858 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1859 TheNISContext()->Erase(aShape);
1864 while ( it.More() ) {
1865 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1866 const Handle(AIS_InteractiveObject) aShape =
1867 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1868 TheAISContext()->Display(aShape, Standard_False);
1869 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1870 Handle(NIS_InteractiveObject) aShape =
1871 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1872 TheNISContext()->Display(aShape);
1876 TheAISContext() ->UpdateCurrentViewer();
1877 // TheNISContext() ->UpdateViews();
1882 //#######################################################################################################
1886 //#######################################################################################################
1888 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1890 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1891 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1892 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1893 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1894 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1896 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1897 if(myAISContext.IsNull())
1899 di << "use 'vinit' command before " << argv[0] << "\n";
1903 Handle(AIS_InteractiveObject) TheAisIO;
1904 Handle(AIS_TexturedShape) myShape;
1905 Standard_Integer myPreviousMode = 0;
1907 if (argc<2 || !argv[1])
1909 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1913 TCollection_AsciiString name = argv[1];
1914 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1916 if (GetMapOfAIS().IsBound2(name))
1917 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1918 (GetMapOfAIS().Find2(name));
1919 if (TheAisIO.IsNull())
1921 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1925 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1927 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1928 myPreviousMode = myShape->DisplayMode() ;
1932 myAISContext->Clear(TheAisIO,Standard_False);
1933 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1934 GetMapOfAIS().UnBind1(TheAisIO);
1935 GetMapOfAIS().UnBind2(name);
1936 GetMapOfAIS().Bind(myShape, name);
1940 case 1: // vtexture : we only map a texture on the shape
1943 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1946 if (argc>2 && argv[2])
1948 if(strcasecmp(argv[2],"?")==0)
1950 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1951 di<<"\n Files in current directory : \n"<<"\n";
1952 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1953 di.Eval(Cmnd.ToCString());
1955 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1958 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1959 di.Eval(Cmnd.ToCString());
1964 myShape->SetTextureFileName(argv[2]);
1968 di <<"Texture mapping disabled \n \
1969 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1971 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1972 if (myPreviousMode == 3 )
1973 myAISContext->RecomputePrsOnly(myShape);
1974 myAISContext->Display(myShape, Standard_True);
1979 case 2: // vtexscale : we change the scaling factor of the texture
1983 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1987 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1988 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1989 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1992 case 3: // vtexorigin : we change the origin of the texture on the shape
1995 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1998 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1999 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
2000 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
2003 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
2006 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2009 if (argc>2 && argv[2])
2011 di <<"Texture repeat enabled"<<"\n";
2012 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
2016 di <<"Texture repeat disabled"<<"\n";
2017 myShape->SetTextureRepeat(Standard_False);
2021 case 5: // vtexdefault : default texture mapping
2022 // ScaleU = ScaleV = 100.0
2023 // URepeat = VRepeat = 1.0
2024 // Uorigin = VOrigin = 0.0
2028 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2031 myShape->SetTextureRepeat(Standard_False);
2032 myShape->SetTextureOrigin(Standard_False);
2033 myShape->SetTextureScale (Standard_False);
2037 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
2038 myAISContext->RecomputePrsOnly(myShape);
2041 myAISContext->SetDisplayMode(myShape,3,Standard_False);
2042 myAISContext->Display(myShape, Standard_True);
2043 myAISContext->Update(myShape,Standard_True);
2048 //==============================================================================
2049 //function : VDisplay2
2051 //purpose : Display an object from its name
2052 //Draw arg : vdisplay name1 [name2] ... [name n]
2053 //==============================================================================
2054 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2057 // Verification des arguments
2058 if ( a3DView().IsNull() ) {
2060 ViewerTest::ViewerInit();
2061 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
2066 di<<argv[0]<<" Syntaxe error"<<"\n";
2071 TCollection_AsciiString name;
2072 if (TheAISContext()->HasOpenedContext())
2073 TheAISContext()->CloseLocalContext();
2075 for ( int i = 1; i < argc; i++ ) {
2077 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
2078 Standard_Boolean IsDatum = Standard_False;
2079 Handle(Standard_Transient) anObj;
2081 anObj = GetMapOfAIS().Find2(name);
2082 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
2083 Handle(AIS_InteractiveObject) aShape =
2084 Handle(AIS_InteractiveObject)::DownCast(anObj);
2085 if (aShape->Type()==AIS_KOI_Datum) {
2086 IsDatum = Standard_True;
2087 TheAISContext()->Display(aShape, Standard_False);
2090 di << "Display " << name.ToCString() << "\n";
2091 // Get the Shape from a name
2092 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2094 // Update the Shape in the AIS_Shape
2095 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2096 if(!TheRealSh.IsNull())
2097 TheRealSh->Set(NewShape);
2098 TheAISContext()->Redisplay(aShape, Standard_False);
2099 TheAISContext()->Display(aShape, Standard_False);
2102 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2103 Handle(NIS_InteractiveObject) aShape =
2104 Handle(NIS_InteractiveObject)::DownCast(anObj);
2105 TheNISContext()->Display(aShape);
2108 else { // Create the AIS_Shape from a name
2109 const Handle(AIS_InteractiveObject) aShape =
2110 GetAISShapeFromName((const char *)name.ToCString());
2111 if ( !aShape.IsNull() ) {
2112 GetMapOfAIS().Bind(aShape, name);
2113 TheAISContext()->Display(aShape, Standard_False);
2117 // Upadate the screen and redraw the view
2118 TheAISContext()->UpdateCurrentViewer();
2119 // TheNISContext()->UpdateViews();
2123 //===============================================================================================
2124 //function : VUpdate
2126 //===============================================================================================
2127 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2129 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2130 if (aContextAIS.IsNull())
2132 std::cout << theArgVec[0] << "AIS context is not available.\n";
2138 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2142 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2144 AIS_ListOfInteractive aListOfIO;
2146 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2148 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2150 Handle(AIS_InteractiveObject) anAISObj;
2151 if (anAISMap.IsBound2 (aName))
2153 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2156 if (anAISObj.IsNull())
2158 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2162 aListOfIO.Append (anAISObj);
2165 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2166 for (; anIOIt.More(); anIOIt.Next())
2168 aContextAIS->Update (anIOIt.Value(), Standard_False);
2171 aContextAIS->UpdateCurrentViewer();
2176 //==============================================================================
2178 //purpose : Test the annimation of an object along a
2179 // predifined trajectory
2180 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2181 //==============================================================================
2183 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2186 if (TheAISContext()->HasOpenedContext())
2187 TheAISContext()->CloseLocalContext();
2189 Standard_Real Step=4*M_PI/180;
2190 Standard_Real Angle=0;
2192 Handle(AIS_InteractiveObject) aIO;
2193 if (GetMapOfAIS().IsBound2(argv[1]))
2194 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2198 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2202 if (Draw::Atoi(argv[3])==1 ) {
2203 di<<" Primitives sensibles OFF"<<"\n";
2204 TheAISContext()->Deactivate(aIO);
2207 di<<" Primitives sensibles ON"<<"\n";
2209 // Movement par transformation
2210 if(Draw::Atoi(argv[2]) ==1) {
2211 di<<" Calcul par Transformation"<<"\n";
2212 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2216 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2217 TheAISContext()->SetLocation(aShape,myTransfo);
2218 TheAISContext() ->UpdateCurrentViewer();
2223 di<<" Calcul par Locations"<<"\n";
2224 gp_Trsf myAngleTrsf;
2225 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2226 TopLoc_Location myDeltaAngle (myAngleTrsf);
2227 TopLoc_Location myTrueLoc;
2229 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2232 myTrueLoc=myTrueLoc*myDeltaAngle;
2233 TheAISContext()->SetLocation(aShape,myTrueLoc );
2234 TheAISContext() ->UpdateCurrentViewer();
2237 if (Draw::Atoi(argv[3])==1 ){
2238 // On reactive la selection des primitives sensibles
2239 TheAISContext()->Activate(aIO,0);
2241 a3DView() -> Redraw();
2243 di<<" Temps ecoule "<<"\n";
2249 //==================================================================================
2250 // Function : VAnimation
2251 //==================================================================================
2252 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2254 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2258 Standard_Real thread = 4;
2259 Standard_Real angleA=0;
2260 Standard_Real angleB;
2262 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2265 TopoDS_Shape CrankArm;
2266 TopoDS_Shape CylinderHead;
2267 TopoDS_Shape Propeller;
2268 TopoDS_Shape EngineBlock;
2270 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2271 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2272 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2273 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2274 BRepTools::Read(CrankArm,argv[1],B);
2275 BRepTools::Read(CylinderHead,argv[2],B);
2276 BRepTools::Read(Propeller,argv[3],B);
2277 BRepTools::Read(EngineBlock,argv[4],B);
2279 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2285 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2286 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2287 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2288 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2290 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2291 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2292 GetMapOfAIS().Bind(myAisCrankArm,"c");
2293 GetMapOfAIS().Bind(myAisPropeller,"d");
2295 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2296 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2297 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2299 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2300 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2301 TheAISContext()->Display(myAisCrankArm,Standard_False );
2302 TheAISContext()->Display(myAisPropeller,Standard_False);
2304 TheAISContext()->Deactivate(myAisCylinderHead);
2305 TheAISContext()->Deactivate(myAisEngineBlock );
2306 TheAISContext()->Deactivate(myAisCrankArm );
2307 TheAISContext()->Deactivate(myAisPropeller );
2309 // Boucle de mouvement
2310 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2312 angleA = thread*myAngle*M_PI/180;
2313 X = Sin(angleA)*3/8;
2314 angleB = atan(X / Sqrt(-X * X + 1));
2315 Standard_Real decal(25*0.6);
2318 //Build a transformation on the display
2319 gp_Trsf aPropellerTrsf;
2320 aPropellerTrsf.SetRotation(Ax1,angleA);
2321 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2323 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));
2324 gp_Trsf aCrankArmTrsf;
2325 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2326 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2328 TheAISContext()->UpdateCurrentViewer();
2331 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2332 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2334 myAisCrankArm ->ResetLocation();
2335 myAisPropeller->ResetLocation();
2337 myAisCrankArm -> Set(myNewCrankArm );
2338 myAisPropeller -> Set(myNewPropeller);
2340 TheAISContext()->Activate(myAisCylinderHead,0);
2341 TheAISContext()->Activate(myAisEngineBlock,0 );
2342 TheAISContext()->Activate(myAisCrankArm ,0 );
2343 TheAISContext()->Activate(myAisPropeller ,0 );
2349 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2350 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2352 TheAISContext()->UpdateCurrentViewer();
2353 a3DView()->Redraw();
2362 //==============================================================================
2363 //function : VShading
2364 //purpose : Sharpen or roughten the quality of the shading
2365 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2366 //==============================================================================
2367 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2369 Standard_Real myDevCoef;
2370 Handle(AIS_InteractiveObject) TheAisIO;
2373 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2375 if (TheAISContext()->HasOpenedContext())
2376 TheAISContext()->CloseLocalContext();
2381 myDevCoef =Draw::Atof(argv[2]);
2384 TCollection_AsciiString name=argv[1];
2385 if (GetMapOfAIS().IsBound2(name ))
2386 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2387 if (TheAisIO.IsNull())
2388 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2391 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2393 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2395 TheAISContext()->Redisplay(TheAisIO);
2398 //==============================================================================
2399 //function : HaveMode
2400 //use : VActivatedModes
2401 //==============================================================================
2402 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2404 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2406 TColStd_ListOfInteger List;
2407 TheAISContext()->ActivatedModes (TheAisIO,List);
2408 TColStd_ListIteratorOfListOfInteger it;
2409 Standard_Boolean Found=Standard_False;
2410 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2411 if (it.Value()==mode ) Found=Standard_True;
2418 //==============================================================================
2419 //function : VActivatedMode
2421 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2422 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2423 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2424 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2425 // qu'un nom et qu'un mode.
2426 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2427 //==============================================================================
2428 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2430 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2433 Standard_Boolean ThereIsName = Standard_False ;
2435 if(!a3DView().IsNull()){
2437 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2438 // verification des arguments
2440 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2441 ThereIsName = (argc == 3);
2445 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2447 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2448 di<<" Fermeture du Context local"<<"\n";
2449 if (TheAISContext()->HasOpenedContext())
2450 TheAISContext()->CloseLocalContext();
2454 // IL n'y a aps de nom de shape passe en argument
2455 if (HaveToSet && !ThereIsName){
2456 Standard_Integer aMode=Draw::Atoi(argv [1]);
2458 const char *cmode="???";
2460 case 0: cmode = "Shape"; break;
2461 case 1: cmode = "Vertex"; break;
2462 case 2: cmode = "Edge"; break;
2463 case 3: cmode = "Wire"; break;
2464 case 4: cmode = "Face"; break;
2465 case 5: cmode = "Shell"; break;
2466 case 6: cmode = "Solid"; break;
2467 case 7: cmode = "Compound"; break;
2470 if( !TheAISContext()->HasOpenedContext() ) {
2471 // il n'y a pas de Context local d'ouvert
2472 // on en ouvre un et on charge toutes les shapes displayees
2473 // on load tous les objets displayees et on Activate les objets de la liste
2474 AIS_ListOfInteractive ListOfIO;
2475 // on sauve dans une AISListOfInteractive tous les objets currents
2476 if (TheAISContext()->NbCurrents()>0 ){
2477 TheAISContext()->UnhilightCurrents(Standard_False);
2479 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2480 ListOfIO.Append(TheAISContext()->Current() );
2484 TheAISContext()->OpenLocalContext(Standard_False);
2485 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2488 Handle(AIS_InteractiveObject) aIO =
2489 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2491 TheAISContext()->Load(aIO,0,Standard_False);
2494 // traitement des objets qui etaient currents dans le Contexte global
2495 if (!ListOfIO.IsEmpty() ) {
2496 // il y avait des objets currents
2497 AIS_ListIteratorOfListOfInteractive iter;
2498 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2499 Handle(AIS_InteractiveObject) aIO=iter.Value();
2500 TheAISContext()->Activate(aIO,aMode);
2501 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2505 // On applique le mode a tous les objets displayes
2506 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2507 it2 (GetMapOfAIS());
2509 Handle(AIS_InteractiveObject) aIO =
2510 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2511 if (!aIO.IsNull()) {
2512 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2513 TheAISContext()->Activate(aIO,aMode);
2522 // un Context local est deja ouvert
2523 // Traitement des objets du Context local
2524 if (TheAISContext()->NbSelected()>0 ){
2525 TheAISContext()->UnhilightSelected(Standard_False);
2526 // il y a des objets selected,on les parcourt
2527 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2528 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2531 if (HaveMode(aIO,aMode) ) {
2532 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2533 TheAISContext()->Deactivate(aIO,aMode);
2536 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2537 TheAISContext()->Activate(aIO,aMode);
2543 // il n'y a pas d'objets selected
2544 // tous les objets diplayes sont traites
2545 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2548 Handle(AIS_InteractiveObject) aIO =
2549 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2550 if (!aIO.IsNull()) {
2551 if (HaveMode(aIO,aMode) ) {
2552 di<<" Mode: "<<cmode<<" OFF pour "
2553 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2554 TheAISContext()->Deactivate(aIO,aMode);
2557 di<<" Mode: "<<cmode<<" ON pour"
2558 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2559 TheAISContext()->Activate(aIO,aMode);
2567 else if (HaveToSet && ThereIsName){
2568 Standard_Integer aMode=Draw::Atoi(argv [2]);
2569 Handle(AIS_InteractiveObject) aIO =
2570 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2572 if (!aIO.IsNull()) {
2573 const char *cmode="???";
2576 case 0: cmode = "Shape"; break;
2577 case 1: cmode = "Vertex"; break;
2578 case 2: cmode = "Edge"; break;
2579 case 3: cmode = "Wire"; break;
2580 case 4: cmode = "Face"; break;
2581 case 5: cmode = "Shell"; break;
2582 case 6: cmode = "Solid"; break;
2583 case 7: cmode = "Compound"; break;
2586 if( !TheAISContext()->HasOpenedContext() ) {
2587 TheAISContext()->OpenLocalContext(Standard_False);
2588 // On charge tous les objets de la map
2589 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2591 Handle(AIS_InteractiveObject) aShape=
2592 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2593 if (!aShape.IsNull())
2594 TheAISContext()->Load(aShape,0,Standard_False);
2597 TheAISContext()->Activate(aIO,aMode);
2598 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2602 // un Context local est deja ouvert
2603 if (HaveMode(aIO,aMode) ) {
2604 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2605 TheAISContext()->Deactivate(aIO,aMode);
2608 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2609 TheAISContext()->Activate(aIO,aMode);
2618 //! Auxiliary method to print Interactive Object information
2619 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
2620 const Handle(Standard_Transient)& theObject,
2621 Draw_Interpretor& theDI)
2623 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
2626 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
2630 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
2631 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
2632 << (theDetected.Contains (anObj) ? " Detected" : " ")
2634 if (anObj->Type() == AIS_KOI_Datum)
2637 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
2638 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
2639 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
2640 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
2641 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
2642 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
2643 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
2646 else if (anObj->Type() == AIS_KOI_Shape
2647 && anObj->Signature() == 0)
2649 theDI << " AIS_Shape";
2651 else if (anObj->Type() == AIS_KOI_Relation)
2653 // AIS_Dimention and AIS_Relation
2654 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
2655 switch (aRelation->KindOfDimension())
2657 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
2658 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
2659 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
2660 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
2661 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
2662 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
2663 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
2664 default: theDI << " UNKNOWN dimension"; break;
2669 theDI << " UserPrs";
2671 theDI << " (" << theObject->DynamicType()->Name() << ")";
2674 //! Print information about locally selected sub-shapes
2675 static void localCtxInfo (Draw_Interpretor& theDI)
2677 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2678 if (!aCtx->HasOpenedContext())
2683 TCollection_AsciiString aPrevName;
2684 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
2685 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
2687 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
2688 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
2689 if (aSubShape.IsNull()
2690 || aShapeIO.IsNull()
2691 || !GetMapOfAIS().IsBound1 (aShapeIO))
2696 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
2697 TopTools_MapOfShape aFilter;
2698 Standard_Integer aNumber = 0;
2699 const TopoDS_Shape aShape = aShapeIO->Shape();
2700 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
2701 anIter.More(); anIter.Next())
2703 if (!aFilter.Add (anIter.Current()))
2705 continue; // filter duplicates
2709 if (!anIter.Current().IsSame (aSubShape))
2714 Standard_CString aShapeName = NULL;
2715 switch (aSubShape.ShapeType())
2717 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
2718 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
2719 case TopAbs_SOLID: aShapeName = " Solid"; break;
2720 case TopAbs_SHELL: aShapeName = " Shell"; break;
2721 case TopAbs_FACE: aShapeName = " Face"; break;
2722 case TopAbs_WIRE: aShapeName = " Wire"; break;
2723 case TopAbs_EDGE: aShapeName = " Edge"; break;
2724 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
2726 case TopAbs_SHAPE: aShapeName = " Shape"; break;
2729 if (aParentName != aPrevName)
2731 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
2732 aPrevName = aParentName;
2734 theDI << " " << aShapeName << " #" << aNumber << "\n";
2740 //==============================================================================
2743 //Draw arg : vstate [nameA] ... [nameN]
2744 //==============================================================================
2745 static Standard_Integer VState (Draw_Interpretor& theDI,
2746 Standard_Integer theArgNb,
2747 Standard_CString* theArgVec)
2749 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
2752 std::cerr << "Error: No opened viewer!\n";
2756 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
2757 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
2759 aDetected.Add (aCtx->DetectedCurrentObject());
2762 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
2766 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2768 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
2769 if (!GetMapOfAIS().IsBound2 (anObjName))
2771 theDI << anObjName << " doesn't exist!\n";
2775 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
2776 TCollection_AsciiString aName = anObjName;
2777 aName.LeftJustify (20, ' ');
2778 theDI << " " << aName << " ";
2779 objInfo (aDetected, anObjTrans, theDI);
2785 if (aCtx->NbCurrents() > 0
2788 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2790 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
2791 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
2792 aName.LeftJustify (20, ' ');
2793 theDI << aName << " ";
2794 objInfo (aDetected, anObj, theDI);
2800 theDI << "Neutral-point state:\n";
2801 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
2802 anObjIter.More(); anObjIter.Next())
2804 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
2810 TCollection_AsciiString aName = anObjIter.Key2();
2811 aName.LeftJustify (20, ' ');
2812 theDI << " " << aName << " ";
2813 objInfo (aDetected, anObj, theDI);
2816 localCtxInfo (theDI);
2820 //=======================================================================
2821 //function : PickObjects
2823 //=======================================================================
2824 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2825 const AIS_KindOfInteractive TheType,
2826 const Standard_Integer TheSignature,
2827 const Standard_Integer MaxPick)
2829 Handle(AIS_InteractiveObject) IO;
2830 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2832 // step 1: prepare the data
2834 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2835 TheAISContext()->AddFilter(F1);
2838 // step 2 : wait for the selection...
2839 // Standard_Boolean IsGood (Standard_False);
2840 // Standard_Integer NbPick(0);
2841 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2842 Standard_Integer NbPickFail(0);
2843 Standard_Integer argccc = 5;
2844 const char *bufff[] = { "A", "B", "C","D", "E" };
2845 const char **argvvv = (const char **) bufff;
2848 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2849 while(ViewerMainLoop(argccc,argvvv)){}
2850 Standard_Integer NbStored = TheAISContext()->NbSelected();
2851 if((unsigned int ) NbStored != NbPickGood)
2852 NbPickGood= NbStored;
2855 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2858 // step3 get result.
2860 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2862 Standard_Integer i(0);
2863 for(TheAISContext()->InitSelected();
2864 TheAISContext()->MoreSelected();
2865 TheAISContext()->NextSelected()){
2867 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2868 arr->SetValue(i,IO2);
2873 TheAISContext()->CloseLocalContext(curindex);
2875 return Standard_True;
2879 //=======================================================================
2880 //function : PickObject
2882 //=======================================================================
2883 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2884 const Standard_Integer TheSignature,
2885 const Standard_Integer MaxPick)
2887 Handle(AIS_InteractiveObject) IO;
2888 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2890 // step 1: prepare the data
2893 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2894 TheAISContext()->AddFilter(F1);
2897 // step 2 : wait for the selection...
2898 Standard_Boolean IsGood (Standard_False);
2899 Standard_Integer NbPick(0);
2900 Standard_Integer argccc = 5;
2901 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2902 const char **argvvv = (const char **) bufff;
2905 while(!IsGood && NbPick<= MaxPick){
2906 while(ViewerMainLoop(argccc,argvvv)){}
2907 IsGood = (TheAISContext()->NbSelected()>0) ;
2909 cout<<"Nb Pick :"<<NbPick<<endl;
2913 // step3 get result.
2915 TheAISContext()->InitSelected();
2916 IO = TheAISContext()->SelectedInteractive();
2920 TheAISContext()->CloseLocalContext(curindex);
2924 //=======================================================================
2925 //function : PickShape
2926 //purpose : First Activate the rightmode + Put Filters to be able to
2927 // pick objets that are of type <TheType>...
2928 //=======================================================================
2930 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2931 const Standard_Integer MaxPick)
2934 // step 1: prepare the data
2936 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2937 TopoDS_Shape result;
2939 if(TheType==TopAbs_SHAPE){
2940 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2941 TheAISContext()->AddFilter(F1);
2944 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2945 TheAISContext()->AddFilter(TF);
2946 TheAISContext()->ActivateStandardMode(TheType);
2951 // step 2 : wait for the selection...
2952 Standard_Boolean NoShape (Standard_True);
2953 Standard_Integer NbPick(0);
2954 Standard_Integer argccc = 5;
2955 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2956 const char **argvvv = (const char **) bufff;
2959 while(NoShape && NbPick<= MaxPick){
2960 while(ViewerMainLoop(argccc,argvvv)){}
2961 NoShape = (TheAISContext()->NbSelected()==0) ;
2963 cout<<"Nb Pick :"<<NbPick<<endl;
2966 // step3 get result.
2970 TheAISContext()->InitSelected();
2971 if(TheAISContext()->HasSelectedShape())
2972 result = TheAISContext()->SelectedShape();
2974 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2975 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2980 TheAISContext()->CloseLocalContext(curindex);
2986 //=======================================================================
2987 //function : PickShapes
2989 //=======================================================================
2990 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2991 Handle(TopTools_HArray1OfShape)& thearr,
2992 const Standard_Integer MaxPick)
2995 Standard_Integer Taille = thearr->Length();
2997 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2999 // step 1: prepare the data
3000 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3001 if(TheType==TopAbs_SHAPE){
3002 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3003 TheAISContext()->AddFilter(F1);
3006 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3007 TheAISContext()->AddFilter(TF);
3008 TheAISContext()->ActivateStandardMode(TheType);
3012 // step 2 : wait for the selection...
3014 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3015 Standard_Integer NbPickFail(0);
3016 Standard_Integer argccc = 5;
3017 const char *bufff[] = { "A", "B", "C","D", "E" };
3018 const char **argvvv = (const char **) bufff;
3021 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3022 while(ViewerMainLoop(argccc,argvvv)){}
3023 Standard_Integer NbStored = TheAISContext()->NbSelected();
3024 if((unsigned int ) NbStored != NbPickGood)
3025 NbPickGood= NbStored;
3028 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3031 // step3 get result.
3033 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3035 Standard_Integer i(0);
3036 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3038 if(TheAISContext()->HasSelectedShape())
3039 thearr->SetValue(i,TheAISContext()->SelectedShape());
3041 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3042 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3046 TheAISContext()->CloseLocalContext(curindex);
3047 return Standard_True;
3051 //=======================================================================
3052 //function : VPickShape
3054 //=======================================================================
3055 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3057 TopoDS_Shape PickSh;
3058 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3061 theType = TopAbs_SHAPE;
3063 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3064 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3065 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3066 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3067 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3068 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3069 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3072 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3073 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3075 TCollection_AsciiString name;
3078 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3080 PickSh = ViewerTest::PickShape(theType);
3089 if(!PickSh.IsNull()){
3090 nbOfSub[Standard_Integer(theType)]++;
3092 name += nameType[Standard_Integer(theType)];
3093 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3098 // si on avait une petite methode pour voir si la shape
3099 // est deja dans la Double map, ca eviterait de creer....
3100 DBRep::Set(name.ToCString(),PickSh);
3102 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3103 GetMapOfAIS().Bind(newsh, name);
3104 TheAISContext()->Display(newsh);
3105 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3108 // Plusieurs objets a picker, vite vite vite....
3111 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3112 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3113 if(ViewerTest::PickShapes(theType,arr)){
3114 for(Standard_Integer i=1;i<=NbToPick;i++){
3115 PickSh = arr->Value(i);
3116 if(!PickSh.IsNull()){
3118 nbOfSub[Standard_Integer(theType)]++;
3121 name += nameType[Standard_Integer(theType)];
3122 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3130 DBRep::Set(name.ToCString(),PickSh);
3131 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3132 GetMapOfAIS().Bind(newsh, name);
3133 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3134 TheAISContext()->Display(newsh);
3142 //=======================================================================
3143 //function : list of known objects
3145 //=======================================================================
3146 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3148 // 1234567890 12345678901234567 123456789
3149 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3150 TCollection_AsciiString BlankLine(64,'_');
3151 Standard_Integer i ;
3153 di<<"/n"<<BlankLine.ToCString()<<"\n";
3156 Colum[i].Center(20,' ');
3158 di<<"|"<<Colum[i].ToCString();
3161 di<<BlankLine.ToCString()<<"\n";
3163 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3164 const char ** names = GetTypeNames();
3166 TCollection_AsciiString curstring;
3167 TCollection_AsciiString curcolum[3];
3170 // les objets de type Datum..
3171 curcolum[1]+="Datum";
3173 curcolum[0].Clear();
3174 curcolum[0] += names[i];
3176 curcolum[2].Clear();
3177 curcolum[2]+=TCollection_AsciiString(i+1);
3179 for(Standard_Integer j =0;j<=2;j++){
3180 curcolum[j].Center(20,' ');
3181 di<<"|"<<curcolum[j].ToCString();
3185 di<<BlankLine.ToCString()<<"\n";
3187 // les objets de type shape
3188 curcolum[1].Clear();
3189 curcolum[1]+="Shape";
3190 curcolum[1].Center(20,' ');
3193 curcolum[0].Clear();
3194 curcolum[0] += names[7+i];
3195 curcolum[2].Clear();
3196 curcolum[2]+=TCollection_AsciiString(i);
3198 for(Standard_Integer j =0;j<=2;j++){
3199 curcolum[j].Center(20,' ');
3200 di<<"|"<<curcolum[j].ToCString();
3204 di<<BlankLine.ToCString()<<"\n";
3205 // les IO de type objet...
3206 curcolum[1].Clear();
3207 curcolum[1]+="Object";
3208 curcolum[1].Center(20,' ');
3210 curcolum[0].Clear();
3211 curcolum[0] += names[10+i];
3212 curcolum[2].Clear();
3213 curcolum[2]+=TCollection_AsciiString(i);
3215 for(Standard_Integer j =0;j<=2;j++){
3216 curcolum[j].Center(20,' ');
3217 di<<"|"<<curcolum[j].ToCString();
3221 di<<BlankLine.ToCString()<<"\n";
3222 // les contraintes et dimensions.
3223 // pour l'instant on separe juste contraintes et dimensions...
3224 // plus tard, on detaillera toutes les sortes...
3225 curcolum[1].Clear();
3226 curcolum[1]+="Relation";
3227 curcolum[1].Center(20,' ');
3229 curcolum[0].Clear();
3230 curcolum[0] += names[12+i];
3231 curcolum[2].Clear();
3232 curcolum[2]+=TCollection_AsciiString(i);
3234 for(Standard_Integer j =0;j<=2;j++){
3235 curcolum[j].Center(20,' ');
3236 di<<"|"<<curcolum[j].ToCString();
3240 di<<BlankLine.ToCString()<<"\n";
3247 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3249 if(argc!=2) return 1;
3251 AIS_KindOfInteractive TheType;
3252 Standard_Integer TheSign(-1);
3253 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3256 AIS_ListOfInteractive LIO;
3258 // en attendant l'amelioration ais pour les dimensions...
3260 Standard_Integer dimension_status(-1);
3261 if(TheType==AIS_KOI_Relation){
3262 dimension_status = TheSign ==1 ? 1 : 0;
3266 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3267 Handle(AIS_InteractiveObject) curio;
3268 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3271 if(dimension_status == -1)
3272 TheAISContext()->Erase(curio,Standard_False);
3274 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3275 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3276 (dimension_status==1 && KOD != AIS_KOD_NONE))
3277 TheAISContext()->Erase(curio,Standard_False);
3280 TheAISContext()->UpdateCurrentViewer();
3283 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3285 if(argc!=2) return 1;
3287 AIS_KindOfInteractive TheType;
3288 Standard_Integer TheSign(-1);
3289 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3291 // en attendant l'amelioration ais pour les dimensions...
3293 Standard_Integer dimension_status(-1);
3294 if(TheType==AIS_KOI_Relation){
3295 dimension_status = TheSign ==1 ? 1 : 0;
3299 AIS_ListOfInteractive LIO;
3300 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3301 Handle(AIS_InteractiveObject) curio;
3302 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3304 if(dimension_status == -1)
3305 TheAISContext()->Display(curio,Standard_False);
3307 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3308 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3309 (dimension_status==1 && KOD != AIS_KOD_NONE))
3310 TheAISContext()->Display(curio,Standard_False);
3315 TheAISContext()->UpdateCurrentViewer();
3319 //==============================================================================
3320 //function : VSetTransMode
3322 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3323 //==============================================================================
3325 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3326 // Verification des arguments
3327 if ( a3DView().IsNull() ) {
3328 ViewerTest::ViewerInit();
3329 di << "La commande vinit n'a pas ete appele avant" << "\n";
3332 if ( argc < 3 || argc > 8 ) {
3333 di << argv[0] << " Invalid number of arguments" << "\n";
3337 TCollection_AsciiString shapeName;
3338 shapeName = argv[1];
3339 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3340 Standard_Integer persFlag2 = 0;
3341 Standard_Integer persFlag3 = 0;
3342 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3343 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3344 persFlag2 = Draw::Atoi(argv[3]);
3346 if ( argc == 5 || argc == 8 ) {
3347 persFlag3 = Draw::Atoi(argv[4]);
3350 origin.SetX( Draw::Atof(argv[argc - 3]) );
3351 origin.SetY( Draw::Atof(argv[argc - 2]) );
3352 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3355 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3356 Handle(Standard_Transient) anObj;
3358 anObj = GetMapOfAIS().Find2(shapeName);
3359 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3360 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3361 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3362 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3363 di << argv[0] << " All persistence modifiers were removed" << "\n";
3366 di << argv[0] << " Wrong object type" << "\n";
3369 } else { // Create the AIS_Shape from a name
3370 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3371 if ( !aShape.IsNull() ) {
3372 GetMapOfAIS().Bind( aShape, shapeName );
3373 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3374 TheAISContext()->Display( aShape, Standard_False );
3376 di << argv[0] << " Object not found" << "\n";
3381 // Upadate the screen and redraw the view
3382 TheAISContext()->UpdateCurrentViewer();
3386 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3389 BRep_Builder builder;
3391 BRepTools::Read(shape, s, builder);
3392 DBRep::Set(a[1], shape);
3393 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3394 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3399 //==============================================================================
3400 //function : ViewerTest::Commands
3401 //purpose : Add all the viewer command in the Draw_Interpretor
3402 //==============================================================================
3404 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3406 ViewerTest::ViewerCommands(theCommands);
3407 ViewerTest::RelationCommands(theCommands);
3408 ViewerTest::ObjectCommands(theCommands);
3409 ViewerTest::FilletCommands(theCommands);
3410 ViewerTest::VoxelCommands(theCommands);
3411 ViewerTest::OpenGlCommands(theCommands);
3413 const char *group = "AIS_Display";
3416 theCommands.Add("visos",
3417 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3418 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3419 __FILE__, visos, group);
3421 theCommands.Add("vdisplay",
3422 "vdisplay name1 [name2] ... [name n]"
3423 "\n\t\t: Displays named objects",
3424 __FILE__,VDisplay2,group);
3426 theCommands.Add ("vupdate",
3427 "vupdate name1 [name2] ... [name n]"
3428 "\n\t\t: Updates named objects in interactive context",
3429 __FILE__, VUpdate, group);
3431 theCommands.Add("verase",
3432 "verase [name1] ... [name n]"
3433 "\n\t\t: Erases selected or named objects."
3434 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3435 __FILE__, VErase, group);
3437 theCommands.Add("vremove",
3438 "vremove [-context] [name1] ... [name n]"
3439 "or vremove [-context] -all to remove all objects"
3440 "\n\t\t: Removes selected or named objects."
3441 "\n\t\t If -context is in arguments, the objects are not deleted"
3442 "\n\t\t from the map of objects and names.",
3443 __FILE__, VRemove, group);
3445 theCommands.Add("vdonly",
3446 "vdonly [name1] ... [name n]"
3447 "\n\t\t: Displays only selected or named objects",
3448 __FILE__,VDonly2,group);
3450 theCommands.Add("vdisplayall",
3451 "Displays all erased interactive objects (see vdir and vstate)",
3452 __FILE__,VDisplayAll,group);
3454 theCommands.Add("veraseall",
3455 "Erases all objects displayed in the viewer",
3456 __FILE__, VErase, group);
3458 theCommands.Add("verasetype",
3460 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3461 __FILE__,VEraseType,group);
3463 theCommands.Add("vdisplaytype",
3464 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3465 __FILE__,VDisplayType,group);
3467 theCommands.Add("vdisplaymode",
3468 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3469 __FILE__,VDispMode,group);
3471 theCommands.Add("verasemode",
3472 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3473 __FILE__,VDispMode,group);
3475 theCommands.Add("vsetdispmode",
3476 "vsetdispmode [name] mode(1,2,..)"
3477 "\n\t\t: Sets display mode for all, selected or named objects.",
3478 __FILE__,VDispMode,group);
3480 theCommands.Add("vunsetdispmode",
3481 "vunsetdispmode [name]"
3482 "\n\t\t: Unsets custom display mode for selected or named objects.",
3483 __FILE__,VDispMode,group);
3485 theCommands.Add("vdir",
3486 "Lists all objects displayed in 3D viewer",
3487 __FILE__,VDebug,group);
3489 theCommands.Add("vdump",
3490 #ifdef HAVE_FREEIMAGE
3491 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]"
3492 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3494 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}]"
3495 "\n\t\t: Dumps contents of viewer window to PPM image file",
3497 __FILE__,VDump,group);
3499 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3500 __FILE__,VSubInt,group);
3502 theCommands.Add("vsetcolor",
3503 "vsetcolor [name] ColorName"
3504 "\n\t\t: Sets color for all, selected or named objects.",
3505 __FILE__,VColor2,group);
3507 theCommands.Add("vunsetcolor",
3508 "vunsetcolor [name]"
3509 "\n\t\t: Resets color for all, selected or named objects.",
3510 __FILE__,VColor2,group);
3512 theCommands.Add("vsettransparency",
3513 "vsettransparency [name] Coefficient"
3514 "\n\t\t: Sets transparency for all, selected or named objects."
3515 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3516 __FILE__,VTransparency,group);
3518 theCommands.Add("vunsettransparency",
3519 "vunsettransparency [name]"
3520 "\n\t\t: Resets transparency for all, selected or named objects.",
3521 __FILE__,VTransparency,group);
3523 theCommands.Add("vsetmaterial",
3524 "vmaterial : vmaterial [name of shape] MaterialName",
3525 __FILE__,VMaterial,group);
3527 theCommands.Add("vunsetmaterial",
3528 "vmaterial : vmaterial [name of shape]",
3529 __FILE__,VMaterial,group);
3531 theCommands.Add("vsetwidth",
3532 "vsetwidth : vwidth [name of shape] width(0->10)",
3533 __FILE__,VWidth,group);
3535 theCommands.Add("vunsetwidth",
3536 "vunsetwidth : vwidth [name of shape]",
3537 __FILE__,VWidth,group);
3539 theCommands.Add("vsetinteriorstyle",
3540 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3541 __FILE__,VInteriorStyle,group);
3543 theCommands.Add("vardis",
3544 "vardis : display activeareas",
3545 __FILE__,VDispAreas,group);
3547 theCommands.Add("varera",
3548 "varera : erase activeareas",
3549 __FILE__,VClearAreas,group);
3551 theCommands.Add("vsensdis",
3552 "vardisp : display active entities",
3553 __FILE__,VDispSensi,group);
3554 theCommands.Add("vsensera",
3555 "vardisp : erase active entities",
3556 __FILE__,VClearSensi,group);
3558 theCommands.Add("vselprecision",
3559 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3560 __FILE__,VSelPrecision,group);
3562 theCommands.Add("vperf",
3563 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3564 __FILE__,VPerf,group);
3566 theCommands.Add("vanimation",
3567 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3568 __FILE__,VAnimation,group);
3570 theCommands.Add("vsetshading",
3571 "vsetshading : vsetshading name Quality(default=0.0008) ",
3572 __FILE__,VShading,group);
3574 theCommands.Add("vunsetshading",
3575 "vunsetshading :vunsetshading name ",
3576 __FILE__,VShading,group);
3578 theCommands.Add("vtexture",
3579 "'vtexture NameOfShape TextureFile' \n \
3580 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3581 or 'vtexture NameOfShape ?' to list available textures\n \
3582 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3583 __FILE__,VTexture,group);
3585 theCommands.Add("vtexscale",
3586 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3587 or 'vtexscale NameOfShape ScaleUV' \n \
3588 or 'vtexscale NameOfShape' to disable scaling\n ",
3589 __FILE__,VTexture,group);
3591 theCommands.Add("vtexorigin",
3592 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3593 or 'vtexorigin NameOfShape UVOrigin' \n \
3594 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3595 __FILE__,VTexture,group);
3597 theCommands.Add("vtexrepeat",
3598 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3599 or 'vtexrepeat NameOfShape UVRepeat \n \
3600 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3603 theCommands.Add("vtexdefault",
3604 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3607 theCommands.Add("vsetam",
3608 "vsetActivatedModes: vsetam mode(1->7) ",
3609 __FILE__,VActivatedMode,group);
3611 theCommands.Add("vunsetam",
3612 "vunsetActivatedModes: vunsetam ",
3613 __FILE__,VActivatedMode,group);
3615 theCommands.Add("vstate",
3616 "vstate [name1] ... [nameN]"
3617 "\n\t\t: Reports show/hidden state for selected or named objects",
3618 __FILE__,VState,group);
3620 theCommands.Add("vpickshapes",
3621 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3622 __FILE__,VPickShape,group);
3624 theCommands.Add("vtypes",
3625 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3628 theCommands.Add("vsettransmode",
3629 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3630 __FILE__,VSetTransMode,group);
3632 theCommands.Add("vr", "vr : reading of the shape",
3633 __FILE__,vr, group);
3637 //=====================================================================
3638 //========================= for testing Draft and Rib =================
3639 //=====================================================================
3640 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3641 #include <DBRep.hxx>
3642 #include <TopoDS_Face.hxx>
3643 #include <gp_Pln.hxx>
3644 #include <AIS_KindOfSurface.hxx>
3645 #include <BRepOffsetAPI_DraftAngle.hxx>
3646 #include <Precision.hxx>
3647 #include <BRepAlgo.hxx>
3648 #include <OSD_Environment.hxx>
3649 #include <DrawTrSurf.hxx>
3650 //#include <DbgTools.hxx>
3651 //#include <FeatAlgo_MakeLinearForm.hxx>
3656 //=======================================================================
3657 //function : IsValid
3659 //=======================================================================
3660 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3661 const TopoDS_Shape& theResult,
3662 const Standard_Boolean closedSolid,
3663 const Standard_Boolean GeomCtrl)
3665 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3666 TCollection_AsciiString checkValid = check.Value();
3667 Standard_Boolean ToCheck = Standard_True;
3668 if (!checkValid.IsEmpty()) {
3670 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3672 if ( checkValid=="true" || checkValid=="TRUE" ) {
3673 ToCheck= Standard_False;
3677 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3680 Standard_Boolean IsValid = Standard_True;
3682 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3687 //===============================================================================
3688 // TDraft : test draft, uses AIS Viewer
3689 // Solid Face Plane Angle Reverse
3690 //===============================================================================
3691 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3693 if (argc < 5) return 1;
3694 // argv[1] - TopoDS_Shape Solid
3695 // argv[2] - TopoDS_Shape Face
3696 // argv[3] - TopoDS_Shape Plane
3697 // argv[4] - Standard_Real Angle
3698 // argv[5] - Standard_Integer Reverse
3700 // Sprintf(prefix, argv[1]);
3701 Standard_Real anAngle = 0;
3702 Standard_Boolean Rev = Standard_False;
3703 Standard_Integer rev = 0;
3704 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3705 TopoDS_Shape face = GetShapeFromName(argv[2]);
3706 TopoDS_Face Face = TopoDS::Face(face);
3707 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3708 if (Plane.IsNull ()) {
3709 di << "TEST : Plane is NULL" << "\n";
3712 anAngle = Draw::Atof(argv[4]);
3713 anAngle = 2*M_PI * anAngle / 360.0;
3715 Handle( Geom_Surface )aSurf;
3716 AIS_KindOfSurface aSurfType;
3717 Standard_Real Offset;
3719 if(argc > 4) { // == 5
3720 rev = Draw::Atoi(argv[5]);
3721 Rev = (rev)? Standard_True : Standard_False;
3724 TopoDS_Face face2 = TopoDS::Face(Plane);
3725 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3727 di << "TEST : Can't find plane" << "\n";
3731 aDir = aPln.Axis().Direction();
3734 if (Plane.Orientation() == TopAbs_REVERSED)
3736 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3738 BRepOffsetAPI_DraftAngle Draft (Solid);
3740 if(Abs(anAngle)< Precision::Angular()) {
3741 di << "TEST : NULL angle" << "\n";
3744 if(Rev) anAngle = - anAngle;
3745 Draft.Add (Face, aDir, anAngle, aPln);
3747 if (!Draft.IsDone()) {
3748 di << "TEST : Draft Not DONE " << "\n";
3751 TopTools_ListOfShape Larg;
3753 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3754 di << "TEST : DesignAlgo returns Not valid" << "\n";
3758 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3759 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3761 if ( !ais.IsNull() ) {
3762 ais->SetColor(DEFAULT_COLOR);
3763 ais->SetMaterial(DEFAULT_MATERIAL);
3764 // Display the AIS_Shape without redraw
3765 Ctx->Display(ais, Standard_False);
3767 const char *Name = "draft1";
3768 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3770 Handle(AIS_InteractiveObject) an_object =
3771 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3772 if (!an_object.IsNull()) {
3773 Ctx->Remove(an_object,
3775 GetMapOfAIS().UnBind2(Name) ;
3778 GetMapOfAIS().Bind(ais, Name);
3779 // DBRep::Set("draft", ais->Shape());
3781 Ctx->Display(ais, Standard_True);
3785 //==============================================================================
3786 //function : splitParameter
3787 //purpose : Split parameter string to parameter name and parameter value
3788 //==============================================================================
3789 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
3790 TCollection_AsciiString& theName,
3791 TCollection_AsciiString& theValue)
3793 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
3795 if (aParamNameEnd == 0)
3797 return Standard_False;
3800 TCollection_AsciiString aString (theString);
3801 if (aParamNameEnd != 0)
3803 theValue = aString.Split (aParamNameEnd);
3804 aString.Split (aString.Length() - 1);
3808 return Standard_True;
3811 //============================================================================
3813 //============================================================================
3814 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3817 DrawTrSurf::BasicCommands(theCommands);
3818 const char* group = "Check Features Operations commands";
3820 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3822 &TDraft,group); //Draft_Modification
3825 //==============================================================================
3826 // ViewerTest::Factory
3827 //==============================================================================
3828 void ViewerTest::Factory(Draw_Interpretor& theDI)
3830 // definition of Viewer Command
3831 ViewerTest::Commands(theDI);
3832 ViewerTest::AviCommands(theDI);
3835 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3839 // Declare entry point PLUGINFACTORY