KiCad PCB EDA Suite
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 <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 polar coordinates require 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::polarCoordFunc, _1, drwFrame );
95}
96
97
99{
100 // The fullscreen cursor requires 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::cursorFunc, _1, drwFrame );
106}
107
108
110{
111 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
112
113 wxASSERT( drwFrame );
114
115 return std::bind( &EDITOR_CONDITIONS::bboxesFunc, _1, drwFrame );
116}
117
118
120{
121 EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
122
123 wxASSERT( drwFrame );
124
125 return std::bind( &EDITOR_CONDITIONS::consoleVisibleFunc, _1, drwFrame );
126}
127
128
130{
131 return aFrame->IsContentModified();
132}
133
134
135bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
136{
137 return aFrame->GetUndoCommandCount() > 0;
138}
139
140
141bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
142{
143 return aFrame->GetRedoCommandCount() > 0;
144}
145
146
148 EDA_UNITS aUnits )
149{
150 return aFrame->GetUserUnits() == aUnits;
151}
152
153
154bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
155 const TOOL_ACTION& aTool )
156{
157 return aFrame->IsCurrentTool( aTool );
158}
159
160
162{
163 return aFrame->ToolStackIsEmpty();
164}
165
166
167bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
168{
169 return aFrame->IsGridVisible();
170}
171
172
174{
175 return aFrame->GetShowPolarCoords();
176}
177
178
180{
182}
183
184
186{
187 return aFrame->GetCanvas()->GetView()->GetPainter()->GetSettings()->GetDrawBoundingBoxes();
188}
189
190
192{
193 return aFrame->IsScriptingConsoleVisible();
194}
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.
KIGFX::GAL_DISPLAY_OPTIONS & 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 PolarCoordinates().
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
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 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 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:213
bool ToolStackIsEmpty()
Definition: tools_holder.h:128
bool IsCurrentTool(const TOOL_ACTION &aAction) const
Represent a single user action.
Definition: tool_action.h:68
EDA_UNITS GetUserUnits() const
Base window classes and related definitions.
EDA_UNITS
Definition: eda_units.h:43
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.