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