Skip to content

Commit

Permalink
Prepared fix for issue #614.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Dec 24, 2017
1 parent 6ed3959 commit f788679
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 20 deletions.
48 changes: 35 additions & 13 deletions src/org/nschmidt/ldparteditor/data/VM28SlantingMatrixProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected VM28SlantingMatrixProjector(DatFile linkedDatFile) {
private static Vertex[] axis3 = null;
private static int axisSelectionMode = -1;
private static boolean movingOriginToAxisCenter = false;
private static boolean resettingSubfileTransformation = false;

private static Matrix transformation = View.ACCURATE_ID;

Expand Down Expand Up @@ -121,20 +122,30 @@ public String getSlantingMatrixProjectorStatusString() {

public SlantingMatrixStatus getSlantingMatrixStatus() {
if (axis1 == null) {
return ""; //$NON-NLS-1$
return SlantingMatrixStatus.INIT;
} else {
switch (axisSelectionMode) {
case 0: // X,Y,Z
return I18n.SLANT_MatrixForXYZ;
case 1: // X,Y
return I18n.SLANT_MatrixForXY;
case 2: // X,Z
return I18n.SLANT_MatrixForXZ;
case 3: // Y,Z
return I18n.SLANT_MatrixForYZ;
default:
return ""; //$NON-NLS-1$
}
final boolean hasSelection =
selectedVertices.size() > 0 ||
selectedSubfiles.size() > 0 ||
selectedLines.size() > 0 ||
selectedTriangles.size() > 0 ||
selectedQuads.size() > 0 ||
selectedCondlines.size() > 0;

if (hasSelection) {
return SlantingMatrixStatus.SELECTION;
}

switch (axisSelectionMode) {
case 0: // X,Y,Z
return SlantingMatrixStatus.NO_SELECTION_THREE_AXIS;
case 1: // X,Y
case 2: // X,Z
case 3: // Y,Z
return SlantingMatrixStatus.NO_SELECTION_TWO_AXIS;
default:
return SlantingMatrixStatus.INIT;
}
}
}

Expand Down Expand Up @@ -193,6 +204,9 @@ public Matrix getSlantingMatrix(boolean originToAxisCenter) {

if (axis3 == null) {
mz = Vector3d.cross(nmx, nmy);
if (Vector3d.distSquare(new Vector3d(), mz).compareTo(BigDecimal.ZERO) > 0) {
mz.normalise(mz);
}
} else {
BigDecimal dXZ0 = Vector3d.distSquare(zref, new Vector3d(axis3[0]));
BigDecimal dXZ1 = Vector3d.distSquare(zref, new Vector3d(axis3[1]));
Expand Down Expand Up @@ -295,4 +309,12 @@ public static boolean isMovingOriginToAxisCenter() {
public static void setMovingOriginToAxisCenter(boolean movingOriginToAxisCenter) {
VM28SlantingMatrixProjector.movingOriginToAxisCenter = movingOriginToAxisCenter;
}

public static boolean isResettingSubfileTransformation() {
return resettingSubfileTransformation;
}

public static void setResettingSubfileTransformation(boolean resettingSubfileTransformation) {
VM28SlantingMatrixProjector.resettingSubfileTransformation = resettingSubfileTransformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package org.nschmidt.ldparteditor.dialogs.slantingmatrixprojector;

import java.math.BigDecimal;
import java.text.DecimalFormatSymbols;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
Expand All @@ -25,8 +28,14 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.nschmidt.ldparteditor.data.Matrix;
import org.nschmidt.ldparteditor.data.VertexManager;
import org.nschmidt.ldparteditor.enums.Font;
import org.nschmidt.ldparteditor.enums.MyLanguage;
import org.nschmidt.ldparteditor.enums.View;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.widgets.NButton;

/**
* The SlantingMatrixProjector dialog
Expand All @@ -41,6 +50,7 @@ class SlantingMatrixProjectorDesign extends Dialog {

// Use final only for subclass/listener references!
final VertexManager vm;
private java.text.DecimalFormat numberFormat = new java.text.DecimalFormat(View.NUMBER_FORMATL4F, new DecimalFormatSymbols(MyLanguage.LOCALE));

SlantingMatrixProjectorDesign(Shell parentShell, VertexManager vm) {
super(parentShell);
Expand All @@ -55,28 +65,88 @@ class SlantingMatrixProjectorDesign extends Dialog {
@Override
protected Control createDialogArea(Composite parent) {
Composite cmp_container = (Composite) super.createDialogArea(parent);
cmp_container.setLayout(new GridLayout(4, true));
GridLayout gridLayout = (GridLayout) cmp_container.getLayout();
gridLayout.verticalSpacing = 10;
gridLayout.horizontalSpacing = 10;

Label lbl_title = new Label(cmp_container, SWT.NONE);
lbl_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
lbl_title.setText(I18n.SLANT_Title);

Label lbl_separator = new Label(cmp_container, SWT.SEPARATOR | SWT.HORIZONTAL);
lbl_separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lbl_separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));

Label lbl_info = new Label(cmp_container, SWT.NONE);
lbl_info.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lbl_info.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));

switch (vm.getSlantingMatrixStatus()) {

case NO_SELECTION_THREE_AXIS:
lbl_info.setText(I18n.SLANT_NoSelectionThreeAxes);
insertMatrix(cmp_container);
break;
case NO_SELECTION_TWO_AXIS:
lbl_info.setText(I18n.SLANT_NoSelectionTwoAxes);
insertMatrix(cmp_container);
break;
case SELECTION:
lbl_info.setText(I18n.SLANT_MatrixReady);
insertMatrix(cmp_container);
NButton cb_setOrigin = new NButton(cmp_container, SWT.CHECK);
cb_setOrigin.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
cb_setOrigin.setText(I18n.SLANT_SetOrigin);
cb_setOrigin.setSelection(VertexManager.isMovingOriginToAxisCenter());

NButton cb_resetSubfileOrientation = new NButton(cmp_container, SWT.CHECK);
cb_resetSubfileOrientation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
cb_resetSubfileOrientation.setText(I18n.SLANT_ResetSubfileOrientation);
cb_resetSubfileOrientation.setSelection(VertexManager.isResettingSubfileTransformation());
break;
case INIT:
default:
lbl_info.setText(I18n.SLANT_HowTo);
break;
}
lbl_info.setText(I18n.SLANT_HowTo);

cmp_container.pack();
return cmp_container;
}

private void insertMatrix(Composite cmp_container) {
// TODO Auto-generated method stub

Matrix M = vm.getSlantingMatrix(VertexManager.isMovingOriginToAxisCenter());

insertMatrixCell(cmp_container, M.M00);
insertMatrixCell(cmp_container, M.M10);
insertMatrixCell(cmp_container, M.M20);
insertMatrixCell(cmp_container, M.M30);
insertMatrixCell(cmp_container, M.M01);
insertMatrixCell(cmp_container, M.M11);
insertMatrixCell(cmp_container, M.M21);
insertMatrixCell(cmp_container, M.M31);
insertMatrixCell(cmp_container, M.M02);
insertMatrixCell(cmp_container, M.M12);
insertMatrixCell(cmp_container, M.M22);
insertMatrixCell(cmp_container, M.M32);
insertMatrixCell(cmp_container, BigDecimal.ZERO);
insertMatrixCell(cmp_container, BigDecimal.ZERO);
insertMatrixCell(cmp_container, BigDecimal.ZERO);
insertMatrixCell(cmp_container, BigDecimal.ONE);

NButton btn_CopyMatrixToClipboard = new NButton(cmp_container, SWT.NONE);
btn_CopyMatrixToClipboard.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
btn_CopyMatrixToClipboard.setText(I18n.SLANT_CopyToClipboard);
}

private void insertMatrixCell(Composite cmp_container, BigDecimal val) {
Text txt_Cell = new Text(cmp_container, SWT.NONE);
txt_Cell.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
txt_Cell.setText(numberFormat.format(val));
txt_Cell.setFont(Font.MONOSPACE);
txt_Cell.setEditable(false);
}

/**
* Create contents of the button bar.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
package org.nschmidt.ldparteditor.enums;

public enum SlantingMatrixStatus {

INIT, NO_SELECTION_TWO_AXIS, NO_SELECTION_THREE_AXIS, SELECTION
}
2 changes: 1 addition & 1 deletion src/org/nschmidt/ldparteditor/enums/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public enum View {
/** The standard decimal format for floating point numbers (8 digits) */
public static final String NUMBER_FORMAT8F = "###,##0.00000000;-###,##0.00000000"; //$NON-NLS-1$
/** The decimal format for floating point numbers with four leading zeros (4 digits) */
public static final String NUMBER_FORMATL4F = "###,##0000.0000;-###,##0000.0000"; //$NON-NLS-1$
public static final String NUMBER_FORMATL4F = " ###,##0000.0000;-###,##0000.0000"; //$NON-NLS-1$

public final static GColour RANDOM_COLOUR = new GColour(-1, 1f, 1f, 1f, 0f);

Expand Down
4 changes: 4 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,12 +1133,16 @@ private static void adjust() { // Calculate line offset
public static final String SEARCH_ReplaceWith = SEARCH.getString(getProperty());
public static final String SEARCH_Scope = SEARCH.getString(getProperty());
public static final String SEARCH_SelectedLines = SEARCH.getString(getProperty());
public static final String SLANT_CopyToClipboard = SLANT.getString(getProperty());
public static final String SLANT_HowTo = SLANT.getString(getProperty());
public static final String SLANT_MatrixForXY = SLANT.getString(getProperty());
public static final String SLANT_MatrixForXYZ = SLANT.getString(getProperty());
public static final String SLANT_MatrixForXZ = SLANT.getString(getProperty());
public static final String SLANT_MatrixForYZ = SLANT.getString(getProperty());
public static final String SLANT_MatrixReady = SLANT.getString(getProperty());
public static final String SLANT_NoSelectionThreeAxes = SLANT.getString(getProperty());
public static final String SLANT_NoSelectionTwoAxes = SLANT.getString(getProperty());
public static final String SLANT_ResetSubfileOrientation = SLANT.getString(getProperty());
public static final String SLANT_SetOrigin = SLANT.getString(getProperty());
public static final String SLANT_Title = SLANT.getString(getProperty());
public static final String SLICERPRO_Hint = SLICERPRO.getString(getProperty());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CopyToClipboard = Copy matrix to clipboard

HowTo = There are two possibilies to use this tool:\n\na) Two-line variant\n\n\t1. Create two lines with one common vertex.\n\t\tExample A: (red line = X axis, blue line = Z axis)\n\t\t\t2 4 0 0 0 1 0 0\n\t\t\t2 1 0 0 0 0 0 1\n\t\tExample B: (red line = X axis, green line = Y axis)\n\t\t\t2 4 0 0 0 1 0 0\n\t\t\t2 2 0 0 0 0 1 0\n\n\t2. Select only these two lines in the 3D editor (LDPE will automatically calculate the matrix)\n\n\t3. Select the element(s) which should be changed and open this tool again.\n\na) Three-line variant\n\n\t1. Create three lines with one common vertex. One red line for the X axis, one green line for the Y axis, and one blue line for the Z axis.\n\t\tExample:\n\t\t\t2 4 0 0 0 1 0 0\n\t\t\t2 2 0 0 0 0 1 0\n\t\t\t2 1 0 0 0 0 0 1\n\n\t2. Select only these three lines in the 3D editor (LDPE will automatically calculate the matrix)\n\n\t3. Select the element(s) which should be changed and open this tool again.

MatrixForXY = Calculated slant matrix for X and Y (press ESC to cancel).
Expand All @@ -10,9 +12,11 @@ MatrixForYZ = Calculated slant matrix for Y and Z (press ESC to cancel).

MatrixReady = The following matrix will be applied to your selection:

NoSelectionThreeAxes = You haven't selected anything, but the following matrix is calculated based on three axes:
NoSelectionTwoAxes = You haven't selected anything, but the following matrix is calculated based on two axes:

NoSelectionThreeAxes = You haven't selected anything, but the following matrix is calculated based on three axes:
ResetSubfileOrientation = Reset subfile orientation

SetOrigin = Set origin to center of the first axis pair (useful for rect-primitives)

Expand Down

0 comments on commit f788679

Please sign in to comment.