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.

211 lines
5.6 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. #include <view/view.h>
  25. #include <gal/painter.h>
  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. #include <functional>
  32. #include <wx/debug.h>
  33. using namespace std::placeholders;
  34. SELECTION_CONDITION EDITOR_CONDITIONS::ContentModified()
  35. {
  36. return std::bind( &EDITOR_CONDITIONS::contentModifiedFunc, _1, m_frame );
  37. }
  38. SELECTION_CONDITION EDITOR_CONDITIONS::UndoAvailable()
  39. {
  40. return std::bind( &EDITOR_CONDITIONS::undoFunc, _1, m_frame );
  41. }
  42. SELECTION_CONDITION EDITOR_CONDITIONS::RedoAvailable()
  43. {
  44. return std::bind( &EDITOR_CONDITIONS::redoFunc, _1, m_frame );
  45. }
  46. SELECTION_CONDITION EDITOR_CONDITIONS::Units( EDA_UNITS aUnit )
  47. {
  48. return std::bind( &EDITOR_CONDITIONS::unitsFunc, _1, m_frame, aUnit );
  49. }
  50. SELECTION_CONDITION EDITOR_CONDITIONS::CurrentTool( const TOOL_ACTION& aTool )
  51. {
  52. return std::bind( &EDITOR_CONDITIONS::toolFunc, _1, m_frame, std::cref( aTool ) );
  53. }
  54. SELECTION_CONDITION EDITOR_CONDITIONS::NoActiveTool()
  55. {
  56. return std::bind( &EDITOR_CONDITIONS::noToolFunc, _1, m_frame );
  57. }
  58. SELECTION_CONDITION EDITOR_CONDITIONS::GridVisible()
  59. {
  60. // The grid visibility check requires a draw frame
  61. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  62. wxASSERT( drwFrame );
  63. return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
  64. }
  65. SELECTION_CONDITION EDITOR_CONDITIONS::GridOverrides()
  66. {
  67. // The grid lock check requires a draw frame
  68. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  69. wxASSERT( drwFrame );
  70. return std::bind( &EDITOR_CONDITIONS::gridOverridesFunc, _1, drwFrame );
  71. }
  72. SELECTION_CONDITION EDITOR_CONDITIONS::PolarCoordinates()
  73. {
  74. // The polar coordinates require a draw frame
  75. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  76. wxASSERT( drwFrame );
  77. return std::bind( &EDITOR_CONDITIONS::polarCoordFunc, _1, drwFrame );
  78. }
  79. SELECTION_CONDITION EDITOR_CONDITIONS::FullscreenCursor()
  80. {
  81. // The fullscreen cursor requires a draw frame
  82. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  83. wxASSERT( drwFrame );
  84. return std::bind( &EDITOR_CONDITIONS::cursorFunc, _1, drwFrame );
  85. }
  86. SELECTION_CONDITION EDITOR_CONDITIONS::BoundingBoxes()
  87. {
  88. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  89. wxASSERT( drwFrame );
  90. return std::bind( &EDITOR_CONDITIONS::bboxesFunc, _1, drwFrame );
  91. }
  92. SELECTION_CONDITION EDITOR_CONDITIONS::ScriptingConsoleVisible()
  93. {
  94. EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
  95. wxASSERT( drwFrame );
  96. return std::bind( &EDITOR_CONDITIONS::consoleVisibleFunc, _1, drwFrame );
  97. }
  98. bool EDITOR_CONDITIONS::contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
  99. {
  100. return aFrame->IsContentModified();
  101. }
  102. bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
  103. {
  104. return aFrame->GetUndoCommandCount() > 0;
  105. }
  106. bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
  107. {
  108. return aFrame->GetRedoCommandCount() > 0;
  109. }
  110. bool EDITOR_CONDITIONS::unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
  111. EDA_UNITS aUnits )
  112. {
  113. return aFrame->GetUserUnits() == aUnits;
  114. }
  115. bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
  116. const TOOL_ACTION& aTool )
  117. {
  118. return aFrame->IsCurrentTool( aTool );
  119. }
  120. bool EDITOR_CONDITIONS::noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
  121. {
  122. return aFrame->ToolStackIsEmpty();
  123. }
  124. bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  125. {
  126. return aFrame->IsGridVisible();
  127. }
  128. bool EDITOR_CONDITIONS::gridOverridesFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  129. {
  130. return aFrame->IsGridOverridden();
  131. }
  132. bool EDITOR_CONDITIONS::polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  133. {
  134. return aFrame->GetShowPolarCoords();
  135. }
  136. bool EDITOR_CONDITIONS::cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  137. {
  138. return aFrame->GetGalDisplayOptions().m_fullscreenCursor;
  139. }
  140. bool EDITOR_CONDITIONS::bboxesFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  141. {
  142. return aFrame->GetCanvas()->GetView()->GetPainter()->GetSettings()->GetDrawBoundingBoxes();
  143. }
  144. bool EDITOR_CONDITIONS::consoleVisibleFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
  145. {
  146. return aFrame->IsScriptingConsoleVisible();
  147. }