KiCad PCB EDA Suite
editrack.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <trigo.h>
#include <wxPcbStruct.h>
#include <colors_selection.h>
#include <pcbnew.h>
#include <drc_stuff.h>
#include <protos.h>
#include <class_board.h>
#include <class_track.h>
#include <class_zone.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)
 
void CalculateSegmentEndPoint (const wxPoint &aPosition, int ox, int oy, int *fx, int *fy)
 Determine coordinate for a segment direction of 0, 90, or 45 degrees depending on it's position from the origin (ox, oy) and aPosiition. 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:98
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:166
void ShowNewTrackWhenMovingCursor(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: editrack.cpp:673
static PICKED_ITEMS_LIST s_ItemsListPicker
Definition: editrack.cpp:55
bool IsHighLightNetON() const
Function IsHighLightNetON.
Definition: class_board.h:370
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:355
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:745
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
void CalculateSegmentEndPoint ( const wxPoint aPosition,
int  ox,
int  oy,
int *  fx,
int *  fy 
)

Determine coordinate for a segment direction of 0, 90, or 45 degrees depending on it's position from the origin (ox, oy) and aPosiition.

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

840 {
841  int deltax, deltay, angle;
842 
843  deltax = aPosition.x - ox;
844  deltay = aPosition.y - oy;
845 
846  deltax = abs( deltax );
847  deltay = abs( deltay );
848  angle = 45;
849 
850  if( deltax >= deltay )
851  {
852  if( deltax == 0 )
853  angle = 0;
854  else if( ( (deltay << 6 ) / deltax ) < 26 )
855  angle = 0;
856  }
857  else
858  {
859  angle = 45;
860 
861  if( deltay == 0 )
862  angle = 90;
863  else if( ( (deltax << 6 ) / deltay ) < 26 )
864  angle = 90;
865  }
866 
867  switch( angle )
868  {
869  case 0:
870  *fx = aPosition.x;
871  *fy = oy;
872  break;
873 
874  case 45:
875  deltax = std::min( deltax, deltay );
876  deltay = deltax;
877 
878  // Recalculate the signs for deltax and deltaY.
879  if( ( aPosition.x - ox ) < 0 )
880  deltax = -deltax;
881 
882  if( ( aPosition.y - oy ) < 0 )
883  deltay = -deltay;
884 
885  *fx = ox + deltax;
886  *fy = oy + deltay;
887  break;
888 
889  case 90:
890  *fx = ox;
891  *fy = aPosition.y;
892  break;
893  }
894 }
#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 900 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().

901 {
902  int iDx = 0;
903  int iDy = 0;
904  int iAngle = 0;
905 
906  if( SegmentCount <= 0 )
907  return;
908 
909  if( track == NULL )
910  return;
911 
912  TRACK* newTrack = track;
913  track = track->Back();
914  SegmentCount--;
915 
916  if( track )
917  {
918  iDx = end.x - track->GetStart().x;
919  iDy = end.y - track->GetStart().y;
920 
921  iDx = abs( iDx );
922  iDy = abs( iDy );
923  }
924 
925  TRACK* lastTrack = track ? track->Back() : NULL;
926 
927  if( lastTrack )
928  {
929  if(( (lastTrack->GetEnd().x == lastTrack->GetStart().x)
930  || (lastTrack->GetEnd().y == lastTrack->GetStart().y) )
932  {
933  iAngle = 45;
934  }
935  }
936  else
937  {
939  {
940  iAngle = 45;
941  }
942  }
943 
944  if( iAngle == 0 )
945  {
946  if( iDx >= iDy )
947  iAngle = 0;
948  else
949  iAngle = 90;
950  }
951 
952  if( track == NULL )
953  iAngle = -1;
954 
955  switch( iAngle )
956  {
957  case -1:
958  break;
959 
960  case 0:
961  if( ( end.x - track->GetStart().x ) < 0 )
962  track->SetEnd(wxPoint( end.x + iDy, track->GetStart().y));
963  else
964  track->SetEnd(wxPoint( end.x - iDy, track->GetStart().y));
965  break;
966 
967  case 45:
968  iDx = std::min( iDx, iDy );
969  iDy = iDx;
970 
971  // Recalculate the signs for deltax and deltaY.
972  if( ( end.x - track->GetStart().x ) < 0 )
973  iDx = -iDx;
974 
975  if( ( end.y - track->GetStart().y ) < 0 )
976  iDy = -iDy;
977 
978  track->SetEnd(wxPoint(track->GetStart().x + iDx, track->GetStart().y + iDy));
979  break;
980 
981  case 90:
982  if( ( end.y - track->GetStart().y ) < 0 )
983  track->SetEnd(wxPoint(track->GetStart().x , end.y + iDx));
984  else
985  track->SetEnd(wxPoint(track->GetStart().x , end.y - iDx));
986  break;
987  }
988 
989  if( track )
990  {
991  if( track->IsNull() )
992  track->SetEnd( end );
993 
994  newTrack->SetStart( track->GetEnd() );
995  }
996 
997  newTrack->SetEnd( end );
998 }
bool IsNull()
Function IsNull returns true if segment length is zero.
bool g_Alternate_Track_Posture
Definition: pcbnew.cpp:73
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 1004 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().

1005 {
1006  if( aTrackList.GetCount() == 0 )
1007  return;
1008 
1009  TRACK* track = aTrackList.GetFirst();
1010  TRACK* firsttrack = track;
1011  TRACK* oldtrack;
1012 
1013  BOARD_CONNECTED_ITEM* lockPoint = track->start;
1014 
1015  while( track != NULL )
1016  {
1017  oldtrack = track;
1018  track = track->Next();
1019 
1020  if( !oldtrack->IsNull() )
1021  {
1022  continue;
1023  }
1024 
1025  // NULL segment, delete it
1026  if( firsttrack == oldtrack )
1027  firsttrack = track;
1028 
1029  delete aTrackList.Remove( oldtrack );
1030  }
1031 
1032  if( aTrackList.GetCount() == 0 )
1033  return; // all the new track segments have been deleted
1034 
1035  // we must set the pointers on connected items and the connection status
1036  oldtrack = track = firsttrack;
1037  firsttrack->start = NULL;
1038 
1039  while( track != NULL )
1040  {
1041  oldtrack = track;
1042  track = track->Next();
1043  oldtrack->end = track;
1044 
1045  if( track )
1046  track->start = oldtrack;
1047 
1048  oldtrack->SetStatus( 0 );
1049  }
1050 
1051  firsttrack->start = lockPoint;
1052 
1053  if( lockPoint && lockPoint->Type()==PCB_PAD_T )
1054  firsttrack->SetState( BEGIN_ONPAD, true );
1055 
1056  track = firsttrack;
1057 
1058  while( track != NULL )
1059  {
1060  TRACK* next_track = track->Next();
1061  lockPoint = pcb->GetPad( track, ENDPOINT_END );
1062 
1063  if( lockPoint )
1064  {
1065  track->end = lockPoint;
1066  track->SetState( END_ONPAD, true );
1067 
1068  if( next_track )
1069  {
1070  next_track->start = lockPoint;
1071  next_track->SetState( BEGIN_ONPAD, true );
1072  }
1073  }
1074 
1075  track = next_track;
1076  }
1077 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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:133
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:132
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
D_PAD * GetPad(unsigned aIndex) const
Function GetPad.
Definition: class_board.h:750
TRACK * Next() const
Definition: class_track.h:98
void SetState(int type, int state)
Definition: base_struct.h:242
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:251
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 659 of file editrack.cpp.

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

Referenced by ShowNewTrackWhenMovingCursor().

664 {
665  //Current viasize clearence circle
666  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor );
667  //Current viasize circle
668  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadius, aColor );
669 }
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 1084 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().

1085 {
1086  if( g_CurrentTrackSegment->GetEnd() == aPad->GetPosition() ) // Ok !
1087  {
1088  g_CurrentTrackSegment->end = aPad;
1089  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1090  return;
1091  }
1092 
1093  TRACK* lasttrack = g_CurrentTrackSegment;
1094 
1095  if( !g_CurrentTrackSegment->IsNull() )
1096  {
1097  // Must create a new segment, from track end to pad center
1098  g_CurrentTrackList.PushBack( (TRACK*)lasttrack->Clone() );
1099 
1100  lasttrack->end = g_CurrentTrackSegment;
1101  }
1102 
1103  g_CurrentTrackSegment->SetEnd( aPad->GetPosition() );
1104  g_CurrentTrackSegment->SetState( END_ONPAD, false );
1105 
1106  g_CurrentTrackSegment->end = aPad;
1107  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1108 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:101
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:133
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
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 541 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().

542 {
543  int net = aTrack->GetNetCode();
544  int width = aTrack->GetWidth();
545 
546  TRACK* found = NULL;
547 
548  for( TRACK* track = listStart; track; track = track->Next() )
549  {
550  if( track->Type() == PCB_TRACE_T ) // skip vias
551  {
552  if( track->GetState( BUSY | IS_DELETED ) )
553  continue;
554 
555  if( aLayer != track->GetLayer() )
556  continue;
557 
558  if( track->GetNetCode() == net )
559  continue;
560 
561  // TRACK::HitTest
562  int dist = (width + track->GetWidth()) / 2 + aTrack->GetClearance( track );
563 
564  if( !TestSegmentHit( aRef, track->GetStart(), track->GetEnd(), dist ) )
565  continue;
566 
567  found = track;
568 
569  // prefer intrusions from the side, not the end
570  wxPoint pos = aRef - track->GetStart();
571  wxPoint vec = track->GetEnd() - track->GetStart();
572  double tmp = (double) pos.x * vec.x + (double) pos.y * vec.y;
573 
574  if( tmp >= 0 && tmp <= (double) vec.x * vec.x + (double) vec.y * vec.y )
575  break;
576  }
577  }
578 
579  return found;
580 }
static const int dist[10][10]
Definition: dist.cpp:57
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
#define IS_DELETED
Definition: base_struct.h:116
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 599 of file editrack.cpp.

References dist, 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, Project(), EDA_DRAW_FRAME::RefPos(), TRACK::SetEnd(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

600 {
601  PCB_SCREEN* screen = (PCB_SCREEN*) panel->GetParent()->GetScreen();
602  BOARD* pcb = ( (PCB_BASE_FRAME*) (panel->GetParent()) )->GetBoard();
603  wxPoint cursor = panel->GetParent()->GetCrossHairPosition();
604  wxPoint cv, vec, n;
605  TRACK* track = g_CurrentTrackSegment;
606  TRACK* other;
607  double det;
608  int dist;
609  double f;
610 
611  other = LocateIntrusion( pcb->m_Track, track, screen->m_Active_Layer, panel->GetParent()->RefPos( true ) );
612 
613  // are we currently pointing into a conflicting trace ?
614  if( !other )
615  return;
616 
617  if( other->GetNetCode() == track->GetNetCode() )
618  return;
619 
620  cv = cursor - other->GetStart();
621  vec = other->GetEnd() - other->GetStart();
622 
623  det = (double) cv.x * vec.y - (double) cv.y * vec.x;
624 
625  // cursor is right at the center of the old track
626  if( !det )
627  return;
628 
629  dist = (track->GetWidth() + 1) / 2 + (other->GetWidth() + 1) / 2 + track->GetClearance( other ) + 2;
630 
631  /*
632  * DRC wants >, so +1.
633  * We may have a quantization error of 1/sqrt(2), so +1 again.
634  */
635 
636  // Vector "n" is perpendicular to "other", pointing towards the cursor.
637  if( det > 0 )
638  {
639  n.x = vec.y;
640  n.y = -vec.x;
641  }
642  else
643  {
644  n.x = -vec.y;
645  n.y = vec.x;
646  }
647 
648  f = dist / hypot( double(n.x), double(n.y) );
649  n.x = KiROUND( f * n.x );
650  n.y = KiROUND( f * n.y );
651 
652  wxPoint hp = track->GetEnd();
653  Project( &hp, cursor, other );
654  track->SetEnd( hp + n );
655 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:101
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:309
const wxPoint & GetStart() const
Definition: class_track.h:121
bool Project(wxPoint *aNearPos, wxPoint on_grid, const TRACK *track)
Finds the projection of a grid point on a track.
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
TRACK * LocateIntrusion(TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
Definition: editrack.cpp:541
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
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:166
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:244
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 673 of file editrack.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), BEGIN_ONPAD, PCB_BASE_FRAME::BuildAirWiresTargetsList(), CalculateSegmentEndPoint(), color, ComputeBreakPoint(), DARKCYAN, DBG, DO_NOT_SHOW_CLEARANCE, DrawTraces(), DrawViaCirclesWhenEditingNewTrack(), g_ColorsSettings, g_CurrentTrackList, g_CurrentTrackSegment, g_Drc_On, g_FirstTrackSegment, g_Track_45_Only_Allowed, g_TwoSegmentTrackBuild, 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, DISPLAY_OPTIONS::m_ShowTrackClearanceMode, BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, PCB_TRACE_T, PushTrack(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), TRACK::SetWidth(), SHOW_CLEARANCE_ALWAYS, SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS, PCB_BASE_FRAME::TraceAirWiresToTargets(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

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

675 {
676 // DBG( g_CurrentTrackList.VerifyListIntegrity(); );
677 
678  PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
679  PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
680  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) aPanel->GetDisplayOptions();
681 
682  bool tmp = displ_opts->m_DisplayPcbTrackFill;
683  displ_opts->m_DisplayPcbTrackFill = true;
684  TRACE_CLEARANCE_DISPLAY_MODE_T showTrackClearanceMode = displ_opts->m_ShowTrackClearanceMode;
685 
686  if ( g_FirstTrackSegment == NULL )
687  return;
688 
689  NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass();
690 
691  if( showTrackClearanceMode != DO_NOT_SHOW_CLEARANCE )
693 
694  // Values to Via circle
695  int boardViaRadius = frame->GetDesignSettings().GetCurrentViaSize()/2;
696  int viaRadiusWithClearence = boardViaRadius+netclass->GetClearance();
697  EDA_RECT* panelClipBox=aPanel->GetClipBox();
698 
699 #ifndef USE_WX_OVERLAY
700  // Erase old track
701  if( aErase )
702  {
704 
705  frame->TraceAirWiresToTargets( aDC );
706 
707  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
708  {
710  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
711  boardViaRadius, viaRadiusWithClearence, color);
712  }
713  }
714 #endif
715  // MacOSX seems to need this.
716  if( g_CurrentTrackList.GetCount() == 0 )
717  return;
718 
719  // Set track parameters, that can be modified while creating the track
720  g_CurrentTrackSegment->SetLayer( screen->m_Active_Layer );
721 
724 
726  {
727  TRACK* previous_track = g_CurrentTrackSegment->Back();
728 
729  if( previous_track && previous_track->Type()==PCB_TRACE_T )
730  {
731  previous_track->SetLayer( screen->m_Active_Layer );
732 
734  previous_track->SetWidth( frame->GetDesignSettings().GetCurrentTrackWidth() );
735  }
736  }
737 
739  {
741  {
742  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
743 
744  if( g_Drc_On )
745  PushTrack( aPanel );
746 
749  g_CurrentTrackSegment->GetEnd() );
750  }
751  else
752  {
753  /* Calculate of the end of the path for the permitted directions:
754  * horizontal, vertical or 45 degrees.
755  */
756  wxPoint hp = g_CurrentTrackSegment->GetEnd();
758  g_CurrentTrackSegment->GetStart().x,
759  g_CurrentTrackSegment->GetStart().y,
760  &hp.x,
761  &hp.y );
762  g_CurrentTrackSegment->SetEnd(hp);
763  }
764  }
765  else // Here the angle is arbitrary
766  {
767  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
768  }
769 
770  // Redraw the new track
771  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
773 
774  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
775  {
777 
778  //Via diameter must have taken what we are using, rather than netclass value.
779  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
780  boardViaRadius, viaRadiusWithClearence, color);
781 
782  }
783 
784  /* Display info about current segment and the full new track:
785  * Choose the interesting segment: because we are using a 2 segments step,
786  * the last segment can be null, and the previous segment can be the
787  * interesting segment.
788  */
789  TRACK* isegm = g_CurrentTrackSegment;
790 
791  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
792  isegm = g_CurrentTrackSegment->Back();
793 
794  // display interesting segment info only:
795  frame->SetMsgPanel( isegm );
796 
797  // Display current track length (on board) and the the actual track len
798  // if there is an extra len due to the len die on the starting pad (if any)
799  double trackLen = 0.0;
800  double lenPadToDie = 0.0;
801  wxString msg;
802 
803  // If the starting point is on a pad, add current track length+ length die
804  if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) )
805  {
806  D_PAD * pad = (D_PAD *) g_FirstTrackSegment->start;
807  lenPadToDie = (double) pad->GetPadToDieLength();
808  }
809 
810  // calculate track len on board:
811  for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
812  trackLen += track->GetLength();
813 
814  msg = frame->LengthDoubleToString( trackLen );
815  frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN );
816 
817  if( lenPadToDie != 0 ) // display the track len on board and the actual track len
818  {
819  frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN );
820  msg = frame->LengthDoubleToString( trackLen+lenPadToDie );
821  frame->AppendMsgPanel( _( "Pad to die" ), msg, DARKCYAN );
822  }
823 
824  // Add current segments count (number of segments in this new track):
825  msg.Printf( wxT( "%d" ), g_CurrentTrackList.GetCount() );
826  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
827 
828  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
829  displ_opts->m_DisplayPcbTrackFill = tmp;
830 
831  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(), false );
832  frame->TraceAirWiresToTargets( aDC );
833 }
#define g_FirstTrackSegment
first segment created
Definition: pcbnew.h:102
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:101
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void TraceAirWiresToTargets(wxDC *aDC)
Function TraceAirWiresToTargets This functions shows airwires to nearest connecting points (pads) fro...
Definition: ratsnest.cpp:915
bool g_Drc_On
Definition: pcbnew.cpp:70
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
int GetPadToDieLength() const
Definition: class_pad.h:241
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:132
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
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:599
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:754
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:798
void BuildAirWiresTargetsList(BOARD_CONNECTED_ITEM *aItemRef, const wxPoint &aPosition, bool aInit)
Function BuildAirWiresTargetsList Build a list of candidates that can be a coonection point when a tr...
Definition: ratsnest.cpp:836
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:175
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
void CalculateSegmentEndPoint(const wxPoint &aPosition, int ox, int oy, int *fx, int *fy)
Determine coordinate for a segment direction of 0, 90, or 45 degrees depending on it's position from ...
Definition: editrack.cpp:839
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:734
void DrawViaCirclesWhenEditingNewTrack(EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
Definition: editrack.cpp:659
bool g_Track_45_Only_Allowed
Definition: pcbnew.cpp:74
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:900
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
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:182
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:48
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool g_TwoSegmentTrackBuild
Definition: pcbnew.cpp:76
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.