From c5cdfcc734220f0343206392da4fada7db069e0d Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 22 May 2015 16:35:04 +0300 Subject: [PATCH] Fix on selection initialization (for revolution axis) and hiding sketch only on apply --- src/Model/Model_AttributeRefAttr.h | 1 - src/Model/Model_AttributeSelection.cpp | 30 ++++++++++++++++++++++++++ src/Model/Model_AttributeSelection.h | 3 +++ src/Model/Model_Update.cpp | 30 ++++++++++++++------------ src/Model/Model_Update.h | 2 +- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/Model/Model_AttributeRefAttr.h b/src/Model/Model_AttributeRefAttr.h index 66c0870e6..49337e695 100644 --- a/src/Model/Model_AttributeRefAttr.h +++ b/src/Model/Model_AttributeRefAttr.h @@ -43,7 +43,6 @@ class Model_AttributeRefAttr : public ModelAPI_AttributeRefAttr /// Returns true if attribute was initialized by some value MODEL_EXPORT virtual bool isInitialized(); - protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeRefAttr(TDF_Label& theLabel); diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 6ff60d02e..6061cc038 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -166,6 +166,36 @@ std::shared_ptr Model_AttributeSelection::value() return aResult; } +bool Model_AttributeSelection::isInitialized() +{ + if (ModelAPI_AttributeSelection::isInitialized()) { // additional checkings if it is initialized + std::shared_ptr aResult; + if (myRef.isInitialized()) { + TDF_Label aSelLab = selectionLabel(); + if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape + ResultPtr aContext = context(); + if (!aContext.get()) + return false; + } + if (aSelLab.IsAttribute(kCONSTUCTION_SIMPLE_REF_ID)) { // it is just reference to construction, nothing is in value + return false; + } + + Handle(TNaming_NamedShape) aSelection; + if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) { + return !aSelection->Get().IsNull(); + } else { // for simple construction element: just shape of this construction element + ResultConstructionPtr aConstr = + std::dynamic_pointer_cast(context()); + if (aConstr.get()) { + return aConstr->shape().get(); + } + } + } + } + return false; +} + Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel) : myRef(theLabel) { diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 19c1a1514..1b2f82601 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -52,6 +52,9 @@ public: /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName); + /// Returns true if attribute was initialized by some value + MODEL_EXPORT virtual bool isInitialized(); + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel); diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 7a8e5277b..6fe00ce28 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -102,7 +102,7 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag // we don't need the update only on operation start (caused problems in PartSet_Listener::processEvent) isOperationChanged = true; } else if (theMessage->eventID() == kOpFinishEvent || theMessage->eventID() == kOpAbortEvent) { - processOperation(true); + processOperation(true, theMessage->eventID() == kOpFinishEvent); isOperationChanged = true; } if (isOperationChanged) { @@ -131,20 +131,22 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag } } -void Model_Update::processOperation(const bool theTotalUpdate) +void Model_Update::processOperation(const bool theTotalUpdate, const bool theFinish) { - // the hardcode (DBC asked): hide the sketch referenced by extrusion on apply - std::set >::iterator aFIter; - for(aFIter = myJustCreated.begin(); aFIter != myJustCreated.end(); aFIter++) - { - FeaturePtr aF = std::dynamic_pointer_cast(*aFIter); - if (aF && aF->data().get() && aF->getKind() == "Extrusion") { - AttributeSelectionListPtr aBase = aF->selectionList("base"); - if (aBase.get()) { - for(int a = aBase->size() - 1; a >= 0; a--) { - ResultPtr aSketchRes = aBase->value(a)->context(); - if (aSketchRes) { - aSketchRes->setDisplayed(false); + if (theFinish) { + // the hardcode (DBC asked): hide the sketch referenced by extrusion on apply + std::set >::iterator aFIter; + for(aFIter = myJustCreated.begin(); aFIter != myJustCreated.end(); aFIter++) + { + FeaturePtr aF = std::dynamic_pointer_cast(*aFIter); + if (aF && aF->data().get() && aF->getKind() == "Extrusion") { + AttributeSelectionListPtr aBase = aF->selectionList("base"); + if (aBase.get()) { + for(int a = aBase->size() - 1; a >= 0; a--) { + ResultPtr aSketchRes = aBase->value(a)->context(); + if (aSketchRes) { + aSketchRes->setDisplayed(false); + } } } } diff --git a/src/Model/Model_Update.h b/src/Model/Model_Update.h index 22fe573b9..9eed59029 100644 --- a/src/Model/Model_Update.h +++ b/src/Model/Model_Update.h @@ -55,7 +55,7 @@ protected: /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way /// \param theTotalUpdate force to updates everything that has been changed in this operation - void processOperation(const bool theTotalUpdate); + void processOperation(const bool theTotalUpdate, const bool theFinish = false); /// Performs the feature execution /// \returns the status of execution -- 2.39.2