KiCad PCB EDA Suite
modedit.cpp File Reference
#include <fctsys.h>
#include <kiface_i.h>
#include <kiway.h>
#include <class_drawpanel.h>
#include <pcb_draw_panel_gal.h>
#include <confirm.h>
#include <gestfich.h>
#include <pgm_base.h>
#include <trigo.h>
#include <3d_viewer/eda_3d_viewer.h>
#include <wxPcbStruct.h>
#include <kicad_device_context.h>
#include <macros.h>
#include <invoke_pcb_dialog.h>
#include <class_pcb_layer_widget.h>
#include <board_commit.h>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <ratsnest_data.h>
#include <pcbnew.h>
#include <protos.h>
#include <pcbnew_id.h>
#include <module_editor_frame.h>
#include <modview_frame.h>
#include <collectors.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <dialog_edit_module_for_Modedit.h>
#include <dialog_move_exact.h>
#include <dialog_create_array.h>
#include <wildcards_and_files_ext.h>
#include <menus_helpers.h>
#include <footprint_wizard_frame.h>
#include <pcbnew_config.h>
#include <functional>

Go to the source code of this file.

Functions

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 in global transform, if force_all is true, all items will be mirrored. More...
 
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 in global transform, if force_all is true, all items will be rotated. More...
 
void MoveMarkedItemsExactly (MODULE *module, const wxPoint &centre, const wxPoint &translation, double rotation, bool force_all=false)
 

Function Documentation

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 in global transform, if force_all is true, all items will be mirrored.

Definition at line 584 of file block_module_editor.cpp.

