From 68a9e952c2238820a515db5f88960cb8639c6f83 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 27 Jun 2019 16:11:03 +0300 Subject: [PATCH] Provide color scale for SALOME SHAPER module --- src/ModuleBase/ModuleBase_IViewer.h | 35 +++++++++++++ src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp | 63 ++++++++++++++++++++++++ src/SHAPERGUI/SHAPERGUI_SalomeViewer.h | 36 ++++++++++++++ src/XGUI/XGUI_ViewerProxy.cpp | 17 +++---- 4 files changed, 142 insertions(+), 9 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index f079bd4d9..e264f5cb4 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -142,6 +142,41 @@ Q_OBJECT return myIs2dMode; } + // Methods for color scale management + + //! Returns True if ColorScale is visible + virtual bool isColorScaleVisible() const = 0; + + //! Show/Hide ColorScale object + virtual void setColorScaleShown(bool on) = 0; + + //! Set position of color scale + // \param theX is X position relative to current view width + // \param theY is Y position relative to current view heigth + virtual void setColorScalePosition(double theX, double theY) = 0; + + //! Set size of color scale + // \param theW is width relative to current view width + // \param theh is height relative to current view heigth + virtual void setColorScaleSize(double theW, double theH) = 0; + + //! Set range of color scale + // \param theMin is a minimal value + // \param theMax is a maximal value + virtual void setColorScaleRange(double theMin, double theMax) = 0; + + //! Set number of intervals of color scale + // \param theNb is number of intervals + virtual void setColorScaleIntervals(int theNb) = 0; + + //! Set text heigth of color scale + // \param theH is number of intervals + virtual void setColorScaleTextHeigth(int theH) = 0; + + //! Set title of color scale + // \param theText is a title + virtual void setColorScaleTitle(const QString& theText) = 0; + static Handle(Prs3d_Drawer) DefaultHighlightDrawer; signals: diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp index 467f6a9b6..aa417a462 100644 --- a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp @@ -507,6 +507,69 @@ void SHAPERGUI_SalomeViewer::activateViewer(bool toActivate) } } +bool SHAPERGUI_SalomeViewer::isColorScaleVisible() const +{ + if (mySelector) { + return mySelector->viewer()->isColorScaleVisible(); + } + return false; +} + +void SHAPERGUI_SalomeViewer::setColorScaleShown(bool on) +{ + if (mySelector) { + mySelector->viewer()->setColorScaleShown(on); + } +} + +void SHAPERGUI_SalomeViewer::setColorScalePosition(double theX, double theY) +{ + if (mySelector) { + QWidget* aWindow = activeViewPort(); + mySelector->viewer()->getColorScale()->SetPosition(aWindow->width() * theX, + aWindow->height() * theY); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleSize(double theW, double theH) +{ + if (mySelector) { + QWidget* aWindow = activeViewPort(); + mySelector->viewer()->getColorScale()->SetSize(aWindow->width() * theW, + aWindow->height() * theH); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleRange(double theMin, double theMax) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetRange(theMin, theMax); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleIntervals(int theNb) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetNumberOfIntervals(theNb); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleTextHeigth(int theH) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetTextHeight(theH); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleTitle(const QString& theText) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetTitle(theText.toStdString().c_str()); + } +} + + + //void SHAPERGUI_SalomeViewer::Zfitall() //{ // if (!mySelector || !mySelector->viewer()) diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h index 6e9129bc1..2b6b88792 100644 --- a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h @@ -168,6 +168,42 @@ Q_OBJECT /// \param toActivate - activation flag void activateViewer(bool toActivate); + + // Methods for color scale management + + //! Returns True if ColorScale is visible + virtual bool isColorScaleVisible() const; + + //! Show/Hide ColorScale object + virtual void setColorScaleShown(bool on); + + //! Set position of color scale + // \param theX is X position relative to current view width + // \param theY is Y position relative to current view heigth + virtual void setColorScalePosition(double theX, double theY); + + //! Set size of color scale + // \param theW is width relative to current view width + // \param theh is height relative to current view heigth + virtual void setColorScaleSize(double theW, double theH); + + //! Set range of color scale + // \param theMin is a minimal value + // \param theMax is a maximal value + virtual void setColorScaleRange(double theMin, double theMax); + + //! Set number of intervals of color scale + // \param theNb is number of intervals + virtual void setColorScaleIntervals(int theNb); + + //! Set text heigth of color scale + // \param theH is number of intervals + virtual void setColorScaleTextHeigth(int theH); + + //! Set title of color scale + // \param theText is a title + virtual void setColorScaleTitle(const QString& theText); + // Fit all along Z (perpendicular to display) //virtual void Zfitall(); diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 753a07d98..ea1b76807 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -580,10 +580,10 @@ void XGUI_ViewerProxy::setColorScaleShown(bool on) void XGUI_ViewerProxy::setColorScalePosition(double theX, double theY) { - QWidget* aWindow = activeViewPort(); #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScalePosition(theX, theY); #else + QWidget* aWindow = activeViewPort(); Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetPosition(aWindow->width() * theX, aWindow->height() * theY); #endif @@ -591,10 +591,10 @@ void XGUI_ViewerProxy::setColorScalePosition(double theX, double theY) void XGUI_ViewerProxy::setColorScaleSize(double theW, double theH) { - QWidget* aWindow = activeViewPort(); #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScaleSize(theW, theH); #else + QWidget* aWindow = activeViewPort(); Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetSize(aWindow->width() * theW, aWindow->height() * theH); #endif @@ -603,7 +603,7 @@ void XGUI_ViewerProxy::setColorScaleSize(double theW, double theH) void XGUI_ViewerProxy::setColorScaleRange(double theMin, double theMax) { #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScaleRange(theMin, theMax); #else Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetRange(theMin, theMax); @@ -613,7 +613,7 @@ void XGUI_ViewerProxy::setColorScaleRange(double theMin, double theMax) void XGUI_ViewerProxy::setColorScaleIntervals(int theNb) { #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScaleIntervals(theNb); #else Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetNumberOfIntervals(theNb); @@ -623,7 +623,7 @@ void XGUI_ViewerProxy::setColorScaleIntervals(int theNb) void XGUI_ViewerProxy::setColorScaleTextHeigth(int theH) { #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScaleTextHeigth(theH); #else Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetTextHeight(theH); @@ -633,7 +633,7 @@ void XGUI_ViewerProxy::setColorScaleTextHeigth(int theH) void XGUI_ViewerProxy::setColorScaleTitle(const QString& theText) { #ifdef HAVE_SALOME - myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); + myWorkshop->salomeConnector()->viewer()->setColorScaleTitle(theText); #else Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); aColorScale->SetTitle(theText.toStdString().c_str()); @@ -648,7 +648,6 @@ void XGUI_ViewerProxy::setupColorScale() setColorScaleSize(0.2, 0.5); setColorScaleTextHeigth(14); setColorScaleIntervals(20); - Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); } -- 2.39.2