KiCad PCB EDA Suite
common.cpp File Reference
#include <fctsys.h>
#include <eda_base_frame.h>
#include <base_struct.h>
#include <common.h>
#include <macros.h>
#include <base_units.h>
#include <reporter.h>
#include <wx/process.h>
#include <wx/config.h>
#include <wx/utils.h>
#include <wx/stdpaths.h>
#include <wx/url.h>
#include <pgm_base.h>
#include <ki_mutex.h>

Go to the source code of this file.

Enumerations

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

Functions

wxSize GetTextSize (const wxString &aSingleLine, wxWindow *aWindow)
 Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window. More...
 
bool EnsureTextCtrlWidth (wxTextCtrl *aCtrl, const wxString *aString)
 Set the minimum pixel width on a text control in order to make a text string be fully visible within it. More...
 
void wxStringSplit (const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
 Split aString to a string list separated at aSplitter. More...
 
int ProcessExecute (const wxString &aCommandLine, int aFlags, wxProcess *callback)
 Run a command in a child process. More...
 
timestamp_t GetNewTimeStamp ()
 
double RoundTo0 (double x, double precision)
 Round to the nearest precision. More...
 
wxConfigBase * GetNewConfig (const wxString &aProgName)
 Create a new wxConfig so we can put configuration files in a more proper place for each platform. More...
 
wxString GetKicadConfigPath ()
 Return the user configuration path used to store KiCad's configuration files. More...
 
wxString KIwxExpandEnvVars (const wxString &str)
 
const wxString ExpandEnvVarSubstitutions (const wxString &aString)
 Replace any environment variable references with their values. More...
 
const wxString ResolveUriByEnvVars (const wxString &aUri)
 Replace any environment variables in file-path uris (leaving network-path URIs alone). More...
 
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. More...
 
bool matchWild (const char *pat, const char *text, bool dot_special)
 A copy of wxMatchWild(), which wxWidgets attributes to Douglas A. More...
 
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. More...
 

Variables

COLOR4D g_GhostColor
 Global variables definitions. More...
 

Enumeration Type Documentation

enum Bracket
Enumerator
Bracket_None 
Bracket_Normal 
Bracket_Curly 
Bracket_Max 

Definition at line 253 of file common.cpp.

254 {
255  Bracket_None,
256  Bracket_Normal = ')',
257  Bracket_Curly = '}',
258 #ifdef __WINDOWS__
259  Bracket_Windows = '%', // yeah, Windows people are a bit strange ;-)
260 #endif
262 };

Function Documentation

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

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

References GetChars(), REPORTER::Report(), REPORTER::RPT_ERROR, and REPORTER::RPT_INFO.

Referenced by DIALOG_GEN_FOOTPRINT_POSITION::CreateFiles(), DIALOG_PLOT_SCHEMATIC::createPlotFileName(), DIALOG_EXPORT_SVG::ExportSVGFile(), DIALOG_GENDRILL::GenDrillAndMapFiles(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

419 {
420  wxString msg;
421  wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
422 
423  // make aTargetFullFileName path, which is relative to aBaseFilename path (if it is not
424  // already an absolute path) absolute:
425  if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
426  {
427  if( aReporter )
428  {
429  msg.Printf( _( "Cannot make path \"%s\" absolute with respect to \"%s\"." ),
430  GetChars( aTargetFullFileName->GetPath() ),
431  GetChars( baseFilePath ) );
432  aReporter->Report( msg, REPORTER::RPT_ERROR );
433  }
434 
435  return false;
436  }
437 
438  // Ensure the path of aTargetFullFileName exists, and create it if needed:
439  wxString outputPath( aTargetFullFileName->GetPath() );
440 
441  if( !wxFileName::DirExists( outputPath ) )
442  {
443  if( wxMkdir( outputPath ) )
444  {
445  if( aReporter )
446  {
447  msg.Printf( _( "Output directory \"%s\" created.\n" ), GetChars( outputPath ) );
448  aReporter->Report( msg, REPORTER::RPT_INFO );
449  return true;
450  }
451  }
452  else
453  {
454  if( aReporter )
455  {
456  msg.Printf( _( "Cannot create output directory \"%s\".\n" ),
457  GetChars( outputPath ) );
458  aReporter->Report( msg, REPORTER::RPT_ERROR );
459  }
460 
461  return false;
462  }
463  }
464 
465  return true;
466 }
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool EnsureTextCtrlWidth ( wxTextCtrl *  aCtrl,
const wxString *  aString = NULL 
)

Set the minimum pixel width on a text control in order to make a text string be fully visible within it.

The current font within the text control is considered. The text can come either from the control or be given as an argument. If the text control is larger than needed, then nothing is done.

Parameters
aCtrlthe text control to potentially make wider.
aStringthe text that is used in sizing the control's pixel width. If NULL, then the text already within the control is used.
Returns
bool - true if the aCtrl had its size changed, else false.

Definition at line 101 of file common.cpp.

References GetTextSize().

Referenced by GERBVIEW_FRAME::UpdateTitleAndInfo().

102 {
103  wxWindow* window = aCtrl->GetParent();
104 
105  if( !window )
106  window = aCtrl;
107 
108  wxString ctrlText;
109 
110  if( !aString )
111  {
112  ctrlText = aCtrl->GetValue();
113  aString = &ctrlText;
114  }
115 
116  wxSize textz = GetTextSize( *aString, window );
117  wxSize ctrlz = aCtrl->GetSize();
118 
119  if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
120  {
121  ctrlz.SetWidth( textz.GetWidth() + 10 );
122  aCtrl->SetSizeHints( ctrlz );
123  return true;
124  }
125 
126  return false;
127 }
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:86
const wxString ExpandEnvVarSubstitutions ( const wxString &  aString)

Replace any environment variable references with their values.

Parameters
aString= a string containing (perhaps) references to env var
Returns
a string where env var are replaced by their value

Definition at line 389 of file common.cpp.

References KIwxExpandEnvVars().

Referenced by FILENAME_RESOLVER::addPath(), FILENAME_RESOLVER::checkEnvVarPath(), S3D_PLUGIN_MANAGER::checkPluginName(), S3D_PLUGIN_MANAGER::checkPluginPath(), FILENAME_RESOLVER::createPathList(), LIB_TABLE::ExpandSubstitutions(), S3D_CACHE::Get3DConfigDir(), WORKSHEET_LAYOUT::MakeFullFileName(), FILENAME_RESOLVER::ResolvePath(), ResolveUriByEnvVars(), FILENAME_RESOLVER::Set3DConfigDir(), S3D_CACHE::Set3DConfigDir(), FILENAME_RESOLVER::SetProjectDir(), and FILENAME_RESOLVER::ShortenPath().

390 {
391  // wxGetenv( wchar_t* ) is not re-entrant on linux.
392  // Put a lock on multithreaded use of wxGetenv( wchar_t* ), called from wxEpandEnvVars(),
393  static MUTEX getenv_mutex;
394 
395  MUTLOCK lock( getenv_mutex );
396 
397  // We reserve the right to do this another way, by providing our own member
398  // function.
399  return KIwxExpandEnvVars( aString );
400 }
wxString KIwxExpandEnvVars(const wxString &str)
Definition: common.cpp:268
boost::interprocess::interprocess_mutex MUTEX
Establish KiCad MUTEX choices here in this file: typedef MUTEX and typedef MUTLOCK.
Definition: ki_mutex.h:42
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
wxString GetKicadConfigPath ( )

Return the user configuration path used to store KiCad's configuration files.

The configuration path order of precedence is determined by the following criteria:

  • The value of the KICAD_CONFIG_HOME environment variable
  • The value of the XDG_CONFIG_HOME environment variable.
  • The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended as required on Linux builds.
Returns
A wxString containing the config path for Kicad

Definition at line 210 of file common.cpp.

Referenced by FP_LIB_TABLE::GetGlobalTableFileName(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), GetNewConfig(), ReadHotkeyConfigFile(), EDA_BASE_FRAME::WriteHotkeyConfig(), and CACHE_WRAPPER::~CACHE_WRAPPER().

211 {
212  wxFileName cfgpath;
213 
214  // http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
215  cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
216 
217  // GetUserConfigDir() does not default to ~/.config which is the current standard
218  // configuration file location on Linux. This has been fixed in later versions of wxWidgets.
219 #if !defined( __WXMSW__ ) && !defined( __WXMAC__ )
220  wxArrayString dirs = cfgpath.GetDirs();
221 
222  if( dirs.Last() != ".config" )
223  cfgpath.AppendDir( ".config" );
224 #endif
225 
226  wxString envstr;
227 
228  // This shouldn't cause any issues on Windows or MacOS.
229  if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
230  {
231  // Override the assignment above with XDG_CONFIG_HOME
232  cfgpath.AssignDir( envstr );
233  }
234 
235  cfgpath.AppendDir( wxT( "kicad" ) );
236 
237  // Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path.
238  if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
239  {
240  // Override the assignment above with KICAD_CONFIG_HOME
241  cfgpath.AssignDir( envstr );
242  }
243 
244  if( !cfgpath.DirExists() )
245  {
246  cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
247  }
248 
249  return cfgpath.GetPath();
250 }
wxConfigBase* GetNewConfig ( const wxString &  aProgName)

Create a new wxConfig so we can put configuration files in a more proper place for each platform.

This is generally $HOME/.config/kicad/ in Linux according to the FreeDesktop specification at http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html The config object created here should be destroyed by the caller.

Parameters
aProgNameis the name of the program calling this function - can be obtained by calling Pgm().App().GetAppName(). This will be the actual file name of the config file.
Returns
A pointer to a new wxConfigBase derived object is returned. The caller is in charge of deleting it.

Definition at line 198 of file common.cpp.

References GetKicadConfigPath().

Referenced by BIN_MOD::Init(), PGM_BASE::InitPgm(), and PGM_BASE::loadCommonSettings().

199 {
200  wxConfigBase* cfg = 0;
201  wxFileName configname;
202  configname.AssignDir( GetKicadConfigPath() );
203  configname.SetFullName( aProgName );
204 
205  cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
206  return cfg;
207 }
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:210
wxSize GetTextSize ( const wxString &  aSingleLine,
wxWindow *  aWindow 
)

Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window.

Definition at line 86 of file common.cpp.

Referenced by PCB_EDIT_FRAME::CreateTextePcb(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), EDA_DRAW_FRAME::EDA_DRAW_FRAME(), EnsureTextCtrlWidth(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::recalculateColumns(), PL_EDITOR_FRAME::ReCreateHToolbar(), BOARD_DESIGN_SETTINGS::SetBoardThickness(), ZONE_SETTINGS::SetupLayersList(), and TEXTE_PCB::TransformShapeWithClearanceToPolygonSet().

87 {
88  wxCoord width;
89  wxCoord height;
90 
91  {
92  wxClientDC dc( aWindow );
93  dc.SetFont( aWindow->GetFont() );
94  dc.GetTextExtent( aSingleLine, &width, &height );
95  }
96 
97  return wxSize( width, height );
98 }
wxString KIwxExpandEnvVars ( const wxString &  str)

Definition at line 268 of file common.cpp.

References Bracket_Curly, Bracket_None, and Bracket_Normal.

Referenced by ExpandEnvVarSubstitutions().

269 {
270  size_t strlen = str.length();
271 
272  wxString strResult;
273  strResult.Alloc(strlen);
274 
275  for ( size_t n = 0; n < strlen; n++ ) {
276  wxUniChar str_n = str[n];
277 
278  switch ( str_n.GetValue() ) {
279 #ifdef __WINDOWS__
280  case wxT('%'):
281 #endif // __WINDOWS__
282  case wxT('$'):
283  {
284  Bracket bracket;
285 #ifdef __WINDOWS__
286  if ( str_n == wxT('%') )
287  bracket = Bracket_Windows;
288  else
289 #endif // __WINDOWS__
290  if ( n == strlen - 1 ) {
291  bracket = Bracket_None;
292  }
293  else {
294  switch ( str[n + 1].GetValue() ) {
295  case wxT('('):
296  bracket = Bracket_Normal;
297  str_n = str[++n]; // skip the bracket
298  break;
299 
300  case wxT('{'):
301  bracket = Bracket_Curly;
302  str_n = str[++n]; // skip the bracket
303  break;
304 
305  default:
306  bracket = Bracket_None;
307  }
308  }
309 
310  size_t m = n + 1;
311  wxUniChar str_m = str[m];
312 
313  while ( m < strlen && (wxIsalnum(str_m) || str_m == wxT('_')) )
314  str_m = str[++m];
315 
316  wxString strVarName(str.c_str() + n + 1, m - n - 1);
317 
318 #ifdef __WXWINCE__
319  const bool expanded = false;
320 #else
321  // NB: use wxGetEnv instead of wxGetenv as otherwise variables
322  // set through wxSetEnv may not be read correctly!
323  bool expanded = false;
324  wxString tmp;
325  if (wxGetEnv(strVarName, &tmp))
326  {
327  strResult += tmp;
328  expanded = true;
329  }
330  else
331 #endif
332  {
333  // variable doesn't exist => don't change anything
334 #ifdef __WINDOWS__
335  if ( bracket != Bracket_Windows )
336 #endif
337  if ( bracket != Bracket_None )
338  strResult << str[n - 1];
339  strResult << str_n << strVarName;
340  }
341 
342  // check the closing bracket
343  if ( bracket != Bracket_None ) {
344  if ( m == strlen || str_m != (wxChar)bracket ) {
345  // under MSW it's common to have '%' characters in the registry
346  // and it's annoying to have warnings about them each time, so
347  // ignroe them silently if they are not used for env vars
348  //
349  // under Unix, OTOH, this warning could be useful for the user to
350  // understand why isn't the variable expanded as intended
351 #ifndef __WINDOWS__
352  wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."),
353  (char)bracket, (unsigned int) (m + 1), str.c_str());
354 #endif // __WINDOWS__
355  }
356  else {
357  // skip closing bracket unless the variables wasn't expanded
358  if ( !expanded )
359  strResult << (wxChar)bracket;
360  str_m = str[++m];
361  }
362  }
363 
364  n = m - 1; // skip variable name
365  str_n = str[n];
366  }
367  break;
368 
369  case wxT('\\'):
370  // backslash can be used to suppress special meaning of % and $
371  if ( n != strlen - 1 && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
372  str_n = str[++n];
373  strResult += str_n;
374 
375  break;
376  }
377  //else: fall through
378 
379  default:
380  strResult += str_n;
381  }
382  }
383 
384  return strResult;
385 }
if(dlg.ShowModal()==wxID_OK)
Definition: selcolor.cpp:75
const string & str
Definition: json11.cpp:596
Bracket
Definition: common.cpp:253
bool matchWild ( const char *  pat,
const char *  text,
bool  dot_special 
)

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

Referenced by TimestampDir().

616 {
617  if ( !*text )
618  {
619  /* Match if both are empty. */
620  return !*pat;
621  }
622 
623  const char *m = pat,
624  *n = text,
625  *ma = NULL,
626  *na = NULL;
627  int just = 0,
628  acount = 0,
629  count = 0;
630 
631  if (dot_special && (*n == '.'))
632  {
633  /* Never match so that hidden Unix files
634  * are never found. */
635  return false;
636  }
637 
638  for (;;)
639  {
640  if (*m == '*')
641  {
642  ma = ++m;
643  na = n;
644  just = 1;
645  acount = count;
646  }
647  else if (*m == '?')
648  {
649  m++;
650  if (!*n++)
651  return false;
652  }
653  else
654  {
655  if (*m == '\\')
656  {
657  m++;
658  /* Quoting "nothing" is a bad thing */
659  if (!*m)
660  return false;
661  }
662  if (!*m)
663  {
664  /*
665  * If we are out of both strings or we just
666  * saw a wildcard, then we can say we have a
667  * match
668  */
669  if (!*n)
670  return true;
671  if (just)
672  return true;
673  just = 0;
674  goto not_matched;
675  }
676  /*
677  * We could check for *n == NULL at this point, but
678  * since it's more common to have a character there,
679  * check to see if they match first (m and n) and
680  * then if they don't match, THEN we can check for
681  * the NULL of n
682  */
683  just = 0;
684  if (*m == *n)
685  {
686  m++;
687  count++;
688  n++;
689  }
690  else
691  {
692 
693  not_matched:
694 
695  /*
696  * If there are no more characters in the
697  * string, but we still need to find another
698  * character (*m != NULL), then it will be
699  * impossible to match it
700  */
701  if (!*n)
702  return false;
703 
704  if (ma)
705  {
706  m = ma;
707  n = ++na;
708  count = acount;
709  }
710  else
711  return false;
712  }
713  }
714  }
715 }
int ProcessExecute ( const wxString &  aCommandLine,
int  aFlags = wxEXEC_ASYNC,
wxProcess *  callback = NULL 
)

Run a command in a child process.

Parameters
aCommandLineThe process and any arguments to it all in a single string.
aFlagsThe same args as allowed for wxExecute()
callbackwxProcess implementing OnTerminate to be run when the child process finishes
Returns
int - pid of process, 0 in case of error (like return values of wxExecute())

Definition at line 153 of file common.cpp.

Referenced by ExecuteFile(), GetAssociatedDocument(), DIALOG_FREEROUTE::OnLaunchButtonClick(), OpenFile(), OpenPDF(), and SCH_EDIT_FRAME::WriteNetListFile().

154 {
155  return wxExecute( aCommandLine, aFlags, callback );
156 }
const wxString ResolveUriByEnvVars ( const wxString &  aUri)

Replace any environment variables in file-path uris (leaving network-path URIs alone).

Definition at line 403 of file common.cpp.

References ExpandEnvVarSubstitutions().

Referenced by FIELDS_GRID_TRICKS::doPopupSelection(), FIELDS_EDITOR_GRID_TRICKS::doPopupSelection(), TEXT_BUTTON_URL::OnButtonClick(), and SCH_EDIT_FRAME::Process_Special_Functions().

404 {
405  // URL-like URI: return as is.
406  wxURL url( aUri );
407  if( url.GetError() == wxURL_NOERR )
408  return aUri;
409 
410  // Otherwise, the path points to a local file. Resolve environment
411  // variables if any.
412  return ExpandEnvVarSubstitutions( aUri );
413 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:389
double RoundTo0 ( double  x,
double  precision 
)

Round to the nearest precision.

Try to approximate a coordinate using a given precision to prevent rounding errors when converting from inches to mm.

ie round the unit value to 0 if unit is 1 or 2, or 8 or 9

Definition at line 175 of file common.cpp.

References KiROUND().

Referenced by SCH_BASE_FRAME::UpdateStatusBar().

176 {
177  assert( precision != 0 );
178 
179  long long ix = KiROUND( x * precision );
180 
181  if ( x < 0.0 )
182  ix = -ix;
183 
184  int remainder = ix % 10; // remainder is in precision mm
185 
186  if( remainder <= 2 )
187  ix -= remainder; // truncate to the near number
188  else if( remainder >= 8 )
189  ix += 10 - remainder; // round to near number
190 
191  if ( x < 0 )
192  ix = -ix;
193 
194  return (double) ix / precision;
195 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
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.

TimestampDir

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

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

Definition at line 751 of file common.cpp.

References matchWild().

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

752 {
753  long long timestamp = 0;
754 
755 #if defined(__WIN32__)
756  // Win32 version.
757  // Save time by not searching for each path twice: once in wxDir.GetNext() and once in
758  // wxFileName.GetModificationTime(). Also cuts out wxWidgets' string-matching and case
759  // conversion by staying on the MSW side of things.
760  std::wstring filespec( aDirPath.t_str() );
761  filespec += '\\';
762  filespec += aFilespec.t_str();
763 
764  WIN32_FIND_DATA findData;
765  wxDateTime lastModDate;
766 
767  HANDLE fileHandle = ::FindFirstFile( filespec.data(), &findData );
768 
769  if( fileHandle != INVALID_HANDLE_VALUE )
770  {
771  do
772  {
773  ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
774  timestamp += lastModDate.GetValue().GetValue();
775  }
776  while ( FindNextFile( fileHandle, &findData ) != 0);
777  }
778 
779  FindClose( fileHandle );
780 #else
781  // POSIX version.
782  // Save time by not converting between encodings -- do everything on the file-system side.
783  std::string filespec( aFilespec.fn_str() );
784  std::string dir_path( aDirPath.fn_str() );
785 
786  DIR* dir = opendir( dir_path.c_str() );
787 
788  if( dir )
789  {
790  for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
791  {
792  if( !matchWild( filespec.c_str(), dir_entry->d_name, true ) )
793  continue;
794 
795  std::string entry_path = dir_path + '/' + dir_entry->d_name;
796  struct stat entry_stat;
797 
798  wxCRT_Lstat( entry_path.c_str(), &entry_stat );
799 
800  // Timestamp the source file, not the symlink
801  if( S_ISLNK( entry_stat.st_mode ) ) // wxFILE_EXISTS_SYMLINK
802  {
803  char buffer[ PATH_MAX + 1 ];
804  ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
805 
806  if( pathLen > 0 )
807  {
808  buffer[ pathLen ] = '\0';
809  entry_path = dir_path + buffer;
810 
811  wxCRT_Lstat( entry_path.c_str(), &entry_stat );
812  }
813  }
814 
815  if( S_ISREG( entry_stat.st_mode ) ) // wxFileExists()
816  timestamp += entry_stat.st_mtime * 1000;
817  }
818  }
819 #endif
820 
821  return timestamp;
822 }
bool matchWild(const char *pat, const char *text, bool dot_special)
A copy of wxMatchWild(), which wxWidgets attributes to Douglas A.
Definition: common.cpp:615
void wxStringSplit ( const wxString &  aText,
wxArrayString &  aStrings,
wxChar  aSplitter 
)

Split aString to a string list separated at aSplitter.

Parameters
aTextis the text to split
aStringswill contain the splitted lines
aSplitteris the 'split' character

Definition at line 130 of file common.cpp.

Referenced by CINFO3D_VISU::AddShapeWithClearanceToContainer(), EDA_TEXT::Draw(), export_vrml_pcbtext(), EDA_TEXT::GetTextBox(), HTML_MESSAGE_BOX::ListSet(), DIALOG_FOOTPRINT_WIZARD_LIST::onShowTrace(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotTextePcb(), TEXTE_PCB::TransformShapeWithClearanceToPolygonSet(), and EDA_TEXT::TransformTextShapeToSegmentList().

131 {
132  wxString tmp;
133 
134  for( unsigned ii = 0; ii < aText.Length(); ii++ )
135  {
136  if( aText[ii] == aSplitter )
137  {
138  aStrings.Add( tmp );
139  tmp.Clear();
140  }
141 
142  else
143  tmp << aText[ii];
144  }
145 
146  if( !tmp.IsEmpty() )
147  {
148  aStrings.Add( tmp );
149  }
150 }

Variable Documentation

COLOR4D g_GhostColor

Global variables definitions.

Draw color for moving objects.

TODO: All of these variables should be moved into the class were they are defined and used. Most of them probably belong in the application class.

Definition at line 57 of file common.cpp.

Referenced by SCH_EDIT_FRAME::ConvertPart(), DrawMovingBlockOutlines(), DrawMovingItems(), SCH_EDIT_FRAME::OnSelectUnit(), and EDA_DRAW_PANEL::ReDraw().