Skip to content

Commit

Permalink
[NEW-FEATURE]TcoInputDialog (#700)
Browse files Browse the repository at this point in the history
* Create draft PR for #699

* +TcoInput dialog
+examples in docu

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Peter Barancek <[email protected]>
  • Loading branch information
github-actions[bot] and peterbarancek authored Mar 25, 2024
1 parent bfaf92a commit d5d7913
Show file tree
Hide file tree
Showing 38 changed files with 951 additions and 19 deletions.
92 changes: 91 additions & 1 deletion src/TcoCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@

## Dialogs

Registration dialogs is defined by *.SetPlcDialogs(DialogProxyServiceWpf.Create(new[] { PlcTcoCoreExamples.EXAMPLES_PRG._diaglogsContext}));*

### Important: For correct behavior use this order of definition in your app.

```csharp
PlcTcoCoreExamples.Connector.BuildAndStart();

TcOpen.Inxton.TcoAppDomain.Current.Builder
.SetUpLogger(new TcOpen.Inxton.Logging.SerilogAdapter(new LoggerConfiguration()
.WriteTo.Console(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose)
.WriteTo.Notepad()
.MinimumLevel.Verbose()))
.SetDispatcher(TcoCore.Wpf.Threading.Dispatcher.Get)
.SetPlcDialogs(DialogProxyServiceWpf.Create(new[] { PlcTcoCoreExamples.EXAMPLES_PRG._diaglogsContext}));
```

### Plc Hide dialog

```csharp
Expand Down Expand Up @@ -184,4 +200,78 @@ Here may be used any signal or condition when dialog should be closed with choos
```

![alt text](assets/customizedDialog3OptionsWithImage.png)
![alt text](assets/customizedDialog3OptionsWithZoomedImage.png)
![alt text](assets/customizedDialog3OptionsWithZoomedImage.png)

## Plc Example usage of Input Dialog

### Declaration

```csharp
_customizedContentInput : MyOwnContent(THIS^);
_dialogWithInput : TcoCore.TcoInputDialog(THIS^);
```

### Structure defined by user that will be displayed in dialog as input fields

```csharp
FUNCTION_BLOCK MyOwnContent EXTENDS TcoCore.TcoInputDialogContentContainer
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
{attribute addProperty Name "<#Recipe#>"}
Recipe:STRING;
{attribute addProperty Name "<#Qantity#>"}
RequiredQuantity:INT;
{attribute addProperty Name "<#Timeout#>"}
Timeout:DATE_AND_TIME;
{attribute addProperty Name "<#Exclude#>"}
Exclude:BOOL;

END_VAR
```

### Usage

```csharp
100:
_dialogWithInput.Show(refContent:=_customizedContentInput)
.WithType(eDialogType.Question)
.WithYesNo()
.WithCaption('Hey wana set data')
.WithText('Do you realy want to sent data to ....?');

IF (_dialogWithInput.Answer = TcoCore.eInputDialogAnswer.Yes) THEN
_state := 15;
END_IF;

IF (_dialogWithInput.Answer = TcoCore.eInputDialogAnswer.No) THEN
_state := 1000;
END_IF;

```

## Plc Example usage of Input Dialog with image

### Usage

```csharp
110:
_dialogWithInput.Show(refContent:=_customizedContentInput)
.WithType(eDialogType.Question)
.WithOk()
.WithImage('https://github.com/TcOpenGroup',400,600)
.WithCaption('Hey wana set data')
.WithText('Do you realy want to sent data to ....?');



IF (_dialogWithInput.Answer = TcoCore.eInputDialogAnswer.OK) THEN
_state := 1000;
_invokeInputDiaglog := FALSE;

END_IF;
```

![alt text](assets/InputDialogExampleWithImage.png)
Binary file added src/TcoCore/assets/InputDialogExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/TcoCore/src/TcoCore.Wpf/TcOpen.Inxton.TcoCore.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="TcoDialog\TcoDialog\TcoCustomizedDialogDialogView.xaml">
<Page Update="TcoDialog\CustomizedDialog\TcoCustomizedDialogDialogView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="TcoDialog\InputDialog\TcoInputDialogDialogView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="TcoMessage\Health\HealthIndicatorView.xaml">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<local:TcoDialogBaseView
x:Class="TcoCore.TcoInputDialogDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TcoCore"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tcocore="clr-namespace:TcoCore;assembly=TcoCoreConnector"
xmlns:vortex="http://vortex.mts/xaml"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"

xmlns:s="clr-namespace:TcOpen.Inxton.TcoCore.Wpf.Properties"
Width="Auto"
Height="Auto"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
ResizeMode="NoResize"
ShowInTaskbar="False"
SizeToContent="WidthAndHeight"
Title="InspectorDialogueWindow"
Topmost="True"
Closing="TcoDialogBaseView_Closing"
WindowStartupLocation="CenterScreen"
WindowStyle="None">
<d:Window.DataContext>
<local:TcoInputDialogDialogViewModel />
</d:Window.DataContext>
<Window.Background>
<SolidColorBrush Color="White" Opacity="1" />
</Window.Background>
<materialDesign:Card
Margin="10"
materialDesign:ShadowAssist.ShadowDepth="Depth5"
materialDesign:ShadowAssist.ShadowEdges="Top,Bottom,Left,Right">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="80*" />
</Grid.ColumnDefinitions>
<materialDesign:PackIcon
DataContext="{Binding Dialog._dialogType}"
Margin="10"
Grid.RowSpan="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding Synchron, Converter={local:DialogTypeVisibilityConverter}}"
Foreground="{Binding Synchron, Converter={local:DialogTypeToColorConverter}}"
Kind="{Binding Synchron, Converter={local:DialogTypeToIconConverter}}"
Width="75" Height="75"/>
<StackPanel Grid.Row="0" Grid.Column="1">
<StackPanel.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource MaterialDesignHeadline6TextBlock}">
<Setter Property="MinWidth" Value="250"></Setter>
</Style>
</StackPanel.Resources>
<TextBlock
Margin="0,10,10,10"
HorizontalAlignment="Center"
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="{Binding Dialog._caption.Synchron}" />
<wv2:WebView2 x:Name="webView" Visibility="{Binding Dialog._imageSource.Synchron,Converter={local:EmptyStringToVisibilityConverter} }" Height="{Binding Dialog._imageHeight.Cyclic}" Width="{Binding Dialog._imageWidth.Cyclic}" Source="{Binding Dialog._imageSource.Synchron ,Mode=OneWay}" />
<vortex:RenderableContentControl DataContext="{Binding Dialog._content}" PresentationType="ShadowControlSlim"></vortex:RenderableContentControl>
<TextBlock
Margin="0,10,10,10"
HorizontalAlignment="Center"
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
Text="{Binding Dialog._text.Synchron}" />
</StackPanel>
<WrapPanel
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Center">
<WrapPanel.Resources>
<Style BasedOn="{StaticResource MaterialDesignRaisedDarkButton}" TargetType="Button">
<Setter Property="Width" Value="250" />
<Setter Property="Margin" Value="10" />
</Style>
</WrapPanel.Resources>
<Button
Command="{Binding YesCommand, Mode=OneWay}"
Content="{x:Static s:strings.Yes}"
Visibility="{Binding Dialog._hasYes.LastValue, Converter={local:DialogAnswerButtonVisibility}}" />
<Button
Command="{Binding NoCommand, Mode=OneWay}"
Content="{x:Static s:strings.No}"
Visibility="{Binding Dialog._hasNo.LastValue, Converter={local:DialogAnswerButtonVisibility}}" />

