From: vsv Date: Wed, 4 Jun 2014 15:29:44 +0000 (+0400) Subject: Provide editing of Point and Extrusion objects X-Git-Tag: V_0.4.4~316^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=41f1d330c5156c27a2b6163fea03a62fea0d602c;p=modules%2Fshaper.git Provide editing of Point and Extrusion objects --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index ee8194422..31f9f36a0 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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(anAttr); @@ -112,6 +115,21 @@ boost::shared_ptr Model_Data::real(const string theID) return aRes; } +boost::shared_ptr Model_Data::boolean(const std::string theID) +{ + map >::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(); + } + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::reference(const string theID) { map >::iterator aFound = myAttrs.find(theID); diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 6eb34e17c..36f5f3614 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -57,6 +57,9 @@ public: /// Returns the attribute that contains list of references to features MODEL_EXPORT virtual boost::shared_ptr reflist(const std::string theID); + /// Returns the attribute that contains boolean value + MODEL_EXPORT virtual boost::shared_ptr + boolean(const std::string theID); /// Returns the generic attribute by identifier /// \param theID identifier of the attribute MODEL_EXPORT virtual boost::shared_ptr attribute(const std::string theID); diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 3bae7c023..76967d181 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -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 refattr(const std::string theID) = 0; /// Returns the attribute that contains list of references to features virtual boost::shared_ptr reflist(const std::string theID) = 0; + /// Returns the attribute that contains boolean value + virtual boost::shared_ptr boolean(const std::string theID) = 0; /// Returns the generic attribute by identifier /// \param theID identifier of the attribute diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 6b1f3d677..8679b5724 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index ff9b6da88..c20357942 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 4b9a4faa0..52b23a92c 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -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; +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index bbbfd04d2..a526655a2 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.cpp b/src/ModuleBase/ModuleBase_SelectorWidget.cpp index 7ac7ba946..eb25247bd 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.cpp +++ b/src/ModuleBase/ModuleBase_SelectorWidget.cpp @@ -21,6 +21,7 @@ #include #include #include +#include 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 aRef = boost::dynamic_pointer_cast(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 aRef = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + boost::shared_ptr 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 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 aChldList = aParent->findChildren(); @@ -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 diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.h b/src/ModuleBase/ModuleBase_SelectorWidget.h index 61d71c415..45ef3d64f 100644 --- a/src/ModuleBase/ModuleBase_SelectorWidget.h +++ b/src/ModuleBase/ModuleBase_SelectorWidget.h @@ -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; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index ecfe258e6..63646b956 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -7,12 +7,12 @@ #include -#include #include #include #include #include #include +#include #include #include @@ -26,7 +26,6 @@ #include #include #include -#include #ifdef _DEBUG #include @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 5dd799d62..e20fd2d9c 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -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); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index ae601b620..2d8c81479 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -68,17 +68,18 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } -bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) +bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(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; } diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index c544b6c16..85c4c938d 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -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 index 000000000..0d810ece1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_Widgets.cpp @@ -0,0 +1,170 @@ +// File: ModuleBase_Widgets.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#include "ModuleBase_Widgets.h" + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + + +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 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 aRef = aData->real(myAttributeID); + + bool isBlocked = mySpinBox->blockSignals(true); + mySpinBox->setValue(aRef->value()); + mySpinBox->blockSignals(isBlocked); + + return true; +} + +QList ModuleBase_DoubleValueWidget::getControls() const +{ + QList 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 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 aRef = aData->boolean(myAttributeID); + + bool isBlocked = myCheckBox->blockSignals(true); + myCheckBox->setChecked(aRef->value()); + myCheckBox->blockSignals(isBlocked); + + return true; +} + +QList ModuleBase_BoolValueWidget::getControls() const +{ + QList aList; + aList.append(myCheckBox); + return aList; +} diff --git a/src/ModuleBase/ModuleBase_Widgets.h b/src/ModuleBase/ModuleBase_Widgets.h new file mode 100644 index 000000000..d8030f9ab --- /dev/null +++ b/src/ModuleBase/ModuleBase_Widgets.h @@ -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 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 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 diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3de97e8b3..c73dcde68 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -233,7 +233,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeatur std::list aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX); aPreviewOp->init(theFeature, aSelected, aHighlighted); } else { - anOperation->setFeature(theFeature); + anOperation->setEditingFeature(theFeature); } sendOperation(anOperation); myWorkshop->actionsMgr()->updateCheckState();