Salome HOME
Porting to the current version of TInspector.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Projection.cpp
index 36df5bb1e27395b970d297e6ac7a5d35bc548026..ef83cce1d2db49d8a2b7fc0c3302de40b4908eaa 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:    SketchPlugin_Projection.cpp
-// Created: 07 May 2014
-// Author:  Artem ZHIDKOV
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include <SketchPlugin_Projection.h>
 
@@ -18,6 +32,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>
@@ -65,6 +80,10 @@ void SketchPlugin_Projection::execute()
 
     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)
@@ -89,7 +108,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
   std::shared_ptr<GeomAPI_Edge> anEdge;
   if (aExtFeature && aExtFeature->value() && aExtFeature->value()->isEdge()) {
     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aExtFeature->value()));
-  } else if (aExtFeature->context() && aExtFeature->context()->shape() && aExtFeature->context()->shape()->isEdge()) {
+  } else if (aExtFeature->context() && aExtFeature->context()->shape() &&
+             aExtFeature->context()->shape()->isEdge()) {
     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aExtFeature->context()->shape()));
   }
   if (!anEdge.get())
@@ -107,7 +127,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);
     }
@@ -117,7 +140,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
 
   ResultConstructionPtr aResult =
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(lastResult());
-  if (aResult && aResult->shape()) {
+  if (aResult && aResult->shape() && theID == EXTERNAL_FEATURE_ID()) {
     aResult->setShape(std::shared_ptr<GeomAPI_Edge>());
     aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
   }
@@ -153,7 +176,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
       aProjection = sketch()->addFeature(SketchPlugin_Circle::ID());
 
     // update attributes of projection
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+    std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         aProjection->attribute(SketchPlugin_Circle::CENTER_ID()));
     aCenterPnt->setValue(aCenterInSketch);
     aProjection->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aRadius);
@@ -172,26 +196,24 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
       aProjection = sketch()->addFeature(SketchPlugin_Arc::ID());
 
     // update attributes of projection
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+    std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         aProjection->attribute(SketchPlugin_Arc::CENTER_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+    std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         aProjection->attribute(SketchPlugin_Arc::START_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+    std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         aProjection->attribute(SketchPlugin_Arc::END_ID()));
     aStartPnt->setValue(aFirstInSketch);
     aEndPnt->setValue(aLastInSketch);
     aCenterPnt->setValue(aCenterInSketch);
   }
 
+  aProjection->boolean(COPY_ID())->setValue(true);
   aProjection->execute();
   aRefAttr->setObject(aProjection);
 
-  if (!hasPrevProj) {
-    FeaturePtr aFixed = sketch()->addFeature(SketchPlugin_ConstraintRigid::ID());
-    aFixed->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(aProjection->lastResult());
-    aFixed->execute();
-  }
-
   if (theID == EXTERNAL_FEATURE_ID()) {
     selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->value());