Package ptolemy.kernel

Examples of ptolemy.kernel.ComponentPort


                        }

                        Iterator entityPorts = entity.portList().iterator();

                        while (entityPorts.hasNext()) {
                            ComponentPort insidePort = (ComponentPort) entityPorts
                                    .next();
                            String name = insidePort.getName();

                            // The outside port may already exist (e.g.
                            // as a consequence of cloning).
                            IOPort newPort = (IOPort) getPort(name);

                            if (newPort == null) {
                                newPort = (IOPort) newPort(name);
                            }

                            if (insidePort instanceof IOPort) {
                                IOPort castPort = (IOPort) insidePort;
                                newPort.setMultiport(castPort.isMultiport());
                                newPort.setInput(castPort.isInput());
                                newPort.setOutput(castPort.isOutput());
                            }

                            // Set up inside connections.
                            // Do this only if they are not already connected.
                            List connectedPorts = insidePort
                                    .connectedPortList();

                            if (!connectedPorts.contains(newPort)) {
                                ComponentRelation relation = newRelation(uniqueName("relation"));
                                newPort.link(relation);
                                insidePort.link(relation);
                            }
                        }
                    } finally {
                        workspace().doneWriting();
                    }
View Full Code Here


     *   that of an entity already in the container.
     */
    public State(CompositeEntity container, String name)
            throws IllegalActionException, NameDuplicationException {
        super(container, name);
        incomingPort = new ComponentPort(this, "incomingPort");
        outgoingPort = new ComponentPort(this, "outgoingPort");
        refinementName = new StringAttribute(this, "refinementName");

        _attachText("_iconDescription", "<svg>\n"
                + "<circle cx=\"0\" cy=\"0\" r=\"20\" style=\"fill:white\"/>\n"
                + "</svg>\n");
View Full Code Here

     @see ptolemy.kernel.Relation#linkedPortList()
     @param ComponentRelation Print the linked ports for this relation.
     */
    public String printLinkedPorts(ComponentRelation r) {
        StringBuffer st = new StringBuffer(r.getName() + ": ");
        ComponentPort po;
        Enumeration ports = r.linkedPorts();

        while (ports.hasMoreElements()) {
            po = (ComponentPort) ports.nextElement();
            st.append(po.getName() + " ");
        }

        return st.toString() + "\n";
    }
View Full Code Here

     @param ComponentRelation Print the deeply linked ports for this
     *  relation.
     */
    public String printDeepLinkedPorts(ComponentRelation r) {
        StringBuffer st = new StringBuffer(r.getName() + ": ");
        ComponentPort po;
        Iterator ports = r.deepLinkedPortList().iterator();

        while (ports.hasNext()) {
            po = (ComponentPort) ports.next();
            st.append(po.getName() + " ");
        }

        return st.toString() + "\n";
    }
View Full Code Here

     @see ptolemy.kernel.Port#connectedPortList()
     @param ComponentPort Print the connected ports for this Port.
     */
    public String printConnectedPorts(ComponentPort p) {
        StringBuffer st = new StringBuffer(p.getName() + ": ");
        ComponentPort po;
        Iterator ports = p.connectedPortList().iterator();

        while (ports.hasNext()) {
            po = (ComponentPort) ports.next();
            st.append(po.getName() + " ");
        }

        return st.toString() + "\n";
    }
View Full Code Here

     @see ptolemy.kernel.ComponentPort#deepConnectedPortList()
     @param ComponentPort Print the deeply connected ports for this Port.
     */
    public String printDeepConnectedPorts(ComponentPort p) {
        StringBuffer st = new StringBuffer(p.getName() + ": ");
        ComponentPort po;
        Iterator ports = p.deepConnectedPortList().iterator();

        while (ports.hasNext()) {
            po = (ComponentPort) ports.next();
            st.append(po.getName() + " ");
        }

        return st.toString() + "\n";
    }
View Full Code Here

     @return The port.
     *  @exception XmlException If no such port is found.
     */
    private ComponentPort _getPort(String portspec, CompositeEntity context)
            throws XmlException {
        ComponentPort port = (ComponentPort) context.getPort(portspec);
        _checkForNull(port, "No port named \"" + portspec + "\" in "
                + context.getFullName());
        return port;
    }
View Full Code Here

        }

        CompositeEntity context = (CompositeEntity) _current;

        // Parse port
        ComponentPort port = _getPort(portName, context);

        // Save to help generate undo MoML
        int origNumOutsideLinks = port.numLinks();
        int origNumInsideLinks = port.numInsideLinks();

        // Get relation if given
        ComponentRelation relation = null;

        if (relationName != null) {
            Relation tmpRelation = context.getRelation(relationName);
            _checkForNull(tmpRelation, "No relation named \"" + relationName
                    + "\" in " + context.getFullName());
            relation = (ComponentRelation) tmpRelation;
        }

        // Ensure that derived objects aren't changed.
        // We have to prohibit adding links between class
        // elements because this operation cannot be undone, and
        // it will not be persistent.
        if (_isLinkInClass(context, port, relation)) {
            throw new IllegalActionException(port,
                    "Cannot link a port to a relation when both"
                            + " are part of the class definition.");
        }

        // Get the index if given
        int insertAt = -1;

        if (insertAtSpec != null) {
            insertAt = Integer.parseInt(insertAtSpec);
        }

        // Get the inside index if given
        int insertInsideAt = -1;

        if (insertInsideAtSpec != null) {
            insertInsideAt = Integer.parseInt(insertInsideAtSpec);
        }

        if (insertAtSpec != null) {
            port.insertLink(insertAt, relation);
        } else if (insertInsideAtSpec != null) {
            port.insertInsideLink(insertInsideAt, relation);
        } else {
            port.link(relation);
        }

        // Propagate. Get the derived list for the relation,
        // then use its container as the context in which to
        // find the port. NOTE: The relation can be null
        // (to insert an empty link in a multiport), so
        // we have two cases to consider.
        if (relation != null) {
            Iterator derivedObjects = relation.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentRelation derivedRelation = (ComponentRelation) derivedObjects
                        .next();
                CompositeEntity derivedContext = (CompositeEntity) derivedRelation
                        .getContainer();
                ComponentPort derivedPort = _getPort(portName, derivedContext);

                // NOTE: Duplicate the above logic exactly.
                if (insertAtSpec != null) {
                    derivedPort.insertLink(insertAt, derivedRelation);
                } else if (insertInsideAtSpec != null) {
                    derivedPort.insertInsideLink(insertInsideAt,
                            derivedRelation);
                } else {
                    derivedPort.link(derivedRelation);
                }
            }
        } else {
            Iterator derivedObjects = port.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentPort derivedPort = (ComponentPort) derivedObjects
                        .next();

                // NOTE: Duplicate the above logic exactly.
                if (insertAtSpec != null) {
                    derivedPort.insertLink(insertAt, null);
                } else if (insertInsideAtSpec != null) {
                    derivedPort.insertInsideLink(insertInsideAt, null);
                } else {
                    // This one probably shouldn't occur.
                    derivedPort.link(null);
                }
            }
        }

        // Handle the undo aspect.
