Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authornds <natalia.donis@opencascade.com>
Tue, 17 Mar 2015 13:22:17 +0000 (16:22 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 17 Mar 2015 13:22:17 +0000 (16:22 +0300)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp

index 335d5046d240ee4f3b160f6fd25e83991d20b07f..b125a7be8c7731e0017dd20f6d31632b8512e603 100644 (file)
@@ -127,10 +127,8 @@ ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
 {
-  bool isStored = storeAttributeValues(mySelectedObject, myShape);
-  if (isStored)
-    updateObject(myFeature);
-  return isStored;
+  // the value is stored on the selection changed signal processing 
+  return true;
 }
 
 //********************************************************************
@@ -193,27 +191,10 @@ void ModuleBase_WidgetShapeSelector::clearAttribute()
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::restoreValue()
 {
-  DataPtr aData = myFeature->data();
   bool isBlocked = this->blockSignals(true);
-
-  AttributeSelectionPtr aSelect = aData->selection(attributeID());
-  if (aSelect) {
-    mySelectedObject = aSelect->context();
-    myShape = aSelect->value();
-  } else {
-    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      mySelectedObject = aRefAttr->object();
-    } else {
-      AttributeReferencePtr aRef = aData->reference(attributeID());
-      if (aRef) {
-        mySelectedObject = aRef->value();
-      }
-    }
-  }
   updateSelectionName();
-
   this->blockSignals(isBlocked);
+
   return true;
 }
 
@@ -243,7 +224,8 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
 bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
 {
   ObjectPtr aObject = theValue.object();
-  if ((!mySelectedObject) && (!aObject))
+  ObjectPtr aCurrentObject = getObject();
+  if ((!aCurrentObject) && (!aObject))
     return false;
 
   // Check that the selected object is result (others can not be accepted)
@@ -305,9 +287,10 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
 {
-  mySelectedObject = theObj;
-  myShape = theShape;
-  if (mySelectedObject) {
+  if (storeAttributeValues(theObj, theShape))
+    updateObject(myFeature);
+
+  if (theObj) {
     raisePanel();
   } 
   updateSelectionName();
@@ -355,6 +338,47 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shap
   return false;
 }
 
+//********************************************************************
+ObjectPtr ModuleBase_WidgetShapeSelector::getObject() const
+{
+  ObjectPtr anObject;
+
+  DataPtr aData = myFeature->data();
+  if (aData.get() == NULL)
+    return anObject;
+
+  AttributeSelectionPtr aSelect = aData->selection(attributeID());
+  if (aSelect) {
+    anObject = aSelect->context();
+  } else {
+    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+    if (aRefAttr) {
+      anObject = aRefAttr->object();
+    } else {
+      AttributeReferencePtr aRef = aData->reference(attributeID());
+      if (aRef) {
+        anObject = aRef->value();
+      }
+    }
+  }
+  return anObject;
+}
+
+//********************************************************************
+GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
+{
+  GeomShapePtr aShape;
+  DataPtr aData = myFeature->data();
+  if (aData.get() == NULL)
+    return aShape;
+
+  AttributeSelectionPtr aSelect = aData->selection(attributeID());
+  if (aSelect)
+    aShape = aSelect->value();
+
+  return aShape;
+}
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::updateSelectionName()
 {
@@ -368,8 +392,9 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
     }
   }
   if (!isNameUpdated) {
-    if (mySelectedObject) {
-      std::string aName = mySelectedObject->data()->name();
+    ObjectPtr anObject = getObject();
+    if (anObject.get() != NULL) {
+      std::string aName = anObject->data()->name();
       myTextLine->setText(QString::fromStdString(aName));
     } else {
       if (myIsActive) {
@@ -456,9 +481,6 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
 
     // 2. store the current values, disable the model's update
     aData->blockSendAttributeUpdated(true);
-    ObjectPtr aPrevSelectedObject = mySelectedObject;
-    GeomShapePtr aPrevShape = myShape;
-
     storeAttributeValues(theObj, theShape);
 
     // 3. check the acceptability of the current values
index 54b928ee86a4e6a547197f4a773078ad9bbce094..c334bdcaf0542b4f706bd88c48d22b07a9a28b2d 100644 (file)
@@ -80,21 +80,17 @@ Q_OBJECT
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
-  /// Returns currently selected data object
-  ObjectPtr selectedFeature() const
-  {
-    return mySelectedObject;
-  }
-
   /// Set the given wrapped value to the current widget
   /// This value should be processed in the widget according to the needs
   /// \param theValue the wrapped widget value
   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
 
-
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
+  // Get the object from the attribute
+  /// \param theObj an object 
+  static ObjectPtr getObject(const AttributePtr& theAttribute) const;
 
  public slots:
 
@@ -128,6 +124,10 @@ Q_OBJECT
   /// \param theShape a shape
   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
 
+  // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
+  /// \return a shape
+  GeomShapePtr getShape() const;
+
   /// Check the selected with validators if installed
   /// \param theObj the object for checking
   /// \param theShape the shape for checking
@@ -153,12 +153,6 @@ Q_OBJECT
   /// Reference to workshop
   ModuleBase_IWorkshop* myWorkshop;
 
-  /// Pointer to selected object
-  ObjectPtr mySelectedObject;
-
-  /// Pointer to selected shape
-  GeomShapePtr myShape;
-
   /// List of accepting shapes types
   QStringList myShapeTypes;
 
index 1c99b1f4f5744ffc2c983d0d404253d298fd848c..405fc74b5b40d17ecdf5deeef1b7167f614480c4 100644 (file)
@@ -21,8 +21,8 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe
   if (aFeature) {
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-    if ((!aSPFeature) && (!myShape->isNull())) {
-      ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
+    if ((!aSPFeature) && (!theShape->isNull())) {
+      ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
                                                                   aSelectedObject, mySketch);
       if (aObj) {
         PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;