Skip to content

Commit

Permalink
separate log window from Log in order to allow use of the API without…
Browse files Browse the repository at this point in the history
… requiring a reference to System.Windows.Forms as long as no Wave.App is instantiated
  • Loading branch information
jamaa committed Jan 18, 2024
1 parent 1311bd7 commit 9e4791a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
5 changes: 5 additions & 0 deletions source/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
BlueM.Wave Release Notes
========================

Development
-------------
API-CHANGES:
* Allow using the API for reading time series files without requiring a reference to System.Windows.Forms

Version 2.7.0
-------------
NEW:
Expand Down
38 changes: 25 additions & 13 deletions source/Controllers/WaveController.vb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Friend Class WaveController

Private WithEvents _axisDialog As AxisDialog

Private _logWindow As LogWindow

'Events handled by the AppInstance
Friend Event Properties_Clicked()
Friend Event TimeseriesValues_Clicked()
Expand All @@ -88,6 +90,8 @@ Friend Class WaveController

_axisDialog = New AxisDialog()

_logWindow = New LogWindow()

'Subscribe to view events

AddHandler Me.View.Load, AddressOf View_Load
Expand Down Expand Up @@ -173,9 +177,9 @@ Friend Class WaveController
AddHandler Me.View.Button_NavEnd.Click, AddressOf navigationStartEnd_Click

'status strip events
AddHandler Me.View.ToolStripStatusLabel_Log.Click, AddressOf ShowLog_Click
AddHandler Me.View.ToolStripStatusLabel_Errors.Click, AddressOf ShowLog_Click
AddHandler Me.View.ToolStripStatusLabel_Warnings.Click, AddressOf ShowLog_Click
AddHandler Me.View.ToolStripStatusLabel_Log.Click, AddressOf LogShowWindow
AddHandler Me.View.ToolStripStatusLabel_Errors.Click, AddressOf LogShowWindow
AddHandler Me.View.ToolStripStatusLabel_Warnings.Click, AddressOf LogShowWindow

'axis dialog events
AddHandler _axisDialog.AxisDeleted, AddressOf axisDeleted
Expand Down Expand Up @@ -325,7 +329,7 @@ Friend Class WaveController

'Log zurücksetzen
Call Log.ClearLog()
Call Log.HideLogWindow()
Call LogHideWindow()

'Reset counters
View.ToolStripStatusLabel_Errors.Text = 0
Expand Down Expand Up @@ -886,7 +890,7 @@ Friend Class WaveController
'Ergebnistext in Log schreiben und anzeigen
If (oAnalysis.hasResultText) Then
Call Log.AddLogEntry(Log.levels.info, oAnalysis.getResultText)
Call Log.ShowLogWindow()
Call LogShowWindow()
End If

'Ergebniswerte in Log schreiben
Expand All @@ -895,7 +899,7 @@ Friend Class WaveController
For Each kvp As KeyValuePair(Of String, Double) In oAnalysis.getResultValues
Call Log.AddLogEntry(Log.levels.info, kvp.Key + ": " + Str(kvp.Value))
Next
Call Log.ShowLogWindow()
Call LogShowWindow()
End If

'Display result series in main diagram
Expand Down Expand Up @@ -1518,13 +1522,6 @@ Friend Class WaveController

End Sub

'Log anzeigen
'************
Private Sub ShowLog_Click(sender As System.Object, e As System.EventArgs)
'LogWindow anzeigen
Call Log.ShowLogWindow()
End Sub

''' <summary>
''' Handles KeyDown events
''' Initiates clipboard import if Ctrl+V was pressed
Expand Down Expand Up @@ -2535,6 +2532,21 @@ Friend Class WaveController

End Sub

Private Sub LogShowWindow()
If IsNothing(_logWindow) Then
_logWindow = New LogWindow()
End If
_logWindow.Show()
_logWindow.WindowState = FormWindowState.Normal
_logWindow.BringToFront()
End Sub

Public Sub LogHideWindow()
If Not IsNothing(_logWindow) Then
_logWindow.Hide()
End If
End Sub

''' <summary>
''' Wenn sich der Log verändert hat, Statustext aktualisieren
''' </summary>
Expand Down
19 changes: 15 additions & 4 deletions source/Dialogs/LogWindow.vb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ Friend Class LogWindow
' This call is required by the Windows Form Designer.
InitializeComponent()

AddHandler Log.LogMsgAdded, AddressOf AddLogEntry
AddHandler Log.LogCleared, AddressOf ClearLog

' Add any initialization after the InitializeComponent() call.
Me.AddLogEntry(Log.levels.info, "Logging level is set to " & Log.level.ToString())

'add any already existing messages
If Not IsNothing(Log.logMessages) Then
For Each msg As KeyValuePair(Of levels, String) In Log.logMessages
Me.AddLogEntry(msg.Key, msg.Value)
Next
End If

End Sub

Friend Sub AddLogEntry(level As Log.levels, msg As String)
Private Sub AddLogEntry(level As Log.levels, msg As String)

Dim start, length As Integer

Expand Down Expand Up @@ -76,16 +87,16 @@ Friend Class LogWindow
Call Application.DoEvents()
End Sub

Friend Sub ClearLog()
Private Sub ClearLog()
Me.TextBox_Log.Text = ""
Call Application.DoEvents()
End Sub

'Form schließen
'Form schließen
'**************
Private Sub LogWindow_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

'verhindern, dass das Formular komplett gelöscht wird
'verhindern, dass das Formular komplett gelöscht wird
e.Cancel = True

'Formular verstecken
Expand Down
36 changes: 6 additions & 30 deletions source/Log.vb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
''' </summary>
Public Module Log

Private logWindow As LogWindow

Public logMessages As List(Of KeyValuePair(Of levels, String))

''' <summary>
Expand All @@ -44,6 +42,11 @@ Public Module Log
''' </summary>
Public Event LogMsgAdded(level As Log.levels, msg As String)

''' <summary>
''' Is triggered when the log was cleared
''' </summary>
Public Event LogCleared()

Sub New()
'attempt to read loggingLevel from application settings
Try
Expand All @@ -69,10 +72,6 @@ Public Module Log
msg = Constants.eol & " " & msg.Replace(Constants.eol, Constants.eol & " ")
End If

If Not IsNothing(logWindow) Then
Log.logWindow.AddLogEntry(level, msg)
End If

RaiseEvent LogMsgAdded(level, msg)
End If

Expand All @@ -85,31 +84,8 @@ Public Module Log

Log.logMessages.Clear()

If Not IsNothing(Log.logWindow) Then
Log.logWindow.ClearLog()
End If

RaiseEvent LogMsgAdded(Log.levels.info, "")
End Sub
RaiseEvent LogCleared()

Public Sub HideLogWindow()
If Not IsNothing(Log.logWindow) Then
Log.logWindow.Hide()
End If
End Sub

Public Sub ShowLogWindow()

If IsNothing(logWindow) Then
logWindow = New LogWindow()
'if this is the first time the window is shown, add any already existing messages
For Each msg As KeyValuePair(Of levels, String) In logMessages
logWindow.AddLogEntry(msg.Key, msg.Value)
Next
End If
logWindow.Show()
logWindow.WindowState = FormWindowState.Normal
logWindow.BringToFront()
End Sub

End Module

0 comments on commit 9e4791a

Please sign in to comment.