Package com.cburch.logisim.circuit

Examples of com.cburch.logisim.circuit.Circuit


  public void setCircuitState(CircuitState value) {
    if (value == null || circuitState == value) return;

    CircuitState old = circuitState;
    Circuit oldCircuit = old == null ? null : old.getCircuit();
    Circuit newCircuit = value.getCircuit();
    boolean circuitChanged = old == null || oldCircuit != newCircuit;
    if (circuitChanged) {
      Canvas canvas = frame == null ? null : frame.getCanvas();
      if (canvas != null) {
        if (tool != null) tool.deselect(canvas);
        Selection selection = canvas.getSelection();
        if (selection != null) {
          Action act = SelectionActions.dropAll(selection);
          if (act != null) {
            doAction(act);
          }
        }
        if (tool != null) tool.select(canvas);
      }
      if (oldCircuit != null) {
        for (CircuitListener l : circuitListeners) {
          oldCircuit.removeCircuitListener(l);
        }
      }
    }
    circuitState = value;
    stateMap.put(circuitState.getCircuit(), circuitState);
    simulator.setCircuitState(circuitState);
    if (circuitChanged) {
      fireEvent(ProjectEvent.ACTION_SET_CURRENT, oldCircuit, newCircuit);
      if (newCircuit != null) {
        for (CircuitListener l : circuitListeners) {
          newCircuit.addCircuitListener(l);
        }
      }
    }
    fireEvent(ProjectEvent.ACTION_SET_STATE, old, circuitState);
  }
View Full Code Here


    Tool old = tool;
    Canvas canvas = frame.getCanvas();
    if (old != null) old.deselect(canvas);
    Selection selection = canvas.getSelection();
    if (selection != null && !selection.isEmpty()) {
      Circuit circuit = canvas.getCircuit();
      CircuitMutation xn = new CircuitMutation(circuit);
      if (value == null) {
        Action act = SelectionActions.dropAll(selection);
        if (act != null) {
          doAction(act);
View Full Code Here

      return Strings.get("moveSelectionAction");
    }

    @Override
    public void doIt(Project proj) {
      Circuit circuit = proj.getCurrentCircuit();
      CircuitMutation xn = new CircuitMutation(circuit);

      sel.translateHelper(xn, dx, dy);
      if (replacements != null) {
        xn.replace(replacements);
View Full Code Here

    EndData data = component.getEnd(portIndex);
    return circuitState.getValue(data.getLocation());
  }
 
  public boolean isPortConnected(int index) {
    Circuit circ = circuitState.getCircuit();
    Location loc = component.getEnd(index).getLocation();
    return circ.isConnected(loc, component);
  }
View Full Code Here

    wireLoc = NULL_LOCATION;
    lastX = Integer.MIN_VALUE;
    if (wire) {
      current = wiring;
      Selection sel = canvas.getSelection();
      Circuit circ = canvas.getCircuit();
      Collection<Component> selected = sel.getAnchoredComponents();
      ArrayList<Component> suppress = null;
      for (Wire w : circ.getWires()) {
        if (selected.contains(w)) {
          if (w.contains(oldWireLoc)) {
            if (suppress == null) suppress = new ArrayList<Component>();
            suppress.add(w);
          }
View Full Code Here

          }
        }
      }
    }
   
    Circuit circ = canvas.getCircuit();
    Collection<? extends Component> at = circ.getComponents(loc);
    if (at != null && at.size() > 0) return wiring;
   
    for (Wire w : circ.getWires()) {
      if (w.contains(loc)) { return wiring; }
    }
    return select;
  }
View Full Code Here

    }
  }
 
  private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
    if (e.getModifiersEx() == 0) {
      final Circuit circuit = canvas.getCircuit();
      final Selection sel = canvas.getSelection();
      SetAttributeAction act = new SetAttributeAction(circuit,
          Strings.getter("selectionRefaceAction"));
      for (Component comp : sel.getComponents()) {
        if (!(comp instanceof Wire)) {
View Full Code Here

    if (zoomFactor != 1.0 && gScaled instanceof Graphics2D) {
      ((Graphics2D) gScaled).scale(zoomFactor, zoomFactor);
    }
    drawWithUserState(g, gScaled, proj);
    drawWidthIncompatibilityData(g, gScaled, proj);
    Circuit circ = proj.getCurrentCircuit();
   
    CircuitState circState = proj.getCircuitState();
    ComponentDrawContext ptContext = new ComponentDrawContext(canvas,
        circ, circState, g, gScaled);
    ptContext.setHighlightedWires(highlightedWires);
View Full Code Here

    proj.getSimulator().drawStepPoints(ptContext);
    gScaled.dispose();
  }

  private void drawWithUserState(Graphics base, Graphics g, Project proj) {
    Circuit circ = proj.getCurrentCircuit();
    Selection sel = proj.getSelection();
    Set<Component> hidden;
    Tool dragTool = canvas.getDragTool();
    if (dragTool == null) {
      hidden = NO_COMPONENTS;
    } else {
      hidden = dragTool.getHiddenComponents(canvas);
      if (hidden == null) hidden = NO_COMPONENTS;
    }

    // draw halo around component whose attributes we are viewing
    boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
    if (showHalo && haloedComponent != null && haloedCircuit == circ
        && !hidden.contains(haloedComponent)) {
      GraphicsUtil.switchToWidth(g, 3);
      g.setColor(Canvas.HALO_COLOR);
      Bounds bds = haloedComponent.getBounds(g).expand(5);
      int w = bds.getWidth();
      int h = bds.getHeight();
      double a = Canvas.SQRT_2 * w;
      double b = Canvas.SQRT_2 * h;
      g.drawOval((int) Math.round(bds.getX() + w/2.0 - a/2.0),
        (int) Math.round(bds.getY() + h/2.0 - b/2.0),
        (int) Math.round(a), (int) Math.round(b));
      GraphicsUtil.switchToWidth(g, 1);
      g.setColor(Color.BLACK);
    }

    // draw circuit and selection
    CircuitState circState = proj.getCircuitState();
    boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
    ComponentDrawContext context = new ComponentDrawContext(canvas,
        circ, circState, base, g, printerView);
    context.setHighlightedWires(highlightedWires);
    circ.draw(context, hidden);
    sel.draw(context, hidden);

    // draw tool
    Tool tool = dragTool != null ? dragTool : proj.getTool();
    if (tool != null && !canvas.isPopupMenuUp()) {
View Full Code Here

    InstanceComponent c = comp;
    return c == null ? Location.create(0, 0) : c.getLocation();
  }
 
  public boolean isPortConnected(int index) {
    Circuit circ = context.getCircuit();
    Location loc = comp.getEnd(index).getLocation();
    return circ.isConnected(loc, comp);
  }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.circuit.Circuit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.