Package ptolemy.kernel

Examples of ptolemy.kernel.CompositeEntity


     */
    protected CompositeEntity _createDefaultLibrary(Workspace workspace) {
        Configuration configuration = getConfiguration();

        if (configuration != null) {
            CompositeEntity result = (CompositeEntity) configuration
                    .getEntity("actor library");

            if (result == null) {
                // Create an empty library by default.
                result = new CompositeEntity(workspace);

                try {
                    result.setName("topLibrary");

                    // Put a marker in so that this is
                    // recognized as a library.
                    new Attribute(result, "_libraryMarker");
                } catch (Exception ex) {
View Full Code Here


                    + "insertAt and insertInsideAt, not both.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        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) {
View Full Code Here

            throw new XmlException("Element unlink requires two relations.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        CompositeEntity context = (CompositeEntity) _current;

        // Get relations.
        ComponentRelation relation1 = context.getRelation(relation1Name);
        _checkForNull(relation1, "No relation named \"" + relation1Name
                + "\" in " + context.getFullName());

        // Get relations.
        ComponentRelation relation2 = context.getRelation(relation2Name);
        _checkForNull(relation2, "No relation named \"" + relation2Name
                + "\" in " + context.getFullName());

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

        relation1.unlink(relation2);

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

        while (derivedObjects.hasNext()) {
            ComponentRelation derivedRelation1 = (ComponentRelation) derivedObjects
                    .next();
            CompositeEntity derivedContext = (CompositeEntity) derivedRelation1
                    .getContainer();
            ComponentRelation derivedRelation2 = derivedContext
                    .getRelation(relation2Name);
            derivedRelation1.unlink(derivedRelation2);
        }

        // Handle the undo aspect.
View Full Code Here

                    + "an index, an insideIndex, or a relation.",
                    _currentExternalEntity(), _getLineNumber(),
                    _getColumnNumber());
        }

        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);
            }
View Full Code Here

     */
    protected NamedObj _createModel(Workspace workspace) throws Exception {
        _toplevel = super._createModel(workspace);

        if (_toplevel instanceof CompositeEntity) {
            CompositeEntity toplevel = (CompositeEntity) _toplevel;
            TypeListener typeListener = new PortTypeListener();
            Iterator entities = toplevel.entityList().iterator();

            while (entities.hasNext()) {
                Entity entity = (Entity) entities.next();
                Iterator ports = entity.portList().iterator();

View Full Code Here

    ////                         private methods                   ////
    // Update the type designator for all ports contained by
    // entities contained by the toplevel.
    private void _updateAllTypeDisplays() {
        if (_toplevel instanceof CompositeEntity) {
            CompositeEntity toplevel = (CompositeEntity) _toplevel;
            Iterator entities = toplevel.entityList().iterator();

            while (entities.hasNext()) {
                Entity entity = (Entity) entities.next();
                Iterator ports = entity.portList().iterator();
View Full Code Here

     *  to generate a main loop.
     *  @return The generated body code.
     *  @exception IllegalActionException If there is no director.
     */
    protected String _generateBodyCode() throws IllegalActionException {
        CompositeEntity model = (CompositeEntity) getContainer();

        // NOTE: The cast is safe because setContainer ensures
        // the container is an Actor.
        ptolemy.actor.Director director = ((Actor) model).getDirector();

View Full Code Here

        _env = _extendEnvWithImports(_globalEnv, actor.getImports());
        _refreshTypedIOPorts(actor.getInputPorts(), true, false);
        _refreshTypedIOPorts(actor.getOutputPorts(), false, true);
        _refreshParameters();

        CompositeEntity container = (CompositeEntity) getContainer();

        if ((_lastGeneratedActorName != null)
                && _lastGeneratedActorName.equals(getName())) {
            if ((container != null)
                    && (container.getEntity(actor.getName()) != this)) {
                _lastGeneratedActorName = ((CompositeEntity) getContainer())
                        .uniqueName(actor.getName());
                setName(_lastGeneratedActorName);
            }
        }
View Full Code Here

                    "Cannot graphically edit a model "
                            + "that is not a CompositeEntity. Model is a "
                            + model);
        }

        CompositeEntity entity = (CompositeEntity) model;

        NavigableActorGraphFrame frame = new NavigableActorGraphFrame(entity,
                this, defaultLibrary);
        setFrame(frame);
        frame.setBackground(BACKGROUND_COLOR);
View Full Code Here

    /** Find the publisher, if there is one.
     *  @return A publisher, or null if none is found.
     */
    private Publisher _findPublisher() throws IllegalActionException {
        // Find the nearest opaque container above in the hierarchy.
        CompositeEntity container = (CompositeEntity) getContainer();
        while (container != null && !container.isOpaque()) {
            container = (CompositeEntity) container.getContainer();
        }
        if (container != null) {
            Iterator actors = container.deepEntityList().iterator();
            while (actors.hasNext()) {
                Object actor = actors.next();
                if (actor instanceof Publisher) {
                    if (_channel.equals(((Publisher) actor)._channel)) {
                        return (Publisher) actor;
View Full Code Here

TOP

Related Classes of ptolemy.kernel.CompositeEntity

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.