Files
2025-08-06 19:08:51 +02:00

627 lines
16 KiB
VB.net

Imports EgtWPFLib5
Imports System.Collections.ObjectModel
Imports Newtonsoft.Json
Imports EgtUILib.EgtInterface
Imports Newtonsoft.Json.Serialization
Imports System.Runtime.InteropServices
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json.Converters
Imports System.Net.Http
<JsonObject(MemberSerialization.OptIn)>
Public Class JsonWindow
Private m_sProfilePath As String
<JsonProperty>
Public Property ProfilePath As String
Get
Return m_sProfilePath
End Get
Set(value As String)
m_sProfilePath = value
End Set
End Property
Private m_AreaList As New List(Of JsonArea)
<JsonProperty>
Public Property AreaList As List(Of JsonArea)
Get
Return m_AreaList
End Get
Set(value As List(Of JsonArea))
m_AreaList = value
End Set
End Property
Sub New(ProfilePath As String)
m_sProfilePath = ProfilePath
End Sub
Friend Function Deserialize() As Window
Dim Window As New Window() With {.sProfilePath = m_sProfilePath}
For Each Area In AreaList
Window.AreaList.Add(Area.Deserialize(Nothing))
Next
Return Window
End Function
End Class
Public Class JsonArea
Private m_AreaList As New List(Of JsonArea)
<JsonProperty>
Public Property AreaList As List(Of JsonArea)
Get
Return m_AreaList
End Get
Set(value As List(Of JsonArea))
m_AreaList = value
End Set
End Property
Private m_AreaType As AreaTypes
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property AreaType As AreaTypes
Get
Return m_AreaType
End Get
Set(value As AreaTypes)
m_AreaType = value
End Set
End Property
Sub New(AreaType As AreaTypes)
m_AreaType = AreaType
End Sub
Friend Overridable Function Deserialize(ParentArea As Area) As Area
Return Nothing
End Function
End Class
Public Class JsonFrame
Inherits JsonArea
Private m_Shape As Shapes
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property Shape As Shapes
Get
Return m_Shape
End Get
Set(value As Shapes)
m_Shape = value
End Set
End Property
Private m_DimensionList As New List(Of JsonFrameDimension)
<JsonProperty>
Public ReadOnly Property DimensionList As List(Of JsonFrameDimension)
Get
Return m_DimensionList
End Get
End Property
Private m_JointList As New List(Of JsonJoint)
<JsonProperty>
Public Property JointList As List(Of JsonJoint)
Get
Return m_JointList
End Get
Set(value As List(Of JsonJoint))
m_JointList = value
End Set
End Property
Private m_bBottomRail As Boolean
<JsonProperty>
Public Property BottomRail As Boolean
Get
Return m_bBottomRail
End Get
Set(value As Boolean)
m_bBottomRail = value
End Set
End Property
Private m_nBottomRailQty As Integer = 0
<JsonProperty>
Public Property BottomRailQty As Integer
Get
Return m_nBottomRailQty
End Get
Set(value As Integer)
m_nBottomRailQty = value
End Set
End Property
Sub New()
MyBase.New(AreaTypes.FRAME)
End Sub
Sub New(Shape As Shapes, BottomRail As Boolean, BottomRailQty As Integer)
MyBase.New(AreaTypes.FRAME)
m_Shape = Shape
m_bBottomRail = BottomRail
m_nBottomRailQty = BottomRailQty
End Sub
Friend Overrides Function Deserialize(ParentArea As Area) As Area
Dim Frame As New Frame(Nothing)
Frame.SetAreaType(AreaTypes.FRAME)
Frame.SetSelShape(m_Shape)
Frame.SetBottomRail(m_bBottomRail)
Frame.SetBottomRailQty(m_nBottomRailQty)
Frame.AppliedDone()
For DimensionIndex = 0 To m_DimensionList.Count - 1
Frame.DimensionList(DimensionIndex).dValue = m_DimensionList(DimensionIndex).dValue
Next
For JointIndex = 0 To m_JointList.Count - 1
Frame.JointList(JointIndex).SetSelJointType(m_JointList(JointIndex).JointType)
Next
For Each Area In AreaList
Frame.AreaList.Add(Area.Deserialize(Frame))
Next
Return Frame
End Function
End Class
Public Class JsonSash
Inherits JsonArea
Private m_bIsSashVertical As Boolean
<JsonProperty>
Public Property bIsSashVertical As Boolean
Get
Return m_bIsSashVertical
End Get
Set(value As Boolean)
m_bIsSashVertical = value
End Set
End Property
Private m_SashList As New List(Of JsonSashDimension)
<JsonProperty>
Public Property SashList As List(Of JsonSashDimension)
Get
Return m_SashList
End Get
Set(value As List(Of JsonSashDimension))
m_SashList = value
End Set
End Property
Private m_SashType As SashTypes
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property SashType As SashTypes
Get
Return m_SashType
End Get
Set(value As SashTypes)
m_SashType = value
End Set
End Property
Private m_JointList As New List(Of JsonJoint)
<JsonProperty>
Public Property JointList As List(Of JsonJoint)
Get
Return m_JointList
End Get
Set(value As List(Of JsonJoint))
m_JointList = value
End Set
End Property
Private m_bBottomRail As Boolean
<JsonProperty>
Public Property BottomRail As Boolean
Get
Return m_bBottomRail
End Get
Set(value As Boolean)
m_bBottomRail = value
End Set
End Property
Private m_nBottomRailQty As Integer = 0
<JsonProperty>
Public Property BottomRailQty As Integer
Get
Return m_nBottomRailQty
End Get
Set(value As Integer)
m_nBottomRailQty = value
End Set
End Property
Private m_Hardware As String
<JsonProperty>
Public Property Hardware As String
Get
Return m_Hardware
End Get
Set(value As String)
m_Hardware = value
End Set
End Property
Sub New()
MyBase.New(AreaTypes.SASH)
End Sub
Sub New(bIsSashVertical As Boolean, SashType As SashTypes, BottomRail As Boolean, BottomRailQty As Integer, Hardware As String)
MyBase.New(AreaTypes.SASH)
m_bIsSashVertical = bIsSashVertical
m_SashType = SashType
m_bBottomRail = BottomRail
m_nBottomRailQty = BottomRailQty
m_Hardware = Hardware
End Sub
Friend Overrides Function Deserialize(ParentArea As Area) As Area
Dim Sash As Sash = New Sash(ParentArea)
Sash.SetAreaType(AreaTypes.SASH)
Sash.SetSashQty(m_SashList.Count)
Sash.SetIsSashVertical(m_bIsSashVertical)
Sash.SetBottomRail(m_bBottomRail)
Sash.SetBottomRailQty(m_nBottomRailQty)
Sash.AppliedDone()
For SashIndex = 0 To m_SashList.Count - 1
Sash.SashList(SashIndex).SetOpeningType(m_SashList(SashIndex).OpeningType)
Sash.SashList(SashIndex).SetHasHandle(m_SashList(SashIndex).bHasHandle)
Sash.SashList(SashIndex).SetDimension(m_SashList(SashIndex).dDimension)
Next
For Each Joint In m_JointList
Sash.JointList.Add(Joint.Deserialize())
Next
Sash.RefreshHardwareList()
Sash.SetSelHardwareFromId(Hardware)
For Each Area In AreaList
Sash.AreaList.Add(Area.Deserialize(Sash))
Next
Return Sash
End Function
End Class
Public Class JsonSplit
Inherits JsonArea
Private m_SplitShape As SplitShapes
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Friend Property SplitShape As SplitShapes
Get
Return m_SplitShape
End Get
Set(value As SplitShapes)
m_SplitShape = value
End Set
End Property
Private m_SplitPositionList As New List(Of JsonSplitDimension)
<JsonProperty>
Public Property SplitPositionList As List(Of JsonSplitDimension)
Get
Return m_SplitPositionList
End Get
Set(value As List(Of JsonSplitDimension))
m_SplitPositionList = value
End Set
End Property
Sub New()
MyBase.New(AreaTypes.SPLIT)
End Sub
Sub New(SplitShape As SplitShapes)
MyBase.New(AreaTypes.SPLIT)
m_SplitShape = SplitShape
End Sub
Friend Overrides Function Deserialize(ParentArea As Area) As Area
Dim Split As New Split(ParentArea)
Split.SetAreaType(AreaTypes.SPLIT)
Split.SetSplitShape(m_SplitShape, True)
Split.SetSplitQty(m_SplitPositionList.Count - 1, True)
Split.AppliedDone()
For SplitIndex = 0 To m_SplitPositionList.Count - 1
Split.SplitPositionList(SplitIndex).SetIsRelative(m_SplitPositionList(SplitIndex).bIsRelative)
Split.SplitPositionList(SplitIndex).SetDimension(m_SplitPositionList(SplitIndex).dDimension)
Next
For Each Area In AreaList
Split.AreaList.Add(Area.Deserialize(Split))
Next
Return Split
End Function
End Class
Public Class JsonSplitted
Inherits JsonArea
Sub New()
MyBase.New(AreaTypes.SPLITTED)
End Sub
Friend Overrides Function Deserialize(ParentArea As Area) As Area
Dim Split As New Splitted(ParentArea)
Split.SetAreaType(AreaTypes.SPLITTED)
Split.AppliedDone()
For Each Area In AreaList
Split.AreaList.Add(Area.Deserialize(Split))
Next
Return Split
End Function
End Class
Public Class JsonFill
Inherits JsonArea
Private m_FillType As FillTypes
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property FillType As FillTypes
Get
Return m_FillType
End Get
Set(value As FillTypes)
m_FillType = value
End Set
End Property
Sub New()
MyBase.New(AreaTypes.FILL)
End Sub
Sub New(FillType As FillTypes)
MyBase.New(AreaTypes.FILL)
m_FillType = FillType
End Sub
Friend Overrides Function Deserialize(ParentArea As Area) As Area
Dim Fill As New Fill(ParentArea)
Fill.SetAreaType(AreaTypes.FILL)
Fill.SetFillType(m_FillType)
Fill.AppliedDone()
For Each Area In AreaList
Fill.AreaList.Add(Area.Deserialize(Fill))
Next
Return Fill
End Function
End Class
Public Class JsonJoint
Private m_nIndex As Integer
<JsonProperty>
Public ReadOnly Property nIndex As Integer
Get
Return m_nIndex
End Get
End Property
Private m_JointType As Joints
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property JointType As Joints
Get
Return m_JointType
End Get
Set(value As Joints)
m_JointType = value
End Set
End Property
Sub New(nIndex As Integer, JointType As Joints)
m_nIndex = nIndex
m_JointType = JointType
End Sub
Friend Function Deserialize() As Joint
Dim Joint As New Joint(m_nIndex, m_JointType)
Return Joint
End Function
End Class
Public Class JsonCurve
Private m_CurveType As GDB_TY
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public Property CurveType As GDB_TY
Get
Return m_CurveType
End Get
Set(value As GDB_TY)
m_CurveType = value
End Set
End Property
Private m_ptStart As Point3d
<JsonProperty>
Public Property ptStart As Point3d
Get
Return m_ptStart
End Get
Set(value As Point3d)
m_ptStart = value
End Set
End Property
Private m_ptEnd As Point3d
<JsonProperty>
Public Property ptEnd As Point3d
Get
Return m_ptEnd
End Get
Set(value As Point3d)
m_ptEnd = value
End Set
End Property
End Class
Public Class JsonFrameDimension
Private m_nIndex As Integer
<JsonProperty>
Public ReadOnly Property nIndex As Integer
Get
Return m_nIndex
End Get
End Property
Private m_sName As String
<JsonProperty>
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_dValue As Double
<JsonProperty>
Public Property dValue As Double
Get
Return m_dValue
End Get
Set(value As Double)
m_dValue = value
End Set
End Property
Sub New(nIndex As Integer, sName As String, dValue As Double)
m_nIndex = nIndex
m_sName = sName
m_dValue = dValue
End Sub
End Class
Public Class JsonSashDimension
Private m_OpeningType As Openings
<JsonProperty>
<JsonConverter(GetType(StringEnumConverter))>
Public ReadOnly Property OpeningType As Openings
Get
Return m_OpeningType
End Get
End Property
Private m_bHasHandle As Boolean
<JsonProperty>
Public Property bHasHandle As Boolean
Get
Return m_bHasHandle
End Get
Set(value As Boolean)
m_bHasHandle = value
End Set
End Property
Private m_dDimension As Double
<JsonProperty>
Public Property dDimension As Double
Get
Return m_dDimension
End Get
Set(value As Double)
m_dDimension = value
End Set
End Property
Sub New(OpeningType As Openings, bHasHandle As Boolean, dDimension As Double)
m_OpeningType = OpeningType
m_bHasHandle = bHasHandle
m_dDimension = dDimension
End Sub
End Class
Public Class JsonSplitDimension
Private m_bIsRelative As Boolean = False
<JsonProperty>
Public ReadOnly Property bIsRelative As Boolean
Get
Return m_bIsRelative
End Get
End Property
Private m_dDimension As Double
<JsonProperty>
Public Property dDimension As Double
Get
Return m_dDimension
End Get
Set(value As Double)
m_dDimension = value
End Set
End Property
Sub New(bIsRelative As Boolean, dDimension As Double)
m_bIsRelative = bIsRelative
m_dDimension = dDimension
End Sub
End Class
Public Class PolymorphicJsonConverter
Inherits JsonConverter
Public Overrides Function ReadJson(ByVal reader As JsonReader, ByVal objectType As Type, ByVal existingValue As Object, ByVal serializer As JsonSerializer) As Object
' disambiguo il tipo JsonArea grazie al capo AreaType nelle classi giuste, e le popolo di dati
Dim item As JObject = JObject.Load(reader)
Dim RawType = item("AreaType").Value(Of String)
Dim Type As AreaTypes = AreaTypes.NULL
[Enum].TryParse(Of AreaTypes)(RawType, Type)
Dim JsonArea As JsonArea = Nothing
Select Case Type
Case AreaTypes.FRAME
JsonArea = New JsonFrame()
Case AreaTypes.SASH
JsonArea = New JsonSash()
Case AreaTypes.FILL
JsonArea = New JsonFill()
Case AreaTypes.SPLIT
JsonArea = New JsonSplit()
Case AreaTypes.SPLITTED
JsonArea = New JsonSplitted()
End Select
If Not IsNothing(JsonArea) Then
serializer.Populate(item.CreateReader(), JsonArea)
Return JsonArea
Else Return Nothing
End If
End Function
Public Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal value As Object, ByVal serializer As JsonSerializer)
Throw New NotImplementedException()
'Dim o As JObject = JObject.FromObject(value)
'If TypeOf value Is SubClass1 Then
' o.AddFirst(New JProperty("type", New JValue("SubClass1")))
'ElseIf TypeOf value Is SubClass1 Then
' o.AddFirst(New JProperty("type", New JValue("SubClass2")))
'End If
'o.WriteTo(writer)
End Sub
Public Overrides Function CanConvert(ByVal objectType As Type) As Boolean
' gestisco solo i tipi dericati da JsonArea
Return GetType(JsonArea).IsAssignableFrom(objectType)
End Function
End Class