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.

153 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  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 __PCB_TOOL_H
  25. #define __PCB_TOOL_H
  26. #include <string>
  27. #include <tool/tool_event.h>
  28. #include <tool/tool_interactive.h>
  29. #include <pcb_edit_frame.h>
  30. #include <class_board.h>
  31. #include <view/view_group.h>
  32. #include <pcb_view.h>
  33. #include <pcb_draw_panel_gal.h>
  34. #include <functional>
  35. #include <tool/tool_menu.h>
  36. /**
  37. * Class PCB_TOOL
  38. *
  39. * A tool operating on a BOARD object
  40. **/
  41. class PCB_TOOL;
  42. class PCB_EDIT_FRAME;
  43. class PCB_DISPLAY_OPTIONS;
  44. class SELECTION;
  45. struct INTERACTIVE_PLACER_BASE
  46. {
  47. virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
  48. virtual void SnapItem( BOARD_ITEM *aItem );
  49. virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
  50. PCB_EDIT_FRAME* m_frame;
  51. BOARD* m_board;
  52. int m_modifiers;
  53. };
  54. class PCB_TOOL : public TOOL_INTERACTIVE
  55. {
  56. public:
  57. /**
  58. * Constructor
  59. *
  60. * Creates a tool with given id & name. The name must be unique. */
  61. PCB_TOOL( TOOL_ID aId, const std::string& aName ) :
  62. TOOL_INTERACTIVE ( aId, aName ),
  63. m_menu( *this ),
  64. m_editModules( false ) {};
  65. /**
  66. * Constructor
  67. *
  68. * Creates a tool with given name. The name must be unique. */
  69. PCB_TOOL( const std::string& aName ) :
  70. TOOL_INTERACTIVE ( aName ),
  71. m_menu( *this ),
  72. m_editModules( false ) {};
  73. virtual ~PCB_TOOL() {};
  74. virtual bool Init() override;
  75. virtual void Reset( RESET_REASON aReason ) override;
  76. /**
  77. * Function SetEditModules()
  78. *
  79. * Toggles edit module mode. When enabled, one may select parts of modules individually
  80. * (graphics, pads, etc.), so they can be modified.
  81. * @param aEnabled decides if the mode should be enabled.
  82. */
  83. void SetEditModules( bool aEnabled )
  84. {
  85. m_editModules = aEnabled;
  86. }
  87. bool EditingModules() const
  88. {
  89. return m_editModules;
  90. }
  91. protected:
  92. enum INTERACTIVE_PLACEMENT_OPTIONS {
  93. IPO_ROTATE = 1,
  94. IPO_FLIP = 2,
  95. IPO_PROPERTIES = 4,
  96. IPO_SINGLE_CLICK = 8,
  97. IPO_REPEAT = 16
  98. };
  99. /**
  100. * Helper function for performing a common interactive idiom:
  101. * wait for a left click, place an item there (perhaps with a
  102. * dialog or other user interaction), then have it move with
  103. * the mouse and respond to rotate/flip, etc
  104. *
  105. * More complex interactive processes are not supported here, you
  106. * should implement a customised event loop for those.
  107. *
  108. * @param aItemCreator the callable that will attempt to create the item
  109. * @param aCommitMessage the message used on a successful commit
  110. */
  111. void doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE *aPlacer,
  112. const wxString& aCommitMessage,
  113. int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
  114. virtual void setTransitions() override;
  115. KIGFX::PCB_VIEW* view() const { return static_cast<KIGFX::PCB_VIEW*>( getView() ); }
  116. KIGFX::VIEW_CONTROLS* controls() const { return getViewControls(); }
  117. PCB_EDIT_FRAME* frame() const { return getEditFrame<PCB_EDIT_FRAME>(); }
  118. BOARD* board() const { return getModel<BOARD>(); }
  119. MODULE* module() const { return board()->m_Modules; }
  120. PCB_DISPLAY_OPTIONS* displayOptions() const;
  121. PCB_DRAW_PANEL_GAL* canvas() const;
  122. const SELECTION& selection() const;
  123. SELECTION& selection();
  124. /// Menu model displayed by the tool.
  125. TOOL_MENU m_menu;
  126. bool m_editModules;
  127. };
  128. #endif