]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchPlugin/SketchPlugin_Trim.cpp
Salome HOME
Get rid of compilation warnings. Part I.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Trim.cpp
index b5c215c629a7a03a734749a660293e142ffda615..53ca4deb1de651b370366bff5acd2e00965f6110 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -66,7 +66,6 @@
 
 #include <cmath>
 
-#define DEBUG_TRIM
 #ifdef DEBUG_TRIM
 #include <iostream>
 #endif
@@ -77,9 +76,6 @@
 
 static const double PI = 3.141592653589793238463;
 
-static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
-static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
-
 SketchPlugin_Trim::SketchPlugin_Trim()
 {
 }
@@ -373,7 +369,19 @@ void SketchPlugin_Trim::execute()
     {
       if (aRefIt->first->isEqual(aPoint)) {
         anInfo = aRefIt->second;
-        break;
+        // prefer a segment instead of a point, because further coincidence with a segment
+        // decreases only 1 DoF (instead of 2 for point) and prevents an overconstraint situation.
+        bool isEdge = false;
+        for (std::list<ObjectPtr>::const_iterator anIt = anInfo.second.begin();
+             anIt != anInfo.second.end() && !isEdge; ++anIt) {
+          ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
+          if (aResult) {
+            GeomShapePtr aShape = aResult->shape();
+            isEdge = aShape && aShape->isEdge();
+          }
+        }
+        if (isEdge)
+          break;
       }
     }
     const std::list<ObjectPtr>& anObjects = anInfo.second;
@@ -1050,13 +1058,18 @@ FeaturePtr SketchPlugin_Trim::trimClosed(const std::shared_ptr<GeomAPI_Pnt2d>& t
     const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
     std::list<AttributePtr> aRefsToParent;
     for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
-      if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
-          (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+      if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
         aRefsToParent.push_back(*aRef);
     }
     for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
-         aRef != aRefsToParent.end(); ++aRef)
+         aRef != aRefsToParent.end(); ++aRef) {
       std::dynamic_pointer_cast<ModelAPI_AttributeReference>(*aRef)->setValue(anNewFeature);
+
+      FeaturePtr anOwner = ModelAPI_Feature::feature((*aRef)->owner());
+      SketchPlugin_Tools::replaceInName(anOwner, aBaseFeature->name(), anNewFeature->name());
+      SketchPlugin_Tools::replaceInName(anOwner->lastResult(),
+          aBaseFeature->name(), anNewFeature->name());
+    }
   }
 
   const std::string& aStartAttrName = anNewFeature->getKind() == SketchPlugin_Arc::ID() ?