001/* A timed actor that outputs the current time . 002 003 Copyright (c) 1998-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.actor.lib; 029 030import ptolemy.actor.Actor; 031import ptolemy.actor.CompositeActor; 032import ptolemy.data.DoubleToken; 033import ptolemy.data.type.BaseType; 034import ptolemy.kernel.CompositeEntity; 035import ptolemy.kernel.util.IllegalActionException; 036import ptolemy.kernel.util.NameDuplicationException; 037import ptolemy.kernel.util.NamedObj; 038 039/////////////////////////////////////////////////////////////////// 040//// TopLevelCurrentTime 041 042/** 043Produce an output token on each firing with a value that is 044the time of the top level director. 045 046@author Jia Zou 047@version $Id$ 048@since Ptolemy II 8.0 049@Pt.ProposedRating Yellow (jiazou) 050@Pt.AcceptedRating 051@deprecated Use CurrentTime with useLocalTime unchecked. 052 */ 053@Deprecated 054public class TopLevelCurrentTime extends TimedSource { 055 /** Construct an actor with the given container and name. 056 * 057 * @param container The container. 058 * @param name The name of this actor. 059 * @exception IllegalActionException If the actor cannot be contained 060 * by the proposed container. 061 * @exception NameDuplicationException If the container already has an 062 * actor with this name. 063 */ 064 public TopLevelCurrentTime(CompositeEntity container, String name) 065 throws NameDuplicationException, IllegalActionException { 066 super(container, name); 067 068 // set the type constraints. 069 output.setTypeEquals(BaseType.DOUBLE); 070 } 071 072 /////////////////////////////////////////////////////////////////// 073 //// public methods //// 074 075 /** Send the model time of the top level to the output. 076 * @exception IllegalActionException If send() throws it. 077 */ 078 @Override 079 public void fire() throws IllegalActionException { 080 081 NamedObj container = getContainer(); 082 while (container instanceof CompositeActor) { 083 if (((CompositeActor) container).getExecutiveDirector() == null) { 084 double time = ((Actor) container).getDirector().getModelTime() 085 .getDoubleValue(); 086 output.send(0, new DoubleToken(time)); 087 break; 088 } 089 container = container.getContainer(); 090 } 091 092 super.fire(); 093 } 094}