Salome HOME
Update constrain Mirror to keep non-zero the length of mirror line (issue #809)
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMirror.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_ConstraintMirror.h
4 // Created: 1 Apr 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_ConstraintMirror_H_
8 #define SketchSolver_ConstraintMirror_H_
9
10 #include "SketchSolver.h"
11 #include <SketchSolver_Constraint.h>
12
13 /** \class   SketchSolver_ConstraintMirror
14  *  \ingroup Plugins
15  *  \brief   Convert fillet constraint to SolveSpace structure
16  */
17 class SketchSolver_ConstraintMirror : public SketchSolver_Constraint
18 {
19 public:
20   SketchSolver_ConstraintMirror(ConstraintPtr theConstraint) :
21       SketchSolver_Constraint(theConstraint),
22       myNumberOfObjects(0),
23       myMirrorLineLength(0.0)
24   {}
25
26   virtual int getType() const
27   { return SLVS_C_SYMMETRIC_LINE; }
28
29   /// \brief Update constraint
30   virtual void update(ConstraintPtr theConstraint = ConstraintPtr());
31
32   /// \brief Tries to remove constraint
33   /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence)
34   virtual bool remove(ConstraintPtr theConstraint = ConstraintPtr());
35
36 protected:
37   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
38   virtual void process();
39
40   /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
41   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
42   /// \param[out] theAttributes list of attributes to be filled
43   virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes)
44   { /* do nothing here */ }
45
46   /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
47   /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
48   /// \return \c true if some attributes are changed
49   virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
50
51   /// \brief Generate list of entities of mirror constraint
52   /// \param[out] theMirrorLine     entity corresponding to mirror line
53   /// \param[out] theBaseEntities   list of entities to mirror
54   /// \param[out] theMirrorEntities list of mirrored entities
55   void getAttributes(Slvs_Entity& theMirrorLine,
56                      std::vector<Slvs_Entity>& theBaseEntities,
57                      std::vector<Slvs_Entity>& theMirrorEntities);
58
59   /// \brief This method is used in derived objects to check consistence of constraint.
60   ///        E.g. the distance between line and point may be signed.
61   virtual void adjustConstraint();
62
63 private:
64   /// \brief Change parameters of entities to be symmetric relative a line,
65   ///        given by array of parameters (coordinates of first and last points)
66   void makeMirrorEntity(const Slvs_Entity& theBase,
67                         const Slvs_Entity& theMirror,
68                         const double theMirrorLine[]) const;
69
70   /// \brief Precisely update last point to be on arc
71   void adjustArcPoints(const Slvs_Entity& theArc) const;
72
73 private:
74   size_t myNumberOfObjects;  ///< number of previously mirrored objects
75   double myMirrorLineLength; ///< length of mirror line (should be always greater than 0)
76 };
77
78 #endif