From: nds Date: Thu, 21 Jan 2016 09:18:25 +0000 (+0300) Subject: correction of Model_Data for AttributeRefAttrList X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=35d50542ffbfe2781839c60f0ff16fd44fe4e998;p=modules%2Fshaper.git correction of Model_Data for AttributeRefAttrList --- diff --git a/src/Model/Model_AttributeRefAttrList.h b/src/Model/Model_AttributeRefAttrList.h index 0d36c383e..2e666db26 100755 --- a/src/Model/Model_AttributeRefAttrList.h +++ b/src/Model/Model_AttributeRefAttrList.h @@ -60,7 +60,7 @@ class Model_AttributeRefAttrList : public ModelAPI_AttributeRefAttrList MODEL_EXPORT virtual AttributePtr attribute(const int theIndex) const; /// Removes the last element in the list. - MODEL_EXPORT virtual void removeLast() = 0; + MODEL_EXPORT virtual void removeLast(); /// Removes the elements from the list. /// \param theIndices a list of indices of elements to be removed diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 067b3c6df..530293b7e 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,8 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin anAttr = new Model_AttributeRefAttr(anAttrLab); } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) { anAttr = new Model_AttributeRefList(anAttrLab); + } else if (theAttrType == ModelAPI_AttributeRefAttrList::typeId()) { + anAttr = new Model_AttributeRefAttrList(anAttrLab); } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) { anAttr = new Model_AttributeIntArray(anAttrLab); } @@ -202,6 +205,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist); +GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray); std::shared_ptr Model_Data::attribute(const std::string& theID) @@ -525,6 +529,15 @@ void Model_Data::referencesToObjects( for(int a = aRef->size() - 1; a >= 0; a--) { aReferenced.push_back(aRef->value(a)->context()); } + } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + std::shared_ptr aRefAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttrList>(anAttr->second); + std::list > aRefs = aRefAttr->list(); + std::list >::const_iterator anIt = aRefs.begin(), + aLast = aRefs.end(); + for (; anIt != aLast; anIt++) { + aReferenced.push_back(anIt->first); + } } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(anAttr->second); diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index ec219f552..8f8cfe515 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -103,6 +104,10 @@ class Model_Data : public ModelAPI_Data /// Returns the attribute that contains list of references to features MODEL_EXPORT virtual std::shared_ptr reflist(const std::string& theID); + /// Returns the attribute that contains list of references to features + /// or reference to an attribute of a feature + MODEL_EXPORT virtual std::shared_ptr + refattrlist(const std::string& theID); /// Returns the attribute that contains boolean value MODEL_EXPORT virtual std::shared_ptr boolean(const std::string& theID); diff --git a/src/ModelAPI/ModelAPI_AttributeRefAttrList.h b/src/ModelAPI/ModelAPI_AttributeRefAttrList.h index 633bcb54d..cd011712a 100755 --- a/src/ModelAPI/ModelAPI_AttributeRefAttrList.h +++ b/src/ModelAPI/ModelAPI_AttributeRefAttrList.h @@ -43,8 +43,7 @@ class ModelAPI_AttributeRefAttrList : public ModelAPI_Attribute virtual void clear() = 0; /// Returns number of features in the list - ///\param theWithEmpty if it is false, returns the number of not-empty referenced objects - virtual int size(const bool theWithEmpty = true) const = 0; + virtual int size() const = 0; /// Returns the list of features and attributes (if it is reference to the attribute) virtual std::list > list() = 0; diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index c95998206..05dc2be64 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -24,6 +24,7 @@ class ModelAPI_AttributeDouble; class ModelAPI_AttributeReference; class ModelAPI_AttributeRefAttr; class ModelAPI_AttributeRefList; +class ModelAPI_AttributeRefAttrList; class ModelAPI_AttributeBoolean; class ModelAPI_AttributeString; class ModelAPI_Document; @@ -77,6 +78,9 @@ class MODELAPI_EXPORT ModelAPI_Data virtual std::shared_ptr refattr(const std::string& theID) = 0; /// Returns the attribute that contains list of references to features virtual std::shared_ptr reflist(const std::string& theID) = 0; + /// Returns the attribute that contains list of references to features or reference to + /// an attribute of a feature + virtual std::shared_ptr refattrlist(const std::string& theID) = 0; /// Returns the attribute that contains boolean value virtual std::shared_ptr boolean(const std::string& theID) = 0; /// Returns the attribute that contains boolean value diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 28d40d282..c8250969a 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -247,9 +247,8 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); std::string aType = anAttribute->attributeType(); if (aType == ModelAPI_AttributeRefAttrList::typeId()) { - AttributeRefAttrListPtr aRefAttrListAttr = + AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast(anAttribute); - bool isDone = false; if (!thePrs.shape().IsNull()) { GeomShapePtr aGeomShape = std::shared_ptr(new GeomAPI_Shape); @@ -261,15 +260,21 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP isDone = true; } } - if (!isDone) - ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + if (!isDone) { + //ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); + setObject(anObject, aShape); + } } else { - ModuleBase_WidgetSelector::setSelectionCustom(thePrs); - /*ObjectPtr anObject; + //ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + + ObjectPtr anObject; GeomShapePtr aShape; getGeomSelection(thePrs, anObject, aShape); - setObject(anObject, aShape);*/ + setObject(anObject, aShape); } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 0f0b2c15a..c5be67919 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -150,17 +150,6 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr return aValid; } -//******************************************************************** -bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - - setObject(anObject, aShape); - return true; -} - //******************************************************************** void ModuleBase_WidgetSelector::deactivate() { diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 150a0ce34..8a282c362 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -51,10 +51,6 @@ Q_OBJECT /// \return a boolean value virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// Fills the attribute with the value of the selected owner - /// \param thePrs a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// The methiod called when widget is deactivated virtual void deactivate(); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index a51e16be6..e062d4f09 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -111,25 +111,24 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) { DataPtr aData = myFeature->data(); - AttributeReferencePtr aRef = aData->reference(attributeID()); - if (aRef) { + std::string aType = aData->attribute(attributeID())->attributeType(); + if (aType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr aRef = aData->reference(attributeID()); ObjectPtr aObject = aRef->value(); if (!(aObject && aObject->isSame(theSelectedObject))) { aRef->setValue(theSelectedObject); } - } else { + } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRefAttr->setObject(theSelectedObject); - } - } else { - AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aSelectAttr.get() != NULL) { - aSelectAttr->setValue(aResult, theShape); - } + ObjectPtr aObject = aRefAttr->object(); + if (!(aObject && aObject->isSame(theSelectedObject))) { + aRefAttr->setObject(theSelectedObject); + } + } else if (aType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); + ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); + if (aSelectAttr.get() != NULL) { + aSelectAttr->setValue(aResult, theShape); } } } @@ -275,3 +274,14 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) aRefAttr->setAttr(myRefAttribute); } } + +//******************************************************************** +bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); + + setObject(anObject, aShape); + return true; +} diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 2c8a10363..a750c8033 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -104,6 +104,10 @@ Q_OBJECT /// \return a list of shapes virtual QIntList getShapeTypes() const; + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + /// 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