KiCad PCB EDA Suite
block_footprint_editor.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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2017 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 
32 #include <fctsys.h>
33 #include <pgm_base.h>
34 #include <gr_basic.h>
35 #include <class_drawpanel.h>
36 #include <confirm.h>
37 #include <block_commande.h>
38 #include <macros.h>
39 
40 #include <footprint_edit_frame.h>
41 #include <pcbplot.h>
42 #include <trigo.h>
43 
44 #include <pcbnew.h>
45 
46 #include <class_board.h>
47 #include <class_track.h>
48 #include <class_drawsegment.h>
49 #include <class_pcb_text.h>
50 #include <class_pcb_target.h>
51 #include <class_module.h>
52 #include <class_dimension.h>
53 #include <class_edge_mod.h>
54 
56 
57 
58 #define BLOCK_COLOR BROWN
59 
60 // Functions defined here, but used also in other files
61 // These 3 functions are used in modedit to rotate, mirror or move the
62 // whole footprint so they are called with force_all = true
63 void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
64 void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
65 void MoveMarkedItemsExactly( MODULE* module, const wxPoint& centre,
66  const wxPoint& translation, double rotation,
67  bool force_all = false );
68 
69 // Local functions:
70 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
71  bool aErase );
72 static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect );
73 
74 static void ClearMarkItems( MODULE* module );
75 static void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement );
76 static void MoveMarkedItems( MODULE* module, wxPoint offset );
77 static void DeleteMarkedItems( MODULE* module );
78 
79 
81 {
82  int cmd;
83 
84  switch( key )
85  {
86  default:
87  cmd = key & 0xFF;
88  break;
89 
90  case EDA_KEY_C( 0xffffffff ): // -1
91  // Historically, -1 has been used as a key, which can cause bit flag
92  // clashes with unaware code. On debug builds, catch any old code that
93  // might still be doing this. TODO: remove if sure all this old code is gone.
94  wxFAIL_MSG( "negative EDA_KEY value should be converted to GR_KEY_INVALID" );
95  // fall through on release builds
96 
97  case GR_KEY_INVALID:
99  break;
100 
101  case 0:
102  cmd = BLOCK_MOVE;
103  break;
104 
105  case GR_KB_ALT:
106  cmd = BLOCK_MIRROR_Y;
107  break;
108 
109  case GR_KB_SHIFTCTRL:
110  cmd = BLOCK_DELETE;
111  break;
112 
113  case GR_KB_SHIFT:
114  cmd = BLOCK_DUPLICATE;
115  break;
116 
117  case GR_KB_CTRL:
118  cmd = BLOCK_ROTATE;
119  break;
120 
121  case MOUSE_MIDDLE:
122  cmd = BLOCK_ZOOM;
123  break;
124  }
125 
126  return cmd;
127 }
128 
129 
131 {
132  int itemsCount = 0;
133  bool nextcmd = false;
134  MODULE* currentModule = GetBoard()->m_Modules;
135 
136  if( GetScreen()->m_BlockLocate.GetCount() )
137  {
138  // Set the SELECTED flag of all preselected items, and clear preselect list
139  ClearMarkItems( currentModule );
141 
142  for( unsigned ii = 0, e = list->GetCount(); ii < e; ++ii )
143  {
144  BOARD_ITEM* item = (BOARD_ITEM*) list->GetPickedItem( ii );
145  item->SetFlags( SELECTED );
146  ++itemsCount;
147  }
148 
150  }
151 
152  switch( GetScreen()->m_BlockLocate.GetCommand() )
153  {
154  case BLOCK_IDLE:
155  DisplayError( this, wxT( "Error in HandleBlockPLace" ) );
156  break;
157 
158  case BLOCK_DRAG: // Drag
159  case BLOCK_DRAG_ITEM: // Drag a given item (not used here)
160  case BLOCK_MOVE: // Move
161  case BLOCK_DUPLICATE: // Duplicate
162  case BLOCK_DUPLICATE_AND_INCREMENT: // Specific to duplicate with increment command
163 
164  // Find selected items if we didn't already set them manually
165  if( itemsCount == 0 )
166  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
167 
168  if( itemsCount )
169  {
170  nextcmd = true;
171 
172  if( m_canvas->IsMouseCaptured() )
173  {
174  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
176  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
177  }
178 
180  m_canvas->Refresh( true );
181  }
182 
183  break;
184 
185  case BLOCK_MOVE_EXACT:
186  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
187 
188  if( itemsCount )
189  {
190  wxPoint translation;
191  double rotation;
192  ROTATION_ANCHOR rotationAnchor = ROTATE_AROUND_SEL_CENTER;
193 
194  DIALOG_MOVE_EXACT dialog( this, translation, rotation, rotationAnchor );
195 
196  if( dialog.ShowModal() == wxID_OK )
197  {
198  SaveCopyInUndoList( currentModule, UR_CHANGED );
199  wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre();
200  blockCentre += translation;
201 
202  switch( rotationAnchor )
203  {
205  MoveMarkedItemsExactly( currentModule, blockCentre, translation, rotation );
206  break;
208  MoveMarkedItemsExactly( currentModule, GetScreen()->m_O_Curseur, translation, rotation );
209  break;
210  default:
211  wxFAIL_MSG( "Rotation choice shouldn't have been available in this context." );
212  }
213  }
214  }
215  break;
216 
217  case BLOCK_PRESELECT_MOVE: // Move with preselection list
218  nextcmd = true;
221  break;
222 
223  case BLOCK_DELETE: // Delete
224  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
225 
226  if( itemsCount )
227  SaveCopyInUndoList( currentModule, UR_CHANGED );
228 
229  DeleteMarkedItems( currentModule );
230  break;
231 
232  case BLOCK_COPY: // Copy
233  case BLOCK_PASTE:
234  case BLOCK_CUT:
235  break;
236 
237  case BLOCK_ROTATE:
238  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
239 
240  if( itemsCount )
241  SaveCopyInUndoList( currentModule, UR_CHANGED );
242 
243  RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
244  break;
245 
246  case BLOCK_MIRROR_X:
247  case BLOCK_MIRROR_Y:
248  case BLOCK_FLIP: // mirror
249  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
250 
251  if( itemsCount )
252  SaveCopyInUndoList( currentModule, UR_CHANGED );
253 
254  MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
255  break;
256 
257  case BLOCK_ZOOM: // Window Zoom
258  Window_Zoom( GetScreen()->m_BlockLocate );
259  break;
260 
261  case BLOCK_ABORT:
262  break;
263 
265  break;
266  }
267 
268  if( !nextcmd )
269  {
270  if( GetScreen()->m_BlockLocate.GetCommand() != BLOCK_SELECT_ITEMS_ONLY )
271  {
272  ClearMarkItems( currentModule );
273  }
274 
276  SetCurItem( NULL );
278  false );
279  m_canvas->Refresh( true );
280  }
281 
282  return nextcmd;
283 }
284 
285 
287 {
288  MODULE* currentModule = GetBoard()->m_Modules;
289 
290  if( !m_canvas->IsMouseCaptured() )
291  {
292  DisplayError( this, wxT( "HandleBlockPLace : m_mouseCaptureCallback = NULL" ) );
293  }
294 
296 
297  const BLOCK_COMMAND_T command = GetScreen()->m_BlockLocate.GetCommand();
298 
299  switch( command )
300  {
301  case BLOCK_IDLE:
302  break;
303 
304  case BLOCK_DRAG: // Drag
305  case BLOCK_MOVE: // Move
306  case BLOCK_PRESELECT_MOVE: // Move with preselection list
308  SaveCopyInUndoList( currentModule, UR_CHANGED );
309  MoveMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector() );
310  m_canvas->Refresh( true );
311  break;
312 
313  case BLOCK_DUPLICATE: // Duplicate
314  case BLOCK_DUPLICATE_AND_INCREMENT: // Duplicate and increment pad names
316  SaveCopyInUndoList( currentModule, UR_CHANGED );
317  CopyMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector(),
318  command == BLOCK_DUPLICATE_AND_INCREMENT );
319  break;
320 
321  case BLOCK_PASTE: // Paste
323  break;
324 
325  case BLOCK_MIRROR_X:
326  case BLOCK_MIRROR_Y:
327  case BLOCK_FLIP: // Mirror by popup menu, from block move
328  SaveCopyInUndoList( currentModule, UR_CHANGED );
329  MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
330  break;
331 
332  case BLOCK_ROTATE:
333  SaveCopyInUndoList( currentModule, UR_CHANGED );
334  RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
335  break;
336 
337  case BLOCK_ZOOM: // Handled by HandleBlockEnd
338  case BLOCK_DELETE:
339  case BLOCK_COPY:
340  case BLOCK_ABORT:
341  default:
342  break;
343  }
344 
345  OnModify();
346 
349  SetCurItem( NULL );
350  m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
351  m_canvas->Refresh( true );
352 }
353 
354 
355 /* Traces the outline of the search block structures
356  * The entire block follows the cursor
357  */
358 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
359  bool aErase )
360 {
361  BASE_SCREEN* screen = aPanel->GetScreen();
362  FOOTPRINT_EDIT_FRAME* moduleEditFrame = static_cast<FOOTPRINT_EDIT_FRAME*>( aPanel->GetParent() );
363 
364  wxASSERT( moduleEditFrame );
365  MODULE* currentModule = moduleEditFrame->GetBoard()->m_Modules;
366 
367  BLOCK_SELECTOR* block = &screen->m_BlockLocate;
368  GRSetDrawMode( aDC, g_XorMode );
369 
370  if( aErase )
371  {
372  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
373 
374  if( currentModule )
375  {
376  wxPoint move_offset = -block->GetMoveVector();
377  BOARD_ITEM* item = currentModule->GraphicalItemsList();
378 
379  for( ; item != NULL; item = item->Next() )
380  {
381  if( !item->IsSelected() )
382  continue;
383 
384  switch( item->Type() )
385  {
386  case PCB_MODULE_TEXT_T:
387  case PCB_MODULE_EDGE_T:
388  item->Draw( aPanel, aDC, g_XorMode, move_offset );
389  break;
390 
391  default:
392  break;
393  }
394  }
395 
396  D_PAD* pad = currentModule->PadsList();
397 
398  for( ; pad != NULL; pad = pad->Next() )
399  {
400  if( !pad->IsSelected() )
401  continue;
402 
403  pad->Draw( aPanel, aDC, g_XorMode, move_offset );
404  }
405  }
406  }
407 
408  // Repaint new view.
409  block->SetMoveVector( moduleEditFrame->GetCrossHairPosition() - block->GetLastCursorPosition() );
410 
411  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
412 
413  if( currentModule )
414  {
415  BOARD_ITEM* item = currentModule->GraphicalItemsList();
416  wxPoint move_offset = - block->GetMoveVector();
417 
418  for( ; item != NULL; item = item->Next() )
419  {
420  if( !item->IsSelected() )
421  continue;
422 
423  switch( item->Type() )
424  {
425  case PCB_MODULE_TEXT_T:
426  case PCB_MODULE_EDGE_T:
427  item->Draw( aPanel, aDC, g_XorMode, move_offset );
428  break;
429 
430  default:
431  break;
432  }
433  }
434 
435  D_PAD* pad = currentModule->PadsList();
436 
437  for( ; pad != NULL; pad = pad->Next() )
438  {
439  if( !pad->IsSelected() )
440  continue;
441 
442  pad->Draw( aPanel, aDC, g_XorMode, move_offset );
443  }
444  }
445 }
446 
447 
448 /* Copy marked items, at new position = old position + offset
449  */
450 void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement )
451 {
452  if( module == NULL )
453  return;
454 
455  // Reference and value cannot be copied, they are unique.
456  // Ensure they are not selected
457  module->Reference().ClearFlags();
458  module->Value().ClearFlags();
459 
460  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
461  {
462  if( !pad->IsSelected() )
463  continue;
464 
465  pad->ClearFlags( SELECTED );
466  D_PAD* NewPad = new D_PAD( *pad );
467  NewPad->SetParent( module );
468  NewPad->SetFlags( SELECTED );
469  module->PadsList().PushFront( NewPad );
470 
471  if( aIncrement )
472  NewPad->IncrementPadName( true, true );
473  }
474 
475  BOARD_ITEM* newItem;
476 
477  for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
478  {
479  if( !item->IsSelected() )
480  continue;
481 
482  item->ClearFlags( SELECTED );
483 
484  newItem = (BOARD_ITEM*)item->Clone();
485  newItem->SetParent( module );
486  newItem->SetFlags( SELECTED );
487  module->GraphicalItemsList().PushFront( newItem );
488  }
489 
490  MoveMarkedItems( module, offset );
491 }
492 
493 
494 /* Move marked items, at new position = old position + offset
495  */
496 void MoveMarkedItems( MODULE* module, wxPoint offset )
497 {
498  EDA_ITEM* item;
499 
500  if( module == NULL )
501  return;
502 
503  if( module->Reference().IsSelected() )
504  module->Reference().Move( offset );
505 
506  if( module->Value().IsSelected() )
507  module->Value().Move( offset );
508 
509  D_PAD* pad = module->PadsList();
510 
511  for( ; pad != NULL; pad = pad->Next() )
512  {
513  if( !pad->IsSelected() )
514  continue;
515 
516  pad->SetPosition( pad->GetPosition() + offset );
517  pad->SetPos0( pad->GetPos0() + offset );
518  }
519 
520  item = module->GraphicalItemsList();
521 
522  for( ; item != NULL; item = item->Next() )
523  {
524  if( !item->IsSelected() )
525  continue;
526 
527  switch( item->Type() )
528  {
529  case PCB_MODULE_TEXT_T:
530  static_cast<TEXTE_MODULE*>( item )->Move( offset );
531  break;
532 
533  case PCB_MODULE_EDGE_T:
534  {
535  EDGE_MODULE* em = (EDGE_MODULE*) item;
536  em->Move( offset );
537  em->SetStart0( em->GetStart0() + offset );
538  em->SetEnd0( em->GetEnd0() + offset );
539  em->SetBezier0_C1( em->GetBezier0_C1() + offset );
540  em->SetBezier0_C2( em->GetBezier0_C2() + offset );
541  }
542  break;
543 
544  default:
545  ;
546  }
547  }
548 
549  ClearMarkItems( module );
550 }
551 
552 
553 /* Delete marked items
554  */
555 void DeleteMarkedItems( MODULE* module )
556 {
557  if( module == NULL )
558  return;
559 
560  D_PAD* next_pad;
561  BOARD* board = module->GetBoard();
562 
563  for( D_PAD* pad = module->PadsList(); pad; pad = next_pad )
564  {
565  next_pad = pad->Next();
566 
567  if( !pad->IsSelected() )
568  continue;
569 
570  if( board )
571  board->PadDelete( pad );
572  else
573  pad->DeleteStructure();
574  }
575 
576  BOARD_ITEM* next_item;
577 
578  for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = next_item )
579  {
580  next_item = item->Next();
581 
582  if( !item->IsSelected() )
583  continue;
584 
585  item->DeleteStructure();
586  }
587 
588  // Ref and value can be flagged, but cannot be deleted
589  ClearMarkItems( module );
590 }
591 
592 
597 void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all )
598 {
599 #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
600  wxPoint tmp;
601  wxSize tmpz;
602 
603  if( module == NULL )
604  return;
605 
606  if( module->Reference().IsSelected() || force_all )
607  module->Reference().Mirror( offset, false );
608 
609  if( module->Value().IsSelected() || force_all )
610  module->Value().Mirror( offset, false );
611 
612  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
613  {
614  // Skip pads not selected, i.e. not inside the block to mirror:
615  if( !pad->IsSelected() && !force_all )
616  continue;
617 
618  tmp = pad->GetPosition();
619  SETMIRROR( tmp.x );
620  pad->SetPosition( tmp );
621 
622  pad->SetX0( pad->GetPosition().x );
623 
624  tmp = pad->GetOffset();
625  tmp.x = -tmp.x;
626  pad->SetOffset( tmp );
627 
628  tmpz = pad->GetDelta();
629  tmpz.x = -tmpz.x;
630  pad->SetDelta( tmpz );
631 
632  pad->SetOrientation( - pad->GetOrientation() );
633  }
634 
635  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
636  {
637  // Skip items not selected, i.e. not inside the block to mirror:
638  if( !item->IsSelected() && !force_all )
639  continue;
640 
641  switch( item->Type() )
642  {
643  case PCB_MODULE_EDGE_T:
644  ((EDGE_MODULE*) item)->Mirror( offset, false );
645  break;
646 
647  case PCB_MODULE_TEXT_T:
648  static_cast<TEXTE_MODULE*>( item )->Mirror( offset, false );
649  break;
650 
651  default:
652  break;
653  }
654  }
655 
656  ClearMarkItems( module );
657 }
658 
659 
664 void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
665 {
666 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
667 
668  if( module == NULL )
669  return;
670 
671  if( module->Reference().IsSelected() || force_all )
672  module->Reference().Rotate( offset, 900 );
673 
674  if( module->Value().IsSelected() || force_all )
675  module->Value().Rotate( offset, 900 );
676 
677  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
678  {
679  if( !pad->IsSelected() && !force_all )
680  continue;
681 
682  wxPoint pos = pad->GetPos0();
683  ROTATE( pos );
684  pad->SetPos0( pos );
685  pad->SetOrientation( pad->GetOrientation() + 900 );
686 
687  pad->SetDrawCoord();
688  }
689 
690  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
691  {
692  if( !item->IsSelected() && !force_all )
693  continue;
694 
695  switch( item->Type() )
696  {
697  case PCB_MODULE_EDGE_T:
698  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
699  break;
700 
701  case PCB_MODULE_TEXT_T:
702  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
703  break;
704 
705  default:
706  break;
707  }
708  }
709 
710  ClearMarkItems( module );
711 }
712 
713 
714 void ClearMarkItems( MODULE* module )
715 {
716  if( module == NULL )
717  return;
718 
719  module->Reference().ClearFlags();
720  module->Value().ClearFlags();
721 
722  EDA_ITEM* item = module->GraphicalItemsList();
723 
724  for( ; item != NULL; item = item->Next() )
725  {
726  item->ClearFlags();
727  }
728 
729  item = module->PadsList();
730 
731  for( ; item != NULL; item = item->Next() )
732  {
733  item->ClearFlags();
734  }
735 }
736 
737 
738 void MoveMarkedItemsExactly( MODULE* module, const wxPoint& centre,
739  const wxPoint& translation,
740  double rotation, bool force_all )
741 {
742  if( module == NULL )
743  return;
744 
745  if( module->Reference().IsSelected() || force_all )
746  {
747  module->Reference().Rotate( centre, rotation );
748  module->Reference().Move( translation );
749  }
750 
751  if( module->Value().IsSelected() || force_all )
752  {
753  module->Value().Rotate( centre, rotation );
754  module->Value().Move( translation );
755  }
756 
757  D_PAD* pad = module->PadsList();
758 
759  for( ; pad != NULL; pad = pad->Next() )
760  {
761  if( !pad->IsSelected() && !force_all )
762  continue;
763 
764  // rotate about centre point,
765  wxPoint newPos = pad->GetPosition();
766  RotatePoint( &newPos, centre, rotation );
767 
768  // shift and update
769  newPos += translation;
770  pad->SetPosition( newPos );
771  pad->SetPos0( newPos );
772 
773  // finally apply rotation to the pad itself
774  pad->Rotate( newPos, rotation );
775  }
776 
777  EDA_ITEM* item = module->GraphicalItemsList();
778 
779  for( ; item != NULL; item = item->Next() )
780  {
781  if( !item->IsSelected() && !force_all )
782  continue;
783 
784  switch( item->Type() )
785  {
786  case PCB_MODULE_TEXT_T:
787  {
788  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
789 
790  text->Rotate( centre, rotation );
791  text->Move( translation );
792  break;
793  }
794  case PCB_MODULE_EDGE_T:
795  {
796  EDGE_MODULE* em = static_cast<EDGE_MODULE*>( item );
797  em->Rotate( centre, rotation );
798  em->Move( translation );
799  break;
800  }
801  default:
802  ;
803  }
804  }
805 
806  ClearMarkItems( module );
807 }
808 
809 
810 /* Mark items inside rect.
811  * Items are inside rect when an end point is inside rect
812  */
813 int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
814 {
815  EDA_ITEM* item;
816  int ItemsCount = 0;
817  wxPoint pos;
818  D_PAD* pad;
819 
820  if( module == NULL )
821  return 0;
822 
823  ClearMarkItems( module ); // Just in case ...
824 
825  pos = module->Reference().GetTextPos();
826 
827  if( Rect.Contains( pos ) )
828  {
829  module->Reference().SetFlags( SELECTED );
830  ItemsCount++;
831  }
832 
833  pos = module->Value().GetTextPos();
834 
835  if( Rect.Contains( pos ) )
836  {
837  module->Value().SetFlags( SELECTED );
838  ItemsCount++;
839  }
840 
841  pad = module->PadsList();
842 
843  for( ; pad != NULL; pad = pad->Next() )
844  {
845  pad->ClearFlags( SELECTED );
846  pos = pad->GetPosition();
847 
848  if( Rect.Contains( pos ) )
849  {
850  pad->SetFlags( SELECTED );
851  ItemsCount++;
852  }
853  }
854 
855  item = module->GraphicalItemsList();
856 
857  for( ; item != NULL; item = item->Next() )
858  {
859  item->ClearFlags( SELECTED );
860 
861  switch( item->Type() )
862  {
863  case PCB_MODULE_EDGE_T:
864  if( ((EDGE_MODULE*)item )->HitTest( Rect ) )
865  {
866  item->SetFlags( SELECTED );
867  ItemsCount++;
868  }
869 
870  break;
871 
872  case PCB_MODULE_TEXT_T:
873  pos = static_cast<TEXTE_MODULE*>( item )->GetTextPos();
874 
875  if( Rect.Contains( pos ) )
876  {
877  item->SetFlags( SELECTED );
878  ItemsCount++;
879  }
880 
881  break;
882 
883  default:
884  break;
885  }
886  }
887 
888  return ItemsCount;
889 }
virtual BASE_SCREEN * GetScreen()=0
D_PAD * Next() const
Definition: class_pad.h:160
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:74
#define SETMIRROR(z)
#define GR_KB_ALT
bool IncrementPadName(bool aSkipUnconnectable, bool aFillSequenceGaps)
Function IncrementPadName.
Definition: class_pad.cpp:565
BLOCK_COMMAND_T GetCommand() const
void SetEnd0(const wxPoint &aPoint)
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 ...
#define MOUSE_MIDDLE
TEXTE_MODULE & Reference()
Definition: class_module.h:512
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
const wxPoint & GetPos0() const
Definition: class_pad.h:263
int GetCurrentCursor() const
Function GetCurrentCursor.
TEXTE_PCB class definition.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
void PadDelete(D_PAD *aPad)
Function PadDelete deletes a given bad from the BOARD by removing it from its module and from the m_N...
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:1198
bool IsSelected() const
Definition: base_struct.h:224
void PushFront(T *aNewElement)
Function PushFront puts aNewElement at front of list sequence.
Definition: dlist.h:240
static void ClearMarkItems(MODULE *module)
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 Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
void Rotate(const wxPoint &aOffset, double aAngle) override
Rotate text, in footprint editor (for instance in footprint rotation transform)
void SetBezier0_C1(const wxPoint &aPoint)
Class BOARD to handle a board.
void SetBezier0_C2(const wxPoint &aPoint)
void Move(const wxPoint &aMoveVector) override
move text in move transform, in footprint editor
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
virtual void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
BLOCK_COMMAND_T
#define GR_KB_CTRL
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
static void CopyMarkedItems(MODULE *module, wxPoint offset, bool aIncrement)
void ClearBlockCommand()
Definition: base_screen.h:501
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
#define EDA_KEY_C
static int MarkItemsInBloc(MODULE *module, EDA_RECT &Rect)
virtual void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)=0
Function Draw BOARD_ITEMs have their own color information.
Definition of class FOOTPRINT_EDIT_FRAME.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
unsigned GetCount() const
Function GetCount.
bool Contains(const wxPoint &aPoint) const
Function Contains.
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Functions relatives to tracks, vias and segments used to fill zones.
This file contains miscellaneous commonly used macros and functions.
void ClearItemsList()
Function ClearItemsList clear only the list of EDA_ITEM pointers, it does NOT delete the EDA_ITEM obj...
EDA_ITEM * Next() const
Definition: base_struct.h:209
Board plot function definition file.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
const wxPoint & GetStart0() const
virtual EDA_DRAW_FRAME * GetParent() const =0
void SetState(BLOCK_STATE_T aState)
DIMENSION class definition.
#define SELECTED
Definition: base_struct.h:121
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
virtual void HandleBlockPlace(wxDC *DC) override
Handle the BLOCK PLACE command.
virtual void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:511
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
uint32_t EDA_KEY
Definition: common.h:74
#define GR_KEY_INVALID
virtual int BlockCommand(EDA_KEY key) override
Return the block command code (BLOCK_MOVE, BLOCK_COPY...) corresponding to the keys pressed (ALT...
const wxPoint & GetBezier0_C2() const
#define ROTATE(z)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
#define GR_KB_SHIFT
void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0)) override
Function SaveCopyInUndoList Creates a new entry in undo list of commands.
Definition: undo_redo.cpp:202
ROTATION_ANCHOR
Definition: solve.cpp:178
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...
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
This file is part of the common library.
#define GR_KB_SHIFTCTRL
see class PGM_BASE
BOARD_ITEM * Next() const
Class to handle a graphic segment.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
DLIST< MODULE > m_Modules
Definition: class_board.h:249
static void DrawMovingBlockOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
void Move(const wxPoint &aMoveVector) override
Move an edge of the footprint.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetStart0(const wxPoint &aPoint)
T Mirror(T aPoint, T aMirrorRef)
Function MIRROR Mirror aPoint in aMirrorRef.
Definition: macros.h:109
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
static void MoveMarkedItems(MODULE *module, wxPoint offset)
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxPoint Centre() const
Definition: eda_rect.h:60
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror text position in footprint editing the text itself is not mirrored, and the layer not modified...
PICKED_ITEMS_LIST & GetItems()
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
virtual void Window_Zoom(EDA_RECT &Rect)
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
const wxPoint & GetBezier0_C1() const
const wxPoint & GetEnd0() const
PCB_TARGET class definition.
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
static void DeleteMarkedItems(MODULE *module)
Module description (excepted pads)
BOARD * GetBoard() const
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
const wxPoint GetPosition() const override
Definition: class_pad.h:220
EDGE_MODULE class definition.
void MoveMarkedItemsExactly(MODULE *module, const wxPoint &centre, const wxPoint &translation, double rotation, bool force_all=false)
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
virtual void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
int GetToolId() const
Definition: draw_frame.h:525
virtual bool HandleBlockEnd(wxDC *DC) override
Handle the "end" of a block command, i.e.
void SetCommand(BLOCK_COMMAND_T aCommand)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201