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 /**\class SketchPlugin_SketchEntity
25 * \brief Sketch Entity for creation of the new feature in PartSet.
26 * This is an abstract class to give
27 * an interface to create the entity features such as line, circle, arc and point.
29 class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
32 /// Reference to the construction type of the feature
33 inline static const std::string& AUXILIARY_ID()
35 static const std::string MY_AUXILIARY_ID("Auxiliary");
36 return MY_AUXILIARY_ID;
39 /// Reference to the external edge or vertex as a AttributeSelection
40 inline static const std::string& EXTERNAL_ID()
42 static const std::string MY_EXTERNAL_ID("External");
43 return MY_EXTERNAL_ID;
46 /// Reference to the copy type of the feature
47 inline static const std::string& COPY_ID()
49 static const std::string MY_COPY_ID("Copy");
53 /// Width of the auxiliary line
54 inline static const double SKETCH_LINE_WIDTH_AUXILIARY()
60 inline static const double SKETCH_LINE_WIDTH()
65 /// Style of the auxiliary line
66 inline static const int SKETCH_LINE_STYLE_AUXILIARY()
72 inline static const int SKETCH_LINE_STYLE()
77 /// Request for initialization of data model of the feature: adding all attributes
78 virtual void initAttributes();
80 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
81 virtual bool isExternal() const
83 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
85 return aAttr->context().get() != NULL && !aAttr->isInvalid();
89 /// Returns true of the feature is a copy of other feature
90 virtual bool isCopy() const
92 AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
94 return anAttr->value();
99 /// Customize presentation of the feature
100 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
101 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
103 /// Store previous color values of the presentation to check it after setting specific entity
104 /// color. Default color is set into presentation to have not modified isCustomized state
105 /// after default customize prs is completed.
106 std::vector<int> aPrevColor;
107 aPrevColor.resize(3);
108 thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
109 if (theResult.get()) {
110 std::string aSection, aName, aDefault;
111 theResult->colorConfigInfo(aSection, aName, aDefault);
112 std::vector<int> aColor;
113 aColor = Config_PropManager::color(aSection, aName);
114 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
117 bool isCustomized = theDefaultPrs.get() != NULL &&
118 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
119 int aShapeType = thePrs->getShapeType();
120 // a compound is processed like the edge because the
121 // arc feature uses the compound for presentable AIS
122 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
125 // set color from preferences
126 std::vector<int> aColor;
127 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
128 data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
129 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
130 if (isConstruction) {
131 aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
133 else if (isExternal()) {
134 aColor = Config_PropManager::color("Visualization", "sketch_external_color");
137 aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
139 if (!aColor.empty()) {
140 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
141 for (int i = 0; i < 3 && !isCustomized; i++)
142 isCustomized = aColor[i] != aPrevColor[i];
145 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
146 if (isConstruction) {
147 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
148 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
151 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
152 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
155 else if (aShapeType == 7) { // otherwise this is a vertex
156 // The width value do not have effect on the point presentation.
157 // It is defined in order to extend selection area of the object.
158 thePrs->setWidth(17);
159 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
162 double aWidth = thePrs->width();
163 isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
166 if (!theResult.get()) {
167 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
168 thePrs->setDeflection(aDeflection);
174 /// initializes mySketch
175 SketchPlugin_SketchEntity();
177 /// \brief Initializes attributes of derived class.
178 virtual void initDerivedClassAttributes(){};