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>
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 QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
37 myGroupBox = new QGroupBox(aPageName, theParent);
38 myGroupBox->setFlat(false);
40 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
41 ModuleBase_Tools::adjustMargins(aGroupLay);
42 aGroupLay->setColumnStretch(1, 1);
44 QLabel* aLabel = new QLabel(myGroupBox);
46 aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
47 aGroupLay->addWidget(aLabel, 0, 0);
49 myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
50 myXSpin->setMinimum(-DBL_MAX);
51 myXSpin->setMaximum(DBL_MAX);
52 myXSpin->setToolTip("X");
53 aGroupLay->addWidget(myXSpin, 0, 1);
55 connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
58 QLabel* aLabel = new QLabel(myGroupBox);
60 aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
61 aGroupLay->addWidget(aLabel, 1, 0);
63 myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox);
64 myYSpin->setMinimum(-DBL_MAX);
65 myYSpin->setMaximum(DBL_MAX);
66 myYSpin->setToolTip("X");
67 aGroupLay->addWidget(myYSpin, 1, 1);
69 connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
73 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
77 bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue)
81 ModuleBase_WidgetValueFeature* aFeatureValue =
82 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
84 boost::shared_ptr<GeomAPI_Pnt2d> aPoint = aFeatureValue->point();
94 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
97 bool isBlocked = this->blockSignals(true);
98 myXSpin->setValue(thePoint->x());
99 myYSpin->setValue(thePoint->y());
100 this->blockSignals(isBlocked);
102 emit valuesChanged();
105 bool ModuleBase_WidgetPoint2D::storeValue() const
107 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
108 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
109 aData->attribute(attributeID()));
111 ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
112 bool isBlocked = that->blockSignals(true);
113 bool isImmutable = aPoint->setImmutable(true);
115 std::string _attr_name = myAttributeID;
116 double _X = myXSpin->value();
117 double _Y = myYSpin->value();
119 aPoint->setValue(myXSpin->value(), myYSpin->value());
120 updateObject(myFeature);
121 aPoint->setImmutable(isImmutable);
122 that->blockSignals(isBlocked);
127 bool ModuleBase_WidgetPoint2D::restoreValue()
129 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
130 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
131 aData->attribute(attributeID()));
134 std::string _attr_name = myAttributeID;
135 double _X = aPoint->x();
136 double _Y = aPoint->y();
138 bool isBlocked = this->blockSignals(true);
139 myXSpin->setValue(aPoint->x());
140 myYSpin->setValue(aPoint->y());
141 this->blockSignals(isBlocked);
145 QWidget* ModuleBase_WidgetPoint2D::getControl() const
150 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
152 QList<QWidget*> aControls;
153 aControls.push_back(myXSpin);
154 aControls.push_back(myYSpin);
159 bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
161 if (myOptionParam.length() == 0)
163 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
164 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
165 aData->attribute(myOptionParam));
167 bool isBlocked = this->blockSignals(true);
168 myXSpin->setValue(aPoint->x());
169 myYSpin->setValue(aPoint->y());
170 this->blockSignals(isBlocked);
172 emit valuesChanged();
173 emit storedPoint2D(theObject, myOptionParam);