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.

155 lines
5.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  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 <base_struct.h>
  26. #include <plotter.h>
  27. #include <ws_painter.h>
  28. #include <base_screen.h>
  29. #include <gr_text.h>
  30. #include <title_block.h>
  31. #include "ws_draw_item.h"
  32. #include "ws_data_item.h"
  33. #include <wx/filename.h>
  34. wxString GetDefaultPlotExtension( PlotFormat aFormat )
  35. {
  36. switch( aFormat )
  37. {
  38. case PLOT_FORMAT_DXF: return DXF_PLOTTER::GetDefaultFileExtension();
  39. case PLOT_FORMAT_POST: return PS_PLOTTER::GetDefaultFileExtension();
  40. case PLOT_FORMAT_PDF: return PDF_PLOTTER::GetDefaultFileExtension();
  41. case PLOT_FORMAT_HPGL: return HPGL_PLOTTER::GetDefaultFileExtension();
  42. case PLOT_FORMAT_GERBER: return GERBER_PLOTTER::GetDefaultFileExtension();
  43. case PLOT_FORMAT_SVG: return SVG_PLOTTER::GetDefaultFileExtension();
  44. default: wxASSERT( false ); return wxEmptyString;
  45. }
  46. }
  47. void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
  48. const PAGE_INFO& aPageInfo, int aSheetNumber, int aNumberOfSheets,
  49. const wxString &aSheetDesc, const wxString &aFilename, const COLOR4D aColor )
  50. {
  51. /* Note: Page sizes values are given in mils
  52. */
  53. double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
  54. COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
  55. if( plotColor == COLOR4D::UNSPECIFIED )
  56. plotColor = COLOR4D( RED );
  57. plotter->SetColor( plotColor );
  58. WS_DRAW_ITEM_LIST drawList;
  59. // Print only a short filename, if aFilename is the full filename
  60. wxFileName fn( aFilename );
  61. // Prepare plot parameters
  62. drawList.SetDefaultPenSize( PLOTTER::USE_DEFAULT_LINE_WIDTH );
  63. drawList.SetMilsToIUfactor( iusPerMil );
  64. drawList.SetSheetNumber( aSheetNumber );
  65. drawList.SetSheetCount( aNumberOfSheets );
  66. drawList.SetFileName( fn.GetFullName() ); // Print only the short filename
  67. drawList.SetSheetName( aSheetDesc );
  68. drawList.BuildWorkSheetGraphicList( aPageInfo, aTitleBlock );
  69. // Draw item list
  70. for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
  71. {
  72. plotter->SetCurrentLineWidth( PLOTTER::USE_DEFAULT_LINE_WIDTH );
  73. switch( item->Type() )
  74. {
  75. case WSG_LINE_T:
  76. {
  77. WS_DRAW_ITEM_LINE* line = (WS_DRAW_ITEM_LINE*) item;
  78. plotter->SetCurrentLineWidth( line->GetPenWidth() );
  79. plotter->MoveTo( line->GetStart() );
  80. plotter->FinishTo( line->GetEnd() );
  81. }
  82. break;
  83. case WSG_RECT_T:
  84. {
  85. WS_DRAW_ITEM_RECT* rect = (WS_DRAW_ITEM_RECT*) item;
  86. plotter->Rect( rect->GetStart(), rect->GetEnd(), NO_FILL, rect->GetPenWidth() );
  87. }
  88. break;
  89. case WSG_TEXT_T:
  90. {
  91. WS_DRAW_ITEM_TEXT* text = (WS_DRAW_ITEM_TEXT*) item;
  92. plotter->Text( text->GetTextPos(), plotColor, text->GetShownText(),
  93. text->GetTextAngle(), text->GetTextSize(),
  94. text->GetHorizJustify(), text->GetVertJustify(),
  95. text->GetPenWidth(), text->IsItalic(), text->IsBold(),
  96. text->IsMultilineAllowed() );
  97. }
  98. break;
  99. case WSG_POLY_T:
  100. {
  101. WS_DRAW_ITEM_POLYPOLYGONS* poly = (WS_DRAW_ITEM_POLYPOLYGONS*) item;
  102. std::vector<wxPoint> points;
  103. for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
  104. {
  105. points.clear();
  106. SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
  107. for( int ii = 0; ii < outline.PointCount(); ii++ )
  108. points.push_back( wxPoint( outline.Point( ii ).x ,
  109. outline.Point( ii ).y ) );
  110. plotter->PlotPoly( points, FILLED_SHAPE, poly->GetPenWidth() );
  111. }
  112. }
  113. break;
  114. case WSG_BITMAP_T:
  115. {
  116. WS_DRAW_ITEM_BITMAP* drawItem = (WS_DRAW_ITEM_BITMAP*) item;
  117. auto* bitmap = (WS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
  118. if( bitmap->m_ImageBitmap == NULL )
  119. break;
  120. bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
  121. PLOTTER::USE_DEFAULT_LINE_WIDTH );
  122. }
  123. break;
  124. default:
  125. wxFAIL_MSG( "PlotWorkSheet(): Unknown worksheet item." );
  126. break;
  127. }
  128. }
  129. }