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

source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/data/IncidentEvent.java @ 3

Revision 3, 8.8 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files - cadclientgui

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