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-2017 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 <project.h>
33 #include <pgm_base.h>
35 
36 #include <dialog_plot_schematic.h>
37 #include <wx_html_report_panel.h>
38 
39 
40 void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
41 {
42  SCH_EDIT_FRAME* schframe = m_parent;
43  SCH_SCREEN* screen = schframe->GetScreen();
44  SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
45 
46  /* When printing all pages, the printed page is not the current page.
47  * In complex hierarchies, we must setup references and others parameters
48  * in the printed SCH_SCREEN
49  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
50  * is shared between many sheets
51  */
52  SCH_SHEET_LIST sheetList;
53 
54  if( aPlotAll )
55  sheetList.BuildSheetList( g_RootSheet );
56  else
57  sheetList.push_back( schframe->GetCurrentSheet() );
58 
59  REPORTER& reporter = m_MessagesBox->Reporter();
60 
61  for( unsigned i = 0; i < sheetList.size(); i++ )
62  {
63  schframe->SetCurrentSheet( sheetList[i] );
65  schframe->SetSheetNumberAndCount();
66  screen = schframe->GetCurrentSheet().LastScreen();
67 
68  wxPoint plot_offset;
69  wxString msg;
70 
71  try
72  {
73  wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
74  wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
75  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
76  ext, &reporter );
77 
78  if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0,
79  aPlotFrameRef ) )
80  {
81  msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
82  reporter.Report( msg, RPT_SEVERITY_ACTION );
83  }
84  else // Error
85  {
86  msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
87  reporter.Report( msg, RPT_SEVERITY_ERROR );
88  }
89  }
90  catch( IO_ERROR& e )
91  {
92  msg.Printf( wxT( "DXF Plotter exception: %s"), e.What() );
93  reporter.Report( msg, RPT_SEVERITY_ERROR );
94  schframe->SetCurrentSheet( oldsheetpath );
96  schframe->SetSheetNumberAndCount();
97  return;
98  }
99  }
100 
101  schframe->SetCurrentSheet( oldsheetpath );
103  schframe->SetSheetNumberAndCount();
104 }
105 
106 
107 bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
108  SCH_SCREEN* aScreen,
109  wxPoint aPlotOffset,
110  double aScale,
111  bool aPlotFrameRef )
112 {
113  DXF_PLOTTER* plotter = new DXF_PLOTTER();
114 
115  auto colors = static_cast<COLOR_SETTINGS*>(
116  m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) );
117 
118  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
119  plotter->SetPageSettings( pageInfo );
120  plotter->SetColorMode( getModeColor() );
121  plotter->SetColorSettings( colors );
122  // Currently, plot units are in decimil
123  plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
124 
125  // Init :
126  plotter->SetCreator( wxT( "Eeschema-DXF" ) );
127 
128  if( ! plotter->OpenFile( aFileName ) )
129  {
130  delete plotter;
131  return false;
132  }
133 
134  LOCALE_IO toggle;
135 
136  plotter->StartPlot();
137 
138  if( aPlotFrameRef )
139  {
140  COLOR4D color = plotter->GetColorMode() ?
143 
144  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
146  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
148  aScreen->GetFileName(),
149  color );
150  }
151 
152  aScreen->Plot( plotter );
153 
154  // finish
155  plotter->EndPlot();
156  delete plotter;
157 
158  return true;
159 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_SHEET_LIST.
void CreateDXFFile(bool aPlotAll, bool aPlotFrameRef)
const wxString & GetFileName() const
Definition: sch_screen.h:157
int m_ScreenNumber
Definition: base_screen.h:135
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:180
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:202
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:82
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:133
int color
Definition: DXF_plotter.cpp:61
Schematic editor (Eeschema) main window.
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:62
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:152
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.
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, const COLOR4D aColor)
static wxString GetDefaultFileExtension()
Definition: plotter.h:1421
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:33
COLOR_SETTINGS * ColorSettings()
Definition: plotter.h:145
wxFileName createPlotFileName(wxTextCtrl *aOutputDirectoryName, wxString &aPlotFileName, wxString &aExtension, REPORTER *aReporter=NULL)
Create a file name with an absolute path name.
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
SCH_SHEET_PATH & GetCurrentSheet()
bool PlotOneSheetDXF(const wxString &aFileName, SCH_SCREEN *aScreen, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
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:573
const PAGE_INFO & GetPageSettings() const override
COLOR4D GetColor(int aLayer) const
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
const TITLE_BLOCK & GetTitleBlock() const override
#define IU_PER_MILS
Definition: plotter.cpp:137
void SetColorSettings(COLOR_SETTINGS *aSettings)
Definition: plotter.h:143
wxString GetUniqueFilenameForCurrentSheet()
int m_NumberOfScreens
Definition: base_screen.h:136
SCH_SHEET * g_RootSheet
Definition: colors.h:45
WX_HTML_REPORT_PANEL * m_MessagesBox
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
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
static VRML_COLOR colors[VRML_COLOR_LAST]
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:147
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
bool GetColorMode() const
Definition: plotter.h:138