KiCad PCB EDA Suite
pl_editor.cpp
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) 2013 CERN
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/file.h>
27#include <wx/snglinst.h>
28
29#include <kiface_base.h>
30#include <confirm.h>
31#include <gestfich.h>
32#include <pgm_base.h>
36
37#include "pl_editor_frame.h"
38#include "pl_editor_settings.h"
39
40
41namespace PGE {
42
43static struct IFACE : public KIFACE_BASE
44{
45 // Of course all are virtual overloads, implementations of the KIFACE.
47 IFACE( const char* aName, KIWAY::FACE_T aType ) :
48 KIFACE_BASE( aName, aType )
49 {}
50
51 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
52
53 void OnKifaceEnd() override;
54
55 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
56 int aCtlBits = 0 ) override
57 {
58 switch( aClassId )
59 {
60 case FRAME_PL_EDITOR:
61 return new PL_EDITOR_FRAME( aKiway, aParent );
62
64 {
67
68 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, cfg );
69 }
70
71 case PANEL_DS_COLORS:
72 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
73
74 default:
75 ;
76 }
77
78 return nullptr;
79 }
80
91 void* IfaceOrAddress( int aDataId ) override
92 {
93 return nullptr;
94 }
95
101 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
102 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
103 const wxString& aSrcFilePath, wxString& aErrors ) override;
104
105} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
106
107} // namespace
108
109
110using namespace PGE;
111
112
114
115
117
118
119// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
120// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
121MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
122{
124 return &kiface;
125}
126
127
129{
130 wxASSERT( process ); // KIFACE_GETTER has already been called.
131 return *process;
132}
133
134
135// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from a python script.
137{
138 return process;
139}
140
142{
145 start_common( aCtlBits );
146 return true;
147}
148
149
151{
152 end_common();
153}
154
155
156void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
157 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
158 const wxString& aSrcFilePath, wxString& aErrors )
159{
160 wxFileName destFile( aSrcFilePath );
161 wxString destPath = destFile.GetPathWithSep();
162 wxUniChar pathSep = wxFileName::GetPathSeparator();
163 wxString ext = destFile.GetExt();
164
165 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
166 {
167 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
168 destFile.SetPath( destPath );
169 }
170
171 if( ext == "kicad_wks" )
172 {
173 if( destFile.GetName() == aSrcProjectName )
174 destFile.SetName( aNewProjectName );
175
176 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
177 }
178 else
179 {
180 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
181 }
182}
183
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
A KIFACE implementation.
Definition: kiface_base.h:39
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_base.h:97
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_base.cpp:42
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_base.cpp:32
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
FACE_T
Known KIFACE implementations.
Definition: kiway.h:285
@ FACE_PL_EDITOR
Definition: kiway.h:290
Container for data for KiCad programs.
Definition: pgm_base.h:95
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:135
The main window used in the drawing sheet editor.
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
This file is part of the common library.
@ PANEL_DS_COLORS
Definition: frame_type.h:100
@ FRAME_PL_EDITOR
Definition: frame_type.h:55
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:99
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:214
#define KIFACE_GETTER
Definition: kiway.h:111
PGE::IFACE KIFACE_BASE kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
see class PGM_BASE
return & kiface
Definition: pl_editor.cpp:124
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
int aKiwayVersion
Definition: pl_editor.cpp:121
static PGM_BASE * process
Definition: pl_editor.cpp:113
int PGM_BASE * aProgram
Definition: pl_editor.cpp:122
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pl_editor.cpp:128
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: pl_editor.cpp:116
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: pl_editor.cpp:136
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: pl_editor.cpp:47
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Definition: pl_editor.cpp:141
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aSrcProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Definition: pl_editor.cpp:156
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: pl_editor.cpp:91
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: pl_editor.cpp:55
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: pl_editor.cpp:150