From 2c60c00640c7e034710b7f4c24088b312c30f950 Mon Sep 17 00:00:00 2001 From: charras Date: Mon, 13 Oct 2008 12:01:12 +0000 Subject: [PATCH] Some enhancements about code for zones --- pcbnew/dialog_copper_zones.cpp | 24 ++++++ pcbnew/zones_by_polygon.cpp | 16 +++- polygon/math_for_graphics.cpp | 107 +------------------------- polygon/math_for_graphics.h | 4 - polygon/polygon_test_point_inside.cpp | 61 +++++++-------- 5 files changed, 67 insertions(+), 145 deletions(-) diff --git a/pcbnew/dialog_copper_zones.cpp b/pcbnew/dialog_copper_zones.cpp index 6a4cd69960..265c6128b2 100644 --- a/pcbnew/dialog_copper_zones.cpp +++ b/pcbnew/dialog_copper_zones.cpp @@ -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; + } + } + } + } + } diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 027fe5a4cb..e12cd9c218 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -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(); } diff --git a/polygon/math_for_graphics.cpp b/polygon/math_for_graphics.cpp index 428c8e3b5e..ccd5b182fe 100644 --- a/polygon/math_for_graphics.cpp +++ b/polygon/math_for_graphics.cpp @@ -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; kq; 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; diff --git a/polygon/math_for_graphics.h b/polygon/math_for_graphics.h index b7adcaf333..a524117f9e 100644 --- a/polygon/math_for_graphics.h +++ b/polygon/math_for_graphics.h @@ -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 ); diff --git a/polygon/polygon_test_point_inside.cpp b/polygon/polygon_test_point_inside.cpp index b19d9e37d1..64f7754696 100644 --- a/polygon/polygon_test_point_inside.cpp +++ b/polygon/polygon_test_point_inside.cpp @@ -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 aPolysList, #else -/* this algo come from freePCB. - */ - bool TestPointInsidePolygon( std::vector aPolysList, int istart, int iend, @@ -294,12 +292,13 @@ bool TestPointInsidePolygon( std::vector 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 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