@@ -22,10 +22,10 @@ This file is part of Universal Gcode Sender (UGS).
22
22
package com .willwinder .universalgcodesender .visualizer ;
23
23
24
24
import com .willwinder .universalgcodesender .gcode .GcodePreprocessorUtils ;
25
+ import com .willwinder .universalgcodesender .gcode .util .GcodeParserException ;
25
26
import com .willwinder .universalgcodesender .gcode .util .PlaneFormatter ;
26
27
import com .willwinder .universalgcodesender .model .Position ;
27
28
import com .willwinder .universalgcodesender .types .PointSegment ;
28
- import com .willwinder .universalgcodesender .utils .GUIHelpers ;
29
29
30
30
import java .io .BufferedReader ;
31
31
import java .io .DataInputStream ;
@@ -35,14 +35,11 @@ This file is part of Universal Gcode Sender (UGS).
35
35
import java .io .InputStreamReader ;
36
36
import java .util .ArrayList ;
37
37
import java .util .List ;
38
- import java .util .logging .Level ;
39
- import java .util .logging .Logger ;
40
38
41
39
/**
42
40
* @author wwinder
43
41
*/
44
42
public class VisualizerUtils {
45
- private static final Logger LOGGER = Logger .getLogger (VisualizerUtils .class .getSimpleName ());
46
43
47
44
/**
48
45
* Returns the maximum side dimension of a box containing two points.
@@ -54,24 +51,14 @@ public static double findMaxSide(Position min, Position max) {
54
51
return Math .max (x , Math .max (y , z ));
55
52
}
56
53
57
- /**
58
- * Returns the aspect ratio from two points.
59
- */
60
- public static double findAspectRatio (Position min , Position max ) {
61
- double x = Math .abs (min .x ) + Math .abs (max .x );
62
- double y = Math .abs (min .y ) + Math .abs (max .y );
63
- return x / y ;
64
- }
65
-
66
54
/**
67
55
* Returns the center point on a line.
68
56
*/
69
57
public static Position findCenter (Position min , Position max ) {
70
- Position center = new Position (
58
+ return new Position (
71
59
(min .x + max .x ) / 2.0 ,
72
60
(min .y + max .y ) / 2.0 ,
73
61
(min .z + max .z ) / 2.0 );
74
- return center ;
75
62
}
76
63
77
64
/**
@@ -132,7 +119,7 @@ public static double getRelativeMovementMultiplier(double objectMin, double obje
132
119
/**
133
120
* Helper to create a line segment with flags initialized.
134
121
*/
135
- private static LineSegment createLineSegment (Position a , Position b , PointSegment meta , double spindleSpeed ) {
122
+ private static LineSegment createLineSegment (Position a , Position b , PointSegment meta ) {
136
123
LineSegment ls = new LineSegment (a , b , meta .getLineNumber ());
137
124
ls .setIsArc (meta .isArc ());
138
125
ls .setIsFastTraverse (meta .isFastTraverse ());
@@ -145,8 +132,10 @@ private static LineSegment createLineSegment(Position a, Position b, PointSegmen
145
132
146
133
/**
147
134
* Turns a point segment into one or more LineSegment. Arcs and rotations around axes are expanded
135
+ *
136
+ * @throws GcodeParserException if the lines could not be expanded
148
137
*/
149
- public static void addLinesFromPointSegment (final Position start , final PointSegment endSegment , double arcSegmentLength , List <LineSegment > ret , double spindleSpeed ) {
138
+ public static void addLinesFromPointSegment (final Position start , final PointSegment endSegment , double arcSegmentLength , List <LineSegment > ret ) throws GcodeParserException {
150
139
// For a line segment list ALL arcs must be converted to lines.
151
140
double minArcLength = 0 ;
152
141
endSegment .convertToMetric ();
@@ -156,22 +145,21 @@ public static void addLinesFromPointSegment(final Position start, final PointSeg
156
145
if (start != null ) {
157
146
// Expand arc for graphics.
158
147
if (endSegment .isArc ()) {
159
- expandArc (start , endSegment , arcSegmentLength , ret , minArcLength , spindleSpeed );
148
+ expandArc (start , endSegment , arcSegmentLength , ret , minArcLength );
160
149
} else if (endSegment .isRotation ()) {
161
- expandRotationalLineSegment (start , endSegment , ret , spindleSpeed );
150
+ expandRotationalLineSegment (start , endSegment , ret );
162
151
} else {
163
152
// Line
164
- ret .add (createLineSegment (start , endSegment .point (), endSegment , spindleSpeed ));
153
+ ret .add (createLineSegment (start , endSegment .point (), endSegment ));
165
154
}
166
155
}
167
156
} catch (Exception e ) {
168
- String message = endSegment .getLineNumber () + ": " + e .getMessage ();
169
- GUIHelpers .displayErrorDialog (message , true );
170
- LOGGER .log (Level .SEVERE , message , e );
157
+ String message = "Line " + endSegment .getLineNumber () + ": " + e .getMessage ();
158
+ throw new GcodeParserException (message , e );
171
159
}
172
160
}
173
161
174
- private static void expandArc (Position start , PointSegment endSegment , double arcSegmentLength , List <LineSegment > ret , double minArcLength , double spindleSpeed ) {
162
+ private static void expandArc (Position start , PointSegment endSegment , double arcSegmentLength , List <LineSegment > ret , double minArcLength ) {
175
163
List <Position > points =
176
164
GcodePreprocessorUtils .generatePointsAlongArcBDring (
177
165
start , endSegment .point (), endSegment .center (), endSegment .isClockwise (),
@@ -180,13 +168,13 @@ private static void expandArc(Position start, PointSegment endSegment, double ar
180
168
if (!points .isEmpty ()) {
181
169
Position startPoint = start ;
182
170
for (Position nextPoint : points ) {
183
- ret .add (createLineSegment (startPoint , nextPoint , endSegment , spindleSpeed ));
171
+ ret .add (createLineSegment (startPoint , nextPoint , endSegment ));
184
172
startPoint = nextPoint ;
185
173
}
186
174
}
187
175
}
188
176
189
- public static void expandRotationalLineSegment (Position start , PointSegment endSegment , List <LineSegment > ret , double spindleSpeed ) {
177
+ public static void expandRotationalLineSegment (Position start , PointSegment endSegment , List <LineSegment > ret ) {
190
178
double maxDegreesPerStep = 5 ;
191
179
double deltaX = defaultZero (endSegment .point ().x ) - defaultZero (start .x );
192
180
double deltaY = defaultZero (endSegment .point ().y ) - defaultZero (start .y );
@@ -217,11 +205,11 @@ public static void expandRotationalLineSegment(Position start, PointSegment endS
217
205
if (deltaC != 0 ) {
218
206
end .setC (defaultZero (start .c ) + ((deltaC / steps ) * i ));
219
207
}
220
- ret .add (createLineSegment (startPoint , end , endSegment , spindleSpeed ));
208
+ ret .add (createLineSegment (startPoint , end , endSegment ));
221
209
startPoint = end ;
222
210
}
223
211
224
- ret .add (createLineSegment (startPoint , endSegment .point (), endSegment , spindleSpeed ));
212
+ ret .add (createLineSegment (startPoint , endSegment .point (), endSegment ));
225
213
}
226
214
227
215
/**
0 commit comments