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.

162 lines
3.9 KiB

  1. /**************/
  2. /* init.cpp */
  3. /**************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "confirm.h"
  7. #include "gr_basic.h"
  8. #include "gestfich.h"
  9. #include "appl_wxstruct.h"
  10. #include "cvpcb.h"
  11. #include "protos.h"
  12. #include "cvpcb_mainframe.h"
  13. #include "cvstruct.h"
  14. #include "build_version.h"
  15. /*
  16. * Set the module to the selected component
  17. * Selects the next component
  18. */
  19. void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
  20. {
  21. COMPONENT* Component;
  22. bool isUndefined = false;
  23. int NumCmp;
  24. wxString msg;
  25. if( m_components.empty() )
  26. return;
  27. NumCmp = m_ListCmp->GetSelection();
  28. if( NumCmp < 0 )
  29. {
  30. NumCmp = 0;
  31. m_ListCmp->SetSelection( NumCmp, true );
  32. }
  33. Component = &m_components[ NumCmp ];
  34. if( Component == NULL )
  35. return;
  36. isUndefined = Component->m_Module.IsEmpty();
  37. Component->m_Module = package;
  38. msg.Printf( CMP_FORMAT, NumCmp + 1,
  39. GetChars( Component->m_Reference ),
  40. GetChars( Component->m_Value ),
  41. GetChars( Component->m_Module ) );
  42. m_modified = true;
  43. if( isUndefined )
  44. m_undefinedComponentCnt -= 1;
  45. m_ListCmp->SetString( NumCmp, msg );
  46. m_ListCmp->SetSelection( NumCmp, FALSE );
  47. // We activate next component:
  48. if( NumCmp < (m_ListCmp->GetCount() - 1) )
  49. NumCmp++;
  50. m_ListCmp->SetSelection( NumCmp, TRUE );
  51. DisplayStatus();
  52. }
  53. /*
  54. * Read the netlist format and file components.
  55. */
  56. bool CVPCB_MAINFRAME::ReadNetList()
  57. {
  58. wxString msg;
  59. int error_level;
  60. error_level = ReadSchematicNetlist();
  61. if( error_level < 0 )
  62. {
  63. msg.Printf( _( "File <%s> does not appear to be a valid Kicad net list file." ),
  64. GetChars( m_NetlistFileName.GetFullPath() ) );
  65. ::wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this );
  66. return false;
  67. }
  68. LoadComponentFile( m_NetlistFileName.GetFullPath(), m_components );
  69. if( m_ListCmp == NULL )
  70. return false;
  71. LoadProjectFile( m_NetlistFileName.GetFullPath() );
  72. LoadFootprintFiles( );
  73. BuildFOOTPRINTS_LISTBOX();
  74. m_ListCmp->Clear();
  75. m_undefinedComponentCnt = 0;
  76. BOOST_FOREACH( COMPONENT& component, m_components )
  77. {
  78. msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
  79. GetChars( component.m_Reference ),
  80. GetChars( component.m_Value ),
  81. GetChars( component.m_Module ) );
  82. m_ListCmp->AppendLine( msg );
  83. if( component.m_Module.IsEmpty() )
  84. m_undefinedComponentCnt += 1;
  85. }
  86. if( !m_components.empty() )
  87. m_ListCmp->SetSelection( 0, TRUE );
  88. DisplayStatus();
  89. /* Update the title of the main window. */
  90. SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
  91. wxT( " " ) + m_NetlistFileName.GetFullPath() );
  92. return true;
  93. }
  94. /*
  95. * Backup and NetList cmp
  96. * The full name of the netlist file must be in FFileName.
  97. * The file name is deducted in cmp
  98. */
  99. int CVPCB_MAINFRAME::SaveNetList( const wxString& fileName )
  100. {
  101. wxFileName fn;
  102. if( !fileName && m_NetlistFileName.IsOk() )
  103. fn = m_NetlistFileName;
  104. else
  105. fn = wxFileName( wxGetCwd(), _( "unamed" ), NetExtBuffer );
  106. wxFileDialog dlg( this, _( "Save Net and Component List" ), fn.GetPath(),
  107. fn.GetFullName(), NetlistFileWildcard,
  108. wxFD_SAVE/*| wxFD_OVERWRITE_PROMPT*/ );
  109. if( dlg.ShowModal() == wxID_CANCEL )
  110. return -1;
  111. if( SaveComponentList( dlg.GetPath() ) == 0 )
  112. {
  113. DisplayError( this, _( "Unable to create component file (.cmp)" ) );
  114. return 0;
  115. }
  116. FILE* netlist = wxFopen( dlg.GetPath(), wxT( "wt" ) );
  117. if( netlist == 0 )
  118. {
  119. DisplayError( this, _( "Unable to create net list file" ) );
  120. return 0;
  121. }
  122. GenNetlistPcbnew( netlist, m_components, m_isEESchemaNetlist,
  123. m_rightJustify );
  124. return 1;
  125. }