Package ptolemy.kernel

Examples of ptolemy.kernel.Relation


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


                        // link the port relation should already exist
                        // from this port's creation in newPort()
                        String relationName = getName() + "Relation";
                        ModalModel model = (ModalModel) container
                                .getContainer();
                        Relation relation = model.getRelation(relationName);

                        if (relation != null) {
                            sibling.link(relation);
                        }
View Full Code Here

            // The default bend radius of 50 is too large...
            // parallel curves look bad.
            connector.setBendRadius(20);

            Relation relation = link.getRelation();

            if (relation != null) {
                String tipText = relation.getName();
                String displayName = relation.getDisplayName();
                if (!tipText.equals(displayName)) {
                    tipText = displayName + " (" + tipText + ")";
                }
                connector.setToolTipText(tipText);

                try {
                    // FIXME: This isn't quite right for relation groups.
                    StringAttribute colorAttribute = (StringAttribute) (relation
                            .getAttribute("_color", StringAttribute.class));

                    if (colorAttribute != null) {
                        String color = colorAttribute.getExpression();
                        if (color != null && !color.trim().equals("")) {
                            connector.setStrokePaint(SVGUtilities
                                    .getColor(color));
                        }
                    }
                } catch (IllegalActionException e) {
                    // Ignore;
                }
                try {
                    // FIXME: This isn't quite right for relation groups.
                    ColorAttribute colorAttribute = (ColorAttribute) (relation
                            .getAttribute("color", ColorAttribute.class));

                    if (colorAttribute != null) {
                        Color color = colorAttribute.asColor();
                        connector.setStrokePaint(color);
                    }
                } catch (IllegalActionException e) {
                    // Ignore;
                }

                StringAttribute _explAttr = (StringAttribute) (relation
                        .getAttribute("_explanation"));

                if (_explAttr != null) {
                    connector.setToolTipText(_explAttr.getExpression());
                }
View Full Code Here

                }

                _temporaryMatch.remove(patternContainer);
            } else {
                for (Object relationObject : patternPort.linkedRelationList()) {
                    Relation relation = (Relation) relationObject;
                    if (!_ignoreRelation(relation)) {
                        patternList.add(relation);
                    }
                }
                for (Object relationObject : hostPort.linkedRelationList()) {
                    Relation relation = (Relation) relationObject;
                    if (!_ignoreRelation(relation)) {
                        hostList.add(relation);
                    }
                }
            }
View Full Code Here

        sub.connect(subinDPx, (ComponentPort) lin.getPort("inputDPx"));
        sub.connect(subinDDPx, (ComponentPort) lin.getPort("inputDDPx"));
        sub.connect(subinD3Px, (ComponentPort) lin.getPort("inputD3Px"));
        sub.connect(subinD4Px, (ComponentPort) lin.getPort("inputD4Px"));

        Relation rInPz = sub.connect(subinPz, (ComponentPort) lin
                .getPort("inputPz"));

        //sub.connect(hPz.output, (ComponentPort)lin.getPort("inputPz"));
        sub.connect(subinDPz, (ComponentPort) lin.getPort("inputDPz"));
        sub.connect(subinDDPz, (ComponentPort) lin.getPort("inputDDPz"));
        sub.connect(subinD3Pz, (ComponentPort) lin.getPort("inputD3Pz"));
        sub.connect(subinD4Pz, (ComponentPort) lin.getPort("inputD4Pz"));

        sub.connect(suboutVx, (ComponentPort) lin.getPort("outputVx"));
        sub.connect(suboutVz, (ComponentPort) lin.getPort("outputVz"));

        Relation rV = sub.connect(suboutV, (ComponentPort) lin
                .getPort("outputV"));
        Relation rR = sub.connect(suboutR, (ComponentPort) lin
                .getPort("outputR"));

        // connect and set the monitors
        Parameter p = null;
