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 {
71 APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
72
73 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, cfg );
74 }
75
76 case PANEL_DS_GRIDS:
77 {
79 APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
80 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PL_EDITOR, false );
81
82 if( frame )
83 SetUserUnits( frame->GetUserUnits() );
84
85 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PL_EDITOR );
86 }
88 case PANEL_DS_COLORS:
89 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
90
92 {
94 APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
95 TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<PL_EDITOR_TOOLBAR_SETTINGS>( "pl_editor-toolbars" );
96
97 std::vector<TOOL_ACTION*> actions;
98 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
99
101 actions.push_back( action );
102
104 controls.push_back( control );
105
106 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls );
107 }
108
109 default:
110 ;
111 }
112
113 return nullptr;
114 }
115
126 void* IfaceOrAddress( int aDataId ) override
127 {
128 return nullptr;
129 }
130
136 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
137 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
138 const wxString& aSrcFilePath, wxString& aErrors ) override;
139
140} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
141
142} // namespace
143
144
145using namespace PGE;
146
147
149
150
151// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
152// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
153KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
154{
155 return &kiface;
156}
157
158bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
159{
162 start_common( aCtlBits );
163 return true;
164}
165
166
168{
169 end_common();
170}
171
172
173void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
174 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
175 const wxString& aSrcFilePath, wxString& aErrors )
176{
177 wxFileName destFile( aSrcFilePath );
178 wxString destPath = destFile.GetPathWithSep();
179 wxUniChar pathSep = wxFileName::GetPathSeparator();
180 wxString ext = destFile.GetExt();
181
182 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
183 {
184 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
185 destFile.SetPath( destPath );
186 }
187
188 if( ext == "kicad_wks" )
189 {
190 if( destFile.GetName() == aSrcProjectName )
191 destFile.SetName( aNewProjectName );
192
193 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
194 }
195 else
196 {
197 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
198 }
199}
200
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:109
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: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:285
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:291
@ FACE_PL_EDITOR
Definition: kiway.h:296
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.
Toolbar configuration for the page layout editor frame.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
Represent a single user action.
Definition: tool_action.h:304
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
EDA_UNITS
Definition: eda_units.h:46
@ 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)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: pl_editor.cpp:148
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:152
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
Definition: pl_editor.cpp:158
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:173
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
Definition: pl_editor.cpp:126
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:167