Exemplo n.º 1
0
        private void addVariable(object sender, RoutedEventArgs e)
        {
            var newDialog = new FunctionsDialog();

            newDialog.ShowDialog();
            if (newDialog.DialogResult == true)
            {
                booleanFunctions.Add(newDialog.Result, "");
            }

            ReloadFunctions(sender, e);


            wiringDiagram.WithGraphAttributesOf(
                RankDir.TB,
                Font.Name("Arial"),
                Font.Size(55))
            .WithNodeAttributesOf(
                Shape.Ellipse,
                Color.Black);

            wiringDiagram.Containing(DotBuilder.Statements.Node.Name(newDialog.Result));


            // to get the raw dot output
            var dot = wiringDiagram.Render();

            // to render to a file stream

            var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }
Exemplo n.º 2
0
        private void removeVariable(object sender, RoutedEventArgs e)
        {
            if (cmbSelectVariable.SelectedItem != null)
            {
                booleanFunctions.Remove(cmbSelectVariable.SelectedItem.ToString());
                cmbSelectVariable.Items.Remove(cmbSelectVariable.SelectedItem);
            }
            else
            {
                MessageBox.Show("Please select a Boolean variable first!");
                return;
            }

            wiringDiagram = Graph.Directed("adiagram");

            wiringDiagram.WithGraphAttributesOf(
                RankDir.TB,
                Font.Name("Arial"),
                Font.Size(55))
            .WithNodeAttributesOf(
                Shape.Ellipse,
                Color.Black);

            foreach (string key in booleanFunctions.Keys)
            {
                wiringDiagram.Containing(DotBuilder.Statements.Node.Name(key)); //make sure all variables are displayed

                string value;
                booleanFunctions.TryGetValue(key, out value);
                foreach (string k in booleanFunctions.Keys)
                {
                    if (value.Contains(k))
                    {
                        wiringDiagram.Containing(Edge.Between(k, key).WithAttributesOf(Color.Black));
                    }
                }
            }

            // to get the raw dot output
            var dot = wiringDiagram.Render();

            // to render to a file stream

            var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }