1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Feature.h
4 // Created: 27 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef SketchPlugin_Feature_H_
8 #define SketchPlugin_Feature_H_
10 #include "SketchPlugin.h"
11 #include <ModelAPI_CompositeFeature.h>
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_AISObject.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_AttributeSelection.h>
16 #include <ModelAPI_AttributeBoolean.h>
17 #include <GeomAPI_ICustomPrs.h>
19 #include <Config_PropManager.h>
21 #define SKETCH_EDGE_COLOR "#ff0000"
22 #define SKETCH_POINT_COLOR "#ff0000"
23 #define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
24 #define SKETCH_CONSTRUCTION_COLOR "#000000"
26 class SketchPlugin_Sketch;
28 class Handle_AIS_InteractiveObject;
30 /**\class SketchPlugin_Feature
32 * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
33 * an interface to create the sketch feature preview.
35 class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
38 /// Reference to the construction type of the feature
39 inline static const std::string& CONSTRUCTION_ID()
41 static const std::string MY_CONSTRUCTION_ID("Construction");
42 return MY_CONSTRUCTION_ID;
45 /// Reference to the external edge or vertex as a AttributeSelection
46 inline static const std::string& EXTERNAL_ID()
48 static const std::string MY_EXTERNAL_ID("External");
49 return MY_EXTERNAL_ID;
52 /// Returns true if this feature must be displayed in the history (top level of Part tree)
53 SKETCHPLUGIN_EXPORT virtual bool isInHistory()
59 /// \param theDeltaX the delta for X coordinate is moved
60 /// \param theDeltaY the delta for Y coordinate is moved
61 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
63 /// Return the distance between the feature and the point
64 /// \param thePoint the point
65 virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
67 /// Construction result is allways recomuted on the fly
68 SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
70 /// Returns true is sketch element is under the rigid constraint
71 SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
73 /// Returns true of the feature is created basing on the external shape of not-this-sketch object
74 inline bool isExternal() const
76 AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
78 return aAttr->context().get() != NULL;
82 /// Customize presentation of the feature
83 virtual void customisePresentation(AISObjectPtr thePrs)
85 std::vector<int> aRGB;
87 int aShapeType = thePrs->getShapeType();
88 if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
91 bool isConstruction = data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value();
92 if (aShapeType == 6) { // if this is an edge
95 aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
96 SKETCH_CONSTRUCTION_COLOR);
101 // Set color from preferences
102 aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
103 SKETCH_EXTERNAL_EDGE_COLOR);
106 // Set color from preferences
107 aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
112 else if (aShapeType == 7) { // otherwise this is a vertex
113 // thePrs->setPointMarker(6, 2.);
114 // Set color from preferences
115 aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
120 thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
123 /// Returns the sketch of this feature
124 SketchPlugin_Sketch* sketch();
126 /// Sets the higher-level feature for the sub-feature (sketch for line)
127 void setSketch(SketchPlugin_Sketch* theSketch)
129 mySketch = theSketch;
131 /// initializes mySketch
132 SketchPlugin_Feature();
134 friend class SketchPlugin_Sketch;
137 std::shared_ptr<GeomAPI_Shape> myPreview; ///< the preview shape
138 SketchPlugin_Sketch* mySketch; /// sketch that contains this feature