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.

561 lines
20 KiB

4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <string_utils.h>
  25. #include <board_commit.h>
  26. #include <pcb_edit_frame.h>
  27. #include <footprint_edit_frame.h>
  28. #include <pcb_layer_box_selector.h>
  29. #include <pcbnew.h>
  30. #include <board.h>
  31. #include <board_design_settings.h>
  32. #include <footprint.h>
  33. #include <pcb_group.h>
  34. #include <pcb_dimension.h>
  35. #include <fp_shape.h>
  36. #include <pcb_text.h>
  37. #include <widgets/unit_binder.h>
  38. #include <widgets/font_choice.h>
  39. #include <tool/tool_manager.h>
  40. #include <tools/global_edit_tool.h>
  41. #include <tools/footprint_editor_control.h>
  42. #include <dialog_global_edit_text_and_graphics_base.h>
  43. // Columns of layer classes grid
  44. enum
  45. {
  46. COL_CLASS_NAME = 0,
  47. COL_LINE_THICKNESS,
  48. COL_TEXT_WIDTH,
  49. COL_TEXT_HEIGHT,
  50. COL_TEXT_THICKNESS,
  51. COL_TEXT_ITALIC,
  52. COL_TEXT_UPRIGHT
  53. };
  54. enum
  55. {
  56. ROW_HEADER = 0,
  57. ROW_SILK,
  58. ROW_COPPER,
  59. ROW_EDGES,
  60. ROW_COURTYARD,
  61. ROW_FAB,
  62. ROW_OTHERS
  63. };
  64. static bool g_modifyReferences;
  65. static bool g_modifyValues;
  66. static bool g_modifyOtherFields;
  67. static bool g_modifyFootprintGraphics;
  68. static bool g_modifyBoardText;
  69. static bool g_modifyBoardGraphics;
  70. static bool g_filterByLayer;
  71. static int g_layerFilter;
  72. static bool g_filterByReference;
  73. static wxString g_referenceFilter;
  74. static bool g_filterByFootprint;
  75. static wxString g_footprintFilter;
  76. static bool g_filterSelected = false;
  77. class DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS : public DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE
  78. {
  79. PCB_BASE_EDIT_FRAME* m_parent;
  80. BOARD_DESIGN_SETTINGS* m_brdSettings;
  81. PCB_SELECTION m_selection;
  82. bool m_isBoardEditor;
  83. UNIT_BINDER m_lineWidth;
  84. UNIT_BINDER m_textWidth;
  85. UNIT_BINDER m_textHeight;
  86. UNIT_BINDER m_thickness;
  87. public:
  88. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS( PCB_BASE_EDIT_FRAME* parent );
  89. ~DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS() override;
  90. protected:
  91. void onActionButtonChange( wxCommandEvent& event ) override;
  92. void onSpecifiedValueUpdateUI( wxUpdateUIEvent& event ) override;
  93. void OnLayerFilterSelect( wxCommandEvent& event ) override
  94. {
  95. m_layerFilterOpt->SetValue( true );
  96. }
  97. void OnReferenceFilterText( wxCommandEvent& event ) override
  98. {
  99. m_referenceFilterOpt->SetValue( true );
  100. }
  101. void OnFootprintFilterText( wxCommandEvent& event ) override
  102. {
  103. m_footprintFilterOpt->SetValue( true );
  104. }
  105. bool TransferDataToWindow() override;
  106. bool TransferDataFromWindow() override;
  107. void visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
  108. void processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem );
  109. };
  110. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS( PCB_BASE_EDIT_FRAME* parent ) :
  111. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE( parent ),
  112. m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits ),
  113. m_textWidth( parent, m_SizeXlabel, m_SizeXCtrl, m_SizeXunit ),
  114. m_textHeight( parent, m_SizeYlabel, m_SizeYCtrl, m_SizeYunit ),
  115. m_thickness( parent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnit )
  116. {
  117. m_parent = parent;
  118. m_brdSettings = &m_parent->GetDesignSettings();
  119. m_isBoardEditor = dynamic_cast<PCB_EDIT_FRAME*>( m_parent ) != nullptr;
  120. if( !m_isBoardEditor )
  121. {
  122. m_otherFields->SetLabel( _( "Other text items" ) );
  123. m_footprintGraphics->SetLabel( _( "Graphic items" ) );
  124. m_boardText->Show( false );
  125. m_boardGraphics->Show( false );
  126. m_referenceFilterOpt->Show( false );
  127. m_referenceFilter->Show( false );
  128. m_footprintFilterOpt->Show( false );
  129. m_footprintFilter->Show( false );
  130. }
  131. m_layerFilter->SetBoardFrame( m_parent );
  132. m_layerFilter->SetLayersHotkeys( false );
  133. m_layerFilter->Resync();
  134. m_LayerCtrl->SetBoardFrame( m_parent );
  135. m_LayerCtrl->SetLayersHotkeys( false );
  136. m_LayerCtrl->SetUndefinedLayerName( INDETERMINATE_ACTION );
  137. m_LayerCtrl->Resync();
  138. m_grid->SetCellHighlightPenWidth( 0 );
  139. m_grid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
  140. SetupStandardButtons();
  141. finishDialogSettings();
  142. }
  143. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::~DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS()
  144. {
  145. g_modifyReferences = m_references->GetValue();
  146. g_modifyValues = m_values->GetValue();
  147. g_modifyOtherFields = m_otherFields->GetValue();
  148. g_modifyFootprintGraphics = m_footprintGraphics->GetValue();
  149. if( m_isBoardEditor )
  150. {
  151. g_modifyBoardText = m_boardText->GetValue();
  152. g_modifyBoardGraphics = m_boardGraphics->GetValue();
  153. }
  154. g_filterByLayer = m_layerFilterOpt->GetValue();
  155. g_layerFilter = m_layerFilter->GetLayerSelection();
  156. if( m_isBoardEditor )
  157. {
  158. g_filterByReference = m_referenceFilterOpt->GetValue();
  159. g_referenceFilter = m_referenceFilter->GetValue();
  160. g_filterByFootprint = m_footprintFilterOpt->GetValue();
  161. g_footprintFilter = m_footprintFilter->GetValue();
  162. }
  163. g_filterSelected = m_selectedItemsFilter->GetValue();
  164. }
  165. bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow()
  166. {
  167. PCB_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
  168. m_selection = selTool->GetSelection();
  169. m_references->SetValue( g_modifyReferences );
  170. m_values->SetValue( g_modifyValues );
  171. m_otherFields->SetValue( g_modifyOtherFields );
  172. m_footprintGraphics->SetValue( g_modifyFootprintGraphics );
  173. if( m_isBoardEditor )
  174. {
  175. m_boardText->SetValue( g_modifyBoardText );
  176. m_boardGraphics->SetValue( g_modifyBoardGraphics );
  177. }
  178. if( m_layerFilter->SetLayerSelection( g_layerFilter ) != wxNOT_FOUND )
  179. m_layerFilterOpt->SetValue( g_filterByLayer );
  180. if( m_isBoardEditor )
  181. {
  182. // SetValue() generates events, ChangeValue() does not
  183. m_referenceFilter->ChangeValue( g_referenceFilter );
  184. m_referenceFilterOpt->SetValue( g_filterByReference );
  185. m_footprintFilter->ChangeValue( g_footprintFilter );
  186. m_footprintFilterOpt->SetValue( g_filterByFootprint );
  187. }
  188. m_selectedItemsFilter->SetValue( g_filterSelected );
  189. m_lineWidth.SetValue( INDETERMINATE_ACTION );
  190. m_fontCtrl->Append( INDETERMINATE_ACTION );
  191. m_fontCtrl->SetStringSelection( INDETERMINATE_ACTION );
  192. m_textWidth.SetValue( INDETERMINATE_ACTION );
  193. m_textHeight.SetValue( INDETERMINATE_ACTION );
  194. m_thickness.SetValue( INDETERMINATE_ACTION );
  195. m_bold->Set3StateValue( wxCHK_UNDETERMINED );
  196. m_italic->Set3StateValue( wxCHK_UNDETERMINED );
  197. m_keepUpright->Set3StateValue( wxCHK_UNDETERMINED );
  198. m_visible->Set3StateValue( wxCHK_UNDETERMINED );
  199. m_LayerCtrl->SetLayerSelection( UNDEFINED_LAYER );
  200. #define SET_INT_VALUE( aRow, aCol, aValue ) \
  201. m_grid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true ) )
  202. #define SET_BOOL_VALUE( aRow, aCol, aValue ) \
  203. attr = new wxGridCellAttr; \
  204. attr->SetRenderer( new wxGridCellBoolRenderer() ); \
  205. attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); \
  206. attr->SetReadOnly(); \
  207. m_grid->SetAttr( aRow, aCol, attr ); \
  208. m_grid->SetCellValue( aRow, aCol, ( aValue ) ? "1" : "" )
  209. const BOARD_DESIGN_SETTINGS& bds = m_parent->GetBoard()->GetDesignSettings();
  210. wxGridCellAttr* attr;
  211. m_grid->SetCellValue( ROW_SILK, COL_CLASS_NAME, _( "Silk Layers" ) );
  212. m_grid->SetCellValue( ROW_COPPER, COL_CLASS_NAME, _( "Copper Layers" ) );
  213. m_grid->SetCellValue( ROW_EDGES, COL_CLASS_NAME, _( "Edge Cuts" ) );
  214. m_grid->SetCellValue( ROW_COURTYARD, COL_CLASS_NAME, _( "Courtyards" ) );
  215. m_grid->SetCellValue( ROW_FAB, COL_CLASS_NAME, _( "Fab Layers" ) );
  216. m_grid->SetCellValue( ROW_OTHERS, COL_CLASS_NAME, _( "Other Layers" ) );
  217. m_grid->SetCellValue( ROW_HEADER, COL_LINE_THICKNESS, _( "Line Thickness" ) );
  218. SET_INT_VALUE( ROW_SILK, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_SILK ] );
  219. SET_INT_VALUE( ROW_COPPER, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_COPPER ] );
  220. SET_INT_VALUE( ROW_EDGES, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_EDGES ] );
  221. SET_INT_VALUE( ROW_COURTYARD, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_COURTYARD ] );
  222. SET_INT_VALUE( ROW_FAB, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_FAB ] );
  223. SET_INT_VALUE( ROW_OTHERS, COL_LINE_THICKNESS, bds.m_LineThickness[ LAYER_CLASS_OTHERS ] );
  224. m_grid->SetCellValue( ROW_HEADER, COL_TEXT_WIDTH, _( "Text Width" ) );
  225. SET_INT_VALUE( ROW_SILK, COL_TEXT_WIDTH, bds.m_TextSize[ LAYER_CLASS_SILK ].x );
  226. SET_INT_VALUE( ROW_COPPER, COL_TEXT_WIDTH, bds.m_TextSize[ LAYER_CLASS_COPPER ].x );
  227. SET_INT_VALUE( ROW_FAB, COL_TEXT_WIDTH, bds.m_TextSize[ LAYER_CLASS_FAB ].x );
  228. SET_INT_VALUE( ROW_OTHERS, COL_TEXT_WIDTH, bds.m_TextSize[ LAYER_CLASS_OTHERS ].x );
  229. m_grid->SetCellValue( ROW_HEADER, COL_TEXT_HEIGHT, _( "Text Height" ) );
  230. SET_INT_VALUE( ROW_SILK, COL_TEXT_HEIGHT, bds.m_TextSize[ LAYER_CLASS_SILK ].y );
  231. SET_INT_VALUE( ROW_COPPER, COL_TEXT_HEIGHT, bds.m_TextSize[ LAYER_CLASS_COPPER ].y );
  232. SET_INT_VALUE( ROW_FAB, COL_TEXT_HEIGHT, bds.m_TextSize[ LAYER_CLASS_FAB ].y );
  233. SET_INT_VALUE( ROW_OTHERS, COL_TEXT_HEIGHT, bds.m_TextSize[ LAYER_CLASS_OTHERS ].y );
  234. m_grid->SetCellValue( ROW_HEADER, COL_TEXT_THICKNESS, _( "Text Thickness" ) );
  235. SET_INT_VALUE( ROW_SILK, COL_TEXT_THICKNESS, bds.m_TextThickness[ LAYER_CLASS_SILK ] );
  236. SET_INT_VALUE( ROW_COPPER, COL_TEXT_THICKNESS, bds.m_TextThickness[ LAYER_CLASS_COPPER ] );
  237. SET_INT_VALUE( ROW_FAB, COL_TEXT_THICKNESS, bds.m_TextThickness[ LAYER_CLASS_FAB ] );
  238. SET_INT_VALUE( ROW_OTHERS, COL_TEXT_THICKNESS, bds.m_TextThickness[ LAYER_CLASS_OTHERS ] );
  239. m_grid->SetCellValue( ROW_HEADER, COL_TEXT_ITALIC, _( "Italic" ) );
  240. SET_BOOL_VALUE( ROW_SILK, COL_TEXT_ITALIC, bds.m_TextItalic[ LAYER_CLASS_SILK ] );
  241. SET_BOOL_VALUE( ROW_COPPER, COL_TEXT_ITALIC, bds.m_TextItalic[ LAYER_CLASS_COPPER ] );
  242. SET_BOOL_VALUE( ROW_FAB, COL_TEXT_ITALIC, bds.m_TextItalic[ LAYER_CLASS_FAB ] );
  243. SET_BOOL_VALUE( ROW_OTHERS, COL_TEXT_ITALIC, bds.m_TextItalic[ LAYER_CLASS_OTHERS ] );
  244. m_grid->SetCellValue( ROW_HEADER, COL_TEXT_UPRIGHT, _( "Upright" ) );
  245. SET_BOOL_VALUE( ROW_SILK, COL_TEXT_UPRIGHT, bds.m_TextUpright[ LAYER_CLASS_SILK ] );
  246. SET_BOOL_VALUE( ROW_COPPER, COL_TEXT_UPRIGHT, bds.m_TextUpright[ LAYER_CLASS_COPPER ] );
  247. SET_BOOL_VALUE( ROW_FAB, COL_TEXT_UPRIGHT, bds.m_TextUpright[ LAYER_CLASS_FAB ] );
  248. SET_BOOL_VALUE( ROW_OTHERS, COL_TEXT_UPRIGHT, bds.m_TextUpright[ LAYER_CLASS_OTHERS ] );
  249. return true;
  250. #undef SET_INT_VALUE
  251. #undef SET_BOOL_VALUE
  252. }
  253. void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::onActionButtonChange( wxCommandEvent& event )
  254. {
  255. // Update the UNIT_BINDER controls if the action to take is changed
  256. bool enable = m_setToSpecifiedValues->GetValue();
  257. m_lineWidth.Enable( enable );
  258. m_textWidth.Enable( enable );
  259. m_textHeight.Enable( enable );
  260. m_thickness.Enable( enable );
  261. }
  262. void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::onSpecifiedValueUpdateUI( wxUpdateUIEvent& event )
  263. {
  264. // Update the UI for the elements inside the use specified values sizer
  265. event.Enable( m_setToSpecifiedValues->GetValue() );
  266. }
  267. void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem )
  268. {
  269. aCommit.Modify( aItem );
  270. EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aItem );
  271. FP_TEXT* fpTextItem = dynamic_cast<FP_TEXT*>( aItem );
  272. PCB_SHAPE* drawItem = dynamic_cast<PCB_SHAPE*>( aItem );
  273. PCB_DIMENSION_BASE* dimension = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
  274. if( dimension )
  275. textItem = &dimension->Text();
  276. if( m_setToSpecifiedValues->GetValue() )
  277. {
  278. if( m_LayerCtrl->GetLayerSelection() != UNDEFINED_LAYER )
  279. aItem->SetLayer( ToLAYER_ID( m_LayerCtrl->GetLayerSelection() ) );
  280. if( !m_textWidth.IsIndeterminate() && textItem )
  281. textItem->SetTextSize( wxSize( m_textWidth.GetValue(), textItem->GetTextSize().y ) );
  282. if( !m_textHeight.IsIndeterminate() && textItem )
  283. textItem->SetTextSize( wxSize( textItem->GetTextSize().x, m_textHeight.GetValue() ) );
  284. if( !m_thickness.IsIndeterminate() && textItem )
  285. textItem->SetTextThickness( m_thickness.GetValue() );
  286. if( m_bold->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
  287. textItem->SetBold( m_bold->GetValue() );
  288. if( m_italic->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
  289. textItem->SetItalic( m_italic->GetValue() );
  290. // Must come after setting bold & italic
  291. if( m_fontCtrl->GetStringSelection() != INDETERMINATE_ACTION && textItem )
  292. {
  293. textItem->SetFont( m_fontCtrl->GetFontSelection( textItem->IsBold(),
  294. textItem->IsItalic() ) );
  295. }
  296. if( m_visible->Get3StateValue() != wxCHK_UNDETERMINED && textItem )
  297. textItem->SetVisible( m_visible->GetValue() );
  298. if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED && fpTextItem )
  299. fpTextItem->SetKeepUpright( m_keepUpright->GetValue() );
  300. if( !m_lineWidth.IsIndeterminate() )
  301. {
  302. if( drawItem )
  303. {
  304. STROKE_PARAMS stroke = drawItem->GetStroke();
  305. stroke.SetWidth( m_lineWidth.GetValue() );
  306. drawItem->SetStroke( stroke );
  307. }
  308. if( dimension )
  309. dimension->SetLineThickness( m_lineWidth.GetValue() );
  310. }
  311. }
  312. else
  313. {
  314. PCB_LAYER_ID layer = aItem->GetLayer();
  315. if( textItem )
  316. {
  317. textItem->SetTextSize( m_brdSettings->GetTextSize( layer ) );
  318. textItem->SetTextThickness( m_brdSettings->GetTextThickness( layer ) );
  319. textItem->SetItalic( m_brdSettings->GetTextItalic( layer ) );
  320. }
  321. if( fpTextItem )
  322. fpTextItem->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) );
  323. if( drawItem )
  324. {
  325. STROKE_PARAMS stroke = drawItem->GetStroke();
  326. stroke.SetWidth( m_brdSettings->GetLineThickness( layer ) );
  327. drawItem->SetStroke( stroke );
  328. }
  329. if( dimension )
  330. dimension->SetLineThickness( m_brdSettings->GetLineThickness( layer ) );
  331. }
  332. }
  333. void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( BOARD_COMMIT& aCommit, BOARD_ITEM* aItem )
  334. {
  335. if( m_selectedItemsFilter->GetValue() )
  336. {
  337. BOARD_ITEM* candidate = aItem;
  338. if( !candidate->IsSelected() )
  339. {
  340. if( candidate->GetParent() && candidate->GetParent()->Type() == PCB_FOOTPRINT_T )
  341. candidate = candidate->GetParent();
  342. }
  343. if( !candidate->IsSelected() )
  344. {
  345. candidate = candidate->GetParentGroup();
  346. while( candidate && !candidate->IsSelected() )
  347. candidate = candidate->GetParentGroup();
  348. if( !candidate )
  349. return;
  350. }
  351. }
  352. if( m_layerFilterOpt->GetValue() && m_layerFilter->GetLayerSelection() != UNDEFINED_LAYER )
  353. {
  354. if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
  355. return;
  356. }
  357. if( m_isBoardEditor )
  358. {
  359. if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
  360. {
  361. FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
  362. if( fp )
  363. {
  364. if( !WildCompareString( m_referenceFilter->GetValue(), fp->GetReference(), false ) )
  365. return;
  366. }
  367. }
  368. if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() )
  369. {
  370. FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParent() );
  371. if( fp )
  372. {
  373. if( !WildCompareString( m_footprintFilter->GetValue(), fp->GetFPID().Format(), false ) )
  374. return;
  375. }
  376. }
  377. }
  378. processItem( aCommit, aItem );
  379. }
  380. bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow()
  381. {
  382. if( !m_textWidth.Validate( TEXTS_MIN_SIZE, TEXTS_MAX_SIZE )
  383. || !m_textHeight.Validate( TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) )
  384. {
  385. return false;
  386. }
  387. BOARD_COMMIT commit( m_parent );
  388. // Go through the footprints
  389. for( FOOTPRINT* fp : m_parent->GetBoard()->Footprints() )
  390. {
  391. if( m_references->GetValue() )
  392. visitItem( commit, &fp->Reference() );
  393. if( m_values->GetValue() )
  394. visitItem( commit, &fp->Value() );
  395. // Go through all other footprint items
  396. for( BOARD_ITEM* boardItem : fp->GraphicalItems() )
  397. {
  398. KICAD_T itemType = boardItem->Type();
  399. if( itemType == PCB_FP_TEXT_T )
  400. {
  401. // We are guaranteed to always get an EDA_TEXT in this statement, but we must
  402. // use the dynamic_cast to move through the type tree anyway.
  403. const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
  404. if( m_references->GetValue() && text == wxT( "${REFERENCE}" ) )
  405. visitItem( commit, boardItem );
  406. else if( m_values->GetValue() && text == wxT( "${VALUE}" ) )
  407. visitItem( commit, boardItem );
  408. else if( m_otherFields->GetValue() )
  409. visitItem( commit, boardItem );
  410. }
  411. else if( itemType == PCB_FP_SHAPE_T || BaseType( itemType ) == PCB_DIMENSION_T )
  412. {
  413. if( m_footprintGraphics->GetValue() )
  414. visitItem( commit, boardItem );
  415. }
  416. }
  417. }
  418. if( m_isBoardEditor )
  419. {
  420. // Go through the PCB text & graphic items
  421. for( BOARD_ITEM* boardItem : m_parent->GetBoard()->Drawings() )
  422. {
  423. KICAD_T itemType = boardItem->Type();
  424. if( itemType == PCB_TEXT_T )
  425. {
  426. if( m_boardText->GetValue() )
  427. visitItem( commit, boardItem );
  428. }
  429. else if( itemType == PCB_SHAPE_T || BaseType( itemType ) == PCB_DIMENSION_T )
  430. {
  431. if( m_boardGraphics->GetValue() )
  432. visitItem( commit, boardItem );
  433. }
  434. }
  435. }
  436. commit.Push( "Edit text and graphics properties" );
  437. m_parent->GetCanvas()->Refresh();
  438. return true;
  439. }
  440. int GLOBAL_EDIT_TOOL::EditTextAndGraphics( const TOOL_EVENT& aEvent )
  441. {
  442. PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
  443. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
  444. dlg.ShowModal();
  445. return 0;
  446. }
  447. int FOOTPRINT_EDITOR_CONTROL::EditTextAndGraphics( const TOOL_EVENT& aEvent )
  448. {
  449. FOOTPRINT_EDIT_FRAME* editFrame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
  450. DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
  451. dlg.ShowModal();
  452. return 0;
  453. }