Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeatureOrAttribute.cpp
index 9a47f92319f81213ac7b5163eefcbb7f8d55f52b..633adbc439e22e36df7a632acd878b5fd734b47d 100644 (file)
@@ -11,7 +11,7 @@
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
@@ -29,8 +29,9 @@
 #include <QLabel>
 
 ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent,
-                                                   const Config_WidgetAPI* theData)
-: ModuleBase_WidgetFeature(theParent, theData)
+                                                   const Config_WidgetAPI* theData, 
+                                                   const std::string& theParentId)
+: ModuleBase_WidgetFeature(theParent, theData, theParentId)
 {
 }
 
@@ -47,12 +48,11 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa
                          dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
     if (aFeatureValue) {
       boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
-      FeaturePtr aValueFeature = aFeatureValue->feature();
-
+      ObjectPtr aValueFeature = aFeatureValue->object();
       if (aValueFeature) {
-        isDone = setFeature(aValueFeature);
+        isDone = setObject(aValueFeature);
       }
-      if (!isDone) {
+      if (!isDone && aValuePoint) {
         // find the given point in the feature attributes
         std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
                                       aValueFeature->data()->attributes(GeomDataAPI_Point2D::type());
@@ -80,13 +80,13 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) cons
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
   ModuleBase_WidgetFeatureOrAttribute* that = (ModuleBase_WidgetFeatureOrAttribute*) this;
-  if (feature())
-    aRef->setFeature(feature());
+  if (object())
+    aRef->setObject(object());
   else if (myAttribute)
     aRef->setAttr(myAttribute);
 
   theFeature->execute();
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
 
   return true;
 }
@@ -97,18 +97,21 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature)
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
-  FeaturePtr aFeature = aRef->feature();
-  setFeature(aFeature);
-  myAttribute = aRef->attr();
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
+  if (aFeature) {
+    setObject(aFeature);
+    myAttribute = aRef->attr();
 
-  std::string aText = "";
-  if (aFeature)
-    aText = aFeature->data()->getName().c_str();
-  else if (myAttribute)
-    aText = myAttribute->attributeType().c_str();
+    std::string aText = "";
+    if (aFeature)
+      aText = aFeature->data()->name().c_str();
+    else if (myAttribute)
+      aText = myAttribute->attributeType().c_str();
 
-  editor()->setText(aText.c_str());
-  return true;
+    editor()->setText(aText.c_str());
+    return true;
+  }
+  return false;
 }
 
 bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr<ModelAPI_Attribute>& theAttribute)