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 (C) 2019-2024 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 */
26#include <confirm.h>
27#include <kidialog.h>
28#include <gestfich.h> // To open with a text editor
29#include <wx/filedlg.h>
31#include <design_block_pane.h>
34#include <ee_actions.h>
35
37{
38 m_editFrame = getEditFrame<SCH_EDIT_FRAME>();
41
42 auto pinnedLib =
43 [this]( const SELECTION& aSel )
44 {
45 //
47 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
48 && current->m_Pinned;
49 };
50 auto unpinnedLib =
51 [this](const SELECTION& aSel )
52 {
54 return current && current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
55 && !current->m_Pinned;
56 };
57
58 auto isInLibrary =
59 [this](const SELECTION& aSel )
60 {
62 return current
63 && ( current->m_Type == LIB_TREE_NODE::TYPE::LIBRARY
64 || current->m_Type == LIB_TREE_NODE::TYPE::ITEM );
65 };
66
67 auto isDesignBlock =
68 [this](const SELECTION& aSel )
69 {
71 return current && current->m_Type == LIB_TREE_NODE::TYPE::ITEM;
72 };
73
74 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
75
76 ctxMenu.AddItem( EE_ACTIONS::placeDesignBlock, isDesignBlock, 1);
77 ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLib, 1 );
78 ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLib, 1 );
79 ctxMenu.AddSeparator( 1 );
80
81 ctxMenu.AddItem( EE_ACTIONS::editDesignBlockProperties, isDesignBlock, 10 );
83 ctxMenu.AddItem( EE_ACTIONS::saveSheetAsDesignBlock, isInLibrary, 10 );
84 ctxMenu.AddItem( EE_ACTIONS::saveSelectionAsDesignBlock, isInLibrary, 10 );
85 ctxMenu.AddItem( EE_ACTIONS::deleteDesignBlock, isDesignBlock, 10 );
86
87 ctxMenu.AddSeparator( 400 );
89
90 return true;
91}
92
93
95{
97
98 if( current && !current->m_Pinned )
99 {
102 current->m_Pinned = true;
104 }
105
106 return 0;
107}
108
109
111{
113
114 if( current && current->m_Pinned )
115 {
118 current->m_Pinned = false;
120 }
121
122 return 0;
123}
124
125
127{
129 return 0;
130}
131
132
134{
136
137 if( !current )
138 return -1;
139
142
143 return 0;
144}
145
146
148{
150
151 if( !current )
152 return -1;
153
155
156 return 0;
157}
158
159
161{
163
164 if( !current )
165 return -1;
166
168
169 return 0;
170}
171
172
174{
176
177 if( !current )
178 return -1;
179
181 return 0;
182
183 return -1;
184}
185
186
188{
190 return 0;
191}
192
193
195{
198
200
205
207}
208
209
211{
213
214 return LIB_ID();
215}
216
217
219{
221}
222
223
225{
227 return libTree ? libTree->GetCurrentTreeNode() : nullptr;
228}
static TOOL_ACTION pinLibrary
Definition: actions.h:143
static TOOL_ACTION hideLibraryTree
Definition: actions.h:146
static TOOL_ACTION unpinLibrary
Definition: actions.h:144
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:207
static TOOL_ACTION placeDesignBlock
Definition: ee_actions.h:80
static TOOL_ACTION saveSheetAsDesignBlock
Definition: ee_actions.h:205
static TOOL_ACTION saveSelectionAsDesignBlock
Definition: ee_actions.h:206
static TOOL_ACTION editDesignBlockProperties
Definition: ee_actions.h:208
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:177
void UnpinLibrary(const wxString &aLibrary, enum LIB_TYPE_T aLibType)
Definition: project.cpp:214
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:218
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).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
This file is part of the common library.
This file is part of the common library.
Definition of file extensions used in Kicad.