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 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 <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PANEL_REMOTE_SYMBOL_H
21#define PANEL_REMOTE_SYMBOL_H
22
23#include <memory>
24#include <optional>
25#include <vector>
26
27#include <kiid.h>
29#include <oauth/oauth_session.h>
35#include <wx/filename.h>
36#include <wx/panel.h>
37
38#include <nlohmann/json_fwd.hpp>
39
40
41class BITMAP_BUTTON;
42class LIB_SYMBOL;
43class SCH_EDIT_FRAME;
44class WEBVIEW_PANEL;
45class wxChoice;
46class wxCommandEvent;
47class wxSysColourChangedEvent;
48class wxWebViewEvent;
49
50#define REMOTE_SYMBOL_SESSION_VERSION 1
51
52
53class PANEL_REMOTE_SYMBOL : public wxPanel
54{
55public:
56 explicit PANEL_REMOTE_SYMBOL( SCH_EDIT_FRAME* aParent );
57 ~PANEL_REMOTE_SYMBOL() override;
58
59 void Activate();
60 void RefreshDataSources();
61 bool HasDataSources() const { return !m_providerEntries.empty(); }
62 void BindWebViewLoaded();
63 void SaveCookies();
64 void LoadCookies();
65
66private:
67 void ensureWebView();
68 void onDataSourceChanged( wxCommandEvent& aEvent );
69 void onConfigure( wxCommandEvent& aEvent );
70 void onRefresh( wxCommandEvent& aEvent );
71 void onWebViewLoaded( wxWebViewEvent& aEvent );
72 void onDarkModeToggle( wxSysColourChangedEvent& aEvent );
73 void onOAuthLoopback( wxCommandEvent& aEvent );
74
75 bool loadProvider( int aIndex );
76 void loadProviderPage( const REMOTE_PROVIDER_METADATA& aMetadata, const wxString& aAccessToken );
78 const wxString& aAccessToken );
79 void showMessage( const wxString& aMessage );
80 void onKicadMessage( const wxString& aMessage );
81 void handleRpcMessage( const nlohmann::json& aMessage );
83 void sendRpcReply( const wxString& aCommand, int aResponseTo,
84 nlohmann::json aParameters = nlohmann::json::object() );
85 void sendRpcError( const wxString& aCommand, int aResponseTo, const wxString& aErrorCode,
86 const wxString& aErrorMessage );
87 void sendRpcNotification( const wxString& aCommand,
88 nlohmann::json aParameters = nlohmann::json::object() );
89 void sendRpcEnvelope( nlohmann::json aEnvelope );
90
91 bool startInteractiveLogin( const REMOTE_PROVIDER_ENTRY& aProvider,
92 const REMOTE_PROVIDER_METADATA& aMetadata, wxString& aError );
93 bool signOutProvider( const REMOTE_PROVIDER_ENTRY& aProvider, wxString& aError );
94 std::optional<OAUTH_TOKEN_SET> loadTokens( const REMOTE_PROVIDER_ENTRY& aProvider ) const;
95 wxString loadAccessToken( const REMOTE_PROVIDER_ENTRY& aProvider );
96 wxFileName cookieFilePath( const wxString& aProviderId ) const;
97 void clearCookies( bool aDeleteSavedCookieFile = true );
98
99 bool receiveComponent( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
100 bool aPlaceSymbol, wxString& aError );
101 bool receiveFootprint( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
102 wxString& aError );
103 bool receiveSymbol( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
104 wxString& aError );
105 bool receive3DModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
106 wxString& aError );
107 bool receiveSPICEModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
108 wxString& aError );
109 bool receiveComponentManifest( const nlohmann::json& aParams, bool aPlaceSymbol, wxString& aError );
110
111 wxString sanitizeForScript( const std::string& aJson ) const;
112 bool decodeBase64Payload( const std::string& aMessage, std::vector<uint8_t>& aOutPayload,
113 wxString& aError ) const;
114 bool decompressIfNeeded( const std::string& aCompression, const std::vector<uint8_t>& aInput,
115 std::vector<uint8_t>& aOutput, wxString& aError ) const;
116 std::unique_ptr<LIB_SYMBOL> loadSymbolFromPayload( const std::vector<uint8_t>& aPayload,
117 const wxString& aLibItemName,
118 wxString& aError ) const;
119private:
125 std::vector<REMOTE_PROVIDER_ENTRY> m_providerEntries;
134 std::unique_ptr<OAUTH_LOOPBACK_SERVER> m_oauthLoopbackServer;
138};
139
140#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:48
Define a library symbol object.
Definition lib_symbol.h:83
bool receiveSymbol(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
void onWebViewLoaded(wxWebViewEvent &aEvent)
void onKicadMessage(const wxString &aMessage)
void showMessage(const wxString &aMessage)
void handleRpcMessage(const nlohmann::json &aMessage)
wxFileName cookieFilePath(const wxString &aProviderId) const
void loadProviderPage(const REMOTE_PROVIDER_METADATA &aMetadata, const wxString &aAccessToken)
bool receiveFootprint(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
void sendRpcError(const wxString &aCommand, int aResponseTo, const wxString &aErrorCode, const wxString &aErrorMessage)
bool loadProvider(int aIndex)
bool signOutProvider(const REMOTE_PROVIDER_ENTRY &aProvider, wxString &aError)
OAUTH_SESSION m_pendingOAuthSession
bool receiveComponentManifest(const nlohmann::json &aParams, bool aPlaceSymbol, wxString &aError)
void sendRpcEnvelope(nlohmann::json aEnvelope)
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
REMOTE_PROVIDER_METADATA m_selectedProviderMetadata
bool decodeBase64Payload(const std::string &aMessage, std::vector< uint8_t > &aOutPayload, wxString &aError) const
void clearCookies(bool aDeleteSavedCookieFile=true)
wxString sanitizeForScript(const std::string &aJson) const
void onOAuthLoopback(wxCommandEvent &aEvent)
std::unique_ptr< LIB_SYMBOL > loadSymbolFromPayload(const std::vector< uint8_t > &aPayload, const wxString &aLibItemName, wxString &aError) const
void onConfigure(wxCommandEvent &aEvent)
bool receiveComponent(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, bool aPlaceSymbol, wxString &aError)
void sendRpcReply(const wxString &aCommand, int aResponseTo, nlohmann::json aParameters=nlohmann::json::object())
bool startInteractiveLogin(const REMOTE_PROVIDER_ENTRY &aProvider, const REMOTE_PROVIDER_METADATA &aMetadata, wxString &aError)
std::vector< REMOTE_PROVIDER_ENTRY > m_providerEntries
wxString loadAccessToken(const REMOTE_PROVIDER_ENTRY &aProvider)
void sendRpcNotification(const wxString &aCommand, nlohmann::json aParameters=nlohmann::json::object())
bool receiveSPICEModel(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
BITMAP_BUTTON * m_configButton
void onDarkModeToggle(wxSysColourChangedEvent &aEvent)
REMOTE_PROVIDER_CLIENT m_providerClient
SECURE_TOKEN_STORE m_tokenStore
bool receive3DModel(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError)
BITMAP_BUTTON * m_refreshButton
void onRefresh(wxCommandEvent &aEvent)
void bootstrapAuthenticatedSession(const REMOTE_PROVIDER_METADATA &aMetadata, const wxString &aAccessToken)
REMOTE_PROVIDER_OAUTH_SERVER_METADATA m_pendingOAuthMetadata
std::unique_ptr< OAUTH_LOOPBACK_SERVER > m_oauthLoopbackServer
std::optional< OAUTH_TOKEN_SET > loadTokens(const REMOTE_PROVIDER_ENTRY &aProvider) const
void onDataSourceChanged(wxCommandEvent &aEvent)
Schematic editor (Eeschema) main window.