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 <class_plotter.h>
30 #include <class_sch_screen.h>
31 #include <schframe.h>
32 #include <sch_sheet_path.h>
33 #include <project.h>
34 
35 #include <dialog_plot_schematic.h>
36 #include <wx_html_report_panel.h>
37 
38 
39 void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
40 {
41  SCH_EDIT_FRAME* schframe = m_parent;
42  SCH_SCREEN* screen = schframe->GetScreen();
43  SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
44 
45  /* When printing all pages, the printed page is not the current page.
46  * In complex hierarchies, we must setup references and others parameters
47  * in the printed SCH_SCREEN
48  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
49  * is shared between many sheets
50  */
51  SCH_SHEET_LIST sheetList;
52 
53  if( aPlotAll )
54  sheetList.BuildSheetList( g_RootSheet );
55  else
56  sheetList.push_back( schframe->GetCurrentSheet() );
57 
58  REPORTER& reporter = m_MessagesBox->Reporter();
59 
60  for( unsigned i = 0; i < sheetList.size(); i++ )
61  {
62  schframe->SetCurrentSheet( sheetList[i] );
64  schframe->SetSheetNumberAndCount();
65  screen = schframe->GetCurrentSheet().LastScreen();
66 
67  wxPoint plot_offset;
68  wxString msg;
69 
70  try
71  {
72  wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
73  wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
74  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
75  ext, &reporter );
76 
77  if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0,
78  aPlotFrameRef ) )
79  {
80  msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
81  reporter.Report( msg, REPORTER::RPT_ACTION );
82  }
83  else // Error
84  {
85  msg.Printf( _( "Unable to create file '%s'.\n" ),
86  GetChars( plotFileName.GetFullPath() ) );
87  reporter.Report( msg, REPORTER::RPT_ERROR );
88  }
89  }
90  catch( IO_ERROR& e )
91  {
92  msg.Printf( wxT( "DXF Plotter exception: %s"), GetChars( e.What() ) );
93  reporter.Report( msg, REPORTER::RPT_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  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
116  plotter->SetPageSettings( pageInfo );
117  plotter->SetColorMode( getModeColor() );
118  // Currently, plot units are in decimil
119  plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
120 
121  // Init :
122  plotter->SetCreator( wxT( "Eeschema-DXF" ) );
123 
124  if( ! plotter->OpenFile( aFileName ) )
125  {
126  delete plotter;
127  return false;
128  }
129 
130  LOCALE_IO toggle;
131 
132  plotter->StartPlot();
133 
134  if( aPlotFrameRef )
135  {
136  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
138  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
140  aScreen->GetFileName() );
141  }
142 
143  aScreen->Plot( plotter );
144 
145  // finish
146  plotter->EndPlot();
147  delete plotter;
148 
149  return true;
150 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Definition: schframe.cpp:586
Class SCH_SHEET_LIST.
void CreateDXFFile(bool aPlotAll, bool aPlotFrameRef)
virtual void SetCreator(const wxString &aCreator)
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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.
const wxString & GetFileName() const
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
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)
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()
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:533
virtual wxString GetScreenDesc() const override
Definition: schframe.cpp:539
virtual bool StartPlot() override
Opens the DXF plot with a skeleton header.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
Definitions for the Eeschema program SCH_SCREEN class.
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...
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_SHEET_PATH & GetCurrentSheet()
Definition: schframe.cpp:578
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:542
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.
Definition: schframe.cpp:498
const TITLE_BLOCK & GetTitleBlock() const override
wxString GetUniqueFilenameForCurrentSheet()
Definition: schframe.cpp:743
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const PAGE_INFO & GetPageSettings() const
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:47
virtual void SetColorMode(bool _color_mode)