Salome HOME
9027af6b0cc085b7c4b92de8c3252a04746bf36a
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef SketchSolver_ConstraintMulti_H_
21 #define SketchSolver_ConstraintMulti_H_
22
23 #include <SketchSolver_Constraint.h>
24
25 #include <vector>
26
27 /** \class   SketchSolver_ConstraintMulti
28  *  \ingroup Plugins
29  *  \brief   Common base class for the Multi constraints
30  */
31 class SketchSolver_ConstraintMulti : public SketchSolver_Constraint
32 {
33 public:
34   /// Constructor based on SketchPlugin constraint
35   SketchSolver_ConstraintMulti(ConstraintPtr theConstraint) :
36       SketchSolver_Constraint(theConstraint),
37       myNumberOfObjects(0),
38       myNumberOfCopies(0),
39       myIsFullValue(false),
40       myAdjusted(false),
41       myIsEventsBlocked(false)
42   {}
43
44   /// \brief Update constraint
45   virtual void update();
46
47   /// \brief Notify this object about the feature is changed somewhere
48   virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update*);
49
50   /// \brief Tries to remove constraint
51   /// \return \c false, if current constraint contains another SketchPlugin
52   /// constraints (like for multiple coincidence)
53   virtual bool remove();
54
55   /// \brief Block or unblock events from this constraint
56   virtual void blockEvents(bool isBlocked);
57
58 protected:
59   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
60   virtual void process()
61   { /* do nothing here */ }
62
63   /// \brief Collect entities which are translated or rotated (not their copies)
64   void getEntities(std::list<EntityWrapperPtr>& theEntities);
65
66   /// \brief Generate list of attributes of constraint in order useful for SolveSpace constraints
67   virtual void getAttributes(EntityWrapperPtr&, std::vector<EntityWrapperPtr>&)
68   { /* do nothing here */ }
69
70   /// \brief This method is used in derived objects to check consistence of constraint.
71   virtual void adjustConstraint();
72
73   /// \brief Update parameters of derived classes
74   virtual void updateLocal() = 0;
75
76   /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
77   virtual const std::string& nameNbObjects() = 0;
78
79 protected:
80   /// \brief Convert absolute coordinates to relative coordinates
81   virtual void getRelative(double theAbsX, double theAbsY, double& theRelX, double& theRelY) = 0;
82   /// \brief Convert relative coordinates to absolute coordinates
83   virtual void getAbsolute(double theRelX, double theRelY, double& theAbsX, double& theAbsY) = 0;
84   /// \brief Apply transformation for relative coordinates
85   virtual void transformRelative(double& theX, double& theY) = 0;
86
87 protected:
88   int myNumberOfObjects; ///< number of previous initial objects
89   int myNumberOfCopies;  ///< number of previous copies of initial objects
90   bool myIsFullValue;    ///< value whether the angle/distance is a full or single for objects
91
92   bool myAdjusted; ///< the constraint is already adjusted (to not do it several times)
93
94   /// lists of original features and their copies to find whether some of them are disappeared
95   std::set<FeaturePtr> myOriginalFeatures;
96   std::set<FeaturePtr> myCopiedFeatures;
97
98   bool myIsEventsBlocked;
99 };
100
101 #endif