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;
454 TopoDS_Shape S = GetShapeFromName(name);
456 retsh = new AIS_Shape(S);
462 //==============================================================================
464 //purpose : Remove all the object from the viewer
465 //==============================================================================
466 void ViewerTest::Clear()
468 if ( !a3DView().IsNull() ) {
469 if (TheAISContext()->HasOpenedContext())
470 TheAISContext()->CloseLocalContext();
471 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
472 while ( it.More() ) {
473 cout << "Remove " << it.Key2() << endl;
474 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
475 const Handle(AIS_InteractiveObject) anObj =
476 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
477 TheAISContext()->Remove(anObj,Standard_False);
478 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
479 const Handle(NIS_InteractiveObject) anObj =
480 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
481 TheNISContext()->Remove(anObj);
485 TheAISContext()->UpdateCurrentViewer();
486 // TheNISContext()->UpdateViews();
487 GetMapOfAIS().Clear();
491 //==============================================================================
492 //function : StandardModesActivation
493 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
495 //==============================================================================
496 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
498 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
500 if (TheAISContext()->HasOpenedContext())
501 aContext->CloseLocalContext();
504 if(!aContext->HasOpenedContext()) {
505 // To unhilight the preselected object
506 aContext->UnhilightCurrents(Standard_False);
507 // Open a local Context in order to be able to select subshape from
508 // the selected shape if any or for all if there is no selection
509 if (!aContext->FirstCurrentObject().IsNull()){
510 aContext->OpenLocalContext(Standard_False);
512 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
513 aContext->Load( aContext->Current(),-1,Standard_True);
517 aContext->OpenLocalContext();
520 const char *cmode="???";
523 case 0: cmode = "Shape"; break;
524 case 1: cmode = "Vertex"; break;
525 case 2: cmode = "Edge"; break;
526 case 3: cmode = "Wire"; break;
527 case 4: cmode = "Face"; break;
528 case 5: cmode = "Shell"; break;
529 case 6: cmode = "Solid"; break;
530 case 7: cmode = "Compsolid"; break;
531 case 8: cmode = "Compound"; break;
534 if(theactivatedmodes.Contains(mode))
536 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
537 theactivatedmodes.Remove(mode);
538 cout<<"Mode "<< cmode <<" OFF"<<endl;
542 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
543 theactivatedmodes.Add(mode);
544 cout<<"Mode "<< cmode << " ON" << endl;
549 //==============================================================================
550 //function : CopyIsoAspect
551 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
552 //==============================================================================
553 static Handle(Prs3d_IsoAspect) CopyIsoAspect
554 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
555 const Standard_Integer theNbIsos)
557 Quantity_Color aColor;
558 Aspect_TypeOfLine aType;
559 Standard_Real aWidth;
561 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
563 Handle(Prs3d_IsoAspect) aResult =
564 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
569 //==============================================================================
571 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
572 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
573 //==============================================================================
574 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
576 if (TheAISContext().IsNull()) {
577 di << argv[0] << " Call 'vinit' before!\n";
582 di << "Current number of isos : " <<
583 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
584 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
585 di << "IsoOnPlane mode is " <<
586 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
591 Standard_Integer aLastInd = argc - 1;
592 Standard_Boolean isChanged = Standard_False;
593 Standard_Integer aNbUIsos;
594 Standard_Integer aNbVIsos;
597 Standard_Boolean isIsoOnPlane = Standard_False;
599 if (strcmp(argv[aLastInd], "1") == 0) {
600 isIsoOnPlane = Standard_True;
601 isChanged = Standard_True;
602 } else if (strcmp(argv[aLastInd], "0") == 0) {
603 isIsoOnPlane = Standard_False;
604 isChanged = Standard_True;
608 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
609 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
612 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
613 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
615 TheAISContext()->IsoOnPlane(isIsoOnPlane);
618 // If there are no shapes provided set the default numbers.
619 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
620 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
627 for (i = 1; i <= aLastInd; i++) {
628 TCollection_AsciiString name(argv[i]);
629 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
632 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
633 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
634 const Handle(AIS_InteractiveObject) aShape =
635 Handle(AIS_InteractiveObject)::DownCast (anObj);
636 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
637 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
638 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
641 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
642 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
643 TheAISContext()->SetLocalAttributes
644 (aShape, CurDrawer, Standard_False);
645 TheAISContext()->Redisplay(aShape);
647 di << "Number of isos for " << argv[i] << " : "
648 << aUIso->Number() << " " << aVIso->Number() << "\n";
651 di << argv[i] << ": Not an AIS interactive object!\n";
654 di << argv[i] << ": Use 'vdisplay' before\n";
659 TheAISContext()->UpdateCurrentViewer();
665 //==============================================================================
666 //function : VDispAreas,VDispSensitive,...
667 //purpose : Redraw the view
669 //==============================================================================
670 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
673 Handle(AIS_InteractiveContext) Ctx;
674 Handle(V3d_View) Viou;
675 GetCtxAndView(Ctx,Viou);
676 Ctx->DisplayActiveAreas(Viou);
679 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
681 Handle(AIS_InteractiveContext) Ctx;
682 Handle(V3d_View) Viou;
683 GetCtxAndView(Ctx,Viou);
684 Ctx->ClearActiveAreas(Viou);
688 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
690 Handle(AIS_InteractiveContext) Ctx;
691 Handle(V3d_View) Viou;
692 GetCtxAndView(Ctx,Viou);
693 Ctx->DisplayActiveSensitive(Viou);
697 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
699 Handle(AIS_InteractiveContext) Ctx;
700 Handle(V3d_View) Viou;
701 GetCtxAndView(Ctx,Viou);
702 Ctx->ClearActiveSensitive(Viou);
706 //==============================================================================
708 //purpose : To list the displayed object with their attributes
710 //==============================================================================
711 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
712 { if ( !a3DView().IsNull() ) {
713 di << "List of object in the viewer :" << "\n";
715 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
717 while ( it.More() ) {
718 di << "\t" << it.Key2().ToCString() << "\n";
726 //==============================================================================
727 //function : VSelPrecision
728 //purpose : To set the selection precision mode and tolerance value
729 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
730 // value (integer number of pixel for window mode, double value of
731 // sensitivity for view mode). Without arguments the function just
732 // prints the current precision mode and the corresponding tolerance.
733 //==============================================================================
734 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
738 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
742 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
743 if( aContext.IsNull() )
748 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
749 if( aMode == StdSelect_SM_WINDOW )
751 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
752 di << "Precision mode : 0 (window)\n";
753 di << "Pixel tolerance : " << aPixelTolerance << "\n";
755 else if( aMode == StdSelect_SM_VIEW )
757 Standard_Real aSensitivity = aContext->Sensitivity();
758 di << "Precision mode : 1 (view)\n";
759 di << "Sensitivity : " << aSensitivity << "\n";
764 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
765 aContext->SetSensitivityMode( aMode );
768 if( aMode == StdSelect_SM_WINDOW )
770 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
771 aContext->SetPixelTolerance( aPixelTolerance );
773 else if( aMode == StdSelect_SM_VIEW )
775 Standard_Real aSensitivity = Draw::Atof( argv[2] );
776 aContext->SetSensitivity( aSensitivity );
783 //==============================================================================
785 //purpose : To dump the active view snapshot to image file
786 //Draw arg : Picture file name with extension corresponding to desired format
787 //==============================================================================
788 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
792 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
796 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
799 const char* aBuffTypeStr = argv[2];
800 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
802 aBufferType = Graphic3d_BT_RGB;
804 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
806 aBufferType = Graphic3d_BT_RGBA;
808 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
810 aBufferType = Graphic3d_BT_Depth;
814 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
815 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
817 Handle(AIS_InteractiveContext) IC;
818 Handle(V3d_View) view;
819 GetCtxAndView (IC, view);
822 di << "Cannot find an active viewer/view\n";
826 if (aWidth <= 0 || aHeight <= 0)
828 if (!view->Dump (argv[1], aBufferType))
830 di << "Dumping failed!\n";
836 Image_AlienPixMap aPixMap;
837 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
839 di << "Dumping failed!\n";
843 if (aPixMap.SizeX() != Standard_Size(aWidth)
844 || aPixMap.SizeY() != Standard_Size(aHeight))
846 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
847 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
849 if (!aPixMap.Save (argv[1]))
851 di << "Saving image failed!\n";
858 //==============================================================================
859 //function : Displays,Erase...
862 //==============================================================================
863 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
864 const Standard_Integer Mode,
865 const Standard_Integer TypeOfOperation,
866 const Standard_Boolean Upd)
868 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
870 switch(TypeOfOperation){
872 Ctx->Display(IO,Mode,Upd);
875 Ctx->Erase(IO,Mode,Upd);
880 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
882 Ctx->SetDisplayMode(IO,Mode,Upd);
887 Ctx->SetDisplayMode(0,Upd);
889 Ctx->UnsetDisplayMode(IO,Upd);
896 //=======================================================================
899 //=======================================================================
900 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
903 TCollection_AsciiString name;
906 // display others presentations
907 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
908 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
909 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
910 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
912 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
914 //unset displaymode.. comportement particulier...
915 if(TypeOfOperation==4){
917 if(Ctx->NbCurrents()==0 ||
918 Ctx->NbSelected()==0){
919 Handle(AIS_InteractiveObject) IO;
920 VwrTst_DispErase(IO,-1,4,Standard_False);
922 else if(!Ctx->HasOpenedContext()){
923 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
924 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
927 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
928 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
929 Ctx->UpdateCurrentViewer();
932 Handle(AIS_InteractiveObject) IO;
934 if(GetMapOfAIS().IsBound2(name)){
935 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
937 VwrTst_DispErase(IO,-1,4,Standard_True);
942 Standard_Integer Dmode = Draw::Atoi(argv[1]);
943 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
944 Handle(AIS_InteractiveObject) IO;
945 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
947 if(!Ctx->HasOpenedContext()){
948 // set/unset display mode sur le Contexte...
949 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
950 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
952 Ctx->UpdateCurrentViewer();
955 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
956 Ctx->Display(Ctx->Interactive(),Dmode);
960 Handle(AIS_InteractiveObject) IO;
962 if(GetMapOfAIS().IsBound2(name))
963 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
965 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
971 //=======================================================================
974 //=======================================================================
975 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
977 if(argc==1) return 1;
978 Standard_Integer On = Draw::Atoi(argv[1]);
979 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
983 if(!Ctx->HasOpenedContext()){
984 di<<"sub intensite ";
987 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
988 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
990 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
992 di <<"passage dans off"<<"\n";
993 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
998 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1000 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1002 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1005 Ctx->UpdateCurrentViewer();
1008 Handle(AIS_InteractiveObject) IO;
1009 TCollection_AsciiString name = argv[2];
1010 if(GetMapOfAIS().IsBound2(name)){
1011 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1014 Ctx->SubIntensityOn(IO);
1016 Ctx->SubIntensityOff(IO);
1024 //==============================================================================
1025 //function : VColor2
1027 //purpose : change the color of a selected or named or displayed shape
1028 //Draw arg : vcolor2 [name] color
1029 //==============================================================================
1030 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1033 Standard_Boolean ThereIsCurrent;
1034 Standard_Boolean ThereIsArgument;
1035 Standard_Boolean IsBound = Standard_False ;
1037 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1039 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1040 ThereIsArgument = (argc != 2);
1043 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1044 ThereIsArgument = (argc == 2);
1047 if ( !a3DView().IsNull() ) {
1048 TCollection_AsciiString name;
1049 if (ThereIsArgument) {
1051 IsBound= GetMapOfAIS().IsBound2(name);
1053 if (TheAISContext()->HasOpenedContext())
1054 TheAISContext()->CloseLocalContext();
1056 // On set le Booleen There is current
1057 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1058 else ThereIsCurrent =Standard_False;
1060 //=======================================================================
1061 // Il y a un argument
1062 //=======================================================================
1063 if ( ThereIsArgument && IsBound ) {
1064 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1065 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1066 Handle(AIS_InteractiveObject) ashape =
1067 Handle(AIS_InteractiveObject)::DownCast (anObj);
1070 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1072 di << "HaveToSet 0\n";
1076 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1078 TheAISContext()->UnsetColor(ashape);
1079 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1080 Handle(NIS_Triangulated) ashape =
1081 Handle(NIS_Triangulated)::DownCast (anObj);
1082 if (!ashape.IsNull())
1083 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1088 //=======================================================================
1089 // Il n'y a pas d'arguments
1090 // Mais un ou plusieurs objets on des current representation
1091 //=======================================================================
1092 if (ThereIsCurrent && !ThereIsArgument) {
1093 for (TheAISContext() -> InitCurrent() ;
1094 TheAISContext() -> MoreCurrent() ;
1095 TheAISContext() ->NextCurrent() )
1097 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1098 if (ashape.IsNull())
1102 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1104 di << "HaveToSet 0\n";
1107 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1109 TheAISContext()->UnsetColor(ashape,Standard_False);
1112 TheAISContext()->UpdateCurrentViewer();
1115 //=======================================================================
1116 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1117 // on impose a tous les objets du viewer la couleur passee
1118 //=======================================================================
1119 else if (!ThereIsCurrent && !ThereIsArgument){
1120 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1121 while ( it.More() ) {
1122 const Handle(AIS_InteractiveObject) ashape =
1123 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1124 if (!ashape.IsNull())
1126 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1128 TheAISContext()->UnsetColor(ashape,Standard_False);
1131 TheAISContext()->UpdateCurrentViewer();
1137 //==============================================================================
1138 //function : VTransparency
1140 //purpose : change the transparency of a selected or named or displayed shape
1141 //Draw arg : vtransparency [name] TransparencyCoeficient
1142 //==============================================================================
1144 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1147 Standard_Boolean ThereIsCurrent;
1148 Standard_Boolean ThereIsArgument;
1149 Standard_Boolean IsBound = Standard_False ;
1151 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1153 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1154 ThereIsArgument = (argc != 2);
1157 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1158 ThereIsArgument = (argc == 2);
1161 if ( !a3DView().IsNull() ) {
1162 TCollection_AsciiString name;
1163 if (ThereIsArgument) {
1165 IsBound= GetMapOfAIS().IsBound2(name);
1167 if (TheAISContext()->HasOpenedContext())
1168 TheAISContext()->CloseLocalContext();
1170 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1171 else ThereIsCurrent = Standard_False;
1173 //=======================================================================
1174 // Il y a des arguments: un nom et une couleur
1175 //=======================================================================
1176 if ( ThereIsArgument && IsBound ) {
1177 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1178 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1179 const Handle(AIS_InteractiveObject) ashape =
1180 Handle(AIS_InteractiveObject)::DownCast(anObj);
1182 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1184 TheAISContext()->UnsetTransparency(ashape);
1185 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1186 const Handle(NIS_InteractiveObject) ashape =
1187 Handle(NIS_InteractiveObject)::DownCast(anObj);
1189 ashape->SetTransparency(Draw::Atof(argv[2]) );
1191 ashape->UnsetTransparency();
1194 //=======================================================================
1195 // Il n'y a pas d'arguments
1196 // Mais un ou plusieurs objets on des current representation
1197 //=======================================================================
1198 if (ThereIsCurrent && !ThereIsArgument) {
1199 for (TheAISContext() -> InitCurrent() ;
1200 TheAISContext() -> MoreCurrent() ;
1201 TheAISContext() ->NextCurrent() )
1203 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1205 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1207 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1210 TheAISContext()->UpdateCurrentViewer();
1212 //=======================================================================
1213 // Il n'y a pas d'arguments ET aucun objet courrant
1214 //=======================================================================
1215 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1216 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1218 while ( it.More() ) {
1219 Handle(AIS_InteractiveObject) ashape =
1220 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1221 if (!ashape.IsNull())
1223 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1225 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1228 TheAISContext()->UpdateCurrentViewer();
1235 //==============================================================================
1236 //function : VMaterial
1238 //purpose : change the Material of a selected or named or displayed shape
1239 //Draw arg : vmaterial [Name] Material
1240 //==============================================================================
1241 static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1244 Standard_Boolean ThereIsCurrent;
1245 Standard_Boolean ThereIsName;
1246 Standard_Boolean IsBound = Standard_False ;
1248 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
1250 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1251 ThereIsName = (argc != 2);
1254 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
1255 ThereIsName = (argc == 2);
1258 if ( !a3DView().IsNull() ) {
1259 TCollection_AsciiString name;
1262 IsBound= GetMapOfAIS().IsBound2(name);
1264 if (TheAISContext()->HasOpenedContext())
1265 TheAISContext()->CloseLocalContext();
1266 if (TheAISContext() -> NbCurrents() > 0 )
1267 ThereIsCurrent =Standard_True;
1269 ThereIsCurrent =Standard_False;
1271 //=======================================================================
1272 // Ther is a name of shape and a material name
1273 //=======================================================================
1274 if ( ThereIsName && IsBound ) {
1275 Handle(AIS_InteractiveObject) ashape =
1276 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
1277 if (!ashape.IsNull())
1279 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
1281 TheAISContext()->UnsetMaterial(ashape);
1283 //=======================================================================
1284 // Il n'y a pas de nom de shape
1285 // Mais un ou plusieurs objets on des current representation
1286 //=======================================================================
1287 if (ThereIsCurrent && !ThereIsName) {
1288 for (TheAISContext() -> InitCurrent() ;
1289 TheAISContext() -> MoreCurrent() ;
1290 TheAISContext() ->NextCurrent() )
1292 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1294 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1296 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1298 TheAISContext()->UpdateCurrentViewer();
1301 //=======================================================================
1302 // Il n'y a pas de noms de shape ET aucun objet courrant
1303 // On impose a tous les objets du viewer le material passe en argument
1304 //=======================================================================
1305 else if (!ThereIsCurrent && !ThereIsName){
1306 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1308 while ( it.More() ) {
1309 Handle(AIS_InteractiveObject) ashape =
1310 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1311 if (!ashape.IsNull())
1313 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1315 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1318 TheAISContext()->UpdateCurrentViewer();
1326 //==============================================================================
1329 //purpose : change the width of the edges of a selected or named or displayed shape
1330 //Draw arg : vwidth [Name] WidthValue(1->10)
1331 //==============================================================================
1332 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1335 Standard_Boolean ThereIsCurrent;
1336 Standard_Boolean ThereIsArgument;
1337 Standard_Boolean IsBound = Standard_False ;
1339 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1341 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1342 ThereIsArgument = (argc != 2);
1345 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1346 ThereIsArgument = (argc == 2);
1348 if ( !a3DView().IsNull() ) {
1349 TCollection_AsciiString name;
1350 if (ThereIsArgument) {
1352 IsBound= GetMapOfAIS().IsBound2(name);
1354 if (TheAISContext()->HasOpenedContext())
1355 TheAISContext()->CloseLocalContext();
1357 if (TheAISContext() -> NbCurrents() > 0 )
1358 ThereIsCurrent =Standard_True;
1360 ThereIsCurrent =Standard_False;
1362 if ( ThereIsArgument && IsBound ) {
1363 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1364 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1365 const Handle(AIS_InteractiveObject) ashape =
1366 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1368 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1370 TheAISContext()->UnsetWidth (ashape);
1371 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1372 const Handle(NIS_Triangulated) ashape =
1373 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1374 if (HaveToSet && !ashape.IsNull())
1375 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1379 //=======================================================================
1380 // Il n'y a pas d'arguments
1381 // Mais un ou plusieurs objets on des current representation
1382 //=======================================================================
1383 if (ThereIsCurrent && !ThereIsArgument) {
1384 for (TheAISContext() -> InitCurrent() ;
1385 TheAISContext() -> MoreCurrent() ;
1386 TheAISContext() ->NextCurrent() )
1388 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1390 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1392 TheAISContext()->UnsetWidth(ashape,Standard_False);
1394 TheAISContext()->UpdateCurrentViewer();
1396 //=======================================================================
1397 // Il n'y a pas d'arguments ET aucun objet courrant
1398 //=======================================================================
1399 else if (!ThereIsCurrent && !ThereIsArgument){
1400 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1402 while ( it.More() ) {
1403 Handle(AIS_InteractiveObject) ashape =
1404 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1405 if (!ashape.IsNull())
1407 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1409 TheAISContext()->UnsetWidth(ashape,Standard_False);
1412 TheAISContext()->UpdateCurrentViewer();
1418 //==============================================================================
1419 //function : VInteriorStyle
1420 //purpose : sets interior style of the a selected or named or displayed shape
1421 //Draw arg : vsetinteriorstyle [shape] style
1422 //==============================================================================
1423 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1424 const Standard_Integer theStyle,
1425 Draw_Interpretor& di)
1427 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1428 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1429 " (Aspect_IS_HIDDENLINE)]\n";
1432 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1433 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1434 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1435 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1436 aFillAspect->SetInteriorStyle (aStyle);
1437 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1440 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1442 if (argc < 2 || argc > 3) {
1443 di << argv[0] << " requires 2 or 3 arguments\n";
1444 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1445 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1446 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1450 Standard_Boolean ThereIsCurrent;
1451 Standard_Boolean ThereIsArgument;
1452 Standard_Boolean IsBound = Standard_False ;
1454 ThereIsArgument = (argc > 2);
1455 if ( !a3DView().IsNull() ) {
1456 TCollection_AsciiString name;
1457 if (ThereIsArgument) {
1459 IsBound= GetMapOfAIS().IsBound2(name);
1461 if (TheAISContext()->HasOpenedContext())
1462 TheAISContext()->CloseLocalContext();
1464 if (TheAISContext() -> NbCurrents() > 0 )
1465 ThereIsCurrent =Standard_True;
1467 ThereIsCurrent =Standard_False;
1469 if ( ThereIsArgument && IsBound ) {
1470 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1471 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1472 const Handle(AIS_InteractiveObject) ashape =
1473 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1474 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1477 //=======================================================================
1478 // No arguments specified
1479 // But there are one or more selected objects
1480 //=======================================================================
1481 if (ThereIsCurrent && !ThereIsArgument) {
1482 for (TheAISContext() -> InitCurrent() ;
1483 TheAISContext() -> MoreCurrent() ;
1484 TheAISContext() ->NextCurrent() )
1486 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1487 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1490 //=======================================================================
1491 // No arguments specified and there are no selected objects
1492 //=======================================================================
1493 else if (!ThereIsCurrent && !ThereIsArgument){
1494 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1496 while ( it.More() ) {
1497 Handle(AIS_InteractiveObject) ashape =
1498 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1499 if (!ashape.IsNull())
1500 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1504 TheAISContext()->UpdateCurrentViewer();
1509 //==============================================================================
1510 //function : VDonly2
1512 //purpose : Display only a selected or named object
1513 // if there is no selected or named object s, nothing is donne
1514 //Draw arg : vdonly2 [name1] ... [name n]
1515 //==============================================================================
1516 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1519 if ( a3DView().IsNull() )
1522 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1523 Standard_Boolean ThereIsArgument= argc>1;
1525 if (TheAISContext()->HasOpenedContext())
1526 TheAISContext()->CloseLocalContext();
1528 //===============================================================
1529 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1531 //===============================================================
1532 if (!ThereIsArgument && ThereIsCurrent) {
1535 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1538 for(TheAISContext()->InitCurrent();
1539 TheAISContext()->MoreCurrent();
1540 TheAISContext()->NextCurrent()){
1541 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1542 TheAISContext()->Erase(aShape,Standard_False);}
1544 TheAISContext() ->UpdateCurrentViewer();
1545 //===============================================================
1546 // Il y a des arguments
1547 //===============================================================
1548 if (ThereIsArgument) {
1549 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1551 while ( it.More() ) {
1552 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1553 const Handle(AIS_InteractiveObject) aShape =
1554 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1555 TheAISContext()->Erase(aShape,Standard_False);
1556 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1557 const Handle(NIS_InteractiveObject) aShape =
1558 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1559 TheNISContext()->Erase(aShape);
1564 // On display les objets passes par parametre
1565 for (int i=1; i<argc ; i++) {
1566 TCollection_AsciiString name=argv[i];
1567 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1569 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1570 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1571 const Handle(AIS_InteractiveObject) aShape =
1572 Handle(AIS_InteractiveObject)::DownCast (anObj);
1573 TheAISContext()->Display(aShape, Standard_False);
1574 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1575 Handle(NIS_InteractiveObject) aShape =
1576 Handle(NIS_InteractiveObject)::DownCast (anObj);
1577 TheNISContext()->Display(aShape);
1581 TheAISContext() ->UpdateCurrentViewer();
1582 // TheNISContext() ->UpdateViews();
1587 //==============================================================================
1588 //function : VErase2
1590 //purpose : Erase some selected or named objects
1591 // if there is no selected or named objects, the whole viewer is erased
1592 //Draw arg : verase2 [name1] ... [name n]
1593 //==============================================================================
1594 static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1597 if ( a3DView().IsNull() )
1600 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1601 Standard_Boolean ThereIsArgument= argc>1;
1602 if(TheAISContext()->HasOpenedContext())
1603 TheAISContext()->CloseLocalContext();
1605 //===============================================================
1606 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1608 //===============================================================
1609 if (!ThereIsArgument && ThereIsCurrent) {
1610 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1612 while ( it.More() ) {
1613 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1614 const Handle(AIS_InteractiveObject) aShape =
1615 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1616 if (TheAISContext()->IsCurrent(aShape))
1617 TheAISContext()->Erase(aShape,Standard_False);
1622 TheAISContext() ->UpdateCurrentViewer();
1625 //===============================================================
1626 // Il n'y a pas d'arguments et aucuns objets selectionnes
1628 // On erase tout le viewer
1629 //===============================================================
1631 if (!ThereIsArgument && !ThereIsCurrent) {
1632 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
1633 while ( it.More() ) {
1634 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1635 const Handle(AIS_InteractiveObject) aShape =
1636 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1637 TheAISContext()->Erase(aShape,Standard_False);
1638 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1639 const Handle(NIS_InteractiveObject) aShape =
1640 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1641 TheNISContext()->Erase(aShape);
1645 TheAISContext() ->UpdateCurrentViewer();
1646 // TheNISContext()->UpdateViews();
1649 //===============================================================
1650 // Il y a des arguments
1651 //===============================================================
1652 if (ThereIsArgument) {
1653 for (int i=1; i<argc ; i++) {
1654 TCollection_AsciiString name=argv[i];
1655 Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
1657 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1658 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1659 const Handle(AIS_InteractiveObject) aShape =
1660 Handle(AIS_InteractiveObject)::DownCast (anObj);
1661 TheAISContext()->Erase(aShape,Standard_False);
1662 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1663 const Handle(NIS_InteractiveObject) aShape =
1664 Handle(NIS_InteractiveObject)::DownCast (anObj);
1665 TheNISContext()->Erase(aShape);
1669 TheAISContext() ->UpdateCurrentViewer();
1670 // TheNISContext() ->UpdateViews();
1675 //==============================================================================
1676 //function : VEraseAll
1678 //purpose : Erase all the objects displayed in the viewer
1679 //Draw arg : veraseall
1680 //==============================================================================
1681 static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1684 // Verification des arguments
1685 if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
1686 if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
1687 TheAISContext()->CloseAllContexts(Standard_False);
1688 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1690 while ( it.More() ) {
1691 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1692 const Handle(AIS_InteractiveObject) aShape =
1693 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1694 TheAISContext()->Erase(aShape,Standard_False);
1695 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1696 const Handle(NIS_InteractiveObject) aShape =
1697 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1698 TheNISContext()->Erase(aShape);
1702 TheAISContext() ->UpdateCurrentViewer();
1703 // TheNISContext() ->UpdateViews();
1708 //==============================================================================
1709 //function : VDisplayAll
1711 //purpose : Display all the objects of the Map
1712 //Draw arg : vdisplayall
1713 //==============================================================================
1714 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1717 if (! a3DView().IsNull() ) {
1718 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1719 if (TheAISContext()->HasOpenedContext())
1720 TheAISContext()->CloseLocalContext();
1721 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1723 while ( it.More() ) {
1724 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1725 const Handle(AIS_InteractiveObject) aShape =
1726 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1727 TheAISContext()->Erase(aShape,Standard_False);
1728 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1729 const Handle(NIS_InteractiveObject) aShape =
1730 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1731 TheNISContext()->Erase(aShape);
1736 while ( it.More() ) {
1737 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1738 const Handle(AIS_InteractiveObject) aShape =
1739 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1740 TheAISContext()->Display(aShape, Standard_False);
1741 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1742 Handle(NIS_InteractiveObject) aShape =
1743 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1744 TheNISContext()->Display(aShape);
1748 TheAISContext() ->UpdateCurrentViewer();
1749 // TheNISContext() ->UpdateViews();
1754 //#######################################################################################################
1758 //#######################################################################################################
1760 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1762 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1763 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1764 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1765 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1766 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1768 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1769 if(myAISContext.IsNull())
1771 di << "use 'vinit' command before " << argv[0] << "\n";
1775 Handle(AIS_InteractiveObject) TheAisIO;
1776 Handle(AIS_TexturedShape) myShape;
1777 Standard_Integer myPreviousMode = 0;
1779 if (argc<2 || !argv[1])
1781 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1785 TCollection_AsciiString name = argv[1];
1786 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1788 if (GetMapOfAIS().IsBound2(name))
1789 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1790 (GetMapOfAIS().Find2(name));
1791 if (TheAisIO.IsNull())
1793 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1797 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1799 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1800 myPreviousMode = myShape->DisplayMode() ;
1804 myAISContext->Clear(TheAisIO,Standard_False);
1805 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1806 GetMapOfAIS().UnBind1(TheAisIO);
1807 GetMapOfAIS().UnBind2(name);
1808 GetMapOfAIS().Bind(myShape, name);
1812 case 1: // vtexture : we only map a texture on the shape
1815 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1818 if (argc>2 && argv[2])
1820 if(strcasecmp(argv[2],"?")==0)
1822 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1823 di<<"\n Files in current directory : \n"<<"\n";
1824 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1825 di.Eval(Cmnd.ToCString());
1827 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1830 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1831 di.Eval(Cmnd.ToCString());
1836 myShape->SetTextureFileName(argv[2]);
1840 di <<"Texture mapping disabled \n \
1841 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1843 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1844 if (myPreviousMode == 3 )
1845 myAISContext->RecomputePrsOnly(myShape);
1846 myAISContext->Display(myShape, Standard_True);
1851 case 2: // vtexscale : we change the scaling factor of the texture
1855 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1859 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1860 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1861 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1864 case 3: // vtexorigin : we change the origin of the texture on the shape
1867 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1870 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1871 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1872 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
1875 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1878 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1881 if (argc>2 && argv[2])
1883 di <<"Texture repeat enabled"<<"\n";
1884 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
1888 di <<"Texture repeat disabled"<<"\n";
1889 myShape->SetTextureRepeat(Standard_False);
1893 case 5: // vtexdefault : default texture mapping
1894 // ScaleU = ScaleV = 100.0
1895 // URepeat = VRepeat = 1.0
1896 // Uorigin = VOrigin = 0.0
1900 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1903 myShape->SetTextureRepeat(Standard_False);
1904 myShape->SetTextureOrigin(Standard_False);
1905 myShape->SetTextureScale (Standard_False);
1909 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
1910 myAISContext->RecomputePrsOnly(myShape);
1913 myAISContext->SetDisplayMode(myShape,3,Standard_False);
1914 myAISContext->Display(myShape, Standard_True);
1915 myAISContext->Update(myShape,Standard_True);
1920 //==============================================================================
1921 //function : VDisplay2
1923 //purpose : Display an object from its name
1924 //Draw arg : vdisplay name1 [name2] ... [name n]
1925 //==============================================================================
1926 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1929 // Verification des arguments
1930 if ( a3DView().IsNull() ) {
1932 ViewerTest::ViewerInit();
1933 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
1938 di<<argv[0]<<" Syntaxe error"<<"\n";
1943 TCollection_AsciiString name;
1944 if (TheAISContext()->HasOpenedContext())
1945 TheAISContext()->CloseLocalContext();
1947 for ( int i = 1; i < argc; i++ ) {
1949 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1950 Standard_Boolean IsDatum = Standard_False;
1951 Handle(Standard_Transient) anObj;
1953 anObj = GetMapOfAIS().Find2(name);
1954 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1955 Handle(AIS_InteractiveObject) aShape =
1956 Handle(AIS_InteractiveObject)::DownCast(anObj);
1957 if (aShape->Type()==AIS_KOI_Datum) {
1958 IsDatum = Standard_True;
1959 TheAISContext()->Display(aShape, Standard_False);
1962 di << "Display " << name.ToCString() << "\n";
1963 // Get the Shape from a name
1964 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
1966 // Update the Shape in the AIS_Shape
1967 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
1968 if(!TheRealSh.IsNull())
1969 TheRealSh->Set(NewShape);
1970 TheAISContext()->Redisplay(aShape, Standard_False);
1971 TheAISContext()->Display(aShape, Standard_False);
1974 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1975 Handle(NIS_InteractiveObject) aShape =
1976 Handle(NIS_InteractiveObject)::DownCast(anObj);
1977 TheNISContext()->Display(aShape);
1980 else { // Create the AIS_Shape from a name
1981 const Handle(AIS_InteractiveObject) aShape =
1982 GetAISShapeFromName((const char *)name.ToCString());
1983 if ( !aShape.IsNull() ) {
1984 GetMapOfAIS().Bind(aShape, name);
1985 TheAISContext()->Display(aShape, Standard_False);
1989 // Upadate the screen and redraw the view
1990 TheAISContext()->UpdateCurrentViewer();
1991 // TheNISContext()->UpdateViews();
1995 //==============================================================================
1997 //purpose : Test the annimation of an object along a
1998 // predifined trajectory
1999 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2000 //==============================================================================
2002 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2005 if (TheAISContext()->HasOpenedContext())
2006 TheAISContext()->CloseLocalContext();
2008 Standard_Real Step=4*M_PI/180;
2009 Standard_Real Angle=0;
2011 Handle(AIS_InteractiveObject) aIO;
2012 if (GetMapOfAIS().IsBound2(argv[1]))
2013 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2017 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2021 if (Draw::Atoi(argv[3])==1 ) {
2022 di<<" Primitives sensibles OFF"<<"\n";
2023 TheAISContext()->Deactivate(aIO);
2026 di<<" Primitives sensibles ON"<<"\n";
2028 // Movement par transformation
2029 if(Draw::Atoi(argv[2]) ==1) {
2030 di<<" Calcul par Transformation"<<"\n";
2031 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2035 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2036 TheAISContext()->SetLocation(aShape,myTransfo);
2037 TheAISContext() ->UpdateCurrentViewer();
2042 di<<" Calcul par Locations"<<"\n";
2043 gp_Trsf myAngleTrsf;
2044 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2045 TopLoc_Location myDeltaAngle (myAngleTrsf);
2046 TopLoc_Location myTrueLoc;
2048 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2051 myTrueLoc=myTrueLoc*myDeltaAngle;
2052 TheAISContext()->SetLocation(aShape,myTrueLoc );
2053 TheAISContext() ->UpdateCurrentViewer();
2056 if (Draw::Atoi(argv[3])==1 ){
2057 // On reactive la selection des primitives sensibles
2058 TheAISContext()->Activate(aIO,0);
2060 a3DView() -> Redraw();
2062 di<<" Temps ecoule "<<"\n";
2068 //==================================================================================
2069 // Function : VAnimation
2070 //==================================================================================
2071 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2073 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2077 Standard_Real thread = 4;
2078 Standard_Real angleA=0;
2079 Standard_Real angleB;
2081 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2084 TopoDS_Shape CrankArm;
2085 TopoDS_Shape CylinderHead;
2086 TopoDS_Shape Propeller;
2087 TopoDS_Shape EngineBlock;
2089 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2090 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2091 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2092 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2093 BRepTools::Read(CrankArm,argv[1],B);
2094 BRepTools::Read(CylinderHead,argv[2],B);
2095 BRepTools::Read(Propeller,argv[3],B);
2096 BRepTools::Read(EngineBlock,argv[4],B);
2098 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2104 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2105 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2106 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2107 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2109 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2110 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2111 GetMapOfAIS().Bind(myAisCrankArm,"c");
2112 GetMapOfAIS().Bind(myAisPropeller,"d");
2114 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2115 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2116 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2118 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2119 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2120 TheAISContext()->Display(myAisCrankArm,Standard_False );
2121 TheAISContext()->Display(myAisPropeller,Standard_False);
2123 TheAISContext()->Deactivate(myAisCylinderHead);
2124 TheAISContext()->Deactivate(myAisEngineBlock );
2125 TheAISContext()->Deactivate(myAisCrankArm );
2126 TheAISContext()->Deactivate(myAisPropeller );
2128 // Boucle de mouvement
2129 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2131 angleA = thread*myAngle*M_PI/180;
2132 X = Sin(angleA)*3/8;
2133 angleB = atan(X / Sqrt(-X * X + 1));
2134 Standard_Real decal(25*0.6);
2137 //Build a transformation on the display
2138 gp_Trsf aPropellerTrsf;
2139 aPropellerTrsf.SetRotation(Ax1,angleA);
2140 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2142 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));
2143 gp_Trsf aCrankArmTrsf;
2144 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2145 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2147 TheAISContext()->UpdateCurrentViewer();
2150 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2151 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2153 myAisCrankArm ->ResetLocation();
2154 myAisPropeller->ResetLocation();
2156 myAisCrankArm -> Set(myNewCrankArm );
2157 myAisPropeller -> Set(myNewPropeller);
2159 TheAISContext()->Activate(myAisCylinderHead,0);
2160 TheAISContext()->Activate(myAisEngineBlock,0 );
2161 TheAISContext()->Activate(myAisCrankArm ,0 );
2162 TheAISContext()->Activate(myAisPropeller ,0 );
2168 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2169 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2171 TheAISContext()->UpdateCurrentViewer();
2172 a3DView()->Redraw();
2181 //==============================================================================
2182 //function : VShading
2183 //purpose : Sharpen or roughten the quality of the shading
2184 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2185 //==============================================================================
2186 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2188 Standard_Real myDevCoef;
2189 Handle(AIS_InteractiveObject) TheAisIO;
2192 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2194 if (TheAISContext()->HasOpenedContext())
2195 TheAISContext()->CloseLocalContext();
2200 myDevCoef =Draw::Atof(argv[2]);
2203 TCollection_AsciiString name=argv[1];
2204 if (GetMapOfAIS().IsBound2(name ))
2205 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2206 if (TheAisIO.IsNull())
2207 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2210 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2212 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2214 TheAISContext()->Redisplay(TheAisIO);
2217 //==============================================================================
2218 //function : HaveMode
2219 //use : VActivatedModes
2220 //==============================================================================
2221 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2223 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2225 TColStd_ListOfInteger List;
2226 TheAISContext()->ActivatedModes (TheAisIO,List);
2227 TColStd_ListIteratorOfListOfInteger it;
2228 Standard_Boolean Found=Standard_False;
2229 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2230 if (it.Value()==mode ) Found=Standard_True;
2237 //==============================================================================
2238 //function : VActivatedMode
2240 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2241 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2242 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2243 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2244 // qu'un nom et qu'un mode.
2245 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2246 //==============================================================================
2247 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2249 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2252 Standard_Boolean ThereIsName = Standard_False ;
2254 if(!a3DView().IsNull()){
2256 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2257 // verification des arguments
2259 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2260 ThereIsName = (argc == 3);
2264 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2266 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2267 di<<" Fermeture du Context local"<<"\n";
2268 if (TheAISContext()->HasOpenedContext())
2269 TheAISContext()->CloseLocalContext();
2273 // IL n'y a aps de nom de shape passe en argument
2274 if (HaveToSet && !ThereIsName){
2275 Standard_Integer aMode=Draw::Atoi(argv [1]);
2277 const char *cmode="???";
2279 case 0: cmode = "Shape"; break;
2280 case 1: cmode = "Vertex"; break;
2281 case 2: cmode = "Edge"; break;
2282 case 3: cmode = "Wire"; break;
2283 case 4: cmode = "Face"; break;
2284 case 5: cmode = "Shell"; break;
2285 case 6: cmode = "Solid"; break;
2286 case 7: cmode = "Compound"; break;
2289 if( !TheAISContext()->HasOpenedContext() ) {
2290 // il n'y a pas de Context local d'ouvert
2291 // on en ouvre un et on charge toutes les shapes displayees
2292 // on load tous les objets displayees et on Activate les objets de la liste
2293 AIS_ListOfInteractive ListOfIO;
2294 // on sauve dans une AISListOfInteractive tous les objets currents
2295 if (TheAISContext()->NbCurrents()>0 ){
2296 TheAISContext()->UnhilightCurrents(Standard_False);
2298 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2299 ListOfIO.Append(TheAISContext()->Current() );
2303 TheAISContext()->OpenLocalContext(Standard_False);
2304 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2307 Handle(AIS_InteractiveObject) aIO =
2308 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2310 TheAISContext()->Load(aIO,0,Standard_False);
2313 // traitement des objets qui etaient currents dans le Contexte global
2314 if (!ListOfIO.IsEmpty() ) {
2315 // il y avait des objets currents
2316 AIS_ListIteratorOfListOfInteractive iter;
2317 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2318 Handle(AIS_InteractiveObject) aIO=iter.Value();
2319 TheAISContext()->Activate(aIO,aMode);
2320 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2324 // On applique le mode a tous les objets displayes
2325 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2326 it2 (GetMapOfAIS());
2328 Handle(AIS_InteractiveObject) aIO =
2329 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2330 if (!aIO.IsNull()) {
2331 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2332 TheAISContext()->Activate(aIO,aMode);
2341 // un Context local est deja ouvert
2342 // Traitement des objets du Context local
2343 if (TheAISContext()->NbSelected()>0 ){
2344 TheAISContext()->UnhilightSelected(Standard_False);
2345 // il y a des objets selected,on les parcourt
2346 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2347 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2350 if (HaveMode(aIO,aMode) ) {
2351 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2352 TheAISContext()->Deactivate(aIO,aMode);
2355 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2356 TheAISContext()->Activate(aIO,aMode);
2362 // il n'y a pas d'objets selected
2363 // tous les objets diplayes sont traites
2364 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2367 Handle(AIS_InteractiveObject) aIO =
2368 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2369 if (!aIO.IsNull()) {
2370 if (HaveMode(aIO,aMode) ) {
2371 di<<" Mode: "<<cmode<<" OFF pour "
2372 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2373 TheAISContext()->Deactivate(aIO,aMode);
2376 di<<" Mode: "<<cmode<<" ON pour"
2377 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2378 TheAISContext()->Activate(aIO,aMode);
2386 else if (HaveToSet && ThereIsName){
2387 Standard_Integer aMode=Draw::Atoi(argv [2]);
2388 Handle(AIS_InteractiveObject) aIO =
2389 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2391 if (!aIO.IsNull()) {
2392 const char *cmode="???";
2395 case 0: cmode = "Shape"; break;
2396 case 1: cmode = "Vertex"; break;
2397 case 2: cmode = "Edge"; break;
2398 case 3: cmode = "Wire"; break;
2399 case 4: cmode = "Face"; break;
2400 case 5: cmode = "Shell"; break;
2401 case 6: cmode = "Solid"; break;
2402 case 7: cmode = "Compound"; break;
2405 if( !TheAISContext()->HasOpenedContext() ) {
2406 TheAISContext()->OpenLocalContext(Standard_False);
2407 // On charge tous les objets de la map
2408 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2410 Handle(AIS_InteractiveObject) aShape=
2411 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2412 if (!aShape.IsNull())
2413 TheAISContext()->Load(aShape,0,Standard_False);
2416 TheAISContext()->Activate(aIO,aMode);
2417 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2421 // un Context local est deja ouvert
2422 if (HaveMode(aIO,aMode) ) {
2423 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2424 TheAISContext()->Deactivate(aIO,aMode);
2427 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2428 TheAISContext()->Activate(aIO,aMode);
2440 //==============================================================================
2441 // function : WhoAmI
2443 //==============================================================================
2444 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2447 if (theShape->Type()==AIS_KOI_Datum) {
2448 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2449 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2450 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2451 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2452 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2453 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2454 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2457 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2458 // AIS_Dimentions et AIS_Relations
2459 else if (theShape->Type()==AIS_KOI_Relation) {
2460 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2462 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2463 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2464 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2465 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2466 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2467 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2468 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2469 // AIS no repertorie.
2470 else {di<<" Type Unknown.";}
2476 //==============================================================================
2479 //Draw arg : vstate [nameA] ... [nameN]
2480 //==============================================================================
2481 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2483 TheAISContext()->CloseAllContexts();
2484 const Standard_Boolean ThereIsArguments=(argc>=2);
2485 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2487 // ==================
2488 // Il y a un argument
2489 // ==================
2490 if (ThereIsArguments) {
2491 for (int cpt=1;cpt<argc;cpt++) {
2492 // Verification que lq piece est bien bindee.
2493 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2494 const Handle(AIS_InteractiveObject) theShape=
2495 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2497 if (!theShape.IsNull()) {
2498 di<<argv[cpt];WhoAmI(theShape, di);
2499 if (TheAISContext()->IsDisplayed(theShape) ) {
2500 di<<" Displayed"<<"\n";
2503 di<<" Not Displayed"<<"\n";
2508 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2512 else if (ThereIsCurrent ) {
2513 for (TheAISContext() -> InitCurrent() ;
2514 TheAISContext() -> MoreCurrent() ;
2515 TheAISContext() ->NextCurrent() )
2517 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2518 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2519 if (TheAISContext()->IsDisplayed(theShape) ) {
2520 di<<" Displayed"<<"\n";
2523 di<<" Not Displayed"<<"\n";
2529 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2531 while ( it.More() ) {
2532 Handle(AIS_InteractiveObject) theShape =
2533 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2534 if (!theShape.IsNull()) {
2535 di<<it.Key2().ToCString();
2536 WhoAmI(theShape, di);
2537 if (TheAISContext()->IsDisplayed(theShape) ) {
2538 di<<" Displayed"<<"\n";
2541 di<<" Not Displayed"<<"\n";
2552 //=======================================================================
2553 //function : PickObjects
2555 //=======================================================================
2556 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2557 const AIS_KindOfInteractive TheType,
2558 const Standard_Integer TheSignature,
2559 const Standard_Integer MaxPick)
2561 Handle(AIS_InteractiveObject) IO;
2562 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2564 // step 1: prepare the data
2566 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2567 TheAISContext()->AddFilter(F1);
2570 // step 2 : wait for the selection...
2571 // Standard_Boolean IsGood (Standard_False);
2572 // Standard_Integer NbPick(0);
2573 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2574 Standard_Integer NbPickFail(0);
2575 Standard_Integer argccc = 5;
2576 const char *bufff[] = { "A", "B", "C","D", "E" };
2577 const char **argvvv = (const char **) bufff;
2580 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2581 while(ViewerMainLoop(argccc,argvvv)){}
2582 Standard_Integer NbStored = TheAISContext()->NbSelected();
2583 if((unsigned int ) NbStored != NbPickGood)
2584 NbPickGood= NbStored;
2587 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2590 // step3 get result.
2592 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2594 Standard_Integer i(0);
2595 for(TheAISContext()->InitSelected();
2596 TheAISContext()->MoreSelected();
2597 TheAISContext()->NextSelected()){
2599 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2600 arr->SetValue(i,IO2);
2605 TheAISContext()->CloseLocalContext(curindex);
2607 return Standard_True;
2611 //=======================================================================
2612 //function : PickObject
2614 //=======================================================================
2615 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2616 const Standard_Integer TheSignature,
2617 const Standard_Integer MaxPick)
2619 Handle(AIS_InteractiveObject) IO;
2620 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2622 // step 1: prepare the data
2625 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2626 TheAISContext()->AddFilter(F1);
2629 // step 2 : wait for the selection...
2630 Standard_Boolean IsGood (Standard_False);
2631 Standard_Integer NbPick(0);
2632 Standard_Integer argccc = 5;
2633 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2634 const char **argvvv = (const char **) bufff;
2637 while(!IsGood && NbPick<= MaxPick){
2638 while(ViewerMainLoop(argccc,argvvv)){}
2639 IsGood = (TheAISContext()->NbSelected()>0) ;
2641 cout<<"Nb Pick :"<<NbPick<<endl;
2645 // step3 get result.
2647 TheAISContext()->InitSelected();
2648 IO = TheAISContext()->SelectedInteractive();
2652 TheAISContext()->CloseLocalContext(curindex);
2656 //=======================================================================
2657 //function : PickShape
2658 //purpose : First Activate the rightmode + Put Filters to be able to
2659 // pick objets that are of type <TheType>...
2660 //=======================================================================
2662 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2663 const Standard_Integer MaxPick)
2666 // step 1: prepare the data
2668 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2669 TopoDS_Shape result;
2671 if(TheType==TopAbs_SHAPE){
2672 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2673 TheAISContext()->AddFilter(F1);
2676 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2677 TheAISContext()->AddFilter(TF);
2678 TheAISContext()->ActivateStandardMode(TheType);
2683 // step 2 : wait for the selection...
2684 Standard_Boolean NoShape (Standard_True);
2685 Standard_Integer NbPick(0);
2686 Standard_Integer argccc = 5;
2687 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2688 const char **argvvv = (const char **) bufff;
2691 while(NoShape && NbPick<= MaxPick){
2692 while(ViewerMainLoop(argccc,argvvv)){}
2693 NoShape = (TheAISContext()->NbSelected()==0) ;
2695 cout<<"Nb Pick :"<<NbPick<<endl;
2698 // step3 get result.
2702 TheAISContext()->InitSelected();
2703 if(TheAISContext()->HasSelectedShape())
2704 result = TheAISContext()->SelectedShape();
2706 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2707 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2712 TheAISContext()->CloseLocalContext(curindex);
2718 //=======================================================================
2719 //function : PickShapes
2721 //=======================================================================
2722 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2723 Handle(TopTools_HArray1OfShape)& thearr,
2724 const Standard_Integer MaxPick)
2727 Standard_Integer Taille = thearr->Length();
2729 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2731 // step 1: prepare the data
2732 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2733 if(TheType==TopAbs_SHAPE){
2734 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2735 TheAISContext()->AddFilter(F1);
2738 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2739 TheAISContext()->AddFilter(TF);
2740 TheAISContext()->ActivateStandardMode(TheType);
2744 // step 2 : wait for the selection...
2746 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2747 Standard_Integer NbPickFail(0);
2748 Standard_Integer argccc = 5;
2749 const char *bufff[] = { "A", "B", "C","D", "E" };
2750 const char **argvvv = (const char **) bufff;
2753 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2754 while(ViewerMainLoop(argccc,argvvv)){}
2755 Standard_Integer NbStored = TheAISContext()->NbSelected();
2756 if((unsigned int ) NbStored != NbPickGood)
2757 NbPickGood= NbStored;
2760 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2763 // step3 get result.
2765 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2767 Standard_Integer i(0);
2768 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2770 if(TheAISContext()->HasSelectedShape())
2771 thearr->SetValue(i,TheAISContext()->SelectedShape());
2773 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2774 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2778 TheAISContext()->CloseLocalContext(curindex);
2779 return Standard_True;
2783 //=======================================================================
2784 //function : VPickShape
2786 //=======================================================================
2787 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2789 TopoDS_Shape PickSh;
2790 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2793 theType = TopAbs_SHAPE;
2795 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2796 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2797 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2798 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2799 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2800 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2801 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2804 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2805 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2807 TCollection_AsciiString name;
2810 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2812 PickSh = ViewerTest::PickShape(theType);
2821 if(!PickSh.IsNull()){
2822 nbOfSub[Standard_Integer(theType)]++;
2824 name += nameType[Standard_Integer(theType)];
2825 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2830 // si on avait une petite methode pour voir si la shape
2831 // est deja dans la Double map, ca eviterait de creer....
2832 DBRep::Set(name.ToCString(),PickSh);
2834 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2835 GetMapOfAIS().Bind(newsh, name);
2836 TheAISContext()->Display(newsh);
2837 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2840 // Plusieurs objets a picker, vite vite vite....
2843 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2844 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2845 if(ViewerTest::PickShapes(theType,arr)){
2846 for(Standard_Integer i=1;i<=NbToPick;i++){
2847 PickSh = arr->Value(i);
2848 if(!PickSh.IsNull()){
2850 nbOfSub[Standard_Integer(theType)]++;
2853 name += nameType[Standard_Integer(theType)];
2854 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2862 DBRep::Set(name.ToCString(),PickSh);
2863 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2864 GetMapOfAIS().Bind(newsh, name);
2865 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2866 TheAISContext()->Display(newsh);
2874 //=======================================================================
2875 //function : list of known objects
2877 //=======================================================================
2878 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2880 // 1234567890 12345678901234567 123456789
2881 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2882 TCollection_AsciiString BlankLine(64,'_');
2883 Standard_Integer i ;
2885 di<<"/n"<<BlankLine.ToCString()<<"\n";
2888 Colum[i].Center(20,' ');
2890 di<<"|"<<Colum[i].ToCString();
2893 di<<BlankLine.ToCString()<<"\n";
2895 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
2896 const char ** names = GetTypeNames();
2898 TCollection_AsciiString curstring;
2899 TCollection_AsciiString curcolum[3];
2902 // les objets de type Datum..
2903 curcolum[1]+="Datum";
2905 curcolum[0].Clear();
2906 curcolum[0] += names[i];
2908 curcolum[2].Clear();
2909 curcolum[2]+=TCollection_AsciiString(i+1);
2911 for(Standard_Integer j =0;j<=2;j++){
2912 curcolum[j].Center(20,' ');
2913 di<<"|"<<curcolum[j].ToCString();
2917 di<<BlankLine.ToCString()<<"\n";
2919 // les objets de type shape
2920 curcolum[1].Clear();
2921 curcolum[1]+="Shape";
2922 curcolum[1].Center(20,' ');
2925 curcolum[0].Clear();
2926 curcolum[0] += names[7+i];
2927 curcolum[2].Clear();
2928 curcolum[2]+=TCollection_AsciiString(i);
2930 for(Standard_Integer j =0;j<=2;j++){
2931 curcolum[j].Center(20,' ');
2932 di<<"|"<<curcolum[j].ToCString();
2936 di<<BlankLine.ToCString()<<"\n";
2937 // les IO de type objet...
2938 curcolum[1].Clear();
2939 curcolum[1]+="Object";
2940 curcolum[1].Center(20,' ');
2942 curcolum[0].Clear();
2943 curcolum[0] += names[10+i];
2944 curcolum[2].Clear();
2945 curcolum[2]+=TCollection_AsciiString(i);
2947 for(Standard_Integer j =0;j<=2;j++){
2948 curcolum[j].Center(20,' ');
2949 di<<"|"<<curcolum[j].ToCString();
2953 di<<BlankLine.ToCString()<<"\n";
2954 // les contraintes et dimensions.
2955 // pour l'instant on separe juste contraintes et dimensions...
2956 // plus tard, on detaillera toutes les sortes...
2957 curcolum[1].Clear();
2958 curcolum[1]+="Relation";
2959 curcolum[1].Center(20,' ');
2961 curcolum[0].Clear();
2962 curcolum[0] += names[12+i];
2963 curcolum[2].Clear();
2964 curcolum[2]+=TCollection_AsciiString(i);
2966 for(Standard_Integer j =0;j<=2;j++){
2967 curcolum[j].Center(20,' ');
2968 di<<"|"<<curcolum[j].ToCString();
2972 di<<BlankLine.ToCString()<<"\n";
2979 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
2981 if(argc!=2) return 1;
2983 AIS_KindOfInteractive TheType;
2984 Standard_Integer TheSign(-1);
2985 GetTypeAndSignfromString(argv[1],TheType,TheSign);
2988 AIS_ListOfInteractive LIO;
2990 // en attendant l'amelioration ais pour les dimensions...
2992 Standard_Integer dimension_status(-1);
2993 if(TheType==AIS_KOI_Relation){
2994 dimension_status = TheSign ==1 ? 1 : 0;
2998 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
2999 Handle(AIS_InteractiveObject) curio;
3000 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3003 if(dimension_status == -1)
3004 TheAISContext()->Erase(curio,Standard_False);
3006 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3007 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3008 (dimension_status==1 && KOD != AIS_KOD_NONE))
3009 TheAISContext()->Erase(curio,Standard_False);
3012 TheAISContext()->UpdateCurrentViewer();
3015 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3017 if(argc!=2) return 1;
3019 AIS_KindOfInteractive TheType;
3020 Standard_Integer TheSign(-1);
3021 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3023 // en attendant l'amelioration ais pour les dimensions...
3025 Standard_Integer dimension_status(-1);
3026 if(TheType==AIS_KOI_Relation){
3027 dimension_status = TheSign ==1 ? 1 : 0;
3031 AIS_ListOfInteractive LIO;
3032 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3033 Handle(AIS_InteractiveObject) curio;
3034 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3036 if(dimension_status == -1)
3037 TheAISContext()->Display(curio,Standard_False);
3039 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3040 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3041 (dimension_status==1 && KOD != AIS_KOD_NONE))
3042 TheAISContext()->Display(curio,Standard_False);
3047 TheAISContext()->UpdateCurrentViewer();
3051 //==============================================================================
3052 //function : VSetTransMode
3054 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3055 //==============================================================================
3057 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3058 // Verification des arguments
3059 if ( a3DView().IsNull() ) {
3060 ViewerTest::ViewerInit();
3061 di << "La commande vinit n'a pas ete appele avant" << "\n";
3064 if ( argc < 3 || argc > 8 ) {
3065 di << argv[0] << " Invalid number of arguments" << "\n";
3069 TCollection_AsciiString shapeName;
3070 shapeName = argv[1];
3071 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3072 Standard_Integer persFlag2 = 0;
3073 Standard_Integer persFlag3 = 0;
3074 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3075 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3076 persFlag2 = Draw::Atoi(argv[3]);
3078 if ( argc == 5 || argc == 8 ) {
3079 persFlag3 = Draw::Atoi(argv[4]);
3082 origin.SetX( Draw::Atof(argv[argc - 3]) );
3083 origin.SetY( Draw::Atof(argv[argc - 2]) );
3084 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3087 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3088 Handle(Standard_Transient) anObj;
3090 anObj = GetMapOfAIS().Find2(shapeName);
3091 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3092 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3093 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3094 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3095 di << argv[0] << " All persistence modifiers were removed" << "\n";
3098 di << argv[0] << " Wrong object type" << "\n";
3101 } else { // Create the AIS_Shape from a name
3102 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3103 if ( !aShape.IsNull() ) {
3104 GetMapOfAIS().Bind( aShape, shapeName );
3105 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3106 TheAISContext()->Display( aShape, Standard_False );
3108 di << argv[0] << " Object not found" << "\n";
3113 // Upadate the screen and redraw the view
3114 TheAISContext()->UpdateCurrentViewer();
3118 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3121 BRep_Builder builder;
3123 BRepTools::Read(shape, s, builder);
3124 DBRep::Set(a[1], shape);
3125 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3126 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3131 //==============================================================================
3132 //function : ViewerTest::Commands
3133 //purpose : Add all the viewer command in the Draw_Interpretor
3134 //==============================================================================
3136 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3138 ViewerTest::ViewerCommands(theCommands);
3139 ViewerTest::RelationCommands(theCommands);
3140 ViewerTest::ObjectCommands(theCommands);
3141 ViewerTest::FilletCommands(theCommands);
3142 ViewerTest::VoxelCommands(theCommands);
3143 ViewerTest::OpenGlCommands(theCommands);
3145 const char *group = "AIS_Display";
3148 theCommands.Add("visos",
3149 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3150 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3151 __FILE__, visos, group);
3153 theCommands.Add("vdisplay",
3154 "vdisplay name1 [name2] ... [name n]"
3155 "\n\t\t: Displays named objects",
3156 __FILE__,VDisplay2,group);
3158 theCommands.Add("verase",
3159 "verase [name1] ... [name n]"
3160 "\n\t\t: Erases selected or named objects."
3161 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3162 __FILE__,VErase2,group);
3164 theCommands.Add("vdonly",
3165 "vdonly [name1] ... [name n]"
3166 "\n\t\t: Displays only selected or named objects",
3167 __FILE__,VDonly2,group);
3169 theCommands.Add("vdisplayall",
3170 "Displays all erased interactive objects (see vdir and vstate)",
3171 __FILE__,VDisplayAll,group);
3173 theCommands.Add("veraseall",
3174 "Erases all objects displayed in the viewer",
3175 __FILE__,VEraseAll,group);
3177 theCommands.Add("verasetype",
3179 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3180 __FILE__,VEraseType,group);
3182 theCommands.Add("vdisplaytype",
3183 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3184 __FILE__,VDisplayType,group);
3186 theCommands.Add("vdisplaymode",
3187 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3188 __FILE__,VDispMode,group);
3190 theCommands.Add("verasemode",
3191 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3192 __FILE__,VDispMode,group);
3194 theCommands.Add("vsetdispmode",
3195 "vsetdispmode [name] mode(1,2,..)"
3196 "\n\t\t: Sets display mode for all, selected or named objects.",
3197 __FILE__,VDispMode,group);
3199 theCommands.Add("vunsetdispmode",
3200 "vunsetdispmode [name]"
3201 "\n\t\t: Unsets custom display mode for selected or named objects.",
3202 __FILE__,VDispMode,group);
3204 theCommands.Add("vdir",
3205 "Lists all objects displayed in 3D viewer",
3206 __FILE__,VDebug,group);
3208 theCommands.Add("vdump",
3209 #ifdef HAVE_FREEIMAGE
3210 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]"
3211 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3213 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height]"
3214 "\n\t\t: Dumps contents of viewer window to PPM image file",
3216 __FILE__,VDump,group);
3218 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3219 __FILE__,VSubInt,group);
3221 theCommands.Add("vsetcolor",
3222 "vsetcolor [name] ColorName"
3223 "\n\t\t: Sets color for all, selected or named objects.",
3224 __FILE__,VColor2,group);
3226 theCommands.Add("vunsetcolor",
3227 "vunsetcolor [name]"
3228 "\n\t\t: Resets color for all, selected or named objects.",
3229 __FILE__,VColor2,group);
3231 theCommands.Add("vsettransparency",
3232 "vsettransparency [name] Coefficient"
3233 "\n\t\t: Sets transparency for all, selected or named objects."
3234 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3235 __FILE__,VTransparency,group);
3237 theCommands.Add("vunsettransparency",
3238 "vunsettransparency [name]"
3239 "\n\t\t: Resets transparency for all, selected or named objects.",
3240 __FILE__,VTransparency,group);
3242 theCommands.Add("vsetmaterial",
3243 "vmaterial : vmaterial [name of shape] MaterialName",
3244 __FILE__,VMaterial,group);
3246 theCommands.Add("vunsetmaterial",
3247 "vmaterial : vmaterial [name of shape]",
3248 __FILE__,VMaterial,group);
3250 theCommands.Add("vsetwidth",
3251 "vsetwidth : vwidth [name of shape] width(0->10)",
3252 __FILE__,VWidth,group);
3254 theCommands.Add("vunsetwidth",
3255 "vunsetwidth : vwidth [name of shape]",
3256 __FILE__,VWidth,group);
3258 theCommands.Add("vsetinteriorstyle",
3259 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3260 __FILE__,VInteriorStyle,group);
3262 theCommands.Add("vardis",
3263 "vardis : display activeareas",
3264 __FILE__,VDispAreas,group);
3266 theCommands.Add("varera",
3267 "varera : erase activeareas",
3268 __FILE__,VClearAreas,group);
3270 theCommands.Add("vsensdis",
3271 "vardisp : display active entities",
3272 __FILE__,VDispSensi,group);
3273 theCommands.Add("vsensera",
3274 "vardisp : erase active entities",
3275 __FILE__,VClearSensi,group);
3277 theCommands.Add("vselprecision",
3278 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3279 __FILE__,VSelPrecision,group);
3281 theCommands.Add("vperf",
3282 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3283 __FILE__,VPerf,group);
3285 theCommands.Add("vanimation",
3286 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3287 __FILE__,VAnimation,group);
3289 theCommands.Add("vsetshading",
3290 "vsetshading : vsetshading name Quality(default=0.0008) ",
3291 __FILE__,VShading,group);
3293 theCommands.Add("vunsetshading",
3294 "vunsetshading :vunsetshading name ",
3295 __FILE__,VShading,group);
3297 theCommands.Add("vtexture",
3298 "'vtexture NameOfShape TextureFile' \n \
3299 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3300 or 'vtexture NameOfShape ?' to list available textures\n \
3301 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3302 __FILE__,VTexture,group);
3304 theCommands.Add("vtexscale",
3305 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3306 or 'vtexscale NameOfShape ScaleUV' \n \
3307 or 'vtexscale NameOfShape' to disable scaling\n ",
3308 __FILE__,VTexture,group);
3310 theCommands.Add("vtexorigin",
3311 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3312 or 'vtexorigin NameOfShape UVOrigin' \n \
3313 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3314 __FILE__,VTexture,group);
3316 theCommands.Add("vtexrepeat",
3317 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3318 or 'vtexrepeat NameOfShape UVRepeat \n \
3319 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3322 theCommands.Add("vtexdefault",
3323 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3326 theCommands.Add("vsetam",
3327 "vsetActivatedModes: vsetam mode(1->7) ",
3328 __FILE__,VActivatedMode,group);
3330 theCommands.Add("vunsetam",
3331 "vunsetActivatedModes: vunsetam ",
3332 __FILE__,VActivatedMode,group);
3334 theCommands.Add("vstate",
3335 "vstate [name1] ... [nameN]"
3336 "\n\t\t: Reports show/hidden state for selected or named objects",
3337 __FILE__,VState,group);
3339 theCommands.Add("vpickshapes",
3340 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3341 __FILE__,VPickShape,group);
3343 theCommands.Add("vtypes",
3344 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3347 theCommands.Add("vsettransmode",
3348 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3349 __FILE__,VSetTransMode,group);
3351 theCommands.Add("vr", "vr : reading of the shape",
3352 __FILE__,vr, group);
3356 //=====================================================================
3357 //========================= for testing Draft and Rib =================
3358 //=====================================================================
3359 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3360 #include <DBRep.hxx>
3361 #include <TopoDS_Face.hxx>
3362 #include <gp_Pln.hxx>
3363 #include <AIS_KindOfSurface.hxx>
3364 #include <BRepOffsetAPI_DraftAngle.hxx>
3365 #include <Precision.hxx>
3366 #include <BRepAlgo.hxx>
3367 #include <OSD_Environment.hxx>
3368 #include <DrawTrSurf.hxx>
3369 //#include <DbgTools.hxx>
3370 //#include <FeatAlgo_MakeLinearForm.hxx>
3375 //=======================================================================
3376 //function : IsValid
3378 //=======================================================================
3379 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3380 const TopoDS_Shape& theResult,
3381 const Standard_Boolean closedSolid,
3382 const Standard_Boolean GeomCtrl)
3384 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3385 TCollection_AsciiString checkValid = check.Value();
3386 Standard_Boolean ToCheck = Standard_True;
3387 if (!checkValid.IsEmpty()) {
3389 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3391 if ( checkValid=="true" || checkValid=="TRUE" ) {
3392 ToCheck= Standard_False;
3396 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3399 Standard_Boolean IsValid = Standard_True;
3401 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3406 //===============================================================================
3407 // TDraft : test draft, uses AIS Viewer
3408 // Solid Face Plane Angle Reverse
3409 //===============================================================================
3410 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3412 if (argc < 5) return 1;
3413 // argv[1] - TopoDS_Shape Solid
3414 // argv[2] - TopoDS_Shape Face
3415 // argv[3] - TopoDS_Shape Plane
3416 // argv[4] - Standard_Real Angle
3417 // argv[5] - Standard_Integer Reverse
3419 // Sprintf(prefix, argv[1]);
3420 Standard_Real anAngle = 0;
3421 Standard_Boolean Rev = Standard_False;
3422 Standard_Integer rev = 0;
3423 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3424 TopoDS_Shape face = GetShapeFromName(argv[2]);
3425 TopoDS_Face Face = TopoDS::Face(face);
3426 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3427 if (Plane.IsNull ()) {
3428 di << "TEST : Plane is NULL" << "\n";
3431 anAngle = Draw::Atof(argv[4]);
3432 anAngle = 2*M_PI * anAngle / 360.0;
3434 Handle( Geom_Surface )aSurf;
3435 AIS_KindOfSurface aSurfType;
3436 Standard_Real Offset;
3438 if(argc > 4) { // == 5
3439 rev = Draw::Atoi(argv[5]);
3440 Rev = (rev)? Standard_True : Standard_False;
3443 TopoDS_Face face2 = TopoDS::Face(Plane);
3444 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3446 di << "TEST : Can't find plane" << "\n";
3450 aDir = aPln.Axis().Direction();
3453 if (Plane.Orientation() == TopAbs_REVERSED)
3455 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3457 BRepOffsetAPI_DraftAngle Draft (Solid);
3459 if(Abs(anAngle)< Precision::Angular()) {
3460 di << "TEST : NULL angle" << "\n";
3463 if(Rev) anAngle = - anAngle;
3464 Draft.Add (Face, aDir, anAngle, aPln);
3466 if (!Draft.IsDone()) {
3467 di << "TEST : Draft Not DONE " << "\n";
3470 TopTools_ListOfShape Larg;
3472 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3473 di << "TEST : DesignAlgo returns Not valid" << "\n";
3477 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3478 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3480 if ( !ais.IsNull() ) {
3481 ais->SetColor(DEFAULT_COLOR);
3482 ais->SetMaterial(DEFAULT_MATERIAL);
3483 // Display the AIS_Shape without redraw
3484 Ctx->Display(ais, Standard_False);
3486 const char *Name = "draft1";
3487 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3489 Handle(AIS_InteractiveObject) an_object =
3490 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3491 if (!an_object.IsNull()) {
3492 Ctx->Remove(an_object,
3494 GetMapOfAIS().UnBind2(Name) ;
3497 GetMapOfAIS().Bind(ais, Name);
3498 // DBRep::Set("draft", ais->Shape());
3500 Ctx->Display(ais, Standard_True);
3506 //============================================================================
3508 //============================================================================
3509 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3512 DrawTrSurf::BasicCommands(theCommands);
3513 const char* group = "Check Features Operations commands";
3515 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3517 &TDraft,group); //Draft_Modification
3520 //==============================================================================
3521 // ViewerTest::Factory
3522 //==============================================================================
3523 void ViewerTest::Factory(Draw_Interpretor& theDI)
3525 // definition of Viewer Command
3526 ViewerTest::Commands(theDI);
3527 ViewerTest::AviCommands(theDI);
3530 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3534 // Declare entry point PLUGINFACTORY