Skip to content

Commit

Permalink
Merge pull request #457 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
dannyparsons authored Jan 10, 2017
2 parents e1eef70 + 0ed50ff commit 8d62331
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 97 deletions.
2 changes: 1 addition & 1 deletion instat/clsBlockReader.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
' 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,
' 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.
Expand Down
206 changes: 182 additions & 24 deletions instat/clsInstatOptions.vb
Original file line number Diff line number Diff line change
@@ -1,39 +1,155 @@
Imports System.Threading
Imports System.Globalization
Imports unvell.ReoGrid
Imports RDotNet

'Serializable allows the class to be exported as a file
<Serializable()> Public Class InstatOptions
Public bIncludeRDefaultParameters As Boolean
Public fntOutput, fntScript, fntComment, fntEditor As Font
Public clrOutput, clrScript, clrComment, clrEditor As Color
Public strComment, strLanguageCultureCode As String
Public strWorkingDirectory As String
Public iPreviewRows As Integer
Public iMaxRows As Integer
' Nullable allows us to have integers and booleans with value = Nothing
' Needed so we can check if variable has been specified, not just has default value
Public iPreviewRows As Nullable(Of Integer)
Public iMaxRows As Nullable(Of Integer)
Public lstColourPalette As List(Of Color)
Public strGraphDisplayOption As String
Public bCommandsinOutput As Boolean
Public bIncludeCommentDefault As Boolean 'sets the default for comments on the dialog
Public bCommandsinOutput As Nullable(Of Boolean)
Public bIncludeCommentDefault As Nullable(Of Boolean) 'sets the default for comments on the dialog
Public iDigits As Nullable(Of Integer)
Public bShowSignifStars As Nullable(Of Boolean)

Public Sub New()
'Factory defaults
Private DEFAULTbIncludeRDefaultParameters As Boolean = False
Private DEFAULTbCommandsinOutput As Boolean = True
Private DEFAULTbIncludeCommentDefault As Boolean = True
Private DEFAULTfntOutput As Font = New Font(FontFamily.GenericMonospace, 8, FontStyle.Regular)
Private DEFAULTclrOutput As Color = Color.Blue
Private DEFAULTfntComment As Font = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular)
Private DEFAULTclrComment As Color = Color.Green
Private DEFAULTfntScript As Font = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular)
Private DEFAULTclrScript As Color = Color.Black
Private DEFAULTfntEditor As Font = New Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)
Private DEFAULTclrEditor As Color = Color.Black
Private DEFAULTiPreviewRows As Integer = 10
Private DEFAULTiMaxRows As Integer = 1000
Private DEFAULTstrComment As String = "code generated by the dialog"
Private DEFAULTstrGraphDisplayOption As String = "view_output_window"
'TODO is this sensible?
Private DEFAULTstrLanguageCultureCode As String = Thread.CurrentThread.CurrentCulture.Name
Private DEFAULTstrWorkingDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Private DEFAULTlstColourPalette As List(Of Color) = ({Color.Aqua, Color.Gray, Color.LightGreen, Color.AliceBlue, Color.Maroon, Color.Green, Color.LightPink, Color.LightSkyBlue, Color.Brown, Color.MediumPurple, Color.White}).ToList
Private DEFAULTiDigits As Integer = 4
Private DEFAULTbShowSignifStars As Boolean = False

