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 
138  virtual void ParseArgs( wxCmdLineParser& aParser )
139  {
140  WXUNUSED( aParser );
141  }
142 
143 
159  virtual bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL );
160 
161  //----</Cross Module API>----------------------------------------------------
162 
163 
169  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
170 
174  bool Destroy() override;
175 
176  bool IsModal() const { return m_modal; }
177  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
178 
185  bool IsDismissed();
186 
187  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
188 
189 protected:
190 
192  void kiway_express( KIWAY_EXPRESS& aEvent );
193 
198  void language_change( wxCommandEvent& event );
199 
200  // variables for modal behavior support, only used by a few derivatives.
201  bool m_modal; // true if frame is intended to be modal, not modeless
202  WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
203  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
204  wxString m_modal_string;
205  bool m_modal_ret_val; // true if a selection was made
206 
207 #ifndef SWIG
208  DECLARE_EVENT_TABLE()
209 #endif
210 };
211 
212 
213 // psuedo code for OpenProjectFiles
214 #if 0
215 
216 bool 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 
271 
272 #endif
273 
274 
275 
276 
277 #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:239
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
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:205
KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIFACE.
Definition: kiface_i.h:37
const wxString & GetFileName() const
Definition: sch_screen.h:189
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
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:203
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
PROJECT holds project specific data.
Definition: project.h:61
wxString m_modal_string
Definition: kiway_player.h:204
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:317
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
TOOL_MANAGER.
Definition: tool_manager.h:51
void language_change(wxCommandEvent &event)
Function language_change is an event handler called on a language menu selection.
#define NULL
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.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
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()
void SetModal(bool aIsModal)
Definition: kiway_player.h:177
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
#define _(s)
Definition: 3d_actions.cpp:33
bool IsModal() const
Definition: kiway_player.h:176
The base frame for deriving all KiCad main window classes.
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
WX_EVENT_LOOP * m_modal_loop
Definition: kiway_player.h:202
static bool empty(const wxTextEntryBase *aCtrl)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
SCH_SHEET * g_RootSheet
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...
virtual void ParseArgs(wxCmdLineParser &aParser)
Handles command-line arguments in a frame-specific way.
Definition: kiway_player.h:138