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.

184 lines
7.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 <eda_item.h>
  25. #include <font/font.h>
  26. #include <plotters/plotter_dxf.h>
  27. #include <plotters/plotter_hpgl.h>
  28. #include <plotters/plotters_pslike.h>
  29. #include <plotters/plotter_gerber.h>
  30. #include <drawing_sheet/ds_data_item.h>
  31. #include <drawing_sheet/ds_draw_item.h>
  32. #include <title_block.h>
  33. #include <wx/filename.h>
  34. wxString GetDefaultPlotExtension( PLOT_FORMAT 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: wxFAIL; return wxEmptyString;
  45. }
  46. }
  47. void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
  48. const PAGE_INFO& aPageInfo, const std::map<wxString, wxString>* aProperties,
  49. const wxString& aSheetNumber, int aSheetCount, const wxString& aSheetName,
  50. const wxString& aSheetPath, const wxString& aFilename, COLOR4D aColor,
  51. bool aIsFirstPage )
  52. {
  53. /* Note: Page sizes values are given in mils
  54. */
  55. double iusPerMil = plotter->GetIUsPerDecimil() * 10.0;
  56. COLOR4D plotColor = plotter->GetColorMode() ? aColor : COLOR4D::BLACK;
  57. RENDER_SETTINGS* settings = plotter->RenderSettings();
  58. int defaultPenWidth = settings->GetDefaultPenWidth();
  59. if( plotColor == COLOR4D::UNSPECIFIED )
  60. plotColor = COLOR4D( RED );
  61. DS_DRAW_ITEM_LIST drawList( unityScale );
  62. // Print only a short filename, if aFilename is the full filename
  63. wxFileName fn( aFilename );
  64. // Prepare plot parameters
  65. drawList.SetDefaultPenSize( PLOTTER::USE_DEFAULT_LINE_WIDTH );
  66. drawList.SetPlotterMilsToIUfactor( iusPerMil );
  67. drawList.SetPageNumber( aSheetNumber );
  68. drawList.SetSheetCount( aSheetCount );
  69. drawList.SetFileName( fn.GetFullPath() );
  70. drawList.SetSheetName( aSheetName );
  71. drawList.SetSheetPath( aSheetPath );
  72. drawList.SetSheetLayer( settings->GetLayerName() );
  73. drawList.SetProject( aProject );
  74. drawList.SetIsFirstPage( aIsFirstPage );
  75. drawList.SetProperties( aProperties );
  76. drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
  77. // Draw bitmaps first
  78. for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
  79. {
  80. if( item->Type() == WSG_BITMAP_T )
  81. {
  82. DS_DRAW_ITEM_BITMAP* drawItem = (DS_DRAW_ITEM_BITMAP*) item;
  83. DS_DATA_ITEM_BITMAP* bitmap = (DS_DATA_ITEM_BITMAP*) drawItem->GetPeer();
  84. if( bitmap->m_ImageBitmap == nullptr )
  85. continue;
  86. bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor,
  87. PLOTTER::USE_DEFAULT_LINE_WIDTH );
  88. }
  89. }
  90. // Draw other items
  91. for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
  92. {
  93. if( item->Type() == WSG_BITMAP_T )
  94. continue;
  95. plotter->SetColor( plotColor );
  96. plotter->SetCurrentLineWidth( PLOTTER::USE_DEFAULT_LINE_WIDTH );
  97. switch( item->Type() )
  98. {
  99. case WSG_LINE_T:
  100. {
  101. DS_DRAW_ITEM_LINE* line = (DS_DRAW_ITEM_LINE*) item;
  102. plotter->SetCurrentLineWidth( std::max( line->GetPenWidth(), defaultPenWidth ) );
  103. plotter->MoveTo( line->GetStart() );
  104. plotter->FinishTo( line->GetEnd() );
  105. }
  106. break;
  107. case WSG_RECT_T:
  108. {
  109. DS_DRAW_ITEM_RECT* rect = (DS_DRAW_ITEM_RECT*) item;
  110. plotter->SetCurrentLineWidth( std::max( rect->GetPenWidth(), defaultPenWidth ) );
  111. plotter->MoveTo( rect->GetStart() );
  112. plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetStart().y ) );
  113. plotter->LineTo( VECTOR2I( rect->GetEnd().x, rect->GetEnd().y ) );
  114. plotter->LineTo( VECTOR2I( rect->GetStart().x, rect->GetEnd().y ) );
  115. plotter->FinishTo( rect->GetStart() );
  116. }
  117. break;
  118. case WSG_TEXT_T:
  119. {
  120. DS_DRAW_ITEM_TEXT* text = (DS_DRAW_ITEM_TEXT*) item;
  121. KIFONT::FONT* font = text->GetFont();
  122. COLOR4D color = plotColor;
  123. if( !font )
  124. {
  125. font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), text->IsBold(),
  126. text->IsItalic() );
  127. }
  128. if( plotter->GetColorMode() && text->GetTextColor() != COLOR4D::UNSPECIFIED )
  129. color = text->GetTextColor();
  130. int penWidth = std::max( text->GetEffectiveTextPenWidth(), defaultPenWidth );
  131. plotter->Text( text->GetTextPos(), color, text->GetShownText( true ),
  132. text->GetTextAngle(), text->GetTextSize(), text->GetHorizJustify(),
  133. text->GetVertJustify(), penWidth, text->IsItalic(), text->IsBold(),
  134. text->IsMultilineAllowed(), font, text->GetFontMetrics() );
  135. }
  136. break;
  137. case WSG_POLY_T:
  138. {
  139. DS_DRAW_ITEM_POLYPOLYGONS* poly = (DS_DRAW_ITEM_POLYPOLYGONS*) item;
  140. int penWidth = poly->GetPenWidth();
  141. std::vector<VECTOR2I> points;
  142. for( int idx = 0; idx < poly->GetPolygons().OutlineCount(); ++idx )
  143. {
  144. points.clear();
  145. SHAPE_LINE_CHAIN& outline = poly->GetPolygons().Outline( idx );
  146. for( int ii = 0; ii < outline.PointCount(); ii++ )
  147. points.emplace_back( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
  148. plotter->PlotPoly( points, FILL_T::FILLED_SHAPE, penWidth );
  149. }
  150. }
  151. break;
  152. default:
  153. wxFAIL_MSG( wxT( "PlotDrawingSheet(): Unknown drawing sheet item." ) );
  154. break;
  155. }
  156. }
  157. }