1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomAPI_Pnt2d.h>
20 #include <QGridLayout>
21 #include <QDoubleSpinBox>
29 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
30 const Config_WidgetAPI* theData)
31 : ModuleBase_ModelWidget(theParent, theData)
33 myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
34 myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
36 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
37 aGroupLay->setContentsMargins(0, 0, 0, 0);
38 aGroupLay->setColumnStretch(1, 1);
40 QLabel* aLabel = new QLabel(myGroupBox);
42 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
43 aGroupLay->addWidget(aLabel, 0, 0);
45 myXSpin = new QDoubleSpinBox(myGroupBox);
46 myXSpin->setMinimum(-DBL_MAX);
47 myXSpin->setMaximum(DBL_MAX);
48 myXSpin->setToolTip("X");
49 aGroupLay->addWidget(myXSpin, 0, 1);
51 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
54 QLabel* aLabel = new QLabel(myGroupBox);
56 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
57 aGroupLay->addWidget(aLabel, 1, 0);
59 myYSpin = new QDoubleSpinBox(myGroupBox);
60 myYSpin->setMinimum(-DBL_MAX);
61 myYSpin->setMaximum(DBL_MAX);
62 myYSpin->setToolTip("X");
63 aGroupLay->addWidget(myYSpin, 1, 1);
65 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
67 myXSpin->installEventFilter(this);
68 myYSpin->installEventFilter(this);
71 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
75 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
78 bool isBlocked = this->blockSignals(true);
79 myXSpin->setValue(thePoint->x());
80 myYSpin->setValue(thePoint->y());
81 this->blockSignals(isBlocked);
86 bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
88 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
89 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
90 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
92 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
93 bool isBlocked = that->blockSignals(true);
94 aPoint->setValue(myXSpin->value(), myYSpin->value());
95 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
96 that->blockSignals(isBlocked);
101 bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
103 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
104 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
105 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
107 bool isBlocked = this->blockSignals(true);
108 myXSpin->setValue(aPoint->x());
109 myYSpin->setValue(aPoint->y());
110 this->blockSignals(isBlocked);
114 QWidget* ModuleBase_WidgetPoint2D::getControl() const
119 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
121 QList<QWidget*> aControls;
122 aControls.push_back(myXSpin);
123 aControls.push_back(myYSpin);
128 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
130 if (theObject == myXSpin || theObject == myYSpin) {
131 if (theEvent->type() == QEvent::KeyRelease) {
132 emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
136 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
139 void ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature)
141 if (myOptionParam.length() == 0)
143 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
144 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
145 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myOptionParam));
147 bool isBlocked = this->blockSignals(true);
148 myXSpin->setValue(aPoint->x());
149 this->blockSignals(isBlocked);
150 myYSpin->setValue(aPoint->y());