Skip to content

Commit

Permalink
Merge pull request #91 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Update main branch
  • Loading branch information
stevekogo authored Jun 20, 2016
2 parents 25c3514 + 5c0d622 commit 2b8afee
Show file tree
Hide file tree
Showing 39 changed files with 840 additions and 299 deletions.
44 changes: 29 additions & 15 deletions instat/UcrGeomListWithAes.designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

195 changes: 92 additions & 103 deletions instat/UcrGeomListWithAes.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports instat

Public Class UcrGeomListWithParameters
Public lstAesParameterLabels As New List(Of Label)
Public lstAesParameterUcr As New List(Of ucrReceiverSingle)
Expand All @@ -23,7 +25,19 @@ Public Class UcrGeomListWithParameters
Public ucrLayersControl As ucrLayerParameters
Public bCheckEnabled As Boolean = True
Public Event DataFrameChanged()
Public clsAesFunction As RFunction
Public clsGeomAesFunction As RFunction
Public bAddToLocalAes As Boolean = True
Public bCurrentFixAes As Boolean = True

Public Sub New()

' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
clsGeomAesFunction = New RFunction
clsGeomAesFunction.SetRCommand("aes")
End Sub

Private Sub UcrGeomListWithParameters_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
Expand All @@ -32,6 +46,7 @@ Public Class UcrGeomListWithParameters
SetParameters()
bFirstLoad = False
End If
SetAes(bCurrentFixAes)
End Sub

Private Sub InitialiseControl()
Expand All @@ -47,17 +62,53 @@ Public Class UcrGeomListWithParameters
ucrReceiverParam1.SetMeAsReceiver()
End Sub

Private Sub SetDefaults()
'sets control defaults
UcrSelector.Reset()
Public Overrides Sub Setup(clsTempGgPlot As RFunction, clsTempGeomFunc As RFunction, clsTempGlobalAesFunc As RFunction, Optional bFixAes As Boolean = False, Optional bFixGeom As Boolean = False, Optional strDataframe As String = "", Optional bUseGlobalAes As Boolean = True, Optional iNumVariablesForGeoms As Integer = -1, Optional clsTempLocalAes As RFunction = Nothing)
MyBase.Setup(clsTempGgPlot, clsTempGeomFunc, clsTempGlobalAesFunc, bFixAes, bFixGeom, strDataframe, bUseGlobalAes, iNumVariablesForGeoms, clsTempLocalAes)
strGlobalDataFrame = strDataframe
If clsTempLocalAes IsNot Nothing Then
clsGeomAesFunction = clsTempLocalAes
Else
clsGeomAesFunction = New RFunction
clsGeomAesFunction.SetRCommand("aes")
End If
UcrSelector.SetDataframe(strGlobalDataFrame, (Not bUseGlobalAes) OrElse strGlobalDataFrame = "")
bCurrentFixAes = bFixAes
SetAes(bCurrentFixAes)
chkApplyOnAllLayers.Checked = bUseGlobalAes
End Sub

Public Sub SetGeomFunction(clsGeomFunc As RFunction)
clsGeomFunction = clsGeomFunc
Private Sub SetAes(Optional bFixAes As Boolean = False)
Dim bFirstEnabled As Boolean = True
Dim iFirstEnabled As Integer = 0
bAddToLocalAes = False
For i = 0 To clsCurrGeom.clsAesParameters.Count - 1
lstAesParameterUcr(i).Enabled = True
For Each clsParam In clsGgplotAesFunction.clsParameters
If clsParam.strArgumentName = lstCurrArguments(i) Then
lstAesParameterUcr(i).Add(clsParam.strArgumentValue)
lstAesParameterUcr(i).Enabled = Not bFixAes
Exit For
End If
Next
For Each clsParam In clsGeomAesFunction.clsParameters
If clsParam.strArgumentName = lstCurrArguments(i) Then
lstAesParameterUcr(i).Add(clsParam.strArgumentValue)
lstAesParameterUcr(i).Enabled = True
Exit For
End If
Next
If bFirstEnabled AndAlso lstAesParameterUcr(i).Enabled Then
iFirstEnabled = i
bFirstEnabled = False
End If
Next
lstAesParameterUcr(iFirstEnabled).SetMeAsReceiver()
bAddToLocalAes = True
End Sub

Public Sub SetAesFunction(clsAesFunc As RFunction)
clsAesFunction = clsAesFunc
Private Sub SetDefaults()
'sets control defaults
UcrSelector.Reset()
End Sub

