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_ColoredShape.hxx>
44 #include <AIS_InteractiveObject.hxx>
45 #include <AIS_Trihedron.hxx>
46 #include <AIS_Axis.hxx>
47 #include <AIS_Relation.hxx>
48 #include <AIS_TypeFilter.hxx>
49 #include <AIS_SignatureFilter.hxx>
50 #include <AIS_LocalContext.hxx>
51 #include <AIS_ListOfInteractive.hxx>
52 #include <AIS_ListIteratorOfListOfInteractive.hxx>
53 #include <Aspect_InteriorStyle.hxx>
54 #include <Aspect_Window.hxx>
55 #include <Graphic3d_AspectFillArea3d.hxx>
56 #include <Graphic3d_AspectLine3d.hxx>
57 #include <Graphic3d_CStructure.hxx>
58 #include <Graphic3d_TextureRoot.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Prs3d_Drawer.hxx>
61 #include <Prs3d_ShadingAspect.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <Prs3d_PointAspect.hxx>
64 #include <Select3D_SensitiveWire.hxx>
65 #include <SelectMgr_EntityOwner.hxx>
66 #include <StdSelect_BRepOwner.hxx>
67 #include <StdSelect_ViewerSelector3d.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <ViewerTest_AutoUpdater.hxx>
73 #include <Draw_Interpretor.hxx>
74 #include <TCollection_AsciiString.hxx>
75 #include <Draw_PluginMacro.hxx>
77 // avoid warnings on 'extern "C"' functions returning C++ classes
79 #define _CRT_SECURE_NO_DEPRECATE
80 #pragma warning(4:4190)
81 #pragma warning (disable:4996)
84 #include <NIS_InteractiveContext.hxx>
85 #include <NIS_Triangulated.hxx>
86 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
88 #include <Quantity_Color.hxx>
89 #include <Quantity_NameOfColor.hxx>
91 #include <Graphic3d_NameOfMaterial.hxx>
93 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
94 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
95 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
97 //=======================================================================
98 //function : GetColorFromName
99 //purpose : get the Quantity_NameOfColor from a string
100 //=======================================================================
102 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
104 Quantity_NameOfColor aColor = DEFAULT_COLOR;
105 Quantity_Color::ColorFromName (theName, aColor);
109 //=======================================================================
110 //function : ParseColor
112 //=======================================================================
114 Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
115 const char** theArgVec,
116 Quantity_Color& theColor)
118 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
120 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
125 else if (theArgNb >= 3)
127 const TCollection_AsciiString anRgbStr[3] =
133 if (!anRgbStr[0].IsRealValue()
134 || !anRgbStr[1].IsRealValue()
135 || !anRgbStr[2].IsRealValue())
140 Graphic3d_Vec4d anRgb;
141 anRgb.x() = anRgbStr[0].RealValue();
142 anRgb.y() = anRgbStr[1].RealValue();
143 anRgb.z() = anRgbStr[2].RealValue();
144 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
145 || anRgb.y() < 0.0 || anRgb.y() > 1.0
146 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
148 std::cout << "Error: RGB color values should be within range 0..1!\n";
152 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
159 //=======================================================================
160 //function : GetTypeNames
162 //=======================================================================
163 static const char** GetTypeNames()
165 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
166 "Shape","ConnectedShape","MultiConn.Shape",
167 "ConnectedInter.","MultiConn.",
168 "Constraint","Dimension"};
169 static const char** ThePointer = names;
173 //=======================================================================
174 //function : GetTypeAndSignfromString
176 //=======================================================================
177 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
179 const char ** thefullnames = GetTypeNames();
180 Standard_Integer index(-1);
182 for(Standard_Integer i=0;i<=13 && index==-1;i++)
183 if(!strcasecmp(name,thefullnames[i]))
187 TheType = AIS_KOI_None;
193 TheType = AIS_KOI_Datum;
197 TheType = AIS_KOI_Shape;
201 TheType = AIS_KOI_Object;
205 TheType = AIS_KOI_Relation;
214 #include <Draw_Interpretor.hxx>
216 #include <Draw_Appli.hxx>
220 #include <TCollection_AsciiString.hxx>
221 #include <V3d_Viewer.hxx>
222 #include <V3d_View.hxx>
225 #include <AIS_InteractiveContext.hxx>
226 #include <AIS_Shape.hxx>
227 #include <AIS_TexturedShape.hxx>
228 #include <AIS_DisplayMode.hxx>
229 #include <TColStd_MapOfInteger.hxx>
230 #include <AIS_MapOfInteractive.hxx>
231 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
232 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
233 #include <ViewerTest_EventManager.hxx>
235 #include <TopoDS_Solid.hxx>
236 #include <BRepTools.hxx>
237 #include <BRep_Builder.hxx>
238 #include <TopAbs_ShapeEnum.hxx>
240 #include <TopoDS.hxx>
241 #include <BRep_Tool.hxx>
244 #include <Draw_Window.hxx>
245 #include <AIS_ListIteratorOfListOfInteractive.hxx>
246 #include <AIS_ListOfInteractive.hxx>
247 #include <AIS_DisplayMode.hxx>
248 #include <TopTools_ListOfShape.hxx>
249 #include <BRepOffsetAPI_MakeThickSolid.hxx>
250 #include <BRepOffset.hxx>
252 //==============================================================================
253 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
254 //==============================================================================
255 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
256 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
261 //==============================================================================
262 //function : VDisplayAISObject
263 //purpose : register interactive object in the map of AIS objects;
264 // if other object with such name already registered, it will be kept
265 // or replaced depending on value of <theReplaceIfExists>,
266 // if "true" - the old object will be cleared from AIS context;
267 // returns Standard_True if <theAISObj> registered in map;
268 //==============================================================================
269 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
270 const Handle(AIS_InteractiveObject)& theAISObj,
271 Standard_Boolean theReplaceIfExists = Standard_True)
273 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
274 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
275 if (aContextAIS.IsNull())
277 std::cout << "AIS context is not available.\n";
278 return Standard_False;
281 if (aMap.IsBound2 (theName))
283 if (!theReplaceIfExists)
285 std::cout << "Other interactive object has been already "
286 << "registered with name: " << theName << ".\n"
287 << "Please use another name.\n";
288 return Standard_False;
291 // stop displaying object
292 Handle(AIS_InteractiveObject) anOldObj =
293 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
295 if (!anOldObj.IsNull())
296 aContextAIS->Remove (anOldObj, Standard_True);
298 // remove name and old object from map
299 aMap.UnBind2 (theName);
302 if (theAISObj.IsNull())
304 // object with specified name already unbound
305 return Standard_True;
308 // unbind AIS object if was bound with another name
309 aMap.UnBind1 (theAISObj);
311 // can be registered without rebinding
312 aMap.Bind (theAISObj, theName);
313 aContextAIS->Display (theAISObj, Standard_True);
314 return Standard_True;
317 static TColStd_MapOfInteger theactivatedmodes(8);
318 static TColStd_ListOfTransient theEventMgrs;
320 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
321 const Handle(AIS_InteractiveContext)& Ctx)
323 theEventMgrs.Clear();
324 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
327 static Handle(V3d_View)& a3DView()
329 static Handle(V3d_View) Viou;
334 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
335 static Handle(AIS_InteractiveContext) aContext;
339 const Handle(V3d_View)& ViewerTest::CurrentView()
343 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
348 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
350 static Handle(NIS_InteractiveContext) aContext;
351 if (aContext.IsNull()) {
352 aContext = new NIS_InteractiveContext;
353 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
358 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
360 return TheAISContext();
363 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
365 TheAISContext() = aCtx;
366 ViewerTest::ResetEventManager();
369 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
371 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
374 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
376 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
380 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
381 theEventMgrs.Prepend(EM);
384 void ViewerTest::UnsetEventManager()
386 theEventMgrs.RemoveFirst();
390 void ViewerTest::ResetEventManager()
392 const Handle(NIS_View) aView =
393 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
394 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
397 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
399 Handle(ViewerTest_EventManager) EM;
400 if(theEventMgrs.IsEmpty()) return EM;
401 Handle(Standard_Transient) Tr = theEventMgrs.First();
402 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
406 //=======================================================================
407 //function : Get Context and active view
409 //=======================================================================
410 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
411 Handle(V3d_View)& theView)
413 theCtx = ViewerTest::GetAISContext();
414 theView = ViewerTest::CurrentView();
418 std::cout << "Error: cannot find an active view!\n";
419 return Standard_False;
421 return Standard_True;
424 //==============================================================================
425 //function : GetShapeFromName
426 //purpose : Compute an Shape from a draw variable or a file name
427 //==============================================================================
429 static TopoDS_Shape GetShapeFromName(const char* name)
431 TopoDS_Shape S = DBRep::Get(name);
434 BRep_Builder aBuilder;
435 BRepTools::Read( S, name, aBuilder);
441 //==============================================================================
442 //function : GetAISShapeFromName
443 //purpose : Compute an AIS_Shape from a draw variable or a file name
444 //==============================================================================
445 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
447 Handle(AIS_Shape) retsh;
449 if(GetMapOfAIS().IsBound2(name)){
450 const Handle(AIS_InteractiveObject) IO =
451 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
453 if(IO->Type()==AIS_KOI_Shape) {
454 if(IO->Signature()==0){
455 retsh = *((Handle(AIS_Shape)*)&IO);
458 cout << "an Object which is not an AIS_Shape "
459 "already has this name!!!"<<endl;
466 TopoDS_Shape S = GetShapeFromName(name);
468 retsh = new AIS_Shape(S);
474 //==============================================================================
476 //purpose : Remove all the object from the viewer
477 //==============================================================================
478 void ViewerTest::Clear()
480 if ( !a3DView().IsNull() ) {
481 if (TheAISContext()->HasOpenedContext())
482 TheAISContext()->CloseLocalContext();
483 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
484 while ( it.More() ) {
485 cout << "Remove " << it.Key2() << endl;
486 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
487 const Handle(AIS_InteractiveObject) anObj =
488 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
489 TheAISContext()->Remove(anObj,Standard_False);
490 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
491 const Handle(NIS_InteractiveObject) anObj =
492 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
493 TheNISContext()->Remove(anObj);
497 TheAISContext()->RebuildSelectionStructs();
498 TheAISContext()->UpdateCurrentViewer();
499 // TheNISContext()->UpdateViews();
500 GetMapOfAIS().Clear();
504 //==============================================================================
505 //function : StandardModesActivation
506 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
508 //==============================================================================
509 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
511 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
513 if (TheAISContext()->HasOpenedContext())
514 aContext->CloseLocalContext();
517 if(!aContext->HasOpenedContext()) {
518 // To unhilight the preselected object
519 aContext->UnhilightCurrents(Standard_False);
520 // Open a local Context in order to be able to select subshape from
521 // the selected shape if any or for all if there is no selection
522 if (!aContext->FirstCurrentObject().IsNull()){
523 aContext->OpenLocalContext(Standard_False);
525 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
526 aContext->Load( aContext->Current(),-1,Standard_True);
530 aContext->OpenLocalContext();
533 const char *cmode="???";
536 case 0: cmode = "Shape"; break;
537 case 1: cmode = "Vertex"; break;
538 case 2: cmode = "Edge"; break;
539 case 3: cmode = "Wire"; break;
540 case 4: cmode = "Face"; break;
541 case 5: cmode = "Shell"; break;
542 case 6: cmode = "Solid"; break;
543 case 7: cmode = "Compsolid"; break;
544 case 8: cmode = "Compound"; break;
547 if(theactivatedmodes.Contains(mode))
549 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
550 theactivatedmodes.Remove(mode);
551 cout<<"Mode "<< cmode <<" OFF"<<endl;
555 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
556 theactivatedmodes.Add(mode);
557 cout<<"Mode "<< cmode << " ON" << endl;
562 //==============================================================================
563 //function : CopyIsoAspect
564 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
565 //==============================================================================
566 static Handle(Prs3d_IsoAspect) CopyIsoAspect
567 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
568 const Standard_Integer theNbIsos)
570 Quantity_Color aColor;
571 Aspect_TypeOfLine aType;
572 Standard_Real aWidth;
574 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
576 Handle(Prs3d_IsoAspect) aResult =
577 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
582 //==============================================================================
584 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
585 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
586 //==============================================================================
587 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
589 if (TheAISContext().IsNull()) {
590 di << argv[0] << " Call 'vinit' before!\n";
595 di << "Current number of isos : " <<
596 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
597 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
598 di << "IsoOnPlane mode is " <<
599 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
604 Standard_Integer aLastInd = argc - 1;
605 Standard_Boolean isChanged = Standard_False;
606 Standard_Integer aNbUIsos = 0;
607 Standard_Integer aNbVIsos = 0;
610 Standard_Boolean isIsoOnPlane = Standard_False;
612 if (strcmp(argv[aLastInd], "1") == 0) {
613 isIsoOnPlane = Standard_True;
614 isChanged = Standard_True;
615 } else if (strcmp(argv[aLastInd], "0") == 0) {
616 isIsoOnPlane = Standard_False;
617 isChanged = Standard_True;
621 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
622 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
625 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
626 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
628 TheAISContext()->IsoOnPlane(isIsoOnPlane);
631 // If there are no shapes provided set the default numbers.
632 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
633 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
640 for (i = 1; i <= aLastInd; i++) {
641 TCollection_AsciiString name(argv[i]);
642 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
645 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
646 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
647 const Handle(AIS_InteractiveObject) aShape =
648 Handle(AIS_InteractiveObject)::DownCast (anObj);
649 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
650 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
651 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
654 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
655 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
656 TheAISContext()->SetLocalAttributes
657 (aShape, CurDrawer, Standard_False);
658 TheAISContext()->Redisplay(aShape);
660 di << "Number of isos for " << argv[i] << " : "
661 << aUIso->Number() << " " << aVIso->Number() << "\n";
664 di << argv[i] << ": Not an AIS interactive object!\n";
667 di << argv[i] << ": Use 'vdisplay' before\n";
672 TheAISContext()->UpdateCurrentViewer();
678 static Standard_Integer VDispSensi (Draw_Interpretor& ,
679 Standard_Integer theArgNb,
684 std::cout << "Error: wrong syntax!\n";
688 Handle(AIS_InteractiveContext) aCtx;
689 Handle(V3d_View) aView;
690 if (!getCtxAndView (aCtx, aView))
695 aCtx->DisplayActiveSensitive (aView);
700 static Standard_Integer VClearSensi (Draw_Interpretor& ,
701 Standard_Integer theArgNb,
706 std::cout << "Error: wrong syntax!\n";
710 Handle(AIS_InteractiveContext) aCtx;
711 Handle(V3d_View) aView;
712 if (!getCtxAndView (aCtx, aView))
716 aCtx->ClearActiveSensitive (aView);
720 //==============================================================================
722 //purpose : To list the displayed object with their attributes
723 //==============================================================================
724 static int VDir (Draw_Interpretor& theDI,
728 if (!a3DView().IsNull())
733 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
734 anIter.More(); anIter.Next())
736 theDI << "\t" << anIter.Key2().ToCString() << "\n";
741 //==============================================================================
742 //function : VSelPrecision
743 //purpose : To set the selection tolerance value
744 //Draw arg : Selection tolerance value (real value determining the width and
745 // height of selecting frustum bases). Without arguments the function
746 // just prints current tolerance.
747 //==============================================================================
748 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
752 di << "Use: " << argv[0] << " [tolerance_value]\n";
756 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
757 if( aContext.IsNull() )
762 Standard_Real aPixelTolerance = aContext->PixelTolerance();
763 di << "Precision mode : 0 (window)\n";
764 di << "Pixel tolerance : " << aPixelTolerance << "\n";
769 Standard_Integer aPixelTolerance = Draw::Atoi (argv[1]);
770 aContext->SetPixelTolerance (aPixelTolerance);
776 //==============================================================================
778 //purpose : To dump the active view snapshot to image file
779 //==============================================================================
780 static Standard_Integer VDump (Draw_Interpretor& theDI,
781 Standard_Integer theArgNb,
782 Standard_CString* theArgVec)
786 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
790 Standard_Integer anArgIter = 1;
791 Standard_CString aFilePath = theArgVec[anArgIter++];
792 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
793 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
794 Standard_Integer aWidth = 0;
795 Standard_Integer aHeight = 0;
796 for (; anArgIter < theArgNb; ++anArgIter)
798 TCollection_AsciiString anArg (theArgVec[anArgIter]);
802 aBufferType = Graphic3d_BT_RGBA;
804 else if (anArg == "rgb")
806 aBufferType = Graphic3d_BT_RGB;
808 else if (anArg == "depth")
810 aBufferType = Graphic3d_BT_Depth;
812 else if (anArg == "l"
815 aStereoOpts = V3d_SDO_LEFT_EYE;
817 else if (anArg == "r"
820 aStereoOpts = V3d_SDO_RIGHT_EYE;
822 else if (anArg == "mono")
824 aStereoOpts = V3d_SDO_MONO;
826 else if (anArg == "w"
831 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
834 else if (++anArgIter >= theArgNb)
836 std::cout << "Error: integer value is expected right after 'width'\n";
839 aWidth = Draw::Atoi (theArgVec[anArgIter]);
841 else if (anArg == "h"
842 || anArg == "height")
846 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
849 if (++anArgIter >= theArgNb)
851 std::cout << "Error: integer value is expected right after 'height'\n";
854 aHeight = Draw::Atoi (theArgVec[anArgIter]);
856 else if (anArg.IsIntegerValue())
858 // compatibility with old syntax
862 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
865 else if (++anArgIter >= theArgNb)
867 std::cout << "Error: height value is expected right after width\n";
870 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
871 aHeight = Draw::Atoi (theArgVec[anArgIter]);
875 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
879 if ((aWidth <= 0 && aHeight > 0)
880 || (aWidth > 0 && aHeight <= 0))
882 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
886 Handle(V3d_View) aView = ViewerTest::CurrentView();
889 std::cout << "Error: cannot find an active view!\n";
893 if (aWidth <= 0 || aHeight <= 0)
895 if (aStereoOpts != V3d_SDO_MONO)
897 aView->Window()->Size (aWidth, aHeight);
901 if (!aView->Dump (aFilePath, aBufferType))
903 theDI << "Fail: view dump failed!\n";
909 Image_AlienPixMap aPixMap;
910 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
912 theDI << "Fail: view dump failed!\n";
916 if (aPixMap.SizeX() != Standard_Size(aWidth)
917 || aPixMap.SizeY() != Standard_Size(aHeight))
919 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
920 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
922 if (!aPixMap.Save (aFilePath))
924 theDI << "Fail: image can not be saved!\n";
930 //==============================================================================
931 //function : Displays,Erase...
934 //==============================================================================
935 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
936 const Standard_Integer Mode,
937 const Standard_Integer TypeOfOperation,
938 const Standard_Boolean Upd)
940 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
942 switch(TypeOfOperation){
944 Ctx->Display(IO,Mode,Upd);
952 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
954 Ctx->SetDisplayMode(IO,Mode,Upd);
959 Ctx->SetDisplayMode(0,Upd);
961 Ctx->UnsetDisplayMode(IO,Upd);
968 //=======================================================================
971 //=======================================================================
972 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
975 TCollection_AsciiString name;
978 // display others presentations
979 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
980 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
981 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
982 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
984 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
986 //unset displaymode.. comportement particulier...
987 if(TypeOfOperation==4){
989 if(Ctx->NbCurrents()==0 ||
990 Ctx->NbSelected()==0){
991 Handle(AIS_InteractiveObject) IO;
992 VwrTst_DispErase(IO,-1,4,Standard_False);
994 else if(!Ctx->HasOpenedContext()){
995 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
996 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
999 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1000 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1001 Ctx->UpdateCurrentViewer();
1004 Handle(AIS_InteractiveObject) IO;
1006 if(GetMapOfAIS().IsBound2(name)){
1007 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1009 VwrTst_DispErase(IO,-1,4,Standard_True);
1014 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1015 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1016 Handle(AIS_InteractiveObject) IO;
1017 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1019 if(!Ctx->HasOpenedContext()){
1020 // set/unset display mode sur le Contexte...
1021 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1022 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1024 Ctx->UpdateCurrentViewer();
1027 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1028 Ctx->Display(Ctx->Interactive(),Dmode);
1032 Handle(AIS_InteractiveObject) IO;
1034 if(GetMapOfAIS().IsBound2(name))
1035 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1037 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1043 //=======================================================================
1046 //=======================================================================
1047 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1049 if(argc==1) return 1;
1050 Standard_Integer On = Draw::Atoi(argv[1]);
1051 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1055 if(!Ctx->HasOpenedContext()){
1056 di<<"sub intensite ";
1059 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1060 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1062 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1064 di <<"passage dans off"<<"\n";
1065 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1070 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1072 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1074 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1077 Ctx->UpdateCurrentViewer();
1080 Handle(AIS_InteractiveObject) IO;
1081 TCollection_AsciiString name = argv[2];
1082 if(GetMapOfAIS().IsBound2(name)){
1083 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1086 Ctx->SubIntensityOn(IO);
1088 Ctx->SubIntensityOff(IO);
1096 //! Auxiliary class to iterate presentations from different collections.
1097 class ViewTest_PrsIter
1101 //! Create and initialize iterator object.
1102 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1103 : mySource (IterSource_All)
1105 NCollection_Sequence<TCollection_AsciiString> aNames;
1106 if (!theName.IsEmpty())
1107 aNames.Append (theName);
1111 //! Create and initialize iterator object.
1112 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1113 : mySource (IterSource_All)
1118 //! Initialize the iterator.
1119 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1121 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1123 mySelIter.Nullify();
1124 myCurrent.Nullify();
1125 myCurrentTrs.Nullify();
1126 if (!mySeq.IsEmpty())
1128 mySource = IterSource_List;
1129 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1131 else if (aCtx->NbCurrents() > 0)
1133 mySource = IterSource_Selected;
1135 mySelIter->InitCurrent();
1139 mySource = IterSource_All;
1140 myMapIter.Initialize (GetMapOfAIS());
1145 const TCollection_AsciiString& CurrentName() const
1147 return myCurrentName;
1150 const Handle(AIS_InteractiveObject)& Current() const
1155 const Handle(Standard_Transient)& CurrentTrs() const
1157 return myCurrentTrs;
1160 //! @return true if iterator points to valid object within collection
1161 Standard_Boolean More() const
1165 case IterSource_All: return myMapIter.More();
1166 case IterSource_List: return mySeqIter.More();
1167 case IterSource_Selected: return mySelIter->MoreCurrent();
1169 return Standard_False;
1172 //! Go to the next item.
1175 myCurrentName.Clear();
1176 myCurrentTrs.Nullify();
1177 myCurrent.Nullify();
1180 case IterSource_All:
1185 case IterSource_List:
1190 case IterSource_Selected:
1192 mySelIter->NextCurrent();
1205 case IterSource_All:
1207 if (myMapIter.More())
1209 myCurrentName = myMapIter.Key2();
1210 myCurrentTrs = myMapIter.Key1();
1211 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1215 case IterSource_List:
1217 if (mySeqIter.More())
1219 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1221 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1224 myCurrentName = mySeqIter.Value();
1225 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1226 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1230 case IterSource_Selected:
1232 if (mySelIter->MoreCurrent())
1234 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1235 myCurrent = mySelIter->Current();
1253 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1254 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1255 NCollection_Sequence<TCollection_AsciiString> mySeq;
1256 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1258 TCollection_AsciiString myCurrentName;//!< current item name
1259 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1260 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1262 IterSource mySource; //!< iterated collection
1266 //==============================================================================
1267 //function : VInteriorStyle
1268 //purpose : sets interior style of the a selected or named or displayed shape
1269 //==============================================================================
1270 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1271 Standard_Integer theArgNb,
1272 const char** theArgVec)
1274 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1275 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1278 std::cerr << "Error: no active view!\n";
1282 Standard_Integer anArgIter = 1;
1283 for (; anArgIter < theArgNb; ++anArgIter)
1285 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1290 TCollection_AsciiString aName;
1291 if (theArgNb - anArgIter == 2)
1293 aName = theArgVec[anArgIter++];
1295 else if (theArgNb - anArgIter != 1)
1297 std::cout << "Error: wrong number of arguments! See usage:\n";
1298 theDI.PrintHelp (theArgVec[0]);
1301 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1302 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1303 aStyleArg.LowerCase();
1304 if (aStyleArg == "empty")
1308 else if (aStyleArg == "hollow")
1312 else if (aStyleArg == "hatch")
1316 else if (aStyleArg == "solid")
1320 else if (aStyleArg == "hiddenline")
1326 anInterStyle = aStyleArg.IntegerValue();
1328 if (anInterStyle < Aspect_IS_EMPTY
1329 || anInterStyle > Aspect_IS_HIDDENLINE)
1331 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1332 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1336 if (!aName.IsEmpty()
1337 && !GetMapOfAIS().IsBound2 (aName))
1339 std::cout << "Error: object " << aName << " is not displayed!\n";
1343 if (aCtx->HasOpenedContext())
1345 aCtx->CloseLocalContext();
1347 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1349 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1352 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1353 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1354 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1355 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1356 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1362 //! Auxiliary structure for VAspects
1363 struct ViewerTest_AspectsChangeSet
1365 Standard_Integer ToSetVisibility;
1366 Standard_Integer Visibility;
1368 Standard_Integer ToSetColor;
1369 Quantity_Color Color;
1371 Standard_Integer ToSetLineWidth;
1372 Standard_Real LineWidth;
1374 Standard_Integer ToSetTransparency;
1375 Standard_Real Transparency;
1377 Standard_Integer ToSetMaterial;
1378 Graphic3d_NameOfMaterial Material;
1379 TCollection_AsciiString MatName;
1381 NCollection_Sequence<TopoDS_Shape> SubShapes;
1383 Standard_Integer ToSetShowFreeBoundary;
1384 Standard_Integer ToSetFreeBoundaryWidth;
1385 Standard_Real FreeBoundaryWidth;
1386 Standard_Integer ToSetFreeBoundaryColor;
1387 Quantity_Color FreeBoundaryColor;
1389 //! Empty constructor
1390 ViewerTest_AspectsChangeSet()
1391 : ToSetVisibility (0),
1394 Color (DEFAULT_COLOR),
1397 ToSetTransparency (0),
1400 Material (Graphic3d_NOM_DEFAULT),
1401 ToSetShowFreeBoundary (0),
1402 ToSetFreeBoundaryWidth (0),
1403 FreeBoundaryWidth (1.0),
1404 ToSetFreeBoundaryColor (0),
1405 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
1407 //! @return true if no changes have been requested
1408 Standard_Boolean IsEmpty() const
1410 return ToSetVisibility == 0
1411 && ToSetLineWidth == 0
1412 && ToSetTransparency == 0
1414 && ToSetMaterial == 0
1415 && ToSetShowFreeBoundary == 0
1416 && ToSetFreeBoundaryColor == 0
1417 && ToSetFreeBoundaryWidth == 0;
1420 //! @return true if properties are valid
1421 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1423 Standard_Boolean isOk = Standard_True;
1424 if (Visibility != 0 && Visibility != 1)
1426 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1427 isOk = Standard_False;
1429 if (LineWidth <= 0.0
1430 || LineWidth > 10.0)
1432 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1433 isOk = Standard_False;
1435 if (Transparency < 0.0
1436 || Transparency > 1.0)
1438 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1439 isOk = Standard_False;
1442 && ToSetTransparency)
1444 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1445 isOk = Standard_False;
1447 if (ToSetMaterial == 1
1448 && Material == Graphic3d_NOM_DEFAULT)
1450 std::cout << "Error: unknown material " << MatName << ".\n";
1451 isOk = Standard_False;
1453 if (FreeBoundaryWidth <= 0.0
1454 || FreeBoundaryWidth > 10.0)
1456 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1457 isOk = Standard_False;
1464 //==============================================================================
1465 //function : VAspects
1467 //==============================================================================
1468 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1469 Standard_Integer theArgNb,
1470 const char** theArgVec)
1472 TCollection_AsciiString aCmdName (theArgVec[0]);
1473 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1474 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1477 std::cerr << "Error: no active view!\n";
1481 Standard_Integer anArgIter = 1;
1482 Standard_Boolean isDefaults = Standard_False;
1483 NCollection_Sequence<TCollection_AsciiString> aNames;
1484 for (; anArgIter < theArgNb; ++anArgIter)
1486 TCollection_AsciiString anArg = theArgVec[anArgIter];
1487 if (anUpdateTool.parseRedrawMode (anArg))
1491 else if (!anArg.IsEmpty()
1492 && anArg.Value (1) != '-')
1494 aNames.Append (anArg);
1498 if (anArg == "-defaults")
1500 isDefaults = Standard_True;
1507 if (!aNames.IsEmpty() && isDefaults)
1509 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1513 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1514 aChanges.Append (ViewerTest_AspectsChangeSet());
1515 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1517 // parse syntax of legacy commands
1518 if (aCmdName == "vsetwidth")
1520 if (aNames.IsEmpty()
1521 || !aNames.Last().IsRealValue())
1523 std::cout << "Error: not enough arguments!\n";
1526 aChangeSet->ToSetLineWidth = 1;
1527 aChangeSet->LineWidth = aNames.Last().RealValue();
1528 aNames.Remove (aNames.Length());
1530 else if (aCmdName == "vunsetwidth")
1532 aChangeSet->ToSetLineWidth = -1;
1534 else if (aCmdName == "vsetcolor")
1536 if (aNames.IsEmpty())
1538 std::cout << "Error: not enough arguments!\n";
1541 aChangeSet->ToSetColor = 1;
1543 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1544 Standard_Boolean isOk = Standard_False;
1545 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1547 aChangeSet->Color = aColor;
1548 aNames.Remove (aNames.Length());
1549 isOk = Standard_True;
1551 else if (aNames.Length() >= 3)
1553 const TCollection_AsciiString anRgbStr[3] =
1555 aNames.Value (aNames.Upper() - 2),
1556 aNames.Value (aNames.Upper() - 1),
1557 aNames.Value (aNames.Upper() - 0)
1559 isOk = anRgbStr[0].IsRealValue()
1560 && anRgbStr[1].IsRealValue()
1561 && anRgbStr[2].IsRealValue();
1564 Graphic3d_Vec4d anRgb;
1565 anRgb.x() = anRgbStr[0].RealValue();
1566 anRgb.y() = anRgbStr[1].RealValue();
1567 anRgb.z() = anRgbStr[2].RealValue();
1568 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1569 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1570 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1572 std::cout << "Error: RGB color values should be within range 0..1!\n";
1575 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1576 aNames.Remove (aNames.Length());
1577 aNames.Remove (aNames.Length());
1578 aNames.Remove (aNames.Length());
1583 std::cout << "Error: not enough arguments!\n";
1587 else if (aCmdName == "vunsetcolor")
1589 aChangeSet->ToSetColor = -1;
1591 else if (aCmdName == "vsettransparency")
1593 if (aNames.IsEmpty()
1594 || !aNames.Last().IsRealValue())
1596 std::cout << "Error: not enough arguments!\n";
1599 aChangeSet->ToSetTransparency = 1;
1600 aChangeSet->Transparency = aNames.Last().RealValue();
1601 aNames.Remove (aNames.Length());
1603 else if (aCmdName == "vunsettransparency")
1605 aChangeSet->ToSetTransparency = -1;
1607 else if (aCmdName == "vsetmaterial")
1609 if (aNames.IsEmpty())
1611 std::cout << "Error: not enough arguments!\n";
1614 aChangeSet->ToSetMaterial = 1;
1615 aChangeSet->MatName = aNames.Last();
1616 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1617 aNames.Remove (aNames.Length());
1619 else if (aCmdName == "vunsetmaterial")
1621 aChangeSet->ToSetMaterial = -1;
1623 else if (anArgIter >= theArgNb)
1625 std::cout << "Error: not enough arguments!\n";
1629 if (!aChangeSet->IsEmpty())
1631 anArgIter = theArgNb;
1633 for (; anArgIter < theArgNb; ++anArgIter)
1635 TCollection_AsciiString anArg = theArgVec[anArgIter];
1637 if (anArg == "-setwidth"
1638 || anArg == "-setlinewidth")
1640 if (++anArgIter >= theArgNb)
1642 std::cout << "Error: wrong syntax at " << anArg << "\n";
1645 aChangeSet->ToSetLineWidth = 1;
1646 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1648 else if (anArg == "-unsetwidth"
1649 || anArg == "-unsetlinewidth")
1651 aChangeSet->ToSetLineWidth = -1;
1652 aChangeSet->LineWidth = 1.0;
1654 else if (anArg == "-settransp"
1655 || anArg == "-settransparency")
1657 if (++anArgIter >= theArgNb)
1659 std::cout << "Error: wrong syntax at " << anArg << "\n";
1662 aChangeSet->ToSetTransparency = 1;
1663 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1664 if (aChangeSet->Transparency >= 0.0
1665 && aChangeSet->Transparency <= Precision::Confusion())
1667 aChangeSet->ToSetTransparency = -1;
1668 aChangeSet->Transparency = 0.0;
1671 else if (anArg == "-setvis"
1672 || anArg == "-setvisibility")
1674 if (++anArgIter >= theArgNb)
1676 std::cout << "Error: wrong syntax at " << anArg << "\n";
1680 aChangeSet->ToSetVisibility = 1;
1681 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1683 else if (anArg == "-setalpha")
1685 if (++anArgIter >= theArgNb)
1687 std::cout << "Error: wrong syntax at " << anArg << "\n";
1690 aChangeSet->ToSetTransparency = 1;
1691 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1692 if (aChangeSet->Transparency < 0.0
1693 || aChangeSet->Transparency > 1.0)
1695 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1698 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1699 if (aChangeSet->Transparency >= 0.0
1700 && aChangeSet->Transparency <= Precision::Confusion())
1702 aChangeSet->ToSetTransparency = -1;
1703 aChangeSet->Transparency = 0.0;
1706 else if (anArg == "-unsettransp"
1707 || anArg == "-unsettransparency"
1708 || anArg == "-unsetalpha"
1709 || anArg == "-opaque")
1711 aChangeSet->ToSetTransparency = -1;
1712 aChangeSet->Transparency = 0.0;
1714 else if (anArg == "-setcolor")
1716 Standard_Integer aNbComps = 0;
1717 Standard_Integer aCompIter = anArgIter + 1;
1718 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1720 if (theArgVec[aCompIter][0] == '-')
1729 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1730 Standard_CString aName = theArgVec[anArgIter + 1];
1731 if (!Quantity_Color::ColorFromName (aName, aColor))
1733 std::cout << "Error: unknown color name '" << aName << "'\n";
1736 aChangeSet->Color = aColor;
1741 Graphic3d_Vec3d anRgb;
1742 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1743 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1744 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1745 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1746 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1747 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1749 std::cout << "Error: RGB color values should be within range 0..1!\n";
1752 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1757 std::cout << "Error: wrong syntax at " << anArg << "\n";
1761 aChangeSet->ToSetColor = 1;
1762 anArgIter += aNbComps;
1764 else if (anArg == "-unsetcolor")
1766 aChangeSet->ToSetColor = -1;
1767 aChangeSet->Color = DEFAULT_COLOR;
1769 else if (anArg == "-setmat"
1770 || anArg == "-setmaterial")
1772 if (++anArgIter >= theArgNb)
1774 std::cout << "Error: wrong syntax at " << anArg << "\n";
1777 aChangeSet->ToSetMaterial = 1;
1778 aChangeSet->MatName = theArgVec[anArgIter];
1779 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1781 else if (anArg == "-unsetmat"
1782 || anArg == "-unsetmaterial")
1784 aChangeSet->ToSetMaterial = -1;
1785 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1787 else if (anArg == "-subshape"
1788 || anArg == "-subshapes")
1792 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1796 if (aNames.IsEmpty())
1798 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1802 aChanges.Append (ViewerTest_AspectsChangeSet());
1803 aChangeSet = &aChanges.ChangeLast();
1805 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1807 Standard_CString aSubShapeName = theArgVec[anArgIter];
1808 if (*aSubShapeName == '-')
1814 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1815 if (aSubShape.IsNull())
1817 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1820 aChangeSet->SubShapes.Append (aSubShape);
1823 if (aChangeSet->SubShapes.IsEmpty())
1825 std::cerr << "Error: empty list is specified after -subshapes!\n";
1829 else if (anArg == "-freeboundary"
1832 if (++anArgIter >= theArgNb)
1834 std::cout << "Error: wrong syntax at " << anArg << "\n";
1837 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1842 aChangeSet->ToSetShowFreeBoundary = 1;
1844 else if (aValue == "off"
1847 aChangeSet->ToSetShowFreeBoundary = -1;
1851 std::cout << "Error: wrong syntax at " << anArg << "\n";
1855 else if (anArg == "-setfreeboundarywidth"
1856 || anArg == "-setfbwidth")
1858 if (++anArgIter >= theArgNb)
1860 std::cout << "Error: wrong syntax at " << anArg << "\n";
1863 aChangeSet->ToSetFreeBoundaryWidth = 1;
1864 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1866 else if (anArg == "-unsetfreeboundarywidth"
1867 || anArg == "-unsetfbwidth")
1869 aChangeSet->ToSetFreeBoundaryWidth = -1;
1870 aChangeSet->FreeBoundaryWidth = 1.0;
1872 else if (anArg == "-setfreeboundarycolor"
1873 || anArg == "-setfbcolor")
1875 Standard_Integer aNbComps = 0;
1876 Standard_Integer aCompIter = anArgIter + 1;
1877 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1879 if (theArgVec[aCompIter][0] == '-')
1888 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1889 Standard_CString aName = theArgVec[anArgIter + 1];
1890 if (!Quantity_Color::ColorFromName (aName, aColor))
1892 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1895 aChangeSet->FreeBoundaryColor = aColor;
1900 Graphic3d_Vec3d anRgb;
1901 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1902 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1903 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1904 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1905 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1906 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1908 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1911 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1916 std::cout << "Error: wrong syntax at " << anArg << "\n";
1920 aChangeSet->ToSetFreeBoundaryColor = 1;
1921 anArgIter += aNbComps;
1923 else if (anArg == "-unsetfreeboundarycolor"
1924 || anArg == "-unsetfbcolor")
1926 aChangeSet->ToSetFreeBoundaryColor = -1;
1927 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1929 else if (anArg == "-unset")
1931 aChangeSet->ToSetVisibility = 1;
1932 aChangeSet->Visibility = 1;
1933 aChangeSet->ToSetLineWidth = -1;
1934 aChangeSet->LineWidth = 1.0;
1935 aChangeSet->ToSetTransparency = -1;
1936 aChangeSet->Transparency = 0.0;
1937 aChangeSet->ToSetColor = -1;
1938 aChangeSet->Color = DEFAULT_COLOR;
1939 aChangeSet->ToSetMaterial = -1;
1940 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1941 aChangeSet->ToSetShowFreeBoundary = -1;
1942 aChangeSet->ToSetFreeBoundaryColor = -1;
1943 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1944 aChangeSet->ToSetFreeBoundaryWidth = -1;
1945 aChangeSet->FreeBoundaryWidth = 1.0;
1949 std::cout << "Error: wrong syntax at " << anArg << "\n";
1954 Standard_Boolean isFirst = Standard_True;
1955 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1956 aChangesIter.More(); aChangesIter.Next())
1958 if (!aChangesIter.Value().Validate (!isFirst))
1962 isFirst = Standard_False;
1965 if (aCtx->HasOpenedContext())
1967 aCtx->CloseLocalContext();
1970 // special case for -defaults parameter.
1971 // all changed values will be set to DefaultDrawer.
1974 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
1976 if (aChangeSet->ToSetLineWidth != 0)
1978 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
1979 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
1980 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
1981 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
1983 if (aChangeSet->ToSetColor != 0)
1985 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
1986 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
1987 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
1988 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
1989 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
1990 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
1992 if (aChangeSet->ToSetTransparency != 0)
1994 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
1996 if (aChangeSet->ToSetMaterial != 0)
1998 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2000 if (aChangeSet->ToSetShowFreeBoundary == 1)
2002 aDrawer->SetFreeBoundaryDraw (Standard_True);
2004 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2006 aDrawer->SetFreeBoundaryDraw (Standard_False);
2008 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2010 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2012 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2014 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2017 // redisplay all objects in context
2018 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2020 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2023 aCtx->Redisplay (aPrs, Standard_False);
2029 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2031 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2032 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2033 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
2034 Handle(AIS_ColoredShape) aColoredPrs;
2035 Standard_Boolean toDisplay = Standard_False;
2036 Standard_Boolean toRedisplay = Standard_False;
2037 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
2039 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2040 if (aShapePrs.IsNull())
2042 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2045 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2046 if (aColoredPrs.IsNull())
2048 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2049 aCtx->Remove (aShapePrs, Standard_False);
2050 GetMapOfAIS().UnBind2 (aName);
2051 GetMapOfAIS().Bind (aColoredPrs, aName);
2052 toDisplay = Standard_True;
2053 aShapePrs = aColoredPrs;
2060 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2061 aChangeSet = &aChangesIter.ChangeValue();
2062 if (aChangeSet->ToSetVisibility == 1)
2064 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2065 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2067 else if (aChangeSet->ToSetMaterial == 1)
2069 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2071 else if (aChangeSet->ToSetMaterial == -1)
2073 aCtx->UnsetMaterial (aPrs, Standard_False);
2075 if (aChangeSet->ToSetColor == 1)
2077 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2079 else if (aChangeSet->ToSetColor == -1)
2081 aCtx->UnsetColor (aPrs, Standard_False);
2083 if (aChangeSet->ToSetTransparency == 1)
2085 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2087 else if (aChangeSet->ToSetTransparency == -1)
2089 aCtx->UnsetTransparency (aPrs, Standard_False);
2091 if (aChangeSet->ToSetLineWidth == 1)
2093 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2095 else if (aChangeSet->ToSetLineWidth == -1)
2097 aCtx->UnsetWidth (aPrs, Standard_False);
2099 if (!aDrawer.IsNull())
2101 if (aChangeSet->ToSetShowFreeBoundary == 1)
2103 aDrawer->SetFreeBoundaryDraw (Standard_True);
2104 toRedisplay = Standard_True;
2106 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2108 aDrawer->SetFreeBoundaryDraw (Standard_False);
2109 toRedisplay = Standard_True;
2111 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2113 Handle(Prs3d_LineAspect) aBoundaryAspect =
2114 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2115 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2116 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2117 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2118 toRedisplay = Standard_True;
2120 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2122 Handle(Prs3d_LineAspect) aBoundaryAspect =
2123 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2124 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2125 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2126 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2127 toRedisplay = Standard_True;
2131 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2133 aChangeSet = &aChangesIter.ChangeValue();
2134 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2135 aSubShapeIter.More(); aSubShapeIter.Next())
2137 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
2138 if (aChangeSet->ToSetVisibility == 1)
2140 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2141 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2143 if (aChangeSet->ToSetColor == 1)
2145 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2147 if (aChangeSet->ToSetLineWidth == 1)
2149 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2151 if (aChangeSet->ToSetColor == -1
2152 || aChangeSet->ToSetLineWidth == -1)
2154 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2160 aCtx->Display (aPrs, Standard_False);
2164 aCtx->Redisplay (aPrs, Standard_False);
2166 else if (!aColoredPrs.IsNull())
2168 aCtx->Redisplay (aColoredPrs, Standard_False);
2173 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
2174 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
2175 if (!aNisObj.IsNull())
2177 if (aChangeSet->ToSetTransparency != 0)
2179 aNisObj->SetTransparency (aChangeSet->Transparency);
2182 if (!aNisTri.IsNull())
2184 if (aChangeSet->ToSetColor != 0)
2186 aNisTri->SetColor (aChangeSet->Color);
2188 if (aChangeSet->ToSetLineWidth != 0)
2190 aNisTri->SetLineWidth (aChangeSet->LineWidth);
2198 //==============================================================================
2199 //function : VDonly2
2201 //purpose : Display only a selected or named object
2202 // if there is no selected or named object s, nothing is done
2203 //==============================================================================
2204 static int VDonly2 (Draw_Interpretor& ,
2205 Standard_Integer theArgNb,
2206 const char** theArgVec)
2208 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2209 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2212 std::cerr << "Error: no active view!\n";
2216 if (aCtx->HasOpenedContext())
2218 aCtx->CloseLocalContext();
2221 Standard_Integer anArgIter = 1;
2222 for (; anArgIter < theArgNb; ++anArgIter)
2224 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2230 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2231 if (anArgIter >= theArgNb)
2233 // display only selected objects
2234 if (aCtx->NbCurrents() < 1)
2239 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2241 aDispSet.Add (aCtx->Current());
2246 // display only specified objects
2247 for (; anArgIter < theArgNb; ++anArgIter)
2249 TCollection_AsciiString aName = theArgVec[anArgIter];
2250 if (GetMapOfAIS().IsBound2 (aName))
2252 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2253 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2255 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2256 aCtx->Display (aShape, Standard_False);
2258 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2260 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2261 TheNISContext()->Display (aShape);
2263 aDispSet.Add (anObj);
2268 // weed out other objects
2269 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2271 if (aDispSet.Contains (anIter.Key1()))
2276 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2278 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2279 aCtx->Erase (aShape, Standard_False);
2281 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2283 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2284 TheNISContext()->Erase (aShape);
2290 //==============================================================================
2291 //function : VRemove
2292 //purpose : Removes selected or named objects.
2293 // If there is no selected or named objects,
2294 // all objects in the viewer can be removed with argument -all.
2295 // If -context is in arguments, the object is not deleted from the map of
2296 // objects (deleted only from the current context).
2297 //==============================================================================
2298 int VRemove (Draw_Interpretor& theDI,
2299 Standard_Integer theArgNb,
2300 const char** theArgVec)
2302 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2303 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2306 std::cerr << "Error: no active view!\n";
2310 Standard_Boolean isContextOnly = Standard_False;
2311 Standard_Boolean toRemoveAll = Standard_False;
2312 Standard_Boolean toPrintInfo = Standard_True;
2313 Standard_Boolean toRemoveLocal = Standard_False;
2315 Standard_Integer anArgIter = 1;
2316 for (; anArgIter < theArgNb; ++anArgIter)
2318 TCollection_AsciiString anArg = theArgVec[anArgIter];
2320 if (anArg == "-context")
2322 isContextOnly = Standard_True;
2324 else if (anArg == "-all")
2326 toRemoveAll = Standard_True;
2328 else if (anArg == "-noinfo")
2330 toPrintInfo = Standard_False;
2332 else if (anArg == "-local")
2334 toRemoveLocal = Standard_True;
2336 else if (anUpdateTool.parseRedrawMode (anArg))
2346 && anArgIter < theArgNb)
2348 std::cerr << "Error: wrong syntax!\n";
2352 if (toRemoveLocal && !aCtx->HasOpenedContext())
2354 std::cerr << "Error: local selection context is not open.\n";
2357 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2359 aCtx->CloseAllContexts (Standard_False);
2362 NCollection_List<TCollection_AsciiString> anIONameList;
2365 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2366 anIter.More(); anIter.Next())
2368 anIONameList.Append (anIter.Key2());
2371 else if (anArgIter < theArgNb) // removed objects names are in argument list
2373 for (; anArgIter < theArgNb; ++anArgIter)
2375 TCollection_AsciiString aName = theArgVec[anArgIter];
2376 if (!GetMapOfAIS().IsBound2 (aName))
2378 theDI << aName.ToCString() << " was not bound to some object.\n";
2382 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2384 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2387 if (anIO->GetContext() != aCtx)
2389 theDI << aName.ToCString() << " was not displayed in current context.\n";
2390 theDI << "Please activate view with this object displayed and try again.\n";
2394 anIONameList.Append (aName);
2398 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2399 if (!aNisIO.IsNull())
2401 anIONameList.Append (aName);
2405 else if (aCtx->NbCurrents() > 0
2406 || TheNISContext()->GetSelected().Extent() > 0)
2408 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2409 anIter.More(); anIter.Next())
2411 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2414 if (!aCtx->IsCurrent (anIO))
2419 anIONameList.Append (anIter.Key2());
2423 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2424 if (!aNisIO.IsNull())
2426 if (!TheNISContext()->IsSelected (aNisIO))
2431 anIONameList.Append (anIter.Key2());
2436 // Unbind all removed objects from the map of displayed IO.
2437 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2438 anIter.More(); anIter.Next())
2440 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2443 aCtx->Remove (anIO, Standard_False);
2446 theDI << anIter.Value().ToCString() << " was removed\n";
2451 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2452 if (!aNisIO.IsNull())
2454 TheNISContext()->Remove (aNisIO);
2457 theDI << anIter.Value().ToCString() << " was removed\n";
2463 GetMapOfAIS().UnBind2 (anIter.Value());
2467 // Close local context if it is empty
2468 TColStd_MapOfTransient aLocalIO;
2469 if (aCtx->HasOpenedContext()
2470 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2472 aCtx->CloseAllContexts (Standard_False);
2478 //==============================================================================
2480 //purpose : Erase some selected or named objects
2481 // if there is no selected or named objects, the whole viewer is erased
2482 //==============================================================================
2483 int VErase (Draw_Interpretor& theDI,
2484 Standard_Integer theArgNb,
2485 const char** theArgVec)
2487 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2488 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2489 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
2492 std::cerr << "Error: no active view!\n";
2496 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2498 Standard_Integer anArgIter = 1;
2499 Standard_Boolean toEraseLocal = Standard_False;
2500 Standard_Boolean toEraseInView = Standard_False;
2501 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
2502 for (; anArgIter < theArgNb; ++anArgIter)
2504 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2505 anArgCase.LowerCase();
2506 if (anUpdateTool.parseRedrawMode (anArgCase))
2510 else if (anArgCase == "-local")
2512 toEraseLocal = Standard_True;
2514 else if (anArgCase == "-view"
2515 || anArgCase == "-inview")
2517 toEraseInView = Standard_True;
2521 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
2525 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
2527 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2531 if (toEraseLocal && !aCtx->HasOpenedContext())
2533 std::cerr << "Error: local selection context is not open.\n";
2536 else if (!toEraseLocal && aCtx->HasOpenedContext())
2538 aCtx->CloseAllContexts (Standard_False);
2541 if (!aNamesOfEraseIO.IsEmpty())
2543 // Erase named objects
2544 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
2546 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
2547 if (!GetMapOfAIS().IsBound2 (aName))
2552 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2553 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2554 theDI << aName.ToCString() << " ";
2559 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2563 aCtx->Erase (anIO, Standard_False);
2568 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2569 if (!aNisIO.IsNull())
2571 TheNISContext()->Erase (aNisIO);
2576 else if (!toEraseAll && aCtx->NbCurrents() > 0)
2578 // Erase selected objects
2579 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2580 anIter.More(); anIter.Next())
2582 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2584 && aCtx->IsCurrent (anIO))
2586 theDI << anIter.Key2().ToCString() << " ";
2589 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2593 aCtx->Erase (anIO, Standard_False);
2600 // Erase all objects
2601 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2602 anIter.More(); anIter.Next())
2604 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2609 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2613 aCtx->Erase (anIO, Standard_False);
2618 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2619 if (!aNisIO.IsNull())
2621 TheNISContext()->Erase (aNisIO);
2630 //==============================================================================
2631 //function : VDisplayAll
2633 //purpose : Display all the objects of the Map
2634 //==============================================================================
2635 static int VDisplayAll (Draw_Interpretor& ,
2636 Standard_Integer theArgNb,
2637 const char** theArgVec)
2640 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2641 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2644 std::cerr << "Error: no active view!\n";
2648 Standard_Integer anArgIter = 1;
2649 Standard_Boolean toDisplayLocal = Standard_False;
2650 for (; anArgIter < theArgNb; ++anArgIter)
2652 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2653 anArgCase.LowerCase();
2654 if (anArgCase == "-local")
2656 toDisplayLocal = Standard_True;
2658 else if (anUpdateTool.parseRedrawMode (anArgCase))
2667 if (anArgIter < theArgNb)
2669 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2673 if (toDisplayLocal && !aCtx->HasOpenedContext())
2675 std::cerr << "Error: local selection context is not open.\n";
2678 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2680 aCtx->CloseLocalContext (Standard_False);
2683 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2684 anIter.More(); anIter.Next())
2686 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2688 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2689 aCtx->Erase (aShape, Standard_False);
2691 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2693 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2694 TheNISContext()->Erase (aShape);
2698 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2699 anIter.More(); anIter.Next())
2701 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2703 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2704 aCtx->Display (aShape, Standard_False);
2706 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2708 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2709 TheNISContext()->Display (aShape);
2715 //! Auxiliary method to find presentation
2716 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2717 const Handle(AIS_InteractiveObject)& theIO,
2718 const Standard_Integer theMode)
2722 return Handle(PrsMgr_Presentation)();
2727 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2729 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2732 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2734 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2736 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2738 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2740 return Handle(PrsMgr_Presentation)();
2743 enum ViewerTest_BndAction
2750 //! Auxiliary method to print bounding box of presentation
2751 inline void bndPresentation (Draw_Interpretor& theDI,
2752 const Handle(PrsMgr_Presentation)& thePrs,
2753 const TCollection_AsciiString& theName,
2754 const ViewerTest_BndAction theAction)
2758 case BndAction_Hide:
2760 thePrs->Presentation()->GraphicUnHighlight();
2763 case BndAction_Show:
2765 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2766 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2767 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2768 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2769 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
2772 case BndAction_Print:
2774 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2775 gp_Pnt aMin = aBox.CornerMin();
2776 gp_Pnt aMax = aBox.CornerMax();
2777 theDI << theName << "\n"
2778 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2779 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
2785 //==============================================================================
2786 //function : VBounding
2788 //==============================================================================
2789 int VBounding (Draw_Interpretor& theDI,
2790 Standard_Integer theArgNb,
2791 const char** theArgVec)
2793 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2794 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2797 std::cout << "Error: no active view!\n";
2801 ViewerTest_BndAction anAction = BndAction_Show;
2802 Standard_Integer aMode = -1;
2804 Standard_Integer anArgIter = 1;
2805 for (; anArgIter < theArgNb; ++anArgIter)
2807 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2809 if (anArg == "-print")
2811 anAction = BndAction_Print;
2813 else if (anArg == "-show")
2815 anAction = BndAction_Show;
2817 else if (anArg == "-hide")
2819 anAction = BndAction_Hide;
2821 else if (anArg == "-mode")
2823 if (++anArgIter >= theArgNb)
2825 std::cout << "Error: wrong syntax at " << anArg << "\n";
2828 aMode = Draw::Atoi (theArgVec[anArgIter]);
2830 else if (!anUpdateTool.parseRedrawMode (anArg))
2836 if (anArgIter < theArgNb)
2838 // has a list of names
2839 for (; anArgIter < theArgNb; ++anArgIter)
2841 TCollection_AsciiString aName = theArgVec[anArgIter];
2842 if (!GetMapOfAIS().IsBound2 (aName))
2844 std::cout << "Error: presentation " << aName << " does not exist\n";
2848 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2849 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2852 std::cout << "Error: presentation " << aName << " does not exist\n";
2855 bndPresentation (theDI, aPrs, aName, anAction);
2858 else if (aCtx->NbCurrents() > 0)
2860 // remove all currently selected objects
2861 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2863 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2864 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2867 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2874 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2875 anIter.More(); anIter.Next())
2877 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2878 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2881 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2888 //==============================================================================
2889 //function : VTexture
2891 //==============================================================================
2892 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2894 TCollection_AsciiString aCommandName (theArgv[0]);
2896 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2897 if (aCommandName == "vtexture")
2901 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2902 std::cout << "Type help for more information.\n";
2906 // look for options of vtexture command
2907 TCollection_AsciiString aParseKey;
2908 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2910 TCollection_AsciiString anArg (theArgv [anArgIt]);
2913 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2916 aParseKey.Remove (1);
2917 aParseKey.UpperCase();
2918 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2922 if (aParseKey.IsEmpty())
2927 aMapOfArgs(aParseKey)->Append (anArg);
2930 else if (aCommandName == "vtexscale"
2931 || aCommandName == "vtexorigin"
2932 || aCommandName == "vtexrepeat")
2934 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2935 // equal to -scale, -origin, -repeat options of vtexture command
2936 if (theArgsNb < 2 || theArgsNb > 4)
2938 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2939 std::cout << "Type help for more information.\n";
2943 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2946 anArgs->Append ("OFF");
2948 else if (theArgsNb == 4)
2950 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2951 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2954 TCollection_AsciiString anArgKey;
2955 if (aCommandName == "vtexscale")
2959 else if (aCommandName == "vtexorigin")
2961 anArgKey = "ORIGIN";
2965 anArgKey = "REPEAT";
2968 aMapOfArgs.Bind (anArgKey, anArgs);
2970 else if (aCommandName == "vtexdefault")
2972 // scan for parameters of vtexdefault command
2973 // equal to -default option of vtexture command
2974 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2977 // Check arguments for validity
2978 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2979 for (; aMapIt.More(); aMapIt.Next())
2981 const TCollection_AsciiString& aKey = aMapIt.Key();
2982 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2984 // -scale, -origin, -repeat: one argument "off", or two real values
2985 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2986 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2987 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2992 // -modulate: single argument "on" / "off"
2993 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2998 // -default: no arguments
2999 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
3004 TCollection_AsciiString aLowerKey;
3007 aLowerKey.LowerCase();
3008 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3009 std::cout << "Type help for more information.\n";
3013 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3014 if (anAISContext.IsNull())
3016 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3020 Standard_Integer aPreviousMode = 0;
3022 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3024 TCollection_AsciiString aShapeName (theArgv[1]);
3025 Handle(AIS_InteractiveObject) anIO;
3027 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3028 if (aMapOfIO.IsBound2 (aShapeName))
3030 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3035 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3039 Handle(AIS_TexturedShape) aTexturedIO;
3040 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3042 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3043 aPreviousMode = aTexturedIO->DisplayMode();
3047 anAISContext->Remove (anIO, Standard_False);
3048 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3049 GetMapOfAIS().UnBind1 (anIO);
3050 GetMapOfAIS().UnBind2 (aShapeName);
3051 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3054 // -------------------------------------------
3055 // Turn texturing on/off - only for vtexture
3056 // -------------------------------------------
3058 if (aCommandName == "vtexture")
3060 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3062 if (aTextureArg.IsEmpty())
3064 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3065 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3067 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3068 if (aPreviousMode == 3)
3070 anAISContext->RecomputePrsOnly (aTexturedIO);
3073 anAISContext->Display (aTexturedIO, Standard_True);
3076 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
3078 if (aTextureArg == "?")
3080 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
3082 theDi << "\n Files in current directory : \n" << "\n";
3083 theDi.Eval ("glob -nocomplain *");
3085 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3086 aCmnd += aTextureFolder;
3089 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3090 theDi.Eval (aCmnd.ToCString());
3095 aTexturedIO->SetTextureFileName (aTextureArg);
3100 // ------------------------------------
3101 // Process other options and commands
3102 // ------------------------------------
3104 Handle(TColStd_HSequenceOfAsciiString) aValues;
3105 if (aMapOfArgs.Find ("DEFAULT", aValues))
3107 aTexturedIO->SetTextureRepeat (Standard_False);
3108 aTexturedIO->SetTextureOrigin (Standard_False);
3109 aTexturedIO->SetTextureScale (Standard_False);
3110 aTexturedIO->EnableTextureModulate();
3114 if (aMapOfArgs.Find ("SCALE", aValues))
3116 if (aValues->Value(1) != "OFF")
3118 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3122 aTexturedIO->SetTextureScale (Standard_False);
3126 if (aMapOfArgs.Find ("ORIGIN", aValues))
3128 if (aValues->Value(1) != "OFF")
3130 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3134 aTexturedIO->SetTextureOrigin (Standard_False);
3138 if (aMapOfArgs.Find ("REPEAT", aValues))
3140 if (aValues->Value(1) != "OFF")
3142 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
3146 aTexturedIO->SetTextureRepeat (Standard_False);
3150 if (aMapOfArgs.Find ("MODULATE", aValues))
3152 if (aValues->Value(1) == "ON")
3154 aTexturedIO->EnableTextureModulate();
3158 aTexturedIO->DisableTextureModulate();
3163 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3165 anAISContext->RecomputePrsOnly (aTexturedIO);
3169 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3170 anAISContext->Display (aTexturedIO, Standard_True);
3171 anAISContext->Update (aTexturedIO,Standard_True);
3177 //! Auxiliary method to parse transformation persistence flags
3178 inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3179 Standard_Integer& theFlags)
3181 if (theFlagString == "pan")
3183 theFlags |= Graphic3d_TMF_PanPers;
3185 else if (theFlagString == "zoom")
3187 theFlags |= Graphic3d_TMF_ZoomPers;
3189 else if (theFlagString == "rotate")
3191 theFlags |= Graphic3d_TMF_RotatePers;
3193 else if (theFlagString == "trihedron")
3195 theFlags = Graphic3d_TMF_TriedronPers;
3197 else if (theFlagString == "full")
3199 theFlags = Graphic3d_TMF_FullPers;
3201 else if (theFlagString == "none")
3203 theFlags = Graphic3d_TMF_None;
3207 return Standard_False;
3210 return Standard_True;
3213 //==============================================================================
3214 //function : VDisplay2
3216 //purpose : Display an object from its name
3217 //==============================================================================
3218 static int VDisplay2 (Draw_Interpretor& theDI,
3219 Standard_Integer theArgNb,
3220 const char** theArgVec)
3224 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3228 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3231 ViewerTest::ViewerInit();
3232 aCtx = ViewerTest::GetAISContext();
3235 // Parse input arguments
3236 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
3237 Standard_Integer isMutable = -1;
3238 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3239 Standard_Boolean toDisplayLocal = Standard_False;
3240 Standard_Boolean toReDisplay = Standard_False;
3241 Standard_Integer isSelectable = -1;
3242 Standard_Integer anObjDispMode = -2;
3243 Standard_Integer anObjHighMode = -2;
3244 Standard_Boolean toSetTrsfPers = Standard_False;
3245 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3247 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
3248 AIS_DisplayStatus aDispStatus = AIS_DS_None;
3249 Standard_Integer toDisplayInView = Standard_False;
3250 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3252 const TCollection_AsciiString aName = theArgVec[anArgIter];
3253 TCollection_AsciiString aNameCase = aName;
3254 aNameCase.LowerCase();
3255 if (anUpdateTool.parseRedrawMode (aName))
3259 else if (aNameCase == "-mutable")
3263 else if (aNameCase == "-neutral")
3265 aDispStatus = AIS_DS_Displayed;
3267 else if (aNameCase == "-immediate"
3268 || aNameCase == "-top")
3270 aZLayer = Graphic3d_ZLayerId_Top;
3272 else if (aNameCase == "-topmost")
3274 aZLayer = Graphic3d_ZLayerId_Topmost;
3276 else if (aNameCase == "-osd"
3277 || aNameCase == "-toposd"
3278 || aNameCase == "-overlay")
3280 aZLayer = Graphic3d_ZLayerId_TopOSD;
3282 else if (aNameCase == "-botosd"
3283 || aNameCase == "-underlay")
3285 aZLayer = Graphic3d_ZLayerId_BotOSD;
3287 else if (aNameCase == "-select"
3288 || aNameCase == "-selectable")
3292 else if (aNameCase == "-noselect"
3293 || aNameCase == "-noselection")
3297 else if (aNameCase == "-dispmode"
3298 || aNameCase == "-displaymode")
3300 if (++anArgIter >= theArgNb)
3302 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3306 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3308 else if (aNameCase == "-highmode"
3309 || aNameCase == "-highlightmode")
3311 if (++anArgIter >= theArgNb)
3313 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3317 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3319 else if (aNameCase == "-3d")
3321 toSetTrsfPers = Standard_True;
3322 aTrsfPersFlags = Graphic3d_TMF_None;
3324 else if (aNameCase == "-2d")
3326 toSetTrsfPers = Standard_True;
3327 aTrsfPersFlags = Graphic3d_TMF_2d;
3329 else if (aNameCase == "-2dtopdown")
3331 toSetTrsfPers = Standard_True;
3332 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3334 else if (aNameCase == "-trsfpers"
3335 || aNameCase == "-pers")
3337 if (++anArgIter >= theArgNb)
3339 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3343 toSetTrsfPers = Standard_True;
3344 aTrsfPersFlags = Graphic3d_TMF_None;
3345 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3346 aPersFlags.LowerCase();
3347 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3349 if (aParserPos == -1)
3351 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3353 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3359 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3360 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3362 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3365 aPersFlags = anOtherFlags;
3368 else if (aNameCase == "-trsfperspos"
3369 || aNameCase == "-perspos")
3371 if (anArgIter + 2 >= theArgNb)
3373 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3377 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3378 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3379 TCollection_AsciiString aZ = "0";
3380 if (!aX.IsIntegerValue()
3381 || !aY.IsIntegerValue())
3383 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3386 if (anArgIter + 1 < theArgNb)
3388 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3389 if (aTemp.IsIntegerValue())
3395 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3397 else if (aNameCase == "-layer")
3399 if (++anArgIter >= theArgNb)
3401 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3405 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3406 if (!aValue.IsIntegerValue())
3408 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3412 aZLayer = aValue.IntegerValue();
3414 else if (aNameCase == "-view"
3415 || aNameCase == "-inview")
3417 toDisplayInView = Standard_True;
3419 else if (aNameCase == "-local")
3421 aDispStatus = AIS_DS_Temporary;
3422 toDisplayLocal = Standard_True;
3424 else if (aNameCase == "-redisplay")
3426 toReDisplay = Standard_True;
3430 aNamesOfDisplayIO.Append (aName);
3434 if (aNamesOfDisplayIO.IsEmpty())
3436 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3440 // Prepare context for display
3441 if (toDisplayLocal && !aCtx->HasOpenedContext())
3443 aCtx->OpenLocalContext (Standard_False);
3445 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3447 aCtx->CloseAllContexts (Standard_False);
3450 // Display interactive objects
3451 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3453 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3455 if (!GetMapOfAIS().IsBound2 (aName))
3457 // create the AIS_Shape from a name
3458 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3459 if (!aShape.IsNull())
3461 if (isMutable != -1)
3463 aShape->SetMutable (isMutable == 1);
3465 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3467 aShape->SetZLayer (aZLayer);
3471 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3473 if (anObjDispMode != -2)
3475 aShape->SetDisplayMode (anObjDispMode);
3477 if (anObjHighMode != -2)
3479 aShape->SetHilightMode (anObjHighMode);
3481 if (!toDisplayLocal)
3482 GetMapOfAIS().Bind (aShape, aName);
3484 Standard_Integer aDispMode = aShape->HasDisplayMode()
3485 ? aShape->DisplayMode()
3486 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3487 ? aCtx->DisplayMode()
3489 Standard_Integer aSelMode = -1;
3490 if ( isSelectable == 1
3491 || (isSelectable == -1
3492 && aCtx->GetAutoActivateSelection()
3493 && aShape->GetTransformPersistenceMode() == 0))
3495 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3498 aCtx->Display (aShape, aDispMode, aSelMode,
3499 Standard_False, aShape->AcceptShapeDecomposition(),
3501 if (toDisplayInView)
3503 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3505 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3507 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3512 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3517 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
3518 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
3520 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
3521 if (isMutable != -1)
3523 aShape->SetMutable (isMutable == 1);
3525 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3527 aShape->SetZLayer (aZLayer);
3531 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3533 if (anObjDispMode != -2)
3535 aShape->SetDisplayMode (anObjDispMode);
3537 if (anObjHighMode != -2)
3539 aShape->SetHilightMode (anObjHighMode);
3541 Standard_Integer aDispMode = aShape->HasDisplayMode()
3542 ? aShape->DisplayMode()
3543 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3544 ? aCtx->DisplayMode()
3546 Standard_Integer aSelMode = -1;
3547 if ( isSelectable == 1
3548 || (isSelectable == -1
3549 && aCtx->GetAutoActivateSelection()
3550 && aShape->GetTransformPersistenceMode() == 0))
3552 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3555 if (aShape->Type() == AIS_KOI_Datum)
3557 aCtx->Display (aShape, Standard_False);
3561 theDI << "Display " << aName.ToCString() << "\n";
3563 // update the Shape in the AIS_Shape
3564 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3565 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3566 if (!aShapePrs.IsNull())
3568 if (!aShapePrs->Shape().IsEqual (aNewShape))
3570 toReDisplay = Standard_True;
3572 aShapePrs->Set (aNewShape);
3576 aCtx->Redisplay (aShape, Standard_False);
3581 aCtx->Erase (aShape);
3583 aCtx->Display (aShape, aDispMode, aSelMode,
3584 Standard_False, aShape->AcceptShapeDecomposition(),
3586 if (toDisplayInView)
3588 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3592 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
3594 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
3595 TheNISContext()->Display (aShape);
3602 //===============================================================================================
3603 //function : VUpdate
3605 //===============================================================================================
3606 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3608 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3609 if (aContextAIS.IsNull())
3611 std::cout << theArgVec[0] << "AIS context is not available.\n";
3617 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3621 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3623 AIS_ListOfInteractive aListOfIO;
3625 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3627 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3629 Handle(AIS_InteractiveObject) anAISObj;
3630 if (anAISMap.IsBound2 (aName))
3632 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3635 if (anAISObj.IsNull())
3637 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3641 aListOfIO.Append (anAISObj);
3644 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3645 for (; anIOIt.More(); anIOIt.Next())
3647 aContextAIS->Update (anIOIt.Value(), Standard_False);
3650 aContextAIS->UpdateCurrentViewer();
3655 //==============================================================================
3657 //purpose : Test the annimation of an object along a
3658 // predifined trajectory
3659 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3660 //==============================================================================
3662 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3665 if (TheAISContext()->HasOpenedContext())
3666 TheAISContext()->CloseLocalContext();
3668 Standard_Real Step=4*M_PI/180;
3669 Standard_Real Angle=0;
3671 Handle(AIS_InteractiveObject) aIO;
3672 if (GetMapOfAIS().IsBound2(argv[1]))
3673 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3677 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3681 if (Draw::Atoi(argv[3])==1 ) {
3682 di<<" Primitives sensibles OFF"<<"\n";
3683 TheAISContext()->Deactivate(aIO);
3686 di<<" Primitives sensibles ON"<<"\n";
3688 // Movement par transformation
3689 if(Draw::Atoi(argv[2]) ==1) {
3690 di<<" Calcul par Transformation"<<"\n";
3691 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3695 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3696 TheAISContext()->SetLocation(aShape,myTransfo);
3697 TheAISContext() ->UpdateCurrentViewer();
3702 di<<" Calcul par Locations"<<"\n";
3703 gp_Trsf myAngleTrsf;
3704 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3705 TopLoc_Location myDeltaAngle (myAngleTrsf);
3706 TopLoc_Location myTrueLoc;
3708 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
3711 myTrueLoc=myTrueLoc*myDeltaAngle;
3712 TheAISContext()->SetLocation(aShape,myTrueLoc );
3713 TheAISContext() ->UpdateCurrentViewer();
3716 if (Draw::Atoi(argv[3])==1 ){
3717 // On reactive la selection des primitives sensibles
3718 TheAISContext()->Activate(aIO,0);
3720 a3DView() -> Redraw();
3722 di<<" Temps ecoule "<<"\n";
3728 //==================================================================================
3729 // Function : VAnimation
3730 //==================================================================================
3731 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
3733 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3737 Standard_Real thread = 4;
3738 Standard_Real angleA=0;
3739 Standard_Real angleB;
3741 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3744 TopoDS_Shape CrankArm;
3745 TopoDS_Shape CylinderHead;
3746 TopoDS_Shape Propeller;
3747 TopoDS_Shape EngineBlock;
3749 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3750 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3751 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3752 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3753 BRepTools::Read(CrankArm,argv[1],B);
3754 BRepTools::Read(CylinderHead,argv[2],B);
3755 BRepTools::Read(Propeller,argv[3],B);
3756 BRepTools::Read(EngineBlock,argv[4],B);
3758 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3764 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3765 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3766 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3767 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3769 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3770 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3771 GetMapOfAIS().Bind(myAisCrankArm,"c");
3772 GetMapOfAIS().Bind(myAisPropeller,"d");
3774 myAisCylinderHead->SetMutable (Standard_True);
3775 myAisEngineBlock ->SetMutable (Standard_True);
3776 myAisCrankArm ->SetMutable (Standard_True);
3777 myAisPropeller ->SetMutable (Standard_True);
3779 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3780 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3781 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3783 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3784 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3785 TheAISContext()->Display (myAisCrankArm, Standard_False);
3786 TheAISContext()->Display (myAisPropeller, Standard_False);
3788 TheAISContext()->Deactivate(myAisCylinderHead);
3789 TheAISContext()->Deactivate(myAisEngineBlock );
3790 TheAISContext()->Deactivate(myAisCrankArm );
3791 TheAISContext()->Deactivate(myAisPropeller );
3793 // Boucle de mouvement
3794 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3796 angleA = thread*myAngle*M_PI/180;
3797 X = Sin(angleA)*3/8;
3798 angleB = atan(X / Sqrt(-X * X + 1));
3799 Standard_Real decal(25*0.6);
3802 //Build a transformation on the display
3803 gp_Trsf aPropellerTrsf;
3804 aPropellerTrsf.SetRotation(Ax1,angleA);
3805 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3807 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));
3808 gp_Trsf aCrankArmTrsf;
3809 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3810 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3812 TheAISContext()->UpdateCurrentViewer();
3815 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3816 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3818 myAisCrankArm ->ResetTransformation();
3819 myAisPropeller->ResetTransformation();
3821 myAisCrankArm -> Set(myNewCrankArm );
3822 myAisPropeller -> Set(myNewPropeller);
3824 TheAISContext()->Activate(myAisCylinderHead,0);
3825 TheAISContext()->Activate(myAisEngineBlock,0 );
3826 TheAISContext()->Activate(myAisCrankArm ,0 );
3827 TheAISContext()->Activate(myAisPropeller ,0 );
3833 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3834 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3836 TheAISContext()->UpdateCurrentViewer();
3837 a3DView()->Redraw();
3846 //==============================================================================
3847 //function : VShading
3848 //purpose : Sharpen or roughten the quality of the shading
3849 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3850 //==============================================================================
3851 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3853 Standard_Real myDevCoef;
3854 Handle(AIS_InteractiveObject) TheAisIO;
3857 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3859 if (TheAISContext()->HasOpenedContext())
3860 TheAISContext()->CloseLocalContext();
3865 myDevCoef =Draw::Atof(argv[2]);
3868 TCollection_AsciiString name=argv[1];
3869 if (GetMapOfAIS().IsBound2(name ))
3870 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3871 if (TheAisIO.IsNull())
3872 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3875 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3877 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3879 TheAISContext()->Redisplay(TheAisIO);
3882 //==============================================================================
3883 //function : HaveMode
3884 //use : VActivatedModes
3885 //==============================================================================
3886 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3888 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3890 TColStd_ListOfInteger List;
3891 TheAISContext()->ActivatedModes (TheAisIO,List);
3892 TColStd_ListIteratorOfListOfInteger it;
3893 Standard_Boolean Found=Standard_False;
3894 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3895 if (it.Value()==mode ) Found=Standard_True;
3902 //==============================================================================
3903 //function : VActivatedMode
3905 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3906 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3907 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3908 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3909 // qu'un nom et qu'un mode.
3910 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3911 //==============================================================================
3912 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3914 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3917 Standard_Boolean ThereIsName = Standard_False ;
3919 if(!a3DView().IsNull()){
3921 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3922 // verification des arguments
3924 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3925 ThereIsName = (argc == 3);
3929 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3931 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3932 di<<" Fermeture du Context local"<<"\n";
3933 if (TheAISContext()->HasOpenedContext())
3934 TheAISContext()->CloseLocalContext();
3938 // IL n'y a aps de nom de shape passe en argument
3939 if (HaveToSet && !ThereIsName){
3940 Standard_Integer aMode=Draw::Atoi(argv [1]);
3942 const char *cmode="???";
3944 case 0: cmode = "Shape"; break;
3945 case 1: cmode = "Vertex"; break;
3946 case 2: cmode = "Edge"; break;
3947 case 3: cmode = "Wire"; break;
3948 case 4: cmode = "Face"; break;
3949 case 5: cmode = "Shell"; break;
3950 case 6: cmode = "Solid"; break;
3951 case 7: cmode = "Compound"; break;
3954 if( !TheAISContext()->HasOpenedContext() ) {
3955 // il n'y a pas de Context local d'ouvert
3956 // on en ouvre un et on charge toutes les shapes displayees
3957 // on load tous les objets displayees et on Activate les objets de la liste
3958 AIS_ListOfInteractive ListOfIO;
3959 // on sauve dans une AISListOfInteractive tous les objets currents
3960 if (TheAISContext()->NbCurrents()>0 ){
3961 TheAISContext()->UnhilightCurrents(Standard_False);
3963 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3964 ListOfIO.Append(TheAISContext()->Current() );
3968 TheAISContext()->OpenLocalContext(Standard_False);
3969 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3972 Handle(AIS_InteractiveObject) aIO =
3973 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3975 TheAISContext()->Load(aIO,0,Standard_False);
3978 // traitement des objets qui etaient currents dans le Contexte global
3979 if (!ListOfIO.IsEmpty() ) {
3980 // il y avait des objets currents
3981 AIS_ListIteratorOfListOfInteractive iter;
3982 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3983 Handle(AIS_InteractiveObject) aIO=iter.Value();
3984 TheAISContext()->Activate(aIO,aMode);
3985 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3989 // On applique le mode a tous les objets displayes
3990 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3991 it2 (GetMapOfAIS());
3993 Handle(AIS_InteractiveObject) aIO =
3994 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3995 if (!aIO.IsNull()) {
3996 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3997 TheAISContext()->Activate(aIO,aMode);
4006 // un Context local est deja ouvert
4007 // Traitement des objets du Context local
4008 if (TheAISContext()->NbSelected()>0 ){
4009 TheAISContext()->UnhilightSelected(Standard_False);
4010 // il y a des objets selected,on les parcourt
4011 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4012 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
4015 if (HaveMode(aIO,aMode) ) {
4016 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4017 TheAISContext()->Deactivate(aIO,aMode);
4020 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4021 TheAISContext()->Activate(aIO,aMode);
4027 // il n'y a pas d'objets selected
4028 // tous les objets diplayes sont traites
4029 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4032 Handle(AIS_InteractiveObject) aIO =
4033 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4034 if (!aIO.IsNull()) {
4035 if (HaveMode(aIO,aMode) ) {
4036 di<<" Mode: "<<cmode<<" OFF pour "
4037 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4038 TheAISContext()->Deactivate(aIO,aMode);
4041 di<<" Mode: "<<cmode<<" ON pour"
4042 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4043 TheAISContext()->Activate(aIO,aMode);
4051 else if (HaveToSet && ThereIsName){
4052 Standard_Integer aMode=Draw::Atoi(argv [2]);
4053 Handle(AIS_InteractiveObject) aIO =
4054 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4056 if (!aIO.IsNull()) {
4057 const char *cmode="???";
4060 case 0: cmode = "Shape"; break;
4061 case 1: cmode = "Vertex"; break;
4062 case 2: cmode = "Edge"; break;
4063 case 3: cmode = "Wire"; break;
4064 case 4: cmode = "Face"; break;
4065 case 5: cmode = "Shell"; break;
4066 case 6: cmode = "Solid"; break;
4067 case 7: cmode = "Compound"; break;
4070 if( !TheAISContext()->HasOpenedContext() ) {
4071 TheAISContext()->OpenLocalContext(Standard_False);
4072 // On charge tous les objets de la map
4073 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4075 Handle(AIS_InteractiveObject) aShape=
4076 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4077 if (!aShape.IsNull())
4078 TheAISContext()->Load(aShape,0,Standard_False);
4081 TheAISContext()->Activate(aIO,aMode);
4082 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4086 // un Context local est deja ouvert
4087 if (HaveMode(aIO,aMode) ) {
4088 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4089 TheAISContext()->Deactivate(aIO,aMode);
4092 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4093 TheAISContext()->Activate(aIO,aMode);
4102 //! Auxiliary method to print Interactive Object information
4103 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4104 const Handle(Standard_Transient)& theObject,
4105 Draw_Interpretor& theDI)
4107 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4110 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4114 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4115 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4116 << (theDetected.Contains (anObj) ? " Detected" : " ")
4118 if (anObj->Type() == AIS_KOI_Datum)
4121 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4122 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4123 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4124 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4125 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4126 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4127 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
4130 else if (anObj->Type() == AIS_KOI_Shape
4131 && anObj->Signature() == 0)
4133 theDI << " AIS_Shape";
4135 else if (anObj->Type() == AIS_KOI_Relation)
4137 // AIS_Dimention and AIS_Relation
4138 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4139 switch (aRelation->KindOfDimension())
4141 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4142 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4143 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4144 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4145 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4146 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4147 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4148 default: theDI << " UNKNOWN dimension"; break;
4153 theDI << " UserPrs";
4155 theDI << " (" << theObject->DynamicType()->Name() << ")";
4158 //! Print information about locally selected sub-shapes
4159 static void localCtxInfo (Draw_Interpretor& theDI)
4161 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4162 if (!aCtx->HasOpenedContext())
4167 TCollection_AsciiString aPrevName;
4168 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
4169 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
4171 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
4172 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
4173 if (aSubShape.IsNull()
4174 || aShapeIO.IsNull()
4175 || !GetMapOfAIS().IsBound1 (aShapeIO))
4180 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4181 TopTools_MapOfShape aFilter;
4182 Standard_Integer aNumber = 0;
4183 const TopoDS_Shape aShape = aShapeIO->Shape();
4184 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4185 anIter.More(); anIter.Next())
4187 if (!aFilter.Add (anIter.Current()))
4189 continue; // filter duplicates
4193 if (!anIter.Current().IsSame (aSubShape))
4198 Standard_CString aShapeName = NULL;
4199 switch (aSubShape.ShapeType())
4201 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4202 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4203 case TopAbs_SOLID: aShapeName = " Solid"; break;
4204 case TopAbs_SHELL: aShapeName = " Shell"; break;
4205 case TopAbs_FACE: aShapeName = " Face"; break;
4206 case TopAbs_WIRE: aShapeName = " Wire"; break;
4207 case TopAbs_EDGE: aShapeName = " Edge"; break;
4208 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4210 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4213 if (aParentName != aPrevName)
4215 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4216 aPrevName = aParentName;
4218 theDI << " " << aShapeName << " #" << aNumber << "\n";
4224 //==============================================================================
4227 //==============================================================================
4228 static Standard_Integer VState (Draw_Interpretor& theDI,
4229 Standard_Integer theArgNb,
4230 Standard_CString* theArgVec)
4232 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4235 std::cerr << "Error: No opened viewer!\n";
4239 Standard_Boolean toPrintEntities = Standard_False;
4240 Standard_Boolean toCheckSelected = Standard_False;
4242 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4244 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4245 anOption.LowerCase();
4246 if (anOption == "-detectedentities"
4247 || anOption == "-entities")
4249 toPrintEntities = Standard_True;
4251 else if (anOption == "-hasselected")
4253 toCheckSelected = Standard_True;
4257 if (toCheckSelected)
4259 aCtx->InitSelected();
4260 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4261 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4266 if (toPrintEntities)
4268 theDI << "Detected entities:\n";
4269 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
4270 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
4272 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
4273 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4274 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4275 SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
4276 : aSelector->GetManager();
4277 SelectBasics_PickResult aResult;
4278 anEntity->Matches (aMgr, aResult);
4279 NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
4281 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4282 aName.LeftJustify (20, ' ');
4283 char anInfoStr[512];
4285 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4287 aResult.DistToGeomCenter(),
4288 aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
4289 theDI << " " << aName
4291 << " (" << anEntity->DynamicType()->Name() << ")"
4294 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4295 if (!aBRepOwner.IsNull())
4297 theDI << " Detected Shape: "
4298 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4302 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4303 if (!aWire.IsNull())
4305 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4306 theDI << " Detected Child: "
4307 << aSen->DynamicType()->Name()
4314 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4315 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4317 aDetected.Add (aCtx->DetectedCurrentObject());
4320 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4324 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4326 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4327 if (!GetMapOfAIS().IsBound2 (anObjName))
4329 theDI << anObjName << " doesn't exist!\n";
4333 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4334 TCollection_AsciiString aName = anObjName;
4335 aName.LeftJustify (20, ' ');
4336 theDI << " " << aName << " ";
4337 objInfo (aDetected, anObjTrans, theDI);
4343 if (aCtx->NbCurrents() > 0
4346 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
4348 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
4349 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4350 aName.LeftJustify (20, ' ');
4351 theDI << aName << " ";
4352 objInfo (aDetected, anObj, theDI);
4358 theDI << "Neutral-point state:\n";
4359 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4360 anObjIter.More(); anObjIter.Next())
4362 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4368 TCollection_AsciiString aName = anObjIter.Key2();
4369 aName.LeftJustify (20, ' ');
4370 theDI << " " << aName << " ";
4371 objInfo (aDetected, anObj, theDI);
4374 localCtxInfo (theDI);
4378 //=======================================================================
4379 //function : PickObjects
4381 //=======================================================================
4382 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4383 const AIS_KindOfInteractive TheType,
4384 const Standard_Integer TheSignature,
4385 const Standard_Integer MaxPick)
4387 Handle(AIS_InteractiveObject) IO;
4388 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4390 // step 1: prepare the data
4392 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4393 TheAISContext()->AddFilter(F1);
4396 // step 2 : wait for the selection...
4397 // Standard_Boolean IsGood (Standard_False);
4398 // Standard_Integer NbPick(0);
4399 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4400 Standard_Integer NbPickFail(0);
4401 Standard_Integer argccc = 5;
4402 const char *bufff[] = { "A", "B", "C","D", "E" };
4403 const char **argvvv = (const char **) bufff;
4406 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4407 while(ViewerMainLoop(argccc,argvvv)){}
4408 Standard_Integer NbStored = TheAISContext()->NbSelected();
4409 if((unsigned int ) NbStored != NbPickGood)
4410 NbPickGood= NbStored;
4413 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4416 // step3 get result.
4418 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4420 Standard_Integer i(0);
4421 for(TheAISContext()->InitSelected();
4422 TheAISContext()->MoreSelected();
4423 TheAISContext()->NextSelected()){
4425 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4426 arr->SetValue(i,IO2);
4431 TheAISContext()->CloseLocalContext(curindex);
4433 return Standard_True;
4437 //=======================================================================
4438 //function : PickObject
4440 //=======================================================================
4441 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4442 const Standard_Integer TheSignature,
4443 const Standard_Integer MaxPick)
4445 Handle(AIS_InteractiveObject) IO;
4446 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4448 // step 1: prepare the data
4451 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4452 TheAISContext()->AddFilter(F1);
4455 // step 2 : wait for the selection...
4456 Standard_Boolean IsGood (Standard_False);
4457 Standard_Integer NbPick(0);
4458 Standard_Integer argccc = 5;
4459 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4460 const char **argvvv = (const char **) bufff;
4463 while(!IsGood && NbPick<= MaxPick){
4464 while(ViewerMainLoop(argccc,argvvv)){}
4465 IsGood = (TheAISContext()->NbSelected()>0) ;
4467 cout<<"Nb Pick :"<<NbPick<<endl;
4471 // step3 get result.
4473 TheAISContext()->InitSelected();
4474 IO = TheAISContext()->SelectedInteractive();
4478 TheAISContext()->CloseLocalContext(curindex);
4482 //=======================================================================
4483 //function : PickShape
4484 //purpose : First Activate the rightmode + Put Filters to be able to
4485 // pick objets that are of type <TheType>...
4486 //=======================================================================
4488 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4489 const Standard_Integer MaxPick)
4492 // step 1: prepare the data
4494 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4495 TopoDS_Shape result;
4497 if(TheType==TopAbs_SHAPE){
4498 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4499 TheAISContext()->AddFilter(F1);
4502 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4503 TheAISContext()->AddFilter(TF);
4504 TheAISContext()->ActivateStandardMode(TheType);
4509 // step 2 : wait for the selection...
4510 Standard_Boolean NoShape (Standard_True);
4511 Standard_Integer NbPick(0);
4512 Standard_Integer argccc = 5;
4513 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4514 const char **argvvv = (const char **) bufff;
4517 while(NoShape && NbPick<= MaxPick){
4518 while(ViewerMainLoop(argccc,argvvv)){}
4519 NoShape = (TheAISContext()->NbSelected()==0) ;
4521 cout<<"Nb Pick :"<<NbPick<<endl;
4524 // step3 get result.
4528 TheAISContext()->InitSelected();
4529 if(TheAISContext()->HasSelectedShape())
4530 result = TheAISContext()->SelectedShape();
4532 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4533 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
4538 TheAISContext()->CloseLocalContext(curindex);
4544 //=======================================================================
4545 //function : PickShapes
4547 //=======================================================================
4548 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4549 Handle(TopTools_HArray1OfShape)& thearr,
4550 const Standard_Integer MaxPick)
4553 Standard_Integer Taille = thearr->Length();
4555 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4557 // step 1: prepare the data
4558 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4559 if(TheType==TopAbs_SHAPE){
4560 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4561 TheAISContext()->AddFilter(F1);
4564 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4565 TheAISContext()->AddFilter(TF);
4566 TheAISContext()->ActivateStandardMode(TheType);
4570 // step 2 : wait for the selection...
4572 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4573 Standard_Integer NbPickFail(0);
4574 Standard_Integer argccc = 5;
4575 const char *bufff[] = { "A", "B", "C","D", "E" };
4576 const char **argvvv = (const char **) bufff;
4579 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4580 while(ViewerMainLoop(argccc,argvvv)){}
4581 Standard_Integer NbStored = TheAISContext()->NbSelected();
4582 if((unsigned int ) NbStored != NbPickGood)
4583 NbPickGood= NbStored;
4586 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4589 // step3 get result.
4591 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4593 Standard_Integer i(0);
4594 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4596 if(TheAISContext()->HasSelectedShape())
4597 thearr->SetValue(i,TheAISContext()->SelectedShape());
4599 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4600 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
4604 TheAISContext()->CloseLocalContext(curindex);
4605 return Standard_True;
4609 //=======================================================================
4610 //function : VPickShape
4612 //=======================================================================
4613 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4615 TopoDS_Shape PickSh;
4616 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4619 theType = TopAbs_SHAPE;
4621 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4622 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4623 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4624 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4625 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4626 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4627 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4630 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4631 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4633 TCollection_AsciiString name;
4636 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4638 PickSh = ViewerTest::PickShape(theType);
4647 if(!PickSh.IsNull()){
4648 nbOfSub[Standard_Integer(theType)]++;
4650 name += nameType[Standard_Integer(theType)];
4651 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4656 // si on avait une petite methode pour voir si la shape
4657 // est deja dans la Double map, ca eviterait de creer....
4658 DBRep::Set(name.ToCString(),PickSh);
4660 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4661 GetMapOfAIS().Bind(newsh, name);
4662 TheAISContext()->Display(newsh);
4663 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4666 // Plusieurs objets a picker, vite vite vite....
4669 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4670 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4671 if(ViewerTest::PickShapes(theType,arr)){
4672 for(Standard_Integer i=1;i<=NbToPick;i++){
4673 PickSh = arr->Value(i);
4674 if(!PickSh.IsNull()){
4676 nbOfSub[Standard_Integer(theType)]++;
4679 name += nameType[Standard_Integer(theType)];
4680 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4688 DBRep::Set(name.ToCString(),PickSh);
4689 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4690 GetMapOfAIS().Bind(newsh, name);
4691 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4692 TheAISContext()->Display(newsh);
4700 //=======================================================================
4701 //function : VPickSelected
4703 //=======================================================================
4704 static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4706 static Standard_Integer aCount = 0;
4707 TCollection_AsciiString aName = "PickedShape_";
4715 aName = aName + aCount++ + "_";
4718 Standard_Integer anIdx = 0;
4719 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4721 TopoDS_Shape aShape;
4722 if (TheAISContext()->HasSelectedShape())
4724 aShape = TheAISContext()->SelectedShape();
4728 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
4729 aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
4732 TCollection_AsciiString aCurrentName = aName;
4735 aCurrentName += anIdx;
4738 DBRep::Set ((aCurrentName).ToCString(), aShape);
4740 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4741 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4742 TheAISContext()->Display (aNewShape);
4748 //=======================================================================
4749 //function : list of known objects
4751 //=======================================================================
4752 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4754 // 1234567890 12345678901234567 123456789
4755 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4756 TCollection_AsciiString BlankLine(64,'_');
4757 Standard_Integer i ;
4759 di<<"/n"<<BlankLine.ToCString()<<"\n";
4762 Colum[i].Center(20,' ');
4764 di<<"|"<<Colum[i].ToCString();
4767 di<<BlankLine.ToCString()<<"\n";
4769 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4770 const char ** names = GetTypeNames();
4772 TCollection_AsciiString curstring;
4773 TCollection_AsciiString curcolum[3];
4776 // les objets de type Datum..
4777 curcolum[1]+="Datum";
4779 curcolum[0].Clear();
4780 curcolum[0] += names[i];
4782 curcolum[2].Clear();
4783 curcolum[2]+=TCollection_AsciiString(i+1);
4785 for(Standard_Integer j =0;j<=2;j++){
4786 curcolum[j].Center(20,' ');
4787 di<<"|"<<curcolum[j].ToCString();
4791 di<<BlankLine.ToCString()<<"\n";
4793 // les objets de type shape
4794 curcolum[1].Clear();
4795 curcolum[1]+="Shape";
4796 curcolum[1].Center(20,' ');
4799 curcolum[0].Clear();
4800 curcolum[0] += names[7+i];
4801 curcolum[2].Clear();
4802 curcolum[2]+=TCollection_AsciiString(i);
4804 for(Standard_Integer j =0;j<=2;j++){
4805 curcolum[j].Center(20,' ');
4806 di<<"|"<<curcolum[j].ToCString();
4810 di<<BlankLine.ToCString()<<"\n";
4811 // les IO de type objet...
4812 curcolum[1].Clear();
4813 curcolum[1]+="Object";
4814 curcolum[1].Center(20,' ');
4816 curcolum[0].Clear();
4817 curcolum[0] += names[10+i];
4818 curcolum[2].Clear();
4819 curcolum[2]+=TCollection_AsciiString(i);
4821 for(Standard_Integer j =0;j<=2;j++){
4822 curcolum[j].Center(20,' ');
4823 di<<"|"<<curcolum[j].ToCString();
4827 di<<BlankLine.ToCString()<<"\n";
4828 // les contraintes et dimensions.
4829 // pour l'instant on separe juste contraintes et dimensions...
4830 // plus tard, on detaillera toutes les sortes...
4831 curcolum[1].Clear();
4832 curcolum[1]+="Relation";
4833 curcolum[1].Center(20,' ');
4835 curcolum[0].Clear();
4836 curcolum[0] += names[12+i];
4837 curcolum[2].Clear();
4838 curcolum[2]+=TCollection_AsciiString(i);
4840 for(Standard_Integer j =0;j<=2;j++){
4841 curcolum[j].Center(20,' ');
4842 di<<"|"<<curcolum[j].ToCString();
4846 di<<BlankLine.ToCString()<<"\n";
4853 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4855 if(argc!=2) return 1;
4857 AIS_KindOfInteractive TheType;
4858 Standard_Integer TheSign(-1);
4859 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4862 AIS_ListOfInteractive LIO;
4864 // en attendant l'amelioration ais pour les dimensions...
4866 Standard_Integer dimension_status(-1);
4867 if(TheType==AIS_KOI_Relation){
4868 dimension_status = TheSign ==1 ? 1 : 0;
4872 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
4873 Handle(AIS_InteractiveObject) curio;
4874 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4877 if(dimension_status == -1)
4878 TheAISContext()->Erase(curio,Standard_False);
4880 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4881 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4882 (dimension_status==1 && KOD != AIS_KOD_NONE))
4883 TheAISContext()->Erase(curio,Standard_False);
4886 TheAISContext()->UpdateCurrentViewer();
4889 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4891 if(argc!=2) return 1;
4893 AIS_KindOfInteractive TheType;
4894 Standard_Integer TheSign(-1);
4895 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4897 // en attendant l'amelioration ais pour les dimensions...
4899 Standard_Integer dimension_status(-1);
4900 if(TheType==AIS_KOI_Relation){
4901 dimension_status = TheSign ==1 ? 1 : 0;
4905 AIS_ListOfInteractive LIO;
4906 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4907 Handle(AIS_InteractiveObject) curio;
4908 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4910 if(dimension_status == -1)
4911 TheAISContext()->Display(curio,Standard_False);
4913 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4914 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4915 (dimension_status==1 && KOD != AIS_KOD_NONE))
4916 TheAISContext()->Display(curio,Standard_False);
4921 TheAISContext()->UpdateCurrentViewer();
4925 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4928 BRep_Builder builder;
4930 BRepTools::Read(shape, s, builder);
4931 DBRep::Set(a[1], shape);
4932 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4933 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4938 //==============================================================================
4939 //function : VLoadSelection
4940 //purpose : Adds given objects to map of AIS and loads selection primitives for them
4941 //==============================================================================
4942 static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
4943 Standard_Integer theArgNb,
4944 const char** theArgVec)
4948 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4952 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4955 ViewerTest::ViewerInit();
4956 aCtx = ViewerTest::GetAISContext();
4959 // Parse input arguments
4960 TColStd_SequenceOfAsciiString aNamesOfIO;
4961 Standard_Boolean isLocal = Standard_False;
4962 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4964 const TCollection_AsciiString aName = theArgVec[anArgIter];
4965 TCollection_AsciiString aNameCase = aName;
4966 aNameCase.LowerCase();
4967 if (aNameCase == "-local")
4969 isLocal = Standard_True;
4973 aNamesOfIO.Append (aName);
4977 if (aNamesOfIO.IsEmpty())
4979 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
4984 if (isLocal && !aCtx->HasOpenedContext())
4986 aCtx->OpenLocalContext (Standard_False);
4988 else if (!isLocal && aCtx->HasOpenedContext())
4990 aCtx->CloseAllContexts (Standard_False);
4993 // Load selection of interactive objects
4994 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
4996 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
4998 const Handle(AIS_InteractiveObject)& aShape = GetMapOfAIS().IsBound2 (aName) ?
4999 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)) : GetAISShapeFromName (aName.ToCString());
5001 if (!aShape.IsNull())
5003 if (!GetMapOfAIS().IsBound2 (aName))
5005 GetMapOfAIS().Bind (aShape, aName);
5008 aCtx->Load (aShape, -1, Standard_False);
5009 aCtx->Activate (aShape, aShape->SelectionMode(), Standard_True);
5016 //==============================================================================
5017 //function : VAutoActivateSelection
5018 //purpose : Activates or deactivates auto computation of selection
5019 //==============================================================================
5020 static int VAutoActivateSelection (Draw_Interpretor& theDi,
5021 Standard_Integer theArgNb,
5022 const char** theArgVec)
5027 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5031 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5034 ViewerTest::ViewerInit();
5035 aCtx = ViewerTest::GetAISContext();
5040 TCollection_AsciiString aSelActivationString;
5041 if (aCtx->GetAutoActivateSelection())
5043 aSelActivationString.Copy ("ON");
5047 aSelActivationString.Copy ("OFF");
5050 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5054 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5055 aCtx->SetAutoActivateSelection (toActivate);
5061 //==============================================================================
5062 //function : ViewerTest::Commands
5063 //purpose : Add all the viewer command in the Draw_Interpretor
5064 //==============================================================================
5066 void ViewerTest::Commands(Draw_Interpretor& theCommands)
5068 ViewerTest::ViewerCommands(theCommands);
5069 ViewerTest::RelationCommands(theCommands);
5070 ViewerTest::ObjectCommands(theCommands);
5071 ViewerTest::FilletCommands(theCommands);
5072 ViewerTest::VoxelCommands(theCommands);
5073 ViewerTest::OpenGlCommands(theCommands);
5075 const char *group = "AIS_Display";
5078 theCommands.Add("visos",
5079 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5080 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5081 __FILE__, visos, group);
5083 theCommands.Add("vdisplay",
5084 "vdisplay [-noupdate|-update] [-local] [-mutable] [-overlay|-underlay]"
5085 "\n\t\t: [-trsfPers flags] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
5086 "\n\t\t: [-dispMode mode] [-highMode mode]"
5087 "\n\t\t: name1 [name2] ... [name n]"
5088 "\n\t\t: Displays named objects."
5089 "\n\t\t: Option -local enables displaying of objects in local"
5090 "\n\t\t: selection context. Local selection context will be opened"
5091 "\n\t\t: if there is not any."
5092 "\n\t\t: -noupdate suppresses viewer redraw call."
5093 "\n\t\t: -mutable enables optimizations for mutable objects."
5094 "\n\t\t: -overlay draws objects in overlay."
5095 "\n\t\t: -underlay draws objects in underlay."
5096 "\n\t\t: -selectable|-noselect controls selection of objects."
5097 "\n\t\t: -trsfPers sets a transform persistence flags."
5098 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
5099 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates.",
5100 __FILE__, VDisplay2, group);
5102 theCommands.Add ("vupdate",
5103 "vupdate name1 [name2] ... [name n]"
5104 "\n\t\t: Updates named objects in interactive context",
5105 __FILE__, VUpdate, group);
5107 theCommands.Add("verase",
5108 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
5109 "\n\t\t: Erases selected or named objects."
5110 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5111 "\n\t\t: Option -local enables erasing of selected or named objects without"
5112 "\n\t\t: closing local selection context.",
5113 __FILE__, VErase, group);
5115 theCommands.Add("vremove",
5116 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5117 "or vremove [-context] -all to remove all objects"
5118 "\n\t\t: Removes selected or named objects."
5119 "\n\t\t If -context is in arguments, the objects are not deleted"
5120 "\n\t\t from the map of objects and names."
5121 "\n\t\t: Option -local enables removing of selected or named objects without"
5122 "\n\t\t: closing local selection context. Empty local selection context will be"
5124 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5125 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
5126 __FILE__, VRemove, group);
5128 theCommands.Add("vdonly",
5129 "vdonly [-noupdate|-update] [name1] ... [name n]"
5130 "\n\t\t: Displays only selected or named objects",
5131 __FILE__,VDonly2,group);
5133 theCommands.Add("vdisplayall",
5134 "vidsplayall [-local]"
5135 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5136 "\n\t\t: Option -local enables displaying of the objects in local"
5137 "\n\t\t: selection context.",
5138 __FILE__, VDisplayAll, group);
5140 theCommands.Add("veraseall",
5141 "veraseall [-local]"
5142 "\n\t\t: Erases all objects displayed in the viewer."
5143 "\n\t\t: Option -local enables erasing of the objects in local"
5144 "\n\t\t: selection context.",
5145 __FILE__, VErase, group);
5147 theCommands.Add("verasetype",
5149 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
5150 __FILE__, VEraseType, group);
5151 theCommands.Add("vbounding",
5152 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5153 "\n\t\t: [-print] [-hide]"
5154 "\n\t\t: Temporarily display bounding box of specified Interactive"
5155 "\n\t\t: Objects, or print it to console if -print is specified."
5156 "\n\t\t: Already displayed box might be hidden by -hide option.",
5157 __FILE__,VBounding,group);
5159 theCommands.Add("vdisplaytype",
5160 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5161 __FILE__,VDisplayType,group);
5163 theCommands.Add("vdisplaymode",
5164 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5165 __FILE__,VDispMode,group);
5167 theCommands.Add("verasemode",
5168 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5169 __FILE__,VDispMode,group);
5171 theCommands.Add("vsetdispmode",
5172 "vsetdispmode [name] mode(1,2,..)"
5173 "\n\t\t: Sets display mode for all, selected or named objects.",
5174 __FILE__,VDispMode,group);
5176 theCommands.Add("vunsetdispmode",
5177 "vunsetdispmode [name]"
5178 "\n\t\t: Unsets custom display mode for selected or named objects.",
5179 __FILE__,VDispMode,group);
5181 theCommands.Add("vdir",
5182 "Lists all objects displayed in 3D viewer",
5183 __FILE__,VDir,group);
5185 theCommands.Add("vdump",
5186 #ifdef HAVE_FREEIMAGE
5187 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5188 "\n\t\t: [width Width=0 height Height=0]"
5189 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
5191 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
5192 "\n\t\t: [width Width=0 height Height=0]"
5193 "\n\t\t: Dumps content of the active view into PPM image file",
5195 __FILE__,VDump,group);
5197 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5198 __FILE__,VSubInt,group);
5200 theCommands.Add("vaspects",
5201 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
5202 "\n\t\t: [-setvisibility 0|1]"
5203 "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
5204 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
5205 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
5206 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
5207 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5208 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5209 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
5210 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5211 "\n\t\t: Manage presentation properties of all, selected or named objects."
5212 "\n\t\t: When -subshapes is specified than following properties will be"
5213 "\n\t\t: assigned to specified sub-shapes."
5214 "\n\t\t: When -defaults is specified than presentation properties will be"
5215 "\n\t\t: assigned to all objects that have not their own specified properties"
5216 "\n\t\t: and to all objects to be displayed in the future."
5217 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
5218 __FILE__,VAspects,group);
5220 theCommands.Add("vsetcolor",
5221 "vsetcolor [-noupdate|-update] [name] ColorName"
5222 "\n\t\t: Sets color for all, selected or named objects."
5223 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5224 __FILE__,VAspects,group);
5226 theCommands.Add("vunsetcolor",
5227 "vunsetcolor [-noupdate|-update] [name]"
5228 "\n\t\t: Resets color for all, selected or named objects."
5229 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5230 __FILE__,VAspects,group);
5232 theCommands.Add("vsettransparency",
5233 "vsettransparency [-noupdate|-update] [name] Coefficient"
5234 "\n\t\t: Sets transparency for all, selected or named objects."
5235 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5236 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5237 __FILE__,VAspects,group);
5239 theCommands.Add("vunsettransparency",
5240 "vunsettransparency [-noupdate|-update] [name]"
5241 "\n\t\t: Resets transparency for all, selected or named objects."
5242 "\n\t\t: Alias for vaspects -unsettransp [name].",
5243 __FILE__,VAspects,group);
5245 theCommands.Add("vsetmaterial",
5246 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5247 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5248 __FILE__,VAspects,group);
5250 theCommands.Add("vunsetmaterial",
5251 "vunsetmaterial [-noupdate|-update] [name]"
5252 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5253 __FILE__,VAspects,group);
5255 theCommands.Add("vsetwidth",
5256 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5257 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5258 __FILE__,VAspects,group);
5260 theCommands.Add("vunsetwidth",
5261 "vunsetwidth [-noupdate|-update] [name]"
5262 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5263 __FILE__,VAspects,group);
5265 theCommands.Add("vsetinteriorstyle",
5266 "vsetinteriorstyle [-noupdate|-update] [name] style"
5267 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5268 __FILE__,VSetInteriorStyle,group);
5270 theCommands.Add("vsensdis",
5271 "vardisp : display active entities",
5272 __FILE__,VDispSensi,group);
5273 theCommands.Add("vsensera",
5274 "vardisp : erase active entities",
5275 __FILE__,VClearSensi,group);
5277 theCommands.Add("vselprecision",
5278 "vselprecision : vselprecision [tolerance_value]",
5279 __FILE__,VSelPrecision,group);
5281 theCommands.Add("vperf",
5282 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
5283 __FILE__,VPerf,group);
5285 theCommands.Add("vanimation",
5286 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5287 __FILE__,VAnimation,group);
5289 theCommands.Add("vsetshading",
5290 "vsetshading : vsetshading name Quality(default=0.0008) ",
5291 __FILE__,VShading,group);
5293 theCommands.Add("vunsetshading",
5294 "vunsetshading :vunsetshading name ",
5295 __FILE__,VShading,group);
5297 theCommands.Add ("vtexture",
5298 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5299 " [-scale u v] [-scale off]\n"
5300 " [-origin u v] [-origin off]\n"
5301 " [-repeat u v] [-repeat off]\n"
5302 " [-modulate {on | off}]"
5304 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5305 " specifying one of the predefined textures.\n"
5306 " The options are: \n"
5307 " -scale u v : enable texture scaling and set scale factors\n"
5308 " -scale off : disable texture scaling\n"
5309 " -origin u v : enable texture origin positioning and set the origin\n"
5310 " -origin off : disable texture origin positioning\n"
5311 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5312 " -repeat off : disable texture repeat\n"
5313 " -modulate {on | off} : enable or disable texture modulation\n"
5314 " -default : sets texture mapping default parameters\n"
5315 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5316 "or 'vtexture NameOfShape ?' to list available textures\n",
5317 __FILE__, VTexture, group);
5319 theCommands.Add("vtexscale",
5320 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5321 or 'vtexscale NameOfShape ScaleUV' \n \
5322 or 'vtexscale NameOfShape' to disable scaling\n ",
5323 __FILE__,VTexture,group);
5325 theCommands.Add("vtexorigin",
5326 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5327 or 'vtexorigin NameOfShape UVOrigin' \n \
5328 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5329 __FILE__,VTexture,group);
5331 theCommands.Add("vtexrepeat",
5332 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5333 or 'vtexrepeat NameOfShape UVRepeat \n \
5334 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5337 theCommands.Add("vtexdefault",
5338 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5341 theCommands.Add("vsetam",
5342 "vsetActivatedModes: vsetam mode(1->7) ",
5343 __FILE__,VActivatedMode,group);
5345 theCommands.Add("vunsetam",
5346 "vunsetActivatedModes: vunsetam ",
5347 __FILE__,VActivatedMode,group);
5349 theCommands.Add("vstate",
5350 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
5351 "\n\t\t: Reports show/hidden state for selected or named objects"
5352 "\n\t\t: -entities - print low-level information about detected entities"
5353 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
5354 __FILE__,VState,group);
5356 theCommands.Add("vpickshapes",
5357 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5358 __FILE__,VPickShape,group);
5360 theCommands.Add("vtypes",
5361 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5364 theCommands.Add("vr", "vr : reading of the shape",
5365 __FILE__,vr, group);
5367 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5368 __FILE__, VPickSelected, group);
5370 theCommands.Add ("vloadselection",
5371 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5372 "\n\t\t: primitives for the shapes with names given without displaying them."
5373 "\n\t\t: -local - open local context before selection computation",
5374 __FILE__, VLoadSelection, group);
5376 theCommands.Add ("vautoactivatesel",
5377 "vautoactivatesel [0|1] : manage or display the option to automatically"
5378 "\n\t\t: activate selection for newly displayed objects"
5379 "\n\t\t: [0|1] - turn off | on auto activation of selection",
5380 __FILE__, VAutoActivateSelection, group);
5384 //=====================================================================
5385 //========================= for testing Draft and Rib =================
5386 //=====================================================================
5387 #include <BRepOffsetAPI_MakeThickSolid.hxx>
5388 #include <DBRep.hxx>
5389 #include <TopoDS_Face.hxx>
5390 #include <gp_Pln.hxx>
5391 #include <AIS_KindOfSurface.hxx>
5392 #include <BRepOffsetAPI_DraftAngle.hxx>
5393 #include <Precision.hxx>
5394 #include <BRepAlgo.hxx>
5395 #include <OSD_Environment.hxx>
5396 #include <DrawTrSurf.hxx>
5397 //#include <DbgTools.hxx>
5398 //#include <FeatAlgo_MakeLinearForm.hxx>
5403 //=======================================================================
5404 //function : IsValid
5406 //=======================================================================
5407 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5408 const TopoDS_Shape& theResult,
5409 const Standard_Boolean closedSolid,
5410 const Standard_Boolean GeomCtrl)
5412 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5413 TCollection_AsciiString checkValid = check.Value();
5414 Standard_Boolean ToCheck = Standard_True;
5415 if (!checkValid.IsEmpty()) {
5417 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5419 if ( checkValid=="true" || checkValid=="TRUE" ) {
5420 ToCheck= Standard_False;
5424 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
5427 Standard_Boolean IsValid = Standard_True;
5429 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5434 //===============================================================================
5435 // TDraft : test draft, uses AIS Viewer
5436 // Solid Face Plane Angle Reverse
5437 //===============================================================================
5438 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5440 if (argc < 5) return 1;
5441 // argv[1] - TopoDS_Shape Solid
5442 // argv[2] - TopoDS_Shape Face
5443 // argv[3] - TopoDS_Shape Plane
5444 // argv[4] - Standard_Real Angle
5445 // argv[5] - Standard_Integer Reverse
5447 // Sprintf(prefix, argv[1]);
5448 Standard_Real anAngle = 0;
5449 Standard_Boolean Rev = Standard_False;
5450 Standard_Integer rev = 0;
5451 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5452 TopoDS_Shape face = GetShapeFromName(argv[2]);
5453 TopoDS_Face Face = TopoDS::Face(face);
5454 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5455 if (Plane.IsNull ()) {
5456 di << "TEST : Plane is NULL" << "\n";
5459 anAngle = Draw::Atof(argv[4]);
5460 anAngle = 2*M_PI * anAngle / 360.0;
5462 Handle( Geom_Surface )aSurf;
5463 AIS_KindOfSurface aSurfType;
5464 Standard_Real Offset;
5466 if(argc > 4) { // == 5
5467 rev = Draw::Atoi(argv[5]);
5468 Rev = (rev)? Standard_True : Standard_False;
5471 TopoDS_Face face2 = TopoDS::Face(Plane);
5472 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5474 di << "TEST : Can't find plane" << "\n";
5478 aDir = aPln.Axis().Direction();
5481 if (Plane.Orientation() == TopAbs_REVERSED)
5483 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5485 BRepOffsetAPI_DraftAngle Draft (Solid);
5487 if(Abs(anAngle)< Precision::Angular()) {
5488 di << "TEST : NULL angle" << "\n";
5491 if(Rev) anAngle = - anAngle;
5492 Draft.Add (Face, aDir, anAngle, aPln);
5494 if (!Draft.IsDone()) {
5495 di << "TEST : Draft Not DONE " << "\n";
5498 TopTools_ListOfShape Larg;
5500 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
5501 di << "TEST : DesignAlgo returns Not valid" << "\n";
5505 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5506 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5508 if ( !ais.IsNull() ) {
5509 ais->SetColor(DEFAULT_COLOR);
5510 ais->SetMaterial(DEFAULT_MATERIAL);
5511 // Display the AIS_Shape without redraw
5512 Ctx->Display(ais, Standard_False);
5514 const char *Name = "draft1";
5515 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5517 Handle(AIS_InteractiveObject) an_object =
5518 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5519 if (!an_object.IsNull()) {
5520 Ctx->Remove(an_object,
5522 GetMapOfAIS().UnBind2(Name) ;
5525 GetMapOfAIS().Bind(ais, Name);
5526 // DBRep::Set("draft", ais->Shape());
5528 Ctx->Display(ais, Standard_True);
5532 //==============================================================================
5533 //function : splitParameter
5534 //purpose : Split parameter string to parameter name and parameter value
5535 //==============================================================================
5536 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5537 TCollection_AsciiString& theName,
5538 TCollection_AsciiString& theValue)
5540 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5542 if (aParamNameEnd == 0)
5544 return Standard_False;
5547 TCollection_AsciiString aString (theString);
5548 if (aParamNameEnd != 0)
5550 theValue = aString.Split (aParamNameEnd);
5551 aString.Split (aString.Length() - 1);
5555 return Standard_True;
5558 //============================================================================
5560 //============================================================================
5561 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5564 DrawTrSurf::BasicCommands(theCommands);
5565 const char* group = "Check Features Operations commands";
5567 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5569 &TDraft,group); //Draft_Modification
5572 //==============================================================================
5573 // ViewerTest::Factory
5574 //==============================================================================
5575 void ViewerTest::Factory(Draw_Interpretor& theDI)
5577 // definition of Viewer Command
5578 ViewerTest::Commands(theDI);
5579 ViewerTest::AviCommands(theDI);
5582 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
5586 // Declare entry point PLUGINFACTORY