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
42#define WX_EVENT_LOOP wxGUIEventLoop
43class WX_EVENT_LOOP;
44
45class wxSocketServer;
46class wxSocketBase;
47class wxSocketEvent;
48class wxCmdLineParser;
49
50
62#ifdef SWIG
63class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
64#else
66#endif
67{
68public:
69 KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
70 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
71 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale );
72
73 ~KIWAY_PLAYER() throw();
74
75 // For the aCtl argument of OpenProjectFiles()
76#define KICTL_NONKICAD_ONLY (1<<0)
77#define KICTL_KICAD_ONLY (1<<1)
78#define KICTL_CREATE (1<<2)
79#define KICTL_IMPORT_LIB (1<<3)
80#define KICTL_REVERT (1<<4)
81
115 virtual bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
116 {
117 // overload me for your wxFrame type.
118
119 // Any overload should probably do this also:
120 // Prj().MaybeLoadProjectSettings();
121
122 // Then update the window title.
123
124 return false;
125 }
126
127
141 virtual bool ShowModal( wxString* aResult = nullptr,
142 wxWindow* aResultantFocusWindow = nullptr );
143
149 virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
150
154 bool Destroy() override;
155
156 bool IsModal() const override { return m_modal; }
157 void SetModal( bool aIsModal ) { m_modal = aIsModal; }
158
164 bool IsDismissed();
165
166 void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
167
168 /* interprocess communication */
169 void CreateServer( int service, bool local = true );
170 void OnSockRequest( wxSocketEvent& evt );
171 void OnSockRequestServer( wxSocketEvent& evt );
172
179 virtual void ExecuteRemoteCommand( const char* cmdline ){}
180
181protected:
182
184 void kiway_express( KIWAY_EXPRESS& aEvent );
185
189 void language_change( wxCommandEvent& event );
190
191 // variables for modal behavior support, only used by a few derivatives.
192 bool m_modal; // true if frame is intended to be modal, not modeless
193
196 wxWindow* m_modal_resultant_parent; // the window caller in modal mode
198 bool m_modal_ret_val; // true if a selection was made
199
200 wxSocketServer* m_socketServer;
201 std::vector<wxSocketBase*> m_sockets;
202
203#ifndef SWIG
204 DECLARE_EVENT_TABLE()
205#endif
206};
207
208
209// pseudo code for OpenProjectFiles
210#if 0
211
212bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
213{
214 if( aFileList.size() != 1 )
215 {
216 complain via UI.
217 return false
218 }
219
220 assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
221
222 if( !Pgm().LockFile( fullFileName ) )
223 {
224 DisplayError( this, _( "This file is already open." ) );
225 return false;
226 }
227
228 if current open project files have been modified
229 {
230 ask if user wants to save them and if yes save.
231 }
232
233 unload any currently open project files.
234
235 Prj().SetProjectFullName( )
236
237 if( aFileList[0] does not exist )
238 {
239 notify user file does not exist and ask if he wants to create it
240 if( yes )
241 {
242 create empty project file(s)
243 mark file as modified.
244
245 use the default project config file.
246 }
247 else
248 return false
249 }
250 else
251 {
252 load aFileList[0]
253
254 use the project config file for project given by aFileList[0]s full path.
255 }
256
257 UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
258
259 /* done in ReDraw typically:
260 UpdateTitle();
261 */
262
263 show contents.
264}
265
266#endif
267
268#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:67
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:197
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Receive KIWAY_EXPRESS messages from other players.
WX_EVENT_LOOP * m_modal_loop
< Points to nested event_loop. NULL means not modal and dismissed.
Definition: kiway_player.h:195
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:179
void language_change(wxCommandEvent &event)
An event handler called on a language menu selection.
bool m_modal_ret_val
Definition: kiway_player.h:198
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:196
void SetModal(bool aIsModal)
Definition: kiway_player.h:157
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:115
std::vector< wxSocketBase * > m_sockets
interprocess communication
Definition: kiway_player.h:201
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:156
wxSocketServer * m_socketServer
Definition: kiway_player.h:200
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
Container for project specific data.
Definition: project.h:62
const wxString & GetFileName() const
Definition: sch_screen.h:144
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
Master controller class:
Definition: tool_manager.h:57
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
Base window classes and related definitions.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:70
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
#define WX_EVENT_LOOP
Definition: kiway_player.h:42
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151