From: mpv Date: Wed, 22 Oct 2014 13:24:51 +0000 (+0400) Subject: The list of selection attributes is added X-Git-Tag: V_0.5~83 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=54f1bc8dd6fe9682aba17578587cd760f8b82b3c;p=modules%2Fshaper.git The list of selection attributes is added --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index c9715ebc2..25626636a 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -15,6 +15,7 @@ SET(PROJECT_HEADERS Model_AttributeString.h Model_AttributeInteger.h Model_AttributeSelection.h + Model_AttributeSelectionList.h Model_Events.h Model_Update.h Model_Validator.h @@ -38,6 +39,7 @@ SET(PROJECT_SOURCES Model_AttributeString.cpp Model_AttributeInteger.cpp Model_AttributeSelection.cpp + Model_AttributeSelectionList.cpp Model_Events.cpp Model_Update.cpp Model_Validator.cpp diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index b41c4dffc..2e71baea1 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -28,6 +28,7 @@ public: /// Returns the context of the selection (the whole shape owner) MODEL_EXPORT virtual ResultPtr context(); + /// Sets the feature object MODEL_EXPORT virtual void setObject(const boost::shared_ptr& theObject); protected: @@ -43,6 +44,7 @@ protected: const ResultPtr& theContext, const boost::shared_ptr& theSubShape); friend class Model_Data; + friend class Model_AttributeSelectionList; }; #endif diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp new file mode 100644 index 000000000..848341184 --- /dev/null +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -0,0 +1,71 @@ +// File: Model_AttributeSelectionList.h +// Created: 22 Oct 2014 +// Author: Mikhail PONIKAROV + +#include "Model_AttributeSelectionList.h" +#include "Model_AttributeSelection.h" +#include "Model_Application.h" +#include "Model_Events.h" +#include "Model_Data.h" + +#include + +using namespace std; + +void Model_AttributeSelectionList::append( + const ResultPtr& theContext, const boost::shared_ptr& theSubShape) +{ + int aNewTag = mySize->Get() + 1; + TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); + mySubs.push_back(boost::shared_ptr( + new Model_AttributeSelection(aNewLab))); + mySize->Set(aNewTag); +} + +int Model_AttributeSelectionList::size() +{ + return mySize->Get(); +} + +boost::shared_ptr + Model_AttributeSelectionList::value(const int theIndex) +{ + return mySubs[theIndex]; +} + +void Model_AttributeSelectionList::clear() +{ + mySubs.clear(); + TDF_ChildIterator aSubIter(mySize->Label()); + for(; aSubIter.More(); aSubIter.Next()) { + aSubIter.Value().ForgetAllAttributes(Standard_True); + } +} + +Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) +{ + myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; + if (!myIsInitialized) { + mySize = TDataStd_Integer::Set(theLabel, 0); + } else { // recollect mySubs + int aNum = mySize->Get(); + TDF_ChildIterator aSubIter(theLabel); + for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) { + TDF_Label aChildLab = aSubIter.Value(); + boost::shared_ptr aNewAttr = + boost::shared_ptr(new Model_AttributeSelection(aChildLab)); + if (owner()) + aNewAttr->setObject(owner()); + mySubs.push_back(aNewAttr); + } + } +} + +void Model_AttributeSelectionList::setObject(const boost::shared_ptr& theObject) +{ + ModelAPI_AttributeSelectionList::setObject(theObject); + std::vector >::iterator aSubIter = mySubs.begin(); + for(; aSubIter != mySubs.end(); aSubIter++) { + (*aSubIter)->setObject(theObject); + } +} diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h new file mode 100644 index 000000000..103b213f1 --- /dev/null +++ b/src/Model/Model_AttributeSelectionList.h @@ -0,0 +1,49 @@ +// File: Model_AttributeSelectionList.h +// Created: 22 Oct 2014 +// Author: Mikhail PONIKAROV + +#ifndef Model_AttributeSelectionList_H_ +#define Model_AttributeSelectionList_H_ + +#include "Model.h" +#include "Model_AttributeSelection.h" +#include +#include +#include + +/**\class Model_AttributeSelectionList + * \ingroup DataModel + * \brief Attribute that contains list of references to the sub-shapes with + * possibility to manage them. + */ + +class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList +{ + Handle(TDataStd_Integer) mySize; ///< Contains size of this list + std::vector > mySubs; /// the selection attributes +public: + /// Adds the new reference to the end of the list + MODEL_EXPORT virtual void append( + const ResultPtr& theContext, const boost::shared_ptr& theSubShape); + + /// Returns the number ofselection attributes in the list + MODEL_EXPORT virtual int size(); + + /// Returns the attribute selection by the index (zero based) + MODEL_EXPORT virtual boost::shared_ptr value(const int theIndex); + + /// Returns all attributes + MODEL_EXPORT virtual void clear(); + + /// Sets the feature object + MODEL_EXPORT virtual void setObject(const boost::shared_ptr& theObject); + +protected: + /// Objects are created for features automatically + MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel); + /// Performs the selection for the body result (TNaming Selection) + + friend class Model_Data; +}; + +#endif diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index c76a2f26f..7b25cb240 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt anAttr = new Model_AttributeReference(anAttrLab); } else if (theAttrType == ModelAPI_AttributeSelection::type()) { anAttr = new Model_AttributeSelection(anAttrLab); + } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) { + anAttr = new Model_AttributeSelectionList(anAttrLab); } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) { anAttr = new Model_AttributeRefAttr(anAttrLab); } else if (theAttrType == ModelAPI_AttributeRefList::type()) { @@ -97,7 +100,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt boost::shared_ptr Model_Data::document(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -112,7 +116,8 @@ boost::shared_ptr Model_Data::document(const std::stri boost::shared_ptr Model_Data::real(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -127,7 +132,8 @@ boost::shared_ptr Model_Data::real(const std::string& boost::shared_ptr Model_Data::integer(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -142,7 +148,8 @@ boost::shared_ptr Model_Data::integer(const std::stri boost::shared_ptr Model_Data::boolean(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -157,7 +164,8 @@ boost::shared_ptr Model_Data::boolean(const std::stri boost::shared_ptr Model_Data::string(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -173,7 +181,8 @@ boost::shared_ptr Model_Data::string(const std::string boost::shared_ptr Model_Data::reference(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -188,7 +197,8 @@ boost::shared_ptr Model_Data::reference(const std:: boost::shared_ptr Model_Data::selection(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -201,9 +211,27 @@ boost::shared_ptr Model_Data::selection(const std:: return aRes; } +boost::shared_ptr + Model_Data::selectionList(const std::string& theID) +{ + std::map >::iterator aFound = + myAttrs.find(theID); + if (aFound == myAttrs.end()) { + // TODO: generate error on unknown attribute request and/or add mechanism for customization + return boost::shared_ptr(); + } + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::refattr(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -218,7 +246,8 @@ boost::shared_ptr Model_Data::refattr(const std::stri boost::shared_ptr Model_Data::reflist(const std::string& theID) { - std::map >::iterator aFound = myAttrs.find(theID); + std::map >::iterator aFound = + myAttrs.find(theID); if (aFound == myAttrs.end()) { // TODO: generate error on unknown attribute request and/or add mechanism for customization return boost::shared_ptr(); @@ -241,7 +270,8 @@ boost::shared_ptr Model_Data::attribute(const std::string& t const std::string& Model_Data::id(const boost::shared_ptr& theAttr) { - std::map >::iterator anAttr = myAttrs.begin(); + std::map >::iterator anAttr = + myAttrs.begin(); for (; anAttr != myAttrs.end(); anAttr++) { if (anAttr->second == theAttr) return anAttr->first; diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 8aead1b5b..c923d79af 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -76,6 +76,9 @@ class Model_Data : public ModelAPI_Data /// Returns the attribute that contains selection to a shape MODEL_EXPORT virtual boost::shared_ptr selection(const std::string& theID); + /// Returns the attribute that contains selection to a shape + MODEL_EXPORT virtual boost::shared_ptr + selectionList(const std::string& theID); /// Returns the attribute that contains reference to an attribute of a feature MODEL_EXPORT virtual boost::shared_ptr refattr(const std::string& theID); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 13e4ee12e..9bebf30fb 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PROJECT_HEADERS ModelAPI_AttributeBoolean.h ModelAPI_AttributeString.h ModelAPI_AttributeSelection.h + ModelAPI_AttributeSelectionList.h ModelAPI_Events.h ModelAPI_Validator.h ModelAPI_FeatureValidator.h diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 0eb00bd49..7ff2bfc8e 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -17,6 +17,7 @@ #include "ModelAPI_AttributeReference.h" #include "ModelAPI_AttributeRefAttr.h" #include "ModelAPI_AttributeSelection.h" + #include "ModelAPI_AttributeSelectionList.h" #include "ModelAPI_Validator.h" #include "ModelAPI_AttributeRefList.h" #include "ModelAPI_AttributeBoolean.h" @@ -62,6 +63,7 @@ %shared_ptr(ModelAPI_AttributeRefList) %shared_ptr(ModelAPI_AttributeBoolean) %shared_ptr(ModelAPI_AttributeSelection) +%shared_ptr(ModelAPI_AttributeSelectionList) %shared_ptr(ModelAPI_Result) %shared_ptr(ModelAPI_ResultConstruction) %shared_ptr(ModelAPI_ResultBody) @@ -84,6 +86,7 @@ %include "ModelAPI_AttributeRefAttr.h" %include "ModelAPI_AttributeBoolean.h" %include "ModelAPI_AttributeSelection.h" +%include "ModelAPI_AttributeSelectionList.h" %include "ModelAPI_AttributeRefList.h" %include "ModelAPI_Validator.h" %include "ModelAPI_Result.h" diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h new file mode 100644 index 000000000..4305471d3 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -0,0 +1,57 @@ +// File: ModelAPI_AttributeSelectionList.h +// Created: 22 Oct 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_AttributeSelectionList_H_ +#define ModelAPI_AttributeSelectionList_H_ + +#include "ModelAPI_AttributeSelection.h" +#include + +/**\class ModelAPI_AttributeSelectionList + * \ingroup DataModel + * \brief Attribute that contains list of references to the sub-shapes with + * possibility to manage them. + */ + +class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute +{ + public: + /// Adds the new reference to the end of the list + virtual void append( + const ResultPtr& theContext, const boost::shared_ptr& theSubShape) = 0; + + /// Returns the number ofselection attributes in the list + virtual int size() = 0; + + /// Returns the attribute selection by the index (zero based) + virtual boost::shared_ptr value(const int theIndex) = 0; + + /// Returns all attributes + virtual void clear() = 0; + + /// Returns the type of this class of attributes + static std::string type() + { + return "SelectionList"; + } + + /// Returns the type of this class of attributes, not static method + virtual std::string attributeType() + { + return type(); + } + + /// To virtually destroy the fields of successors + virtual ~ModelAPI_AttributeSelectionList() + { + } + + protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeSelectionList() + { + } +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 1bd01c5b3..e9852e6e2 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -22,6 +22,7 @@ class ModelAPI_Document; class ModelAPI_Attribute; class ModelAPI_Feature; class ModelAPI_AttributeSelection; +class ModelAPI_AttributeSelectionList; class GeomAPI_Shape; /**\class ModelAPI_Data @@ -50,6 +51,9 @@ class MODELAPI_EXPORT ModelAPI_Data virtual boost::shared_ptr reference(const std::string& theID) = 0; /// Returns the attribute that contains selection to a shape virtual boost::shared_ptr selection(const std::string& theID) = 0; + /// Returns the attribute that contains selection to a shape + virtual boost::shared_ptr + selectionList(const std::string& theID) = 0; /// Returns the attribute that contains reference to an attribute of a feature virtual boost::shared_ptr refattr(const std::string& theID) = 0; /// Returns the attribute that contains list of references to features diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp index 137f8f8a5..db8a54ca2 100644 --- a/src/ModelAPI/ModelAPI_Session.cpp +++ b/src/ModelAPI/ModelAPI_Session.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include