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