Skip to content

Commit

Permalink
Prepared fix for issue #1028.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed May 29, 2024
1 parent 3bbde8f commit 56fbc36
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 9 deletions.
107 changes: 107 additions & 0 deletions src/org/nschmidt/ldparteditor/dialog/selectgdata/SelectionDesign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* 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.dialog.selectgdata;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.resource.ResourceManager;
import org.nschmidt.ldparteditor.widget.Tree;
import org.nschmidt.ldparteditor.widget.TreeColumn;
import org.nschmidt.ldparteditor.widget.TreeItem;

/**
* The data selection dialog
* <p>
* Note: This class should not be instantiated, it defines the gui layout and no
* business logic.
*/
class SelectionDesign<T> extends Dialog {

final String title;
final List<T> selectionData = new ArrayList<>();
final Tree[] treePtr = new Tree[1];

// Use final only for subclass/listener references!

SelectionDesign(Shell parentShell, String title) {
super(parentShell);
this.title = title;
}

/**
* Create contents of the dialog.
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite cmpContainer = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) cmpContainer.getLayout();
gridLayout.verticalSpacing = 5;
gridLayout.horizontalSpacing = 10;

Label lblSpecify = new Label(cmpContainer, SWT.NONE);
lblSpecify.setText(title);

Label lblSeparator = new Label(cmpContainer, SWT.SEPARATOR | SWT.HORIZONTAL);
lblSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

final Tree tree = new Tree(cmpContainer, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL, selectionData.size());
this.treePtr[0] = tree;

tree.setLinesVisible(true);
tree.setHeaderVisible(true);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

TreeColumn trclmnDescription = new TreeColumn(tree, SWT.NONE);
trclmnDescription.setWidth(598);
trclmnDescription.setText(I18n.E3D_DESCRIPTION);

for (T item : selectionData) {
TreeItem trtmEditor3D = new TreeItem(tree);
trtmEditor3D.setImage(ResourceManager.getImage("icon16_primitives.png")); //$NON-NLS-1$
trtmEditor3D.setText(new String[] { item.toString() });
trtmEditor3D.setVisible(true);
trtmEditor3D.setData(item);
}

tree.build();
cmpContainer.pack();
return cmpContainer;
}

/**
* Create contents of the button bar.
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, I18n.DIALOG_OK, false);
createButton(parent, IDialogConstants.CANCEL_ID, I18n.DIALOG_CANCEL, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* 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.dialog.selectgdata;

import java.util.Collection;
import org.eclipse.swt.widgets.Shell;
import org.nschmidt.ldparteditor.logger.NLogger;

/**
*
* <p>
* Note: This class should be instantiated, it defines all listeners and part of
* the business logic. It overrides the {@code open()} method to invoke the
* listener definitions ;)
*/
public class SelectionDialog<T> extends SelectionDesign<T> {

private T selection;

/**
* Create the dialog.
*
* @param parentShell
*/
public SelectionDialog(Shell parentShell, String title) {
super(parentShell, title);
}

@SuppressWarnings("unchecked")
@Override
public int open() {
super.create();
// MARK All final listeners will be configured here..
treePtr[0].addSelectionListener(ev -> {
selection = (T) treePtr[0].getSelection()[0].getData();
NLogger.debug(SelectionDialog.class, "Selected data: {0}", selection); //$NON-NLS-1$
});
return super.open();
}

public void addData(Collection<T> selection) {
selectionData.addAll(selection);
}

public T getSelection() {
return selection;
}
}
3 changes: 3 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/Editor3D.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CREATE_TRANSFORMED_COPY = Create Copy
CSG_OPTIMISATION = CSG optimisation rate:
DECOLOUR = Decolour Part
DELETE_CONFIG = Are you sure to delete your program settings on the next start?
DESCRIPTION = Object Description
DISTRIBUTE_BOTTOM_EDGES = Distribute Bottom Edges
DISTRIBUTE_HORIZONTALLY = Distribute Horizontally
DISTRIBUTE_HORIZONTAL_CENTERS = Distribute Horizontal Centers
Expand Down Expand Up @@ -270,6 +271,8 @@ SEARCH = Search
SEARCH_PRIMITIVES = Search Primitives
SELECT = Select
SELECT_LDCONFIG = Select ldconfig.ldr
SELECT_REFERENCE_OBJECT_LINE = Select the reference object (for the intersection point of two lines):
SELECT_REFERENCE_OBJECT_SUBFILE = Select the reference object (for moving subfiles to the manipulator):
SELECT_VERTEX = Select Single Vertex
SELECTION = Selection:
SET_ACCURACY = Set accuracy:
Expand Down
3 changes: 3 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ private static void adjust() { // Calculate line offset
public static final String E3D_CSG_OPTIMISATION = E3D.getString(getProperty());
public static final String E3D_DECOLOUR = E3D.getString(getProperty());
public static final String E3D_DELETE_CONFIG = E3D.getString(getProperty());
public static final String E3D_DESCRIPTION = E3D.getString(getProperty());
public static final String E3D_DISTRIBUTE_BOTTOM_EDGES = E3D.getString(getProperty());
public static final String E3D_DISTRIBUTE_HORIZONTALLY = E3D.getString(getProperty());
public static final String E3D_DISTRIBUTE_HORIZONTAL_CENTERS = E3D.getString(getProperty());
Expand Down Expand Up @@ -679,6 +680,8 @@ private static void adjust() { // Calculate line offset
public static final String E3D_SELECT = E3D.getString(getProperty());
public static final String E3D_SELECTION = E3D.getString(getProperty());
public static final String E3D_SELECT_LDCONFIG = E3D.getString(getProperty());
public static final String E3D_SELECT_REFERENCE_OBJECT_LINE = E3D.getString(getProperty());
public static final String E3D_SELECT_REFERENCE_OBJECT_SUBFILE = E3D.getString(getProperty());
public static final String E3D_SELECT_VERTEX = E3D.getString(getProperty());
public static final String E3D_SET_ACCURACY = E3D.getString(getProperty());
public static final String E3D_SET_ICON_SIZE = E3D.getString(getProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.math.BigDecimal;
import java.util.Set;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
Expand All @@ -16,10 +17,12 @@
import org.lwjgl.util.vector.Vector4f;
import org.nschmidt.ldparteditor.composite.Composite3D;
import org.nschmidt.ldparteditor.composite.ToolItem;
import org.nschmidt.ldparteditor.data.DatFile;
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.dialog.selectgdata.SelectionDialog;
import org.nschmidt.ldparteditor.enumtype.Task;
import org.nschmidt.ldparteditor.helper.Cocoa;
import org.nschmidt.ldparteditor.helper.Manipulator;
Expand Down Expand Up @@ -510,31 +513,46 @@ public static void mntmManipulatorToSubfile() {
}

public static void mntmManipulatorSubfileTo(boolean resetScale) {
if (Project.getFileToEdit() != null) {
VertexManager vm = Project.getFileToEdit().getVertexManager();
final DatFile df = Project.getFileToEdit();
if (df != null) {
final VertexManager vm = df.getVertexManager();
Set<GData1> subfiles = vm.getSelectedSubfiles();
if (!subfiles.isEmpty()) {
final SelectionDialog<GData1> dialog = new SelectionDialog<>(Editor3DWindow.getWindow().getShell(), I18n.E3D_SELECT_REFERENCE_OBJECT_SUBFILE);
dialog.addData(subfiles.stream().filter(s -> vm.getLineLinkedToVertices().containsKey(s)).sorted(
(a,b) -> Integer.compare(df.getDrawPerLineNoClone().getKey(a), df.getDrawPerLineNoClone().getKey(b))
).toList());
GData1 subfile = null;
for (GData1 g1 : subfiles) {
if (vm.getLineLinkedToVertices().containsKey(g1)) {
subfile = g1;
break;
if (subfiles.size() > 1) {
if (dialog.open() == IDialogConstants.OK_ID) {
subfile = dialog.getSelection();
} else {
return;
}
} else {
for (GData1 g1 : subfiles) {
if (vm.getLineLinkedToVertices().containsKey(g1)) {
subfile = g1;
break;
}
}
}

if (subfile == null) {
return;
}

for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) {
Composite3D c3d = renderer.getC3D();
if (c3d.getLockableDatFileReference().equals(Project.getFileToEdit())) {
vm.addSnapshot();
vm.backupHideShowState();
Manipulator ma = c3d.getManipulator();
Matrix ma = c3d.getManipulator().getAccurateMatrix();
if (resetScale) {
vm.transformSubfile(subfile, ma.getAccurateMatrix(), true, true);
vm.transformSubfile(subfile, ma, true, true);
} else {
vm.transformSubfile(subfile, Matrix.mul(
ma.getAccurateMatrix(),
ma,
MatrixOperations.removeRotationAndTranslation(subfile.getAccurateProductMatrix())), true, true);
}
break;
Expand Down
11 changes: 11 additions & 0 deletions test/moveToManipulator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
0 Move to manipulator test
0 Name: new.dat
0 Author: Nils Schmidt [BlackBrick89]
0 !LDRAW_ORG Unofficial_Part
0 !LICENSE Licensed under CC BY 4.0 : see CAreadme.txt

0 BFC CERTIFY CCW

1 4 -7.70209 29.6 -10 0 0 -1.34 1.34 0 0 0 1 0 1-4chrd.dat
1 2 -7.70209 29.6 -10 0 0 1.34 -1.34 0 0 0 1 0 1-4chrd.dat
1 1 -7.70209 29.6 -10 0 0 -1.34 -1.34 0 0 0 1 0 1-4chrd.dat

0 comments on commit 56fbc36

Please sign in to comment.