Salome HOME
Color preferences for the sketch entities.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_Feature.h
4 // Created:     27 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef SketchPlugin_Feature_H_
8 #define SketchPlugin_Feature_H_
9
10 #include "SketchPlugin.h"
11 #include <ModelAPI_CompositeFeature.h>
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_AISObject.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_AttributeSelection.h>
16 #include <GeomAPI_ICustomPrs.h>
17
18 #include <Config_PropManager.h>
19
20 #define SKETCH_EDGE_COLOR "#ff0000"
21 #define SKETCH_POINT_COLOR "#ff0000"
22 #define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
23
24 class SketchPlugin_Sketch;
25 class GeomAPI_Pnt2d;
26 class Handle_AIS_InteractiveObject;
27
28 /**\class SketchPlugin_Feature
29  * \ingroup Plugins
30  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
31  * an interface to create the sketch feature preview.
32  */
33 class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
34 {
35  public:
36   /// Reference to the external edge or vertex as a AttributeSelection
37   inline static const std::string& EXTERNAL_ID()
38   {
39     static const std::string MY_EXTERNAL_ID("External");
40     return MY_EXTERNAL_ID;
41   }
42
43   /// Returns true if this feature must be displayed in the history (top level of Part tree)
44   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
45   {
46     return false;
47   }
48
49   /// Moves the feature
50   /// \param theDeltaX the delta for X coordinate is moved
51   /// \param theDeltaY the delta for Y coordinate is moved
52   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
53
54   /// Return the distance between the feature and the point
55   /// \param thePoint the point
56   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
57
58   /// Construction result is allways recomuted on the fly
59   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
60
61   /// Returns true is sketch element is under the rigid constraint
62   SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
63
64   /// Returns true of the feature is created basing on the external shape of not-this-sketch object
65   inline bool isExternal() const
66   {
67     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
68     if (aAttr)
69       return aAttr->context().get() != NULL;
70     return false;
71   }
72
73   /// Customize presentation of the feature
74   virtual void customisePresentation(AISObjectPtr thePrs)
75   {
76     std::vector<int> aRGB;
77     // if this is an edge
78     if (thePrs->getShapeType() == 6) {
79       thePrs->setWidth(3);
80       if (isExternal()) {
81         // Set color from preferences
82         aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
83                                          SKETCH_EXTERNAL_EDGE_COLOR);
84       }
85       else {
86         // Set color from preferences
87         aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
88                                          SKETCH_EDGE_COLOR);
89       }
90     }
91     else if (thePrs->getShapeType() == 7) { // otherwise this is a vertex
92       // Set color from preferences
93       aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
94                                        SKETCH_POINT_COLOR);
95     }
96     // if this is a vertex
97     //else if (thePrs->getShapeType() == 7)
98     //  thePrs->setPointMarker(6, 2.);
99     if (!aRGB.empty())
100       thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
101   }
102
103   /// removes also all sub-sketch elements
104   SKETCHPLUGIN_EXPORT virtual void erase()
105   {
106     /*SketchPlugin_Sketch* aSketch = sketch();
107     if (aSketch)
108       aSketch->removeFeature(this);
109       */
110     ModelAPI_Feature::erase();
111   }
112
113   /// Returns the sketch of this feature
114   SketchPlugin_Sketch* sketch();
115 protected:
116   /// Sets the higher-level feature for the sub-feature (sketch for line)
117   void setSketch(SketchPlugin_Sketch* theSketch)
118   {
119     mySketch = theSketch;
120   }
121   /// initializes mySketch
122   SketchPlugin_Feature();
123
124   friend class SketchPlugin_Sketch;
125
126  private:
127   std::shared_ptr<GeomAPI_Shape> myPreview;  ///< the preview shape
128   SketchPlugin_Sketch* mySketch;  /// sketch that contains this feature
129 };
130
131 #endif