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 
193 }
194 
195 
197 {
199 }
200 
201 
203 {
204  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
205 }
206 
207 
209 {
210  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
211 }
212 
213 
215 {
216  if( m_Orient0->GetValue() )
217  m_OrientValue = 0.0;
218  else if( m_Orient90->GetValue() )
219  m_OrientValue = 90.0;
220  else if( m_Orient270->GetValue() )
221  m_OrientValue = 270.0;
222  else if( m_Orient180->GetValue() )
223  m_OrientValue = 180.0;
224 
225  m_OrientValidator.TransferToWindow();
226 }
227 
228 
230 {
231  m_OrientOther->SetValue( true );
232 
233  aEvent.Skip();
234 }
235 
236 
238 {
239  if( !wxDialog::TransferDataToWindow() )
240  return false;
241 
242  if( !m_PanelGeneral->TransferDataToWindow() )
243  return false;
244 
245  if( !m_Panel3D->TransferDataToWindow() )
246  return false;
247 
248  // Module Texts
249 
250  m_texts->push_back( m_footprint->Reference() );
251  m_texts->push_back( m_footprint->Value() );
252 
253  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
254  {
255  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
256 
257  if( textModule )
258  m_texts->push_back( *textModule );
259  }
260 
261  // notify the grid
262  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
263  m_itemsGrid->ProcessTableMessage( tmsg );
264 
265  // Module Properties
266 
269 
271  m_Orient0->SetValue( m_OrientValue == 0.0 );
272  m_Orient90->SetValue( m_OrientValue == 90.0 || m_OrientValue == -270.0 );
273  m_Orient270->SetValue( m_OrientValue == 270.0 || m_OrientValue == -90.0 );
274  m_Orient180->SetValue( m_OrientValue == 180.0 || m_OrientValue == -180.0 );
275 
276  m_OrientOther->SetValue( !m_Orient0->GetValue() && !m_Orient90->GetValue()
277  && !m_Orient270->GetValue() && !m_Orient180->GetValue() );
278  m_OrientValidator.TransferToWindow();
279 
280  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
281 
282  if( m_footprint->IsLocked() )
283  m_AutoPlaceCtrl->SetSelection( 2 );
284  else if( m_footprint->PadsLocked() )
285  m_AutoPlaceCtrl->SetSelection( 1 );
286  else
287  m_AutoPlaceCtrl->SetSelection( 0 );
288 
289  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
290  "can arbitrarily select and edit component's pads." ) );
291  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
292  "its pads cannot be selected or edited." ) );
293  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
294  "auto placed." ) );
295 
298 
299  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
300  "Footprints with this option are not put in the footprint position list file" ) );
301  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
302  "Only footprints with this option are put in the footprint position list file" ) );
303  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn on board\n"
304  "such as an edge connector (old ISA PC bus for instance)" ) );
305 
306  switch( m_footprint->GetAttributes() & 255 )
307  {
308  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
309  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
310  case 0:
311  default: m_AttributsCtrl->SetSelection( 0 ); break;
312  }
313 
314  // Local Clearances
315 
319 
320  // Prefer "-0" to "0" for normally negative values
322  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
323 
324  // Add solder paste margin ratio in per cent
325  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
326  wxString msg;
327  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
328 
330  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
331  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
332  else
334 
335  switch( m_footprint->GetZoneConnection() )
336  {
337  default:
338  case PAD_ZONE_CONN_INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
339  case PAD_ZONE_CONN_FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
340  case PAD_ZONE_CONN_THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
341  case PAD_ZONE_CONN_NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
342  }
343 
344  // 3D Settings
345 
346  wxString default_path;
347  wxGetEnv( KISYS3DMOD, &default_path );
348 #ifdef __WINDOWS__
349  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
350 #endif
351 
352  m_shapes3D_list.clear();
353  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
354 
355  wxString origPath, alias, shortPath;
356  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
357 
358  for( MODULE_3D_SETTINGS model : m_footprint->Models() )
359  {
360  m_shapes3D_list.push_back( model );
361  origPath = model.m_Filename;
362 
363  if( res && res->SplitAlias( origPath, alias, shortPath ) )
364  origPath = alias + wxT( ":" ) + shortPath;
365 
366  m_modelsGrid->AppendRows( 1 );
367  int row = m_modelsGrid->GetNumberRows() - 1;
368  m_modelsGrid->SetCellValue( row, 0, origPath );
369  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
370  }
371 
372  select3DModel( 0 ); // will clamp idx within bounds
373 
374  // Show the footprint's ID.
375  m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
376 
377  Layout();
378  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
379 
380  return true;
381 }
382 
383 
385 {
386  m_inSelect = true;
387 
388  aModelIdx = std::max( 0, aModelIdx );
389  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
390 
391  if( m_modelsGrid->GetNumberRows() )
392  {
393  m_modelsGrid->SelectRow( aModelIdx );
394  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
395  }
396 
397  m_PreviewPane->SetSelectedModel( aModelIdx );
398 
399  m_inSelect = false;
400 }
401 
402 
404 {
405  if( !m_inSelect )
406  select3DModel( aEvent.GetRow() );
407 }
408 
409 
411 {
412  if( aEvent.GetCol() == 0 )
413  {
414  bool hasAlias = false;
415  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
416  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
417 
418  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
419  {
420  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
422  m_delayedFocusRow = aEvent.GetRow();
423  m_delayedFocusColumn = aEvent.GetCol();
424  aEvent.Veto();
425  }
426 
427  // if the user has specified an alias in the name then prepend ':'
428  if( hasAlias )
429  filename.insert( 0, wxT( ":" ) );
430 
431 #ifdef __WINDOWS__
432  // In Kicad files, filenames and paths are stored using Unix notation
433  filename.Replace( wxT( "\\" ), wxT( "/" ) );
434 #endif
435 
436  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
437  }
438  else if( aEvent.GetCol() == 1 )
439  {
440  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
441 
442  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
443  }
444 
446 }
447 
448 
450 {
451  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
452 
453  int idx = m_modelsGrid->GetGridCursorRow();
454 
455  if( idx >= 0 )
456  {
457  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
458  m_modelsGrid->DeleteRows( idx, 1 );
459 
460  select3DModel( idx ); // will clamp idx within bounds
462  }
463 }
464 
465 
467 {
469  return;
470 
471  PROJECT& prj = Prj();
472  MODULE_3D_SETTINGS model;
473 
474  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
475  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
476  int filter = 0;
477 
478  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
479  // varaible and fall back to the project path if necessary.
480  if( initialpath.IsEmpty() )
481  {
482  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
483  initialpath = prj.GetProjectPath();
484  }
485 
486  if( !sidx.empty() )
487  {
488  long tmp;
489  sidx.ToLong( &tmp );
490 
491  if( tmp > 0 && tmp <= INT_MAX )
492  filter = (int) tmp;
493  }
494 
495  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
496  || model.m_Filename.empty() )
497  {
498  return;
499  }
500 
501  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
502  sidx = wxString::Format( wxT( "%i" ), filter );
504  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
505  wxString alias;
506  wxString shortPath;
507  wxString filename = model.m_Filename;
508 
509  if( res && res->SplitAlias( filename, alias, shortPath ) )
510  filename = alias + wxT( ":" ) + shortPath;
511 
512 #ifdef __WINDOWS__
513  // In Kicad files, filenames and paths are stored using Unix notation
514  model.m_Filename.Replace( "\\", "/" );
515 #endif
516 
517  model.m_Preview = true;
518  m_shapes3D_list.push_back( model );
519 
520  int idx = m_modelsGrid->GetNumberRows();
521  m_modelsGrid->AppendRows( 1 );
522  m_modelsGrid->SetCellValue( idx, 0, filename );
523  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
524 
526 }
527 
528 
530 {
532  return;
533 
534  MODULE_3D_SETTINGS model;
535 
536  model.m_Preview = true;
537  m_shapes3D_list.push_back( model );
538 
539  int row = m_modelsGrid->GetNumberRows();
540  m_modelsGrid->AppendRows( 1 );
541  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
542 
543  m_modelsGrid->SetFocus();
544  m_modelsGrid->MakeCellVisible( row, 0 );
545  m_modelsGrid->SetGridCursor( row, 0 );
546 
547  m_modelsGrid->EnableCellEditControl( true );
548  m_modelsGrid->ShowCellEditControl();
549 }
550 
551 
553 {
555  return false;
556 
557  if( !DIALOG_SHIM::Validate() )
558  return false;
559 
560  // Check for empty texts.
561  for( size_t i = 2; i < m_texts->size(); ++i )
562  {
563  TEXTE_MODULE& text = m_texts->at( i );
564 
565  if( text.GetText().IsEmpty() )
566  {
567  if( m_NoteBook->GetSelection() != 0 )
568  m_NoteBook->SetSelection( 0 );
569 
571  m_delayedErrorMessage = _( "Text items must have some content." );
574 
575  return false;
576  }
577  }
578 
579  if( !m_netClearance.Validate( true ) )
580  return false;
581 
582  return true;
583 }
584 
585 
587 {
588  if( !Validate() )
589  return false;
590 
591  if( !DIALOG_SHIM::TransferDataFromWindow() )
592  return false;
593 
594  if( !m_PanelGeneral->TransferDataFromWindow() )
595  return false;
596 
597  if( !m_Panel3D->TransferDataFromWindow() )
598  return false;
599 
600  if( m_DC )
601  {
604  }
605 
606  auto view = m_frame->GetGalCanvas()->GetView();
607  BOARD_COMMIT commit( m_frame );
608  commit.Modify( m_footprint );
609 
610  // copy reference and value
611  m_footprint->Reference() = m_texts->at( 0 );
612  m_footprint->Value() = m_texts->at( 1 );
613 
614  size_t i = 2;
615  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
616  {
617  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
618 
619  if( textModule )
620  {
621  // copy grid table entries till we run out, then delete any remaining texts
622  if( i < m_texts->size() )
623  *textModule = m_texts->at( i++ );
624  else
625  textModule->DeleteStructure();
626  }
627  }
628 
629  // if there are still grid table entries, create new texts for them
630  while( i < m_texts->size() )
631  {
632  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
633  m_footprint->Add( newText, ADD_APPEND );
634  view->Add( newText );
635  }
636 
637  // Initialize masks clearances
641 
642  double dtmp = 0.0;
643  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
644  msg.ToDouble( &dtmp );
645 
646  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
647  if( dtmp < -50.0 )
648  dtmp = -50.0;
649  // A margin ratio is always <= 0
650  // 0 means use full pad copper area
651  if( dtmp > 0.0 )
652  dtmp = 0.0;
653 
655 
656  switch( m_ZoneConnectionChoice->GetSelection() )
657  {
658  default:
663  }
664 
665  // Set Module Position
666  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
667  m_footprint->SetPosition( modpos );
668  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
669  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
670 
671  switch( m_AttributsCtrl->GetSelection() )
672  {
673  case 0: m_footprint->SetAttributes( 0 ); break;
674  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
675  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
676  default: wxFAIL;
677  }
678 
681 
682  // Now, set orientation. Must be done after other changes because rotation changes field
683  // positions on board (so that relative positions are held constant)
684  m_OrientValidator.TransferFromWindow();
685 
686  int orient = KiROUND( m_OrientValue * 10.0 );
687 
688  if( m_footprint->GetOrientation() != orient )
690 
691  // Set component side, that also have effect on the fields positions on board
692  bool change_layer = false;
693  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
694  {
695  if( m_footprint->GetLayer() == B_Cu )
696  change_layer = true;
697  }
698  else if( m_footprint->GetLayer() == F_Cu )
699  change_layer = true;
700 
701  if( change_layer )
703 
704  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
705  draw3D->clear();
706  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
707 
709 
710  // This is a simple edit, we must create an undo entry
711  int mask = EDA_ITEM_ALL_FLAGS - ( SELECTED | HIGHLIGHTED | BRIGHTENED );
712  if( ( m_footprint->GetFlags() & mask ) == 0 ) // i.e. not edited, or moved
713  commit.Push( _( "Modify module properties" ) );
714 
715  SetReturnCode( PRM_EDITOR_EDIT_OK );
716 
717  if( m_DC )
718  {
721  }
722 
723  return true;
724 }
725 
726 
728 {
730  return;
731 
732  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
733  TEXTE_MODULE textMod( m_footprint );
734 
735  // Set active layer if legal; otherwise copy layer from previous text item
736  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
737  textMod.SetLayer( m_frame->GetActiveLayer() );
738  else
739  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
740 
741  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
742  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
743  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
744  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
745 
746  m_texts->push_back( textMod );
747 
748  // notify the grid
749  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
750  m_itemsGrid->ProcessTableMessage( msg );
751 
752  m_itemsGrid->SetFocus();
753  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
754  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
755 
756  m_itemsGrid->EnableCellEditControl( true );
757  m_itemsGrid->ShowCellEditControl();
758 }
759 
760 
762 {
763  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
764 
765  int curRow = m_itemsGrid->GetGridCursorRow();
766 
767  if( curRow < 0 )
768  return;
769  else if( curRow < 2 )
770  {
771  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
772  return;
773  }
774 
775  m_texts->erase( m_texts->begin() + curRow );
776 
777  // notify the grid
778  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
779  m_itemsGrid->ProcessTableMessage( msg );
780 
781  if( m_itemsGrid->GetNumberRows() > 0 )
782  {
783  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
784  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
785  }
786 }
787 
788 
790 {
791  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
793 }
794 
795 
797 {
798  // Account for scroll bars
799  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
800  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
801 
802  itemsWidth -= m_itemsGrid->GetRowLabelSize();
803 
804  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
805  itemsWidth -= m_itemsGrid->GetColSize( i );
806 
807  m_itemsGrid->SetColSize( 0, std::max( itemsWidth, 120 ) );
808 
809  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
810 }
811 
812 
814 {
815  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
816  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
817 
818  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
819  // even when the original validation was triggered from a killFocus event, and so
820  // that the corresponding notebook page can be shown in the background when triggered
821  // from an OK.
822  if( m_delayedFocusRow >= 0 )
823  {
824  // We will re-enter this routine if an error dialog is displayed, so make sure we
825  // zero out our member variables first.
826  wxGrid* grid = m_delayedFocusGrid;
827  int row = m_delayedFocusRow;
828  int col = m_delayedFocusColumn;
829  wxString msg = m_delayedErrorMessage;
830 
831  m_delayedFocusGrid = nullptr;
832  m_delayedFocusRow = -1;
834  m_delayedErrorMessage = wxEmptyString;
835 
836  if( !msg.IsEmpty() )
837  {
838  // Do not use DisplayErrorMessage(); it screws up window order on Mac
839  DisplayError( nullptr, msg );
840  }
841 
842  grid->SetFocus();
843  grid->MakeCellVisible( row, col );
844  grid->SetGridCursor( row, col );
845 
846  grid->EnableCellEditControl( true );
847  grid->ShowCellEditControl();
848 
849  if( grid == m_itemsGrid && row == 0 && col == 0 )
850  {
851  auto referenceEditor = grid->GetCellEditor( 0, 0 );
852  SelectReferenceNumber( dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) );
853  referenceEditor->DecRef();
854  }
855  }
856 }
857 
858 
859 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
860 {
861  adjustGridColumns( aEvent.GetSize().GetX());
862 
863  aEvent.Skip();
864 }
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:584
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:258
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:513
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Class PROJECT holds project specific data.
Definition: project.h:57
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
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:581
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...
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:108
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:583
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...
#define EDA_ITEM_ALL_FLAGS
Definition: base_struct.h:145
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
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
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
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:77
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)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
bool PadsLocked() const
Definition: class_module.h:304
#define SELECTED
Definition: base_struct.h:121
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: common.cpp:155
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:212
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:512
virtual void CrossHairOn(wxDC *DC=nullptr)
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
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
int GetAttributes() const
Definition: class_module.h:226
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
virtual void CrossHairOff(wxDC *DC=nullptr)
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:306
void SetPosition(const wxPoint &aPos) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
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...
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:268
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:90
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
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
see class PGM_BASE
#define HIGHLIGHTED
item is drawn in normal colors, when the rest is darkened
Definition: base_struct.h:137
void EditLibraryFootprint(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:278
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
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:908
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:245
int GetPlacementCost180() const
Definition: class_module.h:580
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:207
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:206
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