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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SketcherPrs_Tools_H
22 #define SketcherPrs_Tools_H
24 #include "SketcherPrs.h"
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Pnt2d.h>
27 #include <GeomAPI_Ax3.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_Feature.h>
33 #include <Events_Loop.h>
34 #include <Events_Message.h>
36 class GeomDataAPI_Point2D;
39 //#define MyTextHeight 20
41 /// Message that style of visualization of parameter is changed.
42 /// It will be shown as expression or value
43 class SketcherPrs_ParameterStyleMessage : public Events_Message
46 /// \enum ParameterStyle lists styles of parameter
48 ParameterValue, ///< using symbol with the parameter value
49 ParameterText ///< using parameter text
53 /// Creates an empty message
54 SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID,
55 const void* theSender = 0)
56 : Events_Message(theID, theSender) {}
57 /// The virtual destructor
58 SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {}
59 /// Static. Returns EventID of the message.
60 SKETCHERPRS_EXPORT static Events_ID eventId()
62 static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
63 return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
65 /// Returns a document stored in the message
66 SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; }
67 /// Sets a document to the message
68 SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; }
70 ParameterStyle myStyle; /// style of the parameter visualization
73 namespace SketcherPrs_Tools {
75 /// Enumeration with modes for activation of selection custom presentations
77 /// Start of enumeration
80 /// Selection mode for all constraints exclude dimensions
83 /// Selection mode for whole dimension
86 /// Selection mode for line of dimension
89 /// Selection mode for text of dimension
92 /// Selectiom mode for faces selection on sketch
95 /// Selectiom mode for wires selection on sketch
101 ANGLE_DIRECT, ///< Angle from the first line to the second line
102 ANGLE_COMPLEMENTARY, ///< Additional angle to the angle from first to second line
103 ANGLE_BACKWARD ///< Angle from the second line to the first line
106 /// Type of dimension location
108 LOCATION_RIGHT, ///< Position is marked by right arrow placed on the left
109 LOCATION_AUTOMATIC, ///< Position is marked by two arrow placed on the both sides
110 LOCATION_LEFT ///< Position is marked by left arrow placed on the left
113 /// Event ID about expression visual state has been changed, the symbol with a digit
114 /// or parameter text is shown
116 /// Returns attribute object referenced by feature
117 /// \param theFeature a feature
118 /// \param theAttrName an attribute name
119 SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
120 const std::string& theAttrName);
122 /// Returns result object referenced by feature
123 /// \param theFeature a feature
124 /// \param theAttrName an attribute name
125 SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
126 const std::string& theAttrName);
128 /// Returns shape from result object (or NULL)
129 /// \param theObject a result object
130 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
133 /// Returns point from a line feature
134 /// \param theFeature a line feature
135 /// \param theAttrName an attribute of the point
136 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
137 const std::string& theAttrName);
140 /// Returns point projected on a line
141 /// \param theLine a line
142 /// \param thePoint a projecting point
143 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
144 const FeaturePtr theLine,
145 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
147 SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
148 const std::string& theAttribute);
150 /// Obtain the point object from specified constraint parameter
151 /// \param theData a data object
152 /// \param theAttribute an attribute name
153 /// \param thePlane a projection plane (sketcher plane)
154 SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
155 const std::string& theAttribute,
156 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
158 /// Returns value of dimension arrows size
159 SKETCHERPRS_EXPORT double getArrowSize();
161 /// Set value of dimension arrows size
162 /// \param theSize a size value
163 SKETCHERPRS_EXPORT void setArrowSize(double theSize);
165 /// Returns default value of dimension arrows size
166 SKETCHERPRS_EXPORT int getDefaultArrowSize();
168 /// Returns value of dimension arrows size set in preferences
169 SKETCHERPRS_EXPORT int getConfigArrowSize();
171 /// Set value of dimension text height
172 /// \param theHeight a height value
173 SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
175 /// Returns value of dimension text height
176 SKETCHERPRS_EXPORT double getTextHeight();
178 /// Returns default value of dimension text height
179 SKETCHERPRS_EXPORT double getDefaultTextHeight();
181 /// Returns value of dimension text height set in preferences
182 SKETCHERPRS_EXPORT double getConfigTextHeight();
184 /// Get flayout distance of the dimension constraint
185 /// \param theConstraint a dimension constraint object
186 SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
188 /// Compute anchor pint for radius dimension
189 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
190 const ModelAPI_Feature* theConstraint,
191 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
193 /// Sends event about expression visualization type is changed for dimension presentations
194 /// Sends event to redisplay all sub-features of composite feature
195 /// \param theState a new state
196 SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
198 /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
199 /// \param theFeature a feature where AIS presentation is empty
200 /// \param theError a debug error information
201 SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
202 const std::string theError);