Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional import settings in Wave project file #121

Merged
merged 30 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aff6c70
implement reading series options from WVP files #117
jamaa Oct 7, 2023
24e4163
make TimeSeries.DisplayOptions an always present property with defaul…
jamaa Oct 8, 2023
318a323
use regex to also parse quoted keyword option values
jamaa Oct 8, 2023
471b960
use named regex capturing groups
jamaa Oct 8, 2023
fc51810
readability
jamaa Oct 8, 2023
3f3799c
rewrite SaveProjectFile(), keep original order of series
jamaa Oct 8, 2023
d949ba6
write changed series titles to project file
jamaa Oct 8, 2023
3955fde
update changelog
jamaa Oct 8, 2023
42c40d2
add "showpoints" as an additional WVP series import option
jamaa Oct 13, 2023
40ce41c
move method for saving Wave project file to WVP class
jamaa Oct 13, 2023
db2aedf
write series options when saving WVP
jamaa Oct 13, 2023
b9333d5
collect display options from chart when saving WVP
jamaa Oct 13, 2023
8fb3a5b
accept hexadecimal ARGB values as a color string
jamaa Oct 13, 2023
554b7f5
always write title, reorder options
jamaa Oct 13, 2023
39323e7
slight reformatting
jamaa Oct 13, 2023
51af002
always use UTF-8 encoding for reading and writing WVP files
jamaa Oct 14, 2023
425372d
add tests for reading and writing WVP files
jamaa Oct 14, 2023
ffb4e67
add setting custom display options to example
jamaa Oct 14, 2023
a38d9b9
Merge branch 'master' into wvp-options
jamaa Nov 11, 2023
2cdac32
added a save project file dialog with options, make all options optional
jamaa Nov 11, 2023
656e7e3
dialog styling
jamaa Nov 11, 2023
7b1b978
display message box if there are no time series to save
jamaa Nov 11, 2023
437c62a
add the option to save relative file paths to a Wave project file
jamaa Nov 11, 2023
459fd92
update changelog
jamaa Nov 11, 2023
f82bfc3
save the title only if it is different from the series name and if it…
jamaa Nov 11, 2023
4381927
better detection of title-only options
jamaa Nov 11, 2023
02d6ab8
display a message box after saving WVP
jamaa Nov 11, 2023
ceaa0b6
expand and fix test TestWVP_WriteOptions
jamaa Nov 11, 2023
4371fe7
prompt for file overwrite only after OK button is pressed
jamaa Nov 11, 2023
8093afc
fix file filter
jamaa Nov 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/Examples.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Public Class Examples
Public Class Examples

''' <summary>
''' Path to the time series file
Expand Down Expand Up @@ -149,6 +149,12 @@
Console.WriteLine("End date: " & ts.EndDate)
Console.WriteLine("Average: " & ts.Average)

'set some custom display options
ts.DisplayOptions.Color = Color.Red
ts.DisplayOptions.LineStyle = Drawing2D.DashStyle.Dash
ts.DisplayOptions.LineWidth = 1
ts.DisplayOptions.ShowPoints = True

'import the series in Wave
Wave1.Import_Series(ts)

Expand Down
6 changes: 6 additions & 0 deletions source/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Development
NEW:
* Added a new series selection dialog for known (non-CSV) file types
* Added the ability to reorder series from within the Time Series Properties window
* Wave project file (WVP):
* Added support for additional series options in WVP files #117
* When saving to WVP, a new dialog allows specifying which series options to save
* When saving to WVP, file paths can now optionally be saved as relative
* WVP files are now always read and written using UTF-8 encoding

CHANGED:
* Upgrade TeeChart to v4.2023.4.18
Expand Down Expand Up @@ -46,6 +51,7 @@ CHANGED:
API-CHANGES:
* Removed property `TimeSeriesFile.nLinesPerTimestamp`
* Removed the properties `TimeSeries.Objekt` and `TimeSeries.Type`
* New public method `Fileformats.WVP.Write_File()` for writing a Wave project file

Version 2.4.5
-------------
Expand Down
16 changes: 16 additions & 0 deletions source/Classes/TimeSeries.vb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Public Class TimeSeries
Private _Type As String
Private _Interpretation As InterpretationEnum
Private _DataSource As TimeSeriesDataSource
Private _displayOptions As TimeSeriesDisplayOptions

#End Region 'Members

Expand Down Expand Up @@ -256,6 +257,19 @@ Public Class TimeSeries
End Set
End Property

''' <summary>
''' Options for displaying the time series
''' </summary>
''' <returns></returns>
Public Property DisplayOptions As TimeSeriesDisplayOptions
Get
Return _displayOptions
End Get
Set(value As TimeSeriesDisplayOptions)
_displayOptions = value
End Set
End Property

