Salome HOME
COPY attribute in SketchEntity now persistent
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_SketchEntity.h
index c0c0925638556abf9425de6208d45c1d184f8553..16101d1866aaac9b4c70b587adf8e23782152e7e 100644 (file)
 
 #include <Config_PropManager.h>
 
-#define SKETCH_EDGE_COLOR "#ff0000"
-#define SKETCH_POINT_COLOR "#ff0000"
-#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
-#define SKETCH_CONSTRUCTION_COLOR "#000000"
+#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
@@ -34,10 +33,10 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
 {
  public:
   /// Reference to the construction type of the feature
-  inline static const std::string& CONSTRUCTION_ID()
+  inline static const std::string& AUXILIARY_ID()
   {
-    static const std::string MY_CONSTRUCTION_ID("Construction");
-    return MY_CONSTRUCTION_ID;
+    static const std::string MY_AUXILIARY_ID("Auxiliary");
+    return MY_AUXILIARY_ID;
   }
 
   /// Reference to the external edge or vertex as a AttributeSelection
@@ -47,6 +46,13 @@ 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;
+  }
+
   /// Request for initialization of data model of the feature: adding all attributes
   virtual void initAttributes();
 
@@ -59,54 +65,76 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
     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;
+  }
+
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs)
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
   {
-    std::vector<int> aRGB;
-  
+    bool isCustomized = false;
     int aShapeType = thePrs->getShapeType();
-    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
-      return;
+    // 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;
 
-    std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
-                                   data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
-    bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
-    if (aShapeType == 6) { // if this is an edge
+    // 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);
+    }
+    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) {
-        thePrs->setWidth(1);
-        thePrs->setLineStyle(3);
-        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
-                                         SKETCH_CONSTRUCTION_COLOR);
+        isCustomized = thePrs->setWidth(1) || isCustomized;
+        isCustomized = thePrs->setLineStyle(3) || isCustomized;
       }
       else {
-        thePrs->setWidth(3);
-        thePrs->setLineStyle(0);
-        if (isExternal()) {
-          // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
-                                           SKETCH_EXTERNAL_EDGE_COLOR);
-        }
-        else {
-          // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
-                                           SKETCH_EDGE_COLOR);
-        }
+        isCustomized = thePrs->setWidth(3) || isCustomized;
+        isCustomized = thePrs->setLineStyle(0) || isCustomized;
       }
     }
     else if (aShapeType == 7) { // otherwise this is a vertex
-      //  thePrs->setPointMarker(6, 2.);
-      // Set color from preferences
-      aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
-                                       SKETCH_POINT_COLOR);
+      // 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 (!aRGB.empty())
-      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+    if(isCopy()) {
+      double aWidth = thePrs->width();
+      isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
+    }
+    return isCustomized;
   }
 
 protected:
   /// initializes mySketch
   SketchPlugin_SketchEntity();
+
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes(){};
+
 };
 
 #endif