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
//********************************************************************
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;
}
//********************************************************************
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();
// 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
/// 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;
#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);
}
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
#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
// 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);
}
+
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