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