# HG changeset patch # User cavaliet # Date 1258038919 -3600 # Node ID 11083c390ce42cfe9d142b6785bd9a0abfcf4158 # Parent 8a25a85f2656f11abed86b5b19533c45da7f8bb9 Second step of data saving : id added for cutting and annotation, and now we can load/display/change the already existing projects. diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.Screen/UserControlScreen.xaml.cs --- a/src/FingersDance.Control.Screen/UserControlScreen.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.Screen/UserControlScreen.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -8,6 +8,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; +using System.Xml.Linq; using FingersDance.Control.ListVideo; using FingersDance.Control.SessionInput; using FingersDance.ViewModels; @@ -22,7 +23,10 @@ public event EventHandler UC_Screen_NewCutting; private MainViewModel _mainViewModel; public Cutting Cutting; - private List existingProjects = new List(); + + private String videoName; + private String videoPath; + User User = new User(); public UserControlScreen(int id, MainViewModel mvmodel) @@ -69,7 +73,9 @@ try { //1 renseigner la video choisie au screen et créer un nouveau projet à partir de ce chemin vidéo - _mainViewModel.CreateProject(((UserControlListVideo)sender).VideoName, ((UserControlListVideo)sender).path); + videoName = ((UserControlListVideo)sender).VideoName; + videoPath = ((UserControlListVideo)sender).path; + _mainViewModel.CreateProject(videoName, videoPath); //2-Supression du UC List Video LayoutRoot.Children.Remove((UserControlListVideo)sender); OpenProjectList(); @@ -86,7 +92,14 @@ { try { - existingProjects = LoadProjects(_mainViewModel.Project.VideoPath); + // We get all the ldt/project files from the current directory... + List existingProjects = new List(); + foreach (String filename in Directory.GetFiles("./")) + { + if (filename.Substring(filename.Length-4).ToLower()==".ldt") + existingProjects.Add(filename.Substring(2, filename.Length - 6)); + } + // ... and display them the the select box UserControlListProject UserControlListProject listProject = new UserControlListProject(existingProjects); listProject.Name = "ListProject"; LayoutRoot.Children.Add(listProject); @@ -100,25 +113,6 @@ } } - private List LoadProjects(string name) - { - // Does nothing because for the moment we do not load sessions when we know the video path, we just create a new session - try - { - List lp = new List(); - foreach (String filename in Directory.GetFiles("./")) - { - if (filename.Substring(filename.Length-4).ToLower()==".ldt") - lp.Add(new Project(filename.Substring(2,filename.Length - 6), "", "")); - } - return lp; - } - catch (Exception) - { - return new List(); - } - } - void listProject_EH_ListProject_ContactDown(object sender, EventArgs e) { try @@ -133,15 +127,35 @@ } else { - foreach (Project elt in existingProjects) + // ((UserControlListProject)sender).SelectedItem is the name of the selected project + // Now we load the xml/ldt file to load all its datas (cuttings, annotations...) + XDocument loadedLdt = XDocument.Load(((UserControlListProject)sender).SelectedItem + ".ldt"); + Project loadedProject = new Project(videoName, videoPath); + loadedProject.Name = loadedLdt.Root.Element("project").Attribute("title").Value; + loadedProject.Description = loadedLdt.Root.Element("project").Attribute("abstract").Value; + loadedProject.Cuttings = new List(); + XElement cuttingsParentNode = loadedLdt.Root.Element("annotations").Element("content"); + foreach (XElement cuttingNode in cuttingsParentNode.Elements()) { - if (elt.Name.Equals(((UserControlListProject)sender).SelectedItem)) + List la = new List(); + foreach (XElement annotNode in cuttingNode.Element("elements").Elements()) { - _mainViewModel.Project.Project = elt; - OpenProject(); - return; + String aId = annotNode.Attribute("id").Value; + float begin = (float)annotNode.Attribute("begin"); + float dur = (float)annotNode.Attribute("dur"); + String gt = annotNode.Element("gestureType").Value; + String colorString = annotNode.Attribute("color").Value; // is type 0xRRGGBB + Byte r = Convert.ToByte(colorString.Substring(2, 2), 16); + Byte g = Convert.ToByte(colorString.Substring(4, 2), 16); + Byte b = Convert.ToByte(colorString.Substring(6, 2), 16); + Color c = Color.FromRgb(r, g, b); + la.Add(new Annotation(aId, begin, dur, gt, c)); } + loadedProject.Cuttings.Add(new Cutting(cuttingNode.Attribute("id").Value,cuttingNode.Element("title").Value,la)); } + // We define the loaded project as the current session's project. + _mainViewModel.Project = new ProjectViewModel(loadedProject); + OpenProject(); } } catch (Exception) @@ -159,7 +173,7 @@ //MainViewModel.Project.Alias = ((UserControlNewProjectForm)sender).Alias; //MainViewModel.Project.Email = ((UserControlNewProjectForm)sender).Email; _mainViewModel.Project.Description = ((UserControlNewProjectForm)sender).Description; - _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).SessionName.Trim(); + _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).ProjectName.Trim(); //2-Suppression UCSession Input @@ -178,6 +192,7 @@ { try { + // We display the list of cuttings available for the current project UserControlListCutting listCuttings = new UserControlListCutting(_mainViewModel.Project.CuttingsDict); listCuttings.Name = "listCuttings"; LayoutRoot.Children.Add(listCuttings); @@ -198,6 +213,7 @@ LayoutRoot.Children.Remove((UserControlListCutting)sender); if (((UserControlListCutting)sender).SelectedItem.Equals("New Cutting")) { + // "New Uutting" was was selected -> we display the form UserControlNewCuttingForm newCutting = new UserControlNewCuttingForm(User); newCutting.Name = "newCutting"; LayoutRoot.Children.Add(newCutting); @@ -205,14 +221,11 @@ } else { - foreach(KeyValuePair elt in _mainViewModel.Project.CuttingsDict) - if (elt.Key.Equals(((UserControlListCutting)sender).SelectedItem)) - { - Cutting = elt.Value; - if (UC_Screen_NewCutting != null) - UC_Screen_NewCutting(this, new EventArgs()); - return; - } + // An already existing project was clicked -> we load the selected project from the dictionnary + Cutting = _mainViewModel.Project.CuttingsDict[((UserControlListCutting)sender).SelectedItem]; + if (UC_Screen_NewCutting != null) + UC_Screen_NewCutting(this, new EventArgs()); + return; } } catch (Exception) @@ -228,6 +241,7 @@ try { LayoutRoot.Children.Remove((UserControlNewCuttingForm)sender); + // The new cutting form sent the cutting instance so we can dispatch the event UC_Screen_NewCutting Cutting = ((UserControlNewCuttingForm)sender).Cutting; if (UC_Screen_NewCutting != null) UC_Screen_NewCutting(this, new EventArgs()); diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.SessionInput/UserControlListProject.xaml.cs --- a/src/FingersDance.Control.SessionInput/UserControlListProject.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.SessionInput/UserControlListProject.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -25,13 +25,13 @@ public event EventHandler EH_ListProject_ContactDown; public string SelectedItem = ""; - public UserControlListProject(List projects) + public UserControlListProject(List projectNames) { InitializeComponent(); - OpenProjects(projects); + OpenProjects(projectNames); } - private void OpenProjects(List projects) + private void OpenProjects(List projectNames) { CustomListBoxItem Contener = new CustomListBoxItem(); Contener.Name = "New Project"; @@ -39,11 +39,11 @@ Contener.Content = l; stackPanel.Children.Add(Contener); Contener.ContactTapGesture += Item_ContactTapGesture; - foreach (Project elt in projects) + foreach (String projectName in projectNames) { Contener = new CustomListBoxItem(); - Contener.Name = elt.Name; - l = new UserControlCustomLabel(elt.Name); + Contener.Name = projectName; + l = new UserControlCustomLabel(projectName); Contener.Content = l; stackPanel.Children.Add(Contener); Contener.ContactTapGesture += Item_ContactTapGesture; diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.SessionInput/UserControlNewCuttingForm.xaml.cs --- a/src/FingersDance.Control.SessionInput/UserControlNewCuttingForm.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.SessionInput/UserControlNewCuttingForm.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -37,18 +37,18 @@ private void SurfaceButtonSubmit_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) { - Cutting = new Cutting(ST_CuttingName.Text.Trim(), new List()); + Cutting = new Cutting("c_" + System.Guid.NewGuid(), ST_CuttingName.Text.Trim(), new List()); if (EH_NewCuttingForm_ContactDown != null) EH_NewCuttingForm_ContactDown(this, new EventArgs()); } private void SurfaceButtonSubmit_Click(object sender, RoutedEventArgs e) { - Cutting = new Cutting(ST_CuttingName.Text.Trim(), new List()); + Cutting = new Cutting("c _" + System.Guid.NewGuid(), ST_CuttingName.Text.Trim(), new List()); if (EH_NewCuttingForm_ContactDown != null) EH_NewCuttingForm_ContactDown(this, new EventArgs()); } #endregion } -} +} diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.SessionInput/UserControlNewProjectForm.xaml.cs --- a/src/FingersDance.Control.SessionInput/UserControlNewProjectForm.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.SessionInput/UserControlNewProjectForm.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -17,7 +17,7 @@ public partial class UserControlNewProjectForm : UserControl { public event EventHandler EH_NewProjectForm_ContactDown; - public string SessionName = ""; + public string ProjectName = ""; public string Email = ""; public string Alias = ""; public string Description = ""; @@ -35,7 +35,7 @@ //if (!ST_Alias.Text.Equals("") && !ST_Date.Text.Equals("") && !ST_Email.Text.Equals("") && !ST_Name.Text.Equals("")) if (!ST_Name.Text.Equals("")) { - SessionName = ST_Name.Text; + ProjectName = ST_Name.Text; Email= ST_Email.Text; Alias = ST_Alias.Text; Description = ST_Desc.Text; @@ -49,7 +49,7 @@ //if (!ST_Alias.Text.Equals("") && !ST_Date.Text.Equals("") && !ST_Email.Text.Equals("") && !ST_Name.Text.Equals("")) if (!ST_Name.Text.Equals("")) { - SessionName = ST_Name.Text; + ProjectName = ST_Name.Text; Email = ST_Email.Text; Alias = ST_Alias.Text; Description = ST_Desc.Text; diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs --- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -145,13 +145,13 @@ // DATA BINDING from the cutting sent in parameter (initialised before by the userPanel with the global project) cut = cutPar; - cut.AnnotList = new List(); - cut.AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", CurrentColor)); - //cut.AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); - //cut.AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3")); - //cut.AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4")); - //cut.AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); - //cut.AnnotList = AnnotList; + //cut.AnnotList = new List(); + //cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), 0, 10, "Axe Cam 1", CurrentColor)); + //cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), 100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); + //cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), 200 - (2 * AnnotWidth), 50, "Saut 3")); + //cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), 100 - (3 * AnnotWidth), 20, "Saut 4")); + //cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), 120 - (4 * AnnotWidth), 50, "Saut 5")); + tv.DataContext = new CuttingViewModel(cut, AnnotWidth); } @@ -281,7 +281,7 @@ // If everything's fine, we create the new one if (annotOk == true) { - cut.AnnotList.Add(new Annotation(avm.TcBegin, avm.Dur, avm.GestureType, avm.Color)); + cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), avm.TcBegin, avm.Dur, avm.GestureType, avm.Color)); tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); AnnotWaiting = false; } @@ -313,7 +313,7 @@ // if not, we mark the beginning if (annotOk == true) { - cut.AnnotList.Add(new Annotation(AnnotTcBegin, 0, cut.AnnotList.Count.ToString(), CurrentColor)); + cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), AnnotTcBegin, 0, cut.AnnotList.Count.ToString(), CurrentColor)); tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); AnnotWaiting = true; } @@ -338,7 +338,7 @@ if (annotOk == true) { cut.AnnotList.RemoveAt(cut.AnnotList.Count - 1); - cut.AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, cut.AnnotList.Count.ToString(), CurrentColor)); + cut.AnnotList.Add(new Annotation("s_" + System.Guid.NewGuid(), AnnotTcBegin, currentDuration, cut.AnnotList.Count.ToString(), CurrentColor)); //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + cut.AnnotList.Count + ", res = " + (AnnotTcBegin - (cut.AnnotList.Count * AnnotWidth))); tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); AnnotWaiting = false; diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Data/Annotation.cs --- a/src/FingersDance.Data/Annotation.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Data/Annotation.cs Thu Nov 12 16:15:19 2009 +0100 @@ -8,19 +8,31 @@ { public class Annotation { + private String _id; private float _tcBegin; private float _dur; - private string _gestureType; + private String _gestureType; private Color _color; - public Annotation(float tcBeginPar, float durPar, string gesturePar, Color colorPar) + public Annotation(String idPar, float tcBeginPar, float durPar, String gesturePar, Color colorPar) { + this._id = idPar; this._tcBegin = tcBeginPar; this._dur = durPar; this._gestureType = gesturePar; this._color = colorPar; } + public String Id + { + get { return _id; } + set + { + if (value == _id || String.IsNullOrEmpty(value)) + return; + _id = value; + } + } public float TcBegin { get { return _tcBegin; } diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Data/Cutting.cs --- a/src/FingersDance.Data/Cutting.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Data/Cutting.cs Thu Nov 12 16:15:19 2009 +0100 @@ -7,18 +7,29 @@ { public class Cutting { + private String _id; private List _annotList; private string _title; - public Cutting(string titlePar, List annotListPar) + public Cutting(String idPar, String titlePar, List annotListPar) { + this._id = idPar; this._title = titlePar; this._annotList = annotListPar; - } public Cutting() {} + public String Id + { + get { return _id; } + set + { + if (value == _id || String.IsNullOrEmpty(value)) + return; + _id = value; + } + } public String Title { get { return _title; } diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.ViewModel/AnnotationViewModel.cs --- a/src/FingersDance.ViewModel/AnnotationViewModel.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.ViewModel/AnnotationViewModel.cs Thu Nov 12 16:15:19 2009 +0100 @@ -30,6 +30,17 @@ this._marginLeft = marginLeft; } + public String Id + { + get { return a.Id; } + set + { + if (value == a.Id || String.IsNullOrEmpty(value)) + return; + a.Id = value; + base.OnPropertyChanged("Id"); + } + } public float TcBegin { get { return a.TcBegin; } diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.ViewModel/CuttingViewModel.cs --- a/src/FingersDance.ViewModel/CuttingViewModel.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.ViewModel/CuttingViewModel.cs Thu Nov 12 16:15:19 2009 +0100 @@ -50,6 +50,17 @@ } } + public String Id + { + get { return cut.Id; } + set + { + if (value == cut.Id || String.IsNullOrEmpty(value)) + return; + cut.Id = value; + base.OnPropertyChanged("Id"); + } + } public String Title { get { return cut.Title; } diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.ViewModel/ProjectViewModel.cs --- a/src/FingersDance.ViewModel/ProjectViewModel.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.ViewModel/ProjectViewModel.cs Thu Nov 12 16:15:19 2009 +0100 @@ -19,6 +19,11 @@ public ProjectViewModel(Project p) { project = p; + _cuttingsDict = new Dictionary(); + foreach(Cutting cut in project.Cuttings) + { + _cuttingsDict.Add(cut.Title, cut); + } } #endregion @@ -55,12 +60,6 @@ set { project.VideoPath = value; } } - //public User User - //{ - // get { return project.User; } - // set { project.User = value; } - //} - public List Cuttings { get { return project.Cuttings; } diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance/MainSurfaceWindow.xaml.cs --- a/src/FingersDance/MainSurfaceWindow.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance/MainSurfaceWindow.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -427,9 +427,12 @@ if (Panel4.Cutting.Title == newCutting.Title) return; - // We add the new cutting to the _mainviewmodel's datas - _mainviewmodel.Project.Cuttings.Add(newCutting); - _mainviewmodel.Project.CuttingsDict.Add(newCutting.Title, newCutting); + // We add the new cutting to the _mainviewmodel's datas IF THE CUTTING IS NEW (if not it means that it is from a loaded project) + if (!_mainviewmodel.Project.CuttingsDict.ContainsKey(newCutting.Title)) + { + _mainviewmodel.Project.Cuttings.Add(newCutting); + _mainviewmodel.Project.CuttingsDict.Add(newCutting.Title, newCutting); + } // And now we build the new UserPanel Random c = new Random(); @@ -545,25 +548,7 @@ // private void saveDatas() { - //XDocument d = new XDocument( - // new XComment("This is a comment."), - // new XProcessingInstruction("xml-stylesheet", - // "href='mystyle.css' title='Compact' type='text/css'"), - // new XElement("Pubs", - // new XElement("Book", - // new XElement("Title", "Artifacts of Roman Civilization"), - // new XElement("Author", "Moreno, Jordao") - // ), - // new XElement("Book", - // new XElement("Title", "Midieval Tools and Implements"), - // new XElement("Author", "Gazit, Inbar") - // ) - // ), - // new XComment("This is another comment.") - //); - //d.Declaration = new XDeclaration("1.0", "utf-8", "true"); - //Console.WriteLine(d); - + // We build the xml to be saved, with the ldt format XDocument d = new XDocument( new XElement("iri", new XElement("project", @@ -597,19 +582,19 @@ XElement annotContent = (XElement)(d.Root.Elements().ToList()[2]).FirstNode; foreach (Cutting cut in _mainviewmodel.Project.Cuttings) { - XElement cutNode = new XElement("decoupage", new XAttribute("id", "c_" + System.Guid.NewGuid()), new XAttribute("author", "perso"), + XElement cutNode = new XElement("decoupage", new XAttribute("id", cut.Id), new XAttribute("author", "perso"), new XElement("title",cut.Title), new XElement("abstract","")); XElement cutElmts = new XElement("elements"); cutNode.Add(cutElmts); foreach (Annotation annot in cut.AnnotList) { - cutElmts.Add(new XElement("element", new XAttribute("id", "s_" + System.Guid.NewGuid()), + cutElmts.Add(new XElement("element", new XAttribute("id", annot.Id), new XAttribute("begin", annot.TcBegin), new XAttribute("dur", annot.Dur), new XAttribute("author", cut.Title), new XAttribute("date", DateTime.Now.Day.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString()), - new XAttribute("color", annot.Color), + new XAttribute("color", "0x" + annot.Color.ToString().Substring(3)), // Color.ToString() return #AARRGGBB and we keep only 0xRRGGBB new XAttribute("src", ""), new XElement("title", annot.GestureType), new XElement("abstract"), @@ -621,8 +606,7 @@ } d.Declaration = new XDeclaration("1.0", "utf-8", "true"); - Console.WriteLine(d); - + //Console.WriteLine(d); d.Save(_mainviewmodel.Project.Name + ".ldt"); }