Initial commit
This commit is contained in:
commit
6138e26c0c
23
.idea/compiler.xml
generated
Normal file
23
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
|
1
.idea/description.html
generated
Normal file
1
.idea/description.html
generated
Normal file
@ -0,0 +1 @@
|
||||
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
|
5
.idea/encodings.xml
generated
Normal file
5
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
11
.idea/libraries/ivy_java_1_2_17.xml
generated
Normal file
11
.idea/libraries/ivy_java_1_2_17.xml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="ivy-java-1.2.17">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/ivy-java-1.2.17.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/ivy-java-1.2.17.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
12
.idea/misc.xml
generated
Normal file
12
.idea/misc.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectKey">
|
||||
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Projet_IHM.iml" filepath="$PROJECT_DIR$/Projet_IHM.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="" />
|
||||
</component>
|
||||
</project>
|
||||
|
12
Projet_IHM.iml
Normal file
12
Projet_IHM.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="ivy-java-1.2.17" level="project" />
|
||||
</component>
|
||||
</module>
|
BIN
lib/ivy-java-1.2.17.jar
Normal file
BIN
lib/ivy-java-1.2.17.jar
Normal file
Binary file not shown.
79
src/Fenetre.java
Normal file
79
src/Fenetre.java
Normal file
@ -0,0 +1,79 @@
|
||||
import fr.dgac.ivy.IvyException;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
/**
|
||||
* Created by renando on 16/01/17.
|
||||
*/
|
||||
class Fenetre extends JFrame {
|
||||
private ivyTranslater monIvy;
|
||||
|
||||
//private Automate a;
|
||||
|
||||
|
||||
Fenetre(Panel panel) {
|
||||
super("IHM TP Lines");
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
Panel panel1 = panel;
|
||||
this.add(panel);
|
||||
try {
|
||||
this.monIvy = new ivyTranslater();
|
||||
} catch (IvyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
panel.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
if (SwingUtilities.isLeftMouseButton(mouseEvent))
|
||||
panel.getStroke().addPoint(mouseEvent.getX(), mouseEvent.getY());
|
||||
panel.stroke = new Stroke();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
monIvy.sendMsg("coord=" + panel.getStroke().toString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
}
|
||||
});
|
||||
|
||||
panel.addMouseMotionListener(new MouseMotionListener() {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent mouseEvent) {
|
||||
if (SwingUtilities.isLeftMouseButton(mouseEvent))
|
||||
panel.getStroke().addPoint(mouseEvent.getX(), mouseEvent.getY());
|
||||
panel.repaint();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
setSize(600, 600);
|
||||
setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
10
src/Main.java
Normal file
10
src/Main.java
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Created by renando on 18/01/17.
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Panel panel = new Panel();
|
||||
new Fenetre(panel);
|
||||
}
|
||||
}
|
40
src/Panel.java
Normal file
40
src/Panel.java
Normal file
@ -0,0 +1,40 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
* Created by renando on 16/01/17.
|
||||
*/
|
||||
public class Panel extends JComponent {
|
||||
|
||||
|
||||
public Stroke stroke;
|
||||
|
||||
public Panel() {
|
||||
super();
|
||||
stroke = new Stroke();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
Graphics2D g2 = (Graphics2D) graphics;
|
||||
|
||||
for (Point2D.Double p : stroke.getPoints()) {
|
||||
int x = (int) p.getX();
|
||||
int y = (int) p.getY();
|
||||
g2.drawOval(x, y, 2, 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Stroke getStroke() {
|
||||
return stroke;
|
||||
}
|
||||
|
||||
public void setStroke(Stroke stroke) {
|
||||
this.stroke = stroke;
|
||||
}
|
||||
|
||||
}
|
202
src/Stroke.java
Normal file
202
src/Stroke.java
Normal file
@ -0,0 +1,202 @@
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Stroke {
|
||||
private static final int NB_POINTS = 32;
|
||||
private static final int SQUARE_SIZE = 100;
|
||||
|
||||
ArrayList<Point2D.Double> listePoint;
|
||||
Point2D.Double centroid;
|
||||
|
||||
public Stroke() {
|
||||
listePoint = new ArrayList<Point2D.Double>();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
listePoint = null;
|
||||
centroid = null;
|
||||
listePoint = new ArrayList<Point2D.Double>();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return listePoint == null || listePoint.size() == 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return listePoint.size();
|
||||
}
|
||||
|
||||
public Point2D.Double getPoint(int i) {
|
||||
return listePoint.get(i);
|
||||
}
|
||||
|
||||
public Point2D.Double getCentroid() {
|
||||
return centroid;
|
||||
}
|
||||
|
||||
public double getCentroidX() {
|
||||
return centroid.x;
|
||||
}
|
||||
|
||||
public double getCentroidY() {
|
||||
return centroid.y;
|
||||
}
|
||||
|
||||
public void addPoint(Point2D.Double p) {
|
||||
listePoint.add(p);
|
||||
}
|
||||
|
||||
public void addPoint(int x, int y) {
|
||||
listePoint.add(new Point2D.Double(x, y));
|
||||
}
|
||||
|
||||
public void normalize() {
|
||||
resample();
|
||||
rotateToZero();
|
||||
scaleToSquare();
|
||||
translateToOrigin();
|
||||
}
|
||||
|
||||
public double getPathLength() {
|
||||
double dist = 0.0;
|
||||
for (int i = 1; i < listePoint.size(); i++) {
|
||||
Point2D.Double p0 = listePoint.get(i - 1);
|
||||
Point2D.Double p1 = listePoint.get(i);
|
||||
dist += p0.distance(p1);
|
||||
}
|
||||
return dist;
|
||||
}
|
||||
|
||||
public ArrayList<Point2D.Double> resample() {
|
||||
double l = getPathLength() / (NB_POINTS - 1);
|
||||
double D = 0;
|
||||
ArrayList<Point2D.Double> newPoints = new ArrayList<Point2D.Double>();
|
||||
newPoints.add(listePoint.get(0));
|
||||
for (int i = 1; i < listePoint.size(); i++) {
|
||||
Point2D.Double p0 = listePoint.get(i - 1);
|
||||
Point2D.Double p1 = listePoint.get(i);
|
||||
double d = p0.distance(p1);
|
||||
if (D + d >= l) {
|
||||
double x = p0.getX() + ((l - D) / d) * (p1.getX() - p0.getX());
|
||||
double y = p0.getY() + ((l - D) / d) * (p1.getY() - p0.getY());
|
||||
Point2D.Double q = new Point2D.Double(x, y);
|
||||
newPoints.add(q);
|
||||
listePoint.add(i, q);
|
||||
D = 0;
|
||||
} else {
|
||||
D += d;
|
||||
}
|
||||
}
|
||||
if (newPoints.size() < NB_POINTS)
|
||||
newPoints.add(listePoint.get(listePoint.size() - 1));
|
||||
|
||||
listePoint = newPoints;
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
public Point2D.Double calculCentroid() {
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
x += p.getX();
|
||||
y += p.getY();
|
||||
}
|
||||
return new Point2D.Double(x / listePoint.size(), y / listePoint.size());
|
||||
}
|
||||
|
||||
public ArrayList<Point2D.Double> rotateToZero() {
|
||||
ArrayList<Point2D.Double> newPoints = new ArrayList<Point2D.Double>();
|
||||
centroid = calculCentroid();
|
||||
Point2D.Double p0 = listePoint.get(0);
|
||||
double theta = Math.atan2(centroid.getY() - p0.getY(), centroid.getX() - p0.getX());
|
||||
theta *= -1;
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
double x = ((p.getX() - centroid.getX()) * Math.cos(theta)) - ((p.getY() - centroid.getY()) * Math.sin(theta)) + centroid.getX();
|
||||
double y = ((p.getX() - centroid.getX()) * Math.sin(theta)) + ((p.getY() - centroid.getY()) * Math.cos(theta)) + centroid.getY();
|
||||
Point2D.Double q = new Point2D.Double(x, y);
|
||||
newPoints.add(q);
|
||||
}
|
||||
listePoint = newPoints;
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
public Rectangle2D.Double getBoundingBox() {
|
||||
Point2D.Double p0 = listePoint.get(0);
|
||||
double minX = p0.getX();
|
||||
double maxX = p0.getX();
|
||||
double minY = p0.getY();
|
||||
double maxY = p0.getY();
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
if (minX > p.getX()) minX = p.getX();
|
||||
if (minY > p.getY()) minY = p.getY();
|
||||
if (maxX < p.getX()) maxX = p.getX();
|
||||
if (maxY < p.getY()) maxY = p.getY();
|
||||
}
|
||||
return new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
public ArrayList<Point2D.Double> scaleToSquare() {
|
||||
ArrayList<Point2D.Double> newPoints = new ArrayList<Point2D.Double>();
|
||||
Rectangle2D.Double boundingBox = getBoundingBox();
|
||||
System.out.println(boundingBox);
|
||||
if (boundingBox.getHeight() > 10) {
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
double x = (p.getX() - boundingBox.getX()) * (SQUARE_SIZE / boundingBox.getWidth());
|
||||
double y = (p.getY() - boundingBox.getY()) * (SQUARE_SIZE / boundingBox.getHeight());
|
||||
Point2D.Double q = new Point2D.Double(x, y);
|
||||
newPoints.add(q);
|
||||
}
|
||||
}
|
||||
// Pour lisser une droite ...
|
||||
else {
|
||||
Point2D.Double p0 = listePoint.get(0);
|
||||
double y = p0.getY();
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
double x = (p.getX() - boundingBox.getX()) * (SQUARE_SIZE / boundingBox.getWidth());
|
||||
Point2D.Double q = new Point2D.Double(x, y);
|
||||
newPoints.add(q);
|
||||
}
|
||||
}
|
||||
listePoint = newPoints;
|
||||
return newPoints;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Point2D.Double> translateToOrigin() {
|
||||
ArrayList<Point2D.Double> newPoints = new ArrayList<Point2D.Double>();
|
||||
centroid = calculCentroid();
|
||||
for (int i = 0; i < listePoint.size(); i++) {
|
||||
Point2D.Double p = listePoint.get(i);
|
||||
double x = p.getX() - centroid.getX() + SQUARE_SIZE;
|
||||
double y = p.getY() - centroid.getY() + SQUARE_SIZE;
|
||||
Point2D.Double q = new Point2D.Double(x, y);
|
||||
newPoints.add(q);
|
||||
}
|
||||
centroid = new Point2D.Double(SQUARE_SIZE, SQUARE_SIZE);
|
||||
listePoint = newPoints;
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
public ArrayList<Point2D.Double> getPoints() {
|
||||
return listePoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Point2D.Double p : listePoint) {
|
||||
sb.append(p.getX());
|
||||
sb.append(",");
|
||||
sb.append(p.getY());
|
||||
sb.append(";");
|
||||
}
|
||||
sb.deleteCharAt(sb.lastIndexOf(";"));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
57
src/ivyTranslater.java
Normal file
57
src/ivyTranslater.java
Normal file
@ -0,0 +1,57 @@
|
||||
import fr.dgac.ivy.Ivy;
|
||||
import fr.dgac.ivy.IvyClient;
|
||||
import fr.dgac.ivy.IvyException;
|
||||
import fr.dgac.ivy.IvyMessageListener;
|
||||
|
||||
class ivyTranslater implements IvyMessageListener {
|
||||
|
||||
private final Ivy bus;
|
||||
private String argument;
|
||||
|
||||
ivyTranslater() throws IvyException {
|
||||
// initialization, name and ready message
|
||||
bus = new Ivy("IvyTranslater", "Geste", null);
|
||||
// classical subscription
|
||||
bus.bindMsg("sra5 Parsed=(.*) Confidence", this);
|
||||
// inner class subscription ( think awt )
|
||||
bus.bindMsg("^Bye$", (client, args) -> {
|
||||
// leaves the bus, and as it is the only thread, quits
|
||||
bus.stop();
|
||||
});
|
||||
bus.start("127.255.255.255:2010"); // starts the bus on the default domain
|
||||
}
|
||||
|
||||
// callback associated to the "Hello" messages"
|
||||
void recevoire(Panel panel) throws IvyException {
|
||||
panel.stroke = new Stroke();
|
||||
bus.bindMsg("^coord=(.*)", (client, args) -> {
|
||||
if (args[0] != null) {
|
||||
panel.stroke = new Stroke();
|
||||
String[] listeCoor = args[0].split(";");
|
||||
String x;
|
||||
String y;
|
||||
for (String coor : listeCoor) {
|
||||
x = coor.split(",")[0].replace(".0", "");
|
||||
y = coor.split(",")[1].replace(".0", "");
|
||||
panel.getStroke().addPoint(Integer.parseInt(x), Integer.parseInt(y));
|
||||
}
|
||||
panel.repaint();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void sendMsg(String msg) {
|
||||
try {
|
||||
bus.sendMsg(msg);
|
||||
} catch (IvyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(IvyClient ivyClient, String[] strings) {
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user