Browse Source
Gerbview: Added support for gerber command SR (Step and Repeat) and multiple MOIN and MOMM in file
pull/1/head
Gerbview: Added support for gerber command SR (Step and Repeat) and multiple MOIN and MOMM in file
pull/1/head
19 changed files with 484 additions and 253 deletions
-
7CHANGELOG.txt
-
1common/common.cpp
-
2eeschema/eeschema.cpp
-
1gerbview/CMakeLists.txt
-
6gerbview/block.cpp
-
42gerbview/class_GERBER.cpp
-
27gerbview/class_GERBER.h
-
22gerbview/class_aperture_macro.cpp
-
5gerbview/class_aperture_macro.h
-
17gerbview/class_gerber_draw_item.cpp
-
11gerbview/class_gerber_draw_item.h
-
68gerbview/gerber_test_files/test-layer-mixed_units_mode.gbr
-
17gerbview/gerber_test_files/test-layer-step-and_repeat-cross.gbr
-
18gerbview/gerber_test_files/test-layer-step-and_repeat-polygon.gbr
-
8gerbview/readgerb.cpp
-
203gerbview/rs274_read_XY_and_IJ_coordinates.cpp
-
235gerbview/rs274d.cpp
-
46gerbview/rs274x.cpp
-
1include/common.h
@ -0,0 +1,68 @@ |
|||
G04 Test handling of unit changes within a RS274X file * |
|||
G04 Handcoded by Julian Lamb * |
|||
%MOIN*% |
|||
%FSLAX23Y23*% |
|||
G04 Aperture 10 should be in Inches * |
|||
%ADD10C,0.050*% |
|||
%MOMM*% |
|||
G04 Aperture 11 should be in MMs * |
|||
%ADD11C,1.250*% |
|||
G04 Aperture 12 should be in MMs * |
|||
%AMTHERMAL* |
|||
7,0,0,25.4,12.7,2.54,0*% |
|||
%MOIN*% |
|||
G04 Aperture 13 is in inches * |
|||
%AMTHERMALTWO* |
|||
7,0,0,1,0.5,0.1,0*% |
|||
%MOMM*% |
|||
%ADD12THERMAL*% |
|||
%MOIN*% |
|||
%ADD13THERMALTWO*% |
|||
|
|||
%MOIN*% |
|||
G04 Box 1, using aperture 10* |
|||
X0Y0D02* |
|||
G54D10* |
|||
X0Y0D01* |
|||
X1000D01* |
|||
Y1000D01* |
|||
X0D01* |
|||
Y0D01* |
|||
|
|||
G04 Box 2, using aperture 11* |
|||
X2000Y0D02* |
|||
G54D11* |
|||
X2000Y0D01* |
|||
X3000D01* |
|||
Y1000D01* |
|||
X2000D01* |
|||
Y0D01* |
|||
|
|||
%MOMM*% |
|||
G04 Box 3, using aperture 10* |
|||
X100000Y0D02* |
|||
G54D10* |
|||
X100000Y0D01* |
|||
X125000D01* |
|||
Y25000D01* |
|||
X100000D01* |
|||
Y0D01* |
|||
|
|||
G04 Draw Thermal in box 1* |
|||
G54D12* |
|||
Y12000X12700D03* |
|||
|
|||
G04 Draw Thermal in box 2* |
|||
G04 ..switch to inches for coordinates* |
|||
G70* |
|||
Y500X2500D02* |
|||
G54D12* |
|||
Y500X2500D03* |
|||
|
|||
G04 ..switch to mms for coordinates* |
|||
G71* |
|||
G04 Draw Thermal in box 3* |
|||
G54D13* |
|||
Y12000X112000D03* |
|||
|
|||
M02* |
|||
@ -0,0 +1,17 @@ |
|||
G04 Test step and repeat 1* |
|||
G04 Repeat a crosshair 3 times in the x direction and 2 times in the Y * |
|||
G04 Handcoded by Julian Lamb * |
|||
%MOIN*% |
|||
%FSLAX23Y23*% |
|||
%SRX3Y2I5.0J2*% |
|||
%ADD10C,0.050*% |
|||
|
|||
G04 Draw crosshairs * |
|||
X-1000Y0D02* |
|||
G54D10* |
|||
X1000Y0D01* |
|||
X0Y-1000D02* |
|||
G54D10* |
|||
X0Y1000D01* |
|||
|
|||
M02* |
|||
@ -0,0 +1,18 @@ |
|||
G04 Test step and repeat 1* |
|||
G04 Repeat a crosshair 3 times in the x direction and 2 times in the Y * |
|||
G04 Handcoded by Julian Lamb * |
|||
%MOIN*% |
|||
%FSLAX23Y23*% |
|||
%SRX3Y2I1J1*% |
|||
%ADD10C,0.050*% |
|||
|
|||
G04 Draw a simple square* |
|||
G36* |
|||
G01X00400Y0D02* |
|||
X00600Y0D01* |
|||
X00600Y00200D01* |
|||
X00400Y00200D01* |
|||
X00400Y0D01* |
|||
G37* |
|||
|
|||
M02* |
|||
@ -0,0 +1,203 @@ |
|||
/**********************************************/ |
|||
/**** rs274_read_XY_and_IJ_coordinates.cpp ****/ |
|||
/**********************************************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "common.h"
|
|||
|
|||
#include "gerbview.h"
|
|||
#include "macros.h"
|
|||
#include "class_GERBER.h"
|
|||
|
|||
|
|||
/* These routines read the text string point from Text.
|
|||
* After use, advanced Text the beginning of the sequence unread |
|||
*/ |
|||
wxPoint GERBER::ReadXYCoord( char*& Text ) |
|||
{ |
|||
wxPoint pos; |
|||
int type_coord = 0, current_coord, nbdigits; |
|||
bool is_float = false; |
|||
char* text; |
|||
char line[256]; |
|||
|
|||
|
|||
if( m_Relative ) |
|||
pos.x = pos.y = 0; |
|||
else |
|||
pos = m_CurrentPos; |
|||
|
|||
if( Text == NULL ) |
|||
return pos; |
|||
|
|||
text = line; |
|||
while( *Text ) |
|||
{ |
|||
if( (*Text == 'X') || (*Text == 'Y') ) |
|||
{ |
|||
type_coord = *Text; |
|||
Text++; |
|||
text = line; |
|||
nbdigits = 0; |
|||
while( IsNumber( *Text ) ) |
|||
{ |
|||
if( *Text == '.' ) |
|||
is_float = true; |
|||
|
|||
// count digits only (sign and decimal point are not counted)
|
|||
if( (*Text >= '0') && (*Text <='9') ) |
|||
nbdigits++; |
|||
*(text++) = *(Text++); |
|||
} |
|||
|
|||
*text = 0; |
|||
if( is_float ) |
|||
{ |
|||
if( m_GerbMetric ) |
|||
current_coord = wxRound( atof( line ) / 0.00254 ); |
|||
else |
|||
current_coord = wxRound( atof( line ) * PCB_INTERNAL_UNIT ); |
|||
} |
|||
else |
|||
{ |
|||
int fmt_scale = (type_coord == 'X') ? m_FmtScale.x : m_FmtScale.y; |
|||
if( m_NoTrailingZeros ) |
|||
{ |
|||
int min_digit = |
|||
(type_coord == 'X') ? m_FmtLen.x : m_FmtLen.y; |
|||
while( nbdigits < min_digit ) |
|||
{ |
|||
*(text++) = '0'; |
|||
nbdigits++; |
|||
} |
|||
|
|||
*text = 0; |
|||
} |
|||
current_coord = atoi( line ); |
|||
double real_scale = 1.0; |
|||
double scale_list[10] = |
|||
{ |
|||
10000.0, 1000.0, 100.0, 10.0, |
|||
1, |
|||
0.1, 0.01, 0.001, 0.0001,0.00001 |
|||
}; |
|||
real_scale = scale_list[fmt_scale]; |
|||
|
|||
if( m_GerbMetric ) |
|||
real_scale = real_scale / 25.4; |
|||
|
|||
current_coord = wxRound( current_coord * real_scale ); |
|||
} |
|||
|
|||
if( type_coord == 'X' ) |
|||
pos.x = current_coord; |
|||
else if( type_coord == 'Y' ) |
|||
pos.y = current_coord; |
|||
|
|||
continue; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
|
|||
if( m_Relative ) |
|||
{ |
|||
pos.x += m_CurrentPos.x; |
|||
pos.y += m_CurrentPos.y; |
|||
} |
|||
|
|||
m_CurrentPos = pos; |
|||
return pos; |
|||
} |
|||
|
|||
|
|||
/* Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm)
|
|||
* These coordinates are relative, so if coordinate is absent, it's value |
|||
* defaults to 0 |
|||
*/ |
|||
wxPoint GERBER::ReadIJCoord( char*& Text ) |
|||
{ |
|||
wxPoint pos( 0, 0 ); |
|||
|
|||
int type_coord = 0, current_coord, nbdigits; |
|||
bool is_float = false; |
|||
char* text; |
|||
char line[256]; |
|||
|
|||
if( Text == NULL ) |
|||
return pos; |
|||
|
|||
text = line; |
|||
while( *Text ) |
|||
{ |
|||
if( (*Text == 'I') || (*Text == 'J') ) |
|||
{ |
|||
type_coord = *Text; |
|||
Text++; |
|||
text = line; |
|||
nbdigits = 0; |
|||
while( IsNumber( *Text ) ) |
|||
{ |
|||
if( *Text == '.' ) |
|||
is_float = true; |
|||
|
|||
// count digits only (sign and decimal point are not counted)
|
|||
if( (*Text >= '0') && (*Text <='9') ) |
|||
nbdigits++; |
|||
*(text++) = *(Text++); |
|||
} |
|||
|
|||
*text = 0; |
|||
if( is_float ) |
|||
{ |
|||
if( m_GerbMetric ) |
|||
current_coord = wxRound( atof( line ) / 0.00254 ); |
|||
else |
|||
current_coord = wxRound( atof( line ) * PCB_INTERNAL_UNIT ); |
|||
} |
|||
else |
|||
{ |
|||
int fmt_scale = |
|||
(type_coord == 'I') ? m_FmtScale.x : m_FmtScale.y; |
|||
if( m_NoTrailingZeros ) |
|||
{ |
|||
int min_digit = |
|||
(type_coord == 'I') ? m_FmtLen.x : m_FmtLen.y; |
|||
while( nbdigits < min_digit ) |
|||
{ |
|||
*(text++) = '0'; |
|||
nbdigits++; |
|||
} |
|||
|
|||
*text = 0; |
|||
} |
|||
current_coord = atoi( line ); |
|||
double real_scale = 1.0; |
|||
if( fmt_scale < 0 || fmt_scale > 9 ) |
|||
fmt_scale = 4; // select scale 1.0
|
|||
|
|||
double scale_list[10] = |
|||
{ |
|||
10000.0, 1000.0, 100.0, 10.0, |
|||
1, |
|||
0.1, 0.01, 0.001, 0.0001,0.00001 |
|||
}; |
|||
real_scale = scale_list[fmt_scale]; |
|||
|
|||
if( m_GerbMetric ) |
|||
real_scale = real_scale / 25.4; |
|||
current_coord = wxRound( current_coord * real_scale ); |
|||
} |
|||
if( type_coord == 'I' ) |
|||
pos.x = current_coord; |
|||
else if( type_coord == 'J' ) |
|||
pos.y = current_coord; |
|||
continue; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
|
|||
m_IJPos = pos; |
|||
return pos; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue