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>
33 #include <dialog_text_entry.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;
67 
68  // Configure display origin transforms
71 
72  for( size_t i = 0; i < m_NoteBook->GetPageCount(); ++i )
73  m_macHack.push_back( true );
74 
76 
77  m_delayedErrorMessage = wxEmptyString;
78  m_delayedFocusGrid = nullptr;
79  m_delayedFocusRow = -1;
81 
82  // Give an icon
83  wxIcon icon;
84  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
85  SetIcon( icon );
86 
87  // Give a bit more room for combobox editors
88  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
89  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
90 
92  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
93  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
94 
95  // Show/hide text item columns according to the user's preference
97 
98  // Set up the 3D models grid
99  // Path selector
100  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
101  if( cfg->m_lastFootprint3dDir.IsEmpty() )
102  {
103  wxGetEnv( KISYS3DMOD, &cfg->m_lastFootprint3dDir );
104  }
105 
106  wxGridCellAttr* attr = new wxGridCellAttr;
107  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
108  true, Prj().GetProjectPath() ) );
109  m_modelsGrid->SetColAttr( 0, attr );
110 
111  // Show checkbox
112  attr = new wxGridCellAttr;
113  attr->SetRenderer( new wxGridCellBoolRenderer() );
114  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
115  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
116  m_modelsGrid->SetColAttr( 1, attr );
117  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
118  m_modelsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
119 
120  m_OrientValidator.SetRange( -360.0, 360.0 );
121  m_OrientValueCtrl->SetValidator( m_OrientValidator );
123 
124  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
125 
127 
128  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
129 
130  // Set font size for items showing long strings:
131  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
132  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
133 #if __WXMAC__
134  m_allow90Label->SetFont( infoFont );
135  m_allow180Label->SetFont( infoFont );
136 #endif
137  m_staticTextInfoCopper->SetFont( infoFont );
138  m_staticTextInfoPaste->SetFont( infoFont );
139 
140  m_libraryIDLabel->SetFont( infoFont );
141  m_tcLibraryID->SetFont( infoFont );
142 
143  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
144  m_staticTextInfoValNeg->SetFont( infoFont );
145  m_staticTextInfoValPos->SetFont( infoFont );
146 
147  m_NoteBook->SetSelection( m_page );
148 
149  if( m_page == 0 )
150  {
152  m_delayedFocusRow = 0;
154  }
155  else if ( m_page == 1 )
157  else
158  {
160  m_delayedFocusRow = 0;
162  }
163 
164  m_sdbSizerStdButtonsOK->SetDefault();
165 
166  m_OrientValue = 0;
167 
168  // Configure button logos
169  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
170  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
171  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
172  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
173  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
174 
176 }
177 
178 
180 {
182  m_itemsGrid->GetShownColumns().ToStdString();
183 
184  // Prevents crash bug in wxGrid's d'tor
186 
187  // Delete the GRID_TRICKS.
188  m_itemsGrid->PopEventHandler( true );
189  m_modelsGrid->PopEventHandler( true );
190 
191  // free the memory used by all models, otherwise models which were
192  // browsed but not used would consume memory
193  Prj().Get3DCacheManager()->FlushCache( false );
194 
195  // the GL canvas has to be visible before it is destroyed
196  m_page = m_NoteBook->GetSelection();
197  m_NoteBook->SetSelection( 1 );
198 
199  delete m_PreviewPane;
200 }
201 
202 
204 {
205  EndModal( FP_PROPS_EDIT_BOARD_FP );
206 }
207 
208 
210 {
211  EndModal( FP_PROPS_EDIT_LIBRARY_FP );
212 }
213 
214 
216 {
217  EndModal( FP_PROPS_UPDATE_FP );
218 }
219 
220 
222 {
223  EndModal( FP_PROPS_CHANGE_FP );
224 }
225 
226 
228 {
229  if( m_Orient0->GetValue() )
230  m_OrientValue = 0.0;
231  else if( m_Orient90->GetValue() )
232  m_OrientValue = 90.0;
233  else if( m_Orient270->GetValue() )
234  m_OrientValue = 270.0;
235  else if( m_Orient180->GetValue() )
236  m_OrientValue = 180.0;
237 
239 }
240 
241 
243 {
244  m_OrientOther->SetValue( true );
245 
246  aEvent.Skip();
247 }
248 
249 
251 {
252  if( !wxDialog::TransferDataToWindow() )
253  return false;
254 
255  if( !m_PanelGeneral->TransferDataToWindow() )
256  return false;
257 
258  if( !m_Panel3D->TransferDataToWindow() )
259  return false;
260 
261  // Footprint Texts
262 
263  m_texts->push_back( m_footprint->Reference() );
264  m_texts->push_back( m_footprint->Value() );
265 
266  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
267  {
268  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
269 
270  if( textItem )
271  m_texts->push_back( *textItem );
272  }
273 
274  // notify the grid
275  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
276  m_itemsGrid->ProcessTableMessage( tmsg );
277 
278  // Footprint Properties
279 
282 
283  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
284 
286 
287  if( m_OrientValue == 0.0 )
288  m_Orient0->SetValue( true );
289  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
290  m_Orient90->SetValue( true );
291  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
292  m_Orient270->SetValue( true );
293  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
294  m_Orient180->SetValue( true );
295  else
296  m_OrientOther->SetValue( true );
297 
299 
300  if( m_footprint->IsLocked() )
301  m_AutoPlaceCtrl->SetSelection( 2 );
302  else if( m_footprint->PadsLocked() )
303  m_AutoPlaceCtrl->SetSelection( 1 );
304  else
305  m_AutoPlaceCtrl->SetSelection( 0 );
306 
307  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
308  "can arbitrarily select and edit component's pads." ) );
309  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
310  "its pads cannot be edited." ) );
311  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
312  "auto placed, and can only be selected when the "
313  "\"Locked items\" checkbox is enabled in the "
314  "selection filter." ) );
315 
318 
320  m_componentType->SetSelection( 0 );
321  else if( m_footprint->GetAttributes() & FP_SMD )
322  m_componentType->SetSelection( 1 );
323  else
324  m_componentType->SetSelection( 2 );
325 
329 
330  // Local Clearances
331 
335 
336  // Prefer "-0" to "0" for normally negative values
338  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
339 
340  // Add solder paste margin ratio in percent
341  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
342  wxString msg;
343  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
344 
346  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
347  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
348  else
350 
351  switch( m_footprint->GetZoneConnection() )
352  {
353  default:
354  case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
355  case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
356  case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
357  case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
358  }
359 
360  // 3D Settings
361  m_shapes3D_list.clear();
362  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
363 
364  wxString origPath, alias, shortPath;
365  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
366 
367  for( const FP_3DMODEL& model : m_footprint->Models() )
368  {
369  m_shapes3D_list.push_back( model );
370  origPath = model.m_Filename;
371 
372  if( res && res->SplitAlias( origPath, alias, shortPath ) )
373  origPath = alias + wxT( ":" ) + shortPath;
374 
375  m_modelsGrid->AppendRows( 1 );
376  int row = m_modelsGrid->GetNumberRows() - 1;
377  m_modelsGrid->SetCellValue( row, 0, origPath );
378  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
379  }
380 
381  select3DModel( 0 ); // will clamp idx within bounds
383 
384  // Show the footprint's FPID.
385  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
386 
387  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
388  {
389  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
390  false ) );
391  // Adjust the column size. The column 6 has a small bitmap, so its width must be
392  // taken in account
393  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
394 
395  if( col == 6 )
396  col_size += 20;
397 
398  if( m_itemsGrid->IsColShown( col ) )
399  m_itemsGrid->SetColSize( col, col_size );
400  }
401 
402  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
403  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
404 
405  Layout();
406  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
407 
408  return true;
409 }
410 
411 
413 {
414  m_inSelect = true;
415 
416  aModelIdx = std::max( 0, aModelIdx );
417  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
418 
419  if( m_modelsGrid->GetNumberRows() )
420  {
421  m_modelsGrid->SelectRow( aModelIdx );
422  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
423  }
424 
425  m_PreviewPane->SetSelectedModel( aModelIdx );
426 
427  m_inSelect = false;
428 }
429 
430 
432 {
433  if( !m_inSelect )
434  select3DModel( aEvent.GetRow() );
435 }
436 
437 
439 {
440  if( aEvent.GetCol() == 0 )
441  {
442  bool hasAlias = false;
443  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
444  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
445 
446  filename.Replace( "\n", "" );
447  filename.Replace( "\r", "" );
448  filename.Replace( "\t", "" );
449 
450  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
451  {
452  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
454  m_delayedFocusRow = aEvent.GetRow();
455  m_delayedFocusColumn = aEvent.GetCol();
456  aEvent.Veto();
457  }
458 
459  // if the user has specified an alias in the name then prepend ':'
460  if( hasAlias )
461  filename.insert( 0, wxT( ":" ) );
462 
463 #ifdef __WINDOWS__
464  // In Kicad files, filenames and paths are stored using Unix notation
465  filename.Replace( wxT( "\\" ), wxT( "/" ) );
466 #endif
467 
468  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
469  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
470  }
471  else if( aEvent.GetCol() == 1 )
472  {
473  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
474 
475  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
476  }
477 
479 }
480 
481 
483 {
484  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
485 
486  int idx = m_modelsGrid->GetGridCursorRow();
487 
488  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
489  {
490  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
491  m_modelsGrid->DeleteRows( idx, 1 );
492 
493  select3DModel( idx ); // will clamp idx within bounds
495  }
496 }
497 
498 
500 {
502  return;
503 
504  int selected = m_modelsGrid->GetGridCursorRow();
505 
506  PROJECT& prj = Prj();
507  FP_3DMODEL model;
508 
509  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
510  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
511  int filter = 0;
512 
513  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
514  // variable and fall back to the project path if necessary.
515  if( initialpath.IsEmpty() )
516  {
517  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
518  initialpath = prj.GetProjectPath();
519  }
520 
521  if( !sidx.empty() )
522  {
523  long tmp;
524  sidx.ToLong( &tmp );
525 
526  if( tmp > 0 && tmp <= INT_MAX )
527  filter = (int) tmp;
528  }
529 
530  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
531  || model.m_Filename.empty() )
532  {
533  select3DModel( selected );
534  return;
535  }
536 
537  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
538  sidx = wxString::Format( wxT( "%i" ), filter );
540  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
541  wxString alias;
542  wxString shortPath;
543  wxString filename = model.m_Filename;
544 
545  if( res && res->SplitAlias( filename, alias, shortPath ) )
546  filename = alias + wxT( ":" ) + shortPath;
547 
548 #ifdef __WINDOWS__
549  // In KiCad files, filenames and paths are stored using Unix notation
550  model.m_Filename.Replace( "\\", "/" );
551 #endif
552 
553  model.m_Show = true;
554  m_shapes3D_list.push_back( model );
555 
556  int idx = m_modelsGrid->GetNumberRows();
557  m_modelsGrid->AppendRows( 1 );
558  m_modelsGrid->SetCellValue( idx, 0, filename );
559  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
560 
561  select3DModel( idx );
563 }
564 
565 
567 {
569  return;
570 
571  FP_3DMODEL model;
572 
573  model.m_Show = true;
574  m_shapes3D_list.push_back( model );
575 
576  int row = m_modelsGrid->GetNumberRows();
577  m_modelsGrid->AppendRows( 1 );
578  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
579 
580  select3DModel( row );
581 
582  m_modelsGrid->SetFocus();
583  m_modelsGrid->MakeCellVisible( row, 0 );
584  m_modelsGrid->SetGridCursor( row, 0 );
585 
586  m_modelsGrid->EnableCellEditControl( true );
587  m_modelsGrid->ShowCellEditControl();
588 }
589 
590 
592 {
594  return false;
595 
596  if( !DIALOG_SHIM::Validate() )
597  return false;
598 
599  // Check for empty texts.
600  for( size_t i = 2; i < m_texts->size(); ++i )
601  {
602  FP_TEXT& text = m_texts->at( i );
603 
604  if( text.GetText().IsEmpty() )
605  {
606  if( m_NoteBook->GetSelection() != 0 )
607  m_NoteBook->SetSelection( 0 );
608 
610  m_delayedErrorMessage = _( "Text items must have some content." );
612  m_delayedFocusRow = i;
613 
614  return false;
615  }
616  }
617 
618  if( !m_netClearance.Validate( 0, INT_MAX ) )
619  return false;
620 
621  return true;
622 }
623 
624 
626 {
627  if( !Validate() )
628  return false;
629 
631  return false;
632 
634  return false;
635 
636  auto view = m_frame->GetCanvas()->GetView();
637  BOARD_COMMIT commit( m_frame );
638  commit.Modify( m_footprint );
639 
640  // copy reference and value
641  m_footprint->Reference() = m_texts->at( 0 );
642  m_footprint->Value() = m_texts->at( 1 );
643 
644  size_t i = 2;
645 
646  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
647  {
648  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
649 
650  if( textItem )
651  {
652  // copy grid table entries till we run out, then delete any remaining texts
653  if( i < m_texts->size() )
654  *textItem = m_texts->at( i++ );
655  else
656  textItem->DeleteStructure();
657  }
658  }
659 
660  // if there are still grid table entries, create new texts for them
661  while( i < m_texts->size() )
662  {
663  auto newText = new FP_TEXT( m_texts->at( i++ ) );
664  m_footprint->Add( newText, ADD_MODE::APPEND );
665  view->Add( newText );
666  }
667 
668  // Initialize masks clearances
672 
673  double dtmp = 0.0;
674  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
675  msg.ToDouble( &dtmp );
676 
677  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
678  if( dtmp < -50.0 )
679  dtmp = -50.0;
680  // A margin ratio is always <= 0
681  // 0 means use full pad copper area
682  if( dtmp > 0.0 )
683  dtmp = 0.0;
684 
686 
687  switch( m_ZoneConnectionChoice->GetSelection() )
688  {
689  default:
694  }
695 
696  // Set Footprint Position
697  wxPoint pos( m_posX.GetValue(), m_posY.GetValue() );
698  m_footprint->SetPosition( pos );
699  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
700  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
701 
702  int attributes = 0;
703 
704  switch( m_componentType->GetSelection() )
705  {
706  case 0: attributes |= FP_THROUGH_HOLE; break;
707  case 1: attributes |= FP_SMD; break;
708  default: break;
709  }
710 
711  if( m_boardOnly->GetValue() )
712  attributes |= FP_BOARD_ONLY;
713 
714  if( m_excludeFromPosFiles->GetValue() )
715  attributes |= FP_EXCLUDE_FROM_POS_FILES;
716 
717  if( m_excludeFromBOM->GetValue() )
718  attributes |= FP_EXCLUDE_FROM_BOM;
719 
720  m_footprint->SetAttributes( attributes );
721 
724 
725  // Now, set orientation. Must be done after other changes because rotation changes field
726  // positions on board (so that relative positions are held constant)
727  m_OrientValidator.TransferFromWindow();
728 
729  double orient = m_OrientValue * 10;
730 
731  if( m_footprint->GetOrientation() != orient )
733 
734  // Set component side, that also have effect on the fields positions on board
735  bool change_layer = false;
736  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
737  {
738  if( m_footprint->GetLayer() == B_Cu )
739  change_layer = true;
740  }
741  else if( m_footprint->GetLayer() == F_Cu )
742  change_layer = true;
743 
744  if( change_layer )
746 
747  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
748  draw3D->clear();
749  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
750 
752 
753  // This is a simple edit, we must create an undo entry
754  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
755  commit.Push( _( "Modify footprint properties" ) );
756 
757  SetReturnCode( FP_PROPS_OK );
758  return true;
759 }
760 
761 
763 {
765  return;
766 
767  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
768  FP_TEXT textItem( m_footprint );
769 
770  // Set active layer if legal; otherwise copy layer from previous text item
772  textItem.SetLayer( m_frame->GetActiveLayer() );
773  else
774  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
775 
776  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
777  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
778  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
779  textItem.SetKeepUpright( dsnSettings.GetTextUpright( textItem.GetLayer() ) );
780  textItem.SetMirrored( IsBackLayer( textItem.GetLayer() ) );
781 
782  m_texts->push_back( textItem );
783 
784  // notify the grid
785  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
786  m_itemsGrid->ProcessTableMessage( msg );
787 
788  m_itemsGrid->SetFocus();
789  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
790  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
791 
792  m_itemsGrid->EnableCellEditControl( true );
793  m_itemsGrid->ShowCellEditControl();
794 }
795 
796 
798 {
799  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
800 
801  int curRow = m_itemsGrid->GetGridCursorRow();
802 
803  if( curRow < 0 )
804  return;
805  else if( curRow < 2 )
806  {
807  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
808  return;
809  }
810 
811  m_texts->erase( m_texts->begin() + curRow );
812 
813  // notify the grid
814  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
815  m_itemsGrid->ProcessTableMessage( msg );
816 
817  if( m_itemsGrid->GetNumberRows() > 0 )
818  {
819  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
820  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
821  }
822 }
823 
824 
826 {
827  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
829 }
830 
831 
833 {
834  // Account for scroll bars
835  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
836  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
837 
838  itemsWidth -= m_itemsGrid->GetRowLabelSize();
839 
840  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
841  itemsWidth -= m_itemsGrid->GetColSize( i );
842 
843  if( itemsWidth > 0 )
844  {
845  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
846  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
847  }
848 
849  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 );
850 }
851 
852 
854 {
855  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
856  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
857 
858  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
859  // even when the original validation was triggered from a killFocus event, and so
860  // that the corresponding notebook page can be shown in the background when triggered
861  // from an OK.
862  if( m_delayedFocusRow >= 0 )
863  {
864  // We will re-enter this routine if an error dialog is displayed, so make sure we
865  // zero out our member variables first.
866  wxGrid* grid = m_delayedFocusGrid;
867  int row = m_delayedFocusRow;
868  int col = m_delayedFocusColumn;
869  wxString msg = m_delayedErrorMessage;
870 
871  m_delayedFocusGrid = nullptr;
872  m_delayedFocusRow = -1;
874  m_delayedErrorMessage = wxEmptyString;
875 
876  if( !msg.IsEmpty() )
877  {
878  // Do not use DisplayErrorMessage(); it screws up window order on Mac
879  DisplayError( nullptr, msg );
880  }
881 
882  grid->SetFocus();
883  grid->MakeCellVisible( row, col );
884 
885  // Selecting the first grid item only makes sense for the
886  // items grid
887  if( !m_initialFocus || grid == m_itemsGrid )
888  {
889  grid->SetGridCursor( row, col );
890  grid->EnableCellEditControl( true );
891  grid->ShowCellEditControl();
892 
893  if( grid == m_itemsGrid && row == 0 && col == 0 )
894  {
895  auto referenceEditor = grid->GetCellEditor( 0, 0 );
896 
897  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
898  KIUI::SelectReferenceNumber( textEntry );
899 
900  referenceEditor->DecRef();
901  }
902  }
903  m_initialFocus = false;
904  }
905 
906  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
907 }
908 
909 
910 void DIALOG_FOOTPRINT_PROPERTIES::OnGridSize( wxSizeEvent& aEvent )
911 {
912  adjustGridColumns( aEvent.GetSize().GetX() );
913 
914  aEvent.Skip();
915 }
916 
917 
918 void DIALOG_FOOTPRINT_PROPERTIES::OnPageChange( wxNotebookEvent& aEvent )
919 {
920  int page = aEvent.GetSelection();
921 
922  // Shouldn't be necessary, but is on at least OSX
923  if( page >= 0 )
924  m_NoteBook->ChangeSelection( (unsigned) page );
925 
926 #ifdef __WXMAC__
927  // Work around an OSX bug where the wxGrid children don't get placed correctly until
928  // the first resize event
929  if( m_macHack[ page ] )
930  {
931  wxSize pageSize = m_NoteBook->GetPage( page )->GetSize();
932  pageSize.x -= 1;
933 
934  m_NoteBook->GetPage( page )->SetSize( pageSize );
935  m_macHack[ page ] = false;
936  }
937 #endif
938 }
939 
940 
942 {
944 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:194
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:240
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:34
bool IsLocked() const override
Function IsLocked.
Definition: footprint.h:298
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
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)
Modifies a given item in the model.
Definition: commit.h:103
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
PROJECT holds project specific data.
Definition: project.h:63
std::list< FP_3DMODEL > & Models()
Definition: footprint.h:196
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: footprint.h:240
void OnAddField(wxCommandEvent &) override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: board_item.h:206
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,...
Definition: board_item.h:86
int GetPlacementCost180() const
Definition: footprint.h:559
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
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:185
void OnUpdateUI(wxUpdateUIEvent &) override
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
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:52
provides an extensible class to resolve 3D model paths.
double GetOrientation() const
Definition: footprint.h:204
void DeleteStructure()
Function DeleteStructure deletes 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:238
wxFloatingPointValidator< double > m_OrientValidator
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
#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
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()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
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 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)
UpdateDummyFootprint - copy shapes from the current shape list which are flagged for preview to the c...
void SetAttributes(int aAttributes)
Definition: footprint.h:250
void SetPlacementCost180(int aCost)
Definition: footprint.h:560
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
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:480
bool GetTextUpright(PCB_LAYER_ID aLayer) const
FP_TEXT & Reference()
Definition: footprint.h:481
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: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:82
wxString m_lastFootprint3dDir
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...
bool m_Show
Include model in rendering.
Definition: footprint.h:99
pads are covered by copper
void Cfg3DPath(wxCommandEvent &) override
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:225
void OnOtherOrientation(wxCommandEvent &aEvent) override
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
Definition: footprint.cpp:1281
void SetLocalClearance(int aClearance)
Definition: footprint.h:224
int GetLocalClearance() const
Definition: footprint.h:223
DRAWINGS & GraphicalItems()
Definition: footprint.h:185
const LIB_ID & GetFPID() const
Definition: footprint.h:208
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:180
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: footprint.cpp:1259
void SetSelectedModel(int idx)
SetSelectedModel - Sets the currently selected index in the model list so that the scale/rotation/off...
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
UTF8 Format() const
Definition: lib_id.cpp:237
const BITMAP_OPAQUE icon_modedit_xpm[1]
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:212
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs 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:98
EDA_UNITS m_units
Definition: dialog_shim.h:190
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:109
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:113
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:227
int GetLocalSolderMaskMargin() const
Definition: footprint.h:220
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Function Validate Validates the control against the given range, informing the user of any errors fou...
see class PGM_BASE
Declaration of the eda_3d_viewer class.
int GetAttributes() const
Definition: footprint.h:249
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
std::vector< FP_3DMODEL > m_shapes3D_list
void OnRemove3DModel(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: footprint.h:308
PCB_EDIT_FRAME is the main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
Pads are not covered.
wxPoint GetPosition() const override
Definition: footprint.h:200
double GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:237
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)
DIALOG_FOOTPRINT_PROPERTIES(PCB_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
void OnAdd3DRow(wxCommandEvent &) override
void SetPadsLocked(bool aPadsLocked)
Definition: footprint.h:336
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
ZONE_CONNECTION GetZoneConnection() const
Definition: footprint.h:241
int GetPlacementCost90() const
Definition: footprint.h:562
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Function SetOriginTransform Sets the current origin transform mode.
Definition: unit_binder.h:168
void UpdateFootprint(wxCommandEvent &) override
int GetLocalSolderPasteMargin() const
Definition: footprint.h:234
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Definition: footprint.cpp:444
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1346
bool PadsLocked() const
Definition: footprint.h:334
void OnPageChange(wxNotebookEvent &event) override
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.
Definition: board_item.h:185
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: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 SetPlacementCost90(int aCost)
Definition: footprint.h:563
void EditFootprint(wxCommandEvent &) override
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:221
void ChangeFootprint(wxCommandEvent &) override
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
Definition: footprint.cpp:567
void OnGridSize(wxSizeEvent &aEvent) override
int GetNumberRows() override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:235