Skip to content

Commit

Permalink
Prepared fix for issue #1039.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Aug 4, 2024
1 parent 2febdf1 commit fdcb0fe
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 1 deletion.
173 changes: 173 additions & 0 deletions icons/svg/primSub.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/Editor3D.properties
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ POSITION_Z4 = Position 4, Z [LDU]:
PREVIOUS = Previous
PREVIOUS_ITEM = Previous Item
PRIMGEN2 = PrimGen2
PRIMITIVE_CURVE_QUALITY = Curve quality:
PROTRACTOR_ANGLE = Protractor Angle [Degree]:
PROTRACTOR_LENGTH = Protractor / Distance Length [LDU]:
PROTRACTOR_LENGTH_MM = Protractor / Distance Length [mm]:
Expand Down Expand Up @@ -325,6 +326,7 @@ THRESH_IN_LDU = Threshold in LDU, range from 0 to 1000.\nC
T_JUNCTION = TJunctionFinder
T_JUNCTION_COUNT = Found {0} T-Junctions on edges.
TOGGLE_BFC = Toggle BFC Winding (for new surfaces)
TOGGLE_PRIMITIVE_SUBSTITUTION = Toggle Primitive Substitution
TOGGLE_TRANSPARENT = Toggle Selection through transparent Subfiles/Objects
TOOLS = Tools\u2026
TOOLS_OPTIONS = Tools and Options
Expand Down
2 changes: 2 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ private static void adjust() { // Calculate line offset
public static final String E3D_PREVIOUS = E3D.getString(getProperty());
public static final String E3D_PREVIOUS_ITEM = E3D.getString(getProperty());
public static final String E3D_PRIMGEN2 = E3D.getString(getProperty());
public static final String E3D_PRIMITIVE_CURVE_QUALITY = E3D.getString(getProperty());
public static final String E3D_PROTRACTOR_ANGLE = E3D.getString(getProperty());
public static final String E3D_PROTRACTOR_LENGTH = E3D.getString(getProperty());
public static final String E3D_PROTRACTOR_LENGTH_MM = E3D.getString(getProperty());
Expand Down Expand Up @@ -739,6 +740,7 @@ private static void adjust() { // Calculate line offset
public static final String E3D_THRESH_IN_DEG = E3D.getString(getProperty());
public static final String E3D_THRESH_IN_LDU = E3D.getString(getProperty());
public static final String E3D_TOGGLE_BFC = E3D.getString(getProperty());
public static final String E3D_TOGGLE_PRIMITIVE_SUBSTITUTION = E3D.getString(getProperty());
public static final String E3D_TOGGLE_TRANSPARENT = E3D.getString(getProperty());
public static final String E3D_TOOLS = E3D.getString(getProperty());
public static final String E3D_TOOLS_OPTIONS = E3D.getString(getProperty());
Expand Down
2 changes: 1 addition & 1 deletion src/org/nschmidt/ldparteditor/opengl/OpenGLRenderer20.java
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@ private void drawGrid3D(float gridSize, final float gridSize10, final float grid
// X
float step = -gridSize20;
if (bgColour) {
GL11.glColor3f(Colour.backgroundColourR, Colour.backgroundColourG, Colour.backgroundColourB);
GL11.glColor4f(Colour.backgroundColourR, Colour.backgroundColourG, Colour.backgroundColourB, .5f);
} else {
GL11.glColor3f(Colour.manipulatorXAxisColourR, Colour.manipulatorXAxisColourG, Colour.manipulatorXAxisColourB);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,33 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

import static org.nschmidt.ldparteditor.helper.WidgetUtility.widgetUtil;

import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.nschmidt.ldparteditor.composite.ToolItem;
import org.nschmidt.ldparteditor.dialog.value.ValueDialogInt;
import org.nschmidt.ldparteditor.enumtype.Task;
import org.nschmidt.ldparteditor.helper.Cocoa;
import org.nschmidt.ldparteditor.helper.composite3d.GuiStatusManager;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.resource.ResourceManager;
import org.nschmidt.ldparteditor.shell.editor3d.Editor3DWindow;
import org.nschmidt.ldparteditor.state.KeyStateManager;
import org.nschmidt.ldparteditor.text.PrimitiveReplacer;
import org.nschmidt.ldparteditor.widget.NButton;
import org.nschmidt.ldparteditor.workbench.WorkbenchManager;

public class MiscToggleToolItem extends ToolItem {

private static final NButton[] btnMoveAdjacentDataPtr = new NButton[1];
private static final NButton[] btnNoTransparentSelectionPtr = new NButton[1];
private static final NButton[] btnPrimitiveSubstitutionPtr = new NButton[1];
private static final NButton[] btnBFCTogglePtr = new NButton[1];

private static boolean movingAdjacentData = WorkbenchManager.getUserSettingState().isMovingAdjacentData();
private static boolean noTransparentSelection = false;
private static boolean bfcToggle = false;
private static boolean substitutingPrimitives = false;

public MiscToggleToolItem(Composite parent, int style, boolean isHorizontal) {
super(parent, style, isHorizontal);
Expand Down Expand Up @@ -78,6 +83,10 @@ public static void setBfcToggle(boolean bfcToggle) {
MiscToggleToolItem.bfcToggle = bfcToggle;
}

public static boolean isSubstitutingPrimitives() {
return substitutingPrimitives;
}

private static void createWidgets(MiscToggleToolItem miscToggleToolItem) {
NButton btnAdjacentMove = new NButton(miscToggleToolItem, SWT.TOGGLE | Cocoa.getStyle());
btnMoveAdjacentDataPtr[0] = btnAdjacentMove;
Expand All @@ -90,6 +99,13 @@ private static void createWidgets(MiscToggleToolItem miscToggleToolItem) {
btnTransSelection.setToolTipText(I18n.E3D_TOGGLE_TRANSPARENT);
btnTransSelection.setImage(ResourceManager.getImage("icon16_notrans.png")); //$NON-NLS-1$

NButton btnPrimitiveSubstitution = new NButton(miscToggleToolItem, SWT.TOGGLE | Cocoa.getStyle());
btnPrimitiveSubstitutionPtr[0] = btnPrimitiveSubstitution;
btnPrimitiveSubstitution.setToolTipText(I18n.E3D_TOGGLE_PRIMITIVE_SUBSTITUTION + Cocoa.replaceCtrlByCmd(I18n.E3D_CONTROL_CLICK_MODIFY));
btnPrimitiveSubstitution.setImage(ResourceManager.getImage("icon16_primSub.png")); //$NON-NLS-1$
substitutingPrimitives = WorkbenchManager.getUserSettingState().isSubstitutingPrimitives();
btnPrimitiveSubstitution.setSelection(substitutingPrimitives);

NButton btnBFCToggle = new NButton(miscToggleToolItem, SWT.TOGGLE | Cocoa.getStyle());
btnBFCTogglePtr[0] = btnBFCToggle;
btnBFCToggle.setToolTipText(I18n.E3D_TOGGLE_BFC);
Expand All @@ -111,6 +127,40 @@ private static void addListeners() {
Editor3DWindow.getWindow().initAllRenderers();
regainFocus();
});
widgetUtil(btnPrimitiveSubstitutionPtr[0]).addSelectionListener(e -> {
substitutingPrimitives = btnPrimitiveSubstitutionPtr[0].getSelection();
WorkbenchManager.getUserSettingState().setSubstitutingPrimitives(substitutingPrimitives);
PrimitiveReplacer.clearCache();
if (Cocoa.checkCtrlOrCmdPressed(e.stateMask)) {
final int[] quality = new int[1];
if (new ValueDialogInt(Editor3DWindow.getWindow().getShell(), I18n.E3D_PRIMITIVE_CURVE_QUALITY, "") { //$NON-NLS-1$

@Override
public void initializeSpinner() {
this.spnValuePtr[0].setMinimum(0);
this.spnValuePtr[0].setMaximum(96);
this.spnValuePtr[0].setValue(WorkbenchManager.getUserSettingState().getPrimitiveSubstitutionQuality());
}

@Override
public void applyValue() {
quality[0] = this.spnValuePtr[0].getValue();
}
}.open() == Window.OK) {
int resultingQuality = Math.clamp((quality[0] - quality[0] % 8), 8, 96);
WorkbenchManager.getUserSettingState().setPrimitiveSubstitutionQuality(resultingQuality);
substitutingPrimitives = true;
WorkbenchManager.getUserSettingState().setSubstitutingPrimitives(substitutingPrimitives);
btnPrimitiveSubstitutionPtr[0].setSelection(true);
}
}

// Recompile
Editor3DWindow.getWindow().compileAll(true);
// Re-initialise the renderer
Editor3DWindow.getWindow().initAllRenderers();
regainFocus();
});
widgetUtil(btnBFCTogglePtr[0]).addSelectionListener(e -> {
setBfcToggle(btnBFCTogglePtr[0].getSelection());
regainFocus();
Expand Down
29 changes: 29 additions & 0 deletions src/org/nschmidt/ldparteditor/text/PrimitiveReplacer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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.text;

import java.util.HashMap;
import java.util.Map;

public enum PrimitiveReplacer {
INSTANCE;

private static final Map<String, String> GENERATED_PRIMITIVES_CACHE = new HashMap<>();

public static void clearCache() {
GENERATED_PRIMITIVES_CACHE.clear();
}
}
20 changes: 20 additions & 0 deletions src/org/nschmidt/ldparteditor/workbench/UserSettingState.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ public class UserSettingState implements Serializable {

private boolean drawLinesOpenGL = false;

private boolean substitutingPrimitives = false;

private int primitiveSubstitutionQuality = 56;

public UserSettingState() {
this.getUserPalette().add(new GColour(0, 0.02f, 0.075f, 0.114f, 1f));

Expand Down Expand Up @@ -1541,4 +1545,20 @@ public boolean isDrawLinesOpenGL() {
public void setDrawLinesOpenGL(boolean drawLinesOpenGL) {
this.drawLinesOpenGL = drawLinesOpenGL;
}

public boolean isSubstitutingPrimitives() {
return substitutingPrimitives;
}

public void setSubstitutingPrimitives(boolean substitutingPrimitives) {
this.substitutingPrimitives = substitutingPrimitives;
}

public int getPrimitiveSubstitutionQuality() {
return primitiveSubstitutionQuality;
}

public void setPrimitiveSubstitutionQuality(int primitiveSubstitutionQuality) {
this.primitiveSubstitutionQuality = primitiveSubstitutionQuality;
}
}
9 changes: 9 additions & 0 deletions src/org/nschmidt/ldparteditor/workbench/WorkbenchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ public static boolean loadWorkbench(String path) {
WorkbenchManager.userSettingState.setPartReview3dViewCount(4);
}


WorkbenchManager.userSettingState.setPartReview3dViewCount(Math.clamp(WorkbenchManager.userSettingState.getPartReview3dViewCount(), 1, 4));

int primSubQuality = WorkbenchManager.userSettingState.getPrimitiveSubstitutionQuality();
if (primSubQuality <= 0) {
// 56 is LDView's default quality. It will affect normal and hi-res primitives.
primSubQuality = 56;
}

WorkbenchManager.userSettingState.setPrimitiveSubstitutionQuality(Math.clamp((primSubQuality - primSubQuality % 8), 8, 96));

Threshold.coplanarityAngleWarning = WorkbenchManager.userSettingState.getCoplanarityAngleWarning();
Threshold.coplanarityAngleError = WorkbenchManager.userSettingState.getCoplanarityAngleError();

Expand Down

0 comments on commit fdcb0fe

Please sign in to comment.