KiCad PCB EDA Suite
dialog_footprint_properties.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 <footprint.h>
32 #include <confirm.h>
34 #include <filename_resolver.h>
35 #include <pcb_edit_frame.h>
36 #include <pcbnew_settings.h>
37 #include <pgm_base.h>
38 #include <validators.h>
40 #include <widgets/text_ctrl_eval.h>
41 #include <widgets/wx_grid.h>
43 
46 
48 
49 
50 int DIALOG_FOOTPRINT_PROPERTIES::m_page = 0; // remember the last open page during session
51 
52 
54  FOOTPRINT* aFootprint ) :
56  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
57  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
58  m_OrientValidator( 3, &m_OrientValue ),
59  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
60  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
61  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
62  m_initialFocus( true ),
63  m_inSelect( false )
64 {
65  m_frame = aParent;
66  m_footprint = aFootprint;
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( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir );
105  }
106 
107  wxGridCellAttr* attr = new wxGridCellAttr;
108  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &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( small_trash_xpm ) );
172  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
173  m_buttonBrowse->SetBitmap( KiBitmap( small_folder_xpm ) );
174  m_buttonRemove->SetBitmap( KiBitmap( small_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 {
206  if( TransferDataFromWindow() )
207  {
209  Close();
210  }
211 }
212 
213 
215 {
216  if( TransferDataFromWindow() )
217  {
219  Close();
220  }
221 }
222 
223 
225 {
226  if( TransferDataFromWindow() )
227  {
229  Close();
230  }
231 }
232 
233 
235 {
236  if( TransferDataFromWindow() )
237  {
239  Close();
240  }
241 }
242 
243 
245 {
246  if( m_Orient0->GetValue() )
247  m_OrientValue = 0.0;
248  else if( m_Orient90->GetValue() )
249  m_OrientValue = 90.0;
250  else if( m_Orient270->GetValue() )
251  m_OrientValue = 270.0;
252  else if( m_Orient180->GetValue() )
253  m_OrientValue = 180.0;
254 
256 }
257 
258 
260 {
261  m_OrientOther->SetValue( true );
262 
263  aEvent.Skip();
264 }
265 
266 
267 bool allPadsLocked( FOOTPRINT* aFootprint )
268 {
269  for( PAD* pad : aFootprint->Pads() )
270  {
271  if( !pad->IsLocked() )
272  return false;
273  }
274 
275  return true;
276 }
277 
278 
280 {
281  if( !wxDialog::TransferDataToWindow() )
282  return false;
283 
284  if( !m_PanelGeneral->TransferDataToWindow() )
285  return false;
286 
287  if( !m_Panel3D->TransferDataToWindow() )
288  return false;
289 
290  // Footprint Texts
291 
292  m_texts->push_back( m_footprint->Reference() );
293  m_texts->push_back( m_footprint->Value() );
294 
295  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
296  {
297  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
298 
299  if( textItem )
300  m_texts->push_back( *textItem );
301  }
302 
303  // notify the grid
304  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
305  m_itemsGrid->ProcessTableMessage( tmsg );
306 
307  // Footprint Properties
308 
311 
312  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
313 
315 
316  if( m_OrientValue == 0.0 )
317  m_Orient0->SetValue( true );
318  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
319  m_Orient90->SetValue( true );
320  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
321  m_Orient270->SetValue( true );
322  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
323  m_Orient180->SetValue( true );
324  else
325  m_OrientOther->SetValue( true );
326 
328 
329  if( m_footprint->IsLocked() )
330  m_AutoPlaceCtrl->SetSelection( 2 );
331  else if( allPadsLocked( m_footprint ) )
332  m_AutoPlaceCtrl->SetSelection( 1 );
333  else
334  m_AutoPlaceCtrl->SetSelection( 0 );
335 
336  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Footprint can be freely moved and oriented on the "
337  "canvas. At least some of the footprint's pads are "
338  "unlocked and can be moved with respect to the "
339  "footprint." ) );
340  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Footprint can be freely moved and oriented on the "
341  "canvas, but all of its pads are locked with respect "
342  "to their position within in the footprint." ) );
343  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Footprint is locked: it cannot be freely moved and "
344  "oriented on the canvas and can only be selected when "
345  "the 'Locked items' checkbox is enabled in the "
346  "selection filter." ) );
347 
350 
352  m_componentType->SetSelection( 0 );
353  else if( m_footprint->GetAttributes() & FP_SMD )
354  m_componentType->SetSelection( 1 );
355  else
356  m_componentType->SetSelection( 2 );
357 
361 
362  // Local Clearances
363 
367 
368  // Prefer "-0" to "0" for normally negative values
370  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
371 
372  // Add solder paste margin ratio in percent
373  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
374  wxString msg;
375  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
376 
378  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
379  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
380  else
382 
383  switch( m_footprint->GetZoneConnection() )
384  {
385  default:
386  case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
387  case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
388  case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
389  case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
390  }
391 
392  // 3D Settings
393  m_shapes3D_list.clear();
394  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
395 
396  wxString origPath, alias, shortPath;
397  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
398 
399  for( const FP_3DMODEL& model : m_footprint->Models() )
400  {
401  m_shapes3D_list.push_back( model );
402  origPath = model.m_Filename;
403 
404  if( res && res->SplitAlias( origPath, alias, shortPath ) )
405  origPath = alias + wxT( ":" ) + shortPath;
406 
407  m_modelsGrid->AppendRows( 1 );
408  int row = m_modelsGrid->GetNumberRows() - 1;
409  m_modelsGrid->SetCellValue( row, 0, origPath );
410  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
411  }
412 
413  select3DModel( 0 ); // will clamp idx within bounds
415 
416  // Show the footprint's FPID.
417  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
418 
419  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
420  {
421  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
422  false ) );
423  // Adjust the column size.
424  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
425 
426  if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
427  {
428  BOARD* board = m_footprint->GetBoard();
429 
430  for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
431  col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
432 
433  // And the swatch:
434  col_size += 20;
435  }
436 
437  if( m_itemsGrid->IsColShown( col ) )
438  m_itemsGrid->SetColSize( col, col_size );
439  }
440 
441  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
442  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
443 
444  Layout();
445  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
446 
447  return true;
448 }
449 
450 
452 {
453  m_inSelect = true;
454 
455  aModelIdx = std::max( 0, aModelIdx );
456  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
457 
458  if( m_modelsGrid->GetNumberRows() )
459  {
460  m_modelsGrid->SelectRow( aModelIdx );
461  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
462  }
463 
464  m_PreviewPane->SetSelectedModel( aModelIdx );
465 
466  m_inSelect = false;
467 }
468 
469 
471 {
472  if( !m_inSelect )
473  select3DModel( aEvent.GetRow() );
474 }
475 
476 
478 {
479  if( aEvent.GetCol() == 0 )
480  {
481  bool hasAlias = false;
482  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
483  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
484 
485  filename.Replace( "\n", "" );
486  filename.Replace( "\r", "" );
487  filename.Replace( "\t", "" );
488 
489  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
490  {
491  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
493  m_delayedFocusRow = aEvent.GetRow();
494  m_delayedFocusColumn = aEvent.GetCol();
495  aEvent.Veto();
496  }
497 
498  // if the user has specified an alias in the name then prepend ':'
499  if( hasAlias )
500  filename.insert( 0, wxT( ":" ) );
501 
502 #ifdef __WINDOWS__
503  // In Kicad files, filenames and paths are stored using Unix notation
504  filename.Replace( wxT( "\\" ), wxT( "/" ) );
505 #endif
506 
507  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
508  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
509  }
510  else if( aEvent.GetCol() == 1 )
511  {
512  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
513 
514  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
515  }
516 
518 }
519 
520 
522 {
523  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
524 
525  int idx = m_modelsGrid->GetGridCursorRow();
526 
527  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
528  {
529  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
530  m_modelsGrid->DeleteRows( idx, 1 );
531 
532  select3DModel( idx ); // will clamp idx within bounds
534  }
535 }
536 
537 
539 {
541  return;
542 
543  int selected = m_modelsGrid->GetGridCursorRow();
544 
545  PROJECT& prj = Prj();
546  FP_3DMODEL model;
547 
548  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
549  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
550  int filter = 0;
551 
552  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment
553  // variable and fall back to the project path if necessary.
554  if( initialpath.IsEmpty() )
555  {
556  if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() )
557  initialpath = prj.GetProjectPath();
558  }
559 
560  if( !sidx.empty() )
561  {
562  long tmp;
563  sidx.ToLong( &tmp );
564 
565  if( tmp > 0 && tmp <= INT_MAX )
566  filter = (int) tmp;
567  }
568 
569  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
570  || model.m_Filename.empty() )
571  {
572  select3DModel( selected );
573  return;
574  }
575 
576  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
577  sidx = wxString::Format( wxT( "%i" ), filter );
579  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
580  wxString alias;
581  wxString shortPath;
582  wxString filename = model.m_Filename;
583 
584  if( res && res->SplitAlias( filename, alias, shortPath ) )
585  filename = alias + wxT( ":" ) + shortPath;
586 
587 #ifdef __WINDOWS__
588  // In KiCad files, filenames and paths are stored using Unix notation
589  model.m_Filename.Replace( "\\", "/" );
590 #endif
591 
592  model.m_Show = true;
593  m_shapes3D_list.push_back( model );
594 
595  int idx = m_modelsGrid->GetNumberRows();
596  m_modelsGrid->AppendRows( 1 );
597  m_modelsGrid->SetCellValue( idx, 0, filename );
598  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
599 
600  select3DModel( idx );
602 }
603 
604 
606 {
608  return;
609 
610  FP_3DMODEL model;
611 
612  model.m_Show = true;
613  m_shapes3D_list.push_back( model );
614 
615  int row = m_modelsGrid->GetNumberRows();
616  m_modelsGrid->AppendRows( 1 );
617  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
618 
619  select3DModel( row );
620 
621  m_modelsGrid->SetFocus();
622  m_modelsGrid->MakeCellVisible( row, 0 );
623  m_modelsGrid->SetGridCursor( row, 0 );
624 
625  m_modelsGrid->EnableCellEditControl( true );
626  m_modelsGrid->ShowCellEditControl();
627 }
628 
629 
631 {
633  return false;
634 
635  if( !DIALOG_SHIM::Validate() )
636  return false;
637 
638  // Check for empty texts.
639  for( size_t i = 2; i < m_texts->size(); ++i )
640  {
641  FP_TEXT& text = m_texts->at( i );
642 
643  if( text.GetText().IsEmpty() )
644  {
645  if( m_NoteBook->GetSelection() != 0 )
646  m_NoteBook->SetSelection( 0 );
647 
649  m_delayedErrorMessage = _( "Text items must have some content." );
651  m_delayedFocusRow = i;
652 
653  return false;
654  }
655  }
656 
657  if( !m_netClearance.Validate( 0, INT_MAX ) )
658  return false;
659 
660  return true;
661 }
662 
663 
665 {
666  if( !Validate() )
667  return false;
668 
670  return false;
671 
673  return false;
674 
675  auto view = m_frame->GetCanvas()->GetView();
676  BOARD_COMMIT commit( m_frame );
677  commit.Modify( m_footprint );
678 
679  // copy reference and value
680  m_footprint->Reference() = m_texts->at( 0 );
681  m_footprint->Value() = m_texts->at( 1 );
682 
683  size_t i = 2;
684 
685  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
686  {
687  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
688 
689  if( textItem )
690  {
691  // copy grid table entries till we run out, then delete any remaining texts
692  if( i < m_texts->size() )
693  *textItem = m_texts->at( i++ );
694  else
695  textItem->DeleteStructure();
696  }
697  }
698 
699  // if there are still grid table entries, create new texts for them
700  while( i < m_texts->size() )
701  {
702  auto newText = new FP_TEXT( m_texts->at( i++ ) );
703  m_footprint->Add( newText, ADD_MODE::APPEND );
704  view->Add( newText );
705  }
706 
707  // Initialize masks clearances
711 
712  double dtmp = 0.0;
713  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
714  msg.ToDouble( &dtmp );
715 
716  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
717  if( dtmp < -50.0 )
718  dtmp = -50.0;
719  // A margin ratio is always <= 0
720  // 0 means use full pad copper area
721  if( dtmp > 0.0 )
722  dtmp = 0.0;
723 
725 
726  switch( m_ZoneConnectionChoice->GetSelection() )
727  {
728  default:
733  }
734 
735  // Set Footprint Position
736  wxPoint pos( m_posX.GetValue(), m_posY.GetValue() );
737  m_footprint->SetPosition( pos );
738  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
739 
740  if( m_AutoPlaceCtrl->GetSelection() == 1 )
741  {
742  for( PAD* pad : m_footprint->Pads() )
743  pad->SetLocked( true );
744  }
745 
746  int attributes = 0;
747 
748  switch( m_componentType->GetSelection() )
749  {
750  case 0: attributes |= FP_THROUGH_HOLE; break;
751  case 1: attributes |= FP_SMD; break;
752  default: break;
753  }
754 
755  if( m_boardOnly->GetValue() )
756  attributes |= FP_BOARD_ONLY;
757 
758  if( m_excludeFromPosFiles->GetValue() )
759  attributes |= FP_EXCLUDE_FROM_POS_FILES;
760 
761  if( m_excludeFromBOM->GetValue() )
762  attributes |= FP_EXCLUDE_FROM_BOM;
763 
764  m_footprint->SetAttributes( attributes );
765 
768 
769  // Now, set orientation. Must be done after other changes because rotation changes field
770  // positions on board (so that relative positions are held constant)
771  m_OrientValidator.TransferFromWindow();
772 
773  double orient = m_OrientValue * 10;
774 
775  if( m_footprint->GetOrientation() != orient )
777 
778  // Set component side, that also have effect on the fields positions on board
779  bool change_layer = false;
780  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
781  {
782  if( m_footprint->GetLayer() == B_Cu )
783  change_layer = true;
784  }
785  else if( m_footprint->GetLayer() == F_Cu )
786  change_layer = true;
787 
788  if( change_layer )
790 
791  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
792  draw3D->clear();
793  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
794 
795  // This is a simple edit, we must create an undo entry
796  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
797  commit.Push( _( "Modify footprint properties" ) );
798 
800  return true;
801 }
802 
803 
805 {
807  return;
808 
809  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
810  FP_TEXT textItem( m_footprint );
811 
812  // Set active layer if legal; otherwise copy layer from previous text item
814  textItem.SetLayer( m_frame->GetActiveLayer() );
815  else
816  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
817 
818  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
819  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
820  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
821  textItem.SetKeepUpright( dsnSettings.GetTextUpright( textItem.GetLayer() ) );
822  textItem.SetMirrored( IsBackLayer( textItem.GetLayer() ) );
823 
824  m_texts->push_back( textItem );
825 
826  // notify the grid
827  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
828  m_itemsGrid->ProcessTableMessage( msg );
829 
830  m_itemsGrid->SetFocus();
831  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
832  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
833 
834  m_itemsGrid->EnableCellEditControl( true );
835  m_itemsGrid->ShowCellEditControl();
836 }
837 
838 
840 {
841  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
842 
843  int curRow = m_itemsGrid->GetGridCursorRow();
844 
845  if( curRow < 0 )
846  return;
847  else if( curRow < 2 )
848  {
849  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
850  return;
851  }
852 
853  m_texts->erase( m_texts->begin() + curRow );
854 
855  // notify the grid
856  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
857  m_itemsGrid->ProcessTableMessage( msg );
858 
859  if( m_itemsGrid->GetNumberRows() > 0 )
860  {
861  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
862  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
863  }
864 }
865 
866 
868 {
869  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
871 }
872 
873 
875 {
876  // Account for scroll bars
877  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
878  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
879 
880  itemsWidth -= m_itemsGrid->GetRowLabelSize();
881 
882  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
883  itemsWidth -= m_itemsGrid->GetColSize( i );
884 
885  if( itemsWidth > 0 )
886  {
887  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
888  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
889  }
890 
891  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 );
892 }
893 
894 
896 {
897  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
898  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
899 
900  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
901  // even when the original validation was triggered from a killFocus event, and so
902  // that the corresponding notebook page can be shown in the background when triggered
903  // from an OK.
904  if( m_delayedFocusRow >= 0 )
905  {
906  // We will re-enter this routine if an error dialog is displayed, so make sure we
907  // zero out our member variables first.
908  wxGrid* grid = m_delayedFocusGrid;
909  int row = m_delayedFocusRow;
910  int col = m_delayedFocusColumn;
911  wxString msg = m_delayedErrorMessage;
912 
913  m_delayedFocusGrid = nullptr;
914  m_delayedFocusRow = -1;
916  m_delayedErrorMessage = wxEmptyString;
917 
918  if( !msg.IsEmpty() )
919  {
920  // Do not use DisplayErrorMessage(); it screws up window order on Mac
921  DisplayError( nullptr, msg );
922  }
923 
924  grid->SetFocus();
925  grid->MakeCellVisible( row, col );
926 
927  // Selecting the first grid item only makes sense for the
928  // items grid
929  if( !m_initialFocus || grid == m_itemsGrid )
930  {
931  grid->SetGridCursor( row, col );
932  grid->EnableCellEditControl( true );
933  grid->ShowCellEditControl();
934 
935  if( grid == m_itemsGrid && row == 0 && col == 0 )
936  {
937  auto referenceEditor = grid->GetCellEditor( 0, 0 );
938 
939  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
940  KIUI::SelectReferenceNumber( textEntry );
941 
942  referenceEditor->DecRef();
943  }
944  }
945  m_initialFocus = false;
946  }
947 
948  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
949 }
950 
951 
952 void DIALOG_FOOTPRINT_PROPERTIES::OnGridSize( wxSizeEvent& aEvent )
953 {
954  adjustGridColumns( aEvent.GetSize().GetX() );
955 
956  aEvent.Skip();
957 }
958 
959 
960 void DIALOG_FOOTPRINT_PROPERTIES::OnPageChange( wxNotebookEvent& aEvent )
961 {
962  int page = aEvent.GetSelection();
963 
964  // Shouldn't be necessary, but is on at least OSX
965  if( page >= 0 )
966  m_NoteBook->ChangeSelection( (unsigned) page );
967 
968 #ifdef __WXMAC__
969  // Work around an OSX bug where the wxGrid children don't get placed correctly until
970  // the first resize event
971  if( m_macHack[ page ] )
972  {
973  wxSize pageSize = m_NoteBook->GetPage( page )->GetSize();
974  pageSize.x -= 1;
975 
976  m_NoteBook->GetPage( page )->SetSize( pageSize );
977  m_macHack[ page ] = false;
978  }
979 #endif
980 }
981 
982 
984 {
986 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
bool IsLocked() const override
Definition: footprint.h:279
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: ui_common.cpp:102
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
Container for project specific data.
Definition: project.h:62
std::list< FP_3DMODEL > & Models()
Definition: footprint.h:178
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: footprint.h:222
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void OnAddField(wxCommandEvent &) override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
int GetPlacementCost180() const
Definition: footprint.h:531
const BITMAP_OPAQUE small_folder_xpm[1]
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:129
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:376
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
int GetNumberRows() override
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:186
void OnUpdateUI(wxUpdateUIEvent &) override
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:52
double GetOrientation() const
Definition: footprint.h:186
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:113
void On3DModelSelected(wxGridEvent &) override
Class DIALOG_FOOTPRINT_PROPERTIES_BASE.
void OnAdd3DModel(wxCommandEvent &) override
void FootprintOrientEvent(wxCommandEvent &) override
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: footprint.h:220
wxFloatingPointValidator< double > m_OrientValidator
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:447
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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
wxString m_FootprintTextShownColumns
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
virtual const wxString GetProjectPath() const
Return the full path of the project.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
void OnDeleteField(wxCommandEvent &) override
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
void UpdateDummyFootprint(bool aRelaodRequired=true)
Copy shapes from the current shape list which are flagged for preview to the copy of footprint that i...
void SetAttributes(int aAttributes)
Definition: footprint.h:232
PADS & Pads()
Definition: footprint.h:164
void SetPlacementCost180(int aCost)
Definition: footprint.h:532
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:238
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:459
bool GetTextUpright(PCB_LAYER_ID aLayer) const
FP_TEXT & Reference()
Definition: footprint.h:460
void EditLibraryFootprint(wxCommandEvent &) override
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:97
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:82
wxString m_lastFootprint3dDir
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath)
Return true if the given name contains an alias and populates the string anAlias with the alias and a...
bool m_Show
Include model in rendering.
Definition: footprint.h:98
PCB_LAYER_ID
A quick note on layer IDs:
pads are covered by copper
void Cfg3DPath(wxCommandEvent &) override
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:207
void OnOtherOrientation(wxCommandEvent &aEvent) override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1366
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
void SetLocalClearance(int aClearance)
Definition: footprint.h:206
int GetLocalClearance() const
Definition: footprint.h:205
DRAWINGS & GraphicalItems()
Definition: footprint.h:167
const LIB_ID & GetFPID() const
Definition: footprint.h:190
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
Definition: footprint.cpp:1341
void SetSelectedModel(int idx)
Set the currently selected index in the model list so that the scale/rotation/offset controls can be ...
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
const BITMAP_OPAQUE small_trash_xpm[1]
Definition: small_trash.cpp:23
UTF8 Format() const
Definition: lib_id.cpp:233
const BITMAP_OPAQUE icon_modedit_xpm[1]
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString m_Filename
The 3D shape filename in 3D library.
Definition: footprint.h:97
EDA_UNITS m_units
Definition: dialog_shim.h:199
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:110
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:115
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
int GetLocalSolderMaskMargin() const
Definition: footprint.h:202
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
see class PGM_BASE
Provide an extensible class to resolve 3D model paths.
Declaration of the eda_3d_viewer class.
int GetAttributes() const
Definition: footprint.h:231
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
std::vector< FP_3DMODEL > m_shapes3D_list
void OnRemove3DModel(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Set the #MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: footprint.h:289
The main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
Pads are not covered.
wxPoint GetPosition() const override
Definition: footprint.h:182
double GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:219
virtual long long int GetValue()
Return the current value in Internal Units.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
DIALOG_FOOTPRINT_PROPERTIES(PCB_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
void OnAdd3DRow(wxCommandEvent &) override
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
ZONE_CONNECTION GetZoneConnection() const
Definition: footprint.h:223
int GetPlacementCost90() const
Definition: footprint.h:534
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:173
void UpdateFootprint(wxCommandEvent &) override
int GetLocalSolderPasteMargin() const
Definition: footprint.h:216
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:467
Definition: pad.h:60
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1437
bool allPadsLocked(FOOTPRINT *aFootprint)
void OnPageChange(wxNotebookEvent &event) override
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Returns true if the given path is a valid aliased relative path.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
void On3DModelCellChanged(wxGridEvent &aEvent) override
void updateOrientationControl()
Update the orientation validated control, without triggering a change event on the control (which wou...
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:18
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
void SetPlacementCost90(int aCost)
Definition: footprint.h:535
void EditFootprint(wxCommandEvent &) override
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:203
void ChangeFootprint(wxCommandEvent &) override
void OnGridSize(wxSizeEvent &aEvent) override
Container for design settings for a BOARD object.
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:217