Salome HOME
Update all arc attributes on execute() (issue #1339)
[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_ENTITY_COLOR "225,0,0"
24 #define SKETCH_EXTERNAL_COLOR "170,0,225"
25 #define SKETCH_AUXILIARY_COLOR "0,85,0"
26 #define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
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& AUXILIARY_ID()
38   {
39     static const std::string MY_AUXILIARY_ID("Auxiliary");
40     return MY_AUXILIARY_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   /// Reference to the copy type of the feature
51   inline static const std::string& COPY_ID()
52   {
53     static const std::string MY_COPY_ID("Copy");
54     return MY_COPY_ID;
55   }
56
57   /// Request for initialization of data model of the feature: adding all attributes
58   virtual void initAttributes();
59
60   /// Returns true of the feature is created basing on the external shape of not-this-sketch object
61   virtual bool isExternal() const
62   {
63     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
64     if (aAttr)
65       return aAttr->context().get() != NULL;
66     return false;
67   }
68
69   /// Returns true of the feature is a copy of other feature
70   virtual bool isCopy() const
71   {
72     AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
73     if(anAttr.get()) {
74       return anAttr->value();
75     }
76     return false;
77   }
78
79   /// Customize presentation of the feature
80   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
81                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
82   {
83     bool isCustomized = false;
84     int aShapeType = thePrs->getShapeType();
85     // a compound is processed like the edge because the arc feature uses the compound for presentable AIS
86     if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
87       return false;
88
89     // set color from preferences
90     std::vector<int> aColor;
91     std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
92                                     data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
93     bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
94     if (isConstruction) {
95       aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color",
96                                          SKETCH_AUXILIARY_COLOR);
97     }
98     else if (isExternal()) {
99       aColor = Config_PropManager::color("Visualization", "sketch_external_color",
100                                         SKETCH_EXTERNAL_COLOR);
101     }
102     else {
103       aColor = Config_PropManager::color("Visualization", "sketch_entity_color",
104                                           SKETCH_ENTITY_COLOR);
105     }
106     if (!aColor.empty())
107       isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
108
109     if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
110       if (isConstruction) {
111         isCustomized = thePrs->setWidth(1) || isCustomized;
112         isCustomized = thePrs->setLineStyle(3) || isCustomized;
113       }
114       else {
115         isCustomized = thePrs->setWidth(3) || isCustomized;
116         isCustomized = thePrs->setLineStyle(0) || isCustomized;
117       }
118     }
119     else if (aShapeType == 7) { // otherwise this is a vertex
120       // The width value do not have effect on the point presentation.
121       // It is defined in order to extend selection area of the object.
122       thePrs->setWidth(17);
123     //  thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
124     }
125     if(isCopy()) {
126       double aWidth = thePrs->width();
127       isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
128     }
129     return isCustomized;
130   }
131
132 protected:
133   /// initializes mySketch
134   SketchPlugin_SketchEntity();
135
136   /// \brief Initializes attributes of derived class.
137   virtual void initDerivedClassAttributes(){};
138
139 };
140
141 #endif