kicad/gerbview/rs274d.cpp

782 lines
24 KiB
C++
Raw Normal View History

/**
* @file rs274d.cpp
* @brief functions to read the rs274d commands from a rs274d/rs274x file
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2018-05-13 16:44:26 +00:00
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <gerbview.h>
#include <gerbview_frame.h>
#include <trigo.h>
#include <gerber_file_image.h>
#include <X2_gerber_attributes.h>
#include <cmath>
/* Gerber: NOTES about some important commands found in RS274D and RS274X (G codes).
* Some are now deprecated, but deprecated commands must be known by the Gerber reader
* Gn =
* G01 linear interpolation (linear trace)
* G02, G20, G21 Circular interpolation, clockwise
* G03, G30, G31 Circular interpolation, counterclockwise
* G04 = comment. Since Sept 2014, file attributes and other X2 attributes can be found here
* if the line starts by G04 #@!
* G06 parabolic interpolation
* G07 Cubic Interpolation
* G10 linear interpolation (scale x10)
* G11 linear interpolation (0.1x range)
* G12 linear interpolation (0.01x scale)
* G36 Start polygon mode (called a region, because the "polygon" can include arcs)
2010-09-29 19:00:35 +00:00
* G37 Stop polygon mode (and close it)
* G54 Selection Tool (outdated)
* G60 linear interpolation (scale x100)
2010-09-29 19:00:35 +00:00
* G70 Select Units = Inches
* G71 Select Units = Millimeters
* G74 enable 90 deg mode for arcs (CW or CCW)
* G75 enable 360 degrees for arcs (CW or CCW)
* G90 mode absolute coordinates
*
* X, Y
* X and Y are followed by + or - and m + n digits (not separated)
* m = integer part
* n = part after the comma
*ic formats: m = 2, n = 3 (size 2.3)
* m = 3, n = 4 (size 3.4)
* eg
2010-09-29 19:00:35 +00:00
* GxxX00345Y-06123*
*
* Tools and D_CODES
* Tool number (identification of shapes)
2010-09-29 19:00:35 +00:00
* 10 to 999
* D_CODES:
2010-09-29 19:00:35 +00:00
* D01 ... D9 = command codes:
* D01 = activating light (pen down) when placement
* D02 = light extinction (pen up) when placement
* D03 = Flash
* D09 = VAPE Flash (I never see this command in gerber file)
* D51 = G54 preceded by -> Select VAPE
*
2010-09-29 19:00:35 +00:00
* D10 ... D999 = Identification Tool: tool selection
2007-09-26 04:09:22 +00:00
*/
/* Local Functions (are lower case since they are private to this source file)
2010-09-28 14:42:05 +00:00
**/
2008-11-14 07:46:43 +00:00
/**
* Function fillFlashedGBRITEM
2010-09-28 14:42:05 +00:00
* initializes a given GBRITEM so that it can draw a circle which is filled and
* has no pen border.
*
2010-09-28 14:42:05 +00:00
* @param aGbrItem The GBRITEM to fill in.
* @param aAperture the associated type of aperture
* @param Dcode_index The DCODE value, like D14
* @param aPos The center point of the flash
* @param aSize The diameter of the round flash
* @param aLayerNegative = true if the current layer is negative
2007-09-26 04:09:22 +00:00
*/
void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
2016-05-26 11:57:43 +00:00
APERTURE_T aAperture,
int Dcode_index,
const wxPoint& aPos,
wxSize aSize,
bool aLayerNegative )
{
aGbrItem->m_Size = aSize;
2010-09-28 14:42:05 +00:00
aGbrItem->m_Start = aPos;
aGbrItem->m_End = aGbrItem->m_Start;
2010-09-28 14:42:05 +00:00
aGbrItem->m_DCode = Dcode_index;
aGbrItem->SetLayerPolarity( aLayerNegative );
2010-09-28 14:42:05 +00:00
aGbrItem->m_Flashed = true;
aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
switch( aAperture )
{
case APT_POLYGON: // flashed regular polygon
aGbrItem->m_Shape = GBR_SPOT_POLY;
break;
case APT_CIRCLE:
aGbrItem->m_Shape = GBR_SPOT_CIRCLE;
aGbrItem->m_Size.y = aGbrItem->m_Size.x;
break;
2007-09-26 04:09:22 +00:00
case APT_OVAL:
aGbrItem->m_Shape = GBR_SPOT_OVAL;
break;
2007-09-26 04:09:22 +00:00
case APT_RECT:
aGbrItem->m_Shape = GBR_SPOT_RECT;
break;
2007-09-26 04:09:22 +00:00
case APT_MACRO:
aGbrItem->m_Shape = GBR_SPOT_MACRO;
// Cache the bounding box for aperture macros
aGbrItem->GetDcodeDescr()->GetMacro()->GetApertureMacroShape( aGbrItem, aPos );
break;
}
}
/**
2010-09-28 14:42:05 +00:00
* Function fillLineGBRITEM
* initializes a given GBRITEM so that it can draw a linear D code.
*
2010-09-28 14:42:05 +00:00
* @param aGbrItem The GERBER_DRAW_ITEM to fill in.
* @param Dcode_index The DCODE value, like D14
* @param aStart The starting point of the line
* @param aEnd The ending point of the line
* @param aPenSize The size of the flash. Note rectangular shapes are legal.
* @param aLayerNegative = true if the current layer is negative
*/
void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
2010-09-28 14:42:05 +00:00
int Dcode_index,
const wxPoint& aStart,
const wxPoint& aEnd,
wxSize aPenSize,
bool aLayerNegative )
{
2010-09-28 14:42:05 +00:00
aGbrItem->m_Flashed = false;
aGbrItem->m_Size = aPenSize;
2008-11-14 07:46:43 +00:00
2010-09-28 14:42:05 +00:00
aGbrItem->m_Start = aStart;
aGbrItem->m_End = aEnd;
2010-09-28 14:42:05 +00:00
aGbrItem->m_DCode = Dcode_index;
aGbrItem->SetLayerPolarity( aLayerNegative );
aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
}
2007-09-26 04:09:22 +00:00
/**
2010-09-28 14:42:05 +00:00
* Function fillArcGBRITEM
* initializes a given GBRITEM so that it can draw an arc G code.
* <p>
* if multiquadrant == true : arc can be 0 to 360 degrees
* and \a rel_center is the center coordinate relative to start point.
* <p>
* if multiquadrant == false arc can be only 0 to 90 deg,
* and only in the same quadrant :
* <ul>
* <li> absolute angle 0 to 90 (quadrant 1) or
* <li> absolute angle 90 to 180 (quadrant 2) or
* <li> absolute angle 180 to 270 (quadrant 3) or
* <li> absolute angle 270 to 0 (quadrant 4)
* </ul><p>
* @param aGbrItem is the GBRITEM to fill in.
* @param Dcode_index is the DCODE value, like D14
* @param aStart is the starting point
* @param aEnd is the ending point
* @param aRelCenter is the center coordinate relative to start point,
* given in ABSOLUTE VALUE and the sign of values x et y de rel_center
2017-06-15 09:28:36 +00:00
* must be calculated from the previously given constraint: arc only in the same quadrant.
* @param aClockwise true if arc must be created clockwise
* @param aPenSize The size of the flash. Note rectangular shapes are legal.
* @param aMultiquadrant = true to create arcs upto 360 deg,
* false when arc is inside one quadrant
* @param aLayerNegative = true if the current layer is negative
*/
void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index,
const wxPoint& aStart, const wxPoint& aEnd,
const wxPoint& aRelCenter, wxSize aPenSize,
bool aClockwise, bool aMultiquadrant,
bool aLayerNegative )
{
wxPoint center, delta;
2007-09-26 04:09:22 +00:00
2010-09-28 14:42:05 +00:00
aGbrItem->m_Shape = GBR_ARC;
aGbrItem->m_Size = aPenSize;
2010-09-28 14:42:05 +00:00
aGbrItem->m_Flashed = false;
2007-09-26 04:09:22 +00:00
if( aGbrItem->m_GerberImageFile )
aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
if( aMultiquadrant )
center = aStart + aRelCenter;
2007-09-26 04:09:22 +00:00
else
{
// in single quadrant mode the relative coordinate aRelCenter is always >= 0
// So we must recalculate the actual sign of aRelCenter.x and aRelCenter.y
center = aRelCenter;
// calculate arc end coordinate relative to the starting point,
// because center is relative to the center point
2010-09-28 14:42:05 +00:00
delta = aEnd - aStart;
2007-09-26 04:09:22 +00:00
// now calculate the relative to aStart center position, for a draw function
// that use trigonometric arc angle (or counter-clockwise)
/* Quadrants:
* Y
* 2 | 1
* -------X
* 3 | 4
* C = actual relative arc center, S = arc start (axis origin) E = relative arc end
*/
2009-05-10 15:43:41 +00:00
if( (delta.x >= 0) && (delta.y >= 0) )
2007-09-26 04:09:22 +00:00
{
/* Quadrant 1 (trigo or cclockwise):
* C | E
* ---S---
* 3 | 4
*/
center.x = -center.x;
2007-09-26 04:09:22 +00:00
}
2009-05-10 15:43:41 +00:00
else if( (delta.x >= 0) && (delta.y < 0) )
2007-09-26 04:09:22 +00:00
{
/* Quadrant 4 (trigo or cclockwise):
* 2 | C
* ---S---
* 3 | E
*/
// Nothing to do
2007-09-26 04:09:22 +00:00
}
2009-05-10 15:43:41 +00:00
else if( (delta.x < 0) && (delta.y >= 0) )
2007-09-26 04:09:22 +00:00
{
/* Quadrant 2 (trigo or cclockwise):
* E | 1
* ---S---
* C | 4
*/
center.x = -center.x;
center.y = -center.y;
2007-09-26 04:09:22 +00:00
}
2009-05-10 15:43:41 +00:00
else
2007-09-26 04:09:22 +00:00
{
/* Quadrant 3 (trigo or cclockwise):
* 2 | 1
* ---S---
* E | C
*/
center.y = -center.y;
2007-09-26 04:09:22 +00:00
}
// Due to your draw arc function, we need this:
if( !aClockwise )
center = - center;
2007-09-26 04:09:22 +00:00
// Calculate actual arc center coordinate:
center += aStart;
}
if( aClockwise )
{
aGbrItem->m_Start = aStart;
aGbrItem->m_End = aEnd;
}
else
{
aGbrItem->m_Start = aEnd;
aGbrItem->m_End = aStart;
2007-09-26 04:09:22 +00:00
}
2010-09-28 14:42:05 +00:00
aGbrItem->m_ArcCentre = center;
aGbrItem->m_DCode = Dcode_index;
aGbrItem->SetLayerPolarity( aLayerNegative );
}
/**
* Function fillArcPOLY
* creates an arc G code when found in poly outlines.
* <p>
* if multiquadrant == true : arc can be 0 to 360 degrees
* and \a rel_center is the center coordinate relative to start point.
* <p>
* if multiquadrant == false arc can be only 0 to 90 deg,
* and only in the same quadrant :
* <ul>
* <li> absolute angle 0 to 90 (quadrant 1) or
* <li> absolute angle 90 to 180 (quadrant 2) or
* <li> absolute angle 180 to 270 (quadrant 3) or
* <li> absolute angle 270 to 0 (quadrant 4)
* </ul><p>
* @param aGbrItem is the GBRITEM to fill in.
* @param aStart is the starting point
* @param aEnd is the ending point
* @param rel_center is the center coordinate relative to start point,
* given in ABSOLUTE VALUE and the sign of values x et y de rel_center
* must be calculated from the previously given constraint: arc only in the
* same quadrant.
* @param aClockwise true if arc must be created clockwise
* @param aMultiquadrant = true to create arcs upto 360 deg,
* false when arc is inside one quadrant
* @param aLayerNegative = true if the current layer is negative
2007-09-26 04:09:22 +00:00
*/
static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem,
2010-09-28 14:42:05 +00:00
const wxPoint& aStart, const wxPoint& aEnd,
const wxPoint& rel_center,
bool aClockwise, bool aMultiquadrant,
bool aLayerNegative )
{
2010-09-28 14:42:05 +00:00
/* in order to calculate arc parameters, we use fillArcGBRITEM
* so we muse create a dummy track and use its geometric parameters
*/
2016-05-26 11:57:43 +00:00
static GERBER_DRAW_ITEM dummyGbrItem( NULL );
aGbrItem->SetLayerPolarity( aLayerNegative );
2016-05-26 11:57:43 +00:00
fillArcGBRITEM( &dummyGbrItem, 0,
aStart, aEnd, rel_center, wxSize(0, 0),
aClockwise, aMultiquadrant, aLayerNegative );
aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
2010-09-28 14:42:05 +00:00
wxPoint center;
center = dummyGbrItem.m_ArcCentre;
// Calculate coordinates relative to arc center;
2010-09-28 14:42:05 +00:00
wxPoint start = dummyGbrItem.m_Start - center;
wxPoint end = dummyGbrItem.m_End - center;
/* Calculate angle arc
* angles are in 0.1 deg
* angle is trigonometrical (counter-clockwise),
* and axis is the X,Y gerber coordinates
*/
double start_angle = ArcTangente( start.y, start.x );
double end_angle = ArcTangente( end.y, end.x );
// dummyTrack has right geometric parameters, but
// fillArcGBRITEM calculates arc parameters for a draw function that expects
// start_angle < end_angle. So ensure this is the case here:
// Due to the fact atan2 returns angles between -180 to + 180 degrees,
// this is not always the case ( a modulo 360.0 degrees can be lost )
if( start_angle > end_angle )
end_angle += 3600;
double arc_angle = start_angle - end_angle;
// Approximate arc by 36 segments per 360 degree
const int increment_angle = 3600 / 36;
int count = std::abs( arc_angle / increment_angle );
if( aGbrItem->m_Polygon.OutlineCount() == 0 )
aGbrItem->m_Polygon.NewOutline();
// calculate polygon corners
// when arc is counter-clockwise, dummyGbrItem arc goes from end to start
// and we must always create a polygon from start to end.
for( int ii = 0; ii <= count; ii++ )
{
double rot;
wxPoint end_arc = start;
if( aClockwise )
rot = ii * increment_angle; // rot is in 0.1 deg
else
rot = (count - ii) * increment_angle; // rot is in 0.1 deg
2010-09-28 14:42:05 +00:00
if( ii < count )
RotatePoint( &end_arc, -rot );
else // last point
end_arc = aClockwise ? end : start;
aGbrItem->m_Polygon.Append( VECTOR2I( end_arc + center ) );
}
}
/* Read the Gnn sequence and returns the value nn.
*/
int GERBER_FILE_IMAGE::GCodeNumber( char*& Text )
{
2007-09-26 04:09:22 +00:00
int ii = 0;
char* text;
char line[1024];
if( Text == NULL )
return 0;
Text++;
text = line;
while( IsNumber( *Text ) )
{
*(text++) = *(Text++);
}
*text = 0;
ii = atoi( line );
return ii;
}
/* Get the sequence Dnn and returns the value nn
*/
int GERBER_FILE_IMAGE::DCodeNumber( char*& Text )
{
2007-09-26 04:09:22 +00:00
int ii = 0;
char* text;
char line[1024];
if( Text == NULL )
return 0;
2007-09-26 04:09:22 +00:00
Text++;
text = line;
while( IsNumber( *Text ) )
*(text++) = *(Text++);
*text = 0;
ii = atoi( line );
return ii;
}
2007-09-26 04:09:22 +00:00
bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command )
{
2011-03-16 10:47:15 +00:00
// D( printf( "%22s: G_CODE<%d>\n", __func__, G_command ); )
2011-03-16 10:47:15 +00:00
switch( G_command )
2007-09-26 04:09:22 +00:00
{
case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can
// be safely ignored
break;
2007-09-26 04:09:22 +00:00
case GC_LINEAR_INTERPOL_1X:
m_Iterpolation = GERB_INTERPOL_LINEAR_1X;
break;
case GC_CIRCLE_NEG_INTERPOL:
m_Iterpolation = GERB_INTERPOL_ARC_NEG;
break;
case GC_CIRCLE_POS_INTERPOL:
m_Iterpolation = GERB_INTERPOL_ARC_POS;
break;
case GC_COMMENT:
// Skip comment, but only if the line does not start by "G04 #@! "
// which is a metadata, i.e. a X2 command inside the comment.
// this comment is called a "structured comment"
if( strncmp( text, " #@! ", 5 ) == 0 )
{
text += 5;
// The string starting at text is the same as the X2 attribute,
// but a X2 attribute ends by '%'. So we build the X2 attribute string
std::string x2buf;
while( *text && (*text != '*') )
{
x2buf += *text;
text++;
}
// add the end of X2 attribute string
x2buf += "*%";
x2buf += '\0';
char* cptr = (char*)x2buf.data();
int code_command = ReadXCommandID( cptr );
ExecuteRS274XCommand( code_command, NULL, 0, cptr );
}
while( *text && (*text != '*') )
text++;
2007-09-26 04:09:22 +00:00
break;
case GC_SELECT_TOOL:
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
int D_commande = DCodeNumber( text );
2007-09-26 04:09:22 +00:00
if( D_commande < FIRST_DCODE )
return false;
2010-09-28 14:42:05 +00:00
if( D_commande > (TOOLS_MAX_COUNT - 1) )
D_commande = TOOLS_MAX_COUNT - 1;
2007-09-26 04:09:22 +00:00
m_Current_Tool = D_commande;
D_CODE* pt_Dcode = GetDCODE( D_commande );
2007-09-26 04:09:22 +00:00
if( pt_Dcode )
pt_Dcode->m_InUse = true;
2007-09-26 04:09:22 +00:00
break;
}
case GC_SPECIFY_INCHES:
m_GerbMetric = false; // false = Inches, true = metric
2007-09-26 04:09:22 +00:00
break;
case GC_SPECIFY_MILLIMETERS:
m_GerbMetric = true; // false = Inches, true = metric
2007-09-26 04:09:22 +00:00
break;
2010-10-04 15:20:37 +00:00
case GC_TURN_OFF_360_INTERPOL: // disable Multi cadran arc and Arc interpol
m_360Arc_enbl = false;
m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // not sure it should be done
m_AsArcG74G75Cmd = true;
2007-09-26 04:09:22 +00:00
break;
case GC_TURN_ON_360_INTERPOL:
m_360Arc_enbl = true;
m_AsArcG74G75Cmd = true;
2007-09-26 04:09:22 +00:00
break;
case GC_SPECIFY_ABSOLUES_COORD:
m_Relative = false; // false = absolute Coord, true = relative
// Coord
2007-09-26 04:09:22 +00:00
break;
case GC_SPECIFY_RELATIVEES_COORD:
m_Relative = true; // false = absolute Coord, true = relative
// Coord
2007-09-26 04:09:22 +00:00
break;
case GC_TURN_ON_POLY_FILL:
m_PolygonFillMode = true;
m_Exposure = false;
2007-09-26 04:09:22 +00:00
break;
case GC_TURN_OFF_POLY_FILL:
if( m_Exposure && GetLastItemInList() ) // End of polygon
{
GERBER_DRAW_ITEM * gbritem = GetLastItemInList();
if( gbritem->m_Polygon.VertexCount() )
gbritem->m_Polygon.Append( gbritem->m_Polygon.CVertex( 0 ) );
StepAndRepeatItem( *gbritem );
}
m_Exposure = false;
m_PolygonFillMode = false;
2007-09-26 04:09:22 +00:00
m_PolygonFillModeState = 0;
m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // not sure it should be done
2007-09-26 04:09:22 +00:00
break;
case GC_MOVE: // Non existent
2007-09-26 04:09:22 +00:00
default:
{
wxString msg;
2011-03-16 10:47:15 +00:00
msg.Printf( wxT( "G%0.2d command not handled" ), G_command );
AddMessageToList( msg );
return false;
2007-09-26 04:09:22 +00:00
}
}
return true;
}
2007-09-26 04:09:22 +00:00
bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
{
2010-09-28 14:42:05 +00:00
wxSize size( 15, 15 );
2007-09-26 04:09:22 +00:00
2010-09-28 14:42:05 +00:00
APERTURE_T aperture = APT_CIRCLE;
GERBER_DRAW_ITEM* gbritem;
2008-11-08 06:44:07 +00:00
2010-09-28 14:42:05 +00:00
int dcode = 0;
D_CODE* tool = NULL;
wxString msg;
2007-09-26 04:09:22 +00:00
if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command
{
2010-09-28 14:42:05 +00:00
if( D_commande > (TOOLS_MAX_COUNT - 1) )
D_commande = TOOLS_MAX_COUNT - 1;
2008-11-10 07:13:37 +00:00
// remember which tool is selected, nothing is done with it in this
// call
2007-09-26 04:09:22 +00:00
m_Current_Tool = D_commande;
2008-11-14 07:46:43 +00:00
D_CODE* pt_Dcode = GetDCODE( D_commande );
2007-09-26 04:09:22 +00:00
if( pt_Dcode )
pt_Dcode->m_InUse = true;
else
m_Has_MissingDCode = true;
2008-11-10 07:13:37 +00:00
return true;
2007-09-26 04:09:22 +00:00
}
else // D_commande = 0..9: this is a pen command (usually D1, D2 or D3)
2007-09-26 04:09:22 +00:00
{
m_Last_Pen_Command = D_commande;
}
if( m_PolygonFillMode ) // Enter a polygon description:
{
switch( D_commande )
{
2008-11-10 07:13:37 +00:00
case 1: // code D01 Draw line, exposure ON
if( !m_Exposure ) // Start a new polygon outline:
2010-09-28 14:42:05 +00:00
{
m_Exposure = true;
2016-05-26 11:57:43 +00:00
gbritem = new GERBER_DRAW_ITEM( this );
AddItemToList( gbritem );
2010-09-28 14:42:05 +00:00
gbritem->m_Shape = GBR_POLYGON;
gbritem->m_Flashed = false;
gbritem->m_DCode = 0; // No DCode for a Polygon (Region in Gerber dialect)
if( gbritem->m_GerberImageFile )
{
gbritem->SetNetAttributes( gbritem->m_GerberImageFile->m_NetAttributeDict );
gbritem->m_AperFunction = gbritem->m_GerberImageFile->m_AperFunction;
}
2010-09-28 14:42:05 +00:00
}
2007-09-26 04:09:22 +00:00
switch( m_Iterpolation )
{
case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS:
// Before any arc command, a G74 or G75 command must be set.
// Otherwise the Gerber file is invalid
if( !m_AsArcG74G75Cmd )
{
2020-04-10 11:41:33 +00:00
AddMessageToList( _( "Invalid Gerber file: missing G74 or G75 arc command" ) );
// Disable further warning messages:
m_AsArcG74G75Cmd = true;
}
gbritem = GetLastItemInList();
fillArcPOLY( gbritem, m_PreviousPos,
m_CurrentPos, m_IJPos,
( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ? false : true,
m_360Arc_enbl, GetLayerParams().m_LayerNegative );
break;
default:
gbritem = GetLastItemInList();
2010-09-28 14:42:05 +00:00
gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage
if( gbritem->m_Polygon.OutlineCount() == 0 )
{
gbritem->m_Polygon.NewOutline();
gbritem->m_Polygon.Append( VECTOR2I( gbritem->m_Start ) );
}
2010-09-28 14:42:05 +00:00
gbritem->m_End = m_CurrentPos; // m_End is used as temporary storage
gbritem->m_Polygon.Append( VECTOR2I( gbritem->m_End ) );
break;
}
2007-09-26 04:09:22 +00:00
m_PreviousPos = m_CurrentPos;
m_PolygonFillModeState = 1;
break;
2008-11-10 07:13:37 +00:00
case 2: // code D2: exposure OFF (i.e. "move to")
if( m_Exposure && GetLastItemInList() ) // End of polygon
{
gbritem = GetLastItemInList();
gbritem->m_Polygon.Append( gbritem->m_Polygon.CVertex( 0 ) );
StepAndRepeatItem( *gbritem );
}
m_Exposure = false;
2007-09-26 04:09:22 +00:00
m_PreviousPos = m_CurrentPos;
m_PolygonFillModeState = 0;
break;
default:
return false;
2007-09-26 04:09:22 +00:00
}
}
else
{
2007-09-26 04:09:22 +00:00
switch( D_commande )
{
2008-11-10 07:13:37 +00:00
case 1: // code D01 Draw line, exposure ON
2008-11-14 07:46:43 +00:00
m_Exposure = true;
tool = GetDCODE( m_Current_Tool );
2008-11-14 07:46:43 +00:00
if( tool )
2007-09-26 04:09:22 +00:00
{
2008-11-14 07:46:43 +00:00
size = tool->m_Size;
dcode = tool->m_Num_Dcode;
aperture = tool->m_Shape;
2007-09-26 04:09:22 +00:00
}
switch( m_Iterpolation )
{
case GERB_INTERPOL_LINEAR_1X:
2016-05-26 11:57:43 +00:00
gbritem = new GERBER_DRAW_ITEM( this );
AddItemToList( gbritem );
2016-05-26 11:57:43 +00:00
fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
m_CurrentPos, size, GetLayerParams().m_LayerNegative );
StepAndRepeatItem( *gbritem );
2007-09-26 04:09:22 +00:00
break;
case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS:
2016-05-26 11:57:43 +00:00
gbritem = new GERBER_DRAW_ITEM( this );
AddItemToList( gbritem );
2016-05-26 11:57:43 +00:00
if( m_LastCoordIsIJPos )
{
fillArcGBRITEM( gbritem, dcode, m_PreviousPos,
m_CurrentPos, m_IJPos, size,
( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ?
false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative );
m_LastCoordIsIJPos = false;
}
else
{
fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
m_CurrentPos, size, GetLayerParams().m_LayerNegative );
}
StepAndRepeatItem( *gbritem );
2007-09-26 04:09:22 +00:00
break;
default:
msg.Printf( wxT( "RS274D: DCODE Command: interpol error (type %X)" ),
m_Iterpolation );
AddMessageToList( msg );
2007-09-26 04:09:22 +00:00
break;
}
m_PreviousPos = m_CurrentPos;
break;
2008-11-10 07:13:37 +00:00
case 2: // code D2: exposure OFF (i.e. "move to")
m_Exposure = false;
2007-09-26 04:09:22 +00:00
m_PreviousPos = m_CurrentPos;
break;
2008-11-10 07:13:37 +00:00
case 3: // code D3: flash aperture
tool = GetDCODE( m_Current_Tool );
2008-11-14 07:46:43 +00:00
if( tool )
2007-09-26 04:09:22 +00:00
{
2008-11-14 07:46:43 +00:00
size = tool->m_Size;
dcode = tool->m_Num_Dcode;
aperture = tool->m_Shape;
2007-09-26 04:09:22 +00:00
}
2016-05-26 11:57:43 +00:00
gbritem = new GERBER_DRAW_ITEM( this );
AddItemToList( gbritem );
2016-05-26 11:57:43 +00:00
fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
size, GetLayerParams().m_LayerNegative );
StepAndRepeatItem( *gbritem );
2007-09-26 04:09:22 +00:00
m_PreviousPos = m_CurrentPos;
break;
default:
return false;
2007-09-26 04:09:22 +00:00
}
}
2007-09-26 04:09:22 +00:00
return true;
}