From 7d03b0af3367d2105e13b9db7cba909df3e1555f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 2 Aug 2012 19:32:42 +0200 Subject: [PATCH] Polygon code cleanup --- polygon/PolyLine.cpp | 109 ++++------------------------------------ polygon/PolyLine.h | 32 +++++++----- polygon/polygons_defs.h | 1 - 3 files changed, 30 insertions(+), 112 deletions(-) diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index c23a5ad17f..aee22e3cf0 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -24,7 +24,6 @@ CPolyLine::CPolyLine() m_hatchStyle = NO_HATCH; m_hatchPitch = 0; m_layer = 0; - m_width = 0; m_utility = 0; m_Kbool_Poly_Engine = NULL; } @@ -135,9 +134,7 @@ int CPolyLine::NormalizeWithKbool( std::vector* aExtraPolyList ) else if( aExtraPolyList ) // a new outside contour is found: create a new CPolyLine { polyline = new CPolyLine; - polyline->SetLayer( GetLayer() ); - polyline->SetHatchStyle( GetHatchStyle() ); - polyline->SetHatchPitch( GetHatchPitch() ); + polyline->ImportSettings( this ); aExtraPolyList->push_back( polyline ); // put it in array bool first = true; @@ -453,98 +450,19 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles ) */ int CPolyLine::NormalizeAreaOutlines( std::vector* aNewPolygonList ) { -#if 1 return NormalizeWithKbool( aNewPolygonList ); -#else // Do NOT use this code: it does not yet work - unsigned corners_count = m_CornersList.size(); - - KI_POLYGON_SET polysholes; - KI_POLYGON_WITH_HOLES mainpoly; - std::vector cornerslist; - KI_POLYGON_WITH_HOLES_SET outlines; - KI_POLYGON poly_tmp; - - unsigned ic = 0; - // enter main outline - while( ic < corners_count ) - { - const CPolyPt& corner = m_CornersList[ic++]; - cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) ); - - if( corner.end_contour ) - break; - } - - mainpoly.set( cornerslist.begin(), cornerslist.end() ); - outlines.push_back( mainpoly ); - outlines &= mainpoly; - - // Enter holes - while( ic < corners_count ) - { - cornerslist.clear(); - { - while( ic < corners_count ) - { - const CPolyPt& corner = m_CornersList[ic++]; - cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) ); - - if( corner.end_contour ) - break; - } - - bpl::set_points( poly_tmp, cornerslist.begin(), cornerslist.end() ); - polysholes.push_back( poly_tmp ); - } - } - - outlines -= polysholes; - - // copy polygon with holes to destination - RemoveAllContours(); - - for( unsigned ii = 0; ii < outlines.size(); ii++ ) - { - CPolyLine* polyline = this; - if( ii > 0 ) - { - polyline = new CPolyLine; - polyline->SetLayer( GetLayer() ); - polyline->SetHatchStyle( GetHatchStyle() ); - polyline->SetHatchPitch( GetHatchPitch() ); - aNewPolygonList->push_back( polyline ); - } - - KI_POLYGON_WITH_HOLES& curr_poly = outlines[ii]; - KI_POLYGON_WITH_HOLES::iterator_type corner = curr_poly.begin(); - // enter main contour - while( corner != curr_poly.end() ) - { - polyline->AppendCorner( corner->x(), corner->y() ); - corner++; - } - polyline->CloseLastContour(); - - // add holes (set of polygons) - KI_POLYGON_WITH_HOLES::iterator_holes_type hole = curr_poly.begin_holes(); - while( hole != curr_poly.end_holes() ) - { - KI_POLYGON::iterator_type hole_corner = hole->begin(); - // create area with external contour: Recreate only area edges, NOT holes - while( hole_corner != hole->end() ) - { - polyline->AppendCorner( hole_corner->x(), hole_corner->y() ); - hole_corner++; - } - polyline->CloseLastContour(); - hole++; - } - } - - return outlines.size(); -#endif } +/** + * Function ImportSettings + * Copy settings (layer, hatch styles) from aPoly + */ +void CPolyLine::ImportSettings( const CPolyLine * aPoly ) +{ + SetLayer( aPoly->GetLayer() ); + SetHatchStyle( aPoly->GetHatchStyle() ); + SetHatchPitch( aPoly->GetHatchPitch() ); +} /* initialize a contour * set layer, hatch style, and starting point @@ -931,11 +849,6 @@ int CPolyLine::GetEndContour( int ic ) CRect CPolyLine::GetBounds() { CRect r = GetCornerBounds(); - - r.left -= m_width / 2; - r.right += m_width / 2; - r.bottom -= m_width / 2; - r.top += m_width / 2; return r; } diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index 984062700c..b7e44b30fc 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -108,6 +108,13 @@ public: CPolyLine(); ~CPolyLine(); + /** + * Function ImportSettings + * Copy settings (layer, hatch styles) from aPoly + * @param aPoly is the CPolyLine to import settings + */ + void ImportSettings( const CPolyLine * aPoly ); + // functions for modifying the CPolyLine contours /* initialize a contour @@ -176,15 +183,15 @@ public: // access functions void SetLayer( int aLayer ) { m_layer = aLayer; } - int GetLayer() { return m_layer; } - int GetNumCorners(); - int GetNumSides(); - int GetClosed(); - int GetContoursCount(); - int GetContour( int ic ); - int GetContourStart( int icont ); - int GetContourEnd( int icont ); - int GetContourSize( int icont ); + int GetLayer() const { return m_layer; } + int GetNumCorners(); + int GetNumSides(); + int GetClosed(); + int GetContoursCount(); + int GetContour( int ic ); + int GetContourStart( int icont ); + int GetContourEnd( int icont ); + int GetContourSize( int icont ); int GetX( int ic ) const { return m_CornersList[ic].x; } int GetY( int ic ) const { return m_CornersList[ic].y; } @@ -193,13 +200,13 @@ public: int GetEndContour( int ic ); - int GetUtility( int ic ) { return m_CornersList[ic].m_utility; }; + int GetUtility( int ic ) const { return m_CornersList[ic].m_utility; }; void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; }; - int GetHatchPitch() { return m_hatchPitch; } + int GetHatchPitch() const { return m_hatchPitch; } static int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils - enum HATCH_STYLE GetHatchStyle() { return m_hatchStyle; } + enum HATCH_STYLE GetHatchStyle() const { return m_hatchStyle; } void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch ) { SetHatchPitch( aHatchPitch ); @@ -286,7 +293,6 @@ public: private: int m_layer; // layer to draw on - int m_width; // lines width when drawing. Provided but not really used enum HATCH_STYLE m_hatchStyle; // hatch style, see enum above int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines // and the len of eacvh segment diff --git a/polygon/polygons_defs.h b/polygon/polygons_defs.h index f9055c1cc6..94437bfff8 100644 --- a/polygon/polygons_defs.h +++ b/polygon/polygons_defs.h @@ -59,7 +59,6 @@ typedef bpl::polygon_with_holes_data KI_POLYGON_WITH_HOLES; * is always stored in a KI_POLYGON_WITH_HOLES_SET, because these operations * can create many separate polygons with holespolygons */ - typedef std::vector KI_POLYGON_WITH_HOLES_SET;