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 = "Compound"; break;
566 if(theactivatedmodes.Contains(mode))
568 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
569 theactivatedmodes.Remove(mode);
570 cout<<"Mode "<< cmode <<" OFF"<<endl;
574 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
575 theactivatedmodes.Add(mode);
576 cout<<"Mode "<< cmode << " ON" << endl;
581 //==============================================================================
582 //function : SelectFromContext
583 //purpose : pick / select an object from the last MoveTo() on a
585 //==============================================================================
587 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
589 Standard_Boolean shift,
590 Standard_Boolean pick )
592 Handle(AIS_InteractiveObject) ret;
593 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
600 const Handle(AIS_InteractiveContext) aContext = EM->Context();
602 if ( !aContext->HasOpenedContext() ) {
603 aContext->InitCurrent();
604 while ( aContext->MoreCurrent() ) {
605 Handle(AIS_InteractiveObject) aisPickedShape =
606 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
609 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
610 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
611 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
613 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
614 if(!TheRealSh.IsNull()){
615 cout << "Current is " << name
616 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
619 ret = aisPickedShape;
620 if(!TheRealSh.IsNull()){
621 if ( pick && argc > 4 ) {
622 DBRep::Set(argv[4], TheRealSh->Shape());
625 aContext->NextCurrent();
629 // A LocalContext is opened, the use xxxxSelected()
630 // to select an object and its SubShape
631 aContext->InitSelected();
632 while ( aContext->MoreSelected() ) {
633 if ( !aContext->HasSelectedShape() ) {
636 TopoDS_Shape PickedShape = aContext->SelectedShape();
637 if ( pick && argc > 5 ) {
638 DBRep::Set(argv[5], PickedShape);
642 if ( aContext->Interactive().IsNull() ) {
643 cout << "??? (No InteractiveObject selected)" << endl;
646 Handle(AIS_InteractiveObject) aisPicked =
647 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
649 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
653 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
654 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
655 GetMapOfAIS().Find1(aisPicked).ToCString() :
658 if(!aisPickedShape.IsNull()){
659 if ( pick && argc > 4 ) {
660 // Create a draw variable to store the wohole shape
662 DBRep::Set(argv[4], aisPickedShape->Shape());
665 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
669 // Goto the next selected object
670 aContext->NextSelected();
676 //==============================================================================
677 //function : DetectedFromContext
678 //purpose : hilight dynamicaly an object from the last MoveTo() on a
680 //==============================================================================
681 Handle(AIS_InteractiveObject) DetectedFromContext(
682 Handle(AIS_InteractiveContext) aContext )
684 Handle(AIS_InteractiveObject) ret;
685 if ( aContext->HasDetected() ) {
686 if ( !aContext->HasDetectedShape() ) {
687 //No SubShape selected
690 // Get the detected SubShape
691 TopoDS_Shape PickedShape = aContext->DetectedShape();
693 if ( !aContext->DetectedInteractive().IsNull() ) {
694 Handle(AIS_InteractiveObject) aisPickedShape =
695 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
696 ret = aisPickedShape;
703 //==============================================================================
704 //function : VDispAreas,VDispSensitive,...
705 //purpose : Redraw the view
707 //==============================================================================
708 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
711 Handle(AIS_InteractiveContext) Ctx;
712 Handle(V3d_View) Viou;
713 GetCtxAndView(Ctx,Viou);
714 Ctx->DisplayActiveAreas(Viou);
717 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
719 Handle(AIS_InteractiveContext) Ctx;
720 Handle(V3d_View) Viou;
721 GetCtxAndView(Ctx,Viou);
722 Ctx->ClearActiveAreas(Viou);
726 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
728 Handle(AIS_InteractiveContext) Ctx;
729 Handle(V3d_View) Viou;
730 GetCtxAndView(Ctx,Viou);
731 Ctx->DisplayActiveSensitive(Viou);
735 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
737 Handle(AIS_InteractiveContext) Ctx;
738 Handle(V3d_View) Viou;
739 GetCtxAndView(Ctx,Viou);
740 Ctx->ClearActiveSensitive(Viou);
744 //==============================================================================
746 //purpose : To list the displayed object with their attributes
748 //==============================================================================
749 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
750 { if ( !a3DView().IsNull() ) {
751 di << "List of object in the viewer :" << "\n";
753 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
755 while ( it.More() ) {
756 di << "\t" << it.Key2().ToCString() << "\n";
764 //==============================================================================
765 //function : VSelPrecision
766 //purpose : To set the selection precision mode and tolerance value
767 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
768 // value (integer number of pixel for window mode, double value of
769 // sensitivity for view mode). Without arguments the function just
770 // prints the current precision mode and the corresponding tolerance.
771 //==============================================================================
772 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
776 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
780 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
781 if( aContext.IsNull() )
786 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
787 if( aMode == StdSelect_SM_WINDOW )
789 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
790 di << "Precision mode : 0 (window)\n";
791 di << "Pixel tolerance : " << aPixelTolerance << "\n";
793 else if( aMode == StdSelect_SM_VIEW )
795 Standard_Real aSensitivity = aContext->Sensitivity();
796 di << "Precision mode : 1 (view)\n";
797 di << "Sensitivity : " << aSensitivity << "\n";
802 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
803 aContext->SetSensitivityMode( aMode );
806 if( aMode == StdSelect_SM_WINDOW )
808 Standard_Integer aPixelTolerance = atoi( argv[2] );
809 aContext->SetPixelTolerance( aPixelTolerance );
811 else if( aMode == StdSelect_SM_VIEW )
813 Standard_Real aSensitivity = atof( argv[2] );
814 aContext->SetSensitivity( aSensitivity );
821 //==============================================================================
823 //purpose : To dump the active view snapshot to image file
824 //Draw arg : Picture file name with extension corresponding to desired format
825 //==============================================================================
826 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
830 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
834 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
837 TCollection_AsciiString aBuffTypeStr (argv[2]);
838 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
840 aBufferType = Graphic3d_BT_RGB;
842 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
844 aBufferType = Graphic3d_BT_RGBA;
846 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
848 aBufferType = Graphic3d_BT_Depth;
852 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
853 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
855 Handle(AIS_InteractiveContext) IC;
856 Handle(V3d_View) view;
857 GetCtxAndView (IC, view);
860 di << "Cannot find an active viewer/view\n";
864 if (aWidth <= 0 || aHeight <= 0)
866 if (!view->Dump (argv[1], aBufferType))
868 di << "Dumping failed!\n";
874 Image_AlienPixMap aPixMap;
875 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
877 di << "Dumping failed!\n";
881 if (aPixMap.SizeX() != Standard_Size(aWidth)
882 || aPixMap.SizeY() != Standard_Size(aHeight))
884 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
885 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
887 if (!aPixMap.Save (argv[1]))
889 di << "Saving image failed!\n";
896 //==============================================================================
897 //function : Displays,Erase...
900 //==============================================================================
901 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
902 const Standard_Integer Mode,
903 const Standard_Integer TypeOfOperation,
904 const Standard_Boolean Upd)
906 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
908 switch(TypeOfOperation){
910 Ctx->Display(IO,Mode,Upd);
913 Ctx->Erase(IO,Mode,Upd);
918 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
920 Ctx->SetDisplayMode(IO,Mode,Upd);
925 Ctx->SetDisplayMode(0,Upd);
927 Ctx->UnsetDisplayMode(IO,Upd);
934 //=======================================================================
937 //=======================================================================
938 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
941 TCollection_AsciiString name;
944 // display others presentations
945 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
946 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
947 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
948 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
950 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
952 //unset displaymode.. comportement particulier...
953 if(TypeOfOperation==4){
955 if(Ctx->NbCurrents()==0 ||
956 Ctx->NbSelected()==0){
957 Handle(AIS_InteractiveObject) IO;
958 VwrTst_DispErase(IO,-1,4,Standard_False);
960 else if(!Ctx->HasOpenedContext()){
961 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
962 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
965 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
966 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
967 Ctx->UpdateCurrentViewer();
970 Handle(AIS_InteractiveObject) IO;
972 if(GetMapOfAIS().IsBound2(name)){
973 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
975 VwrTst_DispErase(IO,-1,4,Standard_True);
980 Standard_Integer Dmode = atoi(argv[1]);
981 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
982 Handle(AIS_InteractiveObject) IO;
983 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
985 if(!Ctx->HasOpenedContext()){
986 // set/unset display mode sur le Contexte...
987 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
988 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
990 Ctx->UpdateCurrentViewer();
993 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
994 Ctx->Display(Ctx->Interactive(),Dmode);
998 Handle(AIS_InteractiveObject) IO;
1000 if(GetMapOfAIS().IsBound2(name))
1001 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1003 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
1009 //=======================================================================
1012 //=======================================================================
1013 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1015 if(argc==1) return 1;
1016 Standard_Integer On = atoi(argv[1]);
1017 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1021 if(!Ctx->HasOpenedContext()){
1022 di<<"sub intensite ";
1025 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1026 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1028 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1030 di <<"passage dans off"<<"\n";
1031 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1036 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1038 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1040 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1043 Ctx->UpdateCurrentViewer();
1046 Handle(AIS_InteractiveObject) IO;
1047 TCollection_AsciiString name = argv[2];
1048 if(GetMapOfAIS().IsBound2(name)){
1049 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1052 Ctx->SubIntensityOn(IO);
1054 Ctx->SubIntensityOff(IO);
1062 //==============================================================================
1063 //function : VColor2
1065 //purpose : change the color of a selected or named or displayed shape
1066 //Draw arg : vcolor2 [name] color
1067 //==============================================================================
1068 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1071 Standard_Boolean ThereIsCurrent;
1072 Standard_Boolean ThereIsArgument;
1073 Standard_Boolean IsBound = Standard_False ;
1075 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1077 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1078 ThereIsArgument = (argc != 2);
1081 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1082 ThereIsArgument = (argc == 2);
1085 if ( !a3DView().IsNull() ) {
1086 TCollection_AsciiString name;
1087 if (ThereIsArgument) {
1089 IsBound= GetMapOfAIS().IsBound2(name);
1091 if (TheAISContext()->HasOpenedContext())
1092 TheAISContext()->CloseLocalContext();
1094 // On set le Booleen There is current
1095 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1096 else ThereIsCurrent =Standard_False;
1098 //=======================================================================
1099 // Il y a un argument
1100 //=======================================================================
1101 if ( ThereIsArgument && IsBound ) {
1102 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1103 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1104 Handle(AIS_InteractiveObject) ashape =
1105 Handle(AIS_InteractiveObject)::DownCast (anObj);
1108 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1110 di << "HaveToSet 0\n";
1114 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1116 TheAISContext()->UnsetColor(ashape);
1117 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1118 Handle(NIS_Triangulated) ashape =
1119 Handle(NIS_Triangulated)::DownCast (anObj);
1120 if (!ashape.IsNull())
1121 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1126 //=======================================================================
1127 // Il n'y a pas d'arguments
1128 // Mais un ou plusieurs objets on des current representation
1129 //=======================================================================
1130 if (ThereIsCurrent && !ThereIsArgument) {
1131 for (TheAISContext() -> InitCurrent() ;
1132 TheAISContext() -> MoreCurrent() ;
1133 TheAISContext() ->NextCurrent() )
1135 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1136 if (ashape.IsNull())
1140 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1142 di << "HaveToSet 0\n";
1145 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1147 TheAISContext()->UnsetColor(ashape,Standard_False);
1150 TheAISContext()->UpdateCurrentViewer();
1153 //=======================================================================
1154 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1155 // on impose a tous les objets du viewer la couleur passee
1156 //=======================================================================
1157 else if (!ThereIsCurrent && !ThereIsArgument){
1158 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1159 while ( it.More() ) {
1160 const Handle(AIS_InteractiveObject) ashape =
1161 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1162 if (!ashape.IsNull())
1164 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1166 TheAISContext()->UnsetColor(ashape,Standard_False);
1169 TheAISContext()->UpdateCurrentViewer();
1175 //==============================================================================
1176 //function : VTransparency
1178 //purpose : change the transparency of a selected or named or displayed shape
1179 //Draw arg : vtransparency [name] TransparencyCoeficient
1180 //==============================================================================
1182 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1185 Standard_Boolean ThereIsCurrent;
1186 Standard_Boolean ThereIsArgument;
1187 Standard_Boolean IsBound = Standard_False ;
1189 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1191 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1192 ThereIsArgument = (argc != 2);
1195 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1196 ThereIsArgument = (argc == 2);
1199 if ( !a3DView().IsNull() ) {
1200 TCollection_AsciiString name;
1201 if (ThereIsArgument) {
1203 IsBound= GetMapOfAIS().IsBound2(name);
1205 if (TheAISContext()->HasOpenedContext())
1206 TheAISContext()->CloseLocalContext();
1208 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1209 else ThereIsCurrent = Standard_False;
1211 //=======================================================================
1212 // Il y a des arguments: un nom et une couleur
1213 //=======================================================================
1214 if ( ThereIsArgument && IsBound ) {
1215 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1216 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1217 const Handle(AIS_InteractiveObject) ashape =
1218 Handle(AIS_InteractiveObject)::DownCast(anObj);
1220 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1222 TheAISContext()->UnsetTransparency(ashape);
1223 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1224 const Handle(NIS_InteractiveObject) ashape =
1225 Handle(NIS_InteractiveObject)::DownCast(anObj);
1227 ashape->SetTransparency(atof(argv[2]) );
1229 ashape->UnsetTransparency();
1232 //=======================================================================
1233 // Il n'y a pas d'arguments
1234 // Mais un ou plusieurs objets on des current representation
1235 //=======================================================================
1236 if (ThereIsCurrent && !ThereIsArgument) {
1237 for (TheAISContext() -> InitCurrent() ;
1238 TheAISContext() -> MoreCurrent() ;
1239 TheAISContext() ->NextCurrent() )
1241 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1243 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1245 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1248 TheAISContext()->UpdateCurrentViewer();
1250 //=======================================================================
1251 // Il n'y a pas d'arguments ET aucun objet courrant
1252 //=======================================================================
1253 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1254 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1256 while ( it.More() ) {
1257 Handle(AIS_InteractiveObject) ashape =
1258 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1259 if (!ashape.IsNull())
1261 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1263 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1266 TheAISContext()->UpdateCurrentViewer();
1273 //==============================================================================
1274 //function : VMaterial
1276 //purpose : change the Material of a selected or named or displayed shape
1277 //Draw arg : vmaterial [Name] Material
1278 //==============================================================================
1279 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1282 Standard_Boolean ThereIsCurrent;
1283 Standard_Boolean ThereIsName;
1284 Standard_Boolean IsBound = Standard_False ;
1286 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1288 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1289 ThereIsName = (argc != 2);
1292 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1293 ThereIsName = (argc == 2);
1296 if ( !a3DView().IsNull() ) {
1297 TCollection_AsciiString name;
1300 IsBound= GetMapOfAIS().IsBound2(name);
1302 if (TheAISContext()->HasOpenedContext())
1303 TheAISContext()->CloseLocalContext();
1304 if (TheAISContext() -> NbCurrents() > 0 )
1305 ThereIsCurrent =Standard_True;
1307 ThereIsCurrent =Standard_False;
1309 //=======================================================================
1310 // Ther is a name of shape and a material name
1311 //=======================================================================
1312 if ( ThereIsName && IsBound ) {
1313 Handle(AIS_InteractiveObject) ashape =
1314 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1315 if (!ashape.IsNull())
1317 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1319 TheAISContext()->UnsetMaterial(ashape);
1321 //=======================================================================
1322 // Il n'y a pas de nom de shape
1323 // Mais un ou plusieurs objets on des current representation
1324 //=======================================================================
1325 if (ThereIsCurrent && !ThereIsName) {
1326 for (TheAISContext() -> InitCurrent() ;
1327 TheAISContext() -> MoreCurrent() ;
1328 TheAISContext() ->NextCurrent() )
1330 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1332 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1334 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1336 TheAISContext()->UpdateCurrentViewer();
1339 //=======================================================================
1340 // Il n'y a pas de noms de shape ET aucun objet courrant
1341 // On impose a tous les objets du viewer le material passe en argument
1342 //=======================================================================
1343 else if (!ThereIsCurrent && !ThereIsName){
1344 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1346 while ( it.More() ) {
1347 Handle(AIS_InteractiveObject) ashape =
1348 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1349 if (!ashape.IsNull())
1351 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1353 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1356 TheAISContext()->UpdateCurrentViewer();
1364 //==============================================================================
1367 //purpose : change the width of the edges of a selected or named or displayed shape
1368 //Draw arg : vwidth [Name] WidthValue(1->10)
1369 //==============================================================================
1370 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1373 Standard_Boolean ThereIsCurrent;
1374 Standard_Boolean ThereIsArgument;
1375 Standard_Boolean IsBound = Standard_False ;
1377 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1379 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1380 ThereIsArgument = (argc != 2);
1383 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1384 ThereIsArgument = (argc == 2);
1386 if ( !a3DView().IsNull() ) {
1387 TCollection_AsciiString name;
1388 if (ThereIsArgument) {
1390 IsBound= GetMapOfAIS().IsBound2(name);
1392 if (TheAISContext()->HasOpenedContext())
1393 TheAISContext()->CloseLocalContext();
1395 if (TheAISContext() -> NbCurrents() > 0 )
1396 ThereIsCurrent =Standard_True;
1398 ThereIsCurrent =Standard_False;
1400 if ( ThereIsArgument && IsBound ) {
1401 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1402 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1403 const Handle(AIS_InteractiveObject) ashape =
1404 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1406 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1408 TheAISContext()->UnsetWidth (ashape);
1409 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1410 const Handle(NIS_Triangulated) ashape =
1411 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1412 if (HaveToSet && !ashape.IsNull())
1413 ashape->SetLineWidth ( atof (argv[2]) );
1417 //=======================================================================
1418 // Il n'y a pas d'arguments
1419 // Mais un ou plusieurs objets on des current representation
1420 //=======================================================================
1421 if (ThereIsCurrent && !ThereIsArgument) {
1422 for (TheAISContext() -> InitCurrent() ;
1423 TheAISContext() -> MoreCurrent() ;
1424 TheAISContext() ->NextCurrent() )
1426 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1428 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1430 TheAISContext()->UnsetWidth(ashape,Standard_False);
1432 TheAISContext()->UpdateCurrentViewer();
1434 //=======================================================================
1435 // Il n'y a pas d'arguments ET aucun objet courrant
1436 //=======================================================================
1437 else if (!ThereIsCurrent && !ThereIsArgument){
1438 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1440 while ( it.More() ) {
1441 Handle(AIS_InteractiveObject) ashape =
1442 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1443 if (!ashape.IsNull())
1445 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1447 TheAISContext()->UnsetWidth(ashape,Standard_False);
1450 TheAISContext()->UpdateCurrentViewer();
1456 //==============================================================================
1457 //function : VInteriorStyle
1458 //purpose : sets interior style of the a selected or named or displayed shape
1459 //Draw arg : vsetinteriorstyle [shape] style
1460 //==============================================================================
1461 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1462 const Standard_Integer theStyle,
1463 Draw_Interpretor& di)
1465 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1466 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1467 " (Aspect_IS_HIDDENLINE)]\n";
1470 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1471 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1472 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1473 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1474 aFillAspect->SetInteriorStyle (aStyle);
1475 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1478 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1480 if (argc < 2 || argc > 3) {
1481 di << argv[0] << " requires 2 or 3 arguments\n";
1482 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1483 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1484 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1488 Standard_Boolean ThereIsCurrent;
1489 Standard_Boolean ThereIsArgument;
1490 Standard_Boolean IsBound = Standard_False ;
1492 ThereIsArgument = (argc > 2);
1493 if ( !a3DView().IsNull() ) {
1494 TCollection_AsciiString name;
1495 if (ThereIsArgument) {
1497 IsBound= GetMapOfAIS().IsBound2(name);
1499 if (TheAISContext()->HasOpenedContext())
1500 TheAISContext()->CloseLocalContext();
1502 if (TheAISContext() -> NbCurrents() > 0 )
1503 ThereIsCurrent =Standard_True;
1505 ThereIsCurrent =Standard_False;
1507 if ( ThereIsArgument && IsBound ) {
1508 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1509 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1510 const Handle(AIS_InteractiveObject) ashape =
1511 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1512 SetInteriorStyle (ashape, atoi (argv[2]), di);
1515 //=======================================================================
1516 // No arguments specified
1517 // But there are one or more selected objects
1518 //=======================================================================
1519 if (ThereIsCurrent && !ThereIsArgument) {
1520 for (TheAISContext() -> InitCurrent() ;
1521 TheAISContext() -> MoreCurrent() ;
1522 TheAISContext() ->NextCurrent() )
1524 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1525 SetInteriorStyle (ashape, atoi (argv[1]), di);
1528 //=======================================================================
1529 // No arguments specified and there are no selected objects
1530 //=======================================================================
1531 else if (!ThereIsCurrent && !ThereIsArgument){
1532 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1534 while ( it.More() ) {
1535 Handle(AIS_InteractiveObject) ashape =
1536 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1537 if (!ashape.IsNull())
1538 SetInteriorStyle (ashape, atoi (argv[1]), di);
1542 TheAISContext()->UpdateCurrentViewer();
1547 //==============================================================================
1548 //function : VDonly2
1550 //purpose : Display only a selected or named object
1551 // if there is no selected or named object s, nothing is donne
1552 //Draw arg : vdonly2 [name1] ... [name n]
1553 //==============================================================================
1554 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1557 if ( a3DView().IsNull() )
1560 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1561 Standard_Boolean ThereIsArgument= argc>1;
1563 if (TheAISContext()->HasOpenedContext())
1564 TheAISContext()->CloseLocalContext();
1566 //===============================================================
1567 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1569 //===============================================================
1570 if (!ThereIsArgument && ThereIsCurrent) {
1573 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1576 for(TheAISContext()->InitCurrent();
1577 TheAISContext()->MoreCurrent();
1578 TheAISContext()->NextCurrent()){
1579 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1580 TheAISContext()->Erase(aShape,Standard_False);}
1582 TheAISContext() ->UpdateCurrentViewer();
1583 //===============================================================
1584 // Il y a des arguments
1585 //===============================================================
1586 if (ThereIsArgument) {
1587 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1589 while ( it.More() ) {
1590 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1591 const Handle(AIS_InteractiveObject) aShape =
1592 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1593 TheAISContext()->Erase(aShape,Standard_False);
1594 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1595 const Handle(NIS_InteractiveObject) aShape =
1596 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1597 TheNISContext()->Erase(aShape);
1602 // On display les objets passes par parametre
1603 for (int i=1; i<argc ; i++) {
1604 TCollection_AsciiString name=argv[i];
1605 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1607 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1608 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1609 const Handle(AIS_InteractiveObject) aShape =
1610 Handle(AIS_InteractiveObject)::DownCast (anObj);
1611 TheAISContext()->Display(aShape, Standard_False);
1612 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1613 Handle(NIS_InteractiveObject) aShape =
1614 Handle(NIS_InteractiveObject)::DownCast (anObj);
1615 TheNISContext()->Display(aShape);
1619 TheAISContext() ->UpdateCurrentViewer();
1620 // TheNISContext() ->UpdateViews();
1625 //==============================================================================
1626 //function : VErase2
1628 //purpose : Erase some selected or named objects
1629 // if there is no selected or named objects, the whole viewer is erased
1630 //Draw arg : verase2 [name1] ... [name n]
1631 //==============================================================================
1632 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1635 if ( a3DView().IsNull() )
1638 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1639 Standard_Boolean ThereIsArgument= argc>1;
1640 if(TheAISContext()->HasOpenedContext())
1641 TheAISContext()->CloseLocalContext();
1643 //===============================================================
1644 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1646 //===============================================================
1647 if (!ThereIsArgument && ThereIsCurrent) {
1648 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1650 while ( it.More() ) {
1651 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1652 const Handle(AIS_InteractiveObject) aShape =
1653 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1654 if (TheAISContext()->IsCurrent(aShape))
1655 TheAISContext()->Erase(aShape,Standard_False);
1660 TheAISContext() ->UpdateCurrentViewer();
1663 //===============================================================
1664 // Il n'y a pas d'arguments et aucuns objets selectionnes
1666 // On erase tout le viewer
1667 //===============================================================
1669 if (!ThereIsArgument && !ThereIsCurrent) {
1670 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1671 while ( it.More() ) {
1672 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1673 const Handle(AIS_InteractiveObject) aShape =
1674 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1675 TheAISContext()->Erase(aShape,Standard_False);
1676 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1677 const Handle(NIS_InteractiveObject) aShape =
1678 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1679 TheNISContext()->Erase(aShape);
1683 TheAISContext() ->UpdateCurrentViewer();
1684 // TheNISContext()->UpdateViews();
1687 //===============================================================
1688 // Il y a des arguments
1689 //===============================================================
1690 if (ThereIsArgument) {
1691 for (int i=1; i<argc ; i++) {
1692 TCollection_AsciiString name=argv[i];
1693 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1695 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1696 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1697 const Handle(AIS_InteractiveObject) aShape =
1698 Handle(AIS_InteractiveObject)::DownCast (anObj);
1699 TheAISContext()->Erase(aShape,Standard_False);
1700 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1701 const Handle(NIS_InteractiveObject) aShape =
1702 Handle(NIS_InteractiveObject)::DownCast (anObj);
1703 TheNISContext()->Erase(aShape);
1707 TheAISContext() ->UpdateCurrentViewer();
1708 // TheNISContext() ->UpdateViews();
1713 //==============================================================================
1714 //function : VEraseAll
1716 //purpose : Erase all the objects displayed in the viewer
1717 //Draw arg : veraseall
1718 //==============================================================================
1719 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1722 // Verification des arguments
1723 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1724 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1725 TheAISContext()->CloseAllContexts(Standard_False);
1726 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1728 while ( it.More() ) {
1729 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1730 const Handle(AIS_InteractiveObject) aShape =
1731 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1732 TheAISContext()->Erase(aShape,Standard_False);
1733 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1734 const Handle(NIS_InteractiveObject) aShape =
1735 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1736 TheNISContext()->Erase(aShape);
1740 TheAISContext() ->UpdateCurrentViewer();
1741 // TheNISContext() ->UpdateViews();
1746 //==============================================================================
1747 //function : VDisplayAll
1749 //purpose : Display all the objects of the Map
1750 //Draw arg : vdisplayall
1751 //==============================================================================
1752 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1755 if (! a3DView().IsNull() ) {
1756 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1757 if (TheAISContext()->HasOpenedContext())
1758 TheAISContext()->CloseLocalContext();
1759 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1761 while ( it.More() ) {
1762 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1763 const Handle(AIS_InteractiveObject) aShape =
1764 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1765 TheAISContext()->Erase(aShape,Standard_False);
1766 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1767 const Handle(NIS_InteractiveObject) aShape =
1768 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1769 TheNISContext()->Erase(aShape);
1774 while ( it.More() ) {
1775 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1776 const Handle(AIS_InteractiveObject) aShape =
1777 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1778 TheAISContext()->Display(aShape, Standard_False);
1779 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1780 Handle(NIS_InteractiveObject) aShape =
1781 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1782 TheNISContext()->Display(aShape);
1786 TheAISContext() ->UpdateCurrentViewer();
1787 // TheNISContext() ->UpdateViews();
1792 //#######################################################################################################
1796 //#######################################################################################################
1798 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1800 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1801 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1802 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1803 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1804 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1806 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1807 if(myAISContext.IsNull())
1809 di << "use 'vinit' command before " << argv[0] << "\n";
1813 Handle(AIS_InteractiveObject) TheAisIO;
1814 Handle(AIS_TexturedShape) myShape;
1815 Standard_Integer myPreviousMode = 0;
1817 if (argc<2 || !argv[1])
1819 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1823 TCollection_AsciiString name = argv[1];
1824 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1826 if (GetMapOfAIS().IsBound2(name))
1827 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1828 (GetMapOfAIS().Find2(name));
1829 if (TheAisIO.IsNull())
1831 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1835 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1837 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1838 myPreviousMode = myShape->DisplayMode() ;
1842 myAISContext->Clear(TheAisIO,Standard_False);
1843 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1844 GetMapOfAIS().UnBind1(TheAisIO);
1845 GetMapOfAIS().UnBind2(name);
1846 GetMapOfAIS().Bind(myShape, name);
1850 case 1: // vtexture : we only map a texture on the shape
1853 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1856 if (argc>2 && argv[2])
1858 if(strcasecmp(argv[2],"?")==0)
1860 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1861 di<<"\n Files in current directory : \n"<<"\n";
1862 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1863 di.Eval(Cmnd.ToCString());
1865 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1868 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1869 di.Eval(Cmnd.ToCString());
1874 myShape->SetTextureFileName(argv[2]);
1878 di <<"Texture mapping disabled \n \
1879 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1881 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1882 if (myPreviousMode == 3 )
1883 myAISContext->RecomputePrsOnly(myShape);
1884 myAISContext->Display(myShape, Standard_True);
1889 case 2: // vtexscale : we change the scaling factor of the texture
1893 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1897 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1898 ( argv[2] ? atof(argv[2]) : 1.0 ),
1899 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1902 case 3: // vtexorigin : we change the origin of the texture on the shape
1905 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1908 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1909 ( argv[2] ? atof(argv[2]) : 0.0 ),
1910 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1913 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1916 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1919 if (argc>2 && argv[2])
1921 di <<"Texture repeat enabled"<<"\n";
1922 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1926 di <<"Texture repeat disabled"<<"\n";
1927 myShape->SetTextureRepeat(Standard_False);
1931 case 5: // vtexdefault : default texture mapping
1932 // ScaleU = ScaleV = 100.0
1933 // URepeat = VRepeat = 1.0
1934 // Uorigin = VOrigin = 0.0
1938 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1941 myShape->SetTextureRepeat(Standard_False);
1942 myShape->SetTextureOrigin(Standard_False);
1943 myShape->SetTextureScale (Standard_False);
1947 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1948 myAISContext->RecomputePrsOnly(myShape);
1951 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1952 myAISContext->Display(myShape, Standard_True);
1953 myAISContext->Update(myShape,Standard_True);
1958 //==============================================================================
1959 //function : VDisplay2
1961 //purpose : Display an object from its name
1962 //Draw arg : vdisplay name1 [name2] ... [name n]
1963 //==============================================================================
1964 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1967 // Verification des arguments
1968 if ( a3DView().IsNull() ) {
1970 ViewerTest::ViewerInit();
1971 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1976 di<<argv[0]<<" Syntaxe error"<<"\n";
1981 TCollection_AsciiString name;
1982 if (TheAISContext()->HasOpenedContext())
1983 TheAISContext()->CloseLocalContext();
1985 for ( int i = 1; i < argc; i++ ) {
1987 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1988 Standard_Boolean IsDatum = Standard_False;
1989 Handle(Standard_Transient) anObj;
1991 anObj = GetMapOfAIS().Find2(name);
1992 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1993 Handle(AIS_InteractiveObject) aShape =
1994 Handle(AIS_InteractiveObject)::DownCast(anObj);
1995 if (aShape->Type()==AIS_KOI_Datum) {
1996 IsDatum = Standard_True;
1997 TheAISContext()->Display(aShape, Standard_False);
2000 di << "Display " << name.ToCString() << "\n";
2001 // Get the Shape from a name
2002 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2004 // Update the Shape in the AIS_Shape
2005 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2006 if(!TheRealSh.IsNull())
2007 TheRealSh->Set(NewShape);
2008 TheAISContext()->Redisplay(aShape, Standard_False);
2009 TheAISContext()->Display(aShape, Standard_False);
2012 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2013 Handle(NIS_InteractiveObject) aShape =
2014 Handle(NIS_InteractiveObject)::DownCast(anObj);
2015 TheNISContext()->Display(aShape);
2018 else { // Create the AIS_Shape from a name
2019 const Handle(AIS_InteractiveObject) aShape =
2020 GetAISShapeFromName((const char *)name.ToCString());
2021 if ( !aShape.IsNull() ) {
2022 GetMapOfAIS().Bind(aShape, name);
2023 TheAISContext()->Display(aShape, Standard_False);
2027 // Upadate the screen and redraw the view
2028 TheAISContext()->UpdateCurrentViewer();
2029 // TheNISContext()->UpdateViews();
2033 //==============================================================================
2035 //purpose : Test the annimation of an object along a
2036 // predifined trajectory
2037 //Draw arg : vmove ShapeName
2038 //==============================================================================
2041 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2046 if (TheAISContext()->HasOpenedContext())
2047 TheAISContext()->CloseLocalContext();
2049 Standard_Real Step=2*M_PI/180;
2050 Standard_Real Angle=0;
2051 // R est le rayon de l'hellicoide
2053 // D est la distance parcourue en translation en 1 tour
2056 Handle(AIS_InteractiveObject) aIO;
2058 if (GetMapOfAIS().IsBound2(argv[1]))
2059 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2062 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
2065 TheAISContext()->Deactivate(aIO);
2067 // boucle generant le mouvement
2069 di<<" Transformations"<<"\n";
2070 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2073 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) );
2075 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
2076 TheAISContext()->SetLocation(aIO,myTransfo);
2078 TheAISContext() ->UpdateCurrentViewer();
2083 di<<" Locations"<<"\n";
2084 gp_Trsf myAngleTrsf;
2085 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2086 TopLoc_Location myDeltaAngle (myAngleTrsf);
2088 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
2089 TopLoc_Location myDeltaDist (myDistTrsf);
2090 TopLoc_Location myTrueLoc;
2092 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2095 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2096 TheAISContext()->SetLocation(aIO,myTrueLoc );
2097 TheAISContext() ->UpdateCurrentViewer();
2102 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2104 //TopLoc_Location Tempo=aIO->Location();
2105 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2106 //ShapeBis.Located(Tempo);
2109 // On reset la location (origine) contenue dans l'AISInteractiveObject
2110 TheAISContext() ->ResetLocation(aIO);
2112 // On force aShape a devenir l'AIS IO propre a ShapeBis
2114 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2115 // ->Set() est une methode de AIS_Shape
2116 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2118 // On donne a ShapeBis le nom de l'AIS IO
2119 //Rep::Set(argv[1],ShapeBis);
2122 TheAISContext()->Redisplay(aIO,Standard_False);
2124 // On reactive la selection des primitives sensibles
2125 TheAISContext()->Activate(aIO,0);
2127 TheAISContext() ->UpdateCurrentViewer();
2128 a3DView() -> Redraw();
2131 di<<" Temps ecoule "<<"\n";
2139 //==============================================================================
2141 //purpose : Test the annimation of an object along a
2142 // predifined trajectory
2143 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2144 //==============================================================================
2146 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2149 if (TheAISContext()->HasOpenedContext())
2150 TheAISContext()->CloseLocalContext();
2152 Standard_Real Step=4*M_PI/180;
2153 Standard_Real Angle=0;
2155 Handle(AIS_InteractiveObject) aIO;
2156 if (GetMapOfAIS().IsBound2(argv[1]))
2157 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2161 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2165 if (atoi(argv[3])==1 ) {
2166 di<<" Primitives sensibles OFF"<<"\n";
2167 TheAISContext()->Deactivate(aIO);
2170 di<<" Primitives sensibles ON"<<"\n";
2172 // Movement par transformation
2173 if(atoi(argv[2]) ==1) {
2174 di<<" Calcul par Transformation"<<"\n";
2175 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2179 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2180 TheAISContext()->SetLocation(aShape,myTransfo);
2181 TheAISContext() ->UpdateCurrentViewer();
2186 di<<" Calcul par Locations"<<"\n";
2187 gp_Trsf myAngleTrsf;
2188 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2189 TopLoc_Location myDeltaAngle (myAngleTrsf);
2190 TopLoc_Location myTrueLoc;
2192 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2195 myTrueLoc=myTrueLoc*myDeltaAngle;
2196 TheAISContext()->SetLocation(aShape,myTrueLoc );
2197 TheAISContext() ->UpdateCurrentViewer();
2200 if (atoi(argv[3])==1 ){
2201 // On reactive la selection des primitives sensibles
2202 TheAISContext()->Activate(aIO,0);
2204 a3DView() -> Redraw();
2206 di<<" Temps ecoule "<<"\n";
2212 //==================================================================================
2213 // Function : VAnimation
2214 //==================================================================================
2215 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2217 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2221 Standard_Real thread = 4;
2222 Standard_Real angleA=0;
2223 Standard_Real angleB;
2225 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2228 TopoDS_Shape CrankArm;
2229 TopoDS_Shape CylinderHead;
2230 TopoDS_Shape Propeller;
2231 TopoDS_Shape EngineBlock;
2233 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2234 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2235 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2236 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2237 BRepTools::Read(CrankArm,argv[1],B);
2238 BRepTools::Read(CylinderHead,argv[2],B);
2239 BRepTools::Read(Propeller,argv[3],B);
2240 BRepTools::Read(EngineBlock,argv[4],B);
2242 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2248 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2249 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2250 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2251 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2253 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2254 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2255 GetMapOfAIS().Bind(myAisCrankArm,"c");
2256 GetMapOfAIS().Bind(myAisPropeller,"d");
2258 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2259 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2260 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2262 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2263 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2264 TheAISContext()->Display(myAisCrankArm,Standard_False );
2265 TheAISContext()->Display(myAisPropeller,Standard_False);
2267 TheAISContext()->Deactivate(myAisCylinderHead);
2268 TheAISContext()->Deactivate(myAisEngineBlock );
2269 TheAISContext()->Deactivate(myAisCrankArm );
2270 TheAISContext()->Deactivate(myAisPropeller );
2272 // Boucle de mouvement
2273 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2275 angleA = thread*myAngle*M_PI/180;
2276 X = Sin(angleA)*3/8;
2277 angleB = atan(X / Sqrt(-X * X + 1));
2278 Standard_Real decal(25*0.6);
2281 //Build a transformation on the display
2282 gp_Trsf aPropellerTrsf;
2283 aPropellerTrsf.SetRotation(Ax1,angleA);
2284 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2286 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));
2287 gp_Trsf aCrankArmTrsf;
2288 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2289 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2291 TheAISContext()->UpdateCurrentViewer();
2294 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2295 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2297 myAisCrankArm ->ResetLocation();
2298 myAisPropeller->ResetLocation();
2300 myAisCrankArm -> Set(myNewCrankArm );
2301 myAisPropeller -> Set(myNewPropeller);
2303 TheAISContext()->Activate(myAisCylinderHead,0);
2304 TheAISContext()->Activate(myAisEngineBlock,0 );
2305 TheAISContext()->Activate(myAisCrankArm ,0 );
2306 TheAISContext()->Activate(myAisPropeller ,0 );
2312 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2313 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2315 TheAISContext()->UpdateCurrentViewer();
2316 a3DView()->Redraw();
2325 //==============================================================================
2326 //function : VShading
2327 //purpose : Sharpen or roughten the quality of the shading
2328 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2329 //==============================================================================
2330 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2332 Standard_Real myDevCoef;
2333 Handle(AIS_InteractiveObject) TheAisIO;
2336 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2338 if (TheAISContext()->HasOpenedContext())
2339 TheAISContext()->CloseLocalContext();
2344 myDevCoef =atof(argv[2]);
2347 TCollection_AsciiString name=argv[1];
2348 if (GetMapOfAIS().IsBound2(name ))
2349 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2350 if (TheAisIO.IsNull())
2351 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2354 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2356 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2358 TheAISContext()->Redisplay(TheAisIO);
2361 //==============================================================================
2362 //function : HaveMode
2363 //use : VActivatedModes
2364 //==============================================================================
2365 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2367 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2369 TColStd_ListOfInteger List;
2370 TheAISContext()->ActivatedModes (TheAisIO,List);
2371 TColStd_ListIteratorOfListOfInteger it;
2372 Standard_Boolean Found=Standard_False;
2373 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2374 if (it.Value()==mode ) Found=Standard_True;
2381 //==============================================================================
2382 //function : VActivatedMode
2384 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2385 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2386 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2387 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2388 // qu'un nom et qu'un mode.
2389 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2390 //==============================================================================
2391 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2393 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2396 Standard_Boolean ThereIsName = Standard_False ;
2398 if(!a3DView().IsNull()){
2400 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2401 // verification des arguments
2403 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2404 ThereIsName = (argc == 3);
2408 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2410 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2411 di<<" Fermeture du Context local"<<"\n";
2412 if (TheAISContext()->HasOpenedContext())
2413 TheAISContext()->CloseLocalContext();
2417 // IL n'y a aps de nom de shape passe en argument
2418 if (HaveToSet && !ThereIsName){
2419 Standard_Integer aMode=atoi(argv [1]);
2421 const char *cmode="???";
2423 case 0: cmode = "Shape"; break;
2424 case 1: cmode = "Vertex"; break;
2425 case 2: cmode = "Edge"; break;
2426 case 3: cmode = "Wire"; break;
2427 case 4: cmode = "Face"; break;
2428 case 5: cmode = "Shell"; break;
2429 case 6: cmode = "Solid"; break;
2430 case 7: cmode = "Compound"; break;
2433 if( !TheAISContext()->HasOpenedContext() ) {
2434 // il n'y a pas de Context local d'ouvert
2435 // on en ouvre un et on charge toutes les shapes displayees
2436 // on load tous les objets displayees et on Activate les objets de la liste
2437 AIS_ListOfInteractive ListOfIO;
2438 // on sauve dans une AISListOfInteractive tous les objets currents
2439 if (TheAISContext()->NbCurrents()>0 ){
2440 TheAISContext()->UnhilightCurrents(Standard_False);
2442 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2443 ListOfIO.Append(TheAISContext()->Current() );
2447 TheAISContext()->OpenLocalContext(Standard_False);
2448 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2451 Handle(AIS_InteractiveObject) aIO =
2452 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2454 TheAISContext()->Load(aIO,0,Standard_False);
2457 // traitement des objets qui etaient currents dans le Contexte global
2458 if (!ListOfIO.IsEmpty() ) {
2459 // il y avait des objets currents
2460 AIS_ListIteratorOfListOfInteractive iter;
2461 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2462 Handle(AIS_InteractiveObject) aIO=iter.Value();
2463 TheAISContext()->Activate(aIO,aMode);
2464 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2468 // On applique le mode a tous les objets displayes
2469 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2470 it2 (GetMapOfAIS());
2472 Handle(AIS_InteractiveObject) aIO =
2473 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2474 if (!aIO.IsNull()) {
2475 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2476 TheAISContext()->Activate(aIO,aMode);
2485 // un Context local est deja ouvert
2486 // Traitement des objets du Context local
2487 if (TheAISContext()->NbSelected()>0 ){
2488 TheAISContext()->UnhilightSelected(Standard_False);
2489 // il y a des objets selected,on les parcourt
2490 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2491 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2494 if (HaveMode(aIO,aMode) ) {
2495 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2496 TheAISContext()->Deactivate(aIO,aMode);
2499 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2500 TheAISContext()->Activate(aIO,aMode);
2506 // il n'y a pas d'objets selected
2507 // tous les objets diplayes sont traites
2508 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2511 Handle(AIS_InteractiveObject) aIO =
2512 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2513 if (!aIO.IsNull()) {
2514 if (HaveMode(aIO,aMode) ) {
2515 di<<" Mode: "<<cmode<<" OFF pour "
2516 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2517 TheAISContext()->Deactivate(aIO,aMode);
2520 di<<" Mode: "<<cmode<<" ON pour"
2521 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2522 TheAISContext()->Activate(aIO,aMode);
2530 else if (HaveToSet && ThereIsName){
2531 Standard_Integer aMode=atoi(argv [2]);
2532 Handle(AIS_InteractiveObject) aIO =
2533 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2535 if (!aIO.IsNull()) {
2536 const char *cmode="???";
2539 case 0: cmode = "Shape"; break;
2540 case 1: cmode = "Vertex"; break;
2541 case 2: cmode = "Edge"; break;
2542 case 3: cmode = "Wire"; break;
2543 case 4: cmode = "Face"; break;
2544 case 5: cmode = "Shell"; break;
2545 case 6: cmode = "Solid"; break;
2546 case 7: cmode = "Compound"; break;
2549 if( !TheAISContext()->HasOpenedContext() ) {
2550 TheAISContext()->OpenLocalContext(Standard_False);
2551 // On charge tous les objets de la map
2552 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2554 Handle(AIS_InteractiveObject) aShape=
2555 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2556 if (!aShape.IsNull())
2557 TheAISContext()->Load(aShape,0,Standard_False);
2560 TheAISContext()->Activate(aIO,aMode);
2561 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2565 // un Context local est deja ouvert
2566 if (HaveMode(aIO,aMode) ) {
2567 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2568 TheAISContext()->Deactivate(aIO,aMode);
2571 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2572 TheAISContext()->Activate(aIO,aMode);
2584 //==============================================================================
2585 // function : WhoAmI
2587 //==============================================================================
2588 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2591 if (theShape->Type()==AIS_KOI_Datum) {
2592 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2593 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2594 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2595 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2596 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2597 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2598 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2601 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2602 // AIS_Dimentions et AIS_Relations
2603 else if (theShape->Type()==AIS_KOI_Relation) {
2604 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2606 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2607 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2608 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2609 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2610 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2611 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2612 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2613 // AIS no repertorie.
2614 else {di<<" Type Unknown.";}
2620 //==============================================================================
2623 //Draw arg : vstate [nameA] ... [nameN]
2624 //==============================================================================
2625 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2627 TheAISContext()->CloseAllContexts();
2628 const Standard_Boolean ThereIsArguments=(argc>=2);
2629 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2631 // ==================
2632 // Il y a un argument
2633 // ==================
2634 if (ThereIsArguments) {
2635 for (int cpt=1;cpt<argc;cpt++) {
2636 // Verification que lq piece est bien bindee.
2637 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2638 const Handle(AIS_InteractiveObject) theShape=
2639 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2641 if (!theShape.IsNull()) {
2642 di<<argv[cpt];WhoAmI(theShape, di);
2643 if (TheAISContext()->IsDisplayed(theShape) ) {
2644 di<<" Displayed"<<"\n";
2647 di<<" Not Displayed"<<"\n";
2652 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2656 else if (ThereIsCurrent ) {
2657 for (TheAISContext() -> InitCurrent() ;
2658 TheAISContext() -> MoreCurrent() ;
2659 TheAISContext() ->NextCurrent() )
2661 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2662 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2663 if (TheAISContext()->IsDisplayed(theShape) ) {
2664 di<<" Displayed"<<"\n";
2667 di<<" Not Displayed"<<"\n";
2673 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2675 while ( it.More() ) {
2676 Handle(AIS_InteractiveObject) theShape =
2677 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2678 if (!theShape.IsNull()) {
2679 di<<it.Key2().ToCString();
2680 WhoAmI(theShape, di);
2681 if (TheAISContext()->IsDisplayed(theShape) ) {
2682 di<<" Displayed"<<"\n";
2685 di<<" Not Displayed"<<"\n";
2696 //=======================================================================
2697 //function : PickObjects
2699 //=======================================================================
2700 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2701 const AIS_KindOfInteractive TheType,
2702 const Standard_Integer TheSignature,
2703 const Standard_Integer MaxPick)
2705 Handle(AIS_InteractiveObject) IO;
2706 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2708 // step 1: prepare the data
2710 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2711 TheAISContext()->AddFilter(F1);
2714 // step 2 : wait for the selection...
2715 // Standard_Boolean IsGood (Standard_False);
2716 // Standard_Integer NbPick(0);
2717 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2718 Standard_Integer NbPickFail(0);
2719 Standard_Integer argccc = 5;
2720 const char *bufff[] = { "A", "B", "C","D", "E" };
2721 const char **argvvv = (const char **) bufff;
2724 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2725 while(ViewerMainLoop(argccc,argvvv)){}
2726 Standard_Integer NbStored = TheAISContext()->NbSelected();
2727 if((unsigned int ) NbStored != NbPickGood)
2728 NbPickGood= NbStored;
2731 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2734 // step3 get result.
2736 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2738 Standard_Integer i(0);
2739 for(TheAISContext()->InitSelected();
2740 TheAISContext()->MoreSelected();
2741 TheAISContext()->NextSelected()){
2743 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2744 arr->SetValue(i,IO2);
2749 TheAISContext()->CloseLocalContext(curindex);
2751 return Standard_True;
2755 //=======================================================================
2756 //function : PickObject
2758 //=======================================================================
2759 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2760 const Standard_Integer TheSignature,
2761 const Standard_Integer MaxPick)
2763 Handle(AIS_InteractiveObject) IO;
2764 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2766 // step 1: prepare the data
2769 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2770 TheAISContext()->AddFilter(F1);
2773 // step 2 : wait for the selection...
2774 Standard_Boolean IsGood (Standard_False);
2775 Standard_Integer NbPick(0);
2776 Standard_Integer argccc = 5;
2777 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2778 const char **argvvv = (const char **) bufff;
2781 while(!IsGood && NbPick<= MaxPick){
2782 while(ViewerMainLoop(argccc,argvvv)){}
2783 IsGood = (TheAISContext()->NbSelected()>0) ;
2785 cout<<"Nb Pick :"<<NbPick<<endl;
2789 // step3 get result.
2791 TheAISContext()->InitSelected();
2792 IO = TheAISContext()->SelectedInteractive();
2796 TheAISContext()->CloseLocalContext(curindex);
2800 //=======================================================================
2801 //function : PickShape
2802 //purpose : First Activate the rightmode + Put Filters to be able to
2803 // pick objets that are of type <TheType>...
2804 //=======================================================================
2806 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2807 const Standard_Integer MaxPick)
2810 // step 1: prepare the data
2812 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2813 TopoDS_Shape result;
2815 if(TheType==TopAbs_SHAPE){
2816 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2817 TheAISContext()->AddFilter(F1);
2820 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2821 TheAISContext()->AddFilter(TF);
2822 TheAISContext()->ActivateStandardMode(TheType);
2827 // step 2 : wait for the selection...
2828 Standard_Boolean NoShape (Standard_True);
2829 Standard_Integer NbPick(0);
2830 Standard_Integer argccc = 5;
2831 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2832 const char **argvvv = (const char **) bufff;
2835 while(NoShape && NbPick<= MaxPick){
2836 while(ViewerMainLoop(argccc,argvvv)){}
2837 NoShape = (TheAISContext()->NbSelected()==0) ;
2839 cout<<"Nb Pick :"<<NbPick<<endl;
2842 // step3 get result.
2846 TheAISContext()->InitSelected();
2847 if(TheAISContext()->HasSelectedShape())
2848 result = TheAISContext()->SelectedShape();
2850 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2851 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2856 TheAISContext()->CloseLocalContext(curindex);
2862 //=======================================================================
2863 //function : PickShapes
2865 //=======================================================================
2866 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2867 Handle(TopTools_HArray1OfShape)& thearr,
2868 const Standard_Integer MaxPick)
2871 Standard_Integer Taille = thearr->Length();
2873 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2875 // step 1: prepare the data
2876 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2877 if(TheType==TopAbs_SHAPE){
2878 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2879 TheAISContext()->AddFilter(F1);
2882 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2883 TheAISContext()->AddFilter(TF);
2884 TheAISContext()->ActivateStandardMode(TheType);
2888 // step 2 : wait for the selection...
2890 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2891 Standard_Integer NbPickFail(0);
2892 Standard_Integer argccc = 5;
2893 const char *bufff[] = { "A", "B", "C","D", "E" };
2894 const char **argvvv = (const char **) bufff;
2897 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2898 while(ViewerMainLoop(argccc,argvvv)){}
2899 Standard_Integer NbStored = TheAISContext()->NbSelected();
2900 if((unsigned int ) NbStored != NbPickGood)
2901 NbPickGood= NbStored;
2904 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2907 // step3 get result.
2909 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2911 Standard_Integer i(0);
2912 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2914 if(TheAISContext()->HasSelectedShape())
2915 thearr->SetValue(i,TheAISContext()->SelectedShape());
2917 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2918 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2922 TheAISContext()->CloseLocalContext(curindex);
2923 return Standard_True;
2927 //=======================================================================
2928 //function : VPickShape
2930 //=======================================================================
2931 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2933 TopoDS_Shape PickSh;
2934 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2937 theType = TopAbs_SHAPE;
2939 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2940 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2941 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2942 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2943 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2944 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2945 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2948 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2949 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2951 TCollection_AsciiString name;
2954 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2956 PickSh = ViewerTest::PickShape(theType);
2965 if(!PickSh.IsNull()){
2966 nbOfSub[Standard_Integer(theType)]++;
2968 name += nameType[Standard_Integer(theType)];
2969 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2974 // si on avait une petite methode pour voir si la shape
2975 // est deja dans la Double map, ca eviterait de creer....
2976 DBRep::Set(name.ToCString(),PickSh);
2978 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2979 GetMapOfAIS().Bind(newsh, name);
2980 TheAISContext()->Display(newsh);
2981 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2984 // Plusieurs objets a picker, vite vite vite....
2987 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2988 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2989 if(ViewerTest::PickShapes(theType,arr)){
2990 for(Standard_Integer i=1;i<=NbToPick;i++){
2991 PickSh = arr->Value(i);
2992 if(!PickSh.IsNull()){
2994 nbOfSub[Standard_Integer(theType)]++;
2997 name += nameType[Standard_Integer(theType)];
2998 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3006 DBRep::Set(name.ToCString(),PickSh);
3007 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3008 GetMapOfAIS().Bind(newsh, name);
3009 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3010 TheAISContext()->Display(newsh);
3020 //=======================================================================
3021 //function : VPickObject
3022 //purpose : filters can be set (type of Object to pick....
3024 //=======================================================================
3027 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
3029 // preparation de la nomination automatique
3030 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
3031 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
3033 /* TCollection_AsciiString name;
3035 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3037 PickSh = ViewerTest::PickObject(theType);
3046 if(!PickSh.IsNull()){
3047 nbOfSub[Standard_Integer(theType)]++;
3049 name += nameType[Standard_Integer(theType)];
3050 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3055 // si on avait une petite methode pour voir si la shape
3056 // est deja dans la Double map, ca eviterait de creer....
3057 DBRep::Set(name.ToCString(),PickSh);
3059 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3060 GetMapOfAIS().Bind(newsh, name);
3061 TheAISContext()->Display(newsh);
3062 cout<<"Nom de la shape pickee : "<<name<<endl;
3065 // Plusieurs objets a picker, vite vite vite....
3068 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3069 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3070 if(ViewerTest::PickShapes(theType,arr)){
3071 for(Standard_Integer i=1;i<=NbToPick;i++){
3072 PickSh = arr->Value(i);
3073 if(!PickSh.IsNull()){
3075 nbOfSub[Standard_Integer(theType)]++;
3078 name += nameType[Standard_Integer(theType)];
3079 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3087 DBRep::Set(name.ToCString(),PickSh);
3088 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3089 GetMapOfAIS().Bind(newsh, name);
3090 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3091 TheAISContext()->Display(newsh);
3101 //=======================================================================
3102 //function : list of known objects
3104 //=======================================================================
3105 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3107 // 1234567890 12345678901234567 123456789
3108 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3109 TCollection_AsciiString BlankLine(64,'_');
3110 Standard_Integer i ;
3112 di<<"/n"<<BlankLine.ToCString()<<"\n";
3115 Colum[i].Center(20,' ');
3117 di<<"|"<<Colum[i].ToCString();
3120 di<<BlankLine.ToCString()<<"\n";
3122 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3123 const char ** names = GetTypeNames();
3125 TCollection_AsciiString curstring;
3126 TCollection_AsciiString curcolum[3];
3129 // les objets de type Datum..
3130 curcolum[1]+="Datum";
3132 curcolum[0].Clear();
3133 curcolum[0] += names[i];
3135 curcolum[2].Clear();
3136 curcolum[2]+=TCollection_AsciiString(i+1);
3138 for(Standard_Integer j =0;j<=2;j++){
3139 curcolum[j].Center(20,' ');
3140 di<<"|"<<curcolum[j].ToCString();
3144 di<<BlankLine.ToCString()<<"\n";
3146 // les objets de type shape
3147 curcolum[1].Clear();
3148 curcolum[1]+="Shape";
3149 curcolum[1].Center(20,' ');
3152 curcolum[0].Clear();
3153 curcolum[0] += names[7+i];
3154 curcolum[2].Clear();
3155 curcolum[2]+=TCollection_AsciiString(i);
3157 for(Standard_Integer j =0;j<=2;j++){
3158 curcolum[j].Center(20,' ');
3159 di<<"|"<<curcolum[j].ToCString();
3163 di<<BlankLine.ToCString()<<"\n";
3164 // les IO de type objet...
3165 curcolum[1].Clear();
3166 curcolum[1]+="Object";
3167 curcolum[1].Center(20,' ');
3169 curcolum[0].Clear();
3170 curcolum[0] += names[10+i];
3171 curcolum[2].Clear();
3172 curcolum[2]+=TCollection_AsciiString(i);
3174 for(Standard_Integer j =0;j<=2;j++){
3175 curcolum[j].Center(20,' ');
3176 di<<"|"<<curcolum[j].ToCString();
3180 di<<BlankLine.ToCString()<<"\n";
3181 // les contraintes et dimensions.
3182 // pour l'instant on separe juste contraintes et dimensions...
3183 // plus tard, on detaillera toutes les sortes...
3184 curcolum[1].Clear();
3185 curcolum[1]+="Relation";
3186 curcolum[1].Center(20,' ');
3188 curcolum[0].Clear();
3189 curcolum[0] += names[12+i];
3190 curcolum[2].Clear();
3191 curcolum[2]+=TCollection_AsciiString(i);
3193 for(Standard_Integer j =0;j<=2;j++){
3194 curcolum[j].Center(20,' ');
3195 di<<"|"<<curcolum[j].ToCString();
3199 di<<BlankLine.ToCString()<<"\n";
3206 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3208 if(argc!=2) return 1;
3210 AIS_KindOfInteractive TheType;
3211 Standard_Integer TheSign(-1);
3212 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3215 AIS_ListOfInteractive LIO;
3217 // en attendant l'amelioration ais pour les dimensions...
3219 Standard_Integer dimension_status(-1);
3220 if(TheType==AIS_KOI_Relation){
3221 dimension_status = TheSign ==1 ? 1 : 0;
3225 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3226 Handle(AIS_InteractiveObject) curio;
3227 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3230 if(dimension_status == -1)
3231 TheAISContext()->Erase(curio,Standard_False);
3233 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3234 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3235 (dimension_status==1 && KOD != AIS_KOD_NONE))
3236 TheAISContext()->Erase(curio,Standard_False);
3239 TheAISContext()->UpdateCurrentViewer();
3242 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3244 if(argc!=2) return 1;
3246 AIS_KindOfInteractive TheType;
3247 Standard_Integer TheSign(-1);
3248 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3250 // en attendant l'amelioration ais pour les dimensions...
3252 Standard_Integer dimension_status(-1);
3253 if(TheType==AIS_KOI_Relation){
3254 dimension_status = TheSign ==1 ? 1 : 0;
3258 AIS_ListOfInteractive LIO;
3259 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3260 Handle(AIS_InteractiveObject) curio;
3261 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3263 if(dimension_status == -1)
3264 TheAISContext()->Display(curio,Standard_False);
3266 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3267 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3268 (dimension_status==1 && KOD != AIS_KOD_NONE))
3269 TheAISContext()->Display(curio,Standard_False);
3274 TheAISContext()->UpdateCurrentViewer();
3278 //==============================================================================
3279 //function : VSetTransMode
3281 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3282 //==============================================================================
3284 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3285 // Verification des arguments
3286 if ( a3DView().IsNull() ) {
3287 ViewerTest::ViewerInit();
3288 di << "La commande vinit n'a pas ete appele avant" << "\n";
3291 if ( argc < 3 || argc > 8 ) {
3292 di << argv[0] << " Invalid number of arguments" << "\n";
3296 TCollection_AsciiString shapeName;
3297 shapeName = argv[1];
3298 Standard_Integer persFlag1 = atoi(argv[2]);
3299 Standard_Integer persFlag2 = 0;
3300 Standard_Integer persFlag3 = 0;
3301 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3302 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3303 persFlag2 = atoi(argv[3]);
3305 if ( argc == 5 || argc == 8 ) {
3306 persFlag3 = atoi(argv[4]);
3309 origin.SetX( atof(argv[argc - 3]) );
3310 origin.SetY( atof(argv[argc - 2]) );
3311 origin.SetZ( atof(argv[argc - 1]) );
3314 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3315 Handle(Standard_Transient) anObj;
3317 anObj = GetMapOfAIS().Find2(shapeName);
3318 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3319 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3320 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3321 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3322 di << argv[0] << " All persistence modifiers were removed" << "\n";
3325 di << argv[0] << " Wrong object type" << "\n";
3328 } else { // Create the AIS_Shape from a name
3329 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3330 if ( !aShape.IsNull() ) {
3331 GetMapOfAIS().Bind( aShape, shapeName );
3332 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3333 TheAISContext()->Display( aShape, Standard_False );
3335 di << argv[0] << " Object not found" << "\n";
3340 // Upadate the screen and redraw the view
3341 TheAISContext()->UpdateCurrentViewer();
3345 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3348 BRep_Builder builder;
3350 BRepTools::Read(shape, s, builder);
3351 DBRep::Set(a[1], shape);
3352 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3353 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3357 //============================================================================
3358 #include <AIS2D_InteractiveContext.hxx>
3359 #include <HLRAlgo_Projector.hxx>
3360 #include <Prs3d_Projector.hxx>
3361 #include <AIS2D_ProjShape.hxx>
3362 #include <gp_Ax2.hxx>
3364 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3367 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3368 /////////////////////
3369 TopoDS_Shape aShape = DBRep::Get(a[1]);
3370 aContext2D->EraseAll(Standard_True);
3371 //Standard_Integer aPolyAlgo = 0;
3372 Standard_Boolean IsPoly = Standard_False;
3373 gp_Ax2 anAx2 = gp::XOY();
3375 //if(n > 2) aPolyAlgo = atoi(a[2]);
3377 //IsPoly = aPolyAlgo > 0;
3379 TopoDS_Shape aResult = aShape;
3384 Standard_Real x = atof(a[2]);
3385 Standard_Real y = atof(a[3]);
3386 Standard_Real z = atof(a[4]);
3388 Standard_Real dx = atof(a[5]);
3389 Standard_Real dy = atof(a[6]);
3390 Standard_Real dz = atof(a[7]);
3392 Standard_Real dx1 = atof(a[8]);
3393 Standard_Real dy1 = atof(a[9]);
3394 Standard_Real dz1 = atof(a[10]);
3396 gp_Pnt anOrigin (x, y, z);
3397 gp_Dir aNormal (dx, dy, dz);
3398 gp_Dir aDX (dx1, dy1, dz1);
3399 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3403 HLRAlgo_Projector aProjector(anAx2);
3405 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3407 //aProjector = aProjector_t.Projector();
3409 Handle(AIS2D_ProjShape) myDisplayableShape =
3410 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3412 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3413 Standard_False, Standard_True, Standard_False);
3415 myDisplayableShape->Add( aResult );
3418 aContext2D->Display( myDisplayableShape,Standard_True );
3419 aContext2D->UpdateCurrentViewer();
3424 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3427 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3428 /////////////////////
3429 TopoDS_Shape aShape = DBRep::Get(a[1]);
3430 aContext2D->EraseAll(Standard_True);
3431 //Standard_Integer aPolyAlgo = 0;
3432 Standard_Boolean IsPoly = Standard_True;
3433 gp_Ax2 anAx2 = gp::XOY();
3435 //if(n > 2) aPolyAlgo = atoi(a[2]);
3437 //IsPoly = aPolyAlgo > 0;
3439 TopoDS_Shape aResult = aShape;
3444 Standard_Real x = atof(a[2]);
3445 Standard_Real y = atof(a[3]);
3446 Standard_Real z = atof(a[4]);
3448 Standard_Real dx = atof(a[5]);
3449 Standard_Real dy = atof(a[6]);
3450 Standard_Real dz = atof(a[7]);
3452 Standard_Real dx1 = atof(a[8]);
3453 Standard_Real dy1 = atof(a[9]);
3454 Standard_Real dz1 = atof(a[10]);
3456 gp_Pnt anOrigin (x, y, z);
3457 gp_Dir aNormal (dx, dy, dz);
3458 gp_Dir aDX (dx1, dy1, dz1);
3459 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3463 HLRAlgo_Projector aProjector(anAx2);
3465 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3467 //aProjector = aProjector_t.Projector();
3469 Handle(AIS2D_ProjShape) myDisplayableShape =
3470 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3472 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3473 Standard_False, Standard_True, Standard_False);
3475 myDisplayableShape->Add( aResult );
3478 aContext2D->Display( myDisplayableShape,Standard_True );
3479 aContext2D->UpdateCurrentViewer();
3484 //==============================================================================
3485 //function : ViewerTest::Commands
3486 //purpose : Add all the viewer command in the Draw_Interpretor
3487 //==============================================================================
3489 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3491 ViewerTest::ViewerCommands(theCommands);
3492 ViewerTest::RelationCommands(theCommands);
3493 ViewerTest::ObjectCommands(theCommands);
3494 ViewerTest::FilletCommands(theCommands);
3495 ViewerTest::VoxelCommands(theCommands);
3496 ViewerTest::OpenGlCommands(theCommands);
3498 const char *group = "AIS_Display";
3502 theCommands.Add("vdisplay",
3503 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3504 __FILE__,VDisplay2,group);
3506 theCommands.Add("verase",
3507 "verase : verase2 [name1] ... [name n] ",
3508 __FILE__,VErase2,group);
3510 theCommands.Add("vdonly",
3511 "vdonly : vdonly2 [name1] ... [name n]",
3512 __FILE__,VDonly2,group);
3514 theCommands.Add("vdisplayall",
3515 "vdisplayall : vdisplayall",
3516 __FILE__,VDisplayAll,group);
3518 theCommands.Add("veraseall",
3519 "veraseall : veraseall ",
3520 __FILE__,VEraseAll,group);
3522 theCommands.Add("verasetype",
3523 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3524 __FILE__,VEraseType,group);
3526 theCommands.Add("vdisplaytype",
3527 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3528 __FILE__,VDisplayType,group);
3530 theCommands.Add("vdisplaymode",
3531 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3532 __FILE__,VDispMode,group);
3534 theCommands.Add("verasemode",
3535 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3536 __FILE__,VDispMode,group);
3538 theCommands.Add("vsetdispmode",
3539 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3540 __FILE__,VDispMode,group);
3542 theCommands.Add("vunsetdispmode",
3543 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3544 __FILE__,VDispMode,group);
3546 theCommands.Add("vdir",
3548 __FILE__,VDebug,group);
3550 theCommands.Add("vdump",
3551 "<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",
3552 __FILE__,VDump,group);
3554 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3555 __FILE__,VSubInt,group);
3557 theCommands.Add("vsetcolor",
3558 "vsetcolor : vsetcolor [name of shape] ColorName",
3559 __FILE__,VColor2,group);
3561 theCommands.Add("vunsetcolor",
3562 "vunsetcolor : vunsetcolor [name of shape] ",
3563 __FILE__,VColor2,group);
3565 theCommands.Add("vsettransparency",
3566 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3567 __FILE__,VTransparency,group);
3569 theCommands.Add("vunsettransparency",
3570 "vunsettransparency : vtransparency [name of shape]",
3571 __FILE__,VTransparency,group);
3573 theCommands.Add("vsetmaterial",
3574 "vmaterial : vmaterial [name of shape] MaterialName",
3575 __FILE__,VMaterial,group);
3577 theCommands.Add("vunsetmaterial",
3578 "vmaterial : vmaterial [name of shape]",
3579 __FILE__,VMaterial,group);
3581 theCommands.Add("vsetwidth",
3582 "vsetwidth : vwidth [name of shape] width(0->10)",
3583 __FILE__,VWidth,group);
3585 theCommands.Add("vunsetwidth",
3586 "vunsetwidth : vwidth [name of shape]",
3587 __FILE__,VWidth,group);
3589 theCommands.Add("vsetinteriorstyle",
3590 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3591 __FILE__,VInteriorStyle,group);
3593 theCommands.Add("vardis",
3594 "vardis : display activeareas",
3595 __FILE__,VDispAreas,group);
3597 theCommands.Add("varera",
3598 "varera : erase activeareas",
3599 __FILE__,VClearAreas,group);
3601 theCommands.Add("vsensdis",
3602 "vardisp : display active entities",
3603 __FILE__,VDispSensi,group);
3604 theCommands.Add("vsensera",
3605 "vardisp : erase active entities",
3606 __FILE__,VClearSensi,group);
3608 theCommands.Add("vselprecision",
3609 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3610 __FILE__,VSelPrecision,group);
3612 theCommands.Add("vperf",
3613 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3614 __FILE__,VPerf,group);
3616 theCommands.Add("vanimation",
3617 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3618 __FILE__,VAnimation,group);
3620 theCommands.Add("vsetshading",
3621 "vsetshading : vsetshading name Quality(default=0.0008) ",
3622 __FILE__,VShading,group);
3624 theCommands.Add("vunsetshading",
3625 "vunsetshading :vunsetshading name ",
3626 __FILE__,VShading,group);
3628 theCommands.Add("vtexture",
3629 "'vtexture NameOfShape TextureFile' \n \
3630 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3631 or 'vtexture NameOfShape ?' to list available textures\n \
3632 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3633 __FILE__,VTexture,group);
3635 theCommands.Add("vtexscale",