trackeditor: fix profil steps

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9275 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
iobyte 2024-01-23 21:49:56 +00:00
parent 21931eadab
commit 33d20a4089
7 changed files with 107 additions and 18 deletions

View File

@ -457,7 +457,11 @@ public class SegmentEditorDlg extends JDialog implements SliderListener
{
if (profilStepsSlider == null)
{
profilStepsSlider = new SegmentSlider(0, 100, 0, 0.001, shape.getProfilSteps(), "Steps", "", "ProfilSteps", true);
int minSteps = 1;
if (!shape.getType().equals("str"))
minSteps = 2;
profilStepsSlider = new SegmentSlider(minSteps, 100, 1, 1, shape.getProfilSteps(), "Steps", "", "ProfilSteps", true);
profilStepsSlider.setIntegerFormat();
profilStepsSlider.setBounds(390, 64, 50, 390);
profilStepsSlider.addSliderListener(this);
}
@ -930,10 +934,20 @@ public class SegmentEditorDlg extends JDialog implements SliderListener
String method = slider.getMethod();
if (Double.isNaN(slider.getValue()))
command = "shape.set" + method + "(Double.NaN)";
if (slider.getIntegerFormat())
{
if (slider.getValue() == Integer.MAX_VALUE)
command = "shape.set" + method + "(Integer.MAX_VALUE)";
else
command = "shape.set" + method + "(" + (int) slider.getValue() + ")";
}
else
command = "shape.set" + method + "(" + slider.getValue() + ")";
{
if (Double.isNaN(slider.getValue()))
command = "shape.set" + method + "(Double.NaN)";
else
command = "shape.set" + method + "(" + slider.getValue() + ")";
}
line.eval(command);
shape = (Segment) line.get("shape");
@ -1071,8 +1085,52 @@ public class SegmentEditorDlg extends JDialog implements SliderListener
{
if (slider.isCheckBoxSelected())
{
shape.setProfilStepsLength(shape.getValidProfilStepsLength(editorFrame));
double stepsLength;
if (shape.hasProfilSteps())
{
double length;
if (!shape.getType().equals("str"))
{
Curve curve = (Curve) shape;
length = curve.getArcRad() * (curve.getRadiusStart() + curve.getRadiusEnd()) / 2;
}
else
{
length = shape.getLength();
}
stepsLength = length / shape.getProfilSteps();
}
else
{
stepsLength = shape.getValidProfilStepsLength(editorFrame);
}
shape.setProfilStepsLength(stepsLength);
slider.setValue(shape.getProfilStepsLength());
shape.setProfilSteps(Integer.MAX_VALUE);
profilStepsSlider.setValue(shape.getProfilSteps());
}
}
else if (slider.getSection().equals("Steps") && slider.getAttr().equals(""))
{
if (slider.isCheckBoxSelected())
{
double length;
if (!shape.getType().equals("str"))
{
Curve curve = (Curve) shape;
length = curve.getArcRad() * (curve.getRadiusStart() + curve.getRadiusEnd()) / 2;
}
else
{
length = shape.getLength();
}
int steps = (int) (length / shape.getValidProfilStepsLength(editorFrame) + 0.5);
shape.setProfilSteps(steps);
slider.setValue(shape.getProfilSteps());
shape.setProfilStepsLength(Double.NaN);
profilStepsLengthSlider.setValue(shape.getProfilStepsLength());
}
}
}

View File

