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.

143 lines
4.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 The 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. DIALOG_UPDATE_FROM_PCB::DIALOG_UPDATE_FROM_PCB( SCH_EDIT_FRAME* aParent ) :
  30. DIALOG_UPDATE_FROM_PCB_BASE( aParent ),
  31. m_frame( aParent )
  32. {
  33. m_messagePanel->SetLabel( _( "Changes to Be Applied" ) );
  34. m_messagePanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
  35. m_messagePanel->SetLazyUpdate( true );
  36. m_messagePanel->GetSizer()->SetSizeHints( this );
  37. if( m_cbRelinkFootprints->GetValue() )
  38. {
  39. m_cbUpdateReferences->SetValue( false );
  40. m_cbUpdateReferences->Enable( false );
  41. }
  42. else
  43. {
  44. m_cbUpdateReferences->Enable( true );
  45. }
  46. SetupStandardButtons( { { wxID_OK, _( "Update Schematic" ) },
  47. { wxID_CANCEL, _( "Close" ) } } );
  48. finishDialogSettings();
  49. }
  50. void DIALOG_UPDATE_FROM_PCB::updateData()
  51. {
  52. bool successfulRun = false;
  53. m_messagePanel->Clear();
  54. BACK_ANNOTATE backAnno( m_frame,
  55. m_messagePanel->Reporter(),
  56. m_cbRelinkFootprints->GetValue(),
  57. m_cbUpdateFootprints->GetValue(),
  58. m_cbUpdateValues->GetValue(),
  59. m_cbUpdateReferences->GetValue(),
  60. m_cbUpdateNetNames->GetValue(),
  61. m_cbUpdateAttributes->GetValue(),
  62. m_cbUpdateOtherFields->GetValue(),
  63. m_cbPreferUnitSwaps->GetValue(),
  64. m_cbPreferPinSwaps->GetValue(),
  65. true );
  66. std::string netlist;
  67. if( backAnno.FetchNetlistFromPCB( netlist ) )
  68. successfulRun = backAnno.BackAnnotateSymbols( netlist );
  69. m_sdbSizerOK->Enable( successfulRun );
  70. m_messagePanel->Flush( false );
  71. }
  72. bool DIALOG_UPDATE_FROM_PCB::TransferDataToWindow()
  73. {
  74. updateData();
  75. return true;
  76. }
  77. void DIALOG_UPDATE_FROM_PCB::OnOptionChanged( wxCommandEvent& event )
  78. {
  79. if( event.GetEventObject() == m_cbRelinkFootprints )
  80. {
  81. if( m_cbRelinkFootprints->GetValue() )
  82. {
  83. m_cbUpdateReferences->SetValue( false );
  84. m_cbUpdateReferences->Enable( false );
  85. }
  86. else
  87. {
  88. m_cbUpdateReferences->Enable( true );
  89. }
  90. }
  91. updateData();
  92. }
  93. void DIALOG_UPDATE_FROM_PCB::OnUpdateClick( wxCommandEvent& event )
  94. {
  95. std::string netlist;
  96. m_messagePanel->Clear();
  97. BACK_ANNOTATE backAnno( m_frame,
  98. m_messagePanel->Reporter(),
  99. m_cbRelinkFootprints->GetValue(),
  100. m_cbUpdateFootprints->GetValue(),
  101. m_cbUpdateValues->GetValue(),
  102. m_cbUpdateReferences->GetValue(),
  103. m_cbUpdateNetNames->GetValue(),
  104. m_cbUpdateAttributes->GetValue(),
  105. m_cbUpdateOtherFields->GetValue(),
  106. m_cbPreferUnitSwaps->GetValue(),
  107. m_cbPreferPinSwaps->GetValue(),
  108. false );
  109. if( backAnno.FetchNetlistFromPCB( netlist ) && backAnno.BackAnnotateSymbols( netlist ) )
  110. {
  111. m_frame->GetCurrentSheet().UpdateAllScreenReferences();
  112. m_frame->SetSheetNumberAndCount();
  113. m_frame->SyncView();
  114. m_frame->OnModify();
  115. m_frame->GetCanvas()->Refresh();
  116. if( m_cbRelinkFootprints->GetValue() )
  117. backAnno.PushNewLinksToPCB();
  118. m_sdbSizerCancel->SetDefault();
  119. m_sdbSizerOK->Enable( false );
  120. }
  121. m_messagePanel->Flush( false );
  122. }