File size: 3,295 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
'    Copyright 2008 Daniel Wagner O. de Medeiros
'
'    This file is part of DWSIM.
'
'    DWSIM is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.
'
'    DWSIM is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.
'
'    You should have received a copy of the GNU General Public License
'    along with DWSIM.  If not, see <http://www.gnu.org/licenses/>.
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization

Namespace Spreadsheet

    Public Enum VarType
        Read = 0
        Write = 1
        Expression = 2
        None = 3
        Unit = 4
    End Enum

    <System.Serializable()> Public Class SpreadsheetCellParameters

        Implements ICloneable, Interfaces.ICustomXMLSerialization

        Public CellType As VarType = VarType.Expression
        Public RelativeTolerance As Double = 0.01
        Public ObjectID As String = ""
        Public PropID As String = ""
        Public PropUnit As String = ""
        Public Expression As String = ""
        Public CurrVal As String = ""
        Public PrevVal As String = ""
        Public CalcOrder As Integer = 0
        Public References As List(Of String)
        Public ToolTipText As String = ""
        <Xml.Serialization.XmlIgnore> Public CellString As String = ""
        Public RawValue As Double = 0.0#

        Sub New()
            References = New List(Of String)
        End Sub

        Public Function Clone() As Object Implements System.ICloneable.Clone

            Return ObjectCopy(Me)

        End Function

        Function ObjectCopy(ByVal obj As Object) As Object

            Dim objMemStream As New MemoryStream(50000)
            Dim objBinaryFormatter As New BinaryFormatter(Nothing, New StreamingContext(StreamingContextStates.Clone))

            objBinaryFormatter.Serialize(objMemStream, obj)
            objMemStream.Seek(0, SeekOrigin.Begin)
            ObjectCopy = objBinaryFormatter.Deserialize(objMemStream)
            objMemStream.Close()

        End Function

        Public Function LoadData(data As System.Collections.Generic.List(Of System.Xml.Linq.XElement)) As Boolean Implements Interfaces.ICustomXMLSerialization.LoadData
            XMLSerializer.XMLSerializer.Deserialize(Me, data, True)
            ToolTipText = Xml.XmlConvert.DecodeName(ToolTipText)
            Return True
        End Function

        Public Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement) Implements Interfaces.ICustomXMLSerialization.SaveData
            ToolTipText = Xml.XmlConvert.EncodeName(ToolTipText)
            If ToolTipText.Length > 65536 Then ToolTipText = Xml.XmlConvert.EncodeName("")
            If Expression <> "" Then
                Return XMLSerializer.XMLSerializer.Serialize(Me, True)
            Else
                Return New List(Of XElement)
            End If
        End Function
    End Class

End Namespace