Skip to content

Commit 3f414bc

Browse files
committed
Error handler and interface fix
1 parent 0bcffd7 commit 3f414bc

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

resources/input.file

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ H87 T0101 M06
22
G94 G97 C400 S260 M04 M08
33
G00 X10 Y10
44
G01 X20 Y20
5-
G01 X30 Y50
5+
H01 X30 Y50
66
G02 X45 Y10 I34 J67
77
G01 X20 Y20
88
G01 X20 Y20

resources/input5G03.file

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ G03 X200 Y250 I200 J200
88
G01 X50 Y250
99
G03 X0 Y200 I50 J200
1010
G01 X0 Y50
11-
G03 X50 Y0 I50 J50
11+
G03 X50 Y0 I50 J100
1212
G00 X100 Y100
1313
M05 M09 M30

src/GCODECompiler/GCODEHandler.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class GCODEHandler {
2828
public static final int CIRCLE_NOT_CONNECTING = 21;
2929
public static final int LAST_WARNING = 30;
3030

31-
List<String> errorList;
31+
static List<String> errorList;
3232
TokenStream lexerStream;
3333

3434
public GCODEHandler (TokenStream ls) {
@@ -37,7 +37,7 @@ public GCODEHandler (TokenStream ls) {
3737
lexerStream = ls;
3838
}
3939

40-
public List<String> getErrorList() {
40+
public static List<String> getErrorList() {
4141
return errorList;
4242
}
4343

@@ -48,18 +48,24 @@ void handleError(String[] tokenNames, RecognitionException e, String h, String m
4848
if (e.token.getType() >=0)
4949
type = tokenNames[e.token.getType()];
5050
if (e.token.getType() == GCODELexer.SCAN_ERROR)
51-
st = "Lexical Error " + TOKEN_ERROR + " at ";
51+
st = "Errore lessicale " + TOKEN_ERROR + " a ";
5252
else
53-
st = "Syntax Error " + ERR_ON_SYNTAX + " at ";
53+
st = "Errore sintattico " + ERR_ON_SYNTAX + " a ";
5454
st += "[" + e.token.getLine() + ", " + (e.token.getCharPositionInLine()+1) + "]: " +
55-
"Found ";
55+
"rilevato ";
5656
st += type;
5757

58+
//System.out.println(m);
59+
//System.out.println(m.substring(m.indexOf("expecting") + 10 , m.length()));
60+
61+
m = " è stato rilevato '" + e.token.getText() + "' invece del comando " + m.substring(m.indexOf("expecting") + 10 , m.length()) + ".";
5862

5963
if (e instanceof MissingTokenException)
6064
st = st + m;
6165
else /*if(e.token.getType() == MISSING_CHAR)*/
6266
st += " ('" + e.token.getText() + "')" + m;
67+
68+
//Interfaccia.setData(st + "\n");
6369
errorList.add(st);
6470

6571
}
@@ -97,9 +103,19 @@ else if (code < LAST_SEMANTIC_ERROR)
97103

98104
if (code == TOKEN_ERROR)
99105
st += "Unrecognized token '" + tk.getText() + "'";
100-
101-
errorList.add(st);
102-
System.out.println(st);
106+
107+
108+
109+
if(!errorList.contains(st)) {
110+
//System.out.println("questo è il comp che cicla: " + s + " questo è quello da aggiungere: " + st);
111+
Interfaccia.setData(st + "\n\n");
112+
errorList.add(st);
113+
}
114+
115+
116+
117+
//System.out.println(st);
118+
103119
}
104120

105121
//utilizzato per creare movimenti e tagli G00 G01
@@ -179,9 +195,10 @@ public void printExit(List<String> e) {
179195
data = "";
180196
System.out.print(config+" ");
181197
System.out.println(recognizeExit(config));
182-
data = config+ " " + recognizeExit(config) + "\n";
198+
data = config + " " + recognizeExit(config) + "\n";
183199
Interfaccia.setData(data);
184200
}
201+
Interfaccia.setData("\n");
185202
System.out.println();
186203
}
187204

src/myPackage/Graphic.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public void paintComponent(Graphics g) {
9595
float startAngle = (float) (180/Math.PI*Math.atan2(y1-y0, x1-x0));
9696
float endAngle = (float) (180/Math.PI*Math.atan2(y2-y0, x2-x0));
9797

98+
float endDist = (float)Math.sqrt((x2-x0)*(x2-x0) + (y2-y0)*(y2-y0));
99+
float startDist = (float)Math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
100+
101+
if(endDist != startDist) {
102+
//System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
103+
String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".";
104+
ParserLauncher.getParser().getHandler().myErrorHandler(21, assad);
105+
}
106+
98107
//System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
99108
if(startAngle - endAngle > 0)
100109
g.drawArc((int)x, (int)y, (int)width, (int)height, (int)(360.0 - startAngle), (int)(startAngle - endAngle));

src/myPackage/Interfaccia.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public Interfaccia() throws IOException{
162162

163163
mainpanel.setLayout(new GridBagLayout());
164164
/*GridBagConstraints*/ gbc = new GridBagConstraints();
165+
gbc.insets = new Insets(10, 10, 10, 10);
165166

166167
// Row 0 - Filename
167168
// Col 0

src/myPackage/ParserLauncher.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.antlr.runtime.RecognitionException;
1111

12+
import GCODECompiler.GCODEHandler;
1213
import GCODECompiler.GCODEParser;
1314

1415
public class ParserLauncher {
@@ -38,14 +39,29 @@ public static void avvio(Interfaccia a) throws FileNotFoundException, IOExceptio
3839
System.out.println ("Errori rilevati");
3940
for (String msg : parser.getErrorList())
4041
System.out.println (++i + " - " + msg);
42+
43+
/*int j = 0;
44+
for(String d:GCODEHandler.getErrorList()) {
45+
System.out.println(++j + d);
46+
//Interfaccia.setData(d + "\n");
47+
}*/
4148
//questo dovrebbe andare alla fine del disegno visto che il programma genera i warning durante la pittura
4249
//perchè qui stampa solo gli errori al momento della fine del parsing
43-
parser.getErrorList().forEach(error -> {
50+
//parser.getErrorList().forEach(error -> {
51+
/*GCODEHandler.getErrorList().forEach(error -> {
4452
int j=0;
53+
System.out.println (++j + " strano " + error);
4554
Interfaccia.setData("\n"+ ++j + " - "+error.toString());
4655
});
4756
48-
}
57+
}*/
58+
59+
int j = 0;
60+
Interfaccia.setData("Lista di errori e warning rilevati:\n");
61+
for(String s:GCODEHandler.getErrorList()) {
62+
Interfaccia.setData(s + "\n\n");
63+
}
64+
}
4965
}
5066

5167
public static void main (String[] args) throws FileNotFoundException, IOException, RecognitionException {

0 commit comments

Comments
 (0)