Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_SelectorWidget.cpp
index f47911d8394f4e990f9d2c8dd73f38453de6fe7a..f6945234c70eaff528582abe1819314cc5688087 100644 (file)
@@ -6,6 +6,9 @@
 #include "ModuleBase_SelectorWidget.h"
 #include "ModuleBase_IWorkshop.h"
 
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeReference.h>
@@ -18,6 +21,7 @@
 #include <QToolButton>
 #include <QString>
 #include <QEvent>
+#include <QDockWidget>
 
 
 ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 
@@ -66,14 +70,17 @@ ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
 }
 
 //********************************************************************
-bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
+bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const
 {
   DataPtr aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
 
-  aRef->setFeature(mySelectedFeature);
-
+  FeaturePtr aFeature = aRef->value();
+  if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+    aRef->setValue(mySelectedFeature);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  }
   return true;
 }
 
@@ -81,23 +88,14 @@ bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
 bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
 {
   DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
+  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(myFeatureAttributeID);
 
+  bool isBlocked = this->blockSignals(true);
   mySelectedFeature = aRef->value();
   updateSelectionName(); 
-  return true;
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::canFocusTo(const std::string& theAttributeName)
-{
-  return false;
-}
 
-//********************************************************************
-void ModuleBase_SelectorWidget::focusTo()
-{
+  this->blockSignals(isBlocked);
+  return true;
 }
 
 //********************************************************************
@@ -122,10 +120,15 @@ void ModuleBase_SelectorWidget::onSelectionChanged()
       return;
 
     // TODO: Check that the selection corresponds to selection type
+    // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text
+    if (aFeature->getKind().compare("Sketch") != 0)
+      return;
+
     mySelectedFeature = aFeature;
     if (mySelectedFeature) {
       updateSelectionName();
       activateSelection(false);
+      raisePanel();
     } else {
       myTextLine->setText("");
     }
@@ -161,7 +164,7 @@ bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent)
 }
 
 //********************************************************************
-void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable)
+void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const
 {
   QWidget* aParent = myContainer->parentWidget();
   QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
@@ -183,4 +186,20 @@ void ModuleBase_SelectorWidget::activateSelection(bool toActivate)
     disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
 
   myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::raisePanel() const
+{
+  QWidget* aParent = myContainer->parentWidget();
+  QWidget* aLastPanel = 0;
+  while (!aParent->inherits("QDockWidget")) {
+    aLastPanel = aParent;
+    aParent = aParent->parentWidget();
+    if (!aParent) return;
+  }
+  if (aParent->inherits("QDockWidget")) {
+    QDockWidget* aTabWgt = (QDockWidget*) aParent;
+    aTabWgt->raise();
+  }
 }
\ No newline at end of file