]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide editing of Point and Extrusion objects
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 4 Jun 2014 15:29:44 +0000 (19:29 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 4 Jun 2014 15:29:44 +0000 (19:29 +0400)
16 files changed:
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Data.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_SelectorWidget.cpp
src/ModuleBase/ModuleBase_SelectorWidget.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/ModuleBase/ModuleBase_WidgetPoint2D.h
src/ModuleBase/ModuleBase_Widgets.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_Widgets.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp

index ee81944226cff7f0e24914eb285d56973459cabc..31f9f36a03eab9542a8410a4e753c2d83248fda6 100644 (file)
@@ -8,6 +8,7 @@
 #include <Model_AttributeReference.h>
 #include <Model_AttributeRefAttr.h>
 #include <Model_AttributeRefList.h>
+#include <Model_AttributeBoolean.h>
 #include <GeomData_Point.h>
 #include <GeomData_Point2D.h>
 #include <GeomData_Dir.h>
@@ -73,6 +74,8 @@ void Model_Data::addAttribute(string theID, string theAttrType)
     anAttr = new GeomData_Dir(anAttrLab);
   else if (theAttrType == GeomData_Point2D::type())
     anAttr = new GeomData_Point2D(anAttrLab);
+  else if (theAttrType == Model_AttributeBoolean::type())
+    anAttr = new Model_AttributeBoolean(anAttrLab);
 
   if (anAttr) {
     myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
@@ -112,6 +115,21 @@ boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
   return aRes;
 }
 
+boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string theID)
+{
+  map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  if (aFound == myAttrs.end()) {
+    // TODO: generate error on unknown attribute request and/or add mechanism for customization
+    return boost::shared_ptr<ModelAPI_AttributeBoolean>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
 boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string theID)
 {
   map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
index 6eb34e17c6977415960a2579228116acf6e7984e..36f5f361463d7372cef018a00f687bebf9c23d65 100644 (file)
@@ -57,6 +57,9 @@ public:
   /// Returns the attribute that contains list of references to features
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList> 
     reflist(const std::string theID);
+  /// Returns the attribute that contains boolean value
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean> 
+    boolean(const std::string theID);
   /// Returns the generic attribute by identifier
   /// \param theID identifier of the attribute
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
index 3bae7c023be864d8134b40e4b08206a8567ddb5e..76967d18143f6e50c00374755a0ad13fa5f6f110 100644 (file)
@@ -14,6 +14,7 @@ class ModelAPI_AttributeDouble;
 class ModelAPI_AttributeReference;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefList;
+class ModelAPI_AttributeBoolean;
 class ModelAPI_Document;
 class ModelAPI_Attribute;
 class GeomAPI_Shape;
@@ -44,6 +45,8 @@ public:
   virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string theID) = 0;
   /// Returns the attribute that contains list of references to features
   virtual boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string theID) = 0;
+  /// Returns the attribute that contains boolean value
+  virtual boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string theID) = 0;
 
   /// Returns the generic attribute by identifier
   /// \param theID identifier of the attribute
