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 <wx/file.h>
31 #include <wx/snglinst.h>
32 
33 #include <kiface_i.h>
34 #include <confirm.h>
35 #include <gestfich.h>
36 #include <pgm_base.h>
37 #include <pl_editor_frame.h>
38 #include <pl_editor_settings.h>
40 
41 
42 namespace PGE {
43 
44 static struct IFACE : public KIFACE_I
45 {
46  // Of course all are virtual overloads, implementations of the KIFACE.
47 
48  IFACE( const char* aName, KIWAY::FACE_T aType ) :
49  KIFACE_I( aName, aType )
50  {}
51 
52  bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
53 
54  void OnKifaceEnd() override;
55 
56  wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
57  {
58  switch( aClassId )
59  {
60  case FRAME_PL_EDITOR:
61  {
62  PL_EDITOR_FRAME* frame = new PL_EDITOR_FRAME( aKiway, aParent );
63  return frame;
64  }
65  break;
66 
67  default:
68  ;
69  }
70 
71  return NULL;
72  }
73 
85  void* IfaceOrAddress( int aDataId ) override
86  {
87  return NULL;
88  }
89 
96  void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
97  const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
98  const wxString& aSrcFilePath, wxString& aErrors ) override;
99 
100 } kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
101 
102 } // namespace
103 
104 using namespace PGE;
105 
107 
108 KIFACE_I& Kiface() { return kiface; }
109 
110 
111 // KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
112 // KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
113 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
114 {
116  return &kiface;
117 }
118 
119 
121 {
122  wxASSERT( process ); // KIFACE_GETTER has already been called.
123  return *process;
124 }
125 
126 
127 bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
128 {
131  start_common( aCtlBits );
132  return true;
133 }
134 
135 
137 {
138  end_common();
139 }
140 
141 
142 void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
143  const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
144  const wxString& aSrcFilePath, wxString& aErrors )
145 {
146  wxFileName destFile( aSrcFilePath );
147  wxString destPath = destFile.GetPathWithSep();
148  wxUniChar pathSep = wxFileName::GetPathSeparator();
149  wxString ext = destFile.GetExt();
150 
151  if( destPath.StartsWith( aProjectBasePath + pathSep ) )
152  {
153  destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
154  destFile.SetPath( destPath );
155  }
156 
157  if( ext == "kicad_wks" )
158  {
159  if( destFile.GetName() == aSrcProjectName )
160  destFile.SetName( aNewProjectName );
161 
162  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
163  }
164  else
165  {
166  wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
167  }
168 }
169 
KIFACE_I is a KIFACE (I)mplementation, with some features useful for DSOs which implement a KIFACE.
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:89
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
This file is part of the common library TODO brief description.
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: pl_editor.cpp:48
This file is part of the common library.
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
PL_EDITOR_FRAME is the main window used in the page layout editor.
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
void CopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Function CopyFile.
Definition: gestfich.cpp:353
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
int PGM_BASE * aProgram
Definition: pl_editor.cpp:114
void * IfaceOrAddress(int aDataId) override
Function IfaceOrAddress return a pointer to the requested object.
Definition: pl_editor.cpp:85
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: pl_editor.cpp:108
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aSrcProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Function SaveFileAs Saving a file under a different name is delegated to the various KIFACEs because ...
Definition: pl_editor.cpp:142
#define NULL
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:99
void OnKifaceEnd() override
Function OnKifaceEnd is called just once just before the DSO is to be unloaded.
Definition: pl_editor.cpp:136
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
#define KIFACE_GETTER
Definition: kiway.h:112
static PGM_BASE * process
Definition: pl_editor.cpp:106
FACE_T
Known KIFACE implementations.
Definition: kiway.h:279
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
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:56
see class PGM_BASE
PGE::IFACE KIFACE_I kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_i.h:105
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pl_editor.cpp:120
int aKiwayVersion
Definition: pl_editor.cpp:113
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Function OnKifaceStart is called just once shortly after the DSO is loaded.
Definition: pl_editor.cpp:127