View Full Code Here

        // any that don't have both ends in the model.
        Iterator links = _linkSet.iterator();

        while (links.hasNext()) {
            Arc link = (Arc) links.next();
            Relation relation = link.getRelation();

            if (relation == null) {
                continue;
            }

            // Check that the relation hasn't been removed.
            // If we do not do this, then redo will thrown an exception
            // if we open ct/demo/BouncingBall/BouncingBall.xml, look
            // inside the Ball Model composite actor,
            // delete the stop actor and then do undo and then redo.
            if (relation.getContainer() == null) {
                link.setHead(null);
                link.setTail(null);
                links.remove();
                continue;
            }

            boolean headOK = GraphUtilities.isContainedNode(link.getHead(),
                    getRoot(), this);
            boolean tailOK = GraphUtilities.isContainedNode(link.getTail(),
                    getRoot(), this);

            // If the head or tail has been removed, then remove this link.
            if (!(headOK && tailOK)) {
                //Object headObj = getSemanticObject(link.getHead());
                //Object tailObj = getSemanticObject(link.getTail());
                link.setHead(null);
                link.setTail(null);
                link.setRelation(null);
                links.remove();

                NamedObj container = getPtolemyModel();

                // remove the relation  This should trigger removing the
                // other link. This will only happen when we've deleted
                // the state at one end of the model.
                // Note that the source is NOT the graph model, so this
                // will trigger the ChangeRequest listener to
                // redraw the graph again.
                MoMLChangeRequest request = new MoMLChangeRequest(container,
                        container, "<deleteRelation name=\""
                                + relation.getName(container) + "\"/>\n");

                // Need to merge the undo for this request in with one that
                // triggered it
                request.setMergeWithPreviousUndo(true);
                request.setUndoable(true);
View Full Code Here

            HashSet createdSet) {
        _relationLocalMap = new HashMap();

        for (Iterator relations = composite.relationList().iterator(); relations
                .hasNext();) {
            Relation relation = (Relation) relations.next();
            String className = relation.getClass().getName();

            // Create a new local variable.
            Local local = PtolemyUtilities.createNamedObjAndLocal(body,
                    className, thisLocal, relation.getName());
            _relationLocalMap.put(relation, local);

            Relation classRelation = (Relation) _findDeferredInstance(relation);

            _updateCreatedSet(composite.getFullName() + "."
                    + relation.getName(), classRelation, classRelation,
                    createdSet);
View Full Code Here

                _updateCreatedSet(prefix, context, entity, set);
            }

            for (Iterator relations = composite.relationList().iterator(); relations
                    .hasNext();) {
                Relation relation = (Relation) relations.next();
                _updateCreatedSet(prefix, context, relation, set);
            }
        }

        if (object instanceof Entity) {
View Full Code Here

         */
        public String getDeleteEdgeMoML(Object edge) {
            final Arc link = (Arc) edge;
            //NamedObj linkHead = (NamedObj) link.getHead();
            //NamedObj linkTail = (NamedObj) link.getTail();
            Relation linkRelation = link.getRelation();

            // This moml is parsed to execute the change
            StringBuffer moml = new StringBuffer();

            // Make the request in the context of the container.
            // JDK1.2.2 fails to compile the next line.
            NamedObj container = getPtolemyModel();

            moml.append(_deleteRelation(container, linkRelation));

            // See whether refinement(s) need to be removed.
            CompositeEntity master = (CompositeEntity) linkRelation
                    .getContainer();

            // Nothing to do if there is no container.
            if (master != null) {
                // Remove any referenced refinements that are not also
                // referenced by other states.
                TypedActor[] refinements = null;

                try {
                    refinements = ((Transition) linkRelation).getRefinement();
                } catch (IllegalActionException e) {
                    // Ignore, no refinement to remove.
                }

                if (refinements != null) {
                    for (int i = 0; i < refinements.length; i++) {
                        TypedActor refinement = refinements[i];

                        // By default, if no other state or transition refers
                        // to this refinement, then we will remove it.
                        boolean removeIt = true;
                        Iterator states = master.entityList(State.class)
                                .iterator();

                        while (removeIt && states.hasNext()) {
                            State state = (State) states.next();
                            TypedActor[] stateRefinements = null;

                            try {
                                stateRefinements = state.getRefinement();
                            } catch (IllegalActionException e1) {
                                // Ignore, no refinement to check.
                            }

                            if (stateRefinements == null) {
                                continue;
                            }

                            for (int j = 0; j < stateRefinements.length; j++) {
                                if (stateRefinements[j] == refinement) {
                                    removeIt = false;
                                    break;
                                }
                            }
                        }

                        // Next check transitions.
                        Iterator transitions = master.relationList().iterator();

                        while (removeIt && transitions.hasNext()) {
                            Relation transition = (Relation) transitions.next();

                            if ((transition == linkRelation)
                                    || !(transition instanceof Transition)) {
                                continue;
                            }
View Full Code Here

         *  to make this modification.
         *  @param edge The edge, which is assumed to be an arc.
         */
        public void removeEdge(final Object edge) {
            final Arc link = (Arc) edge;
            Relation linkRelation = link.getRelation();

            // This moml is parsed to execute the change
            final StringBuffer moml = new StringBuffer();

            // Make the request in the context of the container.
View Full Code Here

TOP

Related Classes of ptolemy.kernel.Relation

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.