Salome HOME
Incorrect dumping of parts with user-defined names (issue #1804)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Projection.cpp
index 319f200cb3069c54aa30ec91c47907a27d60f2bf..ac8b5679743382f6c05902e76c437ee3fe34e6e0 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Circ.h>
 #include <GeomAPI_Edge.h>
 
 static const double tolerance = 1.e-7;
 
-static std::shared_ptr<GeomAPI_Edge> emptyEdge()
-{
-  static std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
-  return anEdge;
-}
-
 SketchPlugin_Projection::SketchPlugin_Projection()
     : SketchPlugin_SketchEntity(),
       myIsComputing(false)
@@ -64,13 +59,17 @@ void SketchPlugin_Projection::execute()
 
   if (!lastResult().get() && aProjection->lastResult().get()) {
     ResultConstructionPtr aConstr = document()->createConstruction(data());
-    aConstr->setShape(emptyEdge());
+    aConstr->setShape(aProjection->lastResult()->shape());
     aConstr->setIsInHistory(false);
     aConstr->setDisplayed(false);
     setResult(aConstr);
 
     aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
   }
+
+  // is sketch plane is changed (issue 1791), attribute of projection is not changed, but
+  // projection must be fully recomputed
+  computeProjection(EXTERNAL_FEATURE_ID());
 }
 
 void SketchPlugin_Projection::move(double theDeltaX, double theDeltaY)
@@ -113,7 +112,10 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
         (anEdge->isCircle() && aProjection->getKind() != SketchPlugin_Circle::ID()) ||
         (anEdge->isArc() && aProjection->getKind() != SketchPlugin_Arc::ID())) {
       DocumentPtr aDoc = sketch()->document();
-      aDoc->removeFeature(aProjection);
+
+      std::set<FeaturePtr> aFeaturesToBeRemoved;
+      aFeaturesToBeRemoved.insert(aProjection);
+      ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved);
       aProjection = FeaturePtr();
       aRefAttr->setObject(aProjection);
     }
@@ -189,6 +191,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     aCenterPnt->setValue(aCenterInSketch);
   }
 
+  aProjection->boolean(COPY_ID())->setValue(true);
   aProjection->execute();
   aRefAttr->setObject(aProjection);
 
@@ -199,10 +202,10 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
   }
 
   if (theID == EXTERNAL_FEATURE_ID()) {
-    selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->context()->shape());
+    selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->value());
 
     if (aResult) {
-      aResult->setShape(emptyEdge());
+      aResult->setShape(aProjection->lastResult()->shape());
       setResult(aResult);
       aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
     }