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.

159 lines
5.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * @author Maciej Suminski <maciej.suminski@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_EDITOR_CONTROL_H
  25. #define PCB_EDITOR_CONTROL_H
  26. #include <tools/pcb_tool.h>
  27. #include <tool/tool_menu.h>
  28. namespace KIGFX {
  29. class ORIGIN_VIEWITEM;
  30. }
  31. class PCB_EDIT_FRAME;
  32. /**
  33. * Class PCB_EDITOR_CONTROL
  34. *
  35. * Handles actions specific to the board editor in pcbnew.
  36. */
  37. class PCB_EDITOR_CONTROL : public wxEvtHandler, public PCB_TOOL
  38. {
  39. public:
  40. PCB_EDITOR_CONTROL();
  41. ~PCB_EDITOR_CONTROL();
  42. /// @copydoc TOOL_INTERACTIVE::Reset()
  43. void Reset( RESET_REASON aReason ) override;
  44. /// @copydoc TOOL_INTERACTIVE::Init()
  45. bool Init() override;
  46. // Track & via size control
  47. int TrackWidthInc( const TOOL_EVENT& aEvent );
  48. int TrackWidthDec( const TOOL_EVENT& aEvent );
  49. int ViaSizeInc( const TOOL_EVENT& aEvent );
  50. int ViaSizeDec( const TOOL_EVENT& aEvent );
  51. // Zone actions
  52. int ZoneMerge( const TOOL_EVENT& aEvent );
  53. ///> Duplicates a zone onto a layer (prompts for new layer)
  54. int ZoneDuplicate( const TOOL_EVENT& aEvent );
  55. /**
  56. * Function PlaceTarget()
  57. * Allows user to place a layer alignment target.
  58. */
  59. int PlaceTarget( const TOOL_EVENT& aEvent );
  60. /**
  61. * Function PlaceModule()
  62. * Displays a dialog to select a module to be added and allows the user to set its position.
  63. */
  64. int PlaceModule( const TOOL_EVENT& aEvent );
  65. ///> Toggles 'lock' property for selected items.
  66. int ToggleLockSelected( const TOOL_EVENT& aEvent );
  67. ///> Locks selected items.
  68. int LockSelected( const TOOL_EVENT& aEvent );
  69. ///> Unlocks selected items.
  70. int UnlockSelected( const TOOL_EVENT& aEvent );
  71. ///> Notifies eeschema about the selected item.
  72. int CrossProbePcbToSch( const TOOL_EVENT& aEvent );
  73. ///> Reacts to selection change in eeschema.
  74. int CrossProbeSchToPcb( const TOOL_EVENT& aEvent );
  75. ///> Runs the drill origin tool for setting the origin for drill and pick-and-place files.
  76. int DrillOrigin( const TOOL_EVENT& aEvent );
  77. ///> UI-level access (including undo) to setting the drill origin
  78. static bool SetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
  79. BOARD_ITEM* aItem, const VECTOR2D& aPoint );
  80. ///> Low-level access (below undo) to setting the drill origin
  81. static bool DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
  82. BOARD_ITEM* aItem, const VECTOR2D& aPoint );
  83. ///> Highlights net belonging to the item under the cursor.
  84. int HighlightNet( const TOOL_EVENT& aEvent );
  85. ///> Clears all board highlights
  86. int ClearHighlight( const TOOL_EVENT& aEvent );
  87. ///> Launches a tool to pick the item whose net is going to be highlighted.
  88. int HighlightNetCursor( const TOOL_EVENT& aEvent );
  89. ///> Updates ratsnest for selected items.
  90. int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent );
  91. ///> Hides ratsnest for selected items. Called when there are no items selected.
  92. int HideSelectionRatsnest( const TOOL_EVENT& aEvent );
  93. ///> Shows local ratsnest of a component
  94. int ShowLocalRatsnest( const TOOL_EVENT& aEvent );
  95. private:
  96. ///> Event handler to recalculate dynamic ratsnest
  97. void ratsnestTimer( wxTimerEvent& aEvent );
  98. ///> Recalculates dynamic ratsnest for the current selection
  99. void calculateSelectionRatsnest();
  100. ///> Sets up handlers for various events.
  101. void setTransitions() override;
  102. ///> Pointer to the currently used edit frame.
  103. PCB_EDIT_FRAME* m_frame;
  104. /// Menu model displayed by the tool.
  105. TOOL_MENU m_menu;
  106. ///> Place & drill origin marker.
  107. std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_placeOrigin;
  108. ///> Flag to ignore a single crossprobe message from eeschema.
  109. bool m_probingSchToPcb;
  110. ///> Flag to indicate whether the current selection ratsnest is slow to calculate.
  111. bool m_slowRatsnest;
  112. ///> Timer that start ratsnest calculation when it is slow to compute.
  113. wxTimer m_ratsnestTimer;
  114. ///> How to modify a property for selected items.
  115. enum MODIFY_MODE { ON, OFF, TOGGLE };
  116. int modifyLockSelected( MODIFY_MODE aMode );
  117. // How does line width change after one -/+ key press.
  118. static const int WIDTH_STEP;
  119. };
  120. #endif