Skip to content

Commit

Permalink
Hide fanout in Instance panel of Function Component tool
Browse files Browse the repository at this point in the history
  • Loading branch information
danilovesky committed Nov 15, 2024
1 parent e492842 commit c7a06fc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ public void drawContactNames(DrawRequest r) {
g.setTransform(savedTransform);
}

public boolean getFanoutVisibility() {
return CircuitSettings.getShowContactFanout();
}

@Override
public Rectangle2D getInternalBoundingBoxInLocalSpace() {
if ((groupImpl != null) && (internalBB == null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ public void draw(DrawRequest r) {
}
g.transform(rotateTransform);

boolean showContact = r.getModel().getMathModel().getConnections(this.getReferencedComponent()).isEmpty()
|| (d instanceof StateDecoration) || (d.getColorisation() != null) || (d.getBackground() != null);
boolean isDisconnected = r.getModel().getMathModel().getConnections(this.getReferencedComponent()).isEmpty();
boolean showContact = isDisconnected || (d instanceof StateDecoration)
|| (d.getColorisation() != null) || (d.getBackground() != null);

if (showContact || isPort()) {
boolean showForcedInit = (d instanceof StateDecoration) && ((StateDecoration) d).showForcedInit();
Expand All @@ -278,7 +279,7 @@ public void draw(DrawRequest r) {
g.fill(VisualJoint.shape);
}

if (CircuitSettings.getShowContactFanout() && isDriver()) {
if (getFanoutVisibility()) {
g.setTransform(savedTransform);
if ((getDirection() == Direction.NORTH) || (getDirection() == Direction.SOUTH)) {
rotateTransform.setToIdentity();
Expand All @@ -303,6 +304,17 @@ public void draw(DrawRequest r) {
d.decorate(g);
}

public boolean getFanoutVisibility() {
if (!isDriver()) {
return false;
}
if (getParent() instanceof VisualCircuitComponent component) {
return component.getFanoutVisibility();
} else {
return CircuitSettings.getShowContactFanout();
}
}

public Font getFanoutFont() {
return FANOUT_FONT.deriveFont((float) CircuitSettings.getContactFontSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class VisualFunctionContact extends VisualContact implements StateObserve

private enum ArrowType { UP, DOWN }

private static final double X_FUNC_OFFSET_SCALE = 0.9;
private static final double FORMULA_OFFSET_SCALE = 0.9;
private static final double ARROW_WIDTH_SCALE = 0.5;

private static final Font functionFont = new Font(Font.SANS_SERIF, Font.PLAIN, 1);
Expand Down Expand Up @@ -104,9 +104,13 @@ private FormulaRenderingResult getRenderedSetFunction() {
return renderedSetFunction;
}

private double getFormulaScaleOffset() {
return getFanoutVisibility() ? FORMULA_OFFSET_SCALE : 0.0;
}

private Point2D getSetFormulaOffset() {
double s = CircuitSettings.getContactFontSize();
double xOffset = (X_FUNC_OFFSET_SCALE + ARROW_WIDTH_SCALE) * s;
double xOffset = (getFormulaScaleOffset() + ARROW_WIDTH_SCALE) * s;
double yOffset = -0.4 * CircuitSettings.getContactFontSize();
FormulaRenderingResult renderingResult = getRenderedSetFunction();
if (renderingResult != null) {
Expand All @@ -115,7 +119,7 @@ private Point2D getSetFormulaOffset() {
dir = dir.flip();
}
if ((dir == Direction.SOUTH) || (dir == Direction.WEST)) {
xOffset = -X_FUNC_OFFSET_SCALE * s - renderingResult.boundingBox.getWidth();
xOffset = -s * getFormulaScaleOffset() - renderingResult.boundingBox.getWidth();
}
}
return new Point2D.Double(xOffset, yOffset);
Expand Down Expand Up @@ -155,7 +159,7 @@ private FormulaRenderingResult getRenderedResetFunction() {

private Point2D getResetFormulaOffset() {
double s = CircuitSettings.getContactFontSize();
double xOffset = (X_FUNC_OFFSET_SCALE + ARROW_WIDTH_SCALE) * s;
double xOffset = (getFormulaScaleOffset() + ARROW_WIDTH_SCALE) * s;
double yOffset = 0.3 * s;
FormulaRenderingResult renderingResult = getRenderedResetFunction();
if (renderingResult != null) {
Expand All @@ -164,9 +168,9 @@ private Point2D getResetFormulaOffset() {
dir = dir.flip();
}
if ((dir == Direction.SOUTH) || (dir == Direction.WEST)) {
xOffset = -X_FUNC_OFFSET_SCALE * s - renderingResult.boundingBox.getWidth();
xOffset = -s * getFormulaScaleOffset() - renderingResult.boundingBox.getWidth();
}
yOffset -= renderingResult.getBoundingBox().getY(); // + renderingResult.boundingBox.getHeight();
yOffset -= renderingResult.getBoundingBox().getY();
}
return new Point2D.Double(xOffset, yOffset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public void update() {
public boolean getNameVisibility() {
return false;
}

@Override
public boolean getLabelVisibility() {
return true;
}

@Override
public boolean getFanoutVisibility() {
return false;
}
};
circuit.getMathModel().add(component.getReferencedComponent());
circuit.add(component);
Expand Down

0 comments on commit c7a06fc

Please sign in to comment.