KiCad PCB EDA Suite
pcbnew/protos.h File Reference
#include <gr_basic.h>

Go to the source code of this file.

Functions

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. More...
 
void ShowNewTrackWhenMovingCursor (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
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...
 
bool FindBestGridPointOnTrack (wxPoint *res, wxPoint on_grid, const TRACK *track)
 Finds the projection of a grid point on a track. More...
 
TRACKLocateIntrusion (TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
 

Function Documentation

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 832 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().

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

Function DrawTraces Draws n consecutive track segments in list.

Useful to show a track when it is a chain of segments (for instance when creating a new track)

Parameters
panelA EDA_DRAW_ITEM pointer to the canvas.
DCA wxDC pointer of the device context used for drawing.
aStartTraceFirst segment
nbsegmentNumber of segments in list
mode_colorDrawing mode (GRXOR, GROR ..)

Definition at line 49 of file tr_modif.cpp.

References TRACK::Next().

Referenced by AddNewTrace(), PCB_EDIT_FRAME::Attribut_Track(), PCB_EDIT_FRAME::End_Route(), PCB_EDIT_FRAME::EraseRedundantTrack(), and ShowNewTrackWhenMovingCursor().

51 {
52  // preserve the start of the list for debugging.
53  for( TRACK* track = aTrackList; nbsegment > 0 && track; nbsegment--, track = track->Next() )
54  {
55  track->Draw( panel, DC, draw_mode );
56  }
57 }
TRACK * Next() const
Definition: class_track.h:98
bool FindBestGridPointOnTrack ( wxPoint res,
wxPoint  on_grid,
const TRACK track 
)

Finds the projection of a grid point on a track.

This is the point from where we want to draw new orthogonal tracks when starting on a track.

Definition at line 97 of file magnetic_tracks_functions.cpp.

References TRACK::GetEnd(), TRACK::GetStart(), KiROUND(), max, min, wxPoint::x, and wxPoint::y.

Referenced by Magnetize(), and PushTrack().

98 {
99  if( track->GetStart ()== track->GetEnd() )
100  return false;
101 
102  wxPoint vec = track->GetEnd() - track->GetStart();
103 
104  double t = double( on_grid.x - track->GetStart().x ) * vec.x +
105  double( on_grid.y - track->GetStart().y ) * vec.y;
106 
107  t /= (double) vec.x * vec.x + (double) vec.y * vec.y;
108  t = std::min( std::max( t, 0.0 ), 1.0 );
109 
110  aNearPos->x = KiROUND( track->GetStart().x + t * vec.x );
111  aNearPos->y = KiROUND( track->GetStart().y + t * vec.y );
112 
113  return true;
114 }
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
const wxPoint & GetEnd() const
Definition: class_track.h:118
const wxPoint & GetStart() const
Definition: class_track.h:121
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
TRACK* LocateIntrusion ( TRACK listStart,
TRACK aTrack,
LAYER_NUM  aLayer,
const wxPoint aRef 
)

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

541 {
542  int net = aTrack->GetNetCode();
543  int width = aTrack->GetWidth();
544 
545  TRACK* found = NULL;
546 
547  for( TRACK* track = listStart; track; track = track->Next() )
548  {
549  if( track->Type() == PCB_TRACE_T ) // skip vias
550  {
551  if( track->GetState( BUSY | IS_DELETED ) )
552  continue;
553 
554  if( aLayer != track->GetLayer() )
555  continue;
556 
557  if( track->GetNetCode() == net )
558  continue;
559 
560  // TRACK::HitTest
561  int dist = (width + track->GetWidth()) / 2 + aTrack->GetClearance( track );
562 
563  if( !TestSegmentHit( aRef, track->GetStart(), track->GetEnd(), dist ) )
564  continue;
565 
566  found = track;
567 
568  // prefer intrusions from the side, not the end
569  wxPoint pos = aRef - track->GetStart();
570  wxPoint vec = track->GetEnd() - track->GetStart();
571  double tmp = (double) pos.x * vec.x + (double) pos.y * vec.y;
572 
573  if( tmp >= 0 && tmp <= (double) vec.x * vec.x + (double) vec.y * vec.y )
574  break;
575  }
576  }
577 
578  return found;
579 }
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
void ShowNewTrackWhenMovingCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)

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

674 {
675 // DBG( g_CurrentTrackList.VerifyListIntegrity(); );
676 
677  PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
678  PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
679  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) aPanel->GetDisplayOptions();
680 
681  bool tmp = displ_opts->m_DisplayPcbTrackFill;
682  displ_opts->m_DisplayPcbTrackFill = true;
683  TRACE_CLEARANCE_DISPLAY_MODE_T showTrackClearanceMode = displ_opts->m_ShowTrackClearanceMode;
684 
685  if ( g_FirstTrackSegment == NULL )
686  return;
687 
688  NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass();
689 
690  if( showTrackClearanceMode != DO_NOT_SHOW_CLEARANCE )
692 
693  // Values to Via circle
694  int boardViaRadius = frame->GetDesignSettings().GetCurrentViaSize()/2;
695  int viaRadiusWithClearence = boardViaRadius+netclass->GetClearance();
696  EDA_RECT* panelClipBox=aPanel->GetClipBox();
697 
698 #ifndef USE_WX_OVERLAY
699  // Erase old track
700  if( aErase )
701  {
703 
704  frame->TraceAirWiresToTargets( aDC );
705 
706  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
707  {
709  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
710  boardViaRadius, viaRadiusWithClearence, color);
711  }
712  }
713 #endif
714  // MacOSX seems to need this.
715  if( g_CurrentTrackList.GetCount() == 0 )
716  return;
717 
718  // Set track parameters, that can be modified while creating the track
719  g_CurrentTrackSegment->SetLayer( screen->m_Active_Layer );
720 
723 
725  {
726  TRACK* previous_track = g_CurrentTrackSegment->Back();
727 
728  if( previous_track && previous_track->Type()==PCB_TRACE_T )
729  {
730  previous_track->SetLayer( screen->m_Active_Layer );
731 
733  previous_track->SetWidth( frame->GetDesignSettings().GetCurrentTrackWidth() );
734  }
735  }
736 
738  {
740  {
741  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
742 
743  if( g_Drc_On )
744  PushTrack( aPanel );
745 
748  g_CurrentTrackSegment->GetEnd() );
749  }
750  else
751  {
752  /* Calculate of the end of the path for the permitted directions:
753  * horizontal, vertical or 45 degrees.
754  */
755  wxPoint hp = g_CurrentTrackSegment->GetEnd();
757  g_CurrentTrackSegment->GetStart() );
758  g_CurrentTrackSegment->SetEnd(hp);
759  }
760  }
761  else // Here the angle is arbitrary
762  {
763  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
764  }
765 
766  // Redraw the new track
767  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
769 
770  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
771  {
773 
774  //Via diameter must have taken what we are using, rather than netclass value.
775  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
776  boardViaRadius, viaRadiusWithClearence, color);
777 
778  }
779 
780  /* Display info about current segment and the full new track:
781  * Choose the interesting segment: because we are using a 2 segments step,
782  * the last segment can be null, and the previous segment can be the
783  * interesting segment.
784  */
785  TRACK* isegm = g_CurrentTrackSegment;
786 
787  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
788  isegm = g_CurrentTrackSegment->Back();
789 
790  // display interesting segment info only:
791  frame->SetMsgPanel( isegm );
792 
793  // Display current track length (on board) and the the actual track len
794  // if there is an extra len due to the len die on the starting pad (if any)
795  double trackLen = 0.0;
796  double lenPadToDie = 0.0;
797  wxString msg;
798 
799  // If the starting point is on a pad, add current track length+ length die
800  if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) )
801  {
802  D_PAD* pad = (D_PAD*) g_FirstTrackSegment->start;
803  lenPadToDie = (double) pad->GetPadToDieLength();
804  }
805 
806  // calculate track len on board:
807  for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
808  trackLen += track->GetLength();
809 
810  msg = frame->LengthDoubleToString( trackLen );
811  frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN );
812 
813  if( lenPadToDie != 0 ) // display the track len on board and the actual track len
814  {
815  frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN );
816  msg = frame->LengthDoubleToString( trackLen+lenPadToDie );
817  frame->AppendMsgPanel( _( "Pad to die" ), msg, DARKCYAN );
818  }
819 
820  // Add current segments count (number of segments in this new track):
821  msg.Printf( wxT( "%d" ), g_CurrentTrackList.GetCount() );
822  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
823 
824  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
825  displ_opts->m_DisplayPcbTrackFill = tmp;
826 
827  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(), g_CurrentTrackSegment->GetNetCode() );
828  frame->TraceAirWiresToTargets( aDC );
829 }
#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:194
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
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:171
#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:832
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:598
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:773
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:817
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:753
void DrawViaCirclesWhenEditingNewTrack(EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
Definition: editrack.cpp:658
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:897
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:49
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