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>
28 #include <common.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  }
52 
54  {
55  return m_origin;
56  }
57 
62  void SetEnd( const VECTOR2I& aEnd )
63  {
64  if( m_angleSnap )
65  {
66  const auto vec = aEnd - m_origin;
67  const auto len = vec.EuclideanNorm();
68  const auto angle = KiROUND( vec.Angle() / M_PI_4 ) * M_PI_4;
69 
70  m_end = m_origin + VECTOR2I( len, 0 ).Rotate( angle );
71  }
72  else
73  {
74  m_end = aEnd;
75  }
76  }
77 
78  VECTOR2I GetEnd() const
79  {
80  return m_end;
81  }
82 
83  void SetAngleSnap( bool aSnap )
84  {
85  m_angleSnap = aSnap;
86  }
87 
88 private:
89 
91  bool m_angleSnap = false;
92 };
93 
94 } // PREVIEW
95 } // KIGFX
96 
97 #endif // PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
Class TWO_POINT_GEOMETRY_MANAGER.
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:372
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:294
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the ruler (the fixed end)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
The common library.
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.