KiCad PCB EDA Suite
Loading...
Searching...
No Matches
editor_conditions.cpp
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) 2020 Ian McInerney <ian.s.mcinerney at ieee.org>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <view/view.h>
27#include <gal/painter.h>
29#include <eda_base_frame.h>
30#include <eda_draw_frame.h>
33#include <tool/selection.h>
34
35#include <functional>
36#include <wx/debug.h>
37
38using namespace std::placeholders;
39
40
45
46
51
52
57
58
63
64
66{
67 return std::bind( &EDITOR_CONDITIONS::toolFunc, _1, m_frame, std::cref( aTool ) );
68}
69
70
75
76
78{
79 // The grid visibility check requires a draw frame
80 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
81
82 wxASSERT( drwFrame );
83
84 return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
85}
86
87
89{
90 // The grid lock check requires a draw frame
91 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
92
93 wxASSERT( drwFrame );
94
95 return std::bind( &EDITOR_CONDITIONS::gridOverridesFunc, _1, drwFrame );
96}
97
98
100{
101 // The polar coordinates require a draw frame
102 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
103
104 wxASSERT( drwFrame );
105
106 return std::bind( &EDITOR_CONDITIONS::polarCoordFunc, _1, drwFrame );
107}
108
109
111{
112 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
113
114 wxASSERT( drwFrame );
115
116 return std::bind( &EDITOR_CONDITIONS::cursorFunc, _1, drwFrame,
118}
119
120
122{
123 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
124
125 wxASSERT( drwFrame );
126
127 return std::bind( &EDITOR_CONDITIONS::cursorFunc, _1, drwFrame,
129}
130
131
133{
134 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
135
136 wxASSERT( drwFrame );
137
138 return std::bind( &EDITOR_CONDITIONS::cursorFunc, _1, drwFrame,
140}
141
142
144{
145 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
146
147 wxASSERT( drwFrame );
148
149 return std::bind( &EDITOR_CONDITIONS::bboxesFunc, _1, drwFrame );
150}
151
152
154{
155 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
156
157 wxASSERT( drwFrame );
158
159 return std::bind( &EDITOR_CONDITIONS::consoleVisibleFunc, _1, drwFrame );
160}
161
162
164{
165 return aFrame->IsContentModified();
166}
167
168
169bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
170{
171 return aFrame->GetUndoCommandCount() > 0;
172}
173
174
175bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
176{
177 return aFrame->GetRedoCommandCount() > 0;
178}
179
180
182 EDA_UNITS aUnits )
183{
184 return aFrame->GetUserUnits() == aUnits;
185}
186
187
188bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
189 const TOOL_ACTION& aTool )
190{
191 return aFrame->IsCurrentTool( aTool );
192}
193
194
196{
197 return aFrame->ToolStackIsEmpty();
198}
199
200
201bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
202{
203 return aFrame->IsGridVisible();
204}
205
206
208{
209 return aFrame->IsGridOverridden();
210}
211
212
214{
215 return aFrame->GetShowPolarCoords();
216}
217
218
221{
222 return aFrame->GetGalDisplayOptions().GetCursorMode() == aMode;
223}
224
225
227{
228 return aFrame->GetCanvas()->GetView()->GetPainter()->GetSettings()->GetDrawBoundingBoxes();
229}
230
231
233{
234 return aFrame->IsScriptingConsoleVisible();
235}
The base frame for deriving all KiCad main window classes.
virtual int GetRedoCommandCount() const
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
virtual int GetUndoCommandCount() const
The base class for create windows for drawing purpose.
bool IsScriptingConsoleVisible()
Get the current visibility of the scripting console window.
bool IsGridOverridden() const
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
bool IsGridVisible() const
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
static bool noToolFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by NoActiveTool().
static bool cursorFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame, KIGFX::CROSS_HAIR_MODE aMode)
Helper function used by FullscreenCursor().
SELECTION_CONDITION BoundingBoxes()
static bool polarCoordFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by PolarCoordinates().
static bool consoleVisibleFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by ScriptingConsoleVisible().
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
EDA_BASE_FRAME * m_frame
The frame to apply the conditions to.
static bool gridFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by GridVisible().
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
virtual SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
SELECTION_CONDITION ScriptingConsoleVisible()
Create a functor testing if the python scripting console window is visible.
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
SELECTION_CONDITION CursorSmallCrosshairs()
Create a functor testing if the cursor is full screen in a frame.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION ContentModified()
Create a functor that tests if the content of the frame is modified.
SELECTION_CONDITION PolarCoordinates()
Create a functor testing if polar coordinates are current being used.
SELECTION_CONDITION GridOverrides()
Create a functor testing if the grid overrides wires is enabled in a frame.
static bool toolFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame, const TOOL_ACTION &aTool)
Helper function used by CurrentTool().
static bool undoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by UndoAvailable().
SELECTION_CONDITION Cursor45Crosshairs()
static bool redoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by RedoAvailable().
static bool gridOverridesFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by GridOverrides().
static bool contentModifiedFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by ContentModified().
static bool unitsFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame, EDA_UNITS aUnits)
Helper function used by Units().
SELECTION_CONDITION CursorFullCrosshairs()
static bool bboxesFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by DrawBoundingBoxes().
CROSS_HAIR_MODE GetCursorMode() const
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
bool GetDrawBoundingBoxes() const
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:220
bool ToolStackIsEmpty()
bool IsCurrentTool(const TOOL_ACTION &aAction) const
Represent a single user action.
EDA_UNITS GetUserUnits() const
Base window classes and related definitions.
EDA_UNITS
Definition eda_units.h:48
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.