Salome HOME
Issue #6 uncheck only one aborted operation, not all nested stack
[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 <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
11 #include <GeomDataAPI_Point2D.h>
12
13 #include <QGroupBox>
14 #include <QGridLayout>
15 #include <QDoubleSpinBox>
16 #include <QLabel>
17
18 #include <cfloat>
19 #include <climits>
20
21 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
22                                                    const std::string& theFeatureAttributeID)
23 : ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
24 {
25   myGroupBox = new QGroupBox(theTitle, theParent);
26   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
27   aGroupLay->setContentsMargins(0, 0, 0, 0);
28   aGroupLay->setColumnStretch(1, 1);
29   {
30     QLabel* aLabel = new QLabel(myGroupBox);
31     aLabel->setText("X");
32     aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
33     aGroupLay->addWidget(aLabel, 0, 0);
34
35     myXSpin = new QDoubleSpinBox(myGroupBox);
36     myXSpin->setMinimum(-DBL_MAX);
37     myXSpin->setMaximum(DBL_MAX);
38     myXSpin->setToolTip("X");
39     aGroupLay->addWidget(myXSpin, 0, 1);
40     
41     connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
42   }
43   {
44     QLabel* aLabel = new QLabel(myGroupBox);
45     aLabel->setText("Y");
46     aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
47     aGroupLay->addWidget(aLabel, 1, 0);
48
49     myYSpin = new QDoubleSpinBox(myGroupBox);
50     myYSpin->setMinimum(-DBL_MAX);
51     myYSpin->setMaximum(DBL_MAX);
52     myYSpin->setToolTip("X");
53     aGroupLay->addWidget(myYSpin, 1, 1);
54
55     connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
56   }
57 }
58
59 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
60 {
61 }
62
63 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
64 {
65   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
66   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
67     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
68
69   bool isBlocked = this->blockSignals(true);
70   aPoint->setValue(myXSpin->value(), myYSpin->value());
71   this->blockSignals(isBlocked);
72   return true;
73 }
74
75 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
76 {
77   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
78   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
79     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
80
81   bool isBlocked = this->blockSignals(true);
82   myXSpin->setValue(aPoint->x());
83   myYSpin->setValue(aPoint->y());
84   this->blockSignals(isBlocked);
85   return true;
86 }
87
88 QWidget* ModuleBase_WidgetPoint2D::getControl() const
89 {
90   return myGroupBox;
91 }