1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef SketchPlugin_SketchEntity_H_
21 #define SketchPlugin_SketchEntity_H_
23 #include "SketchPlugin.h"
24 #include "SketchPlugin_Feature.h"
26 #include <ModelAPI_CompositeFeature.h>
27 #include <GeomAPI_Shape.h>
28 #include <GeomAPI_AISObject.h>
29 #include <ModelAPI_Document.h>
30 #include <ModelAPI_AttributeSelection.h>
31 #include <ModelAPI_AttributeBoolean.h>
32 #include <GeomAPI_ICustomPrs.h>
34 #include <Config_PropManager.h>
36 /**\class SketchPlugin_SketchEntity
38 * \brief Sketch Entity for creation of the new feature in PartSet.
39 * This is an abstract class to give
40 * an interface to create the entity features such as line, circle, arc and point.
42 class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
45 /// Reference to the construction type of the feature
46 inline static const std::string& AUXILIARY_ID()
48 static const std::string MY_AUXILIARY_ID("Auxiliary");
49 return MY_AUXILIARY_ID;
52 /// Reference to the external edge or vertex as a AttributeSelection
53 inline static const std::string& EXTERNAL_ID()
55 static const std::string MY_EXTERNAL_ID("External");
56 return MY_EXTERNAL_ID;
59 /// Reference to the copy type of the feature
60 inline static const std::string& COPY_ID()
62 static const std::string MY_COPY_ID("Copy");
66 /// Width of the auxiliary line
67 inline static const double SKETCH_LINE_WIDTH_AUXILIARY()
73 inline static const double SKETCH_LINE_WIDTH()
78 /// Style of the auxiliary line
79 inline static const int SKETCH_LINE_STYLE_AUXILIARY()
85 inline static const int SKETCH_LINE_STYLE()
90 /// Request for initialization of data model of the feature: adding all attributes
91 virtual void initAttributes();
93 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
94 virtual bool isExternal() const
96 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
98 return aAttr->context().get() != NULL && !aAttr->isInvalid();
102 /// Returns true of the feature is a copy of other feature
103 virtual bool isCopy() const
105 AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
107 return anAttr->value();
112 /// Customize presentation of the feature
113 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
114 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
116 /// Store previous color values of the presentation to check it after setting specific entity
117 /// color. Default color is set into presentation to have not modified isCustomized state
118 /// after default customize prs is completed.
119 std::vector<int> aPrevColor;
120 aPrevColor.resize(3);
121 thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
122 if (theResult.get()) {
123 std::string aSection, aName, aDefault;
124 theResult->colorConfigInfo(aSection, aName, aDefault);
125 std::vector<int> aColor;
126 aColor = Config_PropManager::color(aSection, aName);
127 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
130 bool isCustomized = theDefaultPrs.get() != NULL &&
131 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
132 int aShapeType = thePrs->getShapeType();
133 // a compound is processed like the edge because the
134 // arc feature uses the compound for presentable AIS
135 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
138 // set color from preferences
139 std::vector<int> aColor;
140 std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
141 data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
142 bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
143 if (isConstruction) {
144 aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
146 else if (isExternal()) {
147 aColor = Config_PropManager::color("Visualization", "sketch_external_color");
150 aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
152 if (!aColor.empty()) {
153 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
154 for (int i = 0; i < 3 && !isCustomized; i++)
155 isCustomized = aColor[i] != aPrevColor[i];
158 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
159 if (isConstruction) {
160 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
161 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
164 isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
165 isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
168 else if (aShapeType == 7) { // otherwise this is a vertex
169 // The width value do not have effect on the point presentation.
170 // It is defined in order to extend selection area of the object.
171 thePrs->setWidth(17);
172 // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
175 double aWidth = thePrs->width();
176 isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
179 if (!theResult.get()) {
180 double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
181 thePrs->setDeflection(aDeflection);
187 /// initializes mySketch
188 SketchPlugin_SketchEntity();
190 /// \brief Initializes attributes of derived class.
191 virtual void initDerivedClassAttributes(){};