Commit 899d23d4 authored by jean-pierre charras's avatar jean-pierre charras

Polygon code cleanup

parent 3b56ea67
...@@ -24,7 +24,6 @@ CPolyLine::CPolyLine() ...@@ -24,7 +24,6 @@ CPolyLine::CPolyLine()
m_hatchStyle = NO_HATCH; m_hatchStyle = NO_HATCH;
m_hatchPitch = 0; m_hatchPitch = 0;
m_layer = 0; m_layer = 0;
m_width = 0;
m_utility = 0; m_utility = 0;
m_Kbool_Poly_Engine = NULL; m_Kbool_Poly_Engine = NULL;
} }
...@@ -135,9 +134,7 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList ) ...@@ -135,9 +134,7 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList )
else if( aExtraPolyList ) // a new outside contour is found: create a new CPolyLine else if( aExtraPolyList ) // a new outside contour is found: create a new CPolyLine
{ {
polyline = new CPolyLine; polyline = new CPolyLine;
polyline->SetLayer( GetLayer() ); polyline->ImportSettings( this );
polyline->SetHatchStyle( GetHatchStyle() );
polyline->SetHatchPitch( GetHatchPitch() );
aExtraPolyList->push_back( polyline ); // put it in array aExtraPolyList->push_back( polyline ); // put it in array
bool first = true; bool first = true;
...@@ -453,98 +450,19 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles ) ...@@ -453,98 +450,19 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
*/ */
int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList ) int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
{ {
#if 1
return NormalizeWithKbool( aNewPolygonList ); 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<KI_POLY_POINT> 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 /* initialize a contour
* set layer, hatch style, and starting point * set layer, hatch style, and starting point
...@@ -931,11 +849,6 @@ int CPolyLine::GetEndContour( int ic ) ...@@ -931,11 +849,6 @@ int CPolyLine::GetEndContour( int ic )
CRect CPolyLine::GetBounds() CRect CPolyLine::GetBounds()
{ {
CRect r = GetCornerBounds(); 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; return r;
} }
......
...@@ -108,6 +108,13 @@ public: ...@@ -108,6 +108,13 @@ public:
CPolyLine(); CPolyLine();
~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 // functions for modifying the CPolyLine contours
/* initialize a contour /* initialize a contour
...@@ -176,15 +183,15 @@ public: ...@@ -176,15 +183,15 @@ public:
// access functions // access functions
void SetLayer( int aLayer ) { m_layer = aLayer; } void SetLayer( int aLayer ) { m_layer = aLayer; }
int GetLayer() { return m_layer; } int GetLayer() const { return m_layer; }
int GetNumCorners(); int GetNumCorners();
int GetNumSides(); int GetNumSides();
int GetClosed(); int GetClosed();
int GetContoursCount(); int GetContoursCount();
int GetContour( int ic ); int GetContour( int ic );
int GetContourStart( int icont ); int GetContourStart( int icont );
int GetContourEnd( int icont ); int GetContourEnd( int icont );
int GetContourSize( int icont ); int GetContourSize( int icont );
int GetX( int ic ) const { return m_CornersList[ic].x; } int GetX( int ic ) const { return m_CornersList[ic].x; }
int GetY( int ic ) const { return m_CornersList[ic].y; } int GetY( int ic ) const { return m_CornersList[ic].y; }
...@@ -193,13 +200,13 @@ public: ...@@ -193,13 +200,13 @@ public:
int GetEndContour( int ic ); 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; }; 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 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 ) void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
{ {
SetHatchPitch( aHatchPitch ); SetHatchPitch( aHatchPitch );
...@@ -286,7 +293,6 @@ public: ...@@ -286,7 +293,6 @@ public:
private: private:
int m_layer; // layer to draw on 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 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 // and the len of eacvh segment
......
...@@ -59,7 +59,6 @@ typedef bpl::polygon_with_holes_data<int> KI_POLYGON_WITH_HOLES; ...@@ -59,7 +59,6 @@ typedef bpl::polygon_with_holes_data<int> KI_POLYGON_WITH_HOLES;
* is always stored in a KI_POLYGON_WITH_HOLES_SET, because these operations * is always stored in a KI_POLYGON_WITH_HOLES_SET, because these operations
* can create many separate polygons with holespolygons * can create many separate polygons with holespolygons
*/ */
typedef std::vector<KI_POLYGON_WITH_HOLES> KI_POLYGON_WITH_HOLES_SET; typedef std::vector<KI_POLYGON_WITH_HOLES> KI_POLYGON_WITH_HOLES_SET;
......
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