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 <kiway_holder.h>
31 #include <eda_base_frame.h>
32 
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 
56 #ifdef SWIG
57 class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
58 #else
60 #endif
61 {
62 public:
63  KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
64  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
65  long aStyle, const wxString& aWdoName = wxFrameNameStr );
66 
69  KIWAY_PLAYER( wxWindow* aParent, wxWindowID aId, const wxString& aTitle,
70  const wxPoint& aPos, const wxSize& aSize, long aStyle,
71  const wxString& aWdoName = wxFrameNameStr );
72 
73  ~KIWAY_PLAYER() throw();
74 
75  //----<Cross Module API>-----------------------------------------------------
76 
77  // For the aCtl argument of OpenProjectFiles()
78 #define KICTL_EAGLE_BRD (1<<0)
79 #define KICTL_CREATE (1<<1)
80 
81 
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 
146  virtual bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL );
147 
148  //----</Cross Module API>----------------------------------------------------
149 
150 
156  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
157 
161  bool Destroy() override;
162 
163  bool IsModal() { return m_modal; }
164  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
165 
172  bool IsDismissed();
173 
174  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
175 
176 protected:
177 
179  void kiway_express( KIWAY_EXPRESS& aEvent );
180 
185  void language_change( wxCommandEvent& event );
186 
187  // variables for modal behavior support, only used by a few derivatives.
188  bool m_modal; // true if frame is intended to be modal, not modeless
189  WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
190  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
191  wxString m_modal_string;
192  bool m_modal_ret_val; // true if a selection was made
193 
194 #ifndef SWIG
195  DECLARE_EVENT_TABLE()
196 #endif
197 };
198 
199 
200 // psuedo code for OpenProjectFiles
201 #if 0
202 
203 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
204 {
205  if( aFileList.size() != 1 )
206  {
207  complain via UI.
208  return false
209  }
210 
211  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
212 
213  if( !Pgm().LockFile( fullFileName ) )
214  {
215  DisplayError( this, _( "This file is already open." ) );
216  return false;
217  }
218 
219  if current open project files have been modified
220  {
221  ask if user wants to save them and if yes save.
222  }
223 
224  unload any currently open project files.
225 
227 
228  if( aFileList[0] does not exist )
229  {
230  notify user file does not exist and ask if he wants to create it
231  if( yes )
232  {
233  create empty project file(s)
234  mark file as modified.
235 
236  use the default project config file.
237  }
238  else
239  return false
240  }
241  else
242  {
243  load aFileList[0]
244 
245  use the project config file for project given by aFileList[0]s full path.
246  }
247 
248  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
249 
250  /* done in ReDraw typically:
251  UpdateTitle();
252  */
253 
254  show contents.
255 }
256 
257 
258 
259 #endif
260 
261 
262 
263 
264 #endif // KIWAY_PLAYER_H_
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
virtual 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:118
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
bool m_modal_ret_val
Definition: kiway_player.h:192
Class KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIF...
Definition: kiface_i.h:37
const wxString & GetFileName() const
Definition: sch_screen.h:123
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
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:41
wxWindow * m_modal_resultant_parent
Definition: kiway_player.h:190
Class PROJECT holds project specific data.
Definition: project.h:58
wxString m_modal_string
Definition: kiway_player.h:191
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:303
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:281
Class TOOL_MANAGER.
Definition: tool_manager.h:50
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:47
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:274
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:163
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
#define _(s)
void SetModal(bool aIsModal)
Definition: kiway_player.h:164
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
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:189
static bool empty(const wxTextEntryBase *aCtrl)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual 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...