References ClearMarkItems(), MODULE::GraphicalItems(), EDA_ITEM::IsSelected(), TEXTE_MODULE::Mirror(), Mirror(), D_PAD::Next(), BOARD_ITEM::Next(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, MODULE::Reference(), SETMIRROR, MODULE::Value(), and wxPoint::x.

Referenced by FOOTPRINT_EDIT_FRAME::HandleBlockEnd(), FOOTPRINT_EDIT_FRAME::HandleBlockPlace(), and FOOTPRINT_EDIT_FRAME::Transform().

585 {
586 #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
587  wxPoint tmp;
588  wxSize tmpz;
589 
590  if( module == NULL )
591  return;
592 
593  if( module->Reference().IsSelected() || force_all )
594  module->Reference().Mirror( offset, false );
595 
596  if( module->Value().IsSelected() || force_all )
597  module->Value().Mirror( offset, false );
598 
599  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
600  {
601  // Skip pads not selected, i.e. not inside the block to mirror:
602  if( !pad->IsSelected() && !force_all )
603  continue;
604 
605  tmp = pad->GetPosition();
606  SETMIRROR( tmp.x );
607  pad->SetPosition( tmp );
608 
609  pad->SetX0( pad->GetPosition().x );
610 
611  tmp = pad->GetOffset();
612  tmp.x = -tmp.x;
613  pad->SetOffset( tmp );
614 
615  tmpz = pad->GetDelta();
616  tmpz.x = -tmpz.x;
617  pad->SetDelta( tmpz );
618 
619  pad->SetOrientation( - pad->GetOrientation() );
620  }
621 
622  for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
623  {
624  // Skip items not selected, i.e. not inside the block to mirror:
625  if( !item->IsSelected() && !force_all )
626  continue;
627 
628  switch( item->Type() )
629  {
630  case PCB_MODULE_EDGE_T:
631  ((EDGE_MODULE*) item)->Mirror( offset, false );
632  break;
633 
634  case PCB_MODULE_TEXT_T:
635  static_cast<TEXTE_MODULE*>( item )->Mirror( offset, false );
636  break;
637 
638  default:
639  break;
640  }
641  }
642 
643  ClearMarkItems( module );
644 }
TEXTE_MODULE & Reference()
Definition: class_module.h:455
bool IsSelected() const
Definition: base_struct.h:221
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
D_PAD * Next() const
Definition: class_pad.h:106
#define SETMIRROR(z)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
static void ClearMarkItems(MODULE *module)
T Mirror(T aPoint, T aMirrorRef)
Function MIRROR Mirror aPoint in aMirrorRef.
Definition: macros.h:106
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror text position in footprint edition the text itself is not mirrored, and the layer not modified...
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
void MoveMarkedItemsExactly ( MODULE module,
const wxPoint centre,
const wxPoint translation,
double  rotation,
bool  force_all = false 
)

Definition at line 725 of file block_module_editor.cpp.

References ClearMarkItems(), D_PAD::GetPosition(), MODULE::GraphicalItems(), EDA_ITEM::IsSelected(), EDGE_MODULE::Move(), TEXTE_MODULE::Move(), D_PAD::Next(), EDA_ITEM::Next(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, MODULE::Reference(), EDGE_MODULE::Rotate(), TEXTE_MODULE::Rotate(), D_PAD::Rotate(), RotatePoint(), D_PAD::SetPos0(), D_PAD::SetPosition(), EDA_ITEM::Type(), and MODULE::Value().

Referenced by FOOTPRINT_EDIT_FRAME::HandleBlockEnd(), and FOOTPRINT_EDIT_FRAME::Transform().

728 {
729  if( module == NULL )
730  return;
731 
732  if( module->Reference().IsSelected() || force_all )
733  {
734  module->Reference().Rotate( centre, rotation );
735  module->Reference().Move( translation );
736  }
737 
738  if( module->Value().IsSelected() || force_all )
739  {
740  module->Value().Rotate( centre, rotation );
741  module->Value().Move( translation );
742  }
743 
744  D_PAD* pad = module->Pads();
745 
746  for( ; pad != NULL; pad = pad->Next() )
747  {
748  if( !pad->IsSelected() && !force_all )
749  continue;
750 
751  // rotate about centre point,
752  wxPoint newPos = pad->GetPosition();
753  RotatePoint( &newPos, centre, rotation );
754 
755  // shift and update
756  newPos += translation;
757  pad->SetPosition( newPos );
758  pad->SetPos0( newPos );
759 
760  // finally apply rotation to the pad itself
761  pad->Rotate( newPos, rotation );
762  }
763 
764  EDA_ITEM* item = module->GraphicalItems();
765 
766  for( ; item != NULL; item = item->Next() )
767  {
768  if( !item->IsSelected() && !force_all )
769  continue;
770 
771  switch( item->Type() )
772  {
773  case PCB_MODULE_TEXT_T:
774  {
775  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
776 
777  text->Rotate( centre, rotation );
778  text->Move( translation );
779  break;
780  }
781  case PCB_MODULE_EDGE_T:
782  {
783  EDGE_MODULE* em = static_cast<EDGE_MODULE*>( item );
784  em->Rotate( centre, rotation );
785  em->Move( translation );
786  break;
787  }
788  default:
789  ;
790  }
791  }
792 
793  ClearMarkItems( module );
794 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
TEXTE_MODULE & Reference()
Definition: class_module.h:455
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:836
void Rotate(const wxPoint &aOffset, double aAngle) override
Rotate text, in footprint editor (for instance in footprint rotation transform)
void Move(const wxPoint &aMoveVector) override
move text in move transform, in footprint editor
bool IsSelected() const
Definition: base_struct.h:221
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
EDA_ITEM * Next() const
Definition: base_struct.h:206
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:175
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
D_PAD * Next() const
Definition: class_pad.h:106
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
static void ClearMarkItems(MODULE *module)
void Move(const wxPoint &aMoveVector) override
Move an edge of the footprint.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
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 in global transform, if force_all is true, all items will be rotated.

Definition at line 651 of file block_module_editor.cpp.

References ClearMarkItems(), MODULE::GraphicalItems(), EDA_ITEM::IsSelected(), D_PAD::Next(), BOARD_ITEM::Next(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, MODULE::Reference(), TEXTE_MODULE::Rotate(), ROTATE, and MODULE::Value().

Referenced by FOOTPRINT_EDIT_FRAME::HandleBlockEnd(), FOOTPRINT_EDIT_FRAME::HandleBlockPlace(), and FOOTPRINT_EDIT_FRAME::Transform().

652 {
653 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
654 
655  if( module == NULL )
656  return;
657 
658  if( module->Reference().IsSelected() || force_all )
659  module->Reference().Rotate( offset, 900 );
660 
661  if( module->Value().IsSelected() || force_all )
662  module->Value().Rotate( offset, 900 );
663 
664  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
665  {
666  if( !pad->IsSelected() && !force_all )
667  continue;
668 
669  wxPoint pos = pad->GetPos0();
670  ROTATE( pos );
671  pad->SetPos0( pos );
672  pad->SetOrientation( pad->GetOrientation() + 900 );
673 
674  pad->SetDrawCoord();
675  }
676 
677  for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
678  {
679  if( !item->IsSelected() && !force_all )
680  continue;
681 
682  switch( item->Type() )
683  {
684  case PCB_MODULE_EDGE_T:
685  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
686  break;
687 
688  case PCB_MODULE_TEXT_T:
689  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
690  break;
691 
692  default:
693  break;
694  }
695  }
696 
697  ClearMarkItems( module );
698 }
TEXTE_MODULE & Reference()
Definition: class_module.h:455
void Rotate(const wxPoint &aOffset, double aAngle) override
Rotate text, in footprint editor (for instance in footprint rotation transform)
bool IsSelected() const
Definition: base_struct.h:221
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:454
D_PAD * Next() const
Definition: class_pad.h:106
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
static void ClearMarkItems(MODULE *module)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
#define ROTATE(z)