Changeset 38 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder
- Timestamp:
- 08/03/2017 04:30:19 PM (9 years ago)
- Location:
- trunk/src/scriptbuilder/structures
- Files:
-
- 22 edited
-
MyScriptHandler.java (modified) (7 diffs)
-
ScriptIncident.java (modified) (1 diff)
-
SimulationScript.java (modified) (8 diffs)
-
TimeSlice.java (modified) (1 diff)
-
events/ATMSEvaluationEvent.java (modified) (1 diff)
-
events/ActivityLogEvaluationEvent.java (modified) (1 diff)
-
events/AudioEvent.java (modified) (1 diff)
-
events/CADEvaluationEvent.java (modified) (1 diff)
-
events/CADEvent.java (modified) (1 diff)
-
events/CCTVEvent.java (modified) (1 diff)
-
events/CHPRadioEvent.java (modified) (1 diff)
-
events/CMSEvaluationEvent.java (modified) (1 diff)
-
events/FacilitatorEvaluationEvent.java (modified) (1 diff)
-
events/MaintenanceRadioEvent.java (modified) (1 diff)
-
events/ParamicsEvent.java (modified) (1 diff)
-
events/RadioEvaluationEvent.java (modified) (1 diff)
-
events/TMTRadioEvent.java (modified) (1 diff)
-
events/TelephoneEvent.java (modified) (1 diff)
-
events/TowEvent.java (modified) (1 diff)
-
events/UnitEvent.java (modified) (1 diff)
-
events/WitnessEvent.java (modified) (1 diff)
-
units/Unit.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/structures/MyScriptHandler.java
r37 r38 244 244 incidentMap = new TreeMap<Integer, ScriptIncident>(); 245 245 eventMap = new TreeMap<ELEMENT, I_ScriptEvent>(); 246 unitMap = new TreeMap<String, Unit>(); 246 247 pcData = new TreeMap<ELEMENT, String>(); 247 248 docPosition = new Stack<ELEMENT>(); … … 257 258 return new Vector<ScriptIncident>(incidentMap.values()); 258 259 } 260 261 /** 262 * Get the list of units that have been parsed from the script file. 263 * 264 * @returns Vector of Unit objects. 265 */ 266 public Vector<Unit> getUnits() 267 { 268 return new Vector<Unit>(unitMap.values()); 269 } 259 270 260 271 /** … … 265 276 { 266 277 //System.out.println("STUB: Start the document"); 267 for (ELEMENT e : ELEMENT.values()) 268 { 269 pcData.put(e, null); 270 } 278 271 279 } 272 280 … … 601 609 public void endElement(String uri, String localName, String qName) 602 610 { 603 604 611 currentElement = docPosition.pop(); 605 612 I_ScriptEvent newEvent = null; … … 791 798 } 792 799 793 else if ( qName.equals(ELEMENT.INCIDENT.tag))800 else if (currentElement == ELEMENT.INCIDENT) 794 801 { 795 802 currentIncName = parsedValue.toString(); … … 805 812 806 813 } 807 else if ( qName.equals(ELEMENT.NEW_UNIT))814 else if (currentElement == ELEMENT.NEW_UNIT) 808 815 { 809 816 if (unitMap.get(NewUnitNum) == null) … … 879 886 unit.Timer = pcData.remove(ELEMENT.TIMER); 880 887 } 888 unitMap.put(NewUnitNum, unit); 881 889 } 882 890 } -
trunk/src/scriptbuilder/structures/ScriptIncident.java
r34 r38 254 254 public String openTag(String s) 255 255 { 256 return "<" + s + "> \n";256 return "<" + s + ">"; 257 257 } 258 258 -
trunk/src/scriptbuilder/structures/SimulationScript.java
r30 r38 19 19 import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent; 20 20 import scriptbuilder.structures.ScriptIncident.SliceChangedEvent; 21 import scriptbuilder.structures.units.Unit; 21 22 22 23 /** … … 56 57 public List<ScriptIncident> incidents; 57 58 59 /** 60 * The units which participate in Unit events. 61 */ 62 public List<Unit> units; 63 58 64 //Somewhere in the code, something assumes that the list of incidents 59 65 //contains exactly 10 items. Until I can find and un-break that, this will do. … … 80 86 sh = new MyScriptHandler(this); 81 87 incidents = new ArrayList<ScriptIncident>(); 88 units = new ArrayList<Unit>(); 82 89 numberOfIncidents = 0; 83 90 84 // Create the media event85 /*incidents.add(new ScriptIncident(incidentColors[0], 100, "Media",86 "An incident for the media in CAD.", 10800, this));87 numberOfIncidents++;88 // Create the "other" event89 incidents.add(new ScriptIncident(incidentColors[9], 999, "Other",90 "An incident for small-scale events, false events, "91 + "and noise. All events added to this incident will "92 + "receive a randomly generated incident number.",93 10800, this));94 numberOfIncidents++;*/95 91 //Backfill with null incidents 96 92 for (int i = numberOfIncidents; i < INCIDENT_FILL_COUNT; i++) … … 98 94 incidents.add(null); 99 95 } 100 /*101 Add some demo events102 incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck",103 "Blueberry truck crashed on the freeway.", 8800, this));104 numberOfIncidents++;105 incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash",106 "Crash at construction site on Red Road.", 6800, this));107 numberOfIncidents++;108 incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip",109 "Car flipped across the lane divider on the freeway.", 7200, this));110 numberOfIncidents++;111 incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash",112 "Crash taking two lanes on Tree Road.", 4200, this));113 numberOfIncidents++;114 incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck",115 "Truck stalled on the freeway.", 2800, this));116 numberOfIncidents++;117 incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill",118 "Tomato trucked spilt tomatos all over the freeway.", 3200, this));119 incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection",120 "Crash at the intersection of Tree Road and Red Road.", 4300, this));121 incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat",122 "Bomb threat and Road X.", 6000, this));123 incidents.add(null);124 incidents.add(null);125 incidents.add(null);126 Random rng = new Random();127 ScriptEventType[] eventTypes = ScriptEventType.values();128 if (numberOfIncidents > 0)129 {130 for (int i = 0; i < 300; i++)131 {132 int n = rng.nextInt();133 int s = rng.nextInt();134 int e = rng.nextInt();135 if (n < 0)136 {137 n *= -1;138 }139 if (s < 0)140 {141 s *= -1;142 }143 if (e < 0)144 {145 e *= -1;146 }147 incidents.get(n % numberOfIncidents).slices.get(s % (incidents.get(n % numberOfIncidents).slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length]));148 }149 incidents.get(1).setOffset(200);150 incidents.get(2).setOffset(3400);151 incidents.get(3).setOffset(1400);152 incidents.get(4).setOffset(4400);153 incidents.get(5).setOffset(1400);154 incidents.get(6).setOffset(7600);155 incidents.get(7).setOffset(2400);156 incidents.get(8).setOffset(4800);157 }158 */159 96 } 160 97 … … 207 144 208 145 Vector<ScriptIncident> inc = sh.getIncidents(); 209 146 units = sh.getUnits(); 210 147 for (ScriptIncident sci : inc) 211 148 { … … 246 183 public String toXML() 247 184 { 185 ArrayList<TimeSlice> slices = allSlices(); 248 186 String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; 249 output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">"; 250 ArrayList<TimeSlice> slices = allSlices(); 187 output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n"; 251 188 output += openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + this.title + "\""); 189 190 if (units.size() > 0) 191 { 192 output += openTag(ELEMENT.SCRIPT_DATA.tag); 193 for (Unit unit : units) 194 { 195 output += unit.toXML(); 196 } 197 output += closeTag(ELEMENT.SCRIPT_DATA.tag); 198 } 252 199 for (TimeSlice slice : slices) 253 200 { … … 261 208 public String openTag(String s) 262 209 { 263 return "<" + s + "> \n";210 return "<" + s + ">"; 264 211 } 265 212 … … 291 238 for (ScriptIncident inc : incidents) 292 239 { 293 240 294 241 if (inc != null && inc.slices.get(i) != null) 295 242 { -
trunk/src/scriptbuilder/structures/TimeSlice.java
r37 r38 260 260 public String openTag(String s) 261 261 { 262 return "<" + s + "> \n";262 return "<" + s + ">"; 263 263 } 264 264 -
trunk/src/scriptbuilder/structures/events/ATMSEvaluationEvent.java
r37 r38 68 68 public String openTag(String s) 69 69 { 70 return "<" + s + "> \n";70 return "<" + s + ">"; 71 71 } 72 72 -
trunk/src/scriptbuilder/structures/events/ActivityLogEvaluationEvent.java
r37 r38 68 68 public String openTag(String s) 69 69 { 70 return "<" + s + "> \n";70 return "<" + s + ">"; 71 71 } 72 72 -
trunk/src/scriptbuilder/structures/events/AudioEvent.java
r35 r38 37 37 public String openTag(String s) 38 38 { 39 return "<" + s + "> \n";39 return "<" + s + ">"; 40 40 } 41 41 -
trunk/src/scriptbuilder/structures/events/CADEvaluationEvent.java
r37 r38 68 68 public String openTag(String s) 69 69 { 70 return "<" + s + "> \n";70 return "<" + s + ">"; 71 71 } 72 72 -
trunk/src/scriptbuilder/structures/events/CADEvent.java
r35 r38 40 40 public String openTag(String s) 41 41 { 42 return "<" + s + "> \n";42 return "<" + s + ">"; 43 43 } 44 44 -
trunk/src/scriptbuilder/structures/events/CCTVEvent.java
r36 r38 39 39 public String openTag(String s) 40 40 { 41 return "<" + s + "> \n";41 return "<" + s + ">"; 42 42 } 43 43 -
trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java
r35 r38 54 54 public String openTag(String s) 55 55 { 56 return "<" + s + "> \n";56 return "<" + s + ">"; 57 57 } 58 58 -
trunk/src/scriptbuilder/structures/events/CMSEvaluationEvent.java
r36 r38 87 87 public String openTag(String s) 88 88 { 89 return "<" + s + "> \n";89 return "<" + s + ">"; 90 90 } 91 91 -
trunk/src/scriptbuilder/structures/events/FacilitatorEvaluationEvent.java
r37 r38 68 68 public String openTag(String s) 69 69 { 70 return "<" + s + "> \n";70 return "<" + s + ">"; 71 71 } 72 72 -
trunk/src/scriptbuilder/structures/events/MaintenanceRadioEvent.java
r28 r38 40 40 public String openTag(String s) 41 41 { 42 return "<" + s + "> \n";42 return "<" + s + ">"; 43 43 } 44 44 -
trunk/src/scriptbuilder/structures/events/ParamicsEvent.java
r35 r38 36 36 public String openTag(String s) 37 37 { 38 return "<" + s + "> \n";38 return "<" + s + ">"; 39 39 } 40 40 -
trunk/src/scriptbuilder/structures/events/RadioEvaluationEvent.java
r37 r38 69 69 public String openTag(String s) 70 70 { 71 return "<" + s + "> \n";71 return "<" + s + ">"; 72 72 } 73 73 -
trunk/src/scriptbuilder/structures/events/TMTRadioEvent.java
r36 r38 38 38 public String openTag(String s) 39 39 { 40 return "<" + s + "> \n";40 return "<" + s + ">"; 41 41 } 42 42 -
trunk/src/scriptbuilder/structures/events/TelephoneEvent.java
r35 r38 56 56 public String openTag(String s) 57 57 { 58 return "<" + s + "> \n";58 return "<" + s + ">"; 59 59 } 60 60 -
trunk/src/scriptbuilder/structures/events/TowEvent.java
r36 r38 35 35 public String openTag(String s) 36 36 { 37 return "<" + s + "> \n";37 return "<" + s + ">"; 38 38 } 39 39 -
trunk/src/scriptbuilder/structures/events/UnitEvent.java
r35 r38 35 35 public String openTag(String s) 36 36 { 37 return "<" + s + "> \n";37 return "<" + s + ">"; 38 38 } 39 39 -
trunk/src/scriptbuilder/structures/events/WitnessEvent.java
r36 r38 43 43 public String openTag(String s) 44 44 { 45 return "<" + s + "> \n";45 return "<" + s + ">"; 46 46 } 47 47 -
trunk/src/scriptbuilder/structures/units/Unit.java
r1 r38 5 5 */ 6 6 package scriptbuilder.structures.units; 7 8 import scriptbuilder.structures.ELEMENT; 9 import scriptbuilder.structures.I_XML_Writable; 7 10 8 11 /** … … 13 16 * @author Bryan McGuffin 14 17 */ 15 public class Unit 18 public class Unit implements I_XML_Writable 16 19 { 17 20 18 public String UnitNum = ""; 19 20 public String ID = ""; 21 22 public String Status = ""; 23 24 public String Master_Inc_Num = ""; 25 26 public String Primary = ""; 27 28 public String OOS = ""; 29 30 public String Type = ""; 31 32 public String Curr_Loc = ""; 33 34 public String Destination = ""; 35 36 public String Misc_Info = ""; 37 38 public String Stack = ""; 39 40 public String Area = ""; 41 42 public String Officer = ""; 43 44 public String Badge_Num = ""; 45 46 public String Timer = ""; 47 48 public String Office = ""; 49 50 public String P = ""; 51 52 public String Agy = ""; 53 54 public String Alias = ""; 55 56 public String Unit_Status = ""; 57 21 public String UnitNum; 22 23 public String ID; 24 25 public String Status; 26 27 public String Master_Inc_Num; 28 29 public String Primary; 30 31 public String OOS; 32 33 public String Type; 34 35 public String Curr_Loc; 36 37 public String Destination; 38 39 public String Misc_Info; 40 41 public String Stack; 42 43 public String Area; 44 45 public String Officer; 46 47 public String Badge_Num; 48 49 public String Timer; 50 51 public String Office; 52 53 public String P; 54 55 public String Agy; 56 57 public String Alias; 58 59 public String Unit_Status; 60 61 public Unit() 62 { 63 UnitNum = ""; 64 65 ID = ""; 66 67 Status = ""; 68 69 Master_Inc_Num = ""; 70 71 Primary = ""; 72 73 OOS = ""; 74 75 Type = ""; 76 77 Curr_Loc = ""; 78 79 Destination = ""; 80 81 Misc_Info = ""; 82 83 Stack = ""; 84 85 Area = ""; 86 87 Officer = ""; 88 89 Badge_Num = ""; 90 91 Timer = ""; 92 93 Office = ""; 94 95 P = ""; 96 97 Agy = ""; 98 99 Alias = ""; 100 101 Unit_Status = ""; 102 } 103 104 @Override 105 public String toXML() 106 { 107 String output = openTag(ELEMENT.NEW_UNIT.tag + " UnitNum=\"" + UnitNum + "\""); 108 109 if (!ID.equals("")) 110 { 111 output += openTag(ELEMENT.ID.tag) + ID + closeTag(ELEMENT.ID.tag); 112 } 113 114 if (!Status.equals("")) 115 { 116 output += openTag(ELEMENT.STATUS.tag) + Status + closeTag(ELEMENT.STATUS.tag); 117 } 118 119 if (!Master_Inc_Num.equals("")) 120 { 121 output += openTag(ELEMENT.MASTER_INC_NUM.tag) + Master_Inc_Num + closeTag(ELEMENT.MASTER_INC_NUM.tag); 122 } 123 124 if (!Primary.equals("")) 125 { 126 output += openTag(ELEMENT.PRIMARY.tag) + Primary + closeTag(ELEMENT.PRIMARY.tag); 127 } 128 129 if (!OOS.equals("")) 130 { 131 output += openTag(ELEMENT.OOS.tag) + OOS + closeTag(ELEMENT.OOS.tag); 132 } 133 134 if (!Type.equals("")) 135 { 136 output += openTag(ELEMENT.TYPE.tag) + Type + closeTag(ELEMENT.TYPE.tag); 137 } 138 139 if (!Curr_Loc.equals("")) 140 { 141 output += openTag(ELEMENT.CURR_LOC.tag) + Curr_Loc + closeTag(ELEMENT.CURR_LOC.tag); 142 } 143 144 if (!Destination.equals("")) 145 { 146 output += openTag(ELEMENT.DESTINATION.tag) + Destination + closeTag(ELEMENT.DESTINATION.tag); 147 } 148 149 if (!Misc_Info.equals("")) 150 { 151 output += openTag(ELEMENT.MISC_INFO.tag) + Misc_Info + closeTag(ELEMENT.MISC_INFO.tag); 152 } 153 154 if (!Stack.equals("")) 155 { 156 output += openTag(ELEMENT.STACK.tag) + Stack + closeTag(ELEMENT.STACK.tag); 157 } 158 159 if (!Area.equals("")) 160 { 161 output += openTag(ELEMENT.AREA.tag) + Area + closeTag(ELEMENT.AREA.tag); 162 } 163 164 if (!Badge_Num.equals("")) 165 { 166 output += openTag(ELEMENT.BADGE_NUM.tag) + Badge_Num + closeTag(ELEMENT.BADGE_NUM.tag); 167 } 168 169 if (!Officer.equals("")) 170 { 171 output += openTag(ELEMENT.OFFICER.tag) + Officer + closeTag(ELEMENT.OFFICER.tag); 172 } 173 174 if (!Office.equals("")) 175 { 176 output += openTag(ELEMENT.OFFICE.tag) + Office + closeTag(ELEMENT.OFFICE.tag); 177 } 178 179 if (!Timer.equals("")) 180 { 181 output += openTag(ELEMENT.TIMER.tag) + Timer + closeTag(ELEMENT.TIMER.tag); 182 } 183 184 if (!P.equals("")) 185 { 186 output += openTag(ELEMENT.P.tag) + P + closeTag(ELEMENT.P.tag); 187 } 188 189 if (!Agy.equals("")) 190 { 191 output += openTag(ELEMENT.AGY.tag) + Agy + closeTag(ELEMENT.AGY.tag); 192 } 193 194 if (!Alias.equals("")) 195 { 196 output += openTag(ELEMENT.ALIAS.tag) + Alias + closeTag(ELEMENT.ALIAS.tag); 197 } 198 199 if (!Unit_Status.equals("")) 200 { 201 output += openTag(ELEMENT.UNIT_STATUS.tag) + Unit_Status + closeTag(ELEMENT.UNIT_STATUS.tag); 202 } 203 204 output += closeTag(ELEMENT.NEW_UNIT.tag); 205 return output; 206 } 207 208 @Override 209 public String openTag(String s) 210 { 211 return "<" + s + ">"; 212 } 213 214 @Override 215 public String closeTag(String s) 216 { 217 return "</" + s + ">\n"; 218 } 219 220 @Override 221 public String emptyTag(String s) 222 { 223 return "<" + s + "/>\n"; 224 } 58 225 }
Note: See TracChangeset
for help on using the changeset viewer.
