67#include <wx/filedlg.h>
69#include <wx/process.h>
74#include <../pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
79#include <ApplicationServices/ApplicationServices.h>
88#define EDITORS_CAPTION _( "Editors" )
89#define PROJECT_FILES_CAPTION _( "Project Files" )
91#define SEP() wxFileName::GetPathSeparator()
127#include <wx/xml/xml.h>
130 const wxPoint& pos,
const wxSize& size ) :
133 m_leftWin( nullptr ),
134 m_launcher( nullptr ),
135 m_mainToolBar( nullptr ),
136 m_lastToolbarIconSize( 0 )
138 const int defaultLeftWinWidth = FromDIP( 250 );
140 m_active_project =
false;
141 m_leftWinWidth = defaultLeftWinWidth;
142 m_aboutTitle =
"KiCad";
157 CreateStatusBar( 1 );
164 wxIconBundle icon_bundle;
169 icon_bundle.AddIcon( icon );
171 icon_bundle.AddIcon( icon );
173 icon_bundle.AddIcon( icon );
175 icon_bundle.AddIcon( icon );
177 icon_bundle.AddIcon( icon );
182 icon_bundle.AddIcon( icon );
184 icon_bundle.AddIcon( icon );
186 icon_bundle.AddIcon( icon );
188 icon_bundle.AddIcon( icon );
190 icon_bundle.AddIcon( icon );
193 SetIcons( icon_bundle );
198 m_pcmButton =
nullptr;
199 m_pcmUpdateCount = 0;
207 RecreateBaseLeftToolbar();
210 m_auimgr.SetManagedWindow(
this );
211 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
213 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().VToolbar().Name(
"MainToolbar" ).Left()
221 m_auimgr.AddPane( m_leftWin,
EDA_PANE().Palette().Name(
"ProjectTree" ).Left().Layer( 1 )
223 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
225 wxSize client_size = GetClientSize();
226 m_notebook =
new wxAuiNotebook(
this, wxID_ANY, wxPoint( client_size.x, client_size.y ),
227 FromDIP( wxSize( 700, 590 ) ),
228 wxAUI_NB_TOP | wxAUI_NB_CLOSE_ON_ALL_TABS | wxAUI_NB_TAB_MOVE
229 | wxAUI_NB_SCROLL_BUTTONS | wxNO_BORDER );
231 m_notebook->Bind( wxEVT_AUINOTEBOOK_PAGE_CLOSE,
233 m_notebook->Bind( wxEVT_AUINOTEBOOK_PAGE_CLOSED,
237 m_notebook->Freeze();
238 m_launcher->SetClosable(
false );
240 m_notebook->SetTabCtrlHeight( 0 );
243 m_auimgr.AddPane( m_notebook,
EDA_PANE()
249 .MinSize( m_notebook->GetBestSize() ) );
254 m_auimgr.GetPane( m_leftWin ).MinSize( defaultLeftWinWidth, -1 );
257 wxSizer* mainSizer = GetSizer();
260 if( mainSizer &&
config()->m_Window.state.size_x == 0 &&
config()->m_Window.state.size_y == 0 )
263 mainSizer->Fit(
this );
268 SetTitle( wxT(
"KiCad" ) );
273 m_leftWin->SetFocus();
285 DragAcceptFiles(
true );
297 m_notebook->Unbind( wxEVT_AUINOTEBOOK_PAGE_CLOSE,
299 m_notebook->Unbind( wxEVT_AUINOTEBOOK_PAGE_CLOSED,
310 m_pcm->StopBackgroundUpdate();
336 wxAuiNotebook* ctrl = (wxAuiNotebook*) evt.GetEventObject();
338 wxWindow* pageWindow = ctrl->GetPage( evt.GetSelection() );
366 const wxString&
name )
378 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
379 [
this](
int aUpdateCount )
383 if( aUpdateCount > 0 )
387 _(
"PCM Updates Available" ),
388 wxString::Format(
_(
"%d package update(s) avaliable" ), aUpdateCount ),
441#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
444 activeProjectCond.
Enable( activeProject );
489 wxString( wxEmptyString );
498 return fn.GetFullPath();
507 return fn.GetFullPath();
515 fn.SetExt( FILEEXT::PcbFileExtension );
516 return fn.GetFullPath();
525 return fn.GetFullPath();
570 wxString ext = fileName.GetExt();
574 wxString fn = fileName.GetFullPath();
582 wxString gerberFiles;
587 wxString ext = fileName.GetExt();
592 gerberFiles += wxT(
'\"' );
593 gerberFiles += fileName.GetFullPath() + wxT(
'\"' );
594 gerberFiles = gerberFiles.Pad( 1 );
598 wxString fn = fileName.GetFullPath();
604 if( !gerberFiles.IsEmpty() )
608 if( wxFileExists( fullEditorName ) )
610 wxString command = fullEditorName +
" " + gerberFiles;
623 for(
size_t i = 0; i <
m_notebook->GetPageCount(); i++ )
629 if( !panel->GetCanClose() )
639 aEvent.StopPropagation();
645 if( aEvent.CanVeto() )
663 static std::atomic<unsigned int> lock_close_event( 0 );
665 if( ++lock_close_event > 1 )
671 for(
size_t i = 0; i <
m_notebook->GetPageCount(); i++ )
685 lock_close_event = 0;
699 for(
size_t i = 0; i <
m_notebook->GetPageCount(); i++ )
703 wxFileName jobsetFn( jobset->GetFilePath() );
704 jobsetFn.MakeRelativeTo(
Prj().GetProjectPath() );
721 if( !
Kiway().PlayersClose(
false ) )
732 if( shouldSaveProject )
747 for(
int i = (
int)
m_notebook->GetPageCount() - 1; i >= 0; i-- )
753 if( panel->GetProjectTied() )
766 bool aResaveProjectPreferences )
768 for(
size_t i = 0; i <
m_notebook->GetPageCount(); i++ )
772 if( aFileName.GetFullPath() == panel->GetFilePath() )
782 std::unique_ptr<JOBSET> jobsFile =
783 std::make_unique<JOBSET>( aFileName.GetFullPath().ToStdString() );
785 jobsFile->LoadFromFile();
790 m_notebook->AddPage( jobPanel, aFileName.GetFullName(),
true );
793 if( aResaveProjectPreferences )
806 if( !aProjectFileName.Exists() )
821 if( aProjectFileName.IsDirWritable() )
831 for(
const wxString& jobset :
Prj().GetLocalSettings().m_OpenJobSets )
833 wxFileName jobsetFn( jobset );
834 jobsetFn.MakeAbsolute(
Prj().GetProjectPath() );
836 if( jobsetFn.Exists() )
845 wxPostEvent(
this, cmd );
855 bool aCreateStubFiles )
857 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
858 "Project folder must exist and be writable to create a new project." );
861 if( !aProjectFileName.FileExists() )
863 wxFileName legacyPro( aProjectFileName );
866 if( legacyPro.FileExists() )
871 wxRemoveFile( legacyPro.GetFullPath() );
876 wxString srcFileName =
sys_search().FindValidPath(
"kicad.kicad_pro" );
878 wxFileName destFileName( aProjectFileName );
882 if( !wxFileName::FileExists( srcFileName )
883 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
885 wxFFile file( destFileName.GetFullPath(),
"wb" );
887 if( file.IsOpened() )
888 file.Write( wxT(
"{\n}\n") );
898 if( aCreateStubFiles )
900 wxFileName fn( aProjectFileName.GetFullPath() );
905 if( !fn.FileExists() )
907 wxFFile file( fn.GetFullPath(),
"wb" );
909 if( file.IsOpened() )
910 file.Write( wxString::Format(
"(kicad_sch (version %d) (generator \"eeschema\") (generator_version \"%s\")\n"
911 " (paper \"A4\")\n (lib_symbols)\n"
912 " (symbol_instances)\n)\n",
921 wxFileName leg_fn( fn );
924 if( !fn.FileExists() && !leg_fn.FileExists() )
926 wxFFile file( fn.GetFullPath(),
"wb" );
928 if( file.IsOpened() )
930 file.Write( wxString::Format(
"(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n)",
953 wxFileDialog dlg(
this,
_(
"Edit File in Text Editor" ), default_dir, wxEmptyString, wildcard,
956 if( dlg.ShowModal() == wxID_CANCEL )
959 wxString filename = dlg.GetPath();
961 if( !dlg.GetPath().IsEmpty() && !
Pgm().GetTextEditor().IsEmpty() )
981 int id =
event.GetId();
998 if( pageId != wxNOT_FOUND )
1014 if(
m_pcm && aEnvVarsChanged )
1016 m_pcm->ReadEnvVar();
1035 if( !file.IsEmpty() )
1037 wxFileName fn( file );
1039 title = fn.GetName();
1041 if( !fn.IsDirWritable() )
1042 title += wxS(
" " ) +
_(
"[Read Only]" );
1046 title =
_(
"[no project loaded]" );
1050 title += wxT(
" \u2014 " ) + wxString( wxS(
"KiCad" ) );
1064 wxCHECK( settings, );
1076 wxCHECK( settings, );
1078 settings->m_LeftWinWidth =
m_leftWin->GetSize().x;
1089 wxString status = wxString::Format(
_(
"Project: %s" ),
Prj().GetProjectFullName() );
1113 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files )
1115 int previousOpenCount =
1116 std::count_if(
Prj().GetLocalSettings().m_files.begin(),
1117 Prj().GetLocalSettings().m_files.end(),
1120 return !f.fileName.EndsWith( FILEEXT::ProjectFileExtension ) && f.open;
1123 if( previousOpenCount > 0 )
1126 previousOpenCount,
this );
1129 std::set<wxString> openedFiles;
1135 if( file.open && !openedFiles.count( file.fileName ) )
1137 progressReporter.
Update( i++,
1138 wxString::Format(
_(
"Restoring '%s'" ), file.fileName ) );
1140 openedFiles.insert( file.fileName );
1141 wxFileName fn( file.fileName );
1165 if( !
Pgm().GetCommonSettings()->m_DoNotShowAgain.update_check_prompt )
1168 prompt->ShowModal();
1179 m_pcm->RunBackgroundUpdate();
1182#ifdef KICAD_UPDATE_CHECK
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.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
Handle actions that are shared between different applications.
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
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
Associate file 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 the close window event handler after frames are asked if they can close.
Specialization of the wxAuiPaneInfo class for KiCad panels.
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
static TOOL_ACTION viewDroppedGerbers
static TOOL_ACTION editPCB
static TOOL_ACTION loadProject
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION closeProject
static TOOL_ACTION openJobsetFile
static TOOL_ACTION newJobsetFile
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)
wxString m_FileWatcherInfo
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()
void RecreateBaseLeftToolbar()
(Re)Create the left vertical toolbar
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
Create the status line (like a wxStatusBar).
void OnExit(wxCommandEvent &event)
void OpenJobsFile(const wxFileName &aFileName, bool aCreate=false, bool aResaveProjectPreferences=true)
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
Return 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 onNotebookPageCloseRequest(wxAuiNotebookEvent &evt)
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 SaveOpenJobSetsToLocalSettings(bool aIsExplicitUserSave=false)
void onNotebookPageCountChanged(wxAuiNotebookEvent &evt)
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
void HideTabsIfNeeded()
Hides the tabs for Editor notebook if there is only 1 page.
wxString help_name() override
const wxString PcbFileName()
std::unique_ptr< UPDATE_MANAGER > m_updateManager
wxAuiNotebook * m_notebook
std::vector< wxString > m_OpenProjects
std::vector< std::pair< wxString, wxString > > m_PcmRepositories
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
void SetEllipsedTextField(const wxString &aText, int aFieldId)
Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size to the field size.
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.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void CreateOrUpdate(const wxString &aKey, const wxString &aTitle, const wxString &aDescription, const wxString &aHref=wxEmptyString)
Create a notification with the given parameters or updates an existing one with the same key.
void Remove(const wxString &aKey)
Remove a notification by key.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Remove status bar from handling.
static REPORTER & GetInstance()
void SetClosable(bool aYes)
virtual bool GetCanClose()
void SetProjectTied(bool aYes)
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
wxString GetHelpFileName()
SEARCH_STACK & SysSearch()
APP_SETTINGS_BASE * PgmSettings()
The project local settings are things that are attached to a particular project, but also might be pa...
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
std::vector< wxString > m_OpenJobSets
PROJECT_TREE_PANE Window to display the tree files.
void EmptyTreePrj()
Delete all m_TreeProject entries.
void FileWatcherReset()
Reinit the watched paths Should be called after opening a new project to rebuild the list of watched ...
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
virtual PROJECT_FILE & GetProjectFile() 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)
Save a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
bool IsProjectOpen() const
Helper for checking if we have a project open.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
std::vector< wxString > GetOpenProjects() const
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Call BackupProject() if a new backup is needed according to the current backup policy.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
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...
static const std::string LegacySchematicFileExtension
static const std::string GerberJobFileExtension
static const std::string GerberFileExtension
static const std::string ProjectFileExtension
static const std::string LegacyPcbFileExtension
static const std::string LegacyProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string DrillFileExtension
static const std::string KiCadPcbFileExtension
static wxString AllFilesWildcard()
static bool IsGerberFileExtension(const wxString &ext)
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
#define PROJECT_FILES_CAPTION
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
PGM_BASE & Pgm()
The global program "get" accessor.
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
KIWAY Kiway(KFCTL_STANDALONE)
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.