]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Multi-selection widget to be used in the extrusion feature.
authornds <natalia.donis@opencascade.com>
Tue, 17 Mar 2015 09:18:47 +0000 (12:18 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 17 Mar 2015 09:18:47 +0000 (12:18 +0300)
Sepate the method storeValueCustom on two methods - to change an attribute and update the object.
The method to change attribute without object's update is necessary for isValid functionality

src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h

index 9f9cd941dece9e56d513763868ecb75f3addc4fa..335d5046d240ee4f3b160f6fd25e83991d20b07f 100644 (file)
@@ -127,39 +127,47 @@ ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
 {
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  bool isStored = storeAttributeValues(mySelectedObject, myShape);
+  if (isStored)
+    updateObject(myFeature);
+  return isStored;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject,
+                                                          GeomShapePtr theShape) const
+{
+  bool isChanged = false;
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
   if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
-    return false;
+    return isChanged;
 
   DataPtr aData = myFeature->data();
   AttributeReferencePtr aRef = aData->reference(attributeID());
   if (aRef) {
     ObjectPtr aObject = aRef->value();
-    if (!(aObject && aObject->isSame(mySelectedObject))) {
-      aRef->setValue(mySelectedObject);
-      updateObject(myFeature);
-      return true;
+    if (!(aObject && aObject->isSame(theSelectedObject))) {
+      aRef->setValue(theSelectedObject);
+      isChanged = true;
     }
   } else {
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
     if (aRefAttr) {
       ObjectPtr aObject = aRefAttr->object();
-      if (!(aObject && aObject->isSame(mySelectedObject))) {
-        aRefAttr->setObject(mySelectedObject);
-        updateObject(myFeature);
-        return true;
+      if (!(aObject && aObject->isSame(theSelectedObject))) {
+        aRefAttr->setObject(theSelectedObject);
+        isChanged = true;
       }
     } else {
       AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
-      ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
-      if (aSelectAttr && aBody && (myShape.get() != NULL)) {
-        aSelectAttr->setValue(aBody, myShape);
-        updateObject(myFeature);
-        return true;
+      ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+      if (aSelectAttr && aBody && (theShape.get() != NULL)) {
+        aSelectAttr->setValue(aBody, theShape);
+        isChanged = true;
       }
     }
   }
-  return false;
+  return isChanged;
 }
 
 //********************************************************************
@@ -451,9 +459,7 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
     ObjectPtr aPrevSelectedObject = mySelectedObject;
     GeomShapePtr aPrevShape = myShape;
 
-    mySelectedObject = theObj;
-    myShape = theShape;
-    storeValueCustom();
+    storeAttributeValues(theObj, theShape);
 
     // 3. check the acceptability of the current values
     std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
@@ -469,8 +475,6 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
 
     // 4. if the values are not valid, restore the previous values to the attribute
     //if (!aValid) {
-    mySelectedObject = aPrevSelectedObject;
-    myShape = aPrevShape;
     if (isObject)
       aRefAttr->setObject(aPrevObject);
     else
index f4be3ab69ffa2499beb27462788a3bc7ea937a27..54b928ee86a4e6a547197f4a773078ad9bbce094 100644 (file)
@@ -136,8 +136,14 @@ Q_OBJECT
   /// Clear attribute
   void clearAttribute();
 
+  /// Store the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+
   //----------- Class members -------------
- protected:
 protected:
   /// Label of the widget
   QLabel* myLabel;
 
index 5e1ebe9239d74d799661e2955ee3f051ba1e64f5..1c99b1f4f5744ffc2c983d0d404253d298fd848c 100644 (file)
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
-
-//*********************************************
-bool PartSet_WidgetConstraintShapeSelector::storeValueCustom() const
+bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
 {
-  FeaturePtr aFeature = ModelAPI_Feature::feature(mySelectedObject);
+  ObjectPtr aSelectedObject = theSelectedObject;
+  GeomShapePtr aShape = theShape;
+
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
   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>(),
-                                                                  mySelectedObject, mySketch);
+                                                                  aSelectedObject, mySketch);
       if (aObj) {
         PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
-        that->mySelectedObject = aObj;
+        aSelectedObject = aObj;
       } else 
         return false;
     }
   }
-  return ModuleBase_WidgetShapeSelector::storeValueCustom();
+  return ModuleBase_WidgetShapeSelector::storeAttributeValues(theSelectedObject, theShape);
 }
index 900e4ce3026d6c54b6178c97bad51d2538cb2e75..29ca68dafd55b2ae67611c81cc77d4765e8cdec8 100644 (file)
@@ -43,9 +43,11 @@ Q_OBJECT
   CompositeFeaturePtr sketch() const { return mySketch; }
 
 protected:
-  /// Saves the internal parameters to the given feature
-  /// \return True in success
-  virtual bool storeValueCustom() const;
+  /// Store the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
 
 private:
   /// Pointer to a sketch 
index 422be37e10068822241b816152f5da45be9b2eb9..44962e5908797247b8fa9ee32d351d5ae0844587 100644 (file)
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
-
-bool PartSet_WidgetShapeSelector::storeValueCustom() const
+bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
 {
-  if (!mySelectedObject)
+  ObjectPtr aSelectedObject = theSelectedObject;
+  GeomShapePtr aShape = theShape;
+
+  if (!aSelectedObject)
     return false;
 
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
   if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
     return false;
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-  if ((!aSPFeature) && (!myShape->isNull())) {
+  if ((!aSPFeature) && (!aShape->isNull())) {
     // Processing of external (non-sketch) object
-    ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
-                                                                mySelectedObject, mySketch);
+    ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl<TopoDS_Shape>(),
+                                                                aSelectedObject, mySketch);
     if (aObj) {
       PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
-      that->mySelectedObject = aObj;
+      aSelectedObject = aObj;
     } else 
       return false;
   } else {
     // Processing of sketch object
     DataPtr aData = myFeature->data();
-    if (myShape) {
+    if (aShape) {
       AttributePtr aAttr = aData->attribute(attributeID());
       AttributeRefAttrPtr aRefAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
       if (aRefAttr) {
-        TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
-        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+        TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
+        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aSelectedObject, aTDSShape, mySketch);
 
         // this is an alternative, whether the attribute should be set or object in the attribute
         // the first check is the attribute because the object already exist
@@ -52,13 +54,14 @@ bool PartSet_WidgetShapeSelector::storeValueCustom() const
         // test case is - preselection for distance operation, which contains two points selected on lines
         if (aPntAttr)
           aRefAttr->setAttr(aPntAttr);
-        else if (mySelectedObject)
-          aRefAttr->setObject(mySelectedObject);
-        updateObject(myFeature);
+        else if (aSelectedObject)
+          aRefAttr->setObject(aSelectedObject);
+        //updateObject(myFeature);
         return true;
       }
     }
   }
-  return ModuleBase_WidgetShapeSelector::storeValueCustom();
+  return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, aShape);
 }
 
+
index 503625684600dfea75e76b5eec45ea16af4d8190..bae13ae921be71b9add95ce466d7746dd707adf1 100644 (file)
@@ -43,9 +43,11 @@ Q_OBJECT
   CompositeFeaturePtr sketch() const { return mySketch; }
 
 protected:
-  /// Saves the internal parameters to the given feature
-  /// \return True in success
-  virtual bool storeValueCustom() const;
+  /// Store the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
 
 private:
   /// Pointer to a sketch