From f30891542f6106a1a11c8a050180e852898d8b27 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 24 Jun 2014 15:17:07 +0400 Subject: [PATCH] Initialization of WidgetPoint2d with point from last feature. --- src/Config/Config_Keywords.h | 1 + src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 17 +++++++++++++++++ src/ModuleBase/ModuleBase_WidgetPoint2D.h | 4 ++++ src/PartSet/PartSet_OperationFeatureCreate.cpp | 7 +++---- src/SketchPlugin/plugin-Sketch.xml | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index c9d705d55..e44e5ad83 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -47,6 +47,7 @@ const static char* FEATURE_NESTED = "nested"; const static char* FEATURE_INTERNAL = "internal"; const static char* SOURCE_FILE = "path"; +const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param"; // doublevalue properties: const static char* INFO_WDG_TEXT = FEATURE_TEXT; diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 7903c8293..c13fb2d31 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -30,6 +30,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData) { + myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)), theParent); QGridLayout* aGroupLay = new QGridLayout(myGroupBox); @@ -73,6 +74,7 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& thePoint) { + bool isBlocked = this->blockSignals(true); myXSpin->setValue(thePoint->x()); myYSpin->setValue(thePoint->y()); @@ -133,3 +135,18 @@ bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent) } return ModuleBase_ModelWidget::eventFilter(theObject, theEvent); } + +void ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature) +{ + if (myOptionParam.length() == 0) + return; + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(myOptionParam)); + if (aPoint) { + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(aPoint->x()); + this->blockSignals(isBlocked); + myYSpin->setValue(aPoint->y()); + } +} diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index cf92afd3a..255a3950c 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -55,10 +55,14 @@ public: /// \param theEvent the processed event virtual bool eventFilter(QObject *theObject, QEvent *theEvent); + void initFromPrevious(FeaturePtr theFeature); + private: QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate QDoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate + + std::string myOptionParam; /// Parameter name which has to be taken from previous feature }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index afc823140..82cf4225c 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -202,10 +202,9 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t myActiveWidget = theWidget; if (myInitFeature && myActiveWidget) { - // TODO: to be realized in the custom point selector. The last point values of the init feature - // should be to to the start point of a new feature - //myActiveWidget->init(myInitFeature); - //PartSet_FeatureLinePrs::setFeature(myInitFeature, SM_FirstPoint); + ModuleBase_WidgetPoint2D* aWgt = dynamic_cast(myActiveWidget); + if (aWgt) + aWgt->initFromPrevious(myInitFeature); myInitFeature = FeaturePtr(); emit activateNextWidget(myActiveWidget); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 96665b483..fd884f1da 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -9,7 +9,7 @@ - + -- 2.39.2