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.

179 lines
6.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_base.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_BASE
  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. int New( const TOOL_EVENT& aEvent );
  47. int Open( const TOOL_EVENT& aEvent );
  48. int Save( const TOOL_EVENT& aEvent );
  49. int SaveAs( const TOOL_EVENT& aEvent );
  50. int SaveCopyAs( const TOOL_EVENT& aEvent );
  51. int PageSettings( const TOOL_EVENT& aEvent );
  52. int Plot( const TOOL_EVENT& aEvent );
  53. int BoardSetup( const TOOL_EVENT& aEvent );
  54. int ImportNetlist( const TOOL_EVENT& aEvent );
  55. int ImportSpecctraSession( const TOOL_EVENT& aEvent );
  56. int ExportSpecctraDSN( const TOOL_EVENT& aEvent );
  57. int GenerateDrillFiles( const TOOL_EVENT& aEvent );
  58. int GeneratePosFile( const TOOL_EVENT& aEvent );
  59. int GenerateFabFiles( const TOOL_EVENT& aEvent );
  60. int UpdatePCBFromSchematic( const TOOL_EVENT& aEvent );
  61. int ToggleLayersManager( const TOOL_EVENT& aEvent );
  62. int ToggleMicrowaveToolbar( const TOOL_EVENT& aEvent );
  63. int TogglePythonConsole( const TOOL_EVENT& aEvent );
  64. // Track & via size control
  65. int TrackWidthInc( const TOOL_EVENT& aEvent );
  66. int TrackWidthDec( const TOOL_EVENT& aEvent );
  67. int ViaSizeInc( const TOOL_EVENT& aEvent );
  68. int ViaSizeDec( const TOOL_EVENT& aEvent );
  69. // Zone actions
  70. int ZoneMerge( const TOOL_EVENT& aEvent );
  71. ///> Duplicates a zone onto a layer (prompts for new layer)
  72. int ZoneDuplicate( const TOOL_EVENT& aEvent );
  73. /**
  74. * Function PlaceTarget()
  75. * Allows user to place a layer alignment target.
  76. */
  77. int PlaceTarget( const TOOL_EVENT& aEvent );
  78. /**
  79. * Function PlaceModule()
  80. * Displays a dialog to select a module to be added and allows the user to set its position.
  81. */
  82. int PlaceModule( const TOOL_EVENT& aEvent );
  83. ///> Toggles 'lock' property for selected items.
  84. int ToggleLockSelected( const TOOL_EVENT& aEvent );
  85. ///> Locks selected items.
  86. int LockSelected( const TOOL_EVENT& aEvent );
  87. ///> Unlocks selected items.
  88. int UnlockSelected( const TOOL_EVENT& aEvent );
  89. ///> Notifies eeschema about the selected item.
  90. int CrossProbePcbToSch( const TOOL_EVENT& aEvent );
  91. ///> Reacts to selection change in eeschema.
  92. int CrossProbeSchToPcb( const TOOL_EVENT& aEvent );
  93. ///> Runs the drill origin tool for setting the origin for drill and pick-and-place files.
  94. int DrillOrigin( const TOOL_EVENT& aEvent );
  95. ///> UI-level access (including undo) to setting the drill origin
  96. static bool SetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
  97. BOARD_ITEM* aItem, const VECTOR2D& aPoint );
  98. ///> Low-level access (below undo) to setting the drill origin
  99. static void DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
  100. BOARD_ITEM* aItem, const VECTOR2D& aPoint );
  101. ///> Highlights net belonging to the item under the cursor.
  102. int HighlightNet( const TOOL_EVENT& aEvent );
  103. ///> Clears all board highlights
  104. int ClearHighlight( const TOOL_EVENT& aEvent );
  105. ///> Launches a tool to pick the item whose net is going to be highlighted.
  106. int HighlightNetCursor( const TOOL_EVENT& aEvent );
  107. ///> Updates ratsnest for selected items.
  108. int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent );
  109. ///> Hides ratsnest for selected items. Called when there are no items selected.
  110. int HideDynamicRatsnest( const TOOL_EVENT& aEvent );
  111. ///> Shows local ratsnest of a component
  112. int LocalRatsnestTool( const TOOL_EVENT& aEvent );
  113. int FlipPcbView( const TOOL_EVENT& aEvent );
  114. int ListNets( const TOOL_EVENT& aEvent );
  115. private:
  116. bool highlightNet( const VECTOR2D& aPosition, bool aUseSelection );
  117. ///> Event handler to recalculate dynamic ratsnest
  118. void ratsnestTimer( wxTimerEvent& aEvent );
  119. ///> Recalculates dynamic ratsnest for the current selection
  120. void calculateSelectionRatsnest();
  121. ///> Sets up handlers for various events.
  122. void setTransitions() override;
  123. ///> Pointer to the currently used edit frame.
  124. PCB_EDIT_FRAME* m_frame;
  125. std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_placeOrigin; ///> Place & drill origin marker
  126. bool m_probingSchToPcb; ///> Recursion guard when cross-probing to EESchema
  127. bool m_slowRatsnest; ///> Indicates current selection ratsnest will be slow to calculate
  128. wxTimer m_ratsnestTimer; ///> Timer to initiate lazy ratsnest calculation (ie: when slow)
  129. int m_lastNetcode; ///> Used for toggling between last two highlighted nets
  130. ///> How to modify a property for selected items.
  131. enum MODIFY_MODE { ON, OFF, TOGGLE };
  132. int modifyLockSelected( MODIFY_MODE aMode );
  133. // How does line width change after one -/+ key press.
  134. static const int WIDTH_STEP;
  135. };
  136. #endif