//*************************************************************** // Copyright 2008 Centre For Advanced Spatial Analysis, UCL // // Author: Joel Dearden, University College London // // Contact: j.dearden@ucl.ac.uk // // Joel Dearden, // Centre for Advanced Spatial Analysis, // University College London, // 1-19 Torrington Place, // London, // WC1E 7HB // // // This file is part of PedTrace. // // PedTrace is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // PedTrace is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with PedTrace. If not, see . // //*************************************************************** using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Drawing; using pedTrace; public partial class output : System.Web.UI.Page { private PTModel fModel; protected void Page_Load(object sender, EventArgs e) { //if the model is not valid print error if (Cache[globals.MODEL_CACHE_NAME] == null) { startTimeLiteral.Visible = false; realSecondsLiteral.Visible = false; totalAgentsInLiteral.Visible = false; totalAgentsOutLiteral.Visible = false; errorLiteral.Visible = true; errorLiteral.Text = "ERROR: no model data"; return; } //retrieve model this.fModel = (PTModel)Cache.Get(globals.MODEL_CACHE_NAME); //dynamically render a new image for each floor System.Drawing.Image i; for (int floorIndex = 0; floorIndex < globals.MAX_FLOORS; floorIndex++) { if (fModel.floorExists(floorIndex)) { i = new Bitmap(globals.IMAGE_SIZE, globals.IMAGE_SIZE); if (i == null) { startTimeLiteral.Visible = false; realSecondsLiteral.Visible = false; modelSecondsLiteral.Visible = false; totalAgentsInLiteral.Visible = false; totalAgentsOutLiteral.Visible = false; errorLiteral.Visible = true; errorLiteral.Text = "ERROR: null image"; return; } if (fModel == null) { startTimeLiteral.Visible = false; realSecondsLiteral.Visible = false; modelSecondsLiteral.Visible = false; totalAgentsInLiteral.Visible = false; totalAgentsOutLiteral.Visible = false; errorLiteral.Visible = true; errorLiteral.Text = "ERROR: null model"; return; } fModel.renderModel(ref i, floorIndex); //save image in correct place try { i.Save( globals.ABSOLUTE_DATA_PATH + globals.DISPLAY_IMAGE_FILENAME + floorIndex.ToString() + globals.DISPLAY_IMAGE_FILEEXTENSION); } catch (Exception) { startTimeLiteral.Visible = false; realSecondsLiteral.Visible = false; modelSecondsLiteral.Visible = false; totalAgentsInLiteral.Visible = false; totalAgentsOutLiteral.Visible = false; errorLiteral.Visible = true; errorLiteral.Text = "ERROR: can't write image data"; return; } //update image url switch (floorIndex) { case 0: floor0Image.ImageUrl = globals.RELATIVE_DATA_PATH + globals.DISPLAY_IMAGE_FILENAME + floorIndex.ToString() + globals.DISPLAY_IMAGE_FILEEXTENSION; floor0Image.Visible = true; break; case 1: floor1Image.ImageUrl = globals.RELATIVE_DATA_PATH + globals.DISPLAY_IMAGE_FILENAME + floorIndex.ToString() + globals.DISPLAY_IMAGE_FILEEXTENSION; floor1Image.Visible = true; break; default: throw new Exception("invalid floor index"); } } } //populate data fields startTimeLiteral.Visible = true; startTimeLiteral.Text = fModel.getStartTime().ToLongTimeString(); realSecondsLiteral.Visible = true; realSecondsLiteral.Text = fModel.getRunTime().TotalSeconds.ToString(); modelSecondsLiteral.Visible = true; modelSecondsLiteral.Text = fModel.getModelSeconds().ToString(); totalAgentsInLiteral.Visible = true; totalAgentsInLiteral.Text = fModel.getTotalAgentsIn().ToString(); totalAgentsOutLiteral.Visible = true; totalAgentsOutLiteral.Text = fModel.getTotalAgentsOut().ToString(); totalLineBarriersLiteral.Visible = true; totalLineBarriersLiteral.Text = fModel.getTotalLineBarriers().ToString(); errorLiteral.Visible = false; //render exit time graph i = new Bitmap(globals.IMAGE_SIZE, globals.IMAGE_SIZE); fModel.renderExitTimeGraph(ref i); //save image in correct place try { i.Save( globals.ABSOLUTE_DATA_PATH + globals.EXITTIME_GRAPH_IMAGE_FILENAME ); } catch (Exception) { errorLiteral.Text = "ERROR: can't write graph image data"; return; } //update image url exitTimeGraphImage.ImageUrl = globals.RELATIVE_DATA_PATH + globals.EXITTIME_GRAPH_IMAGE_FILENAME; exitTimeGraphImage.Visible = true; //render average speed graph i = new Bitmap(globals.IMAGE_SIZE, globals.IMAGE_SIZE); fModel.renderAverageSpeedGraph(ref i); //save image in correct place try { i.Save( globals.ABSOLUTE_DATA_PATH + globals.AVGSPEED_GRAPH_IMAGE_FILENAME ); } catch (Exception) { errorLiteral.Text = "ERROR: can't write graph image data"; return; } //update image url walkingSpeedGraphImage.ImageUrl = globals.RELATIVE_DATA_PATH + globals.AVGSPEED_GRAPH_IMAGE_FILENAME; walkingSpeedGraphImage.Visible = true; } }