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_EDGE_COLOR "#ff0000"
24 #define SKETCH_POINT_COLOR "#ff0000"
25 #define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
26 #define SKETCH_CONSTRUCTION_COLOR "#000000"
28 /**\class SketchPlugin_SketchEntity
30 * \brief Sketch Entity for creation of the new feature in PartSet. This is an abstract class to give
31 * an interface to create the entity features such as line, circle, arc and point.
33 class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
36 /// Reference to the construction type of the feature
37 inline static const std::string& CONSTRUCTION_ID()
39 static const std::string MY_CONSTRUCTION_ID("Construction");
40 return MY_CONSTRUCTION_ID;
43 /// Reference to the external edge or vertex as a AttributeSelection
44 inline static const std::string& EXTERNAL_ID()
46 static const std::string MY_EXTERNAL_ID("External");
47 return MY_EXTERNAL_ID;
50 /// Request for initialization of data model of the feature: adding all attributes
51 virtual void initAttributes();
53 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
54 virtual bool isExternal() const
56 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
58 return aAttr->context().get() != NULL;
62 /// Customize presentation of the feature
63 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
64 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
66 bool isCustomized = false;
67 int aShapeType = thePrs->getShapeType();
68 // a compound is processed like the edge because the arc feature uses the compound for presentable AIS
69 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
72 std::vector<int> aColor;
73 std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
74 data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
75 bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
76 if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
78 isCustomized = thePrs->setWidth(1) || isCustomized;
79 isCustomized = thePrs->setLineStyle(3) || isCustomized;
81 aColor = Config_PropManager::color("Visualization", "sketch_construction_color",
82 SKETCH_CONSTRUCTION_COLOR);
85 isCustomized = thePrs->setWidth(3) || isCustomized;
86 isCustomized = thePrs->setLineStyle(0) || isCustomized;
89 // Set color from preferences
90 aColor = Config_PropManager::color("Visualization", "sketch_external_color",
91 SKETCH_EXTERNAL_EDGE_COLOR);
94 // Set color from preferences
95 aColor = Config_PropManager::color("Visualization", "sketch_edge_color",
100 else if (aShapeType == 7) { // otherwise this is a vertex
101 // thePrs->setPointMarker(6, 2.);
102 aColor = Config_PropManager::color("Visualization", "sketch_point_color",
106 if (!aColor.empty()) {
107 isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
113 /// initializes mySketch
114 SketchPlugin_SketchEntity();