index 6b1f3d6772d125e96c31800c3dbb7633f92d92a4..8679b5724cfd008ff0d8246e63ac62ce35651ca1 100644 (file)
@@ -13,6 +13,7 @@ SET(PROJECT_HEADERS
        ModuleBase_MetaWidget.h
     ModuleBase_SelectorWidget.h
     ModuleBase_IWorkshop.h
+    ModuleBase_Widgets.h
 )
 
 SET(PROJECT_SOURCES
@@ -24,6 +25,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetSwitch.cpp
        ModuleBase_MetaWidget.cpp
     ModuleBase_SelectorWidget.cpp
+    ModuleBase_Widgets.cpp
 )
 
 SET(PROJECT_LIBRARIES
index ff9b6da8840cf2b899614fa3d5086d83e244aed5..c203579420b29a78e13f0c0d7e907d9678e348ab 100644 (file)
@@ -36,16 +36,16 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(FeaturePtr theFeature) = 0;
+  virtual bool storeValue(FeaturePtr theFeature) const = 0;
 
   virtual bool restoreValue(FeaturePtr theFeature) = 0;
 
   /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
   /// \param theAttribute name
-  virtual bool canFocusTo(const std::string& theAttributeName) = 0;
+  virtual bool canFocusTo(const std::string& theAttributeName) const { return false; }
 
   /// Set focus to the current widget if it corresponds to the given attribute
-  virtual void focusTo() = 0;
+  virtual void focusTo() {}
 
   /// Returns list of widget controls
   /// \return a control list
index 4b9a4faa0e4f001bd10bc343e29ca8f86c4213cf..52b23a92c7a7e337adeae683e38a4260e768b3db 100644 (file)
@@ -24,7 +24,7 @@
 #endif
 
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-: ModuleBase_IOperation(theId, theParent)
+: ModuleBase_IOperation(theId, theParent), myIsEditing(false)
 {
 }
 
@@ -80,7 +80,7 @@ void ModuleBase_Operation::storeCustomValue()
 
 void ModuleBase_Operation::startOperation()
 {
-  if (!myFeature)
+  if (!myIsEditing)
     setFeature(createFeature());
   //emit callSlot();
   //commit();
@@ -130,3 +130,9 @@ void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
 {
   myFeature = theFeature;
 }
+
+void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
+{
+  myFeature = theFeature;
+  myIsEditing = true;
+}
index bbbfd04d2c304ccf938c44533802ebb13f97349b..a526655a2ab787d574a4706caedd7f5f06bdd188 100644 (file)
@@ -72,7 +72,9 @@ public:
   virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
 
   /// Sets the operation feature
-  void setFeature(FeaturePtr theFeature);
+  void setEditingFeature(FeaturePtr theFeature);
+
+  bool isEditOperation() const { return myIsEditing; }
 
 protected:
   /// Virtual method called when operation started (see start() method for more description)
@@ -97,8 +99,13 @@ protected:
   /// \returns the created feature
   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
 
+  /// Sets the operation feature
+  void setFeature(FeaturePtr theFeature);
+
 private:
   FeaturePtr myFeature; /// the operation feature to be handled
+
+  bool myIsEditing;
 };
 
 #endif
index 7ac7ba946800a96a837af5a71a3228c759fa8a80..eb25247bdecc74b252d6024d1e0861807b2c250c 100644 (file)
@@ -21,6 +21,7 @@
 #include <QToolButton>
 #include <QString>
 #include <QEvent>
+#include <QDockWidget>
 
 
 ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 
@@ -69,17 +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));
 
-  bool isBlocked = this->blockSignals(true);
-  aRef->setValue(mySelectedFeature);
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-
-  this->blockSignals(isBlocked);
+  FeaturePtr aFeature = aRef->value();
+  if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+    aRef->setValue(mySelectedFeature);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  }
   return true;
 }
 
@@ -87,8 +88,7 @@ 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();
@@ -98,17 +98,6 @@ bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
   return true;
 }
 
