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 auto isDesignBlock =
68 [this](const SELECTION& aSel )
69 {
70 return this->selIsDesignBlock(aSel);
71 };
72
73 aMenu->AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
74 aMenu->AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
75 aMenu->AddItem( ACTIONS::newLibrary, !isDesignBlock, 1 );
76 aMenu->AddSeparator( 2 );
77
78 aMenu->AddSeparator( 400 );
80}
81
82
84{
86
87 if( current && !current->m_Pinned )
88 {
90 current->m_Pinned = true;
93
94 return 0;
95 }
96
97 return -1;
98}
99
100
102{
104
105 if( current && current->m_Pinned )
106 {
107 m_frame->Prj().UnpinLibrary( current->m_LibId.GetLibNickname(), PROJECT::LIB_TYPE_T::DESIGN_BLOCK_LIB );
108 current->m_Pinned = false;
111
112 return 0;
113 }
114
115 return -1;
116}
117
118
120{
121 if( !getDesignBlockPane()->CreateNewDesignBlockLibrary( _( "New Design Block Library" ) ).IsEmpty() )
122 {
124 return 0;
125 }
126
127 return -1;
128}
129
130
132{
134
135 if( !current )
136 return -1;
137
138 if( getDesignBlockPane()->DeleteDesignBlockFromLibrary( current->m_LibId, true ) )
139 {
141 return 0;
142 }
143
144 return -1;
145}
146
147
149{
151
152 if( !current )
153 return -1;
154
156 {
158 return 0;
159 }
160
161 return -1;
162}
163
164
166{
167 m_frame->ToggleLibraryTree();
168 return 0;
169}
170
171
173{
175 return current
176 && ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
177 || current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
178}
179
180
182{
184 return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
185}
186
187
195
196
203
204
206{
208 return libTree ? libTree->GetCurrentTreeNode() : nullptr;
209}
210
211
213{
214 std::string payload = "";
215
216 for( FRAME_T frame : m_framesToNotify )
217 m_frame->Kiway().ExpressMail( frame, MAIL_RELOAD_LIB, payload );
218}
static TOOL_ACTION pinLibrary
Definition actions.h:161
static TOOL_ACTION hideLibraryTree
Definition actions.h:164
static TOOL_ACTION unpinLibrary
Definition actions.h:162
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:49
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:196
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