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 <Image_AlienPixMap.hxx>
60 #include <Prs3d_ShadingAspect.hxx>
61 #include <Prs3d_IsoAspect.hxx>
71 #include <Draw_Interpretor.hxx>
72 #include <TCollection_AsciiString.hxx>
73 #include <Draw_PluginMacro.hxx>
74 #include <ViewerTest.hxx>
76 // avoid warnings on 'extern "C"' functions returning C++ classes
78 #define _CRT_SECURE_NO_DEPRECATE
79 #pragma warning(4:4190)
80 #pragma warning (disable:4996)
83 #include <NIS_InteractiveContext.hxx>
84 #include <NIS_Triangulated.hxx>
85 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
96 //=======================================================================
97 //function : GetColorFromName
98 //purpose : get the Quantity_NameOfColor from a string
99 //=======================================================================
101 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
105 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
106 if (strcasecmp (theName, aColorName) == 0)
108 return Quantity_NameOfColor (anIter);
112 return DEFAULT_COLOR;
115 //=======================================================================
116 //function : GetMaterialFromName
117 //purpose : get the Graphic3d_NameOfMaterial from a string
118 //=======================================================================
120 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
122 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
124 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
125 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
126 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
127 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
128 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
129 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
130 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
131 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
132 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
133 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
134 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
135 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
136 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
137 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
138 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
139 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
140 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
141 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
142 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
147 //=======================================================================
148 //function : GetTypeNames
150 //=======================================================================
151 static const char** GetTypeNames()
153 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
154 "Shape","ConnectedShape","MultiConn.Shape",
155 "ConnectedInter.","MultiConn.",
156 "Constraint","Dimension"};
157 static const char** ThePointer = names;
161 //=======================================================================
162 //function : GetTypeAndSignfromString
164 //=======================================================================
165 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
167 const char ** thefullnames = GetTypeNames();
168 Standard_Integer index(-1);
170 for(Standard_Integer i=0;i<=13 && index==-1;i++)
171 if(!strcasecmp(name,thefullnames[i]))
175 TheType = AIS_KOI_None;
181 TheType = AIS_KOI_Datum;
185 TheType = AIS_KOI_Shape;
189 TheType = AIS_KOI_Object;
193 TheType = AIS_KOI_Relation;
202 #include <Draw_Interpretor.hxx>
204 #include <Draw_Appli.hxx>
208 #include <TCollection_AsciiString.hxx>
209 #include <V3d_Viewer.hxx>
210 #include <V3d_View.hxx>
213 #include <AIS_InteractiveContext.hxx>
214 #include <AIS_Shape.hxx>
215 #include <AIS_TexturedShape.hxx>
216 #include <AIS_DisplayMode.hxx>
217 #include <TColStd_MapOfInteger.hxx>
218 #include <AIS_MapOfInteractive.hxx>
219 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
220 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
221 #include <ViewerTest_EventManager.hxx>
223 #include <TopoDS_Solid.hxx>
224 #include <BRepTools.hxx>
225 #include <BRep_Builder.hxx>
226 #include <TopAbs_ShapeEnum.hxx>
228 #include <TopoDS.hxx>
229 #include <BRep_Tool.hxx>
232 #include <Draw_Window.hxx>
233 #include <AIS_ListIteratorOfListOfInteractive.hxx>
234 #include <AIS_ListOfInteractive.hxx>
235 #include <AIS_DisplayMode.hxx>
236 #include <TopTools_ListOfShape.hxx>
237 #include <BRepOffsetAPI_MakeThickSolid.hxx>
238 #include <BRepOffset.hxx>
240 //==============================================================================
241 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
242 //==============================================================================
243 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
244 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
249 //==============================================================================
250 //function : VDisplayAISObject
251 //purpose : register interactive object in the map of AIS objects;
252 // if other object with such name already registered, it will be kept
253 // or replaced depending on value of <theReplaceIfExists>,
254 // if "true" - the old object will be cleared from AIS context;
255 // returns Standard_True if <theAISObj> registered in map;
256 //==============================================================================
257 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
258 const Handle(AIS_InteractiveObject)& theAISObj,
259 Standard_Boolean theReplaceIfExists = Standard_True)
261 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
262 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
263 if (aContextAIS.IsNull())
265 std::cout << "AIS context is not available.\n";
266 return Standard_False;
269 if (aMap.IsBound2 (theName))
271 if (!theReplaceIfExists)
273 std::cout << "Other interactive object has been already "
274 << "registered with name: " << theName << ".\n"
275 << "Please use another name.\n";
276 return Standard_False;
279 // stop displaying object
280 Handle(AIS_InteractiveObject) anOldObj =
281 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
283 if (!anOldObj.IsNull())
284 aContextAIS->Clear (anOldObj, Standard_True);
286 // remove name and old object from map
287 aMap.UnBind2 (theName);
290 if (theAISObj.IsNull())
292 // object with specified name already unbound
293 return Standard_True;
296 // unbind AIS object if was bound with another name
297 aMap.UnBind1 (theAISObj);
299 // can be registered without rebinding
300 aMap.Bind (theAISObj, theName);
301 aContextAIS->Display (theAISObj, Standard_True);
302 return Standard_True;
305 static TColStd_MapOfInteger theactivatedmodes(8);
306 static TColStd_ListOfTransient theEventMgrs;
308 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
309 const Handle(AIS_InteractiveContext)& Ctx)
311 theEventMgrs.Clear();
312 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
315 static Handle(V3d_View)& a3DView()
317 static Handle(V3d_View) Viou;
322 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
323 static Handle(AIS_InteractiveContext) aContext;
327 const Handle(V3d_View)& ViewerTest::CurrentView()
331 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
336 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
338 static Handle(NIS_InteractiveContext) aContext;
339 if (aContext.IsNull()) {
340 aContext = new NIS_InteractiveContext;
341 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
346 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
348 return TheAISContext();
351 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
353 TheAISContext() = aCtx;
354 ViewerTest::ResetEventManager();
357 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
359 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
362 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
364 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
368 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
369 theEventMgrs.Prepend(EM);
372 void ViewerTest::UnsetEventManager()
374 theEventMgrs.RemoveFirst();
378 void ViewerTest::ResetEventManager()
380 const Handle(NIS_View) aView =
381 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
382 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
385 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
387 Handle(ViewerTest_EventManager) EM;
388 if(theEventMgrs.IsEmpty()) return EM;
389 Handle(Standard_Transient) Tr = theEventMgrs.First();
390 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
395 //=======================================================================
396 //function : Get Context and active viou..
398 //=======================================================================
399 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
400 Handle(V3d_View)& Viou)
402 Ctx = ViewerTest::GetAISContext();
405 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
406 Vwr->InitActiveViews();
407 if(Vwr->MoreActiveViews())
408 Viou = Vwr->ActiveView();
413 //==============================================================================
414 //function : GetShapeFromName
415 //purpose : Compute an Shape from a draw variable or a file name
416 //==============================================================================
418 static TopoDS_Shape GetShapeFromName(const char* name)
420 TopoDS_Shape S = DBRep::Get(name);
423 BRep_Builder aBuilder;
424 BRepTools::Read( S, name, aBuilder);
430 //==============================================================================
431 //function : GetAISShapeFromName
432 //purpose : Compute an AIS_Shape from a draw variable or a file name
433 //==============================================================================
434 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
436 Handle(AIS_Shape) retsh;
438 if(GetMapOfAIS().IsBound2(name)){
439 const Handle(AIS_InteractiveObject) IO =
440 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
442 if(IO->Type()==AIS_KOI_Shape) {
443 if(IO->Signature()==0){
444 retsh = *((Handle(AIS_Shape)*)&IO);
447 cout << "an Object which is not an AIS_Shape "
448 "already has this name!!!"<<endl;
455 TopoDS_Shape S = GetShapeFromName(name);
457 retsh = new AIS_Shape(S);
463 //==============================================================================
465 //purpose : Remove all the object from the viewer
466 //==============================================================================
467 void ViewerTest::Clear()
469 if ( !a3DView().IsNull() ) {
470 if (TheAISContext()->HasOpenedContext())
471 TheAISContext()->CloseLocalContext();
472 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
473 while ( it.More() ) {
474 cout << "Remove " << it.Key2() << endl;
475 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
476 const Handle(AIS_InteractiveObject) anObj =
477 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
478 TheAISContext()->Remove(anObj,Standard_False);
479 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
480 const Handle(NIS_InteractiveObject) anObj =
481 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
482 TheNISContext()->Remove(anObj);
486 TheAISContext()->UpdateCurrentViewer();
487 // TheNISContext()->UpdateViews();
488 GetMapOfAIS().Clear();
492 //==============================================================================
493 //function : StandardModesActivation
494 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
496 //==============================================================================
497 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
499 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
501 if (TheAISContext()->HasOpenedContext())
502 aContext->CloseLocalContext();
505 if(!aContext->HasOpenedContext()) {
506 // To unhilight the preselected object
507 aContext->UnhilightCurrents(Standard_False);
508 // Open a local Context in order to be able to select subshape from
509 // the selected shape if any or for all if there is no selection
510 if (!aContext->FirstCurrentObject().IsNull()){
511 aContext->OpenLocalContext(Standard_False);
513 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
514 aContext->Load( aContext->Current(),-1,Standard_True);
518 aContext->OpenLocalContext();
521 const char *cmode="???";
524 case 0: cmode = "Shape"; break;
525 case 1: cmode = "Vertex"; break;
526 case 2: cmode = "Edge"; break;
527 case 3: cmode = "Wire"; break;
528 case 4: cmode = "Face"; break;
529 case 5: cmode = "Shell"; break;
530 case 6: cmode = "Solid"; break;
531 case 7: cmode = "Compsolid"; break;
532 case 8: cmode = "Compound"; break;
535 if(theactivatedmodes.Contains(mode))
537 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
538 theactivatedmodes.Remove(mode);
539 cout<<"Mode "<< cmode <<" OFF"<<endl;
543 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
544 theactivatedmodes.Add(mode);
545 cout<<"Mode "<< cmode << " ON" << endl;
550 //==============================================================================
551 //function : CopyIsoAspect
552 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
553 //==============================================================================
554 static Handle(Prs3d_IsoAspect) CopyIsoAspect
555 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
556 const Standard_Integer theNbIsos)
558 Quantity_Color aColor;
559 Aspect_TypeOfLine aType;
560 Standard_Real aWidth;
562 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
564 Handle(Prs3d_IsoAspect) aResult =
565 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
570 //==============================================================================
572 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
573 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
574 //==============================================================================
575 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
577 if (TheAISContext().IsNull()) {
578 di << argv[0] << " Call 'vinit' before!\n";
583 di << "Current number of isos : " <<
584 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
585 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
586 di << "IsoOnPlane mode is " <<
587 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
592 Standard_Integer aLastInd = argc - 1;
593 Standard_Boolean isChanged = Standard_False;
594 Standard_Integer aNbUIsos = 0;
595 Standard_Integer aNbVIsos = 0;
598 Standard_Boolean isIsoOnPlane = Standard_False;
600 if (strcmp(argv[aLastInd], "1") == 0) {
601 isIsoOnPlane = Standard_True;
602 isChanged = Standard_True;
603 } else if (strcmp(argv[aLastInd], "0") == 0) {
604 isIsoOnPlane = Standard_False;
605 isChanged = Standard_True;
609 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
610 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
613 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
614 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
616 TheAISContext()->IsoOnPlane(isIsoOnPlane);
619 // If there are no shapes provided set the default numbers.
620 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
621 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
628 for (i = 1; i <= aLastInd; i++) {
629 TCollection_AsciiString name(argv[i]);
630 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
633 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
634 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
635 const Handle(AIS_InteractiveObject) aShape =
636 Handle(AIS_InteractiveObject)::DownCast (anObj);
637 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
638 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
639 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
642 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
643 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
644 TheAISContext()->SetLocalAttributes
645 (aShape, CurDrawer, Standard_False);
646 TheAISContext()->Redisplay(aShape);
648 di << "Number of isos for " << argv[i] << " : "
649 << aUIso->Number() << " " << aVIso->Number() << "\n";
652 di << argv[i] << ": Not an AIS interactive object!\n";
655 di << argv[i] << ": Use 'vdisplay' before\n";
660 TheAISContext()->UpdateCurrentViewer();
666 //==============================================================================
667 //function : VDispAreas,VDispSensitive,...
668 //purpose : Redraw the view
670 //==============================================================================
671 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
674 Handle(AIS_InteractiveContext) Ctx;
675 Handle(V3d_View) Viou;
676 GetCtxAndView(Ctx,Viou);
677 Ctx->DisplayActiveAreas(Viou);
680 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
682 Handle(AIS_InteractiveContext) Ctx;
683 Handle(V3d_View) Viou;
684 GetCtxAndView(Ctx,Viou);
685 Ctx->ClearActiveAreas(Viou);
689 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
691 Handle(AIS_InteractiveContext) Ctx;
692 Handle(V3d_View) Viou;
693 GetCtxAndView(Ctx,Viou);
694 Ctx->DisplayActiveSensitive(Viou);
698 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
700 Handle(AIS_InteractiveContext) Ctx;
701 Handle(V3d_View) Viou;
702 GetCtxAndView(Ctx,Viou);
703 Ctx->ClearActiveSensitive(Viou);
707 //==============================================================================
709 //purpose : To list the displayed object with their attributes
711 //==============================================================================
712 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
713 { if ( !a3DView().IsNull() ) {
714 di << "List of object in the viewer :" << "\n";
716 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
718 while ( it.More() ) {
719 di << "\t" << it.Key2().ToCString() << "\n";
727 //==============================================================================
728 //function : VSelPrecision
729 //purpose : To set the selection precision mode and tolerance value
730 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
731 // value (integer number of pixel for window mode, double value of
732 // sensitivity for view mode). Without arguments the function just
733 // prints the current precision mode and the corresponding tolerance.
734 //==============================================================================
735 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
739 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
743 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
744 if( aContext.IsNull() )
749 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
750 if( aMode == StdSelect_SM_WINDOW )
752 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
753 di << "Precision mode : 0 (window)\n";
754 di << "Pixel tolerance : " << aPixelTolerance << "\n";
756 else if( aMode == StdSelect_SM_VIEW )
758 Standard_Real aSensitivity = aContext->Sensitivity();
759 di << "Precision mode : 1 (view)\n";
760 di << "Sensitivity : " << aSensitivity << "\n";
765 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
766 aContext->SetSensitivityMode( aMode );
769 if( aMode == StdSelect_SM_WINDOW )
771 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
772 aContext->SetPixelTolerance( aPixelTolerance );
774 else if( aMode == StdSelect_SM_VIEW )
776 Standard_Real aSensitivity = Draw::Atof( argv[2] );
777 aContext->SetSensitivity( aSensitivity );
784 //==============================================================================
786 //purpose : To dump the active view snapshot to image file
787 //Draw arg : Picture file name with extension corresponding to desired format
788 //==============================================================================
789 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
793 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
797 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
800 const char* aBuffTypeStr = argv[2];
801 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
803 aBufferType = Graphic3d_BT_RGB;
805 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
807 aBufferType = Graphic3d_BT_RGBA;
809 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
811 aBufferType = Graphic3d_BT_Depth;
815 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
816 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
818 Handle(AIS_InteractiveContext) IC;
819 Handle(V3d_View) view;
820 GetCtxAndView (IC, view);
823 di << "Cannot find an active viewer/view\n";
827 if (aWidth <= 0 || aHeight <= 0)
829 if (!view->Dump (argv[1], aBufferType))
831 di << "Dumping failed!\n";
837 Image_AlienPixMap aPixMap;
838 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
840 di << "Dumping failed!\n";
844 if (aPixMap.SizeX() != Standard_Size(aWidth)
845 || aPixMap.SizeY() != Standard_Size(aHeight))
847 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
848 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
850 if (!aPixMap.Save (argv[1]))
852 di << "Saving image failed!\n";
859 //==============================================================================
860 //function : Displays,Erase...
863 //==============================================================================
864 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
865 const Standard_Integer Mode,
866 const Standard_Integer TypeOfOperation,
867 const Standard_Boolean Upd)
869 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
871 switch(TypeOfOperation){
873 Ctx->Display(IO,Mode,Upd);
876 Ctx->Erase(IO,Mode,Upd);
881 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
883 Ctx->SetDisplayMode(IO,Mode,Upd);
888 Ctx->SetDisplayMode(0,Upd);
890 Ctx->UnsetDisplayMode(IO,Upd);
897 //=======================================================================
900 //=======================================================================
901 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
904 TCollection_AsciiString name;
907 // display others presentations
908 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
909 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
910 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
911 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
913 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
915 //unset displaymode.. comportement particulier...
916 if(TypeOfOperation==4){
918 if(Ctx->NbCurrents()==0 ||
919 Ctx->NbSelected()==0){
920 Handle(AIS_InteractiveObject) IO;
921 VwrTst_DispErase(IO,-1,4,Standard_False);
923 else if(!Ctx->HasOpenedContext()){
924 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
925 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
928 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
929 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
930 Ctx->UpdateCurrentViewer();
933 Handle(AIS_InteractiveObject) IO;
935 if(GetMapOfAIS().IsBound2(name)){
936 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
938 VwrTst_DispErase(IO,-1,4,Standard_True);
943 Standard_Integer Dmode = Draw::Atoi(argv[1]);
944 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
945 Handle(AIS_InteractiveObject) IO;
946 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
948 if(!Ctx->HasOpenedContext()){
949 // set/unset display mode sur le Contexte...
950 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
951 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
953 Ctx->UpdateCurrentViewer();
956 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
957 Ctx->Display(Ctx->Interactive(),Dmode);
961 Handle(AIS_InteractiveObject) IO;
963 if(GetMapOfAIS().IsBound2(name))
964 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
966 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
972 //=======================================================================
975 //=======================================================================
976 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
978 if(argc==1) return 1;
979 Standard_Integer On = Draw::Atoi(argv[1]);
980 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
984 if(!Ctx->HasOpenedContext()){
985 di<<"sub intensite ";
988 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
989 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
991 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
993 di <<"passage dans off"<<"\n";
994 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
999 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1001 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1003 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1006 Ctx->UpdateCurrentViewer();
1009 Handle(AIS_InteractiveObject) IO;
1010 TCollection_AsciiString name = argv[2];
1011 if(GetMapOfAIS().IsBound2(name)){
1012 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1015 Ctx->SubIntensityOn(IO);
1017 Ctx->SubIntensityOff(IO);
1025 //==============================================================================
1026 //function : VColor2
1028 //purpose : change the color of a selected or named or displayed shape
1029 //Draw arg : vcolor2 [name] color
1030 //==============================================================================
1031 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1034 Standard_Boolean ThereIsCurrent;
1035 Standard_Boolean ThereIsArgument;
1036 Standard_Boolean IsBound = Standard_False ;
1038 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1040 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1041 ThereIsArgument = (argc != 2);
1044 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1045 ThereIsArgument = (argc == 2);
1048 if ( !a3DView().IsNull() ) {
1049 TCollection_AsciiString name;
1050 if (ThereIsArgument) {
1052 IsBound= GetMapOfAIS().IsBound2(name);
1054 if (TheAISContext()->HasOpenedContext())
1055 TheAISContext()->CloseLocalContext();
1057 // On set le Booleen There is current
1058 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1059 else ThereIsCurrent =Standard_False;
1061 //=======================================================================
1062 // Il y a un argument
1063 //=======================================================================
1064 if ( ThereIsArgument && IsBound ) {
1065 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1066 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1067 Handle(AIS_InteractiveObject) ashape =
1068 Handle(AIS_InteractiveObject)::DownCast (anObj);
1071 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1073 di << "HaveToSet 0\n";
1077 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1079 TheAISContext()->UnsetColor(ashape);
1080 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1081 Handle(NIS_Triangulated) ashape =
1082 Handle(NIS_Triangulated)::DownCast (anObj);
1083 if (!ashape.IsNull())
1084 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1089 //=======================================================================
1090 // Il n'y a pas d'arguments
1091 // Mais un ou plusieurs objets on des current representation
1092 //=======================================================================
1093 if (ThereIsCurrent && !ThereIsArgument) {
1094 for (TheAISContext() -> InitCurrent() ;
1095 TheAISContext() -> MoreCurrent() ;
1096 TheAISContext() ->NextCurrent() )
1098 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1099 if (ashape.IsNull())
1103 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1105 di << "HaveToSet 0\n";
1108 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1110 TheAISContext()->UnsetColor(ashape,Standard_False);
1113 TheAISContext()->UpdateCurrentViewer();
1116 //=======================================================================
1117 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1118 // on impose a tous les objets du viewer la couleur passee
1119 //=======================================================================
1120 else if (!ThereIsCurrent && !ThereIsArgument){
1121 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1122 while ( it.More() ) {
1123 const Handle(AIS_InteractiveObject) ashape =
1124 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1125 if (!ashape.IsNull()) {
1127 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1129 TheAISContext()->UnsetColor(ashape,Standard_False);
1133 TheAISContext()->UpdateCurrentViewer();
1139 //==============================================================================
1140 //function : VTransparency
1142 //purpose : change the transparency of a selected or named or displayed shape
1143 //Draw arg : vtransparency [name] TransparencyCoeficient
1144 //==============================================================================
1146 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1149 Standard_Boolean ThereIsCurrent;
1150 Standard_Boolean ThereIsArgument;
1151 Standard_Boolean IsBound = Standard_False ;
1153 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1155 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1156 ThereIsArgument = (argc != 2);
1159 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1160 ThereIsArgument = (argc == 2);
1163 if ( !a3DView().IsNull() ) {
1164 TCollection_AsciiString name;
1165 if (ThereIsArgument) {
1167 IsBound= GetMapOfAIS().IsBound2(name);
1169 if (TheAISContext()->HasOpenedContext())
1170 TheAISContext()->CloseLocalContext();
1172 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1173 else ThereIsCurrent = Standard_False;
1175 //=======================================================================
1176 // Il y a des arguments: un nom et une couleur
1177 //=======================================================================
1178 if ( ThereIsArgument && IsBound ) {
1179 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1180 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1181 const Handle(AIS_InteractiveObject) ashape =
1182 Handle(AIS_InteractiveObject)::DownCast(anObj);
1184 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1186 TheAISContext()->UnsetTransparency(ashape);
1187 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1188 const Handle(NIS_InteractiveObject) ashape =
1189 Handle(NIS_InteractiveObject)::DownCast(anObj);
1191 ashape->SetTransparency(Draw::Atof(argv[2]) );
1193 ashape->UnsetTransparency();
1196 //=======================================================================
1197 // Il n'y a pas d'arguments
1198 // Mais un ou plusieurs objets on des current representation
1199 //=======================================================================
1200 if (ThereIsCurrent && !ThereIsArgument) {
1201 for (TheAISContext() -> InitCurrent() ;
1202 TheAISContext() -> MoreCurrent() ;
1203 TheAISContext() ->NextCurrent() )
1205 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1207 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1209 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1212 TheAISContext()->UpdateCurrentViewer();
1214 //=======================================================================
1215 // Il n'y a pas d'arguments ET aucun objet courrant
1216 //=======================================================================
1217 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1218 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1220 while ( it.More() ) {
1221 Handle(AIS_InteractiveObject) ashape =
1222 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1223 if (!ashape.IsNull()) {
1225 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1227 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1231 TheAISContext()->UpdateCurrentViewer();
1238 //==============================================================================
1239 //function : VMaterial
1241 //purpose : change the Material of a selected or named or displayed shape
1242 //Draw arg : vmaterial [Name] Material
1243 //==============================================================================
1244 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1247 Standard_Boolean ThereIsCurrent;
1248 Standard_Boolean ThereIsName;
1249 Standard_Boolean IsBound = Standard_False ;
1251 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1253 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1254 ThereIsName = (argc != 2);
1257 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1258 ThereIsName = (argc == 2);
1261 if ( !a3DView().IsNull() ) {
1262 TCollection_AsciiString name;
1265 IsBound= GetMapOfAIS().IsBound2(name);
1267 if (TheAISContext()->HasOpenedContext())
1268 TheAISContext()->CloseLocalContext();
1269 if (TheAISContext() -> NbCurrents() > 0 )
1270 ThereIsCurrent =Standard_True;
1272 ThereIsCurrent =Standard_False;
1274 //=======================================================================
1275 // Ther is a name of shape and a material name
1276 //=======================================================================
1277 if ( ThereIsName && IsBound ) {
1278 Handle(AIS_InteractiveObject) ashape =
1279 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1280 if (!ashape.IsNull()) {
1282 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1284 TheAISContext()->UnsetMaterial(ashape);
1287 //=======================================================================
1288 // Il n'y a pas de nom de shape
1289 // Mais un ou plusieurs objets on des current representation
1290 //=======================================================================
1291 if (ThereIsCurrent && !ThereIsName) {
1292 for (TheAISContext() -> InitCurrent() ;
1293 TheAISContext() -> MoreCurrent() ;
1294 TheAISContext() ->NextCurrent() )
1296 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1298 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1300 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1302 TheAISContext()->UpdateCurrentViewer();
1305 //=======================================================================
1306 // Il n'y a pas de noms de shape ET aucun objet courrant
1307 // On impose a tous les objets du viewer le material passe en argument
1308 //=======================================================================
1309 else if (!ThereIsCurrent && !ThereIsName){
1310 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1312 while ( it.More() ) {
1313 Handle(AIS_InteractiveObject) ashape =
1314 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1315 if (!ashape.IsNull()) {
1317 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1319 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1323 TheAISContext()->UpdateCurrentViewer();
1331 //==============================================================================
1334 //purpose : change the width of the edges of a selected or named or displayed shape
1335 //Draw arg : vwidth [Name] WidthValue(1->10)
1336 //==============================================================================
1337 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1340 Standard_Boolean ThereIsCurrent;
1341 Standard_Boolean ThereIsArgument;
1342 Standard_Boolean IsBound = Standard_False ;
1344 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1346 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1347 ThereIsArgument = (argc != 2);
1350 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1351 ThereIsArgument = (argc == 2);
1353 if ( !a3DView().IsNull() ) {
1354 TCollection_AsciiString name;
1355 if (ThereIsArgument) {
1357 IsBound= GetMapOfAIS().IsBound2(name);
1359 if (TheAISContext()->HasOpenedContext())
1360 TheAISContext()->CloseLocalContext();
1362 if (TheAISContext() -> NbCurrents() > 0 )
1363 ThereIsCurrent =Standard_True;
1365 ThereIsCurrent =Standard_False;
1367 if ( ThereIsArgument && IsBound ) {
1368 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1369 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1370 const Handle(AIS_InteractiveObject) ashape =
1371 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1373 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1375 TheAISContext()->UnsetWidth (ashape);
1376 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1377 const Handle(NIS_Triangulated) ashape =
1378 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1379 if (HaveToSet && !ashape.IsNull())
1380 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1384 //=======================================================================
1385 // Il n'y a pas d'arguments
1386 // Mais un ou plusieurs objets on des current representation
1387 //=======================================================================
1388 if (ThereIsCurrent && !ThereIsArgument) {
1389 for (TheAISContext() -> InitCurrent() ;
1390 TheAISContext() -> MoreCurrent() ;
1391 TheAISContext() ->NextCurrent() )
1393 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1395 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1397 TheAISContext()->UnsetWidth(ashape,Standard_False);
1399 TheAISContext()->UpdateCurrentViewer();
1401 //=======================================================================
1402 // Il n'y a pas d'arguments ET aucun objet courrant
1403 //=======================================================================
1404 else if (!ThereIsCurrent && !ThereIsArgument){
1405 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1407 while ( it.More() ) {
1408 Handle(AIS_InteractiveObject) ashape =
1409 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1410 if (!ashape.IsNull()) {
1412 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1414 TheAISContext()->UnsetWidth(ashape,Standard_False);
1418 TheAISContext()->UpdateCurrentViewer();
1424 //==============================================================================
1425 //function : VInteriorStyle
1426 //purpose : sets interior style of the a selected or named or displayed shape
1427 //Draw arg : vsetinteriorstyle [shape] style
1428 //==============================================================================
1429 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1430 const Standard_Integer theStyle,
1431 Draw_Interpretor& di)
1433 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1434 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1435 " (Aspect_IS_HIDDENLINE)]\n";
1438 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1439 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1440 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1441 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1442 aFillAspect->SetInteriorStyle (aStyle);
1443 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1446 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1448 if (argc < 2 || argc > 3) {
1449 di << argv[0] << " requires 2 or 3 arguments\n";
1450 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1451 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1452 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1456 Standard_Boolean ThereIsCurrent;
1457 Standard_Boolean ThereIsArgument;
1458 Standard_Boolean IsBound = Standard_False ;
1460 ThereIsArgument = (argc > 2);
1461 if ( !a3DView().IsNull() ) {
1462 TCollection_AsciiString name;
1463 if (ThereIsArgument) {
1465 IsBound= GetMapOfAIS().IsBound2(name);
1467 if (TheAISContext()->HasOpenedContext())
1468 TheAISContext()->CloseLocalContext();
1470 if (TheAISContext() -> NbCurrents() > 0 )
1471 ThereIsCurrent =Standard_True;
1473 ThereIsCurrent =Standard_False;
1475 if ( ThereIsArgument && IsBound ) {
1476 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1477 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1478 const Handle(AIS_InteractiveObject) ashape =
1479 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1480 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1483 //=======================================================================
1484 // No arguments specified
1485 // But there are one or more selected objects
1486 //=======================================================================
1487 if (ThereIsCurrent && !ThereIsArgument) {
1488 for (TheAISContext() -> InitCurrent() ;
1489 TheAISContext() -> MoreCurrent() ;
1490 TheAISContext() ->NextCurrent() )
1492 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1493 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1496 //=======================================================================
1497 // No arguments specified and there are no selected objects
1498 //=======================================================================
1499 else if (!ThereIsCurrent && !ThereIsArgument){
1500 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1502 while ( it.More() ) {
1503 Handle(AIS_InteractiveObject) ashape =
1504 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1505 if (!ashape.IsNull())
1506 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1510 TheAISContext()->UpdateCurrentViewer();
1515 //==============================================================================
1516 //function : VDonly2
1518 //purpose : Display only a selected or named object
1519 // if there is no selected or named object s, nothing is donne
1520 //Draw arg : vdonly2 [name1] ... [name n]
1521 //==============================================================================
1522 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1525 if ( a3DView().IsNull() )
1528 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1529 Standard_Boolean ThereIsArgument= argc>1;
1531 if (TheAISContext()->HasOpenedContext())
1532 TheAISContext()->CloseLocalContext();
1534 //===============================================================
1535 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1537 //===============================================================
1538 if (!ThereIsArgument && ThereIsCurrent) {
1541 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1544 for(TheAISContext()->InitCurrent();
1545 TheAISContext()->MoreCurrent();
1546 TheAISContext()->NextCurrent()){
1547 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1548 TheAISContext()->Erase(aShape,Standard_False);}
1550 TheAISContext() ->UpdateCurrentViewer();
1551 //===============================================================
1552 // Il y a des arguments
1553 //===============================================================
1554 if (ThereIsArgument) {
1555 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1557 while ( it.More() ) {
1558 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1559 const Handle(AIS_InteractiveObject) aShape =
1560 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1561 TheAISContext()->Erase(aShape,Standard_False);
1562 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1563 const Handle(NIS_InteractiveObject) aShape =
1564 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1565 TheNISContext()->Erase(aShape);
1570 // On display les objets passes par parametre
1571 for (int i=1; i<argc ; i++) {
1572 TCollection_AsciiString name=argv[i];
1573 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1575 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1576 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1577 const Handle(AIS_InteractiveObject) aShape =
1578 Handle(AIS_InteractiveObject)::DownCast (anObj);
1579 TheAISContext()->Display(aShape, Standard_False);
1580 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1581 Handle(NIS_InteractiveObject) aShape =
1582 Handle(NIS_InteractiveObject)::DownCast (anObj);
1583 TheNISContext()->Display(aShape);
1587 TheAISContext() ->UpdateCurrentViewer();
1588 // TheNISContext() ->UpdateViews();
1593 //==============================================================================
1594 //function : VErase2
1596 //purpose : Erase some selected or named objects
1597 // if there is no selected or named objects, the whole viewer is erased
1598 //Draw arg : verase2 [name1] ... [name n]
1599 //==============================================================================
1600 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1603 if ( a3DView().IsNull() )
1606 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1607 Standard_Boolean ThereIsArgument= argc>1;
1608 if(TheAISContext()->HasOpenedContext())
1609 TheAISContext()->CloseLocalContext();
1611 //===============================================================
1612 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1614 //===============================================================
1615 if (!ThereIsArgument && ThereIsCurrent) {
1616 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1618 while ( it.More() ) {
1619 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1620 const Handle(AIS_InteractiveObject) aShape =
1621 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1622 if (TheAISContext()->IsCurrent(aShape))
1623 TheAISContext()->Erase(aShape,Standard_False);
1628 TheAISContext() ->UpdateCurrentViewer();
1631 //===============================================================
1632 // Il n'y a pas d'arguments et aucuns objets selectionnes
1634 // On erase tout le viewer
1635 //===============================================================
1637 if (!ThereIsArgument && !ThereIsCurrent) {
1638 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1639 while ( it.More() ) {
1640 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1641 const Handle(AIS_InteractiveObject) aShape =
1642 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1643 TheAISContext()->Erase(aShape,Standard_False);
1644 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1645 const Handle(NIS_InteractiveObject) aShape =
1646 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1647 TheNISContext()->Erase(aShape);
1651 TheAISContext() ->UpdateCurrentViewer();
1652 // TheNISContext()->UpdateViews();
1655 //===============================================================
1656 // Il y a des arguments
1657 //===============================================================
1658 if (ThereIsArgument) {
1659 for (int i=1; i<argc ; i++) {
1660 TCollection_AsciiString name=argv[i];
1661 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1663 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1664 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1665 const Handle(AIS_InteractiveObject) aShape =
1666 Handle(AIS_InteractiveObject)::DownCast (anObj);
1667 TheAISContext()->Erase(aShape,Standard_False);
1668 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1669 const Handle(NIS_InteractiveObject) aShape =
1670 Handle(NIS_InteractiveObject)::DownCast (anObj);
1671 TheNISContext()->Erase(aShape);
1675 TheAISContext() ->UpdateCurrentViewer();
1676 // TheNISContext() ->UpdateViews();
1681 //==============================================================================
1682 //function : VEraseAll
1684 //purpose : Erase all the objects displayed in the viewer
1685 //Draw arg : veraseall
1686 //==============================================================================
1687 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1690 // Verification des arguments
1691 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1692 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1693 TheAISContext()->CloseAllContexts(Standard_False);
1694 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1696 while ( it.More() ) {
1697 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1698 const Handle(AIS_InteractiveObject) aShape =
1699 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1700 TheAISContext()->Erase(aShape,Standard_False);
1701 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1702 const Handle(NIS_InteractiveObject) aShape =
1703 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1704 TheNISContext()->Erase(aShape);
1708 TheAISContext() ->UpdateCurrentViewer();
1709 // TheNISContext() ->UpdateViews();
1714 //==============================================================================
1715 //function : VDisplayAll
1717 //purpose : Display all the objects of the Map
1718 //Draw arg : vdisplayall
1719 //==============================================================================
1720 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1723 if (! a3DView().IsNull() ) {
1724 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1725 if (TheAISContext()->HasOpenedContext())
1726 TheAISContext()->CloseLocalContext();
1727 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1729 while ( it.More() ) {
1730 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1731 const Handle(AIS_InteractiveObject) aShape =
1732 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1733 TheAISContext()->Erase(aShape,Standard_False);
1734 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1735 const Handle(NIS_InteractiveObject) aShape =
1736 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1737 TheNISContext()->Erase(aShape);
1742 while ( it.More() ) {
1743 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1744 const Handle(AIS_InteractiveObject) aShape =
1745 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1746 TheAISContext()->Display(aShape, Standard_False);
1747 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1748 Handle(NIS_InteractiveObject) aShape =
1749 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1750 TheNISContext()->Display(aShape);
1754 TheAISContext() ->UpdateCurrentViewer();
1755 // TheNISContext() ->UpdateViews();
1760 //#######################################################################################################
1764 //#######################################################################################################
1766 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1768 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1769 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1770 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1771 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1772 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1774 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1775 if(myAISContext.IsNull())
1777 di << "use 'vinit' command before " << argv[0] << "\n";
1781 Handle(AIS_InteractiveObject) TheAisIO;
1782 Handle(AIS_TexturedShape) myShape;
1783 Standard_Integer myPreviousMode = 0;
1785 if (argc<2 || !argv[1])
1787 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1791 TCollection_AsciiString name = argv[1];
1792 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1794 if (GetMapOfAIS().IsBound2(name))
1795 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1796 (GetMapOfAIS().Find2(name));
1797 if (TheAisIO.IsNull())
1799 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1803 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1805 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1806 myPreviousMode = myShape->DisplayMode() ;
1810 myAISContext->Clear(TheAisIO,Standard_False);
1811 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1812 GetMapOfAIS().UnBind1(TheAisIO);
1813 GetMapOfAIS().UnBind2(name);
1814 GetMapOfAIS().Bind(myShape, name);
1818 case 1: // vtexture : we only map a texture on the shape
1821 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1824 if (argc>2 && argv[2])
1826 if(strcasecmp(argv[2],"?")==0)
1828 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1829 di<<"\n Files in current directory : \n"<<"\n";
1830 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1831 di.Eval(Cmnd.ToCString());
1833 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1836 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1837 di.Eval(Cmnd.ToCString());
1842 myShape->SetTextureFileName(argv[2]);
1846 di <<"Texture mapping disabled \n \
1847 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1849 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1850 if (myPreviousMode == 3 )
1851 myAISContext->RecomputePrsOnly(myShape);
1852 myAISContext->Display(myShape, Standard_True);
1857 case 2: // vtexscale : we change the scaling factor of the texture
1861 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1865 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1866 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1867 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1870 case 3: // vtexorigin : we change the origin of the texture on the shape
1873 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1876 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1877 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1878 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
1881 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1884 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1887 if (argc>2 && argv[2])
1889 di <<"Texture repeat enabled"<<"\n";
1890 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
1894 di <<"Texture repeat disabled"<<"\n";
1895 myShape->SetTextureRepeat(Standard_False);
1899 case 5: // vtexdefault : default texture mapping
1900 // ScaleU = ScaleV = 100.0
1901 // URepeat = VRepeat = 1.0
1902 // Uorigin = VOrigin = 0.0
1906 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1909 myShape->SetTextureRepeat(Standard_False);
1910 myShape->SetTextureOrigin(Standard_False);
1911 myShape->SetTextureScale (Standard_False);
1915 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1916 myAISContext->RecomputePrsOnly(myShape);
1919 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1920 myAISContext->Display(myShape, Standard_True);
1921 myAISContext->Update(myShape,Standard_True);
1926 //==============================================================================
1927 //function : VDisplay2
1929 //purpose : Display an object from its name
1930 //Draw arg : vdisplay name1 [name2] ... [name n]
1931 //==============================================================================
1932 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1935 // Verification des arguments
1936 if ( a3DView().IsNull() ) {
1938 ViewerTest::ViewerInit();
1939 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1944 di<<argv[0]<<" Syntaxe error"<<"\n";
1949 TCollection_AsciiString name;
1950 if (TheAISContext()->HasOpenedContext())
1951 TheAISContext()->CloseLocalContext();
1953 for ( int i = 1; i < argc; i++ ) {
1955 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1956 Standard_Boolean IsDatum = Standard_False;
1957 Handle(Standard_Transient) anObj;
1959 anObj = GetMapOfAIS().Find2(name);
1960 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1961 Handle(AIS_InteractiveObject) aShape =
1962 Handle(AIS_InteractiveObject)::DownCast(anObj);
1963 if (aShape->Type()==AIS_KOI_Datum) {
1964 IsDatum = Standard_True;
1965 TheAISContext()->Display(aShape, Standard_False);
1968 di << "Display " << name.ToCString() << "\n";
1969 // Get the Shape from a name
1970 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1972 // Update the Shape in the AIS_Shape
1973 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1974 if(!TheRealSh.IsNull())
1975 TheRealSh->Set(NewShape);
1976 TheAISContext()->Redisplay(aShape, Standard_False);
1977 TheAISContext()->Display(aShape, Standard_False);
1980 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1981 Handle(NIS_InteractiveObject) aShape =
1982 Handle(NIS_InteractiveObject)::DownCast(anObj);
1983 TheNISContext()->Display(aShape);
1986 else { // Create the AIS_Shape from a name
1987 const Handle(AIS_InteractiveObject) aShape =
1988 GetAISShapeFromName((const char *)name.ToCString());
1989 if ( !aShape.IsNull() ) {
1990 GetMapOfAIS().Bind(aShape, name);
1991 TheAISContext()->Display(aShape, Standard_False);
1995 // Upadate the screen and redraw the view
1996 TheAISContext()->UpdateCurrentViewer();
1997 // TheNISContext()->UpdateViews();
2001 //==============================================================================
2003 //purpose : Test the annimation of an object along a
2004 // predifined trajectory
2005 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2006 //==============================================================================
2008 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2011 if (TheAISContext()->HasOpenedContext())
2012 TheAISContext()->CloseLocalContext();
2014 Standard_Real Step=4*M_PI/180;
2015 Standard_Real Angle=0;
2017 Handle(AIS_InteractiveObject) aIO;
2018 if (GetMapOfAIS().IsBound2(argv[1]))
2019 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2023 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2027 if (Draw::Atoi(argv[3])==1 ) {
2028 di<<" Primitives sensibles OFF"<<"\n";
2029 TheAISContext()->Deactivate(aIO);
2032 di<<" Primitives sensibles ON"<<"\n";
2034 // Movement par transformation
2035 if(Draw::Atoi(argv[2]) ==1) {
2036 di<<" Calcul par Transformation"<<"\n";
2037 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2041 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2042 TheAISContext()->SetLocation(aShape,myTransfo);
2043 TheAISContext() ->UpdateCurrentViewer();
2048 di<<" Calcul par Locations"<<"\n";
2049 gp_Trsf myAngleTrsf;
2050 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2051 TopLoc_Location myDeltaAngle (myAngleTrsf);
2052 TopLoc_Location myTrueLoc;
2054 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2057 myTrueLoc=myTrueLoc*myDeltaAngle;
2058 TheAISContext()->SetLocation(aShape,myTrueLoc );
2059 TheAISContext() ->UpdateCurrentViewer();
2062 if (Draw::Atoi(argv[3])==1 ){
2063 // On reactive la selection des primitives sensibles
2064 TheAISContext()->Activate(aIO,0);
2066 a3DView() -> Redraw();
2068 di<<" Temps ecoule "<<"\n";
2074 //==================================================================================
2075 // Function : VAnimation
2076 //==================================================================================
2077 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2079 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2083 Standard_Real thread = 4;
2084 Standard_Real angleA=0;
2085 Standard_Real angleB;
2087 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2090 TopoDS_Shape CrankArm;
2091 TopoDS_Shape CylinderHead;
2092 TopoDS_Shape Propeller;
2093 TopoDS_Shape EngineBlock;
2095 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2096 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2097 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2098 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2099 BRepTools::Read(CrankArm,argv[1],B);
2100 BRepTools::Read(CylinderHead,argv[2],B);
2101 BRepTools::Read(Propeller,argv[3],B);
2102 BRepTools::Read(EngineBlock,argv[4],B);
2104 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2110 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2111 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2112 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2113 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2115 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2116 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2117 GetMapOfAIS().Bind(myAisCrankArm,"c");
2118 GetMapOfAIS().Bind(myAisPropeller,"d");
2120 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2121 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2122 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2124 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2125 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2126 TheAISContext()->Display(myAisCrankArm,Standard_False );
2127 TheAISContext()->Display(myAisPropeller,Standard_False);
2129 TheAISContext()->Deactivate(myAisCylinderHead);
2130 TheAISContext()->Deactivate(myAisEngineBlock );
2131 TheAISContext()->Deactivate(myAisCrankArm );
2132 TheAISContext()->Deactivate(myAisPropeller );
2134 // Boucle de mouvement
2135 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2137 angleA = thread*myAngle*M_PI/180;
2138 X = Sin(angleA)*3/8;
2139 angleB = atan(X / Sqrt(-X * X + 1));
2140 Standard_Real decal(25*0.6);
2143 //Build a transformation on the display
2144 gp_Trsf aPropellerTrsf;
2145 aPropellerTrsf.SetRotation(Ax1,angleA);
2146 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2148 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));
2149 gp_Trsf aCrankArmTrsf;
2150 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2151 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2153 TheAISContext()->UpdateCurrentViewer();
2156 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2157 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2159 myAisCrankArm ->ResetLocation();
2160 myAisPropeller->ResetLocation();
2162 myAisCrankArm -> Set(myNewCrankArm );
2163 myAisPropeller -> Set(myNewPropeller);
2165 TheAISContext()->Activate(myAisCylinderHead,0);
2166 TheAISContext()->Activate(myAisEngineBlock,0 );
2167 TheAISContext()->Activate(myAisCrankArm ,0 );
2168 TheAISContext()->Activate(myAisPropeller ,0 );
2174 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2175 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2177 TheAISContext()->UpdateCurrentViewer();
2178 a3DView()->Redraw();
2187 //==============================================================================
2188 //function : VShading
2189 //purpose : Sharpen or roughten the quality of the shading
2190 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2191 //==============================================================================
2192 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2194 Standard_Real myDevCoef;
2195 Handle(AIS_InteractiveObject) TheAisIO;
2198 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2200 if (TheAISContext()->HasOpenedContext())
2201 TheAISContext()->CloseLocalContext();
2206 myDevCoef =Draw::Atof(argv[2]);
2209 TCollection_AsciiString name=argv[1];
2210 if (GetMapOfAIS().IsBound2(name ))
2211 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2212 if (TheAisIO.IsNull())
2213 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2216 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2218 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2220 TheAISContext()->Redisplay(TheAisIO);
2223 //==============================================================================
2224 //function : HaveMode
2225 //use : VActivatedModes
2226 //==============================================================================
2227 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2229 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2231 TColStd_ListOfInteger List;
2232 TheAISContext()->ActivatedModes (TheAisIO,List);
2233 TColStd_ListIteratorOfListOfInteger it;
2234 Standard_Boolean Found=Standard_False;
2235 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2236 if (it.Value()==mode ) Found=Standard_True;
2243 //==============================================================================
2244 //function : VActivatedMode
2246 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2247 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2248 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2249 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2250 // qu'un nom et qu'un mode.
2251 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2252 //==============================================================================
2253 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2255 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2258 Standard_Boolean ThereIsName = Standard_False ;
2260 if(!a3DView().IsNull()){
2262 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2263 // verification des arguments
2265 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2266 ThereIsName = (argc == 3);
2270 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2272 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2273 di<<" Fermeture du Context local"<<"\n";
2274 if (TheAISContext()->HasOpenedContext())
2275 TheAISContext()->CloseLocalContext();
2279 // IL n'y a aps de nom de shape passe en argument
2280 if (HaveToSet && !ThereIsName){
2281 Standard_Integer aMode=Draw::Atoi(argv [1]);
2283 const char *cmode="???";
2285 case 0: cmode = "Shape"; break;
2286 case 1: cmode = "Vertex"; break;
2287 case 2: cmode = "Edge"; break;
2288 case 3: cmode = "Wire"; break;
2289 case 4: cmode = "Face"; break;
2290 case 5: cmode = "Shell"; break;
2291 case 6: cmode = "Solid"; break;
2292 case 7: cmode = "Compound"; break;
2295 if( !TheAISContext()->HasOpenedContext() ) {
2296 // il n'y a pas de Context local d'ouvert
2297 // on en ouvre un et on charge toutes les shapes displayees
2298 // on load tous les objets displayees et on Activate les objets de la liste
2299 AIS_ListOfInteractive ListOfIO;
2300 // on sauve dans une AISListOfInteractive tous les objets currents
2301 if (TheAISContext()->NbCurrents()>0 ){
2302 TheAISContext()->UnhilightCurrents(Standard_False);
2304 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2305 ListOfIO.Append(TheAISContext()->Current() );
2309 TheAISContext()->OpenLocalContext(Standard_False);
2310 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2313 Handle(AIS_InteractiveObject) aIO =
2314 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2316 TheAISContext()->Load(aIO,0,Standard_False);
2319 // traitement des objets qui etaient currents dans le Contexte global
2320 if (!ListOfIO.IsEmpty() ) {
2321 // il y avait des objets currents
2322 AIS_ListIteratorOfListOfInteractive iter;
2323 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2324 Handle(AIS_InteractiveObject) aIO=iter.Value();
2325 TheAISContext()->Activate(aIO,aMode);
2326 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2330 // On applique le mode a tous les objets displayes
2331 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2332 it2 (GetMapOfAIS());
2334 Handle(AIS_InteractiveObject) aIO =
2335 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2336 if (!aIO.IsNull()) {
2337 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2338 TheAISContext()->Activate(aIO,aMode);
2347 // un Context local est deja ouvert
2348 // Traitement des objets du Context local
2349 if (TheAISContext()->NbSelected()>0 ){
2350 TheAISContext()->UnhilightSelected(Standard_False);
2351 // il y a des objets selected,on les parcourt
2352 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2353 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2356 if (HaveMode(aIO,aMode) ) {
2357 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2358 TheAISContext()->Deactivate(aIO,aMode);
2361 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2362 TheAISContext()->Activate(aIO,aMode);
2368 // il n'y a pas d'objets selected
2369 // tous les objets diplayes sont traites
2370 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2373 Handle(AIS_InteractiveObject) aIO =
2374 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2375 if (!aIO.IsNull()) {
2376 if (HaveMode(aIO,aMode) ) {
2377 di<<" Mode: "<<cmode<<" OFF pour "
2378 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2379 TheAISContext()->Deactivate(aIO,aMode);
2382 di<<" Mode: "<<cmode<<" ON pour"
2383 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2384 TheAISContext()->Activate(aIO,aMode);
2392 else if (HaveToSet && ThereIsName){
2393 Standard_Integer aMode=Draw::Atoi(argv [2]);
2394 Handle(AIS_InteractiveObject) aIO =
2395 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2397 if (!aIO.IsNull()) {
2398 const char *cmode="???";
2401 case 0: cmode = "Shape"; break;
2402 case 1: cmode = "Vertex"; break;
2403 case 2: cmode = "Edge"; break;
2404 case 3: cmode = "Wire"; break;
2405 case 4: cmode = "Face"; break;
2406 case 5: cmode = "Shell"; break;
2407 case 6: cmode = "Solid"; break;
2408 case 7: cmode = "Compound"; break;
2411 if( !TheAISContext()->HasOpenedContext() ) {
2412 TheAISContext()->OpenLocalContext(Standard_False);
2413 // On charge tous les objets de la map
2414 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2416 Handle(AIS_InteractiveObject) aShape=
2417 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2418 if (!aShape.IsNull())
2419 TheAISContext()->Load(aShape,0,Standard_False);
2422 TheAISContext()->Activate(aIO,aMode);
2423 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2427 // un Context local est deja ouvert
2428 if (HaveMode(aIO,aMode) ) {
2429 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2430 TheAISContext()->Deactivate(aIO,aMode);
2433 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2434 TheAISContext()->Activate(aIO,aMode);
2446 //==============================================================================
2447 // function : WhoAmI
2449 //==============================================================================
2450 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2453 if (theShape->Type()==AIS_KOI_Datum) {
2454 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2455 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2456 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2457 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2458 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2459 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2460 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2463 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2464 // AIS_Dimentions et AIS_Relations
2465 else if (theShape->Type()==AIS_KOI_Relation) {
2466 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2468 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2469 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2470 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2471 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2472 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2473 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2474 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2475 // AIS no repertorie.
2476 else {di<<" Type Unknown.";}
2482 //==============================================================================
2485 //Draw arg : vstate [nameA] ... [nameN]
2486 //==============================================================================
2487 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2489 TheAISContext()->CloseAllContexts();
2490 const Standard_Boolean ThereIsArguments=(argc>=2);
2491 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2493 // ==================
2494 // Il y a un argument
2495 // ==================
2496 if (ThereIsArguments) {
2497 for (int cpt=1;cpt<argc;cpt++) {
2498 // Verification que lq piece est bien bindee.
2499 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2500 const Handle(AIS_InteractiveObject) theShape=
2501 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2503 if (!theShape.IsNull()) {
2504 di<<argv[cpt];WhoAmI(theShape, di);
2505 if (TheAISContext()->IsDisplayed(theShape) ) {
2506 di<<" Displayed"<<"\n";
2509 di<<" Not Displayed"<<"\n";
2514 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2518 else if (ThereIsCurrent ) {
2519 for (TheAISContext() -> InitCurrent() ;
2520 TheAISContext() -> MoreCurrent() ;
2521 TheAISContext() ->NextCurrent() )
2523 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2524 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2525 if (TheAISContext()->IsDisplayed(theShape) ) {
2526 di<<" Displayed"<<"\n";
2529 di<<" Not Displayed"<<"\n";
2535 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2537 while ( it.More() ) {
2538 Handle(AIS_InteractiveObject) theShape =
2539 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2540 if (!theShape.IsNull()) {
2541 di<<it.Key2().ToCString();
2542 WhoAmI(theShape, di);
2543 if (TheAISContext()->IsDisplayed(theShape) ) {
2544 di<<" Displayed"<<"\n";
2547 di<<" Not Displayed"<<"\n";
2558 //=======================================================================
2559 //function : PickObjects
2561 //=======================================================================
2562 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2563 const AIS_KindOfInteractive TheType,
2564 const Standard_Integer TheSignature,
2565 const Standard_Integer MaxPick)
2567 Handle(AIS_InteractiveObject) IO;
2568 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2570 // step 1: prepare the data
2572 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2573 TheAISContext()->AddFilter(F1);
2576 // step 2 : wait for the selection...
2577 // Standard_Boolean IsGood (Standard_False);
2578 // Standard_Integer NbPick(0);
2579 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2580 Standard_Integer NbPickFail(0);
2581 Standard_Integer argccc = 5;
2582 const char *bufff[] = { "A", "B", "C","D", "E" };
2583 const char **argvvv = (const char **) bufff;
2586 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2587 while(ViewerMainLoop(argccc,argvvv)){}
2588 Standard_Integer NbStored = TheAISContext()->NbSelected();
2589 if((unsigned int ) NbStored != NbPickGood)
2590 NbPickGood= NbStored;
2593 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2596 // step3 get result.
2598 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2600 Standard_Integer i(0);
2601 for(TheAISContext()->InitSelected();
2602 TheAISContext()->MoreSelected();
2603 TheAISContext()->NextSelected()){
2605 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2606 arr->SetValue(i,IO2);
2611 TheAISContext()->CloseLocalContext(curindex);
2613 return Standard_True;
2617 //=======================================================================
2618 //function : PickObject
2620 //=======================================================================
2621 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2622 const Standard_Integer TheSignature,
2623 const Standard_Integer MaxPick)
2625 Handle(AIS_InteractiveObject) IO;
2626 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2628 // step 1: prepare the data
2631 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2632 TheAISContext()->AddFilter(F1);
2635 // step 2 : wait for the selection...
2636 Standard_Boolean IsGood (Standard_False);
2637 Standard_Integer NbPick(0);
2638 Standard_Integer argccc = 5;
2639 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2640 const char **argvvv = (const char **) bufff;
2643 while(!IsGood && NbPick<= MaxPick){
2644 while(ViewerMainLoop(argccc,argvvv)){}
2645 IsGood = (TheAISContext()->NbSelected()>0) ;
2647 cout<<"Nb Pick :"<<NbPick<<endl;
2651 // step3 get result.
2653 TheAISContext()->InitSelected();
2654 IO = TheAISContext()->SelectedInteractive();
2658 TheAISContext()->CloseLocalContext(curindex);
2662 //=======================================================================
2663 //function : PickShape
2664 //purpose : First Activate the rightmode + Put Filters to be able to
2665 // pick objets that are of type <TheType>...
2666 //=======================================================================
2668 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2669 const Standard_Integer MaxPick)
2672 // step 1: prepare the data
2674 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2675 TopoDS_Shape result;
2677 if(TheType==TopAbs_SHAPE){
2678 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2679 TheAISContext()->AddFilter(F1);
2682 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2683 TheAISContext()->AddFilter(TF);
2684 TheAISContext()->ActivateStandardMode(TheType);
2689 // step 2 : wait for the selection...
2690 Standard_Boolean NoShape (Standard_True);
2691 Standard_Integer NbPick(0);
2692 Standard_Integer argccc = 5;
2693 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2694 const char **argvvv = (const char **) bufff;
2697 while(NoShape && NbPick<= MaxPick){
2698 while(ViewerMainLoop(argccc,argvvv)){}
2699 NoShape = (TheAISContext()->NbSelected()==0) ;
2701 cout<<"Nb Pick :"<<NbPick<<endl;
2704 // step3 get result.
2708 TheAISContext()->InitSelected();
2709 if(TheAISContext()->HasSelectedShape())
2710 result = TheAISContext()->SelectedShape();
2712 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2713 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2718 TheAISContext()->CloseLocalContext(curindex);
2724 //=======================================================================
2725 //function : PickShapes
2727 //=======================================================================
2728 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2729 Handle(TopTools_HArray1OfShape)& thearr,
2730 const Standard_Integer MaxPick)
2733 Standard_Integer Taille = thearr->Length();
2735 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2737 // step 1: prepare the data
2738 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2739 if(TheType==TopAbs_SHAPE){
2740 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2741 TheAISContext()->AddFilter(F1);
2744 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2745 TheAISContext()->AddFilter(TF);
2746 TheAISContext()->ActivateStandardMode(TheType);
2750 // step 2 : wait for the selection...
2752 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2753 Standard_Integer NbPickFail(0);
2754 Standard_Integer argccc = 5;
2755 const char *bufff[] = { "A", "B", "C","D", "E" };
2756 const char **argvvv = (const char **) bufff;
2759 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2760 while(ViewerMainLoop(argccc,argvvv)){}
2761 Standard_Integer NbStored = TheAISContext()->NbSelected();
2762 if((unsigned int ) NbStored != NbPickGood)
2763 NbPickGood= NbStored;
2766 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2769 // step3 get result.
2771 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2773 Standard_Integer i(0);
2774 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2776 if(TheAISContext()->HasSelectedShape())
2777 thearr->SetValue(i,TheAISContext()->SelectedShape());
2779 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2780 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2784 TheAISContext()->CloseLocalContext(curindex);
2785 return Standard_True;
2789 //=======================================================================
2790 //function : VPickShape
2792 //=======================================================================
2793 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2795 TopoDS_Shape PickSh;
2796 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2799 theType = TopAbs_SHAPE;
2801 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2802 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2803 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2804 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2805 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2806 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2807 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2810 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2811 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2813 TCollection_AsciiString name;
2816 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2818 PickSh = ViewerTest::PickShape(theType);
2827 if(!PickSh.IsNull()){
2828 nbOfSub[Standard_Integer(theType)]++;
2830 name += nameType[Standard_Integer(theType)];
2831 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2836 // si on avait une petite methode pour voir si la shape
2837 // est deja dans la Double map, ca eviterait de creer....
2838 DBRep::Set(name.ToCString(),PickSh);
2840 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2841 GetMapOfAIS().Bind(newsh, name);
2842 TheAISContext()->Display(newsh);
2843 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2846 // Plusieurs objets a picker, vite vite vite....
2849 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2850 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2851 if(ViewerTest::PickShapes(theType,arr)){
2852 for(Standard_Integer i=1;i<=NbToPick;i++){
2853 PickSh = arr->Value(i);
2854 if(!PickSh.IsNull()){
2856 nbOfSub[Standard_Integer(theType)]++;
2859 name += nameType[Standard_Integer(theType)];
2860 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2868 DBRep::Set(name.ToCString(),PickSh);
2869 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2870 GetMapOfAIS().Bind(newsh, name);
2871 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2872 TheAISContext()->Display(newsh);
2880 //=======================================================================
2881 //function : list of known objects
2883 //=======================================================================
2884 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2886 // 1234567890 12345678901234567 123456789
2887 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2888 TCollection_AsciiString BlankLine(64,'_');
2889 Standard_Integer i ;
2891 di<<"/n"<<BlankLine.ToCString()<<"\n";
2894 Colum[i].Center(20,' ');
2896 di<<"|"<<Colum[i].ToCString();
2899 di<<BlankLine.ToCString()<<"\n";
2901 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2902 const char ** names = GetTypeNames();
2904 TCollection_AsciiString curstring;
2905 TCollection_AsciiString curcolum[3];
2908 // les objets de type Datum..
2909 curcolum[1]+="Datum";
2911 curcolum[0].Clear();
2912 curcolum[0] += names[i];
2914 curcolum[2].Clear();
2915 curcolum[2]+=TCollection_AsciiString(i+1);
2917 for(Standard_Integer j =0;j<=2;j++){
2918 curcolum[j].Center(20,' ');
2919 di<<"|"<<curcolum[j].ToCString();
2923 di<<BlankLine.ToCString()<<"\n";
2925 // les objets de type shape
2926 curcolum[1].Clear();
2927 curcolum[1]+="Shape";
2928 curcolum[1].Center(20,' ');
2931 curcolum[0].Clear();
2932 curcolum[0] += names[7+i];
2933 curcolum[2].Clear();
2934 curcolum[2]+=TCollection_AsciiString(i);
2936 for(Standard_Integer j =0;j<=2;j++){
2937 curcolum[j].Center(20,' ');
2938 di<<"|"<<curcolum[j].ToCString();
2942 di<<BlankLine.ToCString()<<"\n";
2943 // les IO de type objet...
2944 curcolum[1].Clear();
2945 curcolum[1]+="Object";
2946 curcolum[1].Center(20,' ');
2948 curcolum[0].Clear();
2949 curcolum[0] += names[10+i];
2950 curcolum[2].Clear();
2951 curcolum[2]+=TCollection_AsciiString(i);
2953 for(Standard_Integer j =0;j<=2;j++){
2954 curcolum[j].Center(20,' ');
2955 di<<"|"<<curcolum[j].ToCString();
2959 di<<BlankLine.ToCString()<<"\n";
2960 // les contraintes et dimensions.
2961 // pour l'instant on separe juste contraintes et dimensions...
2962 // plus tard, on detaillera toutes les sortes...
2963 curcolum[1].Clear();
2964 curcolum[1]+="Relation";
2965 curcolum[1].Center(20,' ');
2967 curcolum[0].Clear();
2968 curcolum[0] += names[12+i];
2969 curcolum[2].Clear();
2970 curcolum[2]+=TCollection_AsciiString(i);
2972 for(Standard_Integer j =0;j<=2;j++){
2973 curcolum[j].Center(20,' ');
2974 di<<"|"<<curcolum[j].ToCString();
2978 di<<BlankLine.ToCString()<<"\n";
2985 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
2987 if(argc!=2) return 1;
2989 AIS_KindOfInteractive TheType;
2990 Standard_Integer TheSign(-1);
2991 GetTypeAndSignfromString(argv[1],TheType,TheSign);
2994 AIS_ListOfInteractive LIO;
2996 // en attendant l'amelioration ais pour les dimensions...
2998 Standard_Integer dimension_status(-1);
2999 if(TheType==AIS_KOI_Relation){
3000 dimension_status = TheSign ==1 ? 1 : 0;
3004 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3005 Handle(AIS_InteractiveObject) curio;
3006 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3009 if(dimension_status == -1)
3010 TheAISContext()->Erase(curio,Standard_False);
3012 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3013 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3014 (dimension_status==1 && KOD != AIS_KOD_NONE))
3015 TheAISContext()->Erase(curio,Standard_False);
3018 TheAISContext()->UpdateCurrentViewer();
3021 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3023 if(argc!=2) return 1;
3025 AIS_KindOfInteractive TheType;
3026 Standard_Integer TheSign(-1);
3027 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3029 // en attendant l'amelioration ais pour les dimensions...
3031 Standard_Integer dimension_status(-1);
3032 if(TheType==AIS_KOI_Relation){
3033 dimension_status = TheSign ==1 ? 1 : 0;
3037 AIS_ListOfInteractive LIO;
3038 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3039 Handle(AIS_InteractiveObject) curio;
3040 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3042 if(dimension_status == -1)
3043 TheAISContext()->Display(curio,Standard_False);
3045 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3046 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3047 (dimension_status==1 && KOD != AIS_KOD_NONE))
3048 TheAISContext()->Display(curio,Standard_False);
3053 TheAISContext()->UpdateCurrentViewer();
3057 //==============================================================================
3058 //function : VSetTransMode
3060 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3061 //==============================================================================
3063 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3064 // Verification des arguments
3065 if ( a3DView().IsNull() ) {
3066 ViewerTest::ViewerInit();
3067 di << "La commande vinit n'a pas ete appele avant" << "\n";
3070 if ( argc < 3 || argc > 8 ) {
3071 di << argv[0] << " Invalid number of arguments" << "\n";
3075 TCollection_AsciiString shapeName;
3076 shapeName = argv[1];
3077 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3078 Standard_Integer persFlag2 = 0;
3079 Standard_Integer persFlag3 = 0;
3080 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3081 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3082 persFlag2 = Draw::Atoi(argv[3]);
3084 if ( argc == 5 || argc == 8 ) {
3085 persFlag3 = Draw::Atoi(argv[4]);
3088 origin.SetX( Draw::Atof(argv[argc - 3]) );
3089 origin.SetY( Draw::Atof(argv[argc - 2]) );
3090 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3093 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3094 Handle(Standard_Transient) anObj;
3096 anObj = GetMapOfAIS().Find2(shapeName);
3097 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3098 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3099 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3100 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3101 di << argv[0] << " All persistence modifiers were removed" << "\n";
3104 di << argv[0] << " Wrong object type" << "\n";
3107 } else { // Create the AIS_Shape from a name
3108 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3109 if ( !aShape.IsNull() ) {
3110 GetMapOfAIS().Bind( aShape, shapeName );
3111 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3112 TheAISContext()->Display( aShape, Standard_False );
3114 di << argv[0] << " Object not found" << "\n";
3119 // Upadate the screen and redraw the view
3120 TheAISContext()->UpdateCurrentViewer();
3124 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3127 BRep_Builder builder;
3129 BRepTools::Read(shape, s, builder);
3130 DBRep::Set(a[1], shape);
3131 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3132 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3137 //==============================================================================
3138 //function : ViewerTest::Commands
3139 //purpose : Add all the viewer command in the Draw_Interpretor
3140 //==============================================================================
3142 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3144 ViewerTest::ViewerCommands(theCommands);
3145 ViewerTest::RelationCommands(theCommands);
3146 ViewerTest::ObjectCommands(theCommands);
3147 ViewerTest::FilletCommands(theCommands);
3148 ViewerTest::VoxelCommands(theCommands);
3149 ViewerTest::OpenGlCommands(theCommands);
3151 const char *group = "AIS_Display";
3154 theCommands.Add("visos",
3155 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3156 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3157 __FILE__, visos, group);
3159 theCommands.Add("vdisplay",
3160 "vdisplay name1 [name2] ... [name n]"
3161 "\n\t\t: Displays named objects",
3162 __FILE__,VDisplay2,group);
3164 theCommands.Add("verase",
3165 "verase [name1] ... [name n]"
3166 "\n\t\t: Erases selected or named objects."
3167 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3168 __FILE__,VErase2,group);
3170 theCommands.Add("vdonly",
3171 "vdonly [name1] ... [name n]"
3172 "\n\t\t: Displays only selected or named objects",
3173 __FILE__,VDonly2,group);
3175 theCommands.Add("vdisplayall",
3176 "Displays all erased interactive objects (see vdir and vstate)",
3177 __FILE__,VDisplayAll,group);
3179 theCommands.Add("veraseall",
3180 "Erases all objects displayed in the viewer",
3181 __FILE__,VEraseAll,group);
3183 theCommands.Add("verasetype",
3185 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3186 __FILE__,VEraseType,group);
3188 theCommands.Add("vdisplaytype",
3189 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3190 __FILE__,VDisplayType,group);
3192 theCommands.Add("vdisplaymode",
3193 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3194 __FILE__,VDispMode,group);
3196 theCommands.Add("verasemode",
3197 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3198 __FILE__,VDispMode,group);
3200 theCommands.Add("vsetdispmode",
3201 "vsetdispmode [name] mode(1,2,..)"
3202 "\n\t\t: Sets display mode for all, selected or named objects.",
3203 __FILE__,VDispMode,group);
3205 theCommands.Add("vunsetdispmode",
3206 "vunsetdispmode [name]"
3207 "\n\t\t: Unsets custom display mode for selected or named objects.",
3208 __FILE__,VDispMode,group);
3210 theCommands.Add("vdir",
3211 "Lists all objects displayed in 3D viewer",
3212 __FILE__,VDebug,group);
3214 theCommands.Add("vdump",
3215 #ifdef HAVE_FREEIMAGE
3216 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]"
3217 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3219 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height]"
3220 "\n\t\t: Dumps contents of viewer window to PPM image file",
3222 __FILE__,VDump,group);
3224 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3225 __FILE__,VSubInt,group);
3227 theCommands.Add("vsetcolor",
3228 "vsetcolor [name] ColorName"
3229 "\n\t\t: Sets color for all, selected or named objects.",
3230 __FILE__,VColor2,group);
3232 theCommands.Add("vunsetcolor",
3233 "vunsetcolor [name]"
3234 "\n\t\t: Resets color for all, selected or named objects.",
3235 __FILE__,VColor2,group);
3237 theCommands.Add("vsettransparency",
3238 "vsettransparency [name] Coefficient"
3239 "\n\t\t: Sets transparency for all, selected or named objects."
3240 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3241 __FILE__,VTransparency,group);
3243 theCommands.Add("vunsettransparency",
3244 "vunsettransparency [name]"
3245 "\n\t\t: Resets transparency for all, selected or named objects.",
3246 __FILE__,VTransparency,group);
3248 theCommands.Add("vsetmaterial",
3249 "vmaterial : vmaterial [name of shape] MaterialName",
3250 __FILE__,VMaterial,group);
3252 theCommands.Add("vunsetmaterial",
3253 "vmaterial : vmaterial [name of shape]",
3254 __FILE__,VMaterial,group);
3256 theCommands.Add("vsetwidth",
3257 "vsetwidth : vwidth [name of shape] width(0->10)",
3258 __FILE__,VWidth,group);
3260 theCommands.Add("vunsetwidth",
3261 "vunsetwidth : vwidth [name of shape]",
3262 __FILE__,VWidth,group);
3264 theCommands.Add("vsetinteriorstyle",
3265 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3266 __FILE__,VInteriorStyle,group);
3268 theCommands.Add("vardis",
3269 "vardis : display activeareas",
3270 __FILE__,VDispAreas,group);
3272 theCommands.Add("varera",
3273 "varera : erase activeareas",
3274 __FILE__,VClearAreas,group);
3276 theCommands.Add("vsensdis",
3277 "vardisp : display active entities",
3278 __FILE__,VDispSensi,group);
3279 theCommands.Add("vsensera",
3280 "vardisp : erase active entities",
3281 __FILE__,VClearSensi,group);
3283 theCommands.Add("vselprecision",
3284 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3285 __FILE__,VSelPrecision,group);
3287 theCommands.Add("vperf",
3288 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3289 __FILE__,VPerf,group);
3291 theCommands.Add("vanimation",
3292 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3293 __FILE__,VAnimation,group);
3295 theCommands.Add("vsetshading",
3296 "vsetshading : vsetshading name Quality(default=0.0008) ",
3297 __FILE__,VShading,group);
3299 theCommands.Add("vunsetshading",
3300 "vunsetshading :vunsetshading name ",
3301 __FILE__,VShading,group);
3303 theCommands.Add("vtexture",
3304 "'vtexture NameOfShape TextureFile' \n \
3305 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3306 or 'vtexture NameOfShape ?' to list available textures\n \
3307 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3308 __FILE__,VTexture,group);
3310 theCommands.Add("vtexscale",
3311 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3312 or 'vtexscale NameOfShape ScaleUV' \n \
3313 or 'vtexscale NameOfShape' to disable scaling\n ",
3314 __FILE__,VTexture,group);
3316 theCommands.Add("vtexorigin",
3317 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3318 or 'vtexorigin NameOfShape UVOrigin' \n \
3319 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3320 __FILE__,VTexture,group);
3322 theCommands.Add("vtexrepeat",
3323 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3324 or 'vtexrepeat NameOfShape UVRepeat \n \
3325 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3328 theCommands.Add("vtexdefault",
3329 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3332 theCommands.Add("vsetam",
3333 "vsetActivatedModes: vsetam mode(1->7) ",
3334 __FILE__,VActivatedMode,group);
3336 theCommands.Add("vunsetam",
3337 "vunsetActivatedModes: vunsetam ",
3338 __FILE__,VActivatedMode,group);
3340 theCommands.Add("vstate",
3341 "vstate [name1] ... [nameN]"
3342 "\n\t\t: Reports show/hidden state for selected or named objects",
3343 __FILE__,VState,group);
3345 theCommands.Add("vpickshapes",
3346 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3347 __FILE__,VPickShape,group);
3349 theCommands.Add("vtypes",
3350 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3353 theCommands.Add("vsettransmode",
3354 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3355 __FILE__,VSetTransMode,group);
3357 theCommands.Add("vr", "vr : reading of the shape",
3358 __FILE__,vr, group);
3362 //=====================================================================
3363 //========================= for testing Draft and Rib =================
3364 //=====================================================================
3365 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3366 #include <DBRep.hxx>
3367 #include <TopoDS_Face.hxx>
3368 #include <gp_Pln.hxx>
3369 #include <AIS_KindOfSurface.hxx>
3370 #include <BRepOffsetAPI_DraftAngle.hxx>
3371 #include <Precision.hxx>
3372 #include <BRepAlgo.hxx>
3373 #include <OSD_Environment.hxx>
3374 #include <DrawTrSurf.hxx>
3375 //#include <DbgTools.hxx>
3376 //#include <FeatAlgo_MakeLinearForm.hxx>
3381 //=======================================================================
3382 //function : IsValid
3384 //=======================================================================
3385 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3386 const TopoDS_Shape& theResult,
3387 const Standard_Boolean closedSolid,
3388 const Standard_Boolean GeomCtrl)
3390 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3391 TCollection_AsciiString checkValid = check.Value();
3392 Standard_Boolean ToCheck = Standard_True;
3393 if (!checkValid.IsEmpty()) {
3395 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3397 if ( checkValid=="true" || checkValid=="TRUE" ) {
3398 ToCheck= Standard_False;
3402 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3405 Standard_Boolean IsValid = Standard_True;
3407 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3412 //===============================================================================
3413 // TDraft : test draft, uses AIS Viewer
3414 // Solid Face Plane Angle Reverse
3415 //===============================================================================
3416 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3418 if (argc < 5) return 1;
3419 // argv[1] - TopoDS_Shape Solid
3420 // argv[2] - TopoDS_Shape Face
3421 // argv[3] - TopoDS_Shape Plane
3422 // argv[4] - Standard_Real Angle
3423 // argv[5] - Standard_Integer Reverse
3425 // Sprintf(prefix, argv[1]);
3426 Standard_Real anAngle = 0;
3427 Standard_Boolean Rev = Standard_False;
3428 Standard_Integer rev = 0;
3429 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3430 TopoDS_Shape face = GetShapeFromName(argv[2]);
3431 TopoDS_Face Face = TopoDS::Face(face);
3432 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3433 if (Plane.IsNull ()) {
3434 di << "TEST : Plane is NULL" << "\n";
3437 anAngle = Draw::Atof(argv[4]);
3438 anAngle = 2*M_PI * anAngle / 360.0;
3440 Handle( Geom_Surface )aSurf;
3441 AIS_KindOfSurface aSurfType;
3442 Standard_Real Offset;
3444 if(argc > 4) { // == 5
3445 rev = Draw::Atoi(argv[5]);
3446 Rev = (rev)? Standard_True : Standard_False;
3449 TopoDS_Face face2 = TopoDS::Face(Plane);
3450 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3452 di << "TEST : Can't find plane" << "\n";
3456 aDir = aPln.Axis().Direction();
3459 if (Plane.Orientation() == TopAbs_REVERSED)
3461 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3463 BRepOffsetAPI_DraftAngle Draft (Solid);
3465 if(Abs(anAngle)< Precision::Angular()) {
3466 di << "TEST : NULL angle" << "\n";
3469 if(Rev) anAngle = - anAngle;
3470 Draft.Add (Face, aDir, anAngle, aPln);
3472 if (!Draft.IsDone()) {
3473 di << "TEST : Draft Not DONE " << "\n";
3476 TopTools_ListOfShape Larg;
3478 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3479 di << "TEST : DesignAlgo returns Not valid" << "\n";
3483 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3484 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3486 if ( !ais.IsNull() ) {
3487 ais->SetColor(DEFAULT_COLOR);
3488 ais->SetMaterial(DEFAULT_MATERIAL);
3489 // Display the AIS_Shape without redraw
3490 Ctx->Display(ais, Standard_False);
3492 const char *Name = "draft1";
3493 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3495 Handle(AIS_InteractiveObject) an_object =
3496 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3497 if (!an_object.IsNull()) {
3498 Ctx->Remove(an_object,
3500 GetMapOfAIS().UnBind2(Name) ;
3503 GetMapOfAIS().Bind(ais, Name);
3504 // DBRep::Set("draft", ais->Shape());
3506 Ctx->Display(ais, Standard_True);
3512 //============================================================================
3514 //============================================================================
3515 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3518 DrawTrSurf::BasicCommands(theCommands);
3519 const char* group = "Check Features Operations commands";
3521 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3523 &TDraft,group); //Draft_Modification
3526 //==============================================================================
3527 // ViewerTest::Factory
3528 //==============================================================================
3529 void ViewerTest::Factory(Draw_Interpretor& theDI)
3531 // definition of Viewer Command
3532 ViewerTest::Commands(theDI);
3533 ViewerTest::AviCommands(theDI);
3536 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3540 // Declare entry point PLUGINFACTORY