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 bool isImmutable = aPoint->setImmutable(true);
116 std::string _attr_name = myAttributeID;
117 double _X = myXSpin->value();
118 double _Y = myYSpin->value();
120 aPoint->setValue(myXSpin->value(), myYSpin->value());
121 updateObject(myFeature);
122 aPoint->setImmutable(isImmutable);
123 that->blockSignals(isBlocked);
128 bool ModuleBase_WidgetPoint2D::restoreValue()
130 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
131 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
132 aData->attribute(attributeID()));
135 std::string _attr_name = myAttributeID;
136 double _X = aPoint->x();
137 double _Y = aPoint->y();
139 bool isBlocked = this->blockSignals(true);
140 myXSpin->setValue(aPoint->x());
141 myYSpin->setValue(aPoint->y());
142 this->blockSignals(isBlocked);
146 QWidget* ModuleBase_WidgetPoint2D::getControl() const
151 QList<QWidget*> ModuleBase_WidgetPoint2D::getControls() const
153 QList<QWidget*> aControls;
154 aControls.push_back(myXSpin);
155 aControls.push_back(myYSpin);
160 bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
162 if (myOptionParam.length() == 0)
164 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
165 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
166 aData->attribute(myOptionParam));
168 bool isBlocked = this->blockSignals(true);
169 myXSpin->setValue(aPoint->x());
170 myYSpin->setValue(aPoint->y());
171 this->blockSignals(isBlocked);
173 emit valuesChanged();
174 emit storedPoint2D(theObject, myOptionParam);