KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
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 <tool/grid_helper.h>
32#include <functional>
33
34class EDIT_POINT;
35class EDIT_LINE;
36class EDIT_POINTS;
37
38
40{
43 SNAP_BY_GRID // Keep it on grid if it started on grid (treat x and y independently)
44};
45
46
48{
52};
53
54
61template<class EDIT_TYPE>
63{
64public:
68 EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) :
69 m_constrained( aConstrained )
70 {};
71
72 virtual ~EDIT_CONSTRAINT() {};
73
77 virtual void Apply( EDIT_TYPE& aHandle, const GRID_HELPER& aGrid ) = 0;
78
82 void Apply( const GRID_HELPER& aGrid )
83 {
84 Apply( m_constrained, aGrid );
85 }
86
87protected:
88 EDIT_TYPE& m_constrained;
89};
90
91
95class EC_VERTICAL : public EDIT_CONSTRAINT<EDIT_POINT>
96{
97public:
102 EC_VERTICAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
103 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
104 m_constrainer( aConstrainer )
105 {}
106
108 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
109
110private:
112};
113
114
118class EC_HORIZONTAL : public EDIT_CONSTRAINT<EDIT_POINT>
119{
120public:
125 EC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
126 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
127 m_constrainer( aConstrainer )
128 {}
129
131 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
132
133private:
135};
136
137
142class EC_45DEGREE : public EDIT_CONSTRAINT<EDIT_POINT>
143{
144public:
149 EC_45DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
150 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
151 m_constrainer( aConstrainer )
152 {}
153
155 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
156
157private:
159};
160
161
166class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
167{
168public:
169 EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer );
170
172 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
173
174private:
177};
178
179
183class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT>
184{
185public:
191 EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) :
192 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
193 m_center( aCenter ),
194 m_end( aEnd )
195 {}
196
198 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
199
200private:
203
206};
207
208
213class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE>
214{
215public:
216 EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints );
217
218 virtual ~EC_CONVERGING();
219
221 virtual void Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid ) override;
222
223private:
226
229
233
236
239
243};
244
245
250class EC_PERPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
251{
252public:
253
254 EC_PERPLINE( EDIT_LINE& aLine );
255
256 virtual ~EC_PERPLINE()
257 {}
258
260 virtual void Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid ) override;
261
262private:
265};
266
267#endif /* EDIT_CONSTRAINTS_H_ */
EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45 degree mu...
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
virtual void Apply(EDIT_POINT &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
EC_45DEGREE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
const EDIT_POINT & m_end
EC_CIRCLE(EDIT_POINT &aConstrained, const EDIT_POINT &aCenter, const EDIT_POINT &aEnd)
const EDIT_POINT & m_center
< Point that imposes the constraint (center of the circle).
virtual void Apply(EDIT_POINT &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes and all...
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Additional constraint, applied when at least two points are collinear.
virtual ~EC_CONVERGING()
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
EDIT_POINTS instance that stores currently modified lines.
VECTOR2I m_draggedVector
Flags to indicate when dragged and neighbouring lines are (almost) collinear.
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
< Constraint for origin side segment.
EDIT_POINTS & m_editPoints
Vector that represents the initial direction of the dragged segment.
virtual void Apply(EDIT_LINE &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
EC_HORIZONTAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
virtual void Apply(EDIT_POINT &aHandle, const GRID_HELPER &aGrid) override
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).
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
VECTOR2I m_line
Vector representing the constraining line.
virtual void Apply(EDIT_POINT &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
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.
virtual void Apply(EDIT_LINE &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
virtual void Apply(EDIT_POINT &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
EC_VERTICAL(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
Describe constraints between two edit handles.
void Apply(const GRID_HELPER &aGrid)
Correct coordinates of the constrained edit handle.
EDIT_TYPE & m_constrained
Point that is constrained by rules implemented by Apply().
EDIT_CONSTRAINT(EDIT_TYPE &aConstrained)
virtual void Apply(EDIT_TYPE &aHandle, const GRID_HELPER &aGrid)=0
Correct coordinates of the constrained edit handle.
virtual ~EDIT_CONSTRAINT()
Represent a line connecting two EDIT_POINTs.
Definition: edit_points.h:223
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
Definition: edit_points.h:330
Represent a single point that can be used for modifying items.
Definition: edit_points.h:48
SNAP_CONSTRAINT_TYPE
@ ALL_LAYERS
@ OBJECT_LAYERS
@ IGNORE_SNAPS
GRID_CONSTRAINT_TYPE
@ IGNORE_GRID
@ SNAP_BY_GRID
@ SNAP_TO_GRID