65#include <wx/filedlg.h>
67#include <wx/process.h>
72#include <../pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
77#include <ApplicationServices/ApplicationServices.h>
84#define SEP() wxFileName::GetPathSeparator()
121#include <wx/xml/xml.h>
124 const wxPoint& pos,
const wxSize& size ) :
127 m_leftWin( nullptr ),
128 m_launcher( nullptr ),
129 m_mainToolBar( nullptr ),
130 m_lastToolbarIconSize( 0 )
132 const int defaultLeftWinWidth = FromDIP( 250 );
134 m_active_project =
false;
135 m_leftWinWidth = defaultLeftWinWidth;
136 m_aboutTitle =
"KiCad";
151 CreateStatusBar( 1 );
152 Pgm().GetBackgroundJobMonitor().RegisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
153 Pgm().GetNotificationsManager().RegisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
158 wxIconBundle icon_bundle;
163 icon_bundle.AddIcon( icon );
165 icon_bundle.AddIcon( icon );
167 icon_bundle.AddIcon( icon );
169 icon_bundle.AddIcon( icon );
171 icon_bundle.AddIcon( icon );
176 icon_bundle.AddIcon( icon );
178 icon_bundle.AddIcon( icon );
180 icon_bundle.AddIcon( icon );
182 icon_bundle.AddIcon( icon );
184 icon_bundle.AddIcon( icon );
187 SetIcons( icon_bundle );
192 m_pcmButton =
nullptr;
193 m_pcmUpdateCount = 0;
203 RecreateBaseHToolbar();
206 m_auimgr.SetManagedWindow(
this );
207 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
209 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name(
"MainToolbar" ).Left()
217 m_auimgr.AddPane( m_leftWin,
EDA_PANE().Palette().Name(
"ProjectTree" ).Left().Layer( 1 )
218 .Caption(
_(
"Project Files" ) ).PaneBorder(
false )
219 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
221 m_auimgr.AddPane( m_launcher,
EDA_PANE().Canvas().Name(
"Launcher" ).Center()
222 .Caption(
_(
"Editors" ) ).PaneBorder(
false )
223 .MinSize( m_launcher->GetBestSize() ) );
228 m_auimgr.GetPane( m_leftWin ).MinSize( defaultLeftWinWidth, -1 );
230 wxSizer* mainSizer = GetSizer();
233 if( mainSizer &&
config()->m_Window.state.size_x == 0 &&
config()->m_Window.state.size_y == 0 )
234 mainSizer->Fit(
this );
237 SetTitle( wxT(
"KiCad" ) );
242 m_leftWin->SetFocus();
254 DragAcceptFiles(
true );
263 Pgm().GetBackgroundJobMonitor().UnregisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
264 Pgm().GetNotificationsManager().UnregisterStatusBar( (
KISTATUSBAR*) GetStatusBar() );
271 m_pcm->StopBackgroundUpdate();
282 const wxString&
name )
294 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
295 [
this](
int aUpdateCount )
299 if( aUpdateCount > 0 )
301 Pgm().GetNotificationsManager().CreateOrUpdate(
303 _(
"PCM Updates Available" ),
304 wxString::Format(
_(
"%d package update(s) avaliable" ), aUpdateCount ),
309 Pgm().GetNotificationsManager().Remove( wxS(
"pcm" ) );
357#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
360 activeProjectCond.
Enable( activeProject );
403 wxString( wxEmptyString );
412 return fn.GetFullPath();
421 return fn.GetFullPath();
429 fn.SetExt( FILEEXT::PcbFileExtension );
430 return fn.GetFullPath();
439 return fn.GetFullPath();
484 wxString ext = fileName.GetExt();
488 wxString fn = fileName.GetFullPath();
496 wxString gerberFiles;
501 wxString ext = fileName.GetExt();
506 gerberFiles += wxT(
'\"' );
507 gerberFiles += fileName.GetFullPath() + wxT(
'\"' );
508 gerberFiles = gerberFiles.Pad( 1 );
512 wxString fn = fileName.GetFullPath();
518 if( !gerberFiles.IsEmpty() )
522 if( wxFileExists( fullEditorName ) )
524 wxString command = fullEditorName +
" " + gerberFiles;
542 aEvent.StopPropagation();
548 if( aEvent.CanVeto() )
566 static std::atomic<unsigned int> lock_close_event( 0 );
568 if( ++lock_close_event > 1 )
575 Pgm().m_Quitting =
true;
580 lock_close_event = 0;
593 if( !
Kiway().PlayersClose(
false ) )
621 if( !aProjectFileName.Exists() )
632 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
636 if( aProjectFileName.IsDirWritable() )
651 wxPostEvent(
this, cmd );
661 bool aCreateStubFiles )
663 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
664 "Project folder must exist and be writable to create a new project." );
667 if( !aProjectFileName.FileExists() )
669 wxFileName legacyPro( aProjectFileName );
672 if( legacyPro.FileExists() )
677 wxRemoveFile( legacyPro.GetFullPath() );
682 wxString srcFileName =
sys_search().FindValidPath(
"kicad.kicad_pro" );
684 wxFileName destFileName( aProjectFileName );
688 if( !wxFileName::FileExists( srcFileName )
689 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
691 wxFFile file( destFileName.GetFullPath(),
"wb" );
693 if( file.IsOpened() )
694 file.Write( wxT(
"{\n}\n") );
704 if( aCreateStubFiles )
706 wxFileName fn( aProjectFileName.GetFullPath() );
711 if( !fn.FileExists() )
713 wxFFile file( fn.GetFullPath(),
"wb" );
715 if( file.IsOpened() )
716 file.Write( wxString::Format(
"(kicad_sch (version %d) (generator \"eeschema\") (generator_version \"%s\")\n"
717 " (paper \"A4\")\n (lib_symbols)\n"
718 " (symbol_instances)\n)\n",
727 wxFileName leg_fn( fn );
730 if( !fn.FileExists() && !leg_fn.FileExists() )
732 wxFFile file( fn.GetFullPath(),
"wb" );
734 if( file.IsOpened() )
736 file.Write( wxString::Format(
"(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n)",
759 wxFileDialog dlg(
this,
_(
"Edit File in Text Editor" ), default_dir, wxEmptyString, wildcard,
762 if( dlg.ShowModal() == wxID_CANCEL )
765 wxString filename = dlg.GetPath();
767 if( !dlg.GetPath().IsEmpty() && !
Pgm().GetTextEditor().IsEmpty() )
787 int id =
event.GetId();
809 if(
m_pcm && aEnvVarsChanged )
830 if( !file.IsEmpty() )
832 wxFileName fn( file );
834 title = fn.GetName();
836 if( !fn.IsDirWritable() )
837 title += wxS(
" " ) +
_(
"[Read Only]" );
841 title =
_(
"[no project loaded]" );
845 title += wxT(
" \u2014 " ) + wxString( wxS(
"KiCad" ) );
859 wxCHECK( settings, );
871 wxCHECK( settings, );
873 settings->m_LeftWinWidth =
m_leftWin->GetSize().x;
884 wxString status = wxString::Format(
_(
"Project: %s" ),
Prj().GetProjectFullName() );
908 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files )
910 int previousOpenCount =
911 std::count_if(
Prj().GetLocalSettings().m_files.begin(),
912 Prj().GetLocalSettings().m_files.end(),
915 return !f.fileName.EndsWith( FILEEXT::ProjectFileExtension ) && f.open;
918 if( previousOpenCount > 0 )
921 previousOpenCount,
this );
924 std::set<wxString> openedFiles;
930 if( file.open && !openedFiles.count( file.fileName ) )
932 progressReporter.
Update( i++,
933 wxString::Format(
_(
"Restoring '%s'" ), file.fileName ) );
935 openedFiles.insert( file.fileName );
936 wxFileName fn( file.fileName );
960 if( !
Pgm().GetCommonSettings()->m_DoNotShowAgain.update_check_prompt )
965 Pgm().GetCommonSettings()->m_DoNotShowAgain.update_check_prompt =
true;
974 m_pcm->RunBackgroundUpdate();
977#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.
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)
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
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()
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 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()
std::unique_ptr< UPDATE_MANAGER > m_updateManager
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 (un...
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...
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
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.