Public Sub SetParameters() 'this will set function or aes parameters
Expand Down Expand Up @@ -134,27 +185,26 @@ Public Class UcrGeomListWithParameters
ucrReceiverParam2.Visible = True
End If
'populating labels with appropriate names
clsGeomAesFunction.ClearParameters()
If clsCurrGeom IsNot Nothing Then
lstCurrArguments.Clear()
For i = 0 To (clsCurrGeom.clsAesParameters.Count - 1)
If Not clsCurrGeom.clsAesParameters(i).bIsMandatory Then
lstAesParameterLabels(i).Text = clsCurrGeom.clsAesParameters(i).strAesParameterName
lstCurrArguments.Add(clsCurrGeom.clsAesParameters(i).strAesParameterName)
Else
'make them uppercase
lstAesParameterLabels(i).Text = (clsCurrGeom.clsAesParameters(i).strAesParameterName)
lstAesParameterLabels(i).Text = clsCurrGeom.clsAesParameters(i).strAesParameterName
lstCurrArguments.Add(clsCurrGeom.clsAesParameters(i).strAesParameterName)
lstAesParameterUcr(i).Clear()
If clsCurrGeom.clsAesParameters(i).bIsMandatory Then
lstAesParameterLabels(i).Font = New Font(lstAesParameterLabels(i).Font, FontStyle.Bold)
lstCurrArguments.Add(clsCurrGeom.clsAesParameters(i).strAesParameterName)
Else
lstAesParameterLabels(i).Font = New Font(lstAesParameterLabels(i).Font, FontStyle.Regular)
End If

If clsCurrGeom.clsAesParameters(i).strIncludedDataTypes IsNot Nothing Then
lstAesParameterUcr(i).SetIncludedDataTypes(clsCurrGeom.clsAesParameters(i).strIncludedDataTypes)

ElseIf clsCurrGeom.clsAesParameters(i).strExcludedDataTypes IsNot Nothing Then
lstAesParameterUcr(i).SetExcludedDataTypes(clsCurrGeom.clsAesParameters(i).strExcludedDataTypes)
End If
Next
End If
SetAes(bCurrentFixAes)
End Sub

Public Sub UcrGeomListWithParameters_cboGeomListIndexChanged(sender As Object, e As EventArgs) Handles Me.GeomChanged
Expand All @@ -166,107 +216,46 @@ Public Class UcrGeomListWithParameters
SetParameters()
End Sub

Private Sub ucrReceiverParam1_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam1.SelectionChanged
If Not ucrReceiverParam1.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(0), ucrReceiverParam1.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(0))
End If
TestForOkEnabled()
End Sub

Private Sub ucrReceiverParam2_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam2.SelectionChanged
If Not ucrReceiverParam2.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(1), ucrReceiverParam2.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(1))
End If
TestForOkEnabled()
End Sub
Private Sub ucrReceiverParam3_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam3.SelectionChanged
If Not ucrReceiverParam3.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(2), ucrReceiverParam3.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(2))
End If
TestForOkEnabled()
Private Sub ucrReceiverParam_WithMeSelectionChanged(ucrChangedReceiver As ucrReceiverSingle) Handles ucrReceiverParam1.WithMeSelectionChanged, ucrReceiverParam2.WithMeSelectionChanged, ucrReceiverParam3.WithMeSelectionChanged, ucrReceiverParam4.WithMeSelectionChanged, ucrReceiverParam5.WithMeSelectionChanged, ucrReceiverParam6.WithMeSelectionChanged, ucrReceiverParam7.WithMeSelectionChanged, ucrReceiverParam8.WithMeSelectionChanged, ucrReceiverParam9.WithMeSelectionChanged
Dim iIndex As Integer

End Sub

Private Sub ucrReceiverParam4_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam4.SelectionChanged
If Not ucrReceiverParam4.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(3), ucrReceiverParam4.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(3))
End If
TestForOkEnabled()
End Sub
Private Sub ucrReceiverParam5_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam5.SelectionChanged
If Not ucrReceiverParam5.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(4), ucrReceiverParam5.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(4))
End If
TestForOkEnabled()
End Sub

Private Sub ucrReceiverParam6_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam6.SelectionChanged
If Not ucrReceiverParam6.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(5), ucrReceiverParam6.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(5))
End If
TestForOkEnabled()
End Sub

