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>
9 #include <Config_Keywords.h>
10 #include <Config_WidgetAPI.h>
12 #include <Events_Loop.h>
13 #include <ModelAPI_Events.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Object.h>
18 #include <GeomDataAPI_Point2D.h>
19 #include <GeomAPI_Pnt2d.h>
22 #include <QGridLayout>
30 ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
31 const Config_WidgetAPI* theData,
32 const std::string& theParentId)
33 : ModuleBase_ModelWidget(theParent, theData, theParentId)
35 myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
36 myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
38 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
39 aGroupLay->setContentsMargins(2, 0, 2, 0);
40 aGroupLay->setColumnStretch(1, 1);
42 QLabel* aLabel = new QLabel(myGroupBox);
44 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
45 aGroupLay->addWidget(aLabel, 0, 0);
47 myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
48 myXSpin->setMinimum(-DBL_MAX);
49 myXSpin->setMaximum(DBL_MAX);
50 myXSpin->setToolTip("X");
51 aGroupLay->addWidget(myXSpin, 0, 1);
53 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
56 QLabel* aLabel = new QLabel(myGroupBox);
58 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
59 aGroupLay->addWidget(aLabel, 1, 0);
61 myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
62 myYSpin->setMinimum(-DBL_MAX);
63 myYSpin->setMaximum(DBL_MAX);
64 myYSpin->setToolTip("X");
65 aGroupLay->addWidget(myYSpin, 1, 1);
67 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
71 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
75 bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue)
79 ModuleBase_WidgetValueFeature* aFeatureValue =
80 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
82 boost::shared_ptr<GeomAPI_Pnt2d> aPoint = aFeatureValue->point();
92 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
95 bool isBlocked = this->blockSignals(true);
96 myXSpin->setValue(thePoint->x());
97 myYSpin->setValue(thePoint->y());
98 this->blockSignals(isBlocked);
100 emit valuesChanged();
103 bool ModuleBase_WidgetPoint2D::storeValue() const
105 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
106 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
107 aData->attribute(attributeID()));
109 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
110 bool isBlocked = that->blockSignals(true);
111 aPoint->setValue(myXSpin->value(), myYSpin->value());
112 updateObject(myFeature);
113 that->blockSignals(isBlocked);
118 bool ModuleBase_WidgetPoint2D::restoreValue()
120 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
121 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
122 aData->attribute(attributeID()));
124 bool isBlocked = this->blockSignals(true);
125 myXSpin->setValue(aPoint->x());
126 myYSpin->setValue(aPoint->y());
127 this->blockSignals(isBlocked);
131 QWidget* ModuleBase_WidgetPoint2D::getControl() const
136 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
138 QList<QWidget*> aControls;
139 aControls.push_back(myXSpin);
140 aControls.push_back(myYSpin);
145 bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
147 if (myOptionParam.length() == 0)
149 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
150 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
151 aData->attribute(myOptionParam));
153 bool isBlocked = this->blockSignals(true);
154 myXSpin->setValue(aPoint->x());
155 myYSpin->setValue(aPoint->y());
156 this->blockSignals(isBlocked);
158 emit valuesChanged();
159 emit storedPoint2D(theObject, myOptionParam);