diff --git a/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java index d180ff18a..46cee2bad 100644 --- a/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java @@ -1668,8 +1668,11 @@ public class Presenter implements IPlugInPort { // messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED, // selectionRect); } else if (instantiationManager.getComponentSlot() != null) { + // a component dragged in from the component tree or the toolbox this.previousScaledPoint = scalePoint(point); - instantiationManager.updateSingleClick(previousScaledPoint, isSnapToGrid(), currentProject.getGridSpacing()); + updatePlacementMirror(previousScaledPoint); + instantiationManager.updateSingleClick(toPlacementSpace(previousScaledPoint), isSnapToGrid(), + currentProject.getGridSpacing()); } messageDispatcher.dispatchMessage(EventType.REPAINT, false, resizeInProgress); @@ -2086,6 +2089,9 @@ public class Presenter implements IPlugInPort { // calculateSelectionDimension()); } else if (instantiationManager.getComponentSlot() != null) { preDragProject = currentProject.clone(); + if (placementMirrorBoard != null) { + MirrorPlacement.placeOnBottom(instantiationManager.getComponentSlot()); + } addPendingComponentsToProject(scaledPoint, instantiationManager.getComponentTypeSlot(), null, null, preDragProject); } else { updateSelection(selectedComponents); diff --git a/diylc/diylc-swing/src/test/java/org/diylc/PresenterTests.java b/diylc/diylc-swing/src/test/java/org/diylc/PresenterTests.java index 82bac7ac4..a6f35dfc7 100644 --- a/diylc/diylc-swing/src/test/java/org/diylc/PresenterTests.java +++ b/diylc/diylc-swing/src/test/java/org/diylc/PresenterTests.java @@ -368,6 +368,25 @@ public class PresenterTests extends TestBase { Assert.assertTrue(board.getBoardRectangle().contains(eyelet.getControlPoint(0))); } + @Test + public void testDropFromComponentTreeIntoUndersideMirror() { + BlankBoard board = mirroredBoard(); + Rectangle2D region = UndersideMirror.getMirrorRegion(board); + Point inMirror = toScreen(new Point2D.Double(region.getCenterX(), region.getCenterY())); + ComponentType resistorType = presenter.getComponentTypes().get("Passive").stream() + .filter(x -> x.getName().equals("Resistor")).findFirst().get(); + + // what the component tree and the canvas drop target do for a drag and drop + presenter.setNewComponentTypeSlot(resistorType, null, null, true); + presenter.dragOver(inMirror); + presenter.dragEnded(inMirror); + + Assert.assertEquals(2, presenter.getCurrentProject().getComponents().size()); + Resistor resistor = (Resistor) presenter.getCurrentProject().getComponents().get(1); + Assert.assertEquals(PCBLayer._1, resistor.getBoardSide()); + Assert.assertTrue(board.getBoardRectangle().contains(resistor.getControlPoint(0))); + } + // a board with its underside mirror below it, with nothing on it yet private BlankBoard mirroredBoard() { BlankBoard board = new BlankBoard(); diff --git a/diylc/docs/plans/bottom-side-components.md b/diylc/docs/plans/bottom-side-components.md index 22a325e52..66b7ec72e 100644 --- a/diylc/docs/plans/bottom-side-components.md +++ b/diylc/docs/plans/bottom-side-components.md @@ -130,8 +130,9 @@ order. through that mirror, under the cursor. On placement, `MirrorPlacement.placeOnBottom` sets an `IBoardSideComponent` to `_1` (Bottom) and a component with a `PCBLayer` (`setLayer`, found the same way `PCBLayerFilter` reads `getLayer`) to `_1`; nothing is mirrored. Anything else, such as - a jumper, eyelet or wire, is placed at the reflected point unchanged. Dragging a new part from - the component tree onto a mirror still places it in the main view. + a jumper, eyelet or wire, is placed at the reflected point unchanged. A part dragged in from + the component tree or the toolbox goes through `Presenter.dragOver` and `dragEnded` instead, + which pick the mirror and put the part on the bottom the same way. ## 4. Open questions @@ -150,7 +151,7 @@ order. - `MirrorPlacementTest` covers what placing through the mirror changes, and `PresenterTests.testPlaceThroughUndersideMirror` and `testPlaceUnsidedPartThroughUndersideMirror` place a resistor and an eyelet in a mirror and check that they land on the board, the resistor on - the bottom. + the bottom; `testDropFromComponentTreeIntoUndersideMirror` does the same for a drag and drop. - `SilkScreenFilterTest` covers which side's page each part and board outline goes on, and `SilkScreenDrawingProviderTest` checks that the bottom page appears only for a bottom part. - `DrawingManagerTest` checks rendered pixels for a part that reports its own side: a bottom part