Private Sub ucrReceiverParam7_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam7.SelectionChanged, ucrReceiverParam9.SelectionChanged, ucrReceiverParam8.SelectionChanged
If Not ucrReceiverParam7.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(6), ucrReceiverParam7.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(6))
End If
TestForOkEnabled()
End Sub
Private Sub ucrReceiverParam8_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam8.SelectionChanged, ucrReceiverParam9.SelectionChanged, ucrReceiverParam8.SelectionChanged
If Not ucrReceiverParam8.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(7), ucrReceiverParam8.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(7))
End If
TestForOkEnabled()
End Sub

Private Sub ucrReceiverParam9_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverParam9.SelectionChanged, ucrReceiverParam9.SelectionChanged, ucrReceiverParam8.SelectionChanged
If Not ucrReceiverParam9.IsEmpty Then
clsRaesFunction.AddParameter(lstCurrArguments(8), ucrReceiverParam9.GetVariableNames(False))
Else
clsRaesFunction.RemoveParameterByName(lstCurrArguments(8))
If bAddToLocalAes Then
iIndex = lstAesParameterUcr.IndexOf(ucrChangedReceiver)
If Not ucrChangedReceiver.IsEmpty Then
clsGeomAesFunction.AddParameter(lstCurrArguments(iIndex), ucrChangedReceiver.GetVariableNames(False))
Else
clsGeomAesFunction.RemoveParameterByName(lstCurrArguments(iIndex))
End If
TestForOkEnabled()
End If
TestForOkEnabled()
End Sub

Public Sub SetDataframe(strDataframe As String, Optional bEnableDataframe As Boolean = True)
UcrSelector.SetDataframe(strDataframe, bEnableDataframe)
End Sub

Private Sub UcrSelector_DataFrameChanged() Handles UcrSelector.DataFrameChanged
clsGeomFunction.AddParameter("data", clsRFunctionParameter:=UcrSelector.ucrAvailableDataFrames.clsCurrDataFrame)
' RaiseEvent DataFrameChanged() do we need this?
End Sub

Public Function TestForOkEnabled() As Boolean
Dim i As Integer = 0

For i = 0 To (clsCurrGeom.clsAesParameters.Count - 1)
If (clsCurrGeom.clsAesParameters(i).bIsMandatory = True) AndAlso (lstAesParameterUcr(i).IsEmpty()) Then
'this should have okay disabled
Return False
End If
Next
Return True
End Function

Private Sub chkChangeAes_CheckedChanged(sender As Object, e As EventArgs) Handles chkChangeAes.CheckedChanged
Private Sub chkChangeAes_CheckedChanged(sender As Object, e As EventArgs) Handles chkApplyOnAllLayers.CheckedChanged
If chkApplyOnAllLayers.Checked Then
chkIgnoreGlobalAes.Checked = False
chkIgnoreGlobalAes.Hide()
Else
chkIgnoreGlobalAes.Show()
End If
UcrSelector.SetDataframe(strGlobalDataFrame, (Not chkApplyOnAllLayers.Checked) OrElse strGlobalDataFrame = "")
End Sub

Private Sub chkIgnoreGlobalAes_CheckedChanged(sender As Object, e As EventArgs) Handles chkIgnoreGlobalAes.CheckedChanged
If chkIgnoreGlobalAes.Checked Then
clsGeomFunction.AddParameter("inherit.aes", "FALSE")
Else
clsGeomFunction.RemoveParameterByName("inherit.aes")
End If
End Sub
End Class
15 changes: 15 additions & 0 deletions instat/clsGeom.vb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Public Class Geoms
Public Sub AddLayerParameter(strLayerParameterName As String, strLayerParameterDataType As String, strLayerParameterDefaultValue As String, Optional bIsDependent As Boolean = False, Optional lstParameterStrings As String() = Nothing, Optional strDependentParameter As String = "", Optional strDependantpParameterValue As String = "")
Dim NewLayerParameter As New LayerParameters

If lstParameterStrings Is Nothing Then
lstParameterStrings = New String() {}
End If
NewLayerParameter.strLayerParameterName = strLayerParameterName
NewLayerParameter.strLayerParameterDataType = strLayerParameterDataType
NewLayerParameter.strParameterDefaultValue = strLayerParameterDefaultValue
Expand All @@ -47,6 +50,18 @@ Public Class Geoms

clsLayerParameters.Add(NewLayerParameter)
End Sub

Public ReadOnly Property iNumMandatoryAes As Integer
Get
Dim iCount As Integer = 0
For Each clsParam In clsAesParameters
If clsParam.bIsMandatory Then
iCount = iCount + 1
End If
Next
Return iCount
End Get
End Property
End Class

Public Class AesParameters
Expand Down
Loading

0 comments on commit 2b8afee

Please sign in to comment.