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  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef EDIT_CONSTRAINTS_H_
28 #define EDIT_CONSTRAINTS_H_
29 
30 #include <math/vector2d.h>
31 #include <functional>
32 
33 class EDIT_POINT;
34 class EDIT_LINE;
35 class EDIT_POINTS;
36 
37 
39 {
42  SNAP_BY_GRID // Keep it on grid if it started on grid (treat x and y independently)
43 };
44 
45 
52 template<class EDIT_TYPE>
54 {
55 public:
59  EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {};
60 
61  virtual ~EDIT_CONSTRAINT() {};
62 
66  virtual void Apply( EDIT_TYPE& aHandle ) = 0;
67 
71  void Apply()
72  {
74  }
75 
76 protected:
77  EDIT_TYPE& m_constrained;
78 };
79 
80 
84 class EC_VERTICAL : public EDIT_CONSTRAINT<EDIT_POINT>
85 {
86 public:
91  EC_VERTICAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
92  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
93  {}
94 
96  virtual void Apply( EDIT_POINT& aHandle ) override;
97 
98 private:
100 };
101 
102 
106 class EC_HORIZONTAL : public EDIT_CONSTRAINT<EDIT_POINT>
107 {
108 public:
113  EC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
114  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
115  {}
116 
118  virtual void Apply( EDIT_POINT& aHandle ) override;
119 
120 private:
122 };
123 
124 
129 class EC_45DEGREE : public EDIT_CONSTRAINT<EDIT_POINT>
130 {
131 public:
136  EC_45DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
137  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
138  {}
139 
141  virtual void Apply( EDIT_POINT& aHandle ) override;
142 
143 private:
145 };
146 
147 
152 class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
153 {
154 public:
155  EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer );
156 
158  virtual void Apply( EDIT_POINT& aHandle ) override;
159 
160 private:
163 };
164 
165 
169 class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT>
170 {
171 public:
177  EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) :
178  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_center( aCenter ), m_end( aEnd )
179  {}
180 
182  virtual void Apply( EDIT_POINT& aHandle ) override;
183 
184 private:
187 
190 };
191 
192 
197 class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE>
198 {
199 public:
200  EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints );
201 
202  virtual ~EC_CONVERGING();
203 
205  virtual void Apply( EDIT_LINE& aHandle ) override;
206 
207 private:
210 
213 
217 
220 
223 };
224 
225 
231 class EC_SNAPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
232 {
233 public:
235  typedef std::function<VECTOR2D( const VECTOR2D& )> V2D_TRANSFORM_FUN;
236 
237  EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun );
238 
239  virtual ~EC_SNAPLINE()
240  {}
241 
243  virtual void Apply( EDIT_LINE& aHandle ) override;
244 
245 private:
248 };
249 
250 
255 class EC_PERPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
256 {
257 public:
258 
259  EC_PERPLINE( EDIT_LINE& aLine );
260 
261  virtual ~EC_PERPLINE()
262  {}
263 
265  virtual void Apply( EDIT_LINE& aHandle ) override;
266 
267 private:
270 };
271 
272 #endif /* EDIT_CONSTRAINTS_H_ */
void Apply()
Correct coordinates of the constrained edit handle.
VECTOR2I m_line
Vector representing the constraining line.
EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes and all...
virtual ~EC_CONVERGING()
Correct coordinates of the constrained edit handle.
EC_45DEGREE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Correct coordinates of the constrained edit handle.
const EDIT_POINT & m_center
< Point that imposes the constraint (center of the circle).
Represent a line connecting two EDIT_POINTs.
Definition: edit_points.h:215
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
EDIT_POINTS instance that stores currently modified lines.
EDIT_CONSTRAINT for a EDIT_LINE, that constrains the line to move perpendicular to the line itself.
virtual ~EC_PERPLINE()
Correct coordinates of the constrained edit handle.
EC_CIRCLE(EDIT_POINT &aConstrained, const EDIT_POINT &aCenter, const EDIT_POINT &aEnd)
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT(EDIT_TYPE &aConstrained)
EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
EC_LINE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined by 2 points).
EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45 degree mu...
EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
EC_SNAPLINE(EDIT_LINE &aLine, V2D_TRANSFORM_FUN aSnapFun)
std::function< VECTOR2D(const VECTOR2D &)> V2D_TRANSFORM_FUN
< Typedef for a function that determines snapping point.
EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
const EDIT_POINT & m_end
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Additional constraint, applied when at least two points are collinear.
V2D_TRANSFORM_FUN m_snapFun
< Function that determines snapping point.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
Definition: edit_points.h:322
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
< Constraint for origin side segment.
virtual ~EDIT_CONSTRAINT()
EC_VERTICAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Correct coordinates of the constrained edit handle.
VECTOR2I m_draggedVector
EDIT_POINTS & m_editPoints
Vector that represents the initial direction of the dragged segment.
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.
Represent a single point that can be used for modifying items.
Definition: edit_points.h:47
EC_HORIZONTAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
Correct coordinates of the constrained edit handle.
Describe constraints between two edit handles.
virtual ~EC_SNAPLINE()
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT for a EDIT_LINE, one of the ends is snapped to a spot determined by a transform funct...
EC_PERPLINE(EDIT_LINE &aLine)
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
GRID_CONSTRAINT_TYPE