KiCad PCB EDA Suite
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 800 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().

801 {
802  // Determine end point for a segment direction 0, 90, or 45 degrees
803  // depending on it's position from the origin \a aOrigin and \a aPosition.
804  wxPoint endPoint;
805 
806  int deltax = aPosition.x - aOrigin.x;
807  int deltay = aPosition.y - aOrigin.y;
808 
809  deltax = abs( deltax );
810  deltay = abs( deltay );
811  int angle = 45;
812 
813  if( deltax >= deltay )
814  {
815  if( deltax == 0 )
816  angle = 0;
817  else if( ( (deltay << 6 ) / deltax ) < 26 )
818  angle = 0;
819  }
820  else
821  {
822  angle = 45;
823 
824  if( deltay == 0 )
825  angle = 90;
826  else if( ( (deltax << 6 ) / deltay ) < 26 )
827  angle = 90;
828  }
829 
830  switch( angle )
831  {
832  case 0:
833  endPoint.x = aPosition.x;
834  endPoint.y = aOrigin.y;
835  break;
836 
837  case 45:
838  deltax = std::min( deltax, deltay );
839  deltay = deltax;
840 
841  // Recalculate the signs for deltax and deltaY.
842  if( ( aPosition.x - aOrigin.x ) < 0 )
843  deltax = -deltax;
844 
845  if( ( aPosition.y - aOrigin.y ) < 0 )
846  deltay = -deltay;
847 
848  endPoint.x = aOrigin.x + deltax;
849  endPoint.y = aOrigin.y + deltay;
850  break;
851 
852  case 90:
853  endPoint.x = aOrigin.x;
854  endPoint.y = aPosition.y;
855  break;
856  }
857 
858  return endPoint;
859 }
#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 229 of file editrack-part2.cpp.

References TRACK::Next().

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

231 {
232  // preserve the start of the list for debugging.
233  for( TRACK* track = aTrackList; nbsegment > 0 && track; nbsegment--, track = track->Next() )
234  {
235  track->Draw( panel, DC, draw_mode );
236  }
237 }
TRACK * Next() const
Definition: class_track.h:99
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)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
const wxPoint & GetEnd() const
Definition: class_track.h:119
const wxPoint & GetStart() const
Definition: class_track.h:122
#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 533 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().

534 {
535  int net = aTrack->GetNetCode();
536  int width = aTrack->GetWidth();
537 
538  TRACK* found = NULL;
539 
540  for( TRACK* track = listStart; track; track = track->Next() )
541  {
542  if( track->Type() == PCB_TRACE_T ) // skip vias
543  {
544  if( track->GetState( BUSY | IS_DELETED ) )
545  continue;
546 
547  if( aLayer != track->GetLayer() )
548  continue;
549 
550  if( track->GetNetCode() == net )
551  continue;
552 
553  // TRACK::HitTest
554  int dist = (width + track->GetWidth()) / 2 + aTrack->GetClearance( track );
555 
556  if( !TestSegmentHit( aRef, track->GetStart(), track->GetEnd(), dist ) )
557  continue;
558 
559  found = track;
560 
561  // prefer intrusions from the side, not the end
562  wxPoint pos = aRef - track->GetStart();
563  wxPoint vec = track->GetEnd() - track->GetStart();
564  double tmp = (double) pos.x * vec.x + (double) pos.y * vec.y;
565 
566  if( tmp >= 0 && tmp <= (double) vec.x * vec.x + (double) vec.y * vec.y )
567  break;
568  }
569  }
570 
571  return found;
572 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:135
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
#define IS_DELETED
Definition: base_struct.h:117
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:99
int GetWidth() const
Definition: class_track.h:116
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
void ShowNewTrackWhenMovingCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)

