kicad/pcbnew/dialogs/dialog_print_pcbnew.cpp

344 lines
12 KiB
C++
Raw Normal View History

2014-10-27 14:14:39 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2016-06-19 18:29:13 +00:00
* Copyright (C) 2010-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018 CERN
* Author: Maciej Suminski <maciej.suminski@cern.ch>
2014-10-27 14:14:39 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
2007-05-06 16:03:28 +00:00
#include <fctsys.h>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <kiface_i.h>
#include <confirm.h>
#include <base_units.h>
#include <pcbnew.h>
#include <pcbplot.h>
#include <class_board.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/pcbnew_control.h>
#include <dialog_print_generic.h>
#include <pcbnew_printout.h>
class DIALOG_PRINT_PCBNEW : public DIALOG_PRINT_GENERIC
2009-01-17 17:32:20 +00:00
{
public:
DIALOG_PRINT_PCBNEW( PCB_BASE_EDIT_FRAME* aParent, PCBNEW_PRINTOUT_SETTINGS* aSettings );
~DIALOG_PRINT_PCBNEW() {}
2009-01-17 17:32:20 +00:00
private:
PCBNEW_PRINTOUT_SETTINGS* settings() const
{
wxASSERT( dynamic_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings ) );
return static_cast<PCBNEW_PRINTOUT_SETTINGS*>( m_settings );
}
bool TransferDataToWindow() override;
void createExtraOptions();
void createLeftPanel();
void onSelectAllClick( wxCommandEvent& event );
void onDeselectAllClick( wxCommandEvent& event );
///> (Un)checks all items in a checklist box
void setListBoxValue( wxCheckListBox* aList, bool aValue );
///> Check whether a layer is enabled in a listbox
bool isLayerEnabled( unsigned int aLayer ) const;
///> Enable/disable layer in a listbox
void enableLayer( unsigned int aLayer, bool aValue );
2008-03-04 04:22:27 +00:00
///> Update layerset basing on the selected layers
int setLayerSetFromList();
2008-04-18 13:28:56 +00:00
void saveSettings() override;
2012-03-26 21:45:05 +00:00
wxPrintout* createPrintout( const wxString& aTitle ) override
2008-03-04 04:22:27 +00:00
{
return new PCBNEW_PRINTOUT( m_parent->GetBoard(), *settings(),
m_parent->GetCanvas()->GetView(), aTitle );
}
PCB_BASE_EDIT_FRAME* m_parent;
2012-03-26 21:45:05 +00:00
// List of existing board layers in wxCheckListBox, with the board layers id:
std::pair<wxCheckListBox*, int> m_layers[PCB_LAYER_ID_COUNT];
2012-03-26 21:45:05 +00:00
// Extra widgets
wxCheckListBox* m_listTechLayers;
wxCheckListBox* m_listCopperLayers;
wxButton* m_buttonSelectAll;
wxButton* m_buttonDeselectAll;
wxCheckBox* m_checkboxNoEdge;
wxCheckBox* m_checkboxMirror;
wxChoice* m_drillMarksChoice;
wxRadioBox* m_boxPagination;
};
2007-05-06 16:03:28 +00:00
DIALOG_PRINT_PCBNEW::DIALOG_PRINT_PCBNEW( PCB_BASE_EDIT_FRAME* aParent, PCBNEW_PRINTOUT_SETTINGS* aSettings ) :
DIALOG_PRINT_GENERIC( aParent, aSettings ), m_parent( aParent )
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
m_config = Kiface().KifaceSettings();
memset( m_layers, 0, sizeof( m_layers ) );
createExtraOptions();
createLeftPanel();
2009-01-17 17:32:20 +00:00
}
2007-05-06 16:03:28 +00:00
2009-01-17 17:32:20 +00:00
bool DIALOG_PRINT_PCBNEW::TransferDataToWindow()
{
if( !DIALOG_PRINT_GENERIC::TransferDataToWindow() )
return false;
BOARD* board = m_parent->GetBoard();
// Create layer list
for( LSEQ seq = board->GetEnabledLayers().UIOrder(); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;
2016-06-19 18:29:13 +00:00
int checkIndex;
if( IsCopperLayer( layer ) )
{
checkIndex = m_listCopperLayers->Append( board->GetLayerName( layer ) );
m_layers[layer] = std::make_pair( m_listCopperLayers, checkIndex );
}
else
{
checkIndex = m_listTechLayers->Append( board->GetLayerName( layer ) );
m_layers[layer] = std::make_pair( m_listTechLayers, checkIndex );
}
m_layers[layer].first->Check( checkIndex, settings()->m_layerSet.test( layer ) );
2008-03-04 04:22:27 +00:00
}
m_checkboxMirror->SetValue( settings()->m_mirror );
m_checkboxNoEdge->SetValue( settings()->m_noEdgeLayer );
m_titleBlock->SetValue( settings()->m_titleBlock );
2008-03-04 04:22:27 +00:00
// Options to plot pads and vias holes
m_drillMarksChoice->SetSelection( settings()->m_drillMarks );
// Print all layers one one page or separately
m_boxPagination->SetSelection( settings()->m_pagination );
2009-01-17 17:32:20 +00:00
// Update the dialog layout when layers are added
GetSizer()->Fit( this );
return true;
2007-05-06 16:03:28 +00:00
}
2008-03-04 04:22:27 +00:00
void DIALOG_PRINT_PCBNEW::createExtraOptions()
2007-05-06 16:03:28 +00:00
{
wxGridBagSizer* optionsSizer = getOptionsSizer();
wxStaticBox* box = getOptionsBox();
int rows = optionsSizer->GetEffectiveRowsCount();
int cols = optionsSizer->GetEffectiveColsCount();
// Drill marks option
auto drillMarksLabel = new wxStaticText( box, wxID_ANY, _( "Drill marks:" ) );
std::vector<wxString> drillMarkChoices =
{ _( "No drill mark" ), _( "Small mark" ), _( "Real drill" ) };
m_drillMarksChoice = new wxChoice( box, wxID_ANY, wxDefaultPosition,
wxDefaultSize, drillMarkChoices.size(), drillMarkChoices.data(), 0 );
m_drillMarksChoice->SetSelection( 0 );
// Print mirrored
m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) );
// Pagination
std::vector<wxString> pagesOption = { _( "One page per layer" ), _( "All layers on single page" ) };
m_boxPagination = new wxRadioBox( box, wxID_ANY, _( "Pagination" ), wxDefaultPosition,
wxDefaultSize, pagesOption.size(), pagesOption.data(), 1, wxRA_SPECIFY_COLS );
m_boxPagination->SetSelection( 0 );
// Sizer layout
optionsSizer->Add( drillMarksLabel, wxGBPosition( rows, 0 ), wxGBSpan( 1, 1 ),
wxBOTTOM | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
optionsSizer->Add( m_drillMarksChoice, wxGBPosition( rows, 1 ), wxGBSpan( 1, cols - 1 ),
wxBOTTOM | wxRIGHT | wxLEFT, 5 );
optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows + 1, 0 ), wxGBSpan( 1, cols ),
wxBOTTOM | wxRIGHT | wxLEFT, 5 );
optionsSizer->Add( m_boxPagination, wxGBPosition( rows + 2, 0 ), wxGBSpan( 1, cols ), wxALL | wxEXPAND, 5 );
}
void DIALOG_PRINT_PCBNEW::createLeftPanel()
{
wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( new wxStaticBox( this,
wxID_ANY, _( "Included Layers" ) ), wxVERTICAL );
// Copper layer list
auto copperLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Copper layers:" ) );
m_listCopperLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
wxBoxSizer* sizerLeft = new wxBoxSizer( wxVERTICAL );
sizerLeft->Add( copperLabel, 0, wxRIGHT | wxLEFT, 5 );
sizerLeft->Add( m_listCopperLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT | wxLEFT, 5 );
2008-03-04 04:22:27 +00:00
// Technical layer list
auto technicalLabel = new wxStaticText( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Technical layers:" ) );
m_listTechLayers = new wxCheckListBox( sbLayersSizer->GetStaticBox(), wxID_ANY );
2007-05-06 16:03:28 +00:00
wxBoxSizer* sizerRight = new wxBoxSizer( wxVERTICAL );
sizerRight->Add( technicalLabel, 0, wxRIGHT | wxLEFT, 5 );
sizerRight->Add( m_listTechLayers, 1, wxEXPAND | wxBOTTOM | wxRIGHT | wxLEFT, 5 );
2008-03-04 04:22:27 +00:00
// Layer list layout
wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL );
bLayerListsSizer->Add( sizerLeft, 1, wxEXPAND, 5 );
bLayerListsSizer->Add( sizerRight, 1, wxEXPAND, 5 );
// Select/Unselect all buttons
m_buttonSelectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Select all" ) );
m_buttonDeselectAll = new wxButton( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Deselect all" ) );
m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onSelectAllClick ), NULL, this );
m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_PRINT_PCBNEW::onDeselectAllClick ), NULL, this );
wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 );
buttonSizer->Add( m_buttonDeselectAll, 1, wxALL, 5 );
// Exclude Edge.Pcb layer checkbox
m_checkboxNoEdge = new wxCheckBox( sbLayersSizer->GetStaticBox(), wxID_ANY, _( "Exclude PCB edge layer" ) );
m_checkboxNoEdge->SetToolTip( _("Exclude contents of Edges_Pcb layer from all other layers") );
// Static box sizer layout
sbLayersSizer->Add( bLayerListsSizer, 1, wxALL | wxEXPAND, 5 );
sbLayersSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, 5 );
sbLayersSizer->Add( m_checkboxNoEdge, 0, wxALL | wxEXPAND, 5 );
getMainSizer()->Insert( 0, sbLayersSizer, 1, wxEXPAND );
2007-05-06 16:03:28 +00:00
}
void DIALOG_PRINT_PCBNEW::onSelectAllClick( wxCommandEvent& event )
{
setListBoxValue( m_listCopperLayers, true );
setListBoxValue( m_listTechLayers, true );
}
2012-03-26 21:45:05 +00:00
void DIALOG_PRINT_PCBNEW::onDeselectAllClick( wxCommandEvent& event )
{
setListBoxValue( m_listCopperLayers, false );
setListBoxValue( m_listTechLayers, false );
}
2007-05-06 16:03:28 +00:00
void DIALOG_PRINT_PCBNEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
{
for( unsigned int i = 0; i < aList->GetCount(); ++i )
aList->Check( i, aValue );
}
bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
2007-05-06 16:03:28 +00:00
{
wxCHECK( aLayer < arrayDim( m_layers ), false );
const auto& layerInfo = m_layers[aLayer];
if( layerInfo.first )
return layerInfo.first->IsChecked( layerInfo.second );
2008-03-04 04:22:27 +00:00
return false;
2007-05-06 16:03:28 +00:00
}
void DIALOG_PRINT_PCBNEW::enableLayer( unsigned int aLayer, bool aValue )
2007-05-06 16:03:28 +00:00
{
wxCHECK( aLayer < arrayDim( m_layers ), /* void */ );
const auto& layerInfo = m_layers[aLayer];
layerInfo.first->Check( layerInfo.second, aValue );
2007-05-06 16:03:28 +00:00
}
int DIALOG_PRINT_PCBNEW::setLayerSetFromList()
2007-05-06 16:03:28 +00:00
{
settings()->m_layerSet = LSET();
int& pageCount = settings()->m_pageCount;
pageCount = 0;
for( unsigned int layer = 0; layer < arrayDim( m_layers ); ++layer )
{
if( isLayerEnabled( layer ) )
{
++pageCount;
settings()->m_layerSet.set( layer );
}
}
// In Pcbnew force the EDGE layer to be printed or not with the other layers
settings()->m_noEdgeLayer = m_checkboxNoEdge->IsChecked();
2007-05-06 16:03:28 +00:00
// All layers on one page (only if there is at least one layer selected)
if( m_boxPagination->GetSelection() != 0 && pageCount > 0 )
pageCount = 1;
2007-05-06 16:03:28 +00:00
return pageCount;
2007-05-06 16:03:28 +00:00
}
void DIALOG_PRINT_PCBNEW::saveSettings()
{
setLayerSetFromList();
settings()->m_drillMarks =
(PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T) m_drillMarksChoice->GetSelection();
settings()->m_pagination = m_boxPagination->GetSelection() == 0
? PCBNEW_PRINTOUT_SETTINGS::LAYER_PER_PAGE : PCBNEW_PRINTOUT_SETTINGS::ALL_LAYERS;
settings()->m_mirror = m_checkboxMirror->GetValue();
DIALOG_PRINT_GENERIC::saveSettings();
}
int PCBNEW_CONTROL::Print( const TOOL_EVENT& aEvent )
{
// Selection affects the origin item visibility
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
PCBNEW_PRINTOUT_SETTINGS settings( m_frame->GetPageSettings() );
DIALOG_PRINT_PCBNEW dlg( (PCB_BASE_EDIT_FRAME*) m_frame, &settings );
if( m_editModules )
dlg.ForcePrintBorder( false );
dlg.ShowModal();
return 0;
}