Public Sub New(Optional bSetOptions As Boolean = True)
'TODO Is this sensible to do in constructor?
bIncludeRDefaultParameters = False
bCommandsinOutput = True
bIncludeCommentDefault = True
SetFormatOutput(New Font(FontFamily.GenericMonospace, 8, FontStyle.Regular), Color.Blue)
SetFormatComment(New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), Color.Green)
SetFormatCommand(New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), Color.Black)
SetEditorFormat(New Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular), Color.Black)
SetPreviewRows(10)
SetMaxRows(1000)
SetCommentsInOutput(True)
SetCommandInOutpt(True)
SetComment("code generated by the dialog")
SetGraphDisplayOption("view_output_window")
bIncludeRDefaultParameters = DEFAULTbIncludeRDefaultParameters
bCommandsinOutput = DEFAULTbCommandsinOutput
bIncludeCommentDefault = DEFAULTbIncludeCommentDefault
fntOutput = DEFAULTfntOutput
clrOutput = DEFAULTclrOutput
fntComment = DEFAULTfntComment
clrComment = DEFAULTclrComment
fntScript = DEFAULTfntScript
clrScript = DEFAULTclrScript
fntEditor = DEFAULTfntEditor
clrEditor = DEFAULTclrEditor
iPreviewRows = DEFAULTiPreviewRows
iMaxRows = DEFAULTiMaxRows
strComment = DEFAULTstrComment
strGraphDisplayOption = DEFAULTstrGraphDisplayOption
'TODO is this sensible?
SetLanguageCultureCode(Thread.CurrentThread.CurrentCulture.Name)
SetWorkingDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
SetColorPalette(({Color.Aqua, Color.Gray, Color.LightGreen, Color.AliceBlue, Color.Maroon, Color.Green, Color.LightPink, Color.LightSkyBlue, Color.Brown, Color.MediumPurple, Color.White}).ToList)
strLanguageCultureCode = DEFAULTstrLanguageCultureCode
strWorkingDirectory = DEFAULTstrWorkingDirectory
SetColorPalette(DEFAULTlstColourPalette)
iDigits = DEFAULTiDigits
bShowSignifStars = DEFAULTbShowSignifStars
If bSetOptions Then
SetOptions()
End If
End Sub

Public Sub SetOptions()
If fntOutput IsNot Nothing AndAlso clrOutput <> Color.Empty Then
SetFormatOutput(fntOutput, clrOutput)
Else
SetFormatOutput(DEFAULTfntOutput, DEFAULTclrOutput)
End If

If fntComment IsNot Nothing AndAlso clrComment <> Color.Empty Then
SetFormatComment(fntComment, clrComment)
Else
SetFormatComment(DEFAULTfntComment, DEFAULTclrComment)
End If

If fntScript IsNot Nothing AndAlso clrScript <> Color.Empty Then
SetFormatScript(fntScript, clrScript)
Else
SetFormatScript(DEFAULTfntScript, DEFAULTclrScript)
End If

If fntEditor IsNot Nothing AndAlso clrEditor <> Color.Empty Then
SetFormatEditor(fntEditor, clrEditor)
Else
SetFormatEditor(DEFAULTfntEditor, DEFAULTclrEditor)
End If

If iPreviewRows.HasValue Then
SetPreviewRows(iPreviewRows)
Else
SetPreviewRows(DEFAULTiPreviewRows)
End If

If iMaxRows.HasValue Then
SetMaxRows(iMaxRows)
Else
SetMaxRows(DEFAULTiMaxRows)
End If

If bCommandsinOutput.HasValue Then
SetCommandInOutpt(bCommandsinOutput)
Else
SetCommandInOutpt(DEFAULTbCommandsinOutput)
End If

If strComment IsNot Nothing Then
SetComment(strComment)
Else
SetComment(DEFAULTstrComment)
End If

If strGraphDisplayOption IsNot Nothing Then
SetGraphDisplayOption(strGraphDisplayOption)
Else
SetGraphDisplayOption(DEFAULTstrGraphDisplayOption)
End If

If strLanguageCultureCode IsNot Nothing Then
SetLanguageCultureCode(strLanguageCultureCode)
Else
SetLanguageCultureCode(DEFAULTstrLanguageCultureCode)
End If

If strWorkingDirectory IsNot Nothing Then
SetWorkingDirectory(strWorkingDirectory)
Else
SetWorkingDirectory(DEFAULTstrWorkingDirectory)
End If

If iDigits.HasValue Then
SetDigits(iDigits)
Else
SetDigits(DEFAULTiDigits)
End If

If bShowSignifStars.HasValue Then
SetSignifStars(bShowSignifStars)
Else
SetSignifStars(DEFAULTbShowSignifStars)
End If
End Sub

Public Sub SetMaxRows(iRows As Integer)
Expand All @@ -47,7 +163,7 @@ Imports unvell.ReoGrid
frmMain.clsRLink.setFormatOutput(fntOutput, clrOutput)
End Sub

Public Sub SetFormatCommand(fntNew As Font, clrNew As Color)
Public Sub SetFormatScript(fntNew As Font, clrNew As Color)
fntScript = fntNew
clrScript = clrNew
frmMain.clsRLink.setFormatScript(fntScript, clrScript)
Expand All @@ -59,7 +175,7 @@ Imports unvell.ReoGrid
frmMain.clsRLink.setFormatComment(fntComment, clrComment)
End Sub

