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 <dick@softplc.com>
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 
34 class KIWAY;
35 class PROJECT;
36 struct KIFACE;
37 class KIFACE_I;
38 class TOOL_MANAGER;
39 class KIWAY_EXPRESS;
40 
41 #define WX_EVENT_LOOP wxGUIEventLoop
42 class WX_EVENT_LOOP;
43 
44 class wxSocketServer;
45 class wxSocketBase;
46 class wxSocketEvent;
47 class wxCmdLineParser;
48 
49 
61 #ifdef SWIG
62 class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
63 #else
65 #endif
66 {
67 public:
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& aWdoName = wxFrameNameStr );
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 
85 
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 
139  virtual void ParseArgs( wxCmdLineParser& aParser )
140  {
141  WXUNUSED( aParser );
142  }
143 
144 
158  virtual bool ShowModal( wxString* aResult = nullptr,
159  wxWindow* aResultantFocusWindow = nullptr );
160 
166  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
167 
171  bool Destroy() override;
172 
173  bool IsModal() const override { return m_modal; }
174  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
175 
181  bool IsDismissed();
182 
183  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
184 
185  /* interprocess communication */
186  void CreateServer( int service, bool local = true );
187  void OnSockRequest( wxSocketEvent& evt );
188  void OnSockRequestServer( wxSocketEvent& evt );
189 
196  virtual void ExecuteRemoteCommand( const char* cmdline ){}
197 
198 
199 protected:
200 
202  void kiway_express( KIWAY_EXPRESS& aEvent );
203 
207  void language_change( wxCommandEvent& event );
208 
209  // variables for modal behavior support, only used by a few derivatives.
210  bool m_modal; // true if frame is intended to be modal, not modeless
211 
214  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
215  wxString m_modal_string;
216  bool m_modal_ret_val; // true if a selection was made
217 
218  wxSocketServer* m_socketServer;
219  std::vector<wxSocketBase*> m_sockets;
220 
221 #ifndef SWIG
222  DECLARE_EVENT_TABLE()
223 #endif
224 };
225 
226 
227 // pseudo code for OpenProjectFiles
228 #if 0
229 
230 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
231 {
232  if( aFileList.size() != 1 )
233  {
234  complain via UI.
235  return false
236  }
237 
238  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
239 
240  if( !Pgm().LockFile( fullFileName ) )
241  {
242  DisplayError( this, _( "This file is already open." ) );
243  return false;
244  }
245 
246  if current open project files have been modified
247  {
248  ask if user wants to save them and if yes save.
249  }
250 
251  unload any currently open project files.
252 
253  Prj().SetProjectFullName( )
254 
255  if( aFileList[0] does not exist )
256  {
257  notify user file does not exist and ask if he wants to create it
258  if( yes )
259  {
260  create empty project file(s)
261  mark file as modified.
262 
263  use the default project config file.
264  }
265  else
266  return false
267  }
268  else
269  {
270  load aFileList[0]
271 
272  use the project config file for project given by aFileList[0]s full path.
273  }
274 
275  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
276 
277  /* done in ReDraw typically:
278  UpdateTitle();
279  */
280 
281  show contents.
282 }
283 
284 #endif
285 
286 #endif // KIWAY_PLAYER_H_
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...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
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
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:36
bool m_modal_ret_val
Definition: kiway_player.h:216
A KIFACE (I)mplementation.
Definition: kiface_i.h:37
const wxString & GetFileName() const
Definition: sch_screen.h:137
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:38
#define WX_EVENT_LOOP
Definition: kiway_player.h:41
wxWindow * m_modal_resultant_parent
Definition: kiway_player.h:214
Container for project specific data.
Definition: project.h:62
wxString m_modal_string
Definition: kiway_player.h:215
bool IsDismissed()
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aWdoName=wxFrameNameStr)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
PROJECT & Prj()
Definition: kicad.cpp:403
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:49
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
Master controller class:
Definition: tool_manager.h:54
void language_change(wxCommandEvent &event)
An event handler called on a language menu selection.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:53
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:196
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:71
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
Base window classes and related definitions.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:258
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Receive KIWAY_EXPRESS messages from other players.
#define _(s)
void kiway_express(KIWAY_EXPRESS &aEvent)
event handler, routes to derivative specific virtual KiwayMailIn()
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:173
void SetModal(bool aIsModal)
Definition: kiway_player.h:174
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:103
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
The base frame for deriving all KiCad main window classes.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:146
WX_EVENT_LOOP * m_modal_loop
< Points to nested event_loop. NULL means not modal and dismissed.
Definition: kiway_player.h:213
static bool empty(const wxTextEntryBase *aCtrl)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
wxSocketServer * m_socketServer
Definition: kiway_player.h:218
std::vector< wxSocketBase * > m_sockets
interprocess communication
Definition: kiway_player.h:219
virtual void ParseArgs(wxCmdLineParser &aParser)
Handle command-line arguments in a frame-specific way.
Definition: kiway_player.h:139