Salome HOME
Issue #901 - It is possible to define empty name for parameter
[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
50 protected:
51   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
52   virtual void process()
53   { /* do nothing here */ }
54
55   /// \brief Collect entities and their copies, like circles and arcs
56   void processEntities(const std::vector< std::vector<Slvs_hEntity> >& theEntAndCopies);
57
58   /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
59   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
60   /// \param[out] theAttributes list of attributes to be filled
61   virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes)
62   { /* do nothing here */ }
63
64   /// \brief This method is used in derived objects to check consistence of constraint.
65   virtual void adjustConstraint();
66
67   /// \brief Update parameters of derived classes
68   virtual void updateLocal() = 0;
69
70   /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
71   virtual const std::string& nameNbCopies() = 0;
72
73 protected:
74   /// \brief Convert absolute coordinates to relative coordinates
75   virtual void getRelative(double theAbsX, double theAbsY, double& theRelX, double& theRelY) = 0;
76   /// \brief Convert relative coordinates to absolute coordinates
77   virtual void getAbsolute(double theRelX, double theRelY, double& theAbsX, double& theAbsY) = 0;
78   /// \brief Apply transformation for relative coordinates
79   virtual void transformRelative(double& theX, double& theY) = 0;
80
81 protected:
82   size_t myNumberOfObjects; ///< number of previous initial objects
83   size_t myNumberOfCopies;  ///< number of previous copies of initial objects
84
85   std::vector< std::vector<Slvs_hEntity> > myPointsAndCopies; ///< list of initial points and their copies
86   std::vector< std::vector<Slvs_hEntity> > myCircsAndCopies;  ///< list of circles and their copies (to change their radii together)
87
88   std::set<Slvs_hEntity> myPointsJustUpdated; ///< list of points touched by user
89   std::set<Slvs_hEntity> myInitialPoints;     ///< list of points containing initial objects
90
91   bool myAdjusted; ///< the constraint is already adjusted (to not do it several times)
92 };
93
94 #endif