Salome HOME
Rectangle correction to have coincidence with point/line selected for the first point...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.cpp
index e062d4f096e28ba2bb3a098a36247f265790c10c..b68e282b69630d35b31d42bb8790a3f5064adf2e 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Filter.h>
+#include <ModuleBase_IModule.h>
 
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
@@ -120,9 +121,15 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
     }
   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    ObjectPtr aObject = aRefAttr->object();
-    if (!(aObject && aObject->isSame(theSelectedObject))) {
-      aRefAttr->setObject(theSelectedObject);
+
+    AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
+    if (anAttribute.get())
+      aRefAttr->setAttr(anAttribute);
+    else {
+      ObjectPtr aObject = aRefAttr->object();
+      if (!(aObject && aObject->isSame(theSelectedObject))) {
+        aRefAttr->setObject(theSelectedObject);
+      }
     }
   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
     AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
@@ -153,13 +160,6 @@ QList<ModuleBase_ViewerPrs> ModuleBase_WidgetShapeSelector::getAttributeSelectio
   return aSelected;
 }
 
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::clearAttribute()
-{
-  // In order to make reselection possible, set empty object and shape should be done
-  setObject(ObjectPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
-}
-
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::restoreValueCustom()
 {
@@ -201,9 +201,18 @@ GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
   if (!aData->isValid())
     return aShape;
 
-  AttributeSelectionPtr aSelect = aData->selection(attributeID());
-  if (aSelect)
-    aShape = aSelect->value();
+  std::string aType = aData->attribute(attributeID())->attributeType();
+  if (aType == ModelAPI_AttributeReference::typeId()) {
+  } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
+    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+    if (aRefAttr.get() && !aRefAttr->isObject()) {
+      AttributePtr anAttribute = aRefAttr->attr();
+      aShape = myWorkshop->module()->findShape(anAttribute);
+    }
+  } else if (aType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
+    aShape = aSelectAttr->value();
+  }
 
   return aShape;
 }
@@ -230,7 +239,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
       AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
       if (aRefAttr && aRefAttr->attr().get() != NULL) {
         //myIsObject = aRefAttr->isObject();
-        std::string anAttrName = generateName(aRefAttr->attr());
+        std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop);
         myTextLine->setText(QString::fromStdString(anAttrName));
       }
       else {
@@ -274,14 +283,3 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
       aRefAttr->setAttr(myRefAttribute);
   }
 }
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
-  ObjectPtr anObject;
-  GeomShapePtr aShape;
-  getGeomSelection(thePrs, anObject, aShape);
-
-  setObject(anObject, aShape);
-  return true;
-}