<Button
Command="{Binding OkCommand, Mode=OneWay}"
Content="{x:Static s:strings.Ok}"
Visibility="{Binding Dialog._hasOK.LastValue, Converter={local:DialogAnswerButtonVisibility}}" />
</WrapPanel>
</Grid>
</materialDesign:Card>
</local:TcoDialogBaseView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TcoCore
{
/// <summary>
/// Interaction logic for TcoDialogView.xaml
/// </summary>
public partial class TcoInputDialogDialogView
{
public TcoInputDialogDialogView() : base()
{
InitializeComponent();
}

private void TcoDialogBaseView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (webView != null)
{
webView.Dispose();
webView = null;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TcOpen.Inxton.Input;
using Vortex.Connector;
using Vortex.Connector.ValueTypes;
using Vortex.Presentation;

namespace TcoCore
{
public class TcoInputDialogDialogViewModel : TcoDialogBaseViewModel , IDisposable
{
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public TcoInputDialogDialogViewModel() : base()
{


dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);


dispatcherTimer.Start();



OkCommand = new RelayCommand((a) => { Dialog._answer.Synchron = (short)eInputDialogAnswer.OK; FlushShadowToOnline(); this.Close(this, new EventArgs()); },
((b) => (bool)Dialog._hasOK.Synchron),
() => TcOpen.Inxton.TcoAppDomain.Current.Logger.Information($"{nameof(TcoCore.TcoInputDialogDialogViewModel.OkCommand)} of {Dialog.HumanReadable} was executed @{{payload}}.", new { Dialog.Symbol }));

YesCommand = new RelayCommand((a) => { Dialog._answer.Synchron = (short)eInputDialogAnswer.Yes; FlushShadowToOnline(); this.Close(this, new EventArgs()); },
(b) => Dialog._hasYes.Synchron,
() => TcOpen.Inxton.TcoAppDomain.Current.Logger.Information($"{nameof(YesCommand)} of {Dialog.HumanReadable} was executed @{{payload}}.", new { Dialog.Symbol }));

NoCommand = new RelayCommand((a) => { Dialog._answer.Synchron = (short)eInputDialogAnswer.No; this.Close(this, new EventArgs()); },
(b) => Dialog._hasNo.Synchron,
() => TcOpen.Inxton.TcoAppDomain.Current.Logger.Information($"{nameof(NoCommand)} of {Dialog.HumanReadable} was executed @{{payload}}.", new { Dialog.Symbol }));




}

private void FlushShadowToOnline()
{
try
{
((dynamic)Dialog.GetConnector().IdentityProvider.GetVortexerByIdentity(Dialog._content.Identity.Synchron)).FlushShadowToOnline();
}
catch (Exception msg)
{

Console.WriteLine(msg);
}

}

private void dispatcherTimer_Tick(object sender, EventArgs e)
{

Dialog.Read();


if (Dialog._answer.LastValue != (short)eDialogAnswer.Invoked)
{
this.Close(this, new EventArgs());

if (dispatcherTimer != null)
{
dispatcherTimer.Stop(); // stop timer
dispatcherTimer.Tick -= dispatcherTimer_Tick;
}
}



}


public void Dispose()
{
if (dispatcherTimer != null)
{
dispatcherTimer.Stop();
dispatcherTimer.Tick -= dispatcherTimer_Tick;

}
}

public TcoInputDialog Dialog { get; private set; } = new TcoInputDialog();
public override object Model { get => Dialog; set => Dialog = (TcoInputDialog)value; }

public RelayCommand OkCommand { get; }
public RelayCommand YesCommand { get; }
public RelayCommand NoCommand { get; }
public PlainTcoInputDialog Plainer { get; private set; } = new PlainTcoInputDialog();
}


}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="___Invalid_reference_axis_1__" xml:space="preserve">
<value>Invalid reference axis 1</value>
</data>
<data name="___Real_time_clock_is_invalid___" xml:space="preserve">
<value>Real time clock is invalid!</value>
</data>
Expand Down
Loading

0 comments on commit d5d7913

Please sign in to comment.