1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017-2021 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_RULER_ITEM_H
25 #define PREVIEW_ITEMS_RULER_ITEM_H
26 
27 #include <eda_item.h>
28 #include <preview_items/two_point_geom_manager.h>
29 
30 namespace KIGFX
31 {
32 class GAL;
33 
34 namespace PREVIEW
35 {
36 class TWO_POINT_GEOMETRY_MANAGER;
37 
38 /**
39  * A drawn ruler item for showing the distance between two points.
40  */
41 class RULER_ITEM : public EDA_ITEM
42 {
43 public:
44     RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& m_geomMgr, EDA_UNITS userUnits, bool aFlipX,
45             bool aFlipY );
46 
47     ///< @copydoc EDA_ITEM::ViewBBox()
48     const BOX2I ViewBBox() const override;
49 
50     ///< @copydoc EDA_ITEM::ViewGetLayers()
51     void ViewGetLayers( int aLayers[], int& aCount ) const override;
52 
53     ///< @copydoc EDA_ITEM::ViewDraw();
54     void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override final;
55 
56 
57 #if defined(DEBUG)
Show(int x,std::ostream & st)58     void Show( int x, std::ostream& st ) const override
59     {
60     }
61 #endif
62 
63     /**
64      * Get class name
65      * @return  string "RULER_ITEM"
66      */
GetClass()67     wxString GetClass() const override
68     {
69         return wxT( "RULER_ITEM" );
70     }
71 
72     /**
73      * Switch the ruler units
74      *
75      * @param aUnits is the new unit system the ruler should use
76      */
SwitchUnits(EDA_UNITS aUnits)77     void SwitchUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }
78 
UpdateDir(bool aFlipX,bool aFlipY)79     void UpdateDir( bool aFlipX, bool aFlipY )
80     {
81         m_flipX = aFlipX;
82         m_flipY = aFlipY;
83     }
84 
85 private:
86     const TWO_POINT_GEOMETRY_MANAGER& m_geomMgr;
87     EDA_UNITS                         m_userUnits;
88     bool                              m_flipX;
89     bool                              m_flipY;
90 };
91 
92 } // PREVIEW
93 } // KIGFX
94 
95 #endif // PREVIEW_ITEMS_RULER_ITEM_H
96