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.

157 lines
5.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 <pcb_edit_frame.h>
  24. #include <pcbnew_settings.h>
  25. #include <dialog_update_pcb.h>
  26. #include <ratsnest/ratsnest_data.h>
  27. #include "widgets/wx_html_report_panel.h"
  28. #include <netlist_reader/pcb_netlist.h>
  29. #include <netlist_reader/board_netlist_updater.h>
  30. #include <tool/tool_manager.h>
  31. #include <tools/pcb_actions.h>
  32. #include <view/view_controls.h>
  33. #include <kiface_base.h>
  34. #include <kiplatform/ui.h>
  35. DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST* aNetlist ) :
  36. DIALOG_UPDATE_PCB_BASE( aParent ),
  37. m_frame( aParent ),
  38. m_netlist( aNetlist ),
  39. m_initialized( false )
  40. {
  41. auto cfg = m_frame->GetPcbNewSettings();
  42. m_cbRelinkFootprints->SetValue( cfg->m_NetlistDialog.associate_by_ref_sch );
  43. m_cbUpdateFootprints->SetValue( cfg->m_NetlistDialog.update_footprints );
  44. m_cbTransferGroups->SetValue( cfg->m_NetlistDialog.transfer_groups );
  45. m_cbDeleteExtraFootprints->SetValue( cfg->m_NetlistDialog.delete_extra_footprints );
  46. m_messagePanel->SetLabel( _("Changes to Be Applied") );
  47. m_messagePanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
  48. m_messagePanel->SetLazyUpdate( true );
  49. m_netlist->SortByReference();
  50. m_messagePanel->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
  51. m_messagePanel->GetSizer()->SetSizeHints( this );
  52. m_messagePanel->Layout();
  53. SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) },
  54. { wxID_CANCEL, _( "Close" ) } } );
  55. finishDialogSettings();
  56. m_initialized = true;
  57. PerformUpdate( true );
  58. }
  59. DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB()
  60. {
  61. PCBNEW_SETTINGS* cfg = nullptr;
  62. try
  63. {
  64. cfg = m_frame->GetPcbNewSettings();
  65. }
  66. catch( const std::runtime_error& e )
  67. {
  68. wxFAIL_MSG( e.what() );
  69. }
  70. if( cfg )
  71. {
  72. cfg->m_NetlistDialog.associate_by_ref_sch = m_cbRelinkFootprints->GetValue();
  73. cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue();
  74. cfg->m_NetlistDialog.transfer_groups = m_cbTransferGroups->GetValue();
  75. cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue();
  76. cfg->m_NetlistDialog.report_filter = m_messagePanel->GetVisibleSeverities();
  77. }
  78. if( m_runDragCommand )
  79. {
  80. KIGFX::VIEW_CONTROLS* controls = m_frame->GetCanvas()->GetViewControls();
  81. controls->SetCursorPosition( controls->GetMousePosition() );
  82. m_frame->GetToolManager()->RunAction( PCB_ACTIONS::move );
  83. }
  84. }
  85. void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
  86. {
  87. m_messagePanel->Clear();
  88. REPORTER& reporter = m_messagePanel->Reporter();
  89. m_runDragCommand = false;
  90. m_netlist->SetFindByTimeStamp( !m_cbRelinkFootprints->GetValue() );
  91. m_netlist->SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
  92. if( !aDryRun )
  93. {
  94. m_frame->GetToolManager()->DeactivateTool();
  95. m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
  96. }
  97. BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
  98. updater.SetReporter ( &reporter );
  99. updater.SetIsDryRun( aDryRun );
  100. updater.SetLookupByTimestamp( !m_cbRelinkFootprints->GetValue() );
  101. updater.SetDeleteUnusedFootprints( m_cbDeleteExtraFootprints->GetValue());
  102. updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
  103. updater.SetTransferGroups( m_cbTransferGroups->GetValue() );
  104. updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
  105. updater.UpdateNetlist( *m_netlist );
  106. m_messagePanel->Flush( true );
  107. if( aDryRun )
  108. return;
  109. m_frame->OnNetlistChanged( updater, &m_runDragCommand );
  110. }
  111. void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
  112. {
  113. if( m_initialized )
  114. {
  115. PerformUpdate( true );
  116. m_sdbSizer1OK->Enable( true );
  117. m_sdbSizer1OK->SetDefault();
  118. }
  119. }
  120. void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
  121. {
  122. m_messagePanel->SetLabel( _( "Changes Applied to PCB" ) );
  123. PerformUpdate( false );
  124. m_sdbSizer1Cancel->SetDefault();
  125. // wxWidgets has a tendency to keep both buttons highlighted without the following:
  126. m_sdbSizer1OK->Enable( false );
  127. }