Commit b963d0f7 authored by Nico Mack's avatar Nico Mack

Added tetherOffsetAngle property to TetherableWidget

Fixed bug in handling of rotation with tether (rotateWithTether=true)
Fixed a bug in newly introduced tether handling
parent 61909052
......@@ -175,6 +175,7 @@ TETHER_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.tether.builder
TETHER_NODE=tether
TETHERABLE_NODE=tetherable
TETHERS_NODE=tethers
TETHER_OFFSET_ANGLE_NODE=tetherOffsetAngle
TEXT_COLOUR_ELEMENT=textColour
TEXT_NODE=text
TICKMARK_COLOUR_NODE=tickMarkColour
......
......@@ -136,6 +136,17 @@ public abstract class TetherableMarker extends Marker implements Tetherable {
return this.tetherManager.isPotentialTether();
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
// ---------------------------------------------------------------------------
@Override
public Tether getTetherFor(Tetherable tethered) {
return this.tetherManager.getTetherFor(tethered);
}
// ---------------------------------------------------------------------------
@Override
......
......@@ -210,6 +210,7 @@ public class Externalization extends NLS {
public static String TETHER_NODE;
public static String TETHERABLE_NODE;
public static String TETHERS_NODE;
public static String TETHER_OFFSET_ANGLE_NODE;
public static String TEXT_COLOUR_ELEMENT;
public static String TEXT_NODE;
public static String TICKMARK_COLOUR_NODE;
......
......@@ -54,7 +54,8 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
private double tetheringDistance;
private boolean draggable;
private boolean rotatesWithTether;
private float angleOffset;
private double tetherOffsetAngle;
private double angleOffset;
private TetherManager tetherManager;
......@@ -84,6 +85,8 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
this.tetheringDistance = builder.tetheringDistance;
this.draggable = builder.draggable;
this.rotatesWithTether = builder.rotatesWithTether;
this.tetherOffsetAngle = (float) builder.tetherOffsetAngle;
this.angleOffset = Double.NaN;
}
// ---------------------------------------------------------------------------
......@@ -106,6 +109,8 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
this.tetheringDistance = original.tetheringDistance;
this.draggable = original.draggable;
this.rotatesWithTether = original.rotatesWithTether;
this.tetherOffsetAngle = original.tetherOffsetAngle;
this.angleOffset = Double.NaN;
}
// ---------------------------------------------------------------------------
......@@ -185,6 +190,17 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
*/
// ---------------------------------------------------------------------------
@Override
public Tether getTetherFor(Tetherable tethered) {
return this.tetherManager.getTetherFor(tethered);
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
// ---------------------------------------------------------------------------
@Override
public Point getTetherOrigin() {
return this.tetherOrigin;
......@@ -354,7 +370,15 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
TangibleObject clone = tangibleObject;
if (this.isTethered() && this.rotatesWithTether) {
clone = tangibleObject.constrainedClone(new Point(tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle() + angleOffset, CameraCoordinates.class));
if (Double.isNaN(angleOffset)) {
angleOffset = tangibleObject.getAngle();
}
double delta = tangibleObject.getAngle() - angleOffset;
double offset = (this.getTetherOrigin().getAngle() - delta + tetherOffsetAngle);
clone = tangibleObject.constrainedClone(new Point(tangibleObject.getX(), tangibleObject.getY(), (float) offset, CameraCoordinates.class));
} else {
angleOffset = Double.NaN;
}
super.actionMove(clone);
......@@ -367,7 +391,7 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
this.tetherManager.move(origin);
angleOffset = this.getTetherOrigin().getAngle();
// angleOffset = this.getTetherOrigin().getAngle() + ;
}
}
......
......@@ -40,6 +40,7 @@ public abstract class BaseTetherableBuilder<B extends BaseTetherableBuilder<B>>
public boolean draggable = false;
public boolean exclusive = true;
public boolean rotatesWithTether = false;
public double tetherOffsetAngle = 0;
public List<String> providers = new ArrayList<>();
public List<String> receivers = new ArrayList<>();
......@@ -94,6 +95,7 @@ public abstract class BaseTetherableBuilder<B extends BaseTetherableBuilder<B>>
this.draggable = BootstrappingUtils.getContentAsBoolean(tetherableNode, Externalization.DRAGGABLE_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.exclusive = BootstrappingUtils.getContentAsBoolean(tetherableNode, Externalization.EXCLUSIVE_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.rotatesWithTether = BootstrappingUtils.getContentAsBoolean(tetherableNode, Externalization.ROTATE_WITH_TETHER_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.tetherOffsetAngle = BootstrappingUtils.getContentAsRadians(tetherableNode, Externalization.TETHER_OFFSET_ANGLE_NODE, BootstrappingUtils.OPTIONAL, 0d, context);
}
}
......@@ -194,8 +196,7 @@ public abstract class BaseTetherableBuilder<B extends BaseTetherableBuilder<B>>
* Method used to specify wether tetherable widget is dragable or not
*
* @param isDraggable
* <code>true</code> to make this tetherable widget dragable, <code>false</code>
* otherwise.
* <code>true</code> to make this tetherable widget dragable, <code>false</code> otherwise.
* @return An instance of the builder for chain-calling.
*/
// ---------------------------------------------------------------------------
......
......@@ -505,6 +505,33 @@ public class TetherManager {
}
}
// ---------------------------------------------------------------------------
/**
* @param tethered
* @return
*/
// ---------------------------------------------------------------------------
public Tether getTetherFor(Tetherable tethered) {
Tether tether = null;
// Case 1: We're already tethered with the given object, so we may
// return the currently known tether instance.
if (this.currentlyTethered.containsKey(tethered)) {
tether = this.currentlyTethered.get(tethered);
// Case 2: We're not yet tethered to the given object but the
// object may already be tethered with us. If so, then we're going
// to retrieve the tether object from that object
} else if (tethered.isTetheredWith(this.tetherable)) {
tether = tethered.getTetherFor(this.tetherable);
// Case 3: We're right at the beginning of the tethering process,
// so we have to clone the potential tether object.
} else {
tether = this.potentialTethers.get(tethered).clone();
}
return tether;
}
// ---------------------------------------------------------------------------
/**
* @param potential
......@@ -551,8 +578,11 @@ public class TetherManager {
this.separateFromAll(propagate);
}
Tether tether = this.potentialTethers.get(candidate);
this.currentlyTethered.put(candidate, tether.clone());
// Tether tether = this.potentialTethers.get(candidate);
// this.currentlyTethered.put(candidate, tether.clone());
Tether tether = this.getTetherFor(candidate);
this.currentlyTethered.put(candidate, tether);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} now tethered with {}!", this.tetherable, candidate); //$NON-NLS-1$
......
......@@ -42,6 +42,8 @@ public interface Tetherable {
public abstract double getTetheringDistance();
public abstract Tether getTetherFor(Tetherable tethered);
public abstract Point getTetherOrigin();
public abstract void setTetherOrigin(Point Origin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment