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.

113 lines
3.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2016 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 <fctsys.h>
  25. #include <pgm_base.h>
  26. #include <gr_basic.h>
  27. #include <base_units.h>
  28. #include <base_screen.h>
  29. #include <gerbview_frame.h>
  30. #include <gerber_file_image.h>
  31. #include <gerber_file_image_list.h>
  32. #include "gerbview_printout.h"
  33. #include <gal/gal_print.h>
  34. #include <view/view.h>
  35. #include <gerbview_painter.h>
  36. GERBVIEW_PRINTOUT::GERBVIEW_PRINTOUT( GBR_LAYOUT* aLayout, const BOARD_PRINTOUT_SETTINGS& aParams,
  37. const KIGFX::VIEW* aView, const wxString& aTitle ) :
  38. BOARD_PRINTOUT( aParams, aView, aTitle )
  39. {
  40. m_layout = aLayout;
  41. }
  42. bool GERBVIEW_PRINTOUT::OnPrintPage( int aPage )
  43. {
  44. // Store the layerset, as it is going to be modified below and the original settings are needed
  45. LSET lset = m_settings.m_layerSet;
  46. // The gerber filename of the page to print will be printed to the worksheet.
  47. // Find this filename:
  48. // Find the graphic layer number for the page to print
  49. LSEQ seq = lset.UIOrder();
  50. wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
  51. auto layerId = seq[aPage - 1];
  52. // In gerbview, draw layers are always printed on separate pages
  53. // because handling negative objects when using only one page is tricky
  54. // Enable only one layer to create a printout
  55. m_settings.m_layerSet = LSET( layerId );
  56. GERBER_FILE_IMAGE_LIST& gbrImgList = GERBER_FILE_IMAGE_LIST::GetImagesList();
  57. GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
  58. wxString gbr_filename;
  59. if( gbrImage )
  60. gbr_filename = gbrImage->m_FileName;
  61. DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
  62. // Restore the original layer set, so the next page can be printed
  63. m_settings.m_layerSet = lset;
  64. return true;
  65. }
  66. int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
  67. {
  68. return KiROUND( IU_PER_MILS * aMils );
  69. }
  70. void GERBVIEW_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
  71. const LSET& aLayerSet )
  72. {
  73. BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
  74. for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq )
  75. aView->SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true );
  76. }
  77. void GERBVIEW_PRINTOUT::setupGal( KIGFX::GAL* aGal )
  78. {
  79. BOARD_PRINTOUT::setupGal( aGal );
  80. aGal->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
  81. }
  82. EDA_RECT GERBVIEW_PRINTOUT::getBoundingBox()
  83. {
  84. return m_layout->ComputeBoundingBox();
  85. }
  86. std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
  87. {
  88. return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::GERBVIEW_PAINTER( aGal ) );
  89. }