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 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 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 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
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:384
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