Imports Interfaces = DWSIM.Interfaces Imports DWSIM.Interfaces Imports DWSIM.Interfaces.Enums.GraphicObjects Namespace GraphicObjects Public Class TextGraphic Inherits GraphicObject #Region "Constructors" Public Sub New() Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Text Me.Height = 20 Me.Width = 50 End Sub Public Sub New(ByVal graphicPosition As SKPoint, ByVal text As String) Me.New() Me.SetPosition(graphicPosition) Me.Text = text End Sub Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal text As String) Me.New(New SKPoint(posX, posY), text) End Sub #End Region Public Property Text As String = "TEXT (double-click to edit)" Public Property Size As Double = 14.0# Public Property Color As SKColor = SKColors.Black Public Overrides Sub Draw(ByVal g As Object) Dim canvas As SKCanvas = DirectCast(g, SKCanvas) Dim tpaint As New SKPaint() If DrawMode = 0 Then With tpaint .TextSize = Size .IsAntialias = GlobalSettings.Settings.DrawingAntiAlias .Color = If(GlobalSettings.Settings.DarkMode, SKColors.LightSteelBlue, Color) .IsStroke = False .Typeface = GetFont() End With Else With tpaint .TextSize = Size .IsAntialias = GlobalSettings.Settings.DrawingAntiAlias .Color = SKColors.Black .IsStroke = False .Typeface = GetFont() End With End If Dim newtext = ReplaceVars(Text) Dim lines = newtext.Split(vbLf) Dim newy As Integer = Y Try Height = 0 Width = 0 For Each l As String In lines Dim trect As New SKRect(0, 0, 2, 2) tpaint.GetTextPath(l, 0, 0).GetBounds(trect) newy += trect.Height + 2 Height += trect.Height + 2 Width = Math.Max(Width, trect.Width) canvas.DrawText(l, X, newy, tpaint) Next Catch ex As Exception Dim trect As New SKRect(0, 0, 2, 2) tpaint.GetTextPath(Text.Replace("\n", vbCrLf), 0, 0).GetBounds(trect) Height = trect.Height Width = trect.Width canvas.DrawText(Text, X, Y + MeasureString(newtext, tpaint).Height, tpaint) End Try End Sub Private Function ReplaceVars(oldtext As String) As String Dim newtext As String = oldtext Dim i As Integer = 0 If Flowsheet IsNot Nothing Then If Text.Contains("{") And Text.Contains("}") Then For i = 1 To Flowsheet.WatchItems.Count Dim objID = Flowsheet.WatchItems(i - 1).ObjID Dim propID = Flowsheet.WatchItems(i - 1).PropID If Flowsheet.SimulationObjects.ContainsKey(objID) Then Dim units = Flowsheet.SimulationObjects(objID).GetPropertyUnit(propID) Dim name = Flowsheet.GetTranslatedString(propID) newtext = newtext.Replace("{" + i.ToString() + ":N}", name) newtext = newtext.Replace("{" + i.ToString() + ":U}", units) Dim value = Flowsheet.SimulationObjects(objID).GetPropertyValue(propID).ToString() If Double.TryParse(value, New Double) Then Dim dval = Double.Parse(value).ToString(Flowsheet.FlowsheetOptions.NumberFormat) newtext = newtext.Replace("{" + i.ToString() + ":V}", dval) Else newtext = newtext.Replace("{" + i.ToString() + ":V}", value) End If End If Next End If End If Return newtext End Function End Class End Namespace