From f1d282c089ece0e49e4ca1e4cde572a59560df9d Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 17 Mar 2015 16:47:17 +0300 Subject: [PATCH] Multi-selection widget to be used in the extrusion feature. Code improvement. --- .../ModuleBase_WidgetShapeSelector.cpp | 42 +++++++++---------- .../ModuleBase_WidgetShapeSelector.h | 3 +- src/PartSet/PartSet_Validators.cpp | 27 ++---------- 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index b125a7be8..bd7db67b2 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -224,7 +224,7 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue) { ObjectPtr aObject = theValue.object(); - ObjectPtr aCurrentObject = getObject(); + ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID())); if ((!aCurrentObject) && (!aObject)) return false; @@ -338,32 +338,29 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptrdata(); - 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(); - } - } + std::string anAttrType = theAttribute->attributeType(); + if (anAttrType == ModelAPI_AttributeRefAttr::type()) { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr != NULL && anAttr->isObject()) + anObject = anAttr->object(); + } + if (anAttrType == ModelAPI_AttributeSelection::type()) { + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr != NULL && anAttr->isInitialized()) + anObject = anAttr->context(); + } + if (anAttrType == ModelAPI_AttributeReference::type()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL && anAttr->isInitialized()) + anObject = anAttr->value(); } return anObject; } + //******************************************************************** GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const { @@ -392,7 +389,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() } } if (!isNameUpdated) { - ObjectPtr anObject = getObject(); + ObjectPtr anObject = getObject(myFeature->attribute(attributeID())); if (anObject.get() != NULL) { std::string aName = anObject->data()->name(); myTextLine->setText(QString::fromStdString(aName)); @@ -471,7 +468,6 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrvalidators(parentID(), attributeID(), aValidators, anArguments); DataPtr aData = myFeature->data(); - //AttributePtr aAttr = aData->attribute(attributeID()); AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); if (aRefAttr) { // 1. saves the previous attribute values diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index c334bdcaf..fe4d0cb49 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -12,6 +12,7 @@ #include "ModuleBase_ViewerFilters.h" #include +#include #include #include @@ -90,7 +91,7 @@ Q_OBJECT // Get the object from the attribute /// \param theObj an object - static ObjectPtr getObject(const AttributePtr& theAttribute) const; + static ObjectPtr getObject(const AttributePtr& theAttribute); public slots: diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 9bda4c9dc..373229f88 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -117,7 +118,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute // 1. check whether the object of the attribute is not among the feature attributes // find the attribute's object - ObjectPtr anObject = getObject(theAttribute); + ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); // check whether the object is not among other feature attributes if (anObject.get() != NULL) { @@ -130,7 +131,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute // the function parameter attribute should be skipped if (anAttr.get() == NULL || anAttr->id() == theAttribute->id()) continue; - ObjectPtr aCurObject = getObject(anAttr); + ObjectPtr aCurObject = ModuleBase_WidgetShapeSelector::getObject(anAttr); if (aCurObject && aCurObject == anObject) return false; } @@ -186,28 +187,6 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& return true; } -ObjectPtr PartSet_DifferentObjectsValidator::getObject(const AttributePtr& theAttribute) const -{ - ObjectPtr anObject; - std::string anAttrType = theAttribute->attributeType(); - if (anAttrType == ModelAPI_AttributeRefAttr::type()) { - AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr != NULL && anAttr->isObject()) - anObject = anAttr->object(); - } - if (anAttrType == ModelAPI_AttributeSelection::type()) { - AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr != NULL && anAttr->isInitialized()) - anObject = anAttr->context(); - } - if (anAttrType == ModelAPI_AttributeReference::type()) { - AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); - if (anAttr.get() != NULL && anAttr->isInitialized()) - anObject = anAttr->value(); - } - return anObject; -} - bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); -- 2.39.2