Salome HOME
Issue #2299: Wrong face support of sketch in script from python dump
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Trim.cpp
index d67e97c8ce5aeac1bc27bae68b278936df555a24..74be0dc1f4854be50af6d6ec28101fe528128e65 100644 (file)
@@ -54,6 +54,7 @@
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
 #include <SketchPlugin_Point.h>
+#include <SketchPlugin_Projection.h>
 
 #include <ModelAPI_EventReentrantMessage.h>
 
@@ -378,7 +379,7 @@ void SketchPlugin_Trim::execute()
       anIt != aLast; anIt++) {
     AttributePtr anAttribute = *anIt;
 
-    if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences))
+    if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences, aFeaturesToDelete))
       continue;
 
     // move tangency constraint to the nearest feature if possible
@@ -532,7 +533,8 @@ std::string SketchPlugin_Trim::processEvent(const std::shared_ptr<Events_Message
 }
 
 bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
-                                const std::set<AttributePoint2DPtr>& theFurtherCoincidences)
+                                const std::set<AttributePoint2DPtr>& theFurtherCoincidences,
+                                std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete)
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
   if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
@@ -550,12 +552,9 @@ bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribu
     AttributePoint2DPtr aPointAttribute = (*anIt);
     std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
     if (aPoint2d->isEqual(aRefPnt2d)) {
-      AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
-                                                                           theAttribute);
-      if (aRefAttr.get()) {
-        aRefAttr->setAttr(aPointAttribute);
-        aFoundPoint = true;
-      }
+      // create new coincidence and then remove the old one
+      createConstraint(SketchPlugin_ConstraintCoincidence::ID(), aRefPointAttr, aPointAttribute);
+      theFeaturesToDelete.insert(aFeature);
     }
   }
   return aFoundPoint;
@@ -1416,7 +1415,7 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject,
                          std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
     for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) {
       FeaturePtr aFeature = aSketchComposite->subFeature(i);
-      if (aFeature.get())
+      if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
         aFeatures.push_back(aFeature);
     }
     ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);