KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_design_block_control.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
24#include <pcb_edit_frame.h>
25#include <tool/tool_manager.h>
26#include <tools/pcb_actions.h>
31
32
34{
35}
36
37
39{
40 m_editFrame = getEditFrame<PCB_EDIT_FRAME>();
43
44 auto isInLibrary =
45 [this](const SELECTION& aSel )
46 {
47 return this->selIsInLibrary(aSel);
48 };
49
50 auto isDesignBlock =
51 [this](const SELECTION& aSel )
52 {
53 return this->selIsDesignBlock(aSel);
54 };
55
56 auto hasSelection =
57 [this](const SELECTION& aSel )
58 {
60 };
61
62 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
63 AddContextMenuItems( &ctxMenu );
64
65 ctxMenu.AddItem( PCB_ACTIONS::placeDesignBlock, isDesignBlock, 50 );
66 ctxMenu.AddSeparator( 50 );
67
68 ctxMenu.AddItem( PCB_ACTIONS::editDesignBlockProperties, isDesignBlock, 100 );
69 ctxMenu.AddItem( PCB_ACTIONS::saveBoardAsDesignBlock, isInLibrary, 100 );
70 ctxMenu.AddItem( PCB_ACTIONS::saveSelectionAsDesignBlock, isInLibrary && hasSelection, 100 );
71 ctxMenu.AddItem( PCB_ACTIONS::saveBoardToDesignBlock, isDesignBlock, 100 );
72 ctxMenu.AddItem( PCB_ACTIONS::saveSelectionToDesignBlock, isDesignBlock && hasSelection, 100 );
73 ctxMenu.AddItem( PCB_ACTIONS::deleteDesignBlock, isDesignBlock, 100 );
74 ctxMenu.AddSeparator( 100 );
75
76 return true;
77}
78
79
81{
83
84 if( !current )
85 return -1;
86
88 return -1;
89
91
92 return 0;
93}
94
95
97{
99
100 if( !current )
101 return -1;
102
104 return -1;
105
107
108 return 0;
109}
110
111
113{
115
116 if( !current )
117 return -1;
118
119 if( !m_editFrame->SaveBoardToDesignBlock( current->m_LibId ) )
120 return -1;
121
123
124 return 0;
125}
126
127
129{
131
132 if( !current )
133 return -1;
134
136 return -1;
137
139
140 return 0;
141}
142
144{
151}
152
153
155{
157
158 return LIB_ID();
159}
160
161
163{
165}
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
EDA_DRAW_FRAME * m_frame
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
bool selIsInLibrary(const SELECTION &aSel)
LIB_TREE_NODE * getCurrentTreeNode()
bool selIsDesignBlock(const SELECTION &aSel)
int EditDesignBlockProperties(const TOOL_EVENT &aEvent)
std::vector< FRAME_T > m_framesToNotify
Notify other frames that the design block lib table has changed.
int DeleteDesignBlock(const TOOL_EVENT &aEvent)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
static TOOL_ACTION saveSelectionAsDesignBlock
Definition: pcb_actions.h:467
static TOOL_ACTION editDesignBlockProperties
Definition: pcb_actions.h:471
static TOOL_ACTION deleteDesignBlock
Definition: pcb_actions.h:470
static TOOL_ACTION saveBoardAsDesignBlock
Definition: pcb_actions.h:466
static TOOL_ACTION placeDesignBlock
Definition: pcb_actions.h:464
static TOOL_ACTION saveSelectionToDesignBlock
Definition: pcb_actions.h:469
static TOOL_ACTION saveBoardToDesignBlock
Definition: pcb_actions.h:468
int SaveSelectionAsDesignBlock(const TOOL_EVENT &aEvent)
DESIGN_BLOCK_PANE * getDesignBlockPane() override
bool Init() override
Init() is called once upon a registration of the tool.
LIB_ID getSelectedLibId()
Set up handlers for various events.
int SaveBoardAsDesignBlock(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int SaveSelectionToDesignBlock(const TOOL_EVENT &aEvent)
int SaveBoardToDesignBlock(const TOOL_EVENT &aEvent)
bool SaveBoardToDesignBlock(const LIB_ID &aLibId)
PCB_DESIGN_BLOCK_PANE * GetDesignBlockPane() const
bool SaveSelectionAsDesignBlock(const wxString &aLibraryName)
bool SaveSelectionToDesignBlock(const LIB_ID &aLibId)
bool SaveBoardAsDesignBlock(const wxString &aLibraryName)
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
Generic, UI-independent tool event.
Definition: tool_event.h:168
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
@ FRAME_SCH
Definition: frame_type.h:34