Definition at line 665 of file editrack.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), PCB_BASE_FRAME::BuildAirWiresTargetsList(), CalculateSegmentEndPoint(), color, PCB_GENERAL_SETTINGS::Colors(), ComputeBreakPoint(), DARKCYAN, DBG, PCB_DISPLAY_OPTIONS::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(), PCB_BASE_FRAME::GetDisplayOptions(), COLORS_DESIGN_SETTINGS::GetLayerColor(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_XOR, PCB_SCREEN::m_Active_Layer, PCB_GENERAL_SETTINGS::m_legacyDrcOn, PCB_GENERAL_SETTINGS::m_legacyUse45DegreeTracks, PCB_GENERAL_SETTINGS::m_legacyUseTwoSegmentTracks, BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, PCB_TRACE_T, PushTrack(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), PCB_BASE_FRAME::Settings(), TRACK::SetWidth(), PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_ALWAYS, PCB_DISPLAY_OPTIONS::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().

667 {
668 // DBG( g_CurrentTrackList.VerifyListIntegrity(); );
669 
670  PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
671  PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
672  auto displ_opts = (PCB_DISPLAY_OPTIONS*) aPanel-> GetDisplayOptions();
673 
674  bool tmp = displ_opts->m_DisplayPcbTrackFill;
675  displ_opts->m_DisplayPcbTrackFill = true;
676  auto showTrackClearanceMode = displ_opts->m_ShowTrackClearanceMode;
677 
678  if ( g_FirstTrackSegment == NULL )
679  return;
680 
681  NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass();
682 
683  if( showTrackClearanceMode != PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE )
684  displ_opts->m_ShowTrackClearanceMode = PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_ALWAYS;
685 
686  // Values to Via circle
687  int boardViaRadius = frame->GetDesignSettings().GetCurrentViaSize()/2;
688  int viaRadiusWithClearence = boardViaRadius+netclass->GetClearance();
689  EDA_RECT* panelClipBox=aPanel->GetClipBox();
690 
691 #ifndef USE_WX_OVERLAY
692  // Erase old track
693  if( aErase )
694  {
696 
697  frame->TraceAirWiresToTargets( aDC );
698 
700  {
701  COLOR4D color = frame->Settings().Colors().GetLayerColor( g_CurrentTrackSegment->GetLayer() );
702  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
703  boardViaRadius, viaRadiusWithClearence, color);
704  }
705  }
706 #endif
707  // MacOSX seems to need this.
708  if( g_CurrentTrackList.GetCount() == 0 )
709  return;
710 
711  // Set track parameters, that can be modified while creating the track
712  g_CurrentTrackSegment->SetLayer( screen->m_Active_Layer );
713 
716 
718  {
719  TRACK* previous_track = g_CurrentTrackSegment->Back();
720 
721  if( previous_track && previous_track->Type()==PCB_TRACE_T )
722  {
723  previous_track->SetLayer( screen->m_Active_Layer );
724 
726  previous_track->SetWidth( frame->GetDesignSettings().GetCurrentTrackWidth() );
727  }
728  }
729 
730  if( frame->Settings().m_legacyUse45DegreeTracks )
731  {
733  {
734  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
735 
736  if( frame->Settings().m_legacyDrcOn )
737  PushTrack( aPanel );
738 
741  g_CurrentTrackSegment->GetEnd() );
742  }
743  else
744  {
745  /* Calculate of the end of the path for the permitted directions:
746  * horizontal, vertical or 45 degrees.
747  */
748  wxPoint hp = g_CurrentTrackSegment->GetEnd();
750  g_CurrentTrackSegment->GetStart() );
751  g_CurrentTrackSegment->SetEnd(hp);
752  }
753  }
754  else // Here the angle is arbitrary
755  {
756  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
757  }
758 
759  // Redraw the new track
760  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
762 
764  {
765  COLOR4D color = frame->Settings().Colors().GetLayerColor(g_CurrentTrackSegment->GetLayer());
766 
767  //Via diameter must have taken what we are using, rather than netclass value.
768  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
769  boardViaRadius, viaRadiusWithClearence, color);
770 
771  }
772 
773  /* Display info about current segment and the full new track:
774  * Choose the interesting segment: because we are using a 2 segments step,
775  * the last segment can be null, and the previous segment can be the
776  * interesting segment.
777  */
778  TRACK* isegm = g_CurrentTrackSegment;
779 
780  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
781  isegm = g_CurrentTrackSegment->Back();
782 
783  // display track info:
784  frame->SetMsgPanel( isegm );
785  wxString msg;
786 
787  // Display current segments count (number of segments in this new track):
788  msg.Printf( "%d", g_CurrentTrackList.GetCount() );
789  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
790 
791  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
792  displ_opts->m_DisplayPcbTrackFill = tmp;
793 
794  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(),
795  g_CurrentTrackSegment->GetNetCode() );
796  frame->TraceAirWiresToTargets( aDC );
797 }
virtual BASE_SCREEN * GetScreen()=0
#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:201
void TraceAirWiresToTargets(wxDC *aDC)
Function TraceAirWiresToTargets This functions shows airwires to nearest connecting points (pads) fro...
Definition: ratsnest.cpp:205
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:90
int color
Definition: DXF_plotter.cpp:62
virtual EDA_RECT * GetClipBox()
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:182
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:44
int GetCurrentViaSize() const
Function GetCurrentViaSize.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
wxPoint CalculateSegmentEndPoint(const wxPoint &aPosition, const wxPoint &aOrigin)
Determine end point for a segment direction 0, 90, or 45 degrees depending on it&#39;s position from the ...
Definition: editrack.cpp:800
void SetWidth(int aWidth)
Definition: class_track.h:115
virtual EDA_DRAW_FRAME * GetParent() const =0
static void PushTrack(EDA_DRAW_PANEL *panel)
Function PushTrack detects if the mouse is pointing into a conflicting track.
Definition: editrack.cpp:591
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
PCB_GENERAL_SETTINGS & Settings()
void DrawTraces(EDA_DRAW_PANEL *panel, wxDC *DC, TRACK *aTrackList, int nbsegment, GR_DRAWMODE draw_mode)
Function DrawTraces Draws n consecutive track segments in list.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
COLORS_DESIGN_SETTINGS & Colors()
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void DrawViaCirclesWhenEditingNewTrack(EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
Definition: editrack.cpp:651
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static void ComputeBreakPoint(TRACK *track, int n, wxPoint end)
Compute new track angle based on previous track.
Definition: editrack.cpp:865
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
#define DBG(x)
Definition: fctsys.h:33
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
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...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39