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 <confirm.h>
#include <env_vars.h>
#include <advanced_config.h>
#include <reporter.h>
#include <macros.h>
#include <string_utils.h>
#include <text_eval/text_eval_wrapper.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, int aDepth)
 
wxString ResolveTextVars (const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
 Multi-pass text variable expansion and math expression evaluation.
 
wxString GetGeneratedFieldDisplayName (const wxString &aSource)
 Returns any variables unexpanded, e.g.
 
bool IsGeneratedField (const wxString &aSource)
 Returns true if the string is generated, e.g contains a single text var reference.
 
wxString DescribeRef (const wxString &aRef)
 Returns a user-visible HTML string describing a footprint reference designator.
 
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.
 
wxString JoinExtensions (const std::vector< std::string > &aExts)
 Join a list of file extensions for use in a file dialog.
 
bool matchWild (const char *pat, const char *text, bool dot_special)
 Performance enhancements to file and directory operations.
 
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 51 of file common.cpp.

Function Documentation

◆ DescribeRef()

wxString DescribeRef ( const wxString & aRef)

◆ 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 579 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_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 558 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(), PANEL_REMOTE_SYMBOL::ensureDestinationRoot(), LIBRARY_MANAGER::ExpandURI(), DIALOG_GENDRILL::genDrillAndMapFiles(), LIBRARY_MANAGER::GetFullURI(), DIALOG_PLOT_SCHEMATIC::getOutputPath(), JOBS_OUTPUT_ARCHIVE::HandleOutputs(), JOBS_OUTPUT_FOLDER::HandleOutputs(), DIALOG_EXPORT_2581::onBrowseClicked(), DIALOG_EXPORT_ODBPP::onBrowseClicked(), DIALOG_EXPORT_STEP::onBrowseClicked(), DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked(), DIALOG_REMOTE_SYMBOL_CONFIG::onBrowseDestination(), 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(), PANEL_DESTINATION::OnOpenOutput(), DIALOG_PLOT::onOpenOutputDirectory(), DIALOG_GEN_FOOTPRINT_POSITION::onOutputDirectoryBrowseClicked(), DIALOG_GENDRILL::onOutputDirectoryBrowseClicked(), DIALOG_PLOT::onOutputDirectoryBrowseClicked(), DIALOG_PLOT_SCHEMATIC::onOutputDirectoryBrowseClicked(), DIALOG_SYMBOL_FIELDS_TABLE::OnOutputFileBrowseClicked(), DIALOG_PAGES_SETTINGS::OnWksFileSelection(), PLOT_CONTROLLER::OpenPlotfile(), DIALOG_PLOT::Plot(), SIM_LIB_MGR::ResolveLibraryPath(), FILENAME_RESOLVER::ResolvePath(), ResolveUriByEnvVars(), JOBS_RUNNER::runSpecialCopyFiles(), JOBS_RUNNER::runSpecialExecute(), FILENAME_RESOLVER::Set3DConfigDir(), S3D_CACHE::Set3DConfigDir(), FILENAME_RESOLVER::SetProject(), SCH_BASE_FRAME::setSymWatcher(), FILENAME_RESOLVER::ShortenPath(), ERC_TESTER::TestTextVars(), DRC_TEST_PROVIDER_MISC::testTextVars(), and NETLIST_EXPORTER_SPICE::writeInclude().

◆ ExpandTextVars() [1/2]

wxString ExpandTextVars ( const wxString & aSource,
const PROJECT * aProject,
int aFlags )

Definition at line 62 of file common.cpp.

References ExpandTextVars(), and PROJECT::TextVarResolver().

Referenced by AddGerberX2Header(), GERBER_JOBFILE_WRITER::addJSONGeneralSpecs(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), DS_DRAW_ITEM_LIST::BuildFullText(), DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles(), EXPRESSION_EVALUATOR::createCombinedCallback(), DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles(), GENCAD_EXPORTER::createHeaderInfoData(), SCH_PLOTTER::createPDFFile(), KIGFX::SCH_PAINTER::expandLibItemTextVars(), ExpandTextVars(), ExpandTextVars(), DIALOG_GENDRILL::genDrillAndMapFiles(), FIELDS_EDITOR_GRID_DATA_MODEL::getFieldShownText(), GetGeneratedFieldDisplayName(), DIALOG_PLOT_SCHEMATIC::getOutputPath(), FIELDS_EDITOR_GRID_DATA_MODEL::GetValue(), API_HANDLER_COMMON::handleExpandTextVariables(), API_HANDLER_PCB::handleExpandTextVariables(), JOBS_OUTPUT_ARCHIVE::HandleOutputs(), JOBS_OUTPUT_FOLDER::HandleOutputs(), DRC_ENGINE::loadRules(), NETLIST_EXPORTER_XML::makeDesignHeader(), PANEL_SETUP_RULES::OnCompile(), DIALOG_SYMBOL_FIELDS_TABLE::OnExport(), DIALOG_EXPORT_STEP::onExportButton(), PANEL_DESTINATION::OnOpenOutput(), DIALOG_PLOT::onOpenOutputDirectory(), DIALOG_PLOT::onOutputDirectoryBrowseClicked(), PLOT_CONTROLLER::OpenPlotfile(), DIALOG_PLOT::Plot(), PCB_PLOTTER::Plot(), JOB::ResolveOutputPath(), ResolveTextVars(), ResolveUriByEnvVars(), and TITLE_BLOCK::TextVarResolver().

◆ ExpandTextVars() [2/2]

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

◆ GetGeneratedFieldDisplayName()

◆ IsGeneratedField()

◆ JoinExtensions()

wxString JoinExtensions ( const std::vector< std::string > & aExts)

Join a list of file extensions for use in a file dialog.

Parameters
aExts
Returns

Definition at line 648 of file common.cpp.

Referenced by PANEL_DESIGN_BLOCK_LIB_TABLE::PANEL_DESIGN_BLOCK_LIB_TABLE(), and PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ 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 678 of file common.cpp.

References text.

◆ ResolveTextVars()

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

Multi-pass text variable expansion and math expression evaluation.

Performs recursive resolution of both ${...} variable references and...} math expressions, then cleans up escape sequences (${...} and @{...}) to display literals.

