88import javax .swing .JFrame ;
99import javax .swing .JPanel ;
1010
11+ import GCODECompiler .GCODEHandler ;
1112import antlr .Token ;
1213
1314
@@ -34,86 +35,173 @@ public void paintComponent(Graphics g) {
3435 //System.out.println(prop[i]);
3536 }
3637
37- if (prop [0 ].equals ("G00" )) {
38- firstx = Integer .parseInt (prop [1 ]);
39- firsty = yorigin - Integer .parseInt (prop [2 ]);
40- }
41-
42- if (prop [0 ].equals ("G01" )) {
43- g .drawLine (firstx , firsty , Integer .parseInt (prop [1 ]), yorigin - Integer .parseInt (prop [2 ]));
44- firstx = Integer .parseInt (prop [1 ]);
45- firsty = yorigin - Integer .parseInt (prop [2 ]);
46- }else if (prop [0 ].equals ("G02" )) {
47- //System.out.println("conta:" + conta++);
48- float x0 = Integer .parseInt (prop [3 ]);
49- float y0 = 500 - Integer .parseInt (prop [4 ]);
50- float x1 = firstx ;
51- float y1 = firsty ;
52- float x2 = Integer .parseInt (prop [1 ]);
53- float y2 = 500 - Integer .parseInt (prop [2 ]);
54- float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
55- float x = x0 -r ;
56- float y = y0 -r ;
57- float width = 2 *r ;
58- float height = 2 *r ;
59- float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
60- float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
61-
62- float endDist = (float )Math .sqrt ((x2 -x0 )*(x2 -x0 ) + (y2 -y0 )*(y2 -y0 ));
63- float startDist = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
64-
65- if (endDist != startDist ) {
66- //System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
67- String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1 ) + " con il punto " + x2 + ";" + (500 - y2 ) +"." ;
68- ParserLauncher .getParser ().getHandler ().myErrorHandler (21 , assad );
38+ if (!GCODEHandler .mode ) { //coordinate assolute
39+ if (prop [0 ].equals ("G00" )) {
40+ firstx = Integer .parseInt (prop [1 ]);
41+ firsty = yorigin - Integer .parseInt (prop [2 ]);
6942 }
7043
71-
72- //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
73- if (startAngle - endAngle < 0 )
74- g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
75- else
76- g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(360 - (startAngle - endAngle )));
77-
78-
79- //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
80- firstx = Integer .parseInt (prop [1 ]);
81- firsty = yorigin - Integer .parseInt (prop [2 ]);
82- } else if (prop [0 ].equals ("G03" )) {
83- //System.out.println("ciao");
84- float x0 = Integer .parseInt (prop [3 ]);
85- float y0 = 500 - Integer .parseInt (prop [4 ]);
86- float x1 = firstx ;
87- float y1 = firsty ;
88- float x2 = Integer .parseInt (prop [1 ]);
89- float y2 = 500 - Integer .parseInt (prop [2 ]);
90- float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
91- float x = x0 -r ;
92- float y = y0 -r ;
93- float width = 2 *r ;
94- float height = 2 *r ;
95- float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
96- float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
97-
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 );
44+ if (prop [0 ].equals ("G01" )) {
45+ g .drawLine (firstx , firsty , Integer .parseInt (prop [1 ]), yorigin - Integer .parseInt (prop [2 ]));
46+ firstx = Integer .parseInt (prop [1 ]);
47+ firsty = yorigin - Integer .parseInt (prop [2 ]);
48+ }else if (prop [0 ].equals ("G02" )) {
49+ //System.out.println("conta:" + conta++);
50+ float x0 = Integer .parseInt (prop [3 ]);
51+ float y0 = 500 - Integer .parseInt (prop [4 ]);
52+ float x1 = firstx ;
53+ float y1 = firsty ;
54+ float x2 = Integer .parseInt (prop [1 ]);
55+ float y2 = 500 - Integer .parseInt (prop [2 ]);
56+ float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
57+ float x = x0 -r ;
58+ float y = y0 -r ;
59+ float width = 2 *r ;
60+ float height = 2 *r ;
61+ float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
62+ float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
63+
64+ float endDist = (float )Math .sqrt ((x2 -x0 )*(x2 -x0 ) + (y2 -y0 )*(y2 -y0 ));
65+ float startDist = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
66+
67+ if (endDist != startDist ) {
68+ //System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
69+ String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1 ) + " con il punto " + x2 + ";" + (500 - y2 ) +"." ;
70+ ParserLauncher .getParser ().getHandler ().myErrorHandler (21 , assad );
71+ }
72+
73+
74+ //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
75+ if (startAngle - endAngle < 0 )
76+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
77+ else
78+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(360 - (startAngle - endAngle )));
79+
80+
81+ //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
82+ firstx = Integer .parseInt (prop [1 ]);
83+ firsty = yorigin - Integer .parseInt (prop [2 ]);
84+ } else if (prop [0 ].equals ("G03" )) {
85+ //System.out.println("ciao");
86+ float x0 = Integer .parseInt (prop [3 ]);
87+ float y0 = 500 - Integer .parseInt (prop [4 ]);
88+ float x1 = firstx ;
89+ float y1 = firsty ;
90+ float x2 = Integer .parseInt (prop [1 ]);
91+ float y2 = 500 - Integer .parseInt (prop [2 ]);
92+ float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
93+ float x = x0 -r ;
94+ float y = y0 -r ;
95+ float width = 2 *r ;
96+ float height = 2 *r ;
97+ float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
98+ float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
99+
100+ float endDist = (float )Math .sqrt ((x2 -x0 )*(x2 -x0 ) + (y2 -y0 )*(y2 -y0 ));
101+ float startDist = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
102+
103+ if (endDist != startDist ) {
104+ //System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
105+ String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1 ) + " con il punto " + x2 + ";" + (500 - y2 ) +"." ;
106+ ParserLauncher .getParser ().getHandler ().myErrorHandler (21 , assad );
107+ }
108+
109+ //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
110+ if (startAngle - endAngle > 0 )
111+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
112+ else
113+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(Math .abs (startAngle ) - endAngle ));
114+
115+
116+ //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
117+ firstx = Integer .parseInt (prop [1 ]);
118+ firsty = yorigin - Integer .parseInt (prop [2 ]);
119+ }
120+ }else { //coordinate relative
121+ if (prop [0 ].equals ("G00" )) {
122+ firstx = Integer .parseInt (prop [1 ]);
123+ firsty = yorigin - Integer .parseInt (prop [2 ]);
124+ //System.out.println("x: " + firstx + " y: " + firsty);
105125 }
106126
107- //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
108- if (startAngle - endAngle > 0 )
109- g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
110- else
111- g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(Math .abs (startAngle ) - endAngle ));
112-
113-
114- //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
115- firstx = Integer .parseInt (prop [1 ]);
116- firsty = yorigin - Integer .parseInt (prop [2 ]);
127+ if (prop [0 ].equals ("G01" )) {
128+ g .drawLine (firstx , firsty , firstx + Integer .parseInt (prop [1 ]), firsty - Integer .parseInt (prop [2 ]));
129+ firstx = firstx + Integer .parseInt (prop [1 ]);
130+ firsty = firsty - (Integer .parseInt (prop [2 ]));
131+ //System.out.println("x: " + firstx + " y: " + firsty);
132+ }else if (prop [0 ].equals ("G02" )) {
133+ //System.out.println("conta:" + conta++);
134+ float x0 = firstx + Integer .parseInt (prop [3 ]);
135+ float y0 = firsty - (Integer .parseInt (prop [4 ]));
136+ float x1 = firstx ;
137+ float y1 = firsty ;
138+ float x2 = firstx + Integer .parseInt (prop [1 ]);
139+ float y2 = firsty - (Integer .parseInt (prop [2 ]));
140+ float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
141+ float x = x0 -r ;
142+ float y = y0 -r ;
143+ float width = 2 *r ;
144+ float height = 2 *r ;
145+ float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
146+ float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
147+
148+ float endDist = (float )Math .sqrt ((x2 -x0 )*(x2 -x0 ) + (y2 -y0 )*(y2 -y0 ));
149+ float startDist = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
150+
151+ if (endDist != startDist ) {
152+ //System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
153+ String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1 ) + " con il punto " + x2 + ";" + (500 - y2 ) +"." ;
154+ ParserLauncher .getParser ().getHandler ().myErrorHandler (21 , assad );
155+ }
156+
157+
158+ //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
159+ if (startAngle - endAngle < 0 )
160+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
161+ else
162+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(360 - (startAngle - endAngle )));
163+
164+
165+ //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
166+ firstx = firstx + Integer .parseInt (prop [1 ]);
167+ firsty = firsty - (Integer .parseInt (prop [2 ]));
168+ //System.out.println("x: " + firstx + " y: " + firsty);
169+ } else if (prop [0 ].equals ("G03" )) {
170+ //System.out.println("ciao");
171+ float x0 = firstx + Integer .parseInt (prop [3 ]);
172+ float y0 = firsty - Integer .parseInt (prop [4 ]);
173+ float x1 = firstx ;
174+ float y1 = firsty ;
175+ float x2 = firstx + Integer .parseInt (prop [1 ]);
176+ float y2 = firsty - Integer .parseInt (prop [2 ]);
177+ float r = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
178+ float x = x0 -r ;
179+ float y = y0 -r ;
180+ float width = 2 *r ;
181+ float height = 2 *r ;
182+ float startAngle = (float ) (180 /Math .PI *Math .atan2 (y1 -y0 , x1 -x0 ));
183+ float endAngle = (float ) (180 /Math .PI *Math .atan2 (y2 -y0 , x2 -x0 ));
184+
185+ float endDist = (float )Math .sqrt ((x2 -x0 )*(x2 -x0 ) + (y2 -y0 )*(y2 -y0 ));
186+ float startDist = (float )Math .sqrt ((x1 -x0 )*(x1 -x0 ) + (y1 -y0 )*(y1 -y0 ));
187+
188+ if (endDist != startDist ) {
189+ //System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
190+ String assad ="Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1 ) + " con il punto " + x2 + ";" + (500 - y2 ) +"." ;
191+ ParserLauncher .getParser ().getHandler ().myErrorHandler (21 , assad );
192+ }
193+
194+ //System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
195+ if (startAngle - endAngle > 0 )
196+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )(startAngle - endAngle ));
197+ else
198+ g .drawArc ((int )x , (int )y , (int )width , (int )height , (int )(360.0 - startAngle ), (int )-(Math .abs (startAngle ) - endAngle ));
199+
200+
201+ //g.drawArc(Integer.parseInt(prop[1]), Integer.parseInt(prop[2]),Integer.parseInt(prop[1]) - firstx ,Integer.parseInt(prop[2]) - firsty, 270, 90);
202+ firstx = firstx + Integer .parseInt (prop [1 ]);
203+ firsty = firsty - Integer .parseInt (prop [2 ]);
204+ }
117205 }
118206 }
119207 }
0 commit comments