KiCad PCB EDA Suite
plot_schematic_DXF.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 1992-2010 Lorenzo Marcantonio
8  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <fctsys.h>
29 #include <plotter.h>
30 #include <sch_edit_frame.h>
31 #include <sch_sheet_path.h>
32 #include <schematic.h>
33 #include <project.h>
34 #include <pgm_base.h>
36 #include <sch_painter.h>
37 #include <dialog_plot_schematic.h>
38 #include <wx_html_report_panel.h>
39 
40 
41 void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef,
42  RENDER_SETTINGS* aRenderSettings )
43 {
44  SCH_EDIT_FRAME* schframe = m_parent;
45  SCH_SCREEN* screen = schframe->GetScreen();
46  SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
47 
48  /* When printing all pages, the printed page is not the current page.
49  * In complex hierarchies, we must setup references and others parameters
50  * in the printed SCH_SCREEN
51  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
52  * is shared between many sheets
53  */
54  SCH_SHEET_LIST sheetList;
55 
56  if( aPlotAll )
57  sheetList.BuildSheetList( &schframe->Schematic().Root() );
58  else
59  sheetList.push_back( schframe->GetCurrentSheet() );
60 
61  REPORTER& reporter = m_MessagesBox->Reporter();
62 
63  for( unsigned i = 0; i < sheetList.size(); i++ )
64  {
65  schframe->SetCurrentSheet( sheetList[i] );
67  schframe->SetSheetNumberAndCount();
68  screen = schframe->GetCurrentSheet().LastScreen();
69 
70  wxPoint plot_offset;
71  wxString msg;
72 
73  try
74  {
75  wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
76  wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
77  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
78 
79  if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, aRenderSettings,
80  plot_offset, 1.0, aPlotFrameRef ) )
81  {
82  msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
83  reporter.Report( msg, RPT_SEVERITY_ACTION );
84  }
85  else // Error
86  {
87  msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
88  reporter.Report( msg, RPT_SEVERITY_ERROR );
89  }
90  }
91  catch( IO_ERROR& e )
92  {
93  msg.Printf( wxT( "DXF Plotter exception: %s"), e.What() );
94  reporter.Report( msg, RPT_SEVERITY_ERROR );
95  schframe->SetCurrentSheet( oldsheetpath );
97  schframe->SetSheetNumberAndCount();
98  return;
99  }
100  }
101 
102  schframe->SetCurrentSheet( oldsheetpath );
104  schframe->SetSheetNumberAndCount();
105 }
106 
107 
108 bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
109  SCH_SCREEN* aScreen,
110  RENDER_SETTINGS* aRenderSettings,
111  wxPoint aPlotOffset,
112  double aScale,
113  bool aPlotFrameRef )
114 {
115  aRenderSettings->LoadColors( getColorSettings() );
116  aRenderSettings->SetDefaultPenWidth( 0 );
117 
118  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
119  DXF_PLOTTER* plotter = new DXF_PLOTTER();
120 
121  plotter->SetRenderSettings( aRenderSettings );
122  plotter->SetPageSettings( pageInfo );
123  plotter->SetColorMode( getModeColor() );
124  // Currently, plot units are in decimil
125  plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
126 
127  // Init :
128  plotter->SetCreator( wxT( "Eeschema-DXF" ) );
129 
130  if( ! plotter->OpenFile( aFileName ) )
131  {
132  delete plotter;
133  return false;
134  }
135 
136  LOCALE_IO toggle;
137 
138  plotter->StartPlot();
139 
140  if( aPlotFrameRef )
141  {
142  PlotWorkSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), pageInfo,
143  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
144  m_parent->GetScreenDesc(), aScreen->GetFileName(),
145  plotter->GetColorMode() ?
147  COLOR4D::BLACK );
148  }
149 
150  aScreen->Plot( plotter );
151 
152  // finish
153  plotter->EndPlot();
154  delete plotter;
155 
156  return true;
157 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_SHEET_LIST.
const wxString & GetFileName() const
Definition: sch_screen.h:185
int m_ScreenNumber
Definition: base_screen.h:79
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:164
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the scale/position for the DXF plot The DXF engine doesn't support line widths and mirroring.
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:77
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:143
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:146
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
COLOR_SETTINGS * getColorSettings()
Schematic editor (Eeschema) main window.
void CreateDXFFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aRenderSettings)
Definition: color4d.h:44
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:180
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
static wxString GetDefaultFileExtension()
Definition: plotter.h:1457
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
virtual bool StartPlot() override
Opens the DXF plot with a skeleton header.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
void PlotWorkSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCHEMATIC & Schematic() const
virtual bool EndPlot() override
SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:781
SCH_SHEET & Root() const
Definition: schematic.h:94
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
see class PGM_BASE
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
#define _(s)
Definition: 3d_actions.cpp:33
bool PlotOneSheetDXF(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
const TITLE_BLOCK & GetTitleBlock() const override
#define IU_PER_MILS
Definition: plotter.cpp:138
wxString GetUniqueFilenameForCurrentSheet()
int m_NumberOfScreens
Definition: base_screen.h:80
SCH_SHEET_PATH & GetCurrentSheet() const
WX_HTML_REPORT_PANEL * m_MessagesBox
void SetDefaultPenWidth(int aWidth)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
wxFileName createPlotFileName(wxString &aPlotFileName, wxString &aExtension, REPORTER *aReporter=NULL)
Create a file name with an absolute path name.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:149
bool GetColorMode() const
Definition: plotter.h:144