KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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, see <https://www.gnu.org/licenses/>.
18 */
19#include <tool/actions.h>
25#include <mail_type.h>
26#include <kiway.h>
27
28
32
34{
35}
36
37
42
43
45{
46 auto pinnedLib =
47 [this]( const SELECTION& aSel )
48 {
49 //
51 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
52 && current->m_Pinned;
53 };
54
55 auto unpinnedLib =
56 [this](const SELECTION& aSel )
57 {
59 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
60 && !current->m_Pinned;
61 };
62
63 aMenu->AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
64 aMenu->AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
66 aMenu->AddSeparator( 2 );
67
68 aMenu->AddSeparator( 400 );
70}
71
72
74{
76
77 if( current && !current->m_Pinned )
78 {
80 current->m_Pinned = true;
83
84 return 0;
85 }
86
87 return -1;
88}
89
90
92{
94
95 if( current && current->m_Pinned )
96 {
98 current->m_Pinned = false;
101
102 return 0;
103 }
104
105 return -1;
106}
107
108
110{
111 if( !getDesignBlockPane()->CreateNewDesignBlockLibrary( _( "New Design Block Library" ) ).IsEmpty() )
112 {
114 return 0;
115 }
116
117 return -1;
118}
119
120
122{
124
125 if( !current )
126 return -1;
127
128 if( getDesignBlockPane()->DeleteDesignBlockFromLibrary( current->m_LibId, true ) )
129 {
131 return 0;
132 }
133
134 return -1;
135}
136
137
139{
141
142 if( !current )
143 return -1;
144
146 {
148 return 0;
149 }
150
151 return -1;
152}
153
154
156{
157 m_frame->ToggleLibraryTree();
158 return 0;
159}
160
161
163{
165 return current
166 && ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
167 || current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
168}
169
170
172{
174 return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
175}
176
177
185
186
193
194
196{
198 return libTree ? libTree->GetCurrentTreeNode() : nullptr;
199}
200
201
203{
204 std::string payload = "";
205
206 for( FRAME_T frame : m_framesToNotify )
207 m_frame->Kiway().ExpressMail( frame, MAIL_RELOAD_LIB, payload );
208}
static TOOL_ACTION pinLibrary
Definition actions.h:158
static TOOL_ACTION hideLibraryTree
Definition actions.h:161
static TOOL_ACTION unpinLibrary
Definition actions.h:159
static TOOL_ACTION newLibrary
Definition actions.h:51
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.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int UnpinLibrary(const TOOL_EVENT &aEvent)
DESIGN_BLOCK_CONTROL(const std::string &aName)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
virtual DESIGN_BLOCK_PANE * getDesignBlockPane()=0
LIB_ID getSelectedLibId()
Set up handlers for various events.
bool selIsInLibrary(const SELECTION &aSel)
LIB_TREE_NODE * getCurrentTreeNode()
bool selIsDesignBlock(const SELECTION &aSel)
int NewLibrary(const TOOL_EVENT &aEvent)
int HideLibraryTree(const TOOL_EVENT &aEvent)
int PinLibrary(const TOOL_EVENT &aEvent)
int EditDesignBlockProperties(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
std::vector< FRAME_T > m_framesToNotify
Notify other frames that the design block lib table has changed.
int DeleteDesignBlock(const TOOL_EVENT &aEvent)
PANEL_DESIGN_BLOCK_CHOOSER * GetDesignBlockPanel() const
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:45
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Widget displaying a tree of symbols with optional search text control and description panel.
Definition lib_tree.h:46
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:347
@ DESIGN_BLOCK_LIB
Definition project.h:192
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
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).
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
#define _(s)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ MAIL_RELOAD_LIB
Definition mail_type.h:54