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

Grid syncing, Instat object & File Menu #452

Merged
merged 5 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
164 changes: 164 additions & 0 deletions instat/clsGridLink.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
' Instat+R
' Copyright (C) 2015
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU 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 General Public License for more details.
'
' 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 RDotNet
Imports unvell.ReoGrid

Public Class clsGridLink
Public grdData As ReoGridControl
Public grdMetadata As ReoGridControl
Public grdVariablesMetadata As ReoGridControl
Public bGrdDataExists As Boolean = False
Public bGrdMetadataExists As Boolean = False
Public bGrdVariablesMetadataExists As Boolean = False
Public bGrdDataChanged As Boolean = False
Public bGrdMetadataChanged As Boolean = False
Public bGrdVariablesMetadataChanged As Boolean = False

Public Sub UpdateGrids()
Dim bRDataChanged As Boolean
Dim bRMetadataChanged As Boolean
Dim bRVariablesMetadataChanged As Boolean
Dim bFoundName As Boolean
Dim lstDataNames As GenericVector
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim dfTemp As DataFrame
Dim strDataName As String
Dim shtTemp As Worksheet

bRDataChanged = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_data_changed()").AsLogical(0)
bRMetadataChanged = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_metadata_changed()").AsLogical(0)
bRVariablesMetadataChanged = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_variables_metadata_changed()").AsLogical(0)

