KiCad PCB EDA Suite
pcb_tool.h
Go to the documentation of this file.
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 
25 #ifndef __PCB_TOOL_H
26 #define __PCB_TOOL_H
27 
28 #include <string>
29 
30 #include <tool/tool_event.h>
31 #include <tool/tool_interactive.h>
32 #include <pcb_edit_frame.h>
33 #include <class_board.h>
34 #include <view/view_group.h>
35 #include <pcb_view.h>
36 
37 #include <functional>
38 
39 
46 class PCB_TOOL;
47 class PCB_EDIT_FRAME;
49 class PCB_DRAW_PANEL_GAL;
50 class SELECTION;
51 
53 {
54  virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
55  virtual bool PlaceItem( BOARD_ITEM *aItem ) { return false; }
56 
59 };
60 
61 
62 class PCB_TOOL : public TOOL_INTERACTIVE
63 {
64 public:
69  PCB_TOOL( TOOL_ID aId, const std::string& aName ) :
70  TOOL_INTERACTIVE ( aId, aName ),
71  m_editModules( false ) {};
72 
77  PCB_TOOL( const std::string& aName ) :
78  TOOL_INTERACTIVE ( aName ),
79  m_editModules( false ) {};
80 
81  virtual ~PCB_TOOL() {};
82 
83  virtual void Reset( RESET_REASON aReason ) override;
84 
92  void SetEditModules( bool aEnabled )
93  {
94  m_editModules = aEnabled;
95  }
96 
97  bool EditingModules() const
98  {
99  return m_editModules;
100  }
101 
102 protected:
103 
105  IPO_ROTATE = 1,
106  IPO_FLIP = 2,
107  IPO_PROPERTIES = 4,
108  IPO_SINGLE_CLICK = 8,
109  IPO_REPEAT = 16
110  };
111 
112 
125  void doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE *aPlacer,
126  const wxString& aCommitMessage,
127  int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
128 
129  virtual void setTransitions() override;
130 
131 
132  KIGFX::PCB_VIEW* view() const { return static_cast<KIGFX::PCB_VIEW*>( getView() ); }
133  KIGFX::VIEW_CONTROLS* controls() const { return getViewControls(); }
134  PCB_EDIT_FRAME* frame() const { return getEditFrame<PCB_EDIT_FRAME>(); }
135  BOARD* board() const { return getModel<BOARD>(); }
136  MODULE* module() const { return board()->m_Modules; }
137  PCB_DISPLAY_OPTIONS* displayOptions() const;
138  PCB_DRAW_PANEL_GAL* canvas() const;
139  const SELECTION& selection() const;
140  SELECTION& selection();
141 
143 };
144 
145 #endif
virtual bool PlaceItem(BOARD_ITEM *aItem)
Definition: pcb_tool.h:55
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
Class BOARD to handle a board.
PCB_EDIT_FRAME * m_frame
Definition: pcb_tool.h:57
INTERACTIVE_PLACEMENT_OPTIONS
Definition: pcb_tool.h:104
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:133
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:57
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
virtual ~PCB_TOOL()
Definition: pcb_tool.h:81
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:69
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:134
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
MODULE * module() const
Definition: pcb_tool.h:136
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
bool m_editModules
Definition: pcb_tool.h:142
bool EditingModules() const
Definition: pcb_tool.h:97
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
KIGFX::PCB_VIEW * view() const
Definition: pcb_tool.h:132
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
PCB_TOOL(const std::string &aName)
Constructor.
Definition: pcb_tool.h:77
void SetEditModules(bool aEnabled)
Function SetEditModules()
Definition: pcb_tool.h:92
BOARD * board() const
Definition: pcb_tool.h:135