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, 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 */
23#include <tool/actions.h>
29#include <mail_type.h>
30#include <kiway.h>
31
32
36
38{
39}
40
41
46
47
49{
50 auto pinnedLib =
51 [this]( const SELECTION& aSel )
52 {
53 //
55 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
56 && current->m_Pinned;
57 };
58
59 auto unpinnedLib =
60 [this](const SELECTION& aSel )
61 {
63 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
64 && !current->m_Pinned;
65 };
66
67 aMenu->AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
68 aMenu->AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
70 aMenu->AddSeparator( 2 );
71
72 aMenu->AddSeparator( 400 );
74}
75
76
78{
80
81 if( current && !current->m_Pinned )
82 {
84 current->m_Pinned = true;
87
88 return 0;
89 }
90
91 return -1;
92}
93
94
96{
98
99 if( current && current->m_Pinned )
100 {
101 m_frame->Prj().UnpinLibrary( current->m_LibId.GetLibNickname(), PROJECT::LIB_TYPE_T::DESIGN_BLOCK_LIB );
102 current->m_Pinned = false;
105
106 return 0;
107 }
108
109 return -1;
110}
111
112
114{
115 if( !getDesignBlockPane()->CreateNewDesignBlockLibrary( _( "New Design Block Library" ) ).IsEmpty() )
116 {
118 return 0;
119 }
120
121 return -1;
122}
123
124
126{
128
129 if( !current )
130 return -1;
131
132 if( getDesignBlockPane()->DeleteDesignBlockFromLibrary( current->m_LibId, true ) )
133 {
135 return 0;
136 }
137
138 return -1;
139}
140
141
143{
145
146 if( !current )
147 return -1;
148
150 {
152 return 0;
153 }
154
155 return -1;
156}
157
158
160{
161 m_frame->ToggleLibraryTree();
162 return 0;
163}
164
165
167{
169 return current
170 && ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
171 || current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
172}
173
174
176{
178 return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
179}
180
181
189
190
197
198
200{
202 return libTree ? libTree->GetCurrentTreeNode() : nullptr;
203}
204
205
207{
208 std::string payload = "";
209
210 for( FRAME_T frame : m_framesToNotify )
211 m_frame->Kiway().ExpressMail( frame, MAIL_RELOAD_LIB, payload );
212}
static TOOL_ACTION pinLibrary
Definition actions.h:162
static TOOL_ACTION hideLibraryTree
Definition actions.h:165
static TOOL_ACTION unpinLibrary
Definition actions.h:163
static TOOL_ACTION newLibrary
Definition actions.h:55
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: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.
Widget displaying a tree of symbols with optional search text control and description panel.
Definition lib_tree.h:48
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:351
@ DESIGN_BLOCK_LIB
Definition project.h:191
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:186
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:171
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:33
@ MAIL_RELOAD_LIB
Definition mail_type.h:57