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  OnModify();
215  }
216  }
217  break;
218 
219  case BLOCK_PRESELECT_MOVE: // Move with preselection list
220  nextcmd = true;
223  break;
224 
225  case BLOCK_DELETE: // Delete
226  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
227 
228  if( itemsCount )
229  SaveCopyInUndoList( currentModule, UR_CHANGED );
230 
231  DeleteMarkedItems( currentModule );
232  OnModify();
233  break;
234 
235  case BLOCK_COPY: // Copy
236  case BLOCK_PASTE:
237  case BLOCK_CUT:
238  break;
239 
240  case BLOCK_ROTATE:
241  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
242 
243  if( itemsCount )
244  SaveCopyInUndoList( currentModule, UR_CHANGED );
245 
246  RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
247  OnModify();
248  break;
249 
250  case BLOCK_MIRROR_X:
251  case BLOCK_MIRROR_Y:
252  case BLOCK_FLIP: // mirror
253  itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );
254 
255  if( itemsCount )
256  SaveCopyInUndoList( currentModule, UR_CHANGED );
257 
258  MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
259  OnModify();
260  break;
261 
262  case BLOCK_ZOOM: // Window Zoom
263  Window_Zoom( GetScreen()->m_BlockLocate );
264  break;
265 
266  case BLOCK_ABORT:
267  break;
268 
270  break;
271  }
272 
273  if( !nextcmd )
274  {
275  if( GetScreen()->m_BlockLocate.GetCommand() != BLOCK_SELECT_ITEMS_ONLY )
276  {
277  ClearMarkItems( currentModule );
278  }
279 
281  SetCurItem( NULL );
283  false );
284  m_canvas->Refresh( true );
285  }
286 
287  return nextcmd;
288 }
289 
290 
292 {
293  MODULE* currentModule = GetBoard()->m_Modules;
294 
295  if( !m_canvas->IsMouseCaptured() )
296  {
297  DisplayError( this, wxT( "HandleBlockPLace : m_mouseCaptureCallback = NULL" ) );
298  }
299 
301 
302  const BLOCK_COMMAND_T command = GetScreen()->m_BlockLocate.GetCommand();
303 
304  switch( command )
305  {
306  case BLOCK_IDLE:
307  break;
308 
309  case BLOCK_DRAG: // Drag
310  case BLOCK_MOVE: // Move
311  case BLOCK_PRESELECT_MOVE: // Move with preselection list
313  SaveCopyInUndoList( currentModule, UR_CHANGED );
314  MoveMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector() );
315  m_canvas->Refresh( true );
316  break;
317 
318  case BLOCK_DUPLICATE: // Duplicate
319  case BLOCK_DUPLICATE_AND_INCREMENT: // Duplicate and increment pad names
321  SaveCopyInUndoList( currentModule, UR_CHANGED );
322  CopyMarkedItems( currentModule, GetScreen()->m_BlockLocate.GetMoveVector(),
323  command == BLOCK_DUPLICATE_AND_INCREMENT );
324  break;
325 
326  case BLOCK_PASTE: // Paste
328  break;
329 
330  case BLOCK_MIRROR_X:
331  case BLOCK_MIRROR_Y:
332  case BLOCK_FLIP: // Mirror by popup menu, from block move
333  SaveCopyInUndoList( currentModule, UR_CHANGED );
334  MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
335  break;
336 
337  case BLOCK_ROTATE:
338  SaveCopyInUndoList( currentModule, UR_CHANGED );
339  RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
340  break;
341 
342  case BLOCK_ZOOM: // Handled by HandleBlockEnd
343  case BLOCK_DELETE:
344  case BLOCK_COPY:
345  case BLOCK_ABORT:
346  default:
347  break;
348  }
349 
350  OnModify();
351 
354  SetCurItem( NULL );
355  m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
356  m_canvas->Refresh( true );
357 }
358 
359 
360 /* Traces the outline of the search block structures
361  * The entire block follows the cursor
362  */
363 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
364  bool aErase )
365 {
366  BASE_SCREEN* screen = aPanel->GetScreen();
367  FOOTPRINT_EDIT_FRAME* moduleEditFrame = static_cast<FOOTPRINT_EDIT_FRAME*>( aPanel->GetParent() );
368 
369  wxASSERT( moduleEditFrame );
370  MODULE* currentModule = moduleEditFrame->GetBoard()->m_Modules;
371 
372  BLOCK_SELECTOR* block = &screen->m_BlockLocate;
373  GRSetDrawMode( aDC, g_XorMode );
374 
375  if( aErase )
376  {
377  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
378 
379  if( currentModule )
380  {
381  wxPoint move_offset = -block->GetMoveVector();
382  BOARD_ITEM* item = currentModule->GraphicalItemsList();
383 
384  for( ; item != NULL; item = item->Next() )
385  {
386  if( !item->IsSelected() )
387  continue;
388 
389  switch( item->Type() )
390  {
391  case PCB_MODULE_TEXT_T:
392  case PCB_MODULE_EDGE_T:
393  item->Draw( aPanel, aDC, g_XorMode, move_offset );
394  break;
395 
396  default:
397  break;
398  }
399  }
400 
401  D_PAD* pad = currentModule->PadsList();
402 
403  for( ; pad != NULL; pad = pad->Next() )
404  {
405  if( !pad->IsSelected() )
406  continue;
407 
408  pad->Draw( aPanel, aDC, g_XorMode, move_offset );
409  }
410  }
411  }
412 
413  // Repaint new view.
414  block->SetMoveVector( moduleEditFrame->GetCrossHairPosition() - block->GetLastCursorPosition() );
415 
416  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
417 
418  if( currentModule )
419  {
420  BOARD_ITEM* item = currentModule->GraphicalItemsList();
421  wxPoint move_offset = - block->GetMoveVector();
422 
423  for( ; item != NULL; item = item->Next() )
424  {
425  if( !item->IsSelected() )
426  continue;
427 
428  switch( item->Type() )
429  {
430  case PCB_MODULE_TEXT_T:
431  case PCB_MODULE_EDGE_T:
432  item->Draw( aPanel, aDC, g_XorMode, move_offset );
433  break;
434 
435  default:
436  break;
437  }
438  }
439 
440  D_PAD* pad = currentModule->PadsList();
441 
442  for( ; pad != NULL; pad = pad->Next() )
443  {
444  if( !pad->IsSelected() )
445  continue;
446 
447  pad->Draw( aPanel, aDC, g_XorMode, move_offset );
448  }
449  }
450 }
451 
452 
453 /* Copy marked items, at new position = old position + offset
454  */
455 void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement )
456 {
457  if( module == NULL )
458  return;
459 
460  // Reference and value cannot be copied, they are unique.
461  // Ensure they are not selected
462  module->Reference().ClearFlags();
463  module->Value().ClearFlags();
464 
465  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
466  {
467  if( !pad->IsSelected() )
468  continue;
469 
470  pad->ClearFlags( SELECTED );
471  D_PAD* NewPad = new D_PAD( *pad );
472  NewPad->SetParent( module );
473  NewPad->SetFlags( SELECTED );
474  module->PadsList().PushFront( NewPad );
475 
476  if( aIncrement )
477  NewPad->IncrementPadName( true, true );
478  }
479 
480  BOARD_ITEM* newItem;
481 
482  for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
483  {
484  if( !item->IsSelected() )
485  continue;
486 
487  item->ClearFlags( SELECTED );
488 
489  newItem = (BOARD_ITEM*)item->Clone();
490  newItem->SetParent( module );
491  newItem->SetFlags( SELECTED );
492  module->GraphicalItemsList().PushFront( newItem );
493  }
494 
495  MoveMarkedItems( module, offset );
496 }
497 
498 
499 /* Move marked items, at new position = old position + offset
500  */
501 void MoveMarkedItems( MODULE* module, wxPoint offset )
502 {
503  EDA_ITEM* item;
504 
505  if( module == NULL )
506  return;
507 
508  if( module->Reference().IsSelected() )
509  module->Reference().Move( offset );
510 
511  if( module->Value().IsSelected() )
512  module->Value().Move( offset );
513 
514  D_PAD* pad = module->PadsList();
515 
516  for( ; pad != NULL; pad = pad->Next() )
517  {
518  if( !pad->IsSelected() )
519  continue;
520 
521  pad->SetPosition( pad->GetPosition() + offset );
522  pad->SetPos0( pad->GetPos0() + offset );
523  }
524 
525  item = module->GraphicalItemsList();
526 
527  for( ; item != NULL; item = item->Next() )
528  {
529  if( !item->IsSelected() )
530  continue;
531 
532  switch( item->Type() )
533  {
534  case PCB_MODULE_TEXT_T:
535  static_cast<TEXTE_MODULE*>( item )->Move( offset );
536  break;
537 
538  case PCB_MODULE_EDGE_T:
539  {
540  EDGE_MODULE* em = (EDGE_MODULE*) item;
541  em->Move( offset );
542  em->SetStart0( em->GetStart0() + offset );
543  em->SetEnd0( em->GetEnd0() + offset );
544  em->SetBezier0_C1( em->GetBezier0_C1() + offset );
545  em->SetBezier0_C2( em->GetBezier0_C2() + offset );
546  }
547  break;
548 
549  default:
550  ;
551  }
552  }
553 
554  ClearMarkItems( module );
555 }
556 
557 
558 /* Delete marked items
559  */
560 void DeleteMarkedItems( MODULE* module )
561 {
562  if( module == NULL )
563  return;
564 
565  D_PAD* next_pad;
566  BOARD* board = module->GetBoard();
567 
568  for( D_PAD* pad = module->PadsList(); pad; pad = next_pad )
569  {
570  next_pad = pad->Next();
571 
572  if( !pad->IsSelected() )
573  continue;
574 
575  if( board )
576  board->PadDelete( pad );
577  else
578  pad->DeleteStructure();
579  }
580 
581  BOARD_ITEM* next_item;
582 
583  for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = next_item )
584  {
585  next_item = item->Next();
586 
587  if( !item->IsSelected() )
588  continue;
589 
590  item->DeleteStructure();
591  }
592 
593  // Ref and value can be flagged, but cannot be deleted
594  ClearMarkItems( module );
595 }
596 
597 
602 void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all )
603 {
604 #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
605  wxPoint tmp;
606  wxSize tmpz;
607 
608  if( module == NULL )
609  return;
610 
611  if( module->Reference().IsSelected() || force_all )
612  module->Reference().Mirror( offset, false );
613 
614  if( module->Value().IsSelected() || force_all )
615  module->Value().Mirror( offset, false );
616 
617  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
618  {
619  // Skip pads not selected, i.e. not inside the block to mirror:
620  if( !pad->IsSelected() && !force_all )
621  continue;
622 
623  tmp = pad->GetPosition();
624  SETMIRROR( tmp.x );
625  pad->SetPosition( tmp );
626 
627  pad->SetX0( pad->GetPosition().x );
628 
629  tmp = pad->GetOffset();
630  tmp.x = -tmp.x;
631  pad->SetOffset( tmp );
632 
633  tmpz = pad->GetDelta();
634  tmpz.x = -tmpz.x;
635  pad->SetDelta( tmpz );
636 
637  pad->SetOrientation( - pad->GetOrientation() );
638  }
639 
640  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
641  {
642  // Skip items not selected, i.e. not inside the block to mirror:
643  if( !item->IsSelected() && !force_all )
644  continue;
645 
646  switch( item->Type() )
647  {
648  case PCB_MODULE_EDGE_T:
649  ((EDGE_MODULE*) item)->Mirror( offset, false );
650  break;
651 
652  case PCB_MODULE_TEXT_T:
653  static_cast<TEXTE_MODULE*>( item )->Mirror( offset, false );
654  break;
655 
656  default:
657  break;
658  }
659  }
660 
661  ClearMarkItems( module );
662 }
663 
664 
669 void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
670 {
671 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
672 
673  if( module == NULL )
674  return;
675 
676  if( module->Reference().IsSelected() || force_all )
677  module->Reference().Rotate( offset, 900 );
678 
679  if( module->Value().IsSelected() || force_all )
680  module->Value().Rotate( offset, 900 );
681 
682  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
683  {
684  if( !pad->IsSelected() && !force_all )
685  continue;
686 
687  wxPoint pos = pad->GetPos0();
688  ROTATE( pos );
689  pad->SetPos0( pos );
690  pad->SetOrientation( pad->GetOrientation() + 900 );
691 
692  pad->SetDrawCoord();
693  }
694 
695  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
696  {
697  if( !item->IsSelected() && !force_all )
698  continue;
699 
700  switch( item->Type() )
701  {
702  case PCB_MODULE_EDGE_T:
703  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
704  break;
705 
706  case PCB_MODULE_TEXT_T:
707  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
708  break;
709 
710  default:
711  break;
712  }
713  }
714 
715  ClearMarkItems( module );
716 }
717 
718 
719 void ClearMarkItems( MODULE* module )
720 {
721  if( module == NULL )
722  return;
723 
724  module->Reference().ClearFlags();
725  module->Value().ClearFlags();
726 
727  EDA_ITEM* item = module->GraphicalItemsList();
728 
729  for( ; item != NULL; item = item->Next() )
730  {
731  item->ClearFlags();
732  }
733 
734  item = module->PadsList();
735 
736  for( ; item != NULL; item = item->Next() )
737  {
738  item->ClearFlags();
739  }
740 }
741 
742 
743 void MoveMarkedItemsExactly( MODULE* module, const wxPoint& centre,
744  const wxPoint& translation,
745  double rotation, bool force_all )
746 {
747  if( module == NULL )
748  return;
749 
750  if( module->Reference().IsSelected() || force_all )
751  {
752  module->Reference().Rotate( centre, rotation );
753  module->Reference().Move( translation );
754  }
755 
756  if( module->Value().IsSelected() || force_all )
757  {
758  module->Value().Rotate( centre, rotation );
759  module->Value().Move( translation );
760  }
761 
762  D_PAD* pad = module->PadsList();
763 
764  for( ; pad != NULL; pad = pad->Next() )
765  {
766  if( !pad->IsSelected() && !force_all )
767  continue;
768 
769  // rotate about centre point,
770  wxPoint newPos = pad->GetPosition();
771  RotatePoint( &newPos, centre, rotation );
772 
773  // shift and update
774  newPos += translation;
775  pad->SetPosition( newPos );
776  pad->SetPos0( newPos );
777 
778  // finally apply rotation to the pad itself
779  pad->Rotate( newPos, rotation );
780  }
781 
782  EDA_ITEM* item = module->GraphicalItemsList();
783 
784  for( ; item != NULL; item = item->Next() )
785  {
786  if( !item->IsSelected() && !force_all )
787  continue;
788 
789  switch( item->Type() )
790  {
791  case PCB_MODULE_TEXT_T:
792  {
793  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
794 
795  text->Rotate( centre, rotation );
796  text->Move( translation );
797  break;
798  }
799  case PCB_MODULE_EDGE_T:
800  {
801  EDGE_MODULE* em = static_cast<EDGE_MODULE*>( item );
802  em->Rotate( centre, rotation );
803  em->Move( translation );
804  break;
805  }
806  default:
807  ;
808  }
809  }
810 
811  ClearMarkItems( module );
812 }
813 
814 
815 /* Mark items inside rect.
816  * Items are inside rect when an end point is inside rect
817  */
818 int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
819 {
820  EDA_ITEM* item;
821  int ItemsCount = 0;
822  wxPoint pos;
823  D_PAD* pad;
824 
825  if( module == NULL )
826  return 0;
827 
828  ClearMarkItems( module ); // Just in case ...
829 
830  pos = module->Reference().GetTextPos();
831 
832  if( Rect.Contains( pos ) )
833  {
834  module->Reference().SetFlags( SELECTED );
835  ItemsCount++;
836  }
837 
838  pos = module->Value().GetTextPos();
839 
840  if( Rect.Contains( pos ) )
841  {
842  module->Value().SetFlags( SELECTED );
843  ItemsCount++;
844  }
845 
846  pad = module->PadsList();
847 
848  for( ; pad != NULL; pad = pad->Next() )
849  {
850  pad->ClearFlags( SELECTED );
851  pos = pad->GetPosition();
852 
853  if( Rect.Contains( pos ) )
854  {
855  pad->SetFlags( SELECTED );
856  ItemsCount++;
857  }
858  }
859 
860  item = module->GraphicalItemsList();
861 
862  for( ; item != NULL; item = item->Next() )
863  {
864  item->ClearFlags( SELECTED );
865 
866  switch( item->Type() )
867  {
868  case PCB_MODULE_EDGE_T:
869  if( ((EDGE_MODULE*)item )->HitTest( Rect ) )
870  {
871  item->SetFlags( SELECTED );
872  ItemsCount++;
873  }
874 
875  break;
876 
877  case PCB_MODULE_TEXT_T:
878  pos = static_cast<TEXTE_MODULE*>( item )->GetTextPos();
879 
880  if( Rect.Contains( pos ) )
881  {
882  item->SetFlags( SELECTED );
883  ItemsCount++;
884  }
885 
886  break;
887 
888  default:
889  break;
890  }
891  }
892 
893  return ItemsCount;
894 }
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:577
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:503
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:1215
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:502
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)
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:243
virtual void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
int GetToolId() const
Definition: draw_frame.h:526
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