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 The 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
39#include <toolbars_pl_editor.h>
40
41#include "pl_editor_frame.h"
42#include "pl_editor_settings.h"
43
44
45namespace PGE {
46
47static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
48{
49 // Of course all are virtual overloads, implementations of the KIFACE.
50
51 IFACE( const char* aName, KIWAY::FACE_T aType ) :
52 KIFACE_BASE( aName, aType ),
54 {}
55
56 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
57
58 void OnKifaceEnd() override;
59
60 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
61 int aCtlBits = 0 ) override
62 {
63 switch( aClassId )
64 {
65 case FRAME_PL_EDITOR:
66 return new PL_EDITOR_FRAME( aKiway, aParent );
67
69 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" ) );
71 case PANEL_DS_GRIDS:
72 {
73 APP_SETTINGS_BASE* cfg = GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
74 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PL_EDITOR, false );
75
76 if( frame )
77 SetUserUnits( frame->GetUserUnits() );
78
79 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PL_EDITOR );
80 }
81
82 case PANEL_DS_COLORS:
83 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
84
86 {
87 APP_SETTINGS_BASE* cfg = GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
88 TOOLBAR_SETTINGS* tb = GetToolbarSettings<PL_EDITOR_TOOLBAR_SETTINGS>( "pl_editor-toolbars" );
89
90 std::vector<TOOL_ACTION*> actions;
91 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
92
94 actions.push_back( action );
95
97 controls.push_back( control );
98
99 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls );
100 }
101
102 default:
103 ;
104 }
105
106 return nullptr;
107 }
108
119 void* IfaceOrAddress( int aDataId ) override
120 {
121 return nullptr;
122 }
123
129 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
130 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
131 const wxString& aSrcFilePath, wxString& aErrors ) override;
132
133} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
134
135} // namespace
136
137
138using namespace PGE;
139
140
142
143
144// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
145// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
146KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
147{
148 return &kiface;
149}
150
151bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
152{
155 start_common( aCtlBits );
156 return true;
157}
158
159
161{
162 end_common();
163}
164
165
166void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
167 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
168 const wxString& aSrcFilePath, wxString& aErrors )
169{
170 wxFileName destFile( aSrcFilePath );
171 wxString destPath = destFile.GetPathWithSep();
172 wxUniChar pathSep = wxFileName::GetPathSeparator();
173 wxString ext = destFile.GetExt();
174
175 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
176 {
177 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
178 destFile.SetPath( destPath );
179 }
180
181 if( ext == "kicad_wks" )
182 {
183 if( destFile.GetName() == aSrcProjectName )
184 destFile.SetName( aNewProjectName );
185
186 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
187 }
188 else
189 {
190 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
191 }
192}
193
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:113
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
Class to hold basic information about controls that can be added to the toolbars.
static std::list< ACTION_TOOLBAR_CONTROL * > & GetCustomControlList()
Get the list of custom controls that could be used on toolbars.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
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:286
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:395
FACE_T
Known KIFACE implementations.
Definition: kiway.h:292
@ FACE_PL_EDITOR
Definition: kiway.h:297
Container for data for KiCad programs.
Definition: pgm_base.h:103
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
The main window used in the drawing sheet editor.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
Represent a single user action.
Definition: tool_action.h:304
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
EDA_UNITS
Definition: eda_units.h:48
@ PANEL_DS_TOOLBARS
Definition: frame_type.h:119
@ PANEL_DS_COLORS
Definition: frame_type.h:118
@ FRAME_PL_EDITOR
Definition: frame_type.h:59
@ PANEL_DS_GRIDS
Definition: frame_type.h:117
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:116
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:290
#define KIFACE_API
Definition: import_export.h:61
#define KIFACE_GETTER
Definition: kiway.h:110
PGE::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
see class PGM_BASE
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: pl_editor.cpp:141
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:153
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Definition: pl_editor.cpp:151
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition: pl_editor.cpp:51
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:166
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: pl_editor.cpp:119
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition: pl_editor.cpp:60
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
Definition: pl_editor.cpp:160