use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Netlist method HasGatedClock.
private boolean HasGatedClock(NetlistComponent comp, int ClockPinIndex, List<SourceInfo> PinSources, List<Set<Wire>> PinWires, List<Set<NetlistComponent>> PinGatedComponents, List<SourceInfo> NonPinSources, List<Set<Wire>> NonPinWires, List<Set<NetlistComponent>> NonPinGatedComponents, Set<NetlistComponent> WarnedComponents, FPGAReport Reporter) {
boolean GatedClock = false;
String ClockNetName = AbstractHDLGeneratorFactory.GetClockNetName(comp, ClockPinIndex, this);
if (ClockNetName.isEmpty()) {
/* we search for the source in case it is connected otherwise we ignore */
ConnectionPoint connection = comp.getEnd(ClockPinIndex).GetConnection((byte) 0);
Net connectedNet = connection.GetParrentNet();
byte connectedNetindex = connection.GetParrentNetBitIndex();
if (connectedNet != null) {
GatedClock = true;
if (connectedNet.IsForcedRootNet()) {
Set<Wire> Segments = new HashSet<Wire>();
Location loc = comp.GetComponent().getEnd(ClockPinIndex).getLocation();
for (Net thisOne : MyNets) if (thisOne.contains(loc)) {
if (!thisOne.IsRootNet())
Segments.addAll(thisOne.getWires());
}
SourceInfo SourceList = GetHiddenSource(connectedNet, connectedNetindex, MyComplexSplitters, null, new HashSet<String>(), Segments, Reporter);
ConnectionPoint source = SourceList.getSource();
if (source.GetComp().getFactory() instanceof Pin) {
int index = IndexOfEntry(PinSources, source, (int) connectedNetindex);
if (index < 0) {
PinSources.add(SourceList);
PinWires.add(Segments);
Set<NetlistComponent> comps = new HashSet<NetlistComponent>();
comps.add(comp);
comps.add(new NetlistComponent(source.GetComp()));
PinGatedComponents.add(comps);
} else {
PinGatedComponents.get(index).add(comp);
}
} else {
int index = IndexOfEntry(NonPinSources, source, (int) connectedNetindex);
if (index < 0) {
NonPinSources.add(SourceList);
NonPinWires.add(Segments);
Set<NetlistComponent> comps = new HashSet<NetlistComponent>();
comps.add(comp);
NonPinGatedComponents.add(comps);
} else {
NonPinGatedComponents.get(index).add(comp);
}
}
} else {
ArrayList<ConnectionPoint> SourceList = connectedNet.GetBitSources(connectedNetindex);
if (SourceList.size() != 1) {
Reporter.AddFatalError("BUG: Found multiple sources\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return GatedClock;
}
ConnectionPoint source = SourceList.get(0);
if (source.GetComp().getFactory() instanceof Pin) {
int index = IndexOfEntry(PinSources, source, (int) connectedNetindex);
if (index < 0) {
SourceInfo NewEntry = new SourceInfo(source, connectedNetindex);
PinSources.add(NewEntry);
PinWires.add(connectedNet.getWires());
Set<NetlistComponent> comps = new HashSet<NetlistComponent>();
comps.add(comp);
PinGatedComponents.add(comps);
} else {
PinGatedComponents.get(index).add(comp);
}
} else {
int index = IndexOfEntry(NonPinSources, source, (int) connectedNetindex);
if (index < 0) {
SourceInfo NewEntry = new SourceInfo(source, connectedNetindex);
NonPinSources.add(NewEntry);
NonPinWires.add(connectedNet.getWires());
Set<NetlistComponent> comps = new HashSet<NetlistComponent>();
comps.add(comp);
NonPinGatedComponents.add(comps);
} else {
NonPinGatedComponents.get(index).add(comp);
}
}
}
} else {
/* Add severe warning, we found a memory with an unconnected clock input */
if (!WarnedComponents.contains(comp)) {
SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_NoClockConnection"), SimpleDRCContainer.LEVEL_SEVERE, SimpleDRCContainer.MARK_INSTANCE);
warn.AddMarkComponent(comp.GetComponent());
Reporter.AddWarning(warn);
WarnedComponents.add(comp);
}
}
}
return GatedClock;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class CanvasPainter method drawWidthIncompatibilityData.
private void drawWidthIncompatibilityData(Graphics base, Graphics g, Project proj) {
Set<WidthIncompatibilityData> exceptions;
exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
if (exceptions == null || exceptions.size() == 0)
return;
g.setColor(Value.WIDTH_ERROR_COLOR);
GraphicsUtil.switchToWidth(g, 2);
FontMetrics fm = base.getFontMetrics(g.getFont());
for (WidthIncompatibilityData ex : exceptions) {
for (int i = 0; i < ex.size(); i++) {
Location p = ex.getPoint(i);
BitWidth w = ex.getBitWidth(i);
// ensure it hasn't already been drawn
boolean drawn = false;
for (int j = 0; j < i; j++) {
if (ex.getPoint(j).equals(p)) {
drawn = true;
break;
}
}
if (drawn)
continue;
// compute the caption combining all similar points
String caption = "" + w.getWidth();
for (int j = i + 1; j < ex.size(); j++) {
if (ex.getPoint(j).equals(p)) {
caption += "/" + ex.getBitWidth(j);
break;
}
}
g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
g.drawString(caption, p.getX() + 5, p.getY() + 2 + fm.getAscent());
}
}
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 1);
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class SelectionActions method getReplacementMap.
private static HashMap<Component, Component> getReplacementMap(Project proj) {
HashMap<Component, Component> replMap;
replMap = new HashMap<Component, Component>();
LogisimFile file = proj.getLogisimFile();
ArrayList<Library> libs = new ArrayList<Library>();
libs.add(file);
libs.addAll(file.getLibraries());
ArrayList<String> dropped = null;
Clipboard clip = Clipboard.get();
Collection<Component> comps = clip.getComponents();
HashMap<ComponentFactory, ComponentFactory> factoryReplacements;
factoryReplacements = new HashMap<ComponentFactory, ComponentFactory>();
for (Component comp : comps) {
if (comp instanceof Wire)
continue;
ComponentFactory compFactory = comp.getFactory();
ComponentFactory copyFactory = findComponentFactory(compFactory, libs, false);
if (factoryReplacements.containsKey(compFactory)) {
copyFactory = factoryReplacements.get(compFactory);
} else if (copyFactory == null) {
ComponentFactory candidate = findComponentFactory(compFactory, libs, true);
if (candidate == null) {
if (dropped == null) {
dropped = new ArrayList<String>();
}
dropped.add(compFactory.getDisplayName());
} else {
String msg = Strings.get("pasteCloneQuery", compFactory.getName());
Object[] opts = { Strings.get("pasteCloneReplace"), Strings.get("pasteCloneIgnore"), Strings.get("pasteCloneCancel") };
int select = JOptionPane.showOptionDialog(proj.getFrame(), msg, Strings.get("pasteCloneTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]);
if (select == 0) {
copyFactory = candidate;
} else if (select == 1) {
copyFactory = null;
} else {
return null;
}
factoryReplacements.put(compFactory, copyFactory);
}
}
if (copyFactory == null) {
replMap.put(comp, null);
} else if (copyFactory != compFactory) {
Location copyLoc = comp.getLocation();
AttributeSet copyAttrs = (AttributeSet) comp.getAttributeSet().clone();
Component copy = copyFactory.createComponent(copyLoc, copyAttrs);
replMap.put(comp, copy);
}
}
if (dropped != null) {
Collections.sort(dropped);
StringBuilder droppedStr = new StringBuilder();
droppedStr.append(Strings.get("pasteDropMessage"));
String curName = dropped.get(0);
int curCount = 1;
int lines = 1;
for (int i = 1; i <= dropped.size(); i++) {
String nextName = i == dropped.size() ? "" : dropped.get(i);
if (nextName.equals(curName)) {
curCount++;
} else {
lines++;
droppedStr.append("\n ");
droppedStr.append(curName);
if (curCount > 1) {
droppedStr.append(" \u00d7 " + curCount);
}
curName = nextName;
curCount = 1;
}
}
lines = Math.max(3, Math.min(7, lines));
JTextArea area = new JTextArea(lines, 60);
area.setEditable(false);
area.setText(droppedStr.toString());
area.setCaretPosition(0);
JScrollPane areaPane = new JScrollPane(area);
JOptionPane.showMessageDialog(proj.getFrame(), areaPane, Strings.get("pasteDropTitle"), JOptionPane.WARNING_MESSAGE);
}
return replMap;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class SelectionBase method copyComponents.
private HashMap<Component, Component> copyComponents(Collection<Component> components, int dx, int dy) {
HashMap<Component, Component> ret = new HashMap<Component, Component>();
for (Component comp : components) {
Location oldLoc = comp.getLocation();
AttributeSet attrs = (AttributeSet) comp.getAttributeSet().clone();
int newX = oldLoc.getX() + dx;
int newY = oldLoc.getY() + dy;
Object snap = comp.getFactory().getFeature(ComponentFactory.SHOULD_SNAP, attrs);
if (snap == null || ((Boolean) snap).booleanValue()) {
newX = Canvas.snapXToGrid(newX);
newY = Canvas.snapYToGrid(newY);
}
Location newLoc = Location.create(newX, newY);
Component copy = comp.getFactory().createComponent(newLoc, attrs);
ret.put(comp, copy);
}
return ret;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Canvas method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
boolean showTips = AppPreferences.COMPONENT_TIPS.getBoolean();
if (showTips) {
Canvas.snapToGrid(event);
Location loc = Location.create(event.getX(), event.getY());
ComponentUserEvent e = null;
for (Component comp : getCircuit().getAllContaining(loc)) {
Object makerObj = comp.getFeature(ToolTipMaker.class);
if (makerObj != null && makerObj instanceof ToolTipMaker) {
ToolTipMaker maker = (ToolTipMaker) makerObj;
if (e == null) {
e = new ComponentUserEvent(this, loc.getX(), loc.getY());
}
String ret = maker.getToolTip(e);
if (ret != null) {
unrepairMouseEvent(event);
return ret;
}
}
}
}
return null;
}
Aggregations