001/*
002 * Copyright (c) 2002-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.geon;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.IntToken;
035import ptolemy.data.ObjectToken;
036import ptolemy.data.StringToken;
037import ptolemy.data.type.BaseType;
038import ptolemy.kernel.CompositeEntity;
039import ptolemy.kernel.util.IllegalActionException;
040import ptolemy.kernel.util.NameDuplicationException;
041
042//////////////////////////////////////////////////////////////////////////
043//// Diagrams
044/**
045 * This is a domain specific actor for processing Rock naming SVG diagrams.
046 * Receive all the diagrams information and the transitions between them from
047 * its predecessor, the DiagramsTransitions actor and a refernce to this level's
048 * diagram and extract the transitions table, the referenced diagram and its
049 * coordinates (For now there are only two digitized diagram, so there is no
050 * actual transitions table. The actor will be extended once more diagrams are
051 * available).
052 * 
053 * @author Efrat Jaeger
054 * @version $Id: Diagrams.java 24234 2010-05-06 05:21:26Z welker $
055 * @since Ptolemy II 3.0.2
056 */
057public class Diagrams extends TypedAtomicActor {
058
059        /**
060         * Construct an actor with the given container and name.
061         * 
062         * @param container
063         *            The container.
064         * @param name
065         *            The name of this actor.
066         * @exception IllegalActionException
067         *                If the actor cannot be contained by the proposed
068         *                container.
069         * @exception NameDuplicationException
070         *                If the container already has an actor with this name.
071         */
072        public Diagrams(CompositeEntity container, String name)
073                        throws NameDuplicationException, IllegalActionException {
074                super(container, name);
075
076                // set the type constraint.
077                diagramTransitions = new TypedIOPort(this, "diagramTransitions", true,
078                                false);
079                diagramTransitions.setTypeEquals(BaseType.STRING);
080                nextDiagram = new TypedIOPort(this, "nextDiagram", true, false);
081                nextDiagram.setTypeEquals(BaseType.INT);
082                coordinateNames = new TypedIOPort(this, "coordinateNames", false, true);
083                coordinateNames.setTypeEquals(BaseType.INT); // FIX ME: layer for demo
084                                                                                                                // purposes!
085                transitionTable = new TypedIOPort(this, "transitionTable", false, true);
086                transitionTable.setTypeEquals(BaseType.OBJECT);
087                diagram = new TypedIOPort(this, "diagram", false, true);
088                diagram.setTypeEquals(BaseType.STRING);
089
090                _attachText("_iconDescription", "<svg>\n"
091                                + "<rect x=\"-25\" y=\"-20\" " + "width=\"50\" height=\"40\" "
092                                + "style=\"fill:yellow\"/>\n"
093                                + "<polygon points=\"-15,-2 0,-15 15,-2 11,15 -11,15\" "
094                                + "style=\"fill:white\"/>\n" + "</svg>\n");
095        }
096
097        // /////////////////////////////////////////////////////////////////
098        // // ports and parameters ////
099
100        /**
101         * All the diagrams and transitions information.
102         */
103        public TypedIOPort diagramTransitions;
104
105        /**
106         * A reference to the diagram to be processed.
107         */
108        public TypedIOPort nextDiagram;
109
110        /**
111         * The coordinates of the referenced diagram.
112         */
113        public TypedIOPort coordinateNames;
114
115        /**
116         * Specifies the transitions between diagrams.
117         */
118        public TypedIOPort transitionTable; // FIX ME: needs to be implemented as
119                                                                                // soon as there are more diagrams.
120
121        /**
122         * An SVG diagram.
123         */
124        public TypedIOPort diagram;
125
126        // /////////////////////////////////////////////////////////////////
127        // // public methods ////
128
129        /**
130         * Receive diagrams information and a reference to the current diagram.
131         * Output the current diagram, its coordinates names and the transition
132         * table.
133         * 
134         * @exception IllegalActionException
135         *                If there's no director.
136         */
137        public void fire() throws IllegalActionException {
138                while (true) {
139
140                        // get the working directory.
141                        String _keplerPath = System.getProperty("user.dir");
142
143                        // FIX ME: for demo purposes since there are only two diagrams.
144                        IntToken layer = (IntToken) nextDiagram.get(0);
145                        coordinateNames.broadcast(layer); // FIX ME: layer would eventually
146                                                                                                // be the coordinates names.
147                        if (layer.intValue() == 1)
148                                diagram.broadcast(new StringToken(_keplerPath
149                                                + "/lib/testdata/geon/QAPF.svg"));
150                        else if (layer.intValue() == 2)
151                                diagram.broadcast(new StringToken(_keplerPath
152                                                + "/lib/testdata/geon/PlagPxOl.svg"));
153                        transitionTable.broadcast(new ObjectToken("transitions table"));
154
155                }
156        }
157}