KiCad PCB EDA Suite
dialog_footprint_properties.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-2020 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 <footprint.h>
32 #include <confirm.h>
34 #include <filename_resolver.h>
35 #include <pcb_edit_frame.h>
36 #include <pcbnew_settings.h>
37 #include <pgm_base.h>
38 #include <validators.h>
40 #include <widgets/text_ctrl_eval.h>
41 #include <widgets/wx_grid.h>
43 
46 
48 
49 
50 int DIALOG_FOOTPRINT_PROPERTIES::m_page = 0; // remember the last open page during session
51 
52 
54  FOOTPRINT* aFootprint ) :
56  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
57  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
58  m_orientValidator( 3, &m_orientValue ),
59  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits ),
60  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
61  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
62  m_initialFocus( true ),
63  m_inSelect( false )
64 {
65  m_frame = aParent;
66  m_footprint = aFootprint;
68 
69  // Configure display origin transforms
72 
73  for( size_t i = 0; i < m_NoteBook->GetPageCount(); ++i )
74  m_macHack.push_back( true );
75 
77 
78  m_delayedErrorMessage = wxEmptyString;
79  m_delayedFocusGrid = nullptr;
80  m_delayedFocusRow = -1;
82 
83  // Give an icon
84  wxIcon icon;
85  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
86  SetIcon( icon );
87 
88  // Give a bit more room for combobox editors
89  m_itemsGrid->SetDefaultRowSize( m_itemsGrid->GetDefaultRowSize() + 4 );
90  m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
91 
93  m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
94  m_modelsGrid->PushEventHandler( new GRID_TRICKS( m_modelsGrid ) );
95 
97 
98  // Show/hide text item columns according to the user's preference
100 
101  // Set up the 3D models grid
102  // Path selector
103  if( cfg->m_lastFootprint3dDir.IsEmpty() )
104  {
105  wxGetEnv( KICAD6_3DMODEL_DIR, &cfg->m_lastFootprint3dDir );
106  }
107 
108  wxGridCellAttr* attr = new wxGridCellAttr;
109  attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_modelsGrid, &cfg->m_lastFootprint3dDir,
110  "*.*", true, Prj().GetProjectPath() ) );
111  m_modelsGrid->SetColAttr( 0, attr );
112 
113  // Show checkbox
114  attr = new wxGridCellAttr;
115  attr->SetRenderer( new wxGridCellBoolRenderer() );
116  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
117  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
118  m_modelsGrid->SetColAttr( 1, attr );
119  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
120  m_modelsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
121 
122  m_orientValidator.SetRange( -360.0, 360.0 );
123  m_OrientValueCtrl->SetValidator( m_orientValidator );
125 
126  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
127 
129 
130  bLowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 );
131 
132  // Set font size for items showing long strings:
133  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
134  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
135 #if __WXMAC__
136  m_allow90Label->SetFont( infoFont );
137  m_allow180Label->SetFont( infoFont );
138 #endif
139  m_staticTextInfoCopper->SetFont( infoFont );
140  m_staticTextInfoPaste->SetFont( infoFont );
141 
142  m_libraryIDLabel->SetFont( infoFont );
143  m_tcLibraryID->SetFont( infoFont );
144 
145  infoFont.SetStyle( wxFONTSTYLE_ITALIC );
146  m_staticTextInfoValNeg->SetFont( infoFont );
147  m_staticTextInfoValPos->SetFont( infoFont );
148 
149  m_NoteBook->SetSelection( m_page );
150 
151  if( m_page == 0 )
152  {
154  m_delayedFocusRow = 0;
156  }
157  else if ( m_page == 1 )
159  else
160  {
162  m_delayedFocusRow = 0;
164  }
165 
166  m_sdbSizerStdButtonsOK->SetDefault();
167 
168  m_orientValue = 0;
169 
170  // Configure button logos
171  m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
172  m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
173  m_buttonAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
176 
178 }
179 
180 
182 {
184  m_itemsGrid->GetShownColumns().ToStdString();
185 
186  // Prevents crash bug in wxGrid's d'tor
188 
189  // Delete the GRID_TRICKS.
190  m_itemsGrid->PopEventHandler( true );
191  m_modelsGrid->PopEventHandler( true );
192 
193  // free the memory used by all models, otherwise models which were
194  // browsed but not used would consume memory
195  Prj().Get3DCacheManager()->FlushCache( false );
196 
197  // the GL canvas has to be visible before it is destroyed
198  m_page = m_NoteBook->GetSelection();
199  m_NoteBook->SetSelection( 1 );
200 
201  delete m_previewPane;
202 }
203 
204 
206 {
207  if( TransferDataFromWindow() )
208  {
210  Close();
211  }
212 }
213 
214 
216 {
217  if( TransferDataFromWindow() )
218  {
220  Close();
221  }
222 }
223 
224 
226 {
227  if( TransferDataFromWindow() )
228  {
230  Close();
231  }
232 }
233 
234 
236 {
237  if( TransferDataFromWindow() )
238  {
240  Close();
241  }
242 }
243 
244 
246 {
247  if( m_Orient0->GetValue() )
248  m_orientValue = 0.0;
249  else if( m_Orient90->GetValue() )
250  m_orientValue = 90.0;
251  else if( m_Orient270->GetValue() )
252  m_orientValue = 270.0;
253  else if( m_Orient180->GetValue() )
254  m_orientValue = 180.0;
255 
257 }
258 
259 
261 {
262  m_OrientOther->SetValue( true );
263 
264  aEvent.Skip();
265 }
266 
267 
268 bool allPadsLocked( FOOTPRINT* aFootprint )
269 {
270  for( PAD* pad : aFootprint->Pads() )
271  {
272  if( !pad->IsLocked() )
273  return false;
274  }
275 
276  return true;
277 }
278 
279 
281 {
282  if( !wxDialog::TransferDataToWindow() )
283  return false;
284 
285  if( !m_PanelGeneral->TransferDataToWindow() )
286  return false;
287 
288  if( !m_Panel3D->TransferDataToWindow() )
289  return false;
290 
291  // Footprint Texts
292 
293  m_texts->push_back( m_footprint->Reference() );
294  m_texts->push_back( m_footprint->Value() );
295 
296  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
297  {
298  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
299 
300  if( textItem )
301  m_texts->push_back( *textItem );
302  }
303 
304  // notify the grid
305  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
306  m_itemsGrid->ProcessTableMessage( tmsg );
307 
308  // Footprint Properties
309 
312 
313  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
314 
316 
317  if( m_orientValue == 0.0 )
318  m_Orient0->SetValue( true );
319  else if( m_orientValue == 90.0 || m_orientValue == -270.0 )
320  m_Orient90->SetValue( true );
321  else if( m_orientValue == 270.0 || m_orientValue == -90.0 )
322  m_Orient270->SetValue( true );
323  else if( m_orientValue == 180.0 || m_orientValue == -180.0 )
324  m_Orient180->SetValue( true );
325  else
326  m_OrientOther->SetValue( true );
327 
329 
330  m_AutoPlaceCtrl->SetSelection( m_footprint->IsLocked() ? 1 : 0 );
331 
332  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Footprint can be freely moved and oriented on the "
333  "canvas." ) );
334  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Footprint is locked: it cannot be freely moved and "
335  "oriented on the canvas and can only be selected when "
336  "the 'Locked items' checkbox is enabled in the "
337  "selection filter." ) );
338 
341 
343  m_componentType->SetSelection( 0 );
344  else if( m_footprint->GetAttributes() & FP_SMD )
345  m_componentType->SetSelection( 1 );
346  else
347  m_componentType->SetSelection( 2 );
348 
352 
353  // Local Clearances
354 
358 
359  // Prefer "-0" to "0" for normally negative values
361  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
362 
363  // Add solder paste margin ratio in percent
364  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
365  wxString msg;
366  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
367 
369  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
370  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
371  else
373 
374  switch( m_footprint->GetZoneConnection() )
375  {
376  default:
377  case ZONE_CONNECTION::INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
378  case ZONE_CONNECTION::FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
379  case ZONE_CONNECTION::THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
380  case ZONE_CONNECTION::NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
381  }
382 
383  // 3D Settings
384  m_shapes3D_list.clear();
385  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
386 
387  wxString origPath, alias, shortPath;
388  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
389 
390  for( const FP_3DMODEL& model : m_footprint->Models() )
391  {
392  m_shapes3D_list.push_back( model );
393  origPath = model.m_Filename;
394 
395  if( res && res->SplitAlias( origPath, alias, shortPath ) )
396  origPath = alias + wxT( ":" ) + shortPath;
397 
398  m_modelsGrid->AppendRows( 1 );
399  int row = m_modelsGrid->GetNumberRows() - 1;
400  m_modelsGrid->SetCellValue( row, 0, origPath );
401  m_modelsGrid->SetCellValue( row, 1, model.m_Show ? wxT( "1" ) : wxT( "0" ) );
402  }
403 
404  select3DModel( 0 ); // will clamp idx within bounds
406 
407  // Show the footprint's FPID.
408  m_tcLibraryID->SetValue( m_footprint->GetFPID().Format() );
409 
410  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
411  {
412  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
413  false ) );
414  // Adjust the column size.
415  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
416 
417  if( col == FPT_LAYER ) // This one's a drop-down. Check all possible values.
418  {
419  BOARD* board = m_footprint->GetBoard();
420 
421  for( PCB_LAYER_ID layer : board->GetEnabledLayers().Seq() )
422  col_size = std::max( col_size, GetTextExtent( board->GetLayerName( layer ) ).x );
423 
424  // And the swatch:
425  col_size += 20;
426  }
427 
428  if( m_itemsGrid->IsColShown( col ) )
429  m_itemsGrid->SetColSize( col, col_size );
430  }
431 
432  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
433  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
434 
435  Layout();
436  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
437 
438  return true;
439 }
440 
441 
443 {
444  m_inSelect = true;
445 
446  aModelIdx = std::max( 0, aModelIdx );
447  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
448 
449  if( m_modelsGrid->GetNumberRows() )
450  {
451  m_modelsGrid->SelectRow( aModelIdx );
452  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
453  }
454 
455  m_previewPane->SetSelectedModel( aModelIdx );
456 
457  m_inSelect = false;
458 }
459 
460 
462 {
463  if( !m_inSelect )
464  select3DModel( aEvent.GetRow() );
465 }
466 
467 
469 {
470  if( aEvent.GetCol() == 0 )
471  {
472  bool hasAlias = false;
473  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
474  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
475 
476  filename.Replace( "\n", "" );
477  filename.Replace( "\r", "" );
478  filename.Replace( "\t", "" );
479 
480  if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) )
481  {
482  m_delayedErrorMessage = wxString::Format( _( "Invalid filename: %s" ), filename );
484  m_delayedFocusRow = aEvent.GetRow();
485  m_delayedFocusColumn = aEvent.GetCol();
486  aEvent.Veto();
487  }
488 
489  // if the user has specified an alias in the name then prepend ':'
490  if( hasAlias )
491  filename.insert( 0, wxT( ":" ) );
492 
493 #ifdef __WINDOWS__
494  // In Kicad files, filenames and paths are stored using Unix notation
495  filename.Replace( wxT( "\\" ), wxT( "/" ) );
496 #endif
497 
498  m_shapes3D_list[ aEvent.GetRow() ].m_Filename = filename;
499  m_modelsGrid->SetCellValue( aEvent.GetRow(), 0, filename );
500  }
501  else if( aEvent.GetCol() == 1 )
502  {
503  wxString showValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
504 
505  m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT( "1" ) );
506  }
507 
509 }
510 
511 
513 {
514  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
515 
516  int idx = m_modelsGrid->GetGridCursorRow();
517 
518  if( idx >= 0 && m_modelsGrid->GetNumberRows() && !m_shapes3D_list.empty() )
519  {
520  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
521  m_modelsGrid->DeleteRows( idx, 1 );
522 
523  select3DModel( idx ); // will clamp idx within bounds
525  }
526 }
527 
528 
530 {
532  return;
533 
534  int selected = m_modelsGrid->GetGridCursorRow();
535 
536  PROJECT& prj = Prj();
537  FP_3DMODEL model;
538 
539  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
540  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
541  int filter = 0;
542 
543  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KICAD6_3DMODEL_DIR environment
544  // variable and fall back to the project path if necessary.
545  if( initialpath.IsEmpty() )
546  {
547  if( !wxGetEnv( "KICAD6_3DMODEL_DIR", &initialpath ) || initialpath.IsEmpty() )
548  initialpath = prj.GetProjectPath();
549  }
550 
551  if( !sidx.empty() )
552  {
553  long tmp;
554  sidx.ToLong( &tmp );
555 
556  if( tmp > 0 && tmp <= INT_MAX )
557  filter = (int) tmp;
558  }
559 
560  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
561  || model.m_Filename.empty() )
562  {
563  select3DModel( selected );
564  return;
565  }
566 
567  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
568  sidx = wxString::Format( wxT( "%i" ), filter );
570  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
571  wxString alias;
572  wxString shortPath;
573  wxString filename = model.m_Filename;
574 
575  if( res && res->SplitAlias( filename, alias, shortPath ) )
576  filename = alias + wxT( ":" ) + shortPath;
577 
578 #ifdef __WINDOWS__
579  // In KiCad files, filenames and paths are stored using Unix notation
580  model.m_Filename.Replace( "\\", "/" );
581 #endif
582 
583  model.m_Show = true;
584  m_shapes3D_list.push_back( model );
585 
586  int idx = m_modelsGrid->GetNumberRows();
587  m_modelsGrid->AppendRows( 1 );
588  m_modelsGrid->SetCellValue( idx, 0, filename );
589  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
590 
591  select3DModel( idx );
593 }
594 
595 
597 {
599  return;
600 
601  FP_3DMODEL model;
602 
603  model.m_Show = true;
604  m_shapes3D_list.push_back( model );
605 
606  int row = m_modelsGrid->GetNumberRows();
607  m_modelsGrid->AppendRows( 1 );
608  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
609 
610  select3DModel( row );
611 
612  m_modelsGrid->SetFocus();
613  m_modelsGrid->MakeCellVisible( row, 0 );
614  m_modelsGrid->SetGridCursor( row, 0 );
615 
616  m_modelsGrid->EnableCellEditControl( true );
617  m_modelsGrid->ShowCellEditControl();
618 }
619 
620 
622 {
624  return false;
625 
626  if( !DIALOG_SHIM::Validate() )
627  return false;
628 
629  // Check for empty texts.
630  for( size_t i = 2; i < m_texts->size(); ++i )
631  {
632  FP_TEXT& text = m_texts->at( i );
633 
634  if( text.GetText().IsEmpty() )
635  {
636  if( m_NoteBook->GetSelection() != 0 )
637  m_NoteBook->SetSelection( 0 );
638 
640  m_delayedErrorMessage = _( "Text items must have some content." );
642  m_delayedFocusRow = i;
643 
644  return false;
645  }
646  }
647 
648  if( !m_netClearance.Validate( 0, INT_MAX ) )
649  return false;
650 
651  return true;
652 }
653 
654 
656 {
657  if( !Validate() )
658  return false;
659 
661  return false;
662 
664  return false;
665 
666  auto view = m_frame->GetCanvas()->GetView();
667  BOARD_COMMIT commit( m_frame );
668  commit.Modify( m_footprint );
669 
670  // copy reference and value
671  m_footprint->Reference() = m_texts->at( 0 );
672  m_footprint->Value() = m_texts->at( 1 );
673 
674  size_t i = 2;
675 
676  for( BOARD_ITEM* item : m_footprint->GraphicalItems() )
677  {
678  FP_TEXT* textItem = dyn_cast<FP_TEXT*>( item );
679 
680  if( textItem )
681  {
682  // copy grid table entries till we run out, then delete any remaining texts
683  if( i < m_texts->size() )
684  *textItem = m_texts->at( i++ );
685  else
686  textItem->DeleteStructure();
687  }
688  }
689 
690  // if there are still grid table entries, create new texts for them
691  while( i < m_texts->size() )
692  {
693  auto newText = new FP_TEXT( m_texts->at( i++ ) );
694  m_footprint->Add( newText, ADD_MODE::APPEND );
695  view->Add( newText );
696  }
697 
698  // Initialize masks clearances
702 
703  double dtmp = 0.0;
704  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
705  msg.ToDouble( &dtmp );
706 
707  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
708  if( dtmp < -50.0 )
709  dtmp = -50.0;
710  // A margin ratio is always <= 0
711  // 0 means use full pad copper area
712  if( dtmp > 0.0 )
713  dtmp = 0.0;
714 
716 
717  switch( m_ZoneConnectionChoice->GetSelection() )
718  {
719  default:
724  }
725 
726  // Set Footprint Position
727  wxPoint pos( m_posX.GetValue(), m_posY.GetValue() );
728  m_footprint->SetPosition( pos );
729  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
730 
731  int attributes = 0;
732 
733  switch( m_componentType->GetSelection() )
734  {
735  case 0: attributes |= FP_THROUGH_HOLE; break;
736  case 1: attributes |= FP_SMD; break;
737  default: break;
738  }
739 
740  if( m_boardOnly->GetValue() )
741  attributes |= FP_BOARD_ONLY;
742 
743  if( m_excludeFromPosFiles->GetValue() )
744  attributes |= FP_EXCLUDE_FROM_POS_FILES;
745 
746  if( m_excludeFromBOM->GetValue() )
747  attributes |= FP_EXCLUDE_FROM_BOM;
748 
749  m_footprint->SetAttributes( attributes );
750 
753 
754  // Now, set orientation. Must be done after other changes because rotation changes field
755  // positions on board (so that relative positions are held constant)
756  m_orientValidator.TransferFromWindow();
757 
758  double orient = m_orientValue * 10;
759 
760  if( m_footprint->GetOrientation() != orient )
762 
763  // Set component side, that also have effect on the fields positions on board
764  bool change_layer = false;
765  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
766  {
767  if( m_footprint->GetLayer() == B_Cu )
768  change_layer = true;
769  }
770  else if( m_footprint->GetLayer() == F_Cu )
771  change_layer = true;
772 
773  if( change_layer )
775 
776  std::list<FP_3DMODEL>* draw3D = &m_footprint->Models();
777  draw3D->clear();
778  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
779 
780  // This is a simple edit, we must create an undo entry
781  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
782  commit.Push( _( "Modify footprint properties" ) );
783 
785  return true;
786 }
787 
788 
790 {
792  return;
793 
794  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
795  FP_TEXT textItem( m_footprint );
796 
797  // Set active layer if legal; otherwise copy layer from previous text item
799  textItem.SetLayer( m_frame->GetActiveLayer() );
800  else
801  textItem.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
802 
803  textItem.SetTextSize( dsnSettings.GetTextSize( textItem.GetLayer() ) );
804  textItem.SetTextThickness( dsnSettings.GetTextThickness( textItem.GetLayer() ) );
805  textItem.SetItalic( dsnSettings.GetTextItalic( textItem.GetLayer() ) );
806  textItem.SetKeepUpright( dsnSettings.GetTextUpright( textItem.GetLayer() ) );
807  textItem.SetMirrored( IsBackLayer( textItem.GetLayer() ) );
808 
809  m_texts->push_back( textItem );
810 
811  // notify the grid
812  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
813  m_itemsGrid->ProcessTableMessage( msg );
814 
815  m_itemsGrid->SetFocus();
816  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
817  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
818 
819  m_itemsGrid->EnableCellEditControl( true );
820  m_itemsGrid->ShowCellEditControl();
821 }
822 
823 
825 {
826  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
827 
828  int curRow = m_itemsGrid->GetGridCursorRow();
829 
830  if( curRow < 0 )
831  return;
832  else if( curRow < 2 )
833  {
834  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
835  return;
836  }
837 
838  m_texts->erase( m_texts->begin() + curRow );
839 
840  // notify the grid
841  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
842  m_itemsGrid->ProcessTableMessage( msg );
843 
844  if( m_itemsGrid->GetNumberRows() > 0 )
845  {
846  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
847  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
848  }
849 }
850 
851 
853 {
854  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
856 }
857 
858 
860 {
861  // Account for scroll bars
862  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
863  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
864 
865  itemsWidth -= m_itemsGrid->GetRowLabelSize();
866 
867  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
868  itemsWidth -= m_itemsGrid->GetColSize( i );
869 
870  if( itemsWidth > 0 )
871  {
872  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
873  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
874  }
875 
876  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 6 );
877 }
878 
879 
881 {
882  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
883  adjustGridColumns( m_itemsGrid->GetRect().GetWidth() );
884 
885  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
886  // even when the original validation was triggered from a killFocus event, and so
887  // that the corresponding notebook page can be shown in the background when triggered
888  // from an OK.
889  if( m_delayedFocusRow >= 0 )
890  {
891  // We will re-enter this routine if an error dialog is displayed, so make sure we
892  // zero out our member variables first.
893  wxGrid* grid = m_delayedFocusGrid;
894  int row = m_delayedFocusRow;
895  int col = m_delayedFocusColumn;
896  wxString msg = m_delayedErrorMessage;
897 
898  m_delayedFocusGrid = nullptr;
899  m_delayedFocusRow = -1;
901  m_delayedErrorMessage = wxEmptyString;
902 
903  if( !msg.IsEmpty() )
904  {
905  // Do not use DisplayErrorMessage(); it screws up window order on Mac
906  DisplayError( nullptr, msg );
907  }
908 
909  grid->SetFocus();
910  grid->MakeCellVisible( row, col );
911 
912  // Selecting the first grid item only makes sense for the
913  // items grid
914  if( !m_initialFocus || grid == m_itemsGrid )
915  {
916  grid->SetGridCursor( row, col );
917  grid->EnableCellEditControl( true );
918  grid->ShowCellEditControl();
919 
920  if( grid == m_itemsGrid && row == 0 && col == 0 )
921  {
922  auto referenceEditor = grid->GetCellEditor( 0, 0 );
923 
924  if( auto textEntry = dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) )
925  KIUI::SelectReferenceNumber( textEntry );
926 
927  referenceEditor->DecRef();
928  }
929  }
930  m_initialFocus = false;
931  }
932 
933  m_buttonRemove->Enable( m_modelsGrid->GetNumberRows() > 0 );
934 }
935 
936 
937 void DIALOG_FOOTPRINT_PROPERTIES::OnGridSize( wxSizeEvent& aEvent )
938 {
939  adjustGridColumns( aEvent.GetSize().GetX() );
940 
941  aEvent.Skip();
942 }
943 
944 
945 void DIALOG_FOOTPRINT_PROPERTIES::OnPageChange( wxNotebookEvent& aEvent )
946 {
947  int page = aEvent.GetSelection();
948 
949  // Shouldn't be necessary, but is on at least OSX
950  if( page >= 0 )
951  m_NoteBook->ChangeSelection( (unsigned) page );
952 
953 #ifdef __WXMAC__
954  // Work around an OSX bug where the wxGrid children don't get placed correctly until
955  // the first resize event
956  if( m_macHack[ page ] )
957  {
958  wxSize pageSize = m_NoteBook->GetPage( page )->GetSize();
959  pageSize.x -= 1;
960 
961  m_NoteBook->GetPage( page )->SetSize( pageSize );
962  m_macHack[ page ] = false;
963  }
964 #endif
965 }
966 
967 
969 {
971 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
void SetSelectedModel(int idx)
Set the currently selected index in the model list so that the scale/rotation/offset controls can be ...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
bool IsLocked() const override
Definition: footprint.h:277
void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
Definition: ui_common.cpp:103
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
Container for project specific data.
Definition: project.h:62
std::list< FP_3DMODEL > & Models()
Definition: footprint.h:173
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:360
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: footprint.h:217
#define KICAD6_3DMODEL_DIR
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void OnAddField(wxCommandEvent &) override
void UpdateDummyFootprint(bool aRelaodRequired=true)
Copy shapes from the current shape list which are flagged for preview to the copy of footprint that i...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
int GetPlacementCost180() const
Definition: footprint.h:529
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:129
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:376
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
int GetNumberRows() override
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:186
void OnUpdateUI(wxUpdateUIEvent &) override
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath) const
Return true if the given name contains an alias and populates the string anAlias with the alias and a...
bool Select3DModel(wxWindow *aParent, S3D_CACHE *aCache, wxString &prevModelSelectDir, int &prevModelWildcard, FP_3DMODEL *aModel)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:52
double GetOrientation() const
Definition: footprint.h:181
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:117
void On3DModelSelected(wxGridEvent &) override
Class DIALOG_FOOTPRINT_PROPERTIES_BASE.
void OnAdd3DModel(wxCommandEvent &) override
void FootprintOrientEvent(wxCommandEvent &) override
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: footprint.h:215
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:465
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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:65
wxString m_FootprintTextShownColumns
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
void OnDeleteField(wxCommandEvent &) override
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
void SetAttributes(int aAttributes)
Definition: footprint.h:227
PADS & Pads()
Definition: footprint.h:159
void SetPlacementCost180(int aCost)
Definition: footprint.h:530
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:238
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:457
bool ValidateFileName(const wxString &aFileName, bool &hasAlias) const
Returns true if the given path is a valid aliased relative path.
bool GetTextUpright(PCB_LAYER_ID aLayer) const
FP_TEXT & Reference()
Definition: footprint.h:458
void EditLibraryFootprint(wxCommandEvent &) override
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:97
bool GetTextItalic(PCB_LAYER_ID aLayer) const
virtual PCB_LAYER_ID GetActiveLayer() const
wxString m_lastFootprint3dDir
bool m_Show
Include model in rendering.
Definition: footprint.h:98
PCB_LAYER_ID
A quick note on layer IDs:
PANEL_PREVIEW_3D_MODEL * m_previewPane
pads are covered by copper
void Cfg3DPath(wxCommandEvent &) override
void OnOtherOrientation(wxCommandEvent &aEvent) override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxFloatingPointValidator< double > m_orientValidator
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1381
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:50
void SetLocalClearance(int aClearance)
Definition: footprint.h:201
int GetLocalClearance() const
Definition: footprint.h:200
#define _(s)
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
const LIB_ID & GetFPID() const
Definition: footprint.h:185
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
Definition: footprint.cpp:1356
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
UTF8 Format() const
Definition: lib_id.cpp:233
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
Definition: project.cpp:213
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString m_Filename
The 3D shape filename in 3D library.
Definition: footprint.h:97
EDA_UNITS m_units
Definition: dialog_shim.h:198
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Use thermal relief for pads.
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:110
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:115
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Definition: project.cpp:228
int GetLocalSolderMaskMargin() const
Definition: footprint.h:197
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
see class PGM_BASE
Provide an extensible class to resolve 3D model paths.
Declaration of the eda_3d_viewer class.
int GetAttributes() const
Definition: footprint.h:226
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
std::vector< FP_3DMODEL > m_shapes3D_list
void OnRemove3DModel(wxCommandEvent &) override
void SetLocked(bool isLocked) override
Set the #MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: footprint.h:287
The main frame for Pcbnew.
PCBNEW_SETTINGS & Settings()
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
Pads are not covered.
wxPoint GetPosition() const override
Definition: footprint.h:177
double GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:214
virtual long long int GetValue()
Return the current value in Internal Units.
DIALOG_FOOTPRINT_PROPERTIES(PCB_EDIT_FRAME *aParent, FOOTPRINT *aFootprint)
void OnAdd3DRow(wxCommandEvent &) override
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
ZONE_CONNECTION GetZoneConnection() const
Definition: footprint.h:218
int GetPlacementCost90() const
Definition: footprint.h:532
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:173
void UpdateFootprint(wxCommandEvent &) override
int GetLocalSolderPasteMargin() const
Definition: footprint.h:211
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:472
Definition: pad.h:57
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1452
bool allPadsLocked(FOOTPRINT *aFootprint)
void OnPageChange(wxNotebookEvent &event) override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
void On3DModelCellChanged(wxGridEvent &aEvent) override
void updateOrientationControl()
Update the orientation validated control, without triggering a change event on the control (which wou...
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
void SetPlacementCost90(int aCost)
Definition: footprint.h:533
void EditFootprint(wxCommandEvent &) override
void SetLocalSolderMaskMargin(int aMargin)
Definition: footprint.h:198
void ChangeFootprint(wxCommandEvent &) override
void OnGridSize(wxSizeEvent &aEvent) override
Container for design settings for a BOARD object.
void SetLocalSolderPasteMargin(int aMargin)
Definition: footprint.h:212