Salome HOME
Construction elements are auxiliary entities:
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.h
index 5563c90135b31b815bb9398b0e2d185a78470395..9e22b9ce812c3472fd1fe948c55b4ec6106cb57e 100644 (file)
@@ -1,37 +1,59 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 // File:        SketchPlugin_Feature.h
 // Created:     27 Mar 2014
 // Author:      Mikhail PONIKAROV
 
-#ifndef SketchPlugin_Feature_HeaderFile
-#define SketchPlugin_Feature_HeaderFile
+#ifndef SketchPlugin_Feature_H_
+#define SketchPlugin_Feature_H_
 
 #include "SketchPlugin.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <GeomAPI_ICustomPrs.h>
+
+#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"
 
 class SketchPlugin_Sketch;
 class GeomAPI_Pnt2d;
+class Handle_AIS_InteractiveObject;
 
 /**\class SketchPlugin_Feature
- * \ingroup DataModel
+ * \ingroup Plugins
  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
  * an interface to create the sketch feature preview.
  */
-class SketchPlugin_Feature: public ModelAPI_Feature
+class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
 {
-public:
-  /// Returns the sketch preview
-  /// \param theSketch the owner of this feature
-  /// \return the built preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
+ public:
+  /// Reference to the construction type of the feature
+  inline static const std::string& CONSTRUCTION_ID()
+  {
+    static const std::string MY_CONSTRUCTION_ID("Construction");
+    return MY_CONSTRUCTION_ID;
+  }
 
-  /// Adds sub-feature of the higher level feature (sub-element of the sketch)
-  /// \param theFeature sub-feature
-  SKETCHPLUGIN_EXPORT virtual const void addSub(
-    const FeaturePtr& theFeature) = 0;
+  /// Reference to the external edge or vertex as a AttributeSelection
+  inline static const std::string& EXTERNAL_ID()
+  {
+    static const std::string MY_EXTERNAL_ID("External");
+    return MY_EXTERNAL_ID;
+  }
 
   /// Returns true if this feature must be displayed in the history (top level of Part tree)
-  SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;}
+  SKETCHPLUGIN_EXPORT virtual bool isInHistory()
+  {
+    return false;
+  }
 
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
@@ -40,27 +62,80 @@ public:
 
   /// Return the distance between the feature and the point
   /// \param thePoint the point
-  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
+  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
+
+  /// Construction result is allways recomuted on the fly
+  SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
+
+  /// Returns true of the feature is created basing on the external shape of not-this-sketch object
+  inline bool isExternal() const
+  {
+    AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
+    if (aAttr)
+      return aAttr->context().get() != NULL;
+    return false;
+  }
+
+  /// Customize presentation of the feature
+  virtual void customisePresentation(AISObjectPtr thePrs)
+  {
+    std::vector<int> aRGB;
+  
+    int aShapeType = thePrs->getShapeType();
+    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
+      return;
+
+    bool isConstruction = data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value();
+    if (aShapeType == 6) { // if this is an edge
+      if (isConstruction) {
+        thePrs->setWidth(1);
+        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
+                                         SKETCH_CONSTRUCTION_COLOR);
+      }
+      else {
+        thePrs->setWidth(3);
+        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);
+        }
+      }
+    }
+    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);
+    }
+
+    if (!aRGB.empty())
+      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+  }
 
-protected:
-  /// Set the shape to the internal preview field
-  /// \param theShape a preview shape
-  void setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape); ///< the preview shape
-  /// Return the shape from the internal preview field
-  /// \return theShape a preview shape
-  const boost::shared_ptr<GeomAPI_Shape>& getPreview() const;
-  /// Sets the higher-level feature for the sub-feature (sketch for line)
-  void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
   /// Returns the sketch of this feature
   SketchPlugin_Sketch* sketch();
+protected:
+  /// Sets the higher-level feature for the sub-feature (sketch for line)
+  void setSketch(SketchPlugin_Sketch* theSketch)
+  {
+    mySketch = theSketch;
+  }
   /// initializes mySketch
   SketchPlugin_Feature();
 
   friend class SketchPlugin_Sketch;
 
-private:
-  boost::shared_ptr<GeomAPI_Shape> myPreview; ///< the preview shape
-  SketchPlugin_Sketch* mySketch; /// sketch that contains this feature
+ private:
+  std::shared_ptr<GeomAPI_Shape> myPreview;  ///< the preview shape
+  SketchPlugin_Sketch* mySketch;  /// sketch that contains this feature
 };
 
 #endif