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 
57  MODULE* aModule ) :
59  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
60  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
61  m_OrientValidator( 1, &m_OrientValue ),
62  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, true ),
63  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
64  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
65  m_initialFocus( true ),
66  m_inSelect( false )
67 {
68  m_frame = aParent;
69  m_footprint = aModule;
70 
71  for( size_t i = 0; i < m_NoteBook->GetPageCount(); ++i )
72  m_macHack.push_back( true );
73 
75 
76  m_delayedErrorMessage = wxEmptyString;
77  m_delayedFocusGrid = nullptr;
78  m_delayedFocusRow = -1;
80 
81  // Give an icon
82  wxIcon icon;
83  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
84  SetIcon( icon );
85 
86  // Give a bit more room for combobox editors
87  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
88  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
89 
91  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
92  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
93 
94  // Show/hide text item columns according to the user's preference
96 
97  // Set up the 3D models grid
98  wxGridCellAttr* attr = new wxGridCellAttr;
99  attr->SetRenderer( new wxGridCellBoolRenderer() );
100  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
101  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
102  m_modelsGrid->SetColAttr( 1, attr );
103  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
104  m_modelsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
105 
106  m_OrientValidator.SetRange( -360.0, 360.0 );
107  m_OrientValueCtrl->SetValidator( m_OrientValidator );
109 
110  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
111 
113 
114  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
115 
116  // Set font size for items showing long strings:
117  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
118  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
119  m_staticTextInfoCopper->SetFont( infoFont );
120  m_staticTextInfoPaste->SetFont( infoFont );
121 
122  m_tcLibraryID->SetFont( infoFont );
123  m_tcFullUuid->SetFont( infoFont );
124 
125  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
126  m_staticTextInfoValNeg->SetFont( infoFont );
127  m_staticTextInfoValPos->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  m_itemsGrid->GetShownColumns().ToStdString();
165 
166  // Prevents crash bug in wxGrid's d'tor
168 
169  // Delete the GRID_TRICKS.
170  m_itemsGrid->PopEventHandler( true );
171  m_modelsGrid->PopEventHandler( true );
172 
173  // free the memory used by all models, otherwise models which were
174  // browsed but not used would consume memory
175  Prj().Get3DCacheManager()->FlushCache( false );
176 
177  // the GL canvas has to be visible before it is destroyed
178  m_page = m_NoteBook->GetSelection();
179  m_NoteBook->SetSelection( 1 );
180 
181  delete m_PreviewPane;
182 }
183 
184 
186 {
188 }
189 
190 
192 {
194 }
195 
196 
198 {
199  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
200 }
201 
202 
204 {
205  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
206 }
207 
208 
210 {
211  if( m_Orient0->GetValue() )
212  m_OrientValue = 0.0;
213  else if( m_Orient90->GetValue() )
214  m_OrientValue = 90.0;
215  else if( m_Orient270->GetValue() )
216  m_OrientValue = 270.0;
217  else if( m_Orient180->GetValue() )
218  m_OrientValue = 180.0;
219 
221 }
222 
223 
225 {
226  m_OrientOther->SetValue( true );
227 
228  aEvent.Skip();
229 }
230 
231 
233 {
234  if( !wxDialog::TransferDataToWindow() )
235  return false;
236 
237  if( !m_PanelGeneral->TransferDataToWindow() )
238  return false;
239 
240  if( !m_Panel3D->TransferDataToWindow() )
241  return false;
242 
243  // Module Texts
244 
245  m_texts->push_back( m_footprint->Reference() );
246  m_texts->push_back( m_footprint->Value() );
247 
248  for( auto item : m_footprint->GraphicalItems() )
249  {
250  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
251 
252  if( textModule )
253  m_texts->push_back( *textModule );
254  }
255 
256  // notify the grid
257  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
258  m_itemsGrid->ProcessTableMessage( tmsg );
259 
260  // Module Properties
261 
264 
265  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
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  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 "
304  "on board\nsuch 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 percent
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:
339  m_ZoneConnectionChoice->SetSelection( 0 );
340  break;
342  m_ZoneConnectionChoice->SetSelection( 1 );
343  break;
345  m_ZoneConnectionChoice->SetSelection( 2 );
346  break;
348  m_ZoneConnectionChoice->SetSelection( 3 );
349  break;
350  }
351 
352  // 3D Settings
353 
354  wxString default_path;
355  wxGetEnv( KISYS3DMOD, &default_path );
356 #ifdef __WINDOWS__
357  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
358 #endif
359 
360  m_shapes3D_list.clear();
361  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
362 
363  wxString origPath, alias, shortPath;
364  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
365 
366  for( const MODULE_3D_SETTINGS& model : m_footprint->Models() )
367  {
368  m_shapes3D_list.push_back( model );
369  origPath = model.m_Filename;
370 
371  if( res && res->SplitAlias( origPath, alias, shortPath ) )
372  origPath = alias + wxT( ":" ) + shortPath;
373 
374  m_modelsGrid->AppendRows( 1 );
375  int row = m_modelsGrid->GetNumberRows() - 1;
376  m_modelsGrid->SetCellValue( row, 0, origPath );
377  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
378  }
379 
380  select3DModel( 0 ); // will clamp idx within bounds
382 
383  // Show the footprint's FPID.
384  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
385 
386  // Show the footprint's full unique Kicad ID.
387  m_tcFullUuid->SetValue( m_footprint->GetPath().AsString() );
388 
389  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
390  {
391  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
392  false ) );
393  // Adjust the column size. The column 6 has a small bitmap, so its width must be
394  // taken in account
395  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
396 
397  if( col == 6 )
398  col_size += 20;
399 
400  if( m_itemsGrid->IsColShown( col ) )
401  m_itemsGrid->SetColSize( col, col_size );
402  }
403 
404  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
405  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
406 
407  Layout();
408  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
409 
410  return true;
411 }
412 
413 
415 {
416  m_inSelect = true;
417 
418  aModelIdx = std::max( 0, aModelIdx );
419  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
420 
421  if( m_modelsGrid->GetNumberRows() )
422  {
423  m_modelsGrid->SelectRow( aModelIdx );
424  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
425  }
426 
427  m_PreviewPane->SetSelectedModel( aModelIdx );
428 
429  m_inSelect = false;
430 }
431 
432 
434 {
435  if( !m_inSelect )
436  select3DModel( aEvent.GetRow() );
437 }
438 
439 
441 {
442  if( aEvent.GetCol() == 0 )
443  {
444  bool hasAlias = false;
445  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
446  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
447 
448  filename.Replace( "\n", "" );
449  filename.Replace( "\r", "" );
450  filename.Replace( "\t", "" );
451 
452  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
453  {
454  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
456  m_delayedFocusRow = aEvent.GetRow();
457  m_delayedFocusColumn = aEvent.GetCol();
458  aEvent.Veto();
459  }
460 
461  // if the user has specified an alias in the name then prepend ':'
462  if( hasAlias )
463  filename.insert( 0, wxT( ":" ) );
464 
465 #ifdef __WINDOWS__
466  // In Kicad files, filenames and paths are stored using Unix notation
467  filename.Replace( wxT( "\\" ), wxT( "/" ) );
468 #endif
469 
470  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
471  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
472  }
473  else if( aEvent.GetCol() == 1 )
474  {
475  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
476 
477  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
478  }
479 
481 }
482 
483 
485 {
486  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
487 
488  int idx = m_modelsGrid->GetGridCursorRow();
489 
490  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
491  {
492  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
493  m_modelsGrid->DeleteRows( idx, 1 );
494 
495  select3DModel( idx ); // will clamp idx within bounds
497  }
498 }
499 
500 
502 {
504  return;
505 
506  int selected = m_modelsGrid->GetGridCursorRow();
507 
508  PROJECT& prj = Prj();
509  MODULE_3D_SETTINGS model;
510 
511  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
512  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
513  int filter = 0;
514 
515  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
516  // variable and fall back to the project path if necessary.
517  if( initialpath.IsEmpty() )
518  {
519  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
520  initialpath = prj.GetProjectPath();
521  }
522 
523  if( !sidx.empty() )
524  {
525  long tmp;
526  sidx.ToLong( &tmp );
527 
528  if( tmp > 0 && tmp <= INT_MAX )
529  filter = (int) tmp;
530  }
531 
532  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
533  || model.m_Filename.empty() )
534  {
535  select3DModel( selected );
536  return;
537  }
538 
539  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
540  sidx = wxString::Format( wxT( "%i" ), filter );
542  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
543  wxString alias;
544  wxString shortPath;
545  wxString filename = model.m_Filename;
546 
547  if( res && res->SplitAlias( filename, alias, shortPath ) )
548  filename = alias + wxT( ":" ) + shortPath;
549 
550 #ifdef __WINDOWS__
551  // In KiCad files, filenames and paths are stored using Unix notation
552  model.m_Filename.Replace( "\\", "/" );
553 #endif
554 
555  model.m_Show = true;
556  m_shapes3D_list.push_back( model );
557 
558  int idx = m_modelsGrid->GetNumberRows();
559  m_modelsGrid->AppendRows( 1 );
560  m_modelsGrid->SetCellValue( idx, 0, filename );
561  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
562 
563  select3DModel( idx );
565 }
566 
567 
569 {
571  return;
572 
573  MODULE_3D_SETTINGS model;
574 
575  model.m_Show = true;
576  m_shapes3D_list.push_back( model );
577 
578  int row = m_modelsGrid->GetNumberRows();
579  m_modelsGrid->AppendRows( 1 );
580  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
581 
582  select3DModel( row );
583 
584  m_modelsGrid->SetFocus();
585  m_modelsGrid->MakeCellVisible( row, 0 );
586  m_modelsGrid->SetGridCursor( row, 0 );
587 
588  m_modelsGrid->EnableCellEditControl( true );
589  m_modelsGrid->ShowCellEditControl();
590 }
591 
592 
594 {
596  return false;
597 
598  if( !DIALOG_SHIM::Validate() )
599  return false;
600 
601  // Check for empty texts.
602  for( size_t i = 2; i < m_texts->size(); ++i )
603  {
604  TEXTE_MODULE& text = m_texts->at( i );
605 
606  if( text.GetText().IsEmpty() )
607  {
608  if( m_NoteBook->GetSelection() != 0 )
609  m_NoteBook->SetSelection( 0 );
610 
612  m_delayedErrorMessage = _( "Text items must have some content." );
614  m_delayedFocusRow = i;
615 
616  return false;
617  }
618  }
619 
620  if( !m_netClearance.Validate( 0, INT_MAX ) )
621  return false;
622 
623  return true;
624 }
625 
626 
628 {
629  if( !Validate() )
630  return false;
631 
632  if( !DIALOG_SHIM::TransferDataFromWindow() )
633  return false;
634 
635  if( !m_PanelGeneral->TransferDataFromWindow() )
636  return false;
637 
638  if( !m_Panel3D->TransferDataFromWindow() )
639  return false;
640 
641  auto view = m_frame->GetCanvas()->GetView();
642  BOARD_COMMIT commit( m_frame );
643  commit.Modify( m_footprint );
644 
645  // copy reference and value
646  m_footprint->Reference() = m_texts->at( 0 );
647  m_footprint->Value() = m_texts->at( 1 );
648 
649  size_t i = 2;
650 
651  for( auto item : m_footprint->GraphicalItems() )
652  {
653  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
654 
655  if( textModule )
656  {
657  // copy grid table entries till we run out, then delete any remaining texts
658  if( i < m_texts->size() )
659  *textModule = m_texts->at( i++ );
660  else
661  textModule->DeleteStructure();
662  }
663  }
664 
665  // if there are still grid table entries, create new texts for them
666  while( i < m_texts->size() )
667  {
668  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
669  m_footprint->Add( newText, ADD_MODE::APPEND );
670  view->Add( newText );
671  }
672 
673  // Initialize masks clearances
677 
678  double dtmp = 0.0;
679  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
680  msg.ToDouble( &dtmp );
681 
682  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
683  if( dtmp < -50.0 )
684  dtmp = -50.0;
685  // A margin ratio is always <= 0
686  // 0 means use full pad copper area
687  if( dtmp > 0.0 )
688  dtmp = 0.0;
689 
691 
692  switch( m_ZoneConnectionChoice->GetSelection() )
693  {
694  default:
695  case 0:
697  break;
698  case 1:
700  break;
701  case 2:
703  break;
704  case 3:
706  break;
707  }
708 
709  // Set Module Position
710  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
711  m_footprint->SetPosition( modpos );
712  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
713  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
714 
715  switch( m_AttributsCtrl->GetSelection() )
716  {
717  case 0: m_footprint->SetAttributes( 0 ); break;
718  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
719  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
720  default: wxFAIL;
721  }
722 
725 
726  // Now, set orientation. Must be done after other changes because rotation changes field
727  // positions on board (so that relative positions are held constant)
728  m_OrientValidator.TransferFromWindow();
729 
730  int orient = KiROUND( m_OrientValue * 10.0 );
731 
732  if( m_footprint->GetOrientation() != orient )
734 
735  // Set component side, that also have effect on the fields positions on board
736  bool change_layer = false;
737  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
738  {
739  if( m_footprint->GetLayer() == B_Cu )
740  change_layer = true;
741  }
742  else if( m_footprint->GetLayer() == F_Cu )
743  change_layer = true;
744 
745  if( change_layer )
747 
748  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
749  draw3D->clear();
750  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
751 
753 
754  // This is a simple edit, we must create an undo entry
755  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
756  commit.Push( _( "Modify module properties" ) );
757 
758  SetReturnCode( PRM_EDITOR_EDIT_OK );
759  return true;
760 }
761 
762 
764 {
766  return;
767 
768  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
769  TEXTE_MODULE textMod( m_footprint );
770 
771  // Set active layer if legal; otherwise copy layer from previous text item
772  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
773  textMod.SetLayer( m_frame->GetActiveLayer() );
774  else
775  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
776 
777  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
778  textMod.SetTextThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
779  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
780  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
781  textMod.SetMirrored( IsBackLayer( textMod.GetLayer() ) );
782 
783  m_texts->push_back( textMod );
784 
785  // notify the grid
786  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
787  m_itemsGrid->ProcessTableMessage( msg );
788 
789  m_itemsGrid->SetFocus();
790  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
791  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
792 
793  m_itemsGrid->EnableCellEditControl( true );
794  m_itemsGrid->ShowCellEditControl();
795 }
796 
797 
799 {
800  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
801 
802  int curRow = m_itemsGrid->GetGridCursorRow();
803 
804  if( curRow < 0 )
805  return;
806  else if( curRow < 2 )
807  {
808  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
809  return;
810  }
811 
812  m_texts->erase( m_texts->begin() + curRow );
813 
814  // notify the grid
815  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
816  m_itemsGrid->ProcessTableMessage( msg );
817 
818  if( m_itemsGrid->GetNumberRows() > 0 )
819  {
820  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
821  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
822  }
823 }
824 
825 
827 {
828  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
830 }
831 
832 
834 {
835  // Account for scroll bars
836  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
837  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
838 
839  itemsWidth -= m_itemsGrid->GetRowLabelSize();
840 
841  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
842  itemsWidth -= m_itemsGrid->GetColSize( i );
843 
844  if( itemsWidth > 0 )
845  {
846  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
847  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
848  }
849 
850  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 );
851 }
852 
853 
855 {
856  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
857  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
858 
859  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
860  // even when the original validation was triggered from a killFocus event, and so
861  // that the corresponding notebook page can be shown in the background when triggered
862  // from an OK.
863  if( m_delayedFocusRow >= 0 )
864  {
865  // We will re-enter this routine if an error dialog is displayed, so make sure we
866  // zero out our member variables first.
867  wxGrid* grid = m_delayedFocusGrid;
868  int row = m_delayedFocusRow;
869  int col = m_delayedFocusColumn;
870  wxString msg = m_delayedErrorMessage;
871 
872  m_delayedFocusGrid = nullptr;
873  m_delayedFocusRow = -1;
875  m_delayedErrorMessage = wxEmptyString;
876 
877  if( !msg.IsEmpty() )
878  {
879  // Do not use DisplayErrorMessage(); it screws up window order on Mac
880  DisplayError( nullptr, msg );
881  }
882 
883  grid->SetFocus();
884  grid->MakeCellVisible( row, col );
885 
886  // Selecting the first grid item only makes sense for the
887  // items grid
888  if( !m_initialFocus || grid == m_itemsGrid )
889  {
890  grid->SetGridCursor( row, col );
891  grid->EnableCellEditControl( true );
892  grid->ShowCellEditControl();
893 
894  if( grid == m_itemsGrid && row == 0 && col == 0 )
895  {
896  auto referenceEditor = grid->GetCellEditor( 0, 0 );
897 
898  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
899  SelectReferenceNumber( textEntry );
900 
901  referenceEditor->DecRef();
902  }
903  }
904  m_initialFocus = false;
905  }
906 
907  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
908 }
909 
910 
911 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
912 {
913  adjustGridColumns( aEvent.GetSize().GetX());
914 
915  aEvent.Skip();
916 }
917 
918 
919 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnPageChange( wxNotebookEvent& aEvent )
920 {
921  int page = aEvent.GetSelection();
922 
923  // Shouldn't be necessary, but is on at least OSX
924  if( page >= 0 )
925  m_NoteBook->ChangeSelection( (unsigned) page );
926 
927 #ifdef __WXMAC__
928  // Work around an OSX bug where the wxGrid children don't get placed correctly until
929  // the first resize event
930  if( m_macHack[ page ] )
931  {
932  wxSize pageSize = m_NoteBook->GetPage( page )->GetSize();
933  pageSize.x -= 1;
934 
935  m_NoteBook->GetPage( page )->SetSize( pageSize );
936  m_macHack[ page ] = false;
937  }
938 #endif
939 }
940 
941 
943 {
945 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:187
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:553
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
int GetAttributes() const
Definition: class_module.h:255
double GetOrientation() const
Definition: class_module.h:211
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:552
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:474
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
PROJECT holds project specific data.
Definition: project.h:61
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:550
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:121
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:178
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:247
int GetLocalClearance(wxString *aSource=nullptr) const
Definition: class_module.h:230
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:68
bool m_Show
Include module in rendering.
Definition: class_module.h:97
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:215
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
const KIID_PATH & GetPath() const
Definition: class_module.h:224
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:59
DRAWINGS & GraphicalItems()
Definition: class_module.h:179
PCBNEW_SETTINGS * GetPcbNewSettings()
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:782
int GetLocalSolderMaskMargin() const
Definition: class_module.h:227
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
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:114
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:230
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:90
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
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:312
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
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:237
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:473
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
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:174
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: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:228
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:240
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:96
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:206
int GetPlacementCost180() const
Definition: class_module.h:549
EDA_UNITS m_units
Definition: dialog_shim.h:197
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:103
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:221
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:243
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:201
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
void OnPageChange(wxNotebookEvent &event) override
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 _(s)
Definition: 3d_actions.cpp:33
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:70
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:246
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString AsString() const
Definition: common.h:137
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:68
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:333
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:157
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, MODULE_3D_SETTINGS *aModel)
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:206
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
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 SetAttributes(int aAttributes)
Definition: class_module.h:256
int GetNumberRows() override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
std::vector< MODULE_3D_SETTINGS > m_shapes3D_list