SHAPER  9.12.0
SketchPlugin_SketchEntity.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef SketchPlugin_SketchEntity_H_
21 #define SketchPlugin_SketchEntity_H_
22 
23 #include "SketchPlugin.h"
24 #include "SketchPlugin_Feature.h"
25 
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>
35 
36 #include <Config_PropManager.h>
37 
44 class SketchPlugin_SketchEntity : public SketchPlugin_Feature //, public GeomAPI_ICustomPrs
45 {
46  public:
48  inline static const std::string& AUXILIARY_ID()
49  {
50  static const std::string MY_AUXILIARY_ID("Auxiliary");
51  return MY_AUXILIARY_ID;
52  }
53 
55  inline static const std::string& EXTERNAL_ID()
56  {
57  static const std::string MY_EXTERNAL_ID("External");
58  return MY_EXTERNAL_ID;
59  }
60 
62  inline static const std::string& COPY_ID()
63  {
64  static const std::string MY_COPY_ID("Copy");
65  return MY_COPY_ID;
66  }
67 
69  inline static const std::string& PARENT_ID()
70  {
71  static const std::string& MY_PARENT_ID("ParentFeature");
72  return MY_PARENT_ID;
73  }
74 
76  inline static const int SKETCH_LINE_WIDTH_AUXILIARY()
77  {
78  return 2;
79  }
80 
82  inline static const int SKETCH_LINE_WIDTH()
83  {
84  return Config_PropManager::integer("Visualization", "sketch_line_width");
85  }
86 
88  inline static const int SKETCH_LINE_STYLE_AUXILIARY()
89  {
90  return 3;
91  }
92 
94  inline static const int SKETCH_LINE_STYLE()
95  {
96  return 0;
97  }
98 
100  virtual void initAttributes();
101 
103  virtual bool isExternal() const
104  {
105  AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
106  if (aAttr)
107  return aAttr->context().get() != NULL && !aAttr->isInvalid();
108  return false;
109  }
110 
112  virtual bool isCopy() const
113  {
114  AttributeBooleanPtr anAttr = data()->boolean(COPY_ID());
115  if(anAttr.get()) {
116  return anAttr->value();
117  }
118  return false;
119  }
120 
121  //virtual bool isIncludeToResult() const
122  //{
123  // AttributeBooleanPtr anAttr;
124  // std::set<AttributePtr> aRefsToMe = data()->refsToMe();
125  // std::set<AttributePtr>::const_iterator aIt;
126  // for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) {
127  // if ((*aIt)->id() == "ProjectedFeature") {
128  // FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
129  // if (aFeature.get()) {
130  // anAttr = aFeature->data()->boolean("IncludeToResult");
131  // if (anAttr.get())
132  // return anAttr->value();
133  // }
134  // }
135  // }
136  // return true;
137  //}
138 
139 // LCOV_EXCL_START
141  //virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
142  // std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
143  //{
144  // /// Store previous color values of the presentation to check it after setting specific entity
145  // /// color. Default color is set into presentation to have not modified isCustomized state
146  // /// after default customize prs is completed.
147  // std::vector<int> aPrevColor;
148  // aPrevColor.resize(3);
149  // thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]);
150  // if (theResult.get()) {
151  // std::string aSection, aName, aDefault;
152  // theResult->colorConfigInfo(aSection, aName, aDefault);
153  // std::vector<int> aColor;
154  // aColor = Config_PropManager::color(aSection, aName);
155  // thePrs->setColor(aColor[0], aColor[1], aColor[2]);
156  // }
157 
158  // bool isCustomized = theDefaultPrs.get() != NULL &&
159  // theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
160  // int aShapeType = thePrs->getShapeType();
161  // // a compound is processed like the edge because the
162  // // arc feature uses the compound for presentable AIS
163  // if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
164  // return false;
165 
166  // // set color from preferences
167  // std::vector<int> aColor;
168  // std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
169  // data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
170  // bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
171  // if (isConstruction) {
172  // aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color");
173  // }
174  // else if (isExternal()) {
175  // aColor = Config_PropManager::color("Visualization", "sketch_external_color");
176  // }
177  // else {
178  // aColor = Config_PropManager::color("Visualization", "sketch_entity_color");
179  // }
180  // if (!aColor.empty()) {
181  // if (theResult.get() && ModelAPI_Session::get()->isOperation()) {
182  // AttributeIntArrayPtr aColorAttr =
183  // theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
184  // aColorAttr->setSize(3);
185  // // Set the color attribute in order do not use default colors in the presentation object
186  // for (int i = 0; i < 3; i++)
187  // aColorAttr->setValue(i, aColor[i]);
188  // }
189  // thePrs->setColor(aColor[0], aColor[1], aColor[2]);
190  // for (int i = 0; i < 3 && !isCustomized; i++)
191  // isCustomized = aColor[i] != aPrevColor[i];
192  // }
193 
194  // if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
195  // if (isConstruction) {
196  // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized;
197  // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized;
198  // }
199  // else {
200  // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized;
201  // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized;
202  // }
203  // }
204  // else if (aShapeType == 7) { // otherwise this is a vertex
205  // // The width value do not have effect on the point presentation.
206  // // It is defined in order to extend selection area of the object.
207  // thePrs->setWidth(17);
208  // // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
209  // }
210  // if(isCopy() && !isIncludeToResult()) {
211  // double aWidth = thePrs->width();
212  // isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
213  // }
214 
215  // if (!theResult.get()) {
216  // double aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
217  // thePrs->setDeflection(aDeflection);
218  // }
219  // return isCustomized;
220  //}
221 // LCOV_EXCL_STOP
222 
223 protected:
226 
228  virtual void initDerivedClassAttributes(){};
229 
231  virtual void initDerivedClassAttributes2(){};
232 
233 };
234 
235 #endif
static int integer(const std::string &theSection, const std::string &theName)
Returns integer by given section and name.
Definition: Config_PropManager.cpp:150
virtual std::shared_ptr< ModelAPI_Data > data() const
Returns the data manager of this object: attributes.
Definition: ModelAPI_Object.cpp:45
Feature for creation of the new feature in PartSet.
Definition: SketchPlugin_Feature.h:40
Sketch Entity for creation of the new feature in PartSet.
Definition: SketchPlugin_SketchEntity.h:45
virtual void initDerivedClassAttributes()
Initializes attributes of derived class.
Definition: SketchPlugin_SketchEntity.h:228
static const std::string & PARENT_ID()
Reference to the parent feature if exist.
Definition: SketchPlugin_SketchEntity.h:69
SketchPlugin_SketchEntity()
Customize presentation of the feature.
Definition: SketchPlugin_SketchEntity.cpp:26
static const int SKETCH_LINE_WIDTH()
Width of the line.
Definition: SketchPlugin_SketchEntity.h:82
static const std::string & EXTERNAL_ID()
Reference to the external edge or vertex as a AttributeSelection.
Definition: SketchPlugin_SketchEntity.h:55
static const int SKETCH_LINE_STYLE_AUXILIARY()
Style of the auxiliary line.
Definition: SketchPlugin_SketchEntity.h:88
static const std::string & COPY_ID()
Reference to the copy type of the feature.
Definition: SketchPlugin_SketchEntity.h:62
virtual void initDerivedClassAttributes2()
Initializes attributes of derived class which were added recently.
Definition: SketchPlugin_SketchEntity.h:231
virtual bool isCopy() const
Returns true of the feature is a copy of other feature.
Definition: SketchPlugin_SketchEntity.h:112
static const std::string & AUXILIARY_ID()
Reference to the construction type of the feature.
Definition: SketchPlugin_SketchEntity.h:48
static const int SKETCH_LINE_STYLE()
Style of the line.
Definition: SketchPlugin_SketchEntity.h:94
virtual bool isExternal() const
Returns true of the feature is created basing on the external shape of not-this-sketch object.
Definition: SketchPlugin_SketchEntity.h:103
static const int SKETCH_LINE_WIDTH_AUXILIARY()
Width of the auxiliary line.
Definition: SketchPlugin_SketchEntity.h:76
virtual void initAttributes()
Request for initialization of data model of the feature: adding all attributes.
Definition: SketchPlugin_SketchEntity.cpp:31