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 <eda_base_frame.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 
182 
198  VTBL_ENTRY bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL );
199 
200  //----</Cross Module API>----------------------------------------------------
201 
202 
208  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
209 
213  bool Destroy() override;
214 
215 protected:
216 
217  bool IsModal() { return m_modal; }
218  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
219 
226  bool IsDismissed();
227 
228  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
229 
231  void kiway_express( KIWAY_EXPRESS& aEvent );
232 
237  void language_change( wxCommandEvent& event );
238 
244  void OnChangeIconsOptions( wxCommandEvent& event ) override;
245 
246  // variables for modal behavior support, only used by a few derivatives.
247  bool m_modal; // true if frame is intended to be modal, not modeless
248  WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
249  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
250  wxString m_modal_string;
251  bool m_modal_ret_val; // true if a selection was made
252 
253 #ifndef SWIG
254  DECLARE_EVENT_TABLE()
255 #endif
256 };
257 
258 
259 // psuedo code for OpenProjectFiles
260 #if 0
261 
262 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
263 {
264  if( aFileList.size() != 1 )
265  {
266  complain via UI.
267  return false
268  }
269 
270  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
271 
272  if( !Pgm().LockFile( fullFileName ) )
273  {
274  DisplayError( this, _( "This file is already open." ) );
275  return false;
276  }
277 
278  if current open project files have been modified
279  {
280  ask if user wants to save them and if yes save.
281  }
282 
283  unload any currently open project files.
284 
286 
287  if( aFileList[0] does not exist )
288  {
289  notify user file does not exist and ask if he wants to create it
290  if( yes )
291  {
292  create empty project file(s)
293  mark file as modified.
294 
295  use the default project config file.
296  }
297  else
298  return false
299  }
300  else
301  {
302  load aFileList[0]
303 
304  use the project config file for project given by aFileList[0]s full path.
305  }
306 
307  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
308 
309  /* done in ReDraw typically:
310  UpdateTitle();
311  */
312 
313  show contents.
314 }
315 
316 
317 
318 #endif
319 
320 
321 
322 
323 #endif // KIWAY_PLAYER_H_
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow&#39;s KIWAY.
Definition: kiway_player.h:48
bool m_modal_ret_val
Definition: kiway_player.h:251
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:249
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:56
wxString m_modal_string
Definition: kiway_player.h:250
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
const wxString & GetFileName() const
Definition: sch_screen.h:120
KIWAY * m_kiway
Definition: kiway_player.h:85
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
#define VTBL_ENTRY
Definition: kiway_player.h:38
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
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.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
KIWAY_HOLDER(KIWAY *aKiway)
Definition: kiway_player.h:51
std::unique_ptr< 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:32
Base window classes and related definitions.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool IsModal()
Definition: kiway_player.h:217
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:218
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
WX_EVENT_LOOP * m_modal_loop
Definition: kiway_player.h:248
static bool empty(const wxTextEntryBase *aCtrl)
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185