54 #include <wx/filedlg.h> 55 #include <wx/dcclient.h> 59 #include <../pcbnew/plugins/kicad/pcb_plugin.h> 64 #include <ApplicationServices/ApplicationServices.h> 71 #define SEP() wxFileName::GetPathSeparator() 103 #include <wx/xml/xml.h> 107 const wxPoint& pos,
const wxSize& size ) :
110 m_leftWin( nullptr ),
111 m_launcher( nullptr ),
112 m_mainToolBar( nullptr )
114 m_active_project =
false;
115 m_leftWinWidth = 250;
116 m_aboutTitle = wxT(
"KiCad" );
128 CreateStatusBar( 2 );
133 wxIconBundle icon_bundle;
136 icon_bundle.AddIcon( icon );
138 icon_bundle.AddIcon( icon );
140 icon_bundle.AddIcon( icon );
142 SetIcons( icon_bundle );
155 RecreateBaseHToolbar();
158 m_auimgr.SetManagedWindow(
this );
159 m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
161 m_auimgr.AddPane( m_mainToolBar,
EDA_PANE().HToolbar().Name( wxT(
"MainToolbar" ) ).
Left()
169 m_auimgr.AddPane( m_leftWin,
EDA_PANE().Palette().Name( wxT(
"ProjectTree" ) ).
Left().Layer( 1 )
170 .Caption(
_(
"Project Files" ) ).PaneBorder(
false )
171 .MinSize( m_leftWinWidth, -1 ).BestSize( m_leftWinWidth, -1 ) );
173 m_auimgr.AddPane( m_launcher,
EDA_PANE().Canvas().Name( wxT(
"Launcher" ) ).
Center()
174 .Caption(
_(
"Editors" ) ).PaneBorder(
false )
175 .MinSize( m_launcher->GetBestSize() ) );
180 m_auimgr.GetPane( m_leftWin ).MinSize( 250, -1 );
182 wxSizer* mainSizer = GetSizer();
185 if( mainSizer &&
config()->m_Window.state.size_x == 0 &&
config()->m_Window.state.size_y == 0 )
186 mainSizer->Fit(
this );
189 SetTitle( wxT(
"KiCad" ) );
194 m_leftWin->SetFocus();
250 activeProjectCond.
Enable( activeProject );
285 wxString( wxEmptyString );
294 return fn.GetFullPath();
303 return fn.GetFullPath();
312 return fn.GetFullPath();
321 return fn.GetFullPath();
364 aEvent.StopPropagation();
370 if( aEvent.CanVeto() )
388 static std::atomic<unsigned int> lock_close_event( 0 );
390 if( ++lock_close_event > 1 )
397 Pgm().m_Quitting =
true;
402 lock_close_event = 0;
415 if( !
Kiway().PlayersClose(
false ) )
432 SetStatusText( wxEmptyString );
443 if( !aProjectFileName.Exists() )
454 Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
458 if( aProjectFileName.IsDirWritable() )
470 wxPostEvent(
this, cmd );
480 bool aCreateStubFiles )
482 wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
483 wxT(
"Project folder must exist and be writable to create a new project." ) );
486 if( !aProjectFileName.FileExists() )
488 wxFileName legacyPro( aProjectFileName );
491 if( legacyPro.FileExists() )
496 wxRemoveFile( legacyPro.GetFullPath() );
501 wxString srcFileName =
sys_search().FindValidPath( wxT(
"kicad.kicad_pro" ) );
503 wxFileName destFileName( aProjectFileName );
507 if( !wxFileName::FileExists( srcFileName )
508 || !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
510 wxFFile file( destFileName.GetFullPath(), wxT(
"wb" ) );
512 if( file.IsOpened() )
513 file.Write( wxT(
"{\n}\n") );
523 if( aCreateStubFiles )
525 wxFileName fn( aProjectFileName.GetFullPath() );
530 if( !fn.FileExists() )
532 wxFFile file( fn.GetFullPath(), wxT(
"wb" ) );
534 if( file.IsOpened() )
535 file.Write(
wxString::Format( wxT(
"(kicad_sch (version %d) (generator eeschema)\n" 536 " (paper \"A4\")\n (lib_symbols)\n" 537 " (symbol_instances)\n)\n" ),
546 wxFileName leg_fn( fn );
549 if( !fn.FileExists() && !leg_fn.FileExists() )
551 wxFFile file( fn.GetFullPath(), wxT(
"wb" ) );
553 if( file.IsOpened() )
555 file.Write(
wxString::Format( wxT(
"(kicad_pcb (version %d) (generator pcbnew)\n)" ),
575 wxFileDialog dlg(
this,
_(
"Load File to Edit" ), default_dir,
576 wxEmptyString, wildcard, wxFD_OPEN );
578 if( dlg.ShowModal() == wxID_CANCEL )
581 wxString filename = wxT(
"\"" );
582 filename += dlg.GetPath() + wxT(
"\"" );
584 if( !dlg.GetPath().IsEmpty() && !
Pgm().GetTextEditor().IsEmpty() )
604 int id =
event.GetId();
633 if( !file.IsEmpty() )
635 wxFileName fn( file );
637 title = fn.GetName();
639 if( !fn.IsDirWritable() )
640 title += wxS(
" " ) +
_(
"[Read Only]" );
644 title =
_(
"[no project loaded]" );
648 title += wxT(
" \u2014 " ) + wxString(
"KiCad" );
660 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
662 wxCHECK( settings, );
672 auto settings = dynamic_cast<KICAD_SETTINGS*>( aCfg );
674 wxCHECK( settings, );
676 settings->m_LeftWinWidth =
m_leftWin->GetSize().x;
692 wxStatusBar* statusBar = GetStatusBar();
693 int width = statusBar->GetSize().GetWidth() / 2;
697 wxClientDC dc(
this );
698 status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
701 SetStatusText( status );
723 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files )
725 int previousOpenCount =
726 std::count_if(
Prj().GetLocalSettings().m_files.begin(),
733 if( previousOpenCount > 0 )
736 previousOpenCount,
this );
744 progressReporter.
Update( i++,
747 wxFileName fn( file.fileName );
void OnBrowseInFileExplorer(wxCommandEvent &event)
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=nullptr) override
IDs used in KiCad main frame foe menuitems and tools.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
void language_change(wxCommandEvent &event)
const wxString GetProjectFileName() const
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow a frame to load its preference panels (if any) into the preferences dialog.
void SetMruPath(const wxString &aPath)
SEARCH_STACK & SysSearch()
SETTINGS_MANAGER * GetSettingsManager() const
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void doCloseWindow() override
const std::string ProjectFileExtension
const std::string LegacyPcbFileExtension
void OnIdle(wxIdleEvent &event)
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
PANEL_KICAD_LAUNCHER * m_launcher
wxWindow * GetToolCanvas() const override
Canvas access.
void OnImportEagleFiles(wxCommandEvent &event)
Open dialog to import Eagle schematic and board files.
virtual void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void OnOpenFileInTextEditor(wxCommandEvent &event)
const wxString SchLegacyFileName()
KICAD_SETTINGS * kicadSettings() const
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
void AddHotKeys(TOOL_MANAGER *aToolMgr)
Handle actions in the kicad manager frame.
Look for files in a number of paths.
std::vector< wxString > m_OpenProjects
void ReCreateTreePrj()
Create or modify the tree showing project file names.
Manage TOOL_ACTION objects.
const std::string KiCadPcbFileExtension
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all #KIWAY_PLAYERs.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
void LoadWindowState(const wxString &aFileName)
virtual const wxString GetProjectPath() const
Return the full path of the project.
wxString AllFilesWildcard()
PROJECT_TREE_PANE * m_leftWin
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
static TOOL_ACTION closeProject
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
PROJECT_TREE_PANE Window to display the tree files.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void OnImportCadstarArchiveFiles(wxCommandEvent &event)
Open dialog to import CADSTAR Schematic and PCB Archive files.
const wxString SchFileName()
static TOOL_ACTION editSchematic
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls BackupProject if a new backup is needed according to the current backup policy.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxString help_name() override
Definition of file extensions used in Kicad.
Base window classes and related definitions.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
const std::string LegacyProjectFileExtension
Handle actions that are shared between different applications.
void ProjectChanged() override
Notification event that the project has changed.
Specialization of the wxAuiPaneInfo class for KiCad panels.
const std::string LegacySchematicFileExtension
void OnArchiveFiles(wxCommandEvent &event)
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...
EVT_MENU_RANGE(ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, KICAD_MANAGER_FRAME::language_change) KICAD_MANAGER_FRAME
wxFont GetStatusFont(wxWindow *aWindow)
void RefreshProjectTree()
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void CreateNewProject(const wxFileName &aProjectFileName, bool aCreateStubFiles=true)
Creates a new project by setting up and initial project, schematic, and board files.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
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;.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
static TOOL_ACTION editPCB
const wxString PcbLegacyFileName()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
static TOOL_ACTION saveAs
std::vector< wxString > GetOpenProjects() const
#define KICAD_MANAGER_FRAME_NAME
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
void EmptyTreePrj()
Delete all m_TreeProject entries.
The base frame for deriving all KiCad main window classes.
const wxString PcbFileName()
APP_SETTINGS_BASE * PgmSettings()
const std::string KiCadSchematicFileExtension
wxProgressDialog with the option to also update the application progress on the taskbar
wxString GetHelpFileName()
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void LoadProject(const wxFileName &aProjectFileName)
void OnUnarchiveFiles(wxCommandEvent &event)
static REPORTER & GetInstance()
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
void OnExit(wxCommandEvent &event)
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
std::vector< PROJECT_FILE_STATE > m_files
Project scope.
const SEARCH_STACK & sys_search() override
Return a SEARCH_STACK pertaining to entire program.
void PrintPrjInfo()
Prints the current working directory name and the project name on the text panel.
The main KiCad project manager frame.
static TOOL_ACTION openTextEditor
void OnSize(wxSizeEvent &event) override
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.