From 131327f5baa87e5c7f82dbeb440c96027ae0fb40 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Sat, 29 Jun 2024 07:42:07 +0200 Subject: [PATCH] Fixed regression problem with rotation setting not working (#2563) --- .../nbp/designer/entities/EntityGroup.java | 2 +- .../entities/cuttable/AbstractCuttable.java | 5 ++- .../entities/cuttable/RectangleTest.java | 37 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java index eb61d436f8..03f6cee76f 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java @@ -277,8 +277,8 @@ public void setRotation(double rotation) { children.forEach(entity -> entity.rotate(center, deltaRotation)); } groupRotation += deltaRotation; - notifyEvent(new EntityEvent(this, EventType.ROTATED)); invalidateBounds(); + notifyEvent(new EntityEvent(this, EventType.ROTATED)); } public final List getAllChildren() { diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/AbstractCuttable.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/AbstractCuttable.java index 880b047239..cc8daa21cd 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/AbstractCuttable.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/cuttable/AbstractCuttable.java @@ -98,8 +98,8 @@ public int getSpindleSpeed() { } @Override - public void setSpindleSpeed(int Speed) { - this.spindleSpeed = Math.abs(Speed); + public void setSpindleSpeed(int speed) { + this.spindleSpeed = Math.abs(speed); notifyEvent(new EntityEvent(this, EventType.SETTINGS_CHANGED)); } @@ -196,6 +196,7 @@ public List getSettings() { EntitySetting.POSITION_Y, EntitySetting.WIDTH, EntitySetting.HEIGHT, + EntitySetting.ROTATION, EntitySetting.CUT_TYPE, EntitySetting.START_DEPTH, EntitySetting.TARGET_DEPTH, diff --git a/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/entities/cuttable/RectangleTest.java b/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/entities/cuttable/RectangleTest.java index 8244f2abda..29781cc1b5 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/entities/cuttable/RectangleTest.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/entities/cuttable/RectangleTest.java @@ -1,9 +1,13 @@ package com.willwinder.ugs.nbp.designer.entities.cuttable; +import com.willwinder.ugs.nbp.designer.entities.EntitySetting; +import com.willwinder.ugs.nbp.designer.entities.EventType; import com.willwinder.ugs.nbp.designer.model.Size; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; -import static org.junit.Assert.*; +import java.util.concurrent.atomic.AtomicBoolean; public class RectangleTest { @@ -15,4 +19,35 @@ public void setSize() { assertEquals(30, rectangle.getSize().getHeight(), 0.1); } + @Test + public void setRotation() { + Rectangle rectangle = new Rectangle(1, 1); + assertEquals(0, rectangle.getRotation(), 0.1); + rectangle.setRotation(10); + assertEquals(10, rectangle.getRotation(), 0.1); + } + + @Test + public void setRotationShouldDispatchRotationEvent() { + AtomicBoolean triggeredEvent = new AtomicBoolean(false); + Rectangle rectangle = new Rectangle(1, 1); + rectangle.addListener(entityEvent -> { + if (entityEvent.getType() == EventType.ROTATED) { + triggeredEvent.set(true); + } + }); + rectangle.setRotation(10); + assertTrue(triggeredEvent.get()); + } + + @Test + public void getSettings() { + Rectangle rectangle = new Rectangle(1, 1); + assertTrue(rectangle.getSettings().contains(EntitySetting.ANCHOR)); + assertTrue(rectangle.getSettings().contains(EntitySetting.WIDTH)); + assertTrue(rectangle.getSettings().contains(EntitySetting.HEIGHT)); + assertTrue(rectangle.getSettings().contains(EntitySetting.POSITION_X)); + assertTrue(rectangle.getSettings().contains(EntitySetting.POSITION_Y)); + assertTrue(rectangle.getSettings().contains(EntitySetting.ROTATION)); + } } \ No newline at end of file