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.

107 lines
3.5 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-2022 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 <base_units.h>
  25. #include <base_screen.h>
  26. #include <gerbview_frame.h>
  27. #include <gerber_file_image.h>
  28. #include <gerber_file_image_list.h>
  29. #include "gerbview_printout.h"
  30. #include <view/view.h>
  31. #include <gerbview_painter.h>
  32. #include <math/util.h> // for KiROUND
  33. GERBVIEW_PRINTOUT::GERBVIEW_PRINTOUT( GBR_LAYOUT* aLayout, const BOARD_PRINTOUT_SETTINGS& aParams,
  34. const KIGFX::VIEW* aView, const wxString& aTitle ) :
  35. BOARD_PRINTOUT( aParams, aView, aTitle )
  36. {
  37. m_layout = aLayout;
  38. m_gerbviewPrint = true;
  39. }
  40. bool GERBVIEW_PRINTOUT::OnPrintPage( int aPage )
  41. {
  42. // Store the layerset, as it is going to be modified below and the original settings are needed
  43. LSET lset = m_settings.m_LayerSet;
  44. LSEQ seq = lset.UIOrder();
  45. wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
  46. auto layerId = seq[aPage - 1];
  47. // In gerbview, draw layers are always printed on separate pages because handling negative
  48. // objects when using only one page is tricky
  49. // Enable only one layer to create a printout
  50. m_settings.m_LayerSet = LSET( layerId );
  51. GERBER_FILE_IMAGE_LIST& gbrImgList = GERBER_FILE_IMAGE_LIST::GetImagesList();
  52. GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
  53. wxString gbr_filename;
  54. if( gbrImage )
  55. gbr_filename = gbrImage->m_FileName;
  56. DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
  57. // Restore the original layer set, so the next page can be printed
  58. m_settings.m_LayerSet = lset;
  59. return true;
  60. }
  61. int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
  62. {
  63. return KiROUND( IU_PER_MILS * aMils );
  64. }
  65. void GERBVIEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
  66. {
  67. BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
  68. for( LSEQ layerSeq = m_settings.m_LayerSet.Seq(); layerSeq; ++layerSeq )
  69. aView.SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true );
  70. }
  71. void GERBVIEW_PRINTOUT::setupGal( KIGFX::GAL* aGal )
  72. {
  73. BOARD_PRINTOUT::setupGal( aGal );
  74. aGal->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
  75. }
  76. EDA_RECT GERBVIEW_PRINTOUT::getBoundingBox()
  77. {
  78. return m_layout->ComputeBoundingBox();
  79. }
  80. std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
  81. {
  82. return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal );
  83. }