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 RefreshDataSources();
60 bool HasDataSources() const { return !m_providerEntries.empty(); }
61 void BindWebViewLoaded();
62 void SaveCookies();
63 void LoadCookies();
64
65private:
66 void onDataSourceChanged( wxCommandEvent& aEvent );
67 void onConfigure( wxCommandEvent& aEvent );
68 void onRefresh( wxCommandEvent& aEvent );
69 void onWebViewLoaded( wxWebViewEvent& aEvent );
70 void onDarkModeToggle( wxSysColourChangedEvent& aEvent );
71 void onOAuthLoopback( wxCommandEvent& aEvent );
72
73 bool loadProvider( int aIndex );
74 void loadProviderPage( const REMOTE_PROVIDER_METADATA& aMetadata, const wxString& aAccessToken );
76 const wxString& aAccessToken );
77 void showMessage( const wxString& aMessage );
78 void onKicadMessage( const wxString& aMessage );
79 void handleRpcMessage( const nlohmann::json& aMessage );
81 void sendRpcReply( const wxString& aCommand, int aResponseTo,
82 nlohmann::json aParameters = nlohmann::json::object() );
83 void sendRpcError( const wxString& aCommand, int aResponseTo, const wxString& aErrorCode,
84 const wxString& aErrorMessage );
85 void sendRpcNotification( const wxString& aCommand,
86 nlohmann::json aParameters = nlohmann::json::object() );
87 void sendRpcEnvelope( nlohmann::json aEnvelope );
88
89 bool startInteractiveLogin( const REMOTE_PROVIDER_ENTRY& aProvider,
90 const REMOTE_PROVIDER_METADATA& aMetadata, wxString& aError );
91 bool signOutProvider( const REMOTE_PROVIDER_ENTRY& aProvider, wxString& aError );
92 std::optional<OAUTH_TOKEN_SET> loadTokens( const REMOTE_PROVIDER_ENTRY& aProvider ) const;
93 wxString loadAccessToken( const REMOTE_PROVIDER_ENTRY& aProvider );
94 wxFileName cookieFilePath( const wxString& aProviderId ) const;
95 void clearCookies( bool aDeleteSavedCookieFile = true );
96
97 bool receiveComponent( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
98 bool aPlaceSymbol, wxString& aError );
99 bool receiveFootprint( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
100 wxString& aError );
101 bool receiveSymbol( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
102 wxString& aError );
103 bool receive3DModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
104 wxString& aError );
105 bool receiveSPICEModel( const nlohmann::json& aParams, const std::vector<uint8_t>& aPayload,
106 wxString& aError );
107 bool receiveComponentManifest( const nlohmann::json& aParams, bool aPlaceSymbol, wxString& aError );
108
109 wxString sanitizeForScript( const std::string& aJson ) const;
110 bool decodeBase64Payload( const std::string& aMessage, std::vector<uint8_t>& aOutPayload,
111 wxString& aError ) const;
112 bool decompressIfNeeded( const std::string& aCompression, const std::vector<uint8_t>& aInput,
113 std::vector<uint8_t>& aOutput, wxString& aError ) const;
114 std::unique_ptr<LIB_SYMBOL> loadSymbolFromPayload( const std::vector<uint8_t>& aPayload,
115 const wxString& aLibItemName,
116 wxString& aError ) const;
117private:
123 std::vector<REMOTE_PROVIDER_ENTRY> m_providerEntries;
132 std::unique_ptr<OAUTH_LOOPBACK_SERVER> m_oauthLoopbackServer;
136};
137
138#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
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.