KiCad PCB EDA Suite
Loading...
Searching...
No Matches
embed_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 */
19
21#include <eda_draw_frame.h>
22#include <eda_item.h>
23#include <embedded_files.h>
24#include <tool/actions.h>
25#include <wx/debug.h>
26#include <wx/filedlg.h>
27
28#include <tool/embed_tool.h>
29
30
31EMBED_TOOL::EMBED_TOOL( const std::string& aName ) :
32 TOOL_INTERACTIVE( aName ),
33 m_files( nullptr )
34{
35}
36
37
39 TOOL_INTERACTIVE( "common.Embed" ),
40 m_files( nullptr )
41{
42}
43
44
46{
47 m_files = getModel<EDA_ITEM>()->GetEmbeddedFiles();
48
49 return true;
50}
51
52
54{
56 m_files = model ? model->GetEmbeddedFiles() : nullptr;
57}
58
59
60int EMBED_TOOL::AddFile( const TOOL_EVENT& aEvent )
61{
62 wxString name = aEvent.Parameter<wxString>();
63 m_files->AddFile( name, false );
64
65 return 1;
66}
67
68
70{
71 wxString name = aEvent.Parameter<wxString>();
72 m_files->RemoveFile( name );
73
74 return 1;
75}
76
77
78std::vector<wxString> EMBED_TOOL::GetFileList()
79{
80 std::vector<wxString> list;
81
82 for( auto& [name, file] : m_files->EmbeddedFileMap() )
83 list.push_back( name );
84
85 return list;
86}
87
88
94
const char * name
static TOOL_ACTION removeFile
Cursor control event types.
Definition actions.h:295
static TOOL_ACTION embeddedFiles
Definition actions.h:293
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
bool Init() override
Init() is called once upon a registration of the tool.
EMBEDDED_FILES * m_files
Definition embed_tool.h:54
int AddFile(const TOOL_EVENT &aEvent)
std::vector< wxString > GetFileList()
int RemoveFile(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:469
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.
KIBIS_MODEL * model