1 // Copyright (C) 2014-2019 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
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 <ModelAPI_Session.h>
28 #include <GeomAPI_Shape.h>
29 #include <GeomAPI_AISObject.h>
30 #include <ModelAPI_Document.h>
31 #include <ModelAPI_AttributeSelection.h>
32 #include <ModelAPI_AttributeBoolean.h>
33 #include <ModelAPI_AttributeIntArray.h>
34 #include <GeomAPI_ICustomPrs.h>
36 #include <Config_PropManager.h>
38 /**\class SketchPlugin_SketchEntity
40 * \brief Sketch Entity for creation of the new feature in PartSet.
41 * This is an abstract class to give
42 * an interface to create the entity features such as line, circle, arc and point.
44 class SketchPlugin_SketchEntity : public SketchPlugin_Feature //, public GeomAPI_ICustomPrs
47 /// Reference to the construction type of the feature
48 inline static const std::string& AUXILIARY_ID()
50 static const std::string MY_AUXILIARY_ID("Auxiliary");
51 return MY_AUXILIARY_ID;
54 /// Reference to the external edge or vertex as a AttributeSelection
55 inline static const std::string& EXTERNAL_ID()
57 static const std::string MY_EXTERNAL_ID("External");
58 return MY_EXTERNAL_ID;
61 /// Reference to the copy type of the feature
62 inline static const std::string& COPY_ID()
64 static const std::string MY_COPY_ID("Copy");
68 /// Width of the auxiliary line
69 inline static const int SKETCH_LINE_WIDTH_AUXILIARY()
75 inline static const int SKETCH_LINE_WIDTH()
77 return Config_PropManager::integer("Visualization", "sketch_line_width");
80 /// Style of the auxiliary line
81 inline static const int SKETCH_LINE_STYLE_AUXILIARY()
87 inline static const int SKETCH_LINE_STYLE()
92 /// Request for initialization of data model of the feature: adding all attributes
93 virtual void initAttributes();
95 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
96 virtual bool isExternal() const
98 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
100 return aAttr->context().get() != NULL && !aAttr->isInvalid();
104 /// Returns true of the feature is a copy of other feature
105 virtual bool isCopy() const
107 AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
109 return anAttr->value();
114 //virtual bool isIncludeToResult() const
116 // AttributeBooleanPtr anAttr;
117 // std::set<AttributePtr> aRefsToMe = data()->refsToMe();
118 // std::set<AttributePtr>::const_iterator aIt;
119 // for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
120 // if ((*aIt)->id() == "ProjectedFeature") {
121 // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
122 // if (aFeature.get()) {
123 // anAttr = aFeature->data()->boolean("IncludeToResult");
125 // return anAttr->value();
133 /// Customize presentation of the feature
134 //virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
135 // std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
137 // /// Store previous color values of the presentation to check it after setting specific entity
138 // /// color. Default color is set into presentation to have not modified isCustomized state
139 // /// after default customize prs is completed.
140 // std::vector<int> aPrevColor;
141 // aPrevColor.resize(3);
142 // thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
143 // if (theResult.get()) {
144 // std::string aSection, aName, aDefault;
145 // theResult->colorConfigInfo(aSection, aName, aDefault);
146 // std::vector<int> aColor;
147 // aColor = Config_PropManager::color(aSection, aName);
148 // thePrs->setColor(aColor[0], aColor[1], aColor[2]);
151 // bool isCustomized = theDefaultPrs.get() != NULL &&
152 // theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
153 // int aShapeType = thePrs->getShapeType();
154 // // a compound is processed like the edge because the
155 // // arc feature uses the compound for presentable AIS
156 // if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
159 // // set color from preferences
160 // std::vector<int> aColor;
161 // std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
162 // data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
163 // bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
164 // if (isConstruction) {
165 // aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
167 // else if (isExternal()) {
168 // aColor = Config_PropManager::color("Visualization", "sketch_external_color");
171 // aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
173 // if (!aColor.empty()) {
174 // if (theResult.get() && ModelAPI_Session::get()->isOperation()) {
175 // AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
176 // aColorAttr->setSize(3);
177 // // Set the color attribute in order do not use default colors in the presentation object
178 // for (int i = 0; i < 3; i++)
179 // aColorAttr->setValue(i, aColor[i]);
181 // thePrs->setColor(aColor[0], aColor[1], aColor[2]);
182 // for (int i = 0; i < 3 && !isCustomized; i++)
183 // isCustomized = aColor[i] != aPrevColor[i];
186 // if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
187 // if (isConstruction) {
188 // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
189 // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
192 // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
193 // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
196 // else if (aShapeType == 7) { // otherwise this is a vertex
197 // // The width value do not have effect on the point presentation.
198 // // It is defined in order to extend selection area of the object.
199 // thePrs->setWidth(17);
200 // // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
202 // if(isCopy() && !isIncludeToResult()) {
203 // double aWidth = thePrs->width();
204 // isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
207 // if (!theResult.get()) {
208 // double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
209 // thePrs->setDeflection(aDeflection);
211 // return isCustomized;
216 /// initializes mySketch
217 SketchPlugin_SketchEntity();
219 /// \brief Initializes attributes of derived class.
220 virtual void initDerivedClassAttributes(){};