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 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 #include <vector>
30 #include <wxstruct.h>
31 
32 
33 class KIWAY;
34 class PROJECT;
35 struct KIFACE;
36 class KIFACE_I;
37 
38 #define VTBL_ENTRY virtual
39 
40 
49 {
50 public:
51  KIWAY_HOLDER( KIWAY* aKiway ) :
52  m_kiway( aKiway )
53  {}
54 
60  KIWAY& Kiway() const
61  {
62  wxASSERT( m_kiway ); // smoke out bugs in Debug build, then Release runs fine.
63  return *m_kiway;
64  }
65 
70  PROJECT& Prj() const;
71 
81  void SetKiway( wxWindow* aDest, KIWAY* aKiway );
82 
83 private:
84  // private, all setting is done through SetKiway().
85  KIWAY* m_kiway; // no ownership.
86 };
87 
88 
89 class KIWAY_EXPRESS;
90 
91 #define WX_EVENT_LOOP wxGUIEventLoop
92 
93 
94 class WX_EVENT_LOOP;
95 
96 
108 #ifdef SWIG
109 class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
110 #else
112 #endif
113 {
114 public:
115  KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
116  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
117  long aStyle, const wxString& aWdoName = wxFrameNameStr );
118 
121  KIWAY_PLAYER( wxWindow* aParent, wxWindowID aId, const wxString& aTitle,
122  const wxPoint& aPos, const wxSize& aSize, long aStyle,
123  const wxString& aWdoName = wxFrameNameStr );
124 
125  ~KIWAY_PLAYER() throw();
126 
127  //----<Cross Module API>-----------------------------------------------------
128 
129  // For the aCtl argument of OpenProjectFiles()
130 #define KICTL_EAGLE_BRD (1<<0)
131 #define KICTL_CREATE (1<<1)
132 
133 
170  VTBL_ENTRY bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
171  {
172  // overload me for your wxFrame type.
173 
174  // Any overload should probably do this also:
175  // Prj().MaybeLoadProjectSettings();
176 
177  // Then update the window title.
178 
179  return false;
180  }
181 
197  VTBL_ENTRY bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL );
198 
199  //----</Cross Module API>----------------------------------------------------
200 
201 
207  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
208 
212  bool Destroy() override;
213 
214 protected:
215 
216  bool IsModal() { return m_modal; }
217  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
218 
225  bool IsDismissed();
226 
227  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
228 
230  void kiway_express( KIWAY_EXPRESS& aEvent );
231 
236  void language_change( wxCommandEvent& event );
237 
243  void OnChangeIconsOptions( wxCommandEvent& event ) override;
244 
245  // variables for modal behavior support, only used by a few derivatives.
246  bool m_modal; // true if frame is intended to be modal, not modeless
247  WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
248  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
249  wxString m_modal_string;
250  bool m_modal_ret_val; // true if a selection was made
251 
252 #ifndef SWIG
253  DECLARE_EVENT_TABLE()
254 #endif
255 };
256 
257 
258 // psuedo code for OpenProjectFiles
259 #if 0
260 
261 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
262 {
263  if( aFileList.size() != 1 )
264  {
265  complain via UI.
266  return false
267  }
268 
269  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
270 
271  if( !Pgm().LockFile( fullFileName ) )
272  {
273  DisplayError( this, _( "This file is already open." ) );
274  return false;
275  }
276 
277  if current open project files have been modified
278  {
279  ask if user wants to save them and if yes save.
280  }
281 
282  unload any currently open project files.
283 
285 
286  if( aFileList[0] does not exist )
287  {
288  notify user file does not exist and ask if he wants to create it
289  if( yes )
290  {
291  create empty project file(s)
292  mark file as modified.
293 
294  use the default project config file.
295  }
296  else
297  return false
298  }
299  else
300  {
301  load aFileList[0]
302 
303  use the project config file for project given by aFileList[0]s full path.
304  }
305 
306  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
307 
308  /* done in ReDraw typically:
309  UpdateTitle();
310  */
311 
312  show contents.
313 }
314 
315 
316 
317 #endif
318 
319 
320 
321 
322 #endif // KIWAY_PLAYER_H_
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_player.h:48
bool m_modal_ret_val
Definition: kiway_player.h:250
Class KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIF...
Definition: kiface_i.h:37
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
Function SetKiway.
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
#define WX_EVENT_LOOP
Definition: kiway_player.h:91
wxWindow * m_modal_resultant_parent
Definition: kiway_player.h:248
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
Class PROJECT holds project specific data.
Definition: project.h:51
wxString m_modal_string
Definition: kiway_player.h:249
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
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
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
PROJECT & Prj()
Definition: kicad.cpp:291
const wxString & GetFileName() const
KIWAY * m_kiway
Definition: kiway_player.h:85
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:63
#define VTBL_ENTRY
Definition: kiway_player.h:38
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
VTBL_ENTRY bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList...
Definition: kiway_player.h:170
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void language_change(wxCommandEvent &event)
Function language_change is an event handler called on a language menu selection. ...
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
wxSingleInstanceChecker * LockFile(const wxString &aFileName)
Function LockFile tests to see if aFileName can be locked (is not already locked) and only then retur...
Definition: lockfile.cpp:30
Base window classes and related definitions.
KIWAY_HOLDER(KIWAY *aKiway)
Definition: kiway_player.h:51
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
void kiway_express(KIWAY_EXPRESS &aEvent)
event handler, routes to derivative specific virtual KiwayMailIn()
bool IsModal()
Definition: kiway_player.h:216
VTBL_ENTRY void SetProjectFullName(const wxString &aFullPathAndName)
Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project...
Definition: project.cpp:64
void SetModal(bool aIsModal)
Definition: kiway_player.h:217
void OnChangeIconsOptions(wxCommandEvent &event) override
Function OnChangeIconsOptions is an event handler called on a icons options in menus or toolbars menu...
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:112
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
WX_EVENT_LOOP * m_modal_loop
Definition: kiway_player.h:247
static bool empty(const wxTextEntryBase *aCtrl)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
VTBL_ENTRY bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...