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_InteractiveObject.hxx>
47 #include <AIS_Trihedron.hxx>
48 #include <AIS_Axis.hxx>
49 #include <AIS_Relation.hxx>
50 #include <AIS_TypeFilter.hxx>
51 #include <AIS_SignatureFilter.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Image_PixMap.hxx>
64 #include <Draw_Interpretor.hxx>
65 #include <TCollection_AsciiString.hxx>
66 #include <Draw_PluginMacro.hxx>
67 #include <ViewerTest.hxx>
68 #include <Viewer2dTest.hxx>
70 // avoid warnings on 'extern "C"' functions returning C++ classes
72 #define _CRT_SECURE_NO_DEPRECATE
73 #pragma warning(4:4190)
74 #pragma warning (disable:4996)
77 #include <NIS_InteractiveContext.hxx>
78 #include <NIS_Triangulated.hxx>
79 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
81 //=======================================================================
82 //function : GetColorFromName
83 //purpose : get the Quantity_NameOfColor from a string
84 //=======================================================================
86 #include <Quantity_NameOfColor.hxx>
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
95 static Quantity_NameOfColor GetColorFromName( const char *name )
97 Quantity_NameOfColor ret = DEFAULT_COLOR;
99 Standard_Boolean Found = Standard_False;
100 Standard_CString colstring;
101 for(Standard_Integer i=0;i<=514 && !Found;i++)
103 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
104 if (!strcasecmp(name,colstring)) {
105 ret = (Quantity_NameOfColor)i;
106 Found = Standard_True;
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,"STONE" ) ) mat = Graphic3d_NOM_STONE;
134 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
135 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
136 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
137 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
138 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
139 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
140 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
141 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
146 //=======================================================================
147 //function : GetTypeNames
149 //=======================================================================
150 static const char** GetTypeNames()
152 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
153 "Shape","ConnectedShape","MultiConn.Shape",
154 "ConnectedInter.","MultiConn.",
155 "Constraint","Dimension"};
156 static const char** ThePointer = names;
160 //=======================================================================
161 //function : GetTypeAndSignfromString
163 //=======================================================================
164 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
166 const char ** thefullnames = GetTypeNames();
167 Standard_Integer index(-1);
169 for(Standard_Integer i=0;i<=13 && index==-1;i++)
170 if(!strcasecmp(name,thefullnames[i]))
174 TheType = AIS_KOI_None;
180 TheType = AIS_KOI_Datum;
184 TheType = AIS_KOI_Shape;
188 TheType = AIS_KOI_Object;
192 TheType = AIS_KOI_Relation;
201 #include <Draw_Interpretor.hxx>
203 #include <Draw_Appli.hxx>
207 #include <TCollection_AsciiString.hxx>
208 #include <V3d_Viewer.hxx>
209 #include <V3d_View.hxx>
212 #include <AIS_InteractiveContext.hxx>
213 #include <AIS_Shape.hxx>
214 #include <AIS_TexturedShape.hxx>
215 #include <AIS_DisplayMode.hxx>
216 #include <TColStd_MapOfInteger.hxx>
217 #include <AIS_MapOfInteractive.hxx>
218 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
219 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
220 #include <ViewerTest_EventManager.hxx>
222 #include <TopoDS_Solid.hxx>
223 #include <BRepTools.hxx>
224 #include <BRep_Builder.hxx>
225 #include <TopAbs_ShapeEnum.hxx>
227 #include <TopoDS.hxx>
228 #include <BRep_Tool.hxx>
231 #include <Draw_Window.hxx>
232 #include <AIS_ListIteratorOfListOfInteractive.hxx>
233 #include <AIS_ListOfInteractive.hxx>
234 #include <AIS_DisplayMode.hxx>
235 #include <TopTools_ListOfShape.hxx>
236 #include <BRepOffsetAPI_MakeThickSolid.hxx>
237 #include <BRepOffset.hxx>
240 //==============================================================================
241 //function : GetTypeNameFromShape
242 //purpose : get the shape type as a string from a shape
243 //==============================================================================
245 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
246 { const char *ret = "????";
248 if ( aShape.IsNull() ) ret = "Null Shape";
250 switch ( aShape.ShapeType() ) {
251 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
252 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
253 case TopAbs_SOLID : ret = "SOLID" ; break;
254 case TopAbs_SHELL : ret = "SHELL" ; break;
255 case TopAbs_FACE : ret = "FACE" ; break;
256 case TopAbs_WIRE : ret = "WIRE" ; break;
257 case TopAbs_EDGE : ret = "EDGE" ; break;
258 case TopAbs_VERTEX : ret = "VERTEX" ; break;
259 case TopAbs_SHAPE : ret = "SHAPE" ; break;
263 //==============================================================================
264 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
265 //==============================================================================
266 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
267 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
272 //==============================================================================
273 //function : VDisplayAISObject
274 //purpose : register interactive object in the map of AIS objects;
275 // if other object with such name already registered, it will be kept
276 // or replaced depending on value of <theReplaceIfExists>,
277 // if "true" - the old object will be cleared from AIS context;
278 // returns Standard_True if <theAISObj> registered in map;
279 //==============================================================================
280 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
281 const Handle(AIS_InteractiveObject)& theAISObj,
282 Standard_Boolean theReplaceIfExists = Standard_True)
284 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
285 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
286 if (aContextAIS.IsNull())
288 std::cout << "AIS context is not available.\n";
289 return Standard_False;
292 if (aMap.IsBound2 (theName))
294 if (!theReplaceIfExists)
296 std::cout << "Other interactive object has been already "
297 << "registered with name: " << theName << ".\n"
298 << "Please use another name.\n";
299 return Standard_False;
302 // stop displaying object
303 Handle(AIS_InteractiveObject) anOldObj =
304 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
306 if (!anOldObj.IsNull())
307 aContextAIS->Clear (anOldObj, Standard_True);
309 // remove name and old object from map
310 aMap.UnBind2 (theName);
313 if (theAISObj.IsNull())
315 // object with specified name already unbound
316 return Standard_True;
319 // unbind AIS object if was bound with another name
320 aMap.UnBind1 (theAISObj);
322 // can be registered without rebinding
323 aMap.Bind (theAISObj, theName);
324 aContextAIS->Display (theAISObj, Standard_True);
325 return Standard_True;
328 static TColStd_MapOfInteger theactivatedmodes(8);
329 static TColStd_ListOfTransient theEventMgrs;
331 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
332 const Handle(AIS_InteractiveContext)& Ctx)
334 theEventMgrs.Clear();
335 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
338 static Handle(V3d_View)& a3DView(){
339 static Handle(V3d_View) Viou;
343 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
344 static Handle(AIS_InteractiveContext) aContext;
348 Handle(V3d_View) ViewerTest::CurrentView()
352 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
357 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
359 static Handle(NIS_InteractiveContext) aContext;
360 if (aContext.IsNull()) {
361 aContext = new NIS_InteractiveContext;
362 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
367 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
369 return TheAISContext();
372 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
374 TheAISContext() = aCtx;
375 ViewerTest::ResetEventManager();
378 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
380 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
383 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
385 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
389 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
390 theEventMgrs.Prepend(EM);
393 void ViewerTest::UnsetEventManager()
395 theEventMgrs.RemoveFirst();
399 void ViewerTest::ResetEventManager()
401 const Handle(NIS_View) aView =
402 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
403 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
406 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
408 Handle(ViewerTest_EventManager) EM;
409 if(theEventMgrs.IsEmpty()) return EM;
410 Handle(Standard_Transient) Tr = theEventMgrs.First();
411 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
416 //=======================================================================
417 //function : Get Context and active viou..
419 //=======================================================================
420 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
421 Handle(V3d_View)& Viou)
423 Ctx = ViewerTest::GetAISContext();
426 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
427 Vwr->InitActiveViews();
428 if(Vwr->MoreActiveViews())
429 Viou = Vwr->ActiveView();
434 //==============================================================================
435 //function : GetShapeFromName
436 //purpose : Compute an Shape from a draw variable or a file name
437 //==============================================================================
439 static TopoDS_Shape GetShapeFromName(const char* name)
441 TopoDS_Shape S = DBRep::Get(name);
444 BRep_Builder aBuilder;
445 BRepTools::Read( S, name, aBuilder);
450 //==============================================================================
451 //function : GetShapeFromName
452 //purpose : Compute an Shape from a draw variable or a file name
453 //==============================================================================
456 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
458 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
462 //==============================================================================
463 //function : GetAISShapeFromName
464 //purpose : Compute an AIS_Shape from a draw variable or a file name
465 //==============================================================================
466 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
468 Handle(AIS_Shape) retsh;
470 if(GetMapOfAIS().IsBound2(name)){
471 const Handle(AIS_InteractiveObject) IO =
472 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
474 if(IO->Type()==AIS_KOI_Shape)
475 if(IO->Signature()==0){
476 retsh = *((Handle(AIS_Shape)*)&IO);
479 cout << "an Object which is not an AIS_Shape "
480 "already has this name!!!"<<endl;
486 TopoDS_Shape S = GetShapeFromName(name);
488 retsh = new AIS_Shape(S);
494 //==============================================================================
496 //purpose : Remove all the object from the viewer
497 //==============================================================================
498 void ViewerTest::Clear()
500 if ( !a3DView().IsNull() ) {
501 if (TheAISContext()->HasOpenedContext())
502 TheAISContext()->CloseLocalContext();
503 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
504 while ( it.More() ) {
505 cout << "Remove " << it.Key2() << endl;
506 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
507 const Handle(AIS_InteractiveObject) anObj =
508 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
509 TheAISContext()->Remove(anObj,Standard_False);
510 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
511 const Handle(NIS_InteractiveObject) anObj =
512 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
513 TheNISContext()->Remove(anObj);
517 TheAISContext()->UpdateCurrentViewer();
518 // TheNISContext()->UpdateViews();
519 GetMapOfAIS().Clear();
523 //==============================================================================
524 //function : StandardModesActivation
525 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
527 //==============================================================================
528 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
530 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
532 if (TheAISContext()->HasOpenedContext())
533 aContext->CloseLocalContext();
536 if(!aContext->HasOpenedContext()) {
537 // To unhilight the preselected object
538 aContext->UnhilightCurrents(Standard_False);
539 // Open a local Context in order to be able to select subshape from
540 // the selected shape if any or for all if there is no selection
541 if (!aContext->FirstCurrentObject().IsNull()){
542 aContext->OpenLocalContext(Standard_False);
544 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
545 aContext->Load( aContext->Current(),-1,Standard_True);
549 aContext->OpenLocalContext();
552 const char *cmode="???";
555 case 0: cmode = "Shape"; break;
556 case 1: cmode = "Vertex"; break;
557 case 2: cmode = "Edge"; break;
558 case 3: cmode = "Wire"; break;
559 case 4: cmode = "Face"; break;
560 case 5: cmode = "Shell"; break;
561 case 6: cmode = "Solid"; break;
562 case 7: cmode = "Compound"; break;
565 if(theactivatedmodes.Contains(mode))
567 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
568 theactivatedmodes.Remove(mode);
569 cout<<"Mode "<< cmode <<" OFF"<<endl;
573 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
574 theactivatedmodes.Add(mode);
575 cout<<"Mode "<< cmode << " ON" << endl;
580 //==============================================================================
581 //function : SelectFromContext
582 //purpose : pick / select an object from the last MoveTo() on a
584 //==============================================================================
586 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
588 Standard_Boolean shift,
589 Standard_Boolean pick )
591 Handle(AIS_InteractiveObject) ret;
592 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
599 const Handle(AIS_InteractiveContext) aContext = EM->Context();
601 if ( !aContext->HasOpenedContext() ) {
602 aContext->InitCurrent();
603 while ( aContext->MoreCurrent() ) {
604 Handle(AIS_InteractiveObject) aisPickedShape =
605 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
608 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
609 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
610 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
612 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
613 if(!TheRealSh.IsNull()){
614 cout << "Current is " << name
615 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
618 ret = aisPickedShape;
619 if(!TheRealSh.IsNull()){
620 if ( pick && argc > 4 ) {
621 DBRep::Set(argv[4], TheRealSh->Shape());
624 aContext->NextCurrent();
628 // A LocalContext is opened, the use xxxxSelected()
629 // to select an object and its SubShape
630 aContext->InitSelected();
631 while ( aContext->MoreSelected() ) {
632 if ( !aContext->HasSelectedShape() ) {
635 TopoDS_Shape PickedShape = aContext->SelectedShape();
636 if ( pick && argc > 5 ) {
637 DBRep::Set(argv[5], PickedShape);
641 if ( aContext->Interactive().IsNull() ) {
642 cout << "??? (No InteractiveObject selected)" << endl;
645 Handle(AIS_InteractiveObject) aisPicked =
646 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
648 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
652 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
653 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
654 GetMapOfAIS().Find1(aisPicked).ToCString() :
657 if(!aisPickedShape.IsNull()){
658 if ( pick && argc > 4 ) {
659 // Create a draw variable to store the wohole shape
661 DBRep::Set(argv[4], aisPickedShape->Shape());
664 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
668 // Goto the next selected object
669 aContext->NextSelected();
675 //==============================================================================
676 //function : DetectedFromContext
677 //purpose : hilight dynamicaly an object from the last MoveTo() on a
679 //==============================================================================
680 Handle(AIS_InteractiveObject) DetectedFromContext(
681 Handle(AIS_InteractiveContext) aContext )
683 Handle(AIS_InteractiveObject) ret;
684 if ( aContext->HasDetected() ) {
685 if ( !aContext->HasDetectedShape() ) {
686 //No SubShape selected
689 // Get the detected SubShape
690 TopoDS_Shape PickedShape = aContext->DetectedShape();
692 if ( !aContext->DetectedInteractive().IsNull() ) {
693 Handle(AIS_InteractiveObject) aisPickedShape =
694 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
695 ret = aisPickedShape;
702 //==============================================================================
703 //function : VDispAreas,VDispSensitive,...
704 //purpose : Redraw the view
706 //==============================================================================
707 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
710 Handle(AIS_InteractiveContext) Ctx;
711 Handle(V3d_View) Viou;
712 GetCtxAndView(Ctx,Viou);
713 Ctx->DisplayActiveAreas(Viou);
716 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
718 Handle(AIS_InteractiveContext) Ctx;
719 Handle(V3d_View) Viou;
720 GetCtxAndView(Ctx,Viou);
721 Ctx->ClearActiveAreas(Viou);
725 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
727 Handle(AIS_InteractiveContext) Ctx;
728 Handle(V3d_View) Viou;
729 GetCtxAndView(Ctx,Viou);
730 Ctx->DisplayActiveSensitive(Viou);
734 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
736 Handle(AIS_InteractiveContext) Ctx;
737 Handle(V3d_View) Viou;
738 GetCtxAndView(Ctx,Viou);
739 Ctx->ClearActiveSensitive(Viou);
743 //==============================================================================
745 //purpose : To list the displayed object with their attributes
747 //==============================================================================
748 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
749 { if ( !a3DView().IsNull() ) {
750 di << "List of object in the viewer :" << "\n";
752 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
754 while ( it.More() ) {
755 di << "\t" << it.Key2().ToCString() << "\n";
763 //==============================================================================
764 //function : VSelPrecision
765 //purpose : To set the selection precision mode and tolerance value
766 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
767 // value (integer number of pixel for window mode, double value of
768 // sensitivity for view mode). Without arguments the function just
769 // prints the current precision mode and the corresponding tolerance.
770 //==============================================================================
771 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
775 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
779 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
780 if( aContext.IsNull() )
785 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
786 if( aMode == StdSelect_SM_WINDOW )
788 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
789 di << "Precision mode : 0 (window)\n";
790 di << "Pixel tolerance : " << aPixelTolerance << "\n";
792 else if( aMode == StdSelect_SM_VIEW )
794 Standard_Real aSensitivity = aContext->Sensitivity();
795 di << "Precision mode : 1 (view)\n";
796 di << "Sensitivity : " << aSensitivity << "\n";
801 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
802 aContext->SetSensitivityMode( aMode );
805 if( aMode == StdSelect_SM_WINDOW )
807 Standard_Integer aPixelTolerance = atoi( argv[2] );
808 aContext->SetPixelTolerance( aPixelTolerance );
810 else if( aMode == StdSelect_SM_VIEW )
812 Standard_Real aSensitivity = atof( argv[2] );
813 aContext->SetSensitivity( aSensitivity );
820 //==============================================================================
822 //purpose : To dump the active view snapshot to image file
823 //Draw arg : Picture file name with extension corresponding to desired format
824 //==============================================================================
825 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
829 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
833 Image_TypeOfImage aBufferType = Image_TOI_RGB;
837 TCollection_AsciiString aBuffTypeStr (argv[2]);
838 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
840 aBufferType = Image_TOI_RGB;
842 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
844 aBufferType = Image_TOI_RGBA;
846 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
848 aBufferType = Image_TOI_FLOAT;
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 Handle(Image_PixMap) aPixMap = view->ToPixMap (aWidth, aHeight, aBufferType);
875 if (aPixMap.IsNull())
877 di << "Dumping failed!\n";
881 Image_CRawBufferData aRawBuffer;
882 aPixMap->AccessBuffer (aRawBuffer);
883 if (aRawBuffer.widthPx != aWidth || aRawBuffer.heightPx != aHeight)
885 std::cout << "Warning! Dumped dimensions " << aRawBuffer.widthPx << "x" << aRawBuffer.heightPx
886 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
888 if (!aPixMap->Dump (argv[1]))
890 di << "Saving image failed!\n";
897 //==============================================================================
898 //function : Displays,Erase...
901 //==============================================================================
902 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
903 const Standard_Integer Mode,
904 const Standard_Integer TypeOfOperation,
905 const Standard_Boolean Upd)
907 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
909 switch(TypeOfOperation){
911 Ctx->Display(IO,Mode,Upd);
914 Ctx->Erase(IO,Mode,Upd);
919 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
921 Ctx->SetDisplayMode(IO,Mode,Upd);
926 Ctx->SetDisplayMode(0,Upd);
928 Ctx->UnsetDisplayMode(IO,Upd);
935 //=======================================================================
938 //=======================================================================
939 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
942 TCollection_AsciiString name;
945 // display others presentations
946 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
947 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
948 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
949 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
951 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
953 //unset displaymode.. comportement particulier...
954 if(TypeOfOperation==4){
956 if(Ctx->NbCurrents()==0 ||
957 Ctx->NbSelected()==0){
958 Handle(AIS_InteractiveObject) IO;
959 VwrTst_DispErase(IO,-1,4,Standard_False);
961 else if(!Ctx->HasOpenedContext()){
962 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
963 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
966 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
967 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
968 Ctx->UpdateCurrentViewer();
971 Handle(AIS_InteractiveObject) IO;
973 if(GetMapOfAIS().IsBound2(name)){
974 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
976 VwrTst_DispErase(IO,-1,4,Standard_True);
981 Standard_Integer Dmode = atoi(argv[1]);
982 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
983 Handle(AIS_InteractiveObject) IO;
984 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
986 if(!Ctx->HasOpenedContext()){
987 // set/unset display mode sur le Contexte...
988 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
989 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
991 Ctx->UpdateCurrentViewer();
994 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
995 Ctx->Display(Ctx->Interactive(),Dmode);
999 Handle(AIS_InteractiveObject) IO;
1001 if(GetMapOfAIS().IsBound2(name))
1002 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1004 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
1010 //=======================================================================
1013 //=======================================================================
1014 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1016 if(argc==1) return 1;
1017 Standard_Integer On = atoi(argv[1]);
1018 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1022 if(!Ctx->HasOpenedContext()){
1023 di<<"sub intensite ";
1026 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1027 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1029 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1031 di <<"passage dans off"<<"\n";
1032 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1037 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1039 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1041 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1044 Ctx->UpdateCurrentViewer();
1047 Handle(AIS_InteractiveObject) IO;
1048 TCollection_AsciiString name = argv[2];
1049 if(GetMapOfAIS().IsBound2(name)){
1050 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1053 Ctx->SubIntensityOn(IO);
1055 Ctx->SubIntensityOff(IO);
1063 //==============================================================================
1064 //function : VColor2
1066 //purpose : change the color of a selected or named or displayed shape
1067 //Draw arg : vcolor2 [name] color
1068 //==============================================================================
1069 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1072 Standard_Boolean ThereIsCurrent;
1073 Standard_Boolean ThereIsArgument;
1074 Standard_Boolean IsBound = Standard_False ;
1076 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1078 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1079 ThereIsArgument = (argc != 2);
1082 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1083 ThereIsArgument = (argc == 2);
1086 if ( !a3DView().IsNull() ) {
1087 TCollection_AsciiString name;
1088 if (ThereIsArgument) {
1090 IsBound= GetMapOfAIS().IsBound2(name);
1092 if (TheAISContext()->HasOpenedContext())
1093 TheAISContext()->CloseLocalContext();
1095 // On set le Booleen There is current
1096 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1097 else ThereIsCurrent =Standard_False;
1099 //=======================================================================
1100 // Il y a un argument
1101 //=======================================================================
1102 if ( ThereIsArgument && IsBound ) {
1103 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1104 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1105 Handle(AIS_InteractiveObject) ashape =
1106 Handle(AIS_InteractiveObject)::DownCast (anObj);
1109 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1111 di << "HaveToSet 0\n";
1115 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
1117 TheAISContext()->UnsetColor(ashape);
1118 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1119 Handle(NIS_Triangulated) ashape =
1120 Handle(NIS_Triangulated)::DownCast (anObj);
1121 if (!ashape.IsNull())
1122 ashape->SetColor (GetColorFromName(argv[2]));
1127 //=======================================================================
1128 // Il n'y a pas d'arguments
1129 // Mais un ou plusieurs objets on des current representation
1130 //=======================================================================
1131 if (ThereIsCurrent && !ThereIsArgument) {
1132 for (TheAISContext() -> InitCurrent() ;
1133 TheAISContext() -> MoreCurrent() ;
1134 TheAISContext() ->NextCurrent() )
1136 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1137 if (ashape.IsNull())
1141 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1143 di << "HaveToSet 0\n";
1146 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1148 TheAISContext()->UnsetColor(ashape,Standard_False);
1151 TheAISContext()->UpdateCurrentViewer();
1154 //=======================================================================
1155 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1156 // on impose a tous les objets du viewer la couleur passee
1157 //=======================================================================
1158 else if (!ThereIsCurrent && !ThereIsArgument){
1159 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1160 while ( it.More() ) {
1161 const Handle(AIS_InteractiveObject) ashape =
1162 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1163 if (!ashape.IsNull())
1165 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1167 TheAISContext()->UnsetColor(ashape,Standard_False);
1170 TheAISContext()->UpdateCurrentViewer();
1176 //==============================================================================
1177 //function : VTransparency
1179 //purpose : change the transparency of a selected or named or displayed shape
1180 //Draw arg : vtransparency [name] TransparencyCoeficient
1181 //==============================================================================
1183 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1186 Standard_Boolean ThereIsCurrent;
1187 Standard_Boolean ThereIsArgument;
1188 Standard_Boolean IsBound = Standard_False ;
1190 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1192 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1193 ThereIsArgument = (argc != 2);
1196 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1197 ThereIsArgument = (argc == 2);
1200 if ( !a3DView().IsNull() ) {
1201 TCollection_AsciiString name;
1202 if (ThereIsArgument) {
1204 IsBound= GetMapOfAIS().IsBound2(name);
1206 if (TheAISContext()->HasOpenedContext())
1207 TheAISContext()->CloseLocalContext();
1209 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1210 else ThereIsCurrent = Standard_False;
1212 //=======================================================================
1213 // Il y a des arguments: un nom et une couleur
1214 //=======================================================================
1215 if ( ThereIsArgument && IsBound ) {
1216 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1217 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1218 const Handle(AIS_InteractiveObject) ashape =
1219 Handle(AIS_InteractiveObject)::DownCast(anObj);
1221 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1223 TheAISContext()->UnsetTransparency(ashape);
1224 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1225 const Handle(NIS_InteractiveObject) ashape =
1226 Handle(NIS_InteractiveObject)::DownCast(anObj);
1228 ashape->SetTransparency(atof(argv[2]) );
1230 ashape->UnsetTransparency();
1233 //=======================================================================
1234 // Il n'y a pas d'arguments
1235 // Mais un ou plusieurs objets on des current representation
1236 //=======================================================================
1237 if (ThereIsCurrent && !ThereIsArgument) {
1238 for (TheAISContext() -> InitCurrent() ;
1239 TheAISContext() -> MoreCurrent() ;
1240 TheAISContext() ->NextCurrent() )
1242 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1244 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1246 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1249 TheAISContext()->UpdateCurrentViewer();
1251 //=======================================================================
1252 // Il n'y a pas d'arguments ET aucun objet courrant
1253 //=======================================================================
1254 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1255 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1257 while ( it.More() ) {
1258 Handle(AIS_InteractiveObject) ashape =
1259 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1260 if (!ashape.IsNull())
1262 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1264 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1267 TheAISContext()->UpdateCurrentViewer();
1274 //==============================================================================
1275 //function : VMaterial
1277 //purpose : change the Material of a selected or named or displayed shape
1278 //Draw arg : vmaterial [Name] Material
1279 //==============================================================================
1280 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1283 Standard_Boolean ThereIsCurrent;
1284 Standard_Boolean ThereIsName;
1285 Standard_Boolean IsBound = Standard_False ;
1287 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1289 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1290 ThereIsName = (argc != 2);
1293 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1294 ThereIsName = (argc == 2);
1297 if ( !a3DView().IsNull() ) {
1298 TCollection_AsciiString name;
1301 IsBound= GetMapOfAIS().IsBound2(name);
1303 if (TheAISContext()->HasOpenedContext())
1304 TheAISContext()->CloseLocalContext();
1305 if (TheAISContext() -> NbCurrents() > 0 )
1306 ThereIsCurrent =Standard_True;
1308 ThereIsCurrent =Standard_False;
1310 //=======================================================================
1311 // Ther is a name of shape and a material name
1312 //=======================================================================
1313 if ( ThereIsName && IsBound ) {
1314 Handle(AIS_InteractiveObject) ashape =
1315 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1316 if (!ashape.IsNull())
1318 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1320 TheAISContext()->UnsetMaterial(ashape);
1322 //=======================================================================
1323 // Il n'y a pas de nom de shape
1324 // Mais un ou plusieurs objets on des current representation
1325 //=======================================================================
1326 if (ThereIsCurrent && !ThereIsName) {
1327 for (TheAISContext() -> InitCurrent() ;
1328 TheAISContext() -> MoreCurrent() ;
1329 TheAISContext() ->NextCurrent() )
1331 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1333 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1335 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1337 TheAISContext()->UpdateCurrentViewer();
1340 //=======================================================================
1341 // Il n'y a pas de noms de shape ET aucun objet courrant
1342 // On impose a tous les objets du viewer le material passe en argument
1343 //=======================================================================
1344 else if (!ThereIsCurrent && !ThereIsName){
1345 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1347 while ( it.More() ) {
1348 Handle(AIS_InteractiveObject) ashape =
1349 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1350 if (!ashape.IsNull())
1352 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1354 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1357 TheAISContext()->UpdateCurrentViewer();
1365 //==============================================================================
1368 //purpose : change the width of the edges of a selected or named or displayed shape
1369 //Draw arg : vwidth [Name] WidthValue(1->10)
1370 //==============================================================================
1371 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1374 Standard_Boolean ThereIsCurrent;
1375 Standard_Boolean ThereIsArgument;
1376 Standard_Boolean IsBound = Standard_False ;
1378 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1380 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1381 ThereIsArgument = (argc != 2);
1384 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1385 ThereIsArgument = (argc == 2);
1387 if ( !a3DView().IsNull() ) {
1388 TCollection_AsciiString name;
1389 if (ThereIsArgument) {
1391 IsBound= GetMapOfAIS().IsBound2(name);
1393 if (TheAISContext()->HasOpenedContext())
1394 TheAISContext()->CloseLocalContext();
1396 if (TheAISContext() -> NbCurrents() > 0 )
1397 ThereIsCurrent =Standard_True;
1399 ThereIsCurrent =Standard_False;
1401 if ( ThereIsArgument && IsBound ) {
1402 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1403 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1404 const Handle(AIS_InteractiveObject) ashape =
1405 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1407 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1409 TheAISContext()->UnsetWidth (ashape);
1410 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1411 const Handle(NIS_Triangulated) ashape =
1412 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1413 if (HaveToSet && !ashape.IsNull())
1414 ashape->SetLineWidth ( atof (argv[2]) );
1418 //=======================================================================
1419 // Il n'y a pas d'arguments
1420 // Mais un ou plusieurs objets on des current representation
1421 //=======================================================================
1422 if (ThereIsCurrent && !ThereIsArgument) {
1423 for (TheAISContext() -> InitCurrent() ;
1424 TheAISContext() -> MoreCurrent() ;
1425 TheAISContext() ->NextCurrent() )
1427 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1429 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1431 TheAISContext()->UnsetWidth(ashape,Standard_False);
1433 TheAISContext()->UpdateCurrentViewer();
1435 //=======================================================================
1436 // Il n'y a pas d'arguments ET aucun objet courrant
1437 //=======================================================================
1438 else if (!ThereIsCurrent && !ThereIsArgument){
1439 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1441 while ( it.More() ) {
1442 Handle(AIS_InteractiveObject) ashape =
1443 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1444 if (!ashape.IsNull())
1446 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1448 TheAISContext()->UnsetWidth(ashape,Standard_False);
1451 TheAISContext()->UpdateCurrentViewer();
1456 //==============================================================================
1457 //function : VDonly2
1459 //purpose : Display only a selected or named object
1460 // if there is no selected or named object s, nothing is donne
1461 //Draw arg : vdonly2 [name1] ... [name n]
1462 //==============================================================================
1463 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1466 if ( a3DView().IsNull() )
1469 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1470 Standard_Boolean ThereIsArgument= argc>1;
1472 if (TheAISContext()->HasOpenedContext())
1473 TheAISContext()->CloseLocalContext();
1475 //===============================================================
1476 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1478 //===============================================================
1479 if (!ThereIsArgument && ThereIsCurrent) {
1482 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1485 for(TheAISContext()->InitCurrent();
1486 TheAISContext()->MoreCurrent();
1487 TheAISContext()->NextCurrent()){
1488 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1489 TheAISContext()->Erase(aShape,Standard_False);}
1491 TheAISContext() ->UpdateCurrentViewer();
1492 //===============================================================
1493 // Il y a des arguments
1494 //===============================================================
1495 if (ThereIsArgument) {
1496 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1498 while ( it.More() ) {
1499 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1500 const Handle(AIS_InteractiveObject) aShape =
1501 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1502 TheAISContext()->Erase(aShape,Standard_False);
1503 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1504 const Handle(NIS_InteractiveObject) aShape =
1505 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1506 TheNISContext()->Erase(aShape);
1511 // On display les objets passes par parametre
1512 for (int i=1; i<argc ; i++) {
1513 TCollection_AsciiString name=argv[i];
1514 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1516 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1517 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1518 const Handle(AIS_InteractiveObject) aShape =
1519 Handle(AIS_InteractiveObject)::DownCast (anObj);
1520 TheAISContext()->Display(aShape, Standard_False);
1521 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1522 Handle(NIS_InteractiveObject) aShape =
1523 Handle(NIS_InteractiveObject)::DownCast (anObj);
1524 TheNISContext()->Display(aShape);
1528 TheAISContext() ->UpdateCurrentViewer();
1529 // TheNISContext() ->UpdateViews();
1534 //==============================================================================
1535 //function : VErase2
1537 //purpose : Erase some selected or named objects
1538 // if there is no selected or named objects, the whole viewer is erased
1539 //Draw arg : verase2 [name1] ... [name n]
1540 //==============================================================================
1541 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1544 if ( a3DView().IsNull() )
1547 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1548 Standard_Boolean ThereIsArgument= argc>1;
1549 if(TheAISContext()->HasOpenedContext())
1550 TheAISContext()->CloseLocalContext();
1552 //===============================================================
1553 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1555 //===============================================================
1556 if (!ThereIsArgument && ThereIsCurrent) {
1557 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1559 while ( it.More() ) {
1560 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1561 const Handle(AIS_InteractiveObject) aShape =
1562 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1563 if (TheAISContext()->IsCurrent(aShape))
1564 TheAISContext()->Erase(aShape,Standard_False);
1569 TheAISContext() ->UpdateCurrentViewer();
1572 //===============================================================
1573 // Il n'y a pas d'arguments et aucuns objets selectionnes
1575 // On erase tout le viewer
1576 //===============================================================
1578 if (!ThereIsArgument && !ThereIsCurrent) {
1579 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1580 while ( it.More() ) {
1581 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1582 const Handle(AIS_InteractiveObject) aShape =
1583 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1584 TheAISContext()->Erase(aShape,Standard_False);
1585 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1586 const Handle(NIS_InteractiveObject) aShape =
1587 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1588 TheNISContext()->Erase(aShape);
1592 TheAISContext() ->UpdateCurrentViewer();
1593 // TheNISContext()->UpdateViews();
1596 //===============================================================
1597 // Il y a des arguments
1598 //===============================================================
1599 if (ThereIsArgument) {
1600 for (int i=1; i<argc ; i++) {
1601 TCollection_AsciiString name=argv[i];
1602 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1604 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1605 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1606 const Handle(AIS_InteractiveObject) aShape =
1607 Handle(AIS_InteractiveObject)::DownCast (anObj);
1608 TheAISContext()->Erase(aShape,Standard_False);
1609 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1610 const Handle(NIS_InteractiveObject) aShape =
1611 Handle(NIS_InteractiveObject)::DownCast (anObj);
1612 TheNISContext()->Erase(aShape);
1616 TheAISContext() ->UpdateCurrentViewer();
1617 // TheNISContext() ->UpdateViews();
1622 //==============================================================================
1623 //function : VEraseAll
1625 //purpose : Erase all the objects displayed in the viewer
1626 //Draw arg : veraseall
1627 //==============================================================================
1628 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1631 // Verification des arguments
1632 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1633 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1634 TheAISContext()->CloseAllContexts(Standard_False);
1635 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1637 while ( it.More() ) {
1638 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1639 const Handle(AIS_InteractiveObject) aShape =
1640 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1641 TheAISContext()->Erase(aShape,Standard_False);
1642 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1643 const Handle(NIS_InteractiveObject) aShape =
1644 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1645 TheNISContext()->Erase(aShape);
1649 TheAISContext() ->UpdateCurrentViewer();
1650 // TheNISContext() ->UpdateViews();
1655 //==============================================================================
1656 //function : VDisplayAll
1658 //purpose : Display all the objects of the Map
1659 //Draw arg : vdisplayall
1660 //==============================================================================
1661 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1664 if (! a3DView().IsNull() ) {
1665 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1666 if (TheAISContext()->HasOpenedContext())
1667 TheAISContext()->CloseLocalContext();
1668 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1670 while ( it.More() ) {
1671 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1672 const Handle(AIS_InteractiveObject) aShape =
1673 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1674 TheAISContext()->Erase(aShape,Standard_False);
1675 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1676 const Handle(NIS_InteractiveObject) aShape =
1677 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1678 TheNISContext()->Erase(aShape);
1683 while ( it.More() ) {
1684 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1685 const Handle(AIS_InteractiveObject) aShape =
1686 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1687 TheAISContext()->Display(aShape, Standard_False);
1688 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1689 Handle(NIS_InteractiveObject) aShape =
1690 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1691 TheNISContext()->Display(aShape);
1695 TheAISContext() ->UpdateCurrentViewer();
1696 // TheNISContext() ->UpdateViews();
1702 //#######################################################################################################
1705 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1707 static Standard_Boolean IsDefined=Standard_False ;
1708 static TCollection_AsciiString VarName;
1710 const char *envir, *casroot ;
1711 envir = getenv("CSF_MDTVTexturesDirectory") ;
1713 Standard_Boolean HasDefinition = Standard_False ;
1715 casroot = getenv("CASROOT");
1717 VarName = TCollection_AsciiString (casroot);
1718 VarName += "/src/Textures" ;
1719 HasDefinition = Standard_True ;
1722 VarName = TCollection_AsciiString (envir);
1723 HasDefinition = Standard_True ;
1725 if ( HasDefinition ) {
1726 OSD_Path aPath ( VarName );
1727 OSD_Directory aDir(aPath);
1728 if ( aDir.Exists () ) {
1729 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1730 OSD_File TextureFile ( aTexture );
1731 if ( !TextureFile.Exists() ) {
1732 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1733 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1734 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1737 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1738 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1739 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1743 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1744 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1745 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1747 IsDefined = Standard_True ;
1753 //#######################################################################################################
1756 //#######################################################################################################
1760 //#######################################################################################################
1762 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1764 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1765 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1766 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1767 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1768 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1770 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1771 if(myAISContext.IsNull())
1773 di << "use 'vinit' command before " << argv[0] << "\n";
1777 Handle(AIS_InteractiveObject) TheAisIO;
1778 Handle(AIS_TexturedShape) myShape;
1779 Standard_Integer myPreviousMode = 0;
1781 if (argc<2 || !argv[1])
1783 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1787 TCollection_AsciiString name = argv[1];
1788 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1790 if (GetMapOfAIS().IsBound2(name))
1791 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1792 (GetMapOfAIS().Find2(name));
1793 if (TheAisIO.IsNull())
1795 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1799 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1801 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1802 myPreviousMode = myShape->DisplayMode() ;
1806 myAISContext->Clear(TheAisIO,Standard_False);
1807 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1808 GetMapOfAIS().UnBind1(TheAisIO);
1809 GetMapOfAIS().UnBind2(name);
1810 GetMapOfAIS().Bind(myShape, name);
1814 case 1: // vtexture : we only map a texture on the shape
1817 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1820 if (argc>2 && argv[2])
1822 if(strcasecmp(argv[2],"?")==0)
1824 TCollection_AsciiString monPath = GetEnvir (di) ;
1826 di<<"\n Files in current directory : \n"<<"\n";
1827 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1828 di.Eval(Cmnd.ToCString());
1830 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1833 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1834 di.Eval(Cmnd.ToCString());
1839 myShape->SetTextureFileName(argv[2]);
1843 di <<"Texture mapping disabled \n \
1844 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1846 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1847 if (myPreviousMode == 3 )
1848 myAISContext->RecomputePrsOnly(myShape);
1849 myAISContext->Display(myShape, Standard_True);
1854 case 2: // vtexscale : we change the scaling factor of the texture
1858 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1862 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1863 ( argv[2] ? atof(argv[2]) : 1.0 ),
1864 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1867 case 3: // vtexorigin : we change the origin of the texture on the shape
1870 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1873 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1874 ( argv[2] ? atof(argv[2]) : 0.0 ),
1875 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1878 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1881 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1884 if (argc>2 && argv[2])
1886 di <<"Texture repeat enabled"<<"\n";
1887 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1891 di <<"Texture repeat disabled"<<"\n";
1892 myShape->SetTextureRepeat(Standard_False);
1896 case 5: // vtexdefault : default texture mapping
1897 // ScaleU = ScaleV = 100.0
1898 // URepeat = VRepeat = 1.0
1899 // Uorigin = VOrigin = 0.0
1903 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1906 myShape->SetTextureRepeat(Standard_False);
1907 myShape->SetTextureOrigin(Standard_False);
1908 myShape->SetTextureScale (Standard_False);
1912 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1913 myAISContext->RecomputePrsOnly(myShape);
1916 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1917 myAISContext->Display(myShape, Standard_True);
1918 myAISContext->Update(myShape,Standard_True);
1923 //==============================================================================
1924 //function : VDisplay2
1926 //purpose : Display an object from its name
1927 //Draw arg : vdisplay name1 [name2] ... [name n]
1928 //==============================================================================
1929 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1932 // Verification des arguments
1933 if ( a3DView().IsNull() ) {
1935 ViewerTest::ViewerInit();
1936 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1941 di<<argv[0]<<" Syntaxe error"<<"\n";
1946 TCollection_AsciiString name;
1947 if (TheAISContext()->HasOpenedContext())
1948 TheAISContext()->CloseLocalContext();
1950 for ( int i = 1; i < argc; i++ ) {
1952 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1953 Standard_Boolean IsDatum = Standard_False;
1954 Handle(Standard_Transient) anObj;
1956 anObj = GetMapOfAIS().Find2(name);
1957 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1958 Handle(AIS_InteractiveObject) aShape =
1959 Handle(AIS_InteractiveObject)::DownCast(anObj);
1960 if (aShape->Type()==AIS_KOI_Datum) {
1961 IsDatum = Standard_True;
1962 TheAISContext()->Display(aShape, Standard_False);
1965 di << "Display " << name.ToCString() << "\n";
1966 // Get the Shape from a name
1967 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1969 // Update the Shape in the AIS_Shape
1970 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1971 if(!TheRealSh.IsNull())
1972 TheRealSh->Set(NewShape);
1973 TheAISContext()->Redisplay(aShape, Standard_False);
1974 TheAISContext()->Display(aShape, Standard_False);
1977 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1978 Handle(NIS_InteractiveObject) aShape =
1979 Handle(NIS_InteractiveObject)::DownCast(anObj);
1980 TheNISContext()->Display(aShape);
1983 else { // Create the AIS_Shape from a name
1984 const Handle(AIS_InteractiveObject) aShape =
1985 GetAISShapeFromName((const char *)name.ToCString());
1986 if ( !aShape.IsNull() ) {
1987 GetMapOfAIS().Bind(aShape, name);
1988 TheAISContext()->Display(aShape, Standard_False);
1992 // Upadate the screen and redraw the view
1993 TheAISContext()->UpdateCurrentViewer();
1994 // TheNISContext()->UpdateViews();
1998 //==============================================================================
2000 //purpose : Test the annimation of an object along a
2001 // predifined trajectory
2002 //Draw arg : vmove ShapeName
2003 //==============================================================================
2006 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2011 if (TheAISContext()->HasOpenedContext())
2012 TheAISContext()->CloseLocalContext();
2014 Standard_Real Step=2*M_PI/180;
2015 Standard_Real Angle=0;
2016 // R est le rayon de l'hellicoide
2018 // D est la distance parcourue en translation en 1 tour
2021 Handle(AIS_InteractiveObject) aIO;
2023 if (GetMapOfAIS().IsBound2(argv[1]))
2024 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2027 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
2030 TheAISContext()->Deactivate(aIO);
2032 // boucle generant le mouvement
2034 di<<" Transformations"<<"\n";
2035 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2038 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) );
2040 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
2041 TheAISContext()->SetLocation(aIO,myTransfo);
2043 TheAISContext() ->UpdateCurrentViewer();
2048 di<<" Locations"<<"\n";
2049 gp_Trsf myAngleTrsf;
2050 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2051 TopLoc_Location myDeltaAngle (myAngleTrsf);
2053 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
2054 TopLoc_Location myDeltaDist (myDistTrsf);
2055 TopLoc_Location myTrueLoc;
2057 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2060 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2061 TheAISContext()->SetLocation(aIO,myTrueLoc );
2062 TheAISContext() ->UpdateCurrentViewer();
2067 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2069 //TopLoc_Location Tempo=aIO->Location();
2070 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2071 //ShapeBis.Located(Tempo);
2074 // On reset la location (origine) contenue dans l'AISInteractiveObject
2075 TheAISContext() ->ResetLocation(aIO);
2077 // On force aShape a devenir l'AIS IO propre a ShapeBis
2079 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2080 // ->Set() est une methode de AIS_Shape
2081 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2083 // On donne a ShapeBis le nom de l'AIS IO
2084 //Rep::Set(argv[1],ShapeBis);
2087 TheAISContext()->Redisplay(aIO,Standard_False);
2089 // On reactive la selection des primitives sensibles
2090 TheAISContext()->Activate(aIO,0);
2092 TheAISContext() ->UpdateCurrentViewer();
2093 a3DView() -> Redraw();
2096 di<<" Temps ecoule "<<"\n";
2104 //==============================================================================
2106 //purpose : Test the annimation of an object along a
2107 // predifined trajectory
2108 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2109 //==============================================================================
2111 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2114 if (TheAISContext()->HasOpenedContext())
2115 TheAISContext()->CloseLocalContext();
2117 Standard_Real Step=4*M_PI/180;
2118 Standard_Real Angle=0;
2120 Handle(AIS_InteractiveObject) aIO;
2121 if (GetMapOfAIS().IsBound2(argv[1]))
2122 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2126 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2130 if (atoi(argv[3])==1 ) {
2131 di<<" Primitives sensibles OFF"<<"\n";
2132 TheAISContext()->Deactivate(aIO);
2135 di<<" Primitives sensibles ON"<<"\n";
2137 // Movement par transformation
2138 if(atoi(argv[2]) ==1) {
2139 di<<" Calcul par Transformation"<<"\n";
2140 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2144 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2145 TheAISContext()->SetLocation(aShape,myTransfo);
2146 TheAISContext() ->UpdateCurrentViewer();
2151 di<<" Calcul par Locations"<<"\n";
2152 gp_Trsf myAngleTrsf;
2153 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2154 TopLoc_Location myDeltaAngle (myAngleTrsf);
2155 TopLoc_Location myTrueLoc;
2157 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2160 myTrueLoc=myTrueLoc*myDeltaAngle;
2161 TheAISContext()->SetLocation(aShape,myTrueLoc );
2162 TheAISContext() ->UpdateCurrentViewer();
2165 if (atoi(argv[3])==1 ){
2166 // On reactive la selection des primitives sensibles
2167 TheAISContext()->Activate(aIO,0);
2169 a3DView() -> Redraw();
2171 di<<" Temps ecoule "<<"\n";
2177 //==================================================================================
2178 // Function : VAnimation
2179 //==================================================================================
2180 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2182 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2186 Standard_Real thread = 4;
2187 Standard_Real angleA=0;
2188 Standard_Real angleB;
2190 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2193 TopoDS_Shape CrankArm;
2194 TopoDS_Shape CylinderHead;
2195 TopoDS_Shape Propeller;
2196 TopoDS_Shape EngineBlock;
2198 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2199 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2200 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2201 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2202 BRepTools::Read(CrankArm,argv[1],B);
2203 BRepTools::Read(CylinderHead,argv[2],B);
2204 BRepTools::Read(Propeller,argv[3],B);
2205 BRepTools::Read(EngineBlock,argv[4],B);
2207 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2213 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2214 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2215 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2216 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2218 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2219 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2220 GetMapOfAIS().Bind(myAisCrankArm,"c");
2221 GetMapOfAIS().Bind(myAisPropeller,"d");
2223 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2224 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2225 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2227 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2228 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2229 TheAISContext()->Display(myAisCrankArm,Standard_False );
2230 TheAISContext()->Display(myAisPropeller,Standard_False);
2232 TheAISContext()->Deactivate(myAisCylinderHead);
2233 TheAISContext()->Deactivate(myAisEngineBlock );
2234 TheAISContext()->Deactivate(myAisCrankArm );
2235 TheAISContext()->Deactivate(myAisPropeller );
2237 // Boucle de mouvement
2238 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2240 angleA = thread*myAngle*M_PI/180;
2241 X = Sin(angleA)*3/8;
2242 angleB = atan(X / Sqrt(-X * X + 1));
2243 Standard_Real decal(25*0.6);
2246 //Build a transformation on the display
2247 gp_Trsf aPropellerTrsf;
2248 aPropellerTrsf.SetRotation(Ax1,angleA);
2249 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2251 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));
2252 gp_Trsf aCrankArmTrsf;
2253 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2254 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2256 TheAISContext()->UpdateCurrentViewer();
2259 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2260 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2262 myAisCrankArm ->ResetLocation();
2263 myAisPropeller->ResetLocation();
2265 myAisCrankArm -> Set(myNewCrankArm );
2266 myAisPropeller -> Set(myNewPropeller);
2268 TheAISContext()->Activate(myAisCylinderHead,0);
2269 TheAISContext()->Activate(myAisEngineBlock,0 );
2270 TheAISContext()->Activate(myAisCrankArm ,0 );
2271 TheAISContext()->Activate(myAisPropeller ,0 );
2277 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2278 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2280 TheAISContext()->UpdateCurrentViewer();
2281 a3DView()->Redraw();
2290 //==============================================================================
2291 //function : VShading
2292 //purpose : Sharpen or roughten the quality of the shading
2293 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2294 //==============================================================================
2295 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2297 Standard_Real myDevCoef;
2298 Handle(AIS_InteractiveObject) TheAisIO;
2301 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2303 if (TheAISContext()->HasOpenedContext())
2304 TheAISContext()->CloseLocalContext();
2309 myDevCoef =atof(argv[2]);
2312 TCollection_AsciiString name=argv[1];
2313 if (GetMapOfAIS().IsBound2(name ))
2314 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2315 if (TheAisIO.IsNull())
2316 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2319 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2321 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2323 TheAISContext()->Redisplay(TheAisIO);
2326 //==============================================================================
2327 //function : HaveMode
2328 //use : VActivatedModes
2329 //==============================================================================
2330 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2332 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2334 TColStd_ListOfInteger List;
2335 TheAISContext()->ActivatedModes (TheAisIO,List);
2336 TColStd_ListIteratorOfListOfInteger it;
2337 Standard_Boolean Found=Standard_False;
2338 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2339 if (it.Value()==mode ) Found=Standard_True;
2346 //==============================================================================
2347 //function : VActivatedMode
2349 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2350 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2351 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2352 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2353 // qu'un nom et qu'un mode.
2354 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2355 //==============================================================================
2356 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2358 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2361 Standard_Boolean ThereIsName = Standard_False ;
2363 if(!a3DView().IsNull()){
2365 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2366 // verification des arguments
2368 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2369 ThereIsName = (argc == 3);
2373 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2375 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2376 di<<" Fermeture du Context local"<<"\n";
2377 if (TheAISContext()->HasOpenedContext())
2378 TheAISContext()->CloseLocalContext();
2382 // IL n'y a aps de nom de shape passe en argument
2383 if (HaveToSet && !ThereIsName){
2384 Standard_Integer aMode=atoi(argv [1]);
2386 const char *cmode="???";
2388 case 0: cmode = "Shape"; break;
2389 case 1: cmode = "Vertex"; break;
2390 case 2: cmode = "Edge"; break;
2391 case 3: cmode = "Wire"; break;
2392 case 4: cmode = "Face"; break;
2393 case 5: cmode = "Shell"; break;
2394 case 6: cmode = "Solid"; break;
2395 case 7: cmode = "Compound"; break;
2398 if( !TheAISContext()->HasOpenedContext() ) {
2399 // il n'y a pas de Context local d'ouvert
2400 // on en ouvre un et on charge toutes les shapes displayees
2401 // on load tous les objets displayees et on Activate les objets de la liste
2402 AIS_ListOfInteractive ListOfIO;
2403 // on sauve dans une AISListOfInteractive tous les objets currents
2404 if (TheAISContext()->NbCurrents()>0 ){
2405 TheAISContext()->UnhilightCurrents(Standard_False);
2407 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2408 ListOfIO.Append(TheAISContext()->Current() );
2412 TheAISContext()->OpenLocalContext(Standard_False);
2413 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2416 Handle(AIS_InteractiveObject) aIO =
2417 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2419 TheAISContext()->Load(aIO,0,Standard_False);
2422 // traitement des objets qui etaient currents dans le Contexte global
2423 if (!ListOfIO.IsEmpty() ) {
2424 // il y avait des objets currents
2425 AIS_ListIteratorOfListOfInteractive iter;
2426 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2427 Handle(AIS_InteractiveObject) aIO=iter.Value();
2428 TheAISContext()->Activate(aIO,aMode);
2429 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2433 // On applique le mode a tous les objets displayes
2434 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2435 it2 (GetMapOfAIS());
2437 Handle(AIS_InteractiveObject) aIO =
2438 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2439 if (!aIO.IsNull()) {
2440 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2441 TheAISContext()->Activate(aIO,aMode);
2450 // un Context local est deja ouvert
2451 // Traitement des objets du Context local
2452 if (TheAISContext()->NbSelected()>0 ){
2453 TheAISContext()->UnhilightSelected(Standard_False);
2454 // il y a des objets selected,on les parcourt
2455 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2456 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2459 if (HaveMode(aIO,aMode) ) {
2460 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2461 TheAISContext()->Deactivate(aIO,aMode);
2464 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2465 TheAISContext()->Activate(aIO,aMode);
2471 // il n'y a pas d'objets selected
2472 // tous les objets diplayes sont traites
2473 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2476 Handle(AIS_InteractiveObject) aIO =
2477 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2478 if (!aIO.IsNull()) {
2479 if (HaveMode(aIO,aMode) ) {
2480 di<<" Mode: "<<cmode<<" OFF pour "
2481 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2482 TheAISContext()->Deactivate(aIO,aMode);
2485 di<<" Mode: "<<cmode<<" ON pour"
2486 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2487 TheAISContext()->Activate(aIO,aMode);
2495 else if (HaveToSet && ThereIsName){
2496 Standard_Integer aMode=atoi(argv [2]);
2497 Handle(AIS_InteractiveObject) aIO =
2498 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2500 if (!aIO.IsNull()) {
2501 const char *cmode="???";
2504 case 0: cmode = "Shape"; break;
2505 case 1: cmode = "Vertex"; break;
2506 case 2: cmode = "Edge"; break;
2507 case 3: cmode = "Wire"; break;
2508 case 4: cmode = "Face"; break;
2509 case 5: cmode = "Shell"; break;
2510 case 6: cmode = "Solid"; break;
2511 case 7: cmode = "Compound"; break;
2514 if( !TheAISContext()->HasOpenedContext() ) {
2515 TheAISContext()->OpenLocalContext(Standard_False);
2516 // On charge tous les objets de la map
2517 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2519 Handle(AIS_InteractiveObject) aShape=
2520 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2521 if (!aShape.IsNull())
2522 TheAISContext()->Load(aShape,0,Standard_False);
2525 TheAISContext()->Activate(aIO,aMode);
2526 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2530 // un Context local est deja ouvert
2531 if (HaveMode(aIO,aMode) ) {
2532 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2533 TheAISContext()->Deactivate(aIO,aMode);
2536 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2537 TheAISContext()->Activate(aIO,aMode);
2549 //==============================================================================
2550 // function : WhoAmI
2552 //==============================================================================
2553 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2556 if (theShape->Type()==AIS_KOI_Datum) {
2557 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2558 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2559 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2560 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2561 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2562 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2563 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2566 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2567 // AIS_Dimentions et AIS_Relations
2568 else if (theShape->Type()==AIS_KOI_Relation) {
2569 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2571 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2572 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2573 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2574 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2575 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2576 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2577 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2578 // AIS no repertorie.
2579 else {di<<" Type Unknown.";}
2585 //==============================================================================
2588 //Draw arg : vstate [nameA] ... [nameN]
2589 //==============================================================================
2590 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2592 TheAISContext()->CloseAllContexts();
2593 const Standard_Boolean ThereIsArguments=(argc>=2);
2594 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2596 // ==================
2597 // Il y a un argument
2598 // ==================
2599 if (ThereIsArguments) {
2600 for (int cpt=1;cpt<argc;cpt++) {
2601 // Verification que lq piece est bien bindee.
2602 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2603 const Handle(AIS_InteractiveObject) theShape=
2604 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2606 if (!theShape.IsNull()) {
2607 di<<argv[cpt];WhoAmI(theShape, di);
2608 if (TheAISContext()->IsDisplayed(theShape) ) {
2609 di<<" Displayed"<<"\n";
2612 di<<" Not Displayed"<<"\n";
2617 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2621 else if (ThereIsCurrent ) {
2622 for (TheAISContext() -> InitCurrent() ;
2623 TheAISContext() -> MoreCurrent() ;
2624 TheAISContext() ->NextCurrent() )
2626 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2627 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2628 if (TheAISContext()->IsDisplayed(theShape) ) {
2629 di<<" Displayed"<<"\n";
2632 di<<" Not Displayed"<<"\n";
2638 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2640 while ( it.More() ) {
2641 Handle(AIS_InteractiveObject) theShape =
2642 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2643 if (!theShape.IsNull()) {
2644 di<<it.Key2().ToCString();
2645 WhoAmI(theShape, di);
2646 if (TheAISContext()->IsDisplayed(theShape) ) {
2647 di<<" Displayed"<<"\n";
2650 di<<" Not Displayed"<<"\n";
2661 //=======================================================================
2662 //function : PickObjects
2664 //=======================================================================
2665 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2666 const AIS_KindOfInteractive TheType,
2667 const Standard_Integer TheSignature,
2668 const Standard_Integer MaxPick)
2670 Handle(AIS_InteractiveObject) IO;
2671 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2673 // step 1: prepare the data
2675 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2676 TheAISContext()->AddFilter(F1);
2679 // step 2 : wait for the selection...
2680 // Standard_Boolean IsGood (Standard_False);
2681 // Standard_Integer NbPick(0);
2682 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2683 Standard_Integer NbPickFail(0);
2684 Standard_Integer argccc = 5;
2685 const char *bufff[] = { "A", "B", "C","D", "E" };
2686 const char **argvvv = (const char **) bufff;
2689 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2690 while(ViewerMainLoop(argccc,argvvv)){}
2691 Standard_Integer NbStored = TheAISContext()->NbSelected();
2692 if((unsigned int ) NbStored != NbPickGood)
2693 NbPickGood= NbStored;
2696 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2699 // step3 get result.
2701 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2703 Standard_Integer i(0);
2704 for(TheAISContext()->InitSelected();
2705 TheAISContext()->MoreSelected();
2706 TheAISContext()->NextSelected()){
2708 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2709 arr->SetValue(i,IO2);
2714 TheAISContext()->CloseLocalContext(curindex);
2716 return Standard_True;
2720 //=======================================================================
2721 //function : PickObject
2723 //=======================================================================
2724 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2725 const Standard_Integer TheSignature,
2726 const Standard_Integer MaxPick)
2728 Handle(AIS_InteractiveObject) IO;
2729 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2731 // step 1: prepare the data
2734 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2735 TheAISContext()->AddFilter(F1);
2738 // step 2 : wait for the selection...
2739 Standard_Boolean IsGood (Standard_False);
2740 Standard_Integer NbPick(0);
2741 Standard_Integer argccc = 5;
2742 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2743 const char **argvvv = (const char **) bufff;
2746 while(!IsGood && NbPick<= MaxPick){
2747 while(ViewerMainLoop(argccc,argvvv)){}
2748 IsGood = (TheAISContext()->NbSelected()>0) ;
2750 cout<<"Nb Pick :"<<NbPick<<endl;
2754 // step3 get result.
2756 TheAISContext()->InitSelected();
2757 IO = TheAISContext()->SelectedInteractive();
2761 TheAISContext()->CloseLocalContext(curindex);
2765 //=======================================================================
2766 //function : PickShape
2767 //purpose : First Activate the rightmode + Put Filters to be able to
2768 // pick objets that are of type <TheType>...
2769 //=======================================================================
2771 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2772 const Standard_Integer MaxPick)
2775 // step 1: prepare the data
2777 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2778 TopoDS_Shape result;
2780 if(TheType==TopAbs_SHAPE){
2781 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2782 TheAISContext()->AddFilter(F1);
2785 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2786 TheAISContext()->AddFilter(TF);
2787 TheAISContext()->ActivateStandardMode(TheType);
2792 // step 2 : wait for the selection...
2793 Standard_Boolean NoShape (Standard_True);
2794 Standard_Integer NbPick(0);
2795 Standard_Integer argccc = 5;
2796 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2797 const char **argvvv = (const char **) bufff;
2800 while(NoShape && NbPick<= MaxPick){
2801 while(ViewerMainLoop(argccc,argvvv)){}
2802 NoShape = (TheAISContext()->NbSelected()==0) ;
2804 cout<<"Nb Pick :"<<NbPick<<endl;
2807 // step3 get result.
2811 TheAISContext()->InitSelected();
2812 if(TheAISContext()->HasSelectedShape())
2813 result = TheAISContext()->SelectedShape();
2815 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2816 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2821 TheAISContext()->CloseLocalContext(curindex);
2827 //=======================================================================
2828 //function : PickShapes
2830 //=======================================================================
2831 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2832 Handle(TopTools_HArray1OfShape)& thearr,
2833 const Standard_Integer MaxPick)
2836 Standard_Integer Taille = thearr->Length();
2838 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2840 // step 1: prepare the data
2841 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2842 if(TheType==TopAbs_SHAPE){
2843 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2844 TheAISContext()->AddFilter(F1);
2847 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2848 TheAISContext()->AddFilter(TF);
2849 TheAISContext()->ActivateStandardMode(TheType);
2853 // step 2 : wait for the selection...
2855 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2856 Standard_Integer NbPickFail(0);
2857 Standard_Integer argccc = 5;
2858 const char *bufff[] = { "A", "B", "C","D", "E" };
2859 const char **argvvv = (const char **) bufff;
2862 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2863 while(ViewerMainLoop(argccc,argvvv)){}
2864 Standard_Integer NbStored = TheAISContext()->NbSelected();
2865 if((unsigned int ) NbStored != NbPickGood)
2866 NbPickGood= NbStored;
2869 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2872 // step3 get result.
2874 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2876 Standard_Integer i(0);
2877 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2879 if(TheAISContext()->HasSelectedShape())
2880 thearr->SetValue(i,TheAISContext()->SelectedShape());
2882 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2883 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2887 TheAISContext()->CloseLocalContext(curindex);
2888 return Standard_True;
2892 //=======================================================================
2893 //function : VPickShape
2895 //=======================================================================
2896 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2898 TopoDS_Shape PickSh;
2899 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2902 theType = TopAbs_SHAPE;
2904 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2905 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2906 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2907 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2908 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2909 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2910 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2913 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2914 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2916 TCollection_AsciiString name;
2919 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2921 PickSh = ViewerTest::PickShape(theType);
2930 if(!PickSh.IsNull()){
2931 nbOfSub[Standard_Integer(theType)]++;
2933 name += nameType[Standard_Integer(theType)];
2934 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2939 // si on avait une petite methode pour voir si la shape
2940 // est deja dans la Double map, ca eviterait de creer....
2941 DBRep::Set(name.ToCString(),PickSh);
2943 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2944 GetMapOfAIS().Bind(newsh, name);
2945 TheAISContext()->Display(newsh);
2946 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2949 // Plusieurs objets a picker, vite vite vite....
2952 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2953 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2954 if(ViewerTest::PickShapes(theType,arr)){
2955 for(Standard_Integer i=1;i<=NbToPick;i++){
2956 PickSh = arr->Value(i);
2957 if(!PickSh.IsNull()){
2959 nbOfSub[Standard_Integer(theType)]++;
2962 name += nameType[Standard_Integer(theType)];
2963 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2971 DBRep::Set(name.ToCString(),PickSh);
2972 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2973 GetMapOfAIS().Bind(newsh, name);
2974 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2975 TheAISContext()->Display(newsh);
2985 //=======================================================================
2986 //function : VPickObject
2987 //purpose : filters can be set (type of Object to pick....
2989 //=======================================================================
2992 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2994 // preparation de la nomination automatique
2995 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2996 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2998 /* TCollection_AsciiString name;
3000 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3002 PickSh = ViewerTest::PickObject(theType);
3011 if(!PickSh.IsNull()){
3012 nbOfSub[Standard_Integer(theType)]++;
3014 name += nameType[Standard_Integer(theType)];
3015 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3020 // si on avait une petite methode pour voir si la shape
3021 // est deja dans la Double map, ca eviterait de creer....
3022 DBRep::Set(name.ToCString(),PickSh);
3024 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3025 GetMapOfAIS().Bind(newsh, name);
3026 TheAISContext()->Display(newsh);
3027 cout<<"Nom de la shape pickee : "<<name<<endl;
3030 // Plusieurs objets a picker, vite vite vite....
3033 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3034 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3035 if(ViewerTest::PickShapes(theType,arr)){
3036 for(Standard_Integer i=1;i<=NbToPick;i++){
3037 PickSh = arr->Value(i);
3038 if(!PickSh.IsNull()){
3040 nbOfSub[Standard_Integer(theType)]++;
3043 name += nameType[Standard_Integer(theType)];
3044 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3052 DBRep::Set(name.ToCString(),PickSh);
3053 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3054 GetMapOfAIS().Bind(newsh, name);
3055 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3056 TheAISContext()->Display(newsh);
3066 //=======================================================================
3067 //function : list of known objects
3069 //=======================================================================
3070 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3072 // 1234567890 12345678901234567 123456789
3073 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3074 TCollection_AsciiString BlankLine(64,'_');
3075 Standard_Integer i ;
3077 di<<"/n"<<BlankLine.ToCString()<<"\n";
3080 Colum[i].Center(20,' ');
3082 di<<"|"<<Colum[i].ToCString();
3085 di<<BlankLine.ToCString()<<"\n";
3087 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3088 const char ** names = GetTypeNames();
3090 TCollection_AsciiString curstring;
3091 TCollection_AsciiString curcolum[3];
3094 // les objets de type Datum..
3095 curcolum[1]+="Datum";
3097 curcolum[0].Clear();
3098 curcolum[0] += names[i];
3100 curcolum[2].Clear();
3101 curcolum[2]+=TCollection_AsciiString(i+1);
3103 for(Standard_Integer j =0;j<=2;j++){
3104 curcolum[j].Center(20,' ');
3105 di<<"|"<<curcolum[j].ToCString();
3109 di<<BlankLine.ToCString()<<"\n";
3111 // les objets de type shape
3112 curcolum[1].Clear();
3113 curcolum[1]+="Shape";
3114 curcolum[1].Center(20,' ');
3117 curcolum[0].Clear();
3118 curcolum[0] += names[7+i];
3119 curcolum[2].Clear();
3120 curcolum[2]+=TCollection_AsciiString(i);
3122 for(Standard_Integer j =0;j<=2;j++){
3123 curcolum[j].Center(20,' ');
3124 di<<"|"<<curcolum[j].ToCString();
3128 di<<BlankLine.ToCString()<<"\n";
3129 // les IO de type objet...
3130 curcolum[1].Clear();
3131 curcolum[1]+="Object";
3132 curcolum[1].Center(20,' ');
3134 curcolum[0].Clear();
3135 curcolum[0] += names[10+i];
3136 curcolum[2].Clear();
3137 curcolum[2]+=TCollection_AsciiString(i);
3139 for(Standard_Integer j =0;j<=2;j++){
3140 curcolum[j].Center(20,' ');
3141 di<<"|"<<curcolum[j].ToCString();
3145 di<<BlankLine.ToCString()<<"\n";
3146 // les contraintes et dimensions.
3147 // pour l'instant on separe juste contraintes et dimensions...
3148 // plus tard, on detaillera toutes les sortes...
3149 curcolum[1].Clear();
3150 curcolum[1]+="Relation";
3151 curcolum[1].Center(20,' ');
3153 curcolum[0].Clear();
3154 curcolum[0] += names[12+i];
3155 curcolum[2].Clear();
3156 curcolum[2]+=TCollection_AsciiString(i);
3158 for(Standard_Integer j =0;j<=2;j++){
3159 curcolum[j].Center(20,' ');
3160 di<<"|"<<curcolum[j].ToCString();
3164 di<<BlankLine.ToCString()<<"\n";
3171 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3173 if(argc!=2) return 1;
3175 AIS_KindOfInteractive TheType;
3176 Standard_Integer TheSign(-1);
3177 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3180 AIS_ListOfInteractive LIO;
3182 // en attendant l'amelioration ais pour les dimensions...
3184 Standard_Integer dimension_status(-1);
3185 if(TheType==AIS_KOI_Relation){
3186 dimension_status = TheSign ==1 ? 1 : 0;
3190 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3191 Handle(AIS_InteractiveObject) curio;
3192 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3195 if(dimension_status == -1)
3196 TheAISContext()->Erase(curio,Standard_False);
3198 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3199 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3200 (dimension_status==1 && KOD != AIS_KOD_NONE))
3201 TheAISContext()->Erase(curio,Standard_False);
3204 TheAISContext()->UpdateCurrentViewer();
3207 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3209 if(argc!=2) return 1;
3211 AIS_KindOfInteractive TheType;
3212 Standard_Integer TheSign(-1);
3213 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3215 // en attendant l'amelioration ais pour les dimensions...
3217 Standard_Integer dimension_status(-1);
3218 if(TheType==AIS_KOI_Relation){
3219 dimension_status = TheSign ==1 ? 1 : 0;
3223 AIS_ListOfInteractive LIO;
3224 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3225 Handle(AIS_InteractiveObject) curio;
3226 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3228 if(dimension_status == -1)
3229 TheAISContext()->Display(curio,Standard_False);
3231 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3232 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3233 (dimension_status==1 && KOD != AIS_KOD_NONE))
3234 TheAISContext()->Display(curio,Standard_False);
3239 TheAISContext()->UpdateCurrentViewer();
3243 //==============================================================================
3244 //function : VSetTransMode
3246 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3247 //==============================================================================
3249 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3250 // Verification des arguments
3251 if ( a3DView().IsNull() ) {
3252 ViewerTest::ViewerInit();
3253 di << "La commande vinit n'a pas ete appele avant" << "\n";
3256 if ( argc < 3 || argc > 8 ) {
3257 di << argv[0] << " Invalid number of arguments" << "\n";
3261 TCollection_AsciiString shapeName;
3262 shapeName = argv[1];
3263 Standard_Integer persFlag1 = atoi(argv[2]);
3264 Standard_Integer persFlag2 = 0;
3265 Standard_Integer persFlag3 = 0;
3266 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3267 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3268 persFlag2 = atoi(argv[3]);
3270 if ( argc == 5 || argc == 8 ) {
3271 persFlag3 = atoi(argv[4]);
3274 origin.SetX( atof(argv[argc - 3]) );
3275 origin.SetY( atof(argv[argc - 2]) );
3276 origin.SetZ( atof(argv[argc - 1]) );
3279 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3280 Handle(Standard_Transient) anObj;
3282 anObj = GetMapOfAIS().Find2(shapeName);
3283 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3284 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3285 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3286 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3287 di << argv[0] << " All persistence modifiers were removed" << "\n";
3290 di << argv[0] << " Wrong object type" << "\n";
3293 } else { // Create the AIS_Shape from a name
3294 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3295 if ( !aShape.IsNull() ) {
3296 GetMapOfAIS().Bind( aShape, shapeName );
3297 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3298 TheAISContext()->Display( aShape, Standard_False );
3300 di << argv[0] << " Object not found" << "\n";
3305 // Upadate the screen and redraw the view
3306 TheAISContext()->UpdateCurrentViewer();
3310 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3313 BRep_Builder builder;
3315 BRepTools::Read(shape, s, builder);
3316 DBRep::Set(a[1], shape);
3317 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3318 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3322 //============================================================================
3323 #include <AIS2D_InteractiveContext.hxx>
3324 #include <HLRAlgo_Projector.hxx>
3325 #include <Prs3d_Projector.hxx>
3326 #include <AIS2D_ProjShape.hxx>
3327 #include <gp_Ax2.hxx>
3329 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3332 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3333 /////////////////////
3334 TopoDS_Shape aShape = DBRep::Get(a[1]);
3335 aContext2D->EraseAll(Standard_True);
3336 //Standard_Integer aPolyAlgo = 0;
3337 Standard_Boolean IsPoly = Standard_False;
3338 gp_Ax2 anAx2 = gp::XOY();
3340 //if(n > 2) aPolyAlgo = atoi(a[2]);
3342 //IsPoly = aPolyAlgo > 0;
3344 TopoDS_Shape aResult = aShape;
3349 Standard_Real x = atof(a[2]);
3350 Standard_Real y = atof(a[3]);
3351 Standard_Real z = atof(a[4]);
3353 Standard_Real dx = atof(a[5]);
3354 Standard_Real dy = atof(a[6]);
3355 Standard_Real dz = atof(a[7]);
3357 Standard_Real dx1 = atof(a[8]);
3358 Standard_Real dy1 = atof(a[9]);
3359 Standard_Real dz1 = atof(a[10]);
3361 gp_Pnt anOrigin (x, y, z);
3362 gp_Dir aNormal (dx, dy, dz);
3363 gp_Dir aDX (dx1, dy1, dz1);
3364 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3368 HLRAlgo_Projector aProjector(anAx2);
3370 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3372 //aProjector = aProjector_t.Projector();
3374 Handle(AIS2D_ProjShape) myDisplayableShape =
3375 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3377 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3378 Standard_False, Standard_True, Standard_False);
3380 myDisplayableShape->Add( aResult );
3383 aContext2D->Display( myDisplayableShape,Standard_True );
3384 aContext2D->UpdateCurrentViewer();
3389 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3392 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3393 /////////////////////
3394 TopoDS_Shape aShape = DBRep::Get(a[1]);
3395 aContext2D->EraseAll(Standard_True);
3396 //Standard_Integer aPolyAlgo = 0;
3397 Standard_Boolean IsPoly = Standard_True;
3398 gp_Ax2 anAx2 = gp::XOY();
3400 //if(n > 2) aPolyAlgo = atoi(a[2]);
3402 //IsPoly = aPolyAlgo > 0;
3404 TopoDS_Shape aResult = aShape;
3409 Standard_Real x = atof(a[2]);
3410 Standard_Real y = atof(a[3]);
3411 Standard_Real z = atof(a[4]);
3413 Standard_Real dx = atof(a[5]);
3414 Standard_Real dy = atof(a[6]);
3415 Standard_Real dz = atof(a[7]);
3417 Standard_Real dx1 = atof(a[8]);
3418 Standard_Real dy1 = atof(a[9]);
3419 Standard_Real dz1 = atof(a[10]);
3421 gp_Pnt anOrigin (x, y, z);
3422 gp_Dir aNormal (dx, dy, dz);
3423 gp_Dir aDX (dx1, dy1, dz1);
3424 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3428 HLRAlgo_Projector aProjector(anAx2);
3430 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3432 //aProjector = aProjector_t.Projector();
3434 Handle(AIS2D_ProjShape) myDisplayableShape =
3435 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3437 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3438 Standard_False, Standard_True, Standard_False);
3440 myDisplayableShape->Add( aResult );
3443 aContext2D->Display( myDisplayableShape,Standard_True );
3444 aContext2D->UpdateCurrentViewer();
3449 //==============================================================================
3450 //function : ViewerTest::Commands
3451 //purpose : Add all the viewer command in the Draw_Interpretor
3452 //==============================================================================
3454 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3456 ViewerTest::ViewerCommands(theCommands);
3457 ViewerTest::RelationCommands(theCommands);
3458 ViewerTest::ObjectCommands(theCommands);
3459 ViewerTest::FilletCommands(theCommands);
3460 ViewerTest::VoxelCommands(theCommands);
3461 ViewerTest::OpenGlCommands(theCommands);
3463 const char *group = "AIS_Display";
3467 theCommands.Add("vdisplay",
3468 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3469 __FILE__,VDisplay2,group);
3471 theCommands.Add("verase",
3472 "verase : verase2 [name1] ... [name n] ",
3473 __FILE__,VErase2,group);
3475 theCommands.Add("vdonly",
3476 "vdonly : vdonly2 [name1] ... [name n]",
3477 __FILE__,VDonly2,group);
3479 theCommands.Add("vdisplayall",
3480 "vdisplayall : vdisplayall",
3481 __FILE__,VDisplayAll,group);
3483 theCommands.Add("veraseall",
3484 "veraseall : veraseall ",
3485 __FILE__,VEraseAll,group);
3487 theCommands.Add("verasetype",
3488 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3489 __FILE__,VEraseType,group);
3491 theCommands.Add("vdisplaytype",
3492 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3493 __FILE__,VDisplayType,group);
3495 theCommands.Add("vdisplaymode",
3496 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3497 __FILE__,VDispMode,group);
3499 theCommands.Add("verasemode",
3500 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3501 __FILE__,VDispMode,group);
3503 theCommands.Add("vsetdispmode",
3504 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3505 __FILE__,VDispMode,group);
3507 theCommands.Add("vunsetdispmode",
3508 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3509 __FILE__,VDispMode,group);
3511 theCommands.Add("vdir",
3513 __FILE__,VDebug,group);
3515 theCommands.Add("vdump",
3516 "<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",
3517 __FILE__,VDump,group);
3519 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3520 __FILE__,VSubInt,group);
3522 theCommands.Add("vsetcolor",
3523 "vsetcolor : vsetcolor [name of shape] ColorName",
3524 __FILE__,VColor2,group);
3526 theCommands.Add("vunsetcolor",
3527 "vunsetcolor : vunsetcolor [name of shape] ",
3528 __FILE__,VColor2,group);
3530 theCommands.Add("vsettransparency",
3531 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3532 __FILE__,VTransparency,group);
3534 theCommands.Add("vunsettransparency",
3535 "vunsettransparency : vtransparency [name of shape]",
3536 __FILE__,VTransparency,group);
3538 theCommands.Add("vsetmaterial",
3539 "vmaterial : vmaterial [name of shape] MaterialName",
3540 __FILE__,VMaterial,group);
3542 theCommands.Add("vunsetmaterial",
3543 "vmaterial : vmaterial [name of shape]",
3544 __FILE__,VMaterial,group);
3546 theCommands.Add("vsetwidth",
3547 "vsetwidth : vwidth [name of shape] width(0->10)",
3548 __FILE__,VWidth,group);
3550 theCommands.Add("vunsetwidth",
3551 "vunsetwidth : vwidth [name of shape]",
3552 __FILE__,VWidth,group);
3554 theCommands.Add("vardis",
3555 "vardis : display activeareas",
3556 __FILE__,VDispAreas,group);
3558 theCommands.Add("varera",
3559 "varera : erase activeareas",
3560 __FILE__,VClearAreas,group);
3562 theCommands.Add("vsensdis",
3563 "vardisp : display active entities",
3564 __FILE__,VDispSensi,group);
3565 theCommands.Add("vsensera",
3566 "vardisp : erase active entities",
3567 __FILE__,VClearSensi,group);
3569 theCommands.Add("vselprecision",
3570 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3571 __FILE__,VSelPrecision,group);
3573 theCommands.Add("vperf",
3574 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3575 __FILE__,VPerf,group);
3577 theCommands.Add("vanimation",
3578 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3579 __FILE__,VAnimation,group);
3581 theCommands.Add("vsetshading",
3582 "vsetshading : vsetshading name Quality(default=0.0008) ",
3583 __FILE__,VShading,group);
3585 theCommands.Add("vunsetshading",
3586 "vunsetshading :vunsetshading name ",
3587 __FILE__,VShading,group);
3589 theCommands.Add("vtexture",
3590 "'vtexture NameOfShape TextureFile' \n \
3591 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3592 or 'vtexture NameOfShape ?' to list available textures\n \
3593 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3594 __FILE__,VTexture,group);
3596 theCommands.Add("vtexscale",
3597 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3598 or 'vtexscale NameOfShape ScaleUV' \n \
3599 or 'vtexscale NameOfShape' to disable scaling\n ",
3600 __FILE__,VTexture,group);
3602 theCommands.Add("vtexorigin",
3603 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3604 or 'vtexorigin NameOfShape UVOrigin' \n \
3605 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3606 __FILE__,VTexture,group);
3608 theCommands.Add("vtexrepeat",
3609 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3610 or 'vtexrepeat NameOfShape UVRepeat \n \
3611 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3614 theCommands.Add("vtexdefault",
3615 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3618 theCommands.Add("vsetam",
3619 "vsetActivatedModes: vsetam mode(1->7) ",
3620 __FILE__,VActivatedMode,group);
3622 theCommands.Add("vunsetam",
3623 "vunsetActivatedModes: vunsetam ",
3624 __FILE__,VActivatedMode,group);
3626 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3627 __FILE__,VState,group);
3629 theCommands.Add("vpickshapes",
3630 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3631 __FILE__,VPickShape,group);
3633 theCommands.Add("vtypes",
3634 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3637 theCommands.Add("vsettransmode",
3638 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3639 __FILE__,VSetTransMode,group);
3641 theCommands.Add("vr", "vr : reading of the shape",
3642 __FILE__,vr, group);
3644 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3645 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3649 //=====================================================================
3650 //========================= for testing Draft and Rib =================
3651 //=====================================================================
3652 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3653 #include <DBRep.hxx>
3654 #include <TopoDS_Face.hxx>
3655 #include <gp_Pln.hxx>
3656 #include <AIS_KindOfSurface.hxx>
3657 #include <BRepOffsetAPI_DraftAngle.hxx>
3658 #include <Precision.hxx>
3659 #include <BRepAlgo.hxx>
3660 #include <OSD_Environment.hxx>
3661 #include <DrawTrSurf.hxx>
3662 //#include <DbgTools.hxx>
3663 //#include <FeatAlgo_MakeLinearForm.hxx>
3668 //=======================================================================
3669 //function : IsValid
3671 //=======================================================================
3672 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3673 const TopoDS_Shape& theResult,
3674 const Standard_Boolean closedSolid,
3675 const Standard_Boolean GeomCtrl)
3677 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3678 TCollection_AsciiString checkValid = check.Value();
3679 Standard_Boolean ToCheck = Standard_True;
3680 if (!checkValid.IsEmpty()) {
3682 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3684 if ( checkValid=="true" || checkValid=="TRUE" ) {
3685 ToCheck= Standard_False;
3689 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3692 Standard_Boolean IsValid = Standard_True;
3694 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3699 //===============================================================================
3700 // TDraft : test draft, uses AIS Viewer
3701 // Solid Face Plane Angle Reverse
3702 //===============================================================================
3703 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3705 if (argc < 5) return 1;
3706 // argv[1] - TopoDS_Shape Solid
3707 // argv[2] - TopoDS_Shape Face
3708 // argv[3] - TopoDS_Shape Plane
3709 // argv[4] - Standard_Real Angle
3710 // argv[5] - Standard_Integer Reverse
3712 // sprintf(prefix, argv[1]);
3713 Standard_Real anAngle = 0;
3714 Standard_Boolean Rev = Standard_False;
3715 Standard_Integer rev = 0;
3716 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3717 TopoDS_Shape face = GetShapeFromName(argv[2]);
3718 TopoDS_Face Face = TopoDS::Face(face);
3719 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3720 if (Plane.IsNull ()) {
3721 di << "TEST : Plane is NULL" << "\n";
3724 anAngle = atof(argv[4]);
3725 anAngle = 2*M_PI * anAngle / 360.0;
3727 Handle( Geom_Surface )aSurf;
3728 AIS_KindOfSurface aSurfType;
3729 Standard_Real Offset;
3731 if(argc > 4) { // == 5
3732 rev = atoi(argv[5]);
3733 Rev = (rev)? Standard_True : Standard_False;
3736 TopoDS_Face face2 = TopoDS::Face(Plane);
3737 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3739 di << "TEST : Can't find plane" << "\n";
3743 aDir = aPln.Axis().Direction();
3746 if (Plane.Orientation() == TopAbs_REVERSED)
3748 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3750 BRepOffsetAPI_DraftAngle Draft (Solid);
3752 if(Abs(anAngle)< Precision::Angular()) {
3753 di << "TEST : NULL angle" << "\n";
3756 if(Rev) anAngle = - anAngle;
3757 Draft.Add (Face, aDir, anAngle, aPln);
3759 if (!Draft.IsDone()) {
3760 di << "TEST : Draft Not DONE " << "\n";
3763 TopTools_ListOfShape Larg;
3765 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3766 di << "TEST : DesignAlgo returns Not valid" << "\n";
3770 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3771 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3773 if ( !ais.IsNull() ) {
3774 ais->SetColor(DEFAULT_COLOR);
3775 ais->SetMaterial(DEFAULT_MATERIAL);
3776 // Display the AIS_Shape without redraw
3777 Ctx->Display(ais, Standard_False);
3779 const char *Name = "draft1";
3780 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3782 Handle(AIS_InteractiveObject) an_object =
3783 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3784 if (!an_object.IsNull()) {
3785 Ctx->Remove(an_object,
3787 GetMapOfAIS().UnBind2(Name) ;
3790 GetMapOfAIS().Bind(ais, Name);
3791 // DBRep::Set("draft", ais->Shape());
3793 Ctx->Display(ais, Standard_True);
3799 //============================================================================
3801 //============================================================================
3802 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3805 DrawTrSurf::BasicCommands(theCommands);
3806 const char* group = "Check Features Operations commands";
3808 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3810 &TDraft,group); //Draft_Modification
3813 //==============================================================================
3814 // ViewerTest::Factory
3815 //==============================================================================
3816 void ViewerTest::Factory(Draw_Interpretor& theDI)
3818 // definition of Viewer Command
3819 ViewerTest::Commands(theDI);
3820 ViewerTest::AviCommands(theDI);
3821 Viewer2dTest::Commands(theDI);
3823 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3827 // Declare entry point PLUGINFACTORY