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 <fctsys.h>
28 #include <confirm.h>
29 #include <dialog_text_entry.h>
30 #include <pcbnew.h>
31 #include <kiface_i.h>
33 #include <pcb_edit_frame.h>
34 #include <validators.h>
35 #include <board_design_settings.h>
36 #include <board_commit.h>
37 #include <bitmaps.h>
38 #include <widgets/wx_grid.h>
39 #include <widgets/text_ctrl_eval.h>
40 #include <class_module.h>
41 #include <footprint_edit_frame.h>
43 #include "filename_resolver.h"
44 #include <pgm_base.h>
47 
48 #include <fp_lib_table.h>
49 
50 #define LibFootprintTextShownColumnsKey wxT( "LibFootprintTextShownColumns" )
51 
52 int DIALOG_FOOTPRINT_FP_EDITOR::m_page = 0; // remember the last open page during session
53 
54 
56  MODULE* aModule ) :
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 {
64 
65  m_frame = aParent;
66  m_footprint = aModule;
67 
69 
70  m_delayedErrorMessage = wxEmptyString;
71  m_delayedFocusCtrl = nullptr;
72  m_delayedFocusGrid = nullptr;
73  m_delayedFocusRow = -1;
75  m_delayedFocusPage = -1;
76 
77  // Give an icon
78  wxIcon icon;
79  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
80  SetIcon( icon );
81 
82  // Give a bit more room for combobox editors
83  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
84  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
85 
87  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
88  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
89 
90  // Show/hide columns according to the user's preference
91  wxString shownColumns;
92  m_config->Read( LibFootprintTextShownColumnsKey, &shownColumns, wxT( "0 1 2 3 4 5 6" ) );
93  m_itemsGrid->ShowHideColumns( shownColumns );
94 
95  // Set up the 3D models grid
96  wxGridCellAttr* attr = new wxGridCellAttr;
97  attr->SetRenderer( new wxGridCellBoolRenderer() );
98  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
99  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
100  m_modelsGrid->SetColAttr( 1, attr );
101  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
102 
103  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
104 
106 
107  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
108 
110 
111  // Set font sizes
112  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
113  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
114  m_allow90Label->SetFont( infoFont );
115  m_allow180Label->SetFont( infoFont );
116  m_staticTextInfoCopper->SetFont( infoFont );
117  m_staticTextInfoPaste->SetFont( infoFont );
118 
119  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
120  m_staticTextInfoValNeg->SetFont( infoFont );
121  m_staticTextInfoValPos->SetFont( infoFont );
122 
123  if( m_page >= 0 )
124  m_NoteBook->SetSelection( (unsigned) m_page );
125 
126  if( m_page == 0 )
127  {
129  m_delayedFocusRow = 0;
131  m_delayedFocusPage = 0;
132  }
133  else if ( m_page == 1 )
135  else
136  {
138  m_delayedFocusRow = 0;
140  m_delayedFocusPage = 2;
141  }
142 
143  m_sdbSizerStdButtonsOK->SetDefault();
144 
145  // Configure button logos
146  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
147  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
148  m_button3DShapeAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
149  m_button3DShapeBrowse->SetBitmap( KiBitmap( folder_xpm ) );
150  m_button3DShapeRemove->SetBitmap( KiBitmap( trash_xpm ) );
151 
152  // wxFormBuilder doesn't include this event...
153  m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
154 
156 }
157 
158 
160 {
162 
163  // Prevents crash bug in wxGrid's d'tor
165 
166  m_itemsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_FP_EDITOR::OnGridCellChanging ), NULL, this );
167 
168  // Delete the GRID_TRICKS.
169  m_itemsGrid->PopEventHandler( true );
170  m_modelsGrid->PopEventHandler( true );
171 
172  // free the memory used by all models, otherwise models which were
173  // browsed but not used would consume memory
174  Prj().Get3DCacheManager()->FlushCache( false );
175 
176  // the GL canvas has to be visible before it is destroyed
177  m_page = m_NoteBook->GetSelection();
178  m_NoteBook->SetSelection( 1 );
179 
180  delete m_PreviewPane;
181 }
182 
183 
185 {
186  LIB_ID fpID = m_footprint->GetFPID();
187  wxString footprintName = fpID.GetLibItemName();
188 
189  m_FootprintNameCtrl->ChangeValue( footprintName );
190 
191  m_DocCtrl->SetValue( m_footprint->GetDescription() );
192  m_KeywordCtrl->SetValue( m_footprint->GetKeywords() );
193 
194  if( !wxDialog::TransferDataToWindow() )
195  return false;
196 
197  if( !m_PanelGeneral->TransferDataToWindow() )
198  return false;
199 
200  if( !m_Panel3D->TransferDataToWindow() )
201  return false;
202 
203  // Module Texts
204 
205  m_texts->push_back( m_footprint->Reference() );
206  m_texts->push_back( m_footprint->Value() );
207 
208  for( auto item : m_footprint->GraphicalItems() )
209  {
210  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
211 
212  if( textModule )
213  m_texts->push_back( *textModule );
214  }
215 
216  // notify the grid
217  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
218  m_itemsGrid->ProcessTableMessage( tmsg );
219 
220  // Module Properties
221 
222  m_AutoPlaceCtrl->SetSelection( (m_footprint->IsLocked()) ? 1 : 0 );
223  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Enable hotkey move commands and Auto Placement" ) );
224  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Disable hotkey move commands and Auto Placement" ) );
225 
228 
229  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
230  "Footprints with this option are not put in the footprint position list file" ) );
231  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
232  "Only footprints with this option are put in the footprint position list file" ) );
233  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn on board\n"
234  "such as an edge connector (old ISA PC bus for instance)" ) );
235 
236  switch( m_footprint->GetAttributes() & 255 )
237  {
238  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
239  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
240  case 0:
241  default: m_AttributsCtrl->SetSelection( 0 ); break;
242  }
243 
244  // Local Clearances
245 
249 
250  // Prefer "-0" to "0" for normally negative values
252  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
253 
254  // Add solder paste margin ratio in percent
255  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
256  wxString msg;
257  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
258 
260  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
261  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
262  else
264 
265  switch( m_footprint->GetZoneConnection() )
266  {
267  default:
269  m_ZoneConnectionChoice->SetSelection( 0 );
270  break;
272  m_ZoneConnectionChoice->SetSelection( 1 );
273  break;
275  m_ZoneConnectionChoice->SetSelection( 2 );
276  break;
278  m_ZoneConnectionChoice->SetSelection( 3 );
279  break;
280  }
281 
282  // 3D Settings
283 
284  wxString default_path;
285  wxGetEnv( KISYS3DMOD, &default_path );
286 #ifdef __WINDOWS__
287  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
288 #endif
289 
290  m_shapes3D_list.clear();
291  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
292 
293  wxString origPath, alias, shortPath;
294  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
295 
296  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
297  {
298  m_shapes3D_list.push_back( model );
299  origPath = model.m_Filename;
300 
301  if( res && res->SplitAlias( origPath, alias, shortPath ) )
302  origPath = alias + wxT( ":" ) + shortPath;
303 
304  m_modelsGrid->AppendRows( 1 );
305  int row = m_modelsGrid->GetNumberRows() - 1;
306  m_modelsGrid->SetCellValue( row, 0, origPath );
307  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
308  }
309 
310  select3DModel( 0 ); // will clamp idx within bounds
311 
312  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
313  {
314  // Adjust min size to the column label size
315  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false, false ) );
316  // Adjust the column size. The column 6 has a small bitmap, so its width must be taken in account
317  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
318 
319  if( col == 6 )
320  col_size += 20;
321 
322  if( m_itemsGrid->IsColShown( col ) )
323  m_itemsGrid->SetColSize( col, col_size );
324  }
325 
326  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) );
327  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
328 
329  Layout();
330  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
331 
332  return true;
333 }
334 
335 
337 {
338  m_inSelect = true;
339 
340  aModelIdx = std::max( 0, aModelIdx );
341  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
342 
343  if( m_modelsGrid->GetNumberRows() )
344  {
345  m_modelsGrid->SelectRow( aModelIdx );
346  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
347  }
348 
349  m_PreviewPane->SetSelectedModel( aModelIdx );
350 
351  m_inSelect = false;
352 }
353 
354 
356 {
357  if( !m_inSelect )
358  select3DModel( aEvent.GetRow() );
359 }
360 
361 
363 {
364  if( aEvent.GetCol() == 0 )
365  {
366  bool hasAlias = false;
367  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
368  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
369 
370  filename.Replace( "\n", "" );
371  filename.Replace( "\r", "" );
372  filename.Replace( "\t", "" );
373 
374  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
375  {
376  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
378  m_delayedFocusRow = aEvent.GetRow();
379  m_delayedFocusColumn = aEvent.GetCol();
380  m_delayedFocusPage = 2;
381  aEvent.Veto();
382  }
383 
384  // if the user has specified an alias in the name then prepend ':'
385  if( hasAlias )
386  filename.insert( 0, wxT( ":" ) );
387 
388 #ifdef __WINDOWS__
389  // In Kicad files, filenames and paths are stored using Unix notation
390  filename.Replace( wxT( "\\" ), wxT( "/" ) );
391 #endif
392 
393  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
394  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
395  }
396  else if( aEvent.GetCol() == 1 )
397  {
398  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
399 
400  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
401  }
402 
404 }
405 
406 
408 {
410  return;
411 
412  int idx = m_modelsGrid->GetGridCursorRow();
413 
414  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
415  {
416  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
417  m_modelsGrid->DeleteRows( idx );
418 
419  select3DModel( idx-1 ); // will clamp idx within bounds
421  }
422 }
423 
424 
426 {
428  return;
429 
430  PROJECT& prj = Prj();
431  MODULE_3D_SETTINGS model;
432 
433  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
434  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
435  int filter = 0;
436 
437  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
438  // varaible and fall back to the project path if necessary.
439  if( initialpath.IsEmpty() )
440  {
441  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
442  initialpath = prj.GetProjectPath();
443  }
444 
445  if( !sidx.empty() )
446  {
447  long tmp;
448  sidx.ToLong( &tmp );
449 
450  if( tmp > 0 && tmp <= INT_MAX )
451  filter = (int) tmp;
452  }
453 
454  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
455  || model.m_Filename.empty() )
456  {
457  return;
458  }
459 
460  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
461  sidx = wxString::Format( wxT( "%i" ), filter );
463  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
464  wxString alias;
465  wxString shortPath;
466  wxString filename = model.m_Filename;
467 
468  if( res && res->SplitAlias( filename, alias, shortPath ) )
469  filename = alias + wxT( ":" ) + shortPath;
470 
471 #ifdef __WINDOWS__
472  // In Kicad files, filenames and paths are stored using Unix notation
473  model.m_Filename.Replace( "\\", "/" );
474 #endif
475 
476  model.m_Preview = true;
477  m_shapes3D_list.push_back( model );
478 
479  int idx = m_modelsGrid->GetNumberRows();
480  m_modelsGrid->AppendRows( 1 );
481  m_modelsGrid->SetCellValue( idx, 0, filename );
482  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
483 
485 }
486 
487 
489 {
491  return;
492 
493  MODULE_3D_SETTINGS model;
494 
495  model.m_Preview = true;
496  m_shapes3D_list.push_back( model );
497 
498  int row = m_modelsGrid->GetNumberRows();
499  m_modelsGrid->AppendRows( 1 );
500  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
501 
502  m_modelsGrid->SetFocus();
503  m_modelsGrid->MakeCellVisible( row, 0 );
504  m_modelsGrid->SetGridCursor( row, 0 );
505 
506  m_modelsGrid->EnableCellEditControl( true );
507  m_modelsGrid->ShowCellEditControl();
508 }
509 
510 
511 bool DIALOG_FOOTPRINT_FP_EDITOR::checkFootprintName( const wxString& aFootprintName )
512 {
513  if( aFootprintName.IsEmpty() )
514  {
515  m_delayedErrorMessage = _( "Footprint must have a name." );
516  return false;
517  }
518  else if( !MODULE::IsLibNameValid( aFootprintName ) )
519  {
520  m_delayedErrorMessage.Printf( _( "Footprint name may not contain \"%s\"." ),
522  return false;
523  }
524 
525  return true;
526 }
527 
528 
530 {
532  return false;
533 
534  if( !DIALOG_SHIM::Validate() )
535  return false;
536 
537  // First, test for invalid chars in module name
538  wxString footprintName = m_FootprintNameCtrl->GetValue();
539 
540  if( !checkFootprintName( footprintName ) )
541  {
542  if( m_NoteBook->GetSelection() != 0 )
543  m_NoteBook->SetSelection( 0 );
544 
546  m_delayedFocusPage = 0;
547 
548  return false;
549  }
550 
551  // Check for empty texts.
552  for( size_t i = 2; i < m_texts->size(); ++i )
553  {
554  TEXTE_MODULE& text = m_texts->at( i );
555 
556  if( text.GetText().IsEmpty() )
557  {
558  if( m_NoteBook->GetSelection() != 0 )
559  m_NoteBook->SetSelection( 0 );
560 
561  m_delayedErrorMessage = _( "Text items must have some content." );
564  m_delayedFocusRow = i;
565 
566  return false;
567  }
568  }
569 
570  if( !m_netClearance.Validate( 0, INT_MAX ) )
571  return false;
572 
573  return true;
574 }
575 
576 
578 {
579  if( !Validate() )
580  return false;
581 
582  if( !DIALOG_SHIM::TransferDataFromWindow() )
583  return false;
584 
585  if( !m_PanelGeneral->TransferDataFromWindow() )
586  return false;
587 
588  if( !m_Panel3D->TransferDataFromWindow() )
589  return false;
590 
591  auto view = m_frame->GetCanvas()->GetView();
592  BOARD_COMMIT commit( m_frame );
593  commit.Modify( m_footprint );
594 
595  LIB_ID fpID = m_footprint->GetFPID();
596  fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false );
597  m_footprint->SetFPID( fpID );
598 
599  m_footprint->SetDescription( m_DocCtrl->GetValue() );
600  m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
601 
602  // copy reference and value
603  m_footprint->Reference() = m_texts->at( 0 );
604  m_footprint->Value() = m_texts->at( 1 );
605 
606  size_t i = 2;
607  for( auto item : m_footprint->GraphicalItems() )
608  {
609  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
610 
611  if( textModule )
612  {
613  // copy grid table entries till we run out, then delete any remaining texts
614  if( i < m_texts->size() )
615  *textModule = m_texts->at( i++ );
616  else
617  textModule->DeleteStructure();
618  }
619  }
620 
621  // if there are still grid table entries, create new texts for them
622  while( i < m_texts->size() )
623  {
624  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
625  m_footprint->Add( newText, ADD_MODE::APPEND );
626  view->Add( newText );
627  }
628 
629  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
630 
631  switch( m_AttributsCtrl->GetSelection() )
632  {
633  case 0: m_footprint->SetAttributes( 0 ); break;
634  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
635  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
636  default: wxFAIL;
637  }
638 
641 
642  // Initialize masks clearances
646 
647  double dtmp = 0.0;
648  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
649  msg.ToDouble( &dtmp );
650 
651  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
652  if( dtmp < -50.0 )
653  dtmp = -50.0;
654  // A margin ratio is always <= 0
655  // 0 means use full pad copper area
656  if( dtmp > 0.0 )
657  dtmp = 0.0;
658 
660 
661  switch( m_ZoneConnectionChoice->GetSelection() )
662  {
663  default:
664  case 0:
666  break;
667  case 1:
669  break;
670  case 2:
672  break;
673  case 3:
675  break;
676  }
677 
678  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
679  draw3D->clear();
680  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
681 
683 
684  commit.Push( _( "Modify module properties" ) );
685 
686  return true;
687 }
688 
689 
690 static bool footprintIsFromBoard( MODULE* aFootprint )
691 {
692  return aFootprint->GetLink() != 0;
693 }
694 
695 
697 {
698  // Currently: nothing to do
699 }
700 
701 
703 {
705  {
706  // Currently: nothing to do
707  }
708 }
709 
710 
711 void DIALOG_FOOTPRINT_FP_EDITOR::OnAddField( wxCommandEvent& event )
712 {
714  return;
715 
716  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
717  TEXTE_MODULE textMod( m_footprint );
718 
719  // Set active layer if legal; otherwise copy layer from previous text item
720  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
721  textMod.SetLayer( m_frame->GetActiveLayer() );
722  else
723  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
724 
725  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
726  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
727  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
728 
729  m_texts->push_back( textMod );
730 
731  // notify the grid
732  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
733  m_itemsGrid->ProcessTableMessage( msg );
734 
735  m_itemsGrid->SetFocus();
736  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
737  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
738 
739  m_itemsGrid->EnableCellEditControl( true );
740  m_itemsGrid->ShowCellEditControl();
741 }
742 
743 
744 void DIALOG_FOOTPRINT_FP_EDITOR::OnDeleteField( wxCommandEvent& event )
745 {
747  return;
748 
749  int curRow = m_itemsGrid->GetGridCursorRow();
750 
751  if( curRow < 0 )
752  return;
753  else if( curRow < 2 )
754  {
755  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
756  return;
757  }
758 
759  m_texts->erase( m_texts->begin() + curRow );
760 
761  // notify the grid
762  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
763  m_itemsGrid->ProcessTableMessage( msg );
764 
765  if( m_itemsGrid->GetNumberRows() > 0 )
766  {
767  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
768  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
769  }
770 }
771 
772 
773 void DIALOG_FOOTPRINT_FP_EDITOR::Cfg3DPath( wxCommandEvent& event )
774 {
775  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
777 }
778 
779 
781 {
782  // Account for scroll bars
783  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
784  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
785 
786  itemsWidth -= m_itemsGrid->GetRowLabelSize();
787 
788  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
789  itemsWidth -= m_itemsGrid->GetColSize( i );
790 
791  if( itemsWidth > 0 )
792  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
793  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
794 
795  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
796 }
797 
798 
799 void DIALOG_FOOTPRINT_FP_EDITOR::OnUpdateUI( wxUpdateUIEvent& event )
800 {
801  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
802  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
803 
804  if( m_itemsGrid->IsCellEditControlShown() )
805  {
806  // Currently: nonthing to do
807  }
808 
809  // Handle a delayed focus. The delay allows us to:
810  // a) change focus when the error was triggered from within a killFocus handler
811  // b) show the correct notebook page in the background before the error dialog comes up
812  // when triggered from an OK or a notebook page change
813 
814  if( m_delayedFocusPage >= 0 )
815  {
816  if( m_NoteBook->GetSelection() != m_delayedFocusPage )
817  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
818 
819  m_delayedFocusPage = -1;
820  }
821 
822  if( !m_delayedErrorMessage.IsEmpty() )
823  {
824  // We will re-enter this routine when the error dialog is displayed, so make
825  // sure we don't keep putting up more dialogs.
826  wxString msg = m_delayedErrorMessage;
827  m_delayedErrorMessage = wxEmptyString;
828 
829  // Do not use DisplayErrorMessage(); it screws up window order on Mac
830  DisplayError( nullptr, msg );
831  }
832 
833  if( m_delayedFocusCtrl )
834  {
835  m_delayedFocusCtrl->SetFocus();
836 
837  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
838  textEntry->SelectAll();
839 
840  m_delayedFocusCtrl = nullptr;
841  }
842  else if( m_delayedFocusGrid )
843  {
844  m_delayedFocusGrid->SetFocus();
847 
848  m_delayedFocusGrid->EnableCellEditControl( true );
849  m_delayedFocusGrid->ShowCellEditControl();
850 
851  m_delayedFocusGrid = nullptr;
852  m_delayedFocusRow = -1;
854  }
855 
856  m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
857 }
858 
859 
860 void DIALOG_FOOTPRINT_FP_EDITOR::OnGridSize( wxSizeEvent& event )
861 {
862  adjustGridColumns( event.GetSize().GetX());
863 
864  event.Skip();
865 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
void Cfg3DPath(wxCommandEvent &event) override
void SetPlacementCost90(int aCost)
Definition: class_module.h:556
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
int GetAttributes() const
Definition: class_module.h:259
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:555
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
TEXTE_MODULE & Reference()
Definition: class_module.h:477
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:98
PROJECT holds project specific data.
Definition: project.h:58
void SetLocalClearance(int aClearance)
Definition: class_module.h:235
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this 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:553
This file is part of the common library.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:119
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:163
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:248
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
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:51
provides an extensible class to resolve 3D model paths.
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
void OnFootprintNameText(wxCommandEvent &event) override
void UpdateDummyModule(bool aRelaodRequired=true)
UpdateModelInfoList - copy shapes from the current shape list which are flagged for preview to the co...
const LIB_ID & GetFPID() const
Definition: class_module.h:219
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:44
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:57
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
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()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:756
void OnAdd3DModel(wxCommandEvent &event) override
int GetLocalSolderMaskMargin() const
Definition: class_module.h:231
bool m_Preview
Include module in 3D preview.
Definition: class_module.h:101
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:241
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.
timestamp_t GetLink() const
Definition: class_module.h:549
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:228
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:88
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
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:79
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
Defines a panel which is to be added to a wxFileDialog via SetExtraControl(); The panel shows a previ...
int GetLocalClearance() const
Definition: class_module.h:234
#define NULL
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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:301
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:225
#define LibFootprintTextShownColumnsKey
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:232
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:237
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:100
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:171
int GetPlacementCost180() const
Definition: class_module.h:552
EDA_UNITS m_units
Definition: dialog_shim.h:196
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:101
void OnAdd3DRow(wxCommandEvent &event) override
const wxString & GetDescription() const
Definition: class_module.h:222
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:238
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:186
void OnRemove3DModel(wxCommandEvent &event) override
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:240
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
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:311
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:205
#define _(s)
Definition: 3d_actions.cpp:31
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:243
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.
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:226
void OnDeleteField(wxCommandEvent &event) override
DIALOG_FOOTPRINT_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, MODULE *aModule)
static bool footprintIsFromBoard(MODULE *aFootprint)
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
Module description (excepted pads)
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:220
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
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 SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
void SetAttributes(int aAttributes)
Definition: class_module.h:260
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:223
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list