1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_TextureRoot.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Prs3d_ShadingAspect.hxx>
69 #include <Draw_Interpretor.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <Draw_PluginMacro.hxx>
72 #include <ViewerTest.hxx>
73 #include <Viewer2dTest.hxx>
75 // avoid warnings on 'extern "C"' functions returning C++ classes
77 #define _CRT_SECURE_NO_DEPRECATE
78 #pragma warning(4:4190)
79 #pragma warning (disable:4996)
82 #include <NIS_InteractiveContext.hxx>
83 #include <NIS_Triangulated.hxx>
84 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
86 #include <Quantity_Color.hxx>
87 #include <Quantity_NameOfColor.hxx>
89 #include <Graphic3d_NameOfMaterial.hxx>
91 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
92 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
94 //=======================================================================
95 //function : GetColorFromName
96 //purpose : get the Quantity_NameOfColor from a string
97 //=======================================================================
99 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
101 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
103 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
104 if (strcasecmp (theName, aColorName) == 0)
106 return Quantity_NameOfColor (anIter);
110 return DEFAULT_COLOR;
113 //=======================================================================
114 //function : GetMaterialFromName
115 //purpose : get the Graphic3d_NameOfMaterial from a string
116 //=======================================================================
118 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
120 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
122 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
123 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
124 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
125 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
126 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
127 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
128 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
129 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
130 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
131 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
132 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
133 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
134 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
135 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
136 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
137 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
138 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
139 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
140 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
145 //=======================================================================
146 //function : GetTypeNames
148 //=======================================================================
149 static const char** GetTypeNames()
151 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
152 "Shape","ConnectedShape","MultiConn.Shape",
153 "ConnectedInter.","MultiConn.",
154 "Constraint","Dimension"};
155 static const char** ThePointer = names;
159 //=======================================================================
160 //function : GetTypeAndSignfromString
162 //=======================================================================
163 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
165 const char ** thefullnames = GetTypeNames();
166 Standard_Integer index(-1);
168 for(Standard_Integer i=0;i<=13 && index==-1;i++)
169 if(!strcasecmp(name,thefullnames[i]))
173 TheType = AIS_KOI_None;
179 TheType = AIS_KOI_Datum;
183 TheType = AIS_KOI_Shape;
187 TheType = AIS_KOI_Object;
191 TheType = AIS_KOI_Relation;
200 #include <Draw_Interpretor.hxx>
202 #include <Draw_Appli.hxx>
206 #include <TCollection_AsciiString.hxx>
207 #include <V3d_Viewer.hxx>
208 #include <V3d_View.hxx>
211 #include <AIS_InteractiveContext.hxx>
212 #include <AIS_Shape.hxx>
213 #include <AIS_TexturedShape.hxx>
214 #include <AIS_DisplayMode.hxx>
215 #include <TColStd_MapOfInteger.hxx>
216 #include <AIS_MapOfInteractive.hxx>
217 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
218 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
219 #include <ViewerTest_EventManager.hxx>
221 #include <TopoDS_Solid.hxx>
222 #include <BRepTools.hxx>
223 #include <BRep_Builder.hxx>
224 #include <TopAbs_ShapeEnum.hxx>
226 #include <TopoDS.hxx>
227 #include <BRep_Tool.hxx>
230 #include <Draw_Window.hxx>
231 #include <AIS_ListIteratorOfListOfInteractive.hxx>
232 #include <AIS_ListOfInteractive.hxx>
233 #include <AIS_DisplayMode.hxx>
234 #include <TopTools_ListOfShape.hxx>
235 #include <BRepOffsetAPI_MakeThickSolid.hxx>
236 #include <BRepOffset.hxx>
239 //==============================================================================
240 //function : GetTypeNameFromShape
241 //purpose : get the shape type as a string from a shape
242 //==============================================================================
244 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
245 { const char *ret = "????";
247 if ( aShape.IsNull() ) ret = "Null Shape";
249 switch ( aShape.ShapeType() ) {
250 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
251 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
252 case TopAbs_SOLID : ret = "SOLID" ; break;
253 case TopAbs_SHELL : ret = "SHELL" ; break;
254 case TopAbs_FACE : ret = "FACE" ; break;
255 case TopAbs_WIRE : ret = "WIRE" ; break;
256 case TopAbs_EDGE : ret = "EDGE" ; break;
257 case TopAbs_VERTEX : ret = "VERTEX" ; break;
258 case TopAbs_SHAPE : ret = "SHAPE" ; break;
262 //==============================================================================
263 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
264 //==============================================================================
265 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
266 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
271 //==============================================================================
272 //function : VDisplayAISObject
273 //purpose : register interactive object in the map of AIS objects;
274 // if other object with such name already registered, it will be kept
275 // or replaced depending on value of <theReplaceIfExists>,
276 // if "true" - the old object will be cleared from AIS context;
277 // returns Standard_True if <theAISObj> registered in map;
278 //==============================================================================
279 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
280 const Handle(AIS_InteractiveObject)& theAISObj,
281 Standard_Boolean theReplaceIfExists = Standard_True)
283 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
284 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
285 if (aContextAIS.IsNull())
287 std::cout << "AIS context is not available.\n";
288 return Standard_False;
291 if (aMap.IsBound2 (theName))
293 if (!theReplaceIfExists)
295 std::cout << "Other interactive object has been already "
296 << "registered with name: " << theName << ".\n"
297 << "Please use another name.\n";
298 return Standard_False;
301 // stop displaying object
302 Handle(AIS_InteractiveObject) anOldObj =
303 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
305 if (!anOldObj.IsNull())
306 aContextAIS->Clear (anOldObj, Standard_True);
308 // remove name and old object from map
309 aMap.UnBind2 (theName);
312 if (theAISObj.IsNull())
314 // object with specified name already unbound
315 return Standard_True;
318 // unbind AIS object if was bound with another name
319 aMap.UnBind1 (theAISObj);
321 // can be registered without rebinding
322 aMap.Bind (theAISObj, theName);
323 aContextAIS->Display (theAISObj, Standard_True);
324 return Standard_True;
327 static TColStd_MapOfInteger theactivatedmodes(8);
328 static TColStd_ListOfTransient theEventMgrs;
330 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
331 const Handle(AIS_InteractiveContext)& Ctx)
333 theEventMgrs.Clear();
334 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
337 static Handle(V3d_View)& a3DView()
339 static Handle(V3d_View) Viou;
344 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
345 static Handle(AIS_InteractiveContext) aContext;
349 const Handle(V3d_View)& ViewerTest::CurrentView()
353 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
358 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
360 static Handle(NIS_InteractiveContext) aContext;
361 if (aContext.IsNull()) {
362 aContext = new NIS_InteractiveContext;
363 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
368 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
370 return TheAISContext();
373 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
375 TheAISContext() = aCtx;
376 ViewerTest::ResetEventManager();
379 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
381 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
384 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
386 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
390 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
391 theEventMgrs.Prepend(EM);
394 void ViewerTest::UnsetEventManager()
396 theEventMgrs.RemoveFirst();
400 void ViewerTest::ResetEventManager()
402 const Handle(NIS_View) aView =
403 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
404 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
407 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
409 Handle(ViewerTest_EventManager) EM;
410 if(theEventMgrs.IsEmpty()) return EM;
411 Handle(Standard_Transient) Tr = theEventMgrs.First();
412 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
417 //=======================================================================
418 //function : Get Context and active viou..
420 //=======================================================================
421 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
422 Handle(V3d_View)& Viou)
424 Ctx = ViewerTest::GetAISContext();
427 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
428 Vwr->InitActiveViews();
429 if(Vwr->MoreActiveViews())
430 Viou = Vwr->ActiveView();
435 //==============================================================================
436 //function : GetShapeFromName
437 //purpose : Compute an Shape from a draw variable or a file name
438 //==============================================================================
440 static TopoDS_Shape GetShapeFromName(const char* name)
442 TopoDS_Shape S = DBRep::Get(name);
445 BRep_Builder aBuilder;
446 BRepTools::Read( S, name, aBuilder);
451 //==============================================================================
452 //function : GetShapeFromName
453 //purpose : Compute an Shape from a draw variable or a file name
454 //==============================================================================
457 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
459 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
463 //==============================================================================
464 //function : GetAISShapeFromName
465 //purpose : Compute an AIS_Shape from a draw variable or a file name
466 //==============================================================================
467 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
469 Handle(AIS_Shape) retsh;
471 if(GetMapOfAIS().IsBound2(name)){
472 const Handle(AIS_InteractiveObject) IO =
473 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
475 if(IO->Type()==AIS_KOI_Shape)
476 if(IO->Signature()==0){
477 retsh = *((Handle(AIS_Shape)*)&IO);
480 cout << "an Object which is not an AIS_Shape "
481 "already has this name!!!"<<endl;
487 TopoDS_Shape S = GetShapeFromName(name);
489 retsh = new AIS_Shape(S);
495 //==============================================================================
497 //purpose : Remove all the object from the viewer
498 //==============================================================================
499 void ViewerTest::Clear()
501 if ( !a3DView().IsNull() ) {
502 if (TheAISContext()->HasOpenedContext())
503 TheAISContext()->CloseLocalContext();
504 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
505 while ( it.More() ) {
506 cout << "Remove " << it.Key2() << endl;
507 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
508 const Handle(AIS_InteractiveObject) anObj =
509 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
510 TheAISContext()->Remove(anObj,Standard_False);
511 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
512 const Handle(NIS_InteractiveObject) anObj =
513 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
514 TheNISContext()->Remove(anObj);
518 TheAISContext()->UpdateCurrentViewer();
519 // TheNISContext()->UpdateViews();
520 GetMapOfAIS().Clear();
524 //==============================================================================
525 //function : StandardModesActivation
526 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
528 //==============================================================================
529 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
531 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
533 if (TheAISContext()->HasOpenedContext())
534 aContext->CloseLocalContext();
537 if(!aContext->HasOpenedContext()) {
538 // To unhilight the preselected object
539 aContext->UnhilightCurrents(Standard_False);
540 // Open a local Context in order to be able to select subshape from
541 // the selected shape if any or for all if there is no selection
542 if (!aContext->FirstCurrentObject().IsNull()){
543 aContext->OpenLocalContext(Standard_False);
545 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
546 aContext->Load( aContext->Current(),-1,Standard_True);
550 aContext->OpenLocalContext();
553 const char *cmode="???";
556 case 0: cmode = "Shape"; break;
557 case 1: cmode = "Vertex"; break;
558 case 2: cmode = "Edge"; break;
559 case 3: cmode = "Wire"; break;
560 case 4: cmode = "Face"; break;
561 case 5: cmode = "Shell"; break;
562 case 6: cmode = "Solid"; break;
563 case 7: cmode = "Compsolid"; break;
564 case 8: cmode = "Compound"; break;
567 if(theactivatedmodes.Contains(mode))
569 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
570 theactivatedmodes.Remove(mode);
571 cout<<"Mode "<< cmode <<" OFF"<<endl;
575 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
576 theactivatedmodes.Add(mode);
577 cout<<"Mode "<< cmode << " ON" << endl;
582 //==============================================================================
583 //function : VDispAreas,VDispSensitive,...
584 //purpose : Redraw the view
586 //==============================================================================
587 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
590 Handle(AIS_InteractiveContext) Ctx;
591 Handle(V3d_View) Viou;
592 GetCtxAndView(Ctx,Viou);
593 Ctx->DisplayActiveAreas(Viou);
596 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
598 Handle(AIS_InteractiveContext) Ctx;
599 Handle(V3d_View) Viou;
600 GetCtxAndView(Ctx,Viou);
601 Ctx->ClearActiveAreas(Viou);
605 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
607 Handle(AIS_InteractiveContext) Ctx;
608 Handle(V3d_View) Viou;
609 GetCtxAndView(Ctx,Viou);
610 Ctx->DisplayActiveSensitive(Viou);
614 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
616 Handle(AIS_InteractiveContext) Ctx;
617 Handle(V3d_View) Viou;
618 GetCtxAndView(Ctx,Viou);
619 Ctx->ClearActiveSensitive(Viou);
623 //==============================================================================
625 //purpose : To list the displayed object with their attributes
627 //==============================================================================
628 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
629 { if ( !a3DView().IsNull() ) {
630 di << "List of object in the viewer :" << "\n";
632 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
634 while ( it.More() ) {
635 di << "\t" << it.Key2().ToCString() << "\n";
643 //==============================================================================
644 //function : VSelPrecision
645 //purpose : To set the selection precision mode and tolerance value
646 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
647 // value (integer number of pixel for window mode, double value of
648 // sensitivity for view mode). Without arguments the function just
649 // prints the current precision mode and the corresponding tolerance.
650 //==============================================================================
651 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
655 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
659 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
660 if( aContext.IsNull() )
665 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
666 if( aMode == StdSelect_SM_WINDOW )
668 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
669 di << "Precision mode : 0 (window)\n";
670 di << "Pixel tolerance : " << aPixelTolerance << "\n";
672 else if( aMode == StdSelect_SM_VIEW )
674 Standard_Real aSensitivity = aContext->Sensitivity();
675 di << "Precision mode : 1 (view)\n";
676 di << "Sensitivity : " << aSensitivity << "\n";
681 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
682 aContext->SetSensitivityMode( aMode );
685 if( aMode == StdSelect_SM_WINDOW )
687 Standard_Integer aPixelTolerance = atoi( argv[2] );
688 aContext->SetPixelTolerance( aPixelTolerance );
690 else if( aMode == StdSelect_SM_VIEW )
692 Standard_Real aSensitivity = atof( argv[2] );
693 aContext->SetSensitivity( aSensitivity );
700 //==============================================================================
702 //purpose : To dump the active view snapshot to image file
703 //Draw arg : Picture file name with extension corresponding to desired format
704 //==============================================================================
705 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
709 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
713 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
716 TCollection_AsciiString aBuffTypeStr (argv[2]);
717 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
719 aBufferType = Graphic3d_BT_RGB;
721 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
723 aBufferType = Graphic3d_BT_RGBA;
725 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
727 aBufferType = Graphic3d_BT_Depth;
731 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
732 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
734 Handle(AIS_InteractiveContext) IC;
735 Handle(V3d_View) view;
736 GetCtxAndView (IC, view);
739 di << "Cannot find an active viewer/view\n";
743 if (aWidth <= 0 || aHeight <= 0)
745 if (!view->Dump (argv[1], aBufferType))
747 di << "Dumping failed!\n";
753 Image_AlienPixMap aPixMap;
754 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
756 di << "Dumping failed!\n";
760 if (aPixMap.SizeX() != Standard_Size(aWidth)
761 || aPixMap.SizeY() != Standard_Size(aHeight))
763 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
764 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
766 if (!aPixMap.Save (argv[1]))
768 di << "Saving image failed!\n";
775 //==============================================================================
776 //function : Displays,Erase...
779 //==============================================================================
780 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
781 const Standard_Integer Mode,
782 const Standard_Integer TypeOfOperation,
783 const Standard_Boolean Upd)
785 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
787 switch(TypeOfOperation){
789 Ctx->Display(IO,Mode,Upd);
792 Ctx->Erase(IO,Mode,Upd);
797 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
799 Ctx->SetDisplayMode(IO,Mode,Upd);
804 Ctx->SetDisplayMode(0,Upd);
806 Ctx->UnsetDisplayMode(IO,Upd);
813 //=======================================================================
816 //=======================================================================
817 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
820 TCollection_AsciiString name;
823 // display others presentations
824 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
825 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
826 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
827 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
829 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
831 //unset displaymode.. comportement particulier...
832 if(TypeOfOperation==4){
834 if(Ctx->NbCurrents()==0 ||
835 Ctx->NbSelected()==0){
836 Handle(AIS_InteractiveObject) IO;
837 VwrTst_DispErase(IO,-1,4,Standard_False);
839 else if(!Ctx->HasOpenedContext()){
840 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
841 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
844 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
845 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
846 Ctx->UpdateCurrentViewer();
849 Handle(AIS_InteractiveObject) IO;
851 if(GetMapOfAIS().IsBound2(name)){
852 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
854 VwrTst_DispErase(IO,-1,4,Standard_True);
859 Standard_Integer Dmode = atoi(argv[1]);
860 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
861 Handle(AIS_InteractiveObject) IO;
862 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
864 if(!Ctx->HasOpenedContext()){
865 // set/unset display mode sur le Contexte...
866 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
867 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
869 Ctx->UpdateCurrentViewer();
872 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
873 Ctx->Display(Ctx->Interactive(),Dmode);
877 Handle(AIS_InteractiveObject) IO;
879 if(GetMapOfAIS().IsBound2(name))
880 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
882 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
888 //=======================================================================
891 //=======================================================================
892 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
894 if(argc==1) return 1;
895 Standard_Integer On = atoi(argv[1]);
896 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
900 if(!Ctx->HasOpenedContext()){
901 di<<"sub intensite ";
904 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
905 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
907 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
909 di <<"passage dans off"<<"\n";
910 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
915 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
917 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
919 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
922 Ctx->UpdateCurrentViewer();
925 Handle(AIS_InteractiveObject) IO;
926 TCollection_AsciiString name = argv[2];
927 if(GetMapOfAIS().IsBound2(name)){
928 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
931 Ctx->SubIntensityOn(IO);
933 Ctx->SubIntensityOff(IO);
941 //==============================================================================
944 //purpose : change the color of a selected or named or displayed shape
945 //Draw arg : vcolor2 [name] color
946 //==============================================================================
947 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
950 Standard_Boolean ThereIsCurrent;
951 Standard_Boolean ThereIsArgument;
952 Standard_Boolean IsBound = Standard_False ;
954 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
956 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
957 ThereIsArgument = (argc != 2);
960 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
961 ThereIsArgument = (argc == 2);
964 if ( !a3DView().IsNull() ) {
965 TCollection_AsciiString name;
966 if (ThereIsArgument) {
968 IsBound= GetMapOfAIS().IsBound2(name);
970 if (TheAISContext()->HasOpenedContext())
971 TheAISContext()->CloseLocalContext();
973 // On set le Booleen There is current
974 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
975 else ThereIsCurrent =Standard_False;
977 //=======================================================================
978 // Il y a un argument
979 //=======================================================================
980 if ( ThereIsArgument && IsBound ) {
981 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
982 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
983 Handle(AIS_InteractiveObject) ashape =
984 Handle(AIS_InteractiveObject)::DownCast (anObj);
987 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
989 di << "HaveToSet 0\n";
993 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
995 TheAISContext()->UnsetColor(ashape);
996 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
997 Handle(NIS_Triangulated) ashape =
998 Handle(NIS_Triangulated)::DownCast (anObj);
999 if (!ashape.IsNull())
1000 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1005 //=======================================================================
1006 // Il n'y a pas d'arguments
1007 // Mais un ou plusieurs objets on des current representation
1008 //=======================================================================
1009 if (ThereIsCurrent && !ThereIsArgument) {
1010 for (TheAISContext() -> InitCurrent() ;
1011 TheAISContext() -> MoreCurrent() ;
1012 TheAISContext() ->NextCurrent() )
1014 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1015 if (ashape.IsNull())
1019 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1021 di << "HaveToSet 0\n";
1024 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1026 TheAISContext()->UnsetColor(ashape,Standard_False);
1029 TheAISContext()->UpdateCurrentViewer();
1032 //=======================================================================
1033 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1034 // on impose a tous les objets du viewer la couleur passee
1035 //=======================================================================
1036 else if (!ThereIsCurrent && !ThereIsArgument){
1037 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1038 while ( it.More() ) {
1039 const Handle(AIS_InteractiveObject) ashape =
1040 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1041 if (!ashape.IsNull())
1043 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1045 TheAISContext()->UnsetColor(ashape,Standard_False);
1048 TheAISContext()->UpdateCurrentViewer();
1054 //==============================================================================
1055 //function : VTransparency
1057 //purpose : change the transparency of a selected or named or displayed shape
1058 //Draw arg : vtransparency [name] TransparencyCoeficient
1059 //==============================================================================
1061 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1064 Standard_Boolean ThereIsCurrent;
1065 Standard_Boolean ThereIsArgument;
1066 Standard_Boolean IsBound = Standard_False ;
1068 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1070 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1071 ThereIsArgument = (argc != 2);
1074 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1075 ThereIsArgument = (argc == 2);
1078 if ( !a3DView().IsNull() ) {
1079 TCollection_AsciiString name;
1080 if (ThereIsArgument) {
1082 IsBound= GetMapOfAIS().IsBound2(name);
1084 if (TheAISContext()->HasOpenedContext())
1085 TheAISContext()->CloseLocalContext();
1087 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1088 else ThereIsCurrent = Standard_False;
1090 //=======================================================================
1091 // Il y a des arguments: un nom et une couleur
1092 //=======================================================================
1093 if ( ThereIsArgument && IsBound ) {
1094 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1095 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1096 const Handle(AIS_InteractiveObject) ashape =
1097 Handle(AIS_InteractiveObject)::DownCast(anObj);
1099 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1101 TheAISContext()->UnsetTransparency(ashape);
1102 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1103 const Handle(NIS_InteractiveObject) ashape =
1104 Handle(NIS_InteractiveObject)::DownCast(anObj);
1106 ashape->SetTransparency(atof(argv[2]) );
1108 ashape->UnsetTransparency();
1111 //=======================================================================
1112 // Il n'y a pas d'arguments
1113 // Mais un ou plusieurs objets on des current representation
1114 //=======================================================================
1115 if (ThereIsCurrent && !ThereIsArgument) {
1116 for (TheAISContext() -> InitCurrent() ;
1117 TheAISContext() -> MoreCurrent() ;
1118 TheAISContext() ->NextCurrent() )
1120 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1122 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1124 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1127 TheAISContext()->UpdateCurrentViewer();
1129 //=======================================================================
1130 // Il n'y a pas d'arguments ET aucun objet courrant
1131 //=======================================================================
1132 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1133 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1135 while ( it.More() ) {
1136 Handle(AIS_InteractiveObject) ashape =
1137 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1138 if (!ashape.IsNull())
1140 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1142 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1145 TheAISContext()->UpdateCurrentViewer();
1152 //==============================================================================
1153 //function : VMaterial
1155 //purpose : change the Material of a selected or named or displayed shape
1156 //Draw arg : vmaterial [Name] Material
1157 //==============================================================================
1158 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1161 Standard_Boolean ThereIsCurrent;
1162 Standard_Boolean ThereIsName;
1163 Standard_Boolean IsBound = Standard_False ;
1165 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1167 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1168 ThereIsName = (argc != 2);
1171 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1172 ThereIsName = (argc == 2);
1175 if ( !a3DView().IsNull() ) {
1176 TCollection_AsciiString name;
1179 IsBound= GetMapOfAIS().IsBound2(name);
1181 if (TheAISContext()->HasOpenedContext())
1182 TheAISContext()->CloseLocalContext();
1183 if (TheAISContext() -> NbCurrents() > 0 )
1184 ThereIsCurrent =Standard_True;
1186 ThereIsCurrent =Standard_False;
1188 //=======================================================================
1189 // Ther is a name of shape and a material name
1190 //=======================================================================
1191 if ( ThereIsName && IsBound ) {
1192 Handle(AIS_InteractiveObject) ashape =
1193 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1194 if (!ashape.IsNull())
1196 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1198 TheAISContext()->UnsetMaterial(ashape);
1200 //=======================================================================
1201 // Il n'y a pas de nom de shape
1202 // Mais un ou plusieurs objets on des current representation
1203 //=======================================================================
1204 if (ThereIsCurrent && !ThereIsName) {
1205 for (TheAISContext() -> InitCurrent() ;
1206 TheAISContext() -> MoreCurrent() ;
1207 TheAISContext() ->NextCurrent() )
1209 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1211 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1213 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1215 TheAISContext()->UpdateCurrentViewer();
1218 //=======================================================================
1219 // Il n'y a pas de noms de shape ET aucun objet courrant
1220 // On impose a tous les objets du viewer le material passe en argument
1221 //=======================================================================
1222 else if (!ThereIsCurrent && !ThereIsName){
1223 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1225 while ( it.More() ) {
1226 Handle(AIS_InteractiveObject) ashape =
1227 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1228 if (!ashape.IsNull())
1230 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1232 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1235 TheAISContext()->UpdateCurrentViewer();
1243 //==============================================================================
1246 //purpose : change the width of the edges of a selected or named or displayed shape
1247 //Draw arg : vwidth [Name] WidthValue(1->10)
1248 //==============================================================================
1249 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1252 Standard_Boolean ThereIsCurrent;
1253 Standard_Boolean ThereIsArgument;
1254 Standard_Boolean IsBound = Standard_False ;
1256 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1258 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1259 ThereIsArgument = (argc != 2);
1262 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1263 ThereIsArgument = (argc == 2);
1265 if ( !a3DView().IsNull() ) {
1266 TCollection_AsciiString name;
1267 if (ThereIsArgument) {
1269 IsBound= GetMapOfAIS().IsBound2(name);
1271 if (TheAISContext()->HasOpenedContext())
1272 TheAISContext()->CloseLocalContext();
1274 if (TheAISContext() -> NbCurrents() > 0 )
1275 ThereIsCurrent =Standard_True;
1277 ThereIsCurrent =Standard_False;
1279 if ( ThereIsArgument && IsBound ) {
1280 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1281 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1282 const Handle(AIS_InteractiveObject) ashape =
1283 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1285 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1287 TheAISContext()->UnsetWidth (ashape);
1288 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1289 const Handle(NIS_Triangulated) ashape =
1290 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1291 if (HaveToSet && !ashape.IsNull())
1292 ashape->SetLineWidth ( atof (argv[2]) );
1296 //=======================================================================
1297 // Il n'y a pas d'arguments
1298 // Mais un ou plusieurs objets on des current representation
1299 //=======================================================================
1300 if (ThereIsCurrent && !ThereIsArgument) {
1301 for (TheAISContext() -> InitCurrent() ;
1302 TheAISContext() -> MoreCurrent() ;
1303 TheAISContext() ->NextCurrent() )
1305 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1307 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1309 TheAISContext()->UnsetWidth(ashape,Standard_False);
1311 TheAISContext()->UpdateCurrentViewer();
1313 //=======================================================================
1314 // Il n'y a pas d'arguments ET aucun objet courrant
1315 //=======================================================================
1316 else if (!ThereIsCurrent && !ThereIsArgument){
1317 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1319 while ( it.More() ) {
1320 Handle(AIS_InteractiveObject) ashape =
1321 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1322 if (!ashape.IsNull())
1324 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1326 TheAISContext()->UnsetWidth(ashape,Standard_False);
1329 TheAISContext()->UpdateCurrentViewer();
1335 //==============================================================================
1336 //function : VInteriorStyle
1337 //purpose : sets interior style of the a selected or named or displayed shape
1338 //Draw arg : vsetinteriorstyle [shape] style
1339 //==============================================================================
1340 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1341 const Standard_Integer theStyle,
1342 Draw_Interpretor& di)
1344 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1345 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1346 " (Aspect_IS_HIDDENLINE)]\n";
1349 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1350 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1351 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1352 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1353 aFillAspect->SetInteriorStyle (aStyle);
1354 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1357 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1359 if (argc < 2 || argc > 3) {
1360 di << argv[0] << " requires 2 or 3 arguments\n";
1361 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1362 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1363 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1367 Standard_Boolean ThereIsCurrent;
1368 Standard_Boolean ThereIsArgument;
1369 Standard_Boolean IsBound = Standard_False ;
1371 ThereIsArgument = (argc > 2);
1372 if ( !a3DView().IsNull() ) {
1373 TCollection_AsciiString name;
1374 if (ThereIsArgument) {
1376 IsBound= GetMapOfAIS().IsBound2(name);
1378 if (TheAISContext()->HasOpenedContext())
1379 TheAISContext()->CloseLocalContext();
1381 if (TheAISContext() -> NbCurrents() > 0 )
1382 ThereIsCurrent =Standard_True;
1384 ThereIsCurrent =Standard_False;
1386 if ( ThereIsArgument && IsBound ) {
1387 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1388 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1389 const Handle(AIS_InteractiveObject) ashape =
1390 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1391 SetInteriorStyle (ashape, atoi (argv[2]), di);
1394 //=======================================================================
1395 // No arguments specified
1396 // But there are one or more selected objects
1397 //=======================================================================
1398 if (ThereIsCurrent && !ThereIsArgument) {
1399 for (TheAISContext() -> InitCurrent() ;
1400 TheAISContext() -> MoreCurrent() ;
1401 TheAISContext() ->NextCurrent() )
1403 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1404 SetInteriorStyle (ashape, atoi (argv[1]), di);
1407 //=======================================================================
1408 // No arguments specified and there are no selected objects
1409 //=======================================================================
1410 else if (!ThereIsCurrent && !ThereIsArgument){
1411 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1413 while ( it.More() ) {
1414 Handle(AIS_InteractiveObject) ashape =
1415 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1416 if (!ashape.IsNull())
1417 SetInteriorStyle (ashape, atoi (argv[1]), di);
1421 TheAISContext()->UpdateCurrentViewer();
1426 //==============================================================================
1427 //function : VDonly2
1429 //purpose : Display only a selected or named object
1430 // if there is no selected or named object s, nothing is donne
1431 //Draw arg : vdonly2 [name1] ... [name n]
1432 //==============================================================================
1433 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1436 if ( a3DView().IsNull() )
1439 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1440 Standard_Boolean ThereIsArgument= argc>1;
1442 if (TheAISContext()->HasOpenedContext())
1443 TheAISContext()->CloseLocalContext();
1445 //===============================================================
1446 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1448 //===============================================================
1449 if (!ThereIsArgument && ThereIsCurrent) {
1452 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1455 for(TheAISContext()->InitCurrent();
1456 TheAISContext()->MoreCurrent();
1457 TheAISContext()->NextCurrent()){
1458 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1459 TheAISContext()->Erase(aShape,Standard_False);}
1461 TheAISContext() ->UpdateCurrentViewer();
1462 //===============================================================
1463 // Il y a des arguments
1464 //===============================================================
1465 if (ThereIsArgument) {
1466 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1468 while ( it.More() ) {
1469 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1470 const Handle(AIS_InteractiveObject) aShape =
1471 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1472 TheAISContext()->Erase(aShape,Standard_False);
1473 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1474 const Handle(NIS_InteractiveObject) aShape =
1475 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1476 TheNISContext()->Erase(aShape);
1481 // On display les objets passes par parametre
1482 for (int i=1; i<argc ; i++) {
1483 TCollection_AsciiString name=argv[i];
1484 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1486 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1487 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1488 const Handle(AIS_InteractiveObject) aShape =
1489 Handle(AIS_InteractiveObject)::DownCast (anObj);
1490 TheAISContext()->Display(aShape, Standard_False);
1491 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1492 Handle(NIS_InteractiveObject) aShape =
1493 Handle(NIS_InteractiveObject)::DownCast (anObj);
1494 TheNISContext()->Display(aShape);
1498 TheAISContext() ->UpdateCurrentViewer();
1499 // TheNISContext() ->UpdateViews();
1504 //==============================================================================
1505 //function : VErase2
1507 //purpose : Erase some selected or named objects
1508 // if there is no selected or named objects, the whole viewer is erased
1509 //Draw arg : verase2 [name1] ... [name n]
1510 //==============================================================================
1511 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1514 if ( a3DView().IsNull() )
1517 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1518 Standard_Boolean ThereIsArgument= argc>1;
1519 if(TheAISContext()->HasOpenedContext())
1520 TheAISContext()->CloseLocalContext();
1522 //===============================================================
1523 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1525 //===============================================================
1526 if (!ThereIsArgument && ThereIsCurrent) {
1527 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1529 while ( it.More() ) {
1530 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1531 const Handle(AIS_InteractiveObject) aShape =
1532 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1533 if (TheAISContext()->IsCurrent(aShape))
1534 TheAISContext()->Erase(aShape,Standard_False);
1539 TheAISContext() ->UpdateCurrentViewer();
1542 //===============================================================
1543 // Il n'y a pas d'arguments et aucuns objets selectionnes
1545 // On erase tout le viewer
1546 //===============================================================
1548 if (!ThereIsArgument && !ThereIsCurrent) {
1549 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1550 while ( it.More() ) {
1551 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1552 const Handle(AIS_InteractiveObject) aShape =
1553 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1554 TheAISContext()->Erase(aShape,Standard_False);
1555 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1556 const Handle(NIS_InteractiveObject) aShape =
1557 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1558 TheNISContext()->Erase(aShape);
1562 TheAISContext() ->UpdateCurrentViewer();
1563 // TheNISContext()->UpdateViews();
1566 //===============================================================
1567 // Il y a des arguments
1568 //===============================================================
1569 if (ThereIsArgument) {
1570 for (int i=1; i<argc ; i++) {
1571 TCollection_AsciiString name=argv[i];
1572 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1574 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1575 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1576 const Handle(AIS_InteractiveObject) aShape =
1577 Handle(AIS_InteractiveObject)::DownCast (anObj);
1578 TheAISContext()->Erase(aShape,Standard_False);
1579 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1580 const Handle(NIS_InteractiveObject) aShape =
1581 Handle(NIS_InteractiveObject)::DownCast (anObj);
1582 TheNISContext()->Erase(aShape);
1586 TheAISContext() ->UpdateCurrentViewer();
1587 // TheNISContext() ->UpdateViews();
1592 //==============================================================================
1593 //function : VEraseAll
1595 //purpose : Erase all the objects displayed in the viewer
1596 //Draw arg : veraseall
1597 //==============================================================================
1598 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1601 // Verification des arguments
1602 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1603 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1604 TheAISContext()->CloseAllContexts(Standard_False);
1605 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1607 while ( it.More() ) {
1608 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1609 const Handle(AIS_InteractiveObject) aShape =
1610 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1611 TheAISContext()->Erase(aShape,Standard_False);
1612 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1613 const Handle(NIS_InteractiveObject) aShape =
1614 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1615 TheNISContext()->Erase(aShape);
1619 TheAISContext() ->UpdateCurrentViewer();
1620 // TheNISContext() ->UpdateViews();
1625 //==============================================================================
1626 //function : VDisplayAll
1628 //purpose : Display all the objects of the Map
1629 //Draw arg : vdisplayall
1630 //==============================================================================
1631 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1634 if (! a3DView().IsNull() ) {
1635 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1636 if (TheAISContext()->HasOpenedContext())
1637 TheAISContext()->CloseLocalContext();
1638 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1640 while ( it.More() ) {
1641 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1642 const Handle(AIS_InteractiveObject) aShape =
1643 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1644 TheAISContext()->Erase(aShape,Standard_False);
1645 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1646 const Handle(NIS_InteractiveObject) aShape =
1647 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1648 TheNISContext()->Erase(aShape);
1653 while ( it.More() ) {
1654 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1655 const Handle(AIS_InteractiveObject) aShape =
1656 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1657 TheAISContext()->Display(aShape, Standard_False);
1658 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1659 Handle(NIS_InteractiveObject) aShape =
1660 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1661 TheNISContext()->Display(aShape);
1665 TheAISContext() ->UpdateCurrentViewer();
1666 // TheNISContext() ->UpdateViews();
1671 //#######################################################################################################
1675 //#######################################################################################################
1677 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1679 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1680 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1681 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1682 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1683 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1685 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1686 if(myAISContext.IsNull())
1688 di << "use 'vinit' command before " << argv[0] << "\n";
1692 Handle(AIS_InteractiveObject) TheAisIO;
1693 Handle(AIS_TexturedShape) myShape;
1694 Standard_Integer myPreviousMode = 0;
1696 if (argc<2 || !argv[1])
1698 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1702 TCollection_AsciiString name = argv[1];
1703 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1705 if (GetMapOfAIS().IsBound2(name))
1706 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1707 (GetMapOfAIS().Find2(name));
1708 if (TheAisIO.IsNull())
1710 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1714 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1716 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1717 myPreviousMode = myShape->DisplayMode() ;
1721 myAISContext->Clear(TheAisIO,Standard_False);
1722 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1723 GetMapOfAIS().UnBind1(TheAisIO);
1724 GetMapOfAIS().UnBind2(name);
1725 GetMapOfAIS().Bind(myShape, name);
1729 case 1: // vtexture : we only map a texture on the shape
1732 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1735 if (argc>2 && argv[2])
1737 if(strcasecmp(argv[2],"?")==0)
1739 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1740 di<<"\n Files in current directory : \n"<<"\n";
1741 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1742 di.Eval(Cmnd.ToCString());
1744 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1747 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1748 di.Eval(Cmnd.ToCString());
1753 myShape->SetTextureFileName(argv[2]);
1757 di <<"Texture mapping disabled \n \
1758 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1760 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1761 if (myPreviousMode == 3 )
1762 myAISContext->RecomputePrsOnly(myShape);
1763 myAISContext->Display(myShape, Standard_True);
1768 case 2: // vtexscale : we change the scaling factor of the texture
1772 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1776 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1777 ( argv[2] ? atof(argv[2]) : 1.0 ),
1778 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1781 case 3: // vtexorigin : we change the origin of the texture on the shape
1784 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1787 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1788 ( argv[2] ? atof(argv[2]) : 0.0 ),
1789 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1792 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1795 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1798 if (argc>2 && argv[2])
1800 di <<"Texture repeat enabled"<<"\n";
1801 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1805 di <<"Texture repeat disabled"<<"\n";
1806 myShape->SetTextureRepeat(Standard_False);
1810 case 5: // vtexdefault : default texture mapping
1811 // ScaleU = ScaleV = 100.0
1812 // URepeat = VRepeat = 1.0
1813 // Uorigin = VOrigin = 0.0
1817 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1820 myShape->SetTextureRepeat(Standard_False);
1821 myShape->SetTextureOrigin(Standard_False);
1822 myShape->SetTextureScale (Standard_False);
1826 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1827 myAISContext->RecomputePrsOnly(myShape);
1830 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1831 myAISContext->Display(myShape, Standard_True);
1832 myAISContext->Update(myShape,Standard_True);
1837 //==============================================================================
1838 //function : VDisplay2
1840 //purpose : Display an object from its name
1841 //Draw arg : vdisplay name1 [name2] ... [name n]
1842 //==============================================================================
1843 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1846 // Verification des arguments
1847 if ( a3DView().IsNull() ) {
1849 ViewerTest::ViewerInit();
1850 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1855 di<<argv[0]<<" Syntaxe error"<<"\n";
1860 TCollection_AsciiString name;
1861 if (TheAISContext()->HasOpenedContext())
1862 TheAISContext()->CloseLocalContext();
1864 for ( int i = 1; i < argc; i++ ) {
1866 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1867 Standard_Boolean IsDatum = Standard_False;
1868 Handle(Standard_Transient) anObj;
1870 anObj = GetMapOfAIS().Find2(name);
1871 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1872 Handle(AIS_InteractiveObject) aShape =
1873 Handle(AIS_InteractiveObject)::DownCast(anObj);
1874 if (aShape->Type()==AIS_KOI_Datum) {
1875 IsDatum = Standard_True;
1876 TheAISContext()->Display(aShape, Standard_False);
1879 di << "Display " << name.ToCString() << "\n";
1880 // Get the Shape from a name
1881 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1883 // Update the Shape in the AIS_Shape
1884 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1885 if(!TheRealSh.IsNull())
1886 TheRealSh->Set(NewShape);
1887 TheAISContext()->Redisplay(aShape, Standard_False);
1888 TheAISContext()->Display(aShape, Standard_False);
1891 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1892 Handle(NIS_InteractiveObject) aShape =
1893 Handle(NIS_InteractiveObject)::DownCast(anObj);
1894 TheNISContext()->Display(aShape);
1897 else { // Create the AIS_Shape from a name
1898 const Handle(AIS_InteractiveObject) aShape =
1899 GetAISShapeFromName((const char *)name.ToCString());
1900 if ( !aShape.IsNull() ) {
1901 GetMapOfAIS().Bind(aShape, name);
1902 TheAISContext()->Display(aShape, Standard_False);
1906 // Upadate the screen and redraw the view
1907 TheAISContext()->UpdateCurrentViewer();
1908 // TheNISContext()->UpdateViews();
1912 //==============================================================================
1914 //purpose : Test the annimation of an object along a
1915 // predifined trajectory
1916 //Draw arg : vmove ShapeName
1917 //==============================================================================
1920 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1925 if (TheAISContext()->HasOpenedContext())
1926 TheAISContext()->CloseLocalContext();
1928 Standard_Real Step=2*M_PI/180;
1929 Standard_Real Angle=0;
1930 // R est le rayon de l'hellicoide
1932 // D est la distance parcourue en translation en 1 tour
1935 Handle(AIS_InteractiveObject) aIO;
1937 if (GetMapOfAIS().IsBound2(argv[1]))
1938 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1941 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1944 TheAISContext()->Deactivate(aIO);
1946 // boucle generant le mouvement
1948 di<<" Transformations"<<"\n";
1949 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1952 gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
1954 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1955 TheAISContext()->SetLocation(aIO,myTransfo);
1957 TheAISContext() ->UpdateCurrentViewer();
1962 di<<" Locations"<<"\n";
1963 gp_Trsf myAngleTrsf;
1964 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1965 TopLoc_Location myDeltaAngle (myAngleTrsf);
1967 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1968 TopLoc_Location myDeltaDist (myDistTrsf);
1969 TopLoc_Location myTrueLoc;
1971 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1974 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1975 TheAISContext()->SetLocation(aIO,myTrueLoc );
1976 TheAISContext() ->UpdateCurrentViewer();
1981 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1983 //TopLoc_Location Tempo=aIO->Location();
1984 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1985 //ShapeBis.Located(Tempo);
1988 // On reset la location (origine) contenue dans l'AISInteractiveObject
1989 TheAISContext() ->ResetLocation(aIO);
1991 // On force aShape a devenir l'AIS IO propre a ShapeBis
1993 // Pour cela on force aShape(AIS IO) a devenir une AISShape
1994 // ->Set() est une methode de AIS_Shape
1995 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
1997 // On donne a ShapeBis le nom de l'AIS IO
1998 //Rep::Set(argv[1],ShapeBis);
2001 TheAISContext()->Redisplay(aIO,Standard_False);
2003 // On reactive la selection des primitives sensibles
2004 TheAISContext()->Activate(aIO,0);
2006 TheAISContext() ->UpdateCurrentViewer();
2007 a3DView() -> Redraw();
2010 di<<" Temps ecoule "<<"\n";
2018 //==============================================================================
2020 //purpose : Test the annimation of an object along a
2021 // predifined trajectory
2022 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2023 //==============================================================================
2025 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2028 if (TheAISContext()->HasOpenedContext())
2029 TheAISContext()->CloseLocalContext();
2031 Standard_Real Step=4*M_PI/180;
2032 Standard_Real Angle=0;
2034 Handle(AIS_InteractiveObject) aIO;
2035 if (GetMapOfAIS().IsBound2(argv[1]))
2036 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2040 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2044 if (atoi(argv[3])==1 ) {
2045 di<<" Primitives sensibles OFF"<<"\n";
2046 TheAISContext()->Deactivate(aIO);
2049 di<<" Primitives sensibles ON"<<"\n";
2051 // Movement par transformation
2052 if(atoi(argv[2]) ==1) {
2053 di<<" Calcul par Transformation"<<"\n";
2054 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2058 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2059 TheAISContext()->SetLocation(aShape,myTransfo);
2060 TheAISContext() ->UpdateCurrentViewer();
2065 di<<" Calcul par Locations"<<"\n";
2066 gp_Trsf myAngleTrsf;
2067 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2068 TopLoc_Location myDeltaAngle (myAngleTrsf);
2069 TopLoc_Location myTrueLoc;
2071 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2074 myTrueLoc=myTrueLoc*myDeltaAngle;
2075 TheAISContext()->SetLocation(aShape,myTrueLoc );
2076 TheAISContext() ->UpdateCurrentViewer();
2079 if (atoi(argv[3])==1 ){
2080 // On reactive la selection des primitives sensibles
2081 TheAISContext()->Activate(aIO,0);
2083 a3DView() -> Redraw();
2085 di<<" Temps ecoule "<<"\n";
2091 //==================================================================================
2092 // Function : VAnimation
2093 //==================================================================================
2094 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2096 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2100 Standard_Real thread = 4;
2101 Standard_Real angleA=0;
2102 Standard_Real angleB;
2104 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2107 TopoDS_Shape CrankArm;
2108 TopoDS_Shape CylinderHead;
2109 TopoDS_Shape Propeller;
2110 TopoDS_Shape EngineBlock;
2112 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2113 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2114 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2115 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2116 BRepTools::Read(CrankArm,argv[1],B);
2117 BRepTools::Read(CylinderHead,argv[2],B);
2118 BRepTools::Read(Propeller,argv[3],B);
2119 BRepTools::Read(EngineBlock,argv[4],B);
2121 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2127 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2128 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2129 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2130 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2132 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2133 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2134 GetMapOfAIS().Bind(myAisCrankArm,"c");
2135 GetMapOfAIS().Bind(myAisPropeller,"d");
2137 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2138 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2139 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2141 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2142 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2143 TheAISContext()->Display(myAisCrankArm,Standard_False );
2144 TheAISContext()->Display(myAisPropeller,Standard_False);
2146 TheAISContext()->Deactivate(myAisCylinderHead);
2147 TheAISContext()->Deactivate(myAisEngineBlock );
2148 TheAISContext()->Deactivate(myAisCrankArm );
2149 TheAISContext()->Deactivate(myAisPropeller );
2151 // Boucle de mouvement
2152 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2154 angleA = thread*myAngle*M_PI/180;
2155 X = Sin(angleA)*3/8;
2156 angleB = atan(X / Sqrt(-X * X + 1));
2157 Standard_Real decal(25*0.6);
2160 //Build a transformation on the display
2161 gp_Trsf aPropellerTrsf;
2162 aPropellerTrsf.SetRotation(Ax1,angleA);
2163 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2165 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));
2166 gp_Trsf aCrankArmTrsf;
2167 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2168 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2170 TheAISContext()->UpdateCurrentViewer();
2173 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2174 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2176 myAisCrankArm ->ResetLocation();
2177 myAisPropeller->ResetLocation();
2179 myAisCrankArm -> Set(myNewCrankArm );
2180 myAisPropeller -> Set(myNewPropeller);
2182 TheAISContext()->Activate(myAisCylinderHead,0);
2183 TheAISContext()->Activate(myAisEngineBlock,0 );
2184 TheAISContext()->Activate(myAisCrankArm ,0 );
2185 TheAISContext()->Activate(myAisPropeller ,0 );
2191 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2192 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2194 TheAISContext()->UpdateCurrentViewer();
2195 a3DView()->Redraw();
2204 //==============================================================================
2205 //function : VShading
2206 //purpose : Sharpen or roughten the quality of the shading
2207 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2208 //==============================================================================
2209 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2211 Standard_Real myDevCoef;
2212 Handle(AIS_InteractiveObject) TheAisIO;
2215 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2217 if (TheAISContext()->HasOpenedContext())
2218 TheAISContext()->CloseLocalContext();
2223 myDevCoef =atof(argv[2]);
2226 TCollection_AsciiString name=argv[1];
2227 if (GetMapOfAIS().IsBound2(name ))
2228 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2229 if (TheAisIO.IsNull())
2230 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2233 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2235 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2237 TheAISContext()->Redisplay(TheAisIO);
2240 //==============================================================================
2241 //function : HaveMode
2242 //use : VActivatedModes
2243 //==============================================================================
2244 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2246 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2248 TColStd_ListOfInteger List;
2249 TheAISContext()->ActivatedModes (TheAisIO,List);
2250 TColStd_ListIteratorOfListOfInteger it;
2251 Standard_Boolean Found=Standard_False;
2252 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2253 if (it.Value()==mode ) Found=Standard_True;
2260 //==============================================================================
2261 //function : VActivatedMode
2263 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2264 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2265 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2266 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2267 // qu'un nom et qu'un mode.
2268 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2269 //==============================================================================
2270 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2272 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2275 Standard_Boolean ThereIsName = Standard_False ;
2277 if(!a3DView().IsNull()){
2279 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2280 // verification des arguments
2282 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2283 ThereIsName = (argc == 3);
2287 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2289 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2290 di<<" Fermeture du Context local"<<"\n";
2291 if (TheAISContext()->HasOpenedContext())
2292 TheAISContext()->CloseLocalContext();
2296 // IL n'y a aps de nom de shape passe en argument
2297 if (HaveToSet && !ThereIsName){
2298 Standard_Integer aMode=atoi(argv [1]);
2300 const char *cmode="???";
2302 case 0: cmode = "Shape"; break;
2303 case 1: cmode = "Vertex"; break;
2304 case 2: cmode = "Edge"; break;
2305 case 3: cmode = "Wire"; break;
2306 case 4: cmode = "Face"; break;
2307 case 5: cmode = "Shell"; break;
2308 case 6: cmode = "Solid"; break;
2309 case 7: cmode = "Compound"; break;
2312 if( !TheAISContext()->HasOpenedContext() ) {
2313 // il n'y a pas de Context local d'ouvert
2314 // on en ouvre un et on charge toutes les shapes displayees
2315 // on load tous les objets displayees et on Activate les objets de la liste
2316 AIS_ListOfInteractive ListOfIO;
2317 // on sauve dans une AISListOfInteractive tous les objets currents
2318 if (TheAISContext()->NbCurrents()>0 ){
2319 TheAISContext()->UnhilightCurrents(Standard_False);
2321 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2322 ListOfIO.Append(TheAISContext()->Current() );
2326 TheAISContext()->OpenLocalContext(Standard_False);
2327 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2330 Handle(AIS_InteractiveObject) aIO =
2331 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2333 TheAISContext()->Load(aIO,0,Standard_False);
2336 // traitement des objets qui etaient currents dans le Contexte global
2337 if (!ListOfIO.IsEmpty() ) {
2338 // il y avait des objets currents
2339 AIS_ListIteratorOfListOfInteractive iter;
2340 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2341 Handle(AIS_InteractiveObject) aIO=iter.Value();
2342 TheAISContext()->Activate(aIO,aMode);
2343 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2347 // On applique le mode a tous les objets displayes
2348 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2349 it2 (GetMapOfAIS());
2351 Handle(AIS_InteractiveObject) aIO =
2352 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2353 if (!aIO.IsNull()) {
2354 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2355 TheAISContext()->Activate(aIO,aMode);
2364 // un Context local est deja ouvert
2365 // Traitement des objets du Context local
2366 if (TheAISContext()->NbSelected()>0 ){
2367 TheAISContext()->UnhilightSelected(Standard_False);
2368 // il y a des objets selected,on les parcourt
2369 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2370 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2373 if (HaveMode(aIO,aMode) ) {
2374 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2375 TheAISContext()->Deactivate(aIO,aMode);
2378 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2379 TheAISContext()->Activate(aIO,aMode);
2385 // il n'y a pas d'objets selected
2386 // tous les objets diplayes sont traites
2387 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2390 Handle(AIS_InteractiveObject) aIO =
2391 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2392 if (!aIO.IsNull()) {
2393 if (HaveMode(aIO,aMode) ) {
2394 di<<" Mode: "<<cmode<<" OFF pour "
2395 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2396 TheAISContext()->Deactivate(aIO,aMode);
2399 di<<" Mode: "<<cmode<<" ON pour"
2400 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2401 TheAISContext()->Activate(aIO,aMode);
2409 else if (HaveToSet && ThereIsName){
2410 Standard_Integer aMode=atoi(argv [2]);
2411 Handle(AIS_InteractiveObject) aIO =
2412 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2414 if (!aIO.IsNull()) {
2415 const char *cmode="???";
2418 case 0: cmode = "Shape"; break;
2419 case 1: cmode = "Vertex"; break;
2420 case 2: cmode = "Edge"; break;
2421 case 3: cmode = "Wire"; break;
2422 case 4: cmode = "Face"; break;
2423 case 5: cmode = "Shell"; break;
2424 case 6: cmode = "Solid"; break;
2425 case 7: cmode = "Compound"; break;
2428 if( !TheAISContext()->HasOpenedContext() ) {
2429 TheAISContext()->OpenLocalContext(Standard_False);
2430 // On charge tous les objets de la map
2431 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2433 Handle(AIS_InteractiveObject) aShape=
2434 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2435 if (!aShape.IsNull())
2436 TheAISContext()->Load(aShape,0,Standard_False);
2439 TheAISContext()->Activate(aIO,aMode);
2440 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2444 // un Context local est deja ouvert
2445 if (HaveMode(aIO,aMode) ) {
2446 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2447 TheAISContext()->Deactivate(aIO,aMode);
2450 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2451 TheAISContext()->Activate(aIO,aMode);
2463 //==============================================================================
2464 // function : WhoAmI
2466 //==============================================================================
2467 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2470 if (theShape->Type()==AIS_KOI_Datum) {
2471 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2472 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2473 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2474 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2475 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2476 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2477 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2480 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2481 // AIS_Dimentions et AIS_Relations
2482 else if (theShape->Type()==AIS_KOI_Relation) {
2483 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2485 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2486 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2487 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2488 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2489 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2490 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2491 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2492 // AIS no repertorie.
2493 else {di<<" Type Unknown.";}
2499 //==============================================================================
2502 //Draw arg : vstate [nameA] ... [nameN]
2503 //==============================================================================
2504 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2506 TheAISContext()->CloseAllContexts();
2507 const Standard_Boolean ThereIsArguments=(argc>=2);
2508 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2510 // ==================
2511 // Il y a un argument
2512 // ==================
2513 if (ThereIsArguments) {
2514 for (int cpt=1;cpt<argc;cpt++) {
2515 // Verification que lq piece est bien bindee.
2516 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2517 const Handle(AIS_InteractiveObject) theShape=
2518 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2520 if (!theShape.IsNull()) {
2521 di<<argv[cpt];WhoAmI(theShape, di);
2522 if (TheAISContext()->IsDisplayed(theShape) ) {
2523 di<<" Displayed"<<"\n";
2526 di<<" Not Displayed"<<"\n";
2531 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2535 else if (ThereIsCurrent ) {
2536 for (TheAISContext() -> InitCurrent() ;
2537 TheAISContext() -> MoreCurrent() ;
2538 TheAISContext() ->NextCurrent() )
2540 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2541 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2542 if (TheAISContext()->IsDisplayed(theShape) ) {
2543 di<<" Displayed"<<"\n";
2546 di<<" Not Displayed"<<"\n";
2552 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2554 while ( it.More() ) {
2555 Handle(AIS_InteractiveObject) theShape =
2556 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2557 if (!theShape.IsNull()) {
2558 di<<it.Key2().ToCString();
2559 WhoAmI(theShape, di);
2560 if (TheAISContext()->IsDisplayed(theShape) ) {
2561 di<<" Displayed"<<"\n";
2564 di<<" Not Displayed"<<"\n";
2575 //=======================================================================
2576 //function : PickObjects
2578 //=======================================================================
2579 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2580 const AIS_KindOfInteractive TheType,
2581 const Standard_Integer TheSignature,
2582 const Standard_Integer MaxPick)
2584 Handle(AIS_InteractiveObject) IO;
2585 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2587 // step 1: prepare the data
2589 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2590 TheAISContext()->AddFilter(F1);
2593 // step 2 : wait for the selection...
2594 // Standard_Boolean IsGood (Standard_False);
2595 // Standard_Integer NbPick(0);
2596 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2597 Standard_Integer NbPickFail(0);
2598 Standard_Integer argccc = 5;
2599 const char *bufff[] = { "A", "B", "C","D", "E" };
2600 const char **argvvv = (const char **) bufff;
2603 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2604 while(ViewerMainLoop(argccc,argvvv)){}
2605 Standard_Integer NbStored = TheAISContext()->NbSelected();
2606 if((unsigned int ) NbStored != NbPickGood)
2607 NbPickGood= NbStored;
2610 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2613 // step3 get result.
2615 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2617 Standard_Integer i(0);
2618 for(TheAISContext()->InitSelected();
2619 TheAISContext()->MoreSelected();
2620 TheAISContext()->NextSelected()){
2622 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2623 arr->SetValue(i,IO2);
2628 TheAISContext()->CloseLocalContext(curindex);
2630 return Standard_True;
2634 //=======================================================================
2635 //function : PickObject
2637 //=======================================================================
2638 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2639 const Standard_Integer TheSignature,
2640 const Standard_Integer MaxPick)
2642 Handle(AIS_InteractiveObject) IO;
2643 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2645 // step 1: prepare the data
2648 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2649 TheAISContext()->AddFilter(F1);
2652 // step 2 : wait for the selection...
2653 Standard_Boolean IsGood (Standard_False);
2654 Standard_Integer NbPick(0);
2655 Standard_Integer argccc = 5;
2656 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2657 const char **argvvv = (const char **) bufff;
2660 while(!IsGood && NbPick<= MaxPick){
2661 while(ViewerMainLoop(argccc,argvvv)){}
2662 IsGood = (TheAISContext()->NbSelected()>0) ;
2664 cout<<"Nb Pick :"<<NbPick<<endl;
2668 // step3 get result.
2670 TheAISContext()->InitSelected();
2671 IO = TheAISContext()->SelectedInteractive();
2675 TheAISContext()->CloseLocalContext(curindex);
2679 //=======================================================================
2680 //function : PickShape
2681 //purpose : First Activate the rightmode + Put Filters to be able to
2682 // pick objets that are of type <TheType>...
2683 //=======================================================================
2685 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2686 const Standard_Integer MaxPick)
2689 // step 1: prepare the data
2691 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2692 TopoDS_Shape result;
2694 if(TheType==TopAbs_SHAPE){
2695 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2696 TheAISContext()->AddFilter(F1);
2699 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2700 TheAISContext()->AddFilter(TF);
2701 TheAISContext()->ActivateStandardMode(TheType);
2706 // step 2 : wait for the selection...
2707 Standard_Boolean NoShape (Standard_True);
2708 Standard_Integer NbPick(0);
2709 Standard_Integer argccc = 5;
2710 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2711 const char **argvvv = (const char **) bufff;
2714 while(NoShape && NbPick<= MaxPick){
2715 while(ViewerMainLoop(argccc,argvvv)){}
2716 NoShape = (TheAISContext()->NbSelected()==0) ;
2718 cout<<"Nb Pick :"<<NbPick<<endl;
2721 // step3 get result.
2725 TheAISContext()->InitSelected();
2726 if(TheAISContext()->HasSelectedShape())
2727 result = TheAISContext()->SelectedShape();
2729 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2730 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2735 TheAISContext()->CloseLocalContext(curindex);
2741 //=======================================================================
2742 //function : PickShapes
2744 //=======================================================================
2745 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2746 Handle(TopTools_HArray1OfShape)& thearr,
2747 const Standard_Integer MaxPick)
2750 Standard_Integer Taille = thearr->Length();
2752 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2754 // step 1: prepare the data
2755 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2756 if(TheType==TopAbs_SHAPE){
2757 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2758 TheAISContext()->AddFilter(F1);
2761 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2762 TheAISContext()->AddFilter(TF);
2763 TheAISContext()->ActivateStandardMode(TheType);
2767 // step 2 : wait for the selection...
2769 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2770 Standard_Integer NbPickFail(0);
2771 Standard_Integer argccc = 5;
2772 const char *bufff[] = { "A", "B", "C","D", "E" };
2773 const char **argvvv = (const char **) bufff;
2776 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2777 while(ViewerMainLoop(argccc,argvvv)){}
2778 Standard_Integer NbStored = TheAISContext()->NbSelected();
2779 if((unsigned int ) NbStored != NbPickGood)
2780 NbPickGood= NbStored;
2783 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2786 // step3 get result.
2788 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2790 Standard_Integer i(0);
2791 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2793 if(TheAISContext()->HasSelectedShape())
2794 thearr->SetValue(i,TheAISContext()->SelectedShape());
2796 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2797 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2801 TheAISContext()->CloseLocalContext(curindex);
2802 return Standard_True;
2806 //=======================================================================
2807 //function : VPickShape
2809 //=======================================================================
2810 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2812 TopoDS_Shape PickSh;
2813 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2816 theType = TopAbs_SHAPE;
2818 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2819 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2820 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2821 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2822 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2823 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2824 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2827 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2828 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2830 TCollection_AsciiString name;
2833 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2835 PickSh = ViewerTest::PickShape(theType);
2844 if(!PickSh.IsNull()){
2845 nbOfSub[Standard_Integer(theType)]++;
2847 name += nameType[Standard_Integer(theType)];
2848 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2853 // si on avait une petite methode pour voir si la shape
2854 // est deja dans la Double map, ca eviterait de creer....
2855 DBRep::Set(name.ToCString(),PickSh);
2857 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2858 GetMapOfAIS().Bind(newsh, name);
2859 TheAISContext()->Display(newsh);
2860 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2863 // Plusieurs objets a picker, vite vite vite....
2866 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2867 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2868 if(ViewerTest::PickShapes(theType,arr)){
2869 for(Standard_Integer i=1;i<=NbToPick;i++){
2870 PickSh = arr->Value(i);
2871 if(!PickSh.IsNull()){
2873 nbOfSub[Standard_Integer(theType)]++;
2876 name += nameType[Standard_Integer(theType)];
2877 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2885 DBRep::Set(name.ToCString(),PickSh);
2886 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2887 GetMapOfAIS().Bind(newsh, name);
2888 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2889 TheAISContext()->Display(newsh);
2899 //=======================================================================
2900 //function : VPickObject
2901 //purpose : filters can be set (type of Object to pick....
2903 //=======================================================================
2906 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2908 // preparation de la nomination automatique
2909 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2910 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2912 /* TCollection_AsciiString name;
2914 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2916 PickSh = ViewerTest::PickObject(theType);
2925 if(!PickSh.IsNull()){
2926 nbOfSub[Standard_Integer(theType)]++;
2928 name += nameType[Standard_Integer(theType)];
2929 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2934 // si on avait une petite methode pour voir si la shape
2935 // est deja dans la Double map, ca eviterait de creer....
2936 DBRep::Set(name.ToCString(),PickSh);
2938 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2939 GetMapOfAIS().Bind(newsh, name);
2940 TheAISContext()->Display(newsh);
2941 cout<<"Nom de la shape pickee : "<<name<<endl;
2944 // Plusieurs objets a picker, vite vite vite....
2947 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2948 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2949 if(ViewerTest::PickShapes(theType,arr)){
2950 for(Standard_Integer i=1;i<=NbToPick;i++){
2951 PickSh = arr->Value(i);
2952 if(!PickSh.IsNull()){
2954 nbOfSub[Standard_Integer(theType)]++;
2957 name += nameType[Standard_Integer(theType)];
2958 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2966 DBRep::Set(name.ToCString(),PickSh);
2967 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2968 GetMapOfAIS().Bind(newsh, name);
2969 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2970 TheAISContext()->Display(newsh);
2980 //=======================================================================
2981 //function : list of known objects
2983 //=======================================================================
2984 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2986 // 1234567890 12345678901234567 123456789
2987 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2988 TCollection_AsciiString BlankLine(64,'_');
2989 Standard_Integer i ;
2991 di<<"/n"<<BlankLine.ToCString()<<"\n";
2994 Colum[i].Center(20,' ');
2996 di<<"|"<<Colum[i].ToCString();
2999 di<<BlankLine.ToCString()<<"\n";
3001 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3002 const char ** names = GetTypeNames();
3004 TCollection_AsciiString curstring;
3005 TCollection_AsciiString curcolum[3];
3008 // les objets de type Datum..
3009 curcolum[1]+="Datum";
3011 curcolum[0].Clear();
3012 curcolum[0] += names[i];
3014 curcolum[2].Clear();
3015 curcolum[2]+=TCollection_AsciiString(i+1);
3017 for(Standard_Integer j =0;j<=2;j++){
3018 curcolum[j].Center(20,' ');
3019 di<<"|"<<curcolum[j].ToCString();
3023 di<<BlankLine.ToCString()<<"\n";
3025 // les objets de type shape
3026 curcolum[1].Clear();
3027 curcolum[1]+="Shape";
3028 curcolum[1].Center(20,' ');
3031 curcolum[0].Clear();
3032 curcolum[0] += names[7+i];
3033 curcolum[2].Clear();
3034 curcolum[2]+=TCollection_AsciiString(i);
3036 for(Standard_Integer j =0;j<=2;j++){
3037 curcolum[j].Center(20,' ');
3038 di<<"|"<<curcolum[j].ToCString();
3042 di<<BlankLine.ToCString()<<"\n";
3043 // les IO de type objet...
3044 curcolum[1].Clear();
3045 curcolum[1]+="Object";
3046 curcolum[1].Center(20,' ');
3048 curcolum[0].Clear();
3049 curcolum[0] += names[10+i];
3050 curcolum[2].Clear();
3051 curcolum[2]+=TCollection_AsciiString(i);
3053 for(Standard_Integer j =0;j<=2;j++){
3054 curcolum[j].Center(20,' ');
3055 di<<"|"<<curcolum[j].ToCString();
3059 di<<BlankLine.ToCString()<<"\n";
3060 // les contraintes et dimensions.
3061 // pour l'instant on separe juste contraintes et dimensions...
3062 // plus tard, on detaillera toutes les sortes...
3063 curcolum[1].Clear();
3064 curcolum[1]+="Relation";
3065 curcolum[1].Center(20,' ');
3067 curcolum[0].Clear();
3068 curcolum[0] += names[12+i];
3069 curcolum[2].Clear();
3070 curcolum[2]+=TCollection_AsciiString(i);
3072 for(Standard_Integer j =0;j<=2;j++){
3073 curcolum[j].Center(20,' ');
3074 di<<"|"<<curcolum[j].ToCString();
3078 di<<BlankLine.ToCString()<<"\n";
3085 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3087 if(argc!=2) return 1;
3089 AIS_KindOfInteractive TheType;
3090 Standard_Integer TheSign(-1);
3091 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3094 AIS_ListOfInteractive LIO;
3096 // en attendant l'amelioration ais pour les dimensions...
3098 Standard_Integer dimension_status(-1);
3099 if(TheType==AIS_KOI_Relation){
3100 dimension_status = TheSign ==1 ? 1 : 0;
3104 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3105 Handle(AIS_InteractiveObject) curio;
3106 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3109 if(dimension_status == -1)
3110 TheAISContext()->Erase(curio,Standard_False);
3112 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3113 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3114 (dimension_status==1 && KOD != AIS_KOD_NONE))
3115 TheAISContext()->Erase(curio,Standard_False);
3118 TheAISContext()->UpdateCurrentViewer();
3121 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3123 if(argc!=2) return 1;
3125 AIS_KindOfInteractive TheType;
3126 Standard_Integer TheSign(-1);
3127 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3129 // en attendant l'amelioration ais pour les dimensions...
3131 Standard_Integer dimension_status(-1);
3132 if(TheType==AIS_KOI_Relation){
3133 dimension_status = TheSign ==1 ? 1 : 0;
3137 AIS_ListOfInteractive LIO;
3138 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3139 Handle(AIS_InteractiveObject) curio;
3140 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3142 if(dimension_status == -1)
3143 TheAISContext()->Display(curio,Standard_False);
3145 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3146 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3147 (dimension_status==1 && KOD != AIS_KOD_NONE))
3148 TheAISContext()->Display(curio,Standard_False);
3153 TheAISContext()->UpdateCurrentViewer();
3157 //==============================================================================
3158 //function : VSetTransMode
3160 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3161 //==============================================================================
3163 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3164 // Verification des arguments
3165 if ( a3DView().IsNull() ) {
3166 ViewerTest::ViewerInit();
3167 di << "La commande vinit n'a pas ete appele avant" << "\n";
3170 if ( argc < 3 || argc > 8 ) {
3171 di << argv[0] << " Invalid number of arguments" << "\n";
3175 TCollection_AsciiString shapeName;
3176 shapeName = argv[1];
3177 Standard_Integer persFlag1 = atoi(argv[2]);
3178 Standard_Integer persFlag2 = 0;
3179 Standard_Integer persFlag3 = 0;
3180 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3181 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3182 persFlag2 = atoi(argv[3]);
3184 if ( argc == 5 || argc == 8 ) {
3185 persFlag3 = atoi(argv[4]);
3188 origin.SetX( atof(argv[argc - 3]) );
3189 origin.SetY( atof(argv[argc - 2]) );
3190 origin.SetZ( atof(argv[argc - 1]) );
3193 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3194 Handle(Standard_Transient) anObj;
3196 anObj = GetMapOfAIS().Find2(shapeName);
3197 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3198 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3199 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3200 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3201 di << argv[0] << " All persistence modifiers were removed" << "\n";
3204 di << argv[0] << " Wrong object type" << "\n";
3207 } else { // Create the AIS_Shape from a name
3208 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3209 if ( !aShape.IsNull() ) {
3210 GetMapOfAIS().Bind( aShape, shapeName );
3211 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3212 TheAISContext()->Display( aShape, Standard_False );
3214 di << argv[0] << " Object not found" << "\n";
3219 // Upadate the screen and redraw the view
3220 TheAISContext()->UpdateCurrentViewer();
3224 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3227 BRep_Builder builder;
3229 BRepTools::Read(shape, s, builder);
3230 DBRep::Set(a[1], shape);
3231 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3232 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3236 //============================================================================
3237 #include <AIS2D_InteractiveContext.hxx>
3238 #include <HLRAlgo_Projector.hxx>
3239 #include <Prs3d_Projector.hxx>
3240 #include <AIS2D_ProjShape.hxx>
3241 #include <gp_Ax2.hxx>
3243 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3246 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3247 /////////////////////
3248 TopoDS_Shape aShape = DBRep::Get(a[1]);
3249 aContext2D->EraseAll(Standard_True);
3250 //Standard_Integer aPolyAlgo = 0;
3251 Standard_Boolean IsPoly = Standard_False;
3252 gp_Ax2 anAx2 = gp::XOY();
3254 //if(n > 2) aPolyAlgo = atoi(a[2]);
3256 //IsPoly = aPolyAlgo > 0;
3258 TopoDS_Shape aResult = aShape;
3263 Standard_Real x = atof(a[2]);
3264 Standard_Real y = atof(a[3]);
3265 Standard_Real z = atof(a[4]);
3267 Standard_Real dx = atof(a[5]);
3268 Standard_Real dy = atof(a[6]);
3269 Standard_Real dz = atof(a[7]);
3271 Standard_Real dx1 = atof(a[8]);
3272 Standard_Real dy1 = atof(a[9]);
3273 Standard_Real dz1 = atof(a[10]);
3275 gp_Pnt anOrigin (x, y, z);
3276 gp_Dir aNormal (dx, dy, dz);
3277 gp_Dir aDX (dx1, dy1, dz1);
3278 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3282 HLRAlgo_Projector aProjector(anAx2);
3284 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3286 //aProjector = aProjector_t.Projector();
3288 Handle(AIS2D_ProjShape) myDisplayableShape =
3289 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3291 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3292 Standard_False, Standard_True, Standard_False);
3294 myDisplayableShape->Add( aResult );
3297 aContext2D->Display( myDisplayableShape,Standard_True );
3298 aContext2D->UpdateCurrentViewer();
3303 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3306 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3307 /////////////////////
3308 TopoDS_Shape aShape = DBRep::Get(a[1]);
3309 aContext2D->EraseAll(Standard_True);
3310 //Standard_Integer aPolyAlgo = 0;
3311 Standard_Boolean IsPoly = Standard_True;
3312 gp_Ax2 anAx2 = gp::XOY();
3314 //if(n > 2) aPolyAlgo = atoi(a[2]);
3316 //IsPoly = aPolyAlgo > 0;
3318 TopoDS_Shape aResult = aShape;
3323 Standard_Real x = atof(a[2]);
3324 Standard_Real y = atof(a[3]);
3325 Standard_Real z = atof(a[4]);
3327 Standard_Real dx = atof(a[5]);
3328 Standard_Real dy = atof(a[6]);
3329 Standard_Real dz = atof(a[7]);
3331 Standard_Real dx1 = atof(a[8]);
3332 Standard_Real dy1 = atof(a[9]);
3333 Standard_Real dz1 = atof(a[10]);
3335 gp_Pnt anOrigin (x, y, z);
3336 gp_Dir aNormal (dx, dy, dz);
3337 gp_Dir aDX (dx1, dy1, dz1);
3338 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3342 HLRAlgo_Projector aProjector(anAx2);
3344 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3346 //aProjector = aProjector_t.Projector();
3348 Handle(AIS2D_ProjShape) myDisplayableShape =
3349 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3351 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3352 Standard_False, Standard_True, Standard_False);
3354 myDisplayableShape->Add( aResult );
3357 aContext2D->Display( myDisplayableShape,Standard_True );
3358 aContext2D->UpdateCurrentViewer();
3363 //==============================================================================
3364 //function : ViewerTest::Commands
3365 //purpose : Add all the viewer command in the Draw_Interpretor
3366 //==============================================================================
3368 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3370 ViewerTest::ViewerCommands(theCommands);
3371 ViewerTest::RelationCommands(theCommands);
3372 ViewerTest::ObjectCommands(theCommands);
3373 ViewerTest::FilletCommands(theCommands);
3374 ViewerTest::VoxelCommands(theCommands);
3375 ViewerTest::OpenGlCommands(theCommands);
3377 const char *group = "AIS_Display";
3381 theCommands.Add("vdisplay",
3382 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3383 __FILE__,VDisplay2,group);
3385 theCommands.Add("verase",
3386 "verase : verase2 [name1] ... [name n] ",
3387 __FILE__,VErase2,group);
3389 theCommands.Add("vdonly",
3390 "vdonly : vdonly2 [name1] ... [name n]",
3391 __FILE__,VDonly2,group);
3393 theCommands.Add("vdisplayall",
3394 "vdisplayall : vdisplayall",
3395 __FILE__,VDisplayAll,group);
3397 theCommands.Add("veraseall",
3398 "veraseall : veraseall ",
3399 __FILE__,VEraseAll,group);
3401 theCommands.Add("verasetype",
3402 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3403 __FILE__,VEraseType,group);
3405 theCommands.Add("vdisplaytype",
3406 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3407 __FILE__,VDisplayType,group);
3409 theCommands.Add("vdisplaymode",
3410 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3411 __FILE__,VDispMode,group);
3413 theCommands.Add("verasemode",
3414 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3415 __FILE__,VDispMode,group);
3417 theCommands.Add("vsetdispmode",
3418 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3419 __FILE__,VDispMode,group);
3421 theCommands.Add("vunsetdispmode",
3422 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3423 __FILE__,VDispMode,group);
3425 theCommands.Add("vdir",
3427 __FILE__,VDebug,group);
3429 theCommands.Add("vdump",
3430 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file",
3431 __FILE__,VDump,group);
3433 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3434 __FILE__,VSubInt,group);
3436 theCommands.Add("vsetcolor",
3437 "vsetcolor : vsetcolor [name of shape] ColorName",
3438 __FILE__,VColor2,group);
3440 theCommands.Add("vunsetcolor",
3441 "vunsetcolor : vunsetcolor [name of shape] ",
3442 __FILE__,VColor2,group);
3444 theCommands.Add("vsettransparency",
3445 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3446 __FILE__,VTransparency,group);
3448 theCommands.Add("vunsettransparency",
3449 "vunsettransparency : vtransparency [name of shape]",
3450 __FILE__,VTransparency,group);
3452 theCommands.Add("vsetmaterial",
3453 "vmaterial : vmaterial [name of shape] MaterialName",
3454 __FILE__,VMaterial,group);
3456 theCommands.Add("vunsetmaterial",
3457 "vmaterial : vmaterial [name of shape]",
3458 __FILE__,VMaterial,group);
3460 theCommands.Add("vsetwidth",
3461 "vsetwidth : vwidth [name of shape] width(0->10)",
3462 __FILE__,VWidth,group);
3464 theCommands.Add("vunsetwidth",
3465 "vunsetwidth : vwidth [name of shape]",
3466 __FILE__,VWidth,group);
3468 theCommands.Add("vsetinteriorstyle",
3469 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3470 __FILE__,VInteriorStyle,group);
3472 theCommands.Add("vardis",
3473 "vardis : display activeareas",
3474 __FILE__,VDispAreas,group);
3476 theCommands.Add("varera",
3477 "varera : erase activeareas",
3478 __FILE__,VClearAreas,group);
3480 theCommands.Add("vsensdis",
3481 "vardisp : display active entities",
3482 __FILE__,VDispSensi,group);
3483 theCommands.Add("vsensera",
3484 "vardisp : erase active entities",
3485 __FILE__,VClearSensi,group);
3487 theCommands.Add("vselprecision",
3488 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3489 __FILE__,VSelPrecision,group);
3491 theCommands.Add("vperf",
3492 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3493 __FILE__,VPerf,group);
3495 theCommands.Add("vanimation",
3496 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3497 __FILE__,VAnimation,group);
3499 theCommands.Add("vsetshading",
3500 "vsetshading : vsetshading name Quality(default=0.0008) ",
3501 __FILE__,VShading,group);
3503 theCommands.Add("vunsetshading",
3504 "vunsetshading :vunsetshading name ",
3505 __FILE__,VShading,group);
3507 theCommands.Add("vtexture",
3508 "'vtexture NameOfShape TextureFile' \n \
3509 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3510 or 'vtexture NameOfShape ?' to list available textures\n \
3511 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3512 __FILE__,VTexture,group);
3514 theCommands.Add("vtexscale",
3515 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3516 or 'vtexscale NameOfShape ScaleUV' \n \
3517 or 'vtexscale NameOfShape' to disable scaling\n ",
3518 __FILE__,VTexture,group);
3520 theCommands.Add("vtexorigin",
3521 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3522 or 'vtexorigin NameOfShape UVOrigin' \n \
3523 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3524 __FILE__,VTexture,group);
3526 theCommands.Add("vtexrepeat",
3527 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3528 or 'vtexrepeat NameOfShape UVRepeat \n \
3529 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3532 theCommands.Add("vtexdefault",
3533 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3536 theCommands.Add("vsetam",
3537 "vsetActivatedModes: vsetam mode(1->7) ",
3538 __FILE__,VActivatedMode,group);
3540 theCommands.Add("vunsetam",
3541 "vunsetActivatedModes: vunsetam ",
3542 __FILE__,VActivatedMode,group);
3544 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3545 __FILE__,VState,group);
3547 theCommands.Add("vpickshapes",
3548 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3549 __FILE__,VPickShape,group);
3551 theCommands.Add("vtypes",
3552 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3555 theCommands.Add("vsettransmode",
3556 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3557 __FILE__,VSetTransMode,group);
3559 theCommands.Add("vr", "vr : reading of the shape",
3560 __FILE__,vr, group);
3562 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3563 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3567 //=====================================================================
3568 //========================= for testing Draft and Rib =================
3569 //=====================================================================
3570 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3571 #include <DBRep.hxx>
3572 #include <TopoDS_Face.hxx>
3573 #include <gp_Pln.hxx>
3574 #include <AIS_KindOfSurface.hxx>
3575 #include <BRepOffsetAPI_DraftAngle.hxx>
3576 #include <Precision.hxx>
3577 #include <BRepAlgo.hxx>
3578 #include <OSD_Environment.hxx>
3579 #include <DrawTrSurf.hxx>
3580 //#include <DbgTools.hxx>
3581 //#include <FeatAlgo_MakeLinearForm.hxx>
3586 //=======================================================================
3587 //function : IsValid
3589 //=======================================================================
3590 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3591 const TopoDS_Shape& theResult,
3592 const Standard_Boolean closedSolid,
3593 const Standard_Boolean GeomCtrl)
3595 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3596 TCollection_AsciiString checkValid = check.Value();
3597 Standard_Boolean ToCheck = Standard_True;
3598 if (!checkValid.IsEmpty()) {
3600 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3602 if ( checkValid=="true" || checkValid=="TRUE" ) {
3603 ToCheck= Standard_False;
3607 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3610 Standard_Boolean IsValid = Standard_True;
3612 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3617 //===============================================================================
3618 // TDraft : test draft, uses AIS Viewer
3619 // Solid Face Plane Angle Reverse
3620 //===============================================================================
3621 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3623 if (argc < 5) return 1;
3624 // argv[1] - TopoDS_Shape Solid
3625 // argv[2] - TopoDS_Shape Face
3626 // argv[3] - TopoDS_Shape Plane
3627 // argv[4] - Standard_Real Angle
3628 // argv[5] - Standard_Integer Reverse
3630 // sprintf(prefix, argv[1]);
3631 Standard_Real anAngle = 0;
3632 Standard_Boolean Rev = Standard_False;
3633 Standard_Integer rev = 0;
3634 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3635 TopoDS_Shape face = GetShapeFromName(argv[2]);
3636 TopoDS_Face Face = TopoDS::Face(face);
3637 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3638 if (Plane.IsNull ()) {
3639 di << "TEST : Plane is NULL" << "\n";
3642 anAngle = atof(argv[4]);
3643 anAngle = 2*M_PI * anAngle / 360.0;
3645 Handle( Geom_Surface )aSurf;
3646 AIS_KindOfSurface aSurfType;
3647 Standard_Real Offset;
3649 if(argc > 4) { // == 5
3650 rev = atoi(argv[5]);
3651 Rev = (rev)? Standard_True : Standard_False;
3654 TopoDS_Face face2 = TopoDS::Face(Plane);
3655 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3657 di << "TEST : Can't find plane" << "\n";
3661 aDir = aPln.Axis().Direction();
3664 if (Plane.Orientation() == TopAbs_REVERSED)
3666 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3668 BRepOffsetAPI_DraftAngle Draft (Solid);
3670 if(Abs(anAngle)< Precision::Angular()) {
3671 di << "TEST : NULL angle" << "\n";
3674 if(Rev) anAngle = - anAngle;
3675 Draft.Add (Face, aDir, anAngle, aPln);
3677 if (!Draft.IsDone()) {
3678 di << "TEST : Draft Not DONE " << "\n";
3681 TopTools_ListOfShape Larg;
3683 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3684 di << "TEST : DesignAlgo returns Not valid" << "\n";
3688 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3689 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3691 if ( !ais.IsNull() ) {
3692 ais->SetColor(DEFAULT_COLOR);
3693 ais->SetMaterial(DEFAULT_MATERIAL);
3694 // Display the AIS_Shape without redraw
3695 Ctx->Display(ais, Standard_False);
3697 const char *Name = "draft1";
3698 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3700 Handle(AIS_InteractiveObject) an_object =
3701 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3702 if (!an_object.IsNull()) {
3703 Ctx->Remove(an_object,
3705 GetMapOfAIS().UnBind2(Name) ;
3708 GetMapOfAIS().Bind(ais, Name);
3709 // DBRep::Set("draft", ais->Shape());
3711 Ctx->Display(ais, Standard_True);
3717 //============================================================================
3719 //============================================================================
3720 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3723 DrawTrSurf::BasicCommands(theCommands);
3724 const char* group = "Check Features Operations commands";
3726 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3728 &TDraft,group); //Draft_Modification
3731 //==============================================================================
3732 // ViewerTest::Factory
3733 //==============================================================================
3734 void ViewerTest::Factory(Draw_Interpretor& theDI)
3736 // definition of Viewer Command
3737 ViewerTest::Commands(theDI);
3738 ViewerTest::AviCommands(theDI);
3739 Viewer2dTest::Commands(theDI);
3741 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3745 // Declare entry point PLUGINFACTORY