KiCad PCB EDA Suite
dragsegm.cpp File Reference

Classes to find track segments connected to a pad or a module for drag commands. More...

#include <fctsys.h>
#include <common.h>
#include <trigo.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxBasePcbFrame.h>
#include <macros.h>
#include <drag.h>
#include <pcbnew.h>
#include <class_module.h>
#include <class_board.h>
#include <connect.h>

Go to the source code of this file.

Functions

bool sortPadsByXthenYCoord (D_PAD *const &ref, D_PAD *const &comp)
 Function SortPadsByXCoord is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value. More...
 
bool sort_tracklist (const DRAG_SEGM_PICKER &ref, const DRAG_SEGM_PICKER &tst)
 
void DrawSegmentWhileMovingFootprint (EDA_DRAW_PANEL *panel, wxDC *DC)
 
void EraseDragList ()
 Function EraseDragList clear the .m_Flags of all track segments stored in g_DragSegmentList and clear the list. More...
 
void AddSegmentToDragList (int flag, TRACK *aTrack)
 
void Collect_TrackSegmentsToDrag (BOARD *aPcb, const wxPoint &aRefPos, LSET aLayerMask, int aNetCode, int aMaxDist)
 Function Collect_TrackSegmentsToDrag. More...
 
void UndrawAndMarkSegmentsToDrag (EDA_DRAW_PANEL *aCanvas, wxDC *aDC)
 

Variables

std::vector< DRAG_SEGM_PICKERg_DragSegmentList
 

Detailed Description

Classes to find track segments connected to a pad or a module for drag commands.

Definition in file dragsegm.cpp.

Function Documentation

void AddSegmentToDragList ( int  flag,
TRACK aTrack 
)

Definition at line 318 of file dragsegm.cpp.

References ENDPOINT, g_DragSegmentList, DRAG_SEGM_PICKER::m_TempFlags, EDA_ITEM::SetFlags(), and STARTPOINT.

Referenced by Collect_TrackSegmentsToDrag(), PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope(), and PCB_EDIT_FRAME::StartMoveOneNodeOrSegment().

319 {
320  DRAG_SEGM_PICKER wrapper( aTrack );
321 
322  if( flag & STARTPOINT )
323  {
324  wrapper.m_TempFlags |= STARTPOINT;
325  aTrack->SetFlags( STARTPOINT );
326  }
327 
328  if( flag & ENDPOINT )
329  {
330  wrapper.m_TempFlags |= ENDPOINT;
331  aTrack->SetFlags( ENDPOINT );
332  }
333 
334  g_DragSegmentList.push_back( wrapper );
335 }
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
#define ENDPOINT
Definition: base_struct.h:119
Helper classes to handle a list of track segments to drag and has info to undo/abort the move command...
Definition: drag.h:58
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
#define STARTPOINT
Definition: base_struct.h:118
void Collect_TrackSegmentsToDrag ( BOARD aPcb,
const wxPoint aRefPos,
LSET  aLayerMask,
int  aNetCode,
int  aMaxDist 
)

Function Collect_TrackSegmentsToDrag.

used to collect track segments in drag track segment Build the list of tracks connected to the ref point by calling AddSegmentToDragList for each selected track Net codes must be up to date, because only tracks having the right net code are tested.

Parameters
aPcbA point the the BOARD object to collect track segment to drag.
aRefPos= reference point of connection
aLayerMask= layers mask to collect tracks
aNetCode= the net code to consider
aMaxDist= max distance from aRefPos to a track end candidate to collect the track

Definition at line 338 of file dragsegm.cpp.

References abs, AddSegmentToDragList(), delta, dist, ENDPOINT, EuclideanNorm(), TRACK::GetEnd(), EDA_ITEM::GetFlags(), BOARD_ITEM::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), TRACK::GetStart(), TRACK::GetStartNetCode(), TRACK::GetWidth(), EDA_ITEM::IsDragging(), KiROUND(), BOARD::m_Track, max, TRACK::Next(), PCB_VIA_T, STARTPOINT, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::StartMoveOneNodeOrSegment().