''' <summary>
''' Returns the start date of the time series
''' </summary>
Expand Down Expand Up @@ -453,6 +467,7 @@ Public Class TimeSeries
Me._unit = "-"
Me._Interpretation = InterpretationEnum.Undefined
Me.DataSource = New TimeSeriesDataSource(TimeSeriesDataSource.OriginEnum.Undefined)
Me.DisplayOptions = New TimeSeriesDisplayOptions()
Me._nodes = New SortedList(Of DateTime, Double)
End Sub

Expand All @@ -477,6 +492,7 @@ Public Class TimeSeries
target.Metadata = Me.Metadata.Copy()
target._Interpretation = Me.Interpretation
target.DataSource = Me.DataSource.Copy()
target.DisplayOptions = Me.DisplayOptions.Copy()
Return target
End Function

Expand Down
169 changes: 169 additions & 0 deletions source/Classes/TimeSeriesDisplayOptions.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
'BlueM.Wave
'Copyright (C) BlueM Dev Group
'<https://www.bluemodel.org>
'
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU Lesser General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'
'This program 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 Lesser General Public License for more details.
'
'You should have received a copy of the GNU Lesser General Public License
'along with this program. If not, see <https://www.gnu.org/licenses/>.
'
''' <summary>
''' Class for storing time series display options
''' </summary>
Public Class TimeSeriesDisplayOptions

Private _color As Color
Private _linestyle As Drawing2D.DashStyle
Private _linewidth As Integer
Private _showPoints As Boolean

''' <summary>
''' Color
''' </summary>
''' <remarks>Default color is empty. When empty, color is automatically assigned by the chart</remarks>
''' <returns></returns>
Public Property Color As Color
Get
Return _color
End Get
Set(value As Color)
_color = value
End Set
End Property

''' <summary>
''' Line style
''' </summary>
''' <returns></returns>
Public Property LineStyle As Drawing2D.DashStyle
Get
Return _linestyle
End Get
Set(value As Drawing2D.DashStyle)
_linestyle = value
End Set
End Property

''' <summary>
''' Line width
''' </summary>
''' <returns></returns>
Public Property LineWidth As Integer
Get
Return _linewidth
End Get
Set(value As Integer)
_linewidth = value
End Set
End Property

''' <summary>
''' Flag to show series points
''' </summary>
''' <returns></returns>
Public Property ShowPoints As Boolean
Get
Return _showPoints
End Get
Set(value As Boolean)
_showPoints = value
End Set
End Property

''' <summary>
''' Creates a new TimeSeriesDisplayOption instance with default properties
''' </summary>
''' <remarks>Default Color is empty in order to allow automatic color assignment by the chart</remarks>
Public Sub New()
Me.Color = Color.Empty
Me.LineStyle = Drawing2D.DashStyle.Solid
Me.LineWidth = 2
Me.ShowPoints = False
End Sub

''' <summary>
''' Returns a copy of the instance
''' </summary>
''' <returns></returns>
Public Function Copy() As TimeSeriesDisplayOptions
Dim displayOptions As New TimeSeriesDisplayOptions() With {
.Color = Me.Color,
.LineStyle = Me.LineStyle,
.LineWidth = Me.LineWidth,
.ShowPoints = Me.ShowPoints
}
Return displayOptions
End Function

''' <summary>
''' Sets the color from a color string
''' </summary>
''' <remarks>
''' Must be either the name of a known color: https://learn.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor
''' or a hexadecimal representation of ARGB values
''' </remarks>
''' <param name="colorString">the color string</param>
Public Sub SetColor(colorString As String)
If [Enum].IsDefined(GetType(KnownColor), colorString) Then
Me.Color = Drawing.Color.FromName(colorString)
Else
Try
'try to convert a hexadecimal representation of ARGB values
Dim argb As Integer = Int32.Parse(colorString, Globalization.NumberStyles.HexNumber)
Me.Color = Color.FromArgb(argb)
Catch e As FormatException
Log.AddLogEntry(levels.warning, $"Color '{colorString}' is not recognized!")
End Try
End If
End Sub

''' <summary>
''' Sets the line style from a string
''' </summary>
''' <remarks>Recognized line styles: https://learn.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.dashstyle</remarks>
''' <param name="lineStyle">the line style as string</param>
Public Sub SetLineStyle(lineStyle As String)
If Not [Enum].IsDefined(GetType(Drawing2D.DashStyle), lineStyle) Then
Log.AddLogEntry(levels.warning, $"Line style '{lineStyle}' is not recognized!")
Else
Me.LineStyle = [Enum].Parse(GetType(Drawing2D.DashStyle), lineStyle)
End If
End Sub

