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.

166 lines
5.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Alexander Shuklin <Jasuramme@gmail.com>
  5. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <backannotate.h>
  25. #include <dialog_update_from_pcb.h>
  26. #include <sch_edit_frame.h>
  27. #include <sch_editor_control.h>
  28. #include "widgets/wx_html_report_panel.h"
  29. // Saved dialog settings
  30. DIALOG_UPDATE_FROM_PCB::DIALOG_UPDATE_FROM_PCB_SAVED_STATE
  31. DIALOG_UPDATE_FROM_PCB::s_savedDialogState{ false, true, true, true, false };
  32. DIALOG_UPDATE_FROM_PCB::DIALOG_UPDATE_FROM_PCB( SCH_EDIT_FRAME* aParent )
  33. : DIALOG_UPDATE_FROM_PCB_BASE( aParent ),
  34. m_frame( aParent ),
  35. m_editorControl( m_frame->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>() )
  36. {
  37. m_messagePanel->SetLabel( _( "Changes To Be Applied" ) );
  38. m_messagePanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
  39. m_messagePanel->SetLazyUpdate( true );
  40. m_messagePanel->GetSizer()->SetSizeHints( this );
  41. m_cbRelinkFootprints->SetValue( s_savedDialogState.MatchByReference );
  42. if( m_cbRelinkFootprints->GetValue() )
  43. {
  44. m_cbUpdateReferences->SetValue( false );
  45. m_cbUpdateReferences->Enable( false );
  46. }
  47. else
  48. {
  49. m_cbUpdateReferences->SetValue( s_savedDialogState.UpdateReferences );
  50. m_cbUpdateReferences->Enable( true );
  51. }
  52. m_cbUpdateFootprints->SetValue( s_savedDialogState.UpdateFootprints );
  53. m_cbUpdateValues->SetValue( s_savedDialogState.UpdateValues );
  54. m_cbUpdateNetNames->SetValue( s_savedDialogState.UpdateNetNames );
  55. SetupStandardButtons( { { wxID_OK, _( "Update Schematic" ) },
  56. { wxID_CANCEL, _( "Close" ) } } );
  57. finishDialogSettings();
  58. }
  59. void DIALOG_UPDATE_FROM_PCB::updateData()
  60. {
  61. bool successfulRun = false;
  62. m_messagePanel->Clear();
  63. BACK_ANNOTATE backAnno( m_frame,
  64. m_messagePanel->Reporter(),
  65. m_cbRelinkFootprints->GetValue(),
  66. m_cbUpdateFootprints->GetValue(),
  67. m_cbUpdateValues->GetValue(),
  68. m_cbUpdateReferences->GetValue(),
  69. m_cbUpdateNetNames->GetValue(),
  70. true );
  71. std::string netlist;
  72. if( backAnno.FetchNetlistFromPCB( netlist ) )
  73. successfulRun = backAnno.BackAnnotateSymbols( netlist );
  74. m_sdbSizerOK->Enable( successfulRun );
  75. m_messagePanel->Flush( false );
  76. }
  77. bool DIALOG_UPDATE_FROM_PCB::TransferDataToWindow()
  78. {
  79. updateData();
  80. return true;
  81. }
  82. DIALOG_UPDATE_FROM_PCB::~DIALOG_UPDATE_FROM_PCB()
  83. {
  84. }
  85. void DIALOG_UPDATE_FROM_PCB::OnOptionChanged( wxCommandEvent& event )
  86. {
  87. if( event.GetEventObject() == m_cbRelinkFootprints )
  88. {
  89. if( m_cbRelinkFootprints->GetValue() )
  90. {
  91. m_cbUpdateReferences->SetValue( false );
  92. m_cbUpdateReferences->Enable( false );
  93. }
  94. else
  95. {
  96. m_cbUpdateReferences->SetValue( s_savedDialogState.UpdateReferences );
  97. m_cbUpdateReferences->Enable( true );
  98. }
  99. }
  100. updateData();
  101. if( event.GetEventObject() == m_cbRelinkFootprints )
  102. s_savedDialogState.MatchByReference = m_cbRelinkFootprints->GetValue();
  103. else if( event.GetEventObject() == m_cbUpdateReferences )
  104. s_savedDialogState.UpdateReferences = m_cbUpdateReferences->GetValue();
  105. else if( event.GetEventObject() == m_cbUpdateFootprints )
  106. s_savedDialogState.UpdateFootprints = m_cbUpdateFootprints->GetValue();
  107. else if( event.GetEventObject() == m_cbUpdateValues )
  108. s_savedDialogState.UpdateValues = m_cbUpdateValues->GetValue();
  109. else if( event.GetEventObject() == m_cbUpdateNetNames )
  110. s_savedDialogState.UpdateNetNames = m_cbUpdateNetNames->GetValue();
  111. }
  112. void DIALOG_UPDATE_FROM_PCB::OnUpdateClick( wxCommandEvent& event )
  113. {
  114. std::string netlist;
  115. m_messagePanel->Clear();
  116. BACK_ANNOTATE backAnno( m_frame,
  117. m_messagePanel->Reporter(),
  118. m_cbRelinkFootprints->GetValue(),
  119. m_cbUpdateFootprints->GetValue(),
  120. m_cbUpdateValues->GetValue(),
  121. m_cbUpdateReferences->GetValue(),
  122. m_cbUpdateNetNames->GetValue(),
  123. false );
  124. if( backAnno.FetchNetlistFromPCB( netlist ) && backAnno.BackAnnotateSymbols( netlist ) )
  125. {
  126. m_frame->GetCurrentSheet().UpdateAllScreenReferences();
  127. m_frame->SetSheetNumberAndCount();
  128. m_frame->SyncView();
  129. m_frame->OnModify();
  130. m_frame->GetCanvas()->Refresh();
  131. if( m_cbRelinkFootprints->GetValue() )
  132. backAnno.PushNewLinksToPCB();
  133. m_sdbSizerCancel->SetDefault();
  134. m_sdbSizerOK->Enable( false );
  135. }
  136. m_messagePanel->Flush( false );
  137. }