public void UpdateScenarioNode(ScenarioForm scenario) { // Refreshes tree for given scenario (a branch is created if one does not exist) if (scenario == null) { return; } TreeNode scenarioNode = null; foreach (TreeNode node in mainTreeView.Nodes) { if (scenario == (ScenarioForm)node.Tag) { scenarioNode = node; break; } } if (scenarioNode == null) { // Create a new node for this scenario scenarioNode = new TreeNode(scenario.Scenario.ScenarioName); scenarioNode.Tag = scenario; mainTreeView.Nodes.Add(scenarioNode); } // Update child nodes, as well: model, environment, targetdeck, and results nodes UpdateModelNode(scenario.Scenario.Model, scenarioNode); UpdateTargetdeckNode(scenario.Scenario.Targetdeck, scenarioNode); UpdateEnvironmentNode(scenario.Scenario.Environment, scenarioNode); UpdateResultsNode(scenarioNode); }
private void launchMenuItem_Click(object sender, EventArgs e) { // Check for saved and launch runner for active scenario ScenarioForm form = (ScenarioForm)(getNodeFromElement(_activeScenario).Tag); if (form.IsSaved) { saveScenario(_activeScenario); } launchScenario(form); }
private void openScenarioFromFile() { // Opens new scenario using open file dialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Hsx file (.hsx)|*.hsx|All files|*.*"; dialog.Title = "Open Scenario"; if (dialog.ShowDialog() != DialogResult.OK) { return; } // Loads new scenario using components specified in given HSX file from dialog string filename = dialog.FileName; XqlParser myParser = new XqlParser(filename); List <Hashtable> result; // Determine paths result = myParser.Query("SELECT path FROM hsx"); string rootPath = (string)result[0]["path"]; result = myParser.Query("SELECT filename FROM scenario"); string scenPath = (string)rootPath + result[0]["filename"]; result = myParser.Query("SELECT filename FROM targetdeck"); string trgtPath = (string)rootPath + result[0]["filename"]; result = myParser.Query("SELECT filename FROM model"); string modlPath = (string)rootPath + result[0]["filename"]; // Create new scenario component from file and attach to form ScenarioComponent newScenario = new ScenarioComponent(); newScenario.FromFile(scenPath); ScenarioForm scenarioForm = new ScenarioForm(newScenario, this); scenarioForm.FileTarget = filename; _scenarios.Add(scenarioForm); // Form takes care of itself via node update? // Create new targetdeck from file and attach to scenario TargetdeckComponent newTargetdeck = new TargetdeckComponent(); newTargetdeck.FromFile(trgtPath); newScenario.Targetdeck = newTargetdeck; // Create new model from file and attach to scenario ModelComponent newModel = new ModelComponent(); newModel.FromFile(modlPath); newScenario.Model = newModel; // Update node tree and select scenario UpdateScenarioNode(scenarioForm); TreeNode node = getNodeFromForm(scenarioForm); mainTreeView.SelectedNode = node; }
protected override void HandleKeyboardState() { if (Game.IsKeyDown(Keys.O)) { var gameplayCameraValues = Utility.GetGameplayCameraValues(); Scenario.CameraSettings.Cameras.Add(gameplayCameraValues); } if (Game.IsKeyDown(Keys.K)) { var gwenForm = new WeatherForm(Scenario); ShowForm(gwenForm); } if (Game.IsKeyDown(Keys.J)) { Camera.DeleteAllCameras(); } if (Game.IsKeyDown(Keys.NumPad7)) { var gwenForm = new ScenarioForm(Scenario, DatasetAnnotator.RootScenariosDirectory); ShowForm(gwenForm); } if (Game.IsKeyDown(Keys.NumPad9)) { var gwenForm = new CameraForm(Scenario); ShowForm(gwenForm); } if (Game.IsKeyDown(Keys.NumPad1)) { var gwenForm = new PedsForm(Scenario); ShowForm(gwenForm); } if (Game.IsKeyDown(Keys.NumPad3)) { var gwenForm = new PlaceForm(Scenario); ShowForm(gwenForm); } if (Game.IsKeyDown(Keys.NumPad4)) { var gwenForm = new TimeForm(Scenario); ShowForm(gwenForm); } }
public BackgroundWorker Worker; // Handle / control point for asynch tasks #endregion #region Constructors public Picasso() { InitializeComponent(); // Initialize Mdi workspace mainMenuStrip.MdiWindowListItem = windowMenuItem; // Initialize list of scenarios _scenarios = new List <ScenarioForm>(); // Initialize documentation _documentationUrl = "http://tythos.net/horizon/documentation/picasso/"; _documentationForm = new SimpleBrowser(_documentationUrl, false); _documentationForm.MdiParent = this; _documentationForm.Text = "Picasso Documentation"; _documentationForm.Icon = Icon; _documentationForm.Persistent = true; // Initialize settings _settingsDialog = new PicassoSettings(); _settingsDialog.Icon = Icon; UpdateSettings(); // Initialize window title _textPrefix = "Horizon / Picasso"; Text = _textPrefix; // Create a blank scenario when application launches ScenarioForm defaultScenario = new ScenarioForm(this); _scenarios.Add(defaultScenario); UpdateTreeView(); // Create a SimpleBrower for displaying serialized elements, and set cache target _xmlBrowser = new SimpleBrowser("http://tythos.net/horizon/xmlBrowser.html", false); _xmlDumpLocation = "C:\\.horizonDump.xml"; _xmlBrowser.MdiParent = this; _xmlBrowser.Persistent = true; // Set up background worker Worker = new BackgroundWorker(); // Debugging setting: true will cause errors to be displayed via message box _isDebugging = true; }
private void closeScenario(ScenarioComponent scenario) { // Closes scenario of given component TreeNode node = getNodeFromScenario(scenario); if (node == null) { ReportError("Cannot close scenario; no node found"); return; } ScenarioForm form = (ScenarioForm)node.Tag; if (!form.IsSaved || form.FileTarget == "") { // Ask to save form if (MessageBox.Show("Save scenario before closing?", "Save Scenario", MessageBoxButtons.YesNo) == DialogResult.Yes) { // Save to file saveScenario(scenario); } } // Close all relevant forms, and remove from scenario & node list closeNodeForms(node); _scenarios.Remove(form); mainTreeView.Nodes.Remove(node); if (_scenarios.Count == 0) { // If there are no scenarios left, set active to null and disable close / save options _activeScenario = null; closeMenuItem.Enabled = false; saveMenuItem.Enabled = false; } else { // Otherwise, select first scenario _activeScenario = _scenarios[0].Scenario; _scenarios[0].Show(); } }
private void launchScenario(ScenarioForm scenarioForm) { // Launches given scenario with new horizon runner HorizonRunnerForm horizonRunner = new HorizonRunnerForm(); horizonRunner.FileName = _picassoSettings.Runner; horizonRunner.WorkingDirectory = _picassoSettings.WorkingDirectory; horizonRunner.OnSuccess = RunnerSucceded; horizonRunner.OnFailure = RunnerFailed; // Set up arguments (dynamically or not) if (_settingsDialog.AutoArgs) { // Mark file names ScenarioComponent baseScenario = (ScenarioComponent)scenarioForm.Element; string fileName = _picassoSettings.WorkingDirectory + @"\" + baseScenario.ScenarioName.Replace(" ", ""); string scenarioFileName = fileName + "_scenario.xml"; string targetdeckFileName = fileName + "_targetdeck.xml"; string modelFileName = fileName + "_model.xml"; string envFileName = fileName + "_env.xml"; // Save scenario files to working directory baseScenario.ToFile(scenarioFileName); baseScenario.Targetdeck.ToFile(targetdeckFileName); baseScenario.Model.ToFile(modelFileName); baseScenario.Environment.ToFile(envFileName); // Create argument from file names and output (working) directory horizonRunner.Arguments = scenarioFileName + " " + targetdeckFileName + " " + modelFileName + " " + _picassoSettings.WorkingDirectory; } else { // Use static arguments from settings form horizonRunner.Arguments = _picassoSettings.Arguments; } // Show and start runner horizonRunner.Show(); RunAndGetOutput(_picassoSettings.Runner); Worker.RunWorkerAsync(_picassoSettings.Runner); ScenarioInRunner = _activeScenario; }
public void CreateNewScenario() { // Create a new scenario with the name entered in a textbox dialog TextboxDialog dialog = new TextboxDialog("Create new scenario", "New scenario name"); dialog.ShowDialog(); if (dialog.Cancelled) { return; } // Create new scenario form with given name ScenarioForm newScenario = new ScenarioForm(this); newScenario.Scenario.ScenarioName = dialog.StringValue; // Add new scenario to scenario list and tree view _scenarios.Add(newScenario); UpdateScenarioNode(newScenario); _activeScenario = newScenario.Scenario; }
private ScenarioComponent getScenarioFromNode(TreeNode node) { // Returns the scenario component of the given node TreeNode focus = node; while (focus.Parent != null) { focus = focus.Parent; } try { ScenarioForm formReferenced = (ScenarioForm)focus.Tag; return(formReferenced.Scenario); } catch (NullReferenceException) { ReportError("Node has no tag"); } catch (InvalidCastException) { ReportError("Head node tag is not a scenario form"); } return(new ScenarioComponent()); }
private void saveScenario(ScenarioComponent scenario) { // Saves scenario with given component to file TreeNode scenarioNode = null; foreach (TreeNode node in mainTreeView.Nodes) { if (((ScenarioForm)node.Tag).Scenario == scenario) { scenarioNode = node; } } if (scenarioNode == null) { // No node exists with given scenario component ReportError("No node exists with given scenario component"); return; } // Get file target from form ScenarioForm form = (ScenarioForm)scenarioNode.Tag; bool incrementVersion = false; if (form.FileTarget == "") { // Need to specify save file incrementVersion = true; SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Hsx file (.hsx)|*.hsx|All files|*.*"; dialog.Title = "Save Scenario"; if (dialog.ShowDialog() != DialogResult.OK) { return; } form.FileTarget = dialog.FileName; } Match match = Regex.Match(form.FileTarget, "[\\.a-zA-Z]+$"); string fileName = Regex.Replace(match.Groups[0].ToString(), "\\.[a-zA-Z]{2,3}$", ""); string basePath = Regex.Replace(form.FileTarget, "[\\.a-zA-Z]+$", ""); // Write components to similar files in same directory string targetdeckFileName = fileName + "_targetdeck.xml"; scenario.Targetdeck.ToFile(targetdeckFileName); string modelFileName = fileName + "_model.xml"; scenario.Model.ToFile(modelFileName); string envFileName = fileName + "_env.xml"; scenario.Environment.ToFile(envFileName); string scenarioFileName = fileName + "_scenario.xml"; scenario.ToFile(scenarioFileName); // Increment version, if file specified, and gather file info if (incrementVersion) { form.Version += 0.1; } string fileInfo = "author=\"" + _picassoSettings.Author + "\" lastSaved=\"" + DateTime.Now.ToUniversalTime() + "\" version=\"" + form.Version + "\""; // Write hsx to file string contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE hsx>"; contents += "<hsx path=\"" + basePath + "\" " + fileInfo + ">"; contents += "<scenario filename=\"" + scenarioFileName + "\"></scenario>"; contents += "<targetdeck filename=\"" + targetdeckFileName + "\"></targetdeck>"; contents += "<model filename=\"" + modelFileName + "\"></model>"; contents += "<environment filename=\"" + envFileName + "\"></environment>"; contents += "</hsx>"; FileStream fs = new FileStream(form.FileTarget, FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs); sw.Write(contents); sw.Close(); fs.Close(); // Mark scenario as saved, reset form title and disable save form.IsSaved = true; Text = _textPrefix + ": " + scenario.ScenarioName; saveMenuItem.Enabled = false; }