-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,58 @@ | ||
|
||
using Automata.Core; | ||
using Automata.Visualization; | ||
using Microsoft.Msagl.Drawing; | ||
using Spectre.Console; | ||
|
||
namespace Automata.App; | ||
|
||
/// <summary> | ||
/// A sample program that demonstrates how to create a graph from a collection of sequences and display it in a separate window. | ||
/// </summary> | ||
public static class Program | ||
{ | ||
public static void Main() | ||
{ | ||
|
||
Console.WriteLine("Creating graph..."); // Write some text output to the console window | ||
|
||
var sequences = Enumerable.Range(0, 10).Select(_ => Enumerable.Range(0, 8).Select(_ => Random.Shared.Next(4).ToString())); //Create some random sequences | ||
|
||
|
||
IFsa fsa = new NFA(sequences).ToDFA().Minimized(); | ||
Graph graph = GraphFactory.CreateGraph(fsa); // Create a graph object to display using the sequences | ||
|
||
//Alternatively: you can replace the two lines above, with the line below which creates a minimized graph directly from a collection of sequences | ||
//Graph graph = GraphFactory.CreateGraph(sequences, minimize: true); // Create a displayable graph object directly using the sequences | ||
|
||
ConsoleWindow consoleWindow = ConsoleWindow.Create(); // Creates the main console window. | ||
GraphView graphView = GraphView.Create(); //Create a non-modal window for displaying graphs | ||
|
||
consoleWindow.WriteLine("Creating graph...", System.Drawing.Color.Blue); // Write some colored text output to the console window | ||
// graphView.ShowGraph(graph); //Display the graph in the graph view | ||
|
||
var sequences = Enumerable.Range(0, 10).Select(_ => Enumerable.Range(0, 8).Select(_ => Random.Shared.Next(4).ToString())); //Create some random sequences | ||
AnsiConsole.MarkupLine("Graph is displayed in a separate window"); | ||
|
||
var graph = GraphFactory.CreateGraph(sequences, minimize: true); // Create a graph object to display using the sequences | ||
} | ||
|
||
consoleWindow.ShowGraph(graph); // Open a new non-modal window that displays the graph in it. | ||
|
||
consoleWindow.WriteLine("Graph created.", System.Drawing.Color.Green); // Write some more colored text output to the console window | ||
|
||
/// <summary> | ||
/// Displays the specified graph in the graph view. | ||
/// </summary> | ||
/// <param name="graph">The graph to display.</param> | ||
//public static void ShowGraph(Graph graph) | ||
//{ | ||
// if (!IsAlive) return; | ||
// // Check if we're on the UI thread | ||
// if (InvokeRequired) | ||
// { | ||
// // If not on UI thread, re-invoke this method on the UI thread | ||
// Invoke(new Action(() => ShowGraph(graph))); | ||
// return; | ||
// } | ||
// GraphView graphView = new GraphView(); | ||
// // Safe to update the GViewer directly here | ||
// graphView.GViewer.Graph = graph; | ||
// graphView.Show(); | ||
// graphView.Activate(); | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters