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.

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