From: nds Date: Thu, 6 Apr 2017 14:05:39 +0000 (+0300) Subject: Issue #2109 trim - wrong result due to constarints X-Git-Tag: V_2.7.0~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=59f84b781e13321cf09c21606b195297fc4c47e5;p=modules%2Fshaper.git Issue #2109 trim - wrong result due to constarints --- diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index f2d2c4da8..9ad6f0db9 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -233,8 +233,8 @@ void SketchPlugin_Trim::execute() std::shared_ptr aStartShapePoint2d = convertPoint(aStartShapePoint); std::shared_ptr aLastShapePoint2d = convertPoint(aLastShapePoint); - std::set aFeaturesToDelete; - getConstraints(aFeaturesToDelete); + std::set aFeaturesToDelete, aFeaturesToUpdate; + getConstraints(aFeaturesToDelete, aFeaturesToUpdate); std::map > aBaseRefAttributes; std::list aRefsToFeature; @@ -414,6 +414,8 @@ void SketchPlugin_Trim::execute() ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + updateFeaturesAfterTrim(aFeaturesToUpdate); + // Send events to update the sub-features by the solver. if(isUpdateFlushed) { Events_Loop::loop()->setFlushed(anUpdateEvent, true); @@ -697,7 +699,8 @@ void SketchPlugin_Trim::getFeaturePoints(const FeaturePtr& theFeature, } } -void SketchPlugin_Trim::getConstraints(std::set& theFeaturesToDelete) +void SketchPlugin_Trim::getConstraints(std::set& theFeaturesToDelete, + std::set& theFeaturesToUpdate) { std::shared_ptr aData = data(); @@ -721,6 +724,8 @@ void SketchPlugin_Trim::getConstraints(std::set& theFeaturesToDelete aRefFeatureKind == SketchPlugin_MultiTranslation::ID() || aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID()) theFeaturesToDelete.insert(aRefFeature); + else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) + theFeaturesToUpdate.insert(aRefFeature); } } @@ -877,6 +882,27 @@ void SketchPlugin_Trim::removeReferencesToAttribute(const AttributePtr& theAttri Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); } +void SketchPlugin_Trim::updateFeaturesAfterTrim(const std::set& theFeaturesToUpdate) +{ + std::set::const_iterator anIt = theFeaturesToUpdate.begin(), + aLast = theFeaturesToUpdate.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aRefFeature = std::dynamic_pointer_cast(*anIt); + std::string aRefFeatureKind = aRefFeature->getKind(); + if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) { + std::shared_ptr aLenghtFeature = + std::dynamic_pointer_cast(*anIt); + if (aLenghtFeature.get()) { + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE())); + double aValue; + if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get()) + aValueAttr->setValue(aValue); + } + } + } +} + FeaturePtr SketchPlugin_Trim::trimLine(const std::shared_ptr& theStartShapePoint, const std::shared_ptr& theLastShapePoint, std::map >& theBaseRefAttributes, diff --git a/src/SketchPlugin/SketchPlugin_Trim.h b/src/SketchPlugin/SketchPlugin_Trim.h index 5791ff690..610ae1e1c 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.h +++ b/src/SketchPlugin/SketchPlugin_Trim.h @@ -126,7 +126,9 @@ private: /// Obtains those constraints of the feature that should be modified. output maps contain /// point of coincidence and attribute id to be modified after split /// \param theFeaturesToDelete [out] constrains that will be deleted after split - void getConstraints(std::set>& theFeaturesToDelete); + /// \param theFeaturesToUpdate [out] constrains that will be updated after split + void getConstraints(std::set>& theFeaturesToDelete, + std::set& theFeaturesToUpdate); /// Obtains references to feature point attributes and to feature, /// e.g. for feature line: 1st container is @@ -161,6 +163,10 @@ private: void removeReferencesToAttribute(const AttributePtr& theAttribute, std::map >& theBaseRefAttributes); + /// Updates line length if it exist in the list + /// \param theFeaturesToUpdate a constraints container + void updateFeaturesAfterTrim(const std::set& theFeaturesToUpdate); + /// Make the base object is splitted by the point attributes /// \param theBaseRefAttributes container of references to the attributes of base feature /// \param thePoints a list of points where coincidences will be build