diff --git a/data/config/AdecWatt.xml b/data/config/AdecWatt.xml index 5ede553..cca7822 100644 --- a/data/config/AdecWatt.xml +++ b/data/config/AdecWatt.xml @@ -1,78 +1,92 @@ -This file is automaticaly generated by AdecWatt application at 10:39 AM on Apr 17, 2019. +This file is automaticaly generated by AdecWatt application at 7:40 AM on Apr 18, 2019. + true -true -false + + 4 -false + + + data/log/ -true + true -true + true false /home/felix/perso/adecWatt56/data/export/CendresLampionsChapelleBleue.lpz -false + North -true + + + true 0 -0 -true -false + + + + + 1 true 3128 -false -FR + + 5 North -[x=3 200,y=146] + +[x=0,y=31] + false + true -[x=73,y=212] +[x=600,y=665] North -false + Day false -[x=3 200,y=146] -[x=3 200,y=146] +[x=0,y=31] + true false 2 North -false + true -false -false + + -false + true true data/images/adecWatt.png -false -fr + + false North -false -webmestre + + false + false -false -20190417 -false -false +20190418 + + + false true 3 -false -false + + false -[x=3 200,y=146] +[x=0,y=31] false -false + + + North + diff --git a/src/java/adecWatt/model/Item.java b/src/java/adecWatt/model/Item.java index be52d2f..d47e341 100644 --- a/src/java/adecWatt/model/Item.java +++ b/src/java/adecWatt/model/Item.java @@ -53,26 +53,29 @@ public abstract class Item

, T extends Enum, A ex } // ======================================== + public boolean onAcc (String accId, double theta, Point2D.Double realPos, double close) { + try { + double [] coord = new double [] {realPos.x, realPos.y}; + Point2D.Double accPos = accCenter.get (accId); + DimensionDouble accSize = this.accSize.get (accId); + AffineTransform at = new AffineTransform (); + at.rotate (theta); + at.translate (-accPos.x, -accPos.y); + at.transform (coord, 0, coord, 0, 1); + double halfWidth = accSize.width/2+close, halfHeight = accSize.height/2+close; + if (coord[0] >= -halfWidth && coord[0] <= halfWidth && + coord[1] >= -halfHeight && coord[1] <= halfHeight) + return true; + } catch (Exception e) { + } + return false; + } public ArrayList findAccs (Point2D.Double realPos, double close) { ArrayList result = new ArrayList (); double theta = Math.toRadians (-getThetaDegree ()); - double [] coord = new double [] {realPos.x, realPos.y}; for (String accId : getEmbeddedIds ()) - try { - coord[0] = realPos.x; - coord[1] = realPos.y; - Point2D.Double accPos = accCenter.get (accId); - DimensionDouble accSize = this.accSize.get (accId); - AffineTransform at = new AffineTransform (); - at.rotate (theta); - at.translate (-accPos.x, -accPos.y); - at.transform (coord, 0, coord, 0, 1); - double halfWidth = accSize.width/2+close, halfHeight = accSize.height/2+close; - if (coord[0] >= -halfWidth && coord[0] <= halfWidth && - coord[1] >= -halfHeight && coord[1] <= halfHeight) - result.add (findEmbedded (accId)); - } catch (Exception e) { - } + if (onAcc (accId, theta, realPos, close)) + result.add (findEmbedded (accId)); return result; } diff --git a/src/java/adecWatt/view/JAcc.java b/src/java/adecWatt/view/JAcc.java index 36fcfb1..14315da 100644 --- a/src/java/adecWatt/view/JAcc.java +++ b/src/java/adecWatt/view/JAcc.java @@ -1,12 +1,13 @@ package adecWatt.view; +import adecWatt.model.Acc; +import adecWatt.model.Item; import java.awt.Dimension; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; import javax.swing.JLabel; -import adecWatt.model.Acc; -import adecWatt.model.Item; @SuppressWarnings ("serial") public class JAcc extends JLabel { @@ -27,9 +28,9 @@ public class JAcc extends JLabel { setIcon (acc.getModel ().getIcon (16)); setSize (getPreferredSize ()); setPos (); - AccMouseAdapter accMouseAdapter = new AccMouseAdapter (); - addMouseListener (accMouseAdapter); - addMouseMotionListener (accMouseAdapter); + // AccMouseAdapter accMouseAdapter = new AccMouseAdapter (); + // addMouseListener (accMouseAdapter); + // addMouseMotionListener (accMouseAdapter); } public void setPos () { setPos (jWorkspaceView.scaleModelToView (item.getAccCenter (acc.getId ()))); @@ -112,6 +113,11 @@ public class JAcc extends JLabel { // } catch (Exception e2) { // } // } + // ======================================== + public boolean contains (Point2D.Double realPos, double close) { + double theta = Math.toRadians (-item.getThetaDegree ()); + return item.onAcc (acc.getId (), theta, realPos, close); + } // ======================================== public void dragAcc (Dimension delta) { diff --git a/src/java/adecWatt/view/JOverlapItemPopup.java b/src/java/adecWatt/view/JOverlapItemPopup.java index 8dea224..981f93f 100644 --- a/src/java/adecWatt/view/JOverlapItemPopup.java +++ b/src/java/adecWatt/view/JOverlapItemPopup.java @@ -4,6 +4,7 @@ import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,8 +23,15 @@ import adecWatt.control.AdecWattManager; this.jWorkspaceView = jWorkspaceView; this.mouseEvent = mouseEvent; Point pos = mouseEvent.getPoint (); + if (jWorkspaceView.selectedAcc != null) { + Point2D.Double realPos = jWorkspaceView.scaleViewToModel (new Point (pos.x, pos.y)); + if (jWorkspaceView.selectedAcc.contains (realPos, jWorkspaceView.closePixelsAccs/jWorkspaceView.scale)) + return; + } ArrayList overlapItems = jWorkspaceView.findItems (pos); - if (mouseEvent.getID () == MouseEvent.MOUSE_PRESSED && !SwingUtilities.isRightMouseButton (mouseEvent) && + if (mouseEvent.getID () == MouseEvent.MOUSE_PRESSED && + !mouseEvent.isShiftDown () && + !SwingUtilities.isRightMouseButton (mouseEvent) && jWorkspaceView.selectedItems.size () > 0) { for (final JItem jItem : jWorkspaceView.selectedItems.values ()) if (overlapItems.contains (jItem.getItem ())) { @@ -53,6 +61,7 @@ import adecWatt.control.AdecWattManager; }); add (menuItem); } + jWorkspaceView.noDrag (); show (jWorkspaceView, pos.x, pos.y); } diff --git a/src/java/adecWatt/view/JWorkspaceView.java b/src/java/adecWatt/view/JWorkspaceView.java index 4c4d0a9..1b31b8b 100644 --- a/src/java/adecWatt/view/JWorkspaceView.java +++ b/src/java/adecWatt/view/JWorkspaceView.java @@ -241,7 +241,11 @@ import adecWatt.model.unit.Workspace; } return false; } - //private ArrayList overlapItems; + public void noDrag () { + refHandle = null; + handleOff = null; + //firstClick = lastClick = null; + } public void startDrag (Item item, Point mPos) { firstClick = lastClick = mPos; selectionRefHandle (item, mPos); @@ -256,6 +260,7 @@ import adecWatt.model.unit.Workspace; } Hashtable> overlapAccs = findAccs (mPos, item); if (overlapAccs.size () > 0) { + firstClick = lastClick = mPos; lastSelectedAccId = (lastSelectedAccId+1)%nbOverlapAccs (overlapAccs); setSelectedAcc (overlapAccs, lastSelectedAccId); return; @@ -265,11 +270,8 @@ import adecWatt.model.unit.Workspace; if (e.isShiftDown ()) { //invertItemSelection (overlapItems.get (0)); invertItemSelection (item); - if (selectedItems.size () < 1) { - firstClick = lastClick = null; - refHandle = null; - handleOff = null; - } + if (selectedItems.size () < 1) + noDrag (); // XXX changement du choix de la poignée de référence ? return; } @@ -453,6 +455,7 @@ import adecWatt.model.unit.Workspace; protected void setSelectedAcc () { if (selectedAcc == null) return; + firstClick = lastClick = null; remove (selectedAcc); selectedAcc = null; updateSelection (); @@ -688,8 +691,6 @@ import adecWatt.model.unit.Workspace; ArrayList dstItems = workspace.findItems (realPos, closePixelsItems/scale); PermanentDB permanentDB = adecWatt.getPermanentDB (); if (selectedAcc.getAcc ().getDirectUnit ().isDescendingFrom (permanentDB.getPowerPlugId ())) { - - if (dstItems.size () < 1) { eraseAcc (selectedAcc.getAcc ()); return; @@ -794,9 +795,7 @@ import adecWatt.model.unit.Workspace; } catch (Exception e2) { e2.printStackTrace (); } finally { - firstClick = lastClick = null; - refHandle = null; - handleOff = null; + noDrag (); } } public void storyRotResizeItem (JItem jItem) {