Salome HOME
2D point selection in multi-rotation/multi-translation.
[modules/shaper.git] / src / SketchSolver / SolveSpaceSolver / SolveSpaceSolver_Builder.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SolveSpaceSolver_Builder.h
4 // Created: 25 Mar 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SolveSpaceSolver_Builder_H_
8 #define SolveSpaceSolver_Builder_H_
9
10 #include <SketchSolver_Builder.h>
11 #include <SketchSolver_Constraint.h>
12
13 #include <SketchPlugin_Constraint.h>
14
15 #include <ModelAPI_CompositeFeature.h>
16
17 /** \class   SolveSpaceSolver_Builder
18  *  \ingroup Plugins
19  *  \brief   Create bridges between SketchPlugin constraints and SolveSpace constraints
20  */
21 class SolveSpaceSolver_Builder : public SketchSolver_Builder
22 {
23 private:
24   /// Default constructor
25   SolveSpaceSolver_Builder() {}
26
27 public:
28   /// \brief Returns single instance of builder
29   static BuilderPtr getInstance();
30
31   /// \brief Creates a storage specific for used solver
32   virtual StoragePtr createStorage(const GroupID& theGroup) const;
33   /// \brief Creates specific solver
34   virtual SolverPtr createSolver() const;
35
36   /// \brief Creates new constraint(s) using given parameters
37   /// \param theConstraint [in]  original constraint
38   /// \param theGroupID    [in]  group the constraint belongs to
39   /// \param theSketchID   [in]  sketch the constraint belongs to
40   /// \param theType       [in]  type of constraint
41   /// \param theValue      [in]  numeric characteristic of constraint (e.g. distance or radius) if applicable
42   /// \param theEntity1    [in]  first attribute of constraint
43   /// \param theEntity2    [in]  second attribute of constraint
44   /// \param theEntity3    [in]  third attribute of constraint
45   /// \param theEntity4    [in]  fourth attribute of constraint
46   /// \return Created list of wrappers of constraints applicable for specific solver.
47   ///         Most of constraint types lead to single constraint, but there are some kind of
48   ///         constraints (e.g. mirror), which may produce couple of constraints.
49   virtual std::list<ConstraintWrapperPtr>
50     createConstraint(ConstraintPtr theConstraint,
51                      const GroupID& theGroupID,
52                      const EntityID& theSketchID,
53                      const SketchSolver_ConstraintType& theType,
54                      const double& theValue,
55                      const EntityWrapperPtr& theEntity1,
56                      const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
57                      const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
58                      const EntityWrapperPtr& theEntity4 = EntityWrapperPtr()) const;
59
60   /// \brief Creates new multi-translation or multi-rotation constraint
61   /// \param theConstraint [in]  original constraint
62   /// \param theGroupID    [in]  group the constraint belongs to
63   /// \param theSketchID   [in]  sketch the constraint belongs to
64   /// \param theType       [in]  type of constraint
65   /// \param theValue      [in]  numeric characteristic of constraint (angle for multi-rotation) if applicable
66   /// \param thePoint1     [in]  center for multi-rotation or start point for multi-translation
67   /// \param thePoint2     [in]  end point for multi-translation (empty for multi-rotation)
68   /// \param theTrsfEnt    [in]  list of transformed entities
69   virtual std::list<ConstraintWrapperPtr>
70     createConstraint(ConstraintPtr theConstraint,
71                      const GroupID& theGroupID,
72                      const EntityID& theSketchID,
73                      const SketchSolver_ConstraintType& theType,
74                      const double& theValue,
75                      const bool& theFullValue,
76                      const EntityWrapperPtr& thePoint1,
77                      const EntityWrapperPtr& thePoint2,
78                      const std::list<EntityWrapperPtr>& theTrsfEnt) const;
79
80   /// \brief Update flags for several kinds of constraints
81   virtual void adjustConstraint(ConstraintWrapperPtr theConstraint) const;
82
83   /// \brief Creates a feature using list of already created attributes
84   /// \param theFeature    [in]  feature to create
85   /// \param theAttributes [in]  attributes of the feature
86   /// \param theGroupID    [in]  group the feature belongs to
87   /// \param theSketchID   [in]  sketch the feature belongs to
88   /// \return Created wrapper of the feature applicable for specific solver
89   virtual EntityWrapperPtr createFeature(FeaturePtr theFeature,
90                                          const std::list<EntityWrapperPtr>& theAttributes,
91                                          const GroupID& theGroupID,
92                                          const EntityID& theSketchID = EID_UNKNOWN) const;
93
94   /// \brief Creates an attribute
95   /// \param theAttribute [in]  attribute to create
96   /// \param theGroup     [in]  group the attribute belongs to
97   /// \param theSketchID  [in]  sketch the attribute belongs to
98   /// \return Created wrapper of the attribute applicable for specific solver
99   virtual EntityWrapperPtr createAttribute(AttributePtr theAttribute,
100                                            const GroupID& theGroup,
101                                            const EntityID& theSketchID = EID_UNKNOWN) const;
102
103 private:
104   /// \brief Create necessary constraints to make two object symmetric relatively a given line
105   std::list<ConstraintWrapperPtr> createMirror(ConstraintPtr theConstraint,
106                                                const GroupID& theGroupID,
107                                                const EntityID& theSketchID,
108                                                const EntityWrapperPtr& theEntity1,
109                                                const EntityWrapperPtr& theEntity2,
110                                                const EntityWrapperPtr& theMirrorLine) const;
111
112   /// \brief Converts sketch parameters to the entity applicable for the solver.
113   /// \param theSketch  [in]  the element to be converted
114   /// \param theGroupID [in]  group where the sketch should be created
115   /// \return Entity respective the sketch or empty pointer, it the sketch has incorrect attributes
116   EntityWrapperPtr createSketchEntity(CompositeFeaturePtr theSketch,
117                                       const GroupID& theGroupID) const;
118
119   /// \brief Converts two axes of sketch's trihedron to the normal entity
120   /// \param theNormal  [in]  direction of the normal of the sketch
121   /// \param theDirX    [in]  direction of the X axis of the sketch
122   /// \param theGroupID [in]  group, the normal belongs to
123   /// \return Created entity or empty pointer, if there are incorrect attributes
124   EntityWrapperPtr createNormal(AttributePtr theNormal,
125                                 AttributePtr theDirX,
126                                 const GroupID& theGroupID) const;
127
128   /// \brief Converts a value to SolveSpace parameter
129   /// \param theGroup [in]  group to store parameter
130   /// \param theValue [in]  value of parameter
131   /// \param theExpr  [in]  shows the parameter is given by expression
132   /// \return Created parameter's wrapper
133   ParameterWrapperPtr createParameter(const GroupID& theGroup,
134                                       const double theValue = 0.0,
135                                       const bool theExpr = false) const;
136
137 private:
138   static BuilderPtr mySelf;
139 };
140
141 #endif