1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by Robert Coublanc [nov 16-17-18 1998]
19 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 // ViewerTest_ObjectCommands.cxx
21 // ViewerTest_RelationCommands.cxx
22 // -add Functions and commands for interactive selection of shapes and objects
23 // in AIS Viewers. (PickShape(s), PickObject(s),
25 #include <Standard_Stream.hxx>
27 #include <ViewerTest.hxx>
29 #include <TopLoc_Location.hxx>
30 #include <TopTools_HArray1OfShape.hxx>
31 #include <TColStd_HArray1OfTransient.hxx>
32 #include <TColStd_HSequenceOfAsciiString.hxx>
33 #include <OSD_Timer.hxx>
34 #include <Geom_Axis2Placement.hxx>
35 #include <Geom_Axis1Placement.hxx>
36 #include <gp_Trsf.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <BRepAdaptor_Curve.hxx>
39 #include <StdSelect_ShapeTypeFilter.hxx>
41 #include <AIS_Drawer.hxx>
42 #include <AIS_ColoredShape.hxx>
43 #include <AIS_InteractiveObject.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Relation.hxx>
47 #include <AIS_TypeFilter.hxx>
48 #include <AIS_SignatureFilter.hxx>
49 #include <AIS_LocalContext.hxx>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <Aspect_InteriorStyle.hxx>
53 #include <Aspect_Window.hxx>
54 #include <Graphic3d_AspectFillArea3d.hxx>
55 #include <Graphic3d_AspectLine3d.hxx>
56 #include <Graphic3d_TextureRoot.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_IsoAspect.hxx>
60 #include <Select3D_SensitiveWire.hxx>
61 #include <SelectMgr_EntityOwner.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_ViewerSelector3d.hxx>
64 #include <Select3D_Projector.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <ViewerTest_AutoUpdater.hxx>
70 #include <Draw_Interpretor.hxx>
71 #include <TCollection_AsciiString.hxx>
72 #include <Draw_PluginMacro.hxx>
74 // avoid warnings on 'extern "C"' functions returning C++ classes
76 #define _CRT_SECURE_NO_DEPRECATE
77 #pragma warning(4:4190)
78 #pragma warning (disable:4996)
81 #include <NIS_InteractiveContext.hxx>
82 #include <NIS_Triangulated.hxx>
83 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
85 #include <Quantity_Color.hxx>
86 #include <Quantity_NameOfColor.hxx>
88 #include <Graphic3d_NameOfMaterial.hxx>
90 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
91 #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 Quantity_NameOfColor aColor = DEFAULT_COLOR;
101 Quantity_Color::ColorFromName (theName, aColor);
105 //=======================================================================
106 //function : GetTypeNames
108 //=======================================================================
109 static const char** GetTypeNames()
111 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
112 "Shape","ConnectedShape","MultiConn.Shape",
113 "ConnectedInter.","MultiConn.",
114 "Constraint","Dimension"};
115 static const char** ThePointer = names;
119 //=======================================================================
120 //function : GetTypeAndSignfromString
122 //=======================================================================
123 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
125 const char ** thefullnames = GetTypeNames();
126 Standard_Integer index(-1);
128 for(Standard_Integer i=0;i<=13 && index==-1;i++)
129 if(!strcasecmp(name,thefullnames[i]))
133 TheType = AIS_KOI_None;
139 TheType = AIS_KOI_Datum;
143 TheType = AIS_KOI_Shape;
147 TheType = AIS_KOI_Object;
151 TheType = AIS_KOI_Relation;
160 #include <Draw_Interpretor.hxx>
162 #include <Draw_Appli.hxx>
166 #include <TCollection_AsciiString.hxx>
167 #include <V3d_Viewer.hxx>
168 #include <V3d_View.hxx>
171 #include <AIS_InteractiveContext.hxx>
172 #include <AIS_Shape.hxx>
173 #include <AIS_TexturedShape.hxx>
174 #include <AIS_DisplayMode.hxx>
175 #include <TColStd_MapOfInteger.hxx>
176 #include <AIS_MapOfInteractive.hxx>
177 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
178 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
179 #include <ViewerTest_EventManager.hxx>
181 #include <TopoDS_Solid.hxx>
182 #include <BRepTools.hxx>
183 #include <BRep_Builder.hxx>
184 #include <TopAbs_ShapeEnum.hxx>
186 #include <TopoDS.hxx>
187 #include <BRep_Tool.hxx>
190 #include <Draw_Window.hxx>
191 #include <AIS_ListIteratorOfListOfInteractive.hxx>
192 #include <AIS_ListOfInteractive.hxx>
193 #include <AIS_DisplayMode.hxx>
194 #include <TopTools_ListOfShape.hxx>
195 #include <BRepOffsetAPI_MakeThickSolid.hxx>
196 #include <BRepOffset.hxx>
198 //==============================================================================
199 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
200 //==============================================================================
201 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
202 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
207 //==============================================================================
208 //function : VDisplayAISObject
209 //purpose : register interactive object in the map of AIS objects;
210 // if other object with such name already registered, it will be kept
211 // or replaced depending on value of <theReplaceIfExists>,
212 // if "true" - the old object will be cleared from AIS context;
213 // returns Standard_True if <theAISObj> registered in map;
214 //==============================================================================
215 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
216 const Handle(AIS_InteractiveObject)& theAISObj,
217 Standard_Boolean theReplaceIfExists = Standard_True)
219 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
220 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
221 if (aContextAIS.IsNull())
223 std::cout << "AIS context is not available.\n";
224 return Standard_False;
227 if (aMap.IsBound2 (theName))
229 if (!theReplaceIfExists)
231 std::cout << "Other interactive object has been already "
232 << "registered with name: " << theName << ".\n"
233 << "Please use another name.\n";
234 return Standard_False;
237 // stop displaying object
238 Handle(AIS_InteractiveObject) anOldObj =
239 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
241 if (!anOldObj.IsNull())
242 aContextAIS->Clear (anOldObj, Standard_True);
244 // remove name and old object from map
245 aMap.UnBind2 (theName);
248 if (theAISObj.IsNull())
250 // object with specified name already unbound
251 return Standard_True;
254 // unbind AIS object if was bound with another name
255 aMap.UnBind1 (theAISObj);
257 // can be registered without rebinding
258 aMap.Bind (theAISObj, theName);
259 aContextAIS->Display (theAISObj, Standard_True);
260 return Standard_True;
263 static TColStd_MapOfInteger theactivatedmodes(8);
264 static TColStd_ListOfTransient theEventMgrs;
266 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
267 const Handle(AIS_InteractiveContext)& Ctx)
269 theEventMgrs.Clear();
270 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
273 static Handle(V3d_View)& a3DView()
275 static Handle(V3d_View) Viou;
280 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
281 static Handle(AIS_InteractiveContext) aContext;
285 const Handle(V3d_View)& ViewerTest::CurrentView()
289 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
294 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
296 static Handle(NIS_InteractiveContext) aContext;
297 if (aContext.IsNull()) {
298 aContext = new NIS_InteractiveContext;
299 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
304 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
306 return TheAISContext();
309 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
311 TheAISContext() = aCtx;
312 ViewerTest::ResetEventManager();
315 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
317 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
320 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
322 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
326 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
327 theEventMgrs.Prepend(EM);
330 void ViewerTest::UnsetEventManager()
332 theEventMgrs.RemoveFirst();
336 void ViewerTest::ResetEventManager()
338 const Handle(NIS_View) aView =
339 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
340 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
343 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
345 Handle(ViewerTest_EventManager) EM;
346 if(theEventMgrs.IsEmpty()) return EM;
347 Handle(Standard_Transient) Tr = theEventMgrs.First();
348 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
352 //=======================================================================
353 //function : Get Context and active view
355 //=======================================================================
356 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
357 Handle(V3d_View)& theView)
359 theCtx = ViewerTest::GetAISContext();
360 theView = ViewerTest::CurrentView();
364 std::cout << "Error: cannot find an active view!\n";
365 return Standard_False;
367 return Standard_True;
370 //==============================================================================
371 //function : GetShapeFromName
372 //purpose : Compute an Shape from a draw variable or a file name
373 //==============================================================================
375 static TopoDS_Shape GetShapeFromName(const char* name)
377 TopoDS_Shape S = DBRep::Get(name);
380 BRep_Builder aBuilder;
381 BRepTools::Read( S, name, aBuilder);
387 //==============================================================================
388 //function : GetAISShapeFromName
389 //purpose : Compute an AIS_Shape from a draw variable or a file name
390 //==============================================================================
391 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
393 Handle(AIS_Shape) retsh;
395 if(GetMapOfAIS().IsBound2(name)){
396 const Handle(AIS_InteractiveObject) IO =
397 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
399 if(IO->Type()==AIS_KOI_Shape) {
400 if(IO->Signature()==0){
401 retsh = *((Handle(AIS_Shape)*)&IO);
404 cout << "an Object which is not an AIS_Shape "
405 "already has this name!!!"<<endl;
412 TopoDS_Shape S = GetShapeFromName(name);
414 retsh = new AIS_Shape(S);
420 //==============================================================================
422 //purpose : Remove all the object from the viewer
423 //==============================================================================
424 void ViewerTest::Clear()
426 if ( !a3DView().IsNull() ) {
427 if (TheAISContext()->HasOpenedContext())
428 TheAISContext()->CloseLocalContext();
429 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
430 while ( it.More() ) {
431 cout << "Remove " << it.Key2() << endl;
432 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
433 const Handle(AIS_InteractiveObject) anObj =
434 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
435 TheAISContext()->Remove(anObj,Standard_False);
436 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
437 const Handle(NIS_InteractiveObject) anObj =
438 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
439 TheNISContext()->Remove(anObj);
443 TheAISContext()->UpdateCurrentViewer();
444 // TheNISContext()->UpdateViews();
445 GetMapOfAIS().Clear();
449 //==============================================================================
450 //function : StandardModesActivation
451 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
453 //==============================================================================
454 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
456 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
458 if (TheAISContext()->HasOpenedContext())
459 aContext->CloseLocalContext();
462 if(!aContext->HasOpenedContext()) {
463 // To unhilight the preselected object
464 aContext->UnhilightCurrents(Standard_False);
465 // Open a local Context in order to be able to select subshape from
466 // the selected shape if any or for all if there is no selection
467 if (!aContext->FirstCurrentObject().IsNull()){
468 aContext->OpenLocalContext(Standard_False);
470 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
471 aContext->Load( aContext->Current(),-1,Standard_True);
475 aContext->OpenLocalContext();
478 const char *cmode="???";
481 case 0: cmode = "Shape"; break;
482 case 1: cmode = "Vertex"; break;
483 case 2: cmode = "Edge"; break;
484 case 3: cmode = "Wire"; break;
485 case 4: cmode = "Face"; break;
486 case 5: cmode = "Shell"; break;
487 case 6: cmode = "Solid"; break;
488 case 7: cmode = "Compsolid"; break;
489 case 8: cmode = "Compound"; break;
492 if(theactivatedmodes.Contains(mode))
494 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
495 theactivatedmodes.Remove(mode);
496 cout<<"Mode "<< cmode <<" OFF"<<endl;
500 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
501 theactivatedmodes.Add(mode);
502 cout<<"Mode "<< cmode << " ON" << endl;
507 //==============================================================================
508 //function : CopyIsoAspect
509 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
510 //==============================================================================
511 static Handle(Prs3d_IsoAspect) CopyIsoAspect
512 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
513 const Standard_Integer theNbIsos)
515 Quantity_Color aColor;
516 Aspect_TypeOfLine aType;
517 Standard_Real aWidth;
519 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
521 Handle(Prs3d_IsoAspect) aResult =
522 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
527 //==============================================================================
529 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
530 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
531 //==============================================================================
532 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
534 if (TheAISContext().IsNull()) {
535 di << argv[0] << " Call 'vinit' before!\n";
540 di << "Current number of isos : " <<
541 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
542 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
543 di << "IsoOnPlane mode is " <<
544 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
549 Standard_Integer aLastInd = argc - 1;
550 Standard_Boolean isChanged = Standard_False;
551 Standard_Integer aNbUIsos = 0;
552 Standard_Integer aNbVIsos = 0;
555 Standard_Boolean isIsoOnPlane = Standard_False;
557 if (strcmp(argv[aLastInd], "1") == 0) {
558 isIsoOnPlane = Standard_True;
559 isChanged = Standard_True;
560 } else if (strcmp(argv[aLastInd], "0") == 0) {
561 isIsoOnPlane = Standard_False;
562 isChanged = Standard_True;
566 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
567 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
570 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
571 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
573 TheAISContext()->IsoOnPlane(isIsoOnPlane);
576 // If there are no shapes provided set the default numbers.
577 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
578 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
585 for (i = 1; i <= aLastInd; i++) {
586 TCollection_AsciiString name(argv[i]);
587 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
590 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
591 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
592 const Handle(AIS_InteractiveObject) aShape =
593 Handle(AIS_InteractiveObject)::DownCast (anObj);
594 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
595 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
596 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
599 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
600 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
601 TheAISContext()->SetLocalAttributes
602 (aShape, CurDrawer, Standard_False);
603 TheAISContext()->Redisplay(aShape);
605 di << "Number of isos for " << argv[i] << " : "
606 << aUIso->Number() << " " << aVIso->Number() << "\n";
609 di << argv[i] << ": Not an AIS interactive object!\n";
612 di << argv[i] << ": Use 'vdisplay' before\n";
617 TheAISContext()->UpdateCurrentViewer();
623 //==============================================================================
624 //function : VDispAreas,VDispSensitive,...
626 //==============================================================================
627 static Standard_Integer VDispAreas (Draw_Interpretor& ,
628 Standard_Integer theArgNb,
633 std::cout << "Error: wrong syntax!\n";
637 Handle(AIS_InteractiveContext) aCtx;
638 Handle(V3d_View) aView;
639 if (!getCtxAndView (aCtx, aView))
644 aCtx->DisplayActiveAreas (aView);
647 static Standard_Integer VClearAreas (Draw_Interpretor& ,
648 Standard_Integer theArgNb,
653 std::cout << "Error: wrong syntax!\n";
657 Handle(AIS_InteractiveContext) aCtx;
658 Handle(V3d_View) aView;
659 if (!getCtxAndView (aCtx, aView))
664 aCtx->ClearActiveAreas (aView);
668 static Standard_Integer VDispSensi (Draw_Interpretor& ,
669 Standard_Integer theArgNb,
674 std::cout << "Error: wrong syntax!\n";
678 Handle(AIS_InteractiveContext) aCtx;
679 Handle(V3d_View) aView;
680 if (!getCtxAndView (aCtx, aView))
685 aCtx->DisplayActiveSensitive (aView);
690 static Standard_Integer VClearSensi (Draw_Interpretor& ,
691 Standard_Integer theArgNb,
696 std::cout << "Error: wrong syntax!\n";
700 Handle(AIS_InteractiveContext) aCtx;
701 Handle(V3d_View) aView;
702 if (!getCtxAndView (aCtx, aView))
706 aCtx->ClearActiveSensitive (aView);
710 //==============================================================================
712 //purpose : To list the displayed object with their attributes
713 //==============================================================================
714 static int VDir (Draw_Interpretor& theDI,
718 if (!a3DView().IsNull())
723 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
724 anIter.More(); anIter.Next())
726 theDI << "\t" << anIter.Key2().ToCString() << "\n";
731 //==============================================================================
732 //function : VSelPrecision
733 //purpose : To set the selection precision mode and tolerance value
734 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
735 // value (integer number of pixel for window mode, double value of
736 // sensitivity for view mode). Without arguments the function just
737 // prints the current precision mode and the corresponding tolerance.
738 //==============================================================================
739 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
743 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
747 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
748 if( aContext.IsNull() )
753 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
754 if( aMode == StdSelect_SM_WINDOW )
756 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
757 di << "Precision mode : 0 (window)\n";
758 di << "Pixel tolerance : " << aPixelTolerance << "\n";
760 else if( aMode == StdSelect_SM_VIEW )
762 Standard_Real aSensitivity = aContext->Sensitivity();
763 di << "Precision mode : 1 (view)\n";
764 di << "Sensitivity : " << aSensitivity << "\n";
769 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
770 aContext->SetSensitivityMode( aMode );
773 if( aMode == StdSelect_SM_WINDOW )
775 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
776 aContext->SetPixelTolerance( aPixelTolerance );
778 else if( aMode == StdSelect_SM_VIEW )
780 Standard_Real aSensitivity = Draw::Atof( argv[2] );
781 aContext->SetSensitivity( aSensitivity );
788 //==============================================================================
790 //purpose : To dump the active view snapshot to image file
791 //==============================================================================
792 static Standard_Integer VDump (Draw_Interpretor& theDI,
793 Standard_Integer theArgNb,
794 Standard_CString* theArgVec)
798 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
802 Standard_Integer anArgIter = 1;
803 Standard_CString aFilePath = theArgVec[anArgIter++];
804 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
805 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
806 Standard_Integer aWidth = 0;
807 Standard_Integer aHeight = 0;
808 for (; anArgIter < theArgNb; ++anArgIter)
810 TCollection_AsciiString anArg (theArgVec[anArgIter]);
814 aBufferType = Graphic3d_BT_RGBA;
816 else if (anArg == "rgb")
818 aBufferType = Graphic3d_BT_RGB;
820 else if (anArg == "depth")
822 aBufferType = Graphic3d_BT_Depth;
824 else if (anArg == "l"
827 aStereoOpts = V3d_SDO_LEFT_EYE;
829 else if (anArg == "r"
832 aStereoOpts = V3d_SDO_RIGHT_EYE;
834 else if (anArg == "mono")
836 aStereoOpts = V3d_SDO_MONO;
838 else if (anArg == "w"
843 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
846 else if (++anArgIter >= theArgNb)
848 std::cout << "Error: integer value is expected right after 'width'\n";
851 aWidth = Draw::Atoi (theArgVec[anArgIter]);
853 else if (anArg == "h"
854 || anArg == "height")
858 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
861 if (++anArgIter >= theArgNb)
863 std::cout << "Error: integer value is expected right after 'height'\n";
866 aHeight = Draw::Atoi (theArgVec[anArgIter]);
868 else if (anArg.IsIntegerValue())
870 // compatibility with old syntax
874 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
877 else if (++anArgIter >= theArgNb)
879 std::cout << "Error: height value is expected right after width\n";
882 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
883 aHeight = Draw::Atoi (theArgVec[anArgIter]);
887 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
891 if ((aWidth <= 0 && aHeight > 0)
892 || (aWidth > 0 && aHeight <= 0))
894 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
898 Handle(V3d_View) aView = ViewerTest::CurrentView();
901 std::cout << "Error: cannot find an active view!\n";
905 if (aWidth <= 0 || aHeight <= 0)
907 if (aStereoOpts != V3d_SDO_MONO)
909 aView->Window()->Size (aWidth, aHeight);
913 if (!aView->Dump (aFilePath, aBufferType))
915 theDI << "Fail: view dump failed!\n";
921 Image_AlienPixMap aPixMap;
922 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
924 theDI << "Fail: view dump failed!\n";
928 if (aPixMap.SizeX() != Standard_Size(aWidth)
929 || aPixMap.SizeY() != Standard_Size(aHeight))
931 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
932 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
934 if (!aPixMap.Save (aFilePath))
936 theDI << "Fail: image can not be saved!\n";
942 //==============================================================================
943 //function : Displays,Erase...
946 //==============================================================================
947 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
948 const Standard_Integer Mode,
949 const Standard_Integer TypeOfOperation,
950 const Standard_Boolean Upd)
952 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
954 switch(TypeOfOperation){
956 Ctx->Display(IO,Mode,Upd);
964 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
966 Ctx->SetDisplayMode(IO,Mode,Upd);
971 Ctx->SetDisplayMode(0,Upd);
973 Ctx->UnsetDisplayMode(IO,Upd);
980 //=======================================================================
983 //=======================================================================
984 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
987 TCollection_AsciiString name;
990 // display others presentations
991 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
992 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
993 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
994 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
996 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
998 //unset displaymode.. comportement particulier...
999 if(TypeOfOperation==4){
1001 if(Ctx->NbCurrents()==0 ||
1002 Ctx->NbSelected()==0){
1003 Handle(AIS_InteractiveObject) IO;
1004 VwrTst_DispErase(IO,-1,4,Standard_False);
1006 else if(!Ctx->HasOpenedContext()){
1007 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1008 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1011 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1012 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1013 Ctx->UpdateCurrentViewer();
1016 Handle(AIS_InteractiveObject) IO;
1018 if(GetMapOfAIS().IsBound2(name)){
1019 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1021 VwrTst_DispErase(IO,-1,4,Standard_True);
1026 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1027 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1028 Handle(AIS_InteractiveObject) IO;
1029 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1031 if(!Ctx->HasOpenedContext()){
1032 // set/unset display mode sur le Contexte...
1033 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1034 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1036 Ctx->UpdateCurrentViewer();
1039 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1040 Ctx->Display(Ctx->Interactive(),Dmode);
1044 Handle(AIS_InteractiveObject) IO;
1046 if(GetMapOfAIS().IsBound2(name))
1047 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1049 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1055 //=======================================================================
1058 //=======================================================================
1059 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1061 if(argc==1) return 1;
1062 Standard_Integer On = Draw::Atoi(argv[1]);
1063 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1067 if(!Ctx->HasOpenedContext()){
1068 di<<"sub intensite ";
1071 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1072 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1074 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1076 di <<"passage dans off"<<"\n";
1077 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1082 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1084 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1086 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1089 Ctx->UpdateCurrentViewer();
1092 Handle(AIS_InteractiveObject) IO;
1093 TCollection_AsciiString name = argv[2];
1094 if(GetMapOfAIS().IsBound2(name)){
1095 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1098 Ctx->SubIntensityOn(IO);
1100 Ctx->SubIntensityOff(IO);
1108 //! Auxiliary class to iterate presentations from different collections.
1109 class ViewTest_PrsIter
1113 //! Create and initialize iterator object.
1114 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1115 : mySource (IterSource_All)
1117 NCollection_Sequence<TCollection_AsciiString> aNames;
1118 if (!theName.IsEmpty())
1119 aNames.Append (theName);
1123 //! Create and initialize iterator object.
1124 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1125 : mySource (IterSource_All)
1130 //! Initialize the iterator.
1131 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1133 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1135 mySelIter.Nullify();
1136 myCurrent.Nullify();
1137 myCurrentTrs.Nullify();
1138 if (!mySeq.IsEmpty())
1140 mySource = IterSource_List;
1141 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1143 else if (aCtx->NbCurrents() > 0)
1145 mySource = IterSource_Selected;
1147 mySelIter->InitCurrent();
1151 mySource = IterSource_All;
1152 myMapIter.Initialize (GetMapOfAIS());
1157 const TCollection_AsciiString& CurrentName() const
1159 return myCurrentName;
1162 const Handle(AIS_InteractiveObject)& Current() const
1167 const Handle(Standard_Transient)& CurrentTrs() const
1169 return myCurrentTrs;
1172 //! @return true if iterator points to valid object within collection
1173 Standard_Boolean More() const
1177 case IterSource_All: return myMapIter.More();
1178 case IterSource_List: return mySeqIter.More();
1179 case IterSource_Selected: return mySelIter->MoreCurrent();
1181 return Standard_False;
1184 //! Go to the next item.
1187 myCurrentName.Clear();
1188 myCurrentTrs.Nullify();
1189 myCurrent.Nullify();
1192 case IterSource_All:
1197 case IterSource_List:
1202 case IterSource_Selected:
1204 mySelIter->NextCurrent();
1217 case IterSource_All:
1219 if (myMapIter.More())
1221 myCurrentName = myMapIter.Key2();
1222 myCurrentTrs = myMapIter.Key1();
1223 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1227 case IterSource_List:
1229 if (mySeqIter.More())
1231 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1233 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1236 myCurrentName = mySeqIter.Value();
1237 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1238 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1242 case IterSource_Selected:
1244 if (mySelIter->MoreCurrent())
1246 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1247 myCurrent = mySelIter->Current();
1265 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1266 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1267 NCollection_Sequence<TCollection_AsciiString> mySeq;
1268 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1270 TCollection_AsciiString myCurrentName;//!< current item name
1271 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1272 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1274 IterSource mySource; //!< iterated collection
1278 //==============================================================================
1279 //function : VInteriorStyle
1280 //purpose : sets interior style of the a selected or named or displayed shape
1281 //==============================================================================
1282 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1283 Standard_Integer theArgNb,
1284 const char** theArgVec)
1286 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1287 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1290 std::cerr << "Error: no active view!\n";
1294 Standard_Integer anArgIter = 1;
1295 for (; anArgIter < theArgNb; ++anArgIter)
1297 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1302 TCollection_AsciiString aName;
1303 if (theArgNb - anArgIter == 2)
1305 aName = theArgVec[anArgIter++];
1307 else if (theArgNb - anArgIter != 1)
1309 std::cout << "Error: wrong number of arguments! See usage:\n";
1310 theDI.PrintHelp (theArgVec[0]);
1313 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1314 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1315 aStyleArg.LowerCase();
1316 if (aStyleArg == "empty")
1320 else if (aStyleArg == "hollow")
1324 else if (aStyleArg == "hatch")
1328 else if (aStyleArg == "solid")
1332 else if (aStyleArg == "hiddenline")
1338 anInterStyle = aStyleArg.IntegerValue();
1340 if (anInterStyle < Aspect_IS_EMPTY
1341 || anInterStyle > Aspect_IS_HIDDENLINE)
1343 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1344 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1348 if (!aName.IsEmpty()
1349 && !GetMapOfAIS().IsBound2 (aName))
1351 std::cout << "Error: object " << aName << " is not displayed!\n";
1355 if (aCtx->HasOpenedContext())
1357 aCtx->CloseLocalContext();
1359 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1361 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1364 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1365 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1366 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1367 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1368 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1374 //! Auxiliary structure for VAspects
1375 struct ViewerTest_AspectsChangeSet
1377 Standard_Integer ToSetColor;
1378 Quantity_Color Color;
1380 Standard_Integer ToSetLineWidth;
1381 Standard_Real LineWidth;
1383 Standard_Integer ToSetTransparency;
1384 Standard_Real Transparency;
1386 Standard_Integer ToSetMaterial;
1387 Graphic3d_NameOfMaterial Material;
1388 TCollection_AsciiString MatName;
1390 NCollection_Sequence<TopoDS_Shape> SubShapes;
1392 //! Empty constructor
1393 ViewerTest_AspectsChangeSet()
1395 Color (DEFAULT_COLOR),
1398 ToSetTransparency (0),
1401 Material (Graphic3d_NOM_DEFAULT) {}
1403 //! @return true if no changes have been requested
1404 Standard_Boolean IsEmpty() const
1406 return ToSetLineWidth == 0
1407 && ToSetTransparency == 0
1409 && ToSetMaterial == 0;
1412 //! @return true if properties are valid
1413 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1415 Standard_Boolean isOk = Standard_True;
1416 if (LineWidth <= 0.0
1417 || LineWidth > 10.0)
1419 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1420 isOk = Standard_False;
1422 if (Transparency < 0.0
1423 || Transparency > 1.0)
1425 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1426 isOk = Standard_False;
1429 && ToSetTransparency)
1431 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1432 isOk = Standard_False;
1434 if (ToSetMaterial == 1
1435 && Material == Graphic3d_NOM_DEFAULT)
1437 std::cout << "Error: unknown material " << MatName << ".\n";
1438 isOk = Standard_False;
1445 //==============================================================================
1446 //function : VAspects
1448 //==============================================================================
1449 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1450 Standard_Integer theArgNb,
1451 const char** theArgVec)
1453 TCollection_AsciiString aCmdName (theArgVec[0]);
1454 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1455 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1458 std::cerr << "Error: no active view!\n";
1462 Standard_Integer anArgIter = 1;
1463 NCollection_Sequence<TCollection_AsciiString> aNames;
1464 for (; anArgIter < theArgNb; ++anArgIter)
1466 TCollection_AsciiString anArg = theArgVec[anArgIter];
1467 if (anUpdateTool.parseRedrawMode (anArg))
1471 else if (!anArg.IsEmpty()
1472 && anArg.Value (1) != '-')
1474 aNames.Append (anArg);
1482 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1483 aChanges.Append (ViewerTest_AspectsChangeSet());
1484 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1486 // parse syntax of legacy commands
1487 if (aCmdName == "vsetwidth")
1489 if (aNames.IsEmpty()
1490 || !aNames.Last().IsRealValue())
1492 std::cout << "Error: not enough arguments!\n";
1495 aChangeSet->ToSetLineWidth = 1;
1496 aChangeSet->LineWidth = aNames.Last().RealValue();
1497 aNames.Remove (aNames.Length());
1499 else if (aCmdName == "vunsetwidth")
1501 aChangeSet->ToSetLineWidth = -1;
1503 else if (aCmdName == "vsetcolor")
1505 if (aNames.IsEmpty())
1507 std::cout << "Error: not enough arguments!\n";
1510 aChangeSet->ToSetColor = 1;
1512 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1513 Standard_Boolean isOk = Standard_False;
1514 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1516 aChangeSet->Color = aColor;
1517 aNames.Remove (aNames.Length());
1518 isOk = Standard_True;
1520 else if (aNames.Length() >= 3)
1522 const TCollection_AsciiString anRgbStr[3] =
1524 aNames.Value (aNames.Upper() - 2),
1525 aNames.Value (aNames.Upper() - 1),
1526 aNames.Value (aNames.Upper() - 0)
1528 isOk = anRgbStr[0].IsRealValue()
1529 && anRgbStr[1].IsRealValue()
1530 && anRgbStr[2].IsRealValue();
1533 Graphic3d_Vec4d anRgb;
1534 anRgb.x() = anRgbStr[0].RealValue();
1535 anRgb.y() = anRgbStr[1].RealValue();
1536 anRgb.z() = anRgbStr[2].RealValue();
1537 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1538 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1539 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1541 std::cout << "Error: RGB color values should be within range 0..1!\n";
1544 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1545 aNames.Remove (aNames.Length());
1546 aNames.Remove (aNames.Length());
1547 aNames.Remove (aNames.Length());
1552 std::cout << "Error: not enough arguments!\n";
1556 else if (aCmdName == "vunsetcolor")
1558 aChangeSet->ToSetColor = -1;
1560 else if (aCmdName == "vsettransparency")
1562 if (aNames.IsEmpty()
1563 || !aNames.Last().IsRealValue())
1565 std::cout << "Error: not enough arguments!\n";
1568 aChangeSet->ToSetTransparency = 1;
1569 aChangeSet->Transparency = aNames.Last().RealValue();
1570 aNames.Remove (aNames.Length());
1572 else if (aCmdName == "vunsettransparency")
1574 aChangeSet->ToSetTransparency = -1;
1576 else if (aCmdName == "vsetmaterial")
1578 if (aNames.IsEmpty())
1580 std::cout << "Error: not enough arguments!\n";
1583 aChangeSet->ToSetMaterial = 1;
1584 aChangeSet->MatName = aNames.Last();
1585 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1586 aNames.Remove (aNames.Length());
1588 else if (aCmdName == "vunsetmaterial")
1590 aChangeSet->ToSetMaterial = -1;
1592 else if (anArgIter >= theArgNb)
1594 std::cout << "Error: not enough arguments!\n";
1598 if (!aChangeSet->IsEmpty())
1600 anArgIter = theArgNb;
1602 for (; anArgIter < theArgNb; ++anArgIter)
1604 TCollection_AsciiString anArg = theArgVec[anArgIter];
1606 if (anArg == "-setwidth"
1607 || anArg == "-setlinewidth")
1609 if (++anArgIter >= theArgNb)
1611 std::cout << "Error: wrong syntax at " << anArg << "\n";
1614 aChangeSet->ToSetLineWidth = 1;
1615 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1617 else if (anArg == "-unsetwidth"
1618 || anArg == "-unsetlinewidth")
1620 aChangeSet->ToSetLineWidth = -1;
1621 aChangeSet->LineWidth = 1.0;
1623 else if (anArg == "-settransp"
1624 || anArg == "-settransparency")
1626 if (++anArgIter >= theArgNb)
1628 std::cout << "Error: wrong syntax at " << anArg << "\n";
1631 aChangeSet->ToSetTransparency = 1;
1632 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1633 if (aChangeSet->Transparency >= 0.0
1634 && aChangeSet->Transparency <= Precision::Confusion())
1636 aChangeSet->ToSetTransparency = -1;
1637 aChangeSet->Transparency = 0.0;
1640 else if (anArg == "-setalpha")
1642 if (++anArgIter >= theArgNb)
1644 std::cout << "Error: wrong syntax at " << anArg << "\n";
1647 aChangeSet->ToSetTransparency = 1;
1648 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1649 if (aChangeSet->Transparency < 0.0
1650 || aChangeSet->Transparency > 1.0)
1652 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1655 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1656 if (aChangeSet->Transparency >= 0.0
1657 && aChangeSet->Transparency <= Precision::Confusion())
1659 aChangeSet->ToSetTransparency = -1;
1660 aChangeSet->Transparency = 0.0;
1663 else if (anArg == "-unsettransp"
1664 || anArg == "-unsettransparency"
1665 || anArg == "-unsetalpha"
1666 || anArg == "-opaque")
1668 aChangeSet->ToSetTransparency = -1;
1669 aChangeSet->Transparency = 0.0;
1671 else if (anArg == "-setcolor")
1673 Standard_Integer aNbComps = 0;
1674 Standard_Integer aCompIter = anArgIter + 1;
1675 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1677 if (theArgVec[aCompIter][0] == '-')
1686 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1687 Standard_CString aName = theArgVec[anArgIter + 1];
1688 if (!Quantity_Color::ColorFromName (aName, aColor))
1690 std::cout << "Error: unknown color name '" << aName << "'\n";
1693 aChangeSet->Color = aColor;
1698 Graphic3d_Vec3d anRgb;
1699 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1700 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1701 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1702 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1703 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1704 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1706 std::cout << "Error: RGB color values should be within range 0..1!\n";
1709 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1714 std::cout << "Error: wrong syntax at " << anArg << "\n";
1718 aChangeSet->ToSetColor = 1;
1719 anArgIter += aNbComps;
1721 else if (anArg == "-unsetcolor")
1723 aChangeSet->ToSetColor = -1;
1724 aChangeSet->Color = DEFAULT_COLOR;
1726 else if (anArg == "-setmat"
1727 || anArg == "-setmaterial")
1729 if (++anArgIter >= theArgNb)
1731 std::cout << "Error: wrong syntax at " << anArg << "\n";
1734 aChangeSet->ToSetMaterial = 1;
1735 aChangeSet->MatName = theArgVec[anArgIter];
1736 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1738 else if (anArg == "-unsetmat"
1739 || anArg == "-unsetmaterial")
1741 aChangeSet->ToSetMaterial = -1;
1742 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1744 else if (anArg == "-subshape"
1745 || anArg == "-subshapes")
1747 if (aNames.IsEmpty())
1749 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1753 aChanges.Append (ViewerTest_AspectsChangeSet());
1754 aChangeSet = &aChanges.ChangeLast();
1756 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1758 Standard_CString aSubShapeName = theArgVec[anArgIter];
1759 if (*aSubShapeName == '-')
1765 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1766 if (aSubShape.IsNull())
1768 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1771 aChangeSet->SubShapes.Append (aSubShape);
1774 if (aChangeSet->SubShapes.IsEmpty())
1776 std::cerr << "Error: empty list is specified after -subshapes!\n";
1780 else if (anArg == "-unset")
1782 aChangeSet->ToSetLineWidth = -1;
1783 aChangeSet->LineWidth = 1.0;
1784 aChangeSet->ToSetTransparency = -1;
1785 aChangeSet->Transparency = 0.0;
1786 aChangeSet->ToSetColor = -1;
1787 aChangeSet->Color = DEFAULT_COLOR;
1788 aChangeSet->ToSetMaterial = -1;
1789 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1793 std::cout << "Error: wrong syntax at " << anArg << "\n";
1798 Standard_Boolean isFirst = Standard_True;
1799 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1800 aChangesIter.More(); aChangesIter.Next())
1802 if (!aChangesIter.Value().Validate (!isFirst))
1806 isFirst = Standard_False;
1809 if (aCtx->HasOpenedContext())
1811 aCtx->CloseLocalContext();
1813 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1815 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1816 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1817 Handle(AIS_ColoredShape) aColoredPrs;
1818 Standard_Boolean toDisplay = Standard_False;
1819 if (aChanges.Length() > 1)
1821 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1822 if (aShapePrs.IsNull())
1824 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1827 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1828 if (aColoredPrs.IsNull())
1830 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1831 aCtx->Remove (aShapePrs, Standard_False);
1832 GetMapOfAIS().UnBind2 (aName);
1833 GetMapOfAIS().Bind (aColoredPrs, aName);
1834 toDisplay = Standard_True;
1835 aShapePrs = aColoredPrs;
1842 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1843 aChangeSet = &aChangesIter.ChangeValue();
1844 if (aChangeSet->ToSetMaterial == 1)
1846 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1848 else if (aChangeSet->ToSetMaterial == -1)
1850 aCtx->UnsetMaterial (aPrs, Standard_False);
1852 if (aChangeSet->ToSetColor == 1)
1854 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1856 else if (aChangeSet->ToSetColor == -1)
1858 aCtx->UnsetColor (aPrs, Standard_False);
1860 if (aChangeSet->ToSetTransparency == 1)
1862 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1864 else if (aChangeSet->ToSetTransparency == -1)
1866 aCtx->UnsetTransparency (aPrs, Standard_False);
1868 if (aChangeSet->ToSetLineWidth == 1)
1870 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1872 else if (aChangeSet->ToSetLineWidth == -1)
1874 aCtx->UnsetWidth (aPrs, Standard_False);
1877 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1879 aChangeSet = &aChangesIter.ChangeValue();
1880 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1881 aSubShapeIter.More(); aSubShapeIter.Next())
1883 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1884 if (aChangeSet->ToSetColor == 1)
1886 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1888 if (aChangeSet->ToSetLineWidth == 1)
1890 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1892 if (aChangeSet->ToSetColor == -1
1893 || aChangeSet->ToSetLineWidth == -1)
1895 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1901 aCtx->Display (aPrs, Standard_False);
1903 else if (!aColoredPrs.IsNull())
1905 aColoredPrs->Redisplay();
1910 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1911 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1912 if (!aNisObj.IsNull())
1914 if (aChangeSet->ToSetTransparency != 0)
1916 aNisObj->SetTransparency (aChangeSet->Transparency);
1919 if (!aNisTri.IsNull())
1921 if (aChangeSet->ToSetColor != 0)
1923 aNisTri->SetColor (aChangeSet->Color);
1925 if (aChangeSet->ToSetLineWidth != 0)
1927 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1935 //==============================================================================
1936 //function : VDonly2
1938 //purpose : Display only a selected or named object
1939 // if there is no selected or named object s, nothing is done
1940 //==============================================================================
1941 static int VDonly2 (Draw_Interpretor& ,
1942 Standard_Integer theArgNb,
1943 const char** theArgVec)
1945 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1946 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1949 std::cerr << "Error: no active view!\n";
1953 if (aCtx->HasOpenedContext())
1955 aCtx->CloseLocalContext();
1958 Standard_Integer anArgIter = 1;
1959 for (; anArgIter < theArgNb; ++anArgIter)
1961 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1967 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1968 if (anArgIter >= theArgNb)
1970 // display only selected objects
1971 if (aCtx->NbCurrents() < 1)
1976 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1978 aDispSet.Add (aCtx->Current());
1983 // display only specified objects
1984 for (; anArgIter < theArgNb; ++anArgIter)
1986 TCollection_AsciiString aName = theArgVec[anArgIter];
1987 if (GetMapOfAIS().IsBound2 (aName))
1989 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1990 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1992 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1993 aCtx->Display (aShape, Standard_False);
1995 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1997 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1998 TheNISContext()->Display (aShape);
2000 aDispSet.Add (anObj);
2005 // weed out other objects
2006 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2008 if (aDispSet.Contains (anIter.Key1()))
2013 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2015 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2016 aCtx->Erase (aShape, Standard_False);
2018 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2020 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2021 TheNISContext()->Erase (aShape);
2027 //==============================================================================
2028 //function : VRemove
2029 //purpose : Removes selected or named objects.
2030 // If there is no selected or named objects,
2031 // all objects in the viewer can be removed with argument -all.
2032 // If -context is in arguments, the object is not deleted from the map of
2033 // objects (deleted only from the current context).
2034 //==============================================================================
2035 int VRemove (Draw_Interpretor& theDI,
2036 Standard_Integer theArgNb,
2037 const char** theArgVec)
2039 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2040 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2043 std::cout << "Error: no active view!\n";
2047 aCtx->CloseAllContexts (Standard_False);
2049 Standard_Boolean isContextOnly = Standard_False;
2050 Standard_Boolean toRemoveAll = Standard_False;
2051 Standard_Boolean toPrintInfo = Standard_True;
2053 Standard_Integer anArgIter = 1;
2054 for (; anArgIter < theArgNb; ++anArgIter)
2056 TCollection_AsciiString anArg = theArgVec[anArgIter];
2058 if (anArg == "-context")
2060 isContextOnly = Standard_True;
2062 else if (anArg == "-all")
2064 toRemoveAll = Standard_True;
2066 else if (anArg == "-noinfo")
2068 toPrintInfo = Standard_False;
2070 else if (!anUpdateTool.parseRedrawMode (anArg))
2076 && anArgIter < theArgNb)
2078 std::cout << "Error: wrong syntax!\n";
2082 NCollection_List<TCollection_AsciiString> anIONameList;
2085 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2086 anIter.More(); anIter.Next())
2088 anIONameList.Append (anIter.Key2());
2091 else if (anArgIter < theArgNb) // removed objects names are in argument list
2093 for (; anArgIter < theArgNb; ++anArgIter)
2095 TCollection_AsciiString aName = theArgVec[anArgIter];
2096 if (!GetMapOfAIS().IsBound2 (aName))
2098 theDI << aName.ToCString() << " was not bound to some object.\n";
2102 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2104 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2107 if (anIO->GetContext() != aCtx)
2109 theDI << aName.ToCString() << " was not displayed in current context.\n";
2110 theDI << "Please activate view with this object displayed and try again.\n";
2114 anIONameList.Append (aName);
2118 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2119 if (!aNisIO.IsNull())
2121 anIONameList.Append (aName);
2125 else if (aCtx->NbCurrents() > 0
2126 || TheNISContext()->GetSelected().Extent() > 0)
2128 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2129 anIter.More(); anIter.Next())
2131 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2134 if (!aCtx->IsCurrent (anIO))
2139 anIONameList.Append (anIter.Key2());
2143 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2144 if (!aNisIO.IsNull())
2146 if (!TheNISContext()->IsSelected (aNisIO))
2151 anIONameList.Append (anIter.Key2());
2156 // Unbind all removed objects from the map of displayed IO.
2157 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2158 anIter.More(); anIter.Next())
2160 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2163 aCtx->Remove (anIO, Standard_False);
2166 theDI << anIter.Value().ToCString() << " was removed\n";
2171 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2172 if (!aNisIO.IsNull())
2174 TheNISContext()->Remove (aNisIO);
2177 theDI << anIter.Value().ToCString() << " was removed\n";
2183 GetMapOfAIS().UnBind2 (anIter.Value());
2189 //==============================================================================
2191 //purpose : Erase some selected or named objects
2192 // if there is no selected or named objects, the whole viewer is erased
2193 //==============================================================================
2194 int VErase (Draw_Interpretor& theDI,
2195 Standard_Integer theArgNb,
2196 const char** theArgVec)
2198 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2199 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2202 std::cout << "Error: no active view!\n";
2205 aCtx->CloseAllContexts (Standard_False);
2207 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2209 Standard_Integer anArgIter = 1;
2210 for (; anArgIter < theArgNb; ++anArgIter)
2212 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2218 if (anArgIter < theArgNb)
2222 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2226 // has a list of names
2227 for (; anArgIter < theArgNb; ++anArgIter)
2229 TCollection_AsciiString aName = theArgVec[anArgIter];
2230 if (!GetMapOfAIS().IsBound2 (aName))
2235 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2236 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2237 theDI << aName.ToCString() << " ";
2240 aCtx->Erase (anIO, Standard_False);
2244 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2245 if (!aNisIO.IsNull())
2247 TheNISContext()->Erase (aNisIO);
2252 else if (!toEraseAll
2253 && aCtx->NbCurrents() > 0)
2255 // remove all currently selected objects
2256 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2257 anIter.More(); anIter.Next())
2259 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2261 && aCtx->IsCurrent (anIO))
2263 theDI << anIter.Key2().ToCString() << " ";
2264 aCtx->Erase (anIO, Standard_False);
2270 // erase entire viewer
2271 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2272 anIter.More(); anIter.Next())
2274 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2277 aCtx->Erase (anIO, Standard_False);
2281 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2282 if (!aNisIO.IsNull())
2284 TheNISContext()->Erase (aNisIO);
2292 //==============================================================================
2293 //function : VDisplayAll
2295 //purpose : Display all the objects of the Map
2296 //==============================================================================
2297 static int VDisplayAll (Draw_Interpretor& ,
2298 Standard_Integer theArgNb,
2299 const char** theArgVec)
2302 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2303 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2306 std::cout << "Error: no active view!\n";
2310 Standard_Integer anArgIter = 1;
2311 for (; anArgIter < theArgNb; ++anArgIter)
2313 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2318 if (anArgIter < theArgNb)
2320 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2324 if (aCtx->HasOpenedContext())
2326 aCtx->CloseLocalContext();
2329 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2330 anIter.More(); anIter.Next())
2332 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2334 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2335 aCtx->Erase (aShape, Standard_False);
2337 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2339 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2340 TheNISContext()->Erase (aShape);
2344 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2345 anIter.More(); anIter.Next())
2347 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2349 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2350 aCtx->Display (aShape, Standard_False);
2352 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2354 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2355 TheNISContext()->Display (aShape);
2361 //! Auxiliary method to find presentation
2362 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2363 const Handle(AIS_InteractiveObject)& theIO,
2364 const Standard_Integer theMode)
2368 return Handle(PrsMgr_Presentation)();
2373 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2375 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2378 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2380 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2382 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2384 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2386 return Handle(PrsMgr_Presentation)();
2389 enum ViewerTest_BndAction
2396 //! Auxiliary method to print bounding box of presentation
2397 inline void bndPresentation (Draw_Interpretor& theDI,
2398 const Handle(PrsMgr_Presentation)& thePrs,
2399 const TCollection_AsciiString& theName,
2400 const ViewerTest_BndAction theAction)
2404 case BndAction_Hide:
2406 thePrs->Presentation()->GraphicUnHighlight();
2409 case BndAction_Show:
2411 thePrs->Presentation()->BoundBox();
2414 case BndAction_Print:
2416 Graphic3d_Vec3d aMin, aMax;
2417 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2418 aMax.x(), aMax.y(), aMax.z());
2419 theDI << theName << "\n"
2420 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2421 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2427 //==============================================================================
2428 //function : VBounding
2430 //==============================================================================
2431 int VBounding (Draw_Interpretor& theDI,
2432 Standard_Integer theArgNb,
2433 const char** theArgVec)
2435 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2436 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2439 std::cout << "Error: no active view!\n";
2443 ViewerTest_BndAction anAction = BndAction_Show;
2444 Standard_Integer aMode = -1;
2446 Standard_Integer anArgIter = 1;
2447 for (; anArgIter < theArgNb; ++anArgIter)
2449 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2451 if (anArg == "-print")
2453 anAction = BndAction_Print;
2455 else if (anArg == "-show")
2457 anAction = BndAction_Show;
2459 else if (anArg == "-hide")
2461 anAction = BndAction_Hide;
2463 else if (anArg == "-mode")
2465 if (++anArgIter >= theArgNb)
2467 std::cout << "Error: wrong syntax at " << anArg << "\n";
2470 aMode = Draw::Atoi (theArgVec[anArgIter]);
2472 else if (!anUpdateTool.parseRedrawMode (anArg))
2478 if (anArgIter < theArgNb)
2480 // has a list of names
2481 for (; anArgIter < theArgNb; ++anArgIter)
2483 TCollection_AsciiString aName = theArgVec[anArgIter];
2484 if (!GetMapOfAIS().IsBound2 (aName))
2486 std::cout << "Error: presentation " << aName << " does not exist\n";
2490 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2491 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2494 std::cout << "Error: presentation " << aName << " does not exist\n";
2497 bndPresentation (theDI, aPrs, aName, anAction);
2500 else if (aCtx->NbCurrents() > 0)
2502 // remove all currently selected objects
2503 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2505 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2506 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2509 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2516 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2517 anIter.More(); anIter.Next())
2519 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2520 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2523 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2530 //==============================================================================
2531 //function : VTexture
2533 //==============================================================================
2534 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2536 TCollection_AsciiString aCommandName (theArgv[0]);
2538 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2539 if (aCommandName == "vtexture")
2543 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2544 std::cout << "Type help for more information.\n";
2548 // look for options of vtexture command
2549 TCollection_AsciiString aParseKey;
2550 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2552 TCollection_AsciiString anArg (theArgv [anArgIt]);
2555 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2558 aParseKey.Remove (1);
2559 aParseKey.UpperCase();
2560 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2564 if (aParseKey.IsEmpty())
2569 aMapOfArgs(aParseKey)->Append (anArg);
2572 else if (aCommandName == "vtexscale"
2573 || aCommandName == "vtexorigin"
2574 || aCommandName == "vtexrepeat")
2576 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2577 // equal to -scale, -origin, -repeat options of vtexture command
2578 if (theArgsNb < 2 || theArgsNb > 4)
2580 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2581 std::cout << "Type help for more information.\n";
2585 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2588 anArgs->Append ("OFF");
2590 else if (theArgsNb == 4)
2592 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2593 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2596 TCollection_AsciiString anArgKey;
2597 if (aCommandName == "vtexscale")
2601 else if (aCommandName == "vtexorigin")
2603 anArgKey = "ORIGIN";
2607 anArgKey = "REPEAT";
2610 aMapOfArgs.Bind (anArgKey, anArgs);
2612 else if (aCommandName == "vtexdefault")
2614 // scan for parameters of vtexdefault command
2615 // equal to -default option of vtexture command
2616 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2619 // Check arguments for validity
2620 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2621 for (; aMapIt.More(); aMapIt.Next())
2623 const TCollection_AsciiString& aKey = aMapIt.Key();
2624 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2626 // -scale, -origin, -repeat: one argument "off", or two real values
2627 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2628 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2629 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2634 // -modulate: single argument "on" / "off"
2635 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2640 // -default: no arguments
2641 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2646 TCollection_AsciiString aLowerKey;
2649 aLowerKey.LowerCase();
2650 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2651 std::cout << "Type help for more information.\n";
2655 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2656 if (anAISContext.IsNull())
2658 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2662 Standard_Integer aPreviousMode = 0;
2664 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2666 TCollection_AsciiString aShapeName (theArgv[1]);
2667 Handle(AIS_InteractiveObject) anIO;
2669 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2670 if (aMapOfIO.IsBound2 (aShapeName))
2672 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2677 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2681 Handle(AIS_TexturedShape) aTexturedIO;
2682 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2684 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2685 aPreviousMode = aTexturedIO->DisplayMode();
2689 anAISContext->Clear (anIO, Standard_False);
2690 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2691 GetMapOfAIS().UnBind1 (anIO);
2692 GetMapOfAIS().UnBind2 (aShapeName);
2693 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2696 // -------------------------------------------
2697 // Turn texturing on/off - only for vtexture
2698 // -------------------------------------------
2700 if (aCommandName == "vtexture")
2702 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2704 if (aTextureArg.IsEmpty())
2706 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2707 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2709 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2710 if (aPreviousMode == 3)
2712 anAISContext->RecomputePrsOnly (aTexturedIO);
2715 anAISContext->Display (aTexturedIO, Standard_True);
2718 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2720 if (aTextureArg == "?")
2722 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2724 theDi << "\n Files in current directory : \n" << "\n";
2725 theDi.Eval ("glob -nocomplain *");
2727 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2728 aCmnd += aTextureFolder;
2731 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2732 theDi.Eval (aCmnd.ToCString());
2737 aTexturedIO->SetTextureFileName (aTextureArg);
2742 // ------------------------------------
2743 // Process other options and commands
2744 // ------------------------------------
2746 Handle(TColStd_HSequenceOfAsciiString) aValues;
2747 if (aMapOfArgs.Find ("DEFAULT", aValues))
2749 aTexturedIO->SetTextureRepeat (Standard_False);
2750 aTexturedIO->SetTextureOrigin (Standard_False);
2751 aTexturedIO->SetTextureScale (Standard_False);
2752 aTexturedIO->EnableTextureModulate();
2756 if (aMapOfArgs.Find ("SCALE", aValues))
2758 if (aValues->Value(1) != "OFF")
2760 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2764 aTexturedIO->SetTextureScale (Standard_False);
2768 if (aMapOfArgs.Find ("ORIGIN", aValues))
2770 if (aValues->Value(1) != "OFF")
2772 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2776 aTexturedIO->SetTextureOrigin (Standard_False);
2780 if (aMapOfArgs.Find ("REPEAT", aValues))
2782 if (aValues->Value(1) != "OFF")
2784 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2788 aTexturedIO->SetTextureRepeat (Standard_False);
2792 if (aMapOfArgs.Find ("MODULATE", aValues))
2794 if (aValues->Value(1) == "ON")
2796 aTexturedIO->EnableTextureModulate();
2800 aTexturedIO->DisableTextureModulate();
2805 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2807 anAISContext->RecomputePrsOnly (aTexturedIO);
2811 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2812 anAISContext->Display (aTexturedIO, Standard_True);
2813 anAISContext->Update (aTexturedIO,Standard_True);
2819 //==============================================================================
2820 //function : VDisplay2
2822 //purpose : Display an object from its name
2823 //==============================================================================
2824 static int VDisplay2 (Draw_Interpretor& theDI,
2825 Standard_Integer theArgNb,
2826 const char** theArgVec)
2828 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2831 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2834 else if (aCtx.IsNull())
2836 ViewerTest::ViewerInit();
2837 std::cout << "Command vinit should be called before!\n";
2839 aCtx = ViewerTest::GetAISContext();
2842 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2843 if (aCtx->HasOpenedContext())
2845 aCtx->CloseLocalContext();
2848 Standard_Integer isMutable = -1;
2849 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2851 const TCollection_AsciiString aName = theArgVec[anArgIter];
2852 TCollection_AsciiString aNameCase = aName;
2853 aNameCase.LowerCase();
2854 if (anUpdateTool.parseRedrawMode (aName))
2858 else if (aNameCase == "-mutable")
2863 else if (!GetMapOfAIS().IsBound2 (aName))
2865 // create the AIS_Shape from a name
2866 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2867 if (!aShape.IsNull())
2869 if (isMutable != -1)
2871 aShape->SetMutable (isMutable == 1);
2873 GetMapOfAIS().Bind (aShape, aName);
2874 aCtx->Display (aShape, Standard_False);
2879 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2880 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2882 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2883 if (isMutable != -1)
2885 aShape->SetMutable (isMutable == 1);
2888 if (aShape->Type() == AIS_KOI_Datum)
2890 aCtx->Display (aShape, Standard_False);
2894 theDI << "Display " << aName.ToCString() << "\n";
2895 // get the Shape from a name
2896 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2898 // update the Shape in the AIS_Shape
2899 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2900 if (!aShapePrs.IsNull())
2902 aShapePrs->Set (aNewShape);
2904 aCtx->Redisplay (aShape, Standard_False);
2905 aCtx->Display (aShape, Standard_False);
2908 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2910 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2911 TheNISContext()->Display (aShape);
2917 //===============================================================================================
2918 //function : VUpdate
2920 //===============================================================================================
2921 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2923 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2924 if (aContextAIS.IsNull())
2926 std::cout << theArgVec[0] << "AIS context is not available.\n";
2932 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2936 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2938 AIS_ListOfInteractive aListOfIO;
2940 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2942 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2944 Handle(AIS_InteractiveObject) anAISObj;
2945 if (anAISMap.IsBound2 (aName))
2947 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2950 if (anAISObj.IsNull())
2952 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2956 aListOfIO.Append (anAISObj);
2959 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2960 for (; anIOIt.More(); anIOIt.Next())
2962 aContextAIS->Update (anIOIt.Value(), Standard_False);
2965 aContextAIS->UpdateCurrentViewer();
2970 //==============================================================================
2972 //purpose : Test the annimation of an object along a
2973 // predifined trajectory
2974 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2975 //==============================================================================
2977 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2980 if (TheAISContext()->HasOpenedContext())
2981 TheAISContext()->CloseLocalContext();
2983 Standard_Real Step=4*M_PI/180;
2984 Standard_Real Angle=0;
2986 Handle(AIS_InteractiveObject) aIO;
2987 if (GetMapOfAIS().IsBound2(argv[1]))
2988 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2992 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2996 if (Draw::Atoi(argv[3])==1 ) {
2997 di<<" Primitives sensibles OFF"<<"\n";
2998 TheAISContext()->Deactivate(aIO);
3001 di<<" Primitives sensibles ON"<<"\n";
3003 // Movement par transformation
3004 if(Draw::Atoi(argv[2]) ==1) {
3005 di<<" Calcul par Transformation"<<"\n";
3006 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3010 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3011 TheAISContext()->SetLocation(aShape,myTransfo);
3012 TheAISContext() ->UpdateCurrentViewer();
3017 di<<" Calcul par Locations"<<"\n";
3018 gp_Trsf myAngleTrsf;
3019 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3020 TopLoc_Location myDeltaAngle (myAngleTrsf);
3021 TopLoc_Location myTrueLoc;
3023 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3026 myTrueLoc=myTrueLoc*myDeltaAngle;
3027 TheAISContext()->SetLocation(aShape,myTrueLoc );
3028 TheAISContext() ->UpdateCurrentViewer();
3031 if (Draw::Atoi(argv[3])==1 ){
3032 // On reactive la selection des primitives sensibles
3033 TheAISContext()->Activate(aIO,0);
3035 a3DView() -> Redraw();
3037 di<<" Temps ecoule "<<"\n";
3043 //==================================================================================
3044 // Function : VAnimation
3045 //==================================================================================
3046 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3048 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3052 Standard_Real thread = 4;
3053 Standard_Real angleA=0;
3054 Standard_Real angleB;
3056 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3059 TopoDS_Shape CrankArm;
3060 TopoDS_Shape CylinderHead;
3061 TopoDS_Shape Propeller;
3062 TopoDS_Shape EngineBlock;
3064 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3065 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3066 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3067 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3068 BRepTools::Read(CrankArm,argv[1],B);
3069 BRepTools::Read(CylinderHead,argv[2],B);
3070 BRepTools::Read(Propeller,argv[3],B);
3071 BRepTools::Read(EngineBlock,argv[4],B);
3073 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3079 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3080 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3081 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3082 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3084 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3085 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3086 GetMapOfAIS().Bind(myAisCrankArm,"c");
3087 GetMapOfAIS().Bind(myAisPropeller,"d");
3089 myAisCylinderHead->SetMutable (Standard_True);
3090 myAisEngineBlock ->SetMutable (Standard_True);
3091 myAisCrankArm ->SetMutable (Standard_True);
3092 myAisPropeller ->SetMutable (Standard_True);
3094 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3095 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3096 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3098 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3099 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3100 TheAISContext()->Display (myAisCrankArm, Standard_False);
3101 TheAISContext()->Display (myAisPropeller, Standard_False);
3103 TheAISContext()->Deactivate(myAisCylinderHead);
3104 TheAISContext()->Deactivate(myAisEngineBlock );
3105 TheAISContext()->Deactivate(myAisCrankArm );
3106 TheAISContext()->Deactivate(myAisPropeller );
3108 // Boucle de mouvement
3109 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3111 angleA = thread*myAngle*M_PI/180;
3112 X = Sin(angleA)*3/8;
3113 angleB = atan(X / Sqrt(-X * X + 1));
3114 Standard_Real decal(25*0.6);
3117 //Build a transformation on the display
3118 gp_Trsf aPropellerTrsf;
3119 aPropellerTrsf.SetRotation(Ax1,angleA);
3120 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3122 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));
3123 gp_Trsf aCrankArmTrsf;
3124 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3125 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3127 TheAISContext()->UpdateCurrentViewer();
3130 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3131 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3133 myAisCrankArm ->ResetTransformation();
3134 myAisPropeller->ResetTransformation();
3136 myAisCrankArm -> Set(myNewCrankArm );
3137 myAisPropeller -> Set(myNewPropeller);
3139 TheAISContext()->Activate(myAisCylinderHead,0);
3140 TheAISContext()->Activate(myAisEngineBlock,0 );
3141 TheAISContext()->Activate(myAisCrankArm ,0 );
3142 TheAISContext()->Activate(myAisPropeller ,0 );
3148 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3149 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3151 TheAISContext()->UpdateCurrentViewer();
3152 a3DView()->Redraw();
3161 //==============================================================================
3162 //function : VShading
3163 //purpose : Sharpen or roughten the quality of the shading
3164 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3165 //==============================================================================
3166 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3168 Standard_Real myDevCoef;
3169 Handle(AIS_InteractiveObject) TheAisIO;
3172 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3174 if (TheAISContext()->HasOpenedContext())
3175 TheAISContext()->CloseLocalContext();
3180 myDevCoef =Draw::Atof(argv[2]);
3183 TCollection_AsciiString name=argv[1];
3184 if (GetMapOfAIS().IsBound2(name ))
3185 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3186 if (TheAisIO.IsNull())
3187 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3190 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3192 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3194 TheAISContext()->Redisplay(TheAisIO);
3197 //==============================================================================
3198 //function : HaveMode
3199 //use : VActivatedModes
3200 //==============================================================================
3201 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3203 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3205 TColStd_ListOfInteger List;
3206 TheAISContext()->ActivatedModes (TheAisIO,List);
3207 TColStd_ListIteratorOfListOfInteger it;
3208 Standard_Boolean Found=Standard_False;
3209 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3210 if (it.Value()==mode ) Found=Standard_True;
3217 //==============================================================================
3218 //function : VActivatedMode
3220 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3221 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3222 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3223 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3224 // qu'un nom et qu'un mode.
3225 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3226 //==============================================================================
3227 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3229 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3232 Standard_Boolean ThereIsName = Standard_False ;
3234 if(!a3DView().IsNull()){
3236 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3237 // verification des arguments
3239 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3240 ThereIsName = (argc == 3);
3244 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3246 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3247 di<<" Fermeture du Context local"<<"\n";
3248 if (TheAISContext()->HasOpenedContext())
3249 TheAISContext()->CloseLocalContext();
3253 // IL n'y a aps de nom de shape passe en argument
3254 if (HaveToSet && !ThereIsName){
3255 Standard_Integer aMode=Draw::Atoi(argv [1]);
3257 const char *cmode="???";
3259 case 0: cmode = "Shape"; break;
3260 case 1: cmode = "Vertex"; break;
3261 case 2: cmode = "Edge"; break;
3262 case 3: cmode = "Wire"; break;
3263 case 4: cmode = "Face"; break;
3264 case 5: cmode = "Shell"; break;
3265 case 6: cmode = "Solid"; break;
3266 case 7: cmode = "Compound"; break;
3269 if( !TheAISContext()->HasOpenedContext() ) {
3270 // il n'y a pas de Context local d'ouvert
3271 // on en ouvre un et on charge toutes les shapes displayees
3272 // on load tous les objets displayees et on Activate les objets de la liste
3273 AIS_ListOfInteractive ListOfIO;
3274 // on sauve dans une AISListOfInteractive tous les objets currents
3275 if (TheAISContext()->NbCurrents()>0 ){
3276 TheAISContext()->UnhilightCurrents(Standard_False);
3278 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3279 ListOfIO.Append(TheAISContext()->Current() );
3283 TheAISContext()->OpenLocalContext(Standard_False);
3284 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3287 Handle(AIS_InteractiveObject) aIO =
3288 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3290 TheAISContext()->Load(aIO,0,Standard_False);
3293 // traitement des objets qui etaient currents dans le Contexte global
3294 if (!ListOfIO.IsEmpty() ) {
3295 // il y avait des objets currents
3296 AIS_ListIteratorOfListOfInteractive iter;
3297 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3298 Handle(AIS_InteractiveObject) aIO=iter.Value();
3299 TheAISContext()->Activate(aIO,aMode);
3300 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3304 // On applique le mode a tous les objets displayes
3305 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3306 it2 (GetMapOfAIS());
3308 Handle(AIS_InteractiveObject) aIO =
3309 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3310 if (!aIO.IsNull()) {
3311 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3312 TheAISContext()->Activate(aIO,aMode);
3321 // un Context local est deja ouvert
3322 // Traitement des objets du Context local
3323 if (TheAISContext()->NbSelected()>0 ){
3324 TheAISContext()->UnhilightSelected(Standard_False);
3325 // il y a des objets selected,on les parcourt
3326 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3327 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3330 if (HaveMode(aIO,aMode) ) {
3331 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3332 TheAISContext()->Deactivate(aIO,aMode);
3335 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3336 TheAISContext()->Activate(aIO,aMode);
3342 // il n'y a pas d'objets selected
3343 // tous les objets diplayes sont traites
3344 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3347 Handle(AIS_InteractiveObject) aIO =
3348 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3349 if (!aIO.IsNull()) {
3350 if (HaveMode(aIO,aMode) ) {
3351 di<<" Mode: "<<cmode<<" OFF pour "
3352 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3353 TheAISContext()->Deactivate(aIO,aMode);
3356 di<<" Mode: "<<cmode<<" ON pour"
3357 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3358 TheAISContext()->Activate(aIO,aMode);
3366 else if (HaveToSet && ThereIsName){
3367 Standard_Integer aMode=Draw::Atoi(argv [2]);
3368 Handle(AIS_InteractiveObject) aIO =
3369 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3371 if (!aIO.IsNull()) {
3372 const char *cmode="???";
3375 case 0: cmode = "Shape"; break;
3376 case 1: cmode = "Vertex"; break;
3377 case 2: cmode = "Edge"; break;
3378 case 3: cmode = "Wire"; break;
3379 case 4: cmode = "Face"; break;
3380 case 5: cmode = "Shell"; break;
3381 case 6: cmode = "Solid"; break;
3382 case 7: cmode = "Compound"; break;
3385 if( !TheAISContext()->HasOpenedContext() ) {
3386 TheAISContext()->OpenLocalContext(Standard_False);
3387 // On charge tous les objets de la map
3388 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3390 Handle(AIS_InteractiveObject) aShape=
3391 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3392 if (!aShape.IsNull())
3393 TheAISContext()->Load(aShape,0,Standard_False);
3396 TheAISContext()->Activate(aIO,aMode);
3397 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3401 // un Context local est deja ouvert
3402 if (HaveMode(aIO,aMode) ) {
3403 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3404 TheAISContext()->Deactivate(aIO,aMode);
3407 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3408 TheAISContext()->Activate(aIO,aMode);
3417 //! Auxiliary method to print Interactive Object information
3418 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3419 const Handle(Standard_Transient)& theObject,
3420 Draw_Interpretor& theDI)
3422 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3425 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3429 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3430 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3431 << (theDetected.Contains (anObj) ? " Detected" : " ")
3433 if (anObj->Type() == AIS_KOI_Datum)
3436 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3437 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3438 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3439 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3440 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3441 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3442 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3445 else if (anObj->Type() == AIS_KOI_Shape
3446 && anObj->Signature() == 0)
3448 theDI << " AIS_Shape";
3450 else if (anObj->Type() == AIS_KOI_Relation)
3452 // AIS_Dimention and AIS_Relation
3453 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3454 switch (aRelation->KindOfDimension())
3456 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3457 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3458 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3459 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3460 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3461 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3462 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3463 default: theDI << " UNKNOWN dimension"; break;
3468 theDI << " UserPrs";
3470 theDI << " (" << theObject->DynamicType()->Name() << ")";
3473 //! Print information about locally selected sub-shapes
3474 static void localCtxInfo (Draw_Interpretor& theDI)
3476 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3477 if (!aCtx->HasOpenedContext())
3482 TCollection_AsciiString aPrevName;
3483 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3484 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3486 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3487 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3488 if (aSubShape.IsNull()
3489 || aShapeIO.IsNull()
3490 || !GetMapOfAIS().IsBound1 (aShapeIO))
3495 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3496 TopTools_MapOfShape aFilter;
3497 Standard_Integer aNumber = 0;
3498 const TopoDS_Shape aShape = aShapeIO->Shape();
3499 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3500 anIter.More(); anIter.Next())
3502 if (!aFilter.Add (anIter.Current()))
3504 continue; // filter duplicates
3508 if (!anIter.Current().IsSame (aSubShape))
3513 Standard_CString aShapeName = NULL;
3514 switch (aSubShape.ShapeType())
3516 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3517 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3518 case TopAbs_SOLID: aShapeName = " Solid"; break;
3519 case TopAbs_SHELL: aShapeName = " Shell"; break;
3520 case TopAbs_FACE: aShapeName = " Face"; break;
3521 case TopAbs_WIRE: aShapeName = " Wire"; break;
3522 case TopAbs_EDGE: aShapeName = " Edge"; break;
3523 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3525 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3528 if (aParentName != aPrevName)
3530 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3531 aPrevName = aParentName;
3533 theDI << " " << aShapeName << " #" << aNumber << "\n";
3539 //==============================================================================
3542 //==============================================================================
3543 static Standard_Integer VState (Draw_Interpretor& theDI,
3544 Standard_Integer theArgNb,
3545 Standard_CString* theArgVec)
3547 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3550 std::cerr << "Error: No opened viewer!\n";
3554 TCollection_AsciiString anOption (theArgNb >= 2 ? theArgVec[1] : "");
3555 anOption.LowerCase();
3556 if (anOption == "-detectedEntities"
3557 || anOption == "-entities")
3559 theDI << "Detected entities:\n";
3560 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
3561 for (aSelector->Init(); aSelector->More(); aSelector->Next())
3563 Handle(SelectBasics_SensitiveEntity) anEntity = aSelector->Primitive (0);
3564 Standard_Real aMatchDMin = 0.0;
3565 Standard_Real aMatchDepth = Precision::Infinite();
3566 anEntity->Matches (aSelector->LastPickingArguments(), aMatchDMin, aMatchDepth);
3568 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3569 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3571 const gp_Lin aLine = aSelector->LastPickingArguments().PickLine();
3572 const gp_Pnt aPnt = aLine.Location().Translated (gp_Vec (aLine.Direction()) * aMatchDepth);
3574 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3575 aName.LeftJustify (20, ' ');
3576 char anInfoStr[512];
3577 Sprintf (anInfoStr, " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f", aMatchDepth, aMatchDMin, aPnt.X(), aPnt.Y(), aPnt.Z());
3578 theDI << " " << aName
3580 << " (" << anEntity->DynamicType()->Name() << ")"
3583 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
3584 if (!aBRepOwner.IsNull())
3586 theDI << " Detected Shape: "
3587 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
3591 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
3592 if (!aWire.IsNull())
3594 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
3595 theDI << " Detected Child: "
3596 << aSen->DynamicType()->Name()
3603 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3604 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3606 aDetected.Add (aCtx->DetectedCurrentObject());
3609 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3613 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3615 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3616 if (!GetMapOfAIS().IsBound2 (anObjName))
3618 theDI << anObjName << " doesn't exist!\n";
3622 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3623 TCollection_AsciiString aName = anObjName;
3624 aName.LeftJustify (20, ' ');
3625 theDI << " " << aName << " ";
3626 objInfo (aDetected, anObjTrans, theDI);
3632 if (aCtx->NbCurrents() > 0
3635 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3637 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3638 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3639 aName.LeftJustify (20, ' ');
3640 theDI << aName << " ";
3641 objInfo (aDetected, anObj, theDI);
3647 theDI << "Neutral-point state:\n";
3648 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3649 anObjIter.More(); anObjIter.Next())
3651 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3657 TCollection_AsciiString aName = anObjIter.Key2();
3658 aName.LeftJustify (20, ' ');
3659 theDI << " " << aName << " ";
3660 objInfo (aDetected, anObj, theDI);
3663 localCtxInfo (theDI);
3667 //=======================================================================
3668 //function : PickObjects
3670 //=======================================================================
3671 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3672 const AIS_KindOfInteractive TheType,
3673 const Standard_Integer TheSignature,
3674 const Standard_Integer MaxPick)
3676 Handle(AIS_InteractiveObject) IO;
3677 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3679 // step 1: prepare the data
3681 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3682 TheAISContext()->AddFilter(F1);
3685 // step 2 : wait for the selection...
3686 // Standard_Boolean IsGood (Standard_False);
3687 // Standard_Integer NbPick(0);
3688 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3689 Standard_Integer NbPickFail(0);
3690 Standard_Integer argccc = 5;
3691 const char *bufff[] = { "A", "B", "C","D", "E" };
3692 const char **argvvv = (const char **) bufff;
3695 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3696 while(ViewerMainLoop(argccc,argvvv)){}
3697 Standard_Integer NbStored = TheAISContext()->NbSelected();
3698 if((unsigned int ) NbStored != NbPickGood)
3699 NbPickGood= NbStored;
3702 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3705 // step3 get result.
3707 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3709 Standard_Integer i(0);
3710 for(TheAISContext()->InitSelected();
3711 TheAISContext()->MoreSelected();
3712 TheAISContext()->NextSelected()){
3714 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3715 arr->SetValue(i,IO2);
3720 TheAISContext()->CloseLocalContext(curindex);
3722 return Standard_True;
3726 //=======================================================================
3727 //function : PickObject
3729 //=======================================================================
3730 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3731 const Standard_Integer TheSignature,
3732 const Standard_Integer MaxPick)
3734 Handle(AIS_InteractiveObject) IO;
3735 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3737 // step 1: prepare the data
3740 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3741 TheAISContext()->AddFilter(F1);
3744 // step 2 : wait for the selection...
3745 Standard_Boolean IsGood (Standard_False);
3746 Standard_Integer NbPick(0);
3747 Standard_Integer argccc = 5;
3748 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3749 const char **argvvv = (const char **) bufff;
3752 while(!IsGood && NbPick<= MaxPick){
3753 while(ViewerMainLoop(argccc,argvvv)){}
3754 IsGood = (TheAISContext()->NbSelected()>0) ;
3756 cout<<"Nb Pick :"<<NbPick<<endl;
3760 // step3 get result.
3762 TheAISContext()->InitSelected();
3763 IO = TheAISContext()->SelectedInteractive();
3767 TheAISContext()->CloseLocalContext(curindex);
3771 //=======================================================================
3772 //function : PickShape
3773 //purpose : First Activate the rightmode + Put Filters to be able to
3774 // pick objets that are of type <TheType>...
3775 //=======================================================================
3777 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3778 const Standard_Integer MaxPick)
3781 // step 1: prepare the data
3783 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3784 TopoDS_Shape result;
3786 if(TheType==TopAbs_SHAPE){
3787 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3788 TheAISContext()->AddFilter(F1);
3791 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3792 TheAISContext()->AddFilter(TF);
3793 TheAISContext()->ActivateStandardMode(TheType);
3798 // step 2 : wait for the selection...
3799 Standard_Boolean NoShape (Standard_True);
3800 Standard_Integer NbPick(0);
3801 Standard_Integer argccc = 5;
3802 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3803 const char **argvvv = (const char **) bufff;
3806 while(NoShape && NbPick<= MaxPick){
3807 while(ViewerMainLoop(argccc,argvvv)){}
3808 NoShape = (TheAISContext()->NbSelected()==0) ;
3810 cout<<"Nb Pick :"<<NbPick<<endl;
3813 // step3 get result.
3817 TheAISContext()->InitSelected();
3818 if(TheAISContext()->HasSelectedShape())
3819 result = TheAISContext()->SelectedShape();
3821 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3822 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3827 TheAISContext()->CloseLocalContext(curindex);
3833 //=======================================================================
3834 //function : PickShapes
3836 //=======================================================================
3837 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3838 Handle(TopTools_HArray1OfShape)& thearr,
3839 const Standard_Integer MaxPick)
3842 Standard_Integer Taille = thearr->Length();
3844 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3846 // step 1: prepare the data
3847 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3848 if(TheType==TopAbs_SHAPE){
3849 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3850 TheAISContext()->AddFilter(F1);
3853 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3854 TheAISContext()->AddFilter(TF);
3855 TheAISContext()->ActivateStandardMode(TheType);
3859 // step 2 : wait for the selection...
3861 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3862 Standard_Integer NbPickFail(0);
3863 Standard_Integer argccc = 5;
3864 const char *bufff[] = { "A", "B", "C","D", "E" };
3865 const char **argvvv = (const char **) bufff;
3868 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3869 while(ViewerMainLoop(argccc,argvvv)){}
3870 Standard_Integer NbStored = TheAISContext()->NbSelected();
3871 if((unsigned int ) NbStored != NbPickGood)
3872 NbPickGood= NbStored;
3875 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3878 // step3 get result.
3880 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3882 Standard_Integer i(0);
3883 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3885 if(TheAISContext()->HasSelectedShape())
3886 thearr->SetValue(i,TheAISContext()->SelectedShape());
3888 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3889 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3893 TheAISContext()->CloseLocalContext(curindex);
3894 return Standard_True;
3898 //=======================================================================
3899 //function : VPickShape
3901 //=======================================================================
3902 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3904 TopoDS_Shape PickSh;
3905 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3908 theType = TopAbs_SHAPE;
3910 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3911 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3912 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3913 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3914 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3915 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3916 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3919 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3920 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3922 TCollection_AsciiString name;
3925 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3927 PickSh = ViewerTest::PickShape(theType);
3936 if(!PickSh.IsNull()){
3937 nbOfSub[Standard_Integer(theType)]++;
3939 name += nameType[Standard_Integer(theType)];
3940 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3945 // si on avait une petite methode pour voir si la shape
3946 // est deja dans la Double map, ca eviterait de creer....
3947 DBRep::Set(name.ToCString(),PickSh);
3949 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3950 GetMapOfAIS().Bind(newsh, name);
3951 TheAISContext()->Display(newsh);
3952 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3955 // Plusieurs objets a picker, vite vite vite....
3958 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3959 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3960 if(ViewerTest::PickShapes(theType,arr)){
3961 for(Standard_Integer i=1;i<=NbToPick;i++){
3962 PickSh = arr->Value(i);
3963 if(!PickSh.IsNull()){
3965 nbOfSub[Standard_Integer(theType)]++;
3968 name += nameType[Standard_Integer(theType)];
3969 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3977 DBRep::Set(name.ToCString(),PickSh);
3978 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3979 GetMapOfAIS().Bind(newsh, name);
3980 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3981 TheAISContext()->Display(newsh);
3989 //=======================================================================
3990 //function : list of known objects
3992 //=======================================================================
3993 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3995 // 1234567890 12345678901234567 123456789
3996 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3997 TCollection_AsciiString BlankLine(64,'_');
3998 Standard_Integer i ;
4000 di<<"/n"<<BlankLine.ToCString()<<"\n";
4003 Colum[i].Center(20,' ');
4005 di<<"|"<<Colum[i].ToCString();
4008 di<<BlankLine.ToCString()<<"\n";
4010 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4011 const char ** names = GetTypeNames();
4013 TCollection_AsciiString curstring;
4014 TCollection_AsciiString curcolum[3];
4017 // les objets de type Datum..
4018 curcolum[1]+="Datum";
4020 curcolum[0].Clear();
4021 curcolum[0] += names[i];
4023 curcolum[2].Clear();
4024 curcolum[2]+=TCollection_AsciiString(i+1);
4026 for(Standard_Integer j =0;j<=2;j++){
4027 curcolum[j].Center(20,' ');
4028 di<<"|"<<curcolum[j].ToCString();
4032 di<<BlankLine.ToCString()<<"\n";
4034 // les objets de type shape
4035 curcolum[1].Clear();
4036 curcolum[1]+="Shape";
4037 curcolum[1].Center(20,' ');
4040 curcolum[0].Clear();
4041 curcolum[0] += names[7+i];
4042 curcolum[2].Clear();
4043 curcolum[2]+=TCollection_AsciiString(i);
4045 for(Standard_Integer j =0;j<=2;j++){
4046 curcolum[j].Center(20,' ');
4047 di<<"|"<<curcolum[j].ToCString();
4051 di<<BlankLine.ToCString()<<"\n";
4052 // les IO de type objet...
4053 curcolum[1].Clear();
4054 curcolum[1]+="Object";
4055 curcolum[1].Center(20,' ');
4057 curcolum[0].Clear();
4058 curcolum[0] += names[10+i];
4059 curcolum[2].Clear();
4060 curcolum[2]+=TCollection_AsciiString(i);
4062 for(Standard_Integer j =0;j<=2;j++){
4063 curcolum[j].Center(20,' ');
4064 di<<"|"<<curcolum[j].ToCString();
4068 di<<BlankLine.ToCString()<<"\n";
4069 // les contraintes et dimensions.
4070 // pour l'instant on separe juste contraintes et dimensions...
4071 // plus tard, on detaillera toutes les sortes...
4072 curcolum[1].Clear();
4073 curcolum[1]+="Relation";
4074 curcolum[1].Center(20,' ');
4076 curcolum[0].Clear();
4077 curcolum[0] += names[12+i];
4078 curcolum[2].Clear();
4079 curcolum[2]+=TCollection_AsciiString(i);
4081 for(Standard_Integer j =0;j<=2;j++){
4082 curcolum[j].Center(20,' ');
4083 di<<"|"<<curcolum[j].ToCString();
4087 di<<BlankLine.ToCString()<<"\n";
4094 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4096 if(argc!=2) return 1;
4098 AIS_KindOfInteractive TheType;
4099 Standard_Integer TheSign(-1);
4100 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4103 AIS_ListOfInteractive LIO;
4105 // en attendant l'amelioration ais pour les dimensions...
4107 Standard_Integer dimension_status(-1);
4108 if(TheType==AIS_KOI_Relation){
4109 dimension_status = TheSign ==1 ? 1 : 0;
4113 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4114 Handle(AIS_InteractiveObject) curio;
4115 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4118 if(dimension_status == -1)
4119 TheAISContext()->Erase(curio,Standard_False);
4121 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4122 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4123 (dimension_status==1 && KOD != AIS_KOD_NONE))
4124 TheAISContext()->Erase(curio,Standard_False);
4127 TheAISContext()->UpdateCurrentViewer();
4130 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4132 if(argc!=2) return 1;
4134 AIS_KindOfInteractive TheType;
4135 Standard_Integer TheSign(-1);
4136 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4138 // en attendant l'amelioration ais pour les dimensions...
4140 Standard_Integer dimension_status(-1);
4141 if(TheType==AIS_KOI_Relation){
4142 dimension_status = TheSign ==1 ? 1 : 0;
4146 AIS_ListOfInteractive LIO;
4147 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4148 Handle(AIS_InteractiveObject) curio;
4149 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4151 if(dimension_status == -1)
4152 TheAISContext()->Display(curio,Standard_False);
4154 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4155 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4156 (dimension_status==1 && KOD != AIS_KOD_NONE))
4157 TheAISContext()->Display(curio,Standard_False);
4162 TheAISContext()->UpdateCurrentViewer();
4166 //==============================================================================
4167 //function : VSetTransMode
4169 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4170 //==============================================================================
4172 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4173 // Verification des arguments
4174 if ( a3DView().IsNull() ) {
4175 ViewerTest::ViewerInit();
4176 di << "La commande vinit n'a pas ete appele avant" << "\n";
4179 if ( argc < 3 || argc > 8 ) {
4180 di << argv[0] << " Invalid number of arguments" << "\n";
4184 TCollection_AsciiString shapeName;
4185 shapeName = argv[1];
4186 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4187 Standard_Integer persFlag2 = 0;
4188 Standard_Integer persFlag3 = 0;
4189 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4190 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4191 persFlag2 = Draw::Atoi(argv[3]);
4193 if ( argc == 5 || argc == 8 ) {
4194 persFlag3 = Draw::Atoi(argv[4]);
4197 origin.SetX( Draw::Atof(argv[argc - 3]) );
4198 origin.SetY( Draw::Atof(argv[argc - 2]) );
4199 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4202 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4203 Handle(Standard_Transient) anObj;
4205 anObj = GetMapOfAIS().Find2(shapeName);
4206 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4207 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4208 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4209 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4210 di << argv[0] << " All persistence modifiers were removed" << "\n";
4213 di << argv[0] << " Wrong object type" << "\n";
4216 } else { // Create the AIS_Shape from a name
4217 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4218 if ( !aShape.IsNull() ) {
4219 GetMapOfAIS().Bind( aShape, shapeName );
4220 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4221 TheAISContext()->Display( aShape, Standard_False );
4223 di << argv[0] << " Object not found" << "\n";
4228 // Upadate the screen and redraw the view
4229 TheAISContext()->UpdateCurrentViewer();
4233 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4236 BRep_Builder builder;
4238 BRepTools::Read(shape, s, builder);
4239 DBRep::Set(a[1], shape);
4240 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4241 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4246 //==============================================================================
4247 //function : ViewerTest::Commands
4248 //purpose : Add all the viewer command in the Draw_Interpretor
4249 //==============================================================================
4251 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4253 ViewerTest::ViewerCommands(theCommands);
4254 ViewerTest::RelationCommands(theCommands);
4255 ViewerTest::ObjectCommands(theCommands);
4256 ViewerTest::FilletCommands(theCommands);
4257 ViewerTest::VoxelCommands(theCommands);
4258 ViewerTest::OpenGlCommands(theCommands);
4260 const char *group = "AIS_Display";
4263 theCommands.Add("visos",
4264 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4265 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4266 __FILE__, visos, group);
4268 theCommands.Add("vdisplay",
4269 "vdisplay [-noupdate|-update] [-mutable] name1 [name2] ... [name n]"
4270 "\n\t\t: Displays named objects."
4271 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4272 "\n\t\t: Option -mutable enables optimizations for mutable objects."
4273 __FILE__,VDisplay2,group);
4275 theCommands.Add ("vupdate",
4276 "vupdate name1 [name2] ... [name n]"
4277 "\n\t\t: Updates named objects in interactive context",
4278 __FILE__, VUpdate, group);
4280 theCommands.Add("verase",
4281 "verase [-noupdate|-update] [name1] ... [name n]"
4282 "\n\t\t: Erases selected or named objects."
4283 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
4284 __FILE__, VErase, group);
4286 theCommands.Add("vremove",
4287 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4288 "or vremove [-context] -all to remove all objects"
4289 "\n\t\t: Removes selected or named objects."
4290 "\n\t\t If -context is in arguments, the objects are not deleted"
4291 "\n\t\t from the map of objects and names."
4292 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4293 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4294 __FILE__, VRemove, group);
4296 theCommands.Add("vdonly",
4297 "vdonly [-noupdate|-update] [name1] ... [name n]"
4298 "\n\t\t: Displays only selected or named objects",
4299 __FILE__,VDonly2,group);
4301 theCommands.Add("vdisplayall",
4302 "Displays all erased interactive objects (see vdir and vstate)",
4303 __FILE__,VDisplayAll,group);
4305 theCommands.Add("veraseall",
4306 "Erases all objects displayed in the viewer",
4307 __FILE__, VErase, group);
4309 theCommands.Add("verasetype",
4311 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4312 __FILE__,VEraseType,group);
4314 theCommands.Add("vbounding",
4315 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4316 "\n\t\t: [-print] [-hide]"
4317 "\n\t\t: Temporarily display bounding box of specified Interactive"
4318 "\n\t\t: Objects, or print it to console if -print is specified."
4319 "\n\t\t: Already displayed box might be hidden by -hide option.",
4320 __FILE__,VBounding,group);
4322 theCommands.Add("vdisplaytype",
4323 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4324 __FILE__,VDisplayType,group);
4326 theCommands.Add("vdisplaymode",
4327 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4328 __FILE__,VDispMode,group);
4330 theCommands.Add("verasemode",
4331 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4332 __FILE__,VDispMode,group);
4334 theCommands.Add("vsetdispmode",
4335 "vsetdispmode [name] mode(1,2,..)"
4336 "\n\t\t: Sets display mode for all, selected or named objects.",
4337 __FILE__,VDispMode,group);
4339 theCommands.Add("vunsetdispmode",
4340 "vunsetdispmode [name]"
4341 "\n\t\t: Unsets custom display mode for selected or named objects.",
4342 __FILE__,VDispMode,group);
4344 theCommands.Add("vdir",
4345 "Lists all objects displayed in 3D viewer",
4346 __FILE__,VDir,group);
4348 theCommands.Add("vdump",
4349 #ifdef HAVE_FREEIMAGE
4350 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4351 "\n\t\t: [width Width=0 height Height=0]"
4352 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4354 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4355 "\n\t\t: [width Width=0 height Height=0]"
4356 "\n\t\t: Dumps content of the active view into PPM image file",
4358 __FILE__,VDump,group);
4360 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4361 __FILE__,VSubInt,group);
4363 theCommands.Add("vaspects",
4364 "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4365 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
4366 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4367 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4368 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4369 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4370 "\n\t\t: Manage presentation properties of all, selected or named objects."
4371 "\n\t\t: When -subshapes is specified than following properties will be"
4372 "\n\t\t: assigned to specified sub-shapes.",
4373 __FILE__,VAspects,group);
4375 theCommands.Add("vsetcolor",
4376 "vsetcolor [-noupdate|-update] [name] ColorName"
4377 "\n\t\t: Sets color for all, selected or named objects."
4378 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4379 __FILE__,VAspects,group);
4381 theCommands.Add("vunsetcolor",
4382 "vunsetcolor [-noupdate|-update] [name]"
4383 "\n\t\t: Resets color for all, selected or named objects."
4384 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4385 __FILE__,VAspects,group);
4387 theCommands.Add("vsettransparency",
4388 "vsettransparency [-noupdate|-update] [name] Coefficient"
4389 "\n\t\t: Sets transparency for all, selected or named objects."
4390 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4391 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4392 __FILE__,VAspects,group);
4394 theCommands.Add("vunsettransparency",
4395 "vunsettransparency [-noupdate|-update] [name]"
4396 "\n\t\t: Resets transparency for all, selected or named objects."
4397 "\n\t\t: Alias for vaspects -unsettransp [name].",
4398 __FILE__,VAspects,group);
4400 theCommands.Add("vsetmaterial",
4401 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4402 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4403 __FILE__,VAspects,group);
4405 theCommands.Add("vunsetmaterial",
4406 "vunsetmaterial [-noupdate|-update] [name]"
4407 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4408 __FILE__,VAspects,group);
4410 theCommands.Add("vsetwidth",
4411 "vsetwidth [-noupdate|-update] [name] width(0->10)"
4412 "\n\t\t: Alias for vaspects -setwidth [name] width.",
4413 __FILE__,VAspects,group);
4415 theCommands.Add("vunsetwidth",
4416 "vunsetwidth [-noupdate|-update] [name]"
4417 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4418 __FILE__,VAspects,group);
4420 theCommands.Add("vsetinteriorstyle",
4421 "vsetinteriorstyle [-noupdate|-update] [name] style"
4422 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4423 __FILE__,VSetInteriorStyle,group);
4425 theCommands.Add("vardis",
4426 "vardis : display activeareas",
4427 __FILE__,VDispAreas,group);
4429 theCommands.Add("varera",
4430 "varera : erase activeareas",
4431 __FILE__,VClearAreas,group);
4433 theCommands.Add("vsensdis",
4434 "vardisp : display active entities",
4435 __FILE__,VDispSensi,group);
4436 theCommands.Add("vsensera",
4437 "vardisp : erase active entities",
4438 __FILE__,VClearSensi,group);
4440 theCommands.Add("vselprecision",
4441 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4442 __FILE__,VSelPrecision,group);
4444 theCommands.Add("vperf",
4445 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4446 __FILE__,VPerf,group);
4448 theCommands.Add("vanimation",
4449 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4450 __FILE__,VAnimation,group);
4452 theCommands.Add("vsetshading",
4453 "vsetshading : vsetshading name Quality(default=0.0008) ",
4454 __FILE__,VShading,group);
4456 theCommands.Add("vunsetshading",
4457 "vunsetshading :vunsetshading name ",
4458 __FILE__,VShading,group);
4460 theCommands.Add ("vtexture",
4461 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4462 " [-scale u v] [-scale off]\n"
4463 " [-origin u v] [-origin off]\n"
4464 " [-repeat u v] [-repeat off]\n"
4465 " [-modulate {on | off}]"
4467 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4468 " specifying one of the predefined textures.\n"
4469 " The options are: \n"
4470 " -scale u v : enable texture scaling and set scale factors\n"
4471 " -scale off : disable texture scaling\n"
4472 " -origin u v : enable texture origin positioning and set the origin\n"
4473 " -origin off : disable texture origin positioning\n"
4474 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4475 " -repeat off : disable texture repeat\n"
4476 " -modulate {on | off} : enable or disable texture modulation\n"
4477 " -default : sets texture mapping default parameters\n"
4478 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4479 "or 'vtexture NameOfShape ?' to list available textures\n",
4480 __FILE__, VTexture, group);
4482 theCommands.Add("vtexscale",
4483 "'vtexscale NameOfShape ScaleU ScaleV' \n \
4484 or 'vtexscale NameOfShape ScaleUV' \n \
4485 or 'vtexscale NameOfShape' to disable scaling\n ",
4486 __FILE__,VTexture,group);
4488 theCommands.Add("vtexorigin",
4489 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4490 or 'vtexorigin NameOfShape UVOrigin' \n \
4491 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4492 __FILE__,VTexture,group);
4494 theCommands.Add("vtexrepeat",
4495 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
4496 or 'vtexrepeat NameOfShape UVRepeat \n \
4497 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4500 theCommands.Add("vtexdefault",
4501 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4504 theCommands.Add("vsetam",
4505 "vsetActivatedModes: vsetam mode(1->7) ",
4506 __FILE__,VActivatedMode,group);
4508 theCommands.Add("vunsetam",
4509 "vunsetActivatedModes: vunsetam ",
4510 __FILE__,VActivatedMode,group);
4512 theCommands.Add("vstate",
4513 "vstate [-entities] [name1] ... [nameN]"
4514 "\n\t\t: Reports show/hidden state for selected or named objects"
4515 "\n\t\t: -entities - print low-level information about detected entities",
4516 __FILE__,VState,group);
4518 theCommands.Add("vpickshapes",
4519 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4520 __FILE__,VPickShape,group);
4522 theCommands.Add("vtypes",
4523 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4526 theCommands.Add("vsettransmode",
4527 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4528 __FILE__,VSetTransMode,group);
4530 theCommands.Add("vr", "vr : reading of the shape",
4531 __FILE__,vr, group);
4535 //=====================================================================
4536 //========================= for testing Draft and Rib =================
4537 //=====================================================================
4538 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4539 #include <DBRep.hxx>
4540 #include <TopoDS_Face.hxx>
4541 #include <gp_Pln.hxx>
4542 #include <AIS_KindOfSurface.hxx>
4543 #include <BRepOffsetAPI_DraftAngle.hxx>
4544 #include <Precision.hxx>
4545 #include <BRepAlgo.hxx>
4546 #include <OSD_Environment.hxx>
4547 #include <DrawTrSurf.hxx>
4548 //#include <DbgTools.hxx>
4549 //#include <FeatAlgo_MakeLinearForm.hxx>
4554 //=======================================================================
4555 //function : IsValid
4557 //=======================================================================
4558 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4559 const TopoDS_Shape& theResult,
4560 const Standard_Boolean closedSolid,
4561 const Standard_Boolean GeomCtrl)
4563 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4564 TCollection_AsciiString checkValid = check.Value();
4565 Standard_Boolean ToCheck = Standard_True;
4566 if (!checkValid.IsEmpty()) {
4568 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4570 if ( checkValid=="true" || checkValid=="TRUE" ) {
4571 ToCheck= Standard_False;
4575 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4578 Standard_Boolean IsValid = Standard_True;
4580 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4585 //===============================================================================
4586 // TDraft : test draft, uses AIS Viewer
4587 // Solid Face Plane Angle Reverse
4588 //===============================================================================
4589 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4591 if (argc < 5) return 1;
4592 // argv[1] - TopoDS_Shape Solid
4593 // argv[2] - TopoDS_Shape Face
4594 // argv[3] - TopoDS_Shape Plane
4595 // argv[4] - Standard_Real Angle
4596 // argv[5] - Standard_Integer Reverse
4598 // Sprintf(prefix, argv[1]);
4599 Standard_Real anAngle = 0;
4600 Standard_Boolean Rev = Standard_False;
4601 Standard_Integer rev = 0;
4602 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4603 TopoDS_Shape face = GetShapeFromName(argv[2]);
4604 TopoDS_Face Face = TopoDS::Face(face);
4605 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4606 if (Plane.IsNull ()) {
4607 di << "TEST : Plane is NULL" << "\n";
4610 anAngle = Draw::Atof(argv[4]);
4611 anAngle = 2*M_PI * anAngle / 360.0;
4613 Handle( Geom_Surface )aSurf;
4614 AIS_KindOfSurface aSurfType;
4615 Standard_Real Offset;
4617 if(argc > 4) { // == 5
4618 rev = Draw::Atoi(argv[5]);
4619 Rev = (rev)? Standard_True : Standard_False;
4622 TopoDS_Face face2 = TopoDS::Face(Plane);
4623 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4625 di << "TEST : Can't find plane" << "\n";
4629 aDir = aPln.Axis().Direction();
4632 if (Plane.Orientation() == TopAbs_REVERSED)
4634 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4636 BRepOffsetAPI_DraftAngle Draft (Solid);
4638 if(Abs(anAngle)< Precision::Angular()) {
4639 di << "TEST : NULL angle" << "\n";
4642 if(Rev) anAngle = - anAngle;
4643 Draft.Add (Face, aDir, anAngle, aPln);
4645 if (!Draft.IsDone()) {
4646 di << "TEST : Draft Not DONE " << "\n";
4649 TopTools_ListOfShape Larg;
4651 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4652 di << "TEST : DesignAlgo returns Not valid" << "\n";
4656 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4657 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4659 if ( !ais.IsNull() ) {
4660 ais->SetColor(DEFAULT_COLOR);
4661 ais->SetMaterial(DEFAULT_MATERIAL);
4662 // Display the AIS_Shape without redraw
4663 Ctx->Display(ais, Standard_False);
4665 const char *Name = "draft1";
4666 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4668 Handle(AIS_InteractiveObject) an_object =
4669 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4670 if (!an_object.IsNull()) {
4671 Ctx->Remove(an_object,
4673 GetMapOfAIS().UnBind2(Name) ;
4676 GetMapOfAIS().Bind(ais, Name);
4677 // DBRep::Set("draft", ais->Shape());
4679 Ctx->Display(ais, Standard_True);
4683 //==============================================================================
4684 //function : splitParameter
4685 //purpose : Split parameter string to parameter name and parameter value
4686 //==============================================================================
4687 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4688 TCollection_AsciiString& theName,
4689 TCollection_AsciiString& theValue)
4691 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4693 if (aParamNameEnd == 0)
4695 return Standard_False;
4698 TCollection_AsciiString aString (theString);
4699 if (aParamNameEnd != 0)
4701 theValue = aString.Split (aParamNameEnd);
4702 aString.Split (aString.Length() - 1);
4706 return Standard_True;
4709 //============================================================================
4711 //============================================================================
4712 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4715 DrawTrSurf::BasicCommands(theCommands);
4716 const char* group = "Check Features Operations commands";
4718 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4720 &TDraft,group); //Draft_Modification
4723 //==============================================================================
4724 // ViewerTest::Factory
4725 //==============================================================================
4726 void ViewerTest::Factory(Draw_Interpretor& theDI)
4728 // definition of Viewer Command
4729 ViewerTest::Commands(theDI);
4730 ViewerTest::AviCommands(theDI);
4733 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4737 // Declare entry point PLUGINFACTORY