Salome HOME
registerNotObligatory is not necessary if this property is set in XML.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.cpp
index c5be67919c214a1eca31ed60a5e52eb68b83ad39..8aed922a3b728e1e29430149f1c20528c3a0260e 100755 (executable)
@@ -9,6 +9,10 @@
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_IModule.h>
 
 #include <ModelAPI_ResultConstruction.h>
 
@@ -54,6 +58,9 @@ void ModuleBase_WidgetSelector::onSelectionChanged()
   // calls validators for the feature and, as a result, updates the Apply button state.
   updateObject(myFeature);
 
+  // we need to forget about previous validation result as the current selection can influence on it
+  clearValidatedCash();
+
   if (isDone)
     updateFocus();
 }
@@ -150,6 +157,17 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr
   return aValid;
 }
 
+//********************************************************************
+bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  getGeomSelection(thePrs, anObject, aShape);
+
+  setObject(anObject, aShape);
+  return true;
+}
+
 //********************************************************************
 void ModuleBase_WidgetSelector::deactivate()
 {
@@ -160,13 +178,26 @@ void ModuleBase_WidgetSelector::deactivate()
 }
 
 //********************************************************************
-std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttribute)
+std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttribute,
+                                                    ModuleBase_IWorkshop* theWorkshop)
 {
   std::string aName;
   if (theAttribute.get() != NULL) {
-    std::stringstream aStreamName;
-    aStreamName << theAttribute->owner()->data()->name() << "/"<< theAttribute->id();
-    aName = aStreamName.str();
+    ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
+
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+    if (aFeature.get()) {
+      std::string aXmlCfg, aDescription;
+      theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
+
+      ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
+      std::string anAttributeTitle;
+      aFactory.getAttributeTitle(aFeature->getKind(), theAttribute->id(), anAttributeTitle);
+
+      std::stringstream aStreamName;
+      aStreamName << theAttribute->owner()->data()->name() << "/"<< anAttributeTitle.c_str();
+      aName = aStreamName.str();
+    }
   }
   return aName;
 }