KiCad PCB EDA Suite
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 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 
30 namespace KIGFX
31 {
32 class GAL;
33 
34 namespace PREVIEW
35 {
36 
44 {
45 public:
46 
48  void SetOrigin( const VECTOR2I& aOrigin )
49  {
50  m_origin = aOrigin;
51  m_originSet = true;
53  }
54 
56  {
57  return m_origin;
58  }
59 
64  void SetEnd( const VECTOR2I& aEnd )
65  {
66  if( m_angleSnap )
67  {
69  }
70  else
71  {
72  m_end = aEnd;
73  }
75  }
76 
77  VECTOR2I GetEnd() const
78  {
79  return m_end;
80  }
81 
82  void SetAngleSnap( bool aSnap )
83  {
84  m_angleSnap = aSnap;
85  }
86 
87  bool GetAngleSnap() const
88  {
89  return m_angleSnap;
90  }
91 
95  bool IsReset() const
96  {
97  return !m_originSet;
98  }
99 
103  void Reset()
104  {
105  m_originSet = false;
107  }
108 
113  bool HasGeometryChanged() const
114  {
115  return m_changed;
116  }
117 
123  {
124  m_changed = false;
125  }
126 
127 protected:
130  {
131  m_changed = true;
132  }
133 
134 private:
135 
137  bool m_angleSnap = false;
138 
140  bool m_changed = false;
141  bool m_originSet = false;
142 };
143 
144 } // PREVIEW
145 } // KIGFX
146 
147 #endif // PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
bool m_changed
Has the gemotry changed such that a client should redraw?
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
void Reset()
Reset the manager to the initial state.
void ClearGeometryChanged()
Clear the geometry changed flag, call after the client code has updated everything as needed.
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the ruler (the fixed end)
a few functions useful in geometry calculations.
void setGeometryChanged()
Mark the geometry as changed for clients to notice
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.