public void Run() { const string testFileName = "output"; string dotFilePath = Path.Combine(GetTemporaryTestDirectory(), testFileName); const string content = "digraph G {}"; var dotEngine = new FileDotEngine(); dotEngine.Run(GraphvizImageType.Jpeg, content, dotFilePath); CheckFileContent($"{dotFilePath}.dot", content); const string testFileName2 = "output2.dot"; string dotFilePath2 = Path.Combine(GetTemporaryTestDirectory(), testFileName2); const string content2 = "digraph G { 1; 2; 3; 1 -- 2; }"; dotEngine.Run(GraphvizImageType.Jpeg, content2, dotFilePath2); CheckFileContent(dotFilePath2, content2); #region Local function void CheckFileContent(string filePath, string fileContent) { Assert.IsTrue(File.Exists(filePath)); string loadedContent = File.ReadAllText(filePath); Assert.AreEqual(fileContent, loadedContent); } #endregion }
private void drawGraph(object sender, RoutedEventArgs e) { if (graphToDraw is null) { return; } // to get the raw dot output var dot = graphToDraw.Render(); //// to render to a file stream //var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png); //System.GC.Collect(); //System.GC.WaitForPendingFinalizers(); //var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "temporary.png"); //File.Delete(path); //using (var stream = new FileStream(path, FileMode.Create)) //{ // graphviz.RenderGraph(graphToDraw, stream); // stream.Close(); //} Bitmap bm = FileDotEngine.Run(dot); StateGraph stateGraph = new StateGraph(bm, booleanFunctions); stateGraph.Show(); }
public void Run_Throws() { const string dot = "digraph G {}"; const string filePath = "NotSaved.dot"; var dotEngine = new FileDotEngine(); // ReSharper disable AssignNullToNotNullAttribute Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, null, filePath)); Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, string.Empty, filePath)); Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, dot, null)); Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, dot, string.Empty)); Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, null, null)); Assert.Throws <ArgumentException>(() => dotEngine.Run(GraphvizImageType.Jpeg, string.Empty, string.Empty)); // ReSharper restore AssignNullToNotNullAttribute }
private void pNGToolStripMenuItem_Click(object sender, EventArgs e) { if (FileOpened && Automaton != default(Automaton)) { FileDotEngine FDE = new FileDotEngine(); string FileName = Interaction.InputBox("Insira o nome do arquivo para exportar", string.Empty); if (FileName != string.Empty) { if (!File.Exists(TPI_Teoria_Linguagem.Properties.Settings.Default.ExportDirectory + @"\" + FileName + ".png")) { FDE.ExportPNG(FileName); } else { MessageBox.Show("Este arquivo já existe no diretório de exportação.", "Arquivo já existente", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Selecione um arquivo para carregar um autômato antes de tentar exportá-lo.", "Selecione um arquivo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Call the program either with or without arguments specifying in which folder it should run. /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Ensure working directory is proper so doxyfile is retrievable. Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string path = args.FirstOrDefault(); if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Must specify path to code to analyze."); } path = path.Replace('\\', '/'); Console.WriteLine($"Running Doxygen on {path}..."); Console.Out.Flush(); //Have doxygen run with our doxyfile and make a subfolder. DoxygenRunner.Run(path); string outputSubPath = "uml_diagram_and_documentation"; //must match the doxyfile! must not have slashes. string diagramName = "ClassDiagram"; Console.WriteLine($"Parsing XML output."); //Use and parse the XML in the subfolder to then generete the dot and SVG of the class diagram with. Package root; List <UMLEntity> parsed; (root, parsed) = ParseDoxygenStructure($@"{path}\{outputSubPath}\xml"); //var parsed = ParseDoxygenStructure(@"C:\Users\Joep\source\repos\DatabasesTentamenCheckerConsoleApp\doxygen\xml"); StringBuilder result = new StringBuilder(); root.OutputSelf(result); foreach (var item in parsed) { // item.OutputSelf(result); // result.AppendLine(); } foreach (var item in parsed.Where(p => p is Node)) { (item as Node).OutputRelations(result); result.AppendLine(); } String template = $@" digraph {diagramName} {{ fontname = ""Consolas"" fontsize = 8 node [ fontname = ""Consolas"" fontsize = 8 shape = ""record"" ] edge [ fontname = ""Consolas"" fontsize = 8 ] {result.ToString()} }} "; string outputFileClassDiagram = $"{path}/{outputSubPath}/{diagramName}"; Console.WriteLine($"Running DOT to generate class diagram..."); FileDotEngine.Run(template, outputFileClassDiagram); /* if(args.Length<1) * { * if(!Directory.Exists(args[0])) * { * throw new ArgumentException("specified directory does not exist."); * } * Directory.SetCurrentDirectory(args[0]); * } * ParseDoxygenStructure(".");*/ Console.WriteLine($"Opening classdiagram..."); System.Diagnostics.Process.Start($"{outputFileClassDiagram}.svg"); Console.WriteLine($"Done."); }
private void drawGraphClustering(object sender, RoutedEventArgs e, List <int> indexes, List <string> variables) { int totalStates = Convert.ToInt32(Math.Pow(2.0, Convert.ToDouble(cmbSelectVariable.Items.Count))); if (cmbSelectVariable.Items.Count == 0) { return; } graphToDraw = Graph.Directed("agraph"); graphToDraw.WithGraphAttributesOf( RankDir.TB, Font.Name("Arial"), Font.Size(55)) .WithNodeAttributesOf( Shape.Ellipse, Color.Black); string attributes = ""; int last = variables.LastIndexOf(variables.Last()); while (indexes.Contains(last)) { last--; } for (int i = 0; i < variables.Count; i++) { if (!indexes.Contains(i)) { attributes += variables.ElementAt(i); if (i != last) { attributes += ", "; } } } graphToDraw.WithGraphAttributesOf( Label.Set("Graph showing attributes: " + attributes), Font.Size(16)); g = new AdjacencyGraph <string, Edge <string> >(); List <List <byte> > inputs = new List <List <byte> >(); for (int i = 0; i < totalStates; i++) { string binary = "00000000000" + Convert.ToString(i, 2); string final = binary.Substring(binary.Count() - cmbSelectVariable.Items.Count); List <byte> newInput = new List <byte>(); for (int j = 0; j < cmbSelectVariable.Items.Count; j++) { newInput.Add(Convert.ToByte(final[j].ToString())); } inputs.Add(newInput); } List <Dictionary <List <byte>, byte> > allTruthtables = new List <Dictionary <List <byte>, byte> >(); for (int k = 0; k < cmbSelectVariable.Items.Count; k++) { Dictionary <List <byte>, byte> truthTableX = new Dictionary <List <byte>, byte>(); foreach (List <byte> input in inputs) { truthTableX.Add(input, evaluateBoolean(input, k)); } allTruthtables.Add(truthTableX); } foreach (var pair in allTruthtables.ElementAt(0)) { string inputX = ""; string outputX = ""; for (int l = 0; l < allTruthtables.Count; l++) { if (!indexes.Contains(l)) { inputX += pair.Key.ElementAt(l); outputX += allTruthtables.ElementAt(l)[pair.Key]; } } if (!g.ContainsEdge(inputX, outputX)) { graphToDraw.Containing(Edge.Between(inputX, outputX).WithAttributesOf(Color.Black)); } //*****Code to convert graph for use with QuickGraph library string v1 = inputX; string v2 = outputX; var edge = new Edge <string>(v1, v2); g.AddVerticesAndEdge(edge); } if (graphToDraw is null) { return; } // to get the raw dot output var dot = graphToDraw.Render(); //// to render to a file stream //var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png); //System.GC.Collect(); //System.GC.WaitForPendingFinalizers(); //var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "temporary.png"); //File.Delete(path); //using (var stream = new FileStream(path, FileMode.Create)) //{ // graphviz.RenderGraph(graphToDraw, stream); // stream.Close(); //} Bitmap bm = FileDotEngine.Run(dot); StateGraph stateGraph = new StateGraph(bm, booleanFunctions); stateGraph.Show(); }