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

618 {
619 #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
620  wxPoint tmp;
621  wxSize tmpz;
622 
623  if( module == NULL )
624  return;
625 
626  if( module->Reference().IsSelected() || force_all )
627  module->Reference().Mirror( offset, false );
628 
629  if( module->Value().IsSelected() || force_all )
630  module->Value().Mirror( offset, false );
631 
632  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
633  {
634  // Skip pads not selected, i.e. not inside the block to mirror:
635  if( !pad->IsSelected() && !force_all )
636  continue;
637 
638  tmp = pad->GetPosition();
639  SETMIRROR( tmp.x );
640  pad->SetPosition( tmp );
641 
642  pad->SetX0( pad->GetPosition().x );
643 
644  tmp = pad->GetOffset();
645  tmp.x = -tmp.x;
646  pad->SetOffset( tmp );
647 
648  tmpz = pad->GetDelta();
649  tmpz.x = -tmpz.x;
650  pad->SetDelta( tmpz );
651 
652  pad->SetOrientation( - pad->GetOrientation() );
653  }
654 
655  for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
656  {
657  // Skip items not selected, i.e. not inside the block to mirror:
658  if( !item->IsSelected() && !force_all )
659  continue;
660 
661  switch( item->Type() )
662  {
663  case PCB_MODULE_EDGE_T:
664  ((EDGE_MODULE*) item)->Mirror( offset, false );
665  break;
666 
667  case PCB_MODULE_TEXT_T:
668  static_cast<TEXTE_MODULE*>( item )->Mirror( offset, false );
669  break;
670 
671  default:
672  break;
673  }
674  }
675 
676  ClearMarkItems( module );
677 }
TEXTE_MODULE & Reference()
Definition: class_module.h:456
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:137
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
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:134
void MoveMarkedItemsExactly ( MODULE module,
const wxPoint centre,
const wxPoint translation,
double  rotation,
bool  force_all = false 
)

Definition at line 758 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().

761 {
762  if( module == NULL )
763  return;
764 
765  if( module->Reference().IsSelected() || force_all )
766  {
767  module->Reference().Rotate( centre, rotation );
768  module->Reference().Move( translation );
769  }
770 
771  if( module->Value().IsSelected() || force_all )
772  {
773  module->Value().Rotate( centre, rotation );
774  module->Value().Move( translation );
775  }
776 
777  D_PAD* pad = module->Pads();
778 
779  for( ; pad != NULL; pad = pad->Next() )
780  {
781  if( !pad->IsSelected() && !force_all )
782  continue;
783 
784  // rotate about centre point,
785  wxPoint newPos = pad->GetPosition();
786  RotatePoint( &newPos, centre, rotation );
787 
788  // shift and update
789  newPos += translation;
790  pad->SetPosition( newPos );
791  pad->SetPos0( newPos );
792 
793  // finally apply rotation to the pad itself
794  pad->Rotate( newPos, rotation );
795  }
796 
797  EDA_ITEM* item = module->GraphicalItems();
798 
799  for( ; item != NULL; item = item->Next() )
800  {
801  if( !item->IsSelected() && !force_all )
802  continue;
803 
804  switch( item->Type() )
805  {
806  case PCB_MODULE_TEXT_T:
807  {
808  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
809 
810  text->Rotate( centre, rotation );
811  text->Move( translation );
812  break;
813  }
814  case PCB_MODULE_EDGE_T:
815  {
816  EDGE_MODULE* em = static_cast<EDGE_MODULE*>( item );
817  em->Rotate( centre, rotation );
818  em->Move( translation );
819  break;
820  }
821  default:
822  ;
823  }
824  }
825 
826  ClearMarkItems( module );
827 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
TEXTE_MODULE & Reference()
Definition: class_module.h:456
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:137
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
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:134
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 684 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().

685 {
686 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
687 
688  if( module == NULL )
689  return;
690 
691  if( module->Reference().IsSelected() || force_all )
692  module->Reference().Rotate( offset, 900 );
693 
694  if( module->Value().IsSelected() || force_all )
695  module->Value().Rotate( offset, 900 );
696 
697  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
698  {
699  if( !pad->IsSelected() && !force_all )
700  continue;
701 
702  wxPoint pos = pad->GetPos0();
703  ROTATE( pos );
704  pad->SetPos0( pos );
705  pad->SetOrientation( pad->GetOrientation() + 900 );
706 
707  pad->SetDrawCoord();
708  }
709 
710  for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
711  {
712  if( !item->IsSelected() && !force_all )
713  continue;
714 
715  switch( item->Type() )
716  {
717  case PCB_MODULE_EDGE_T:
718  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
719  break;
720 
721  case PCB_MODULE_TEXT_T:
722  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
723  break;
724 
725  default:
726  break;
727  }
728  }
729 
730  ClearMarkItems( module );
731 }
TEXTE_MODULE & Reference()
Definition: class_module.h:456
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:137
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
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:134
#define ROTATE(z)