1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_InteractiveObject.hxx>
47 #include <AIS_Trihedron.hxx>
48 #include <AIS_Axis.hxx>
49 #include <AIS_Relation.hxx>
50 #include <AIS_TypeFilter.hxx>
51 #include <AIS_SignatureFilter.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Image_PixMap.hxx>
64 #include <Draw_Interpretor.hxx>
65 #include <TCollection_AsciiString.hxx>
66 #include <Draw_PluginMacro.hxx>
67 #include <ViewerTest.hxx>
68 #include <Viewer2dTest.hxx>
70 // avoid warnings on 'extern "C"' functions returning C++ classes
72 #define _CRT_SECURE_NO_DEPRECATE
73 #pragma warning(4:4190)
74 #pragma warning (disable:4996)
77 #include <NIS_InteractiveContext.hxx>
78 #include <NIS_Triangulated.hxx>
79 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
81 //=======================================================================
82 //function : GetColorFromName
83 //purpose : get the Quantity_NameOfColor from a string
84 //=======================================================================
86 #include <Quantity_NameOfColor.hxx>
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
95 static Quantity_NameOfColor GetColorFromName( const char *name )
97 Quantity_NameOfColor ret = DEFAULT_COLOR;
99 Standard_Boolean Found = Standard_False;
100 Standard_CString colstring;
101 for(Standard_Integer i=0;i<=514 && !Found;i++)
103 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
104 if (!strcasecmp(name,colstring)) {
105 ret = (Quantity_NameOfColor)i;
106 Found = Standard_True;
113 //=======================================================================
114 //function : GetMaterialFromName
115 //purpose : get the Graphic3d_NameOfMaterial from a string
116 //=======================================================================
118 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
120 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
122 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
123 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
124 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
125 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
126 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
127 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
128 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
129 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
130 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
131 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
132 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
133 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
134 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
135 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
136 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
137 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
138 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
139 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
140 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
141 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
146 //=======================================================================
147 //function : GetTypeNames
149 //=======================================================================
150 static const char** GetTypeNames()
152 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
153 "Shape","ConnectedShape","MultiConn.Shape",
154 "ConnectedInter.","MultiConn.",
155 "Constraint","Dimension"};
156 static const char** ThePointer = names;
160 //=======================================================================
161 //function : GetTypeAndSignfromString
163 //=======================================================================
164 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
166 const char ** thefullnames = GetTypeNames();
167 Standard_Integer index(-1);
169 for(Standard_Integer i=0;i<=13 && index==-1;i++)
170 if(!strcasecmp(name,thefullnames[i]))
174 TheType = AIS_KOI_None;
180 TheType = AIS_KOI_Datum;
184 TheType = AIS_KOI_Shape;
188 TheType = AIS_KOI_Object;
192 TheType = AIS_KOI_Relation;
201 #include <Draw_Interpretor.hxx>
203 #include <Draw_Appli.hxx>
207 #include <TCollection_AsciiString.hxx>
208 #include <V3d_Viewer.hxx>
209 #include <V3d_View.hxx>
212 #include <AIS_InteractiveContext.hxx>
213 #include <AIS_Shape.hxx>
214 #include <AIS_TexturedShape.hxx>
215 #include <AIS_DisplayMode.hxx>
216 #include <TColStd_MapOfInteger.hxx>
217 #include <AIS_MapOfInteractive.hxx>
218 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
219 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
220 #include <ViewerTest_EventManager.hxx>
222 #include <TopoDS_Solid.hxx>
223 #include <BRepTools.hxx>
224 #include <BRep_Builder.hxx>
225 #include <TopAbs_ShapeEnum.hxx>
227 #include <TopoDS.hxx>
228 #include <BRep_Tool.hxx>
231 #include <Draw_Window.hxx>
232 #include <AIS_ListIteratorOfListOfInteractive.hxx>
233 #include <AIS_ListOfInteractive.hxx>
234 #include <AIS_DisplayMode.hxx>
235 #include <TopTools_ListOfShape.hxx>
236 #include <BRepOffsetAPI_MakeThickSolid.hxx>
237 #include <BRepOffset.hxx>
240 //==============================================================================
241 //function : GetTypeNameFromShape
242 //purpose : get the shape type as a string from a shape
243 //==============================================================================
245 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
246 { const char *ret = "????";
248 if ( aShape.IsNull() ) ret = "Null Shape";
250 switch ( aShape.ShapeType() ) {
251 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
252 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
253 case TopAbs_SOLID : ret = "SOLID" ; break;
254 case TopAbs_SHELL : ret = "SHELL" ; break;
255 case TopAbs_FACE : ret = "FACE" ; break;
256 case TopAbs_WIRE : ret = "WIRE" ; break;
257 case TopAbs_EDGE : ret = "EDGE" ; break;
258 case TopAbs_VERTEX : ret = "VERTEX" ; break;
259 case TopAbs_SHAPE : ret = "SHAPE" ; break;
263 //==============================================================================
264 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
265 //==============================================================================
266 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
267 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
272 //==============================================================================
273 //function : VDisplayAISObject
274 //purpose : register interactive object in the map of AIS objects;
275 // if other object with such name already registered, it will be kept
276 // or replaced depending on value of <theReplaceIfExists>,
277 // if "true" - the old object will be cleared from AIS context;
278 // returns Standard_True if <theAISObj> registered in map;
279 //==============================================================================
280 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
281 const Handle(AIS_InteractiveObject)& theAISObj,
282 Standard_Boolean theReplaceIfExists = Standard_True)
284 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
285 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
286 if (aContextAIS.IsNull())
288 std::cout << "AIS context is not available.\n";
289 return Standard_False;
292 if (aMap.IsBound2 (theName))
294 if (!theReplaceIfExists)
296 std::cout << "Other interactive object has been already "
297 << "registered with name: " << theName << ".\n"
298 << "Please use another name.\n";
299 return Standard_False;
302 // stop displaying object
303 Handle(AIS_InteractiveObject) anOldObj =
304 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
306 if (!anOldObj.IsNull())
307 aContextAIS->Clear (anOldObj, Standard_True);
309 // remove name and old object from map
310 aMap.UnBind2 (theName);
313 // unbind AIS object if was bound with another name
314 aMap.UnBind1 (theAISObj);
316 // can be registered without rebinding
317 aMap.Bind (theAISObj, theName);
318 aContextAIS->Display (theAISObj, Standard_True);
319 return Standard_True;
322 static TColStd_MapOfInteger theactivatedmodes(8);
323 static TColStd_ListOfTransient theEventMgrs;
325 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
326 const Handle(AIS_InteractiveContext)& Ctx)
328 theEventMgrs.Clear();
329 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
332 static Handle(V3d_View)& a3DView(){
333 static Handle(V3d_View) Viou;
337 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
338 static Handle(AIS_InteractiveContext) aContext;
342 Handle(V3d_View) ViewerTest::CurrentView()
346 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
351 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
353 static Handle(NIS_InteractiveContext) aContext;
354 if (aContext.IsNull()) {
355 aContext = new NIS_InteractiveContext;
356 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
361 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
363 return TheAISContext();
366 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
368 TheAISContext() = aCtx;
369 ViewerTest::ResetEventManager();
372 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
374 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
377 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
379 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
383 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
384 theEventMgrs.Prepend(EM);
387 void ViewerTest::UnsetEventManager()
389 theEventMgrs.RemoveFirst();
393 void ViewerTest::ResetEventManager()
395 const Handle(NIS_View) aView =
396 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
397 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
400 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
402 Handle(ViewerTest_EventManager) EM;
403 if(theEventMgrs.IsEmpty()) return EM;
404 Handle(Standard_Transient) Tr = theEventMgrs.First();
405 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
410 //=======================================================================
411 //function : Get Context and active viou..
413 //=======================================================================
414 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
415 Handle(V3d_View)& Viou)
417 Ctx = ViewerTest::GetAISContext();
420 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
421 Vwr->InitActiveViews();
422 if(Vwr->MoreActiveViews())
423 Viou = Vwr->ActiveView();
428 //==============================================================================
429 //function : GetShapeFromName
430 //purpose : Compute an Shape from a draw variable or a file name
431 //==============================================================================
433 static TopoDS_Shape GetShapeFromName(const char* name)
435 TopoDS_Shape S = DBRep::Get(name);
438 BRep_Builder aBuilder;
439 BRepTools::Read( S, name, aBuilder);
444 //==============================================================================
445 //function : GetShapeFromName
446 //purpose : Compute an Shape from a draw variable or a file name
447 //==============================================================================
450 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
452 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
456 //==============================================================================
457 //function : GetAISShapeFromName
458 //purpose : Compute an AIS_Shape from a draw variable or a file name
459 //==============================================================================
460 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
462 Handle(AIS_Shape) retsh;
464 if(GetMapOfAIS().IsBound2(name)){
465 const Handle(AIS_InteractiveObject) IO =
466 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
468 if(IO->Type()==AIS_KOI_Shape)
469 if(IO->Signature()==0){
470 retsh = *((Handle(AIS_Shape)*)&IO);
473 cout << "an Object which is not an AIS_Shape "
474 "already has this name!!!"<<endl;
480 TopoDS_Shape S = GetShapeFromName(name);
482 retsh = new AIS_Shape(S);
488 //==============================================================================
490 //purpose : Remove all the object from the viewer
491 //==============================================================================
492 void ViewerTest::Clear()
494 if ( !a3DView().IsNull() ) {
495 if (TheAISContext()->HasOpenedContext())
496 TheAISContext()->CloseLocalContext();
497 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
498 while ( it.More() ) {
499 cout << "Remove " << it.Key2() << endl;
500 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
501 const Handle(AIS_InteractiveObject) anObj =
502 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
503 TheAISContext()->Remove(anObj,Standard_False);
504 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
505 const Handle(NIS_InteractiveObject) anObj =
506 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
507 TheNISContext()->Remove(anObj);
511 TheAISContext()->UpdateCurrentViewer();
512 // TheNISContext()->UpdateViews();
513 GetMapOfAIS().Clear();
517 //==============================================================================
518 //function : StandardModesActivation
519 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
521 //==============================================================================
522 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
524 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
526 if (TheAISContext()->HasOpenedContext())
527 aContext->CloseLocalContext();
530 if(!aContext->HasOpenedContext()) {
531 // To unhilight the preselected object
532 aContext->UnhilightCurrents(Standard_False);
533 // Open a local Context in order to be able to select subshape from
534 // the selected shape if any or for all if there is no selection
535 if (!aContext->FirstCurrentObject().IsNull()){
536 aContext->OpenLocalContext(Standard_False);
538 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
539 aContext->Load( aContext->Current(),-1,Standard_True);
543 aContext->OpenLocalContext();
546 const char *cmode="???";
549 case 0: cmode = "Shape"; break;
550 case 1: cmode = "Vertex"; break;
551 case 2: cmode = "Edge"; break;
552 case 3: cmode = "Wire"; break;
553 case 4: cmode = "Face"; break;
554 case 5: cmode = "Shell"; break;
555 case 6: cmode = "Solid"; break;
556 case 7: cmode = "Compound"; break;
559 if(theactivatedmodes.Contains(mode))
561 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
562 theactivatedmodes.Remove(mode);
563 cout<<"Mode "<< cmode <<" OFF"<<endl;
567 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
568 theactivatedmodes.Add(mode);
569 cout<<"Mode "<< cmode << " ON" << endl;
574 //==============================================================================
575 //function : SelectFromContext
576 //purpose : pick / select an object from the last MoveTo() on a
578 //==============================================================================
580 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
582 Standard_Boolean shift,
583 Standard_Boolean pick )
585 Handle(AIS_InteractiveObject) ret;
586 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
593 const Handle(AIS_InteractiveContext) aContext = EM->Context();
595 if ( !aContext->HasOpenedContext() ) {
596 aContext->InitCurrent();
597 while ( aContext->MoreCurrent() ) {
598 Handle(AIS_InteractiveObject) aisPickedShape =
599 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
602 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
603 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
604 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
606 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
607 if(!TheRealSh.IsNull()){
608 cout << "Current is " << name
609 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
612 ret = aisPickedShape;
613 if(!TheRealSh.IsNull()){
614 if ( pick && argc > 4 ) {
615 DBRep::Set(argv[4], TheRealSh->Shape());
618 aContext->NextCurrent();
622 // A LocalContext is opened, the use xxxxSelected()
623 // to select an object and its SubShape
624 aContext->InitSelected();
625 while ( aContext->MoreSelected() ) {
626 if ( !aContext->HasSelectedShape() ) {
629 TopoDS_Shape PickedShape = aContext->SelectedShape();
630 if ( pick && argc > 5 ) {
631 DBRep::Set(argv[5], PickedShape);
635 if ( aContext->Interactive().IsNull() ) {
636 cout << "??? (No InteractiveObject selected)" << endl;
639 Handle(AIS_InteractiveObject) aisPicked =
640 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
642 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
646 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
647 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
648 GetMapOfAIS().Find1(aisPicked).ToCString() :
651 if(!aisPickedShape.IsNull()){
652 if ( pick && argc > 4 ) {
653 // Create a draw variable to store the wohole shape
655 DBRep::Set(argv[4], aisPickedShape->Shape());
658 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
662 // Goto the next selected object
663 aContext->NextSelected();
669 //==============================================================================
670 //function : DetectedFromContext
671 //purpose : hilight dynamicaly an object from the last MoveTo() on a
673 //==============================================================================
674 Handle(AIS_InteractiveObject) DetectedFromContext(
675 Handle(AIS_InteractiveContext) aContext )
677 Handle(AIS_InteractiveObject) ret;
678 if ( aContext->HasDetected() ) {
679 if ( !aContext->HasDetectedShape() ) {
680 //No SubShape selected
683 // Get the detected SubShape
684 TopoDS_Shape PickedShape = aContext->DetectedShape();
686 if ( !aContext->DetectedInteractive().IsNull() ) {
687 Handle(AIS_InteractiveObject) aisPickedShape =
688 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
689 ret = aisPickedShape;
696 //==============================================================================
697 //function : VDispAreas,VDispSensitive,...
698 //purpose : Redraw the view
700 //==============================================================================
701 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
704 Handle(AIS_InteractiveContext) Ctx;
705 Handle(V3d_View) Viou;
706 GetCtxAndView(Ctx,Viou);
707 Ctx->DisplayActiveAreas(Viou);
710 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
712 Handle(AIS_InteractiveContext) Ctx;
713 Handle(V3d_View) Viou;
714 GetCtxAndView(Ctx,Viou);
715 Ctx->ClearActiveAreas(Viou);
719 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
721 Handle(AIS_InteractiveContext) Ctx;
722 Handle(V3d_View) Viou;
723 GetCtxAndView(Ctx,Viou);
724 Ctx->DisplayActiveSensitive(Viou);
728 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
730 Handle(AIS_InteractiveContext) Ctx;
731 Handle(V3d_View) Viou;
732 GetCtxAndView(Ctx,Viou);
733 Ctx->ClearActiveSensitive(Viou);
737 //==============================================================================
739 //purpose : To list the displayed object with their attributes
741 //==============================================================================
742 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
743 { if ( !a3DView().IsNull() ) {
744 di << "List of object in the viewer :" << "\n";
746 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
748 while ( it.More() ) {
749 di << "\t" << it.Key2().ToCString() << "\n";
757 //==============================================================================
759 //purpose : To dump the active view snapshot to image file
760 //Draw arg : Picture file name with extension corresponding to desired format
761 //==============================================================================
762 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
766 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
770 Image_TypeOfImage aBufferType = Image_TOI_RGB;
774 TCollection_AsciiString aBuffTypeStr (argv[2]);
775 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
777 aBufferType = Image_TOI_RGB;
779 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
781 aBufferType = Image_TOI_RGBA;
783 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
785 aBufferType = Image_TOI_FLOAT;
789 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
790 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
792 Handle(AIS_InteractiveContext) IC;
793 Handle(V3d_View) view;
794 GetCtxAndView (IC, view);
797 if (aWidth > 0 && aHeight > 0)
799 return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
803 return view->Dump (argv[1], aBufferType) ? 0 : 1;
808 di << "Cannot find an active viewer/view" << "\n";
814 //==============================================================================
815 //function : Displays,Erase...
818 //==============================================================================
819 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
820 const Standard_Integer Mode,
821 const Standard_Integer TypeOfOperation,
822 const Standard_Boolean Upd)
824 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
826 switch(TypeOfOperation){
828 Ctx->Display(IO,Mode,Upd);
831 Ctx->Erase(IO,Mode,Upd);
836 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
838 Ctx->SetDisplayMode(IO,Mode,Upd);
843 Ctx->SetDisplayMode(0,Upd);
845 Ctx->UnsetDisplayMode(IO,Upd);
852 //=======================================================================
855 //=======================================================================
856 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
859 TCollection_AsciiString name;
862 // display others presentations
863 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
864 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
865 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
866 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
868 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
870 //unset displaymode.. comportement particulier...
871 if(TypeOfOperation==4){
873 if(Ctx->NbCurrents()==0 ||
874 Ctx->NbSelected()==0){
875 Handle(AIS_InteractiveObject) IO;
876 VwrTst_DispErase(IO,-1,4,Standard_False);
878 else if(!Ctx->HasOpenedContext()){
879 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
880 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
883 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
884 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
885 Ctx->UpdateCurrentViewer();
888 Handle(AIS_InteractiveObject) IO;
890 if(GetMapOfAIS().IsBound2(name)){
891 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
893 VwrTst_DispErase(IO,-1,4,Standard_True);
898 Standard_Integer Dmode = atoi(argv[1]);
899 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
900 Handle(AIS_InteractiveObject) IO;
901 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
903 if(!Ctx->HasOpenedContext()){
904 // set/unset display mode sur le Contexte...
905 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
906 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
908 Ctx->UpdateCurrentViewer();
911 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
912 Ctx->Display(Ctx->Interactive(),Dmode);
916 Handle(AIS_InteractiveObject) IO;
918 if(GetMapOfAIS().IsBound2(name))
919 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
921 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
927 //=======================================================================
930 //=======================================================================
931 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
933 if(argc==1) return 1;
934 Standard_Integer On = atoi(argv[1]);
935 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
939 if(!Ctx->HasOpenedContext()){
940 di<<"sub intensite ";
943 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
944 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
946 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
948 di <<"passage dans off"<<"\n";
949 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
954 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
956 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
958 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
961 Ctx->UpdateCurrentViewer();
964 Handle(AIS_InteractiveObject) IO;
965 TCollection_AsciiString name = argv[2];
966 if(GetMapOfAIS().IsBound2(name)){
967 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
970 Ctx->SubIntensityOn(IO);
972 Ctx->SubIntensityOff(IO);
980 //==============================================================================
983 //purpose : change the color of a selected or named or displayed shape
984 //Draw arg : vcolor2 [name] color
985 //==============================================================================
986 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
989 Standard_Boolean ThereIsCurrent;
990 Standard_Boolean ThereIsArgument;
991 Standard_Boolean IsBound = Standard_False ;
993 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
995 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
996 ThereIsArgument = (argc != 2);
999 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1000 ThereIsArgument = (argc == 2);
1003 if ( !a3DView().IsNull() ) {
1004 TCollection_AsciiString name;
1005 if (ThereIsArgument) {
1007 IsBound= GetMapOfAIS().IsBound2(name);
1009 if (TheAISContext()->HasOpenedContext())
1010 TheAISContext()->CloseLocalContext();
1012 // On set le Booleen There is current
1013 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1014 else ThereIsCurrent =Standard_False;
1016 //=======================================================================
1017 // Il y a un argument
1018 //=======================================================================
1019 if ( ThereIsArgument && IsBound ) {
1020 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1021 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1022 Handle(AIS_InteractiveObject) ashape =
1023 Handle(AIS_InteractiveObject)::DownCast (anObj);
1026 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1028 di << "HaveToSet 0\n";
1032 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
1034 TheAISContext()->UnsetColor(ashape);
1035 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1036 Handle(NIS_Triangulated) ashape =
1037 Handle(NIS_Triangulated)::DownCast (anObj);
1038 if (!ashape.IsNull())
1039 ashape->SetColor (GetColorFromName(argv[2]));
1044 //=======================================================================
1045 // Il n'y a pas d'arguments
1046 // Mais un ou plusieurs objets on des current representation
1047 //=======================================================================
1048 if (ThereIsCurrent && !ThereIsArgument) {
1049 for (TheAISContext() -> InitCurrent() ;
1050 TheAISContext() -> MoreCurrent() ;
1051 TheAISContext() ->NextCurrent() )
1053 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1054 if (ashape.IsNull())
1058 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1060 di << "HaveToSet 0\n";
1063 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1065 TheAISContext()->UnsetColor(ashape,Standard_False);
1068 TheAISContext()->UpdateCurrentViewer();
1071 //=======================================================================
1072 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1073 // on impose a tous les objets du viewer la couleur passee
1074 //=======================================================================
1075 else if (!ThereIsCurrent && !ThereIsArgument){
1076 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1077 while ( it.More() ) {
1078 const Handle(AIS_InteractiveObject) ashape =
1079 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1080 if (!ashape.IsNull())
1082 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1084 TheAISContext()->UnsetColor(ashape,Standard_False);
1087 TheAISContext()->UpdateCurrentViewer();
1093 //==============================================================================
1094 //function : VTransparency
1096 //purpose : change the transparency of a selected or named or displayed shape
1097 //Draw arg : vtransparency [name] TransparencyCoeficient
1098 //==============================================================================
1100 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1103 Standard_Boolean ThereIsCurrent;
1104 Standard_Boolean ThereIsArgument;
1105 Standard_Boolean IsBound = Standard_False ;
1107 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1109 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1110 ThereIsArgument = (argc != 2);
1113 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1114 ThereIsArgument = (argc == 2);
1117 if ( !a3DView().IsNull() ) {
1118 TCollection_AsciiString name;
1119 if (ThereIsArgument) {
1121 IsBound= GetMapOfAIS().IsBound2(name);
1123 if (TheAISContext()->HasOpenedContext())
1124 TheAISContext()->CloseLocalContext();
1126 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1127 else ThereIsCurrent = Standard_False;
1129 //=======================================================================
1130 // Il y a des arguments: un nom et une couleur
1131 //=======================================================================
1132 if ( ThereIsArgument && IsBound ) {
1133 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1134 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1135 const Handle(AIS_InteractiveObject) ashape =
1136 Handle(AIS_InteractiveObject)::DownCast(anObj);
1138 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1140 TheAISContext()->UnsetTransparency(ashape);
1141 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1142 const Handle(NIS_InteractiveObject) ashape =
1143 Handle(NIS_InteractiveObject)::DownCast(anObj);
1145 ashape->SetTransparency(atof(argv[2]) );
1147 ashape->UnsetTransparency();
1150 //=======================================================================
1151 // Il n'y a pas d'arguments
1152 // Mais un ou plusieurs objets on des current representation
1153 //=======================================================================
1154 if (ThereIsCurrent && !ThereIsArgument) {
1155 for (TheAISContext() -> InitCurrent() ;
1156 TheAISContext() -> MoreCurrent() ;
1157 TheAISContext() ->NextCurrent() )
1159 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1161 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1163 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1166 TheAISContext()->UpdateCurrentViewer();
1168 //=======================================================================
1169 // Il n'y a pas d'arguments ET aucun objet courrant
1170 //=======================================================================
1171 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1172 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1174 while ( it.More() ) {
1175 Handle(AIS_InteractiveObject) ashape =
1176 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1177 if (!ashape.IsNull())
1179 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1181 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1184 TheAISContext()->UpdateCurrentViewer();
1191 //==============================================================================
1192 //function : VMaterial
1194 //purpose : change the Material of a selected or named or displayed shape
1195 //Draw arg : vmaterial [Name] Material
1196 //==============================================================================
1197 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1200 Standard_Boolean ThereIsCurrent;
1201 Standard_Boolean ThereIsName;
1202 Standard_Boolean IsBound = Standard_False ;
1204 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1206 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1207 ThereIsName = (argc != 2);
1210 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1211 ThereIsName = (argc == 2);
1214 if ( !a3DView().IsNull() ) {
1215 TCollection_AsciiString name;
1218 IsBound= GetMapOfAIS().IsBound2(name);
1220 if (TheAISContext()->HasOpenedContext())
1221 TheAISContext()->CloseLocalContext();
1222 if (TheAISContext() -> NbCurrents() > 0 )
1223 ThereIsCurrent =Standard_True;
1225 ThereIsCurrent =Standard_False;
1227 //=======================================================================
1228 // Ther is a name of shape and a material name
1229 //=======================================================================
1230 if ( ThereIsName && IsBound ) {
1231 Handle(AIS_InteractiveObject) ashape =
1232 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1233 if (!ashape.IsNull())
1235 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1237 TheAISContext()->UnsetMaterial(ashape);
1239 //=======================================================================
1240 // Il n'y a pas de nom de shape
1241 // Mais un ou plusieurs objets on des current representation
1242 //=======================================================================
1243 if (ThereIsCurrent && !ThereIsName) {
1244 for (TheAISContext() -> InitCurrent() ;
1245 TheAISContext() -> MoreCurrent() ;
1246 TheAISContext() ->NextCurrent() )
1248 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1250 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1252 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1254 TheAISContext()->UpdateCurrentViewer();
1257 //=======================================================================
1258 // Il n'y a pas de noms de shape ET aucun objet courrant
1259 // On impose a tous les objets du viewer le material passe en argument
1260 //=======================================================================
1261 else if (!ThereIsCurrent && !ThereIsName){
1262 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1264 while ( it.More() ) {
1265 Handle(AIS_InteractiveObject) ashape =
1266 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1267 if (!ashape.IsNull())
1269 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1271 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1274 TheAISContext()->UpdateCurrentViewer();
1282 //==============================================================================
1285 //purpose : change the width of the edges of a selected or named or displayed shape
1286 //Draw arg : vwidth [Name] WidthValue(1->10)
1287 //==============================================================================
1288 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1291 Standard_Boolean ThereIsCurrent;
1292 Standard_Boolean ThereIsArgument;
1293 Standard_Boolean IsBound = Standard_False ;
1295 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1297 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1298 ThereIsArgument = (argc != 2);
1301 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1302 ThereIsArgument = (argc == 2);
1304 if ( !a3DView().IsNull() ) {
1305 TCollection_AsciiString name;
1306 if (ThereIsArgument) {
1308 IsBound= GetMapOfAIS().IsBound2(name);
1310 if (TheAISContext()->HasOpenedContext())
1311 TheAISContext()->CloseLocalContext();
1313 if (TheAISContext() -> NbCurrents() > 0 )
1314 ThereIsCurrent =Standard_True;
1316 ThereIsCurrent =Standard_False;
1318 if ( ThereIsArgument && IsBound ) {
1319 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1320 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1321 const Handle(AIS_InteractiveObject) ashape =
1322 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1324 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1326 TheAISContext()->UnsetWidth (ashape);
1327 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1328 const Handle(NIS_Triangulated) ashape =
1329 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1330 if (HaveToSet && !ashape.IsNull())
1331 ashape->SetLineWidth ( atof (argv[2]) );
1335 //=======================================================================
1336 // Il n'y a pas d'arguments
1337 // Mais un ou plusieurs objets on des current representation
1338 //=======================================================================
1339 if (ThereIsCurrent && !ThereIsArgument) {
1340 for (TheAISContext() -> InitCurrent() ;
1341 TheAISContext() -> MoreCurrent() ;
1342 TheAISContext() ->NextCurrent() )
1344 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1346 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1348 TheAISContext()->UnsetWidth(ashape,Standard_False);
1350 TheAISContext()->UpdateCurrentViewer();
1352 //=======================================================================
1353 // Il n'y a pas d'arguments ET aucun objet courrant
1354 //=======================================================================
1355 else if (!ThereIsCurrent && !ThereIsArgument){
1356 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1358 while ( it.More() ) {
1359 Handle(AIS_InteractiveObject) ashape =
1360 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1361 if (!ashape.IsNull())
1363 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1365 TheAISContext()->UnsetWidth(ashape,Standard_False);
1368 TheAISContext()->UpdateCurrentViewer();
1373 //==============================================================================
1374 //function : VDonly2
1376 //purpose : Display only a selected or named object
1377 // if there is no selected or named object s, nothing is donne
1378 //Draw arg : vdonly2 [name1] ... [name n]
1379 //==============================================================================
1380 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1383 if ( a3DView().IsNull() )
1386 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1387 Standard_Boolean ThereIsArgument= argc>1;
1389 if (TheAISContext()->HasOpenedContext())
1390 TheAISContext()->CloseLocalContext();
1392 //===============================================================
1393 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1395 //===============================================================
1396 if (!ThereIsArgument && ThereIsCurrent) {
1399 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1402 for(TheAISContext()->InitCurrent();
1403 TheAISContext()->MoreCurrent();
1404 TheAISContext()->NextCurrent()){
1405 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1406 TheAISContext()->Erase(aShape,Standard_False);}
1408 TheAISContext() ->UpdateCurrentViewer();
1409 //===============================================================
1410 // Il y a des arguments
1411 //===============================================================
1412 if (ThereIsArgument) {
1413 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1415 while ( it.More() ) {
1416 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1417 const Handle(AIS_InteractiveObject) aShape =
1418 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1419 TheAISContext()->Erase(aShape,Standard_False);
1420 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1421 const Handle(NIS_InteractiveObject) aShape =
1422 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1423 TheNISContext()->Erase(aShape);
1428 // On display les objets passes par parametre
1429 for (int i=1; i<argc ; i++) {
1430 TCollection_AsciiString name=argv[i];
1431 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1433 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1434 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1435 const Handle(AIS_InteractiveObject) aShape =
1436 Handle(AIS_InteractiveObject)::DownCast (anObj);
1437 TheAISContext()->Display(aShape, Standard_False);
1438 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1439 Handle(NIS_InteractiveObject) aShape =
1440 Handle(NIS_InteractiveObject)::DownCast (anObj);
1441 TheNISContext()->Display(aShape);
1445 TheAISContext() ->UpdateCurrentViewer();
1446 // TheNISContext() ->UpdateViews();
1451 //==============================================================================
1452 //function : VErase2
1454 //purpose : Erase some selected or named objects
1455 // if there is no selected or named objects, the whole viewer is erased
1456 //Draw arg : verase2 [name1] ... [name n]
1457 //==============================================================================
1458 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1461 if ( a3DView().IsNull() )
1464 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1465 Standard_Boolean ThereIsArgument= argc>1;
1466 if(TheAISContext()->HasOpenedContext())
1467 TheAISContext()->CloseLocalContext();
1469 //===============================================================
1470 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1472 //===============================================================
1473 if (!ThereIsArgument && ThereIsCurrent) {
1474 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1476 while ( it.More() ) {
1477 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1478 const Handle(AIS_InteractiveObject) aShape =
1479 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1480 if (TheAISContext()->IsCurrent(aShape))
1481 TheAISContext()->Erase(aShape,Standard_False);
1486 TheAISContext() ->UpdateCurrentViewer();
1489 //===============================================================
1490 // Il n'y a pas d'arguments et aucuns objets selectionnes
1492 // On erase tout le viewer
1493 //===============================================================
1495 if (!ThereIsArgument && !ThereIsCurrent) {
1496 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1497 while ( it.More() ) {
1498 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1499 const Handle(AIS_InteractiveObject) aShape =
1500 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1501 TheAISContext()->Erase(aShape,Standard_False);
1502 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1503 const Handle(NIS_InteractiveObject) aShape =
1504 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1505 TheNISContext()->Erase(aShape);
1509 TheAISContext() ->UpdateCurrentViewer();
1510 // TheNISContext()->UpdateViews();
1513 //===============================================================
1514 // Il y a des arguments
1515 //===============================================================
1516 if (ThereIsArgument) {
1517 for (int i=1; i<argc ; i++) {
1518 TCollection_AsciiString name=argv[i];
1519 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1521 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1522 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1523 const Handle(AIS_InteractiveObject) aShape =
1524 Handle(AIS_InteractiveObject)::DownCast (anObj);
1525 TheAISContext()->Erase(aShape,Standard_False);
1526 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1527 const Handle(NIS_InteractiveObject) aShape =
1528 Handle(NIS_InteractiveObject)::DownCast (anObj);
1529 TheNISContext()->Erase(aShape);
1533 TheAISContext() ->UpdateCurrentViewer();
1534 // TheNISContext() ->UpdateViews();
1539 //==============================================================================
1540 //function : VEraseAll
1542 //purpose : Erase all the objects displayed in the viewer
1543 //Draw arg : veraseall
1544 //==============================================================================
1545 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1548 // Verification des arguments
1549 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1550 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1551 TheAISContext()->CloseAllContexts(Standard_False);
1552 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1554 while ( it.More() ) {
1555 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1556 const Handle(AIS_InteractiveObject) aShape =
1557 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1558 TheAISContext()->Erase(aShape,Standard_False);
1559 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1560 const Handle(NIS_InteractiveObject) aShape =
1561 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1562 TheNISContext()->Erase(aShape);
1566 TheAISContext() ->UpdateCurrentViewer();
1567 // TheNISContext() ->UpdateViews();
1572 //==============================================================================
1573 //function : VDisplayAll
1575 //purpose : Display all the objects of the Map
1576 //Draw arg : vdisplayall
1577 //==============================================================================
1578 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1581 if (! a3DView().IsNull() ) {
1582 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1583 if (TheAISContext()->HasOpenedContext())
1584 TheAISContext()->CloseLocalContext();
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 while ( it.More() ) {
1601 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1602 const Handle(AIS_InteractiveObject) aShape =
1603 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1604 TheAISContext()->Display(aShape, Standard_False);
1605 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1606 Handle(NIS_InteractiveObject) aShape =
1607 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1608 TheNISContext()->Display(aShape);
1612 TheAISContext() ->UpdateCurrentViewer();
1613 // TheNISContext() ->UpdateViews();
1619 //#######################################################################################################
1622 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1624 static Standard_Boolean IsDefined=Standard_False ;
1625 static TCollection_AsciiString VarName;
1627 const char *envir, *casroot ;
1628 envir = getenv("CSF_MDTVTexturesDirectory") ;
1630 Standard_Boolean HasDefinition = Standard_False ;
1632 casroot = getenv("CASROOT");
1634 VarName = TCollection_AsciiString (casroot);
1635 VarName += "/src/Textures" ;
1636 HasDefinition = Standard_True ;
1639 VarName = TCollection_AsciiString (envir);
1640 HasDefinition = Standard_True ;
1642 if ( HasDefinition ) {
1643 OSD_Path aPath ( VarName );
1644 OSD_Directory aDir(aPath);
1645 if ( aDir.Exists () ) {
1646 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1647 OSD_File TextureFile ( aTexture );
1648 if ( !TextureFile.Exists() ) {
1649 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1650 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1651 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1654 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1655 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1656 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1660 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1661 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1662 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1664 IsDefined = Standard_True ;
1670 //#######################################################################################################
1673 //#######################################################################################################
1677 //#######################################################################################################
1679 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1681 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1682 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1683 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1684 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1685 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1687 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1688 if(myAISContext.IsNull())
1690 di << "use 'vinit' command before " << argv[0] << "\n";
1694 Handle(AIS_InteractiveObject) TheAisIO;
1695 Handle(AIS_TexturedShape) myShape;
1696 Standard_Integer myPreviousMode = 0;
1698 if (argc<2 || !argv[1])
1700 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1704 TCollection_AsciiString name = argv[1];
1705 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1707 if (GetMapOfAIS().IsBound2(name))
1708 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1709 (GetMapOfAIS().Find2(name));
1710 if (TheAisIO.IsNull())
1712 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1716 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1718 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1719 myPreviousMode = myShape->DisplayMode() ;
1723 myAISContext->Clear(TheAisIO,Standard_False);
1724 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1725 GetMapOfAIS().UnBind1(TheAisIO);
1726 GetMapOfAIS().UnBind2(name);
1727 GetMapOfAIS().Bind(myShape, name);
1731 case 1: // vtexture : we only map a texture on the shape
1734 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1737 if (argc>2 && argv[2])
1739 if(strcasecmp(argv[2],"?")==0)
1741 TCollection_AsciiString monPath = GetEnvir (di) ;
1743 di<<"\n Files in current directory : \n"<<"\n";
1744 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1745 di.Eval(Cmnd.ToCString());
1747 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1750 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1751 di.Eval(Cmnd.ToCString());
1756 myShape->SetTextureFileName(argv[2]);
1760 di <<"Texture mapping disabled \n \
1761 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1763 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1764 if (myPreviousMode == 3 )
1765 myAISContext->RecomputePrsOnly(myShape);
1766 myAISContext->Display(myShape, Standard_True);
1771 case 2: // vtexscale : we change the scaling factor of the texture
1775 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1779 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1780 ( argv[2] ? atof(argv[2]) : 1.0 ),
1781 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1784 case 3: // vtexorigin : we change the origin of the texture on the shape
1787 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1790 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1791 ( argv[2] ? atof(argv[2]) : 0.0 ),
1792 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1795 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1798 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1801 if (argc>2 && argv[2])
1803 di <<"Texture repeat enabled"<<"\n";
1804 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1808 di <<"Texture repeat disabled"<<"\n";
1809 myShape->SetTextureRepeat(Standard_False);
1813 case 5: // vtexdefault : default texture mapping
1814 // ScaleU = ScaleV = 100.0
1815 // URepeat = VRepeat = 1.0
1816 // Uorigin = VOrigin = 0.0
1820 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1823 myShape->SetTextureRepeat(Standard_False);
1824 myShape->SetTextureOrigin(Standard_False);
1825 myShape->SetTextureScale (Standard_False);
1829 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1830 myAISContext->RecomputePrsOnly(myShape);
1833 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1834 myAISContext->Display(myShape, Standard_True);
1835 myAISContext->Update(myShape,Standard_True);
1840 //==============================================================================
1841 //function : VDisplay2
1843 //purpose : Display an object from its name
1844 //Draw arg : vdisplay name1 [name2] ... [name n]
1845 //==============================================================================
1846 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1849 // Verification des arguments
1850 if ( a3DView().IsNull() ) {
1852 ViewerTest::ViewerInit();
1853 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1858 di<<argv[0]<<" Syntaxe error"<<"\n";
1863 TCollection_AsciiString name;
1864 if (TheAISContext()->HasOpenedContext())
1865 TheAISContext()->CloseLocalContext();
1867 for ( int i = 1; i < argc; i++ ) {
1869 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1870 Standard_Boolean IsDatum = Standard_False;
1871 Handle(Standard_Transient) anObj;
1873 anObj = GetMapOfAIS().Find2(name);
1874 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1875 Handle(AIS_InteractiveObject) aShape =
1876 Handle(AIS_InteractiveObject)::DownCast(anObj);
1877 if (aShape->Type()==AIS_KOI_Datum) {
1878 IsDatum = Standard_True;
1879 TheAISContext()->Display(aShape, Standard_False);
1882 di << "Display " << name.ToCString() << "\n";
1883 // Get the Shape from a name
1884 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1886 // Update the Shape in the AIS_Shape
1887 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1888 if(!TheRealSh.IsNull())
1889 TheRealSh->Set(NewShape);
1890 TheAISContext()->Redisplay(aShape, Standard_False);
1891 TheAISContext()->Display(aShape, Standard_False);
1894 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1895 Handle(NIS_InteractiveObject) aShape =
1896 Handle(NIS_InteractiveObject)::DownCast(anObj);
1897 TheNISContext()->Display(aShape);
1900 else { // Create the AIS_Shape from a name
1901 const Handle(AIS_InteractiveObject) aShape =
1902 GetAISShapeFromName((const char *)name.ToCString());
1903 if ( !aShape.IsNull() ) {
1904 GetMapOfAIS().Bind(aShape, name);
1905 TheAISContext()->Display(aShape, Standard_False);
1909 // Upadate the screen and redraw the view
1910 TheAISContext()->UpdateCurrentViewer();
1911 // TheNISContext()->UpdateViews();
1915 //==============================================================================
1917 //purpose : Test the annimation of an object along a
1918 // predifined trajectory
1919 //Draw arg : vmove ShapeName
1920 //==============================================================================
1923 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
1928 if (TheAISContext()->HasOpenedContext())
1929 TheAISContext()->CloseLocalContext();
1931 Standard_Real Step=2*M_PI/180;
1932 Standard_Real Angle=0;
1933 // R est le rayon de l'hellicoide
1935 // D est la distance parcourue en translation en 1 tour
1938 Handle(AIS_InteractiveObject) aIO;
1940 if (GetMapOfAIS().IsBound2(argv[1]))
1941 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
1944 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
1947 TheAISContext()->Deactivate(aIO);
1949 // boucle generant le mouvement
1951 di<<" Transformations"<<"\n";
1952 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1955 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) );
1957 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
1958 TheAISContext()->SetLocation(aIO,myTransfo);
1960 TheAISContext() ->UpdateCurrentViewer();
1965 di<<" Locations"<<"\n";
1966 gp_Trsf myAngleTrsf;
1967 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
1968 TopLoc_Location myDeltaAngle (myAngleTrsf);
1970 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
1971 TopLoc_Location myDeltaDist (myDistTrsf);
1972 TopLoc_Location myTrueLoc;
1974 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
1977 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
1978 TheAISContext()->SetLocation(aIO,myTrueLoc );
1979 TheAISContext() ->UpdateCurrentViewer();
1984 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
1986 //TopLoc_Location Tempo=aIO->Location();
1987 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
1988 //ShapeBis.Located(Tempo);
1991 // On reset la location (origine) contenue dans l'AISInteractiveObject
1992 TheAISContext() ->ResetLocation(aIO);
1994 // On force aShape a devenir l'AIS IO propre a ShapeBis
1996 // Pour cela on force aShape(AIS IO) a devenir une AISShape
1997 // ->Set() est une methode de AIS_Shape
1998 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2000 // On donne a ShapeBis le nom de l'AIS IO
2001 //Rep::Set(argv[1],ShapeBis);
2004 TheAISContext()->Redisplay(aIO,Standard_False);
2006 // On reactive la selection des primitives sensibles
2007 TheAISContext()->Activate(aIO,0);
2009 TheAISContext() ->UpdateCurrentViewer();
2010 a3DView() -> Redraw();
2013 di<<" Temps ecoule "<<"\n";
2021 //==============================================================================
2023 //purpose : Test the annimation of an object along a
2024 // predifined trajectory
2025 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2026 //==============================================================================
2028 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2031 if (TheAISContext()->HasOpenedContext())
2032 TheAISContext()->CloseLocalContext();
2034 Standard_Real Step=4*M_PI/180;
2035 Standard_Real Angle=0;
2037 Handle(AIS_InteractiveObject) aIO;
2038 if (GetMapOfAIS().IsBound2(argv[1]))
2039 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2043 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2047 if (atoi(argv[3])==1 ) {
2048 di<<" Primitives sensibles OFF"<<"\n";
2049 TheAISContext()->Deactivate(aIO);
2052 di<<" Primitives sensibles ON"<<"\n";
2054 // Movement par transformation
2055 if(atoi(argv[2]) ==1) {
2056 di<<" Calcul par Transformation"<<"\n";
2057 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2061 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2062 TheAISContext()->SetLocation(aShape,myTransfo);
2063 TheAISContext() ->UpdateCurrentViewer();
2068 di<<" Calcul par Locations"<<"\n";
2069 gp_Trsf myAngleTrsf;
2070 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2071 TopLoc_Location myDeltaAngle (myAngleTrsf);
2072 TopLoc_Location myTrueLoc;
2074 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2077 myTrueLoc=myTrueLoc*myDeltaAngle;
2078 TheAISContext()->SetLocation(aShape,myTrueLoc );
2079 TheAISContext() ->UpdateCurrentViewer();
2082 if (atoi(argv[3])==1 ){
2083 // On reactive la selection des primitives sensibles
2084 TheAISContext()->Activate(aIO,0);
2086 a3DView() -> Redraw();
2088 di<<" Temps ecoule "<<"\n";
2094 //==================================================================================
2095 // Function : VAnimation
2096 //==================================================================================
2097 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2099 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2103 Standard_Real thread = 4;
2104 Standard_Real angleA=0;
2105 Standard_Real angleB;
2107 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2110 TopoDS_Shape CrankArm;
2111 TopoDS_Shape CylinderHead;
2112 TopoDS_Shape Propeller;
2113 TopoDS_Shape EngineBlock;
2115 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2116 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2117 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2118 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2119 BRepTools::Read(CrankArm,argv[1],B);
2120 BRepTools::Read(CylinderHead,argv[2],B);
2121 BRepTools::Read(Propeller,argv[3],B);
2122 BRepTools::Read(EngineBlock,argv[4],B);
2124 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2130 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2131 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2132 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2133 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2135 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2136 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2137 GetMapOfAIS().Bind(myAisCrankArm,"c");
2138 GetMapOfAIS().Bind(myAisPropeller,"d");
2140 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2141 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2142 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2144 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2145 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2146 TheAISContext()->Display(myAisCrankArm,Standard_False );
2147 TheAISContext()->Display(myAisPropeller,Standard_False);
2149 TheAISContext()->Deactivate(myAisCylinderHead);
2150 TheAISContext()->Deactivate(myAisEngineBlock );
2151 TheAISContext()->Deactivate(myAisCrankArm );
2152 TheAISContext()->Deactivate(myAisPropeller );
2154 // Boucle de mouvement
2155 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2157 angleA = thread*myAngle*M_PI/180;
2158 X = Sin(angleA)*3/8;
2159 angleB = atan(X / Sqrt(-X * X + 1));
2160 Standard_Real decal(25*0.6);
2163 //Build a transformation on the display
2164 gp_Trsf aPropellerTrsf;
2165 aPropellerTrsf.SetRotation(Ax1,angleA);
2166 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2168 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));
2169 gp_Trsf aCrankArmTrsf;
2170 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2171 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2173 TheAISContext()->UpdateCurrentViewer();
2176 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2177 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2179 myAisCrankArm ->ResetLocation();
2180 myAisPropeller->ResetLocation();
2182 myAisCrankArm -> Set(myNewCrankArm );
2183 myAisPropeller -> Set(myNewPropeller);
2185 TheAISContext()->Activate(myAisCylinderHead,0);
2186 TheAISContext()->Activate(myAisEngineBlock,0 );
2187 TheAISContext()->Activate(myAisCrankArm ,0 );
2188 TheAISContext()->Activate(myAisPropeller ,0 );
2194 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2195 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2197 TheAISContext()->UpdateCurrentViewer();
2198 a3DView()->Redraw();
2207 //==============================================================================
2208 //function : VShading
2209 //purpose : Sharpen or roughten the quality of the shading
2210 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2211 //==============================================================================
2212 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2214 Standard_Real myDevCoef;
2215 Handle(AIS_InteractiveObject) TheAisIO;
2218 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2220 if (TheAISContext()->HasOpenedContext())
2221 TheAISContext()->CloseLocalContext();
2226 myDevCoef =atof(argv[2]);
2229 TCollection_AsciiString name=argv[1];
2230 if (GetMapOfAIS().IsBound2(name ))
2231 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2232 if (TheAisIO.IsNull())
2233 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2236 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2238 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2240 TheAISContext()->Redisplay(TheAisIO);
2243 //==============================================================================
2244 //function : HaveMode
2245 //use : VActivatedModes
2246 //==============================================================================
2247 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2249 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2251 TColStd_ListOfInteger List;
2252 TheAISContext()->ActivatedModes (TheAisIO,List);
2253 TColStd_ListIteratorOfListOfInteger it;
2254 Standard_Boolean Found=Standard_False;
2255 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2256 if (it.Value()==mode ) Found=Standard_True;
2263 //==============================================================================
2264 //function : VActivatedMode
2266 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2267 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2268 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2269 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2270 // qu'un nom et qu'un mode.
2271 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2272 //==============================================================================
2273 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2275 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2278 Standard_Boolean ThereIsName = Standard_False ;
2280 if(!a3DView().IsNull()){
2282 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2283 // verification des arguments
2285 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2286 ThereIsName = (argc == 3);
2290 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2292 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2293 di<<" Fermeture du Context local"<<"\n";
2294 if (TheAISContext()->HasOpenedContext())
2295 TheAISContext()->CloseLocalContext();
2299 // IL n'y a aps de nom de shape passe en argument
2300 if (HaveToSet && !ThereIsName){
2301 Standard_Integer aMode=atoi(argv [1]);
2303 const char *cmode="???";
2305 case 0: cmode = "Shape"; break;
2306 case 1: cmode = "Vertex"; break;
2307 case 2: cmode = "Edge"; break;
2308 case 3: cmode = "Wire"; break;
2309 case 4: cmode = "Face"; break;
2310 case 5: cmode = "Shell"; break;
2311 case 6: cmode = "Solid"; break;
2312 case 7: cmode = "Compound"; break;
2315 if( !TheAISContext()->HasOpenedContext() ) {
2316 // il n'y a pas de Context local d'ouvert
2317 // on en ouvre un et on charge toutes les shapes displayees
2318 // on load tous les objets displayees et on Activate les objets de la liste
2319 AIS_ListOfInteractive ListOfIO;
2320 // on sauve dans une AISListOfInteractive tous les objets currents
2321 if (TheAISContext()->NbCurrents()>0 ){
2322 TheAISContext()->UnhilightCurrents(Standard_False);
2324 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2325 ListOfIO.Append(TheAISContext()->Current() );
2329 TheAISContext()->OpenLocalContext(Standard_False);
2330 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2333 Handle(AIS_InteractiveObject) aIO =
2334 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2336 TheAISContext()->Load(aIO,0,Standard_False);
2339 // traitement des objets qui etaient currents dans le Contexte global
2340 if (!ListOfIO.IsEmpty() ) {
2341 // il y avait des objets currents
2342 AIS_ListIteratorOfListOfInteractive iter;
2343 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2344 Handle(AIS_InteractiveObject) aIO=iter.Value();
2345 TheAISContext()->Activate(aIO,aMode);
2346 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2350 // On applique le mode a tous les objets displayes
2351 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2352 it2 (GetMapOfAIS());
2354 Handle(AIS_InteractiveObject) aIO =
2355 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2356 if (!aIO.IsNull()) {
2357 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2358 TheAISContext()->Activate(aIO,aMode);
2367 // un Context local est deja ouvert
2368 // Traitement des objets du Context local
2369 if (TheAISContext()->NbSelected()>0 ){
2370 TheAISContext()->UnhilightSelected(Standard_False);
2371 // il y a des objets selected,on les parcourt
2372 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2373 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2376 if (HaveMode(aIO,aMode) ) {
2377 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2378 TheAISContext()->Deactivate(aIO,aMode);
2381 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2382 TheAISContext()->Activate(aIO,aMode);
2388 // il n'y a pas d'objets selected
2389 // tous les objets diplayes sont traites
2390 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2393 Handle(AIS_InteractiveObject) aIO =
2394 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2395 if (!aIO.IsNull()) {
2396 if (HaveMode(aIO,aMode) ) {
2397 di<<" Mode: "<<cmode<<" OFF pour "
2398 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2399 TheAISContext()->Deactivate(aIO,aMode);
2402 di<<" Mode: "<<cmode<<" ON pour"
2403 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2404 TheAISContext()->Activate(aIO,aMode);
2412 else if (HaveToSet && ThereIsName){
2413 Standard_Integer aMode=atoi(argv [2]);
2414 Handle(AIS_InteractiveObject) aIO =
2415 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2417 if (!aIO.IsNull()) {
2418 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 TheAISContext()->OpenLocalContext(Standard_False);
2433 // On charge tous les objets de la map
2434 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2436 Handle(AIS_InteractiveObject) aShape=
2437 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2438 if (!aShape.IsNull())
2439 TheAISContext()->Load(aShape,0,Standard_False);
2442 TheAISContext()->Activate(aIO,aMode);
2443 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2447 // un Context local est deja ouvert
2448 if (HaveMode(aIO,aMode) ) {
2449 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2450 TheAISContext()->Deactivate(aIO,aMode);
2453 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2454 TheAISContext()->Activate(aIO,aMode);
2466 //==============================================================================
2467 // function : WhoAmI
2469 //==============================================================================
2470 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2473 if (theShape->Type()==AIS_KOI_Datum) {
2474 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2475 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2476 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2477 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2478 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2479 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2480 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2483 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2484 // AIS_Dimentions et AIS_Relations
2485 else if (theShape->Type()==AIS_KOI_Relation) {
2486 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2488 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2489 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2490 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2491 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2492 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2493 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2494 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2495 // AIS no repertorie.
2496 else {di<<" Type Unknown.";}
2502 //==============================================================================
2505 //Draw arg : vstate [nameA] ... [nameN]
2506 //==============================================================================
2507 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2509 TheAISContext()->CloseAllContexts();
2510 const Standard_Boolean ThereIsArguments=(argc>=2);
2511 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2513 // ==================
2514 // Il y a un argument
2515 // ==================
2516 if (ThereIsArguments) {
2517 for (int cpt=1;cpt<argc;cpt++) {
2518 // Verification que lq piece est bien bindee.
2519 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2520 const Handle(AIS_InteractiveObject) theShape=
2521 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2523 if (!theShape.IsNull()) {
2524 di<<argv[cpt];WhoAmI(theShape, di);
2525 if (TheAISContext()->IsDisplayed(theShape) ) {
2526 di<<" Displayed"<<"\n";
2529 di<<" Not Displayed"<<"\n";
2534 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2538 else if (ThereIsCurrent ) {
2539 for (TheAISContext() -> InitCurrent() ;
2540 TheAISContext() -> MoreCurrent() ;
2541 TheAISContext() ->NextCurrent() )
2543 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2544 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2545 if (TheAISContext()->IsDisplayed(theShape) ) {
2546 di<<" Displayed"<<"\n";
2549 di<<" Not Displayed"<<"\n";
2555 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2557 while ( it.More() ) {
2558 Handle(AIS_InteractiveObject) theShape =
2559 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2560 if (!theShape.IsNull()) {
2561 di<<it.Key2().ToCString();
2562 WhoAmI(theShape, di);
2563 if (TheAISContext()->IsDisplayed(theShape) ) {
2564 di<<" Displayed"<<"\n";
2567 di<<" Not Displayed"<<"\n";
2578 //=======================================================================
2579 //function : PickObjects
2581 //=======================================================================
2582 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2583 const AIS_KindOfInteractive TheType,
2584 const Standard_Integer TheSignature,
2585 const Standard_Integer MaxPick)
2587 Handle(AIS_InteractiveObject) IO;
2588 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2590 // step 1: prepare the data
2592 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2593 TheAISContext()->AddFilter(F1);
2596 // step 2 : wait for the selection...
2597 // Standard_Boolean IsGood (Standard_False);
2598 // Standard_Integer NbPick(0);
2599 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2600 Standard_Integer NbPickFail(0);
2601 Standard_Integer argccc = 5;
2602 const char *bufff[] = { "A", "B", "C","D", "E" };
2603 const char **argvvv = (const char **) bufff;
2606 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2607 while(ViewerMainLoop(argccc,argvvv)){}
2608 Standard_Integer NbStored = TheAISContext()->NbSelected();
2609 if((unsigned int ) NbStored != NbPickGood)
2610 NbPickGood= NbStored;
2613 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2616 // step3 get result.
2618 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2620 Standard_Integer i(0);
2621 for(TheAISContext()->InitSelected();
2622 TheAISContext()->MoreSelected();
2623 TheAISContext()->NextSelected()){
2625 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2626 arr->SetValue(i,IO2);
2631 TheAISContext()->CloseLocalContext(curindex);
2633 return Standard_True;
2637 //=======================================================================
2638 //function : PickObject
2640 //=======================================================================
2641 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2642 const Standard_Integer TheSignature,
2643 const Standard_Integer MaxPick)
2645 Handle(AIS_InteractiveObject) IO;
2646 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2648 // step 1: prepare the data
2651 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2652 TheAISContext()->AddFilter(F1);
2655 // step 2 : wait for the selection...
2656 Standard_Boolean IsGood (Standard_False);
2657 Standard_Integer NbPick(0);
2658 Standard_Integer argccc = 5;
2659 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2660 const char **argvvv = (const char **) bufff;
2663 while(!IsGood && NbPick<= MaxPick){
2664 while(ViewerMainLoop(argccc,argvvv)){}
2665 IsGood = (TheAISContext()->NbSelected()>0) ;
2667 cout<<"Nb Pick :"<<NbPick<<endl;
2671 // step3 get result.
2673 TheAISContext()->InitSelected();
2674 IO = TheAISContext()->SelectedInteractive();
2678 TheAISContext()->CloseLocalContext(curindex);
2682 //=======================================================================
2683 //function : PickShape
2684 //purpose : First Activate the rightmode + Put Filters to be able to
2685 // pick objets that are of type <TheType>...
2686 //=======================================================================
2688 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2689 const Standard_Integer MaxPick)
2692 // step 1: prepare the data
2694 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2695 TopoDS_Shape result;
2697 if(TheType==TopAbs_SHAPE){
2698 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2699 TheAISContext()->AddFilter(F1);
2702 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2703 TheAISContext()->AddFilter(TF);
2704 TheAISContext()->ActivateStandardMode(TheType);
2709 // step 2 : wait for the selection...
2710 Standard_Boolean NoShape (Standard_True);
2711 Standard_Integer NbPick(0);
2712 Standard_Integer argccc = 5;
2713 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2714 const char **argvvv = (const char **) bufff;
2717 while(NoShape && NbPick<= MaxPick){
2718 while(ViewerMainLoop(argccc,argvvv)){}
2719 NoShape = (TheAISContext()->NbSelected()==0) ;
2721 cout<<"Nb Pick :"<<NbPick<<endl;
2724 // step3 get result.
2728 TheAISContext()->InitSelected();
2729 if(TheAISContext()->HasSelectedShape())
2730 result = TheAISContext()->SelectedShape();
2732 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2733 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2738 TheAISContext()->CloseLocalContext(curindex);
2744 //=======================================================================
2745 //function : PickShapes
2747 //=======================================================================
2748 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2749 Handle(TopTools_HArray1OfShape)& thearr,
2750 const Standard_Integer MaxPick)
2753 Standard_Integer Taille = thearr->Length();
2755 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2757 // step 1: prepare the data
2758 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2759 if(TheType==TopAbs_SHAPE){
2760 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2761 TheAISContext()->AddFilter(F1);
2764 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2765 TheAISContext()->AddFilter(TF);
2766 TheAISContext()->ActivateStandardMode(TheType);
2770 // step 2 : wait for the selection...
2772 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2773 Standard_Integer NbPickFail(0);
2774 Standard_Integer argccc = 5;
2775 const char *bufff[] = { "A", "B", "C","D", "E" };
2776 const char **argvvv = (const char **) bufff;
2779 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2780 while(ViewerMainLoop(argccc,argvvv)){}
2781 Standard_Integer NbStored = TheAISContext()->NbSelected();
2782 if((unsigned int ) NbStored != NbPickGood)
2783 NbPickGood= NbStored;
2786 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2789 // step3 get result.
2791 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2793 Standard_Integer i(0);
2794 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2796 if(TheAISContext()->HasSelectedShape())
2797 thearr->SetValue(i,TheAISContext()->SelectedShape());
2799 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2800 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2804 TheAISContext()->CloseLocalContext(curindex);
2805 return Standard_True;
2809 //=======================================================================
2810 //function : VPickShape
2812 //=======================================================================
2813 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2815 TopoDS_Shape PickSh;
2816 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2819 theType = TopAbs_SHAPE;
2821 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2822 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2823 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2824 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2825 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2826 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2827 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2830 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2831 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2833 TCollection_AsciiString name;
2836 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2838 PickSh = ViewerTest::PickShape(theType);
2847 if(!PickSh.IsNull()){
2848 nbOfSub[Standard_Integer(theType)]++;
2850 name += nameType[Standard_Integer(theType)];
2851 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2856 // si on avait une petite methode pour voir si la shape
2857 // est deja dans la Double map, ca eviterait de creer....
2858 DBRep::Set(name.ToCString(),PickSh);
2860 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2861 GetMapOfAIS().Bind(newsh, name);
2862 TheAISContext()->Display(newsh);
2863 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2866 // Plusieurs objets a picker, vite vite vite....
2869 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2870 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2871 if(ViewerTest::PickShapes(theType,arr)){
2872 for(Standard_Integer i=1;i<=NbToPick;i++){
2873 PickSh = arr->Value(i);
2874 if(!PickSh.IsNull()){
2876 nbOfSub[Standard_Integer(theType)]++;
2879 name += nameType[Standard_Integer(theType)];
2880 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2888 DBRep::Set(name.ToCString(),PickSh);
2889 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2890 GetMapOfAIS().Bind(newsh, name);
2891 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2892 TheAISContext()->Display(newsh);
2902 //=======================================================================
2903 //function : VPickObject
2904 //purpose : filters can be set (type of Object to pick....
2906 //=======================================================================
2909 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
2911 // preparation de la nomination automatique
2912 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
2913 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
2915 /* TCollection_AsciiString name;
2917 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2919 PickSh = ViewerTest::PickObject(theType);
2928 if(!PickSh.IsNull()){
2929 nbOfSub[Standard_Integer(theType)]++;
2931 name += nameType[Standard_Integer(theType)];
2932 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2937 // si on avait une petite methode pour voir si la shape
2938 // est deja dans la Double map, ca eviterait de creer....
2939 DBRep::Set(name.ToCString(),PickSh);
2941 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2942 GetMapOfAIS().Bind(newsh, name);
2943 TheAISContext()->Display(newsh);
2944 cout<<"Nom de la shape pickee : "<<name<<endl;
2947 // Plusieurs objets a picker, vite vite vite....
2950 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2951 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2952 if(ViewerTest::PickShapes(theType,arr)){
2953 for(Standard_Integer i=1;i<=NbToPick;i++){
2954 PickSh = arr->Value(i);
2955 if(!PickSh.IsNull()){
2957 nbOfSub[Standard_Integer(theType)]++;
2960 name += nameType[Standard_Integer(theType)];
2961 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2969 DBRep::Set(name.ToCString(),PickSh);
2970 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2971 GetMapOfAIS().Bind(newsh, name);
2972 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
2973 TheAISContext()->Display(newsh);
2983 //=======================================================================
2984 //function : list of known objects
2986 //=======================================================================
2987 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2989 // 1234567890 12345678901234567 123456789
2990 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2991 TCollection_AsciiString BlankLine(64,'_');
2992 Standard_Integer i ;
2994 di<<"/n"<<BlankLine.ToCString()<<"\n";
2997 Colum[i].Center(20,' ');
2999 di<<"|"<<Colum[i].ToCString();
3002 di<<BlankLine.ToCString()<<"\n";
3004 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3005 const char ** names = GetTypeNames();
3007 TCollection_AsciiString curstring;
3008 TCollection_AsciiString curcolum[3];
3011 // les objets de type Datum..
3012 curcolum[1]+="Datum";
3014 curcolum[0].Clear();
3015 curcolum[0] += names[i];
3017 curcolum[2].Clear();
3018 curcolum[2]+=TCollection_AsciiString(i+1);
3020 for(Standard_Integer j =0;j<=2;j++){
3021 curcolum[j].Center(20,' ');
3022 di<<"|"<<curcolum[j].ToCString();
3026 di<<BlankLine.ToCString()<<"\n";
3028 // les objets de type shape
3029 curcolum[1].Clear();
3030 curcolum[1]+="Shape";
3031 curcolum[1].Center(20,' ');
3034 curcolum[0].Clear();
3035 curcolum[0] += names[7+i];
3036 curcolum[2].Clear();
3037 curcolum[2]+=TCollection_AsciiString(i);
3039 for(Standard_Integer j =0;j<=2;j++){
3040 curcolum[j].Center(20,' ');
3041 di<<"|"<<curcolum[j].ToCString();
3045 di<<BlankLine.ToCString()<<"\n";
3046 // les IO de type objet...
3047 curcolum[1].Clear();
3048 curcolum[1]+="Object";
3049 curcolum[1].Center(20,' ');
3051 curcolum[0].Clear();
3052 curcolum[0] += names[10+i];
3053 curcolum[2].Clear();
3054 curcolum[2]+=TCollection_AsciiString(i);
3056 for(Standard_Integer j =0;j<=2;j++){
3057 curcolum[j].Center(20,' ');
3058 di<<"|"<<curcolum[j].ToCString();
3062 di<<BlankLine.ToCString()<<"\n";
3063 // les contraintes et dimensions.
3064 // pour l'instant on separe juste contraintes et dimensions...
3065 // plus tard, on detaillera toutes les sortes...
3066 curcolum[1].Clear();
3067 curcolum[1]+="Relation";
3068 curcolum[1].Center(20,' ');
3070 curcolum[0].Clear();
3071 curcolum[0] += names[12+i];
3072 curcolum[2].Clear();
3073 curcolum[2]+=TCollection_AsciiString(i);
3075 for(Standard_Integer j =0;j<=2;j++){
3076 curcolum[j].Center(20,' ');
3077 di<<"|"<<curcolum[j].ToCString();
3081 di<<BlankLine.ToCString()<<"\n";
3088 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3090 if(argc!=2) return 1;
3092 AIS_KindOfInteractive TheType;
3093 Standard_Integer TheSign(-1);
3094 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3097 AIS_ListOfInteractive LIO;
3099 // en attendant l'amelioration ais pour les dimensions...
3101 Standard_Integer dimension_status(-1);
3102 if(TheType==AIS_KOI_Relation){
3103 dimension_status = TheSign ==1 ? 1 : 0;
3107 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3108 Handle(AIS_InteractiveObject) curio;
3109 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3112 if(dimension_status == -1)
3113 TheAISContext()->Erase(curio,Standard_False);
3115 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3116 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3117 (dimension_status==1 && KOD != AIS_KOD_NONE))
3118 TheAISContext()->Erase(curio,Standard_False);
3121 TheAISContext()->UpdateCurrentViewer();
3124 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3126 if(argc!=2) return 1;
3128 AIS_KindOfInteractive TheType;
3129 Standard_Integer TheSign(-1);
3130 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3132 // en attendant l'amelioration ais pour les dimensions...
3134 Standard_Integer dimension_status(-1);
3135 if(TheType==AIS_KOI_Relation){
3136 dimension_status = TheSign ==1 ? 1 : 0;
3140 AIS_ListOfInteractive LIO;
3141 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3142 Handle(AIS_InteractiveObject) curio;
3143 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3145 if(dimension_status == -1)
3146 TheAISContext()->Display(curio,Standard_False);
3148 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3149 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3150 (dimension_status==1 && KOD != AIS_KOD_NONE))
3151 TheAISContext()->Display(curio,Standard_False);
3156 TheAISContext()->UpdateCurrentViewer();
3160 //==============================================================================
3161 //function : VSetTransMode
3163 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3164 //==============================================================================
3166 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3167 // Verification des arguments
3168 if ( a3DView().IsNull() ) {
3169 ViewerTest::ViewerInit();
3170 di << "La commande vinit n'a pas ete appele avant" << "\n";
3173 if ( argc < 3 || argc > 8 ) {
3174 di << argv[0] << " Invalid number of arguments" << "\n";
3178 TCollection_AsciiString shapeName;
3179 shapeName = argv[1];
3180 Standard_Integer persFlag1 = atoi(argv[2]);
3181 Standard_Integer persFlag2 = 0;
3182 Standard_Integer persFlag3 = 0;
3183 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3184 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3185 persFlag2 = atoi(argv[3]);
3187 if ( argc == 5 || argc == 8 ) {
3188 persFlag3 = atoi(argv[4]);
3191 origin.SetX( atof(argv[argc - 3]) );
3192 origin.SetY( atof(argv[argc - 2]) );
3193 origin.SetZ( atof(argv[argc - 1]) );
3196 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3197 Handle(Standard_Transient) anObj;
3199 anObj = GetMapOfAIS().Find2(shapeName);
3200 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3201 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3202 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3203 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3204 di << argv[0] << " All persistence modifiers were removed" << "\n";
3207 di << argv[0] << " Wrong object type" << "\n";
3210 } else { // Create the AIS_Shape from a name
3211 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3212 if ( !aShape.IsNull() ) {
3213 GetMapOfAIS().Bind( aShape, shapeName );
3214 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3215 TheAISContext()->Display( aShape, Standard_False );
3217 di << argv[0] << " Object not found" << "\n";
3222 // Upadate the screen and redraw the view
3223 TheAISContext()->UpdateCurrentViewer();
3227 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3230 BRep_Builder builder;
3232 BRepTools::Read(shape, s, builder);
3233 DBRep::Set(a[1], shape);
3234 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3235 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3239 //============================================================================
3240 #include <AIS2D_InteractiveContext.hxx>
3241 #include <HLRAlgo_Projector.hxx>
3242 #include <Prs3d_Projector.hxx>
3243 #include <AIS2D_ProjShape.hxx>
3244 #include <gp_Ax2.hxx>
3246 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3249 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3250 /////////////////////
3251 TopoDS_Shape aShape = DBRep::Get(a[1]);
3252 aContext2D->EraseAll(Standard_True);
3253 //Standard_Integer aPolyAlgo = 0;
3254 Standard_Boolean IsPoly = Standard_False;
3255 gp_Ax2 anAx2 = gp::XOY();
3257 //if(n > 2) aPolyAlgo = atoi(a[2]);
3259 //IsPoly = aPolyAlgo > 0;
3261 TopoDS_Shape aResult = aShape;
3266 Standard_Real x = atof(a[2]);
3267 Standard_Real y = atof(a[3]);
3268 Standard_Real z = atof(a[4]);
3270 Standard_Real dx = atof(a[5]);
3271 Standard_Real dy = atof(a[6]);
3272 Standard_Real dz = atof(a[7]);
3274 Standard_Real dx1 = atof(a[8]);
3275 Standard_Real dy1 = atof(a[9]);
3276 Standard_Real dz1 = atof(a[10]);
3278 gp_Pnt anOrigin (x, y, z);
3279 gp_Dir aNormal (dx, dy, dz);
3280 gp_Dir aDX (dx1, dy1, dz1);
3281 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3285 HLRAlgo_Projector aProjector(anAx2);
3287 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3289 //aProjector = aProjector_t.Projector();
3291 Handle(AIS2D_ProjShape) myDisplayableShape =
3292 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3294 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3295 Standard_False, Standard_True, Standard_False);
3297 myDisplayableShape->Add( aResult );
3300 aContext2D->Display( myDisplayableShape,Standard_True );
3301 aContext2D->UpdateCurrentViewer();
3306 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3309 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3310 /////////////////////
3311 TopoDS_Shape aShape = DBRep::Get(a[1]);
3312 aContext2D->EraseAll(Standard_True);
3313 //Standard_Integer aPolyAlgo = 0;
3314 Standard_Boolean IsPoly = Standard_True;
3315 gp_Ax2 anAx2 = gp::XOY();
3317 //if(n > 2) aPolyAlgo = atoi(a[2]);
3319 //IsPoly = aPolyAlgo > 0;
3321 TopoDS_Shape aResult = aShape;
3326 Standard_Real x = atof(a[2]);
3327 Standard_Real y = atof(a[3]);
3328 Standard_Real z = atof(a[4]);
3330 Standard_Real dx = atof(a[5]);
3331 Standard_Real dy = atof(a[6]);
3332 Standard_Real dz = atof(a[7]);
3334 Standard_Real dx1 = atof(a[8]);
3335 Standard_Real dy1 = atof(a[9]);
3336 Standard_Real dz1 = atof(a[10]);
3338 gp_Pnt anOrigin (x, y, z);
3339 gp_Dir aNormal (dx, dy, dz);
3340 gp_Dir aDX (dx1, dy1, dz1);
3341 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3345 HLRAlgo_Projector aProjector(anAx2);
3347 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3349 //aProjector = aProjector_t.Projector();
3351 Handle(AIS2D_ProjShape) myDisplayableShape =
3352 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3354 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3355 Standard_False, Standard_True, Standard_False);
3357 myDisplayableShape->Add( aResult );
3360 aContext2D->Display( myDisplayableShape,Standard_True );
3361 aContext2D->UpdateCurrentViewer();
3366 //==============================================================================
3367 //function : ViewerTest::Commands
3368 //purpose : Add all the viewer command in the Draw_Interpretor
3369 //==============================================================================
3371 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3373 ViewerTest::ViewerCommands(theCommands);
3374 ViewerTest::RelationCommands(theCommands);
3375 ViewerTest::ObjectCommands(theCommands);
3376 ViewerTest::FilletCommands(theCommands);
3377 ViewerTest::VoxelCommands(theCommands);
3379 const char *group = "AIS_Display";
3383 theCommands.Add("vdisplay",
3384 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3385 __FILE__,VDisplay2,group);
3387 theCommands.Add("verase",
3388 "verase : verase2 [name1] ... [name n] ",
3389 __FILE__,VErase2,group);
3391 theCommands.Add("vdonly",
3392 "vdonly : vdonly2 [name1] ... [name n]",
3393 __FILE__,VDonly2,group);
3395 theCommands.Add("vdisplayall",
3396 "vdisplayall : vdisplayall",
3397 __FILE__,VDisplayAll,group);
3399 theCommands.Add("veraseall",
3400 "veraseall : veraseall ",
3401 __FILE__,VEraseAll,group);
3403 theCommands.Add("verasetype",
3404 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3405 __FILE__,VEraseType,group);
3407 theCommands.Add("vdisplaytype",
3408 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3409 __FILE__,VDisplayType,group);
3411 theCommands.Add("vdisplaymode",
3412 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3413 __FILE__,VDispMode,group);
3415 theCommands.Add("verasemode",
3416 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3417 __FILE__,VDispMode,group);
3419 theCommands.Add("vsetdispmode",
3420 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3421 __FILE__,VDispMode,group);
3423 theCommands.Add("vunsetdispmode",
3424 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3425 __FILE__,VDispMode,group);
3427 theCommands.Add("vdir",
3429 __FILE__,VDebug,group);
3431 theCommands.Add("vdump",
3432 "<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",
3433 __FILE__,VDump,group);
3435 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3436 __FILE__,VSubInt,group);
3438 theCommands.Add("vsetcolor",
3439 "vsetcolor : vsetcolor [name of shape] ColorName",
3440 __FILE__,VColor2,group);
3442 theCommands.Add("vunsetcolor",
3443 "vunsetcolor : vunsetcolor [name of shape] ",
3444 __FILE__,VColor2,group);
3446 theCommands.Add("vsettransparency",
3447 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3448 __FILE__,VTransparency,group);
3450 theCommands.Add("vunsettransparency",
3451 "vunsettransparency : vtransparency [name of shape]",
3452 __FILE__,VTransparency,group);
3454 theCommands.Add("vsetmaterial",
3455 "vmaterial : vmaterial [name of shape] MaterialName",
3456 __FILE__,VMaterial,group);
3458 theCommands.Add("vunsetmaterial",
3459 "vmaterial : vmaterial [name of shape]",
3460 __FILE__,VMaterial,group);
3462 theCommands.Add("vsetwidth",
3463 "vsetwidth : vwidth [name of shape] width(0->10)",
3464 __FILE__,VWidth,group);
3466 theCommands.Add("vunsetwidth",
3467 "vunsetwidth : vwidth [name of shape]",
3468 __FILE__,VWidth,group);
3470 theCommands.Add("vardis",
3471 "vardis : display activeareas",
3472 __FILE__,VDispAreas,group);
3474 theCommands.Add("varera",
3475 "varera : erase activeareas",
3476 __FILE__,VClearAreas,group);
3478 theCommands.Add("vsensdis",
3479 "vardisp : display active entities",
3480 __FILE__,VDispSensi,group);
3481 theCommands.Add("vsensera",
3482 "vardisp : erase active entities",
3483 __FILE__,VClearSensi,group);
3485 theCommands.Add("vperf",
3486 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3487 __FILE__,VPerf,group);
3489 theCommands.Add("vanimation",
3490 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3491 __FILE__,VAnimation,group);
3493 theCommands.Add("vsetshading",
3494 "vsetshading : vsetshading name Quality(default=0.0008) ",
3495 __FILE__,VShading,group);
3497 theCommands.Add("vunsetshading",
3498 "vunsetshading :vunsetshading name ",
3499 __FILE__,VShading,group);
3501 theCommands.Add("vtexture",
3502 "'vtexture NameOfShape TextureFile' \n \
3503 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3504 or 'vtexture NameOfShape ?' to list available textures\n \
3505 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3506 __FILE__,VTexture,group);
3508 theCommands.Add("vtexscale",
3509 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3510 or 'vtexscale NameOfShape ScaleUV' \n \
3511 or 'vtexscale NameOfShape' to disable scaling\n ",
3512 __FILE__,VTexture,group);
3514 theCommands.Add("vtexorigin",
3515 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3516 or 'vtexorigin NameOfShape UVOrigin' \n \
3517 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3518 __FILE__,VTexture,group);
3520 theCommands.Add("vtexrepeat",
3521 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3522 or 'vtexrepeat NameOfShape UVRepeat \n \
3523 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3526 theCommands.Add("vtexdefault",
3527 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3530 theCommands.Add("vsetam",
3531 "vsetActivatedModes: vsetam mode(1->7) ",
3532 __FILE__,VActivatedMode,group);
3534 theCommands.Add("vunsetam",
3535 "vunsetActivatedModes: vunsetam ",
3536 __FILE__,VActivatedMode,group);
3538 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3539 __FILE__,VState,group);
3541 theCommands.Add("vpickshapes",
3542 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3543 __FILE__,VPickShape,group);
3545 theCommands.Add("vtypes",
3546 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3549 theCommands.Add("vsettransmode",
3550 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3551 __FILE__,VSetTransMode,group);
3553 theCommands.Add("vr", "vr : reading of the shape",
3554 __FILE__,vr, group);
3556 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3557 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3561 //=====================================================================
3562 //========================= for testing Draft and Rib =================
3563 //=====================================================================
3564 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3565 #include <DBRep.hxx>
3566 #include <TopoDS_Face.hxx>
3567 #include <gp_Pln.hxx>
3568 #include <AIS_KindOfSurface.hxx>
3569 #include <BRepOffsetAPI_DraftAngle.hxx>
3570 #include <Precision.hxx>
3571 #include <BRepAlgo.hxx>
3572 #include <OSD_Environment.hxx>
3573 #include <DrawTrSurf.hxx>
3574 //#include <DbgTools.hxx>
3575 //#include <FeatAlgo_MakeLinearForm.hxx>
3580 //=======================================================================
3581 //function : IsValid
3583 //=======================================================================
3584 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3585 const TopoDS_Shape& theResult,
3586 const Standard_Boolean closedSolid,
3587 const Standard_Boolean GeomCtrl)
3589 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3590 TCollection_AsciiString checkValid = check.Value();
3591 Standard_Boolean ToCheck = Standard_True;
3592 if (!checkValid.IsEmpty()) {
3594 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3596 if ( checkValid=="true" || checkValid=="TRUE" ) {
3597 ToCheck= Standard_False;
3601 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3604 Standard_Boolean IsValid = Standard_True;
3606 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3611 //===============================================================================
3612 // TDraft : test draft, uses AIS Viewer
3613 // Solid Face Plane Angle Reverse
3614 //===============================================================================
3615 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3617 if (argc < 5) return 1;
3618 // argv[1] - TopoDS_Shape Solid
3619 // argv[2] - TopoDS_Shape Face
3620 // argv[3] - TopoDS_Shape Plane
3621 // argv[4] - Standard_Real Angle
3622 // argv[5] - Standard_Integer Reverse
3624 // sprintf(prefix, argv[1]);
3625 Standard_Real anAngle = 0;
3626 Standard_Boolean Rev = Standard_False;
3627 Standard_Integer rev = 0;
3628 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3629 TopoDS_Shape face = GetShapeFromName(argv[2]);
3630 TopoDS_Face Face = TopoDS::Face(face);
3631 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3632 if (Plane.IsNull ()) {
3633 di << "TEST : Plane is NULL" << "\n";
3636 anAngle = atof(argv[4]);
3637 anAngle = 2*M_PI * anAngle / 360.0;
3639 Handle( Geom_Surface )aSurf;
3640 AIS_KindOfSurface aSurfType;
3641 Standard_Real Offset;
3643 if(argc > 4) { // == 5
3644 rev = atoi(argv[5]);
3645 Rev = (rev)? Standard_True : Standard_False;
3648 TopoDS_Face face2 = TopoDS::Face(Plane);
3649 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3651 di << "TEST : Can't find plane" << "\n";
3655 aDir = aPln.Axis().Direction();
3658 if (Plane.Orientation() == TopAbs_REVERSED)
3660 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3662 BRepOffsetAPI_DraftAngle Draft (Solid);
3664 if(Abs(anAngle)< Precision::Angular()) {
3665 di << "TEST : NULL angle" << "\n";
3668 if(Rev) anAngle = - anAngle;
3669 Draft.Add (Face, aDir, anAngle, aPln);
3671 if (!Draft.IsDone()) {
3672 di << "TEST : Draft Not DONE " << "\n";
3675 TopTools_ListOfShape Larg;
3677 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3678 di << "TEST : DesignAlgo returns Not valid" << "\n";
3682 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3683 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3685 if ( !ais.IsNull() ) {
3686 ais->SetColor(DEFAULT_COLOR);
3687 ais->SetMaterial(DEFAULT_MATERIAL);
3688 // Display the AIS_Shape without redraw
3689 Ctx->Display(ais, Standard_False);
3691 const char *Name = "draft1";
3692 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3694 Handle(AIS_InteractiveObject) an_object =
3695 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3696 if (!an_object.IsNull()) {
3697 Ctx->Remove(an_object,
3699 GetMapOfAIS().UnBind2(Name) ;
3702 GetMapOfAIS().Bind(ais, Name);
3703 // DBRep::Set("draft", ais->Shape());
3705 Ctx->Display(ais, Standard_True);
3711 //============================================================================
3713 //============================================================================
3714 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3717 DrawTrSurf::BasicCommands(theCommands);
3718 const char* group = "Check Features Operations commands";
3720 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3722 &TDraft,group); //Draft_Modification
3725 //==============================================================================
3726 // ViewerTest::Factory
3727 //==============================================================================
3728 void ViewerTest::Factory(Draw_Interpretor& theDI)
3730 // definition of Viewer Command
3731 ViewerTest::Commands(theDI);
3732 ViewerTest::AviCommands(theDI);
3733 Viewer2dTest::Commands(theDI);
3735 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3739 // Declare entry point PLUGINFACTORY