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

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

630 {
631  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
632 
633  aPad.SetPosition( tmpPt );
634 
635  aPad.SetX0( aPad.GetPosition().x );
636 
637  tmpPt = aPad.GetOffset();
638  tmpPt.x = -tmpPt.x;
639  aPad.SetOffset( tmpPt );
640 
641  auto tmpz = aPad.GetDelta();
642  tmpz.x = -tmpz.x;
643  aPad.SetDelta( tmpz );
644 
645  aPad.SetOrientation( -aPad.GetOrientation() );
646 }
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
const wxSize & GetDelta() const
Definition: class_pad.h:185
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:614
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:357
void SetX0(int x)
Definition: class_pad.h:179
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:190
const wxPoint & GetOffset() const
Definition: class_pad.h:191
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:184
static wxPoint mirrorPointX ( const wxPoint aPoint,
const wxPoint aMirrorPoint 
)
static

Mirror a point about the vertical axis passing through another point

Definition at line 614 of file edit_tool.cpp.

References wxPoint::x.

Referenced by mirrorPadX().

615 {
616  wxPoint mirrored = aPoint;
617 
618  mirrored.x -= aMirrorPoint.x;
619  mirrored.x = -mirrored.x;
620  mirrored.x += aMirrorPoint.x;
621 
622  return mirrored;
623 }