public void refresh() { GateContact.StateType res = (complexOrAnd) ? GateContact.StateType.set : GateContact.StateType.reset; for (SubGate sg : subGates) { GateContact.StateType inres = (complexOrAnd) ? GateContact.StateType.reset : GateContact.StateType.set; for (GateContact cin : sg.in) { if (cin.getState() == GateContact.StateType.reset) { if (!complexOrAnd) { inres = GateContact.StateType.reset; break; } } else { if (complexOrAnd) { inres = GateContact.StateType.set; break; } } } if (inres == GateContact.StateType.reset) { if (complexOrAnd) { res = GateContact.StateType.reset; break; } } else { if (!complexOrAnd) { res = GateContact.StateType.set; break; } } } out.getFirst().setState(res); super.refresh(); }
public void doDraw(Painter p) { super.doDraw(p); p.setShapeMode(ShapeMode.FILL_AND_OUTLINE); p.setLineMode(LineMode.SOLID); p.setLineWidth(0.0075f); p.setLineColor((selected) ? selectedOutlineColor : (canWork) ? userOutlineColor : outlineColor); p.setFillColor( (selected) ? selectedFillColor : (canFire) ? enabledFillColor : (lostSignal) ? lostSignalFillColor : fillColor); for (SubGate sg : subGates) { if (sg.in.size() < 2) continue; p.setTransform(transform.getLocalToViewMatrix()); p.translate(-rad * 0.75f, -sg.y); p.drawShape((complexOrAnd) ? or_shape : and_shape); } p.setTransform(transform.getLocalToViewMatrix()); p.translate(-((complexOrAnd) ? -subrad : -subrad + rad * 0.1f), 0.0f); p.drawShape((!complexOrAnd) ? or_shape : and_shape); // draw invertion circles for (GateContact c : in) { c.doDrawInvert(p); } out.getFirst().doDrawInvert(p); }
private String getFunction(String self) { boolean first = true; String s = ""; for (SubGate sg : subGates) { if (!first) s += (complexOrAnd) ? " & " : " | "; first = false; boolean sfirst = true; s += "("; for (GateContact c : sg.in) { if (!sfirst) s += (!complexOrAnd) ? " & " : " | "; sfirst = false; s += c.getSrcFunction(self); } s += ")"; } if (out.getFirst().getInvertSignal()) s = "not (" + s + ")"; return s; }
protected void updateContactOffsets() { if (fixed_radius > 0) { subrad = fixed_radius * distContacts / 2; } else { subrad = aveContacts * distContacts / 2; if (subrad < 0.05f) subrad = 0.05f; } rad = subrad * (subGates.size() - nSingle) + distContacts * nSingle / 2; float xrad = rad * 0.75f + subrad; boundingBox.setExtents(new Vec2(-xrad, -rad), new Vec2(xrad, rad)); float ygstart = -rad; for (SubGate sg : subGates) { if (sg.in.size() < 2) { sg.in.getFirst().setOffs(new Vec2(xrad + 0.05f, ygstart + distContacts / 2)); if (!complexOrAnd) { float rx = rad * 0.85f; float ry = rad; Bezier leftside = new Bezier( new Vec2(-rx, -ry), new Vec2(-rx * 0.5f, -ry * 0.5f), new Vec2(-rx * 0.5f, ry * 0.5f), new Vec2(-rx, ry)); Vec2 pt = leftside.Point((ygstart + distContacts / 2 + rad) / 2.0f / rad); pt.sub(new Vec2(-subrad + rad * 0.1f, 0.0f)); sg.in.getFirst().offsInvX = -pt.getX(); } else { sg.in.getFirst().offsInvX = xrad - subrad * 2; } ygstart += distContacts; } else { int i = 0; float dc = 2 * subrad / sg.in.size(); float ystart = -((sg.in.size() - 1) * dc) / 2; sg.y = ygstart + subrad; for (GateContact c : sg.in) { Vec2 offs = new Vec2(); offs.setXY(xrad + 0.05f, ygstart + subrad + ystart + i * dc); c.setOffs(offs); i++; } if (complexOrAnd) { float rx = subrad; float ry = subrad * 0.95f; Bezier leftside = new Bezier( new Vec2(-rx, -ry), new Vec2(-rx * 0.5f, -ry * 0.5f), new Vec2(-rx * 0.5f, ry * 0.5f), new Vec2(-rx, ry)); i = 0; for (GateContact c : sg.in) { Vec2 pt = leftside.Point((ystart + i * dc + subrad) / 2.0f / subrad); pt.sub(new Vec2(rad * 0.75f, sg.y)); c.offsInvX = -pt.getX(); i++; } } else { for (GateContact c : sg.in) { c.offsInvX = xrad - subrad * 0.25f; } } ygstart += subrad * 2; } } out.getFirst().setOffs(new Vec2(-xrad - 0.05f, 0.0f)); out.getFirst().offsInvX = -xrad; and_shape = createAndShape(); or_shape = createOrShape(); }