public void addRally(Rally rally) { string xpathExpr = "descendant::Spiel"; XmlNode rootNode, newRally, rallyTree; // Get rallies tree for given set number rootNode = xmlDoc.DocumentElement; rallyTree = rootNode.SelectSingleNode(xpathExpr); // Construct new rally node newRally = newRallyNode(rally); //xmlDoc.InsertAfter(newRally, lastRally); rallyTree.AppendChild(newRally); // Write rally to xml output file xmlDoc.Save(xmlDocLocation); }
// this method updates a live rally which got changed in review mode public void updateReviewRally(Rally toChangeRally) { XmlNode rootNode, locCurrentNode; string liveRallyStartTime = toChangeRally.Start_time.ToString(); rootNode = xmlDoc.DocumentElement; string xpathExpr = "descendant::Spiel/Spielzug[@ID=" + liveRallyStartTime + "]"; locCurrentNode = rootNode.SelectSingleNode(xpathExpr); if (locCurrentNode != null) { locCurrentNode.ParentNode.RemoveChild(locCurrentNode); addRally(toChangeRally); } }
private XmlNode newRallyNode(Rally rally) { XmlNode newRally; XmlNode punktchance_aus_Defence; newRally = xmlDoc.CreateElement("Spielzug"); // ID Attribute XmlAttribute spielzug_attribute = xmlDoc.CreateAttribute("ID"); spielzug_attribute.InnerText = rally.Start_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Anfang Attribute spielzug_attribute = xmlDoc.CreateAttribute("Anfang"); spielzug_attribute.InnerText = rally.Absolute_start_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Ende Attribute spielzug_attribute = xmlDoc.CreateAttribute("Ende"); spielzug_attribute.InnerText = rally.Absolute_end_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Erfolg Attribute spielzug_attribute = xmlDoc.CreateAttribute("Erfolg"); spielzug_attribute.InnerText = rally.Kill.ToString(); newRally.Attributes.Append(spielzug_attribute); // Smash Attribute spielzug_attribute = xmlDoc.CreateAttribute("Smash"); spielzug_attribute.InnerText = rally.Smash.ToString(); newRally.Attributes.Append(spielzug_attribute); // Drop Attribute spielzug_attribute = xmlDoc.CreateAttribute("Drop"); spielzug_attribute.InnerText = rally.Drop.ToString(); newRally.Attributes.Append(spielzug_attribute); // Spieler_An Attribute spielzug_attribute = xmlDoc.CreateAttribute("Spieler_An"); spielzug_attribute.InnerText = rally.Reception_pos.Player.Name; newRally.Attributes.Append(spielzug_attribute); // Satz Attribute spielzug_attribute = xmlDoc.CreateAttribute("Satz"); spielzug_attribute.InnerText = rally.CorrespondingSetNr.ToString(); newRally.Attributes.Append(spielzug_attribute); // Bigpoint Attribute spielzug_attribute = xmlDoc.CreateAttribute("Bigpoint"); spielzug_attribute.InnerText = rally.BigPoint.ToString(); newRally.Attributes.Append(spielzug_attribute); // Spielstand Attribute spielzug_attribute = xmlDoc.CreateAttribute("Spielstand"); spielzug_attribute.InnerText = configuration.Teama_score + ":" + configuration.Teamb_score; newRally.Attributes.Append(spielzug_attribute); // Timeout Attribute spielzug_attribute = xmlDoc.CreateAttribute("Timeout"); spielzug_attribute.InnerText = rally.Timeout.ToString(); newRally.Attributes.Append(spielzug_attribute); // Standardseite Attribute spielzug_attribute = xmlDoc.CreateAttribute("Standardseite"); spielzug_attribute.InnerText = rally.Standardposition.ToString(); newRally.Attributes.Append(spielzug_attribute); newRally.AppendChild(newPositionNode(rally.Service_pos, "Aufschlag")); newRally.AppendChild(newPositionNode(rally.Reception_pos, "Annahme")); newRally.AppendChild(newPositionNode(rally.Set_pos, "Zuspiel")); newRally.AppendChild(newPositionNode(rally.Takeoff_pos, "Anlauf")); newRally.AppendChild(newPositionNode(rally.Approach_pos, "Angriff")); newRally.AppendChild(newPositionNode(rally.Defence_pos, "Abwehr")); punktchance_aus_Defence = xmlDoc.CreateElement("Punktchance_aus_Defence"); List <Person> defenceplayers = rally.Reception_pos.Defenceplayers; for (int i = 0; i < defenceplayers.Count; i++) { XmlNode player = xmlDoc.CreateElement("Player"); XmlAttribute player_attribute = xmlDoc.CreateAttribute("Name"); player_attribute.InnerText = defenceplayers[i].Name; player.Attributes.Append(player_attribute); punktchance_aus_Defence.AppendChild(player); } newRally.AppendChild(punktchance_aus_Defence); return(newRally); }
private int[][] getActuallPositions(Rally rally) { int[][] positions = new int[6][]; positions[0] = new int[2]; positions[0][0] = rally.Service_pos.WorldX; positions[0][1] = rally.Service_pos.WorldY; positions[1] = new int[2]; positions[1][0] = rally.Reception_pos.WorldX; positions[1][1] = rally.Reception_pos.WorldY; positions[2] = new int[2]; positions[2][0] = rally.Set_pos.WorldX; positions[2][1] = rally.Set_pos.WorldY; positions[3] = new int[2]; positions[3][0] = rally.Approach_pos.WorldX; positions[3][1] = rally.Approach_pos.WorldY; positions[4] = new int[2]; positions[4][0] = rally.Takeoff_pos.WorldX; positions[4][1] = rally.Takeoff_pos.WorldY; positions[5] = new int[2]; positions[5][0] = rally.Defence_pos.WorldX; positions[5][1] = rally.Defence_pos.WorldY; return positions; }
/* * This function loads the Rally that is to be reviewed. * That is, it sets its frame position to 00:00, Enables the control buttons in the reviewer, etc */ private void loadReviewingRally(Rally rally) { Game.Reviewing_rally = rally; if (Game.Reviewing_rally != null) { pictureBox_birdview.Refresh(); updatePositionList(); // Enable control buttons panel_reviewervideocontrols.Enabled = true; panel_reviewerpositions.Enabled = true; if (Game.Reviewing_rally.Finalized) button_reviewerfinalized.Text = "Unfinalize"; else button_reviewerfinalized.Text = "Finalize"; // Reception Player Radiobuttons if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teama.Player1) radioButton_reviewerplayer1.Checked = true; if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teama.Player2) radioButton_reviewerplayer2.Checked = true; if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teamb.Player1) radioButton_reviewerplayer3.Checked = true; if (Game.Reviewing_rally.Reception_pos.Player == configuration.Teamb.Player2) radioButton_reviewerplayer4.Checked = true; radioButton_reviewerplayer1.Text = configuration.Teama.Player1.Name; radioButton_reviewerplayer2.Text = configuration.Teama.Player2.Name; radioButton_reviewerplayer3.Text = configuration.Teamb.Player1.Name; radioButton_reviewerplayer4.Text = configuration.Teamb.Player2.Name; // Defence player checkboxes: List<Person> defenceplayers = Game.Reviewing_rally.Reception_pos.Defenceplayers; checkBox_defenceplayer1.Checked = defenceplayers.Contains(configuration.Teama.Player1); checkBox_defenceplayer2.Checked = defenceplayers.Contains(configuration.Teama.Player2); checkBox_defenceplayer3.Checked = defenceplayers.Contains(configuration.Teamb.Player1); checkBox_defenceplayer4.Checked = defenceplayers.Contains(configuration.Teamb.Player2); // here we load the video for the first time in the reviewer at frame=0 String video_name = Game.Reviewing_rally.Start_time.ToString(); try { capture_review = null; // delete the old one String videopath = Program.getConfiguration().Mediafolderpath + @"\" + video_name + ".mpg"; this.capture_review = new Capture(videopath); double fps = capture_review.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS); if (fps > 0) { review_timer_interval = (int)Math.Ceiling((1000 / fps)) - 3; //timer_review_capture.Interval = interval; } else { fps = 25; timer_review_capture.Interval = 40; } } catch (NullReferenceException) { Console.WriteLine("unreadable video file"); } // Count the frames in the video double frame_number = 0; if (capture_review != null) { //this.capture_review.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES, 0); while (capture_review.QueryFrame() != null) frame_number++; String videopath = Program.getConfiguration().Mediafolderpath + @"\" + video_name + ".mpg"; this.capture_review.Dispose(); this.capture_review = new Capture(videopath); /* if (capture_device_index != -1) { for (int i = 0; i < 10; i++) capture_review.QueryFrame(); this.capture_review.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_POS_FRAMES, 0); } */ } trackBar_reviewervideo.Maximum = (int)frame_number; trackBar_reviewervideo.Value = 0; // If all the loading is done we display the right tab tabControl_main.SelectedIndex = 1; // switch to review-tab // After we loaded all the stuff we can finally play the video: button_reviewerplaypause.Text = "Pause"; timer_review_capture.Start(); if (calibration != null) { if (game.Reviewing_rally.Service_pos.ImageX != 0 && game.Reviewing_rally.Service_pos.ImageY != 0) { editing_position = 0; savePosition(game.Reviewing_rally.Service_pos.ImageX, game.Reviewing_rally.Service_pos.ImageY); } if (game.Reviewing_rally.Defence_pos.ImageX != 0 && game.Reviewing_rally.Defence_pos.ImageY != 0) { editing_position = 5; savePosition(game.Reviewing_rally.Defence_pos.ImageX, game.Reviewing_rally.Defence_pos.ImageY); } } //selectnextEmptyPosition(); // Select first index listView_reviewertrackedpoints.Items[0].Selected = true; listView_reviewertrackedpoints.Focus(); } }
private XmlNode newRallyNode(Rally rally) { XmlNode newRally; XmlNode punktchance_aus_Defence; newRally = xmlDoc.CreateElement("Spielzug"); // ID Attribute XmlAttribute spielzug_attribute = xmlDoc.CreateAttribute("ID"); spielzug_attribute.InnerText = rally.Start_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Anfang Attribute spielzug_attribute = xmlDoc.CreateAttribute("Anfang"); spielzug_attribute.InnerText = rally.Absolute_start_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Ende Attribute spielzug_attribute = xmlDoc.CreateAttribute("Ende"); spielzug_attribute.InnerText = rally.Absolute_end_time.ToString(); newRally.Attributes.Append(spielzug_attribute); // Erfolg Attribute spielzug_attribute = xmlDoc.CreateAttribute("Erfolg"); spielzug_attribute.InnerText = rally.Kill.ToString(); newRally.Attributes.Append(spielzug_attribute); // Smash Attribute spielzug_attribute = xmlDoc.CreateAttribute("Smash"); spielzug_attribute.InnerText = rally.Smash.ToString(); newRally.Attributes.Append(spielzug_attribute); // Drop Attribute spielzug_attribute = xmlDoc.CreateAttribute("Drop"); spielzug_attribute.InnerText = rally.Drop.ToString(); newRally.Attributes.Append(spielzug_attribute); // Spieler_An Attribute spielzug_attribute = xmlDoc.CreateAttribute("Spieler_An"); spielzug_attribute.InnerText = rally.Reception_pos.Player.Name; newRally.Attributes.Append(spielzug_attribute); // Satz Attribute spielzug_attribute = xmlDoc.CreateAttribute("Satz"); spielzug_attribute.InnerText = rally.CorrespondingSetNr.ToString(); newRally.Attributes.Append(spielzug_attribute); // Bigpoint Attribute spielzug_attribute = xmlDoc.CreateAttribute("Bigpoint"); spielzug_attribute.InnerText = rally.BigPoint.ToString(); newRally.Attributes.Append(spielzug_attribute); // Spielstand Attribute spielzug_attribute = xmlDoc.CreateAttribute("Spielstand"); spielzug_attribute.InnerText = configuration.Teama_score + ":" + configuration.Teamb_score; newRally.Attributes.Append(spielzug_attribute); // Timeout Attribute spielzug_attribute = xmlDoc.CreateAttribute("Timeout"); spielzug_attribute.InnerText = rally.Timeout.ToString(); newRally.Attributes.Append(spielzug_attribute); // Standardseite Attribute spielzug_attribute = xmlDoc.CreateAttribute("Standardseite"); spielzug_attribute.InnerText = rally.Standardposition.ToString(); newRally.Attributes.Append(spielzug_attribute); newRally.AppendChild(newPositionNode(rally.Service_pos, "Aufschlag")); newRally.AppendChild(newPositionNode(rally.Reception_pos, "Annahme")); newRally.AppendChild(newPositionNode(rally.Set_pos, "Zuspiel")); newRally.AppendChild(newPositionNode(rally.Takeoff_pos, "Anlauf")); newRally.AppendChild(newPositionNode(rally.Approach_pos, "Angriff")); newRally.AppendChild(newPositionNode(rally.Defence_pos, "Abwehr")); punktchance_aus_Defence = xmlDoc.CreateElement("Punktchance_aus_Defence"); List<Person> defenceplayers = rally.Reception_pos.Defenceplayers; for (int i = 0; i < defenceplayers.Count; i++) { XmlNode player = xmlDoc.CreateElement("Player"); XmlAttribute player_attribute = xmlDoc.CreateAttribute("Name"); player_attribute.InnerText = defenceplayers[i].Name; player.Attributes.Append(player_attribute); punktchance_aus_Defence.AppendChild(player); } newRally.AppendChild(punktchance_aus_Defence); return newRally; }
public void loadRallies(Form_Main mainForm) { XmlNode rootNode; rootNode = xmlDoc.DocumentElement; List<long> list_timestamps = new List<long>(); ImageList imageList_screenshots = new ImageList(); imageList_screenshots.ImageSize = new Size(84, 68); mainForm.listView_screenshots.Items.Clear(); List<Set> sets = new List<Set>(); sets.Add(new Set(1)); sets.Add(new Set(2)); sets.Add(new Set(3)); XmlNodeList rallies = xmlDoc.GetElementsByTagName("Spielzug"); for (int i = 0; i < rallies.Count; i++) { int setnr = Convert.ToInt32(rallies[i].SelectSingleNode("@Satz").InnerText); long starttime = Convert.ToInt64(rallies[i].SelectSingleNode("@ID").InnerText); list_timestamps.Add(starttime); Rally rally = new Rally(starttime,setnr); rally.Kill = (rallies[i].SelectSingleNode("@Erfolg").InnerText == "True"); rally.Smash = (rallies[i].SelectSingleNode("@Smash").InnerText == "True"); rally.Drop = (rallies[i].SelectSingleNode("@Drop").InnerText == "True"); rally.BigPoint = (rallies[i].SelectSingleNode("@Bigpoint").InnerText == "True"); rally.Timeout = (rallies[i].SelectSingleNode("@Timeout").InnerText == "True"); rally.Standardposition = (rallies[i].SelectSingleNode("@Standardseite").InnerText == "True"); // Get All Positions XmlNode xmlposition = rallies[i].SelectSingleNode("Aufschlag"); rally.Service_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Annahme"); rally.Reception_pos = getPosition(xmlposition); rally.Reception_pos.Player = new Person(); String playername = rallies[i].SelectSingleNode("ReceptionPlayer/Player/@Name").InnerText; rally.Reception_pos.Player = readPlayer(playername); XmlNodeList defenceplayers = rallies[i].SelectNodes("Punktchance_aus_Defence/Player"); List<Person> defenceplayerslist = new List<Person>(); for (int c = 0; c < defenceplayers.Count; c++) { string name = defenceplayers[c].SelectSingleNode("@Name").InnerText; defenceplayerslist.Add(readPlayer(name)); } rally.Reception_pos.Defenceplayers = defenceplayerslist; xmlposition = rallies[i].SelectSingleNode("Zuspiel"); rally.Set_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Anlauf"); rally.Takeoff_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Angriff"); rally.Approach_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Abwehr"); rally.Defence_pos = getPosition(xmlposition); // Set Screenshot CaptureStream capture_stream = new CaptureStream(); Bitmap screenshot = capture_stream.createScreenshot(starttime, false); if (screenshot != null) { imageList_screenshots.Images.Add(screenshot); mainForm.setImageListScreenshots(imageList_screenshots); int screenshot_index = i; ListViewItem screenshot_item = new ListViewItem("", screenshot_index); mainForm.listView_screenshots.Items.Add(screenshot_item); mainForm.listView_screenshots.LargeImageList = mainForm.getImageListScreenshots(); mainForm.listView_screenshots.Refresh(); } sets[setnr - 1].Rallies.Add(rally); } mainForm.Game.Sets = sets; mainForm.List_timestamps = list_timestamps; }
public void loadRallies(Form_Main mainForm) { XmlNode rootNode; rootNode = xmlDoc.DocumentElement; List <long> list_timestamps = new List <long>(); ImageList imageList_screenshots = new ImageList(); imageList_screenshots.ImageSize = new Size(84, 68); mainForm.listView_screenshots.Items.Clear(); List <Set> sets = new List <Set>(); sets.Add(new Set(1)); sets.Add(new Set(2)); sets.Add(new Set(3)); XmlNodeList rallies = xmlDoc.GetElementsByTagName("Spielzug"); for (int i = 0; i < rallies.Count; i++) { int setnr = Convert.ToInt32(rallies[i].SelectSingleNode("@Satz").InnerText); long starttime = Convert.ToInt64(rallies[i].SelectSingleNode("@ID").InnerText); list_timestamps.Add(starttime); Rally rally = new Rally(starttime, setnr); rally.Kill = (rallies[i].SelectSingleNode("@Erfolg").InnerText == "True"); rally.Smash = (rallies[i].SelectSingleNode("@Smash").InnerText == "True"); rally.Drop = (rallies[i].SelectSingleNode("@Drop").InnerText == "True"); rally.BigPoint = (rallies[i].SelectSingleNode("@Bigpoint").InnerText == "True"); rally.Timeout = (rallies[i].SelectSingleNode("@Timeout").InnerText == "True"); rally.Standardposition = (rallies[i].SelectSingleNode("@Standardseite").InnerText == "True"); // Get All Positions XmlNode xmlposition = rallies[i].SelectSingleNode("Aufschlag"); rally.Service_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Annahme"); rally.Reception_pos = getPosition(xmlposition); rally.Reception_pos.Player = new Person(); String playername = rallies[i].SelectSingleNode("ReceptionPlayer/Player/@Name").InnerText; rally.Reception_pos.Player = readPlayer(playername); XmlNodeList defenceplayers = rallies[i].SelectNodes("Punktchance_aus_Defence/Player"); List <Person> defenceplayerslist = new List <Person>(); for (int c = 0; c < defenceplayers.Count; c++) { string name = defenceplayers[c].SelectSingleNode("@Name").InnerText; defenceplayerslist.Add(readPlayer(name)); } rally.Reception_pos.Defenceplayers = defenceplayerslist; xmlposition = rallies[i].SelectSingleNode("Zuspiel"); rally.Set_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Anlauf"); rally.Takeoff_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Angriff"); rally.Approach_pos = getPosition(xmlposition); xmlposition = rallies[i].SelectSingleNode("Abwehr"); rally.Defence_pos = getPosition(xmlposition); // Set Screenshot CaptureStream capture_stream = new CaptureStream(); Bitmap screenshot = capture_stream.createScreenshot(starttime, false); if (screenshot != null) { imageList_screenshots.Images.Add(screenshot); mainForm.setImageListScreenshots(imageList_screenshots); int screenshot_index = i; ListViewItem screenshot_item = new ListViewItem("", screenshot_index); mainForm.listView_screenshots.Items.Add(screenshot_item); mainForm.listView_screenshots.LargeImageList = mainForm.getImageListScreenshots(); mainForm.listView_screenshots.Refresh(); } sets[setnr - 1].Rallies.Add(rally); } mainForm.Game.Sets = sets; mainForm.List_timestamps = list_timestamps; }