Commit cc6cae9b authored by jean-pierre charras's avatar jean-pierre charras

Gerbview: added support of mirroring, scaling an offseting RS274X commands

parent 55eefbbe
...@@ -82,8 +82,8 @@ static void GRSFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle ...@@ -82,8 +82,8 @@ static void GRSFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle
int EndAngle, int r, int width, int Color, int BgColor ); int EndAngle, int r, int width, int Color, int BgColor );
static void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, static void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int aPenSize, int Color ); int width, int aPenSize, int Color );
static void GRSFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, static void GRSLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int width, int Color ); int lines, int width, int Color );
/**/ /**/
extern BASE_SCREEN* ActiveScreen; extern BASE_SCREEN* ActiveScreen;
...@@ -882,7 +882,7 @@ void GRSLine( EDA_Rect* ClipBox, ...@@ -882,7 +882,7 @@ void GRSLine( EDA_Rect* ClipBox,
} }
/* /*
* Draw an array of lines * Draw an array of lines
*/ */
void GRLineArray(EDA_Rect* ClipBox, void GRLineArray(EDA_Rect* ClipBox,
...@@ -892,7 +892,7 @@ void GRLineArray(EDA_Rect* ClipBox, ...@@ -892,7 +892,7 @@ void GRLineArray(EDA_Rect* ClipBox,
int width, int width,
int Color ) int Color )
{ {
for(int i= 0 ; i < lines; i++) for(int i= 0 ; i < lines; i++)
{ {
points[i].x = GRMapX( points[i].x ); points[i].x = GRMapX( points[i].x );
points[i].y = GRMapY( points[i].y ); points[i].y = GRMapY( points[i].y );
...@@ -916,7 +916,7 @@ void GRSLineArray(EDA_Rect* ClipBox, ...@@ -916,7 +916,7 @@ void GRSLineArray(EDA_Rect* ClipBox,
wxASSERT(gc); wxASSERT(gc);
gc->Clip( ClipBox->GetX(), ClipBox->GetY(), ClipBox->GetRight(), ClipBox->GetHeight()); gc->Clip( ClipBox->GetX(), ClipBox->GetY(), ClipBox->GetRight(), ClipBox->GetHeight());
wxGraphicsPath path = gc->CreatePath(); wxGraphicsPath path = gc->CreatePath();
for(int i= 0 ; i < lines; i+=2) for(int i= 0 ; i < lines; i+=2)
{ {
path.MoveToPoint(points[i].x, points[i].y); path.MoveToPoint(points[i].x, points[i].y);
...@@ -927,7 +927,7 @@ void GRSLineArray(EDA_Rect* ClipBox, ...@@ -927,7 +927,7 @@ void GRSLineArray(EDA_Rect* ClipBox,
gc->ResetClip(); gc->ResetClip();
delete gc; delete gc;
#else #else
for(int i= 0 ; i < lines; i+=2) for(int i= 0 ; i < lines; i+=2)
{ {
WinClipAndDrawLine( ClipBox, DC, points[i].x , points[i].y, points[i+1].x , points[i+1].y, Color, width ); WinClipAndDrawLine( ClipBox, DC, points[i].x , points[i].y, points[i+1].x , points[i+1].y, Color, width );
GRLastMoveToX = points[i+1].x; GRLastMoveToX = points[i+1].x;
...@@ -990,6 +990,13 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -990,6 +990,13 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
GRMapY( y2 ), ZoomValue( width ), 0, Color ); GRMapY( y2 ), ZoomValue( width ), 0, Color );
} }
void GRCSegm( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
int aWidth, int aColor )
{
GRSCSegm( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
GRMapX( aEnd.x ), GRMapY( aEnd.y ),
ZoomValue( aWidth ), 0, aColor );
}
/* /*
* Draw segment (full) with rounded ends in object space (real coords.). * Draw segment (full) with rounded ends in object space (real coords.).
...@@ -997,24 +1004,17 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -997,24 +1004,17 @@ void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
void GRFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int Color ) int width, int Color )
{ {
GRSFillCSegm( ClipBox, DC, GRMapX( x1 ), GRMapY( y1 ), GRMapX( x2 ), WinClipAndDrawLine( ClipBox, DC, GRMapX( x1 ), GRMapY( y1 ), GRMapX( x2 ),
GRMapY( y2 ), ZoomValue( width ), Color ); GRMapY( y2 ), Color, ZoomValue( width ) );
} }
/* void GRFilledSegment( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
* Draw segment with rounded ends in screen space. int aWidth, int aColor )
*/
void GRSFillCSegm( EDA_Rect* ClipBox,
wxDC* DC,
int x1,
int y1,
int x2,
int y2,
int width,
int Color )
{ {
WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, Color, width ); WinClipAndDrawLine( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
GRMapX( aEnd.x ), GRMapY( aEnd.y ),
aColor, ZoomValue( aWidth ) );
} }
...@@ -1498,6 +1498,15 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -1498,6 +1498,15 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
Color ); Color );
} }
void GRArc1( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
wxPoint aCenter, int aWidth, int aColor )
{
GRSArc1( aClipBox, aDC, GRMapX( aStart.x ), GRMapY( aStart.y ),
GRMapX( aEnd.x ), GRMapY( aEnd.y ),
GRMapX( aCenter.x ), GRMapY( aCenter.y ), ZoomValue( aWidth ),
aColor );
}
/* /*
* Draw an arc, width = width, in screen space. * Draw an arc, width = width, in screen space.
......
...@@ -123,12 +123,13 @@ void GERBER::ResetDefaultValues() ...@@ -123,12 +123,13 @@ void GERBER::ResetDefaultValues()
m_LayerName = wxT( "no layer name" ); // Layer name from the LN command m_LayerName = wxT( "no layer name" ); // Layer name from the LN command
m_LayerNegative = false; // true = Negative Layer m_LayerNegative = false; // true = Negative Layer
m_ImageNegative = false; // true = Negative image m_ImageNegative = false; // true = Negative image
m_GerbMetric = false; // false = Inches, true = metric m_GerbMetric = false; // false = Inches (default), true = metric
m_Relative = false; // false = absolute Coord, m_Relative = false; // false = absolute Coord,
// true = relative Coord // true = relative Coord
m_NoTrailingZeros = false; // true: trailing zeros deleted m_NoTrailingZeros = false; // true: trailing zeros deleted
m_MirorA = false; // true: miror / axe A (default = X) m_MirrorA = false; // true: miror / axe A (default = X)
m_MirorB = false; // true: miror / axe B (default = Y) m_MirrorB = false; // true: miror / axe B (default = Y)
m_SwapAxis = false; // false if A = X, B = Y; true if A =Y, B = Y
m_Has_DCode = false; // true = DCodes in file m_Has_DCode = false; // true = DCodes in file
// false = no DCode-> // false = no DCode->
// search for separate DCode file // search for separate DCode file
......
...@@ -38,11 +38,12 @@ public: ...@@ -38,11 +38,12 @@ public:
bool m_GerbMetric; // false = Inches, true = metric bool m_GerbMetric; // false = Inches, true = metric
bool m_Relative; // false = absolute Coord, true = relative Coord bool m_Relative; // false = absolute Coord, true = relative Coord
bool m_NoTrailingZeros; // true: remove tailing zeros. bool m_NoTrailingZeros; // true: remove tailing zeros.
bool m_MirorA; // true: miror / axe A (X) bool m_SwapAxis; // false (default) if A = X and B = Y
bool m_MirorB; // true: miror / axe B (Y) // true if A = Y, B = X
bool m_Has_DCode; // true = DCodes in file bool m_MirrorA; // true: miror / axe A (X)
// (false = no DCode -> separate DCode file bool m_MirrorB; // true: miror / axe B (Y)
wxPoint m_Offset; // Coord Offset wxPoint m_ImageOffset; // Coord Offset, from IO command
wxPoint m_Offset; // Coord Offset, from OF command
wxSize m_FmtScale; // Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4 wxSize m_FmtScale; // Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4
wxSize m_FmtLen; // Nb chars per coord. ex fmt 2.3, m_FmtLen = 5 wxSize m_FmtLen; // Nb chars per coord. ex fmt 2.3, m_FmtLen = 5
wxRealPoint m_LayerScale; // scale (X and Y) of layer. wxRealPoint m_LayerScale; // scale (X and Y) of layer.
...@@ -62,7 +63,8 @@ public: ...@@ -62,7 +63,8 @@ public:
int m_FilesPtr; // Stack pointer for files list int m_FilesPtr; // Stack pointer for files list
int m_Selected_Tool; // For hightlight: current selected Dcode int m_Selected_Tool; // For hightlight: current selected Dcode
bool m_Has_DCode; // true = DCodes in file
// (false = no DCode -> separate DCode file
bool m_360Arc_enbl; // Enbl 360 deg circular interpolation bool m_360Arc_enbl; // Enbl 360 deg circular interpolation
bool m_PolygonFillMode; // Enable polygon mode (read coord as a polygon descr) bool m_PolygonFillMode; // Enable polygon mode (read coord as a polygon descr)
int m_PolygonFillModeState; // In polygon mode: 0 = first segm, 1 = next segm int m_PolygonFillModeState; // In polygon mode: 0 = first segm, 1 = next segm
......
...@@ -42,17 +42,24 @@ ...@@ -42,17 +42,24 @@
/**********************************************************/ /**********************************************************/
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) : GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER* aGerberparams ) :
BOARD_ITEM( aParent, TYPE_GERBER_DRAW_ITEM ) BOARD_ITEM( aParent, TYPE_GERBER_DRAW_ITEM )
/**********************************************************/ /**********************************************************/
{ {
m_Layer = 0; m_imageParams = aGerberparams;
m_Shape = GBR_SEGMENT; m_Layer = 0;
m_Flashed = false; m_Shape = GBR_SEGMENT;
m_DCode = 0; m_Flashed = false;
m_UnitsMetric = false; m_DCode = 0;
m_UnitsMetric = false;
m_ImageNegative = false; m_ImageNegative = false;
m_LayerNegative = false; m_LayerNegative = false;
m_swapAxis = false;
m_mirrorA = false;
m_mirrorB = false;
m_drawScale.x = m_drawScale.y = 1.0;
if( m_imageParams )
SetLayerParameters();
} }
...@@ -60,24 +67,30 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) : ...@@ -60,24 +67,30 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent ) :
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) : GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) :
BOARD_ITEM( aSource ) BOARD_ITEM( aSource )
{ {
m_imageParams = aSource.m_imageParams;
m_Shape = aSource.m_Shape; m_Shape = aSource.m_Shape;
m_Flags = aSource.m_Flags; m_Flags = aSource.m_Flags;
m_TimeStamp = aSource.m_TimeStamp; m_TimeStamp = aSource.m_TimeStamp;
SetStatus( aSource.ReturnStatus() ); SetStatus( aSource.ReturnStatus() );
m_Start = aSource.m_Start; m_Start = aSource.m_Start;
m_End = aSource.m_End; m_End = aSource.m_End;
m_Size = aSource.m_Size; m_Size = aSource.m_Size;
m_Layer = aSource.m_Layer; m_Layer = aSource.m_Layer;
m_Shape = aSource.m_Shape; m_Shape = aSource.m_Shape;
m_Flashed = aSource.m_Flashed; m_Flashed = aSource.m_Flashed;
m_DCode = aSource.m_DCode; m_DCode = aSource.m_DCode;
m_PolyCorners = aSource.m_PolyCorners; m_PolyCorners = aSource.m_PolyCorners;
m_UnitsMetric = aSource.m_UnitsMetric; m_UnitsMetric = aSource.m_UnitsMetric;
m_ImageNegative = aSource.m_ImageNegative; m_ImageNegative = aSource.m_ImageNegative;
m_LayerNegative = aSource.m_LayerNegative; m_LayerNegative = aSource.m_LayerNegative;
m_swapAxis = aSource.m_swapAxis;
m_mirrorA = aSource.m_mirrorA;
m_mirrorB = aSource.m_mirrorB;
m_layerOffset = aSource.m_layerOffset;
m_drawScale.x = aSource.m_drawScale.x;
m_drawScale.y = aSource.m_drawScale.y;
} }
...@@ -92,6 +105,55 @@ GERBER_DRAW_ITEM* GERBER_DRAW_ITEM::Copy() const ...@@ -92,6 +105,55 @@ GERBER_DRAW_ITEM* GERBER_DRAW_ITEM::Copy() const
} }
/**
* Function GetABPosition
* returns the image position of aPosition for this object.
* Image position is the value of aPosition, modified by image parameters:
* offsets, axis selection, scale, rotation
* @param aXYPosition = position in Y,X gerber axis
* @return const wxPoint& - The position in A,B axis.
*/
wxPoint GERBER_DRAW_ITEM::GetABPosition( wxPoint& aXYPosition )
{
/* Note: RS274Xrevd_e is obscure about the order of transforms:
* For instance: Rotation must be made after or before mirroring ?
*/
wxPoint abPos = aXYPosition;
if( m_swapAxis )
EXCHG( abPos.x, abPos.y );
abPos += m_layerOffset + m_imageParams->m_ImageOffset;
abPos.x = wxRound( abPos.x * m_drawScale.x );
abPos.y = wxRound( abPos.y * m_drawScale.y );
if( m_imageParams->m_Rotation )
RotatePoint( &abPos, m_imageParams->m_Rotation );
if( m_mirrorA )
NEGATE( abPos.x );
if( m_mirrorB )
NEGATE( abPos.y );
return abPos;
}
/** function SetLayerParameters
* Initialize draw parameters from Image and Layer parameters
* found in the gerber file:
* m_UnitsMetric,
* m_MirrorA, m_MirrorB,
* m_DrawScale, m_DrawOffset
*/
void GERBER_DRAW_ITEM::SetLayerParameters()
{
m_UnitsMetric = m_imageParams->m_GerbMetric;
m_swapAxis = m_imageParams->m_SwapAxis; // false if A = X, B = Y;
// true if A =Y, B = Y
m_mirrorA = m_imageParams->m_MirrorA; // true: mirror / axe A
m_mirrorB = m_imageParams->m_MirrorB; // true: mirror / axe B
m_drawScale = m_imageParams->m_LayerScale; // A and B scaling factor
m_layerOffset = m_imageParams->m_Offset; // Offset from OF command
}
wxString GERBER_DRAW_ITEM::ShowGBRShape() wxString GERBER_DRAW_ITEM::ShowGBRShape()
{ {
switch( m_Shape ) switch( m_Shape )
...@@ -215,11 +277,11 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode, ...@@ -215,11 +277,11 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
if( color & HIGHT_LIGHT_FLAG ) if( color & HIGHT_LIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor; color = ColorRefs[color & MASKCOLOR].m_LightColor;
alt_color = g_DrawBgColor ; alt_color = g_DrawBgColor;
if( m_Flags & DRAW_ERASED ) // draw in background color ("negative" color) if( m_Flags & DRAW_ERASED ) // draw in background color ("negative" color)
{ {
EXCHG(color, alt_color); EXCHG( color, alt_color );
} }
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
...@@ -244,27 +306,29 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode, ...@@ -244,27 +306,29 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
if( !isFilled ) if( !isFilled )
{ {
// draw the border of the pen's path using two circles, each as narrow as possible // draw the border of the pen's path using two circles, each as narrow as possible
GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius - halfPenWidth, 0, color ); GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius + halfPenWidth, 0, color ); radius - halfPenWidth, 0, color );
GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
radius + halfPenWidth, 0, color );
} }
else // Filled mode else // Filled mode
{ {
GRCircle( &aPanel->m_ClipBox, aDC, m_Start, radius, m_Size.x, color ); GRCircle( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
radius, m_Size.x, color );
} }
break; break;
case GBR_ARC: case GBR_ARC:
if( !isFilled ) if( !isFilled )
{ {
GRArc1( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y, GRArc1( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
m_End.x, m_End.y, GetABPosition( m_End ), GetABPosition( m_ArcCentre ),
m_ArcCentre.x, m_ArcCentre.y, 0, color ); 0, color );
} }
else else
{ {
GRArc1( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y, GRArc1( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
m_End.x, m_End.y, GetABPosition( m_End ), GetABPosition( m_ArcCentre ),
m_ArcCentre.x, m_ArcCentre.y,
m_Size.x, color ); m_Size.x, color );
} }
break; break;
...@@ -281,11 +345,11 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode, ...@@ -281,11 +345,11 @@ void GERBER_DRAW_ITEM::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
case GBR_SEGMENT: case GBR_SEGMENT:
if( !isFilled ) if( !isFilled )
GRCSegm( &aPanel->m_ClipBox, aDC, m_Start.x, m_Start.y, GRCSegm( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
m_End.x, m_End.y, m_Size.x, color ); GetABPosition( m_End ), m_Size.x, color );
else else
GRFillCSegm( &aPanel->m_ClipBox, aDC, m_Start.x, GRFilledSegment( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ),
m_Start.y, m_End.x, m_End.y, m_Size.x, color ); GetABPosition( m_End ), m_Size.x, color );
break; break;
default: default:
...@@ -307,7 +371,7 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_Rect* aClipBox, ...@@ -307,7 +371,7 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_Rect* aClipBox,
wxDC* aDC, wxDC* aDC,
int aColor, int aColor,
const wxPoint& aOffset, const wxPoint& aOffset,
bool aFilledShape ) bool aFilledShape )
{ {
std::vector<wxPoint> points; std::vector<wxPoint> points;
...@@ -317,6 +381,7 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_Rect* aClipBox, ...@@ -317,6 +381,7 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_Rect* aClipBox,
for( unsigned ii = 0; ii < points.size(); ii++ ) for( unsigned ii = 0; ii < points.size(); ii++ )
{ {
points[ii] += aOffset; points[ii] += aOffset;
points[ii] = GetABPosition( points[ii] );
} }
} }
...@@ -355,7 +420,7 @@ void GERBER_DRAW_ITEM::DisplayInfo( WinEDA_DrawFrame* frame ) ...@@ -355,7 +420,7 @@ void GERBER_DRAW_ITEM::DisplayInfo( WinEDA_DrawFrame* frame )
bool GERBER_DRAW_ITEM::HitTest( const wxPoint& ref_pos ) bool GERBER_DRAW_ITEM::HitTest( const wxPoint& ref_pos )
{ {
// TODO: a better analyse od the shape (perhaps create a D_CODE::HitTest for flashed items) // TODO: a better analyse od the shape (perhaps create a D_CODE::HitTest for flashed items)
int radius = MIN( m_Size.x, m_Size.y) >> 1; int radius = MIN( m_Size.x, m_Size.y ) >> 1;
// delta is a vector from m_Start to m_End (an origin of m_Start) // delta is a vector from m_Start to m_End (an origin of m_Start)
wxPoint delta = m_End - m_Start; wxPoint delta = m_End - m_Start;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "base_struct.h" #include "base_struct.h"
#include "class_board_item.h" #include "class_board_item.h"
class GERBER;
/* Shapes id for basic shapes ( .m_Shape member ) */ /* Shapes id for basic shapes ( .m_Shape member ) */
enum Gbr_Basic_Shapes { enum Gbr_Basic_Shapes {
...@@ -58,7 +59,7 @@ private: ...@@ -58,7 +59,7 @@ private:
public: public:
bool m_UnitsMetric; /* store here the gerber units (inch/mm). bool m_UnitsMetric; /* store here the gerber units (inch/mm).
* Used only to calculate aperture macros shapes sizes */ * Used only to calculate aperture macros shapes sizes */
int m_Shape; // Shape and type of this gerber item int m_Shape; // Shape and type of this gerber item
wxPoint m_Start; // Line or arc start point or position of the shape wxPoint m_Start; // Line or arc start point or position of the shape
...@@ -67,18 +68,34 @@ public: ...@@ -67,18 +68,34 @@ public:
wxPoint m_ArcCentre; // for arcs only: Centre of arc wxPoint m_ArcCentre; // for arcs only: Centre of arc
std::vector <wxPoint> m_PolyCorners; // list of corners for polygons (G36 to G37 coordinates) std::vector <wxPoint> m_PolyCorners; // list of corners for polygons (G36 to G37 coordinates)
// or for complex shapes which are converted to polygon // or for complex shapes which are converted to polygon
wxSize m_Size; // Flashed shapes size of the shape wxSize m_Size; // Flashed shapes: size of the shape
// Lines : m_Size.x = m_Size.y = line width // Lines : m_Size.x = m_Size.y = line width
bool m_Flashed; // True for flashed items bool m_Flashed; // True for flashed items
int m_DCode; // DCode used to draw this item. int m_DCode; // DCode used to draw this item.
// 0 for items that do not use DCodes (polygons) // 0 for items that do not use DCodes (polygons)
// or when unknown and normal values are 10 to 999 // or when unknown and normal values are 10 to 999
// values 0 to 9 can be used for special purposes // values 0 to 9 can be used for special purposes
bool m_ImageNegative; // true = item in negative image // These values are used to draw this item, according to gerber layers parameters
bool m_LayerNegative; // TRUE = item in negative Layer // Because these values can change inside a gerber image, they are stored here
// for each item
bool m_ImageNegative; // true = item in negative image
bool m_LayerNegative; // TRUE = item in negative Layer
private:
GERBER* m_imageParams; /* main GERBER info for this item
* Note: some params stored in this class are common
* to the whole gerber file (i.e) the whole graphic layer
* and some can change when reaging the file, so they
* are stored inside this item
* there is no redundancy for these parameters
*/
bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
bool m_mirrorA; // true: mirror / axe A
bool m_mirrorB; // true: mirror / axe B
wxRealPoint m_drawScale; // A and B scaling factor
wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
public: public:
GERBER_DRAW_ITEM( BOARD_ITEM* aParent ); GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER* aGerberparams );
GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ); GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
~GERBER_DRAW_ITEM(); ~GERBER_DRAW_ITEM();
...@@ -99,6 +116,15 @@ public: ...@@ -99,6 +116,15 @@ public:
} }
/** function SetLayerParameters
* Initialize parameters from Image and Layer parameters
* found in the gerber file:
* m_UnitsMetric,
* m_MirrorA, m_MirrorB,
* m_DrawScale, m_DrawOffset
*/
void SetLayerParameters( );
/** /**
* Function Move * Function Move
* move this object. * move this object.
...@@ -110,12 +136,22 @@ public: ...@@ -110,12 +136,22 @@ public:
* Function GetPosition * Function GetPosition
* returns the position of this object. * returns the position of this object.
* @return const wxPoint& - The position of this object. * @return const wxPoint& - The position of this object.
* This function exists mainly to satisfy the virtual GetPosition() in parent class
*/ */
wxPoint& GetPosition() wxPoint& GetPosition()
{ {
return m_Start; // it had to be start or end. return m_Start; // it had to be start or end.
} }
/**
* Function GetABPosition
* returns the image position of aPosition for this object.
* Image position is the value of aPosition, modified by image parameters:
* offsets, axis selection, scale, rotation
* @param aXYPosition = position in Y,X gerber axis
* @return const wxPoint - The given position in A,B axis.
*/
wxPoint GetABPosition(wxPoint& aXYPosition );
/** /**
* Function GetDcodeDescr * Function GetDcodeDescr
...@@ -135,8 +171,8 @@ public: ...@@ -135,8 +171,8 @@ public:
/** function DrawGbrPoly /** function DrawGbrPoly
* a helper function used id ::Draw to draw the polygon stored ion m_PolyCorners * a helper function used id ::Draw to draw the polygon stored ion m_PolyCorners
*/ */
void DrawGbrPoly( EDA_Rect* aClipBox, void DrawGbrPoly( EDA_Rect* aClipBox,
wxDC* aDC, int aColor, wxDC* aDC, int aColor,
const wxPoint& aOffset, bool aFilledShape ); const wxPoint& aOffset, bool aFilledShape );
/* divers */ /* divers */
...@@ -182,9 +218,10 @@ public: ...@@ -182,9 +218,10 @@ public:
} }
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG) #if defined(DEBUG)
/** /**
* Function Show * Function Show
* is used to output the object tree, currently for debugging only. * is used to output the object tree, currently for debugging only.
...@@ -193,6 +230,7 @@ public: ...@@ -193,6 +230,7 @@ public:
* @param os The ostream& to output to. * @param os The ostream& to output to.
*/ */
virtual void Show( int nestLevel, std::ostream& os ); virtual void Show( int nestLevel, std::ostream& os );
#endif #endif
}; };
......
...@@ -358,7 +358,7 @@ static void fillArcPOLY( BOARD* aPcb, GERBER_DRAW_ITEM* aGbrItem, ...@@ -358,7 +358,7 @@ static void fillArcPOLY( BOARD* aPcb, GERBER_DRAW_ITEM* aGbrItem,
/* in order to calculate arc parameters, we use fillArcGBRITEM /* in order to calculate arc parameters, we use fillArcGBRITEM
* so we muse create a dummy track and use its geometric parameters * so we muse create a dummy track and use its geometric parameters
*/ */
static GERBER_DRAW_ITEM dummyGbrItem( NULL ); static GERBER_DRAW_ITEM dummyGbrItem( NULL, NULL );
aGbrItem->m_LayerNegative = aLayerNegative; aGbrItem->m_LayerNegative = aLayerNegative;
aGbrItem->m_ImageNegative = aImageNegative; aGbrItem->m_ImageNegative = aImageNegative;
...@@ -861,12 +861,11 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int ...@@ -861,12 +861,11 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int
if( !m_Exposure ) if( !m_Exposure )
{ {
m_Exposure = true; m_Exposure = true;
gbritem = new GERBER_DRAW_ITEM( pcb ); gbritem = new GERBER_DRAW_ITEM( pcb, this );
pcb->m_Drawings.Append( gbritem ); pcb->m_Drawings.Append( gbritem );
gbritem->m_Shape = GBR_POLYGON; gbritem->m_Shape = GBR_POLYGON;
gbritem->SetLayer( activeLayer ); gbritem->SetLayer( activeLayer );
gbritem->m_Flashed = false; gbritem->m_Flashed = false;
gbritem->m_UnitsMetric = m_GerbMetric;
} }
switch( m_Iterpolation ) switch( m_Iterpolation )
...@@ -940,8 +939,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int ...@@ -940,8 +939,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int
switch( m_Iterpolation ) switch( m_Iterpolation )
{ {
case GERB_INTERPOL_LINEAR_1X: case GERB_INTERPOL_LINEAR_1X:
gbritem = new GERBER_DRAW_ITEM( pcb ); gbritem = new GERBER_DRAW_ITEM( pcb, this );
gbritem->m_UnitsMetric = m_GerbMetric;
pcb->m_Drawings.Append( gbritem ); pcb->m_Drawings.Append( gbritem );
// D( printf( "Add line %d,%d to %d,%d\n", // D( printf( "Add line %d,%d to %d,%d\n",
// m_PreviousPos.x, m_PreviousPos.y, // m_PreviousPos.x, m_PreviousPos.y,
...@@ -958,8 +956,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int ...@@ -958,8 +956,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int
case GERB_INTERPOL_ARC_NEG: case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS: case GERB_INTERPOL_ARC_POS:
gbritem = new GERBER_DRAW_ITEM( pcb ); gbritem = new GERBER_DRAW_ITEM( pcb, this );
gbritem->m_UnitsMetric = m_GerbMetric;
pcb->m_Drawings.Append( gbritem ); pcb->m_Drawings.Append( gbritem );
// D( printf( "Add arc %d,%d to %d,%d center %d, %d interpol %d 360_enb %d\n", // D( printf( "Add arc %d,%d to %d,%d center %d, %d interpol %d 360_enb %d\n",
// m_PreviousPos.x, m_PreviousPos.y, m_CurrentPos.x, // m_PreviousPos.x, m_PreviousPos.y, m_CurrentPos.x,
...@@ -999,8 +996,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int ...@@ -999,8 +996,7 @@ bool GERBER::Execute_DCODE_Command( WinEDA_GerberFrame* frame, char*& text, int
aperture = tool->m_Shape; aperture = tool->m_Shape;
} }
gbritem = new GERBER_DRAW_ITEM( pcb ); gbritem = new GERBER_DRAW_ITEM( pcb, this );
gbritem->m_UnitsMetric = m_GerbMetric;
pcb->m_Drawings.Append( gbritem ); pcb->m_Drawings.Append( gbritem );
// D( printf( "Add flashed dcode %d layer %d at %d %d\n", dcode, activeLayer, // D( printf( "Add flashed dcode %d layer %d at %d %d\n", dcode, activeLayer,
// m_CurrentPos.x, m_CurrentPos.y ); ) // m_CurrentPos.x, m_CurrentPos.y ); )
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
// So a gerber layer is not like a board layer or the graphic layers used in Gerbview to show a file. // So a gerber layer is not like a board layer or the graphic layers used in Gerbview to show a file.
enum RS274X_PARAMETERS { enum RS274X_PARAMETERS {
// Directive parameters: single usage recommended // Directive parameters: single usage recommended
// Must be at the beginning of the file
AXIS_SELECT = CODE( 'A', 'S' ), // Default: A=X, B=Y AXIS_SELECT = CODE( 'A', 'S' ), // Default: A=X, B=Y
FORMAT_STATEMENT = CODE( 'F', 'S' ), // no default: this command must exists FORMAT_STATEMENT = CODE( 'F', 'S' ), // no default: this command must exists
MIRROR_IMAGE = CODE( 'M', 'I' ), // Default: mo mirror MIRROR_IMAGE = CODE( 'M', 'I' ), // Default: mo mirror
...@@ -291,7 +292,7 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -291,7 +292,7 @@ bool GERBER::ExecuteRS274XCommand( int command,
conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT; conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT;
break; break;
case OFFSET: // command: OFAnnBnn (nn = float number) case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset
m_Offset.x = m_Offset.y = 0; m_Offset.x = m_Offset.y = 0;
while( *text != '*' ) while( *text != '*' )
{ {
...@@ -307,10 +308,10 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -307,10 +308,10 @@ bool GERBER::ExecuteRS274XCommand( int command,
text++; text++;
fcoord = ReadDouble( text ); fcoord = ReadDouble( text );
m_Offset.y = wxRound( fcoord * conv_scale ); m_Offset.y = wxRound( fcoord * conv_scale );
NEGATE( m_Offset.y );
break; break;
} }
} }
break; break;
case SCALE_FACTOR: case SCALE_FACTOR:
...@@ -330,17 +331,44 @@ bool GERBER::ExecuteRS274XCommand( int command, ...@@ -330,17 +331,44 @@ bool GERBER::ExecuteRS274XCommand( int command,
break; break;
} }
} }
break;
if( m_LayerScale.x != 1.0 || m_LayerScale.y != 1.0 ) case IMAGE_OFFSET: // command: IOAnnBnn (nn = float number) = Image Offset
m_ImageOffset.x = m_ImageOffset.y = 0;
while( *text != '*' )
{ {
msg.Printf( _( "RS274X: FS command: Gerbview uses 1.0 only scale factor" ) ); switch( *text )
ReportMessage( msg ); {
case 'A': // A axis offset in current unit (inch or mm)
text++;
fcoord = ReadDouble( text );
m_ImageOffset.x = wxRound( fcoord * conv_scale );
break;
case 'B': // B axis offset in current unit (inch or mm)
text++;
fcoord = ReadDouble( text );
m_ImageOffset.y = wxRound( fcoord * conv_scale );
NEGATE( m_ImageOffset.y );
break;
}
} }
break; break;
case IMAGE_ROTATION: // command IR0* or IR90* or IR180* or IR270*
if( strnicmp( text, "0*", 2 ) == 0 )
m_Rotation = 0;
if( strnicmp( text, "90*", 2 ) == 0 )
m_Rotation = 900;
if( strnicmp( text, "180*", 2 ) == 0 )
m_Rotation = 1800;
if( strnicmp( text, "270*", 2 ) == 0 )
m_Rotation = 2700;
else
ReportMessage( _( "RS274X: Command \"IR\" rotation value not allowed" ) );
break;
case IMAGE_JUSTIFY: case IMAGE_JUSTIFY:
case IMAGE_ROTATION:
case IMAGE_OFFSET:
case PLOTTER_FILM: case PLOTTER_FILM:
case KNOCKOUT: case KNOCKOUT:
case STEP_AND_REPEAT: case STEP_AND_REPEAT:
......
...@@ -167,6 +167,8 @@ void Show_Items_DCode_Value( WinEDA_DrawPanel* aPanel, wxDC* aDC, BOARD* aPcb, i ...@@ -167,6 +167,8 @@ void Show_Items_DCode_Value( WinEDA_DrawPanel* aPanel, wxDC* aDC, BOARD* aPcb, i
pos.y = (gerb_item->m_Start.y + gerb_item->m_End.y) / 2; pos.y = (gerb_item->m_Start.y + gerb_item->m_End.y) / 2;
} }
pos = gerb_item->GetABPosition( pos );
Line.Printf( wxT( "D%d" ), gerb_item->m_DCode ); Line.Printf( wxT( "D%d" ), gerb_item->m_DCode );
width = MIN( gerb_item->m_Size.x, gerb_item->m_Size.y ); width = MIN( gerb_item->m_Size.x, gerb_item->m_Size.y );
......
...@@ -168,17 +168,23 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -168,17 +168,23 @@ void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int xc, int yc, int Color ); int xc, int yc, int Color );
void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRArc1( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int xc, int yc, int width, int Color ); int xc, int yc, int width, int Color );
void GRArc1( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
wxPoint aCenter, int aWidth, int aColor );
void GRFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, void GRFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y,
int StAngle, int EndAngle, int r, int Color, int BgColor ); int StAngle, int EndAngle, int r, int Color, int BgColor );
void GRFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle, void GRFilledArc( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int StAngle,
int EndAngle, int r, int width, int Color, int BgColor ); int EndAngle, int r, int width, int Color, int BgColor );
void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, int Color ); void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, int Color );
void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int aPenSize, int Color );
void GRFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRFillCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int Color ); int width, int Color );
void GRFilledSegment( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
int aWidth, int aColor );
void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int aPenSize, int Color ); int width, int aPenSize, int Color );
void GRCSegm( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
int aWidth, int aColor );
void GRSetColor( int Color ); void GRSetColor( int Color );
void GRSetDefaultPalette(); void GRSetDefaultPalette();
...@@ -200,7 +206,5 @@ void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, ...@@ -200,7 +206,5 @@ void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
void GRLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[], void GRLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color ); int lines, int width, int Color );
void GRSLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color );
#endif /* define GR_BASIC */ #endif /* define GR_BASIC */
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