Some enhancements about code for zones
This commit is contained in:
parent
3de5ffc703
commit
2c60c00640
|
@ -229,6 +229,7 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
|
|||
if( ListNetName[ii] == equipot->m_Netname )
|
||||
{
|
||||
m_ListNetNameSelection->SetSelection( ii );
|
||||
m_ListNetNameSelection->EnsureVisible( ii );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -388,6 +389,29 @@ void dialog_copper_zone::OnNetSortingOptionSelected( wxCommandEvent& event )
|
|||
m_Parent->m_Parent->m_EDA_Config->Write( ZONE_NET_SORT_OPTION_KEY, (long) m_NetSorting );
|
||||
m_Parent->m_Parent->m_EDA_Config->Write( ZONE_NET_FILTER_STRING_KEY, m_NetNameFilter->GetValue() );
|
||||
}
|
||||
|
||||
// Select and isplay current zone net name in listbox:
|
||||
int net_select = g_HightLigth_NetCode;
|
||||
if( m_Zone_Container )
|
||||
net_select = m_Zone_Container->GetNet();
|
||||
|
||||
if( net_select > 0 )
|
||||
{
|
||||
EQUIPOT* equipot = m_Parent->m_Pcb->FindNet( net_select );
|
||||
if( equipot ) // Search net in list and select it
|
||||
{
|
||||
for( unsigned ii = 0; ii < ListNetName.GetCount(); ii++ )
|
||||
{
|
||||
if( ListNetName[ii] == equipot->m_Netname )
|
||||
{
|
||||
m_ListNetNameSelection->SetSelection( ii );
|
||||
m_ListNetNameSelection->EnsureVisible( ii );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -508,11 +508,23 @@ int WinEDA_PcbFrame::Begin_Zone( wxDC* DC )
|
|||
if( s_CurrentZone == NULL ) // A new outline is created
|
||||
{
|
||||
int diag;
|
||||
DrawPanel->m_IgnoreMouseEvents = TRUE;
|
||||
// Init zone params to reasonnable values
|
||||
zone->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer );
|
||||
|
||||
// Prompt user fro exact parameters:
|
||||
DrawPanel->m_IgnoreMouseEvents = TRUE;
|
||||
if( zone->IsOnCopperLayer() )
|
||||
{ // Put a zone on a copper layer
|
||||
dialog_copper_zone* frame = new dialog_copper_zone( this, zone );
|
||||
if ( g_HightLigth_NetCode )
|
||||
{
|
||||
g_NetcodeSelection = g_HightLigth_NetCode;
|
||||
zone->SetNet( g_NetcodeSelection );
|
||||
EQUIPOT* net = m_Pcb->FindNet( g_NetcodeSelection );
|
||||
if( net )
|
||||
zone->m_Netname = net->m_Netname;
|
||||
}
|
||||
|
||||
dialog_copper_zone* frame = new dialog_copper_zone( this, zone );
|
||||
diag = frame->ShowModal();
|
||||
frame->Destroy();
|
||||
}
|
||||
|
|
|
@ -832,111 +832,8 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
|
|||
}
|
||||
|
||||
|
||||
// quicksort algorithm
|
||||
// sorts array numbers[], also moves elements of another array index[]
|
||||
//
|
||||
#define Q3WAY
|
||||
void quickSort(int numbers[], int index[], int array_size)
|
||||
{
|
||||
#ifdef Q3WAY
|
||||
q_sort_3way(numbers, index, 0, array_size - 1);
|
||||
#else
|
||||
q_sort(numbers, index, 0, array_size - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
// standard quicksort
|
||||
//
|
||||
void q_sort(int numbers[], int index[], int left, int right)
|
||||
{
|
||||
int pivot, pivot_index, l_hold, r_hold;
|
||||
|
||||
l_hold = left;
|
||||
r_hold = right;
|
||||
pivot = numbers[left];
|
||||
pivot_index = index[left];
|
||||
while (left < right)
|
||||
{
|
||||
while ((numbers[right] >= pivot) && (left < right))
|
||||
right--;
|
||||
if (left != right)
|
||||
{
|
||||
numbers[left] = numbers[right];
|
||||
index[left] = index[right];
|
||||
left++;
|
||||
}
|
||||
while ((numbers[left] <= pivot) && (left < right))
|
||||
left++;
|
||||
if (left != right)
|
||||
{
|
||||
numbers[right] = numbers[left];
|
||||
index[right] = index[left];
|
||||
right--;
|
||||
}
|
||||
}
|
||||
numbers[left] = pivot;
|
||||
index[left] = pivot_index;
|
||||
|
||||
pivot = left;
|
||||
left = l_hold;
|
||||
right = r_hold;
|
||||
if (left < pivot)
|
||||
q_sort(numbers, index, left, pivot-1);
|
||||
if (right > pivot)
|
||||
q_sort(numbers, index, pivot+1, right);
|
||||
}
|
||||
|
||||
// 3-way quicksort...useful where there are duplicate values
|
||||
//
|
||||
void q_sort_3way( int a[], int b[], int l, int r )
|
||||
{
|
||||
#define EXCH(i,j) {int temp=a[i]; a[i]=a[j]; a[j]=temp; temp=b[i]; b[i]=b[j]; b[j]=temp;}
|
||||
|
||||
int i = l - 1;
|
||||
int j = r;
|
||||
int p = l - 1;
|
||||
int q = r;
|
||||
int v = a[r];
|
||||
|
||||
if( r <= l )
|
||||
return;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
while( a[++i] < v );
|
||||
while( v < a[--j] )
|
||||
if( j == 1 )
|
||||
break;
|
||||
if( i >= j )
|
||||
break;
|
||||
EXCH( i, j );
|
||||
if( a[i] == v )
|
||||
{
|
||||
p++;
|
||||
EXCH( p, i );
|
||||
}
|
||||
if( v == a[j] )
|
||||
{
|
||||
q--;
|
||||
EXCH( j, q );
|
||||
}
|
||||
}
|
||||
EXCH( i, r );
|
||||
j = i - 1;
|
||||
i = i + 1;
|
||||
for( int k=l; k<p; k++, j-- )
|
||||
EXCH( k, j );
|
||||
for( int k=r-1; k>q; k--, i++ )
|
||||
EXCH( i, k );
|
||||
q_sort_3way( a, b, l, j );
|
||||
q_sort_3way( a, b, i, r );
|
||||
}
|
||||
|
||||
// solves quadratic equation
|
||||
// i.e. ax**2 + bx + c = 0
|
||||
// returns true if solution exist, with solutions in x1 and x2
|
||||
// else returns false
|
||||
//
|
||||
/*solves the Quadratic equation = a*x*x + b*x + c
|
||||
*/
|
||||
bool Quadratic( double a, double b, double c, double *x1, double *x2 )
|
||||
{
|
||||
double root = b*b - 4.0*a*c;
|
||||
|
|
|
@ -106,7 +106,3 @@ int GetArcIntersections( EllipseKH * el1, EllipseKH * el2,
|
|||
double * x2=NULL, double * y2=NULL );
|
||||
CPoint GetInflectionPoint( CPoint pi, CPoint pf, int mode );
|
||||
|
||||
// quicksort (2-way or 3-way)
|
||||
void quickSort(int numbers[], int index[], int array_size);
|
||||
void q_sort(int numbers[], int index[], int left, int right);
|
||||
void q_sort_3way( int a[], int b[], int left, int right );
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Name: polygon_test_point_inside.cpp
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -9,18 +10,18 @@
|
|||
using namespace std;
|
||||
|
||||
/* this algo uses the the Jordan curve theorem to find if a point is inside or outside a polygon:
|
||||
* It run a semi-infinite line horizontally (increasing x, fixed y)
|
||||
* out from the test point, and count how many edges it crosses.
|
||||
* At each crossing, the ray switches between inside and outside.
|
||||
* If odd count, the test point is inside the polygon
|
||||
* This is called the Jordan curve theorem, or sometimes referred to as the "even-odd" test.
|
||||
* It run a semi-infinite line horizontally (increasing x, fixed y)
|
||||
* out from the test point, and count how many edges it crosses.
|
||||
* At each crossing, the ray switches between inside and outside.
|
||||
* If odd count, the test point is inside the polygon
|
||||
* This is called the Jordan curve theorem, or sometimes referred to as the "even-odd" test.
|
||||
*/
|
||||
|
||||
/* 2 versions are given.
|
||||
* the second version is GPL (currently used)
|
||||
* the first version is for explanations and tests (used to test the second version)
|
||||
* both use the same algorithm.
|
||||
*/
|
||||
*/
|
||||
#if 0
|
||||
|
||||
/* This text and the algorithm come from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
|
@ -282,9 +283,6 @@ bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
|
|||
|
||||
#else
|
||||
|
||||
/* this algo come from freePCB.
|
||||
*/
|
||||
|
||||
bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
|
||||
int istart,
|
||||
int iend,
|
||||
|
@ -294,12 +292,13 @@ bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
|
|||
/** Function TestPointInsidePolygon
|
||||
* test if a point is inside or outside a polygon.
|
||||
* if a point is on a outline segment, it is considered outside the polygon
|
||||
* the polygon must have only lines (not arcs) for outlines.
|
||||
* Use TestPointInside or TestPointInsideContour for more complex polygons
|
||||
* @param aPolysList: the list of polygons
|
||||
* @param istart: the starting point of a given polygon in m_FilledPolysList.
|
||||
* @param iend: the ending point of the polygon in m_FilledPolysList.
|
||||
* @param refx,refy: the point coordinate to test
|
||||
* @return true if the point is inside, false for outside
|
||||
* this algorithm come from FreePCB.
|
||||
*/
|
||||
{
|
||||
#define OUTSIDE_IF_ON_SIDE 0 // = 1 if we consider point on a side outside the polygon
|
||||
|
@ -307,37 +306,31 @@ bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
|
|||
// get intersection points
|
||||
// count intersection points to right of (x,y), if odd (x,y) is inside polyline
|
||||
int xx, yy;
|
||||
double slope = 0;
|
||||
double a = refy - slope * refx;
|
||||
double slope = 0; // Using an horizontal line.
|
||||
double a = refy - slope * refx;
|
||||
int ics, ice;
|
||||
bool inside = false;
|
||||
|
||||
// find all intersection points of line with polyline sides
|
||||
for( ics = istart, ice = iend; ics <= iend; ice = ics++ )
|
||||
{
|
||||
double x, y, x2, y2;
|
||||
int ok = FindLineSegmentIntersection( a, slope,
|
||||
aPolysList[ics].x, aPolysList[ics].y,
|
||||
aPolysList[ice].x, aPolysList[ice].y,
|
||||
0,
|
||||
&x, &y,
|
||||
&x2, &y2 );
|
||||
if( ok )
|
||||
double intersectx1, intersecty1, intersectx2, intersecty2;
|
||||
int ok;
|
||||
ok = FindLineSegmentIntersection( a, slope,
|
||||
aPolysList[ics].x, aPolysList[ics].y,
|
||||
aPolysList[ice].x, aPolysList[ice].y,
|
||||
CPolyLine::STRAIGHT,
|
||||
&intersectx1, &intersecty1,
|
||||
&intersectx2, &intersecty2 );
|
||||
|
||||
/* FindLineSegmentIntersection() returns 0, 1 or 2 coordinates (ok = 0, 1, 2)
|
||||
* for straight line segments, only 0 or 1 are possible
|
||||
* (2 intersections points are possible only with arcs
|
||||
*/
|
||||
if( ok ) // Intersection found
|
||||
{
|
||||
xx = (int) x;
|
||||
yy = (int) y;
|
||||
#if OUTSIDE_IF_ON_SIDE
|
||||
if( xx == refx && yy == refy )
|
||||
return false; // (x,y) is on a side, call it outside
|
||||
else
|
||||
#endif
|
||||
if( xx > refx )
|
||||
inside = not inside;
|
||||
}
|
||||
if( ok == 2 )
|
||||
{
|
||||
xx = (int) x2;
|
||||
yy = (int) y2;
|
||||
xx = (int) intersectx1;
|
||||
yy = (int) intersecty1;
|
||||
#if OUTSIDE_IF_ON_SIDE
|
||||
if( xx == refx && yy == refy )
|
||||
return false; // (x,y) is on a side, call it outside
|
||||
|
|
Loading…
Reference in New Issue