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.

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