Salome HOME
4d99d01be7fccfd41897cc5c04ea5d594e8f1548
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetPoint2D.cpp
1 // File:        ModuleBase_WidgetPoint2D.cpp
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <ModuleBase_WidgetPoint2D.h>
6
7 #include <Config_Keywords.h>
8
9 #include <Events_Loop.h>
10 #include <Model_Events.h>
11
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Data.h>
14 #include <GeomDataAPI_Point2D.h>
15
16 #include <QGroupBox>
17 #include <QGridLayout>
18 #include <QDoubleSpinBox>
19 #include <QLabel>
20
21 #include <cfloat>
22 #include <climits>
23
24 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
25                                                    const std::string& theFeatureAttributeID)
26 : ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
27 {
28   myGroupBox = new QGroupBox(theTitle, theParent);
29   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
30   aGroupLay->setContentsMargins(0, 0, 0, 0);
31   aGroupLay->setColumnStretch(1, 1);
32   {
33     QLabel* aLabel = new QLabel(myGroupBox);
34     aLabel->setText("X");
35     aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
36     aGroupLay->addWidget(aLabel, 0, 0);
37
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);
43     
44     connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
45   }
46   {
47     QLabel* aLabel = new QLabel(myGroupBox);
48     aLabel->setText("Y");
49     aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
50     aGroupLay->addWidget(aLabel, 1, 0);
51
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);
57
58     connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
59   }
60 }
61
62 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
63 {
64 }
65
66 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
67 {
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));
71
72   bool isBlocked = this->blockSignals(true);
73   aPoint->setValue(myXSpin->value(), myYSpin->value());
74   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
75
76   this->blockSignals(isBlocked);
77   return true;
78 }
79
80 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
81 {
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));
85
86   bool isBlocked = this->blockSignals(true);
87   myXSpin->setValue(aPoint->x());
88   myYSpin->setValue(aPoint->y());
89   this->blockSignals(isBlocked);
90   return true;
91 }
92
93 QWidget* ModuleBase_WidgetPoint2D::getControl() const
94 {
95   return myGroupBox;
96 }