6 using System.Windows.Controls; |
6 using System.Windows.Controls; |
7 using System.Windows.Data; |
7 using System.Windows.Data; |
8 using System.Windows.Media; |
8 using System.Windows.Media; |
9 using System.Windows.Media.Animation; |
9 using System.Windows.Media.Animation; |
10 using System.Windows.Navigation; |
10 using System.Windows.Navigation; |
|
11 using System.Xml.Linq; |
11 using FingersDance.Control.ListVideo; |
12 using FingersDance.Control.ListVideo; |
12 using FingersDance.Control.SessionInput; |
13 using FingersDance.Control.SessionInput; |
13 using FingersDance.ViewModels; |
14 using FingersDance.ViewModels; |
14 using FingersDance.Data; |
15 using FingersDance.Data; |
15 |
16 |
20 public String contexteGrid; |
21 public String contexteGrid; |
21 public int id = 0; |
22 public int id = 0; |
22 public event EventHandler UC_Screen_NewCutting; |
23 public event EventHandler UC_Screen_NewCutting; |
23 private MainViewModel _mainViewModel; |
24 private MainViewModel _mainViewModel; |
24 public Cutting Cutting; |
25 public Cutting Cutting; |
25 private List<Project> existingProjects = new List<Project>(); |
26 |
|
27 private String videoName; |
|
28 private String videoPath; |
|
29 |
26 User User = new User(); |
30 User User = new User(); |
27 |
31 |
28 public UserControlScreen(int id, MainViewModel mvmodel) |
32 public UserControlScreen(int id, MainViewModel mvmodel) |
29 { |
33 { |
30 try |
34 try |
67 private void ListVideo_EH_ItemVideo_ContactDown(object sender, EventArgs e) |
71 private void ListVideo_EH_ItemVideo_ContactDown(object sender, EventArgs e) |
68 { |
72 { |
69 try |
73 try |
70 { |
74 { |
71 //1 renseigner la video choisie au screen et créer un nouveau projet à partir de ce chemin vidéo |
75 //1 renseigner la video choisie au screen et créer un nouveau projet à partir de ce chemin vidéo |
72 _mainViewModel.CreateProject(((UserControlListVideo)sender).VideoName, ((UserControlListVideo)sender).path); |
76 videoName = ((UserControlListVideo)sender).VideoName; |
|
77 videoPath = ((UserControlListVideo)sender).path; |
|
78 _mainViewModel.CreateProject(videoName, videoPath); |
73 //2-Supression du UC List Video |
79 //2-Supression du UC List Video |
74 LayoutRoot.Children.Remove((UserControlListVideo)sender); |
80 LayoutRoot.Children.Remove((UserControlListVideo)sender); |
75 OpenProjectList(); |
81 OpenProjectList(); |
76 } |
82 } |
77 catch (Exception ex) |
83 catch (Exception ex) |
84 |
90 |
85 private void OpenProjectList() |
91 private void OpenProjectList() |
86 { |
92 { |
87 try |
93 try |
88 { |
94 { |
89 existingProjects = LoadProjects(_mainViewModel.Project.VideoPath); |
95 // We get all the ldt/project files from the current directory... |
|
96 List<String> existingProjects = new List<String>(); |
|
97 foreach (String filename in Directory.GetFiles("./")) |
|
98 { |
|
99 if (filename.Substring(filename.Length-4).ToLower()==".ldt") |
|
100 existingProjects.Add(filename.Substring(2, filename.Length - 6)); |
|
101 } |
|
102 // ... and display them the the select box UserControlListProject |
90 UserControlListProject listProject = new UserControlListProject(existingProjects); |
103 UserControlListProject listProject = new UserControlListProject(existingProjects); |
91 listProject.Name = "ListProject"; |
104 listProject.Name = "ListProject"; |
92 LayoutRoot.Children.Add(listProject); |
105 LayoutRoot.Children.Add(listProject); |
93 listProject.EH_ListProject_ContactDown += new EventHandler(listProject_EH_ListProject_ContactDown); |
106 listProject.EH_ListProject_ContactDown += new EventHandler(listProject_EH_ListProject_ContactDown); |
94 } |
107 } |
98 if (UC_Screen_NewCutting != null) |
111 if (UC_Screen_NewCutting != null) |
99 UC_Screen_NewCutting(this, new EventArgs()); |
112 UC_Screen_NewCutting(this, new EventArgs()); |
100 } |
113 } |
101 } |
114 } |
102 |
115 |
103 private List<Project> LoadProjects(string name) |
|
104 { |
|
105 // Does nothing because for the moment we do not load sessions when we know the video path, we just create a new session |
|
106 try |
|
107 { |
|
108 List<Project> lp = new List<Project>(); |
|
109 foreach (String filename in Directory.GetFiles("./")) |
|
110 { |
|
111 if (filename.Substring(filename.Length-4).ToLower()==".ldt") |
|
112 lp.Add(new Project(filename.Substring(2,filename.Length - 6), "", "")); |
|
113 } |
|
114 return lp; |
|
115 } |
|
116 catch (Exception) |
|
117 { |
|
118 return new List<Project>(); |
|
119 } |
|
120 } |
|
121 |
|
122 void listProject_EH_ListProject_ContactDown(object sender, EventArgs e) |
116 void listProject_EH_ListProject_ContactDown(object sender, EventArgs e) |
123 { |
117 { |
124 try |
118 try |
125 { |
119 { |
126 LayoutRoot.Children.Remove((UserControlListProject)sender); |
120 LayoutRoot.Children.Remove((UserControlListProject)sender); |
131 LayoutRoot.Children.Add(ProjectInput); |
125 LayoutRoot.Children.Add(ProjectInput); |
132 ProjectInput.EH_NewProjectForm_ContactDown += new System.EventHandler(this.ProjectInput_EH_NewProjectForm_ContactDown); |
126 ProjectInput.EH_NewProjectForm_ContactDown += new System.EventHandler(this.ProjectInput_EH_NewProjectForm_ContactDown); |
133 } |
127 } |
134 else |
128 else |
135 { |
129 { |
136 foreach (Project elt in existingProjects) |
130 // ((UserControlListProject)sender).SelectedItem is the name of the selected project |
|
131 // Now we load the xml/ldt file to load all its datas (cuttings, annotations...) |
|
132 XDocument loadedLdt = XDocument.Load(((UserControlListProject)sender).SelectedItem + ".ldt"); |
|
133 Project loadedProject = new Project(videoName, videoPath); |
|
134 loadedProject.Name = loadedLdt.Root.Element("project").Attribute("title").Value; |
|
135 loadedProject.Description = loadedLdt.Root.Element("project").Attribute("abstract").Value; |
|
136 loadedProject.Cuttings = new List<Cutting>(); |
|
137 XElement cuttingsParentNode = loadedLdt.Root.Element("annotations").Element("content"); |
|
138 foreach (XElement cuttingNode in cuttingsParentNode.Elements()) |
137 { |
139 { |
138 if (elt.Name.Equals(((UserControlListProject)sender).SelectedItem)) |
140 List<Annotation> la = new List<Annotation>(); |
|
141 foreach (XElement annotNode in cuttingNode.Element("elements").Elements()) |
139 { |
142 { |
140 _mainViewModel.Project.Project = elt; |
143 String aId = annotNode.Attribute("id").Value; |
141 OpenProject(); |
144 float begin = (float)annotNode.Attribute("begin"); |
142 return; |
145 float dur = (float)annotNode.Attribute("dur"); |
|
146 String gt = annotNode.Element("gestureType").Value; |
|
147 String colorString = annotNode.Attribute("color").Value; // is type 0xRRGGBB |
|
148 Byte r = Convert.ToByte(colorString.Substring(2, 2), 16); |
|
149 Byte g = Convert.ToByte(colorString.Substring(4, 2), 16); |
|
150 Byte b = Convert.ToByte(colorString.Substring(6, 2), 16); |
|
151 Color c = Color.FromRgb(r, g, b); |
|
152 la.Add(new Annotation(aId, begin, dur, gt, c)); |
143 } |
153 } |
|
154 loadedProject.Cuttings.Add(new Cutting(cuttingNode.Attribute("id").Value,cuttingNode.Element("title").Value,la)); |
144 } |
155 } |
|
156 // We define the loaded project as the current session's project. |
|
157 _mainViewModel.Project = new ProjectViewModel(loadedProject); |
|
158 OpenProject(); |
145 } |
159 } |
146 } |
160 } |
147 catch (Exception) |
161 catch (Exception) |
148 { |
162 { |
149 Cutting = null; |
163 Cutting = null; |
157 try |
171 try |
158 { |
172 { |
159 //MainViewModel.Project.Alias = ((UserControlNewProjectForm)sender).Alias; |
173 //MainViewModel.Project.Alias = ((UserControlNewProjectForm)sender).Alias; |
160 //MainViewModel.Project.Email = ((UserControlNewProjectForm)sender).Email; |
174 //MainViewModel.Project.Email = ((UserControlNewProjectForm)sender).Email; |
161 _mainViewModel.Project.Description = ((UserControlNewProjectForm)sender).Description; |
175 _mainViewModel.Project.Description = ((UserControlNewProjectForm)sender).Description; |
162 _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).SessionName.Trim(); |
176 _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).ProjectName.Trim(); |
163 |
177 |
164 |
178 |
165 //2-Suppression UCSession Input |
179 //2-Suppression UCSession Input |
166 LayoutRoot.Children.Remove((UserControlNewProjectForm)sender); |
180 LayoutRoot.Children.Remove((UserControlNewProjectForm)sender); |
167 OpenProject(); |
181 OpenProject(); |
176 |
190 |
177 private void OpenProject() |
191 private void OpenProject() |
178 { |
192 { |
179 try |
193 try |
180 { |
194 { |
|
195 // We display the list of cuttings available for the current project |
181 UserControlListCutting listCuttings = new UserControlListCutting(_mainViewModel.Project.CuttingsDict); |
196 UserControlListCutting listCuttings = new UserControlListCutting(_mainViewModel.Project.CuttingsDict); |
182 listCuttings.Name = "listCuttings"; |
197 listCuttings.Name = "listCuttings"; |
183 LayoutRoot.Children.Add(listCuttings); |
198 LayoutRoot.Children.Add(listCuttings); |
184 listCuttings.EH_Item_ContactDown += new EventHandler(listCuttings_EH_Item_ContactDown); |
199 listCuttings.EH_Item_ContactDown += new EventHandler(listCuttings_EH_Item_ContactDown); |
185 } |
200 } |
196 try |
211 try |
197 { |
212 { |
198 LayoutRoot.Children.Remove((UserControlListCutting)sender); |
213 LayoutRoot.Children.Remove((UserControlListCutting)sender); |
199 if (((UserControlListCutting)sender).SelectedItem.Equals("New Cutting")) |
214 if (((UserControlListCutting)sender).SelectedItem.Equals("New Cutting")) |
200 { |
215 { |
|
216 // "New Uutting" was was selected -> we display the form |
201 UserControlNewCuttingForm newCutting = new UserControlNewCuttingForm(User); |
217 UserControlNewCuttingForm newCutting = new UserControlNewCuttingForm(User); |
202 newCutting.Name = "newCutting"; |
218 newCutting.Name = "newCutting"; |
203 LayoutRoot.Children.Add(newCutting); |
219 LayoutRoot.Children.Add(newCutting); |
204 newCutting.EH_NewCuttingForm_ContactDown += new EventHandler(newCutting_EH_ContactDown); |
220 newCutting.EH_NewCuttingForm_ContactDown += new EventHandler(newCutting_EH_ContactDown); |
205 } |
221 } |
206 else |
222 else |
207 { |
223 { |
208 foreach(KeyValuePair<string, Cutting> elt in _mainViewModel.Project.CuttingsDict) |
224 // An already existing project was clicked -> we load the selected project from the dictionnary |
209 if (elt.Key.Equals(((UserControlListCutting)sender).SelectedItem)) |
225 Cutting = _mainViewModel.Project.CuttingsDict[((UserControlListCutting)sender).SelectedItem]; |
210 { |
226 if (UC_Screen_NewCutting != null) |
211 Cutting = elt.Value; |
227 UC_Screen_NewCutting(this, new EventArgs()); |
212 if (UC_Screen_NewCutting != null) |
228 return; |
213 UC_Screen_NewCutting(this, new EventArgs()); |
|
214 return; |
|
215 } |
|
216 } |
229 } |
217 } |
230 } |
218 catch (Exception) |
231 catch (Exception) |
219 { |
232 { |
220 Cutting = null; |
233 Cutting = null; |
226 void newCutting_EH_ContactDown(object sender, EventArgs e) |
239 void newCutting_EH_ContactDown(object sender, EventArgs e) |
227 { |
240 { |
228 try |
241 try |
229 { |
242 { |
230 LayoutRoot.Children.Remove((UserControlNewCuttingForm)sender); |
243 LayoutRoot.Children.Remove((UserControlNewCuttingForm)sender); |
|
244 // The new cutting form sent the cutting instance so we can dispatch the event UC_Screen_NewCutting |
231 Cutting = ((UserControlNewCuttingForm)sender).Cutting; |
245 Cutting = ((UserControlNewCuttingForm)sender).Cutting; |
232 if (UC_Screen_NewCutting != null) |
246 if (UC_Screen_NewCutting != null) |
233 UC_Screen_NewCutting(this, new EventArgs()); |
247 UC_Screen_NewCutting(this, new EventArgs()); |
234 } |
248 } |
235 catch (Exception) |
249 catch (Exception) |