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 
188  VTBL_ENTRY bool ImportFile( const wxString& aFileName, int aFileType )
189  {
190  // overload me for your wxFrame type.
191 
192  return false;
193  }
194 
199  VTBL_ENTRY void ReadPcbNetlist( const wxString& aNetlistFileName,
200  const wxString& aCmpFileName,
201  REPORTER* aReporter,
202  bool aChangeFootprint,
203  bool aDeleteBadTracks,
204  bool aDeleteExtraFootprints,
205  bool aSelectByTimestamp,
206  bool aDeleteSinglePadNets,
207  bool aIsDryRun )
208  {
209  };
210 
215  VTBL_ENTRY bool CreateNetlist( int aFormat,
216  const wxString& aFullFileName,
217  unsigned aNetlistOptions,
218  REPORTER* aReporter = NULL,
219  bool silent = false )
220  {
221  return false;
222  };
223 
224 
240  VTBL_ENTRY bool ShowModal( wxString* aResult = NULL, wxWindow* aResultantFocusWindow = NULL );
241 
242  //----</Cross Module API>----------------------------------------------------
243 
244 
250  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
251 
255  bool Destroy() override;
256 
257 protected:
258 
259  bool IsModal() { return m_modal; }
260  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
261 
268  bool IsDismissed();
269 
270  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
271 
273  void kiway_express( KIWAY_EXPRESS& aEvent );
274 
279  void language_change( wxCommandEvent& event );
280 
286  void OnChangeIconsOptions( wxCommandEvent& event ) override;
287 
288  // variables for modal behavior support, only used by a few derivatives.
289  bool m_modal; // true if frame is intended to be modal, not modeless
290  WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed
291  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
292  wxString m_modal_string;
293  bool m_modal_ret_val; // true if a selection was made
294 
295 #ifndef SWIG
296  DECLARE_EVENT_TABLE()
297 #endif
298 };
299 
300 
301 // psuedo code for OpenProjectFiles
302 #if 0
303 
304 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
305 {
306  if( aFileList.size() != 1 )
307  {
308  complain via UI.
309  return false
310  }
311 
312  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
313 
314  if( !Pgm().LockFile( fullFileName ) )
315  {
316  DisplayError( this, _( "This file is already open." ) );
317  return false;
318  }
319 
320  if current open project files have been modified
321  {
322  ask if user wants to save them and if yes save.
323  }
324 
325  unload any currently open project files.
326 
328 
329  if( aFileList[0] does not exist )
330  {
331  notify user file does not exist and ask if he wants to create it
332  if( yes )
333  {
334  create empty project file(s)
335  mark file as modified.
336 
337  use the default project config file.
338  }
339  else
340  return false
341  }
342  else
343  {
344  load aFileList[0]
345 
346  use the project config file for project given by aFileList[0]s full path.
347  }
348 
349  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
350 
351  /* done in ReDraw typically:
352  UpdateTitle();
353  */
354 
355  show contents.
356 }
357 
358 
359 
360 #endif
361 
362 
363 
364 
365 #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:293
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:291
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:292
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:270
const wxString & GetFileName() const
KIWAY * m_kiway
Definition: kiway_player.h:85
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
#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:55
Base window classes and related definitions.
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
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:259
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:65
void SetModal(bool aIsModal)
Definition: kiway_player.h:260
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:117
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:290
static bool empty(const wxTextEntryBase *aCtrl)
VTBL_ENTRY bool CreateNetlist(int aFormat, const wxString &aFullFileName, unsigned aNetlistOptions, REPORTER *aReporter=NULL, bool silent=false)
Function ReadPcbNetlist provides access to Eeschema's function CreateNetlist.
Definition: kiway_player.h:215
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
VTBL_ENTRY void ReadPcbNetlist(const wxString &aNetlistFileName, const wxString &aCmpFileName, REPORTER *aReporter, bool aChangeFootprint, bool aDeleteBadTracks, bool aDeleteExtraFootprints, bool aSelectByTimestamp, bool aDeleteSinglePadNets, bool aIsDryRun)
Function ReadPcbNetlist provides access to PcbNew's function ReadPcbNetlist.
Definition: kiway_player.h:199
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
VTBL_ENTRY bool ImportFile(const wxString &aFileName, int aFileType)
Function ImportFile load the given filename but sets the path to the current project path...
Definition: kiway_player.h:188
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...