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.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 "grid_helper.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 164 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().

165 {
166  wxPoint anchorPoint;
167 
168  if( params.origin == RELATIVE_TO_CURRENT_POSITION )
169  {
170  return wxPoint( 0, 0 );
171  }
172 
173  // set default anchor
174  VECTOR2I rp = selection.GetCenter();
175  anchorPoint = wxPoint( rp.x, rp.y );
176 
177  // If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override.
178  // Also run through this block if only one item is slected because it may be a module,
179  // in which case we want something different than the center of the selection
180  if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) )
181  {
182  BOARD_ITEM* topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftModule() );
183 
184  // no module found if the GetTopLeftModule() returns null
185  if( topLeftItem != nullptr )
186  {
187  if( topLeftItem->Type() == PCB_MODULE_T )
188  {
189  // Cast to module to allow access to the pads
190  MODULE* mod = static_cast<MODULE*>( topLeftItem );
191 
192  switch( params.anchor )
193  {
194  case ANCHOR_FROM_LIBRARY:
195  anchorPoint = mod->GetPosition();
196  break;
197 
198  case ANCHOR_TOP_LEFT_PAD:
199  topLeftItem = mod->GetTopLeftPad();
200  break;
201 
203  anchorPoint = mod->GetFootprintRect().GetCenter();
204  break;
205  }
206  }
207 
208  if( topLeftItem->Type() == PCB_PAD_T )
209  {
210  if( static_cast<D_PAD*>( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD )
211  {
212  // Use the top left corner of SMD pads as an anchor instead of the center
213  anchorPoint = topLeftItem->GetBoundingBox().GetPosition();
214  }
215  else
216  {
217  anchorPoint = topLeftItem->GetPosition();
218  }
219  }
220  }
221  else // no module found in the selection
222  {
223  // in a selection of non-modules
224  if( params.anchor == ANCHOR_TOP_LEFT_PAD )
225  {
226  // approach the top left pad override for non-modules by using the position of
227  // the topleft item as an anchor
228  topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
229  anchorPoint = topLeftItem->GetPosition();
230  }
231  }
232  }
233 
234  return anchorPoint;
235 }
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:155
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:102
class MODULE, a footprint
Definition: typeinfo.h:101
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text...
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const
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.
EDA_ITEM * GetTopLeftModule() const
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 694 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().

695 {
696  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
697 
698  aPad.SetPosition( tmpPt );
699 
700  aPad.SetX0( aPad.GetPosition().x );
701 
702  tmpPt = aPad.GetOffset();
703  tmpPt.x = -tmpPt.x;
704  aPad.SetOffset( tmpPt );
705 
706  auto tmpz = aPad.GetDelta();
707  tmpz.x = -tmpz.x;
708  aPad.SetDelta( tmpz );
709 
710  aPad.SetOrientation( -aPad.GetOrientation() );
711 }
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:204
const wxPoint & GetPosition() const override
Definition: class_pad.h:205
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:357
const wxSize & GetDelta() const
Definition: class_pad.h:257
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:679
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:251
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:262
const wxPoint & GetOffset() const
Definition: class_pad.h:263
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:256
static wxPoint mirrorPointX ( const wxPoint aPoint,
const wxPoint aMirrorPoint 
)
static

Mirror a point about the vertical axis passing through another point

Definition at line 679 of file edit_tool.cpp.

References wxPoint::x.

Referenced by mirrorPadX().

680 {
681  wxPoint mirrored = aPoint;
682 
683  mirrored.x -= aMirrorPoint.x;
684  mirrored.x = -mirrored.x;
685  mirrored.x += aMirrorPoint.x;
686 
687  return mirrored;
688 }