forked from JulesStringer/GerberParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GerberMacro.cpp
85 lines (84 loc) · 1.86 KB
/
GerberMacro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "GerberMacro.h"
#include "GerberParser.h"
#include "InputStream.h"
#include "Variable.h"
#include "GerberPrimitive.h"
#include "Expression.h"
CGerberMacro::CGerberMacro()
{
}
CGerberMacro::~CGerberMacro()
{
}
void CGerberMacro::Parse(CGerberParser* pParser)
{
CInputStream* pStream = pParser->Stream();
while (!pStream->AtEndExtended())
{
char ch = pStream->PeekChar();
if (ch == '$')
{
pStream->GetChar();
unsigned int nVar = pStream->GetInt();
// Variable definition
CVariable* pVariable = new CVariable(nVar);
pVariable->ParseExpression(pStream, this);
m_mapVariables[nVar] = pVariable;
}
else if ( isdigit(ch))
{
unsigned int nPrimitive = pStream->GetInt();
if (nPrimitive == 0)
{
pStream->SkipToEndBlock();
}
else
{
CGerberPrimitive* pPrimitive = CGerberPrimitive::Create(nPrimitive);
// Get modifiers
while (pStream->PeekChar() != '*')
{
ch = pStream->GetChar();
if (ch == ',')
{
ch = pStream->GetChar();
}
std::string strModifier;
while (ch != ',' && ch != '*' && !pStream->AtEOF())
{
strModifier += ch;
ch = pStream->PeekChar();
if (ch != '*')
{
ch = pStream->GetChar();
}
}
CExpression* pExpression = new CExpression();
pExpression->Parse(strModifier.c_str(), this);
pPrimitive->AddModifier(pExpression);
}
m_vecPrimitives.push_back(pPrimitive);
}
}
else
{
ch = pStream->GetChar();
}
}
pStream->SkipToEndExtended();
}
CVariable* CGerberMacro::GetVariable(int nVar)
{
std::map<int, CVariable*>::iterator it = m_mapVariables.find(nVar);
if (it == m_mapVariables.end())
{
CVariable* pVar = new CVariable(nVar);
m_mapVariables[nVar] = pVar;
return pVar;
}
else
{
return it->second;
}
return NULL;
}