-// File: ViewerTest.cxx
-// Created: Wed Jul 23 14:14:01 1997
-// Author: Henri JEANNIN
-// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
+// Created on: 1997-07-23
+// Created by: Henri JEANNIN
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
// Modified by Robert Coublanc [nov 16-17-18 1998]
// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
// ViewerTest_ObjectCommands.cxx
#include <TopLoc_Location.hxx>
#include <TopTools_HArray1OfShape.hxx>
#include <TColStd_HArray1OfTransient.hxx>
-#include <OSD_Directory.hxx>
-#include <OSD_File.hxx>
-#include <OSD_Path.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
#include <OSD_Timer.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_Axis1Placement.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <StdSelect_ShapeTypeFilter.hxx>
#include <AIS.hxx>
+#include <AIS_Drawer.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Trihedron.hxx>
#include <AIS_Axis.hxx>
#include <AIS_Relation.hxx>
#include <AIS_TypeFilter.hxx>
#include <AIS_SignatureFilter.hxx>
+#include <AIS_LocalContext.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <Image_PixMap.hxx>
+#include <Aspect_InteriorStyle.hxx>
+#include <Aspect_Window.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_TextureRoot.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <TopTools_MapOfShape.hxx>
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <TCollection_AsciiString.hxx>
#include <Draw_PluginMacro.hxx>
#include <ViewerTest.hxx>
-#include <Viewer2dTest.hxx>
// avoid warnings on 'extern "C"' functions returning C++ classes
#ifdef WNT
#include <NIS_Triangulated.hxx>
extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
-//=======================================================================
-//function : GetColorFromName
-//purpose : get the Quantity_NameOfColor from a string
-//=======================================================================
-
-#include <Quantity_NameOfColor.hxx>
#include <Quantity_Color.hxx>
#include <Quantity_NameOfColor.hxx>
#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
-static Quantity_NameOfColor GetColorFromName( const char *name )
+enum ViewerTest_RedrawMode
+{
+ ViewerTest_RM_Auto = -1,
+ ViewerTest_RM_RedrawForce,
+ ViewerTest_RM_RedrawSuppress
+};
+
+//! Auxiliary method to parse redraw mode argument
+static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
+ ViewerTest_RedrawMode& theMode)
{
- Quantity_NameOfColor ret = DEFAULT_COLOR;
+ TCollection_AsciiString anArgCase (theArg);
+ anArgCase.LowerCase();
+ if (anArgCase == "-update"
+ || anArgCase == "-redraw")
+ {
+ theMode = ViewerTest_RM_RedrawForce;
+ return Standard_True;
+ }
+ else if (anArgCase == "-noupdate"
+ || anArgCase == "-noredraw")
+ {
+ theMode = ViewerTest_RM_RedrawSuppress;
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+//=======================================================================
+//function : GetColorFromName
+//purpose : get the Quantity_NameOfColor from a string
+//=======================================================================
- Standard_Boolean Found = Standard_False;
- Standard_CString colstring;
- for(Standard_Integer i=0;i<=514 && !Found;i++)
+Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
+{
+ for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
+ {
+ Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
+ if (strcasecmp (theName, aColorName) == 0)
{
- colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
- if (!strcasecmp(name,colstring)) {
- ret = (Quantity_NameOfColor)i;
- Found = Standard_True;
- }
+ return Quantity_NameOfColor (anIter);
}
+ }
- return ret;
+ return DEFAULT_COLOR;
}
//=======================================================================
else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME;
else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM;
- else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE;
else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC;
else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC;
else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER;
#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <BRepOffset.hxx>
-
-//==============================================================================
-//function : GetTypeNameFromShape
-//purpose : get the shape type as a string from a shape
-//==============================================================================
-
-static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape )
-{ const char *ret = "????";
-
- if ( aShape.IsNull() ) ret = "Null Shape";
-
- switch ( aShape.ShapeType() ) {
- case TopAbs_COMPOUND : ret = "COMPOUND" ; break;
- case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break;
- case TopAbs_SOLID : ret = "SOLID" ; break;
- case TopAbs_SHELL : ret = "SHELL" ; break;
- case TopAbs_FACE : ret = "FACE" ; break;
- case TopAbs_WIRE : ret = "WIRE" ; break;
- case TopAbs_EDGE : ret = "EDGE" ; break;
- case TopAbs_VERTEX : ret = "VERTEX" ; break;
- case TopAbs_SHAPE : ret = "SHAPE" ; break;
- }
- return ret;
-}
//==============================================================================
// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
//==============================================================================
aMap.UnBind2 (theName);
}
+ if (theAISObj.IsNull())
+ {
+ // object with specified name already unbound
+ return Standard_True;
+ }
+
// unbind AIS object if was bound with another name
aMap.UnBind1 (theAISObj);
theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
}
-static Handle(V3d_View)& a3DView(){
+static Handle(V3d_View)& a3DView()
+{
static Handle(V3d_View) Viou;
return Viou;
}
+
Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
static Handle(AIS_InteractiveContext) aContext;
return aContext;
}
-Handle(V3d_View) ViewerTest::CurrentView()
+const Handle(V3d_View)& ViewerTest::CurrentView()
{
return a3DView();
}
return aContext;
}
-Handle(AIS_InteractiveContext) ViewerTest::GetAISContext()
+const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
{
return TheAISContext();
}
return EM;
}
-
//=======================================================================
-//function : Get Context and active viou..
+//function : Get Context and active view
//purpose :
//=======================================================================
-void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx,
- Handle(V3d_View)& Viou)
+static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
+ Handle(V3d_View)& theView)
{
- Ctx = ViewerTest::GetAISContext();
- if (!Ctx.IsNull())
+ theCtx = ViewerTest::GetAISContext();
+ theView = ViewerTest::CurrentView();
+ if (theCtx.IsNull()
+ || theView.IsNull())
{
- const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer();
- Vwr->InitActiveViews();
- if(Vwr->MoreActiveViews())
- Viou = Vwr->ActiveView();
+ std::cout << "Error: cannot find an active view!\n";
+ return Standard_False;
}
+ return Standard_True;
}
-
//==============================================================================
//function : GetShapeFromName
//purpose : Compute an Shape from a draw variable or a file name
return S;
}
-//==============================================================================
-//function : GetShapeFromName
-//purpose : Compute an Shape from a draw variable or a file name
-//==============================================================================
-// Unused :
-#ifdef DEB
-static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO )
-{
- TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape();
- return TheShape;
-}
-#endif
+
//==============================================================================
//function : GetAISShapeFromName
//purpose : Compute an AIS_Shape from a draw variable or a file name
const Handle(AIS_InteractiveObject) IO =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
if (!IO.IsNull()) {
- if(IO->Type()==AIS_KOI_Shape)
+ if(IO->Type()==AIS_KOI_Shape) {
if(IO->Signature()==0){
retsh = *((Handle(AIS_Shape)*)&IO);
}
else
cout << "an Object which is not an AIS_Shape "
"already has this name!!!"<<endl;
+ }
}
return retsh;
}
case 4: cmode = "Face"; break;
case 5: cmode = "Shell"; break;
case 6: cmode = "Solid"; break;
- case 7: cmode = "Compound"; break;
+ case 7: cmode = "Compsolid"; break;
+ case 8: cmode = "Compound"; break;
}
if(theactivatedmodes.Contains(mode))
}
//==============================================================================
-//function : SelectFromContext
-//purpose : pick / select an object from the last MoveTo() on a
-// ButtonPress event
+//function : CopyIsoAspect
+//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
//==============================================================================
+static Handle(Prs3d_IsoAspect) CopyIsoAspect
+ (const Handle(Prs3d_IsoAspect) &theIsoAspect,
+ const Standard_Integer theNbIsos)
+{
+ Quantity_Color aColor;
+ Aspect_TypeOfLine aType;
+ Standard_Real aWidth;
+
+ theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
+
+ Handle(Prs3d_IsoAspect) aResult =
+ new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
-Handle(AIS_InteractiveObject) Select(Standard_Integer argc,
- const char** argv,
- Standard_Boolean shift,
- Standard_Boolean pick )
+ return aResult;
+}
+
+//==============================================================================
+//function : visos
+//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
+//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
+//==============================================================================
+static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- Handle(AIS_InteractiveObject) ret;
- Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
- if ( shift ) {
- EM->ShiftSelect();
+ if (TheAISContext().IsNull()) {
+ di << argv[0] << " Call 'vinit' before!\n";
+ return 1;
}
- else {
- EM->Select();
- }
- const Handle(AIS_InteractiveContext) aContext = EM->Context();
-
- if ( !aContext->HasOpenedContext() ) {
- aContext->InitCurrent();
- while ( aContext->MoreCurrent() ) {
- Handle(AIS_InteractiveObject) aisPickedShape =
- Handle(AIS_InteractiveObject)::DownCast(aContext->Current());
-
-//JR/Hp
- const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
-// const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))?
- GetMapOfAIS().Find1(aisPickedShape).ToCString() :
- "????";
- Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape);
- if(!TheRealSh.IsNull()){
- cout << "Current is " << name
- << " (" << GetTypeNameFromShape(TheRealSh->Shape())
- << ")" << endl;
- }
- ret = aisPickedShape;
- if(!TheRealSh.IsNull()){
- if ( pick && argc > 4 ) {
- DBRep::Set(argv[4], TheRealSh->Shape());
- }
+
+ if (argc <= 1) {
+ di << "Current number of isos : " <<
+ TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
+ TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
+ di << "IsoOnPlane mode is " <<
+ (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
+
+ return 0;
+ }
+
+ Standard_Integer aLastInd = argc - 1;
+ Standard_Boolean isChanged = Standard_False;
+ Standard_Integer aNbUIsos = 0;
+ Standard_Integer aNbVIsos = 0;
+
+ if (aLastInd >= 3) {
+ Standard_Boolean isIsoOnPlane = Standard_False;
+
+ if (strcmp(argv[aLastInd], "1") == 0) {
+ isIsoOnPlane = Standard_True;
+ isChanged = Standard_True;
+ } else if (strcmp(argv[aLastInd], "0") == 0) {
+ isIsoOnPlane = Standard_False;
+ isChanged = Standard_True;
+ }
+
+ if (isChanged) {
+ aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
+ aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
+ aLastInd -= 3;
+
+ di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
+ di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
+
+ TheAISContext()->IsoOnPlane(isIsoOnPlane);
+
+ if (aLastInd == 0) {
+ // If there are no shapes provided set the default numbers.
+ TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
+ TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
}
- aContext->NextCurrent();
}
}
- else {
- // A LocalContext is opened, the use xxxxSelected()
- // to select an object and its SubShape
- aContext->InitSelected();
- while ( aContext->MoreSelected() ) {
- if ( !aContext->HasSelectedShape() ) {
- }
- else {
- TopoDS_Shape PickedShape = aContext->SelectedShape();
- if ( pick && argc > 5 ) {
- DBRep::Set(argv[5], PickedShape);
- }
- }
- if ( aContext->Interactive().IsNull() ) {
- cout << "??? (No InteractiveObject selected)" << endl;
- }
- else {
- Handle(AIS_InteractiveObject) aisPicked =
- Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive());
- ret = aisPicked;
- Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked);
-
- // Get back its name
-//JR/Hp
- const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
-// const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )?
- GetMapOfAIS().Find1(aisPicked).ToCString() :
- "????";
-
- if(!aisPickedShape.IsNull()){
- if ( pick && argc > 4 ) {
- // Create a draw variable to store the wohole shape
- // for vpick command
- DBRep::Set(argv[4], aisPickedShape->Shape());
- }
+ Standard_Integer i;
- cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape())
- << ")" << endl ;
- }
+ for (i = 1; i <= aLastInd; i++) {
+ TCollection_AsciiString name(argv[i]);
+ Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
+
+ if (IsBound) {
+ const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
+ if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
+ const Handle(AIS_InteractiveObject) aShape =
+ Handle(AIS_InteractiveObject)::DownCast (anObj);
+ Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
+ Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
+ Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
+
+ if (isChanged) {
+ CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
+ CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
+ TheAISContext()->SetLocalAttributes
+ (aShape, CurDrawer, Standard_False);
+ TheAISContext()->Redisplay(aShape);
+ } else {
+ di << "Number of isos for " << argv[i] << " : "
+ << aUIso->Number() << " " << aVIso->Number() << "\n";
+ }
+ } else {
+ di << argv[i] << ": Not an AIS interactive object!\n";
}
- // Goto the next selected object
- aContext->NextSelected();
+ } else {
+ di << argv[i] << ": Use 'vdisplay' before\n";
}
}
- return ret;
-}
-//==============================================================================
-//function : DetectedFromContext
-//purpose : hilight dynamicaly an object from the last MoveTo() on a
-// MouseMove event
-//==============================================================================
-Handle(AIS_InteractiveObject) DetectedFromContext(
- Handle(AIS_InteractiveContext) aContext )
-{
- Handle(AIS_InteractiveObject) ret;
- if ( aContext->HasDetected() ) {
- if ( !aContext->HasDetectedShape() ) {
- //No SubShape selected
- }
- else {
- // Get the detected SubShape
- TopoDS_Shape PickedShape = aContext->DetectedShape();
- }
- if ( !aContext->DetectedInteractive().IsNull() ) {
- Handle(AIS_InteractiveObject) aisPickedShape =
- Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive());
- ret = aisPickedShape;
-#ifdef DEB
- const char *name =
-#endif
- ( GetMapOfAIS().IsBound1(aisPickedShape) )?
- GetMapOfAIS().Find1(aisPickedShape).ToCString() :
- (char *) "????";
- }
+ if (isChanged) {
+ TheAISContext()->UpdateCurrentViewer();
}
- return ret;
-}
+ return 0;
+}
//==============================================================================
//function : VDispAreas,VDispSensitive,...
-//purpose : Redraw the view
-//Draw arg : No args
+//purpose :
//==============================================================================
-static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** )
+static Standard_Integer VDispAreas (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ Standard_CString* )
{
+ if (theArgNb > 1)
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) aCtx;
+ Handle(V3d_View) aView;
+ if (!getCtxAndView (aCtx, aView))
+ {
+ return 1;
+ }
- Handle(AIS_InteractiveContext) Ctx;
- Handle(V3d_View) Viou;
- GetCtxAndView(Ctx,Viou);
- Ctx->DisplayActiveAreas(Viou);
+ aCtx->DisplayActiveAreas (aView);
return 0;
}
-static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** )
+static Standard_Integer VClearAreas (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ Standard_CString* )
{
- Handle(AIS_InteractiveContext) Ctx;
- Handle(V3d_View) Viou;
- GetCtxAndView(Ctx,Viou);
- Ctx->ClearActiveAreas(Viou);
+ if (theArgNb > 1)
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) aCtx;
+ Handle(V3d_View) aView;
+ if (!getCtxAndView (aCtx, aView))
+ {
+ return 1;
+ }
+
+ aCtx->ClearActiveAreas (aView);
return 0;
}
-static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** )
+static Standard_Integer VDispSensi (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ Standard_CString* )
{
- Handle(AIS_InteractiveContext) Ctx;
- Handle(V3d_View) Viou;
- GetCtxAndView(Ctx,Viou);
- Ctx->DisplayActiveSensitive(Viou);
+ if (theArgNb > 1)
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) aCtx;
+ Handle(V3d_View) aView;
+ if (!getCtxAndView (aCtx, aView))
+ {
+ return 1;
+ }
+
+ aCtx->DisplayActiveSensitive (aView);
return 0;
}
-static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** )
+
+static Standard_Integer VClearSensi (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ Standard_CString* )
{
- Handle(AIS_InteractiveContext) Ctx;
- Handle(V3d_View) Viou;
- GetCtxAndView(Ctx,Viou);
- Ctx->ClearActiveSensitive(Viou);
+ if (theArgNb > 1)
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) aCtx;
+ Handle(V3d_View) aView;
+ if (!getCtxAndView (aCtx, aView))
+ {
+ return 1;
+ }
+ aCtx->ClearActiveSensitive (aView);
return 0;
}
//==============================================================================
-//function : VDebug
+//function : VDir
//purpose : To list the displayed object with their attributes
-//Draw arg : No args
//==============================================================================
-static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** )
-{ if ( !a3DView().IsNull() ) {
- di << "List of object in the viewer :" << "\n";
+static int VDir (Draw_Interpretor& theDI,
+ Standard_Integer ,
+ const char** )
+{
+ if (!a3DView().IsNull())
+ {
+ return 0;
+ }
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ theDI << "\t" << anIter.Key2().ToCString() << "\n";
+ }
+ return 0;
+}
- while ( it.More() ) {
- di << "\t" << it.Key2().ToCString() << "\n";
- it.Next();
- }
+//==============================================================================
+//function : VSelPrecision
+//purpose : To set the selection precision mode and tolerance value
+//Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
+// value (integer number of pixel for window mode, double value of
+// sensitivity for view mode). Without arguments the function just
+// prints the current precision mode and the corresponding tolerance.
+//==============================================================================
+static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if( argc > 3 )
+ {
+ di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
+ return 1;
}
+ Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+ if( aContext.IsNull() )
+ return 1;
+
+ if( argc == 1 )
+ {
+ StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
+ if( aMode == StdSelect_SM_WINDOW )
+ {
+ Standard_Integer aPixelTolerance = aContext->PixelTolerance();
+ di << "Precision mode : 0 (window)\n";
+ di << "Pixel tolerance : " << aPixelTolerance << "\n";
+ }
+ else if( aMode == StdSelect_SM_VIEW )
+ {
+ Standard_Real aSensitivity = aContext->Sensitivity();
+ di << "Precision mode : 1 (view)\n";
+ di << "Sensitivity : " << aSensitivity << "\n";
+ }
+ }
+ else if( argc > 1 )
+ {
+ StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
+ aContext->SetSensitivityMode( aMode );
+ if( argc > 2 )
+ {
+ if( aMode == StdSelect_SM_WINDOW )
+ {
+ Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
+ aContext->SetPixelTolerance( aPixelTolerance );
+ }
+ else if( aMode == StdSelect_SM_VIEW )
+ {
+ Standard_Real aSensitivity = Draw::Atof( argv[2] );
+ aContext->SetSensitivity( aSensitivity );
+ }
+ }
+ }
return 0;
}
//==============================================================================
//function : VDump
//purpose : To dump the active view snapshot to image file
-//Draw arg : Picture file name with extension corresponding to desired format
//==============================================================================
-static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer VDump (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ Standard_CString* theArgVec)
{
- if (argc < 2)
+ if (theArgNb < 2)
{
- di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n";
+ std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
return 1;
}
- Image_TypeOfImage aBufferType = Image_TOI_RGB;
-
- if (argc > 2)
+ Standard_Integer anArgIter = 1;
+ Standard_CString aFilePath = theArgVec[anArgIter++];
+ Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
+ V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
+ Standard_Integer aWidth = 0;
+ Standard_Integer aHeight = 0;
+ for (; anArgIter < theArgNb; ++anArgIter)
{
- TCollection_AsciiString aBuffTypeStr (argv[2]);
- if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb")))
+ TCollection_AsciiString anArg (theArgVec[anArgIter]);
+ anArg.LowerCase();
+ if (anArg == "rgba")
+ {
+ aBufferType = Graphic3d_BT_RGBA;
+ }
+ else if (anArg == "rgb")
+ {
+ aBufferType = Graphic3d_BT_RGB;
+ }
+ else if (anArg == "depth")
+ {
+ aBufferType = Graphic3d_BT_Depth;
+ }
+ else if (anArg == "l"
+ || anArg == "left")
{
- aBufferType = Image_TOI_RGB;
+ aStereoOpts = V3d_SDO_LEFT_EYE;
+ }
+ else if (anArg == "r"
+ || anArg == "right")
+ {
+ aStereoOpts = V3d_SDO_RIGHT_EYE;
+ }
+ else if (anArg == "mono")
+ {
+ aStereoOpts = V3d_SDO_MONO;
+ }
+ else if (anArg == "w"
+ || anArg == "width")
+ {
+ if (aWidth != 0)
+ {
+ std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
+ return 1;
+ }
+ else if (++anArgIter >= theArgNb)
+ {
+ std::cout << "Error: integer value is expected right after 'width'\n";
+ return 1;
+ }
+ aWidth = Draw::Atoi (theArgVec[anArgIter]);
+ }
+ else if (anArg == "h"
+ || anArg == "height")
+ {
+ if (aHeight != 0)
+ {
+ std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
+ return 1;
+ }
+ if (++anArgIter >= theArgNb)
+ {
+ std::cout << "Error: integer value is expected right after 'height'\n";
+ return 1;
+ }
+ aHeight = Draw::Atoi (theArgVec[anArgIter]);
}
- else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba")))
+ else if (anArg.IsIntegerValue())
{
- aBufferType = Image_TOI_RGBA;
+ // compatibility with old syntax
+ if (aWidth != 0
+ || aHeight != 0)
+ {
+ std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
+ return 1;
+ }
+ else if (++anArgIter >= theArgNb)
+ {
+ std::cout << "Error: height value is expected right after width\n";
+ return 1;
+ }
+ aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
+ aHeight = Draw::Atoi (theArgVec[anArgIter]);
}
- else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth")))
+ else
{
- aBufferType = Image_TOI_FLOAT;
+ std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
+ return 1;
}
}
+ if ((aWidth <= 0 && aHeight > 0)
+ || (aWidth > 0 && aHeight <= 0))
+ {
+ std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
+ return 1;
+ }
- Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0;
- Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0;
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ std::cout << "Error: cannot find an active view!\n";
+ return 1;
+ }
- Handle(AIS_InteractiveContext) IC;
- Handle(V3d_View) view;
- GetCtxAndView (IC, view);
- if (!view.IsNull())
+ if (aWidth <= 0 || aHeight <= 0)
{
- if (aWidth > 0 && aHeight > 0)
+ if (aStereoOpts != V3d_SDO_MONO)
{
- return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1;
+ aView->Window()->Size (aWidth, aHeight);
}
else
{
- return view->Dump (argv[1], aBufferType) ? 0 : 1;
+ if (!aView->Dump (aFilePath, aBufferType))
+ {
+ theDI << "Fail: view dump failed!\n";
+ }
+ return 0;
}
}
- else
+
+ Image_AlienPixMap aPixMap;
+ if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
{
- di << "Cannot find an active viewer/view" << "\n";
- return 1;
+ theDI << "Fail: view dump failed!\n";
+ return 0;
+ }
+
+ if (aPixMap.SizeX() != Standard_Size(aWidth)
+ || aPixMap.SizeY() != Standard_Size(aHeight))
+ {
+ theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
+ << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
}
+ if (!aPixMap.Save (aFilePath))
+ {
+ theDI << "Fail: image can not be saved!\n";
+ }
+ return 0;
}
Ctx->Display(IO,Mode,Upd);
break;
case 2:{
- Ctx->Erase(IO,Mode,Upd);
+ Ctx->Erase(IO,Upd);
break;
}
case 3:{
}
}
else if(argc==2){
- Standard_Integer Dmode = atoi(argv[1]);
+ Standard_Integer Dmode = Draw::Atoi(argv[1]);
if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
Handle(AIS_InteractiveObject) IO;
VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
if(GetMapOfAIS().IsBound2(name))
IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
if (!IO.IsNull())
- VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True);
+ VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
}
return 0;
}
static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if(argc==1) return 1;
- Standard_Integer On = atoi(argv[1]);
+ Standard_Integer On = Draw::Atoi(argv[1]);
const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
if(argc==2){
TCollection_AsciiString name = argv[2];
if(GetMapOfAIS().IsBound2(name)){
IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
- if (!IO.IsNull())
+ if (!IO.IsNull()) {
if(On==1)
Ctx->SubIntensityOn(IO);
else
Ctx->SubIntensityOff(IO);
-
+ }
}
else return 1;
}
Handle(AIS_InteractiveObject)::DownCast (anObj);
#ifdef DEB
if (HaveToSet)
- di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
+ di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
else
di << "HaveToSet 0\n";
#endif
if(HaveToSet)
- TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) );
+ TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
else
TheAISContext()->UnsetColor(ashape);
} else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
Handle(NIS_Triangulated) ashape =
Handle(NIS_Triangulated)::DownCast (anObj);
if (!ashape.IsNull())
- ashape->SetColor (GetColorFromName(argv[2]));
+ ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
}
}
continue;
#ifdef DEB
if (HaveToSet)
- di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n";
+ di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
else
di << "HaveToSet 0\n";
#endif
if(HaveToSet)
- TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
+ TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
else
TheAISContext()->UnsetColor(ashape,Standard_False);
}
while ( it.More() ) {
const Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- if (!ashape.IsNull())
+ if (!ashape.IsNull()) {
if(HaveToSet)
- TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False);
+ TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
else
TheAISContext()->UnsetColor(ashape,Standard_False);
+ }
it.Next();
}
TheAISContext()->UpdateCurrentViewer();
const Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast(anObj);
if(HaveToSet)
- TheAISContext()->SetTransparency(ashape,atof(argv[2]) );
+ TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
else
TheAISContext()->UnsetTransparency(ashape);
} else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
const Handle(NIS_InteractiveObject) ashape =
Handle(NIS_InteractiveObject)::DownCast(anObj);
if(HaveToSet)
- ashape->SetTransparency(atof(argv[2]) );
+ ashape->SetTransparency(Draw::Atof(argv[2]) );
else
ashape->UnsetTransparency();
}
{
Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
if(HaveToSet)
- TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
+ TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
else
TheAISContext()->UnsetTransparency(ashape,Standard_False);
}
while ( it.More() ) {
Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- if (!ashape.IsNull())
+ if (!ashape.IsNull()) {
if(HaveToSet)
- TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False);
+ TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
else
TheAISContext()->UnsetTransparency(ashape,Standard_False);
+ }
it.Next();
}
TheAISContext()->UpdateCurrentViewer();
if ( ThereIsName && IsBound ) {
Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
- if (!ashape.IsNull())
+ if (!ashape.IsNull()) {
if (HaveToSet)
TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
else
TheAISContext()->UnsetMaterial(ashape);
+ }
}
//=======================================================================
// Il n'y a pas de nom de shape
while ( it.More() ) {
Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast (it.Key1());
- if (!ashape.IsNull())
+ if (!ashape.IsNull()) {
if (HaveToSet)
TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
else
TheAISContext()->UnsetMaterial(ashape,Standard_False);
+ }
it.Next();
}
TheAISContext()->UpdateCurrentViewer();
const Handle(AIS_InteractiveObject) ashape =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
if (HaveToSet)
- TheAISContext()->SetWidth ( ashape,atof (argv[2]) );
+ TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
else
TheAISContext()->UnsetWidth (ashape);
} else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
const Handle(NIS_Triangulated) ashape =
Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
if (HaveToSet && !ashape.IsNull())
- ashape->SetLineWidth ( atof (argv[2]) );
+ ashape->SetLineWidth ( Draw::Atof (argv[2]) );
}
}
{
Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
if (HaveToSet)
- TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
+ TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
else
TheAISContext()->UnsetWidth(ashape,Standard_False);
}
else if (!ThereIsCurrent && !ThereIsArgument){
ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
it(GetMapOfAIS());
- while ( it.More() ) {
- Handle(AIS_InteractiveObject) ashape =
- Handle(AIS_InteractiveObject)::DownCast (it.Key1());
- if (!ashape.IsNull())
- if (HaveToSet)
- TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False);
- else
- TheAISContext()->UnsetWidth(ashape,Standard_False);
- it.Next();
+ while ( it.More() ) {
+ Handle(AIS_InteractiveObject) ashape =
+ Handle(AIS_InteractiveObject)::DownCast (it.Key1());
+ if (!ashape.IsNull()) {
+ if (HaveToSet)
+ TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
+ else
+ TheAISContext()->UnsetWidth(ashape,Standard_False);
+ }
+ it.Next();
}
TheAISContext()->UpdateCurrentViewer();
}
}
return 0;
}
+
//==============================================================================
-//function : VDonly2
-//author : ege
-//purpose : Display only a selected or named object
-// if there is no selected or named object s, nothing is donne
-//Draw arg : vdonly2 [name1] ... [name n]
+//function : VInteriorStyle
+//purpose : sets interior style of the a selected or named or displayed shape
+//Draw arg : vsetinteriorstyle [shape] style
//==============================================================================
-static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
+static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
+ const Standard_Integer theStyle,
+ Draw_Interpretor& di)
+{
+ if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
+ di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
+ " (Aspect_IS_HIDDENLINE)]\n";
+ return;
+ }
+ const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
+ Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
+ Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
+ Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
+ aFillAspect->SetInteriorStyle (aStyle);
+ TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
+}
+static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if ( a3DView().IsNull() )
+ if (argc < 2 || argc > 3) {
+ di << argv[0] << " requires 2 or 3 arguments\n";
+ di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
+ di << "Style must match Aspect_InteriorStyle and be one of:\n";
+ di << " 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
return 1;
+ }
- Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
- Standard_Boolean ThereIsArgument= argc>1;
-
- if (TheAISContext()->HasOpenedContext())
- TheAISContext()->CloseLocalContext();
+ Standard_Boolean ThereIsCurrent;
+ Standard_Boolean ThereIsArgument;
+ Standard_Boolean IsBound = Standard_False ;
- //===============================================================
- // Il n'y a pas d'arguments mais des objets selectionnes(current)
- // dans le viewer
- //===============================================================
- if (!ThereIsArgument && ThereIsCurrent) {
+ ThereIsArgument = (argc > 2);
+ if ( !a3DView().IsNull() ) {
+ TCollection_AsciiString name;
+ if (ThereIsArgument) {
+ name = argv[1];
+ IsBound= GetMapOfAIS().IsBound2(name);
+ }
+ if (TheAISContext()->HasOpenedContext())
+ TheAISContext()->CloseLocalContext();
-#ifdef DEB
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it (GetMapOfAIS());
-#endif
- for(TheAISContext()->InitCurrent();
- TheAISContext()->MoreCurrent();
- TheAISContext()->NextCurrent()){
- Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current();
- TheAISContext()->Erase(aShape,Standard_False);}
- }
- TheAISContext() ->UpdateCurrentViewer();
- //===============================================================
- // Il y a des arguments
- //===============================================================
- if (ThereIsArgument) {
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it (GetMapOfAIS());
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- TheAISContext()->Erase(aShape,Standard_False);
- } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- const Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(it.Key1());
- TheNISContext()->Erase(aShape);
+ if (TheAISContext() -> NbCurrents() > 0 )
+ ThereIsCurrent =Standard_True;
+ else
+ ThereIsCurrent =Standard_False;
+
+ if ( ThereIsArgument && IsBound ) {
+ const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
+ if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
+ const Handle(AIS_InteractiveObject) ashape =
+ Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
+ SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
}
- it.Next();
}
-
- // On display les objets passes par parametre
- for (int i=1; i<argc ; i++) {
- TCollection_AsciiString name=argv[i];
- Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
- if (IsBound) {
- const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
- if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast (anObj);
- TheAISContext()->Display(aShape, Standard_False);
- } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast (anObj);
- TheNISContext()->Display(aShape);
- }
+ //=======================================================================
+ // No arguments specified
+ // But there are one or more selected objects
+ //=======================================================================
+ if (ThereIsCurrent && !ThereIsArgument) {
+ for (TheAISContext() -> InitCurrent() ;
+ TheAISContext() -> MoreCurrent() ;
+ TheAISContext() ->NextCurrent() )
+ {
+ Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current();
+ SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
+ }
+ }
+ //=======================================================================
+ // No arguments specified and there are no selected objects
+ //=======================================================================
+ else if (!ThereIsCurrent && !ThereIsArgument){
+ ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
+ it(GetMapOfAIS());
+ while ( it.More() ) {
+ Handle(AIS_InteractiveObject) ashape =
+ Handle(AIS_InteractiveObject)::DownCast (it.Key1());
+ if (!ashape.IsNull())
+ SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
+ it.Next();
}
}
- TheAISContext() ->UpdateCurrentViewer();
-// TheNISContext() ->UpdateViews();
+ TheAISContext()->UpdateCurrentViewer();
}
return 0;
}
//==============================================================================
-//function : VErase2
+//function : VDonly2
//author : ege
-//purpose : Erase some selected or named objects
-// if there is no selected or named objects, the whole viewer is erased
-//Draw arg : verase2 [name1] ... [name n]
+//purpose : Display only a selected or named object
+// if there is no selected or named object s, nothing is done
//==============================================================================
-static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
-
+static int VDonly2 (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
{
- if ( a3DView().IsNull() )
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ if (aCtx.IsNull())
+ {
+ std::cerr << "Error: no active view!\n";
return 1;
+ }
- Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
- Standard_Boolean ThereIsArgument= argc>1;
- if(TheAISContext()->HasOpenedContext())
- TheAISContext()->CloseLocalContext();
+ if (aCtx->HasOpenedContext())
+ {
+ aCtx->CloseLocalContext();
+ }
+ ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
- //===============================================================
- // Il n'y a pas d'arguments mais des objets selectionnes(current)
- // dans le viewer
- //===============================================================
- if (!ThereIsArgument && ThereIsCurrent) {
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it (GetMapOfAIS());
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- if (TheAISContext()->IsCurrent(aShape))
- TheAISContext()->Erase(aShape,Standard_False);
- }
- it.Next();
+ Standard_Integer anArgIter = 1;
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ {
+ break;
}
-
- TheAISContext() ->UpdateCurrentViewer();
}
- //===============================================================
- // Il n'y a pas d'arguments et aucuns objets selectionnes
- // dans le viewer:
- // On erase tout le viewer
- //===============================================================
+ NCollection_Map<Handle(Standard_Transient)> aDispSet;
+ if (anArgIter >= theArgNb)
+ {
+ // display only selected objects
+ if (aCtx->NbCurrents() < 1)
+ {
+ return 0;
+ }
- if (!ThereIsArgument && !ThereIsCurrent) {
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- TheAISContext()->Erase(aShape,Standard_False);
- } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- const Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(it.Key1());
- TheNISContext()->Erase(aShape);
- }
- it.Next();
+ for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
+ {
+ aDispSet.Add (aCtx->Current());
}
- TheAISContext() ->UpdateCurrentViewer();
-// TheNISContext()->UpdateViews();
}
-
- //===============================================================
- // Il y a des arguments
- //===============================================================
- if (ThereIsArgument) {
- for (int i=1; i<argc ; i++) {
- TCollection_AsciiString name=argv[i];
- Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
- if (IsBound) {
- const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
- if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast (anObj);
- TheAISContext()->Erase(aShape,Standard_False);
- } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- const Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast (anObj);
- TheNISContext()->Erase(aShape);
+ else
+ {
+ // display only specified objects
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ TCollection_AsciiString aName = theArgVec[anArgIter];
+ if (GetMapOfAIS().IsBound2 (aName))
+ {
+ const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
+ if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+ {
+ const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
+ aCtx->Display (aShape, Standard_False);
}
+ else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
+ {
+ Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
+ TheNISContext()->Display (aShape);
+ }
+ aDispSet.Add (anObj);
}
}
- TheAISContext() ->UpdateCurrentViewer();
-// TheNISContext() ->UpdateViews();
}
+
+ // weed out other objects
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
+ {
+ if (aDispSet.Contains (anIter.Key1()))
+ {
+ continue;
+ }
+
+ if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+ {
+ const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ aCtx->Erase (aShape, Standard_False);
+ }
+ else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
+ {
+ const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
+ TheNISContext()->Erase (aShape);
+ }
+ }
+
+ // update the screen and redraw the view
+ const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
+ a3DView()->SetImmediateUpdate (isAutoUpdate);
+ if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
+ || aToUpdate == ViewerTest_RM_RedrawForce)
+ {
+ TheAISContext()->UpdateCurrentViewer();
+ }
+
return 0;
}
//==============================================================================
-//function : VEraseAll
-//author : ege
-//purpose : Erase all the objects displayed in the viewer
-//Draw arg : veraseall
+//function : VRemove
+//purpose : Removes selected or named objects.
+// If there is no selected or named objects,
+// all objects in the viewer can be removed with argument -all.
+// If -context is in arguments, the object is not deleted from the map of
+// objects (deleted only from the current context).
//==============================================================================
-static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-
+int VRemove (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
{
- // Verification des arguments
- if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
- if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
- TheAISContext()->CloseAllContexts(Standard_False);
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it(GetMapOfAIS());
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- TheAISContext()->Erase(aShape,Standard_False);
- } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- const Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(it.Key1());
- TheNISContext()->Erase(aShape);
- }
- it.Next();
- }
- TheAISContext() ->UpdateCurrentViewer();
-// TheNISContext() ->UpdateViews();
- return 0;
-}
+ if (a3DView().IsNull())
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+ TheAISContext()->CloseAllContexts (Standard_False);
-//==============================================================================
-//function : VDisplayAll
-//author : ege
-//purpose : Display all the objects of the Map
-//Draw arg : vdisplayall
-//==============================================================================
-static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+ ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
+ Standard_Boolean isContextOnly = Standard_False;
+ Standard_Boolean toRemoveAll = Standard_False;
-{
- if (! a3DView().IsNull() ) {
- if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
- if (TheAISContext()->HasOpenedContext())
- TheAISContext()->CloseLocalContext();
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it (GetMapOfAIS());
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- TheAISContext()->Erase(aShape,Standard_False);
- } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- const Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(it.Key1());
- TheNISContext()->Erase(aShape);
+ Standard_Integer anArgIter = 1;
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ TCollection_AsciiString anArg = theArgVec[anArgIter];
+ anArg.LowerCase();
+ if (anArg == "-context")
+ {
+ isContextOnly = Standard_True;
+ }
+ else if (anArg == "-all")
+ {
+ toRemoveAll = Standard_True;
+ }
+ else if (!parseRedrawMode (anArg, aToUpdate))
+ {
+ break;
+ }
+ }
+ if (toRemoveAll
+ && anArgIter < theArgNb)
+ {
+ std::cout << "Error: wrong syntax!\n";
+ return 1;
+ }
+
+ NCollection_List<TCollection_AsciiString> anIONameList;
+ if (toRemoveAll)
+ {
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ anIONameList.Append (anIter.Key2());
+ }
+ }
+ else if (anArgIter < theArgNb) // removed objects names are in argument list
+ {
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ TCollection_AsciiString aName = theArgVec[anArgIter];
+ if (!GetMapOfAIS().IsBound2 (aName))
+ {
+ theDI << aName.ToCString() << " was not bound to some object.\n";
+ continue;
+ }
+
+ const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
+
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
+ if (!anIO.IsNull())
+ {
+ if (anIO->GetContext() != TheAISContext())
+ {
+ theDI << aName.ToCString() << " was not displayed in current context.\n";
+ theDI << "Please activate view with this object displayed and try again.\n";
+ continue;
+ }
+
+ anIONameList.Append (aName);
+ continue;
+ }
+
+ const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
+ if (!aNisIO.IsNull())
+ {
+ anIONameList.Append (aName);
}
- it.Next();
}
- it.Reset();
- while ( it.More() ) {
- if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- const Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- TheAISContext()->Display(aShape, Standard_False);
- } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(it.Key1());
- TheNISContext()->Display(aShape);
+ }
+ else if (TheAISContext()->NbCurrents() > 0
+ || TheNISContext()->GetSelected().Extent() > 0)
+ {
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ if (!anIO.IsNull())
+ {
+ if (!TheAISContext()->IsCurrent (anIO))
+ {
+ continue;
+ }
+
+ anIONameList.Append (anIter.Key2());
+ continue;
+ }
+
+ const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
+ if (!aNisIO.IsNull())
+ {
+ if (!TheNISContext()->IsSelected (aNisIO))
+ {
+ continue;
+ }
+
+ anIONameList.Append (anIter.Key2());
}
- it.Next();
}
- TheAISContext() ->UpdateCurrentViewer();
-// TheNISContext() ->UpdateViews();
}
+
+ // Unbind all removed objects from the map of displayed IO.
+ for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
+ anIter.More(); anIter.Next())
+ {
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
+
+ if (!anIO.IsNull())
+ {
+ TheAISContext()->Remove (anIO, Standard_False);
+ theDI << anIter.Value().ToCString() << " was removed\n";
+ }
+ else
+ {
+ const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
+ if (!aNisIO.IsNull())
+ {
+ TheNISContext()->Remove (aNisIO);
+ theDI << anIter.Value().ToCString() << " was removed\n";
+ }
+ }
+
+ if (!isContextOnly)
+ {
+ GetMapOfAIS().UnBind2 (anIter.Value());
+ }
+ }
+
+ // update the screen and redraw the view
+ const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
+ a3DView()->SetImmediateUpdate (isAutoUpdate);
+ if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
+ || aToUpdate == ViewerTest_RM_RedrawForce)
+ {
+ TheAISContext()->UpdateCurrentViewer();
+ }
+
return 0;
}
+//==============================================================================
+//function : VErase
+//purpose : Erase some selected or named objects
+// if there is no selected or named objects, the whole viewer is erased
+//==============================================================================
+int VErase (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+{
+ if (a3DView().IsNull())
+ {
+ std::cout << "Error: no active view!\n";
+ return 1;
+ }
+ TheAISContext()->CloseAllContexts (Standard_False);
-//#######################################################################################################
+ ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
+ const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
+ Standard_Integer anArgIter = 1;
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ {
+ break;
+ }
+ }
-static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) {
+ if (anArgIter < theArgNb)
+ {
+ if (toEraseAll)
+ {
+ std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
+ return 1;
+ }
- static Standard_Boolean IsDefined=Standard_False ;
- static TCollection_AsciiString VarName;
- if ( !IsDefined ) {
- const char *envir, *casroot ;
- envir = getenv("CSF_MDTVTexturesDirectory") ;
+ // has a list of names
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ TCollection_AsciiString aName = theArgVec[anArgIter];
+ if (!GetMapOfAIS().IsBound2 (aName))
+ {
+ continue;
+ }
- Standard_Boolean HasDefinition = Standard_False ;
- if ( !envir ) {
- casroot = getenv("CASROOT");
- if ( casroot ) {
- VarName = TCollection_AsciiString (casroot);
- VarName += "/src/Textures" ;
- HasDefinition = Standard_True ;
+ const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
+ theDI << aName.ToCString() << " ";
+ if (!anIO.IsNull())
+ {
+ TheAISContext()->Erase (anIO, Standard_False);
}
- } else {
- VarName = TCollection_AsciiString (envir);
- HasDefinition = Standard_True ;
- }
- if ( HasDefinition ) {
- OSD_Path aPath ( VarName );
- OSD_Directory aDir(aPath);
- if ( aDir.Exists () ) {
- TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
- OSD_File TextureFile ( aTexture );
- if ( !TextureFile.Exists() ) {
- di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
- di << " not all files are found in : "<<VarName.ToCString() << "\n";
- Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
- }
- } else {
- di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n";
- di << " Directory : "<< VarName.ToCString() << " not exist " << "\n";
- Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
+ else
+ {
+ const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
+ if (!aNisIO.IsNull())
+ {
+ TheNISContext()->Erase (aNisIO);
+ }
+ }
+ }
+ }
+ else if (!toEraseAll
+ && TheAISContext()->NbCurrents() > 0)
+ {
+ // remove all currently selected objects
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ if (!anIO.IsNull()
+ && TheAISContext()->IsCurrent (anIO))
+ {
+ theDI << anIter.Key2().ToCString() << " ";
+ TheAISContext()->Erase (anIO, Standard_False);
+ }
+ }
+ }
+ else
+ {
+ // erase entire viewer
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ if (!anIO.IsNull())
+ {
+ TheAISContext()->Erase (anIO, Standard_False);
+ }
+ else
+ {
+ const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
+ if (!aNisIO.IsNull())
+ {
+ TheNISContext()->Erase (aNisIO);
+ }
}
- return VarName ;
- } else {
- di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n";
- di << " one of these variable are mandatory to use this fonctionnality" << "\n";
- Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
}
- IsDefined = Standard_True ;
}
- return VarName ;
+ // update the screen and redraw the view
+ const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
+ a3DView()->SetImmediateUpdate (isAutoUpdate);
+ if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
+ || aToUpdate == ViewerTest_RM_RedrawForce)
+ {
+ TheAISContext()->UpdateCurrentViewer();
+ }
+
+ return 0;
}
-//#######################################################################################################
+//==============================================================================
+//function : VDisplayAll
+//author : ege
+//purpose : Display all the objects of the Map
+//==============================================================================
+static int VDisplayAll (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+
+{
+ if (a3DView().IsNull())
+ {
+ std::cout << "Error: no active view!\n";
+ return 1;
+ }
+ ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
+
+ Standard_Integer anArgIter = 1;
+ for (; anArgIter < theArgNb; ++anArgIter)
+ {
+ if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+ {
+ break;
+ }
+ }
+ if (anArgIter < theArgNb)
+ {
+ std::cout << theArgVec[0] << "Error: wrong syntax\n";
+ return 1;
+ }
+
+ if (TheAISContext()->HasOpenedContext())
+ {
+ TheAISContext()->CloseLocalContext();
+ }
+
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+ {
+ const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ TheAISContext()->Erase (aShape, Standard_False);
+ }
+ else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
+ {
+ const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
+ TheNISContext()->Erase (aShape);
+ }
+ }
-//#######################################################################################################
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+ anIter.More(); anIter.Next())
+ {
+ if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+ {
+ const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+ TheAISContext()->Display (aShape, Standard_False);
+ }
+ else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
+ {
+ Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
+ TheNISContext()->Display (aShape);
+ }
+ }
-//## VTexture
+ // update the screen and redraw the view
+ const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
+ a3DView()->SetImmediateUpdate (isAutoUpdate);
+ if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
+ || aToUpdate == ViewerTest_RM_RedrawForce)
+ {
+ TheAISContext()->UpdateCurrentViewer();
+ }
-//#######################################################################################################
+ return 0;
+}
-Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv )
+//==============================================================================
+//function : VTexture
+//purpose :
+//==============================================================================
+Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
{
- Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1:
- (strcasecmp(argv[0],"vtexscale")==0) ? 2 :
- (strcasecmp(argv[0],"vtexorigin")==0) ? 3 :
- (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 :
- (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1;
+ TCollection_AsciiString aCommandName (theArgv[0]);
- Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
- if(myAISContext.IsNull())
+ NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString> aMapOfArgs;
+ if (aCommandName == "vtexture")
+ {
+ if (theArgsNb < 2)
{
- di << "use 'vinit' command before " << argv[0] << "\n";
+ std::cout << theArgv[0] << ": " << " invalid arguments.\n";
+ std::cout << "Type help for more information.\n";
return 1;
}
- Handle(AIS_InteractiveObject) TheAisIO;
- Handle(AIS_TexturedShape) myShape;
- Standard_Integer myPreviousMode = 0;
+ // look for options of vtexture command
+ TCollection_AsciiString aParseKey;
+ for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
+ {
+ TCollection_AsciiString anArg (theArgv [anArgIt]);
+
+ anArg.UpperCase();
+ if (anArg.Value (1) == '-' && !anArg.IsRealValue())
+ {
+ aParseKey = anArg;
+ aParseKey.Remove (1);
+ aParseKey.UpperCase();
+ aMapOfArgs.Bind (aParseKey, TColStd_SequenceOfAsciiString());
+ continue;
+ }
+
+ if (aParseKey.IsEmpty())
+ {
+ continue;
+ }
- if (argc<2 || !argv[1])
+ aMapOfArgs.ChangeFind (aParseKey).Append (anArg);
+ }
+ }
+ else if (aCommandName == "vtexscale"
+ || aCommandName == "vtexorigin"
+ || aCommandName == "vtexrepeat")
+ {
+ // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
+ // equal to -scale, -origin, -repeat options of vtexture command
+ if (theArgsNb < 2 || theArgsNb > 4)
{
- di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n";
+ std::cout << theArgv[0] << ": " << " invalid arguments.\n";
+ std::cout << "Type help for more information.\n";
return 1;
}
- TCollection_AsciiString name = argv[1];
- ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL);
+ TColStd_SequenceOfAsciiString anArgs;
+ if (theArgsNb == 2)
+ {
+ anArgs.Append ("OFF");
+ }
+ else if (theArgsNb == 4)
+ {
+ anArgs.Append (TCollection_AsciiString (theArgv[2]));
+ anArgs.Append (TCollection_AsciiString (theArgv[3]));
+ }
+
+ TCollection_AsciiString anArgKey;
+ if (aCommandName == "vtexscale")
+ {
+ anArgKey = "SCALE";
+ }
+ else if (aCommandName == "vtexorigin")
+ {
+ anArgKey = "ORIGIN";
+ }
+ else
+ {
+ anArgKey = "REPEAT";
+ }
- if (GetMapOfAIS().IsBound2(name))
- TheAisIO = Handle(AIS_InteractiveObject)::DownCast
- (GetMapOfAIS().Find2(name));
- if (TheAisIO.IsNull())
+ aMapOfArgs.Bind (anArgKey, anArgs);
+ }
+ else if (aCommandName == "vtexdefault")
{
- di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n";
- return 1;
+ // scan for parameters of vtexdefault command
+ // equal to -default option of vtexture command
+ aMapOfArgs.Bind ("DEFAULT", TColStd_SequenceOfAsciiString());
}
- if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull())
+ // Check arguments for validity
+ NCollection_DataMap<TCollection_AsciiString, TColStd_SequenceOfAsciiString>::Iterator aMapIt (aMapOfArgs);
+ for (; aMapIt.More(); aMapIt.Next())
+ {
+ const TCollection_AsciiString& aKey = aMapIt.Key();
+ const TColStd_SequenceOfAsciiString& anArgs = aMapIt.Value();
+
+ // -scale, -origin, -repeat: one argument "off", or two real values
+ if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
+ && ((anArgs.Length() == 1 && anArgs (1) == "OFF")
+ || (anArgs.Length() == 2 && anArgs (1).IsRealValue() && anArgs (2).IsRealValue())))
{
- myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO);
- myPreviousMode = myShape->DisplayMode() ;
+ continue;
}
- else
+
+ // -modulate: single argument "on" / "off"
+ if (aKey.IsEqual ("MODULATE") && anArgs.Length() == 1 && (anArgs (1) == "OFF" || anArgs (1) == "ON"))
{
- myAISContext->Clear(TheAisIO,Standard_False);
- myShape = new AIS_TexturedShape (DBRep::Get(argv[1]));
- GetMapOfAIS().UnBind1(TheAisIO);
- GetMapOfAIS().UnBind2(name);
- GetMapOfAIS().Bind(myShape, name);
+ continue;
}
- switch (command)
+
+ // -default: no arguments
+ if (aKey.IsEqual ("DEFAULT") && anArgs.IsEmpty())
{
- case 1: // vtexture : we only map a texture on the shape
- if(argc<=1)
- {
- di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
- return 1;
- }
- if (argc>2 && argv[2])
- {
- if(strcasecmp(argv[2],"?")==0)
- {
- TCollection_AsciiString monPath = GetEnvir (di) ;
-
- di<<"\n Files in current directory : \n"<<"\n";
- TCollection_AsciiString Cmnd ("glob -nocomplain *");
- di.Eval(Cmnd.ToCString());
-
- Cmnd = TCollection_AsciiString("glob -nocomplain ") ;
- Cmnd += monPath ;
- Cmnd += "/* " ;
- di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n";
- di.Eval(Cmnd.ToCString());
-
- return 0;
- }
- else
- myShape->SetTextureFileName(argv[2]);
- }
- else
- {
- di <<"Texture mapping disabled \n \
- To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n";
-
- myAISContext->SetDisplayMode(myShape,1,Standard_False);
- if (myPreviousMode == 3 )
- myAISContext->RecomputePrsOnly(myShape);
- myAISContext->Display(myShape, Standard_True);
- return 0;
- }
- break;
+ continue;
+ }
- case 2: // vtexscale : we change the scaling factor of the texture
+ TCollection_AsciiString aLowerKey;
+ aLowerKey = "-";
+ aLowerKey += aKey;
+ aLowerKey.LowerCase();
+ std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
+ std::cout << "Type help for more information.\n";
+ return 1;
+ }
- if(argc<2)
- {
- di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
- return 1;
- }
+ Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+ if (anAISContext.IsNull())
+ {
+ std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
+ return 1;
+ }
- myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ),
- ( argv[2] ? atof(argv[2]) : 1.0 ),
- ( argv[2] ? atof(argv[argc-1]) : 1.0 ) );
- break;
+ Standard_Integer aPreviousMode = 0;
- case 3: // vtexorigin : we change the origin of the texture on the shape
- if(argc<2)
- {
- di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
- return 1;
- }
- myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ),
- ( argv[2] ? atof(argv[2]) : 0.0 ),
- ( argv[2] ? atof(argv[argc-1]) : 0.0 ));
- break;
+ ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
- case 4: // vtexrepeat : we change the number of occurences of the texture on the shape
- if(argc<2)
- {
- di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
- return 1;
- }
- if (argc>2 && argv[2])
- {
- di <<"Texture repeat enabled"<<"\n";
- myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) );
- }
- else
- {
- di <<"Texture repeat disabled"<<"\n";
- myShape->SetTextureRepeat(Standard_False);
- }
- break;
+ TCollection_AsciiString aShapeName (theArgv[1]);
+ Handle(AIS_InteractiveObject) anIO;
- case 5: // vtexdefault : default texture mapping
- // ScaleU = ScaleV = 100.0
- // URepeat = VRepeat = 1.0
- // Uorigin = VOrigin = 0.0
+ const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
+ if (aMapOfIO.IsBound2 (aShapeName))
+ {
+ anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
+ }
- if(argc<2)
- {
- di << argv[0] <<" syntax error - Type 'help vtex'" << "\n";
- return 1;
- }
- myShape->SetTextureRepeat(Standard_False);
- myShape->SetTextureOrigin(Standard_False);
- myShape->SetTextureScale (Standard_False);
- break;
- }
+ if (anIO.IsNull())
+ {
+ std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
+ return 1;
+ }
- if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 ))
- myAISContext->RecomputePrsOnly(myShape);
+ Handle(AIS_TexturedShape) aTexturedIO;
+ if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
+ {
+ aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
+ aPreviousMode = aTexturedIO->DisplayMode();
+ }
else
+ {
+ anAISContext->Clear (anIO, Standard_False);
+ aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
+ GetMapOfAIS().UnBind1 (anIO);
+ GetMapOfAIS().UnBind2 (aShapeName);
+ GetMapOfAIS().Bind (aTexturedIO, aShapeName);
+ }
+
+ // -------------------------------------------
+ // Turn texturing on/off - only for vtexture
+ // -------------------------------------------
+
+ if (aCommandName == "vtexture")
+ {
+ TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
+
+ if (aTextureArg.IsEmpty())
{
- myAISContext->SetDisplayMode(myShape,3,Standard_False);
- myAISContext->Display(myShape, Standard_True);
- myAISContext->Update(myShape,Standard_True);
+ std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
+ std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
+
+ anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
+ if (aPreviousMode == 3)
+ {
+ anAISContext->RecomputePrsOnly (aTexturedIO);
+ }
+
+ anAISContext->Display (aTexturedIO, Standard_True);
+ return 0;
}
- return 0;
-}
+ else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
+ {
+ if (aTextureArg == "?")
+ {
+ TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
-//==============================================================================
-//function : VDisplay2
-//author : ege
-//purpose : Display an object from its name
-//Draw arg : vdisplay name1 [name2] ... [name n]
-//==============================================================================
-static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+ theDi << "\n Files in current directory : \n" << "\n";
+ theDi.Eval ("glob -nocomplain *");
-{
- // Verification des arguments
- if ( a3DView().IsNull() ) {
+ TCollection_AsciiString aCmnd ("glob -nocomplain ");
+ aCmnd += aTextureFolder;
+ aCmnd += "/* ";
- ViewerTest::ViewerInit();
- di<<"La commande vinit n'a pas ete appele avant"<<"\n";
- // return 1;
+ theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
+ theDi.Eval (aCmnd.ToCString());
+ return 0;
+ }
+ else
+ {
+ aTexturedIO->SetTextureFileName (aTextureArg);
+ }
+ }
}
- if ( argc<2) {
- di<<argv[0]<<" Syntaxe error"<<"\n";
- return 1;
- }
+ // ------------------------------------
+ // Process other options and commands
+ // ------------------------------------
+ TColStd_SequenceOfAsciiString aValues;
+ if (aMapOfArgs.Find ("DEFAULT", aValues))
+ {
+ aTexturedIO->SetTextureRepeat (Standard_False);
+ aTexturedIO->SetTextureOrigin (Standard_False);
+ aTexturedIO->SetTextureScale (Standard_False);
+ aTexturedIO->EnableTextureModulate();
+ }
+ else
+ {
+ if (aMapOfArgs.Find ("SCALE", aValues))
+ {
+ if (aValues (1) != "OFF")
+ {
+ aTexturedIO->SetTextureScale (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
+ }
+ else
+ {
+ aTexturedIO->SetTextureScale (Standard_False);
+ }
+ }
- TCollection_AsciiString name;
- if (TheAISContext()->HasOpenedContext())
- TheAISContext()->CloseLocalContext();
+ if (aMapOfArgs.Find ("ORIGIN", aValues))
+ {
+ if (aValues (1) != "OFF")
+ {
+ aTexturedIO->SetTextureOrigin (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
+ }
+ else
+ {
+ aTexturedIO->SetTextureOrigin (Standard_False);
+ }
+ }
- for ( int i = 1; i < argc; i++ ) {
- name = argv[i];
- Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
- Standard_Boolean IsDatum = Standard_False;
- Handle(Standard_Transient) anObj;
- if ( IsBound ) {
- anObj = GetMapOfAIS().Find2(name);
- if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
- Handle(AIS_InteractiveObject) aShape =
- Handle(AIS_InteractiveObject)::DownCast(anObj);
- if (aShape->Type()==AIS_KOI_Datum) {
- IsDatum = Standard_True;
- TheAISContext()->Display(aShape, Standard_False);
- }
- if (!IsDatum) {
- di << "Display " << name.ToCString() << "\n";
- // Get the Shape from a name
- TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString());
-
- // Update the Shape in the AIS_Shape
- Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape);
- if(!TheRealSh.IsNull())
- TheRealSh->Set(NewShape);
- TheAISContext()->Redisplay(aShape, Standard_False);
- TheAISContext()->Display(aShape, Standard_False);
- }
- aShape.Nullify();
- } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
- Handle(NIS_InteractiveObject) aShape =
- Handle(NIS_InteractiveObject)::DownCast(anObj);
- TheNISContext()->Display(aShape);
+ if (aMapOfArgs.Find ("REPEAT", aValues))
+ {
+ if (aValues (1) != "OFF")
+ {
+ aTexturedIO->SetTextureRepeat (Standard_True, aValues (1).RealValue(), aValues (2).RealValue());
+ }
+ else
+ {
+ aTexturedIO->SetTextureRepeat (Standard_False);
}
}
- else { // Create the AIS_Shape from a name
- const Handle(AIS_InteractiveObject) aShape =
- GetAISShapeFromName((const char *)name.ToCString());
- if ( !aShape.IsNull() ) {
- GetMapOfAIS().Bind(aShape, name);
- TheAISContext()->Display(aShape, Standard_False);
+
+ if (aMapOfArgs.Find ("MODULATE", aValues))
+ {
+ if (aValues (1) == "ON")
+ {
+ aTexturedIO->EnableTextureModulate();
+ }
+ else
+ {
+ aTexturedIO->DisableTextureModulate();
}
}
}
- // Upadate the screen and redraw the view
- TheAISContext()->UpdateCurrentViewer();
-// TheNISContext()->UpdateViews();
+
+ if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
+ {
+ anAISContext->RecomputePrsOnly (aTexturedIO);
+ }
+ else
+ {
+ anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
+ anAISContext->Display (aTexturedIO, Standard_True);
+ anAISContext->Update (aTexturedIO,Standard_True);
+ }
+
return 0;
}
//==============================================================================
-//function : VMoveA
-//purpose : Test the annimation of an object along a
-// predifined trajectory
-//Draw arg : vmove ShapeName
+//function : VDisplay2
+//author : ege
+//purpose : Display an object from its name
//==============================================================================
-
-#ifdef DEB
-static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
-
- OSD_Timer myTimer;
- myTimer.Start();
-
- if (TheAISContext()->HasOpenedContext())
- TheAISContext()->CloseLocalContext();
-
- Standard_Real Step=2*M_PI/180;
- Standard_Real Angle=0;
- // R est le rayon de l'hellicoide
- Standard_Real R=50;
- // D est la distance parcourue en translation en 1 tour
- Standard_Real D=50;
-
- Handle(AIS_InteractiveObject) aIO;
-
- if (GetMapOfAIS().IsBound2(argv[1]))
- aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
-
- if (aIO.IsNull()) {
- di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n";
+static int VDisplay2 (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+{
+ if (theArgNb < 2)
+ {
+ std::cout << theArgVec[0] << "Error: wrong syntax!\n";
return 1;
}
- TheAISContext()->Deactivate(aIO);
-
- // boucle generant le mouvement
- if(argc==3) {
- di<<" Transformations"<<"\n";
- for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
+ else if (a3DView().IsNull())
+ {
+ ViewerTest::ViewerInit();
+ std::cout << "Command vinit should be called before!\n";
+ // return 1;
+ }
- Angle=Step*myAngle;
- gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) );
- gp_Trsf myTransfo;
- myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) );
- TheAISContext()->SetLocation(aIO,myTransfo);
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ if (aCtx->HasOpenedContext())
+ {
+ aCtx->CloseLocalContext();
+ }
- TheAISContext() ->UpdateCurrentViewer();
+ ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+ {
+ const TCollection_AsciiString aName = theArgVec[anArgIter];
+ if (parseRedrawMode (aName, aToUpdate))
+ {
+ continue;
+ }
+ else if (!GetMapOfAIS().IsBound2 (aName))
+ {
+ // create the AIS_Shape from a name
+ const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
+ if (!aShape.IsNull())
+ {
+ GetMapOfAIS().Bind (aShape, aName);
+ aCtx->Display (aShape, Standard_False);
+ }
+ continue;
+ }
+ Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
+ if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
+ {
+ Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
+ if (aShape->Type() == AIS_KOI_Datum)
+ {
+ aCtx->Display (aShape, Standard_False);
+ }
+ else
+ {
+ theDI << "Display " << aName.ToCString() << "\n";
+ // get the Shape from a name
+ TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
+
+ // update the Shape in the AIS_Shape
+ Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
+ if (!aShapePrs.IsNull())
+ {
+ aShapePrs->Set (aNewShape);
+ }
+ aCtx->Redisplay (aShape, Standard_False);
+ aCtx->Display (aShape, Standard_False);
+ }
+ aShape.Nullify();
+ }
+ else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
+ {
+ Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
+ TheNISContext()->Display (aShape);
}
}
- else {
- di<<" Locations"<<"\n";
- gp_Trsf myAngleTrsf;
- myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
- TopLoc_Location myDeltaAngle (myAngleTrsf);
- gp_Trsf myDistTrsf;
- myDistTrsf.SetTranslation(gp_Dir(0,0,1) );
- TopLoc_Location myDeltaDist (myDistTrsf);
- TopLoc_Location myTrueLoc;
-
- for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) {
- Angle=Step*myAngle;
- myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist;
- TheAISContext()->SetLocation(aIO,myTrueLoc );
- TheAISContext() ->UpdateCurrentViewer();
- }
+ const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
+ a3DView()->SetImmediateUpdate (isAutoUpdate);
+ if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
+ || aToUpdate == ViewerTest_RM_RedrawForce)
+ {
+ // update the screen and redraw the view
+ aCtx->UpdateCurrentViewer();
}
+ return 0;
+}
+//===============================================================================================
+//function : VUpdate
+//purpose :
+//===============================================================================================
+static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
+{
+ Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+ if (aContextAIS.IsNull())
+ {
+ std::cout << theArgVec[0] << "AIS context is not available.\n";
+ return 1;
+ }
- TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() );
-
- //TopLoc_Location Tempo=aIO->Location();
- //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape());
- //ShapeBis.Located(Tempo);
-
-
- // On reset la location (origine) contenue dans l'AISInteractiveObject
- TheAISContext() ->ResetLocation(aIO);
+ if (theArgsNb < 2)
+ {
+ std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
+ return 1;
+ }
- // On force aShape a devenir l'AIS IO propre a ShapeBis
+ const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
- // Pour cela on force aShape(AIS IO) a devenir une AISShape
- // ->Set() est une methode de AIS_Shape
- (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis);
+ AIS_ListOfInteractive aListOfIO;
- // On donne a ShapeBis le nom de l'AIS IO
- //Rep::Set(argv[1],ShapeBis);
+ for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
+ {
+ TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
+ Handle(AIS_InteractiveObject) anAISObj;
+ if (anAISMap.IsBound2 (aName))
+ {
+ anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
+ }
- TheAISContext()->Redisplay(aIO,Standard_False);
+ if (anAISObj.IsNull())
+ {
+ std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
+ return 1;
+ }
- // On reactive la selection des primitives sensibles
- TheAISContext()->Activate(aIO,0);
+ aListOfIO.Append (anAISObj);
+ }
- TheAISContext() ->UpdateCurrentViewer();
- a3DView() -> Redraw();
+ AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
+ for (; anIOIt.More(); anIOIt.Next())
+ {
+ aContextAIS->Update (anIOIt.Value(), Standard_False);
+ }
- myTimer.Stop();
- di<<" Temps ecoule "<<"\n";
- myTimer.Show();
+ aContextAIS->UpdateCurrentViewer();
return 0;
}
-#endif
-
//==============================================================================
//function : VPerf
myTimer.Start();
- if (atoi(argv[3])==1 ) {
+ if (Draw::Atoi(argv[3])==1 ) {
di<<" Primitives sensibles OFF"<<"\n";
TheAISContext()->Deactivate(aIO);
}
di<<" Primitives sensibles ON"<<"\n";
}
// Movement par transformation
- if(atoi(argv[2]) ==1) {
+ if(Draw::Atoi(argv[2]) ==1) {
di<<" Calcul par Transformation"<<"\n";
for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
TheAISContext() ->UpdateCurrentViewer();
}
}
- if (atoi(argv[3])==1 ){
+ if (Draw::Atoi(argv[3])==1 ){
// On reactive la selection des primitives sensibles
TheAISContext()->Activate(aIO,0);
}
if (argc < 3) {
myDevCoef = 0.0008;
} else {
- myDevCoef =atof(argv[2]);
+ myDevCoef =Draw::Atof(argv[2]);
}
TCollection_AsciiString name=argv[1];
// IL n'y a aps de nom de shape passe en argument
if (HaveToSet && !ThereIsName){
- Standard_Integer aMode=atoi(argv [1]);
+ Standard_Integer aMode=Draw::Atoi(argv [1]);
const char *cmode="???";
switch (aMode) {
}
}
else if (HaveToSet && ThereIsName){
- Standard_Integer aMode=atoi(argv [2]);
+ Standard_Integer aMode=Draw::Atoi(argv [2]);
Handle(AIS_InteractiveObject) aIO =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
}
}
return 0;
-
}
+//! Auxiliary method to print Interactive Object information
+static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
+ const Handle(Standard_Transient)& theObject,
+ Draw_Interpretor& theDI)
+{
+ const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
+ if (anObj.IsNull())
+ {
+ theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
+ return;
+ }
-
-//==============================================================================
-// function : WhoAmI
-// user : vState
-//==============================================================================
-void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) {
-
- // AIS_Datum
- if (theShape->Type()==AIS_KOI_Datum) {
- if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; }
- else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; }
- else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; }
- else if (theShape->Signature()==5 ) { di<<" AIS_Line"; }
- else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; }
- else if (theShape->Signature()==1 ) { di<<" AIS_Point"; }
- else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; }
+ theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
+ << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
+ << (theDetected.Contains (anObj) ? " Detected" : " ")
+ << " Type: ";
+ if (anObj->Type() == AIS_KOI_Datum)
+ {
+ // AIS_Datum
+ if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
+ else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
+ else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
+ else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
+ else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
+ else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
+ else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
}
// AIS_Shape
- else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; }
- // AIS_Dimentions et AIS_Relations
- else if (theShape->Type()==AIS_KOI_Relation) {
- Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape));
-
- if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";}
- else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; }
- else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";}
- else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";}
- //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;}
- else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";}
- else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";}
- // AIS no repertorie.
- else {di<<" Type Unknown.";}
+ else if (anObj->Type() == AIS_KOI_Shape
+ && anObj->Signature() == 0)
+ {
+ theDI << " AIS_Shape";
+ }
+ else if (anObj->Type() == AIS_KOI_Relation)
+ {
+ // AIS_Dimention and AIS_Relation
+ Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
+ switch (aRelation->KindOfDimension())
+ {
+ case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
+ case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
+ case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
+ case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
+ //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
+ case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
+ case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
+ default: theDI << " UNKNOWN dimension"; break;
+ }
}
+ else
+ {
+ theDI << " UserPrs";
+ }
+ theDI << " (" << theObject->DynamicType()->Name() << ")";
}
+//! Print information about locally selected sub-shapes
+static void localCtxInfo (Draw_Interpretor& theDI)
+{
+ Handle(AIS_InteractiveContext) aCtx = TheAISContext();
+ if (!aCtx->HasOpenedContext())
+ {
+ return;
+ }
+
+ TCollection_AsciiString aPrevName;
+ Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
+ for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
+ {
+ const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
+ const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
+ if (aSubShape.IsNull()
+ || aShapeIO.IsNull()
+ || !GetMapOfAIS().IsBound1 (aShapeIO))
+ {
+ continue;
+ }
+
+ const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
+ TopTools_MapOfShape aFilter;
+ Standard_Integer aNumber = 0;
+ const TopoDS_Shape aShape = aShapeIO->Shape();
+ for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
+ anIter.More(); anIter.Next())
+ {
+ if (!aFilter.Add (anIter.Current()))
+ {
+ continue; // filter duplicates
+ }
+
+ ++aNumber;
+ if (!anIter.Current().IsSame (aSubShape))
+ {
+ continue;
+ }
+
+ Standard_CString aShapeName = NULL;
+ switch (aSubShape.ShapeType())
+ {
+ case TopAbs_COMPOUND: aShapeName = " Compound"; break;
+ case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
+ case TopAbs_SOLID: aShapeName = " Solid"; break;
+ case TopAbs_SHELL: aShapeName = " Shell"; break;
+ case TopAbs_FACE: aShapeName = " Face"; break;
+ case TopAbs_WIRE: aShapeName = " Wire"; break;
+ case TopAbs_EDGE: aShapeName = " Edge"; break;
+ case TopAbs_VERTEX: aShapeName = " Vertex"; break;
+ default:
+ case TopAbs_SHAPE: aShapeName = " Shape"; break;
+ }
+ if (aParentName != aPrevName)
+ {
+ theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
+ aPrevName = aParentName;
+ }
+ theDI << " " << aShapeName << " #" << aNumber << "\n";
+ break;
+ }
+ }
+}
//==============================================================================
//function : VState
//purpose :
//Draw arg : vstate [nameA] ... [nameN]
//==============================================================================
-static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
- TheAISContext()->CloseAllContexts();
- const Standard_Boolean ThereIsArguments=(argc>=2);
- const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0);
- // Debut...
- // ==================
- // Il y a un argument
- // ==================
- if (ThereIsArguments) {
- for (int cpt=1;cpt<argc;cpt++) {
- // Verification que lq piece est bien bindee.
- if (GetMapOfAIS().IsBound2(argv[cpt]) ) {
- const Handle(AIS_InteractiveObject) theShape=
- Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2
- (argv[cpt]));
- if (!theShape.IsNull()) {
- di<<argv[cpt];WhoAmI(theShape, di);
- if (TheAISContext()->IsDisplayed(theShape) ) {
- di<<" Displayed"<<"\n";
- }
- else {
- di<<" Not Displayed"<<"\n";
- }
- }
- }
- else {
- di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1;
- }
- }
+static Standard_Integer VState (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ Standard_CString* theArgVec)
+{
+ Handle(AIS_InteractiveContext) aCtx = TheAISContext();
+ if (aCtx.IsNull())
+ {
+ std::cerr << "Error: No opened viewer!\n";
+ return 1;
+ }
+
+ NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
+ for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
+ {
+ aDetected.Add (aCtx->DetectedCurrentObject());
}
- else if (ThereIsCurrent ) {
- for (TheAISContext() -> InitCurrent() ;
- TheAISContext() -> MoreCurrent() ;
- TheAISContext() ->NextCurrent() )
+
+ const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
+ if (theArgNb >= 2
+ && !toShowAll)
+ {
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
{
- Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current();
- di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di);
- if (TheAISContext()->IsDisplayed(theShape) ) {
- di<<" Displayed"<<"\n";
- }
- else {
- di<<" Not Displayed"<<"\n";
+ const TCollection_AsciiString anObjName = theArgVec[anArgIter];
+ if (!GetMapOfAIS().IsBound2 (anObjName))
+ {
+ theDI << anObjName << " doesn't exist!\n";
+ continue;
}
+ const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
+ TCollection_AsciiString aName = anObjName;
+ aName.LeftJustify (20, ' ');
+ theDI << " " << aName << " ";
+ objInfo (aDetected, anObjTrans, theDI);
+ theDI << "\n";
}
+ return 0;
}
- else {
- ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
- it(GetMapOfAIS());
- while ( it.More() ) {
- Handle(AIS_InteractiveObject) theShape =
- Handle(AIS_InteractiveObject)::DownCast(it.Key1());
- if (!theShape.IsNull()) {
- di<<it.Key2().ToCString();
- WhoAmI(theShape, di);
- if (TheAISContext()->IsDisplayed(theShape) ) {
- di<<" Displayed"<<"\n";
- }
- else {
- di<<" Not Displayed"<<"\n";
- }
- }
- it.Next();
+
+ if (aCtx->NbCurrents() > 0
+ && !toShowAll)
+ {
+ for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
+ {
+ Handle(AIS_InteractiveObject) anObj = aCtx->Current();
+ TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+ aName.LeftJustify (20, ' ');
+ theDI << aName << " ";
+ objInfo (aDetected, anObj, theDI);
+ theDI << "\n";
}
+ return 0;
}
+ theDI << "Neutral-point state:\n";
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
+ anObjIter.More(); anObjIter.Next())
+ {
+ Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
+ if (anObj.IsNull())
+ {
+ continue;
+ }
+
+ TCollection_AsciiString aName = anObjIter.Key2();
+ aName.LeftJustify (20, ' ');
+ theDI << " " << aName << " ";
+ objInfo (aDetected, anObj, theDI);
+ theDI << "\n";
+ }
+ localCtxInfo (theDI);
return 0;
}
-
//=======================================================================
//function : PickObjects
//purpose :
}
}
return 0;
-
-}
-
-
-//=======================================================================
-//function : VPickObject
-//purpose : filters can be set (type of Object to pick....
-//
-//=======================================================================
-// Unused :
-#ifdef DEB
-static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/)
-{
- // preparation de la nomination automatique
- static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"};
-// static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"};
-
-/* TCollection_AsciiString name;
-
- Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
- if(NbToPick==1){
- PickSh = ViewerTest::PickObject(theType);
-
- if(PickSh.IsNull())
- return 1;
- if(argc>2){
- name += argv[2];
- }
- else{
-
- if(!PickSh.IsNull()){
- nbOfSub[Standard_Integer(theType)]++;
- name += "Picked_";
- name += nameType[Standard_Integer(theType)];
- TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
- name +="_";
- name+=indxstring;
- }
- }
- // si on avait une petite methode pour voir si la shape
- // est deja dans la Double map, ca eviterait de creer....
- DBRep::Set(name.ToCString(),PickSh);
-
- Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
- GetMapOfAIS().Bind(newsh, name);
- TheAISContext()->Display(newsh);
- cout<<"Nom de la shape pickee : "<<name<<endl;
- }
-
- // Plusieurs objets a picker, vite vite vite....
- //
- else{
- Standard_Boolean autonaming = !strcasecmp(argv[2],".");
- Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
- if(ViewerTest::PickShapes(theType,arr)){
- for(Standard_Integer i=1;i<=NbToPick;i++){
- PickSh = arr->Value(i);
- if(!PickSh.IsNull()){
- if(autonaming){
- nbOfSub[Standard_Integer(theType)]++;
- name.Clear();
- name += "Picked_";
- name += nameType[Standard_Integer(theType)];
- TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
- name +="_";
- name+=indxstring;
- }
- }
- else
- name = argv[1+i];
-
- DBRep::Set(name.ToCString(),PickSh);
- Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
- GetMapOfAIS().Bind(newsh, name);
- cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl;
- TheAISContext()->Display(newsh);
-
- }
- }
- }
- */
- return 0;
}
-#endif
//=======================================================================
//function : list of known objects
TCollection_AsciiString shapeName;
shapeName = argv[1];
- Standard_Integer persFlag1 = atoi(argv[2]);
+ Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
Standard_Integer persFlag2 = 0;
Standard_Integer persFlag3 = 0;
gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
- persFlag2 = atoi(argv[3]);
+ persFlag2 = Draw::Atoi(argv[3]);
}
if ( argc == 5 || argc == 8 ) {
- persFlag3 = atoi(argv[4]);
+ persFlag3 = Draw::Atoi(argv[4]);
}
if ( argc >= 6 ) {
- origin.SetX( atof(argv[argc - 3]) );
- origin.SetY( atof(argv[argc - 2]) );
- origin.SetZ( atof(argv[argc - 1]) );
+ origin.SetX( Draw::Atof(argv[argc - 3]) );
+ origin.SetY( Draw::Atof(argv[argc - 2]) );
+ origin.SetZ( Draw::Atof(argv[argc - 1]) );
}
Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
- Standard_Boolean IsDatum = Standard_False;
Handle(Standard_Transient) anObj;
if ( IsBound ) {
anObj = GetMapOfAIS().Find2(shapeName);
Ctx->Display(ais);
return 0;
}
-//============================================================================
-#include <AIS2D_InteractiveContext.hxx>
-#include <HLRAlgo_Projector.hxx>
-#include <Prs3d_Projector.hxx>
-#include <AIS2D_ProjShape.hxx>
-#include <gp_Ax2.hxx>
-#include <gp.hxx>
-Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
-{
-
- Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
- /////////////////////
- TopoDS_Shape aShape = DBRep::Get(a[1]);
- aContext2D->EraseAll(Standard_True);
- Standard_Integer aPolyAlgo = 0;
- Standard_Boolean IsPoly = Standard_False;
- gp_Ax2 anAx2 = gp::XOY();
-
- //if(n > 2) aPolyAlgo = atoi(a[2]);
-
- //IsPoly = aPolyAlgo > 0;
-
- TopoDS_Shape aResult = aShape;
-
-
- if (n == 11)
- {
- Standard_Real x = atof(a[2]);
- Standard_Real y = atof(a[3]);
- Standard_Real z = atof(a[4]);
-
- Standard_Real dx = atof(a[5]);
- Standard_Real dy = atof(a[6]);
- Standard_Real dz = atof(a[7]);
-
- Standard_Real dx1 = atof(a[8]);
- Standard_Real dy1 = atof(a[9]);
- Standard_Real dz1 = atof(a[10]);
-
- gp_Pnt anOrigin (x, y, z);
- gp_Dir aNormal (dx, dy, dz);
- gp_Dir aDX (dx1, dy1, dz1);
- anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
- }
-
-
- HLRAlgo_Projector aProjector(anAx2);
-
- //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
-
- //aProjector = aProjector_t.Projector();
-
- Handle(AIS2D_ProjShape) myDisplayableShape =
- new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
-
- myDisplayableShape->ShowEdges(Standard_True, Standard_False,
- Standard_False, Standard_True, Standard_False);
-
- myDisplayableShape->Add( aResult );
-
-
- aContext2D->Display( myDisplayableShape,Standard_True );
- aContext2D->UpdateCurrentViewer();
-
- return 0;
-}
-
-Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a)
-{
-
- Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext();
- /////////////////////
- TopoDS_Shape aShape = DBRep::Get(a[1]);
- aContext2D->EraseAll(Standard_True);
- Standard_Integer aPolyAlgo = 0;
- Standard_Boolean IsPoly = Standard_True;
- gp_Ax2 anAx2 = gp::XOY();
-
- //if(n > 2) aPolyAlgo = atoi(a[2]);
-
- //IsPoly = aPolyAlgo > 0;
-
- TopoDS_Shape aResult = aShape;
-
-
- if (n == 11)
- {
- Standard_Real x = atof(a[2]);
- Standard_Real y = atof(a[3]);
- Standard_Real z = atof(a[4]);
-
- Standard_Real dx = atof(a[5]);
- Standard_Real dy = atof(a[6]);
- Standard_Real dz = atof(a[7]);
-
- Standard_Real dx1 = atof(a[8]);
- Standard_Real dy1 = atof(a[9]);
- Standard_Real dz1 = atof(a[10]);
-
- gp_Pnt anOrigin (x, y, z);
- gp_Dir aNormal (dx, dy, dz);
- gp_Dir aDX (dx1, dy1, dz1);
- anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
- }
-
-
- HLRAlgo_Projector aProjector(anAx2);
-
- //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0);
-
- //aProjector = aProjector_t.Projector();
-
- Handle(AIS2D_ProjShape) myDisplayableShape =
- new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False);
-
- myDisplayableShape->ShowEdges(Standard_True, Standard_False,
- Standard_False, Standard_True, Standard_False);
-
- myDisplayableShape->Add( aResult );
-
-
- aContext2D->Display( myDisplayableShape,Standard_True );
- aContext2D->UpdateCurrentViewer();
-
- return 0;
-}
//==============================================================================
//function : ViewerTest::Commands
ViewerTest::ObjectCommands(theCommands);
ViewerTest::FilletCommands(theCommands);
ViewerTest::VoxelCommands(theCommands);
+ ViewerTest::OpenGlCommands(theCommands);
const char *group = "AIS_Display";
// display
+ theCommands.Add("visos",
+ "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
+ "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
+ __FILE__, visos, group);
theCommands.Add("vdisplay",
- "vdisplay : vdisplay2 name1 [name2] ... [name n] ",
+ "vdisplay [-noupdate|-update] name1 [name2] ... [name n]"
+ "\n\t\t: Displays named objects."
+ "\n\t\t: Option -noupdate suppresses viewer redraw call."
__FILE__,VDisplay2,group);
+ theCommands.Add ("vupdate",
+ "vupdate name1 [name2] ... [name n]"
+ "\n\t\t: Updates named objects in interactive context",
+ __FILE__, VUpdate, group);
+
theCommands.Add("verase",
- "verase : verase2 [name1] ... [name n] ",
- __FILE__,VErase2,group);
+ "verase [-noupdate|-update] [name1] ... [name n]"
+ "\n\t\t: Erases selected or named objects."
+ "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
+ __FILE__, VErase, group);
+
+ theCommands.Add("vremove",
+ "vremove [-noupdate|-update] [-context] [-all] [name1] ... [name n]"
+ "or vremove [-context] -all to remove all objects"
+ "\n\t\t: Removes selected or named objects."
+ "\n\t\t If -context is in arguments, the objects are not deleted"
+ "\n\t\t from the map of objects and names."
+ "\n\t\t: Option -noupdate suppresses viewer redraw call.",
+ __FILE__, VRemove, group);
theCommands.Add("vdonly",
- "vdonly : vdonly2 [name1] ... [name n]",
+ "vdonly [-noupdate|-update] [name1] ... [name n]"
+ "\n\t\t: Displays only selected or named objects",
__FILE__,VDonly2,group);
theCommands.Add("vdisplayall",
- "vdisplayall : vdisplayall",
+ "Displays all erased interactive objects (see vdir and vstate)",
__FILE__,VDisplayAll,group);
theCommands.Add("veraseall",
- "veraseall : veraseall ",
- __FILE__,VEraseAll,group);
+ "Erases all objects displayed in the viewer",
+ __FILE__, VErase, group);
theCommands.Add("verasetype",
- "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)",
+ "verasetype <Type>"
+ "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
__FILE__,VEraseType,group);
theCommands.Add("vdisplaytype",
__FILE__,VDispMode,group);
theCommands.Add("vsetdispmode",
- "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ",
+ "vsetdispmode [name] mode(1,2,..)"
+ "\n\t\t: Sets display mode for all, selected or named objects.",
__FILE__,VDispMode,group);
theCommands.Add("vunsetdispmode",
- "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects",
+ "vunsetdispmode [name]"
+ "\n\t\t: Unsets custom display mode for selected or named objects.",
__FILE__,VDispMode,group);
theCommands.Add("vdir",
- "vdir",
- __FILE__,VDebug,group);
+ "Lists all objects displayed in 3D viewer",
+ __FILE__,VDir,group);
theCommands.Add("vdump",
- "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file",
+ #ifdef HAVE_FREEIMAGE
+ "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
+ "\n\t\t: [width Width=0 height Height=0]"
+ "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
+ #else
+ "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
+ "\n\t\t: [width Width=0 height Height=0]"
+ "\n\t\t: Dumps content of the active view into PPM image file",
+ #endif
__FILE__,VDump,group);
theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
__FILE__,VSubInt,group);
theCommands.Add("vsetcolor",
- "vsetcolor : vsetcolor [name of shape] ColorName",
+ "vsetcolor [name] ColorName"
+ "\n\t\t: Sets color for all, selected or named objects.",
__FILE__,VColor2,group);
theCommands.Add("vunsetcolor",
- "vunsetcolor : vunsetcolor [name of shape] ",
+ "vunsetcolor [name]"
+ "\n\t\t: Resets color for all, selected or named objects.",
__FILE__,VColor2,group);
theCommands.Add("vsettransparency",
- "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)",
+ "vsettransparency [name] Coefficient"
+ "\n\t\t: Sets transparency for all, selected or named objects."
+ "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
__FILE__,VTransparency,group);
theCommands.Add("vunsettransparency",
- "vunsettransparency : vtransparency [name of shape]",
+ "vunsettransparency [name]"
+ "\n\t\t: Resets transparency for all, selected or named objects.",
__FILE__,VTransparency,group);
theCommands.Add("vsetmaterial",
"vunsetwidth : vwidth [name of shape]",
__FILE__,VWidth,group);
+ theCommands.Add("vsetinteriorstyle",
+ "vsetinteriorstyle : vsetinteriorstyle [name of shape] style",
+ __FILE__,VInteriorStyle,group);
+
theCommands.Add("vardis",
"vardis : display activeareas",
__FILE__,VDispAreas,group);
"vardisp : erase active entities",
__FILE__,VClearSensi,group);
+ theCommands.Add("vselprecision",
+ "vselprecision : vselprecision [precision_mode [tolerance_value]]",
+ __FILE__,VSelPrecision,group);
+
theCommands.Add("vperf",
"vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)",
__FILE__,VPerf,group);
"vunsetshading :vunsetshading name ",
__FILE__,VShading,group);
- theCommands.Add("vtexture",
- "'vtexture NameOfShape TextureFile' \n \
- or 'vtexture NameOfShape' if you want to disable texture mapping \n \
- or 'vtexture NameOfShape ?' to list available textures\n \
- or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ",
- __FILE__,VTexture,group);
+ theCommands.Add ("vtexture",
+ "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
+ " [-scale u v] [-scale off]\n"
+ " [-origin u v] [-origin off]\n"
+ " [-repeat u v] [-repeat off]\n"
+ " [-modulate {on | off}]"
+ " [-default]'\n"
+ " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
+ " specifying one of the predefined textures.\n"
+ " The options are: \n"
+ " -scale u v : enable texture scaling and set scale factors\n"
+ " -scale off : disable texture scaling\n"
+ " -origin u v : enable texture origin positioning and set the origin\n"
+ " -origin off : disable texture origin positioning\n"
+ " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
+ " -repeat off : disable texture repeat\n"
+ " -modulate {on | off} : enable or disable texture modulation\n"
+ " -default : sets texture mapping default parameters\n"
+ "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
+ "or 'vtexture NameOfShape ?' to list available textures\n",
+ __FILE__, VTexture, group);
theCommands.Add("vtexscale",
"'vtexscale NameOfShape ScaleU ScaleV' \n \
"vunsetActivatedModes: vunsetam ",
__FILE__,VActivatedMode,group);
- theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ",
+ theCommands.Add("vstate",
+ "vstate [name1] ... [nameN]"
+ "\n\t\t: Reports show/hidden state for selected or named objects",
__FILE__,VState,group);
theCommands.Add("vpickshapes",
theCommands.Add("vr", "vr : reading of the shape",
__FILE__,vr, group);
- theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group);
- theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group);
-
}
//=====================================================================
// argv[4] - Standard_Real Angle
// argv[5] - Standard_Integer Reverse
-// sprintf(prefix, argv[1]);
+// Sprintf(prefix, argv[1]);
Standard_Real anAngle = 0;
Standard_Boolean Rev = Standard_False;
Standard_Integer rev = 0;
di << "TEST : Plane is NULL" << "\n";
return 1;
}
- anAngle = atof(argv[4]);
+ anAngle = Draw::Atof(argv[4]);
anAngle = 2*M_PI * anAngle / 360.0;
gp_Pln aPln;
Handle( Geom_Surface )aSurf;
Standard_Real Offset;
gp_Dir aDir;
if(argc > 4) { // == 5
- rev = atoi(argv[5]);
+ rev = Draw::Atoi(argv[5]);
Rev = (rev)? Standard_True : Standard_False;
}
return 0;
}
+//==============================================================================
+//function : splitParameter
+//purpose : Split parameter string to parameter name and parameter value
+//==============================================================================
+Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
+ TCollection_AsciiString& theName,
+ TCollection_AsciiString& theValue)
+{
+ Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
+
+ if (aParamNameEnd == 0)
+ {
+ return Standard_False;
+ }
+
+ TCollection_AsciiString aString (theString);
+ if (aParamNameEnd != 0)
+ {
+ theValue = aString.Split (aParamNameEnd);
+ aString.Split (aString.Length() - 1);
+ theName = aString;
+ }
+ return Standard_True;
+}
//============================================================================
// MyCommands
void ViewerTest::Factory(Draw_Interpretor& theDI)
{
// definition of Viewer Command
- ViewerTest::Commands(theDI);
- ViewerTest::AviCommands(theDI);
- Viewer2dTest::Commands(theDI);
+ ViewerTest::Commands(theDI);
+ ViewerTest::AviCommands(theDI);
+
#ifdef DEB
theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
#endif