KiCad PCB EDA Suite
common.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #ifndef INCLUDE__COMMON_H_
33 #define INCLUDE__COMMON_H_
34 
35 #include <vector>
36 #include <functional>
37 
38 #include <wx/confbase.h>
39 #include <wx/fileconf.h>
40 #include <wx/dir.h>
41 #include <wx/string.h>
42 #include <wx/gdicmn.h>
43 #include <wx/process.h>
44 
45 #include <atomic>
46 #include <limits>
47 #include <memory>
48 #include <type_traits>
49 #include <typeinfo>
50 #include <macros.h>
51 
52 class PROJECT;
53 class SEARCH_STACK;
54 class REPORTER;
55 
67 int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
68  wxProcess *callback = NULL );
69 
89 wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName );
90 
100 bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
101  const wxString& aBaseFilename,
102  REPORTER* aReporter = NULL );
103 
110 const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aProject );
111 
116 wxString ExpandTextVars( const wxString& aSource,
117  const std::function<bool( wxString* )>* aLocalResolver,
118  const PROJECT* aProject,
119  const std::function<bool( wxString* )>* aFallbackResolver = nullptr );
120 
125 const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject );
126 
127 
128 #ifdef __WXMAC__
129 
133 wxString GetOSXKicadUserDataDir();
134 
139 wxString GetOSXKicadMachineDataDir();
140 
145 wxString GetOSXKicadDataDir();
146 #endif
147 
148 // Some wxWidgets versions (for instance before 3.1.0) do not include
149 // this function, so add it if missing
150 #if !wxCHECK_VERSION( 3, 1, 0 )
151 #define USE_KICAD_WXSTRING_HASH // for common.cpp
152 namespace std
154 {
155  template<> struct hash<wxString>
156  {
157  size_t operator()( const wxString& s ) const;
158  };
159 }
160 #endif
161 
163 #define USE_KICAD_WXPOINT_LESS_AND_HASH // for common.cpp
164 namespace std
165 {
166  template <> struct hash<wxPoint>
167  {
168  size_t operator() ( const wxPoint& k ) const;
169  };
170 }
171 
172 namespace std
173 {
174  template<> struct less<wxPoint>
175  {
176  bool operator()( const wxPoint& aA, const wxPoint& aB ) const;
177  };
178 }
179 
186 std::ostream& operator<<( std::ostream& out, const wxSize& size );
187 
194 std::ostream& operator<<( std::ostream& out, const wxPoint& pt );
195 
196 long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec );
197 
198 
199 #endif // INCLUDE__COMMON_H_
PROJECT holds project specific data.
Definition: project.h:63
wxString ExpandTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject, const std::function< bool(wxString *)> *aFallbackResolver=nullptr)
Expand '${var-name}' templates in text.
Definition: common.cpp:58
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:58
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
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/...
Definition: common.cpp:582
This file contains miscellaneous commonly used macros and functions.
int ProcessExecute(const wxString &aCommandLine, int aFlags=wxEXEC_ASYNC, wxProcess *callback=NULL)
Run a command in a child process.
Definition: common.cpp:40
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSearchStack, const wxString &aBaseName)
Return the help file's full path.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:255
const wxString ResolveUriByEnvVars(const wxString &aUri, PROJECT *aProject)
Replace any environment and/or text variables in file-path uris (leaving network-path URIs alone).
Definition: common.cpp:268
#define NULL
std::ostream & operator<<(std::ostream &out, const wxSize &size)
Helper function to print the given wxSize to a stream.
Definition: common.cpp:412
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.
Definition: common.cpp:283