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)
 
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: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...
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 833 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().

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

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

1003 {
1004  if( aTrackList.GetCount() == 0 )
1005  return;
1006 
1007  TRACK* track = aTrackList.GetFirst();
1008  TRACK* firsttrack = track;
1009  TRACK* oldtrack;
1010 
1011  BOARD_CONNECTED_ITEM* lockPoint = track->start;
1012 
1013  while( track != NULL )
1014  {
1015  oldtrack = track;
1016  track = track->Next();
1017 
1018  if( !oldtrack->IsNull() )
1019  {
1020  continue;
1021  }
1022 
1023  // NULL segment, delete it
1024  if( firsttrack == oldtrack )
1025  firsttrack = track;
1026 
1027  delete aTrackList.Remove( oldtrack );
1028  }
1029 
1030  if( aTrackList.GetCount() == 0 )
1031  return; // all the new track segments have been deleted
1032 
1033  // we must set the pointers on connected items and the connection status
1034  oldtrack = track = firsttrack;
1035  firsttrack->start = NULL;
1036 
1037  while( track != NULL )
1038  {
1039  oldtrack = track;
1040  track = track->Next();
1041  oldtrack->end = track;
1042 
1043  if( track )
1044  track->start = oldtrack;
1045 
1046  oldtrack->SetStatus( 0 );
1047  }
1048 
1049  firsttrack->start = lockPoint;
1050 
1051  if( lockPoint && lockPoint->Type()==PCB_PAD_T )
1052  firsttrack->SetState( BEGIN_ONPAD, true );
1053 
1054  track = firsttrack;
1055 
1056  while( track != NULL )
1057  {
1058  TRACK* next_track = track->Next();
1059  lockPoint = pcb->GetPad( track, ENDPOINT_END );
1060 
1061  if( lockPoint )
1062  {
1063  track->end = lockPoint;
1064  track->SetState( END_ONPAD, true );
1065 
1066  if( next_track )
1067  {
1068  next_track->start = lockPoint;
1069  next_track->SetState( BEGIN_ONPAD, true );
1070  }
1071  }
1072 
1073  track = next_track;
1074  }
1075 }
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 clearance 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 1082 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().

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

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  FindBestGridPointOnTrack( &hp, cursor, other );
654  track->SetEnd( hp + n );
655 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:100
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
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.
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: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(), 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().

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() );
759  g_CurrentTrackSegment->SetEnd(hp);
760  }
761  }
762  else // Here the angle is arbitrary
763  {
764  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
765  }
766 
767  // Redraw the new track
768  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
770 
771  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
772  {
774 
775  //Via diameter must have taken what we are using, rather than netclass value.
776  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
777  boardViaRadius, viaRadiusWithClearence, color);
778 
779  }
780 
781  /* Display info about current segment and the full new track:
782  * Choose the interesting segment: because we are using a 2 segments step,
783  * the last segment can be null, and the previous segment can be the
784  * interesting segment.
785  */
786  TRACK* isegm = g_CurrentTrackSegment;
787 
788  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
789  isegm = g_CurrentTrackSegment->Back();
790 
791  // display interesting segment info only:
792  frame->SetMsgPanel( isegm );
793 
794  // Display current track length (on board) and the the actual track len
795  // if there is an extra len due to the len die on the starting pad (if any)
796  double trackLen = 0.0;
797  double lenPadToDie = 0.0;
798  wxString msg;
799 
800  // If the starting point is on a pad, add current track length+ length die
801  if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) )
802  {
803  D_PAD * pad = (D_PAD *) g_FirstTrackSegment->start;
804  lenPadToDie = (double) pad->GetPadToDieLength();
805  }
806 
807  // calculate track len on board:
808  for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
809  trackLen += track->GetLength();
810 
811  msg = frame->LengthDoubleToString( trackLen );
812  frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN );
813 
814  if( lenPadToDie != 0 ) // display the track len on board and the actual track len
815  {
816  frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN );
817  msg = frame->LengthDoubleToString( trackLen+lenPadToDie );
818  frame->AppendMsgPanel( _( "Pad to die" ), msg, DARKCYAN );
819  }
820 
821  // Add current segments count (number of segments in this new track):
822  msg.Printf( wxT( "%d" ), g_CurrentTrackList.GetCount() );
823  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
824 
825  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
826  displ_opts->m_DisplayPcbTrackFill = tmp;
827 
828  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(), false );
829  frame->TraceAirWiresToTargets( aDC );
830 }
#define g_FirstTrackSegment
first segment created
Definition: pcbnew.h:101
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:100
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
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:833
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
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:898
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.