Examples of TypedIOPort


Examples of ptolemy.actor.TypedIOPort

     * @exception NameDuplicationException If the container already has an
     * actor with this name.
     */
    public OrderedMerge(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException  {
        super(container, name);
        inputA = new TypedIOPort(this, "inputA", true, false);
        inputB = new TypedIOPort(this, "inputB", true, false);
        inputB.setTypeSameAs(inputA);
        inputA.setTypeAtMost(BaseType.SCALAR);
        output = new TypedIOPort(this, "output", false, true);
        output.setTypeSameAs(inputA);
        selectedA = new TypedIOPort(this, "selectedA", false, true);
        selectedA.setTypeEquals(BaseType.BOOLEAN);
        StringAttribute channelCardinal = new StringAttribute(selectedA, "_cardinal");
        channelCardinal.setExpression("SOUTH");
        _attachText("_iconDescription", "<svg>\n" + "<polygon points=\"-10,20 10,10 10,-10, -10,-20\" "+"style=\"fill:blue\"/>\n"+"</svg>\n");
    }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * @exception NameDuplicationException If the container already has an
     * actor with this name.
     */
    public SequentialClock(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException  {
        super(container, name);
        output = new TypedIOPort(this, "output", false, true);
        period = new Parameter(this, "period", new DoubleToken(2.0));
        period.setTypeEquals(BaseType.DOUBLE);
        offsets = new Parameter(this, "offsets");
        offsets.setExpression("{0.0, 1.0}");
        offsets.setTypeEquals(new ArrayType(BaseType.DOUBLE));
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     @exception IllegalActionException If there is a problem
     *  creating the ports.
     */
    public void createPorts() throws IllegalActionException {
        Iterator arguments = this.argumentsList().iterator();
        TypedIOPort port;

        while (arguments.hasNext()) {
            Argument argument = (Argument) arguments.next();
            port = (TypedIOPort) this.getPort(argument.getName());

            if (port == null) {
                if (argument.isReturn()) {
                    try {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + "</port>");
                        request.setUndoable(true);
                        requestChange(request);

                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct port "
                                        + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                } else if (argument.isInput() && argument.isOutput()) {
                    try {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<group>\n"
                                        + " <port name=\""
                                        + argument.getName()
                                        + "in"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"input\"/>\n"
                                        + " </port>\n"
                                        + " <port name=\""
                                        + argument.getName()
                                        + "out"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + " </port>\n" + "</group>");
                        request.setUndoable(true);
                        requestChange(request);
                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct " + "input or output "
                                        + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                } else {
                    try {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + (argument.isInput() ? "    <property name=\"input\"/>\n"
                                                : "")
                                        + (argument.isOutput() ? "    <property name=\"output\"/>\n"
                                                : "") + "</port>");
                        request.setUndoable(true);
                        requestChange(request);
                    } catch (Exception ex) {
                        throw new IllegalActionException(this, ex,
                                "Unable to construct " + "port for argument \""
                                        + argument.getName() + "\"");
                    }
                }
            } else {

                // synchronized the arguments and the ports
                if (argument.isReturn()) {
                    MoMLChangeRequest request = new MoMLChangeRequest(
                            this,
                            this,
                            "<port name=\""
                                    + argument.getName()
                                    + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                                    + "    <property name=\"output\"/>\n"
                                    + "</port>");
                    request.setUndoable(true);
                    requestChange(request);
                } else {
                    MoMLChangeRequest request = new MoMLChangeRequest(
                            this,
                            this,
                            "<port name=\""
                                    + argument.getName()
                                    + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                                    + "    <property name=\"input\"/>\n"
                                    + "</port>");
                    request.setUndoable(true);
                    requestChange(request);

                }
            }
            port = (TypedIOPort) this.getPort(argument.getName());
            if (port != null) {
                port.setTypeEquals(BaseType.GENERAL);
            }
        }
    }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

        //getting the in/inout parameters
        Iterator ports = this.portList().iterator();
        Vector args = new Vector();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();

            if (port.isInput() && port.hasToken(0)
                    && !(port.isOutput() && !port.isInput())) {
                Token tok = port.get(0);

                String typ = _methods[_methodIndex].getParameterTypes()[args
                        .size()].toString();

                if (typ.equals("boolean")) {
                    args.add(Boolean.valueOf(((BooleanToken) tok)
                            .booleanValue()));
                } else if (typ.equals("int")) {
                    args.add(Integer.valueOf(((IntToken) tok).intValue()));
                } else if (typ.equals("double")) {
                    args.add(Double.valueOf(((DoubleToken) tok).doubleValue()));
                } else if (typ.equals("class [I")) {
                    int siz = ((ArrayToken) tok).arrayValue().length;
                    int[] tab = new int[siz];

                    for (int j = 0; j < siz; j++) {
                        tab[j] = ((IntToken) (((ArrayToken) tok).arrayValue()[j]))
                                .intValue();
                    }

                    //(int[])((ArrayToken)tok).arrayValue();
                    args.add(tab);
                } else {
                    System.out.println("The intype is not convertible "
                            + "with Ptolemy II types.");
                }
            }
        }

        //tBFixed : the out parameter is not in by definition
        //...so no port in can initialize the param
        //call the native function
        Object obj = null;
        Object ret = null;

        try {
            try {
                obj = _class.newInstance();
            } catch (Error error) {
                // Using JNI to link in a native library
                // can result in a java.lang.UnsatisfiedLinkError
                // which extends Error, not Exception.
                // FIXME: Rethrow the error as an exception
                String libraryPath = StringUtilities
                        .getProperty("java.library.path");

                throw new Exception("Class '" + _class
                        + "' cannot be instantiated.\n"
                        + "If you are running under Windows, "
                        + "be sure that the directory containing the library "
                        + "is in your PATH.\n"
                        + "If you are running under Solaris, "
                        + "be sure that the directory containing the library "
                        + "is in your LD_LIBRARY_PATH and that the library "
                        + "name begin with 'lib' and end with '.so'.\n"
                        + "You may need to exit, set your "
                        + "PATH or LD_LIBRARY_PATH to include the directory "
                        + "that contains the shared library and "
                        + "restart.\n" + "For example, under Windows "
                        + "in a Cygwin bash shell:\n"
                        + "PATH=/cygdrive/c/ptII/jni/dll:${PATH}\n"
                        + "export PATH\n" + "vergil -jni foo.xml\n"
                        + "A common error is that "
                        + "the class cannot be found in "
                        + "property 'java.library.path' " + "which is:\n"
                        + libraryPath + "\nError message was: "
                        + error.getMessage(), error);
            }
        } catch (Exception ex) {
            throw new IllegalActionException(this, ex,
                    "Class cannot be instantiated");
        }

        try {
            ret = _methods[_methodIndex].invoke(obj, args.toArray());
        } catch (Throwable ex) {
            StringBuffer argumentsDescription = new StringBuffer("");

            try {
                if (args.size() >= 1) {
                    argumentsDescription.append(args.elementAt(0).toString());

                    for (int i = 1; i < args.size(); i++) {
                        argumentsDescription.append(", "
                                + args.elementAt(i).toString());
                    }
                }
            } catch (Throwable throwable) {
                // Ignore
            }

            throw new IllegalActionException(this, ex,
                    "Native operation call failed." + "Failed to invoke '"
                            + obj + "' with " + args.size() + " arg(s) "
                            + argumentsDescription.toString());
        }

        ports = portList().iterator();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();

            //if the argument is return
            if (getArgumentReturn() == null) {
                System.err.println("Warning: GenericJNIActor.java: "
                        + "getArgumentReturn() returns null?");
            }

            if ((port != null)
                    && (port.getName() != null)
                    && (getArgumentReturn() != null)
                    && port.getName()
                            .equals(this.getArgumentReturn().getName())) {
                String typ = "";
                Field field = null;

                try {
                    field = _class.getDeclaredField("_" + port.getName());
                    typ = field.getType().toString();
                } catch (NoSuchFieldException e) {
                    try {
                        throw new IllegalActionException(this, e,
                                "No return type field '_" + port.getName()
                                        + "'");
                    } catch (Throwable throwable) {
                        getDirector().stop();
                    }
                }

                if (typ.equals("boolean")) {
                    port.send(0, new BooleanToken(((Boolean) ret)
                            .booleanValue()));
                } else if (typ.equals("double")) {
                    port.send(0, new DoubleToken(((Double) ret).doubleValue()));
                } else if (typ.equals("int")) {
                    port.send(0, new IntToken(((Integer) ret).intValue()));
                } else if (typ.equals("char")) {
                    port.send(0,
                            new UnsignedByteToken(((Byte) ret).byteValue()));
                } else {
                    System.out.println("The return type is not convertible "
                            + "with Ptolemy II types.");
                }
            }
            //if the argument is output
            else if ((port != null)
                    && port.isOutput()
                    && (port.getName() != null)
                    && (getArgumentReturn() != null)
                    && !(port.getName().equals(this.getArgumentReturn()
                            .getName()))) {
                String typ = "";
                Field field = null;

                try {
                    field = _class.getDeclaredField("_" + port.getName());
                    typ = field.getType().toString();
                } catch (NoSuchFieldException ex) {
                    try {
                        field = _class.getDeclaredField("_"
                                + port.getName().substring(0,
                                        port.getName().length() - 3));
                        typ = field.getType().toString();
                    } catch (Throwable throwable) {
                        try {
                            throw new IllegalActionException(this, throwable,
                                    "No '+" + port.getName() + "' field !");
                        } catch (Throwable throwable2) {
                            getDirector().stop();
                        }
                    }
                }

                if (field == null) {
                    throw new InternalErrorException("Field '" + port.getName()
                            + "' in '" + _class + "' is null?");
                } else {
                    if (typ.equals("boolean")) {
                        try {
                            port.send(0,
                                    new BooleanToken(field.getBoolean(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("double")) {
                        try {
                            port.send(0, new DoubleToken(field.getDouble(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("int")) {
                        try {
                            port.send(0, new IntToken(field.getInt(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("char")) {
                        try {
                            port.send(0, new UnsignedByteToken(field
                                    .getChar(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("class [I")) {
                        try {
                            if (field == null) {
                                throw new InternalErrorException(
                                        "field == null?");
                            }
                            if (obj == null) {
                                throw new InternalErrorException("obj == null?");
                            }
                            if (field.get(obj) == null) {
                                throw new InternalErrorException(
                                        "field.get(obj)  == null? (field = "
                                                + field + " obj = " + obj);
                            }
                            Token[] toks = new Token[((int[]) field.get(obj)).length];

                            for (int j = 0; j < ((int[]) field.get(obj)).length; j++) {
                                toks[j] = new IntToken(
                                        ((int[]) field.get(obj))[j]);
                            }

                            port.send(0, new ArrayToken(BaseType.INT, toks));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("class [D")) {
                        try {
                            Token[] toks = new Token[((double[]) field.get(obj)).length];

                            for (int j = 0; j < ((double[]) field.get(obj)).length; j++) {
                                toks[j] = new DoubleToken(((double[]) field
                                        .get(obj))[j]);
                            }

                            port.send(0, new ArrayToken(toks));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else {
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     @exception IllegalActionException If there is a problem updating
     *  the ports.
     */
    public void updatePorts() throws IllegalActionException {
        Iterator arguments = this.argumentsList().iterator();
        TypedIOPort port;

        while (arguments.hasNext()) {
            Argument argument = (Argument) arguments.next();
            port = (TypedIOPort) this.getPort(argument.getName());

            if (port == null) {
                MoMLChangeRequest request = null;

                try {
                    if (argument.isReturn()) {

                        request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + "</port>");
                    } else if (argument.isInput() && argument.isOutput()) {
                        request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "in"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"input\"/>\n"
                                        + "</port>\n"
                                        + "<port name=\""
                                        + argument.getName()
                                        + "out"
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + "</port>");
                    } else {
                        request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + (argument.isInput() ? "    <property name=\"input\"/>\n"
                                                : "")
                                        + (argument.isOutput() ? "    <property name=\"output\"/>\n"
                                                : "") + "</port>");

                    }
                    request.setUndoable(true);
                    requestChange(request);
                } catch (Throwable throwable) {
                    throw new IllegalActionException(this, throwable,
                            "MoMLChangeRequest for \"" + argument.getName()
                                    + "\" failed. Request was:\n" + request);
                }
            } else {
                // We have a preexisting port, synchronized the
                // arguments and the ports.

                if (argument.isReturn()) {
                    if (port.isInput()) {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <deleteProperty name=\"input\"/>\n"
                                        + (port.isOutput() ? ""
                                                : "    <property name=\"output\"/>\n")
                                        + "</port>");
                        request.setUndoable(true);
                        requestChange(request);
                    }
                    if (!port.isOutput()) {
                        MoMLChangeRequest request = new MoMLChangeRequest(
                                this,
                                this,
                                "<port name=\""
                                        + argument.getName()
                                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                        + "    <property name=\"output\"/>\n"
                                        + "</port>");
                        request.setUndoable(true);
                        requestChange(request);
                    }
                } else /*if (port.isInput() != argument.isInput()
                                                              || port.isOutput() != argument.isOutput())*/{
                    MoMLChangeRequest request = new MoMLChangeRequest(
                            this,
                            this,
                            "<port name=\""
                                    + argument.getName()
                                    + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                                    + (port.isInput() ? (argument.isInput() ? ""
                                            : "<deleteProperty name=\"input\"/>\n")
                                            : (argument.isInput() ? "<property name=\"input\"/>\n"
                                                    : ""))
                                    + (port.isOutput() ? (argument.isOutput() ? ""
                                            : "<deleteProperty name=\"output\"/>\n")
                                            : (argument.isOutput() ? "<property name=\"output\"/>\n"
                                                    : "")) + "</port>");
                    request.setUndoable(true);
                    requestChange(request);
                }
            }
        }

        // Remove any ports that do not have arguments.
        Iterator ports = portList().iterator();

        while (ports.hasNext()) {
            port = (TypedIOPort) ports.next();
            Argument argument = (Argument) _argumentsList.get(port.getName());
            if (argument == null) {
                MoMLChangeRequest request = new MoMLChangeRequest(this, this,
                        "<deletePort name=\"" + port.getName() + "\"/>");
                request.setUndoable(true);
                requestChange(request);

            }
        }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * @exception NameDuplicationException If the container already has an
     * actor with this name.
     */
    public Counter(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException  {
        super(container, name);
        increment = new TypedIOPort(this, "increment", true, false);
        increment.setTypeEquals(BaseType.GENERAL);
        decrement = new TypedIOPort(this, "decrement", true, false);
        decrement.setTypeEquals(BaseType.GENERAL);
        output = new TypedIOPort(this, "output", false, true);
        output.setTypeEquals(BaseType.INT);
    }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * an actor already in the container.
     */
    public Switch(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException  {
        super(container, name);
        output.setMultiport(true);
        control = new TypedIOPort(this, "control", true, false);
        control.setTypeEquals(BaseType.INT);
        StringAttribute controlCardinal = new StringAttribute(control, "_cardinal");
        controlCardinal.setExpression("SOUTH");
    }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * actor with this name.
     */
    public Accumulator(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException  {
        super(container, name);
        input.setMultiport(true);
        reset = new TypedIOPort(this, "reset", true, false);
        reset.setTypeEquals(BaseType.BOOLEAN);
        reset.setMultiport(true);
        init = new Parameter(this, "init");
        init.setExpression("0");
        lowerBound = new Parameter(this, "lowerBound");
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * @exception NameDuplicationException If the container already has an
     * actor with this name.
     */
    public Average(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException  {
        super(container, name);
        reset = new TypedIOPort(this, "reset", true, false);
        reset.setTypeEquals(BaseType.BOOLEAN);
    }
View Full Code Here

Examples of ptolemy.actor.TypedIOPort

     * @exception NameDuplicationException If the name coincides with
     * an actor already in the container.
     */
    public BooleanSelect(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException  {
        super(container, name);
        trueInput = new TypedIOPort(this, "trueInput", true, false);
        falseInput = new TypedIOPort(this, "falseInput", true, false);
        control = new TypedIOPort(this, "control", true, false);
        control.setTypeEquals(BaseType.BOOLEAN);
        output = new TypedIOPort(this, "output", false, true);
        output.setTypeAtLeast(trueInput);
        output.setTypeAtLeast(falseInput);
        StringAttribute controlCardinal = new StringAttribute(control, "_cardinal");
        controlCardinal.setExpression("SOUTH");
        _attachText("_iconDescription", "<svg>\n" + "<rect x=\"-20\" y=\"-20\" "+"width=\"40\" height=\"40\" "+"style=\"fill:white\"/>\n"+"<text x=\"-17\" y=\"-3\" "+"style=\"font-size:14\">\n"+"T \n"+"</text>\n"+"<text x=\"-17\" y=\"15\" "+"style=\"font-size:14\">\n"+"F \n"+"</text>\n"+"<text x=\"-5\" y=\"16\" "+"style=\"font-size:14\">\n"+"C \n"+"</text>\n"+"</svg>\n");
View Full Code Here
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.