From: mpv Date: Thu, 30 Oct 2014 16:22:18 +0000 (+0300) Subject: Added groups results X-Git-Tag: V_0.5~58^2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b378265f0b502fe00e8af93ce9f2c5739acfc1c;p=modules%2Fshaper.git Added groups results --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp index dad22dbf6..e9ae74d59 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp @@ -25,10 +25,7 @@ void FeaturesPlugin_Group::initAttributes() void FeaturesPlugin_Group::execute() { - //AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast( - // data()->attribute(FeaturesPlugin_Group::NAME_ID())); - //if (!aNameAttr) - // return; - //std::string aName = aNameAttr->value(); - //data()->setName(aName); + if (results().empty()) { // just create result if not exists + document()->createGroup(data()); + } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.h b/src/FeaturesPlugin/FeaturesPlugin_Group.h index 23078ae67..7138c1241 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Group.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.h @@ -44,6 +44,9 @@ class FeaturesPlugin_Group : public ModelAPI_Feature /// Request for initialization of data model of the feature: adding all attributes FEATURESPLUGIN_EXPORT virtual void initAttributes(); + /// Result of groups is created on the fly and don't stored to the document + FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + /// Use plugin manager for features creation FeaturesPlugin_Group(); diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 1656a618f..753fd7817 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PROJECT_HEADERS Model_ResultBody.h Model_ResultConstruction.h Model_ResultPart.h + Model_ResultGroup.h Model_FeatureValidator.h ) @@ -46,6 +47,7 @@ SET(PROJECT_SOURCES Model_ResultBody.cpp Model_ResultConstruction.cpp Model_ResultPart.cpp + Model_ResultGroup.cpp Model_FeatureValidator.cpp ) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index f502aee03..aac5c3f08 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -91,8 +91,8 @@ bool Model_AttributeSelection::update() // body: just a named shape, use selection mechanism from OCCT TNaming_Selector aSelector(selectionLabel()); TDF_LabelMap aScope; // empty means the whole document + owner()->data()->sendAttributeUpdated(this); return aSelector.Solve(aScope) == Standard_True; - } else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) { // construction: identification by the results indexes, recompute faces and // take the face that more close by the indexes @@ -171,6 +171,7 @@ bool Model_AttributeSelection::update() } if (aNewSelected) { // store this new selection selectConstruction(aContext, aNewSelected); + owner()->data()->sendAttributeUpdated(this); return true; } } diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index cbf4ac79d..2487b7c30 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -912,6 +913,23 @@ boost::shared_ptr Model_Document::createPart( return aResult; } +boost::shared_ptr Model_Document::createGroup( + const boost::shared_ptr& theFeatureData, const int theIndex) +{ + TDF_Label aLab = resultLabel(theFeatureData, theIndex); + TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str()); + ObjectPtr anOldObject = object(aLab); + boost::shared_ptr aResult; + if (anOldObject) { + aResult = boost::dynamic_pointer_cast(anOldObject); + } + if (!aResult) { + aResult = boost::shared_ptr(new Model_ResultGroup(theFeatureData)); + storeResult(theFeatureData, aResult, theIndex); + } + return aResult; +} + boost::shared_ptr Model_Document::feature( const boost::shared_ptr& theResult) { @@ -957,7 +975,8 @@ void Model_Document::updateResults(FeaturePtr theFeature) aNewBody = createBody(theFeature->data(), aResIndex); } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) { aNewBody = createPart(theFeature->data(), aResIndex); - } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str()) { + } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str() && + aGroup->Get() != ModelAPI_ResultGroup::group().c_str()) { Events_Error::send(std::string("Unknown type of result is found in the document:") + TCollection_AsciiString(aGroup->Get()).ToCString()); } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index cbea4a19e..d8743f099 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -121,6 +121,9 @@ class Model_Document : public ModelAPI_Document /// Creates a part results MODEL_EXPORT virtual boost::shared_ptr createPart( const boost::shared_ptr& theFeatureData, const int theIndex = 0); + /// Creates a group results + MODEL_EXPORT virtual boost::shared_ptr createGroup( + const boost::shared_ptr& theFeatureData, const int theIndex = 0); //! Returns a feature by result (owner of result) MODEL_EXPORT virtual boost::shared_ptr diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 807dcc733..3c7f7a689 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -101,11 +101,6 @@ boost::shared_ptr Model_ResultBody::shape() return boost::shared_ptr(); } -boost::shared_ptr Model_ResultBody::owner() -{ - return myOwner; -} - void Model_ResultBody::clean() { std::vector::iterator aBuilder = myBuilders.begin(); diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 340b35bb5..a12ccb87d 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -23,7 +23,6 @@ class TNaming_Builder; */ class Model_ResultBody : public ModelAPI_ResultBody { - boost::shared_ptr myOwner; ///< owner of this result /// builders that tores the naming history: one per label to allow store several shapes to one /// label; index in vector corresponds to the label tag std::vector myBuilders; @@ -41,8 +40,6 @@ public: /// Returns the shape-result produced by this feature MODEL_EXPORT virtual boost::shared_ptr shape(); - /// Returns the source feature of this result - MODEL_EXPORT virtual boost::shared_ptr owner(); /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp new file mode 100644 index 000000000..2fd1ead9d --- /dev/null +++ b/src/Model/Model_ResultGroup.cpp @@ -0,0 +1,34 @@ +// File: Model_ResultGroup.cpp +// Created: 08 Jul 2014 +// Author: Mikhail PONIKAROV + +#include +#include +#include + +Model_ResultGroup::Model_ResultGroup(boost::shared_ptr theOwnerData) +{ + setIsConcealed(false); + myOwnerData = theOwnerData; +} + +boost::shared_ptr Model_ResultGroup::shape() const +{ + boost::shared_ptr aResult; + if (myOwnerData) { + AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list"); + if (aList) { + std::list > aSubs; + for(int a = aList->size(); a >= 0; a--) { + boost::shared_ptr aSelection = aList->value(a)->value(); + if (aSelection && !aSelection->isNull()) { + aSubs.push_back(aSelection); + } + } + if (!aSubs.empty()) { + aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs); + } + } + } + return aResult; +} diff --git a/src/Model/Model_ResultGroup.h b/src/Model/Model_ResultGroup.h new file mode 100644 index 000000000..30e358898 --- /dev/null +++ b/src/Model/Model_ResultGroup.h @@ -0,0 +1,34 @@ +// File: Model_ResultGroup.h +// Created: 08 Jul 2014 +// Author: Mikhail PONIKAROV + +#ifndef Model_ResultGroup_H_ +#define Model_ResultGroup_H_ + +#include "Model.h" +#include + +/**\class ModelAPI_ResultGroup + * \ingroup DataModel + * \brief The groups result. + * + * Provides a compound of selected elements, without storage, one the fly. + */ +class Model_ResultGroup : public ModelAPI_ResultGroup +{ + boost::shared_ptr myOwnerData; ///< data of owner of this result +public: + /// Returns the compound of selected entities + MODEL_EXPORT virtual boost::shared_ptr shape() const; + + /// Removes the stored builders + MODEL_EXPORT virtual ~Model_ResultGroup() {} + +protected: + /// Makes a body on the given feature data + Model_ResultGroup(boost::shared_ptr theOwnerData); + + friend class Model_Document; +}; + +#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 0bfa08a58..bbc99cbb1 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -31,6 +31,7 @@ SET(PROJECT_HEADERS ModelAPI_ResultConstruction.h ModelAPI_ResultPart.h ModelAPI_ResultParameters.h + ModelAPI_ResultGroup.h ModelAPI_ResultValidator.h ModelAPI_AttributeValidator.h ModelAPI_Tools.h diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index cdfa1d75e..703ab0f88 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -17,6 +17,7 @@ class ModelAPI_Result; class ModelAPI_ResultConstruction; class ModelAPI_ResultBody; class ModelAPI_ResultPart; +class ModelAPI_ResultGroup; class ModelAPI_Data; /**\class Model_Document @@ -76,6 +77,9 @@ public: /// Creates a part results virtual boost::shared_ptr createPart( const boost::shared_ptr& theFeatureData, const int theIndex = 0) = 0; + /// Creates a group results + virtual boost::shared_ptr createGroup( + const boost::shared_ptr& theFeatureData, const int theIndex = 0) = 0; //! Returns a feature by result (owner of result) virtual boost::shared_ptr feature( diff --git a/src/ModelAPI/ModelAPI_ResultGroup.h b/src/ModelAPI/ModelAPI_ResultGroup.h new file mode 100644 index 000000000..a8b183c12 --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultGroup.h @@ -0,0 +1,42 @@ +// File: ModelAPI_ResultGroup.hxx +// Created: 07 Jul 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_ResultGroup_H_ +#define ModelAPI_ResultGroup_H_ + +#include "ModelAPI_Result.h" +#include +#include +#include + +/**\class ModelAPI_ResultGroup + * \ingroup DataModel + * \brief The groups result. + * + * Provides a compound of selected elements, without storage, one the fly. + */ +class ModelAPI_ResultGroup : public ModelAPI_Result +{ +public: + /// Returns the group identifier of this result + virtual std::string groupName() + { + return group(); + } + + /// Returns the group identifier of this result + static std::string group() + { + static std::string MY_GROUP = "Groups"; + return MY_GROUP; + } + + /// Returns the compound of selected entities + virtual boost::shared_ptr shape() const = 0; +}; + +//! Pointer on feature object +typedef boost::shared_ptr ResultGroupPtr; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 75c404a77..2d85a43b3 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -21,8 +21,7 @@ using namespace std; SketchPlugin_Line::SketchPlugin_Line() : SketchPlugin_Feature() -{ -} +{} void SketchPlugin_Line::initAttributes() {