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.

322 lines
10 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /** @file dialog_plot_schematic.cpp
  2. */
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
  7. * Copyright (C) 1992-2010 Lorenzo Marcantonio
  8. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  9. *
  10. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, you may find one here:
  24. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. * or you may search the http://www.gnu.org website for the version 2 license,
  26. * or you may write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #include <pgm_base.h>
  30. #include <kiface_i.h>
  31. #include <bitmaps.h>
  32. #include <worksheet.h>
  33. #include <base_units.h>
  34. #include <sch_sheet.h>
  35. #include <dialog_plot_schematic.h>
  36. #include <wx_html_report_panel.h>
  37. // Keys for configuration
  38. #define PLOT_FORMAT_KEY wxT( "PlotFormat" )
  39. #define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
  40. #define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
  41. #define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
  42. #define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )
  43. #define PLOT_HPGL_PEN_SIZE_KEY wxT( "PlotHPGLPenSize" )
  44. // static members (static to remember last state):
  45. int DIALOG_PLOT_SCHEMATIC::m_pageSizeSelect = PAGE_SIZE_AUTO;
  46. void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
  47. {
  48. DIALOG_PLOT_SCHEMATIC dlg( this );
  49. dlg.ShowModal();
  50. // save project config if the prj config has changed:
  51. if( dlg.PrjConfigChanged() )
  52. SaveProjectSettings( false );
  53. }
  54. DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC( SCH_EDIT_FRAME* parent ) :
  55. DIALOG_PLOT_SCHEMATIC_BASE( parent )
  56. {
  57. m_parent = parent;
  58. m_configChanged = false;
  59. m_config = Kiface().KifaceSettings();
  60. m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
  61. // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
  62. // that requires us to correct the button labels here.
  63. m_sdbSizer1OK->SetLabel( _( "Plot All Pages" ) );
  64. m_sdbSizer1Apply->SetLabel( _( "Plot Current Page" ) );
  65. m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
  66. m_sdbSizer1->Layout();
  67. m_sdbSizer1OK->SetDefault();
  68. initDlg();
  69. // Now all widgets have the size fixed, call FinishDialogSettings
  70. FinishDialogSettings();
  71. }
  72. // Initialize the dialog options:
  73. void DIALOG_PLOT_SCHEMATIC::initDlg()
  74. {
  75. // Set color or B&W plot option
  76. bool tmp;
  77. m_config->Read( PLOT_MODECOLOR_KEY, &tmp, true );
  78. setModeColor( tmp );
  79. // Set plot or not frame reference option
  80. m_config->Read( PLOT_FRAME_REFERENCE_KEY, &tmp, true );
  81. setPlotFrameRef( tmp );
  82. // Set HPGL plot origin to center of paper of left bottom corner
  83. m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
  84. SetPlotOriginCenter( tmp );
  85. m_config->Read( PLOT_HPGL_PAPERSIZE_KEY, &m_HPGLPaperSizeSelect, 0 );
  86. // HPGL Pen Size is stored in mm in config
  87. m_config->Read( PLOT_HPGL_PEN_SIZE_KEY, &m_HPGLPenSize, 0.5 );
  88. m_HPGLPenSize *= IU_PER_MM;
  89. // Switch to the last save plot format
  90. long plotfmt;
  91. m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
  92. switch( plotfmt )
  93. {
  94. default:
  95. case PLOT_FORMAT_POST: m_plotFormatOpt->SetSelection( 0 ); break;
  96. case PLOT_FORMAT_PDF: m_plotFormatOpt->SetSelection( 1 ); break;
  97. case PLOT_FORMAT_SVG: m_plotFormatOpt->SetSelection( 2 ); break;
  98. case PLOT_FORMAT_DXF: m_plotFormatOpt->SetSelection( 3 ); break;
  99. case PLOT_FORMAT_HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
  100. }
  101. // Set the default line width (pen width which should be used for
  102. // items that do not have a pen size defined (like frame ref)
  103. PutValueInLocalUnits( *m_DefaultLineSizeCtrl, GetDefaultLineThickness() );
  104. // Initialize HPGL specific widgets
  105. PutValueInLocalUnits( *m_penHPGLWidthCtrl, m_HPGLPenSize );
  106. // Plot directory
  107. wxString path = m_parent->GetPlotDirectoryName();
  108. #ifdef __WINDOWS__
  109. path.Replace( '/', '\\' );
  110. #endif
  111. m_outputDirectoryName->SetValue( path );
  112. }
  113. /**
  114. * @todo Copy of DIALOG_PLOT::OnOutputDirectoryBrowseClicked in dialog_plot.cpp, maybe merge to
  115. * a common method.
  116. */
  117. void DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
  118. {
  119. // Build the absolute path of current output plot directory
  120. // to preselect it when opening the dialog.
  121. wxFileName fn( m_outputDirectoryName->GetValue() );
  122. wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
  123. wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
  124. if( dirDialog.ShowModal() == wxID_CANCEL )
  125. {
  126. return;
  127. }
  128. wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
  129. fn = Prj().AbsolutePath( g_RootSheet->GetFileName() );
  130. wxString defaultPath = fn.GetPathWithSep();
  131. wxString msg;
  132. msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ), GetChars( defaultPath ) );
  133. wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
  134. wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
  135. // relative directory selected
  136. if( dialog.ShowModal() == wxID_YES )
  137. {
  138. if( !dirName.MakeRelativeTo( defaultPath ) )
  139. wxMessageBox( _( "Cannot make path relative (target volume different from file "
  140. "volume)!" ), _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
  141. }
  142. m_outputDirectoryName->SetValue( dirName.GetFullPath() );
  143. }
  144. PlotFormat DIALOG_PLOT_SCHEMATIC::GetPlotFileFormat()
  145. {
  146. switch( m_plotFormatOpt->GetSelection() )
  147. {
  148. default:
  149. case 0: return PLOT_FORMAT_POST;
  150. case 1: return PLOT_FORMAT_PDF;
  151. case 2: return PLOT_FORMAT_SVG;
  152. case 3: return PLOT_FORMAT_DXF;
  153. case 4: return PLOT_FORMAT_HPGL;
  154. }
  155. }
  156. void DIALOG_PLOT_SCHEMATIC::OnPageSizeSelected( wxCommandEvent& event )
  157. {
  158. if( GetPlotFileFormat() == PLOT_FORMAT_HPGL )
  159. m_HPGLPaperSizeSelect = m_paperSizeOption->GetSelection();
  160. else
  161. m_pageSizeSelect = m_paperSizeOption->GetSelection();
  162. }
  163. void DIALOG_PLOT_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event )
  164. {
  165. PlotFormat fmt = GetPlotFileFormat();
  166. wxArrayString paperSizes;
  167. paperSizes.push_back( _( "Schematic size" ) );
  168. int selection;
  169. if( fmt == PLOT_FORMAT_HPGL )
  170. {
  171. paperSizes.push_back( _( "A4" ) );
  172. paperSizes.push_back( _( "A3" ) );
  173. paperSizes.push_back( _( "A2" ) );
  174. paperSizes.push_back( _( "A1" ) );
  175. paperSizes.push_back( _( "A0" ) );
  176. paperSizes.push_back( _( "A" ) );
  177. paperSizes.push_back( _( "B" ) );
  178. paperSizes.push_back( _( "C" ) );
  179. paperSizes.push_back( _( "D" ) );
  180. paperSizes.push_back( _( "E" ) );
  181. selection = m_HPGLPaperSizeSelect;
  182. }
  183. else
  184. {
  185. paperSizes.push_back( _( "A4" ) );
  186. paperSizes.push_back( _( "A" ) );
  187. selection = m_pageSizeSelect;
  188. }
  189. m_paperSizeOption->Set( paperSizes );
  190. m_paperSizeOption->SetSelection( selection );
  191. m_DefaultLineSizeCtrl->Enable( fmt == PLOT_FORMAT_POST
  192. || fmt == PLOT_FORMAT_PDF
  193. || fmt == PLOT_FORMAT_SVG );
  194. m_plotOriginOpt->Enable( fmt == PLOT_FORMAT_HPGL );
  195. m_penHPGLWidthCtrl->Enable( fmt == PLOT_FORMAT_HPGL );
  196. }
  197. void DIALOG_PLOT_SCHEMATIC::getPlotOptions()
  198. {
  199. m_config->Write( PLOT_MODECOLOR_KEY, getModeColor() );
  200. m_config->Write( PLOT_FRAME_REFERENCE_KEY, getPlotFrameRef() );
  201. m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
  202. m_config->Write( PLOT_HPGL_ORIGIN_KEY, GetPlotOriginCenter() );
  203. m_config->Write( PLOT_HPGL_PAPERSIZE_KEY, m_HPGLPaperSizeSelect );
  204. // HPGL Pen Size is stored in mm in config
  205. m_config->Write( PLOT_HPGL_PEN_SIZE_KEY, m_HPGLPenSize/IU_PER_MM );
  206. SetDefaultLineThickness( ValueFromTextCtrl( *m_DefaultLineSizeCtrl ) );
  207. // Plot directory
  208. wxString path = m_outputDirectoryName->GetValue();
  209. path.Replace( '\\', '/' );
  210. if( m_parent->GetPlotDirectoryName() != path )
  211. m_configChanged = true;
  212. m_parent->SetPlotDirectoryName( path );
  213. }
  214. void DIALOG_PLOT_SCHEMATIC::OnPlotCurrent( wxCommandEvent& event )
  215. {
  216. PlotSchematic( false );
  217. }
  218. void DIALOG_PLOT_SCHEMATIC::OnPlotAll( wxCommandEvent& event )
  219. {
  220. PlotSchematic( true );
  221. }
  222. void DIALOG_PLOT_SCHEMATIC::PlotSchematic( bool aPlotAll )
  223. {
  224. getPlotOptions();
  225. switch( GetPlotFileFormat() )
  226. {
  227. default:
  228. case PLOT_FORMAT_POST: createPSFile( aPlotAll, getPlotFrameRef() ); break;
  229. case PLOT_FORMAT_DXF: CreateDXFFile( aPlotAll, getPlotFrameRef() ); break;
  230. case PLOT_FORMAT_PDF: createPDFFile( aPlotAll, getPlotFrameRef() ); break;
  231. case PLOT_FORMAT_SVG: createSVGFile( aPlotAll, getPlotFrameRef() ); break;
  232. case PLOT_FORMAT_HPGL: createHPGLFile( aPlotAll, getPlotFrameRef() ); break;
  233. }
  234. }
  235. wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirectoryName,
  236. wxString& aPlotFileName,
  237. wxString& aExtension,
  238. REPORTER* aReporter )
  239. {
  240. wxString outputDirName = aOutputDirectoryName->GetValue();
  241. wxFileName outputDir = wxFileName::DirName( outputDirName );
  242. wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT( "." ) + aExtension);
  243. if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
  244. {
  245. wxString msg;
  246. msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
  247. GetChars( outputDir.GetPath() ) );
  248. aReporter->Report( msg, REPORTER::RPT_ERROR );
  249. }
  250. wxFileName fn( plotFileName );
  251. fn.SetPath( outputDir.GetFullPath() );
  252. return fn;
  253. }