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

50 {
51  // preserve the start of the list for debugging.
52  for( TRACK* track = aTrackList; nbsegment > 0 && track; nbsegment--, track = track->Next() )
53  {
54  track->Draw( panel, DC, draw_mode );
55  }
56 }
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 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
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