KiCad PCB EDA Suite
dialog_edit_footprint_for_BoardEditor.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) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com
7  * Copyright (C) 2004-2018 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 
28 #include <fctsys.h>
29 #include <kiface_i.h>
30 #include <view/view.h>
31 #include <gr_basic.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <pcbnew.h>
35 #include <pgm_base.h>
36 #include <pcb_edit_frame.h>
37 #include <board_commit.h>
38 #include <board_design_settings.h>
39 #include <dialog_text_entry.h>
40 #include <class_module.h>
41 #include <validators.h>
42 #include <widgets/wx_grid.h>
43 #include <widgets/text_ctrl_eval.h>
44 #include <filename_resolver.h>
47 #include <bitmaps.h>
48 #include <3d_viewer.h>
49 
51 
52 
53 #define FootprintTextShownColumnsKey wxT( "FootprintTextShownColumns" )
54 
55 int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
56 
57 
59  MODULE* aModule, wxDC* aDC ) :
61  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
62  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
63  m_OrientValidator( 1, &m_OrientValue ),
64  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, false, 0 ),
65  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
66  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
67  m_inSelect( false )
68 {
70 
71  m_frame = aParent;
72  m_DC = aDC;
73  m_footprint = aModule;
74 
76 
77  m_delayedErrorMessage = wxEmptyString;
78  m_delayedFocusGrid = nullptr;
79  m_delayedFocusRow = -1;
81 
82  // Give an icon
83  wxIcon icon;
84  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
85  SetIcon( icon );
86 
87  // Give a bit more room for combobox editors
88  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
89  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
90 
92  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
93  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
94 
95  // Show/hide text item columns according to the user's preference
96  wxString shownColumns;
97  m_config->Read( FootprintTextShownColumnsKey, &shownColumns, wxT( "0 1 2 3 4 5 6" ) );
98  m_itemsGrid->ShowHideColumns( shownColumns );
99 
100  // Set up the 3D models grid
101  wxGridCellAttr* attr = new wxGridCellAttr;
102  attr->SetRenderer( new wxGridCellBoolRenderer() );
103  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
104  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
105  m_modelsGrid->SetColAttr( 1, attr );
106  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
107 
108  m_OrientValidator.SetRange( -360.0, 360.0 );
109  m_OrientValueCtrl->SetValidator( m_OrientValidator );
111 
112  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
113 
115 
116  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
117 
118  // Set font sizes
119  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
120  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
121  m_allow90Label->SetFont( infoFont );
122  m_allow180Label->SetFont( infoFont );
123  m_libraryIDLabel->SetFont( infoFont );
124  m_staticLibraryID->SetFont( infoFont );
125  m_staticTextInfoValNeg->SetFont( infoFont );
126  m_staticTextInfoValPos->SetFont( infoFont );
127  m_staticTextInfoCopper->SetFont( infoFont );
128 
129  m_NoteBook->SetSelection( m_page );
130 
131  if( m_page == 0 )
132  {
134  m_delayedFocusRow = 0;
136  }
137  else if ( m_page == 1 )
139  else
140  {
142  m_delayedFocusRow = 0;
144  }
145 
146  m_sdbSizerStdButtonsOK->SetDefault();
147 
148  m_OrientValue = 0;
149 
150  // Configure button logos
151  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
152  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
153  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
154  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
155  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
156 
158 }
159 
160 
162 {
164 
165  // Prevents crash bug in wxGrid's d'tor
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  if( m_footprint->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
187  {
189  m_frame->OnModify();
190  }
191 
192  EndModal( PRM_EDITOR_WANT_MODEDIT );
193 }
194 
195 
197 {
198  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
199 }
200 
201 
203 {
204  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
205 }
206 
207 
209 {
210  if( m_Orient0->GetValue() )
211  m_OrientValue = 0.0;
212  else if( m_Orient90->GetValue() )
213  m_OrientValue = 90.0;
214  else if( m_Orient270->GetValue() )
215  m_OrientValue = 270.0;
216  else if( m_Orient180->GetValue() )
217  m_OrientValue = 180.0;
218 
219  m_OrientValidator.TransferToWindow();
220 }
221 
222 
224 {
225  m_OrientOther->SetValue( true );
226 
227  aEvent.Skip();
228 }
229 
230 
232 {
233  if( !wxDialog::TransferDataToWindow() )
234  return false;
235 
236  if( !m_PanelGeneral->TransferDataToWindow() )
237  return false;
238 
239  if( !m_Panel3D->TransferDataToWindow() )
240  return false;
241 
242  // Module Texts
243 
244  m_texts->push_back( m_footprint->Reference() );
245  m_texts->push_back( m_footprint->Value() );
246 
247  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
248  {
249  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
250 
251  if( textModule )
252  m_texts->push_back( *textModule );
253  }
254 
255  // notify the grid
256  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
257  m_itemsGrid->ProcessTableMessage( tmsg );
258 
259  // Module Properties
260 
263 
265  m_Orient0->SetValue( m_OrientValue == 0.0 );
266  m_Orient90->SetValue( m_OrientValue == 90.0 || m_OrientValue == -270.0 );
267  m_Orient270->SetValue( m_OrientValue == 270.0 || m_OrientValue == -90.0 );
268  m_Orient180->SetValue( m_OrientValue == 180.0 || m_OrientValue == -180.0 );
269 
270  m_OrientOther->SetValue( !m_Orient0->GetValue() && !m_Orient90->GetValue()
271  && !m_Orient270->GetValue() && !m_Orient180->GetValue() );
272  m_OrientValidator.TransferToWindow();
273 
274  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
275 
276  if( m_footprint->IsLocked() )
277  m_AutoPlaceCtrl->SetSelection( 2 );
278  else if( m_footprint->PadsLocked() )
279  m_AutoPlaceCtrl->SetSelection( 1 );
280  else
281  m_AutoPlaceCtrl->SetSelection( 0 );
282 
283  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
284  "can arbitrarily select and edit component's pads." ) );
285  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
286  "its pads cannot be selected or edited." ) );
287  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
288  "auto placed." ) );
289 
292 
293  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
294  "Footprints with this option are not put in the footprint position list file" ) );
295  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
296  "Only footprints with this option are put in the footprint position list file" ) );
297  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn on board\n"
298  "such as an edge connector (old ISA PC bus for instance)" ) );
299 
300  switch( m_footprint->GetAttributes() & 255 )
301  {
302  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
303  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
304  case 0:
305  default: m_AttributsCtrl->SetSelection( 0 ); break;
306  }
307 
308  // Local Clearances
309 
313 
314  // Prefer "-0" to "0" for normally negative values
316  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
317 
318  // Add solder paste margin ratio in per cent
319  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
320  wxString msg;
321  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
322 
324  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
325  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
326  else
328 
329  switch( m_footprint->GetZoneConnection() )
330  {
331  default:
332  case PAD_ZONE_CONN_INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
333  case PAD_ZONE_CONN_FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
334  case PAD_ZONE_CONN_THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
335  case PAD_ZONE_CONN_NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
336  }
337 
338  // 3D Settings
339 
340  wxString default_path;
341  wxGetEnv( KISYS3DMOD, &default_path );
342 #ifdef __WINDOWS__
343  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
344 #endif
345 
346  m_shapes3D_list.clear();
347  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
348 
349  wxString origPath, alias, shortPath;
350  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
351 
352  for( MODULE_3D_SETTINGS model : m_footprint->Models() )
353  {
354  m_shapes3D_list.push_back( model );
355  origPath = model.m_Filename;
356 
357  if( res && res->SplitAlias( origPath, alias, shortPath ) )
358  origPath = alias + wxT( ":" ) + shortPath;
359 
360  m_modelsGrid->AppendRows( 1 );
361  int row = m_modelsGrid->GetNumberRows() - 1;
362  m_modelsGrid->SetCellValue( row, 0, origPath );
363  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
364  }
365 
366  select3DModel( 0 ); // will clamp idx within bounds
367 
368  // Show the footprint's ID.
369  m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
370 
371  Layout();
372  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
373 
374  return true;
375 }
376 
377 
379 {
380  m_inSelect = true;
381 
382  aModelIdx = std::max( 0, aModelIdx );
383  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
384 
385  if( m_modelsGrid->GetNumberRows() )
386  {
387  m_modelsGrid->SelectRow( aModelIdx );
388  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
389  }
390 
391  m_PreviewPane->SetSelectedModel( aModelIdx );
392 
393  m_inSelect = false;
394 }
395 
396 
398 {
399  if( !m_inSelect )
400  select3DModel( aEvent.GetRow() );
401 }
402 
403 
405 {
406  if( aEvent.GetCol() == 0 )
407  {
408  bool hasAlias = false;
409  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
410  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
411 
412  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
413  {
414  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
416  m_delayedFocusRow = aEvent.GetRow();
417  m_delayedFocusColumn = aEvent.GetCol();
418  aEvent.Veto();
419  }
420 
421  // if the user has specified an alias in the name then prepend ':'
422  if( hasAlias )
423  filename.insert( 0, wxT( ":" ) );
424 
425 #ifdef __WINDOWS__
426  // In Kicad files, filenames and paths are stored using Unix notation
427  filename.Replace( wxT( "\\" ), wxT( "/" ) );
428 #endif
429 
430  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
431  }
432  else if( aEvent.GetCol() == 1 )
433  {
434  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
435 
436  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
437  }
438 
440 }
441 
442 
444 {
445  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
446 
447  int idx = m_modelsGrid->GetGridCursorRow();
448 
449  if( idx >= 0 )
450  {
451  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
452  m_modelsGrid->DeleteRows( idx, 1 );
453 
454  select3DModel( idx ); // will clamp idx within bounds
456  }
457 }
458 
459 
461 {
463  return;
464 
465  PROJECT& prj = Prj();
466  MODULE_3D_SETTINGS model;
467 
468  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
469  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
470  int filter = 0;
471 
472  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
473  // varaible and fall back to the project path if necessary.
474  if( initialpath.IsEmpty() )
475  {
476  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
477  initialpath = prj.GetProjectPath();
478  }
479 
480  if( !sidx.empty() )
481  {
482  long tmp;
483  sidx.ToLong( &tmp );
484 
485  if( tmp > 0 && tmp <= INT_MAX )
486  filter = (int) tmp;
487  }
488 
489  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
490  || model.m_Filename.empty() )
491  {
492  return;
493  }
494 
495  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
496  sidx = wxString::Format( wxT( "%i" ), filter );
498  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
499  wxString alias;
500  wxString shortPath;
501  wxString filename = model.m_Filename;
502 
503  if( res && res->SplitAlias( filename, alias, shortPath ) )
504  filename = alias + wxT( ":" ) + shortPath;
505 
506 #ifdef __WINDOWS__
507  // In Kicad files, filenames and paths are stored using Unix notation
508  model.m_Filename.Replace( "\\", "/" );
509 #endif
510 
511  model.m_Preview = true;
512  m_shapes3D_list.push_back( model );
513 
514  int idx = m_modelsGrid->GetNumberRows();
515  m_modelsGrid->AppendRows( 1 );
516  m_modelsGrid->SetCellValue( idx, 0, filename );
517  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
518 
520 }
521 
522 
524 {
526  return;
527 
528  MODULE_3D_SETTINGS model;
529 
530  model.m_Preview = true;
531  m_shapes3D_list.push_back( model );
532 
533  int row = m_modelsGrid->GetNumberRows();
534  m_modelsGrid->AppendRows( 1 );
535  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
536 
537  m_modelsGrid->SetFocus();
538  m_modelsGrid->MakeCellVisible( row, 0 );
539  m_modelsGrid->SetGridCursor( row, 0 );
540 
541  m_modelsGrid->EnableCellEditControl( true );
542  m_modelsGrid->ShowCellEditControl();
543 }
544 
545 
547 {
549  return false;
550 
551  if( !DIALOG_SHIM::Validate() )
552  return false;
553 
554  // Check for empty texts.
555  for( size_t i = 2; i < m_texts->size(); ++i )
556  {
557  TEXTE_MODULE& text = m_texts->at( i );
558 
559  if( text.GetText().IsEmpty() )
560  {
561  if( m_NoteBook->GetSelection() != 0 )
562  m_NoteBook->SetSelection( 0 );
563 
564  m_delayedErrorMessage = _( "Text items must have some content." );
567 
568  return false;
569  }
570  }
571 
572  if( !m_netClearance.Validate( true ) )
573  return false;
574 
575  return true;
576 }
577 
578 
580 {
581  if( !Validate() )
582  return false;
583 
584  if( !DIALOG_SHIM::TransferDataFromWindow() )
585  return false;
586 
587  if( !m_PanelGeneral->TransferDataFromWindow() )
588  return false;
589 
590  if( !m_Panel3D->TransferDataFromWindow() )
591  return false;
592 
593  if( m_DC )
594  {
597  }
598 
599  auto view = m_frame->GetGalCanvas()->GetView();
600  BOARD_COMMIT commit( m_frame );
601  commit.Modify( m_footprint );
602 
603  // copy reference and value
604  m_footprint->Reference() = m_texts->at( 0 );
605  m_footprint->Value() = m_texts->at( 1 );
606 
607  size_t i = 2;
608  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
609  {
610  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
611 
612  if( textModule )
613  {
614  // copy grid table entries till we run out, then delete any remaining texts
615  if( i < m_texts->size() )
616  *textModule = m_texts->at( i++ );
617  else
618  textModule->DeleteStructure();
619  }
620  }
621 
622  // if there are still grid table entries, create new texts for them
623  while( i < m_texts->size() )
624  {
625  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
626  m_footprint->Add( newText, ADD_APPEND );
627  view->Add( newText );
628  }
629 
630  // Initialize masks clearances
634 
635  double dtmp = 0.0;
636  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
637  msg.ToDouble( &dtmp );
638 
639  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
640  if( dtmp < -50.0 )
641  dtmp = -50.0;
642  // A margin ratio is always <= 0
643  // 0 means use full pad copper area
644  if( dtmp > 0.0 )
645  dtmp = 0.0;
646 
648 
649  switch( m_ZoneConnectionChoice->GetSelection() )
650  {
651  default:
656  }
657 
658  // Set Module Position
659  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
660  m_footprint->SetPosition( modpos );
661  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
662  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
663 
664  switch( m_AttributsCtrl->GetSelection() )
665  {
666  case 0: m_footprint->SetAttributes( 0 ); break;
667  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
668  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
669  default: wxFAIL;
670  }
671 
674 
675  // Now, set orientation. Must be done after other changes because rotation changes field
676  // positions on board (so that relative positions are held constant)
677  m_OrientValidator.TransferFromWindow();
678 
679  int orient = KiROUND( m_OrientValue * 10.0 );
680 
681  if( m_footprint->GetOrientation() != orient )
683 
684  // Set component side, that also have effect on the fields positions on board
685  bool change_layer = false;
686  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
687  {
688  if( m_footprint->GetLayer() == B_Cu )
689  change_layer = true;
690  }
691  else if( m_footprint->GetLayer() == F_Cu )
692  change_layer = true;
693 
694  if( change_layer )
696 
697  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
698  draw3D->clear();
699  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
700 
702 
703  // This is a simple edit, we must create an undo entry
704  if( m_footprint->GetFlags() == 0 )
705  commit.Push( _( "Modify module properties" ) );
706 
707  SetReturnCode( PRM_EDITOR_EDIT_OK );
708 
709  if( m_DC )
710  {
713  }
714 
715  return true;
716 }
717 
718 
720 {
722  return;
723 
724  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
725  TEXTE_MODULE textMod( m_footprint );
726 
727  // Set active layer if legal; otherwise copy layer from previous text item
728  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
729  textMod.SetLayer( m_frame->GetActiveLayer() );
730  else
731  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
732 
733  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
734  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
735  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
736  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
737 
738  m_texts->push_back( textMod );
739 
740  // notify the grid
741  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
742  m_itemsGrid->ProcessTableMessage( msg );
743 
744  m_itemsGrid->SetFocus();
745  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
746  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
747 
748  m_itemsGrid->EnableCellEditControl( true );
749  m_itemsGrid->ShowCellEditControl();
750 }
751 
752 
754 {
755  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
756 
757  int curRow = m_itemsGrid->GetGridCursorRow();
758 
759  if( curRow < 0 )
760  return;
761  else if( curRow < 2 )
762  {
763  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
764  return;
765  }
766 
767  m_texts->erase( m_texts->begin() + curRow );
768 
769  // notify the grid
770  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
771  m_itemsGrid->ProcessTableMessage( msg );
772 
773  if( m_itemsGrid->GetNumberRows() > 0 )
774  {
775  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
776  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
777  }
778 }
779 
780 
782 {
783  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
785 }
786 
787 
789 {
790  // Account for scroll bars
791  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
792  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
793 
794  itemsWidth -= m_itemsGrid->GetRowLabelSize();
795 
796  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
797  itemsWidth -= m_itemsGrid->GetColSize( i );
798 
799  m_itemsGrid->SetColSize( 0, std::max( itemsWidth, 120 ) );
800 
801  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
802 }
803 
804 
806 {
807  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
808  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
809 
810  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
811  // even when the original validation was triggered from a killFocus event, and so
812  // that the corresponding notebook page can be shown in the background when triggered
813  // from an OK.
814  if( m_delayedFocusRow >= 0 )
815  {
816  if( !m_delayedErrorMessage.IsEmpty() )
817  {
818  // We will re-enter this routine when the error dialog is displayed, so make
819  // sure we don't keep putting up more dialogs.
820  wxString msg = m_delayedErrorMessage;
821  m_delayedErrorMessage = wxEmptyString;
822 
823  // Do not use DisplayErrorMessage(); it screws up window order on Mac
824  DisplayError( nullptr, msg );
825  }
826 
827  m_delayedFocusGrid->SetFocus();
830 
831  m_delayedFocusGrid->EnableCellEditControl( true );
832  m_delayedFocusGrid->ShowCellEditControl();
833 
834  m_delayedFocusRow = -1;
836  }
837 }
838 
839 
840 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
841 {
842  adjustGridColumns( aEvent.GetSize().GetX());
843 
844  aEvent.Skip();
845 }
virtual bool Validate(bool setFocusOnError=false)
Function Validate Validates the control, informing the user of any errors found.
void SetPlacementCost90(int aCost)
Definition: class_module.h:581
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:510
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Class PROJECT holds project specific data.
Definition: project.h:57
bool GetTextItalic(PCB_LAYER_ID aLayer) const
void SetLocalClearance(int aClearance)
Definition: class_module.h:209
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:578
This file is part of the common library.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:374
int GetLocalClearance() const
Definition: class_module.h:208
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:104
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw draws the footprint to the aDC.
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
void SetItalic(bool isItalic)
Definition: eda_text.h:182
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
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:77
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
void SetZoneConnection(ZoneConnection aType)
Definition: class_module.h:217
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
void UpdateDummyModule(bool aRelaodRequired=true)
UpdateModelInfoList - copy shapes from the current shape list which are flagged for preview to the co...
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
ZoneConnection GetZoneConnection() const
Definition: class_module.h:218
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid&#39;s SetTable() method with one which doesn&#39;t mess up the grid column widths when setting th...
Definition: wx_grid.cpp:46
int GetPlacementCost90() const
Definition: class_module.h:580
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side...
Definition: lset.cpp:743
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
bool m_Preview
Include module in 3D preview.
Definition: class_module.h:104
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:215
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:86
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:214
virtual int GetValue() const
Function GetValue Returns the current value in Internal Units.
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
Pads are not covered.
Definition: zones.h:52
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:75
BOARD_ITEM * Next() const
const LIB_ID & GetFPID() const
Definition: class_module.h:193
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
bool PadsLocked() const
Definition: class_module.h:301
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...
timestamp_t GetNewTimeStamp()
Definition: common.cpp:159
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
Defines a panel which is to be added to a wxFileDialog via SetExtraControl(); The panel shows a previ...
double GetOrientation() const
Definition: class_module.h:189
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:509
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
void On3DModelCellChanged(wxGridEvent &aEvent) override
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: 3d_viewer.h:38
wxFloatingPointValidator< double > m_OrientValidator
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
int GetAttributes() const
Definition: class_module.h:226
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void OnOtherOrientation(wxKeyEvent &aEvent) override
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:303
void SetPosition(const wxPoint &aPos) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:152
int GetLocalSolderMaskMargin() const
Definition: class_module.h:205
void SetSelectedModel(int idx)
SetModelDataIdx - Sets the currently selected index in the model list so that the scale/rotation/offs...
void CrossHairOff(wxDC *DC)
Definition: draw_panel.cpp:248
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:265
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:206
int GetLocalSolderPasteMargin() const
Definition: class_module.h:211
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:103
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
Definition: gr_basic.h:38
bool GetTextUpright(PCB_LAYER_ID aLayer) const
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:86
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:212
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
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:179
void CrossHairOn(wxDC *DC)
Definition: draw_panel.cpp:255
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
see class PGM_BASE
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:275
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 max(a, b)
Definition: auxiliary.h:86
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:79
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
size_t i
Definition: json11.cpp:597
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
UTF8 Format() const
Definition: lib_id.cpp:237
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:901
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:166
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
Module description (excepted pads)
EDA_UNITS_T m_units
Definition: dialog_shim.h:143
DIALOG_FOOTPRINT_BOARD_EDITOR(PCB_EDIT_FRAME *aParent, MODULE *aModule, wxDC *aDC)
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Function ValidateName returns true if the given path is a valid aliased relative path.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:232
int GetPlacementCost180() const
Definition: class_module.h:577
const wxPoint GetPosition() const override
Definition: class_module.h:184
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
Use thermal relief for pads.
Definition: zones.h:53
Custom text control validator definitions.
Declaration of the eda_3d_viewer class.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
timestamp_t GetTimeStamp() const
Definition: base_struct.h:204
void SetAttributes(int aAttributes)
Definition: class_module.h:227
Class DIALOG_FOOTPRINT_BOARD_EDITOR_BASE.
#define min(a, b)
Definition: auxiliary.h:85
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:203
pads are covered by copper
Definition: zones.h:54
int GetNumberRows() override
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
#define FootprintTextShownColumnsKey
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list