Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/cadmodels/IncidentEvent.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/cadmodels/IncidentEvent.java @ 2

Revision 2, 8.7 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

RevLine 
1package tmcsim.cadmodels;
2
3import java.io.Serializable;
4import java.util.Vector;
5
6import tmcsim.common.CCTVInfo;
7import tmcsim.common.XMLIncident;
8
9/**
10 * IncidentEvent class contains data for an event that occurs during a
11 * simulation.  Incident event information includes the following:<br/>
12 * <ul>
13 * <li>Second after Incident begins Event is schedule to occur.</li>
14 * <li>Simulation time Event occurs.</li>
15 * <li>IncidentInquiry model data.</li>
16 * <li>Audio file name and duration.</li>
17 * <li>XMLIncident Objects</li>
18 * <li>CCTVInfo Objects</li>
19 * <li>Current Event status.</li>
20 * </ul>
21 * <br/>
22 * <br/>
23 * The EVENT_STATUS is used to keep track of what state this event is in.  An
24 * event is WAITING until its time to occur is reached in the simulation.  The
25 * event will then enter the TRIGGERED state if it has a wave file length
26 * greater than 0, otherwise it will enter the COMPLETED state.  When an
27 * audio file is completed, the wavePlayed() method is called, and the Event
28 * enters the COMPLETED state.  The finalizeEvent method finalizes the Event by
29 * timestamping the model data and setting the number of seconds the event
30 * occured in the simulation.  The EVENT_STATUS is then set to FINALIZED.
31 *
32 * @author Matthew Cechini (mcechini@calpoly.edu)
33 * @version $Date: 2006/06/06 20:46:40 $ $Revision: 1.4 $
34 */
35@SuppressWarnings("serial")
36public class IncidentEvent implements Comparable<IncidentEvent>, Serializable {
37   
38    /**
39     * Enumeration
40     * @author Matthew Cechini
41     */
42    public static enum EVENT_STATUS {
43        /** Waiting to be triggered. */
44        WAITING,
45        /** Event has been triggered. */
46        TRIGGERED, 
47        /** Completed audio playing, if necessary. */
48        COMPLETED,   
49        /**
50         * Incident has been triggered, audio file has been played,
51         * and model data timestamped.
52         */
53        FINALIZED
54    };
55
56    /** Number of seconds after the incident begins that this event will trigger. */   
57    public long secondsToOccurInIncident;
58   
59    /** Number of seconds after the simulation started that this event occured. */ 
60    public long secondsOccuredInSimulation;
61   
62    /** Model object containing the data that will be added to the incident when this event occurs. */ 
63    public IncidentInquiryModel_obj eventInfo = null;
64   
65    /** Audio wav file associated with this event. */   
66    public String waveFile;
67   
68    /** Duration(in seconds) of the waveFile. */   
69    public int waveLength;
70           
71    /** Vector of XMLIncident objects which are associated with this incident event. */
72    public Vector<XMLIncident> XMLIncidents;
73   
74    /** Vector of CCTV objects which are associated with this incident event. */
75    public Vector<CCTVInfo> cctvInfos;
76   
77    /** Current Incident Event status. */
78    public EVENT_STATUS eventStatus;
79   
80
81    /** 
82     * Constructor.
83     *
84     * @param timeToOccur Time (in seconds) in simulation for this incident event to occur.
85     */
86    public IncidentEvent(long timeToOccur) {
87           
88        eventInfo       = new IncidentInquiryModel_obj();   
89        waveFile        = "";
90        waveLength      = 0;
91        eventStatus     = EVENT_STATUS.WAITING;
92        XMLIncidents    = new Vector<XMLIncident>();
93        cctvInfos       = new Vector<CCTVInfo>();
94
95        secondsToOccurInIncident   = timeToOccur;
96        secondsOccuredInSimulation = 0;   
97           
98    }   
99     
100   /**
101    * Constructor.
102    *
103    * @param timeToOccur      Time (in seconds) in simulation for this incident event to occur.
104    * @param info             IncidentInquiry model data.
105    * @param newWaveFile      Filename of audio wav file to be played with this event.
106    * @param newWaveLength    Duration (in seconds) of audio wav file
107    * @param newXMLIncidents  List of XMLIncidents for this event.
108    * @param newCCTVInfos     List of CCTVInfos for this event.
109    */
110    public IncidentEvent(long timeToOccur, 
111                         IncidentInquiryModel_obj info, 
112                         String newWaveFile, 
113                         int newWaveLength,
114                         Vector<XMLIncident> newXMLIncidents,
115                         Vector<CCTVInfo> newCCTVInfos){
116       
117        eventInfo       = info;
118        eventStatus     = EVENT_STATUS.WAITING;
119        waveFile        = newWaveFile;
120        waveLength      = newWaveLength;
121
122        XMLIncidents    = new Vector<XMLIncident>();
123        XMLIncidents.addAll(newXMLIncidents);
124       
125        cctvInfos       = new Vector<CCTVInfo>();
126        cctvInfos.addAll(newCCTVInfos);     
127       
128        secondsToOccurInIncident   = timeToOccur;
129        secondsOccuredInSimulation = 0;     
130    }
131   
132    /**
133     * Copy Constructor.
134     *
135     * @param timeToOccur      Time (in seconds) in simulation for this incident event to occur.
136     * @param info             IncidentInquiry model data.
137     * @param newWaveFile      Filename of audio wav file to be played with this event.
138     * @param newWaveLength    Duration (in seconds) of audio wav file
139     * @param newXMLIncidents  List of XMLIncidents for this event.
140     * @param newCCTVInfos     List of CCTVInfos for this event.
141     */
142     public IncidentEvent(final IncidentEvent copyEvent){
143       
144        eventInfo       = copyEvent.eventInfo;
145        eventStatus     = copyEvent.eventStatus;
146        waveFile        = copyEvent.waveFile;
147        waveLength      = copyEvent.waveLength;
148
149        XMLIncidents    = new Vector<XMLIncident>();
150        XMLIncidents.addAll(copyEvent.XMLIncidents);
151       
152        cctvInfos       = new Vector<CCTVInfo>();
153        cctvInfos.addAll(copyEvent.cctvInfos);     
154       
155        secondsToOccurInIncident   = copyEvent.secondsToOccurInIncident;
156        secondsOccuredInSimulation = copyEvent.secondsOccuredInSimulation;     
157     }   
158   
159    /** Compare objects according o comparison of secondsToOccurInIncident member data. */
160    public int compareTo(IncidentEvent o) {
161        if(secondsToOccurInIncident < o.secondsToOccurInIncident)
162            return -1;
163           
164        else if(secondsToOccurInIncident > o.secondsToOccurInIncident)
165            return 1;
166       
167        else 
168            return 0;
169    }
170   
171    /**
172     * Method determines if the Event is ready to be triggered.  This is
173     * determined by assessing the current Event status and simulation
174     * time.  The Event will be triggered if the Event is WAITING and the
175     * Event's time to start has been reached.  The Event's relative start
176     * time is added to the Incident start time parameter and compared
177     * against the current simulation time parameter.  If the audio file
178     * duration is greater than  zero seconds, then the Event status is set to
179     * TRIGGERED, and true is returned.  If the audio file is zero, the status
180     * is set to COMPLETED and false is returned.
181     *
182     * @param incidentStartTime Simulation time that Event's Incident began (in seconds).
183     * @param simulationTime Current simulation time (in seconds).
184     * @return true if incident enters the TRIGGERED state, false if it is not
185     * ready to be triggered or has entered the COMPLETED state.
186     */
187    public boolean triggerEvent(long incidentStartTime, long simulationTime) {
188        boolean retVal = false;
189       
190        if(eventStatus == EVENT_STATUS.WAITING &&
191           simulationTime > (incidentStartTime + secondsToOccurInIncident) )
192        {               
193            if(waveLength == 0) {
194                eventStatus = EVENT_STATUS.COMPLETED;
195            }
196            else {
197                retVal = true;
198                eventStatus = EVENT_STATUS.TRIGGERED;
199            }
200        }
201       
202        return retVal;
203    }       
204   
205 
206    /**
207     * Method is called when the Event's audio file completes.  The Event
208     * status is set to COMPLETED.
209     */
210    public void wavePlayed() {
211        eventStatus = EVENT_STATUS.COMPLETED;
212    }
213   
214    /**
215     * Method is called to finalize and Event.  The Event info
216     * is timestamped with the parameter and the  secondsInSimulationOccured
217     * member is set to the current time in the simulation.  The Event
218     * status is set to FINALIZED.
219     *
220     * @param occured Current simulation time (in seconds).
221     * @param timestamp CAD time stamp for model data.
222     */
223    public void finalizeEvent(long occured, String timestamp) {
224        //set time stamp
225        eventInfo.timeStamp(timestamp);     
226        secondsOccuredInSimulation = occured;
227       
228        eventStatus = EVENT_STATUS.FINALIZED;
229    }
230   
231    /**
232     * Called to reset the simulation.  The Event status is set to WAITING and
233     * the secondsOccuredinSimulation is reset to 0.
234     */
235    public void resetSimulation() {
236        eventStatus = EVENT_STATUS.WAITING;
237        secondsOccuredInSimulation = 0;
238    }
239
240} 
Note: See TracBrowser for help on using the repository browser.