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 <config_params.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 594 of file block_module_editor.cpp.

References ClearMarkItems(), MODULE::GraphicalItemsList(), EDA_ITEM::IsSelected(), TEXTE_MODULE::Mirror(), Mirror(), BOARD_ITEM::Next(), D_PAD::Next(), MODULE::PadsList(), 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().

595 {
596 #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
597  wxPoint tmp;
598  wxSize tmpz;
599 
600  if( module == NULL )
601  return;
602 
603  if( module->Reference().IsSelected() || force_all )
604  module->Reference().Mirror( offset, false );
605 
606  if( module->Value().IsSelected() || force_all )
607  module->Value().Mirror( offset, false );
608 
609  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
610  {
611  // Skip pads not selected, i.e. not inside the block to mirror:
612  if( !pad->IsSelected() && !force_all )
613  continue;
614 
615  tmp = pad->GetPosition();
616  SETMIRROR( tmp.x );
617  pad->SetPosition( tmp );
618 
619  pad->SetX0( pad->GetPosition().x );
620 
621  tmp = pad->GetOffset();
622  tmp.x = -tmp.x;
623  pad->SetOffset( tmp );
624 
625  tmpz = pad->GetDelta();
626  tmpz.x = -tmpz.x;
627  pad->SetDelta( tmpz );
628 
629  pad->SetOrientation( - pad->GetOrientation() );
630  }
631 
632  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
633  {
634  // Skip items not selected, i.e. not inside the block to mirror:
635  if( !item->IsSelected() && !force_all )
636  continue;
637 
638  switch( item->Type() )
639  {
640  case PCB_MODULE_EDGE_T:
641  ((EDGE_MODULE*) item)->Mirror( offset, false );
642  break;
643 
644  case PCB_MODULE_TEXT_T:
645  static_cast<TEXTE_MODULE*>( item )->Mirror( offset, false );
646  break;
647 
648  default:
649  break;
650  }
651  }
652 
653  ClearMarkItems( module );
654 }
TEXTE_MODULE & Reference()
Definition: class_module.h:463
bool IsSelected() const
Definition: base_struct.h:235
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:462
D_PAD * Next() const
Definition: class_pad.h:146
#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:165
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< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
void MoveMarkedItemsExactly ( MODULE module,
const wxPoint centre,
const wxPoint translation,
double  rotation,
bool  force_all = false 
)

Definition at line 735 of file block_module_editor.cpp.

References ClearMarkItems(), D_PAD::GetPosition(), MODULE::GraphicalItemsList(), EDA_ITEM::IsSelected(), EDGE_MODULE::Move(), TEXTE_MODULE::Move(), D_PAD::Next(), EDA_ITEM::Next(), MODULE::PadsList(), 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().

738 {
739  if( module == NULL )
740  return;
741 
742  if( module->Reference().IsSelected() || force_all )
743  {
744  module->Reference().Rotate( centre, rotation );
745  module->Reference().Move( translation );
746  }
747 
748  if( module->Value().IsSelected() || force_all )
749  {
750  module->Value().Rotate( centre, rotation );
751  module->Value().Move( translation );
752  }
753 
754  D_PAD* pad = module->PadsList();
755 
756  for( ; pad != NULL; pad = pad->Next() )
757  {
758  if( !pad->IsSelected() && !force_all )
759  continue;
760 
761  // rotate about centre point,
762  wxPoint newPos = pad->GetPosition();
763  RotatePoint( &newPos, centre, rotation );
764 
765  // shift and update
766  newPos += translation;
767  pad->SetPosition( newPos );
768  pad->SetPos0( newPos );
769 
770  // finally apply rotation to the pad itself
771  pad->Rotate( newPos, rotation );
772  }
773 
774  EDA_ITEM* item = module->GraphicalItemsList();
775 
776  for( ; item != NULL; item = item->Next() )
777  {
778  if( !item->IsSelected() && !force_all )
779  continue;
780 
781  switch( item->Type() )
782  {
783  case PCB_MODULE_TEXT_T:
784  {
785  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
786 
787  text->Rotate( centre, rotation );
788  text->Move( translation );
789  break;
790  }
791  case PCB_MODULE_EDGE_T:
792  {
793  EDGE_MODULE* em = static_cast<EDGE_MODULE*>( item );
794  em->Rotate( centre, rotation );
795  em->Move( translation );
796  break;
797  }
798  default:
799  ;
800  }
801  }
802 
803  ClearMarkItems( module );
804 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
TEXTE_MODULE & Reference()
Definition: class_module.h:463
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:1119
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:235
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:205
EDA_ITEM * Next() const
Definition: base_struct.h:220
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate an edge of the footprint.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:462
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:248
const wxPoint & GetPosition() const override
Definition: class_pad.h:206
D_PAD * Next() const
Definition: class_pad.h:146
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:165
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
DLIST< D_PAD > & PadsList()
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 661 of file block_module_editor.cpp.

References ClearMarkItems(), MODULE::GraphicalItemsList(), EDA_ITEM::IsSelected(), BOARD_ITEM::Next(), D_PAD::Next(), MODULE::PadsList(), 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().

662 {
663 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
664 
665  if( module == NULL )
666  return;
667 
668  if( module->Reference().IsSelected() || force_all )
669  module->Reference().Rotate( offset, 900 );
670 
671  if( module->Value().IsSelected() || force_all )
672  module->Value().Rotate( offset, 900 );
673 
674  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
675  {
676  if( !pad->IsSelected() && !force_all )
677  continue;
678 
679  wxPoint pos = pad->GetPos0();
680  ROTATE( pos );
681  pad->SetPos0( pos );
682  pad->SetOrientation( pad->GetOrientation() + 900 );
683 
684  pad->SetDrawCoord();
685  }
686 
687  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
688  {
689  if( !item->IsSelected() && !force_all )
690  continue;
691 
692  switch( item->Type() )
693  {
694  case PCB_MODULE_EDGE_T:
695  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
696  break;
697 
698  case PCB_MODULE_TEXT_T:
699  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
700  break;
701 
702  default:
703  break;
704  }
705  }
706 
707  ClearMarkItems( module );
708 }
TEXTE_MODULE & Reference()
Definition: class_module.h:463
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:235
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:462
D_PAD * Next() const
Definition: class_pad.h:146
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:165
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
#define ROTATE(z)