You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.7 KiB

  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. #ifndef EDITOR_CONDITIONS_H_
  25. #define EDITOR_CONDITIONS_H_
  26. #include <class_draw_panel_gal.h>
  27. #include <functional>
  28. #include <tool/selection.h>
  29. #include <tool/selection_conditions.h>
  30. class EDA_BASE_FRAME;
  31. class EDA_DRAW_FRAME;
  32. class TOOL_ACTION;
  33. /**
  34. * Class that groups generic conditions for editor states.
  35. */
  36. class EDITOR_CONDITIONS : public SELECTION_CONDITIONS
  37. {
  38. public:
  39. /**
  40. * Create an object to define conditions dependent upon a specific frame.
  41. *
  42. * @param aFrame is the frame to query for the conditions
  43. */
  44. EDITOR_CONDITIONS( EDA_BASE_FRAME* aFrame ) :
  45. m_frame( aFrame )
  46. {}
  47. /**
  48. * Create a functor that tests if the content of the frame is modified.
  49. *
  50. * @return Functor testing for modified content.
  51. */
  52. SELECTION_CONDITION ContentModified();
  53. /**
  54. * Create a functor that tests if there are any items in the undo queue.
  55. *
  56. * @return Functor testing if the undo queue has items.
  57. */
  58. SELECTION_CONDITION UndoAvailable();
  59. /**
  60. * Create a functor that tests if there are any items in the redo queue.
  61. *
  62. * @return Functor testing if the redo queue has items.
  63. */
  64. SELECTION_CONDITION RedoAvailable();
  65. /**
  66. * Create a functor that tests if the frame has the specified units.
  67. *
  68. * @return Functor testing the units of a frame.
  69. */
  70. SELECTION_CONDITION Units( EDA_UNITS aUnit );
  71. /**
  72. * Create a functor testing if the specified tool is the current active tool in the frame.
  73. *
  74. * @return Functor testing the current tool of a frame.
  75. */
  76. SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool );
  77. /**
  78. * Create a functor testing if there are no tools active in the frame.
  79. *
  80. * @return Functor testing the frame has no tools running.
  81. */
  82. SELECTION_CONDITION NoActiveTool();
  83. /**
  84. * Create a functor testing if the grid is visible in a frame.
  85. *
  86. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
  87. *
  88. * @return Functor testing if the grid is visible
  89. */
  90. SELECTION_CONDITION GridVisible();
  91. /**
  92. * Create a functor testing if polar coordinates are current being used.
  93. *
  94. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
  95. *
  96. * @return Functor testing if the grid is visible
  97. */
  98. SELECTION_CONDITION PolarCoordinates();
  99. /**
  100. * Create a functor testing if the cursor is full screen in a frame.
  101. *
  102. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
  103. *
  104. * @return Functor testing if the cursor is full screen
  105. */
  106. SELECTION_CONDITION FullscreenCursor();
  107. /**
  108. * Create a functor testing if the python scripting console window is visible.
  109. *
  110. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
  111. *
  112. * @return Functor testing if the python scripting console window is visible
  113. */
  114. SELECTION_CONDITION ScriptingConsoleVisible();
  115. protected:
  116. ///< Helper function used by ContentModified().
  117. static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
  118. ///< Helper function used by UndoAvailable().
  119. static bool undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
  120. ///< Helper function used by RedoAvailable().
  121. static bool redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
  122. ///< Helper function used by Units().
  123. static bool unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, EDA_UNITS aUnits );
  124. ///< Helper function used by CurrentTool().
  125. static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
  126. const TOOL_ACTION& aTool );
  127. ///< Helper function used by NoActiveTool().
  128. static bool noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
  129. ///< Helper function used by GridVisible().
  130. static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
  131. ///< Helper function used by PolarCoordinates().
  132. static bool polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
  133. ///< Helper function used by FullscreenCursor().
  134. static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
  135. ///< Helper function used by ScriptingConsoleVisible().
  136. static bool consoleVisibleFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
  137. ///< The frame to apply the conditions to.
  138. EDA_BASE_FRAME* m_frame;
  139. };
  140. #endif /* EDITOR_CONDITIONS_H_ */