View Full Code Here

        }

        CompositeEntity context = (CompositeEntity) _current;

        // Parse port
        ComponentPort port = _getPort(portName, context);

        // Get relation if given
        if (relationName != null) {
            Relation tmpRelation = context.getRelation(relationName);
            _checkForNull(tmpRelation, "No relation named \"" + relationName
                    + "\" in " + context.getFullName());

            ComponentRelation relation = (ComponentRelation) tmpRelation;

            // Ensure that derived objects aren't changed.
            if (_isLinkInClass(context, port, relation)) {
                throw new IllegalActionException(port,
                        "Cannot unlink a port from a relation when both"
                                + " are part of the class definition.");
            }

            // Handle the undoable aspect.
            // Generate a link in the undo only if one or the other relation is
            // not derived. If they are both derived, then the link belongs to
            // the class definition and should not be recreated in undo.
            if (_undoEnabled
                    && (port.getDerivedLevel() == Integer.MAX_VALUE || relation
                            .getDerivedLevel() == Integer.MAX_VALUE)) {
                // Get the relation at the given index
                List linkedRelations = port.linkedRelationList();
                int index = linkedRelations.indexOf(tmpRelation);

                if (index != -1) {
                    // Linked on the outside...
                    _undoContext.appendUndoMoML("<link port=\"" + portName
                            + "\" insertAt=\"" + index + "\" relation=\""
                            + relationName + "\" />\n");
                } else {
                    List insideLinkedRelations = port.insideRelationList();
                    index = insideLinkedRelations.indexOf(tmpRelation);

                    // Linked on the inside.
                    _undoContext.appendUndoMoML("<link port=\"" + portName
                            + "\" insertInsideAt=\"" + index + "\" relation=\""
                            + relationName + "\" />\n");
                }
            }

            // Propagate. Get the derived list for the relation,
            // then use its container as the context in which to
            // find the port.
            Iterator derivedObjects = relation.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentRelation derivedRelation = (ComponentRelation) derivedObjects
                        .next();
                CompositeEntity derivedContext = (CompositeEntity) derivedRelation
                        .getContainer();
                ComponentPort derivedPort = _getPort(portName, derivedContext);
                derivedPort.unlink(derivedRelation);
            }

            port.unlink(relation);
        } else if (indexSpec != null) {
            // index is given.
            int index = Integer.parseInt(indexSpec);

            // Ensure that derived objects aren't changed.
            // Unfortunately, getting the relation is fairly
            // expensive.
            List relationList = port.linkedRelationList();
            if (relationList.size() <= index) {
                throw new IllegalActionException(port, "Cannot unlink index "
                        + indexSpec + ", because there is no such link.");
            }
            Relation relation = (Relation) relationList.get(index);

            if (_isLinkInClass(context, port, relation)) {
                throw new IllegalActionException(port,
                        "Cannot unlink a port from a relation when both"
                                + " are part of the class definition.");
            }

            // Handle the undoable aspect before doing the unlinking.
            // Generate a link in the undo only if one or the other relation is
            // not derived. If they are both derived, then the link belongs to
            // the class definition and should not be recreated in undo.
            if (_undoEnabled) {
                // Get the relation at the given index.
                List linkedRelations = port.linkedRelationList();
                Relation r = (Relation) linkedRelations.get(index);
                // Generate undo moml only if either the port is
                // not derived or there is a relation and it is not derived.
                if (port.getDerivedLevel() == Integer.MAX_VALUE
                        || (r != null && r.getDerivedLevel() == Integer.MAX_VALUE)) {
                    // FIXME: need to worry about vertex?
                    _undoContext.appendUndoMoML("<link port=\"" + portName
                            + "\" insertAt=\"" + indexSpec + "\" ");

                    // Only need to specify the relation if there was
                    // a relation at that index. Otherwise a null
                    // link is inserted
                    if (r != null) {
                        _undoContext.appendUndoMoML("relation=\""
                                + r.getName(context) + "\" ");
                    }
                    _undoContext.appendUndoMoML(" />\n");
                }
            }

            // Propagate.
            Iterator derivedObjects = port.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentPort derivedPort = (ComponentPort) derivedObjects
                        .next();
                derivedPort.unlink(index);
            }

            port.unlink(index);
        } else {
            // insideIndex is given.
            int index = Integer.parseInt(insideIndexSpec);

            // Ensure that derived objects aren't changed.
            // Unfortunately, getting the relation is fairly
            // expensive.
            List relationList = port.insideRelationList();
            Relation relation = (Relation) relationList.get(index);

            if (_isLinkInClass(context, port, relation)) {
                throw new IllegalActionException(port,
                        "Cannot unlink a port from a relation when both"
                                + " are part of the class definition.");
            }

            // Handle the undoable aspect  before doing the unlinking
            if (_undoEnabled) {
                // Get the relation at the given index
                List linkedRelations = port.insideRelationList();
                Relation r = (Relation) linkedRelations.get(index);
                // Generate undo moml only if either the port is
                // not derived or there is a relation and it is not derived.
                if (port.getDerivedLevel() == Integer.MAX_VALUE
                        || (r != null && r.getDerivedLevel() == Integer.MAX_VALUE)) {
                    // FIXME: need to worry about vertex?
                    _undoContext.appendUndoMoML("<link port=\"" + portName
                            + "\" insertInsideAt=\"" + index + "\" ");

                    // Only need to specify the relation if there was
                    // a relation at that index. Otherwise a null
                    // link is inserted
                    if (r != null) {
                        _undoContext.appendUndoMoML("relation=\""
                                + r.getName(context) + "\" ");
                    }
                    _undoContext.appendUndoMoML(" />\n");
                }
            }

            // Propagate.
            Iterator derivedObjects = port.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                ComponentPort derivedPort = (ComponentPort) derivedObjects
                        .next();
                derivedPort.unlinkInside(index);
            }

            port.unlinkInside(index);
        }
    }
View Full Code Here

                NamedObj head = (NamedObj) getSemanticObject(linkHead);
                NamedObj tail = (NamedObj) getSemanticObject(linkTail);

                if (head instanceof ComponentPort
                        && tail instanceof ComponentPort) {
                    ComponentPort headPort = (ComponentPort) head;
                    ComponentPort tailPort = (ComponentPort) tail;

                    // Unlinking two ports with an anonymous relation.
                    moml.append("<unlink port=\"" + headPort.getName(container)
                            + "\" relation=\"" + relation.getName(container)
                            + "\"/>\n");
                    moml.append("<unlink port=\"" + tailPort.getName(container)
                            + "\" relation=\"" + relation.getName(container)
                            + "\"/>\n");
                    moml.append("<deleteRelation name=\""
                            + relation.getName(container) + "\"/>\n");
                } else if (head instanceof ComponentPort
View Full Code Here

TOP

Related Classes of ptolemy.kernel.ComponentPort

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.