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 <class_draw_panel_gal.h>
27 #include <eda_base_frame.h>
28 #include <eda_draw_frame.h>
29 #include <tool/editor_conditions.h>
30 #include <tool/selection.h>
31 
32 #include <functional>
33 #include <wx/debug.h>
34 
35 using namespace std::placeholders;
36 
37 
39 {
40  return std::bind( &EDITOR_CONDITIONS::contentModifiedFunc, _1, m_frame );
41 }
42 
43 
45 {
46  return std::bind( &EDITOR_CONDITIONS::undoFunc, _1, m_frame );
47 }
48 
49 
51 {
52  return std::bind( &EDITOR_CONDITIONS::redoFunc, _1, m_frame );
53 }
54 
55 
57 {
58  return std::bind( &EDITOR_CONDITIONS::unitsFunc, _1, m_frame, aUnit );
59 }
60 
61 
63 {
64  return std::bind( &EDITOR_CONDITIONS::toolFunc, _1, m_frame, std::cref( aTool ) );
65 }
66 
67 
69 {
70  return std::bind( &EDITOR_CONDITIONS::noToolFunc, _1, m_frame );
71 }
72 
73 
75 {
76  // The grid visibility check requires a draw frame
77  EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
78 
79  wxASSERT( drwFrame );
80 
81  return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
82 }
83 
84 
86 {
87  // The polar coordinates require a draw frame
88  EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
89 
90  wxASSERT( drwFrame );
91 
92  return std::bind( &EDITOR_CONDITIONS::polarCoordFunc, _1, drwFrame );
93 }
94 
95 
97 {
98  // The fullscreen cursor requires a draw frame
99  EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
100 
101  wxASSERT( drwFrame );
102 
103  return std::bind( &EDITOR_CONDITIONS::cursorFunc, _1, drwFrame );
104 }
105 
106 
108 {
109  // The canvas type requires a draw frame
110  EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
111 
112  wxASSERT( drwFrame );
113 
114  return std::bind( &EDITOR_CONDITIONS::canvasTypeFunc, _1, drwFrame, aType );
115 }
116 
117 
119 {
120  return aFrame->IsContentModified();
121 }
122 
123 
124 bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
125 {
126  return aFrame->GetUndoCommandCount() > 0;
127 }
128 
129 
130 bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
131 {
132  return aFrame->GetRedoCommandCount() > 0;
133 }
134 
135 
136 bool EDITOR_CONDITIONS::unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
137  EDA_UNITS aUnits )
138 {
139  return aFrame->GetUserUnits() == aUnits;
140 }
141 
142 
143 bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
144  const TOOL_ACTION& aTool )
145 {
146  return aFrame->IsCurrentTool( aTool );
147 }
148 
149 
150 bool EDITOR_CONDITIONS::noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
151 {
152  return aFrame->ToolStackIsEmpty();
153 }
154 
155 
156 bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
157 {
158  return aFrame->IsGridVisible();
159 }
160 
161 
163 {
164  return aFrame->GetShowPolarCoords();
165 }
166 
167 
168 bool EDITOR_CONDITIONS::cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
169 {
170  return aFrame->GetGalDisplayOptions().m_fullscreenCursor;
171 }
172 
173 
176 {
177  return aFrame->GetCanvas()->GetBackend() == aType;
178 }
bool IsCurrentTool(const TOOL_ACTION &aAction) const
static bool canvasTypeFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame, EDA_DRAW_PANEL_GAL::GAL_TYPE aType)
Helper function used by CanvasType()
static bool unitsFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame, EDA_UNITS aUnits)
Helper function used by Units()
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
SELECTION_CONDITION FullscreenCursor()
Creates a functor testing if the cursor is full screen in a frame.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
static bool contentModifiedFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by ContentModified()
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Creates a functor testing if the specified tool is the current active tool in the frame.
virtual bool IsContentModified()
Get if the contents of the frame have been modified since the last save.
SELECTION_CONDITION CanvasType(EDA_DRAW_PANEL_GAL::GAL_TYPE aType)
Creates a functor testing if the specified canvas is active in the frame.
virtual int GetRedoCommandCount() const
SELECTION_CONDITION RedoAvailable()
Creates a functor that tests if there are any items in the redo queue.
The base class for create windows for drawing purpose.
static bool cursorFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by FullscreenCursor()
static bool polarCoordFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by PolarCoordinates()
static bool noToolFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by NoActiveTool()
SELECTION_CONDITION GridVisible()
Creates a functor testing if the grid is visible in a frame.
virtual int GetUndoCommandCount() const
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Creates a functor that tests if the frame has the specified units.
bool IsGridVisible() const
static bool undoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by UndoAvailable()
bool ToolStackIsEmpty()
Definition: tools_holder.h:136
Base window classes and related definitions.
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
SELECTION_CONDITION PolarCoordinates()
Creates a functor testing if polar coordinates are current being used.
SELECTION_CONDITION ContentModified()
Creates a functor that tests if the content of the frame is modified.
SELECTION_CONDITION NoActiveTool()
Creates a functor testing if there are no tools active in the frame.
static bool gridFunc(const SELECTION &aSelection, EDA_DRAW_FRAME *aFrame)
Helper function used by GridVisible()
static bool toolFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame, const TOOL_ACTION &aTool)
Helper function used by CurrentTool()
EDA_UNITS
Definition: eda_units.h:38
static bool redoFunc(const SELECTION &aSelection, EDA_BASE_FRAME *aFrame)
Helper function used by RedoAvailable()
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
SELECTION_CONDITION UndoAvailable()
Creates a functor that tests if there are any items in the undo queue.
The base frame for deriving all KiCad main window classes.
Represents a single user action.
Definition: tool_action.h:44
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
bool m_fullscreenCursor
Fullscreen crosshair or small cross
EDA_UNITS GetUserUnits() const
Return the user units currently in use.