File size: 16,112 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
' Table Graphic Object
' 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.Linq
Imports DWSIM.Interfaces
Namespace GraphicObjects.Tables
Public Class TableGraphic
Inherits ShapeGraphic
Implements IDisposable
Public Enum SortMode
AsAdded = 0
NameAsc = 1
NameDesc = 2
FirstParentThenNameAsc = 3
FirstParentThenNameDesc = 4
End Enum
Public Property SortingMode As SortMode = SortMode.AsAdded
Public Property VisibleProperties As New Dictionary(Of String, List(Of String))
Public Property Padding As Integer = 4
Public Property TextColor As SKColor = SKColors.Black
Public Property BorderColor As SKColor = SKColors.Black
Public Property TextColorDark As SKColor = SKColors.WhiteSmoke
Public Property BorderColorDark As SKColor = SKColors.WhiteSmoke
Public Property HeaderText As String = "PROPERTIES TABLE"
Public Property ClipboardData As String = ""
<Xml.Serialization.XmlIgnore> Public Property Flowsheet As IFlowsheet
Public Overrides Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement)
Dim elements As System.Collections.Generic.List(Of System.Xml.Linq.XElement) = MyBase.SaveData()
elements.Add(New XElement("VisibleProperties"))
For Each item In VisibleProperties
Dim xel2 = New XElement("Object", New XAttribute("Value", item.Key))
elements(elements.Count - 1).Add(xel2)
For Each item2 In item.Value
xel2.Add(New XElement("PropertyID", New XAttribute("Value", item2)))
Next
Next
Return elements
End Function
Public Overrides Function LoadData(data As System.Collections.Generic.List(Of System.Xml.Linq.XElement)) As Boolean
Dim el As XElement = (From xel As XElement In data Select xel Where xel.Name = "VisibleProperties").SingleOrDefault
If Not el Is Nothing Then
VisibleProperties.Clear()
For Each xel2 As XElement In el.Elements
VisibleProperties.Add(xel2.@Value, New List(Of String))
For Each xel3 In xel2.Elements
VisibleProperties(xel2.@Value).Add(xel3.@Value)
Next
Next
End If
Return MyBase.LoadData(data)
End Function
Public Sub New()
Me.ObjectType = Enums.GraphicObjects.ObjectType.GO_Table
End Sub
Public Sub New(ByVal graphicPosition As SKPoint)
Me.New()
Me.SetPosition(graphicPosition)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer)
Me.New(New SKPoint(posX, posY))
End Sub
Dim tpaint, tpaint2, bpaint As SKPaint
Private disposedValue As Boolean
Public Overrides Sub Draw(ByVal g As Object)
Dim canvas As SKCanvas = DirectCast(g, SKCanvas)
If tpaint Is Nothing Then tpaint = New SKPaint()
If tpaint2 Is Nothing Then tpaint2 = New SKPaint()
If bpaint Is Nothing Then bpaint = New SKPaint()
If DrawMode = 0 Then
With tpaint
.TextSize = FontSize
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
If GlobalSettings.Settings.DarkMode Then
.Color = TextColorDark
Else
.Color = TextColor
End If
.IsStroke = False
.Typeface = GetFont()
.FakeBoldText = True
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
With tpaint2
.TextSize = FontSize
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
If GlobalSettings.Settings.DarkMode Then
.Color = TextColorDark
Else
.Color = TextColor
End If
.IsStroke = False
.Typeface = GetFont()
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
With bpaint
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
If GlobalSettings.Settings.DarkMode Then
.Color = BorderColorDark
Else
.Color = BorderColor
End If
.IsStroke = True
.StrokeWidth = 1
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
Else
With tpaint
.TextSize = FontSize
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.Color = SKColors.Black
.IsStroke = False
.Typeface = GetFont()
.FakeBoldText = True
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
With tpaint2
.TextSize = FontSize
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.Color = SKColors.Black
.IsStroke = False
.Typeface = GetFont()
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
With bpaint
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.Color = SKColors.Black
.IsStroke = True
.StrokeWidth = 1
.HintingLevel = SKPaintHinting.Normal
.SubpixelText = True
End With
End If
Dim maxL0, maxL1, maxL2, maxL3, count As Integer
Dim maxH As Integer
'determinar comprimento das colunas e altura das linhas
maxL0 = 0
maxL1 = 0
maxL2 = 0
maxL3 = 0
maxH = 0
count = 1
Dim size As SKSize
Dim propstring, propval, propunit As String, pval0 As Object
Dim toremove As New List(Of String)
For Each item In VisibleProperties
If Not Me.Flowsheet.SimulationObjects.ContainsKey(item.Key) Then toremove.Add(item.Key)
Next
For Each item In toremove
VisibleProperties.Remove(item)
Next
toremove.Clear()
toremove = Nothing
Dim items As New List(Of Tuple(Of String, String))
Select Case SortingMode
Case SortMode.AsAdded
For Each item In VisibleProperties
For Each value In item.Value
items.Add(New Tuple(Of String, String)(item.Key, value))
Next
Next
Case SortMode.NameAsc
For Each item In VisibleProperties
For Each value In item.Value
items.Add(New Tuple(Of String, String)(item.Key, value))
Next
Next
items = items.OrderBy(Function(i) Flowsheet.GetTranslatedString(i.Item2)).ToList()
Case SortMode.NameDesc
For Each item In VisibleProperties
For Each value In item.Value
items.Add(New Tuple(Of String, String)(item.Key, value))
Next
Next
items = items.OrderByDescending(Function(i) Flowsheet.GetTranslatedString(i.Item2)).ToList()
Case SortMode.FirstParentThenNameAsc
For Each item In VisibleProperties
Dim values = item.Value.OrderBy(Function(v) Flowsheet.GetTranslatedString(v))
For Each v In values
items.Add(New Tuple(Of String, String)(item.Key, v))
Next
Next
items = items.OrderBy(Function(i) Flowsheet.SimulationObjects(i.Item1).GraphicObject.Tag).ToList()
Case SortMode.FirstParentThenNameDesc
For Each item In VisibleProperties
Dim values = item.Value.OrderByDescending(Function(v) Flowsheet.GetTranslatedString(v))
For Each v In values
items.Add(New Tuple(Of String, String)(item.Key, v))
Next
Next
items = items.OrderByDescending(Function(i) Flowsheet.SimulationObjects(i.Item1).GraphicObject.Tag).ToList()
End Select
If items.Count > 0 Then
For Each item In items
size = MeasureString(Me.Flowsheet.SimulationObjects(item.Item1).GraphicObject.Tag, tpaint)
If size.Width > maxL0 Then maxL0 = size.Width
If size.Height > maxH Then maxH = size.Height
propstring = Me.Flowsheet.GetTranslatedString(item.Item2)
pval0 = Me.Flowsheet.SimulationObjects(item.Item1).GetPropertyValue(item.Item2, Me.Flowsheet.FlowsheetOptions.SelectedUnitSystem)
If TypeOf pval0 Is Double Then
propval = Convert.ToDouble(pval0).ToString(Me.Flowsheet.FlowsheetOptions.NumberFormat)
Else
If pval0 IsNot Nothing Then
propval = pval0.ToString
Else
propval = ""
End If
End If
propunit = Me.Flowsheet.SimulationObjects(item.Item1).GetPropertyUnit(item.Item2, Me.Flowsheet.FlowsheetOptions.SelectedUnitSystem)
size = MeasureString(Flowsheet.GetTranslatedString(propstring), tpaint)
If size.Width > maxL1 Then maxL1 = size.Width
If size.Height > maxH Then maxH = size.Height
size = MeasureString(propval, tpaint2)
If size.Width > maxL2 Then maxL2 = size.Width
If size.Height > maxH Then maxH = size.Height
size = MeasureString(propunit, tpaint)
If size.Width > maxL3 Then maxL3 = size.Width
If size.Height > maxH Then maxH = size.Height
count += 1
Next
size = MeasureString(Me.HeaderText, tpaint)
If size.Width > maxL0 + maxL1 + maxL2 + maxL3 Then maxL1 = size.Width - maxL0 - maxL2 - maxL3
If size.Height > maxH Then maxH = size.Height
Me.Height = (count) * (maxH + 2 * Me.Padding)
Me.Width = 10 * Me.Padding + maxL0 + maxL1 + maxL2 + maxL3
maxL0 = maxL0 + 2 * Padding
maxL1 = maxL1 + 2 * Padding
maxL2 = maxL2 + 2 * Padding
maxL3 = maxL3 + 2 * Padding
maxH = maxH + 2 * Padding
'desenhar textos e retangulos
size = MeasureString("MEASURE", tpaint)
ClipboardData = HeaderText + vbCrLf
canvas.DrawText(Me.HeaderText, X + Padding, Y + Padding + size.Height, tpaint)
Dim n As Integer = 1
For Each item In items
canvas.DrawText(Me.Flowsheet.SimulationObjects(item.Item1).GraphicObject.Tag, X + Padding, Y + n * maxH + Padding + size.Height, tpaint)
propstring = Me.Flowsheet.GetTranslatedString(item.Item2)
Try
pval0 = Me.Flowsheet.SimulationObjects(item.Item1).GetPropertyValue(item.Item2, Me.Flowsheet.FlowsheetOptions.SelectedUnitSystem)
Catch ex As Exception
pval0 = ""
End Try
If TypeOf pval0 Is Double Then
propval = Convert.ToDouble(pval0).ToString(Me.Flowsheet.FlowsheetOptions.NumberFormat)
Else
If pval0 IsNot Nothing Then
propval = pval0.ToString
Else
propval = ""
End If
End If
propunit = Me.Flowsheet.SimulationObjects(item.Item1).GetPropertyUnit(item.Item2, Me.Flowsheet.FlowsheetOptions.SelectedUnitSystem)
canvas.DrawText(propstring, X + maxL0 + Padding, Y + n * maxH + Padding + size.Height, tpaint)
canvas.DrawText(propval, (maxL2 - MeasureString(propval, tpaint).Width) + X + maxL0 + maxL1, Y + n * maxH + Padding + size.Height, tpaint2)
canvas.DrawText(propunit, X + maxL0 + maxL1 + maxL2 + 2 * Padding, Y + n * maxH + Padding + size.Height, tpaint)
canvas.DrawLine(X, Y + n * maxH, X + Width, Y + n * maxH, bpaint)
ClipboardData += Me.Flowsheet.SimulationObjects(item.Item1).GraphicObject.Tag + vbTab + propstring + vbTab + propval + vbTab + propunit + vbCrLf
n += 1
Next
canvas.DrawRect(New SKRect(X, Y, X + Width, Y + Height), bpaint)
canvas.DrawLine(X + maxL0, Y + maxH, X + maxL0, Y + Height, bpaint)
canvas.DrawLine(X + maxL0 + maxL1, Y + maxH, X + maxL0 + maxL1, Y + Height, bpaint)
canvas.DrawLine(X + maxL0 + maxL1 + maxL2 + Padding, Y + maxH, X + maxL0 + maxL1 + maxL2 + Padding, Y + Height, bpaint)
Else
size = MeasureString(Flowsheet.GetTranslatedString("DoubleClickToEdit"), tpaint)
Me.Width = 20 + size.Width
Me.Height = 80 + size.Height
canvas.DrawText(Flowsheet.GetTranslatedString("DoubleClickToEdit"), X + 10, Y + 40, tpaint)
canvas.DrawRect(New SKRect(X, Y, X + Width, Y + Height), bpaint)
End If
End Sub
Protected Overridable Sub Dispose(disposing As Boolean)
If Not disposedValue Then
tpaint?.Dispose()
tpaint2?.Dispose()
bpaint?.Dispose()
disposedValue = True
End If
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(disposing:=True)
GC.SuppressFinalize(Me)
End Sub
End Class
End Namespace
|