Commit 46e82e4e authored by jean-pierre charras's avatar jean-pierre charras

Move HitTestForCorner and HitTestForEdge code from class_zone to...

Move HitTestForCorner and HitTestForEdge code from class_zone to polygon/PolyLine.cpp, to avoid redundant code.
Fix bug 1264248.
Fix a very minor issue in RemoveTrailingZeros, for countries where the separator in floating numbers is a comma.
parent 5418a083
......@@ -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;
......
......@@ -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;
}
......
......@@ -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();
}
}
......
......@@ -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 );
......
......@@ -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
......
......@@ -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 <CSegment> m_HatchLines; // hatch lines showing the polygon area
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment