1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_SketchEntity.h
4 // Created: 05 Mar 2015
5 // Author: Natalia ERMOLAEVA
7 #ifndef SketchPlugin_SketchEntity_H_
8 #define SketchPlugin_SketchEntity_H_
10 #include "SketchPlugin.h"
11 #include "SketchPlugin_Feature.h"
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>
21 #include <Config_PropManager.h>
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"
28 /**\class SketchPlugin_SketchEntity
30 * \brief Sketch Entity for creation of the new feature in PartSet.
31 * This is an abstract class to give
32 * an interface to create the entity features such as line, circle, arc and point.
34 class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
37 /// Reference to the construction type of the feature
38 inline static const std::string& AUXILIARY_ID()
40 static const std::string MY_AUXILIARY_ID("Auxiliary");
41 return MY_AUXILIARY_ID;
44 /// Reference to the external edge or vertex as a AttributeSelection
45 inline static const std::string& EXTERNAL_ID()
47 static const std::string MY_EXTERNAL_ID("External");
48 return MY_EXTERNAL_ID;
51 /// Reference to the copy type of the feature
52 inline static const std::string& COPY_ID()
54 static const std::string MY_COPY_ID("Copy");
58 /// Width of the auxiliary line
59 inline static const double SKETCH_LINE_WIDTH_AUXILIARY()
65 inline static const double SKETCH_LINE_WIDTH()
70 /// Style of the auxiliary line
71 inline static const int SKETCH_LINE_STYLE_AUXILIARY()
77 inline static const int SKETCH_LINE_STYLE()
82 /// Request for initialization of data model of the feature: adding all attributes
83 virtual void initAttributes();
85 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
86 virtual bool isExternal() const
88 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
90 return aAttr->context().get() != NULL && !aAttr->isInvalid();
94 /// Returns true of the feature is a copy of other feature
95 virtual bool isCopy() const
97 AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
99 return anAttr->value();
104 /// Customize presentation of the feature
105 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
106 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
108 /// Store previous color values of the presentation to check it after setting specific entity
109 /// color. Default color is set into presentation to have not modified isCustomized state
110 /// after default customize prs is completed.
111 std::vector<int> aPrevColor;
112 aPrevColor.resize(3);
113 thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
114 if (theResult.get()) {
115 std::string aSection, aName, aDefault;
116 theResult->colorConfigInfo(aSection, aName, aDefault);
117 std::vector<int> aColor;
118 aColor = Config_PropManager::color(aSection, aName);
119 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
122 bool isCustomized = theDefaultPrs.get() != NULL &&
123 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
124 int aShapeType = thePrs->getShapeType();
125 // a compound is processed like the edge because the
126 // arc feature uses the compound for presentable AIS
127 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
130 // set color from preferences
131 std::vector<int> aColor;
132 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
133 data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
134 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
135 if (isConstruction) {
136 aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
138 else if (isExternal()) {
139 aColor = Config_PropManager::color("Visualization", "sketch_external_color");
142 aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
144 if (!aColor.empty()) {
145 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
146 for (int i = 0; i < 3 && !isCustomized; i++)
147 isCustomized = aColor[i] != aPrevColor[i];
150 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
151 if (isConstruction) {
152 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
153 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
156 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
157 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
160 else if (aShapeType == 7) { // otherwise this is a vertex
161 // The width value do not have effect on the point presentation.
162 // It is defined in order to extend selection area of the object.
163 thePrs->setWidth(17);
164 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
167 double aWidth = thePrs->width();
168 isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
171 if (!theResult.get()) {
172 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
173 thePrs->setDeflection(aDeflection);
179 /// initializes mySketch
180 SketchPlugin_SketchEntity();
182 /// \brief Initializes attributes of derived class.
183 virtual void initDerivedClassAttributes(){};