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 
28 #include <fctsys.h>
29 #include <kiface_i.h>
30 #include <view/view.h>
31 #include <gr_basic.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <pcbnew.h>
35 #include <pgm_base.h>
36 #include <pcb_edit_frame.h>
37 #include <board_commit.h>
38 #include <board_design_settings.h>
39 #include <dialog_text_entry.h>
40 #include <class_module.h>
41 #include <validators.h>
42 #include <widgets/wx_grid.h>
43 #include <widgets/text_ctrl_eval.h>
44 #include <filename_resolver.h>
47 #include <bitmaps.h>
48 #include <3d_viewer.h>
49 
51 
52 
53 #define FootprintTextShownColumnsKey wxT( "FootprintTextShownColumns" )
54 
55 int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
56 
57 
59  MODULE* aModule, wxDC* aDC ) :
61  m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
62  m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
63  m_OrientValidator( 1, &m_OrientValue ),
64  m_netClearance( aParent, m_NetClearanceLabel, m_NetClearanceCtrl, m_NetClearanceUnits, false, 0 ),
65  m_solderMask( aParent, m_SolderMaskMarginLabel, m_SolderMaskMarginCtrl, m_SolderMaskMarginUnits ),
66  m_solderPaste( aParent, m_SolderPasteMarginLabel, m_SolderPasteMarginCtrl, m_SolderPasteMarginUnits ),
67  m_initialFocus( true ),
68  m_inSelect( false )
69 {
71 
72  m_frame = aParent;
73  m_DC = aDC;
74  m_footprint = aModule;
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( icon_modedit_xpm ) );
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 
96  // Show/hide text item columns according to the user's preference
97  wxString shownColumns;
98  m_config->Read( FootprintTextShownColumnsKey, &shownColumns, wxT( "0 1 2 3 4 5 6" ) );
99  m_itemsGrid->ShowHideColumns( shownColumns );
100 
101  // Set up the 3D models grid
102  wxGridCellAttr* attr = new wxGridCellAttr;
103  attr->SetRenderer( new wxGridCellBoolRenderer() );
104  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
105  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
106  m_modelsGrid->SetColAttr( 1, attr );
107  m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
108 
109  m_OrientValidator.SetRange( -360.0, 360.0 );
110  m_OrientValueCtrl->SetValidator( m_OrientValidator );
112 
113  aParent->Prj().Get3DCacheManager()->GetResolver()->SetProgramBase( &Pgm() );
114 
116 
117  bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
118 
119  // Set font sizes
120  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
121  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
122  m_allow90Label->SetFont( infoFont );
123  m_allow180Label->SetFont( infoFont );
124  m_libraryIDLabel->SetFont( infoFont );
125  m_staticLibraryID->SetFont( infoFont );
126  m_staticTextInfoValNeg->SetFont( infoFont );
127  m_staticTextInfoValPos->SetFont( infoFont );
128  m_staticTextInfoCopper->SetFont( infoFont );
129 
130  m_NoteBook->SetSelection( m_page );
131 
132  if( m_page == 0 )
133  {
135  m_delayedFocusRow = 0;
137  }
138  else if ( m_page == 1 )
140  else
141  {
143  m_delayedFocusRow = 0;
145  }
146 
147  m_sdbSizerStdButtonsOK->SetDefault();
148 
149  m_OrientValue = 0;
150 
151  // Configure button logos
152  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
153  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
154  m_buttonAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
155  m_buttonBrowse->SetBitmap( KiBitmap( folder_xpm ) );
156  m_buttonRemove->SetBitmap( KiBitmap( trash_xpm ) );
157 
159 }
160 
161 
163 {
165 
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 {
187  if( m_footprint->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
188  {
190  m_frame->OnModify();
191  }
192 
194 }
195 
196 
198 {
200 }
201 
202 
204 {
205  EndModal( PRM_EDITOR_WANT_UPDATE_FP );
206 }
207 
208 
210 {
211  EndModal( PRM_EDITOR_WANT_EXCHANGE_FP );
212 }
213 
214 
216 {
217  if( m_Orient0->GetValue() )
218  m_OrientValue = 0.0;
219  else if( m_Orient90->GetValue() )
220  m_OrientValue = 90.0;
221  else if( m_Orient270->GetValue() )
222  m_OrientValue = 270.0;
223  else if( m_Orient180->GetValue() )
224  m_OrientValue = 180.0;
225 
227 }
228 
229 
231 {
232  m_OrientOther->SetValue( true );
233 
234  aEvent.Skip();
235 }
236 
237 
239 {
240  if( !wxDialog::TransferDataToWindow() )
241  return false;
242 
243  if( !m_PanelGeneral->TransferDataToWindow() )
244  return false;
245 
246  if( !m_Panel3D->TransferDataToWindow() )
247  return false;
248 
249  // Module Texts
250 
251  m_texts->push_back( m_footprint->Reference() );
252  m_texts->push_back( m_footprint->Value() );
253 
254  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = item->Next() )
255  {
256  auto textModule = dyn_cast<TEXTE_MODULE*>( item );
257 
258  if( textModule )
259  m_texts->push_back( *textModule );
260  }
261 
262  // notify the grid
263  wxGridTableMessage tmsg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_texts->GetNumberRows() );
264  m_itemsGrid->ProcessTableMessage( tmsg );
265 
266  // Module Properties
267 
270 
272 
273  if( m_OrientValue == 0.0 )
274  m_Orient0->SetValue( true );
275  else if( m_OrientValue == 90.0 || m_OrientValue == -270.0 )
276  m_Orient90->SetValue( true );
277  else if( m_OrientValue == 270.0 || m_OrientValue == -90.0 )
278  m_Orient270->SetValue( true );
279  else if( m_OrientValue == 180.0 || m_OrientValue == -180.0 )
280  m_Orient180->SetValue( true );
281  else
282  m_OrientOther->SetValue( true );
283 
285 
286  m_BoardSideCtrl->SetSelection( (m_footprint->GetLayer() == B_Cu) ? 1 : 0 );
287 
288  if( m_footprint->IsLocked() )
289  m_AutoPlaceCtrl->SetSelection( 2 );
290  else if( m_footprint->PadsLocked() )
291  m_AutoPlaceCtrl->SetSelection( 1 );
292  else
293  m_AutoPlaceCtrl->SetSelection( 0 );
294 
295  m_AutoPlaceCtrl->SetItemToolTip( 0, _( "Component can be freely moved and auto placed. User "
296  "can arbitrarily select and edit component's pads." ) );
297  m_AutoPlaceCtrl->SetItemToolTip( 1, _( "Component can be freely moved and auto placed, but "
298  "its pads cannot be selected or edited." ) );
299  m_AutoPlaceCtrl->SetItemToolTip( 2, _( "Component is locked: it cannot be freely moved or "
300  "auto placed." ) );
301 
304 
305  m_AttributsCtrl->SetItemToolTip( 0, _( "Use this attribute for most non SMD footprints\n"
306  "Footprints with this option are not put in the footprint position list file" ) );
307  m_AttributsCtrl->SetItemToolTip( 1, _( "Use this attribute for SMD footprints.\n"
308  "Only footprints with this option are put in the footprint position list file" ) );
309  m_AttributsCtrl->SetItemToolTip( 2, _( "Use this attribute for \"virtual\" footprints drawn "
310  "on board\nsuch as an edge connector (old ISA PC bus for instance)" ) );
311 
312  switch( m_footprint->GetAttributes() & 255 )
313  {
314  case MOD_CMS: m_AttributsCtrl->SetSelection( 1 ); break;
315  case MOD_VIRTUAL: m_AttributsCtrl->SetSelection( 2 ); break;
316  case 0:
317  default: m_AttributsCtrl->SetSelection( 0 ); break;
318  }
319 
320  // Local Clearances
321 
325 
326  // Prefer "-0" to "0" for normally negative values
328  m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
329 
330  // Add solder paste margin ratio in percent
331  // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
332  wxString msg;
333  msg.Printf( wxT( "%f" ), m_footprint->GetLocalSolderPasteMarginRatio() * 100.0 );
334 
336  msg[0] == '0') // Sometimes Printf adds a sign if the value is very small (0.0)
337  m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
338  else
340 
341  switch( m_footprint->GetZoneConnection() )
342  {
343  default:
344  case PAD_ZONE_CONN_INHERITED: m_ZoneConnectionChoice->SetSelection( 0 ); break;
345  case PAD_ZONE_CONN_FULL: m_ZoneConnectionChoice->SetSelection( 1 ); break;
346  case PAD_ZONE_CONN_THERMAL: m_ZoneConnectionChoice->SetSelection( 2 ); break;
347  case PAD_ZONE_CONN_NONE: m_ZoneConnectionChoice->SetSelection( 3 ); break;
348  }
349 
350  // 3D Settings
351 
352  wxString default_path;
353  wxGetEnv( KISYS3DMOD, &default_path );
354 #ifdef __WINDOWS__
355  default_path.Replace( wxT( "/" ), wxT( "\\" ) );
356 #endif
357 
358  m_shapes3D_list.clear();
359  m_modelsGrid->DeleteRows( 0, m_modelsGrid->GetNumberRows() );
360 
361  wxString origPath, alias, shortPath;
362  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
363 
364  for( MODULE_3D_SETTINGS model : m_footprint->Models() )
365  {
366  m_shapes3D_list.push_back( model );
367  origPath = model.m_Filename;
368 
369  if( res && res->SplitAlias( origPath, alias, shortPath ) )
370  origPath = alias + wxT( ":" ) + shortPath;
371 
372  m_modelsGrid->AppendRows( 1 );
373  int row = m_modelsGrid->GetNumberRows() - 1;
374  m_modelsGrid->SetCellValue( row, 0, origPath );
375  m_modelsGrid->SetCellValue( row, 1, model.m_Preview ? wxT( "1" ) : wxT( "0" ) );
376  }
377 
378  select3DModel( 0 ); // will clamp idx within bounds
380 
381  // Show the footprint's ID.
382  m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
383 
384  for( int col = 0; col < m_itemsGrid->GetNumberCols(); col++ )
385  {
386  m_itemsGrid->SetColMinimalWidth( col, m_itemsGrid->GetVisibleWidth( col, true, false,
387  false ) );
388  // Adjust the column size. The column 6 has a small bitmap, so its width must be
389  // taken in account
390  int col_size = m_itemsGrid->GetVisibleWidth( col, true, true, false );
391 
392  if( col == 6 )
393  col_size += 20;
394 
395  if( m_itemsGrid->IsColShown( col ) )
396  m_itemsGrid->SetColSize( col, col_size );
397  }
398 
399  m_itemsGrid->SetRowLabelSize( m_itemsGrid->GetVisibleWidth( -1, false, true, true ) );
400  m_modelsGrid->SetColSize( 1, m_modelsGrid->GetVisibleWidth( 1, true, false, false ) );
401 
402  Layout();
403  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
404 
405  return true;
406 }
407 
408 
410 {
411  m_inSelect = true;
412 
413  aModelIdx = std::max( 0, aModelIdx );
414  aModelIdx = std::min( aModelIdx, m_modelsGrid->GetNumberRows() - 1 );
415 
416  if( m_modelsGrid->GetNumberRows() )
417  {
418  m_modelsGrid->SelectRow( aModelIdx );
419  m_modelsGrid->SetGridCursor( aModelIdx, 0 );
420  }
421 
422  m_PreviewPane->SetSelectedModel( aModelIdx );
423 
424  m_inSelect = false;
425 }
426 
427 
429 {
430  if( !m_inSelect )
431  select3DModel( aEvent.GetRow() );
432 }
433 
434 
436 {
437  if( aEvent.GetCol() == 0 )
438  {
439  bool hasAlias = false;
440  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
441  wxString filename = m_modelsGrid->GetCellValue( aEvent.GetRow(), 0 );
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  }
463  else if( aEvent.GetCol() == 1 )
464  {
465  wxString previewValue = m_modelsGrid->GetCellValue( aEvent.GetRow(), 1 );
466 
467  m_shapes3D_list[ aEvent.GetRow() ].m_Preview = previewValue == wxT( "1" );
468  }
469 
471 }
472 
473 
475 {
476  m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
477 
478  int idx = m_modelsGrid->GetGridCursorRow();
479 
480  if( idx >= 0 )
481  {
482  m_shapes3D_list.erase( m_shapes3D_list.begin() + idx );
483  m_modelsGrid->DeleteRows( idx, 1 );
484 
485  select3DModel( idx ); // will clamp idx within bounds
487  }
488 }
489 
490 
492 {
494  return;
495 
496  PROJECT& prj = Prj();
497  MODULE_3D_SETTINGS model;
498 
499  wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
500  wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX );
501  int filter = 0;
502 
503  // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment
504  // variable and fall back to the project path if necessary.
505  if( initialpath.IsEmpty() )
506  {
507  if( !wxGetEnv( "KISYS3DMOD", &initialpath ) || initialpath.IsEmpty() )
508  initialpath = prj.GetProjectPath();
509  }
510 
511  if( !sidx.empty() )
512  {
513  long tmp;
514  sidx.ToLong( &tmp );
515 
516  if( tmp > 0 && tmp <= INT_MAX )
517  filter = (int) tmp;
518  }
519 
520  if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model )
521  || model.m_Filename.empty() )
522  {
523  return;
524  }
525 
526  prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath );
527  sidx = wxString::Format( wxT( "%i" ), filter );
529  FILENAME_RESOLVER* res = Prj().Get3DCacheManager()->GetResolver();
530  wxString alias;
531  wxString shortPath;
532  wxString filename = model.m_Filename;
533 
534  if( res && res->SplitAlias( filename, alias, shortPath ) )
535  filename = alias + wxT( ":" ) + shortPath;
536 
537 #ifdef __WINDOWS__
538  // In KiCad files, filenames and paths are stored using Unix notation
539  model.m_Filename.Replace( "\\", "/" );
540 #endif
541 
542  model.m_Preview = true;
543  m_shapes3D_list.push_back( model );
544 
545  int idx = m_modelsGrid->GetNumberRows();
546  m_modelsGrid->AppendRows( 1 );
547  m_modelsGrid->SetCellValue( idx, 0, filename );
548  m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) );
549 
551 }
552 
553 
555 {
557  return;
558 
559  MODULE_3D_SETTINGS model;
560 
561  model.m_Preview = true;
562  m_shapes3D_list.push_back( model );
563 
564  int row = m_modelsGrid->GetNumberRows();
565  m_modelsGrid->AppendRows( 1 );
566  m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) );
567 
568  m_modelsGrid->SetFocus();
569  m_modelsGrid->MakeCellVisible( row, 0 );
570  m_modelsGrid->SetGridCursor( row, 0 );
571 
572  m_modelsGrid->EnableCellEditControl( true );
573  m_modelsGrid->ShowCellEditControl();
574 }
575 
576 
578 {
580  return false;
581 
582  if( !DIALOG_SHIM::Validate() )
583  return false;
584 
585  // Check for empty texts.
586  for( size_t i = 2; i < m_texts->size(); ++i )
587  {
588  TEXTE_MODULE& text = m_texts->at( i );
589 
590  if( text.GetText().IsEmpty() )
591  {
592  if( m_NoteBook->GetSelection() != 0 )
593  m_NoteBook->SetSelection( 0 );
594 
596  m_delayedErrorMessage = _( "Text items must have some content." );
599 
600  return false;
601  }
602  }
603 
604  if( !m_netClearance.Validate( 0, INT_MAX ) )
605  return false;
606 
607  return true;
608 }
609 
610 
612 {
613  if( !Validate() )
614  return false;
615 
616  if( !DIALOG_SHIM::TransferDataFromWindow() )
617  return false;
618 
619  if( !m_PanelGeneral->TransferDataFromWindow() )
620  return false;
621 
622  if( !m_Panel3D->TransferDataFromWindow() )
623  return false;
624 
625  if( m_DC )
626  {
629  }
630 
631  auto view = m_frame->GetGalCanvas()->GetView();
632  BOARD_COMMIT commit( m_frame );
633  commit.Modify( m_footprint );
634 
635  // copy reference and value
636  m_footprint->Reference() = m_texts->at( 0 );
637  m_footprint->Value() = m_texts->at( 1 );
638 
639  size_t i = 2;
640  BOARD_ITEM* next;
641 
642  for( BOARD_ITEM* item = m_footprint->GraphicalItemsList().GetFirst(); item; item = next )
643  {
644  next = item->Next();
645  TEXTE_MODULE* textModule = dyn_cast<TEXTE_MODULE*>( item );
646 
647  if( textModule )
648  {
649  // copy grid table entries till we run out, then delete any remaining texts
650  if( i < m_texts->size() )
651  *textModule = m_texts->at( i++ );
652  else
653  textModule->DeleteStructure();
654  }
655  }
656 
657  // if there are still grid table entries, create new texts for them
658  while( i < m_texts->size() )
659  {
660  auto newText = new TEXTE_MODULE( m_texts->at( i++ ) );
661  m_footprint->Add( newText, ADD_APPEND );
662  view->Add( newText );
663  }
664 
665  // Initialize masks clearances
669 
670  double dtmp = 0.0;
671  wxString msg = m_SolderPasteMarginRatioCtrl->GetValue();
672  msg.ToDouble( &dtmp );
673 
674  // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
675  if( dtmp < -50.0 )
676  dtmp = -50.0;
677  // A margin ratio is always <= 0
678  // 0 means use full pad copper area
679  if( dtmp > 0.0 )
680  dtmp = 0.0;
681 
683 
684  switch( m_ZoneConnectionChoice->GetSelection() )
685  {
686  default:
691  }
692 
693  // Set Module Position
694  wxPoint modpos( m_posX.GetValue(), m_posY.GetValue() );
695  m_footprint->SetPosition( modpos );
696  m_footprint->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 );
697  m_footprint->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
698 
699  switch( m_AttributsCtrl->GetSelection() )
700  {
701  case 0: m_footprint->SetAttributes( 0 ); break;
702  case 1: m_footprint->SetAttributes( MOD_CMS ); break;
703  case 2: m_footprint->SetAttributes( MOD_VIRTUAL ); break;
704  default: wxFAIL;
705  }
706 
709 
710  // Now, set orientation. Must be done after other changes because rotation changes field
711  // positions on board (so that relative positions are held constant)
712  m_OrientValidator.TransferFromWindow();
713 
714  int orient = KiROUND( m_OrientValue * 10.0 );
715 
716  if( m_footprint->GetOrientation() != orient )
718 
719  // Set component side, that also have effect on the fields positions on board
720  bool change_layer = false;
721  if( m_BoardSideCtrl->GetSelection() == 0 ) // layer req = COMPONENT
722  {
723  if( m_footprint->GetLayer() == B_Cu )
724  change_layer = true;
725  }
726  else if( m_footprint->GetLayer() == F_Cu )
727  change_layer = true;
728 
729  if( change_layer )
731 
732  std::list<MODULE_3D_SETTINGS>* draw3D = &m_footprint->Models();
733  draw3D->clear();
734  draw3D->insert( draw3D->end(), m_shapes3D_list.begin(), m_shapes3D_list.end() );
735 
737 
738  // This is a simple edit, we must create an undo entry
739  if( m_footprint->GetEditFlags() == 0 ) // i.e. not edited, or moved
740  commit.Push( _( "Modify module properties" ) );
741 
742  SetReturnCode( PRM_EDITOR_EDIT_OK );
743 
744  if( m_DC )
745  {
748  }
749 
750  return true;
751 }
752 
753 
755 {
757  return;
758 
759  const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
760  TEXTE_MODULE textMod( m_footprint );
761 
762  // Set active layer if legal; otherwise copy layer from previous text item
763  if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) )
764  textMod.SetLayer( m_frame->GetActiveLayer() );
765  else
766  textMod.SetLayer( m_texts->at( m_texts->size() - 1 ).GetLayer() );
767 
768  textMod.SetTextSize( dsnSettings.GetTextSize( textMod.GetLayer() ) );
769  textMod.SetThickness( dsnSettings.GetTextThickness( textMod.GetLayer() ) );
770  textMod.SetItalic( dsnSettings.GetTextItalic( textMod.GetLayer() ) );
771  textMod.SetKeepUpright( dsnSettings.GetTextUpright( textMod.GetLayer() ) );
772  textMod.SetMirrored( IsBackLayer( textMod.GetLayer() ) );
773 
774  m_texts->push_back( textMod );
775 
776  // notify the grid
777  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
778  m_itemsGrid->ProcessTableMessage( msg );
779 
780  m_itemsGrid->SetFocus();
781  m_itemsGrid->MakeCellVisible( m_texts->size() - 1, 0 );
782  m_itemsGrid->SetGridCursor( m_texts->size() - 1, 0 );
783 
784  m_itemsGrid->EnableCellEditControl( true );
785  m_itemsGrid->ShowCellEditControl();
786 }
787 
788 
790 {
791  m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
792 
793  int curRow = m_itemsGrid->GetGridCursorRow();
794 
795  if( curRow < 0 )
796  return;
797  else if( curRow < 2 )
798  {
799  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
800  return;
801  }
802 
803  m_texts->erase( m_texts->begin() + curRow );
804 
805  // notify the grid
806  wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
807  m_itemsGrid->ProcessTableMessage( msg );
808 
809  if( m_itemsGrid->GetNumberRows() > 0 )
810  {
811  m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
812  m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
813  }
814 }
815 
816 
818 {
819  if( S3D::Configure3DPaths( this, Prj().Get3DCacheManager()->GetResolver() ) )
821 }
822 
823 
825 {
826  // Account for scroll bars
827  int itemsWidth = aWidth - ( m_itemsGrid->GetSize().x - m_itemsGrid->GetClientSize().x );
828  int modelsWidth = aWidth - ( m_modelsGrid->GetSize().x - m_modelsGrid->GetClientSize().x );
829 
830  itemsWidth -= m_itemsGrid->GetRowLabelSize();
831 
832  for( int i = 1; i < m_itemsGrid->GetNumberCols(); i++ )
833  itemsWidth -= m_itemsGrid->GetColSize( i );
834 
835  if( itemsWidth > 0 )
836  m_itemsGrid->SetColSize( 0, std::max( itemsWidth,
837  m_itemsGrid->GetVisibleWidth( 0, true, false, false ) ) );
838 
839  m_modelsGrid->SetColSize( 0, modelsWidth - m_modelsGrid->GetColSize( 1 ) - 5 );
840 }
841 
842 
844 {
845  if( !m_itemsGrid->IsCellEditControlShown() && !m_modelsGrid->IsCellEditControlShown() )
846  adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
847 
848  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
849  // even when the original validation was triggered from a killFocus event, and so
850  // that the corresponding notebook page can be shown in the background when triggered
851  // from an OK.
852  if( m_delayedFocusRow >= 0 )
853  {
854  // We will re-enter this routine if an error dialog is displayed, so make sure we
855  // zero out our member variables first.
856  wxGrid* grid = m_delayedFocusGrid;
857  int row = m_delayedFocusRow;
858  int col = m_delayedFocusColumn;
859  wxString msg = m_delayedErrorMessage;
860 
861  m_delayedFocusGrid = nullptr;
862  m_delayedFocusRow = -1;
864  m_delayedErrorMessage = wxEmptyString;
865 
866  if( !msg.IsEmpty() )
867  {
868  // Do not use DisplayErrorMessage(); it screws up window order on Mac
869  DisplayError( nullptr, msg );
870  }
871 
872  grid->SetFocus();
873  grid->MakeCellVisible( row, col );
874 
875  // Selecting the first grid item only makes sense for the
876  // items grid
877  if( !m_initialFocus || grid == m_itemsGrid )
878  {
879  grid->SetGridCursor( row, col );
880  grid->EnableCellEditControl( true );
881  grid->ShowCellEditControl();
882 
883  if( grid == m_itemsGrid && row == 0 && col == 0 )
884  {
885  auto referenceEditor = grid->GetCellEditor( 0, 0 );
886  SelectReferenceNumber( dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) );
887  referenceEditor->DecRef();
888  }
889  }
890  m_initialFocus = false;
891  }
892 }
893 
894 
895 void DIALOG_FOOTPRINT_BOARD_EDITOR::OnGridSize( wxSizeEvent& aEvent )
896 {
897  adjustGridColumns( aEvent.GetSize().GetX());
898 
899  aEvent.Skip();
900 }
901 
902 
904 {
906 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:195
CITER next(CITER it)
Definition: ptree.cpp:130
void SetPlacementCost90(int aCost)
Definition: class_module.h:574
int GetAttributes() const
Definition: class_module.h:225
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
double GetOrientation() const
Definition: class_module.h:188
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
int GetPlacementCost90() const
Definition: class_module.h:573
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:503
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:57
void SetLocalClearance(int aClearance)
Definition: class_module.h:208
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:571
This file is part of the common library.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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:321
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw draws the footprint to the aDC.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void SetItalic(bool isItalic)
Definition: eda_text.h:186
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:76
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one.
void SetZoneConnection(ZoneConnection aType)
Definition: class_module.h:216
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
virtual const wxString GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:147
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:192
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:231
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
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:204
bool m_Preview
Include module in 3D preview.
Definition: class_module.h:103
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:214
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:116
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:223
bool GetTextUpright(PCB_LAYER_ID aLayer) const
Pads are not covered.
Definition: zones.h:52
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp: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:207
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:263
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:502
virtual void CrossHairOn(wxDC *DC=nullptr)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void On3DModelCellChanged(wxGridEvent &aEvent) override
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: 3d_viewer.h:38
wxFloatingPointValidator< double > m_OrientValidator
timestamp_t GetTimeStamp() const
Definition: base_struct.h:210
virtual void CrossHairOff(wxDC *DC=nullptr)
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:305
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:399
void SetPosition(const wxPoint &aPos) override
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty.
Definition: dlist.h:163
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:267
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:205
UTF8 Format() const
Definition: lib_id.cpp:237
int GetLocalSolderPasteMargin() const
Definition: class_module.h:210
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:102
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:171
Definition: gr_basic.h:38
int GetPlacementCost180() const
Definition: class_module.h:570
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:211
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:213
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:178
bool Configure3DPaths(wxWindow *aParent, FILENAME_RESOLVER *aResolver)
see class PGM_BASE
BOARD_ITEM * Next() const
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:277
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
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:78
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
size_t i
Definition: json11.cpp:597
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
bool PadsLocked() const
Definition: class_module.h:303
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
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:173
DIALOG_FOOTPRINT_BOARD_EDITOR(PCB_EDIT_FRAME *aParent, MODULE *aModule, wxDC *aDC)
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Function ValidateName returns true if the given path is a valid aliased relative path.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:244
const wxPoint GetPosition() const override
Definition: class_module.h:183
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.
Declaration of the eda_3d_viewer class.
ZoneConnection GetZoneConnection() const
Definition: class_module.h:217
void updateOrientationControl()
Update the orientation validated control, without triggering a change event on the control (which wou...
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:165
void SetAttributes(int aAttributes)
Definition: class_module.h:226
#define min(a, b)
Definition: auxiliary.h:85
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:209
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