1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 CERN
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
25  */
26 
27 #ifndef BOARD_EDITOR_CONTROL_H
28 #define BOARD_EDITOR_CONTROL_H
29 
30 #include <tools/pcb_tool_base.h>
31 #include <tool/tool_menu.h>
32 
33 namespace KIGFX {
34     class ORIGIN_VIEWITEM;
35 }
36 
37 class PCB_EDIT_FRAME;
38 
39 /**
40  * Handle actions specific to the board editor in PcbNew.
41  */
42 class BOARD_EDITOR_CONTROL : public PCB_TOOL_BASE
43 {
44 public:
45     BOARD_EDITOR_CONTROL();
46     ~BOARD_EDITOR_CONTROL();
47 
48     /// @copydoc TOOL_INTERACTIVE::Reset()
49     void Reset( RESET_REASON aReason ) override;
50 
51     /// @copydoc TOOL_INTERACTIVE::Init()
52     bool Init() override;
53 
54     int New( const TOOL_EVENT& aEvent );
55     int Open( const TOOL_EVENT& aEvent );
56     int Save( const TOOL_EVENT& aEvent );
57     int SaveAs( const TOOL_EVENT& aEvent );
58     int SaveCopyAs( const TOOL_EVENT& aEvent );
59     int PageSettings( const TOOL_EVENT& aEvent );
60     int Plot( const TOOL_EVENT& aEvent );
61 
62     int Find( const TOOL_EVENT& aEvent );
63     int FindNext( const TOOL_EVENT& aEvent );
64 
65     int BoardSetup( const TOOL_EVENT& aEvent );
66     int ImportNetlist( const TOOL_EVENT& aEvent );
67     int ImportSpecctraSession( const TOOL_EVENT& aEvent );
68     int ExportSpecctraDSN( const TOOL_EVENT& aEvent );
69     int ExportNetlist( const TOOL_EVENT& aEvent );
70     int GenerateDrillFiles( const TOOL_EVENT& aEvent );
71     int GeneratePosFile( const TOOL_EVENT& aEvent );
72     int GenerateFabFiles( const TOOL_EVENT& aEvent );
73     int RepairBoard( const TOOL_EVENT& aEvent );
74 
75     int UpdatePCBFromSchematic( const TOOL_EVENT& aEvent );
76     int UpdateSchematicFromPCB( const TOOL_EVENT& aEvent );
77     int ShowEeschema( const TOOL_EVENT& aEvent );
78     int ToggleLayersManager( const TOOL_EVENT& aEvent );
79     int TogglePythonConsole( const TOOL_EVENT& aEvent );
80 
81     // Track & via size control
82     int TrackWidthInc( const TOOL_EVENT& aEvent );
83     int TrackWidthDec( const TOOL_EVENT& aEvent );
84     int ViaSizeInc( const TOOL_EVENT& aEvent );
85     int ViaSizeDec( const TOOL_EVENT& aEvent );
86 
87     // Zone actions
88     int ZoneMerge( const TOOL_EVENT& aEvent );
89 
90     ///< Duplicate a zone onto a layer (prompts for new layer)
91     int ZoneDuplicate( const TOOL_EVENT& aEvent );
92 
93     int EditFpInFpEditor( const TOOL_EVENT& aEvent );
94 
95     /**
96      * Allow user to place a layer alignment target.
97      */
98     int PlaceTarget( const TOOL_EVENT& aEvent );
99 
100     /**
101      * Display a dialog to select a footprint to be added and allows the user to set its position.
102      */
103     int PlaceFootprint( const TOOL_EVENT& aEvent );
104 
105     /**
106      * Re-entrancy checker for above.
107      */
PlacingFootprint()108     bool PlacingFootprint() const { return m_placingFootprint; }
109 
110     ///< Toggle 'lock' property for selected items.
111     int ToggleLockSelected( const TOOL_EVENT& aEvent );
112 
113     ///< Lock selected items.
114     int LockSelected( const TOOL_EVENT& aEvent );
115 
116     ///< Unlock selected items.
117     int UnlockSelected( const TOOL_EVENT& aEvent );
118 
119     ///< Run the drill origin tool for setting the origin for drill and pick-and-place files.
120     int DrillOrigin( const TOOL_EVENT& aEvent );
121 
122     ///< Low-level access (below undo) to setting the drill origin.
123     static void DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
124                                   EDA_ITEM* aItem, const VECTOR2D& aPoint );
125 
126 private:
127     ///< How to modify a property for selected items.
128     enum MODIFY_MODE { ON, OFF, TOGGLE };
129 
130     int modifyLockSelected( MODIFY_MODE aMode );
131 
132     ///< Set up handlers for various events.
133     void setTransitions() override;
134 
135 private:
136     PCB_EDIT_FRAME*  m_frame;
137     bool             m_inPlaceFootprint;      // Re-entrancy guard for tool.
138     bool             m_placingFootprint;      // Re-entrancy guard for placement loop.
139     bool             m_inPlaceTarget;         // Re-entrancy guard.
140 
141     std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_placeOrigin;
142 
143     static const int WIDTH_STEP; ///< How does line width change after one -/+ key press.
144 };
145 
146 #endif
147