KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_edit_table_tool.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) 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 */
23
24#include <tool/tool_manager.h>
26#include <tools/pcb_actions.h>
27#include <collectors.h>
28#include <dialogs/dialog_table_properties.h>
30
31
33 PCB_TOOL_BASE( "pcbnew.TableEditor" )
34{
35}
36
37
39{
41
43
44 return true;
45}
46
47
49{
50 PCB_TABLECELL* cell = new PCB_TABLECELL( aSource->GetParent() );
51
52 cell->SetStart( aSource->GetStart() );
53 cell->SetEnd( aSource->GetEnd() );
54
55 return cell;
56}
57
58
60{
62
63 return selTool->RequestSelection(
64 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
65 {
66 // Iterate from the back so we don't have to worry about removals.
67 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
68 {
69 if( !dynamic_cast<PCB_TABLECELL*>( aCollector[ i ] ) )
70 aCollector.Remove( aCollector[ i ] );
71 }
72 },
73 false /* prompt user regarding locked items */ );
74}
75
76
78{
80};
81
82
84{
87 PCB_TABLE* parentTable = nullptr;
88
89 for( EDA_ITEM* item : selection.Items() )
90 {
91 if( item->Type() != PCB_TABLECELL_T )
92 return 0;
93
94 PCB_TABLE* table = static_cast<PCB_TABLE*>( item->GetParent() );
95
96 if( !parentTable )
97 {
98 parentTable = table;
99 }
100 else if( parentTable != table )
101 {
102 parentTable = nullptr;
103 break;
104 }
105 }
106
107 if( parentTable )
108 {
109 DIALOG_TABLE_PROPERTIES dlg( frame(), parentTable );
110
111 dlg.ShowQuasiModal(); // Scintilla's auto-complete requires quasiModal
112 }
113
114 if( clearSelection )
116
117 return 0;
118}
119
120
122{
125
128
131
134
136}
static TOOL_ACTION addRowAbove
Definition: actions.h:97
static TOOL_ACTION addColBefore
Definition: actions.h:99
static TOOL_ACTION deleteRows
Definition: actions.h:101
static TOOL_ACTION addRowBelow
Definition: actions.h:98
static TOOL_ACTION deleteColumns
Definition: actions.h:102
static TOOL_ACTION unmergeCells
Definition: actions.h:104
static TOOL_ACTION mergeCells
Definition: actions.h:103
static TOOL_ACTION addColAfter
Definition: actions.h:100
static TOOL_ACTION editTable
Definition: actions.h:105
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:215
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:109
int ShowQuasiModal()
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:167
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:134
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:130
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:171
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:202
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
int AddRowAbove(const TOOL_EVENT &aEvent)
int EditTable(const TOOL_EVENT &aEvent)
int DeleteRows(const TOOL_EVENT &aEvent)
int AddRowBelow(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
void setTransitions() override
< Set up handlers for various events.
int UnmergeCells(const TOOL_EVENT &aEvent)
int AddColumnAfter(const TOOL_EVENT &aEvent)
int DeleteColumns(const TOOL_EVENT &aEvent)
int AddColumnBefore(const TOOL_EVENT &aEvent)
void clearSelection() override
const SELECTION & getTableCellSelection() override
int MergeCells(const TOOL_EVENT &aEvent)
PCB_TABLECELL * copyCell(PCB_TABLECELL *aSource) override
The selection tool: currently supports:
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection, filtered according to aClientFilter.
T * frame() const
virtual bool Init() override
Init() is called once upon a registration of the tool.
const PCB_SELECTION & selection() const
bool IsHover() const
Definition: selection.h:84
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:177
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).
TOOL_MENU & GetToolMenu()
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95