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 @@
#ifndef CLASS_DRAWSEGMENT_H
#define CLASS_DRAWSEGMENT_H
#include "polyline.h"
class DRAWSEGMENT : public BOARD_ITEM
{
......@@ -15,8 +16,8 @@ public:
int m_Shape; // Shape: line, Circle, Arc
int m_Type; // Used in complex associations ( Dimensions.. )
int m_Angle; // Used only for Arcs: Arc angle in 1/10 deg
wxPoint m_BezierC1; // Bezier Control Point 1
wxPoint m_BezierC2; // Bezier Control Point 1
wxPoint m_BezierC1; // Bezier Control Point 1
wxPoint m_BezierC2; // Bezier Control Point 1
std::vector<wxPoint> m_BezierPoints;
public:
......@@ -42,13 +43,13 @@ public:
* Function GetStart
* returns the starting point of the graphic
*/
wxPoint GetStart() const;
wxPoint GetStart() const;
/**
* Function GetEnd
* returns the ending point of the graphic
*/
wxPoint GetEnd() const;
wxPoint GetEnd() const;
/**
* Function Save
......@@ -56,15 +57,15 @@ public:
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
bool Save( FILE* aFile ) const;
bool ReadDrawSegmentDescr( FILE* File, int* LineNum );
bool ReadDrawSegmentDescr( FILE* File, int* LineNum );
void Copy( DRAWSEGMENT* source );
void Copy( DRAWSEGMENT* source );
void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
int aDrawMode, const wxPoint& offset = ZeroOffset );
void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
int aDrawMode, const wxPoint& offset = ZeroOffset );
/**
* Function DisplayInfo
......@@ -73,7 +74,7 @@ public:
* Is virtual from EDA_BaseStruct.
* @param frame A WinEDA_BasePcbFrame in which to print status information.
*/
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
/**
......@@ -82,7 +83,7 @@ public:
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& ref_pos );
bool HitTest( const wxPoint& ref_pos );
/**
* Function HitTest (overlayed)
......@@ -91,7 +92,7 @@ public:
* @param refPos the given EDA_Rect to test
* @return bool - true if a hit, else false
*/
bool HitTest( EDA_Rect& refArea );
bool HitTest( EDA_Rect& refArea );
/**
* Function GetClass
......@@ -116,36 +117,56 @@ public:
return hypot( delta.x, delta.y );
}
/**
* Function Move
* move 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_End += aMoveVector;
m_End += aMoveVector;
}
/**
* Function Rotate
* Rotate this object.
* @param const wxPoint& aRotCentre - the rotation point.
* @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
* Flip this object, i.e. change the board side for this object
* @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)
void Show( int nestLevel, std::ostream& os );
#endif
#endif
};
......
......@@ -5,6 +5,7 @@
class Pcb3D_GLCanvas;
#include "pad_shapes.h"
#include "polyline.h"
/* Default layers used for pads, according to the pad type.
* this is default values only, they can be changed for a given pad
......@@ -141,7 +142,7 @@ public:
m_Pos = aPos;
}
/** function TransformPadWithClearanceToPolygon
/** function TransformShapeWithClearanceToPolygon
* Convert the pad shape to a closed polygon
* Used in filling zones calculations
* Circles and arcs are approximated by segments
......@@ -152,7 +153,7 @@ public:
* clearance when the circle is approxiamted by segment bigger or equal
* 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 );
/**
......
......@@ -5,6 +5,7 @@
#define CLASS_PCB_TEXT_H
#include "base_struct.h"
#include "polyline.h"
class TEXTE_PCB : public BOARD_ITEM, public EDA_TextStruct
{
......@@ -110,6 +111,23 @@ public:
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)
/**
* Function Show
......
......@@ -6,6 +6,7 @@
#define CLASS_TRACK_H
#include "base_struct.h"
#include "polyline.h"
// Via attributes (m_Shape parmeter)
......@@ -148,7 +149,7 @@ public:
/* divers */
int Shape() const { return m_Shape & 0xFF; }
/** Function TransformTrackWithClearanceToPolygon
/** Function TransformShapeWithClearanceToPolygon
* Convert the track shape to a closed polygon
* Used in filling zones calculations
* Circles (vias) and arcs (ends of tracks) are approximated by segments
......@@ -159,7 +160,7 @@ public:
* clearance when the circle is approxiamted by segment bigger or equal
* 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 aCircleToSegmentsCount,
double aCorrectionFactor );
......
......@@ -14,9 +14,15 @@
#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 char sDate_Time[256];
static vector <kfcoord> s_EntityCoordinates;
void CreateKeyFile()
{
......@@ -48,6 +54,8 @@ void CreateKeyFile()
{
wxMessageBox( wxT( "CreateKeyFile() cannot create output file" ) );
}
s_EntityCoordinates.clear();
}
......@@ -58,11 +66,11 @@ void CloseKeyFile()
fprintf( kdebugFile, "\nENDLIB;\n" );
fclose( kdebugFile );
}
s_EntityCoordinates.clear();
}
const char* sCurrEntityName = NULL;
static int s_count;
void OpenKeyFileEntity( const char* aName )
{
......@@ -74,7 +82,7 @@ void OpenKeyFileEntity( const char* aName )
fprintf( kdebugFile, "STRNAME %s;\n", aName );
}
sCurrEntityName = aName;
s_count = 0;
s_EntityCoordinates.clear();
}
......@@ -84,20 +92,45 @@ void CloseKeyFileEntity()
fprintf( kdebugFile, "\nENDSTR %s;\n", sCurrEntityName );
}
void StartKeyFilePolygon(int aCornersCount, int aLayer)
/* start a polygon entity in key file
*/
void StartKeyFilePolygon( int aLayer)
{
s_EntityCoordinates.clear();
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 )
fprintf( kdebugFile, "\n");
fprintf( kdebugFile, "\nENDEL;\n" );
s_count = 0;
kfcoord coord;
coord.x = aXcoord;
coord.y = aYcoord;
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 )
......@@ -106,30 +139,15 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer
return;
unsigned corners_count = aZone->m_FilledPolysList.size();
int count = 0;
unsigned ic = 0;
CPolyPt* corner;
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:
StartKeyFilePolygon( count+1, aLayer );
corner = &aZone->m_FilledPolysList[ic];
int startpointX = corner->x;
int startpointY = corner->y;
// write polygon:
StartKeyFilePolygon( aLayer );
for( ; ic < corners_count; ic++ )
{
corner = &aZone->m_FilledPolysList[ic];
CPolyPt* corner = &aZone->m_FilledPolysList[ic];
AddKeyFilePointXY( corner->x, corner->y );
if( corner->end_contour )
{
......@@ -137,21 +155,8 @@ void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer
break;
}
}
// Close polygon:
AddKeyFilePointXY( startpointX, startpointY );
EndKeyFileElement();
}
}
void AddKeyFilePointXY( int aXcoord, int aYcoord)
{
if ( s_count >= 2 )
{
s_count = 0;
fprintf( kdebugFile, "\n");
EndKeyFilePolygon();
}
fprintf( kdebugFile, " X %d; Y %d;", aXcoord, aYcoord );
s_count ++;
}
#endif
......@@ -38,9 +38,9 @@ void CloseKeyFileEntity();
/* polygon creations:
*/
void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer);
void StartKeyFilePolygon(int aCornersCount, int aLayer);
void StartKeyFilePolygon( int aLayer);
void AddKeyFilePointXY( int aXcoord, int aYcoord);
void EndKeyFileElement();
void EndKeyFilePolygon();
#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