KiCad PCB EDA Suite
dialog_footprint_properties_fp_editor.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 2004-2021 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 
27 #include <confirm.h>
30 #include <validators.h>
31 #include <board_design_settings.h>
32 #include <board_commit.h>
33 #include <bitmaps.h>
35 #include <widgets/wx_grid.h>
36 #include <widgets/text_ctrl_eval.h>
37 #include <footprint.h>
38 #include <footprint_edit_frame.h>
41 #include "filename_resolver.h"
42 #include <pgm_base.h>
46 #include <tool/tool_manager.h>
48 
49 #include <fp_lib_table.h>
50 
51 
52 // Remember the last open page during session.
54 
55 
57  FOOTPRINT_EDIT_FRAME* aParent,
58  FOOTPRINT* aFootprint ) :
60  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits ),
61  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl,
62  m_SolderMaskMarginUnits ),
63  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl,
64  m_SolderPasteMarginUnits ),
65  m_inSelect( false )
66 {
67  m_frame = aParent;
68  m_footprint = aFootprint;
69 
71 
72  m_delayedErrorMessage = wxEmptyString;
73  m_delayedFocusCtrl = nullptr;
74  m_delayedFocusGrid = nullptr;
75  m_delayedFocusRow = -1;
77  m_delayedFocusPage = -1;
78 
79  // Give an icon
80  wxIcon icon;
81  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
82  SetIcon( icon );
83 
84  // Give a bit more room for combobox editors
85  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
86  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
87 
89  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
90  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
91 
92  // Show/hide columns according to the user's preference
94 
95  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
96 
97  if( cfg->m_lastFootprint3dDir.IsEmpty() )
98  {
99  wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir );
100  }
101 
102  wxGridCellAttr* attr = new wxGridCellAttr;
103  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir,
104  "*.*", true, Prj().GetProjectPath() ) );
105  m_modelsGrid->SetColAttr( 0, attr );
106 
107  // Show checkbox
108  attr = new wxGridCellAttr;
109  attr->SetRenderer( new wxGridCellBoolRenderer() );
110  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
111  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
112  m_modelsGrid->SetColAttr( 1, attr );
113  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
114 
115  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
116 
118 
119  bLowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 );
120 
122 
123  // Set font sizes
124  wxFont infoFont = KIUI::GetInfoFont();
125 #if __WXMAC__
126  m_allow90Label->SetFont( infoFont );
127  m_allow180Label->SetFont( infoFont );
128 #endif
129  m_staticTextInfoCopper->SetFont( infoFont );
130  m_staticTextInfoPaste->SetFont( infoFont );
131 
132  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
133  m_staticTextInfoValNeg->SetFont( infoFont );
134  m_staticTextInfoValPos->SetFont( infoFont );
135 
136  if( m_page >= 0 )
137  m_NoteBook->SetSelection( (unsigned) m_page );
138 
139  if( m_page == 0 )
140  {
142  m_delayedFocusRow = 0;
144  m_delayedFocusPage = 0;
145  }
146  else if ( m_page == 1 )
148  else
149  {
151  m_delayedFocusRow = 0;
153  m_delayedFocusPage = 2;
154  }
155 
156  m_sdbSizerStdButtonsOK->SetDefault();
157 
158  // Configure button logos
159  m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
160  m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
164 
165  // wxFormBuilder doesn't include this event...
166  m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING,
168  nullptr, this );
169 
171 }
172 
173 
175 {
177  m_itemsGrid->GetShownColumns().ToStdString();
178 
179  // Prevents crash bug in wxGrid's d'tor
181 
182  m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
184  nullptr, this );
185 
186  // Delete the GRID_TRICKS.
187  m_itemsGrid->PopEventHandler( true );
188  m_modelsGrid->PopEventHandler( true );
189 
190  // free the memory used by all models, otherwise models which were
191  // browsed but not used would consume memory
192  Prj().Get3DCacheManager()->FlushCache( false );
193 
194  // the GL canvas has to be visible before it is destroyed
195  m_page = m_NoteBook->GetSelection();
196  m_NoteBook->SetSelection( 1 );
197 
198  delete m_previewPane;
199 }
200 
201 
203 {
204  LIB_ID fpID = m_footprint->GetFPID();
205  wxString footprintName = fpID.GetLibItemName();
206 
207  m_FootprintNameCtrl->ChangeValue( footprintName );
208 
209  m_DocCtrl->SetValue( m_footprint->GetDescription() );
210  m_KeywordCtrl->SetValue( m_footprint->GetKeywords() );
211 
212  if( !wxDialog::TransferDataToWindow() )
213  return false;
214 
215  if( !m_PanelGeneral->TransferDataToWindow() )
216  return false;
217 
218  if( !m_Panel3D->TransferDataToWindow() )
219  return false;
220 
221  // Module Texts
222 
223  m_texts->push_back( m_footprint->Reference() );
224  m_texts->push_back( m_footprint->Value() );
225 
226  for( auto item : m_footprint->GraphicalItems() )
227  {
228  auto textItem = dyn_cast<FP_TEXT*>( item );
229 
230  if( textItem )
231  m_texts->push_back( *textItem );
232  }
233 
234  // notify the grid
235  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
236  m_itemsGrid->ProcessTableMessage( tmsg );
237 
238  // Footprint Properties
241 
243  m_componentType->SetSelection( 0 );
244  else if( m_footprint->GetAttributes() & FP_SMD )
245  m_componentType->SetSelection( 1 );
246  else
247  m_componentType->SetSelection( 2 );
248 
252 
253  // Local Clearances
254 
258 
259  // Prefer "-0" to "0" for normally negative values
261  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
262 
263  // Add solder paste margin ratio in percent
264  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
265  wxString msg;
266  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
267 
269  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
270  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
271  else
273 
274  switch( m_footprint->GetZoneConnection() )
275  {
276  default:
278  m_ZoneConnectionChoice->SetSelection( 0 );
279  break;
281  m_ZoneConnectionChoice->SetSelection( 1 );
282  break;
284  m_ZoneConnectionChoice->SetSelection( 2 );
285  break;
287  m_ZoneConnectionChoice->SetSelection( 3 );
288  break;
289  }
290 
291  // 3D Settings
292 
293  wxString default_path;
294  wxGetEnv( KICAD6_3DMODEL_DIR, &default_path );
295 
296 #ifdef __WINDOWS__
297  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
298 #endif
299 
300  m_shapes3D_list.clear();
301  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
302 
303  wxString origPath, alias, shortPath;
304  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
305 
306  for( const FP_3DMODEL& model : m_footprint->Models() )
307  {
308  m_shapes3D_list.push_back( model );
309  origPath = model.m_Filename;
310 
311  if( res && res->SplitAlias( origPath, alias, shortPath ) )
312  origPath = alias + wxT( ":" ) + shortPath;
313 
314  m_modelsGrid->AppendRows( 1 );
315  int row = m_modelsGrid->GetNumberRows() - 1;
316  m_modelsGrid->SetCellValue( row, 0, origPath );
317  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
318  }
319 
320  select3DModel( 0 ); // will clamp idx within bounds
322 
323  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
324  {
325  // Adjust min size to the column label size
326  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
327  false ) );
328  // Adjust the column size.
329  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
330 
331  if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
332  {
333  BOARD* board = m_footprint->GetBoard();
334 
335  for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
336  col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
337 
338  // And the swatch:
339  col_size += 20;
340  }
341 
342  if( m_itemsGrid->IsColShown( col ) )
343  m_itemsGrid->SetColSize( col, col_size );
344  }
345 
346  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) );
347  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
348 
349  Layout();
350  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
351 
352  return true;
353 }
354 
355 
357 {
358  m_inSelect = true;
359 
360  aModelIdx = std::max( 0, aModelIdx );
361  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
362 
363  if( m_modelsGrid->GetNumberRows() )
364  {
365  m_modelsGrid->SelectRow( aModelIdx );
366  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
367  }
368 
369  m_previewPane->SetSelectedModel( aModelIdx );
370 
371  m_inSelect = false;
372 }
373 
374 
376 {
377  if( !m_inSelect )
378  select3DModel( aEvent.GetRow() );
379 }
380 
381 
383 {
384  if( aEvent.GetCol() == 0 )
385  {
386  bool hasAlias = false;
387  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
388  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
389 
390  filename.Replace( "\n", "" );
391  filename.Replace( "\r", "" );
392  filename.Replace( "\t", "" );
393 
394  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
395  {
396  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
398  m_delayedFocusRow = aEvent.GetRow();
399  m_delayedFocusColumn = aEvent.GetCol();
400  m_delayedFocusPage = 2;
401  aEvent.Veto();
402  }
403 
404  // if the user has specified an alias in the name then prepend ':'
405  if( hasAlias )
406  filename.insert( 0, wxT( ":" ) );
407 
408 #ifdef __WINDOWS__
409  // In KiCad files, filenames and paths are stored using Unix notation
410  filename.Replace( wxT( "\\" ), wxT( "/" ) );
411 #endif
412 
413  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
414  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
415  }
416  else if( aEvent.GetCol() == 1 )
417  {
418  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
419 
420  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
421  }
422 
424 }
425 
426 
428 {
430  return;
431 
432  int idx = m_modelsGrid->GetGridCursorRow();
433 
434  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
435  {
436  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
437  m_modelsGrid->DeleteRows( idx );
438 
439  select3DModel( idx ); // will clamp idx within bounds
441  }
442 }
443 
444 
446 {
448  return;
449 
450  int selected = m_modelsGrid->GetGridCursorRow();
451 
452  PROJECT& prj = Prj();
453  FP_3DMODEL model;
454 
455  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
456  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
457  int filter = 0;
458 
459  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment
460  // variable and fall back to the project path if necessary.
461  if( initialpath.IsEmpty() )
462  {
463  if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() )
464  initialpath = prj.GetProjectPath();
465  }
466 
467  if( !sidx.empty() )
468  {
469  long tmp;
470  sidx.ToLong( &tmp );
471 
472  if( tmp > 0 && tmp <= INT_MAX )
473  filter = (int) tmp;
474  }
475 
476  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
477  || model.m_Filename.empty() )
478  {
479  select3DModel( selected );
480  return;
481  }
482 
483  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
484  sidx = wxString::Format( wxT( "%i" ), filter );
486  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
487  wxString alias;
488  wxString shortPath;
489  wxString filename = model.m_Filename;
490 
491  if( res && res->SplitAlias( filename, alias, shortPath ) )
492  filename = alias + wxT( ":" ) + shortPath;
493 
494 #ifdef __WINDOWS__
495  // In KiCad files, filenames and paths are stored using Unix notation
496  model.m_Filename.Replace( "\\", "/" );
497 #endif
498 
499  model.m_Show = true;
500  m_shapes3D_list.push_back( model );
501 
502  int idx = m_modelsGrid->GetNumberRows();
503  m_modelsGrid->AppendRows( 1 );
504  m_modelsGrid->SetCellValue( idx, 0, filename );
505  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
506 
507  select3DModel( idx );
509 }
510 
511 
513 {
515  return;
516 
517  FP_3DMODEL model;
518 
519  model.m_Show = true;
520  m_shapes3D_list.push_back( model );
521 
522  int row = m_modelsGrid->GetNumberRows();
523  m_modelsGrid->AppendRows( 1 );
524  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
525 
526  select3DModel( row );
527 
528  m_modelsGrid->SetFocus();
529  m_modelsGrid->MakeCellVisible( row, 0 );
530  m_modelsGrid->SetGridCursor( row, 0 );
531 
532  m_modelsGrid->EnableCellEditControl( true );
533  m_modelsGrid->ShowCellEditControl();
534 }
535 
536 
537 bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::checkFootprintName( const wxString& aFootprintName )
538 {
539  if( aFootprintName.IsEmpty() )
540  {
541  m_delayedErrorMessage = _( "Footprint must have a name." );
542  return false;
543  }
544  else if( !FOOTPRINT::IsLibNameValid( aFootprintName ) )
545  {
546  m_delayedErrorMessage.Printf( _( "Footprint name may not contain '%s'." ),
548  return false;
549  }
550 
551  return true;
552 }
553 
554 
556 {
558  return false;
559 
560  if( !DIALOG_SHIM::Validate() )
561  return false;
562 
563  // First, test for invalid chars in footprint name
564  wxString footprintName = m_FootprintNameCtrl->GetValue();
565 
566  if( !checkFootprintName( footprintName ) )
567  {
568  if( m_NoteBook->GetSelection() != 0 )
569  m_NoteBook->SetSelection( 0 );
570 
572  m_delayedFocusPage = 0;
573 
574  return false;
575  }
576 
577  // Check for empty texts.
578  for( size_t i = 2; i < m_texts->size(); ++i )
579  {
580  FP_TEXT& text = m_texts->at( i );
581 
582  if( text.GetText().IsEmpty() )
583  {
584  if( m_NoteBook->GetSelection() != 0 )
585  m_NoteBook->SetSelection( 0 );
586 
587  m_delayedErrorMessage = _( "Text items must have some content." );
590  m_delayedFocusRow = i;
591 
592  return false;
593  }
594  }
595 
596  if( !m_netClearance.Validate( 0, INT_MAX ) )
597  return false;
598 
599  return true;
600 }
601 
602 
604 {
605  if( !Validate() )
606  return false;
607 
608  if( !DIALOG_SHIM::TransferDataFromWindow() )
609  return false;
610 
612  return false;
613 
615  return false;
616 
617  auto view = m_frame->GetCanvas()->GetView();
618  BOARD_COMMIT commit( m_frame );
619  commit.Modify( m_footprint );
620 
621  LIB_ID fpID = m_footprint->GetFPID();
622  fpID.SetLibItemName( m_FootprintNameCtrl->GetValue() );
623  m_footprint->SetFPID( fpID );
624 
625  m_footprint->SetDescription( m_DocCtrl->GetValue() );
626  m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
627 
628  // copy reference and value
629  m_footprint->Reference() = m_texts->at( 0 );
630  m_footprint->Value() = m_texts->at( 1 );
631 
632  size_t i = 2;
633  std::vector<FP_TEXT*> items_to_remove;
634 
635  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
636  {
637  FP_TEXT* textItem = dynamic_cast<FP_TEXT*>( item );
638 
639  if( textItem )
640  {
641  // copy grid table entries till we run out, then delete any remaining texts
642  if( i < m_texts->size() )
643  *textItem = m_texts->at( i++ );
644  else // store this item to remove and delete it later,
645  // after the graphic list is explored:
646  items_to_remove.push_back( textItem );
647  }
648  }
649 
650  // Remove text items:
652 
653  for( FP_TEXT* item: items_to_remove )
654  {
655  selTool->RemoveItemFromSel( item );
656  view->Remove( item );
657  item->DeleteStructure();
658  }
659 
660  // if there are still grid table entries, create new texts for them
661  while( i < m_texts->size() )
662  {
663  FP_TEXT* newText = new FP_TEXT( m_texts->at( i++ ) );
664  m_footprint->Add( newText, ADD_MODE::APPEND );
665  view->Add( newText );
666  }
667 
668  int attributes = 0;
669 
670  switch( m_componentType->GetSelection() )
671  {
672  case 0: attributes |= FP_THROUGH_HOLE; break;
673  case 1: attributes |= FP_SMD; break;
674  default: break;
675  }
676 
677  if( m_boardOnly->GetValue() )
678  attributes |= FP_BOARD_ONLY;
679 
680  if( m_excludeFromPosFiles->GetValue() )
681  attributes |= FP_EXCLUDE_FROM_POS_FILES;
682 
683  if( m_excludeFromBOM->GetValue() )
684  attributes |= FP_EXCLUDE_FROM_BOM;
685 
686  m_footprint->SetAttributes( attributes );
687 
690 
691  // Initialize masks clearances
695 
696  double dtmp = 0.0;
697  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
698  msg.ToDouble( &dtmp );
699 
700  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
701  if( dtmp < -50.0 )
702  dtmp = -50.0;
703 
704  // A margin ratio is always <= 0
705  // 0 means use full pad copper area
706  if( dtmp > 0.0 )
707  dtmp = 0.0;
708 
710 
711  switch( m_ZoneConnectionChoice->GetSelection() )
712  {
713  default:
718  }
719 
720  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
721  draw3D->clear();
722  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
723 
724  commit.Push( _( "Modify footprint properties" ) );
725 
726  return true;
727 }
728 
729 
730 static bool footprintIsFromBoard( FOOTPRINT* aFootprint )
731 {
732  return aFootprint->GetLink() != niluuid;
733 }
734 
735 
737 {
738  // Currently: nothing to do
739 }
740 
741 
743 {
745  {
746  // Currently: nothing to do
747  }
748 }
749 
750 
752 {
754  return;
755 
756  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
757  FP_TEXT textItem( m_footprint );
758 
759  // Set active layer if legal; otherwise copy layer from previous text item
761  textItem.SetLayer( m_frame->GetActiveLayer() );
762  else
763  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
764 
765  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
766  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
767  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
768 
769  m_texts->push_back( textItem );
770 
771  // notify the grid
772  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
773  m_itemsGrid->ProcessTableMessage( msg );
774 
775  m_itemsGrid->SetFocus();
776  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
777  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
778 
779  m_itemsGrid->EnableCellEditControl( true );
780  m_itemsGrid->ShowCellEditControl();
781 }
782 
783 
785 {
787  return;
788 
789  int curRow = m_itemsGrid->GetGridCursorRow();
790 
791  if( curRow < 0 )
792  return;
793  else if( curRow < 2 )
794  {
795  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
796  return;
797  }
798 
799  m_texts->erase( m_texts->begin() + curRow );
800 
801  // notify the grid
802  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
803  m_itemsGrid->ProcessTableMessage( msg );
804 
805  if( m_itemsGrid->GetNumberRows() > 0 )
806  {
807  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
808  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
809  }
810 }
811 
812 
814 {
815  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
817 }
818 
819 
821 {
822  // Account for scroll bars
823  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
824  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
825 
826  itemsWidth -= m_itemsGrid->GetRowLabelSize();
827 
828  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
829  itemsWidth -= m_itemsGrid->GetColSize( i );
830 
831  if( itemsWidth > 0 )
832  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
833  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
834 
835  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
836 }
837 
838 
840 {
841  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
842  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
843 
844  if( m_itemsGrid->IsCellEditControlShown() )
845  {
846  // Currently: nothing to do
847  }
848 
849  // Handle a delayed focus. The delay allows us to:
850  // a) change focus when the error was triggered from within a killFocus handler
851  // b) show the correct notebook page in the background before the error dialog comes up
852  // when triggered from an OK or a notebook page change
853 
854  if( m_delayedFocusPage >= 0 )
855  {
856  if( m_NoteBook->GetSelection() != m_delayedFocusPage )
857  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
858 
859  m_delayedFocusPage = -1;
860  }
861 
862  if( !m_delayedErrorMessage.IsEmpty() )
863  {
864  // We will re-enter this routine when the error dialog is displayed, so make
865  // sure we don't keep putting up more dialogs.
866  wxString msg = m_delayedErrorMessage;
867  m_delayedErrorMessage = wxEmptyString;
868 
869  // Do not use DisplayErrorMessage(); it screws up window order on Mac
870  DisplayError( nullptr, msg );
871  }
872 
873  if( m_delayedFocusCtrl )
874  {
875  m_delayedFocusCtrl->SetFocus();
876 
877  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
878  textEntry->SelectAll();
879 
880  m_delayedFocusCtrl = nullptr;
881  }
882  else if( m_delayedFocusGrid )
883  {
884  m_delayedFocusGrid->SetFocus();
887 
888  m_delayedFocusGrid->EnableCellEditControl( true );
889  m_delayedFocusGrid->ShowCellEditControl();
890 
891  m_delayedFocusGrid = nullptr;
892  m_delayedFocusRow = -1;
894  }
895 
896  m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
897 }
898 
899 
901 {
902  adjustGridColumns( event.GetSize().GetX() );
903 
904  event.Skip();
905 }
void SetSelectedModel(int idx)
Set the currently selected index in the model list so that the scale/rotation/offset controls can be ...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:247
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
const wxString & GetDescription() const
Definition: footprint.h:188
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
KIID niluuid(0)
Container for project specific data.
Definition: project.h:62
std::list< FP_3DMODEL > & Models()
Definition: footprint.h:173
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:360
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: footprint.h:217
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void UpdateDummyFootprint(bool aRelaodRequired=true)
Copy shapes from the current shape list which are flagged for preview to the copy of footprint that i...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
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:80
int GetPlacementCost180() const
Definition: footprint.h:529
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:129
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:179
Class DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE.
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath) const
Return true if the given name contains an alias and populates the string anAlias with the alias and a...
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
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: footprint.h:215
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:465
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
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
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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.
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:97
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
void SetAttributes(int aAttributes)
Definition: footprint.h:227
void SetPlacementCost180(int aCost)
Definition: footprint.h:530
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:457
void SetDescription(const wxString &aDoc)
Definition: footprint.h:189
bool ValidateFileName(const wxString &aFileName, bool &hasAlias) const
Returns true if the given path is a valid aliased relative path.
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
FP_TEXT & Reference()
Definition: footprint.h:458
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
wxString m_lastFootprint3dDir
DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
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
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static bool footprintIsFromBoard(FOOTPRINT *aFootprint)
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:51
void SetLocalClearance(int aClearance)
Definition: footprint.h:201
int GetLocalClearance() const
Definition: footprint.h:200
#define _(s)
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
const LIB_ID & GetFPID() const
Definition: footprint.h:185
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
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:108
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
const wxString & GetKeywords() const
Definition: footprint.h:191
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
KIID GetLink() const
Definition: footprint.h:526
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...
Definition: project.cpp:212
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:198
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.
void SetFPID(const LIB_ID &aFPID)
Definition: footprint.h:186
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:110
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Definition: project.cpp:227
int GetLocalSolderMaskMargin() const
Definition: footprint.h:197
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:226
wxFont GetInfoFont()
Definition: ui_common.cpp:97
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetKeywords(const wxString &aKeywords)
Definition: footprint.h:192
The selection tool: currently supports:
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.
double GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:214
virtual long long int GetValue()
Return the current value in Internal Units.
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:159
ZONE_CONNECTION GetZoneConnection() const
Definition: footprint.h:218
int GetPlacementCost90() const
Definition: footprint.h:532
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
static bool IsLibNameValid(const wxString &aName)
Test for validity of a name of a footprint to be used in a footprint library ( no spaces,...
Definition: footprint.cpp:1323
int GetLocalSolderPasteMargin() const
Definition: footprint.h:211
void RemoveItemFromSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Multiple item unselection event handler.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:472
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
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.
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
Test for validity of the name in a library of the footprint ( no spaces, dir separators ....
Definition: footprint.cpp:1334
void SetPlacementCost90(int aCost)
Definition: footprint.h:533
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:198
Container for design settings for a BOARD object.
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:212