KiCad PCB EDA Suite
pl_editor.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2013 CERN
10  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <fctsys.h>
31 #include <kiface_i.h>
32 #include <confirm.h>
33 #include <gestfich.h>
35 #include <pl_editor_frame.h>
36 #include <hotkeys.h>
37 
38 #include <build_version.h>
39 
40 #include <wx/file.h>
41 #include <wx/snglinst.h>
42 
43 
44 namespace PGE {
45 
46 static struct IFACE : public KIFACE_I
47 {
48  // Of course all are virtual overloads, implementations of the KIFACE.
49 
50  IFACE( const char* aName, KIWAY::FACE_T aType ) :
51  KIFACE_I( aName, aType )
52  {}
53 
54  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
55 
56  void OnKifaceEnd() override;
57 
58  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
59  {
60  switch( aClassId )
61  {
62  case FRAME_PL_EDITOR:
63  {
64  PL_EDITOR_FRAME* frame = new PL_EDITOR_FRAME( aKiway, aParent );
65  return frame;
66  }
67  break;
68 
69  default:
70  ;
71  }
72 
73  return NULL;
74  }
75 
87  void* IfaceOrAddress( int aDataId ) override
88  {
89  return NULL;
90  }
91 
92 } kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
93 
94 } // namespace
95 
96 using namespace PGE;
97 
98 static PGM_BASE* process;
99 
100 KIFACE_I& Kiface() { return kiface; }
101 
102 
103 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
104 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
105 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
106 {
107  process = (PGM_BASE*) aProgram;
108  return &kiface;
109 }
110 
111 
113 {
114  wxASSERT( process ); // KIFACE_GETTER has already been called.
115  return *process;
116 }
117 
118 
119 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
120 {
121  start_common( aCtlBits );
122 
123  // Must be called before creating the main frame in order to
124  // display the real hotkeys in menus or tool tips
126 
128 
129  return true;
130 }
131 
132 
134 {
135  end_common();
136 }
137 
138 
139 #if 0
141 
142 {
143  wxFileName fn;
145  InitEDA_Appl( wxT( "pl_editor" ), APP_PL_EDITOR_T );
146 
147  if( m_Checker && m_Checker->IsAnotherRunning() )
148  {
149  if( !IsOK( NULL, _( "pl_editor is already running. Continue?" ) ) )
150  return false;
151  }
152 
154 
155  // read current setup and reopen last directory if no filename to open in
156  // command line
157  bool reopenLastUsedDirectory = argc == 1;
158  GetSettings( reopenLastUsedDirectory );
159 
160  // Must be called before creating the main frame in order to
161  // display the real hotkeys in menus or tool tips
162  ReadHotkeyConfig( PL_EDITOR_FRAME_NAME, s_PlEditor_Hokeys_Descr );
163 
164  PL_EDITOR_FRAME * frame = new PL_EDITOR_FRAME( NULL, wxT( "PlEditorFrame" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
165 
166  // frame title:
167  frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() );
168 
169  SetTopWindow( frame );
170  frame->Show( true );
171  frame->Zoom_Automatique( true ); // Zoom fit in frame
172  frame->GetScreen()->m_FirstRedraw = false;
174 
175  bool descrLoaded = false;
176  if( argc > 1 )
177  {
178  fn = argv[1];
179 
180  if( fn.IsOk() )
181  {
182  bool success = frame->LoadPageLayoutDescrFile( fn.GetFullPath() );
183  if( !success )
184  {
185  wxString msg;
186  msg.Printf( _("Error when loading file <%s>"),
187  fn.GetFullPath().GetData() );
188  wxMessageBox( msg );
189  }
190  else
191  {
192  descrLoaded = true;
193  frame->OnNewPageLayout();
194  }
195  }
196  }
197 
198  if( !descrLoaded )
199  {
201  frame->OnNewPageLayout();
202  }
203 
204  return true;
205 }
206 #endif
void ReadHotkeyConfig(const wxString &Appname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for th...
Class KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIF...
Definition: kiface_i.h:37
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:94
This file is part of the common library TODO brief description.
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: pl_editor.cpp:50
This file is part of the common library.
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
int PGM_BASE * aProgram
Definition: pl_editor.cpp:106
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: pl_editor.cpp:87
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: pl_editor.cpp:100
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
KIFACE * KIFACE_GETTER(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
No name mangling. Each KIFACE (DSO/DLL) will implement this once.
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:104
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void OnNewPageLayout()
Must be called to initialize parameters when a new page layout description is loaded.
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: pl_editor.cpp:133
PL_EDITOR_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
#define PL_EDITOR_FRAME_NAME
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
static PGM_BASE * process
Definition: pl_editor.cpp:98
FACE_T
Known KIFACE implementations.
Definition: kiway.h:263
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Function CreateWindow creates a wxWindow for the current project.
Definition: pl_editor.cpp:58
PGE::IFACE KIFACE_I kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[]
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
bool LoadPageLayoutDescrFile(const wxString &aFullFileName)
Function LoadPageLayoutDescrFile Loads a .kicad_wks page layout descr file.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pl_editor.cpp:112
classes and function to generate graphics to plt or draw titles blocks and frame references ...
int aKiwayVersion
Definition: pl_editor.cpp:105
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
Definition: pl_editor.cpp:119
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
void SetPageLayout(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout, or the default layout, if no custom layout available...