KiCad PCB EDA Suite
modedit.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) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
28 #include <fctsys.h>
29 #include <kiface_i.h>
30 #include <kiway.h>
31 #include <class_drawpanel.h>
32 #include <pcb_draw_panel_gal.h>
33 #include <confirm.h>
34 #include <gestfich.h>
35 #include <pgm_base.h>
36 #include <trigo.h>
38 #include <wxPcbStruct.h>
39 #include <kicad_device_context.h>
40 #include <macros.h>
41 #include <invoke_pcb_dialog.h>
42 #include <class_pcb_layer_widget.h>
43 #include <board_commit.h>
44 
45 #include <class_board.h>
46 #include <class_module.h>
47 #include <class_edge_mod.h>
48 
49 #include <ratsnest_data.h>
50 #include <pcbnew.h>
51 #include <protos.h>
52 #include <pcbnew_id.h>
53 #include <module_editor_frame.h>
54 #include <modview_frame.h>
55 #include <collectors.h>
56 #include <tool/tool_manager.h>
57 #include <tools/pcb_actions.h>
58 
60 #include <dialog_move_exact.h>
61 #include <dialog_create_array.h>
63 #include <menus_helpers.h>
64 #include <footprint_wizard_frame.h>
65 #include <pcbnew_config.h>
66 
67 #include <functional>
68 using namespace std::placeholders;
69 
70 
71 // Functions defined in block_module_editor, but used here
72 // These 3 functions are used in modedit to rotate, mirror or move the
73 // whole footprint so they are called with force_all = true
74 void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
75 void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
76 void MoveMarkedItemsExactly( MODULE* module, const wxPoint& centre,
77  const wxPoint& translation, double rotation,
78  bool force_all = false );
79 
80 
82 {
83  BOARD_ITEM* item = GetCurItem();
84 
85  if( GetBoard()->m_Modules == NULL )
86  return NULL;
87 
88  GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();
89 
90  // Assign to scanList the proper item types desired based on tool type
91  // or hotkey that is in play.
92 
93  const KICAD_T* scanList = NULL;
94 
95  if( aHotKeyCode )
96  {
97  // @todo: add switch here and add calls to PcbGeneralLocateAndDisplay(
98  // int aHotKeyCode ) when searching is needed from a hotkey handler
99  }
100  else
101  {
103  }
104 
105  m_Collector->Collect( GetBoard(), scanList, RefPos( true ), guide );
106 
107  // Remove redundancies: when an item is found, we can remove the module from list
108  if( m_Collector->GetCount() > 1 )
109  {
110  for( int ii = 0; ii < m_Collector->GetCount(); ii++ )
111  {
112  item = (*m_Collector)[ii];
113 
114  if( item->Type() != PCB_MODULE_T )
115  continue;
116 
117  m_Collector->Remove( ii );
118  ii--;
119  }
120  }
121 
122  if( m_Collector->GetCount() <= 1 )
123  {
124  item = (*m_Collector)[0];
125  SetCurItem( item );
126  }
127  else // we can't figure out which item user wants, do popup menu so user can choose
128  {
129  wxMenu itemMenu;
130 
131  // Give a title to the selection menu. It also allow to close the popup menu without any action
132  AddMenuItem( &itemMenu, wxID_NONE, _( "Clarify Selection" ),
133  KiBitmap( dismiss_xpm ) );
134  itemMenu.AppendSeparator();
135 
136  int limit = std::min( MAX_ITEMS_IN_PICKER, m_Collector->GetCount() );
137 
138  for( int ii = 0; ii<limit; ++ii )
139  {
140  item = (*m_Collector)[ii];
141 
142  wxString text = item->GetSelectMenuText();
143  BITMAP_DEF xpm = item->GetMenuImage();
144 
145  AddMenuItem( &itemMenu,
147  text,
148  KiBitmap( xpm ) );
149  }
150 
151  // this menu's handler is void
152  // PCB_BASE_FRAME::ProcessItemSelection()
153  // and it calls SetCurItem() which in turn calls DisplayInfo() on the
154  // item.
155  m_canvas->SetAbortRequest( true ); // changed in false if an item is selected
156  PopupMenu( &itemMenu ); // m_AbortRequest = false if an item is selected
157 
158  m_canvas->MoveCursorToCrossHair();
159  m_canvas->SetIgnoreMouseEvents( false );
160 
161  // The function ProcessItemSelection() has set the current item, return it.
162  item = GetCurItem();
163  }
164 
165  if( item )
166  {
167  SetMsgPanel( item );
168  }
169 
170  return item;
171 }
172 
173 
174 void FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard( wxCommandEvent& event )
175 {
176  if( GetScreen()->IsModify() )
177  {
178  if( !IsOK( this,
179  _( "Current footprint changes will be lost and this operation cannot be undone. Continue?" ) ) )
180  return;
181  }
182 
183  if( ! Load_Module_From_BOARD( NULL ) )
184  return;
185 
186  GetScreen()->ClearUndoRedoList();
187  GetScreen()->ClrModify();
188 
189  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
190 
191  if( draw3DFrame )
192  draw3DFrame->NewDisplay();
193 }
194 
195 
197 {
198  int id = event.GetId();
199  wxPoint pos;
200 
201  INSTALL_UNBUFFERED_DC( dc, m_canvas );
202 
203  wxGetMousePosition( &pos.x, &pos.y );
204 
205  pos.y += 20;
206 
207  switch( id )
208  {
209  case wxID_CUT:
210  case wxID_COPY:
233  case ID_POPUP_ZOOM_BLOCK:
236  case ID_POPUP_COPY_BLOCK:
237  break;
238 
240  default:
241  if( m_canvas->IsMouseCaptured() )
242  {
243  // for all other commands: stop the move in progress
244  m_canvas->CallEndMouseCapture( &dc );
245  }
246 
248  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
249 
250  break;
251  }
252 
253  switch( id )
254  {
255  case ID_EXIT:
256  Close( true );
257  break;
258 
260  {
261  wxString library = SelectLibrary( GetCurrentLib() );
262 
263  if( library.size() )
264  {
266  updateTitle();
267  }
268  }
269  break;
270 
272  {
274 
275  if( !viewer )
276  {
278  viewer->Show( true );
279  viewer->Zoom_Automatique( false );
280  }
281  else
282  {
283  // On Windows, Raise() does not bring the window on screen, when iconized
284  if( viewer->IsIconized() )
285  viewer->Iconize( false );
286 
287  viewer->Raise();
288 
289  // Raising the window does not set the focus on Linux. This should work on
290  // any platform.
291  if( wxWindow::FindFocus() != viewer )
292  viewer->SetFocus();
293  }
294  }
295  break;
296 
298  DeleteModuleFromCurrentLibrary();
299  break;
300 
302  {
303  if( !Clear_Pcb( true ) )
304  break;
305 
306  SetCrossHairPosition( wxPoint( 0, 0 ) );
307 
308  MODULE* module = CreateNewModule( wxEmptyString );
309 
310  if( module ) // i.e. if create module command not aborted
311  {
312  // Initialize data relative to nets and netclasses (for a new
313  // module the defaults are used)
314  // This is mandatory to handle and draw pads
316  module->SetPosition( wxPoint( 0, 0 ) );
317 
318  if( GetBoard()->m_Modules )
320 
321  Zoom_Automatique( false );
322  }
323 
324  updateView();
325  m_canvas->Refresh();
326 
327  GetScreen()->ClrModify();
328  }
329  break;
330 
332  {
333  if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
334  {
335  if( !IsOK( this,
336  _( "Current Footprint will be lost and this operation cannot be undone. Continue ?" ) ) )
337  break;
338  }
339 
341  FRAME_PCB_FOOTPRINT_WIZARD_MODAL, true, this );
342 
343  if( wizard->ShowModal( NULL, this ) )
344  {
345  // Creates the new footprint from python script wizard
346  MODULE* module = wizard->GetBuiltFootprint();
347 
348  if( module == NULL ) // i.e. if create module command aborted
349  break;
350 
351  Clear_Pcb( false );
352 
353  SetCrossHairPosition( wxPoint( 0, 0 ) );
354 
355  // Add the new object to board
356  GetBoard()->Add( module, ADD_APPEND );
357 
358  // Initialize data relative to nets and netclasses (for a new
359  // module the defaults are used)
360  // This is mandatory to handle and draw pads
362  module->SetPosition( wxPoint( 0, 0 ) );
363  module->ClearFlags();
364 
365  Zoom_Automatique( false );
366  updateView();
367  m_canvas->Refresh();
368 
369  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
370 
371  if( draw3DFrame )
372  draw3DFrame->NewDisplay();
373 
374  GetScreen()->ClrModify();
375  }
376 
377  wizard->Destroy();
378  }
379  break;
380 
382  if( GetBoard()->m_Modules && GetCurrentLib().size() )
383  {
384  SaveFootprintInLibrary( GetCurrentLib(), GetBoard()->m_Modules, true, true );
385  GetScreen()->ClrModify();
386  }
387  break;
388 
391  {
392  // update module in the current board,
393  // not just add it to the board with total disregard for the netlist...
394  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
395 
396  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
397  {
398  wxMessageBox( _("No board currently edited" ) );
399  break;
400  }
401 
402  BOARD* mainpcb = pcbframe->GetBoard();
403  MODULE* source_module = NULL;
404  MODULE* module_in_edit = GetBoard()->m_Modules;
405 
406  // Search the old module (source) if exists
407  // Because this source could be deleted when editing the main board...
408  if( module_in_edit->GetLink() ) // this is not a new module ...
409  {
410  source_module = mainpcb->m_Modules;
411 
412  for( ; source_module != NULL; source_module = source_module->Next() )
413  {
414  if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
415  break;
416  }
417  }
418 
419  if( ( source_module == NULL )
420  && ( id == ID_MODEDIT_UPDATE_MODULE_IN_BOARD ) ) // source not found
421  {
422  wxString msg;
423  msg.Printf( _( "Unable to find the footprint source on the main board" ) );
424  msg << _( "\nCannot update the footprint" );
425  DisplayError( this, msg );
426  break;
427  }
428 
429  if( ( source_module != NULL )
430  && ( id == ID_MODEDIT_INSERT_MODULE_IN_BOARD ) ) // source not found
431  {
432  wxString msg;
433  msg.Printf( _( "A footprint source was found on the main board" ) );
434  msg << _( "\nCannot insert this footprint" );
435  DisplayError( this, msg );
436  break;
437  }
438 
439  m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
441  BOARD_COMMIT commit( pcbframe );
442 
443  // Create the "new" module
444  MODULE* newmodule = new MODULE( *module_in_edit );
445  newmodule->SetParent( mainpcb );
446  newmodule->SetLink( 0 );
447 
448  if( source_module ) // this is an update command
449  {
450  // In the main board,
451  // the new module replace the old module (pos, orient, ref, value
452  // and connexions are kept)
453  // and the source_module (old module) is deleted
454  pcbframe->Exchange_Module( source_module, newmodule, commit );
455  newmodule->SetTimeStamp( module_in_edit->GetLink() );
456  commit.Push( wxT( "Update module" ) );
457  }
458  else // This is an insert command
459  {
460  wxPoint cursor_pos = pcbframe->GetCrossHairPosition();
461 
462  commit.Add( newmodule );
463  pcbframe->SetCrossHairPosition( wxPoint( 0, 0 ) );
464  pcbframe->PlaceModule( newmodule, NULL );
465  newmodule->SetPosition( wxPoint( 0, 0 ) );
466  pcbframe->SetCrossHairPosition( cursor_pos );
467  newmodule->SetTimeStamp( GetNewTimeStamp() );
468  commit.Push( wxT( "Insert module" ) );
469  }
470 
471  newmodule->ClearFlags();
472  GetScreen()->ClrModify();
473  pcbframe->SetCurItem( NULL );
474  // @todo LEGACY should be unnecessary
475  mainpcb->m_Status_Pcb = 0;
476  }
477  break;
478 
480  if( ! Clear_Pcb( true ) )
481  break; // //this command is aborted
482 
483  SetCrossHairPosition( wxPoint( 0, 0 ) );
484  Import_Module();
485 
486  if( GetBoard()->m_Modules )
488 
489  GetScreen()->ClrModify();
490  Zoom_Automatique( false );
491  m_canvas->Refresh();
492  {
493  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
494 
495  if( draw3DFrame )
496  draw3DFrame->NewDisplay();
497  }
498 
499  break;
500 
502  if( GetBoard()->m_Modules )
503  Export_Module( GetBoard()->m_Modules );
504  break;
505 
507  if( GetBoard()->m_Modules )
508  {
509  // CreateModuleLibrary() only creates a new library, does not save footprint
510  wxString libPath = CreateNewLibrary();
511  if( libPath.size() )
512  SaveCurrentModule( &libPath );
513  }
514  break;
515 
517  break;
518 
520  wxLogDebug( wxT( "Loading module from library " ) + getLibPath() );
521 
522  if( ! Clear_Pcb( true ) )
523  break;
524 
525  SetCrossHairPosition( wxPoint( 0, 0 ) );
526 
527  LoadModuleFromLibrary( GetCurrentLib(), Prj().PcbFootprintLibs(), true );
528 
529  if( GetBoard() && GetBoard()->m_Modules )
530  {
532 
533  // if either m_Reference or m_Value are gone, reinstall them -
534  // otherwise you cannot see what you are doing on board
536  TEXTE_MODULE* val = &GetBoard()->m_Modules->Value();
537 
538  if( val && ref )
539  {
540  ref->SetType( TEXTE_MODULE::TEXT_is_REFERENCE ); // just in case ...
541 
542  if( ref->GetLength() == 0 )
543  ref->SetText( wxT( "Ref**" ) );
544 
545  val->SetType( TEXTE_MODULE::TEXT_is_VALUE ); // just in case ...
546 
547  if( val->GetLength() == 0 )
548  val->SetText( wxT( "Val**" ) );
549  }
550  }
551 
552  Zoom_Automatique( false );
553 
554  {
555  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
556 
557  if( draw3DFrame )
558  draw3DFrame->NewDisplay();
559  }
560 
561  GetScreen()->ClrModify();
562 
563  updateView();
564  m_canvas->Refresh();
565 
566  break;
567 
569  InstallPadOptionsFrame( NULL );
570  break;
571 
572  case ID_MODEDIT_CHECK:
573  // Currently: not implemented
574  break;
575 
577  if( GetBoard()->m_Modules )
578  {
579  SetCurItem( GetBoard()->m_Modules );
580 
581  DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) GetScreen()->GetCurItem() );
582 
583  int ret = dialog.ShowModal();
584  GetScreen()->GetCurItem()->ClearFlags();
585 
586  if( ret > 0 )
587  m_canvas->Refresh();
588  }
589  break;
590 
592  break;
593 
595  break;
596 
598  m_canvas->MoveCursorToCrossHair();
599  Rotate_Module( NULL, (MODULE*) GetScreen()->GetCurItem(), 900, true );
600  m_canvas->Refresh();
601  break;
602 
604  m_canvas->MoveCursorToCrossHair();
605  Rotate_Module( NULL, (MODULE*) GetScreen()->GetCurItem(), -900, true );
606  m_canvas->Refresh();
607  break;
608 
610  {
611  DIALOG_MODULE_MODULE_EDITOR dialog( this, (MODULE*) GetScreen()->GetCurItem() );
612  dialog.ShowModal();
613  GetScreen()->GetCurItem()->ClearFlags();
614  m_canvas->MoveCursorToCrossHair();
615  m_canvas->Refresh();
616  }
617  break;
618 
620  m_canvas->MoveCursorToCrossHair();
621  StartMovePad( (D_PAD*) GetScreen()->GetCurItem(), &dc, false );
622  break;
623 
625  InstallPadOptionsFrame( (D_PAD*) GetScreen()->GetCurItem() );
626  m_canvas->MoveCursorToCrossHair();
627  break;
628 
630  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
631  DeletePad( (D_PAD*) GetScreen()->GetCurItem(), false );
632  SetCurItem( NULL );
633  m_canvas->MoveCursorToCrossHair();
634  break;
635 
637  duplicateItems( false );
638  break;
639 
641  duplicateItems( true );
642  break;
643 
645  moveExact();
646  break;
647 
649  createArray();
650  break;
651 
653  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
654  m_canvas->MoveCursorToCrossHair();
655  Import_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem(), true );
656  break;
657 
659  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
660  // Calls the global change dialog:
661  DlgGlobalChange_PadSettings( (D_PAD*) GetScreen()->GetCurItem() );
662  m_canvas->MoveCursorToCrossHair();
663  break;
664 
666  m_canvas->MoveCursorToCrossHair();
667  Export_Pad_Settings( (D_PAD*) GetScreen()->GetCurItem() );
668  break;
669 
671  InstallTextModOptionsFrame( static_cast<TEXTE_MODULE*>( GetScreen()->GetCurItem() ), &dc );
672  m_canvas->MoveCursorToCrossHair();
673  break;
674 
676  m_canvas->MoveCursorToCrossHair();
677  StartMoveTexteModule( static_cast<TEXTE_MODULE*>( GetScreen()->GetCurItem() ), &dc );
678  break;
679 
681  RotateTextModule( static_cast<TEXTE_MODULE*>( GetScreen()->GetCurItem() ), &dc );
682  m_canvas->MoveCursorToCrossHair();
683  break;
684 
686  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
687  DeleteTextModule( static_cast<TEXTE_MODULE*>( GetScreen()->GetCurItem() ) );
688  SetCurItem( NULL );
689  m_canvas->MoveCursorToCrossHair();
690  break;
691 
693  Start_Move_EdgeMod( static_cast<EDGE_MODULE*>( GetScreen()->GetCurItem() ), &dc );
694  m_canvas->MoveCursorToCrossHair();
695  break;
696 
698  m_canvas->MoveCursorToCrossHair();
699 
700  if( GetScreen()->GetCurItem()->IsNew() )
701  {
702  End_Edge_Module( (EDGE_MODULE*) GetScreen()->GetCurItem() );
703  SetCurItem( NULL );
704  }
705  break;
706 
708  {
709  EDGE_MODULE* edge = NULL;
710 
711  if( GetScreen()->GetCurItem()
712  && ( GetScreen()->GetCurItem()->Type() == PCB_MODULE_EDGE_T ) )
713  {
714  edge = (EDGE_MODULE*) GetScreen()->GetCurItem();
715  }
716 
717  Enter_Edge_Width( edge );
718  m_canvas->MoveCursorToCrossHair();
719 
720  if( edge )
721  m_canvas->Refresh();
722  }
723  break;
724 
726  m_canvas->MoveCursorToCrossHair();
727  InstallFootprintBodyItemPropertiesDlg( (EDGE_MODULE*) GetScreen()->GetCurItem() );
728  m_canvas->Refresh();
729  break;
730 
732  m_canvas->MoveCursorToCrossHair();
733  Edit_Edge_Width( NULL );
734  m_canvas->Refresh();
735  break;
736 
738  m_canvas->MoveCursorToCrossHair();
739  Edit_Edge_Layer( NULL );
740  m_canvas->Refresh();
741  break;
742 
744  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
745  m_canvas->MoveCursorToCrossHair();
746  RemoveStruct( GetScreen()->GetCurItem() );
747  SetCurItem( NULL );
748  break;
749 
753  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
754  Transform( (MODULE*) GetScreen()->GetCurItem(), id );
755  m_canvas->Refresh();
756  break;
757 
759  InstallOptionsFrame( pos );
760  break;
761 
762  case ID_PCB_PAD_SETUP:
763  {
764  BOARD_ITEM* item = GetCurItem();
765 
766  if( item )
767  {
768  if( item->Type() != PCB_PAD_T )
769  item = NULL;
770  }
771 
772  InstallPadOptionsFrame( (D_PAD*) item );
773  }
774  break;
775 
777  InvokeDialogGrid();
778  break;
779 
781  GetScreen()->m_BlockLocate.SetCommand( BLOCK_MOVE );
782  m_canvas->SetAutoPanRequest( false );
783  HandleBlockPlace( &dc );
784  break;
785 
786  case ID_POPUP_COPY_BLOCK:
787  GetScreen()->m_BlockLocate.SetCommand( BLOCK_COPY );
788  GetScreen()->m_BlockLocate.SetMessageBlock( this );
789  m_canvas->SetAutoPanRequest( false );
790  HandleBlockPlace( &dc );
791  break;
792 
793  case ID_POPUP_ZOOM_BLOCK:
794  GetScreen()->m_BlockLocate.SetCommand( BLOCK_ZOOM );
795  GetScreen()->m_BlockLocate.SetMessageBlock( this );
796  HandleBlockEnd( &dc );
797  break;
798 
800  GetScreen()->m_BlockLocate.SetCommand( BLOCK_DELETE );
801  GetScreen()->m_BlockLocate.SetMessageBlock( this );
802  HandleBlockEnd( &dc );
803  break;
804 
806  GetScreen()->m_BlockLocate.SetCommand( BLOCK_ROTATE );
807  GetScreen()->m_BlockLocate.SetMessageBlock( this );
808  HandleBlockEnd( &dc );
809  break;
810 
812  GetScreen()->m_BlockLocate.SetCommand( BLOCK_MIRROR_X );
813  GetScreen()->m_BlockLocate.SetMessageBlock( this );
814  HandleBlockEnd( &dc );
815  break;
816 
818  GetScreen()->m_BlockLocate.SetCommand( BLOCK_MOVE_EXACT );
819  GetScreen()->m_BlockLocate.SetMessageBlock( this );
820  HandleBlockEnd( &dc );
821  break;
822 
824  if( GetBoard()->m_Modules )
825  {
826  InvokeDXFDialogModuleImport( this, GetBoard()->m_Modules );
827  m_canvas->Refresh();
828  }
829  break;
830 
831  default:
832  DisplayError( this,
833  wxT( "FOOTPRINT_EDIT_FRAME::Process_Special_Functions error" ) );
834  break;
835  }
836 }
837 
838 
840 {
841  wxPoint translation;
842  double rotation = 0;
843 
844  DIALOG_MOVE_EXACT dialog( this, translation, rotation );
845  int ret = dialog.ShowModal();
846 
847  if( ret == wxID_OK )
848  {
849  SaveCopyInUndoList( GetBoard()->m_Modules, UR_CHANGED );
850 
851  BOARD_ITEM* item = GetScreen()->GetCurItem();
852 
853  item->Move( translation );
854  item->Rotate( item->GetPosition(), rotation );
855  m_canvas->Refresh();
856  }
857 
858  m_canvas->MoveCursorToCrossHair();
859 }
860 
861 
863 {
864  BOARD_ITEM* item = GetScreen()->GetCurItem();
865 
866  PCB_BASE_EDIT_FRAME::duplicateItem( item, aIncrement );
867 }
868 
869 
870 void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform )
871 {
872  switch( transform )
873  {
875  RotateMarkedItems( module, wxPoint(0,0), true );
876  break;
877 
879  MirrorMarkedItems( module, wxPoint(0,0), true );
880  break;
881 
883  {
884  wxPoint translation;
885  double rotation = 0;
886 
887  DIALOG_MOVE_EXACT dialog( this, translation, rotation );
888  int ret = dialog.ShowModal();
889 
890  if( ret == wxID_OK )
891  {
892  MoveMarkedItemsExactly( module, wxPoint(0, 0),
893  translation, rotation, true );
894  }
895 
896  break;
897  }
898 
899  default:
900  DisplayInfoMessage( this, wxT( "Not available" ) );
901  break;
902  }
903 
904  module->CalculateBoundingBox();
905  OnModify();
906 }
907 
908 
909 void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
910 {
911  int id = aEvent.GetId();
912 
913  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
914 
915  switch( id )
916  {
917  case ID_NO_TOOL_SELECTED:
918  break;
919 
920  case ID_ZOOM_SELECTION:
921  SetToolID( id, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
922  break;
923 
925  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
926  break;
927 
928  case ID_MODEDIT_ARC_TOOL:
929  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
930  break;
931 
933  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
934  break;
935 
937  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
938  break;
939 
941  SetToolID( id, wxCURSOR_PENCIL, _( "Place anchor" ) );
942  break;
943 
945  SetToolID( id, wxCURSOR_PENCIL, _( "Set grid origin" ) );
946  break;
947 
948  case ID_MODEDIT_PAD_TOOL:
949  if( GetBoard()->m_Modules )
950  {
951  SetToolID( id, wxCURSOR_PENCIL, _( "Add pad" ) );
952  }
953  else
954  {
955  SetToolID( id, wxCURSOR_ARROW, _( "Pad settings" ) );
956  InstallPadOptionsFrame( NULL );
957  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
958  }
959  break;
960 
962  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
963  break;
964 
966  DisplayError( this, wxT( "Unsupported tool in legacy canvas" ) );
967  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
968  break;
969 
970  default:
971  wxFAIL_MSG( wxT( "Unknown command id." ) );
972  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
973  }
974 }
975 
976 
978 {
980 }
981 
982 
984 {
986 
987  m_Layers->SelectLayer( GetActiveLayer() );
988  m_Layers->OnLayerSelected();
989 
990  if( IsGalCanvasActive() )
991  {
992  GetGalCanvas()->SetHighContrastLayer( aLayer );
993  GetGalCanvas()->Refresh();
994  }
995 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
BOARD_ITEM * ModeditLocateAndDisplay(int aHotKeyCode=0)
Definition: modedit.cpp:81
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
int GetLength() const
void BuildListOfNets()
Definition: class_board.h:764
Class FOOTPRINT_WIZARD_FRAME.
Definition of class FOOTPRINT_EDIT_FRAME.
TEXTE_MODULE & Reference()
Definition: class_module.h:455
PNG memory record (file in memory).
Definition: bitmap_types.h:38
This file is part of the common library TODO brief description.
void OnVerticalToolbar(wxCommandEvent &aEvent)
Definition: modedit.cpp:909
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 Exchange_Module(MODULE *aOldModule, MODULE *aNewModule, BOARD_COMMIT &aCommit)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position...
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
PROJECT & Prj()
Definition: kicad.cpp:293
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
Component library viewer main window.
Definition: modview_frame.h:44
MODULE * Next() const
Definition: class_module.h:99
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
time_t GetNewTimeStamp()
Definition: common.cpp:166
virtual const wxPoint & GetPosition() const =0
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
void duplicateItem(BOARD_ITEM *aItem, bool aIncrement)
Function duplicateItem Duplicate the specified item This function is shared between pcbnew and modedi...
Definition: edit.cpp:1585
bool InvokeDXFDialogModuleImport(PCB_BASE_FRAME *aCaller, MODULE *aModule)
Function InvokeDXFDialogModuleImport shows the modal DIALOG_DXF_IMPORT for importing a DXF file as fo...
void duplicateItems(bool aIncrement) override
Function duplicateItems Duplicate the item under the cursor.
Definition: modedit.cpp:862
void SetActiveLayer(LAYER_ID aLayer) override
>
Definition: modedit.cpp:983
void MoveMarkedItemsExactly(MODULE *module, const wxPoint &centre, const wxPoint &translation, double rotation, bool force_all=false)
virtual void SetActiveLayer(LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
void MirrorMarkedItems(MODULE *module, wxPoint offset, bool force_all=false)
Mirror marked items, refer to a Vertical axis at position offset Note: because this function is used ...
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
This file contains miscellaneous commonly used macros and functions.
static const KICAD_T ModulesAndTheirItems[]
A scan list for MODULEs and their items (for Modedit)
Definition: collectors.h:282
void scanList(PTREE *aTree, DSNLEXER *aLexer)
Function scanList reads a sexpr list from the input stream into a new node with key aLexer->CurText()...
Definition: ptree.cpp:55
void PlaceModule(MODULE *aModule, wxDC *aDC, bool aDoNotRecreateRatsnest=false)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
Definition: modules.cpp:351
Definition: id.h:109
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
class MODULE, a footprint
Definition: typeinfo.h:101
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
a helper to handle the real device context used in KiCad
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
time_t GetLink() const
Definition: class_module.h:517
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
The common library.
Configuration parameters for Pcbnew.
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
void SetPosition(const wxPoint &aPos) override
virtual COLOR4D GetGridColor() const override
Function GetGridColor() , virtual.
Definition: modedit.cpp:977
void moveExact()
Function moveExact Move the selected item exactly, popping up a dialog to allow the user the enter th...
Definition: modedit.cpp:839
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
void SetType(TEXT_TYPE aType)
void NewDisplay(int dummy=0)
Definition: eda_3d_viewer.h:71
time_t GetTimeStamp() const
Definition: base_struct.h:204
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:162
BOARD * GetBoard()
void Process_Special_Functions(wxCommandEvent &event)
Definition: modedit.cpp:196
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:810
see class PGM_BASE
void LoadModuleFromBoard(wxCommandEvent &event)
Function LoadModuleFromBoard called from the main toolbar to load a footprint from board mainly to ed...
Definition: modedit.cpp:174
Declaration of the eda_3d_viewer class.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
DLIST< MODULE > m_Modules
Definition: class_board.h:243
#define INSTALL_UNBUFFERED_DC(name, parent)
void RotateMarkedItems(MODULE *module, wxPoint offset, bool force_all=false)
Rotate marked items, refer to a rotation point at position offset Note: because this function is used...
void SetLink(time_t aLink)
Definition: class_module.h:518
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
Class EDA_3D_VIEWER Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard...
Definition: eda_3d_viewer.h:50
#define MAX_ITEMS_IN_PICKER
Command IDs for the printed circuit board editor.
Definition: pcbnew_id.h:14
Module description (excepted pads)
Class GENERAL_COLLECTORS_GUIDE is a general implementation of a COLLECTORS_GUIDE. ...
Definition: collectors.h:378
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Function SetCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
EDGE_MODULE class definition.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
VTBL_ENTRY bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
void Transform(MODULE *module, int transform)
Function Transform performs a geometric transform on the current footprint.
Definition: modedit.cpp:870
#define min(a, b)
Definition: auxiliary.h:85
KIWAY Kiway
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39