Search in sources :

Example 1 with AbstractCanvasObject

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

the class XmlWriter method fromCircuit.

Element fromCircuit(Circuit circuit) {
    Element ret = doc.createElement("circuit");
    ret.setAttribute("name", circuit.getName());
    addAttributeSetContent(ret, circuit.getStaticAttributes(), null);
    if (!circuit.getAppearance().isDefaultAppearance()) {
        Element appear = doc.createElement("appear");
        for (Object o : circuit.getAppearance().getObjectsFromBottom()) {
            if (o instanceof AbstractCanvasObject) {
                Element elt = ((AbstractCanvasObject) o).toSvgElement(doc);
                if (elt != null) {
                    appear.appendChild(elt);
                }
            }
        }
        ret.appendChild(appear);
    }
    for (Wire w : circuit.getWires()) {
        ret.appendChild(fromWire(w));
    }
    for (Component comp : circuit.getNonWires()) {
        Element elt = fromComponent(comp);
        if (elt != null)
            ret.appendChild(elt);
    }
    return ret;
}
Also used : Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Wire(com.cburch.logisim.circuit.Wire) Component(com.cburch.logisim.comp.Component)

Example 2 with AbstractCanvasObject

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

the class AppearanceSvgReader method createShape.

public static AbstractCanvasObject createShape(Element elt, Map<Location, Instance> pins) {
    String name = elt.getTagName();
    if (name.equals("circ-anchor") || name.equals("circ-origin")) {
        Location loc = getLocation(elt);
        AbstractCanvasObject ret = new AppearanceAnchor(loc);
        if (elt.hasAttribute("facing")) {
            Direction facing = Direction.parse(elt.getAttribute("facing"));
            ret.setValue(AppearanceAnchor.FACING, facing);
        }
        return ret;
    } else if (name.equals("circ-port")) {
        Location loc = getLocation(elt);
        String[] pinStr = elt.getAttribute("pin").split(",");
        Location pinLoc = Location.create(Integer.parseInt(pinStr[0].trim()), Integer.parseInt(pinStr[1].trim()));
        Instance pin = pins.get(pinLoc);
        if (pin == null) {
            return null;
        } else {
            return new AppearancePort(loc, pin);
        }
    } else {
        return SvgReader.createShape(elt);
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 3 with AbstractCanvasObject

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

the class DrawingAttributeSet method applyTo.

public <E extends CanvasObject> E applyTo(E drawable) {
    AbstractCanvasObject d = (AbstractCanvasObject) drawable;
    // use a for(i...) loop since the attribute list may change as we go on
    for (int i = 0; i < d.getAttributes().size(); i++) {
        Attribute<?> attr = d.getAttributes().get(i);
        @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
        if (attr == DrawAttr.FILL_COLOR && this.containsAttribute(DrawAttr.TEXT_DEFAULT_FILL)) {
            d.setValue(a, this.getValue(DrawAttr.TEXT_DEFAULT_FILL));
        } else if (this.containsAttribute(a)) {
            Object value = this.getValue(a);
            d.setValue(a, value);
        }
    }
    return drawable;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 4 with AbstractCanvasObject

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

the class SvgReader method createRectangle.

private static AbstractCanvasObject createRectangle(Element elt) {
    int x = Integer.parseInt(elt.getAttribute("x"));
    int y = Integer.parseInt(elt.getAttribute("y"));
    int w = Integer.parseInt(elt.getAttribute("width"));
    int h = Integer.parseInt(elt.getAttribute("height"));
    if (elt.hasAttribute("rx")) {
        AbstractCanvasObject ret = new RoundRectangle(x, y, w, h);
        int rx = Integer.parseInt(elt.getAttribute("rx"));
        ret.setValue(DrawAttr.CORNER_RADIUS, Integer.valueOf(rx));
        return ret;
    } else {
        return new Rectangle(x, y, w, h);
    }
}
Also used : AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject)

Example 5 with AbstractCanvasObject

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

the class SvgReader method createShape.

public static AbstractCanvasObject createShape(Element elt) {
    String name = elt.getTagName();
    AbstractCanvasObject ret;
    if (name.equals("ellipse")) {
        ret = createOval(elt);
    } else if (name.equals("line")) {
        ret = createLine(elt);
    } else if (name.equals("path")) {
        ret = createPath(elt);
    } else if (name.equals("polyline")) {
        ret = createPolyline(elt);
    } else if (name.equals("polygon")) {
        ret = createPolygon(elt);
    } else if (name.equals("rect")) {
        ret = createRectangle(elt);
    } else if (name.equals("text")) {
        ret = createText(elt);
    } else {
        return null;
    }
    List<Attribute<?>> attrs = ret.getAttributes();
    if (attrs.contains(DrawAttr.PAINT_TYPE)) {
        String stroke = elt.getAttribute("stroke");
        String fill = elt.getAttribute("fill");
        if (stroke.equals("") || stroke.equals("none")) {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_FILL);
        } else if (fill.equals("none")) {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
        } else {
            ret.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE_FILL);
        }
    }
    // since changing paintType could change it
    attrs = ret.getAttributes();
    if (attrs.contains(DrawAttr.STROKE_WIDTH) && elt.hasAttribute("stroke-width")) {
        Integer width = Integer.valueOf(elt.getAttribute("stroke-width"));
        ret.setValue(DrawAttr.STROKE_WIDTH, width);
    }
    if (attrs.contains(DrawAttr.STROKE_COLOR)) {
        String color = elt.getAttribute("stroke");
        String opacity = elt.getAttribute("stroke-opacity");
        if (!color.equals("none")) {
            ret.setValue(DrawAttr.STROKE_COLOR, getColor(color, opacity));
        }
    }
    if (attrs.contains(DrawAttr.FILL_COLOR)) {
        String color = elt.getAttribute("fill");
        if (color.equals(""))
            color = "#000000";
        String opacity = elt.getAttribute("fill-opacity");
        if (!color.equals("none")) {
            ret.setValue(DrawAttr.FILL_COLOR, getColor(color, opacity));
        }
    }
    return ret;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject)

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