KiCad PCB EDA Suite
Loading...
Searching...
No Matches
common.cpp File Reference
#include <eda_base_frame.h>
#include <kiplatform/app.h>
#include <project.h>
#include <common.h>
#include <env_vars.h>
#include <reporter.h>
#include <macros.h>
#include <mutex>
#include <wx/config.h>
#include <wx/log.h>
#include <wx/msgdlg.h>
#include <wx/stdpaths.h>
#include <wx/url.h>
#include <wx/utils.h>
#include <wx/regex.h>

Go to the source code of this file.

Enumerations

enum  Bracket { Bracket_None , Bracket_Normal = ')' , Bracket_Curly = '}' , Bracket_Max }
 

Functions

wxString ExpandTextVars (const wxString &aSource, const PROJECT *aProject, int aFlags)
 
wxString ExpandTextVars (const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int aFlags)
 
wxString GetTextVars (const wxString &aSource)
 Returns any variables unexpanded, e.g.
 
bool IsTextVar (const wxString &aSource)
 Returns true if the string is a text var, e.g starts with ${.
 
wxString KIwxExpandEnvVars (const wxString &str, const PROJECT *aProject, std::set< wxString > *aSet=nullptr)
 
const wxString ExpandEnvVarSubstitutions (const wxString &aString, const PROJECT *aProject)
 Replace any environment variable & text variable references with their values.
 
const wxString ResolveUriByEnvVars (const wxString &aUri, const PROJECT *aProject)
 Replace any environment and/or text variables in URIs.
 
bool EnsureFileDirectoryExists (wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
 Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
 
wxString EnsureFileExtension (const wxString &aFilename, const wxString &aExtension)
 It's annoying to throw up nag dialogs when the extension isn't right.
 
bool matchWild (const char *pat, const char *text, bool dot_special)
 Performance enhancements to file and directory operations.
 
long long TimestampDir (const wxString &aDirPath, const wxString &aFilespec)
 A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/filename.cpp.
 
bool WarnUserIfOperatingSystemUnsupported ()
 Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
 

Enumeration Type Documentation

◆ Bracket

enum Bracket
Enumerator
Bracket_None 
Bracket_Normal 
Bracket_Curly 
Bracket_Max 

Definition at line 47 of file common.cpp.

Function Documentation

◆ EnsureFileDirectoryExists()

bool EnsureFileDirectoryExists ( wxFileName *  aTargetFullFileName,
const wxString &  aBaseFilename,
REPORTER aReporter = nullptr 
)

Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.

Parameters
aTargetFullFileNamethe wxFileName containing the full path and file name to modify. The path may be absolute or relative to aBaseFilename .
aBaseFilenamea full filename. Only its path is used to set the aTargetFullFileName path.
aReportera point to a REPORTER object use to show messages (can be NULL)
Returns
true if aOutputDir already exists or was successfully created.

Definition at line 369 of file common.cpp.

References _, REPORTER::Report(), RPT_SEVERITY_ERROR, and RPT_SEVERITY_INFO.

Referenced by DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles(), DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles(), SCH_PLOTTER::createPlotFileName(), DIALOG_EXPORT_SVG::ExportSVGFile(), DIALOG_GENDRILL::GenDrillAndMapFiles(), DIALOG_SYMBOL_FIELDS_TABLE::OnExport(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

◆ EnsureFileExtension()

◆ ExpandEnvVarSubstitutions()

const wxString ExpandEnvVarSubstitutions ( const wxString &  aString,
const PROJECT aProject 
)

Replace any environment variable & text variable references with their values.

Parameters
aStringa string containing (perhaps) references to env var
Returns
the expanded environment variable.

Definition at line 348 of file common.cpp.

References KIwxExpandEnvVars().

Referenced by FILENAME_RESOLVER::addPath(), FILENAME_RESOLVER::checkEnvVarPath(), S3D_PLUGIN_MANAGER::checkPluginName(), DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles(), DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles(), FILENAME_RESOLVER::createPathList(), DIALOG_EXPORT_SVG::ExportSVGFile(), DIALOG_GENDRILL::GenDrillAndMapFiles(), LIB_TABLE_ROW::GetFullURI(), DIALOG_PLOT_SCHEMATIC::getOutputPath(), DIALOG_EXPORT_STEP::onBrowseClicked(), DIALOG_EXPORT_2581::onBrowseClicked(), DIALOG_EXPORT_ODBPP::onBrowseClicked(), TEXT_BUTTON_FILE_BROWSER::OnButtonClick(), PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), DIALOG_SYMBOL_FIELDS_TABLE::OnExport(), DIALOG_EXPORT_STEP::onExportButton(), DIALOG_GENDRILL::OnGenReportFile(), PANEL_DESIGN_BLOCK_LIB_TABLE::onMigrateLibraries(), PANEL_FP_LIB_TABLE::onMigrateLibraries(), DIALOG_PLOT::onOpenOutputDirectory(), DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked(), DIALOG_EXPORT_SVG::OnOutputDirectoryBrowseClicked(), DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked(), DIALOG_GENDRILL::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT::OnOutputDirectoryBrowseClicked(), DIALOG_SYMBOL_FIELDS_TABLE::OnOutputFileBrowseClicked(), DIALOG_PAGES_SETTINGS::OnWksFileSelection(), PLOT_CONTROLLER::OpenPlotfile(), DIALOG_PLOT::Plot(), SIM_LIB_MGR::ResolveLibraryPath(), FILENAME_RESOLVER::ResolvePath(), ResolveUriByEnvVars(), S3D_CACHE::Set3DConfigDir(), FILENAME_RESOLVER::Set3DConfigDir(), FILENAME_RESOLVER::SetProject(), FILENAME_RESOLVER::ShortenPath(), DRC_TEST_PROVIDER_MISC::testTextVars(), ERC_TESTER::TestTextVars(), and NETLIST_EXPORTER_SPICE::writeInclude().

◆ ExpandTextVars() [1/2]

◆ ExpandTextVars() [2/2]

wxString ExpandTextVars ( const wxString &  aSource,
const std::function< bool(wxString *)> *  aResolver,
int  aFlags 
)

Definition at line 71 of file common.cpp.

References FOR_ERC_DRC.

◆ GetTextVars()

◆ IsTextVar()

◆ KIwxExpandEnvVars()

wxString KIwxExpandEnvVars ( const wxString &  str,
const PROJECT aProject,
std::set< wxString > *  aSet = nullptr 
)

◆ matchWild()

bool matchWild ( const char *  pat,
const char *  text,
bool  dot_special 
)

Performance enhancements to file and directory operations.

Note: while it's annoying to have to make copies of wxWidgets stuff and then add platform-specific performance optimizations, the following routines offer SIGNIFICANT performance benefits. A copy of wxMatchWild(), which wxWidgets attributes to Douglas A. Lewis dalew.nosp@m.is@c.nosp@m.s.Buf.nosp@m.falo.nosp@m..EDU and ircII's reg.c.

This version is modified to skip any encoding conversions (for performance).

Definition at line 455 of file common.cpp.

References text.

Referenced by TimestampDir().

◆ ResolveUriByEnvVars()

const wxString ResolveUriByEnvVars ( const wxString &  aUri,
const PROJECT aProject 
)

Replace any environment and/or text variables in URIs.

Definition at line 361 of file common.cpp.

References ExpandEnvVarSubstitutions(), and ExpandTextVars().

Referenced by PDF_PLOTTER::EndPlot(), and GetAssociatedDocument().

◆ TimestampDir()

long long TimestampDir ( const wxString &  aDirPath,
const wxString &  aFilespec 
)

A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/filename.cpp.

This routine offers SIGNIFICANT performance benefits over using wxWidgets to gather timestamps from matching files in a directory.

Parameters
aDirPathis the directory to search.
aFilespecis a (wildcarded) file spec to match against.
Returns
a hash of the last-mod-dates of all matching files in the directory.

Definition at line 597 of file common.cpp.

References matchWild().

Referenced by DESIGN_BLOCK_IO::GetLibraryTimestamp(), GPCB_FPL_CACHE::GetTimestamp(), and FP_CACHE::GetTimestamp().

◆ WarnUserIfOperatingSystemUnsupported()

bool WarnUserIfOperatingSystemUnsupported ( )

Checks if the operating system is explicitly unsupported and displays a disclaimer message box.

Returns
true if the operating system is unsupported

Definition at line 696 of file common.cpp.

References _, and KIPLATFORM::APP::IsOperatingSystemUnsupported().

Referenced by PGM_BASE::InitPgm(), and COMMON_CONTROL::ReportBug().