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>
28#include <lib_id.h>
30#include <oauth/oauth_session.h>
36#include <wx/filename.h>
37#include <wx/panel.h>
38
39#include <nlohmann/json_fwd.hpp>
40
41
42class BITMAP_BUTTON;
43class LIB_SYMBOL;
44class SCH_EDIT_FRAME;
45class WEBVIEW_PANEL;
46class wxChoice;
47class wxCommandEvent;
48class wxSysColourChangedEvent;
49class wxWebViewEvent;
50
51#define REMOTE_SYMBOL_SESSION_VERSION 1
52
53
54class PANEL_REMOTE_SYMBOL : public wxPanel
55{
56public:
57 explicit PANEL_REMOTE_SYMBOL( SCH_EDIT_FRAME* aParent );
58 ~PANEL_REMOTE_SYMBOL() override;
59
60 void Activate();
61 void RefreshDataSources();
62 bool HasDataSources() const { return !m_providerEntries.empty(); }
63 void BindWebViewLoaded();
64 void SaveCookies();
65 void LoadCookies();
66
67private:
68 void ensureWebView();
69 void onDataSourceChanged( wxCommandEvent& aEvent );
70 void onConfigure( wxCommandEvent& aEvent );
71 void onRefresh( wxCommandEvent& aEvent );
72 void onWebViewLoaded( wxWebViewEvent& aEvent );
73 void onDarkModeToggle( wxSysColourChangedEvent& aEvent );
74 void onOAuthLoopback( wxCommandEvent& aEvent );
75
76 bool loadProvider( int aIndex );
77 void loadProviderPage( const REMOTE_PROVIDER_METADATA& aMetadata, const wxString& aAccessToken );
79 const wxString& aAccessToken );
80 void showMessage( const wxString& aMessage );
81 void onKicadMessage( const wxString& aMessage );
82 void handleRpcMessage( const nlohmann::json& aMessage );
84 void sendRpcReply( const wxString& aCommand, int aResponseTo,
85 nlohmann::json aParameters = nlohmann::json::object() );
86 void sendRpcError( const wxString& aCommand, int aResponseTo, const wxString& aErrorCode,
87 const wxString& aErrorMessage );
88 void sendRpcNotification( const wxString& aCommand,
89 nlohmann::json aParameters = nlohmann::json::object() );
90 void sendRpcEnvelope( nlohmann::json aEnvelope );
91
92 bool startInteractiveLogin( const REMOTE_PROVIDER_ENTRY& aProvider,
93 const REMOTE_PROVIDER_METADATA& aMetadata, wxString& aError );
94 bool signOutProvider( const REMOTE_PROVIDER_ENTRY& aProvider, wxString& aError );
95 std::optional<OAUTH_TOKEN_SET> loadTokens( const REMOTE_PROVIDER_ENTRY& aProvider ) const;
96 wxString loadAccessToken( const REMOTE_PROVIDER_ENTRY& aProvider );
97 wxFileName cookieFilePath( const wxString& aProviderId ) const;
98 void clearCookies( bool aDeleteSavedCookieFile = true );
99
100 bool receiveComponent( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
101 bool aPlaceSymbol, wxString& aError );
102 bool receiveFootprint( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
103 wxString& aError, LIB_ID* aOutLibId = nullptr );
104 bool receiveSymbol( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
105 wxString& aError,
106 const std::vector<LIB_ID>& aFootprintLinks = {} );
107 bool receive3DModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
108 wxString& aError );
109 bool receiveSPICEModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
110 wxString& aError );
111 bool receiveComponentManifest( const nlohmann::json& aParams, bool aPlaceSymbol, wxString& aError );
112
113 wxString sanitizeForScript( const std::string& aJson ) const;
114 bool decodeBase64Payload( const std::string& aMessage, std::vector<uint8_t>& aOutPayload,
115 wxString& aError ) const;
116 bool decompressIfNeeded( const std::string& aCompression, const std::vector<uint8_t>& aInput,
117 std::vector<uint8_t>& aOutput, wxString& aError ) const;
118private:
124 std::vector<REMOTE_PROVIDER_ENTRY> m_providerEntries;
133 std::unique_ptr<OAUTH_LOOPBACK_SERVER> m_oauthLoopbackServer;
137};
138
139#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
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
Define a library symbol object.
Definition lib_symbol.h:83
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)
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)
bool receiveFootprint(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError, LIB_ID *aOutLibId=nullptr)
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
bool receiveSymbol(const nlohmann::json &aParams, const std::vector< uint8_t > &aPayload, wxString &aError, const std::vector< LIB_ID > &aFootprintLinks={})
void onOAuthLoopback(wxCommandEvent &aEvent)
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.