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)
 
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...
 
bool Project (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

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 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:97
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:97
int GetWidth() const
Definition: class_track.h:114
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
bool Project ( 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:117
const wxPoint & GetStart() const
Definition: class_track.h:120
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
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(), 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
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
int GetPadToDieLength() const
Definition: class_pad.h:241
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:132
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:113
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:751
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:795
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:731
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
LAYER_ID m_Active_Layer
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:170
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