1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
68 #include <Draw_Interpretor.hxx>
69 #include <TCollection_AsciiString.hxx>
70 #include <Draw_PluginMacro.hxx>
71 #include <ViewerTest.hxx>
72 #include <Viewer2dTest.hxx>
74 // avoid warnings on 'extern "C"' functions returning C++ classes
76 #define _CRT_SECURE_NO_DEPRECATE
77 #pragma warning(4:4190)
78 #pragma warning (disable:4996)
81 #include <NIS_InteractiveContext.hxx>
82 #include <NIS_Triangulated.hxx>
83 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
85 //=======================================================================
86 //function : GetColorFromName
87 //purpose : get the Quantity_NameOfColor from a string
88 //=======================================================================
90 #include <Quantity_NameOfColor.hxx>
91 #include <Quantity_Color.hxx>
92 #include <Quantity_NameOfColor.hxx>
94 #include <Graphic3d_NameOfMaterial.hxx>
96 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
97 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
99 static Quantity_NameOfColor GetColorFromName( const char *name )
101 Quantity_NameOfColor ret = DEFAULT_COLOR;
103 Standard_Boolean Found = Standard_False;
104 Standard_CString colstring;
105 for(Standard_Integer i=0;i<=514 && !Found;i++)
107 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
108 if (!strcasecmp(name,colstring)) {
109 ret = (Quantity_NameOfColor)i;
110 Found = Standard_True;
117 //=======================================================================
118 //function : GetMaterialFromName
119 //purpose : get the Graphic3d_NameOfMaterial from a string
120 //=======================================================================
122 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
124 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
126 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
127 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
128 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
129 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
130 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
131 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
132 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
133 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
134 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
135 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
136 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
137 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
138 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
139 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
140 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
141 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
142 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
143 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
144 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
149 //=======================================================================
150 //function : GetTypeNames
152 //=======================================================================
153 static const char** GetTypeNames()
155 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
156 "Shape","ConnectedShape","MultiConn.Shape",
157 "ConnectedInter.","MultiConn.",
158 "Constraint","Dimension"};
159 static const char** ThePointer = names;
163 //=======================================================================
164 //function : GetTypeAndSignfromString
166 //=======================================================================
167 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
169 const char ** thefullnames = GetTypeNames();
170 Standard_Integer index(-1);
172 for(Standard_Integer i=0;i<=13 && index==-1;i++)
173 if(!strcasecmp(name,thefullnames[i]))
177 TheType = AIS_KOI_None;
183 TheType = AIS_KOI_Datum;
187 TheType = AIS_KOI_Shape;
191 TheType = AIS_KOI_Object;
195 TheType = AIS_KOI_Relation;
204 #include <Draw_Interpretor.hxx>
206 #include <Draw_Appli.hxx>
210 #include <TCollection_AsciiString.hxx>
211 #include <V3d_Viewer.hxx>
212 #include <V3d_View.hxx>
215 #include <AIS_InteractiveContext.hxx>
216 #include <AIS_Shape.hxx>
217 #include <AIS_TexturedShape.hxx>
218 #include <AIS_DisplayMode.hxx>
219 #include <TColStd_MapOfInteger.hxx>
220 #include <AIS_MapOfInteractive.hxx>
221 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
222 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
223 #include <ViewerTest_EventManager.hxx>
225 #include <TopoDS_Solid.hxx>
226 #include <BRepTools.hxx>
227 #include <BRep_Builder.hxx>
228 #include <TopAbs_ShapeEnum.hxx>
230 #include <TopoDS.hxx>
231 #include <BRep_Tool.hxx>
234 #include <Draw_Window.hxx>
235 #include <AIS_ListIteratorOfListOfInteractive.hxx>
236 #include <AIS_ListOfInteractive.hxx>
237 #include <AIS_DisplayMode.hxx>
238 #include <TopTools_ListOfShape.hxx>
239 #include <BRepOffsetAPI_MakeThickSolid.hxx>
240 #include <BRepOffset.hxx>
243 //==============================================================================
244 //function : GetTypeNameFromShape
245 //purpose : get the shape type as a string from a shape
246 //==============================================================================
248 static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
249 { const char *ret = "????";
251 if ( aShape.IsNull() ) ret = "Null Shape";
253 switch ( aShape.ShapeType() ) {
254 case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
255 case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
256 case TopAbs_SOLID : ret = "SOLID" ; break;
257 case TopAbs_SHELL : ret = "SHELL" ; break;
258 case TopAbs_FACE : ret = "FACE" ; break;
259 case TopAbs_WIRE : ret = "WIRE" ; break;
260 case TopAbs_EDGE : ret = "EDGE" ; break;
261 case TopAbs_VERTEX : ret = "VERTEX" ; break;
262 case TopAbs_SHAPE : ret = "SHAPE" ; break;
266 //==============================================================================
267 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
268 //==============================================================================
269 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
270 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
275 //==============================================================================
276 //function : VDisplayAISObject
277 //purpose : register interactive object in the map of AIS objects;
278 // if other object with such name already registered, it will be kept
279 // or replaced depending on value of <theReplaceIfExists>,
280 // if "true" - the old object will be cleared from AIS context;
281 // returns Standard_True if <theAISObj> registered in map;
282 //==============================================================================
283 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
284 const Handle(AIS_InteractiveObject)& theAISObj,
285 Standard_Boolean theReplaceIfExists = Standard_True)
287 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
288 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
289 if (aContextAIS.IsNull())
291 std::cout << "AIS context is not available.\n";
292 return Standard_False;
295 if (aMap.IsBound2 (theName))
297 if (!theReplaceIfExists)
299 std::cout << "Other interactive object has been already "
300 << "registered with name: " << theName << ".\n"
301 << "Please use another name.\n";
302 return Standard_False;
305 // stop displaying object
306 Handle(AIS_InteractiveObject) anOldObj =
307 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
309 if (!anOldObj.IsNull())
310 aContextAIS->Clear (anOldObj, Standard_True);
312 // remove name and old object from map
313 aMap.UnBind2 (theName);
316 if (theAISObj.IsNull())
318 // object with specified name already unbound
319 return Standard_True;
322 // unbind AIS object if was bound with another name
323 aMap.UnBind1 (theAISObj);
325 // can be registered without rebinding
326 aMap.Bind (theAISObj, theName);
327 aContextAIS->Display (theAISObj, Standard_True);
328 return Standard_True;
331 static TColStd_MapOfInteger theactivatedmodes(8);
332 static TColStd_ListOfTransient theEventMgrs;
334 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
335 const Handle(AIS_InteractiveContext)& Ctx)
337 theEventMgrs.Clear();
338 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
341 static Handle(V3d_View)& a3DView(){
342 static Handle(V3d_View) Viou;
346 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
347 static Handle(AIS_InteractiveContext) aContext;
351 Handle(V3d_View) ViewerTest::CurrentView()
355 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
360 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
362 static Handle(NIS_InteractiveContext) aContext;
363 if (aContext.IsNull()) {
364 aContext = new NIS_InteractiveContext;
365 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
370 Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
372 return TheAISContext();
375 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
377 TheAISContext() = aCtx;
378 ViewerTest::ResetEventManager();
381 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
383 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
386 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
388 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
392 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
393 theEventMgrs.Prepend(EM);
396 void ViewerTest::UnsetEventManager()
398 theEventMgrs.RemoveFirst();
402 void ViewerTest::ResetEventManager()
404 const Handle(NIS_View) aView =
405 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
406 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
409 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
411 Handle(ViewerTest_EventManager) EM;
412 if(theEventMgrs.IsEmpty()) return EM;
413 Handle(Standard_Transient) Tr = theEventMgrs.First();
414 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
419 //=======================================================================
420 //function : Get Context and active viou..
422 //=======================================================================
423 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
424 Handle(V3d_View)& Viou)
426 Ctx = ViewerTest::GetAISContext();
429 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
430 Vwr->InitActiveViews();
431 if(Vwr->MoreActiveViews())
432 Viou = Vwr->ActiveView();
437 //==============================================================================
438 //function : GetShapeFromName
439 //purpose : Compute an Shape from a draw variable or a file name
440 //==============================================================================
442 static TopoDS_Shape GetShapeFromName(const char* name)
444 TopoDS_Shape S = DBRep::Get(name);
447 BRep_Builder aBuilder;
448 BRepTools::Read( S, name, aBuilder);
453 //==============================================================================
454 //function : GetShapeFromName
455 //purpose : Compute an Shape from a draw variable or a file name
456 //==============================================================================
459 static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
461 TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
465 //==============================================================================
466 //function : GetAISShapeFromName
467 //purpose : Compute an AIS_Shape from a draw variable or a file name
468 //==============================================================================
469 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
471 Handle(AIS_Shape) retsh;
473 if(GetMapOfAIS().IsBound2(name)){
474 const Handle(AIS_InteractiveObject) IO =
475 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
477 if(IO->Type()==AIS_KOI_Shape)
478 if(IO->Signature()==0){
479 retsh = *((Handle(AIS_Shape)*)&IO);
482 cout << "an Object which is not an AIS_Shape "
483 "already has this name!!!"<<endl;
489 TopoDS_Shape S = GetShapeFromName(name);
491 retsh = new AIS_Shape(S);
497 //==============================================================================
499 //purpose : Remove all the object from the viewer
500 //==============================================================================
501 void ViewerTest::Clear()
503 if ( !a3DView().IsNull() ) {
504 if (TheAISContext()->HasOpenedContext())
505 TheAISContext()->CloseLocalContext();
506 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
507 while ( it.More() ) {
508 cout << "Remove " << it.Key2() << endl;
509 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
510 const Handle(AIS_InteractiveObject) anObj =
511 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
512 TheAISContext()->Remove(anObj,Standard_False);
513 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
514 const Handle(NIS_InteractiveObject) anObj =
515 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
516 TheNISContext()->Remove(anObj);
520 TheAISContext()->UpdateCurrentViewer();
521 // TheNISContext()->UpdateViews();
522 GetMapOfAIS().Clear();
526 //==============================================================================
527 //function : StandardModesActivation
528 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
530 //==============================================================================
531 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
533 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
535 if (TheAISContext()->HasOpenedContext())
536 aContext->CloseLocalContext();
539 if(!aContext->HasOpenedContext()) {
540 // To unhilight the preselected object
541 aContext->UnhilightCurrents(Standard_False);
542 // Open a local Context in order to be able to select subshape from
543 // the selected shape if any or for all if there is no selection
544 if (!aContext->FirstCurrentObject().IsNull()){
545 aContext->OpenLocalContext(Standard_False);
547 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
548 aContext->Load( aContext->Current(),-1,Standard_True);
552 aContext->OpenLocalContext();
555 const char *cmode="???";
558 case 0: cmode = "Shape"; break;
559 case 1: cmode = "Vertex"; break;
560 case 2: cmode = "Edge"; break;
561 case 3: cmode = "Wire"; break;
562 case 4: cmode = "Face"; break;
563 case 5: cmode = "Shell"; break;
564 case 6: cmode = "Solid"; break;
565 case 7: cmode = "Compound"; break;
568 if(theactivatedmodes.Contains(mode))
570 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
571 theactivatedmodes.Remove(mode);
572 cout<<"Mode "<< cmode <<" OFF"<<endl;
576 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
577 theactivatedmodes.Add(mode);
578 cout<<"Mode "<< cmode << " ON" << endl;
583 //==============================================================================
584 //function : SelectFromContext
585 //purpose : pick / select an object from the last MoveTo() on a
587 //==============================================================================
589 Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
591 Standard_Boolean shift,
592 Standard_Boolean pick )
594 Handle(AIS_InteractiveObject) ret;
595 Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
602 const Handle(AIS_InteractiveContext) aContext = EM->Context();
604 if ( !aContext->HasOpenedContext() ) {
605 aContext->InitCurrent();
606 while ( aContext->MoreCurrent() ) {
607 Handle(AIS_InteractiveObject) aisPickedShape =
608 Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
611 const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
612 // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
613 GetMapOfAIS().Find1(aisPickedShape).ToCString() :
615 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
616 if(!TheRealSh.IsNull()){
617 cout << "Current is " << name
618 << " (" << GetTypeNameFromShape(TheRealSh->Shape())
621 ret = aisPickedShape;
622 if(!TheRealSh.IsNull()){
623 if ( pick && argc > 4 ) {
624 DBRep::Set(argv[4], TheRealSh->Shape());
627 aContext->NextCurrent();
631 // A LocalContext is opened, the use xxxxSelected()
632 // to select an object and its SubShape
633 aContext->InitSelected();
634 while ( aContext->MoreSelected() ) {
635 if ( !aContext->HasSelectedShape() ) {
638 TopoDS_Shape PickedShape = aContext->SelectedShape();
639 if ( pick && argc > 5 ) {
640 DBRep::Set(argv[5], PickedShape);
644 if ( aContext->Interactive().IsNull() ) {
645 cout << "??? (No InteractiveObject selected)" << endl;
648 Handle(AIS_InteractiveObject) aisPicked =
649 Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
651 Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
655 const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
656 // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
657 GetMapOfAIS().Find1(aisPicked).ToCString() :
660 if(!aisPickedShape.IsNull()){
661 if ( pick && argc > 4 ) {
662 // Create a draw variable to store the wohole shape
664 DBRep::Set(argv[4], aisPickedShape->Shape());
667 cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
671 // Goto the next selected object
672 aContext->NextSelected();
678 //==============================================================================
679 //function : DetectedFromContext
680 //purpose : hilight dynamicaly an object from the last MoveTo() on a
682 //==============================================================================
683 Handle(AIS_InteractiveObject) DetectedFromContext(
684 Handle(AIS_InteractiveContext) aContext )
686 Handle(AIS_InteractiveObject) ret;
687 if ( aContext->HasDetected() ) {
688 if ( !aContext->HasDetectedShape() ) {
689 //No SubShape selected
692 // Get the detected SubShape
693 TopoDS_Shape PickedShape = aContext->DetectedShape();
695 if ( !aContext->DetectedInteractive().IsNull() ) {
696 Handle(AIS_InteractiveObject) aisPickedShape =
697 Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
698 ret = aisPickedShape;
705 //==============================================================================
706 //function : VDispAreas,VDispSensitive,...
707 //purpose : Redraw the view
709 //==============================================================================
710 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
713 Handle(AIS_InteractiveContext) Ctx;
714 Handle(V3d_View) Viou;
715 GetCtxAndView(Ctx,Viou);
716 Ctx->DisplayActiveAreas(Viou);
719 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
721 Handle(AIS_InteractiveContext) Ctx;
722 Handle(V3d_View) Viou;
723 GetCtxAndView(Ctx,Viou);
724 Ctx->ClearActiveAreas(Viou);
728 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
730 Handle(AIS_InteractiveContext) Ctx;
731 Handle(V3d_View) Viou;
732 GetCtxAndView(Ctx,Viou);
733 Ctx->DisplayActiveSensitive(Viou);
737 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
739 Handle(AIS_InteractiveContext) Ctx;
740 Handle(V3d_View) Viou;
741 GetCtxAndView(Ctx,Viou);
742 Ctx->ClearActiveSensitive(Viou);
746 //==============================================================================
748 //purpose : To list the displayed object with their attributes
750 //==============================================================================
751 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
752 { if ( !a3DView().IsNull() ) {
753 di << "List of object in the viewer :" << "\n";
755 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
757 while ( it.More() ) {
758 di << "\t" << it.Key2().ToCString() << "\n";
766 //==============================================================================
767 //function : VSelPrecision
768 //purpose : To set the selection precision mode and tolerance value
769 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
770 // value (integer number of pixel for window mode, double value of
771 // sensitivity for view mode). Without arguments the function just
772 // prints the current precision mode and the corresponding tolerance.
773 //==============================================================================
774 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
778 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
782 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
783 if( aContext.IsNull() )
788 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
789 if( aMode == StdSelect_SM_WINDOW )
791 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
792 di << "Precision mode : 0 (window)\n";
793 di << "Pixel tolerance : " << aPixelTolerance << "\n";
795 else if( aMode == StdSelect_SM_VIEW )
797 Standard_Real aSensitivity = aContext->Sensitivity();
798 di << "Precision mode : 1 (view)\n";
799 di << "Sensitivity : " << aSensitivity << "\n";
804 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )atoi( argv[1] );
805 aContext->SetSensitivityMode( aMode );
808 if( aMode == StdSelect_SM_WINDOW )
810 Standard_Integer aPixelTolerance = atoi( argv[2] );
811 aContext->SetPixelTolerance( aPixelTolerance );
813 else if( aMode == StdSelect_SM_VIEW )
815 Standard_Real aSensitivity = atof( argv[2] );
816 aContext->SetSensitivity( aSensitivity );
823 //==============================================================================
825 //purpose : To dump the active view snapshot to image file
826 //Draw arg : Picture file name with extension corresponding to desired format
827 //==============================================================================
828 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
832 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
836 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
839 TCollection_AsciiString aBuffTypeStr (argv[2]);
840 if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
842 aBufferType = Graphic3d_BT_RGB;
844 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
846 aBufferType = Graphic3d_BT_RGBA;
848 else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
850 aBufferType = Graphic3d_BT_Depth;
854 Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
855 Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
857 Handle(AIS_InteractiveContext) IC;
858 Handle(V3d_View) view;
859 GetCtxAndView (IC, view);
862 di << "Cannot find an active viewer/view\n";
866 if (aWidth <= 0 || aHeight <= 0)
868 if (!view->Dump (argv[1], aBufferType))
870 di << "Dumping failed!\n";
876 Image_AlienPixMap aPixMap;
877 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
879 di << "Dumping failed!\n";
883 if (aPixMap.SizeX() != Standard_Size(aWidth)
884 || aPixMap.SizeY() != Standard_Size(aHeight))
886 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
887 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
889 if (!aPixMap.Save (argv[1]))
891 di << "Saving image failed!\n";
898 //==============================================================================
899 //function : Displays,Erase...
902 //==============================================================================
903 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
904 const Standard_Integer Mode,
905 const Standard_Integer TypeOfOperation,
906 const Standard_Boolean Upd)
908 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
910 switch(TypeOfOperation){
912 Ctx->Display(IO,Mode,Upd);
915 Ctx->Erase(IO,Mode,Upd);
920 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
922 Ctx->SetDisplayMode(IO,Mode,Upd);
927 Ctx->SetDisplayMode(0,Upd);
929 Ctx->UnsetDisplayMode(IO,Upd);
936 //=======================================================================
939 //=======================================================================
940 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
943 TCollection_AsciiString name;
946 // display others presentations
947 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
948 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
949 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
950 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
952 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
954 //unset displaymode.. comportement particulier...
955 if(TypeOfOperation==4){
957 if(Ctx->NbCurrents()==0 ||
958 Ctx->NbSelected()==0){
959 Handle(AIS_InteractiveObject) IO;
960 VwrTst_DispErase(IO,-1,4,Standard_False);
962 else if(!Ctx->HasOpenedContext()){
963 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
964 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
967 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
968 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
969 Ctx->UpdateCurrentViewer();
972 Handle(AIS_InteractiveObject) IO;
974 if(GetMapOfAIS().IsBound2(name)){
975 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
977 VwrTst_DispErase(IO,-1,4,Standard_True);
982 Standard_Integer Dmode = atoi(argv[1]);
983 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
984 Handle(AIS_InteractiveObject) IO;
985 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
987 if(!Ctx->HasOpenedContext()){
988 // set/unset display mode sur le Contexte...
989 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
990 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
992 Ctx->UpdateCurrentViewer();
995 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
996 Ctx->Display(Ctx->Interactive(),Dmode);
1000 Handle(AIS_InteractiveObject) IO;
1002 if(GetMapOfAIS().IsBound2(name))
1003 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1005 VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
1011 //=======================================================================
1014 //=======================================================================
1015 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1017 if(argc==1) return 1;
1018 Standard_Integer On = atoi(argv[1]);
1019 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1023 if(!Ctx->HasOpenedContext()){
1024 di<<"sub intensite ";
1027 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1028 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1030 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1032 di <<"passage dans off"<<"\n";
1033 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1038 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1040 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1042 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1045 Ctx->UpdateCurrentViewer();
1048 Handle(AIS_InteractiveObject) IO;
1049 TCollection_AsciiString name = argv[2];
1050 if(GetMapOfAIS().IsBound2(name)){
1051 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1054 Ctx->SubIntensityOn(IO);
1056 Ctx->SubIntensityOff(IO);
1064 //==============================================================================
1065 //function : VColor2
1067 //purpose : change the color of a selected or named or displayed shape
1068 //Draw arg : vcolor2 [name] color
1069 //==============================================================================
1070 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1073 Standard_Boolean ThereIsCurrent;
1074 Standard_Boolean ThereIsArgument;
1075 Standard_Boolean IsBound = Standard_False ;
1077 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1079 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1080 ThereIsArgument = (argc != 2);
1083 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1084 ThereIsArgument = (argc == 2);
1087 if ( !a3DView().IsNull() ) {
1088 TCollection_AsciiString name;
1089 if (ThereIsArgument) {
1091 IsBound= GetMapOfAIS().IsBound2(name);
1093 if (TheAISContext()->HasOpenedContext())
1094 TheAISContext()->CloseLocalContext();
1096 // On set le Booleen There is current
1097 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1098 else ThereIsCurrent =Standard_False;
1100 //=======================================================================
1101 // Il y a un argument
1102 //=======================================================================
1103 if ( ThereIsArgument && IsBound ) {
1104 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1105 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1106 Handle(AIS_InteractiveObject) ashape =
1107 Handle(AIS_InteractiveObject)::DownCast (anObj);
1110 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1112 di << "HaveToSet 0\n";
1116 TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
1118 TheAISContext()->UnsetColor(ashape);
1119 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1120 Handle(NIS_Triangulated) ashape =
1121 Handle(NIS_Triangulated)::DownCast (anObj);
1122 if (!ashape.IsNull())
1123 ashape->SetColor (GetColorFromName(argv[2]));
1128 //=======================================================================
1129 // Il n'y a pas d'arguments
1130 // Mais un ou plusieurs objets on des current representation
1131 //=======================================================================
1132 if (ThereIsCurrent && !ThereIsArgument) {
1133 for (TheAISContext() -> InitCurrent() ;
1134 TheAISContext() -> MoreCurrent() ;
1135 TheAISContext() ->NextCurrent() )
1137 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1138 if (ashape.IsNull())
1142 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
1144 di << "HaveToSet 0\n";
1147 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1149 TheAISContext()->UnsetColor(ashape,Standard_False);
1152 TheAISContext()->UpdateCurrentViewer();
1155 //=======================================================================
1156 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1157 // on impose a tous les objets du viewer la couleur passee
1158 //=======================================================================
1159 else if (!ThereIsCurrent && !ThereIsArgument){
1160 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1161 while ( it.More() ) {
1162 const Handle(AIS_InteractiveObject) ashape =
1163 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1164 if (!ashape.IsNull())
1166 TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
1168 TheAISContext()->UnsetColor(ashape,Standard_False);
1171 TheAISContext()->UpdateCurrentViewer();
1177 //==============================================================================
1178 //function : VTransparency
1180 //purpose : change the transparency of a selected or named or displayed shape
1181 //Draw arg : vtransparency [name] TransparencyCoeficient
1182 //==============================================================================
1184 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1187 Standard_Boolean ThereIsCurrent;
1188 Standard_Boolean ThereIsArgument;
1189 Standard_Boolean IsBound = Standard_False ;
1191 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1193 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1194 ThereIsArgument = (argc != 2);
1197 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1198 ThereIsArgument = (argc == 2);
1201 if ( !a3DView().IsNull() ) {
1202 TCollection_AsciiString name;
1203 if (ThereIsArgument) {
1205 IsBound= GetMapOfAIS().IsBound2(name);
1207 if (TheAISContext()->HasOpenedContext())
1208 TheAISContext()->CloseLocalContext();
1210 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1211 else ThereIsCurrent = Standard_False;
1213 //=======================================================================
1214 // Il y a des arguments: un nom et une couleur
1215 //=======================================================================
1216 if ( ThereIsArgument && IsBound ) {
1217 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1218 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1219 const Handle(AIS_InteractiveObject) ashape =
1220 Handle(AIS_InteractiveObject)::DownCast(anObj);
1222 TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
1224 TheAISContext()->UnsetTransparency(ashape);
1225 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1226 const Handle(NIS_InteractiveObject) ashape =
1227 Handle(NIS_InteractiveObject)::DownCast(anObj);
1229 ashape->SetTransparency(atof(argv[2]) );
1231 ashape->UnsetTransparency();
1234 //=======================================================================
1235 // Il n'y a pas d'arguments
1236 // Mais un ou plusieurs objets on des current representation
1237 //=======================================================================
1238 if (ThereIsCurrent && !ThereIsArgument) {
1239 for (TheAISContext() -> InitCurrent() ;
1240 TheAISContext() -> MoreCurrent() ;
1241 TheAISContext() ->NextCurrent() )
1243 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1245 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1247 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1250 TheAISContext()->UpdateCurrentViewer();
1252 //=======================================================================
1253 // Il n'y a pas d'arguments ET aucun objet courrant
1254 //=======================================================================
1255 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1256 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1258 while ( it.More() ) {
1259 Handle(AIS_InteractiveObject) ashape =
1260 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1261 if (!ashape.IsNull())
1263 TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
1265 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1268 TheAISContext()->UpdateCurrentViewer();
1275 //==============================================================================
1276 //function : VMaterial
1278 //purpose : change the Material of a selected or named or displayed shape
1279 //Draw arg : vmaterial [Name] Material
1280 //==============================================================================
1281 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1284 Standard_Boolean ThereIsCurrent;
1285 Standard_Boolean ThereIsName;
1286 Standard_Boolean IsBound = Standard_False ;
1288 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1290 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1291 ThereIsName = (argc != 2);
1294 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1295 ThereIsName = (argc == 2);
1298 if ( !a3DView().IsNull() ) {
1299 TCollection_AsciiString name;
1302 IsBound= GetMapOfAIS().IsBound2(name);
1304 if (TheAISContext()->HasOpenedContext())
1305 TheAISContext()->CloseLocalContext();
1306 if (TheAISContext() -> NbCurrents() > 0 )
1307 ThereIsCurrent =Standard_True;
1309 ThereIsCurrent =Standard_False;
1311 //=======================================================================
1312 // Ther is a name of shape and a material name
1313 //=======================================================================
1314 if ( ThereIsName && IsBound ) {
1315 Handle(AIS_InteractiveObject) ashape =
1316 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1317 if (!ashape.IsNull())
1319 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1321 TheAISContext()->UnsetMaterial(ashape);
1323 //=======================================================================
1324 // Il n'y a pas de nom de shape
1325 // Mais un ou plusieurs objets on des current representation
1326 //=======================================================================
1327 if (ThereIsCurrent && !ThereIsName) {
1328 for (TheAISContext() -> InitCurrent() ;
1329 TheAISContext() -> MoreCurrent() ;
1330 TheAISContext() ->NextCurrent() )
1332 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1334 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1336 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1338 TheAISContext()->UpdateCurrentViewer();
1341 //=======================================================================
1342 // Il n'y a pas de noms de shape ET aucun objet courrant
1343 // On impose a tous les objets du viewer le material passe en argument
1344 //=======================================================================
1345 else if (!ThereIsCurrent && !ThereIsName){
1346 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1348 while ( it.More() ) {
1349 Handle(AIS_InteractiveObject) ashape =
1350 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1351 if (!ashape.IsNull())
1353 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1355 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1358 TheAISContext()->UpdateCurrentViewer();
1366 //==============================================================================
1369 //purpose : change the width of the edges of a selected or named or displayed shape
1370 //Draw arg : vwidth [Name] WidthValue(1->10)
1371 //==============================================================================
1372 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1375 Standard_Boolean ThereIsCurrent;
1376 Standard_Boolean ThereIsArgument;
1377 Standard_Boolean IsBound = Standard_False ;
1379 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1381 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1382 ThereIsArgument = (argc != 2);
1385 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1386 ThereIsArgument = (argc == 2);
1388 if ( !a3DView().IsNull() ) {
1389 TCollection_AsciiString name;
1390 if (ThereIsArgument) {
1392 IsBound= GetMapOfAIS().IsBound2(name);
1394 if (TheAISContext()->HasOpenedContext())
1395 TheAISContext()->CloseLocalContext();
1397 if (TheAISContext() -> NbCurrents() > 0 )
1398 ThereIsCurrent =Standard_True;
1400 ThereIsCurrent =Standard_False;
1402 if ( ThereIsArgument && IsBound ) {
1403 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1404 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1405 const Handle(AIS_InteractiveObject) ashape =
1406 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1408 TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
1410 TheAISContext()->UnsetWidth (ashape);
1411 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1412 const Handle(NIS_Triangulated) ashape =
1413 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1414 if (HaveToSet && !ashape.IsNull())
1415 ashape->SetLineWidth ( atof (argv[2]) );
1419 //=======================================================================
1420 // Il n'y a pas d'arguments
1421 // Mais un ou plusieurs objets on des current representation
1422 //=======================================================================
1423 if (ThereIsCurrent && !ThereIsArgument) {
1424 for (TheAISContext() -> InitCurrent() ;
1425 TheAISContext() -> MoreCurrent() ;
1426 TheAISContext() ->NextCurrent() )
1428 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1430 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1432 TheAISContext()->UnsetWidth(ashape,Standard_False);
1434 TheAISContext()->UpdateCurrentViewer();
1436 //=======================================================================
1437 // Il n'y a pas d'arguments ET aucun objet courrant
1438 //=======================================================================
1439 else if (!ThereIsCurrent && !ThereIsArgument){
1440 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1442 while ( it.More() ) {
1443 Handle(AIS_InteractiveObject) ashape =
1444 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1445 if (!ashape.IsNull())
1447 TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
1449 TheAISContext()->UnsetWidth(ashape,Standard_False);
1452 TheAISContext()->UpdateCurrentViewer();
1458 //==============================================================================
1459 //function : VInteriorStyle
1460 //purpose : sets interior style of the a selected or named or displayed shape
1461 //Draw arg : vsetinteriorstyle [shape] style
1462 //==============================================================================
1463 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1464 const Standard_Integer theStyle,
1465 Draw_Interpretor& di)
1467 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1468 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1469 " (Aspect_IS_HIDDENLINE)]\n";
1472 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1473 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1474 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1475 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1476 aFillAspect->SetInteriorStyle (aStyle);
1477 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1480 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1482 if (argc < 2 || argc > 3) {
1483 di << argv[0] << " requires 2 or 3 arguments\n";
1484 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1485 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1486 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1490 Standard_Boolean ThereIsCurrent;
1491 Standard_Boolean ThereIsArgument;
1492 Standard_Boolean IsBound = Standard_False ;
1494 ThereIsArgument = (argc > 2);
1495 if ( !a3DView().IsNull() ) {
1496 TCollection_AsciiString name;
1497 if (ThereIsArgument) {
1499 IsBound= GetMapOfAIS().IsBound2(name);
1501 if (TheAISContext()->HasOpenedContext())
1502 TheAISContext()->CloseLocalContext();
1504 if (TheAISContext() -> NbCurrents() > 0 )
1505 ThereIsCurrent =Standard_True;
1507 ThereIsCurrent =Standard_False;
1509 if ( ThereIsArgument && IsBound ) {
1510 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1511 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1512 const Handle(AIS_InteractiveObject) ashape =
1513 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1514 SetInteriorStyle (ashape, atoi (argv[2]), di);
1517 //=======================================================================
1518 // No arguments specified
1519 // But there are one or more selected objects
1520 //=======================================================================
1521 if (ThereIsCurrent && !ThereIsArgument) {
1522 for (TheAISContext() -> InitCurrent() ;
1523 TheAISContext() -> MoreCurrent() ;
1524 TheAISContext() ->NextCurrent() )
1526 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1527 SetInteriorStyle (ashape, atoi (argv[1]), di);
1530 //=======================================================================
1531 // No arguments specified and there are no selected objects
1532 //=======================================================================
1533 else if (!ThereIsCurrent && !ThereIsArgument){
1534 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1536 while ( it.More() ) {
1537 Handle(AIS_InteractiveObject) ashape =
1538 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1539 if (!ashape.IsNull())
1540 SetInteriorStyle (ashape, atoi (argv[1]), di);
1544 TheAISContext()->UpdateCurrentViewer();
1549 //==============================================================================
1550 //function : VDonly2
1552 //purpose : Display only a selected or named object
1553 // if there is no selected or named object s, nothing is donne
1554 //Draw arg : vdonly2 [name1] ... [name n]
1555 //==============================================================================
1556 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1559 if ( a3DView().IsNull() )
1562 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1563 Standard_Boolean ThereIsArgument= argc>1;
1565 if (TheAISContext()->HasOpenedContext())
1566 TheAISContext()->CloseLocalContext();
1568 //===============================================================
1569 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1571 //===============================================================
1572 if (!ThereIsArgument && ThereIsCurrent) {
1575 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1578 for(TheAISContext()->InitCurrent();
1579 TheAISContext()->MoreCurrent();
1580 TheAISContext()->NextCurrent()){
1581 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1582 TheAISContext()->Erase(aShape,Standard_False);}
1584 TheAISContext() ->UpdateCurrentViewer();
1585 //===============================================================
1586 // Il y a des arguments
1587 //===============================================================
1588 if (ThereIsArgument) {
1589 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1591 while ( it.More() ) {
1592 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1593 const Handle(AIS_InteractiveObject) aShape =
1594 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1595 TheAISContext()->Erase(aShape,Standard_False);
1596 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1597 const Handle(NIS_InteractiveObject) aShape =
1598 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1599 TheNISContext()->Erase(aShape);
1604 // On display les objets passes par parametre
1605 for (int i=1; i<argc ; i++) {
1606 TCollection_AsciiString name=argv[i];
1607 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1609 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1610 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1611 const Handle(AIS_InteractiveObject) aShape =
1612 Handle(AIS_InteractiveObject)::DownCast (anObj);
1613 TheAISContext()->Display(aShape, Standard_False);
1614 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1615 Handle(NIS_InteractiveObject) aShape =
1616 Handle(NIS_InteractiveObject)::DownCast (anObj);
1617 TheNISContext()->Display(aShape);
1621 TheAISContext() ->UpdateCurrentViewer();
1622 // TheNISContext() ->UpdateViews();
1627 //==============================================================================
1628 //function : VErase2
1630 //purpose : Erase some selected or named objects
1631 // if there is no selected or named objects, the whole viewer is erased
1632 //Draw arg : verase2 [name1] ... [name n]
1633 //==============================================================================
1634 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1637 if ( a3DView().IsNull() )
1640 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1641 Standard_Boolean ThereIsArgument= argc>1;
1642 if(TheAISContext()->HasOpenedContext())
1643 TheAISContext()->CloseLocalContext();
1645 //===============================================================
1646 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1648 //===============================================================
1649 if (!ThereIsArgument && ThereIsCurrent) {
1650 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1652 while ( it.More() ) {
1653 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1654 const Handle(AIS_InteractiveObject) aShape =
1655 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1656 if (TheAISContext()->IsCurrent(aShape))
1657 TheAISContext()->Erase(aShape,Standard_False);
1662 TheAISContext() ->UpdateCurrentViewer();
1665 //===============================================================
1666 // Il n'y a pas d'arguments et aucuns objets selectionnes
1668 // On erase tout le viewer
1669 //===============================================================
1671 if (!ThereIsArgument && !ThereIsCurrent) {
1672 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1673 while ( it.More() ) {
1674 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1675 const Handle(AIS_InteractiveObject) aShape =
1676 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1677 TheAISContext()->Erase(aShape,Standard_False);
1678 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1679 const Handle(NIS_InteractiveObject) aShape =
1680 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1681 TheNISContext()->Erase(aShape);
1685 TheAISContext() ->UpdateCurrentViewer();
1686 // TheNISContext()->UpdateViews();
1689 //===============================================================
1690 // Il y a des arguments
1691 //===============================================================
1692 if (ThereIsArgument) {
1693 for (int i=1; i<argc ; i++) {
1694 TCollection_AsciiString name=argv[i];
1695 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1697 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1698 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1699 const Handle(AIS_InteractiveObject) aShape =
1700 Handle(AIS_InteractiveObject)::DownCast (anObj);
1701 TheAISContext()->Erase(aShape,Standard_False);
1702 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1703 const Handle(NIS_InteractiveObject) aShape =
1704 Handle(NIS_InteractiveObject)::DownCast (anObj);
1705 TheNISContext()->Erase(aShape);
1709 TheAISContext() ->UpdateCurrentViewer();
1710 // TheNISContext() ->UpdateViews();
1715 //==============================================================================
1716 //function : VEraseAll
1718 //purpose : Erase all the objects displayed in the viewer
1719 //Draw arg : veraseall
1720 //==============================================================================
1721 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1724 // Verification des arguments
1725 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1726 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1727 TheAISContext()->CloseAllContexts(Standard_False);
1728 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1730 while ( it.More() ) {
1731 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1732 const Handle(AIS_InteractiveObject) aShape =
1733 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1734 TheAISContext()->Erase(aShape,Standard_False);
1735 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1736 const Handle(NIS_InteractiveObject) aShape =
1737 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1738 TheNISContext()->Erase(aShape);
1742 TheAISContext() ->UpdateCurrentViewer();
1743 // TheNISContext() ->UpdateViews();
1748 //==============================================================================
1749 //function : VDisplayAll
1751 //purpose : Display all the objects of the Map
1752 //Draw arg : vdisplayall
1753 //==============================================================================
1754 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1757 if (! a3DView().IsNull() ) {
1758 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1759 if (TheAISContext()->HasOpenedContext())
1760 TheAISContext()->CloseLocalContext();
1761 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1763 while ( it.More() ) {
1764 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1765 const Handle(AIS_InteractiveObject) aShape =
1766 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1767 TheAISContext()->Erase(aShape,Standard_False);
1768 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1769 const Handle(NIS_InteractiveObject) aShape =
1770 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1771 TheNISContext()->Erase(aShape);
1776 while ( it.More() ) {
1777 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1778 const Handle(AIS_InteractiveObject) aShape =
1779 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1780 TheAISContext()->Display(aShape, Standard_False);
1781 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1782 Handle(NIS_InteractiveObject) aShape =
1783 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1784 TheNISContext()->Display(aShape);
1788 TheAISContext() ->UpdateCurrentViewer();
1789 // TheNISContext() ->UpdateViews();
1795 //#######################################################################################################
1798 static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
1800 static Standard_Boolean IsDefined=Standard_False ;
1801 static TCollection_AsciiString VarName;
1803 const char *envir, *casroot ;
1804 envir = getenv("CSF_MDTVTexturesDirectory") ;
1806 Standard_Boolean HasDefinition = Standard_False ;
1808 casroot = getenv("CASROOT");
1810 VarName = TCollection_AsciiString (casroot);
1811 VarName += "/src/Textures" ;
1812 HasDefinition = Standard_True ;
1815 VarName = TCollection_AsciiString (envir);
1816 HasDefinition = Standard_True ;
1818 if ( HasDefinition ) {
1819 OSD_Path aPath ( VarName );
1820 OSD_Directory aDir(aPath);
1821 if ( aDir.Exists () ) {
1822 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
1823 OSD_File TextureFile ( aTexture );
1824 if ( !TextureFile.Exists() ) {
1825 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1826 di << " not all files are found in : "<<VarName.ToCString() << "\n";
1827 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1830 di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
1831 di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
1832 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
1836 di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
1837 di << " one of these variable are mandatory to use this fonctionnality" << "\n";
1838 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
1840 IsDefined = Standard_True ;
1846 //#######################################################################################################
1849 //#######################################################################################################
1853 //#######################################################################################################
1855 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1857 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1858 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1859 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1860 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1861 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1863 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1864 if(myAISContext.IsNull())
1866 di << "use 'vinit' command before " << argv[0] << "\n";
1870 Handle(AIS_InteractiveObject) TheAisIO;
1871 Handle(AIS_TexturedShape) myShape;
1872 Standard_Integer myPreviousMode = 0;
1874 if (argc<2 || !argv[1])
1876 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1880 TCollection_AsciiString name = argv[1];
1881 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1883 if (GetMapOfAIS().IsBound2(name))
1884 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1885 (GetMapOfAIS().Find2(name));
1886 if (TheAisIO.IsNull())
1888 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1892 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1894 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1895 myPreviousMode = myShape->DisplayMode() ;
1899 myAISContext->Clear(TheAisIO,Standard_False);
1900 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1901 GetMapOfAIS().UnBind1(TheAisIO);
1902 GetMapOfAIS().UnBind2(name);
1903 GetMapOfAIS().Bind(myShape, name);
1907 case 1: // vtexture : we only map a texture on the shape
1910 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1913 if (argc>2 && argv[2])
1915 if(strcasecmp(argv[2],"?")==0)
1917 TCollection_AsciiString monPath = GetEnvir (di) ;
1919 di<<"\n Files in current directory : \n"<<"\n";
1920 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1921 di.Eval(Cmnd.ToCString());
1923 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1926 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1927 di.Eval(Cmnd.ToCString());
1932 myShape->SetTextureFileName(argv[2]);
1936 di <<"Texture mapping disabled \n \
1937 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1939 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1940 if (myPreviousMode == 3 )
1941 myAISContext->RecomputePrsOnly(myShape);
1942 myAISContext->Display(myShape, Standard_True);
1947 case 2: // vtexscale : we change the scaling factor of the texture
1951 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1955 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1956 ( argv[2] ? atof(argv[2]) : 1.0 ),
1957 ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
1960 case 3: // vtexorigin : we change the origin of the texture on the shape
1963 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1966 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1967 ( argv[2] ? atof(argv[2]) : 0.0 ),
1968 ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
1971 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1974 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1977 if (argc>2 && argv[2])
1979 di <<"Texture repeat enabled"<<"\n";
1980 myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
1984 di <<"Texture repeat disabled"<<"\n";
1985 myShape->SetTextureRepeat(Standard_False);
1989 case 5: // vtexdefault : default texture mapping
1990 // ScaleU = ScaleV = 100.0
1991 // URepeat = VRepeat = 1.0
1992 // Uorigin = VOrigin = 0.0
1996 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1999 myShape->SetTextureRepeat(Standard_False);
2000 myShape->SetTextureOrigin(Standard_False);
2001 myShape->SetTextureScale (Standard_False);
2005 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
2006 myAISContext->RecomputePrsOnly(myShape);
2009 myAISContext->SetDisplayMode(myShape,3,Standard_False);
2010 myAISContext->Display(myShape, Standard_True);
2011 myAISContext->Update(myShape,Standard_True);
2016 //==============================================================================
2017 //function : VDisplay2
2019 //purpose : Display an object from its name
2020 //Draw arg : vdisplay name1 [name2] ... [name n]
2021 //==============================================================================
2022 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2025 // Verification des arguments
2026 if ( a3DView().IsNull() ) {
2028 ViewerTest::ViewerInit();
2029 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
2034 di<<argv[0]<<" Syntaxe error"<<"\n";
2039 TCollection_AsciiString name;
2040 if (TheAISContext()->HasOpenedContext())
2041 TheAISContext()->CloseLocalContext();
2043 for ( int i = 1; i < argc; i++ ) {
2045 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
2046 Standard_Boolean IsDatum = Standard_False;
2047 Handle(Standard_Transient) anObj;
2049 anObj = GetMapOfAIS().Find2(name);
2050 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
2051 Handle(AIS_InteractiveObject) aShape =
2052 Handle(AIS_InteractiveObject)::DownCast(anObj);
2053 if (aShape->Type()==AIS_KOI_Datum) {
2054 IsDatum = Standard_True;
2055 TheAISContext()->Display(aShape, Standard_False);
2058 di << "Display " << name.ToCString() << "\n";
2059 // Get the Shape from a name
2060 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2062 // Update the Shape in the AIS_Shape
2063 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2064 if(!TheRealSh.IsNull())
2065 TheRealSh->Set(NewShape);
2066 TheAISContext()->Redisplay(aShape, Standard_False);
2067 TheAISContext()->Display(aShape, Standard_False);
2070 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2071 Handle(NIS_InteractiveObject) aShape =
2072 Handle(NIS_InteractiveObject)::DownCast(anObj);
2073 TheNISContext()->Display(aShape);
2076 else { // Create the AIS_Shape from a name
2077 const Handle(AIS_InteractiveObject) aShape =
2078 GetAISShapeFromName((const char *)name.ToCString());
2079 if ( !aShape.IsNull() ) {
2080 GetMapOfAIS().Bind(aShape, name);
2081 TheAISContext()->Display(aShape, Standard_False);
2085 // Upadate the screen and redraw the view
2086 TheAISContext()->UpdateCurrentViewer();
2087 // TheNISContext()->UpdateViews();
2091 //==============================================================================
2093 //purpose : Test the annimation of an object along a
2094 // predifined trajectory
2095 //Draw arg : vmove ShapeName
2096 //==============================================================================
2099 static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2104 if (TheAISContext()->HasOpenedContext())
2105 TheAISContext()->CloseLocalContext();
2107 Standard_Real Step=2*M_PI/180;
2108 Standard_Real Angle=0;
2109 // R est le rayon de l'hellicoide
2111 // D est la distance parcourue en translation en 1 tour
2114 Handle(AIS_InteractiveObject) aIO;
2116 if (GetMapOfAIS().IsBound2(argv[1]))
2117 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2120 di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
2123 TheAISContext()->Deactivate(aIO);
2125 // boucle generant le mouvement
2127 di<<" Transformations"<<"\n";
2128 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2131 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) );
2133 myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
2134 TheAISContext()->SetLocation(aIO,myTransfo);
2136 TheAISContext() ->UpdateCurrentViewer();
2141 di<<" Locations"<<"\n";
2142 gp_Trsf myAngleTrsf;
2143 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2144 TopLoc_Location myDeltaAngle (myAngleTrsf);
2146 myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
2147 TopLoc_Location myDeltaDist (myDistTrsf);
2148 TopLoc_Location myTrueLoc;
2150 for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
2153 myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
2154 TheAISContext()->SetLocation(aIO,myTrueLoc );
2155 TheAISContext() ->UpdateCurrentViewer();
2160 TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
2162 //TopLoc_Location Tempo=aIO->Location();
2163 //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
2164 //ShapeBis.Located(Tempo);
2167 // On reset la location (origine) contenue dans l'AISInteractiveObject
2168 TheAISContext() ->ResetLocation(aIO);
2170 // On force aShape a devenir l'AIS IO propre a ShapeBis
2172 // Pour cela on force aShape(AIS IO) a devenir une AISShape
2173 // ->Set() est une methode de AIS_Shape
2174 (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
2176 // On donne a ShapeBis le nom de l'AIS IO
2177 //Rep::Set(argv[1],ShapeBis);
2180 TheAISContext()->Redisplay(aIO,Standard_False);
2182 // On reactive la selection des primitives sensibles
2183 TheAISContext()->Activate(aIO,0);
2185 TheAISContext() ->UpdateCurrentViewer();
2186 a3DView() -> Redraw();
2189 di<<" Temps ecoule "<<"\n";
2197 //==============================================================================
2199 //purpose : Test the annimation of an object along a
2200 // predifined trajectory
2201 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2202 //==============================================================================
2204 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2207 if (TheAISContext()->HasOpenedContext())
2208 TheAISContext()->CloseLocalContext();
2210 Standard_Real Step=4*M_PI/180;
2211 Standard_Real Angle=0;
2213 Handle(AIS_InteractiveObject) aIO;
2214 if (GetMapOfAIS().IsBound2(argv[1]))
2215 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2219 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2223 if (atoi(argv[3])==1 ) {
2224 di<<" Primitives sensibles OFF"<<"\n";
2225 TheAISContext()->Deactivate(aIO);
2228 di<<" Primitives sensibles ON"<<"\n";
2230 // Movement par transformation
2231 if(atoi(argv[2]) ==1) {
2232 di<<" Calcul par Transformation"<<"\n";
2233 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2237 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2238 TheAISContext()->SetLocation(aShape,myTransfo);
2239 TheAISContext() ->UpdateCurrentViewer();
2244 di<<" Calcul par Locations"<<"\n";
2245 gp_Trsf myAngleTrsf;
2246 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2247 TopLoc_Location myDeltaAngle (myAngleTrsf);
2248 TopLoc_Location myTrueLoc;
2250 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2253 myTrueLoc=myTrueLoc*myDeltaAngle;
2254 TheAISContext()->SetLocation(aShape,myTrueLoc );
2255 TheAISContext() ->UpdateCurrentViewer();
2258 if (atoi(argv[3])==1 ){
2259 // On reactive la selection des primitives sensibles
2260 TheAISContext()->Activate(aIO,0);
2262 a3DView() -> Redraw();
2264 di<<" Temps ecoule "<<"\n";
2270 //==================================================================================
2271 // Function : VAnimation
2272 //==================================================================================
2273 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2275 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2279 Standard_Real thread = 4;
2280 Standard_Real angleA=0;
2281 Standard_Real angleB;
2283 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2286 TopoDS_Shape CrankArm;
2287 TopoDS_Shape CylinderHead;
2288 TopoDS_Shape Propeller;
2289 TopoDS_Shape EngineBlock;
2291 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2292 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2293 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2294 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2295 BRepTools::Read(CrankArm,argv[1],B);
2296 BRepTools::Read(CylinderHead,argv[2],B);
2297 BRepTools::Read(Propeller,argv[3],B);
2298 BRepTools::Read(EngineBlock,argv[4],B);
2300 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2306 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2307 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2308 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2309 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2311 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2312 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2313 GetMapOfAIS().Bind(myAisCrankArm,"c");
2314 GetMapOfAIS().Bind(myAisPropeller,"d");
2316 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2317 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2318 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2320 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2321 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2322 TheAISContext()->Display(myAisCrankArm,Standard_False );
2323 TheAISContext()->Display(myAisPropeller,Standard_False);
2325 TheAISContext()->Deactivate(myAisCylinderHead);
2326 TheAISContext()->Deactivate(myAisEngineBlock );
2327 TheAISContext()->Deactivate(myAisCrankArm );
2328 TheAISContext()->Deactivate(myAisPropeller );
2330 // Boucle de mouvement
2331 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2333 angleA = thread*myAngle*M_PI/180;
2334 X = Sin(angleA)*3/8;
2335 angleB = atan(X / Sqrt(-X * X + 1));
2336 Standard_Real decal(25*0.6);
2339 //Build a transformation on the display
2340 gp_Trsf aPropellerTrsf;
2341 aPropellerTrsf.SetRotation(Ax1,angleA);
2342 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2344 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));
2345 gp_Trsf aCrankArmTrsf;
2346 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2347 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2349 TheAISContext()->UpdateCurrentViewer();
2352 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2353 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2355 myAisCrankArm ->ResetLocation();
2356 myAisPropeller->ResetLocation();
2358 myAisCrankArm -> Set(myNewCrankArm );
2359 myAisPropeller -> Set(myNewPropeller);
2361 TheAISContext()->Activate(myAisCylinderHead,0);
2362 TheAISContext()->Activate(myAisEngineBlock,0 );
2363 TheAISContext()->Activate(myAisCrankArm ,0 );
2364 TheAISContext()->Activate(myAisPropeller ,0 );
2370 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2371 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2373 TheAISContext()->UpdateCurrentViewer();
2374 a3DView()->Redraw();
2383 //==============================================================================
2384 //function : VShading
2385 //purpose : Sharpen or roughten the quality of the shading
2386 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2387 //==============================================================================
2388 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2390 Standard_Real myDevCoef;
2391 Handle(AIS_InteractiveObject) TheAisIO;
2394 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2396 if (TheAISContext()->HasOpenedContext())
2397 TheAISContext()->CloseLocalContext();
2402 myDevCoef =atof(argv[2]);
2405 TCollection_AsciiString name=argv[1];
2406 if (GetMapOfAIS().IsBound2(name ))
2407 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2408 if (TheAisIO.IsNull())
2409 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2412 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2414 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2416 TheAISContext()->Redisplay(TheAisIO);
2419 //==============================================================================
2420 //function : HaveMode
2421 //use : VActivatedModes
2422 //==============================================================================
2423 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2425 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2427 TColStd_ListOfInteger List;
2428 TheAISContext()->ActivatedModes (TheAisIO,List);
2429 TColStd_ListIteratorOfListOfInteger it;
2430 Standard_Boolean Found=Standard_False;
2431 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2432 if (it.Value()==mode ) Found=Standard_True;
2439 //==============================================================================
2440 //function : VActivatedMode
2442 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2443 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2444 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2445 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2446 // qu'un nom et qu'un mode.
2447 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2448 //==============================================================================
2449 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2451 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2454 Standard_Boolean ThereIsName = Standard_False ;
2456 if(!a3DView().IsNull()){
2458 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2459 // verification des arguments
2461 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2462 ThereIsName = (argc == 3);
2466 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2468 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2469 di<<" Fermeture du Context local"<<"\n";
2470 if (TheAISContext()->HasOpenedContext())
2471 TheAISContext()->CloseLocalContext();
2475 // IL n'y a aps de nom de shape passe en argument
2476 if (HaveToSet && !ThereIsName){
2477 Standard_Integer aMode=atoi(argv [1]);
2479 const char *cmode="???";
2481 case 0: cmode = "Shape"; break;
2482 case 1: cmode = "Vertex"; break;
2483 case 2: cmode = "Edge"; break;
2484 case 3: cmode = "Wire"; break;
2485 case 4: cmode = "Face"; break;
2486 case 5: cmode = "Shell"; break;
2487 case 6: cmode = "Solid"; break;
2488 case 7: cmode = "Compound"; break;
2491 if( !TheAISContext()->HasOpenedContext() ) {
2492 // il n'y a pas de Context local d'ouvert
2493 // on en ouvre un et on charge toutes les shapes displayees
2494 // on load tous les objets displayees et on Activate les objets de la liste
2495 AIS_ListOfInteractive ListOfIO;
2496 // on sauve dans une AISListOfInteractive tous les objets currents
2497 if (TheAISContext()->NbCurrents()>0 ){
2498 TheAISContext()->UnhilightCurrents(Standard_False);
2500 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2501 ListOfIO.Append(TheAISContext()->Current() );
2505 TheAISContext()->OpenLocalContext(Standard_False);
2506 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2509 Handle(AIS_InteractiveObject) aIO =
2510 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2512 TheAISContext()->Load(aIO,0,Standard_False);
2515 // traitement des objets qui etaient currents dans le Contexte global
2516 if (!ListOfIO.IsEmpty() ) {
2517 // il y avait des objets currents
2518 AIS_ListIteratorOfListOfInteractive iter;
2519 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2520 Handle(AIS_InteractiveObject) aIO=iter.Value();
2521 TheAISContext()->Activate(aIO,aMode);
2522 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2526 // On applique le mode a tous les objets displayes
2527 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2528 it2 (GetMapOfAIS());
2530 Handle(AIS_InteractiveObject) aIO =
2531 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2532 if (!aIO.IsNull()) {
2533 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2534 TheAISContext()->Activate(aIO,aMode);
2543 // un Context local est deja ouvert
2544 // Traitement des objets du Context local
2545 if (TheAISContext()->NbSelected()>0 ){
2546 TheAISContext()->UnhilightSelected(Standard_False);
2547 // il y a des objets selected,on les parcourt
2548 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2549 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2552 if (HaveMode(aIO,aMode) ) {
2553 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2554 TheAISContext()->Deactivate(aIO,aMode);
2557 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2558 TheAISContext()->Activate(aIO,aMode);
2564 // il n'y a pas d'objets selected
2565 // tous les objets diplayes sont traites
2566 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2569 Handle(AIS_InteractiveObject) aIO =
2570 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2571 if (!aIO.IsNull()) {
2572 if (HaveMode(aIO,aMode) ) {
2573 di<<" Mode: "<<cmode<<" OFF pour "
2574 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2575 TheAISContext()->Deactivate(aIO,aMode);
2578 di<<" Mode: "<<cmode<<" ON pour"
2579 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2580 TheAISContext()->Activate(aIO,aMode);
2588 else if (HaveToSet && ThereIsName){
2589 Standard_Integer aMode=atoi(argv [2]);
2590 Handle(AIS_InteractiveObject) aIO =
2591 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2593 if (!aIO.IsNull()) {
2594 const char *cmode="???";
2597 case 0: cmode = "Shape"; break;
2598 case 1: cmode = "Vertex"; break;
2599 case 2: cmode = "Edge"; break;
2600 case 3: cmode = "Wire"; break;
2601 case 4: cmode = "Face"; break;
2602 case 5: cmode = "Shell"; break;
2603 case 6: cmode = "Solid"; break;
2604 case 7: cmode = "Compound"; break;
2607 if( !TheAISContext()->HasOpenedContext() ) {
2608 TheAISContext()->OpenLocalContext(Standard_False);
2609 // On charge tous les objets de la map
2610 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2612 Handle(AIS_InteractiveObject) aShape=
2613 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2614 if (!aShape.IsNull())
2615 TheAISContext()->Load(aShape,0,Standard_False);
2618 TheAISContext()->Activate(aIO,aMode);
2619 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2623 // un Context local est deja ouvert
2624 if (HaveMode(aIO,aMode) ) {
2625 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2626 TheAISContext()->Deactivate(aIO,aMode);
2629 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2630 TheAISContext()->Activate(aIO,aMode);
2642 //==============================================================================
2643 // function : WhoAmI
2645 //==============================================================================
2646 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2649 if (theShape->Type()==AIS_KOI_Datum) {
2650 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2651 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2652 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2653 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2654 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2655 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2656 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2659 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2660 // AIS_Dimentions et AIS_Relations
2661 else if (theShape->Type()==AIS_KOI_Relation) {
2662 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2664 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2665 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2666 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2667 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2668 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2669 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2670 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2671 // AIS no repertorie.
2672 else {di<<" Type Unknown.";}
2678 //==============================================================================
2681 //Draw arg : vstate [nameA] ... [nameN]
2682 //==============================================================================
2683 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2685 TheAISContext()->CloseAllContexts();
2686 const Standard_Boolean ThereIsArguments=(argc>=2);
2687 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2689 // ==================
2690 // Il y a un argument
2691 // ==================
2692 if (ThereIsArguments) {
2693 for (int cpt=1;cpt<argc;cpt++) {
2694 // Verification que lq piece est bien bindee.
2695 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2696 const Handle(AIS_InteractiveObject) theShape=
2697 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2699 if (!theShape.IsNull()) {
2700 di<<argv[cpt];WhoAmI(theShape, di);
2701 if (TheAISContext()->IsDisplayed(theShape) ) {
2702 di<<" Displayed"<<"\n";
2705 di<<" Not Displayed"<<"\n";
2710 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2714 else if (ThereIsCurrent ) {
2715 for (TheAISContext() -> InitCurrent() ;
2716 TheAISContext() -> MoreCurrent() ;
2717 TheAISContext() ->NextCurrent() )
2719 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2720 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2721 if (TheAISContext()->IsDisplayed(theShape) ) {
2722 di<<" Displayed"<<"\n";
2725 di<<" Not Displayed"<<"\n";
2731 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2733 while ( it.More() ) {
2734 Handle(AIS_InteractiveObject) theShape =
2735 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2736 if (!theShape.IsNull()) {
2737 di<<it.Key2().ToCString();
2738 WhoAmI(theShape, di);
2739 if (TheAISContext()->IsDisplayed(theShape) ) {
2740 di<<" Displayed"<<"\n";
2743 di<<" Not Displayed"<<"\n";
2754 //=======================================================================
2755 //function : PickObjects
2757 //=======================================================================
2758 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2759 const AIS_KindOfInteractive TheType,
2760 const Standard_Integer TheSignature,
2761 const Standard_Integer MaxPick)
2763 Handle(AIS_InteractiveObject) IO;
2764 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2766 // step 1: prepare the data
2768 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2769 TheAISContext()->AddFilter(F1);
2772 // step 2 : wait for the selection...
2773 // Standard_Boolean IsGood (Standard_False);
2774 // Standard_Integer NbPick(0);
2775 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2776 Standard_Integer NbPickFail(0);
2777 Standard_Integer argccc = 5;
2778 const char *bufff[] = { "A", "B", "C","D", "E" };
2779 const char **argvvv = (const char **) bufff;
2782 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2783 while(ViewerMainLoop(argccc,argvvv)){}
2784 Standard_Integer NbStored = TheAISContext()->NbSelected();
2785 if((unsigned int ) NbStored != NbPickGood)
2786 NbPickGood= NbStored;
2789 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2792 // step3 get result.
2794 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2796 Standard_Integer i(0);
2797 for(TheAISContext()->InitSelected();
2798 TheAISContext()->MoreSelected();
2799 TheAISContext()->NextSelected()){
2801 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2802 arr->SetValue(i,IO2);
2807 TheAISContext()->CloseLocalContext(curindex);
2809 return Standard_True;
2813 //=======================================================================
2814 //function : PickObject
2816 //=======================================================================
2817 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2818 const Standard_Integer TheSignature,
2819 const Standard_Integer MaxPick)
2821 Handle(AIS_InteractiveObject) IO;
2822 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2824 // step 1: prepare the data
2827 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2828 TheAISContext()->AddFilter(F1);
2831 // step 2 : wait for the selection...
2832 Standard_Boolean IsGood (Standard_False);
2833 Standard_Integer NbPick(0);
2834 Standard_Integer argccc = 5;
2835 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2836 const char **argvvv = (const char **) bufff;
2839 while(!IsGood && NbPick<= MaxPick){
2840 while(ViewerMainLoop(argccc,argvvv)){}
2841 IsGood = (TheAISContext()->NbSelected()>0) ;
2843 cout<<"Nb Pick :"<<NbPick<<endl;
2847 // step3 get result.
2849 TheAISContext()->InitSelected();
2850 IO = TheAISContext()->SelectedInteractive();
2854 TheAISContext()->CloseLocalContext(curindex);
2858 //=======================================================================
2859 //function : PickShape
2860 //purpose : First Activate the rightmode + Put Filters to be able to
2861 // pick objets that are of type <TheType>...
2862 //=======================================================================
2864 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2865 const Standard_Integer MaxPick)
2868 // step 1: prepare the data
2870 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2871 TopoDS_Shape result;
2873 if(TheType==TopAbs_SHAPE){
2874 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2875 TheAISContext()->AddFilter(F1);
2878 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2879 TheAISContext()->AddFilter(TF);
2880 TheAISContext()->ActivateStandardMode(TheType);
2885 // step 2 : wait for the selection...
2886 Standard_Boolean NoShape (Standard_True);
2887 Standard_Integer NbPick(0);
2888 Standard_Integer argccc = 5;
2889 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2890 const char **argvvv = (const char **) bufff;
2893 while(NoShape && NbPick<= MaxPick){
2894 while(ViewerMainLoop(argccc,argvvv)){}
2895 NoShape = (TheAISContext()->NbSelected()==0) ;
2897 cout<<"Nb Pick :"<<NbPick<<endl;
2900 // step3 get result.
2904 TheAISContext()->InitSelected();
2905 if(TheAISContext()->HasSelectedShape())
2906 result = TheAISContext()->SelectedShape();
2908 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2909 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2914 TheAISContext()->CloseLocalContext(curindex);
2920 //=======================================================================
2921 //function : PickShapes
2923 //=======================================================================
2924 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2925 Handle(TopTools_HArray1OfShape)& thearr,
2926 const Standard_Integer MaxPick)
2929 Standard_Integer Taille = thearr->Length();
2931 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2933 // step 1: prepare the data
2934 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2935 if(TheType==TopAbs_SHAPE){
2936 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2937 TheAISContext()->AddFilter(F1);
2940 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2941 TheAISContext()->AddFilter(TF);
2942 TheAISContext()->ActivateStandardMode(TheType);
2946 // step 2 : wait for the selection...
2948 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2949 Standard_Integer NbPickFail(0);
2950 Standard_Integer argccc = 5;
2951 const char *bufff[] = { "A", "B", "C","D", "E" };
2952 const char **argvvv = (const char **) bufff;
2955 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2956 while(ViewerMainLoop(argccc,argvvv)){}
2957 Standard_Integer NbStored = TheAISContext()->NbSelected();
2958 if((unsigned int ) NbStored != NbPickGood)
2959 NbPickGood= NbStored;
2962 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2965 // step3 get result.
2967 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2969 Standard_Integer i(0);
2970 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2972 if(TheAISContext()->HasSelectedShape())
2973 thearr->SetValue(i,TheAISContext()->SelectedShape());
2975 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2976 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2980 TheAISContext()->CloseLocalContext(curindex);
2981 return Standard_True;
2985 //=======================================================================
2986 //function : VPickShape
2988 //=======================================================================
2989 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2991 TopoDS_Shape PickSh;
2992 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2995 theType = TopAbs_SHAPE;
2997 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2998 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2999 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3000 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3001 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3002 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3003 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3006 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3007 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3009 TCollection_AsciiString name;
3012 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3014 PickSh = ViewerTest::PickShape(theType);
3023 if(!PickSh.IsNull()){
3024 nbOfSub[Standard_Integer(theType)]++;
3026 name += nameType[Standard_Integer(theType)];
3027 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3032 // si on avait une petite methode pour voir si la shape
3033 // est deja dans la Double map, ca eviterait de creer....
3034 DBRep::Set(name.ToCString(),PickSh);
3036 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3037 GetMapOfAIS().Bind(newsh, name);
3038 TheAISContext()->Display(newsh);
3039 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3042 // Plusieurs objets a picker, vite vite vite....
3045 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3046 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3047 if(ViewerTest::PickShapes(theType,arr)){
3048 for(Standard_Integer i=1;i<=NbToPick;i++){
3049 PickSh = arr->Value(i);
3050 if(!PickSh.IsNull()){
3052 nbOfSub[Standard_Integer(theType)]++;
3055 name += nameType[Standard_Integer(theType)];
3056 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3064 DBRep::Set(name.ToCString(),PickSh);
3065 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3066 GetMapOfAIS().Bind(newsh, name);
3067 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3068 TheAISContext()->Display(newsh);
3078 //=======================================================================
3079 //function : VPickObject
3080 //purpose : filters can be set (type of Object to pick....
3082 //=======================================================================
3085 static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
3087 // preparation de la nomination automatique
3088 static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
3089 // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
3091 /* TCollection_AsciiString name;
3093 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3095 PickSh = ViewerTest::PickObject(theType);
3104 if(!PickSh.IsNull()){
3105 nbOfSub[Standard_Integer(theType)]++;
3107 name += nameType[Standard_Integer(theType)];
3108 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3113 // si on avait une petite methode pour voir si la shape
3114 // est deja dans la Double map, ca eviterait de creer....
3115 DBRep::Set(name.ToCString(),PickSh);
3117 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3118 GetMapOfAIS().Bind(newsh, name);
3119 TheAISContext()->Display(newsh);
3120 cout<<"Nom de la shape pickee : "<<name<<endl;
3123 // Plusieurs objets a picker, vite vite vite....
3126 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3127 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3128 if(ViewerTest::PickShapes(theType,arr)){
3129 for(Standard_Integer i=1;i<=NbToPick;i++){
3130 PickSh = arr->Value(i);
3131 if(!PickSh.IsNull()){
3133 nbOfSub[Standard_Integer(theType)]++;
3136 name += nameType[Standard_Integer(theType)];
3137 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3145 DBRep::Set(name.ToCString(),PickSh);
3146 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3147 GetMapOfAIS().Bind(newsh, name);
3148 cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
3149 TheAISContext()->Display(newsh);
3159 //=======================================================================
3160 //function : list of known objects
3162 //=======================================================================
3163 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3165 // 1234567890 12345678901234567 123456789
3166 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3167 TCollection_AsciiString BlankLine(64,'_');
3168 Standard_Integer i ;
3170 di<<"/n"<<BlankLine.ToCString()<<"\n";
3173 Colum[i].Center(20,' ');
3175 di<<"|"<<Colum[i].ToCString();
3178 di<<BlankLine.ToCString()<<"\n";
3180 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3181 const char ** names = GetTypeNames();
3183 TCollection_AsciiString curstring;
3184 TCollection_AsciiString curcolum[3];
3187 // les objets de type Datum..
3188 curcolum[1]+="Datum";
3190 curcolum[0].Clear();
3191 curcolum[0] += names[i];
3193 curcolum[2].Clear();
3194 curcolum[2]+=TCollection_AsciiString(i+1);
3196 for(Standard_Integer j =0;j<=2;j++){
3197 curcolum[j].Center(20,' ');
3198 di<<"|"<<curcolum[j].ToCString();
3202 di<<BlankLine.ToCString()<<"\n";
3204 // les objets de type shape
3205 curcolum[1].Clear();
3206 curcolum[1]+="Shape";
3207 curcolum[1].Center(20,' ');
3210 curcolum[0].Clear();
3211 curcolum[0] += names[7+i];
3212 curcolum[2].Clear();
3213 curcolum[2]+=TCollection_AsciiString(i);
3215 for(Standard_Integer j =0;j<=2;j++){
3216 curcolum[j].Center(20,' ');
3217 di<<"|"<<curcolum[j].ToCString();
3221 di<<BlankLine.ToCString()<<"\n";
3222 // les IO de type objet...
3223 curcolum[1].Clear();
3224 curcolum[1]+="Object";
3225 curcolum[1].Center(20,' ');
3227 curcolum[0].Clear();
3228 curcolum[0] += names[10+i];
3229 curcolum[2].Clear();
3230 curcolum[2]+=TCollection_AsciiString(i);
3232 for(Standard_Integer j =0;j<=2;j++){
3233 curcolum[j].Center(20,' ');
3234 di<<"|"<<curcolum[j].ToCString();
3238 di<<BlankLine.ToCString()<<"\n";
3239 // les contraintes et dimensions.
3240 // pour l'instant on separe juste contraintes et dimensions...
3241 // plus tard, on detaillera toutes les sortes...
3242 curcolum[1].Clear();
3243 curcolum[1]+="Relation";
3244 curcolum[1].Center(20,' ');
3246 curcolum[0].Clear();
3247 curcolum[0] += names[12+i];
3248 curcolum[2].Clear();
3249 curcolum[2]+=TCollection_AsciiString(i);
3251 for(Standard_Integer j =0;j<=2;j++){
3252 curcolum[j].Center(20,' ');
3253 di<<"|"<<curcolum[j].ToCString();
3257 di<<BlankLine.ToCString()<<"\n";
3264 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3266 if(argc!=2) return 1;
3268 AIS_KindOfInteractive TheType;
3269 Standard_Integer TheSign(-1);
3270 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3273 AIS_ListOfInteractive LIO;
3275 // en attendant l'amelioration ais pour les dimensions...
3277 Standard_Integer dimension_status(-1);
3278 if(TheType==AIS_KOI_Relation){
3279 dimension_status = TheSign ==1 ? 1 : 0;
3283 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3284 Handle(AIS_InteractiveObject) curio;
3285 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3288 if(dimension_status == -1)
3289 TheAISContext()->Erase(curio,Standard_False);
3291 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3292 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3293 (dimension_status==1 && KOD != AIS_KOD_NONE))
3294 TheAISContext()->Erase(curio,Standard_False);
3297 TheAISContext()->UpdateCurrentViewer();
3300 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3302 if(argc!=2) return 1;
3304 AIS_KindOfInteractive TheType;
3305 Standard_Integer TheSign(-1);
3306 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3308 // en attendant l'amelioration ais pour les dimensions...
3310 Standard_Integer dimension_status(-1);
3311 if(TheType==AIS_KOI_Relation){
3312 dimension_status = TheSign ==1 ? 1 : 0;
3316 AIS_ListOfInteractive LIO;
3317 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3318 Handle(AIS_InteractiveObject) curio;
3319 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3321 if(dimension_status == -1)
3322 TheAISContext()->Display(curio,Standard_False);
3324 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3325 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3326 (dimension_status==1 && KOD != AIS_KOD_NONE))
3327 TheAISContext()->Display(curio,Standard_False);
3332 TheAISContext()->UpdateCurrentViewer();
3336 //==============================================================================
3337 //function : VSetTransMode
3339 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3340 //==============================================================================
3342 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3343 // Verification des arguments
3344 if ( a3DView().IsNull() ) {
3345 ViewerTest::ViewerInit();
3346 di << "La commande vinit n'a pas ete appele avant" << "\n";
3349 if ( argc < 3 || argc > 8 ) {
3350 di << argv[0] << " Invalid number of arguments" << "\n";
3354 TCollection_AsciiString shapeName;
3355 shapeName = argv[1];
3356 Standard_Integer persFlag1 = atoi(argv[2]);
3357 Standard_Integer persFlag2 = 0;
3358 Standard_Integer persFlag3 = 0;
3359 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3360 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3361 persFlag2 = atoi(argv[3]);
3363 if ( argc == 5 || argc == 8 ) {
3364 persFlag3 = atoi(argv[4]);
3367 origin.SetX( atof(argv[argc - 3]) );
3368 origin.SetY( atof(argv[argc - 2]) );
3369 origin.SetZ( atof(argv[argc - 1]) );
3372 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3373 Handle(Standard_Transient) anObj;
3375 anObj = GetMapOfAIS().Find2(shapeName);
3376 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3377 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3378 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3379 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3380 di << argv[0] << " All persistence modifiers were removed" << "\n";
3383 di << argv[0] << " Wrong object type" << "\n";
3386 } else { // Create the AIS_Shape from a name
3387 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3388 if ( !aShape.IsNull() ) {
3389 GetMapOfAIS().Bind( aShape, shapeName );
3390 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3391 TheAISContext()->Display( aShape, Standard_False );
3393 di << argv[0] << " Object not found" << "\n";
3398 // Upadate the screen and redraw the view
3399 TheAISContext()->UpdateCurrentViewer();
3403 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3406 BRep_Builder builder;
3408 BRepTools::Read(shape, s, builder);
3409 DBRep::Set(a[1], shape);
3410 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3411 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3415 //============================================================================
3416 #include <AIS2D_InteractiveContext.hxx>
3417 #include <HLRAlgo_Projector.hxx>
3418 #include <Prs3d_Projector.hxx>
3419 #include <AIS2D_ProjShape.hxx>
3420 #include <gp_Ax2.hxx>
3422 Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3425 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3426 /////////////////////
3427 TopoDS_Shape aShape = DBRep::Get(a[1]);
3428 aContext2D->EraseAll(Standard_True);
3429 //Standard_Integer aPolyAlgo = 0;
3430 Standard_Boolean IsPoly = Standard_False;
3431 gp_Ax2 anAx2 = gp::XOY();
3433 //if(n > 2) aPolyAlgo = atoi(a[2]);
3435 //IsPoly = aPolyAlgo > 0;
3437 TopoDS_Shape aResult = aShape;
3442 Standard_Real x = atof(a[2]);
3443 Standard_Real y = atof(a[3]);
3444 Standard_Real z = atof(a[4]);
3446 Standard_Real dx = atof(a[5]);
3447 Standard_Real dy = atof(a[6]);
3448 Standard_Real dz = atof(a[7]);
3450 Standard_Real dx1 = atof(a[8]);
3451 Standard_Real dy1 = atof(a[9]);
3452 Standard_Real dz1 = atof(a[10]);
3454 gp_Pnt anOrigin (x, y, z);
3455 gp_Dir aNormal (dx, dy, dz);
3456 gp_Dir aDX (dx1, dy1, dz1);
3457 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3461 HLRAlgo_Projector aProjector(anAx2);
3463 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3465 //aProjector = aProjector_t.Projector();
3467 Handle(AIS2D_ProjShape) myDisplayableShape =
3468 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3470 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3471 Standard_False, Standard_True, Standard_False);
3473 myDisplayableShape->Add( aResult );
3476 aContext2D->Display( myDisplayableShape,Standard_True );
3477 aContext2D->UpdateCurrentViewer();
3482 Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
3485 Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
3486 /////////////////////
3487 TopoDS_Shape aShape = DBRep::Get(a[1]);
3488 aContext2D->EraseAll(Standard_True);
3489 //Standard_Integer aPolyAlgo = 0;
3490 Standard_Boolean IsPoly = Standard_True;
3491 gp_Ax2 anAx2 = gp::XOY();
3493 //if(n > 2) aPolyAlgo = atoi(a[2]);
3495 //IsPoly = aPolyAlgo > 0;
3497 TopoDS_Shape aResult = aShape;
3502 Standard_Real x = atof(a[2]);
3503 Standard_Real y = atof(a[3]);
3504 Standard_Real z = atof(a[4]);
3506 Standard_Real dx = atof(a[5]);
3507 Standard_Real dy = atof(a[6]);
3508 Standard_Real dz = atof(a[7]);
3510 Standard_Real dx1 = atof(a[8]);
3511 Standard_Real dy1 = atof(a[9]);
3512 Standard_Real dz1 = atof(a[10]);
3514 gp_Pnt anOrigin (x, y, z);
3515 gp_Dir aNormal (dx, dy, dz);
3516 gp_Dir aDX (dx1, dy1, dz1);
3517 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
3521 HLRAlgo_Projector aProjector(anAx2);
3523 //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
3525 //aProjector = aProjector_t.Projector();
3527 Handle(AIS2D_ProjShape) myDisplayableShape =
3528 new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
3530 myDisplayableShape->ShowEdges(Standard_True, Standard_False,
3531 Standard_False, Standard_True, Standard_False);
3533 myDisplayableShape->Add( aResult );
3536 aContext2D->Display( myDisplayableShape,Standard_True );
3537 aContext2D->UpdateCurrentViewer();
3542 //==============================================================================
3543 //function : ViewerTest::Commands
3544 //purpose : Add all the viewer command in the Draw_Interpretor
3545 //==============================================================================
3547 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3549 ViewerTest::ViewerCommands(theCommands);
3550 ViewerTest::RelationCommands(theCommands);
3551 ViewerTest::ObjectCommands(theCommands);
3552 ViewerTest::FilletCommands(theCommands);
3553 ViewerTest::VoxelCommands(theCommands);
3554 ViewerTest::OpenGlCommands(theCommands);
3556 const char *group = "AIS_Display";
3560 theCommands.Add("vdisplay",
3561 "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
3562 __FILE__,VDisplay2,group);
3564 theCommands.Add("verase",
3565 "verase : verase2 [name1] ... [name n] ",
3566 __FILE__,VErase2,group);
3568 theCommands.Add("vdonly",
3569 "vdonly : vdonly2 [name1] ... [name n]",
3570 __FILE__,VDonly2,group);
3572 theCommands.Add("vdisplayall",
3573 "vdisplayall : vdisplayall",
3574 __FILE__,VDisplayAll,group);
3576 theCommands.Add("veraseall",
3577 "veraseall : veraseall ",
3578 __FILE__,VEraseAll,group);
3580 theCommands.Add("verasetype",
3581 "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
3582 __FILE__,VEraseType,group);
3584 theCommands.Add("vdisplaytype",
3585 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3586 __FILE__,VDisplayType,group);
3588 theCommands.Add("vdisplaymode",
3589 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3590 __FILE__,VDispMode,group);
3592 theCommands.Add("verasemode",
3593 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3594 __FILE__,VDispMode,group);
3596 theCommands.Add("vsetdispmode",
3597 "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
3598 __FILE__,VDispMode,group);
3600 theCommands.Add("vunsetdispmode",
3601 "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
3602 __FILE__,VDispMode,group);
3604 theCommands.Add("vdir",
3606 __FILE__,VDebug,group);
3608 theCommands.Add("vdump",
3609 "<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",
3610 __FILE__,VDump,group);
3612 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3613 __FILE__,VSubInt,group);
3615 theCommands.Add("vsetcolor",
3616 "vsetcolor : vsetcolor [name of shape] ColorName",
3617 __FILE__,VColor2,group);
3619 theCommands.Add("vunsetcolor",
3620 "vunsetcolor : vunsetcolor [name of shape] ",
3621 __FILE__,VColor2,group);
3623 theCommands.Add("vsettransparency",
3624 "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
3625 __FILE__,VTransparency,group);
3627 theCommands.Add("vunsettransparency",
3628 "vunsettransparency : vtransparency [name of shape]",
3629 __FILE__,VTransparency,group);
3631 theCommands.Add("vsetmaterial",
3632 "vmaterial : vmaterial [name of shape] MaterialName",
3633 __FILE__,VMaterial,group);
3635 theCommands.Add("vunsetmaterial",
3636 "vmaterial : vmaterial [name of shape]",
3637 __FILE__,VMaterial,group);
3639 theCommands.Add("vsetwidth",
3640 "vsetwidth : vwidth [name of shape] width(0->10)",
3641 __FILE__,VWidth,group);
3643 theCommands.Add("vunsetwidth",
3644 "vunsetwidth : vwidth [name of shape]",
3645 __FILE__,VWidth,group);
3647 theCommands.Add("vsetinteriorstyle",
3648 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3649 __FILE__,VInteriorStyle,group);
3651 theCommands.Add("vardis",
3652 "vardis : display activeareas",
3653 __FILE__,VDispAreas,group);
3655 theCommands.Add("varera",
3656 "varera : erase activeareas",
3657 __FILE__,VClearAreas,group);
3659 theCommands.Add("vsensdis",
3660 "vardisp : display active entities",
3661 __FILE__,VDispSensi,group);
3662 theCommands.Add("vsensera",
3663 "vardisp : erase active entities",
3664 __FILE__,VClearSensi,group);
3666 theCommands.Add("vselprecision",
3667 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3668 __FILE__,VSelPrecision,group);
3670 theCommands.Add("vperf",
3671 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3672 __FILE__,VPerf,group);
3674 theCommands.Add("vanimation",
3675 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3676 __FILE__,VAnimation,group);
3678 theCommands.Add("vsetshading",
3679 "vsetshading : vsetshading name Quality(default=0.0008) ",
3680 __FILE__,VShading,group);
3682 theCommands.Add("vunsetshading",
3683 "vunsetshading :vunsetshading name ",
3684 __FILE__,VShading,group);
3686 theCommands.Add("vtexture",
3687 "'vtexture NameOfShape TextureFile' \n \
3688 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3689 or 'vtexture NameOfShape ?' to list available textures\n \
3690 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3691 __FILE__,VTexture,group);
3693 theCommands.Add("vtexscale",
3694 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3695 or 'vtexscale NameOfShape ScaleUV' \n \
3696 or 'vtexscale NameOfShape' to disable scaling\n ",
3697 __FILE__,VTexture,group);
3699 theCommands.Add("vtexorigin",
3700 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3701 or 'vtexorigin NameOfShape UVOrigin' \n \
3702 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3703 __FILE__,VTexture,group);
3705 theCommands.Add("vtexrepeat",
3706 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3707 or 'vtexrepeat NameOfShape UVRepeat \n \
3708 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3711 theCommands.Add("vtexdefault",
3712 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3715 theCommands.Add("vsetam",
3716 "vsetActivatedModes: vsetam mode(1->7) ",
3717 __FILE__,VActivatedMode,group);
3719 theCommands.Add("vunsetam",
3720 "vunsetActivatedModes: vunsetam ",
3721 __FILE__,VActivatedMode,group);
3723 theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
3724 __FILE__,VState,group);
3726 theCommands.Add("vpickshapes",
3727 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3728 __FILE__,VPickShape,group);
3730 theCommands.Add("vtypes",
3731 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3734 theCommands.Add("vsettransmode",
3735 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3736 __FILE__,VSetTransMode,group);
3738 theCommands.Add("vr", "vr : reading of the shape",
3739 __FILE__,vr, group);
3741 theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
3742 theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
3746 //=====================================================================
3747 //========================= for testing Draft and Rib =================
3748 //=====================================================================
3749 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3750 #include <DBRep.hxx>
3751 #include <TopoDS_Face.hxx>
3752 #include <gp_Pln.hxx>
3753 #include <AIS_KindOfSurface.hxx>
3754 #include <BRepOffsetAPI_DraftAngle.hxx>
3755 #include <Precision.hxx>
3756 #include <BRepAlgo.hxx>
3757 #include <OSD_Environment.hxx>
3758 #include <DrawTrSurf.hxx>
3759 //#include <DbgTools.hxx>
3760 //#include <FeatAlgo_MakeLinearForm.hxx>
3765 //=======================================================================
3766 //function : IsValid
3768 //=======================================================================
3769 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3770 const TopoDS_Shape& theResult,
3771 const Standard_Boolean closedSolid,
3772 const Standard_Boolean GeomCtrl)
3774 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3775 TCollection_AsciiString checkValid = check.Value();
3776 Standard_Boolean ToCheck = Standard_True;
3777 if (!checkValid.IsEmpty()) {
3779 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3781 if ( checkValid=="true" || checkValid=="TRUE" ) {
3782 ToCheck= Standard_False;
3786 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3789 Standard_Boolean IsValid = Standard_True;
3791 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3796 //===============================================================================
3797 // TDraft : test draft, uses AIS Viewer
3798 // Solid Face Plane Angle Reverse
3799 //===============================================================================
3800 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3802 if (argc < 5) return 1;
3803 // argv[1] - TopoDS_Shape Solid
3804 // argv[2] - TopoDS_Shape Face
3805 // argv[3] - TopoDS_Shape Plane
3806 // argv[4] - Standard_Real Angle
3807 // argv[5] - Standard_Integer Reverse
3809 // sprintf(prefix, argv[1]);
3810 Standard_Real anAngle = 0;
3811 Standard_Boolean Rev = Standard_False;
3812 Standard_Integer rev = 0;
3813 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3814 TopoDS_Shape face = GetShapeFromName(argv[2]);
3815 TopoDS_Face Face = TopoDS::Face(face);
3816 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3817 if (Plane.IsNull ()) {
3818 di << "TEST : Plane is NULL" << "\n";
3821 anAngle = atof(argv[4]);
3822 anAngle = 2*M_PI * anAngle / 360.0;
3824 Handle( Geom_Surface )aSurf;
3825 AIS_KindOfSurface aSurfType;
3826 Standard_Real Offset;
3828 if(argc > 4) { // == 5
3829 rev = atoi(argv[5]);
3830 Rev = (rev)? Standard_True : Standard_False;
3833 TopoDS_Face face2 = TopoDS::Face(Plane);
3834 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3836 di << "TEST : Can't find plane" << "\n";
3840 aDir = aPln.Axis().Direction();
3843 if (Plane.Orientation() == TopAbs_REVERSED)
3845 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3847 BRepOffsetAPI_DraftAngle Draft (Solid);
3849 if(Abs(anAngle)< Precision::Angular()) {
3850 di << "TEST : NULL angle" << "\n";
3853 if(Rev) anAngle = - anAngle;
3854 Draft.Add (Face, aDir, anAngle, aPln);
3856 if (!Draft.IsDone()) {
3857 di << "TEST : Draft Not DONE " << "\n";
3860 TopTools_ListOfShape Larg;
3862 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3863 di << "TEST : DesignAlgo returns Not valid" << "\n";
3867 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3868 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3870 if ( !ais.IsNull() ) {
3871 ais->SetColor(DEFAULT_COLOR);
3872 ais->SetMaterial(DEFAULT_MATERIAL);
3873 // Display the AIS_Shape without redraw
3874 Ctx->Display(ais, Standard_False);
3876 const char *Name = "draft1";
3877 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3879 Handle(AIS_InteractiveObject) an_object =
3880 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3881 if (!an_object.IsNull()) {
3882 Ctx->Remove(an_object,
3884 GetMapOfAIS().UnBind2(Name) ;
3887 GetMapOfAIS().Bind(ais, Name);
3888 // DBRep::Set("draft", ais->Shape());
3890 Ctx->Display(ais, Standard_True);
3896 //============================================================================
3898 //============================================================================
3899 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3902 DrawTrSurf::BasicCommands(theCommands);
3903 const char* group = "Check Features Operations commands";
3905 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3907 &TDraft,group); //Draft_Modification
3910 //==============================================================================
3911 // ViewerTest::Factory
3912 //==============================================================================
3913 void ViewerTest::Factory(Draw_Interpretor& theDI)
3915 // definition of Viewer Command
3916 ViewerTest::Commands(theDI);
3917 ViewerTest::AviCommands(theDI);
3918 Viewer2dTest::Commands(theDI);
3920 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3924 // Declare entry point PLUGINFACTORY