KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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 */
25#include <design_block_pane.h>
28#include <ee_actions.h>
29
31{
32 m_editFrame = getEditFrame<SCH_EDIT_FRAME>();
35
36 auto pinnedLib =
37 [this]( const SELECTION& aSel )
38 {
39 //
41 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
42 && current->m_Pinned;
43 };
44 auto unpinnedLib =
45 [this](const SELECTION& aSel )
46 {
48 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
49 && !current->m_Pinned;
50 };
51
52 auto isInLibrary =
53 [this](const SELECTION& aSel )
54 {
56 return current
57 && ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
58 || current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
59 };
60
61 auto isDesignBlock =
62 [this](const SELECTION& aSel )
63 {
65 return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
66 };
67
68 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
69
70 ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
71 ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
72 ctxMenu.AddItem( ACTIONS::newLibrary, !isDesignBlock, 1 );
73 ctxMenu.AddSeparator( 1 );
74
75 ctxMenu.AddItem( EE_ACTIONS::placeDesignBlock, isDesignBlock, 50 );
76 ctxMenu.AddSeparator( 50 );
77
78 ctxMenu.AddItem( EE_ACTIONS::editDesignBlockProperties, isDesignBlock, 100 );
79 ctxMenu.AddItem( EE_ACTIONS::saveSheetAsDesignBlock, isInLibrary, 100 );
80 ctxMenu.AddItem( EE_ACTIONS::saveSelectionAsDesignBlock, isInLibrary, 100 );
81 ctxMenu.AddItem( EE_ACTIONS::deleteDesignBlock, isDesignBlock, 100 );
82 ctxMenu.AddSeparator( 100 );
83
85
86 return true;
87}
88
89
91{
93
94 if( current && !current->m_Pinned )
95 {
98 current->m_Pinned = true;
100 }
101
102 return 0;
103}
104
105
107{
109
110 if( current && current->m_Pinned )
111 {
114 current->m_Pinned = false;
116 }
117
118 return 0;
119}
120
121
123{
125 return 0;
126}
127
128
130{
132
133 if( !current )
134 return -1;
135
138
139 return 0;
140}
141
142
144{
146
147 if( !current )
148 return -1;
149
151
152 return 0;
153}
154
155
157{
159
160 if( !current )
161 return -1;
162
164
165 return 0;
166}
167
168
170{
172
173 if( !current )
174 return -1;
175
177 return 0;
178
179 return -1;
180}
181
182
184{
186 return 0;
187}
188
189
191{
194
196
201
203}
204
205
207{
209
210 return LIB_ID();
211}
212
213
215{
217}
218
219
221{
223 return libTree ? libTree->GetCurrentTreeNode() : nullptr;
224}
static TOOL_ACTION pinLibrary
Definition: actions.h:152
static TOOL_ACTION hideLibraryTree
Definition: actions.h:155
static TOOL_ACTION unpinLibrary
Definition: actions.h:153
static TOOL_ACTION newLibrary
Definition: actions.h:48
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.
PANEL_DESIGN_BLOCK_CHOOSER * GetDesignBlockPanel() const
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
static TOOL_ACTION deleteDesignBlock
Definition: ee_actions.h:209
static TOOL_ACTION placeDesignBlock
Definition: ee_actions.h:82
static TOOL_ACTION saveSheetAsDesignBlock
Definition: ee_actions.h:207
static TOOL_ACTION saveSelectionAsDesignBlock
Definition: ee_actions.h:208
static TOOL_ACTION editDesignBlockProperties
Definition: ee_actions.h:210
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
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.
enum TYPE m_Type
Widget displaying a tree of symbols with optional search text control and description panel.
Definition: lib_tree.h:49
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:332
@ DESIGN_BLOCK_LIB
Definition: project.h:192
void PinLibrary(const wxString &aLibrary, enum LIB_TYPE_T aLibType)
Definition: project.cpp:188
void UnpinLibrary(const wxString &aLibrary, enum LIB_TYPE_T aLibType)
Definition: project.cpp:225
int DeleteDesignBlock(const TOOL_EVENT &aEvent)
int PinLibrary(const TOOL_EVENT &aEvent)
int HideLibraryTree(const TOOL_EVENT &aEvent)
LIB_ID getSelectedLibId()
Set up handlers for various events.
int SaveSheetAsDesignBlock(const TOOL_EVENT &aEvent)
int EditDesignBlockProperties(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int SaveSelectionAsDesignBlock(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
DESIGN_BLOCK_PANE * getDesignBlockPane()
int UnpinLibrary(const TOOL_EVENT &aEvent)
int NewLibrary(const TOOL_EVENT &aEvent)
void SaveSelectionAsDesignBlock(const wxString &aLibraryName)
bool EditDesignBlockProperties(const LIB_ID &aLibId)
void ToggleLibraryTree() override
void SaveSheetAsDesignBlock(const wxString &aLibraryName, SCH_SHEET_PATH &aSheetPath)
bool DeleteDesignBlockFromLibrary(const LIB_ID &aLibId, bool aConfirm)
SCH_SHEET_PATH & GetCurrentSheet() const
wxString CreateNewDesignBlockLibrary(const wxString &aLibName=wxEmptyString, const wxString &aProposedName=wxEmptyString)
If a library name is given, creates a new design block library in the project folder with the given n...
DESIGN_BLOCK_PANE * GetDesignBlockPane() const
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
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.