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.

105 lines
3.4 KiB

  1. /*************/
  2. /** cfg.cpp **/
  3. /*************/
  4. #include "fctsys.h"
  5. #include "appl_wxstruct.h"
  6. #include "common.h"
  7. #include "gestfich.h"
  8. #include "param_config.h"
  9. #include "cvpcb.h"
  10. #include "protos.h"
  11. #include "cvstruct.h"
  12. #define GROUP wxT("/cvpcb")
  13. #define GROUPLIB wxT("/pcbnew/libraries")
  14. #define GROUPEQU wxT("/cvpcb/libraries")
  15. /**
  16. * Return project file parameter list for CVPcb.
  17. *
  18. * Populate the project file parameter array specific to CVPcb if it hasn't
  19. * already been populated and return a reference to the array to the caller.
  20. * Creating the parameter list at run time has the advantage of being able
  21. * to define local variables. The old method of statically building the array
  22. * at compile time requiring global variable definitions.
  23. */
  24. PARAM_CFG_ARRAY& WinEDA_CvpcbFrame::GetProjectFileParameters( void )
  25. {
  26. if( !m_projectFileParams.empty() )
  27. return m_projectFileParams;
  28. m_projectFileParams.push_back( new PARAM_CFG_BASE( GROUPLIB,
  29. PARAM_COMMAND_ERASE ) );
  30. m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ),
  31. &m_ModuleLibNames,
  32. GROUPLIB ) );
  33. m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "EquName" ),
  34. &m_AliasLibNames,
  35. GROUPEQU ) );
  36. m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "NetIExt" ),
  37. &m_NetlistFileExtension ) );
  38. m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "LibDir" ),
  39. &m_UserLibraryPath,
  40. GROUPLIB ) );
  41. return m_projectFileParams;
  42. }
  43. /**
  44. * Reads the configuration
  45. * 1 - bed cvpcb.cnf
  46. * 2 - if not in path of <cvpcb.exe> / cvpcb.cnf
  47. * 3 - If not found: init variables to default values
  48. *
  49. * Note:
  50. * The path of the executable must be in cvpcb.exe.
  51. *
  52. */
  53. void WinEDA_CvpcbFrame::LoadProjectFile( const wxString& FileName )
  54. {
  55. wxFileName fn = FileName;
  56. m_ModuleLibNames.Clear();
  57. m_AliasLibNames.Clear();
  58. if( fn.GetExt() != ProjectFileExtension )
  59. fn.SetExt( ProjectFileExtension );
  60. wxGetApp().RemoveLibraryPath( m_UserLibraryPath );
  61. wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP,
  62. GetProjectFileParameters(), FALSE );
  63. if( m_NetlistFileExtension.IsEmpty() )
  64. m_NetlistFileExtension = wxT( "net" );
  65. /* User library path takes precedent over default library search paths. */
  66. wxGetApp().InsertLibraryPath( m_UserLibraryPath, 1 );
  67. }
  68. void WinEDA_CvpcbFrame::Update_Config( wxCommandEvent& event )
  69. {
  70. SaveProjectFile( m_NetlistFileName.GetFullPath() );
  71. }
  72. void WinEDA_CvpcbFrame::SaveProjectFile( const wxString& fileName )
  73. {
  74. wxFileName fn = fileName;
  75. fn.SetExt( ProjectFileExtension );
  76. wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(),
  77. fn.GetFullName(), ProjectFileWildcard, wxFD_SAVE );
  78. if( dlg.ShowModal() == wxID_CANCEL )
  79. return;
  80. wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP,
  81. GetProjectFileParameters() );
  82. }