Salome HOME
Import of edges participating to the result of the sketch
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index ca60111969f1ee5646b8cf1599b42e5353ba0a61..b0660a958229009b031b28166fe51419621a8db7 100755 (executable)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        SketchPlugin_Sketch.cxx
-// Created:     27 Mar 2014
-// Author:      Mikhail PONIKAROV
+// 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 <Config_PropManager.h>
 
@@ -29,6 +43,7 @@
 
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Projection.h>
 #include <SketchPlugin_SketchEntity.h>
 #include <SketchPlugin_Tools.h>
 
@@ -39,8 +54,6 @@
 #include <math.h>
 #include <vector>
 
-using namespace std;
-
 SketchPlugin_Sketch::SketchPlugin_Sketch()
 {
 }
@@ -90,10 +103,14 @@ void SketchPlugin_Sketch::execute()
     if (aFeature) {
       if (!aFeature->sketch()) // on load document the back references are missed
         aFeature->setSketch(this);
-      // do not include the external edges into the result
+      // do not include into the result the external edges with disabled flag "Include into result"
       if (aFeature->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())) {
-        if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->context())
-          continue;
+        if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->context()) {
+          AttributeBooleanPtr aKeepResult =
+              aFeature->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT());
+          if (!aKeepResult || !aKeepResult->value())
+            continue;
+        }
       }
       // do not include the construction entities in the result
       if (aFeature->data()->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID())) {
@@ -141,6 +158,7 @@ std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string th
   }
    // set as current also after it becomes sub to set correctly enabled for other sketch subs
   document()->setCurrentFeature(aNew, false);
+
   return aNew;
 }
 
@@ -214,9 +232,10 @@ bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
 
 void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
   if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
-    std::shared_ptr<GeomAPI_Shape> aSelection =
-      data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
-    if (aSelection) { // update arguments due to the selection value
+    AttributeSelectionPtr aSelAttr = selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+    if (aSelAttr->context().get()) { // update arguments due to the selection value
+      std::shared_ptr<GeomAPI_Shape> aSelection = aSelAttr->value();
+      if (!aSelection.get()) aSelection = aSelAttr->context()->shape();
       // update the sketch plane
       std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
       std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
@@ -297,8 +316,8 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur
   theFeature->data()->copyTo(aNewFeature->data());
   // external state should not be copied as a new object is an object of the current sketch
   if (theFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()).get())
-    theFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(ResultPtr(),
-                                                                              GeomShapePtr());
+    aNewFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(ResultPtr(),
+                                                                               GeomShapePtr());
   aNewFeature->data()->setName(aUniqueFeatureName);
   // text expressions could block setValue of some attributes
   SketchPlugin_Tools::clearExpressions(aNewFeature);