KiCad PCB EDA Suite
dialog_edit_footprint_for_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-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 
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 int DIALOG_FOOTPRINT_FP_EDITOR::m_page = 0; // remember the last open page during session
53 
54 
56  FOOTPRINT* aFootprint ) :
58  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
59  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
60  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
61  m_inSelect( false )
62 {
63  m_frame = aParent;
64  m_footprint = aFootprint;
65 
67 
68  m_delayedErrorMessage = wxEmptyString;
69  m_delayedFocusCtrl = nullptr;
70  m_delayedFocusGrid = nullptr;
71  m_delayedFocusRow = -1;
73  m_delayedFocusPage = -1;
74 
75  // Give an icon
76  wxIcon icon;
77  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
78  SetIcon( icon );
79 
80  // Give a bit more room for combobox editors
81  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
82  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
83 
85  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
86  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
87 
88  // Show/hide columns according to the user's preference
90 
91  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
92  if( cfg->m_lastFootprint3dDir.IsEmpty() )
93  {
94  wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir );
95  }
96 
97  wxGridCellAttr* attr = new wxGridCellAttr;
98  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir,
99  "*.*", true, Prj().GetProjectPath() ) );
100  m_modelsGrid->SetColAttr( 0, attr );
101 
102  // Show checkbox
103  attr = new wxGridCellAttr;
104  attr->SetRenderer( new wxGridCellBoolRenderer() );
105  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
106  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
107  m_modelsGrid->SetColAttr( 1, attr );
108  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
109 
110  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
111 
113 
114  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
115 
117 
118  // Set font sizes
119  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
120  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
121 #if __WXMAC__
122  m_allow90Label->SetFont( infoFont );
123  m_allow180Label->SetFont( infoFont );
124 #endif
125  m_staticTextInfoCopper->SetFont( infoFont );
126  m_staticTextInfoPaste->SetFont( infoFont );
127 
128  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
129  m_staticTextInfoValNeg->SetFont( infoFont );
130  m_staticTextInfoValPos->SetFont( infoFont );
131 
132  if( m_page >= 0 )
133  m_NoteBook->SetSelection( (unsigned) m_page );
134 
135  if( m_page == 0 )
136  {
138  m_delayedFocusRow = 0;
140  m_delayedFocusPage = 0;
141  }
142  else if ( m_page == 1 )
144  else
145  {
147  m_delayedFocusRow = 0;
149  m_delayedFocusPage = 2;
150  }
151 
152  m_sdbSizerStdButtonsOK->SetDefault();
153 
154  // Configure button logos
155  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
156  m_bpDelete->SetBitmap( KiBitmap( small_trash_xpm ) );
157  m_button3DShapeAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
160 
161  // wxFormBuilder doesn't include this event...
162  m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
163 
165 }
166 
167 
169 {
171  m_itemsGrid->GetShownColumns().ToStdString();
172 
173  // Prevents crash bug in wxGrid's d'tor
175 
176  m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
177 
178  // Delete the GRID_TRICKS.
179  m_itemsGrid->PopEventHandler( true );
180  m_modelsGrid->PopEventHandler( true );
181 
182  // free the memory used by all models, otherwise models which were
183  // browsed but not used would consume memory
184  Prj().Get3DCacheManager()->FlushCache( false );
185 
186  // the GL canvas has to be visible before it is destroyed
187  m_page = m_NoteBook->GetSelection();
188  m_NoteBook->SetSelection( 1 );
189 
190  delete m_PreviewPane;
191 }
192 
193 
195 {
196  LIB_ID fpID = m_footprint->GetFPID();
197  wxString footprintName = fpID.GetLibItemName();
198 
199  m_FootprintNameCtrl->ChangeValue( footprintName );
200 
201  m_DocCtrl->SetValue( m_footprint->GetDescription() );
202  m_KeywordCtrl->SetValue( m_footprint->GetKeywords() );
203 
204  if( !wxDialog::TransferDataToWindow() )
205  return false;
206 
207  if( !m_PanelGeneral->TransferDataToWindow() )
208  return false;
209 
210  if( !m_Panel3D->TransferDataToWindow() )
211  return false;
212 
213  // Module Texts
214 
215  m_texts->push_back( m_footprint->Reference() );
216  m_texts->push_back( m_footprint->Value() );
217 
218  for( auto item : m_footprint->GraphicalItems() )
219  {
220  auto textItem = dyn_cast<FP_TEXT*>( item );
221 
222  if( textItem )
223  m_texts->push_back( *textItem );
224  }
225 
226  // notify the grid
227  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
228  m_itemsGrid->ProcessTableMessage( tmsg );
229 
230  // Module Properties
231 
232  m_AutoPlaceCtrl->SetSelection( m_footprint->IsLocked() ? 1 : 0 );
233  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Enable hotkey move commands and Auto Placement" ) );
234  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Disable hotkey move commands and Auto Placement" ) );
235 
238 
240  m_componentType->SetSelection( 0 );
241  else if( m_footprint->GetAttributes() & FP_SMD )
242  m_componentType->SetSelection( 1 );
243  else
244  m_componentType->SetSelection( 2 );
245 
249 
250  // Local Clearances
251 
255 
256  // Prefer "-0" to "0" for normally negative values
258  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
259 
260  // Add solder paste margin ratio in percent
261  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
262  wxString msg;
263  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
264 
266  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
267  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
268  else
270 
271  switch( m_footprint->GetZoneConnection() )
272  {
273  default:
275  m_ZoneConnectionChoice->SetSelection( 0 );
276  break;
278  m_ZoneConnectionChoice->SetSelection( 1 );
279  break;
281  m_ZoneConnectionChoice->SetSelection( 2 );
282  break;
284  m_ZoneConnectionChoice->SetSelection( 3 );
285  break;
286  }
287 
288  // 3D Settings
289 
290  wxString default_path;
291  wxGetEnv( KICAD6_3DMODEL_DIR, &default_path );
292 #ifdef __WINDOWS__
293  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
294 #endif
295 
296  m_shapes3D_list.clear();
297  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
298 
299  wxString origPath, alias, shortPath;
300  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
301 
302  for( const FP_3DMODEL& model : m_footprint->Models() )
303  {
304  m_shapes3D_list.push_back( model );
305  origPath = model.m_Filename;
306 
307  if( res && res->SplitAlias( origPath, alias, shortPath ) )
308  origPath = alias + wxT( ":" ) + shortPath;
309 
310  m_modelsGrid->AppendRows( 1 );
311  int row = m_modelsGrid->GetNumberRows() - 1;
312  m_modelsGrid->SetCellValue( row, 0, origPath );
313  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
314  }
315 
316  select3DModel( 0 ); // will clamp idx within bounds
318 
319  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
320  {
321  // Adjust min size to the column label size
322  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
323  false ) );
324  // Adjust the column size.
325  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
326 
327  if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
328  {
329  BOARD* board = m_footprint->GetBoard();
330 
331  for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
332  col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
333 
334  // And the swatch:
335  col_size += 20;
336  }
337 
338  if( m_itemsGrid->IsColShown( col ) )
339  m_itemsGrid->SetColSize( col, col_size );
340  }
341 
342  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) );
343  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
344 
345  Layout();
346  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
347 
348  return true;
349 }
350 
351 
353 {
354  m_inSelect = true;
355 
356  aModelIdx = std::max( 0, aModelIdx );
357  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
358 
359  if( m_modelsGrid->GetNumberRows() )
360  {
361  m_modelsGrid->SelectRow( aModelIdx );
362  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
363  }
364 
365  m_PreviewPane->SetSelectedModel( aModelIdx );
366 
367  m_inSelect = false;
368 }
369 
370 
372 {
373  if( !m_inSelect )
374  select3DModel( aEvent.GetRow() );
375 }
376 
377 
379 {
380  if( aEvent.GetCol() == 0 )
381  {
382  bool hasAlias = false;
383  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
384  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
385 
386  filename.Replace( "\n", "" );
387  filename.Replace( "\r", "" );
388  filename.Replace( "\t", "" );
389 
390  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
391  {
392  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
394  m_delayedFocusRow = aEvent.GetRow();
395  m_delayedFocusColumn = aEvent.GetCol();
396  m_delayedFocusPage = 2;
397  aEvent.Veto();
398  }
399 
400  // if the user has specified an alias in the name then prepend ':'
401  if( hasAlias )
402  filename.insert( 0, wxT( ":" ) );
403 
404 #ifdef __WINDOWS__
405  // In Kicad files, filenames and paths are stored using Unix notation
406  filename.Replace( wxT( "\\" ), wxT( "/" ) );
407 #endif
408 
409  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
410  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
411  }
412  else if( aEvent.GetCol() == 1 )
413  {
414  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
415 
416  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
417  }
418 
420 }
421 
422 
424 {
426  return;
427 
428  int idx = m_modelsGrid->GetGridCursorRow();
429 
430  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
431  {
432  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
433  m_modelsGrid->DeleteRows( idx );
434 
435  select3DModel( idx ); // will clamp idx within bounds
437  }
438 }
439 
440 
442 {
444  return;
445 
446  int selected = m_modelsGrid->GetGridCursorRow();
447 
448  PROJECT& prj = Prj();
449  FP_3DMODEL model;
450 
451  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
452  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
453  int filter = 0;
454 
455  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment
456  // varaible and fall back to the project path if necessary.
457  if( initialpath.IsEmpty() )
458  {
459  if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() )
460  initialpath = prj.GetProjectPath();
461  }
462 
463  if( !sidx.empty() )
464  {
465  long tmp;
466  sidx.ToLong( &tmp );
467 
468  if( tmp > 0 && tmp <= INT_MAX )
469  filter = (int) tmp;
470  }
471 
472  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
473  || model.m_Filename.empty() )
474  {
475  select3DModel( selected );
476  return;
477  }
478 
479  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
480  sidx = wxString::Format( wxT( "%i" ), filter );
482  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
483  wxString alias;
484  wxString shortPath;
485  wxString filename = model.m_Filename;
486 
487  if( res && res->SplitAlias( filename, alias, shortPath ) )
488  filename = alias + wxT( ":" ) + shortPath;
489 
490 #ifdef __WINDOWS__
491  // In Kicad files, filenames and paths are stored using Unix notation
492  model.m_Filename.Replace( "\\", "/" );
493 #endif
494 
495  model.m_Show = true;
496  m_shapes3D_list.push_back( model );
497 
498  int idx = m_modelsGrid->GetNumberRows();
499  m_modelsGrid->AppendRows( 1 );
500  m_modelsGrid->SetCellValue( idx, 0, filename );
501  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
502 
503  select3DModel( idx );
505 }
506 
507 
509 {
511  return;
512 
513  FP_3DMODEL model;
514 
515  model.m_Show = true;
516  m_shapes3D_list.push_back( model );
517 
518  int row = m_modelsGrid->GetNumberRows();
519  m_modelsGrid->AppendRows( 1 );
520  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
521 
522  select3DModel( row );
523 
524  m_modelsGrid->SetFocus();
525  m_modelsGrid->MakeCellVisible( row, 0 );
526  m_modelsGrid->SetGridCursor( row, 0 );
527 
528  m_modelsGrid->EnableCellEditControl( true );
529  m_modelsGrid->ShowCellEditControl();
530 }
531 
532 
533 bool DIALOG_FOOTPRINT_FP_EDITOR::checkFootprintName( const wxString& aFootprintName )
534 {
535  if( aFootprintName.IsEmpty() )
536  {
537  m_delayedErrorMessage = _( "Footprint must have a name." );
538  return false;
539  }
540  else if( !FOOTPRINT::IsLibNameValid( aFootprintName ) )
541  {
542  m_delayedErrorMessage.Printf( _( "Footprint name may not contain \"%s\"." ),
544  return false;
545  }
546 
547  return true;
548 }
549 
550 
552 {
554  return false;
555 
556  if( !DIALOG_SHIM::Validate() )
557  return false;
558 
559  // First, test for invalid chars in footprint name
560  wxString footprintName = m_FootprintNameCtrl->GetValue();
561 
562  if( !checkFootprintName( footprintName ) )
563  {
564  if( m_NoteBook->GetSelection() != 0 )
565  m_NoteBook->SetSelection( 0 );
566 
568  m_delayedFocusPage = 0;
569 
570  return false;
571  }
572 
573  // Check for empty texts.
574  for( size_t i = 2; i < m_texts->size(); ++i )
575  {
576  FP_TEXT& text = m_texts->at( i );
577 
578  if( text.GetText().IsEmpty() )
579  {
580  if( m_NoteBook->GetSelection() != 0 )
581  m_NoteBook->SetSelection( 0 );
582 
583  m_delayedErrorMessage = _( "Text items must have some content." );
586  m_delayedFocusRow = i;
587 
588  return false;
589  }
590  }
591 
592  if( !m_netClearance.Validate( 0, INT_MAX ) )
593  return false;
594 
595  return true;
596 }
597 
598 
600 {
601  if( !Validate() )
602  return false;
603 
604  if( !DIALOG_SHIM::TransferDataFromWindow() )
605  return false;
606 
607  if( !m_PanelGeneral->TransferDataFromWindow() )
608  return false;
609 
610  if( !m_Panel3D->TransferDataFromWindow() )
611  return false;
612 
613  auto view = m_frame->GetCanvas()->GetView();
614  BOARD_COMMIT commit( m_frame );
615  commit.Modify( m_footprint );
616 
617  LIB_ID fpID = m_footprint->GetFPID();
618  fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false );
619  m_footprint->SetFPID( fpID );
620 
621  m_footprint->SetDescription( m_DocCtrl->GetValue() );
622  m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
623 
624  // copy reference and value
625  m_footprint->Reference() = m_texts->at( 0 );
626  m_footprint->Value() = m_texts->at( 1 );
627 
628  size_t i = 2;
629  std::vector<FP_TEXT*> items_to_remove;
630 
631  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
632  {
633  FP_TEXT* textItem = dynamic_cast<FP_TEXT*>( item );
634 
635  if( textItem )
636  {
637  // copy grid table entries till we run out, then delete any remaining texts
638  if( i < m_texts->size() )
639  *textItem = m_texts->at( i++ );
640  else // store this item to remove and delete it later,
641  // after the graphic list is explored:
642  items_to_remove.push_back( textItem );
643  }
644  }
645 
646  // Remove text items:
648 
649  for( FP_TEXT* item: items_to_remove )
650  {
651  selTool->RemoveItemFromSel( item );
652  view->Remove( item );
653  item->DeleteStructure();
654  }
655 
656  // if there are still grid table entries, create new texts for them
657  while( i < m_texts->size() )
658  {
659  FP_TEXT* newText = new FP_TEXT( m_texts->at( i++ ) );
660  m_footprint->Add( newText, ADD_MODE::APPEND );
661  view->Add( newText );
662  }
663 
664  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
665 
666  int attributes = 0;
667 
668  switch( m_componentType->GetSelection() )
669  {
670  case 0: attributes |= FP_THROUGH_HOLE; break;
671  case 1: attributes |= FP_SMD; break;
672  default: break;
673  }
674 
675  if( m_boardOnly->GetValue() )
676  attributes |= FP_BOARD_ONLY;
677 
678  if( m_excludeFromPosFiles->GetValue() )
679  attributes |= FP_EXCLUDE_FROM_POS_FILES;
680 
681  if( m_excludeFromBOM->GetValue() )
682  attributes |= FP_EXCLUDE_FROM_BOM;
683 
684  m_footprint->SetAttributes( attributes );
685 
688 
689  // Initialize masks clearances
693 
694  double dtmp = 0.0;
695  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
696  msg.ToDouble( &dtmp );
697 
698  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
699  if( dtmp < -50.0 )
700  dtmp = -50.0;
701  // A margin ratio is always <= 0
702  // 0 means use full pad copper area
703  if( dtmp > 0.0 )
704  dtmp = 0.0;
705 
707 
708  switch( m_ZoneConnectionChoice->GetSelection() )
709  {
710  default:
715  }
716 
717  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
718  draw3D->clear();
719  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
720 
721  commit.Push( _( "Modify footprint properties" ) );
722 
723  return true;
724 }
725 
726 
727 static bool footprintIsFromBoard( FOOTPRINT* aFootprint )
728 {
729  return aFootprint->GetLink() != niluuid;
730 }
731 
732 
734 {
735  // Currently: nothing to do
736 }
737 
738 
740 {
742  {
743  // Currently: nothing to do
744  }
745 }
746 
747 
748 void DIALOG_FOOTPRINT_FP_EDITOR::OnAddField( wxCommandEvent& event )
749 {
751  return;
752 
753  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
754  FP_TEXT textItem( m_footprint );
755 
756  // Set active layer if legal; otherwise copy layer from previous text item
758  textItem.SetLayer( m_frame->GetActiveLayer() );
759  else
760  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
761 
762  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
763  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
764  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
765 
766  m_texts->push_back( textItem );
767 
768  // notify the grid
769  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
770  m_itemsGrid->ProcessTableMessage( msg );
771 
772  m_itemsGrid->SetFocus();
773  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
774  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
775 
776  m_itemsGrid->EnableCellEditControl( true );
777  m_itemsGrid->ShowCellEditControl();
778 }
779 
780 
781 void DIALOG_FOOTPRINT_FP_EDITOR::OnDeleteField( wxCommandEvent& event )
782 {
784  return;
785 
786  int curRow = m_itemsGrid->GetGridCursorRow();
787 
788  if( curRow < 0 )
789  return;
790  else if( curRow < 2 )
791  {
792  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
793  return;
794  }
795 
796  m_texts->erase( m_texts->begin() + curRow );
797 
798  // notify the grid
799  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
800  m_itemsGrid->ProcessTableMessage( msg );
801 
802  if( m_itemsGrid->GetNumberRows() > 0 )
803  {
804  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
805  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
806  }
807 }
808 
809 
810 void DIALOG_FOOTPRINT_FP_EDITOR::Cfg3DPath( wxCommandEvent& event )
811 {
812  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
814 }
815 
816 
818 {
819  // Account for scroll bars
820  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
821  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
822 
823  itemsWidth -= m_itemsGrid->GetRowLabelSize();
824 
825  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
826  itemsWidth -= m_itemsGrid->GetColSize( i );
827 
828  if( itemsWidth > 0 )
829  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
830  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
831 
832  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
833 }
834 
835 
836 void DIALOG_FOOTPRINT_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event )
837 {
838  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
839  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
840 
841  if( m_itemsGrid->IsCellEditControlShown() )
842  {
843  // Currently: nonthing to do
844  }
845 
846  // Handle a delayed focus. The delay allows us to:
847  // a) change focus when the error was triggered from within a killFocus handler
848  // b) show the correct notebook page in the background before the error dialog comes up
849  // when triggered from an OK or a notebook page change
850 
851  if( m_delayedFocusPage >= 0 )
852  {
853  if( m_NoteBook->GetSelection() != m_delayedFocusPage )
854  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
855 
856  m_delayedFocusPage = -1;
857  }
858 
859  if( !m_delayedErrorMessage.IsEmpty() )
860  {
861  // We will re-enter this routine when the error dialog is displayed, so make
862  // sure we don't keep putting up more dialogs.
863  wxString msg = m_delayedErrorMessage;
864  m_delayedErrorMessage = wxEmptyString;
865 
866  // Do not use DisplayErrorMessage(); it screws up window order on Mac
867  DisplayError( nullptr, msg );
868  }
869 
870  if( m_delayedFocusCtrl )
871  {
872  m_delayedFocusCtrl->SetFocus();
873 
874  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
875  textEntry->SelectAll();
876 
877  m_delayedFocusCtrl = nullptr;
878  }
879  else if( m_delayedFocusGrid )
880  {
881  m_delayedFocusGrid->SetFocus();
884 
885  m_delayedFocusGrid->EnableCellEditControl( true );
886  m_delayedFocusGrid->ShowCellEditControl();
887 
888  m_delayedFocusGrid = nullptr;
889  m_delayedFocusRow = -1;
891  }
892 
893  m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
894 }
895 
896 
897 void DIALOG_FOOTPRINT_FP_EDITOR::OnGridSize( wxSizeEvent& event )
898 {
899  adjustGridColumns( event.GetSize().GetX() );
900 
901  event.Skip();
902 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:253
void Cfg3DPath(wxCommandEvent &event) override
bool IsLocked() const override
Definition: footprint.h:279
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:193
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
KIID niluuid(0)
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
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
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
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
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
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:220
void OnFootprintNameText(wxCommandEvent &event) override
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
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
void OnAdd3DModel(wxCommandEvent &event) override
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 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
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
void SetDescription(const wxString &aDoc)
Definition: footprint.h:194
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:460
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
void OnAddField(wxCommandEvent &event) override
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
void On3DModelCellChanged(wxGridEvent &aEvent) override
PCB_LAYER_ID
A quick note on layer IDs:
pads are covered by copper
void OnUpdateUI(wxUpdateUIEvent &event) override
#define NULL
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
DIALOG_FOOTPRINT_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
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 SetSelectedModel(int idx)
Set the currently selected index in the model list so that the scale/rotation/offset controls can be ...
const wxString & GetKeywords() const
Definition: footprint.h:196
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
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:204
KIID GetLink() const
Definition: footprint.h:528
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 OnGridSize(wxSizeEvent &event) override
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:191
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:110
void OnAdd3DRow(wxCommandEvent &event) override
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
void OnRemove3DModel(wxCommandEvent &event) override
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:189
#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.
void SetKeywords(const wxString &aKeywords)
Definition: footprint.h:197
void SetLocked(bool isLocked) override
Set the #MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: footprint.h:289
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: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)
void OnDeleteField(wxCommandEvent &event) override
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
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:1308
int GetLocalSolderPasteMargin() const
Definition: footprint.h:216
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:467
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Returns true if the given path is a valid aliased relative path.
static bool footprintIsFromBoard(FOOTPRINT *aFootprint)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
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.
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:1319
void SetPlacementCost90(int aCost)
Definition: footprint.h:535
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:203
Container for design settings for a BOARD object.
bool checkFootprintName(const wxString &aFootprintName)
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:217