From 5bd71db89b7a145e0e1e51b03361e7ed400b961a Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 29 Jul 2015 11:22:48 +0300 Subject: [PATCH] CompSolid filled presentation. Sub-results bodies are stored to an internal list. --- .../FeaturesPlugin_Extrusion.cpp | 15 +++-- src/Model/Model_ResultCompSolid.cpp | 66 ++++++++++++++++--- src/Model/Model_ResultCompSolid.h | 17 ++++- src/ModelAPI/ModelAPI_ResultCompSolid.cpp | 4 -- src/ModelAPI/ModelAPI_ResultCompSolid.h | 10 ++- 5 files changed, 86 insertions(+), 26 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 04b52ff42..38fe43254 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -98,6 +98,7 @@ void FeaturesPlugin_Extrusion::execute() // for each selected face generate a result int anIndex = 0, aResultIndex = 0; + for(; anIndex < aFaceRefs->size(); anIndex++) { std::shared_ptr aFaceRef = aFaceRefs->value(anIndex); ResultPtr aContextRes = aFaceRef->context(); @@ -122,10 +123,14 @@ void FeaturesPlugin_Extrusion::execute() } } +#ifdef DEBUG_COMPSOLID + ResultCompSolidPtr aCompSolidResult = document()->createCompSolid(data(), aResultIndex); + setResult(aCompSolidResult, aResultIndex); + aResultIndex++; +#endif for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { - //ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); #ifdef DEBUG_COMPSOLID - ResultCompSolidPtr aResultBody = document()->createCompSolid(data(), aResultIndex); + ResultBodyPtr aResultBody = aCompSolidResult->addResult(aResultIndex); #else ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); #endif @@ -155,10 +160,10 @@ void FeaturesPlugin_Extrusion::execute() break; } //LoadNamingDS -#ifdef DEBUG_COMPSOLID -#else +//#ifdef DEBUG_COMPSOLID +//#else LoadNamingDS(aFeature, aResultBody, aBaseShape, aContext); -#endif +//#endif setResult(aResultBody, aResultIndex); aResultIndex++; diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index 93f4331a0..cc3a09015 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -6,6 +6,11 @@ #include +#include +#include + +#include + Model_ResultCompSolid::Model_ResultCompSolid() { } @@ -14,10 +19,18 @@ Model_ResultCompSolid::~Model_ResultCompSolid() { } -std::shared_ptr Model_ResultCompSolid::addResult(std::string theID) +void Model_ResultCompSolid::initAttributes() +{ + data()->addAttribute(Model_ResultCompSolid::BODIES_ID(), ModelAPI_AttributeRefList::typeId()); +} + +std::shared_ptr Model_ResultCompSolid::addResult(const int theIndex) { - std::shared_ptr aResult; - return aResult; + std::shared_ptr aBody = document()->createBody(data(), theIndex); + if (aBody.get()) { + data()->reflist(Model_ResultCompSolid::BODIES_ID())->append(aBody); + } + return aBody; } int Model_ResultCompSolid::numberOfSubs(bool forTree) const @@ -28,21 +41,56 @@ int Model_ResultCompSolid::numberOfSubs(bool forTree) const std::shared_ptr Model_ResultCompSolid::subResult(const int theIndex, bool forTree) const { - std::shared_ptr aBody; + if (forTree) { + std::shared_ptr aBody; + return aBody; + } - return aBody; + ObjectPtr anObj = data()->reflist(Model_ResultCompSolid::BODIES_ID())->object(theIndex); + return std::dynamic_pointer_cast(anObj); } -int Model_ResultCompSolid::subResultId(const int theIndex) const +/*int Model_ResultCompSolid::subResultId(const int theIndex) const { - return 0; -} + return subResult(theIndex)->data()->featureId(); +}*/ bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const { - return true; + // check is this feature of result + ResultBodyPtr aResult = std::dynamic_pointer_cast(theObject); + /*if (!aFeature) { + ResultPtr aRes = std::dynamic_pointer_cast(theObject); + if (aRes) + aFeature = document()->feature(aRes); + }*/ + if (aResult) { + return data()->reflist(Model_ResultCompSolid::BODIES_ID())->isInList(aResult); + } + return false; } void Model_ResultCompSolid::removeResult(std::shared_ptr theResult) { + if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed + return; + + std::list aSubs = data()->reflist(Model_ResultCompSolid::BODIES_ID())->list(); + + std::list::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end(); + bool isRemoved = false; + bool aHasEmtpyResult = false; + for(; aSubIt != aLastIt && !isRemoved; aSubIt++) { + std::shared_ptr aResult = std::dynamic_pointer_cast(*aSubIt); + if (aResult.get() != NULL && aResult == theResult) { + data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(aResult); + isRemoved = true; + } + else if (aResult.get() == NULL) + aHasEmtpyResult = true; + } + // if the object is not found in the sketch sub-elements, that means that the object is removed already. + // Find the first empty element and remove it + if (!isRemoved && aHasEmtpyResult) + data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(ObjectPtr()); } diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index 6e7c2c663..f1c697e56 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -19,11 +19,24 @@ class Model_ResultCompSolid : public ModelAPI_ResultCompSolid { public: + /// All features of this sketch (list of references) + inline static const std::string& BODIES_ID() + { + static const std::string MY_BODIES_ID("Bodies"); + return MY_BODIES_ID; + } + /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultCompSolid(); + /// Request for initialization of data model of the object: adding all attributes + MODEL_EXPORT virtual void initAttributes(); + /// Adds result to the sketch and to its document - virtual std::shared_ptr addResult(std::string theID); + /// \param theIndex an index of the created body result in the compsolid + /// The real index in the document of the result is an incremented given index + /// The reason is that the first index is used for the comp solid result on the data + virtual std::shared_ptr addResult(const int theIndex); /// Returns the number of sub-elements virtual int numberOfSubs(bool forTree = false) const; @@ -33,7 +46,7 @@ public: bool forTree = false) const; /// Returns the sub-feature unique identifier in this composite feature by zero-base index - virtual int subResultId(const int theIndex) const; + //virtual int subResultId(const int theIndex) const; /// Returns true if feature or reuslt belong to this composite feature as subs virtual bool isSub(ObjectPtr theObject) const; diff --git a/src/ModelAPI/ModelAPI_ResultCompSolid.cpp b/src/ModelAPI/ModelAPI_ResultCompSolid.cpp index d62ab8bc7..b4953c70f 100755 --- a/src/ModelAPI/ModelAPI_ResultCompSolid.cpp +++ b/src/ModelAPI/ModelAPI_ResultCompSolid.cpp @@ -15,10 +15,6 @@ std::string ModelAPI_ResultCompSolid::groupName() return group(); } -void ModelAPI_ResultCompSolid::initAttributes() -{ -} - bool ModelAPI_ResultCompSolid::isDisabled() const { return false; diff --git a/src/ModelAPI/ModelAPI_ResultCompSolid.h b/src/ModelAPI/ModelAPI_ResultCompSolid.h index e2147b07a..4a0efd6fc 100755 --- a/src/ModelAPI/ModelAPI_ResultCompSolid.h +++ b/src/ModelAPI/ModelAPI_ResultCompSolid.h @@ -27,18 +27,16 @@ public: /// Returns the group identifier of this result inline static std::string group() { - static std::string MY_GROUP = "CompSolid"; + static std::string MY_GROUP = "Bodies"; return MY_GROUP; } - /// Request for initialization of data model of the object: adding all attributes - MODELAPI_EXPORT virtual void initAttributes(); - /// Returns the feature is disabled or not. MODELAPI_EXPORT virtual bool isDisabled() const; /// Adds result to the sketch and to its document - virtual std::shared_ptr addResult(std::string theID) = 0; + /// \param theIndex an index of the created body result in the compsolid + virtual std::shared_ptr addResult(const int theIndex) = 0; /// Returns the number of sub-elements virtual int numberOfSubs(bool forTree = false) const = 0; @@ -48,7 +46,7 @@ public: bool forTree = false) const = 0; /// Returns the sub-feature unique identifier in this composite feature by zero-base index - virtual int subResultId(const int theIndex) const = 0; + //virtual int subResultId(const int theIndex) const = 0; /// Returns true if feature or reuslt belong to this composite feature as subs virtual bool isSub(ObjectPtr theObject) const = 0; -- 2.39.2