1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
6 #include <ModuleBase_WidgetValueFeature.h>
8 #include <Config_Keywords.h>
9 #include <Config_WidgetAPI.h>
11 #include <Events_Loop.h>
12 #include <Model_Events.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Data.h>
16 #include <ModelAPI_Object.h>
17 #include <GeomDataAPI_Point2D.h>
18 #include <GeomAPI_Pnt2d.h>
21 #include <QGridLayout>
22 #include <QDoubleSpinBox>
30 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
31 const Config_WidgetAPI* theData)
32 : ModuleBase_ModelWidget(theParent, theData)
34 myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
35 myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
37 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
38 aGroupLay->setContentsMargins(0, 0, 0, 0);
39 aGroupLay->setColumnStretch(1, 1);
41 QLabel* aLabel = new QLabel(myGroupBox);
43 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
44 aGroupLay->addWidget(aLabel, 0, 0);
46 myXSpin = new QDoubleSpinBox(myGroupBox);
47 myXSpin->setMinimum(-DBL_MAX);
48 myXSpin->setMaximum(DBL_MAX);
49 myXSpin->setToolTip("X");
50 aGroupLay->addWidget(myXSpin, 0, 1);
52 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
55 QLabel* aLabel = new QLabel(myGroupBox);
57 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
58 aGroupLay->addWidget(aLabel, 1, 0);
60 myYSpin = new QDoubleSpinBox(myGroupBox);
61 myYSpin->setMinimum(-DBL_MAX);
62 myYSpin->setMaximum(DBL_MAX);
63 myYSpin->setToolTip("X");
64 aGroupLay->addWidget(myYSpin, 1, 1);
66 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
68 myXSpin->installEventFilter(this);
69 myYSpin->installEventFilter(this);
72 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
76 bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue)
80 ModuleBase_WidgetValueFeature* aFeatureValue =
81 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
83 setPoint(aFeatureValue->point());
90 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
93 bool isBlocked = this->blockSignals(true);
94 myXSpin->setValue(thePoint->x());
95 myYSpin->setValue(thePoint->y());
96 this->blockSignals(isBlocked);
101 bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
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 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
108 bool isBlocked = that->blockSignals(true);
109 aPoint->setValue(myXSpin->value(), myYSpin->value());
110 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
111 that->blockSignals(isBlocked);
116 bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
118 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
119 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
120 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
122 bool isBlocked = this->blockSignals(true);
123 myXSpin->setValue(aPoint->x());
124 myYSpin->setValue(aPoint->y());
125 this->blockSignals(isBlocked);
129 QWidget* ModuleBase_WidgetPoint2D::getControl() const
134 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
136 QList<QWidget*> aControls;
137 aControls.push_back(myXSpin);
138 aControls.push_back(myYSpin);
143 bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
145 if (theObject == myXSpin || theObject == myYSpin) {
146 if (theEvent->type() == QEvent::KeyRelease) {
147 QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
148 if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
149 emit focusOutWidget(this);
151 emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
155 return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
158 bool ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature)
160 if (myOptionParam.length() == 0)
162 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
163 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
164 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myOptionParam));
166 bool isBlocked = this->blockSignals(true);
167 myXSpin->setValue(aPoint->x());
168 myYSpin->setValue(aPoint->y());
169 this->blockSignals(isBlocked);
171 emit valuesChanged();
172 emit storedPoint2D(theFeature, myOptionParam);