Last-Modified: Fri, 26 Jun 2026 09:31:08 GMT Expires: Mon, 23 Jun 2036 09:31:08 GMT MachineVersionDialog.xaml « Views « Tango.MachineStudio.MachineDesigner « Modules « MachineStudio « Visual_Studio « Software - Tango - Twine softwares
aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineVersionDialog.xaml
blob: b047206472cd705cbcddf5b3ef424dfd882e4632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<UserControl x:Class="Tango.MachineStudio.MachineDesigner.Views.MachineVersionDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:providers="clr-namespace:Tango.MachineStudio.MachineDesigner.AutoComplete"
             xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
             xmlns:local="clr-namespace:Tango.MachineStudio.MachineDesigner.Views"
             mc:Ignorable="d" Width="530" Height="239" Background="{StaticResource Dialog.Background}" Foreground="{StaticResource Dialog.Foreground}">

    <UserControl.Resources>
        <providers:MachineVersionsProvider x:Key="VersionsProvider"></providers:MachineVersionsProvider>
    </UserControl.Resources>
    
    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>

            <Grid>
                <StackPanel Orientation="Horizontal" Margin="10">
                    <materialDesign:PackIcon Width="24" Height="24" Kind="Verified" VerticalAlignment="Center"></materialDesign:PackIcon>
                    <TextBlock Text="Default Version Configuration" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="16"></TextBlock>
                </StackPanel>
            </Grid>

            <Grid Grid.Row="1" Margin="10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid>
                    <StackPanel Margin="10">
                        <TextBlock>Version</TextBlock>
                        <ComboBox ItemsSource="{Binding Adapter.MachineVersions}" Text="{Binding Version}" DisplayMemberPath="Version" SelectedItem="{Binding SelectedVersion}" IsEditable="True" materialDesign:HintAssist.Hint="Select or enter a new version name"></ComboBox>
                        <TextBlock Margin="0 10 0 0">Name</TextBlock>
                        <TextBox materialDesign:HintAssist.Hint="Version name" Text="{Binding VersionName}">
                            <TextBox.Style>
                                <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                                    <Setter Property="IsEnabled" Value="False"></Setter>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding SelectedVersion}" Value="{x:Null}">
                                            <Setter Property="IsEnabled" Value="True"></Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>
                        </TextBox>
                        </StackPanel>
                </Grid>

                <Grid Grid.Row="1">
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
                        <Button Command="{Binding AcceptCommand}" Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0">
                            ACCEPT
                        </Button>
                        <Button Command="{Binding CancelCommand}" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="False" Margin="0 8 8 0">
                            CANCEL
                        </Button>
                    </StackPanel>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
/* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using Tango.BL.Enumerations;
using Tango.BL.ValueObjects;
using Tango.Core;
using System.Windows.Media;
using System.Windows;

namespace Tango.MachineStudio.Statistics.Models
{
    public class StatisticsValue
    {
        public string Name { get; set; }

        public object Value { get; set; }

        public string Unit { get; set; }
    }
    public class MoreValue
    {
        public string Text { get; set; }
    }

    public class StatisticsValueCollection : ExtendedObject
    {
        private List<Color> _pieColors;

        #region Properties

        private ObservableCollection<StatisticsValue> _statisticsCollection;

        /// <summary>
        /// Gets or sets the statistics collection of StatisticsValue object.
        /// </summary>
        public ObservableCollection<StatisticsValue> StatisticsCollection
        {
            get { return _statisticsCollection; }
            set
            {
                _statisticsCollection = value;
                RaisePropertyChangedAuto();
            }
        }

        private List<StatisticsValue> _threadConsumptionPerThread;
        /// <summary>
        /// Gets or sets the thread consumption per thread list.
        /// </summary>
        public List<StatisticsValue> ThreadConsumptionPerThread
        {
            get { return _threadConsumptionPerThread; }
            set { _threadConsumptionPerThread = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Gets or sets the thread consumption per thread collection.
        /// </summary>
        public CompositeCollection ThreadConsumptionPerThreadCollection { get; set; }

        private LabeledSeriesCollection _pieJobSource;

        /// <summary>
        /// Gets or sets the pie job source.
        /// </summary>
        public LabeledSeriesCollection PieJobSource
        {
            get { return _pieJobSource; }
            set { _pieJobSource = value; RaisePropertyChangedAuto(); }
        }

        private LabeledSeriesCollection _pieJobRunStatus;

        /// <summary>
        /// Gets or sets the pie job run status.
        /// </summary>
        public LabeledSeriesCollection PieJobRunStatus
        {
            get { return _pieJobRunStatus; }
            set { _pieJobRunStatus = value; RaisePropertyChangedAuto(); }
        }

        private LabeledSeriesCollection _pieGradientSolid;

        /// <summary>
        /// Gets or sets the pie gradient solid.
        /// </summary>
        public LabeledSeriesCollection PieGradientSolid
        {
            get { return _pieGradientSolid; }
            set { _pieGradientSolid = value; RaisePropertyChangedAuto(); }
        }

        private List<TotalLiquidQuantityModel> _liquidQuantities;

        /// <summary>
        /// Gets or sets the liquid quantities.
        /// </summary>
        public List<TotalLiquidQuantityModel> LiquidQuantities
        {
            get
            {
                if (_liquidQuantities == null)
                {
                    _liquidQuantities = new List<TotalLiquidQuantityModel>();
                }
                return _liquidQuantities;
            }
            set
            { _liquidQuantities = value; RaisePropertyChangedAuto(); }
        }

        private ulong _totalLiquidQuantities;

        /// <summary>
        /// Gets or sets the total liquid quantities.
        /// </summary>
        public ulong TotalLiquidQuantities
        {
            get { return _totalLiquidQuantities; }
            set { _totalLiquidQuantities = value; RaisePropertyChangedAuto(); }
        }

        #endregion

        public StatisticsValueCollection()
        {
            StatisticsCollection = new ObservableCollection<StatisticsValue>();
            ThreadConsumptionPerThread = new List<StatisticsValue>();
            ThreadConsumptionPerThreadCollection = new CompositeCollection();

            _pieColors = new List<Color>();
            _pieColors.Add(((SolidColorBrush)Application.Current.Resources["RedBrush500"]).Color);
            _pieColors.Add(((SolidColorBrush)Application.Current.Resources["OrangeBrush"]).Color);
            _pieColors.Add(((SolidColorBrush)Application.Current.Resources["GreenBrush"]).Color);
            _pieColors.Add(((SolidColorBrush)Application.Current.Resources["BlueBrush100"]).Color);
            _pieColors.Add(Color.FromRgb(255, 216, 76));


            PieJobSource = new LabeledSeriesCollection()
            {
                Title = "PPC/MS",
                SeriesColors = _pieColors,
            };
            PieJobRunStatus = new LabeledSeriesCollection()
            {
                Title = "Failed/Aborted/Completed",
                SeriesColors = _pieColors,
            };
            PieGradientSolid = new LabeledSeriesCollection()
            {
                Title = "Gradient/Solid",
                SeriesColors = _pieColors,
            };
        }

        /// <summary>
        /// Cleans all values.
        /// </summary>
        public void Clean()
        {
            StatisticsCollection.Clear();
            ThreadConsumptionPerThreadCollection.Clear();
            ThreadConsumptionPerThread.Clear();
            PieJobSource.SeriesCollection.Clear();
            PieJobRunStatus.SeriesCollection.Clear();
            PieGradientSolid.SeriesCollection.Clear();
        }

        /// <summary>
        /// Adds the statistics value.
        /// </summary>
        public void AddStatisticsValue(string name, object value, string unit)
        {
            StatisticsCollection.Add(new StatisticsValue() { Name = name, Value = value, Unit = unit });
            RaisePropertyChanged("StatisticsCollection");
        }

        /// <summary>
        /// Creates the thread consumption per thread.
        /// </summary>
        public void CreateThreadConsumptionPerThread(List<StatisticsValue> threads)
        {
            ThreadConsumptionPerThreadCollection.Add(new CollectionContainer() { Collection = threads.Take(threads.Count() > 2 ? 2 : threads.Count()) });
            if (threads.Count() > 2)
            {
                ThreadConsumptionPerThreadCollection.Add(new CollectionContainer() { Collection = new List<MoreValue>() { new MoreValue() { Text = "More threads ..." } } });
                ThreadConsumptionPerThread = threads.Skip(2).ToList();
            }

            RaisePropertyChanged("ThreadConsumptionPerThreadCollection");
        }

        #region GeneratePieChart
        Func<ChartPoint, string> labelPoint = chartPoint =>
            string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

        public void GeneratePieJobSource(int PPCCount, int MSCount)
        {
            var series = new PieSeries()
            {
                Title = "PPC",
                Values = new ChartValues<int>() { PPCCount },
                Fill = new SolidColorBrush(_pieColors[4]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint

            };

            PieJobSource.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "MS",
                Values = new ChartValues<int>() { MSCount },
                Fill = new SolidColorBrush(_pieColors[3]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieJobSource.SeriesCollection.Add(series);
            RaisePropertyChanged("PieJobSource");
        }

        public void GeneratePieJobRunStatus(int failedCount, int abortedCount, int completedCount)
        {
            var series = new PieSeries()
            {
                Title = "Failed",
                Values = new ChartValues<int>() { failedCount },
                Fill = new SolidColorBrush(_pieColors[0]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };

            PieJobRunStatus.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Aborted",
                Values = new ChartValues<int>() { abortedCount },
                Fill = new SolidColorBrush(_pieColors[1]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint,

            };
            PieJobRunStatus.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Completed",
                Values = new ChartValues<int>() { completedCount },
                Fill = new SolidColorBrush(_pieColors[2]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieJobRunStatus.SeriesCollection.Add(series);

            RaisePropertyChanged("PieJobRunStatus");
        }

        public void GeneratePieGradientSolid(int gradientCount, int solidCount)
        {
            var series = new PieSeries()
            {
                Title = "Solid",
                Values = new ChartValues<int>() { solidCount },
                Fill = new SolidColorBrush(_pieColors[4]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint
            };
            PieGradientSolid.SeriesCollection.Add(series);

            series = new PieSeries()
            {
                Title = "Gradient",
                Values = new ChartValues<int>() { gradientCount },
                Fill = new SolidColorBrush(_pieColors[3]),
                DataLabels = true,
                ToolTip = "",
                LabelPoint = labelPoint

            };

            PieGradientSolid.SeriesCollection.Add(series);


            RaisePropertyChanged("PieGradientSolid");
        }
        #endregion

        /// <summary>
        /// Generates the statistics liquid quantity and TotalLiquidQuantities.
        /// </summary>
        public void GenerateStatisticsLiquidQuantity(List<TotalLiquidQuantityModel> liquidQuantities)
        {
            LiquidQuantities = liquidQuantities;
            TotalLiquidQuantities = 0;

            foreach (var item in liquidQuantities)
            {
                TotalLiquidQuantities += (ulong)item.Quantity;
            }
        }

    }
}