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_Timer.hxx>
36 #include <Geom_Axis2Placement.hxx>
37 #include <Geom_Axis1Placement.hxx>
38 #include <gp_Trsf.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <BRepAdaptor_Curve.hxx>
41 #include <StdSelect_ShapeTypeFilter.hxx>
43 #include <AIS_Drawer.hxx>
44 #include <AIS_InteractiveObject.hxx>
45 #include <AIS_Trihedron.hxx>
46 #include <AIS_Axis.hxx>
47 #include <AIS_Relation.hxx>
48 #include <AIS_TypeFilter.hxx>
49 #include <AIS_SignatureFilter.hxx>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <Aspect_InteriorStyle.hxx>
53 #include <Graphic3d_AspectFillArea3d.hxx>
54 #include <Graphic3d_AspectLine3d.hxx>
55 #include <Graphic3d_TextureRoot.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <Prs3d_ShadingAspect.hxx>
58 #include <Prs3d_IsoAspect.hxx>
68 #include <Draw_Interpretor.hxx>
69 #include <TCollection_AsciiString.hxx>
70 #include <Draw_PluginMacro.hxx>
71 #include <ViewerTest.hxx>
73 // avoid warnings on 'extern "C"' functions returning C++ classes
75 #define _CRT_SECURE_NO_DEPRECATE
76 #pragma warning(4:4190)
77 #pragma warning (disable:4996)
80 #include <NIS_InteractiveContext.hxx>
81 #include <NIS_Triangulated.hxx>
82 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
84 #include <Quantity_Color.hxx>
85 #include <Quantity_NameOfColor.hxx>
87 #include <Graphic3d_NameOfMaterial.hxx>
89 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
90 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
93 //=======================================================================
94 //function : GetColorFromName
95 //purpose : get the Quantity_NameOfColor from a string
96 //=======================================================================
98 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
100 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
102 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
103 if (strcasecmp (theName, aColorName) == 0)
105 return Quantity_NameOfColor (anIter);
109 return DEFAULT_COLOR;
112 //=======================================================================
113 //function : GetMaterialFromName
114 //purpose : get the Graphic3d_NameOfMaterial from a string
115 //=======================================================================
117 static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
119 Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
121 if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS;
122 else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE;
123 else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER;
124 else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD;
125 else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER;
126 else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER;
127 else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL;
128 else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED;
129 else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
130 else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
131 else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
132 else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
133 else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
134 else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
135 else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
136 else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN;
137 else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC;
138 else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN;
139 else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE;
144 //=======================================================================
145 //function : GetTypeNames
147 //=======================================================================
148 static const char** GetTypeNames()
150 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
151 "Shape","ConnectedShape","MultiConn.Shape",
152 "ConnectedInter.","MultiConn.",
153 "Constraint","Dimension"};
154 static const char** ThePointer = names;
158 //=======================================================================
159 //function : GetTypeAndSignfromString
161 //=======================================================================
162 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
164 const char ** thefullnames = GetTypeNames();
165 Standard_Integer index(-1);
167 for(Standard_Integer i=0;i<=13 && index==-1;i++)
168 if(!strcasecmp(name,thefullnames[i]))
172 TheType = AIS_KOI_None;
178 TheType = AIS_KOI_Datum;
182 TheType = AIS_KOI_Shape;
186 TheType = AIS_KOI_Object;
190 TheType = AIS_KOI_Relation;
199 #include <Draw_Interpretor.hxx>
201 #include <Draw_Appli.hxx>
205 #include <TCollection_AsciiString.hxx>
206 #include <V3d_Viewer.hxx>
207 #include <V3d_View.hxx>
210 #include <AIS_InteractiveContext.hxx>
211 #include <AIS_Shape.hxx>
212 #include <AIS_TexturedShape.hxx>
213 #include <AIS_DisplayMode.hxx>
214 #include <TColStd_MapOfInteger.hxx>
215 #include <AIS_MapOfInteractive.hxx>
216 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
217 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
218 #include <ViewerTest_EventManager.hxx>
220 #include <TopoDS_Solid.hxx>
221 #include <BRepTools.hxx>
222 #include <BRep_Builder.hxx>
223 #include <TopAbs_ShapeEnum.hxx>
225 #include <TopoDS.hxx>
226 #include <BRep_Tool.hxx>
229 #include <Draw_Window.hxx>
230 #include <AIS_ListIteratorOfListOfInteractive.hxx>
231 #include <AIS_ListOfInteractive.hxx>
232 #include <AIS_DisplayMode.hxx>
233 #include <TopTools_ListOfShape.hxx>
234 #include <BRepOffsetAPI_MakeThickSolid.hxx>
235 #include <BRepOffset.hxx>
237 //==============================================================================
238 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
239 //==============================================================================
240 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
241 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
246 //==============================================================================
247 //function : VDisplayAISObject
248 //purpose : register interactive object in the map of AIS objects;
249 // if other object with such name already registered, it will be kept
250 // or replaced depending on value of <theReplaceIfExists>,
251 // if "true" - the old object will be cleared from AIS context;
252 // returns Standard_True if <theAISObj> registered in map;
253 //==============================================================================
254 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
255 const Handle(AIS_InteractiveObject)& theAISObj,
256 Standard_Boolean theReplaceIfExists = Standard_True)
258 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
259 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
260 if (aContextAIS.IsNull())
262 std::cout << "AIS context is not available.\n";
263 return Standard_False;
266 if (aMap.IsBound2 (theName))
268 if (!theReplaceIfExists)
270 std::cout << "Other interactive object has been already "
271 << "registered with name: " << theName << ".\n"
272 << "Please use another name.\n";
273 return Standard_False;
276 // stop displaying object
277 Handle(AIS_InteractiveObject) anOldObj =
278 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
280 if (!anOldObj.IsNull())
281 aContextAIS->Clear (anOldObj, Standard_True);
283 // remove name and old object from map
284 aMap.UnBind2 (theName);
287 if (theAISObj.IsNull())
289 // object with specified name already unbound
290 return Standard_True;
293 // unbind AIS object if was bound with another name
294 aMap.UnBind1 (theAISObj);
296 // can be registered without rebinding
297 aMap.Bind (theAISObj, theName);
298 aContextAIS->Display (theAISObj, Standard_True);
299 return Standard_True;
302 static TColStd_MapOfInteger theactivatedmodes(8);
303 static TColStd_ListOfTransient theEventMgrs;
305 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
306 const Handle(AIS_InteractiveContext)& Ctx)
308 theEventMgrs.Clear();
309 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
312 static Handle(V3d_View)& a3DView()
314 static Handle(V3d_View) Viou;
319 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
320 static Handle(AIS_InteractiveContext) aContext;
324 const Handle(V3d_View)& ViewerTest::CurrentView()
328 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
333 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
335 static Handle(NIS_InteractiveContext) aContext;
336 if (aContext.IsNull()) {
337 aContext = new NIS_InteractiveContext;
338 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
343 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
345 return TheAISContext();
348 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
350 TheAISContext() = aCtx;
351 ViewerTest::ResetEventManager();
354 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
356 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
359 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
361 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
365 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
366 theEventMgrs.Prepend(EM);
369 void ViewerTest::UnsetEventManager()
371 theEventMgrs.RemoveFirst();
375 void ViewerTest::ResetEventManager()
377 const Handle(NIS_View) aView =
378 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
379 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
382 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
384 Handle(ViewerTest_EventManager) EM;
385 if(theEventMgrs.IsEmpty()) return EM;
386 Handle(Standard_Transient) Tr = theEventMgrs.First();
387 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
392 //=======================================================================
393 //function : Get Context and active viou..
395 //=======================================================================
396 void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
397 Handle(V3d_View)& Viou)
399 Ctx = ViewerTest::GetAISContext();
402 const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
403 Vwr->InitActiveViews();
404 if(Vwr->MoreActiveViews())
405 Viou = Vwr->ActiveView();
410 //==============================================================================
411 //function : GetShapeFromName
412 //purpose : Compute an Shape from a draw variable or a file name
413 //==============================================================================
415 static TopoDS_Shape GetShapeFromName(const char* name)
417 TopoDS_Shape S = DBRep::Get(name);
420 BRep_Builder aBuilder;
421 BRepTools::Read( S, name, aBuilder);
427 //==============================================================================
428 //function : GetAISShapeFromName
429 //purpose : Compute an AIS_Shape from a draw variable or a file name
430 //==============================================================================
431 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
433 Handle(AIS_Shape) retsh;
435 if(GetMapOfAIS().IsBound2(name)){
436 const Handle(AIS_InteractiveObject) IO =
437 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
439 if(IO->Type()==AIS_KOI_Shape) {
440 if(IO->Signature()==0){
441 retsh = *((Handle(AIS_Shape)*)&IO);
444 cout << "an Object which is not an AIS_Shape "
445 "already has this name!!!"<<endl;
452 TopoDS_Shape S = GetShapeFromName(name);
454 retsh = new AIS_Shape(S);
460 //==============================================================================
462 //purpose : Remove all the object from the viewer
463 //==============================================================================
464 void ViewerTest::Clear()
466 if ( !a3DView().IsNull() ) {
467 if (TheAISContext()->HasOpenedContext())
468 TheAISContext()->CloseLocalContext();
469 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
470 while ( it.More() ) {
471 cout << "Remove " << it.Key2() << endl;
472 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
473 const Handle(AIS_InteractiveObject) anObj =
474 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
475 TheAISContext()->Remove(anObj,Standard_False);
476 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
477 const Handle(NIS_InteractiveObject) anObj =
478 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
479 TheNISContext()->Remove(anObj);
483 TheAISContext()->UpdateCurrentViewer();
484 // TheNISContext()->UpdateViews();
485 GetMapOfAIS().Clear();
489 //==============================================================================
490 //function : StandardModesActivation
491 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
493 //==============================================================================
494 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
496 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
498 if (TheAISContext()->HasOpenedContext())
499 aContext->CloseLocalContext();
502 if(!aContext->HasOpenedContext()) {
503 // To unhilight the preselected object
504 aContext->UnhilightCurrents(Standard_False);
505 // Open a local Context in order to be able to select subshape from
506 // the selected shape if any or for all if there is no selection
507 if (!aContext->FirstCurrentObject().IsNull()){
508 aContext->OpenLocalContext(Standard_False);
510 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
511 aContext->Load( aContext->Current(),-1,Standard_True);
515 aContext->OpenLocalContext();
518 const char *cmode="???";
521 case 0: cmode = "Shape"; break;
522 case 1: cmode = "Vertex"; break;
523 case 2: cmode = "Edge"; break;
524 case 3: cmode = "Wire"; break;
525 case 4: cmode = "Face"; break;
526 case 5: cmode = "Shell"; break;
527 case 6: cmode = "Solid"; break;
528 case 7: cmode = "Compsolid"; break;
529 case 8: cmode = "Compound"; break;
532 if(theactivatedmodes.Contains(mode))
534 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
535 theactivatedmodes.Remove(mode);
536 cout<<"Mode "<< cmode <<" OFF"<<endl;
540 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
541 theactivatedmodes.Add(mode);
542 cout<<"Mode "<< cmode << " ON" << endl;
547 //==============================================================================
548 //function : CopyIsoAspect
549 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
550 //==============================================================================
551 static Handle(Prs3d_IsoAspect) CopyIsoAspect
552 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
553 const Standard_Integer theNbIsos)
555 Quantity_Color aColor;
556 Aspect_TypeOfLine aType;
557 Standard_Real aWidth;
559 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
561 Handle(Prs3d_IsoAspect) aResult =
562 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
567 //==============================================================================
569 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
570 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
571 //==============================================================================
572 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
574 if (TheAISContext().IsNull()) {
575 di << argv[0] << " Call 'vinit' before!\n";
580 di << "Current number of isos : " <<
581 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
582 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
583 di << "IsoOnPlane mode is " <<
584 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
589 Standard_Integer aLastInd = argc - 1;
590 Standard_Boolean isChanged = Standard_False;
591 Standard_Integer aNbUIsos = 0;
592 Standard_Integer aNbVIsos = 0;
595 Standard_Boolean isIsoOnPlane = Standard_False;
597 if (strcmp(argv[aLastInd], "1") == 0) {
598 isIsoOnPlane = Standard_True;
599 isChanged = Standard_True;
600 } else if (strcmp(argv[aLastInd], "0") == 0) {
601 isIsoOnPlane = Standard_False;
602 isChanged = Standard_True;
606 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
607 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
610 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
611 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
613 TheAISContext()->IsoOnPlane(isIsoOnPlane);
616 // If there are no shapes provided set the default numbers.
617 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
618 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
625 for (i = 1; i <= aLastInd; i++) {
626 TCollection_AsciiString name(argv[i]);
627 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
630 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
631 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
632 const Handle(AIS_InteractiveObject) aShape =
633 Handle(AIS_InteractiveObject)::DownCast (anObj);
634 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
635 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
636 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
639 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
640 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
641 TheAISContext()->SetLocalAttributes
642 (aShape, CurDrawer, Standard_False);
643 TheAISContext()->Redisplay(aShape);
645 di << "Number of isos for " << argv[i] << " : "
646 << aUIso->Number() << " " << aVIso->Number() << "\n";
649 di << argv[i] << ": Not an AIS interactive object!\n";
652 di << argv[i] << ": Use 'vdisplay' before\n";
657 TheAISContext()->UpdateCurrentViewer();
663 //==============================================================================
664 //function : VDispAreas,VDispSensitive,...
665 //purpose : Redraw the view
667 //==============================================================================
668 static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
671 Handle(AIS_InteractiveContext) Ctx;
672 Handle(V3d_View) Viou;
673 GetCtxAndView(Ctx,Viou);
674 Ctx->DisplayActiveAreas(Viou);
677 static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
679 Handle(AIS_InteractiveContext) Ctx;
680 Handle(V3d_View) Viou;
681 GetCtxAndView(Ctx,Viou);
682 Ctx->ClearActiveAreas(Viou);
686 static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
688 Handle(AIS_InteractiveContext) Ctx;
689 Handle(V3d_View) Viou;
690 GetCtxAndView(Ctx,Viou);
691 Ctx->DisplayActiveSensitive(Viou);
695 static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
697 Handle(AIS_InteractiveContext) Ctx;
698 Handle(V3d_View) Viou;
699 GetCtxAndView(Ctx,Viou);
700 Ctx->ClearActiveSensitive(Viou);
704 //==============================================================================
706 //purpose : To list the displayed object with their attributes
708 //==============================================================================
709 static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
710 { if ( !a3DView().IsNull() ) {
711 di << "List of object in the viewer :" << "\n";
713 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
715 while ( it.More() ) {
716 di << "\t" << it.Key2().ToCString() << "\n";
724 //==============================================================================
725 //function : VSelPrecision
726 //purpose : To set the selection precision mode and tolerance value
727 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
728 // value (integer number of pixel for window mode, double value of
729 // sensitivity for view mode). Without arguments the function just
730 // prints the current precision mode and the corresponding tolerance.
731 //==============================================================================
732 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
736 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
740 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
741 if( aContext.IsNull() )
746 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
747 if( aMode == StdSelect_SM_WINDOW )
749 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
750 di << "Precision mode : 0 (window)\n";
751 di << "Pixel tolerance : " << aPixelTolerance << "\n";
753 else if( aMode == StdSelect_SM_VIEW )
755 Standard_Real aSensitivity = aContext->Sensitivity();
756 di << "Precision mode : 1 (view)\n";
757 di << "Sensitivity : " << aSensitivity << "\n";
762 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
763 aContext->SetSensitivityMode( aMode );
766 if( aMode == StdSelect_SM_WINDOW )
768 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
769 aContext->SetPixelTolerance( aPixelTolerance );
771 else if( aMode == StdSelect_SM_VIEW )
773 Standard_Real aSensitivity = Draw::Atof( argv[2] );
774 aContext->SetSensitivity( aSensitivity );
781 //==============================================================================
783 //purpose : To dump the active view snapshot to image file
784 //Draw arg : Picture file name with extension corresponding to desired format
785 //==============================================================================
786 static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
790 di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
794 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
797 const char* aBuffTypeStr = argv[2];
798 if ( strcasecmp( aBuffTypeStr, "rgb" ) == 0 ) // 4 is to compare '\0' as well
800 aBufferType = Graphic3d_BT_RGB;
802 else if ( strcasecmp( aBuffTypeStr, "rgba" ) == 0 )
804 aBufferType = Graphic3d_BT_RGBA;
806 else if ( strcasecmp( aBuffTypeStr, "depth" ) == 0 )
808 aBufferType = Graphic3d_BT_Depth;
812 Standard_Integer aWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
813 Standard_Integer aHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
815 Handle(AIS_InteractiveContext) IC;
816 Handle(V3d_View) view;
817 GetCtxAndView (IC, view);
820 di << "Cannot find an active viewer/view\n";
824 if (aWidth <= 0 || aHeight <= 0)
826 if (!view->Dump (argv[1], aBufferType))
828 di << "Dumping failed!\n";
834 Image_AlienPixMap aPixMap;
835 if (!view->ToPixMap (aPixMap, aWidth, aHeight, aBufferType))
837 di << "Dumping failed!\n";
841 if (aPixMap.SizeX() != Standard_Size(aWidth)
842 || aPixMap.SizeY() != Standard_Size(aHeight))
844 std::cout << "Warning! Dumped dimensions " << aPixMap.SizeX() << "x" << aPixMap.SizeY()
845 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
847 if (!aPixMap.Save (argv[1]))
849 di << "Saving image failed!\n";
856 //==============================================================================
857 //function : Displays,Erase...
860 //==============================================================================
861 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
862 const Standard_Integer Mode,
863 const Standard_Integer TypeOfOperation,
864 const Standard_Boolean Upd)
866 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
868 switch(TypeOfOperation){
870 Ctx->Display(IO,Mode,Upd);
878 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
880 Ctx->SetDisplayMode(IO,Mode,Upd);
885 Ctx->SetDisplayMode(0,Upd);
887 Ctx->UnsetDisplayMode(IO,Upd);
894 //=======================================================================
897 //=======================================================================
898 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
901 TCollection_AsciiString name;
904 // display others presentations
905 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
906 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
907 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
908 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
910 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
912 //unset displaymode.. comportement particulier...
913 if(TypeOfOperation==4){
915 if(Ctx->NbCurrents()==0 ||
916 Ctx->NbSelected()==0){
917 Handle(AIS_InteractiveObject) IO;
918 VwrTst_DispErase(IO,-1,4,Standard_False);
920 else if(!Ctx->HasOpenedContext()){
921 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
922 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
925 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
926 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
927 Ctx->UpdateCurrentViewer();
930 Handle(AIS_InteractiveObject) IO;
932 if(GetMapOfAIS().IsBound2(name)){
933 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
935 VwrTst_DispErase(IO,-1,4,Standard_True);
940 Standard_Integer Dmode = Draw::Atoi(argv[1]);
941 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
942 Handle(AIS_InteractiveObject) IO;
943 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
945 if(!Ctx->HasOpenedContext()){
946 // set/unset display mode sur le Contexte...
947 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
948 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
950 Ctx->UpdateCurrentViewer();
953 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
954 Ctx->Display(Ctx->Interactive(),Dmode);
958 Handle(AIS_InteractiveObject) IO;
960 if(GetMapOfAIS().IsBound2(name))
961 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
963 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
969 //=======================================================================
972 //=======================================================================
973 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
975 if(argc==1) return 1;
976 Standard_Integer On = Draw::Atoi(argv[1]);
977 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
981 if(!Ctx->HasOpenedContext()){
982 di<<"sub intensite ";
985 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
986 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
988 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
990 di <<"passage dans off"<<"\n";
991 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
996 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
998 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1000 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1003 Ctx->UpdateCurrentViewer();
1006 Handle(AIS_InteractiveObject) IO;
1007 TCollection_AsciiString name = argv[2];
1008 if(GetMapOfAIS().IsBound2(name)){
1009 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1012 Ctx->SubIntensityOn(IO);
1014 Ctx->SubIntensityOff(IO);
1022 //==============================================================================
1023 //function : VColor2
1025 //purpose : change the color of a selected or named or displayed shape
1026 //Draw arg : vcolor2 [name] color
1027 //==============================================================================
1028 static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1031 Standard_Boolean ThereIsCurrent;
1032 Standard_Boolean ThereIsArgument;
1033 Standard_Boolean IsBound = Standard_False ;
1035 const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
1037 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
1038 ThereIsArgument = (argc != 2);
1041 if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
1042 ThereIsArgument = (argc == 2);
1045 if ( !a3DView().IsNull() ) {
1046 TCollection_AsciiString name;
1047 if (ThereIsArgument) {
1049 IsBound= GetMapOfAIS().IsBound2(name);
1051 if (TheAISContext()->HasOpenedContext())
1052 TheAISContext()->CloseLocalContext();
1054 // On set le Booleen There is current
1055 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1056 else ThereIsCurrent =Standard_False;
1058 //=======================================================================
1059 // Il y a un argument
1060 //=======================================================================
1061 if ( ThereIsArgument && IsBound ) {
1062 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1063 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1064 Handle(AIS_InteractiveObject) ashape =
1065 Handle(AIS_InteractiveObject)::DownCast (anObj);
1068 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1070 di << "HaveToSet 0\n";
1074 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
1076 TheAISContext()->UnsetColor(ashape);
1077 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1078 Handle(NIS_Triangulated) ashape =
1079 Handle(NIS_Triangulated)::DownCast (anObj);
1080 if (!ashape.IsNull())
1081 ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
1086 //=======================================================================
1087 // Il n'y a pas d'arguments
1088 // Mais un ou plusieurs objets on des current representation
1089 //=======================================================================
1090 if (ThereIsCurrent && !ThereIsArgument) {
1091 for (TheAISContext() -> InitCurrent() ;
1092 TheAISContext() -> MoreCurrent() ;
1093 TheAISContext() ->NextCurrent() )
1095 const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
1096 if (ashape.IsNull())
1100 di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
1102 di << "HaveToSet 0\n";
1105 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1107 TheAISContext()->UnsetColor(ashape,Standard_False);
1110 TheAISContext()->UpdateCurrentViewer();
1113 //=======================================================================
1114 // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
1115 // on impose a tous les objets du viewer la couleur passee
1116 //=======================================================================
1117 else if (!ThereIsCurrent && !ThereIsArgument){
1118 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
1119 while ( it.More() ) {
1120 const Handle(AIS_InteractiveObject) ashape =
1121 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1122 if (!ashape.IsNull()) {
1124 TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
1126 TheAISContext()->UnsetColor(ashape,Standard_False);
1130 TheAISContext()->UpdateCurrentViewer();
1136 //==============================================================================
1137 //function : VTransparency
1139 //purpose : change the transparency of a selected or named or displayed shape
1140 //Draw arg : vtransparency [name] TransparencyCoeficient
1141 //==============================================================================
1143 static int VTransparency (Draw_Interpretor& di, Standard_Integer argc,
1146 Standard_Boolean ThereIsCurrent;
1147 Standard_Boolean ThereIsArgument;
1148 Standard_Boolean IsBound = Standard_False ;
1150 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
1152 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1153 ThereIsArgument = (argc != 2);
1156 if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
1157 ThereIsArgument = (argc == 2);
1160 if ( !a3DView().IsNull() ) {
1161 TCollection_AsciiString name;
1162 if (ThereIsArgument) {
1164 IsBound= GetMapOfAIS().IsBound2(name);
1166 if (TheAISContext()->HasOpenedContext())
1167 TheAISContext()->CloseLocalContext();
1169 if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; }
1170 else ThereIsCurrent = Standard_False;
1172 //=======================================================================
1173 // Il y a des arguments: un nom et une couleur
1174 //=======================================================================
1175 if ( ThereIsArgument && IsBound ) {
1176 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1177 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1178 const Handle(AIS_InteractiveObject) ashape =
1179 Handle(AIS_InteractiveObject)::DownCast(anObj);
1181 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
1183 TheAISContext()->UnsetTransparency(ashape);
1184 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1185 const Handle(NIS_InteractiveObject) ashape =
1186 Handle(NIS_InteractiveObject)::DownCast(anObj);
1188 ashape->SetTransparency(Draw::Atof(argv[2]) );
1190 ashape->UnsetTransparency();
1193 //=======================================================================
1194 // Il n'y a pas d'arguments
1195 // Mais un ou plusieurs objets on des current representation
1196 //=======================================================================
1197 if (ThereIsCurrent && !ThereIsArgument) {
1198 for (TheAISContext() -> InitCurrent() ;
1199 TheAISContext() -> MoreCurrent() ;
1200 TheAISContext() ->NextCurrent() )
1202 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1204 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1206 TheAISContext()->UnsetTransparency(ashape,Standard_False);
1209 TheAISContext()->UpdateCurrentViewer();
1211 //=======================================================================
1212 // Il n'y a pas d'arguments ET aucun objet courrant
1213 //=======================================================================
1214 else if ( !ThereIsCurrent && !ThereIsArgument ) {
1215 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1217 while ( it.More() ) {
1218 Handle(AIS_InteractiveObject) ashape =
1219 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1220 if (!ashape.IsNull()) {
1222 TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
1224 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);
1284 //=======================================================================
1285 // Il n'y a pas de nom de shape
1286 // Mais un ou plusieurs objets on des current representation
1287 //=======================================================================
1288 if (ThereIsCurrent && !ThereIsName) {
1289 for (TheAISContext() -> InitCurrent() ;
1290 TheAISContext() -> MoreCurrent() ;
1291 TheAISContext() ->NextCurrent() )
1293 Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
1295 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1297 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1299 TheAISContext()->UpdateCurrentViewer();
1302 //=======================================================================
1303 // Il n'y a pas de noms de shape ET aucun objet courrant
1304 // On impose a tous les objets du viewer le material passe en argument
1305 //=======================================================================
1306 else if (!ThereIsCurrent && !ThereIsName){
1307 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1309 while ( it.More() ) {
1310 Handle(AIS_InteractiveObject) ashape =
1311 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1312 if (!ashape.IsNull()) {
1314 TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
1316 TheAISContext()->UnsetMaterial(ashape,Standard_False);
1320 TheAISContext()->UpdateCurrentViewer();
1328 //==============================================================================
1331 //purpose : change the width of the edges of a selected or named or displayed shape
1332 //Draw arg : vwidth [Name] WidthValue(1->10)
1333 //==============================================================================
1334 static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1337 Standard_Boolean ThereIsCurrent;
1338 Standard_Boolean ThereIsArgument;
1339 Standard_Boolean IsBound = Standard_False ;
1341 const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
1343 if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
1344 ThereIsArgument = (argc != 2);
1347 if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; }
1348 ThereIsArgument = (argc == 2);
1350 if ( !a3DView().IsNull() ) {
1351 TCollection_AsciiString name;
1352 if (ThereIsArgument) {
1354 IsBound= GetMapOfAIS().IsBound2(name);
1356 if (TheAISContext()->HasOpenedContext())
1357 TheAISContext()->CloseLocalContext();
1359 if (TheAISContext() -> NbCurrents() > 0 )
1360 ThereIsCurrent =Standard_True;
1362 ThereIsCurrent =Standard_False;
1364 if ( ThereIsArgument && IsBound ) {
1365 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1366 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1367 const Handle(AIS_InteractiveObject) ashape =
1368 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1370 TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
1372 TheAISContext()->UnsetWidth (ashape);
1373 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1374 const Handle(NIS_Triangulated) ashape =
1375 Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
1376 if (HaveToSet && !ashape.IsNull())
1377 ashape->SetLineWidth ( Draw::Atof (argv[2]) );
1381 //=======================================================================
1382 // Il n'y a pas d'arguments
1383 // Mais un ou plusieurs objets on des current representation
1384 //=======================================================================
1385 if (ThereIsCurrent && !ThereIsArgument) {
1386 for (TheAISContext() -> InitCurrent() ;
1387 TheAISContext() -> MoreCurrent() ;
1388 TheAISContext() ->NextCurrent() )
1390 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1392 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1394 TheAISContext()->UnsetWidth(ashape,Standard_False);
1396 TheAISContext()->UpdateCurrentViewer();
1398 //=======================================================================
1399 // Il n'y a pas d'arguments ET aucun objet courrant
1400 //=======================================================================
1401 else if (!ThereIsCurrent && !ThereIsArgument){
1402 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1404 while ( it.More() ) {
1405 Handle(AIS_InteractiveObject) ashape =
1406 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1407 if (!ashape.IsNull()) {
1409 TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
1411 TheAISContext()->UnsetWidth(ashape,Standard_False);
1415 TheAISContext()->UpdateCurrentViewer();
1421 //==============================================================================
1422 //function : VInteriorStyle
1423 //purpose : sets interior style of the a selected or named or displayed shape
1424 //Draw arg : vsetinteriorstyle [shape] style
1425 //==============================================================================
1426 static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
1427 const Standard_Integer theStyle,
1428 Draw_Interpretor& di)
1430 if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
1431 di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
1432 " (Aspect_IS_HIDDENLINE)]\n";
1435 const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
1436 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1437 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1438 Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
1439 aFillAspect->SetInteriorStyle (aStyle);
1440 TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
1443 static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1445 if (argc < 2 || argc > 3) {
1446 di << argv[0] << " requires 2 or 3 arguments\n";
1447 di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
1448 di << "Style must match Aspect_InteriorStyle and be one of:\n";
1449 di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
1453 Standard_Boolean ThereIsCurrent;
1454 Standard_Boolean ThereIsArgument;
1455 Standard_Boolean IsBound = Standard_False ;
1457 ThereIsArgument = (argc > 2);
1458 if ( !a3DView().IsNull() ) {
1459 TCollection_AsciiString name;
1460 if (ThereIsArgument) {
1462 IsBound= GetMapOfAIS().IsBound2(name);
1464 if (TheAISContext()->HasOpenedContext())
1465 TheAISContext()->CloseLocalContext();
1467 if (TheAISContext() -> NbCurrents() > 0 )
1468 ThereIsCurrent =Standard_True;
1470 ThereIsCurrent =Standard_False;
1472 if ( ThereIsArgument && IsBound ) {
1473 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1474 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1475 const Handle(AIS_InteractiveObject) ashape =
1476 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1477 SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
1480 //=======================================================================
1481 // No arguments specified
1482 // But there are one or more selected objects
1483 //=======================================================================
1484 if (ThereIsCurrent && !ThereIsArgument) {
1485 for (TheAISContext() -> InitCurrent() ;
1486 TheAISContext() -> MoreCurrent() ;
1487 TheAISContext() ->NextCurrent() )
1489 Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
1490 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1493 //=======================================================================
1494 // No arguments specified and there are no selected objects
1495 //=======================================================================
1496 else if (!ThereIsCurrent && !ThereIsArgument){
1497 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1499 while ( it.More() ) {
1500 Handle(AIS_InteractiveObject) ashape =
1501 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
1502 if (!ashape.IsNull())
1503 SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
1507 TheAISContext()->UpdateCurrentViewer();
1512 //==============================================================================
1513 //function : VDonly2
1515 //purpose : Display only a selected or named object
1516 // if there is no selected or named object s, nothing is donne
1517 //Draw arg : vdonly2 [name1] ... [name n]
1518 //==============================================================================
1519 static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
1522 if ( a3DView().IsNull() )
1525 Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
1526 Standard_Boolean ThereIsArgument= argc>1;
1528 if (TheAISContext()->HasOpenedContext())
1529 TheAISContext()->CloseLocalContext();
1531 //===============================================================
1532 // Il n'y a pas d'arguments mais des objets selectionnes(current)
1534 //===============================================================
1535 if (!ThereIsArgument && ThereIsCurrent) {
1538 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1541 for(TheAISContext()->InitCurrent();
1542 TheAISContext()->MoreCurrent();
1543 TheAISContext()->NextCurrent()){
1544 Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
1545 TheAISContext()->Erase(aShape,Standard_False);}
1547 TheAISContext() ->UpdateCurrentViewer();
1548 //===============================================================
1549 // Il y a des arguments
1550 //===============================================================
1551 if (ThereIsArgument) {
1552 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1554 while ( it.More() ) {
1555 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1556 const Handle(AIS_InteractiveObject) aShape =
1557 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1558 TheAISContext()->Erase(aShape,Standard_False);
1559 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1560 const Handle(NIS_InteractiveObject) aShape =
1561 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1562 TheNISContext()->Erase(aShape);
1567 // On display les objets passes par parametre
1568 for (int i=1; i<argc ; i++) {
1569 TCollection_AsciiString name=argv[i];
1570 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
1572 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
1573 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1574 const Handle(AIS_InteractiveObject) aShape =
1575 Handle(AIS_InteractiveObject)::DownCast (anObj);
1576 TheAISContext()->Display(aShape, Standard_False);
1577 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1578 Handle(NIS_InteractiveObject) aShape =
1579 Handle(NIS_InteractiveObject)::DownCast (anObj);
1580 TheNISContext()->Display(aShape);
1584 TheAISContext() ->UpdateCurrentViewer();
1585 // TheNISContext() ->UpdateViews();
1590 //==============================================================================
1591 //function : VRemove
1592 //purpose : Removes selected or named objects.
1593 // If there is no selected or named objects,
1594 // all objects in the viewer can be removed with argument -all.
1595 // If -context is in arguments, the object is not deleted from the map of
1596 // objects (deleted only from the current context).
1597 //==============================================================================
1598 int VRemove (Draw_Interpretor& theDI,
1599 Standard_Integer theArgNb,
1600 const char** theArgVec)
1602 if (a3DView().IsNull())
1607 TheAISContext()->CloseAllContexts (Standard_False);
1609 //Standard_Boolean isStayedInMap = Standard_False;
1610 TCollection_AsciiString aContextOnlyStr ("-context");
1611 TCollection_AsciiString aRemoveAllStr ("-all");
1613 Standard_Boolean isContextOnly = (theArgNb > 1 && TCollection_AsciiString (theArgVec[1]) == aContextOnlyStr);
1615 Standard_Boolean isRemoveAll = (theArgNb == 3 && TCollection_AsciiString (theArgVec[2]) == aRemoveAllStr) ||
1616 (theArgNb == 2 && TCollection_AsciiString (theArgVec[1]) == aRemoveAllStr);
1618 NCollection_List<TCollection_AsciiString> anIONameList;
1622 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1623 anIter.More(); anIter.Next())
1625 anIONameList.Append (anIter.Key2());
1628 else if (isContextOnly ? theArgNb > 2 : theArgNb > 1) // removed objects names are in argument list
1630 for (Standard_Integer anIt = isContextOnly ? 2 : 1; anIt < theArgNb; ++anIt)
1632 TCollection_AsciiString aName = theArgVec[anIt];
1634 if (!GetMapOfAIS().IsBound2 (aName))
1636 theDI << aName.ToCString() << " was not bound to some object.\n";
1640 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
1642 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
1645 if (anIO->GetContext() != TheAISContext())
1647 theDI << aName.ToCString() << " was not displayed in current context.\n";
1648 theDI << "Please activate view with this object displayed and try again.\n";
1652 anIONameList.Append (aName);
1656 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
1657 if (!aNisIO.IsNull())
1659 anIONameList.Append (aName);
1663 else if (TheAISContext()->NbCurrents() > 0
1664 || TheNISContext()->GetSelected().Extent() > 0)
1666 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1667 anIter.More(); anIter.Next())
1669 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1672 if (!TheAISContext()->IsCurrent (anIO))
1677 anIONameList.Append (anIter.Key2());
1681 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1682 if (!aNisIO.IsNull())
1684 if (!TheNISContext()->IsSelected (aNisIO))
1689 anIONameList.Append (anIter.Key2());
1694 // Unbind all removed objects from the map of displayed IO.
1695 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
1696 anIter.More(); anIter.Next())
1698 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1702 TheAISContext()->Remove (anIO, Standard_False);
1703 theDI << anIter.Value().ToCString() << " was removed\n";
1707 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
1708 if (!aNisIO.IsNull())
1710 TheNISContext()->Remove (aNisIO);
1711 theDI << anIter.Value().ToCString() << " was removed\n";
1717 GetMapOfAIS().UnBind2 (anIter.Value());
1721 TheAISContext()->UpdateCurrentViewer();
1725 //==============================================================================
1727 //purpose : Erase some selected or named objects
1728 // if there is no selected or named objects, the whole viewer is erased
1729 //==============================================================================
1730 int VErase (Draw_Interpretor& theDI,
1731 Standard_Integer theArgNb,
1732 const char** theArgVec)
1734 if (a3DView().IsNull())
1739 TheAISContext()->CloseAllContexts (Standard_False);
1740 const Standard_Boolean isEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "").IsEqual ("veraseall");
1745 std::cerr << " Syntax error: " << theArgVec[0] << " too much arguments.\n";
1749 // has a list of names
1750 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
1752 TCollection_AsciiString aName = theArgVec[anArgIter];
1753 if (!GetMapOfAIS().IsBound2 (aName))
1758 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1759 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
1760 theDI << aName.ToCString() << " ";
1763 TheAISContext()->Erase (anIO, Standard_False);
1767 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
1768 if (!aNisIO.IsNull())
1770 TheNISContext()->Erase (aNisIO);
1774 TheAISContext()->UpdateCurrentViewer();
1779 && TheAISContext()->NbCurrents() > 0)
1781 // remove all currently selected objects
1782 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1783 anIter.More(); anIter.Next())
1785 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1787 && TheAISContext()->IsCurrent (anIO))
1789 theDI << anIter.Key2().ToCString() << " ";
1790 TheAISContext()->Erase (anIO, Standard_False);
1794 TheAISContext()->UpdateCurrentViewer();
1798 // erase entire viewer
1799 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
1800 anIter.More(); anIter.Next())
1802 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1805 TheAISContext()->Erase (anIO, Standard_False);
1809 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1810 if (!aNisIO.IsNull())
1812 TheNISContext()->Erase (aNisIO);
1816 TheAISContext()->UpdateCurrentViewer();
1820 //==============================================================================
1821 //function : VDisplayAll
1823 //purpose : Display all the objects of the Map
1824 //Draw arg : vdisplayall
1825 //==============================================================================
1826 static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1829 if (! a3DView().IsNull() ) {
1830 if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
1831 if (TheAISContext()->HasOpenedContext())
1832 TheAISContext()->CloseLocalContext();
1833 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
1835 while ( it.More() ) {
1836 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1837 const Handle(AIS_InteractiveObject) aShape =
1838 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1839 TheAISContext()->Erase(aShape,Standard_False);
1840 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1841 const Handle(NIS_InteractiveObject) aShape =
1842 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1843 TheNISContext()->Erase(aShape);
1848 while ( it.More() ) {
1849 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
1850 const Handle(AIS_InteractiveObject) aShape =
1851 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
1852 TheAISContext()->Display(aShape, Standard_False);
1853 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
1854 Handle(NIS_InteractiveObject) aShape =
1855 Handle(NIS_InteractiveObject)::DownCast(it.Key1());
1856 TheNISContext()->Display(aShape);
1860 TheAISContext() ->UpdateCurrentViewer();
1861 // TheNISContext() ->UpdateViews();
1866 //#######################################################################################################
1870 //#######################################################################################################
1872 Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
1874 Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
1875 (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
1876 (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
1877 (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
1878 (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
1880 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1881 if(myAISContext.IsNull())
1883 di << "use 'vinit' command before " << argv[0] << "\n";
1887 Handle(AIS_InteractiveObject) TheAisIO;
1888 Handle(AIS_TexturedShape) myShape;
1889 Standard_Integer myPreviousMode = 0;
1891 if (argc<2 || !argv[1])
1893 di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
1897 TCollection_AsciiString name = argv[1];
1898 ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
1900 if (GetMapOfAIS().IsBound2(name))
1901 TheAisIO = Handle(AIS_InteractiveObject)::DownCast
1902 (GetMapOfAIS().Find2(name));
1903 if (TheAisIO.IsNull())
1905 di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
1909 if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
1911 myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
1912 myPreviousMode = myShape->DisplayMode() ;
1916 myAISContext->Clear(TheAisIO,Standard_False);
1917 myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
1918 GetMapOfAIS().UnBind1(TheAisIO);
1919 GetMapOfAIS().UnBind2(name);
1920 GetMapOfAIS().Bind(myShape, name);
1924 case 1: // vtexture : we only map a texture on the shape
1927 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1930 if (argc>2 && argv[2])
1932 if(strcasecmp(argv[2],"?")==0)
1934 TCollection_AsciiString monPath = Graphic3d_TextureRoot::TexturesFolder();
1935 di<<"\n Files in current directory : \n"<<"\n";
1936 TCollection_AsciiString Cmnd ("glob -nocomplain *");
1937 di.Eval(Cmnd.ToCString());
1939 Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
1942 di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
1943 di.Eval(Cmnd.ToCString());
1948 myShape->SetTextureFileName(argv[2]);
1952 di <<"Texture mapping disabled \n \
1953 To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
1955 myAISContext->SetDisplayMode(myShape,1,Standard_False);
1956 if (myPreviousMode == 3 )
1957 myAISContext->RecomputePrsOnly(myShape);
1958 myAISContext->Display(myShape, Standard_True);
1963 case 2: // vtexscale : we change the scaling factor of the texture
1967 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1971 myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
1972 ( argv[2] ? Draw::Atof(argv[2]) : 1.0 ),
1973 ( argv[2] ? Draw::Atof(argv[argc-1]) : 1.0 ) );
1976 case 3: // vtexorigin : we change the origin of the texture on the shape
1979 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1982 myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
1983 ( argv[2] ? Draw::Atof(argv[2]) : 0.0 ),
1984 ( argv[2] ? Draw::Atof(argv[argc-1]) : 0.0 ));
1987 case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
1990 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
1993 if (argc>2 && argv[2])
1995 di <<"Texture repeat enabled"<<"\n";
1996 myShape->SetTextureRepeat(Standard_True, Draw::Atof(argv[2]), Draw::Atof(argv[argc-1]) );
2000 di <<"Texture repeat disabled"<<"\n";
2001 myShape->SetTextureRepeat(Standard_False);
2005 case 5: // vtexdefault : default texture mapping
2006 // ScaleU = ScaleV = 100.0
2007 // URepeat = VRepeat = 1.0
2008 // Uorigin = VOrigin = 0.0
2012 di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
2015 myShape->SetTextureRepeat(Standard_False);
2016 myShape->SetTextureOrigin(Standard_False);
2017 myShape->SetTextureScale (Standard_False);
2021 if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
2022 myAISContext->RecomputePrsOnly(myShape);
2025 myAISContext->SetDisplayMode(myShape,3,Standard_False);
2026 myAISContext->Display(myShape, Standard_True);
2027 myAISContext->Update(myShape,Standard_True);
2032 //==============================================================================
2033 //function : VDisplay2
2035 //purpose : Display an object from its name
2036 //Draw arg : vdisplay name1 [name2] ... [name n]
2037 //==============================================================================
2038 static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2041 // Verification des arguments
2042 if ( a3DView().IsNull() ) {
2044 ViewerTest::ViewerInit();
2045 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
2050 di<<argv[0]<<" Syntaxe error"<<"\n";
2055 TCollection_AsciiString name;
2056 if (TheAISContext()->HasOpenedContext())
2057 TheAISContext()->CloseLocalContext();
2059 for ( int i = 1; i < argc; i++ ) {
2061 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
2062 Standard_Boolean IsDatum = Standard_False;
2063 Handle(Standard_Transient) anObj;
2065 anObj = GetMapOfAIS().Find2(name);
2066 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
2067 Handle(AIS_InteractiveObject) aShape =
2068 Handle(AIS_InteractiveObject)::DownCast(anObj);
2069 if (aShape->Type()==AIS_KOI_Datum) {
2070 IsDatum = Standard_True;
2071 TheAISContext()->Display(aShape, Standard_False);
2074 di << "Display " << name.ToCString() << "\n";
2075 // Get the Shape from a name
2076 TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
2078 // Update the Shape in the AIS_Shape
2079 Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
2080 if(!TheRealSh.IsNull())
2081 TheRealSh->Set(NewShape);
2082 TheAISContext()->Redisplay(aShape, Standard_False);
2083 TheAISContext()->Display(aShape, Standard_False);
2086 } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
2087 Handle(NIS_InteractiveObject) aShape =
2088 Handle(NIS_InteractiveObject)::DownCast(anObj);
2089 TheNISContext()->Display(aShape);
2092 else { // Create the AIS_Shape from a name
2093 const Handle(AIS_InteractiveObject) aShape =
2094 GetAISShapeFromName((const char *)name.ToCString());
2095 if ( !aShape.IsNull() ) {
2096 GetMapOfAIS().Bind(aShape, name);
2097 TheAISContext()->Display(aShape, Standard_False);
2101 // Upadate the screen and redraw the view
2102 TheAISContext()->UpdateCurrentViewer();
2103 // TheNISContext()->UpdateViews();
2107 //==============================================================================
2109 //purpose : Test the annimation of an object along a
2110 // predifined trajectory
2111 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2112 //==============================================================================
2114 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2117 if (TheAISContext()->HasOpenedContext())
2118 TheAISContext()->CloseLocalContext();
2120 Standard_Real Step=4*M_PI/180;
2121 Standard_Real Angle=0;
2123 Handle(AIS_InteractiveObject) aIO;
2124 if (GetMapOfAIS().IsBound2(argv[1]))
2125 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2129 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2133 if (Draw::Atoi(argv[3])==1 ) {
2134 di<<" Primitives sensibles OFF"<<"\n";
2135 TheAISContext()->Deactivate(aIO);
2138 di<<" Primitives sensibles ON"<<"\n";
2140 // Movement par transformation
2141 if(Draw::Atoi(argv[2]) ==1) {
2142 di<<" Calcul par Transformation"<<"\n";
2143 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2147 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2148 TheAISContext()->SetLocation(aShape,myTransfo);
2149 TheAISContext() ->UpdateCurrentViewer();
2154 di<<" Calcul par Locations"<<"\n";
2155 gp_Trsf myAngleTrsf;
2156 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2157 TopLoc_Location myDeltaAngle (myAngleTrsf);
2158 TopLoc_Location myTrueLoc;
2160 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2163 myTrueLoc=myTrueLoc*myDeltaAngle;
2164 TheAISContext()->SetLocation(aShape,myTrueLoc );
2165 TheAISContext() ->UpdateCurrentViewer();
2168 if (Draw::Atoi(argv[3])==1 ){
2169 // On reactive la selection des primitives sensibles
2170 TheAISContext()->Activate(aIO,0);
2172 a3DView() -> Redraw();
2174 di<<" Temps ecoule "<<"\n";
2180 //==================================================================================
2181 // Function : VAnimation
2182 //==================================================================================
2183 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2185 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2189 Standard_Real thread = 4;
2190 Standard_Real angleA=0;
2191 Standard_Real angleB;
2193 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2196 TopoDS_Shape CrankArm;
2197 TopoDS_Shape CylinderHead;
2198 TopoDS_Shape Propeller;
2199 TopoDS_Shape EngineBlock;
2201 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2202 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2203 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2204 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2205 BRepTools::Read(CrankArm,argv[1],B);
2206 BRepTools::Read(CylinderHead,argv[2],B);
2207 BRepTools::Read(Propeller,argv[3],B);
2208 BRepTools::Read(EngineBlock,argv[4],B);
2210 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2216 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
2217 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
2218 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
2219 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
2221 GetMapOfAIS().Bind(myAisCylinderHead,"a");
2222 GetMapOfAIS().Bind(myAisEngineBlock,"b");
2223 GetMapOfAIS().Bind(myAisCrankArm,"c");
2224 GetMapOfAIS().Bind(myAisPropeller,"d");
2226 TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
2227 TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
2228 TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN);
2230 TheAISContext()->Display(myAisCylinderHead,Standard_False);
2231 TheAISContext()->Display(myAisEngineBlock,Standard_False );
2232 TheAISContext()->Display(myAisCrankArm,Standard_False );
2233 TheAISContext()->Display(myAisPropeller,Standard_False);
2235 TheAISContext()->Deactivate(myAisCylinderHead);
2236 TheAISContext()->Deactivate(myAisEngineBlock );
2237 TheAISContext()->Deactivate(myAisCrankArm );
2238 TheAISContext()->Deactivate(myAisPropeller );
2240 // Boucle de mouvement
2241 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
2243 angleA = thread*myAngle*M_PI/180;
2244 X = Sin(angleA)*3/8;
2245 angleB = atan(X / Sqrt(-X * X + 1));
2246 Standard_Real decal(25*0.6);
2249 //Build a transformation on the display
2250 gp_Trsf aPropellerTrsf;
2251 aPropellerTrsf.SetRotation(Ax1,angleA);
2252 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
2254 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));
2255 gp_Trsf aCrankArmTrsf;
2256 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
2257 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
2259 TheAISContext()->UpdateCurrentViewer();
2262 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
2263 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
2265 myAisCrankArm ->ResetLocation();
2266 myAisPropeller->ResetLocation();
2268 myAisCrankArm -> Set(myNewCrankArm );
2269 myAisPropeller -> Set(myNewPropeller);
2271 TheAISContext()->Activate(myAisCylinderHead,0);
2272 TheAISContext()->Activate(myAisEngineBlock,0 );
2273 TheAISContext()->Activate(myAisCrankArm ,0 );
2274 TheAISContext()->Activate(myAisPropeller ,0 );
2280 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
2281 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
2283 TheAISContext()->UpdateCurrentViewer();
2284 a3DView()->Redraw();
2293 //==============================================================================
2294 //function : VShading
2295 //purpose : Sharpen or roughten the quality of the shading
2296 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
2297 //==============================================================================
2298 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
2300 Standard_Real myDevCoef;
2301 Handle(AIS_InteractiveObject) TheAisIO;
2304 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
2306 if (TheAISContext()->HasOpenedContext())
2307 TheAISContext()->CloseLocalContext();
2312 myDevCoef =Draw::Atof(argv[2]);
2315 TCollection_AsciiString name=argv[1];
2316 if (GetMapOfAIS().IsBound2(name ))
2317 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
2318 if (TheAisIO.IsNull())
2319 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
2322 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
2324 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
2326 TheAISContext()->Redisplay(TheAisIO);
2329 //==============================================================================
2330 //function : HaveMode
2331 //use : VActivatedModes
2332 //==============================================================================
2333 #include <TColStd_ListIteratorOfListOfInteger.hxx>
2335 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
2337 TColStd_ListOfInteger List;
2338 TheAISContext()->ActivatedModes (TheAisIO,List);
2339 TColStd_ListIteratorOfListOfInteger it;
2340 Standard_Boolean Found=Standard_False;
2341 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
2342 if (it.Value()==mode ) Found=Standard_True;
2349 //==============================================================================
2350 //function : VActivatedMode
2352 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
2353 // (edges,vertex...)qui lui est propre et le mode de selection standard.
2354 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
2355 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
2356 // qu'un nom et qu'un mode.
2357 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
2358 //==============================================================================
2359 #include <AIS_ListIteratorOfListOfInteractive.hxx>
2361 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2364 Standard_Boolean ThereIsName = Standard_False ;
2366 if(!a3DView().IsNull()){
2368 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
2369 // verification des arguments
2371 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
2372 ThereIsName = (argc == 3);
2376 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
2378 di<<" R.A.Z de tous les modes de selecion"<<"\n";
2379 di<<" Fermeture du Context local"<<"\n";
2380 if (TheAISContext()->HasOpenedContext())
2381 TheAISContext()->CloseLocalContext();
2385 // IL n'y a aps de nom de shape passe en argument
2386 if (HaveToSet && !ThereIsName){
2387 Standard_Integer aMode=Draw::Atoi(argv [1]);
2389 const char *cmode="???";
2391 case 0: cmode = "Shape"; break;
2392 case 1: cmode = "Vertex"; break;
2393 case 2: cmode = "Edge"; break;
2394 case 3: cmode = "Wire"; break;
2395 case 4: cmode = "Face"; break;
2396 case 5: cmode = "Shell"; break;
2397 case 6: cmode = "Solid"; break;
2398 case 7: cmode = "Compound"; break;
2401 if( !TheAISContext()->HasOpenedContext() ) {
2402 // il n'y a pas de Context local d'ouvert
2403 // on en ouvre un et on charge toutes les shapes displayees
2404 // on load tous les objets displayees et on Activate les objets de la liste
2405 AIS_ListOfInteractive ListOfIO;
2406 // on sauve dans une AISListOfInteractive tous les objets currents
2407 if (TheAISContext()->NbCurrents()>0 ){
2408 TheAISContext()->UnhilightCurrents(Standard_False);
2410 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
2411 ListOfIO.Append(TheAISContext()->Current() );
2415 TheAISContext()->OpenLocalContext(Standard_False);
2416 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2419 Handle(AIS_InteractiveObject) aIO =
2420 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2422 TheAISContext()->Load(aIO,0,Standard_False);
2425 // traitement des objets qui etaient currents dans le Contexte global
2426 if (!ListOfIO.IsEmpty() ) {
2427 // il y avait des objets currents
2428 AIS_ListIteratorOfListOfInteractive iter;
2429 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
2430 Handle(AIS_InteractiveObject) aIO=iter.Value();
2431 TheAISContext()->Activate(aIO,aMode);
2432 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2436 // On applique le mode a tous les objets displayes
2437 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2438 it2 (GetMapOfAIS());
2440 Handle(AIS_InteractiveObject) aIO =
2441 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
2442 if (!aIO.IsNull()) {
2443 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
2444 TheAISContext()->Activate(aIO,aMode);
2453 // un Context local est deja ouvert
2454 // Traitement des objets du Context local
2455 if (TheAISContext()->NbSelected()>0 ){
2456 TheAISContext()->UnhilightSelected(Standard_False);
2457 // il y a des objets selected,on les parcourt
2458 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
2459 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
2462 if (HaveMode(aIO,aMode) ) {
2463 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2464 TheAISContext()->Deactivate(aIO,aMode);
2467 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2468 TheAISContext()->Activate(aIO,aMode);
2474 // il n'y a pas d'objets selected
2475 // tous les objets diplayes sont traites
2476 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2479 Handle(AIS_InteractiveObject) aIO =
2480 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2481 if (!aIO.IsNull()) {
2482 if (HaveMode(aIO,aMode) ) {
2483 di<<" Mode: "<<cmode<<" OFF pour "
2484 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2485 TheAISContext()->Deactivate(aIO,aMode);
2488 di<<" Mode: "<<cmode<<" ON pour"
2489 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2490 TheAISContext()->Activate(aIO,aMode);
2498 else if (HaveToSet && ThereIsName){
2499 Standard_Integer aMode=Draw::Atoi(argv [2]);
2500 Handle(AIS_InteractiveObject) aIO =
2501 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2503 if (!aIO.IsNull()) {
2504 const char *cmode="???";
2507 case 0: cmode = "Shape"; break;
2508 case 1: cmode = "Vertex"; break;
2509 case 2: cmode = "Edge"; break;
2510 case 3: cmode = "Wire"; break;
2511 case 4: cmode = "Face"; break;
2512 case 5: cmode = "Shell"; break;
2513 case 6: cmode = "Solid"; break;
2514 case 7: cmode = "Compound"; break;
2517 if( !TheAISContext()->HasOpenedContext() ) {
2518 TheAISContext()->OpenLocalContext(Standard_False);
2519 // On charge tous les objets de la map
2520 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
2522 Handle(AIS_InteractiveObject) aShape=
2523 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2524 if (!aShape.IsNull())
2525 TheAISContext()->Load(aShape,0,Standard_False);
2528 TheAISContext()->Activate(aIO,aMode);
2529 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2533 // un Context local est deja ouvert
2534 if (HaveMode(aIO,aMode) ) {
2535 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
2536 TheAISContext()->Deactivate(aIO,aMode);
2539 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
2540 TheAISContext()->Activate(aIO,aMode);
2552 //==============================================================================
2553 // function : WhoAmI
2555 //==============================================================================
2556 void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
2559 if (theShape->Type()==AIS_KOI_Datum) {
2560 if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
2561 else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
2562 else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
2563 else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
2564 else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
2565 else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
2566 else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
2569 else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
2570 // AIS_Dimentions et AIS_Relations
2571 else if (theShape->Type()==AIS_KOI_Relation) {
2572 Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
2574 if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
2575 else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
2576 else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
2577 else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
2578 //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
2579 else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
2580 else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
2581 // AIS no repertorie.
2582 else {di<<" Type Unknown.";}
2588 //==============================================================================
2591 //Draw arg : vstate [nameA] ... [nameN]
2592 //==============================================================================
2593 static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2595 TheAISContext()->CloseAllContexts();
2596 const Standard_Boolean ThereIsArguments=(argc>=2);
2597 const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
2599 // ==================
2600 // Il y a un argument
2601 // ==================
2602 if (ThereIsArguments) {
2603 for (int cpt=1;cpt<argc;cpt++) {
2604 // Verification que lq piece est bien bindee.
2605 if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
2606 const Handle(AIS_InteractiveObject) theShape=
2607 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
2609 if (!theShape.IsNull()) {
2610 di<<argv[cpt];WhoAmI(theShape, di);
2611 if (TheAISContext()->IsDisplayed(theShape) ) {
2612 di<<" Displayed"<<"\n";
2615 di<<" Not Displayed"<<"\n";
2620 di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
2624 else if (ThereIsCurrent ) {
2625 for (TheAISContext() -> InitCurrent() ;
2626 TheAISContext() -> MoreCurrent() ;
2627 TheAISContext() ->NextCurrent() )
2629 Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
2630 di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
2631 if (TheAISContext()->IsDisplayed(theShape) ) {
2632 di<<" Displayed"<<"\n";
2635 di<<" Not Displayed"<<"\n";
2641 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
2643 while ( it.More() ) {
2644 Handle(AIS_InteractiveObject) theShape =
2645 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
2646 if (!theShape.IsNull()) {
2647 di<<it.Key2().ToCString();
2648 WhoAmI(theShape, di);
2649 if (TheAISContext()->IsDisplayed(theShape) ) {
2650 di<<" Displayed"<<"\n";
2653 di<<" Not Displayed"<<"\n";
2664 //=======================================================================
2665 //function : PickObjects
2667 //=======================================================================
2668 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
2669 const AIS_KindOfInteractive TheType,
2670 const Standard_Integer TheSignature,
2671 const Standard_Integer MaxPick)
2673 Handle(AIS_InteractiveObject) IO;
2674 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2676 // step 1: prepare the data
2678 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2679 TheAISContext()->AddFilter(F1);
2682 // step 2 : wait for the selection...
2683 // Standard_Boolean IsGood (Standard_False);
2684 // Standard_Integer NbPick(0);
2685 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
2686 Standard_Integer NbPickFail(0);
2687 Standard_Integer argccc = 5;
2688 const char *bufff[] = { "A", "B", "C","D", "E" };
2689 const char **argvvv = (const char **) bufff;
2692 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2693 while(ViewerMainLoop(argccc,argvvv)){}
2694 Standard_Integer NbStored = TheAISContext()->NbSelected();
2695 if((unsigned int ) NbStored != NbPickGood)
2696 NbPickGood= NbStored;
2699 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
2702 // step3 get result.
2704 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2706 Standard_Integer i(0);
2707 for(TheAISContext()->InitSelected();
2708 TheAISContext()->MoreSelected();
2709 TheAISContext()->NextSelected()){
2711 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
2712 arr->SetValue(i,IO2);
2717 TheAISContext()->CloseLocalContext(curindex);
2719 return Standard_True;
2723 //=======================================================================
2724 //function : PickObject
2726 //=======================================================================
2727 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
2728 const Standard_Integer TheSignature,
2729 const Standard_Integer MaxPick)
2731 Handle(AIS_InteractiveObject) IO;
2732 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
2734 // step 1: prepare the data
2737 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
2738 TheAISContext()->AddFilter(F1);
2741 // step 2 : wait for the selection...
2742 Standard_Boolean IsGood (Standard_False);
2743 Standard_Integer NbPick(0);
2744 Standard_Integer argccc = 5;
2745 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2746 const char **argvvv = (const char **) bufff;
2749 while(!IsGood && NbPick<= MaxPick){
2750 while(ViewerMainLoop(argccc,argvvv)){}
2751 IsGood = (TheAISContext()->NbSelected()>0) ;
2753 cout<<"Nb Pick :"<<NbPick<<endl;
2757 // step3 get result.
2759 TheAISContext()->InitSelected();
2760 IO = TheAISContext()->SelectedInteractive();
2764 TheAISContext()->CloseLocalContext(curindex);
2768 //=======================================================================
2769 //function : PickShape
2770 //purpose : First Activate the rightmode + Put Filters to be able to
2771 // pick objets that are of type <TheType>...
2772 //=======================================================================
2774 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
2775 const Standard_Integer MaxPick)
2778 // step 1: prepare the data
2780 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2781 TopoDS_Shape result;
2783 if(TheType==TopAbs_SHAPE){
2784 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2785 TheAISContext()->AddFilter(F1);
2788 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2789 TheAISContext()->AddFilter(TF);
2790 TheAISContext()->ActivateStandardMode(TheType);
2795 // step 2 : wait for the selection...
2796 Standard_Boolean NoShape (Standard_True);
2797 Standard_Integer NbPick(0);
2798 Standard_Integer argccc = 5;
2799 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2800 const char **argvvv = (const char **) bufff;
2803 while(NoShape && NbPick<= MaxPick){
2804 while(ViewerMainLoop(argccc,argvvv)){}
2805 NoShape = (TheAISContext()->NbSelected()==0) ;
2807 cout<<"Nb Pick :"<<NbPick<<endl;
2810 // step3 get result.
2814 TheAISContext()->InitSelected();
2815 if(TheAISContext()->HasSelectedShape())
2816 result = TheAISContext()->SelectedShape();
2818 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2819 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
2824 TheAISContext()->CloseLocalContext(curindex);
2830 //=======================================================================
2831 //function : PickShapes
2833 //=======================================================================
2834 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
2835 Handle(TopTools_HArray1OfShape)& thearr,
2836 const Standard_Integer MaxPick)
2839 Standard_Integer Taille = thearr->Length();
2841 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
2843 // step 1: prepare the data
2844 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
2845 if(TheType==TopAbs_SHAPE){
2846 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
2847 TheAISContext()->AddFilter(F1);
2850 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
2851 TheAISContext()->AddFilter(TF);
2852 TheAISContext()->ActivateStandardMode(TheType);
2856 // step 2 : wait for the selection...
2858 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
2859 Standard_Integer NbPickFail(0);
2860 Standard_Integer argccc = 5;
2861 const char *bufff[] = { "A", "B", "C","D", "E" };
2862 const char **argvvv = (const char **) bufff;
2865 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
2866 while(ViewerMainLoop(argccc,argvvv)){}
2867 Standard_Integer NbStored = TheAISContext()->NbSelected();
2868 if((unsigned int ) NbStored != NbPickGood)
2869 NbPickGood= NbStored;
2872 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
2875 // step3 get result.
2877 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
2879 Standard_Integer i(0);
2880 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
2882 if(TheAISContext()->HasSelectedShape())
2883 thearr->SetValue(i,TheAISContext()->SelectedShape());
2885 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
2886 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
2890 TheAISContext()->CloseLocalContext(curindex);
2891 return Standard_True;
2895 //=======================================================================
2896 //function : VPickShape
2898 //=======================================================================
2899 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2901 TopoDS_Shape PickSh;
2902 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
2905 theType = TopAbs_SHAPE;
2907 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
2908 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
2909 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
2910 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
2911 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
2912 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
2913 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
2916 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
2917 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
2919 TCollection_AsciiString name;
2922 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
2924 PickSh = ViewerTest::PickShape(theType);
2933 if(!PickSh.IsNull()){
2934 nbOfSub[Standard_Integer(theType)]++;
2936 name += nameType[Standard_Integer(theType)];
2937 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2942 // si on avait une petite methode pour voir si la shape
2943 // est deja dans la Double map, ca eviterait de creer....
2944 DBRep::Set(name.ToCString(),PickSh);
2946 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2947 GetMapOfAIS().Bind(newsh, name);
2948 TheAISContext()->Display(newsh);
2949 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
2952 // Plusieurs objets a picker, vite vite vite....
2955 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
2956 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
2957 if(ViewerTest::PickShapes(theType,arr)){
2958 for(Standard_Integer i=1;i<=NbToPick;i++){
2959 PickSh = arr->Value(i);
2960 if(!PickSh.IsNull()){
2962 nbOfSub[Standard_Integer(theType)]++;
2965 name += nameType[Standard_Integer(theType)];
2966 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
2974 DBRep::Set(name.ToCString(),PickSh);
2975 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
2976 GetMapOfAIS().Bind(newsh, name);
2977 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
2978 TheAISContext()->Display(newsh);
2986 //=======================================================================
2987 //function : list of known objects
2989 //=======================================================================
2990 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
2992 // 1234567890 12345678901234567 123456789
2993 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
2994 TCollection_AsciiString BlankLine(64,'_');
2995 Standard_Integer i ;
2997 di<<"/n"<<BlankLine.ToCString()<<"\n";
3000 Colum[i].Center(20,' ');
3002 di<<"|"<<Colum[i].ToCString();
3005 di<<BlankLine.ToCString()<<"\n";
3007 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3008 const char ** names = GetTypeNames();
3010 TCollection_AsciiString curstring;
3011 TCollection_AsciiString curcolum[3];
3014 // les objets de type Datum..
3015 curcolum[1]+="Datum";
3017 curcolum[0].Clear();
3018 curcolum[0] += names[i];
3020 curcolum[2].Clear();
3021 curcolum[2]+=TCollection_AsciiString(i+1);
3023 for(Standard_Integer j =0;j<=2;j++){
3024 curcolum[j].Center(20,' ');
3025 di<<"|"<<curcolum[j].ToCString();
3029 di<<BlankLine.ToCString()<<"\n";
3031 // les objets de type shape
3032 curcolum[1].Clear();
3033 curcolum[1]+="Shape";
3034 curcolum[1].Center(20,' ');
3037 curcolum[0].Clear();
3038 curcolum[0] += names[7+i];
3039 curcolum[2].Clear();
3040 curcolum[2]+=TCollection_AsciiString(i);
3042 for(Standard_Integer j =0;j<=2;j++){
3043 curcolum[j].Center(20,' ');
3044 di<<"|"<<curcolum[j].ToCString();
3048 di<<BlankLine.ToCString()<<"\n";
3049 // les IO de type objet...
3050 curcolum[1].Clear();
3051 curcolum[1]+="Object";
3052 curcolum[1].Center(20,' ');
3054 curcolum[0].Clear();
3055 curcolum[0] += names[10+i];
3056 curcolum[2].Clear();
3057 curcolum[2]+=TCollection_AsciiString(i);
3059 for(Standard_Integer j =0;j<=2;j++){
3060 curcolum[j].Center(20,' ');
3061 di<<"|"<<curcolum[j].ToCString();
3065 di<<BlankLine.ToCString()<<"\n";
3066 // les contraintes et dimensions.
3067 // pour l'instant on separe juste contraintes et dimensions...
3068 // plus tard, on detaillera toutes les sortes...
3069 curcolum[1].Clear();
3070 curcolum[1]+="Relation";
3071 curcolum[1].Center(20,' ');
3073 curcolum[0].Clear();
3074 curcolum[0] += names[12+i];
3075 curcolum[2].Clear();
3076 curcolum[2]+=TCollection_AsciiString(i);
3078 for(Standard_Integer j =0;j<=2;j++){
3079 curcolum[j].Center(20,' ');
3080 di<<"|"<<curcolum[j].ToCString();
3084 di<<BlankLine.ToCString()<<"\n";
3091 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3093 if(argc!=2) return 1;
3095 AIS_KindOfInteractive TheType;
3096 Standard_Integer TheSign(-1);
3097 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3100 AIS_ListOfInteractive LIO;
3102 // en attendant l'amelioration ais pour les dimensions...
3104 Standard_Integer dimension_status(-1);
3105 if(TheType==AIS_KOI_Relation){
3106 dimension_status = TheSign ==1 ? 1 : 0;
3110 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3111 Handle(AIS_InteractiveObject) curio;
3112 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3115 if(dimension_status == -1)
3116 TheAISContext()->Erase(curio,Standard_False);
3118 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3119 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3120 (dimension_status==1 && KOD != AIS_KOD_NONE))
3121 TheAISContext()->Erase(curio,Standard_False);
3124 TheAISContext()->UpdateCurrentViewer();
3127 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
3129 if(argc!=2) return 1;
3131 AIS_KindOfInteractive TheType;
3132 Standard_Integer TheSign(-1);
3133 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3135 // en attendant l'amelioration ais pour les dimensions...
3137 Standard_Integer dimension_status(-1);
3138 if(TheType==AIS_KOI_Relation){
3139 dimension_status = TheSign ==1 ? 1 : 0;
3143 AIS_ListOfInteractive LIO;
3144 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
3145 Handle(AIS_InteractiveObject) curio;
3146 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3148 if(dimension_status == -1)
3149 TheAISContext()->Display(curio,Standard_False);
3151 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3152 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3153 (dimension_status==1 && KOD != AIS_KOD_NONE))
3154 TheAISContext()->Display(curio,Standard_False);
3159 TheAISContext()->UpdateCurrentViewer();
3163 //==============================================================================
3164 //function : VSetTransMode
3166 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
3167 //==============================================================================
3169 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3170 // Verification des arguments
3171 if ( a3DView().IsNull() ) {
3172 ViewerTest::ViewerInit();
3173 di << "La commande vinit n'a pas ete appele avant" << "\n";
3176 if ( argc < 3 || argc > 8 ) {
3177 di << argv[0] << " Invalid number of arguments" << "\n";
3181 TCollection_AsciiString shapeName;
3182 shapeName = argv[1];
3183 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
3184 Standard_Integer persFlag2 = 0;
3185 Standard_Integer persFlag3 = 0;
3186 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
3187 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
3188 persFlag2 = Draw::Atoi(argv[3]);
3190 if ( argc == 5 || argc == 8 ) {
3191 persFlag3 = Draw::Atoi(argv[4]);
3194 origin.SetX( Draw::Atof(argv[argc - 3]) );
3195 origin.SetY( Draw::Atof(argv[argc - 2]) );
3196 origin.SetZ( Draw::Atof(argv[argc - 1]) );
3199 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
3200 Handle(Standard_Transient) anObj;
3202 anObj = GetMapOfAIS().Find2(shapeName);
3203 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
3204 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
3205 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3206 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
3207 di << argv[0] << " All persistence modifiers were removed" << "\n";
3210 di << argv[0] << " Wrong object type" << "\n";
3213 } else { // Create the AIS_Shape from a name
3214 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
3215 if ( !aShape.IsNull() ) {
3216 GetMapOfAIS().Bind( aShape, shapeName );
3217 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
3218 TheAISContext()->Display( aShape, Standard_False );
3220 di << argv[0] << " Object not found" << "\n";
3225 // Upadate the screen and redraw the view
3226 TheAISContext()->UpdateCurrentViewer();
3230 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
3233 BRep_Builder builder;
3235 BRepTools::Read(shape, s, builder);
3236 DBRep::Set(a[1], shape);
3237 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3238 Handle(AIS_Shape) ais = new AIS_Shape(shape);
3243 //==============================================================================
3244 //function : ViewerTest::Commands
3245 //purpose : Add all the viewer command in the Draw_Interpretor
3246 //==============================================================================
3248 void ViewerTest::Commands(Draw_Interpretor& theCommands)
3250 ViewerTest::ViewerCommands(theCommands);
3251 ViewerTest::RelationCommands(theCommands);
3252 ViewerTest::ObjectCommands(theCommands);
3253 ViewerTest::FilletCommands(theCommands);
3254 ViewerTest::VoxelCommands(theCommands);
3255 ViewerTest::OpenGlCommands(theCommands);
3257 const char *group = "AIS_Display";
3260 theCommands.Add("visos",
3261 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
3262 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
3263 __FILE__, visos, group);
3265 theCommands.Add("vdisplay",
3266 "vdisplay name1 [name2] ... [name n]"
3267 "\n\t\t: Displays named objects",
3268 __FILE__,VDisplay2,group);
3270 theCommands.Add("verase",
3271 "verase [name1] ... [name n]"
3272 "\n\t\t: Erases selected or named objects."
3273 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
3274 __FILE__, VErase, group);
3276 theCommands.Add("vremove",
3277 "vremove [-context] [name1] ... [name n]"
3278 "or vremove [-context] -all to remove all objects"
3279 "\n\t\t: Removes selected or named objects."
3280 "\n\t\t If -context is in arguments, the objects are not deleted"
3281 "\n\t\t from the map of objects and names.",
3282 __FILE__, VRemove, group);
3284 theCommands.Add("vdonly",
3285 "vdonly [name1] ... [name n]"
3286 "\n\t\t: Displays only selected or named objects",
3287 __FILE__,VDonly2,group);
3289 theCommands.Add("vdisplayall",
3290 "Displays all erased interactive objects (see vdir and vstate)",
3291 __FILE__,VDisplayAll,group);
3293 theCommands.Add("veraseall",
3294 "Erases all objects displayed in the viewer",
3295 __FILE__, VErase, group);
3297 theCommands.Add("verasetype",
3299 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
3300 __FILE__,VEraseType,group);
3302 theCommands.Add("vdisplaytype",
3303 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
3304 __FILE__,VDisplayType,group);
3306 theCommands.Add("vdisplaymode",
3307 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
3308 __FILE__,VDispMode,group);
3310 theCommands.Add("verasemode",
3311 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
3312 __FILE__,VDispMode,group);
3314 theCommands.Add("vsetdispmode",
3315 "vsetdispmode [name] mode(1,2,..)"
3316 "\n\t\t: Sets display mode for all, selected or named objects.",
3317 __FILE__,VDispMode,group);
3319 theCommands.Add("vunsetdispmode",
3320 "vunsetdispmode [name]"
3321 "\n\t\t: Unsets custom display mode for selected or named objects.",
3322 __FILE__,VDispMode,group);
3324 theCommands.Add("vdir",
3325 "Lists all objects displayed in 3D viewer",
3326 __FILE__,VDebug,group);
3328 theCommands.Add("vdump",
3329 #ifdef HAVE_FREEIMAGE
3330 "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]"
3331 "\n\t\t: Dumps contents of viewer window to PNG, BMP, JPEG or GIF file",
3333 "<filename>.{ppm} [buffer={rgb|rgba|depth}] [width height]"
3334 "\n\t\t: Dumps contents of viewer window to PPM image file",
3336 __FILE__,VDump,group);
3338 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
3339 __FILE__,VSubInt,group);
3341 theCommands.Add("vsetcolor",
3342 "vsetcolor [name] ColorName"
3343 "\n\t\t: Sets color for all, selected or named objects.",
3344 __FILE__,VColor2,group);
3346 theCommands.Add("vunsetcolor",
3347 "vunsetcolor [name]"
3348 "\n\t\t: Resets color for all, selected or named objects.",
3349 __FILE__,VColor2,group);
3351 theCommands.Add("vsettransparency",
3352 "vsettransparency [name] Coefficient"
3353 "\n\t\t: Sets transparency for all, selected or named objects."
3354 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
3355 __FILE__,VTransparency,group);
3357 theCommands.Add("vunsettransparency",
3358 "vunsettransparency [name]"
3359 "\n\t\t: Resets transparency for all, selected or named objects.",
3360 __FILE__,VTransparency,group);
3362 theCommands.Add("vsetmaterial",
3363 "vmaterial : vmaterial [name of shape] MaterialName",
3364 __FILE__,VMaterial,group);
3366 theCommands.Add("vunsetmaterial",
3367 "vmaterial : vmaterial [name of shape]",
3368 __FILE__,VMaterial,group);
3370 theCommands.Add("vsetwidth",
3371 "vsetwidth : vwidth [name of shape] width(0->10)",
3372 __FILE__,VWidth,group);
3374 theCommands.Add("vunsetwidth",
3375 "vunsetwidth : vwidth [name of shape]",
3376 __FILE__,VWidth,group);
3378 theCommands.Add("vsetinteriorstyle",
3379 "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
3380 __FILE__,VInteriorStyle,group);
3382 theCommands.Add("vardis",
3383 "vardis : display activeareas",
3384 __FILE__,VDispAreas,group);
3386 theCommands.Add("varera",
3387 "varera : erase activeareas",
3388 __FILE__,VClearAreas,group);
3390 theCommands.Add("vsensdis",
3391 "vardisp : display active entities",
3392 __FILE__,VDispSensi,group);
3393 theCommands.Add("vsensera",
3394 "vardisp : erase active entities",
3395 __FILE__,VClearSensi,group);
3397 theCommands.Add("vselprecision",
3398 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
3399 __FILE__,VSelPrecision,group);
3401 theCommands.Add("vperf",
3402 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
3403 __FILE__,VPerf,group);
3405 theCommands.Add("vanimation",
3406 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
3407 __FILE__,VAnimation,group);
3409 theCommands.Add("vsetshading",
3410 "vsetshading : vsetshading name Quality(default=0.0008) ",
3411 __FILE__,VShading,group);
3413 theCommands.Add("vunsetshading",
3414 "vunsetshading :vunsetshading name ",
3415 __FILE__,VShading,group);
3417 theCommands.Add("vtexture",
3418 "'vtexture NameOfShape TextureFile' \n \
3419 or 'vtexture NameOfShape' if you want to disable texture mapping \n \
3420 or 'vtexture NameOfShape ?' to list available textures\n \
3421 or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
3422 __FILE__,VTexture,group);
3424 theCommands.Add("vtexscale",
3425 "'vtexscale NameOfShape ScaleU ScaleV' \n \
3426 or 'vtexscale NameOfShape ScaleUV' \n \
3427 or 'vtexscale NameOfShape' to disable scaling\n ",
3428 __FILE__,VTexture,group);
3430 theCommands.Add("vtexorigin",
3431 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
3432 or 'vtexorigin NameOfShape UVOrigin' \n \
3433 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
3434 __FILE__,VTexture,group);
3436 theCommands.Add("vtexrepeat",
3437 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
3438 or 'vtexrepeat NameOfShape UVRepeat \n \
3439 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
3442 theCommands.Add("vtexdefault",
3443 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
3446 theCommands.Add("vsetam",
3447 "vsetActivatedModes: vsetam mode(1->7) ",
3448 __FILE__,VActivatedMode,group);
3450 theCommands.Add("vunsetam",
3451 "vunsetActivatedModes: vunsetam ",
3452 __FILE__,VActivatedMode,group);
3454 theCommands.Add("vstate",
3455 "vstate [name1] ... [nameN]"
3456 "\n\t\t: Reports show/hidden state for selected or named objects",
3457 __FILE__,VState,group);
3459 theCommands.Add("vpickshapes",
3460 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
3461 __FILE__,VPickShape,group);
3463 theCommands.Add("vtypes",
3464 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
3467 theCommands.Add("vsettransmode",
3468 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
3469 __FILE__,VSetTransMode,group);
3471 theCommands.Add("vr", "vr : reading of the shape",
3472 __FILE__,vr, group);
3476 //=====================================================================
3477 //========================= for testing Draft and Rib =================
3478 //=====================================================================
3479 #include <BRepOffsetAPI_MakeThickSolid.hxx>
3480 #include <DBRep.hxx>
3481 #include <TopoDS_Face.hxx>
3482 #include <gp_Pln.hxx>
3483 #include <AIS_KindOfSurface.hxx>
3484 #include <BRepOffsetAPI_DraftAngle.hxx>
3485 #include <Precision.hxx>
3486 #include <BRepAlgo.hxx>
3487 #include <OSD_Environment.hxx>
3488 #include <DrawTrSurf.hxx>
3489 //#include <DbgTools.hxx>
3490 //#include <FeatAlgo_MakeLinearForm.hxx>
3495 //=======================================================================
3496 //function : IsValid
3498 //=======================================================================
3499 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
3500 const TopoDS_Shape& theResult,
3501 const Standard_Boolean closedSolid,
3502 const Standard_Boolean GeomCtrl)
3504 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
3505 TCollection_AsciiString checkValid = check.Value();
3506 Standard_Boolean ToCheck = Standard_True;
3507 if (!checkValid.IsEmpty()) {
3509 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
3511 if ( checkValid=="true" || checkValid=="TRUE" ) {
3512 ToCheck= Standard_False;
3516 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
3519 Standard_Boolean IsValid = Standard_True;
3521 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
3526 //===============================================================================
3527 // TDraft : test draft, uses AIS Viewer
3528 // Solid Face Plane Angle Reverse
3529 //===============================================================================
3530 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3532 if (argc < 5) return 1;
3533 // argv[1] - TopoDS_Shape Solid
3534 // argv[2] - TopoDS_Shape Face
3535 // argv[3] - TopoDS_Shape Plane
3536 // argv[4] - Standard_Real Angle
3537 // argv[5] - Standard_Integer Reverse
3539 // Sprintf(prefix, argv[1]);
3540 Standard_Real anAngle = 0;
3541 Standard_Boolean Rev = Standard_False;
3542 Standard_Integer rev = 0;
3543 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
3544 TopoDS_Shape face = GetShapeFromName(argv[2]);
3545 TopoDS_Face Face = TopoDS::Face(face);
3546 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
3547 if (Plane.IsNull ()) {
3548 di << "TEST : Plane is NULL" << "\n";
3551 anAngle = Draw::Atof(argv[4]);
3552 anAngle = 2*M_PI * anAngle / 360.0;
3554 Handle( Geom_Surface )aSurf;
3555 AIS_KindOfSurface aSurfType;
3556 Standard_Real Offset;
3558 if(argc > 4) { // == 5
3559 rev = Draw::Atoi(argv[5]);
3560 Rev = (rev)? Standard_True : Standard_False;
3563 TopoDS_Face face2 = TopoDS::Face(Plane);
3564 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
3566 di << "TEST : Can't find plane" << "\n";
3570 aDir = aPln.Axis().Direction();
3573 if (Plane.Orientation() == TopAbs_REVERSED)
3575 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
3577 BRepOffsetAPI_DraftAngle Draft (Solid);
3579 if(Abs(anAngle)< Precision::Angular()) {
3580 di << "TEST : NULL angle" << "\n";
3583 if(Rev) anAngle = - anAngle;
3584 Draft.Add (Face, aDir, anAngle, aPln);
3586 if (!Draft.IsDone()) {
3587 di << "TEST : Draft Not DONE " << "\n";
3590 TopTools_ListOfShape Larg;
3592 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
3593 di << "TEST : DesignAlgo returns Not valid" << "\n";
3597 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
3598 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
3600 if ( !ais.IsNull() ) {
3601 ais->SetColor(DEFAULT_COLOR);
3602 ais->SetMaterial(DEFAULT_MATERIAL);
3603 // Display the AIS_Shape without redraw
3604 Ctx->Display(ais, Standard_False);
3606 const char *Name = "draft1";
3607 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
3609 Handle(AIS_InteractiveObject) an_object =
3610 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
3611 if (!an_object.IsNull()) {
3612 Ctx->Remove(an_object,
3614 GetMapOfAIS().UnBind2(Name) ;
3617 GetMapOfAIS().Bind(ais, Name);
3618 // DBRep::Set("draft", ais->Shape());
3620 Ctx->Display(ais, Standard_True);
3624 //==============================================================================
3625 //function : splitParameter
3626 //purpose : Split parameter string to parameter name an parameter value
3627 //==============================================================================
3628 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
3629 TCollection_AsciiString& theName,
3630 TCollection_AsciiString& theValue)
3632 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
3634 if (aParamNameEnd == 0)
3636 return Standard_False;
3639 TCollection_AsciiString aString (theString);
3640 if (aParamNameEnd != 0)
3642 theValue = aString.Split (aParamNameEnd);
3643 aString.Split (aString.Length() - 1);
3647 return Standard_True;
3650 //============================================================================
3652 //============================================================================
3653 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
3656 DrawTrSurf::BasicCommands(theCommands);
3657 const char* group = "Check Features Operations commands";
3659 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
3661 &TDraft,group); //Draft_Modification
3664 //==============================================================================
3665 // ViewerTest::Factory
3666 //==============================================================================
3667 void ViewerTest::Factory(Draw_Interpretor& theDI)
3669 // definition of Viewer Command
3670 ViewerTest::Commands(theDI);
3671 ViewerTest::AviCommands(theDI);
3674 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
3678 // Declare entry point PLUGINFACTORY