1 // Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #ifndef SolveSpaceSolver_Builder_H_
21 #define SolveSpaceSolver_Builder_H_
23 #include <SketchSolver_Builder.h>
24 #include <SketchSolver_Constraint.h>
26 #include <SketchPlugin_Constraint.h>
28 #include <ModelAPI_CompositeFeature.h>
30 /** \class SolveSpaceSolver_Builder
32 * \brief Create bridges between SketchPlugin constraints and SolveSpace constraints
34 class SolveSpaceSolver_Builder : public SketchSolver_Builder
37 /// Default constructor
38 SolveSpaceSolver_Builder() {}
41 /// \brief Returns single instance of builder
42 static BuilderPtr getInstance();
44 /// \brief Creates a storage specific for used solver
45 virtual StoragePtr createStorage(const GroupID& theGroup) const;
46 /// \brief Creates specific solver
47 virtual SolverPtr createSolver() const;
49 /// \brief Creates new constraint(s) using given parameters
50 /// \param theConstraint [in] original constraint
51 /// \param theGroupID [in] group the constraint belongs to
52 /// \param theSketchID [in] sketch the constraint belongs to
53 /// \param theType [in] type of constraint
54 /// \param theValue [in] numeric characteristic of constraint
55 /// (e.g. distance or radius) if applicable
56 /// \param theEntity1 [in] first attribute of constraint
57 /// \param theEntity2 [in] second attribute of constraint
58 /// \param theEntity3 [in] third attribute of constraint
59 /// \param theEntity4 [in] fourth attribute of constraint
60 /// \return Created list of wrappers of constraints applicable for specific solver.
61 /// Most of constraint types lead to single constraint, but there are some kind of
62 /// constraints (e.g. mirror), which may produce couple of constraints.
63 virtual std::list<ConstraintWrapperPtr>
64 createConstraint(ConstraintPtr theConstraint,
65 const GroupID& theGroupID,
66 const EntityID& theSketchID,
67 const SketchSolver_ConstraintType& theType,
68 const double& theValue,
69 const EntityWrapperPtr& theEntity1,
70 const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
71 const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
72 const EntityWrapperPtr& theEntity4 = EntityWrapperPtr()) const;
74 /// \brief Creates new multi-translation or multi-rotation constraint
75 /// \param theConstraint [in] original constraint
76 /// \param theGroupID [in] group the constraint belongs to
77 /// \param theSketchID [in] sketch the constraint belongs to
78 /// \param theType [in] type of constraint
79 /// \param theValue [in] numeric characteristic of constraint
80 /// (angle for multi-rotation) if applicable
81 /// \param theFullValue [in] indicates theValue shows full translation
82 /// delta/rotation angle or delta/angle between neighbor entities
83 /// \param thePoint1 [in] center for multi-rotation or start point for multi-translation
84 /// \param thePoint2 [in] end point for multi-translation (empty for multi-rotation)
85 /// \param theTrsfEnt [in] list of transformed entities
86 virtual std::list<ConstraintWrapperPtr>
87 createConstraint(ConstraintPtr theConstraint,
88 const GroupID& theGroupID,
89 const EntityID& theSketchID,
90 const SketchSolver_ConstraintType& theType,
91 const double& theValue,
92 const bool theFullValue,
93 const EntityWrapperPtr& thePoint1,
94 const EntityWrapperPtr& thePoint2,
95 const std::list<EntityWrapperPtr>& theTrsfEnt) const;
97 /// \brief Update flags for several kinds of constraints
98 virtual void adjustConstraint(ConstraintWrapperPtr theConstraint) const;
100 /// \brief Creates a feature using list of already created attributes
101 /// \param theFeature [in] feature to create
102 /// \param theAttributes [in] attributes of the feature
103 /// \param theGroupID [in] group the feature belongs to
104 /// \param theSketchID [in] sketch the feature belongs to
105 /// \return Created wrapper of the feature applicable for specific solver
106 virtual EntityWrapperPtr createFeature(FeaturePtr theFeature,
107 const std::list<EntityWrapperPtr>& theAttributes,
108 const GroupID& theGroupID,
109 const EntityID& theSketchID = EID_UNKNOWN) const;
111 /// \brief Creates an attribute
112 /// \param theAttribute [in] attribute to create
113 /// \param theGroup [in] group the attribute belongs to
114 /// \param theSketchID [in] sketch the attribute belongs to
115 /// \return Created wrapper of the attribute applicable for specific solver
116 virtual EntityWrapperPtr createAttribute(AttributePtr theAttribute,
117 const GroupID& theGroup,
118 const EntityID& theSketchID = EID_UNKNOWN) const;
121 /// \brief Create necessary constraints to make two object symmetric relatively a given line
122 std::list<ConstraintWrapperPtr> createMirror(ConstraintPtr theConstraint,
123 const GroupID& theGroupID,
124 const EntityID& theSketchID,
125 const EntityWrapperPtr& theEntity1,
126 const EntityWrapperPtr& theEntity2,
127 const EntityWrapperPtr& theMirrorLine) const;
129 /// \brief Converts sketch parameters to the entity applicable for the solver.
130 /// \param theSketch [in] the element to be converted
131 /// \param theGroupID [in] group where the sketch should be created
132 /// \return Entity respective the sketch or empty pointer, it the sketch has incorrect attributes
133 EntityWrapperPtr createSketchEntity(CompositeFeaturePtr theSketch,
134 const GroupID& theGroupID) const;
136 /// \brief Converts two axes of sketch's trihedron to the normal entity
137 /// \param theNormal [in] direction of the normal of the sketch
138 /// \param theDirX [in] direction of the X axis of the sketch
139 /// \param theGroupID [in] group, the normal belongs to
140 /// \return Created entity or empty pointer, if there are incorrect attributes
141 EntityWrapperPtr createNormal(AttributePtr theNormal,
142 AttributePtr theDirX,
143 const GroupID& theGroupID) const;
145 /// \brief Converts a value to SolveSpace parameter
146 /// \param theGroup [in] group to store parameter
147 /// \param theValue [in] value of parameter
148 /// \param theExpr [in] shows the parameter is given by expression
149 /// \return Created parameter's wrapper
150 ParameterWrapperPtr createParameter(const GroupID& theGroup,
151 const double theValue = 0.0,
152 const bool theExpr = false) const;
155 static BuilderPtr mySelf;