Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_SketchEntity.h
index 95c4505b6a8034a1489dba34014ba2186e5aa19f..84214ce014abd05eca8dcb13bfe5709c89061bf8 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-2022  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"
-
 /**\class SketchPlugin_SketchEntity
  * \ingroup Plugins
- * \brief Sketch Entity for creation of the new feature in PartSet. This is an abstract class to give
+ * \brief Sketch Entity for creation of the new feature in PartSet. 
+ * This is an abstract class to give
  * an interface to create the entity features such as line, circle, arc and point.
  */
-class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
+class SketchPlugin_SketchEntity : public SketchPlugin_Feature //, public GeomAPI_ICustomPrs
 {
  public:
   /// Reference to the construction type of the feature
@@ -46,6 +58,44 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
     return MY_EXTERNAL_ID;
   }
 
+  /// Reference to the copy type of the feature
+  inline static const std::string& COPY_ID()
+  {
+    static const std::string MY_COPY_ID("Copy");
+    return MY_COPY_ID;
+  }
+
+  /// Reference to the parent feature if exist
+  inline static const std::string& PARENT_ID()
+  {
+    static const std::string& MY_PARENT_ID("ParentFeature");
+    return MY_PARENT_ID;
+  }
+
+  /// Width of the auxiliary line
+  inline static const int SKETCH_LINE_WIDTH_AUXILIARY()
+  {
+    return 2;
+  }
+
+  /// Width of the line
+  inline static const int SKETCH_LINE_WIDTH()
+  {
+    return Config_PropManager::integer("Visualization", "sketch_line_width");
+  }
+
+  /// Style of the auxiliary line
+  inline static const int SKETCH_LINE_STYLE_AUXILIARY()
+  {
+    return  3;
+  }
+
+  /// Style of the line
+  inline static const int SKETCH_LINE_STYLE()
+  {
+    return  0;
+  }
+
   /// Request for initialization of data model of the feature: adding all attributes
   virtual void initAttributes();
 
@@ -54,59 +104,132 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
   {
     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
     if (aAttr)
-      return aAttr->context().get() != NULL;
+      return aAttr->context().get() != NULL && !aAttr->isInvalid();
     return false;
   }
 
-  /// Customize presentation of the feature
-  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+  /// Returns true of the feature is a copy of other feature
+  virtual bool isCopy() const
   {
-    bool isCustomized = false;
-    int aShapeType = thePrs->getShapeType();
-    // a compound is processed like the edge because the arc feature uses the compound for presentable AIS
-    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
-      return false;
-
-    // set color from preferences
-    std::vector<int> aColor;
-    std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
-                                    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);
-    }
-    else if (isExternal()) {
-      aColor = Config_PropManager::color("Visualization", "sketch_external_color",
-                                        SKETCH_EXTERNAL_COLOR);
-    }
-    else {
-      aColor = Config_PropManager::color("Visualization", "sketch_entity_color",
-                                          SKETCH_ENTITY_COLOR);
+    AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
+    if(anAttr.get()) {
+      return anAttr->value();
     }
-    if (!aColor.empty())
-      isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
-
-    if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
-      if (isConstruction) {
-        isCustomized = thePrs->setWidth(1) || isCustomized;
-        isCustomized = thePrs->setLineStyle(3) || isCustomized;
-      }
-      else {
-        isCustomized = thePrs->setWidth(3) || isCustomized;
-        isCustomized = thePrs->setLineStyle(0) || isCustomized;
-      }
-    }
-    else if (aShapeType == 7) { // otherwise this is a vertex
-      //  thePrs->setPointMarker(6, 2.);
-    }
-    return isCustomized;
+    return false;
   }
 
+  //virtual bool isIncludeToResult() const
+  //{
+  //  AttributeBooleanPtr anAttr;
+  //  std::set<AttributePtr> aRefsToMe = data()->refsToMe();
+  //  std::set<AttributePtr>::const_iterator aIt;
+  //  for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
+  //    if ((*aIt)->id() == "ProjectedFeature") {
+  //      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
+  //      if (aFeature.get()) {
+  //        anAttr = aFeature->data()->boolean("IncludeToResult");
+  //        if (anAttr.get())
+  //          return anAttr->value();
+  //      }
+  //    }
+  //  }
+  //  return true;
+  //}
+
+// LCOV_EXCL_START
+  /// Customize presentation of the feature
+  //virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+  //                                   std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+  //{
+  //  /// Store previous color values of the presentation to check it after setting specific entity
+  //  /// color. Default color is set into presentation to have not modified isCustomized state
+  //  /// after default customize prs is completed.
+  //  std::vector<int> aPrevColor;
+  //  aPrevColor.resize(3);
+  //  thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
+  //  if (theResult.get()) {
+  //    std::string aSection, aName, aDefault;
+  //    theResult->colorConfigInfo(aSection, aName, aDefault);
+  //    std::vector<int> aColor;
+  //    aColor = Config_PropManager::color(aSection, aName);
+  //    thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+  //  }
+
+  //  bool isCustomized = theDefaultPrs.get() != NULL &&
+  //                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+  //  int aShapeType = thePrs->getShapeType();
+  //  // a compound is processed like the edge because the
+  //  // arc feature uses the compound for presentable AIS
+  //  if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
+  //    return false;
+
+  //  // set color from preferences
+  //  std::vector<int> aColor;
+  //  std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
+  //                                  data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
+  //  bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
+  //  if (isConstruction) {
+  //    aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
+  //  }
+  //  else if (isExternal()) {
+  //    aColor = Config_PropManager::color("Visualization", "sketch_external_color");
+  //  }
+  //  else {
+  //    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 presentation 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];
+  //  }
+
+  //  if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
+  //    if (isConstruction) {
+  //      isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
+  //      isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
+  //    }
+  //    else {
+  //      isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
+  //      isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
+  //    }
+  //  }
+  //  else if (aShapeType == 7) { // otherwise this is a vertex
+  //    // The width value do not have effect on the point presentation.
+  //    // It is defined in order to extend selection area of the object.
+  //    thePrs->setWidth(17);
+  //  //  thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
+  //  }
+  //  if(isCopy() && !isIncludeToResult()) {
+  //    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
   SketchPlugin_SketchEntity();
+
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes(){};
+
+  /// \brief Initializes attributes of derived class which were added recently.
+  virtual void initDerivedClassAttributes2(){};
+
 };
 
 #endif