KiCad PCB EDA Suite
Loading...
Searching...
No Matches
two_point_geom_manager.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) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
25#define PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
26
27#include <math/vector2d.h>
29
30namespace KIGFX
31{
32class GAL;
33
34namespace PREVIEW
35{
36
41{
42public:
43
45 void SetOrigin( const VECTOR2I& aOrigin )
46 {
47 m_origin = aOrigin;
48 m_originSet = true;
49 }
50
52 {
53 return m_origin;
54 }
55
59 void SetEnd( const VECTOR2I& aEnd )
60 {
61 if( m_angleSnap )
63 else
64 m_end = aEnd;
65 }
66
68 {
69 return m_end;
70 }
71
72 void SetAngleSnap( bool aSnap )
73 {
74 m_angleSnap = aSnap;
75 }
76
77 bool GetAngleSnap() const
78 {
79 return m_angleSnap;
80 }
81
85 bool IsReset() const
86 {
87 return !m_originSet;
88 }
89
93 void Reset()
94 {
95 m_originSet = false;
96 }
97
98 bool IsEmpty() const
99 {
100 return !m_originSet || m_origin == m_end;
101 }
102
103private:
104
107 bool m_angleSnap = false;
108 bool m_originSet = false;
109};
110
111} // PREVIEW
112} // KIGFX
113
114#endif // PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
Represent a very simple geometry manager for items that have a start and end point.
void SetOrigin(const VECTOR2I &aOrigin)
< Set the origin of the ruler (the fixed end)
void Reset()
Reset the manager to the initial state.
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.
a few functions useful in geometry calculations.
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247