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 The 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
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_90DEGREE : public EDIT_CONSTRAINT<EDIT_POINT>
167{
168public:
173 EC_90DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
174 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
175 m_constrainer( aConstrainer )
176 {};
177
179 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
180
181private:
183};
184
189class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
190{
191public:
192 EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer );
193
195 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
196
197private:
200};
201
202
206class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT>
207{
208public:
214 EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) :
215 EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ),
216 m_center( aCenter ),
217 m_end( aEnd )
218 {}
219
221 virtual void Apply( EDIT_POINT& aHandle, const GRID_HELPER& aGrid ) override;
222
223private:
226
229};
230
231
236class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE>
237{
238public:
239 EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints );
240
241 virtual ~EC_CONVERGING();
242
244 virtual void Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid ) override;
245
246private:
248 std::unique_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_originSideConstraint;
249
251 std::unique_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_endSideConstraint;
252
256
259
262
266
270
273
276};
277
278
283class EC_PERPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
284{
285public:
286
287 EC_PERPLINE( EDIT_LINE& aLine );
288
289 virtual ~EC_PERPLINE()
290 {}
291
293 virtual void Apply( EDIT_LINE& aHandle, const GRID_HELPER& aGrid ) override;
294
295private:
298};
299
300#endif /* EDIT_CONSTRAINTS_H_ */
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)
EC_90DEGREE(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.
const EDIT_POINT & m_end
Point that imposes the constraint (decides on the radius of the circle).
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.
std::unique_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_endSideConstraint
Constraint for end side segment.
EC_CONVERGING(EDIT_LINE &aLine, EDIT_POINTS &aPoints)
std::unique_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_originSideConstraint
Constraint for origin side segment.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
Additional constraint, applied when at least two points are collinear.
VECTOR2I m_midVector
Vector from the convergence point to the mid-line point.
VECTOR2I m_draggedVector
Vector that represents the initial direction of the dragged segment.
EDIT_POINT * m_nextEnd
EDIT_POINT * m_prevOrigin
Previous and next points to keep drag endpoints fixed.
bool m_originCollinear
Flags to indicate when dragged and neighbouring lines are (almost) collinear.
EDIT_POINTS & m_editPoints
EDIT_POINTS instance that stores currently modified lines.
virtual void Apply(EDIT_LINE &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
VECTOR2I m_convergencePoint
Original convergence point of adjacent segments.
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.
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.
EC_LINE(EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
virtual ~EC_PERPLINE()
EC_PERPLINE(EDIT_LINE &aLine)
virtual void Apply(EDIT_LINE &aHandle, const GRID_HELPER &aGrid) override
Correct coordinates of the constrained edit handle.
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.
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.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695