1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
22 // Modified by Robert Coublanc [nov 16-17-18 1998]
23 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
24 // ViewerTest_ObjectCommands.cxx
25 // ViewerTest_RelationCommands.cxx
26 // -add Functions and commands for interactive selection of shapes and objects
27 // in AIS Viewers. (PickShape(s), PickObject(s),
29 #include <Standard_Stream.hxx>
31 #include <ViewerTest.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopTools_HArray1OfShape.hxx>
34 #include <TColStd_HArray1OfTransient.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_File.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Timer.hxx>
39 #include <Geom_Axis2Placement.hxx>
40 #include <Geom_Axis1Placement.hxx>
41 #include <gp_Trsf.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <StdSelect_ShapeTypeFilter.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_Trihedron.hxx>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Relation.hxx>
51 #include <AIS_TypeFilter.hxx>
52 #include <AIS_SignatureFilter.hxx>
53 #include <AIS_ListOfInteractive.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <Aspect_InteriorStyle.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_TextureRoot.hxx>
58 #include <Graphic3d_AspectLine3d.hxx>
59 #include <Graphic3d_ShaderObject.hxx>
60 #include <Graphic3d_ShaderProgram.hxx>
61 #include <Image_AlienPixMap.hxx>
62 #include <Prs3d_ShadingAspect.hxx>
63 #include <Prs3d_IsoAspect.hxx>
73 #include <Draw_Interpretor.hxx>
74 #include <TCollection_AsciiString.hxx>
75 #include <Draw_PluginMacro.hxx>
76 #include <ViewerTest.hxx>
78 // avoid warnings on 'extern "C"' functions returning C++ classes
80 #define _CRT_SECURE_NO_DEPRECATE
81 #pragma warning(4:4190)
82 #pragma warning (disable:4996)
85 #include <NIS_InteractiveContext.hxx>
86 #include <NIS_Triangulated.hxx>
87 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
89 #include <Quantity_Color.hxx>
90 #include <Quantity_NameOfColor.hxx>
92 #include <Graphic3d_NameOfMaterial.hxx>
94 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
95 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
98 //=======================================================================
99 //function : GetColorFromName
100 //purpose : get the Quantity_NameOfColor from a string
101 //=======================================================================
103 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
105 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
107 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
108 if (strcasecmp (theName, aColorName) == 0)
110 return Quantity_NameOfColor (anIter);
114 return DEFAULT_COLOR;
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>
242 //==============================================================================
243 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
244 //==============================================================================
245 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
246 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
251 //==============================================================================
252 //function : VDisplayAISObject
253 //purpose : register interactive object in the map of AIS objects;
254 // if other object with such name already registered, it will be kept
255 // or replaced depending on value of <theReplaceIfExists>,
256 // if "true" - the old object will be cleared from AIS context;
257 // returns Standard_True if <theAISObj> registered in map;
258 //==============================================================================
259 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
260 const Handle(AIS_InteractiveObject)& theAISObj,
261 Standard_Boolean theReplaceIfExists = Standard_True)
263 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
264 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
265 if (aContextAIS.IsNull())
267 std::cout << "AIS context is not available.\n";
268 return Standard_False;
271 if (aMap.IsBound2 (theName))
273 if (!theReplaceIfExists)
275 std::cout << "Other interactive object has been already "
276 << "registered with name: " << theName << ".\n"
277 << "Please use another name.\n";
278 return Standard_False;
281 // stop displaying object
282 Handle(AIS_InteractiveObject) anOldObj =
283 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
285 if (!anOldObj.IsNull())
286 aContextAIS->Clear (anOldObj, Standard_True);
288 // remove name and old object from map
289 aMap.UnBind2 (theName);
292 if (theAISObj.IsNull())
294 // object with specified name already unbound
295 return Standard_True;
298 // unbind AIS object if was bound with another name
299 aMap.UnBind1 (theAISObj);
301 // can be registered without rebinding
302 aMap.Bind (theAISObj, theName);
303 aContextAIS->Display (theAISObj, Standard_True);
304 return Standard_True;
307 static TColStd_MapOfInteger theactivatedmodes(8);
308 static TColStd_ListOfTransient theEventMgrs;
310 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
311 const Handle(AIS_InteractiveContext)& Ctx)
313 theEventMgrs.Clear();
314 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
317 static Handle(V3d_View)& a3DView()
319 static Handle(V3d_View) Viou;
324 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
325 static Handle(AIS_InteractiveContext) aContext;
329 const Handle(V3d_View)& ViewerTest::CurrentView()
333 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
338 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
340 static Handle(NIS_InteractiveContext) aContext;
341 if (aContext.IsNull()) {
342 aContext = new NIS_InteractiveContext;
343 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
348 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
350 return TheAISContext();
353 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
355 TheAISContext() = aCtx;
356 ViewerTest::ResetEventManager();
359 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
361 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
364 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
366 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
370 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
371 theEventMgrs.Prepend(EM);
374 void ViewerTest::UnsetEventManager()
376 theEventMgrs.RemoveFirst();
380 void ViewerTest::ResetEventManager()
382 const Handle(NIS_View) aView =
383 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
384 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
387 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
389 Handle(ViewerTest_EventManager) EM;
390 if(theEventMgrs.IsEmpty()) return EM;
391 Handle(Standard_Transient) Tr = theEventMgrs.First();
392 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
397 //=======================================================================
398 //function : Get Context and active viou..
400 //=======================================================================
401 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
402 Handle(V3d_View)& Viou)
404 Ctx = ViewerTest::GetAISContext();
407 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
408 Vwr->InitActiveViews();
409 if(Vwr->MoreActiveViews())
410 Viou = Vwr->ActiveView();
415 //==============================================================================
416 //function : GetShapeFromName
417 //purpose : Compute an Shape from a draw variable or a file name
418 //==============================================================================
420 static TopoDS_Shape GetShapeFromName(const char* name)
422 TopoDS_Shape S = DBRep::Get(name);
425 BRep_Builder aBuilder;
426 BRepTools::Read( S, name, aBuilder);
432 //==============================================================================
433 //function : GetAISShapeFromName
434 //purpose : Compute an AIS_Shape from a draw variable or a file name
435 //==============================================================================
436 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
438 Handle(AIS_Shape) retsh;
440 if(GetMapOfAIS().IsBound2(name)){
441 const Handle(AIS_InteractiveObject) IO =
442 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
444 if(IO->Type()==AIS_KOI_Shape) {
445 if(IO->Signature()==0){
446 retsh = *((Handle(AIS_Shape)*)&IO);
449 cout << "an Object which is not an AIS_Shape "
450 "already has this name!!!"<<endl;
457 TopoDS_Shape S = GetShapeFromName(name);
459 retsh = new AIS_Shape(S);
465 //==============================================================================
467 //purpose : Remove all the object from the viewer
468 //==============================================================================
469 void ViewerTest::Clear()
471 if ( !a3DView().IsNull() ) {
472 if (TheAISContext()->HasOpenedContext())
473 TheAISContext()->CloseLocalContext();
474 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
475 while ( it.More() ) {
476 cout << "Remove " << it.Key2() << endl;
477 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
478 const Handle(AIS_InteractiveObject) anObj =
479 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
480 TheAISContext()->Remove(anObj,Standard_False);
481 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
482 const Handle(NIS_InteractiveObject) anObj =
483 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
484 TheNISContext()->Remove(anObj);
488 TheAISContext()->UpdateCurrentViewer();
489 // TheNISContext()->UpdateViews();
490 GetMapOfAIS().Clear();
494 //==============================================================================
495 //function : StandardModesActivation
496 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
498 //==============================================================================
499 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
501 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
503 if (TheAISContext()->HasOpenedContext())
504 aContext->CloseLocalContext();
507 if(!aContext->HasOpenedContext()) {
508 // To unhilight the preselected object
509 aContext->UnhilightCurrents(Standard_False);
510 // Open a local Context in order to be able to select subshape from
511 // the selected shape if any or for all if there is no selection
512 if (!aContext->FirstCurrentObject().IsNull()){
513 aContext->OpenLocalContext(Standard_False);
515 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
516 aContext->Load( aContext->Current(),-1,Standard_True);
520 aContext->OpenLocalContext();
523 const char *cmode="???";
526 case 0: cmode = "Shape"; break;
527 case 1: cmode = "Vertex"; break;
528 case 2: cmode = "Edge"; break;
529 case 3: cmode = "Wire"; break;
530 case 4: cmode = "Face"; break;
531 case 5: cmode = "Shell"; break;
532 case 6: cmode = "Solid"; break;
533 case 7: cmode = "Compsolid"; break;
534 case 8: cmode = "Compound"; break;
537 if(theactivatedmodes.Contains(mode))
539 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
540 theactivatedmodes.Remove(mode);
541 cout<<"Mode "<< cmode <<" OFF"<<endl;
545 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
546 theactivatedmodes.Add(mode);
547 cout<<"Mode "<< cmode << " ON" << endl;
552 //==============================================================================
553 //function : CopyIsoAspect
554 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
555 //==============================================================================
556 static Handle(Prs3d_IsoAspect) CopyIsoAspect
557 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
558 const Standard_Integer theNbIsos)
560 Quantity_Color aColor;
561 Aspect_TypeOfLine aType;
562 Standard_Real aWidth;
564 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
566 Handle(Prs3d_IsoAspect) aResult =
567 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
572 //==============================================================================
574 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
575 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
576 //==============================================================================
577 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
579 if (TheAISContext().IsNull()) {
580 di << argv[0] << " Call 'vinit' before!\n";
585 di << "Current number of isos : " <<
586 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
587 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
588 di << "IsoOnPlane mode is " <<
589 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
594 Standard_Integer aLastInd = argc - 1;
595 Standard_Boolean isChanged = Standard_False;
596 Standard_Integer aNbUIsos = 0;
597 Standard_Integer aNbVIsos = 0;
600 Standard_Boolean isIsoOnPlane = Standard_False;
602 if (strcmp(argv[aLastInd], "1") == 0) {
603 isIsoOnPlane = Standard_True;
604 isChanged = Standard_True;
605 } else if (strcmp(argv[aLastInd], "0") == 0) {
606 isIsoOnPlane = Standard_False;
607 isChanged = Standard_True;
611 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
612 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
615 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
616 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
618 TheAISContext()->IsoOnPlane(isIsoOnPlane);
621 // If there are no shapes provided set the default numbers.
622 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
623 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
630 for (i = 1; i <= aLastInd; i++) {
631 TCollection_AsciiString name(argv[i]);
632 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
635 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
636 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
637 const Handle(AIS_InteractiveObject) aShape =
638 Handle(AIS_InteractiveObject)::DownCast (anObj);
639 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
640 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
641 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
644 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
645 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
646 TheAISContext()->SetLocalAttributes
647 (aShape, CurDrawer, Standard_False);
648 TheAISContext()->Redisplay(aShape);
650 di << "Number of isos for " << argv[i] << " : "
651 << aUIso->Number() << " " << aVIso->Number() << "\n";
654 di << argv[i] << ": Not an AIS interactive object!\n";
657 di << argv[i] << ": Use 'vdisplay' before\n";
662 TheAISContext()->UpdateCurrentViewer();
668 //==============================================================================
669 //function : VDispAreas,VDispSensitive,...
670 //purpose : Redraw the view
672 //==============================================================================
673 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
676 Handle(AIS_InteractiveContext) Ctx;
677 Handle(V3d_View) Viou;
678 GetCtxAndView(Ctx,Viou);
679 Ctx->DisplayActiveAreas(Viou);
682 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
684 Handle(AIS_InteractiveContext) Ctx;
685 Handle(V3d_View) Viou;
686 GetCtxAndView(Ctx,Viou);
687 Ctx->ClearActiveAreas(Viou);
691 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
693 Handle(AIS_InteractiveContext) Ctx;
694 Handle(V3d_View) Viou;
695 GetCtxAndView(Ctx,Viou);
696 Ctx->DisplayActiveSensitive(Viou);
700 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
702 Handle(AIS_InteractiveContext) Ctx;
703 Handle(V3d_View) Viou;
704 GetCtxAndView(Ctx,Viou);
705 Ctx->ClearActiveSensitive(Viou);
709 //==============================================================================
711 //purpose : To list the displayed object with their attributes
713 //==============================================================================
714 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
715 { if ( !a3DView().IsNull() ) {
716 di << "List of object in the viewer :" << "\n";
718 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
720 while ( it.More() ) {
721 di << "\t" << it.Key2().ToCString() << "\n";
729 //==============================================================================
730 //function : VSelPrecision
731 //purpose : To set the selection precision mode and tolerance value
732 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
733 // value (integer number of pixel for window mode, double value of
734 // sensitivity for view mode). Without arguments the function just
735 // prints the current precision mode and the corresponding tolerance.
736 //==============================================================================
737 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
741 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
745 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
746 if( aContext.IsNull() )
751 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
752 if( aMode == StdSelect_SM_WINDOW )
754 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
755 di << "Precision mode : 0 (window)\n";
756 di << "Pixel tolerance : " << aPixelTolerance << "\n";
758 else if( aMode == StdSelect_SM_VIEW )
760 Standard_Real aSensitivity = aContext->Sensitivity();
761 di << "Precision mode : 1 (view)\n";
762 di << "Sensitivity : " << aSensitivity << "\n";
767 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
768 aContext->SetSensitivityMode( aMode );
771 if( aMode == StdSelect_SM_WINDOW )
773 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
774 aContext->SetPixelTolerance( aPixelTolerance );
776 else if( aMode == StdSelect_SM_VIEW )
778 Standard_Real aSensitivity = Draw::Atof( argv[2] );
779 aContext->SetSensitivity( aSensitivity );
786 //==============================================================================
788 //purpose : To dump the active view snapshot to image file
789 //Draw arg : Picture file name with extension corresponding to desired format
790 //==============================================================================
791 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
795 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
799 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
802 const char* aBuffTypeStr = argv[2];
803 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
805 aBufferType = Graphic3d_BT_RGB;
807 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
809 aBufferType = Graphic3d_BT_RGBA;
811 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
813 aBufferType = Graphic3d_BT_Depth;
817 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
818 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
820 Handle(AIS_InteractiveContext) IC;
821 Handle(V3d_View) view;
822 GetCtxAndView (IC, view);
825 di << "Cannot find an active viewer/view\n";
829 if (aWidth <= 0 || aHeight <= 0)
831 if (!view->Dump (argv[1], aBufferType))
833 di << "Dumping failed!\n";
839 Image_AlienPixMap aPixMap;
840 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
842 di << "Dumping failed!\n";
846 if (aPixMap.SizeX() != Standard_Size(aWidth)
847 || aPixMap.SizeY() != Standard_Size(aHeight))
849 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
850 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
852 if (!aPixMap.Save (argv[1]))
854 di << "Saving image failed!\n";
861 //==============================================================================
862 //function : Displays,Erase...
865 //==============================================================================
866 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
867 const Standard_Integer Mode,
868 const Standard_Integer TypeOfOperation,
869 const Standard_Boolean Upd)
871 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
873 switch(TypeOfOperation){
875 Ctx->Display(IO,Mode,Upd);
883 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
885 Ctx->SetDisplayMode(IO,Mode,Upd);
890 Ctx->SetDisplayMode(0,Upd);
892 Ctx->UnsetDisplayMode(IO,Upd);
899 //=======================================================================
902 //=======================================================================
903 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
906 TCollection_AsciiString name;
909 // display others presentations
910 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
911 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
912 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
913 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
915 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
917 //unset displaymode.. comportement particulier...
918 if(TypeOfOperation==4){
920 if(Ctx->NbCurrents()==0 ||
921 Ctx->NbSelected()==0){
922 Handle(AIS_InteractiveObject) IO;
923 VwrTst_DispErase(IO,-1,4,Standard_False);
925 else if(!Ctx->HasOpenedContext()){
926 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
927 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
930 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
931 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
932 Ctx->UpdateCurrentViewer();
935 Handle(AIS_InteractiveObject) IO;
937 if(GetMapOfAIS().IsBound2(name)){
938 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
940 VwrTst_DispErase(IO,-1,4,Standard_True);
945 Standard_Integer Dmode = Draw::Atoi(argv[1]);
946 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
947 Handle(AIS_InteractiveObject) IO;
948 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
950 if(!Ctx->HasOpenedContext()){
951 // set/unset display mode sur le Contexte...
952 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
953 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
955 Ctx->UpdateCurrentViewer();
958 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
959 Ctx->Display(Ctx->Interactive(),Dmode);
963 Handle(AIS_InteractiveObject) IO;
965 if(GetMapOfAIS().IsBound2(name))
966 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
968 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
974 //=======================================================================
977 //=======================================================================
978 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
980 if(argc==1) return 1;
981 Standard_Integer On = Draw::Atoi(argv[1]);
982 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
986 if(!Ctx->HasOpenedContext()){
987 di<<"sub intensite ";
990 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
991 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
993 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
995 di <<"passage dans off"<<"\n";
996 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1001 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1003 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1005 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1008 Ctx->UpdateCurrentViewer();
1011 Handle(AIS_InteractiveObject) IO;
1012 TCollection_AsciiString name = argv[2];
1013 if(GetMapOfAIS().IsBound2(name)){
1014 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1017 Ctx->SubIntensityOn(IO);
1019 Ctx->SubIntensityOff(IO);
1027 //==============================================================================
1028 //function : VColor2
1030 //purpose : change the color of a selected or named or displayed shape
1031 //Draw arg : vcolor2 [name] color
1032 //==============================================================================
1033 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1036 Standard_Boolean ThereIsCurrent;
1037 Standard_Boolean ThereIsArgument;
1038 Standard_Boolean IsBound = Standard_False ;
1040 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1042 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1043 ThereIsArgument = (argc != 2);
1046 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1047 ThereIsArgument = (argc == 2);
1050 if ( !a3DView().IsNull() ) {
1051 TCollection_AsciiString name;
1052 if (ThereIsArgument) {
1054 IsBound= GetMapOfAIS().IsBound2(name);
1056 if (TheAISContext()->HasOpenedContext())
1057 TheAISContext()->CloseLocalContext();
1059 // On set le Booleen There is current
1060 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1061 else ThereIsCurrent =Standard_False;
1063 //=======================================================================
1064 // Il y a un argument
1065 //=======================================================================
1066 if ( ThereIsArgument && IsBound ) {
1067 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1068 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1069 Handle(AIS_InteractiveObject) ashape =
1070 Handle(AIS_InteractiveObject)::DownCast (anObj);
1073 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1075 di << "HaveToSet 0\n";
1079 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1081 TheAISContext()->UnsetColor(ashape);
1082 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1083 Handle(NIS_Triangulated) ashape =
1084 Handle(NIS_Triangulated)::DownCast (anObj);
1085 if (!ashape.IsNull())
1086 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1091 //=======================================================================
1092 // Il n'y a pas d'arguments
1093 // Mais un ou plusieurs objets on des current representation
1094 //=======================================================================
1095 if (ThereIsCurrent && !ThereIsArgument) {
1096 for (TheAISContext() -> InitCurrent() ;
1097 TheAISContext() -> MoreCurrent() ;
1098 TheAISContext() ->NextCurrent() )
1100 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1101 if (ashape.IsNull())
1105 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1107 di << "HaveToSet 0\n";
1110 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1112 TheAISContext()->UnsetColor(ashape,Standard_False);
1115 TheAISContext()->UpdateCurrentViewer();
1118 //=======================================================================
1119 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1120 // on impose a tous les objets du viewer la couleur passee
1121 //=======================================================================
1122 else if (!ThereIsCurrent && !ThereIsArgument){
1123 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1124 while ( it.More() ) {
1125 const Handle(AIS_InteractiveObject) ashape =
1126 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1127 if (!ashape.IsNull()) {
1129 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1131 TheAISContext()->UnsetColor(ashape,Standard_False);
1135 TheAISContext()->UpdateCurrentViewer();
1141 //==============================================================================
1142 //function : VTransparency
1144 //purpose : change the transparency of a selected or named or displayed shape
1145 //Draw arg : vtransparency [name] TransparencyCoeficient
1146 //==============================================================================
1148 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1151 Standard_Boolean ThereIsCurrent;
1152 Standard_Boolean ThereIsArgument;
1153 Standard_Boolean IsBound = Standard_False ;
1155 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1157 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1158 ThereIsArgument = (argc != 2);
1161 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1162 ThereIsArgument = (argc == 2);
1165 if ( !a3DView().IsNull() ) {
1166 TCollection_AsciiString name;
1167 if (ThereIsArgument) {
1169 IsBound= GetMapOfAIS().IsBound2(name);
1171 if (TheAISContext()->HasOpenedContext())
1172 TheAISContext()->CloseLocalContext();
1174 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1175 else ThereIsCurrent = Standard_False;
1177 //=======================================================================
1178 // Il y a des arguments: un nom et une couleur
1179 //=======================================================================
1180 if ( ThereIsArgument && IsBound ) {
1181 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1182 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1183 const Handle(AIS_InteractiveObject) ashape =
1184 Handle(AIS_InteractiveObject)::DownCast(anObj);
1186 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1188 TheAISContext()->UnsetTransparency(ashape);
1189 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1190 const Handle(NIS_InteractiveObject) ashape =
1191 Handle(NIS_InteractiveObject)::DownCast(anObj);
1193 ashape->SetTransparency(Draw::Atof(argv[2]) );
1195 ashape->UnsetTransparency();
1198 //=======================================================================
1199 // Il n'y a pas d'arguments
1200 // Mais un ou plusieurs objets on des current representation
1201 //=======================================================================
1202 if (ThereIsCurrent && !ThereIsArgument) {
1203 for (TheAISContext() -> InitCurrent() ;
1204 TheAISContext() -> MoreCurrent() ;
1205 TheAISContext() ->NextCurrent() )
1207 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1209 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1211 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1214 TheAISContext()->UpdateCurrentViewer();
1216 //=======================================================================
1217 // Il n'y a pas d'arguments ET aucun objet courrant
1218 //=======================================================================
1219 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1220 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1222 while ( it.More() ) {
1223 Handle(AIS_InteractiveObject) ashape =
1224 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1225 if (!ashape.IsNull()) {
1227 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1229 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1233 TheAISContext()->UpdateCurrentViewer();
1240 //==============================================================================
1241 //function : VMaterial
1243 //purpose : change the Material of a selected or named or displayed shape
1244 //Draw arg : vmaterial [Name] Material
1245 //==============================================================================
1246 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1249 Standard_Boolean ThereIsCurrent;
1250 Standard_Boolean ThereIsName;
1251 Standard_Boolean IsBound = Standard_False ;
1253 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1255 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1256 ThereIsName = (argc != 2);
1259 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1260 ThereIsName = (argc == 2);
1263 if ( !a3DView().IsNull() ) {
1264 TCollection_AsciiString name;
1267 IsBound= GetMapOfAIS().IsBound2(name);
1269 if (TheAISContext()->HasOpenedContext())
1270 TheAISContext()->CloseLocalContext();
1271 if (TheAISContext() -> NbCurrents() > 0 )
1272 ThereIsCurrent =Standard_True;
1274 ThereIsCurrent =Standard_False;
1276 //=======================================================================
1277 // Ther is a name of shape and a material name
1278 //=======================================================================
1279 if ( ThereIsName && IsBound ) {
1280 Handle(AIS_InteractiveObject) ashape =
1281 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1282 if (!ashape.IsNull()) {
1284 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1286 TheAISContext()->UnsetMaterial(ashape);
1289 //=======================================================================
1290 // Il n'y a pas de nom de shape
1291 // Mais un ou plusieurs objets on des current representation
1292 //=======================================================================
1293 if (ThereIsCurrent && !ThereIsName) {
1294 for (TheAISContext() -> InitCurrent() ;
1295 TheAISContext() -> MoreCurrent() ;
1296 TheAISContext() ->NextCurrent() )
1298 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1300 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1302 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1304 TheAISContext()->UpdateCurrentViewer();
1307 //=======================================================================
1308 // Il n'y a pas de noms de shape ET aucun objet courrant
1309 // On impose a tous les objets du viewer le material passe en argument
1310 //=======================================================================
1311 else if (!ThereIsCurrent && !ThereIsName){
1312 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1314 while ( it.More() ) {
1315 Handle(AIS_InteractiveObject) ashape =
1316 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1317 if (!ashape.IsNull()) {
1319 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1321 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1325 TheAISContext()->UpdateCurrentViewer();
1333 //==============================================================================
1336 //purpose : change the width of the edges of a selected or named or displayed shape
1337 //Draw arg : vwidth [Name] WidthValue(1->10)
1338 //==============================================================================
1339 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1342 Standard_Boolean ThereIsCurrent;
1343 Standard_Boolean ThereIsArgument;
1344 Standard_Boolean IsBound = Standard_False ;
1346 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1348 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1349 ThereIsArgument = (argc != 2);
1352 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1353 ThereIsArgument = (argc == 2);
1355 if ( !a3DView().IsNull() ) {
1356 TCollection_AsciiString name;
1357 if (ThereIsArgument) {
1359 IsBound= GetMapOfAIS().IsBound2(name);
1361 if (TheAISContext()->HasOpenedContext())
1362 TheAISContext()->CloseLocalContext();
1364 if (TheAISContext() -> NbCurrents() > 0 )
1365 ThereIsCurrent =Standard_True;
1367 ThereIsCurrent =Standard_False;
1369 if ( ThereIsArgument && IsBound ) {
1370 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1371 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1372 const Handle(AIS_InteractiveObject) ashape =
1373 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1375 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1377 TheAISContext()->UnsetWidth (ashape);
1378 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1379 const Handle(NIS_Triangulated) ashape =
1380 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1381 if (HaveToSet && !ashape.IsNull())
1382 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1386 //=======================================================================
1387 // Il n'y a pas d'arguments
1388 // Mais un ou plusieurs objets on des current representation
1389 //=======================================================================
1390 if (ThereIsCurrent && !ThereIsArgument) {
1391 for (TheAISContext() -> InitCurrent() ;
1392 TheAISContext() -> MoreCurrent() ;
1393 TheAISContext() ->NextCurrent() )
1395 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1397 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1399 TheAISContext()->UnsetWidth(ashape,Standard_False);
1401 TheAISContext()->UpdateCurrentViewer();
1403 //=======================================================================
1404 // Il n'y a pas d'arguments ET aucun objet courrant
1405 //=======================================================================
1406 else if (!ThereIsCurrent && !ThereIsArgument){
1407 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1409 while ( it.More() ) {
1410 Handle(AIS_InteractiveObject) ashape =
1411 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1412 if (!ashape.IsNull()) {
1414 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1416 TheAISContext()->UnsetWidth(ashape,Standard_False);
1420 TheAISContext()->UpdateCurrentViewer();
1426 //==============================================================================
1427 //function : VInteriorStyle
1428 //purpose : sets interior style of the a selected or named or displayed shape
1429 //Draw arg : vsetinteriorstyle [shape] style
1430 //==============================================================================
1431 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1432 const Standard_Integer theStyle,
1433 Draw_Interpretor& di)
1435 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1436 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1437 " (Aspect_IS_HIDDENLINE)]\n";
1440 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1441 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1442 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1443 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1444 aFillAspect->SetInteriorStyle (aStyle);
1445 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1448 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1450 if (argc < 2 || argc > 3) {
1451 di << argv[0] << " requires 2 or 3 arguments\n";
1452 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1453 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1454 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1458 Standard_Boolean ThereIsCurrent;
1459 Standard_Boolean ThereIsArgument;
1460 Standard_Boolean IsBound = Standard_False ;
1462 ThereIsArgument = (argc > 2);
1463 if ( !a3DView().IsNull() ) {
1464 TCollection_AsciiString name;
1465 if (ThereIsArgument) {
1467 IsBound= GetMapOfAIS().IsBound2(name);
1469 if (TheAISContext()->HasOpenedContext())
1470 TheAISContext()->CloseLocalContext();
1472 if (TheAISContext() -> NbCurrents() > 0 )
1473 ThereIsCurrent =Standard_True;
1475 ThereIsCurrent =Standard_False;
1477 if ( ThereIsArgument && IsBound ) {
1478 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1479 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1480 const Handle(AIS_InteractiveObject) ashape =
1481 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1482 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1485 //=======================================================================
1486 // No arguments specified
1487 // But there are one or more selected objects
1488 //=======================================================================
1489 if (ThereIsCurrent && !ThereIsArgument) {
1490 for (TheAISContext() -> InitCurrent() ;
1491 TheAISContext() -> MoreCurrent() ;
1492 TheAISContext() ->NextCurrent() )
1494 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1495 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1498 //=======================================================================
1499 // No arguments specified and there are no selected objects
1500 //=======================================================================
1501 else if (!ThereIsCurrent && !ThereIsArgument){
1502 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1504 while ( it.More() ) {
1505 Handle(AIS_InteractiveObject) ashape =
1506 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1507 if (!ashape.IsNull())
1508 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1512 TheAISContext()->UpdateCurrentViewer();
1517 //==============================================================================
1518 //function : VDonly2
1520 //purpose : Display only a selected or named object
1521 // if there is no selected or named object s, nothing is donne
1522 //Draw arg : vdonly2 [name1] ... [name n]
1523 //==============================================================================
1524 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1527 if ( a3DView().IsNull() )
1530 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1531 Standard_Boolean ThereIsArgument= argc>1;
1533 if (TheAISContext()->HasOpenedContext())
1534 TheAISContext()->CloseLocalContext();
1536 //===============================================================
1537 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1539 //===============================================================
1540 if (!ThereIsArgument && ThereIsCurrent) {
1543 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1546 for(TheAISContext()->InitCurrent();
1547 TheAISContext()->MoreCurrent();
1548 TheAISContext()->NextCurrent()){
1549 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1550 TheAISContext()->Erase(aShape,Standard_False);}
1552 TheAISContext() ->UpdateCurrentViewer();
1553 //===============================================================
1554 // Il y a des arguments
1555 //===============================================================
1556 if (ThereIsArgument) {
1557 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1559 while ( it.More() ) {
1560 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1561 const Handle(AIS_InteractiveObject) aShape =
1562 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1563 TheAISContext()->Erase(aShape,Standard_False);
1564 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1565 const Handle(NIS_InteractiveObject) aShape =
1566 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1567 TheNISContext()->Erase(aShape);
1572 // On display les objets passes par parametre
1573 for (int i=1; i<argc ; i++) {
1574 TCollection_AsciiString name=argv[i];
1575 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1577 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1578 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1579 const Handle(AIS_InteractiveObject) aShape =
1580 Handle(AIS_InteractiveObject)::DownCast (anObj);
1581 TheAISContext()->Display(aShape, Standard_False);
1582 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1583 Handle(NIS_InteractiveObject) aShape =
1584 Handle(NIS_InteractiveObject)::DownCast (anObj);
1585 TheNISContext()->Display(aShape);
1589 TheAISContext() ->UpdateCurrentViewer();
1590 // TheNISContext() ->UpdateViews();
1595 //==============================================================================
1597 //purpose : Erase some selected or named objects
1598 // if there is no selected or named objects, the whole viewer is erased
1599 //==============================================================================
1600 int VErase (Draw_Interpretor& theDI,
1601 Standard_Integer theArgNb,
1602 const char** theArgVec)
1604 if (a3DView().IsNull())
1609 TheAISContext()->CloseAllContexts (Standard_False);
1610 const Standard_Boolean isEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "").IsEqual ("veraseall");
1615 std::cerr << " Syntax error: " << theArgVec[0] << " too much arguments.\n";
1619 // has a list of names
1620 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1622 TCollection_AsciiString aName = theArgVec[anArgIter];
1623 if (!GetMapOfAIS().IsBound2 (aName))
1628 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1629 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1630 theDI << aName.ToCString() << " ";
1633 TheAISContext()->Erase (anIO, Standard_False);
1637 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1638 if (!aNisIO.IsNull())
1640 TheNISContext()->Erase (aNisIO);
1644 TheAISContext()->UpdateCurrentViewer();
1649 && TheAISContext()->NbCurrents() > 0)
1651 // remove all currently selected objects
1652 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1653 anIter.More(); anIter.Next())
1655 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1657 && TheAISContext()->IsCurrent (anIO))
1659 theDI << anIter.Key2().ToCString() << " ";
1660 TheAISContext()->Erase (anIO, Standard_False);
1664 TheAISContext()->UpdateCurrentViewer();
1668 // erase entire viewer
1669 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1670 anIter.More(); anIter.Next())
1672 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1675 TheAISContext()->Erase (anIO, Standard_False);
1679 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1680 if (!aNisIO.IsNull())
1682 TheNISContext()->Erase (aNisIO);
1686 TheAISContext()->UpdateCurrentViewer();
1690 //==============================================================================
1691 //function : VDisplayAll
1693 //purpose : Display all the objects of the Map
1694 //Draw arg : vdisplayall
1695 //==============================================================================
1696 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1699 if (! a3DView().IsNull() ) {
1700 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1701 if (TheAISContext()->HasOpenedContext())
1702 TheAISContext()->CloseLocalContext();
1703 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1705 while ( it.More() ) {
1706 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1707 const Handle(AIS_InteractiveObject) aShape =
1708 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1709 TheAISContext()->Erase(aShape,Standard_False);
1710 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1711 const Handle(NIS_InteractiveObject) aShape =
1712 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1713 TheNISContext()->Erase(aShape);
1718 while ( it.More() ) {
1719 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1720 const Handle(AIS_InteractiveObject) aShape =
1721 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1722 TheAISContext()->Display(aShape, Standard_False);
1723 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1724 Handle(NIS_InteractiveObject) aShape =
1725 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1726 TheNISContext()->Display(aShape);
1730 TheAISContext() ->UpdateCurrentViewer();
1731 // TheNISContext() ->UpdateViews();
1736 //#######################################################################################################
1740 //#######################################################################################################
1742 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1744 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1745 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1746 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1747 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1748 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1750 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1751 if(myAISContext.IsNull())
1753 di << "use 'vinit' command before " << argv[0] << "\n";
1757 Handle(AIS_InteractiveObject) TheAisIO;
1758 Handle(AIS_TexturedShape) myShape;
1759 Standard_Integer myPreviousMode = 0;
1761 if (argc<2 || !argv[1])
1763 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1767 TCollection_AsciiString name = argv[1];
1768 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1770 if (GetMapOfAIS().IsBound2(name))
1771 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1772 (GetMapOfAIS().Find2(name));
1773 if (TheAisIO.IsNull())
1775 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1779 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1781 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1782 myPreviousMode = myShape->DisplayMode() ;
1786 myAISContext->Clear(TheAisIO,Standard_False);
1787 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1788 GetMapOfAIS().UnBind1(TheAisIO);
1789 GetMapOfAIS().UnBind2(name);
1790 GetMapOfAIS().Bind(myShape, name);
1794 case 1: // vtexture : we only map a texture on the shape
1797 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1800 if (argc>2 && argv[2])
1802 if(strcasecmp(argv[2],"?")==0)
1804 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1805 di<<"\n Files in current directory : \n"<<"\n";
1806 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1807 di.Eval(Cmnd.ToCString());
1809 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1812 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1813 di.Eval(Cmnd.ToCString());
1818 myShape->SetTextureFileName(argv[2]);
1822 di <<"Texture mapping disabled \n \
1823 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1825 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1826 if (myPreviousMode == 3 )
1827 myAISContext->RecomputePrsOnly(myShape);
1828 myAISContext->Display(myShape, Standard_True);
1833 case 2: // vtexscale : we change the scaling factor of the texture
1837 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1841 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1842 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1843 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1846 case 3: // vtexorigin : we change the origin of the texture on the shape
1849 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1852 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1853 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1854 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
1857 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1860 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1863 if (argc>2 && argv[2])
1865 di <<"Texture repeat enabled"<<"\n";
1866 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
1870 di <<"Texture repeat disabled"<<"\n";
1871 myShape->SetTextureRepeat(Standard_False);
1875 case 5: // vtexdefault : default texture mapping
1876 // ScaleU = ScaleV = 100.0
1877 // URepeat = VRepeat = 1.0
1878 // Uorigin = VOrigin = 0.0
1882 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1885 myShape->SetTextureRepeat(Standard_False);
1886 myShape->SetTextureOrigin(Standard_False);
1887 myShape->SetTextureScale (Standard_False);
1891 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1892 myAISContext->RecomputePrsOnly(myShape);
1895 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1896 myAISContext->Display(myShape, Standard_True);
1897 myAISContext->Update(myShape,Standard_True);
1902 //==============================================================================
1903 //function : VShaderProg
1904 //purpose : Sets the pair of vertex and fragment shaders for the object
1905 //==============================================================================
1906 static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/,
1907 Standard_Integer theArgNb,
1908 const char** theArgVec)
1910 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
1911 if (anAISContext.IsNull())
1913 std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
1919 std::cerr << theArgVec[0] <<" syntax error: lack of arguments - Type 'help vshaderprog\n";
1923 const TCollection_AsciiString aShapeName = theArgVec[1];
1924 if (!GetMapOfAIS().IsBound2 (aShapeName))
1926 std::cerr << theArgVec[0] << ": Use 'vdisplay' before\n";
1930 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aShapeName));
1933 std::cerr << "Shape " << aShapeName.ToCString() << " does not exist\n";
1937 Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
1938 const TCollection_AsciiString aVertexSource (theArgVec[2]);
1939 if (!aVertexSource.IsEmpty() && !OSD_File(aVertexSource).Exists())
1941 std::cerr << "Non-existing vertex shader source\n";
1945 TCollection_AsciiString aFragmentSource (theArgVec[3]);
1946 if (!aFragmentSource.IsEmpty() && !OSD_File(aFragmentSource).Exists())
1948 std::cerr << "Non-existing fragment shader source\n";
1952 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aVertexSource));
1953 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aFragmentSource));
1954 anIO->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);
1956 anAISContext->Redisplay (anIO);
1960 //==============================================================================
1961 //function : VDisplay2
1963 //purpose : Display an object from its name
1964 //Draw arg : vdisplay name1 [name2] ... [name n]
1965 //==============================================================================
1966 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1969 // Verification des arguments
1970 if ( a3DView().IsNull() ) {
1972 ViewerTest::ViewerInit();
1973 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1978 di<<argv[0]<<" Syntaxe error"<<"\n";
1983 TCollection_AsciiString name;
1984 if (TheAISContext()->HasOpenedContext())
1985 TheAISContext()->CloseLocalContext();
1987 for ( int i = 1; i < argc; i++ ) {
1989 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1990 Standard_Boolean IsDatum = Standard_False;
1991 Handle(Standard_Transient) anObj;
1993 anObj = GetMapOfAIS().Find2(name);
1994 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1995 Handle(AIS_InteractiveObject) aShape =
1996 Handle(AIS_InteractiveObject)::DownCast(anObj);
1997 if (aShape->Type()==AIS_KOI_Datum) {
1998 IsDatum = Standard_True;
1999 TheAISContext()->Display(aShape, Standard_False);
2002 di << "Display " << name.ToCString() << "\n";
2003 // Get the Shape from a name
2004 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2006 // Update the Shape in the AIS_Shape
2007 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2008 if(!TheRealSh.IsNull())
2009 TheRealSh->Set(NewShape);
2010 TheAISContext()->Redisplay(aShape, Standard_False);
2011 TheAISContext()->Display(aShape, Standard_False);
2014 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2015 Handle(NIS_InteractiveObject) aShape =
2016 Handle(NIS_InteractiveObject)::DownCast(anObj);
2017 TheNISContext()->Display(aShape);
2020 else { // Create the AIS_Shape from a name
2021 const Handle(AIS_InteractiveObject) aShape =
2022 GetAISShapeFromName((const char *)name.ToCString());
2023 if ( !aShape.IsNull() ) {
2024 GetMapOfAIS().Bind(aShape, name);
2025 TheAISContext()->Display(aShape, Standard_False);
2029 // Upadate the screen and redraw the view
2030 TheAISContext()->UpdateCurrentViewer();
2031 // TheNISContext()->UpdateViews();
2035 //==============================================================================
2037 //purpose : Test the annimation of an object along a
2038 // predifined trajectory
2039 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2040 //==============================================================================
2042 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2045 if (TheAISContext()->HasOpenedContext())
2046 TheAISContext()->CloseLocalContext();
2048 Standard_Real Step=4*M_PI/180;
2049 Standard_Real Angle=0;
2051 Handle(AIS_InteractiveObject) aIO;
2052 if (GetMapOfAIS().IsBound2(argv[1]))
2053 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2057 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2061 if (Draw::Atoi(argv[3])==1 ) {
2062 di<<" Primitives sensibles OFF"<<"\n";
2063 TheAISContext()->Deactivate(aIO);
2066 di<<" Primitives sensibles ON"<<"\n";
2068 // Movement par transformation
2069 if(Draw::Atoi(argv[2]) ==1) {
2070 di<<" Calcul par Transformation"<<"\n";
2071 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2075 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2076 TheAISContext()->SetLocation(aShape,myTransfo);
2077 TheAISContext() ->UpdateCurrentViewer();
2082 di<<" Calcul par Locations"<<"\n";
2083 gp_Trsf myAngleTrsf;
2084 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2085 TopLoc_Location myDeltaAngle (myAngleTrsf);
2086 TopLoc_Location myTrueLoc;
2088 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2091 myTrueLoc=myTrueLoc*myDeltaAngle;
2092 TheAISContext()->SetLocation(aShape,myTrueLoc );
2093 TheAISContext() ->UpdateCurrentViewer();
2096 if (Draw::Atoi(argv[3])==1 ){
2097 // On reactive la selection des primitives sensibles
2098 TheAISContext()->Activate(aIO,0);
2100 a3DView() -> Redraw();
2102 di<<" Temps ecoule "<<"\n";
2108 //==================================================================================
2109 // Function : VAnimation
2110 //==================================================================================
2111 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2113 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2117 Standard_Real thread = 4;
2118 Standard_Real angleA=0;
2119 Standard_Real angleB;
2121 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2124 TopoDS_Shape CrankArm;
2125 TopoDS_Shape CylinderHead;
2126 TopoDS_Shape Propeller;
2127 TopoDS_Shape EngineBlock;
2129 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2130 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2131 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2132 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2133 BRepTools::Read(CrankArm,argv[1],B);
2134 BRepTools::Read(CylinderHead,argv[2],B);
2135 BRepTools::Read(Propeller,argv[3],B);
2136 BRepTools::Read(EngineBlock,argv[4],B);
2138 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2144 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2145 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2146 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2147 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2149 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2150 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2151 GetMapOfAIS().Bind(myAisCrankArm,"c");
2152 GetMapOfAIS().Bind(myAisPropeller,"d");
2154 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2155 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2156 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2158 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2159 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2160 TheAISContext()->Display(myAisCrankArm,Standard_False );
2161 TheAISContext()->Display(myAisPropeller,Standard_False);
2163 TheAISContext()->Deactivate(myAisCylinderHead);
2164 TheAISContext()->Deactivate(myAisEngineBlock );
2165 TheAISContext()->Deactivate(myAisCrankArm );
2166 TheAISContext()->Deactivate(myAisPropeller );
2168 // Boucle de mouvement
2169 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2171 angleA = thread*myAngle*M_PI/180;
2172 X = Sin(angleA)*3/8;
2173 angleB = atan(X / Sqrt(-X * X + 1));
2174 Standard_Real decal(25*0.6);
2177 //Build a transformation on the display
2178 gp_Trsf aPropellerTrsf;
2179 aPropellerTrsf.SetRotation(Ax1,angleA);
2180 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2182 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));
2183 gp_Trsf aCrankArmTrsf;
2184 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2185 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2187 TheAISContext()->UpdateCurrentViewer();
2190 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2191 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2193 myAisCrankArm ->ResetLocation();
2194 myAisPropeller->ResetLocation();
2196 myAisCrankArm -> Set(myNewCrankArm );
2197 myAisPropeller -> Set(myNewPropeller);
2199 TheAISContext()->Activate(myAisCylinderHead,0);
2200 TheAISContext()->Activate(myAisEngineBlock,0 );
2201 TheAISContext()->Activate(myAisCrankArm ,0 );
2202 TheAISContext()->Activate(myAisPropeller ,0 );
2208 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2209 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2211 TheAISContext()->UpdateCurrentViewer();
2212 a3DView()->Redraw();
2221 //==============================================================================
2222 //function : VShading
2223 //purpose : Sharpen or roughten the quality of the shading
2224 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2225 //==============================================================================
2226 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2228 Standard_Real myDevCoef;
2229 Handle(AIS_InteractiveObject) TheAisIO;
2232 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2234 if (TheAISContext()->HasOpenedContext())
2235 TheAISContext()->CloseLocalContext();
2240 myDevCoef =Draw::Atof(argv[2]);
2243 TCollection_AsciiString name=argv[1];
2244 if (GetMapOfAIS().IsBound2(name ))
2245 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2246 if (TheAisIO.IsNull())
2247 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2250 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2252 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2254 TheAISContext()->Redisplay(TheAisIO);
2257 //==============================================================================
2258 //function : HaveMode
2259 //use : VActivatedModes
2260 //==============================================================================
2261 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2263 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2265 TColStd_ListOfInteger List;
2266 TheAISContext()->ActivatedModes (TheAisIO,List);
2267 TColStd_ListIteratorOfListOfInteger it;
2268 Standard_Boolean Found=Standard_False;
2269 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2270 if (it.Value()==mode ) Found=Standard_True;
2277 //==============================================================================
2278 //function : VActivatedMode
2280 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2281 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2282 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2283 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2284 // qu'un nom et qu'un mode.
2285 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2286 //==============================================================================
2287 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2289 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2292 Standard_Boolean ThereIsName = Standard_False ;
2294 if(!a3DView().IsNull()){
2296 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2297 // verification des arguments
2299 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2300 ThereIsName = (argc == 3);
2304 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2306 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2307 di<<" Fermeture du Context local"<<"\n";
2308 if (TheAISContext()->HasOpenedContext())
2309 TheAISContext()->CloseLocalContext();
2313 // IL n'y a aps de nom de shape passe en argument
2314 if (HaveToSet && !ThereIsName){
2315 Standard_Integer aMode=Draw::Atoi(argv [1]);
2317 const char *cmode="???";
2319 case 0: cmode = "Shape"; break;
2320 case 1: cmode = "Vertex"; break;
2321 case 2: cmode = "Edge"; break;
2322 case 3: cmode = "Wire"; break;
2323 case 4: cmode = "Face"; break;
2324 case 5: cmode = "Shell"; break;
2325 case 6: cmode = "Solid"; break;
2326 case 7: cmode = "Compound"; break;
2329 if( !TheAISContext()->HasOpenedContext() ) {
2330 // il n'y a pas de Context local d'ouvert
2331 // on en ouvre un et on charge toutes les shapes displayees
2332 // on load tous les objets displayees et on Activate les objets de la liste
2333 AIS_ListOfInteractive ListOfIO;
2334 // on sauve dans une AISListOfInteractive tous les objets currents
2335 if (TheAISContext()->NbCurrents()>0 ){
2336 TheAISContext()->UnhilightCurrents(Standard_False);
2338 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2339 ListOfIO.Append(TheAISContext()->Current() );
2343 TheAISContext()->OpenLocalContext(Standard_False);
2344 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2347 Handle(AIS_InteractiveObject) aIO =
2348 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2350 TheAISContext()->Load(aIO,0,Standard_False);
2353 // traitement des objets qui etaient currents dans le Contexte global
2354 if (!ListOfIO.IsEmpty() ) {
2355 // il y avait des objets currents
2356 AIS_ListIteratorOfListOfInteractive iter;
2357 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2358 Handle(AIS_InteractiveObject) aIO=iter.Value();
2359 TheAISContext()->Activate(aIO,aMode);
2360 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2364 // On applique le mode a tous les objets displayes
2365 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2366 it2 (GetMapOfAIS());
2368 Handle(AIS_InteractiveObject) aIO =
2369 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2370 if (!aIO.IsNull()) {
2371 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2372 TheAISContext()->Activate(aIO,aMode);
2381 // un Context local est deja ouvert
2382 // Traitement des objets du Context local
2383 if (TheAISContext()->NbSelected()>0 ){
2384 TheAISContext()->UnhilightSelected(Standard_False);
2385 // il y a des objets selected,on les parcourt
2386 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2387 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2390 if (HaveMode(aIO,aMode) ) {
2391 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2392 TheAISContext()->Deactivate(aIO,aMode);
2395 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2396 TheAISContext()->Activate(aIO,aMode);
2402 // il n'y a pas d'objets selected
2403 // tous les objets diplayes sont traites
2404 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2407 Handle(AIS_InteractiveObject) aIO =
2408 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2409 if (!aIO.IsNull()) {
2410 if (HaveMode(aIO,aMode) ) {
2411 di<<" Mode: "<<cmode<<" OFF pour "
2412 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2413 TheAISContext()->Deactivate(aIO,aMode);
2416 di<<" Mode: "<<cmode<<" ON pour"
2417 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2418 TheAISContext()->Activate(aIO,aMode);
2426 else if (HaveToSet && ThereIsName){
2427 Standard_Integer aMode=Draw::Atoi(argv [2]);
2428 Handle(AIS_InteractiveObject) aIO =
2429 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2431 if (!aIO.IsNull()) {
2432 const char *cmode="???";
2435 case 0: cmode = "Shape"; break;
2436 case 1: cmode = "Vertex"; break;
2437 case 2: cmode = "Edge"; break;
2438 case 3: cmode = "Wire"; break;
2439 case 4: cmode = "Face"; break;
2440 case 5: cmode = "Shell"; break;
2441 case 6: cmode = "Solid"; break;
2442 case 7: cmode = "Compound"; break;
2445 if( !TheAISContext()->HasOpenedContext() ) {
2446 TheAISContext()->OpenLocalContext(Standard_False);
2447 // On charge tous les objets de la map
2448 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2450 Handle(AIS_InteractiveObject) aShape=
2451 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2452 if (!aShape.IsNull())
2453 TheAISContext()->Load(aShape,0,Standard_False);
2456 TheAISContext()->Activate(aIO,aMode);
2457 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2461 // un Context local est deja ouvert
2462 if (HaveMode(aIO,aMode) ) {
2463 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2464 TheAISContext()->Deactivate(aIO,aMode);
2467 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2468 TheAISContext()->Activate(aIO,aMode);
2480 //==============================================================================
2481 // function : WhoAmI
2483 //==============================================================================
2484 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2487 if (theShape->Type()==AIS_KOI_Datum) {
2488 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2489 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2490 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2491 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2492 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2493 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2494 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2497 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2498 // AIS_Dimentions et AIS_Relations
2499 else if (theShape->Type()==AIS_KOI_Relation) {
2500 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2502 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2503 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2504 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2505 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2506 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2507 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2508 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2509 // AIS no repertorie.
2510 else {di<<" Type Unknown.";}
2516 //==============================================================================
2519 //Draw arg : vstate [nameA] ... [nameN]
2520 //==============================================================================
2521 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2523 TheAISContext()->CloseAllContexts();
2524 const Standard_Boolean ThereIsArguments=(argc>=2);
2525 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2527 // ==================
2528 // Il y a un argument
2529 // ==================
2530 if (ThereIsArguments) {
2531 for (int cpt=1;cpt<argc;cpt++) {
2532 // Verification que lq piece est bien bindee.
2533 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2534 const Handle(AIS_InteractiveObject) theShape=
2535 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2537 if (!theShape.IsNull()) {
2538 di<<argv[cpt];WhoAmI(theShape, di);
2539 if (TheAISContext()->IsDisplayed(theShape) ) {
2540 di<<" Displayed"<<"\n";
2543 di<<" Not Displayed"<<"\n";
2548 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2552 else if (ThereIsCurrent ) {
2553 for (TheAISContext() -> InitCurrent() ;
2554 TheAISContext() -> MoreCurrent() ;
2555 TheAISContext() ->NextCurrent() )
2557 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2558 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2559 if (TheAISContext()->IsDisplayed(theShape) ) {
2560 di<<" Displayed"<<"\n";
2563 di<<" Not Displayed"<<"\n";
2569 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2571 while ( it.More() ) {
2572 Handle(AIS_InteractiveObject) theShape =
2573 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2574 if (!theShape.IsNull()) {
2575 di<<it.Key2().ToCString();
2576 WhoAmI(theShape, di);
2577 if (TheAISContext()->IsDisplayed(theShape) ) {
2578 di<<" Displayed"<<"\n";
2581 di<<" Not Displayed"<<"\n";
2592 //=======================================================================
2593 //function : PickObjects
2595 //=======================================================================
2596 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2597 const AIS_KindOfInteractive TheType,
2598 const Standard_Integer TheSignature,
2599 const Standard_Integer MaxPick)
2601 Handle(AIS_InteractiveObject) IO;
2602 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2604 // step 1: prepare the data
2606 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2607 TheAISContext()->AddFilter(F1);
2610 // step 2 : wait for the selection...
2611 // Standard_Boolean IsGood (Standard_False);
2612 // Standard_Integer NbPick(0);
2613 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2614 Standard_Integer NbPickFail(0);
2615 Standard_Integer argccc = 5;
2616 const char *bufff[] = { "A", "B", "C","D", "E" };
2617 const char **argvvv = (const char **) bufff;
2620 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2621 while(ViewerMainLoop(argccc,argvvv)){}
2622 Standard_Integer NbStored = TheAISContext()->NbSelected();
2623 if((unsigned int ) NbStored != NbPickGood)
2624 NbPickGood= NbStored;
2627 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2630 // step3 get result.
2632 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2634 Standard_Integer i(0);
2635 for(TheAISContext()->InitSelected();
2636 TheAISContext()->MoreSelected();
2637 TheAISContext()->NextSelected()){
2639 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2640 arr->SetValue(i,IO2);
2645 TheAISContext()->CloseLocalContext(curindex);
2647 return Standard_True;
2651 //=======================================================================
2652 //function : PickObject
2654 //=======================================================================
2655 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2656 const Standard_Integer TheSignature,
2657 const Standard_Integer MaxPick)
2659 Handle(AIS_InteractiveObject) IO;
2660 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2662 // step 1: prepare the data
2665 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2666 TheAISContext()->AddFilter(F1);
2669 // step 2 : wait for the selection...
2670 Standard_Boolean IsGood (Standard_False);
2671 Standard_Integer NbPick(0);
2672 Standard_Integer argccc = 5;
2673 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2674 const char **argvvv = (const char **) bufff;
2677 while(!IsGood && NbPick<= MaxPick){
2678 while(ViewerMainLoop(argccc,argvvv)){}
2679 IsGood = (TheAISContext()->NbSelected()>0) ;
2681 cout<<"Nb Pick :"<<NbPick<<endl;
2685 // step3 get result.
2687 TheAISContext()->InitSelected();
2688 IO = TheAISContext()->SelectedInteractive();
2692 TheAISContext()->CloseLocalContext(curindex);
2696 //=======================================================================
2697 //function : PickShape
2698 //purpose : First Activate the rightmode + Put Filters to be able to
2699 // pick objets that are of type <TheType>...
2700 //=======================================================================
2702 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2703 const Standard_Integer MaxPick)
2706 // step 1: prepare the data
2708 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2709 TopoDS_Shape result;
2711 if(TheType==TopAbs_SHAPE){
2712 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2713 TheAISContext()->AddFilter(F1);
2716 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2717 TheAISContext()->AddFilter(TF);
2718 TheAISContext()->ActivateStandardMode(TheType);
2723 // step 2 : wait for the selection...
2724 Standard_Boolean NoShape (Standard_True);
2725 Standard_Integer NbPick(0);
2726 Standard_Integer argccc = 5;
2727 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2728 const char **argvvv = (const char **) bufff;
2731 while(NoShape && NbPick<= MaxPick){
2732 while(ViewerMainLoop(argccc,argvvv)){}
2733 NoShape = (TheAISContext()->NbSelected()==0) ;
2735 cout<<"Nb Pick :"<<NbPick<<endl;
2738 // step3 get result.
2742 TheAISContext()->InitSelected();
2743 if(TheAISContext()->HasSelectedShape())
2744 result = TheAISContext()->SelectedShape();
2746 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2747 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2752 TheAISContext()->CloseLocalContext(curindex);
2758 //=======================================================================
2759 //function : PickShapes
2761 //=======================================================================
2762 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2763 Handle(TopTools_HArray1OfShape)& thearr,
2764 const Standard_Integer MaxPick)
2767 Standard_Integer Taille = thearr->Length();
2769 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2771 // step 1: prepare the data
2772 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2773 if(TheType==TopAbs_SHAPE){
2774 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2775 TheAISContext()->AddFilter(F1);
2778 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2779 TheAISContext()->AddFilter(TF);
2780 TheAISContext()->ActivateStandardMode(TheType);
2784 // step 2 : wait for the selection...
2786 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2787 Standard_Integer NbPickFail(0);
2788 Standard_Integer argccc = 5;
2789 const char *bufff[] = { "A", "B", "C","D", "E" };
2790 const char **argvvv = (const char **) bufff;
2793 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2794 while(ViewerMainLoop(argccc,argvvv)){}
2795 Standard_Integer NbStored = TheAISContext()->NbSelected();
2796 if((unsigned int ) NbStored != NbPickGood)
2797 NbPickGood= NbStored;
2800 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2803 // step3 get result.
2805 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2807 Standard_Integer i(0);
2808 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2810 if(TheAISContext()->HasSelectedShape())
2811 thearr->SetValue(i,TheAISContext()->SelectedShape());
2813 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2814 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2818 TheAISContext()->CloseLocalContext(curindex);
2819 return Standard_True;
2823 //=======================================================================
2824 //function : VPickShape
2826 //=======================================================================
2827 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2829 TopoDS_Shape PickSh;
2830 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2833 theType = TopAbs_SHAPE;
2835 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2836 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2837 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2838 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2839 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2840 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2841 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2844 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2845 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2847 TCollection_AsciiString name;
2850 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2852 PickSh = ViewerTest::PickShape(theType);
2861 if(!PickSh.IsNull()){
2862 nbOfSub[Standard_Integer(theType)]++;
2864 name += nameType[Standard_Integer(theType)];
2865 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2870 // si on avait une petite methode pour voir si la shape
2871 // est deja dans la Double map, ca eviterait de creer....
2872 DBRep::Set(name.ToCString(),PickSh);
2874 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2875 GetMapOfAIS().Bind(newsh, name);
2876 TheAISContext()->Display(newsh);
2877 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2880 // Plusieurs objets a picker, vite vite vite....
2883 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2884 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2885 if(ViewerTest::PickShapes(theType,arr)){
2886 for(Standard_Integer i=1;i<=NbToPick;i++){
2887 PickSh = arr->Value(i);
2888 if(!PickSh.IsNull()){
2890 nbOfSub[Standard_Integer(theType)]++;
2893 name += nameType[Standard_Integer(theType)];
2894 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2902 DBRep::Set(name.ToCString(),PickSh);
2903 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2904 GetMapOfAIS().Bind(newsh, name);
2905 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2906 TheAISContext()->Display(newsh);
2914 //=======================================================================
2915 //function : list of known objects
2917 //=======================================================================
2918 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2920 // 1234567890 12345678901234567 123456789
2921 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2922 TCollection_AsciiString BlankLine(64,'_');
2923 Standard_Integer i ;
2925 di<<"/n"<<BlankLine.ToCString()<<"\n";
2928 Colum[i].Center(20,' ');
2930 di<<"|"<<Colum[i].ToCString();
2933 di<<BlankLine.ToCString()<<"\n";
2935 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2936 const char ** names = GetTypeNames();
2938 TCollection_AsciiString curstring;
2939 TCollection_AsciiString curcolum[3];
2942 // les objets de type Datum..
2943 curcolum[1]+="Datum";
2945 curcolum[0].Clear();
2946 curcolum[0] += names[i];
2948 curcolum[2].Clear();
2949 curcolum[2]+=TCollection_AsciiString(i+1);
2951 for(Standard_Integer j =0;j<=2;j++){
2952 curcolum[j].Center(20,' ');
2953 di<<"|"<<curcolum[j].ToCString();
2957 di<<BlankLine.ToCString()<<"\n";
2959 // les objets de type shape
2960 curcolum[1].Clear();
2961 curcolum[1]+="Shape";
2962 curcolum[1].Center(20,' ');
2965 curcolum[0].Clear();
2966 curcolum[0] += names[7+i];
2967 curcolum[2].Clear();
2968 curcolum[2]+=TCollection_AsciiString(i);
2970 for(Standard_Integer j =0;j<=2;j++){
2971 curcolum[j].Center(20,' ');
2972 di<<"|"<<curcolum[j].ToCString();
2976 di<<BlankLine.ToCString()<<"\n";
2977 // les IO de type objet...
2978 curcolum[1].Clear();
2979 curcolum[1]+="Object";
2980 curcolum[1].Center(20,' ');
2982 curcolum[0].Clear();
2983 curcolum[0] += names[10+i];
2984 curcolum[2].Clear();
2985 curcolum[2]+=TCollection_AsciiString(i);
2987 for(Standard_Integer j =0;j<=2;j++){
2988 curcolum[j].Center(20,' ');
2989 di<<"|"<<curcolum[j].ToCString();
2993 di<<BlankLine.ToCString()<<"\n";
2994 // les contraintes et dimensions.
2995 // pour l'instant on separe juste contraintes et dimensions...
2996 // plus tard, on detaillera toutes les sortes...
2997 curcolum[1].Clear();
2998 curcolum[1]+="Relation";
2999 curcolum[1].Center(20,' ');
3001 curcolum[0].Clear();
3002 curcolum[0] += names[12+i];
3003 curcolum[2].Clear();
3004 curcolum[2]+=TCollection_AsciiString(i);
3006 for(Standard_Integer j =0;j<=2;j++){
3007 curcolum[j].Center(20,' ');
3008 di<<"|"<<curcolum[j].ToCString();
3012 di<<BlankLine.ToCString()<<"\n";
3019 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3021 if(argc!=2) return 1;
3023 AIS_KindOfInteractive TheType;
3024 Standard_Integer TheSign(-1);
3025 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3028 AIS_ListOfInteractive LIO;
3030 // en attendant l'amelioration ais pour les dimensions...
3032 Standard_Integer dimension_status(-1);
3033 if(TheType==AIS_KOI_Relation){
3034 dimension_status = TheSign ==1 ? 1 : 0;
3038 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3039 Handle(AIS_InteractiveObject) curio;
3040 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3043 if(dimension_status == -1)
3044 TheAISContext()->Erase(curio,Standard_False);
3046 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3047 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3048 (dimension_status==1 && KOD != AIS_KOD_NONE))
3049 TheAISContext()->Erase(curio,Standard_False);
3052 TheAISContext()->UpdateCurrentViewer();
3055 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3057 if(argc!=2) return 1;
3059 AIS_KindOfInteractive TheType;
3060 Standard_Integer TheSign(-1);
3061 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3063 // en attendant l'amelioration ais pour les dimensions...
3065 Standard_Integer dimension_status(-1);
3066 if(TheType==AIS_KOI_Relation){
3067 dimension_status = TheSign ==1 ? 1 : 0;
3071 AIS_ListOfInteractive LIO;
3072 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3073 Handle(AIS_InteractiveObject) curio;
3074 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3076 if(dimension_status == -1)
3077 TheAISContext()->Display(curio,Standard_False);
3079 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3080 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3081 (dimension_status==1 && KOD != AIS_KOD_NONE))
3082 TheAISContext()->Display(curio,Standard_False);
3087 TheAISContext()->UpdateCurrentViewer();
3091 //==============================================================================
3092 //function : VSetTransMode
3094 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3095 //==============================================================================
3097 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3098 // Verification des arguments
3099 if ( a3DView().IsNull() ) {
3100 ViewerTest::ViewerInit();
3101 di << "La commande vinit n'a pas ete appele avant" << "\n";
3104 if ( argc < 3 || argc > 8 ) {
3105 di << argv[0] << " Invalid number of arguments" << "\n";
3109 TCollection_AsciiString shapeName;
3110 shapeName = argv[1];
3111 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3112 Standard_Integer persFlag2 = 0;
3113 Standard_Integer persFlag3 = 0;
3114 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3115 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3116 persFlag2 = Draw::Atoi(argv[3]);
3118 if ( argc == 5 || argc == 8 ) {
3119 persFlag3 = Draw::Atoi(argv[4]);
3122 origin.SetX( Draw::Atof(argv[argc - 3]) );
3123 origin.SetY( Draw::Atof(argv[argc - 2]) );
3124 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3127 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3128 Handle(Standard_Transient) anObj;
3130 anObj = GetMapOfAIS().Find2(shapeName);
3131 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3132 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3133 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3134 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3135 di << argv[0] << " All persistence modifiers were removed" << "\n";
3138 di << argv[0] << " Wrong object type" << "\n";
3141 } else { // Create the AIS_Shape from a name
3142 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3143 if ( !aShape.IsNull() ) {
3144 GetMapOfAIS().Bind( aShape, shapeName );
3145 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3146 TheAISContext()->Display( aShape, Standard_False );
3148 di << argv[0] << " Object not found" << "\n";
3153 // Upadate the screen and redraw the view
3154 TheAISContext()->UpdateCurrentViewer();
3158 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3161 BRep_Builder builder;
3163 BRepTools::Read(shape, s, builder);
3164 DBRep::Set(a[1], shape);
3165 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3166 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3171 //==============================================================================
3172 //function : ViewerTest::Commands
3173 //purpose : Add all the viewer command in the Draw_Interpretor
3174 //==============================================================================
3176 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3178 ViewerTest::ViewerCommands(theCommands);
3179 ViewerTest::RelationCommands(theCommands);
3180 ViewerTest::ObjectCommands(theCommands);
3181 ViewerTest::FilletCommands(theCommands);
3182 ViewerTest::VoxelCommands(theCommands);
3183 ViewerTest::OpenGlCommands(theCommands);
3185 const char *group = "AIS_Display";
3188 theCommands.Add("visos",
3189 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3190 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3191 __FILE__, visos, group);
3193 theCommands.Add("vdisplay",
3194 "vdisplay name1 [name2] ... [name n]"
3195 "\n\t\t: Displays named objects",
3196 __FILE__,VDisplay2,group);
3198 theCommands.Add("verase",
3199 "verase [name1] ... [name n]"
3200 "\n\t\t: Erases selected or named objects."
3201 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3202 __FILE__, VErase, group);
3204 theCommands.Add("vdonly",
3205 "vdonly [name1] ... [name n]"
3206 "\n\t\t: Displays only selected or named objects",
3207 __FILE__,VDonly2,group);
3209 theCommands.Add("vdisplayall",
3210 "Displays all erased interactive objects (see vdir and vstate)",
3211 __FILE__,VDisplayAll,group);
3213 theCommands.Add("veraseall",
3214 "Erases all objects displayed in the viewer",
3215 __FILE__, VErase, group);
3217 theCommands.Add("verasetype",
3219 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3220 __FILE__,VEraseType,group);
3222 theCommands.Add("vdisplaytype",
3223 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3224 __FILE__,VDisplayType,group);
3226 theCommands.Add("vdisplaymode",
3227 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3228 __FILE__,VDispMode,group);
3230 theCommands.Add("verasemode",
3231 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3232 __FILE__,VDispMode,group);
3234 theCommands.Add("vsetdispmode",
3235 "vsetdispmode [name] mode(1,2,..)"
3236 "\n\t\t: Sets display mode for all, selected or named objects.",
3237 __FILE__,VDispMode,group);
3239 theCommands.Add("vunsetdispmode",
3240 "vunsetdispmode [name]"
3241 "\n\t\t: Unsets custom display mode for selected or named objects.",
3242 __FILE__,VDispMode,group);
3244 theCommands.Add("vdir",
3245 "Lists all objects displayed in 3D viewer",
3246 __FILE__,VDebug,group);
3248 theCommands.Add("vdump",
3249 #ifdef HAVE_FREEIMAGE
3250 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]"
3251 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3253 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height]"
3254 "\n\t\t: Dumps contents of viewer window to PPM image file",
3256 __FILE__,VDump,group);
3258 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3259 __FILE__,VSubInt,group);
3261 theCommands.Add("vsetcolor",
3262 "vsetcolor [name] ColorName"
3263 "\n\t\t: Sets color for all, selected or named objects.",
3264 __FILE__,VColor2,group);
3266 theCommands.Add("vunsetcolor",
3267 "vunsetcolor [name]"
3268 "\n\t\t: Resets color for all, selected or named objects.",
3269 __FILE__,VColor2,group);
3271 theCommands.Add("vsettransparency",
3272 "vsettransparency [name] Coefficient"
3273 "\n\t\t: Sets transparency for all, selected or named objects."
3274 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3275 __FILE__,VTransparency,group);
3277 theCommands.Add("vunsettransparency",
3278 "vunsettransparency [name]"
3279 "\n\t\t: Resets transparency for all, selected or named objects.",
3280 __FILE__,VTransparency,group);
3282 theCommands.Add("vsetmaterial",
3283 "vmaterial : vmaterial [name of shape] MaterialName",
3284 __FILE__,VMaterial,group);
3286 theCommands.Add("vunsetmaterial",
3287 "vmaterial : vmaterial [name of shape]",
3288 __FILE__,VMaterial,group);
3290 theCommands.Add("vsetwidth",
3291 "vsetwidth : vwidth [name of shape] width(0->10)",
3292 __FILE__,VWidth,group);
3294 theCommands.Add("vunsetwidth",
3295 "vunsetwidth : vwidth [name of shape]",
3296 __FILE__,VWidth,group);
3298 theCommands.Add("vsetinteriorstyle",
3299 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3300 __FILE__,VInteriorStyle,group);
3302 theCommands.Add("vardis",
3303 "vardis : display activeareas",
3304 __FILE__,VDispAreas,group);
3306 theCommands.Add("varera",
3307 "varera : erase activeareas",
3308 __FILE__,VClearAreas,group);
3310 theCommands.Add("vsensdis",
3311 "vardisp : display active entities",
3312 __FILE__,VDispSensi,group);
3313 theCommands.Add("vsensera",
3314 "vardisp : erase active entities",
3315 __FILE__,VClearSensi,group);
3317 theCommands.Add("vselprecision",
3318 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3319 __FILE__,VSelPrecision,group);
3321 theCommands.Add("vperf",
3322 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3323 __FILE__,VPerf,group);
3325 theCommands.Add("vanimation",
3326 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3327 __FILE__,VAnimation,group);
3329 theCommands.Add("vsetshading",
3330 "vsetshading : vsetshading name Quality(default=0.0008) ",
3331 __FILE__,VShading,group);
3333 theCommands.Add("vunsetshading",
3334 "vunsetshading :vunsetshading name ",
3335 __FILE__,VShading,group);
3337 theCommands.Add("vtexture",
3338 "'vtexture NameOfShape TextureFile' \n \
3339 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3340 or 'vtexture NameOfShape ?' to list available textures\n \
3341 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3342 __FILE__,VTexture,group);
3344 theCommands.Add("vshaderprog",
3345 "'vshaderprog NameOfShape VertexShaderFile FragmentShaderFile'",
3346 __FILE__,VShaderProg,group);
3348 theCommands.Add("vtexscale",
3349 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3350 or 'vtexscale NameOfShape ScaleUV' \n \
3351 or 'vtexscale NameOfShape' to disable scaling\n ",
3352 __FILE__,VTexture,group);
3354 theCommands.Add("vtexorigin",
3355 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3356 or 'vtexorigin NameOfShape UVOrigin' \n \
3357 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3358 __FILE__,VTexture,group);
3360 theCommands.Add("vtexrepeat",
3361 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3362 or 'vtexrepeat NameOfShape UVRepeat \n \
3363 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3366 theCommands.Add("vtexdefault",
3367 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3370 theCommands.Add("vsetam",
3371 "vsetActivatedModes: vsetam mode(1->7) ",
3372 __FILE__,VActivatedMode,group);
3374 theCommands.Add("vunsetam",
3375 "vunsetActivatedModes: vunsetam ",
3376 __FILE__,VActivatedMode,group);
3378 theCommands.Add("vstate",
3379 "vstate [name1] ... [nameN]"
3380 "\n\t\t: Reports show/hidden state for selected or named objects",
3381 __FILE__,VState,group);
3383 theCommands.Add("vpickshapes",
3384 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3385 __FILE__,VPickShape,group);
3387 theCommands.Add("vtypes",
3388 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3391 theCommands.Add("vsettransmode",
3392 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3393 __FILE__,VSetTransMode,group);
3395 theCommands.Add("vr", "vr : reading of the shape",
3396 __FILE__,vr, group);
3400 //=====================================================================
3401 //========================= for testing Draft and Rib =================
3402 //=====================================================================
3403 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3404 #include <DBRep.hxx>
3405 #include <TopoDS_Face.hxx>
3406 #include <gp_Pln.hxx>
3407 #include <AIS_KindOfSurface.hxx>
3408 #include <BRepOffsetAPI_DraftAngle.hxx>
3409 #include <Precision.hxx>
3410 #include <BRepAlgo.hxx>
3411 #include <OSD_Environment.hxx>
3412 #include <DrawTrSurf.hxx>
3413 //#include <DbgTools.hxx>
3414 //#include <FeatAlgo_MakeLinearForm.hxx>
3419 //=======================================================================
3420 //function : IsValid
3422 //=======================================================================
3423 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3424 const TopoDS_Shape& theResult,
3425 const Standard_Boolean closedSolid,
3426 const Standard_Boolean GeomCtrl)
3428 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3429 TCollection_AsciiString checkValid = check.Value();
3430 Standard_Boolean ToCheck = Standard_True;
3431 if (!checkValid.IsEmpty()) {
3433 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3435 if ( checkValid=="true" || checkValid=="TRUE" ) {
3436 ToCheck= Standard_False;
3440 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3443 Standard_Boolean IsValid = Standard_True;
3445 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3450 //===============================================================================
3451 // TDraft : test draft, uses AIS Viewer
3452 // Solid Face Plane Angle Reverse
3453 //===============================================================================
3454 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3456 if (argc < 5) return 1;
3457 // argv[1] - TopoDS_Shape Solid
3458 // argv[2] - TopoDS_Shape Face
3459 // argv[3] - TopoDS_Shape Plane
3460 // argv[4] - Standard_Real Angle
3461 // argv[5] - Standard_Integer Reverse
3463 // Sprintf(prefix, argv[1]);
3464 Standard_Real anAngle = 0;
3465 Standard_Boolean Rev = Standard_False;
3466 Standard_Integer rev = 0;
3467 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3468 TopoDS_Shape face = GetShapeFromName(argv[2]);
3469 TopoDS_Face Face = TopoDS::Face(face);
3470 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3471 if (Plane.IsNull ()) {
3472 di << "TEST : Plane is NULL" << "\n";
3475 anAngle = Draw::Atof(argv[4]);
3476 anAngle = 2*M_PI * anAngle / 360.0;
3478 Handle( Geom_Surface )aSurf;
3479 AIS_KindOfSurface aSurfType;
3480 Standard_Real Offset;
3482 if(argc > 4) { // == 5
3483 rev = Draw::Atoi(argv[5]);
3484 Rev = (rev)? Standard_True : Standard_False;
3487 TopoDS_Face face2 = TopoDS::Face(Plane);
3488 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3490 di << "TEST : Can't find plane" << "\n";
3494 aDir = aPln.Axis().Direction();
3497 if (Plane.Orientation() == TopAbs_REVERSED)
3499 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3501 BRepOffsetAPI_DraftAngle Draft (Solid);
3503 if(Abs(anAngle)< Precision::Angular()) {
3504 di << "TEST : NULL angle" << "\n";
3507 if(Rev) anAngle = - anAngle;
3508 Draft.Add (Face, aDir, anAngle, aPln);
3510 if (!Draft.IsDone()) {
3511 di << "TEST : Draft Not DONE " << "\n";
3514 TopTools_ListOfShape Larg;
3516 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3517 di << "TEST : DesignAlgo returns Not valid" << "\n";
3521 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3522 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3524 if ( !ais.IsNull() ) {
3525 ais->SetColor(DEFAULT_COLOR);
3526 ais->SetMaterial(DEFAULT_MATERIAL);
3527 // Display the AIS_Shape without redraw
3528 Ctx->Display(ais, Standard_False);
3530 const char *Name = "draft1";
3531 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3533 Handle(AIS_InteractiveObject) an_object =
3534 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3535 if (!an_object.IsNull()) {
3536 Ctx->Remove(an_object,
3538 GetMapOfAIS().UnBind2(Name) ;
3541 GetMapOfAIS().Bind(ais, Name);
3542 // DBRep::Set("draft", ais->Shape());
3544 Ctx->Display(ais, Standard_True);
3550 //============================================================================
3552 //============================================================================
3553 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3556 DrawTrSurf::BasicCommands(theCommands);
3557 const char* group = "Check Features Operations commands";
3559 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3561 &TDraft,group); //Draft_Modification
3564 //==============================================================================
3565 // ViewerTest::Factory
3566 //==============================================================================
3567 void ViewerTest::Factory(Draw_Interpretor& theDI)
3569 // definition of Viewer Command
3570 ViewerTest::Commands(theDI);
3571 ViewerTest::AviCommands(theDI);
3574 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3578 // Declare entry point PLUGINFACTORY