KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_remote_symbol.h
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,
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#ifndef PANEL_REMOTE_SYMBOL_H
25#define PANEL_REMOTE_SYMBOL_H
26
27
28#include <memory>
29#include <optional>
30#include <vector>
31#include <map>
32
33#include <pcm.h>
34#include <nlohmann/json_fwd.hpp>
35#include <wx/filename.h>
36#include <wx/panel.h>
37#include <kiid.h>
38
39class BITMAP_BUTTON;
40class LIB_SYMBOL;
41class SCH_EDIT_FRAME;
42class WEBVIEW_PANEL;
43class wxChoice;
44class wxCommandEvent;
45class wxWebViewEvent;
47
48#define REMOTE_SYMBOL_SESSION_VERSION 1
49
50class PANEL_REMOTE_SYMBOL : public wxPanel
51{
52public:
53 explicit PANEL_REMOTE_SYMBOL( SCH_EDIT_FRAME* aParent );
54
55 void RefreshDataSources();
56 bool HasDataSources() const;
57 void BindWebViewLoaded();
58
59private:
60 void onDataSourceChanged( wxCommandEvent& aEvent );
61 void onConfigure( wxCommandEvent& aEvent );
62 void onRefresh( wxCommandEvent& aEvent );
63 void onWebViewLoaded( wxWebViewEvent& aEvent );
64 void onRemoteLoginResult( wxCommandEvent& aEvent );
65
66 bool loadDataSource( size_t aIndex );
67 bool loadDataSource( const PCM_INSTALLATION_ENTRY& aEntry );
68 std::optional<wxFileName> findDataSourceJson( const PCM_INSTALLATION_ENTRY& aEntry ) const;
69 void showMessage( const wxString& aMessage );
70 std::optional<wxString> extractUrlFromJson( const wxString& aJsonContent ) const;
71 void onKicadMessage( const wxString& aMessage );
72 void handleRpcMessage( const nlohmann::json& aMessage );
74 void handleRemoteLogin( const nlohmann::json& aParams, int aMessageId );
75 void stopLoginServer();
76 void storeUserIdForActiveSource( const wxString& aUserId );
78 wxString currentDataSourceKey() const;
79
80 void sendRpcMessage( const wxString& aCommand,
81 nlohmann::json aParameters = nlohmann::json::object(),
82 std::optional<int> aResponseTo = std::nullopt,
83 const wxString& aStatus = wxS( "OK" ),
84 const std::string& aData = std::string(),
85 const wxString& aErrorCode = wxEmptyString,
86 const wxString& aErrorMessage = wxEmptyString );
87
88 void respondWithError( const wxString& aCommand, int aResponseTo,
89 const wxString& aErrorCode, const wxString& aErrorMessage );
90
91 bool ensureDestinationRoot( wxFileName& aOutDir, wxString& aError ) const;
92 bool ensureSymbolLibraryEntry( const wxFileName& aLibraryFile, const wxString& aNickname,
93 bool aGlobalTable, wxString& aError ) const;
94 bool ensureFootprintLibraryEntry( const wxFileName& aLibraryDir, const wxString& aNickname,
95 bool aGlobalTable, wxString& aError ) const;
96 wxString sanitizedPrefix() const;
97
98 bool receiveFootprint( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
99 wxString& aError );
100 bool receiveSymbol( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
101 wxString& aError );
102 bool receive3DModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
103 wxString& aError );
104 bool receiveSPICEModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
105 wxString& aError );
106 bool receiveComponent( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
107 wxString& aError, nlohmann::json* aResponseParams = nullptr );
108 bool placeDownloadedSymbol( const wxString& aNickname, const wxString& aLibItemName,
109 wxString& aError );
110
111 wxString sanitizeFileComponent( const wxString& aComponent, const wxString& aDefault ) const;
112 wxString sanitizeForScript( const std::string& aJson ) const;
113
114 wxString jsonString( const nlohmann::json& aObject, const char* aKey ) const;
115 wxString normalizeDataSourceUrl( const wxString& aUrl ) const;
116
117 bool decodeBase64Payload( const std::string& aMessage,
118 std::vector<uint8_t>& aOutPayload,
119 wxString& aError ) const;
120
121 bool decompressIfNeeded( const std::string& aCompression,
122 const std::vector<uint8_t>& aInput,
123 std::vector<uint8_t>& aOutput,
124 wxString& aError ) const;
125
126 bool writeBinaryFile( const wxFileName& aFile,
127 const std::vector<uint8_t>& aData,
128 wxString& aError ) const;
129
130 std::unique_ptr<LIB_SYMBOL> loadSymbolFromPayload( const std::vector<uint8_t>& aPayload,
131 const wxString& aLibItemName,
132 wxString& aError ) const;
133
134private:
140 std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm;
141 std::vector<PCM_INSTALLATION_ENTRY> m_dataSources;
145 std::unique_ptr<REMOTE_LOGIN_SERVER> m_loginServer;
149};
150
151#endif // PANEL_REMOTE_SYMBOL_H
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition kiid.h:49
Define a library symbol object.
Definition lib_symbol.h:83
wxString sanitizeFileComponent(const wxString &aComponent, const wxString &aDefault) const
std::optional< wxString > extractUrlFromJson(const wxString &aJsonContent) const
void sendRpcMessage(const wxString &aCommand, nlohmann::json aParameters=nlohmann::json::object(), std::optional< int > aResponseTo=std::nullopt, const wxString &aStatus=wxS("OK"), const std::string &aData=std::string(), const wxString &aErrorCode=wxEmptyString, const wxString &aErrorMessage=wxEmptyString)
bool receiveSymbol(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
void onWebViewLoaded(wxWebViewEvent &aEvent)
void onKicadMessage(const wxString &aMessage)
void handleRemoteLogin(const nlohmann::json &aParams, int aMessageId)
wxString sanitizedPrefix() const
void showMessage(const wxString &aMessage)
wxString jsonString(const nlohmann::json &aObject, const char *aKey) const
bool writeBinaryFile(const wxFileName &aFile, const std::vector< uint8_t > &aData, wxString &aError) const
void handleRpcMessage(const nlohmann::json &aMessage)
std::vector< PCM_INSTALLATION_ENTRY > m_dataSources
bool receiveFootprint(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
bool ensureSymbolLibraryEntry(const wxFileName &aLibraryFile, const wxString &aNickname, bool aGlobalTable, wxString &aError) const
wxString currentDataSourceKey() const
void respondWithError(const wxString &aCommand, int aResponseTo, const wxString &aErrorCode, const wxString &aErrorMessage)
std::optional< wxFileName > findDataSourceJson(const PCM_INSTALLATION_ENTRY &aEntry) const
PANEL_REMOTE_SYMBOL(SCH_EDIT_FRAME *aParent)
bool decompressIfNeeded(const std::string &aCompression, const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput, wxString &aError) const
bool decodeBase64Payload(const std::string &aMessage, std::vector< uint8_t > &aOutPayload, wxString &aError) const
wxString sanitizeForScript(const std::string &aJson) const
std::unique_ptr< LIB_SYMBOL > loadSymbolFromPayload(const std::vector< uint8_t > &aPayload, const wxString &aLibItemName, wxString &aError) const
bool receiveComponent(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError, nlohmann::json *aResponseParams=nullptr)
void onConfigure(wxCommandEvent &aEvent)
bool ensureDestinationRoot(wxFileName &aOutDir, wxString &aError) const
wxString normalizeDataSourceUrl(const wxString &aUrl) const
bool loadDataSource(size_t aIndex)
void onRemoteLoginResult(wxCommandEvent &aEvent)
bool ensureFootprintLibraryEntry(const wxFileName &aLibraryDir, const wxString &aNickname, bool aGlobalTable, wxString &aError) const
bool receiveSPICEModel(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
BITMAP_BUTTON * m_configButton
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
bool receive3DModel(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
void storeUserIdForActiveSource(const wxString &aUserId)
BITMAP_BUTTON * m_refreshButton
std::unique_ptr< REMOTE_LOGIN_SERVER > m_loginServer
void onRefresh(wxCommandEvent &aEvent)
void onDataSourceChanged(wxCommandEvent &aEvent)
bool placeDownloadedSymbol(const wxString &aNickname, const wxString &aLibItemName, wxString &aError)
Schematic editor (Eeschema) main window.
Definition pcm_data.h:158