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 PartSet_Tools_H
22 #define PartSet_Tools_H
31 #include <ModelAPI_CompositeFeature.h>
32 #include <ModelAPI_Object.h>
33 #include <ModelAPI_Attribute.h>
34 #include <ModelAPI_AttributeSelection.h>
36 #include <Events_Message.h>
38 #include <TopoDS_Shape.hxx>
43 class ModuleBase_IViewWindow;
44 class ModuleBase_ViewerPrs;
45 class ModuleBase_IWorkshop;
46 class GeomDataAPI_Point2D;
53 class ModelAPI_Result;
58 * \class PartSet_Tools
60 * \brief The operation for the sketch feature creation
62 class PARTSET_EXPORT PartSet_Tools
65 /// \enum ConstraintVisibleState types of constraints which visible state can be
66 /// changed in the sketch widget
67 enum ConstraintVisibleState
69 Geometrical = 0, // all constrains excepting dimensional
70 Dimensional, // lenght, distance, radius and angle constraints
71 Expressions, // parameter text should be shown in dimensional constraint
72 Any // both, geometrical and dimensional, types of constraints
76 /// Returns default value of AIS presentation
77 /// \return integer value
78 static int getAISDefaultWidth();
80 /// Converts the 2D screen point to the 3D point on the view according to the point of view
81 /// \param thePoint a screen point
82 /// \param theView a 3D view
83 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView);
85 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
86 /// \param thePoint the 3D point in the viewer
87 /// \param theSketch the sketch feature
88 /// \param theView a view 3d object
89 /// \param theX the X coordinate
90 /// \param theY the Y coordinate
91 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
92 Handle(V3d_View) theView,
93 double& theX, double& theY);
95 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
96 /// \param theSketch the sketch feature
97 /// \param thePnt the 3D point in the viewer
98 /// \returns the converted point object
99 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
100 const std::shared_ptr<GeomAPI_Pnt>& thePnt);
102 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
103 /// \param theX the X coordinate
104 /// \param theY the Y coordinate
105 /// \param theSketch the sketch feature
106 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
107 FeaturePtr theSketch);
109 /// Returns pointer to the root document.
110 static std::shared_ptr<ModelAPI_Document> document();
112 /// \brief Save the double to the feature. If the attribute is double, it is filled.
113 /// \param theFeature the feature
114 /// \param theX the horizontal coordinate
115 /// \param theAttribute the feature attribute
116 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
118 /// \brief Returns the feature double value if it is.
119 /// \param theFeature the feature
120 /// \param theAttribute the feature attribute
121 /// \param isValid an output parameter whether the value is valid
122 /// \returns the feature value
123 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
125 /// Find a feature in the attribute of the given feature. If the kind is not empty,
126 /// the return feature should be this type. Otherwise it is null
127 /// \param theFeature a source feature
128 /// \param theAttribute a name of the requried attribute attribute
129 /// \param theKind an output feature kind
130 /// \return the feature
131 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
132 const std::string& theKind);
134 /// Creates a constraint on two points
135 /// \param theSketch a sketch feature
136 /// \param thePoint1 the first point
137 /// \param thePoint2 the second point
138 static void createConstraint(CompositeFeaturePtr theSketch,
139 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
140 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
142 /// Create a sketch plane instance
143 /// \param theSketch a sketch feature
144 /// \return API object of geom plane
145 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
147 /// Create a point 3D on a basis of point 2D and sketch feature
148 /// \param thePoint2D a point on a sketch
149 /// \param theSketch a sketch feature
150 /// \return API object of point 3D
151 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
152 CompositeFeaturePtr theSketch);
154 /// Finds a line (arc or circle) by given edge
155 /// \param theShape an edge
156 /// \param theObject a selected result object
157 /// \param theSketch a sketch feature
158 /// \return result of found feature or NULL
159 static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
160 const TopoDS_Shape& theShape,
161 const ObjectPtr& theObject,
162 CompositeFeaturePtr theSketch);
164 /// Creates a line (arc or circle) by given edge
165 /// Created line will have fixed constraint
166 /// \param theShape an edge
167 /// \param theObject a selected result object
168 /// \param theSketch a sketch feature
169 /// \param theTemporary the created external object is temporary, execute is not performed for it
170 /// \param theCreatedFeature a new projection feature
171 /// \return result of created feature
172 static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
173 const std::shared_ptr<GeomAPI_Shape>& theShape,
174 const ObjectPtr& theObject,
175 CompositeFeaturePtr theSketch,
176 const bool theTemporary,
177 FeaturePtr& theCreatedFeature);
179 /// Checks whether the list of selected presentations contains the given one
180 /// \param theSelected a list of presentations
181 /// \param thePrs a presentation to be found
182 /// \return - result of check, true if the list contains the prs
183 static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
184 const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
187 * Find attribute of object which corresponds to the given shape
188 * \param theObj - an object
189 * \param theShape - a Shape
190 * \param theSketch - a Sketch to get a plane of converting to 2d
192 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
193 FeaturePtr theSketch);
196 * Finds an attribute value in attribute reference attribute value
197 * \param theAttribute - an attribure reference filled with an attribute
198 * \param theWorkshop a reference to workshop
199 * \return a geometry shape
201 static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
202 ModuleBase_IWorkshop* theWorkshop);
205 * Returns point of coincidence feature
206 * \param theFeature the coincidence feature
207 * \param theAttribute the attribute name
209 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
210 const std::string& theAttribute);
213 * Convertes parameters into a geom point
214 * \theEvent a Qt event to find mouse position
215 * \param theWindow view window to define eye of view
216 * \param theSketch to convert 3D point coordinates into coorditates of the sketch plane
218 static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(QMouseEvent* theEvent,
219 ModuleBase_IViewWindow* theWindow,
220 const FeaturePtr& theSketch);
223 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
224 * and compare the point value to be equal with the given. Returns the first feature, which has
226 * \param theFeature the coincidence feature
227 * \param thePoint a 2d point
228 * \return the coincidence feature or null
230 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
231 std::shared_ptr<GeomAPI_Pnt2d> thePoint);
234 * Returns list of features connected in a councedence feature point
235 * \param theStartCoin the coincidence feature
236 * \param theList a list which collects lines features
237 * \param theCoincidencies a list of coincidence features
238 * \param theAttr the attribute name
240 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
241 QList<FeaturePtr>& theCoincidencies,
242 std::string theAttr, QList<bool>& theIsAttributes);
245 * Finds and returns feature reerenced to the paramenter feature with the given name if found
246 * \param theFeature a source feature where refsToMe is obtained
247 * \param theFeatureId an indentifier of the searched feature
249 static FeaturePtr findRefsToMeFeature(FeaturePtr theFeature, const std::string& theFeatureId)
251 if (!theFeature.get())
254 // find first projected feature and edit it
255 const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
256 std::set<AttributePtr>::const_iterator anIt;
257 for (anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
258 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*anIt)->owner());
259 if (aRefFeature && aRefFeature->getKind() == theFeatureId)
266 * Returns point of a coincedence
267 * \param theStartCoin the coincedence feature
269 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
271 /// Sends redisplay event for all sub-features of the composite. Flush it.
272 static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
273 const Events_ID theId);
276 * Returns true if the object is a sketch entity, where auxiliary attribute has true value
277 * \param theObject a result or feature
278 * \return boolean result
280 static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
283 * Returns true if the object is a sketch entity produced by projection or intersection feature
284 * and if it should not be included into the sketch result
286 static bool isIncludeIntoSketchResult(const ObjectPtr& theObject);
288 static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
289 const std::shared_ptr<GeomAPI_Edge>& theEdge,
290 ModelAPI_AttributeSelection::CenterType theType,
291 const CompositeFeaturePtr& theSketch,
293 FeaturePtr& theCreatedFeature);