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.

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