If (bGrdDataExists And (bGrdDataChanged Or bRDataChanged)) Or (bGrdVariablesMetadataExists And (bGrdVariablesMetadataChanged Or bRVariablesMetadataChanged)) Then
lstDataNames = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_data_names()").AsList
For i = 0 To lstDataNames.Length - 1
strDataName = lstDataNames.AsCharacter(i)
If (bGrdDataExists And frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_data_changed(obj_name = " & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
dfTemp = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_data(" & Chr(34) & strDataName & Chr(34) & ")").AsDataFrame
FillSheet(dfTemp, strDataName, grdData)
frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$set_data_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
End If
If (bGrdVariablesMetadataExists And frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
dfTemp = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_variables_metadata(" & Chr(34) & strDataName & Chr(34) & ")").AsDataFrame
FillSheet(dfTemp, strDataName, grdVariablesMetadata)
frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$set_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
End If

Next
'delete old sheets
'TODO look at this code to improve it (simplify)
If bGrdDataExists Then
k = 0
For i = 0 To grdData.Worksheets.Count - 1
' look up convert genericvector to string list to avoid this loop
bFoundName = False
For j = 0 To lstDataNames.Length - 1
strDataName = lstDataNames.AsCharacter(j)
If strDataName = grdData.Worksheets(i - k).Name Then
bFoundName = True
Exit For
End If
Next
If Not bFoundName Then
shtTemp = grdData.Worksheets(i - k)
grdData.Worksheets.Remove(shtTemp)
k = k + 1
End If
Next
End If

If bGrdVariablesMetadataExists Then
k = 0
For i = 0 To grdVariablesMetadata.Worksheets.Count - 1
' look up convert genericvector to string list to avoid this loop
bFoundName = False
For j = 0 To lstDataNames.Length - 1
strDataName = lstDataNames.AsCharacter(j)
If strDataName = grdVariablesMetadata.Worksheets(i - k).Name Then
bFoundName = True
Exit For
End If
Next
If Not bFoundName Then
shtTemp = grdVariablesMetadata.Worksheets(i - k)
grdVariablesMetadata.Worksheets.Remove(shtTemp)
k = k + 1
End If
Next
End If
End If

If bGrdMetadataExists And (bGrdMetadataChanged Or bRMetadataChanged) Then
dfTemp = frmMain.clsRInterface.clsEngine.Evaluate(frmMain.clsRInterface.strInstatDataObject & "$get_combined_metadata()").AsDataFrame
FillSheet(dfTemp, "metadata", grdMetadata)
End If

End Sub

Public Sub SetData(grdTemp As ReoGridControl)
grdData = grdTemp
bGrdDataExists = True
bGrdDataChanged = True
UpdateGrids()
End Sub

Public Sub SetMetadata(grdTemp As ReoGridControl)
grdMetadata = grdTemp
bGrdMetadataExists = True
bGrdMetadataChanged = True
UpdateGrids()
End Sub

Public Sub SetVariablesMetadata(grdTemp As ReoGridControl)
grdVariablesMetadata = grdTemp
bGrdVariablesMetadataExists = True
bGrdVariablesMetadataChanged = True
UpdateGrids()
End Sub

Public Sub FillSheet(dfTemp As DataFrame, strName As String, grdCurr As ReoGridControl)
Dim bFoundWorksheet As Boolean = False
Dim tempWorkSheet
Dim fillWorkSheet

For Each tempWorkSheet In grdCurr.Worksheets
If tempWorkSheet.Name = strName Then
fillWorkSheet = grdCurr.GetWorksheetByName(strName)
bFoundWorksheet = True
End If
Next

If Not bFoundWorksheet Then
fillWorkSheet = grdCurr.CreateWorksheet(strName)
grdCurr.AddWorksheet(fillWorkSheet)
End If

fillWorkSheet.Reset()
fillWorkSheet.Rows = dfTemp.RowCount
fillWorkSheet.Columns = dfTemp.ColumnCount
For i As Integer = 0 To dfTemp.RowCount - 1
For j As Integer = 0 To dfTemp.ColumnCount - 1
fillWorkSheet.ColumnHeaders(j).Text = dfTemp.ColumnNames(j)
fillWorkSheet(row:=i, col:=j) = dfTemp(i, j)
Next
Next
grdCurr.CurrentWorksheet = fillWorkSheet
End Sub


End Class
5 changes: 3 additions & 2 deletions instat/dlgEndofRains.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Public Class dlgEndofRains
strScript = strScript & ",replace=TRUE)"
frmMain.clsRInterface.climateObject()
frmMain.clsRInterface.RunScript(strScript, False)
frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
'TODO fix this to update grids instead of calling FillData which no longer exists
' frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
' frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
Me.Hide()
End Sub

Expand Down
5 changes: 3 additions & 2 deletions instat/dlgExtremeEvents.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Public Class dlgExtremeEvents
strScript = strScript & ",replace=True)"
frmMain.clsRInterface.climateObject()
frmMain.clsRInterface.RunScript(strScript, False)
frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
'TODO fix this to update grids instead of calling FillData which no longer exists
' frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
' frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
Me.Hide()
End Sub

Expand Down
4 changes: 1 addition & 3 deletions instat/dlgFileNew.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Public Class dlgFileNew

Private Sub ucrBase_Load(sender As Object, e As EventArgs) Handles ucrBase.ClickOk
frmMain.clsRInterface.LoadData(txtName.Text, "data.frame(matrix(NA, nrow = " & txtRows.Text & ", ncol = " & txtColumns.Text & "))")
frmMain.clsRInterface.FillDataObjectVariables(frmVariables.gridVariables)
frmMain.clsRInterface.FillDataObjectMetadata(frmMetaData.gridMetaData)
frmMain.clsRInterface.FillDataObjectData(frmEditor.gridColumns)
frmMain.clsGrids.UpdateGrids()
End Sub
End Class
2 changes: 1 addition & 1 deletion instat/dlgOneSample.vb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Public Class dlgOneSample
Private Sub ucrReceiverDataColumn_ValueChanged(sender As Object, e As EventArgs) Handles ucrReceiverDataColumn.ValueChanged
If Not (ucrReceiverDataColumn.txtReceiverSingle.Text = "") Then
ucrBase.clsRsyntax.AddParameter("x", ucrReceiverDataColumn.GetVariables())
ucrBase.clsRsyntax.AddParameter("n", frmEditor.gridColumns.CurrentWorksheet.RowCount)
ucrBase.clsRsyntax.AddParameter("n", frmEditor.grdData.CurrentWorksheet.RowCount)
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
Expand Down
5 changes: 3 additions & 2 deletions instat/dlgStartofRains.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Public Class dlgStartofRains
strScript = strScript & ",replace=TRUE)"
frmMain.clsRInterface.climateObject()
frmMain.clsRInterface.RunScript(strScript, False)
frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
'TODO fix this to update grids instead of calling FillData which no longer exists
' frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
' frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
Me.Hide()
End Sub

Expand Down
5 changes: 3 additions & 2 deletions instat/dlgWaterBalance.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Public Class dlgWaterBalance
strScript = strScript & ")"
frmMain.clsRInterface.climateObject()
frmMain.clsRInterface.RunScript(strScript, False)
frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
'TODO fix this to update grids instead of calling FillData which no longer exists
' frmMain.FillData("climate_obj$climate_data_objects[[1]]$data")
' frmMain.FillData("climate_obj$used_data_objects[[1]]$data")
Me.Hide()
End Sub

Expand Down
51 changes: 33 additions & 18 deletions instat/frmEditor.Designer.vb

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

25 changes: 1 addition & 24 deletions instat/frmEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,8 @@ Imports System.Globalization
Imports System.Threading
Imports instat.Translations
Public Class frmEditor
Public Sub UpdateSheet(DataSet As DataFrame, strName As String)
Dim tempSheet = gridColumns.GetWorksheetByName(strName)
tempSheet.Reset()
tempSheet.Rows = DataSet.RowCount
tempSheet.Columns = DataSet.ColumnCount
For k As Integer = 0 To DataSet.ColumnCount - 1
tempSheet.ColumnHeaders(k).Text = DataSet.ColumnNames(k)
Next
For i As Integer = 0 To DataSet.RowCount - 1
For k As Integer = 0 To DataSet.ColumnCount - 1
tempSheet(row:=i, col:=k) = DataSet(i, k)
Next
Next

End Sub
Private Sub frmEditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load
gridColumns.SheetTabControlWidth = 300
gridColumns.CurrentWorksheet.Resize(1, 1)
'gridColumns.CurrentWorksheet.Name = "Data View"
frmMain.clsGrids.SetData(grdData)
autoTranslate(Me)
End Sub
Public Sub NewSheet(strName As String)
Dim sheet = gridColumns.CreateWorksheet(strName)

gridColumns.Worksheets.Add(sheet)
gridColumns.CurrentWorksheet = sheet
End Sub
End Class
Loading