001/* A timed actor that outputs the simulated physical 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.domains.de.lib; 029 030import ptolemy.actor.lib.TimedSource; 031import ptolemy.data.IntToken; 032import ptolemy.data.type.BaseType; 033import ptolemy.domains.de.kernel.DEDirector; 034import ptolemy.kernel.CompositeEntity; 035import ptolemy.kernel.util.IllegalActionException; 036import ptolemy.kernel.util.NameDuplicationException; 037 038/////////////////////////////////////////////////////////////////// 039//// GetCurrentMicrostep 040 041/** 042Produce an output token on each firing with a value that is 043the current microstep, also called the current index, 044of superdense time. This can only be used with 045directors that implement SuperdenseTimeDirector. 046 047@author Jia Zou 048@version $Id$ 049@since Ptolemy II 8.0 050@see ptolemy.actor.SuperdenseTimeDirector 051@deprecated Use actor.lib.GetCurrentMicrostep instead. 052@Pt.ProposedRating Yellow (jiazou) 053@Pt.AcceptedRating Red 054 */ 055@Deprecated 056public class GetCurrentMicrostep extends TimedSource { 057 /** Construct an actor with the given container and name. 058 * 059 * @param container The container. 060 * @param name The name of this actor. 061 * @exception IllegalActionException If the actor cannot be contained 062 * by the proposed container. 063 * @exception NameDuplicationException If the container already has an 064 * actor with this name. 065 */ 066 public GetCurrentMicrostep(CompositeEntity container, String name) 067 throws NameDuplicationException, IllegalActionException { 068 super(container, name); 069 070 // set the type constraints. 071 output.setTypeEquals(BaseType.INT); 072 } 073 074 /////////////////////////////////////////////////////////////////// 075 //// public methods //// 076 077 /** Send the simulated physical time to the output, which is the 078 * currentTime of the enclosing DE director. 079 * @exception IllegalActionException If send() throws it. 080 */ 081 @Override 082 public void fire() throws IllegalActionException { 083 if (!(getDirector() instanceof DEDirector)) { 084 throw new IllegalActionException(this, 085 "Actor can only work with DE or PTIDES directors."); 086 } 087 DEDirector director = (DEDirector) getDirector(); 088 089 output.send(0, new IntToken(director.getMicrostep())); 090 091 super.fire(); 092 } 093 094}