From: nds Date: Tue, 17 Mar 2015 09:18:47 +0000 (+0300) Subject: Multi-selection widget to be used in the extrusion feature. X-Git-Tag: V_1.1.0~124 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=90031a393623d09c62d33690830010f1cc3ab6e3;p=modules%2Fshaper.git Multi-selection widget to be used in the extrusion feature. 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 --- diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 9f9cd941d..335d5046d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -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(mySelectedObject); - if (aSelectAttr && aBody && (myShape.get() != NULL)) { - aSelectAttr->setValue(aBody, myShape); - updateObject(myFeature); - return true; + ResultPtr aBody = std::dynamic_pointer_cast(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::iterator aValidator = aValidators.begin(); @@ -469,8 +475,6 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrsetObject(aPrevObject); else diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index f4be3ab69..54b928ee8 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -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; diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp index 5e1ebe923..1c99b1f4f 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp @@ -12,23 +12,24 @@ #include #include - -//********************************************* -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 aSPFeature = std::dynamic_pointer_cast(aFeature); if ((!aSPFeature) && (!myShape->isNull())) { ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl(), - 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); } diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.h b/src/PartSet/PartSet_WidgetConstraintShapeSelector.h index 900e4ce30..29ca68daf 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.h +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.h @@ -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 diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 422be37e1..44962e590 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -15,36 +15,38 @@ #include #include - -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 aSPFeature = std::dynamic_pointer_cast(aSelectedFeature); - if ((!aSPFeature) && (!myShape->isNull())) { + if ((!aSPFeature) && (!aShape->isNull())) { // Processing of external (non-sketch) object - ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl(), - mySelectedObject, mySketch); + ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl(), + 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(aAttr); if (aRefAttr) { - TopoDS_Shape aShape = myShape->impl(); - AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch); + TopoDS_Shape aTDSShape = aShape->impl(); + 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); } + diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index 503625684..bae13ae92 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -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