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, KIWAY* aKiway ) 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 {
70 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, cfg );
71 }
72
73 case PANEL_DS_GRIDS:
74 {
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
130// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
131// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
132KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
133{
134 return &kiface;
135}
136
137bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
138{
141 start_common( aCtlBits );
142 return true;
143}
144
145
147{
148 end_common();
149}
150
151
152void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
153 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
154 const wxString& aSrcFilePath, wxString& aErrors )
155{
156 wxFileName destFile( aSrcFilePath );
157 wxString destPath = destFile.GetPathWithSep();
158 wxUniChar pathSep = wxFileName::GetPathSeparator();
159 wxString ext = destFile.GetExt();
160
161 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
162 {
163 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
164 destFile.SetPath( destPath );
165 }
166
167 if( ext == "kicad_wks" )
168 {
169 if( destFile.GetName() == aSrcProjectName )
170 destFile.SetName( aNewProjectName );
171
172 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
173 }
174 else
175 {
176 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
177 }
178}
179
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:109
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:406
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:102
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
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:111
@ FRAME_PL_EDITOR
Definition: frame_type.h:59
@ PANEL_DS_GRIDS
Definition: frame_type.h:110
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:109
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:305
#define KIFACE_API
Definition: import_export.h:61
#define KIFACE_GETTER
Definition: kiway.h:111
PGE::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: pl_editor.cpp:127
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Definition: pl_editor.cpp:137
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: pl_editor.cpp:48
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:152
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:146