trackeditor: added Segment -> Dump Text and Segment -> Dump AC3D menu items for debugging

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9320 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
iobyte 2024-02-14 05:29:54 +00:00
parent f50ae917c5
commit e2471abb84
6 changed files with 205 additions and 69 deletions

View File

@ -44,6 +44,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -123,6 +124,8 @@ public class EditorFrame extends JFrame
ShowReliefsAction showReliefsAction = null;
MoveAction moveAction = null;
SubdivideAction subdivideAction = null;
DumpTextAction dumpTextAction = null;
DumpAC3DAction dumpAC3DAction = null;
HelpAction helpAction = null;
ImportAction importAction = null;
ExportAction exportAction = null;
@ -187,7 +190,9 @@ public class EditorFrame extends JFrame
private JMenuItem addLeftMenuItem = null;
private JMenuItem moveMenuItem = null;
private JMenuItem deleteMenuItem = null;
private JMenuItem subdivideMenuItem = null;
private JMenuItem subdivideMenuItem = null;
private JMenuItem dumpTextMenuItem = null;
private JMenuItem dumpAC3DMenuItem = null;
private JMenuItem showArrowsMenuItem = null;
private JMenuItem showBackgroundMenuItem = null;
private JMenuItem showObjectsMenuItem = null;
@ -651,8 +656,6 @@ public class EditorFrame extends JFrame
updateRecentFiles(projectFileName);
setTitle(originalTitle + " - Project: " + projectFileName);
//writeTrack();
}
/**
@ -1091,6 +1094,9 @@ public class EditorFrame extends JFrame
segmentMenu.add(getMoveMenuItem());
segmentMenu.add(getDeleteMenuItem());
segmentMenu.add(getSubdivideMenuItem());
segmentMenu.addSeparator();
segmentMenu.add(getDumpTextMenuItem());
segmentMenu.add(getDumpAC3DMenuItem());
}
return segmentMenu;
}
@ -1199,7 +1205,39 @@ public class EditorFrame extends JFrame
}
return subdivideMenuItem;
}
/**
/**
* This method initializes dumpTextMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getDumpTextMenuItem()
{
if (dumpTextMenuItem == null)
{
dumpTextMenuItem = new JMenuItem();
dumpTextMenuItem.setAction(dumpTextAction);
dumpTextMenuItem.setIcon(null);
}
return dumpTextMenuItem;
}
/**
* This method initializes dumpAC3DMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getDumpAC3DMenuItem()
{
if (dumpAC3DMenuItem == null)
{
dumpAC3DMenuItem = new JMenuItem();
dumpAC3DMenuItem.setAction(dumpAC3DAction);
dumpAC3DMenuItem.setIcon(null);
}
return dumpAC3DMenuItem;
}
/**
* This method initializes deleteMenuItem
*
* @return javax.swing.JMenuItem
@ -2156,7 +2194,38 @@ public class EditorFrame extends JFrame
checkButtons(toggleButtonSubdivide, CircuitView.STATE_SUBDIVIDE);
}
void menuItemAddBackground_actionPerformed(ActionEvent e)
void dumpText_actionPerformed(ActionEvent e)
{
if (trackData == null)
{
message("No track", "Nothing to dump.");
return;
}
String fileName = Editor.getProperties().getPath();
String trackName = fileName.substring(fileName.lastIndexOf(sep) + 1);
fileName = fileName + sep + trackName + "-track.txt";
try
{
FileOutputStream stream = new FileOutputStream(fileName);
PrintStream printStream = new PrintStream(stream);
trackData.getSegments().dump(printStream);
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this,
"Couldn't write : " + fileName + "\n\n" + ex.getLocalizedMessage(),
"Dump Segment Text", JOptionPane.ERROR_MESSAGE);
}
}
void dumpAC3D_actionPerformed(ActionEvent e)
{
writeTrack();
}
void menuItemAddBackground_actionPerformed(ActionEvent e)
{
if (trackData == null)
{
@ -2316,6 +2385,8 @@ public class EditorFrame extends JFrame
redoAction = new RedoAction("Redo", createNavigationIcon("Redo24"), "Redo.", KeyEvent.VK_R);
deleteAction = new DeleteAction("Delete", createNavigationIcon("Cut24"), "Delete.", KeyEvent.VK_L);
subdivideAction = new SubdivideAction("Subdivide", createNavigationIcon("Subdivide24"), "Subdivide.", KeyEvent.VK_Q);
dumpTextAction = new DumpTextAction("Dump Text", null, "Dump segments to file.", null);
dumpAC3DAction = new DumpAC3DAction("Dump Ac3d", null, "Dumpsegements to AC3d file.", null);
zoomPlusAction = new ZoomPlusAction("Zoom in", createNavigationIcon("ZoomIn24"), "Zoom in.", KeyEvent.VK_M);
zoomOneAction = new ZoomOneAction("Zoom 1:1", createNavigationIcon("Zoom24"), "Zoom 1:1.", KeyEvent.VK_N);
zoomMinusAction = new ZoomMinusAction("Zoom out", createNavigationIcon("ZoomOut24"), "Zoom out.", KeyEvent.VK_O);
@ -2400,7 +2471,35 @@ public class EditorFrame extends JFrame
toggleButtonSubdivide_actionPerformed(e);
}
}
public class ZoomPlusAction extends AbstractAction
public class DumpTextAction extends AbstractAction
{
public DumpTextAction(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
public void actionPerformed(final ActionEvent e) {
dumpText_actionPerformed(e);
}
}
public class DumpAC3DAction extends AbstractAction
{
public DumpAC3DAction(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
public void actionPerformed(final ActionEvent e) {
dumpAC3D_actionPerformed(e);
}
}
public class ZoomPlusAction extends AbstractAction
{
public ZoomPlusAction(String text, ImageIcon icon, String desc, Integer mnemonic)
{
@ -3013,7 +3112,9 @@ public class EditorFrame extends JFrame
message("No track", "Can't write track.");
return;
}
String filename = Editor.getProperties().getPath() + sep + trackData.getHeader().getName() + "-track.ac";
String filePath = Editor.getProperties().getPath();
String trackName = filePath.substring(filePath.lastIndexOf(sep) + 1);
String filename = Editor.getProperties().getPath() + sep + trackName + "-track.ac";
Ac3d track = new Ac3d();
Ac3dMaterial material = new Ac3dMaterial("");
@ -3029,7 +3130,7 @@ public class EditorFrame extends JFrame
track.getMaterials().add(material);
track.setRoot(world);
Ac3dObject group = new Ac3dObject("group", 5);
group.setName("track");
world.addKid(group);

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.41";
public final String version = "1.4.42";
private String path;
private double imageScale = 1;

View File

@ -1,5 +1,6 @@
package utils;
import java.io.PrintStream;
import java.util.Vector;
import utils.circuit.Segment;
@ -146,6 +147,15 @@ public class SegmentVector extends Vector<Segment>
}
}
public void dump(PrintStream printStream)
{
for (int i = 0; i < size(); i++)
{
printStream.println("segment[" + i + "]");
get(i).dump(printStream, " ", true, false, false, false);
}
}
public void dumpLinks()
{
for (int i = 0; i < size(); i++)

View File

@ -21,6 +21,8 @@
package utils.circuit;
import java.awt.geom.Point2D;
import java.io.PrintStream;
import gui.EditorFrame;
import utils.Editor;
@ -557,4 +559,15 @@ public class Curve extends Segment
return s; // return the clone
}
public void dump(PrintStream printStream, String indent, boolean dumpCalculated, boolean dumpPoints, boolean dumpTrPoints, boolean dumpToDraw)
{
printStream.println(indent + "Curve");
printStream.println(indent + " arcDeg : " + arcDeg);
printStream.println(indent + " radiusStart : " + radiusStart);
printStream.println(indent + " radiusEnd : " + radiusEnd);
printStream.println(indent + " center : " + center.x + ", " + center.y);
printStream.println(indent + " marks : " + marks);
super.dump(printStream, indent, dumpCalculated, dumpPoints, dumpTrPoints, dumpToDraw);
}
}

View File

@ -26,6 +26,7 @@ import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Vector;
@ -2497,114 +2498,118 @@ public class Segment implements Cloneable
public void dump(String indent, boolean dumpCalculated, boolean dumpPoints, boolean dumpTrPoints, boolean dumpToDraw)
{
System.out.println(indent + "Segment");
System.out.println(indent + " previousShape : " + (previousShape != null ? previousShape.name : "null"));
System.out.println(indent + " nextShape : " + (nextShape != null ? nextShape.name : "null"));
System.out.println(indent + " name : " + name);
System.out.println(indent + " type : " + type);
System.out.println(indent + " count : " + count);
System.out.println(indent + " length : " + length);
System.out.println(indent + " nbSteps : " + nbSteps);
System.out.println(indent + " stepLength : " + stepLength);
System.out.println(indent + " surface : " + surface);
System.out.println(indent + " heightStart : " + heightStart);
System.out.println(indent + " heightStartLeft : " + heightStartLeft);
System.out.println(indent + " heightStartRight : " + heightStartRight);
System.out.println(indent + " heightEnd : " + heightEnd);
System.out.println(indent + " heightEndLeft : " + heightEndLeft);
System.out.println(indent + " heightEndRight : " + heightEndRight);
System.out.println(indent + " grade : " + grade);
System.out.println(indent + " bankingStart : " + bankingStart);
System.out.println(indent + " bankingEnd : " + bankingEnd);
System.out.println(indent + " profil : " + profil);
System.out.println(indent + " profilSteps : " + profilSteps);
System.out.println(indent + " profilStepsLength : " + profilStepsLength);
System.out.println(indent + " profilStartTangent : " + profilStartTangent);
System.out.println(indent + " profilEndTangent : " + profilEndTangent);
System.out.println(indent + " profilStartTangentLeft : " + profilStartTangentLeft);
System.out.println(indent + " profilEndTangentLeft : " + profilEndTangentLeft);
System.out.println(indent + " profilStartTangentRight : " + profilStartTangentRight);
System.out.println(indent + " profilEndTangentRight : " + profilEndTangentRight);
dump(System.out, indent, dumpCalculated, dumpPoints, dumpTrPoints, dumpToDraw);
}
public void dump(PrintStream printStream, String indent, boolean dumpCalculated, boolean dumpPoints, boolean dumpTrPoints, boolean dumpToDraw)
{
printStream.println(indent + " previousShape : " + (previousShape != null ? previousShape.name : "null"));
printStream.println(indent + " nextShape : " + (nextShape != null ? nextShape.name : "null"));
printStream.println(indent + " name : " + name);
printStream.println(indent + " type : " + type);
printStream.println(indent + " count : " + count);
printStream.println(indent + " length : " + length);
printStream.println(indent + " nbSteps : " + nbSteps);
printStream.println(indent + " stepLength : " + stepLength);
printStream.println(indent + " surface : " + surface);
printStream.println(indent + " heightStart : " + heightStart);
printStream.println(indent + " heightStartLeft : " + heightStartLeft);
printStream.println(indent + " heightStartRight : " + heightStartRight);
printStream.println(indent + " heightEnd : " + heightEnd);
printStream.println(indent + " heightEndLeft : " + heightEndLeft);
printStream.println(indent + " heightEndRight : " + heightEndRight);
printStream.println(indent + " grade : " + grade);
printStream.println(indent + " bankingStart : " + bankingStart);
printStream.println(indent + " bankingEnd : " + bankingEnd);
printStream.println(indent + " profil : " + profil);
printStream.println(indent + " profilSteps : " + profilSteps);
printStream.println(indent + " profilStepsLength : " + profilStepsLength);
printStream.println(indent + " profilStartTangent : " + profilStartTangent);
printStream.println(indent + " profilEndTangent : " + profilEndTangent);
printStream.println(indent + " profilStartTangentLeft : " + profilStartTangentLeft);
printStream.println(indent + " profilEndTangentLeft : " + profilEndTangentLeft);
printStream.println(indent + " profilStartTangentRight : " + profilStartTangentRight);
printStream.println(indent + " profilEndTangentRight : " + profilEndTangentRight);
if (dumpCalculated)
{
System.out.println(indent + " calculatedHeightStart : " + calculatedHeightStart);
System.out.println(indent + " calculatedHeightStartLeft : " + calculatedHeightStartLeft);
System.out.println(indent + " calculatedHeightStartRight : " + calculatedHeightStartRight);
System.out.println(indent + " calculatedHeightEnd : " + calculatedHeightEndLeft);
System.out.println(indent + " calculatedHeightEndLeft : " + calculatedHeightEndLeft);
System.out.println(indent + " calculatedHeightEndRight : " + calculatedHeightEndRight);
System.out.println(indent + " calculatedGrade : " + calculatedGrade);
System.out.println(indent + " calculatedBankingStart : " + calculatedBankingStart);
System.out.println(indent + " calculatedBankingEnd : " + calculatedBankingEnd);
System.out.println(indent + " calculatedStartTangent : " + calculatedStartTangent);
System.out.println(indent + " calculatedStartTangentLeft : " + calculatedStartTangentLeft);
System.out.println(indent + " calculatedStartTangentRight : " + calculatedStartTangentRight);
System.out.println(indent + " calculatedEndTangent : " + calculatedEndTangent);
System.out.println(indent + " calculatedEndTangentLeft : " + calculatedEndTangentLeft);
System.out.println(indent + " calculatedEndTangentRight : " + calculatedEndTangentRight);
printStream.println(indent + " calculatedHeightStart : " + calculatedHeightStart);
printStream.println(indent + " calculatedHeightStartLeft : " + calculatedHeightStartLeft);
printStream.println(indent + " calculatedHeightStartRight : " + calculatedHeightStartRight);
printStream.println(indent + " calculatedHeightEnd : " + calculatedHeightEndLeft);
printStream.println(indent + " calculatedHeightEndLeft : " + calculatedHeightEndLeft);
printStream.println(indent + " calculatedHeightEndRight : " + calculatedHeightEndRight);
printStream.println(indent + " calculatedGrade : " + calculatedGrade);
printStream.println(indent + " calculatedBankingStart : " + calculatedBankingStart);
printStream.println(indent + " calculatedBankingEnd : " + calculatedBankingEnd);
printStream.println(indent + " calculatedStartTangent : " + calculatedStartTangent);
printStream.println(indent + " calculatedStartTangentLeft : " + calculatedStartTangentLeft);
printStream.println(indent + " calculatedStartTangentRight : " + calculatedStartTangentRight);
printStream.println(indent + " calculatedEndTangent : " + calculatedEndTangent);
printStream.println(indent + " calculatedEndTangentLeft : " + calculatedEndTangentLeft);
printStream.println(indent + " calculatedEndTangentRight : " + calculatedEndTangentRight);
}
if (points != null)
{
System.out.println(indent + " points : " + points.length);
printStream.println(indent + " points : " + points.length);
if (dumpPoints)
{
for (int i = 0; i < points.length; i++)
{
System.out.println(indent + " points[" + i + "] " +
String.format("%12.7f", points[i].x) + ", " +
String.format("%12.7f", points[i].y) + ", " +
String.format("%12.7f", points[i].z));
printStream.println(indent + " points[" + i + "] " +
String.format("%12.7f", points[i].x) + ", " +
String.format("%12.7f", points[i].y) + ", " +
String.format("%12.7f", points[i].z));
}
}
}
else
{
System.out.println(indent + " points : null");
printStream.println(indent + " points : null");
}
if (trPoints != null)
{
System.out.println(indent + " trPoints : " + trPoints.length);
printStream.println(indent + " trPoints : " + trPoints.length);
if (dumpTrPoints)
{
for (int i = 0; i < trPoints.length; i++)
{
System.out.println(indent + " trPoints[" + i + "] " + trPoints[i].x + ", " + trPoints[i].y);
printStream.println(indent + " trPoints[" + i + "] " + trPoints[i].x + ", " + trPoints[i].y);
}
}
}
else
{
System.out.println(indent + " trPoints : null");
printStream.println(indent + " trPoints : null");
}
if (dumpToDraw)
{
if (xToDraw != null)
{
System.out.println(indent + " xToDraw : " + xToDraw.length);
printStream.println(indent + " xToDraw : " + xToDraw.length);
for (int i = 0; i < xToDraw.length; i++)
{
System.out.println(indent + " xToDraw[" + i + "] " + xToDraw[i]);
printStream.println(indent + " xToDraw[" + i + "] " + xToDraw[i]);
}
}
else
{
System.out.println(indent + " xToDraw : null");
printStream.println(indent + " xToDraw : null");
}
if (yToDraw != null)
{
System.out.println(indent + " yToDraw : " + yToDraw.length);
printStream.println(indent + " yToDraw : " + yToDraw.length);
for (int i = 0; i < yToDraw.length; i++)
{
System.out.println(indent + " yToDraw[" + i + "] " + yToDraw[i]);
printStream.println(indent + " yToDraw[" + i + "] " + yToDraw[i]);
}
}
else
{
System.out.println(indent + " yToDraw : null");
printStream.println(indent + " yToDraw : null");
}
}
System.out.println(indent + " dx : " + dx);
System.out.println(indent + " dy : " + dy);
printStream.println(indent + " dx : " + dx);
printStream.println(indent + " dy : " + dy);
}
}

View File

@ -21,6 +21,8 @@
package utils.circuit;
import java.awt.geom.Point2D;
import java.io.PrintStream;
import gui.EditorFrame;
import utils.Editor;
@ -375,4 +377,9 @@ public class Straight extends Segment
return s; // return the clone
}
public void dump(PrintStream printStream, String indent, boolean dumpCalculated, boolean dumpPoints, boolean dumpTrPoints, boolean dumpToDraw)
{
printStream.println(indent + "Straight");
super.dump(printStream, indent, dumpCalculated, dumpPoints, dumpTrPoints, dumpToDraw);
}
}