Salome HOME
Update copyrights
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.cpp
index 27140f32039077dac42646f8d0c6bdb37bd65e46..a08b1572bd5d343b85e313cd1fdb33c99c4cec64 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
@@ -12,9 +12,9 @@
 //
 // 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 "ParametersPlugin_WidgetParamsMgr.h"
@@ -175,7 +175,8 @@ void ParametersPlugin_TreeWidget::closeEditor(QWidget* theEditor,
 
 ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent,
   const Config_WidgetAPI* theData)
-  : ModuleBase_ModelDialogWidget(theParent, theData)
+  : ModuleBase_ModelDialogWidget(theParent, theData),
+  isUpplyBlocked(false)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
 
@@ -247,6 +248,20 @@ ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theP
   onSelectionChanged();
 }
 
+void ParametersPlugin_WidgetParamsMgr::setDialogButtons(QDialogButtonBox* theButtons)
+{
+  ModuleBase_ModelDialogWidget::setDialogButtons(theButtons);
+
+  QWidget* aBtnParentWgt = myOkCancelBtn->parentWidget();
+  QHBoxLayout* aBtnParentLayout = dynamic_cast<QHBoxLayout*>(aBtnParentWgt->layout());
+
+  QPushButton* aPreviewBtn = new QPushButton(tr("See preview"), aBtnParentWgt);
+  aBtnParentLayout->insertWidget(0, aPreviewBtn);
+  aBtnParentLayout->insertStretch(1, 1);
+  connect(aPreviewBtn, SIGNAL(clicked(bool)), SLOT(onShowPreview()));
+}
+
+
 QList<QWidget*> ParametersPlugin_WidgetParamsMgr::getControls() const
 {
   QList<QWidget*> aList;
@@ -282,6 +297,11 @@ bool ParametersPlugin_WidgetParamsMgr::storeValueCustom()
     }
     aId++;
   }
+  // #2813 : make the current feature the latest in the document
+  std::list<FeaturePtr> allFeatures = myFeature->document()->allFeatures();
+  if (!allFeatures.empty()) {
+    myFeature->document()->setCurrentFeature(*(allFeatures.rbegin()), true);
+  }
   return true;
 }
 
@@ -310,7 +330,7 @@ void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
   int aNbFeatures = aDoc->numInternalFeatures();
   for (int i = 0; i < aNbFeatures; i++) {
     aParamFeature = aDoc->internalFeature(i);
-    if (aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
+    if (aParamFeature && aParamFeature->getKind() == ParametersPlugin_Parameter::ID()) {
       myParametersList.append(aParamFeature);
     }
   }
@@ -782,3 +802,26 @@ bool ParametersPlugin_WidgetParamsMgr::isValid()
   return true;
 }
 
+void ParametersPlugin_WidgetParamsMgr::showEvent(QShowEvent* theEvent)
+{
+  ModuleBase_ModelDialogWidget::showEvent(theEvent);
+  SessionPtr aMgr = ModelAPI_Session::get();
+  isUpplyBlocked = aMgr->isAutoUpdateBlocked();
+  aMgr->blockAutoUpdate(true);
+  Events_Loop* aLoop = Events_Loop::loop();
+  aLoop->flush(aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE));
+}
+
+void ParametersPlugin_WidgetParamsMgr::hideEvent(QHideEvent* theEvent)
+{
+  ModuleBase_ModelDialogWidget::hideEvent(theEvent);
+  SessionPtr aMgr = ModelAPI_Session::get();
+  aMgr->blockAutoUpdate(isUpplyBlocked);
+}
+
+void ParametersPlugin_WidgetParamsMgr::onShowPreview()
+{
+  SessionPtr aMgr = ModelAPI_Session::get();
+  aMgr->blockAutoUpdate(false);
+  aMgr->blockAutoUpdate(true);
+}
\ No newline at end of file