340 {
341  TRACK* track = aPcb->m_Track->GetStartNetCode( aNetCode );
342 
343  for( ; track; track = track->Next() )
344  {
345  if( track->GetNetCode() != aNetCode ) // not the same netcode: all candidates tested
346  break;
347 
348  if( !( aLayerMask & track->GetLayerSet() ).any() )
349  continue; // Cannot be connected, not on the same layer
350 
351  if( track->IsDragging() )
352  continue; // already put in list
353 
354  STATUS_FLAGS flag = 0;
355  int maxdist = std::max( aMaxDist, track->GetWidth() / 2 );
356 
357  if( (track->GetFlags() & STARTPOINT) == 0 )
358  {
359  wxPoint delta = track->GetStart() - aRefPos;
360 
361  if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
362  {
363  int dist = KiROUND( EuclideanNorm( delta ) );
364 
365  if( dist <= maxdist )
366  {
367  flag |= STARTPOINT;
368 
369  if( track->Type() == PCB_VIA_T )
370  flag |= ENDPOINT;
371  }
372  }
373  }
374 
375  if( (track->GetFlags() & ENDPOINT) == 0 )
376  {
377  wxPoint delta = track->GetEnd() - aRefPos;
378 
379  if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
380  {
381  int dist = KiROUND( EuclideanNorm( delta ) );
382 
383  if( dist <= maxdist )
384  flag |= ENDPOINT;
385  }
386  }
387 
388  // Note: vias will be flagged with both STARTPOINT and ENDPOINT
389  // and must not be entered twice.
390  if( flag )
391  {
392  AddSegmentToDragList( flag, track );
393 
394  // If a connected via is found at location aRefPos,
395  // collect also tracks connected by this via.
396  if( track->Type() == PCB_VIA_T )
397  Collect_TrackSegmentsToDrag( aPcb, aRefPos, track->GetLayerSet(),
398  aNetCode, track->GetWidth() / 2 );
399  }
400  }
401 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
void Collect_TrackSegmentsToDrag(BOARD *aPcb, const wxPoint &aRefPos, LSET aLayerMask, int aNetCode, int aMaxDist)
Function Collect_TrackSegmentsToDrag.
Definition: dragsegm.cpp:338
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
static const int dist[10][10]
Definition: dist.cpp:57
#define abs(a)
Definition: auxiliary.h:84
static const int delta[8][2]
Definition: solve.cpp:112
const wxPoint & GetEnd() const
Definition: class_track.h:117
const wxPoint & GetStart() const
Definition: class_track.h:120
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
unsigned STATUS_FLAGS
Definition: base_struct.h:144
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:97
TRACK * GetStartNetCode(int NetCode)
#define max(a, b)
Definition: auxiliary.h:86
int GetWidth() const
Definition: class_track.h:114
void AddSegmentToDragList(int flag, TRACK *aTrack)
Definition: dragsegm.cpp:318
#define ENDPOINT
Definition: base_struct.h:119
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
DLIST< TRACK > m_Track
Definition: class_board.h:244
#define STARTPOINT
Definition: base_struct.h:118
bool IsDragging() const
Definition: base_struct.h:219
void DrawSegmentWhileMovingFootprint ( EDA_DRAW_PANEL panel,
wxDC *  DC 
)

Definition at line 294 of file dragsegm.cpp.

References TRACK::Draw(), g_DragSegmentList, g_Offset_Module, and GR_XOR.

Referenced by PCB_EDIT_FRAME::Change_Side_Module(), MoveFootprint(), and PCB_BASE_FRAME::Rotate_Module().

295 {
296  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
297  {
298  TRACK* track = g_DragSegmentList[ii].m_Track;
299 
300 #ifndef USE_WX_OVERLAY
301  track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
302 #endif
303  g_DragSegmentList[ii].SetTrackEndsCoordinates( g_Offset_Module );
304  track->Draw( panel, DC, GR_XOR );
305  }
306 }
wxPoint g_Offset_Module
Definition: pcbnew.cpp:83
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
void EraseDragList ( )

Function EraseDragList clear the .m_Flags of all track segments stored in g_DragSegmentList and clear the list.

In order to avoid useless memory reallocation, the memory is not freed and will be reused when creating a new list

Definition at line 309 of file dragsegm.cpp.

References g_DragSegmentList.

Referenced by Abort_Move_Pad(), Abort_MoveOrCopyModule(), Abort_MoveTrack(), PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment(), PCB_BASE_FRAME::PlaceModule(), PCB_BASE_FRAME::PlacePad(), PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope(), PCB_EDIT_FRAME::StartMoveModule(), PCB_EDIT_FRAME::StartMoveOneNodeOrSegment(), and PCB_BASE_FRAME::StartMovePad().

310 {
311  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
312  g_DragSegmentList[ii].m_Track->ClearFlags();
313 
314  g_DragSegmentList.clear();
315 }
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
bool sort_tracklist ( const DRAG_SEGM_PICKER ref,
const DRAG_SEGM_PICKER tst 
)

Definition at line 186 of file dragsegm.cpp.

References DRAG_SEGM_PICKER::m_Track.

Referenced by DRAG_LIST::fillList().

187 {
188  return ref.m_Track < tst.m_Track;
189 }
TRACK * m_Track
Definition: drag.h:61
bool sortPadsByXthenYCoord ( D_PAD *const &  ref,
D_PAD *const &  comp 
)

Function SortPadsByXCoord is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value.

This function is used to build ordered pads lists

Definition at line 1737 of file class_board.cpp.

References D_PAD::GetPosition(), wxPoint::x, and wxPoint::y.

Referenced by DRAG_LIST::BuildDragListe(), and BOARD::GetSortedPadListByXthenYCoord().

1738 {
1739  if( ref->GetPosition().x == comp->GetPosition().x )
1740  return ref->GetPosition().y < comp->GetPosition().y;
1741  return ref->GetPosition().x < comp->GetPosition().x;
1742 }
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
void UndrawAndMarkSegmentsToDrag ( EDA_DRAW_PANEL aCanvas,
wxDC *  aDC 
)

Definition at line 404 of file dragsegm.cpp.

References TRACK::Draw(), ENDPOINT, g_DragSegmentList, GR_XOR, IN_EDIT, IS_DRAGGED, EDA_ITEM::SetFlags(), EDA_ITEM::SetState(), and STARTPOINT.

Referenced by PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope(), PCB_EDIT_FRAME::StartMoveModule(), PCB_EDIT_FRAME::StartMoveOneNodeOrSegment(), and PCB_BASE_FRAME::StartMovePad().

405 {
406  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
407  {
408  TRACK* track = g_DragSegmentList[ii].m_Track;
409 
410  track->Draw( aCanvas, aDC, GR_XOR );
411  track->SetState( IN_EDIT, false );
412  track->SetFlags( IS_DRAGGED );
413 
414  if( g_DragSegmentList[ii].m_TempFlags & STARTPOINT )
415  track->SetFlags( STARTPOINT );
416 
417  if( g_DragSegmentList[ii].m_TempFlags & ENDPOINT )
418  track->SetFlags( ENDPOINT );
419 
420  track->Draw( aCanvas, aDC, GR_XOR );
421  }
422 }
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:111
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:115
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
void SetState(int type, int state)
Definition: base_struct.h:242
#define ENDPOINT
Definition: base_struct.h:119
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
#define STARTPOINT
Definition: base_struct.h:118

Variable Documentation