From: mpv Date: Wed, 1 Aug 2018 11:35:07 +0000 (+0300) Subject: Added ability to select features as a context of selection attribute X-Git-Tag: SHAPER_V9_1_0RC1~73^2~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d94dd9ddc9af69edf23dbe9996cee6ed54db5c1;p=modules%2Fshaper.git Added ability to select features as a context of selection attribute --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 985bd4b12..6726c06f4 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -91,11 +91,13 @@ Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32"); // TDataStd_IntPackedMap - indexes of edges in composite element (for construction) // TDataStd_Integer - type of the selected shape (for construction) // TDF_Reference - from ReferenceAttribute, the context -bool Model_AttributeSelection::setValue(const ResultPtr& theContext, +bool Model_AttributeSelection::setValue(const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) { - if (theTemporarily) { // just keep the stored without DF update - myTmpContext = theContext; + if (theTemporarily && + (!theContext.get() || theContext->groupName() != ModelAPI_Feature::group())) { + // just keep the stored without DF update + myTmpContext = std::dynamic_pointer_cast(theContext); myTmpSubShape = theSubShape; owner()->data()->sendAttributeUpdated(this); return true; @@ -143,34 +145,37 @@ bool Model_AttributeSelection::setValue(const ResultPtr& theContext, return false; } if (theContext->groupName() == ModelAPI_ResultBody::group()) { + ResultBodyPtr aContextBody = std::dynamic_pointer_cast(theContext); // do not select the whole shape for body:it is already must be in the data framework // equal and null selected objects mean the same: object is equal to context, - if (theContext->shape().get() && - (theContext->shape()->isEqual(theSubShape) || !theSubShape.get())) { + if (aContextBody->shape().get() && + (aContextBody->shape()->isEqual(theSubShape) || !theSubShape.get())) { aSelLab.ForgetAllAttributes(true); TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID); } else { - selectBody(theContext, theSubShape); + selectBody(aContextBody, theSubShape); } } else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) { + ResultConstructionPtr aContextConstruction = + std::dynamic_pointer_cast(theContext); aSelLab.ForgetAllAttributes(true); // to remove old selection data std::shared_ptr aConstruction = std::dynamic_pointer_cast(theContext); std::shared_ptr aSubShape; - if (theSubShape.get() && !theContext->shape()->isEqual(theSubShape)) + if (theSubShape.get() && !aContextConstruction->shape()->isEqual(theSubShape)) aSubShape = theSubShape; // the whole context if (aConstruction->isInfinite()) { // For correct naming selection, put the shape into the naming structure. // It seems sub-shapes are not needed: only this shape is (and can be ) selected. TNaming_Builder aBuilder(aSelLab); - aBuilder.Generated(theContext->shape()->impl()); + aBuilder.Generated(aContextConstruction->shape()->impl()); } int anIndex = aConstruction->select(theSubShape, owner()->document()); TDataStd_Integer::Set(aSelLab, anIndex); } else if (theContext->groupName() == ModelAPI_ResultPart::group()) { aSelLab.ForgetAllAttributes(true); TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID); - selectPart(theContext, theSubShape); + selectPart(std::dynamic_pointer_cast(theContext), theSubShape); } owner()->data()->sendAttributeUpdated(this); @@ -182,7 +187,7 @@ bool Model_AttributeSelection::setValue(const ResultPtr& theContext, } void Model_AttributeSelection::setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, + const ObjectPtr& theContext, const std::shared_ptr& theEdge, const CenterType theCenterType, const bool theTemporarily) { bool anUpdated = setValue(theContext, theEdge, theTemporarily); @@ -435,6 +440,15 @@ ResultPtr Model_AttributeSelection::context() { return aResult; } +FeaturePtr Model_AttributeSelection::contextFeature() { + if (myTmpContext.get() || myTmpSubShape.get()) { + return FeaturePtr(); // feature can not be selected temporarily + } + return std::dynamic_pointer_cast(myRef.value()); + +} + + void Model_AttributeSelection::setObject(const std::shared_ptr& theObject) { diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 5306aa68d..357691377 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -55,13 +55,13 @@ public: /// (used to remove immideately, without the following updates) /// \returns true if attribute was updated MODEL_EXPORT virtual bool setValue( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false); /// Same as SetValue, but it takes an edge (on circular or elliptical curve) /// and stores the vertex of the central point (for ellipse the first or the second focus point) MODEL_EXPORT virtual void setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, + const ObjectPtr& theContext, const std::shared_ptr& theEdge, const CenterType theCenterType, const bool theTemporarily = false); @@ -78,6 +78,9 @@ public: /// Returns the context of the selection (the whole shape owner) MODEL_EXPORT virtual ResultPtr context(); + /// Returns the context of the selection if the whole feature was selected + MODEL_EXPORT virtual FeaturePtr contextFeature(); + /// Sets the feature object MODEL_EXPORT virtual void setObject(const std::shared_ptr& theObject); diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 5207a1120..bc1c7f117 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -41,7 +41,7 @@ #include void Model_AttributeSelectionList::append( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) { // do not use the degenerated edge as a shape, a list is not incremented in this case @@ -53,7 +53,9 @@ void Model_AttributeSelectionList::append( } if (myIsCashed && !theTemporarily) { - myCash[theContext].push_back(theSubShape); + ResultPtr aResContext = std::dynamic_pointer_cast(theContext); + if (aResContext.get()) + myCash[aResContext].push_back(theSubShape); } int aNewTag = mySize->Get() + 1; @@ -225,28 +227,31 @@ int Model_AttributeSelectionList::size() return mySize->Get(); } -bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext, +bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) { + ResultPtr aResCont = std::dynamic_pointer_cast(theContext); if (myIsCashed) { // the cashing is active - std::map > >::iterator aContext = - myCash.find(theContext); - if (aContext != myCash.end()) { - // iterate shapes because "isSame" method must be called for each shape - std::list >::iterator aShapes = aContext->second.begin(); - for(; aShapes != aContext->second.end(); aShapes++) { - if (!theSubShape.get()) { - if (!aShapes->get() || (*aShapes)->isSame(aContext->first->shape())) - return true; - } else { - // we need to call here isSame instead of isEqual to do not check shapes orientation - if (theSubShape->isSame(*aShapes)) - return true; + if (aResCont.get()) { + std::map > >::iterator aContext = + myCash.find(aResCont); + if (aContext != myCash.end()) { + // iterate shapes because "isSame" method must be called for each shape + std::list >::iterator aShapes = aContext->second.begin(); + for(; aShapes != aContext->second.end(); aShapes++) { + if (!theSubShape.get()) { + if (!aShapes->get() || (*aShapes)->isSame(aContext->first->shape())) + return true; + } else { + // we need to call here isSame instead of isEqual to do not check shapes orientation + if (theSubShape->isSame(*aShapes)) + return true; + } } } + return false; } - return false; } // no-cash method for(int anIndex = size() - 1; anIndex >= 0; anIndex--) { @@ -255,7 +260,7 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext, if (anAttr->context() == theContext) { // contexts are equal, so, check that values are also std::shared_ptr aValue = anAttr->value(); if (!theSubShape.get()) { - if (!aValue.get() || aValue->isSame(theContext->shape())) { // both are null + if (!aValue.get() || (aResCont.get() && aValue->isSame(aResCont->shape()))) {// both null return true; } } else { diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index fd37b734b..289534c62 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -52,7 +52,7 @@ public: /// \param theTemporarily if it is true, do not store and name the added in the data framework /// (used to remove immideately, without the following updates) MODEL_EXPORT virtual void append( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false); /// Adds the new reference to the end of the list by the naming name of the selected shape @@ -78,7 +78,7 @@ public: /// \param theTemporarily if it is true, it checks also the temporary added item /// \returns true if the pair is found in the attirbute MODEL_EXPORT virtual bool isInList( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false); /// The type of all elements selection diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 904711ea2..22d1f8a54 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -49,13 +49,13 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute /// (used to remove immideately, without the following updates) /// \returns true if attribute was updated virtual bool setValue( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false) = 0; /// Same as SetValue, but it takes an edge (on circular or elliptical curve) /// and stores the vertex of the central point (for ellipse the first or the second focus point) virtual void setValueCenter( - const ResultPtr& theContext, const std::shared_ptr& theEdge, + const ObjectPtr& theContext, const std::shared_ptr& theEdge, const CenterType theCenterType, const bool theTemporarily = false) = 0; @@ -72,6 +72,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute /// Returns the context of the selection (the whole shape owner) virtual ResultPtr context() = 0; + /// Returns the context of the selection if the whole feature was selected + virtual std::shared_ptr contextFeature() = 0; + /// Updates the underlied selection due to the changes in the referenced objects /// \returns false if update is failed virtual bool update() = 0; diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 7aba03eb5..7070744b6 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -40,7 +40,7 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute /// \param theSubShape selected sub-shape (if null, the whole context is selected) /// \param theTemporarily if it is true, do not store and name the added in the data framework /// (used to remove immediately, without the following updates) - virtual void append(const ResultPtr& theContext, + virtual void append(const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false) = 0; @@ -67,7 +67,7 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute /// \param theTemporarily if it is true, it checks also the temporary added item /// \returns true if the pair is found in the attirbute virtual bool isInList( - const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily = false) = 0; /// The type of all elements selection