use of com.bfh.logisim.fpgaboardeditor.BoardRectangle in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method GetSelectableItemsList.
public ArrayList<BoardRectangle> GetSelectableItemsList(String DisplayName, BoardInformation BoardInfo) {
ArrayList<BoardRectangle> List;
ArrayList<String> key = GetHierarchyKey(DisplayName);
NetlistComponent comp = myMappableResources.get(key);
int pinNeeded = comp.GetIOInformationContainer().GetNrOfInOutports() + comp.GetIOInformationContainer().GetNrOfInports() + comp.GetIOInformationContainer().GetNrOfOutports();
/* first check main map type */
if (!comp.AlternateMappingEnabled(key)) {
List = BoardInfo.GetIoComponentsOfType(comp.GetIOInformationContainer().GetMainMapType(), pinNeeded);
if (!List.isEmpty()) {
return RemoveUsedItems(List, 0);
}
}
List = new ArrayList<BoardRectangle>();
int MapId = 0;
IOComponentTypes MapType;
do {
MapType = comp.GetIOInformationContainer().GetAlternateMapType(MapId);
List.addAll(BoardInfo.GetIoComponentsOfType(MapType, 0));
MapId++;
} while (MapType != IOComponentTypes.Unknown);
return RemoveUsedItems(List, pinNeeded);
}
use of com.bfh.logisim.fpgaboardeditor.BoardRectangle in project logisim-evolution by reds-heig.
the class ComponentMapDialog method Load.
private void Load() {
JFileChooser fc = new JFileChooser(OldDirectory);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setDialogTitle("Choose XML board description file to use");
FileFilter XML_FILTER = new XMLFileFilter();
fc.setFileFilter(XML_FILTER);
fc.setAcceptAllFileFilterUsed(false);
panel.setVisible(false);
int retval = fc.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String FileName = file.getName();
String AbsoluteFileName = file.getPath();
OldDirectory = AbsoluteFileName.substring(0, AbsoluteFileName.length() - FileName.length());
try {
// Create instance of DocumentBuilderFactory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DocumentBuilder
DocumentBuilder parser = factory.newDocumentBuilder();
// Create blank DOM Document
File xml = new File(AbsoluteFileName);
Document MapDoc = parser.parse(xml);
NodeList Elements = MapDoc.getElementsByTagName("LogisimGoesFPGABoardMapInformation");
Node CircuitInfo = Elements.item(0);
NodeList CircuitInfoDetails = CircuitInfo.getChildNodes();
for (int i = 0; i < CircuitInfoDetails.getLength(); i++) {
if (CircuitInfoDetails.item(i).getNodeName().equals("GlobalMapInformation")) {
NamedNodeMap Attrs = CircuitInfoDetails.item(i).getAttributes();
for (int j = 0; j < Attrs.getLength(); j++) {
if (Attrs.item(j).getNodeName().equals("BoardName")) {
if (!BoardInfo.getBoardName().equals(Attrs.item(j).getNodeValue())) {
MessageLine.setForeground(Color.RED);
MessageLine.setText("LOAD ERROR: The selected Map file is not for the selected target board!");
panel.setVisible(true);
return;
}
} else if (Attrs.item(j).getNodeName().equals("ToplevelCircuitName")) {
if (!MappableComponents.GetToplevelName().equals(Attrs.item(j).getNodeValue())) {
MessageLine.setForeground(Color.RED);
MessageLine.setText("LOAD ERROR: The selected Map file is not for the selected toplevel circuit!");
panel.setVisible(true);
return;
}
}
}
break;
}
}
/* cleanup the current map */
UnMapAll();
for (int i = 0; i < CircuitInfoDetails.getLength(); i++) {
if (CircuitInfoDetails.item(i).getNodeName().startsWith("MAPPEDCOMPONENT")) {
int x = -1, y = -1, width = -1, height = -1;
String key = "";
NamedNodeMap Attrs = CircuitInfoDetails.item(i).getAttributes();
for (int j = 0; j < Attrs.getLength(); j++) {
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[0])) {
key = Attrs.item(j).getNodeValue();
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[1])) {
x = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[2])) {
y = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[3])) {
width = Integer.parseInt(Attrs.item(j).getNodeValue());
}
if (Attrs.item(j).getNodeName().equals(MapSectionStrings[4])) {
height = Integer.parseInt(Attrs.item(j).getNodeValue());
}
}
if (!key.isEmpty() && (x > 0) && (y > 0) && (width > 0) && (height > 0)) {
BoardRectangle rect = null;
for (FPGAIOInformationContainer comp : BoardInfo.GetAllComponents()) {
if ((comp.GetRectangle().getXpos() == x) && (comp.GetRectangle().getYpos() == y) && (comp.GetRectangle().getWidth() == width) && (comp.GetRectangle().getHeight() == height)) {
rect = comp.GetRectangle();
break;
}
}
if (rect != null) {
MappableComponents.TryMap(key, rect, BoardInfo.GetComponentType(rect));
}
}
}
}
ClearSelections();
RebuildSelectionLists();
BoardPic.paintImmediately(0, 0, BoardPic.getWidth(), BoardPic.getHeight());
} catch (Exception e) {
/* TODO: handle exceptions */
logger.error("Exceptions not handled yet in Load(), but got an exception: {}", e.getMessage());
}
}
panel.setVisible(true);
}
use of com.bfh.logisim.fpgaboardeditor.BoardRectangle in project logisim-evolution by reds-heig.
the class ComponentMapDialog method Save.
private void Save() {
panel.setVisible(false);
String SelectedDir = getDirName("Select Directory to save the current map");
if (!SelectedDir.isEmpty()) {
String SaveFileName = SelectedDir + CorrectLabel.getCorrectLabel(MappableComponents.GetToplevelName()) + "-" + BoardInfo.getBoardName() + "-MAP.xml";
try {
// Create instance of DocumentBuilderFactory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DocumentBuilder
DocumentBuilder parser = factory.newDocumentBuilder();
// Create blank DOM Document
Document MapInfo = parser.newDocument();
Element root = MapInfo.createElement("LogisimGoesFPGABoardMapInformation");
MapInfo.appendChild(root);
Element CircuitInfo = MapInfo.createElement("GlobalMapInformation");
CircuitInfo.setAttribute("BoardName", BoardInfo.getBoardName());
Attr circ = MapInfo.createAttribute("ToplevelCircuitName");
circ.setNodeValue(MappableComponents.GetToplevelName());
CircuitInfo.setAttributeNode(circ);
root.appendChild(CircuitInfo);
int count = 1;
for (String key : MappableComponents.MappedList()) {
Element Map = MapInfo.createElement("MAPPEDCOMPONENT_" + Integer.toHexString(count++));
BoardRectangle rect = MappableComponents.GetMap(key);
Map.setAttribute(MapSectionStrings[0], key);
Attr xpos = MapInfo.createAttribute(MapSectionStrings[1]);
xpos.setValue(Integer.toString(rect.getXpos()));
Map.setAttributeNode(xpos);
Attr ypos = MapInfo.createAttribute(MapSectionStrings[2]);
ypos.setValue(Integer.toString(rect.getYpos()));
Map.setAttributeNode(ypos);
Attr width = MapInfo.createAttribute(MapSectionStrings[3]);
width.setValue(Integer.toString(rect.getWidth()));
Map.setAttributeNode(width);
Attr height = MapInfo.createAttribute(MapSectionStrings[4]);
height.setValue(Integer.toString(rect.getHeight()));
Map.setAttributeNode(height);
root.appendChild(Map);
}
TransformerFactory tranFactory = TransformerFactory.newInstance();
tranFactory.setAttribute("indent-number", 3);
Transformer aTransformer = tranFactory.newTransformer();
aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
Source src = new DOMSource(MapInfo);
File file = new File(SaveFileName);
Result dest = new StreamResult(file);
aTransformer.transform(src, dest);
} catch (Exception e) {
/* TODO: handle exceptions */
logger.error("Exceptions not handled yet in Save(), but got an exception: {}", e.getMessage());
}
}
panel.setVisible(true);
}
use of com.bfh.logisim.fpgaboardeditor.BoardRectangle in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method GetFPGAPinLocs.
public ArrayList<String> GetFPGAPinLocs(int FPGAVendor) {
ArrayList<String> Contents = new ArrayList<String>();
for (String Map : fpgaInputsList.keySet()) {
int InputId = fpgaInputsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "in", InputId));
}
for (String Map : fpgaInOutsList.keySet()) {
int InOutId = fpgaInOutsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "inout", InOutId));
}
for (String Map : fpgaOutputsList.keySet()) {
int OutputId = fpgaOutputsList.get(Map);
if (!mappedList.containsKey(Map)) {
logger.warn("No mapping found for {}", Map);
return Contents;
}
BoardRectangle rect = mappedList.get(Map);
FPGAIOInformationContainer Comp = currentUsedBoard.GetComponent(rect);
Contents.addAll(Comp.GetPinlocStrings(FPGAVendor, "out", OutputId));
}
return Contents;
}
use of com.bfh.logisim.fpgaboardeditor.BoardRectangle in project logisim-evolution by reds-heig.
the class MappableResourcesContainer method RemoveUsedItems.
/**
* *************************************************************************
* **************************************
*/
/**
* Here all private handles are defined *
*/
/**
* *************************************************************************
* **************************************
*/
private ArrayList<BoardRectangle> RemoveUsedItems(ArrayList<BoardRectangle> List, int pinNeeded) {
int used = pinNeeded;
Iterator<BoardRectangle> ListIterator = List.iterator();
while (ListIterator.hasNext()) {
BoardRectangle current = ListIterator.next();
if (mappedList.containsValue(current)) {
ListIterator.remove();
used--;
}
}
/* We dont want to list Pin if they are not enough */
if (List.size() < used) {
List.clear();
}
return List;
}
Aggregations