List of usage examples for org.jdom2 Document addContent
@Override public Document addContent(Collection<? extends Content> c)
From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java
License:Open Source License
private static void convertDiagramSpecification16ToVirtualModel17(File file, Document diagram, List<File> oldPaletteFiles, List<File> oldExampleDiagramFiles, ViewPointResource viewPointResource) { // Create the diagram specification and a virtual model with a diagram typed model slot referencing this diagram specification final String ADDRESSED_DIAGRAM_MODEL_SLOT = "AddressedDiagramModelSlot"; final String MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT = "ModelSlot_VirtualModelModelSlot"; final String MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT = "ModelSlot_TypedDiagramModelSlot"; try {// w w w .j a v a 2s.com String diagramName = file.getName().replace(".xml", ""); // Create a folder that contains the diagram specification File diagramSpecificationFolder = new File( file.getParentFile() + "/" + diagramName + ".diagramspecification"); diagramSpecificationFolder.mkdir(); // Retrieve diagram drop schemes Iterator<Element> dropSchemeElements = diagram.getDescendants(new ElementFilter("DropScheme")); List<Element> dropSchemes = IteratorUtils.toList(dropSchemeElements); // Retrieve Diagram Model slots references Iterator<? extends Content> thisModelSlotsIterator = diagram.getDescendants( new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT))); List<Element> thisModelSlots = IteratorUtils.toList(thisModelSlotsIterator); // Retrieve the DiagramModelSlot (this), and transform it to a virtual model slot with a virtual model uri int thisID = 0; String newThisUri = viewPointResource.getURI() + "/" + diagramName; String diagramSpecificationURI = newThisUri + "/" + diagramName + ".diagramspecification"; Element typedDiagramModelSlot = null; boolean foundThis = false; for (Element thisMs : thisModelSlots) { // Retriev the ID and URI of this DiagramModelSlot if (thisMs.getAttribute("name") != null && thisMs.getAttributeValue("name").equals("this") && !foundThis) { // Store its ID and its URI thisID = thisMs.getAttribute("id").getIntValue(); if (thisMs.getAttributeValue("virtualModelURI") != null) { newThisUri = thisMs.getAttributeValue("virtualModelURI"); thisMs.removeAttribute("virtualModelURI"); thisMs.removeAttribute("name"); thisMs.getAttribute("id").setName("idref"); thisMs.setAttribute("idref", Integer.toString(thisID)); } // Replace by a Typed model slot typedDiagramModelSlot = new Element(MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT); typedDiagramModelSlot.setAttribute("metaModelURI", diagramSpecificationURI); typedDiagramModelSlot.setAttribute("name", "typedDiagramModelSlot"); typedDiagramModelSlot.setAttribute("id", Integer.toString(computeNewID(diagram))); foundThis = true; } } // Replace the Diagram Model Slot by a Virtual Model Model slot for (Element thisMs : thisModelSlots) { if (hasSameID(thisMs, thisID) && thisMs.getName().equals("DiagramModelSlot")) { thisMs.setName("FMLRTModelSlot"); thisMs.getAttributes().add(new Attribute("virtualModelURI", newThisUri)); thisMs.getAttributes().add(new Attribute("name", "virtualModelInstance")); thisMs.getAttributes().add(new Attribute("id", Integer.toString(thisID))); thisMs.removeAttribute("idref"); } } // Update ids for all model slots Iterator<? extends Content> diagramModelSlotsIterator = diagram.getDescendants( new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT))); List<Element> thisDiagramModelSlots = IteratorUtils.toList(diagramModelSlotsIterator); for (Element diagramMs : thisDiagramModelSlots) { if (diagramMs.getAttribute("id") != null && typedDiagramModelSlot != null) { diagramMs.setAttribute("id", typedDiagramModelSlot.getAttributeValue("id")); } if (diagramMs.getAttribute("idref") != null) { // Change to TypedDiagramModelSlot if (diagramMs.getParentElement().getName().equals("AddShape") || diagramMs.getParentElement().getName().equals("AddConnector") || diagramMs.getParentElement().getName().equals("AddDiagram") || diagramMs.getParentElement().getName().equals("ContainedShapePatternRole") || diagramMs.getParentElement().getName().equals("ContainedConnectorPatternRole") || diagramMs.getParentElement().getName().equals("ContainedDiagramPatternRole")) { if (typedDiagramModelSlot.getAttributeValue("id") != null) { diagramMs.setAttribute("idref", typedDiagramModelSlot.getAttributeValue("id")); diagramMs.setName("TypedDiagramModelSlot"); } } else { diagramMs.setName(MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT); } } } for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; if (element.getName().equals("AddShape") || element.getName().equals("AddConnector") || element.getName().equals("AddDiagram")) { if (element.getChild("TypedDiagramModelSlot") == null && element.getChild("AddressedDiagramModelSlot") == null) { Element adressedMsElement = new Element("TypedDiagramModelSlot"); Attribute newIdRefAttribute = new Attribute("idref", typedDiagramModelSlot.getAttributeValue("id")); adressedMsElement.getAttributes().add(newIdRefAttribute); element.addContent(adressedMsElement); } } } } // Update DiagramSpecification URI for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; if (element.getAttribute("diagramSpecificationURI") != null) { String oldDiagramSpecificationUri = element.getAttributeValue("diagramSpecificationURI"); String diagramSpecificationName = oldDiagramSpecificationUri .substring(oldDiagramSpecificationUri.lastIndexOf("/")); String newDiagramSpecificationUri = oldDiagramSpecificationUri + diagramSpecificationName + ".diagramspecification"; element.getAttribute("diagramSpecificationURI").setValue(newDiagramSpecificationUri); } } } // Change all the "diagram" binding with "this", and "toplevel" with typedDiagramModelSlot.topLevel" in case of not // DropSchemeAction for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; for (Attribute attribute : element.getAttributes()) { if (attribute.getValue().startsWith("diagram")) { attribute.setValue(attribute.getValue().replace("diagram", "this")); } if (attribute.getValue().startsWith("topLevel")) { boolean diagramScheme = false; Element parentElement = element.getParentElement(); while (parentElement != null) { if (parentElement.getName().equals("DropScheme") || parentElement.getName().equals("LinkScheme")) { diagramScheme = true; } parentElement = parentElement.getParentElement(); } if (!diagramScheme) { attribute.setValue(attribute.getValue().replace("topLevel", "virtualModelInstance.typedDiagramModelSlot")); } } } } } // Create the diagram specificaion xml file File diagramSpecificationFile = new File(diagramSpecificationFolder, file.getName()); Document diagramSpecification = new Document(); Element rootElement = new Element("DiagramSpecification"); Attribute name = new Attribute("name", diagramName); Attribute diagramSpecificationURIAttribute = new Attribute("uri", diagramSpecificationURI); diagramSpecification.addContent(rootElement); rootElement.getAttributes().add(name); rootElement.getAttributes().add(diagramSpecificationURIAttribute); XMLUtils.saveXMLFile(diagramSpecification, diagramSpecificationFile); // Copy the palette files inside diagram specification repository ArrayList<File> newPaletteFiles = new ArrayList<File>(); for (File paletteFile : oldPaletteFiles) { File newFile = new File(diagramSpecificationFolder + "/" + paletteFile.getName()); FileUtils.rename(paletteFile, newFile); newPaletteFiles.add(newFile); Document palette = XMLUtils.readXMLFile(newFile); Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI); palette.getRootElement().getAttributes().add(diagramSpecUri); convertNames16ToNames17(palette); XMLUtils.saveXMLFile(palette, newFile); } // Copy the example diagram files inside diagram specification repository ArrayList<File> newExampleDiagramFiles = new ArrayList<File>(); for (File exampleDiagramFile : oldExampleDiagramFiles) { File newFile = new File(diagramSpecificationFolder + "/" + exampleDiagramFile.getName()); FileUtils.rename(exampleDiagramFile, newFile); newExampleDiagramFiles.add(newFile); Document exampleDiagram = XMLUtils.readXMLFile(newFile); exampleDiagram.getRootElement().setAttribute("uri", diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name")); Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI); exampleDiagram.getRootElement().getAttributes().add(diagramSpecUri); exampleDiagram.getRootElement().setAttribute("uri", diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name")); convertNames16ToNames17(exampleDiagram); XMLUtils.saveXMLFile(exampleDiagram, newFile); } // Update the diagram palette element bindings ArrayList<Element> paletteElementBindings = new ArrayList<Element>(); for (File paletteFile : newPaletteFiles) { Document palette = XMLUtils.readXMLFile(paletteFile); String paletteUri = diagramSpecificationURI + "/" + palette.getRootElement().getAttribute("name").getValue() + ".palette"; Iterator<? extends Content> paletteElements = palette .getDescendants(new ElementFilter("DiagramPaletteElement")); while (paletteElements.hasNext()) { Element paletteElement = (Element) paletteElements.next(); Element binding = createPaletteElementBinding(paletteElement, paletteUri, dropSchemes); if (binding != null) { paletteElementBindings.add(binding); } } XMLUtils.saveXMLFile(palette, paletteFile); } // Add the Palette Element Bindings to the TypedDiagramModelSlot if (!paletteElementBindings.isEmpty()) { typedDiagramModelSlot.addContent(paletteElementBindings); } if (typedDiagramModelSlot != null) { diagram.getRootElement().addContent(typedDiagramModelSlot); } // Update names convertNames16ToNames17(diagram); convertOldNameToNewNames("DiagramSpecification", "VirtualModel", diagram); // Save the files XMLUtils.saveXMLFile(diagram, file); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.openflexo.foundation.viewpoint.rm.ViewPointResourceImpl.java
License:Open Source License
private static void convertDiagramSpecification16ToVirtualModel17(File file, Document diagram, List<File> oldPaletteFiles, List<File> oldExampleDiagramFiles, ViewPointResource viewPointResource) { // Create the diagram specification and a virtual model with a diagram typed model slot referencing this diagram specification final String ADDRESSED_DIAGRAM_MODEL_SLOT = "AddressedDiagramModelSlot"; final String MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT = "ModelSlot_VirtualModelModelSlot"; final String MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT = "ModelSlot_TypedDiagramModelSlot"; try {/*from www . j ava 2 s . c o m*/ String diagramName = file.getName().replace(".xml", ""); // Create a folder that contains the diagram specification File diagramSpecificationFolder = new File( file.getParentFile() + "/" + diagramName + ".diagramspecification"); diagramSpecificationFolder.mkdir(); // Retrieve diagram drop schemes Iterator<Element> dropSchemeElements = diagram.getDescendants(new ElementFilter("DropScheme")); List<Element> dropSchemes = IteratorUtils.toList(dropSchemeElements); // Retrieve Diagram Model slots references Iterator<? extends Content> thisModelSlotsIterator = diagram.getDescendants( new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT))); List<Element> thisModelSlots = IteratorUtils.toList(thisModelSlotsIterator); // Retrieve the DiagramModelSlot (this), and transform it to a virtual model slot with a virtual model uri int thisID = 0; String newThisUri = viewPointResource.getURI() + "/" + diagramName; String diagramSpecificationURI = newThisUri + "/" + diagramName + ".diagramspecification"; Element typedDiagramModelSlot = null; boolean foundThis = false; for (Element thisMs : thisModelSlots) { // Retriev the ID and URI of this DiagramModelSlot if (thisMs.getAttribute("name") != null && thisMs.getAttributeValue("name").equals("this") && !foundThis) { // Store its ID and its URI thisID = thisMs.getAttribute("id").getIntValue(); if (thisMs.getAttributeValue("virtualModelURI") != null) { newThisUri = thisMs.getAttributeValue("virtualModelURI"); thisMs.removeAttribute("virtualModelURI"); thisMs.removeAttribute("name"); thisMs.getAttribute("id").setName("idref"); thisMs.setAttribute("idref", Integer.toString(thisID)); } // Replace by a Typed model slot typedDiagramModelSlot = new Element(MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT); typedDiagramModelSlot.setAttribute("metaModelURI", diagramSpecificationURI); typedDiagramModelSlot.setAttribute("name", "typedDiagramModelSlot"); typedDiagramModelSlot.setAttribute("id", Integer.toString(computeNewID(diagram))); foundThis = true; } } // Replace the Diagram Model Slot by a Virtual Model Model slot for (Element thisMs : thisModelSlots) { if (hasSameID(thisMs, thisID) && thisMs.getName().equals("DiagramModelSlot")) { thisMs.setName("VirtualModelModelSlot"); thisMs.getAttributes().add(new Attribute("virtualModelURI", newThisUri)); thisMs.getAttributes().add(new Attribute("name", "virtualModelInstance")); thisMs.getAttributes().add(new Attribute("id", Integer.toString(thisID))); thisMs.removeAttribute("idref"); } } // Update ids for all model slots Iterator<? extends Content> diagramModelSlotsIterator = diagram.getDescendants( new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT))); List<Element> thisDiagramModelSlots = IteratorUtils.toList(diagramModelSlotsIterator); for (Element diagramMs : thisDiagramModelSlots) { if (diagramMs.getAttribute("id") != null && typedDiagramModelSlot != null) { diagramMs.setAttribute("id", typedDiagramModelSlot.getAttributeValue("id")); } if (diagramMs.getAttribute("idref") != null) { // Change to TypedDiagramModelSlot if (diagramMs.getParentElement().getName().equals("AddShape") || diagramMs.getParentElement().getName().equals("AddConnector") || diagramMs.getParentElement().getName().equals("AddDiagram") || diagramMs.getParentElement().getName().equals("ContainedShapePatternRole") || diagramMs.getParentElement().getName().equals("ContainedConnectorPatternRole") || diagramMs.getParentElement().getName().equals("ContainedDiagramPatternRole")) { if (typedDiagramModelSlot.getAttributeValue("id") != null) { diagramMs.setAttribute("idref", typedDiagramModelSlot.getAttributeValue("id")); diagramMs.setName("TypedDiagramModelSlot"); } } else { diagramMs.setName(MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT); } } } for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; if (element.getName().equals("AddShape") || element.getName().equals("AddConnector") || element.getName().equals("AddDiagram")) { if (element.getChild("TypedDiagramModelSlot") == null && element.getChild("AddressedDiagramModelSlot") == null) { Element adressedMsElement = new Element("TypedDiagramModelSlot"); Attribute newIdRefAttribute = new Attribute("idref", typedDiagramModelSlot.getAttributeValue("id")); adressedMsElement.getAttributes().add(newIdRefAttribute); element.addContent(adressedMsElement); } } } } // Update DiagramSpecification URI for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; if (element.getAttribute("diagramSpecificationURI") != null) { String oldDiagramSpecificationUri = element.getAttributeValue("diagramSpecificationURI"); String diagramSpecificationName = oldDiagramSpecificationUri .substring(oldDiagramSpecificationUri.lastIndexOf("/")); String newDiagramSpecificationUri = oldDiagramSpecificationUri + diagramSpecificationName + ".diagramspecification"; element.getAttribute("diagramSpecificationURI").setValue(newDiagramSpecificationUri); } } } // Change all the "diagram" binding with "this", and "toplevel" with typedDiagramModelSlot.topLevel" in case of not // DropSchemeAction for (Content content : diagram.getDescendants()) { if (content instanceof Element) { Element element = (Element) content; for (Attribute attribute : element.getAttributes()) { if (attribute.getValue().startsWith("diagram")) { attribute.setValue(attribute.getValue().replace("diagram", "this")); } if (attribute.getValue().startsWith("topLevel")) { boolean diagramScheme = false; Element parentElement = element.getParentElement(); while (parentElement != null) { if (parentElement.getName().equals("DropScheme") || parentElement.getName().equals("LinkScheme")) { diagramScheme = true; } parentElement = parentElement.getParentElement(); } if (!diagramScheme) { attribute.setValue(attribute.getValue().replace("topLevel", "virtualModelInstance.typedDiagramModelSlot")); } } } } } // Create the diagram specificaion xml file File diagramSpecificationFile = new File(diagramSpecificationFolder, file.getName()); Document diagramSpecification = new Document(); Element rootElement = new Element("DiagramSpecification"); Attribute name = new Attribute("name", diagramName); Attribute diagramSpecificationURIAttribute = new Attribute("uri", diagramSpecificationURI); diagramSpecification.addContent(rootElement); rootElement.getAttributes().add(name); rootElement.getAttributes().add(diagramSpecificationURIAttribute); XMLUtils.saveXMLFile(diagramSpecification, diagramSpecificationFile); // Copy the palette files inside diagram specification repository ArrayList<File> newPaletteFiles = new ArrayList<File>(); for (File paletteFile : oldPaletteFiles) { File newFile = new File(diagramSpecificationFolder + "/" + paletteFile.getName()); FileUtils.rename(paletteFile, newFile); newPaletteFiles.add(newFile); Document palette = XMLUtils.readXMLFile(newFile); Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI); palette.getRootElement().getAttributes().add(diagramSpecUri); convertNames16ToNames17(palette); XMLUtils.saveXMLFile(palette, newFile); } // Copy the example diagram files inside diagram specification repository ArrayList<File> newExampleDiagramFiles = new ArrayList<File>(); for (File exampleDiagramFile : oldExampleDiagramFiles) { File newFile = new File(diagramSpecificationFolder + "/" + exampleDiagramFile.getName()); FileUtils.rename(exampleDiagramFile, newFile); newExampleDiagramFiles.add(newFile); Document exampleDiagram = XMLUtils.readXMLFile(newFile); exampleDiagram.getRootElement().setAttribute("uri", diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name")); Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI); exampleDiagram.getRootElement().getAttributes().add(diagramSpecUri); exampleDiagram.getRootElement().setAttribute("uri", diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name")); convertNames16ToNames17(exampleDiagram); XMLUtils.saveXMLFile(exampleDiagram, newFile); } // Update the diagram palette element bindings ArrayList<Element> paletteElementBindings = new ArrayList<Element>(); for (File paletteFile : newPaletteFiles) { Document palette = XMLUtils.readXMLFile(paletteFile); String paletteUri = diagramSpecificationURI + "/" + palette.getRootElement().getAttribute("name").getValue() + ".palette"; Iterator<? extends Content> paletteElements = palette .getDescendants(new ElementFilter("DiagramPaletteElement")); while (paletteElements.hasNext()) { Element paletteElement = (Element) paletteElements.next(); Element binding = createPaletteElementBinding(paletteElement, paletteUri, dropSchemes); if (binding != null) { paletteElementBindings.add(binding); } } XMLUtils.saveXMLFile(palette, paletteFile); } // Add the Palette Element Bindings to the TypedDiagramModelSlot if (!paletteElementBindings.isEmpty()) { typedDiagramModelSlot.addContent(paletteElementBindings); } if (typedDiagramModelSlot != null) { diagram.getRootElement().addContent(typedDiagramModelSlot); } // Update names convertNames16ToNames17(diagram); convertOldNameToNewNames("DiagramSpecification", "VirtualModel", diagram); // Save the files XMLUtils.saveXMLFile(diagram, file); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:per.sunmes.kfat.sys.FileUtil.java
public static void exportProject() { AnimationProjectInfo project = SysData.instance().getProject(); if (project == null) { return;//from w ww. ja va2s . c o m } Document document = new Document(); Element rootElement = new Element("kfa"); document.addContent(rootElement); rootElement.setAttribute("name", project.name); for (AnimationInfo ai : project.animations) { Element aiElement = new Element("animation"); aiElement.setAttribute("name", ai.name); rootElement.addContent(aiElement); for (FrameInfo fi : ai.frames) { Element fiElement = new Element("frame"); fiElement.setAttribute("id", String.valueOf(fi.id)); aiElement.addContent(fiElement); for (ImagePartInfo ipi : fi.parts) { Element ipiElement = new Element("part"); ipiElement.setAttribute("img", ipi.imageName); ipiElement.setAttribute("x", String.valueOf(ipi.x)); ipiElement.setAttribute("y", String.valueOf(ipi.y)); ipiElement.setAttribute("flipx", String.valueOf(ipi.flipX)); ipiElement.setAttribute("flipy", String.valueOf(ipi.flipY)); fiElement.addContent(ipiElement); } for (Rectangle rect : fi.rectangles) { Element rectElement = new Element("rectangle"); rectElement.setAttribute("x", String.valueOf(rect.x)); rectElement.setAttribute("y", String.valueOf(rect.y)); rectElement.setAttribute("width", String.valueOf(rect.width)); rectElement.setAttribute("height", String.valueOf(rect.height)); fiElement.addContent(rectElement); } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String outFile = String.format("%s/out/%s.xml", project.projectDirectory, project.name); try { outputter.output(document, new FileOutputStream(outFile)); JOptionPane.showMessageDialog(null, String.format("[%s],?!", outFile)); } catch (IOException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pl.edu.pwr.iiar.zak.thermalKit.util.ReadDesign.java
License:Open Source License
public void showDesign(String filename) throws JDOMException, IOException { try {/*w w w .j av a 2 s . c o m*/ System.out.println("Converting NCD file to XDL..."); FileConverter.convertNCD2XDL(filename); } catch (NullPointerException e) { System.out.println("Please indicate correct ncd file!"); System.exit(0); } Design design = new Design(); design.loadXDLFile(filename.substring(0, filename.length() - 3) + "xdl"); Device device = design.getDevice(); Document writer = new Document(); Element rootElement = new Element("device"); writer.addContent(rootElement); rootElement.setAttribute(new Attribute("version", "0.2")); rootElement.setAttribute(new Attribute("name", device.getPartName())); Element size = new Element("size"); rootElement.addContent(size); size.setAttribute(new Attribute("cols", String.format("%d", device.getColumns()))); size.setAttribute(new Attribute("rows", String.format("%d", device.getRows()))); Element clbsize = new Element("clbsize"); rootElement.addContent(clbsize); clbsize.setAttribute(new Attribute("width", "0.00025")); clbsize.setAttribute(new Attribute("height", "0.0002")); int old_z = -1; int k = 0; String progress_bar = "|/-\\"; for (int row = 0; row < device.getColumns(); row++) { if (print) { System.out.format("%d\t", row + 1); } for (int col = 0; col < device.getRows(); col++) { System.out.println(String.format("Col: %d, Row: %d", col, row)); System.out.println(design.getDevice().getTile(col, row).getName()); if (design.getDevice().getTile(col, row).getName().contains("CLB")) { try { boolean used = false; for (PrimitiveSite ps : design.getDevice().getTile(col, row).getPrimitiveSites()) { if (design.isPrimitiveSiteUsed(ps)) { used = true; } } if (used) { if (print) { System.out.print("@"); } rootElement.addContent(addElement(row, col, "unit")); } else { if (print) { System.out.print("*"); } } k++; } catch (Exception e) { if (print) { System.out.print("#"); } rootElement.addContent(addElement(row, col, "obstacle")); } } else { rootElement.addContent(addElement(row, col, "obstacle")); if (print) { System.out.print("#"); } } } if (print) { System.out.println(); } else { int z = (int) ((row / 177.0) * 100); if (old_z != z) { System.out.write(progressBar(z, 50).getBytes()); old_z = z; } } } System.out.format("\nNumber of CLB tiles %d\n", k); System.out.format("Number of columns %d; Number of rows %d\n", design.getDevice().getColumns(), design.getDevice().getRows()); System.out.println("Creating XML file with device floorplan..."); XMLOutputter xml = new XMLOutputter(); xml.setFormat(Format.getPrettyFormat()); String path = "floorplan.xml"; if (!print) { PrintWriter xmlWriter = new PrintWriter(path, "UTF-8"); xmlWriter.print(xml.outputString(writer)); xmlWriter.close(); System.out.println("FPGA description saved in floorplan.xml!"); } }