Skip to content

Commit

Permalink
Final clean-up in the Blazor application
Browse files Browse the repository at this point in the history
  • Loading branch information
Zedrichu committed May 15, 2023
1 parent ba97b38 commit abc64ac
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 111 deletions.
9 changes: 9 additions & 0 deletions QuBoxEngine/QuBoxEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
<PackageIcon>qubox-logo.png</PackageIcon>
<Company>QuBox</Company>
<AssemblyVersion>1.0</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Copyright (c) Zedrichu 2023</Copyright>
<PackageProjectUrl>https://github.com/Zedrichu/Qubox-Sim</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/Zedrichu/Qubox-Sim/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/Zedrichu/Qubox-Sim</RepositoryUrl>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Zedrichu.snk</AssemblyOriginatorKeyFile>
<PublicSign>true</PublicSign>
<Version>1.0.1</Version>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
Binary file added QuBoxEngine/Zedrichu.snk
Binary file not shown.
5 changes: 5 additions & 0 deletions QuLangProcessor/QuLangProcessor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<Title>QuLangProcessor</Title>
<Description>Language Processor for the QuLang Quantum Circuit Definition Language</Description>
<AssemblyVersion>1.0</AssemblyVersion>
<Version>1.0.1</Version>
<Copyright>Copyright (c) Zedrichu 2023</Copyright>
<PackageProjectUrl>https://github.com/Zedrichu/Qubox-Sim</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/Zedrichu/Qubox-Sim/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/Zedrichu/Qubox-Sim</RepositoryUrl>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
28 changes: 25 additions & 3 deletions QuboxBlazor/Pages/CircuitDesigner.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,28 @@

