1 // File: ModuleBase_WidgetPoint2D.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetPoint2D.h>
6 #include <ModuleBase_WidgetValueFeature.h>
7 #include <ModuleBase_DoubleSpinBox.h>
8 #include <ModuleBase_Tools.h>
10 #include <Config_Keywords.h>
11 #include <Config_WidgetAPI.h>
13 #include <Events_Loop.h>
14 #include <ModelAPI_Events.h>
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Object.h>
19 #include <GeomDataAPI_Point2D.h>
20 #include <GeomAPI_Pnt2d.h>
23 #include <QGridLayout>
31 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
32 const Config_WidgetAPI* theData,
33 const std::string& theParentId)
34 : ModuleBase_ModelWidget(theParent, theData, theParentId)
36 myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
37 QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
38 myGroupBox = new QGroupBox(aPageName, theParent);
39 myGroupBox->setFlat(false);
41 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
42 ModuleBase_Tools::adjustMargins(aGroupLay);
43 aGroupLay->setColumnStretch(1, 1);
45 QLabel* aLabel = new QLabel(myGroupBox);
47 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
48 aGroupLay->addWidget(aLabel, 0, 0);
50 myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
51 myXSpin->setMinimum(-DBL_MAX);
52 myXSpin->setMaximum(DBL_MAX);
53 myXSpin->setToolTip("X");
54 aGroupLay->addWidget(myXSpin, 0, 1);
56 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
59 QLabel* aLabel = new QLabel(myGroupBox);
61 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
62 aGroupLay->addWidget(aLabel, 1, 0);
64 myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
65 myYSpin->setMinimum(-DBL_MAX);
66 myYSpin->setMaximum(DBL_MAX);
67 myYSpin->setToolTip("X");
68 aGroupLay->addWidget(myYSpin, 1, 1);
70 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
74 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
78 bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue)
82 ModuleBase_WidgetValueFeature* aFeatureValue =
83 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
85 boost::shared_ptr<GeomAPI_Pnt2d> aPoint = aFeatureValue->point();
95 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
98 bool isBlocked = this->blockSignals(true);
99 myXSpin->setValue(thePoint->x());
100 myYSpin->setValue(thePoint->y());
101 this->blockSignals(isBlocked);
103 emit valuesChanged();
106 bool ModuleBase_WidgetPoint2D::storeValue() const
108 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
109 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
110 aData->attribute(attributeID()));
112 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
113 bool isBlocked = that->blockSignals(true);
114 aPoint->setValue(myXSpin->value(), myYSpin->value());
115 updateObject(myFeature);
116 that->blockSignals(isBlocked);
121 bool ModuleBase_WidgetPoint2D::restoreValue()
123 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
124 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
125 aData->attribute(attributeID()));
127 bool isBlocked = this->blockSignals(true);
128 myXSpin->setValue(aPoint->x());
129 myYSpin->setValue(aPoint->y());
130 this->blockSignals(isBlocked);
134 QWidget* ModuleBase_WidgetPoint2D::getControl() const
139 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
141 QList<QWidget*> aControls;
142 aControls.push_back(myXSpin);
143 aControls.push_back(myYSpin);
148 bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
150 if (myOptionParam.length() == 0)
152 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
153 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
154 aData->attribute(myOptionParam));
156 bool isBlocked = this->blockSignals(true);
157 myXSpin->setValue(aPoint->x());
158 myYSpin->setValue(aPoint->y());
159 this->blockSignals(isBlocked);
161 emit valuesChanged();
162 emit storedPoint2D(theObject, myOptionParam);