Salome HOME
Issue #2109 trim - wrong result due to constarints
authornds <nds@opencascade.com>
Thu, 6 Apr 2017 14:05:39 +0000 (17:05 +0300)
committernds <nds@opencascade.com>
Thu, 6 Apr 2017 14:12:55 +0000 (17:12 +0300)
src/SketchPlugin/SketchPlugin_Trim.cpp
src/SketchPlugin/SketchPlugin_Trim.h

index f2d2c4da8bc856f4ef3492a3152cf05b32eece81..9ad6f0db9ecb71e6b63ee53c4f49d71abd29d794 100644 (file)
@@ -233,8 +233,8 @@ void SketchPlugin_Trim::execute()
   std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
   std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
 
-  std::set<FeaturePtr> aFeaturesToDelete;
-  getConstraints(aFeaturesToDelete);
+  std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
+  getConstraints(aFeaturesToDelete, aFeaturesToUpdate);
 
   std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
   std::list<AttributePtr> 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<FeaturePtr>& theFeaturesToDelete)
+void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
+                                       std::set<FeaturePtr>& theFeaturesToUpdate)
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
 
@@ -721,6 +724,8 @@ void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& 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<FeaturePtr>& theFeaturesToUpdate)
+{
+  std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
+                                       aLast = theFeaturesToUpdate.end();
+  for (; anIt != aLast; anIt++) {
+    FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+    std::string aRefFeatureKind = aRefFeature->getKind();
+    if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
+      std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
+                              std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
+      if (aLenghtFeature.get()) {
+        std::shared_ptr<ModelAPI_AttributeDouble> 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<GeomAPI_Pnt2d>& theStartShapePoint,
                   const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
                   std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
index 5791ff690c450125bc1588654bb7bd0cade6ada8..610ae1e1c7800e3405496f93ffcc4a2a085fd0ba 100644 (file)
@@ -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<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
+  /// \param theFeaturesToUpdate [out] constrains that will be updated after split
+  void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
+                      std::set<FeaturePtr>& 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<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
 
+   /// Updates line length if it exist in the list
+  /// \param theFeaturesToUpdate a constraints container
+  void updateFeaturesAfterTrim(const std::set<FeaturePtr>& 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