1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SolveSpaceSolver_Builder.h
4 // Created: 25 Mar 2015
5 // Author: Artem ZHIDKOV
7 #ifndef SolveSpaceSolver_Builder_H_
8 #define SolveSpaceSolver_Builder_H_
10 #include <SketchSolver_Builder.h>
11 #include <SketchSolver_Constraint.h>
13 #include <SketchPlugin_Constraint.h>
15 #include <ModelAPI_CompositeFeature.h>
17 /** \class SolveSpaceSolver_Builder
19 * \brief Create bridges between SketchPlugin constraints and SolveSpace constraints
21 class SolveSpaceSolver_Builder : public SketchSolver_Builder
24 /// Default constructor
25 SolveSpaceSolver_Builder() {}
28 /// \brief Returns single instance of builder
29 static BuilderPtr getInstance();
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;
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;
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 EntityWrapperPtr& thePoint1,
76 const EntityWrapperPtr& thePoint2,
77 const std::list<EntityWrapperPtr>& theTrsfEnt) const;
79 /// \brief Update flags for several kinds of constraints
80 virtual void adjustConstraint(ConstraintWrapperPtr theConstraint) const;
82 /// \brief Creates a feature using list of already created attributes
83 /// \param theFeature [in] feature to create
84 /// \param theAttributes [in] attributes of the feature
85 /// \param theGroupID [in] group the feature belongs to
86 /// \param theSketchID [in] sketch the feature belongs to
87 /// \return Created wrapper of the feature applicable for specific solver
88 virtual EntityWrapperPtr createFeature(FeaturePtr theFeature,
89 const std::list<EntityWrapperPtr>& theAttributes,
90 const GroupID& theGroupID,
91 const EntityID& theSketchID = EID_UNKNOWN) const;
93 /// \brief Creates an attribute
94 /// \param theAttribute [in] attribute to create
95 /// \param theGroup [in] group the attribute belongs to
96 /// \param theSketchID [in] sketch the attribute belongs to
97 /// \return Created wrapper of the attribute applicable for specific solver
98 virtual EntityWrapperPtr createAttribute(AttributePtr theAttribute,
99 const GroupID& theGroup,
100 const EntityID& theSketchID = EID_UNKNOWN) const;
103 /// \brief Create necessary constraints to make two object symmetric relatively a given line
104 std::list<ConstraintWrapperPtr> createMirror(ConstraintPtr theConstraint,
105 const GroupID& theGroupID,
106 const EntityID& theSketchID,
107 const EntityWrapperPtr& theEntity1,
108 const EntityWrapperPtr& theEntity2,
109 const EntityWrapperPtr& theMirrorLine) const;
111 /// \brief Converts sketch parameters to the entity applicable for the solver.
112 /// \param theSketch [in] the element to be converted
113 /// \param theGroupID [in] group where the sketch should be created
114 /// \return Entity respective the sketch or empty pointer, it the sketch has incorrect attributes
115 EntityWrapperPtr createSketchEntity(CompositeFeaturePtr theSketch,
116 const GroupID& theGroupID) const;
118 /// \brief Converts two axes of sketch's trihedron to the normal entity
119 /// \param theNormal [in] direction of the normal of the sketch
120 /// \param theDirX [in] direction of the X axis of the sketch
121 /// \param theGroupID [in] group, the normal belongs to
122 /// \return Created entity or empty pointer, if there are incorrect attributes
123 EntityWrapperPtr createNormal(AttributePtr theNormal,
124 AttributePtr theDirX,
125 const GroupID& theGroupID) const;
127 /// \brief Converts a value to SolveSpace parameter
128 /// \param theGroup [in] group to store parameter
129 /// \param theValue [in] value of parameter
130 /// \param theExpr [in] shows the parameter is given by expression
131 /// \return Created parameter's wrapper
132 ParameterWrapperPtr createParameter(const GroupID& theGroup,
133 const double theValue = 0.0,
134 const bool theExpr = false) const;
137 static BuilderPtr mySelf;