1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
7 #include <Config_Keywords.h>
9 #include <Events_Loop.h>
10 #include <Model_Events.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Data.h>
14 #include <GeomDataAPI_Point2D.h>
17 #include <QGridLayout>
18 #include <QDoubleSpinBox>
24 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
25 const std::string& theFeatureAttributeID)
26 : ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
28 myGroupBox = new QGroupBox(theTitle, theParent);
29 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
30 aGroupLay->setContentsMargins(0, 0, 0, 0);
31 aGroupLay->setColumnStretch(1, 1);
33 QLabel* aLabel = new QLabel(myGroupBox);
35 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
36 aGroupLay->addWidget(aLabel, 0, 0);
38 myXSpin = new QDoubleSpinBox(myGroupBox);
39 myXSpin->setMinimum(-DBL_MAX);
40 myXSpin->setMaximum(DBL_MAX);
41 myXSpin->setToolTip("X");
42 aGroupLay->addWidget(myXSpin, 0, 1);
44 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
47 QLabel* aLabel = new QLabel(myGroupBox);
49 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
50 aGroupLay->addWidget(aLabel, 1, 0);
52 myYSpin = new QDoubleSpinBox(myGroupBox);
53 myYSpin->setMinimum(-DBL_MAX);
54 myYSpin->setMaximum(DBL_MAX);
55 myYSpin->setToolTip("X");
56 aGroupLay->addWidget(myYSpin, 1, 1);
58 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
62 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
66 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
68 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
69 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
70 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
72 bool isBlocked = this->blockSignals(true);
73 aPoint->setValue(myXSpin->value(), myYSpin->value());
74 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
76 this->blockSignals(isBlocked);
80 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
82 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
83 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
84 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
86 bool isBlocked = this->blockSignals(true);
87 myXSpin->setValue(aPoint->x());
88 myYSpin->setValue(aPoint->y());
89 this->blockSignals(isBlocked);
93 QWidget* ModuleBase_WidgetPoint2D::getControl() const