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_sheetPathLabel->SetFont( infoFont );
126  m_staticSheetPath->SetFont( infoFont );
127  m_staticTextInfoValNeg->SetFont( infoFont );
128  m_staticTextInfoValPos->SetFont( infoFont );
129  m_staticTextInfoCopper->SetFont( infoFont );
130 
131  m_NoteBook->SetSelection( m_page );
132 
133  if( m_page == 0 )
134  {
136  m_delayedFocusRow = 0;
138  }
139  else if ( m_page == 1 )
141  else
142  {
144  m_delayedFocusRow = 0;
146  }
147 
148  m_sdbSizerStdButtonsOK->SetDefault();
149 
150  m_OrientValue = 0;
151 
152  // Configure button logos
153  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
154  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
155  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
156  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
157  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
158 
160 }
161 
162 
164 {
166 
167  // Prevents crash bug in wxGrid's d'tor
169 
170  // Delete the GRID_TRICKS.
171  m_itemsGrid->PopEventHandler( true );
172  m_modelsGrid->PopEventHandler( true );
173 
174  // free the memory used by all models, otherwise models which were
175  // browsed but not used would consume memory
176  Prj().Get3DCacheManager()->FlushCache( false );
177 
178  // the GL canvas has to be visible before it is destroyed
179  m_page = m_NoteBook->GetSelection();
180  m_NoteBook->SetSelection( 1 );
181 
182  delete m_PreviewPane;
183 }
184 
185 
187 {
188  if( m_footprint->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
189  {
191  m_frame->OnModify();
192  }
193 
194  EndModal( PRM_EDITOR_WANT_MODEDIT );
195 }
196 
197 
199 {
200  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
201 }
202 
203 
205 {
206  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
207 }
208 
209 
211 {
212  if( m_Orient0->GetValue() )
213  m_OrientValue = 0.0;
214  else if( m_Orient90->GetValue() )
215  m_OrientValue = 90.0;
216  else if( m_Orient270->GetValue() )
217  m_OrientValue = 270.0;
218  else if( m_Orient180->GetValue() )
219  m_OrientValue = 180.0;
220 
221  m_OrientValidator.TransferToWindow();
222 }
223 
224 
226 {
227  m_OrientOther->SetValue( true );
228 
229  aEvent.Skip();
230 }
231 
232 
234 {
235  if( !wxDialog::TransferDataToWindow() )
236  return false;
237 
238  if( !m_PanelGeneral->TransferDataToWindow() )
239  return false;
240 
241  if( !m_Panel3D->TransferDataToWindow() )
242  return false;
243 
244  // Module Texts
245 
246  m_texts->push_back( m_footprint->Reference() );
247  m_texts->push_back( m_footprint->Value() );
248 
249  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
250  {
251  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
252 
253  if( textModule )
254  m_texts->push_back( *textModule );
255  }
256 
257  // notify the grid
258  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
259  m_itemsGrid->ProcessTableMessage( tmsg );
260 
261  // Module Properties
262 
265 
267  m_Orient0->SetValue( m_OrientValue == 0.0 );
268  m_Orient90->SetValue( m_OrientValue == 90.0 || m_OrientValue == -270.0 );
269  m_Orient270->SetValue( m_OrientValue == 270.0 || m_OrientValue == -90.0 );
270  m_Orient180->SetValue( m_OrientValue == 180.0 || m_OrientValue == -180.0 );
271 
272  m_OrientOther->SetValue( !m_Orient0->GetValue() && !m_Orient90->GetValue()
273  && !m_Orient270->GetValue() && !m_Orient180->GetValue() );
274  m_OrientValidator.TransferToWindow();
275 
276  m_LayerCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
277 
278  if( m_footprint->IsLocked() )
279  m_AutoPlaceCtrl->SetSelection( 2 );
280  else if( m_footprint->PadsLocked() )
281  m_AutoPlaceCtrl->SetSelection( 1 );
282  else
283  m_AutoPlaceCtrl->SetSelection( 0 );
284 
285  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
286  "can arbitrarily select and edit component's pads." ) );
287  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
288  "its pads cannot be selected or edited." ) );
289  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
290  "auto placed." ) );
291 
294 
295  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
296  "Footprints with this option are not put in the footprint position list file" ) );
297  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
298  "Only footprints with this option are put in the footprint position list file" ) );
299  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn on board\n"
300  "such as an edge connector (old ISA PC bus for instance)" ) );
301 
302  switch( m_footprint->GetAttributes() & 255 )
303  {
304  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
305  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
306  case 0:
307  default: m_AttributsCtrl->SetSelection( 0 ); break;
308  }
309 
310  // Local Clearances
311 
315 
316  // Prefer "-0" to "0" for normally negative values
318  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
319 
320  // Add solder paste margin ratio in per cent
321  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
322  wxString msg;
323  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
324 
326  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
327  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
328  else
330 
331  switch( m_footprint->GetZoneConnection() )
332  {
333  default:
334  case PAD_ZONE_CONN_INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
335  case PAD_ZONE_CONN_FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
336  case PAD_ZONE_CONN_THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
337  case PAD_ZONE_CONN_NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
338  }
339 
340  // 3D Settings
341 
342  wxString default_path;
343  wxGetEnv( KISYS3DMOD, &default_path );
344 #ifdef __WINDOWS__
345  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
346 #endif
347 
348  m_shapes3D_list.clear();
349  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
350 
351  wxString origPath, alias, shortPath;
352  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
353 
354  for( MODULE_3D_SETTINGS model : m_footprint->Models() )
355  {
356  m_shapes3D_list.push_back( model );
357  origPath = model.m_Filename;
358 
359  if( res && res->SplitAlias( origPath, alias, shortPath ) )
360  origPath = alias + wxT( ":" ) + shortPath;
361 
362  m_modelsGrid->AppendRows( 1 );
363  int row = m_modelsGrid->GetNumberRows() - 1;
364  m_modelsGrid->SetCellValue( row, 0, origPath );
365  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
366  }
367 
368  select3DModel( 0 ); // will clamp idx within bounds
369 
370  // Show the footprint's ID and schematic reference.
371  m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
372  m_staticSheetPath->SetLabel( m_footprint->GetPath() );
373 
374  Layout();
375  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
376 
377  return true;
378 }
379 
380 
382 {
383  m_inSelect = true;
384 
385  aModelIdx = std::max( 0, aModelIdx );
386  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
387 
388  if( m_modelsGrid->GetNumberRows() )
389  {
390  m_modelsGrid->SelectRow( aModelIdx );
391  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
392  }
393 
394  m_PreviewPane->SetSelectedModel( aModelIdx );
395 
396  m_inSelect = false;
397 }
398 
399 
401 {
402  if( !m_inSelect )
403  select3DModel( aEvent.GetRow() );
404 }
405 
406 
408 {
409  if( aEvent.GetCol() == 0 )
410  {
411  bool hasAlias = false;
412  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
413  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
414 
415  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
416  {
417  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
419  m_delayedFocusRow = aEvent.GetRow();
420  m_delayedFocusColumn = aEvent.GetCol();
421  }
422 
423  // if the user has specified an alias in the name then prepend ':'
424  if( hasAlias )
425  filename.insert( 0, wxT( ":" ) );
426 
427 #ifdef __WINDOWS__
428  // In Kicad files, filenames and paths are stored using Unix notation
429  filename.Replace( wxT( "\\" ), wxT( "/" ) );
430 #endif
431 
432  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
433  }
434  else if( aEvent.GetCol() == 1 )
435  {
436  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
437 
438  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
439  }
440 
442 }
443 
444 
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 {
462  PROJECT& prj = Prj();
463  MODULE_3D_SETTINGS model;
464 
465  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
466  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
467  int filter = 0;
468 
469  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
470  // varaible and fall back to the project path if necessary.
471  if( initialpath.IsEmpty() )
472  {
473  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
474  initialpath = prj.GetProjectPath();
475  }
476 
477  if( !sidx.empty() )
478  {
479  long tmp;
480  sidx.ToLong( &tmp );
481 
482  if( tmp > 0 && tmp <= INT_MAX )
483  filter = (int) tmp;
484  }
485 
486  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
487  || model.m_Filename.empty() )
488  {
489  return;
490  }
491 
492  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
493  sidx = wxString::Format( wxT( "%i" ), filter );
495  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
496  wxString alias;
497  wxString shortPath;
498  wxString filename = model.m_Filename;
499 
500  if( res && res->SplitAlias( filename, alias, shortPath ) )
501  filename = alias + wxT( ":" ) + shortPath;
502 
503 #ifdef __WINDOWS__
504  // In Kicad files, filenames and paths are stored using Unix notation
505  model.m_Filename.Replace( "\\", "/" );
506 #endif
507 
508  model.m_Preview = true;
509  m_shapes3D_list.push_back( model );
510 
511  int idx = m_modelsGrid->GetNumberRows();
512  m_modelsGrid->AppendRows( 1 );
513  m_modelsGrid->SetCellValue( idx, 0, filename );
514  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
515 
517 }
518 
519 
521 {
522  MODULE_3D_SETTINGS model;
523 
524  model.m_Preview = true;
525  m_shapes3D_list.push_back( model );
526 
527  int row = m_modelsGrid->GetNumberRows();
528  m_modelsGrid->AppendRows( 1 );
529  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
530 
531  m_modelsGrid->SetFocus();
532  m_modelsGrid->MakeCellVisible( row, 0 );
533  m_modelsGrid->SetGridCursor( row, 0 );
534 
535  m_modelsGrid->EnableCellEditControl( true );
536  m_modelsGrid->ShowCellEditControl();
537 }
538 
539 
541 {
542  // Commit any pending in-place edits and close the editor
543  m_itemsGrid->DisableCellEditControl();
544 
545  if( !DIALOG_SHIM::Validate() )
546  return false;
547 
548  // Check for empty texts.
549  for( size_t i = 2; i < m_texts->size(); ++i )
550  {
551  TEXTE_MODULE& text = m_texts->at( i );
552 
553  if( text.GetText().IsEmpty() )
554  {
555  if( m_NoteBook->GetSelection() != 0 )
556  m_NoteBook->SetSelection( 0 );
557 
558  m_delayedErrorMessage = _( "Text items must have some content." );
561 
562  return false;
563  }
564  }
565 
566  if( !m_netClearance.Validate( true ) )
567  return false;
568 
569  return true;
570 }
571 
572 
574 {
575  if( !Validate() )
576  return false;
577 
578  if( !DIALOG_SHIM::TransferDataFromWindow() )
579  return false;
580 
581  if( !m_PanelGeneral->TransferDataFromWindow() )
582  return false;
583 
584  if( !m_Panel3D->TransferDataFromWindow() )
585  return false;
586 
587  if( m_DC )
588  {
591  }
592 
593  auto view = m_frame->GetGalCanvas()->GetView();
594  BOARD_COMMIT commit( m_frame );
595  commit.Modify( m_footprint );
596 
597  // copy reference and value
598  m_footprint->Reference() = m_texts->at( 0 );
599  m_footprint->Value() = m_texts->at( 1 );
600 
601  size_t i = 2;
602  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
603  {
604  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
605 
606  if( textModule )
607  {
608  // copy grid table entries till we run out, then delete any remaining texts
609  if( i < m_texts->size() )
610  *textModule = m_texts->at( i++ );
611  else
612  textModule->DeleteStructure();
613  }
614  }
615 
616  // if there are still grid table entries, create new texts for them
617  while( i < m_texts->size() )
618  {
619  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
620  m_footprint->Add( newText, ADD_APPEND );
621  view->Add( newText );
622  }
623 
624  // Initialize masks clearances
628 
629  double dtmp = 0.0;
630  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
631  msg.ToDouble( &dtmp );
632 
633  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
634  if( dtmp < -50.0 )
635  dtmp = -50.0;
636  // A margin ratio is always <= 0
637  // 0 means use full pad copper area
638  if( dtmp > 0.0 )
639  dtmp = 0.0;
640 
642 
643  switch( m_ZoneConnectionChoice->GetSelection() )
644  {
645  default:
650  }
651 
652  // Set Module Position
653  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
654  m_footprint->SetPosition( modpos );
655  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
656  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
657 
658  switch( m_AttributsCtrl->GetSelection() )
659  {
660  case 0: m_footprint->SetAttributes( 0 ); break;
661  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
662  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
663  default: wxFAIL;
664  }
665 
668 
669  // Now, set orientation. Must be done after other changes because rotation changes field
670  // positions on board (so that relative positions are held constant)
671  m_OrientValidator.TransferFromWindow();
672 
673  int orient = KiROUND( m_OrientValue * 10.0 );
674 
675  if( m_footprint->GetOrientation() != orient )
677 
678  // Set component side, that also have effect on the fields positions on board
679  bool change_layer = false;
680  if( m_LayerCtrl->GetSelection() == 0 ) // layer req = COMPONENT
681  {
682  if( m_footprint->GetLayer() == B_Cu )
683  change_layer = true;
684  }
685  else if( m_footprint->GetLayer() == F_Cu )
686  change_layer = true;
687 
688  if( change_layer )
690 
691  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
692  draw3D->clear();
693  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
694 
696 
697  // This is a simple edit, we must create an undo entry
698  if( m_footprint->GetFlags() == 0 )
699  commit.Push( _( "Modify module properties" ) );
700 
701  SetReturnCode( PRM_EDITOR_EDIT_OK );
702 
703  if( m_DC )
704  {
707  }
708 
709  return true;
710 }
711 
712 
714 {
715  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
716  TEXTE_MODULE textMod( m_footprint );
717 
718  // Set active layer if legal; otherwise copy layer from previous text item
719  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
720  textMod.SetLayer( m_frame->GetActiveLayer() );
721  else
722  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
723 
724  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
725  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
726  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
727  textMod.SetKeepUpright( dsnSettings.GetTextUpright( 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 
745 {
746  int rowCount = m_itemsGrid->GetNumberRows();
747  int curRow = m_itemsGrid->GetGridCursorRow();
748 
749  if( curRow < 0 || curRow >= (int) m_texts->size() )
750  return;
751 
752  if( curRow < 2 )
753  {
754  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
755  return;
756  }
757 
758  auto start = m_texts->begin() + curRow;
759  m_texts->erase( start, start + 1 );
760 
761  // notify the grid
762  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
763  m_itemsGrid->ProcessTableMessage( msg );
764 
765  if( curRow == rowCount - 1 )
766  {
767  m_itemsGrid->MakeCellVisible( curRow-1, m_itemsGrid->GetGridCursorCol() );
768  m_itemsGrid->SetGridCursor( curRow-1, m_itemsGrid->GetGridCursorCol() );
769  }
770 }
771 
772 
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  m_itemsGrid->SetColSize( 0, std::max( itemsWidth, 120 ) );
792 
793  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
794 }
795 
796 
798 {
799  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
800  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
801 
802  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
803  // even when the original validation was triggered from a killFocus event, and so
804  // that the corresponding notebook page can be shown in the background when triggered
805  // from an OK.
806  if( m_delayedFocusRow >= 0 )
807  {
808  if( !m_delayedErrorMessage.IsEmpty() )
809  {
810  // We will re-enter this routine when the error dialog is displayed, so make
811  // sure we don't keep putting up more dialogs.
812  wxString msg = m_delayedErrorMessage;
813  m_delayedErrorMessage = wxEmptyString;
814 
815  // Do not use DisplayErrorMessage(); it screws up window order on Mac
816  DisplayError( nullptr, msg );
817  }
818 
819  m_delayedFocusGrid->SetFocus();
822 
823  m_delayedFocusGrid->EnableCellEditControl( true );
824  m_delayedFocusGrid->ShowCellEditControl();
825 
826  m_delayedFocusRow = -1;
828  }
829 }
830 
831 
832 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
833 {
834  adjustGridColumns( aEvent.GetSize().GetX());
835 
836  aEvent.Skip();
837 }
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:575
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:504
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Class PROJECT holds project specific data.
Definition: project.h:56
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:119
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:572
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:372
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:76
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:167
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:212
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
int GetPlacementCost90() const
Definition: class_module.h:574
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:47
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:503
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
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
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
void SetTable(wxGridTableBase *table)
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:29
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:58
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:263
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:894
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
const wxString & GetPath() const
Definition: class_module.h:202
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:185
int GetPlacementCost180() const
Definition: class_module.h:571
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:146
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