Author Topic: Gerber parsing bug - all CamBam versions  (Read 1915 times)

Offline CitizenOfDreams

  • Ewok
  • *
  • Posts: 25
    • View Profile
Gerber parsing bug - all CamBam versions
« on: June 24, 2020, 19:50:02 pm »
All versions of CamBam seem to have a serious problem (incomplete implementation?) with Gerber import. When a Gerber macro contains an arithmetic statement such as:

Code: [Select]
$1=0.5
CamBam throws this error:

Code: [Select]
Input string was not in the correct format.
Attached is a test file I wrote to illustrate the case. The file opens without errors or warnings in the official Ucamco Gerber viewer, yet CamBam gives you an error until you delete the offending line #8.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5115
  • Made in England
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #1 on: June 24, 2020, 20:49:41 pm »
I don't think it's a bug.

The variable should be declared first before it is used, thus making that section read as;

Code: [Select]

G04 This is RECT macro *
%AMRECT*
21,1,$1/2,$2,$3,$4,0*%
$1 = 0.5*


CamBam then opens it okay.
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7048
    • View Profile
    • Cambam V1.0 French Doc
Re: Gerber parsing bug - all CamBam versions
« Reply #2 on: June 24, 2020, 20:58:58 pm »
Hello

Quote
The variable should be declared first before it is used, thus making that section read as;

Yes, the open bug go away, but the message in the log windows said that Gerber_Command $1=0.5* and Code G90 are not supported by the plugin.
Quote
Unhandled gerber command Gerber_Command $1=0.5*
Unhandled code G90

Same result with both Andy 1.5 plugin and Jeff plugin (1.5.1)
http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/Excellon.html

Andy said it's a simple implementation of the Excellon handler, so, not a bug but a limitation ;)

http://www.cambam.info/ref/plugin.excellonio

++
David
« Last Edit: June 24, 2020, 21:03:14 pm by dh42 »

Offline CitizenOfDreams

  • Ewok
  • *
  • Posts: 25
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #3 on: June 24, 2020, 21:05:10 pm »
1. $1, $2, $3, $4 are parameters passed to the macro. They do not require any additional declaration.

2. In your code, pay attention to the % sign (end of macro). You excluded "$1=0.5" from the macro altogether. If you put the statement back inside the macro, the error is back:

Code: [Select]
G04 This is RECT macro *
%AMRECT*
21,1,$1/2,$2,$3,$4,0*
$1 = 0.5*%

3. This code would work incorrectly anyway, because you draw the rectangle using the current $1 parameter (which is 1.0 in this case) and only then assign $1=0.5. The aperture would be two times wider than expected.

Offline CitizenOfDreams

  • Ewok
  • *
  • Posts: 25
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #4 on: June 24, 2020, 21:12:49 pm »
Andy said it's a simple implementation of the Excellon handler, so, not a bug but a limitation ;)

Too bad. It's a shame, because the rest of the arithmetics seems to work fine. You can use pretty complex arithmetic expressions inside the 21 command, such as

Code: [Select]
21,1,$1-$3,$2-$3,0-$1/2-$4,0-$2/2-$3/2,0*
Anyway, I made a workaround by patching the FreePCB executable. Now it generates "CamBam-compatible" Gerbers.  ;)

Offline CitizenOfDreams

  • Ewok
  • *
  • Posts: 25
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #5 on: June 24, 2020, 21:16:21 pm »
P. S. The Gerber handler also has a problem with inches/millimeters, but that's more of an annoyance than a problem.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5115
  • Made in England
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #6 on: June 24, 2020, 21:47:11 pm »
That's fine, I knew nothing about gerber an hour ago and it appears I still don't  :D
Filmed in Supermarionation

Offline CitizenOfDreams

  • Ewok
  • *
  • Posts: 25
    • View Profile
Re: Gerber parsing bug - all CamBam versions
« Reply #7 on: June 25, 2020, 10:30:38 am »
That's fine, I knew nothing about gerber an hour ago and it appears I still don't  :D

Same here, I had no idea what Gerber was made of until last night. A couple hours of reading and thinking got me to the point where I was able to find a workaround for my problem. That's all I ever wanted to know about the Gerber format.  :D