KiCad PCB EDA Suite
dialog_edit_footprint_for_BoardEditor.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
7  * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
28 #include <bitmaps.h>
29 #include <board_commit.h>
30 #include <board_design_settings.h>
31 #include <class_module.h>
32 #include <confirm.h>
33 #include <dialog_text_entry.h>
34 #include <fctsys.h>
35 #include <filename_resolver.h>
36 #include <pcb_edit_frame.h>
37 #include <pcbnew_settings.h>
38 #include <pgm_base.h>
39 #include <validators.h>
41 #include <widgets/text_ctrl_eval.h>
42 #include <widgets/wx_grid.h>
44 
47 
49 
50 
51 int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
52 
53 
55  MODULE* aModule ) :
57  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
58  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
59  m_OrientValidator( 1, &m_OrientValue ),
60  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
61  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
62  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
63  m_initialFocus( true ),
64  m_inSelect( false )
65 {
66  m_frame = aParent;
67  m_footprint = aModule;
68 
69  // Configure display origin transforms
72 
73  for( size_t i = 0; i < m_NoteBook->GetPageCount(); ++i )
74  m_macHack.push_back( true );
75 
77 
78  m_delayedErrorMessage = wxEmptyString;
79  m_delayedFocusGrid = nullptr;
80  m_delayedFocusRow = -1;
82 
83  // Give an icon
84  wxIcon icon;
85  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
86  SetIcon( icon );
87 
88  // Give a bit more room for combobox editors
89  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
90  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
91 
93  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
94  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
95 
96  // Show/hide text item columns according to the user's preference
98 
99  // Set up the 3D models grid
100  // Path selector
101  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
102  if( cfg->m_lastFootprint3dDir.IsEmpty() )
103  {
104  wxGetEnv( KISYS3DMOD, &cfg->m_lastFootprint3dDir );
105  }
106 
107  wxGridCellAttr* attr = new wxGridCellAttr;
108  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
109  true, Prj().GetProjectPath() ) );
110  m_modelsGrid->SetColAttr( 0, attr );
111 
112  // Show checkbox
113  attr = new wxGridCellAttr;
114  attr->SetRenderer( new wxGridCellBoolRenderer() );
115  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
116  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
117  m_modelsGrid->SetColAttr( 1, attr );
118  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
119  m_modelsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
120 
121  m_OrientValidator.SetRange( -360.0, 360.0 );
122  m_OrientValueCtrl->SetValidator( m_OrientValidator );
124 
125  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
126 
128 
129  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
130 
131  // Set font size for items showing long strings:
132  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
133  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
134 #if __WXMAC__
135  m_allow90Label->SetFont( infoFont );
136  m_allow180Label->SetFont( infoFont );
137 #endif
138  m_staticTextInfoCopper->SetFont( infoFont );
139  m_staticTextInfoPaste->SetFont( infoFont );
140 
141  m_libraryIDLabel->SetFont( infoFont );
142  m_tcLibraryID->SetFont( infoFont );
143 
144  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
145  m_staticTextInfoValNeg->SetFont( infoFont );
146  m_staticTextInfoValPos->SetFont( infoFont );
147 
148  m_NoteBook->SetSelection( m_page );
149 
150  if( m_page == 0 )
151  {
153  m_delayedFocusRow = 0;
155  }
156  else if ( m_page == 1 )
158  else
159  {
161  m_delayedFocusRow = 0;
163  }
164 
165  m_sdbSizerStdButtonsOK->SetDefault();
166 
167  m_OrientValue = 0;
168 
169  // Configure button logos
170  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
171  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
172  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
173  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
174  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
175 
177 }
178 
179 
181 {
183  m_itemsGrid->GetShownColumns().ToStdString();
184 
185  // Prevents crash bug in wxGrid's d'tor
187 
188  // Delete the GRID_TRICKS.
189  m_itemsGrid->PopEventHandler( true );
190  m_modelsGrid->PopEventHandler( true );
191 
192  // free the memory used by all models, otherwise models which were
193  // browsed but not used would consume memory
194  Prj().Get3DCacheManager()->FlushCache( false );
195 
196  // the GL canvas has to be visible before it is destroyed
197  m_page = m_NoteBook->GetSelection();
198  m_NoteBook->SetSelection( 1 );
199 
200  delete m_PreviewPane;
201 }
202 
203 
205 {
207 }
208 
209 
211 {
213 }
214 
215 
217 {
218  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
219 }
220 
221 
223 {
224  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
225 }
226 
227 
229 {
230  if( m_Orient0->GetValue() )
231  m_OrientValue = 0.0;
232  else if( m_Orient90->GetValue() )
233  m_OrientValue = 90.0;
234  else if( m_Orient270->GetValue() )
235  m_OrientValue = 270.0;
236  else if( m_Orient180->GetValue() )
237  m_OrientValue = 180.0;
238 
240 }
241 
242 
244 {
245  m_OrientOther->SetValue( true );
246 
247  aEvent.Skip();
248 }
249 
250 
252 {
253  if( !wxDialog::TransferDataToWindow() )
254  return false;
255 
256  if( !m_PanelGeneral->TransferDataToWindow() )
257  return false;
258 
259  if( !m_Panel3D->TransferDataToWindow() )
260  return false;
261 
262  // Module Texts
263 
264  m_texts->push_back( m_footprint->Reference() );
265  m_texts->push_back( m_footprint->Value() );
266 
267  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
268  {
269  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
270 
271  if( textModule )
272  m_texts->push_back( *textModule );
273  }
274 
275  // notify the grid
276  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
277  m_itemsGrid->ProcessTableMessage( tmsg );
278 
279  // Module Properties
280 
283 
284  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
285 
287 
288  if( m_OrientValue == 0.0 )
289  m_Orient0->SetValue( true );
290  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
291  m_Orient90->SetValue( true );
292  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
293  m_Orient270->SetValue( true );
294  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
295  m_Orient180->SetValue( true );
296  else
297  m_OrientOther->SetValue( true );
298 
300 
301  if( m_footprint->IsLocked() )
302  m_AutoPlaceCtrl->SetSelection( 2 );
303  else if( m_footprint->PadsLocked() )
304  m_AutoPlaceCtrl->SetSelection( 1 );
305  else
306  m_AutoPlaceCtrl->SetSelection( 0 );
307 
308  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
309  "can arbitrarily select and edit component's pads." ) );
310  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
311  "its pads cannot be selected or edited." ) );
312  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
313  "auto placed." ) );
314 
317 
319  m_componentType->SetSelection( 0 );
320  else if( m_footprint->GetAttributes() & MOD_SMD )
321  m_componentType->SetSelection( 1 );
322  else
323  m_componentType->SetSelection( 2 );
324 
328 
329  // Local Clearances
330 
334 
335  // Prefer "-0" to "0" for normally negative values
337  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
338 
339  // Add solder paste margin ratio in percent
340  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
341  wxString msg;
342  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
343 
345  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
346  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
347  else
349 
350  switch( m_footprint->GetZoneConnection() )
351  {
352  default:
353  case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
354  case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
355  case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
356  case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
357  }
358 
359  // 3D Settings
360  m_shapes3D_list.clear();
361  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
362 
363  wxString origPath, alias, shortPath;
364  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
365 
366  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
367  {
368  m_shapes3D_list.push_back( model );
369  origPath = model.m_Filename;
370 
371  if( res && res->SplitAlias( origPath, alias, shortPath ) )
372  origPath = alias + wxT( ":" ) + shortPath;
373 
374  m_modelsGrid->AppendRows( 1 );
375  int row = m_modelsGrid->GetNumberRows() - 1;
376  m_modelsGrid->SetCellValue( row, 0, origPath );
377  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
378  }
379 
380  select3DModel( 0 ); // will clamp idx within bounds
382 
383  // Show the footprint's FPID.
384  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
385 
386  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
387  {
388  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
389  false ) );
390  // Adjust the column size. The column 6 has a small bitmap, so its width must be
391  // taken in account
392  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
393 
394  if( col == 6 )
395  col_size += 20;
396 
397  if( m_itemsGrid->IsColShown( col ) )
398  m_itemsGrid->SetColSize( col, col_size );
399  }
400 
401  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
402  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
403 
404  Layout();
405  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
406 
407  return true;
408 }
409 
410 
412 {
413  m_inSelect = true;
414 
415  aModelIdx = std::max( 0, aModelIdx );
416  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
417 
418  if( m_modelsGrid->GetNumberRows() )
419  {
420  m_modelsGrid->SelectRow( aModelIdx );
421  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
422  }
423 
424  m_PreviewPane->SetSelectedModel( aModelIdx );
425 
426  m_inSelect = false;
427 }
428 
429 
431 {
432  if( !m_inSelect )
433  select3DModel( aEvent.GetRow() );
434 }
435 
436 
438 {
439  if( aEvent.GetCol() == 0 )
440  {
441  bool hasAlias = false;
442  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
443  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
444 
445  filename.Replace( "\n", "" );
446  filename.Replace( "\r", "" );
447  filename.Replace( "\t", "" );
448 
449  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
450  {
451  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
453  m_delayedFocusRow = aEvent.GetRow();
454  m_delayedFocusColumn = aEvent.GetCol();
455  aEvent.Veto();
456  }
457 
458  // if the user has specified an alias in the name then prepend ':'
459  if( hasAlias )
460  filename.insert( 0, wxT( ":" ) );
461 
462 #ifdef __WINDOWS__
463  // In Kicad files, filenames and paths are stored using Unix notation
464  filename.Replace( wxT( "\\" ), wxT( "/" ) );
465 #endif
466 
467  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
468  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
469  }
470  else if( aEvent.GetCol() == 1 )
471  {
472  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
473 
474  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
475  }
476 
478 }
479 
480 
482 {
483  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
484 
485  int idx = m_modelsGrid->GetGridCursorRow();
486 
487  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
488  {
489  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
490  m_modelsGrid->DeleteRows( idx, 1 );
491 
492  select3DModel( idx ); // will clamp idx within bounds
494  }
495 }
496 
497 
499 {
501  return;
502 
503  int selected = m_modelsGrid->GetGridCursorRow();
504 
505  PROJECT& prj = Prj();
506  MODULE_3D_SETTINGS model;
507 
508  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
509  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
510  int filter = 0;
511 
512  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
513  // variable and fall back to the project path if necessary.
514  if( initialpath.IsEmpty() )
515  {
516  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
517  initialpath = prj.GetProjectPath();
518  }
519 
520  if( !sidx.empty() )
521  {
522  long tmp;
523  sidx.ToLong( &tmp );
524 
525  if( tmp > 0 && tmp <= INT_MAX )
526  filter = (int) tmp;
527  }
528 
529  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
530  || model.m_Filename.empty() )
531  {
532  select3DModel( selected );
533  return;
534  }
535 
536  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
537  sidx = wxString::Format( wxT( "%i" ), filter );
539  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
540  wxString alias;
541  wxString shortPath;
542  wxString filename = model.m_Filename;
543 
544  if( res && res->SplitAlias( filename, alias, shortPath ) )
545  filename = alias + wxT( ":" ) + shortPath;
546 
547 #ifdef __WINDOWS__
548  // In KiCad files, filenames and paths are stored using Unix notation
549  model.m_Filename.Replace( "\\", "/" );
550 #endif
551 
552  model.m_Show = true;
553  m_shapes3D_list.push_back( model );
554 
555  int idx = m_modelsGrid->GetNumberRows();
556  m_modelsGrid->AppendRows( 1 );
557  m_modelsGrid->SetCellValue( idx, 0, filename );
558  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
559 
560  select3DModel( idx );
562 }
563 
564 
566 {
568  return;
569 
570  MODULE_3D_SETTINGS model;
571 
572  model.m_Show = true;
573  m_shapes3D_list.push_back( model );
574 
575  int row = m_modelsGrid->GetNumberRows();
576  m_modelsGrid->AppendRows( 1 );
577  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
578 
579  select3DModel( row );
580 
581  m_modelsGrid->SetFocus();
582  m_modelsGrid->MakeCellVisible( row, 0 );
583  m_modelsGrid->SetGridCursor( row, 0 );
584 
585  m_modelsGrid->EnableCellEditControl( true );
586  m_modelsGrid->ShowCellEditControl();
587 }
588 
589 
591 {
593  return false;
594 
595  if( !DIALOG_SHIM::Validate() )
596  return false;
597 
598  // Check for empty texts.
599  for( size_t i = 2; i < m_texts->size(); ++i )
600  {
601  TEXTE_MODULE& text = m_texts->at( i );
602 
603  if( text.GetText().IsEmpty() )
604  {
605  if( m_NoteBook->GetSelection() != 0 )
606  m_NoteBook->SetSelection( 0 );
607 
609  m_delayedErrorMessage = _( "Text items must have some content." );
611  m_delayedFocusRow = i;
612 
613  return false;
614  }
615  }
616 
617  if( !m_netClearance.Validate( 0, INT_MAX ) )
618  return false;
619 
620  return true;
621 }
622 
623 
625 {
626  if( !Validate() )
627  return false;
628 
629  if( !DIALOG_SHIM::TransferDataFromWindow() )
630  return false;
631 
632  if( !m_PanelGeneral->TransferDataFromWindow() )
633  return false;
634 
635  if( !m_Panel3D->TransferDataFromWindow() )
636  return false;
637 
638  auto view = m_frame->GetCanvas()->GetView();
639  BOARD_COMMIT commit( m_frame );
640  commit.Modify( m_footprint );
641 
642  // copy reference and value
643  m_footprint->Reference() = m_texts->at( 0 );
644  m_footprint->Value() = m_texts->at( 1 );
645 
646  size_t i = 2;
647 
648  for( auto item : m_footprint->GraphicalItems() )
649  {
650  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
651 
652  if( textModule )
653  {
654  // copy grid table entries till we run out, then delete any remaining texts
655  if( i < m_texts->size() )
656  *textModule = m_texts->at( i++ );
657  else
658  textModule->DeleteStructure();
659  }
660  }
661 
662  // if there are still grid table entries, create new texts for them
663  while( i < m_texts->size() )
664  {
665  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
666  m_footprint->Add( newText, ADD_MODE::APPEND );
667  view->Add( newText );
668  }
669 
670  // Initialize masks clearances
674 
675  double dtmp = 0.0;
676  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
677  msg.ToDouble( &dtmp );
678 
679  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
680  if( dtmp < -50.0 )
681  dtmp = -50.0;
682  // A margin ratio is always <= 0
683  // 0 means use full pad copper area
684  if( dtmp > 0.0 )
685  dtmp = 0.0;
686 
688 
689  switch( m_ZoneConnectionChoice->GetSelection() )
690  {
691  default:
696  }
697 
698  // Set Module Position
699  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
700  m_footprint->SetPosition( modpos );
701  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
702  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
703 
704  int attributes = 0;
705 
706  switch( m_componentType->GetSelection() )
707  {
708  case 0: attributes |= MOD_THROUGH_HOLE; break;
709  case 1: attributes |= MOD_SMD; break;
710  default: break;
711  }
712 
713  if( m_boardOnly->GetValue() )
714  attributes |= MOD_BOARD_ONLY;
715 
716  if( m_excludeFromPosFiles->GetValue() )
717  attributes |= MOD_EXCLUDE_FROM_POS_FILES;
718 
719  if( m_excludeFromBOM->GetValue() )
720  attributes |= MOD_EXCLUDE_FROM_BOM;
721 
722  m_footprint->SetAttributes( attributes );
723 
726 
727  // Now, set orientation. Must be done after other changes because rotation changes field
728  // positions on board (so that relative positions are held constant)
729  m_OrientValidator.TransferFromWindow();
730 
731  int orient = KiROUND( m_OrientValue * 10.0 );
732 
733  if( m_footprint->GetOrientation() != orient )
735 
736  // Set component side, that also have effect on the fields positions on board
737  bool change_layer = false;
738  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
739  {
740  if( m_footprint->GetLayer() == B_Cu )
741  change_layer = true;
742  }
743  else if( m_footprint->GetLayer() == F_Cu )
744  change_layer = true;
745 
746  if( change_layer )
748 
749  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
750  draw3D->clear();
751  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
752 
754 
755  // This is a simple edit, we must create an undo entry
756  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
757  commit.Push( _( "Modify module properties" ) );
758 
759  SetReturnCode( PRM_EDITOR_EDIT_OK );
760  return true;
761 }
762 
763 
765 {
767  return;
768 
769  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
770  TEXTE_MODULE textMod( m_footprint );
771 
772  // Set active layer if legal; otherwise copy layer from previous text item
774  textMod.SetLayer( m_frame->GetActiveLayer() );
775  else
776  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
777 
778  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
779  textMod.SetTextThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
780  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
781  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
782  textMod.SetMirrored( IsBackLayer( textMod.GetLayer() ) );
783 
784  m_texts->push_back( textMod );
785 
786  // notify the grid
787  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
788  m_itemsGrid->ProcessTableMessage( msg );
789 
790  m_itemsGrid->SetFocus();
791  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
792  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
793 
794  m_itemsGrid->EnableCellEditControl( true );
795  m_itemsGrid->ShowCellEditControl();
796 }
797 
798 
800 {
801  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
802 
803  int curRow = m_itemsGrid->GetGridCursorRow();
804 
805  if( curRow < 0 )
806  return;
807  else if( curRow < 2 )
808  {
809  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
810  return;
811  }
812 
813  m_texts->erase( m_texts->begin() + curRow );
814 
815  // notify the grid
816  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
817  m_itemsGrid->ProcessTableMessage( msg );
818 
819  if( m_itemsGrid->GetNumberRows() > 0 )
820  {
821  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
822  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
823  }
824 }
825 
826 
828 {
829  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
831 }
832 
833 
835 {
836  // Account for scroll bars
837  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
838  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
839 
840  itemsWidth -= m_itemsGrid->GetRowLabelSize();
841 
842  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
843  itemsWidth -= m_itemsGrid->GetColSize( i );
844 
845  if( itemsWidth > 0 )
846  {
847  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
848  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
849  }
850 
851  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 );
852 }
853 
854 
856 {
857  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
858  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
859 
860  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
861  // even when the original validation was triggered from a killFocus event, and so
862  // that the corresponding notebook page can be shown in the background when triggered
863  // from an OK.
864  if( m_delayedFocusRow >= 0 )
865  {
866  // We will re-enter this routine if an error dialog is displayed, so make sure we
867  // zero out our member variables first.
868  wxGrid* grid = m_delayedFocusGrid;
869  int row = m_delayedFocusRow;
870  int col = m_delayedFocusColumn;
871  wxString msg = m_delayedErrorMessage;
872 
873  m_delayedFocusGrid = nullptr;
874  m_delayedFocusRow = -1;
876  m_delayedErrorMessage = wxEmptyString;
877 
878  if( !msg.IsEmpty() )
879  {
880  // Do not use DisplayErrorMessage(); it screws up window order on Mac
881  DisplayError( nullptr, msg );
882  }
883 
884  grid->SetFocus();
885  grid->MakeCellVisible( row, col );
886 
887  // Selecting the first grid item only makes sense for the
888  // items grid
889  if( !m_initialFocus || grid == m_itemsGrid )
890  {
891  grid->SetGridCursor( row, col );
892  grid->EnableCellEditControl( true );
893  grid->ShowCellEditControl();
894 
895  if( grid == m_itemsGrid && row == 0 && col == 0 )
896  {
897  auto referenceEditor = grid->GetCellEditor( 0, 0 );
898 
899  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
900  SelectReferenceNumber( textEntry );
901 
902  referenceEditor->DecRef();
903  }
904  }
905  m_initialFocus = false;
906  }
907 
908  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
909 }
910 
911 
912 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
913 {
914  adjustGridColumns( aEvent.GetSize().GetX());
915 
916  aEvent.Skip();
917 }
918 
919 
920 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnPageChange( wxNotebookEvent& aEvent )
921 {
922  int page = aEvent.GetSelection();
923 
924  // Shouldn't be necessary, but is on at least OSX
925  if( page >= 0 )
926  m_NoteBook->ChangeSelection( (unsigned) page );
927 
928 #ifdef __WXMAC__
929  // Work around an OSX bug where the wxGrid children don't get placed correctly until
930  // the first resize event
931  if( m_macHack[ page ] )
932  {
933  wxSize pageSize = m_NoteBook->GetPage( page )->GetSize();
934  pageSize.x -= 1;
935 
936  m_NoteBook->GetPage( page )->SetSize( pageSize );
937  m_macHack[ page ] = false;
938  }
939 #endif
940 }
941 
942 
944 {
946 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:188
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
void SetPlacementCost90(int aCost)
Definition: class_module.h:574
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
int GetAttributes() const
Definition: class_module.h:269
double GetOrientation() const
Definition: class_module.h:224
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:573
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:492
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
PROJECT holds project specific data.
Definition: project.h:61
void SetLocalClearance(int aClearance)
Definition: class_module.h:244
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:571
This file is part of the common library.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:127
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:376
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetItalic(bool isItalic)
Definition: eda_text.h:179
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:261
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
provides an extensible class to resolve 3D model paths.
bool m_Show
Include module in rendering.
Definition: class_module.h:98
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
void UpdateDummyModule(bool aRelaodRequired=true)
UpdateModelInfoList - copy shapes from the current shape list which are flagged for preview to the co...
const LIB_ID & GetFPID() const
Definition: class_module.h:228
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:238
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:65
DRAWINGS & GraphicalItems()
Definition: class_module.h:191
PCBNEW_SETTINGS * GetPcbNewSettings()
wxString m_FootprintTextShownColumns
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:789
int GetLocalSolderMaskMargin() const
Definition: class_module.h:240
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:124
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:258
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:236
bool GetTextUpright(PCB_LAYER_ID aLayer) const
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:96
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
wxString m_lastFootprint3dDir
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: common.cpp:312
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath)
Function SplitAlias returns true if the given name contains an alias and populates the string anAlias...
pads are covered by copper
int GetLocalClearance() const
Definition: class_module.h:243
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:237
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:491
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void On3DModelCellChanged(wxGridEvent &aEvent) override
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
wxFloatingPointValidator< double > m_OrientValidator
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:349
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
void SetPosition(const wxPoint &aPos) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180
void SetSelectedModel(int idx)
SetModelDataIdx - Sets the currently selected index in the model list so that the scale/rotation/offs...
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:311
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:241
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:254
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
const BITMAP_OPAQUE icon_modedit_xpm[1]
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:97
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:214
int GetPlacementCost180() const
Definition: class_module.h:570
EDA_UNITS m_units
Definition: dialog_shim.h:197
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:109
void OnOtherOrientation(wxCommandEvent &aEvent) override
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:255
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:229
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:257
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:214
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
void OnPageChange(wxNotebookEvent &event) override
see class PGM_BASE
Declaration of the eda_3d_viewer class.
void EditLibraryFootprint(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:321
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:260
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
PCB_EDIT_FRAME is the main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
Pads are not covered.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
bool PadsLocked() const
Definition: class_module.h:347
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:158
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Function SetOriginTransform Sets the current origin transform mode.
Definition: unit_binder.h:171
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
wxPoint GetPosition() const override
Definition: class_module.h:219
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Function ValidateName returns true if the given path is a valid aliased relative path.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
void updateOrientationControl()
Update the orientation validated control, without triggering a change event on the control (which wou...
DIALOG_FOOTPRINT_BOARD_EDITOR(PCB_EDIT_FRAME *aParent, MODULE *aModule)
void SetAttributes(int aAttributes)
Definition: class_module.h:270
int GetNumberRows() override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list