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
032//tokens
033import ptolemy.actor.TypedAtomicActor;
034import ptolemy.actor.TypedIOPort;
035import ptolemy.data.IntToken;
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////NextDiagram
044/**
045 * This is a domain specific actor used within the GEON mineral classification
046 * workflow for choosing the next iteration's diagram. (For now there are only
047 * two digitized diagram, so there is no actual transitions table. The actor
048 * will be extended once more diagrams are available).
049 * 
050 * @author Efrat Jaeger
051 * @version $Id: NextDiagram.java 24234 2010-05-06 05:21:26Z welker $
052 * @since Ptolemy II 3.0.2
053 */
054public class NextDiagram extends TypedAtomicActor {
055        // input ports
056        public TypedIOPort rowInfo = new TypedIOPort(this, "rowInfo", true, false);
057        public TypedIOPort transitionTable = new TypedIOPort(this,
058                        "transitionTable", true, false);
059        public TypedIOPort region = new TypedIOPort(this, "region", true, false);
060        // output ports
061        public TypedIOPort rockName = new TypedIOPort(this, "rockName", false, true);
062        public TypedIOPort nextDiagram = new TypedIOPort(this, "nextDiagram",
063                        false, true);
064
065        public NextDiagram(CompositeEntity container, String name)
066                        throws NameDuplicationException, IllegalActionException {
067                super(container, name);
068                region.setTypeEquals(BaseType.STRING);
069                transitionTable.setTypeEquals(BaseType.GENERAL);
070                rowInfo.setTypeEquals(BaseType.GENERAL);
071                nextDiagram.setTypeEquals(BaseType.INT); // index to the next diagram.
072                rockName.setTypeEquals(BaseType.STRING); // index to the next diagram.
073
074                _attachText("_iconDescription", "<svg>\n"
075                                + "<rect x=\"-30\" y=\"-20\" " + "width=\"60\" height=\"40\" "
076                                + "style=\"fill:white\"/>\n" + "<text x=\"-18\" y=\"-5\" "
077                                + "style=\"font-size:14\">\n" + "Next \n" + "</text>\n"
078                                + "<text x=\"-27\" y=\"13\" " + "style=\"font-size:14\">\n"
079                                + "diagram \n" + "</text>\n" + "</svg>\n");
080        }
081
082        public void fire() throws IllegalActionException {
083                // FIX ME: needs to be updated according to a transition table.
084                if (rowInfo.hasToken(0) && region.hasToken(0)
085                                && transitionTable.hasToken(0)) {
086                        StringToken regionToken = (StringToken) region.get(0); // FIX ME!!!
087                                                                                                                                        // TAKE CARE
088                                                                                                                                        // OF EMPTY
089                                                                                                                                        // REGION!!!
090                        String _region = regionToken.stringValue();
091                        if (_region.trim().startsWith("diorite")) {
092                                nextDiagram.broadcast(new IntToken(2));
093                        } else {
094                                rockName.broadcast(regionToken);
095                        }
096                }
097
098        }
099}