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_SequenceOfAsciiString.hxx>
33 #include <TColStd_HSequenceOfAsciiString.hxx>
34 #include <TColStd_MapOfTransient.hxx>
35 #include <OSD_Timer.hxx>
36 #include <Geom_Axis2Placement.hxx>
37 #include <Geom_Axis1Placement.hxx>
38 #include <gp_Trsf.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <BRepAdaptor_Curve.hxx>
41 #include <StdSelect_ShapeTypeFilter.hxx>
43 #include <AIS_Drawer.hxx>
44 #include <AIS_ColoredShape.hxx>
45 #include <AIS_InteractiveObject.hxx>
46 #include <AIS_Trihedron.hxx>
47 #include <AIS_Axis.hxx>
48 #include <AIS_Relation.hxx>
49 #include <AIS_TypeFilter.hxx>
50 #include <AIS_SignatureFilter.hxx>
51 #include <AIS_LocalContext.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Aspect_InteriorStyle.hxx>
55 #include <Aspect_Window.hxx>
56 #include <Graphic3d_AspectFillArea3d.hxx>
57 #include <Graphic3d_AspectLine3d.hxx>
58 #include <Graphic3d_TextureRoot.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Prs3d_ShadingAspect.hxx>
61 #include <Prs3d_IsoAspect.hxx>
62 #include <Select3D_SensitiveWire.hxx>
63 #include <SelectMgr_EntityOwner.hxx>
64 #include <StdSelect_BRepOwner.hxx>
65 #include <StdSelect_ViewerSelector3d.hxx>
66 #include <Select3D_Projector.hxx>
67 #include <TopTools_MapOfShape.hxx>
68 #include <ViewerTest_AutoUpdater.hxx>
72 #include <Draw_Interpretor.hxx>
73 #include <TCollection_AsciiString.hxx>
74 #include <Draw_PluginMacro.hxx>
76 // avoid warnings on 'extern "C"' functions returning C++ classes
78 #define _CRT_SECURE_NO_DEPRECATE
79 #pragma warning(4:4190)
80 #pragma warning (disable:4996)
83 #include <NIS_InteractiveContext.hxx>
84 #include <NIS_Triangulated.hxx>
85 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87 #include <Quantity_Color.hxx>
88 #include <Quantity_NameOfColor.hxx>
90 #include <Graphic3d_NameOfMaterial.hxx>
92 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
95 //=======================================================================
96 //function : GetColorFromName
97 //purpose : get the Quantity_NameOfColor from a string
98 //=======================================================================
100 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
102 Quantity_NameOfColor aColor = DEFAULT_COLOR;
103 Quantity_Color::ColorFromName (theName, aColor);
107 //=======================================================================
108 //function : GetTypeNames
110 //=======================================================================
111 static const char** GetTypeNames()
113 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
114 "Shape","ConnectedShape","MultiConn.Shape",
115 "ConnectedInter.","MultiConn.",
116 "Constraint","Dimension"};
117 static const char** ThePointer = names;
121 //=======================================================================
122 //function : GetTypeAndSignfromString
124 //=======================================================================
125 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
127 const char ** thefullnames = GetTypeNames();
128 Standard_Integer index(-1);
130 for(Standard_Integer i=0;i<=13 && index==-1;i++)
131 if(!strcasecmp(name,thefullnames[i]))
135 TheType = AIS_KOI_None;
141 TheType = AIS_KOI_Datum;
145 TheType = AIS_KOI_Shape;
149 TheType = AIS_KOI_Object;
153 TheType = AIS_KOI_Relation;
162 #include <Draw_Interpretor.hxx>
164 #include <Draw_Appli.hxx>
168 #include <TCollection_AsciiString.hxx>
169 #include <V3d_Viewer.hxx>
170 #include <V3d_View.hxx>
173 #include <AIS_InteractiveContext.hxx>
174 #include <AIS_Shape.hxx>
175 #include <AIS_TexturedShape.hxx>
176 #include <AIS_DisplayMode.hxx>
177 #include <TColStd_MapOfInteger.hxx>
178 #include <AIS_MapOfInteractive.hxx>
179 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
180 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
181 #include <ViewerTest_EventManager.hxx>
183 #include <TopoDS_Solid.hxx>
184 #include <BRepTools.hxx>
185 #include <BRep_Builder.hxx>
186 #include <TopAbs_ShapeEnum.hxx>
188 #include <TopoDS.hxx>
189 #include <BRep_Tool.hxx>
192 #include <Draw_Window.hxx>
193 #include <AIS_ListIteratorOfListOfInteractive.hxx>
194 #include <AIS_ListOfInteractive.hxx>
195 #include <AIS_DisplayMode.hxx>
196 #include <TopTools_ListOfShape.hxx>
197 #include <BRepOffsetAPI_MakeThickSolid.hxx>
198 #include <BRepOffset.hxx>
200 //==============================================================================
201 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
202 //==============================================================================
203 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
204 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
209 //==============================================================================
210 //function : VDisplayAISObject
211 //purpose : register interactive object in the map of AIS objects;
212 // if other object with such name already registered, it will be kept
213 // or replaced depending on value of <theReplaceIfExists>,
214 // if "true" - the old object will be cleared from AIS context;
215 // returns Standard_True if <theAISObj> registered in map;
216 //==============================================================================
217 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
218 const Handle(AIS_InteractiveObject)& theAISObj,
219 Standard_Boolean theReplaceIfExists = Standard_True)
221 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
222 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
223 if (aContextAIS.IsNull())
225 std::cout << "AIS context is not available.\n";
226 return Standard_False;
229 if (aMap.IsBound2 (theName))
231 if (!theReplaceIfExists)
233 std::cout << "Other interactive object has been already "
234 << "registered with name: " << theName << ".\n"
235 << "Please use another name.\n";
236 return Standard_False;
239 // stop displaying object
240 Handle(AIS_InteractiveObject) anOldObj =
241 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
243 if (!anOldObj.IsNull())
244 aContextAIS->Clear (anOldObj, Standard_True);
246 // remove name and old object from map
247 aMap.UnBind2 (theName);
250 if (theAISObj.IsNull())
252 // object with specified name already unbound
253 return Standard_True;
256 // unbind AIS object if was bound with another name
257 aMap.UnBind1 (theAISObj);
259 // can be registered without rebinding
260 aMap.Bind (theAISObj, theName);
261 aContextAIS->Display (theAISObj, Standard_True);
262 return Standard_True;
265 static TColStd_MapOfInteger theactivatedmodes(8);
266 static TColStd_ListOfTransient theEventMgrs;
268 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
269 const Handle(AIS_InteractiveContext)& Ctx)
271 theEventMgrs.Clear();
272 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
275 static Handle(V3d_View)& a3DView()
277 static Handle(V3d_View) Viou;
282 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
283 static Handle(AIS_InteractiveContext) aContext;
287 const Handle(V3d_View)& ViewerTest::CurrentView()
291 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
296 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
298 static Handle(NIS_InteractiveContext) aContext;
299 if (aContext.IsNull()) {
300 aContext = new NIS_InteractiveContext;
301 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
306 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
308 return TheAISContext();
311 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
313 TheAISContext() = aCtx;
314 ViewerTest::ResetEventManager();
317 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
319 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
322 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
324 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
328 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
329 theEventMgrs.Prepend(EM);
332 void ViewerTest::UnsetEventManager()
334 theEventMgrs.RemoveFirst();
338 void ViewerTest::ResetEventManager()
340 const Handle(NIS_View) aView =
341 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
342 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
345 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
347 Handle(ViewerTest_EventManager) EM;
348 if(theEventMgrs.IsEmpty()) return EM;
349 Handle(Standard_Transient) Tr = theEventMgrs.First();
350 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
354 //=======================================================================
355 //function : Get Context and active view
357 //=======================================================================
358 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
359 Handle(V3d_View)& theView)
361 theCtx = ViewerTest::GetAISContext();
362 theView = ViewerTest::CurrentView();
366 std::cout << "Error: cannot find an active view!\n";
367 return Standard_False;
369 return Standard_True;
372 //==============================================================================
373 //function : GetShapeFromName
374 //purpose : Compute an Shape from a draw variable or a file name
375 //==============================================================================
377 static TopoDS_Shape GetShapeFromName(const char* name)
379 TopoDS_Shape S = DBRep::Get(name);
382 BRep_Builder aBuilder;
383 BRepTools::Read( S, name, aBuilder);
389 //==============================================================================
390 //function : GetAISShapeFromName
391 //purpose : Compute an AIS_Shape from a draw variable or a file name
392 //==============================================================================
393 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
395 Handle(AIS_Shape) retsh;
397 if(GetMapOfAIS().IsBound2(name)){
398 const Handle(AIS_InteractiveObject) IO =
399 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
401 if(IO->Type()==AIS_KOI_Shape) {
402 if(IO->Signature()==0){
403 retsh = *((Handle(AIS_Shape)*)&IO);
406 cout << "an Object which is not an AIS_Shape "
407 "already has this name!!!"<<endl;
414 TopoDS_Shape S = GetShapeFromName(name);
416 retsh = new AIS_Shape(S);
422 //==============================================================================
424 //purpose : Remove all the object from the viewer
425 //==============================================================================
426 void ViewerTest::Clear()
428 if ( !a3DView().IsNull() ) {
429 if (TheAISContext()->HasOpenedContext())
430 TheAISContext()->CloseLocalContext();
431 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
432 while ( it.More() ) {
433 cout << "Remove " << it.Key2() << endl;
434 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
435 const Handle(AIS_InteractiveObject) anObj =
436 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
437 TheAISContext()->Remove(anObj,Standard_False);
438 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
439 const Handle(NIS_InteractiveObject) anObj =
440 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
441 TheNISContext()->Remove(anObj);
445 TheAISContext()->UpdateCurrentViewer();
446 // TheNISContext()->UpdateViews();
447 GetMapOfAIS().Clear();
451 //==============================================================================
452 //function : StandardModesActivation
453 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
455 //==============================================================================
456 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
458 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
460 if (TheAISContext()->HasOpenedContext())
461 aContext->CloseLocalContext();
464 if(!aContext->HasOpenedContext()) {
465 // To unhilight the preselected object
466 aContext->UnhilightCurrents(Standard_False);
467 // Open a local Context in order to be able to select subshape from
468 // the selected shape if any or for all if there is no selection
469 if (!aContext->FirstCurrentObject().IsNull()){
470 aContext->OpenLocalContext(Standard_False);
472 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
473 aContext->Load( aContext->Current(),-1,Standard_True);
477 aContext->OpenLocalContext();
480 const char *cmode="???";
483 case 0: cmode = "Shape"; break;
484 case 1: cmode = "Vertex"; break;
485 case 2: cmode = "Edge"; break;
486 case 3: cmode = "Wire"; break;
487 case 4: cmode = "Face"; break;
488 case 5: cmode = "Shell"; break;
489 case 6: cmode = "Solid"; break;
490 case 7: cmode = "Compsolid"; break;
491 case 8: cmode = "Compound"; break;
494 if(theactivatedmodes.Contains(mode))
496 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
497 theactivatedmodes.Remove(mode);
498 cout<<"Mode "<< cmode <<" OFF"<<endl;
502 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
503 theactivatedmodes.Add(mode);
504 cout<<"Mode "<< cmode << " ON" << endl;
509 //==============================================================================
510 //function : CopyIsoAspect
511 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
512 //==============================================================================
513 static Handle(Prs3d_IsoAspect) CopyIsoAspect
514 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
515 const Standard_Integer theNbIsos)
517 Quantity_Color aColor;
518 Aspect_TypeOfLine aType;
519 Standard_Real aWidth;
521 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
523 Handle(Prs3d_IsoAspect) aResult =
524 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
529 //==============================================================================
531 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
532 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
533 //==============================================================================
534 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
536 if (TheAISContext().IsNull()) {
537 di << argv[0] << " Call 'vinit' before!\n";
542 di << "Current number of isos : " <<
543 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
544 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
545 di << "IsoOnPlane mode is " <<
546 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
551 Standard_Integer aLastInd = argc - 1;
552 Standard_Boolean isChanged = Standard_False;
553 Standard_Integer aNbUIsos = 0;
554 Standard_Integer aNbVIsos = 0;
557 Standard_Boolean isIsoOnPlane = Standard_False;
559 if (strcmp(argv[aLastInd], "1") == 0) {
560 isIsoOnPlane = Standard_True;
561 isChanged = Standard_True;
562 } else if (strcmp(argv[aLastInd], "0") == 0) {
563 isIsoOnPlane = Standard_False;
564 isChanged = Standard_True;
568 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
569 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
572 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
573 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
575 TheAISContext()->IsoOnPlane(isIsoOnPlane);
578 // If there are no shapes provided set the default numbers.
579 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
580 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
587 for (i = 1; i <= aLastInd; i++) {
588 TCollection_AsciiString name(argv[i]);
589 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
592 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
593 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
594 const Handle(AIS_InteractiveObject) aShape =
595 Handle(AIS_InteractiveObject)::DownCast (anObj);
596 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
597 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
598 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
601 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
602 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
603 TheAISContext()->SetLocalAttributes
604 (aShape, CurDrawer, Standard_False);
605 TheAISContext()->Redisplay(aShape);
607 di << "Number of isos for " << argv[i] << " : "
608 << aUIso->Number() << " " << aVIso->Number() << "\n";
611 di << argv[i] << ": Not an AIS interactive object!\n";
614 di << argv[i] << ": Use 'vdisplay' before\n";
619 TheAISContext()->UpdateCurrentViewer();
625 //==============================================================================
626 //function : VDispAreas,VDispSensitive,...
628 //==============================================================================
629 static Standard_Integer VDispAreas (Draw_Interpretor& ,
630 Standard_Integer theArgNb,
635 std::cout << "Error: wrong syntax!\n";
639 Handle(AIS_InteractiveContext) aCtx;
640 Handle(V3d_View) aView;
641 if (!getCtxAndView (aCtx, aView))
646 aCtx->DisplayActiveAreas (aView);
649 static Standard_Integer VClearAreas (Draw_Interpretor& ,
650 Standard_Integer theArgNb,
655 std::cout << "Error: wrong syntax!\n";
659 Handle(AIS_InteractiveContext) aCtx;
660 Handle(V3d_View) aView;
661 if (!getCtxAndView (aCtx, aView))
666 aCtx->ClearActiveAreas (aView);
670 static Standard_Integer VDispSensi (Draw_Interpretor& ,
671 Standard_Integer theArgNb,
676 std::cout << "Error: wrong syntax!\n";
680 Handle(AIS_InteractiveContext) aCtx;
681 Handle(V3d_View) aView;
682 if (!getCtxAndView (aCtx, aView))
687 aCtx->DisplayActiveSensitive (aView);
692 static Standard_Integer VClearSensi (Draw_Interpretor& ,
693 Standard_Integer theArgNb,
698 std::cout << "Error: wrong syntax!\n";
702 Handle(AIS_InteractiveContext) aCtx;
703 Handle(V3d_View) aView;
704 if (!getCtxAndView (aCtx, aView))
708 aCtx->ClearActiveSensitive (aView);
712 //==============================================================================
714 //purpose : To list the displayed object with their attributes
715 //==============================================================================
716 static int VDir (Draw_Interpretor& theDI,
720 if (!a3DView().IsNull())
725 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
726 anIter.More(); anIter.Next())
728 theDI << "\t" << anIter.Key2().ToCString() << "\n";
733 //==============================================================================
734 //function : VSelPrecision
735 //purpose : To set the selection precision mode and tolerance value
736 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
737 // value (integer number of pixel for window mode, double value of
738 // sensitivity for view mode). Without arguments the function just
739 // prints the current precision mode and the corresponding tolerance.
740 //==============================================================================
741 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
745 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
749 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
750 if( aContext.IsNull() )
755 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
756 if( aMode == StdSelect_SM_WINDOW )
758 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
759 di << "Precision mode : 0 (window)\n";
760 di << "Pixel tolerance : " << aPixelTolerance << "\n";
762 else if( aMode == StdSelect_SM_VIEW )
764 Standard_Real aSensitivity = aContext->Sensitivity();
765 di << "Precision mode : 1 (view)\n";
766 di << "Sensitivity : " << aSensitivity << "\n";
771 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
772 aContext->SetSensitivityMode( aMode );
775 if( aMode == StdSelect_SM_WINDOW )
777 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
778 aContext->SetPixelTolerance( aPixelTolerance );
780 else if( aMode == StdSelect_SM_VIEW )
782 Standard_Real aSensitivity = Draw::Atof( argv[2] );
783 aContext->SetSensitivity( aSensitivity );
790 //==============================================================================
792 //purpose : To dump the active view snapshot to image file
793 //==============================================================================
794 static Standard_Integer VDump (Draw_Interpretor& theDI,
795 Standard_Integer theArgNb,
796 Standard_CString* theArgVec)
800 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
804 Standard_Integer anArgIter = 1;
805 Standard_CString aFilePath = theArgVec[anArgIter++];
806 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
807 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
808 Standard_Integer aWidth = 0;
809 Standard_Integer aHeight = 0;
810 for (; anArgIter < theArgNb; ++anArgIter)
812 TCollection_AsciiString anArg (theArgVec[anArgIter]);
816 aBufferType = Graphic3d_BT_RGBA;
818 else if (anArg == "rgb")
820 aBufferType = Graphic3d_BT_RGB;
822 else if (anArg == "depth")
824 aBufferType = Graphic3d_BT_Depth;
826 else if (anArg == "l"
829 aStereoOpts = V3d_SDO_LEFT_EYE;
831 else if (anArg == "r"
834 aStereoOpts = V3d_SDO_RIGHT_EYE;
836 else if (anArg == "mono")
838 aStereoOpts = V3d_SDO_MONO;
840 else if (anArg == "w"
845 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
848 else if (++anArgIter >= theArgNb)
850 std::cout << "Error: integer value is expected right after 'width'\n";
853 aWidth = Draw::Atoi (theArgVec[anArgIter]);
855 else if (anArg == "h"
856 || anArg == "height")
860 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
863 if (++anArgIter >= theArgNb)
865 std::cout << "Error: integer value is expected right after 'height'\n";
868 aHeight = Draw::Atoi (theArgVec[anArgIter]);
870 else if (anArg.IsIntegerValue())
872 // compatibility with old syntax
876 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
879 else if (++anArgIter >= theArgNb)
881 std::cout << "Error: height value is expected right after width\n";
884 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
885 aHeight = Draw::Atoi (theArgVec[anArgIter]);
889 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
893 if ((aWidth <= 0 && aHeight > 0)
894 || (aWidth > 0 && aHeight <= 0))
896 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
900 Handle(V3d_View) aView = ViewerTest::CurrentView();
903 std::cout << "Error: cannot find an active view!\n";
907 if (aWidth <= 0 || aHeight <= 0)
909 if (aStereoOpts != V3d_SDO_MONO)
911 aView->Window()->Size (aWidth, aHeight);
915 if (!aView->Dump (aFilePath, aBufferType))
917 theDI << "Fail: view dump failed!\n";
923 Image_AlienPixMap aPixMap;
924 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
926 theDI << "Fail: view dump failed!\n";
930 if (aPixMap.SizeX() != Standard_Size(aWidth)
931 || aPixMap.SizeY() != Standard_Size(aHeight))
933 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
934 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
936 if (!aPixMap.Save (aFilePath))
938 theDI << "Fail: image can not be saved!\n";
944 //==============================================================================
945 //function : Displays,Erase...
948 //==============================================================================
949 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
950 const Standard_Integer Mode,
951 const Standard_Integer TypeOfOperation,
952 const Standard_Boolean Upd)
954 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
956 switch(TypeOfOperation){
958 Ctx->Display(IO,Mode,Upd);
966 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
968 Ctx->SetDisplayMode(IO,Mode,Upd);
973 Ctx->SetDisplayMode(0,Upd);
975 Ctx->UnsetDisplayMode(IO,Upd);
982 //=======================================================================
985 //=======================================================================
986 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
989 TCollection_AsciiString name;
992 // display others presentations
993 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
994 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
995 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
996 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
998 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1000 //unset displaymode.. comportement particulier...
1001 if(TypeOfOperation==4){
1003 if(Ctx->NbCurrents()==0 ||
1004 Ctx->NbSelected()==0){
1005 Handle(AIS_InteractiveObject) IO;
1006 VwrTst_DispErase(IO,-1,4,Standard_False);
1008 else if(!Ctx->HasOpenedContext()){
1009 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1010 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1013 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1014 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1015 Ctx->UpdateCurrentViewer();
1018 Handle(AIS_InteractiveObject) IO;
1020 if(GetMapOfAIS().IsBound2(name)){
1021 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1023 VwrTst_DispErase(IO,-1,4,Standard_True);
1028 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1029 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1030 Handle(AIS_InteractiveObject) IO;
1031 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1033 if(!Ctx->HasOpenedContext()){
1034 // set/unset display mode sur le Contexte...
1035 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1036 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1038 Ctx->UpdateCurrentViewer();
1041 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1042 Ctx->Display(Ctx->Interactive(),Dmode);
1046 Handle(AIS_InteractiveObject) IO;
1048 if(GetMapOfAIS().IsBound2(name))
1049 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1051 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1057 //=======================================================================
1060 //=======================================================================
1061 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1063 if(argc==1) return 1;
1064 Standard_Integer On = Draw::Atoi(argv[1]);
1065 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1069 if(!Ctx->HasOpenedContext()){
1070 di<<"sub intensite ";
1073 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1074 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1076 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1078 di <<"passage dans off"<<"\n";
1079 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1084 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1086 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1088 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1091 Ctx->UpdateCurrentViewer();
1094 Handle(AIS_InteractiveObject) IO;
1095 TCollection_AsciiString name = argv[2];
1096 if(GetMapOfAIS().IsBound2(name)){
1097 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1100 Ctx->SubIntensityOn(IO);
1102 Ctx->SubIntensityOff(IO);
1110 //! Auxiliary class to iterate presentations from different collections.
1111 class ViewTest_PrsIter
1115 //! Create and initialize iterator object.
1116 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1117 : mySource (IterSource_All)
1119 NCollection_Sequence<TCollection_AsciiString> aNames;
1120 if (!theName.IsEmpty())
1121 aNames.Append (theName);
1125 //! Create and initialize iterator object.
1126 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1127 : mySource (IterSource_All)
1132 //! Initialize the iterator.
1133 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1135 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1137 mySelIter.Nullify();
1138 myCurrent.Nullify();
1139 myCurrentTrs.Nullify();
1140 if (!mySeq.IsEmpty())
1142 mySource = IterSource_List;
1143 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1145 else if (aCtx->NbCurrents() > 0)
1147 mySource = IterSource_Selected;
1149 mySelIter->InitCurrent();
1153 mySource = IterSource_All;
1154 myMapIter.Initialize (GetMapOfAIS());
1159 const TCollection_AsciiString& CurrentName() const
1161 return myCurrentName;
1164 const Handle(AIS_InteractiveObject)& Current() const
1169 const Handle(Standard_Transient)& CurrentTrs() const
1171 return myCurrentTrs;
1174 //! @return true if iterator points to valid object within collection
1175 Standard_Boolean More() const
1179 case IterSource_All: return myMapIter.More();
1180 case IterSource_List: return mySeqIter.More();
1181 case IterSource_Selected: return mySelIter->MoreCurrent();
1183 return Standard_False;
1186 //! Go to the next item.
1189 myCurrentName.Clear();
1190 myCurrentTrs.Nullify();
1191 myCurrent.Nullify();
1194 case IterSource_All:
1199 case IterSource_List:
1204 case IterSource_Selected:
1206 mySelIter->NextCurrent();
1219 case IterSource_All:
1221 if (myMapIter.More())
1223 myCurrentName = myMapIter.Key2();
1224 myCurrentTrs = myMapIter.Key1();
1225 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1229 case IterSource_List:
1231 if (mySeqIter.More())
1233 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1235 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1238 myCurrentName = mySeqIter.Value();
1239 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1240 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1244 case IterSource_Selected:
1246 if (mySelIter->MoreCurrent())
1248 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1249 myCurrent = mySelIter->Current();
1267 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1268 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1269 NCollection_Sequence<TCollection_AsciiString> mySeq;
1270 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1272 TCollection_AsciiString myCurrentName;//!< current item name
1273 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1274 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1276 IterSource mySource; //!< iterated collection
1280 //==============================================================================
1281 //function : VInteriorStyle
1282 //purpose : sets interior style of the a selected or named or displayed shape
1283 //==============================================================================
1284 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1285 Standard_Integer theArgNb,
1286 const char** theArgVec)
1288 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1289 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1292 std::cerr << "Error: no active view!\n";
1296 Standard_Integer anArgIter = 1;
1297 for (; anArgIter < theArgNb; ++anArgIter)
1299 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1304 TCollection_AsciiString aName;
1305 if (theArgNb - anArgIter == 2)
1307 aName = theArgVec[anArgIter++];
1309 else if (theArgNb - anArgIter != 1)
1311 std::cout << "Error: wrong number of arguments! See usage:\n";
1312 theDI.PrintHelp (theArgVec[0]);
1315 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1316 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1317 aStyleArg.LowerCase();
1318 if (aStyleArg == "empty")
1322 else if (aStyleArg == "hollow")
1326 else if (aStyleArg == "hatch")
1330 else if (aStyleArg == "solid")
1334 else if (aStyleArg == "hiddenline")
1340 anInterStyle = aStyleArg.IntegerValue();
1342 if (anInterStyle < Aspect_IS_EMPTY
1343 || anInterStyle > Aspect_IS_HIDDENLINE)
1345 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1346 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1350 if (!aName.IsEmpty()
1351 && !GetMapOfAIS().IsBound2 (aName))
1353 std::cout << "Error: object " << aName << " is not displayed!\n";
1357 if (aCtx->HasOpenedContext())
1359 aCtx->CloseLocalContext();
1361 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1363 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1366 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1367 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1368 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1369 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1370 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1376 //! Auxiliary structure for VAspects
1377 struct ViewerTest_AspectsChangeSet
1379 Standard_Integer ToSetColor;
1380 Quantity_Color Color;
1382 Standard_Integer ToSetLineWidth;
1383 Standard_Real LineWidth;
1385 Standard_Integer ToSetTransparency;
1386 Standard_Real Transparency;
1388 Standard_Integer ToSetMaterial;
1389 Graphic3d_NameOfMaterial Material;
1390 TCollection_AsciiString MatName;
1392 NCollection_Sequence<TopoDS_Shape> SubShapes;
1394 //! Empty constructor
1395 ViewerTest_AspectsChangeSet()
1397 Color (DEFAULT_COLOR),
1400 ToSetTransparency (0),
1403 Material (Graphic3d_NOM_DEFAULT) {}
1405 //! @return true if no changes have been requested
1406 Standard_Boolean IsEmpty() const
1408 return ToSetLineWidth == 0
1409 && ToSetTransparency == 0
1411 && ToSetMaterial == 0;
1414 //! @return true if properties are valid
1415 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1417 Standard_Boolean isOk = Standard_True;
1418 if (LineWidth <= 0.0
1419 || LineWidth > 10.0)
1421 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1422 isOk = Standard_False;
1424 if (Transparency < 0.0
1425 || Transparency > 1.0)
1427 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1428 isOk = Standard_False;
1431 && ToSetTransparency)
1433 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1434 isOk = Standard_False;
1436 if (ToSetMaterial == 1
1437 && Material == Graphic3d_NOM_DEFAULT)
1439 std::cout << "Error: unknown material " << MatName << ".\n";
1440 isOk = Standard_False;
1447 //==============================================================================
1448 //function : VAspects
1450 //==============================================================================
1451 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1452 Standard_Integer theArgNb,
1453 const char** theArgVec)
1455 TCollection_AsciiString aCmdName (theArgVec[0]);
1456 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1457 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1460 std::cerr << "Error: no active view!\n";
1464 Standard_Integer anArgIter = 1;
1465 NCollection_Sequence<TCollection_AsciiString> aNames;
1466 for (; anArgIter < theArgNb; ++anArgIter)
1468 TCollection_AsciiString anArg = theArgVec[anArgIter];
1469 if (anUpdateTool.parseRedrawMode (anArg))
1473 else if (!anArg.IsEmpty()
1474 && anArg.Value (1) != '-')
1476 aNames.Append (anArg);
1484 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1485 aChanges.Append (ViewerTest_AspectsChangeSet());
1486 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1488 // parse syntax of legacy commands
1489 if (aCmdName == "vsetwidth")
1491 if (aNames.IsEmpty()
1492 || !aNames.Last().IsRealValue())
1494 std::cout << "Error: not enough arguments!\n";
1497 aChangeSet->ToSetLineWidth = 1;
1498 aChangeSet->LineWidth = aNames.Last().RealValue();
1499 aNames.Remove (aNames.Length());
1501 else if (aCmdName == "vunsetwidth")
1503 aChangeSet->ToSetLineWidth = -1;
1505 else if (aCmdName == "vsetcolor")
1507 if (aNames.IsEmpty())
1509 std::cout << "Error: not enough arguments!\n";
1512 aChangeSet->ToSetColor = 1;
1514 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1515 Standard_Boolean isOk = Standard_False;
1516 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1518 aChangeSet->Color = aColor;
1519 aNames.Remove (aNames.Length());
1520 isOk = Standard_True;
1522 else if (aNames.Length() >= 3)
1524 const TCollection_AsciiString anRgbStr[3] =
1526 aNames.Value (aNames.Upper() - 2),
1527 aNames.Value (aNames.Upper() - 1),
1528 aNames.Value (aNames.Upper() - 0)
1530 isOk = anRgbStr[0].IsRealValue()
1531 && anRgbStr[1].IsRealValue()
1532 && anRgbStr[2].IsRealValue();
1535 Graphic3d_Vec4d anRgb;
1536 anRgb.x() = anRgbStr[0].RealValue();
1537 anRgb.y() = anRgbStr[1].RealValue();
1538 anRgb.z() = anRgbStr[2].RealValue();
1539 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1540 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1541 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1543 std::cout << "Error: RGB color values should be within range 0..1!\n";
1546 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1547 aNames.Remove (aNames.Length());
1548 aNames.Remove (aNames.Length());
1549 aNames.Remove (aNames.Length());
1554 std::cout << "Error: not enough arguments!\n";
1558 else if (aCmdName == "vunsetcolor")
1560 aChangeSet->ToSetColor = -1;
1562 else if (aCmdName == "vsettransparency")
1564 if (aNames.IsEmpty()
1565 || !aNames.Last().IsRealValue())
1567 std::cout << "Error: not enough arguments!\n";
1570 aChangeSet->ToSetTransparency = 1;
1571 aChangeSet->Transparency = aNames.Last().RealValue();
1572 aNames.Remove (aNames.Length());
1574 else if (aCmdName == "vunsettransparency")
1576 aChangeSet->ToSetTransparency = -1;
1578 else if (aCmdName == "vsetmaterial")
1580 if (aNames.IsEmpty())
1582 std::cout << "Error: not enough arguments!\n";
1585 aChangeSet->ToSetMaterial = 1;
1586 aChangeSet->MatName = aNames.Last();
1587 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1588 aNames.Remove (aNames.Length());
1590 else if (aCmdName == "vunsetmaterial")
1592 aChangeSet->ToSetMaterial = -1;
1594 else if (anArgIter >= theArgNb)
1596 std::cout << "Error: not enough arguments!\n";
1600 if (!aChangeSet->IsEmpty())
1602 anArgIter = theArgNb;
1604 for (; anArgIter < theArgNb; ++anArgIter)
1606 TCollection_AsciiString anArg = theArgVec[anArgIter];
1608 if (anArg == "-setwidth"
1609 || anArg == "-setlinewidth")
1611 if (++anArgIter >= theArgNb)
1613 std::cout << "Error: wrong syntax at " << anArg << "\n";
1616 aChangeSet->ToSetLineWidth = 1;
1617 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1619 else if (anArg == "-unsetwidth"
1620 || anArg == "-unsetlinewidth")
1622 aChangeSet->ToSetLineWidth = -1;
1623 aChangeSet->LineWidth = 1.0;
1625 else if (anArg == "-settransp"
1626 || anArg == "-settransparency")
1628 if (++anArgIter >= theArgNb)
1630 std::cout << "Error: wrong syntax at " << anArg << "\n";
1633 aChangeSet->ToSetTransparency = 1;
1634 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1635 if (aChangeSet->Transparency >= 0.0
1636 && aChangeSet->Transparency <= Precision::Confusion())
1638 aChangeSet->ToSetTransparency = -1;
1639 aChangeSet->Transparency = 0.0;
1642 else if (anArg == "-setalpha")
1644 if (++anArgIter >= theArgNb)
1646 std::cout << "Error: wrong syntax at " << anArg << "\n";
1649 aChangeSet->ToSetTransparency = 1;
1650 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1651 if (aChangeSet->Transparency < 0.0
1652 || aChangeSet->Transparency > 1.0)
1654 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1657 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1658 if (aChangeSet->Transparency >= 0.0
1659 && aChangeSet->Transparency <= Precision::Confusion())
1661 aChangeSet->ToSetTransparency = -1;
1662 aChangeSet->Transparency = 0.0;
1665 else if (anArg == "-unsettransp"
1666 || anArg == "-unsettransparency"
1667 || anArg == "-unsetalpha"
1668 || anArg == "-opaque")
1670 aChangeSet->ToSetTransparency = -1;
1671 aChangeSet->Transparency = 0.0;
1673 else if (anArg == "-setcolor")
1675 Standard_Integer aNbComps = 0;
1676 Standard_Integer aCompIter = anArgIter + 1;
1677 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1679 if (theArgVec[aCompIter][0] == '-')
1688 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1689 Standard_CString aName = theArgVec[anArgIter + 1];
1690 if (!Quantity_Color::ColorFromName (aName, aColor))
1692 std::cout << "Error: unknown color name '" << aName << "'\n";
1695 aChangeSet->Color = aColor;
1700 Graphic3d_Vec3d anRgb;
1701 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1702 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1703 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1704 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1705 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1706 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1708 std::cout << "Error: RGB color values should be within range 0..1!\n";
1711 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1716 std::cout << "Error: wrong syntax at " << anArg << "\n";
1720 aChangeSet->ToSetColor = 1;
1721 anArgIter += aNbComps;
1723 else if (anArg == "-unsetcolor")
1725 aChangeSet->ToSetColor = -1;
1726 aChangeSet->Color = DEFAULT_COLOR;
1728 else if (anArg == "-setmat"
1729 || anArg == "-setmaterial")
1731 if (++anArgIter >= theArgNb)
1733 std::cout << "Error: wrong syntax at " << anArg << "\n";
1736 aChangeSet->ToSetMaterial = 1;
1737 aChangeSet->MatName = theArgVec[anArgIter];
1738 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1740 else if (anArg == "-unsetmat"
1741 || anArg == "-unsetmaterial")
1743 aChangeSet->ToSetMaterial = -1;
1744 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1746 else if (anArg == "-subshape"
1747 || anArg == "-subshapes")
1749 if (aNames.IsEmpty())
1751 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1755 aChanges.Append (ViewerTest_AspectsChangeSet());
1756 aChangeSet = &aChanges.ChangeLast();
1758 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1760 Standard_CString aSubShapeName = theArgVec[anArgIter];
1761 if (*aSubShapeName == '-')
1767 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1768 if (aSubShape.IsNull())
1770 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1773 aChangeSet->SubShapes.Append (aSubShape);
1776 if (aChangeSet->SubShapes.IsEmpty())
1778 std::cerr << "Error: empty list is specified after -subshapes!\n";
1782 else if (anArg == "-unset")
1784 aChangeSet->ToSetLineWidth = -1;
1785 aChangeSet->LineWidth = 1.0;
1786 aChangeSet->ToSetTransparency = -1;
1787 aChangeSet->Transparency = 0.0;
1788 aChangeSet->ToSetColor = -1;
1789 aChangeSet->Color = DEFAULT_COLOR;
1790 aChangeSet->ToSetMaterial = -1;
1791 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1795 std::cout << "Error: wrong syntax at " << anArg << "\n";
1800 Standard_Boolean isFirst = Standard_True;
1801 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1802 aChangesIter.More(); aChangesIter.Next())
1804 if (!aChangesIter.Value().Validate (!isFirst))
1808 isFirst = Standard_False;
1811 if (aCtx->HasOpenedContext())
1813 aCtx->CloseLocalContext();
1815 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1817 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1818 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1819 Handle(AIS_ColoredShape) aColoredPrs;
1820 Standard_Boolean toDisplay = Standard_False;
1821 if (aChanges.Length() > 1)
1823 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1824 if (aShapePrs.IsNull())
1826 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1829 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1830 if (aColoredPrs.IsNull())
1832 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1833 aCtx->Remove (aShapePrs, Standard_False);
1834 GetMapOfAIS().UnBind2 (aName);
1835 GetMapOfAIS().Bind (aColoredPrs, aName);
1836 toDisplay = Standard_True;
1837 aShapePrs = aColoredPrs;
1844 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1845 aChangeSet = &aChangesIter.ChangeValue();
1846 if (aChangeSet->ToSetMaterial == 1)
1848 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1850 else if (aChangeSet->ToSetMaterial == -1)
1852 aCtx->UnsetMaterial (aPrs, Standard_False);
1854 if (aChangeSet->ToSetColor == 1)
1856 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1858 else if (aChangeSet->ToSetColor == -1)
1860 aCtx->UnsetColor (aPrs, Standard_False);
1862 if (aChangeSet->ToSetTransparency == 1)
1864 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1866 else if (aChangeSet->ToSetTransparency == -1)
1868 aCtx->UnsetTransparency (aPrs, Standard_False);
1870 if (aChangeSet->ToSetLineWidth == 1)
1872 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1874 else if (aChangeSet->ToSetLineWidth == -1)
1876 aCtx->UnsetWidth (aPrs, Standard_False);
1879 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1881 aChangeSet = &aChangesIter.ChangeValue();
1882 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1883 aSubShapeIter.More(); aSubShapeIter.Next())
1885 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1886 if (aChangeSet->ToSetColor == 1)
1888 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1890 if (aChangeSet->ToSetLineWidth == 1)
1892 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1894 if (aChangeSet->ToSetColor == -1
1895 || aChangeSet->ToSetLineWidth == -1)
1897 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1903 aCtx->Display (aPrs, Standard_False);
1905 else if (!aColoredPrs.IsNull())
1907 aColoredPrs->Redisplay();
1912 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1913 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1914 if (!aNisObj.IsNull())
1916 if (aChangeSet->ToSetTransparency != 0)
1918 aNisObj->SetTransparency (aChangeSet->Transparency);
1921 if (!aNisTri.IsNull())
1923 if (aChangeSet->ToSetColor != 0)
1925 aNisTri->SetColor (aChangeSet->Color);
1927 if (aChangeSet->ToSetLineWidth != 0)
1929 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1937 //==============================================================================
1938 //function : VDonly2
1940 //purpose : Display only a selected or named object
1941 // if there is no selected or named object s, nothing is done
1942 //==============================================================================
1943 static int VDonly2 (Draw_Interpretor& ,
1944 Standard_Integer theArgNb,
1945 const char** theArgVec)
1947 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1948 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1951 std::cerr << "Error: no active view!\n";
1955 if (aCtx->HasOpenedContext())
1957 aCtx->CloseLocalContext();
1960 Standard_Integer anArgIter = 1;
1961 for (; anArgIter < theArgNb; ++anArgIter)
1963 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1969 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1970 if (anArgIter >= theArgNb)
1972 // display only selected objects
1973 if (aCtx->NbCurrents() < 1)
1978 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1980 aDispSet.Add (aCtx->Current());
1985 // display only specified objects
1986 for (; anArgIter < theArgNb; ++anArgIter)
1988 TCollection_AsciiString aName = theArgVec[anArgIter];
1989 if (GetMapOfAIS().IsBound2 (aName))
1991 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1992 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1994 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1995 aCtx->Display (aShape, Standard_False);
1997 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1999 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2000 TheNISContext()->Display (aShape);
2002 aDispSet.Add (anObj);
2007 // weed out other objects
2008 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2010 if (aDispSet.Contains (anIter.Key1()))
2015 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2017 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2018 aCtx->Erase (aShape, Standard_False);
2020 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2022 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2023 TheNISContext()->Erase (aShape);
2029 //==============================================================================
2030 //function : VRemove
2031 //purpose : Removes selected or named objects.
2032 // If there is no selected or named objects,
2033 // all objects in the viewer can be removed with argument -all.
2034 // If -context is in arguments, the object is not deleted from the map of
2035 // objects (deleted only from the current context).
2036 //==============================================================================
2037 int VRemove (Draw_Interpretor& theDI,
2038 Standard_Integer theArgNb,
2039 const char** theArgVec)
2041 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2042 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2045 std::cerr << "Error: no active view!\n";
2049 Standard_Boolean isContextOnly = Standard_False;
2050 Standard_Boolean toRemoveAll = Standard_False;
2051 Standard_Boolean toPrintInfo = Standard_True;
2052 Standard_Boolean toRemoveLocal = Standard_False;
2054 Standard_Integer anArgIter = 1;
2055 for (; anArgIter < theArgNb; ++anArgIter)
2057 TCollection_AsciiString anArg = theArgVec[anArgIter];
2059 if (anArg == "-context")
2061 isContextOnly = Standard_True;
2063 else if (anArg == "-all")
2065 toRemoveAll = Standard_True;
2067 else if (anArg == "-noinfo")
2069 toPrintInfo = Standard_False;
2071 else if (anArg == "-local")
2073 toRemoveLocal = Standard_True;
2075 else if (anUpdateTool.parseRedrawMode (anArg))
2085 && anArgIter < theArgNb)
2087 std::cerr << "Error: wrong syntax!\n";
2091 if (toRemoveLocal && !aCtx->HasOpenedContext())
2093 std::cerr << "Error: local selection context is not open.\n";
2096 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2098 aCtx->CloseAllContexts (Standard_False);
2101 NCollection_List<TCollection_AsciiString> anIONameList;
2104 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2105 anIter.More(); anIter.Next())
2107 anIONameList.Append (anIter.Key2());
2110 else if (anArgIter < theArgNb) // removed objects names are in argument list
2112 for (; anArgIter < theArgNb; ++anArgIter)
2114 TCollection_AsciiString aName = theArgVec[anArgIter];
2115 if (!GetMapOfAIS().IsBound2 (aName))
2117 theDI << aName.ToCString() << " was not bound to some object.\n";
2121 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2123 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2126 if (anIO->GetContext() != aCtx)
2128 theDI << aName.ToCString() << " was not displayed in current context.\n";
2129 theDI << "Please activate view with this object displayed and try again.\n";
2133 anIONameList.Append (aName);
2137 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2138 if (!aNisIO.IsNull())
2140 anIONameList.Append (aName);
2144 else if (aCtx->NbCurrents() > 0
2145 || TheNISContext()->GetSelected().Extent() > 0)
2147 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2148 anIter.More(); anIter.Next())
2150 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2153 if (!aCtx->IsCurrent (anIO))
2158 anIONameList.Append (anIter.Key2());
2162 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2163 if (!aNisIO.IsNull())
2165 if (!TheNISContext()->IsSelected (aNisIO))
2170 anIONameList.Append (anIter.Key2());
2175 // Unbind all removed objects from the map of displayed IO.
2176 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2177 anIter.More(); anIter.Next())
2179 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2182 aCtx->Remove (anIO, Standard_False);
2185 theDI << anIter.Value().ToCString() << " was removed\n";
2190 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2191 if (!aNisIO.IsNull())
2193 TheNISContext()->Remove (aNisIO);
2196 theDI << anIter.Value().ToCString() << " was removed\n";
2202 GetMapOfAIS().UnBind2 (anIter.Value());
2206 // Close local context if it is empty
2207 TColStd_MapOfTransient aLocalIO;
2208 if (aCtx->HasOpenedContext()
2209 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2211 aCtx->CloseAllContexts (Standard_False);
2217 //==============================================================================
2219 //purpose : Erase some selected or named objects
2220 // if there is no selected or named objects, the whole viewer is erased
2221 //==============================================================================
2222 int VErase (Draw_Interpretor& theDI,
2223 Standard_Integer theArgNb,
2224 const char** theArgVec)
2226 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2227 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2230 std::cerr << "Error: no active view!\n";
2234 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2236 Standard_Integer anArgIter = 1;
2237 Standard_Boolean toEraseLocal = Standard_False;
2238 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2239 for (; anArgIter < theArgNb; ++anArgIter)
2241 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2242 anArgCase.LowerCase();
2243 if (anUpdateTool.parseRedrawMode (anArgCase))
2247 else if (anArgCase == "-local")
2249 toEraseLocal = Standard_True;
2253 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2257 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2259 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2263 if (toEraseLocal && !aCtx->HasOpenedContext())
2265 std::cerr << "Error: local selection context is not open.\n";
2268 else if (!toEraseLocal && aCtx->HasOpenedContext())
2270 aCtx->CloseAllContexts (Standard_False);
2273 if (!aNamesOfEraseIO.IsEmpty())
2275 // Erase named objects
2276 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2278 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2279 if (!GetMapOfAIS().IsBound2 (aName))
2284 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2285 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2286 theDI << aName.ToCString() << " ";
2289 aCtx->Erase (anIO, Standard_False);
2293 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2294 if (!aNisIO.IsNull())
2296 TheNISContext()->Erase (aNisIO);
2301 else if (!toEraseAll && aCtx->NbCurrents() > 0)
2303 // Erase selected objects
2304 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2305 anIter.More(); anIter.Next())
2307 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2309 && aCtx->IsCurrent (anIO))
2311 theDI << anIter.Key2().ToCString() << " ";
2312 aCtx->Erase (anIO, Standard_False);
2318 // Erase all objects
2319 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2320 anIter.More(); anIter.Next())
2322 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2325 aCtx->Erase (anIO, Standard_False);
2329 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2330 if (!aNisIO.IsNull())
2332 TheNISContext()->Erase (aNisIO);
2341 //==============================================================================
2342 //function : VDisplayAll
2344 //purpose : Display all the objects of the Map
2345 //==============================================================================
2346 static int VDisplayAll (Draw_Interpretor& ,
2347 Standard_Integer theArgNb,
2348 const char** theArgVec)
2351 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2352 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2355 std::cerr << "Error: no active view!\n";
2359 Standard_Integer anArgIter = 1;
2360 Standard_Boolean toDisplayLocal = Standard_False;
2361 for (; anArgIter < theArgNb; ++anArgIter)
2363 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2364 anArgCase.LowerCase();
2365 if (anArgCase == "-local")
2367 toDisplayLocal = Standard_True;
2369 else if (anUpdateTool.parseRedrawMode (anArgCase))
2378 if (anArgIter < theArgNb)
2380 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2384 if (toDisplayLocal && !aCtx->HasOpenedContext())
2386 std::cerr << "Error: local selection context is not open.\n";
2389 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2391 aCtx->CloseLocalContext (Standard_False);
2394 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2395 anIter.More(); anIter.Next())
2397 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2399 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2400 aCtx->Erase (aShape, Standard_False);
2402 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2404 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2405 TheNISContext()->Erase (aShape);
2409 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2410 anIter.More(); anIter.Next())
2412 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2414 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2415 aCtx->Display (aShape, Standard_False);
2417 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2419 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2420 TheNISContext()->Display (aShape);
2426 //! Auxiliary method to find presentation
2427 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2428 const Handle(AIS_InteractiveObject)& theIO,
2429 const Standard_Integer theMode)
2433 return Handle(PrsMgr_Presentation)();
2438 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2440 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2443 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2445 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2447 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2449 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2451 return Handle(PrsMgr_Presentation)();
2454 enum ViewerTest_BndAction
2461 //! Auxiliary method to print bounding box of presentation
2462 inline void bndPresentation (Draw_Interpretor& theDI,
2463 const Handle(PrsMgr_Presentation)& thePrs,
2464 const TCollection_AsciiString& theName,
2465 const ViewerTest_BndAction theAction)
2469 case BndAction_Hide:
2471 thePrs->Presentation()->GraphicUnHighlight();
2474 case BndAction_Show:
2476 thePrs->Presentation()->BoundBox();
2479 case BndAction_Print:
2481 Graphic3d_Vec3d aMin, aMax;
2482 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2483 aMax.x(), aMax.y(), aMax.z());
2484 theDI << theName << "\n"
2485 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2486 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2492 //==============================================================================
2493 //function : VBounding
2495 //==============================================================================
2496 int VBounding (Draw_Interpretor& theDI,
2497 Standard_Integer theArgNb,
2498 const char** theArgVec)
2500 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2501 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2504 std::cout << "Error: no active view!\n";
2508 ViewerTest_BndAction anAction = BndAction_Show;
2509 Standard_Integer aMode = -1;
2511 Standard_Integer anArgIter = 1;
2512 for (; anArgIter < theArgNb; ++anArgIter)
2514 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2516 if (anArg == "-print")
2518 anAction = BndAction_Print;
2520 else if (anArg == "-show")
2522 anAction = BndAction_Show;
2524 else if (anArg == "-hide")
2526 anAction = BndAction_Hide;
2528 else if (anArg == "-mode")
2530 if (++anArgIter >= theArgNb)
2532 std::cout << "Error: wrong syntax at " << anArg << "\n";
2535 aMode = Draw::Atoi (theArgVec[anArgIter]);
2537 else if (!anUpdateTool.parseRedrawMode (anArg))
2543 if (anArgIter < theArgNb)
2545 // has a list of names
2546 for (; anArgIter < theArgNb; ++anArgIter)
2548 TCollection_AsciiString aName = theArgVec[anArgIter];
2549 if (!GetMapOfAIS().IsBound2 (aName))
2551 std::cout << "Error: presentation " << aName << " does not exist\n";
2555 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2556 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2559 std::cout << "Error: presentation " << aName << " does not exist\n";
2562 bndPresentation (theDI, aPrs, aName, anAction);
2565 else if (aCtx->NbCurrents() > 0)
2567 // remove all currently selected objects
2568 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2570 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2571 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2574 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2581 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2582 anIter.More(); anIter.Next())
2584 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2585 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2588 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2595 //==============================================================================
2596 //function : VTexture
2598 //==============================================================================
2599 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2601 TCollection_AsciiString aCommandName (theArgv[0]);
2603 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2604 if (aCommandName == "vtexture")
2608 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2609 std::cout << "Type help for more information.\n";
2613 // look for options of vtexture command
2614 TCollection_AsciiString aParseKey;
2615 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2617 TCollection_AsciiString anArg (theArgv [anArgIt]);
2620 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2623 aParseKey.Remove (1);
2624 aParseKey.UpperCase();
2625 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2629 if (aParseKey.IsEmpty())
2634 aMapOfArgs(aParseKey)->Append (anArg);
2637 else if (aCommandName == "vtexscale"
2638 || aCommandName == "vtexorigin"
2639 || aCommandName == "vtexrepeat")
2641 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2642 // equal to -scale, -origin, -repeat options of vtexture command
2643 if (theArgsNb < 2 || theArgsNb > 4)
2645 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2646 std::cout << "Type help for more information.\n";
2650 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2653 anArgs->Append ("OFF");
2655 else if (theArgsNb == 4)
2657 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2658 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2661 TCollection_AsciiString anArgKey;
2662 if (aCommandName == "vtexscale")
2666 else if (aCommandName == "vtexorigin")
2668 anArgKey = "ORIGIN";
2672 anArgKey = "REPEAT";
2675 aMapOfArgs.Bind (anArgKey, anArgs);
2677 else if (aCommandName == "vtexdefault")
2679 // scan for parameters of vtexdefault command
2680 // equal to -default option of vtexture command
2681 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2684 // Check arguments for validity
2685 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2686 for (; aMapIt.More(); aMapIt.Next())
2688 const TCollection_AsciiString& aKey = aMapIt.Key();
2689 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2691 // -scale, -origin, -repeat: one argument "off", or two real values
2692 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2693 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2694 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2699 // -modulate: single argument "on" / "off"
2700 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2705 // -default: no arguments
2706 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2711 TCollection_AsciiString aLowerKey;
2714 aLowerKey.LowerCase();
2715 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2716 std::cout << "Type help for more information.\n";
2720 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2721 if (anAISContext.IsNull())
2723 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2727 Standard_Integer aPreviousMode = 0;
2729 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2731 TCollection_AsciiString aShapeName (theArgv[1]);
2732 Handle(AIS_InteractiveObject) anIO;
2734 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2735 if (aMapOfIO.IsBound2 (aShapeName))
2737 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2742 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2746 Handle(AIS_TexturedShape) aTexturedIO;
2747 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2749 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2750 aPreviousMode = aTexturedIO->DisplayMode();
2754 anAISContext->Clear (anIO, Standard_False);
2755 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2756 GetMapOfAIS().UnBind1 (anIO);
2757 GetMapOfAIS().UnBind2 (aShapeName);
2758 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2761 // -------------------------------------------
2762 // Turn texturing on/off - only for vtexture
2763 // -------------------------------------------
2765 if (aCommandName == "vtexture")
2767 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2769 if (aTextureArg.IsEmpty())
2771 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2772 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2774 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2775 if (aPreviousMode == 3)
2777 anAISContext->RecomputePrsOnly (aTexturedIO);
2780 anAISContext->Display (aTexturedIO, Standard_True);
2783 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2785 if (aTextureArg == "?")
2787 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2789 theDi << "\n Files in current directory : \n" << "\n";
2790 theDi.Eval ("glob -nocomplain *");
2792 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2793 aCmnd += aTextureFolder;
2796 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2797 theDi.Eval (aCmnd.ToCString());
2802 aTexturedIO->SetTextureFileName (aTextureArg);
2807 // ------------------------------------
2808 // Process other options and commands
2809 // ------------------------------------
2811 Handle(TColStd_HSequenceOfAsciiString) aValues;
2812 if (aMapOfArgs.Find ("DEFAULT", aValues))
2814 aTexturedIO->SetTextureRepeat (Standard_False);
2815 aTexturedIO->SetTextureOrigin (Standard_False);
2816 aTexturedIO->SetTextureScale (Standard_False);
2817 aTexturedIO->EnableTextureModulate();
2821 if (aMapOfArgs.Find ("SCALE", aValues))
2823 if (aValues->Value(1) != "OFF")
2825 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2829 aTexturedIO->SetTextureScale (Standard_False);
2833 if (aMapOfArgs.Find ("ORIGIN", aValues))
2835 if (aValues->Value(1) != "OFF")
2837 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2841 aTexturedIO->SetTextureOrigin (Standard_False);
2845 if (aMapOfArgs.Find ("REPEAT", aValues))
2847 if (aValues->Value(1) != "OFF")
2849 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2853 aTexturedIO->SetTextureRepeat (Standard_False);
2857 if (aMapOfArgs.Find ("MODULATE", aValues))
2859 if (aValues->Value(1) == "ON")
2861 aTexturedIO->EnableTextureModulate();
2865 aTexturedIO->DisableTextureModulate();
2870 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2872 anAISContext->RecomputePrsOnly (aTexturedIO);
2876 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2877 anAISContext->Display (aTexturedIO, Standard_True);
2878 anAISContext->Update (aTexturedIO,Standard_True);
2884 //==============================================================================
2885 //function : VDisplay2
2887 //purpose : Display an object from its name
2888 //==============================================================================
2889 static int VDisplay2 (Draw_Interpretor& theDI,
2890 Standard_Integer theArgNb,
2891 const char** theArgVec)
2895 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
2899 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2902 ViewerTest::ViewerInit();
2903 aCtx = ViewerTest::GetAISContext();
2906 // Parse input arguments
2907 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2908 Standard_Integer isMutable = -1;
2909 Standard_Boolean toDisplayLocal = Standard_False;
2910 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
2911 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2913 const TCollection_AsciiString aName = theArgVec[anArgIter];
2914 TCollection_AsciiString aNameCase = aName;
2915 aNameCase.LowerCase();
2916 if (anUpdateTool.parseRedrawMode (aName))
2920 else if (aNameCase == "-mutable")
2924 else if (aNameCase == "-local")
2926 toDisplayLocal = Standard_True;
2930 aNamesOfDisplayIO.Append (aName);
2934 if (aNamesOfDisplayIO.IsEmpty())
2936 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
2940 // Prepare context for display
2941 if (toDisplayLocal && !aCtx->HasOpenedContext())
2943 aCtx->OpenLocalContext (Standard_False);
2945 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2947 aCtx->CloseAllContexts (Standard_False);
2950 // Display interactive objects
2951 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
2953 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
2955 if (!GetMapOfAIS().IsBound2 (aName))
2957 // create the AIS_Shape from a name
2958 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2959 if (!aShape.IsNull())
2961 if (isMutable != -1)
2963 aShape->SetMutable (isMutable == 1);
2965 GetMapOfAIS().Bind (aShape, aName);
2966 aCtx->Display (aShape, Standard_False);
2971 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2972 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2974 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2975 if (isMutable != -1)
2977 aShape->SetMutable (isMutable == 1);
2980 if (aShape->Type() == AIS_KOI_Datum)
2982 aCtx->Display (aShape, Standard_False);
2986 theDI << "Display " << aName.ToCString() << "\n";
2987 // get the Shape from a name
2988 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2990 // update the Shape in the AIS_Shape
2991 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2992 if (!aShapePrs.IsNull())
2994 aShapePrs->Set (aNewShape);
2996 aCtx->Redisplay (aShape, Standard_False);
2997 aCtx->Display (aShape, Standard_False);
3000 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
3002 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
3003 TheNISContext()->Display (aShape);
3010 //===============================================================================================
3011 //function : VUpdate
3013 //===============================================================================================
3014 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3016 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3017 if (aContextAIS.IsNull())
3019 std::cout << theArgVec[0] << "AIS context is not available.\n";
3025 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3029 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3031 AIS_ListOfInteractive aListOfIO;
3033 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3035 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3037 Handle(AIS_InteractiveObject) anAISObj;
3038 if (anAISMap.IsBound2 (aName))
3040 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3043 if (anAISObj.IsNull())
3045 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3049 aListOfIO.Append (anAISObj);
3052 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3053 for (; anIOIt.More(); anIOIt.Next())
3055 aContextAIS->Update (anIOIt.Value(), Standard_False);
3058 aContextAIS->UpdateCurrentViewer();
3063 //==============================================================================
3065 //purpose : Test the annimation of an object along a
3066 // predifined trajectory
3067 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3068 //==============================================================================
3070 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3073 if (TheAISContext()->HasOpenedContext())
3074 TheAISContext()->CloseLocalContext();
3076 Standard_Real Step=4*M_PI/180;
3077 Standard_Real Angle=0;
3079 Handle(AIS_InteractiveObject) aIO;
3080 if (GetMapOfAIS().IsBound2(argv[1]))
3081 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3085 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3089 if (Draw::Atoi(argv[3])==1 ) {
3090 di<<" Primitives sensibles OFF"<<"\n";
3091 TheAISContext()->Deactivate(aIO);
3094 di<<" Primitives sensibles ON"<<"\n";
3096 // Movement par transformation
3097 if(Draw::Atoi(argv[2]) ==1) {
3098 di<<" Calcul par Transformation"<<"\n";
3099 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3103 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3104 TheAISContext()->SetLocation(aShape,myTransfo);
3105 TheAISContext() ->UpdateCurrentViewer();
3110 di<<" Calcul par Locations"<<"\n";
3111 gp_Trsf myAngleTrsf;
3112 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3113 TopLoc_Location myDeltaAngle (myAngleTrsf);
3114 TopLoc_Location myTrueLoc;
3116 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3119 myTrueLoc=myTrueLoc*myDeltaAngle;
3120 TheAISContext()->SetLocation(aShape,myTrueLoc );
3121 TheAISContext() ->UpdateCurrentViewer();
3124 if (Draw::Atoi(argv[3])==1 ){
3125 // On reactive la selection des primitives sensibles
3126 TheAISContext()->Activate(aIO,0);
3128 a3DView() -> Redraw();
3130 di<<" Temps ecoule "<<"\n";
3136 //==================================================================================
3137 // Function : VAnimation
3138 //==================================================================================
3139 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3141 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3145 Standard_Real thread = 4;
3146 Standard_Real angleA=0;
3147 Standard_Real angleB;
3149 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3152 TopoDS_Shape CrankArm;
3153 TopoDS_Shape CylinderHead;
3154 TopoDS_Shape Propeller;
3155 TopoDS_Shape EngineBlock;
3157 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3158 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3159 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3160 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3161 BRepTools::Read(CrankArm,argv[1],B);
3162 BRepTools::Read(CylinderHead,argv[2],B);
3163 BRepTools::Read(Propeller,argv[3],B);
3164 BRepTools::Read(EngineBlock,argv[4],B);
3166 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3172 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3173 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3174 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3175 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3177 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3178 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3179 GetMapOfAIS().Bind(myAisCrankArm,"c");
3180 GetMapOfAIS().Bind(myAisPropeller,"d");
3182 myAisCylinderHead->SetMutable (Standard_True);
3183 myAisEngineBlock ->SetMutable (Standard_True);
3184 myAisCrankArm ->SetMutable (Standard_True);
3185 myAisPropeller ->SetMutable (Standard_True);
3187 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3188 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3189 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3191 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3192 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3193 TheAISContext()->Display (myAisCrankArm, Standard_False);
3194 TheAISContext()->Display (myAisPropeller, Standard_False);
3196 TheAISContext()->Deactivate(myAisCylinderHead);
3197 TheAISContext()->Deactivate(myAisEngineBlock );
3198 TheAISContext()->Deactivate(myAisCrankArm );
3199 TheAISContext()->Deactivate(myAisPropeller );
3201 // Boucle de mouvement
3202 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3204 angleA = thread*myAngle*M_PI/180;
3205 X = Sin(angleA)*3/8;
3206 angleB = atan(X / Sqrt(-X * X + 1));
3207 Standard_Real decal(25*0.6);
3210 //Build a transformation on the display
3211 gp_Trsf aPropellerTrsf;
3212 aPropellerTrsf.SetRotation(Ax1,angleA);
3213 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3215 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));
3216 gp_Trsf aCrankArmTrsf;
3217 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3218 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3220 TheAISContext()->UpdateCurrentViewer();
3223 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3224 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3226 myAisCrankArm ->ResetTransformation();
3227 myAisPropeller->ResetTransformation();
3229 myAisCrankArm -> Set(myNewCrankArm );
3230 myAisPropeller -> Set(myNewPropeller);
3232 TheAISContext()->Activate(myAisCylinderHead,0);
3233 TheAISContext()->Activate(myAisEngineBlock,0 );
3234 TheAISContext()->Activate(myAisCrankArm ,0 );
3235 TheAISContext()->Activate(myAisPropeller ,0 );
3241 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3242 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3244 TheAISContext()->UpdateCurrentViewer();
3245 a3DView()->Redraw();
3254 //==============================================================================
3255 //function : VShading
3256 //purpose : Sharpen or roughten the quality of the shading
3257 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3258 //==============================================================================
3259 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3261 Standard_Real myDevCoef;
3262 Handle(AIS_InteractiveObject) TheAisIO;
3265 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3267 if (TheAISContext()->HasOpenedContext())
3268 TheAISContext()->CloseLocalContext();
3273 myDevCoef =Draw::Atof(argv[2]);
3276 TCollection_AsciiString name=argv[1];
3277 if (GetMapOfAIS().IsBound2(name ))
3278 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3279 if (TheAisIO.IsNull())
3280 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3283 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3285 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3287 TheAISContext()->Redisplay(TheAisIO);
3290 //==============================================================================
3291 //function : HaveMode
3292 //use : VActivatedModes
3293 //==============================================================================
3294 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3296 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3298 TColStd_ListOfInteger List;
3299 TheAISContext()->ActivatedModes (TheAisIO,List);
3300 TColStd_ListIteratorOfListOfInteger it;
3301 Standard_Boolean Found=Standard_False;
3302 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3303 if (it.Value()==mode ) Found=Standard_True;
3310 //==============================================================================
3311 //function : VActivatedMode
3313 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3314 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3315 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3316 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3317 // qu'un nom et qu'un mode.
3318 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3319 //==============================================================================
3320 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3322 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3325 Standard_Boolean ThereIsName = Standard_False ;
3327 if(!a3DView().IsNull()){
3329 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3330 // verification des arguments
3332 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3333 ThereIsName = (argc == 3);
3337 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3339 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3340 di<<" Fermeture du Context local"<<"\n";
3341 if (TheAISContext()->HasOpenedContext())
3342 TheAISContext()->CloseLocalContext();
3346 // IL n'y a aps de nom de shape passe en argument
3347 if (HaveToSet && !ThereIsName){
3348 Standard_Integer aMode=Draw::Atoi(argv [1]);
3350 const char *cmode="???";
3352 case 0: cmode = "Shape"; break;
3353 case 1: cmode = "Vertex"; break;
3354 case 2: cmode = "Edge"; break;
3355 case 3: cmode = "Wire"; break;
3356 case 4: cmode = "Face"; break;
3357 case 5: cmode = "Shell"; break;
3358 case 6: cmode = "Solid"; break;
3359 case 7: cmode = "Compound"; break;
3362 if( !TheAISContext()->HasOpenedContext() ) {
3363 // il n'y a pas de Context local d'ouvert
3364 // on en ouvre un et on charge toutes les shapes displayees
3365 // on load tous les objets displayees et on Activate les objets de la liste
3366 AIS_ListOfInteractive ListOfIO;
3367 // on sauve dans une AISListOfInteractive tous les objets currents
3368 if (TheAISContext()->NbCurrents()>0 ){
3369 TheAISContext()->UnhilightCurrents(Standard_False);
3371 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3372 ListOfIO.Append(TheAISContext()->Current() );
3376 TheAISContext()->OpenLocalContext(Standard_False);
3377 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3380 Handle(AIS_InteractiveObject) aIO =
3381 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3383 TheAISContext()->Load(aIO,0,Standard_False);
3386 // traitement des objets qui etaient currents dans le Contexte global
3387 if (!ListOfIO.IsEmpty() ) {
3388 // il y avait des objets currents
3389 AIS_ListIteratorOfListOfInteractive iter;
3390 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3391 Handle(AIS_InteractiveObject) aIO=iter.Value();
3392 TheAISContext()->Activate(aIO,aMode);
3393 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3397 // On applique le mode a tous les objets displayes
3398 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3399 it2 (GetMapOfAIS());
3401 Handle(AIS_InteractiveObject) aIO =
3402 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3403 if (!aIO.IsNull()) {
3404 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3405 TheAISContext()->Activate(aIO,aMode);
3414 // un Context local est deja ouvert
3415 // Traitement des objets du Context local
3416 if (TheAISContext()->NbSelected()>0 ){
3417 TheAISContext()->UnhilightSelected(Standard_False);
3418 // il y a des objets selected,on les parcourt
3419 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3420 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3423 if (HaveMode(aIO,aMode) ) {
3424 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3425 TheAISContext()->Deactivate(aIO,aMode);
3428 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3429 TheAISContext()->Activate(aIO,aMode);
3435 // il n'y a pas d'objets selected
3436 // tous les objets diplayes sont traites
3437 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3440 Handle(AIS_InteractiveObject) aIO =
3441 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3442 if (!aIO.IsNull()) {
3443 if (HaveMode(aIO,aMode) ) {
3444 di<<" Mode: "<<cmode<<" OFF pour "
3445 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3446 TheAISContext()->Deactivate(aIO,aMode);
3449 di<<" Mode: "<<cmode<<" ON pour"
3450 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3451 TheAISContext()->Activate(aIO,aMode);
3459 else if (HaveToSet && ThereIsName){
3460 Standard_Integer aMode=Draw::Atoi(argv [2]);
3461 Handle(AIS_InteractiveObject) aIO =
3462 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3464 if (!aIO.IsNull()) {
3465 const char *cmode="???";
3468 case 0: cmode = "Shape"; break;
3469 case 1: cmode = "Vertex"; break;
3470 case 2: cmode = "Edge"; break;
3471 case 3: cmode = "Wire"; break;
3472 case 4: cmode = "Face"; break;
3473 case 5: cmode = "Shell"; break;
3474 case 6: cmode = "Solid"; break;
3475 case 7: cmode = "Compound"; break;
3478 if( !TheAISContext()->HasOpenedContext() ) {
3479 TheAISContext()->OpenLocalContext(Standard_False);
3480 // On charge tous les objets de la map
3481 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3483 Handle(AIS_InteractiveObject) aShape=
3484 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3485 if (!aShape.IsNull())
3486 TheAISContext()->Load(aShape,0,Standard_False);
3489 TheAISContext()->Activate(aIO,aMode);
3490 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3494 // un Context local est deja ouvert
3495 if (HaveMode(aIO,aMode) ) {
3496 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3497 TheAISContext()->Deactivate(aIO,aMode);
3500 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3501 TheAISContext()->Activate(aIO,aMode);
3510 //! Auxiliary method to print Interactive Object information
3511 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3512 const Handle(Standard_Transient)& theObject,
3513 Draw_Interpretor& theDI)
3515 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3518 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3522 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3523 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3524 << (theDetected.Contains (anObj) ? " Detected" : " ")
3526 if (anObj->Type() == AIS_KOI_Datum)
3529 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3530 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3531 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3532 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3533 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3534 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3535 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3538 else if (anObj->Type() == AIS_KOI_Shape
3539 && anObj->Signature() == 0)
3541 theDI << " AIS_Shape";
3543 else if (anObj->Type() == AIS_KOI_Relation)
3545 // AIS_Dimention and AIS_Relation
3546 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3547 switch (aRelation->KindOfDimension())
3549 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3550 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3551 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3552 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3553 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3554 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3555 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3556 default: theDI << " UNKNOWN dimension"; break;
3561 theDI << " UserPrs";
3563 theDI << " (" << theObject->DynamicType()->Name() << ")";
3566 //! Print information about locally selected sub-shapes
3567 static void localCtxInfo (Draw_Interpretor& theDI)
3569 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3570 if (!aCtx->HasOpenedContext())
3575 TCollection_AsciiString aPrevName;
3576 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3577 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3579 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3580 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3581 if (aSubShape.IsNull()
3582 || aShapeIO.IsNull()
3583 || !GetMapOfAIS().IsBound1 (aShapeIO))
3588 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3589 TopTools_MapOfShape aFilter;
3590 Standard_Integer aNumber = 0;
3591 const TopoDS_Shape aShape = aShapeIO->Shape();
3592 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3593 anIter.More(); anIter.Next())
3595 if (!aFilter.Add (anIter.Current()))
3597 continue; // filter duplicates
3601 if (!anIter.Current().IsSame (aSubShape))
3606 Standard_CString aShapeName = NULL;
3607 switch (aSubShape.ShapeType())
3609 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3610 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3611 case TopAbs_SOLID: aShapeName = " Solid"; break;
3612 case TopAbs_SHELL: aShapeName = " Shell"; break;
3613 case TopAbs_FACE: aShapeName = " Face"; break;
3614 case TopAbs_WIRE: aShapeName = " Wire"; break;
3615 case TopAbs_EDGE: aShapeName = " Edge"; break;
3616 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3618 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3621 if (aParentName != aPrevName)
3623 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3624 aPrevName = aParentName;
3626 theDI << " " << aShapeName << " #" << aNumber << "\n";
3632 //==============================================================================
3635 //==============================================================================
3636 static Standard_Integer VState (Draw_Interpretor& theDI,
3637 Standard_Integer theArgNb,
3638 Standard_CString* theArgVec)
3640 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3643 std::cerr << "Error: No opened viewer!\n";
3647 TCollection_AsciiString anOption (theArgNb >= 2 ? theArgVec[1] : "");
3648 anOption.LowerCase();
3649 if (anOption == "-detectedEntities"
3650 || anOption == "-entities")
3652 theDI << "Detected entities:\n";
3653 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
3654 for (aSelector->Init(); aSelector->More(); aSelector->Next())
3656 Handle(SelectBasics_SensitiveEntity) anEntity = aSelector->Primitive (0);
3657 Standard_Real aMatchDMin = 0.0;
3658 Standard_Real aMatchDepth = Precision::Infinite();
3659 anEntity->Matches (aSelector->LastPickingArguments(), aMatchDMin, aMatchDepth);
3661 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3662 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3664 const gp_Lin aLine = aSelector->LastPickingArguments().PickLine();
3665 const gp_Pnt aPnt = aLine.Location().Translated (gp_Vec (aLine.Direction()) * aMatchDepth);
3667 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3668 aName.LeftJustify (20, ' ');
3669 char anInfoStr[512];
3670 Sprintf (anInfoStr, " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f", aMatchDepth, aMatchDMin, aPnt.X(), aPnt.Y(), aPnt.Z());
3671 theDI << " " << aName
3673 << " (" << anEntity->DynamicType()->Name() << ")"
3676 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
3677 if (!aBRepOwner.IsNull())
3679 theDI << " Detected Shape: "
3680 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
3684 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
3685 if (!aWire.IsNull())
3687 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
3688 theDI << " Detected Child: "
3689 << aSen->DynamicType()->Name()
3696 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3697 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3699 aDetected.Add (aCtx->DetectedCurrentObject());
3702 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3706 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3708 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3709 if (!GetMapOfAIS().IsBound2 (anObjName))
3711 theDI << anObjName << " doesn't exist!\n";
3715 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3716 TCollection_AsciiString aName = anObjName;
3717 aName.LeftJustify (20, ' ');
3718 theDI << " " << aName << " ";
3719 objInfo (aDetected, anObjTrans, theDI);
3725 if (aCtx->NbCurrents() > 0
3728 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3730 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3731 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3732 aName.LeftJustify (20, ' ');
3733 theDI << aName << " ";
3734 objInfo (aDetected, anObj, theDI);
3740 theDI << "Neutral-point state:\n";
3741 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3742 anObjIter.More(); anObjIter.Next())
3744 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3750 TCollection_AsciiString aName = anObjIter.Key2();
3751 aName.LeftJustify (20, ' ');
3752 theDI << " " << aName << " ";
3753 objInfo (aDetected, anObj, theDI);
3756 localCtxInfo (theDI);
3760 //=======================================================================
3761 //function : PickObjects
3763 //=======================================================================
3764 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3765 const AIS_KindOfInteractive TheType,
3766 const Standard_Integer TheSignature,
3767 const Standard_Integer MaxPick)
3769 Handle(AIS_InteractiveObject) IO;
3770 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3772 // step 1: prepare the data
3774 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3775 TheAISContext()->AddFilter(F1);
3778 // step 2 : wait for the selection...
3779 // Standard_Boolean IsGood (Standard_False);
3780 // Standard_Integer NbPick(0);
3781 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3782 Standard_Integer NbPickFail(0);
3783 Standard_Integer argccc = 5;
3784 const char *bufff[] = { "A", "B", "C","D", "E" };
3785 const char **argvvv = (const char **) bufff;
3788 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3789 while(ViewerMainLoop(argccc,argvvv)){}
3790 Standard_Integer NbStored = TheAISContext()->NbSelected();
3791 if((unsigned int ) NbStored != NbPickGood)
3792 NbPickGood= NbStored;
3795 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3798 // step3 get result.
3800 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3802 Standard_Integer i(0);
3803 for(TheAISContext()->InitSelected();
3804 TheAISContext()->MoreSelected();
3805 TheAISContext()->NextSelected()){
3807 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3808 arr->SetValue(i,IO2);
3813 TheAISContext()->CloseLocalContext(curindex);
3815 return Standard_True;
3819 //=======================================================================
3820 //function : PickObject
3822 //=======================================================================
3823 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3824 const Standard_Integer TheSignature,
3825 const Standard_Integer MaxPick)
3827 Handle(AIS_InteractiveObject) IO;
3828 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3830 // step 1: prepare the data
3833 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3834 TheAISContext()->AddFilter(F1);
3837 // step 2 : wait for the selection...
3838 Standard_Boolean IsGood (Standard_False);
3839 Standard_Integer NbPick(0);
3840 Standard_Integer argccc = 5;
3841 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3842 const char **argvvv = (const char **) bufff;
3845 while(!IsGood && NbPick<= MaxPick){
3846 while(ViewerMainLoop(argccc,argvvv)){}
3847 IsGood = (TheAISContext()->NbSelected()>0) ;
3849 cout<<"Nb Pick :"<<NbPick<<endl;
3853 // step3 get result.
3855 TheAISContext()->InitSelected();
3856 IO = TheAISContext()->SelectedInteractive();
3860 TheAISContext()->CloseLocalContext(curindex);
3864 //=======================================================================
3865 //function : PickShape
3866 //purpose : First Activate the rightmode + Put Filters to be able to
3867 // pick objets that are of type <TheType>...
3868 //=======================================================================
3870 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3871 const Standard_Integer MaxPick)
3874 // step 1: prepare the data
3876 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3877 TopoDS_Shape result;
3879 if(TheType==TopAbs_SHAPE){
3880 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3881 TheAISContext()->AddFilter(F1);
3884 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3885 TheAISContext()->AddFilter(TF);
3886 TheAISContext()->ActivateStandardMode(TheType);
3891 // step 2 : wait for the selection...
3892 Standard_Boolean NoShape (Standard_True);
3893 Standard_Integer NbPick(0);
3894 Standard_Integer argccc = 5;
3895 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3896 const char **argvvv = (const char **) bufff;
3899 while(NoShape && NbPick<= MaxPick){
3900 while(ViewerMainLoop(argccc,argvvv)){}
3901 NoShape = (TheAISContext()->NbSelected()==0) ;
3903 cout<<"Nb Pick :"<<NbPick<<endl;
3906 // step3 get result.
3910 TheAISContext()->InitSelected();
3911 if(TheAISContext()->HasSelectedShape())
3912 result = TheAISContext()->SelectedShape();
3914 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3915 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3920 TheAISContext()->CloseLocalContext(curindex);
3926 //=======================================================================
3927 //function : PickShapes
3929 //=======================================================================
3930 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3931 Handle(TopTools_HArray1OfShape)& thearr,
3932 const Standard_Integer MaxPick)
3935 Standard_Integer Taille = thearr->Length();
3937 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3939 // step 1: prepare the data
3940 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3941 if(TheType==TopAbs_SHAPE){
3942 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3943 TheAISContext()->AddFilter(F1);
3946 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3947 TheAISContext()->AddFilter(TF);
3948 TheAISContext()->ActivateStandardMode(TheType);
3952 // step 2 : wait for the selection...
3954 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3955 Standard_Integer NbPickFail(0);
3956 Standard_Integer argccc = 5;
3957 const char *bufff[] = { "A", "B", "C","D", "E" };
3958 const char **argvvv = (const char **) bufff;
3961 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3962 while(ViewerMainLoop(argccc,argvvv)){}
3963 Standard_Integer NbStored = TheAISContext()->NbSelected();
3964 if((unsigned int ) NbStored != NbPickGood)
3965 NbPickGood= NbStored;
3968 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3971 // step3 get result.
3973 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3975 Standard_Integer i(0);
3976 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3978 if(TheAISContext()->HasSelectedShape())
3979 thearr->SetValue(i,TheAISContext()->SelectedShape());
3981 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3982 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3986 TheAISContext()->CloseLocalContext(curindex);
3987 return Standard_True;
3991 //=======================================================================
3992 //function : VPickShape
3994 //=======================================================================
3995 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3997 TopoDS_Shape PickSh;
3998 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4001 theType = TopAbs_SHAPE;
4003 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4004 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4005 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4006 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4007 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4008 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4009 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4012 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4013 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4015 TCollection_AsciiString name;
4018 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4020 PickSh = ViewerTest::PickShape(theType);
4029 if(!PickSh.IsNull()){
4030 nbOfSub[Standard_Integer(theType)]++;
4032 name += nameType[Standard_Integer(theType)];
4033 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4038 // si on avait une petite methode pour voir si la shape
4039 // est deja dans la Double map, ca eviterait de creer....
4040 DBRep::Set(name.ToCString(),PickSh);
4042 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4043 GetMapOfAIS().Bind(newsh, name);
4044 TheAISContext()->Display(newsh);
4045 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4048 // Plusieurs objets a picker, vite vite vite....
4051 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4052 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4053 if(ViewerTest::PickShapes(theType,arr)){
4054 for(Standard_Integer i=1;i<=NbToPick;i++){
4055 PickSh = arr->Value(i);
4056 if(!PickSh.IsNull()){
4058 nbOfSub[Standard_Integer(theType)]++;
4061 name += nameType[Standard_Integer(theType)];
4062 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4070 DBRep::Set(name.ToCString(),PickSh);
4071 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4072 GetMapOfAIS().Bind(newsh, name);
4073 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4074 TheAISContext()->Display(newsh);
4082 //=======================================================================
4083 //function : VPickSelected
4085 //=======================================================================
4086 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4088 static Standard_Integer aCount = 0;
4089 TCollection_AsciiString aName = "PickedShape_";
4097 aName = aName + aCount++ + "_";
4100 Standard_Integer anIdx = 0;
4101 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4103 TopoDS_Shape aShape;
4104 if (TheAISContext()->HasSelectedShape())
4106 aShape = TheAISContext()->SelectedShape();
4110 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4111 aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
4114 TCollection_AsciiString aCurrentName = aName;
4117 aCurrentName += anIdx;
4120 DBRep::Set ((aCurrentName).ToCString(), aShape);
4122 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4123 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4124 TheAISContext()->Display (aNewShape);
4130 //=======================================================================
4131 //function : list of known objects
4133 //=======================================================================
4134 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4136 // 1234567890 12345678901234567 123456789
4137 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4138 TCollection_AsciiString BlankLine(64,'_');
4139 Standard_Integer i ;
4141 di<<"/n"<<BlankLine.ToCString()<<"\n";
4144 Colum[i].Center(20,' ');
4146 di<<"|"<<Colum[i].ToCString();
4149 di<<BlankLine.ToCString()<<"\n";
4151 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4152 const char ** names = GetTypeNames();
4154 TCollection_AsciiString curstring;
4155 TCollection_AsciiString curcolum[3];
4158 // les objets de type Datum..
4159 curcolum[1]+="Datum";
4161 curcolum[0].Clear();
4162 curcolum[0] += names[i];
4164 curcolum[2].Clear();
4165 curcolum[2]+=TCollection_AsciiString(i+1);
4167 for(Standard_Integer j =0;j<=2;j++){
4168 curcolum[j].Center(20,' ');
4169 di<<"|"<<curcolum[j].ToCString();
4173 di<<BlankLine.ToCString()<<"\n";
4175 // les objets de type shape
4176 curcolum[1].Clear();
4177 curcolum[1]+="Shape";
4178 curcolum[1].Center(20,' ');
4181 curcolum[0].Clear();
4182 curcolum[0] += names[7+i];
4183 curcolum[2].Clear();
4184 curcolum[2]+=TCollection_AsciiString(i);
4186 for(Standard_Integer j =0;j<=2;j++){
4187 curcolum[j].Center(20,' ');
4188 di<<"|"<<curcolum[j].ToCString();
4192 di<<BlankLine.ToCString()<<"\n";
4193 // les IO de type objet...
4194 curcolum[1].Clear();
4195 curcolum[1]+="Object";
4196 curcolum[1].Center(20,' ');
4198 curcolum[0].Clear();
4199 curcolum[0] += names[10+i];
4200 curcolum[2].Clear();
4201 curcolum[2]+=TCollection_AsciiString(i);
4203 for(Standard_Integer j =0;j<=2;j++){
4204 curcolum[j].Center(20,' ');
4205 di<<"|"<<curcolum[j].ToCString();
4209 di<<BlankLine.ToCString()<<"\n";
4210 // les contraintes et dimensions.
4211 // pour l'instant on separe juste contraintes et dimensions...
4212 // plus tard, on detaillera toutes les sortes...
4213 curcolum[1].Clear();
4214 curcolum[1]+="Relation";
4215 curcolum[1].Center(20,' ');
4217 curcolum[0].Clear();
4218 curcolum[0] += names[12+i];
4219 curcolum[2].Clear();
4220 curcolum[2]+=TCollection_AsciiString(i);
4222 for(Standard_Integer j =0;j<=2;j++){
4223 curcolum[j].Center(20,' ');
4224 di<<"|"<<curcolum[j].ToCString();
4228 di<<BlankLine.ToCString()<<"\n";
4235 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4237 if(argc!=2) return 1;
4239 AIS_KindOfInteractive TheType;
4240 Standard_Integer TheSign(-1);
4241 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4244 AIS_ListOfInteractive LIO;
4246 // en attendant l'amelioration ais pour les dimensions...
4248 Standard_Integer dimension_status(-1);
4249 if(TheType==AIS_KOI_Relation){
4250 dimension_status = TheSign ==1 ? 1 : 0;
4254 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4255 Handle(AIS_InteractiveObject) curio;
4256 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4259 if(dimension_status == -1)
4260 TheAISContext()->Erase(curio,Standard_False);
4262 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4263 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4264 (dimension_status==1 && KOD != AIS_KOD_NONE))
4265 TheAISContext()->Erase(curio,Standard_False);
4268 TheAISContext()->UpdateCurrentViewer();
4271 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4273 if(argc!=2) return 1;
4275 AIS_KindOfInteractive TheType;
4276 Standard_Integer TheSign(-1);
4277 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4279 // en attendant l'amelioration ais pour les dimensions...
4281 Standard_Integer dimension_status(-1);
4282 if(TheType==AIS_KOI_Relation){
4283 dimension_status = TheSign ==1 ? 1 : 0;
4287 AIS_ListOfInteractive LIO;
4288 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4289 Handle(AIS_InteractiveObject) curio;
4290 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4292 if(dimension_status == -1)
4293 TheAISContext()->Display(curio,Standard_False);
4295 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4296 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4297 (dimension_status==1 && KOD != AIS_KOD_NONE))
4298 TheAISContext()->Display(curio,Standard_False);
4303 TheAISContext()->UpdateCurrentViewer();
4307 //==============================================================================
4308 //function : VSetTransMode
4310 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4311 //==============================================================================
4313 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4314 // Verification des arguments
4315 if ( a3DView().IsNull() ) {
4316 ViewerTest::ViewerInit();
4317 di << "La commande vinit n'a pas ete appele avant" << "\n";
4320 if ( argc < 3 || argc > 8 ) {
4321 di << argv[0] << " Invalid number of arguments" << "\n";
4325 TCollection_AsciiString shapeName;
4326 shapeName = argv[1];
4327 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4328 Standard_Integer persFlag2 = 0;
4329 Standard_Integer persFlag3 = 0;
4330 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4331 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4332 persFlag2 = Draw::Atoi(argv[3]);
4334 if ( argc == 5 || argc == 8 ) {
4335 persFlag3 = Draw::Atoi(argv[4]);
4338 origin.SetX( Draw::Atof(argv[argc - 3]) );
4339 origin.SetY( Draw::Atof(argv[argc - 2]) );
4340 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4343 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4344 Handle(Standard_Transient) anObj;
4346 anObj = GetMapOfAIS().Find2(shapeName);
4347 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4348 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4349 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4350 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4351 di << argv[0] << " All persistence modifiers were removed" << "\n";
4354 di << argv[0] << " Wrong object type" << "\n";
4357 } else { // Create the AIS_Shape from a name
4358 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4359 if ( !aShape.IsNull() ) {
4360 GetMapOfAIS().Bind( aShape, shapeName );
4361 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4362 TheAISContext()->Display( aShape, Standard_False );
4364 di << argv[0] << " Object not found" << "\n";
4369 // Upadate the screen and redraw the view
4370 TheAISContext()->UpdateCurrentViewer();
4374 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4377 BRep_Builder builder;
4379 BRepTools::Read(shape, s, builder);
4380 DBRep::Set(a[1], shape);
4381 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4382 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4387 //==============================================================================
4388 //function : ViewerTest::Commands
4389 //purpose : Add all the viewer command in the Draw_Interpretor
4390 //==============================================================================
4392 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4394 ViewerTest::ViewerCommands(theCommands);
4395 ViewerTest::RelationCommands(theCommands);
4396 ViewerTest::ObjectCommands(theCommands);
4397 ViewerTest::FilletCommands(theCommands);
4398 ViewerTest::VoxelCommands(theCommands);
4399 ViewerTest::OpenGlCommands(theCommands);
4401 const char *group = "AIS_Display";
4404 theCommands.Add("visos",
4405 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4406 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4407 __FILE__, visos, group);
4409 theCommands.Add("vdisplay",
4410 "vdisplay [-noupdate|-update] [-local] [-mutable] name1 [name2] ... [name n]"
4411 "\n\t\t: Displays named objects."
4412 "\n\t\t: Option -local enables displaying of objects in local"
4413 "\n\t\t: selection context. Local selection context will be opened"
4414 "\n\t\t: if there is not any."
4415 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4416 "\n\t\t: Option -mutable enables optimizations for mutable objects.",
4417 __FILE__, VDisplay2, group);
4419 theCommands.Add ("vupdate",
4420 "vupdate name1 [name2] ... [name n]"
4421 "\n\t\t: Updates named objects in interactive context",
4422 __FILE__, VUpdate, group);
4424 theCommands.Add("verase",
4425 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
4426 "\n\t\t: Erases selected or named objects."
4427 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
4428 "\n\t\t: Option -local enables erasing of selected or named objects without"
4429 "\n\t\t: closing local selection context.",
4430 __FILE__, VErase, group);
4432 theCommands.Add("vremove",
4433 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4434 "or vremove [-context] -all to remove all objects"
4435 "\n\t\t: Removes selected or named objects."
4436 "\n\t\t If -context is in arguments, the objects are not deleted"
4437 "\n\t\t from the map of objects and names."
4438 "\n\t\t: Option -local enables removing of selected or named objects without"
4439 "\n\t\t: closing local selection context. Empty local selection context will be"
4441 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4442 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4443 __FILE__, VRemove, group);
4445 theCommands.Add("vdonly",
4446 "vdonly [-noupdate|-update] [name1] ... [name n]"
4447 "\n\t\t: Displays only selected or named objects",
4448 __FILE__,VDonly2,group);
4450 theCommands.Add("vdisplayall",
4451 "vidsplayall [-local]"
4452 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
4453 "\n\t\t: Option -local enables displaying of the objects in local"
4454 "\n\t\t: selection context.",
4455 __FILE__, VDisplayAll, group);
4457 theCommands.Add("veraseall",
4458 "veraseall [-local]"
4459 "\n\t\t: Erases all objects displayed in the viewer."
4460 "\n\t\t: Option -local enables erasing of the objects in local"
4461 "\n\t\t: selection context.",
4462 __FILE__, VErase, group);
4464 theCommands.Add("verasetype",
4466 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4467 __FILE__, VEraseType, group);
4468 theCommands.Add("vbounding",
4469 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4470 "\n\t\t: [-print] [-hide]"
4471 "\n\t\t: Temporarily display bounding box of specified Interactive"
4472 "\n\t\t: Objects, or print it to console if -print is specified."
4473 "\n\t\t: Already displayed box might be hidden by -hide option.",
4474 __FILE__,VBounding,group);
4476 theCommands.Add("vdisplaytype",
4477 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4478 __FILE__,VDisplayType,group);
4480 theCommands.Add("vdisplaymode",
4481 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4482 __FILE__,VDispMode,group);
4484 theCommands.Add("verasemode",
4485 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4486 __FILE__,VDispMode,group);
4488 theCommands.Add("vsetdispmode",
4489 "vsetdispmode [name] mode(1,2,..)"
4490 "\n\t\t: Sets display mode for all, selected or named objects.",
4491 __FILE__,VDispMode,group);
4493 theCommands.Add("vunsetdispmode",
4494 "vunsetdispmode [name]"
4495 "\n\t\t: Unsets custom display mode for selected or named objects.",
4496 __FILE__,VDispMode,group);
4498 theCommands.Add("vdir",
4499 "Lists all objects displayed in 3D viewer",
4500 __FILE__,VDir,group);
4502 theCommands.Add("vdump",
4503 #ifdef HAVE_FREEIMAGE
4504 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4505 "\n\t\t: [width Width=0 height Height=0]"
4506 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4508 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4509 "\n\t\t: [width Width=0 height Height=0]"
4510 "\n\t\t: Dumps content of the active view into PPM image file",
4512 __FILE__,VDump,group);
4514 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4515 __FILE__,VSubInt,group);
4517 theCommands.Add("vaspects",
4518 "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4519 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
4520 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4521 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4522 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4523 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4524 "\n\t\t: Manage presentation properties of all, selected or named objects."
4525 "\n\t\t: When -subshapes is specified than following properties will be"
4526 "\n\t\t: assigned to specified sub-shapes.",
4527 __FILE__,VAspects,group);
4529 theCommands.Add("vsetcolor",
4530 "vsetcolor [-noupdate|-update] [name] ColorName"
4531 "\n\t\t: Sets color for all, selected or named objects."
4532 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4533 __FILE__,VAspects,group);
4535 theCommands.Add("vunsetcolor",
4536 "vunsetcolor [-noupdate|-update] [name]"
4537 "\n\t\t: Resets color for all, selected or named objects."
4538 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4539 __FILE__,VAspects,group);
4541 theCommands.Add("vsettransparency",
4542 "vsettransparency [-noupdate|-update] [name] Coefficient"
4543 "\n\t\t: Sets transparency for all, selected or named objects."
4544 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4545 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4546 __FILE__,VAspects,group);
4548 theCommands.Add("vunsettransparency",
4549 "vunsettransparency [-noupdate|-update] [name]"
4550 "\n\t\t: Resets transparency for all, selected or named objects."
4551 "\n\t\t: Alias for vaspects -unsettransp [name].",
4552 __FILE__,VAspects,group);
4554 theCommands.Add("vsetmaterial",
4555 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4556 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4557 __FILE__,VAspects,group);
4559 theCommands.Add("vunsetmaterial",
4560 "vunsetmaterial [-noupdate|-update] [name]"
4561 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4562 __FILE__,VAspects,group);
4564 theCommands.Add("vsetwidth",
4565 "vsetwidth [-noupdate|-update] [name] width(0->10)"
4566 "\n\t\t: Alias for vaspects -setwidth [name] width.",
4567 __FILE__,VAspects,group);
4569 theCommands.Add("vunsetwidth",
4570 "vunsetwidth [-noupdate|-update] [name]"
4571 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4572 __FILE__,VAspects,group);
4574 theCommands.Add("vsetinteriorstyle",
4575 "vsetinteriorstyle [-noupdate|-update] [name] style"
4576 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4577 __FILE__,VSetInteriorStyle,group);
4579 theCommands.Add("vardis",
4580 "vardis : display activeareas",
4581 __FILE__,VDispAreas,group);
4583 theCommands.Add("varera",
4584 "varera : erase activeareas",
4585 __FILE__,VClearAreas,group);
4587 theCommands.Add("vsensdis",
4588 "vardisp : display active entities",
4589 __FILE__,VDispSensi,group);
4590 theCommands.Add("vsensera",
4591 "vardisp : erase active entities",
4592 __FILE__,VClearSensi,group);
4594 theCommands.Add("vselprecision",
4595 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4596 __FILE__,VSelPrecision,group);
4598 theCommands.Add("vperf",
4599 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4600 __FILE__,VPerf,group);
4602 theCommands.Add("vanimation",
4603 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4604 __FILE__,VAnimation,group);
4606 theCommands.Add("vsetshading",
4607 "vsetshading : vsetshading name Quality(default=0.0008) ",
4608 __FILE__,VShading,group);
4610 theCommands.Add("vunsetshading",
4611 "vunsetshading :vunsetshading name ",
4612 __FILE__,VShading,group);
4614 theCommands.Add ("vtexture",
4615 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4616 " [-scale u v] [-scale off]\n"
4617 " [-origin u v] [-origin off]\n"
4618 " [-repeat u v] [-repeat off]\n"
4619 " [-modulate {on | off}]"
4621 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4622 " specifying one of the predefined textures.\n"
4623 " The options are: \n"
4624 " -scale u v : enable texture scaling and set scale factors\n"
4625 " -scale off : disable texture scaling\n"
4626 " -origin u v : enable texture origin positioning and set the origin\n"
4627 " -origin off : disable texture origin positioning\n"
4628 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4629 " -repeat off : disable texture repeat\n"
4630 " -modulate {on | off} : enable or disable texture modulation\n"
4631 " -default : sets texture mapping default parameters\n"
4632 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4633 "or 'vtexture NameOfShape ?' to list available textures\n",
4634 __FILE__, VTexture, group);
4636 theCommands.Add("vtexscale",
4637 "'vtexscale NameOfShape ScaleU ScaleV' \n \
4638 or 'vtexscale NameOfShape ScaleUV' \n \
4639 or 'vtexscale NameOfShape' to disable scaling\n ",
4640 __FILE__,VTexture,group);
4642 theCommands.Add("vtexorigin",
4643 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4644 or 'vtexorigin NameOfShape UVOrigin' \n \
4645 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4646 __FILE__,VTexture,group);
4648 theCommands.Add("vtexrepeat",
4649 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
4650 or 'vtexrepeat NameOfShape UVRepeat \n \
4651 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4654 theCommands.Add("vtexdefault",
4655 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4658 theCommands.Add("vsetam",
4659 "vsetActivatedModes: vsetam mode(1->7) ",
4660 __FILE__,VActivatedMode,group);
4662 theCommands.Add("vunsetam",
4663 "vunsetActivatedModes: vunsetam ",
4664 __FILE__,VActivatedMode,group);
4666 theCommands.Add("vstate",
4667 "vstate [-entities] [name1] ... [nameN]"
4668 "\n\t\t: Reports show/hidden state for selected or named objects"
4669 "\n\t\t: -entities - print low-level information about detected entities",
4670 __FILE__,VState,group);
4672 theCommands.Add("vpickshapes",
4673 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4674 __FILE__,VPickShape,group);
4676 theCommands.Add("vtypes",
4677 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4680 theCommands.Add("vsettransmode",
4681 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4682 __FILE__,VSetTransMode,group);
4684 theCommands.Add("vr", "vr : reading of the shape",
4685 __FILE__,vr, group);
4687 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
4688 __FILE__, VPickSelected, group);
4692 //=====================================================================
4693 //========================= for testing Draft and Rib =================
4694 //=====================================================================
4695 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4696 #include <DBRep.hxx>
4697 #include <TopoDS_Face.hxx>
4698 #include <gp_Pln.hxx>
4699 #include <AIS_KindOfSurface.hxx>
4700 #include <BRepOffsetAPI_DraftAngle.hxx>
4701 #include <Precision.hxx>
4702 #include <BRepAlgo.hxx>
4703 #include <OSD_Environment.hxx>
4704 #include <DrawTrSurf.hxx>
4705 //#include <DbgTools.hxx>
4706 //#include <FeatAlgo_MakeLinearForm.hxx>
4711 //=======================================================================
4712 //function : IsValid
4714 //=======================================================================
4715 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4716 const TopoDS_Shape& theResult,
4717 const Standard_Boolean closedSolid,
4718 const Standard_Boolean GeomCtrl)
4720 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4721 TCollection_AsciiString checkValid = check.Value();
4722 Standard_Boolean ToCheck = Standard_True;
4723 if (!checkValid.IsEmpty()) {
4724 #ifdef VIEWERTEST_DEB
4725 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4727 if ( checkValid=="true" || checkValid=="TRUE" ) {
4728 ToCheck= Standard_False;
4731 #ifdef VIEWERTEST_DEB
4732 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4735 Standard_Boolean IsValid = Standard_True;
4737 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4742 //===============================================================================
4743 // TDraft : test draft, uses AIS Viewer
4744 // Solid Face Plane Angle Reverse
4745 //===============================================================================
4746 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4748 if (argc < 5) return 1;
4749 // argv[1] - TopoDS_Shape Solid
4750 // argv[2] - TopoDS_Shape Face
4751 // argv[3] - TopoDS_Shape Plane
4752 // argv[4] - Standard_Real Angle
4753 // argv[5] - Standard_Integer Reverse
4755 // Sprintf(prefix, argv[1]);
4756 Standard_Real anAngle = 0;
4757 Standard_Boolean Rev = Standard_False;
4758 Standard_Integer rev = 0;
4759 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4760 TopoDS_Shape face = GetShapeFromName(argv[2]);
4761 TopoDS_Face Face = TopoDS::Face(face);
4762 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4763 if (Plane.IsNull ()) {
4764 di << "TEST : Plane is NULL" << "\n";
4767 anAngle = Draw::Atof(argv[4]);
4768 anAngle = 2*M_PI * anAngle / 360.0;
4770 Handle( Geom_Surface )aSurf;
4771 AIS_KindOfSurface aSurfType;
4772 Standard_Real Offset;
4774 if(argc > 4) { // == 5
4775 rev = Draw::Atoi(argv[5]);
4776 Rev = (rev)? Standard_True : Standard_False;
4779 TopoDS_Face face2 = TopoDS::Face(Plane);
4780 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4782 di << "TEST : Can't find plane" << "\n";
4786 aDir = aPln.Axis().Direction();
4789 if (Plane.Orientation() == TopAbs_REVERSED)
4791 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4793 BRepOffsetAPI_DraftAngle Draft (Solid);
4795 if(Abs(anAngle)< Precision::Angular()) {
4796 di << "TEST : NULL angle" << "\n";
4799 if(Rev) anAngle = - anAngle;
4800 Draft.Add (Face, aDir, anAngle, aPln);
4802 if (!Draft.IsDone()) {
4803 di << "TEST : Draft Not DONE " << "\n";
4806 TopTools_ListOfShape Larg;
4808 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4809 di << "TEST : DesignAlgo returns Not valid" << "\n";
4813 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4814 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4816 if ( !ais.IsNull() ) {
4817 ais->SetColor(DEFAULT_COLOR);
4818 ais->SetMaterial(DEFAULT_MATERIAL);
4819 // Display the AIS_Shape without redraw
4820 Ctx->Display(ais, Standard_False);
4822 const char *Name = "draft1";
4823 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4825 Handle(AIS_InteractiveObject) an_object =
4826 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4827 if (!an_object.IsNull()) {
4828 Ctx->Remove(an_object,
4830 GetMapOfAIS().UnBind2(Name) ;
4833 GetMapOfAIS().Bind(ais, Name);
4834 // DBRep::Set("draft", ais->Shape());
4836 Ctx->Display(ais, Standard_True);
4840 //==============================================================================
4841 //function : splitParameter
4842 //purpose : Split parameter string to parameter name and parameter value
4843 //==============================================================================
4844 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4845 TCollection_AsciiString& theName,
4846 TCollection_AsciiString& theValue)
4848 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4850 if (aParamNameEnd == 0)
4852 return Standard_False;
4855 TCollection_AsciiString aString (theString);
4856 if (aParamNameEnd != 0)
4858 theValue = aString.Split (aParamNameEnd);
4859 aString.Split (aString.Length() - 1);
4863 return Standard_True;
4866 //============================================================================
4868 //============================================================================
4869 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4872 DrawTrSurf::BasicCommands(theCommands);
4873 const char* group = "Check Features Operations commands";
4875 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4877 &TDraft,group); //Draft_Modification
4880 //==============================================================================
4881 // ViewerTest::Factory
4882 //==============================================================================
4883 void ViewerTest::Factory(Draw_Interpretor& theDI)
4885 // definition of Viewer Command
4886 ViewerTest::Commands(theDI);
4887 ViewerTest::AviCommands(theDI);
4890 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4894 // Declare entry point PLUGINFACTORY