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.

164 lines
6.8 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 <design_block.h>
  24. #include <widgets/pcb_design_block_pane.h>
  25. #include <widgets/pcb_design_block_preview_widget.h>
  26. #include <widgets/panel_design_block_chooser.h>
  27. #include <pcbnew_settings.h>
  28. #include <kiface_base.h>
  29. #include <pcb_edit_frame.h>
  30. #include <core/kicad_algo.h>
  31. #include <template_fieldnames.h>
  32. #include <wx/button.h>
  33. #include <wx/checkbox.h>
  34. #include <wx/sizer.h>
  35. #include <confirm.h>
  36. #include <wildcards_and_files_ext.h>
  37. #include <tool/tool_manager.h>
  38. #include <tools/pcb_actions.h>
  39. #include <tools/pcb_design_block_control.h>
  40. // Do not make these static wxStrings; they need to respond to language changes
  41. #define REPEATED_PLACEMENT _( "Place repeated copies" )
  42. #define PLACE_AS_GROUP _( "Place as group" )
  43. #define KEEP_ANNOTATIONS _( "Keep annotations" )
  44. PCB_DESIGN_BLOCK_PANE::PCB_DESIGN_BLOCK_PANE( PCB_EDIT_FRAME* aParent, const LIB_ID* aPreselect,
  45. std::vector<LIB_ID>& aHistoryList ) :
  46. DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
  47. {
  48. wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
  49. m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
  50. [aParent]()
  51. {
  52. aParent->GetToolManager()->RunAction(
  53. PCB_ACTIONS::placeDesignBlock );
  54. },
  55. aParent->GetToolManager()->GetTool<PCB_DESIGN_BLOCK_CONTROL>()
  56. );
  57. m_chooserPanel->SetPreviewWidget(new PCB_DESIGN_BLOCK_PREVIEW_WIDGET( m_chooserPanel->GetDetailsPanel(), aParent ) );
  58. sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
  59. if( aPreselect && aPreselect->IsValid() )
  60. m_chooserPanel->SetPreselect( *aPreselect );
  61. SetName( wxT( "Design Blocks" ) );
  62. wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
  63. m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
  64. m_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
  65. m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
  66. setLabelsAndTooltips();
  67. UpdateCheckboxes();
  68. // Set all checkbox handlers to the same function
  69. m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
  70. m_placeAsGroup->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
  71. m_keepAnnotations->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
  72. cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
  73. cbSizer->Add( m_placeAsGroup, 0, wxTOP | wxLEFT, 2 );
  74. cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
  75. sizer->Add( cbSizer, 0, wxEXPAND, 5 );
  76. SetSizer( sizer );
  77. m_chooserPanel->FinishSetup();
  78. Layout();
  79. Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
  80. }
  81. void PCB_DESIGN_BLOCK_PANE::setLabelsAndTooltips()
  82. {
  83. if( m_repeatedPlacement )
  84. {
  85. m_repeatedPlacement->SetLabel( REPEATED_PLACEMENT );
  86. m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
  87. "clicks." ) );
  88. }
  89. if( m_placeAsGroup )
  90. {
  91. m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
  92. m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
  93. }
  94. if( m_keepAnnotations )
  95. {
  96. m_keepAnnotations->SetLabel( KEEP_ANNOTATIONS );
  97. m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
  98. "layout. Otherwise, clear them." ) );
  99. }
  100. }
  101. void PCB_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
  102. {
  103. if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
  104. {
  105. cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
  106. cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsGroup->GetValue();
  107. cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
  108. }
  109. }
  110. void PCB_DESIGN_BLOCK_PANE::UpdateCheckboxes()
  111. {
  112. if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
  113. {
  114. m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
  115. m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
  116. m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
  117. }
  118. }
  119. FILEDLG_IMPORT_SHEET_CONTENTS::FILEDLG_IMPORT_SHEET_CONTENTS( PCBNEW_SETTINGS* aSettings ) :
  120. m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsSheet( nullptr ), m_cbKeepAnnotations( nullptr )
  121. {
  122. wxASSERT( aSettings );
  123. m_settings = aSettings;
  124. };
  125. void FILEDLG_IMPORT_SHEET_CONTENTS::TransferDataFromCustomControls()
  126. {
  127. m_settings->m_DesignBlockChooserPanel.repeated_placement = m_cbRepeatedPlacement->GetValue();
  128. m_settings->m_DesignBlockChooserPanel.place_as_sheet = m_cbPlaceAsSheet->GetValue();
  129. m_settings->m_DesignBlockChooserPanel.keep_annotations = m_cbKeepAnnotations->GetValue();
  130. }
  131. void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
  132. {
  133. m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
  134. m_cbRepeatedPlacement->SetValue( m_settings->m_DesignBlockChooserPanel.repeated_placement );
  135. m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_GROUP );
  136. m_cbPlaceAsSheet->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_sheet );
  137. m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
  138. m_cbKeepAnnotations->SetValue( m_settings->m_DesignBlockChooserPanel.keep_annotations );
  139. }