diff --git a/src/org/nschmidt/ldparteditor/data/DatFile.java b/src/org/nschmidt/ldparteditor/data/DatFile.java index 18d316aea..d4f2bedc5 100644 --- a/src/org/nschmidt/ldparteditor/data/DatFile.java +++ b/src/org/nschmidt/ldparteditor/data/DatFile.java @@ -46,6 +46,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of import org.nschmidt.ldparteditor.data.colour.GCChrome; import org.nschmidt.ldparteditor.data.colour.GCMatteMetal; import org.nschmidt.ldparteditor.data.colour.GCMetal; +import org.nschmidt.ldparteditor.enums.Axis; import org.nschmidt.ldparteditor.enums.MyLanguage; import org.nschmidt.ldparteditor.enums.View; import org.nschmidt.ldparteditor.helpers.composite3d.ViewIdleManager; @@ -650,8 +651,8 @@ public void parseForErrorAndData(StyledText compositeText, int startOffset_pos, g = g.next; } if (validState) { - - if (getVertexManager().isFlat((GData1) g)) { + final Axis flatAxis; + if ((flatAxis = getVertexManager().isFlatOnAxis((GData1) g)) != Axis.NONE) { position = compositeText.getOffsetAtLine(lineNumber - 1); Object[] messageArguments = {lineNumber, position}; MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$ @@ -661,7 +662,21 @@ public void parseForErrorAndData(StyledText compositeText, int startOffset_pos, TreeItem trtmNewTreeitem = new TreeItem(errors, SWT.NONE); trtmNewTreeitem.setImage(ResourceManager.getImage("icon16_error.png")); //$NON-NLS-1$ trtmNewTreeitem.setVisible(false); - trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0D] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + switch (flatAxis) { + case X: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0A] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case Y: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0B] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case Z: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0C] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case NONE: + default: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0D] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + } trtmNewTreeitem.setData(position); } @@ -827,8 +842,8 @@ public void parseForError(StyledText compositeText, int startOffset_pos, int end g = g.next; } if (validState) { - - if (getVertexManager().isFlat((GData1) g)) { + final Axis flatAxis; + if ((flatAxis = getVertexManager().isFlatOnAxis((GData1) g)) != Axis.NONE) { position = compositeText.getOffsetAtLine(lineNumber - 1); Object[] messageArguments = {lineNumber, position}; MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$ @@ -838,8 +853,21 @@ public void parseForError(StyledText compositeText, int startOffset_pos, int end TreeItem trtmNewTreeitem = new TreeItem(errors, SWT.NONE); trtmNewTreeitem.setImage(ResourceManager.getImage("icon16_error.png")); //$NON-NLS-1$ trtmNewTreeitem.setVisible(false); - trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0D] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ - trtmNewTreeitem.setData(position); + switch (flatAxis) { + case X: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0A] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case Y: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0B] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case Z: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0C] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + case NONE: + default: + trtmNewTreeitem.setText(new String[] { I18n.DATPARSER_InvalidInvertNextFlat, formatter.format(messageArguments), "[E0D] " + I18n.DATPARSER_SyntaxError }); //$NON-NLS-1$ + break; + }trtmNewTreeitem.setData(position); } } else { diff --git a/src/org/nschmidt/ldparteditor/data/GData1.java b/src/org/nschmidt/ldparteditor/data/GData1.java index 9c2c0d54d..9e1cc8f57 100644 --- a/src/org/nschmidt/ldparteditor/data/GData1.java +++ b/src/org/nschmidt/ldparteditor/data/GData1.java @@ -409,6 +409,10 @@ public Matrix getAccurateProductMatrix() { return accurateProductMatrix; } + public String getShortName() { + return shortName; + } + private boolean isNotBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { diff --git a/src/org/nschmidt/ldparteditor/data/VM23FlatSubfileTester.java b/src/org/nschmidt/ldparteditor/data/VM23FlatSubfileTester.java index 45038dbfb..d3ce562fb 100644 --- a/src/org/nschmidt/ldparteditor/data/VM23FlatSubfileTester.java +++ b/src/org/nschmidt/ldparteditor/data/VM23FlatSubfileTester.java @@ -21,6 +21,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector4f; +import org.nschmidt.ldparteditor.enums.Axis; import org.nschmidt.ldparteditor.helpers.math.MathHelper; import org.nschmidt.ldparteditor.i18n.I18n; @@ -29,19 +30,19 @@ class VM23FlatSubfileTester extends VM22TJunctionFixer { protected VM23FlatSubfileTester(DatFile linkedDatFile) { super(linkedDatFile); } - - public boolean isFlat(GData1 ref) { - - if (ref == null) return false; - + + public Axis isFlatOnAxis(GData1 ref) { + + if (ref == null) return Axis.NONE; + Matrix4f tMatrix = (Matrix4f) ref.accurateLocalMatrix.getMatrix4f().invert(); - + boolean plainOnX = true; boolean plainOnY = true; boolean plainOnZ = true; Set verts = lineLinkedToVertices.get(ref); - if (verts == null) return false; + if (verts == null) return Axis.NONE; for (VertexInfo vi : verts) { Vector4f vert = vi.vertex.toVector4f(); vert.setX(vert.x / 1000f); @@ -59,16 +60,24 @@ public boolean isFlat(GData1 ref) { plainOnZ = false; } if (!plainOnX && !plainOnY && !plainOnZ) { - return false; + return Axis.NONE; } } - - return true; + + if (plainOnX) { + return Axis.X; + } else if (plainOnY) { + return Axis.Y; + } else if (plainOnZ) { + return Axis.Z; + } else { + return Axis.NONE; + } } public ArrayList checkForFlatScaling(GData1 ref) { ArrayList result = new ArrayList(); - + Matrix4f tMatrix = (Matrix4f) ref.accurateLocalMatrix.getMatrix4f().invert(); boolean plainOnX = true; diff --git a/src/org/nschmidt/ldparteditor/enums/Axis.java b/src/org/nschmidt/ldparteditor/enums/Axis.java new file mode 100644 index 000000000..4c6117b06 --- /dev/null +++ b/src/org/nschmidt/ldparteditor/enums/Axis.java @@ -0,0 +1,20 @@ +/* MIT - License + +Copyright (c) 2012 - this year, Nils Schmidt + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package org.nschmidt.ldparteditor.enums; + +public enum Axis { + X, Y, Z, NONE +} diff --git a/src/org/nschmidt/ldparteditor/helpers/compositetext/ErrorFixer.java b/src/org/nschmidt/ldparteditor/helpers/compositetext/ErrorFixer.java index 4458a9306..3c0bc5375 100644 --- a/src/org/nschmidt/ldparteditor/helpers/compositetext/ErrorFixer.java +++ b/src/org/nschmidt/ldparteditor/helpers/compositetext/ErrorFixer.java @@ -17,19 +17,25 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of import java.math.BigDecimal; import java.text.MessageFormat; +import java.util.HashSet; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.nschmidt.ldparteditor.data.DatFile; +import org.nschmidt.ldparteditor.data.GData; import org.nschmidt.ldparteditor.data.GData1; +import org.nschmidt.ldparteditor.data.Matrix; import org.nschmidt.ldparteditor.data.Vertex; import org.nschmidt.ldparteditor.data.VertexManager; import org.nschmidt.ldparteditor.enums.MyLanguage; import org.nschmidt.ldparteditor.enums.Threshold; +import org.nschmidt.ldparteditor.enums.View; +import org.nschmidt.ldparteditor.helpers.math.MathHelper; import org.nschmidt.ldparteditor.helpers.math.Vector3d; import org.nschmidt.ldparteditor.i18n.I18n; import org.nschmidt.ldparteditor.logger.NLogger; +import org.nschmidt.ldparteditor.text.DatParser; /** * @author nils @@ -43,6 +49,73 @@ public static String fix(int lineNumber, String sort, String line, String text, case 1: // Duplicated line text = QuickFixer.setLine(lineNumber + 1, "", text); //$NON-NLS-1$ break; + case 10: // INVERTNEXT (Flat subfile) + case 11: + case 12: + { + text = QuickFixer.setLine(lineNumber + 1, "", text); //$NON-NLS-1$ + GData1 subfileToFlip = null; + boolean validState = false; + GData g = datFile.getDrawPerLine_NOCLONE().getValue(lineNumber + 1).getNext(); + while (g != null && g.type() < 2) { + lineNumber++; + if (g.type() == 1) { + validState = true; + break; + } else if (!g.toString().trim().isEmpty()) { + break; + } + g = g.getNext(); + } + if (validState) { + subfileToFlip = (GData1) g; + Matrix m = null; + final Matrix t = subfileToFlip.getAccurateProductMatrix(); + GData1 untransformedSubfile; + StringBuilder colourBuilder = new StringBuilder(); + if (subfileToFlip.colourNumber == -1) { + colourBuilder.append("0x2"); //$NON-NLS-1$ + colourBuilder.append(MathHelper.toHex((int) (255f * subfileToFlip.r)).toUpperCase()); + colourBuilder.append(MathHelper.toHex((int) (255f * subfileToFlip.g)).toUpperCase()); + colourBuilder.append(MathHelper.toHex((int) (255f * subfileToFlip.b)).toUpperCase()); + } else { + colourBuilder.append(subfileToFlip.colourNumber); + } + untransformedSubfile = (GData1) DatParser + .parseLine("1 " + colourBuilder.toString() + " 0 0 0 1 0 0 0 1 0 0 0 1 " + subfileToFlip.getShortName() , 0, 0, 0.5f, 0.5f, 0.5f, 1f, View.DUMMY_REFERENCE, View.ID, View.ACCURATE_ID, datFile, false, //$NON-NLS-1$ //$NON-NLS-2$ + new HashSet(), false).get(0).getGraphicalData(); + switch (s) { + case 10: // INVERTNEXT on X (Flat subfile) + m = new Matrix( + t.M00.negate(), t.M01.negate(), t.M02.negate(), t.M03, + t.M10, t.M11, t.M12, t.M13, + t.M20, t.M21, t.M22, t.M23, + t.M30, t.M31, t.M32, t.M33); + break; + case 11: // INVERTNEXT on Y (Flat subfile) + m = new Matrix( + t.M00, t.M01, t.M02, t.M03, + t.M10.negate(), t.M11.negate(), t.M12.negate(), t.M13, + t.M20, t.M21, t.M22, t.M23, + t.M30, t.M31, t.M32, t.M33); + break; + case 12: // INVERTNEXT on Z (Flat subfile) + m = new Matrix( + t.M00, t.M01, t.M02, t.M03, + t.M10, t.M11, t.M12, t.M13, + t.M20.negate(), t.M21.negate(), t.M22.negate(), t.M23, + t.M30, t.M31, t.M32, t.M33); + break; + } + + GData1 newSubfile = (GData1) DatParser + .parseLine(untransformedSubfile.getTransformedString(m, datFile, false) , datFile.getDrawPerLine_NOCLONE().getKey(subfileToFlip).intValue(), 0, 0.5f, 0.5f, 0.5f, 1f, View.DUMMY_REFERENCE, View.ID, View.ACCURATE_ID, datFile, false, + new HashSet(), false).get(0).getGraphicalData(); + datFile.getVertexManager().remove(untransformedSubfile); + text = QuickFixer.setLine(lineNumber + 1, newSubfile.toString(), text); + } + } + break; case 2: // Singular Matrix { String[] data_segments = line.trim().split(" "); //$NON-NLS-1$ @@ -276,26 +349,26 @@ public static String fix(int lineNumber, String sort, String line, String text, Vector3d.sub(vertexB, vertexC, vertexB); Vector3d.sub(vertexD, vertexC, vertexC); Vector3d.sub(vertexD, new Vector3d(A), vertexD); - - + + boolean pointA, pointC, pointB, pointD; double angle = Vector3d.angle(vertexA, vertexD); double sumAngle = angle; pointA = angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum; - + angle = Vector3d.angle(vertexB, vertexC); sumAngle = sumAngle + angle; pointC = angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum; - + vertexA.negate(); vertexB.negate(); angle = Vector3d.angle(vertexA, vertexB); sumAngle = sumAngle + angle; pointB = angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum; - + angle = 360.0 - sumAngle; pointD = angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum; - + VertexManager vm = datFile.getVertexManager(); if (pointA && (pointC || pointB || pointD) || pointC && (pointB || pointD) || pointB && pointD) {