KiCad PCB EDA Suite
edit_constraints.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef EDIT_CONSTRAINTS_H_
26 #define EDIT_CONSTRAINTS_H_
27 
28 #include <math/vector2d.h>
29 #include <boost/function.hpp>
30 
31 class EDIT_POINT;
32 class EDIT_LINE;
33 class EDIT_POINTS;
34 
41 template<class EDIT_TYPE>
43 {
44 public:
50  EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {};
51 
52  virtual ~EDIT_CONSTRAINT() {};
53 
59  virtual void Apply( EDIT_TYPE& aHandle ) = 0;
60 
66  void Apply()
67  {
69  }
70 
71 protected:
72  EDIT_TYPE& m_constrained;
73 };
74 
75 
81 class EC_VERTICAL : public EDIT_CONSTRAINT<EDIT_POINT>
82 {
83 public:
90  EC_VERTICAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
91  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
92  {}
93 
95  virtual void Apply( EDIT_POINT& aHandle ) override;
96 
97 private:
99 };
100 
101 
107 class EC_HORIZONTAL : public EDIT_CONSTRAINT<EDIT_POINT>
108 {
109 public:
116  EC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
117  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
118  {}
119 
121  virtual void Apply( EDIT_POINT& aHandle ) override;
122 
123 private:
125 };
126 
127 
134 class EC_45DEGREE : public EDIT_CONSTRAINT<EDIT_POINT>
135 {
136 public:
143  EC_45DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
144  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
145  {}
146 
148  virtual void Apply( EDIT_POINT& aHandle ) override;
149 
150 private:
152 };
153 
154 
161 class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
162 {
163 public:
164  EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer );
165 
167  virtual void Apply( EDIT_POINT& aHandle ) override;
168 
169 private:
172 };
173 
174 
180 class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT>
181 {
182 public:
190  EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) :
191  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_center( aCenter ), m_end( aEnd )
192  {}
193 
195  virtual void Apply( EDIT_POINT& aHandle ) override;
196 
197 private:
200 
203 };
204 
205 
212 class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE>
213 {
214 public:
215  EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints );
216 
217  virtual ~EC_CONVERGING();
218 
220  virtual void Apply( EDIT_LINE& aHandle ) override;
221 
222 private:
225 
228 
232 
235 
238 };
239 
240 
248 class EC_SNAPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
249 {
250 public:
252  typedef boost::function<VECTOR2D (const VECTOR2D&)> V2D_TRANSFORM_FUN;
253 
254  EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun );
255 
256  virtual ~EC_SNAPLINE()
257  {}
258 
260  virtual void Apply( EDIT_LINE& aHandle ) override;
261 
262 private:
264  V2D_TRANSFORM_FUN m_snapFun;
265 };
266 
267 #endif /* EDIT_CONSTRAINTS_H_ */
void Apply()
Function Apply()
VECTOR2I m_line
Vector representing the constraining line.
Class EC_CONVERGING.
virtual ~EC_CONVERGING()
EC_45DEGREE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Constructor.
const EDIT_POINT & m_center
Point that imposes the constraint (center of the circle).
Class EDIT_LINE.
Definition: edit_points.h:189
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
Additional constriant, applied when at least two points are collinear.
EC_CIRCLE(EDIT_POINT &aConstrained, const EDIT_POINT &aCenter, const EDIT_POINT &aEnd)
Constructor.
EDIT_CONSTRAINT(EDIT_TYPE &aConstrained)
Constructor.
Class EC_VERTICAL.
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
EC_LINE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Class EC_LINE.
Class EC_45DEGREE.
Class EC_CIRCLE.
EC_SNAPLINE(EDIT_LINE &aLine, V2D_TRANSFORM_FUN aSnapFun)
Class EC_HORIZONTAL.
const EDIT_POINT & m_end
Point that imposes the constraint (decides on the radius of the circle).
boost::function< VECTOR2D(const VECTOR2D &)> V2D_TRANSFORM_FUN
Typedef for a function that determines snapping point.
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Constraint for end side segment.
V2D_TRANSFORM_FUN m_snapFun
Function that determines snapping point.
Class EDIT_POINTS.
Definition: edit_points.h:305
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
Constraint for origin side segment.
virtual ~EDIT_CONSTRAINT()
EC_VERTICAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Constructor.
VECTOR2I m_draggedVector
Vector that represents the initial direction of the dragged segment.
EDIT_POINTS & m_editPoints
EDIT_POINTS instance that stores currently modified lines.
EC_CONVERGING(EDIT_LINE &aLine, EDIT_POINTS &aPoints)
EDIT_TYPE & m_constrained
Point that is constrained by rules implemented by Apply()
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
Class EDIT_POINT.
Definition: edit_points.h:46
EC_HORIZONTAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Constructor.
Class EDIT_CONSTRAINT.
virtual ~EC_SNAPLINE()
Class EC_SNAPLINE.
const EDIT_POINT & m_constrainer
Point that imposes the constraint.