Commit e73bfd50 authored by Eric Tobias's avatar Eric Tobias

Merge branch 'dev-nico' of http://git.list.lu/nui/tulip into dev-nico

Conflicts:
	TULIP/src/lu/list/itis/dkd/tui/adapter/TuioAdapter.java
parents 0909642f febb5f7d
......@@ -13,10 +13,10 @@
<attribute name="javadoc_location" value="jar:platform:/resource/TUI%20Framework/libs/guava-15.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="libs/tuio-1.4.jar" sourcepath="C:/Users/tobias/.m2/repository/net/sourceforge/tuio/tuio/1.4/tuio-1.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="libs/dbc.annotation.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="libs/bluecove-2.1.1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libs/RXTXcomm.jar"/>
<classpathentry kind="lib" path="libs/libTUIO.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -11,9 +11,9 @@ org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nonnull=dbc.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=dbc.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=dbc.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
......
......@@ -16,10 +16,12 @@ font = Arial
fontSize = 13
colour = BLACK
centred = false
# Adapter to load
tableAdapter = tuio
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursorIDRemappingConstant = 1024
\ No newline at end of file
cursorIDRemappingConstant = 1024
# Add the property "tableAdapter" with the adapter to load
# Syntax is : tableAdapter = packageName.ClassName
# i.e : tableAdapter = lu.list.itis.dkd.tui.adapter.TuioAdapter
\ No newline at end of file
......@@ -87,9 +87,8 @@ public abstract class TangibleApplication {
*
* @param newPropertiesFileURI
* The URI of the properties file to load.
* @throws Exception
*/
protected TangibleApplication(@Nullable String newPropertiesFileURI) throws Exception {
protected TangibleApplication(@Nullable String newPropertiesFileURI) {
if (newPropertiesFileURI != null && !newPropertiesFileURI.isEmpty()) {
propertiesFileURI = newPropertiesFileURI;
}
......@@ -109,41 +108,33 @@ public abstract class TangibleApplication {
adapter = (TuiAdapter) Class.forName(properties.getProperty("tableAdapter")).getConstructor(TangibleInterfaceManager.class).newInstance(interfaceManager); //$NON-NLS-1$
} catch (InstantiationException e) {
logger.log(Level.SEVERE, "Cannot instantiate adapter.\n" //$NON-NLS-1$
+ "You try to instantiate an abstract class or an interface!"); //$NON-NLS-1$s
throw new Exception("Cannot instantiate adapter\n" //$NON-NLS-1$
+ "You try to instantiate an abstract class or an interface!", e); //$NON-NLS-1$
logger.log(Level.SEVERE, "Cannot instantiate adapter. You try to instantiate an abstract class or an interface!"); //$NON-NLS-1$s
System.exit(42);
} catch (IllegalAccessException e) {
logger.log(Level.SEVERE, "The currently executing method does not have access to the definition of the constructor."); //$NON-NLS-1$
throw new IllegalAccessException("The currently executing method does not have access to the definition of the constructor."); //$NON-NLS-1$
System.exit(42);
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "A wrong argument has been passed to the adapter."); //$NON-NLS-1$
throw new Exception("A wrong argument has been passed to the adapter.\n+" //$NON-NLS-1$
+ "Required argument of type lu.list.itis.dkd.tui.TangibleInterfaceManager!", e); //$NON-NLS-1$
System.exit(42);
} catch (InvocationTargetException e) {
logger.log(Level.SEVERE, "An exception has been thrown in the constructor of the adapter"); //$NON-NLS-1$
throw new InvocationTargetException(e, "Une exception a été jeté dans le constructeur de l'adaptateur.\n+" //$NON-NLS-1$
+ "Check the constructor of " + properties.getProperty("tableAdapter")); //$NON-NLS-1$ //$NON-NLS-2$
System.exit(42);
} catch (NoSuchMethodException e) {
logger.log(Level.SEVERE, "The called method was not found"); //$NON-NLS-1$
throw new NoSuchMethodException("The called method was not found"); //$NON-NLS-1$
System.exit(42);
} catch (SecurityException e) {
logger.log(Level.SEVERE, "Security violation"); //$NON-NLS-1$
throw new Exception("Security violation", e); //$NON-NLS-1$
System.exit(42);
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "The class " + properties.getProperty("tableAdapter") + "was not found."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new ClassNotFoundException("The class " + properties.getProperty("tableAdapter") + "was not found.\n" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "Check the spelling of your adapter class name in properties file."); //$NON-NLS-1$
logger.log(Level.SEVERE, "The class " + properties.getProperty("tableAdapter") + " was not found. Check the spelling !"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
System.exit(42);
}
GlobalContext.setGlobalContext(adapter);
IDMapper.initialise(properties);
......
......@@ -51,6 +51,9 @@ public abstract class TangibleObjectManager {
/** This dictionary stores all cursors detected by reacTIVision. */
protected volatile static ConcurrentHashMap<Integer, BaseWidget> cursorList = new ConcurrentHashMap<>();
/** This dictionary stores all blobs detected by reacTIVision. */
protected volatile static ConcurrentHashMap<Integer, BaseWidget> blobList = new ConcurrentHashMap<>();
/** A {@link Logger} to log all messages during execution. */
protected Logger logger;
......@@ -180,6 +183,12 @@ public abstract class TangibleObjectManager {
}
break;
case BLOB:
blobList.putIfAbsent(tangibleObject.getObjectId(), new BaseWidgetBuilder().withCorona(tangibleObject.getObjectId(), new ShadowBuilder(new Point()).withShape(ShapeFactory.buildCircle(5)).build()).build());
blobList.get(tangibleObject.getObjectId()).actionDrop(tangibleObject);
ensureConsistency();
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......@@ -211,7 +220,10 @@ public abstract class TangibleObjectManager {
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
}
break;
case BLOB:
if (blobList.containsKey(tangibleObject.getObjectId())) {
blobList.remove(tangibleObject.getObjectId()).actionLift(tangibleObject);
}
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......@@ -243,6 +255,12 @@ public abstract class TangibleObjectManager {
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
}
break;
case BLOB:
if (blobList.containsKey(tangibleObject.getObjectId())) {
blobList.get(tangibleObject.getObjectId()).actionMove(tangibleObject);
} else {
logger.log(Level.WARNING, "The blob could not be recognised!"); //$NON-NLS-1$
}
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......
......@@ -18,7 +18,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import java.util.Vector;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -28,7 +28,7 @@ import java.util.logging.Logger;
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @author Eric TOBIAS [eric.tobias@list.lu]
* @since 2.0
* @version 2.0.2
* @version 2.0.41
*/
@NonNullByDefault
public class TangibleObject {
......@@ -40,7 +40,10 @@ public class TangibleObject {
* Type denoting that the object is a cursor, most likely a finger or pen used to manipulate
* the interface.
*/
CURSOR
CURSOR,
/** Type denoting that the object is any untagged generic object */
BLOB
}
/** A {@link Logger} to log all messages during execution. */
......@@ -77,7 +80,7 @@ public class TangibleObject {
protected float rotationAccel;
/** A Vector of {@link Point} containing all the previous positions of the tangible object. */
protected Vector<Point> path;
protected ArrayList<Point> path;
/** Reflects the current state of the {@link TangibleObject} */
protected State state;
......@@ -123,6 +126,15 @@ public class TangibleObject {
}
}
/** The width value. */
protected float width;
/** The height value. */
protected float height;
/** The area value. */
protected float area;
/**
* Default constructor
......@@ -162,7 +174,7 @@ public class TangibleObject {
* @return the x coordinates of the object.
*/
public float getX() {
return (float) path.lastElement().getX();
return (float) path.get(path.size() - 1).getX();
}
/**
......@@ -171,7 +183,7 @@ public class TangibleObject {
* @return the y coordinates of the object.
*/
public float getY() {
return (float) path.lastElement().getY();
return (float) path.get(path.size() - 1).getY();
}
/**
......@@ -180,7 +192,7 @@ public class TangibleObject {
* @return The value of angle.
*/
public float getAngle() {
return path.lastElement().getAngle();
return path.get(path.size() - 1).getAngle();
}
/**
......@@ -354,7 +366,7 @@ public class TangibleObject {
return rotationAccel;
}
/***
/**
* Simple setter method for the rotation acceleration
*
* @param rotationAccel
......@@ -368,7 +380,7 @@ public class TangibleObject {
*
* @return the path of the object
*/
public Vector<Point> getPath() {
public ArrayList<Point> getPath() {
return path;
}
......@@ -377,7 +389,7 @@ public class TangibleObject {
*
* @param path
*/
public void setPath(Vector<Point> path) {
public void setPath(ArrayList<Point> path) {
this.path = path;
}
......@@ -405,4 +417,61 @@ public class TangibleObject {
public void setState(int state) {
this.state = State.getState(state);
}
/**
* Simple getter method for width.
*
* @return The value of width.
*/
public float getWidth() {
return width;
}
/**
* Simple setter method for width.
*
* @param width
* The value to set width to.
*/
public void setWidth(float width) {
this.width = width;
}
/**
* Simple getter method for height.
*
* @return The value of height.
*/
public float getHeight() {
return height;
}
/**
* Simple setter method for height.
*
* @param height
* The value to set height to.
*/
public void setHeight(float height) {
this.height = height;
}
/**
* Simple getter method for area.
*
* @return The value of area.
*/
public float getArea() {
return area;
}
/**
* Simple setter method for area.
*
* @param area
* The value to set area to.
*/
public void setArea(float area) {
this.area = area;
}
}
......@@ -19,7 +19,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import java.util.Vector;
import java.util.ArrayList;
/**
* REFACTORED Method names should be refactored due to them not being additions as suggested. Use
......@@ -66,10 +66,19 @@ public class TangibleObjectBuilder {
/** The rotation acceleration value. */
protected float rotationAccel = 0;
/** The width value. */
protected float width = 0;
/** The height value. */
protected float height = 0;
/** The area value. */
protected float area = 0;
/**
* A Vector of {@link Point} containing all the previous positions of the tangible object.
*/
protected Vector<Point> path = new Vector<>();
protected ArrayList<Point> path = new ArrayList<>();
/** Reflects the current state of the {@link TangibleObject} */
protected State state = TangibleObject.State.ADDED;
......@@ -88,7 +97,7 @@ public class TangibleObjectBuilder {
public TangibleObjectBuilder(int objectId, Type type, float x, float y) {
this.objectId = objectId;
this.type = type;
path.addElement(new Point(x, y, 0));
path.add(new Point(x, y, 0));
}
......@@ -196,7 +205,7 @@ public class TangibleObjectBuilder {
* object.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withPath(Vector<Point> path) {
public TangibleObjectBuilder withPath(ArrayList<Point> path) {
this.path = path;
return this;
}
......@@ -222,6 +231,42 @@ public class TangibleObjectBuilder {
return this;
}
/**
* Method for adding width to the tangible object
*
* @param width
* The width value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withWidth(float width) {
this.width = width;
return this;
}
/**
* Method for adding height to the tangible object
*
* @param height
* The height value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withHeight(float height) {
this.height = height;
return this;
}
/**
* Method for adding area to the tangible object
*
* @param area
* The area value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withArea(float area) {
this.area = area;
return this;
}
/**
* Method for building a {@link TangibleObject} with the values set by the builder.
*
......
......@@ -90,6 +90,13 @@ public abstract class TuiAdapter {
*/
public abstract Collection<TangibleObject> getActiveObjects();
/**
* Method returning a collection of {@link TangibleObject} (blob) instances held by this.
*
* @return The collection of managed {@link TangibleObject} instances.
*/
public abstract Collection<TangibleObject> getActiveBlobs();
/**
* Method returning the {@link TangibleObject} (cursor) with the given id
*
......@@ -110,6 +117,16 @@ public abstract class TuiAdapter {
*/
public abstract TangibleObject getObject(long id);
/**
* Method returning the {@link TangibleObject} (blob) with the given id
*
* @param id
* of the blob to get
*
* @return The {@link TangibleObject} with objectId = id.
*/
public abstract TangibleObject getBlob(long id);
/**
* create a string representation of a tangible object to the logging mechanism
*
......@@ -134,4 +151,16 @@ public abstract class TuiAdapter {
EventLogger.getInstance().addCurInfo(tangibleObject.getObjectId(), tangibleObject.getX(), tangibleObject.getY(), operation, tangibleObject.getTotalMilliseconds());
}
/**
* create a string representation of a tangible object to the logging mechanism
*
* @param tangibleObject
* is the concerned blob.
* @param operation
* is the move done.
*/
public synchronized void addBlobInfo(TangibleObject tangibleObject, String operation) {
EventLogger.getInstance().addObjInfo(tangibleObject.getObjectId(), tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle(), operation, tangibleObject.getTotalMilliseconds());
}
}
......@@ -23,6 +23,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import lu.tudor.ssi.kiss.dbc.annotation.Nullable;
import TUIO.TuioBlob;
import TUIO.TuioClient;
import TUIO.TuioCursor;
import TUIO.TuioListener;
......@@ -31,15 +32,17 @@ import TUIO.TuioTime;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
/**
* Adapter class managing interaction with reacTIVision tangible table using TUIO protocol.
*
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 2.0
* @version 2.0.1
* @version 2.0.2
*/
@NonNullByDefault
public class TuioAdapter extends TuiAdapter implements TuioListener {
......@@ -55,6 +58,9 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
protected TangibleObjectManager objectManager;
/** This dictionary stores all the objects detected by reacTIVision */
protected volatile static ConcurrentHashMap<Integer, TangibleObject> tangibleObjectList = new ConcurrentHashMap<>();
/**
* Constructor initialising several fields and setting up the interfaceManager for refresh.
*
......@@ -95,7 +101,8 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
@Override
public void connect() {
Preconditions.checkState(objectManager != null, "All managers need to be instantiated!"); //$NON-NLS-1$
Preconditions.checkState(objectManager != null, "ObjectManager need to be instantiated!"); //$NON-NLS-1$
Preconditions.checkState(interfaceManager != null, "InterfaceManager need to be instantiated!"); //$NON-NLS-1$
client.addTuioListener(this);
client.connect();
......@@ -107,58 +114,120 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
@Override
public void disconnect() {
// client.removeAllTuioListeners();
client.removeAllTuioListeners();
client.disconnect();
}
/**
* Convert a TUIO object into a tangibleObject
*
* @param tangibleObject
* @param tuioObject
* @pre tangibleObject != null
* @return tangibleObject with TuioObject values
*/
private TangibleObject convertTuioObjectToTangibleObject(TuioObject tangibleObject) {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
Vector<Point> tempPath = new Vector<>();
tangibleObject.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), tangibleObject.getAngle())));
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(tangibleObject.getSymbolID(), Type.OBJECT, tangibleObject.getPath().lastElement().getX(), tangibleObject.getPath().lastElement().getY())
.withSeconds(tangibleObject.getTuioTime().getSeconds())
.withMicroSeconds(tangibleObject.getTuioTime().getMicroseconds())
.withxSpeed(tangibleObject.getXSpeed())
.withySpeed(tangibleObject.getYSpeed())
.withMotionSpeed(tangibleObject.getMotionSpeed())
.withMotionAccel(tangibleObject.getMotionAccel())
.withRotationSpeed(tangibleObject.getRotationSpeed())
.withRotationAccel(tangibleObject.getRotationAccel())
.withPath(tempPath)
.withState(tangibleObject.getTuioState())
.build();
private TangibleObject convertTuioObjectToTangibleObject(TuioObject tuioObject) {
Preconditions.checkArgument(tuioObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
// get the object if present
TangibleObject updateObject = tangibleObjectList.get(tuioObject.getSymbolID());
TangibleObject convertedTangibleObject;
if (updateObject == null) {
// if the object is not present simply convert the tuioPath
ArrayList<Point> tempPath = new ArrayList<>();
tuioObject.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioObject.getAngle())));
convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().get(tuioObject.getPath().size() - 1).getX(), tuioObject.getPath().get(tuioObject.getPath().size() - 1).getY())
.withSeconds(tuioObject.getTuioTime().getSeconds())
.withMicroSeconds(tuioObject.getTuioTime().getMicroseconds())
.withxSpeed(tuioObject.getXSpeed())
.withySpeed(tuioObject.getYSpeed())
.withMotionSpeed(tuioObject.getMotionSpeed())
.withMotionAccel(tuioObject.getMotionAccel())
.withRotationSpeed(tuioObject.getRotationSpeed())
.withRotationAccel(tuioObject.getRotationAccel())
.withPath(tempPath)
.withState(tuioObject.getTuioState())
.build();
} else {
// if the object is present in the list, get previous path and add the last point
ArrayList<Point> tempPath = new ArrayList<>();
tempPath = updateObject.getPath();
int index = tuioObject.getPath().size() - 1;
tempPath.add(new Point(tuioObject.getPath().get(index).getX(), tuioObject.getPath().get(index).getY(), tuioObject.getAngle()));
convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().get(tuioObject.getPath().size() - 1).getX(), tuioObject.getPath().get(tuioObject.getPath().size() - 1).getY())
.withSeconds(tuioObject.getTuioTime().getSeconds())
.withMicroSeconds(tuioObject.getTuioTime().getMicroseconds())
.withxSpeed(tuioObject.getXSpeed())
.withySpeed(tuioObject.getYSpeed())
.withMotionSpeed(tuioObject.getMotionSpeed())
.withMotionAccel(tuioObject.getMotionAccel())
.withRotationSpeed(tuioObject.getRotationSpeed())
.withRotationAccel(tuioObject.getRotationAccel())
.withPath(tempPath)
.withState(tuioObject.getTuioState())
.build();
}
return convertedTangibleObject;
}
/**
* Convert a TUIO cursor into a tangibleObject