private void SaveNotation_Click(object sender, RoutedEventArgs e) { ReportStatusBar.clearReportMessage(); if (String.IsNullOrEmpty(NotationNameTextBox.Text)) { ReportStatusBar.ShowStatus("Notation name is not provided!", ReportIcon.Error); logger.log("Generating \'" + NotationNameTextBox.Text + "\' failed -> " + "Notation name is not provided!", ReportIcon.Error); NotationNameTextBox.Focus(); } else { string xamlText = new TextRange(GraphicsInput.Document.ContentStart, GraphicsInput.Document.ContentEnd).Text; if (String.IsNullOrEmpty(xamlText)) { ReportStatusBar.ShowStatus("Notation XAML is missing!", ReportIcon.Error); logger.log("Generating \'" + NotationNameTextBox.Text + "\' failed -> " + "Notation XAML is missing!", ReportIcon.Error); GraphicsInput.Focus(); } else { string dataText = new TextRange(XMLDataInput.Document.ContentStart, XMLDataInput.Document.ContentEnd).Text; if (String.IsNullOrEmpty(dataText)) { ReportStatusBar.ShowStatus("Data XML is missing!", ReportIcon.Error); logger.log("Generating \'" + NotationNameTextBox.Text + "\' failed -> " + "Data XML is missing!", ReportIcon.Error); XMLDataInput.Focus(); } else { XmlDocument xdoc = new XmlDocument(); XmlNode itemNode = xdoc.CreateElement("item"); XmlAttribute nameAttr = xdoc.CreateAttribute("name"); nameAttr.Value = NotationNameTextBox.Text; itemNode.Attributes.Append(nameAttr); XmlAttribute typeAttr = xdoc.CreateAttribute("type"); if (visType == VisualisationType.XAML) typeAttr.Value = "XAML"; else if (visType == VisualisationType.SVG) typeAttr.Value = "SVG"; itemNode.Attributes.Append(typeAttr); //data XML String dataXML = dataText; xdoc.LoadXml(dataXML); XmlNode dataNode = xdoc.CreateElement("data"); dataNode.AppendChild(xdoc.DocumentElement.Clone()); string dataNodeName = xdoc.DocumentElement.Name; //name of the data XML document element to be the name of (template match="name") itemNode.AppendChild(dataNode); xdoc.RemoveAll(); //create transforamtion Collection<XmlNode> transXSLTemplates = parseAnnotatedGraphics(xamlText, dataNodeName, dataNode.FirstChild); if (transXSLTemplates.Count > 0) { XmlNode transformationNode = xdoc.CreateElement("trans"); foreach (XmlNode x in transXSLTemplates) transformationNode.AppendChild(transformationNode.OwnerDocument.ImportNode(x, true)); itemNode.AppendChild(transformationNode); xdoc.RemoveAll(); //save notation XML //MessageBox.Show(prettyPrinter.PrintToString(itemNode.OuterXml)); //find ToolBoxItems.xml string customElementsFile = getDirectory("Resources\\ToolBoxItems.xml"); customElementsFile = (customElementsFile.Replace("file:\\", "")); XmlDocument customElementsDoc = new XmlDocument(); customElementsDoc.Load(customElementsFile); XmlNode customItemsNode = customElementsDoc.SelectSingleNode("items"); if (customItemsNode != null) { customItemsNode.AppendChild(customItemsNode.OwnerDocument.ImportNode(itemNode, true)); customElementsDoc.Save(customElementsFile); //create visual element if (visType == VisualisationType.XAML) { XAMLRenderer rend = new XAMLRenderer(); VisualElement v = rend.render(itemNode) as VisualElement; if (v != null) { XAMLRenderCanvas.Children.Clear(); XAMLRenderCanvas.Children.Add(v); ReportStatusBar.ShowStatus("XAML Notation Saved", ReportIcon.OK); logger.log("XAML Notation \'" + NotationNameTextBox.Text + "\' saved in notation repository.", ReportIcon.OK); SkinOutputTabControl.SelectedIndex = 0; //Clear callforlist callForList.Clear(); } else { ReportStatusBar.ShowStatus("XAML Notation failed!", ReportIcon.OK); logger.log("XAML Notation \'" + NotationNameTextBox.Text + "\' failed.", ReportIcon.Error); } } else if (visType == VisualisationType.SVG) { ReportStatusBar.ShowStatus("SVG Notation Saved", ReportIcon.OK); logger.log("SVG Notation \'" + NotationNameTextBox.Text + "\' saved in notation repository.", ReportIcon.OK); } } else { ReportStatusBar.ShowStatus("Could not locate custom items", ReportIcon.Error); logger.log("Generating \'" + NotationNameTextBox.Text + "\' failed.", ReportIcon.Error); } } } } } }
private void RenderStillVisualisation_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; openDialog.Title = "Select visualisation file"; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml"; try { XAMLRenderer rend = new XAMLRenderer(); UIElement rendResult = rend.createStillVisualisation(tempFileName); if (rendResult != null) { RenderCanvas.Children.Clear(); RenderCanvas.Children.Add(rendResult); //log event logger.log("Tried rendering still visualisation \"" + tempFileName + "\"."); DesignerTabControl.SelectedIndex = 2; reportMessage("Still visualisation \"" + tempFileName + " rendered", ReportIcon.OK); } } catch (Exception ex) { reportMessage(ex.ToString(), ReportIcon.Error); } } }
private void ExportToXAML_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Select visualisation file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml"; try { XAMLRenderer rend = new XAMLRenderer(); string rendResult = rend.renderToStillXAML(tempFileName); if (!String.IsNullOrEmpty(rendResult)) { //save the xaml file SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Export to XAML file"; saveDialog.Filter = "XAML files (*.xaml)|*.xaml|All files (*.*)|*.*"; saveDialog.FileName = ""; saveDialog.ShowDialog(); if (!saveDialog.FileName.Equals("")) { //resulted visualisation model file string saveXamlFile = saveDialog.FileName; //where the reaulted reverse will be saved if (!saveXamlFile.ToLower().EndsWith(".xaml")) saveXamlFile += ".xaml"; //save string to file using (StreamWriter outfile = new StreamWriter(saveXamlFile)) { outfile.Write(rendResult); outfile.Close(); reportMessage("XAML file generated successfully", ReportIcon.OK); } } else reportMessage("Failed to save XAML file!", ReportIcon.Error); } else reportMessage("Rendered XAML returned empty!", ReportIcon.Error); } catch (Exception ex) { reportMessage("Exception in Visualiser.ExportToXAML -> " + ex.Message, ReportIcon.Error); } } }
private void ExportToPNG_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Select visualisation file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml"; try { XAMLRenderer rend = new XAMLRenderer(); UIElement rendResult = rend.createStillVisualisation(tempFileName); if (rendResult != null) { //get PNG file name SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Export to PNG"; saveDialog.Filter = "PNG files (*.png)|*.png|All files (*.*)|*.*"; saveDialog.FileName = ""; saveDialog.ShowDialog(); if (!saveDialog.FileName.Equals("")) { //resulted visualisation model file string savePngFile = saveDialog.FileName; //where the reaulted reverse will be saved if (!savePngFile.ToLower().EndsWith(".png")) savePngFile += ".png"; //save to file using (Stream imageStream = File.Create(savePngFile)) { Window wind = new Window(); wind.WindowStyle = WindowStyle.None; wind.ShowInTaskbar = false; wind.ShowActivated = false; // Create Minimized so the window does not show. wind.WindowState = System.Windows.WindowState.Minimized; wind.SizeToContent = SizeToContent.WidthAndHeight; wind.Content = (UIElement)rendResult; wind.Show(); // The window needs to be created for the XAML elements to be rendered. BitmapSource bitmapSrc = visualToBitmap(wind, 100, 100);//dpiX, dpiY); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Clear(); encoder.Frames.Add(BitmapFrame.Create(bitmapSrc)); encoder.Save(imageStream); imageStream.Flush(); wind.Hide(); } } else reportMessage("Failed to save PNG file!", ReportIcon.Error); } else reportMessage("Export to PNG -> Rendered XAML returned empty!", ReportIcon.Error); } catch (Exception ex) { reportMessage("Exception in Visualiser.ExportToPNG -> " + ex.Message, ReportIcon.Error); } } }
private void ExportToHTML_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Select visualisation file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; try { XAMLRenderer rend = new XAMLRenderer(); string rendResult = rend.renderToStillXAML(tempFileName); if (!String.IsNullOrEmpty(rendResult)) { //save the xaml file SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Export to HTML file"; saveDialog.Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*"; saveDialog.FileName = ""; saveDialog.ShowDialog(); if (!saveDialog.FileName.Equals("")) { string dialogFile = saveDialog.FileName; string saveHtmlFile = ""; //resulted visualisation html file string xamlFile = ""; //where the xaml to be viewed will be saved if (!dialogFile.ToLower().EndsWith(".xaml")) xamlFile = dialogFile + ".xaml"; else xamlFile = dialogFile; if (!dialogFile.ToLower().EndsWith(".html")) saveHtmlFile = dialogFile + ".html"; else saveHtmlFile = dialogFile; //save xaml string to file using (StreamWriter outfile = new StreamWriter(xamlFile)) { outfile.Write(rendResult); outfile.Close(); reportMessage("HTML files generated successfully", ReportIcon.OK); } string htmlResult = rend.renderToStillHTML(tempFileName, xamlFile); //save xaml string to file using (StreamWriter outfile = new StreamWriter(saveHtmlFile)) { outfile.Write(htmlResult); outfile.Close(); reportMessage("HTML files generated successfully", ReportIcon.OK); } //get } else reportMessage("Failed to save HTML file!", ReportIcon.Error); } else reportMessage("Rendered HTML returned empty!", ReportIcon.Error); } catch (Exception ex) { reportMessage("Exception in Visualiser.ExportToHTML -> " + ex.Message, ReportIcon.Error); } } }
private void LoadTarget_Click(object sender, RoutedEventArgs e) { try { TargetCanvas.Children.Clear(); targetVisualElements.Clear(); OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Open Target file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { targetFile = openDialog.FileName; XAMLRenderer rend = new XAMLRenderer(); TargetCanvas.Children.Add(rend.createVisualisation(targetFile)); if (TargetCanvas.Children.Count > 0)//get visual elements for suggester targetVisualElements = rend.VisualElementList; targetASTL = new AbstractLattice(targetFile); prepareSuggestions(); ReportStatusBar.ShowStatus("Target model loaded", ReportIcon.OK); string modelname = targetFile.Substring(targetFile.LastIndexOf("\\") + 1); //log event logger.log("Target model \"" + modelname + "\" opened.", ReportIcon.Info); } else ReportStatusBar.ShowStatus("Could not load Target model", ReportIcon.Error); } catch (Exception ex) { ReportStatusBar.ShowStatus(ex.ToString(), ReportIcon.Error); } }