61#include <wx/filedlg.h>
62#include <wx/dcclient.h>
64#include <wx/process.h>
68#include <../pcbnew/plugins/kicad/pcb_plugin.h>
73#include <ApplicationServices/ApplicationServices.h>
80#define SEP() wxFileName::GetPathSeparator()
115#include <wx/xml/xml.h>
118 const wxPoint& pos,
const wxSize& size ) :
121 m_leftWin( nullptr ),
122 m_launcher( nullptr ),
123 m_mainToolBar( nullptr )
125 m_active_project =
false;
126 m_leftWinWidth = 250;
127 m_aboutTitle =
"KiCad";
137 CreateStatusBar( 2 );
142 wxIconBundle icon_bundle;
147 icon_bundle.AddIcon( icon );
149 icon_bundle.AddIcon( icon );
151 icon_bundle.AddIcon( icon );
156 icon_bundle.AddIcon( icon );
158 icon_bundle.AddIcon( icon );
160 icon_bundle.AddIcon( icon );
163 SetIcons( icon_bundle );
168 m_pcmButton =
nullptr;
169 m_pcmUpdateCount = 0;
170 m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
171 [
this](
int aUpdateCount )
173 m_pcmUpdateCount = aUpdateCount;
177 updatePcmButtonBadge();
180 [
this](
const wxString aText )
185 SetStatusText( aText, 1 );
188 m_pcm->SetRepositoryList( kicadSettings()->m_PcmRepositories );
198 RecreateBaseHToolbar();
201 m_auimgr.SetManagedWindow(
this );
202 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
204 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name(
"MainToolbar" ).
Left()
212 m_auimgr.AddPane( m_leftWin,
EDA_PANE().Palette().Name(
"ProjectTree" ).
Left().Layer( 1 )
213 .Caption(
_(
"Project Files" ) ).PaneBorder(
false )
214 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
216 m_auimgr.AddPane( m_launcher,
EDA_PANE().Canvas().Name(
"Launcher" ).
Center()
217 .Caption(
_(
"Editors" ) ).PaneBorder(
false )
218 .MinSize( m_launcher->GetBestSize() ) );
223 m_auimgr.GetPane( m_leftWin ).MinSize( 250, -1 );
225 wxSizer* mainSizer = GetSizer();
228 if( mainSizer &&
config()->m_Window.state.size_x == 0 &&
config()->m_Window.state.size_y == 0 )
229 mainSizer->Fit(
this );
232 SetTitle( wxT(
"KiCad" ) );
237 m_leftWin->SetFocus();
259 DragAcceptFiles(
true );
272 m_pcm->StopBackgroundUpdate();
316#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
319 activeProjectCond.
Enable( activeProject );
362 wxString( wxEmptyString );
371 return fn.GetFullPath();
380 return fn.GetFullPath();
389 return fn.GetFullPath();
398 return fn.GetFullPath();
438 wxString ext = fileName.GetExt();
442 wxString fn = fileName.GetFullPath();
450 wxString gerberFiles;
455 wxString ext = fileName.GetExt();
460 gerberFiles += wxT(
'\"' );
461 gerberFiles += fileName.GetFullPath() + wxT(
'\"' );
462 gerberFiles = gerberFiles.Pad( 1 );
466 wxString fn = fileName.GetFullPath();
472 if( !gerberFiles.IsEmpty() )
476 if( wxFileExists( fullEditorName ) )
478 wxString command = fullEditorName +
" " + gerberFiles;
496 aEvent.StopPropagation();
502 if( aEvent.CanVeto() )
520 static std::atomic<unsigned int> lock_close_event( 0 );
522 if( ++lock_close_event > 1 )
529 Pgm().m_Quitting =
true;
534 lock_close_event = 0;
547 if( !
Kiway().PlayersClose(
false ) )
575 if( !aProjectFileName.Exists() )
586 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
590 if( aProjectFileName.IsDirWritable() )
602 wxPostEvent(
this, cmd );
612 bool aCreateStubFiles )
614 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
615 "Project folder must exist and be writable to create a new project." );
618 if( !aProjectFileName.FileExists() )
620 wxFileName legacyPro( aProjectFileName );
623 if( legacyPro.FileExists() )
628 wxRemoveFile( legacyPro.GetFullPath() );
633 wxString srcFileName =
sys_search().FindValidPath(
"kicad.kicad_pro" );
635 wxFileName destFileName( aProjectFileName );
639 if( !wxFileName::FileExists( srcFileName )
640 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
642 wxFFile file( destFileName.GetFullPath(),
"wb" );
644 if( file.IsOpened() )
645 file.Write( wxT(
"{\n}\n") );
655 if( aCreateStubFiles )
657 wxFileName fn( aProjectFileName.GetFullPath() );
662 if( !fn.FileExists() )
664 wxFFile file( fn.GetFullPath(),
"wb" );
666 if( file.IsOpened() )
667 file.Write(
wxString::Format(
"(kicad_sch (version %d) (generator eeschema)\n"
668 " (paper \"A4\")\n (lib_symbols)\n"
669 " (symbol_instances)\n)\n",
678 wxFileName leg_fn( fn );
681 if( !fn.FileExists() && !leg_fn.FileExists() )
683 wxFFile file( fn.GetFullPath(),
"wb" );
685 if( file.IsOpened() )
687 file.Write(
wxString::Format(
"(kicad_pcb (version %d) (generator pcbnew)\n)",
707 wxFileDialog dlg(
this,
_(
"Load File to Edit" ), default_dir,
708 wxEmptyString, wildcard, wxFD_OPEN );
710 if( dlg.ShowModal() == wxID_CANCEL )
713 wxString filename = dlg.GetPath();
715 if( !dlg.GetPath().IsEmpty() && !
Pgm().GetTextEditor().IsEmpty() )
735 int id =
event.GetId();
757 if( aEnvVarsChanged )
769 if( !file.IsEmpty() )
771 wxFileName fn( file );
773 title = fn.GetName();
775 if( !fn.IsDirWritable() )
776 title += wxS(
" " ) +
_(
"[Read Only]" );
780 title =
_(
"[no project loaded]" );
784 title += wxT(
" \u2014 " ) + wxString( wxS(
"KiCad" ) );
798 wxCHECK( settings, );
810 wxCHECK( settings, );
812 settings->m_LeftWinWidth =
m_leftWin->GetSize().x;
821 wxStatusBar* statusBar = GetStatusBar();
822 int width = statusBar->GetSize().GetWidth() / 2;
826 wxClientDC dc(
this );
827 status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
830 SetStatusText( status );
852 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files )
854 int previousOpenCount =
855 std::count_if(
Prj().GetLocalSettings().m_files.begin(),
856 Prj().GetLocalSettings().m_files.end(),
859 return !f.fileName.EndsWith( ProjectFileExtension ) && f.open;
862 if( previousOpenCount > 0 )
865 previousOpenCount,
this );
873 progressReporter.
Update( i++,
876 wxFileName fn( file.fileName );
900 if( settings->
m_updateCheck == KICAD_SETTINGS::UPDATE_CHECK::UNINITIALIZED )
902 if( wxMessageBox(
_(
"Would you like to automatically check for plugin updates on startup?" ),
903 _(
"Check for updates" ), wxICON_QUESTION | wxYES_NO,
this )
906 settings->
m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::ALLOWED;
911 settings->
m_updateCheck = KICAD_SETTINGS::UPDATE_CHECK::NOT_ALLOWED;
919 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
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
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.
Specialization of the wxAuiPaneInfo class for KiCad panels.
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 importNonKicadProj
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 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.
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.
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.
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 PrintPrjInfo()
Prints the current working directory name and the project name on the text panel.
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
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 CadstarPcbFileExtension
const std::string LegacySchematicFileExtension
const std::string GerberJobFileExtension
const std::string DrillFileExtension
const std::string EagleSchematicFileExtension
const std::string LegacyProjectFileExtension
const std::string KiCadPcbFileExtension
bool IsGerberFileExtension(const wxString &ext)
const std::string ProjectFileExtension
const std::string EaglePcbFileExtension
const std::string CadstarSchematicFileExtension
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_CADSTAR_ARCHIVE_PROJECT
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
@ 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.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#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.