From f1069929dfcc903ec40401deb205d3a3581b12df Mon Sep 17 00:00:00 2001 From: Lorenzo Marcantonio Date: Fri, 25 Apr 2014 19:13:33 +0200 Subject: [PATCH] Reworked the endpoint designator constants FLG_BEGIN and FLG_END in a ENDPOINT_T enum type --- pcbnew/autorouter/solve.cpp | 6 ++++-- pcbnew/class_board.cpp | 15 +++------------ pcbnew/class_board.h | 2 +- pcbnew/class_track.cpp | 11 +++-------- pcbnew/class_track.h | 13 ++++++++++++- pcbnew/clean.cpp | 30 +++++++++++++++--------------- pcbnew/editrack.cpp | 4 ++-- pcbnew/move_or_drag_track.cpp | 8 ++++---- pcbnew/pcbnew.h | 8 +++++--- 9 files changed, 49 insertions(+), 48 deletions(-) diff --git a/pcbnew/autorouter/solve.cpp b/pcbnew/autorouter/solve.cpp index 5e94db6b09..8ddf52f040 100644 --- a/pcbnew/autorouter/solve.cpp +++ b/pcbnew/autorouter/solve.cpp @@ -1300,12 +1300,14 @@ static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) g_CurrentTrackList.PushBack( newTrack ); } - g_FirstTrackSegment->start = pcbframe->GetBoard()->GetPad( g_FirstTrackSegment, FLG_START ); + g_FirstTrackSegment->start = pcbframe->GetBoard()->GetPad( g_FirstTrackSegment, + ENDPOINT_START ); if( g_FirstTrackSegment->start ) g_FirstTrackSegment->SetState( BEGIN_ONPAD, true ); - g_CurrentTrackSegment->end = pcbframe->GetBoard()->GetPad( g_CurrentTrackSegment, FLG_END ); + g_CurrentTrackSegment->end = pcbframe->GetBoard()->GetPad( g_CurrentTrackSegment, + ENDPOINT_END ); if( g_CurrentTrackSegment->end ) g_CurrentTrackSegment->SetState( END_ONPAD, true ); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 6109e60945..2960e9e315 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1598,22 +1598,13 @@ D_PAD* BOARD::GetPad( const wxPoint& aPosition, LAYER_MSK aLayerMask ) } -D_PAD* BOARD::GetPad( TRACK* aTrace, int aEndPoint ) +D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint ) { D_PAD* pad = NULL; - wxPoint aPosition; + const wxPoint &aPosition = aTrace->GetEndPoint( aEndPoint ); LAYER_MSK aLayerMask = GetLayerMask( aTrace->GetLayer() ); - if( aEndPoint == FLG_START ) - { - aPosition = aTrace->GetStart(); - } - else - { - aPosition = aTrace->GetEnd(); - } - for( MODULE* module = m_Modules; module; module = module->Next() ) { pad = module->GetPad( aPosition, aLayerMask ); @@ -2195,7 +2186,7 @@ TRACK* BOARD::CreateLockPoint( wxPoint& aPosition, TRACK* aSegment, PICKED_ITEMS aSegment->end = newTrack; aSegment->SetState( END_ONPAD, false ); - D_PAD * pad = GetPad( newTrack, FLG_START ); + D_PAD * pad = GetPad( newTrack, ENDPOINT_START ); if ( pad ) { diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index d899096819..516d09ca1f 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -1392,7 +1392,7 @@ public: * @param aEndPoint The end point of \a aTrace the hit test against. * @return A pointer to a D_PAD object if found or NULL if not found. */ - D_PAD* GetPad( TRACK* aTrace, int aEndPoint ); + D_PAD* GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint ); /** * Function GetPadFast diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index d1564f0066..abf4d7a732 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -70,7 +70,7 @@ static bool ShowClearance( const TRACK* aTrack ) * return true if the dist between p1 and p2 < max_dist * Currently in test (currently ratsnest algos work only if p1 == p2) */ -inline bool IsNear( wxPoint& p1, wxPoint& p2, int max_dist ) +inline bool IsNear( const wxPoint& p1, const wxPoint& p2, int max_dist ) { #if 0 // Do not change it: does not work int dist; @@ -1320,21 +1320,16 @@ VIA* TRACK::GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LAYER_MSK aLayer } -TRACK* TRACK::GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, int aEndPoint ) +TRACK* TRACK::GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, ENDPOINT_T aEndPoint ) { const int NEIGHTBOUR_COUNT_MAX = 50; TRACK* previousSegment; TRACK* nextSegment; int Reflayer; - wxPoint position; int ii; int max_dist; - - if( aEndPoint == FLG_START ) - position = m_Start; - else - position = m_End; + const wxPoint &position = GetEndPoint( aEndPoint ); Reflayer = GetLayerMask(); diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index 34b651094a..63c9026967 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -31,6 +31,7 @@ #define CLASS_TRACK_H +#include #include #include #include @@ -124,6 +125,16 @@ public: void SetStart( const wxPoint& aStart ) { m_Start = aStart; } const wxPoint& GetStart() const { return m_Start; } + + /// Return the selected endpoint (start or end) + const wxPoint& GetEndPoint( ENDPOINT_T aEndPoint ) const + { + if( aEndPoint == ENDPOINT_START ) + return m_Start; + else + return m_End; + } + // Virtual function const EDA_RECT GetBoundingBox() const; @@ -252,7 +263,7 @@ public: * @param aEndPoint The start or end point of the segment to test against. * @return A TRACK object pointer if found otherwise NULL. */ - TRACK* GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, int aEndPoint ); + TRACK* GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, ENDPOINT_T aEndPoint ); /** * Function GetEndSegments diff --git a/pcbnew/clean.cpp b/pcbnew/clean.cpp index 443394157d..9bf5a83c95 100644 --- a/pcbnew/clean.cpp +++ b/pcbnew/clean.cpp @@ -86,7 +86,7 @@ private: * i.e. when they are colinear, same width, and obviously same layer */ TRACK* mergeCollinearSegmentIfPossible( TRACK* aTrackRef, - TRACK* aCandidate, int aEndType ); + TRACK* aCandidate, ENDPOINT_T aEndType ); }; /* Install the cleanup dialog frame to know what should be cleaned @@ -304,7 +304,7 @@ bool TRACKS_CLEANER::deleteUnconnectedTracks() if( (type_end & START_ON_PAD ) == 0 ) { - TRACK* other = track->GetTrack( m_Brd->m_Track, NULL, FLG_START ); + TRACK* other = track->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_START ); if( other == NULL ) // Test a connection to zones { @@ -341,7 +341,7 @@ bool TRACKS_CLEANER::deleteUnconnectedTracks() track->SetState( BUSY, true ); VIA* via = (VIA*) other; - other = via->GetTrack( m_Brd->m_Track, NULL, FLG_START ); + other = via->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_START ); if( other == NULL ) { @@ -364,7 +364,7 @@ bool TRACKS_CLEANER::deleteUnconnectedTracks() // test if this track end point is connected to an other track if( (type_end & END_ON_PAD ) == 0 ) { - TRACK* other = track->GetTrack( m_Brd->m_Track, NULL, FLG_END ); + TRACK* other = track->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_END ); if( other == NULL ) // Test a connection to zones { @@ -402,7 +402,7 @@ bool TRACKS_CLEANER::deleteUnconnectedTracks() track->SetState( BUSY, true ); VIA* via = (VIA*) other; - other = via->GetTrack( m_Brd->m_Track, NULL, FLG_END ); + other = via->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_END ); if( other == NULL ) { @@ -508,7 +508,7 @@ bool TRACKS_CLEANER::clean_segments() // search for a possible point connected to the START point of the current segment for( segStart = segment->Next(); ; ) { - segStart = segment->GetTrack( segStart, NULL, FLG_START ); + segStart = segment->GetTrack( segStart, NULL, ENDPOINT_START ); if( segStart ) { @@ -522,7 +522,7 @@ bool TRACKS_CLEANER::clean_segments() // We must have only one segment connected segStart->SetState( BUSY, true ); - other = segment->GetTrack( m_Brd->m_Track, NULL, FLG_START ); + other = segment->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_START ); segStart->SetState( BUSY, false ); if( other == NULL ) @@ -535,7 +535,7 @@ bool TRACKS_CLEANER::clean_segments() if( flag ) // We have the starting point of the segment is connected to an other segment { - segDelete = mergeCollinearSegmentIfPossible( segment, segStart, FLG_START ); + segDelete = mergeCollinearSegmentIfPossible( segment, segStart, ENDPOINT_START ); if( segDelete ) { @@ -548,7 +548,7 @@ bool TRACKS_CLEANER::clean_segments() // search for a possible point connected to the END point of the current segment: for( segEnd = segment->Next(); ; ) { - segEnd = segment->GetTrack( segEnd, NULL, FLG_END ); + segEnd = segment->GetTrack( segEnd, NULL, ENDPOINT_END ); if( segEnd ) { @@ -560,7 +560,7 @@ bool TRACKS_CLEANER::clean_segments() // We must have only one segment connected segEnd->SetState( BUSY, true ); - other = segment->GetTrack( m_Brd->m_Track, NULL, FLG_END ); + other = segment->GetTrack( m_Brd->m_Track, NULL, ENDPOINT_END ); segEnd->SetState( BUSY, false ); if( other == NULL ) @@ -576,7 +576,7 @@ bool TRACKS_CLEANER::clean_segments() if( flag & 2 ) // We have the ending point of the segment is connected to an other segment { - segDelete = mergeCollinearSegmentIfPossible( segment, segEnd, FLG_END ); + segDelete = mergeCollinearSegmentIfPossible( segment, segEnd, ENDPOINT_END ); if( segDelete ) { @@ -607,7 +607,7 @@ bool TRACKS_CLEANER::clean_segments() * else return NULL */ TRACK* TRACKS_CLEANER::mergeCollinearSegmentIfPossible( TRACK* aTrackRef, TRACK* aCandidate, - int aEndType ) + ENDPOINT_T aEndType ) { if( aTrackRef->GetWidth() != aCandidate->GetWidth() ) return NULL; @@ -667,7 +667,7 @@ TRACK* TRACKS_CLEANER::mergeCollinearSegmentIfPossible( TRACK* aTrackRef, TRACK* * (this function) is called when there is only 2 connected segments, *and if this point is not on a pad, it can be removed and the 2 segments will be merged */ - if( aEndType == FLG_START ) + if( aEndType == ENDPOINT_START ) { // We do not have a pad, which is a always terminal point for a track if( aTrackRef->GetState( START_ON_PAD) ) @@ -744,7 +744,7 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks() } else { - other = segment->GetTrack( GetBoard()->m_Track, NULL, FLG_START ); + other = segment->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_START ); if( other ) net_code_s = other->GetNetCode(); @@ -762,7 +762,7 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks() } else { - other = segment->GetTrack( GetBoard()->m_Track, NULL, FLG_END ); + other = segment->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_END ); if( other ) net_code_e = other->GetNetCode(); diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 41cc2d7e30..683b7d41d7 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -266,7 +266,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* aDC ) newTrack->SetState( BEGIN_ONPAD | END_ONPAD, false ); - D_PAD* pad = GetBoard()->GetPad( previousTrack, FLG_END ); + D_PAD* pad = GetBoard()->GetPad( previousTrack, ENDPOINT_END ); if( pad ) { @@ -1057,7 +1057,7 @@ void DeleteNullTrackSegments( BOARD* pcb, DLIST& aTrackList ) while( track != NULL ) { TRACK* next_track = track->Next(); - LockPoint = pcb->GetPad( track, FLG_END ); + LockPoint = pcb->GetPad( track, ENDPOINT_END ); if( LockPoint ) { diff --git a/pcbnew/move_or_drag_track.cpp b/pcbnew/move_or_drag_track.cpp index 7d108eea4b..6631ce31dc 100644 --- a/pcbnew/move_or_drag_track.cpp +++ b/pcbnew/move_or_drag_track.cpp @@ -709,7 +709,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC s_StartSegmentPresent = s_EndSegmentPresent = true; if( ( track->start == NULL ) || ( track->start->Type() == PCB_TRACE_T ) ) - TrackToStartPoint = track->GetTrack( GetBoard()->m_Track, NULL, FLG_START ); + TrackToStartPoint = track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_START ); // Test if more than one segment is connected to this point if( TrackToStartPoint ) @@ -717,14 +717,14 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC TrackToStartPoint->SetState( BUSY, true ); if( ( TrackToStartPoint->Type() == PCB_VIA_T ) - || track->GetTrack( GetBoard()->m_Track, NULL, FLG_START ) ) + || track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_START ) ) error = true; TrackToStartPoint->SetState( BUSY, false ); } if( ( track->end == NULL ) || ( track->end->Type() == PCB_TRACE_T ) ) - TrackToEndPoint = track->GetTrack( GetBoard()->m_Track, NULL, FLG_END ); + TrackToEndPoint = track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_END ); // Test if more than one segment is connected to this point if( TrackToEndPoint ) @@ -732,7 +732,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC TrackToEndPoint->SetState( BUSY, true ); if( (TrackToEndPoint->Type() == PCB_VIA_T) - || track->GetTrack( GetBoard()->m_Track, NULL, FLG_END ) ) + || track->GetTrack( GetBoard()->m_Track, NULL, ENDPOINT_END ) ) error = true; TrackToEndPoint->SetState( BUSY, false ); diff --git a/pcbnew/pcbnew.h b/pcbnew/pcbnew.h index 25df567ebb..d2c6427ea6 100644 --- a/pcbnew/pcbnew.h +++ b/pcbnew/pcbnew.h @@ -25,9 +25,11 @@ #define MATCH_LAYER (1 << 2) ///< if module not on current layer, do not select #define VISIBLE_ONLY (1 << 3) ///< if module not on a visible layer, do not select - -#define FLG_START 0 // Flag used in locate routines -#define FLG_END 1 // Flag used in locate routines +/// Flag used in locate routines (from which endpoint work) +enum ENDPOINT_T { + ENDPOINT_START = 0, + ENDPOINT_END = 1 +}; #define DIM_ANCRE_MODULE 3 // Anchor size (footprint center)