diff --git a/common/string.cpp b/common/string.cpp index 86b60d938f..91f2099b36 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -487,7 +487,7 @@ wxString RemoveTrailingZeros( const wxString& aString ) while( --i > 0 && retv[i] == wxChar( '0' ) ) retv.RemoveLast(); - if( retv[i] == wxChar( '.' ) ) + if( retv[i] == wxChar( '.' ) || retv[i] == wxChar( ',' ) ) retv.RemoveLast(); return retv; diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 642023de9d..b1d8405c81 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -480,32 +480,12 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) // Zones outlines have no thickness, so it Hit Test functions // we must have a default distance between the test point // and a corner or a zone edge: -#define MIN_DIST_IN_MILS 10 +#define MAX_DIST_IN_MM 0.25 bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) { - m_CornerSelection = -1; // Set to not found - - // distance (in internal units) to detect a corner in a zone outline. - int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS; - - wxPoint delta; - unsigned lim = m_Poly->m_CornersList.GetCornersCount(); - - for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) - { - delta.x = refPos.x - m_Poly->m_CornersList.GetX( item_pos ); - delta.y = refPos.y - m_Poly->m_CornersList.GetY( item_pos ); - - // Calculate a distance: - int dist = std::max( abs( delta.x ), abs( delta.y ) ); - - if( dist < min_dist ) // this corner is a candidate: - { - m_CornerSelection = item_pos; - min_dist = dist; - } - } + int distmax = Millimeter2iu( MAX_DIST_IN_MM ); + m_CornerSelection = m_Poly->HitTestForCorner( refPos, distmax ); return m_CornerSelection >= 0; } @@ -513,44 +493,8 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) { - unsigned lim = m_Poly->m_CornersList.GetCornersCount(); - - m_CornerSelection = -1; // Set to not found - - // distance (in internal units) to detect a zone outline - int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS; - - unsigned first_corner_pos = 0; - - for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) - { - unsigned end_segm = item_pos + 1; - - /* the last corner of the current outline is tested - * the last segment of the current outline starts at current corner, and ends - * at the first corner of the outline - */ - if( m_Poly->m_CornersList.IsEndContour ( item_pos ) || end_segm >= lim ) - { - unsigned tmp = first_corner_pos; - first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline - end_segm = tmp; // end_segm is the beginning of the current outline - } - - // test the dist between segment and ref point - int dist = KiROUND( GetPointToLineSegmentDistance( - refPos.x, refPos.y, - m_Poly->m_CornersList.GetX( item_pos ), - m_Poly->m_CornersList.GetY( item_pos ), - m_Poly->m_CornersList.GetX( end_segm ), - m_Poly->m_CornersList.GetY( end_segm ) ) ); - - if( dist < min_dist ) - { - m_CornerSelection = item_pos; - min_dist = dist; - } - } + int distmax = Millimeter2iu( MAX_DIST_IN_MM ); + m_CornerSelection = m_Poly->HitTestForEdge( refPos, distmax ); return m_CornerSelection >= 0; } diff --git a/pcbnew/edit_track_width.cpp b/pcbnew/edit_track_width.cpp index 869afdaede..6698f2be1a 100644 --- a/pcbnew/edit_track_width.cpp +++ b/pcbnew/edit_track_width.cpp @@ -63,9 +63,9 @@ bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem, if( aTrackItem->GetShape() == VIA_MICROVIA ) { if( net ) - new_width = net->GetViaSize(); - else new_width = net->GetMicroViaSize(); + else + new_width = GetBoard()->GetCurrentMicroViaSize(); } } diff --git a/pcbnew/tr_modif.cpp b/pcbnew/tr_modif.cpp index 11fa841a96..d4aa7eb5a6 100644 --- a/pcbnew/tr_modif.cpp +++ b/pcbnew/tr_modif.cpp @@ -234,7 +234,9 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, } nbconnect--; - pt_del->SetState( IS_LINKED, false ); + + if( pt_del ) + pt_del->SetState( IS_LINKED, false ); pt_del = GetBoard()->MarkTrace( pt_del, &nb_segm, NULL, NULL, true ); diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index 41a562a154..de50c23a0c 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -1149,6 +1149,75 @@ int CPolyLine::Distance( const wxPoint& aPoint ) } +/* test is the point aPos is near (< aDistMax ) a vertex + * return int = the index of the first corner of the vertex, or -1 if not found. + */ +int CPolyLine::HitTestForEdge( const wxPoint& aPos, int aDistMax ) const +{ + unsigned lim = m_CornersList.GetCornersCount(); + int corner = -1; // Set to not found + unsigned first_corner_pos = 0; + + for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) + { + unsigned end_segm = item_pos + 1; + + /* the last corner of the current outline is tested + * the last segment of the current outline starts at current corner, and ends + * at the first corner of the outline + */ + if( m_CornersList.IsEndContour ( item_pos ) || end_segm >= lim ) + { + unsigned tmp = first_corner_pos; + first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline + end_segm = tmp; // end_segm is the beginning of the current outline + } + + // test the dist between segment and ref point + int dist = KiROUND( GetPointToLineSegmentDistance( + aPos.x, aPos.y, + m_CornersList.GetX( item_pos ), + m_CornersList.GetY( item_pos ), + m_CornersList.GetX( end_segm ), + m_CornersList.GetY( end_segm ) ) ); + + if( dist < aDistMax ) + { + corner = item_pos; + aDistMax = dist; + } + } + + return corner; +} + +/* test is the point aPos is near (< aDistMax ) a corner + * return int = the index of corner of the, or -1 if not found. + */ +int CPolyLine::HitTestForCorner( const wxPoint& aPos, int aDistMax ) const +{ + int corner = -1; // Set to not found + wxPoint delta; + unsigned lim = m_CornersList.GetCornersCount(); + + for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) + { + delta.x = aPos.x - m_CornersList.GetX( item_pos ); + delta.y = aPos.y - m_CornersList.GetY( item_pos ); + + // Calculate a distance: + int dist = std::max( abs( delta.x ), abs( delta.y ) ); + + if( dist < aDistMax ) // this corner is a candidate: + { + corner = item_pos; + aDistMax = dist; + } + } + + return corner; +} + /* * Copy the contours to a KI_POLYGON_WITH_HOLES * The first contour is the main outline, others are holes diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index 1eb4a83e85..2610a5d765 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -409,13 +409,31 @@ public: */ int Distance( wxPoint aStart, wxPoint aEnd, int aWidth ); + /** + * Function HitTestForEdge + * test is the point aPos is near (< aDistMax ) a vertex + * @param aPos = the reference point + * @param aDistMax = the max distance between a vertex and the reference point + * @return int = the index of the first corner of the vertex, or -1 if not found. + */ + int HitTestForEdge( const wxPoint& aPos, int aDistMax ) const; + + /** + * Function HitTestForCorner + * test is the point aPos is near (< aDistMax ) a corner + * @param aPos = the reference point + * @param aDistMax = the max distance between a vertex and the corner + * @return int = the index of corner of the, or -1 if not found. + */ + int HitTestForCorner( const wxPoint& aPos, int aDistMax ) const; + private: LAYER_NUM m_layer; // layer to draw on enum HATCH_STYLE m_hatchStyle; // hatch style, see enum above - int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines + int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines // and the len of eacvh segment // for DIAGONAL_FULL, the pitch is twice this value - int m_utility; // a flag used in some calculations + int m_utility; // a flag used in some calculations public: CPOLYGONS_LIST m_CornersList; // array of points for corners std::vector m_HatchLines; // hatch lines showing the polygon area