X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetPoint2D.cpp;h=c6d341d002134e20b5c797013e147e080c3fb4c4;hb=2df4457d07ad1b2e2a1d48068a24fc024f1715e3;hp=4d99d01be7fccfd41897cc5c04ea5d594e8f1548;hpb=582c30d5a6ba4624022c04107809428d594b9245;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 4d99d01be..c6d341d00 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -3,31 +3,43 @@ // Author: Natalia ERMOLAEVA #include +#include +#include +#include #include +#include #include -#include +#include #include #include +#include #include +#include #include #include -#include #include +#include +#include #include #include -ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, - const std::string& theFeatureAttributeID) -: ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID) +ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) { - myGroupBox = new QGroupBox(theTitle, theParent); + myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); + QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)); + myGroupBox = new QGroupBox(aPageName, theParent); + myGroupBox->setFlat(false); + QGridLayout* aGroupLay = new QGridLayout(myGroupBox); - aGroupLay->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::adjustMargins(aGroupLay); aGroupLay->setColumnStretch(1, 1); { QLabel* aLabel = new QLabel(myGroupBox); @@ -35,12 +47,12 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString t aLabel->setPixmap(QPixmap(":pictures/x_point.png")); aGroupLay->addWidget(aLabel, 0, 0); - myXSpin = new QDoubleSpinBox(myGroupBox); + myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox); myXSpin->setMinimum(-DBL_MAX); myXSpin->setMaximum(DBL_MAX); myXSpin->setToolTip("X"); aGroupLay->addWidget(myXSpin, 0, 1); - + connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); } { @@ -49,7 +61,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString t aLabel->setPixmap(QPixmap(":pictures/y_point.png")); aGroupLay->addWidget(aLabel, 1, 0); - myYSpin = new QDoubleSpinBox(myGroupBox); + myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox); myYSpin->setMinimum(-DBL_MAX); myYSpin->setMaximum(DBL_MAX); myYSpin->setToolTip("X"); @@ -63,25 +75,54 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } -bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) { + boost::shared_ptr aPoint = aFeatureValue->point(); + if (aPoint) { + setPoint(aPoint); + isDone = true; + } + } + } + return isDone; +} + +void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& thePoint) { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); bool isBlocked = this->blockSignals(true); + myXSpin->setValue(thePoint->x()); + myYSpin->setValue(thePoint->y()); + this->blockSignals(isBlocked); + + emit valuesChanged(); +} + +bool ModuleBase_WidgetPoint2D::storeValue() const +{ + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast( + aData->attribute(attributeID())); + + 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)); + updateObject(myFeature); + that->blockSignals(isBlocked); - this->blockSignals(isBlocked); return true; } -bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::restoreValue() { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast( + aData->attribute(attributeID())); bool isBlocked = this->blockSignals(true); myXSpin->setValue(aPoint->x()); @@ -94,3 +135,32 @@ QWidget* ModuleBase_WidgetPoint2D::getControl() const { return myGroupBox; } + +QList ModuleBase_WidgetPoint2D::getControls() const +{ + QList aControls; + aControls.push_back(myXSpin); + aControls.push_back(myYSpin); + + return aControls; +} + +bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) +{ + if (myOptionParam.length() == 0) + return false; + boost::shared_ptr aData = theObject->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast( + aData->attribute(myOptionParam)); + if (aPoint) { + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(aPoint->x()); + myYSpin->setValue(aPoint->y()); + this->blockSignals(isBlocked); + + emit valuesChanged(); + emit storedPoint2D(theObject, myOptionParam); + return true; + } + return false; +}