1 // Created on: 1997-07-23
2 // Created by: Henri JEANNIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
18 // Modified by Robert Coublanc [nov 16-17-18 1998]
19 // -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20 // ViewerTest_ObjectCommands.cxx
21 // ViewerTest_RelationCommands.cxx
22 // -add Functions and commands for interactive selection of shapes and objects
23 // in AIS Viewers. (PickShape(s), PickObject(s),
25 #include <Standard_Stream.hxx>
27 #include <ViewerTest.hxx>
29 #include <TopLoc_Location.hxx>
30 #include <TopTools_HArray1OfShape.hxx>
31 #include <TColStd_HArray1OfTransient.hxx>
32 #include <TColStd_HSequenceOfAsciiString.hxx>
33 #include <OSD_Timer.hxx>
34 #include <Geom_Axis2Placement.hxx>
35 #include <Geom_Axis1Placement.hxx>
36 #include <gp_Trsf.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <BRepAdaptor_Curve.hxx>
39 #include <StdSelect_ShapeTypeFilter.hxx>
41 #include <AIS_Drawer.hxx>
42 #include <AIS_ColoredShape.hxx>
43 #include <AIS_InteractiveObject.hxx>
44 #include <AIS_Trihedron.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Relation.hxx>
47 #include <AIS_TypeFilter.hxx>
48 #include <AIS_SignatureFilter.hxx>
49 #include <AIS_LocalContext.hxx>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <Aspect_InteriorStyle.hxx>
53 #include <Aspect_Window.hxx>
54 #include <Graphic3d_AspectFillArea3d.hxx>
55 #include <Graphic3d_AspectLine3d.hxx>
56 #include <Graphic3d_TextureRoot.hxx>
57 #include <Image_AlienPixMap.hxx>
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_IsoAspect.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <ViewerTest_AutoUpdater.hxx>
65 #include <Draw_Interpretor.hxx>
66 #include <TCollection_AsciiString.hxx>
67 #include <Draw_PluginMacro.hxx>
69 // avoid warnings on 'extern "C"' functions returning C++ classes
71 #define _CRT_SECURE_NO_DEPRECATE
72 #pragma warning(4:4190)
73 #pragma warning (disable:4996)
76 #include <NIS_InteractiveContext.hxx>
77 #include <NIS_Triangulated.hxx>
78 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
80 #include <Quantity_Color.hxx>
81 #include <Quantity_NameOfColor.hxx>
83 #include <Graphic3d_NameOfMaterial.hxx>
85 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
86 #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
88 //=======================================================================
89 //function : GetColorFromName
90 //purpose : get the Quantity_NameOfColor from a string
91 //=======================================================================
93 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
95 for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
97 Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
98 if (strcasecmp (theName, aColorName) == 0)
100 return Quantity_NameOfColor (anIter);
104 return DEFAULT_COLOR;
107 //=======================================================================
108 //function : GetTypeNames
110 //=======================================================================
111 static const char** GetTypeNames()
113 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
114 "Shape","ConnectedShape","MultiConn.Shape",
115 "ConnectedInter.","MultiConn.",
116 "Constraint","Dimension"};
117 static const char** ThePointer = names;
121 //=======================================================================
122 //function : GetTypeAndSignfromString
124 //=======================================================================
125 void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
127 const char ** thefullnames = GetTypeNames();
128 Standard_Integer index(-1);
130 for(Standard_Integer i=0;i<=13 && index==-1;i++)
131 if(!strcasecmp(name,thefullnames[i]))
135 TheType = AIS_KOI_None;
141 TheType = AIS_KOI_Datum;
145 TheType = AIS_KOI_Shape;
149 TheType = AIS_KOI_Object;
153 TheType = AIS_KOI_Relation;
162 #include <Draw_Interpretor.hxx>
164 #include <Draw_Appli.hxx>
168 #include <TCollection_AsciiString.hxx>
169 #include <V3d_Viewer.hxx>
170 #include <V3d_View.hxx>
173 #include <AIS_InteractiveContext.hxx>
174 #include <AIS_Shape.hxx>
175 #include <AIS_TexturedShape.hxx>
176 #include <AIS_DisplayMode.hxx>
177 #include <TColStd_MapOfInteger.hxx>
178 #include <AIS_MapOfInteractive.hxx>
179 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
180 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
181 #include <ViewerTest_EventManager.hxx>
183 #include <TopoDS_Solid.hxx>
184 #include <BRepTools.hxx>
185 #include <BRep_Builder.hxx>
186 #include <TopAbs_ShapeEnum.hxx>
188 #include <TopoDS.hxx>
189 #include <BRep_Tool.hxx>
192 #include <Draw_Window.hxx>
193 #include <AIS_ListIteratorOfListOfInteractive.hxx>
194 #include <AIS_ListOfInteractive.hxx>
195 #include <AIS_DisplayMode.hxx>
196 #include <TopTools_ListOfShape.hxx>
197 #include <BRepOffsetAPI_MakeThickSolid.hxx>
198 #include <BRepOffset.hxx>
200 //==============================================================================
201 // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
202 //==============================================================================
203 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
204 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
209 //==============================================================================
210 //function : VDisplayAISObject
211 //purpose : register interactive object in the map of AIS objects;
212 // if other object with such name already registered, it will be kept
213 // or replaced depending on value of <theReplaceIfExists>,
214 // if "true" - the old object will be cleared from AIS context;
215 // returns Standard_True if <theAISObj> registered in map;
216 //==============================================================================
217 Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
218 const Handle(AIS_InteractiveObject)& theAISObj,
219 Standard_Boolean theReplaceIfExists = Standard_True)
221 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
222 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
223 if (aContextAIS.IsNull())
225 std::cout << "AIS context is not available.\n";
226 return Standard_False;
229 if (aMap.IsBound2 (theName))
231 if (!theReplaceIfExists)
233 std::cout << "Other interactive object has been already "
234 << "registered with name: " << theName << ".\n"
235 << "Please use another name.\n";
236 return Standard_False;
239 // stop displaying object
240 Handle(AIS_InteractiveObject) anOldObj =
241 Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
243 if (!anOldObj.IsNull())
244 aContextAIS->Clear (anOldObj, Standard_True);
246 // remove name and old object from map
247 aMap.UnBind2 (theName);
250 if (theAISObj.IsNull())
252 // object with specified name already unbound
253 return Standard_True;
256 // unbind AIS object if was bound with another name
257 aMap.UnBind1 (theAISObj);
259 // can be registered without rebinding
260 aMap.Bind (theAISObj, theName);
261 aContextAIS->Display (theAISObj, Standard_True);
262 return Standard_True;
265 static TColStd_MapOfInteger theactivatedmodes(8);
266 static TColStd_ListOfTransient theEventMgrs;
268 static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
269 const Handle(AIS_InteractiveContext)& Ctx)
271 theEventMgrs.Clear();
272 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
275 static Handle(V3d_View)& a3DView()
277 static Handle(V3d_View) Viou;
282 Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
283 static Handle(AIS_InteractiveContext) aContext;
287 const Handle(V3d_View)& ViewerTest::CurrentView()
291 void ViewerTest::CurrentView(const Handle(V3d_View)& V)
296 Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
298 static Handle(NIS_InteractiveContext) aContext;
299 if (aContext.IsNull()) {
300 aContext = new NIS_InteractiveContext;
301 aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
306 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
308 return TheAISContext();
311 void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
313 TheAISContext() = aCtx;
314 ViewerTest::ResetEventManager();
317 Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
319 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
322 Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
324 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
328 void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
329 theEventMgrs.Prepend(EM);
332 void ViewerTest::UnsetEventManager()
334 theEventMgrs.RemoveFirst();
338 void ViewerTest::ResetEventManager()
340 const Handle(NIS_View) aView =
341 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
342 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
345 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
347 Handle(ViewerTest_EventManager) EM;
348 if(theEventMgrs.IsEmpty()) return EM;
349 Handle(Standard_Transient) Tr = theEventMgrs.First();
350 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
354 //=======================================================================
355 //function : Get Context and active view
357 //=======================================================================
358 static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
359 Handle(V3d_View)& theView)
361 theCtx = ViewerTest::GetAISContext();
362 theView = ViewerTest::CurrentView();
366 std::cout << "Error: cannot find an active view!\n";
367 return Standard_False;
369 return Standard_True;
372 //==============================================================================
373 //function : GetShapeFromName
374 //purpose : Compute an Shape from a draw variable or a file name
375 //==============================================================================
377 static TopoDS_Shape GetShapeFromName(const char* name)
379 TopoDS_Shape S = DBRep::Get(name);
382 BRep_Builder aBuilder;
383 BRepTools::Read( S, name, aBuilder);
389 //==============================================================================
390 //function : GetAISShapeFromName
391 //purpose : Compute an AIS_Shape from a draw variable or a file name
392 //==============================================================================
393 Handle(AIS_Shape) GetAISShapeFromName(const char* name)
395 Handle(AIS_Shape) retsh;
397 if(GetMapOfAIS().IsBound2(name)){
398 const Handle(AIS_InteractiveObject) IO =
399 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
401 if(IO->Type()==AIS_KOI_Shape) {
402 if(IO->Signature()==0){
403 retsh = *((Handle(AIS_Shape)*)&IO);
406 cout << "an Object which is not an AIS_Shape "
407 "already has this name!!!"<<endl;
414 TopoDS_Shape S = GetShapeFromName(name);
416 retsh = new AIS_Shape(S);
422 //==============================================================================
424 //purpose : Remove all the object from the viewer
425 //==============================================================================
426 void ViewerTest::Clear()
428 if ( !a3DView().IsNull() ) {
429 if (TheAISContext()->HasOpenedContext())
430 TheAISContext()->CloseLocalContext();
431 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
432 while ( it.More() ) {
433 cout << "Remove " << it.Key2() << endl;
434 if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
435 const Handle(AIS_InteractiveObject) anObj =
436 Handle(AIS_InteractiveObject)::DownCast (it.Key1());
437 TheAISContext()->Remove(anObj,Standard_False);
438 } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
439 const Handle(NIS_InteractiveObject) anObj =
440 Handle(NIS_InteractiveObject)::DownCast (it.Key1());
441 TheNISContext()->Remove(anObj);
445 TheAISContext()->UpdateCurrentViewer();
446 // TheNISContext()->UpdateViews();
447 GetMapOfAIS().Clear();
451 //==============================================================================
452 //function : StandardModesActivation
453 //purpose : Activate a selection mode, vertex, edge, wire ..., in a local
455 //==============================================================================
456 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
458 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
460 if (TheAISContext()->HasOpenedContext())
461 aContext->CloseLocalContext();
464 if(!aContext->HasOpenedContext()) {
465 // To unhilight the preselected object
466 aContext->UnhilightCurrents(Standard_False);
467 // Open a local Context in order to be able to select subshape from
468 // the selected shape if any or for all if there is no selection
469 if (!aContext->FirstCurrentObject().IsNull()){
470 aContext->OpenLocalContext(Standard_False);
472 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
473 aContext->Load( aContext->Current(),-1,Standard_True);
477 aContext->OpenLocalContext();
480 const char *cmode="???";
483 case 0: cmode = "Shape"; break;
484 case 1: cmode = "Vertex"; break;
485 case 2: cmode = "Edge"; break;
486 case 3: cmode = "Wire"; break;
487 case 4: cmode = "Face"; break;
488 case 5: cmode = "Shell"; break;
489 case 6: cmode = "Solid"; break;
490 case 7: cmode = "Compsolid"; break;
491 case 8: cmode = "Compound"; break;
494 if(theactivatedmodes.Contains(mode))
496 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
497 theactivatedmodes.Remove(mode);
498 cout<<"Mode "<< cmode <<" OFF"<<endl;
502 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
503 theactivatedmodes.Add(mode);
504 cout<<"Mode "<< cmode << " ON" << endl;
509 //==============================================================================
510 //function : CopyIsoAspect
511 //purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
512 //==============================================================================
513 static Handle(Prs3d_IsoAspect) CopyIsoAspect
514 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
515 const Standard_Integer theNbIsos)
517 Quantity_Color aColor;
518 Aspect_TypeOfLine aType;
519 Standard_Real aWidth;
521 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
523 Handle(Prs3d_IsoAspect) aResult =
524 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
529 //==============================================================================
531 //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
532 //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
533 //==============================================================================
534 static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
536 if (TheAISContext().IsNull()) {
537 di << argv[0] << " Call 'vinit' before!\n";
542 di << "Current number of isos : " <<
543 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
544 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
545 di << "IsoOnPlane mode is " <<
546 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
551 Standard_Integer aLastInd = argc - 1;
552 Standard_Boolean isChanged = Standard_False;
553 Standard_Integer aNbUIsos = 0;
554 Standard_Integer aNbVIsos = 0;
557 Standard_Boolean isIsoOnPlane = Standard_False;
559 if (strcmp(argv[aLastInd], "1") == 0) {
560 isIsoOnPlane = Standard_True;
561 isChanged = Standard_True;
562 } else if (strcmp(argv[aLastInd], "0") == 0) {
563 isIsoOnPlane = Standard_False;
564 isChanged = Standard_True;
568 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
569 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
572 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
573 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
575 TheAISContext()->IsoOnPlane(isIsoOnPlane);
578 // If there are no shapes provided set the default numbers.
579 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
580 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
587 for (i = 1; i <= aLastInd; i++) {
588 TCollection_AsciiString name(argv[i]);
589 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
592 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
593 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
594 const Handle(AIS_InteractiveObject) aShape =
595 Handle(AIS_InteractiveObject)::DownCast (anObj);
596 Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
597 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
598 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
601 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
602 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
603 TheAISContext()->SetLocalAttributes
604 (aShape, CurDrawer, Standard_False);
605 TheAISContext()->Redisplay(aShape);
607 di << "Number of isos for " << argv[i] << " : "
608 << aUIso->Number() << " " << aVIso->Number() << "\n";
611 di << argv[i] << ": Not an AIS interactive object!\n";
614 di << argv[i] << ": Use 'vdisplay' before\n";
619 TheAISContext()->UpdateCurrentViewer();
625 //==============================================================================
626 //function : VDispAreas,VDispSensitive,...
628 //==============================================================================
629 static Standard_Integer VDispAreas (Draw_Interpretor& ,
630 Standard_Integer theArgNb,
635 std::cout << "Error: wrong syntax!\n";
639 Handle(AIS_InteractiveContext) aCtx;
640 Handle(V3d_View) aView;
641 if (!getCtxAndView (aCtx, aView))
646 aCtx->DisplayActiveAreas (aView);
649 static Standard_Integer VClearAreas (Draw_Interpretor& ,
650 Standard_Integer theArgNb,
655 std::cout << "Error: wrong syntax!\n";
659 Handle(AIS_InteractiveContext) aCtx;
660 Handle(V3d_View) aView;
661 if (!getCtxAndView (aCtx, aView))
666 aCtx->ClearActiveAreas (aView);
670 static Standard_Integer VDispSensi (Draw_Interpretor& ,
671 Standard_Integer theArgNb,
676 std::cout << "Error: wrong syntax!\n";
680 Handle(AIS_InteractiveContext) aCtx;
681 Handle(V3d_View) aView;
682 if (!getCtxAndView (aCtx, aView))
687 aCtx->DisplayActiveSensitive (aView);
692 static Standard_Integer VClearSensi (Draw_Interpretor& ,
693 Standard_Integer theArgNb,
698 std::cout << "Error: wrong syntax!\n";
702 Handle(AIS_InteractiveContext) aCtx;
703 Handle(V3d_View) aView;
704 if (!getCtxAndView (aCtx, aView))
708 aCtx->ClearActiveSensitive (aView);
712 //==============================================================================
714 //purpose : To list the displayed object with their attributes
715 //==============================================================================
716 static int VDir (Draw_Interpretor& theDI,
720 if (!a3DView().IsNull())
725 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
726 anIter.More(); anIter.Next())
728 theDI << "\t" << anIter.Key2().ToCString() << "\n";
733 //==============================================================================
734 //function : VSelPrecision
735 //purpose : To set the selection precision mode and tolerance value
736 //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
737 // value (integer number of pixel for window mode, double value of
738 // sensitivity for view mode). Without arguments the function just
739 // prints the current precision mode and the corresponding tolerance.
740 //==============================================================================
741 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
745 di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
749 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
750 if( aContext.IsNull() )
755 StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
756 if( aMode == StdSelect_SM_WINDOW )
758 Standard_Integer aPixelTolerance = aContext->PixelTolerance();
759 di << "Precision mode : 0 (window)\n";
760 di << "Pixel tolerance : " << aPixelTolerance << "\n";
762 else if( aMode == StdSelect_SM_VIEW )
764 Standard_Real aSensitivity = aContext->Sensitivity();
765 di << "Precision mode : 1 (view)\n";
766 di << "Sensitivity : " << aSensitivity << "\n";
771 StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
772 aContext->SetSensitivityMode( aMode );
775 if( aMode == StdSelect_SM_WINDOW )
777 Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
778 aContext->SetPixelTolerance( aPixelTolerance );
780 else if( aMode == StdSelect_SM_VIEW )
782 Standard_Real aSensitivity = Draw::Atof( argv[2] );
783 aContext->SetSensitivity( aSensitivity );
790 //==============================================================================
792 //purpose : To dump the active view snapshot to image file
793 //==============================================================================
794 static Standard_Integer VDump (Draw_Interpretor& theDI,
795 Standard_Integer theArgNb,
796 Standard_CString* theArgVec)
800 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
804 Standard_Integer anArgIter = 1;
805 Standard_CString aFilePath = theArgVec[anArgIter++];
806 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
807 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
808 Standard_Integer aWidth = 0;
809 Standard_Integer aHeight = 0;
810 for (; anArgIter < theArgNb; ++anArgIter)
812 TCollection_AsciiString anArg (theArgVec[anArgIter]);
816 aBufferType = Graphic3d_BT_RGBA;
818 else if (anArg == "rgb")
820 aBufferType = Graphic3d_BT_RGB;
822 else if (anArg == "depth")
824 aBufferType = Graphic3d_BT_Depth;
826 else if (anArg == "l"
829 aStereoOpts = V3d_SDO_LEFT_EYE;
831 else if (anArg == "r"
834 aStereoOpts = V3d_SDO_RIGHT_EYE;
836 else if (anArg == "mono")
838 aStereoOpts = V3d_SDO_MONO;
840 else if (anArg == "w"
845 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
848 else if (++anArgIter >= theArgNb)
850 std::cout << "Error: integer value is expected right after 'width'\n";
853 aWidth = Draw::Atoi (theArgVec[anArgIter]);
855 else if (anArg == "h"
856 || anArg == "height")
860 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
863 if (++anArgIter >= theArgNb)
865 std::cout << "Error: integer value is expected right after 'height'\n";
868 aHeight = Draw::Atoi (theArgVec[anArgIter]);
870 else if (anArg.IsIntegerValue())
872 // compatibility with old syntax
876 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
879 else if (++anArgIter >= theArgNb)
881 std::cout << "Error: height value is expected right after width\n";
884 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
885 aHeight = Draw::Atoi (theArgVec[anArgIter]);
889 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
893 if ((aWidth <= 0 && aHeight > 0)
894 || (aWidth > 0 && aHeight <= 0))
896 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
900 Handle(V3d_View) aView = ViewerTest::CurrentView();
903 std::cout << "Error: cannot find an active view!\n";
907 if (aWidth <= 0 || aHeight <= 0)
909 if (aStereoOpts != V3d_SDO_MONO)
911 aView->Window()->Size (aWidth, aHeight);
915 if (!aView->Dump (aFilePath, aBufferType))
917 theDI << "Fail: view dump failed!\n";
923 Image_AlienPixMap aPixMap;
924 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
926 theDI << "Fail: view dump failed!\n";
930 if (aPixMap.SizeX() != Standard_Size(aWidth)
931 || aPixMap.SizeY() != Standard_Size(aHeight))
933 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
934 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
936 if (!aPixMap.Save (aFilePath))
938 theDI << "Fail: image can not be saved!\n";
944 //==============================================================================
945 //function : Displays,Erase...
948 //==============================================================================
949 static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
950 const Standard_Integer Mode,
951 const Standard_Integer TypeOfOperation,
952 const Standard_Boolean Upd)
954 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
956 switch(TypeOfOperation){
958 Ctx->Display(IO,Mode,Upd);
966 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
968 Ctx->SetDisplayMode(IO,Mode,Upd);
973 Ctx->SetDisplayMode(0,Upd);
975 Ctx->UnsetDisplayMode(IO,Upd);
982 //=======================================================================
985 //=======================================================================
986 static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
989 TCollection_AsciiString name;
992 // display others presentations
993 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
994 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
995 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
996 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
998 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1000 //unset displaymode.. comportement particulier...
1001 if(TypeOfOperation==4){
1003 if(Ctx->NbCurrents()==0 ||
1004 Ctx->NbSelected()==0){
1005 Handle(AIS_InteractiveObject) IO;
1006 VwrTst_DispErase(IO,-1,4,Standard_False);
1008 else if(!Ctx->HasOpenedContext()){
1009 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1010 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
1013 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1014 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
1015 Ctx->UpdateCurrentViewer();
1018 Handle(AIS_InteractiveObject) IO;
1020 if(GetMapOfAIS().IsBound2(name)){
1021 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1023 VwrTst_DispErase(IO,-1,4,Standard_True);
1028 Standard_Integer Dmode = Draw::Atoi(argv[1]);
1029 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1030 Handle(AIS_InteractiveObject) IO;
1031 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1033 if(!Ctx->HasOpenedContext()){
1034 // set/unset display mode sur le Contexte...
1035 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1036 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1038 Ctx->UpdateCurrentViewer();
1041 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1042 Ctx->Display(Ctx->Interactive(),Dmode);
1046 Handle(AIS_InteractiveObject) IO;
1048 if(GetMapOfAIS().IsBound2(name))
1049 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1051 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
1057 //=======================================================================
1060 //=======================================================================
1061 static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1063 if(argc==1) return 1;
1064 Standard_Integer On = Draw::Atoi(argv[1]);
1065 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1069 if(!Ctx->HasOpenedContext()){
1070 di<<"sub intensite ";
1073 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1074 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1076 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1078 di <<"passage dans off"<<"\n";
1079 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1084 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1086 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1088 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1091 Ctx->UpdateCurrentViewer();
1094 Handle(AIS_InteractiveObject) IO;
1095 TCollection_AsciiString name = argv[2];
1096 if(GetMapOfAIS().IsBound2(name)){
1097 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1100 Ctx->SubIntensityOn(IO);
1102 Ctx->SubIntensityOff(IO);
1110 //! Auxiliary class to iterate presentations from different collections.
1111 class ViewTest_PrsIter
1115 //! Create and initialize iterator object.
1116 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1117 : mySource (IterSource_All)
1119 NCollection_Sequence<TCollection_AsciiString> aNames;
1120 if (!theName.IsEmpty())
1121 aNames.Append (theName);
1125 //! Create and initialize iterator object.
1126 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1127 : mySource (IterSource_All)
1132 //! Initialize the iterator.
1133 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1135 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1137 mySelIter.Nullify();
1138 myCurrent.Nullify();
1139 myCurrentTrs.Nullify();
1140 if (!mySeq.IsEmpty())
1142 mySource = IterSource_List;
1143 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
1145 else if (aCtx->NbCurrents() > 0)
1147 mySource = IterSource_Selected;
1149 mySelIter->InitCurrent();
1153 mySource = IterSource_All;
1154 myMapIter.Initialize (GetMapOfAIS());
1159 const TCollection_AsciiString& CurrentName() const
1161 return myCurrentName;
1164 const Handle(AIS_InteractiveObject)& Current() const
1169 const Handle(Standard_Transient)& CurrentTrs() const
1171 return myCurrentTrs;
1174 //! @return true if iterator points to valid object within collection
1175 Standard_Boolean More() const
1179 case IterSource_All: return myMapIter.More();
1180 case IterSource_List: return mySeqIter.More();
1181 case IterSource_Selected: return mySelIter->MoreCurrent();
1183 return Standard_False;
1186 //! Go to the next item.
1189 myCurrentName.Clear();
1190 myCurrentTrs.Nullify();
1191 myCurrent.Nullify();
1194 case IterSource_All:
1199 case IterSource_List:
1204 case IterSource_Selected:
1206 mySelIter->NextCurrent();
1219 case IterSource_All:
1221 if (myMapIter.More())
1223 myCurrentName = myMapIter.Key2();
1224 myCurrentTrs = myMapIter.Key1();
1225 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1229 case IterSource_List:
1231 if (mySeqIter.More())
1233 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1235 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1238 myCurrentName = mySeqIter.Value();
1239 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1240 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1244 case IterSource_Selected:
1246 if (mySelIter->MoreCurrent())
1248 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1249 myCurrent = mySelIter->Current();
1267 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1268 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1269 NCollection_Sequence<TCollection_AsciiString> mySeq;
1270 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1272 TCollection_AsciiString myCurrentName;//!< current item name
1273 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1274 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1276 IterSource mySource; //!< iterated collection
1280 //==============================================================================
1281 //function : VInteriorStyle
1282 //purpose : sets interior style of the a selected or named or displayed shape
1283 //==============================================================================
1284 static int VSetInteriorStyle (Draw_Interpretor& theDI,
1285 Standard_Integer theArgNb,
1286 const char** theArgVec)
1288 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1289 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1292 std::cerr << "Error: no active view!\n";
1296 Standard_Integer anArgIter = 1;
1297 for (; anArgIter < theArgNb; ++anArgIter)
1299 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1304 TCollection_AsciiString aName;
1305 if (theArgNb - anArgIter == 2)
1307 aName = theArgVec[anArgIter++];
1309 else if (theArgNb - anArgIter != 1)
1311 std::cout << "Error: wrong number of arguments! See usage:\n";
1312 theDI.PrintHelp (theArgVec[0]);
1315 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1316 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1317 aStyleArg.LowerCase();
1318 if (aStyleArg == "empty")
1322 else if (aStyleArg == "hollow")
1326 else if (aStyleArg == "hatch")
1330 else if (aStyleArg == "solid")
1334 else if (aStyleArg == "hiddenline")
1340 anInterStyle = aStyleArg.IntegerValue();
1342 if (anInterStyle < Aspect_IS_EMPTY
1343 || anInterStyle > Aspect_IS_HIDDENLINE)
1345 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1346 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1350 if (!aName.IsEmpty()
1351 && !GetMapOfAIS().IsBound2 (aName))
1353 std::cout << "Error: object " << aName << " is not displayed!\n";
1357 if (aCtx->HasOpenedContext())
1359 aCtx->CloseLocalContext();
1361 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1363 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1366 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1367 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1368 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1369 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1370 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
1376 //! Auxiliary structure for VAspects
1377 struct ViewerTest_AspectsChangeSet
1379 Standard_Integer ToSetColor;
1380 Quantity_Color Color;
1382 Standard_Integer ToSetLineWidth;
1383 Standard_Real LineWidth;
1385 Standard_Integer ToSetTransparency;
1386 Standard_Real Transparency;
1388 Standard_Integer ToSetMaterial;
1389 Graphic3d_NameOfMaterial Material;
1390 TCollection_AsciiString MatName;
1392 NCollection_Sequence<TopoDS_Shape> SubShapes;
1394 //! Empty constructor
1395 ViewerTest_AspectsChangeSet()
1397 Color (DEFAULT_COLOR),
1400 ToSetTransparency (0),
1403 Material (Graphic3d_NOM_DEFAULT) {}
1405 //! @return true if no changes have been requested
1406 Standard_Boolean IsEmpty() const
1408 return ToSetLineWidth == 0
1409 && ToSetTransparency == 0
1411 && ToSetMaterial == 0;
1414 //! @return true if properties are valid
1415 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1417 Standard_Boolean isOk = Standard_True;
1418 if (LineWidth <= 0.0
1419 || LineWidth > 10.0)
1421 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1422 isOk = Standard_False;
1424 if (Transparency < 0.0
1425 || Transparency > 1.0)
1427 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1428 isOk = Standard_False;
1431 && ToSetTransparency)
1433 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1434 isOk = Standard_False;
1436 if (ToSetMaterial == 1
1437 && Material == Graphic3d_NOM_DEFAULT)
1439 std::cout << "Error: unknown material " << MatName << ".\n";
1440 isOk = Standard_False;
1447 //==============================================================================
1448 //function : VAspects
1450 //==============================================================================
1451 static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1452 Standard_Integer theArgNb,
1453 const char** theArgVec)
1455 TCollection_AsciiString aCmdName (theArgVec[0]);
1456 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1457 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1460 std::cerr << "Error: no active view!\n";
1464 Standard_Integer anArgIter = 1;
1465 NCollection_Sequence<TCollection_AsciiString> aNames;
1466 for (; anArgIter < theArgNb; ++anArgIter)
1468 TCollection_AsciiString anArg = theArgVec[anArgIter];
1469 if (anUpdateTool.parseRedrawMode (anArg))
1473 else if (!anArg.IsEmpty()
1474 && anArg.Value (1) != '-')
1476 aNames.Append (anArg);
1484 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1485 aChanges.Append (ViewerTest_AspectsChangeSet());
1486 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
1488 // parse syntax of legacy commands
1489 if (aCmdName == "vsetwidth")
1491 if (aNames.IsEmpty()
1492 || !aNames.Last().IsRealValue())
1494 std::cout << "Error: not enough arguments!\n";
1497 aChangeSet->ToSetLineWidth = 1;
1498 aChangeSet->LineWidth = aNames.Last().RealValue();
1499 aNames.Remove (aNames.Length());
1501 else if (aCmdName == "vunsetwidth")
1503 aChangeSet->ToSetLineWidth = -1;
1505 else if (aCmdName == "vsetcolor")
1507 if (aNames.IsEmpty())
1509 std::cout << "Error: not enough arguments!\n";
1512 aChangeSet->ToSetColor = 1;
1513 aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString());
1514 aNames.Remove (aNames.Length());
1516 else if (aCmdName == "vunsetcolor")
1518 aChangeSet->ToSetColor = -1;
1520 else if (aCmdName == "vsettransparency")
1522 if (aNames.IsEmpty()
1523 || !aNames.Last().IsRealValue())
1525 std::cout << "Error: not enough arguments!\n";
1528 aChangeSet->ToSetTransparency = 1;
1529 aChangeSet->Transparency = aNames.Last().RealValue();
1530 aNames.Remove (aNames.Length());
1532 else if (aCmdName == "vunsettransparency")
1534 aChangeSet->ToSetTransparency = -1;
1536 else if (aCmdName == "vsetmaterial")
1538 if (aNames.IsEmpty())
1540 std::cout << "Error: not enough arguments!\n";
1543 aChangeSet->ToSetMaterial = 1;
1544 aChangeSet->MatName = aNames.Last();
1545 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1546 aNames.Remove (aNames.Length());
1548 else if (aCmdName == "vunsetmaterial")
1550 aChangeSet->ToSetMaterial = -1;
1552 else if (anArgIter >= theArgNb)
1554 std::cout << "Error: not enough arguments!\n";
1558 if (!aChangeSet->IsEmpty())
1560 anArgIter = theArgNb;
1562 for (; anArgIter < theArgNb; ++anArgIter)
1564 TCollection_AsciiString anArg = theArgVec[anArgIter];
1566 if (anArg == "-setwidth"
1567 || anArg == "-setlinewidth")
1569 if (++anArgIter >= theArgNb)
1571 std::cout << "Error: wrong syntax at " << anArg << "\n";
1574 aChangeSet->ToSetLineWidth = 1;
1575 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
1577 else if (anArg == "-unsetwidth"
1578 || anArg == "-unsetlinewidth")
1580 aChangeSet->ToSetLineWidth = -1;
1581 aChangeSet->LineWidth = 1.0;
1583 else if (anArg == "-settransp"
1584 || anArg == "-settransparency")
1586 if (++anArgIter >= theArgNb)
1588 std::cout << "Error: wrong syntax at " << anArg << "\n";
1591 aChangeSet->ToSetTransparency = 1;
1592 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1593 if (aChangeSet->Transparency >= 0.0
1594 && aChangeSet->Transparency <= Precision::Confusion())
1596 aChangeSet->ToSetTransparency = -1;
1597 aChangeSet->Transparency = 0.0;
1600 else if (anArg == "-setalpha")
1602 if (++anArgIter >= theArgNb)
1604 std::cout << "Error: wrong syntax at " << anArg << "\n";
1607 aChangeSet->ToSetTransparency = 1;
1608 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1609 if (aChangeSet->Transparency < 0.0
1610 || aChangeSet->Transparency > 1.0)
1612 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1615 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1616 if (aChangeSet->Transparency >= 0.0
1617 && aChangeSet->Transparency <= Precision::Confusion())
1619 aChangeSet->ToSetTransparency = -1;
1620 aChangeSet->Transparency = 0.0;
1623 else if (anArg == "-unsettransp"
1624 || anArg == "-unsettransparency"
1625 || anArg == "-unsetalpha"
1626 || anArg == "-opaque")
1628 aChangeSet->ToSetTransparency = -1;
1629 aChangeSet->Transparency = 0.0;
1631 else if (anArg == "-setcolor")
1633 if (++anArgIter >= theArgNb)
1635 std::cout << "Error: wrong syntax at " << anArg << "\n";
1638 aChangeSet->ToSetColor = 1;
1639 aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
1641 else if (anArg == "-unsetcolor")
1643 aChangeSet->ToSetColor = -1;
1644 aChangeSet->Color = DEFAULT_COLOR;
1646 else if (anArg == "-setmat"
1647 || anArg == "-setmaterial")
1649 if (++anArgIter >= theArgNb)
1651 std::cout << "Error: wrong syntax at " << anArg << "\n";
1654 aChangeSet->ToSetMaterial = 1;
1655 aChangeSet->MatName = theArgVec[anArgIter];
1656 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1658 else if (anArg == "-unsetmat"
1659 || anArg == "-unsetmaterial")
1661 aChangeSet->ToSetMaterial = -1;
1662 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1664 else if (anArg == "-subshape"
1665 || anArg == "-subshapes")
1667 if (aNames.IsEmpty())
1669 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1673 aChanges.Append (ViewerTest_AspectsChangeSet());
1674 aChangeSet = &aChanges.ChangeLast();
1676 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1678 Standard_CString aSubShapeName = theArgVec[anArgIter];
1679 if (*aSubShapeName == '-')
1685 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1686 if (aSubShape.IsNull())
1688 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1691 aChangeSet->SubShapes.Append (aSubShape);
1694 if (aChangeSet->SubShapes.IsEmpty())
1696 std::cerr << "Error: empty list is specified after -subshapes!\n";
1700 else if (anArg == "-unset")
1702 aChangeSet->ToSetLineWidth = -1;
1703 aChangeSet->LineWidth = 1.0;
1704 aChangeSet->ToSetTransparency = -1;
1705 aChangeSet->Transparency = 0.0;
1706 aChangeSet->ToSetColor = -1;
1707 aChangeSet->Color = DEFAULT_COLOR;
1708 aChangeSet->ToSetMaterial = -1;
1709 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1713 std::cout << "Error: wrong syntax at " << anArg << "\n";
1718 Standard_Boolean isFirst = Standard_True;
1719 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1720 aChangesIter.More(); aChangesIter.Next())
1722 if (!aChangesIter.Value().Validate (!isFirst))
1726 isFirst = Standard_False;
1729 if (aCtx->HasOpenedContext())
1731 aCtx->CloseLocalContext();
1733 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
1735 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
1736 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
1737 Handle(AIS_ColoredShape) aColoredPrs;
1738 Standard_Boolean toDisplay = Standard_False;
1739 if (aChanges.Length() > 1)
1741 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
1742 if (aShapePrs.IsNull())
1744 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
1747 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
1748 if (aColoredPrs.IsNull())
1750 aColoredPrs = new AIS_ColoredShape (aShapePrs);
1751 aCtx->Remove (aShapePrs, Standard_False);
1752 GetMapOfAIS().UnBind2 (aName);
1753 GetMapOfAIS().Bind (aColoredPrs, aName);
1754 toDisplay = Standard_True;
1755 aShapePrs = aColoredPrs;
1762 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1763 aChangeSet = &aChangesIter.ChangeValue();
1764 if (aChangeSet->ToSetMaterial == 1)
1766 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
1768 else if (aChangeSet->ToSetMaterial == -1)
1770 aCtx->UnsetMaterial (aPrs, Standard_False);
1772 if (aChangeSet->ToSetColor == 1)
1774 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
1776 else if (aChangeSet->ToSetColor == -1)
1778 aCtx->UnsetColor (aPrs, Standard_False);
1780 if (aChangeSet->ToSetTransparency == 1)
1782 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
1784 else if (aChangeSet->ToSetTransparency == -1)
1786 aCtx->UnsetTransparency (aPrs, Standard_False);
1788 if (aChangeSet->ToSetLineWidth == 1)
1790 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
1792 else if (aChangeSet->ToSetLineWidth == -1)
1794 aCtx->UnsetWidth (aPrs, Standard_False);
1797 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
1799 aChangeSet = &aChangesIter.ChangeValue();
1800 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
1801 aSubShapeIter.More(); aSubShapeIter.Next())
1803 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
1804 if (aChangeSet->ToSetColor == 1)
1806 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
1808 if (aChangeSet->ToSetLineWidth == 1)
1810 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
1812 if (aChangeSet->ToSetColor == -1
1813 || aChangeSet->ToSetLineWidth == -1)
1815 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
1821 aCtx->Display (aPrs, Standard_False);
1823 else if (!aColoredPrs.IsNull())
1825 aColoredPrs->Redisplay();
1830 Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
1831 Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
1832 if (!aNisObj.IsNull())
1834 if (aChangeSet->ToSetTransparency != 0)
1836 aNisObj->SetTransparency (aChangeSet->Transparency);
1839 if (!aNisTri.IsNull())
1841 if (aChangeSet->ToSetColor != 0)
1843 aNisTri->SetColor (aChangeSet->Color);
1845 if (aChangeSet->ToSetLineWidth != 0)
1847 aNisTri->SetLineWidth (aChangeSet->LineWidth);
1855 //==============================================================================
1856 //function : VDonly2
1858 //purpose : Display only a selected or named object
1859 // if there is no selected or named object s, nothing is done
1860 //==============================================================================
1861 static int VDonly2 (Draw_Interpretor& ,
1862 Standard_Integer theArgNb,
1863 const char** theArgVec)
1865 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1866 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1869 std::cerr << "Error: no active view!\n";
1873 if (aCtx->HasOpenedContext())
1875 aCtx->CloseLocalContext();
1878 Standard_Integer anArgIter = 1;
1879 for (; anArgIter < theArgNb; ++anArgIter)
1881 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
1887 NCollection_Map<Handle(Standard_Transient)> aDispSet;
1888 if (anArgIter >= theArgNb)
1890 // display only selected objects
1891 if (aCtx->NbCurrents() < 1)
1896 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
1898 aDispSet.Add (aCtx->Current());
1903 // display only specified objects
1904 for (; anArgIter < theArgNb; ++anArgIter)
1906 TCollection_AsciiString aName = theArgVec[anArgIter];
1907 if (GetMapOfAIS().IsBound2 (aName))
1909 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
1910 if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1912 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
1913 aCtx->Display (aShape, Standard_False);
1915 else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1917 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
1918 TheNISContext()->Display (aShape);
1920 aDispSet.Add (anObj);
1925 // weed out other objects
1926 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
1928 if (aDispSet.Contains (anIter.Key1()))
1933 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
1935 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
1936 aCtx->Erase (aShape, Standard_False);
1938 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
1940 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
1941 TheNISContext()->Erase (aShape);
1947 //==============================================================================
1948 //function : VRemove
1949 //purpose : Removes selected or named objects.
1950 // If there is no selected or named objects,
1951 // all objects in the viewer can be removed with argument -all.
1952 // If -context is in arguments, the object is not deleted from the map of
1953 // objects (deleted only from the current context).
1954 //==============================================================================
1955 int VRemove (Draw_Interpretor& theDI,
1956 Standard_Integer theArgNb,
1957 const char** theArgVec)
1959 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
1960 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
1963 std::cout << "Error: no active view!\n";
1967 aCtx->CloseAllContexts (Standard_False);
1969 Standard_Boolean isContextOnly = Standard_False;
1970 Standard_Boolean toRemoveAll = Standard_False;
1971 Standard_Boolean toPrintInfo = Standard_True;
1973 Standard_Integer anArgIter = 1;
1974 for (; anArgIter < theArgNb; ++anArgIter)
1976 TCollection_AsciiString anArg = theArgVec[anArgIter];
1978 if (anArg == "-context")
1980 isContextOnly = Standard_True;
1982 else if (anArg == "-all")
1984 toRemoveAll = Standard_True;
1986 else if (anArg == "-noinfo")
1988 toPrintInfo = Standard_False;
1990 else if (!anUpdateTool.parseRedrawMode (anArg))
1996 && anArgIter < theArgNb)
1998 std::cout << "Error: wrong syntax!\n";
2002 NCollection_List<TCollection_AsciiString> anIONameList;
2005 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2006 anIter.More(); anIter.Next())
2008 anIONameList.Append (anIter.Key2());
2011 else if (anArgIter < theArgNb) // removed objects names are in argument list
2013 for (; anArgIter < theArgNb; ++anArgIter)
2015 TCollection_AsciiString aName = theArgVec[anArgIter];
2016 if (!GetMapOfAIS().IsBound2 (aName))
2018 theDI << aName.ToCString() << " was not bound to some object.\n";
2022 const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
2024 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
2027 if (anIO->GetContext() != aCtx)
2029 theDI << aName.ToCString() << " was not displayed in current context.\n";
2030 theDI << "Please activate view with this object displayed and try again.\n";
2034 anIONameList.Append (aName);
2038 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
2039 if (!aNisIO.IsNull())
2041 anIONameList.Append (aName);
2045 else if (aCtx->NbCurrents() > 0
2046 || TheNISContext()->GetSelected().Extent() > 0)
2048 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2049 anIter.More(); anIter.Next())
2051 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2054 if (!aCtx->IsCurrent (anIO))
2059 anIONameList.Append (anIter.Key2());
2063 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2064 if (!aNisIO.IsNull())
2066 if (!TheNISContext()->IsSelected (aNisIO))
2071 anIONameList.Append (anIter.Key2());
2076 // Unbind all removed objects from the map of displayed IO.
2077 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2078 anIter.More(); anIter.Next())
2080 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2083 aCtx->Remove (anIO, Standard_False);
2086 theDI << anIter.Value().ToCString() << " was removed\n";
2091 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
2092 if (!aNisIO.IsNull())
2094 TheNISContext()->Remove (aNisIO);
2097 theDI << anIter.Value().ToCString() << " was removed\n";
2103 GetMapOfAIS().UnBind2 (anIter.Value());
2109 //==============================================================================
2111 //purpose : Erase some selected or named objects
2112 // if there is no selected or named objects, the whole viewer is erased
2113 //==============================================================================
2114 int VErase (Draw_Interpretor& theDI,
2115 Standard_Integer theArgNb,
2116 const char** theArgVec)
2118 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2119 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2122 std::cout << "Error: no active view!\n";
2125 aCtx->CloseAllContexts (Standard_False);
2127 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2129 Standard_Integer anArgIter = 1;
2130 for (; anArgIter < theArgNb; ++anArgIter)
2132 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2138 if (anArgIter < theArgNb)
2142 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2146 // has a list of names
2147 for (; anArgIter < theArgNb; ++anArgIter)
2149 TCollection_AsciiString aName = theArgVec[anArgIter];
2150 if (!GetMapOfAIS().IsBound2 (aName))
2155 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2156 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2157 theDI << aName.ToCString() << " ";
2160 aCtx->Erase (anIO, Standard_False);
2164 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
2165 if (!aNisIO.IsNull())
2167 TheNISContext()->Erase (aNisIO);
2172 else if (!toEraseAll
2173 && aCtx->NbCurrents() > 0)
2175 // remove all currently selected objects
2176 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2177 anIter.More(); anIter.Next())
2179 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2181 && aCtx->IsCurrent (anIO))
2183 theDI << anIter.Key2().ToCString() << " ";
2184 aCtx->Erase (anIO, Standard_False);
2190 // erase entire viewer
2191 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2192 anIter.More(); anIter.Next())
2194 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2197 aCtx->Erase (anIO, Standard_False);
2201 const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2202 if (!aNisIO.IsNull())
2204 TheNISContext()->Erase (aNisIO);
2212 //==============================================================================
2213 //function : VDisplayAll
2215 //purpose : Display all the objects of the Map
2216 //==============================================================================
2217 static int VDisplayAll (Draw_Interpretor& ,
2218 Standard_Integer theArgNb,
2219 const char** theArgVec)
2222 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2223 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2226 std::cout << "Error: no active view!\n";
2230 Standard_Integer anArgIter = 1;
2231 for (; anArgIter < theArgNb; ++anArgIter)
2233 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
2238 if (anArgIter < theArgNb)
2240 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2244 if (aCtx->HasOpenedContext())
2246 aCtx->CloseLocalContext();
2249 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2250 anIter.More(); anIter.Next())
2252 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2254 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2255 aCtx->Erase (aShape, Standard_False);
2257 else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
2259 const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2260 TheNISContext()->Erase (aShape);
2264 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2265 anIter.More(); anIter.Next())
2267 if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
2269 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2270 aCtx->Display (aShape, Standard_False);
2272 else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
2274 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
2275 TheNISContext()->Display (aShape);
2281 //! Auxiliary method to find presentation
2282 inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2283 const Handle(AIS_InteractiveObject)& theIO,
2284 const Standard_Integer theMode)
2288 return Handle(PrsMgr_Presentation)();
2293 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2295 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2298 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2300 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2302 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2304 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2306 return Handle(PrsMgr_Presentation)();
2309 enum ViewerTest_BndAction
2316 //! Auxiliary method to print bounding box of presentation
2317 inline void bndPresentation (Draw_Interpretor& theDI,
2318 const Handle(PrsMgr_Presentation)& thePrs,
2319 const TCollection_AsciiString& theName,
2320 const ViewerTest_BndAction theAction)
2324 case BndAction_Hide:
2326 thePrs->Presentation()->GraphicUnHighlight();
2329 case BndAction_Show:
2331 thePrs->Presentation()->BoundBox();
2334 case BndAction_Print:
2336 Graphic3d_Vec3d aMin, aMax;
2337 thePrs->Presentation()->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2338 aMax.x(), aMax.y(), aMax.z());
2339 theDI << theName << "\n"
2340 << aMin.x() << " " << aMin.y() << " " << aMin.z() << " "
2341 << aMax.x() << " " << aMax.y() << " " << aMax.z() << "\n";
2347 //==============================================================================
2348 //function : VBounding
2350 //==============================================================================
2351 int VBounding (Draw_Interpretor& theDI,
2352 Standard_Integer theArgNb,
2353 const char** theArgVec)
2355 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2356 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2359 std::cout << "Error: no active view!\n";
2363 ViewerTest_BndAction anAction = BndAction_Show;
2364 Standard_Integer aMode = -1;
2366 Standard_Integer anArgIter = 1;
2367 for (; anArgIter < theArgNb; ++anArgIter)
2369 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2371 if (anArg == "-print")
2373 anAction = BndAction_Print;
2375 else if (anArg == "-show")
2377 anAction = BndAction_Show;
2379 else if (anArg == "-hide")
2381 anAction = BndAction_Hide;
2383 else if (anArg == "-mode")
2385 if (++anArgIter >= theArgNb)
2387 std::cout << "Error: wrong syntax at " << anArg << "\n";
2390 aMode = Draw::Atoi (theArgVec[anArgIter]);
2392 else if (!anUpdateTool.parseRedrawMode (anArg))
2398 if (anArgIter < theArgNb)
2400 // has a list of names
2401 for (; anArgIter < theArgNb; ++anArgIter)
2403 TCollection_AsciiString aName = theArgVec[anArgIter];
2404 if (!GetMapOfAIS().IsBound2 (aName))
2406 std::cout << "Error: presentation " << aName << " does not exist\n";
2410 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2411 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2414 std::cout << "Error: presentation " << aName << " does not exist\n";
2417 bndPresentation (theDI, aPrs, aName, anAction);
2420 else if (aCtx->NbCurrents() > 0)
2422 // remove all currently selected objects
2423 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2425 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2426 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2429 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2436 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2437 anIter.More(); anIter.Next())
2439 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2440 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2443 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2450 //==============================================================================
2451 //function : VTexture
2453 //==============================================================================
2454 Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
2456 TCollection_AsciiString aCommandName (theArgv[0]);
2458 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
2459 if (aCommandName == "vtexture")
2463 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2464 std::cout << "Type help for more information.\n";
2468 // look for options of vtexture command
2469 TCollection_AsciiString aParseKey;
2470 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2472 TCollection_AsciiString anArg (theArgv [anArgIt]);
2475 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2478 aParseKey.Remove (1);
2479 aParseKey.UpperCase();
2480 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
2484 if (aParseKey.IsEmpty())
2489 aMapOfArgs(aParseKey)->Append (anArg);
2492 else if (aCommandName == "vtexscale"
2493 || aCommandName == "vtexorigin"
2494 || aCommandName == "vtexrepeat")
2496 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2497 // equal to -scale, -origin, -repeat options of vtexture command
2498 if (theArgsNb < 2 || theArgsNb > 4)
2500 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2501 std::cout << "Type help for more information.\n";
2505 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
2508 anArgs->Append ("OFF");
2510 else if (theArgsNb == 4)
2512 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2513 anArgs->Append (TCollection_AsciiString (theArgv[3]));
2516 TCollection_AsciiString anArgKey;
2517 if (aCommandName == "vtexscale")
2521 else if (aCommandName == "vtexorigin")
2523 anArgKey = "ORIGIN";
2527 anArgKey = "REPEAT";
2530 aMapOfArgs.Bind (anArgKey, anArgs);
2532 else if (aCommandName == "vtexdefault")
2534 // scan for parameters of vtexdefault command
2535 // equal to -default option of vtexture command
2536 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
2539 // Check arguments for validity
2540 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
2541 for (; aMapIt.More(); aMapIt.Next())
2543 const TCollection_AsciiString& aKey = aMapIt.Key();
2544 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
2546 // -scale, -origin, -repeat: one argument "off", or two real values
2547 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
2548 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2549 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
2554 // -modulate: single argument "on" / "off"
2555 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
2560 // -default: no arguments
2561 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
2566 TCollection_AsciiString aLowerKey;
2569 aLowerKey.LowerCase();
2570 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2571 std::cout << "Type help for more information.\n";
2575 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2576 if (anAISContext.IsNull())
2578 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2582 Standard_Integer aPreviousMode = 0;
2584 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2586 TCollection_AsciiString aShapeName (theArgv[1]);
2587 Handle(AIS_InteractiveObject) anIO;
2589 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2590 if (aMapOfIO.IsBound2 (aShapeName))
2592 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2597 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2601 Handle(AIS_TexturedShape) aTexturedIO;
2602 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2604 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2605 aPreviousMode = aTexturedIO->DisplayMode();
2609 anAISContext->Clear (anIO, Standard_False);
2610 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2611 GetMapOfAIS().UnBind1 (anIO);
2612 GetMapOfAIS().UnBind2 (aShapeName);
2613 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2616 // -------------------------------------------
2617 // Turn texturing on/off - only for vtexture
2618 // -------------------------------------------
2620 if (aCommandName == "vtexture")
2622 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
2624 if (aTextureArg.IsEmpty())
2626 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
2627 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
2629 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
2630 if (aPreviousMode == 3)
2632 anAISContext->RecomputePrsOnly (aTexturedIO);
2635 anAISContext->Display (aTexturedIO, Standard_True);
2638 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
2640 if (aTextureArg == "?")
2642 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
2644 theDi << "\n Files in current directory : \n" << "\n";
2645 theDi.Eval ("glob -nocomplain *");
2647 TCollection_AsciiString aCmnd ("glob -nocomplain ");
2648 aCmnd += aTextureFolder;
2651 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
2652 theDi.Eval (aCmnd.ToCString());
2657 aTexturedIO->SetTextureFileName (aTextureArg);
2662 // ------------------------------------
2663 // Process other options and commands
2664 // ------------------------------------
2666 Handle(TColStd_HSequenceOfAsciiString) aValues;
2667 if (aMapOfArgs.Find ("DEFAULT", aValues))
2669 aTexturedIO->SetTextureRepeat (Standard_False);
2670 aTexturedIO->SetTextureOrigin (Standard_False);
2671 aTexturedIO->SetTextureScale (Standard_False);
2672 aTexturedIO->EnableTextureModulate();
2676 if (aMapOfArgs.Find ("SCALE", aValues))
2678 if (aValues->Value(1) != "OFF")
2680 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2684 aTexturedIO->SetTextureScale (Standard_False);
2688 if (aMapOfArgs.Find ("ORIGIN", aValues))
2690 if (aValues->Value(1) != "OFF")
2692 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2696 aTexturedIO->SetTextureOrigin (Standard_False);
2700 if (aMapOfArgs.Find ("REPEAT", aValues))
2702 if (aValues->Value(1) != "OFF")
2704 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
2708 aTexturedIO->SetTextureRepeat (Standard_False);
2712 if (aMapOfArgs.Find ("MODULATE", aValues))
2714 if (aValues->Value(1) == "ON")
2716 aTexturedIO->EnableTextureModulate();
2720 aTexturedIO->DisableTextureModulate();
2725 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
2727 anAISContext->RecomputePrsOnly (aTexturedIO);
2731 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
2732 anAISContext->Display (aTexturedIO, Standard_True);
2733 anAISContext->Update (aTexturedIO,Standard_True);
2739 //==============================================================================
2740 //function : VDisplay2
2742 //purpose : Display an object from its name
2743 //==============================================================================
2744 static int VDisplay2 (Draw_Interpretor& theDI,
2745 Standard_Integer theArgNb,
2746 const char** theArgVec)
2748 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2751 std::cout << theArgVec[0] << "Error: wrong syntax!\n";
2754 else if (aCtx.IsNull())
2756 ViewerTest::ViewerInit();
2757 std::cout << "Command vinit should be called before!\n";
2759 aCtx = ViewerTest::GetAISContext();
2762 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2763 if (aCtx->HasOpenedContext())
2765 aCtx->CloseLocalContext();
2768 Standard_Integer isMutable = -1;
2769 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2771 const TCollection_AsciiString aName = theArgVec[anArgIter];
2772 TCollection_AsciiString aNameCase = aName;
2773 aNameCase.LowerCase();
2774 if (anUpdateTool.parseRedrawMode (aName))
2778 else if (aNameCase == "-mutable")
2783 else if (!GetMapOfAIS().IsBound2 (aName))
2785 // create the AIS_Shape from a name
2786 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
2787 if (!aShape.IsNull())
2789 if (isMutable != -1)
2791 aShape->SetMutable (isMutable == 1);
2793 GetMapOfAIS().Bind (aShape, aName);
2794 aCtx->Display (aShape, Standard_False);
2799 Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2800 if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
2802 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
2803 if (isMutable != -1)
2805 aShape->SetMutable (isMutable == 1);
2808 if (aShape->Type() == AIS_KOI_Datum)
2810 aCtx->Display (aShape, Standard_False);
2814 theDI << "Display " << aName.ToCString() << "\n";
2815 // get the Shape from a name
2816 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
2818 // update the Shape in the AIS_Shape
2819 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
2820 if (!aShapePrs.IsNull())
2822 aShapePrs->Set (aNewShape);
2824 aCtx->Redisplay (aShape, Standard_False);
2825 aCtx->Display (aShape, Standard_False);
2828 else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
2830 Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
2831 TheNISContext()->Display (aShape);
2837 //===============================================================================================
2838 //function : VUpdate
2840 //===============================================================================================
2841 static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2843 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2844 if (aContextAIS.IsNull())
2846 std::cout << theArgVec[0] << "AIS context is not available.\n";
2852 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
2856 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
2858 AIS_ListOfInteractive aListOfIO;
2860 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
2862 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
2864 Handle(AIS_InteractiveObject) anAISObj;
2865 if (anAISMap.IsBound2 (aName))
2867 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
2870 if (anAISObj.IsNull())
2872 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
2876 aListOfIO.Append (anAISObj);
2879 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
2880 for (; anIOIt.More(); anIOIt.Next())
2882 aContextAIS->Update (anIOIt.Value(), Standard_False);
2885 aContextAIS->UpdateCurrentViewer();
2890 //==============================================================================
2892 //purpose : Test the annimation of an object along a
2893 // predifined trajectory
2894 //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
2895 //==============================================================================
2897 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
2900 if (TheAISContext()->HasOpenedContext())
2901 TheAISContext()->CloseLocalContext();
2903 Standard_Real Step=4*M_PI/180;
2904 Standard_Real Angle=0;
2906 Handle(AIS_InteractiveObject) aIO;
2907 if (GetMapOfAIS().IsBound2(argv[1]))
2908 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
2912 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
2916 if (Draw::Atoi(argv[3])==1 ) {
2917 di<<" Primitives sensibles OFF"<<"\n";
2918 TheAISContext()->Deactivate(aIO);
2921 di<<" Primitives sensibles ON"<<"\n";
2923 // Movement par transformation
2924 if(Draw::Atoi(argv[2]) ==1) {
2925 di<<" Calcul par Transformation"<<"\n";
2926 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2930 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
2931 TheAISContext()->SetLocation(aShape,myTransfo);
2932 TheAISContext() ->UpdateCurrentViewer();
2937 di<<" Calcul par Locations"<<"\n";
2938 gp_Trsf myAngleTrsf;
2939 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
2940 TopLoc_Location myDeltaAngle (myAngleTrsf);
2941 TopLoc_Location myTrueLoc;
2943 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
2946 myTrueLoc=myTrueLoc*myDeltaAngle;
2947 TheAISContext()->SetLocation(aShape,myTrueLoc );
2948 TheAISContext() ->UpdateCurrentViewer();
2951 if (Draw::Atoi(argv[3])==1 ){
2952 // On reactive la selection des primitives sensibles
2953 TheAISContext()->Activate(aIO,0);
2955 a3DView() -> Redraw();
2957 di<<" Temps ecoule "<<"\n";
2963 //==================================================================================
2964 // Function : VAnimation
2965 //==================================================================================
2966 static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
2968 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
2972 Standard_Real thread = 4;
2973 Standard_Real angleA=0;
2974 Standard_Real angleB;
2976 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
2979 TopoDS_Shape CrankArm;
2980 TopoDS_Shape CylinderHead;
2981 TopoDS_Shape Propeller;
2982 TopoDS_Shape EngineBlock;
2984 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
2985 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
2986 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
2987 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
2988 BRepTools::Read(CrankArm,argv[1],B);
2989 BRepTools::Read(CylinderHead,argv[2],B);
2990 BRepTools::Read(Propeller,argv[3],B);
2991 BRepTools::Read(EngineBlock,argv[4],B);
2993 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
2999 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3000 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3001 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3002 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3004 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3005 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3006 GetMapOfAIS().Bind(myAisCrankArm,"c");
3007 GetMapOfAIS().Bind(myAisPropeller,"d");
3009 myAisCylinderHead->SetMutable (Standard_True);
3010 myAisEngineBlock ->SetMutable (Standard_True);
3011 myAisCrankArm ->SetMutable (Standard_True);
3012 myAisPropeller ->SetMutable (Standard_True);
3014 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3015 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3016 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3018 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3019 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3020 TheAISContext()->Display (myAisCrankArm, Standard_False);
3021 TheAISContext()->Display (myAisPropeller, Standard_False);
3023 TheAISContext()->Deactivate(myAisCylinderHead);
3024 TheAISContext()->Deactivate(myAisEngineBlock );
3025 TheAISContext()->Deactivate(myAisCrankArm );
3026 TheAISContext()->Deactivate(myAisPropeller );
3028 // Boucle de mouvement
3029 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
3031 angleA = thread*myAngle*M_PI/180;
3032 X = Sin(angleA)*3/8;
3033 angleB = atan(X / Sqrt(-X * X + 1));
3034 Standard_Real decal(25*0.6);
3037 //Build a transformation on the display
3038 gp_Trsf aPropellerTrsf;
3039 aPropellerTrsf.SetRotation(Ax1,angleA);
3040 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3042 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));
3043 gp_Trsf aCrankArmTrsf;
3044 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3045 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3047 TheAISContext()->UpdateCurrentViewer();
3050 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3051 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
3053 myAisCrankArm ->ResetTransformation();
3054 myAisPropeller->ResetTransformation();
3056 myAisCrankArm -> Set(myNewCrankArm );
3057 myAisPropeller -> Set(myNewPropeller);
3059 TheAISContext()->Activate(myAisCylinderHead,0);
3060 TheAISContext()->Activate(myAisEngineBlock,0 );
3061 TheAISContext()->Activate(myAisCrankArm ,0 );
3062 TheAISContext()->Activate(myAisPropeller ,0 );
3068 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3069 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3071 TheAISContext()->UpdateCurrentViewer();
3072 a3DView()->Redraw();
3081 //==============================================================================
3082 //function : VShading
3083 //purpose : Sharpen or roughten the quality of the shading
3084 //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3085 //==============================================================================
3086 static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3088 Standard_Real myDevCoef;
3089 Handle(AIS_InteractiveObject) TheAisIO;
3092 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3094 if (TheAISContext()->HasOpenedContext())
3095 TheAISContext()->CloseLocalContext();
3100 myDevCoef =Draw::Atof(argv[2]);
3103 TCollection_AsciiString name=argv[1];
3104 if (GetMapOfAIS().IsBound2(name ))
3105 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
3106 if (TheAisIO.IsNull())
3107 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
3110 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
3112 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
3114 TheAISContext()->Redisplay(TheAisIO);
3117 //==============================================================================
3118 //function : HaveMode
3119 //use : VActivatedModes
3120 //==============================================================================
3121 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3123 Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
3125 TColStd_ListOfInteger List;
3126 TheAISContext()->ActivatedModes (TheAisIO,List);
3127 TColStd_ListIteratorOfListOfInteger it;
3128 Standard_Boolean Found=Standard_False;
3129 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
3130 if (it.Value()==mode ) Found=Standard_True;
3137 //==============================================================================
3138 //function : VActivatedMode
3140 //purpose : permet d'attribuer a chacune des shapes un mode d'activation
3141 // (edges,vertex...)qui lui est propre et le mode de selection standard.
3142 // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
3143 // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
3144 // qu'un nom et qu'un mode.
3145 //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
3146 //==============================================================================
3147 #include <AIS_ListIteratorOfListOfInteractive.hxx>
3149 static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3152 Standard_Boolean ThereIsName = Standard_False ;
3154 if(!a3DView().IsNull()){
3156 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
3157 // verification des arguments
3159 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
3160 ThereIsName = (argc == 3);
3164 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
3166 di<<" R.A.Z de tous les modes de selecion"<<"\n";
3167 di<<" Fermeture du Context local"<<"\n";
3168 if (TheAISContext()->HasOpenedContext())
3169 TheAISContext()->CloseLocalContext();
3173 // IL n'y a aps de nom de shape passe en argument
3174 if (HaveToSet && !ThereIsName){
3175 Standard_Integer aMode=Draw::Atoi(argv [1]);
3177 const char *cmode="???";
3179 case 0: cmode = "Shape"; break;
3180 case 1: cmode = "Vertex"; break;
3181 case 2: cmode = "Edge"; break;
3182 case 3: cmode = "Wire"; break;
3183 case 4: cmode = "Face"; break;
3184 case 5: cmode = "Shell"; break;
3185 case 6: cmode = "Solid"; break;
3186 case 7: cmode = "Compound"; break;
3189 if( !TheAISContext()->HasOpenedContext() ) {
3190 // il n'y a pas de Context local d'ouvert
3191 // on en ouvre un et on charge toutes les shapes displayees
3192 // on load tous les objets displayees et on Activate les objets de la liste
3193 AIS_ListOfInteractive ListOfIO;
3194 // on sauve dans une AISListOfInteractive tous les objets currents
3195 if (TheAISContext()->NbCurrents()>0 ){
3196 TheAISContext()->UnhilightCurrents(Standard_False);
3198 for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
3199 ListOfIO.Append(TheAISContext()->Current() );
3203 TheAISContext()->OpenLocalContext(Standard_False);
3204 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3207 Handle(AIS_InteractiveObject) aIO =
3208 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3210 TheAISContext()->Load(aIO,0,Standard_False);
3213 // traitement des objets qui etaient currents dans le Contexte global
3214 if (!ListOfIO.IsEmpty() ) {
3215 // il y avait des objets currents
3216 AIS_ListIteratorOfListOfInteractive iter;
3217 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
3218 Handle(AIS_InteractiveObject) aIO=iter.Value();
3219 TheAISContext()->Activate(aIO,aMode);
3220 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3224 // On applique le mode a tous les objets displayes
3225 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3226 it2 (GetMapOfAIS());
3228 Handle(AIS_InteractiveObject) aIO =
3229 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
3230 if (!aIO.IsNull()) {
3231 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
3232 TheAISContext()->Activate(aIO,aMode);
3241 // un Context local est deja ouvert
3242 // Traitement des objets du Context local
3243 if (TheAISContext()->NbSelected()>0 ){
3244 TheAISContext()->UnhilightSelected(Standard_False);
3245 // il y a des objets selected,on les parcourt
3246 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
3247 Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive();
3250 if (HaveMode(aIO,aMode) ) {
3251 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3252 TheAISContext()->Deactivate(aIO,aMode);
3255 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3256 TheAISContext()->Activate(aIO,aMode);
3262 // il n'y a pas d'objets selected
3263 // tous les objets diplayes sont traites
3264 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
3267 Handle(AIS_InteractiveObject) aIO =
3268 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3269 if (!aIO.IsNull()) {
3270 if (HaveMode(aIO,aMode) ) {
3271 di<<" Mode: "<<cmode<<" OFF pour "
3272 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3273 TheAISContext()->Deactivate(aIO,aMode);
3276 di<<" Mode: "<<cmode<<" ON pour"
3277 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3278 TheAISContext()->Activate(aIO,aMode);
3286 else if (HaveToSet && ThereIsName){
3287 Standard_Integer aMode=Draw::Atoi(argv [2]);
3288 Handle(AIS_InteractiveObject) aIO =
3289 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3291 if (!aIO.IsNull()) {
3292 const char *cmode="???";
3295 case 0: cmode = "Shape"; break;
3296 case 1: cmode = "Vertex"; break;
3297 case 2: cmode = "Edge"; break;
3298 case 3: cmode = "Wire"; break;
3299 case 4: cmode = "Face"; break;
3300 case 5: cmode = "Shell"; break;
3301 case 6: cmode = "Solid"; break;
3302 case 7: cmode = "Compound"; break;
3305 if( !TheAISContext()->HasOpenedContext() ) {
3306 TheAISContext()->OpenLocalContext(Standard_False);
3307 // On charge tous les objets de la map
3308 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
3310 Handle(AIS_InteractiveObject) aShape=
3311 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
3312 if (!aShape.IsNull())
3313 TheAISContext()->Load(aShape,0,Standard_False);
3316 TheAISContext()->Activate(aIO,aMode);
3317 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3321 // un Context local est deja ouvert
3322 if (HaveMode(aIO,aMode) ) {
3323 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
3324 TheAISContext()->Deactivate(aIO,aMode);
3327 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
3328 TheAISContext()->Activate(aIO,aMode);
3337 //! Auxiliary method to print Interactive Object information
3338 static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
3339 const Handle(Standard_Transient)& theObject,
3340 Draw_Interpretor& theDI)
3342 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
3345 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
3349 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
3350 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
3351 << (theDetected.Contains (anObj) ? " Detected" : " ")
3353 if (anObj->Type() == AIS_KOI_Datum)
3356 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
3357 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
3358 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
3359 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
3360 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
3361 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
3362 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
3365 else if (anObj->Type() == AIS_KOI_Shape
3366 && anObj->Signature() == 0)
3368 theDI << " AIS_Shape";
3370 else if (anObj->Type() == AIS_KOI_Relation)
3372 // AIS_Dimention and AIS_Relation
3373 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
3374 switch (aRelation->KindOfDimension())
3376 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
3377 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
3378 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
3379 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
3380 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
3381 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
3382 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
3383 default: theDI << " UNKNOWN dimension"; break;
3388 theDI << " UserPrs";
3390 theDI << " (" << theObject->DynamicType()->Name() << ")";
3393 //! Print information about locally selected sub-shapes
3394 static void localCtxInfo (Draw_Interpretor& theDI)
3396 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3397 if (!aCtx->HasOpenedContext())
3402 TCollection_AsciiString aPrevName;
3403 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
3404 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
3406 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
3407 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
3408 if (aSubShape.IsNull()
3409 || aShapeIO.IsNull()
3410 || !GetMapOfAIS().IsBound1 (aShapeIO))
3415 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
3416 TopTools_MapOfShape aFilter;
3417 Standard_Integer aNumber = 0;
3418 const TopoDS_Shape aShape = aShapeIO->Shape();
3419 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
3420 anIter.More(); anIter.Next())
3422 if (!aFilter.Add (anIter.Current()))
3424 continue; // filter duplicates
3428 if (!anIter.Current().IsSame (aSubShape))
3433 Standard_CString aShapeName = NULL;
3434 switch (aSubShape.ShapeType())
3436 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
3437 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
3438 case TopAbs_SOLID: aShapeName = " Solid"; break;
3439 case TopAbs_SHELL: aShapeName = " Shell"; break;
3440 case TopAbs_FACE: aShapeName = " Face"; break;
3441 case TopAbs_WIRE: aShapeName = " Wire"; break;
3442 case TopAbs_EDGE: aShapeName = " Edge"; break;
3443 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
3445 case TopAbs_SHAPE: aShapeName = " Shape"; break;
3448 if (aParentName != aPrevName)
3450 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
3451 aPrevName = aParentName;
3453 theDI << " " << aShapeName << " #" << aNumber << "\n";
3459 //==============================================================================
3462 //Draw arg : vstate [nameA] ... [nameN]
3463 //==============================================================================
3464 static Standard_Integer VState (Draw_Interpretor& theDI,
3465 Standard_Integer theArgNb,
3466 Standard_CString* theArgVec)
3468 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
3471 std::cerr << "Error: No opened viewer!\n";
3475 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
3476 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
3478 aDetected.Add (aCtx->DetectedCurrentObject());
3481 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
3485 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3487 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
3488 if (!GetMapOfAIS().IsBound2 (anObjName))
3490 theDI << anObjName << " doesn't exist!\n";
3494 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
3495 TCollection_AsciiString aName = anObjName;
3496 aName.LeftJustify (20, ' ');
3497 theDI << " " << aName << " ";
3498 objInfo (aDetected, anObjTrans, theDI);
3504 if (aCtx->NbCurrents() > 0
3507 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
3509 Handle(AIS_InteractiveObject) anObj = aCtx->Current();
3510 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
3511 aName.LeftJustify (20, ' ');
3512 theDI << aName << " ";
3513 objInfo (aDetected, anObj, theDI);
3519 theDI << "Neutral-point state:\n";
3520 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3521 anObjIter.More(); anObjIter.Next())
3523 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
3529 TCollection_AsciiString aName = anObjIter.Key2();
3530 aName.LeftJustify (20, ' ');
3531 theDI << " " << aName << " ";
3532 objInfo (aDetected, anObj, theDI);
3535 localCtxInfo (theDI);
3539 //=======================================================================
3540 //function : PickObjects
3542 //=======================================================================
3543 Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
3544 const AIS_KindOfInteractive TheType,
3545 const Standard_Integer TheSignature,
3546 const Standard_Integer MaxPick)
3548 Handle(AIS_InteractiveObject) IO;
3549 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3551 // step 1: prepare the data
3553 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3554 TheAISContext()->AddFilter(F1);
3557 // step 2 : wait for the selection...
3558 // Standard_Boolean IsGood (Standard_False);
3559 // Standard_Integer NbPick(0);
3560 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
3561 Standard_Integer NbPickFail(0);
3562 Standard_Integer argccc = 5;
3563 const char *bufff[] = { "A", "B", "C","D", "E" };
3564 const char **argvvv = (const char **) bufff;
3567 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3568 while(ViewerMainLoop(argccc,argvvv)){}
3569 Standard_Integer NbStored = TheAISContext()->NbSelected();
3570 if((unsigned int ) NbStored != NbPickGood)
3571 NbPickGood= NbStored;
3574 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
3577 // step3 get result.
3579 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3581 Standard_Integer i(0);
3582 for(TheAISContext()->InitSelected();
3583 TheAISContext()->MoreSelected();
3584 TheAISContext()->NextSelected()){
3586 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
3587 arr->SetValue(i,IO2);
3592 TheAISContext()->CloseLocalContext(curindex);
3594 return Standard_True;
3598 //=======================================================================
3599 //function : PickObject
3601 //=======================================================================
3602 Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
3603 const Standard_Integer TheSignature,
3604 const Standard_Integer MaxPick)
3606 Handle(AIS_InteractiveObject) IO;
3607 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
3609 // step 1: prepare the data
3612 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
3613 TheAISContext()->AddFilter(F1);
3616 // step 2 : wait for the selection...
3617 Standard_Boolean IsGood (Standard_False);
3618 Standard_Integer NbPick(0);
3619 Standard_Integer argccc = 5;
3620 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3621 const char **argvvv = (const char **) bufff;
3624 while(!IsGood && NbPick<= MaxPick){
3625 while(ViewerMainLoop(argccc,argvvv)){}
3626 IsGood = (TheAISContext()->NbSelected()>0) ;
3628 cout<<"Nb Pick :"<<NbPick<<endl;
3632 // step3 get result.
3634 TheAISContext()->InitSelected();
3635 IO = TheAISContext()->SelectedInteractive();
3639 TheAISContext()->CloseLocalContext(curindex);
3643 //=======================================================================
3644 //function : PickShape
3645 //purpose : First Activate the rightmode + Put Filters to be able to
3646 // pick objets that are of type <TheType>...
3647 //=======================================================================
3649 TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
3650 const Standard_Integer MaxPick)
3653 // step 1: prepare the data
3655 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3656 TopoDS_Shape result;
3658 if(TheType==TopAbs_SHAPE){
3659 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3660 TheAISContext()->AddFilter(F1);
3663 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3664 TheAISContext()->AddFilter(TF);
3665 TheAISContext()->ActivateStandardMode(TheType);
3670 // step 2 : wait for the selection...
3671 Standard_Boolean NoShape (Standard_True);
3672 Standard_Integer NbPick(0);
3673 Standard_Integer argccc = 5;
3674 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
3675 const char **argvvv = (const char **) bufff;
3678 while(NoShape && NbPick<= MaxPick){
3679 while(ViewerMainLoop(argccc,argvvv)){}
3680 NoShape = (TheAISContext()->NbSelected()==0) ;
3682 cout<<"Nb Pick :"<<NbPick<<endl;
3685 // step3 get result.
3689 TheAISContext()->InitSelected();
3690 if(TheAISContext()->HasSelectedShape())
3691 result = TheAISContext()->SelectedShape();
3693 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3694 result = (*((Handle(AIS_Shape)*) &IO))->Shape();
3699 TheAISContext()->CloseLocalContext(curindex);
3705 //=======================================================================
3706 //function : PickShapes
3708 //=======================================================================
3709 Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
3710 Handle(TopTools_HArray1OfShape)& thearr,
3711 const Standard_Integer MaxPick)
3714 Standard_Integer Taille = thearr->Length();
3716 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
3718 // step 1: prepare the data
3719 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
3720 if(TheType==TopAbs_SHAPE){
3721 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
3722 TheAISContext()->AddFilter(F1);
3725 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
3726 TheAISContext()->AddFilter(TF);
3727 TheAISContext()->ActivateStandardMode(TheType);
3731 // step 2 : wait for the selection...
3733 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
3734 Standard_Integer NbPickFail(0);
3735 Standard_Integer argccc = 5;
3736 const char *bufff[] = { "A", "B", "C","D", "E" };
3737 const char **argvvv = (const char **) bufff;
3740 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
3741 while(ViewerMainLoop(argccc,argvvv)){}
3742 Standard_Integer NbStored = TheAISContext()->NbSelected();
3743 if((unsigned int ) NbStored != NbPickGood)
3744 NbPickGood= NbStored;
3747 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
3750 // step3 get result.
3752 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
3754 Standard_Integer i(0);
3755 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
3757 if(TheAISContext()->HasSelectedShape())
3758 thearr->SetValue(i,TheAISContext()->SelectedShape());
3760 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
3761 thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
3765 TheAISContext()->CloseLocalContext(curindex);
3766 return Standard_True;
3770 //=======================================================================
3771 //function : VPickShape
3773 //=======================================================================
3774 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3776 TopoDS_Shape PickSh;
3777 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
3780 theType = TopAbs_SHAPE;
3782 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
3783 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
3784 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
3785 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
3786 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
3787 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
3788 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
3791 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
3792 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
3794 TCollection_AsciiString name;
3797 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
3799 PickSh = ViewerTest::PickShape(theType);
3808 if(!PickSh.IsNull()){
3809 nbOfSub[Standard_Integer(theType)]++;
3811 name += nameType[Standard_Integer(theType)];
3812 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3817 // si on avait une petite methode pour voir si la shape
3818 // est deja dans la Double map, ca eviterait de creer....
3819 DBRep::Set(name.ToCString(),PickSh);
3821 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3822 GetMapOfAIS().Bind(newsh, name);
3823 TheAISContext()->Display(newsh);
3824 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
3827 // Plusieurs objets a picker, vite vite vite....
3830 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
3831 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
3832 if(ViewerTest::PickShapes(theType,arr)){
3833 for(Standard_Integer i=1;i<=NbToPick;i++){
3834 PickSh = arr->Value(i);
3835 if(!PickSh.IsNull()){
3837 nbOfSub[Standard_Integer(theType)]++;
3840 name += nameType[Standard_Integer(theType)];
3841 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
3849 DBRep::Set(name.ToCString(),PickSh);
3850 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
3851 GetMapOfAIS().Bind(newsh, name);
3852 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
3853 TheAISContext()->Display(newsh);
3861 //=======================================================================
3862 //function : list of known objects
3864 //=======================================================================
3865 static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
3867 // 1234567890 12345678901234567 123456789
3868 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
3869 TCollection_AsciiString BlankLine(64,'_');
3870 Standard_Integer i ;
3872 di<<"/n"<<BlankLine.ToCString()<<"\n";
3875 Colum[i].Center(20,' ');
3877 di<<"|"<<Colum[i].ToCString();
3880 di<<BlankLine.ToCString()<<"\n";
3882 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
3883 const char ** names = GetTypeNames();
3885 TCollection_AsciiString curstring;
3886 TCollection_AsciiString curcolum[3];
3889 // les objets de type Datum..
3890 curcolum[1]+="Datum";
3892 curcolum[0].Clear();
3893 curcolum[0] += names[i];
3895 curcolum[2].Clear();
3896 curcolum[2]+=TCollection_AsciiString(i+1);
3898 for(Standard_Integer j =0;j<=2;j++){
3899 curcolum[j].Center(20,' ');
3900 di<<"|"<<curcolum[j].ToCString();
3904 di<<BlankLine.ToCString()<<"\n";
3906 // les objets de type shape
3907 curcolum[1].Clear();
3908 curcolum[1]+="Shape";
3909 curcolum[1].Center(20,' ');
3912 curcolum[0].Clear();
3913 curcolum[0] += names[7+i];
3914 curcolum[2].Clear();
3915 curcolum[2]+=TCollection_AsciiString(i);
3917 for(Standard_Integer j =0;j<=2;j++){
3918 curcolum[j].Center(20,' ');
3919 di<<"|"<<curcolum[j].ToCString();
3923 di<<BlankLine.ToCString()<<"\n";
3924 // les IO de type objet...
3925 curcolum[1].Clear();
3926 curcolum[1]+="Object";
3927 curcolum[1].Center(20,' ');
3929 curcolum[0].Clear();
3930 curcolum[0] += names[10+i];
3931 curcolum[2].Clear();
3932 curcolum[2]+=TCollection_AsciiString(i);
3934 for(Standard_Integer j =0;j<=2;j++){
3935 curcolum[j].Center(20,' ');
3936 di<<"|"<<curcolum[j].ToCString();
3940 di<<BlankLine.ToCString()<<"\n";
3941 // les contraintes et dimensions.
3942 // pour l'instant on separe juste contraintes et dimensions...
3943 // plus tard, on detaillera toutes les sortes...
3944 curcolum[1].Clear();
3945 curcolum[1]+="Relation";
3946 curcolum[1].Center(20,' ');
3948 curcolum[0].Clear();
3949 curcolum[0] += names[12+i];
3950 curcolum[2].Clear();
3951 curcolum[2]+=TCollection_AsciiString(i);
3953 for(Standard_Integer j =0;j<=2;j++){
3954 curcolum[j].Center(20,' ');
3955 di<<"|"<<curcolum[j].ToCString();
3959 di<<BlankLine.ToCString()<<"\n";
3966 static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
3968 if(argc!=2) return 1;
3970 AIS_KindOfInteractive TheType;
3971 Standard_Integer TheSign(-1);
3972 GetTypeAndSignfromString(argv[1],TheType,TheSign);
3975 AIS_ListOfInteractive LIO;
3977 // en attendant l'amelioration ais pour les dimensions...
3979 Standard_Integer dimension_status(-1);
3980 if(TheType==AIS_KOI_Relation){
3981 dimension_status = TheSign ==1 ? 1 : 0;
3985 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
3986 Handle(AIS_InteractiveObject) curio;
3987 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
3990 if(dimension_status == -1)
3991 TheAISContext()->Erase(curio,Standard_False);
3993 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
3994 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
3995 (dimension_status==1 && KOD != AIS_KOD_NONE))
3996 TheAISContext()->Erase(curio,Standard_False);
3999 TheAISContext()->UpdateCurrentViewer();
4002 static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
4004 if(argc!=2) return 1;
4006 AIS_KindOfInteractive TheType;
4007 Standard_Integer TheSign(-1);
4008 GetTypeAndSignfromString(argv[1],TheType,TheSign);
4010 // en attendant l'amelioration ais pour les dimensions...
4012 Standard_Integer dimension_status(-1);
4013 if(TheType==AIS_KOI_Relation){
4014 dimension_status = TheSign ==1 ? 1 : 0;
4018 AIS_ListOfInteractive LIO;
4019 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
4020 Handle(AIS_InteractiveObject) curio;
4021 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
4023 if(dimension_status == -1)
4024 TheAISContext()->Display(curio,Standard_False);
4026 AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
4027 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
4028 (dimension_status==1 && KOD != AIS_KOD_NONE))
4029 TheAISContext()->Display(curio,Standard_False);
4034 TheAISContext()->UpdateCurrentViewer();
4038 //==============================================================================
4039 //function : VSetTransMode
4041 //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
4042 //==============================================================================
4044 static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
4045 // Verification des arguments
4046 if ( a3DView().IsNull() ) {
4047 ViewerTest::ViewerInit();
4048 di << "La commande vinit n'a pas ete appele avant" << "\n";
4051 if ( argc < 3 || argc > 8 ) {
4052 di << argv[0] << " Invalid number of arguments" << "\n";
4056 TCollection_AsciiString shapeName;
4057 shapeName = argv[1];
4058 Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
4059 Standard_Integer persFlag2 = 0;
4060 Standard_Integer persFlag3 = 0;
4061 gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
4062 if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
4063 persFlag2 = Draw::Atoi(argv[3]);
4065 if ( argc == 5 || argc == 8 ) {
4066 persFlag3 = Draw::Atoi(argv[4]);
4069 origin.SetX( Draw::Atof(argv[argc - 3]) );
4070 origin.SetY( Draw::Atof(argv[argc - 2]) );
4071 origin.SetZ( Draw::Atof(argv[argc - 1]) );
4074 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
4075 Handle(Standard_Transient) anObj;
4077 anObj = GetMapOfAIS().Find2(shapeName);
4078 if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
4079 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
4080 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4081 if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
4082 di << argv[0] << " All persistence modifiers were removed" << "\n";
4085 di << argv[0] << " Wrong object type" << "\n";
4088 } else { // Create the AIS_Shape from a name
4089 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
4090 if ( !aShape.IsNull() ) {
4091 GetMapOfAIS().Bind( aShape, shapeName );
4092 aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
4093 TheAISContext()->Display( aShape, Standard_False );
4095 di << argv[0] << " Object not found" << "\n";
4100 // Upadate the screen and redraw the view
4101 TheAISContext()->UpdateCurrentViewer();
4105 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
4108 BRep_Builder builder;
4110 BRepTools::Read(shape, s, builder);
4111 DBRep::Set(a[1], shape);
4112 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4113 Handle(AIS_Shape) ais = new AIS_Shape(shape);
4118 //==============================================================================
4119 //function : ViewerTest::Commands
4120 //purpose : Add all the viewer command in the Draw_Interpretor
4121 //==============================================================================
4123 void ViewerTest::Commands(Draw_Interpretor& theCommands)
4125 ViewerTest::ViewerCommands(theCommands);
4126 ViewerTest::RelationCommands(theCommands);
4127 ViewerTest::ObjectCommands(theCommands);
4128 ViewerTest::FilletCommands(theCommands);
4129 ViewerTest::VoxelCommands(theCommands);
4130 ViewerTest::OpenGlCommands(theCommands);
4132 const char *group = "AIS_Display";
4135 theCommands.Add("visos",
4136 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
4137 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
4138 __FILE__, visos, group);
4140 theCommands.Add("vdisplay",
4141 "vdisplay [-noupdate|-update] [-mutable] name1 [name2] ... [name n]"
4142 "\n\t\t: Displays named objects."
4143 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4144 "\n\t\t: Option -mutable enables optimizations for mutable objects."
4145 __FILE__,VDisplay2,group);
4147 theCommands.Add ("vupdate",
4148 "vupdate name1 [name2] ... [name n]"
4149 "\n\t\t: Updates named objects in interactive context",
4150 __FILE__, VUpdate, group);
4152 theCommands.Add("verase",
4153 "verase [-noupdate|-update] [name1] ... [name n]"
4154 "\n\t\t: Erases selected or named objects."
4155 "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
4156 __FILE__, VErase, group);
4158 theCommands.Add("vremove",
4159 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
4160 "or vremove [-context] -all to remove all objects"
4161 "\n\t\t: Removes selected or named objects."
4162 "\n\t\t If -context is in arguments, the objects are not deleted"
4163 "\n\t\t from the map of objects and names."
4164 "\n\t\t: Option -noupdate suppresses viewer redraw call."
4165 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
4166 __FILE__, VRemove, group);
4168 theCommands.Add("vdonly",
4169 "vdonly [-noupdate|-update] [name1] ... [name n]"
4170 "\n\t\t: Displays only selected or named objects",
4171 __FILE__,VDonly2,group);
4173 theCommands.Add("vdisplayall",
4174 "Displays all erased interactive objects (see vdir and vstate)",
4175 __FILE__,VDisplayAll,group);
4177 theCommands.Add("veraseall",
4178 "Erases all objects displayed in the viewer",
4179 __FILE__, VErase, group);
4181 theCommands.Add("verasetype",
4183 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
4184 __FILE__,VEraseType,group);
4186 theCommands.Add("vbounding",
4187 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
4188 "\n\t\t: [-print] [-hide]"
4189 "\n\t\t: Temporarily display bounding box of specified Interactive"
4190 "\n\t\t: Objects, or print it to console if -print is specified."
4191 "\n\t\t: Already displayed box might be hidden by -hide option.",
4192 __FILE__,VBounding,group);
4194 theCommands.Add("vdisplaytype",
4195 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
4196 __FILE__,VDisplayType,group);
4198 theCommands.Add("vdisplaymode",
4199 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
4200 __FILE__,VDispMode,group);
4202 theCommands.Add("verasemode",
4203 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
4204 __FILE__,VDispMode,group);
4206 theCommands.Add("vsetdispmode",
4207 "vsetdispmode [name] mode(1,2,..)"
4208 "\n\t\t: Sets display mode for all, selected or named objects.",
4209 __FILE__,VDispMode,group);
4211 theCommands.Add("vunsetdispmode",
4212 "vunsetdispmode [name]"
4213 "\n\t\t: Unsets custom display mode for selected or named objects.",
4214 __FILE__,VDispMode,group);
4216 theCommands.Add("vdir",
4217 "Lists all objects displayed in 3D viewer",
4218 __FILE__,VDir,group);
4220 theCommands.Add("vdump",
4221 #ifdef HAVE_FREEIMAGE
4222 "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4223 "\n\t\t: [width Width=0 height Height=0]"
4224 "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
4226 "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
4227 "\n\t\t: [width Width=0 height Height=0]"
4228 "\n\t\t: Dumps content of the active view into PPM image file",
4230 __FILE__,VDump,group);
4232 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
4233 __FILE__,VSubInt,group);
4235 theCommands.Add("vaspects",
4236 "vaspects [-noupdate|-update] [name1 [name2 [...]]]"
4237 "\n\t\t: [-setcolor ColorName] [-unsetcolor]"
4238 "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
4239 "\n\t\t: [-settransparency Transp] [-unsettransparency]"
4240 "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
4241 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
4242 "\n\t\t: Manage presentation properties of all, selected or named objects."
4243 "\n\t\t: When -subshapes is specified than following properties will be"
4244 "\n\t\t: assigned to specified sub-shapes.",
4245 __FILE__,VAspects,group);
4247 theCommands.Add("vsetcolor",
4248 "vsetcolor [-noupdate|-update] [name] ColorName"
4249 "\n\t\t: Sets color for all, selected or named objects."
4250 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
4251 __FILE__,VAspects,group);
4253 theCommands.Add("vunsetcolor",
4254 "vunsetcolor [-noupdate|-update] [name]"
4255 "\n\t\t: Resets color for all, selected or named objects."
4256 "\n\t\t: Alias for vaspects -unsetcolor [name].",
4257 __FILE__,VAspects,group);
4259 theCommands.Add("vsettransparency",
4260 "vsettransparency [-noupdate|-update] [name] Coefficient"
4261 "\n\t\t: Sets transparency for all, selected or named objects."
4262 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
4263 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
4264 __FILE__,VAspects,group);
4266 theCommands.Add("vunsettransparency",
4267 "vunsettransparency [-noupdate|-update] [name]"
4268 "\n\t\t: Resets transparency for all, selected or named objects."
4269 "\n\t\t: Alias for vaspects -unsettransp [name].",
4270 __FILE__,VAspects,group);
4272 theCommands.Add("vsetmaterial",
4273 "vsetmaterial [-noupdate|-update] [name] MaterialName"
4274 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
4275 __FILE__,VAspects,group);
4277 theCommands.Add("vunsetmaterial",
4278 "vunsetmaterial [-noupdate|-update] [name]"
4279 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
4280 __FILE__,VAspects,group);
4282 theCommands.Add("vsetwidth",
4283 "vsetwidth [-noupdate|-update] [name] width(0->10)"
4284 "\n\t\t: Alias for vaspects -setwidth [name] width.",
4285 __FILE__,VAspects,group);
4287 theCommands.Add("vunsetwidth",
4288 "vunsetwidth [-noupdate|-update] [name]"
4289 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
4290 __FILE__,VAspects,group);
4292 theCommands.Add("vsetinteriorstyle",
4293 "vsetinteriorstyle [-noupdate|-update] [name] style"
4294 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
4295 __FILE__,VSetInteriorStyle,group);
4297 theCommands.Add("vardis",
4298 "vardis : display activeareas",
4299 __FILE__,VDispAreas,group);
4301 theCommands.Add("varera",
4302 "varera : erase activeareas",
4303 __FILE__,VClearAreas,group);
4305 theCommands.Add("vsensdis",
4306 "vardisp : display active entities",
4307 __FILE__,VDispSensi,group);
4308 theCommands.Add("vsensera",
4309 "vardisp : erase active entities",
4310 __FILE__,VClearSensi,group);
4312 theCommands.Add("vselprecision",
4313 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
4314 __FILE__,VSelPrecision,group);
4316 theCommands.Add("vperf",
4317 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
4318 __FILE__,VPerf,group);
4320 theCommands.Add("vanimation",
4321 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
4322 __FILE__,VAnimation,group);
4324 theCommands.Add("vsetshading",
4325 "vsetshading : vsetshading name Quality(default=0.0008) ",
4326 __FILE__,VShading,group);
4328 theCommands.Add("vunsetshading",
4329 "vunsetshading :vunsetshading name ",
4330 __FILE__,VShading,group);
4332 theCommands.Add ("vtexture",
4333 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
4334 " [-scale u v] [-scale off]\n"
4335 " [-origin u v] [-origin off]\n"
4336 " [-repeat u v] [-repeat off]\n"
4337 " [-modulate {on | off}]"
4339 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
4340 " specifying one of the predefined textures.\n"
4341 " The options are: \n"
4342 " -scale u v : enable texture scaling and set scale factors\n"
4343 " -scale off : disable texture scaling\n"
4344 " -origin u v : enable texture origin positioning and set the origin\n"
4345 " -origin off : disable texture origin positioning\n"
4346 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
4347 " -repeat off : disable texture repeat\n"
4348 " -modulate {on | off} : enable or disable texture modulation\n"
4349 " -default : sets texture mapping default parameters\n"
4350 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
4351 "or 'vtexture NameOfShape ?' to list available textures\n",
4352 __FILE__, VTexture, group);
4354 theCommands.Add("vtexscale",
4355 "'vtexscale NameOfShape ScaleU ScaleV' \n \
4356 or 'vtexscale NameOfShape ScaleUV' \n \
4357 or 'vtexscale NameOfShape' to disable scaling\n ",
4358 __FILE__,VTexture,group);
4360 theCommands.Add("vtexorigin",
4361 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
4362 or 'vtexorigin NameOfShape UVOrigin' \n \
4363 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
4364 __FILE__,VTexture,group);
4366 theCommands.Add("vtexrepeat",
4367 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
4368 or 'vtexrepeat NameOfShape UVRepeat \n \
4369 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
4372 theCommands.Add("vtexdefault",
4373 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
4376 theCommands.Add("vsetam",
4377 "vsetActivatedModes: vsetam mode(1->7) ",
4378 __FILE__,VActivatedMode,group);
4380 theCommands.Add("vunsetam",
4381 "vunsetActivatedModes: vunsetam ",
4382 __FILE__,VActivatedMode,group);
4384 theCommands.Add("vstate",
4385 "vstate [name1] ... [nameN]"
4386 "\n\t\t: Reports show/hidden state for selected or named objects",
4387 __FILE__,VState,group);
4389 theCommands.Add("vpickshapes",
4390 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
4391 __FILE__,VPickShape,group);
4393 theCommands.Add("vtypes",
4394 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
4397 theCommands.Add("vsettransmode",
4398 "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
4399 __FILE__,VSetTransMode,group);
4401 theCommands.Add("vr", "vr : reading of the shape",
4402 __FILE__,vr, group);
4406 //=====================================================================
4407 //========================= for testing Draft and Rib =================
4408 //=====================================================================
4409 #include <BRepOffsetAPI_MakeThickSolid.hxx>
4410 #include <DBRep.hxx>
4411 #include <TopoDS_Face.hxx>
4412 #include <gp_Pln.hxx>
4413 #include <AIS_KindOfSurface.hxx>
4414 #include <BRepOffsetAPI_DraftAngle.hxx>
4415 #include <Precision.hxx>
4416 #include <BRepAlgo.hxx>
4417 #include <OSD_Environment.hxx>
4418 #include <DrawTrSurf.hxx>
4419 //#include <DbgTools.hxx>
4420 //#include <FeatAlgo_MakeLinearForm.hxx>
4425 //=======================================================================
4426 //function : IsValid
4428 //=======================================================================
4429 static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
4430 const TopoDS_Shape& theResult,
4431 const Standard_Boolean closedSolid,
4432 const Standard_Boolean GeomCtrl)
4434 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
4435 TCollection_AsciiString checkValid = check.Value();
4436 Standard_Boolean ToCheck = Standard_True;
4437 if (!checkValid.IsEmpty()) {
4439 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
4441 if ( checkValid=="true" || checkValid=="TRUE" ) {
4442 ToCheck= Standard_False;
4446 cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
4449 Standard_Boolean IsValid = Standard_True;
4451 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
4456 //===============================================================================
4457 // TDraft : test draft, uses AIS Viewer
4458 // Solid Face Plane Angle Reverse
4459 //===============================================================================
4460 static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4462 if (argc < 5) return 1;
4463 // argv[1] - TopoDS_Shape Solid
4464 // argv[2] - TopoDS_Shape Face
4465 // argv[3] - TopoDS_Shape Plane
4466 // argv[4] - Standard_Real Angle
4467 // argv[5] - Standard_Integer Reverse
4469 // Sprintf(prefix, argv[1]);
4470 Standard_Real anAngle = 0;
4471 Standard_Boolean Rev = Standard_False;
4472 Standard_Integer rev = 0;
4473 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
4474 TopoDS_Shape face = GetShapeFromName(argv[2]);
4475 TopoDS_Face Face = TopoDS::Face(face);
4476 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
4477 if (Plane.IsNull ()) {
4478 di << "TEST : Plane is NULL" << "\n";
4481 anAngle = Draw::Atof(argv[4]);
4482 anAngle = 2*M_PI * anAngle / 360.0;
4484 Handle( Geom_Surface )aSurf;
4485 AIS_KindOfSurface aSurfType;
4486 Standard_Real Offset;
4488 if(argc > 4) { // == 5
4489 rev = Draw::Atoi(argv[5]);
4490 Rev = (rev)? Standard_True : Standard_False;
4493 TopoDS_Face face2 = TopoDS::Face(Plane);
4494 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
4496 di << "TEST : Can't find plane" << "\n";
4500 aDir = aPln.Axis().Direction();
4503 if (Plane.Orientation() == TopAbs_REVERSED)
4505 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
4507 BRepOffsetAPI_DraftAngle Draft (Solid);
4509 if(Abs(anAngle)< Precision::Angular()) {
4510 di << "TEST : NULL angle" << "\n";
4513 if(Rev) anAngle = - anAngle;
4514 Draft.Add (Face, aDir, anAngle, aPln);
4516 if (!Draft.IsDone()) {
4517 di << "TEST : Draft Not DONE " << "\n";
4520 TopTools_ListOfShape Larg;
4522 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
4523 di << "TEST : DesignAlgo returns Not valid" << "\n";
4527 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
4528 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
4530 if ( !ais.IsNull() ) {
4531 ais->SetColor(DEFAULT_COLOR);
4532 ais->SetMaterial(DEFAULT_MATERIAL);
4533 // Display the AIS_Shape without redraw
4534 Ctx->Display(ais, Standard_False);
4536 const char *Name = "draft1";
4537 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
4539 Handle(AIS_InteractiveObject) an_object =
4540 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
4541 if (!an_object.IsNull()) {
4542 Ctx->Remove(an_object,
4544 GetMapOfAIS().UnBind2(Name) ;
4547 GetMapOfAIS().Bind(ais, Name);
4548 // DBRep::Set("draft", ais->Shape());
4550 Ctx->Display(ais, Standard_True);
4554 //==============================================================================
4555 //function : splitParameter
4556 //purpose : Split parameter string to parameter name and parameter value
4557 //==============================================================================
4558 Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
4559 TCollection_AsciiString& theName,
4560 TCollection_AsciiString& theValue)
4562 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
4564 if (aParamNameEnd == 0)
4566 return Standard_False;
4569 TCollection_AsciiString aString (theString);
4570 if (aParamNameEnd != 0)
4572 theValue = aString.Split (aParamNameEnd);
4573 aString.Split (aString.Length() - 1);
4577 return Standard_True;
4580 //============================================================================
4582 //============================================================================
4583 void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
4586 DrawTrSurf::BasicCommands(theCommands);
4587 const char* group = "Check Features Operations commands";
4589 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
4591 &TDraft,group); //Draft_Modification
4594 //==============================================================================
4595 // ViewerTest::Factory
4596 //==============================================================================
4597 void ViewerTest::Factory(Draw_Interpretor& theDI)
4599 // definition of Viewer Command
4600 ViewerTest::Commands(theDI);
4601 ViewerTest::AviCommands(theDI);
4604 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
4608 // Declare entry point PLUGINFACTORY