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.

954 lines
34 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
  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 <pcbnew_settings.h>
  28. #include <pcbplot.h>
  29. #include <gerber_jobfile_writer.h>
  30. #include <reporter.h>
  31. #include <wildcards_and_files_ext.h>
  32. #include <layers_id_colors_and_visibility.h>
  33. #include <locale_io.h>
  34. #include <bitmaps.h>
  35. #include <board.h>
  36. #include <dialog_plot.h>
  37. #include <dialog_gendrill.h>
  38. #include <wx_html_report_panel.h>
  39. #include <tool/tool_manager.h>
  40. #include <tools/zone_filler_tool.h>
  41. #include <tools/drc_tool.h>
  42. #include <math/util.h> // for KiROUND
  43. #include <macros.h>
  44. DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) :
  45. DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
  46. m_defaultPenSize( aParent, m_hpglPenLabel, m_hpglPenCtrl, m_hpglPenUnits, true ),
  47. m_trackWidthCorrection( aParent, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits, true )
  48. {
  49. SetName( DLG_WINDOW_NAME );
  50. m_plotOpts = aParent->GetPlotSettings();
  51. m_DRCWarningTemplate = m_DRCExclusionsWarning->GetLabel();
  52. init_Dialog();
  53. // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
  54. // that requires us to correct the button labels here.
  55. m_sdbSizer1OK->SetLabel( _( "Plot" ) );
  56. m_sdbSizer1Apply->SetLabel( _( "Generate Drill Files..." ) );
  57. m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
  58. m_sizerButtons->Layout();
  59. m_sdbSizer1OK->SetDefault();
  60. GetSizer()->Fit( this );
  61. GetSizer()->SetSizeHints( this );
  62. }
  63. void DIALOG_PLOT::init_Dialog()
  64. {
  65. BOARD* board = m_parent->GetBoard();
  66. wxFileName fileName;
  67. auto cfg = m_parent->GetPcbNewSettings();
  68. m_XScaleAdjust = cfg->m_Plot.fine_scale_x;
  69. m_YScaleAdjust = cfg->m_Plot.fine_scale_y;
  70. m_zoneFillCheck->SetValue( cfg->m_Plot.check_zones_before_plotting );
  71. m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
  72. // m_PSWidthAdjust is stored in mm in user config
  73. m_PSWidthAdjust = KiROUND( cfg->m_Plot.ps_fine_width_adjust * IU_PER_MM );
  74. // The reasonable width correction value must be in a range of
  75. // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
  76. m_widthAdjustMinValue = -( board->GetDesignSettings().m_TrackMinWidth - 1 );
  77. m_widthAdjustMaxValue = board->GetDesignSettings().GetSmallestClearanceValue() - 1;
  78. switch( m_plotOpts.GetFormat() )
  79. {
  80. default:
  81. case PLOT_FORMAT::GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
  82. case PLOT_FORMAT::POST: m_plotFormatOpt->SetSelection( 1 ); break;
  83. case PLOT_FORMAT::SVG: m_plotFormatOpt->SetSelection( 2 ); break;
  84. case PLOT_FORMAT::DXF: m_plotFormatOpt->SetSelection( 3 ); break;
  85. case PLOT_FORMAT::HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
  86. case PLOT_FORMAT::PDF: m_plotFormatOpt->SetSelection( 5 ); break;
  87. }
  88. // Set units and value for HPGL pen size (this param is in mils).
  89. m_defaultPenSize.SetValue( m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS );
  90. // Test for a reasonable scale value. Set to 1 if problem
  91. if( m_XScaleAdjust < PLOT_MIN_SCALE || m_YScaleAdjust < PLOT_MIN_SCALE
  92. || m_XScaleAdjust > PLOT_MAX_SCALE || m_YScaleAdjust > PLOT_MAX_SCALE )
  93. m_XScaleAdjust = m_YScaleAdjust = 1.0;
  94. m_fineAdjustXCtrl->SetValue( StringFromValue( EDA_UNITS::UNSCALED, m_XScaleAdjust ) );
  95. m_fineAdjustYCtrl->SetValue( StringFromValue( EDA_UNITS::UNSCALED, m_YScaleAdjust ) );
  96. // Test for a reasonable PS width correction value. Set to 0 if problem.
  97. if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
  98. m_PSWidthAdjust = 0.;
  99. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  100. m_plotPSNegativeOpt->SetValue( m_plotOpts.GetNegative() );
  101. m_forcePSA4OutputOpt->SetValue( m_plotOpts.GetA4Output() );
  102. // Could devote a PlotOrder() function in place of UIOrder().
  103. m_layerList = board->GetEnabledLayers().UIOrder();
  104. // Populate the check list box by all enabled layers names
  105. for( LSEQ seq = m_layerList; seq; ++seq )
  106. {
  107. PCB_LAYER_ID layer = *seq;
  108. int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
  109. if( m_plotOpts.GetLayerSelection()[layer] )
  110. m_layerCheckListBox->Check( checkIndex );
  111. }
  112. // Option for disabling Gerber Aperture Macro (for broken Gerber readers)
  113. m_disableApertMacros->SetValue( m_plotOpts.GetDisableGerberMacros() );
  114. // Option for using proper Gerber extensions. Note also Protel extensions are
  115. // a broken feature. However, for now, we need to handle it.
  116. m_useGerberExtensions->SetValue( m_plotOpts.GetUseGerberProtelExtensions() );
  117. // Option for including Gerber attributes, from Gerber X2 format, in the output
  118. // In X1 format, they will be added as comments
  119. m_useGerberX2Format->SetValue( m_plotOpts.GetUseGerberX2format() );
  120. // Option for including Gerber netlist info (from Gerber X2 format) in the output
  121. m_useGerberNetAttributes->SetValue( m_plotOpts.GetIncludeGerberNetlistInfo() );
  122. // Option to generate a Gerber job file
  123. m_generateGerberJobFile->SetValue( m_plotOpts.GetCreateGerberJobFile() );
  124. // Gerber precision for coordinates
  125. m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
  126. // SVG precision and units for coordinates
  127. m_svgPrecsision->SetValue( m_plotOpts.GetSvgPrecision() );
  128. m_svgUnits->SetSelection( m_plotOpts.GetSvgUseInch() );
  129. // Option for excluding contents of "Edges Pcb" layer
  130. m_excludeEdgeLayerOpt->SetValue( m_plotOpts.GetExcludeEdgeLayer() );
  131. // Option to exclude pads from silkscreen layers
  132. m_sketchPadsOnFabLayers->SetValue( m_plotOpts.GetSketchPadsOnFabLayers() );
  133. // Option to tent vias
  134. m_subtractMaskFromSilk->SetValue( m_plotOpts.GetSubtractMaskFromSilk() );
  135. // Option to use aux origin
  136. m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() );
  137. // Option to plot page references:
  138. m_plotSheetRef->SetValue( m_plotOpts.GetPlotFrameRef() );
  139. // Options to plot texts on footprints
  140. m_plotModuleValueOpt->SetValue( m_plotOpts.GetPlotValue() );
  141. m_plotModuleRefOpt->SetValue( m_plotOpts.GetPlotReference() );
  142. m_plotInvisibleText->SetValue( m_plotOpts.GetPlotInvisibleText() );
  143. // Options to plot pads and vias holes
  144. m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
  145. // Scale option
  146. m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
  147. // Plot mode
  148. setPlotModeChoiceSelection( m_plotOpts.GetPlotMode() );
  149. // DXF outline mode
  150. m_DXF_plotModeOpt->SetValue( m_plotOpts.GetDXFPlotPolygonMode() );
  151. // DXF text mode
  152. m_DXF_plotTextStrokeFontOpt->SetValue( m_plotOpts.GetTextMode() == PLOT_TEXT_MODE::DEFAULT );
  153. // DXF units selection
  154. m_DXF_plotUnits->SetSelection( m_plotOpts.GetDXFPlotUnits() == DXF_UNITS::INCHES ? 0 : 1);
  155. // Plot mirror option
  156. m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
  157. // Put vias on mask layer
  158. m_plotNoViaOnMaskOpt->SetValue( m_plotOpts.GetPlotViaOnMaskLayer() );
  159. // Initialize a few other parameters, which can also be modified
  160. // from the drill dialog
  161. reInitDialog();
  162. // Update options values:
  163. wxCommandEvent cmd_event;
  164. SetPlotFormat( cmd_event );
  165. OnSetScaleOpt( cmd_event );
  166. }
  167. void DIALOG_PLOT::reInitDialog()
  168. {
  169. // after calling the Drill or DRC dialogs some parameters can be modified....
  170. // Output directory
  171. m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
  172. // Origin of coordinates:
  173. m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() );
  174. int knownViolations = 0;
  175. int exclusions = 0;
  176. for( PCB_MARKER* marker : m_parent->GetBoard()->Markers() )
  177. {
  178. if( marker->IsExcluded() )
  179. exclusions++;
  180. else
  181. knownViolations++;
  182. }
  183. if( knownViolations || exclusions )
  184. {
  185. m_DRCExclusionsWarning->SetLabel( wxString::Format( m_DRCWarningTemplate,
  186. knownViolations,
  187. exclusions ) );
  188. m_DRCExclusionsWarning->Show();
  189. }
  190. else
  191. {
  192. m_DRCExclusionsWarning->Hide();
  193. }
  194. BOARD* board = m_parent->GetBoard();
  195. const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
  196. if( getPlotFormat() == PLOT_FORMAT::GERBER &&
  197. ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
  198. {
  199. m_PlotOptionsSizer->Show( m_SizerSolderMaskAlert );
  200. }
  201. else
  202. {
  203. m_PlotOptionsSizer->Hide( m_SizerSolderMaskAlert );
  204. }
  205. }
  206. // A helper function to show a popup menu, when the dialog is right clicked.
  207. void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
  208. {
  209. PopupMenu( m_popMenu );
  210. }
  211. // Select or deselect groups of layers in the layers list:
  212. void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
  213. {
  214. // Build a list of layers for usual fabrication:
  215. // copper layers + tech layers without courtyard
  216. LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() )
  217. & ~LSET( 2, B_CrtYd, F_CrtYd );
  218. switch( event.GetId() )
  219. {
  220. case ID_LAYER_FAB: // Select layers usually needed to build a board
  221. for( unsigned i = 0; i < m_layerList.size(); i++ )
  222. {
  223. LSET layermask( m_layerList[ i ] );
  224. if( ( layermask & fab_layer_set ).any() )
  225. m_layerCheckListBox->Check( i, true );
  226. else
  227. m_layerCheckListBox->Check( i, false );
  228. }
  229. break;
  230. case ID_SELECT_COPPER_LAYERS:
  231. for( unsigned i = 0; i < m_layerList.size(); i++ )
  232. {
  233. if( IsCopperLayer( m_layerList[i] ) )
  234. m_layerCheckListBox->Check( i, true );
  235. }
  236. break;
  237. case ID_DESELECT_COPPER_LAYERS:
  238. for( unsigned i = 0; i < m_layerList.size(); i++ )
  239. {
  240. if( IsCopperLayer( m_layerList[i] ) )
  241. m_layerCheckListBox->Check( i, false );
  242. }
  243. break;
  244. case ID_SELECT_ALL_LAYERS:
  245. for( unsigned i = 0; i < m_layerList.size(); i++ )
  246. m_layerCheckListBox->Check( i, true );
  247. break;
  248. case ID_DESELECT_ALL_LAYERS:
  249. for( unsigned i = 0; i < m_layerList.size(); i++ )
  250. m_layerCheckListBox->Check( i, false );
  251. break;
  252. default:
  253. break;
  254. }
  255. }
  256. void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
  257. {
  258. // Be sure drill file use the same settings (axis option, plot directory)
  259. // as plot files:
  260. applyPlotSettings();
  261. DIALOG_GENDRILL dlg( m_parent, this );
  262. dlg.ShowModal();
  263. // a few plot settings can be modified: take them in account
  264. m_plotOpts = m_parent->GetPlotSettings();
  265. reInitDialog();
  266. }
  267. void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
  268. {
  269. // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
  270. // is checked (plot in DXF polygon mode)
  271. m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
  272. // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
  273. // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
  274. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
  275. m_DXF_plotTextStrokeFontOpt->SetValue( true );
  276. }
  277. void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
  278. {
  279. /* Disable sheet reference for scale != 1:1 */
  280. bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
  281. m_plotSheetRef->Enable( scale1 );
  282. if( !scale1 )
  283. m_plotSheetRef->SetValue( false );
  284. }
  285. void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
  286. {
  287. // Build the absolute path of current output directory to preselect it in the file browser.
  288. wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
  289. path = Prj().AbsolutePath( path );
  290. wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
  291. if( dirDialog.ShowModal() == wxID_CANCEL )
  292. return;
  293. wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
  294. wxFileName fn( Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() ) );
  295. wxString defaultPath = fn.GetPathWithSep();
  296. wxString msg;
  297. wxFileName relPathTest; // Used to test if we can make the path relative
  298. relPathTest.Assign( dirDialog.GetPath() );
  299. // Test if making the path relative is possible before asking the user if they want to do it
  300. if( relPathTest.MakeRelativeTo( defaultPath ) )
  301. {
  302. msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ), defaultPath );
  303. wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
  304. wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
  305. if( dialog.ShowModal() == wxID_YES )
  306. dirName.MakeRelativeTo( defaultPath );
  307. }
  308. m_outputDirectoryName->SetValue( dirName.GetFullPath() );
  309. }
  310. PLOT_FORMAT DIALOG_PLOT::getPlotFormat()
  311. {
  312. // plot format id's are ordered like displayed in m_plotFormatOpt
  313. static const PLOT_FORMAT plotFmt[] = { PLOT_FORMAT::GERBER, PLOT_FORMAT::POST, PLOT_FORMAT::SVG,
  314. PLOT_FORMAT::DXF, PLOT_FORMAT::HPGL, PLOT_FORMAT::PDF };
  315. return plotFmt[m_plotFormatOpt->GetSelection()];
  316. }
  317. // Enable or disable widgets according to the plot format selected
  318. // and clear also some optional values
  319. void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
  320. {
  321. // this option exist only in DXF format:
  322. m_DXF_plotModeOpt->Enable( getPlotFormat() == PLOT_FORMAT::DXF );
  323. // The alert message about non 0 solder mask min width and margin is shown
  324. // only in gerber format and if min mask width or mask margin is not 0
  325. BOARD* board = m_parent->GetBoard();
  326. const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
  327. if( getPlotFormat() == PLOT_FORMAT::GERBER &&
  328. ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
  329. {
  330. m_PlotOptionsSizer->Show( m_SizerSolderMaskAlert );
  331. }
  332. else
  333. {
  334. m_PlotOptionsSizer->Hide( m_SizerSolderMaskAlert );
  335. }
  336. switch( getPlotFormat() )
  337. {
  338. case PLOT_FORMAT::SVG:
  339. case PLOT_FORMAT::PDF:
  340. m_drillShapeOpt->Enable( true );
  341. m_plotModeOpt->Enable( false );
  342. setPlotModeChoiceSelection( FILLED );
  343. m_plotMirrorOpt->Enable( true );
  344. m_useAuxOriginCheckBox->Enable( false );
  345. m_useAuxOriginCheckBox->SetValue( false );
  346. m_defaultPenSize.Enable( false );
  347. m_excludeEdgeLayerOpt->Enable( true );
  348. m_scaleOpt->Enable( false );
  349. m_scaleOpt->SetSelection( 1 );
  350. m_fineAdjustXCtrl->Enable( false );
  351. m_fineAdjustYCtrl->Enable( false );
  352. m_trackWidthCorrection.Enable( false );
  353. m_plotPSNegativeOpt->Enable( true );
  354. m_forcePSA4OutputOpt->Enable( false );
  355. m_forcePSA4OutputOpt->SetValue( false );
  356. if( getPlotFormat() == PLOT_FORMAT::SVG )
  357. m_PlotOptionsSizer->Show( m_svgOptionsSizer );
  358. else
  359. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  360. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  361. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  362. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  363. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  364. break;
  365. case PLOT_FORMAT::POST:
  366. m_drillShapeOpt->Enable( true );
  367. m_plotModeOpt->Enable( true );
  368. m_plotMirrorOpt->Enable( true );
  369. m_useAuxOriginCheckBox->Enable( false );
  370. m_useAuxOriginCheckBox->SetValue( false );
  371. m_defaultPenSize.Enable( false );
  372. m_excludeEdgeLayerOpt->Enable( true );
  373. m_scaleOpt->Enable( true );
  374. m_fineAdjustXCtrl->Enable( true );
  375. m_fineAdjustYCtrl->Enable( true );
  376. m_trackWidthCorrection.Enable( true );
  377. m_plotPSNegativeOpt->Enable( true );
  378. m_forcePSA4OutputOpt->Enable( true );
  379. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  380. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  381. m_PlotOptionsSizer->Show( m_PSOptionsSizer );
  382. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  383. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  384. break;
  385. case PLOT_FORMAT::GERBER:
  386. m_drillShapeOpt->Enable( false );
  387. m_drillShapeOpt->SetSelection( 0 );
  388. m_plotModeOpt->Enable( false );
  389. setPlotModeChoiceSelection( FILLED );
  390. m_plotMirrorOpt->Enable( false );
  391. m_plotMirrorOpt->SetValue( false );
  392. m_useAuxOriginCheckBox->Enable( true );
  393. m_defaultPenSize.Enable( false );
  394. m_excludeEdgeLayerOpt->Enable( true );
  395. m_scaleOpt->Enable( false );
  396. m_scaleOpt->SetSelection( 1 );
  397. m_fineAdjustXCtrl->Enable( false );
  398. m_fineAdjustYCtrl->Enable( false );
  399. m_trackWidthCorrection.Enable( false );
  400. m_plotPSNegativeOpt->Enable( false );
  401. m_plotPSNegativeOpt->SetValue( false );
  402. m_forcePSA4OutputOpt->Enable( false );
  403. m_forcePSA4OutputOpt->SetValue( false );
  404. m_PlotOptionsSizer->Show( m_GerberOptionsSizer );
  405. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  406. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  407. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  408. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  409. break;
  410. case PLOT_FORMAT::HPGL:
  411. m_drillShapeOpt->Enable( true );
  412. m_plotModeOpt->Enable( true );
  413. m_plotMirrorOpt->Enable( true );
  414. m_useAuxOriginCheckBox->Enable( false );
  415. m_useAuxOriginCheckBox->SetValue( false );
  416. m_defaultPenSize.Enable( true );
  417. m_excludeEdgeLayerOpt->Enable( true );
  418. m_scaleOpt->Enable( true );
  419. m_fineAdjustXCtrl->Enable( false );
  420. m_fineAdjustYCtrl->Enable( false );
  421. m_trackWidthCorrection.Enable( false );
  422. m_plotPSNegativeOpt->SetValue( false );
  423. m_plotPSNegativeOpt->Enable( false );
  424. m_forcePSA4OutputOpt->Enable( true );
  425. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  426. m_PlotOptionsSizer->Show( m_HPGLOptionsSizer );
  427. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  428. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  429. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  430. break;
  431. case PLOT_FORMAT::DXF:
  432. m_drillShapeOpt->Enable( true );
  433. m_plotModeOpt->Enable( false );
  434. setPlotModeChoiceSelection( FILLED );
  435. m_plotMirrorOpt->Enable( false );
  436. m_plotMirrorOpt->SetValue( false );
  437. m_useAuxOriginCheckBox->Enable( true );
  438. m_defaultPenSize.Enable( false );
  439. m_excludeEdgeLayerOpt->Enable( true );
  440. m_scaleOpt->Enable( false );
  441. m_scaleOpt->SetSelection( 1 );
  442. m_fineAdjustXCtrl->Enable( false );
  443. m_fineAdjustYCtrl->Enable( false );
  444. m_trackWidthCorrection.Enable( false );
  445. m_plotPSNegativeOpt->Enable( false );
  446. m_plotPSNegativeOpt->SetValue( false );
  447. m_forcePSA4OutputOpt->Enable( false );
  448. m_forcePSA4OutputOpt->SetValue( false );
  449. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  450. m_PlotOptionsSizer->Hide( m_HPGLOptionsSizer );
  451. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  452. m_PlotOptionsSizer->Show( m_SizerDXF_options );
  453. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  454. OnChangeDXFPlotMode( event );
  455. break;
  456. case PLOT_FORMAT::UNDEFINED:
  457. break;
  458. }
  459. /* Update the interlock between scale and frame reference
  460. * (scaling would mess up the frame border...) */
  461. OnSetScaleOpt( event );
  462. Layout();
  463. m_MainSizer->SetSizeHints( this );
  464. }
  465. // A helper function to "clip" aValue between aMin and aMax
  466. // and write result in * aResult
  467. // return false if clipped, true if aValue is just copied into * aResult
  468. static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
  469. {
  470. if( aValue < aMin )
  471. {
  472. *aResult = aMin;
  473. return false;
  474. }
  475. else if( aValue > aMax )
  476. {
  477. *aResult = aMax;
  478. return false;
  479. }
  480. *aResult = aValue;
  481. return true;
  482. }
  483. static bool setInt( int* aResult, int aValue, int aMin, int aMax )
  484. {
  485. if( aValue < aMin )
  486. {
  487. *aResult = aMin;
  488. return false;
  489. }
  490. else if( aValue > aMax )
  491. {
  492. *aResult = aMax;
  493. return false;
  494. }
  495. *aResult = aValue;
  496. return true;
  497. }
  498. void DIALOG_PLOT::applyPlotSettings()
  499. {
  500. REPORTER& reporter = m_messagesPanel->Reporter();
  501. int sel;
  502. PCB_PLOT_PARAMS tempOptions;
  503. tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
  504. tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
  505. tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
  506. tempOptions.SetSketchPadsOnFabLayers( m_sketchPadsOnFabLayers->GetValue() );
  507. tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
  508. tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
  509. tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
  510. tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
  511. tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
  512. sel = m_drillShapeOpt->GetSelection();
  513. tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>( sel ) );
  514. tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
  515. tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
  516. tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
  517. sel = m_DXF_plotUnits->GetSelection();
  518. tempOptions.SetDXFPlotUnits( sel == 0 ? DXF_UNITS::INCHES : DXF_UNITS::MILLIMETERS );
  519. tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
  520. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
  521. tempOptions.SetTextMode( PLOT_TEXT_MODE::DEFAULT );
  522. else
  523. tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ? PLOT_TEXT_MODE::DEFAULT :
  524. PLOT_TEXT_MODE::NATIVE );
  525. // Update settings from text fields. Rewrite values back to the fields,
  526. // since the values may have been constrained by the setters.
  527. wxString msg;
  528. // read HPLG pen size (this param is stored in mils)
  529. // However, due to issues when converting this value from or to mm
  530. // that can slightly change the value, update this param only if it
  531. // is in use
  532. if( getPlotFormat() == PLOT_FORMAT::HPGL )
  533. {
  534. if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
  535. {
  536. m_defaultPenSize.SetValue( tempOptions.GetHPGLPenDiameter() * IU_PER_MILS );
  537. msg.Printf( _( "HPGL pen size constrained." ) );
  538. reporter.Report( msg, RPT_SEVERITY_INFO );
  539. }
  540. }
  541. else // keep the last value (initial value if no HPGL plot made)
  542. tempOptions.SetHPGLPenDiameter( m_plotOpts.GetHPGLPenDiameter() );
  543. // X scale
  544. double tmpDouble;
  545. msg = m_fineAdjustXCtrl->GetValue();
  546. msg.ToDouble( &tmpDouble );
  547. if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  548. {
  549. msg.Printf( wxT( "%f" ), m_XScaleAdjust );
  550. m_fineAdjustXCtrl->SetValue( msg );
  551. msg.Printf( _( "X scale constrained." ) );
  552. reporter.Report( msg, RPT_SEVERITY_INFO );
  553. }
  554. // Y scale
  555. msg = m_fineAdjustYCtrl->GetValue();
  556. msg.ToDouble( &tmpDouble );
  557. if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  558. {
  559. msg.Printf( wxT( "%f" ), m_YScaleAdjust );
  560. m_fineAdjustYCtrl->SetValue( msg );
  561. msg.Printf( _( "Y scale constrained." ) );
  562. reporter.Report( msg, RPT_SEVERITY_INFO );
  563. }
  564. auto cfg = m_parent->GetPcbNewSettings();
  565. cfg->m_Plot.fine_scale_x = m_XScaleAdjust;
  566. cfg->m_Plot.fine_scale_y = m_YScaleAdjust;
  567. cfg->m_Plot.check_zones_before_plotting = m_zoneFillCheck->GetValue();
  568. // PS Width correction
  569. if( !setInt( &m_PSWidthAdjust, m_trackWidthCorrection.GetValue(),
  570. m_widthAdjustMinValue, m_widthAdjustMaxValue ) )
  571. {
  572. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  573. msg.Printf( _( "Width correction constrained. "
  574. "The reasonable width correction value must be in a range of "
  575. " [%s; %s] (%s) for current design rules." ),
  576. StringFromValue( GetUserUnits(), m_widthAdjustMinValue, false ),
  577. StringFromValue( GetUserUnits(), m_widthAdjustMaxValue, false ),
  578. GetAbbreviatedUnitsLabel( GetUserUnits() ) );
  579. reporter.Report( msg, RPT_SEVERITY_WARNING );
  580. }
  581. // Store m_PSWidthAdjust in mm in user config
  582. cfg->m_Plot.ps_fine_width_adjust = Iu2Millimeter( m_PSWidthAdjust );
  583. tempOptions.SetFormat( getPlotFormat() );
  584. tempOptions.SetDisableGerberMacros( m_disableApertMacros->GetValue() );
  585. tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
  586. tempOptions.SetUseGerberX2format( m_useGerberX2Format->GetValue() );
  587. tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
  588. tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
  589. tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
  590. tempOptions.SetSvgPrecision( m_svgPrecsision->GetValue(), m_svgUnits->GetSelection() );
  591. LSET selectedLayers;
  592. for( unsigned i = 0; i < m_layerList.size(); i++ )
  593. {
  594. if( m_layerCheckListBox->IsChecked( i ) )
  595. selectedLayers.set( m_layerList[i] );
  596. }
  597. // Get a list of copper layers that aren't being used by inverting enabled layers.
  598. LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
  599. // Enable all of the disabled copper layers.
  600. // If someone enables more copper layers they will be selected by default.
  601. selectedLayers = selectedLayers | disabledCopperLayers;
  602. tempOptions.SetLayerSelection( selectedLayers );
  603. tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
  604. tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
  605. // Set output directory and replace backslashes with forward ones
  606. wxString dirStr;
  607. dirStr = m_outputDirectoryName->GetValue();
  608. dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
  609. tempOptions.SetOutputDirectory( dirStr );
  610. if( !m_plotOpts.IsSameAs( tempOptions, false ) )
  611. {
  612. // First, mark board as modified only for parameters saved in file
  613. if( !m_plotOpts.IsSameAs( tempOptions, true ) )
  614. m_parent->OnModify();
  615. // Now, save any change, for the session
  616. m_parent->SetPlotSettings( tempOptions );
  617. m_plotOpts = tempOptions;
  618. }
  619. }
  620. void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
  621. {
  622. // Currently: do nothing
  623. }
  624. void DIALOG_PLOT::Plot( wxCommandEvent& event )
  625. {
  626. BOARD* board = m_parent->GetBoard();
  627. applyPlotSettings();
  628. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  629. PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>();
  630. m_plotOpts.SetColorSettings( mgr.GetColorSettings( cfg->m_ColorTheme ) );
  631. m_plotOpts.SetSketchPadLineWidth( board->GetDesignSettings().GetLineThickness( F_Fab ) );
  632. // If no layer selected, we have nothing plotted.
  633. // Prompt user if it happens because he could think there is a bug in Pcbnew.
  634. if( !m_plotOpts.GetLayerSelection().any() )
  635. {
  636. DisplayError( this, _( "No layer selected, Nothing to plot" ) );
  637. return;
  638. }
  639. // Create output directory if it does not exist (also transform it in
  640. // absolute form). Bail if it fails
  641. wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
  642. wxFileName outputDir = wxFileName::DirName( path );
  643. wxString boardFilename = m_parent->GetBoard()->GetFileName();
  644. REPORTER& reporter = m_messagesPanel->Reporter();
  645. if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
  646. {
  647. wxString msg;
  648. msg.Printf( _( "Could not write plot files to folder \"%s\"." ), outputDir.GetPath() );
  649. DisplayError( this, msg );
  650. return;
  651. }
  652. if( m_zoneFillCheck->GetValue() )
  653. m_parent->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
  654. m_plotOpts.SetAutoScale( false );
  655. switch( m_plotOpts.GetScaleSelection() )
  656. {
  657. default: m_plotOpts.SetScale( 1 ); break;
  658. case 0: m_plotOpts.SetAutoScale( true ); break;
  659. case 2: m_plotOpts.SetScale( 1.5 ); break;
  660. case 3: m_plotOpts.SetScale( 2 ); break;
  661. case 4: m_plotOpts.SetScale( 3 ); break;
  662. }
  663. /* If the scale factor edit controls are disabled or the scale value
  664. * is 0, don't adjust the base scale factor. This fixes a bug when
  665. * the default scale adjust is initialized to 0 and saved in program
  666. * settings resulting in a divide by zero fault.
  667. */
  668. if( getPlotFormat() == PLOT_FORMAT::POST )
  669. {
  670. if( m_XScaleAdjust != 0.0 )
  671. m_plotOpts.SetFineScaleAdjustX( m_XScaleAdjust );
  672. if( m_YScaleAdjust != 0.0 )
  673. m_plotOpts.SetFineScaleAdjustY( m_YScaleAdjust );
  674. m_plotOpts.SetWidthAdjust( m_PSWidthAdjust );
  675. }
  676. wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
  677. // Test for a reasonable scale value
  678. // XXX could this actually happen? isn't it constrained in the apply
  679. // function?
  680. if( m_plotOpts.GetScale() < PLOT_MIN_SCALE )
  681. DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
  682. if( m_plotOpts.GetScale() > PLOT_MAX_SCALE )
  683. DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
  684. GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
  685. // Save the current plot options in the board
  686. m_parent->SetPlotSettings( m_plotOpts );
  687. wxBusyCursor dummy;
  688. for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
  689. {
  690. PCB_LAYER_ID layer = *seq;
  691. // All copper layers that are disabled are actually selected
  692. // This is due to wonkyness in automatically selecting copper layers
  693. // for plotting when adding more than two layers to a board.
  694. // If plot options become accessible to the layers setup dialog
  695. // please move this functionality there!
  696. // This skips a copper layer if it is actually disabled on the board.
  697. if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
  698. continue;
  699. // Pick the basename from the board file
  700. wxFileName fn( boardFilename );
  701. // Use Gerber Extensions based on layer number
  702. // (See http://en.wikipedia.org/wiki/Gerber_File)
  703. if( m_plotOpts.GetFormat() == PLOT_FORMAT::GERBER && m_useGerberExtensions->GetValue() )
  704. file_ext = GetGerberProtelExtension( layer );
  705. BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
  706. wxString fullname = fn.GetFullName();
  707. jobfile_writer.AddGbrFile( layer, fullname );
  708. LOCALE_IO toggle;
  709. PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
  710. // Print diags in messages box:
  711. wxString msg;
  712. if( plotter )
  713. {
  714. PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
  715. plotter->EndPlot();
  716. delete plotter->RenderSettings();
  717. delete plotter;
  718. msg.Printf( _( "Plot file \"%s\" created." ), fn.GetFullPath() );
  719. reporter.Report( msg, RPT_SEVERITY_ACTION );
  720. }
  721. else
  722. {
  723. msg.Printf( _( "Unable to create file \"%s\"." ), fn.GetFullPath() );
  724. reporter.Report( msg, RPT_SEVERITY_ERROR );
  725. }
  726. wxSafeYield(); // displays report message.
  727. }
  728. if( m_plotOpts.GetFormat() == PLOT_FORMAT::GERBER && m_plotOpts.GetCreateGerberJobFile() )
  729. {
  730. // Pick the basename from the board file
  731. wxFileName fn( boardFilename );
  732. // Build gerber job file from basename
  733. BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
  734. jobfile_writer.CreateJobFile( fn.GetFullPath() );
  735. }
  736. }
  737. void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
  738. {
  739. PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
  740. if( parent )
  741. {
  742. DRC_TOOL* drcTool = parent->GetToolManager()->GetTool<DRC_TOOL>();
  743. // First close an existing dialog if open
  744. // (low probability, but can happen)
  745. drcTool->DestroyDRCDialog();
  746. // Open a new drc dialod, with the right parent frame, and in Modal Mode
  747. drcTool->ShowDRCDialog( this );
  748. // Update DRC warnings on return to this dialog
  749. reInitDialog();
  750. }
  751. }
  752. void DIALOG_PLOT::onBoardSetup( wxHyperlinkEvent& aEvent )
  753. {
  754. PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
  755. if( parent )
  756. {
  757. parent->ShowBoardSetupDialog( _( "Solder Mask/Paste" ) );
  758. // Update warnings on return to this dialog
  759. reInitDialog();
  760. }
  761. }