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-2019 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>
28 #include <dialog_text_entry.h>
30 #include <pcb_edit_frame.h>
31 #include <validators.h>
32 #include <board_design_settings.h>
33 #include <board_commit.h>
34 #include <bitmaps.h>
36 #include <widgets/wx_grid.h>
37 #include <widgets/text_ctrl_eval.h>
38 #include <class_module.h>
39 #include <footprint_edit_frame.h>
42 #include "filename_resolver.h"
43 #include <pgm_base.h>
47 
48 #include <fp_lib_table.h>
49 
50 
51 int DIALOG_FOOTPRINT_FP_EDITOR::m_page = 0; // remember the last open page during session
52 
53 
55  MODULE* aModule ) :
57  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
58  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
59  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
60  m_inSelect( false )
61 {
62  m_frame = aParent;
63  m_footprint = aModule;
64 
66 
67  m_delayedErrorMessage = wxEmptyString;
68  m_delayedFocusCtrl = nullptr;
69  m_delayedFocusGrid = nullptr;
70  m_delayedFocusRow = -1;
72  m_delayedFocusPage = -1;
73 
74  // Give an icon
75  wxIcon icon;
76  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
77  SetIcon( icon );
78 
79  // Give a bit more room for combobox editors
80  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
81  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
82 
84  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
85  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
86 
87  // Show/hide columns according to the user's preference
89 
90  PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
91  if( cfg->m_lastFootprint3dDir.IsEmpty() )
92  {
93  wxGetEnv( KISYS3DMOD, &cfg->m_lastFootprint3dDir );
94  }
95 
96  wxGridCellAttr* attr = new wxGridCellAttr;
97  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
98  true, Prj().GetProjectPath() ) );
99  m_modelsGrid->SetColAttr( 0, attr );
100 
101  // Show checkbox
102  attr = new wxGridCellAttr;
103  attr->SetRenderer( new wxGridCellBoolRenderer() );
104  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
105  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
106  m_modelsGrid->SetColAttr( 1, attr );
107  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
108 
109  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
110 
112 
113  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
114 
116 
117  // Set font sizes
118  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
119  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
120 #if __WXMAC__
121  m_allow90Label->SetFont( infoFont );
122  m_allow180Label->SetFont( infoFont );
123 #endif
124  m_staticTextInfoCopper->SetFont( infoFont );
125  m_staticTextInfoPaste->SetFont( infoFont );
126 
127  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
128  m_staticTextInfoValNeg->SetFont( infoFont );
129  m_staticTextInfoValPos->SetFont( infoFont );
130 
131  if( m_page >= 0 )
132  m_NoteBook->SetSelection( (unsigned) m_page );
133 
134  if( m_page == 0 )
135  {
137  m_delayedFocusRow = 0;
139  m_delayedFocusPage = 0;
140  }
141  else if ( m_page == 1 )
143  else
144  {
146  m_delayedFocusRow = 0;
148  m_delayedFocusPage = 2;
149  }
150 
151  m_sdbSizerStdButtonsOK->SetDefault();
152 
153  // Configure button logos
154  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
155  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
156  m_button3DShapeAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
157  m_button3DShapeBrowse->SetBitmap( KiBitmap( folder_xpm ) );
158  m_button3DShapeRemove->SetBitmap( KiBitmap( trash_xpm ) );
159 
160  // wxFormBuilder doesn't include this event...
161  m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
162 
164 }
165 
166 
168 {
170  m_itemsGrid->GetShownColumns().ToStdString();
171 
172  // Prevents crash bug in wxGrid's d'tor
174 
175  m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
176 
177  // Delete the GRID_TRICKS.
178  m_itemsGrid->PopEventHandler( true );
179  m_modelsGrid->PopEventHandler( true );
180 
181  // free the memory used by all models, otherwise models which were
182  // browsed but not used would consume memory
183  Prj().Get3DCacheManager()->FlushCache( false );
184 
185  // the GL canvas has to be visible before it is destroyed
186  m_page = m_NoteBook->GetSelection();
187  m_NoteBook->SetSelection( 1 );
188 
189  delete m_PreviewPane;
190 }
191 
192 
194 {
195  LIB_ID fpID = m_footprint->GetFPID();
196  wxString footprintName = fpID.GetLibItemName();
197 
198  m_FootprintNameCtrl->ChangeValue( footprintName );
199 
200  m_DocCtrl->SetValue( m_footprint->GetDescription() );
201  m_KeywordCtrl->SetValue( m_footprint->GetKeywords() );
202 
203  if( !wxDialog::TransferDataToWindow() )
204  return false;
205 
206  if( !m_PanelGeneral->TransferDataToWindow() )
207  return false;
208 
209  if( !m_Panel3D->TransferDataToWindow() )
210  return false;
211 
212  // Module Texts
213 
214  m_texts->push_back( m_footprint->Reference() );
215  m_texts->push_back( m_footprint->Value() );
216 
217  for( auto item : m_footprint->GraphicalItems() )
218  {
219  auto textItem = dyn_cast<FP_TEXT*>( item );
220 
221  if( textItem )
222  m_texts->push_back( *textItem );
223  }
224 
225  // notify the grid
226  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
227  m_itemsGrid->ProcessTableMessage( tmsg );
228 
229  // Module Properties
230 
231  m_AutoPlaceCtrl->SetSelection( (m_footprint->IsLocked()) ? 1 : 0 );
232  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Enable hotkey move commands and Auto Placement" ) );
233  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Disable hotkey move commands and Auto Placement" ) );
234 
237 
239  m_componentType->SetSelection( 0 );
240  else if( m_footprint->GetAttributes() & MOD_SMD )
241  m_componentType->SetSelection( 1 );
242  else
243  m_componentType->SetSelection( 2 );
244 
248 
249  // Local Clearances
250 
254 
255  // Prefer "-0" to "0" for normally negative values
257  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
258 
259  // Add solder paste margin ratio in percent
260  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
261  wxString msg;
262  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
263 
265  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
266  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
267  else
269 
270  switch( m_footprint->GetZoneConnection() )
271  {
272  default:
274  m_ZoneConnectionChoice->SetSelection( 0 );
275  break;
277  m_ZoneConnectionChoice->SetSelection( 1 );
278  break;
280  m_ZoneConnectionChoice->SetSelection( 2 );
281  break;
283  m_ZoneConnectionChoice->SetSelection( 3 );
284  break;
285  }
286 
287  // 3D Settings
288 
289  wxString default_path;
290  wxGetEnv( KISYS3DMOD, &default_path );
291 #ifdef __WINDOWS__
292  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
293 #endif
294 
295  m_shapes3D_list.clear();
296  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
297 
298  wxString origPath, alias, shortPath;
299  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
300 
301  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
302  {
303  m_shapes3D_list.push_back( model );
304  origPath = model.m_Filename;
305 
306  if( res && res->SplitAlias( origPath, alias, shortPath ) )
307  origPath = alias + wxT( ":" ) + shortPath;
308 
309  m_modelsGrid->AppendRows( 1 );
310  int row = m_modelsGrid->GetNumberRows() - 1;
311  m_modelsGrid->SetCellValue( row, 0, origPath );
312  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
313  }
314 
315  select3DModel( 0 ); // will clamp idx within bounds
316 
317  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
318  {
319  // Adjust min size to the column label size
320  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false, false ) );
321  // Adjust the column size. The column 6 has a small bitmap, so its width must be taken in account
322  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
323 
324  if( col == 6 )
325  col_size += 20;
326 
327  if( m_itemsGrid->IsColShown( col ) )
328  m_itemsGrid->SetColSize( col, col_size );
329  }
330 
331  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) );
332  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
333 
334  Layout();
335  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
336 
337  return true;
338 }
339 
340 
342 {
343  m_inSelect = true;
344 
345  aModelIdx = std::max( 0, aModelIdx );
346  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
347 
348  if( m_modelsGrid->GetNumberRows() )
349  {
350  m_modelsGrid->SelectRow( aModelIdx );
351  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
352  }
353 
354  m_PreviewPane->SetSelectedModel( aModelIdx );
355 
356  m_inSelect = false;
357 }
358 
359 
361 {
362  if( !m_inSelect )
363  select3DModel( aEvent.GetRow() );
364 }
365 
366 
368 {
369  if( aEvent.GetCol() == 0 )
370  {
371  bool hasAlias = false;
372  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
373  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
374 
375  filename.Replace( "\n", "" );
376  filename.Replace( "\r", "" );
377  filename.Replace( "\t", "" );
378 
379  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
380  {
381  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
383  m_delayedFocusRow = aEvent.GetRow();
384  m_delayedFocusColumn = aEvent.GetCol();
385  m_delayedFocusPage = 2;
386  aEvent.Veto();
387  }
388 
389  // if the user has specified an alias in the name then prepend ':'
390  if( hasAlias )
391  filename.insert( 0, wxT( ":" ) );
392 
393 #ifdef __WINDOWS__
394  // In Kicad files, filenames and paths are stored using Unix notation
395  filename.Replace( wxT( "\\" ), wxT( "/" ) );
396 #endif
397 
398  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
399  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
400  }
401  else if( aEvent.GetCol() == 1 )
402  {
403  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
404 
405  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
406  }
407 
409 }
410 
411 
413 {
415  return;
416 
417  int idx = m_modelsGrid->GetGridCursorRow();
418 
419  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
420  {
421  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
422  m_modelsGrid->DeleteRows( idx );
423 
424  select3DModel( idx ); // will clamp idx within bounds
426  }
427 }
428 
429 
431 {
433  return;
434 
435  int selected = m_modelsGrid->GetGridCursorRow();
436 
437  PROJECT& prj = Prj();
438  MODULE_3D_SETTINGS model;
439 
440  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
441  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
442  int filter = 0;
443 
444  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
445  // varaible and fall back to the project path if necessary.
446  if( initialpath.IsEmpty() )
447  {
448  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
449  initialpath = prj.GetProjectPath();
450  }
451 
452  if( !sidx.empty() )
453  {
454  long tmp;
455  sidx.ToLong( &tmp );
456 
457  if( tmp > 0 && tmp <= INT_MAX )
458  filter = (int) tmp;
459  }
460 
461  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
462  || model.m_Filename.empty() )
463  {
464  select3DModel( selected );
465  return;
466  }
467 
468  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
469  sidx = wxString::Format( wxT( "%i" ), filter );
471  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
472  wxString alias;
473  wxString shortPath;
474  wxString filename = model.m_Filename;
475 
476  if( res && res->SplitAlias( filename, alias, shortPath ) )
477  filename = alias + wxT( ":" ) + shortPath;
478 
479 #ifdef __WINDOWS__
480  // In Kicad files, filenames and paths are stored using Unix notation
481  model.m_Filename.Replace( "\\", "/" );
482 #endif
483 
484  model.m_Show = true;
485  m_shapes3D_list.push_back( model );
486 
487  int idx = m_modelsGrid->GetNumberRows();
488  m_modelsGrid->AppendRows( 1 );
489  m_modelsGrid->SetCellValue( idx, 0, filename );
490  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
491 
492  select3DModel( idx );
494 }
495 
496 
498 {
500  return;
501 
502  MODULE_3D_SETTINGS model;
503 
504  model.m_Show = true;
505  m_shapes3D_list.push_back( model );
506 
507  int row = m_modelsGrid->GetNumberRows();
508  m_modelsGrid->AppendRows( 1 );
509  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
510 
511  select3DModel( row );
512 
513  m_modelsGrid->SetFocus();
514  m_modelsGrid->MakeCellVisible( row, 0 );
515  m_modelsGrid->SetGridCursor( row, 0 );
516 
517  m_modelsGrid->EnableCellEditControl( true );
518  m_modelsGrid->ShowCellEditControl();
519 }
520 
521 
522 bool DIALOG_FOOTPRINT_FP_EDITOR::checkFootprintName( const wxString& aFootprintName )
523 {
524  if( aFootprintName.IsEmpty() )
525  {
526  m_delayedErrorMessage = _( "Footprint must have a name." );
527  return false;
528  }
529  else if( !MODULE::IsLibNameValid( aFootprintName ) )
530  {
531  m_delayedErrorMessage.Printf( _( "Footprint name may not contain \"%s\"." ),
533  return false;
534  }
535 
536  return true;
537 }
538 
539 
541 {
543  return false;
544 
545  if( !DIALOG_SHIM::Validate() )
546  return false;
547 
548  // First, test for invalid chars in module name
549  wxString footprintName = m_FootprintNameCtrl->GetValue();
550 
551  if( !checkFootprintName( footprintName ) )
552  {
553  if( m_NoteBook->GetSelection() != 0 )
554  m_NoteBook->SetSelection( 0 );
555 
557  m_delayedFocusPage = 0;
558 
559  return false;
560  }
561 
562  // Check for empty texts.
563  for( size_t i = 2; i < m_texts->size(); ++i )
564  {
565  FP_TEXT& text = m_texts->at( i );
566 
567  if( text.GetText().IsEmpty() )
568  {
569  if( m_NoteBook->GetSelection() != 0 )
570  m_NoteBook->SetSelection( 0 );
571 
572  m_delayedErrorMessage = _( "Text items must have some content." );
575  m_delayedFocusRow = i;
576 
577  return false;
578  }
579  }
580 
581  if( !m_netClearance.Validate( 0, INT_MAX ) )
582  return false;
583 
584  return true;
585 }
586 
587 
589 {
590  if( !Validate() )
591  return false;
592 
593  if( !DIALOG_SHIM::TransferDataFromWindow() )
594  return false;
595 
596  if( !m_PanelGeneral->TransferDataFromWindow() )
597  return false;
598 
599  if( !m_Panel3D->TransferDataFromWindow() )
600  return false;
601 
602  auto view = m_frame->GetCanvas()->GetView();
603  BOARD_COMMIT commit( m_frame );
604  commit.Modify( m_footprint );
605 
606  LIB_ID fpID = m_footprint->GetFPID();
607  fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false );
608  m_footprint->SetFPID( fpID );
609 
610  m_footprint->SetDescription( m_DocCtrl->GetValue() );
611  m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
612 
613  // copy reference and value
614  m_footprint->Reference() = m_texts->at( 0 );
615  m_footprint->Value() = m_texts->at( 1 );
616 
617  size_t i = 2;
618  std::vector<FP_TEXT*> items_to_remove;
619 
620  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
621  {
622  FP_TEXT* textItem = dynamic_cast<FP_TEXT*>( item );
623 
624  if( textItem )
625  {
626  // copy grid table entries till we run out, then delete any remaining texts
627  if( i < m_texts->size() )
628  *textItem = m_texts->at( i++ );
629  else // store this item to remove and delete it later,
630  // after the graphic list is explored:
631  items_to_remove.push_back( textItem );
632  }
633  }
634 
635  // Remove items from m_footprint graphic list:
636  for( FP_TEXT* item: items_to_remove )
637  item->DeleteStructure();
638 
639  // if there are still grid table entries, create new texts for them
640  while( i < m_texts->size() )
641  {
642  FP_TEXT* newText = new FP_TEXT( m_texts->at( i++ ) );
643  m_footprint->Add( newText, ADD_MODE::APPEND );
644  view->Add( newText );
645  }
646 
647  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
648 
649  int attributes = 0;
650 
651  switch( m_componentType->GetSelection() )
652  {
653  case 0: attributes |= MOD_THROUGH_HOLE; break;
654  case 1: attributes |= MOD_SMD; break;
655  default: break;
656  }
657 
658  if( m_boardOnly->GetValue() )
659  attributes |= MOD_BOARD_ONLY;
660 
661  if( m_excludeFromPosFiles->GetValue() )
662  attributes |= MOD_EXCLUDE_FROM_POS_FILES;
663 
664  if( m_excludeFromBOM->GetValue() )
665  attributes |= MOD_EXCLUDE_FROM_BOM;
666 
667  m_footprint->SetAttributes( attributes );
668 
671 
672  // Initialize masks clearances
676 
677  double dtmp = 0.0;
678  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
679  msg.ToDouble( &dtmp );
680 
681  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
682  if( dtmp < -50.0 )
683  dtmp = -50.0;
684  // A margin ratio is always <= 0
685  // 0 means use full pad copper area
686  if( dtmp > 0.0 )
687  dtmp = 0.0;
688 
690 
691  switch( m_ZoneConnectionChoice->GetSelection() )
692  {
693  default:
698  }
699 
700  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
701  draw3D->clear();
702  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
703 
705 
706  commit.Push( _( "Modify module properties" ) );
707 
708  return true;
709 }
710 
711 
712 static bool footprintIsFromBoard( MODULE* aFootprint )
713 {
714  return aFootprint->GetLink() != niluuid;
715 }
716 
717 
719 {
720  // Currently: nothing to do
721 }
722 
723 
725 {
727  {
728  // Currently: nothing to do
729  }
730 }
731 
732 
733 void DIALOG_FOOTPRINT_FP_EDITOR::OnAddField( wxCommandEvent& event )
734 {
736  return;
737 
738  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
739  FP_TEXT textItem( m_footprint );
740 
741  // Set active layer if legal; otherwise copy layer from previous text item
743  textItem.SetLayer( m_frame->GetActiveLayer() );
744  else
745  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
746 
747  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
748  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
749  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
750 
751  m_texts->push_back( textItem );
752 
753  // notify the grid
754  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
755  m_itemsGrid->ProcessTableMessage( msg );
756 
757  m_itemsGrid->SetFocus();
758  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
759  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
760 
761  m_itemsGrid->EnableCellEditControl( true );
762  m_itemsGrid->ShowCellEditControl();
763 }
764 
765 
766 void DIALOG_FOOTPRINT_FP_EDITOR::OnDeleteField( wxCommandEvent& event )
767 {
769  return;
770 
771  int curRow = m_itemsGrid->GetGridCursorRow();
772 
773  if( curRow < 0 )
774  return;
775  else if( curRow < 2 )
776  {
777  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
778  return;
779  }
780 
781  m_texts->erase( m_texts->begin() + curRow );
782 
783  // notify the grid
784  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
785  m_itemsGrid->ProcessTableMessage( msg );
786 
787  if( m_itemsGrid->GetNumberRows() > 0 )
788  {
789  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
790  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
791  }
792 }
793 
794 
795 void DIALOG_FOOTPRINT_FP_EDITOR::Cfg3DPath( wxCommandEvent& event )
796 {
797  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
799 }
800 
801 
803 {
804  // Account for scroll bars
805  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
806  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
807 
808  itemsWidth -= m_itemsGrid->GetRowLabelSize();
809 
810  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
811  itemsWidth -= m_itemsGrid->GetColSize( i );
812 
813  if( itemsWidth > 0 )
814  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
815  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
816 
817  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
818 }
819 
820 
821 void DIALOG_FOOTPRINT_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event )
822 {
823  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
824  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
825 
826  if( m_itemsGrid->IsCellEditControlShown() )
827  {
828  // Currently: nonthing to do
829  }
830 
831  // Handle a delayed focus. The delay allows us to:
832  // a) change focus when the error was triggered from within a killFocus handler
833  // b) show the correct notebook page in the background before the error dialog comes up
834  // when triggered from an OK or a notebook page change
835 
836  if( m_delayedFocusPage >= 0 )
837  {
838  if( m_NoteBook->GetSelection() != m_delayedFocusPage )
839  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
840 
841  m_delayedFocusPage = -1;
842  }
843 
844  if( !m_delayedErrorMessage.IsEmpty() )
845  {
846  // We will re-enter this routine when the error dialog is displayed, so make
847  // sure we don't keep putting up more dialogs.
848  wxString msg = m_delayedErrorMessage;
849  m_delayedErrorMessage = wxEmptyString;
850 
851  // Do not use DisplayErrorMessage(); it screws up window order on Mac
852  DisplayError( nullptr, msg );
853  }
854 
855  if( m_delayedFocusCtrl )
856  {
857  m_delayedFocusCtrl->SetFocus();
858 
859  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
860  textEntry->SelectAll();
861 
862  m_delayedFocusCtrl = nullptr;
863  }
864  else if( m_delayedFocusGrid )
865  {
866  m_delayedFocusGrid->SetFocus();
869 
870  m_delayedFocusGrid->EnableCellEditControl( true );
871  m_delayedFocusGrid->ShowCellEditControl();
872 
873  m_delayedFocusGrid = nullptr;
874  m_delayedFocusRow = -1;
876  }
877 
878  m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
879 }
880 
881 
882 void DIALOG_FOOTPRINT_FP_EDITOR::OnGridSize( wxSizeEvent& event )
883 {
884  adjustGridColumns( event.GetSize().GetX());
885 
886  event.Skip();
887 }
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
void Cfg3DPath(wxCommandEvent &event) override
void SetPlacementCost90(int aCost)
Definition: class_module.h:558
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
int GetAttributes() const
Definition: class_module.h:251
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:557
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
KIID niluuid(0)
PROJECT holds project specific data.
Definition: project.h:63
void SetLocalClearance(int aClearance)
Definition: class_module.h:226
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:555
This file is part of the common library.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:127
FP_TEXT & Value()
read/write accessors:
Definition: class_module.h:475
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
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
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:243
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:52
provides an extensible class to resolve 3D model paths.
bool m_Show
Include module in rendering.
Definition: class_module.h:98
void OnFootprintNameText(wxCommandEvent &event) override
const LIB_ID & GetFPID() const
Definition: class_module.h:210
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
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:65
DRAWINGS & GraphicalItems()
Definition: class_module.h:185
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
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:819
void OnAdd3DModel(wxCommandEvent &event) override
int GetLocalSolderMaskMargin() const
Definition: class_module.h:222
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:121
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:240
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
void UpdateDummyFootprint(bool aRelaodRequired=true)
UpdateModelInfoList - copy shapes from the current shape list which are flagged for preview to the co...
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 & Reference()
Definition: class_module.h:476
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
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)
Function SplitAlias returns true if the given name contains an alias and populates the string anAlias...
void On3DModelCellChanged(wxGridEvent &aEvent) override
pads are covered by copper
void OnUpdateUI(wxUpdateUIEvent &event) override
int GetLocalClearance() const
Definition: class_module.h:225
#define NULL
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
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 SetSelectedModel(int idx)
SetModelDataIdx - Sets the currently selected index in the model list so that the scale/rotation/offs...
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:293
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
const wxString & GetKeywords() const
Definition: class_module.h:216
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:223
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:206
int GetLocalSolderPasteMargin() const
Definition: class_module.h:236
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
const BITMAP_OPAQUE icon_modedit_xpm[1]
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:97
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:211
int GetPlacementCost180() const
Definition: class_module.h:554
EDA_UNITS m_units
Definition: dialog_shim.h:198
void OnGridSize(wxSizeEvent &event) override
static bool IsLibNameValid(const wxString &aName)
static function IsLibNameValid Test for validity of a name of a footprint to be used in a footprint l...
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:109
void OnAdd3DRow(wxCommandEvent &event) override
const wxString & GetDescription() const
Definition: class_module.h:213
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:237
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:226
void OnRemove3DModel(wxCommandEvent &event) override
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:239
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:196
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.
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:303
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:242
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
Pads are not covered.
KIID GetLink() const
Definition: class_module.h:551
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)
void SetKeywords(const wxString &aKeywords)
Definition: class_module.h:217
void OnDeleteField(wxCommandEvent &event) override
DIALOG_FOOTPRINT_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, MODULE *aModule)
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
static bool footprintIsFromBoard(MODULE *aFootprint)
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
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.
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:211
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 SetAttributes(int aAttributes)
Definition: class_module.h:252
int GetNumberRows() override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
bool checkFootprintName(const wxString &aFootprintName)
void SetDescription(const wxString &aDoc)
Definition: class_module.h:214
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list