Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
19                                                    const std::string& theFeatureAttributeID)
20 : ModuleBase_WidgetCustom(theParent), myFeatureAttributeID(theFeatureAttributeID)
21 {
22   myGroupBox = new QGroupBox(theTitle, theParent);
23   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
24   aGroupLay->setContentsMargins(0, 0, 0, 0);
25   aGroupLay->setColumnStretch(1, 1);
26   {
27     QLabel* aLabel = new QLabel(myGroupBox);
28     aLabel->setText("X");
29     aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
30     aGroupLay->addWidget(aLabel, 0, 0);
31
32     myXSpin = new QDoubleSpinBox(myGroupBox);
33     myXSpin->setMinimum(-DBL_MAX);
34     myXSpin->setMaximum(DBL_MAX);
35     myXSpin->setToolTip("X");
36     aGroupLay->addWidget(myXSpin, 0, 1);
37     
38     connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
39   }
40   {
41     QLabel* aLabel = new QLabel(myGroupBox);
42     aLabel->setText("Y");
43     aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
44     aGroupLay->addWidget(aLabel, 1, 0);
45
46     myYSpin = new QDoubleSpinBox(myGroupBox);
47     myYSpin->setMinimum(-DBL_MAX);
48     myYSpin->setMaximum(DBL_MAX);
49     myYSpin->setToolTip("X");
50     aGroupLay->addWidget(myYSpin, 1, 1);
51
52     connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
53   }
54 }
55
56 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
57 {
58 }
59
60 void ModuleBase_WidgetPoint2D::store(boost::shared_ptr<ModelAPI_Feature> theFeature)
61 {
62   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
63   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
64     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
65
66   aPoint->setValue(myXSpin->value(), myYSpin->value());
67 }
68
69 QWidget* ModuleBase_WidgetPoint2D::getControl() const
70 {
71   return myGroupBox;
72 }