Skip to content

Commit 6c2c1f7

Browse files
authored
Merge pull request #42 (Maven Gauthier) from vykio/develop
Develop -> main
2 parents 61bf638 + 568b5f5 commit 6c2c1f7

31 files changed

+2338
-145
lines changed

pom.xml

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<groupId>vykio</groupId>
88
<artifactId>java-rdp</artifactId>
99
<version>${shownVersion</version>
10-
1110
<properties>
1211
<maven.compiler.source>11</maven.compiler.source>
1312
<maven.compiler.target>11</maven.compiler.target>
@@ -205,5 +204,4 @@
205204
<version>4.1.0</version>
206205
</dependency>
207206
</dependencies>
208-
209207
</project>

src/main/java/com/tech/app/models/Arc.java

+92-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Arc(Place place, int poids, double xOrigin, double yOrigin, boolean place
3030
this.placeToTransition = placeToTransition;
3131
this.transition = transition;
3232
this.forme = new Line2D.Double(xOrigin, yOrigin, this.place.getX(), this.place.getY());
33-
this.pointCtr1 = new PointControle();
33+
this.pointCtr1 = new PointControle(0,0,this);
3434
}
3535

3636
/**
@@ -54,6 +54,10 @@ public Arc(Place place, int poids){
5454
*/
5555
public Place getPlace() { return this.place; }
5656

57+
public Transition getTransition() { return transition; }
58+
59+
public boolean isPlaceToTransition() { return placeToTransition; }
60+
5761
/**
5862
* Méthode qui permet de récupérer le poids de l'arc.
5963
* @return poids.
@@ -70,7 +74,12 @@ public Arc(Place place, int poids){
7074
* Méthode qui permet de donner/modifier le poids d'un arc.
7175
* @param poids Poids de l'arc
7276
*/
73-
public void setPoids(int poids) { this.poids = poids; }
77+
public void setPoids(int poids) {
78+
if(poids >= 1) {
79+
this.poids = poids;
80+
}
81+
}
82+
7483

7584
/**
7685
* Méthode qui permet d'afficher les caractéristiques de l'arc : {place,poids}.
@@ -81,13 +90,20 @@ public String toString() {
8190
return "Arc{" +
8291
"place=" + place +
8392
", poids=" + poids +
93+
", placetoTransition=" + placeToTransition +
94+
", ptctrl= "+ pointCtr1+
8495
'}';
8596
}
8697

8798
/* Partie Graphique */
8899

89100
public Line2D.Double forme;
101+
public QuadCurve2D.Double courbe;
90102
public AffineTransform at;
103+
public AffineTransform reverse;
104+
public Path2D.Double hitbox;
105+
public Path2D arrowHead;
106+
91107

92108
/**
93109
* Méthode qui permet de dessiner un arc.
@@ -116,30 +132,63 @@ private void drawArrow(Graphics2D g2, double oX, double oY, double dX, double dY
116132
at.concatenate(AffineTransform.getRotateInstance(angle));
117133
g2.transform(at);
118134

135+
reverse = getReverseAt();
136+
119137
/* Ligne */
120138
if (!this.pointCtr1.getMoved()) {
121139
this.pointCtr1.setX((start + len-ARR_SIZE)/2);
122140
this.pointCtr1.setY(0);
123141
}
124142

125143
/*point de controle*/
126-
pointCtr1.draw(g2);
127-
128-
QuadCurve2D.Double courbe = new QuadCurve2D.Double(start, 0, this.pointCtr1.getX(), this.pointCtr1.getY(), len, 0);
129-
/* Référentiel */
144+
//pointCtr1.draw(g2);
130145

146+
courbe = new QuadCurve2D.Double(start, 0, this.pointCtr1.getX(), this.pointCtr1.getY(), len, 0);
131147
g2.draw(courbe);
132148

149+
150+
hitbox = new Path2D.Double(arcHitbox(len));
151+
//g2.draw(hitbox);
152+
153+
// Line between control Point and ArrowHead Point
154+
Line2D.Double line1 = new Line2D.Double(0,0,len,0);
155+
Line2D.Double line2 = new Line2D.Double(pointCtr1.getX(),pointCtr1.getY(),len,0);
156+
//g2.draw(line1);
157+
//g2.draw(line2);
158+
133159
/* Fléche */
134-
Path2D path = new Path2D.Double();
135-
double[] xval = {len, len-ARR_SIZE, len-ARR_SIZE, len};
136-
double[] yval = {0, -ARR_SIZE, ARR_SIZE, 0};
137-
path.moveTo(xval[0], yval[0]);
160+
arrowHead = new Path2D.Double();
161+
double[] xval = {line2.getX2(), line2.getX2()-ARR_SIZE, line2.getX2()-ARR_SIZE, line2.getX2()};
162+
double[] yval = {line2.getY2(), -ARR_SIZE, ARR_SIZE, line2.getY2()};
163+
arrowHead.moveTo(xval[0], yval[0]);
138164
for(int i = 1; i < xval.length; ++i) {
139-
path.lineTo(xval[i], yval[i]);
165+
arrowHead.lineTo(xval[i], yval[i]);
140166
}
141-
path.closePath();
142-
g2.fill(path);
167+
arrowHead.closePath();
168+
169+
AffineTransform rotate = new AffineTransform(AffineTransform.getRotateInstance(Math.toRadians(angleBetween2Lines(line1,line2)),line2.getX2(), line2.getY2()));
170+
arrowHead.transform(rotate);
171+
172+
g2.fill(arrowHead);
173+
174+
/* Affichage du poids */
175+
if(this.poids > 1 ) {
176+
g2.setFont(new Font("Console", Font.PLAIN, 15));
177+
if(this.placeToTransition && this.transition.getX() < this.place.getX() || !this.placeToTransition && this.place.getX() < this.transition.getX()){
178+
g2.scale(-1,-1);
179+
g2.drawString(Integer.toString(poids), (int) -courbe.getCtrlX(), (int) -(courbe.getCtrlY() - 15));
180+
g2.scale(1,1);
181+
}else {
182+
g2.drawString(Integer.toString(poids), (int) courbe.getCtrlX(), (int) courbe.getCtrlY() + 15);
183+
}
184+
}
185+
}
186+
187+
public static double angleBetween2Lines(Line2D.Double line1, Line2D.Double line2)
188+
{
189+
double angle1 = Math.atan2(line1.getY1() - line1.getY2(), line1.getX1() - line1.getX2());
190+
double angle2 = Math.atan2(line2.getY1() - line2.getY2(), line2.getX1() - line2.getX2());
191+
return -(Math.toDegrees(Math.abs(angle1-angle2))+360)%360;
143192
}
144193

145194
/**
@@ -173,6 +222,18 @@ public void draw(Graphics g) {
173222

174223
}
175224

225+
public Path2D.Double arcHitbox(double len){
226+
int ecart = 7;
227+
Path2D.Double hitbox = new Path2D.Double();
228+
hitbox.moveTo(this.place.forme.width/2,-ecart);
229+
hitbox.quadTo(this.pointCtr1.getX(),this.pointCtr1.getY() -ecart,len,-ecart);
230+
hitbox.lineTo(len,+ecart);
231+
hitbox.quadTo(this.pointCtr1.getX(),this.pointCtr1.getY()+ecart, this.place.forme.width/2,+ecart);
232+
hitbox.lineTo(this.place.forme.width/2,-ecart);
233+
hitbox.closePath();
234+
return hitbox;
235+
}
236+
176237
/**
177238
* Retourne true lorsque la différence absolue entre les coordonnées du point
178239
* d'origine et du point à comparer (toCompare) est inférieur à la valeur size
@@ -201,13 +262,16 @@ public boolean containsControlPoint1(double x, double y) {
201262
Point.Double point = new Point.Double(pointCtr1.getX(),pointCtr1.getY());
202263
Point2D.Double pointDest = new Point.Double();
203264

204-
at.transform(point, pointDest);
265+
getAt().transform(point, pointDest);
205266

206267
System.out.println("PtCtrlTRANSFORM:(" + pointDest.getX() + ":" + pointDest.getY() + ") PtCtrl:(" + pointCtr1.getX() + ":" + pointCtr1.getY()+ ")");
207268

208-
boolean res = containing(pointDest, pointCtr1.getSize(), new Point.Double(x,y));
209-
System.out.println(res);
210-
return res;
269+
boolean res = containing(pointDest, pointCtr1.getSize()+ pointCtr1.getSize()/2, new Point.Double(x,y));
270+
271+
boolean result = pointCtr1.contains(x,y);
272+
System.out.println(result);
273+
return result;
274+
211275
}
212276

213277
/**
@@ -218,6 +282,17 @@ public PointControle getPointCtr1() {
218282
return pointCtr1;
219283
}
220284

285+
public AffineTransform getAt() { return at; }
286+
287+
public AffineTransform getReverseAt() {
288+
try{
289+
return at.createInverse();
290+
} catch (Exception e) {
291+
e.printStackTrace();
292+
}
293+
return null;
294+
}
295+
221296
/**
222297
* Méthode qui permet de mettre à jour les coordonnées de l'arc.
223298
* @param x : x.

0 commit comments

Comments
 (0)