Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeature.cpp
1 // File:        ModuleBase_WidgetFeature.cpp
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <ModuleBase_WidgetFeature.h>
6
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
9
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
12
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_AttributeRefAttr.h>
17
18 #include <QWidget>
19
20 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
21                                                    const Config_WidgetAPI* theData)
22 : ModuleBase_ModelWidget(theParent, theData)
23 {
24   QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
25   myFeatureKinds = aKinds.split(" ");
26 }
27
28 ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
29 {
30 }
31
32 bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
33 {
34   if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
35     return false;
36
37   //bool isBlocked = this->blockSignals(true);
38   myFeature = theFeature;
39   //this->blockSignals(isBlocked);
40   emit valuesChanged();
41   return true;
42 }
43
44 bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
45 {
46   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
47   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
48           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
49
50   ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
51   //bool isBlocked = that->blockSignals(true);
52   aRef->setFeature(myFeature);
53   theFeature->execute();
54   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
55   //that->blockSignals(isBlocked);
56
57   return true;
58 }
59
60 bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
61 {
62   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
63   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
64           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
65
66   //bool isBlocked = this->blockSignals(true);
67   myFeature = aRef->feature();
68   //this->blockSignals(isBlocked);
69   return true;
70 }
71
72 QWidget* ModuleBase_WidgetFeature::getControl() const
73 {
74   return 0;
75 }
76
77 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
78 {
79   QList<QWidget*> aControls;
80   return aControls;
81 }