KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kiway_player.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 (C) 2014 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2017-2023 KiCad Developers, see change_log.txt for contributors.
6 * Copyright (C) 2023 CERN (www.cern.ch)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef KIWAY_PLAYER_H_
27#define KIWAY_PLAYER_H_
28
29#include <wx/frame.h>
30
31#include <vector>
32#include <kiway_holder.h>
33#include <eda_base_frame.h>
34
35class KIWAY;
36class PROJECT;
37struct KIFACE;
38class KIFACE_BASE;
39class TOOL_MANAGER;
40class KIWAY_EXPRESS;
41
42class wxGUIEventLoop;
43class wxSocketServer;
44class wxSocketBase;
45class wxSocketEvent;
46class wxCmdLineParser;
47
48
60#ifdef SWIG
61class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
62#else
64#endif
65{
66public:
67 KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
68 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
69 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale );
70
71 ~KIWAY_PLAYER() throw();
72
73 // For the aCtl argument of OpenProjectFiles()
74#define KICTL_NONKICAD_ONLY (1<<0)
75#define KICTL_KICAD_ONLY (1<<1)
76#define KICTL_CREATE (1<<2)
77#define KICTL_IMPORT_LIB (1<<3)
78#define KICTL_REVERT (1<<4)
79
113 virtual bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
114 {
115 // overload me for your wxFrame type.
116
117 // Any overload should probably do this also:
118 // Prj().MaybeLoadProjectSettings();
119
120 // Then update the window title.
121
122 return false;
123 }
124
125
139 virtual bool ShowModal( wxString* aResult = nullptr,
140 wxWindow* aResultantFocusWindow = nullptr );
141
147 virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
148
152 bool Destroy() override;
153
154 bool IsModal() const override { return m_modal; }
155 void SetModal( bool aIsModal ) { m_modal = aIsModal; }
156
162 bool IsDismissed();
163
164 void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
165
166 /* interprocess communication */
167 void CreateServer( int service, bool local = true );
168 void OnSockRequest( wxSocketEvent& evt );
169 void OnSockRequestServer( wxSocketEvent& evt );
170
177 virtual void ExecuteRemoteCommand( const char* cmdline ){}
178
179protected:
180
182 void kiway_express( KIWAY_EXPRESS& aEvent );
183
187 void language_change( wxCommandEvent& event );
188
189 // variables for modal behavior support, only used by a few derivatives.
190 bool m_modal; // true if frame is intended to be modal, not modeless
191
193 wxGUIEventLoop* m_modal_loop;
194 wxWindow* m_modal_resultant_parent; // the window caller in modal mode
196 bool m_modal_ret_val; // true if a selection was made
197
198 wxSocketServer* m_socketServer;
199 std::vector<wxSocketBase*> m_sockets;
200
201#ifndef SWIG
202 DECLARE_EVENT_TABLE()
203#endif
204};
205
206
207// pseudo code for OpenProjectFiles
208#if 0
209
210bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
211{
212 if( aFileList.size() != 1 )
213 {
214 complain via UI.
215 return false
216 }
217
218 assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
219
220 if( !Pgm().LockFile( fullFileName ) )
221 {
222 DisplayError( this, _( "This file is already open." ) );
223 return false;
224 }
225
226 if current open project files have been modified
227 {
228 ask if user wants to save them and if yes save.
229 }
230
231 unload any currently open project files.
232
233 Prj().SetProjectFullName( )
234
235 if( aFileList[0] does not exist )
236 {
237 notify user file does not exist and ask if he wants to create it
238 if( yes )
239 {
240 create empty project file(s)
241 mark file as modified.
242
243 use the default project config file.
244 }
245 else
246 return false
247 }
248 else
249 {
250 load aFileList[0]
251
252 use the project config file for project given by aFileList[0]s full path.
253 }
254
255 UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
256
257 /* done in ReDraw typically:
258 UpdateTitle();
259 */
260
261 show contents.
262}
263
264#endif
265
266#endif // KIWAY_PLAYER_H_
The base frame for deriving all KiCad main window classes.
A KIFACE implementation.
Definition: kiface_base.h:39
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:40
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool IsDismissed()
wxString m_modal_string
Definition: kiway_player.h:195
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Receive KIWAY_EXPRESS messages from other players.
virtual void ExecuteRemoteCommand(const char *cmdline)
Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER, currently 4242).
Definition: kiway_player.h:177
void language_change(wxCommandEvent &event)
An event handler called on a language menu selection.
bool m_modal_ret_val
Definition: kiway_player.h:196
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:43
void kiway_express(KIWAY_EXPRESS &aEvent)
event handler, routes to derivative specific virtual KiwayMailIn()
wxWindow * m_modal_resultant_parent
Definition: kiway_player.h:194
void SetModal(bool aIsModal)
Definition: kiway_player.h:155
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:113
wxGUIEventLoop * m_modal_loop
< Points to nested event_loop. NULL means not modal and dismissed.
Definition: kiway_player.h:193
std::vector< wxSocketBase * > m_sockets
interprocess communication
Definition: kiway_player.h:199
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:99
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:69
bool IsModal() const override
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Definition: kiway_player.h:154
wxSocketServer * m_socketServer
Definition: kiway_player.h:198
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
Container for project specific data.
Definition: project.h:64
const wxString & GetFileName() const
Definition: sch_screen.h:143
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
Master controller class:
Definition: tool_manager.h:62
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
Base window classes and related definitions.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:73
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
PROJECT & Prj()
Definition: kicad.cpp:595
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151