kicad/include/tool/editor_conditions.h

172 lines
5.9 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney at ieee.org>
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef EDITOR_CONDITIONS_H_
#define EDITOR_CONDITIONS_H_
#include <class_draw_panel_gal.h>
#include <functional>
#include <tool/selection.h>
#include <tool/selection_conditions.h>
class EDA_BASE_FRAME;
class EDA_DRAW_FRAME;
class TOOL_ACTION;
2020-12-27 00:41:04 +00:00
/**
* Class that groups generic conditions for editor states.
*/
class EDITOR_CONDITIONS : public SELECTION_CONDITIONS
{
public:
/**
* Create an object to define conditions dependent upon a specific frame.
*
* @param aFrame is the frame to query for the conditions
*/
EDITOR_CONDITIONS( EDA_BASE_FRAME* aFrame ) :
m_frame( aFrame )
{}
/**
2020-12-27 00:41:04 +00:00
* Create a functor that tests if the content of the frame is modified.
*
2020-12-27 00:41:04 +00:00
* @return Functor testing for modified content.
*/
SELECTION_CONDITION ContentModified();
/**
2020-12-27 00:41:04 +00:00
* Create a functor that tests if there are any items in the undo queue.
*
* @return Functor testing if the undo queue has items.
*/
virtual SELECTION_CONDITION UndoAvailable();
/**
2020-12-27 00:41:04 +00:00
* Create a functor that tests if there are any items in the redo queue.
*
* @return Functor testing if the redo queue has items.
*/
SELECTION_CONDITION RedoAvailable();
/**
2020-12-27 00:41:04 +00:00
* Create a functor that tests if the frame has the specified units.
*
* @return Functor testing the units of a frame.
*/
SELECTION_CONDITION Units( EDA_UNITS aUnit );
/**
2020-12-27 00:41:04 +00:00
* Create a functor testing if the specified tool is the current active tool in the frame.
*
2020-12-27 00:41:04 +00:00
* @return Functor testing the current tool of a frame.
*/
SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool );
/**
2020-12-27 00:41:04 +00:00
* Create a functor testing if there are no tools active in the frame.
*
2020-12-27 00:41:04 +00:00
* @return Functor testing the frame has no tools running.
*/
SELECTION_CONDITION NoActiveTool();
/**
2020-12-27 00:41:04 +00:00
* Create a functor testing if the grid is visible in a frame.
*
2020-12-27 00:41:04 +00:00
* @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the grid is visible
*/
SELECTION_CONDITION GridVisible();
/**
2020-12-27 00:41:04 +00:00
* Create a functor testing if polar coordinates are current being used.
*
2020-12-27 00:41:04 +00:00
* @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the grid is visible
*/
SELECTION_CONDITION PolarCoordinates();
/**
2020-12-27 00:41:04 +00:00
* Create a functor testing if the cursor is full screen in a frame.
*
2020-12-27 00:41:04 +00:00
* @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the cursor is full screen
*/
SELECTION_CONDITION FullscreenCursor();
SELECTION_CONDITION BoundingBoxes();
/**
* Create a functor testing if the python scripting console window is visible.
*
* @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the python scripting console window is visible
*/
SELECTION_CONDITION ScriptingConsoleVisible();
protected:
2020-12-27 00:41:04 +00:00
///< Helper function used by ContentModified().
static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by UndoAvailable().
static bool undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by RedoAvailable().
static bool redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by Units().
static bool unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, EDA_UNITS aUnits );
2020-12-27 00:41:04 +00:00
///< Helper function used by CurrentTool().
static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
const TOOL_ACTION& aTool );
2020-12-27 00:41:04 +00:00
///< Helper function used by NoActiveTool().
static bool noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by GridVisible().
static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by PolarCoordinates().
static bool polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< Helper function used by FullscreenCursor().
static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///< Helper function used by DrawBoundingBoxes().
static bool bboxesFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///< Helper function used by ScriptingConsoleVisible().
static bool consoleVisibleFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
2020-12-27 00:41:04 +00:00
///< The frame to apply the conditions to.
EDA_BASE_FRAME* m_frame;
};
#endif /* EDITOR_CONDITIONS_H_ */