trackeditor: add ability to set height of individual objects
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9121 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
parent
b388df28e3
commit
140edbd52a
|
@ -14,6 +14,7 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import gui.properties.GraphicObjectData;
|
||||
import utils.circuit.GraphicObject;
|
||||
import utils.circuit.ObjShapeObject;
|
||||
import utils.circuit.ObjectData;
|
||||
|
@ -25,6 +26,7 @@ public class TrackObjectDialog extends JDialog
|
|||
private GraphicObject graphicObject = null;
|
||||
private ObjShapeObject objectShape = null;
|
||||
private ObjectData objectData = null;
|
||||
private GraphicObjectData graphicObjectData = null;
|
||||
private Vector<TrackObject> objects = null;
|
||||
private boolean ignoreActions = true;
|
||||
private boolean changed = false;
|
||||
|
@ -52,6 +54,9 @@ public class TrackObjectDialog extends JDialog
|
|||
private JLabel orientationLabel = new JLabel();
|
||||
private JTextField orientationTextField = new JTextField();
|
||||
|
||||
private JLabel heightLabel = new JLabel();
|
||||
private JTextField heightTextField = new JTextField();
|
||||
|
||||
private JButton applyButton = new JButton();
|
||||
private JButton cancelButton = new JButton();
|
||||
|
||||
|
@ -108,6 +113,15 @@ public class TrackObjectDialog extends JDialog
|
|||
initialize(0, 0);
|
||||
}
|
||||
|
||||
public TrackObjectDialog(EditorFrame editorFrame, boolean all, GraphicObjectData graphicObjectData)
|
||||
{
|
||||
super();
|
||||
this.graphicObjectData = graphicObjectData;
|
||||
setTitle("Edit Object");
|
||||
this.editorFrame = editorFrame;
|
||||
initialize(0, 0);
|
||||
}
|
||||
|
||||
public boolean isChanged()
|
||||
{
|
||||
return changed;
|
||||
|
@ -120,6 +134,11 @@ public class TrackObjectDialog extends JDialog
|
|||
return objectShape.getRGB();
|
||||
}
|
||||
|
||||
if (graphicObjectData != null)
|
||||
{
|
||||
return graphicObjectData.color;
|
||||
}
|
||||
|
||||
return objectData.color;
|
||||
}
|
||||
private void setRGB(int rgb)
|
||||
|
@ -130,6 +149,12 @@ public class TrackObjectDialog extends JDialog
|
|||
return;
|
||||
}
|
||||
|
||||
if (graphicObjectData != null)
|
||||
{
|
||||
graphicObjectData.color = rgb;
|
||||
return;
|
||||
}
|
||||
|
||||
objectData.color = rgb;
|
||||
}
|
||||
|
||||
|
@ -140,6 +165,11 @@ public class TrackObjectDialog extends JDialog
|
|||
return objectShape.getName();
|
||||
}
|
||||
|
||||
if (graphicObjectData != null)
|
||||
{
|
||||
return graphicObjectData.name;
|
||||
}
|
||||
|
||||
return objectData.name;
|
||||
}
|
||||
private void setObjectName(String name)
|
||||
|
@ -150,6 +180,12 @@ public class TrackObjectDialog extends JDialog
|
|||
return;
|
||||
}
|
||||
|
||||
if (graphicObjectData != null)
|
||||
{
|
||||
graphicObjectData.name = name;
|
||||
return;
|
||||
}
|
||||
|
||||
objectData.name = name;
|
||||
}
|
||||
|
||||
|
@ -160,6 +196,11 @@ public class TrackObjectDialog extends JDialog
|
|||
return objectShape.getTrackLocation();
|
||||
}
|
||||
|
||||
if (graphicObjectData != null)
|
||||
{
|
||||
return new Point2D.Double(graphicObjectData.trackX, graphicObjectData.trackY);
|
||||
}
|
||||
|
||||
return new Point2D.Double(objectData.trackX, objectData.trackY);
|
||||
}
|
||||
|
||||
|
@ -182,15 +223,43 @@ public class TrackObjectDialog extends JDialog
|
|||
|
||||
return objectData.imageY;
|
||||
}
|
||||
|
||||
private double getOrientation()
|
||||
{
|
||||
if (graphicObject != null)
|
||||
{
|
||||
return graphicObject.getOrientation();
|
||||
}
|
||||
else if (graphicObjectData != null)
|
||||
{
|
||||
return graphicObjectData.orientation;
|
||||
}
|
||||
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
private double getObjectHeight()
|
||||
{
|
||||
if (graphicObject != null)
|
||||
{
|
||||
return graphicObject.getHeight();
|
||||
}
|
||||
else if (graphicObjectData != null)
|
||||
{
|
||||
return graphicObjectData.height;
|
||||
}
|
||||
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
private void initialize(int x, int y)
|
||||
{
|
||||
isGraphicObject = objectShape != null && objectShape.getType().equals("graphic object");
|
||||
isGraphicObject = (objectShape != null && objectShape.getType().equals("graphic object")) || graphicObjectData != null;
|
||||
|
||||
setLayout(null);
|
||||
setSize(320, 252);
|
||||
setSize(320, 279);
|
||||
setResizable(false);
|
||||
if (objectData == null)
|
||||
if (objectData == null && graphicObjectData == null)
|
||||
{
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
@ -296,12 +365,19 @@ public class TrackObjectDialog extends JDialog
|
|||
orientationLabel.setText("Orientation");
|
||||
orientationLabel.setBounds(10, 145, 120, 23);
|
||||
|
||||
if (!Double.isNaN(graphicObject.getOrientation()))
|
||||
orientationTextField.setText("" + graphicObject.getOrientation());
|
||||
if (!Double.isNaN(getOrientation()))
|
||||
orientationTextField.setText("" + getOrientation());
|
||||
orientationTextField.setBounds(120, 145, 170, 23);
|
||||
|
||||
heightLabel.setText("Height");
|
||||
heightLabel.setBounds(10, 172, 120, 23);
|
||||
|
||||
if (!Double.isNaN(getObjectHeight()))
|
||||
heightTextField.setText("" + getObjectHeight());
|
||||
heightTextField.setBounds(120, 172, 170, 23);
|
||||
}
|
||||
|
||||
applyButton.setBounds(50, 177, 70, 25);
|
||||
applyButton.setBounds(50, 204, 70, 25);
|
||||
applyButton.setText("Apply");
|
||||
applyButton.addActionListener(new ActionListener()
|
||||
{
|
||||
|
@ -311,7 +387,7 @@ public class TrackObjectDialog extends JDialog
|
|||
}
|
||||
});
|
||||
|
||||
cancelButton.setBounds(185, 177, 70, 25);
|
||||
cancelButton.setBounds(185, 204, 70, 25);
|
||||
cancelButton.setText("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener()
|
||||
{
|
||||
|
@ -344,6 +420,8 @@ public class TrackObjectDialog extends JDialog
|
|||
{
|
||||
add(orientationLabel);
|
||||
add(orientationTextField);
|
||||
add(heightLabel);
|
||||
add(heightTextField);
|
||||
}
|
||||
|
||||
add(applyButton);
|
||||
|
@ -435,7 +513,7 @@ public class TrackObjectDialog extends JDialog
|
|||
|
||||
setRGB(rgb);
|
||||
|
||||
if (isGraphicObject)
|
||||
if (objectShape != null)
|
||||
{
|
||||
String newName = nameTextField.getText();
|
||||
|
||||
|
@ -467,6 +545,64 @@ public class TrackObjectDialog extends JDialog
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
String heightText = heightTextField.getText();
|
||||
if (heightText == null || heightText.isEmpty())
|
||||
{
|
||||
graphicObject.setHeight(Double.NaN);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
graphicObject.setHeight(Double.parseDouble(heightText));
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (graphicObjectData != null)
|
||||
{
|
||||
String newName = nameTextField.getText();
|
||||
|
||||
if (!newName.equals(graphicObjectData.name))
|
||||
{
|
||||
// TODO: check for duplicate name
|
||||
graphicObjectData.name = newName;
|
||||
}
|
||||
|
||||
String orientationText = orientationTextField.getText();
|
||||
if (orientationText == null || orientationText.isEmpty())
|
||||
{
|
||||
graphicObjectData.orientation = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
graphicObjectData.orientation = Double.parseDouble(orientationText);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
String heightText = heightTextField.getText();
|
||||
if (heightText == null || heightText.isEmpty())
|
||||
{
|
||||
graphicObjectData.height = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
graphicObjectData.height = Double.parseDouble(heightText);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changed = true;
|
||||
|
|
|
@ -2,18 +2,20 @@ package gui.properties;
|
|||
|
||||
public class GraphicObjectData
|
||||
{
|
||||
String name;
|
||||
Integer color;
|
||||
Double trackX;
|
||||
Double trackY;
|
||||
Double orientation;
|
||||
public String name;
|
||||
public Integer color;
|
||||
public Double trackX;
|
||||
public Double trackY;
|
||||
public Double orientation;
|
||||
public Double height;
|
||||
|
||||
GraphicObjectData(String name, Integer color, double trackX, double trackY, double orientation)
|
||||
GraphicObjectData(String name, Integer color, double trackX, double trackY, double orientation, double height)
|
||||
{
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.trackX = trackX;
|
||||
this.trackY = trackY;
|
||||
this.orientation = orientation;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.swing.table.DefaultTableCellRenderer;
|
|||
import javax.swing.table.TableColumn;
|
||||
|
||||
import gui.EditorFrame;
|
||||
import gui.TrackObjectDialog;
|
||||
import utils.circuit.GraphicObject;
|
||||
|
||||
public class GraphicObjectProperties extends PropertyPanel
|
||||
|
@ -134,16 +135,16 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
name = new String("Unknown");
|
||||
}
|
||||
|
||||
data.add(new GraphicObjectData(name, object.getColor(), object.getX(), object.getY(), object.getOrientation()));
|
||||
data.add(new GraphicObjectData(name, object.getColor(), object.getX(), object.getY(), object.getOrientation(), object.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
class GraphicObjectTableModel extends AbstractTableModel
|
||||
{
|
||||
private final String[] columnNames = { null, "Name", "Object", "Color", "Track X", "Track Y", "Orientation" };
|
||||
private final String[] columnNames = { null, "Name", "Object", "Color", "Track X", "Track Y", "Orientation", "Height" };
|
||||
private final Class<?>[] columnClass = new Class[]
|
||||
{
|
||||
Integer.class, String.class, String.class, Integer.class, Double.class, Double.class, Double.class
|
||||
Integer.class, String.class, String.class, Integer.class, Double.class, Double.class, Double.class, Double.class
|
||||
};
|
||||
private Vector<GraphicObject> graphicObjects = null;
|
||||
|
||||
|
@ -206,6 +207,12 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
return datum.orientation;
|
||||
}
|
||||
return null;
|
||||
case 7:
|
||||
if (datum.height != null && !Double.isNaN(datum.height))
|
||||
{
|
||||
return datum.height;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -248,6 +255,10 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
datum.orientation = (Double) value;
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
case 7:
|
||||
datum.height = (Double) value;
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,9 +353,37 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
public JPopupMenu createPopupMenu(GraphicObjectTablePanel panel)
|
||||
{
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem editItem = new JMenuItem("Edit Object");
|
||||
JMenuItem deleteItem = new JMenuItem("Delete Object");
|
||||
JMenuItem deleteAllColorItem = new JMenuItem("Delete All Objects With This Color");
|
||||
|
||||
editItem.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int row = panel.table.getSelectedRow();
|
||||
if (row != -1)
|
||||
{
|
||||
GraphicObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
|
||||
|
||||
TrackObjectDialog editObjectDialog = new TrackObjectDialog(getEditorFrame(), false, datum);
|
||||
|
||||
editObjectDialog.setModal(true);
|
||||
editObjectDialog.setVisible(true);
|
||||
|
||||
if (editObjectDialog.isChanged())
|
||||
{
|
||||
panel.model.setValueAt(datum.name, row, 1);
|
||||
panel.model.setValueAt(datum.color, row, 3);
|
||||
panel.model.setValueAt(datum.orientation, row, 6);
|
||||
panel.model.setValueAt(datum.height, row, 7);
|
||||
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deleteItem.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
|
@ -395,6 +434,7 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
}
|
||||
});
|
||||
|
||||
popupMenu.add(editItem);
|
||||
popupMenu.add(deleteItem);
|
||||
popupMenu.add(deleteAllColorItem);
|
||||
|
||||
|
@ -451,6 +491,20 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
object.setOrientation(datum.orientation);
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
|
||||
if (datum.height == null)
|
||||
{
|
||||
if (!Double.isNaN(object.getHeight()))
|
||||
{
|
||||
object.setHeight(Double.NaN);
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
}
|
||||
else if (!datum.height.equals(object.getHeight()))
|
||||
{
|
||||
object.setHeight(datum.height);
|
||||
getEditorFrame().documentIsModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.size() < graphicObjects.size())
|
||||
|
@ -474,6 +528,11 @@ public class GraphicObjectProperties extends PropertyPanel
|
|||
{
|
||||
graphicObjects.lastElement().setOrientation(datum.orientation);
|
||||
}
|
||||
|
||||
if (datum.height != null && !Double.isNaN(datum.height))
|
||||
{
|
||||
graphicObjects.lastElement().setHeight(datum.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -800,7 +800,7 @@ public class ObjectMapProperties extends PropertyPanel
|
|||
{
|
||||
ObjectData datum = data.elementAt(panel.table.convertRowIndexToModel(row));
|
||||
String name = getEditorFrame().getObjectColorName(datum.color) + "-" + data.size();
|
||||
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum.trackX, datum.trackY, Double.NaN);
|
||||
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum.trackX, datum.trackY, Double.NaN, Double.NaN);
|
||||
getEditorFrame().getGraphicObjectProperties().addData(graphicObjectData);
|
||||
panel.model.removeRowAt(panel.table.convertRowIndexToModel(row));
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ public class ObjectMapProperties extends PropertyPanel
|
|||
{
|
||||
ObjectData datum1 = data.elementAt(i);
|
||||
String name = getEditorFrame().getObjectColorName(datum.color) + "-" + size++;
|
||||
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum1.trackX, datum1.trackY, Double.NaN);
|
||||
GraphicObjectData graphicObjectData = new GraphicObjectData(name, datum.color, datum1.trackX, datum1.trackY, Double.NaN, Double.NaN);
|
||||
getEditorFrame().getGraphicObjectProperties().addData(graphicObjectData);
|
||||
}
|
||||
for (int i = 0; i < toMove.size(); i++)
|
||||
|
|
|
@ -639,6 +639,7 @@ public class XmlReader
|
|||
getAttrIntValue(el, "color"),
|
||||
new Point2D.Double(getAttrNumValue(el, "x"), getAttrNumValue(el, "y")));
|
||||
object.setOrientation(getAttrNumValue(el, "orientation", "deg"));
|
||||
object.setHeight(getAttrNumValue(el, "height", "m"));
|
||||
graphicObjects.add(object);
|
||||
}
|
||||
data.getTerrainGeneration().setGraphicObjects(graphicObjects);
|
||||
|
|
|
@ -936,6 +936,7 @@ public class XmlWriter
|
|||
addContent(el, "x", "m", graphicObject.getX());
|
||||
addContent(el, "y", "m", graphicObject.getY());
|
||||
addContent(el, "orientation", "deg", graphicObject.getOrientation());
|
||||
addContent(el, "height", "m", graphicObject.getHeight());
|
||||
|
||||
element.addContent(el);
|
||||
}
|
||||
|
|
|
@ -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.3.16";
|
||||
public final String version = "1.3.17";
|
||||
private String path;
|
||||
|
||||
private double imageScale = 1;
|
||||
|
|
|
@ -8,6 +8,7 @@ public class GraphicObject
|
|||
|
||||
// TODO add more overrides here
|
||||
private double orientation = Double.NaN;
|
||||
private double height = Double.NaN;
|
||||
|
||||
public GraphicObject(String name, int rgb, Point2D.Double location)
|
||||
{
|
||||
|
@ -86,6 +87,16 @@ public class GraphicObject
|
|||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public double getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(double height)
|
||||
{
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void dump(String indent)
|
||||
{
|
||||
System.out.println(indent + "name : " + getName());
|
||||
|
@ -93,5 +104,6 @@ public class GraphicObject
|
|||
System.out.println(indent + "x : " + getX());
|
||||
System.out.println(indent + "y : " + getY());
|
||||
System.out.println(indent + "orientation : " + getOrientation());
|
||||
System.out.println(indent + "height : " + getHeight());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
|
||||
//! Constructor.
|
||||
Application::Application()
|
||||
: GfApplication("TrackGen", "1.6.0.33", "Terrain generator for tracks")
|
||||
: GfApplication("TrackGen", "1.6.0.34", "Terrain generator for tracks")
|
||||
, HeightSteps(30)
|
||||
, Bump(false)
|
||||
, Raceline(false)
|
||||
|
|
|
@ -216,10 +216,12 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
|
|||
tdble angle = 0;
|
||||
float z = 0;
|
||||
tdble orientation = 0;
|
||||
tdble height = 0;
|
||||
|
||||
if (individual)
|
||||
{
|
||||
orientation = GfParmGetCurNum(trackHandle, TRK_SECT_TERRAIN_OBJECTS, TRK_ATT_ORIENTATION, "deg", 0);
|
||||
height = GfParmGetCurNum(trackHandle, TRK_SECT_TERRAIN_OBJECTS, TRK_ATT_HEIGHT, "m", 0);
|
||||
}
|
||||
|
||||
Ac3d obj(curObj.ac3d);
|
||||
|
@ -293,7 +295,7 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
|
|||
m.makeRotation(angle + orientation, dv / 2.0 - dv * rand() / (RAND_MAX + 1.0), dv / 2.0 - dv * rand() / (RAND_MAX + 1.0));
|
||||
obj.transform(m);
|
||||
|
||||
m.makeLocation(x, y, z);
|
||||
m.makeLocation(x, y, z + height);
|
||||
obj.transform(m);
|
||||
obj.splitBySURF();
|
||||
obj.splitByMaterial();
|
||||
|
|
Loading…
Reference in New Issue