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, see <https://www.gnu.org/licenses/>.
18 */
20#include <sch_actions.h>
21#include <sch_selection_tool.h>
23#include <sch_edit_frame.h>
24#include <tool/tool_manager.h>
27
28
32
33
35{
39
40 auto isInLibrary =
41 [this](const SELECTION& aSel )
42 {
43 return this->selIsInLibrary(aSel);
44 };
45
46 auto isDesignBlock =
47 [this](const SELECTION& aSel )
48 {
49 return this->selIsDesignBlock(aSel);
50 };
51
52 auto hasSelection =
53 [this](const SELECTION& aSel )
54 {
55 return !m_editFrame->GetCurrentSelection().Empty();
56 };
57
58 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
59 AddContextMenuItems( &ctxMenu );
60
61 ctxMenu.AddItem( SCH_ACTIONS::placeDesignBlock, isDesignBlock, 50 );
62 ctxMenu.AddSeparator( 50 );
63
64 ctxMenu.AddItem( SCH_ACTIONS::editDesignBlockProperties, isDesignBlock, 100 );
65 ctxMenu.AddItem( SCH_ACTIONS::saveSheetAsDesignBlock, isInLibrary, 100 );
66 ctxMenu.AddItem( SCH_ACTIONS::saveSelectionAsDesignBlock, isInLibrary && hasSelection, 100 );
67 ctxMenu.AddItem( SCH_ACTIONS::updateDesignBlockFromSheet, isDesignBlock, 100 );
68 ctxMenu.AddItem( SCH_ACTIONS::updateDesignBlockFromSelection, isDesignBlock && hasSelection, 100 );
69 ctxMenu.AddItem( SCH_ACTIONS::deleteDesignBlock, isDesignBlock, 100 );
70 ctxMenu.AddSeparator( 100 );
71
72 return true;
73}
74
75
77{
79
80 if( !current )
81 return -1;
82
83 // This can be modified as a result of the save operation so copy it
84 LIB_ID libId = current->m_LibId;
85
86 if( !m_editFrame->SaveSheetAsDesignBlock( libId.GetLibNickname(), m_editFrame->GetCurrentSheet() ) )
87 return -1;
88
90
91 return 0;
92}
93
94
96{
98
99 if( !current )
100 return -1;
101
102 // This can be modified as a result of the save operation so copy it
103 LIB_ID libId = current->m_LibId;
104
105 if( !m_editFrame->SaveSelectionAsDesignBlock( libId.GetLibNickname() ) )
106 return -1;
107
109
110 return 0;
111}
112
113
115{
117
118 if( !current )
119 return -1;
120
121 // This can be modified as a result of the save operation so copy it
122 LIB_ID libId = current->m_LibId;
123
124 if( !m_editFrame->UpdateDesignBlockFromSheet( libId, m_editFrame->GetCurrentSheet() ) )
125 return -1;
126
128
129 return 0;
130}
131
132
134{
136
137 if( !current )
138 return -1;
139
140 // This can be modified as a result of the save operation so copy it
141 LIB_ID libId = current->m_LibId;
142
143 if( !m_editFrame->UpdateDesignBlockFromSelection( libId ) )
144 return -1;
145
147
148 return 0;
149}
150
151
163
164
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.
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
bool selIsInLibrary(const SELECTION &aSel)
LIB_TREE_NODE * getCurrentTreeNode()
bool selIsDesignBlock(const SELECTION &aSel)
int EditDesignBlockProperties(const TOOL_EVENT &aEvent)
std::vector< FRAME_T > m_framesToNotify
Notify other frames that the design block lib table has changed.
int DeleteDesignBlock(const TOOL_EVENT &aEvent)
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.
static TOOL_ACTION updateDesignBlockFromSheet
static TOOL_ACTION saveSheetAsDesignBlock
static TOOL_ACTION saveSelectionAsDesignBlock
static TOOL_ACTION deleteDesignBlock
static TOOL_ACTION editDesignBlockProperties
static TOOL_ACTION placeDesignBlock
Definition sch_actions.h:65
static TOOL_ACTION updateDesignBlockFromSelection
int UpdateDesignBlockFromSheet(const TOOL_EVENT &aEvent)
int UpdateDesignBlockFromSelection(const TOOL_EVENT &aEvent)
int SaveSheetAsDesignBlock(const TOOL_EVENT &aEvent)
DESIGN_BLOCK_PANE * getDesignBlockPane() override
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.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
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.
@ FRAME_PCB_EDITOR
Definition frame_type.h:38