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 SketcherPrs_Tools_H
21 #define SketcherPrs_Tools_H
23 #include "SketcherPrs.h"
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_Pnt2d.h>
26 #include <GeomAPI_Ax3.h>
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Attribute.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_Result.h>
34 #include <Events_Loop.h>
35 #include <Events_Message.h>
37 class GeomDataAPI_Point2D;
40 //#define MyTextHeight 20
42 /// Message that style of visualization of parameter is changed.
43 /// It will be shown as expression or value
44 class SketcherPrs_ParameterStyleMessage : public Events_Message
47 /// \enum ParameterStyle lists styles of parameter
49 ParameterValue, ///< using symbol with the parameter value
50 ParameterText ///< using parameter text
54 /// Creates an empty message
55 SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID,
56 const void* theSender = 0)
57 : Events_Message(theID, theSender) {}
58 /// The virtual destructor
59 SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {}
60 /// Static. Returns EventID of the message.
61 SKETCHERPRS_EXPORT static Events_ID eventId()
63 static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
64 return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
66 /// Returns a document stored in the message
67 SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; }
68 /// Sets a document to the message
69 SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; }
71 ParameterStyle myStyle; /// style of the parameter visualization
74 namespace SketcherPrs_Tools {
76 /// Enumeration with modes for activation of selection custom presentations
78 /// Start of enumeration
81 /// Selection mode for all constraints exclude dimensions
84 /// Selection mode for whole dimension
87 /// Selection mode for line of dimension
90 /// Selection mode for text of dimension
93 /// Selectiom mode for faces selection on sketch
96 /// Selectiom mode for wires selection on sketch
102 ANGLE_DIRECT, ///< Angle from the first line to the second line
103 ANGLE_COMPLEMENTARY, ///< Additional angle to the angle from first to second line
104 ANGLE_BACKWARD ///< Angle from the second line to the first line
107 /// Type of dimension location
109 LOCATION_RIGHT, ///< Position is marked by right arrow placed on the left
110 LOCATION_AUTOMATIC, ///< Position is marked by two arrow placed on the both sides
111 LOCATION_LEFT ///< Position is marked by left arrow placed on the left
114 /// Event ID about expression visual state has been changed, the symbol with a digit
115 /// or parameter text is shown
117 /// Returns attribute object referenced by feature
118 /// \param theFeature a feature
119 /// \param theAttrName an attribute name
120 SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
121 const std::string& theAttrName);
123 /// Returns result object referenced by feature
124 /// \param theFeature a feature
125 /// \param theAttrName an attribute name
126 SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
127 const std::string& theAttrName);
129 /// Returns shape from result object (or NULL)
130 /// \param theObject a result object
131 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
134 /// Returns point from a line feature
135 /// \param theFeature a line feature
136 /// \param theAttrName an attribute of the point
137 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
138 const std::string& theAttrName);
141 /// Returns point projected on a line
142 /// \param theLine a line
143 /// \param thePoint a projecting point
144 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
145 const FeaturePtr theLine,
146 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
148 SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
149 const std::string& theAttribute);
151 /// Obtain the point object from specified constraint parameter
152 /// \param theData a data object
153 /// \param theAttribute an attribute name
154 /// \param thePlane a projection plane (sketcher plane)
155 SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
156 const std::string& theAttribute,
157 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
159 /// Collect all sketch points which are not connected with other entities.
160 /// \param theSketch sketch feature
161 /// \return list of results of SketchPlugin_Point features
162 SKETCHERPRS_EXPORT std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch);
164 /// Returns value of dimension arrows size
165 SKETCHERPRS_EXPORT double getArrowSize();
167 /// Set value of dimension arrows size
168 /// \param theSize a size value
169 SKETCHERPRS_EXPORT void setArrowSize(double theSize);
171 /// Returns default value of dimension arrows size
172 SKETCHERPRS_EXPORT int getDefaultArrowSize();
174 /// Returns value of dimension arrows size set in preferences
175 SKETCHERPRS_EXPORT int getConfigArrowSize();
177 /// Set value of dimension text height
178 /// \param theHeight a height value
179 SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
181 /// Returns value of dimension text height
182 SKETCHERPRS_EXPORT double getTextHeight();
184 /// Returns default value of dimension text height
185 SKETCHERPRS_EXPORT double getDefaultTextHeight();
187 /// Returns value of dimension text height set in preferences
188 SKETCHERPRS_EXPORT double getConfigTextHeight();
190 /// Get flayout distance of the dimension constraint
191 /// \param theConstraint a dimension constraint object
192 SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
194 /// Compute anchor pint for radius dimension
195 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
196 const ModelAPI_Feature* theConstraint,
197 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
199 /// Sends event about expression visualization type is changed for dimension presentations
200 /// Sends event to redisplay all sub-features of composite feature
201 /// \param theState a new state
202 SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
204 /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
205 /// \param theFeature a feature where AIS presentation is empty
206 /// \param theError a debug error information
207 SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
208 const std::string theError);
210 SKETCHERPRS_EXPORT void setPixelRatio(int theRatio);
212 SKETCHERPRS_EXPORT int pixelRatio();