From: nds Date: Tue, 17 Mar 2015 14:50:53 +0000 (+0300) Subject: Multi-selection widget to be used in the extrusion feature. X-Git-Tag: V_1.1.0~117 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cdfa83cece2461c9b0caa7adf73a1cb78c4dc1e;p=modules%2Fshaper.git Multi-selection widget to be used in the extrusion feature. Crash fix. --- diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index bd7db67b2..7a9c2449d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -380,13 +380,14 @@ GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const void ModuleBase_WidgetShapeSelector::updateSelectionName() { DataPtr aData = myFeature->data(); + if (aData.get() == NULL) + return; + bool isNameUpdated = false; - if (aData.get() != NULL) { - AttributeSelectionPtr aSelect = aData->selection(attributeID()); - if (aSelect) { - myTextLine->setText(QString::fromStdString(aSelect->namingName())); - isNameUpdated = true; - } + AttributeSelectionPtr aSelect = aData->selection(attributeID()); + if (aSelect) { + myTextLine->setText(QString::fromStdString(aSelect->namingName())); + isNameUpdated = true; } if (!isNameUpdated) { ObjectPtr anObject = getObject(myFeature->attribute(attributeID())); @@ -468,44 +469,53 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrvalidators(parentID(), attributeID(), aValidators, anArguments); DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + // 1. make a backup of the previous attribute values + ObjectPtr aPrevObject = getObject(anAttribute); + GeomShapePtr aPrevShape = getShape(); + AttributePtr aPrevAttribute; + bool aPrevIsObject = false; AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); if (aRefAttr) { - // 1. saves the previous attribute values - bool isObject = aRefAttr->isObject(); - ObjectPtr aPrevObject = aRefAttr->object(); - AttributePtr aPrevAttr = aRefAttr->attr(); - - // 2. store the current values, disable the model's update - aData->blockSendAttributeUpdated(true); - storeAttributeValues(theObj, theShape); - - // 3. check the acceptability of the current values - std::list::iterator aValidator = aValidators.begin(); - std::list >::iterator aArgs = anArguments.begin(); - bool aValid = true; - for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) { - const ModelAPI_RefAttrValidator* aAttrValidator = - dynamic_cast(*aValidator); - if (aAttrValidator) { - aValid = aAttrValidator->isValid(aRefAttr, *aArgs); - } + aPrevIsObject = aRefAttr->isObject(); + aPrevAttribute = aRefAttr->attr(); + } + + // 2. store the current values, disable the model's update + aData->blockSendAttributeUpdated(true); + storeAttributeValues(theObj, theShape); + +// 3. check the acceptability of the current values + std::list::iterator aValidator = aValidators.begin(); + std::list >::iterator aArgs = anArguments.begin(); + bool aValid = true; + for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) { + const ModelAPI_RefAttrValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + aValid = aAttrValidator->isValid(anAttribute, *aArgs); } + } - // 4. if the values are not valid, restore the previous values to the attribute - //if (!aValid) { - if (isObject) + // 4. if the values are not valid, restore the previous values to the attribute + storeAttributeValues(aPrevObject, aPrevShape); + if (aRefAttr) { + if (aPrevIsObject) aRefAttr->setObject(aPrevObject); else - aRefAttr->setAttr(aPrevAttr); - //} - // 5. enable the model's update - aData->blockSendAttributeUpdated(false); - //updateObject(myFeature); - - return aValid; + aRefAttr->setAttr(aPrevAttribute); } - // Check the acceptability of the object as attribute + // 5. enable the model's update + aData->blockSendAttributeUpdated(false); + //updateObject(myFeature); + //return aValid; + + if (!aValid) + return false; + +/* // Check the acceptability of the object as attribute std::list::iterator aValidator = aValidators.begin(); std::list >::iterator aArgs = anArguments.begin(); for (; aValidator != aValidators.end(); aValidator++, aArgs++) { @@ -527,6 +537,6 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr