X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFeatureOrAttribute.cpp;h=cea8d1ec49bc7c75adcb7dacc1131ceaec1d6580;hb=d058dc531b24c5c548fabfc0dbede4506b4e3076;hp=40fb3a52f7bae73bd9c2ce01e3de5dcbb4b2ed85;hpb=96ff1d1fb2acb842cee193f15492de81060a1d58;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index 40fb3a52f..cea8d1ec4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include #include @@ -30,10 +33,10 @@ #include #include -ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) -: ModuleBase_WidgetFeature(theParent, theData, theParentId) +ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetFeature(theParent, theData, theParentId) { } @@ -46,33 +49,19 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa bool isDone = false; if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); if (aFeatureValue) { - boost::shared_ptr aValuePoint = aFeatureValue->point(); ObjectPtr aObject = aFeatureValue->object(); - if (aObject) { - isDone = setObject(aObject, false); + + boost::shared_ptr anAttribute = findAttribute(aFeatureValue); + if (anAttribute) { + isDone = setAttribute(anAttribute, false); } - if (aValuePoint) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (aFeature) { - // find the given point in the feature attributes - std::list > anAttiributes = - aFeature->data()->attributes(GeomDataAPI_Point2D::type()); - std::list >::const_iterator anIt = anAttiributes.begin(), - aLast = anAttiributes.end(); - boost::shared_ptr aFPoint; - for (;anIt!=aLast && !aFPoint; anIt++) { - boost::shared_ptr aCurPoint = - boost::dynamic_pointer_cast(*anIt); - if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) - aFPoint = aCurPoint; - } - if (aFPoint) - isDone = setAttribute(aFPoint, false); - } + else if (aObject) { + isDone = setObject(aObject, false); } + if (isDone) emit valuesChanged(); } @@ -87,8 +76,8 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const // return false; boost::shared_ptr aData = myFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); if (myObject) aRef->setObject(myObject); @@ -104,8 +93,8 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() { boost::shared_ptr aData = myFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); ObjectPtr aObj = aRef->object(); FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); @@ -125,13 +114,62 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() return false; } +boost::shared_ptr ModuleBase_WidgetFeatureOrAttribute::findAttribute( + ModuleBase_WidgetValue* theValue) +{ + boost::shared_ptr anAttribute; + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (!aFeatureValue) + return anAttribute; + + boost::shared_ptr aValuePoint = aFeatureValue->point(); + if (aValuePoint) { + ObjectPtr aObject = aFeatureValue->object(); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature) { + // find the given point in the feature attributes + std::list > anAttiributes = aFeature->data() + ->attributes(GeomDataAPI_Point2D::type()); + std::list >::const_iterator anIt = anAttiributes + .begin(), aLast = anAttiributes.end(); + for (; anIt != aLast && !anAttribute; anIt++) { + boost::shared_ptr aCurPoint = boost::dynamic_pointer_cast< + GeomDataAPI_Point2D>(*anIt); + if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) + anAttribute = aCurPoint; + } + } + } + return anAttribute; +} + bool ModuleBase_WidgetFeatureOrAttribute::setAttribute( - const boost::shared_ptr& theAttribute, - bool theSendEvent) + const boost::shared_ptr& theAttribute, bool theSendEvent) { - if (!theAttribute)// || !featureKinds().contains(theAttribute->attributeType().c_str())) + if (!theAttribute) // || !featureKinds().contains(theAttribute->attributeType().c_str())) return false; + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + std::list > anArguments; + aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + // Check the acceptability of the attribute + std::list::iterator aValidator = aValidators.begin(); + int aSize = aValidators.size(); + std::list >::iterator aArgs = anArguments.begin(); + for (; aValidator != aValidators.end(); aValidator++, aArgs++) { + const ModelAPI_RefAttrValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theAttribute)) { + return false; + } + } + } + myAttribute = theAttribute; editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : ""); if (theSendEvent)