SHAPER  9.12.0
PartSet_Tools.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef PartSet_Tools_H
21 #define PartSet_Tools_H
22 
23 #include "PartSet.h"
24 
25 #include <gp_Pnt.hxx>
26 
27 #include <QPoint>
28 #include <QList>
29 #include <QCursor>
30 
31 #include <ModelAPI_CompositeFeature.h>
32 #include <ModelAPI_Object.h>
33 #include <ModelAPI_Attribute.h>
34 #include <ModelAPI_AttributeSelection.h>
35 
36 #include <Events_Message.h>
37 
38 #include <TopoDS_Shape.hxx>
39 
40 #include <memory>
41 
42 class V3d_View;
47 class GeomAPI_Shape;
48 class GeomAPI_Pln;
49 class GeomAPI_Pnt2d;
50 class GeomAPI_Pnt;
51 class GeomAPI_Edge;
52 class GeomAPI_Vertex;
53 class ModelAPI_Result;
54 
55 class QMouseEvent;
56 
62 class PARTSET_EXPORT PartSet_Tools
63 {
64 public:
68  {
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
73  };
74 
75  public:
78  static int getAISDefaultWidth();
79 
83  static gp_Pnt convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView);
84 
91  static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
92  Handle(V3d_View) theView,
93  double& theX, double& theY);
94 
99  static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
100  const std::shared_ptr<GeomAPI_Pnt>& thePnt);
101 
106  static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
107  FeaturePtr theSketch);
108 
110  static std::shared_ptr<ModelAPI_Document> document();
111 
116  static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
117 
123  static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
124 
131  static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
132  const std::string& theKind);
133 
138  static void createConstraint(CompositeFeaturePtr theSketch,
139  std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
140  std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
141 
145  static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
146 
150  static void nullifySketchPlane(CompositeFeaturePtr theSketch);
151 
156  static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
157  CompositeFeaturePtr theSketch);
158 
164  static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
165  const TopoDS_Shape& theShape,
166  const ObjectPtr& theObject,
167  CompositeFeaturePtr theSketch);
168 
177  static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
178  const std::shared_ptr<GeomAPI_Shape>& theShape,
179  const ObjectPtr& theObject,
180  CompositeFeaturePtr theSketch,
181  const bool theTemporary,
182  FeaturePtr& theCreatedFeature);
183 
188  static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
189  const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
190 
198  static std::pair<AttributePtr, int> findAttributeBy2dPoint(ObjectPtr theObj,
199  const TopoDS_Shape theShape,
200  FeaturePtr theSketch);
201 
208  static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
209  ModuleBase_IWorkshop* theWorkshop);
210 
216  static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
217  const std::string& theAttribute);
218 
225  static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(QMouseEvent* theEvent,
226  ModuleBase_IViewWindow* theWindow,
227  const FeaturePtr& theSketch);
228 
235  static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(const Handle(V3d_View)& theView,
236  const TopoDS_Shape& theShape,
237  const FeaturePtr& theSketch);
238 
247  static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
248  std::shared_ptr<GeomAPI_Pnt2d> thePoint);
249 
257  static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
258  QList<FeaturePtr>& theCoincidencies,
259  std::string theAttr, QList<bool>& theIsAttributes);
260 
261  /*
262  * Finds and returns feature reerenced to the paramenter feature with the given name if found
263  * \param theFeature a source feature where refsToMe is obtained
264  * \param theFeatureId an indentifier of the searched feature
265  */
266  static FeaturePtr findRefsToMeFeature(FeaturePtr theFeature, const std::string& theFeatureId)
267  {
268  if (!theFeature.get())
269  return FeaturePtr();
270 
271  // find first projected feature and edit it
272  const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
273  std::set<AttributePtr>::const_iterator anIt;
274  for (anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
275  FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*anIt)->owner());
276  if (aRefFeature && aRefFeature->getKind() == theFeatureId)
277  return aRefFeature;
278  }
279  return FeaturePtr();
280  }
281 
286  static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
287 
289  static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
290  const Events_ID theId);
291 
297  static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
298 
303  static bool isIncludeIntoSketchResult(const ObjectPtr& theObject);
304 
305  static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
306  const std::shared_ptr<GeomAPI_Edge>& theEdge,
308  const CompositeFeaturePtr& theSketch,
309  bool theTemporary,
310  FeaturePtr& theCreatedFeature);
311 
312 
313  static void getFirstAndLastIndexInFolder(const ObjectPtr& theFolder,
314  int& theFirst, int& theLast);
315 
316 
320  static void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
321  std::vector<int>& theColor);
322 
326  static double getDefaultDeflection(const ObjectPtr& theObject);
327 
328 
332  static double getDefaultTransparency();
333 
337  static QCursor getOperationCursor();
338 };
339 
340 #endif
Identifier of the event kind.
Definition: Events_Message.h:36
Interface to the edge object.
Definition: GeomAPI_Edge.h:38
3D point defined by three coordinates
Definition: GeomAPI_Pln.h:37
2D point defined by two coordinates
Definition: GeomAPI_Pnt2d.h:36
3D point defined by three coordinates
Definition: GeomAPI_Pnt.h:38
Interface to the topological shape object.
Definition: GeomAPI_Shape.h:43
Interface to the vertex object.
Definition: GeomAPI_Vertex.h:31
Attribute that contains 2D point coordinates.
Definition: GeomDataAPI_Point2D.h:37
CenterType
Type of the center of the circular of elliptic edge.
Definition: ModelAPI_AttributeSelection.h:38
The result of a feature.
Definition: ModelAPI_Result.h:35
Interface to ViewWindow object which contains 3d scene.
Definition: ModuleBase_IViewWindow.h:34
Class which provides access to Workshop object services.
Definition: ModuleBase_IWorkshop.h:48
Presentation.
Definition: ModuleBase_ViewerPrs.h:37
The operation for the sketch feature creation.
Definition: PartSet_Tools.h:63
ConstraintVisibleState
types of constraints which visible state can be changed in the sketch widget
Definition: PartSet_Tools.h:68