aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataVM.cs
blob: 403494a8ebf64e491202978d5c1ed93b1c8ffce6 (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
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core;
using Tango.SharedUI;

namespace Tango.MachineStudio.RML.ViewModels
{
    public class CalibrationDataVM : ExtendedObject
    {
        private LiquidType _liquidType;

        public LiquidType LiquidType
        {
            get { return _liquidType; }
            set { _liquidType = value; RaisePropertyChangedAuto(); }
        }

        private IdsPack _idsPack;

        public IdsPack IdsPack
        {
            get { return _idsPack; }
            set { _idsPack = value; RaisePropertyChangedAuto(); }
        }

        private ObservableCollection<CalibrationDataPointVM> _calibrationPoints;

        public ObservableCollection<CalibrationDataPointVM> CalibrationPoints
        {
            get { return _calibrationPoints; }
            set { _calibrationPoints = value; RaisePropertyChangedAuto(); OnCalibrationPointsChanged(); }
        }

        private void OnCalibrationPointsChanged()
        {
            if (CalibrationPoints != null)
            {
                CalibrationPoints.CollectionChanged -= CalibrationPoints_CollectionChanged;
                CalibrationPoints.CollectionChanged += CalibrationPoints_CollectionChanged;

                SetIndices();
            }
        }

        private void CalibrationPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            SetIndices();
        }

        private void SetIndices()
        {
            if (CalibrationPoints != null)
            {
                int index = 1;
                foreach (var p in CalibrationPoints)
                {
                    p.Index = index++;
                }
            }
        }

        private CalibrationDataVM()
        {
            CalibrationPoints = new ObservableCollection<CalibrationDataPointVM>();
        }

        public CalibrationDataVM(IdsPack pack) : this()
        {
            IdsPack = pack;
            LiquidType = pack.LiquidType;
        }

        public CalibrationDataVM(LiquidType liquidType) : this()
        {
            LiquidType = liquidType;
        }
    }
}
} if (TextView.Options.ShowEndOfLine && textSourceCharacterIndex == VisualLine.VisualLength) { return CreateTextRunForNewLine(); } return new TextEndOfParagraph(1); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } } TextRun CreateTextRunForNewLine() { string newlineText = ""; DocumentLine lastDocumentLine = VisualLine.LastDocumentLine; if (lastDocumentLine.DelimiterLength == 2) { newlineText = "¶"; } else if (lastDocumentLine.DelimiterLength == 1) { char newlineChar = Document.GetCharAt(lastDocumentLine.Offset + lastDocumentLine.Length); if (newlineChar == '\r') newlineText = "\\r"; else if (newlineChar == '\n') newlineText = "\\n"; else newlineText = "?"; } return new FormattedTextRun(new FormattedTextElement(TextView.cachedElements.GetTextForNonPrintableCharacter(newlineText, this), 0), GlobalTextRunProperties); } public override TextSpan<CultureSpecificCharacterBufferRange> GetPrecedingText(int textSourceCharacterIndexLimit) { try { foreach (VisualLineElement element in VisualLine.Elements) { if (textSourceCharacterIndexLimit > element.VisualColumn && textSourceCharacterIndexLimit <= element.VisualColumn + element.VisualLength) { TextSpan<CultureSpecificCharacterBufferRange> span = element.GetPrecedingText(textSourceCharacterIndexLimit, this); if (span == null) break; int relativeOffset = textSourceCharacterIndexLimit - element.VisualColumn; if (span.Length > relativeOffset) throw new ArgumentException("The returned TextSpan is too long.", element.GetType().Name + ".GetPrecedingText"); return span; } } CharacterBufferRange empty = CharacterBufferRange.Empty; return new TextSpan<CultureSpecificCharacterBufferRange>(empty.Length, new CultureSpecificCharacterBufferRange(null, empty)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } } public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(int textSourceCharacterIndex) { throw new NotSupportedException(); } string cachedString; int cachedStringOffset; public StringSegment GetText(int offset, int length) { if (cachedString != null) { if (offset >= cachedStringOffset && offset + length <= cachedStringOffset + cachedString.Length) { return new StringSegment(cachedString, offset - cachedStringOffset, length); } } cachedStringOffset = offset; return new StringSegment(cachedString = this.Document.GetText(offset, length)); } } }