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

Autofill of summary variables in the Climograph dialog. #9192

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

MeSophie
Copy link
Contributor

Fixes #9067
@rdstern I ensured the Autofill of summary variables in the Climograph dialog. Please have a look.

rdstern
rdstern previously approved these changes Oct 30, 2024
Copy link
Collaborator

@rdstern rdstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MeSophie that looks fine.
@N-thony over to you to check and hopefully merge

Copy link
Collaborator

@N-thony N-thony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MeSophie I have made some code improvement, have a look and try it if it works well.

Comment on lines 1835 to 2017
ucrCurrentReceiver.SetMeAsReceiver()
End If

' Re-enable the event handler
AddHandler ucrSelectorClimograph.ControlValueChanged, AddressOf AutoFillTmaxReceivers

isFilling = False
End Sub

Private Sub AutoFillTminReceivers()
If isFilling Then
Exit Sub
End If
isFilling = True

' Temporarily remove the event handler
RemoveHandler ucrSelectorClimograph.ControlValueChanged, AddressOf AutoFillTminReceivers

Dim lstRecognisedValues As List(Of String)
Dim ucrCurrentReceiver As ucrReceiver
Dim bFound As Boolean = False

ucrCurrentReceiver = ucrSelectorClimograph.CurrentReceiver

For Each ucrTempReceiver As ucrReceiver In lstTminReceivers
ucrTempReceiver.SetMeAsReceiver()
lstRecognisedValues = GetRecognisedValues(ucrTempReceiver.Tag)

If lstRecognisedValues.Count > 0 Then
For Each lviTempVariable As ListViewItem In ucrSelectorClimograph.lstAvailableVariable.Items
For Each strValue As String In lstRecognisedValues
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]", String.Empty).Equals(strValue) Then
ucrTempReceiver.Add(lviTempVariable.Text, ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
bFound = True
Exit For
End If
Next
If bFound Then
bFound = False
Exit For
End If
Next
End If
Next

If ucrCurrentReceiver IsNot Nothing Then
ucrCurrentReceiver.SetMeAsReceiver()
End If

' Re-enable the event handler
AddHandler ucrSelectorClimograph.ControlValueChanged, AddressOf AutoFillTminReceivers

isFilling = False
End Sub

Private Sub AutoFillTminminReceivers()
If isFilling Then
Exit Sub
End If
isFilling = True

' Temporarily remove the event handler
RemoveHandler ucrSelectorClimograph.ControlValueChanged, AddressOf AutoFillTminminReceivers

Dim lstRecognisedValues As List(Of String)
Dim ucrCurrentReceiver As ucrReceiver
Dim bFound As Boolean = False

ucrCurrentReceiver = ucrSelectorClimograph.CurrentReceiver

For Each ucrTempReceiver As ucrReceiver In lstTminminReceivers
ucrTempReceiver.SetMeAsReceiver()
lstRecognisedValues = GetRecognisedValues(ucrTempReceiver.Tag)

If lstRecognisedValues.Count > 0 Then
For Each lviTempVariable As ListViewItem In ucrSelectorClimograph.lstAvailableVariable.Items
For Each strValue As String In lstRecognisedValues
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]", String.Empty).Equals(strValue) Then
ucrTempReceiver.Add(lviTempVariable.Text, ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
bFound = True
Exit For
End If
Next
If bFound Then
bFound = False
Exit For
End If
Next
End If
Next

If ucrCurrentReceiver IsNot Nothing Then
ucrCurrentReceiver.SetMeAsReceiver()
End If

' Re-enable the event handler
AddHandler ucrSelectorClimograph.ControlValueChanged, AddressOf AutoFillTminminReceivers

isFilling = False
End Sub
Copy link
Collaborator

@N-thony N-thony Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about reducing the four subs to one like this?

Private Sub AutoFillReceivers(lstReceivers As List(Of ucrReceiverSingle ))
    Dim lstRecognisedValues As List(Of String)
    Dim ucrCurrentReceiver As ucrReceiver = ucrSelectorClimograph.CurrentReceiver
    Dim bFound As Boolean = False

    For Each ucrTempReceiver As ucrReceiver In lstReceivers
        ucrTempReceiver.SetMeAsReceiver()
        lstRecognisedValues = GetRecognisedValues(ucrTempReceiver.Tag)

        If lstRecognisedValues.Count > 0 Then
            For Each lviTempVariable As ListViewItem In ucrSelectorClimograph.lstAvailableVariable.Items
                For Each strValue As String In lstRecognisedValues
                    If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]", String.Empty).Equals(strValue) Then
                        ucrTempReceiver.Add(lviTempVariable.Text, ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then
                    bFound = False
                    Exit For
                End If
            Next
        End If
    Next

    If ucrCurrentReceiver IsNot Nothing Then
        ucrCurrentReceiver.SetMeAsReceiver()
    End If
End Sub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solved.

Comment on lines 1336 to 1339
AutoFillRainReceivers()
AutoFillTmaxReceivers()
AutoFillTminReceivers()
AutoFillTminminReceivers()
Copy link
Collaborator

@N-thony N-thony Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then replace this with

If isFilling Then
     Exit Sub
 End If
 isFilling = True

 Dim lstReceivers As List(Of ucrReceiverSingle ) = Nothing
If ucrSelectorClimograph.CurrentReceiver IsNot Nothing Then
 Select Case ucrSelectorClimograph.CurrentReceiver.Tag ' Or any property that differentiates the lists
     Case "Rain"
         lstReceivers = lstRainReceivers
     Case "Tmax"
         lstReceivers = lstTmaxReceivers
     Case "Tmin"
         lstReceivers = lstTminReceivers
     Case "Tminmin"
         lstReceivers = lstTminminReceivers
     ' Add additional cases as necessary
 End Select
End If
 If lstReceivers IsNot Nothing Then
     AutoFillReceivers(lstReceivers)
 End If

 isFilling = False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-thony I wasn't able to test the new change because of this code. lstTminminReceivers, lstTminReceivers, lstTmaxReceivers and lstRainReceivers are producing errors saying 'Unable to convert “List(Of ucrReceiverSingle)” to “List(Of ucrReceiver)”. So I changed ucrReceiver to ucrReceiverSingle then I obtained this message
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-thony I wasn't able to test the new change because of this code. lstTminminReceivers, lstTminReceivers, lstTmaxReceivers and lstRainReceivers are producing errors saying 'Unable to convert “List(Of ucrReceiverSingle)” to “List(Of ucrReceiver)”. So I changed ucrReceiver to ucrReceiverSingle then I obtained this message image

@MeSophie I have made a small change in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-thony I wasn't able to test the new change because of this code. lstTminminReceivers, lstTminReceivers, lstTmaxReceivers and lstRainReceivers are producing errors saying 'Unable to convert “List(Of ucrReceiverSingle)” to “List(Of ucrReceiver)”. So I changed ucrReceiver to ucrReceiverSingle then I obtained this message image

@MeSophie I have made a small change in the code

@N-thony I still have this error

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check again, an If was missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-thony the Autofill is not working anymore
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solved.

Comment on lines 869 to 872
AutoFillRainReceivers()
AutoFillTmaxReceivers()
AutoFillTminReceivers()
AutoFillTminminReceivers()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MeSophie pull my branch MeSophie-SummaryClimaticissue9067 and have a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solved.

@N-thony
Copy link
Collaborator

N-thony commented Oct 31, 2024

@MeSophie can you push the changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define summary climatic variables as climatic
3 participants