@ -68,6 +68,7 @@ public class SegmentSlider extends JPanel
private String method;
private double value = Double.NaN;
private NumberFormat nf;
private boolean integerFormat = false;
/**
*
@ -109,7 +110,6 @@ public class SegmentSlider extends JPanel
nf = NumberFormat.getNumberInstance(Locale.US);
nf.setMaximumFractionDigits(3);
nf.setMinimumFractionDigits(1);
nf.setGroupingUsed(false);
attLabel = new JLabel();
sectionLabel = new JLabel();
@ -131,6 +131,17 @@ public class SegmentSlider extends JPanel
this.add(getSlider(), null);
}
public void setIntegerFormat()
{
integerFormat = true;
nf.setMaximumFractionDigits(0);
nf.setMinimumFractionDigits(0);
}
public boolean getIntegerFormat()
{
return integerFormat;
}
private void setSliderValue(double value)
{
getSlider().setValue((int) Math.round(value / resolution));
@ -211,7 +222,7 @@ public class SegmentSlider extends JPanel
char c = e.getKeyChar();
// check for valid digit or a single decimal point
if (!(Character.isDigit(c) || (c == '.' && !textField.getText().contains("."))))
if (!(Character.isDigit(c) || (!integerFormat && (c == '.' && !textField.getText().contains(".")))))
{
e.consume();
return;
@ -397,6 +408,11 @@ public class SegmentSlider extends JPanel
*/
public double getValue()
{
if (integerFormat && Double.isNaN(value))
{
return Integer.MAX_VALUE;
}
return value;
}
/**
@ -405,8 +421,16 @@ public class SegmentSlider extends JPanel
*/
public void setValue(double val)
{
value = val;
if (Double.isNaN(val))
if (integerFormat && val == Integer.MAX_VALUE)
{
value = Double.NaN;
}
else
{
value = val;
}
if (Double.isNaN(value))
{
getTextField().setText("");
getTextField().setEnabled(false);

View File

@ -937,7 +937,7 @@ public class XmlReader
shape.setBankingStart(getAttrNumValue(seg, "banking start", "deg"));
shape.setBankingEnd(getAttrNumValue(seg, "banking end", "deg"));
shape.setProfil(getAttrStrValue(seg, "profil"));
shape.setProfilSteps(getAttrNumValue(seg, "profil steps"));
shape.setProfilSteps(getAttrIntValue(seg, "profil steps"));
shape.setProfilStepsLength(getAttrNumValue(seg, "profil steps length", "m"));
shape.setProfilStartTangent(getAttrNumValue(seg, "profil start tangent", "%"));
shape.setProfilEndTangent(getAttrNumValue(seg, "profil end tangent", "%"));

View File

@ -316,7 +316,7 @@ public class XmlWriter
addContent(segment, "banking start", "deg", shape.getBankingStart());
addContent(segment, "banking end", "deg", shape.getBankingEnd());
addContent(segment, "profil", shape.getProfil());
addContent(segment, "profil steps", "m", shape.getProfilSteps());
addContent(segment, "profil steps", null, shape.getProfilSteps());
addContent(segment, "profil steps length", "m", shape.getProfilStepsLength());
addContent(segment, "profil start tangent", "%", shape.getProfilStartTangent());
addContent(segment, "profil end tangent", "%", shape.getProfilEndTangent());

View File

@ -34,7 +34,7 @@ public class Properties
private static Properties instance = new Properties();
private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>();
public final String title = "sd2-trackeditor";
public final String version = "1.4.15";
public final String version = "1.4.16";
private String path;
private double imageScale = 1;

View File

@ -131,11 +131,18 @@ public class Curve extends Segment
*
*
*/
// calc turn length
double arc = getArcRad();
length = arc * (radiusStart + radiusEnd) / 2;
nbSteps = (int) (length / profilStepsLength + 0.5) + 1;
if (hasProfilSteps())
{
nbSteps = getProfilSteps();
}
else
{
nbSteps = (int) (length / profilStepsLength + 0.5) + 1;
}
trackStartDist += length;

View File

@ -77,7 +77,7 @@ public class Segment implements Cloneable
protected double bankingEnd = Double.NaN;
protected String profil = null;
protected double profilSteps = Double.NaN;
protected int profilSteps = Integer.MAX_VALUE;
protected double profilStepsLength = Double.NaN;
protected double profilStartTangent = Double.NaN;
protected double profilEndTangent = Double.NaN;
@ -575,7 +575,7 @@ public class Segment implements Cloneable
/**
* @return Returns the profilSteps.
*/
public double getProfilSteps()
public int getProfilSteps()
{
return profilSteps;
}
@ -583,13 +583,13 @@ public class Segment implements Cloneable
* @param profilSteps
* The profilSteps to set.
*/
public void setProfilSteps(double profilSteps)
public void setProfilSteps(int profilSteps)
{
this.profilSteps = profilSteps;
}
public boolean hasProfilSteps()
{
return !Double.isNaN(profilSteps);
return profilSteps != Integer.MAX_VALUE;
}
/**