KiCad PCB EDA Suite
footprint_editor_utils.cpp File Reference
#include <fctsys.h>
#include <kiface_i.h>
#include <kiway.h>
#include <kiway_express.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 <kicad_device_context.h>
#include <macros.h>
#include <invoke_pcb_dialog.h>
#include <pcb_layer_widget.h>
#include <board_commit.h>
#include <view/view.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 <footprint_edit_frame.h>
#include <footprint_viewer_frame.h>
#include <footprint_tree_pane.h>
#include <fp_lib_table.h>
#include <widgets/lib_tree.h>
#include <collectors.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <dialog_edit_footprint_for_fp_editor.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 597 of file block_footprint_editor.cpp.

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

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

Definition at line 738 of file block_footprint_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().

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

665 {
666 #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
667 
668  if( module == NULL )
669  return;
670 
671  if( module->Reference().IsSelected() || force_all )
672  module->Reference().Rotate( offset, 900 );
673 
674  if( module->Value().IsSelected() || force_all )
675  module->Value().Rotate( offset, 900 );
676 
677  for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
678  {
679  if( !pad->IsSelected() && !force_all )
680  continue;
681 
682  wxPoint pos = pad->GetPos0();
683  ROTATE( pos );
684  pad->SetPos0( pos );
685  pad->SetOrientation( pad->GetOrientation() + 900 );
686 
687  pad->SetDrawCoord();
688  }
689 
690  for( EDA_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() )
691  {
692  if( !item->IsSelected() && !force_all )
693  continue;
694 
695  switch( item->Type() )
696  {
697  case PCB_MODULE_EDGE_T:
698  ((EDGE_MODULE*) item)->Rotate( offset, 900 );
699  break;
700 
701  case PCB_MODULE_TEXT_T:
702  static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
703  break;
704 
705  default:
706  break;
707  }
708  }
709 
710  ClearMarkItems( module );
711 }
TEXTE_MODULE & Reference()
Definition: class_module.h:513
static void ClearMarkItems(MODULE *module)
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:224
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
BOARD_ITEM * Next() const
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:512
D_PAD * Next() const
Definition: class_pad.h:160
#define ROTATE(z)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:166
DLIST< D_PAD > & PadsList()
Definition: class_module.h:163