Salome HOME
Fix sketcher bugs
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeature.cpp
index d1e2ceea66fc30ea0734f2fd7f534ec6167391da..b08058a604c24e3c68ecce8bd6a3f18730ae5c7a 100644 (file)
@@ -6,17 +6,19 @@
 
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
+#include <ModuleBase_ResultValidators.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Validator.h>
 
 #include <QWidget>
 #include <QLineEdit>
 #include <QLabel>
 
 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
-                                                   const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)
+                                                   const Config_WidgetAPI* theData, 
+                                                   const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
-  QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
-  myFeatureKinds = aKinds.split(" ");
+  //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
+  //myObjectKinds = aKinds.split(" ");
+  //theData->
 
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
@@ -63,45 +67,60 @@ bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
     ModuleBase_WidgetValueFeature* aFeatureValue = 
                          dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
     if (aFeatureValue)
-      isDone = setFeature(aFeatureValue->feature());
+      isDone = setObject(aFeatureValue->object());
   }
   return isDone;
 }
 
-bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
+bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject)
 {
-  if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
-    return false;
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  const ModelAPI_Validator* aValidator = aFactory->validator(parentID(), attributeID());
+  if (aValidator) {
+    const ModuleBase_ResultValidator* aResValidator = 
+      dynamic_cast<const ModuleBase_ResultValidator*>(aValidator);
+    if (aResValidator) {
+      if (!aResValidator->isValid(theObject))
+        return false;
+    }
+  }
 
-  myFeature = theFeature;
-  myEditor->setText(theFeature ? theFeature->data()->getName().c_str() : "");
+  myObject = theObject;
+  myEditor->setText(theObject ? theObject->data()->name().c_str() : "");
   emit valuesChanged();
   return true;
 }
 
-bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (!aFeature)
+    return false;
+  boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
   ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
-  aRef->setFeature(myFeature);
-  theFeature->execute();
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-
+  aRef->setObject(myObject);
+  aFeature->execute();
+  updateObject(theObject);
   return true;
 }
 
-bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
-  myFeature = aRef->feature();
-  myEditor->setText(myFeature ? myFeature->data()->getName().c_str() : "");
-  return true;
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
+  if (aFeature) {
+    myObject = aFeature;
+    myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
+    return true;
+  }
+  return false;
 }
 
 QWidget* ModuleBase_WidgetFeature::getControl() const