Salome HOME
Temporary modification
[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   /// Constructor based on SketchPlugin constraint
23   SketchSolver_ConstraintMulti(ConstraintPtr theConstraint) :
24       SketchSolver_Constraint(theConstraint),
25       myNumberOfObjects(0),
26       myNumberOfCopies(0),
27       myAdjusted(false),
28       myIsFullValue(false)
29   {}
30
31   /// \brief Update constraint
32   virtual void update();
33   /// \brief Update constraint
34   void update(bool isForce);
35
36   /// \brief Tries to remove constraint
37   /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence)
38   virtual bool remove();
39
40   /// \brief Check the feature is a source or a copy of Multi-constraint
41   virtual bool isUsed(FeaturePtr theFeature) const;
42   /// \brief Check the attribute is used in Multi-constraint
43   virtual bool isUsed(AttributePtr theAttribute) const;
44
45 protected:
46   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
47   virtual void process()
48   { /* do nothing here */ }
49
50   /// \brief Collect entities which translated or rotated (not their copies)
51   void getEntities(std::list<EntityWrapperPtr>& theEntities);
52
53   /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
54   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
55   /// \param[out] theAttributes list of attributes to be filled
56   virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes)
57   { /* do nothing here */ }
58
59   /// \brief This method is used in derived objects to check consistence of constraint.
60   virtual void adjustConstraint();
61
62   /// \brief Update parameters of derived classes
63   virtual void updateLocal() = 0;
64
65   /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
66   virtual const std::string& nameNbObjects() = 0;
67   
68 protected:
69   /// \brief Convert absolute coordinates to relative coordinates
70   virtual void getRelative(double theAbsX, double theAbsY, double& theRelX, double& theRelY) = 0;
71   /// \brief Convert relative coordinates to absolute coordinates
72   virtual void getAbsolute(double theRelX, double theRelY, double& theAbsX, double& theAbsY) = 0;
73   /// \brief Apply transformation for relative coordinates
74   virtual void transformRelative(double& theX, double& theY) = 0;
75
76 protected:
77   int myNumberOfObjects; ///< number of previous initial objects
78   int myNumberOfCopies;  ///< number of previous copies of initial objects
79   bool myIsFullValue;    ///< value whether the angle/distance is a full or single for objects
80
81   bool myAdjusted; ///< the constraint is already adjusted (to not do it several times)
82
83   std::set<FeaturePtr> myFeatures; ///< list of features and their copies to find whether some of them are disappeared
84 };
85
86 #endif