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.

114 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include "dialog_footprint_associations.h"
  24. #include <widgets/wx_grid.h>
  25. #include <pcb_base_frame.h>
  26. #include <kiface_base.h>
  27. #include <fp_lib_table.h>
  28. #include <footprint.h>
  29. #include <project_pcb.h>
  30. DIALOG_FOOTPRINT_ASSOCIATIONS::DIALOG_FOOTPRINT_ASSOCIATIONS( PCB_BASE_FRAME* aFrame,
  31. FOOTPRINT* aFootprint ) :
  32. DIALOG_FOOTPRINT_ASSOCIATIONS_BASE( aFrame ),
  33. m_frame( aFrame ),
  34. m_footprint( aFootprint )
  35. {
  36. // Remove wxgrid's selection boxes
  37. for( wxGrid* grid : { m_gridLibrary, m_gridSymbol } )
  38. grid->SetCellHighlightPenWidth( 0 );
  39. m_libraryAssociationLabel->SetFont( KIUI::GetStatusFont( this ) );
  40. m_symbolAssociationLabel->SetFont( KIUI::GetStatusFont( this ) );
  41. m_gridLibrary->SetCellValue( 0, 0, _( "Library: " ) );
  42. m_gridLibrary->SetCellValue( 1, 0, _( "Footprint: " ) );
  43. }
  44. bool DIALOG_FOOTPRINT_ASSOCIATIONS::TransferDataToWindow()
  45. {
  46. LIB_ID fpID = m_footprint->GetFPID();
  47. wxString libName = fpID.GetLibNickname();
  48. wxString fpName = fpID.GetLibItemName();
  49. wxString libDesc;
  50. wxString fpDesc;
  51. PROJECT* project = m_footprint->GetBoard()->GetProject();
  52. FP_LIB_TABLE* libTable = PROJECT_PCB::PcbFootprintLibs( project );
  53. const LIB_TABLE_ROW* libTableRow = nullptr;
  54. try
  55. {
  56. libTableRow = libTable->FindRow( libName );
  57. libDesc = libTableRow->GetDescr();
  58. }
  59. catch( const IO_ERROR& )
  60. {
  61. }
  62. std::shared_ptr<FOOTPRINT> libFootprint;
  63. try
  64. {
  65. libFootprint.reset( libTable->FootprintLoad( libName, fpName, true ) );
  66. fpDesc = libFootprint->GetLibDescription();
  67. }
  68. catch( const IO_ERROR& )
  69. {
  70. }
  71. m_gridLibrary->SetCellValue( 0, 1, fpID.GetLibNickname() );
  72. m_gridLibrary->SetCellValue( 0, 2, libDesc );
  73. m_gridLibrary->SetCellValue( 1, 1, fpID.GetLibItemName() );
  74. m_gridLibrary->SetCellValue( 1, 2, fpDesc );
  75. KIID_PATH symbolPath = m_footprint->GetPath();
  76. m_gridSymbol->ClearRows();
  77. for( int ii = 0; ii < (int) symbolPath.size(); ++ii )
  78. {
  79. m_gridSymbol->AppendRows();
  80. m_gridSymbol->SetCellValue( ii, 0, ii == (int) symbolPath.size() - 1 ? _( "Symbol:" )
  81. : _( "Sheet: " ) );
  82. m_gridSymbol->SetCellValue( ii, 1, symbolPath[ii].AsString() );
  83. if( !Kiface().IsSingle() && m_frame->Kiway().Player( FRAME_SCH, false ) )
  84. {
  85. std::string item = symbolPath[ii].AsString().ToStdString();
  86. m_frame->Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_ITEM, item );
  87. m_gridSymbol->SetCellValue( ii, 2, item );
  88. }
  89. }
  90. finishDialogSettings();
  91. return true;
  92. }