This helper encapsulates the common pattern used across schematic text components:

  • While text contains ${...} or...} and depth < max:
  • Convert escape markers back to literals
Parameters
aSourceThe source text containing variables and/or expressions
aResolverFunction to resolve variable references
aDepthCurrent recursion depth (passed by reference, will be incremented)
Returns
Fully expanded and evaluated text with escape sequences cleaned up

Definition at line 296 of file common.cpp.

References EXPRESSION_EVALUATOR::Evaluate(), ExpandTextVars(), ADVANCED_CFG::GetCfg(), ADVANCED_CFG::m_ResolveTextRecursionDepth, and text.

Referenced by LIB_SYMBOL::GetShownKeyWords(), PCB_FIELD::GetShownText(), PCB_TABLECELL::GetShownText(), PCB_TEXT::GetShownText(), PCB_TEXTBOX::GetShownText(), SCH_LABEL_BASE::GetShownText(), SCH_TABLECELL::GetShownText(), SCH_TEXT::GetShownText(), SCH_TEXTBOX::GetShownText(), and SCH_ITEM::ResolveText().

◆ ResolveUriByEnvVars()

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

Replace any environment and/or text variables in URIs.

Definition at line 571 of file common.cpp.

References ExpandEnvVarSubstitutions(), and ExpandTextVars().

Referenced by PDF_PLOTTER::endPlotEmitResources(), GetAssociatedDocument(), and SCH_NAVIGATE_TOOL::HypertextCommand().

◆ 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 782 of file common.cpp.

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

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