Salome HOME
Check multi coincidence and remove fixing of copied entities in MultiRotation/MultiTr...
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_ConstraintMulti.h
4 // Created: 2 Sep 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_ConstraintMulti_H_
8 #define SketchSolver_ConstraintMulti_H_
9
10 #include "SketchSolver.h"
11 #include <SketchSolver_Constraint.h>
12
13 #include <vector>
14
15 /** \class   SketchSolver_ConstraintMulti
16  *  \ingroup Plugins
17  *  \brief   Common base class for the Multi constraints
18  */
19 class SketchSolver_ConstraintMulti : public SketchSolver_Constraint
20 {
21 public:
22   SketchSolver_ConstraintMulti(ConstraintPtr theConstraint) :
23       SketchSolver_Constraint(theConstraint),
24       myNumberOfObjects(0),
25       myNumberOfCopies(0),
26       myAdjusted(false)
27   {}
28
29   virtual int getType() const
30   { return SLVS_C_UNKNOWN; }
31
32   /// \brief Update constraint
33   virtual void update(ConstraintPtr theConstraint = ConstraintPtr());
34
35   /// \brief Tries to remove constraint
36   /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence)
37   virtual bool remove(ConstraintPtr theConstraint = ConstraintPtr());
38
39   /// \brief Adds a feature to constraint and create its analogue in SolveSpace
40   virtual void addFeature(FeaturePtr theFeature);
41
42   /// \brief Update SketchPlugin attributes using the data obtained from SolveSpace entities
43   virtual void refresh()
44   {
45     myAdjusted = false;
46     SketchSolver_Constraint::refresh();
47   }
48
49   /// \brief Verifies, the coincidence between points of copied entities appears or disappears,
50   ///        and removes or adds fixing of corresponding points.
51   void checkCoincidence();
52
53 protected:
54   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
55   virtual void process()
56   { /* do nothing here */ }
57
58   /// \brief Collect entities and their copies, like circles and arcs
59   void processEntities(const std::vector< std::vector<Slvs_hEntity> >& theEntAndCopies);
60
61   /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
62   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
63   /// \param[out] theAttributes list of attributes to be filled
64   virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes)
65   { /* do nothing here */ }
66
67   /// \brief This method is used in derived objects to check consistence of constraint.
68   virtual void adjustConstraint();
69
70   /// \brief Update parameters of derived classes
71   virtual void updateLocal() = 0;
72
73   /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
74   virtual const std::string& nameNbCopies() = 0;
75
76 protected:
77   /// \brief Convert absolute coordinates to relative coordinates
78   virtual void getRelative(double theAbsX, double theAbsY, double& theRelX, double& theRelY) = 0;
79   /// \brief Convert relative coordinates to absolute coordinates
80   virtual void getAbsolute(double theRelX, double theRelY, double& theAbsX, double& theAbsY) = 0;
81   /// \brief Apply transformation for relative coordinates
82   virtual void transformRelative(double& theX, double& theY) = 0;
83
84 protected:
85   size_t myNumberOfObjects; ///< number of previous initial objects
86   size_t myNumberOfCopies;  ///< number of previous copies of initial objects
87
88   std::vector< std::vector<Slvs_hEntity> > myPointsAndCopies; ///< list of initial points and their copies
89   std::vector< std::vector<Slvs_hEntity> > myCircsAndCopies;  ///< list of circles and their copies (to change their radii together)
90
91   std::set<Slvs_hEntity> myPointsJustUpdated; ///< list of points touched by user
92   std::set<Slvs_hEntity> myInitialPoints;     ///< list of points containing initial objects
93
94   bool myAdjusted; ///< the constraint is already adjusted (to not do it several times)
95 };
96
97 #endif