File size: 11,901 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 | Imports DWSIM.Drawing.SkiaSharp.GraphicObjects
Imports DWSIM.Interfaces.Enums.GraphicObjects
Imports DWSIM.DrawingTools.Point
Namespace GraphicObjects.Shapes
Public Class ScriptGraphic
Inherits ShapeGraphic
#Region "Constructors"
Public Sub New()
Me.ObjectType = DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.CustomUO
Me.Description = "Python Script Block"
EmbeddedResourceIconName = "python_script.png"
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
Public Sub New(ByVal graphicPosition As SKPoint, ByVal graphicSize As SKSize)
Me.New(graphicPosition)
Me.SetSize(graphicSize)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As SKSize)
Me.New(New SKPoint(posX, posY), graphicSize)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, ByVal height As Integer)
Me.New(New SKPoint(posX, posY), New SKSize(width, height))
End Sub
#End Region
Public Overrides Sub PositionConnectors()
CreateConnectors(0, 0)
End Sub
Public Overrides Sub CreateConnectors(InCount As Integer, OutCount As Integer)
Dim myIC1 As New ConnectionPoint
myIC1.Position = New Point(X, Y)
myIC1.Type = ConType.ConIn
myIC1.ConnectorName = "Inlet Port #1"
Dim myIC2 As New ConnectionPoint
myIC2.Position = New Point(X, Y + 1 * 0.13 * Height)
myIC2.Type = ConType.ConIn
myIC2.ConnectorName = "Inlet Port #2"
Dim myIC3 As New ConnectionPoint
myIC3.Position = New Point(X, Y + 2 * 0.13 * Height)
myIC3.Type = ConType.ConIn
myIC3.ConnectorName = "Inlet Port #3"
Dim myIC4 As New ConnectionPoint
myIC4.Position = New Point(X, Y)
myIC4.Type = ConType.ConEn
myIC4.Direction = ConDir.Up
myIC4.ConnectorName = "Inlet Energy Port"
Dim myIC5 As New ConnectionPoint
myIC5.Position = New Point(X, Y + 3 * 0.13 * Height)
myIC5.Type = ConType.ConIn
myIC5.ConnectorName = "Inlet Port #4"
Dim myIC6 As New ConnectionPoint
myIC6.Position = New Point(X, Y + 4 * 0.13 * Height)
myIC6.Type = ConType.ConIn
myIC6.ConnectorName = "Inlet Port #5"
Dim myIC7 As New ConnectionPoint
myIC7.Position = New Point(X, Y + 5 * 0.13 * Height)
myIC7.Type = ConType.ConIn
myIC7.ConnectorName = "Inlet Port #6"
Dim myOC1 As New ConnectionPoint
myOC1.Position = New Point(X + Width, Y)
myOC1.Type = ConType.ConOut
myOC1.ConnectorName = "Outlet Port #1"
Dim myOC2 As New ConnectionPoint
myOC2.Position = New Point(X + Width, Y + 1 * 0.13 * Height)
myOC2.Type = ConType.ConOut
myOC2.ConnectorName = "Outlet Port #2"
Dim myOC3 As New ConnectionPoint
myOC3.Position = New Point(X + Width, Y + 2 * 0.13 * Height)
myOC3.Type = ConType.ConOut
myOC3.ConnectorName = "Outlet Port #3"
Dim myOC4 As New ConnectionPoint
myOC4.Position = New Point(X + Width, Y + Height)
myOC4.Type = ConType.ConEn
myOC4.Direction = ConDir.Down
myOC4.ConnectorName = "Outlet Energy Port"
Dim myOC5 As New ConnectionPoint
myOC5.Position = New Point(X + Width, Y + 3 * 0.13 * Height)
myOC5.Type = ConType.ConIn
myOC5.ConnectorName = "Outlet Port #4"
Dim myOC6 As New ConnectionPoint
myOC6.Position = New Point(X + Width, Y + 4 * 0.13 * Height)
myOC6.Type = ConType.ConIn
myOC6.ConnectorName = "Outlet Port #5"
Dim myOC7 As New ConnectionPoint
myOC7.Position = New Point(X + Width, Y + 5 * 0.13 * Height)
myOC7.Type = ConType.ConIn
myOC7.ConnectorName = "Outlet Port #6"
With InputConnectors
If .Count <> 0 Then
If .Count = 3 Then
.Add(myIC4)
ElseIf .Count = 4 Then
.Add(myIC5)
.Add(myIC6)
.Add(myIC7)
Else
.Item(0).Position = New Point(X, Y)
.Item(1).Position = New Point(X, Y + 1 * 0.13 * Height)
.Item(2).Position = New Point(X, Y + 2 * 0.13 * Height)
.Item(3).Position = New Point(X, Y + Height)
.Item(4).Position = New Point(X, Y + 3 * 0.13 * Height)
.Item(5).Position = New Point(X, Y + 4 * 0.13 * Height)
.Item(6).Position = New Point(X, Y + 5 * 0.13 * Height)
End If
Else
.Add(myIC1)
.Add(myIC2)
.Add(myIC3)
.Add(myIC4)
.Add(myIC5)
.Add(myIC6)
.Add(myIC7)
End If
End With
With OutputConnectors
If .Count <> 0 Then
If .Count = 3 Then
.Add(myOC4)
ElseIf .Count = 4 Then
.Add(myOC5)
.Add(myOC6)
.Add(myOC7)
Else
.Item(0).Position = New Point(X + Width, Y)
.Item(1).Position = New Point(X + Width, Y + 1 * 0.13 * Height)
.Item(2).Position = New Point(X + Width, Y + 2 * 0.13 * Height)
.Item(3).Position = New Point(X + Width, Y + Height)
.Item(4).Position = New Point(X + Width, Y + 3 * 0.13 * Height)
.Item(5).Position = New Point(X + Width, Y + 4 * 0.13 * Height)
.Item(6).Position = New Point(X + Width, Y + 5 * 0.13 * Height)
End If
Else
.Add(myOC1)
.Add(myOC2)
.Add(myOC3)
.Add(myOC4)
.Add(myOC5)
.Add(myOC6)
.Add(myOC7)
End If
End With
Me.EnergyConnector.Active = False
End Sub
Public Overrides Sub Draw(ByVal g As Object)
Dim canvas As SKCanvas = DirectCast(g, SKCanvas)
CreateConnectors(0, 0)
UpdateStatus()
MyBase.Draw(g)
If Owner IsNot Nothing AndAlso Owner.UseEmbeddedImage = True AndAlso Owner.EmbeddedImageData <> "" Then
Dim p As New SKPaint
With p
p.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
p.FilterQuality = SKFilterQuality.High
End With
Using image As SKImage = EmbeddedImageGraphic.Base64ToImage(Owner.EmbeddedImageData)
canvas.DrawImage(image, New SKRect(X, Y, X + Width, Y + Height), p)
End Using
Else
Select Case DrawMode
Case 0
'default
Dim myPen2 As New SKPaint()
With myPen2
.Color = LineColor
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.IsStroke = True
.StrokeWidth = LineWidth
End With
Dim rect1 As New SKRect(X + 0.1 * Width, Y, X + 0.9 * Width, Y + Height)
Dim gradPen As New SKPaint()
With gradPen
.Color = LineColor.WithAlpha(50)
.StrokeWidth = LineWidth
.IsStroke = False
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
End With
canvas.DrawRoundRect(rect1, 2, 2, gradPen)
canvas.DrawRoundRect(rect1, 2, 2, myPen2)
Dim tpaint As New SKPaint()
With tpaint
.TextSize = 10.0#
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.Color = LineColor
.IsStroke = False
.Typeface = BoldTypeFace
End With
Dim trect As New SKRect(0, 0, 2, 2)
tpaint.GetTextPath("PS", 0, 0).GetBounds(trect)
Dim ax, ay As Integer
ax = Me.X + (Me.Width - (trect.Right - trect.Left)) / 2
ay = Me.Y + (Me.Height - (trect.Top - trect.Bottom)) / 2
Using New SKAutoCanvasRestore(canvas)
StraightCanvas(canvas)
canvas.DrawText("PS", ax, ay, tpaint)
End Using
Case 1
'b/w
Dim myPen2 As New SKPaint()
With myPen2
.Color = SKColors.Black
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.IsStroke = True
.StrokeWidth = LineWidth
End With
Dim rect1 As New SKRect(X + 0.1 * Width, Y, X + 0.9 * Width, Y + Height)
canvas.DrawRoundRect(rect1, 2, 2, myPen2)
Dim tpaint As New SKPaint()
With tpaint
.TextSize = 10.0#
.IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
.Color = SKColors.Black
.IsStroke = False
.Typeface = BoldTypeFace
End With
Dim trect As New SKRect(0, 0, 2, 2)
tpaint.GetTextPath("PS", 0, 0).GetBounds(trect)
Dim ax, ay As Integer
ax = Me.X + (Me.Width - (trect.Right - trect.Left)) / 2
ay = Me.Y + (Me.Height - (trect.Top - trect.Bottom)) / 2
Using New SKAutoCanvasRestore(canvas)
StraightCanvas(canvas)
canvas.DrawText("PS", ax, ay, tpaint)
End Using
Case 2
DrawIcon(canvas)
Case 3
'Temperature Gradients
Case 4
'Pressure Gradients
Case 5
'Temperature/Pressure Gradients
End Select
End If
End Sub
End Class
End Namespace |