KiCad PCB EDA Suite
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-2020 KiCad Developers, see change_log.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef KIWAY_PLAYER_H_
26#define KIWAY_PLAYER_H_
27
28#include <wx/frame.h>
29
30#include <vector>
31#include <kiway_holder.h>
32#include <eda_base_frame.h>
33
34class KIWAY;
35class PROJECT;
36struct KIFACE;
37class KIFACE_BASE;
38class TOOL_MANAGER;
39class KIWAY_EXPRESS;
40
41#define WX_EVENT_LOOP wxGUIEventLoop
42class WX_EVENT_LOOP;
43
44class wxSocketServer;
45class wxSocketBase;
46class wxSocketEvent;
47class wxCmdLineParser;
48
49
61#ifdef SWIG
62class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
63#else
65#endif
66{
67public:
68 KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
69 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
70 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale );
71
74 KIWAY_PLAYER( wxWindow* aParent, wxWindowID aId, const wxString& aTitle,
75 const wxPoint& aPos, const wxSize& aSize, long aStyle,
76 const wxString& aWdoName = wxFrameNameStr );
77
78 ~KIWAY_PLAYER() throw();
79
80 // For the aCtl argument of OpenProjectFiles()
81#define KICTL_EAGLE_BRD (1<<0)
82#define KICTL_CREATE (1<<1)
83#define KICTL_IMPORT_LIB (1<<2)
84
118 virtual bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
119 {
120 // overload me for your wxFrame type.
121
122 // Any overload should probably do this also:
123 // Prj().MaybeLoadProjectSettings();
124
125 // Then update the window title.
126
127 return false;
128 }
129
130
144 virtual bool ShowModal( wxString* aResult = nullptr,
145 wxWindow* aResultantFocusWindow = nullptr );
146
152 virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
153
157 bool Destroy() override;
158
159 bool IsModal() const override { return m_modal; }
160 void SetModal( bool aIsModal ) { m_modal = aIsModal; }
161
167 bool IsDismissed();
168
169 void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
170
171 /* interprocess communication */
172 void CreateServer( int service, bool local = true );
173 void OnSockRequest( wxSocketEvent& evt );
174 void OnSockRequestServer( wxSocketEvent& evt );
175
182 virtual void ExecuteRemoteCommand( const char* cmdline ){}
183
184
185protected:
186
188 void kiway_express( KIWAY_EXPRESS& aEvent );
189
193 void language_change( wxCommandEvent& event );
194
195 // variables for modal behavior support, only used by a few derivatives.
196 bool m_modal; // true if frame is intended to be modal, not modeless
197
200 wxWindow* m_modal_resultant_parent; // the window caller in modal mode
202 bool m_modal_ret_val; // true if a selection was made
203
204 wxSocketServer* m_socketServer;
205 std::vector<wxSocketBase*> m_sockets;
206
207#ifndef SWIG
208 DECLARE_EVENT_TABLE()
209#endif
210};
211
212
213// pseudo code for OpenProjectFiles
214#if 0
215
216bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
217{
218 if( aFileList.size() != 1 )
219 {
220 complain via UI.
221 return false
222 }
223
224 assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
225
226 if( !Pgm().LockFile( fullFileName ) )
227 {
228 DisplayError( this, _( "This file is already open." ) );
229 return false;
230 }
231
232 if current open project files have been modified
233 {
234 ask if user wants to save them and if yes save.
235 }
236
237 unload any currently open project files.
238
239 Prj().SetProjectFullName( )
240
241 if( aFileList[0] does not exist )
242 {
243 notify user file does not exist and ask if he wants to create it
244 if( yes )
245 {
246 create empty project file(s)
247 mark file as modified.
248
249 use the default project config file.
250 }
251 else
252 return false
253 }
254 else
255 {
256 load aFileList[0]
257
258 use the project config file for project given by aFileList[0]s full path.
259 }
260
261 UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
262
263 /* done in ReDraw typically:
264 UpdateTitle();
265 */
266
267 show contents.
268}
269
270#endif
271
272#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:39
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:37
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
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:201
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:199
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:182
void language_change(wxCommandEvent &event)
An event handler called on a language menu selection.
bool m_modal_ret_val
Definition: kiway_player.h:202
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:200
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
void SetModal(bool aIsModal)
Definition: kiway_player.h:160
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:118
std::vector< wxSocketBase * > m_sockets
interprocess communication
Definition: kiway_player.h:205
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:159
wxSocketServer * m_socketServer
Definition: kiway_player.h:204
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:273
Container for project specific data.
Definition: project.h:63
const wxString & GetFileName() const
Definition: sch_screen.h:144
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:104
Master controller class:
Definition: tool_manager.h:55
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:65
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:556
#define WX_EVENT_LOOP
Definition: kiway_player.h:41
std::unique_ptr< wxSingleInstanceChecker > LockFile(const wxString &aFileName)
Test to see if aFileName can be locked (is not already locked) and only then returns a wxSingleInstan...
Definition: lockfile.cpp:34
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151