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 
34 #include <dialog_plot_schematic.h>
35 #include <wx_html_report_panel.h>
36 
37 
38 void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
39 {
40  SCH_EDIT_FRAME* schframe = m_parent;
41  SCH_SCREEN* screen = schframe->GetScreen();
42  SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
43 
44  /* When printing all pages, the printed page is not the current page.
45  * In complex hierarchies, we must setup references and others parameters
46  * in the printed SCH_SCREEN
47  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
48  * is shared between many sheets
49  */
50  SCH_SHEET_LIST sheetList;
51 
52  if( aPlotAll )
53  sheetList.BuildSheetList( g_RootSheet );
54  else
55  sheetList.push_back( schframe->GetCurrentSheet() );
56 
57  REPORTER& reporter = m_MessagesBox->Reporter();
58 
59  for( unsigned i = 0; i < sheetList.size(); i++ )
60  {
61  schframe->SetCurrentSheet( sheetList[i] );
63  schframe->SetSheetNumberAndCount();
64  screen = schframe->GetCurrentSheet().LastScreen();
65 
66  wxPoint plot_offset;
67  wxString msg;
68 
69  try
70  {
71  wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
72  wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
73  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
74  ext, &reporter );
75 
76  if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0,
77  aPlotFrameRef ) )
78  {
79  msg.Printf( _( "Plot: \"%s\" OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
80  reporter.Report( msg, REPORTER::RPT_ACTION );
81  }
82  else // Error
83  {
84  msg.Printf( _( "Unable to create file \"%s\".\n" ),
85  GetChars( plotFileName.GetFullPath() ) );
86  reporter.Report( msg, REPORTER::RPT_ERROR );
87  }
88  }
89  catch( IO_ERROR& e )
90  {
91  msg.Printf( wxT( "DXF Plotter exception: %s"), GetChars( e.What() ) );
92  reporter.Report( msg, REPORTER::RPT_ERROR );
93  schframe->SetCurrentSheet( oldsheetpath );
95  schframe->SetSheetNumberAndCount();
96  return;
97  }
98  }
99 
100  schframe->SetCurrentSheet( oldsheetpath );
102  schframe->SetSheetNumberAndCount();
103 }
104 
105 
106 bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
107  SCH_SCREEN* aScreen,
108  wxPoint aPlotOffset,
109  double aScale,
110  bool aPlotFrameRef )
111 {
112  DXF_PLOTTER* plotter = new DXF_PLOTTER();
113 
114  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
115  plotter->SetPageSettings( pageInfo );
116  plotter->SetColorMode( getModeColor() );
117  // Currently, plot units are in decimil
118  plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
119 
120  // Init :
121  plotter->SetCreator( wxT( "Eeschema-DXF" ) );
122 
123  if( ! plotter->OpenFile( aFileName ) )
124  {
125  delete plotter;
126  return false;
127  }
128 
129  LOCALE_IO toggle;
130 
131  plotter->StartPlot();
132 
133  if( aPlotFrameRef )
134  {
135  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
137  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
139  aScreen->GetFileName() );
140  }
141 
142  aScreen->Plot( plotter );
143 
144  // finish
145  plotter->EndPlot();
146  delete plotter;
147 
148  return true;
149 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_SHEET_LIST.
void CreateDXFFile(bool aPlotAll, bool aPlotFrameRef)
int m_ScreenNumber
Definition: base_screen.h:216
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:161
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
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&#39;t support line widths and mirroring...
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:79
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:126
const wxString & GetFileName() const
Definition: sch_screen.h:131
Schematic editor (Eeschema) main window.
SCH_SCREEN * LastScreen() const
Function LastScreen.
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.cpp:537
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename)
static wxString GetDefaultFileExtension()
Definition: plotter.h:1247
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual wxString GetScreenDesc() const override
virtual bool StartPlot() override
Opens the DXF plot with a skeleton header.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
wxFileName createPlotFileName(wxTextCtrl *aOutputDirectoryName, wxString &aPlotFileName, wxString &aExtension, REPORTER *aReporter=NULL)
Create a file name with an absolute path name.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
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
Class 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:533
const PAGE_INFO & GetPageSettings() const override
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
const TITLE_BLOCK & GetTitleBlock() const override
size_t i
Definition: json11.cpp:597
#define IU_PER_MILS
Definition: plotter.cpp:134
wxString GetUniqueFilenameForCurrentSheet()
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
int m_NumberOfScreens
Definition: base_screen.h:217
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:126
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