use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class SelectionBase method hasConflictTranslated.
private boolean hasConflictTranslated(Collection<Component> components, int dx, int dy, boolean selfConflicts) {
Circuit circuit = proj.getCurrentCircuit();
if (circuit == null)
return false;
for (Component comp : components) {
if (!(comp instanceof Wire)) {
for (EndData endData : comp.getEnds()) {
if (endData != null && endData.isExclusive()) {
Location endLoc = endData.getLocation().translate(dx, dy);
Component conflict = circuit.getExclusive(endLoc);
if (conflict != null) {
if (selfConflicts || !components.contains(conflict))
return true;
}
}
}
Location newLoc = comp.getLocation().translate(dx, dy);
Bounds newBounds = comp.getBounds().translate(dx, dy);
for (Component comp2 : circuit.getAllContaining(newLoc)) {
Bounds bds = comp2.getBounds();
if (bds.equals(newBounds)) {
if (selfConflicts || !components.contains(comp2))
return true;
}
}
}
}
return false;
}
use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class Netlist method WarningTraceForGatedClock.
private void WarningTraceForGatedClock(ConnectionPoint Source, int index, ArrayList<Netlist> HierarchyNetlists, ArrayList<String> HierarchyNames, FPGAReport Reporter) {
Component comp = Source.GetComp();
if (comp.getFactory() instanceof Pin) {
if (HierarchyNames.isEmpty())
/* we cannot go up at toplevel, so leave */
return;
int idx = -1;
for (int i = 0; i < MyInputPorts.size(); i++) {
if (MyInputPorts.get(i).GetComponent().equals(comp))
idx = i;
}
if (idx < 0) {
Reporter.AddFatalError("BUG: Could not find port!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
ConnectionPoint SubNet = HierarchyNetlists.get(HierarchyNetlists.size() - 2).GetNetlistConnectionForSubCircuitInput(HierarchyNames.get(HierarchyNames.size() - 1), idx, (byte) index);
if (SubNet == null) {
Reporter.AddFatalError("BUG: Could not find a sub-circuit connection in overlying hierarchy level!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
if (SubNet.GetParrentNet() != null) {
ArrayList<String> NewHierarchyNames = new ArrayList<String>();
ArrayList<Netlist> NewHierarchyNetlists = new ArrayList<Netlist>();
NewHierarchyNames.addAll(HierarchyNames);
NewHierarchyNames.remove(NewHierarchyNames.size() - 1);
NewHierarchyNetlists.addAll(HierarchyNetlists);
NewHierarchyNetlists.remove(NewHierarchyNetlists.size() - 1);
Netlist SubNetList = HierarchyNetlists.get(HierarchyNetlists.size() - 2);
Net NewNet = SubNet.GetParrentNet();
Byte NewNetIndex = SubNet.GetParrentNetBitIndex();
Set<Wire> Segments = new HashSet<Wire>();
SourceInfo source = SubNetList.GetHiddenSource(NewNet, NewNetIndex, SubNetList.MyComplexSplitters, null, new HashSet<String>(), Segments, Reporter);
if (source == null) {
Reporter.AddFatalError("BUG: Unable to find source in sub-circuit!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
ComponentFactory sfac = source.getSource().GetComp().getFactory();
if (sfac instanceof Pin || sfac instanceof SubcircuitFactory) {
SimpleDRCContainer warn = new SimpleDRCContainer(SubNetList.getCircuit(), Strings.get("NetList_GatedClockInt"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE, true);
warn.AddMarkComponents(Segments);
Reporter.AddWarning(warn);
SubNetList.WarningTraceForGatedClock(source.getSource(), source.getIndex(), NewHierarchyNetlists, NewHierarchyNames, Reporter);
} else {
SimpleDRCContainer warn = new SimpleDRCContainer(SubNetList.getCircuit(), Strings.get("NetList_GatedClockSource"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE, true);
warn.AddMarkComponents(Segments);
Reporter.AddWarning(warn);
}
}
}
if (comp.getFactory() instanceof SubcircuitFactory) {
/* TODO */
SubcircuitFactory sub = (SubcircuitFactory) comp.getFactory();
if (Source.getChildsPortIndex() < 0) {
Reporter.AddFatalError("BUG: Subcircuit port is not annotated!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
NetlistComponent OutputPort = sub.getSubcircuit().getNetList().GetOutputPin(Source.getChildsPortIndex());
if (OutputPort == null) {
Reporter.AddFatalError("BUG: Unable to find Subcircuit output port!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
Net ConnectedNet = Source.GetParrentNet();
/* Find the correct subcircuit */
NetlistComponent SubCirc = null;
for (NetlistComponent subc : MySubCircuits) {
if (subc.GetComponent().equals(Source.GetComp()))
SubCirc = subc;
}
if (SubCirc == null) {
Reporter.AddFatalError("BUG: Unable to find Subcircuit!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
byte BitIndex = SubCirc.GetConnectionBitIndex(ConnectedNet, (byte) index);
if (BitIndex < 0) {
Reporter.AddFatalError("BUG: Unable to find the bit index of a Subcircuit output port!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
ConnectionPoint SubNet = OutputPort.getEnd(0).GetConnection(BitIndex);
if (SubNet.GetParrentNet() != null) {
/* we have a connected pin */
Netlist SubNetList = sub.getSubcircuit().getNetList();
ArrayList<String> NewHierarchyNames = new ArrayList<String>();
ArrayList<Netlist> NewHierarchyNetlists = new ArrayList<Netlist>();
NewHierarchyNames.addAll(HierarchyNames);
NewHierarchyNames.add(CorrectLabel.getCorrectLabel(SubCirc.GetComponent().getAttributeSet().getValue(StdAttr.LABEL)));
NewHierarchyNetlists.addAll(HierarchyNetlists);
NewHierarchyNetlists.add(SubNetList);
Net NewNet = SubNet.GetParrentNet();
Byte NewNetIndex = SubNet.GetParrentNetBitIndex();
Set<Wire> Segments = new HashSet<Wire>();
SourceInfo source = SubNetList.GetHiddenSource(NewNet, NewNetIndex, SubNetList.MyComplexSplitters, null, new HashSet<String>(), Segments, Reporter);
if (source == null) {
Reporter.AddFatalError("BUG: Unable to find source in sub-circuit!\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return;
}
ComponentFactory sfac = source.getSource().GetComp().getFactory();
if (sfac instanceof Pin || sfac instanceof SubcircuitFactory) {
SimpleDRCContainer warn = new SimpleDRCContainer(SubNetList.getCircuit(), Strings.get("NetList_GatedClockInt"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE, true);
warn.AddMarkComponents(Segments);
Reporter.AddWarning(warn);
SubNetList.WarningTraceForGatedClock(source.getSource(), source.getIndex(), NewHierarchyNetlists, NewHierarchyNames, Reporter);
} else {
SimpleDRCContainer warn = new SimpleDRCContainer(SubNetList.getCircuit(), Strings.get("NetList_GatedClockSource"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE, true);
warn.AddMarkComponents(Segments);
Reporter.AddWarning(warn);
}
}
}
}
use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class PokeTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
boolean dirty = false;
canvas.setHighlightedWires(WireSet.EMPTY);
if (pokeCaret != null && !pokeCaret.getBounds(g).contains(loc)) {
dirty = true;
removeCaret(true);
}
if (pokeCaret == null) {
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
Circuit circ = canvas.getCircuit();
for (Component c : circ.getAllContaining(loc, g)) {
if (pokeCaret != null)
break;
if (c instanceof Wire) {
Caret caret = new WireCaret(canvas, (Wire) c, x, y, canvas.getProject().getOptions().getAttributeSet());
setPokedComponent(circ, c, caret);
canvas.setHighlightedWires(circ.getWireSet((Wire) c));
} else {
Pokable p = (Pokable) c.getFeature(Pokable.class);
if (p != null) {
Caret caret = p.getPokeCaret(event);
setPokedComponent(circ, c, caret);
AttributeSet attrs = c.getAttributeSet();
if (attrs != null && attrs.getAttributes().size() > 0) {
Project proj = canvas.getProject();
proj.getFrame().viewComponentAttributes(circ, c);
}
}
}
}
}
if (pokeCaret != null) {
dirty = true;
pokeCaret.mousePressed(e);
}
if (dirty)
canvas.getProject().repaintCanvas();
}
use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class SelectTool method draw.
@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
Project proj = canvas.getProject();
int dx = curDx;
int dy = curDy;
if (state == MOVING) {
proj.getSelection().drawGhostsShifted(context, dx, dy);
MoveGesture gesture = moveGesture;
if (gesture != null && drawConnections && (dx != 0 || dy != 0)) {
MoveResult result = gesture.findResult(dx, dy);
if (result != null) {
Collection<Wire> wiresToAdd = result.getWiresToAdd();
Graphics g = context.getGraphics();
GraphicsUtil.switchToWidth(g, 3);
g.setColor(Color.GRAY);
for (Wire w : wiresToAdd) {
Location loc0 = w.getEnd0();
Location loc1 = w.getEnd1();
g.drawLine(loc0.getX(), loc0.getY(), loc1.getX(), loc1.getY());
}
GraphicsUtil.switchToWidth(g, 1);
g.setColor(COLOR_UNMATCHED);
for (Location conn : result.getUnconnectedLocations()) {
int connX = conn.getX();
int connY = conn.getY();
g.fillOval(connX - 3, connY - 3, 6, 6);
g.fillOval(connX + dx - 3, connY + dy - 3, 6, 6);
}
}
}
} else if (state == RECT_SELECT) {
int left = start.getX();
int right = left + dx;
if (left > right) {
int i = left;
left = right;
right = i;
}
int top = start.getY();
int bot = top + dy;
if (top > bot) {
int i = top;
top = bot;
bot = i;
}
Graphics gBase = context.getGraphics();
int w = right - left - 1;
int h = bot - top - 1;
if (w > 2 && h > 2) {
gBase.setColor(BACKGROUND_RECT_SELECT);
gBase.fillRect(left + 1, top + 1, w - 1, h - 1);
}
Circuit circ = canvas.getCircuit();
Bounds bds = Bounds.create(left, top, right - left, bot - top);
for (Component c : circ.getAllWithin(bds)) {
Location cloc = c.getLocation();
Graphics gDup = gBase.create();
context.setGraphics(gDup);
c.getFactory().drawGhost(context, COLOR_RECT_SELECT, cloc.getX(), cloc.getY(), c.getAttributeSet());
gDup.dispose();
}
gBase.setColor(COLOR_RECT_SELECT);
GraphicsUtil.switchToWidth(gBase, 2);
if (w < 0)
w = 0;
if (h < 0)
h = 0;
gBase.drawRect(left, top, w, h);
}
}
use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class EditTool method isWiringPoint.
private boolean isWiringPoint(Canvas canvas, Location loc, int modsEx) {
boolean wiring = (modsEx & MouseEvent.ALT_DOWN_MASK) == 0;
boolean select = !wiring;
if (canvas != null && canvas.getSelection() != null) {
Collection<Component> sel = canvas.getSelection().getComponents();
if (sel != null) {
for (Component c : sel) {
if (c instanceof Wire) {
Wire w = (Wire) c;
if (w.contains(loc) && !w.endsAt(loc))
return select;
}
}
}
}
Circuit circ = canvas.getCircuit();
Collection<? extends Component> at = circ.getComponents(loc);
if (at != null && at.size() > 0)
return wiring;
for (Wire w : circ.getWires()) {
if (w.contains(loc)) {
return wiring;
}
}
return select;
}
Aggregations