Commit f2f4cd53 authored by charras's avatar charras

rework on zones (continued):try to fix a filling problem with kbool: cleanup code

parent 537d4861
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#ifndef CLASS_DRAWSEGMENT_H #ifndef CLASS_DRAWSEGMENT_H
#define CLASS_DRAWSEGMENT_H #define CLASS_DRAWSEGMENT_H
#include "polyline.h"
class DRAWSEGMENT : public BOARD_ITEM class DRAWSEGMENT : public BOARD_ITEM
{ {
...@@ -116,36 +117,56 @@ public: ...@@ -116,36 +117,56 @@ public:
return hypot( delta.x, delta.y ); return hypot( delta.x, delta.y );
} }
/** /**
* Function Move * Function Move
* move this object. * move this object.
* @param const wxPoint& aMoveVector - the move vector for this object. * @param const wxPoint& aMoveVector - the move vector for this object.
*/ */
virtual void Move(const wxPoint& aMoveVector) virtual void Move( const wxPoint& aMoveVector )
{ {
m_Start += aMoveVector; m_Start += aMoveVector;
m_End += aMoveVector; m_End += aMoveVector;
} }
/** /**
* Function Rotate * Function Rotate
* Rotate this object. * Rotate this object.
* @param const wxPoint& aRotCentre - the rotation point. * @param const wxPoint& aRotCentre - the rotation point.
* @param aAngle - the rotation angle in 0.1 degree. * @param aAngle - the rotation angle in 0.1 degree.
*/ */
virtual void Rotate(const wxPoint& aRotCentre, int aAngle); virtual void Rotate( const wxPoint& aRotCentre, int aAngle );
/** /**
* Function Flip * Function Flip
* Flip this object, i.e. change the board side for this object * Flip this object, i.e. change the board side for this object
* @param const wxPoint& aCentre - the rotation point. * @param const wxPoint& aCentre - the rotation point.
*/ */
virtual void Flip(const wxPoint& aCentre ); virtual void Flip( const wxPoint& aCentre );
/** Function TransformShapeWithClearanceToPolygon
* Convert the track shape to a closed polygon
* Used in filling zones calculations
* Circles and arcs are approximated by segments
* @param aCornerBuffer = a buffer to store the polygon
* @param aClearanceValue = the clearance around the pad
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
* @param aCorrectionFactor = the correction to apply to circles radius to keep
* clearance when the circle is approxiamted by segment bigger or equal
* to the real clearance value (usually near from 1.0)
*/
void TransformShapeWithClearanceToPolygon(
std::vector <CPolyPt>& aCornerBuffer,
int aClearanceValue,
int
aCircleToSegmentsCount,
double aCorrectionFactor );
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ); void Show( int nestLevel, std::ostream& os );
#endif
#endif
}; };
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
class Pcb3D_GLCanvas; class Pcb3D_GLCanvas;
#include "pad_shapes.h" #include "pad_shapes.h"
#include "polyline.h"
/* Default layers used for pads, according to the pad type. /* Default layers used for pads, according to the pad type.
* this is default values only, they can be changed for a given pad * this is default values only, they can be changed for a given pad
...@@ -141,7 +142,7 @@ public: ...@@ -141,7 +142,7 @@ public:
m_Pos = aPos; m_Pos = aPos;
} }
/** function TransformPadWithClearanceToPolygon /** function TransformShapeWithClearanceToPolygon
* Convert the pad shape to a closed polygon * Convert the pad shape to a closed polygon
* Used in filling zones calculations * Used in filling zones calculations
* Circles and arcs are approximated by segments * Circles and arcs are approximated by segments
...@@ -152,7 +153,7 @@ public: ...@@ -152,7 +153,7 @@ public:
* clearance when the circle is approxiamted by segment bigger or equal * clearance when the circle is approxiamted by segment bigger or equal
* to the real clearance value (usually near from 1.0) * to the real clearance value (usually near from 1.0)
*/ */
void TransformPadWithClearanceToPolygon( std::vector <wxPoint>& aCornerBuffer, void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor ); int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor );
/** /**
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#define CLASS_PCB_TEXT_H #define CLASS_PCB_TEXT_H
#include "base_struct.h" #include "base_struct.h"
#include "polyline.h"
class TEXTE_PCB : public BOARD_ITEM, public EDA_TextStruct class TEXTE_PCB : public BOARD_ITEM, public EDA_TextStruct
{ {
...@@ -110,6 +111,23 @@ public: ...@@ -110,6 +111,23 @@ public:
return wxT("PTEXT"); return wxT("PTEXT");
} }
/** Function TransformShapeWithClearanceToPolygon
* Convert the track shape to a closed polygon
* Used in filling zones calculations
* Circles and arcs are approximated by segments
* @param aCornerBuffer = a buffer to store the polygon
* @param aClearanceValue = the clearance around the pad
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
* @param aCorrectionFactor = the correction to apply to circles radius to keep
* clearance when the circle is approximated by segment bigger or equal
* to the real clearance value (usually near from 1.0)
*/
void TransformShapeWithClearanceToPolygon(
std::vector <CPolyPt>& aCornerBuffer,
int aClearanceValue,
int aCircleToSegmentsCount,
double aCorrectionFactor );
#if defined(DEBUG) #if defined(DEBUG)
/** /**
* Function Show * Function Show
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CLASS_TRACK_H #define CLASS_TRACK_H
#include "base_struct.h" #include "base_struct.h"
#include "polyline.h"
// Via attributes (m_Shape parmeter) // Via attributes (m_Shape parmeter)
...@@ -148,7 +149,7 @@ public: ...@@ -148,7 +149,7 @@ public:
/* divers */ /* divers */
int Shape() const { return m_Shape & 0xFF; } int Shape() const { return m_Shape & 0xFF; }
/** Function TransformTrackWithClearanceToPolygon /** Function TransformShapeWithClearanceToPolygon
* Convert the track shape to a closed polygon * Convert the track shape to a closed polygon
* Used in filling zones calculations * Used in filling zones calculations
* Circles (vias) and arcs (ends of tracks) are approximated by segments * Circles (vias) and arcs (ends of tracks) are approximated by segments
...@@ -159,7 +160,7 @@ public: ...@@ -159,7 +160,7 @@ public:
* clearance when the circle is approxiamted by segment bigger or equal * clearance when the circle is approxiamted by segment bigger or equal
* to the real clearance value (usually near from 1.0) * to the real clearance value (usually near from 1.0)
*/ */
void TransformTrackWithClearanceToPolygon( std::vector <wxPoint>& aCornerBuffer, void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
int aClearanceValue, int aClearanceValue,
int aCircleToSegmentsCount, int aCircleToSegmentsCount,
double aCorrectionFactor ); double aCorrectionFactor );
......
...@@ -14,9 +14,15 @@ ...@@ -14,9 +14,15 @@
#if defined (CREATE_KBOOL_KEY_FILES) || (CREATE_KBOOL_KEY_FILES_FIRST_PASS) #if defined (CREATE_KBOOL_KEY_FILES) || (CREATE_KBOOL_KEY_FILES_FIRST_PASS)
// Helper class to handle a coordinate
struct kfcoord
{
int x, y;
};
static FILE* kdebugFile; static FILE* kdebugFile;
static char sDate_Time[256]; static char sDate_Time[256];
static vector <kfcoord> s_EntityCoordinates;
void CreateKeyFile() void CreateKeyFile()
{ {
...@@ -48,6 +54,8 @@ void CreateKeyFile() ...@@ -48,6 +54,8 @@ void CreateKeyFile()
{ {
wxMessageBox( wxT( "CreateKeyFile() cannot create output file" ) ); wxMessageBox( wxT( "CreateKeyFile() cannot create output file" ) );
} }
s_EntityCoordinates.clear();
} }
...@@ -58,11 +66,11 @@ void CloseKeyFile() ...@@ -58,11 +66,11 @@ void CloseKeyFile()
fprintf( kdebugFile, "\nENDLIB;\n" ); fprintf( kdebugFile, "\nENDLIB;\n" );
fclose( kdebugFile ); fclose( kdebugFile );
} }
s_EntityCoordinates.clear();
} }
const char* sCurrEntityName = NULL; const char* sCurrEntityName = NULL;
static int s_count;
void OpenKeyFileEntity( const char* aName ) void OpenKeyFileEntity( const char* aName )
{ {
...@@ -74,7 +82,7 @@ void OpenKeyFileEntity( const char* aName ) ...@@ -74,7 +82,7 @@ void OpenKeyFileEntity( const char* aName )
fprintf( kdebugFile, "STRNAME %s;\n", aName ); fprintf( kdebugFile, "STRNAME %s;\n", aName );
} }
sCurrEntityName = aName; sCurrEntityName = aName;
s_count = 0; s_EntityCoordinates.clear();
} }
...@@ -84,20 +92,45 @@ void CloseKeyFileEntity() ...@@ -84,20 +92,45 @@ void CloseKeyFileEntity()
fprintf( kdebugFile, "\nENDSTR %s;\n", sCurrEntityName ); fprintf( kdebugFile, "\nENDSTR %s;\n", sCurrEntityName );
} }
/* start a polygon entity in key file
void StartKeyFilePolygon(int aCornersCount, int aLayer) */
void StartKeyFilePolygon( int aLayer)
{ {
s_EntityCoordinates.clear();
fprintf( kdebugFile, "\nBOUNDARY; LAYER %d; DATATYPE 0;\n", aLayer ); fprintf( kdebugFile, "\nBOUNDARY; LAYER %d; DATATYPE 0;\n", aLayer );
fprintf( kdebugFile, " XY %d;\n", aCornersCount );
s_count = 0;
} }
void EndKeyFileElement() /* add a polygon corner to the current polygon entity in key file
*/
void AddKeyFilePointXY( int aXcoord, int aYcoord)
{ {
if ( s_count == 1 ) kfcoord coord;
fprintf( kdebugFile, "\n"); coord.x = aXcoord;
fprintf( kdebugFile, "\nENDEL;\n" ); coord.y = aYcoord;
s_count = 0; s_EntityCoordinates.push_back( coord );
}
/* Close a polygon entity in key file
* write the entire polygon data to the file
*/
void EndKeyFilePolygon()
{
// Polygon must be closed: test for that and close it if needed
if( s_EntityCoordinates.size() )
{
if( s_EntityCoordinates.back().x != s_EntityCoordinates[0].x
|| s_EntityCoordinates.back().y != s_EntityCoordinates[0].y )
s_EntityCoordinates.push_back( s_EntityCoordinates[0] );
}
fprintf( kdebugFile, " XY %d;\n", s_EntityCoordinates.size() );
for( unsigned ii = 0; ii < s_EntityCoordinates.size(); ii ++ )
fprintf( kdebugFile, " X %d; Y %d;\n",
s_EntityCoordinates[ii].x, s_EntityCoordinates[ii].y );
fprintf( kdebugFile, "ENDEL;\n" );
s_EntityCoordinates.clear();
} }
void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer ) void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer )
...@@ -106,30 +139,15 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer ...@@ -106,30 +139,15 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer
return; return;
unsigned corners_count = aZone->m_FilledPolysList.size(); unsigned corners_count = aZone->m_FilledPolysList.size();
int count = 0;
unsigned ic = 0; unsigned ic = 0;
CPolyPt* corner;
while( ic < corners_count ) while( ic < corners_count )
{ {
// Count corners:
count = 0;
for( unsigned ii = ic; ii < corners_count; ii++ )
{
corner = &aZone->m_FilledPolysList[ii];
count++;
if( corner->end_contour )
break;
}
// write corners: // write polygon:
StartKeyFilePolygon( count+1, aLayer ); StartKeyFilePolygon( aLayer );
corner = &aZone->m_FilledPolysList[ic];
int startpointX = corner->x;
int startpointY = corner->y;
for( ; ic < corners_count; ic++ ) for( ; ic < corners_count; ic++ )
{ {
corner = &aZone->m_FilledPolysList[ic]; CPolyPt* corner = &aZone->m_FilledPolysList[ic];
AddKeyFilePointXY( corner->x, corner->y ); AddKeyFilePointXY( corner->x, corner->y );
if( corner->end_contour ) if( corner->end_contour )
{ {
...@@ -137,21 +155,8 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer ...@@ -137,21 +155,8 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer
break; break;
} }
} }
// Close polygon: EndKeyFilePolygon();
AddKeyFilePointXY( startpointX, startpointY );
EndKeyFileElement();
}
}
void AddKeyFilePointXY( int aXcoord, int aYcoord)
{
if ( s_count >= 2 )
{
s_count = 0;
fprintf( kdebugFile, "\n");
} }
fprintf( kdebugFile, " X %d; Y %d;", aXcoord, aYcoord );
s_count ++;
} }
#endif #endif
...@@ -38,9 +38,9 @@ void CloseKeyFileEntity(); ...@@ -38,9 +38,9 @@ void CloseKeyFileEntity();
/* polygon creations: /* polygon creations:
*/ */
void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer); void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer);
void StartKeyFilePolygon(int aCornersCount, int aLayer); void StartKeyFilePolygon( int aLayer);
void AddKeyFilePointXY( int aXcoord, int aYcoord); void AddKeyFilePointXY( int aXcoord, int aYcoord);
void EndKeyFileElement(); void EndKeyFilePolygon();
#endif // CREATE_KBOOL_KEY_FILES #endif // CREATE_KBOOL_KEY_FILES
......
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