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-2020 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 <wx/cmdline.h>
30 
31 #include <vector>
32 #include <kiway_holder.h>
33 #include <eda_base_frame.h>
34 
35 
36 class KIWAY;
37 class PROJECT;
38 struct KIFACE;
39 class KIFACE_I;
40 class TOOL_MANAGER;
41 class KIWAY_EXPRESS;
42 
43 #define WX_EVENT_LOOP wxGUIEventLoop
44 class WX_EVENT_LOOP;
45 
46 
58 #ifdef SWIG
59 class KIWAY_PLAYER : public wxFrame, public KIWAY_HOLDER
60 #else
62 #endif
63 {
64 public:
65  KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
66  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
67  long aStyle, const wxString& aWdoName = wxFrameNameStr );
68 
71  KIWAY_PLAYER( wxWindow* aParent, wxWindowID aId, const wxString& aTitle,
72  const wxPoint& aPos, const wxSize& aSize, long aStyle,
73  const wxString& aWdoName = wxFrameNameStr );
74 
75  ~KIWAY_PLAYER() throw();
76 
77  // For the aCtl argument of OpenProjectFiles()
78 #define KICTL_EAGLE_BRD (1<<0)
79 #define KICTL_CREATE (1<<1)
80 #define KICTL_IMPORT_LIB (1<<2)
81 
82 
115  virtual bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
116  {
117  // overload me for your wxFrame type.
118 
119  // Any overload should probably do this also:
120  // Prj().MaybeLoadProjectSettings();
121 
122  // Then update the window title.
123 
124  return false;
125  }
126 
136  virtual void ParseArgs( wxCmdLineParser& aParser )
137  {
138  WXUNUSED( aParser );
139  }
140 
141 
155  virtual bool ShowModal( wxString* aResult = nullptr,
156  wxWindow* aResultantFocusWindow = nullptr );
157 
163  virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent );
164 
168  bool Destroy() override;
169 
170  bool IsModal() const override { return m_modal; }
171  void SetModal( bool aIsModal ) { m_modal = aIsModal; }
172 
178  bool IsDismissed();
179 
180  void DismissModal( bool aRetVal, const wxString& aResult = wxEmptyString );
181 
182 protected:
183 
185  void kiway_express( KIWAY_EXPRESS& aEvent );
186 
190  void language_change( wxCommandEvent& event );
191 
192  // variables for modal behavior support, only used by a few derivatives.
193  bool m_modal; // true if frame is intended to be modal, not modeless
194 
197  wxWindow* m_modal_resultant_parent; // the window caller in modal mode
198  wxString m_modal_string;
199  bool m_modal_ret_val; // true if a selection was made
200 
201 #ifndef SWIG
202  DECLARE_EVENT_TABLE()
203 #endif
204 };
205 
206 
207 // psuedo code for OpenProjectFiles
208 #if 0
209 
210 bool OpenProjectFiles( const std::vector<wxString>& aFileList, int aCtl = 0 )
211 {
212  if( aFileList.size() != 1 )
213  {
214  complain via UI.
215  return false
216  }
217 
218  assert( aFileList[0] is absolute ) // bug in single_top.cpp or project manager.
219 
220  if( !Pgm().LockFile( fullFileName ) )
221  {
222  DisplayError( this, _( "This file is already open." ) );
223  return false;
224  }
225 
226  if current open project files have been modified
227  {
228  ask if user wants to save them and if yes save.
229  }
230 
231  unload any currently open project files.
232 
233  Prj().SetProjectFullName( )
234 
235  if( aFileList[0] does not exist )
236  {
237  notify user file does not exist and ask if he wants to create it
238  if( yes )
239  {
240  create empty project file(s)
241  mark file as modified.
242 
243  use the default project config file.
244  }
245  else
246  return false
247  }
248  else
249  {
250  load aFileList[0]
251 
252  use the project config file for project given by aFileList[0]s full path.
253  }
254 
255  UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
256 
257  /* done in ReDraw typically:
258  UpdateTitle();
259  */
260 
261  show contents.
262 }
263 
264 #endif
265 
266 #endif // KIWAY_PLAYER_H_
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:115
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:199
A KIFACE (I)mplementation.
Definition: kiface_i.h:37
const wxString & GetFileName() const
Definition: sch_screen.h:192
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:38
#define WX_EVENT_LOOP
Definition: kiway_player.h:43
wxWindow * m_modal_resultant_parent
Definition: kiway_player.h:197
Container for project specific data.
Definition: project.h:62
wxString m_modal_string
Definition: kiway_player.h:198
bool IsDismissed()
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
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
PROJECT & Prj()
Definition: kicad.cpp:386
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:285
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
Master controller class:
Definition: tool_manager.h:52
void language_change(wxCommandEvent &event)
An event handler called on a language menu selection.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:53
std::unique_ptr< wxSingleInstanceChecker > LockFile(const wxString &aFileName)
Test to see if aFileName can be locked (is not already locked) and only then returns a wxSingleInstan...
Definition: lockfile.cpp:33
Base window classes and related definitions.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Receive KIWAY_EXPRESS messages from other players.
void kiway_express(KIWAY_EXPRESS &aEvent)
event handler, routes to derivative specific virtual KiwayMailIn()
bool IsModal() const override
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Definition: kiway_player.h:170
void SetModal(bool aIsModal)
Definition: kiway_player.h:171
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
#define _(s)
Definition: 3d_actions.cpp:33
The base frame for deriving all KiCad main window classes.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:147
WX_EVENT_LOOP * m_modal_loop
< Points to nested event_loop. NULL means not modal and dismissed.
Definition: kiway_player.h:196
static bool empty(const wxTextEntryBase *aCtrl)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual void ParseArgs(wxCmdLineParser &aParser)
Handle command-line arguments in a frame-specific way.
Definition: kiway_player.h:136