X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFeatureOrAttribute.cpp;h=d9674c4d45d7e0856c33fed4b493c160f280f8f8;hb=9d08fda0173567e0b8f1232a9dabb330fdeffe0f;hp=4ff9ab84b52227c625efc4620d7baa002dcb4549;hpb=a0e93f487500aca7d440c6e527867289c486fa32;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index 4ff9ab84b..d9674c4d4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -11,12 +11,14 @@ #include #include -#include +#include #include #include #include #include +#include + #include #include @@ -28,9 +30,10 @@ #include #include -ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, - const Config_WidgetAPI* theData) -: ModuleBase_WidgetFeature(theParent, theData) +ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetFeature(theParent, theData, theParentId) { } @@ -43,83 +46,95 @@ 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(); - FeaturePtr aValueFeature = aFeatureValue->feature(); - if (aValuePoint && aValueFeature) { - if (aValueFeature) { - isDone = setFeature(aValueFeature); - } - if (!isDone) { + ObjectPtr aObject = aFeatureValue->object(); + if (aObject) { + isDone = setObject(aObject, false); + } + if (aValuePoint) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature) { // find the given point in the feature attributes - std::list > anAttiributes = - aValueFeature->data()->attributes(GeomDataAPI_Point2D::type()); - std::list >::const_iterator anIt = anAttiributes.begin(), - aLast = anAttiributes.end(); + 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); + for (; anIt != aLast && !aFPoint; anIt++) { + boost::shared_ptr aCurPoint = boost::dynamic_pointer_cast< + GeomDataAPI_Point2D>(*anIt); if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) aFPoint = aCurPoint; } if (aFPoint) - isDone = setAttribute(aFPoint); + isDone = setAttribute(aFPoint, false); } } + if (isDone) + emit valuesChanged(); } } return isDone; } -bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) const +bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); - - ModuleBase_WidgetFeatureOrAttribute* that = (ModuleBase_WidgetFeatureOrAttribute*) this; - if (feature()) - aRef->setFeature(feature()); - else if (myAttribute) + //FeaturePtr aFeature = boost::dynamic_pointer_cast(theFeature); + //if (!aFeature) + // return false; + + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); + + if (myObject) + aRef->setObject(myObject); + if (myAttribute) aRef->setAttr(myAttribute); - theFeature->execute(); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + myFeature->execute(); + updateObject(myFeature); return true; } -bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature) +bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() { - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); - - FeaturePtr aFeature = aRef->feature(); - setFeature(aFeature); - myAttribute = aRef->attr(); - - std::string aText = ""; - if (aFeature) - aText = aFeature->data()->getName().c_str(); - else if (myAttribute) - aText = myAttribute->attributeType().c_str(); - - editor()->setText(aText.c_str()); - return true; + boost::shared_ptr aData = myFeature->data(); + boost::shared_ptr aRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); + + ObjectPtr aObj = aRef->object(); + FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); + if (aFeature) { + myObject = aFeature; + myAttribute = aRef->attr(); + + std::string aText = ""; + if (aFeature) + aText = aFeature->data()->name().c_str(); + if (myAttribute) + aText = myAttribute->attributeType().c_str(); + + editor()->setText(aText.c_str()); + return true; + } + return false; } -bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr& theAttribute) +bool ModuleBase_WidgetFeatureOrAttribute::setAttribute( + 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; myAttribute = theAttribute; editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : ""); - emit valuesChanged(); + if (theSendEvent) + emit valuesChanged(); return true; }