KiCad PCB EDA Suite
Loading...
Searching...
No Matches
view_item.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) 2013-2016 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[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#pragma once
28
29#include <bitset>
30#include <vector>
31#include <limits>
32
33#include <gal/gal.h>
34#include <math/box2.h>
35#include <inspectable.h>
36
37#if defined( _MSC_VER )
38#pragma warning( push )
39#pragma warning( disable : 4275 )
40#endif
41
42namespace KIGFX
43{
44// Forward declarations
45class VIEW;
46class VIEW_ITEM_DATA;
47
52 NONE = 0x00,
53 APPEARANCE = 0x01,
54 COLOR = 0x02,
55 GEOMETRY = 0x04,
56 LAYERS = 0x08,
57 INITIAL_ADD = 0x10,
58 REPAINT = 0x20,
59 ALL = 0xef
60};
61
66 VISIBLE = 0x01,
67
70 HIDDEN = 0x02,
71 OVERLAY_HIDDEN = 0x04
72};
73
86{
87public:
88 VIEW_ITEM( bool isSCH_ITEM = false, bool isBOARD_ITEM = false ) :
89 m_isSCH_ITEM( isSCH_ITEM ),
90 m_isBOARD_ITEM( isBOARD_ITEM ),
91 m_viewPrivData( nullptr ),
92 m_forcedTransparency( 0.0 )
93 {
94 }
95
96 virtual ~VIEW_ITEM();
97
98 VIEW_ITEM( const VIEW_ITEM& aOther ) = delete;
99 VIEW_ITEM& operator=( const VIEW_ITEM& aOther ) = delete;
100
101 bool IsSCH_ITEM() const { return m_isSCH_ITEM; }
102 bool IsBOARD_ITEM() const { return m_isBOARD_ITEM; }
108 virtual const BOX2I ViewBBox() const = 0;
109
121 virtual void ViewDraw( int aLayer, VIEW* aView ) const
122 {}
123
131 virtual std::vector<int> ViewGetLayers() const = 0;
132
149 virtual double ViewGetLOD( int aLayer, const VIEW* aView ) const
150 {
151 // By default always show the item
152 return LOD_SHOW;
153 }
154
156 {
157 return m_viewPrivData;
158 }
159
160 void SetForcedTransparency( double aForcedTransparency )
161 {
162 m_forcedTransparency = aForcedTransparency;
163 }
164
166 {
167 return m_forcedTransparency;
168 }
169
170protected:
174 static constexpr double LOD_HIDE = std::numeric_limits<double>::max();
175
179 static constexpr double LOD_SHOW = 0.0;
180
196 static constexpr double lodScaleForThreshold( int aWhatIu, int aThresholdIu )
197 {
198 if( aWhatIu == 0 )
199 return LOD_HIDE;
200
201 return double( aThresholdIu ) / aWhatIu;
202 }
203
204private:
205 friend class VIEW;
206
211};
212
213} // namespace KIGFX
214
215#if defined( _MSC_VER )
216#pragma warning( pop )
217#endif
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
virtual const BOX2I ViewBBox() const =0
Return the bounding box of the item covering all its layers.
VIEW_ITEM(bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition: view_item.h:88
bool IsSCH_ITEM() const
Definition: view_item.h:101
double m_forcedTransparency
Additional transparency for diff'ing items.
Definition: view_item.h:210
VIEW_ITEM_DATA * viewPrivData() const
Definition: view_item.h:155
virtual void ViewDraw(int aLayer, VIEW *aView) const
Draw the parts of the object belonging to layer aLayer.
Definition: view_item.h:121
VIEW_ITEM & operator=(const VIEW_ITEM &aOther)=delete
void SetForcedTransparency(double aForcedTransparency)
Definition: view_item.h:160
virtual std::vector< int > ViewGetLayers() const =0
Return the all the layers within the VIEW the object is painted on.
bool IsBOARD_ITEM() const
Definition: view_item.h:102
VIEW_ITEM(const VIEW_ITEM &aOther)=delete
double GetForcedTransparency() const
Definition: view_item.h:165
virtual double ViewGetLOD(int aLayer, const VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:149
VIEW_ITEM_DATA * m_viewPrivData
Definition: view_item.h:209
static constexpr double lodScaleForThreshold(int aWhatIu, int aThresholdIu)
Get the scale at which aWhatIu would be drawn at the same size as aThresholdIu on screen.
Definition: view_item.h:196
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
#define GAL_API
Definition: gal.h:28
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
VIEW_UPDATE_FLAGS
Define the how severely the appearance of the item has been changed.
Definition: view_item.h:51
@ COLOR
Color has changed.
Definition: view_item.h:54
@ INITIAL_ADD
Item is being added to the view.
Definition: view_item.h:57
@ NONE
No updates are required.
Definition: view_item.h:52
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:58
@ APPEARANCE
Visibility flag has changed.
Definition: view_item.h:53
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:55
@ LAYERS
Layers have changed.
Definition: view_item.h:56
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:59
VIEW_VISIBILITY_FLAGS
Define the visibility of the item (temporarily hidden, invisible, etc).
Definition: view_item.h:65
@ HIDDEN
Item is temporarily hidden (usually in favor of a being drawn from an overlay, such as a SELECTION).
Definition: view_item.h:70
@ OVERLAY_HIDDEN
Item is temporarily hidden from being drawn on an overlay.
Definition: view_item.h:71
@ VISIBLE
Item is visible (in general)
Definition: view_item.h:66