Permalink
Browse files

Added upper limit for F

  • Loading branch information...
1 parent 1193315 commit 8117be3202807df04ecae74a7633ba09db53607e @mnemonia committed Mar 12, 2012
@@ -6,6 +6,7 @@
public void setImportFile(File file);
public void setExportFile(File file);
public void go();
+ public void setFUpperLimit(int value);
public void setFFactor(int value);
public void setFScaling(int value);
public void setSFactor(int value);
@@ -9,6 +9,7 @@
public final class GCodeTransformerImpl implements GCodeTransformer {
private File in,out;
private int fScaling = 1;
+ private int fUpperLimit = 1000;
private int fFactor = 60;
private int sScaling = 1;
private int sFactor = 1;
@@ -21,8 +22,8 @@ public GCodeTransformerImpl(){
@Override
public void go() {
new TransformerImpl(
- new ScaleValuesTransformation("F",fFactor,fScaling),
- new ScaleValuesTransformation("S",sFactor,sScaling)
+ new ScaleValuesTransformation("F",fFactor,fScaling,fUpperLimit),
+ new ScaleValuesTransformation("S",sFactor,sScaling,Integer.MAX_VALUE)
).transform(in, out);
}
@@ -56,4 +57,9 @@ public void setSFactor(int value) {
sFactor = value;
}
+ @Override
+ public void setFUpperLimit(int value) {
+ fUpperLimit = value;
+ }
+
}
@@ -10,11 +10,13 @@
private final String marker;
private final int scaling;
private final int factor;
+ private final int upperLimit;
- public ScaleValuesTransformation(String marker, int factor, int scaling) {
+ public ScaleValuesTransformation(String marker, int factor, int scaling, int upperLimit) {
this.factor = factor;
this.scaling = scaling;
this.marker = marker;
+ this.upperLimit = upperLimit;
}
@Override
@@ -36,14 +38,28 @@ private Line transform(Line line) {
while(t.hasMoreTokens()){
String v = t.nextToken();
if(v.startsWith(marker)){
- v = v.substring(1,v.length());
- double d = Double.parseDouble(v);
- d = Math.round( 1.0/scaling/100.0 * factor * d );
- newLineBuffer.append(marker+d);
+ newLineBuffer.append(
+ marker +
+ calc(
+ extractValue(v)));
}else{
newLineBuffer.append(v);
}
}
return new Line(newLineBuffer.toString());
}
+
+ private String extractValue(String v) {
+ return v.substring(1,v.length());
+ }
+
+ private int calc(String v) {
+ double d = Double.parseDouble(v);
+ d *= factor;
+ d *= scaling / 100.0;
+ if(d > upperLimit){
+ d = upperLimit;
+ }
+ return (int)d;
+ }
}
@@ -30,6 +30,7 @@
JTextField sFactorField;
private static final long serialVersionUID = 1L;
private final GCodeTransformer gCodeTransformer;
+ private JTextField fUpperField;
public GCodeTransformerUI(GCodeTransformer gCodeTransformer){
super(new BorderLayout());
@@ -75,6 +76,14 @@ private void addParametrisation() {
sFactorField = new JTextField("1", JLabel.SOUTH);
p.add(sFactorField, BorderLayout.CENTER);
+ p = new JPanel(new BorderLayout());
+ param.add(p);
+
+ JLabel fUpperLabel = new JLabel("F Upper Limit");
+ p.add(fUpperLabel, BorderLayout.WEST);
+ fUpperField = new JTextField("1000", JLabel.SOUTH);
+ p.add(fUpperField, BorderLayout.CENTER);
+
param = new JPanel(new BorderLayout());
parametrisation.add(param);
@@ -174,6 +183,7 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
gCodeTransformer.setFFactor(Integer.parseInt(fFactorField.getText()));
gCodeTransformer.setSFactor(Integer.parseInt(sFactorField.getText()));
+ gCodeTransformer.setFUpperLimit(Integer.parseInt(fUpperField.getText()));
gCodeTransformer.go();
}
});

0 comments on commit 8117be3

Please sign in to comment.