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 (C) 1992-2020 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>
32#include <tool/selection.h>
33
34#include <functional>
35#include <wx/debug.h>
36
37using namespace std::placeholders;
38
39
41{
42 return std::bind( &EDITOR_CONDITIONS::contentModifiedFunc, _1, m_frame );
43}
44
45
47{
48 return std::bind( &EDITOR_CONDITIONS::undoFunc, _1, m_frame );
49}
50
51
53{
54 return std::bind( &EDITOR_CONDITIONS::redoFunc, _1, m_frame );
55}
56
57
59{
60 return std::bind( &EDITOR_CONDITIONS::unitsFunc, _1, m_frame, aUnit );
61}
62
63
65{
66 return std::bind( &EDITOR_CONDITIONS::toolFunc, _1, m_frame, std::cref( aTool ) );
67}
68
69
71{
72 return std::bind( &EDITOR_CONDITIONS::noToolFunc, _1, m_frame );
73}
74
75
77{
78 // The grid visibility check requires a draw frame
79 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
80
81 wxASSERT( drwFrame );
82
83 return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
84}
85
86
88{
89 // The grid lock check requires a draw frame
90 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
91
92 wxASSERT( drwFrame );
93
94 return std::bind( &EDITOR_CONDITIONS::gridOverridesFunc, _1, drwFrame );
95}
96
97
99{
100 // The polar coordinates require a draw frame
101 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
102
103 wxASSERT( drwFrame );
104
105 return std::bind( &EDITOR_CONDITIONS::polarCoordFunc, _1, drwFrame );
106}
107
108
110{
111 // The fullscreen cursor requires a draw frame
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 );
117}
118
119
121{
122 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
123
124 wxASSERT( drwFrame );
125
126 return std::bind( &EDITOR_CONDITIONS::bboxesFunc, _1, drwFrame );
127}
128
129
131{
132 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
133
134 wxASSERT( drwFrame );
135
136 return std::bind( &EDITOR_CONDITIONS::consoleVisibleFunc, _1, drwFrame );
137}
138
139
141{
142 return aFrame->IsContentModified();
143}
144
145
146bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
147{
148 return aFrame->GetUndoCommandCount() > 0;
149}
150
151
152bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
153{
154 return aFrame->GetRedoCommandCount() > 0;
155}
156
157
159 EDA_UNITS aUnits )
160{
161 return aFrame->GetUserUnits() == aUnits;
162}
163
164
165bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
166 const TOOL_ACTION& aTool )
167{
168 return aFrame->IsCurrentTool( aTool );
169}
170
171
173{
174 return aFrame->ToolStackIsEmpty();
175}
176
177
178bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
179{
180 return aFrame->IsGridVisible();
181}
182
183
185{
186 return aFrame->IsGridOverridden();
187}
188
189
191{
192 return aFrame->GetShowPolarCoords();
193}
194
195
197{
199}
200
201
203{
204 return aFrame->GetCanvas()->GetView()->GetPainter()->GetSettings()->GetDrawBoundingBoxes();
205}
206
207
209{
210 return aFrame->IsScriptingConsoleVisible();
211}
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()
Gets 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 GridVisible().
static bool cursorFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by DrawBoundingBoxes().
SELECTION_CONDITION BoundingBoxes()
static bool polarCoordFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by FullscreenCursor().
static bool consoleVisibleFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
The frame to apply the conditions to.
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
EDA_BASE_FRAME * m_frame
static bool gridFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by GridOverrides().
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 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.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
static bool toolFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame, const TOOL_ACTION &aTool)
Helper function used by NoActiveTool().
static bool undoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by RedoAvailable().
static bool redoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by Units().
static bool gridOverridesFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by PolarCoordinates().
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 CurrentTool().
static bool bboxesFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by ScriptingConsoleVisible().
bool m_fullscreenCursor
Force cursor display.
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:217
bool ToolStackIsEmpty()
Definition: tools_holder.h:125
bool IsCurrentTool(const TOOL_ACTION &aAction) const
Represent a single user action.
Definition: tool_action.h:269
EDA_UNITS GetUserUnits() const
Base window classes and related definitions.
EDA_UNITS
Definition: eda_units.h:46
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.