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.

1408 lines
50 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
10 months ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
11 months ago
3 years ago
3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 <wx/bmpbuttn.h>
  24. #include <wx/clntdata.h>
  25. #include <wx/rearrangectrl.h>
  26. #include <plotters/plotter.h>
  27. #include <confirm.h>
  28. #include <pcb_edit_frame.h>
  29. #include <project/project_file.h>
  30. #include <pcbplot.h>
  31. #include <pgm_base.h>
  32. #include <gerber_jobfile_writer.h>
  33. #include <reporter.h>
  34. #include <wildcards_and_files_ext.h>
  35. #include <layer_ids.h>
  36. #include <locale_io.h>
  37. #include <bitmaps.h>
  38. #include <dialog_plot.h>
  39. #include <dialog_gendrill.h>
  40. #include <widgets/wx_html_report_panel.h>
  41. #include <widgets/std_bitmap_button.h>
  42. #include <tool/tool_manager.h>
  43. #include <tools/zone_filler_tool.h>
  44. #include <tools/drc_tool.h>
  45. #include <math/util.h> // for KiROUND
  46. #include <macros.h>
  47. #include <jobs/job_export_pcb_gerbers.h>
  48. #include <jobs/job_export_pcb_hpgl.h>
  49. #include <jobs/job_export_pcb_dxf.h>
  50. #include <jobs/job_export_pcb_pdf.h>
  51. #include <jobs/job_export_pcb_ps.h>
  52. #include <jobs/job_export_pcb_svg.h>
  53. #include <plotters/plotters_pslike.h>
  54. #include <pcb_plotter.h>
  55. #include <wx/dirdlg.h>
  56. #include <wx/msgdlg.h>
  57. LSET DIALOG_PLOT::s_lastLayerSet;
  58. LSET DIALOG_PLOT::s_lastAllLayersSet;
  59. LSEQ DIALOG_PLOT::s_lastAllLayersOrder;
  60. static double selectionToScale( int selection )
  61. {
  62. switch( selection )
  63. {
  64. default: return 1;
  65. case 0: return 0;
  66. case 2: return 1.5;
  67. case 3: return 2;
  68. case 4: return 3;
  69. }
  70. return 1;
  71. }
  72. /**
  73. * A helper wxWidgets control client data object to store layer IDs.
  74. */
  75. class PCB_LAYER_ID_CLIENT_DATA : public wxClientData
  76. {
  77. public:
  78. PCB_LAYER_ID_CLIENT_DATA() :
  79. m_id( UNDEFINED_LAYER )
  80. { }
  81. PCB_LAYER_ID_CLIENT_DATA( PCB_LAYER_ID aId ) :
  82. m_id( aId )
  83. { }
  84. void SetData( PCB_LAYER_ID aId ) { m_id = aId; }
  85. PCB_LAYER_ID Layer() const { return m_id; }
  86. private:
  87. PCB_LAYER_ID m_id;
  88. };
  89. PCB_LAYER_ID_CLIENT_DATA* getLayerClientData( const wxRearrangeList* aList, int aIdx )
  90. {
  91. return static_cast<PCB_LAYER_ID_CLIENT_DATA*>( aList->GetClientObject( aIdx ) );
  92. }
  93. DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aEditFrame )
  94. : DIALOG_PLOT( aEditFrame, aEditFrame )
  95. {
  96. }
  97. DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aEditFrame, wxWindow* aParent,
  98. JOB_EXPORT_PCB_PLOT* aJob ) :
  99. DIALOG_PLOT_BASE( aParent ),
  100. m_editFrame( aEditFrame ),
  101. m_trackWidthCorrection( m_editFrame, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits ),
  102. m_job( aJob )
  103. {
  104. BOARD* board = m_editFrame->GetBoard();
  105. SetName( DLG_WINDOW_NAME );
  106. m_DRCWarningTemplate = m_DRCExclusionsWarning->GetLabel();
  107. if( m_job )
  108. {
  109. SetTitle( aJob->GetSettingsDialogTitle() );
  110. PCB_PLOTTER::PlotJobToPlotOpts( m_plotOpts, m_job, m_messagesPanel->Reporter() );
  111. m_messagesPanel->Hide();
  112. m_browseButton->Hide();
  113. m_openDirButton->Hide();
  114. m_staticTextPlotFmt->Hide();
  115. m_plotFormatOpt->Hide();
  116. m_buttonDRC->Hide();
  117. m_DRCExclusionsWarning->Hide();
  118. m_sdbSizer1Apply->Hide();
  119. }
  120. else
  121. {
  122. m_plotOpts = m_editFrame->GetPlotSettings();
  123. m_messagesPanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
  124. }
  125. // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
  126. // non-job versions (which have different sizes).
  127. m_hash_key = TO_UTF8( GetTitle() );
  128. int order = 0;
  129. wxArrayInt plotAllLayersOrder;
  130. wxArrayString plotAllLayersChoicesStrings;
  131. std::vector<PCB_LAYER_ID> layersIdChoiceList;
  132. int textWidth = 0;
  133. for( PCB_LAYER_ID layer : board->GetEnabledLayers().SeqStackupForPlotting() )
  134. {
  135. wxString layerName = board->GetLayerName( layer );
  136. // wxCOL_WIDTH_AUTOSIZE doesn't work on all platforms, so we calculate width here
  137. textWidth = std::max( textWidth, KIUI::GetTextSize( layerName, m_layerCheckListBox ).x );
  138. plotAllLayersChoicesStrings.Add( layerName );
  139. layersIdChoiceList.push_back( layer );
  140. if( alg::contains( m_plotOpts.GetPlotOnAllLayersSequence(), layer ) )
  141. plotAllLayersOrder.push_back( order );
  142. else
  143. plotAllLayersOrder.push_back( ~order );
  144. order += 1;
  145. }
  146. int checkColSize = 22;
  147. int layerColSize = textWidth + 15;
  148. #ifdef __WXMAC__
  149. // TODO: something in wxWidgets 3.1.x pads checkbox columns with extra space. (It used to
  150. // also be that the width of the column would get set too wide (to 30), but that's patched in
  151. // our local wxWidgets fork.)
  152. checkColSize += 30;
  153. #endif
  154. m_layerCheckListBox->SetMinClientSize( wxSize( checkColSize + layerColSize,
  155. m_layerCheckListBox->GetMinClientSize().y ) );
  156. wxStaticBox* allLayersLabel = new wxStaticBox( this, wxID_ANY, _( "Plot on All Layers" ) );
  157. wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( allLayersLabel, wxVERTICAL );
  158. m_plotAllLayersList = new wxRearrangeList( sbSizer->GetStaticBox(), wxID_ANY,
  159. wxDefaultPosition, wxDefaultSize,
  160. plotAllLayersOrder, plotAllLayersChoicesStrings, 0 );
  161. m_plotAllLayersList->SetMinClientSize( wxSize( checkColSize + layerColSize,
  162. m_plotAllLayersList->GetMinClientSize().y ) );
  163. // Attach the LAYER_ID to each item in m_plotAllLayersList
  164. // plotAllLayersChoicesStrings and layersIdChoiceList are in the same order,
  165. // but m_plotAllLayersList has these strings in a different order
  166. for( size_t idx = 0; idx < layersIdChoiceList.size(); idx++ )
  167. {
  168. wxString& txt = plotAllLayersChoicesStrings[idx];
  169. int list_idx = m_plotAllLayersList->FindString( txt, true );
  170. PCB_LAYER_ID layer_id = layersIdChoiceList[idx];
  171. m_plotAllLayersList->SetClientObject( list_idx, new PCB_LAYER_ID_CLIENT_DATA( layer_id ) );
  172. }
  173. sbSizer->Add( m_plotAllLayersList, 1, wxALL | wxEXPAND | wxFIXED_MINSIZE, 3 );
  174. wxBoxSizer* bButtonSizer;
  175. bButtonSizer = new wxBoxSizer( wxHORIZONTAL );
  176. m_bpMoveUp = new STD_BITMAP_BUTTON( sbSizer->GetStaticBox(), wxID_ANY, wxNullBitmap,
  177. wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW | 0 );
  178. m_bpMoveUp->SetToolTip( _( "Move current selection up" ) );
  179. m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
  180. bButtonSizer->Add( m_bpMoveUp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 3 );
  181. m_bpMoveDown = new STD_BITMAP_BUTTON( sbSizer->GetStaticBox(), wxID_ANY, wxNullBitmap,
  182. wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW | 0 );
  183. m_bpMoveDown->SetToolTip( _( "Move current selection down" ) );
  184. m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
  185. bButtonSizer->Add( m_bpMoveDown, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
  186. sbSizer->Add( bButtonSizer, 0, wxALL | wxEXPAND, 3 );
  187. bmiddleSizer->Insert( 1, sbSizer, 1, wxALL | wxEXPAND, 5 );
  188. init_Dialog();
  189. if( m_job )
  190. {
  191. SetupStandardButtons();
  192. }
  193. else
  194. {
  195. SetupStandardButtons( { { wxID_OK, _( "Plot" ) },
  196. { wxID_APPLY, _( "Generate Drill Files..." ) },
  197. { wxID_CANCEL, _( "Close" ) } } );
  198. }
  199. GetSizer()->Fit( this );
  200. GetSizer()->SetSizeHints( this );
  201. m_bpMoveUp->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_PLOT::onPlotAllListMoveUp, this );
  202. m_bpMoveDown->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_PLOT::onPlotAllListMoveDown, this );
  203. m_layerCheckListBox->Connect( wxEVT_RIGHT_DOWN,
  204. wxMouseEventHandler( DIALOG_PLOT::OnRightClickLayers ), nullptr,
  205. this );
  206. m_plotAllLayersList->Connect( wxEVT_RIGHT_DOWN,
  207. wxMouseEventHandler( DIALOG_PLOT::OnRightClickAllLayers ), nullptr,
  208. this );
  209. }
  210. DIALOG_PLOT::~DIALOG_PLOT()
  211. {
  212. s_lastAllLayersOrder.clear();
  213. for( int ii = 0; ii < (int) m_plotAllLayersList->GetCount(); ++ii )
  214. s_lastAllLayersOrder.push_back( getLayerClientData( m_plotAllLayersList, ii )->Layer() );
  215. m_bpMoveDown->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_PLOT::onPlotAllListMoveDown, this );
  216. m_bpMoveUp->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_PLOT::onPlotAllListMoveUp, this );
  217. }
  218. void DIALOG_PLOT::init_Dialog()
  219. {
  220. BOARD* board = m_editFrame->GetBoard();
  221. wxFileName fileName;
  222. PROJECT_FILE& projectFile = m_editFrame->Prj().GetProjectFile();
  223. // Could devote a PlotOrder() function in place of UIOrder().
  224. m_layerList = board->GetEnabledLayers().UIOrder();
  225. PCBNEW_SETTINGS* cfg = m_editFrame->GetPcbNewSettings();
  226. if( !m_job && !projectFile.m_PcbLastPath[ LAST_PATH_PLOT ].IsEmpty() )
  227. m_plotOpts.SetOutputDirectory( projectFile.m_PcbLastPath[ LAST_PATH_PLOT ] );
  228. if( m_job
  229. && !( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::POST
  230. && dynamic_cast<JOB_EXPORT_PCB_PS*>( m_job )->m_useGlobalSettings ) )
  231. {
  232. // When we are using a job we get the PS adjust values from the plot options
  233. // The exception is when this is a fresh job and we want to get the global values as defaults
  234. m_XScaleAdjust = m_plotOpts.GetFineScaleAdjustX();
  235. m_YScaleAdjust = m_plotOpts.GetFineScaleAdjustY();
  236. m_PSWidthAdjust = m_plotOpts.GetWidthAdjust();
  237. }
  238. else
  239. {
  240. // The default is to use the global adjusts from the pcbnew settings
  241. m_XScaleAdjust = cfg->m_Plot.fine_scale_x;
  242. m_YScaleAdjust = cfg->m_Plot.fine_scale_y;
  243. // m_PSWidthAdjust is stored in mm in user config
  244. m_PSWidthAdjust = KiROUND( cfg->m_Plot.ps_fine_width_adjust * pcbIUScale.IU_PER_MM );
  245. }
  246. m_zoneFillCheck->SetValue( cfg->m_Plot.check_zones_before_plotting );
  247. m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
  248. m_openDirButton->SetBitmap( KiBitmapBundle( BITMAPS::small_new_window ) );
  249. // The reasonable width correction value must be in a range of
  250. // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
  251. m_widthAdjustMinValue = -( board->GetDesignSettings().m_TrackMinWidth - 1 );
  252. m_widthAdjustMaxValue = board->GetDesignSettings().GetSmallestClearanceValue() - 1;
  253. switch( m_plotOpts.GetFormat() )
  254. {
  255. default:
  256. case PLOT_FORMAT::GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
  257. case PLOT_FORMAT::POST: m_plotFormatOpt->SetSelection( 1 ); break;
  258. case PLOT_FORMAT::SVG: m_plotFormatOpt->SetSelection( 2 ); break;
  259. case PLOT_FORMAT::DXF: m_plotFormatOpt->SetSelection( 3 ); break;
  260. case PLOT_FORMAT::HPGL: /* no longer supported */ break;
  261. case PLOT_FORMAT::PDF: m_plotFormatOpt->SetSelection( 4 ); break;
  262. }
  263. // Test for a reasonable scale value. Set to 1 if problem
  264. if( m_XScaleAdjust < PLOT_MIN_SCALE || m_YScaleAdjust < PLOT_MIN_SCALE
  265. || m_XScaleAdjust > PLOT_MAX_SCALE || m_YScaleAdjust > PLOT_MAX_SCALE )
  266. {
  267. m_XScaleAdjust = m_YScaleAdjust = 1.0;
  268. }
  269. m_fineAdjustXCtrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue(
  270. unityScale, EDA_UNITS::UNSCALED, m_XScaleAdjust ) );
  271. m_fineAdjustYCtrl->SetValue( EDA_UNIT_UTILS::UI::StringFromValue(
  272. unityScale, EDA_UNITS::UNSCALED, m_YScaleAdjust ) );
  273. // Test for a reasonable PS width correction value. Set to 0 if problem.
  274. if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
  275. m_PSWidthAdjust = 0.;
  276. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  277. m_plotPSNegativeOpt->SetValue( m_plotOpts.GetNegative() );
  278. m_forcePSA4OutputOpt->SetValue( m_plotOpts.GetA4Output() );
  279. // Populate the check list box by all enabled layers names.
  280. for( PCB_LAYER_ID layer : m_layerList )
  281. {
  282. int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
  283. if( m_plotOpts.GetLayerSelection()[layer] )
  284. m_layerCheckListBox->Check( checkIndex );
  285. }
  286. arrangeAllLayersList( s_lastAllLayersOrder );
  287. // Option for disabling Gerber Aperture Macro (for broken Gerber readers)
  288. m_disableApertMacros->SetValue( m_plotOpts.GetDisableGerberMacros() );
  289. // Option for using proper Gerber extensions. Note also Protel extensions are
  290. // a broken feature. However, for now, we need to handle it.
  291. m_useGerberExtensions->SetValue( m_plotOpts.GetUseGerberProtelExtensions() );
  292. // Option for including Gerber attributes, from Gerber X2 format, in the output
  293. // In X1 format, they will be added as comments
  294. m_useGerberX2Format->SetValue( m_plotOpts.GetUseGerberX2format() );
  295. // Option for including Gerber netlist info (from Gerber X2 format) in the output
  296. m_useGerberNetAttributes->SetValue( m_plotOpts.GetIncludeGerberNetlistInfo() );
  297. // Option to generate a Gerber job file
  298. m_generateGerberJobFile->SetValue( m_plotOpts.GetCreateGerberJobFile() );
  299. // Gerber precision for coordinates
  300. m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
  301. // SVG precision and units for coordinates
  302. m_svgPrecsision->SetValue( m_plotOpts.GetSvgPrecision() );
  303. m_SVG_fitPageToBoard->SetValue( m_plotOpts.GetSvgFitPagetoBoard() );
  304. m_sketchPadsOnFabLayers->SetValue( m_plotOpts.GetSketchPadsOnFabLayers() );
  305. m_plotPadNumbers->SetValue( m_plotOpts.GetPlotPadNumbers() );
  306. m_plotPadNumbers->Enable( m_plotOpts.GetSketchPadsOnFabLayers() );
  307. m_plotDNP->SetValue( m_plotOpts.GetHideDNPFPsOnFabLayers()
  308. || m_plotOpts.GetSketchDNPFPsOnFabLayers()
  309. || m_plotOpts.GetCrossoutDNPFPsOnFabLayers() );
  310. if( m_plotDNP->GetValue() )
  311. {
  312. if( m_plotOpts.GetHideDNPFPsOnFabLayers() )
  313. m_hideDNP->SetValue( true );
  314. else
  315. m_crossoutDNP->SetValue( true );
  316. }
  317. m_hideDNP->Enable( m_plotDNP->GetValue() );
  318. m_crossoutDNP->Enable( m_plotDNP->GetValue() );
  319. m_subtractMaskFromSilk->SetValue( m_plotOpts.GetSubtractMaskFromSilk() );
  320. m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() );
  321. m_plotSheetRef->SetValue( m_plotOpts.GetPlotFrameRef() );
  322. // Options to plot pads and vias holes
  323. m_drillShapeOpt->SetSelection( (int) m_plotOpts.GetDrillMarksType() );
  324. // Scale option
  325. m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
  326. // DXF outline mode
  327. m_DXF_plotModeOpt->SetValue( m_plotOpts.GetDXFPlotPolygonMode() );
  328. // DXF text mode
  329. m_DXF_plotTextStrokeFontOpt->SetValue( m_plotOpts.GetTextMode()
  330. == PLOT_TEXT_MODE::DEFAULT );
  331. // DXF units selection
  332. m_DXF_plotUnits->SetSelection( m_plotOpts.GetDXFPlotUnits() == DXF_UNITS::INCH ? 0 : 1 );
  333. // Plot mirror option
  334. m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
  335. // Black and white plotting
  336. m_SVGColorChoice->SetSelection( m_plotOpts.GetBlackAndWhite() ? 1 : 0 );
  337. m_PDFColorChoice->SetSelection( m_plotOpts.GetBlackAndWhite() ? 1 : 0 );
  338. m_frontFPPropertyPopups->SetValue( m_plotOpts.m_PDFFrontFPPropertyPopups );
  339. m_backFPPropertyPopups->SetValue( m_plotOpts.m_PDFBackFPPropertyPopups );
  340. m_pdfMetadata->SetValue( m_plotOpts.m_PDFMetadata );
  341. m_pdfSingle->SetValue( m_plotOpts.m_PDFSingle );
  342. // Initialize a few other parameters, which can also be modified
  343. // from the drill dialog
  344. reInitDialog();
  345. // Update options values:
  346. wxCommandEvent cmd_event;
  347. SetPlotFormat( cmd_event );
  348. }
  349. void DIALOG_PLOT::transferPlotParamsToJob()
  350. {
  351. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::GERBER )
  352. {
  353. JOB_EXPORT_PCB_GERBERS* gJob = static_cast<JOB_EXPORT_PCB_GERBERS*>( m_job );
  354. gJob->m_disableApertureMacros = m_plotOpts.GetDisableGerberMacros();
  355. gJob->m_useProtelFileExtension = m_plotOpts.GetUseGerberProtelExtensions();
  356. gJob->m_useX2Format = m_plotOpts.GetUseGerberX2format();
  357. gJob->m_includeNetlistAttributes = m_plotOpts.GetIncludeGerberNetlistInfo();
  358. gJob->m_createJobsFile = m_plotOpts.GetCreateGerberJobFile();
  359. gJob->m_precision = m_plotOpts.GetGerberPrecision();
  360. gJob->m_useBoardPlotParams = false;
  361. }
  362. else
  363. {
  364. m_job->m_scale = selectionToScale( m_plotOpts.GetScaleSelection() );
  365. }
  366. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::SVG )
  367. {
  368. JOB_EXPORT_PCB_SVG* svgJob = static_cast<JOB_EXPORT_PCB_SVG*>( m_job );
  369. svgJob->m_precision = m_plotOpts.GetSvgPrecision();
  370. svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::MULTI;
  371. svgJob->m_fitPageToBoard = m_plotOpts.GetSvgFitPagetoBoard();
  372. }
  373. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::DXF )
  374. {
  375. JOB_EXPORT_PCB_DXF* dxfJob = static_cast<JOB_EXPORT_PCB_DXF*>( m_job );
  376. dxfJob->m_dxfUnits = m_plotOpts.GetDXFPlotUnits() == DXF_UNITS::INCH
  377. ? JOB_EXPORT_PCB_DXF::DXF_UNITS::INCH
  378. : JOB_EXPORT_PCB_DXF::DXF_UNITS::MM;
  379. dxfJob->m_plotGraphicItemsUsingContours = m_plotOpts.GetPlotMode() == OUTLINE_MODE::SKETCH;
  380. dxfJob->m_polygonMode = m_plotOpts.GetDXFPlotPolygonMode();
  381. dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::MULTI;
  382. }
  383. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::POST )
  384. {
  385. JOB_EXPORT_PCB_PS* psJob = static_cast<JOB_EXPORT_PCB_PS*>( m_job );
  386. psJob->m_genMode = JOB_EXPORT_PCB_PS::GEN_MODE::MULTI;
  387. psJob->m_XScaleAdjust = m_plotOpts.GetFineScaleAdjustX();
  388. psJob->m_YScaleAdjust = m_plotOpts.GetFineScaleAdjustY();
  389. psJob->m_trackWidthCorrection = pcbIUScale.IUTomm( m_plotOpts.GetWidthAdjust() );
  390. psJob->m_forceA4 = m_plotOpts.GetA4Output();
  391. // For a fresh job we got the adjusts from the global pcbnew settings
  392. // After the user confirmed and/or changed them we stop using the global adjusts
  393. psJob->m_useGlobalSettings = false;
  394. }
  395. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::PDF )
  396. {
  397. JOB_EXPORT_PCB_PDF* pdfJob = static_cast<JOB_EXPORT_PCB_PDF*>( m_job );
  398. pdfJob->m_pdfFrontFPPropertyPopups = m_plotOpts.m_PDFFrontFPPropertyPopups;
  399. pdfJob->m_pdfBackFPPropertyPopups = m_plotOpts.m_PDFBackFPPropertyPopups;
  400. pdfJob->m_pdfMetadata = m_plotOpts.m_PDFMetadata;
  401. pdfJob->m_pdfSingle = m_plotOpts.m_PDFSingle;
  402. // we need to embed this for the cli deprecation fix
  403. if( pdfJob->m_pdfSingle )
  404. {
  405. pdfJob->m_pdfGenMode = JOB_EXPORT_PCB_PDF::GEN_MODE::ONE_PAGE_PER_LAYER_ONE_FILE;
  406. }
  407. else
  408. {
  409. pdfJob->m_pdfGenMode = JOB_EXPORT_PCB_PDF::GEN_MODE::ALL_LAYERS_SEPARATE_FILE;
  410. }
  411. }
  412. m_job->m_subtractSolderMaskFromSilk = m_plotOpts.GetSubtractMaskFromSilk();
  413. m_job->m_useDrillOrigin = m_plotOpts.GetUseAuxOrigin();
  414. m_job->m_crossoutDNPFPsOnFabLayers = m_plotOpts.GetCrossoutDNPFPsOnFabLayers();
  415. m_job->m_hideDNPFPsOnFabLayers = m_plotOpts.GetHideDNPFPsOnFabLayers();
  416. m_job->m_sketchDNPFPsOnFabLayers = m_plotOpts.GetSketchDNPFPsOnFabLayers();
  417. m_job->m_sketchPadsOnFabLayers = m_plotOpts.GetSketchPadsOnFabLayers();
  418. m_job->m_plotDrawingSheet = m_plotOpts.GetPlotFrameRef();
  419. m_job->m_plotPadNumbers = m_plotOpts.GetPlotPadNumbers();
  420. m_job->m_blackAndWhite = m_plotOpts.GetBlackAndWhite();
  421. m_job->m_mirror = m_plotOpts.GetMirror();
  422. m_job->m_negative = m_plotOpts.GetNegative();
  423. m_job->m_plotLayerSequence = m_plotOpts.GetLayerSelection().SeqStackupForPlotting();
  424. m_job->m_plotOnAllLayersSequence = m_plotOpts.GetPlotOnAllLayersSequence();
  425. if( m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::SVG ||
  426. m_job->m_plotFormat == JOB_EXPORT_PCB_PLOT::PLOT_FORMAT::PDF )
  427. {
  428. switch( m_plotOpts.GetDrillMarksType() )
  429. {
  430. case DRILL_MARKS::NO_DRILL_SHAPE: m_job->m_drillShapeOption = DRILL_MARKS::NO_DRILL_SHAPE; break;
  431. case DRILL_MARKS::SMALL_DRILL_SHAPE: m_job->m_drillShapeOption = DRILL_MARKS::SMALL_DRILL_SHAPE; break;
  432. default:
  433. case DRILL_MARKS::FULL_DRILL_SHAPE: m_job->m_drillShapeOption = DRILL_MARKS::FULL_DRILL_SHAPE; break;
  434. }
  435. }
  436. m_job->SetConfiguredOutputPath( m_plotOpts.GetOutputDirectory() );
  437. }
  438. void DIALOG_PLOT::reInitDialog()
  439. {
  440. // after calling the Drill or DRC dialogs some parameters can be modified....
  441. // Output directory
  442. m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
  443. // Origin of coordinates:
  444. m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() );
  445. int knownViolations = 0;
  446. int exclusions = 0;
  447. for( PCB_MARKER* marker : m_editFrame->GetBoard()->Markers() )
  448. {
  449. if( marker->GetSeverity() == RPT_SEVERITY_EXCLUSION )
  450. exclusions++;
  451. else
  452. knownViolations++;
  453. }
  454. if( !m_job && ( knownViolations || exclusions ) )
  455. {
  456. m_DRCExclusionsWarning->SetLabel( wxString::Format( m_DRCWarningTemplate, knownViolations,
  457. exclusions ) );
  458. m_DRCExclusionsWarning->Show();
  459. }
  460. else
  461. {
  462. m_DRCExclusionsWarning->Hide();
  463. }
  464. BOARD* board = m_editFrame->GetBoard();
  465. const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
  466. if( getPlotFormat() == PLOT_FORMAT::GERBER &&
  467. ( brd_settings.m_SolderMaskExpansion || brd_settings.m_SolderMaskMinWidth ) )
  468. {
  469. m_PlotOptionsSizer->Show( m_SizerSolderMaskAlert );
  470. }
  471. else
  472. {
  473. m_PlotOptionsSizer->Hide( m_SizerSolderMaskAlert );
  474. }
  475. }
  476. void DIALOG_PLOT::arrangeAllLayersList( const LSEQ& aSeq )
  477. {
  478. auto findLayer =
  479. [&]( wxRearrangeList* aList, PCB_LAYER_ID aLayer ) -> int
  480. {
  481. for( int ii = 0; ii < (int) aList->GetCount(); ++ii )
  482. {
  483. if( getLayerClientData( aList, ii )->Layer() == aLayer )
  484. return ii;
  485. }
  486. return -1;
  487. };
  488. int idx = 0;
  489. for( PCB_LAYER_ID layer : aSeq )
  490. {
  491. int currentPos = findLayer( m_plotAllLayersList, layer );
  492. while( currentPos > idx )
  493. {
  494. m_plotAllLayersList->Select( currentPos );
  495. m_plotAllLayersList->MoveCurrentUp();
  496. currentPos--;
  497. }
  498. idx++;
  499. }
  500. }
  501. #define ID_LAYER_FAB 13001
  502. #define ID_SELECT_COPPER_LAYERS 13002
  503. #define ID_DESELECT_COPPER_LAYERS 13003
  504. #define ID_SELECT_ALL_LAYERS 13004
  505. #define ID_DESELECT_ALL_LAYERS 13005
  506. #define ID_STACKUP_ORDER 13006
  507. // A helper function to show a popup menu, when the dialog is right clicked.
  508. void DIALOG_PLOT::OnRightClickLayers( wxMouseEvent& event )
  509. {
  510. // Build a list of layers for usual fabrication: copper layers + tech layers without courtyard
  511. LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() ) & ~LSET( { B_CrtYd, F_CrtYd } );
  512. wxMenu menu;
  513. menu.Append( new wxMenuItem( &menu, ID_LAYER_FAB, _( "Select Fab Layers" ) ) );
  514. menu.AppendSeparator();
  515. menu.Append( new wxMenuItem( &menu, ID_SELECT_COPPER_LAYERS, _( "Select All Copper Layers" ) ) );
  516. menu.Append( new wxMenuItem( &menu, ID_DESELECT_COPPER_LAYERS, _( "Deselect All Copper Layers" ) ) );
  517. menu.AppendSeparator();
  518. menu.Append( new wxMenuItem( &menu, ID_SELECT_ALL_LAYERS, _( "Select All Layers" ) ) );
  519. menu.Append( new wxMenuItem( &menu, ID_DESELECT_ALL_LAYERS, _( "Deselect All Layers" ) ) );
  520. menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
  521. [&]( wxCommandEvent& aCmd )
  522. {
  523. switch( aCmd.GetId() )
  524. {
  525. case ID_LAYER_FAB: // Select layers usually needed to build a board
  526. {
  527. for( unsigned i = 0; i < m_layerList.size(); i++ )
  528. {
  529. LSET layermask( { m_layerList[ i ] } );
  530. if( ( layermask & fab_layer_set ).any() )
  531. m_layerCheckListBox->Check( i, true );
  532. else
  533. m_layerCheckListBox->Check( i, false );
  534. }
  535. break;
  536. }
  537. case ID_SELECT_COPPER_LAYERS:
  538. for( unsigned i = 0; i < m_layerList.size(); i++ )
  539. {
  540. if( IsCopperLayer( m_layerList[i] ) )
  541. m_layerCheckListBox->Check( i, true );
  542. }
  543. break;
  544. case ID_DESELECT_COPPER_LAYERS:
  545. for( unsigned i = 0; i < m_layerList.size(); i++ )
  546. {
  547. if( IsCopperLayer( m_layerList[i] ) )
  548. m_layerCheckListBox->Check( i, false );
  549. }
  550. break;
  551. case ID_SELECT_ALL_LAYERS:
  552. for( unsigned i = 0; i < m_layerList.size(); i++ )
  553. m_layerCheckListBox->Check( i, true );
  554. break;
  555. case ID_DESELECT_ALL_LAYERS:
  556. for( unsigned i = 0; i < m_layerList.size(); i++ )
  557. m_layerCheckListBox->Check( i, false );
  558. break;
  559. default:
  560. aCmd.Skip();
  561. }
  562. } );
  563. PopupMenu( &menu );
  564. }
  565. void DIALOG_PLOT::OnRightClickAllLayers( wxMouseEvent& event )
  566. {
  567. wxMenu menu;
  568. menu.Append( new wxMenuItem( &menu, ID_SELECT_ALL_LAYERS, _( "Select All Layers" ) ) );
  569. menu.Append( new wxMenuItem( &menu, ID_DESELECT_ALL_LAYERS, _( "Deselect All Layers" ) ) );
  570. menu.AppendSeparator();
  571. menu.Append( new wxMenuItem( &menu, ID_STACKUP_ORDER, _( "Order as Board Stackup" ) ) );
  572. menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
  573. [&]( wxCommandEvent& aCmd )
  574. {
  575. switch( aCmd.GetId() )
  576. {
  577. case ID_SELECT_ALL_LAYERS:
  578. for( unsigned i = 0; i < m_plotAllLayersList->GetCount(); i++ )
  579. m_plotAllLayersList->Check( i, true );
  580. break;
  581. case ID_DESELECT_ALL_LAYERS:
  582. for( unsigned i = 0; i < m_plotAllLayersList->GetCount(); i++ )
  583. m_plotAllLayersList->Check( i, false );
  584. break;
  585. case ID_STACKUP_ORDER:
  586. {
  587. LSEQ stackup = m_editFrame->GetBoard()->GetEnabledLayers().SeqStackupForPlotting();
  588. arrangeAllLayersList( stackup );
  589. m_plotAllLayersList->Select( -1 );
  590. break;
  591. }
  592. default:
  593. aCmd.Skip();
  594. }
  595. } );
  596. PopupMenu( &menu );
  597. }
  598. void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
  599. {
  600. // Be sure drill file use the same settings (axis option, plot directory) as plot files:
  601. applyPlotSettings();
  602. DIALOG_GENDRILL dlg( m_editFrame, this );
  603. dlg.ShowModal();
  604. // a few plot settings can be modified: take them in account
  605. m_plotOpts = m_editFrame->GetPlotSettings();
  606. reInitDialog();
  607. }
  608. void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
  609. {
  610. // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt is checked (plot in DXF
  611. // polygon mode)
  612. m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
  613. // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode), force
  614. // m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
  615. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
  616. m_DXF_plotTextStrokeFontOpt->SetValue( true );
  617. }
  618. void DIALOG_PLOT::onOutputDirectoryBrowseClicked( wxCommandEvent& event )
  619. {
  620. // Build the absolute path of current output directory to preselect it in the file browser.
  621. std::function<bool( wxString* )> textResolver =
  622. [&]( wxString* token ) -> bool
  623. {
  624. return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
  625. };
  626. wxString path = m_outputDirectoryName->GetValue();
  627. path = ExpandTextVars( path, &textResolver );
  628. path = ExpandEnvVarSubstitutions( path, &Prj() );
  629. path = Prj().AbsolutePath( path );
  630. wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
  631. if( dirDialog.ShowModal() == wxID_CANCEL )
  632. return;
  633. wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
  634. wxFileName fn( Prj().AbsolutePath( m_editFrame->GetBoard()->GetFileName() ) );
  635. wxString defaultPath = fn.GetPathWithSep();
  636. wxString msg;
  637. wxFileName relPathTest; // Used to test if we can make the path relative
  638. relPathTest.Assign( dirDialog.GetPath() );
  639. // Test if making the path relative is possible before asking the user if they want to do it
  640. if( relPathTest.MakeRelativeTo( defaultPath ) )
  641. {
  642. msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
  643. wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
  644. wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
  645. if( dialog.ShowModal() == wxID_YES )
  646. dirName.MakeRelativeTo( defaultPath );
  647. }
  648. m_outputDirectoryName->SetValue( dirName.GetFullPath() );
  649. }
  650. PLOT_FORMAT DIALOG_PLOT::getPlotFormat()
  651. {
  652. // plot format id's are ordered like displayed in m_plotFormatOpt
  653. static const PLOT_FORMAT plotFmt[] = {
  654. PLOT_FORMAT::GERBER,
  655. PLOT_FORMAT::POST,
  656. PLOT_FORMAT::SVG,
  657. PLOT_FORMAT::DXF,
  658. PLOT_FORMAT::PDF };
  659. return plotFmt[m_plotFormatOpt->GetSelection()];
  660. }
  661. void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
  662. {
  663. // this option exist only in DXF format:
  664. m_DXF_plotModeOpt->Enable( getPlotFormat() == PLOT_FORMAT::DXF );
  665. // The alert message about non 0 solder mask min width and margin is shown
  666. // only in gerber format and if min mask width or mask margin is not 0
  667. BOARD* board = m_editFrame->GetBoard();
  668. const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
  669. if( getPlotFormat() == PLOT_FORMAT::GERBER
  670. && ( brd_settings.m_SolderMaskExpansion || brd_settings.m_SolderMaskMinWidth ) )
  671. {
  672. m_PlotOptionsSizer->Show( m_SizerSolderMaskAlert );
  673. }
  674. else
  675. {
  676. m_PlotOptionsSizer->Hide( m_SizerSolderMaskAlert );
  677. }
  678. switch( getPlotFormat() )
  679. {
  680. case PLOT_FORMAT::SVG:
  681. case PLOT_FORMAT::PDF:
  682. m_drillShapeOpt->Enable( true );
  683. m_plotMirrorOpt->Enable( true );
  684. m_useAuxOriginCheckBox->Enable( true );
  685. m_scaleOpt->Enable( true );
  686. m_fineAdjustXCtrl->Enable( false );
  687. m_fineAdjustYCtrl->Enable( false );
  688. m_trackWidthCorrection.Enable( false );
  689. m_plotPSNegativeOpt->Enable( true );
  690. m_forcePSA4OutputOpt->Enable( false );
  691. m_forcePSA4OutputOpt->SetValue( false );
  692. if( getPlotFormat() == PLOT_FORMAT::SVG )
  693. {
  694. m_PlotOptionsSizer->Show( m_svgOptionsSizer );
  695. m_PlotOptionsSizer->Hide( m_PDFOptionsSizer );
  696. }
  697. else
  698. {
  699. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  700. m_PlotOptionsSizer->Show( m_PDFOptionsSizer );
  701. }
  702. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  703. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  704. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  705. break;
  706. case PLOT_FORMAT::POST:
  707. m_drillShapeOpt->Enable( true );
  708. m_plotMirrorOpt->Enable( true );
  709. m_useAuxOriginCheckBox->Enable( false );
  710. m_useAuxOriginCheckBox->SetValue( false );
  711. m_scaleOpt->Enable( true );
  712. m_fineAdjustXCtrl->Enable( true );
  713. m_fineAdjustYCtrl->Enable( true );
  714. m_trackWidthCorrection.Enable( true );
  715. m_plotPSNegativeOpt->Enable( true );
  716. m_forcePSA4OutputOpt->Enable( true );
  717. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  718. m_PlotOptionsSizer->Show( m_PSOptionsSizer );
  719. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  720. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  721. m_PlotOptionsSizer->Hide( m_PDFOptionsSizer );
  722. break;
  723. case PLOT_FORMAT::GERBER:
  724. m_drillShapeOpt->Enable( false );
  725. m_drillShapeOpt->SetSelection( 0 );
  726. m_plotMirrorOpt->Enable( false );
  727. m_plotMirrorOpt->SetValue( false );
  728. m_useAuxOriginCheckBox->Enable( true );
  729. m_scaleOpt->Enable( false );
  730. m_scaleOpt->SetSelection( 1 );
  731. m_fineAdjustXCtrl->Enable( false );
  732. m_fineAdjustYCtrl->Enable( false );
  733. m_trackWidthCorrection.Enable( false );
  734. m_plotPSNegativeOpt->Enable( false );
  735. m_plotPSNegativeOpt->SetValue( false );
  736. m_forcePSA4OutputOpt->Enable( false );
  737. m_forcePSA4OutputOpt->SetValue( false );
  738. m_PlotOptionsSizer->Show( m_GerberOptionsSizer );
  739. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  740. m_PlotOptionsSizer->Hide( m_SizerDXF_options );
  741. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  742. m_PlotOptionsSizer->Hide( m_PDFOptionsSizer );
  743. break;
  744. case PLOT_FORMAT::DXF:
  745. m_drillShapeOpt->Enable( true );
  746. m_plotMirrorOpt->Enable( false );
  747. m_plotMirrorOpt->SetValue( false );
  748. m_useAuxOriginCheckBox->Enable( true );
  749. m_scaleOpt->Enable( true );
  750. m_fineAdjustXCtrl->Enable( false );
  751. m_fineAdjustYCtrl->Enable( false );
  752. m_trackWidthCorrection.Enable( false );
  753. m_plotPSNegativeOpt->Enable( false );
  754. m_plotPSNegativeOpt->SetValue( false );
  755. m_forcePSA4OutputOpt->Enable( false );
  756. m_forcePSA4OutputOpt->SetValue( false );
  757. m_PlotOptionsSizer->Hide( m_GerberOptionsSizer );
  758. m_PlotOptionsSizer->Hide( m_PSOptionsSizer );
  759. m_PlotOptionsSizer->Show( m_SizerDXF_options );
  760. m_PlotOptionsSizer->Hide( m_svgOptionsSizer );
  761. m_PlotOptionsSizer->Hide( m_PDFOptionsSizer );
  762. OnChangeDXFPlotMode( event );
  763. break;
  764. default:
  765. case PLOT_FORMAT::HPGL:
  766. case PLOT_FORMAT::UNDEFINED:
  767. break;
  768. }
  769. Layout();
  770. m_MainSizer->SetSizeHints( this );
  771. }
  772. // A helper function to "clip" aValue between aMin and aMax and write result in * aResult
  773. // return false if clipped, true if aValue is just copied into * aResult
  774. static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
  775. {
  776. if( aValue < aMin )
  777. {
  778. *aResult = aMin;
  779. return false;
  780. }
  781. else if( aValue > aMax )
  782. {
  783. *aResult = aMax;
  784. return false;
  785. }
  786. *aResult = aValue;
  787. return true;
  788. }
  789. static bool setInt( int* aResult, int aValue, int aMin, int aMax )
  790. {
  791. if( aValue < aMin )
  792. {
  793. *aResult = aMin;
  794. return false;
  795. }
  796. else if( aValue > aMax )
  797. {
  798. *aResult = aMax;
  799. return false;
  800. }
  801. *aResult = aValue;
  802. return true;
  803. }
  804. void DIALOG_PLOT::applyPlotSettings()
  805. {
  806. REPORTER& reporter = m_messagesPanel->Reporter();
  807. PCB_PLOT_PARAMS tempOptions;
  808. tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
  809. tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
  810. tempOptions.SetSketchPadsOnFabLayers( m_sketchPadsOnFabLayers->GetValue() );
  811. tempOptions.SetPlotPadNumbers( m_plotPadNumbers->GetValue() );
  812. tempOptions.SetHideDNPFPsOnFabLayers( m_plotDNP->GetValue()
  813. && m_hideDNP->GetValue() );
  814. tempOptions.SetSketchDNPFPsOnFabLayers( m_plotDNP->GetValue()
  815. && m_crossoutDNP->GetValue() );
  816. tempOptions.SetCrossoutDNPFPsOnFabLayers( m_plotDNP->GetValue()
  817. && m_crossoutDNP->GetValue() );
  818. tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
  819. tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
  820. int sel = m_drillShapeOpt->GetSelection();
  821. tempOptions.SetDrillMarksType( static_cast<DRILL_MARKS>( sel ) );
  822. tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
  823. tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
  824. sel = m_DXF_plotUnits->GetSelection();
  825. tempOptions.SetDXFPlotUnits( sel == 0 ? DXF_UNITS::INCH : DXF_UNITS::MM );
  826. if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
  827. tempOptions.SetTextMode( PLOT_TEXT_MODE::DEFAULT );
  828. else
  829. tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ? PLOT_TEXT_MODE::DEFAULT :
  830. PLOT_TEXT_MODE::NATIVE );
  831. if( getPlotFormat() == PLOT_FORMAT::SVG )
  832. {
  833. tempOptions.SetBlackAndWhite( m_SVGColorChoice->GetSelection() == 1 );
  834. }
  835. else if( getPlotFormat() == PLOT_FORMAT::PDF )
  836. {
  837. tempOptions.SetBlackAndWhite( m_PDFColorChoice->GetSelection() == 1 );
  838. tempOptions.m_PDFFrontFPPropertyPopups = m_frontFPPropertyPopups->GetValue();
  839. tempOptions.m_PDFBackFPPropertyPopups = m_backFPPropertyPopups->GetValue();
  840. tempOptions.m_PDFMetadata = m_pdfMetadata->GetValue();
  841. tempOptions.m_PDFSingle = m_pdfSingle->GetValue();
  842. }
  843. else
  844. {
  845. tempOptions.SetBlackAndWhite( true );
  846. }
  847. // Update settings from text fields. Rewrite values back to the fields,
  848. // since the values may have been constrained by the setters.
  849. // X scale
  850. double tmpDouble;
  851. wxString msg = m_fineAdjustXCtrl->GetValue();
  852. msg.ToDouble( &tmpDouble );
  853. if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  854. {
  855. msg.Printf( wxT( "%f" ), m_XScaleAdjust );
  856. m_fineAdjustXCtrl->SetValue( msg );
  857. msg.Printf( _( "X scale constrained." ) );
  858. reporter.Report( msg, RPT_SEVERITY_INFO );
  859. }
  860. // Y scale
  861. msg = m_fineAdjustYCtrl->GetValue();
  862. msg.ToDouble( &tmpDouble );
  863. if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
  864. {
  865. msg.Printf( wxT( "%f" ), m_YScaleAdjust );
  866. m_fineAdjustYCtrl->SetValue( msg );
  867. msg.Printf( _( "Y scale constrained." ) );
  868. reporter.Report( msg, RPT_SEVERITY_INFO );
  869. }
  870. auto cfg = m_editFrame->GetPcbNewSettings();
  871. if( m_job )
  872. {
  873. // When using a job we store the adjusts in the plot options
  874. tempOptions.SetFineScaleAdjustX( m_XScaleAdjust );
  875. tempOptions.SetFineScaleAdjustY( m_YScaleAdjust );
  876. }
  877. else
  878. {
  879. // The default is to use the pcbnew settings, so here we modify them
  880. cfg->m_Plot.fine_scale_x = m_XScaleAdjust;
  881. cfg->m_Plot.fine_scale_y = m_YScaleAdjust;
  882. }
  883. cfg->m_Plot.check_zones_before_plotting = m_zoneFillCheck->GetValue();
  884. // PS Width correction
  885. if( !setInt( &m_PSWidthAdjust, m_trackWidthCorrection.GetValue(), m_widthAdjustMinValue,
  886. m_widthAdjustMaxValue ) )
  887. {
  888. m_trackWidthCorrection.SetValue( m_PSWidthAdjust );
  889. msg.Printf( _( "Width correction constrained. The width correction value must be in the"
  890. " range of [%s; %s] for the current design rules." ),
  891. m_editFrame->StringFromValue( m_widthAdjustMinValue, true ),
  892. m_editFrame->StringFromValue( m_widthAdjustMaxValue, true ) );
  893. reporter.Report( msg, RPT_SEVERITY_WARNING );
  894. }
  895. if( m_job )
  896. {
  897. // When using a job we store the adjusts in the plot options
  898. tempOptions.SetWidthAdjust( m_PSWidthAdjust );
  899. }
  900. else
  901. {
  902. // The default is to use the pcbnew settings, so here we modify them
  903. // Store m_PSWidthAdjust in mm in user config
  904. cfg->m_Plot.ps_fine_width_adjust = pcbIUScale.IUTomm( m_PSWidthAdjust );
  905. }
  906. tempOptions.SetFormat( getPlotFormat() );
  907. tempOptions.SetDisableGerberMacros( m_disableApertMacros->GetValue() );
  908. tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
  909. tempOptions.SetUseGerberX2format( m_useGerberX2Format->GetValue() );
  910. tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
  911. tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
  912. tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
  913. tempOptions.SetSvgPrecision( m_svgPrecsision->GetValue() );
  914. tempOptions.SetSvgFitPageToBoard( m_SVG_fitPageToBoard->GetValue() );
  915. LSET selectedLayers;
  916. for( unsigned i = 0; i < m_layerList.size(); i++ )
  917. {
  918. if( m_layerCheckListBox->IsChecked( i ) )
  919. selectedLayers.set( m_layerList[i] );
  920. }
  921. // Get a list of copper layers that aren't being used by inverting enabled layers.
  922. LSET disabledCopperLayers = LSET::AllCuMask() & ~m_editFrame->GetBoard()->GetEnabledLayers();
  923. // Add selected layers from plot on all layers list in order set by user.
  924. wxArrayInt plotOnAllLayers;
  925. LSEQ commonLayers;
  926. if( m_plotAllLayersList->GetCheckedItems( plotOnAllLayers ) )
  927. {
  928. size_t count = plotOnAllLayers.GetCount();
  929. for( size_t i = 0; i < count; i++ )
  930. {
  931. int index = plotOnAllLayers.Item( i );
  932. PCB_LAYER_ID client_layer = getLayerClientData( m_plotAllLayersList, index )->Layer();
  933. commonLayers.push_back( client_layer );
  934. }
  935. }
  936. tempOptions.SetPlotOnAllLayersSequence( commonLayers );
  937. // Enable all of the disabled copper layers.
  938. // If someone enables more copper layers they will be selected by default.
  939. selectedLayers = selectedLayers | disabledCopperLayers;
  940. tempOptions.SetLayerSelection( selectedLayers );
  941. tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
  942. tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
  943. // Set output directory and replace backslashes with forward ones
  944. wxString dirStr;
  945. dirStr = m_outputDirectoryName->GetValue();
  946. dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
  947. tempOptions.SetOutputDirectory( dirStr );
  948. m_editFrame->Prj().GetProjectFile().m_PcbLastPath[ LAST_PATH_PLOT ] = dirStr;
  949. if( !m_job && !m_plotOpts.IsSameAs( tempOptions ) )
  950. {
  951. m_editFrame->SetPlotSettings( tempOptions );
  952. m_editFrame->OnModify();
  953. m_plotOpts = tempOptions;
  954. }
  955. else
  956. {
  957. m_plotOpts = tempOptions;
  958. }
  959. }
  960. void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
  961. {
  962. // Currently: do nothing
  963. }
  964. void DIALOG_PLOT::Plot( wxCommandEvent& event )
  965. {
  966. if( m_job )
  967. {
  968. applyPlotSettings();
  969. transferPlotParamsToJob();
  970. EndModal( wxID_OK );
  971. }
  972. else
  973. {
  974. BOARD* board = m_editFrame->GetBoard();
  975. applyPlotSettings();
  976. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  977. PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
  978. m_plotOpts.SetColorSettings( mgr.GetColorSettings( cfg->m_ColorTheme ) );
  979. m_plotOpts.SetSketchPadLineWidth( board->GetDesignSettings().GetLineThickness( F_Fab ) );
  980. // If no layer selected, we have nothing plotted.
  981. // Prompt user if it happens because he could think there is a bug in Pcbnew.
  982. if( !m_plotOpts.GetLayerSelection().any() )
  983. {
  984. DisplayError( this, _( "No layer selected, Nothing to plot" ) );
  985. return;
  986. }
  987. // Create output directory if it does not exist (also transform it in absolute form).
  988. // Bail if it fails.
  989. std::function<bool( wxString* )> textResolver =
  990. [&]( wxString* token ) -> bool
  991. {
  992. // Handles board->GetTitleBlock() *and* board->GetProject()
  993. return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
  994. };
  995. wxString path = m_plotOpts.GetOutputDirectory();
  996. path = ExpandTextVars( path, &textResolver );
  997. path = ExpandEnvVarSubstitutions( path, board->GetProject() );
  998. wxFileName outputDir = wxFileName::DirName( path );
  999. wxString boardFilename = m_editFrame->GetBoard()->GetFileName();
  1000. REPORTER& reporter = m_messagesPanel->Reporter();
  1001. if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
  1002. {
  1003. wxString msg;
  1004. msg.Printf( _( "Could not write plot files to folder '%s'." ), outputDir.GetPath() );
  1005. DisplayError( this, msg );
  1006. return;
  1007. }
  1008. if( m_zoneFillCheck->GetValue() )
  1009. m_editFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
  1010. m_plotOpts.SetAutoScale( false );
  1011. switch( m_plotOpts.GetScaleSelection() )
  1012. {
  1013. default: m_plotOpts.SetScale( 1 ); break;
  1014. case 0: m_plotOpts.SetAutoScale( true ); break;
  1015. case 2: m_plotOpts.SetScale( 1.5 ); break;
  1016. case 3: m_plotOpts.SetScale( 2 ); break;
  1017. case 4: m_plotOpts.SetScale( 3 ); break;
  1018. }
  1019. /* If the scale factor edit controls are disabled or the scale value
  1020. * is 0, don't adjust the base scale factor. This fixes a bug when
  1021. * the default scale adjust is initialized to 0 and saved in program
  1022. * settings resulting in a divide by zero fault.
  1023. */
  1024. if( getPlotFormat() == PLOT_FORMAT::POST )
  1025. {
  1026. if( m_XScaleAdjust != 0.0 )
  1027. m_plotOpts.SetFineScaleAdjustX( m_XScaleAdjust );
  1028. if( m_YScaleAdjust != 0.0 )
  1029. m_plotOpts.SetFineScaleAdjustY( m_YScaleAdjust );
  1030. m_plotOpts.SetWidthAdjust( m_PSWidthAdjust );
  1031. }
  1032. // Test for a reasonable scale value
  1033. // XXX could this actually happen? isn't it constrained in the apply function?
  1034. if( m_plotOpts.GetScale() < PLOT_MIN_SCALE )
  1035. DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
  1036. if( m_plotOpts.GetScale() > PLOT_MAX_SCALE )
  1037. DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
  1038. // Save the current plot options in the board
  1039. m_editFrame->SetPlotSettings( m_plotOpts );
  1040. LOCALE_IO dummy; // Ensure the "C3 locale is used by the plotter
  1041. PCB_PLOTTER pcbPlotter( m_editFrame->GetBoard(), &reporter, m_plotOpts );
  1042. LSEQ layersToPlot = m_plotOpts.GetLayerSelection().UIOrder();
  1043. wxArrayInt plotOnAllLayers;
  1044. LSEQ commonLayers;
  1045. if( m_plotAllLayersList->GetCheckedItems( plotOnAllLayers ) )
  1046. {
  1047. size_t count = plotOnAllLayers.GetCount();
  1048. for( size_t i = 0; i < count; i++ )
  1049. {
  1050. int index = plotOnAllLayers.Item( i );
  1051. PCB_LAYER_ID client_layer = getLayerClientData( m_plotAllLayersList, index )->Layer();
  1052. commonLayers.push_back( client_layer );
  1053. }
  1054. }
  1055. pcbPlotter.Plot( outputDir.GetPath(), layersToPlot, commonLayers,
  1056. m_useGerberExtensions->GetValue() );
  1057. }
  1058. }
  1059. void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
  1060. {
  1061. PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
  1062. if( parent )
  1063. {
  1064. DRC_TOOL* drcTool = parent->GetToolManager()->GetTool<DRC_TOOL>();
  1065. // First close an existing dialog if open
  1066. // (low probability, but can happen)
  1067. drcTool->DestroyDRCDialog();
  1068. // Open a new drc dialog, with the right parent frame, and in Modal Mode
  1069. drcTool->ShowDRCDialog( this );
  1070. // Update DRC warnings on return to this dialog
  1071. reInitDialog();
  1072. }
  1073. }
  1074. void DIALOG_PLOT::onOpenOutputDirectory( wxCommandEvent& event )
  1075. {
  1076. std::function<bool( wxString* )> textResolver = [&]( wxString* token ) -> bool
  1077. {
  1078. return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
  1079. };
  1080. wxString path = m_outputDirectoryName->GetValue();
  1081. path = ExpandTextVars( path, &textResolver );
  1082. path = ExpandEnvVarSubstitutions( path, &Prj() );
  1083. path = Prj().AbsolutePath( path );
  1084. if( !wxDirExists( path ) )
  1085. {
  1086. DisplayError( this, wxString::Format( _( "Directory '%s' does not exist." ), path ) );
  1087. return;
  1088. }
  1089. wxLaunchDefaultApplication( path );
  1090. }
  1091. void DIALOG_PLOT::onBoardSetup( wxHyperlinkEvent& aEvent )
  1092. {
  1093. PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
  1094. if( parent )
  1095. {
  1096. parent->ShowBoardSetupDialog( _( "Solder Mask/Paste" ) );
  1097. // Update warnings on return to this dialog
  1098. reInitDialog();
  1099. }
  1100. }
  1101. void DIALOG_PLOT::onPlotAllListMoveUp( wxCommandEvent& aEvent )
  1102. {
  1103. if( m_plotAllLayersList->CanMoveCurrentUp() )
  1104. m_plotAllLayersList->MoveCurrentUp();
  1105. }
  1106. void DIALOG_PLOT::onPlotAllListMoveDown( wxCommandEvent& aEvent )
  1107. {
  1108. if( m_plotAllLayersList->CanMoveCurrentDown() )
  1109. m_plotAllLayersList->MoveCurrentDown();
  1110. }
  1111. void DIALOG_PLOT::onDNPCheckbox( wxCommandEvent& aEvent )
  1112. {
  1113. m_hideDNP->Enable( aEvent.IsChecked() );
  1114. m_crossoutDNP->Enable( aEvent.IsChecked() );
  1115. }
  1116. void DIALOG_PLOT::onSketchPads( wxCommandEvent& aEvent )
  1117. {
  1118. m_plotPadNumbers->Enable( aEvent.IsChecked() );
  1119. }