Salome HOME
Issue #17347: B-Splines in Sketcher
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Tools.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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 PlaneGCSSolver_Tools_H_
21 #define PlaneGCSSolver_Tools_H_
22
23 #include <SketchSolver_Constraint.h>
24 #include <SketchSolver_ConstraintMovement.h>
25 #include <SketchPlugin_Constraint.h>
26
27 class GeomAPI_Circ2d;
28 class GeomAPI_Ellipse2d;
29 class GeomAPI_Lin2d;
30 class GeomAPI_Pnt2d;
31
32 class ModelAPI_AttributeDoubleArray;
33 class ModelAPI_AttributeIntArray;
34
35 /** \namespace  PlaneGCSSolver_Tools
36  *  \ingroup    Plugins
37  *  \brief      Converter tools
38  */
39 namespace PlaneGCSSolver_Tools
40 {
41   /// \brief Creates a solver's constraint using given SketchPlugin constraint
42   ///        or returns empty pointer if not all attributes are correct
43   SolverConstraintPtr createConstraint(ConstraintPtr theConstraint);
44
45   /// \brief Creates temporary constraint to fix the feature after movement
46   std::shared_ptr<SketchSolver_ConstraintMovement>
47       createMovementConstraint(FeaturePtr theMovedFeature);
48   /// \brief Creates temporary constraint to fix the attribute after movement
49   std::shared_ptr<SketchSolver_ConstraintMovement>
50       createMovementConstraint(AttributePtr theMovedAttribute);
51   /// \brief Creates temporary constraint to fix the point in array after movement
52   std::shared_ptr<SketchSolver_ConstraintMovement>
53       createMovementConstraint(const std::pair<AttributePtr, int>& theMovedPointInArray);
54
55   /// \brief Creates new constraint using given parameters
56   /// \param theConstraint [in]  original constraint
57   /// \param theType       [in]  type of constraint
58   /// \param theValue      [in]  numeric characteristic of constraint
59   ///                            (e.g. distance or radius) if applicable
60   /// \param theEntity1    [in]  first attribute of constraint
61   /// \param theEntity2    [in]  second attribute of constraint
62   /// \param theEntity3    [in]  third attribute of constraint
63   /// \param theEntity4    [in]  fourth attribute of constraint
64   /// \return Created wrapper of constraints applicable for specific solver.
65   ConstraintWrapperPtr createConstraint(ConstraintPtr theConstraint,
66                                         const SketchSolver_ConstraintType& theType,
67                                         const EntityWrapperPtr& theValue,
68                                         const EntityWrapperPtr& theEntity1,
69                                         const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
70                                         const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
71                                         const EntityWrapperPtr& theEntity4 = EntityWrapperPtr());
72
73   /// \brief Return \c true if the attribute is used in PlaneGCS solver
74   /// \param[in] theAttrName  name of the attribute
75   /// \param[in] theOwnerName name of the parent feature
76   bool isAttributeApplicable(const std::string& theAttrName,
77                              const std::string& theOwnerName);
78
79   /// \brief Convert entity to point
80   /// \return empty pointer if the entity is not a point
81   std::shared_ptr<GeomAPI_Pnt2d> point(EntityWrapperPtr theEntity);
82   /// \brief Convert entity to line
83   /// \return empty pointer if the entity is not a line
84   std::shared_ptr<GeomAPI_Lin2d> line(EntityWrapperPtr theEntity);
85   /// \brief Convert entity to circle
86   /// \return empty pointer if the entity is not a circle
87   std::shared_ptr<GeomAPI_Circ2d> circle(EntityWrapperPtr theEntity);
88   /// \brief Convert entity to ellipse
89   /// \return empty pointer if the entity is not an ellipse
90   std::shared_ptr<GeomAPI_Ellipse2d> ellipse(EntityWrapperPtr theEntity);
91
92   /// \brief Convert entity to line
93   /// \return empty pointer if the entity is not a line
94   std::shared_ptr<GeomAPI_Lin2d> line(FeaturePtr theFeature);
95
96   /// \brief Update start and end parameters of circular and elliptic arcs
97   ///        respectively to start and end points on the arc.
98   ///        For the circular arc, the radius is calculated too.
99   void recalculateArcParameters(EntityWrapperPtr theArc);
100
101   /// brief Return list of parameters for the given entity
102   GCS::SET_pD parameters(const EntityWrapperPtr& theEntity);
103
104   /// \brief Update value in theDest if theSource is differ more than theTolerance
105   /// \return \c true if the value was updated.
106   bool updateValue(const double& theSource, double& theDest,
107                    const double theTolerance = 1.e-4 * tolerance);
108
109   /// \brief Provide an interface to access values in attribute which is an array of values
110   class AttributeArray
111   {
112   public:
113     AttributeArray(AttributePtr theAttribute);
114
115     bool isInitialized() const;
116
117     int size() const;
118
119     double value(const int theIndex) const;
120
121   private:
122     std::shared_ptr<ModelAPI_AttributeDoubleArray> myDouble;
123     std::shared_ptr<ModelAPI_AttributeIntArray> myInteger;
124   };
125 };
126
127 #endif