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 
27 #include <fctsys.h>
28 #include <kiface_i.h>
29 #include <confirm.h>
30 #include <pcbnew.h>
31 #include <pgm_base.h>
32 #include <pcb_edit_frame.h>
33 #include <board_commit.h>
34 #include <board_design_settings.h>
35 #include <dialog_text_entry.h>
36 #include <class_module.h>
37 #include <validators.h>
38 #include <widgets/wx_grid.h>
39 #include <widgets/text_ctrl_eval.h>
40 #include <filename_resolver.h>
43 #include <bitmaps.h>
45 
47 
48 
49 #define FootprintTextShownColumnsKey wxT( "FootprintTextShownColumns" )
50 
51 int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
52 
53 
55  MODULE* aModule ) :
57  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
58  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
59  m_OrientValidator( 1, &m_OrientValue ),
60  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
61  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
62  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
63  m_initialFocus( true ),
64  m_inSelect( false )
65 {
67 
68  m_frame = aParent;
69  m_footprint = aModule;
70 
72 
73  m_delayedErrorMessage = wxEmptyString;
74  m_delayedFocusGrid = nullptr;
75  m_delayedFocusRow = -1;
77 
78  // Give an icon
79  wxIcon icon;
80  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
81  SetIcon( icon );
82 
83  // Give a bit more room for combobox editors
84  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
85  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
86 
88  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
89  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
90 
91  // Show/hide text item columns according to the user's preference
92  wxString shownColumns;
93  m_config->Read( FootprintTextShownColumnsKey, &shownColumns, wxT( "0 1 2 3 4 5 6" ) );
94  m_itemsGrid->ShowHideColumns( shownColumns );
95 
96  // Set up the 3D models grid
97  wxGridCellAttr* attr = new wxGridCellAttr;
98  attr->SetRenderer( new wxGridCellBoolRenderer() );
99  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
100  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
101  m_modelsGrid->SetColAttr( 1, attr );
102  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
103 
104  m_OrientValidator.SetRange( -360.0, 360.0 );
105  m_OrientValueCtrl->SetValidator( m_OrientValidator );
107 
108  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
109 
111 
112  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
113 
114  // Set font sizes
115  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
116  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
117  m_allow90Label->SetFont( infoFont );
118  m_allow180Label->SetFont( infoFont );
119  m_staticTextInfoCopper->SetFont( infoFont );
120  m_staticTextInfoPaste->SetFont( infoFont );
121 
122  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
123  m_staticTextInfoValNeg->SetFont( infoFont );
124  m_staticTextInfoValPos->SetFont( infoFont );
125 
126  m_NoteBook->SetSelection( m_page );
127 
128  if( m_page == 0 )
129  {
131  m_delayedFocusRow = 0;
133  }
134  else if ( m_page == 1 )
136  else
137  {
139  m_delayedFocusRow = 0;
141  }
142 
143  m_sdbSizerStdButtonsOK->SetDefault();
144 
145  m_OrientValue = 0;
146 
147  // Configure button logos
148  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
149  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
150  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
151  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
152  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
153 
155 }
156 
157 
159 {
161 
162  // Prevents crash bug in wxGrid's d'tor
164 
165  // Delete the GRID_TRICKS.
166  m_itemsGrid->PopEventHandler( true );
167  m_modelsGrid->PopEventHandler( true );
168 
169  // free the memory used by all models, otherwise models which were
170  // browsed but not used would consume memory
171  Prj().Get3DCacheManager()->FlushCache( false );
172 
173  // the GL canvas has to be visible before it is destroyed
174  m_page = m_NoteBook->GetSelection();
175  m_NoteBook->SetSelection( 1 );
176 
177  delete m_PreviewPane;
178 }
179 
180 
182 {
183  if( m_footprint->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
184  {
186  m_frame->OnModify();
187  }
188 
190 }
191 
192 
194 {
196 }
197 
198 
200 {
201  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
202 }
203 
204 
206 {
207  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
208 }
209 
210 
212 {
213  if( m_Orient0->GetValue() )
214  m_OrientValue = 0.0;
215  else if( m_Orient90->GetValue() )
216  m_OrientValue = 90.0;
217  else if( m_Orient270->GetValue() )
218  m_OrientValue = 270.0;
219  else if( m_Orient180->GetValue() )
220  m_OrientValue = 180.0;
221 
223 }
224 
225 
227 {
228  m_OrientOther->SetValue( true );
229 
230  aEvent.Skip();
231 }
232 
233 
235 {
236  if( !wxDialog::TransferDataToWindow() )
237  return false;
238 
239  if( !m_PanelGeneral->TransferDataToWindow() )
240  return false;
241 
242  if( !m_Panel3D->TransferDataToWindow() )
243  return false;
244 
245  // Module Texts
246 
247  m_texts->push_back( m_footprint->Reference() );
248  m_texts->push_back( m_footprint->Value() );
249 
250  for( auto item : m_footprint->GraphicalItems() )
251  {
252  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
253 
254  if( textModule )
255  m_texts->push_back( *textModule );
256  }
257 
258  // notify the grid
259  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
260  m_itemsGrid->ProcessTableMessage( tmsg );
261 
262  // Module Properties
263 
266 
268 
269  if( m_OrientValue == 0.0 )
270  m_Orient0->SetValue( true );
271  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
272  m_Orient90->SetValue( true );
273  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
274  m_Orient270->SetValue( true );
275  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
276  m_Orient180->SetValue( true );
277  else
278  m_OrientOther->SetValue( true );
279 
281 
282  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
283 
284  if( m_footprint->IsLocked() )
285  m_AutoPlaceCtrl->SetSelection( 2 );
286  else if( m_footprint->PadsLocked() )
287  m_AutoPlaceCtrl->SetSelection( 1 );
288  else
289  m_AutoPlaceCtrl->SetSelection( 0 );
290 
291  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
292  "can arbitrarily select and edit component's pads." ) );
293  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
294  "its pads cannot be selected or edited." ) );
295  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
296  "auto placed." ) );
297 
300 
301  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
302  "Footprints with this option are not put in the footprint position list file" ) );
303  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
304  "Only footprints with this option are put in the footprint position list file" ) );
305  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn "
306  "on board\nsuch as an edge connector (old ISA PC bus for instance)" ) );
307 
308  switch( m_footprint->GetAttributes() & 255 )
309  {
310  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
311  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
312  case 0:
313  default: m_AttributsCtrl->SetSelection( 0 ); break;
314  }
315 
316  // Local Clearances
317 
321 
322  // Prefer "-0" to "0" for normally negative values
324  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
325 
326  // Add solder paste margin ratio in percent
327  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
328  wxString msg;
329  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
330 
332  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
333  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
334  else
336 
337  switch( m_footprint->GetZoneConnection() )
338  {
339  default:
340  case PAD_ZONE_CONN_INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
341  case PAD_ZONE_CONN_FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
342  case PAD_ZONE_CONN_THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
343  case PAD_ZONE_CONN_NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
344  }
345 
346  // 3D Settings
347 
348  wxString default_path;
349  wxGetEnv( KISYS3DMOD, &default_path );
350 #ifdef __WINDOWS__
351  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
352 #endif
353 
354  m_shapes3D_list.clear();
355  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
356 
357  wxString origPath, alias, shortPath;
358  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
359 
360  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
361  {
362  m_shapes3D_list.push_back( model );
363  origPath = model.m_Filename;
364 
365  if( res && res->SplitAlias( origPath, alias, shortPath ) )
366  origPath = alias + wxT( ":" ) + shortPath;
367 
368  m_modelsGrid->AppendRows( 1 );
369  int row = m_modelsGrid->GetNumberRows() - 1;
370  m_modelsGrid->SetCellValue( row, 0, origPath );
371  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
372  }
373 
374  select3DModel( 0 ); // will clamp idx within bounds
376 
377  // Show the footprint's ID.
378  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
379 
380  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
381  {
382  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
383  false ) );
384  // Adjust the column size. The column 6 has a small bitmap, so its width must be
385  // taken in account
386  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
387 
388  if( col == 6 )
389  col_size += 20;
390 
391  if( m_itemsGrid->IsColShown( col ) )
392  m_itemsGrid->SetColSize( col, col_size );
393  }
394 
395  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
396  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
397 
398  Layout();
399  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
400 
401  return true;
402 }
403 
404 
406 {
407  m_inSelect = true;
408 
409  aModelIdx = std::max( 0, aModelIdx );
410  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
411 
412  if( m_modelsGrid->GetNumberRows() )
413  {
414  m_modelsGrid->SelectRow( aModelIdx );
415  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
416  }
417 
418  m_PreviewPane->SetSelectedModel( aModelIdx );
419 
420  m_inSelect = false;
421 }
422 
423 
425 {
426  if( !m_inSelect )
427  select3DModel( aEvent.GetRow() );
428 }
429 
430 
432 {
433  if( aEvent.GetCol() == 0 )
434  {
435  bool hasAlias = false;
436  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
437  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
438 
439  filename.Replace( "\n", "" );
440  filename.Replace( "\r", "" );
441  filename.Replace( "\t", "" );
442 
443  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
444  {
445  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
447  m_delayedFocusRow = aEvent.GetRow();
448  m_delayedFocusColumn = aEvent.GetCol();
449  aEvent.Veto();
450  }
451 
452  // if the user has specified an alias in the name then prepend ':'
453  if( hasAlias )
454  filename.insert( 0, wxT( ":" ) );
455 
456 #ifdef __WINDOWS__
457  // In Kicad files, filenames and paths are stored using Unix notation
458  filename.Replace( wxT( "\\" ), wxT( "/" ) );
459 #endif
460 
461  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
462  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
463  }
464  else if( aEvent.GetCol() == 1 )
465  {
466  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
467 
468  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
469  }
470 
472 }
473 
474 
476 {
477  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
478 
479  int idx = m_modelsGrid->GetGridCursorRow();
480 
481  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
482  {
483  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
484  m_modelsGrid->DeleteRows( idx, 1 );
485 
486  select3DModel( idx ); // will clamp idx within bounds
488  }
489 }
490 
491 
493 {
495  return;
496 
497  PROJECT& prj = Prj();
498  MODULE_3D_SETTINGS model;
499 
500  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
501  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
502  int filter = 0;
503 
504  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
505  // variable and fall back to the project path if necessary.
506  if( initialpath.IsEmpty() )
507  {
508  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
509  initialpath = prj.GetProjectPath();
510  }
511 
512  if( !sidx.empty() )
513  {
514  long tmp;
515  sidx.ToLong( &tmp );
516 
517  if( tmp > 0 && tmp <= INT_MAX )
518  filter = (int) tmp;
519  }
520 
521  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
522  || model.m_Filename.empty() )
523  {
524  return;
525  }
526 
527  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
528  sidx = wxString::Format( wxT( "%i" ), filter );
530  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
531  wxString alias;
532  wxString shortPath;
533  wxString filename = model.m_Filename;
534 
535  if( res && res->SplitAlias( filename, alias, shortPath ) )
536  filename = alias + wxT( ":" ) + shortPath;
537 
538 #ifdef __WINDOWS__
539  // In KiCad files, filenames and paths are stored using Unix notation
540  model.m_Filename.Replace( "\\", "/" );
541 #endif
542 
543  model.m_Preview = true;
544  m_shapes3D_list.push_back( model );
545 
546  int idx = m_modelsGrid->GetNumberRows();
547  m_modelsGrid->AppendRows( 1 );
548  m_modelsGrid->SetCellValue( idx, 0, filename );
549  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
550 
552 }
553 
554 
556 {
558  return;
559 
560  MODULE_3D_SETTINGS model;
561 
562  model.m_Preview = true;
563  m_shapes3D_list.push_back( model );
564 
565  int row = m_modelsGrid->GetNumberRows();
566  m_modelsGrid->AppendRows( 1 );
567  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
568 
569  m_modelsGrid->SetFocus();
570  m_modelsGrid->MakeCellVisible( row, 0 );
571  m_modelsGrid->SetGridCursor( row, 0 );
572 
573  m_modelsGrid->EnableCellEditControl( true );
574  m_modelsGrid->ShowCellEditControl();
575 }
576 
577 
579 {
581  return false;
582 
583  if( !DIALOG_SHIM::Validate() )
584  return false;
585 
586  // Check for empty texts.
587  for( size_t i = 2; i < m_texts->size(); ++i )
588  {
589  TEXTE_MODULE& text = m_texts->at( i );
590 
591  if( text.GetText().IsEmpty() )
592  {
593  if( m_NoteBook->GetSelection() != 0 )
594  m_NoteBook->SetSelection( 0 );
595 
597  m_delayedErrorMessage = _( "Text items must have some content." );
600 
601  return false;
602  }
603  }
604 
605  if( !m_netClearance.Validate( 0, INT_MAX ) )
606  return false;
607 
608  return true;
609 }
610 
611 
613 {
614  if( !Validate() )
615  return false;
616 
617  if( !DIALOG_SHIM::TransferDataFromWindow() )
618  return false;
619 
620  if( !m_PanelGeneral->TransferDataFromWindow() )
621  return false;
622 
623  if( !m_Panel3D->TransferDataFromWindow() )
624  return false;
625 
626  auto view = m_frame->GetCanvas()->GetView();
627  BOARD_COMMIT commit( m_frame );
628  commit.Modify( m_footprint );
629 
630  // copy reference and value
631  m_footprint->Reference() = m_texts->at( 0 );
632  m_footprint->Value() = m_texts->at( 1 );
633 
634  size_t i = 2;
635 
636  for( auto item : m_footprint->GraphicalItems() )
637  {
638  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
639 
640  if( textModule )
641  {
642  // copy grid table entries till we run out, then delete any remaining texts
643  if( i < m_texts->size() )
644  *textModule = m_texts->at( i++ );
645  else
646  textModule->DeleteStructure();
647  }
648  }
649 
650  // if there are still grid table entries, create new texts for them
651  while( i < m_texts->size() )
652  {
653  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
654  m_footprint->Add( newText, ADD_APPEND );
655  view->Add( newText );
656  }
657 
658  // Initialize masks clearances
662 
663  double dtmp = 0.0;
664  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
665  msg.ToDouble( &dtmp );
666 
667  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
668  if( dtmp < -50.0 )
669  dtmp = -50.0;
670  // A margin ratio is always <= 0
671  // 0 means use full pad copper area
672  if( dtmp > 0.0 )
673  dtmp = 0.0;
674 
676 
677  switch( m_ZoneConnectionChoice->GetSelection() )
678  {
679  default:
684  }
685 
686  // Set Module Position
687  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
688  m_footprint->SetPosition( modpos );
689  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
690  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
691 
692  switch( m_AttributsCtrl->GetSelection() )
693  {
694  case 0: m_footprint->SetAttributes( 0 ); break;
695  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
696  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
697  default: wxFAIL;
698  }
699 
702 
703  // Now, set orientation. Must be done after other changes because rotation changes field
704  // positions on board (so that relative positions are held constant)
705  m_OrientValidator.TransferFromWindow();
706 
707  int orient = KiROUND( m_OrientValue * 10.0 );
708 
709  if( m_footprint->GetOrientation() != orient )
711 
712  // Set component side, that also have effect on the fields positions on board
713  bool change_layer = false;
714  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
715  {
716  if( m_footprint->GetLayer() == B_Cu )
717  change_layer = true;
718  }
719  else if( m_footprint->GetLayer() == F_Cu )
720  change_layer = true;
721 
722  if( change_layer )
724 
725  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
726  draw3D->clear();
727  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
728 
730 
731  // This is a simple edit, we must create an undo entry
732  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
733  commit.Push( _( "Modify module properties" ) );
734 
735  SetReturnCode( PRM_EDITOR_EDIT_OK );
736  return true;
737 }
738 
739 
741 {
743  return;
744 
745  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
746  TEXTE_MODULE textMod( m_footprint );
747 
748  // Set active layer if legal; otherwise copy layer from previous text item
749  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
750  textMod.SetLayer( m_frame->GetActiveLayer() );
751  else
752  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
753 
754  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
755  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
756  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
757  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
758  textMod.SetMirrored( IsBackLayer( textMod.GetLayer() ) );
759 
760  m_texts->push_back( textMod );
761 
762  // notify the grid
763  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
764  m_itemsGrid->ProcessTableMessage( msg );
765 
766  m_itemsGrid->SetFocus();
767  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
768  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
769 
770  m_itemsGrid->EnableCellEditControl( true );
771  m_itemsGrid->ShowCellEditControl();
772 }
773 
774 
776 {
777  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
778 
779  int curRow = m_itemsGrid->GetGridCursorRow();
780 
781  if( curRow < 0 )
782  return;
783  else if( curRow < 2 )
784  {
785  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
786  return;
787  }
788 
789  m_texts->erase( m_texts->begin() + curRow );
790 
791  // notify the grid
792  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
793  m_itemsGrid->ProcessTableMessage( msg );
794 
795  if( m_itemsGrid->GetNumberRows() > 0 )
796  {
797  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
798  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
799  }
800 }
801 
802 
804 {
805  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
807 }
808 
809 
811 {
812  // Account for scroll bars
813  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
814  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
815 
816  itemsWidth -= m_itemsGrid->GetRowLabelSize();
817 
818  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
819  itemsWidth -= m_itemsGrid->GetColSize( i );
820 
821  if( itemsWidth > 0 )
822  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
823  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
824 
825  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
826 }
827 
828 
830 {
831  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
832  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
833 
834  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
835  // even when the original validation was triggered from a killFocus event, and so
836  // that the corresponding notebook page can be shown in the background when triggered
837  // from an OK.
838  if( m_delayedFocusRow >= 0 )
839  {
840  // We will re-enter this routine if an error dialog is displayed, so make sure we
841  // zero out our member variables first.
842  wxGrid* grid = m_delayedFocusGrid;
843  int row = m_delayedFocusRow;
844  int col = m_delayedFocusColumn;
845  wxString msg = m_delayedErrorMessage;
846 
847  m_delayedFocusGrid = nullptr;
848  m_delayedFocusRow = -1;
850  m_delayedErrorMessage = wxEmptyString;
851 
852  if( !msg.IsEmpty() )
853  {
854  // Do not use DisplayErrorMessage(); it screws up window order on Mac
855  DisplayError( nullptr, msg );
856  }
857 
858  grid->SetFocus();
859  grid->MakeCellVisible( row, col );
860 
861  // Selecting the first grid item only makes sense for the
862  // items grid
863  if( !m_initialFocus || grid == m_itemsGrid )
864  {
865  grid->SetGridCursor( row, col );
866  grid->EnableCellEditControl( true );
867  grid->ShowCellEditControl();
868 
869  if( grid == m_itemsGrid && row == 0 && col == 0 )
870  {
871  auto referenceEditor = grid->GetCellEditor( 0, 0 );
872  SelectReferenceNumber( dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) );
873  referenceEditor->DecRef();
874  }
875  }
876  m_initialFocus = false;
877  }
878 
879  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
880 }
881 
882 
883 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
884 {
885  adjustGridColumns( aEvent.GetSize().GetX());
886 
887  aEvent.Skip();
888 }
889 
890 
892 {
894 }
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:236
void SetPlacementCost90(int aCost)
Definition: class_module.h:552
int GetAttributes() const
Definition: class_module.h:255
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
double GetOrientation() const
Definition: class_module.h:218
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:551
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:473
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Class PROJECT holds project specific data.
Definition: project.h:58
void SetLocalClearance(int aClearance)
Definition: class_module.h:238
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:549
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
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
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 mouse and command handling (such as cut, copy, and paste) to a WX_GR...
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 removing from its parent if it has one.
void SetZoneConnection(ZoneConnection aType)
Definition: class_module.h:246
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...
const LIB_ID & GetFPID() const
Definition: class_module.h:222
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
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:186
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:746
int GetLocalSolderMaskMargin() const
Definition: class_module.h:234
bool m_Preview
Include module in 3D preview.
Definition: class_module.h:104
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:244
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.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
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
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: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:79
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: common.cpp:159
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:217
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...
int GetLocalClearance() const
Definition: class_module.h:237
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:270
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:472
PCB_GENERAL_SETTINGS & Settings()
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.
wxFloatingPointValidator< double > m_OrientValidator
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:335
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...
#define _(s)
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:297
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:235
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:240
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
int GetPlacementCost180() const
Definition: class_module.h:548
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:241
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
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:243
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:208
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:307
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,...
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:649
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
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:333
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:193
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:213
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
Use thermal relief for pads.
Definition: zones.h:53
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.
ZoneConnection GetZoneConnection() const
Definition: class_module.h:247
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)
Function SetThickness sets pen width.
Definition: eda_text.h:142
void SetAttributes(int aAttributes)
Definition: class_module.h:256
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:114
#define min(a, b)
Definition: auxiliary.h:85
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
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