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 <connectivity_data.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 302 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().

303 {
304  DRAG_SEGM_PICKER wrapper( aTrack );
305 
306  if( flag & STARTPOINT )
307  {
308  wrapper.m_TempFlags |= STARTPOINT;
309  aTrack->SetFlags( STARTPOINT );
310  }
311 
312  if( flag & ENDPOINT )
313  {
314  wrapper.m_TempFlags |= ENDPOINT;
315  aTrack->SetFlags( ENDPOINT );
316  }
317 
318  g_DragSegmentList.push_back( wrapper );
319 }
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:267
#define ENDPOINT
Definition: base_struct.h:133
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:47
#define STARTPOINT
Definition: base_struct.h:132
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 322 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().

324 {
325  TRACK* track = aPcb->m_Track->GetStartNetCode( aNetCode );
326 
327  for( ; track; track = track->Next() )
328  {
329  if( track->GetNetCode() != aNetCode ) // not the same netcode: all candidates tested
330  break;
331 
332  if( !( aLayerMask & track->GetLayerSet() ).any() )
333  continue; // Cannot be connected, not on the same layer
334 
335  if( track->IsDragging() )
336  continue; // already put in list
337 
338  STATUS_FLAGS flag = 0;
339  int maxdist = std::max( aMaxDist, track->GetWidth() / 2 );
340 
341  if( (track->GetFlags() & STARTPOINT) == 0 )
342  {
343  wxPoint delta = track->GetStart() - aRefPos;
344 
345  if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
346  {
347  int dist = KiROUND( EuclideanNorm( delta ) );
348 
349  if( dist <= maxdist )
350  {
351  flag |= STARTPOINT;
352 
353  if( track->Type() == PCB_VIA_T )
354  flag |= ENDPOINT;
355  }
356  }
357  }
358 
359  if( (track->GetFlags() & ENDPOINT) == 0 )
360  {
361  wxPoint delta = track->GetEnd() - aRefPos;
362 
363  if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
364  {
365  int dist = KiROUND( EuclideanNorm( delta ) );
366 
367  if( dist <= maxdist )
368  flag |= ENDPOINT;
369  }
370  }
371 
372  // Note: vias will be flagged with both STARTPOINT and ENDPOINT
373  // and must not be entered twice.
374  if( flag )
375  {
376  AddSegmentToDragList( flag, track );
377 
378  // If a connected via is found at location aRefPos,
379  // collect also tracks connected by this via.
380  if( track->Type() == PCB_VIA_T )
381  Collect_TrackSegmentsToDrag( aPcb, aRefPos, track->GetLayerSet(),
382  aNetCode, track->GetWidth() / 2 );
383  }
384  }
385 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:269
void Collect_TrackSegmentsToDrag(BOARD *aPcb, const wxPoint &aRefPos, LSET aLayerMask, int aNetCode, int aMaxDist)
Function Collect_TrackSegmentsToDrag.
Definition: dragsegm.cpp:322
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
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:120
const wxPoint & GetStart() const
Definition: class_track.h:123
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:158
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:100
TRACK * GetStartNetCode(int NetCode)
#define max(a, b)
Definition: auxiliary.h:86
int GetWidth() const
Definition: class_track.h:117
void AddSegmentToDragList(int flag, TRACK *aTrack)
Definition: dragsegm.cpp:302
#define ENDPOINT
Definition: base_struct.h:133
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< TRACK > m_Track
Definition: class_board.h:246
#define STARTPOINT
Definition: base_struct.h:132
bool IsDragging() const
Definition: base_struct.h:233
void DrawSegmentWhileMovingFootprint ( EDA_DRAW_PANEL panel,
wxDC *  DC 
)

Definition at line 278 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().

279 {
280  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
281  {
282  TRACK* track = g_DragSegmentList[ii].m_Track;
283 
284 #ifndef USE_WX_OVERLAY
285  track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
286 #endif
287  g_DragSegmentList[ii].SetTrackEndsCoordinates( g_Offset_Module );
288  track->Draw( panel, DC, GR_XOR );
289  }
290 }
wxPoint g_Offset_Module
Definition: pcbnew.cpp:73
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:47
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 293 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().

294 {
295  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
296  g_DragSegmentList[ii].m_Track->ClearFlags();
297 
298  g_DragSegmentList.clear();
299 }
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:47
bool sort_tracklist ( const DRAG_SEGM_PICKER ref,
const DRAG_SEGM_PICKER tst 
)

Definition at line 182 of file dragsegm.cpp.

References DRAG_SEGM_PICKER::m_Track.

Referenced by DRAG_LIST::fillList().

183 {
184  return ref.m_Track < tst.m_Track;
185 }
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 1707 of file class_board.cpp.

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

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

1708 {
1709  if( ref->GetPosition().x == comp->GetPosition().x )
1710  return ref->GetPosition().y < comp->GetPosition().y;
1711  return ref->GetPosition().x < comp->GetPosition().x;
1712 }
const wxPoint & GetPosition() const override
Definition: class_pad.h:220
void UndrawAndMarkSegmentsToDrag ( EDA_DRAW_PANEL aCanvas,
wxDC *  aDC 
)

Definition at line 388 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().

389 {
390  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
391  {
392  TRACK* track = g_DragSegmentList[ii].m_Track;
393 
394  track->Draw( aCanvas, aDC, GR_XOR );
395  track->SetState( IN_EDIT, false );
396  track->SetFlags( IS_DRAGGED );
397 
398  if( g_DragSegmentList[ii].m_TempFlags & STARTPOINT )
399  track->SetFlags( STARTPOINT );
400 
401  if( g_DragSegmentList[ii].m_TempFlags & ENDPOINT )
402  track->SetFlags( ENDPOINT );
403 
404  track->Draw( aCanvas, aDC, GR_XOR );
405  }
406 }
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:125
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:129
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:267
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:256
#define ENDPOINT
Definition: base_struct.h:133
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:47
#define STARTPOINT
Definition: base_struct.h:132

Variable Documentation