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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22#include <eda_draw_frame.h>
23#include <eda_item.h>
24#include <embedded_files.h>
25#include <tool/actions.h>
26#include <wx/debug.h>
27#include <wx/filedlg.h>
28
29#include <tool/embed_tool.h>
30
31
32EMBED_TOOL::EMBED_TOOL( const std::string& aName ) :
33 TOOL_INTERACTIVE( aName ),
34 m_files( nullptr )
35{
36}
37
38
40 TOOL_INTERACTIVE( "common.Embed" ),
41 m_files( nullptr )
42{
43}
44
45
47{
48 m_files = getModel<EDA_ITEM>()->GetEmbeddedFiles();
49
50 return true;
51}
52
53
55{
56 m_files = getModel<EDA_ITEM>()->GetEmbeddedFiles();
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>();
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 {
84 list.push_back( name );
85 }
86
87 return list;
88}
89
90
92{
95}
96
const char * name
Definition: DXF_plotter.cpp:59
static TOOL_ACTION removeFile
Cursor control event types.
Definition: actions.h:246
static TOOL_ACTION embeddedFiles
Definition: actions.h:244
void RemoveFile(const wxString &name, bool aErase=true)
Remove a file from the collection and frees the memory.
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
bool Init() override
Init() is called once upon a registration of the tool.
Definition: embed_tool.cpp:46
EMBEDDED_FILES * m_files
Definition: embed_tool.h:54
int AddFile(const TOOL_EVENT &aEvent)
Definition: embed_tool.cpp:60
std::vector< wxString > GetFileList()
Definition: embed_tool.cpp:78
int RemoveFile(const TOOL_EVENT &aEvent)
Definition: embed_tool.cpp:69
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: embed_tool.cpp:54
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
Definition: embed_tool.cpp:91
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:465
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).