Salome HOME
Porting to SALOME_8.2.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_SketchEntity.h
index 8f716c79f1de1427c742db9c61afbc18f7b67255..dd7c0d36e805552e1c98da47747de8096d396545 100644 (file)
 
 #include <Config_PropManager.h>
 
-#define SKETCH_ENTITY_COLOR "#ff0000"
-#define SKETCH_EXTERNAL_COLOR "#00ff00"
-#define SKETCH_AUXILIARY_COLOR "#000000"
+#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. 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
@@ -46,6 +48,37 @@ 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;
+  }
+
+  /// Width of the auxiliary line
+  inline static const double SKETCH_LINE_WIDTH_AUXILIARY()
+  {
+    return 2;
+  }
+
+  /// Width of the line
+  inline static const double SKETCH_LINE_WIDTH()
+  {
+    return 3;
+  }
+
+  /// 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,7 +87,17 @@ 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;
+  }
+
+  /// Returns true of the feature is a copy of other feature
+  virtual bool isCopy() const
+  {
+    AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
+    if(anAttr.get()) {
+      return anAttr->value();
+    }
     return false;
   }
 
@@ -62,9 +105,25 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
   {
-    bool isCustomized = false;
+    /// 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, aDefault);
+      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
+    // 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;
 
@@ -85,21 +144,31 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
       aColor = Config_PropManager::color("Visualization", "sketch_entity_color",
                                           SKETCH_ENTITY_COLOR);
     }
-    if (!aColor.empty())
-      isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
+    if (!aColor.empty()) {
+      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(1) || isCustomized;
-        isCustomized = thePrs->setLineStyle(3) || isCustomized;
+        isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
+        isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
       }
       else {
-        isCustomized = thePrs->setWidth(3) || isCustomized;
-        isCustomized = thePrs->setLineStyle(0) || isCustomized;
+        isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
+        isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
       }
     }
     else if (aShapeType == 7) { // otherwise this is a vertex
-      //  thePrs->setPointMarker(6, 2.);
+      // 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()) {
+      double aWidth = thePrs->width();
+      isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
     }
     return isCustomized;
   }
@@ -107,6 +176,10 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
 protected:
   /// initializes mySketch
   SketchPlugin_SketchEntity();
+
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes(){};
+
 };
 
 #endif