SHAPER  9.15.0
PartSet_Tools.h
1 // Copyright (C) 2014-2025 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 #include <gp_Ax3.hxx>
27 #include <Bnd_Box.hxx>
28 
29 #include <QPoint>
30 #include <QList>
31 #include <QCursor>
32 
33 #include <ModelAPI_CompositeFeature.h>
34 #include <ModelAPI_Object.h>
35 #include <ModelAPI_Attribute.h>
36 #include <ModelAPI_AttributeSelection.h>
37 
38 #include <Events_Message.h>
39 
40 #include <TopoDS_Shape.hxx>
41 
42 #include <memory>
43 #include <string>
44 #include <array>
45 #include <utility>
46 
47 class V3d_View;
52 class GeomAPI_Shape;
53 class GeomAPI_Face;
54 class GeomAPI_Pln;
55 class GeomAPI_Pnt2d;
56 class GeomAPI_Pnt;
57 class GeomAPI_Edge;
58 class GeomAPI_Vertex;
59 class ModelAPI_Result;
60 
61 class QMouseEvent;
62 
68 class PARTSET_EXPORT PartSet_Tools
69 {
70 public:
74  {
75  Geometrical = 0, // all constrains excepting dimensional
76  Dimensional, // length, distance, radius and angle constraints
77  Expressions, // parameter text should be shown in dimensional constraint
78  Any // both, geometrical and dimensional, types of constraints
79  };
80 
81  public:
84  static int getAISDefaultWidth();
85 
89  static gp_Pnt convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView);
90 
97  static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
98  Handle(V3d_View) theView,
99  double& theX, double& theY);
100 
105  static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
106  const std::shared_ptr<GeomAPI_Pnt>& thePnt);
107 
112  static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
113  FeaturePtr theSketch);
114 
116  static std::shared_ptr<ModelAPI_Document> document();
117 
122  static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
123 
129  static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
130 
137  static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
138  const std::string& theKind);
139 
144  static void createConstraint(CompositeFeaturePtr theSketch,
145  std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
146  std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
147 
151  static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
152 
156  static void nullifySketchPlane(CompositeFeaturePtr theSketch);
157 
159  static std::pair<bool, gp_Ax3> getWorldCSAt(const GeomAPI_Face& theFace, double U, double V);
160 
162  static std::pair<bool, gp_Pnt> getWorldPointByUV(const GeomAPI_Face& theFace, double U, double V);
163 
168  static std::pair<bool, Bnd_Box> getBBoxAtCS(const GeomAPI_Shape& theShape, const gp_Ax3 theCS);
169 
171  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneDefaultSize(CompositeFeaturePtr theSketch);
172 
174  static std::shared_ptr<ModelAPI_AttributeBoolean> sketchPlaneAxesEnabled(CompositeFeaturePtr theSketch);
175 
177  static std::shared_ptr<ModelAPI_AttributeBoolean> sketchPlaneSubstrateEnabled(CompositeFeaturePtr theSketch);
178 
180  static std::shared_ptr<ModelAPI_AttributeString> sketchPlaneGridType(CompositeFeaturePtr theSketch);
181 
183  public:
184  typedef enum {
185  No,
186  Rectangular,
187  Circular
188  } Enum;
189 
190  static std::string toString(Enum iType);
191  static Enum fromString(const std::string& iTypeString);
192 
193  private:
194  static const std::array<std::string, 3> STRINGS;
195  };
196 
197  static void setSketchPlaneGridType(CompositeFeaturePtr theSketch, SketchPlaneGridType::Enum theType);
198  static SketchPlaneGridType::Enum getSketchPlaneGridType(CompositeFeaturePtr theSketch);
199 
201  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneRectangularGridStepX(CompositeFeaturePtr theSketch);
202 
204  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneRectangularGridStepY(CompositeFeaturePtr theSketch);
205 
207  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneRectangularGridOffsetAngle(CompositeFeaturePtr theSketch);
208 
210  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneRectangularGridOffsetX(CompositeFeaturePtr theSketch);
211 
213  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneRectangularGridOffsetY(CompositeFeaturePtr theSketch);
214 
216  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneCircularGridStepR(CompositeFeaturePtr theSketch);
217 
219  static std::shared_ptr<ModelAPI_AttributeInteger> sketchPlaneCircularGridNumOfAngSegments(CompositeFeaturePtr theSketch);
220 
222  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneCircularGridOffsetAngle(CompositeFeaturePtr theSketch);
223 
225  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneCircularGridOffsetX(CompositeFeaturePtr theSketch);
226 
228  static std::shared_ptr<ModelAPI_AttributeDouble> sketchPlaneCircularGridOffsetY(CompositeFeaturePtr theSketch);
229 
230 
235  static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
236  CompositeFeaturePtr theSketch);
237 
243  static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
244  const TopoDS_Shape& theShape,
245  const ObjectPtr& theObject,
246  CompositeFeaturePtr theSketch);
247 
256  static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
257  const std::shared_ptr<GeomAPI_Shape>& theShape,
258  const ObjectPtr& theObject,
259  CompositeFeaturePtr theSketch,
260  const bool theTemporary,
261  FeaturePtr& theCreatedFeature);
262 
267  static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
268  const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
269 
277  static std::pair<AttributePtr, int> findAttributeBy2dPoint(ObjectPtr theObj,
278  const TopoDS_Shape theShape,
279  FeaturePtr theSketch);
280 
287  static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
288  ModuleBase_IWorkshop* theWorkshop);
289 
295  static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
296  const std::string& theAttribute);
297 
304  static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(QMouseEvent* theEvent,
305  ModuleBase_IViewWindow* theWindow,
306  const FeaturePtr& theSketch);
307 
314  static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(const Handle(V3d_View)& theView,
315  const TopoDS_Shape& theShape,
316  const FeaturePtr& theSketch);
317 
326  static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
327  std::shared_ptr<GeomAPI_Pnt2d> thePoint);
328 
336  static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
337  QList<FeaturePtr>& theCoincidencies,
338  std::string theAttr, QList<bool>& theIsAttributes);
339 
340  /*
341  * Finds and returns feature reerenced to the paramenter feature with the given name if found
342  * \param theFeature a source feature where refsToMe is obtained
343  * \param theFeatureId an identifier of the searched feature
344  */
345  static FeaturePtr findRefsToMeFeature(FeaturePtr theFeature, const std::string& theFeatureId)
346  {
347  if (!theFeature.get())
348  return FeaturePtr();
349 
350  // find first projected feature and edit it
351  const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
352  std::set<AttributePtr>::const_iterator anIt;
353  for (anIt = aRefsList.cbegin(); anIt != aRefsList.cend(); ++anIt) {
354  FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*anIt)->owner());
355  if (aRefFeature && aRefFeature->getKind() == theFeatureId)
356  return aRefFeature;
357  }
358  return FeaturePtr();
359  }
360 
365  static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
366 
368  static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
369  const Events_ID theId);
370 
376  static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
377 
382  static bool isIncludeIntoSketchResult(const ObjectPtr& theObject);
383 
384  static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
385  const std::shared_ptr<GeomAPI_Edge>& theEdge,
387  const CompositeFeaturePtr& theSketch,
388  bool theTemporary,
389  FeaturePtr& theCreatedFeature);
390 
391 
392  static void getFirstAndLastIndexInFolder(const ObjectPtr& theFolder,
393  int& theFirst, int& theLast);
394 
395 
399  static void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
400  std::vector<int>& theColor);
401 
405  static double getDefaultDeflection(const ObjectPtr& theObject);
406 
407 
411  static double getDefaultTransparency();
412 
416  static QCursor getOperationCursor();
417 };
418 
419 #endif
Identifier of the event kind.
Definition: Events_Message.h:36
Interface to the edge object.
Definition: GeomAPI_Edge.h:38
Interface to the face object.
Definition: GeomAPI_Face.h:36
\Plane in 3D place, defined by normal, center and x-direction.
Definition: GeomAPI_Pln.h:38
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:37
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
Definition: PartSet_Tools.h:182
The operation for the sketch feature creation.
Definition: PartSet_Tools.h:69
ConstraintVisibleState
types of constraints which visible state can be changed in the sketch widget
Definition: PartSet_Tools.h:74