64#include <wx/filedlg.h>
65#include <wx/dcclient.h>
67#include <wx/process.h>
71#include <../pcbnew/plugins/kicad/pcb_plugin.h>
76#include <ApplicationServices/ApplicationServices.h>
83#define SEP() wxFileName::GetPathSeparator()
120#include <wx/xml/xml.h>
123 const wxPoint& pos,
const wxSize& size ) :
126 m_leftWin( nullptr ),
127 m_launcher( nullptr ),
128 m_mainToolBar( nullptr ),
129 m_lastToolbarIconSize( 0 )
131 m_active_project =
false;
132 m_leftWinWidth = 250;
133 m_aboutTitle =
"KiCad";
143 CreateStatusBar( 3 );
144 Pgm().GetBackgroundJobMonitor().RegisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
145 Pgm().GetNotificationsManager().RegisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
150 wxIconBundle icon_bundle;
155 icon_bundle.AddIcon( icon );
157 icon_bundle.AddIcon( icon );
159 icon_bundle.AddIcon( icon );
164 icon_bundle.AddIcon( icon );
166 icon_bundle.AddIcon( icon );
168 icon_bundle.AddIcon( icon );
171 SetIcons( icon_bundle );
176 m_pcmButton =
nullptr;
177 m_pcmUpdateCount = 0;
187 RecreateBaseHToolbar();
190 m_auimgr.SetManagedWindow(
this );
191 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
193 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name(
"MainToolbar" ).Left()
201 m_auimgr.AddPane( m_leftWin,
EDA_PANE().Palette().Name(
"ProjectTree" ).Left().Layer( 1 )
202 .Caption(
_(
"Project Files" ) ).PaneBorder(
false )
203 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
205 m_auimgr.AddPane( m_launcher,
EDA_PANE().Canvas().Name(
"Launcher" ).Center()
206 .Caption(
_(
"Editors" ) ).PaneBorder(
false )
207 .MinSize( m_launcher->GetBestSize() ) );
212 m_auimgr.GetPane( m_leftWin ).MinSize( 250, -1 );
214 wxSizer* mainSizer = GetSizer();
217 if( mainSizer &&
config()->m_Window.state.size_x == 0 &&
config()->m_Window.state.size_y == 0 )
218 mainSizer->Fit(
this );
221 SetTitle( wxT(
"KiCad" ) );
226 m_leftWin->SetFocus();
238 DragAcceptFiles(
true );
247 Pgm().GetBackgroundJobMonitor().UnregisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
248 Pgm().GetNotificationsManager().UnregisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
255 m_pcm->StopBackgroundUpdate();
266 const wxString&
name )
278 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
279 [
this](
int aUpdateCount )
283 if( aUpdateCount > 0 )
285 Pgm().GetNotificationsManager().CreateOrUpdate(
287 _(
"PCM Updates Available" ),
288 wxString::Format(
_(
"%d package update(s) avaliable" ), aUpdateCount ),
293 Pgm().GetNotificationsManager().Remove( wxS(
"pcm" ) );
341#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
344 activeProjectCond.
Enable( activeProject );
387 wxString( wxEmptyString );
396 return fn.GetFullPath();
405 return fn.GetFullPath();
414 return fn.GetFullPath();
423 return fn.GetFullPath();
463 wxString ext = fileName.GetExt();
467 wxString fn = fileName.GetFullPath();
475 wxString gerberFiles;
480 wxString ext = fileName.GetExt();
485 gerberFiles += wxT(
'\"' );
486 gerberFiles += fileName.GetFullPath() + wxT(
'\"' );
487 gerberFiles = gerberFiles.Pad( 1 );
491 wxString fn = fileName.GetFullPath();
497 if( !gerberFiles.IsEmpty() )
501 if( wxFileExists( fullEditorName ) )
503 wxString command = fullEditorName +
" " + gerberFiles;
521 aEvent.StopPropagation();
527 if( aEvent.CanVeto() )
545 static std::atomic<unsigned int> lock_close_event( 0 );
547 if( ++lock_close_event > 1 )
554 Pgm().m_Quitting =
true;
559 lock_close_event = 0;
572 if( !
Kiway().PlayersClose(
false ) )
600 if( !aProjectFileName.Exists() )
611 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
615 if( aProjectFileName.IsDirWritable() )
630 wxPostEvent(
this, cmd );
640 bool aCreateStubFiles )
642 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
643 "Project folder must exist and be writable to create a new project." );
646 if( !aProjectFileName.FileExists() )
648 wxFileName legacyPro( aProjectFileName );
651 if( legacyPro.FileExists() )
656 wxRemoveFile( legacyPro.GetFullPath() );
661 wxString srcFileName =
sys_search().FindValidPath(
"kicad.kicad_pro" );
663 wxFileName destFileName( aProjectFileName );
667 if( !wxFileName::FileExists( srcFileName )
668 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
670 wxFFile file( destFileName.GetFullPath(),
"wb" );
672 if( file.IsOpened() )
673 file.Write( wxT(
"{\n}\n") );
683 if( aCreateStubFiles )
685 wxFileName fn( aProjectFileName.GetFullPath() );
690 if( !fn.FileExists() )
692 wxFFile file( fn.GetFullPath(),
"wb" );
694 if( file.IsOpened() )
695 file.Write( wxString::Format(
"(kicad_sch (version %d) (generator \"eeschema\") (generator_version \"%s\")\n"
696 " (paper \"A4\")\n (lib_symbols)\n"
697 " (symbol_instances)\n)\n",
706 wxFileName leg_fn( fn );
709 if( !fn.FileExists() && !leg_fn.FileExists() )
711 wxFFile file( fn.GetFullPath(),
"wb" );
713 if( file.IsOpened() )
715 file.Write( wxString::Format(
"(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n)",
738 wxFileDialog dlg(
this,
_(
"Edit File in Text Editor" ), default_dir, wxEmptyString, wildcard,
741 if( dlg.ShowModal() == wxID_CANCEL )
744 wxString filename = dlg.GetPath();
746 if( !dlg.GetPath().IsEmpty() && !
Pgm().GetTextEditor().IsEmpty() )
766 int id =
event.GetId();
788 if(
m_pcm && aEnvVarsChanged )
809 if( !file.IsEmpty() )
811 wxFileName fn( file );
813 title = fn.GetName();
815 if( !fn.IsDirWritable() )
816 title += wxS(
" " ) +
_(
"[Read Only]" );
820 title =
_(
"[no project loaded]" );
824 title += wxT(
" \u2014 " ) + wxString( wxS(
"KiCad" ) );
838 wxCHECK( settings, );
850 wxCHECK( settings, );
852 settings->m_LeftWinWidth =
m_leftWin->GetSize().x;
863 wxString status = wxString::Format(
_(
"Project: %s" ),
Prj().GetProjectFullName() );
864 wxStatusBar* statusBar = GetStatusBar();
865 int width = statusBar->GetSize().GetWidth() / 2;
869 wxClientDC dc(
this );
870 status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
873 SetStatusText( status );
895 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files )
897 int previousOpenCount =
898 std::count_if(
Prj().GetLocalSettings().m_files.begin(),
899 Prj().GetLocalSettings().m_files.end(),
902 return !f.fileName.EndsWith( ProjectFileExtension ) && f.open;
905 if( previousOpenCount > 0 )
908 previousOpenCount,
this );
911 std::set<wxString> openedFiles;
917 if( file.open && !openedFiles.count( file.fileName ) )
919 progressReporter.
Update( i++,
920 wxString::Format(
_(
"Restoring '%s'" ), file.fileName ) );
922 openedFiles.insert( file.fileName );
923 wxFileName fn( file.fileName );
949 if( wxMessageBox(
_(
"Would you like to automatically check for plugin updates on startup?" ),
950 _(
"Check for updates" ), wxICON_QUESTION | wxYES_NO,
this )
969 m_pcm->RunBackgroundUpdate();
constexpr EDA_IU_SCALE unityScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
bool IsNightlyVersion()
Check if the build is meant to be nightly.
static TOOL_ACTION saveAs
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
wxProgressDialog with the option to also update the application progress on the taskbar
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=nullptr) override
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Handle actions that are shared between different applications.
The base frame for deriving all KiCad main window classes.
void LoadWindowState(const wxString &aFileName)
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
std::vector< wxFileName > m_AcceptedFiles
SETTINGS_MANAGER * GetSettingsManager() const
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associates files extensions with action to execute.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void SetMruPath(const wxString &aPath)
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
Specialization of the wxAuiPaneInfo class for KiCad panels.
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION editPCB
static TOOL_ACTION loadProject
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION closeProject
Handle actions in the kicad manager frame.
The main KiCad project manager frame.
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void language_change(wxCommandEvent &event)
void SetPcmButton(BITMAP_BUTTON *aButton)
void doCloseWindow() override
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
void OnUnarchiveFiles(wxCommandEvent &event)
const SEARCH_STACK & sys_search() override
Return a SEARCH_STACK pertaining to entire program.
void OnImportEasyEdaProFiles(wxCommandEvent &event)
Open dialog to import EasyEDA Pro schematic and board files.
void ProjectChanged() override
Notification event that the project has changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const wxString SchLegacyFileName()
wxWindow * GetToolCanvas() const override
Canvas access.
void OnImportEasyEdaFiles(wxCommandEvent &event)
Open dialog to import EasyEDA Std schematic and board files.
PROJECT_TREE_PANE * m_leftWin
const wxString GetProjectFileName() const
void updatePcmButtonBadge()
void OnBrowseInFileExplorer(wxCommandEvent &event)
KICAD_SETTINGS * kicadSettings() const
const wxString SchFileName()
void OnImportEagleFiles(wxCommandEvent &event)
Open dialog to import Eagle schematic and board files.
wxStatusBar * OnCreateStatusBar(int number, long style, wxWindowID id, const wxString &name) override
void OnExit(wxCommandEvent &event)
void LoadProject(const wxFileName &aProjectFileName)
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void OnSize(wxSizeEvent &event) override
virtual void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void DoWithAcceptedFiles() override
Execute action on accepted dropped file.
void OnOpenFileInTextEditor(wxCommandEvent &event)
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
int m_lastToolbarIconSize
const wxString PcbLegacyFileName()
KICAD_MANAGER_FRAME(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
bool CloseProject(bool aSave)
Closes the project, and saves it if aSave is true;.
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void OnIdle(wxIdleEvent &event)
void onToolbarSizeChanged()
void PrintPrjInfo()
Prints the current working directory name and the project name on the text panel.
ACTION_TOOLBAR * m_mainToolBar
void OnArchiveFiles(wxCommandEvent &event)
void OnImportCadstarArchiveFiles(wxCommandEvent &event)
Open dialog to import CADSTAR Schematic and PCB Archive files.
void RefreshProjectTree()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
BITMAP_BUTTON * m_pcmButton
PANEL_KICAD_LAUNCHER * m_launcher
wxString help_name() override
const wxString PcbFileName()
int m_updateCheck
General setting for various update checks.
std::vector< wxString > m_OpenProjects
std::vector< std::pair< wxString, wxString > > m_PcmRepositories
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all #KIWAY_PLAYERs.
static REPORTER & GetInstance()
wxString GetHelpFileName()
SEARCH_STACK & SysSearch()
APP_SETTINGS_BASE * PgmSettings()
PROJECT_TREE_PANE Window to display the tree files.
void EmptyTreePrj()
Delete all m_TreeProject entries.
void ReCreateTreePrj()
Create or modify the tree showing project file names.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Look for files in a number of paths.
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
std::vector< wxString > GetOpenProjects() const
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls BackupProject if a new backup is needed according to the current backup policy.
Base window classes and related definitions.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define KICAD_MANAGER_FRAME_NAME
const wxString GERBVIEW_EXE
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
const std::string LegacyPcbFileExtension
const std::string LegacySchematicFileExtension
const std::string GerberJobFileExtension
const std::string DrillFileExtension
const std::string LegacyProjectFileExtension
const std::string KiCadPcbFileExtension
bool IsGerberFileExtension(const wxString &ext)
const std::string ProjectFileExtension
const std::string KiCadSchematicFileExtension
const std::string GerberFileExtension
wxString AllFilesWildcard()
IDs used in KiCad main frame foe menuitems and tools.
@ ID_IMPORT_EAGLE_PROJECT
@ ID_IMPORT_EASYEDAPRO_PROJECT
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
@ ID_IMPORT_EASYEDA_PROJECT
@ ID_BROWSE_IN_FILE_EXPLORER
EVT_MENU_RANGE(ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, KICAD_MANAGER_FRAME::language_change) KICAD_MANAGER_FRAME
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
wxFont GetStatusFont(wxWindow *aWindow)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
Definition of file extensions used in Kicad.