KiCad PCB EDA Suite
edit_tool.cpp File Reference
#include <limits>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <class_zone.h>
#include <collectors.h>
#include <wxPcbStruct.h>
#include <kiway.h>
#include <class_draw_panel_gal.h>
#include <module_editor_frame.h>
#include <array_creator.h>
#include <pcbnew_id.h>
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <view/view.h>
#include <gal/graphics_abstraction_layer.h>
#include <connectivity_data.h>
#include <confirm.h>
#include <bitmaps.h>
#include <hotkeys.h>
#include <cassert>
#include <functional>
#include "pcb_actions.h"
#include "selection_tool.h"
#include "edit_tool.h"
#include "picker_tool.h"
#include "grid_helper.h"
#include "kicad_clipboard.h"
#include "pcbnew_control.h"
#include <router/router_tool.h>
#include <dialogs/dialog_move_exact.h>
#include <dialogs/dialog_track_via_properties.h>
#include <dialogs/dialog_exchange_modules.h>
#include <tools/tool_event_utils.h>
#include <preview_items/ruler_item.h>
#include <board_commit.h>

Go to the source code of this file.

Classes

class  GAL_ARRAY_CREATOR
 

Functions

static wxPoint getAnchorPoint (const SELECTION &selection, const MOVE_PARAMETERS &params)
 
static wxPoint mirrorPointX (const wxPoint &aPoint, const wxPoint &aMirrorPoint)
 
static void mirrorPadX (D_PAD &aPad, const wxPoint &aMirrorPoint)
 Mirror a pad in the vertical axis passing through a point. More...
 

Function Documentation

static wxPoint getAnchorPoint ( const SELECTION selection,
const MOVE_PARAMETERS params 
)
static

Definition at line 177 of file edit_tool.cpp.

References MOVE_PARAMETERS::anchor, ANCHOR_CENTER_FOOTPRINT, ANCHOR_FROM_LIBRARY, ANCHOR_TOP_LEFT_PAD, EDA_ITEM::GetBoundingBox(), EDA_RECT::GetCenter(), SELECTION::GetCenter(), MODULE::GetFootprintRect(), BOARD_ITEM::GetPosition(), EDA_RECT::GetPosition(), MODULE::GetPosition(), SELECTION::GetSize(), SELECTION::GetTopLeftItem(), SELECTION::GetTopLeftModule(), MODULE::GetTopLeftPad(), mod, MOVE_PARAMETERS::origin, PAD_ATTRIB_SMD, PCB_MODULE_T, PCB_PAD_T, RELATIVE_TO_CURRENT_POSITION, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDIT_TOOL::MoveExact().

178 {
179  wxPoint anchorPoint;
180 
181  if( params.origin == RELATIVE_TO_CURRENT_POSITION )
182  {
183  return wxPoint( 0, 0 );
184  }
185 
186  // set default anchor
187  VECTOR2I rp = selection.GetCenter();
188  anchorPoint = wxPoint( rp.x, rp.y );
189 
190  // If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override.
191  // Also run through this block if only one item is slected because it may be a module,
192  // in which case we want something different than the center of the selection
193  if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) )
194  {
195  BOARD_ITEM* topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftModule() );
196 
197  // no module found if the GetTopLeftModule() returns null
198  if( topLeftItem != nullptr )
199  {
200  if( topLeftItem->Type() == PCB_MODULE_T )
201  {
202  // Cast to module to allow access to the pads
203  MODULE* mod = static_cast<MODULE*>( topLeftItem );
204 
205  switch( params.anchor )
206  {
207  case ANCHOR_FROM_LIBRARY:
208  anchorPoint = mod->GetPosition();
209  break;
210 
211  case ANCHOR_TOP_LEFT_PAD:
212  topLeftItem = mod->GetTopLeftPad();
213  break;
214 
216  anchorPoint = mod->GetFootprintRect().GetCenter();
217  break;
218  }
219  }
220 
221  if( topLeftItem->Type() == PCB_PAD_T )
222  {
223  if( static_cast<D_PAD*>( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD )
224  {
225  // Use the top left corner of SMD pads as an anchor instead of the center
226  anchorPoint = topLeftItem->GetBoundingBox().GetPosition();
227  }
228  else
229  {
230  anchorPoint = topLeftItem->GetPosition();
231  }
232  }
233  }
234  else // no module found in the selection
235  {
236  // in a selection of non-modules
237  if( params.anchor == ANCHOR_TOP_LEFT_PAD )
238  {
239  // approach the top left pad override for non-modules by using the position of
240  // the topleft item as an anchor
241  topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
242  anchorPoint = topLeftItem->GetPosition();
243  }
244  }
245  }
246 
247  return anchorPoint;
248 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
const wxPoint & GetPosition() const override
Definition: class_module.h:175
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
MOVE_EXACT_ORIGIN origin
virtual const wxPoint & GetPosition() const =0
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class MODULE, a footprint
Definition: typeinfo.h:89
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text...
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const
Definition: selection.cpp:90
D_PAD * GetTopLeftPad()
const wxPoint & GetPosition() const
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:86
VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:67
EDA_ITEM * GetTopLeftModule() const
Definition: selection.cpp:126
MOVE_EXACT_ANCHOR anchor
#define mod(a, n)
Definition: greymap.cpp:24
const wxPoint GetCenter() const
static void mirrorPadX ( D_PAD aPad,
const wxPoint aMirrorPoint 
)
static

Mirror a pad in the vertical axis passing through a point.

Definition at line 715 of file edit_tool.cpp.

References D_PAD::GetDelta(), D_PAD::GetOffset(), D_PAD::GetOrientation(), D_PAD::GetPosition(), mirrorPointX(), D_PAD::SetDelta(), D_PAD::SetOffset(), D_PAD::SetOrientation(), D_PAD::SetPosition(), D_PAD::SetX0(), and wxPoint::x.

Referenced by EDIT_TOOL::Mirror().

716 {
717  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
718 
719  aPad.SetPosition( tmpPt );
720 
721  aPad.SetX0( aPad.GetPosition().x );
722 
723  tmpPt = aPad.GetOffset();
724  tmpPt.x = -tmpPt.x;
725  aPad.SetOffset( tmpPt );
726 
727  auto tmpz = aPad.GetDelta();
728  tmpz.x = -tmpz.x;
729  aPad.SetDelta( tmpz );
730 
731  aPad.SetOrientation( -aPad.GetOrientation() );
732 }
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
const wxPoint & GetPosition() const override
Definition: class_pad.h:220
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:375
const wxSize & GetDelta() const
Definition: class_pad.h:272
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:700
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:401
void SetX0(int x)
Definition: class_pad.h:266
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:277
const wxPoint & GetOffset() const
Definition: class_pad.h:278
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:271
static wxPoint mirrorPointX ( const wxPoint aPoint,
const wxPoint aMirrorPoint 
)
static

Mirror a point about the vertical axis passing through another point

Definition at line 700 of file edit_tool.cpp.

References wxPoint::x.

Referenced by mirrorPadX().

701 {
702  wxPoint mirrored = aPoint;
703 
704  mirrored.x -= aMirrorPoint.x;
705  mirrored.x = -mirrored.x;
706  mirrored.x += aMirrorPoint.x;
707 
708  return mirrored;
709 }