1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_TextureRoot.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Prs3d_ShadingAspect.hxx>
69 #include <Draw_Interpretor.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <Draw_PluginMacro.hxx>
72 #include <ViewerTest.hxx>
73 #include <Viewer2dTest.hxx>
75 // avoid warnings on 'extern "C"' functions returning C++ classes
77 #define _CRT_SECURE_NO_DEPRECATE
78 #pragma warning(4:4190)
79 #pragma warning (disable:4996)
82 #include <NIS_InteractiveContext.hxx>
83 #include <NIS_Triangulated.hxx>
84 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
86 #include <Quantity_Color.hxx>
87 #include <Quantity_NameOfColor.hxx>
89 #include <Graphic3d_NameOfMaterial.hxx>
91 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
92 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
94 //=======================================================================
95 //function : GetColorFromName
96 //purpose : get the Quantity_NameOfColor from a string
97 //=======================================================================
99 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
101 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
103 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
104 if (strcasecmp (theName, aColorName) == 0)
106 return Quantity_NameOfColor (anIter);
110 return DEFAULT_COLOR;
113 //=======================================================================
114 //function : GetMaterialFromName
115 //purpose : get the Graphic3d_NameOfMaterial from a string
116 //=======================================================================
118 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
120 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
122 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
123 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
124 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
125 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
126 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
127 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
128 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
129 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
130 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
131 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
132 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
133 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
134 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
135 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
136 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
137 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
138 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
139 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
140 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
145 //=======================================================================
146 //function : GetTypeNames
148 //=======================================================================
149 static const char** GetTypeNames()
151 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
152 "Shape","ConnectedShape","MultiConn.Shape",
153 "ConnectedInter.","MultiConn.",
154 "Constraint","Dimension"};
155 static const char** ThePointer = names;
159 //=======================================================================
160 //function : GetTypeAndSignfromString
162 //=======================================================================
163 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
165 const char ** thefullnames = GetTypeNames();
166 Standard_Integer index(-1);
168 for(Standard_Integer i=0;i<=13 && index==-1;i++)
169 if(!strcasecmp(name,thefullnames[i]))
173 TheType = AIS_KOI_None;
179 TheType = AIS_KOI_Datum;
183 TheType = AIS_KOI_Shape;
187 TheType = AIS_KOI_Object;
191 TheType = AIS_KOI_Relation;
200 #include <Draw_Interpretor.hxx>
202 #include <Draw_Appli.hxx>
206 #include <TCollection_AsciiString.hxx>
207 #include <V3d_Viewer.hxx>
208 #include <V3d_View.hxx>
211 #include <AIS_InteractiveContext.hxx>
212 #include <AIS_Shape.hxx>
213 #include <AIS_TexturedShape.hxx>
214 #include <AIS_DisplayMode.hxx>
215 #include <TColStd_MapOfInteger.hxx>
216 #include <AIS_MapOfInteractive.hxx>
217 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
218 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
219 #include <ViewerTest_EventManager.hxx>
221 #include <TopoDS_Solid.hxx>
222 #include <BRepTools.hxx>
223 #include <BRep_Builder.hxx>
224 #include <TopAbs_ShapeEnum.hxx>
226 #include <TopoDS.hxx>
227 #include <BRep_Tool.hxx>
230 #include <Draw_Window.hxx>
231 #include <AIS_ListIteratorOfListOfInteractive.hxx>
232 #include <AIS_ListOfInteractive.hxx>
233 #include <AIS_DisplayMode.hxx>
234 #include <TopTools_ListOfShape.hxx>
235 #include <BRepOffsetAPI_MakeThickSolid.hxx>
236 #include <BRepOffset.hxx>
239 //==============================================================================
240 //function : GetTypeNameFromShape
241 //purpose : get the shape type as a string from a shape
242 //==============================================================================
244 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
245 { const char *ret = "????";
247 if ( aShape.IsNull() ) ret = "Null Shape";
249 switch ( aShape.ShapeType() ) {
250 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
251 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
252 case TopAbs_SOLID : ret = "SOLID" ; break;
253 case TopAbs_SHELL : ret = "SHELL" ; break;
254 case TopAbs_FACE : ret = "FACE" ; break;
255 case TopAbs_WIRE : ret = "WIRE" ; break;
256 case TopAbs_EDGE : ret = "EDGE" ; break;
257 case TopAbs_VERTEX : ret = "VERTEX" ; break;
258 case TopAbs_SHAPE : ret = "SHAPE" ; break;
262 //==============================================================================
263 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
264 //==============================================================================
265 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
266 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
271 //==============================================================================
272 //function : VDisplayAISObject
273 //purpose : register interactive object in the map of AIS objects;
274 // if other object with such name already registered, it will be kept
275 // or replaced depending on value of <theReplaceIfExists>,
276 // if "true" - the old object will be cleared from AIS context;
277 // returns Standard_True if <theAISObj> registered in map;
278 //==============================================================================
279 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
280 const Handle(AIS_InteractiveObject)& theAISObj,
281 Standard_Boolean theReplaceIfExists = Standard_True)
283 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
284 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
285 if (aContextAIS.IsNull())
287 std::cout << "AIS context is not available.\n";
288 return Standard_False;
291 if (aMap.IsBound2 (theName))
293 if (!theReplaceIfExists)
295 std::cout << "Other interactive object has been already "
296 << "registered with name: " << theName << ".\n"
297 << "Please use another name.\n";
298 return Standard_False;
301 // stop displaying object
302 Handle(AIS_InteractiveObject) anOldObj =
303 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
305 if (!anOldObj.IsNull())
306 aContextAIS->Clear (anOldObj, Standard_True);
308 // remove name and old object from map
309 aMap.UnBind2 (theName);
312 if (theAISObj.IsNull())
314 // object with specified name already unbound
315 return Standard_True;
318 // unbind AIS object if was bound with another name
319 aMap.UnBind1 (theAISObj);
321 // can be registered without rebinding
322 aMap.Bind (theAISObj, theName);
323 aContextAIS->Display (theAISObj, Standard_True);
324 return Standard_True;
327 static TColStd_MapOfInteger theactivatedmodes(8);
328 static TColStd_ListOfTransient theEventMgrs;
330 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
331 const Handle(AIS_InteractiveContext)& Ctx)
333 theEventMgrs.Clear();
334 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
337 static Handle(V3d_View)& a3DView(){
338 static Handle(V3d_View) Viou;
342 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
343 static Handle(AIS_InteractiveContext) aContext;
347 Handle(V3d_View) ViewerTest::CurrentView()
351 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
356 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
358 static Handle(NIS_InteractiveContext) aContext;
359 if (aContext.IsNull()) {
360 aContext = new NIS_InteractiveContext;
361 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
366 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
368 return TheAISContext();
371 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
373 TheAISContext() = aCtx;
374 ViewerTest::ResetEventManager();
377 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
379 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
382 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
384 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
388 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
389 theEventMgrs.Prepend(EM);
392 void ViewerTest::UnsetEventManager()
394 theEventMgrs.RemoveFirst();
398 void ViewerTest::ResetEventManager()
400 const Handle(NIS_View) aView =
401 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
402 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
405 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
407 Handle(ViewerTest_EventManager) EM;
408 if(theEventMgrs.IsEmpty()) return EM;
409 Handle(Standard_Transient) Tr = theEventMgrs.First();
410 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
415 //=======================================================================
416 //function : Get Context and active viou..
418 //=======================================================================
419 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
420 Handle(V3d_View)& Viou)
422 Ctx = ViewerTest::GetAISContext();
425 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
426 Vwr->InitActiveViews();
427 if(Vwr->MoreActiveViews())
428 Viou = Vwr->ActiveView();
433 //==============================================================================
434 //function : GetShapeFromName
435 //purpose : Compute an Shape from a draw variable or a file name
436 //==============================================================================
438 static TopoDS_Shape GetShapeFromName(const char* name)
440 TopoDS_Shape S = DBRep::Get(name);
443 BRep_Builder aBuilder;
444 BRepTools::Read( S, name, aBuilder);
449 //==============================================================================
450 //function : GetShapeFromName
451 //purpose : Compute an Shape from a draw variable or a file name
452 //==============================================================================
455 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
457 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
461 //==============================================================================
462 //function : GetAISShapeFromName
463 //purpose : Compute an AIS_Shape from a draw variable or a file name
464 //==============================================================================
465 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
467 Handle(AIS_Shape) retsh;
469 if(GetMapOfAIS().IsBound2(name)){
470 const Handle(AIS_InteractiveObject) IO =
471 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
473 if(IO->Type()==AIS_KOI_Shape)
474 if(IO->Signature()==0){
475 retsh = *((Handle(AIS_Shape)*)&IO);
478 cout << "an Object which is not an AIS_Shape "
479 "already has this name!!!"<<endl;
485 TopoDS_Shape S = GetShapeFromName(name);
487 retsh = new AIS_Shape(S);
493 //==============================================================================
495 //purpose : Remove all the object from the viewer
496 //==============================================================================
497 void ViewerTest::Clear()
499 if ( !a3DView().IsNull() ) {
500 if (TheAISContext()->HasOpenedContext())
501 TheAISContext()->CloseLocalContext();
502 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
503 while ( it.More() ) {
504 cout << "Remove " << it.Key2() << endl;
505 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
506 const Handle(AIS_InteractiveObject) anObj =
507 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
508 TheAISContext()->Remove(anObj,Standard_False);
509 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
510 const Handle(NIS_InteractiveObject) anObj =
511 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
512 TheNISContext()->Remove(anObj);
516 TheAISContext()->UpdateCurrentViewer();
517 // TheNISContext()->UpdateViews();
518 GetMapOfAIS().Clear();
522 //==============================================================================
523 //function : StandardModesActivation
524 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
526 //==============================================================================
527 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
529 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
531 if (TheAISContext()->HasOpenedContext())
532 aContext->CloseLocalContext();
535 if(!aContext->HasOpenedContext()) {
536 // To unhilight the preselected object
537 aContext->UnhilightCurrents(Standard_False);
538 // Open a local Context in order to be able to select subshape from
539 // the selected shape if any or for all if there is no selection
540 if (!aContext->FirstCurrentObject().IsNull()){
541 aContext->OpenLocalContext(Standard_False);
543 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
544 aContext->Load( aContext->Current(),-1,Standard_True);
548 aContext->OpenLocalContext();
551 const char *cmode="???";
554 case 0: cmode = "Shape"; break;
555 case 1: cmode = "Vertex"; break;
556 case 2: cmode = "Edge"; break;
557 case 3: cmode = "Wire"; break;
558 case 4: cmode = "Face"; break;
559 case 5: cmode = "Shell"; break;
560 case 6: cmode = "Solid"; break;
561 case 7: cmode = "Compound"; break;
564 if(theactivatedmodes.Contains(mode))
566 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
567 theactivatedmodes.Remove(mode);
568 cout<<"Mode "<< cmode <<" OFF"<<endl;
572 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
573 theactivatedmodes.Add(mode);
574 cout<<"Mode "<< cmode << " ON" << endl;
579 //==============================================================================
580 //function : SelectFromContext
581 //purpose : pick / select an object from the last MoveTo() on a
583 //==============================================================================
585 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
587 Standard_Boolean shift,
588 Standard_Boolean pick )
590 Handle(AIS_InteractiveObject) ret;
591 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
598 const Handle(AIS_InteractiveContext) aContext = EM->Context();
600 if ( !aContext->HasOpenedContext() ) {
601 aContext->InitCurrent();
602 while ( aContext->MoreCurrent() ) {
603 Handle(AIS_InteractiveObject) aisPickedShape =
604 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
607 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
608 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
609 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
611 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
612 if(!TheRealSh.IsNull()){
613 cout << "Current is " << name
614 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
617 ret = aisPickedShape;
618 if(!TheRealSh.IsNull()){
619 if ( pick && argc > 4 ) {
620 DBRep::Set(argv[4], TheRealSh->Shape());
623 aContext->NextCurrent();
627 // A LocalContext is opened, the use xxxxSelected()
628 // to select an object and its SubShape
629 aContext->InitSelected();
630 while ( aContext->MoreSelected() ) {
631 if ( !aContext->HasSelectedShape() ) {
634 TopoDS_Shape PickedShape = aContext->SelectedShape();
635 if ( pick && argc > 5 ) {
636 DBRep::Set(argv[5], PickedShape);
640 if ( aContext->Interactive().IsNull() ) {
641 cout << "??? (No InteractiveObject selected)" << endl;
644 Handle(AIS_InteractiveObject) aisPicked =
645 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
647 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
651 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
652 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
653 GetMapOfAIS().Find1(aisPicked).ToCString() :
656 if(!aisPickedShape.IsNull()){
657 if ( pick && argc > 4 ) {
658 // Create a draw variable to store the wohole shape
660 DBRep::Set(argv[4], aisPickedShape->Shape());
663 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
667 // Goto the next selected object
668 aContext->NextSelected();
674 //==============================================================================
675 //function : DetectedFromContext
676 //purpose : hilight dynamicaly an object from the last MoveTo() on a
678 //==============================================================================
679 Handle(AIS_InteractiveObject) DetectedFromContext(
680 Handle(AIS_InteractiveContext) aContext )
682 Handle(AIS_InteractiveObject) ret;
683 if ( aContext->HasDetected() ) {
684 if ( !aContext->HasDetectedShape() ) {
685 //No SubShape selected
688 // Get the detected SubShape
689 TopoDS_Shape PickedShape = aContext->DetectedShape();
691 if ( !aContext->DetectedInteractive().IsNull() ) {
692 Handle(AIS_InteractiveObject) aisPickedShape =
693 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
694 ret = aisPickedShape;
701 //==============================================================================
702 //function : VDispAreas,VDispSensitive,...
703 //purpose : Redraw the view
705 //==============================================================================
706 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
709 Handle(AIS_InteractiveContext) Ctx;
710 Handle(V3d_View) Viou;
711 GetCtxAndView(Ctx,Viou);
712 Ctx->DisplayActiveAreas(Viou);
715 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
717 Handle(AIS_InteractiveContext) Ctx;
718 Handle(V3d_View) Viou;
719 GetCtxAndView(Ctx,Viou);
720 Ctx->ClearActiveAreas(Viou);
724 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
726 Handle(AIS_InteractiveContext) Ctx;
727 Handle(V3d_View) Viou;
728 GetCtxAndView(Ctx,Viou);
729 Ctx->DisplayActiveSensitive(Viou);
733 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
735 Handle(AIS_InteractiveContext) Ctx;
736 Handle(V3d_View) Viou;
737 GetCtxAndView(Ctx,Viou);
738 Ctx->ClearActiveSensitive(Viou);
742 //==============================================================================
744 //purpose : To list the displayed object with their attributes
746 //==============================================================================
747 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
748 { if ( !a3DView().IsNull() ) {
749 di << "List of object in the viewer :" << "\n";
751 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
753 while ( it.More() ) {
754 di << "\t" << it.Key2().ToCString() << "\n";
762 //==============================================================================
763 //function : VSelPrecision
764 //purpose : To set the selection precision mode and tolerance value
765 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
766 // value (integer number of pixel for window mode, double value of
767 // sensitivity for view mode). Without arguments the function just
768 // prints the current precision mode and the corresponding tolerance.
769 //==============================================================================
770 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
774 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
778 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
779 if( aContext.IsNull() )
784 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
785 if( aMode == StdSelect_SM_WINDOW )
787 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
788 di << "Precision mode : 0 (window)\n";
789 di << "Pixel tolerance : " << aPixelTolerance << "\n";
791 else if( aMode == StdSelect_SM_VIEW )
793 Standard_Real aSensitivity = aContext->Sensitivity();
794 di << "Precision mode : 1 (view)\n";
795 di << "Sensitivity : " << aSensitivity << "\n";
800 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
801 aContext->SetSensitivityMode( aMode );
804 if( aMode == StdSelect_SM_WINDOW )
806 Standard_Integer aPixelTolerance = atoi( argv[2] );
807 aContext->SetPixelTolerance( aPixelTolerance );
809 else if( aMode == StdSelect_SM_VIEW )
811 Standard_Real aSensitivity = atof( argv[2] );
812 aContext->SetSensitivity( aSensitivity );
819 //==============================================================================
821 //purpose : To dump the active view snapshot to image file
822 //Draw arg : Picture file name with extension corresponding to desired format
823 //==============================================================================
824 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
828 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
832 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
835 TCollection_AsciiString aBuffTypeStr (argv[2]);
836 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
838 aBufferType = Graphic3d_BT_RGB;
840 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
842 aBufferType = Graphic3d_BT_RGBA;
844 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
846 aBufferType = Graphic3d_BT_Depth;
850 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
851 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
853 Handle(AIS_InteractiveContext) IC;
854 Handle(V3d_View) view;
855 GetCtxAndView (IC, view);
858 di << "Cannot find an active viewer/view\n";
862 if (aWidth <= 0 || aHeight <= 0)
864 if (!view->Dump (argv[1], aBufferType))
866 di << "Dumping failed!\n";
872 Image_AlienPixMap aPixMap;
873 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
875 di << "Dumping failed!\n";
879 if (aPixMap.SizeX() != Standard_Size(aWidth)
880 || aPixMap.SizeY() != Standard_Size(aHeight))
882 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
883 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
885 if (!aPixMap.Save (argv[1]))
887 di << "Saving image failed!\n";
894 //==============================================================================
895 //function : Displays,Erase...
898 //==============================================================================
899 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
900 const Standard_Integer Mode,
901 const Standard_Integer TypeOfOperation,
902 const Standard_Boolean Upd)
904 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
906 switch(TypeOfOperation){
908 Ctx->Display(IO,Mode,Upd);
911 Ctx->Erase(IO,Mode,Upd);
916 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
918 Ctx->SetDisplayMode(IO,Mode,Upd);
923 Ctx->SetDisplayMode(0,Upd);
925 Ctx->UnsetDisplayMode(IO,Upd);
932 //=======================================================================
935 //=======================================================================
936 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
939 TCollection_AsciiString name;
942 // display others presentations
943 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
944 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
945 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
946 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
948 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
950 //unset displaymode.. comportement particulier...
951 if(TypeOfOperation==4){
953 if(Ctx->NbCurrents()==0 ||
954 Ctx->NbSelected()==0){
955 Handle(AIS_InteractiveObject) IO;
956 VwrTst_DispErase(IO,-1,4,Standard_False);
958 else if(!Ctx->HasOpenedContext()){
959 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
960 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
963 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
964 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
965 Ctx->UpdateCurrentViewer();
968 Handle(AIS_InteractiveObject) IO;
970 if(GetMapOfAIS().IsBound2(name)){
971 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
973 VwrTst_DispErase(IO,-1,4,Standard_True);
978 Standard_Integer Dmode = atoi(argv[1]);
979 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
980 Handle(AIS_InteractiveObject) IO;
981 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
983 if(!Ctx->HasOpenedContext()){
984 // set/unset display mode sur le Contexte...
985 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
986 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
988 Ctx->UpdateCurrentViewer();
991 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
992 Ctx->Display(Ctx->Interactive(),Dmode);
996 Handle(AIS_InteractiveObject) IO;
998 if(GetMapOfAIS().IsBound2(name))
999 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1001 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
1007 //=======================================================================
1010 //=======================================================================
1011 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1013 if(argc==1) return 1;
1014 Standard_Integer On = atoi(argv[1]);
1015 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1019 if(!Ctx->HasOpenedContext()){
1020 di<<"sub intensite ";
1023 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1024 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1026 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1028 di <<"passage dans off"<<"\n";
1029 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1034 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1036 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1038 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1041 Ctx->UpdateCurrentViewer();
1044 Handle(AIS_InteractiveObject) IO;
1045 TCollection_AsciiString name = argv[2];
1046 if(GetMapOfAIS().IsBound2(name)){
1047 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1050 Ctx->SubIntensityOn(IO);
1052 Ctx->SubIntensityOff(IO);
1060 //==============================================================================
1061 //function : VColor2
1063 //purpose : change the color of a selected or named or displayed shape
1064 //Draw arg : vcolor2 [name] color
1065 //==============================================================================
1066 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1069 Standard_Boolean ThereIsCurrent;
1070 Standard_Boolean ThereIsArgument;
1071 Standard_Boolean IsBound = Standard_False ;
1073 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1075 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1076 ThereIsArgument = (argc != 2);
1079 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1080 ThereIsArgument = (argc == 2);
1083 if ( !a3DView().IsNull() ) {
1084 TCollection_AsciiString name;
1085 if (ThereIsArgument) {
1087 IsBound= GetMapOfAIS().IsBound2(name);
1089 if (TheAISContext()->HasOpenedContext())
1090 TheAISContext()->CloseLocalContext();
1092 // On set le Booleen There is current
1093 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1094 else ThereIsCurrent =Standard_False;
1096 //=======================================================================
1097 // Il y a un argument
1098 //=======================================================================
1099 if ( ThereIsArgument && IsBound ) {
1100 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1101 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1102 Handle(AIS_InteractiveObject) ashape =
1103 Handle(AIS_InteractiveObject)::DownCast (anObj);
1106 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1108 di << "HaveToSet 0\n";
1112 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1114 TheAISContext()->UnsetColor(ashape);
1115 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1116 Handle(NIS_Triangulated) ashape =
1117 Handle(NIS_Triangulated)::DownCast (anObj);
1118 if (!ashape.IsNull())
1119 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1124 //=======================================================================
1125 // Il n'y a pas d'arguments
1126 // Mais un ou plusieurs objets on des current representation
1127 //=======================================================================
1128 if (ThereIsCurrent && !ThereIsArgument) {
1129 for (TheAISContext() -> InitCurrent() ;
1130 TheAISContext() -> MoreCurrent() ;
1131 TheAISContext() ->NextCurrent() )
1133 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1134 if (ashape.IsNull())
1138 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1140 di << "HaveToSet 0\n";
1143 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1145 TheAISContext()->UnsetColor(ashape,Standard_False);
1148 TheAISContext()->UpdateCurrentViewer();
1151 //=======================================================================
1152 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1153 // on impose a tous les objets du viewer la couleur passee
1154 //=======================================================================
1155 else if (!ThereIsCurrent && !ThereIsArgument){
1156 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1157 while ( it.More() ) {
1158 const Handle(AIS_InteractiveObject) ashape =
1159 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1160 if (!ashape.IsNull())
1162 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1164 TheAISContext()->UnsetColor(ashape,Standard_False);
1167 TheAISContext()->UpdateCurrentViewer();
1173 //==============================================================================
1174 //function : VTransparency
1176 //purpose : change the transparency of a selected or named or displayed shape
1177 //Draw arg : vtransparency [name] TransparencyCoeficient
1178 //==============================================================================
1180 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1183 Standard_Boolean ThereIsCurrent;
1184 Standard_Boolean ThereIsArgument;
1185 Standard_Boolean IsBound = Standard_False ;
1187 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1189 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1190 ThereIsArgument = (argc != 2);
1193 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1194 ThereIsArgument = (argc == 2);
1197 if ( !a3DView().IsNull() ) {
1198 TCollection_AsciiString name;
1199 if (ThereIsArgument) {
1201 IsBound= GetMapOfAIS().IsBound2(name);
1203 if (TheAISContext()->HasOpenedContext())
1204 TheAISContext()->CloseLocalContext();
1206 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1207 else ThereIsCurrent = Standard_False;
1209 //=======================================================================
1210 // Il y a des arguments: un nom et une couleur
1211 //=======================================================================
1212 if ( ThereIsArgument && IsBound ) {
1213 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1214 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1215 const Handle(AIS_InteractiveObject) ashape =
1216 Handle(AIS_InteractiveObject)::DownCast(anObj);
1218 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1220 TheAISContext()->UnsetTransparency(ashape);
1221 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1222 const Handle(NIS_InteractiveObject) ashape =
1223 Handle(NIS_InteractiveObject)::DownCast(anObj);
1225 ashape->SetTransparency(atof(argv[2]) );
1227 ashape->UnsetTransparency();
1230 //=======================================================================
1231 // Il n'y a pas d'arguments
1232 // Mais un ou plusieurs objets on des current representation
1233 //=======================================================================
1234 if (ThereIsCurrent && !ThereIsArgument) {
1235 for (TheAISContext() -> InitCurrent() ;
1236 TheAISContext() -> MoreCurrent() ;
1237 TheAISContext() ->NextCurrent() )
1239 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1241 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1243 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1246 TheAISContext()->UpdateCurrentViewer();
1248 //=======================================================================
1249 // Il n'y a pas d'arguments ET aucun objet courrant
1250 //=======================================================================
1251 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1252 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1254 while ( it.More() ) {
1255 Handle(AIS_InteractiveObject) ashape =
1256 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1257 if (!ashape.IsNull())
1259 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1261 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1264 TheAISContext()->UpdateCurrentViewer();
1271 //==============================================================================
1272 //function : VMaterial
1274 //purpose : change the Material of a selected or named or displayed shape
1275 //Draw arg : vmaterial [Name] Material
1276 //==============================================================================
1277 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1280 Standard_Boolean ThereIsCurrent;
1281 Standard_Boolean ThereIsName;
1282 Standard_Boolean IsBound = Standard_False ;
1284 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1286 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1287 ThereIsName = (argc != 2);
1290 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1291 ThereIsName = (argc == 2);
1294 if ( !a3DView().IsNull() ) {
1295 TCollection_AsciiString name;
1298 IsBound= GetMapOfAIS().IsBound2(name);
1300 if (TheAISContext()->HasOpenedContext())
1301 TheAISContext()->CloseLocalContext();
1302 if (TheAISContext() -> NbCurrents() > 0 )
1303 ThereIsCurrent =Standard_True;
1305 ThereIsCurrent =Standard_False;
1307 //=======================================================================
1308 // Ther is a name of shape and a material name
1309 //=======================================================================
1310 if ( ThereIsName && IsBound ) {
1311 Handle(AIS_InteractiveObject) ashape =
1312 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1313 if (!ashape.IsNull())
1315 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1317 TheAISContext()->UnsetMaterial(ashape);
1319 //=======================================================================
1320 // Il n'y a pas de nom de shape
1321 // Mais un ou plusieurs objets on des current representation
1322 //=======================================================================
1323 if (ThereIsCurrent && !ThereIsName) {
1324 for (TheAISContext() -> InitCurrent() ;
1325 TheAISContext() -> MoreCurrent() ;
1326 TheAISContext() ->NextCurrent() )
1328 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1330 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1332 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1334 TheAISContext()->UpdateCurrentViewer();
1337 //=======================================================================
1338 // Il n'y a pas de noms de shape ET aucun objet courrant
1339 // On impose a tous les objets du viewer le material passe en argument
1340 //=======================================================================
1341 else if (!ThereIsCurrent && !ThereIsName){
1342 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1344 while ( it.More() ) {
1345 Handle(AIS_InteractiveObject) ashape =
1346 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1347 if (!ashape.IsNull())
1349 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1351 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1354 TheAISContext()->UpdateCurrentViewer();
1362 //==============================================================================
1365 //purpose : change the width of the edges of a selected or named or displayed shape
1366 //Draw arg : vwidth [Name] WidthValue(1->10)
1367 //==============================================================================
1368 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1371 Standard_Boolean ThereIsCurrent;
1372 Standard_Boolean ThereIsArgument;
1373 Standard_Boolean IsBound = Standard_False ;
1375 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1377 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1378 ThereIsArgument = (argc != 2);
1381 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1382 ThereIsArgument = (argc == 2);
1384 if ( !a3DView().IsNull() ) {
1385 TCollection_AsciiString name;
1386 if (ThereIsArgument) {
1388 IsBound= GetMapOfAIS().IsBound2(name);
1390 if (TheAISContext()->HasOpenedContext())
1391 TheAISContext()->CloseLocalContext();
1393 if (TheAISContext() -> NbCurrents() > 0 )
1394 ThereIsCurrent =Standard_True;
1396 ThereIsCurrent =Standard_False;
1398 if ( ThereIsArgument && IsBound ) {
1399 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1400 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1401 const Handle(AIS_InteractiveObject) ashape =
1402 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1404 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1406 TheAISContext()->UnsetWidth (ashape);
1407 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1408 const Handle(NIS_Triangulated) ashape =
1409 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1410 if (HaveToSet && !ashape.IsNull())
1411 ashape->SetLineWidth ( atof (argv[2]) );
1415 //=======================================================================
1416 // Il n'y a pas d'arguments
1417 // Mais un ou plusieurs objets on des current representation
1418 //=======================================================================
1419 if (ThereIsCurrent && !ThereIsArgument) {
1420 for (TheAISContext() -> InitCurrent() ;
1421 TheAISContext() -> MoreCurrent() ;
1422 TheAISContext() ->NextCurrent() )
1424 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1426 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1428 TheAISContext()->UnsetWidth(ashape,Standard_False);
1430 TheAISContext()->UpdateCurrentViewer();
1432 //=======================================================================
1433 // Il n'y a pas d'arguments ET aucun objet courrant
1434 //=======================================================================
1435 else if (!ThereIsCurrent && !ThereIsArgument){
1436 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1438 while ( it.More() ) {
1439 Handle(AIS_InteractiveObject) ashape =
1440 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1441 if (!ashape.IsNull())
1443 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1445 TheAISContext()->UnsetWidth(ashape,Standard_False);
1448 TheAISContext()->UpdateCurrentViewer();
1454 //==============================================================================
1455 //function : VInteriorStyle
1456 //purpose : sets interior style of the a selected or named or displayed shape
1457 //Draw arg : vsetinteriorstyle [shape] style
1458 //==============================================================================
1459 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1460 const Standard_Integer theStyle,
1461 Draw_Interpretor& di)
1463 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1464 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1465 " (Aspect_IS_HIDDENLINE)]\n";
1468 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1469 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1470 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1471 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1472 aFillAspect->SetInteriorStyle (aStyle);
1473 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1476 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1478 if (argc < 2 || argc > 3) {
1479 di << argv[0] << " requires 2 or 3 arguments\n";
1480 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1481 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1482 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1486 Standard_Boolean ThereIsCurrent;
1487 Standard_Boolean ThereIsArgument;
1488 Standard_Boolean IsBound = Standard_False ;
1490 ThereIsArgument = (argc > 2);
1491 if ( !a3DView().IsNull() ) {
1492 TCollection_AsciiString name;
1493 if (ThereIsArgument) {
1495 IsBound= GetMapOfAIS().IsBound2(name);
1497 if (TheAISContext()->HasOpenedContext())
1498 TheAISContext()->CloseLocalContext();
1500 if (TheAISContext() -> NbCurrents() > 0 )
1501 ThereIsCurrent =Standard_True;
1503 ThereIsCurrent =Standard_False;
1505 if ( ThereIsArgument && IsBound ) {
1506 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1507 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1508 const Handle(AIS_InteractiveObject) ashape =
1509 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1510 SetInteriorStyle (ashape, atoi (argv[2]), di);
1513 //=======================================================================
1514 // No arguments specified
1515 // But there are one or more selected objects
1516 //=======================================================================
1517 if (ThereIsCurrent && !ThereIsArgument) {
1518 for (TheAISContext() -> InitCurrent() ;
1519 TheAISContext() -> MoreCurrent() ;
1520 TheAISContext() ->NextCurrent() )
1522 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1523 SetInteriorStyle (ashape, atoi (argv[1]), di);
1526 //=======================================================================
1527 // No arguments specified and there are no selected objects
1528 //=======================================================================
1529 else if (!ThereIsCurrent && !ThereIsArgument){
1530 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1532 while ( it.More() ) {
1533 Handle(AIS_InteractiveObject) ashape =
1534 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1535 if (!ashape.IsNull())
1536 SetInteriorStyle (ashape, atoi (argv[1]), di);
1540 TheAISContext()->UpdateCurrentViewer();
1545 //==============================================================================
1546 //function : VDonly2
1548 //purpose : Display only a selected or named object
1549 // if there is no selected or named object s, nothing is donne
1550 //Draw arg : vdonly2 [name1] ... [name n]
1551 //==============================================================================
1552 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1555 if ( a3DView().IsNull() )
1558 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1559 Standard_Boolean ThereIsArgument= argc>1;
1561 if (TheAISContext()->HasOpenedContext())
1562 TheAISContext()->CloseLocalContext();
1564 //===============================================================
1565 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1567 //===============================================================
1568 if (!ThereIsArgument && ThereIsCurrent) {
1571 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1574 for(TheAISContext()->InitCurrent();
1575 TheAISContext()->MoreCurrent();
1576 TheAISContext()->NextCurrent()){
1577 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1578 TheAISContext()->Erase(aShape,Standard_False);}
1580 TheAISContext() ->UpdateCurrentViewer();
1581 //===============================================================
1582 // Il y a des arguments
1583 //===============================================================
1584 if (ThereIsArgument) {
1585 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1587 while ( it.More() ) {
1588 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1589 const Handle(AIS_InteractiveObject) aShape =
1590 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1591 TheAISContext()->Erase(aShape,Standard_False);
1592 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1593 const Handle(NIS_InteractiveObject) aShape =
1594 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1595 TheNISContext()->Erase(aShape);
1600 // On display les objets passes par parametre
1601 for (int i=1; i<argc ; i++) {
1602 TCollection_AsciiString name=argv[i];
1603 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1605 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1606 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1607 const Handle(AIS_InteractiveObject) aShape =
1608 Handle(AIS_InteractiveObject)::DownCast (anObj);
1609 TheAISContext()->Display(aShape, Standard_False);
1610 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1611 Handle(NIS_InteractiveObject) aShape =
1612 Handle(NIS_InteractiveObject)::DownCast (anObj);
1613 TheNISContext()->Display(aShape);
1617 TheAISContext() ->UpdateCurrentViewer();
1618 // TheNISContext() ->UpdateViews();
1623 //==============================================================================
1624 //function : VErase2
1626 //purpose : Erase some selected or named objects
1627 // if there is no selected or named objects, the whole viewer is erased
1628 //Draw arg : verase2 [name1] ... [name n]
1629 //==============================================================================
1630 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1633 if ( a3DView().IsNull() )
1636 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1637 Standard_Boolean ThereIsArgument= argc>1;
1638 if(TheAISContext()->HasOpenedContext())
1639 TheAISContext()->CloseLocalContext();
1641 //===============================================================
1642 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1644 //===============================================================
1645 if (!ThereIsArgument && ThereIsCurrent) {
1646 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1648 while ( it.More() ) {
1649 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1650 const Handle(AIS_InteractiveObject) aShape =
1651 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1652 if (TheAISContext()->IsCurrent(aShape))
1653 TheAISContext()->Erase(aShape,Standard_False);
1658 TheAISContext() ->UpdateCurrentViewer();
1661 //===============================================================
1662 // Il n'y a pas d'arguments et aucuns objets selectionnes
1664 // On erase tout le viewer
1665 //===============================================================
1667 if (!ThereIsArgument && !ThereIsCurrent) {
1668 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1669 while ( it.More() ) {
1670 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1671 const Handle(AIS_InteractiveObject) aShape =
1672 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1673 TheAISContext()->Erase(aShape,Standard_False);
1674 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1675 const Handle(NIS_InteractiveObject) aShape =
1676 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1677 TheNISContext()->Erase(aShape);
1681 TheAISContext() ->UpdateCurrentViewer();
1682 // TheNISContext()->UpdateViews();
1685 //===============================================================
1686 // Il y a des arguments
1687 //===============================================================
1688 if (ThereIsArgument) {
1689 for (int i=1; i<argc ; i++) {
1690 TCollection_AsciiString name=argv[i];
1691 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1693 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1694 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1695 const Handle(AIS_InteractiveObject) aShape =
1696 Handle(AIS_InteractiveObject)::DownCast (anObj);
1697 TheAISContext()->Erase(aShape,Standard_False);
1698 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1699 const Handle(NIS_InteractiveObject) aShape =
1700 Handle(NIS_InteractiveObject)::DownCast (anObj);
1701 TheNISContext()->Erase(aShape);
1705 TheAISContext() ->UpdateCurrentViewer();
1706 // TheNISContext() ->UpdateViews();
1711 //==============================================================================
1712 //function : VEraseAll
1714 //purpose : Erase all the objects displayed in the viewer
1715 //Draw arg : veraseall
1716 //==============================================================================
1717 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1720 // Verification des arguments
1721 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1722 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1723 TheAISContext()->CloseAllContexts(Standard_False);
1724 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1726 while ( it.More() ) {
1727 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1728 const Handle(AIS_InteractiveObject) aShape =
1729 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1730 TheAISContext()->Erase(aShape,Standard_False);
1731 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1732 const Handle(NIS_InteractiveObject) aShape =
1733 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1734 TheNISContext()->Erase(aShape);
1738 TheAISContext() ->UpdateCurrentViewer();
1739 // TheNISContext() ->UpdateViews();
1744 //==============================================================================
1745 //function : VDisplayAll
1747 //purpose : Display all the objects of the Map
1748 //Draw arg : vdisplayall
1749 //==============================================================================
1750 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1753 if (! a3DView().IsNull() ) {
1754 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1755 if (TheAISContext()->HasOpenedContext())
1756 TheAISContext()->CloseLocalContext();
1757 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1759 while ( it.More() ) {
1760 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1761 const Handle(AIS_InteractiveObject) aShape =
1762 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1763 TheAISContext()->Erase(aShape,Standard_False);
1764 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1765 const Handle(NIS_InteractiveObject) aShape =
1766 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1767 TheNISContext()->Erase(aShape);
1772 while ( it.More() ) {
1773 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1774 const Handle(AIS_InteractiveObject) aShape =
1775 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1776 TheAISContext()->Display(aShape, Standard_False);
1777 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1778 Handle(NIS_InteractiveObject) aShape =
1779 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1780 TheNISContext()->Display(aShape);
1784 TheAISContext() ->UpdateCurrentViewer();
1785 // TheNISContext() ->UpdateViews();
1790 //#######################################################################################################
1794 //#######################################################################################################
1796 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1798 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1799 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1800 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1801 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1802 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1804 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1805 if(myAISContext.IsNull())
1807 di << "use 'vinit' command before " << argv[0] << "\n";
1811 Handle(AIS_InteractiveObject) TheAisIO;
1812 Handle(AIS_TexturedShape) myShape;
1813 Standard_Integer myPreviousMode = 0;
1815 if (argc<2 || !argv[1])
1817 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1821 TCollection_AsciiString name = argv[1];
1822 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1824 if (GetMapOfAIS().IsBound2(name))
1825 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1826 (GetMapOfAIS().Find2(name));
1827 if (TheAisIO.IsNull())
1829 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1833 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1835 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1836 myPreviousMode = myShape->DisplayMode() ;
1840 myAISContext->Clear(TheAisIO,Standard_False);
1841 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1842 GetMapOfAIS().UnBind1(TheAisIO);
1843 GetMapOfAIS().UnBind2(name);
1844 GetMapOfAIS().Bind(myShape, name);
1848 case 1: // vtexture : we only map a texture on the shape
1851 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1854 if (argc>2 && argv[2])
1856 if(strcasecmp(argv[2],"?")==0)
1858 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1859 di<<"\n Files in current directory : \n"<<"\n";
1860 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1861 di.Eval(Cmnd.ToCString());
1863 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1866 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1867 di.Eval(Cmnd.ToCString());
1872 myShape->SetTextureFileName(argv[2]);
1876 di <<"Texture mapping disabled \n \
1877 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1879 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1880 if (myPreviousMode == 3 )
1881 myAISContext->RecomputePrsOnly(myShape);
1882 myAISContext->Display(myShape, Standard_True);
1887 case 2: // vtexscale : we change the scaling factor of the texture
1891 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1895 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1896 ( argv[2] ? atof(argv[2]) : 1.0 ),
1897 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1900 case 3: // vtexorigin : we change the origin of the texture on the shape
1903 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1906 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1907 ( argv[2] ? atof(argv[2]) : 0.0 ),
1908 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1911 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1914 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1917 if (argc>2 && argv[2])
1919 di <<"Texture repeat enabled"<<"\n";
1920 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1924 di <<"Texture repeat disabled"<<"\n";
1925 myShape->SetTextureRepeat(Standard_False);
1929 case 5: // vtexdefault : default texture mapping
1930 // ScaleU = ScaleV = 100.0
1931 // URepeat = VRepeat = 1.0
1932 // Uorigin = VOrigin = 0.0
1936 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1939 myShape->SetTextureRepeat(Standard_False);
1940 myShape->SetTextureOrigin(Standard_False);
1941 myShape->SetTextureScale (Standard_False);
1945 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1946 myAISContext->RecomputePrsOnly(myShape);
1949 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1950 myAISContext->Display(myShape, Standard_True);
1951 myAISContext->Update(myShape,Standard_True);
1956 //==============================================================================
1957 //function : VDisplay2
1959 //purpose : Display an object from its name
1960 //Draw arg : vdisplay name1 [name2] ... [name n]
1961 //==============================================================================
1962 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1965 // Verification des arguments
1966 if ( a3DView().IsNull() ) {
1968 ViewerTest::ViewerInit();
1969 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1974 di<<argv[0]<<" Syntaxe error"<<"\n";
1979 TCollection_AsciiString name;
1980 if (TheAISContext()->HasOpenedContext())
1981 TheAISContext()->CloseLocalContext();
1983 for ( int i = 1; i < argc; i++ ) {
1985 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1986 Standard_Boolean IsDatum = Standard_False;
1987 Handle(Standard_Transient) anObj;
1989 anObj = GetMapOfAIS().Find2(name);
1990 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1991 Handle(AIS_InteractiveObject) aShape =
1992 Handle(AIS_InteractiveObject)::DownCast(anObj);
1993 if (aShape->Type()==AIS_KOI_Datum) {
1994 IsDatum = Standard_True;
1995 TheAISContext()->Display(aShape, Standard_False);
1998 di << "Display " << name.ToCString() << "\n";
1999 // Get the Shape from a name
2000 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2002 // Update the Shape in the AIS_Shape
2003 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2004 if(!TheRealSh.IsNull())
2005 TheRealSh->Set(NewShape);
2006 TheAISContext()->Redisplay(aShape, Standard_False);
2007 TheAISContext()->Display(aShape, Standard_False);
2010 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2011 Handle(NIS_InteractiveObject) aShape =
2012 Handle(NIS_InteractiveObject)::DownCast(anObj);
2013 TheNISContext()->Display(aShape);
2016 else { // Create the AIS_Shape from a name
2017 const Handle(AIS_InteractiveObject) aShape =
2018 GetAISShapeFromName((const char *)name.ToCString());
2019 if ( !aShape.IsNull() ) {
2020 GetMapOfAIS().Bind(aShape, name);
2021 TheAISContext()->Display(aShape, Standard_False);
2025 // Upadate the screen and redraw the view
2026 TheAISContext()->UpdateCurrentViewer();
2027 // TheNISContext()->UpdateViews();
2031 //==============================================================================
2033 //purpose : Test the annimation of an object along a
2034 // predifined trajectory
2035 //Draw arg : vmove ShapeName
2036 //==============================================================================
2039 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2044 if (TheAISContext()->HasOpenedContext())
2045 TheAISContext()->CloseLocalContext();
2047 Standard_Real Step=2*M_PI/180;
2048 Standard_Real Angle=0;
2049 // R est le rayon de l'hellicoide
2051 // D est la distance parcourue en translation en 1 tour
2054 Handle(AIS_InteractiveObject) aIO;
2056 if (GetMapOfAIS().IsBound2(argv[1]))
2057 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2060 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
2063 TheAISContext()->Deactivate(aIO);
2065 // boucle generant le mouvement
2067 di<<" Transformations"<<"\n";
2068 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2071 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) );
2073 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
2074 TheAISContext()->SetLocation(aIO,myTransfo);
2076 TheAISContext() ->UpdateCurrentViewer();
2081 di<<" Locations"<<"\n";
2082 gp_Trsf myAngleTrsf;
2083 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2084 TopLoc_Location myDeltaAngle (myAngleTrsf);
2086 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
2087 TopLoc_Location myDeltaDist (myDistTrsf);
2088 TopLoc_Location myTrueLoc;
2090 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2093 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2094 TheAISContext()->SetLocation(aIO,myTrueLoc );
2095 TheAISContext() ->UpdateCurrentViewer();
2100 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2102 //TopLoc_Location Tempo=aIO->Location();
2103 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2104 //ShapeBis.Located(Tempo);
2107 // On reset la location (origine) contenue dans l'AISInteractiveObject
2108 TheAISContext() ->ResetLocation(aIO);
2110 // On force aShape a devenir l'AIS IO propre a ShapeBis
2112 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2113 // ->Set() est une methode de AIS_Shape
2114 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2116 // On donne a ShapeBis le nom de l'AIS IO
2117 //Rep::Set(argv[1],ShapeBis);
2120 TheAISContext()->Redisplay(aIO,Standard_False);
2122 // On reactive la selection des primitives sensibles
2123 TheAISContext()->Activate(aIO,0);
2125 TheAISContext() ->UpdateCurrentViewer();
2126 a3DView() -> Redraw();
2129 di<<" Temps ecoule "<<"\n";
2137 //==============================================================================
2139 //purpose : Test the annimation of an object along a
2140 // predifined trajectory
2141 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2142 //==============================================================================
2144 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2147 if (TheAISContext()->HasOpenedContext())
2148 TheAISContext()->CloseLocalContext();
2150 Standard_Real Step=4*M_PI/180;
2151 Standard_Real Angle=0;
2153 Handle(AIS_InteractiveObject) aIO;
2154 if (GetMapOfAIS().IsBound2(argv[1]))
2155 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2159 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2163 if (atoi(argv[3])==1 ) {
2164 di<<" Primitives sensibles OFF"<<"\n";
2165 TheAISContext()->Deactivate(aIO);
2168 di<<" Primitives sensibles ON"<<"\n";
2170 // Movement par transformation
2171 if(atoi(argv[2]) ==1) {
2172 di<<" Calcul par Transformation"<<"\n";
2173 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2177 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2178 TheAISContext()->SetLocation(aShape,myTransfo);
2179 TheAISContext() ->UpdateCurrentViewer();
2184 di<<" Calcul par Locations"<<"\n";
2185 gp_Trsf myAngleTrsf;
2186 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2187 TopLoc_Location myDeltaAngle (myAngleTrsf);
2188 TopLoc_Location myTrueLoc;
2190 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2193 myTrueLoc=myTrueLoc*myDeltaAngle;
2194 TheAISContext()->SetLocation(aShape,myTrueLoc );
2195 TheAISContext() ->UpdateCurrentViewer();
2198 if (atoi(argv[3])==1 ){
2199 // On reactive la selection des primitives sensibles
2200 TheAISContext()->Activate(aIO,0);
2202 a3DView() -> Redraw();
2204 di<<" Temps ecoule "<<"\n";
2210 //==================================================================================
2211 // Function : VAnimation
2212 //==================================================================================
2213 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2215 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2219 Standard_Real thread = 4;
2220 Standard_Real angleA=0;
2221 Standard_Real angleB;
2223 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2226 TopoDS_Shape CrankArm;
2227 TopoDS_Shape CylinderHead;
2228 TopoDS_Shape Propeller;
2229 TopoDS_Shape EngineBlock;
2231 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2232 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2233 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2234 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2235 BRepTools::Read(CrankArm,argv[1],B);
2236 BRepTools::Read(CylinderHead,argv[2],B);
2237 BRepTools::Read(Propeller,argv[3],B);
2238 BRepTools::Read(EngineBlock,argv[4],B);
2240 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2246 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2247 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2248 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2249 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2251 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2252 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2253 GetMapOfAIS().Bind(myAisCrankArm,"c");
2254 GetMapOfAIS().Bind(myAisPropeller,"d");
2256 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2257 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2258 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2260 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2261 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2262 TheAISContext()->Display(myAisCrankArm,Standard_False );
2263 TheAISContext()->Display(myAisPropeller,Standard_False);
2265 TheAISContext()->Deactivate(myAisCylinderHead);
2266 TheAISContext()->Deactivate(myAisEngineBlock );
2267 TheAISContext()->Deactivate(myAisCrankArm );
2268 TheAISContext()->Deactivate(myAisPropeller );
2270 // Boucle de mouvement
2271 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2273 angleA = thread*myAngle*M_PI/180;
2274 X = Sin(angleA)*3/8;
2275 angleB = atan(X / Sqrt(-X * X + 1));
2276 Standard_Real decal(25*0.6);
2279 //Build a transformation on the display
2280 gp_Trsf aPropellerTrsf;
2281 aPropellerTrsf.SetRotation(Ax1,angleA);
2282 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2284 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));
2285 gp_Trsf aCrankArmTrsf;
2286 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2287 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2289 TheAISContext()->UpdateCurrentViewer();
2292 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2293 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2295 myAisCrankArm ->ResetLocation();
2296 myAisPropeller->ResetLocation();
2298 myAisCrankArm -> Set(myNewCrankArm );
2299 myAisPropeller -> Set(myNewPropeller);
2301 TheAISContext()->Activate(myAisCylinderHead,0);
2302 TheAISContext()->Activate(myAisEngineBlock,0 );
2303 TheAISContext()->Activate(myAisCrankArm ,0 );
2304 TheAISContext()->Activate(myAisPropeller ,0 );
2310 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2311 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2313 TheAISContext()->UpdateCurrentViewer();
2314 a3DView()->Redraw();
2323 //==============================================================================
2324 //function : VShading
2325 //purpose : Sharpen or roughten the quality of the shading
2326 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2327 //==============================================================================
2328 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2330 Standard_Real myDevCoef;
2331 Handle(AIS_InteractiveObject) TheAisIO;
2334 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2336 if (TheAISContext()->HasOpenedContext())
2337 TheAISContext()->CloseLocalContext();
2342 myDevCoef =atof(argv[2]);
2345 TCollection_AsciiString name=argv[1];
2346 if (GetMapOfAIS().IsBound2(name ))
2347 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2348 if (TheAisIO.IsNull())
2349 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2352 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2354 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2356 TheAISContext()->Redisplay(TheAisIO);
2359 //==============================================================================
2360 //function : HaveMode
2361 //use : VActivatedModes
2362 //==============================================================================
2363 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2365 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2367 TColStd_ListOfInteger List;
2368 TheAISContext()->ActivatedModes (TheAisIO,List);
2369 TColStd_ListIteratorOfListOfInteger it;
2370 Standard_Boolean Found=Standard_False;
2371 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2372 if (it.Value()==mode ) Found=Standard_True;
2379 //==============================================================================
2380 //function : VActivatedMode
2382 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2383 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2384 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2385 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2386 // qu'un nom et qu'un mode.
2387 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2388 //==============================================================================
2389 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2391 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2394 Standard_Boolean ThereIsName = Standard_False ;
2396 if(!a3DView().IsNull()){
2398 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2399 // verification des arguments
2401 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2402 ThereIsName = (argc == 3);
2406 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2408 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2409 di<<" Fermeture du Context local"<<"\n";
2410 if (TheAISContext()->HasOpenedContext())
2411 TheAISContext()->CloseLocalContext();
2415 // IL n'y a aps de nom de shape passe en argument
2416 if (HaveToSet && !ThereIsName){
2417 Standard_Integer aMode=atoi(argv [1]);
2419 const char *cmode="???";
2421 case 0: cmode = "Shape"; break;
2422 case 1: cmode = "Vertex"; break;
2423 case 2: cmode = "Edge"; break;
2424 case 3: cmode = "Wire"; break;
2425 case 4: cmode = "Face"; break;
2426 case 5: cmode = "Shell"; break;
2427 case 6: cmode = "Solid"; break;
2428 case 7: cmode = "Compound"; break;
2431 if( !TheAISContext()->HasOpenedContext() ) {
2432 // il n'y a pas de Context local d'ouvert
2433 // on en ouvre un et on charge toutes les shapes displayees
2434 // on load tous les objets displayees et on Activate les objets de la liste
2435 AIS_ListOfInteractive ListOfIO;
2436 // on sauve dans une AISListOfInteractive tous les objets currents
2437 if (TheAISContext()->NbCurrents()>0 ){
2438 TheAISContext()->UnhilightCurrents(Standard_False);
2440 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2441 ListOfIO.Append(TheAISContext()->Current() );
2445 TheAISContext()->OpenLocalContext(Standard_False);
2446 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2449 Handle(AIS_InteractiveObject) aIO =
2450 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2452 TheAISContext()->Load(aIO,0,Standard_False);
2455 // traitement des objets qui etaient currents dans le Contexte global
2456 if (!ListOfIO.IsEmpty() ) {
2457 // il y avait des objets currents
2458 AIS_ListIteratorOfListOfInteractive iter;
2459 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2460 Handle(AIS_InteractiveObject) aIO=iter.Value();
2461 TheAISContext()->Activate(aIO,aMode);
2462 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2466 // On applique le mode a tous les objets displayes
2467 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2468 it2 (GetMapOfAIS());
2470 Handle(AIS_InteractiveObject) aIO =
2471 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2472 if (!aIO.IsNull()) {
2473 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2474 TheAISContext()->Activate(aIO,aMode);
2483 // un Context local est deja ouvert
2484 // Traitement des objets du Context local
2485 if (TheAISContext()->NbSelected()>0 ){
2486 TheAISContext()->UnhilightSelected(Standard_False);
2487 // il y a des objets selected,on les parcourt
2488 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2489 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2492 if (HaveMode(aIO,aMode) ) {
2493 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2494 TheAISContext()->Deactivate(aIO,aMode);
2497 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2498 TheAISContext()->Activate(aIO,aMode);
2504 // il n'y a pas d'objets selected
2505 // tous les objets diplayes sont traites
2506 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2509 Handle(AIS_InteractiveObject) aIO =
2510 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2511 if (!aIO.IsNull()) {
2512 if (HaveMode(aIO,aMode) ) {
2513 di<<" Mode: "<<cmode<<" OFF pour "
2514 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2515 TheAISContext()->Deactivate(aIO,aMode);
2518 di<<" Mode: "<<cmode<<" ON pour"
2519 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2520 TheAISContext()->Activate(aIO,aMode);
2528 else if (HaveToSet && ThereIsName){
2529 Standard_Integer aMode=atoi(argv [2]);
2530 Handle(AIS_InteractiveObject) aIO =
2531 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2533 if (!aIO.IsNull()) {
2534 const char *cmode="???";
2537 case 0: cmode = "Shape"; break;
2538 case 1: cmode = "Vertex"; break;
2539 case 2: cmode = "Edge"; break;
2540 case 3: cmode = "Wire"; break;
2541 case 4: cmode = "Face"; break;
2542 case 5: cmode = "Shell"; break;
2543 case 6: cmode = "Solid"; break;
2544 case 7: cmode = "Compound"; break;
2547 if( !TheAISContext()->HasOpenedContext() ) {
2548 TheAISContext()->OpenLocalContext(Standard_False);
2549 // On charge tous les objets de la map
2550 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2552 Handle(AIS_InteractiveObject) aShape=
2553 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2554 if (!aShape.IsNull())
2555 TheAISContext()->Load(aShape,0,Standard_False);
2558 TheAISContext()->Activate(aIO,aMode);
2559 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2563 // un Context local est deja ouvert
2564 if (HaveMode(aIO,aMode) ) {
2565 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2566 TheAISContext()->Deactivate(aIO,aMode);
2569 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2570 TheAISContext()->Activate(aIO,aMode);
2582 //==============================================================================
2583 // function : WhoAmI
2585 //==============================================================================
2586 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2589 if (theShape->Type()==AIS_KOI_Datum) {
2590 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2591 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2592 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2593 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2594 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2595 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2596 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2599 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2600 // AIS_Dimentions et AIS_Relations
2601 else if (theShape->Type()==AIS_KOI_Relation) {
2602 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2604 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2605 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2606 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2607 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2608 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2609 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2610 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2611 // AIS no repertorie.
2612 else {di<<" Type Unknown.";}
2618 //==============================================================================
2621 //Draw arg : vstate [nameA] ... [nameN]
2622 //==============================================================================
2623 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2625 TheAISContext()->CloseAllContexts();
2626 const Standard_Boolean ThereIsArguments=(argc>=2);
2627 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2629 // ==================
2630 // Il y a un argument
2631 // ==================
2632 if (ThereIsArguments) {
2633 for (int cpt=1;cpt<argc;cpt++) {
2634 // Verification que lq piece est bien bindee.
2635 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2636 const Handle(AIS_InteractiveObject) theShape=
2637 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2639 if (!theShape.IsNull()) {
2640 di<<argv[cpt];WhoAmI(theShape, di);
2641 if (TheAISContext()->IsDisplayed(theShape) ) {
2642 di<<" Displayed"<<"\n";
2645 di<<" Not Displayed"<<"\n";
2650 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2654 else if (ThereIsCurrent ) {
2655 for (TheAISContext() -> InitCurrent() ;
2656 TheAISContext() -> MoreCurrent() ;
2657 TheAISContext() ->NextCurrent() )
2659 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2660 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2661 if (TheAISContext()->IsDisplayed(theShape) ) {
2662 di<<" Displayed"<<"\n";
2665 di<<" Not Displayed"<<"\n";
2671 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2673 while ( it.More() ) {
2674 Handle(AIS_InteractiveObject) theShape =
2675 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2676 if (!theShape.IsNull()) {
2677 di<<it.Key2().ToCString();
2678 WhoAmI(theShape, di);
2679 if (TheAISContext()->IsDisplayed(theShape) ) {
2680 di<<" Displayed"<<"\n";
2683 di<<" Not Displayed"<<"\n";
2694 //=======================================================================
2695 //function : PickObjects
2697 //=======================================================================
2698 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2699 const AIS_KindOfInteractive TheType,
2700 const Standard_Integer TheSignature,
2701 const Standard_Integer MaxPick)
2703 Handle(AIS_InteractiveObject) IO;
2704 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2706 // step 1: prepare the data
2708 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2709 TheAISContext()->AddFilter(F1);
2712 // step 2 : wait for the selection...
2713 // Standard_Boolean IsGood (Standard_False);
2714 // Standard_Integer NbPick(0);
2715 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2716 Standard_Integer NbPickFail(0);
2717 Standard_Integer argccc = 5;
2718 const char *bufff[] = { "A", "B", "C","D", "E" };
2719 const char **argvvv = (const char **) bufff;
2722 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2723 while(ViewerMainLoop(argccc,argvvv)){}
2724 Standard_Integer NbStored = TheAISContext()->NbSelected();
2725 if((unsigned int ) NbStored != NbPickGood)
2726 NbPickGood= NbStored;
2729 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2732 // step3 get result.
2734 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2736 Standard_Integer i(0);
2737 for(TheAISContext()->InitSelected();
2738 TheAISContext()->MoreSelected();
2739 TheAISContext()->NextSelected()){
2741 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2742 arr->SetValue(i,IO2);
2747 TheAISContext()->CloseLocalContext(curindex);
2749 return Standard_True;
2753 //=======================================================================
2754 //function : PickObject
2756 //=======================================================================
2757 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2758 const Standard_Integer TheSignature,
2759 const Standard_Integer MaxPick)
2761 Handle(AIS_InteractiveObject) IO;
2762 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2764 // step 1: prepare the data
2767 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2768 TheAISContext()->AddFilter(F1);
2771 // step 2 : wait for the selection...
2772 Standard_Boolean IsGood (Standard_False);
2773 Standard_Integer NbPick(0);
2774 Standard_Integer argccc = 5;
2775 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2776 const char **argvvv = (const char **) bufff;
2779 while(!IsGood && NbPick<= MaxPick){
2780 while(ViewerMainLoop(argccc,argvvv)){}
2781 IsGood = (TheAISContext()->NbSelected()>0) ;
2783 cout<<"Nb Pick :"<<NbPick<<endl;
2787 // step3 get result.
2789 TheAISContext()->InitSelected();
2790 IO = TheAISContext()->SelectedInteractive();
2794 TheAISContext()->CloseLocalContext(curindex);
2798 //=======================================================================
2799 //function : PickShape
2800 //purpose : First Activate the rightmode + Put Filters to be able to
2801 // pick objets that are of type <TheType>...
2802 //=======================================================================
2804 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2805 const Standard_Integer MaxPick)
2808 // step 1: prepare the data
2810 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2811 TopoDS_Shape result;
2813 if(TheType==TopAbs_SHAPE){
2814 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2815 TheAISContext()->AddFilter(F1);
2818 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2819 TheAISContext()->AddFilter(TF);
2820 TheAISContext()->ActivateStandardMode(TheType);
2825 // step 2 : wait for the selection...
2826 Standard_Boolean NoShape (Standard_True);
2827 Standard_Integer NbPick(0);
2828 Standard_Integer argccc = 5;
2829 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2830 const char **argvvv = (const char **) bufff;
2833 while(NoShape && NbPick<= MaxPick){
2834 while(ViewerMainLoop(argccc,argvvv)){}
2835 NoShape = (TheAISContext()->NbSelected()==0) ;
2837 cout<<"Nb Pick :"<<NbPick<<endl;
2840 // step3 get result.
2844 TheAISContext()->InitSelected();
2845 if(TheAISContext()->HasSelectedShape())
2846 result = TheAISContext()->SelectedShape();
2848 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2849 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2854 TheAISContext()->CloseLocalContext(curindex);
2860 //=======================================================================
2861 //function : PickShapes
2863 //=======================================================================
2864 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2865 Handle(TopTools_HArray1OfShape)& thearr,
2866 const Standard_Integer MaxPick)
2869 Standard_Integer Taille = thearr->Length();
2871 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2873 // step 1: prepare the data
2874 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2875 if(TheType==TopAbs_SHAPE){
2876 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2877 TheAISContext()->AddFilter(F1);
2880 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2881 TheAISContext()->AddFilter(TF);
2882 TheAISContext()->ActivateStandardMode(TheType);
2886 // step 2 : wait for the selection...
2888 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2889 Standard_Integer NbPickFail(0);
2890 Standard_Integer argccc = 5;
2891 const char *bufff[] = { "A", "B", "C","D", "E" };
2892 const char **argvvv = (const char **) bufff;
2895 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2896 while(ViewerMainLoop(argccc,argvvv)){}
2897 Standard_Integer NbStored = TheAISContext()->NbSelected();
2898 if((unsigned int ) NbStored != NbPickGood)
2899 NbPickGood= NbStored;
2902 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2905 // step3 get result.
2907 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2909 Standard_Integer i(0);
2910 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2912 if(TheAISContext()->HasSelectedShape())
2913 thearr->SetValue(i,TheAISContext()->SelectedShape());
2915 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2916 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2920 TheAISContext()->CloseLocalContext(curindex);
2921 return Standard_True;
2925 //=======================================================================
2926 //function : VPickShape
2928 //=======================================================================
2929 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2931 TopoDS_Shape PickSh;
2932 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2935 theType = TopAbs_SHAPE;
2937 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2938 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2939 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2940 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2941 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2942 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2943 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2946 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2947 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2949 TCollection_AsciiString name;
2952 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2954 PickSh = ViewerTest::PickShape(theType);
2963 if(!PickSh.IsNull()){
2964 nbOfSub[Standard_Integer(theType)]++;
2966 name += nameType[Standard_Integer(theType)];
2967 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2972 // si on avait une petite methode pour voir si la shape
2973 // est deja dans la Double map, ca eviterait de creer....
2974 DBRep::Set(name.ToCString(),PickSh);
2976 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2977 GetMapOfAIS().Bind(newsh, name);
2978 TheAISContext()->Display(newsh);
2979 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2982 // Plusieurs objets a picker, vite vite vite....
2985 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2986 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2987 if(ViewerTest::PickShapes(theType,arr)){
2988 for(Standard_Integer i=1;i<=NbToPick;i++){
2989 PickSh = arr->Value(i);
2990 if(!PickSh.IsNull()){
2992 nbOfSub[Standard_Integer(theType)]++;
2995 name += nameType[Standard_Integer(theType)];
2996 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3004 DBRep::Set(name.ToCString(),PickSh);
3005 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3006 GetMapOfAIS().Bind(newsh, name);
3007 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3008 TheAISContext()->Display(newsh);
3018 //=======================================================================
3019 //function : VPickObject
3020 //purpose : filters can be set (type of Object to pick....
3022 //=======================================================================
3025 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
3027 // preparation de la nomination automatique
3028 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
3029 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
3031 /* TCollection_AsciiString name;
3033 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3035 PickSh = ViewerTest::PickObject(theType);
3044 if(!PickSh.IsNull()){
3045 nbOfSub[Standard_Integer(theType)]++;
3047 name += nameType[Standard_Integer(theType)];
3048 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3053 // si on avait une petite methode pour voir si la shape
3054 // est deja dans la Double map, ca eviterait de creer....
3055 DBRep::Set(name.ToCString(),PickSh);
3057 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3058 GetMapOfAIS().Bind(newsh, name);
3059 TheAISContext()->Display(newsh);
3060 cout<<"Nom de la shape pickee : "<<name<<endl;
3063 // Plusieurs objets a picker, vite vite vite....
3066 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3067 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3068 if(ViewerTest::PickShapes(theType,arr)){
3069 for(Standard_Integer i=1;i<=NbToPick;i++){
3070 PickSh = arr->Value(i);
3071 if(!PickSh.IsNull()){
3073 nbOfSub[Standard_Integer(theType)]++;
3076 name += nameType[Standard_Integer(theType)];
3077 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3085 DBRep::Set(name.ToCString(),PickSh);
3086 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3087 GetMapOfAIS().Bind(newsh, name);
3088 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3089 TheAISContext()->Display(newsh);
3099 //=======================================================================
3100 //function : list of known objects
3102 //=======================================================================
3103 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3105 // 1234567890 12345678901234567 123456789
3106 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3107 TCollection_AsciiString BlankLine(64,'_');
3108 Standard_Integer i ;
3110 di<<"/n"<<BlankLine.ToCString()<<"\n";
3113 Colum[i].Center(20,' ');
3115 di<<"|"<<Colum[i].ToCString();
3118 di<<BlankLine.ToCString()<<"\n";
3120 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3121 const char ** names = GetTypeNames();
3123 TCollection_AsciiString curstring;
3124 TCollection_AsciiString curcolum[3];
3127 // les objets de type Datum..
3128 curcolum[1]+="Datum";
3130 curcolum[0].Clear();
3131 curcolum[0] += names[i];
3133 curcolum[2].Clear();
3134 curcolum[2]+=TCollection_AsciiString(i+1);
3136 for(Standard_Integer j =0;j<=2;j++){
3137 curcolum[j].Center(20,' ');
3138 di<<"|"<<curcolum[j].ToCString();
3142 di<<BlankLine.ToCString()<<"\n";
3144 // les objets de type shape
3145 curcolum[1].Clear();
3146 curcolum[1]+="Shape";
3147 curcolum[1].Center(20,' ');
3150 curcolum[0].Clear();
3151 curcolum[0] += names[7+i];
3152 curcolum[2].Clear();
3153 curcolum[2]+=TCollection_AsciiString(i);
3155 for(Standard_Integer j =0;j<=2;j++){
3156 curcolum[j].Center(20,' ');
3157 di<<"|"<<curcolum[j].ToCString();
3161 di<<BlankLine.ToCString()<<"\n";
3162 // les IO de type objet...
3163 curcolum[1].Clear();
3164 curcolum[1]+="Object";
3165 curcolum[1].Center(20,' ');
3167 curcolum[0].Clear();
3168 curcolum[0] += names[10+i];
3169 curcolum[2].Clear();
3170 curcolum[2]+=TCollection_AsciiString(i);
3172 for(Standard_Integer j =0;j<=2;j++){
3173 curcolum[j].Center(20,' ');
3174 di<<"|"<<curcolum[j].ToCString();
3178 di<<BlankLine.ToCString()<<"\n";
3179 // les contraintes et dimensions.
3180 // pour l'instant on separe juste contraintes et dimensions...
3181 // plus tard, on detaillera toutes les sortes...
3182 curcolum[1].Clear();
3183 curcolum[1]+="Relation";
3184 curcolum[1].Center(20,' ');
3186 curcolum[0].Clear();
3187 curcolum[0] += names[12+i];
3188 curcolum[2].Clear();
3189 curcolum[2]+=TCollection_AsciiString(i);
3191 for(Standard_Integer j =0;j<=2;j++){
3192 curcolum[j].Center(20,' ');
3193 di<<"|"<<curcolum[j].ToCString();
3197 di<<BlankLine.ToCString()<<"\n";
3204 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3206 if(argc!=2) return 1;
3208 AIS_KindOfInteractive TheType;
3209 Standard_Integer TheSign(-1);
3210 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3213 AIS_ListOfInteractive LIO;
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 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3224 Handle(AIS_InteractiveObject) curio;
3225 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3228 if(dimension_status == -1)
3229 TheAISContext()->Erase(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()->Erase(curio,Standard_False);
3237 TheAISContext()->UpdateCurrentViewer();
3240 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3242 if(argc!=2) return 1;
3244 AIS_KindOfInteractive TheType;
3245 Standard_Integer TheSign(-1);
3246 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3248 // en attendant l'amelioration ais pour les dimensions...
3250 Standard_Integer dimension_status(-1);
3251 if(TheType==AIS_KOI_Relation){
3252 dimension_status = TheSign ==1 ? 1 : 0;
3256 AIS_ListOfInteractive LIO;
3257 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3258 Handle(AIS_InteractiveObject) curio;
3259 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3261 if(dimension_status == -1)
3262 TheAISContext()->Display(curio,Standard_False);
3264 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3265 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3266 (dimension_status==1 && KOD != AIS_KOD_NONE))
3267 TheAISContext()->Display(curio,Standard_False);
3272 TheAISContext()->UpdateCurrentViewer();
3276 //==============================================================================
3277 //function : VSetTransMode
3279 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3280 //==============================================================================
3282 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3283 // Verification des arguments
3284 if ( a3DView().IsNull() ) {
3285 ViewerTest::ViewerInit();
3286 di << "La commande vinit n'a pas ete appele avant" << "\n";
3289 if ( argc < 3 || argc > 8 ) {
3290 di << argv[0] << " Invalid number of arguments" << "\n";
3294 TCollection_AsciiString shapeName;
3295 shapeName = argv[1];
3296 Standard_Integer persFlag1 = atoi(argv[2]);
3297 Standard_Integer persFlag2 = 0;
3298 Standard_Integer persFlag3 = 0;
3299 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3300 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3301 persFlag2 = atoi(argv[3]);
3303 if ( argc == 5 || argc == 8 ) {
3304 persFlag3 = atoi(argv[4]);
3307 origin.SetX( atof(argv[argc - 3]) );
3308 origin.SetY( atof(argv[argc - 2]) );
3309 origin.SetZ( atof(argv[argc - 1]) );
3312 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3313 Handle(Standard_Transient) anObj;
3315 anObj = GetMapOfAIS().Find2(shapeName);
3316 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3317 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3318 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3319 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3320 di << argv[0] << " All persistence modifiers were removed" << "\n";
3323 di << argv[0] << " Wrong object type" << "\n";
3326 } else { // Create the AIS_Shape from a name
3327 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3328 if ( !aShape.IsNull() ) {
3329 GetMapOfAIS().Bind( aShape, shapeName );
3330 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3331 TheAISContext()->Display( aShape, Standard_False );
3333 di << argv[0] << " Object not found" << "\n";
3338 // Upadate the screen and redraw the view
3339 TheAISContext()->UpdateCurrentViewer();
3343 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3346 BRep_Builder builder;
3348 BRepTools::Read(shape, s, builder);
3349 DBRep::Set(a[1], shape);
3350 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3351 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3355 //============================================================================
3356 #include <AIS2D_InteractiveContext.hxx>
3357 #include <HLRAlgo_Projector.hxx>
3358 #include <Prs3d_Projector.hxx>
3359 #include <AIS2D_ProjShape.hxx>
3360 #include <gp_Ax2.hxx>
3362 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3365 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3366 /////////////////////
3367 TopoDS_Shape aShape = DBRep::Get(a[1]);
3368 aContext2D->EraseAll(Standard_True);
3369 //Standard_Integer aPolyAlgo = 0;
3370 Standard_Boolean IsPoly = Standard_False;
3371 gp_Ax2 anAx2 = gp::XOY();
3373 //if(n > 2) aPolyAlgo = atoi(a[2]);
3375 //IsPoly = aPolyAlgo > 0;
3377 TopoDS_Shape aResult = aShape;
3382 Standard_Real x = atof(a[2]);
3383 Standard_Real y = atof(a[3]);
3384 Standard_Real z = atof(a[4]);
3386 Standard_Real dx = atof(a[5]);
3387 Standard_Real dy = atof(a[6]);
3388 Standard_Real dz = atof(a[7]);
3390 Standard_Real dx1 = atof(a[8]);
3391 Standard_Real dy1 = atof(a[9]);
3392 Standard_Real dz1 = atof(a[10]);
3394 gp_Pnt anOrigin (x, y, z);
3395 gp_Dir aNormal (dx, dy, dz);
3396 gp_Dir aDX (dx1, dy1, dz1);
3397 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3401 HLRAlgo_Projector aProjector(anAx2);
3403 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3405 //aProjector = aProjector_t.Projector();
3407 Handle(AIS2D_ProjShape) myDisplayableShape =
3408 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3410 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3411 Standard_False, Standard_True, Standard_False);
3413 myDisplayableShape->Add( aResult );
3416 aContext2D->Display( myDisplayableShape,Standard_True );
3417 aContext2D->UpdateCurrentViewer();
3422 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3425 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3426 /////////////////////
3427 TopoDS_Shape aShape = DBRep::Get(a[1]);
3428 aContext2D->EraseAll(Standard_True);
3429 //Standard_Integer aPolyAlgo = 0;
3430 Standard_Boolean IsPoly = Standard_True;
3431 gp_Ax2 anAx2 = gp::XOY();
3433 //if(n > 2) aPolyAlgo = atoi(a[2]);
3435 //IsPoly = aPolyAlgo > 0;
3437 TopoDS_Shape aResult = aShape;
3442 Standard_Real x = atof(a[2]);
3443 Standard_Real y = atof(a[3]);
3444 Standard_Real z = atof(a[4]);
3446 Standard_Real dx = atof(a[5]);
3447 Standard_Real dy = atof(a[6]);
3448 Standard_Real dz = atof(a[7]);
3450 Standard_Real dx1 = atof(a[8]);
3451 Standard_Real dy1 = atof(a[9]);
3452 Standard_Real dz1 = atof(a[10]);
3454 gp_Pnt anOrigin (x, y, z);
3455 gp_Dir aNormal (dx, dy, dz);
3456 gp_Dir aDX (dx1, dy1, dz1);
3457 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3461 HLRAlgo_Projector aProjector(anAx2);
3463 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3465 //aProjector = aProjector_t.Projector();
3467 Handle(AIS2D_ProjShape) myDisplayableShape =
3468 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3470 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3471 Standard_False, Standard_True, Standard_False);
3473 myDisplayableShape->Add( aResult );
3476 aContext2D->Display( myDisplayableShape,Standard_True );
3477 aContext2D->UpdateCurrentViewer();
3482 //==============================================================================
3483 //function : ViewerTest::Commands
3484 //purpose : Add all the viewer command in the Draw_Interpretor
3485 //==============================================================================
3487 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3489 ViewerTest::ViewerCommands(theCommands);
3490 ViewerTest::RelationCommands(theCommands);
3491 ViewerTest::ObjectCommands(theCommands);
3492 ViewerTest::FilletCommands(theCommands);
3493 ViewerTest::VoxelCommands(theCommands);
3494 ViewerTest::OpenGlCommands(theCommands);
3496 const char *group = "AIS_Display";
3500 theCommands.Add("vdisplay",
3501 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3502 __FILE__,VDisplay2,group);
3504 theCommands.Add("verase",
3505 "verase : verase2 [name1] ... [name n] ",
3506 __FILE__,VErase2,group);
3508 theCommands.Add("vdonly",
3509 "vdonly : vdonly2 [name1] ... [name n]",
3510 __FILE__,VDonly2,group);
3512 theCommands.Add("vdisplayall",
3513 "vdisplayall : vdisplayall",
3514 __FILE__,VDisplayAll,group);
3516 theCommands.Add("veraseall",
3517 "veraseall : veraseall ",
3518 __FILE__,VEraseAll,group);
3520 theCommands.Add("verasetype",
3521 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3522 __FILE__,VEraseType,group);
3524 theCommands.Add("vdisplaytype",
3525 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3526 __FILE__,VDisplayType,group);
3528 theCommands.Add("vdisplaymode",
3529 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3530 __FILE__,VDispMode,group);
3532 theCommands.Add("verasemode",
3533 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3534 __FILE__,VDispMode,group);
3536 theCommands.Add("vsetdispmode",
3537 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3538 __FILE__,VDispMode,group);
3540 theCommands.Add("vunsetdispmode",
3541 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3542 __FILE__,VDispMode,group);
3544 theCommands.Add("vdir",
3546 __FILE__,VDebug,group);
3548 theCommands.Add("vdump",
3549 "<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",
3550 __FILE__,VDump,group);
3552 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3553 __FILE__,VSubInt,group);
3555 theCommands.Add("vsetcolor",
3556 "vsetcolor : vsetcolor [name of shape] ColorName",
3557 __FILE__,VColor2,group);
3559 theCommands.Add("vunsetcolor",
3560 "vunsetcolor : vunsetcolor [name of shape] ",
3561 __FILE__,VColor2,group);
3563 theCommands.Add("vsettransparency",
3564 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3565 __FILE__,VTransparency,group);
3567 theCommands.Add("vunsettransparency",
3568 "vunsettransparency : vtransparency [name of shape]",
3569 __FILE__,VTransparency,group);
3571 theCommands.Add("vsetmaterial",
3572 "vmaterial : vmaterial [name of shape] MaterialName",
3573 __FILE__,VMaterial,group);
3575 theCommands.Add("vunsetmaterial",
3576 "vmaterial : vmaterial [name of shape]",
3577 __FILE__,VMaterial,group);
3579 theCommands.Add("vsetwidth",
3580 "vsetwidth : vwidth [name of shape] width(0->10)",
3581 __FILE__,VWidth,group);
3583 theCommands.Add("vunsetwidth",
3584 "vunsetwidth : vwidth [name of shape]",
3585 __FILE__,VWidth,group);
3587 theCommands.Add("vsetinteriorstyle",
3588 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3589 __FILE__,VInteriorStyle,group);
3591 theCommands.Add("vardis",
3592 "vardis : display activeareas",
3593 __FILE__,VDispAreas,group);
3595 theCommands.Add("varera",
3596 "varera : erase activeareas",
3597 __FILE__,VClearAreas,group);
3599 theCommands.Add("vsensdis",
3600 "vardisp : display active entities",
3601 __FILE__,VDispSensi,group);
3602 theCommands.Add("vsensera",
3603 "vardisp : erase active entities",
3604 __FILE__,VClearSensi,group);
3606 theCommands.Add("vselprecision",
3607 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3608 __FILE__,VSelPrecision,group);
3610 theCommands.Add("vperf",
3611 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3612 __FILE__,VPerf,group);
3614 theCommands.Add("vanimation",
3615 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3616 __FILE__,VAnimation,group);
3618 theCommands.Add("vsetshading",
3619 "vsetshading : vsetshading name Quality(default=0.0008) ",
3620 __FILE__,VShading,group);
3622 theCommands.Add("vunsetshading",
3623 "vunsetshading :vunsetshading name ",
3624 __FILE__,VShading,group);
3626 theCommands.Add("vtexture",
3627 "'vtexture NameOfShape TextureFile' \n \
3628 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3629 or 'vtexture NameOfShape ?' to list available textures\n \
3630 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3631 __FILE__,VTexture,group);
3633 theCommands.Add("vtexscale",
3634 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3635 or 'vtexscale NameOfShape ScaleUV' \n \
3636 or 'vtexscale NameOfShape' to disable scaling\n ",
3637 __FILE__,VTexture,group);
3639 theCommands.Add("vtexorigin",
3640 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3641 or 'vtexorigin NameOfShape UVOrigin' \n \
3642 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3643 __FILE__,VTexture,group);
3645 theCommands.Add("vtexrepeat",
3646 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3647 or 'vtexrepeat NameOfShape UVRepeat \n \
3648 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3651 theCommands.Add("vtexdefault",
3652 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3655 theCommands.Add("vsetam",
3656 "vsetActivatedModes: vsetam mode(1->7) ",
3657 __FILE__,VActivatedMode,group);
3659 theCommands.Add("vunsetam",
3660 "vunsetActivatedModes: vunsetam ",
3661 __FILE__,VActivatedMode,group);
3663 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3664 __FILE__,VState,group);
3666 theCommands.Add("vpickshapes",
3667 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3668 __FILE__,VPickShape,group);
3670 theCommands.Add("vtypes",
3671 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3674 theCommands.Add("vsettransmode",
3675 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3676 __FILE__,VSetTransMode,group);
3678 theCommands.Add("vr", "vr : reading of the shape",
3679 __FILE__,vr, group);
3681 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3682 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3686 //=====================================================================
3687 //========================= for testing Draft and Rib =================
3688 //=====================================================================
3689 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3690 #include <DBRep.hxx>
3691 #include <TopoDS_Face.hxx>
3692 #include <gp_Pln.hxx>
3693 #include <AIS_KindOfSurface.hxx>
3694 #include <BRepOffsetAPI_DraftAngle.hxx>
3695 #include <Precision.hxx>
3696 #include <BRepAlgo.hxx>
3697 #include <OSD_Environment.hxx>
3698 #include <DrawTrSurf.hxx>
3699 //#include <DbgTools.hxx>
3700 //#include <FeatAlgo_MakeLinearForm.hxx>
3705 //=======================================================================
3706 //function : IsValid
3708 //=======================================================================
3709 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3710 const TopoDS_Shape& theResult,
3711 const Standard_Boolean closedSolid,
3712 const Standard_Boolean GeomCtrl)
3714 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3715 TCollection_AsciiString checkValid = check.Value();
3716 Standard_Boolean ToCheck = Standard_True;
3717 if (!checkValid.IsEmpty()) {
3719 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3721 if ( checkValid=="true" || checkValid=="TRUE" ) {
3722 ToCheck= Standard_False;
3726 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3729 Standard_Boolean IsValid = Standard_True;
3731 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3736 //===============================================================================
3737 // TDraft : test draft, uses AIS Viewer
3738 // Solid Face Plane Angle Reverse
3739 //===============================================================================
3740 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3742 if (argc < 5) return 1;
3743 // argv[1] - TopoDS_Shape Solid
3744 // argv[2] - TopoDS_Shape Face
3745 // argv[3] - TopoDS_Shape Plane
3746 // argv[4] - Standard_Real Angle
3747 // argv[5] - Standard_Integer Reverse
3749 // sprintf(prefix, argv[1]);
3750 Standard_Real anAngle = 0;
3751 Standard_Boolean Rev = Standard_False;
3752 Standard_Integer rev = 0;
3753 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3754 TopoDS_Shape face = GetShapeFromName(argv[2]);
3755 TopoDS_Face Face = TopoDS::Face(face);
3756 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3757 if (Plane.IsNull ()) {
3758 di << "TEST : Plane is NULL" << "\n";
3761 anAngle = atof(argv[4]);
3762 anAngle = 2*M_PI * anAngle / 360.0;
3764 Handle( Geom_Surface )aSurf;
3765 AIS_KindOfSurface aSurfType;
3766 Standard_Real Offset;
3768 if(argc > 4) { // == 5
3769 rev = atoi(argv[5]);
3770 Rev = (rev)? Standard_True : Standard_False;
3773 TopoDS_Face face2 = TopoDS::Face(Plane);
3774 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3776 di << "TEST : Can't find plane" << "\n";
3780 aDir = aPln.Axis().Direction();
3783 if (Plane.Orientation() == TopAbs_REVERSED)
3785 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3787 BRepOffsetAPI_DraftAngle Draft (Solid);
3789 if(Abs(anAngle)< Precision::Angular()) {
3790 di << "TEST : NULL angle" << "\n";
3793 if(Rev) anAngle = - anAngle;
3794 Draft.Add (Face, aDir, anAngle, aPln);
3796 if (!Draft.IsDone()) {
3797 di << "TEST : Draft Not DONE " << "\n";
3800 TopTools_ListOfShape Larg;
3802 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3803 di << "TEST : DesignAlgo returns Not valid" << "\n";
3807 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3808 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3810 if ( !ais.IsNull() ) {
3811 ais->SetColor(DEFAULT_COLOR);
3812 ais->SetMaterial(DEFAULT_MATERIAL);
3813 // Display the AIS_Shape without redraw
3814 Ctx->Display(ais, Standard_False);
3816 const char *Name = "draft1";
3817 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3819 Handle(AIS_InteractiveObject) an_object =
3820 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3821 if (!an_object.IsNull()) {
3822 Ctx->Remove(an_object,
3824 GetMapOfAIS().UnBind2(Name) ;
3827 GetMapOfAIS().Bind(ais, Name);
3828 // DBRep::Set("draft", ais->Shape());
3830 Ctx->Display(ais, Standard_True);
3836 //============================================================================
3838 //============================================================================
3839 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3842 DrawTrSurf::BasicCommands(theCommands);
3843 const char* group = "Check Features Operations commands";
3845 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3847 &TDraft,group); //Draft_Modification
3850 //==============================================================================
3851 // ViewerTest::Factory
3852 //==============================================================================
3853 void ViewerTest::Factory(Draw_Interpretor& theDI)
3855 // definition of Viewer Command
3856 ViewerTest::Commands(theDI);
3857 ViewerTest::AviCommands(theDI);
3858 Viewer2dTest::Commands(theDI);
3860 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3864 // Declare entry point PLUGINFACTORY