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 (C) 2024 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{
35}
36
37
39 TOOL_INTERACTIVE( "common.Embed" )
40{
41}
42
43
45{
46
47 m_files = getModel<EDA_ITEM>()->GetEmbeddedFiles();
48
49 return true;
50}
51
52
54{
55 m_files = getModel<EDA_ITEM>()->GetEmbeddedFiles();
56
57}
58
59int EMBED_TOOL::AddFile( const TOOL_EVENT& aEvent )
60{
61 wxString name = aEvent.Parameter<wxString>();
62 m_files->AddFile( name, false );
63
64 return 1;
65}
66
68{
69 wxString name = aEvent.Parameter<wxString>();
71
72 return 1;
73}
74
75std::vector<wxString> EMBED_TOOL::GetFileList()
76{
77 std::vector<wxString> list;
78
79 for( auto& [name, file] : m_files->EmbeddedFileMap() )
80 {
81 list.push_back( name );
82 }
83
84 return list;
85}
86
88{
91}
92
const char * name
Definition: DXF_plotter.cpp:57
static TOOL_ACTION removeFile
Cursor control event types.
Definition: actions.h:234
static TOOL_ACTION embeddedFiles
Definition: actions.h:232
void RemoveFile(const wxString &name, bool aErase=true)
Removes a file from the collection and frees the memory.
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Loads 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:44
EMBEDDED_FILES * m_files
Definition: embed_tool.h:54
int AddFile(const TOOL_EVENT &aEvent)
Definition: embed_tool.cpp:59
std::vector< wxString > GetFileList()
Definition: embed_tool.cpp:75
int RemoveFile(const TOOL_EVENT &aEvent)
Definition: embed_tool.cpp:67
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: embed_tool.cpp:53
void setTransitions() override
<
Definition: embed_tool.cpp:87
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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).