''' <summary>
''' Sets the line width from a string
''' </summary>
''' <remarks>string must be convertible to an integer</remarks>
''' <param name="lineWidth">line width as string</param>
Public Sub SetLineWidth(lineWidth As String)
Dim lineWidthInt As Integer
If Not Integer.TryParse(lineWidth, lineWidthInt) Then
Log.AddLogEntry(levels.warning, $"Line width '{lineWidth}' can not be converted to integer!")
Else
Me.LineWidth = lineWidthInt
End If
End Sub

''' <summary>
''' Sets the ShowPoints property from a string
''' </summary>
''' <remarks>string must be convertible to a boolean</remarks>
''' <param name="showPoints">whether to show points</param>
Public Sub SetShowPoints(showPoints As String)
Select Case showPoints.ToLower()
Case "true", "y", "1"
Me.ShowPoints = True
Case Else
Me.ShowPoints = False
End Select
End Sub

End Class
65 changes: 50 additions & 15 deletions source/Controllers/WaveController.vb
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,46 @@ Friend Class WaveController
''' <remarks></remarks>
Private Sub SaveProjectFile_Click(sender As System.Object, e As System.EventArgs)

If _model.TimeSeries.Count = 0 Then
MsgBox("No time series to save!", MsgBoxStyle.Exclamation)
Exit Sub
End If

Try
'show save project file dialog
Dim dlgres As DialogResult

'Prepare SaveFileDialog
View.SaveFileDialog1.Title = "Save project file"
View.SaveFileDialog1.Filter = "Wave project files (*.wvp)|*wvp"
View.SaveFileDialog1.DefaultExt = "wvp"
View.SaveFileDialog1.OverwritePrompt = True

'Show dialog
dlgres = View.SaveFileDialog1.ShowDialog()
Dim dlg As New SaveProjectFileDialog()
dlgres = dlg.ShowDialog()

If dlgres = Windows.Forms.DialogResult.OK Then
Call _model.SaveProjectFile(View.SaveFileDialog1.FileName)
'collect display options from chart and store them in timeseries
Dim tsList As New List(Of TimeSeries)
For Each ts As TimeSeries In _model.TimeSeries.ToList()
For Each series As Steema.TeeChart.Styles.Series In View.TChart1.Series
If series.Tag = ts.Id Then
If TypeOf series Is Steema.TeeChart.Styles.Line Then
Dim line As Steema.TeeChart.Styles.Line = CType(series, Steema.TeeChart.Styles.Line)
ts.DisplayOptions.Color = line.Color
ts.DisplayOptions.LineStyle = line.LinePen.Style
ts.DisplayOptions.LineWidth = line.LinePen.Width
ts.DisplayOptions.ShowPoints = line.Pointer.Visible
End If
Exit For
End If
Next
tsList.Add(ts)
Next
Call Fileformats.WVP.Write_File(tsList, dlg.FileName,
saveRelativePaths:=dlg.SaveRelativePaths,
saveTitle:=dlg.SaveTitle,
saveUnit:=dlg.SaveUnit,
saveInterpretation:=dlg.SaveInterpretation,
saveColor:=dlg.SaveColor,
saveLineStyle:=dlg.SaveLineStyle,
saveLineWidth:=dlg.SaveLineWidth,
savePointsVisibility:=dlg.SavePointsVisibility
)
MsgBox($"Wave project file {dlg.FileName} saved.", MsgBoxStyle.Information)
End If

Catch ex As Exception
Expand Down Expand Up @@ -2174,7 +2200,7 @@ Friend Class WaveController
''' Adds the series to the charts
''' Also adds the datasource to the MRU file list if the time series has a file datasource
''' </summary>
''' <param name="ts">Die anzuzeigende Zeitreihe</param>
''' <param name="ts">time series to display</param>
Private Sub SeriesAdded(ts As TimeSeries)

'Check for extreme dates not supported by TChart
Expand Down Expand Up @@ -2228,8 +2254,13 @@ Friend Class WaveController
'Namen vergeben
Line1.Title = ts.Title

'Set line width to 2
Line1.LinePen.Width = 2
'set display options
If Not ts.DisplayOptions.Color.IsEmpty Then
Line1.Color = ts.DisplayOptions.Color
End If
Line1.LinePen.Style = ts.DisplayOptions.LineStyle
Line1.LinePen.Width = ts.DisplayOptions.LineWidth
Line1.Pointer.Visible = ts.DisplayOptions.ShowPoints

'Stützstellen zur Serie hinzufügen
'Main chart
Expand Down Expand Up @@ -2287,8 +2318,12 @@ Friend Class WaveController
'Namen vergeben
Line2.Title = ts.Title

'Set line width to 2
Line2.LinePen.Width = 2
'set display options
If Not ts.DisplayOptions.Color.IsEmpty Then
Line2.Color = ts.DisplayOptions.Color
End If
Line2.LinePen.Style = ts.DisplayOptions.LineStyle
Line2.LinePen.Width = ts.DisplayOptions.LineWidth

'Stützstellen zur Serie hinzufügen
Line2.BeginUpdate()
Expand Down
Loading