KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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>
37
38#include "pl_editor_frame.h"
39#include "pl_editor_settings.h"
40
41
42namespace PGE {
43
44static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
45{
46 // Of course all are virtual overloads, implementations of the KIFACE.
47
48 IFACE( const char* aName, KIWAY::FACE_T aType ) :
49 KIFACE_BASE( aName, aType ),
51 {}
52
53 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override;
54
55 void OnKifaceEnd() override;
56
57 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
58 int aCtlBits = 0 ) override
59 {
60 switch( aClassId )
61 {
62 case FRAME_PL_EDITOR:
63 return new PL_EDITOR_FRAME( aKiway, aParent );
64
66 {
67 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
70 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, cfg );
71 }
72
73 case PANEL_DS_GRIDS:
74 {
75 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
77 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PL_EDITOR, false );
78
79 if( frame )
80 SetUserUnits( frame->GetUserUnits() );
81
82 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PL_EDITOR );
83 }
84
85 case PANEL_DS_COLORS:
86 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
87
88 default:
89 ;
90 }
91
92 return nullptr;
93 }
94
105 void* IfaceOrAddress( int aDataId ) override
106 {
107 return nullptr;
108 }
109
115 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
116 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
117 const wxString& aSrcFilePath, wxString& aErrors ) override;
118
119} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
120
121} // namespace
122
123
124using namespace PGE;
125
126
128
129
131
132
133// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
134// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
135KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
136{
137 process = (PGM_BASE*) aProgram;
138 return &kiface;
139}
140
141
143{
144 wxASSERT( process ); // KIFACE_GETTER has already been called.
145 return *process;
146}
147
148
149// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from a python script.
151{
152 return process;
153}
154
155bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
156{
159 start_common( aCtlBits );
160 return true;
161}
162
163
165{
166 end_common();
167}
168
169
170void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
171 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
172 const wxString& aSrcFilePath, wxString& aErrors )
173{
174 wxFileName destFile( aSrcFilePath );
175 wxString destPath = destFile.GetPathWithSep();
176 wxUniChar pathSep = wxFileName::GetPathSeparator();
177 wxString ext = destFile.GetExt();
178
179 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
180 {
181 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
182 destFile.SetPath( destPath );
183 }
184
185 if( ext == "kicad_wks" )
186 {
187 if( destFile.GetName() == aSrcProjectName )
188 destFile.SetName( aNewProjectName );
189
190 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
191 }
192 else
193 {
194 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
195 }
196}
197
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:110
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
The base frame for deriving all KiCad main window classes.
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
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:432
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:99
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:139
The main window used in the drawing sheet editor.
T * GetAppSettings()
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.
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
EDA_UNITS
Definition: eda_units.h:46
@ PANEL_DS_COLORS
Definition: frame_type.h:109
@ FRAME_PL_EDITOR
Definition: frame_type.h:59
@ PANEL_DS_GRIDS
Definition: frame_type.h:108
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:107
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:277
#define KIFACE_API
Definition: import_export.h:51
#define KIFACE_GETTER
Definition: kiway.h:111
PGE::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
see class PGM_BASE
static PGM_BASE * process
Definition: pl_editor.cpp:127
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pl_editor.cpp:142
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: pl_editor.cpp:130
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:150
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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:48
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Definition: pl_editor.cpp:155
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:170
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: pl_editor.cpp:105
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: pl_editor.cpp:57
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: pl_editor.cpp:164