You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

426 lines
14 KiB

++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file appl_wxstruct.h
  27. * @brief Base class implementation for all KiCad applications.
  28. */
  29. #ifndef APPL_WXSTRUCT_H
  30. #define APPL_WXSTRUCT_H
  31. /* Use wxFileHistory for most recently used file handling. */
  32. #include <wx/docview.h>
  33. #include <wx/config.h>
  34. #include <wx/filename.h>
  35. #include <param_config.h>
  36. enum EDA_APP_T {
  37. APP_UNKNOWN_T,
  38. APP_EESCHEMA_T,
  39. APP_PCBNEW_T,
  40. APP_CVPCB_T,
  41. APP_GERBVIEW_T,
  42. APP_KICAD_T
  43. };
  44. class wxConfigBase;
  45. class wxFileConfig;
  46. class wxSingleInstanceChecker;
  47. class wxHtmlHelpController;
  48. /**
  49. * Class EDA_APP
  50. * is the base class representing all of KiCad applications.
  51. */
  52. class EDA_APP : public wxApp
  53. {
  54. protected:
  55. /// Used mainly to handle default paths libs m_Id = APP_EESCHEMA_T, APP_PCBNEW_T ...
  56. EDA_APP_T m_Id;
  57. /// Used to prevent multiple instances of an application from being run at the same time.
  58. wxSingleInstanceChecker* m_Checker;
  59. /// Used to prevent opening the same file multiple times.
  60. wxSingleInstanceChecker* m_oneInstancePerFileChecker;
  61. wxString m_Project;
  62. /// The application specific configuration settings.
  63. wxConfig* m_settings;
  64. /// The configuration settings common to all KiCad applications.
  65. wxConfig* m_commonSettings;
  66. /// The current project specific settings.
  67. wxFileConfig* m_projectSettings;
  68. /// KiCad executable path.
  69. wxString m_BinDir;
  70. /// The KICAD system environment variable.
  71. wxString m_KicadEnv;
  72. /// The current locale.
  73. wxLocale* m_Locale;
  74. /// The current language setting.
  75. int m_LanguageId;
  76. /// The file name of the the program selected for browsing pdf files.
  77. wxString m_PdfBrowser;
  78. wxPathList m_searchPaths;
  79. wxFileHistory m_fileHistory;
  80. wxString m_HelpFileName;
  81. wxString m_EditorName;
  82. wxString m_CurrentOptionFile;
  83. wxString m_CurrentOptionFileDateAndTime;
  84. wxPoint m_HelpPos;
  85. wxSize m_HelpSize;
  86. wxHtmlHelpController* m_HtmlCtrl;
  87. wxString m_Title;
  88. wxPathList m_libSearchPaths;
  89. wxFileName m_projectFileName;
  90. wxString m_LastVisitedLibPath;
  91. public:
  92. EDA_APP();
  93. ~EDA_APP();
  94. /**
  95. * Function OnInit
  96. * this is the first executed function (like main() )
  97. * @return true if the application can be started.
  98. */
  99. bool OnInit(); // should this be virtual
  100. wxHtmlHelpController* GetHtmlHelpController() { return m_HtmlCtrl; }
  101. void SetHtmlHelpController( wxHtmlHelpController* aController );
  102. wxString GetHelpFileName() const { return m_HelpFileName; }
  103. void SetHelpFileName( const wxString& aFileName ) { m_HelpFileName = aFileName; }
  104. wxConfig* GetSettings() { return m_settings; }
  105. wxConfig* GetCommonSettings() { return m_commonSettings; }
  106. wxString GetEditorName() const { return m_EditorName; }
  107. void SetEditorName( const wxString& aFileName ) { m_EditorName = aFileName; }
  108. wxString GetCurrentOptionFile() const { return m_CurrentOptionFile; }
  109. bool IsKicadEnvVariableDefined() const { return !m_KicadEnv.IsEmpty(); }
  110. wxString GetKicadEnvVariable() const { return m_KicadEnv; }
  111. wxString GetExecutablePath() const { return m_BinDir; }
  112. wxLocale* GetLocale() { return m_Locale; }
  113. wxString GetPdfBrowserFileName() const { return m_PdfBrowser; }
  114. void SetPdfBrowserFileName( const wxString& aFileName ) { m_PdfBrowser = aFileName; }
  115. bool UseSystemPdfBrowser() const { return m_PdfBrowser.IsEmpty(); }
  116. wxFileHistory& GetFileHistory() { return m_fileHistory; }
  117. /**
  118. * Function SetBinDir
  119. * finds the path to the executable and store it in EDA_APP::m_BinDir
  120. *
  121. * @return TODO
  122. */
  123. bool SetBinDir();
  124. /**
  125. * Function SetDefaultSearchPaths
  126. * sets search paths for libraries, modules, internationalization files, etc.
  127. */
  128. void SetDefaultSearchPaths( void );
  129. /**
  130. * Function MacOpenFile
  131. * Specific to MacOSX. Not used under Linux or Windows
  132. * MacOSX: Needed for file association
  133. * http://wiki.wxwidgets.org/WxMac-specific_topics
  134. */
  135. virtual void MacOpenFile(const wxString &fileName);
  136. /**
  137. * Function InitEDA_Appl
  138. * initialize some general parameters
  139. * - Default paths (help, libs, bin)and configuration files names
  140. * - Language and locale
  141. * - fonts
  142. * @param aName : used as paths in configuration files
  143. * @param aId = flag : LIBRARY_TYPE_EESCHEMA or LIBRARY_TYPE_PCBNEW
  144. * used to choose what default library path must be used
  145. */
  146. void InitEDA_Appl( const wxString& aName, EDA_APP_T aId = APP_UNKNOWN_T );
  147. /**
  148. * Function SetLanguage
  149. * sets the dictionary file name for internationalization.
  150. * <p>
  151. * The files are in kicad/internat/xx or kicad/internat/xx_XX and are named kicad.mo
  152. * </p>
  153. * @param first_time must be set to true the first time this funct is
  154. * called, false otherwise
  155. * @return true if the language can be set (i.e. if the locale is available)
  156. */
  157. bool SetLanguage( bool first_time = false );
  158. /**
  159. * Function AddMenuLanguageList
  160. * creates a menu list for language choice, and add it as submenu to \a MasterMenu.
  161. *
  162. * @param MasterMenu The main menu. The sub menu list will be accessible from the menu
  163. * item with id ID_LANGUAGE_CHOICE
  164. */
  165. void AddMenuLanguageList( wxMenu* MasterMenu );
  166. /**
  167. * Function SetLanguageIdentifier
  168. * sets in .m_LanguageId member the wxWidgets language identifier Id from
  169. * the KiCad menu id (internal menu identifier).
  170. *
  171. * @param menu_id The KiCad menuitem id (returned by Menu Event, when
  172. * clicking on a menu item)
  173. */
  174. void SetLanguageIdentifier( int menu_id );
  175. void SetLanguagePath( void );
  176. /**
  177. * Function InitOnLineHelp
  178. * initializes KiCad's online help.
  179. */
  180. void InitOnLineHelp();
  181. /**
  182. * Function GetSettings
  183. * gets the application settings.
  184. * @param aReopenLastUsedDirectory True to switch to last opened directory, false
  185. * to use current CWD
  186. */
  187. void GetSettings( bool aReopenLastUsedDirectory );
  188. /**
  189. * Function SaveSettings
  190. * saves the application settings.
  191. */
  192. void SaveSettings();
  193. /**
  194. * Function WriteProjectConfig
  195. * Save the current "project" parameters
  196. * saved parameters are parameters that have the .m_Setup member set to false
  197. * saving file is the .pro file project
  198. */
  199. void WriteProjectConfig( const wxString& fileName,
  200. const wxString& GroupName,
  201. const PARAM_CFG_ARRAY& params );
  202. /**
  203. * Function SaveCurrentSetupValues
  204. * saves the current setup values in m_settings.
  205. * Saved parameters are parameters that have the .m_Setup member set to
  206. * true.
  207. * @param aList = array of PARAM_CFG_BASE pointers
  208. */
  209. void SaveCurrentSetupValues( const PARAM_CFG_ARRAY& aList );
  210. /**
  211. * Function ReadCurrentSetupValues
  212. * reads the current setup values previously saved, from m_settings.
  213. * Saved parameters are parameters that have the .m_Setup member set to
  214. * true.
  215. * @param aList = array of PARAM_CFG_BASE pointers
  216. */
  217. void ReadCurrentSetupValues( const PARAM_CFG_ARRAY& aList );
  218. /**
  219. * Function ReadProjectConfig
  220. * Read the current "project" parameters
  221. * Parameters are parameters that have the .m_Setup member set to false
  222. * read file is the .pro file project
  223. *
  224. * if Load_Only_if_New == true, this file is read only if it differs from
  225. * the current config (different dates )
  226. *
  227. * @return true if read.
  228. * Also set:
  229. * wxGetApp().m_CurrentOptionFileDateAndTime
  230. * wxGetApp().m_CurrentOptionFile
  231. */
  232. bool ReadProjectConfig( const wxString& local_config_filename,
  233. const wxString& GroupName,
  234. PARAM_CFG_BASE** List,
  235. bool Load_Only_if_New );
  236. bool ReadProjectConfig( const wxString& local_config_filename,
  237. const wxString& GroupName,
  238. const PARAM_CFG_ARRAY& List,
  239. bool Load_Only_if_New );
  240. /**
  241. * Creates or recreates the KiCad project file. (filename.pro)
  242. * Initialize:
  243. * G_Prj_Config
  244. * G_Prj_Config_LocalFilename
  245. * G_Prj_Default_Config_FullFilename
  246. * Return:
  247. * True if local config
  248. * False if default config
  249. */
  250. bool ReCreatePrjConfig( const wxString& local_config_filename,
  251. const wxString& GroupName,
  252. bool ForceUseLocalConfig );
  253. /**
  254. * Function ReadPdfBrowserInfos
  255. * read the PDF browser choice from the common configuration.
  256. */
  257. void ReadPdfBrowserInfos();
  258. /* Function WritePdfBrowserInfos
  259. * save the PDF browser choice to the common configuration.
  260. */
  261. void WritePdfBrowserInfos();
  262. /**
  263. * Function FindFileInSearchPaths
  264. * looks in search paths for \a filename.
  265. */
  266. wxString FindFileInSearchPaths( const wxString& filename,
  267. const wxArrayString* subdirs = NULL );
  268. /**
  269. * Function GetHelpFile
  270. * get the help file path.
  271. * <p>
  272. * Return the KiCad help file with path. The base paths defined in
  273. * m_searchPaths are tested for a valid file. The path returned can
  274. * be relative depending on the paths added to m_searchPaths. See the
  275. * documentation for wxPathList for more information. If the help file
  276. * for the current locale is not found, an attempt to find the English
  277. * version of the help file is made.
  278. * wxEmptyString is returned if help file not found.
  279. * Help file is searched in directories in this order:
  280. * help/\<canonical name\> like help/en_GB
  281. * help/\<short name\> like help/en
  282. * help/en
  283. * </p>
  284. */
  285. wxString GetHelpFile( void );
  286. wxString GetLibraryFile( const wxString& filename );
  287. /**
  288. * Return the preferred editor name.
  289. */
  290. wxString& GetEditorName();
  291. const wxString& GetTitle() { return m_Title; }
  292. void SetTitle( const wxString& title ) { m_Title = title; }
  293. wxPathList& GetLibraryPathList() { return m_libSearchPaths; }
  294. wxString FindLibraryPath( const wxString& fileName );
  295. /**
  296. * Function FindLibraryPath
  297. * KiCad saves user defined library files that are not in the standard
  298. * library search path list with the full file path. Calling the library
  299. * search path list with a user library file will fail. This helper method
  300. * solves that problem.
  301. * @param fileName
  302. * @return a wxEmptyString if library file is not found.
  303. */
  304. wxString FindLibraryPath( const wxFileName& fileName )
  305. {
  306. return FindLibraryPath( fileName.GetFullPath() );
  307. }
  308. /**
  309. * Function ReturnLastVisitedLibraryPath
  310. * returns the last visited library directory, or (if void) the first
  311. * path in lib path list ( but not the CWD )
  312. *
  313. * @param aSubPathToSearch = Preferred sub path to search in path list
  314. */
  315. wxString ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch = wxEmptyString );
  316. void SaveLastVisitedLibraryPath( const wxString& aPath );
  317. /**
  318. * Function ReturnFilenameWithRelativePathInLibPath
  319. * @return a short filename (with extension) with only a relative path if
  320. * this filename can be found in library paths
  321. * @param aFullFilename The filename with path and extension.
  322. */
  323. wxString ReturnFilenameWithRelativePathInLibPath( const wxString& aFullFilename );
  324. /**
  325. * Function RemoveLibraryPath
  326. * Removes the given path(s) from the library path list
  327. * @param aPaths = path or path list to remove. paths must be separated by
  328. * ";"
  329. */
  330. void RemoveLibraryPath( const wxString& aPaths );
  331. /**
  332. * Function InsertLibraryPath
  333. * insert path(s) int lib paths list.
  334. * @param aPaths = path or path list to add. paths must be separated by ";"
  335. * @param aIndex = insertion point
  336. */
  337. void InsertLibraryPath( const wxString& aPaths, size_t aIndex );
  338. /**
  339. * Function LockFile
  340. * Locks the access to a file.
  341. * @param fileName = full path to the file.
  342. * @return false if the file was already locked, true otherwise.
  343. */
  344. bool LockFile( const wxString& fileName );
  345. };
  346. /*
  347. * Use wxGetApp() to access EDA_APP. It is not necessary to keep copies
  348. * of the application pointer all over the place or worse yet in a global
  349. * variable.
  350. */
  351. DECLARE_APP( EDA_APP )
  352. #endif /* APPL_WXSTRUCT_H */