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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <wx/file.h>
23#include <wx/snglinst.h>
24
25#include <kiface_base.h>
26#include <confirm.h>
27#include <gestfich.h>
28#include <pgm_base.h>
33
35#include <toolbars_pl_editor.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, public UNITS_PROVIDER
44{
45 // Of course all are virtual overloads, implementations of the KIFACE.
46
47 IFACE( const char* aName, KIWAY::FACE_T aType ) :
48 KIFACE_BASE( aName, aType ),
50 {}
51
52 bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) override;
53
54 void OnKifaceEnd() override;
55
56 wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway,
57 int aCtlBits = 0 ) override
58 {
59 switch( aClassId )
60 {
61 case FRAME_PL_EDITOR:
62 return new PL_EDITOR_FRAME( aKiway, aParent );
63
65 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" ) );
66
67 case PANEL_DS_GRIDS:
68 {
70 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PL_EDITOR, false );
71
72 if( frame )
73 SetUserUnits( frame->GetUserUnits() );
74
75 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PL_EDITOR );
76 }
77
78 case PANEL_DS_COLORS:
79 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
82 {
85
86 std::vector<TOOL_ACTION*> actions;
87 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
88
90 actions.push_back( action );
91
93 controls.push_back( control );
94
95 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, FRAME_PL_EDITOR, actions, controls );
96 }
97
98 default:
99 ;
100 }
101
102 return nullptr;
103 }
104
115 void* IfaceOrAddress( int aDataId ) override
116 {
117 return nullptr;
118 }
119
125 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
126 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
127 const wxString& aSrcFilePath, wxString& aErrors ) override;
128
129} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
130
131} // namespace
132
133
134using namespace PGE;
135
136
138
139
140// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
141// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
142KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
143{
144 return &kiface;
145}
146
147bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
148{
151 start_common( aCtlBits );
152 return true;
153}
154
155
157{
158 end_common();
159}
160
161
162void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
163 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
164 const wxString& aSrcFilePath, wxString& aErrors )
165{
166 wxFileName destFile( aSrcFilePath );
167 wxString destPath = destFile.GetPathWithSep();
168 wxUniChar pathSep = wxFileName::GetPathSeparator();
169 wxString ext = destFile.GetExt();
170
171 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
172 {
173 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
174 destFile.SetPath( destPath );
175 }
176
177 if( ext == "kicad_wks" )
178 {
179 if( destFile.GetName() == aSrcProjectName )
180 destFile.SetName( aNewProjectName );
181
182 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
183 }
184 else
185 {
186 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
187 }
188}
189
constexpr EDA_IU_SCALE drawSheetIUScale
Definition base_units.h:122
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(FRAME_T aContext)
Get the list of custom controls that could be used on a particular frame type.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
The base frame for deriving all KiCad main window classes.
A KIFACE implementation.
Definition kiface_base.h:35
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition kiface_base.h:63
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition kiface_base.h:93
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:91
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:398
FACE_T
Known KIFACE implementations.
Definition kiway.h:317
@ FACE_PL_EDITOR
Definition kiway.h:322
Container for data for KiCad programs.
Definition pgm_base.h:102
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
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.
UNITS_PROVIDER(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
This file is part of the common library.
EDA_UNITS
Definition eda_units.h:44
@ PANEL_DS_TOOLBARS
Definition frame_type.h:121
@ PANEL_DS_COLORS
Definition frame_type.h:120
@ FRAME_PL_EDITOR
Definition frame_type.h:55
@ PANEL_DS_GRIDS
Definition frame_type.h:119
@ PANEL_DS_DISPLAY_OPTIONS
Definition frame_type.h:118
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition gestfich.cpp:307
#define KIFACE_API
#define KIFACE_GETTER
Definition kiway.h:109
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.
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
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.
IFACE(const char *aName, KIWAY::FACE_T aType)
Definition pl_editor.cpp:47
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 ...
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Definition pl_editor.cpp:56
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
static const long long MM