From: jfa Date: Tue, 18 Apr 2006 11:08:07 +0000 (+0000) Subject: PAL12120: New methods for presentations parameters management from python. X-Git-Tag: T3_2_0b1_pre1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8eee1677b1d1b51031e00d0d98f7a4d9d8a2eb5a;p=modules%2Fvisu.git PAL12120: New methods for presentations parameters management from python. --- diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index a769fa05..722b086c 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -1901,6 +1901,72 @@ module VISU { * \param theName The name of the view parameters which will be restored. */ boolean RestoreViewParams(in string theName); + + + /*! Get representation type of the given presentation in this view. + * \param thePrs Object to get a representation type of. + * \return PresentationType Representation type of object in this view. + */ + PresentationType GetPresentationType(in ScalarMap thePrs); + + /*! Set representation type of the given presentation in this view. + * \param thePrs Object to set a representation type of. + * \param thePrsType Representation type to be set to the given object. + * \return Empty string in case of success, error description in case of failure. + */ + string SetPresentationType(in ScalarMap thePrs, in PresentationType thePrsType); + + /*! Get shrink state of the given presentation in this view. + * \param thePrs Object to get a shrink state of. + * \return TRUE if \a thePrs is shrinked in this view, FALSE overwise. + */ + boolean IsShrinked(in ScalarMap thePrs); + + /*! Make the given presentation shrinked or not shrinked in this view. + * \param thePrs Object to change a shrink state of. + * \param isShrinked Pass TRUE to make \a thePrs shrinked, FALSE overwise. + * \return Empty string in case of success, error description in case of failure. + */ + string SetShrinked(in ScalarMap thePrs, in boolean isShrinked); + + /*! Get shading state of the given presentation in this view. + * \param thePrs Object to get a shading state of. + * \return TRUE if \a thePrs is shaded in this view, FALSE overwise. + */ + boolean IsShaded(in ScalarMap thePrs); + + /*! Make the given presentation shaded or not shaded in this view. + * \param thePrs Object to set a shading state of. + * \param isShaded Pass TRUE to make \a thePrs shaded, FALSE overwise. + * \return Empty string in case of success, error description in case of failure. + */ + string SetShaded(in ScalarMap thePrs, in boolean isShaded); + + /*! Get opacity of the given presentation in this view. + * \param thePrs Object to get an opacity of. + * \return Opacity value in range [0, 1], 0 - transparent, 1 - opaque. + */ + double GetOpacity(in ScalarMap thePrs); + + /*! Set opacity of the given presentation in this view. + * \param thePrs Object to set an opacity of. + * \param theOpacity Opacity value [0, 1]. 0 - transparent, 1 - opaque. + * \return Empty string in case of success, error description in case of failure. + */ + string SetOpacity(in ScalarMap thePrs, in double theOpacity); + + /*! Get line width of the given presentation in this view. + * \param thePrs Object to get a line width of. + * \return Line width of \a thePrs in this view. + */ + double GetLineWidth(in ScalarMap thePrs); + + /*! Set line width of the given presentation in this view. + * \param thePrs Object to set a line width of. + * \param theLineWidth Line width value. Recommended values are in range [1, 10]. + * \return Empty string in case of success, error description in case of failure. + */ + string SetLineWidth(in ScalarMap thePrs, in double theLineWidth); }; //------------------------------------------------------- diff --git a/src/VISU_I/VISU_View_i.cc b/src/VISU_I/VISU_View_i.cc index 06a3893d..ae5bf27c 100644 --- a/src/VISU_I/VISU_View_i.cc +++ b/src/VISU_I/VISU_View_i.cc @@ -29,11 +29,13 @@ #include "VISU_Gen_i.hh" #include "VISU_Prs3d_i.hh" #include "VISU_Table_i.hh" +#include "VISU_ScalarMap_i.hh" #include "VISU_ViewManager_i.hh" #include "VisuGUI_TableDlg.h" #include "VISU_Actor.h" +#include "VISU_ScalarMapAct.h" #include "SALOME_Event.hxx" @@ -2160,4 +2162,316 @@ namespace VISU { ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale)); } } + + //================================================ + // Certain presentation view parameters management + //================================================ + class TPrsManageEvent: public SALOME_Event + { + protected: + View3D_i* myView3D; + ScalarMap_ptr myPrs; + string myError; + + TPrsManageEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + myView3D(theView3D), + myPrs(ScalarMap::_duplicate(thePrs)), + myError("Unknown error occured") + {} + VISU_Actor* GetMyActor() + { + SUIT_ViewWindow* aVW = myView3D->GetViewWindow(); + SVTK_ViewWindow* vw = dynamic_cast(aVW); + if (!aVW) { + myError = "Corrupted view window"; + } else { + ScalarMap_i* aPrs = dynamic_cast(VISU::GetServant(myPrs).in()); + if (!aPrs) { + myError = "Corrupted presentation"; + } else { + VISU_Actor* anActor = VISU::GetActor(aPrs, vw); + if (!anActor) { + myError = "No actor found. Display the presentation at first."; + } else { + myError = ""; + return anActor; + } + } + } + return NULL; + } + }; + + // Get + class TGetPrsTypeEvent: public TPrsManageEvent { + public: + typedef VISU::PresentationType TResult; + TResult myResult; + TGetPrsTypeEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + TPrsManageEvent(theView3D, thePrs), myResult(VISU::SHRINK) {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) + myResult = (VISU::PresentationType)anActor->GetRepresentation(); + } + }; + + class TGetShrinkedEvent: public TPrsManageEvent { + public: + typedef bool TResult; + TResult myResult; + TGetShrinkedEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + TPrsManageEvent(theView3D, thePrs), myResult(false) {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) { + if (anActor->IsShrunkable()) + myResult = anActor->IsShrunk(); + else + myResult = false; + } + } + }; + + class TGetShadedEvent: public TPrsManageEvent { + public: + typedef bool TResult; + TResult myResult; + TGetShadedEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + TPrsManageEvent(theView3D, thePrs), myResult(false) {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) + if (VISU_ScalarMapAct* aScalarMapActor = dynamic_cast(anActor)) + myResult = aScalarMapActor->IsShading(); + } + }; + + class TGetOpacityEvent: public TPrsManageEvent { + public: + typedef double TResult; + TResult myResult; + TGetOpacityEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + TPrsManageEvent(theView3D, thePrs), myResult(-1.0) {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) { + vtkFloatingPointType oldvalue = anActor->GetOpacity(); + myResult = (double)oldvalue; + } + } + }; + + class TGetLineWidthEvent: public TPrsManageEvent { + public: + typedef double TResult; + TResult myResult; + TGetLineWidthEvent(View3D_i* theView3D, ScalarMap_ptr thePrs): + TPrsManageEvent(theView3D, thePrs), myResult(-1.0) {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) { + vtkFloatingPointType oldvalue = anActor->GetLineWidth(); + myResult = (double)oldvalue; + } + } + }; + + // Set + class TSetPrsTypeEvent: public TPrsManageEvent { + private: + PresentationType myPrsType; + public: + typedef string TResult; + TResult myResult; + TSetPrsTypeEvent(View3D_i* theView3D, ScalarMap_ptr thePrs, PresentationType thePrsType): + TPrsManageEvent(theView3D, thePrs), myPrsType(thePrsType), + myResult("Unknown error occured") + {} + virtual void Execute() { + switch (myPrsType) { + case VISU::INSIDEFRAME: + { + VISU::VISUType aType = myPrs->GetType(); + if (aType != VISU::TSCALARMAP && + aType != VISU::TDEFORMEDSHAPE && + aType != VISU::TSCALARMAPONDEFORMEDSHAPE) { + myResult = "Insideframe representation is not available for this type of presentations."; + return; + } + } + break; + case VISU::SURFACEFRAME: + myResult = "Surfaceframe representation is available only for mesh presentation."; + return; + case VISU::SHRINK: + myResult = "Use SetShrinked() method to shrink/unshrink presentation."; + return; + default: + break; + } + if (VISU_Actor* anActor = GetMyActor()) { + anActor->SetRepresentation((int)myPrsType); + SVTK_ViewWindow* vw = dynamic_cast(myView3D->GetViewWindow()); + vw->Repaint(); + myResult = ""; + } else { + myResult = myError; + } + } + }; + + class TSetShrinkedEvent: public TPrsManageEvent { + private: + bool myIsOn; + public: + typedef string TResult; + TResult myResult; + TSetShrinkedEvent(View3D_i* theView3D, ScalarMap_ptr thePrs, bool isOn): + TPrsManageEvent(theView3D, thePrs), myIsOn(isOn), + myResult("Unknown error occured") + {} + virtual void Execute() { + VISU::VISUType aType = myPrs->GetType(); + if (aType == VISU::TVECTORS || aType == VISU::TSTREAMLINES) { + myResult = "Shrinked representation is not available for this type of presentations."; + } else { + if (VISU_Actor* anActor = GetMyActor()) { + if (anActor->IsShrunkable()) { + if (myIsOn) anActor->SetShrink(); + else anActor->UnShrink(); + SVTK_ViewWindow* vw = dynamic_cast(myView3D->GetViewWindow()); + vw->Repaint(); + myResult = ""; + } else { + myResult = "This presentation is not shrunkable."; + } + } else { + myResult = myError; + } + } + } + }; + + class TSetShadedEvent: public TPrsManageEvent { + private: + bool myIsOn; + public: + typedef string TResult; + TResult myResult; + TSetShadedEvent(View3D_i* theView3D, ScalarMap_ptr thePrs, bool isOn): + TPrsManageEvent(theView3D, thePrs), myIsOn(isOn), + myResult("Unknown error occured") + {} + virtual void Execute() { + if (VISU_Actor* anActor = GetMyActor()) { + if (VISU_ScalarMapAct* aScalarMapActor = + dynamic_cast(anActor)) { + aScalarMapActor->SetShading(myIsOn); + SVTK_ViewWindow* vw = dynamic_cast(myView3D->GetViewWindow()); + vw->Repaint(); + myResult = ""; + } else { + myResult = "Corrupted actor"; + } + } else { + myResult = myError; + } + } + }; + + class TSetOpacityEvent: public TPrsManageEvent { + private: + double myOpacity; + public: + typedef string TResult; + TResult myResult; + TSetOpacityEvent(View3D_i* theView3D, ScalarMap_ptr thePrs, double theOpacity): + TPrsManageEvent(theView3D, thePrs), myOpacity(theOpacity), + myResult("Unknown error occured") + {} + virtual void Execute() { + VISU::VISUType aType = myPrs->GetType(); + if (aType == VISU::TVECTORS || aType == VISU::TSTREAMLINES) { + myResult = "Opacity is meaningless for this type of presentations."; + return; + } + if (VISU_Actor* anActor = GetMyActor()) { + anActor->SetOpacity((vtkFloatingPointType)myOpacity); + SVTK_ViewWindow* vw = dynamic_cast(myView3D->GetViewWindow()); + vw->Repaint(); + myResult = ""; + } else { + myResult = myError; + } + } + }; + + class TSetLineWidthEvent: public TPrsManageEvent { + private: + double myLineWidth; + public: + typedef string TResult; + TResult myResult; + TSetLineWidthEvent(View3D_i* theView3D, ScalarMap_ptr thePrs, double theLineWidth): + TPrsManageEvent(theView3D, thePrs), myLineWidth(theLineWidth), + myResult("Unknown error occured") + {} + virtual void Execute() { + if (myPrs->GetType() == VISU::TVECTORS) { + myResult = "Line Width is meaningless for Vectors presentation."; + return; + } + if (VISU_Actor* anActor = GetMyActor()) { + anActor->SetLineWidth((vtkFloatingPointType)myLineWidth); + SVTK_ViewWindow* vw = dynamic_cast(myView3D->GetViewWindow()); + vw->Repaint(); + myResult = ""; + } else { + myResult = myError; + } + } + }; + + PresentationType View3D_i::GetPresentationType(ScalarMap_ptr thePrs) + { + return ProcessEvent(new TGetPrsTypeEvent(this,thePrs)); + } + CORBA::Boolean View3D_i::IsShrinked(ScalarMap_ptr thePrs) + { + return ProcessEvent(new TGetShrinkedEvent(this,thePrs)); + } + CORBA::Boolean View3D_i::IsShaded(ScalarMap_ptr thePrs) + { + return ProcessEvent(new TGetShadedEvent(this,thePrs)); + } + CORBA::Double View3D_i::GetOpacity(ScalarMap_ptr thePrs) + { + return ProcessEvent(new TGetOpacityEvent(this,thePrs)); + } + CORBA::Double View3D_i::GetLineWidth(ScalarMap_ptr thePrs) + { + return ProcessEvent(new TGetLineWidthEvent(this,thePrs)); + } + + char* View3D_i::SetPresentationType(ScalarMap_ptr thePrs, PresentationType thePrsType) + { + string aRet = ProcessEvent(new TSetPrsTypeEvent(this,thePrs,thePrsType)); + return CORBA::string_dup(aRet.c_str()); + } + char* View3D_i::SetShrinked(ScalarMap_ptr thePrs, CORBA::Boolean isShrinked) + { + string aRet = ProcessEvent(new TSetShrinkedEvent(this,thePrs,isShrinked)); + return CORBA::string_dup(aRet.c_str()); + } + char* View3D_i::SetShaded(ScalarMap_ptr thePrs, CORBA::Boolean isShaded) + { + string aRet = ProcessEvent(new TSetShadedEvent(this,thePrs,isShaded)); + return CORBA::string_dup(aRet.c_str()); + } + char* View3D_i::SetOpacity(ScalarMap_ptr thePrs, CORBA::Double theOpacity) + { + string aRet = ProcessEvent(new TSetOpacityEvent(this,thePrs,theOpacity)); + return CORBA::string_dup(aRet.c_str()); + } + char* View3D_i::SetLineWidth(ScalarMap_ptr thePrs, CORBA::Double theLineWidth) + { + string aRet = ProcessEvent(new TSetLineWidthEvent(this,thePrs,theLineWidth)); + return CORBA::string_dup(aRet.c_str()); + } } diff --git a/src/VISU_I/VISU_View_i.hh b/src/VISU_I/VISU_View_i.hh index 76b44da5..72ebb313 100644 --- a/src/VISU_I/VISU_View_i.hh +++ b/src/VISU_I/VISU_View_i.hh @@ -292,6 +292,19 @@ namespace VISU virtual void Close(); + // Certain presentation view parameters management + virtual PresentationType GetPresentationType(ScalarMap_ptr thePrs); + virtual CORBA::Boolean IsShrinked (ScalarMap_ptr thePrs); + virtual CORBA::Boolean IsShaded (ScalarMap_ptr thePrs); + virtual CORBA::Double GetOpacity (ScalarMap_ptr thePrs); + virtual CORBA::Double GetLineWidth (ScalarMap_ptr thePrs); + + virtual char* SetPresentationType(ScalarMap_ptr thePrs, PresentationType thePrsType); + virtual char* SetShrinked (ScalarMap_ptr thePrs, CORBA::Boolean isShrinked); + virtual char* SetShaded (ScalarMap_ptr thePrs, CORBA::Boolean isShaded); + virtual char* SetOpacity (ScalarMap_ptr thePrs, CORBA::Double theOpacity); + virtual char* SetLineWidth (ScalarMap_ptr thePrs, CORBA::Double theLineWidth); + protected: static int myNbViewParams; diff --git a/src/VISU_SWIG/Makefile.in b/src/VISU_SWIG/Makefile.in index 31dc3141..753d607f 100644 --- a/src/VISU_SWIG/Makefile.in +++ b/src/VISU_SWIG/Makefile.in @@ -45,7 +45,8 @@ EXPORT_PYSCRIPTS = libVISU_Swig.py batchmode_visu.py batchmode_visu_table.py bat visu_med.py visu_view3d.py visu.py visu_gui.py visu_prs_example.py \ visu_table.py visu_big_table.py visu_view.py visu_delete.py \ visu_swig_test.py test_events.py batch_test_events.py visu_split_views.py \ - VISU_Example_01.py VISU_Example_02.py VISU_Example_03.py VISU_Example_04.py VISU_Example_05.py VISU_Example_06.py + VISU_Example_01.py VISU_Example_02.py VISU_Example_03.py VISU_Example_04.py \ + VISU_Example_05.py VISU_Example_06.py VISU_Example_07.py EXPORT_SHAREDPYSCRIPTS = VISU_shared_modules.py LIB_CLIENT_IDL = diff --git a/src/VISU_SWIG/VISU_Example_07.py b/src/VISU_SWIG/VISU_Example_07.py new file mode 100644 index 00000000..4908bc27 --- /dev/null +++ b/src/VISU_SWIG/VISU_Example_07.py @@ -0,0 +1,142 @@ +# Manage view parameters of presentations: +# Representation Mode, Shrink, Shading, Opacity, Line Width + +import salome + +import VISU +import visu_gui + +import os +import time + +datadir = os.getenv("DATA_DIR") + "/MedFiles/" + +myVisu = visu_gui.myVisu +myVisu.SetCurrentStudy(salome.myStudy) +myViewManager = myVisu.GetViewManager() +myView = myViewManager.Create3DView() + +sleep_delay = 1 + +def AfterSet(error_string, method_name, old_value, new_value): + print method_name, "(): old_value = ", old_value, "new_value = ", new_value + if error_string == "": + time.sleep(sleep_delay) + else: + print method_name, "() error = ", error_string + pass + pass + +def ChangeRepresentation(scalarmap,repres,shrink,shading,opacity,linew): + if scalarmap is None : print "Error" + else : print "OK" + + myView.DisplayOnly(scalarmap) + myView.FitAll() + + time.sleep(sleep_delay) + + # enum PresentationType{ POINT, WIREFRAME, SHADED, INSIDEFRAME, SURFACEFRAME, SHRINK } + old_prs_type = myView.GetPresentationType(scalarmap) + if old_prs_type != repres: + err_str = myView.SetPresentationType(scalarmap, repres) + AfterSet(err_str, "SetPresentationType", old_prs_type, repres) + pass + + old_is_shrinked = myView.IsShrinked(scalarmap) + if old_is_shrinked != shrink: + err_str = myView.SetShrinked(scalarmap, shrink) # 1 - shrinked, 0 - not shrinked + AfterSet(err_str, "SetShrinked", old_is_shrinked, shrink) + pass + + old_is_shaded = myView.IsShaded(scalarmap) + if old_is_shaded != shading: + err_str = myView.SetShaded(scalarmap, shading) # 1 - shaded, 0 - not shaded + AfterSet(err_str, "SetShaded", old_is_shaded, shading) + pass + + old_opacity = myView.GetOpacity(scalarmap) + if old_opacity != opacity: + err_str = myView.SetOpacity(scalarmap, opacity) # double value [0, 1] + AfterSet(err_str, "SetOpacity", old_opacity, opacity) + pass + + old_linew = myView.GetLineWidth(scalarmap) + if old_linew != linew: + err_str = myView.SetLineWidth(scalarmap, linew) # double value, recommended round [1, 10] + AfterSet(err_str, "SetLineWidth", old_linew, linew) + pass + + print "" + pass + +# ResOK_0000.med + +print 'Import "ResOK_0000.med"...............', +medFile = datadir + "ResOK_0000.med" +myMeshName = 'dom' +myFieldName = 'vitesse' + +myResult = myVisu.ImportFile(medFile) +if myResult is None : print "Error" +else : print "OK" + +print "Creating Scalar Map.......", +scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.INSIDEFRAME, 1, 0, 0.3, 5) + +print "Creating Stream Lines.......", +scmap = myVisu.StreamLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3) + +print "Creating Vectors..........", +scmap = myVisu.VectorsOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.7, 2) + +print "Creating Iso Surfaces.....", +scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.SHADED, 1, 0, 0.4, 8) + +print "Creating Cut Planes.......", +scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.POINT, 0, 0, 0.6, 4) + +# fra.med + +print 'Import "fra.med"...............', +medFile = datadir + "fra.med" +myMeshName = 'LE VOLUME' +myFieldName = 'VITESSE' + +myResult = myVisu.ImportFile(medFile) +if myResult is None : print "Error" +else : print "OK" + +print "Creating Scalar Map.......", +scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3) + +print "Creating Iso Surfaces.....", +scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3) + +print "Creating Cut Planes.......", +scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3) + +print "Creating Scalar Map On Deformed Shape.......", +scmap = myVisu.ScalarMapOnDeformedShapeOnField(myResult,myMeshName,VISU.NODE,myFieldName,1); +ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3) + +print "Creating Deformed Shape.......", +scmap = myVisu.DeformedShapeOnField(myResult,myMeshName,VISU.NODE,myFieldName,1) +scmap.ShowColored(1) +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3) + +print "Creating Cut Lines.......", +scmap = myVisu.CutLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1) +ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3) + +print "Creating Plot 3D.......", +scmap = myVisu.Plot3DOnField(myResult,myMeshName,VISU.NODE,myFieldName,1) +ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)