Public Sub SetEditorFormat(fntNew As Font, clrNew As Color)
Public Sub SetFormatEditor(fntNew As Font, clrNew As Color)
fntEditor = fntNew
clrEditor = clrNew
frmMain.clsGrids.SetFormatDataView(fntEditor, clrEditor)
Expand Down Expand Up @@ -96,8 +212,14 @@ Imports unvell.ReoGrid
End Sub

Public Sub SetWorkingDirectory(strWD As String)
Dim clsSetwdFunction As New RFunction

clsSetwdFunction.SetRCommand("setwd")
clsSetwdFunction.AddParameter("dir", Chr(34) & strWorkingDirectory & Chr(34))
strWorkingDirectory = strWD
'frmMain.clsRLink.RunScript("setwd(" & Chr(34) & strWorkingDirectory & Chr(34) & ")")
'This is done in R link setup. Need to rethink how this is done.
'Commented out for now to not repeat.
'frmMain.clsRLink.RunScript(clsSetwdFunction.ToScript(), strComment:="Option: Setting working directory")
End Sub

Public Sub SetColorPalette(lstColours As List(Of Color))
Expand All @@ -118,4 +240,40 @@ Imports unvell.ReoGrid
Public Sub SetCommentsInOutput(bComment As Boolean)
bCommandsinOutput = bComment
End Sub

Public Sub SetDigits(iNewDigits As Integer)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionFunction As New RFunction

If iNewDigits > 22 OrElse iNewDigits < 0 Then
MsgBox("Cannot set digits to: " & iNewDigits & ". Digits must be an integer between 0 and 22.", MsgBoxStyle.Critical, "Error setting digits")
Else
iDigits = iNewDigits
clsGetOptionFunction.SetRCommand("getOption")
clsGetOptionFunction.AddParameter("x", Chr(34) & "digits" & Chr(34))
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionFunction.ToScript()).AsInteger(0) <> iDigits Then
clsOptionsFunction.SetRCommand("options")
clsOptionsFunction.AddParameter("digits", iDigits)
frmMain.clsRLink.RunScript(clsOptionsFunction.ToScript(), strComment:="Option: Number of digits to display")
End If
End If
End Sub

Public Sub SetSignifStars(bShowStars As Boolean)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionsFunction As New RFunction

bShowSignifStars = bShowStars
clsGetOptionsFunction.SetRCommand("getOption")
clsGetOptionsFunction.AddParameter("x", Chr(34) & "show.signif.stars" & Chr(34))
clsOptionsFunction.SetRCommand("options")
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionsFunction.ToScript()).AsLogical(0) <> bShowSignifStars Then
If bShowSignifStars Then
clsOptionsFunction.AddParameter("show.signif.stars", "TRUE")
Else
clsOptionsFunction.AddParameter("show.signif.stars", "FALSE")
End If
frmMain.clsRLink.RunScript(clsOptionsFunction.ToScript(), strComment:="Option: Show stars on summary tables of coefficients")
End If
End Sub
End Class
6 changes: 3 additions & 3 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ Public Class RLink
'run script to load libraries
frmMain.Cursor = Cursors.WaitCursor
frmSetupLoading.Show()
RunScript("setwd('" & frmMain.strStaticPath.Replace("\", "/") & strInstatObjectPath & "')") 'This is bad the wd should be flexible and not automatically set to the instat object directory
RunScript("source(" & Chr(34) & "Rsetup.R" & Chr(34) & ")")
RunScript("setwd('" & frmMain.strStaticPath.Replace("\", "/") & strInstatObjectPath & "')", strComment:="Setting the working directory") 'This is bad the wd should be flexible and not automatically set to the instat object directory
RunScript("source(" & Chr(34) & "Rsetup.R" & Chr(34) & ")", strComment:="Sourcing the Instat Object R code")
CreateNewInstatObject()
frmSetupLoading.Close()
frmMain.Cursor = Cursors.Default
End Sub

Public Sub CreateNewInstatObject()
RunScript(strInstatDataObject & " <- instat_object$new()")
RunScript(strInstatDataObject & " <- instat_object$new()", strComment:="Defining new Instat Object")
bInstatObjectExists = True
End Sub

Expand Down
Loading

0 comments on commit 8d62331

Please sign in to comment.