Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_SketchEntity.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_SketchEntity.h
4 // Created:     05 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef SketchPlugin_SketchEntity_H_
8 #define SketchPlugin_SketchEntity_H_
9
10 #include "SketchPlugin.h"
11 #include "SketchPlugin_Feature.h"
12
13 #include <ModelAPI_CompositeFeature.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_AISObject.h>
16 #include <ModelAPI_Document.h>
17 #include <ModelAPI_AttributeSelection.h>
18 #include <ModelAPI_AttributeBoolean.h>
19 #include <GeomAPI_ICustomPrs.h>
20
21 #include <Config_PropManager.h>
22
23 #define SKETCH_EDGE_COLOR "#ff0000"
24 #define SKETCH_POINT_COLOR "#ff0000"
25 #define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
26 #define SKETCH_CONSTRUCTION_COLOR "#000000"
27
28 /**\class SketchPlugin_SketchEntity
29  * \ingroup Plugins
30  * \brief Sketch Entity for creation of the new feature in PartSet. This is an abstract class to give
31  * an interface to create the entity features such as line, circle, arc and point.
32  */
33 class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
34 {
35  public:
36   /// Reference to the construction type of the feature
37   inline static const std::string& CONSTRUCTION_ID()
38   {
39     static const std::string MY_CONSTRUCTION_ID("Construction");
40     return MY_CONSTRUCTION_ID;
41   }
42
43   /// Reference to the external edge or vertex as a AttributeSelection
44   inline static const std::string& EXTERNAL_ID()
45   {
46     static const std::string MY_EXTERNAL_ID("External");
47     return MY_EXTERNAL_ID;
48   }
49
50   /// Request for initialization of data model of the feature: adding all attributes
51   virtual void initAttributes();
52
53   /// Returns true of the feature is created basing on the external shape of not-this-sketch object
54   virtual bool isExternal() const
55   {
56     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
57     if (aAttr)
58       return aAttr->context().get() != NULL;
59     return false;
60   }
61
62   /// Customize presentation of the feature
63   virtual void customisePresentation(AISObjectPtr thePrs)
64   {
65     std::vector<int> aRGB;
66   
67     int aShapeType = thePrs->getShapeType();
68     if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
69       return;
70
71     std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
72                                    data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
73     bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
74     if (aShapeType == 6) { // if this is an edge
75       if (isConstruction) {
76         thePrs->setWidth(1);
77         thePrs->setLineStyle(3);
78         aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
79                                          SKETCH_CONSTRUCTION_COLOR);
80       }
81       else {
82         thePrs->setWidth(3);
83         thePrs->setLineStyle(0);
84         if (isExternal()) {
85           // Set color from preferences
86           aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
87                                            SKETCH_EXTERNAL_EDGE_COLOR);
88         }
89         else {
90           // Set color from preferences
91           aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
92                                            SKETCH_EDGE_COLOR);
93         }
94       }
95     }
96     else if (aShapeType == 7) { // otherwise this is a vertex
97       //  thePrs->setPointMarker(6, 2.);
98       // Set color from preferences
99       aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
100                                        SKETCH_POINT_COLOR);
101     }
102
103     if (!aRGB.empty())
104       thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
105   }
106
107 protected:
108   /// initializes mySketch
109   SketchPlugin_SketchEntity();
110 };
111
112 #endif