KiCad PCB EDA Suite
editrack.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <trigo.h>
#include <wxPcbStruct.h>
#include <pcbnew.h>
#include <drc_stuff.h>
#include <protos.h>
#include <class_board.h>
#include <class_track.h>
#include <class_zone.h>
#include <connectivity.h>

Go to the source code of this file.

Functions

static void Abort_Create_Track (EDA_DRAW_PANEL *panel, wxDC *DC)
 
void ShowNewTrackWhenMovingCursor (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void ComputeBreakPoint (TRACK *track, int SegmentCount, wxPoint end)
 Compute new track angle based on previous track. More...
 
static void DeleteNullTrackSegments (BOARD *pcb, DLIST< TRACK > &aTrackList)
 
static void EnsureEndTrackOnPad (D_PAD *Pad)
 
TRACKLocateIntrusion (TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
 
static void PushTrack (EDA_DRAW_PANEL *panel)
 Function PushTrack detects if the mouse is pointing into a conflicting track. More...
 
void DrawViaCirclesWhenEditingNewTrack (EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
 
wxPoint CalculateSegmentEndPoint (const wxPoint &aPosition, const wxPoint &aOrigin)
 Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the origin aOrigin and aPosition. More...
 

Variables

static PICKED_ITEMS_LIST s_ItemsListPicker
 

Function Documentation

static void Abort_Create_Track ( EDA_DRAW_PANEL panel,
wxDC *  DC 
)
static

Definition at line 60 of file editrack.cpp.

References PICKED_ITEMS_LIST::ClearListAndDeleteItems(), EDA_DRAW_FRAME::ClearMsgPanel(), DHEAD::DeleteAll(), BOARD::DrawHighLight(), dyn_cast(), g_CurrentTrackList, PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCurItem(), BOARD::GetHighLightNetCode(), EDA_DRAW_PANEL::GetParent(), PCB_EDIT_FRAME::HighLight(), BOARD::IsHighLightNetON(), BOARD::PopHighLight(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_FRAME::SetCurItem(), and ShowNewTrackWhenMovingCursor().

Referenced by PCB_EDIT_FRAME::Begin_Route().

61 {
62  PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent();
63  BOARD* pcb = frame->GetBoard();
64  TRACK* track = dyn_cast<TRACK*>( frame->GetCurItem() );
65 
66  if( track )
67  {
68  // Erase the current drawing
69  ShowNewTrackWhenMovingCursor( Panel, DC, wxDefaultPosition, false );
70 
71  if( pcb->IsHighLightNetON() )
72  frame->HighLight( DC );
73 
74  pcb->PopHighLight();
75 
76  if( pcb->IsHighLightNetON() )
77  pcb->DrawHighLight( Panel, DC, pcb->GetHighLightNetCode() );
78 
79  frame->ClearMsgPanel();
80 
81  // Undo pending changes (mainly a lock point creation) and clear the
82  // undo picker list:
83  frame->PutDataInPreviousState( &s_ItemsListPicker, false, false );
85 
86  // Delete current (new) track
88  }
89 
90  frame->SetCurItem( NULL );
91 }
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:88
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
BOARD * GetBoard() const
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
void PopHighLight()
Function PopHighLight retrieve a previously saved high light info.
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList, bool aRedoCommand, bool aRebuildRatsnet=true)
Function PutDataInPreviousState Used in undo or redo command.
Definition: undo_redo.cpp:377
void HighLight(wxDC *DC)
Function HighLight.
Definition: highlight.cpp:101
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void ShowNewTrackWhenMovingCursor(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: editrack.cpp:671
static PICKED_ITEMS_LIST s_ItemsListPicker
Definition: editrack.cpp:55
bool IsHighLightNetON() const
Function IsHighLightNetON.
Definition: class_board.h:381
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:366
void DrawHighLight(EDA_DRAW_PANEL *aDrawPanel, wxDC *aDC, int aNetCode)
Function DrawHighLight redraws the objects in the board that are associated with the given aNetCode a...
Definition: tracepcb.cpp:247
BOARD_ITEM * GetCurItem()
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:775
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
wxPoint CalculateSegmentEndPoint ( const wxPoint aPosition,
const wxPoint aOrigin 
)

Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the origin aOrigin and aPosition.

Definition at line 831 of file editrack.cpp.

References abs, PNS::angle(), min, wxPoint::x, and wxPoint::y.

Referenced by DrawSegment(), Show_New_Edge_While_Move_Mouse(), and ShowNewTrackWhenMovingCursor().

832 {
833  // Determine end point for a segment direction 0, 90, or 45 degrees
834  // depending on it's position from the origin \a aOrigin and \a aPosition.
835  wxPoint endPoint;
836 
837  int deltax = aPosition.x - aOrigin.x;
838  int deltay = aPosition.y - aOrigin.y;
839 
840  deltax = abs( deltax );
841  deltay = abs( deltay );
842  int angle = 45;
843 
844  if( deltax >= deltay )
845  {
846  if( deltax == 0 )
847  angle = 0;
848  else if( ( (deltay << 6 ) / deltax ) < 26 )
849  angle = 0;
850  }
851  else
852  {
853  angle = 45;
854 
855  if( deltay == 0 )
856  angle = 90;
857  else if( ( (deltax << 6 ) / deltay ) < 26 )
858  angle = 90;
859  }
860 
861  switch( angle )
862  {
863  case 0:
864  endPoint.x = aPosition.x;
865  endPoint.y = aOrigin.y;
866  break;
867 
868  case 45:
869  deltax = std::min( deltax, deltay );
870  deltay = deltax;
871 
872  // Recalculate the signs for deltax and deltaY.
873  if( ( aPosition.x - aOrigin.x ) < 0 )
874  deltax = -deltax;
875 
876  if( ( aPosition.y - aOrigin.y ) < 0 )
877  deltay = -deltay;
878 
879  endPoint.x = aOrigin.x + deltax;
880  endPoint.y = aOrigin.y + deltay;
881  break;
882 
883  case 90:
884  endPoint.x = aOrigin.x;
885  endPoint.y = aPosition.y;
886  break;
887  }
888 
889  return endPoint;
890 }
#define abs(a)
Definition: auxiliary.h:84
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
#define min(a, b)
Definition: auxiliary.h:85
void ComputeBreakPoint ( TRACK track,
int  n,
wxPoint  end 
)
static

Compute new track angle based on previous track.

Definition at line 896 of file editrack.cpp.

References abs, TRACK::Back(), g_Alternate_Track_Posture, TRACK::GetEnd(), TRACK::GetStart(), TRACK::IsNull(), min, TRACK::SetEnd(), TRACK::SetStart(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

897 {
898  int iDx = 0;
899  int iDy = 0;
900  int iAngle = 0;
901 
902  if( SegmentCount <= 0 )
903  return;
904 
905  if( track == NULL )
906  return;
907 
908  TRACK* newTrack = track;
909  track = track->Back();
910  SegmentCount--;
911 
912  if( track )
913  {
914  iDx = end.x - track->GetStart().x;
915  iDy = end.y - track->GetStart().y;
916 
917  iDx = abs( iDx );
918  iDy = abs( iDy );
919  }
920 
921  TRACK* lastTrack = track ? track->Back() : NULL;
922 
923  if( lastTrack )
924  {
925  if(( (lastTrack->GetEnd().x == lastTrack->GetStart().x)
926  || (lastTrack->GetEnd().y == lastTrack->GetStart().y) )
928  {
929  iAngle = 45;
930  }
931  }
932  else
933  {
935  {
936  iAngle = 45;
937  }
938  }
939 
940  if( iAngle == 0 )
941  {
942  if( iDx >= iDy )
943  iAngle = 0;
944  else
945  iAngle = 90;
946  }
947 
948  if( track == NULL )
949  iAngle = -1;
950 
951  switch( iAngle )
952  {
953  case -1:
954  break;
955 
956  case 0:
957  if( ( end.x - track->GetStart().x ) < 0 )
958  track->SetEnd(wxPoint( end.x + iDy, track->GetStart().y));
959  else
960  track->SetEnd(wxPoint( end.x - iDy, track->GetStart().y));
961  break;
962 
963  case 45:
964  iDx = std::min( iDx, iDy );
965  iDy = iDx;
966 
967  // Recalculate the signs for deltax and deltaY.
968  if( ( end.x - track->GetStart().x ) < 0 )
969  iDx = -iDx;
970 
971  if( ( end.y - track->GetStart().y ) < 0 )
972  iDy = -iDy;
973 
974  track->SetEnd(wxPoint(track->GetStart().x + iDx, track->GetStart().y + iDy));
975  break;
976 
977  case 90:
978  if( ( end.y - track->GetStart().y ) < 0 )
979  track->SetEnd(wxPoint(track->GetStart().x , end.y + iDx));
980  else
981  track->SetEnd(wxPoint(track->GetStart().x , end.y - iDx));
982  break;
983  }
984 
985  if( track )
986  {
987  if( track->IsNull() )
988  track->SetEnd( end );
989 
990  newTrack->SetStart( track->GetEnd() );
991  }
992 
993  newTrack->SetEnd( end );
994 }
bool IsNull()
Function IsNull returns true if segment length is zero.
bool g_Alternate_Track_Posture
Definition: pcbnew.cpp:70
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
#define abs(a)
Definition: auxiliary.h:84
TRACK * Back() const
Definition: class_track.h:99
const wxPoint & GetEnd() const
Definition: class_track.h:118
const wxPoint & GetStart() const
Definition: class_track.h:121
void SetStart(const wxPoint &aStart)
Definition: class_track.h:120
#define min(a, b)
Definition: auxiliary.h:85
void DeleteNullTrackSegments ( BOARD pcb,
DLIST< TRACK > &  aTrackList 
)
static

Definition at line 1000 of file editrack.cpp.

References BEGIN_ONPAD, TRACK::end, END_ONPAD, ENDPOINT_END, DHEAD::GetCount(), DLIST< T >::GetFirst(), BOARD::GetPad(), TRACK::IsNull(), TRACK::Next(), PCB_PAD_T, DLIST< T >::Remove(), EDA_ITEM::SetState(), EDA_ITEM::SetStatus(), TRACK::start, and EDA_ITEM::Type().

Referenced by PCB_EDIT_FRAME::End_Route().

1001 {
1002  if( aTrackList.GetCount() == 0 )
1003  return;
1004 
1005  TRACK* track = aTrackList.GetFirst();
1006  TRACK* firsttrack = track;
1007  TRACK* oldtrack;
1008 
1009  BOARD_CONNECTED_ITEM* lockPoint = track->start;
1010 
1011  while( track != NULL )
1012  {
1013  oldtrack = track;
1014  track = track->Next();
1015 
1016  if( !oldtrack->IsNull() )
1017  {
1018  continue;
1019  }
1020 
1021  // NULL segment, delete it
1022  if( firsttrack == oldtrack )
1023  firsttrack = track;
1024 
1025  delete aTrackList.Remove( oldtrack );
1026  }
1027 
1028  if( aTrackList.GetCount() == 0 )
1029  return; // all the new track segments have been deleted
1030 
1031  // we must set the pointers on connected items and the connection status
1032  oldtrack = track = firsttrack;
1033  firsttrack->start = NULL;
1034 
1035  while( track != NULL )
1036  {
1037  oldtrack = track;
1038  track = track->Next();
1039  oldtrack->end = track;
1040 
1041  if( track )
1042  track->start = oldtrack;
1043 
1044  oldtrack->SetStatus( 0 );
1045  }
1046 
1047  firsttrack->start = lockPoint;
1048 
1049  if( lockPoint && lockPoint->Type()==PCB_PAD_T )
1050  firsttrack->SetState( BEGIN_ONPAD, true );
1051 
1052  track = firsttrack;
1053 
1054  while( track != NULL )
1055  {
1056  TRACK* next_track = track->Next();
1057  lockPoint = pcb->GetPad( track, ENDPOINT_END );
1058 
1059  if( lockPoint )
1060  {
1061  track->end = lockPoint;
1062  track->SetState( END_ONPAD, true );
1063 
1064  if( next_track )
1065  {
1066  next_track->start = lockPoint;
1067  next_track->SetState( BEGIN_ONPAD, true );
1068  }
1069  }
1070 
1071  track = next_track;
1072  }
1073 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool IsNull()
Function IsNull returns true if segment length is zero.
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:147
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
D_PAD * GetPad(unsigned aIndex) const
Function GetPad.
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:146
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
TRACK * Next() const
Definition: class_track.h:98
void SetState(int type, int state)
Definition: base_struct.h:256
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:265
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:90
BOARD_CONNECTED_ITEM * start
Definition: class_track.h:89
void DrawViaCirclesWhenEditingNewTrack ( EDA_RECT aPanelClipBox,
wxDC *  aDC,
const wxPoint aPos,
int  aViaRadius,
int  aViaRadiusWithClearence,
COLOR4D  aColor 
)
inline

Definition at line 657 of file editrack.cpp.

References GRCircle(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

662 {
663  //Current viasize clearance circle
664  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor );
665  //Current viasize circle
666  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadius, aColor );
667 }
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:791
void EnsureEndTrackOnPad ( D_PAD Pad)
static

Definition at line 1080 of file editrack.cpp.

References TRACK::Clone(), TRACK::end, END_ONPAD, g_CurrentTrackList, g_CurrentTrackSegment, D_PAD::GetPosition(), and DLIST< T >::PushBack().

Referenced by PCB_EDIT_FRAME::End_Route().

1081 {
1082  if( g_CurrentTrackSegment->GetEnd() == aPad->GetPosition() ) // Ok !
1083  {
1084  g_CurrentTrackSegment->end = aPad;
1085  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1086  return;
1087  }
1088 
1089  TRACK* lasttrack = g_CurrentTrackSegment;
1090 
1091  if( !g_CurrentTrackSegment->IsNull() )
1092  {
1093  // Must create a new segment, from track end to pad center
1094  g_CurrentTrackList.PushBack( (TRACK*)lasttrack->Clone() );
1095 
1096  lasttrack->end = g_CurrentTrackSegment;
1097  }
1098 
1099  g_CurrentTrackSegment->SetEnd( aPad->GetPosition() );
1100  g_CurrentTrackSegment->SetState( END_ONPAD, false );
1101 
1102  g_CurrentTrackSegment->end = aPad;
1103  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1104 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:95
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:147
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:88
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:90
TRACK* LocateIntrusion ( TRACK listStart,
TRACK aTrack,
LAYER_NUM  aLayer,
const wxPoint aRef 
)

Definition at line 539 of file editrack.cpp.

References BUSY, dist, TRACK::GetClearance(), BOARD_CONNECTED_ITEM::GetNetCode(), TRACK::GetWidth(), IS_DELETED, TRACK::Next(), PCB_TRACE_T, TestSegmentHit(), wxPoint::x, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::GeneralControl(), and PushTrack().

540 {
541  int net = aTrack->GetNetCode();
542  int width = aTrack->GetWidth();
543 
544  TRACK* found = NULL;
545 
546  for( TRACK* track = listStart; track; track = track->Next() )
547  {
548  if( track->Type() == PCB_TRACE_T ) // skip vias
549  {
550  if( track->GetState( BUSY | IS_DELETED ) )
551  continue;
552 
553  if( aLayer != track->GetLayer() )
554  continue;
555 
556  if( track->GetNetCode() == net )
557  continue;
558 
559  // TRACK::HitTest
560  int dist = (width + track->GetWidth()) / 2 + aTrack->GetClearance( track );
561 
562  if( !TestSegmentHit( aRef, track->GetStart(), track->GetEnd(), dist ) )
563  continue;
564 
565  found = track;
566 
567  // prefer intrusions from the side, not the end
568  wxPoint pos = aRef - track->GetStart();
569  wxPoint vec = track->GetEnd() - track->GetStart();
570  double tmp = (double) pos.x * vec.x + (double) pos.y * vec.y;
571 
572  if( tmp >= 0 && tmp <= (double) vec.x * vec.x + (double) vec.y * vec.y )
573  break;
574  }
575  }
576 
577  return found;
578 }
static const int dist[10][10]
Definition: dist.cpp:57
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:148
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
#define IS_DELETED
Definition: base_struct.h:130
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:98
int GetWidth() const
Definition: class_track.h:115
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:142
static void PushTrack ( EDA_DRAW_PANEL panel)
static

Function PushTrack detects if the mouse is pointing into a conflicting track.

In this case, it tries to push the new track out of the conflicting track's clearance zone. This gives us a cheap mechanism for drawing tracks that tightly follow others, independent of grid settings.

KNOWN BUGS:

  • we do the same sort of search and calculation up to three times: 1) we search for magnetic hits (in controle.cpp) 2) we check if there's a DRC violation in the making (also controle.cpp) 3) we try to fix the DRC violation (here)
  • if we have a magnetic hit and a DRC violation at the same time, we choose the magnetic hit instead of solving the violation
  • should locate conflicting tracks also when we're crossing over them

Definition at line 597 of file editrack.cpp.

References dist, FindBestGridPointOnTrack(), g_CurrentTrackSegment, BOARD_ITEM::GetBoard(), TRACK::GetClearance(), EDA_DRAW_FRAME::GetCrossHairPosition(), TRACK::GetEnd(), BOARD_CONNECTED_ITEM::GetNetCode(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_FRAME::GetScreen(), TRACK::GetStart(), TRACK::GetWidth(), KiROUND(), LocateIntrusion(), PCB_SCREEN::m_Active_Layer, BOARD::m_Track, EDA_DRAW_FRAME::RefPos(), TRACK::SetEnd(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

598 {
599  PCB_SCREEN* screen = (PCB_SCREEN*) panel->GetParent()->GetScreen();
600  BOARD* pcb = ( (PCB_BASE_FRAME*) (panel->GetParent()) )->GetBoard();
601  wxPoint cursor = panel->GetParent()->GetCrossHairPosition();
602  wxPoint cv, vec, n;
603  TRACK* track = g_CurrentTrackSegment;
604  TRACK* other;
605  double det;
606  int dist;
607  double f;
608 
609  other = LocateIntrusion( pcb->m_Track, track, screen->m_Active_Layer, panel->GetParent()->RefPos( true ) );
610 
611  // are we currently pointing into a conflicting trace ?
612  if( !other )
613  return;
614 
615  if( other->GetNetCode() == track->GetNetCode() )
616  return;
617 
618  cv = cursor - other->GetStart();
619  vec = other->GetEnd() - other->GetStart();
620 
621  det = (double) cv.x * vec.y - (double) cv.y * vec.x;
622 
623  // cursor is right at the center of the old track
624  if( !det )
625  return;
626 
627  dist = (track->GetWidth() + 1) / 2 + (other->GetWidth() + 1) / 2 + track->GetClearance( other ) + 2;
628 
629  /*
630  * DRC wants >, so +1.
631  * We may have a quantization error of 1/sqrt(2), so +1 again.
632  */
633 
634  // Vector "n" is perpendicular to "other", pointing towards the cursor.
635  if( det > 0 )
636  {
637  n.x = vec.y;
638  n.y = -vec.x;
639  }
640  else
641  {
642  n.x = -vec.y;
643  n.y = vec.x;
644  }
645 
646  f = dist / hypot( double(n.x), double(n.y) );
647  n.x = KiROUND( f * n.x );
648  n.y = KiROUND( f * n.y );
649 
650  wxPoint hp = track->GetEnd();
651  FindBestGridPointOnTrack( &hp, cursor, other );
652  track->SetEnd( hp + n );
653 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:95
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
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
static const int dist[10][10]
Definition: dist.cpp:57
PCB_LAYER_ID m_Active_Layer
const wxPoint & GetEnd() const
Definition: class_track.h:118
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:347
const wxPoint & GetStart() const
Definition: class_track.h:121
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
TRACK * LocateIntrusion(TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
Definition: editrack.cpp:539
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
bool FindBestGridPointOnTrack(wxPoint *aNearPos, wxPoint on_grid, const TRACK *track)
Finds the projection of a grid point on a track.
int GetNetCode() const
Function GetNetCode.
wxPoint RefPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int GetWidth() const
Definition: class_track.h:115
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
DLIST< TRACK > m_Track
Definition: class_board.h:246
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void ShowNewTrackWhenMovingCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)

Definition at line 671 of file editrack.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), BEGIN_ONPAD, PCB_BASE_FRAME::BuildAirWiresTargetsList(), CalculateSegmentEndPoint(), color, PCB_GENERAL_SETTINGS::Colors(), ComputeBreakPoint(), DARKCYAN, DBG, DO_NOT_SHOW_CLEARANCE, DrawTraces(), DrawViaCirclesWhenEditingNewTrack(), g_CurrentTrackList, g_CurrentTrackSegment, g_FirstTrackSegment, EDA_DRAW_PANEL::GetClipBox(), DHEAD::GetCount(), EDA_DRAW_FRAME::GetCrossHairPosition(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetCurrentViaSize(), PCB_BASE_FRAME::GetDesignSettings(), EDA_DRAW_PANEL::GetDisplayOptions(), COLORS_DESIGN_SETTINGS::GetLayerColor(), TRACK::GetLength(), D_PAD::GetPadToDieLength(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_XOR, EDA_DRAW_FRAME::LengthDoubleToString(), PCB_SCREEN::m_Active_Layer, DISPLAY_OPTIONS::m_DisplayPcbTrackFill, PCB_GENERAL_SETTINGS::m_legacyDrcOn, PCB_GENERAL_SETTINGS::m_legacyUse45DegreeTracks, PCB_GENERAL_SETTINGS::m_legacyUseTwoSegmentTracks, DISPLAY_OPTIONS::m_ShowTrackClearanceMode, BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, PCB_TRACE_T, PushTrack(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_BASE_FRAME::Settings(), TRACK::SetWidth(), SHOW_CLEARANCE_ALWAYS, SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS, PCB_BASE_FRAME::TraceAirWiresToTargets(), and EDA_ITEM::Type().

Referenced by Abort_Create_Track(), PCB_EDIT_FRAME::Begin_Route(), PCB_EDIT_FRAME::Delete_Segment(), and PCB_EDIT_FRAME::End_Route().

673 {
674 // DBG( g_CurrentTrackList.VerifyListIntegrity(); );
675 
676  PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
677  PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
678  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) aPanel->GetDisplayOptions();
679 
680  bool tmp = displ_opts->m_DisplayPcbTrackFill;
681  displ_opts->m_DisplayPcbTrackFill = true;
682  TRACE_CLEARANCE_DISPLAY_MODE_T showTrackClearanceMode = displ_opts->m_ShowTrackClearanceMode;
683 
684  if ( g_FirstTrackSegment == NULL )
685  return;
686 
687  NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass();
688 
689  if( showTrackClearanceMode != DO_NOT_SHOW_CLEARANCE )
691 
692  // Values to Via circle
693  int boardViaRadius = frame->GetDesignSettings().GetCurrentViaSize()/2;
694  int viaRadiusWithClearence = boardViaRadius+netclass->GetClearance();
695  EDA_RECT* panelClipBox=aPanel->GetClipBox();
696 
697 #ifndef USE_WX_OVERLAY
698  // Erase old track
699  if( aErase )
700  {
702 
703  frame->TraceAirWiresToTargets( aDC );
704 
705  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
706  {
707  COLOR4D color = frame->Settings().Colors().GetLayerColor( g_CurrentTrackSegment->GetLayer() );
708  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
709  boardViaRadius, viaRadiusWithClearence, color);
710  }
711  }
712 #endif
713  // MacOSX seems to need this.
714  if( g_CurrentTrackList.GetCount() == 0 )
715  return;
716 
717  // Set track parameters, that can be modified while creating the track
718  g_CurrentTrackSegment->SetLayer( screen->m_Active_Layer );
719 
722 
724  {
725  TRACK* previous_track = g_CurrentTrackSegment->Back();
726 
727  if( previous_track && previous_track->Type()==PCB_TRACE_T )
728  {
729  previous_track->SetLayer( screen->m_Active_Layer );
730 
732  previous_track->SetWidth( frame->GetDesignSettings().GetCurrentTrackWidth() );
733  }
734  }
735 
736  if( frame->Settings().m_legacyUse45DegreeTracks )
737  {
739  {
740  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
741 
742  if( frame->Settings().m_legacyDrcOn )
743  PushTrack( aPanel );
744 
747  g_CurrentTrackSegment->GetEnd() );
748  }
749  else
750  {
751  /* Calculate of the end of the path for the permitted directions:
752  * horizontal, vertical or 45 degrees.
753  */
754  wxPoint hp = g_CurrentTrackSegment->GetEnd();
756  g_CurrentTrackSegment->GetStart() );
757  g_CurrentTrackSegment->SetEnd(hp);
758  }
759  }
760  else // Here the angle is arbitrary
761  {
762  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
763  }
764 
765  // Redraw the new track
766  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
768 
769  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
770  {
771  COLOR4D color = frame->Settings().Colors().GetLayerColor(g_CurrentTrackSegment->GetLayer());
772 
773  //Via diameter must have taken what we are using, rather than netclass value.
774  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
775  boardViaRadius, viaRadiusWithClearence, color);
776 
777  }
778 
779  /* Display info about current segment and the full new track:
780  * Choose the interesting segment: because we are using a 2 segments step,
781  * the last segment can be null, and the previous segment can be the
782  * interesting segment.
783  */
784  TRACK* isegm = g_CurrentTrackSegment;
785 
786  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
787  isegm = g_CurrentTrackSegment->Back();
788 
789  // display interesting segment info only:
790  frame->SetMsgPanel( isegm );
791 
792  // Display current track length (on board) and the the actual track len
793  // if there is an extra len due to the len die on the starting pad (if any)
794  double trackLen = 0.0;
795  double lenPadToDie = 0.0;
796  wxString msg;
797 
798  // If the starting point is on a pad, add current track length+ length die
799  if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) )
800  {
801  D_PAD* pad = (D_PAD*) g_FirstTrackSegment->start;
802  lenPadToDie = (double) pad->GetPadToDieLength();
803  }
804 
805  // calculate track len on board:
806  for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
807  trackLen += track->GetLength();
808 
809  msg = frame->LengthDoubleToString( trackLen );
810  frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN );
811 
812  if( lenPadToDie != 0 ) // display the track len on board and the actual track len
813  {
814  frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN );
815  msg = frame->LengthDoubleToString( trackLen+lenPadToDie );
816  frame->AppendMsgPanel( _( "Pad to die" ), msg, DARKCYAN );
817  }
818 
819  // Add current segments count (number of segments in this new track):
820  msg.Printf( wxT( "%d" ), g_CurrentTrackList.GetCount() );
821  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
822 
823  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
824  displ_opts->m_DisplayPcbTrackFill = tmp;
825 
826  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(), g_CurrentTrackSegment->GetNetCode() );
827  frame->TraceAirWiresToTargets( aDC );
828 }
#define g_FirstTrackSegment
first segment created
Definition: pcbnew.h:96
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:95
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void TraceAirWiresToTargets(wxDC *aDC)
Function TraceAirWiresToTargets This functions shows airwires to nearest connecting points (pads) fro...
Definition: ratsnest.cpp:196
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:88
int GetPadToDieLength() const
Definition: class_pad.h:401
void BuildAirWiresTargetsList(BOARD_CONNECTED_ITEM *aItemRef, const wxPoint &aPosition, int aNet)
Function BuildAirWiresTargetsList Build a list of candidates that can be a coonection point when a tr...
Definition: ratsnest.cpp:173
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:146
PCB_LAYER_ID m_Active_Layer
int GetCurrentViaSize() const
Function GetCurrentViaSize.
bool m_UseConnectedTrackWidth
if true, when creating a new track starting on an existing track, use this track width ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
wxPoint CalculateSegmentEndPoint(const wxPoint &aPosition, const wxPoint &aOrigin)
Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the ...
Definition: editrack.cpp:831
void SetWidth(int aWidth)
Definition: class_track.h:114
bool m_DisplayPcbTrackFill
Definition: pcbstruct.h:71
static void PushTrack(EDA_DRAW_PANEL *panel)
Function PushTrack detects if the mouse is pointing into a conflicting track.
Definition: editrack.cpp:597
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:784
wxString LengthDoubleToString(double aValue, bool aConvertToMils=false) const
Function LengthDoubleToString is a helper to convert the double value aValue to a string in inches or...
Definition: draw_frame.cpp:828
PCB_GENERAL_SETTINGS & Settings()
EDA_RECT * GetClipBox()
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
COLORS_DESIGN_SETTINGS & Colors()
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
Definition: pcbstruct.h:74
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:764
void DrawViaCirclesWhenEditingNewTrack(EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
Definition: editrack.cpp:657
Class EDA_RECT handles the component boundary box.
static void ComputeBreakPoint(TRACK *track, int n, wxPoint end)
Compute new track angle based on previous track.
Definition: editrack.cpp:896
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:171
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
#define DBG(x)
Definition: fctsys.h:33
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:181
void DrawTraces(EDA_DRAW_PANEL *panel, wxDC *DC, TRACK *aStartTrace, int nbsegment, GR_DRAWMODE mode_color)
Function DrawTraces Draws n consecutive track segments in list.
Definition: tr_modif.cpp:49
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
TRACE_CLEARANCE_DISPLAY_MODE_T
Enum TRACE_CLEARANCE_DISPLAY_MODE_T is the set of values for DISPLAY_OPTIONS.ShowTrackClearanceMode p...
Definition: pcbstruct.h:39
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

Variable Documentation

PICKED_ITEMS_LIST s_ItemsListPicker
static

Definition at line 55 of file editrack.cpp.