@code {

/// <summary>
/// Saved reference to the circuit object built on the platform
/// </summary>
private Circuit? _circuit { get; set; }

/// <summary>
/// Saved reference of the error tag during processing
/// </summary>
private AST.Error Error { get; set; } = AST.Error.Success;



/// <summary>
/// Upon initialization, subscribe to the state container
/// </summary>
protected override void OnInitialized()
{
StateContainer.OnChange += StateHasChanged;
}

/// <summary>
/// Mouse hovering binding function to update the circuit object
/// </summary>
private async void UpdateCircuit(MouseEventArgs e)
{
Interpreter.HandleLang(Content);
Expand All @@ -77,13 +90,19 @@
StateContainer.Property = _circuit;
}

/// <summary>
/// Unsubscribe from the state container when the component is disposed
/// </summary>
public void Dispose()
{
StateContainer.OnChange -= StateHasChanged;
}

private string Content { get; set; } = "...Try typing something in the editor or switch focus...";

/// <summary>
/// Function to obtain a stream of data containing the translated Q# code
/// </summary>
private Stream GetStreamData()
{
Interpreter.DecomposeCircuit(_circuit);
Expand All @@ -92,7 +111,10 @@
var fileStream = new MemoryStream(Encoding.UTF8.GetBytes(translated));
return fileStream;
}


/// <summary>
/// Function to trigger the download the Q# code as a file, by invoking a JS function
/// </summary>
private async Task DownloadFile()
{
var stream = GetStreamData();
Expand Down
37 changes: 32 additions & 5 deletions QuboxBlazor/Pages/QuLangEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@
</div>

@code {


/// <summary>
/// String contained in the code editor passed as a parameter from the parent component.
/// </summary>
[Parameter]
public string CodeContent { get; set; } = "";

/// <summary>
/// Reference to the Monaco editor component.
/// </summary>
private StandaloneCodeEditor _editor = null!;

/// <summary>
/// Event callback to the parent component when the code content changes. Notify whole page about update.
/// </summary>
[Parameter]
public EventCallback<string> CodeContentChanged { get; set; }

[Parameter]
public string ValueToSet { get; set; } = "";


/// <summary>
/// Instance creation for the editor component with specific configuration such as theme, font, initial value etc.
/// </summary>
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
Expand All @@ -43,33 +55,48 @@
};
}


/// <summary>
/// Asynchronous task triggered when the cursor position changes inside the editor.
/// </summary>
private async void EditorChangedPosition(CursorPositionChangedEvent eventArg)
{
CodeContent = await _editor.GetValue();
//Console.WriteLine($"Cursor position changed to: {eventArg.Position.LineNumber}, {eventArg.Position.Column}");
await UpdateContent(new MouseEventArgs());
}

/// <summary>
/// Asynchronous task triggered when the content of the editor changes.
/// </summary>
private async Task EditorChangedContent(ModelContentChangedEvent eventArg)
{
CodeContent = await _editor.GetValue();
//Console.WriteLine($"Content changed to: {CodeContent}");
await UpdateContent(new MouseEventArgs());
}


/// <summary>
/// Task executed when the mouse pointer leaves the area of the editor. Action-binding to the @onmouseleave event.
/// </summary>
private Task UpdateContent(MouseEventArgs eventArg)
{
//Console.WriteLine("Content is updated!");
return CodeContentChanged.InvokeAsync(CodeContent);
}


/// <summary>
/// Synchronous update of code editor content with new value.
/// </summary>
private async Task SetValue()
{
Console.WriteLine($"setting value to: {ValueToSet}");
await _editor.SetValue(ValueToSet);
}


/// <summary>
/// Synchronous retrieval of code editor content.
/// </summary>
private async Task GetValue()
{
var val = await _editor.GetValue();
Expand Down
14 changes: 12 additions & 2 deletions QuboxBlazor/Pages/SchemaVisual.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
</div>

@code {



/// <summary>
/// Parameter object received from the parent component for data-binding.
/// </summary>
[Parameter]
public Circuit Circuit { get; set; }

Expand All @@ -31,13 +35,19 @@

private readonly int InterGatePadding = 20;

/// <summary>
/// Trigger a task to render the visualisation for the first time after circuit update.
/// </summary>
protected override Task OnAfterRenderAsync(bool firstRender)
{
skiaView.EnableRenderLoop = true;
skiaView.EnableRenderLoop = false;
return base.OnAfterRenderAsync(firstRender);
}


/// <summary>
/// Method to construct the SVG visualisation of the circuit.
/// </summary>
private void PaintSurface(SKPaintSurfaceEventArgs e)
{
var svg = e.Surface.Canvas;
Expand Down
17 changes: 15 additions & 2 deletions QuboxBlazor/Pages/Simulation.razor
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,27 @@

@code {
private State state;



/// <summary>
/// Subscribe to the injected state container to be notified when the state changes.
/// </summary>
protected override void OnInitialized()
{
StateContainer.OnChange += StateHasChanged;
}


/// <summary>
/// Unsubscribe from the injected state container when the component is disposed.
/// </summary>
public void Dispose()
{
StateContainer.OnChange -= StateHasChanged;
}

/// <summary>
/// Trigger an asynchronous task to execute the circuit simulation.
/// </summary>
private async void SimCircuit()
{
await Task.Delay(500);
Expand All @@ -96,6 +106,9 @@
StateHasChanged();
}

/// <summary>
/// Method to display the results of the simulation.
/// </summary>
private string DisplayResults(State results )
{
if (results == null)
Expand Down
26 changes: 24 additions & 2 deletions QuboxBlazor/StateContainer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
namespace QuboxBlazor;
/* C#
-*- coding: utf-8 -*-
StateContainer
Description: Implementation of a state container to maintain session state between tabs.
@__Author --> Created by Adrian Zvizdenco aka Zedrichu
@__Date & Time --> Created on 14/04/2023
@__Email --> adrzvizdencojr@gmail.com
@__Version --> 1.0
@__Status --> DEV
*/

using QuBoxEngine.Circuits;

namespace QuboxBlazor;

/// <summary>
/// Class modelling the state container for the application.
/// </summary>
public class StateContainer
{
/// <summary>
/// Instance of the circuit object to be saved.
/// </summary>
private Circuit? savedCircuit;

public string PrintState()
{
if (savedCircuit == null)
Expand All @@ -15,6 +34,9 @@ public string PrintState()
return savedCircuit.ToString();
}

/// <summary>
/// Retrieval and update of the saved Circuit property.
/// </summary>
public Circuit? Property
{
get => savedCircuit;
Expand Down
Binary file removed QuboxBlazor/wwwroot/apple-touch-icon.png
Binary file not shown.
Binary file removed QuboxBlazor/wwwroot/favicon-16x16.png
Binary file not shown.
Binary file removed QuboxBlazor/wwwroot/favicon-32x32.png
Binary file not shown.
Binary file removed QuboxBlazor/wwwroot/favicon.ico
Binary file not shown.
Binary file removed QuboxBlazor/wwwroot/icon-192.png
Binary file not shown.
16 changes: 16 additions & 0 deletions QuboxBlazor/wwwroot/monacoSetup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/* Vanilla JavaScript
-*- coding: utf-8 -*-
monacoSetup
Description: This file is used to setup the Monaco editor. The tokens used in the QuLang format are registered to a
new language within the Monaco configuration. Using the token providers a color theme for the language is defined along
with code completion feature for the language.
@__Author --> Created by Adrian Zvizdenco aka Zedrichu
@__Date & Time --> Created on 29/03/2023
@__Email --> adrzvizdencojr@gmail.com
@__Version --> 1.0
@__Status --> DEV
*/


require.config({ paths: { 'vs': '_content/BlazorMonaco/lib/monaco-editor/min/vs' }});

let gate = ["H","X","Z","ID","Y","S","T","SDG","TDG","SX","SXDG","P","RZ","RY","RX","U"];
Expand Down
78 changes: 0 additions & 78 deletions QuboxBlazor/wwwroot/safari-pinned-tab.svg

This file was deleted.

Loading

0 comments on commit abc64ac

Please sign in to comment.