mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 08:25:09 -04:00
minor improvement of fsm layout
This commit is contained in:
parent
c41dc3a387
commit
5c43b39468
@ -9,8 +9,10 @@ import de.neemann.digital.analyse.expression.Expression;
|
|||||||
import de.neemann.digital.analyse.parser.ParseException;
|
import de.neemann.digital.analyse.parser.ParseException;
|
||||||
import de.neemann.digital.analyse.parser.Parser;
|
import de.neemann.digital.analyse.parser.Parser;
|
||||||
import de.neemann.digital.draw.graphics.*;
|
import de.neemann.digital.draw.graphics.*;
|
||||||
|
import de.neemann.digital.draw.graphics.Polygon;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -82,7 +84,7 @@ public class Transition extends Movable<Transition> {
|
|||||||
|
|
||||||
for (Transition t : transitions)
|
for (Transition t : transitions)
|
||||||
if (t != this)
|
if (t != this)
|
||||||
addRepulsive(t.getPos(), 1800);
|
addRepulsive(t.getPos(), 1500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,12 +95,16 @@ public class Transition extends Movable<Transition> {
|
|||||||
@Override
|
@Override
|
||||||
public void setPos(VectorFloat position) {
|
public void setPos(VectorFloat position) {
|
||||||
if (fromState != toState) {
|
if (fromState != toState) {
|
||||||
VectorFloat dist = fromState.getPos().sub(toState.getPos());
|
VectorFloat dist = toState.getPos().sub(fromState.getPos());
|
||||||
if (dist.getXFloat() != 0 || dist.getYFloat() != 0) {
|
if (dist.getXFloat() != 0 || dist.getYFloat() != 0) {
|
||||||
VectorFloat p = position.sub(fromState.getPos());
|
dist = dist.norm();
|
||||||
VectorFloat n = dist.getOrthogonal().norm();
|
VectorFloat start = fromState.getPos().add(dist.mul(fromState.getVisualRadius()));
|
||||||
|
VectorFloat end = toState.getPos().sub(dist.mul(toState.getVisualRadius()));
|
||||||
|
|
||||||
|
VectorFloat p = position.sub(start);
|
||||||
|
VectorFloat n = dist.getOrthogonal();
|
||||||
float l = p.mul(n);
|
float l = p.mul(n);
|
||||||
super.setPos(fromState.getPos().sub(dist.mul(0.5f)).add(n.mul(l)));
|
super.setPos(start.add(end).div(2).add(n.mul(l)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,48 +117,53 @@ public class Transition extends Movable<Transition> {
|
|||||||
* @param gr the Graphic instance to draw to
|
* @param gr the Graphic instance to draw to
|
||||||
*/
|
*/
|
||||||
public void drawTo(Graphic gr) {
|
public void drawTo(Graphic gr) {
|
||||||
|
final VectorFloat start;
|
||||||
VectorFloat anchorFrom = getPos();
|
final VectorFloat anchor;
|
||||||
VectorFloat anchorTo = getPos();
|
final VectorFloat end;
|
||||||
|
|
||||||
if (fromState == toState) {
|
if (fromState == toState) {
|
||||||
VectorFloat dif = anchorFrom.sub(fromState.getPos());
|
VectorFloat dif = getPos().sub(fromState.getPos()).getOrthogonal().mul(0.5f);
|
||||||
dif = new VectorFloat(dif.getYFloat(), -dif.getXFloat()).mul(0.3f);
|
VectorFloat ps = getPos().add(dif);
|
||||||
anchorFrom = anchorFrom.add(dif);
|
VectorFloat pe = getPos().sub(dif);
|
||||||
anchorTo = anchorTo.sub(dif);
|
start = fromState.getPos().add(
|
||||||
|
ps.sub(fromState.getPos()).norm().mul(fromState.getVisualRadius() + Style.MAXLINETHICK));
|
||||||
|
end = toState.getPos().add(
|
||||||
|
pe.sub(toState.getPos()).norm().mul(toState.getVisualRadius() + Style.MAXLINETHICK + 2));
|
||||||
|
} else {
|
||||||
|
start = fromState.getPos().add(
|
||||||
|
getPos().sub(fromState.getPos()).norm().mul(fromState.getVisualRadius() + Style.MAXLINETHICK));
|
||||||
|
end = toState.getPos().add(
|
||||||
|
getPos().sub(toState.getPos()).norm().mul(toState.getVisualRadius() + Style.MAXLINETHICK + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorFloat difFrom = anchorFrom.sub(fromState.getPos()).norm().mul(fromState.getVisualRadius() + Style.MAXLINETHICK);
|
|
||||||
VectorFloat difTo = anchorTo.sub(toState.getPos()).norm().mul(toState.getVisualRadius() + Style.MAXLINETHICK + 2);
|
|
||||||
VectorFloat difToTip = anchorTo.sub(toState.getPos()).norm().mul(toState.getVisualRadius() + Style.MAXLINETHICK);
|
|
||||||
|
|
||||||
final VectorFloat start = fromState.getPos().add(difFrom);
|
|
||||||
final VectorFloat end = toState.getPos().add(difTo);
|
|
||||||
final VectorFloat arrowTip = toState.getPos().add(difToTip);
|
|
||||||
|
|
||||||
Polygon p = new Polygon(false)
|
|
||||||
.add(start);
|
|
||||||
|
|
||||||
if (anchorFrom.equals(anchorTo))
|
|
||||||
p.add(anchorFrom, end);
|
|
||||||
else
|
|
||||||
p.add(anchorFrom, anchorTo, end);
|
|
||||||
|
|
||||||
final Style arrowStyle = Style.SHAPE_PIN;
|
final Style arrowStyle = Style.SHAPE_PIN;
|
||||||
gr.drawPolygon(p, arrowStyle);
|
// arrow line
|
||||||
|
anchor = getPos().mul(2).sub(start.div(2)).sub(end.div(2));
|
||||||
|
gr.drawPolygon(new Polygon(false).add(start).add(anchor, end), arrowStyle);
|
||||||
|
|
||||||
// arrow
|
// arrowhead
|
||||||
VectorFloat lot = difTo.getOrthogonal().mul(0.5f);
|
VectorFloat dir = anchor.sub(end).norm().mul(20);
|
||||||
|
VectorFloat lot = dir.getOrthogonal().mul(0.3f);
|
||||||
gr.drawPolygon(new Polygon(false)
|
gr.drawPolygon(new Polygon(false)
|
||||||
.add(end.add(difTo.add(lot).mul(0.2f)))
|
.add(end.add(dir).add(lot))
|
||||||
.add(arrowTip)
|
.add(end.sub(dir.mul(0.1f)))
|
||||||
.add(end.add(difTo.sub(lot).mul(0.2f))), arrowStyle);
|
.add(end.add(dir).sub(lot)), arrowStyle);
|
||||||
|
|
||||||
|
// text
|
||||||
|
VectorFloat textPos = getPos();
|
||||||
|
final int fontSize = Style.NORMAL.getFontSize();
|
||||||
|
if (fromState.getPos().getYFloat() < getPos().getYFloat()
|
||||||
|
&& toState.getPos().getYFloat() < getPos().getYFloat())
|
||||||
|
textPos = textPos.add(new VectorFloat(0, fontSize / 2f));
|
||||||
|
if (fromState.getPos().getYFloat() > getPos().getYFloat()
|
||||||
|
&& toState.getPos().getYFloat() > getPos().getYFloat())
|
||||||
|
textPos = textPos.add(new VectorFloat(0, -fontSize / 2f));
|
||||||
|
|
||||||
if (condition != null && condition.length() > 0) {
|
if (condition != null && condition.length() > 0) {
|
||||||
gr.drawText(getPos(), getPos().add(new Vector(1, 0)), condition, Orientation.CENTERCENTER, Style.INOUT);
|
gr.drawText(textPos, textPos.add(new Vector(1, 0)), condition, Orientation.CENTERCENTER, Style.INOUT);
|
||||||
}
|
}
|
||||||
if (getValues() != null && getValues().length() > 0) {
|
if (getValues() != null && getValues().length() > 0) {
|
||||||
VectorFloat pos = getPos().add(new VectorFloat(0, Style.NORMAL.getFontSize()));
|
textPos = textPos.add(new VectorFloat(0, fontSize));
|
||||||
gr.drawText(pos, pos.add(new Vector(1, 0)), Lang.get("fsm_set_N", getValues()), Orientation.CENTERCENTER, Style.INOUT);
|
gr.drawText(textPos, textPos.add(new Vector(1, 0)), Lang.get("fsm_set_N", getValues()), Orientation.CENTERCENTER, Style.INOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user