Search in sources :

Example 6 with AbstractCanvasObject

use of com.cburch.draw.model.AbstractCanvasObject in project logisim-evolution by reds-heig.

the class XmlCircuitReader method buildCircuit.

private void buildCircuit(XmlReader.CircuitData circData, CircuitMutator mutator) {
    Element elt = circData.circuitElement;
    Circuit dest = circData.circuit;
    Map<Element, Component> knownComponents = circData.knownComponents;
    if (knownComponents == null)
        knownComponents = Collections.emptyMap();
    try {
        /* Here we check the attribute circuitnamedbox for backwards compatibility */
        boolean HasNamedBox = false;
        for (Element attrElt : XmlIterator.forChildElements(circData.circuitElement, "a")) {
            if (attrElt.hasAttribute("name")) {
                String Name = attrElt.getAttribute("name");
                if (Name.equals("circuitnamedbox")) {
                    HasNamedBox = true;
                }
            }
        }
        reader.initAttributeSet(circData.circuitElement, dest.getStaticAttributes(), null);
        if ((!HasNamedBox) && circData.circuitElement.hasChildNodes()) {
            dest.getStaticAttributes().setValue(CircuitAttributes.NAMED_CIRCUIT_BOX, false);
        }
    } catch (XmlReaderException e) {
        reader.addErrors(e, circData.circuit.getName() + ".static");
    }
    for (Element sub_elt : XmlIterator.forChildElements(elt)) {
        String sub_elt_name = sub_elt.getTagName();
        if (sub_elt_name.equals("comp")) {
            try {
                Component comp = knownComponents.get(sub_elt);
                if (comp == null) {
                    comp = getComponent(sub_elt, reader);
                }
                if (comp != null) {
                    mutator.add(dest, comp);
                }
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toComponentString(sub_elt));
            }
        } else if (sub_elt_name.equals("wire")) {
            try {
                addWire(dest, mutator, sub_elt);
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toWireString(sub_elt));
            }
        }
    }
    List<AbstractCanvasObject> appearance = circData.appearance;
    if (appearance != null && !appearance.isEmpty()) {
        dest.getAppearance().setObjectsForce(appearance);
        dest.getAppearance().setDefaultAppearance(false);
    }
}
Also used : Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component)

Aggregations

AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)6 Component (com.cburch.logisim.comp.Component)2 Attribute (com.cburch.logisim.data.Attribute)2 Element (org.w3c.dom.Element)2 CanvasObject (com.cburch.draw.model.CanvasObject)1 Circuit (com.cburch.logisim.circuit.Circuit)1 Wire (com.cburch.logisim.circuit.Wire)1 Direction (com.cburch.logisim.data.Direction)1 Location (com.cburch.logisim.data.Location)1 Instance (com.cburch.logisim.instance.Instance)1