-//********************************************************************
-bool ModuleBase_SelectorWidget::canFocusTo(const std::string& theAttributeName)
-{
-  return false;
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::focusTo()
-{
-}
-
 //********************************************************************
 QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
 {
@@ -138,6 +127,7 @@ void ModuleBase_SelectorWidget::onSelectionChanged()
     if (mySelectedFeature) {
       updateSelectionName();
       activateSelection(false);
+      raisePanel();
     } else {
       myTextLine->setText("");
     }
@@ -173,7 +163,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*>();
@@ -195,4 +185,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
index 61d71c415320288d8ce6dbf1b17c8fe1cfa7e7dd..45ef3d64f82edbb7f0260c5b2d5a71879e7c0e9c 100644 (file)
@@ -30,17 +30,10 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(FeaturePtr theFeature);
+  virtual bool storeValue(FeaturePtr theFeature) const;
 
   virtual bool restoreValue(FeaturePtr theFeature);
 
-  /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
-  /// \param theAttribute name
-  virtual bool canFocusTo(const std::string& theAttributeName);
-
-  /// Set focus to the current widget if it corresponds to the given attribute
-  virtual void focusTo();
-
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
   QWidget* getControl() const { return myContainer; }
@@ -66,8 +59,9 @@ private slots:
   void onSelectionChanged();
 
 private:
-  void enableOthersControls(bool toEnable);
+  void enableOthersControls(bool toEnable) const;
   void updateSelectionName();
+  void raisePanel() const;
 
   std::string myFeatureAttributeID;
 
index ecfe258e6646956c15f132d5ddb9f6a5a6b0fdcc..63646b9565474d81917db69ca089bd0cf30155bb 100644 (file)
@@ -7,12 +7,12 @@
 
 #include <ModuleBase_WidgetFactory.h>
 
-#include <ModuleBase_MetaWidget.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetSwitch.h>
 #include <ModuleBase_SelectorWidget.h>
+#include <ModuleBase_Widgets.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -26,7 +26,6 @@
 #include <QPixmap>
 #include <QGroupBox>
 #include <QToolBox>
-#include <QCheckBox>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -105,7 +104,7 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
 {
   QWidget* result = NULL;
   if (theType == WDG_DOUBLEVALUE) {
-    result = doubleSpinBoxControl();
+    result = doubleSpinBoxControl(theParent);
 
   } else if (theType == WDG_INFO) {
     result = labelControl(theParent);
@@ -148,52 +147,17 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q
   return result;
 }
 
-QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl()
+QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
 {
-  QWidget* result = new QWidget();
-  QHBoxLayout* aControlLay = new QHBoxLayout(result);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
-  QString aLabelText = qs(myWidgetApi->widgetLabel());
-  QString aLabelIcon = qs(myWidgetApi->widgetIcon());
-  QLabel* aLabel = new QLabel(aLabelText);
-  aLabel->setPixmap(QPixmap(aLabelIcon));
-
-  aControlLay->addWidget(aLabel);
-  QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
-  QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
-  aBox->setObjectName(anObjName);
-  bool isOk = false;
-  std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
-  double aMinVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setMinimum(aMinVal);
-  } else {
-    aBox->setMinimum(-DBL_MAX);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
-  double aMaxVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setMaximum(aMaxVal);
-  } else {
-    aBox->setMaximum(DBL_MAX);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
-  double aStepVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setSingleStep(aStepVal);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
-  double aDefVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setValue(aDefVal);
-  }
-  QString aTTip = qs(myWidgetApi->widgetTooltip());
-  aBox->setToolTip(aTTip);
-  aControlLay->addWidget(aBox);
-  aControlLay->setStretch(1, 1);
-  result->setLayout(aControlLay);
-  connectWidget(aBox, WDG_DOUBLEVALUE);
-  return result;
+  ModuleBase_DoubleValueWidget* aDblWgt = new ModuleBase_DoubleValueWidget(theParent, myWidgetApi);
+  QObject::connect(aDblWgt, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
+
+  myModelWidgets.append(aDblWgt);
+
+  // Init default values
+  if (!myOperation->isEditOperation())
+    aDblWgt->storeValue(myOperation->feature());
+  return aDblWgt->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
@@ -239,12 +203,13 @@ QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
 
 QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
 {
-  QString aText = qs(myWidgetApi->widgetLabel());
-  QString aToolTip = qs(myWidgetApi->widgetTooltip());
-  QString aDefault = qs(myWidgetApi->getProperty("default"));
-
-  QCheckBox* aRes = new QCheckBox(aText, theParent);
-  aRes->setToolTip(aToolTip);
-  aRes->setChecked(aDefault == "true");
-  return aRes;
+  ModuleBase_BoolValueWidget* aBoolWgt = new ModuleBase_BoolValueWidget(theParent, myWidgetApi);
+  QObject::connect(aBoolWgt, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
+
+  myModelWidgets.append(aBoolWgt);
+
+  // Init default values
+  if (!myOperation->isEditOperation())
+    aBoolWgt->storeValue(myOperation->feature());
+  return aBoolWgt->getControl();
 }
\ No newline at end of file
index 5dd799d62c706a0f71748dd60d573bc2a9b23a07..e20fd2d9cf7191ddfa151b9cdfb6d97fe0aefb89 100644 (file)
@@ -37,7 +37,7 @@ protected:
   //Widgets
   QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
   QWidget* labelControl(QWidget* theParent);
-  QWidget* doubleSpinBoxControl();
+  QWidget* doubleSpinBoxControl(QWidget* theParent);
   QWidget* pointSelectorControl(QWidget* theParent);
   QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
   QWidget* selectorControl(QWidget* theParent);
index ae601b62094bbf04f030e1a105ee639ee91cf075..2d8c814798d423fb16cbbe8a1f1dee2bc1865ae9 100644 (file)
@@ -68,17 +68,18 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
 {
 }
 
-bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
 {
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
 
-  bool isBlocked = this->blockSignals(true);
+  ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
+  bool isBlocked = that->blockSignals(true);
   aPoint->setValue(myXSpin->value(), myYSpin->value());
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  that->blockSignals(isBlocked);
 
-  this->blockSignals(isBlocked);
   return true;
 }
 
index c544b6c168f8de9bdbc934295bc610568c14dfb2..85c4c938d5aa0e6dfd69a2b768debcfd44f74bff 100644 (file)
@@ -34,7 +34,7 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(FeaturePtr theFeature);
+  virtual bool storeValue(FeaturePtr theFeature) const;
 
   virtual bool restoreValue(FeaturePtr theFeature);
 
diff --git a/src/ModuleBase/ModuleBase_Widgets.cpp b/src/ModuleBase/ModuleBase_Widgets.cpp
new file mode 100644 (file)
index 0000000..0d810ec
--- /dev/null
@@ -0,0 +1,170 @@
+// File:        ModuleBase_Widgets.h
+// Created:     04 June 2014
+// Author:      Vitaly Smetannikov
+
+#include "ModuleBase_Widgets.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_Data.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QDoubleSpinBox>
+#include <QCheckBox>
+
+
+ModuleBase_DoubleValueWidget::ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData)
+  : ModuleBase_ModelWidget(theParent)
+{
+  myContainer = new QWidget(theParent);
+  QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
+  aControlLay->setContentsMargins(0, 0, 0, 0);
+
+  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  myLabel = new QLabel(aLabelText, myContainer);
+  myLabel->setPixmap(QPixmap(aLabelIcon));
+  aControlLay->addWidget(myLabel);
+
+  myAttributeID = theData->widgetId();
+  mySpinBox = new QDoubleSpinBox(myContainer);
+  QString anObjName = QString::fromStdString(myAttributeID);
+  mySpinBox->setObjectName(anObjName);
+
+  bool isOk = false;
+  std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
+  double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
+  if (isOk) {
+    mySpinBox->setMinimum(aMinVal);
+  } else {
+    mySpinBox->setMinimum(-DBL_MAX);
+  }
+
+  aProp = theData->getProperty(DOUBLE_WDG_MAX);
+  double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
+  if (isOk) {
+    mySpinBox->setMaximum(aMaxVal);
+  } else {
+    mySpinBox->setMaximum(DBL_MAX);
+  }
+
+  aProp = theData->getProperty(DOUBLE_WDG_STEP);
+  double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
+  if (isOk) {
+    mySpinBox->setSingleStep(aStepVal);
+  }
+
+  aProp = theData->getProperty(DOUBLE_WDG_DFLT);
+  double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
+  if (isOk) {
+    mySpinBox->setValue(aDefVal);
+  }
+
+  QString aTTip = QString::fromStdString(theData->widgetTooltip());
+  mySpinBox->setToolTip(aTTip);
+
+  aControlLay->addWidget(mySpinBox);
+  aControlLay->setStretch(1, 1);
+
+  connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_DoubleValueWidget::~ModuleBase_DoubleValueWidget()
+{
+}
+
+bool ModuleBase_DoubleValueWidget::storeValue(FeaturePtr theFeature) const
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(myAttributeID);
+  if (aReal->value() != mySpinBox->value()) {
+    aReal->setValue(mySpinBox->value());
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  }
+  return true;
+}
+
+bool ModuleBase_DoubleValueWidget::restoreValue(FeaturePtr theFeature)
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(myAttributeID);
+
+  bool isBlocked = mySpinBox->blockSignals(true);
+  mySpinBox->setValue(aRef->value());
+  mySpinBox->blockSignals(isBlocked);
+
+  return true;
+}
+
+QList<QWidget*> ModuleBase_DoubleValueWidget::getControls() const
+{
+  QList<QWidget*> aList;
+  aList.append(myLabel);
+  aList.append(mySpinBox);
+  return aList;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////
+ModuleBase_BoolValueWidget::ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData)
+  : ModuleBase_ModelWidget(theParent)
+{
+  myAttributeID = theData->widgetId();
+  QString aText = QString::fromStdString(theData->widgetLabel());
+  QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+  QString aDefault = QString::fromStdString(theData->getProperty("default"));
+
+  myCheckBox = new QCheckBox(aText, theParent);
+  myCheckBox->setToolTip(aToolTip);
+  myCheckBox->setChecked(aDefault == "true");
+
+  connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_BoolValueWidget::~ModuleBase_BoolValueWidget()
+{
+}
+
+QWidget* ModuleBase_BoolValueWidget::getControl() const 
+{ 
+  return myCheckBox; 
+}
+
+bool ModuleBase_BoolValueWidget::storeValue(FeaturePtr theFeature) const
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
+
+  if (aBool->value() != myCheckBox->isChecked()) {
+    aBool->setValue(myCheckBox->isChecked());
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  }
+  return true;
+}
+
+bool ModuleBase_BoolValueWidget::restoreValue(FeaturePtr theFeature)
+{
+  DataPtr aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
+
+  bool isBlocked = myCheckBox->blockSignals(true);
+  myCheckBox->setChecked(aRef->value());
+  myCheckBox->blockSignals(isBlocked);
+
+  return true;
+}
+
+QList<QWidget*> ModuleBase_BoolValueWidget::getControls() const
+{
+  QList<QWidget*> aList;
+  aList.append(myCheckBox);
+  return aList;
+}
diff --git a/src/ModuleBase/ModuleBase_Widgets.h b/src/ModuleBase/ModuleBase_Widgets.h
new file mode 100644 (file)
index 0000000..d8030f9
--- /dev/null
@@ -0,0 +1,78 @@
+// File:        ModuleBase_Widgets.h
+// Created:     04 June 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ModuleBase_Widgets_H
+#define ModuleBase_Widgets_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QDoubleSpinBox;
+class QCheckBox;
+
+class MODULEBASE_EXPORT ModuleBase_DoubleValueWidget: public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+public:
+  ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_DoubleValueWidget();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theFeature a model feature to be changed
+  virtual bool storeValue(FeaturePtr theFeature) const;
+
+  virtual bool restoreValue(FeaturePtr theFeature);
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const { return myContainer; }
+
+private:
+  std::string myAttributeID;
+  
+  QWidget*     myContainer;
+  QLabel*      myLabel;
+  QDoubleSpinBox* mySpinBox;
+};
+
+
+//////////////////////////////////////////////////////////////////////////////////
+
+class MODULEBASE_EXPORT ModuleBase_BoolValueWidget: public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+public:
+  ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_BoolValueWidget();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theFeature a model feature to be changed
+  virtual bool storeValue(FeaturePtr theFeature) const;
+
+  virtual bool restoreValue(FeaturePtr theFeature);
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const;
+
+private:
+  std::string myAttributeID;
+  
+  QCheckBox* myCheckBox;
+};
+
+#endif
\ No newline at end of file
index 3de97e8b371a038e2fabd60a2e80b5cba5a20e00..c73dcde680eccc4c0e550f909a87b13e68336236 100644 (file)
@@ -233,7 +233,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeatur
     std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
   } else {
-    anOperation->setFeature(theFeature);
+    anOperation->setEditingFeature(theFeature);
   }
   sendOperation(anOperation);
   myWorkshop->actionsMgr()->updateCheckState();