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.

880 lines
31 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
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <kiface_i.h>
  24. #include <plotter.h>
  25. #include <confirm.h>
  26. #include <pcb_edit_frame.h>
  27. #include <pcbplot.h>
  28. #include <gerber_jobfile_writer.h>
  29. #include <reporter.h>
  30. #include <wildcards_and_files_ext.h>
  31. #include <bitmaps.h>
  32. #include <class_board.h>
  33. #include <dialog_plot.h>
  34. #include <wx_html_report_panel.h>
  35. #include <drc.h>
  36. DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) :
  37. DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
  38. m_defaultLineWidth( aParent, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits, true, 0 ),
  39. m_defaultPenSize( aParent, m_hpglPenLabel, m_hpglPenCtrl, m_hpglPenUnits, true, 0 ),
  40. m_trackWidthCorrection( aParent, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits, true )
  41. {
  42. SetName( DLG_WINDOW_NAME );
  43. m_config = Kiface().KifaceSettings();
  44. m_plotOpts = aParent->GetPlotSettings();
  45. init_Dialog();
  46. // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
  47. // that requires us to correct the button labels here.
  48. m_sdbSizer1OK->SetLabel( _( "Plot" ) );
  49. m_sdbSizer1Apply->SetLabel( _( "Generate Drill Files..." ) );
  50. m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
  51. m_sizerButtons->Layout();
  52. m_sdbSizer1OK->SetDefault();
  53. GetSizer()->Fit( this );
  54. GetSizer()->SetSizeHints( this );
  55. }
  56. void DIALOG_PLOT::init_Dialog()
  57. {
  58. BOARD* board = m_parent->GetBoard();
  59. wxFileName fileName;
  60. m_config->Read( OPTKEY_PLOT_X_FINESCALE_ADJ, &m_XScaleAdjust );
  61. m_config->Read( OPTKEY_PLOT_Y_FINESCALE_ADJ, &m_YScaleAdjust );
  62. bool checkZones;
  63. m_config->Read( OPTKEY_PLOT_CHECK_ZONES, &checkZones, true );
  64. m_zoneFillCheck->SetValue( checkZones );
  65. m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
  66. // m_PSWidthAdjust is stored in mm in user config
  67. double dtmp;
  68. m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 );
  69. m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM );
  70. // The reasonable width correction value must be in a range of
  71. // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
  72. m_widthAdjustMinValue = -( board->GetDesignSettings().m_TrackMinWidth - 1 );
  73. m_widthAdjustMaxValue = board->GetDesignSettings().GetSmallestClearanceValue() - 1;
  74. switch( m_plotOpts.GetFormat() )
  75. {
  76. default:
  77. case PLOT_FORMAT_GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
  78. case PLOT_FORMAT_POST: m_plotFormatOpt->SetSelection( 1 ); break;
  79. case PLOT_FORMAT_SVG: m_plotFormatOpt->SetSelection( 2 ); break;
  80. case PLOT_FORMAT_DXF: m_plotFormatOpt->SetSelection( 3 ); break;
  81. case PLOT_FORMAT_HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
  82. case PLOT_FORMAT_PDF: m_plotFormatOpt->SetSelection( 5 ); break;
  83. }
  84. // Set units and value for HPGL pen size (this param is in mils).
  85. m_defaultPenSize.SetValue( m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS );
  86. m_defaultLineWidth.SetValue( m_plotOpts.GetLineWidth() );
  87. // Test for a reasonable scale value. Set to 1 if problem
  88. if( m_XScaleAdjust < PLOT_MIN_SCALE || m_YScaleAdjust < PLOT_MIN_SCALE
  89. || m_XScaleAdjust > PLOT_MAX_SCALE || m_YScaleAdjust > PLOT_MAX_SCALE )
  90. m_XScaleAdjust = m_YScaleAdjust = 1.0;
  91. m_fineAdjustXCtrl->SetValue( StringFromValue( UNSCALED_UNITS, m_XScaleAdjust ) );
  92. m_fineAdjustYCtrl->SetValue( StringFromValue( UNSCALED_UNITS, m_YScaleAdjust ) );
  93. // Test for a reasonable PS width correction value. Set to 0 if problem.
  94. if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
  95. m_PSWidthAdjust = 0.;
  96. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  97. m_plotPSNegativeOpt->SetValue( m_plotOpts.GetNegative() );
  98. m_forcePSA4OutputOpt->SetValue( m_plotOpts.GetA4Output() );
  99. // Could devote a PlotOrder() function in place of UIOrder().
  100. m_layerList = board->GetEnabledLayers().UIOrder();
  101. // Populate the check list box by all enabled layers names
  102. for( LSEQ seq = m_layerList; seq; ++seq )
  103. {
  104. PCB_LAYER_ID layer = *seq;
  105. int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
  106. if( m_plotOpts.GetLayerSelection()[layer] )
  107. m_layerCheckListBox->Check( checkIndex );
  108. }
  109. // Option for using proper Gerber extensions
  110. m_useGerberExtensions->SetValue( m_plotOpts.GetUseGerberProtelExtensions() );
  111. // Option for including Gerber attributes (from Gerber X2 format) in the output
  112. m_useGerberX2Attributes->SetValue( m_plotOpts.GetUseGerberAttributes() );
  113. // Option for including Gerber netlist info (from Gerber X2 format) in the output
  114. m_useGerberNetAttributes->SetValue( m_plotOpts.GetIncludeGerberNetlistInfo() );
  115. // Grey out if m_useGerberX2Attributes is not checked
  116. m_useGerberNetAttributes->Enable( m_useGerberX2Attributes->GetValue() );
  117. // Option to generate a Gerber job file
  118. m_generateGerberJobFile->SetValue( m_plotOpts.GetCreateGerberJobFile() );
  119. // Gerber precision for coordinates
  120. m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
  121. // Option for excluding contents of "Edges Pcb" layer
  122. m_excludeEdgeLayerOpt->SetValue( m_plotOpts.GetExcludeEdgeLayer() );
  123. // Option to exclude pads from silkscreen layers
  124. m_excludePadsFromSilkscreen->SetValue( !m_plotOpts.GetPlotPadsOnSilkLayer() );
  125. m_subtractMaskFromSilk->SetValue( m_plotOpts.GetSubtractMaskFromSilk() );
  126. // Option to plot page references:
  127. m_plotSheetRef->SetValue( m_plotOpts.GetPlotFrameRef() );
  128. // Options to plot texts on footprints
  129. m_plotModuleValueOpt->SetValue( m_plotOpts.GetPlotValue() );
  130. m_plotModuleRefOpt->SetValue( m_plotOpts.GetPlotReference() );
  131. m_plotInvisibleText->SetValue( m_plotOpts.GetPlotInvisibleText() );
  132. // Options to plot pads and vias holes
  133. m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
  134. // Scale option
  135. m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
  136. // Plot mode
  137. setPlotModeChoiceSelection( m_plotOpts.GetPlotMode() );
  138. // Plot outline mode
  139. m_DXF_plotModeOpt->SetValue( m_plotOpts.GetDXFPlotPolygonMode() );
  140. // Plot text mode
  141. m_DXF_plotTextStrokeFontOpt->SetValue( m_plotOpts.GetTextMode() == PLOTTEXTMODE_DEFAULT );
  142. // Plot mirror option
  143. m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
  144. // Put vias on mask layer
  145. m_plotNoViaOnMaskOpt->SetValue( m_plotOpts.GetPlotViaOnMaskLayer() );
  146. // Initialize a few other parameters, which can also be modified
  147. // from the drill dialog
  148. reInitDialog();
  149. // Update options values:
  150. wxCommandEvent cmd_event;
  151. SetPlotFormat( cmd_event );
  152. OnSetScaleOpt( cmd_event );
  153. }
  154. void DIALOG_PLOT::reInitDialog()
  155. {
  156. // after calling drill dialog, some parameters can be modified.
  157. // update them
  158. // Output directory
  159. m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
  160. // Origin of coordinates:
  161. m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() );
  162. }
  163. // A helper function to show a popup menu, when the dialog is right clicked.
  164. void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
  165. {
  166. PopupMenu( m_popMenu );
  167. }
  168. // Select or deselect groups of layers in the layers list:
  169. #include <layers_id_colors_and_visibility.h>
  170. void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
  171. {
  172. unsigned int i;
  173. switch( event.GetId() )
  174. {
  175. case ID_LAYER_FAB: // Select layers usually needed to build a board
  176. for( i = 0; i < m_layerList.size(); i++ )
  177. {
  178. LSET layermask( m_layerList[ i ] );
  179. if( ( layermask & ( LSET::AllCuMask() | LSET::AllTechMask() ) ).any() )
  180. m_layerCheckListBox->Check( i, true );
  181. else
  182. m_layerCheckListBox->Check( i, false );
  183. }
  184. break;
  185. case ID_SELECT_COPPER_LAYERS:
  186. for( i = 0; i < m_layerList.size(); i++ )
  187. {
  188. if( IsCopperLayer( m_layerList[i] ) )
  189. m_layerCheckListBox->Check( i, true );
  190. }
  191. break;
  192. case ID_DESELECT_COPPER_LAYERS:
  193. for( i = 0; i < m_layerList.size(); i++ )
  194. {
  195. if( IsCopperLayer( m_layerList[i] ) )
  196. m_layerCheckListBox->Check( i, false );
  197. }
  198. break;
  199. case ID_SELECT_ALL_LAYERS:
  200. for( i = 0; i < m_layerList.size(); i++ )
  201. m_layerCheckListBox->Check( i, true );
  202. break;
  203. case ID_DESELECT_ALL_LAYERS:
  204. for( i = 0; i < m_layerList.size(); i++ )
  205. m_layerCheckListBox->Check( i, false );
  206. break;
  207. default:
  208. break;
  209. }
  210. }
  211. void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
  212. {
  213. // Be sure drill file use the same settings (axis option, plot directory)
  214. // than plot files:
  215. applyPlotSettings();
  216. m_parent->InstallDrillFrame( event );
  217. // a few plot settings can be modified: take them in account
  218. m_plotOpts = m_parent->GetPlotSettings();
  219. reInitDialog();
  220. }
  221. void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
  222. {
  223. // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
  224. // is checked (plot in DXF polygon mode)
  225. m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
  226. // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
  227. // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
  228. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
  229. m_DXF_plotTextStrokeFontOpt->SetValue( true );
  230. }
  231. void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
  232. {
  233. /* Disable sheet reference for scale != 1:1 */
  234. bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
  235. m_plotSheetRef->Enable( scale1 );
  236. if( !scale1 )
  237. m_plotSheetRef->SetValue( false );
  238. }
  239. void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
  240. {
  241. // Build the absolute path of current output plot directory
  242. // to preselect it when opening the dialog.
  243. wxFileName fn( m_outputDirectoryName->GetValue() );
  244. wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
  245. wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
  246. if( dirDialog.ShowModal() == wxID_CANCEL )
  247. return;
  248. wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
  249. fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
  250. wxString defaultPath = fn.GetPathWithSep();
  251. wxString msg;
  252. msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ),
  253. GetChars( defaultPath ) );
  254. wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
  255. wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
  256. if( dialog.ShowModal() == wxID_YES )
  257. {
  258. if( !dirName.MakeRelativeTo( defaultPath ) )
  259. wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
  260. _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
  261. }
  262. m_outputDirectoryName->SetValue( dirName.GetFullPath() );
  263. }
  264. PlotFormat DIALOG_PLOT::getPlotFormat()
  265. {
  266. // plot format id's are ordered like displayed in m_plotFormatOpt
  267. static const PlotFormat plotFmt[] =
  268. {
  269. PLOT_FORMAT_GERBER,
  270. PLOT_FORMAT_POST,
  271. PLOT_FORMAT_SVG,
  272. PLOT_FORMAT_DXF,
  273. PLOT_FORMAT_HPGL,
  274. PLOT_FORMAT_PDF
  275. };
  276. return plotFmt[ m_plotFormatOpt->GetSelection() ];
  277. }
  278. // Enable or disable widgets according to the plot format selected
  279. // and clear also some optional values
  280. void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
  281. {
  282. // this option exist only in DXF format:
  283. m_DXF_plotModeOpt->Enable( getPlotFormat() == PLOT_FORMAT_DXF );
  284. switch( getPlotFormat() )
  285. {
  286. case PLOT_FORMAT_PDF:
  287. case PLOT_FORMAT_SVG:
  288. m_drillShapeOpt->Enable( true );
  289. m_plotModeOpt->Enable( false );
  290. setPlotModeChoiceSelection( FILLED );
  291. m_plotMirrorOpt->Enable( true );
  292. m_useAuxOriginCheckBox->Enable( false );
  293. m_useAuxOriginCheckBox->SetValue( false );
  294. m_defaultLineWidth.Enable( true );
  295. m_defaultPenSize.Enable( false );
  296. m_excludeEdgeLayerOpt->Enable( true );
  297. m_scaleOpt->Enable( false );
  298. m_scaleOpt->SetSelection( 1 );
  299. m_fineAdjustXCtrl->Enable( false );
  300. m_fineAdjustYCtrl->Enable( false );
  301. m_trackWidthCorrection.Enable( false );
  302. m_plotPSNegativeOpt->Enable( true );
  303. m_forcePSA4OutputOpt->Enable( false );
  304. m_forcePSA4OutputOpt->SetValue( false );
  305. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  306. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  307. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  308. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  309. break;
  310. case PLOT_FORMAT_POST:
  311. m_drillShapeOpt->Enable( true );
  312. m_plotModeOpt->Enable( true );
  313. m_plotMirrorOpt->Enable( true );
  314. m_useAuxOriginCheckBox->Enable( false );
  315. m_useAuxOriginCheckBox->SetValue( false );
  316. m_defaultLineWidth.Enable( true );
  317. m_defaultPenSize.Enable( false );
  318. m_excludeEdgeLayerOpt->Enable( true );
  319. m_scaleOpt->Enable( true );
  320. m_fineAdjustXCtrl->Enable( true );
  321. m_fineAdjustYCtrl->Enable( true );
  322. m_trackWidthCorrection.Enable( true );
  323. m_plotPSNegativeOpt->Enable( true );
  324. m_forcePSA4OutputOpt->Enable( true );
  325. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  326. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  327. m_PlotOptionsSizer->Show( m_PSOptionsSizer );
  328. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  329. break;
  330. case PLOT_FORMAT_GERBER:
  331. m_drillShapeOpt->Enable( false );
  332. m_drillShapeOpt->SetSelection( 0 );
  333. m_plotModeOpt->Enable( false );
  334. setPlotModeChoiceSelection( FILLED );
  335. m_plotMirrorOpt->Enable( false );
  336. m_plotMirrorOpt->SetValue( false );
  337. m_useAuxOriginCheckBox->Enable( true );
  338. m_defaultLineWidth.Enable( true );
  339. m_defaultPenSize.Enable( false );
  340. m_excludeEdgeLayerOpt->Enable( true );
  341. m_scaleOpt->Enable( false );
  342. m_scaleOpt->SetSelection( 1 );
  343. m_fineAdjustXCtrl->Enable( false );
  344. m_fineAdjustYCtrl->Enable( false );
  345. m_trackWidthCorrection.Enable( false );
  346. m_plotPSNegativeOpt->Enable( false );
  347. m_plotPSNegativeOpt->SetValue( false );
  348. m_forcePSA4OutputOpt->Enable( false );
  349. m_forcePSA4OutputOpt->SetValue( false );
  350. m_PlotOptionsSizer->Show( m_GerberOptionsSizer );
  351. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  352. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  353. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  354. break;
  355. case PLOT_FORMAT_HPGL:
  356. m_drillShapeOpt->Enable( true );
  357. m_plotModeOpt->Enable( true );
  358. m_plotMirrorOpt->Enable( true );
  359. m_useAuxOriginCheckBox->Enable( false );
  360. m_useAuxOriginCheckBox->SetValue( false );
  361. m_defaultLineWidth.Enable( false );
  362. m_defaultPenSize.Enable( true );
  363. m_excludeEdgeLayerOpt->Enable( true );
  364. m_scaleOpt->Enable( true );
  365. m_fineAdjustXCtrl->Enable( false );
  366. m_fineAdjustYCtrl->Enable( false );
  367. m_trackWidthCorrection.Enable( false );
  368. m_plotPSNegativeOpt->SetValue( false );
  369. m_plotPSNegativeOpt->Enable( false );
  370. m_forcePSA4OutputOpt->Enable( true );
  371. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  372. m_PlotOptionsSizer->Show( m_HPGLOptionsSizer );
  373. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  374. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  375. break;
  376. case PLOT_FORMAT_DXF:
  377. m_drillShapeOpt->Enable( true );
  378. m_plotModeOpt->Enable( false );
  379. setPlotModeChoiceSelection( FILLED );
  380. m_plotMirrorOpt->Enable( false );
  381. m_plotMirrorOpt->SetValue( false );
  382. m_useAuxOriginCheckBox->Enable( true );
  383. m_defaultLineWidth.Enable( false );
  384. m_defaultPenSize.Enable( false );
  385. m_excludeEdgeLayerOpt->Enable( true );
  386. m_scaleOpt->Enable( false );
  387. m_scaleOpt->SetSelection( 1 );
  388. m_fineAdjustXCtrl->Enable( false );
  389. m_fineAdjustYCtrl->Enable( false );
  390. m_trackWidthCorrection.Enable( false );
  391. m_plotPSNegativeOpt->Enable( false );
  392. m_plotPSNegativeOpt->SetValue( false );
  393. m_forcePSA4OutputOpt->Enable( false );
  394. m_forcePSA4OutputOpt->SetValue( false );
  395. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  396. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  397. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  398. m_PlotOptionsSizer->Show( m_SizerDXF_options );
  399. OnChangeDXFPlotMode( event );
  400. break;
  401. case PLOT_FORMAT_UNDEFINED:
  402. break;
  403. }
  404. /* Update the interlock between scale and frame reference
  405. * (scaling would mess up the frame border...) */
  406. OnSetScaleOpt( event );
  407. Layout();
  408. m_MainSizer->SetSizeHints( this );
  409. }
  410. // A helper function to "clip" aValue between aMin and aMax
  411. // and write result in * aResult
  412. // return false if clipped, true if aValue is just copied into * aResult
  413. static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
  414. {
  415. if( aValue < aMin )
  416. {
  417. *aResult = aMin;
  418. return false;
  419. }
  420. else if( aValue > aMax )
  421. {
  422. *aResult = aMax;
  423. return false;
  424. }
  425. *aResult = aValue;
  426. return true;
  427. }
  428. static bool setInt( int* aResult, int aValue, int aMin, int aMax )
  429. {
  430. if( aValue < aMin )
  431. {
  432. *aResult = aMin;
  433. return false;
  434. }
  435. else if( aValue > aMax )
  436. {
  437. *aResult = aMax;
  438. return false;
  439. }
  440. *aResult = aValue;
  441. return true;
  442. }
  443. void DIALOG_PLOT::applyPlotSettings()
  444. {
  445. REPORTER& reporter = m_messagesPanel->Reporter();
  446. PCB_PLOT_PARAMS tempOptions;
  447. tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
  448. tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
  449. tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
  450. tempOptions.SetPlotPadsOnSilkLayer( !m_excludePadsFromSilkscreen->GetValue() );
  451. tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
  452. tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
  453. tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
  454. tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
  455. tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
  456. tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>
  457. ( m_drillShapeOpt->GetSelection() ) );
  458. tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
  459. tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
  460. tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
  461. tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
  462. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
  463. tempOptions.SetTextMode( PLOTTEXTMODE_DEFAULT );
  464. else
  465. tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ?
  466. PLOTTEXTMODE_DEFAULT : PLOTTEXTMODE_NATIVE );
  467. // Update settings from text fields. Rewrite values back to the fields,
  468. // since the values may have been constrained by the setters.
  469. wxString msg;
  470. // read HPLG pen size (this param is stored in mils)
  471. // However, due to issues when converting this value from or to mm
  472. // that can slightly change the value, update this param only if it
  473. // is in use
  474. if( getPlotFormat() == PLOT_FORMAT_HPGL )
  475. {
  476. if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
  477. {
  478. m_defaultPenSize.SetValue( tempOptions.GetHPGLPenDiameter() * IU_PER_MILS );
  479. msg.Printf( _( "HPGL pen size constrained." ) );
  480. reporter.Report( msg, REPORTER::RPT_INFO );
  481. }
  482. }
  483. else // keep the last value (initial value if no HPGL plot made)
  484. tempOptions.SetHPGLPenDiameter( m_plotOpts.GetHPGLPenDiameter() );
  485. // Default linewidth
  486. if( !tempOptions.SetLineWidth( m_defaultLineWidth.GetValue() ) )
  487. {
  488. m_defaultLineWidth.SetValue( tempOptions.GetLineWidth() );
  489. msg.Printf( _( "Default line width constrained." ) );
  490. reporter.Report( msg, REPORTER::RPT_INFO );
  491. }
  492. // X scale
  493. double tmpDouble;
  494. msg = m_fineAdjustXCtrl->GetValue();
  495. msg.ToDouble( &tmpDouble );
  496. if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  497. {
  498. msg.Printf( wxT( "%f" ), m_XScaleAdjust );
  499. m_fineAdjustXCtrl->SetValue( msg );
  500. msg.Printf( _( "X scale constrained." ) );
  501. reporter.Report( msg, REPORTER::RPT_INFO );
  502. }
  503. ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_X_FINESCALE_ADJ, m_XScaleAdjust );
  504. // Y scale
  505. msg = m_fineAdjustYCtrl->GetValue();
  506. msg.ToDouble( &tmpDouble );
  507. if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  508. {
  509. msg.Printf( wxT( "%f" ), m_YScaleAdjust );
  510. m_fineAdjustYCtrl->SetValue( msg );
  511. msg.Printf( _( "Y scale constrained." ) );
  512. reporter.Report( msg, REPORTER::RPT_INFO );
  513. }
  514. ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_Y_FINESCALE_ADJ, m_YScaleAdjust );
  515. m_config->Write( OPTKEY_PLOT_CHECK_ZONES, m_zoneFillCheck->GetValue() );
  516. // PS Width correction
  517. if( !setInt( &m_PSWidthAdjust, m_trackWidthCorrection.GetValue(),
  518. m_widthAdjustMinValue, m_widthAdjustMaxValue ) )
  519. {
  520. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  521. msg.Printf( _( "Width correction constrained. "
  522. "The reasonable width correction value must be in a range of "
  523. " [%s; %s] (%s) for current design rules." ),
  524. StringFromValue( GetUserUnits(), m_widthAdjustMinValue, false, true ),
  525. StringFromValue( GetUserUnits(), m_widthAdjustMaxValue, false, true ),
  526. GetAbbreviatedUnitsLabel( GetUserUnits(), true ) );
  527. reporter.Report( msg, REPORTER::RPT_WARNING );
  528. }
  529. // Store m_PSWidthAdjust in mm in user config
  530. ConfigBaseWriteDouble( m_config, CONFIG_PS_FINEWIDTH_ADJ,
  531. (double)m_PSWidthAdjust / IU_PER_MM );
  532. tempOptions.SetFormat( getPlotFormat() );
  533. tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
  534. tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() );
  535. tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
  536. tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
  537. tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
  538. LSET selectedLayers;
  539. for( unsigned i = 0; i < m_layerList.size(); i++ )
  540. {
  541. if( m_layerCheckListBox->IsChecked( i ) )
  542. selectedLayers.set( m_layerList[i] );
  543. }
  544. // Get a list of copper layers that aren't being used by inverting enabled layers.
  545. LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
  546. // Enable all of the disabled copper layers.
  547. // If someone enables more copper layers they will be selected by default.
  548. selectedLayers = selectedLayers | disabledCopperLayers;
  549. tempOptions.SetLayerSelection( selectedLayers );
  550. tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
  551. tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
  552. // Set output directory and replace backslashes with forward ones
  553. wxString dirStr;
  554. dirStr = m_outputDirectoryName->GetValue();
  555. dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
  556. tempOptions.SetOutputDirectory( dirStr );
  557. if( !m_plotOpts.IsSameAs( tempOptions, false ) )
  558. {
  559. // First, mark board as modified only for parameters saved in file
  560. if( !m_plotOpts.IsSameAs( tempOptions, true ) )
  561. m_parent->OnModify();
  562. // Now, save any change, for the session
  563. m_parent->SetPlotSettings( tempOptions );
  564. m_plotOpts = tempOptions;
  565. }
  566. }
  567. void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
  568. {
  569. // m_useGerberNetAttributes is useless if m_useGerberX2Attributes
  570. // is not checked. So disabled (greyed out) when Gerber X2 gets unchecked
  571. // to make it clear to the user.
  572. if( m_useGerberX2Attributes->GetValue() )
  573. {
  574. m_useGerberNetAttributes->Enable( true );
  575. }
  576. else
  577. {
  578. m_useGerberNetAttributes->Enable( false );
  579. m_useGerberNetAttributes->SetValue( false );
  580. }
  581. }
  582. void DIALOG_PLOT::Plot( wxCommandEvent& event )
  583. {
  584. BOARD* board = m_parent->GetBoard();
  585. applyPlotSettings();
  586. // If no layer selected, we have nothing plotted.
  587. // Prompt user if it happens because he could think there is a bug in Pcbnew.
  588. if( !m_plotOpts.GetLayerSelection().any() )
  589. {
  590. DisplayError( this, _( "No layer selected, Nothing to plot" ) );
  591. return;
  592. }
  593. // Create output directory if it does not exist (also transform it in
  594. // absolute form). Bail if it fails
  595. wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
  596. wxString boardFilename = m_parent->GetBoard()->GetFileName();
  597. REPORTER& reporter = m_messagesPanel->Reporter();
  598. if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
  599. {
  600. wxString msg;
  601. msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
  602. GetChars( outputDir.GetPath() ) );
  603. DisplayError( this, msg );
  604. return;
  605. }
  606. if( m_zoneFillCheck->GetValue() )
  607. m_parent->Check_All_Zones( this );
  608. m_plotOpts.SetAutoScale( false );
  609. m_plotOpts.SetScale( 1 );
  610. switch( m_plotOpts.GetScaleSelection() )
  611. {
  612. default:
  613. break;
  614. case 0: // Autoscale option
  615. m_plotOpts.SetAutoScale( true );
  616. break;
  617. case 2: // 3:2 option
  618. m_plotOpts.SetScale( 1.5 );
  619. break;
  620. case 3: // 2:1 option
  621. m_plotOpts.SetScale( 2 );
  622. break;
  623. case 4: // 3:1 option
  624. m_plotOpts.SetScale( 3 );
  625. break;
  626. }
  627. /* If the scale factor edit controls are disabled or the scale value
  628. * is 0, don't adjust the base scale factor. This fixes a bug when
  629. * the default scale adjust is initialized to 0 and saved in program
  630. * settings resulting in a divide by zero fault.
  631. */
  632. if( getPlotFormat() == PLOT_FORMAT_POST )
  633. {
  634. if( m_XScaleAdjust != 0.0 )
  635. m_plotOpts.SetFineScaleAdjustX( m_XScaleAdjust );
  636. if( m_YScaleAdjust != 0.0 )
  637. m_plotOpts.SetFineScaleAdjustY( m_YScaleAdjust );
  638. m_plotOpts.SetWidthAdjust( m_PSWidthAdjust );
  639. }
  640. wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
  641. // Test for a reasonable scale value
  642. // XXX could this actually happen? isn't it constrained in the apply
  643. // function?
  644. if( m_plotOpts.GetScale() < PLOT_MIN_SCALE )
  645. DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
  646. if( m_plotOpts.GetScale() > PLOT_MAX_SCALE )
  647. DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
  648. GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
  649. // Save the current plot options in the board
  650. m_parent->SetPlotSettings( m_plotOpts );
  651. wxBusyCursor dummy;
  652. for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
  653. {
  654. PCB_LAYER_ID layer = *seq;
  655. // All copper layers that are disabled are actually selected
  656. // This is due to wonkyness in automatically selecting copper layers
  657. // for plotting when adding more than two layers to a board.
  658. // If plot options become accessible to the layers setup dialog
  659. // please move this functionality there!
  660. // This skips a copper layer if it is actually disabled on the board.
  661. if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
  662. continue;
  663. // Pick the basename from the board file
  664. wxFileName fn( boardFilename );
  665. // Use Gerber Extensions based on layer number
  666. // (See http://en.wikipedia.org/wiki/Gerber_File)
  667. if( m_plotOpts.GetFormat() == PLOT_FORMAT_GERBER && m_useGerberExtensions->GetValue() )
  668. file_ext = GetGerberProtelExtension( layer );
  669. BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
  670. wxString fullname = fn.GetFullName();
  671. jobfile_writer.AddGbrFile( layer, fullname );
  672. LOCALE_IO toggle;
  673. PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
  674. // Print diags in messages box:
  675. wxString msg;
  676. if( plotter )
  677. {
  678. PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
  679. plotter->EndPlot();
  680. delete plotter;
  681. msg.Printf( _( "Plot file \"%s\" created." ), GetChars( fn.GetFullPath() ) );
  682. reporter.Report( msg, REPORTER::RPT_ACTION );
  683. }
  684. else
  685. {
  686. msg.Printf( _( "Unable to create file \"%s\"." ), GetChars( fn.GetFullPath() ) );
  687. reporter.Report( msg, REPORTER::RPT_ERROR );
  688. }
  689. }
  690. if( m_plotOpts.GetFormat() == PLOT_FORMAT_GERBER && m_plotOpts.GetCreateGerberJobFile() )
  691. {
  692. // Pick the basename from the board file
  693. wxFileName fn( boardFilename );
  694. // Build gerber job file from basename
  695. BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
  696. jobfile_writer.CreateJobFile( fn.GetFullPath() );
  697. }
  698. }
  699. void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
  700. {
  701. PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
  702. if( parent )
  703. {
  704. // First close an existing dialog if open
  705. // (low probability, but can happen)
  706. parent->GetDrcController()->DestroyDRCDialog( wxID_OK );
  707. // Open a new drc dialod, with the right parent frame, and in Modal Mode
  708. parent->GetDrcController()->ShowDRCDialog( this );
  709. }
  710. }