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 616 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().

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 }
TEXTE_MODULE & Reference()
Definition: class_module.h:452
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:451
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 757 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().

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 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
TEXTE_MODULE & Reference()
Definition: class_module.h:452
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:1077
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:451
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 683 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().

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 }
TEXTE_MODULE & Reference()
Definition: class_module.h:452
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:451
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)