Salome HOME
Fix for the issue #2225 : Incorrect face naming when creating a pipe from a face...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_SketchEntity.h
index dd7c0d36e805552e1c98da47747de8096d396545..c207dd72b264b3f279483e3fa17021978e59a006 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        SketchPlugin_SketchEntity.h
-// Created:     05 Mar 2015
-// Author:      Natalia ERMOLAEVA
+// Copyright (C) 2014-2019  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
+//
 
 #ifndef SketchPlugin_SketchEntity_H_
 #define SketchPlugin_SketchEntity_H_
 #include "SketchPlugin_Feature.h"
 
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Session.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_AISObject.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <GeomAPI_ICustomPrs.h>
 
 #include <Config_PropManager.h>
 
-#define SKETCH_ENTITY_COLOR "225,0,0"
-#define SKETCH_EXTERNAL_COLOR "170,0,225"
-#define SKETCH_AUXILIARY_COLOR "0,85,0"
-#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
-
 /**\class SketchPlugin_SketchEntity
  * \ingroup Plugins
  * \brief Sketch Entity for creation of the new feature in PartSet. 
@@ -101,6 +111,7 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
     return false;
   }
 
+// LCOV_EXCL_START
   /// Customize presentation of the feature
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
@@ -115,7 +126,7 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
       std::string aSection, aName, aDefault;
       theResult->colorConfigInfo(aSection, aName, aDefault);
       std::vector<int> aColor;
-      aColor = Config_PropManager::color(aSection, aName, aDefault);
+      aColor = Config_PropManager::color(aSection, aName);
       thePrs->setColor(aColor[0], aColor[1], aColor[2]);
     }
 
@@ -133,18 +144,22 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
                                     data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
     bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
     if (isConstruction) {
-      aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color",
-                                         SKETCH_AUXILIARY_COLOR);
+      aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
     }
     else if (isExternal()) {
-      aColor = Config_PropManager::color("Visualization", "sketch_external_color",
-                                        SKETCH_EXTERNAL_COLOR);
+      aColor = Config_PropManager::color("Visualization", "sketch_external_color");
     }
     else {
-      aColor = Config_PropManager::color("Visualization", "sketch_entity_color",
-                                          SKETCH_ENTITY_COLOR);
+      aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
     }
     if (!aColor.empty()) {
+      if (theResult.get() && ModelAPI_Session::get()->isOperation()) {
+        AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+        aColorAttr->setSize(3);
+        // Set the color attribute in order do not use default colors in the perasentation object
+        for (int i = 0; i < 3; i++)
+          aColorAttr->setValue(i, aColor[i]);
+      }
       thePrs->setColor(aColor[0], aColor[1], aColor[2]);
       for (int i = 0; i < 3 && !isCustomized; i++)
         isCustomized = aColor[i] != aPrevColor[i];
@@ -170,8 +185,14 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
       double aWidth = thePrs->width();
       isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
     }
+
+    if (!theResult.get()) {
+      double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
+      thePrs->setDeflection(aDeflection);
+    }
     return isCustomized;
   }
+// LCOV_EXCL_STOP
 
 protected:
   /// initializes mySketch