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>
34
36#include <toolbars_pl_editor.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 return new PANEL_PL_EDITOR_DISPLAY_OPTIONS( aParent, GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" ) );
67
68 case PANEL_DS_GRIDS:
69 {
71 EDA_BASE_FRAME* frame = aKiway->Player( FRAME_PL_EDITOR, false );
72
73 if( frame )
75
76 return new PANEL_GRID_SETTINGS( aParent, this, frame, cfg, FRAME_PL_EDITOR );
77 }
78
80 return CreateSnappingPanel( aParent, GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" ),
82
83 case PANEL_DS_COLORS:
84 return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent );
85
87 {
90
91 std::vector<TOOL_ACTION*> actions;
92 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
93
95 actions.push_back( action );
96
98 controls.push_back( control );
99
100 return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, FRAME_PL_EDITOR, actions, controls );
101 }
102
103 default:
104 ;
105 }
106
107 return nullptr;
108 }
109
120 void* IfaceOrAddress( int aDataId ) override
121 {
122 return nullptr;
123 }
124
130 void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
131 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
132 const wxString& aSrcFilePath, wxString& aErrors ) override;
133
134} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
135
136} // namespace
137
138
139using namespace PGE;
140
141
143
144
145// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
146// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
147KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKiwayVersion, PGM_BASE* aProgram )
148{
149 return &kiface;
150}
151
152bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway )
153{
156 start_common( aCtlBits );
157 return true;
158}
159
160
162{
163 end_common();
164}
165
166
167void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
168 const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
169 const wxString& aSrcFilePath, wxString& aErrors )
170{
171 wxFileName destFile( aSrcFilePath );
172 wxString destPath = destFile.GetPathWithSep();
173 wxUniChar pathSep = wxFileName::GetPathSeparator();
174 wxString ext = destFile.GetExt();
175
176 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
177 {
178 destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
179 destFile.SetPath( destPath );
180 }
181
182 if( ext == "kicad_wks" )
183 {
184 if( destFile.GetName() == aSrcProjectName )
185 destFile.SetName( aNewProjectName );
186
187 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
188 }
189 else
190 {
191 wxFAIL_MSG( "Unexpected filetype for Pcbnew::SaveFileAs()" );
192 }
193}
194
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:388
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:127
@ PANEL_DS_COLORS
Definition frame_type.h:126
@ PANEL_DS_SNAPPING
Definition frame_type.h:125
@ FRAME_PL_EDITOR
Definition frame_type.h:55
@ PANEL_DS_GRIDS
Definition frame_type.h:124
@ PANEL_DS_DISPLAY_OPTIONS
Definition frame_type.h:123
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition gestfich.cpp:343
#define KIFACE_API
#define KIFACE_GETTER
Definition kiway.h:109
PGE::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("pl_editor", KIWAY::FACE_PL_EDITOR)
PANEL_SNAPPING * CreateSnappingPanel(wxWindow *aParent, SETTINGS_T *aCfg, FRAME_T aFrameType, SNAP_INFERENCE_SETTINGS SETTINGS_T::*aInference=nullptr, MAGNETIC_SETTINGS SETTINGS_T::*aMagnetics=nullptr)
Build the snapping page for an 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: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 ...
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:57
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
static const long long MM