Package examples.circuit

Source Code of examples.circuit.OrComponent

/* ==============================================
* Simtools : The tools library used in JSynoptic
* ==============================================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 1999-2008, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: OrComponent.java,v 1.5 2009/01/15 12:29:45 ogor Exp $
*
* Changes
* -------
* 08-Sep-2008 : Initial public release (RO);
*
*/
package examples.circuit;

import jsynoptic.plugins.circuit.CircuitGate;
import jsynoptic.plugins.circuit.boxes.CircuitBox;
import simtools.diagram.gate.Connection;
import simtools.diagram.gate.Gate;
import simtools.shapes.AbstractShape;

public class OrComponent extends CircuitBox {

    private static final long serialVersionUID = -4526939344845134612L;
   
    protected CircuitGate in1, in2, out;
       
   
    public OrComponent(int ox, int oy, int width, int height) {
        super(ox, oy, width, height);
        addGate(in1 = new CircuitGate(this, Gate.EAST, "IN 1"true));
        addGate(in2 = new CircuitGate(this, Gate.EAST, "IN 2",true));
        addGate(out = new CircuitGate(this, Gate.WEST, "OUT", false));
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.shapes.AbstractShape#cloneShape()
     */
    protected AbstractShape cloneShape() {
        OrComponent res = (OrComponent) super.cloneShape();
       
        res.in1 = (CircuitGate)in1.cloneGate(res);
        res.addGate(res.in1);
       
        res.in2 = (CircuitGate)in2.cloneGate(res);
        res.addGate(res.in2);
       
        res.out = (CircuitGate)out.cloneGate(res);
        res.addGate(res.out);
       
        return res;
    }
   
    public void signalHasBeenReceived(CircuitGate gate) {

        if (gate != null && (gate == in1 || (gate == in2))){

            Boolean in1Value = null;
            if (in1.getCurrentSignal() instanceof LogicalSignal){
                in1Value = new Boolean( ((LogicalSignal)in1.getCurrentSignal()).getBooleanValue() );  
            }

            Boolean in2Value = null;
            if (in2.getCurrentSignal() instanceof LogicalSignal){
                in2Value = new Boolean(((LogicalSignal)in2.getCurrentSignal()).getBooleanValue() );  
            }

            LogicalSignal outSignal = null;

            if (! (in1Value== null && in2Value==null)){
                boolean outValue = (in1Value==null? false : in1Value.booleanValue()) || (in2Value==null? false : in2Value.booleanValue());
                outSignal = new LogicalSignal(outValue);
            }
            out.sendSignal(outSignal, gate.getCurrentSignalEventId());
        }
    }

    public void connectionAddedAt(Gate gate, Connection connection) {
        // TODO Auto-generated method stub
       
    }

    public void connectionRemovedAt(Gate gate, Connection connection) {
        // TODO Auto-generated method stub
       
    }
   
   
    public CircuitGate getIn1() {
        return in1;
    }

    public CircuitGate getIn2() {
        return in2;
    }

    public CircuitGate getOut() {
        return out;
    }
}

TOP

Related Classes of examples.circuit.OrComponent

TOP
Copyright © 2018 www.massapi.com. 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.