Salome HOME
Initial implementation of the feature
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.cpp
index 0af846aa2d92940fc32b0c535c5740e34e841e5c..1f0d054f491c861650d04b4d833b68c8a6739529 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "SHAPERGUI_SalomeViewer.h"
 #include <SUIT_ViewManager.h>
 
 #include <QtxActionToolMgr.h>
+#include <SALOME_AISShape.hxx>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 
 #include <QMouseEvent>
 #include <QContextMenuEvent>
 
-//#define SALOME_PATCH_FOR_CTRL_WHEEL
+#define SALOME_PATCH_FOR_CTRL_WHEEL
 
 SHAPERGUI_SalomeView::SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer)
 : ModuleBase_IViewWindow(), myCurrentView(0)
@@ -119,7 +119,7 @@ Handle(V3d_View) SHAPERGUI_SalomeViewer::activeView() const
 //**********************************************
 QWidget* SHAPERGUI_SalomeViewer::activeViewPort() const
 {
-  QWidget* aViewPort;
+  QWidget* aViewPort = 0;
   if (mySelector) {
     OCCViewer_Viewer* aViewer = mySelector->viewer();
     SUIT_ViewManager* aMgr = aViewer->getViewManager();
@@ -374,8 +374,20 @@ void SHAPERGUI_SalomeViewer::fitAll()
 //**********************************************
 void SHAPERGUI_SalomeViewer::eraseAll()
 {
-  SOCC_Viewer* aViewer = dynamic_cast<SOCC_Viewer*>(myView->viewer());
-  aViewer->EraseAll(0);
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+  AIS_ListOfInteractive aList;
+  aContext->DisplayedObjects(aList);
+  AIS_ListIteratorOfListOfInteractive aLIt;
+  Handle(AIS_InteractiveObject) anAISIO;
+  for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
+    anAISIO = aLIt.Value();
+    Handle(Standard_Type) aType = anAISIO->DynamicType();
+    if (anAISIO->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
+      aContext->Erase(anAISIO, false);
+    }
+  }
 }
 
 //**********************************************
@@ -495,6 +507,89 @@ 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::setColorScaleTextColor(const QColor& theColor)
+{
+  if (mySelector) {
+    Quantity_Color aColor(theColor.redF(), theColor.greenF(), theColor.blueF(), Quantity_TOC_RGB);
+    mySelector->viewer()->getColorScale()->SetColor(aColor);
+  }
+}
+
+void SHAPERGUI_SalomeViewer::setColorScaleTitle(const QString& theText)
+{
+  if (mySelector) {
+    mySelector->viewer()->getColorScale()->SetTitle(theText.toStdString().c_str());
+  }
+}
+
+void SHAPERGUI_SalomeViewer::setFitter(OCCViewer_Fitter* theFitter)
+{
+  if (mySelector)
+    mySelector->viewer()->setFitter(theFitter);
+}
+
+OCCViewer_Fitter* SHAPERGUI_SalomeViewer::fitter() const
+{
+  if (mySelector)
+    return mySelector->viewer()->fitter();
+  return 0;
+}
+
+
 //void SHAPERGUI_SalomeViewer::Zfitall()
 //{
 //  if (!mySelector || !mySelector->viewer())