KiCad PCB EDA Suite
dialog_footprint_properties_fp_editor.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 2004-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_PROPERTIES_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 ),
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( BITMAPS::icon_modedit ) );
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( BITMAPS::small_plus ) );
156  m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
160 
161  // wxFormBuilder doesn't include this event...
162  m_itemsGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_FOOTPRINT_PROPERTIES_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_PROPERTIES_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  // Footprint Properties
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() & FP_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( KICAD6_3DMODEL_DIR, &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 FP_3DMODEL& 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
317 
318  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
319  {
320  // Adjust min size to the column label size
321  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
322  false ) );
323  // Adjust the column size.
324  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
325 
326  if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
327  {
328  BOARD* board = m_footprint->GetBoard();
329 
330  for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
331  col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
332 
333  // And the swatch:
334  col_size += 20;
335  }
336 
337  if( m_itemsGrid->IsColShown( col ) )
338  m_itemsGrid->SetColSize( col, col_size );
339  }
340 
341  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, true, true, true ) );
342  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
343 
344  Layout();
345  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
346 
347  return true;
348 }
349 
350 
352 {
353  m_inSelect = true;
354 
355  aModelIdx = std::max( 0, aModelIdx );
356  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
357 
358  if( m_modelsGrid->GetNumberRows() )
359  {
360  m_modelsGrid->SelectRow( aModelIdx );
361  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
362  }
363 
364  m_PreviewPane->SetSelectedModel( aModelIdx );
365 
366  m_inSelect = false;
367 }
368 
369 
371 {
372  if( !m_inSelect )
373  select3DModel( aEvent.GetRow() );
374 }
375 
376 
378 {
379  if( aEvent.GetCol() == 0 )
380  {
381  bool hasAlias = false;
382  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
383  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
384 
385  filename.Replace( "\n", "" );
386  filename.Replace( "\r", "" );
387  filename.Replace( "\t", "" );
388 
389  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
390  {
391  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
393  m_delayedFocusRow = aEvent.GetRow();
394  m_delayedFocusColumn = aEvent.GetCol();
395  m_delayedFocusPage = 2;
396  aEvent.Veto();
397  }
398 
399  // if the user has specified an alias in the name then prepend ':'
400  if( hasAlias )
401  filename.insert( 0, wxT( ":" ) );
402 
403 #ifdef __WINDOWS__
404  // In Kicad files, filenames and paths are stored using Unix notation
405  filename.Replace( wxT( "\\" ), wxT( "/" ) );
406 #endif
407 
408  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
409  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
410  }
411  else if( aEvent.GetCol() == 1 )
412  {
413  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
414 
415  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
416  }
417 
419 }
420 
421 
423 {
425  return;
426 
427  int idx = m_modelsGrid->GetGridCursorRow();
428 
429  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
430  {
431  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
432  m_modelsGrid->DeleteRows( idx );
433 
434  select3DModel( idx ); // will clamp idx within bounds
436  }
437 }
438 
439 
441 {
443  return;
444 
445  int selected = m_modelsGrid->GetGridCursorRow();
446 
447  PROJECT& prj = Prj();
448  FP_3DMODEL model;
449 
450  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
451  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
452  int filter = 0;
453 
454  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment
455  // varaible and fall back to the project path if necessary.
456  if( initialpath.IsEmpty() )
457  {
458  if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() )
459  initialpath = prj.GetProjectPath();
460  }
461 
462  if( !sidx.empty() )
463  {
464  long tmp;
465  sidx.ToLong( &tmp );
466 
467  if( tmp > 0 && tmp <= INT_MAX )
468  filter = (int) tmp;
469  }
470 
471  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
472  || model.m_Filename.empty() )
473  {
474  select3DModel( selected );
475  return;
476  }
477 
478  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
479  sidx = wxString::Format( wxT( "%i" ), filter );
481  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
482  wxString alias;
483  wxString shortPath;
484  wxString filename = model.m_Filename;
485 
486  if( res && res->SplitAlias( filename, alias, shortPath ) )
487  filename = alias + wxT( ":" ) + shortPath;
488 
489 #ifdef __WINDOWS__
490  // In Kicad files, filenames and paths are stored using Unix notation
491  model.m_Filename.Replace( "\\", "/" );
492 #endif
493 
494  model.m_Show = true;
495  m_shapes3D_list.push_back( model );
496 
497  int idx = m_modelsGrid->GetNumberRows();
498  m_modelsGrid->AppendRows( 1 );
499  m_modelsGrid->SetCellValue( idx, 0, filename );
500  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
501 
502  select3DModel( idx );
504 }
505 
506 
508 {
510  return;
511 
512  FP_3DMODEL model;
513 
514  model.m_Show = true;
515  m_shapes3D_list.push_back( model );
516 
517  int row = m_modelsGrid->GetNumberRows();
518  m_modelsGrid->AppendRows( 1 );
519  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
520 
521  select3DModel( row );
522 
523  m_modelsGrid->SetFocus();
524  m_modelsGrid->MakeCellVisible( row, 0 );
525  m_modelsGrid->SetGridCursor( row, 0 );
526 
527  m_modelsGrid->EnableCellEditControl( true );
528  m_modelsGrid->ShowCellEditControl();
529 }
530 
531 
532 bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::checkFootprintName( const wxString& aFootprintName )
533 {
534  if( aFootprintName.IsEmpty() )
535  {
536  m_delayedErrorMessage = _( "Footprint must have a name." );
537  return false;
538  }
539  else if( !FOOTPRINT::IsLibNameValid( aFootprintName ) )
540  {
541  m_delayedErrorMessage.Printf( _( "Footprint name may not contain \"%s\"." ),
543  return false;
544  }
545 
546  return true;
547 }
548 
549 
551 {
553  return false;
554 
555  if( !DIALOG_SHIM::Validate() )
556  return false;
557 
558  // First, test for invalid chars in footprint name
559  wxString footprintName = m_FootprintNameCtrl->GetValue();
560 
561  if( !checkFootprintName( footprintName ) )
562  {
563  if( m_NoteBook->GetSelection() != 0 )
564  m_NoteBook->SetSelection( 0 );
565 
567  m_delayedFocusPage = 0;
568 
569  return false;
570  }
571 
572  // Check for empty texts.
573  for( size_t i = 2; i < m_texts->size(); ++i )
574  {
575  FP_TEXT& text = m_texts->at( i );
576 
577  if( text.GetText().IsEmpty() )
578  {
579  if( m_NoteBook->GetSelection() != 0 )
580  m_NoteBook->SetSelection( 0 );
581 
582  m_delayedErrorMessage = _( "Text items must have some content." );
585  m_delayedFocusRow = i;
586 
587  return false;
588  }
589  }
590 
591  if( !m_netClearance.Validate( 0, INT_MAX ) )
592  return false;
593 
594  return true;
595 }
596 
597 
599 {
600  if( !Validate() )
601  return false;
602 
603  if( !DIALOG_SHIM::TransferDataFromWindow() )
604  return false;
605 
607  return false;
608 
610  return false;
611 
612  auto view = m_frame->GetCanvas()->GetView();
613  BOARD_COMMIT commit( m_frame );
614  commit.Modify( m_footprint );
615 
616  LIB_ID fpID = m_footprint->GetFPID();
617  fpID.SetLibItemName( m_FootprintNameCtrl->GetValue(), false );
618  m_footprint->SetFPID( fpID );
619 
620  m_footprint->SetDescription( m_DocCtrl->GetValue() );
621  m_footprint->SetKeywords( m_KeywordCtrl->GetValue() );
622 
623  // copy reference and value
624  m_footprint->Reference() = m_texts->at( 0 );
625  m_footprint->Value() = m_texts->at( 1 );
626 
627  size_t i = 2;
628  std::vector<FP_TEXT*> items_to_remove;
629 
630  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
631  {
632  FP_TEXT* textItem = dynamic_cast<FP_TEXT*>( item );
633 
634  if( textItem )
635  {
636  // copy grid table entries till we run out, then delete any remaining texts
637  if( i < m_texts->size() )
638  *textItem = m_texts->at( i++ );
639  else // store this item to remove and delete it later,
640  // after the graphic list is explored:
641  items_to_remove.push_back( textItem );
642  }
643  }
644 
645  // Remove text items:
647 
648  for( FP_TEXT* item: items_to_remove )
649  {
650  selTool->RemoveItemFromSel( item );
651  view->Remove( item );
652  item->DeleteStructure();
653  }
654 
655  // if there are still grid table entries, create new texts for them
656  while( i < m_texts->size() )
657  {
658  FP_TEXT* newText = new FP_TEXT( m_texts->at( i++ ) );
659  m_footprint->Add( newText, ADD_MODE::APPEND );
660  view->Add( newText );
661  }
662 
663  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
664 
665  int attributes = 0;
666 
667  switch( m_componentType->GetSelection() )
668  {
669  case 0: attributes |= FP_THROUGH_HOLE; break;
670  case 1: attributes |= FP_SMD; break;
671  default: break;
672  }
673 
674  if( m_boardOnly->GetValue() )
675  attributes |= FP_BOARD_ONLY;
676 
677  if( m_excludeFromPosFiles->GetValue() )
678  attributes |= FP_EXCLUDE_FROM_POS_FILES;
679 
680  if( m_excludeFromBOM->GetValue() )
681  attributes |= FP_EXCLUDE_FROM_BOM;
682 
683  m_footprint->SetAttributes( attributes );
684 
687 
688  // Initialize masks clearances
692 
693  double dtmp = 0.0;
694  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
695  msg.ToDouble( &dtmp );
696 
697  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
698  if( dtmp < -50.0 )
699  dtmp = -50.0;
700  // A margin ratio is always <= 0
701  // 0 means use full pad copper area
702  if( dtmp > 0.0 )
703  dtmp = 0.0;
704 
706 
707  switch( m_ZoneConnectionChoice->GetSelection() )
708  {
709  default:
714  }
715 
716  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
717  draw3D->clear();
718  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
719 
720  commit.Push( _( "Modify footprint properties" ) );
721 
722  return true;
723 }
724 
725 
726 static bool footprintIsFromBoard( FOOTPRINT* aFootprint )
727 {
728  return aFootprint->GetLink() != niluuid;
729 }
730 
731 
733 {
734  // Currently: nothing to do
735 }
736 
737 
739 {
741  {
742  // Currently: nothing to do
743  }
744 }
745 
746 
748 {
750  return;
751 
752  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
753  FP_TEXT textItem( m_footprint );
754 
755  // Set active layer if legal; otherwise copy layer from previous text item
757  textItem.SetLayer( m_frame->GetActiveLayer() );
758  else
759  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
760 
761  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
762  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
763  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
764 
765  m_texts->push_back( textItem );
766 
767  // notify the grid
768  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
769  m_itemsGrid->ProcessTableMessage( msg );
770 
771  m_itemsGrid->SetFocus();
772  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
773  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
774 
775  m_itemsGrid->EnableCellEditControl( true );
776  m_itemsGrid->ShowCellEditControl();
777 }
778 
779 
781 {
783  return;
784 
785  int curRow = m_itemsGrid->GetGridCursorRow();
786 
787  if( curRow < 0 )
788  return;
789  else if( curRow < 2 )
790  {
791  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
792  return;
793  }
794 
795  m_texts->erase( m_texts->begin() + curRow );
796 
797  // notify the grid
798  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
799  m_itemsGrid->ProcessTableMessage( msg );
800 
801  if( m_itemsGrid->GetNumberRows() > 0 )
802  {
803  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
804  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
805  }
806 }
807 
808 
810 {
811  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
813 }
814 
815 
817 {
818  // Account for scroll bars
819  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
820  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
821 
822  itemsWidth -= m_itemsGrid->GetRowLabelSize();
823 
824  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
825  itemsWidth -= m_itemsGrid->GetColSize( i );
826 
827  if( itemsWidth > 0 )
828  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
829  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
830 
831  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
832 }
833 
834 
836 {
837  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
838  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
839 
840  if( m_itemsGrid->IsCellEditControlShown() )
841  {
842  // Currently: nonthing to do
843  }
844 
845  // Handle a delayed focus. The delay allows us to:
846  // a) change focus when the error was triggered from within a killFocus handler
847  // b) show the correct notebook page in the background before the error dialog comes up
848  // when triggered from an OK or a notebook page change
849 
850  if( m_delayedFocusPage >= 0 )
851  {
852  if( m_NoteBook->GetSelection() != m_delayedFocusPage )
853  m_NoteBook->SetSelection( (unsigned) m_delayedFocusPage );
854 
855  m_delayedFocusPage = -1;
856  }
857 
858  if( !m_delayedErrorMessage.IsEmpty() )
859  {
860  // We will re-enter this routine when the error dialog is displayed, so make
861  // sure we don't keep putting up more dialogs.
862  wxString msg = m_delayedErrorMessage;
863  m_delayedErrorMessage = wxEmptyString;
864 
865  // Do not use DisplayErrorMessage(); it screws up window order on Mac
866  DisplayError( nullptr, msg );
867  }
868 
869  if( m_delayedFocusCtrl )
870  {
871  m_delayedFocusCtrl->SetFocus();
872 
873  if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
874  textEntry->SelectAll();
875 
876  m_delayedFocusCtrl = nullptr;
877  }
878  else if( m_delayedFocusGrid )
879  {
880  m_delayedFocusGrid->SetFocus();
883 
884  m_delayedFocusGrid->EnableCellEditControl( true );
885  m_delayedFocusGrid->ShowCellEditControl();
886 
887  m_delayedFocusGrid = nullptr;
888  m_delayedFocusRow = -1;
890  }
891 
892  m_button3DShapeRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
893 }
894 
895 
897 {
898  adjustGridColumns( event.GetSize().GetX() );
899 
900  event.Skip();
901 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
bool IsLocked() const override
Definition: footprint.h:282
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:534
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
Class DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE.
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath) const
Return true if the given name contains an alias and populates the string anAlias with the alias and a...
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:52
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: footprint.h:220
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
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
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:535
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:462
void SetDescription(const wxString &aDoc)
Definition: footprint.h:194
bool ValidateFileName(const wxString &aFileName, bool &hasAlias) const
Returns true if the given path is a valid aliased relative path.
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
FP_TEXT & Reference()
Definition: footprint.h:463
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:97
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
wxString m_lastFootprint3dDir
DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(FOOTPRINT_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
bool m_Show
Include model in rendering.
Definition: footprint.h:98
PCB_LAYER_ID
A quick note on layer IDs:
pads are covered by copper
#define NULL
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static bool footprintIsFromBoard(FOOTPRINT *aFootprint)
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
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
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
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.
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:531
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
Definition: project.cpp:213
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 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
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Definition: project.cpp:228
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:190
#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:292
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.
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:537
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:1309
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:468
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
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:1320
void SetPlacementCost90(int aCost)
Definition: footprint.h:538
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:203
Container for design settings for a BOARD object.
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:217