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-2019 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
28 #include <bitmaps.h>
29 #include <board_commit.h>
30 #include <board_design_settings.h>
31 #include <class_module.h>
32 #include <confirm.h>
33 #include <dialog_text_entry.h>
34 #include <fctsys.h>
35 #include <filename_resolver.h>
36 #include <kiface_i.h>
37 #include <math/util.h> // for KiROUND
38 #include <pcb_edit_frame.h>
39 #include <pcbnew.h>
40 #include <pcbnew_settings.h>
41 #include <pgm_base.h>
42 #include <validators.h>
43 #include <widgets/text_ctrl_eval.h>
44 #include <widgets/wx_grid.h>
45 
48 
50 
51 
52 #define FootprintTextShownColumnsKey wxT( "FootprintTextShownColumns" )
53 
54 int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
55 
56 
58  MODULE* aModule ) :
60  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
61  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
62  m_OrientValidator( 1, &m_OrientValue ),
63  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
64  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
65  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
66  m_initialFocus( true ),
67  m_inSelect( false )
68 {
69  m_frame = aParent;
70  m_footprint = aModule;
71 
73 
74  m_delayedErrorMessage = wxEmptyString;
75  m_delayedFocusGrid = nullptr;
76  m_delayedFocusRow = -1;
78 
79  // Give an icon
80  wxIcon icon;
81  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
82  SetIcon( icon );
83 
84  // Give a bit more room for combobox editors
85  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
86  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
87 
89  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
90  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
91 
92  // Show/hide text item columns according to the user's preference
94 
95  // Set up the 3D models grid
96  wxGridCellAttr* attr = new wxGridCellAttr;
97  attr->SetRenderer( new wxGridCellBoolRenderer() );
98  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
99  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
100  m_modelsGrid->SetColAttr( 1, attr );
101  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
102 
103  m_OrientValidator.SetRange( -360.0, 360.0 );
104  m_OrientValueCtrl->SetValidator( m_OrientValidator );
106 
107  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
108 
110 
111  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
112 
113  // Set font sizes
114  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
115  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
116  m_allow90Label->SetFont( infoFont );
117  m_allow180Label->SetFont( infoFont );
118  m_staticTextInfoCopper->SetFont( infoFont );
119  m_staticTextInfoPaste->SetFont( infoFont );
120 
121  m_libraryIDLabel->SetFont( infoFont );
122  m_tcLibraryID->SetFont( infoFont );
123  m_sheetPathLabel->SetFont( infoFont );
124  m_tcSheetPath->SetFont( infoFont );
125 
126  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
127  m_staticTextInfoValNeg->SetFont( infoFont );
128  m_staticTextInfoValPos->SetFont( infoFont );
129 
130  m_NoteBook->SetSelection( m_page );
131 
132  if( m_page == 0 )
133  {
135  m_delayedFocusRow = 0;
137  }
138  else if ( m_page == 1 )
140  else
141  {
143  m_delayedFocusRow = 0;
145  }
146 
147  m_sdbSizerStdButtonsOK->SetDefault();
148 
149  m_OrientValue = 0;
150 
151  // Configure button logos
152  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
153  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
154  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
155  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
156  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
157 
159 }
160 
161 
163 {
165  m_itemsGrid->GetShownColumns().ToStdString();
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 {
189 }
190 
191 
193 {
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 
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( auto item : m_footprint->GraphicalItems() )
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 
266  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
267 
269 
270  if( m_OrientValue == 0.0 )
271  m_Orient0->SetValue( true );
272  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
273  m_Orient90->SetValue( true );
274  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
275  m_Orient270->SetValue( true );
276  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
277  m_Orient180->SetValue( true );
278  else
279  m_OrientOther->SetValue( true );
280 
282 
283  if( m_footprint->IsLocked() )
284  m_AutoPlaceCtrl->SetSelection( 2 );
285  else if( m_footprint->PadsLocked() )
286  m_AutoPlaceCtrl->SetSelection( 1 );
287  else
288  m_AutoPlaceCtrl->SetSelection( 0 );
289 
290  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
291  "can arbitrarily select and edit component's pads." ) );
292  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
293  "its pads cannot be selected or edited." ) );
294  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
295  "auto placed." ) );
296 
299 
300  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
301  "Footprints with this option are not put in the footprint position list file" ) );
302  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
303  "Only footprints with this option are put in the footprint position list file" ) );
304  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn "
305  "on board\nsuch as an edge connector (old ISA PC bus for instance)" ) );
306 
307  switch( m_footprint->GetAttributes() & 255 )
308  {
309  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
310  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
311  case 0:
312  default: m_AttributsCtrl->SetSelection( 0 ); break;
313  }
314 
315  // Local Clearances
316 
320 
321  // Prefer "-0" to "0" for normally negative values
323  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
324 
325  // Add solder paste margin ratio in percent
326  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
327  wxString msg;
328  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
329 
331  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
332  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
333  else
335 
336  switch( m_footprint->GetZoneConnection() )
337  {
338  default:
340  m_ZoneConnectionChoice->SetSelection( 0 );
341  break;
343  m_ZoneConnectionChoice->SetSelection( 1 );
344  break;
346  m_ZoneConnectionChoice->SetSelection( 2 );
347  break;
349  m_ZoneConnectionChoice->SetSelection( 3 );
350  break;
351  }
352 
353  // 3D Settings
354 
355  wxString default_path;
356  wxGetEnv( KISYS3DMOD, &default_path );
357 #ifdef __WINDOWS__
358  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
359 #endif
360 
361  m_shapes3D_list.clear();
362  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
363 
364  wxString origPath, alias, shortPath;
365  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
366 
367  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
368  {
369  m_shapes3D_list.push_back( model );
370  origPath = model.m_Filename;
371 
372  if( res && res->SplitAlias( origPath, alias, shortPath ) )
373  origPath = alias + wxT( ":" ) + shortPath;
374 
375  m_modelsGrid->AppendRows( 1 );
376  int row = m_modelsGrid->GetNumberRows() - 1;
377  m_modelsGrid->SetCellValue( row, 0, origPath );
378  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
379  }
380 
381  select3DModel( 0 ); // will clamp idx within bounds
383 
384  // Show the footprint's ID.
385  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
386  m_tcSheetPath->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
387 
388  wxString path = "/";
389 
390  // Exclude the last path step (it's the component)
391  for( size_t i = 0; i + 1 < m_footprint->GetPath().size(); ++i )
392  {
393  if( path.length() > 1 )
394  path += "/";
395 
396  path += Prj().GetSheetName( m_footprint->GetPath()[i] );
397  }
398 
399  m_tcSheetPath->SetValue( path );
400  m_tcSheetPath->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
401 
402  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
403  {
404  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
405  false ) );
406  // Adjust the column size. The column 6 has a small bitmap, so its width must be
407  // taken in account
408  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
409 
410  if( col == 6 )
411  col_size += 20;
412 
413  if( m_itemsGrid->IsColShown( col ) )
414  m_itemsGrid->SetColSize( col, col_size );
415  }
416 
417  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
418  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
419 
420  Layout();
421  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
422 
423  return true;
424 }
425 
426 
428 {
429  m_inSelect = true;
430 
431  aModelIdx = std::max( 0, aModelIdx );
432  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
433 
434  if( m_modelsGrid->GetNumberRows() )
435  {
436  m_modelsGrid->SelectRow( aModelIdx );
437  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
438  }
439 
440  m_PreviewPane->SetSelectedModel( aModelIdx );
441 
442  m_inSelect = false;
443 }
444 
445 
447 {
448  if( !m_inSelect )
449  select3DModel( aEvent.GetRow() );
450 }
451 
452 
454 {
455  if( aEvent.GetCol() == 0 )
456  {
457  bool hasAlias = false;
458  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
459  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
460 
461  filename.Replace( "\n", "" );
462  filename.Replace( "\r", "" );
463  filename.Replace( "\t", "" );
464 
465  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
466  {
467  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
469  m_delayedFocusRow = aEvent.GetRow();
470  m_delayedFocusColumn = aEvent.GetCol();
471  aEvent.Veto();
472  }
473 
474  // if the user has specified an alias in the name then prepend ':'
475  if( hasAlias )
476  filename.insert( 0, wxT( ":" ) );
477 
478 #ifdef __WINDOWS__
479  // In Kicad files, filenames and paths are stored using Unix notation
480  filename.Replace( wxT( "\\" ), wxT( "/" ) );
481 #endif
482 
483  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
484  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
485  }
486  else if( aEvent.GetCol() == 1 )
487  {
488  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
489 
490  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
491  }
492 
494 }
495 
496 
498 {
499  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
500 
501  int idx = m_modelsGrid->GetGridCursorRow();
502 
503  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
504  {
505  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
506  m_modelsGrid->DeleteRows( idx, 1 );
507 
508  select3DModel( idx ); // will clamp idx within bounds
510  }
511 }
512 
513 
515 {
517  return;
518 
519  PROJECT& prj = Prj();
520  MODULE_3D_SETTINGS model;
521 
522  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
523  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
524  int filter = 0;
525 
526  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
527  // variable and fall back to the project path if necessary.
528  if( initialpath.IsEmpty() )
529  {
530  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
531  initialpath = prj.GetProjectPath();
532  }
533 
534  if( !sidx.empty() )
535  {
536  long tmp;
537  sidx.ToLong( &tmp );
538 
539  if( tmp > 0 && tmp <= INT_MAX )
540  filter = (int) tmp;
541  }
542 
543  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
544  || model.m_Filename.empty() )
545  {
546  return;
547  }
548 
549  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
550  sidx = wxString::Format( wxT( "%i" ), filter );
552  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
553  wxString alias;
554  wxString shortPath;
555  wxString filename = model.m_Filename;
556 
557  if( res && res->SplitAlias( filename, alias, shortPath ) )
558  filename = alias + wxT( ":" ) + shortPath;
559 
560 #ifdef __WINDOWS__
561  // In KiCad files, filenames and paths are stored using Unix notation
562  model.m_Filename.Replace( "\\", "/" );
563 #endif
564 
565  model.m_Preview = true;
566  m_shapes3D_list.push_back( model );
567 
568  int idx = m_modelsGrid->GetNumberRows();
569  m_modelsGrid->AppendRows( 1 );
570  m_modelsGrid->SetCellValue( idx, 0, filename );
571  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
572 
574 }
575 
576 
578 {
580  return;
581 
582  MODULE_3D_SETTINGS model;
583 
584  model.m_Preview = true;
585  m_shapes3D_list.push_back( model );
586 
587  int row = m_modelsGrid->GetNumberRows();
588  m_modelsGrid->AppendRows( 1 );
589  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
590 
591  m_modelsGrid->SetFocus();
592  m_modelsGrid->MakeCellVisible( row, 0 );
593  m_modelsGrid->SetGridCursor( row, 0 );
594 
595  m_modelsGrid->EnableCellEditControl( true );
596  m_modelsGrid->ShowCellEditControl();
597 }
598 
599 
601 {
603  return false;
604 
605  if( !DIALOG_SHIM::Validate() )
606  return false;
607 
608  // Check for empty texts.
609  for( size_t i = 2; i < m_texts->size(); ++i )
610  {
611  TEXTE_MODULE& text = m_texts->at( i );
612 
613  if( text.GetText().IsEmpty() )
614  {
615  if( m_NoteBook->GetSelection() != 0 )
616  m_NoteBook->SetSelection( 0 );
617 
619  m_delayedErrorMessage = _( "Text items must have some content." );
621  m_delayedFocusRow = i;
622 
623  return false;
624  }
625  }
626 
627  if( !m_netClearance.Validate( 0, INT_MAX ) )
628  return false;
629 
630  return true;
631 }
632 
633 
635 {
636  if( !Validate() )
637  return false;
638 
639  if( !DIALOG_SHIM::TransferDataFromWindow() )
640  return false;
641 
642  if( !m_PanelGeneral->TransferDataFromWindow() )
643  return false;
644 
645  if( !m_Panel3D->TransferDataFromWindow() )
646  return false;
647 
648  auto view = m_frame->GetCanvas()->GetView();
649  BOARD_COMMIT commit( m_frame );
650  commit.Modify( m_footprint );
651 
652  // copy reference and value
653  m_footprint->Reference() = m_texts->at( 0 );
654  m_footprint->Value() = m_texts->at( 1 );
655 
656  size_t i = 2;
657 
658  for( auto item : m_footprint->GraphicalItems() )
659  {
660  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
661 
662  if( textModule )
663  {
664  // copy grid table entries till we run out, then delete any remaining texts
665  if( i < m_texts->size() )
666  *textModule = m_texts->at( i++ );
667  else
668  textModule->DeleteStructure();
669  }
670  }
671 
672  // if there are still grid table entries, create new texts for them
673  while( i < m_texts->size() )
674  {
675  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
676  m_footprint->Add( newText, ADD_MODE::APPEND );
677  view->Add( newText );
678  }
679 
680  // Initialize masks clearances
684 
685  double dtmp = 0.0;
686  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
687  msg.ToDouble( &dtmp );
688 
689  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
690  if( dtmp < -50.0 )
691  dtmp = -50.0;
692  // A margin ratio is always <= 0
693  // 0 means use full pad copper area
694  if( dtmp > 0.0 )
695  dtmp = 0.0;
696 
698 
699  switch( m_ZoneConnectionChoice->GetSelection() )
700  {
701  default:
702  case 0:
704  break;
705  case 1:
707  break;
708  case 2:
710  break;
711  case 3:
713  break;
714  }
715 
716  // Set Module Position
717  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
718  m_footprint->SetPosition( modpos );
719  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
720  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
721 
722  switch( m_AttributsCtrl->GetSelection() )
723  {
724  case 0: m_footprint->SetAttributes( 0 ); break;
725  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
726  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
727  default: wxFAIL;
728  }
729 
732 
733  // Now, set orientation. Must be done after other changes because rotation changes field
734  // positions on board (so that relative positions are held constant)
735  m_OrientValidator.TransferFromWindow();
736 
737  int orient = KiROUND( m_OrientValue * 10.0 );
738 
739  if( m_footprint->GetOrientation() != orient )
741 
742  // Set component side, that also have effect on the fields positions on board
743  bool change_layer = false;
744  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
745  {
746  if( m_footprint->GetLayer() == B_Cu )
747  change_layer = true;
748  }
749  else if( m_footprint->GetLayer() == F_Cu )
750  change_layer = true;
751 
752  if( change_layer )
754 
755  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
756  draw3D->clear();
757  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
758 
760 
761  // This is a simple edit, we must create an undo entry
762  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
763  commit.Push( _( "Modify module properties" ) );
764 
765  SetReturnCode( PRM_EDITOR_EDIT_OK );
766  return true;
767 }
768 
769 
771 {
773  return;
774 
775  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
776  TEXTE_MODULE textMod( m_footprint );
777 
778  // Set active layer if legal; otherwise copy layer from previous text item
779  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
780  textMod.SetLayer( m_frame->GetActiveLayer() );
781  else
782  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
783 
784  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
785  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
786  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
787  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
788  textMod.SetMirrored( IsBackLayer( textMod.GetLayer() ) );
789 
790  m_texts->push_back( textMod );
791 
792  // notify the grid
793  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
794  m_itemsGrid->ProcessTableMessage( msg );
795 
796  m_itemsGrid->SetFocus();
797  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
798  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
799 
800  m_itemsGrid->EnableCellEditControl( true );
801  m_itemsGrid->ShowCellEditControl();
802 }
803 
804 
806 {
807  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
808 
809  int curRow = m_itemsGrid->GetGridCursorRow();
810 
811  if( curRow < 0 )
812  return;
813  else if( curRow < 2 )
814  {
815  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
816  return;
817  }
818 
819  m_texts->erase( m_texts->begin() + curRow );
820 
821  // notify the grid
822  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
823  m_itemsGrid->ProcessTableMessage( msg );
824 
825  if( m_itemsGrid->GetNumberRows() > 0 )
826  {
827  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
828  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
829  }
830 }
831 
832 
834 {
835  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
837 }
838 
839 
841 {
842  // Account for scroll bars
843  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
844  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
845 
846  itemsWidth -= m_itemsGrid->GetRowLabelSize();
847 
848  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
849  itemsWidth -= m_itemsGrid->GetColSize( i );
850 
851  if( itemsWidth > 0 )
852  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
853  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
854 
855  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
856 }
857 
858 
860 {
861  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
862  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
863 
864  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
865  // even when the original validation was triggered from a killFocus event, and so
866  // that the corresponding notebook page can be shown in the background when triggered
867  // from an OK.
868  if( m_delayedFocusRow >= 0 )
869  {
870  // We will re-enter this routine if an error dialog is displayed, so make sure we
871  // zero out our member variables first.
872  wxGrid* grid = m_delayedFocusGrid;
873  int row = m_delayedFocusRow;
874  int col = m_delayedFocusColumn;
875  wxString msg = m_delayedErrorMessage;
876 
877  m_delayedFocusGrid = nullptr;
878  m_delayedFocusRow = -1;
880  m_delayedErrorMessage = wxEmptyString;
881 
882  if( !msg.IsEmpty() )
883  {
884  // Do not use DisplayErrorMessage(); it screws up window order on Mac
885  DisplayError( nullptr, msg );
886  }
887 
888  grid->SetFocus();
889  grid->MakeCellVisible( row, col );
890 
891  // Selecting the first grid item only makes sense for the
892  // items grid
893  if( !m_initialFocus || grid == m_itemsGrid )
894  {
895  grid->SetGridCursor( row, col );
896  grid->EnableCellEditControl( true );
897  grid->ShowCellEditControl();
898 
899  if( grid == m_itemsGrid && row == 0 && col == 0 )
900  {
901  auto referenceEditor = grid->GetCellEditor( 0, 0 );
902 
903  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
904  SelectReferenceNumber( textEntry );
905 
906  referenceEditor->DecRef();
907  }
908  }
909  m_initialFocus = false;
910  }
911 
912  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
913 }
914 
915 
916 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
917 {
918  adjustGridColumns( aEvent.GetSize().GetX());
919 
920  aEvent.Skip();
921 }
922 
923 
925 {
927 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
void SetPlacementCost90(int aCost)
Definition: class_module.h:556
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
int GetAttributes() const
Definition: class_module.h:259
double GetOrientation() const
Definition: class_module.h:215
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:555
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:477
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
PROJECT holds project specific data.
Definition: project.h:59
void SetLocalClearance(int aClearance)
Definition: class_module.h:235
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:553
This file is part of the common library.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:119
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:319
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetItalic(bool isItalic)
Definition: eda_text.h:163
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:248
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
provides an extensible class to resolve 3D model paths.
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
void UpdateDummyModule(bool aRelaodRequired=true)
UpdateModelInfoList - copy shapes from the current shape list which are flagged for preview to the co...
const LIB_ID & GetFPID() const
Definition: class_module.h:219
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:44
const KIID_PATH & GetPath() const
Definition: class_module.h:228
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:57
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
wxString m_FootprintTextShownColumns
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:756
int GetLocalSolderMaskMargin() const
Definition: class_module.h:231
bool m_Preview
Include module in 3D preview.
Definition: class_module.h:101
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:241
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:228
bool GetTextUpright(PCB_LAYER_ID aLayer) const
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:88
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: common.cpp:307
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...
pads are covered by copper
Defines a panel which is to be added to a wxFileDialog via SetExtraControl(); The panel shows a previ...
int GetLocalClearance() const
Definition: class_module.h:234
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:262
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void On3DModelCellChanged(wxGridEvent &aEvent) override
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
VTBL_ENTRY const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:171
wxFloatingPointValidator< double > m_OrientValidator
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:339
void SetPosition(const wxPoint &aPos) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void SetSelectedModel(int idx)
SetModelDataIdx - Sets the currently selected index in the model list so that the scale/rotation/offs...
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:301
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:232
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:237
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
const BITMAP_OPAQUE icon_modedit_xpm[1]
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:100
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:198
int GetPlacementCost180() const
Definition: class_module.h:552
EDA_UNITS m_units
Definition: dialog_shim.h:196
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:101
void OnOtherOrientation(wxCommandEvent &aEvent) override
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:238
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:213
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:240
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
see class PGM_BASE
Declaration of the eda_3d_viewer class.
void EditLibraryFootprint(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:311
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:243
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
PCB_EDIT_FRAME is the main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
Pads are not covered.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
bool PadsLocked() const
Definition: class_module.h:337
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
Module description (excepted pads)
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Function ValidateName returns true if the given path is a valid aliased relative path.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint GetPosition() const override
Definition: class_module.h:210
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
void updateOrientationControl()
Update the orientation validated control, without triggering a change event on the control (which wou...
DIALOG_FOOTPRINT_BOARD_EDITOR(PCB_EDIT_FRAME *aParent, MODULE *aModule)
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
void SetAttributes(int aAttributes)
Definition: class_module.h:260
int GetNumberRows() override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
PCBNEW_SETTINGS * GetSettings()
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list