diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index a212e73cbe9..e0fc9f0dbe9 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -752,6 +752,15 @@ Public Class RLink Return strOut End Function + Public Function IsValidText(strText As String) As String + Dim bValid As Boolean + Dim strValidText As String + Dim clsMakeNames As New RFunction + + strValidText = MakeValidText(strText) + Return (strText = strValidText) + End Function + 'Corruption analysis functions Public Function GetCorruptionContractDataFrameNames() As List(Of String) Dim clsGetDataNames As New RFunction diff --git a/instat/dlgNewSummaryTables.Designer.vb b/instat/dlgNewSummaryTables.Designer.vb index c8c710da4a0..986f3501275 100644 --- a/instat/dlgNewSummaryTables.Designer.vb +++ b/instat/dlgNewSummaryTables.Designer.vb @@ -25,12 +25,12 @@ Partial Class dlgNewSummaryTables Me.lblFactors = New System.Windows.Forms.Label() Me.lblSummaryColumns = New System.Windows.Forms.Label() Me.GroupBox1 = New System.Windows.Forms.GroupBox() - Me.lblDecimals = New System.Windows.Forms.Label() - Me.lblColumnFactors = New System.Windows.Forms.Label() - Me.cmdSummaries = New System.Windows.Forms.Button() Me.ucrNudDecimals = New instat.ucrNud() + Me.lblDecimals = New System.Windows.Forms.Label() Me.ucrNudColumnFactors = New instat.ucrNud() + Me.lblColumnFactors = New System.Windows.Forms.Label() Me.ucrchkCheckDisplayMargins = New instat.ucrCheck() + Me.cmdSummaries = New System.Windows.Forms.Button() Me.ucrchkCheckSummaries = New instat.ucrCheck() Me.ucrBase = New instat.ucrButtons() Me.ucrReceiverNumeric = New instat.ucrReceiverMultiple() @@ -44,7 +44,7 @@ Partial Class dlgNewSummaryTables 'lblFactors ' Me.lblFactors.AutoSize = True - Me.lblFactors.Location = New System.Drawing.Point(265, 45) + Me.lblFactors.Location = New System.Drawing.Point(264, 45) Me.lblFactors.Name = "lblFactors" Me.lblFactors.Size = New System.Drawing.Size(45, 13) Me.lblFactors.TabIndex = 1 @@ -54,7 +54,7 @@ Partial Class dlgNewSummaryTables 'lblSummaryColumns ' Me.lblSummaryColumns.AutoSize = True - Me.lblSummaryColumns.Location = New System.Drawing.Point(266, 170) + Me.lblSummaryColumns.Location = New System.Drawing.Point(264, 170) Me.lblSummaryColumns.Name = "lblSummaryColumns" Me.lblSummaryColumns.Size = New System.Drawing.Size(96, 13) Me.lblSummaryColumns.TabIndex = 3 @@ -75,35 +75,6 @@ Partial Class dlgNewSummaryTables Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Layout:" ' - 'lblDecimals - ' - Me.lblDecimals.AutoSize = True - Me.lblDecimals.Location = New System.Drawing.Point(5, 65) - Me.lblDecimals.Name = "lblDecimals" - Me.lblDecimals.Size = New System.Drawing.Size(53, 13) - Me.lblDecimals.TabIndex = 3 - Me.lblDecimals.Tag = "Decimals" - Me.lblDecimals.Text = "Decimals:" - ' - 'lblColumnFactors - ' - Me.lblColumnFactors.AutoSize = True - Me.lblColumnFactors.Location = New System.Drawing.Point(5, 42) - Me.lblColumnFactors.Name = "lblColumnFactors" - Me.lblColumnFactors.Size = New System.Drawing.Size(83, 13) - Me.lblColumnFactors.TabIndex = 1 - Me.lblColumnFactors.Tag = "Column_Factors" - Me.lblColumnFactors.Text = "Column Factors:" - ' - 'cmdSummaries - ' - Me.cmdSummaries.Location = New System.Drawing.Point(309, 288) - Me.cmdSummaries.Name = "cmdSummaries" - Me.cmdSummaries.Size = New System.Drawing.Size(75, 23) - Me.cmdSummaries.TabIndex = 9 - Me.cmdSummaries.Text = "Summaries" - Me.cmdSummaries.UseVisualStyleBackColor = True - ' 'ucrNudDecimals ' Me.ucrNudDecimals.DecimalPlaces = New Decimal(New Integer() {0, 0, 0, 0}) @@ -116,6 +87,16 @@ Partial Class dlgNewSummaryTables Me.ucrNudDecimals.TabIndex = 4 Me.ucrNudDecimals.Value = New Decimal(New Integer() {0, 0, 0, 0}) ' + 'lblDecimals + ' + Me.lblDecimals.AutoSize = True + Me.lblDecimals.Location = New System.Drawing.Point(5, 65) + Me.lblDecimals.Name = "lblDecimals" + Me.lblDecimals.Size = New System.Drawing.Size(53, 13) + Me.lblDecimals.TabIndex = 3 + Me.lblDecimals.Tag = "Decimals" + Me.lblDecimals.Text = "Decimals:" + ' 'ucrNudColumnFactors ' Me.ucrNudColumnFactors.DecimalPlaces = New Decimal(New Integer() {0, 0, 0, 0}) @@ -128,6 +109,16 @@ Partial Class dlgNewSummaryTables Me.ucrNudColumnFactors.TabIndex = 2 Me.ucrNudColumnFactors.Value = New Decimal(New Integer() {0, 0, 0, 0}) ' + 'lblColumnFactors + ' + Me.lblColumnFactors.AutoSize = True + Me.lblColumnFactors.Location = New System.Drawing.Point(5, 42) + Me.lblColumnFactors.Name = "lblColumnFactors" + Me.lblColumnFactors.Size = New System.Drawing.Size(83, 13) + Me.lblColumnFactors.TabIndex = 1 + Me.lblColumnFactors.Tag = "Column_Factors" + Me.lblColumnFactors.Text = "Column Factors:" + ' 'ucrchkCheckDisplayMargins ' Me.ucrchkCheckDisplayMargins.Checked = False @@ -136,6 +127,15 @@ Partial Class dlgNewSummaryTables Me.ucrchkCheckDisplayMargins.Size = New System.Drawing.Size(104, 20) Me.ucrchkCheckDisplayMargins.TabIndex = 0 ' + 'cmdSummaries + ' + Me.cmdSummaries.Location = New System.Drawing.Point(309, 288) + Me.cmdSummaries.Name = "cmdSummaries" + Me.cmdSummaries.Size = New System.Drawing.Size(75, 23) + Me.cmdSummaries.TabIndex = 9 + Me.cmdSummaries.Text = "Summaries..." + Me.cmdSummaries.UseVisualStyleBackColor = True + ' 'ucrchkCheckSummaries ' Me.ucrchkCheckSummaries.Checked = False diff --git a/instat/dlgStack.Designer.vb b/instat/dlgStack.Designer.vb index cd706d60a0a..14cb3d1b96f 100644 --- a/instat/dlgStack.Designer.vb +++ b/instat/dlgStack.Designer.vb @@ -25,24 +25,22 @@ Partial Class dlgStack Me.lblColumnsTostack = New System.Windows.Forms.Label() Me.lblStackDataInto = New System.Windows.Forms.Label() Me.lblFactorInto = New System.Windows.Forms.Label() - Me.lblNewDataFrameName = New System.Windows.Forms.Label() Me.ucrChkCarryColumns = New instat.ucrCheck() - Me.ucrNewDataName = New instat.ucrInputTextBox() Me.ucrStackDataInto = New instat.ucrInputTextBox() Me.ucrFactorInto = New instat.ucrInputTextBox() Me.ucrColumnsToCarryReceiver = New instat.ucrReceiverMultiple() Me.ucrSelectorStack = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrBase = New instat.ucrButtons() Me.ucrReceiverColumnsToBeStack = New instat.ucrReceiverMultiple() + Me.ucrSaveNewDataName = New instat.ucrSave() Me.SuspendLayout() ' 'lblColumnsTostack ' Me.lblColumnsTostack.AutoSize = True - Me.lblColumnsTostack.Location = New System.Drawing.Point(381, 32) - Me.lblColumnsTostack.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblColumnsTostack.Location = New System.Drawing.Point(285, 26) Me.lblColumnsTostack.Name = "lblColumnsTostack" - Me.lblColumnsTostack.Size = New System.Drawing.Size(121, 17) + Me.lblColumnsTostack.Size = New System.Drawing.Size(93, 13) Me.lblColumnsTostack.TabIndex = 1 Me.lblColumnsTostack.Tag = "Columns_to_Stack:" Me.lblColumnsTostack.Text = "Columns to Stack:" @@ -50,123 +48,108 @@ Partial Class dlgStack 'lblStackDataInto ' Me.lblStackDataInto.AutoSize = True - Me.lblStackDataInto.Location = New System.Drawing.Point(13, 316) - Me.lblStackDataInto.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblStackDataInto.Location = New System.Drawing.Point(10, 263) Me.lblStackDataInto.Name = "lblStackDataInto" - Me.lblStackDataInto.Size = New System.Drawing.Size(108, 17) - Me.lblStackDataInto.TabIndex = 9 + Me.lblStackDataInto.Size = New System.Drawing.Size(85, 13) + Me.lblStackDataInto.TabIndex = 8 Me.lblStackDataInto.Tag = "Stack_Data_Into" Me.lblStackDataInto.Text = "Stack Data Into:" ' 'lblFactorInto ' Me.lblFactorInto.AutoSize = True - Me.lblFactorInto.Location = New System.Drawing.Point(13, 284) - Me.lblFactorInto.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblFactorInto.Location = New System.Drawing.Point(10, 234) Me.lblFactorInto.Name = "lblFactorInto" - Me.lblFactorInto.Size = New System.Drawing.Size(79, 17) - Me.lblFactorInto.TabIndex = 7 + Me.lblFactorInto.Size = New System.Drawing.Size(61, 13) + Me.lblFactorInto.TabIndex = 6 Me.lblFactorInto.Tag = "Factor_Into" Me.lblFactorInto.Text = "Factor Into:" ' - 'lblNewDataFrameName - ' - Me.lblNewDataFrameName.AutoSize = True - Me.lblNewDataFrameName.Location = New System.Drawing.Point(13, 252) - Me.lblNewDataFrameName.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) - Me.lblNewDataFrameName.Name = "lblNewDataFrameName" - Me.lblNewDataFrameName.Size = New System.Drawing.Size(158, 17) - Me.lblNewDataFrameName.TabIndex = 5 - Me.lblNewDataFrameName.Tag = "New_Data_Frame_Name:" - Me.lblNewDataFrameName.Text = "New Data Frame Name:" - ' 'ucrChkCarryColumns ' Me.ucrChkCarryColumns.Checked = False - Me.ucrChkCarryColumns.Location = New System.Drawing.Point(380, 185) - Me.ucrChkCarryColumns.Margin = New System.Windows.Forms.Padding(5) + Me.ucrChkCarryColumns.Location = New System.Drawing.Point(285, 147) + Me.ucrChkCarryColumns.Margin = New System.Windows.Forms.Padding(4) Me.ucrChkCarryColumns.Name = "ucrChkCarryColumns" - Me.ucrChkCarryColumns.Size = New System.Drawing.Size(133, 25) + Me.ucrChkCarryColumns.Size = New System.Drawing.Size(100, 20) Me.ucrChkCarryColumns.TabIndex = 3 ' - 'ucrNewDataName - ' - Me.ucrNewDataName.IsMultiline = False - Me.ucrNewDataName.IsReadOnly = False - Me.ucrNewDataName.Location = New System.Drawing.Point(175, 250) - Me.ucrNewDataName.Margin = New System.Windows.Forms.Padding(7, 6, 7, 6) - Me.ucrNewDataName.Name = "ucrNewDataName" - Me.ucrNewDataName.Size = New System.Drawing.Size(193, 26) - Me.ucrNewDataName.TabIndex = 6 - ' 'ucrStackDataInto ' + Me.ucrStackDataInto.AddQuotesIfUnrecognised = True Me.ucrStackDataInto.IsMultiline = False Me.ucrStackDataInto.IsReadOnly = False - Me.ucrStackDataInto.Location = New System.Drawing.Point(175, 311) - Me.ucrStackDataInto.Margin = New System.Windows.Forms.Padding(7, 6, 7, 6) + Me.ucrStackDataInto.Location = New System.Drawing.Point(131, 259) + Me.ucrStackDataInto.Margin = New System.Windows.Forms.Padding(5) Me.ucrStackDataInto.Name = "ucrStackDataInto" - Me.ucrStackDataInto.Size = New System.Drawing.Size(193, 26) - Me.ucrStackDataInto.TabIndex = 10 + Me.ucrStackDataInto.Size = New System.Drawing.Size(145, 21) + Me.ucrStackDataInto.TabIndex = 9 ' 'ucrFactorInto ' + Me.ucrFactorInto.AddQuotesIfUnrecognised = True Me.ucrFactorInto.IsMultiline = False Me.ucrFactorInto.IsReadOnly = False - Me.ucrFactorInto.Location = New System.Drawing.Point(175, 281) - Me.ucrFactorInto.Margin = New System.Windows.Forms.Padding(7, 6, 7, 6) + Me.ucrFactorInto.Location = New System.Drawing.Point(131, 230) + Me.ucrFactorInto.Margin = New System.Windows.Forms.Padding(5) Me.ucrFactorInto.Name = "ucrFactorInto" - Me.ucrFactorInto.Size = New System.Drawing.Size(193, 26) - Me.ucrFactorInto.TabIndex = 8 + Me.ucrFactorInto.Size = New System.Drawing.Size(145, 21) + Me.ucrFactorInto.TabIndex = 7 ' 'ucrColumnsToCarryReceiver ' Me.ucrColumnsToCarryReceiver.frmParent = Me - Me.ucrColumnsToCarryReceiver.Location = New System.Drawing.Point(380, 213) + Me.ucrColumnsToCarryReceiver.Location = New System.Drawing.Point(285, 173) Me.ucrColumnsToCarryReceiver.Margin = New System.Windows.Forms.Padding(0) Me.ucrColumnsToCarryReceiver.Name = "ucrColumnsToCarryReceiver" Me.ucrColumnsToCarryReceiver.Selector = Nothing - Me.ucrColumnsToCarryReceiver.Size = New System.Drawing.Size(160, 123) + Me.ucrColumnsToCarryReceiver.Size = New System.Drawing.Size(120, 107) Me.ucrColumnsToCarryReceiver.TabIndex = 4 ' 'ucrSelectorStack ' Me.ucrSelectorStack.bShowHiddenColumns = False Me.ucrSelectorStack.bUseCurrentFilter = True - Me.ucrSelectorStack.Location = New System.Drawing.Point(13, 12) + Me.ucrSelectorStack.Location = New System.Drawing.Point(10, 10) Me.ucrSelectorStack.Margin = New System.Windows.Forms.Padding(0) Me.ucrSelectorStack.Name = "ucrSelectorStack" - Me.ucrSelectorStack.Size = New System.Drawing.Size(280, 222) + Me.ucrSelectorStack.Size = New System.Drawing.Size(210, 180) Me.ucrSelectorStack.TabIndex = 0 ' 'ucrBase ' - Me.ucrBase.Location = New System.Drawing.Point(13, 345) - Me.ucrBase.Margin = New System.Windows.Forms.Padding(5) + Me.ucrBase.Location = New System.Drawing.Point(10, 286) + Me.ucrBase.Margin = New System.Windows.Forms.Padding(4) Me.ucrBase.Name = "ucrBase" - Me.ucrBase.Size = New System.Drawing.Size(547, 64) - Me.ucrBase.TabIndex = 11 + Me.ucrBase.Size = New System.Drawing.Size(410, 52) + Me.ucrBase.TabIndex = 10 ' 'ucrReceiverColumnsToBeStack ' Me.ucrReceiverColumnsToBeStack.frmParent = Me - Me.ucrReceiverColumnsToBeStack.Location = New System.Drawing.Point(380, 50) + Me.ucrReceiverColumnsToBeStack.Location = New System.Drawing.Point(285, 41) Me.ucrReceiverColumnsToBeStack.Margin = New System.Windows.Forms.Padding(0) Me.ucrReceiverColumnsToBeStack.Name = "ucrReceiverColumnsToBeStack" Me.ucrReceiverColumnsToBeStack.Selector = Nothing - Me.ucrReceiverColumnsToBeStack.Size = New System.Drawing.Size(160, 123) + Me.ucrReceiverColumnsToBeStack.Size = New System.Drawing.Size(120, 100) Me.ucrReceiverColumnsToBeStack.TabIndex = 2 ' + 'ucrSaveNewDataName + ' + Me.ucrSaveNewDataName.Location = New System.Drawing.Point(10, 200) + Me.ucrSaveNewDataName.Name = "ucrSaveNewDataName" + Me.ucrSaveNewDataName.Size = New System.Drawing.Size(266, 20) + Me.ucrSaveNewDataName.TabIndex = 5 + ' 'dlgStack ' - Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(559, 417) + Me.ClientSize = New System.Drawing.Size(419, 349) + Me.Controls.Add(Me.ucrSaveNewDataName) Me.Controls.Add(Me.ucrChkCarryColumns) - Me.Controls.Add(Me.ucrNewDataName) Me.Controls.Add(Me.ucrStackDataInto) Me.Controls.Add(Me.ucrFactorInto) - Me.Controls.Add(Me.lblNewDataFrameName) Me.Controls.Add(Me.ucrColumnsToCarryReceiver) Me.Controls.Add(Me.ucrSelectorStack) Me.Controls.Add(Me.ucrBase) @@ -175,7 +158,6 @@ Partial Class dlgStack Me.Controls.Add(Me.lblColumnsTostack) Me.Controls.Add(Me.ucrReceiverColumnsToBeStack) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow - Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "dlgStack" @@ -193,9 +175,8 @@ Partial Class dlgStack Friend WithEvents ucrBase As ucrButtons Friend WithEvents ucrSelectorStack As ucrSelectorByDataFrameAddRemove Friend WithEvents ucrColumnsToCarryReceiver As ucrReceiverMultiple - Friend WithEvents lblNewDataFrameName As Label Friend WithEvents ucrFactorInto As ucrInputTextBox Friend WithEvents ucrStackDataInto As ucrInputTextBox - Friend WithEvents ucrNewDataName As ucrInputTextBox Friend WithEvents ucrChkCarryColumns As ucrCheck + Friend WithEvents ucrSaveNewDataName As ucrSave End Class diff --git a/instat/dlgStack.vb b/instat/dlgStack.vb index 50de4cc0971..e3d46b3d8bf 100644 --- a/instat/dlgStack.vb +++ b/instat/dlgStack.vb @@ -16,115 +16,138 @@ Imports instat.Translations Public Class dlgStack Private clsMelt As New RFunction - Public bFirstLoad As Boolean = True + Private bFirstLoad As Boolean = True + Private bReset As Boolean = True Private Sub dlgStack_Load(sender As Object, e As EventArgs) Handles MyBase.Load autoTranslate(Me) - If bFirstLoad Then + If bFirstLoad Then InitialiseDialog() - SetDefaults() bFirstLoad = False - Else - ReopenDialog() End If + If bReset Then + SetDefaults() + End If + SetRCodeForControls(bReset) + bReset = False TestOKEnabled() End Sub + Private Sub SetRCodeForControls(bReset As Boolean) + SetRCode(Me, ucrBase.clsRsyntax.clsBaseFunction, bReset) + If bReset Then + SetCarryColumnsOptions() + End If + End Sub + Private Sub InitialiseDialog() ucrBase.iHelpTopicID = 57 - ucrReceiverColumnsToBeStack.Selector = ucrSelectorStack - ucrColumnsToCarryReceiver.Selector = ucrSelectorStack - ucrReceiverColumnsToBeStack.SetMeAsReceiver() + ucrSelectorStack.SetParameter(New RParameter("data", 0)) ucrSelectorStack.SetParameterIsrfunction() - ucrChkCarryColumns.SetText("Carry Columns") - ucrFactorInto.SetName("variable") - ucrStackDataInto.SetName("value") + + ucrReceiverColumnsToBeStack.Selector = ucrSelectorStack ucrReceiverColumnsToBeStack.SetParameter(New RParameter("measure.vars", 1)) ucrReceiverColumnsToBeStack.SetParameterIsString() + + ucrColumnsToCarryReceiver.Selector = ucrSelectorStack ucrColumnsToCarryReceiver.SetParameter(New RParameter("id.vars", 2)) ucrColumnsToCarryReceiver.SetParameterIsString() + ucrColumnsToCarryReceiver.bAddRemoveParameter = False + ucrColumnsToCarryReceiver.SetValuesToIgnore({"NULL"}) + + ucrChkCarryColumns.SetText("Carry Columns") + ucrChkCarryColumns.AddParameterValuesCondition(True, "id.vars", "NULL", False) + ucrChkCarryColumns.AddParameterValuesCondition(False, "id.vars", "NULL") + ' I would like to do this since the checkbox also controls the value of id.vars + ' but there is confusion with both controls setting the value of the same parameter at the same time. For now the writing is done manually in this dialog. + 'ucrChkCarryColumns.SetParameter(ucrColumnsToCarryReceiver.GetParameter(), bNewChangeParameterValue:=True, bNewAddRemoveParameter:=True, strNewValueIfChecked:="", strNewValueIfUnchecked:="NULL") + 'We don't want the receiver to remove the parameter when the checkbox is unchecked since the id.vars parameter will always be given. + ucrChkCarryColumns.AddToLinkedControls(ucrColumnsToCarryReceiver, {True}, bNewLinkedAddRemoveParameter:=False, bNewLinkedHideIfParameterMissing:=True) + ucrFactorInto.SetParameter(New RParameter("variable.name", 3)) + ucrFactorInto.SetValidationTypeAsRVariable() + ucrStackDataInto.SetParameter(New RParameter("value.name", 4)) - ucrNewDataName.SetValidationTypeAsRVariable() - 'TODO Should this be enforced for column names? - 'ucrStackDataInto.SetValidationTypeAsRVariable() - 'ucrFactorInto.SetValidationTypeAsRVariable() ucrStackDataInto.SetValidationTypeAsRVariable() - clsMelt.AddParameter("variable.name", Chr(34) & ucrFactorInto.GetText() & Chr(34)) - clsMelt.SetRCommand("melt") + + ucrSaveNewDataName.SetIsTextBox() + ucrSaveNewDataName.SetLabelText("New Data Frame Name:") + ucrSaveNewDataName.SetSaveTypeAsDataFrame() + ucrSaveNewDataName.SetDataFrameSelector(ucrSelectorStack.ucrAvailableDataFrames) End Sub - Private Sub ReopenDialog() - 'TODO this is a work around for AssignTo not clearing in RSyntax - If ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" Then - ucrNewDataName.SetName(ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_stacked") + Private Sub SetDataFrameName() + If ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" AndAlso (Not ucrSaveNewDataName.bUserTyped) Then + ucrSaveNewDataName.SetName(ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_stacked") End If End Sub Private Sub TestOKEnabled() - If ucrReceiverColumnsToBeStack.IsEmpty() OrElse ucrNewDataName.IsEmpty() OrElse ucrStackDataInto.IsEmpty() OrElse ucrFactorInto.IsEmpty() Then - ucrBase.OKEnabled(False) + If ucrSaveNewDataName.IsComplete AndAlso Not ucrStackDataInto.IsEmpty() AndAlso Not ucrFactorInto.IsEmpty() Then + If Not ucrChkCarryColumns.Checked Then + If Not ucrReceiverColumnsToBeStack.IsEmpty() Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If + Else + If Not ucrColumnsToCarryReceiver.IsEmpty Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If + End If Else - ucrBase.OKEnabled(True) + ucrBase.OKEnabled(False) End If End Sub Private Sub SetDefaults() - ucrNewDataName.Reset() + clsMelt = New RFunction + + ucrSelectorStack.Reset() + ucrSaveNewDataName.Reset() ucrStackDataInto.Reset() ucrFactorInto.Reset() - ucrSelectorStack.Reset() ucrReceiverColumnsToBeStack.SetMeAsReceiver() - ucrChkCarryColumns.Checked = False - SetColumnsToCarryProperties() - AddSuffix() - ucrBase.clsRsyntax.SetBaseRFunction(clsMelt.Clone()) - SetRCode(Me, ucrBase.clsRsyntax.clsBaseFunction, True) - End Sub - - Private Sub chkIDVariables_CheckedChanged() Handles ucrChkCarryColumns.ControlValueChanged - SetColumnsToCarryProperties() - End Sub - Private Sub SetColumnsToCarryProperties() - If ucrChkCarryColumns.Checked Then - ucrColumnsToCarryReceiver.Visible = True - ucrColumnsToCarryReceiver.SetMeAsReceiver() - Else - ucrColumnsToCarryReceiver.Visible = False - ucrReceiverColumnsToBeStack.SetMeAsReceiver() - End If - End Sub - - Private Sub AddSuffix() - If (Not ucrNewDataName.bUserTyped) AndAlso ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" Then - ucrNewDataName.SetName(ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_stacked") - End If - End Sub + clsMelt.SetRCommand("melt") + clsMelt.AddParameter("variable.name", Chr(34) & "variable" & Chr(34)) + clsMelt.AddParameter("value.name", Chr(34) & "value" & Chr(34)) + clsMelt.AddParameter("id.vars", "NULL") + clsMelt.SetAssignTo(ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_stacked", strTempDataframe:=ucrSelectorStack.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_stacked") - Private Sub chkIDVariables_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ucrChkCarryColumns.KeyPress - If e.KeyChar = vbCr Then - ucrChkCarryColumns.Checked = Not ucrChkCarryColumns.Checked - End If + ucrBase.clsRsyntax.SetBaseRFunction(clsMelt) End Sub Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset SetDefaults() + SetRCodeForControls(True) TestOKEnabled() End Sub - Private Sub ucrReceiverColumnsToBeStack_ControlContentesChanged(ucrChangedControl As ucrCore) Handles ucrReceiverColumnsToBeStack.ControlContentsChanged, ucrNewDataName.ControlContentsChanged, ucrStackDataInto.ControlContentsChanged, ucrFactorInto.ControlContentsChanged, ucrNewDataName.ControlContentsChanged + Private Sub ucrReceiverColumnsToBeStack_ControlContentesChanged(ucrChangedControl As ucrCore) Handles ucrReceiverColumnsToBeStack.ControlContentsChanged, ucrStackDataInto.ControlContentsChanged, ucrFactorInto.ControlContentsChanged, ucrSaveNewDataName.ControlContentsChanged, ucrChkCarryColumns.ControlContentsChanged, ucrColumnsToCarryReceiver.ControlContentsChanged TestOKEnabled() End Sub - Private Sub ucrNewDataName_CotrolValueChanged(ucrChangedControl As ucrCore) Handles ucrNewDataName.ControlValueChanged - NewDataName() + Private Sub ucrChkCarryColumns_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkCarryColumns.ControlValueChanged + SetCarryColumnsOptions() End Sub - Private Sub NewDataName() - If Not ucrNewDataName.IsEmpty Then - clsMelt.SetAssignTo(ucrNewDataName.GetText(), strTempDataframe:=ucrNewDataName.GetText()) + + Private Sub SetCarryColumnsOptions() + If ucrChkCarryColumns.Checked Then + ucrColumnsToCarryReceiver.SetMeAsReceiver() + If Not ucrColumnsToCarryReceiver.IsEmpty() Then + clsMelt.AddParameter("id.vars", ucrColumnsToCarryReceiver.GetVariableNames()) + End If Else - ucrBase.clsRsyntax.RemoveAssignTo() + ucrReceiverColumnsToBeStack.SetMeAsReceiver() + clsMelt.AddParameter("id.vars", "NULL") End If End Sub + + Private Sub ucrSelectorStack_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorStack.ControlValueChanged + SetDataFrameName() + SetCarryColumnsOptions() + End Sub End Class diff --git a/instat/dlgSummaryTables.designer.vb b/instat/dlgSummaryTables.designer.vb index a650082744a..b1484065e81 100644 --- a/instat/dlgSummaryTables.designer.vb +++ b/instat/dlgSummaryTables.designer.vb @@ -1,9 +1,9 @@ - _ + Partial Class dlgSummaryTables Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. - _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then @@ -20,237 +20,231 @@ Partial Class dlgSummaryTables 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. - _ + Private Sub InitializeComponent() Me.ucrBase = New instat.ucrButtons() - Me.ucrAddRemove = New instat.ucrSelectorAddRemove() - Me.ucrReceiverFactor = New instat.ucrReceiverMultiple() - Me.ucrReceiverVariate = New instat.ucrReceiverMultiple() Me.lblFactors = New System.Windows.Forms.Label() Me.lblVariates = New System.Windows.Forms.Label() Me.grpTwoways = New System.Windows.Forms.GroupBox() Me.lblDecimals = New System.Windows.Forms.Label() - Me.nudDecimals = New System.Windows.Forms.NumericUpDown() Me.lblColumnFactors = New System.Windows.Forms.Label() - Me.txtColumnFactors = New System.Windows.Forms.TextBox() - Me.chkDisplayMargins = New System.Windows.Forms.CheckBox() Me.grpSummaryStat = New System.Windows.Forms.GroupBox() Me.cmdMore = New System.Windows.Forms.Button() - Me.chkMeans = New System.Windows.Forms.CheckBox() - Me.chkTotals = New System.Windows.Forms.CheckBox() Me.cboWeights = New System.Windows.Forms.ComboBox() - Me.chkWeights = New System.Windows.Forms.CheckBox() - Me.chkTobeImplementedLater = New System.Windows.Forms.CheckBox() + Me.ucrSelectorSummaryTables = New instat.ucrSelectorByDataFrameAddRemove() + Me.ucrReceiverFactor = New instat.ucrReceiverMultiple() + Me.ucrReceiverVariate = New instat.ucrReceiverMultiple() + Me.ucrChkDisplayMargins = New instat.ucrCheck() + Me.ucrChkMeans = New instat.ucrCheck() + Me.ucrChkTotals = New instat.ucrCheck() + Me.ucrChkTrtSCFactor = New instat.ucrCheck() + Me.ucrChkWeights = New instat.ucrCheck() + Me.ucrInputColumnFactors = New instat.ucrInputTextBox() + Me.ucrNudDecimals = New instat.ucrNud() Me.grpTwoways.SuspendLayout() - CType(Me.nudDecimals, System.ComponentModel.ISupportInitialize).BeginInit() Me.grpSummaryStat.SuspendLayout() Me.SuspendLayout() ' 'ucrBase ' - Me.ucrBase.Location = New System.Drawing.Point(2, 295) + Me.ucrBase.Location = New System.Drawing.Point(10, 384) Me.ucrBase.Name = "ucrBase" Me.ucrBase.Size = New System.Drawing.Size(407, 55) Me.ucrBase.TabIndex = 0 ' - 'ucrAddRemove - ' - Me.ucrAddRemove.bShowHiddenColumns = False - Me.ucrAddRemove.Location = New System.Drawing.Point(2, 3) - Me.ucrAddRemove.Margin = New System.Windows.Forms.Padding(0) - Me.ucrAddRemove.Name = "ucrAddRemove" - Me.ucrAddRemove.Size = New System.Drawing.Size(207, 127) - Me.ucrAddRemove.TabIndex = 1 - ' - 'ucrReceiverFactor - ' - Me.ucrReceiverFactor.Location = New System.Drawing.Point(205, 19) - Me.ucrReceiverFactor.Margin = New System.Windows.Forms.Padding(0) - Me.ucrReceiverFactor.Name = "ucrReceiverFactor" - Me.ucrReceiverFactor.Selector = Nothing - Me.ucrReceiverFactor.Size = New System.Drawing.Size(91, 101) - Me.ucrReceiverFactor.TabIndex = 2 - ' - 'ucrReceiverVariate - ' - Me.ucrReceiverVariate.Location = New System.Drawing.Point(305, 19) - Me.ucrReceiverVariate.Margin = New System.Windows.Forms.Padding(0) - Me.ucrReceiverVariate.Name = "ucrReceiverVariate" - Me.ucrReceiverVariate.Selector = Nothing - Me.ucrReceiverVariate.Size = New System.Drawing.Size(91, 101) - Me.ucrReceiverVariate.TabIndex = 3 - ' 'lblFactors ' Me.lblFactors.AutoSize = True - Me.lblFactors.Location = New System.Drawing.Point(202, 3) + Me.lblFactors.Location = New System.Drawing.Point(272, 45) Me.lblFactors.Name = "lblFactors" - Me.lblFactors.Size = New System.Drawing.Size(42, 13) + Me.lblFactors.Size = New System.Drawing.Size(45, 13) Me.lblFactors.TabIndex = 4 - Me.lblFactors.Tag = "Factors" - Me.lblFactors.Text = "Factors" + Me.lblFactors.Tag = "Factors:" + Me.lblFactors.Text = "Factors:" ' 'lblVariates ' Me.lblVariates.AutoSize = True - Me.lblVariates.Location = New System.Drawing.Point(302, 3) + Me.lblVariates.Location = New System.Drawing.Point(272, 163) Me.lblVariates.Name = "lblVariates" - Me.lblVariates.Size = New System.Drawing.Size(45, 13) + Me.lblVariates.Size = New System.Drawing.Size(48, 13) Me.lblVariates.TabIndex = 5 Me.lblVariates.Tag = "Variates" - Me.lblVariates.Text = "Variates" + Me.lblVariates.Text = "Variates:" ' 'grpTwoways ' + Me.grpTwoways.Controls.Add(Me.ucrNudDecimals) + Me.grpTwoways.Controls.Add(Me.ucrInputColumnFactors) Me.grpTwoways.Controls.Add(Me.lblDecimals) - Me.grpTwoways.Controls.Add(Me.nudDecimals) Me.grpTwoways.Controls.Add(Me.lblColumnFactors) - Me.grpTwoways.Controls.Add(Me.txtColumnFactors) - Me.grpTwoways.Controls.Add(Me.chkDisplayMargins) - Me.grpTwoways.Location = New System.Drawing.Point(12, 166) + Me.grpTwoways.Controls.Add(Me.ucrChkDisplayMargins) + Me.grpTwoways.Location = New System.Drawing.Point(10, 278) Me.grpTwoways.Name = "grpTwoways" Me.grpTwoways.Size = New System.Drawing.Size(207, 100) Me.grpTwoways.TabIndex = 6 Me.grpTwoways.TabStop = False - Me.grpTwoways.Tag = "Two_ways_table(s)" - Me.grpTwoways.Text = "Two way table(s)" + Me.grpTwoways.Tag = "Two_Way_Table(s)" + Me.grpTwoways.Text = "Two Way Table(s)" ' 'lblDecimals ' Me.lblDecimals.AutoSize = True - Me.lblDecimals.Location = New System.Drawing.Point(6, 77) + Me.lblDecimals.Location = New System.Drawing.Point(6, 73) Me.lblDecimals.Name = "lblDecimals" - Me.lblDecimals.Size = New System.Drawing.Size(50, 13) + Me.lblDecimals.Size = New System.Drawing.Size(53, 13) Me.lblDecimals.TabIndex = 4 - Me.lblDecimals.Tag = "Decimals" - Me.lblDecimals.Text = "Decimals" - ' - 'nudDecimals - ' - Me.nudDecimals.AllowDrop = True - Me.nudDecimals.Location = New System.Drawing.Point(95, 75) - Me.nudDecimals.Maximum = New Decimal(New Integer() {5, 0, 0, 0}) - Me.nudDecimals.Name = "nudDecimals" - Me.nudDecimals.Size = New System.Drawing.Size(44, 20) - Me.nudDecimals.TabIndex = 3 + Me.lblDecimals.Tag = "Decimals:" + Me.lblDecimals.Text = "Decimals:" ' 'lblColumnFactors ' Me.lblColumnFactors.AutoSize = True Me.lblColumnFactors.Location = New System.Drawing.Point(6, 46) Me.lblColumnFactors.Name = "lblColumnFactors" - Me.lblColumnFactors.Size = New System.Drawing.Size(77, 13) + Me.lblColumnFactors.Size = New System.Drawing.Size(83, 13) Me.lblColumnFactors.TabIndex = 2 - Me.lblColumnFactors.Tag = "Column_factors" - Me.lblColumnFactors.Text = "Column factors" - ' - 'txtColumnFactors - ' - Me.txtColumnFactors.Location = New System.Drawing.Point(95, 42) - Me.txtColumnFactors.Name = "txtColumnFactors" - Me.txtColumnFactors.Size = New System.Drawing.Size(29, 20) - Me.txtColumnFactors.TabIndex = 1 - ' - 'chkDisplayMargins - ' - Me.chkDisplayMargins.AutoSize = True - Me.chkDisplayMargins.Location = New System.Drawing.Point(23, 19) - Me.chkDisplayMargins.Name = "chkDisplayMargins" - Me.chkDisplayMargins.Size = New System.Drawing.Size(99, 17) - Me.chkDisplayMargins.TabIndex = 0 - Me.chkDisplayMargins.Tag = "Display_margins" - Me.chkDisplayMargins.Text = "Display margins" - Me.chkDisplayMargins.UseVisualStyleBackColor = True + Me.lblColumnFactors.Tag = "Column_Factors:" + Me.lblColumnFactors.Text = "Column Factors:" ' 'grpSummaryStat ' Me.grpSummaryStat.Controls.Add(Me.cmdMore) - Me.grpSummaryStat.Controls.Add(Me.chkMeans) - Me.grpSummaryStat.Controls.Add(Me.chkTotals) - Me.grpSummaryStat.Location = New System.Drawing.Point(234, 166) + Me.grpSummaryStat.Controls.Add(Me.ucrChkMeans) + Me.grpSummaryStat.Controls.Add(Me.ucrChkTotals) + Me.grpSummaryStat.Location = New System.Drawing.Point(226, 278) Me.grpSummaryStat.Name = "grpSummaryStat" - Me.grpSummaryStat.Size = New System.Drawing.Size(151, 100) + Me.grpSummaryStat.Size = New System.Drawing.Size(182, 100) Me.grpSummaryStat.TabIndex = 7 Me.grpSummaryStat.TabStop = False Me.grpSummaryStat.Tag = "Summary_statistics" - Me.grpSummaryStat.Text = "Summary statistics" + Me.grpSummaryStat.Text = "Summary Statistics" ' 'cmdMore ' - Me.cmdMore.Location = New System.Drawing.Point(36, 65) + Me.cmdMore.Location = New System.Drawing.Point(77, 66) Me.cmdMore.Name = "cmdMore" - Me.cmdMore.Size = New System.Drawing.Size(75, 23) + Me.cmdMore.Size = New System.Drawing.Size(98, 23) Me.cmdMore.TabIndex = 2 Me.cmdMore.Tag = "More" - Me.cmdMore.Text = "More" + Me.cmdMore.Text = "More..." Me.cmdMore.UseVisualStyleBackColor = True ' - 'chkMeans - ' - Me.chkMeans.AutoSize = True - Me.chkMeans.Location = New System.Drawing.Point(7, 42) - Me.chkMeans.Name = "chkMeans" - Me.chkMeans.Size = New System.Drawing.Size(58, 17) - Me.chkMeans.TabIndex = 1 - Me.chkMeans.Tag = "Means" - Me.chkMeans.Text = "Means" - Me.chkMeans.UseVisualStyleBackColor = True - ' - 'chkTotals - ' - Me.chkTotals.AutoSize = True - Me.chkTotals.Location = New System.Drawing.Point(7, 19) - Me.chkTotals.Name = "chkTotals" - Me.chkTotals.Size = New System.Drawing.Size(55, 17) - Me.chkTotals.TabIndex = 0 - Me.chkTotals.Tag = "Totals" - Me.chkTotals.Text = "Totals" - Me.chkTotals.UseVisualStyleBackColor = True - ' 'cboWeights ' Me.cboWeights.FormattingEnabled = True - Me.cboWeights.Location = New System.Drawing.Point(205, 134) + Me.cboWeights.Location = New System.Drawing.Point(116, 200) Me.cboWeights.Name = "cboWeights" - Me.cboWeights.Size = New System.Drawing.Size(83, 21) + Me.cboWeights.Size = New System.Drawing.Size(136, 21) Me.cboWeights.TabIndex = 9 ' - 'chkWeights + 'ucrSelectorSummaryTables ' - Me.chkWeights.AutoSize = True - Me.chkWeights.Location = New System.Drawing.Point(118, 136) - Me.chkWeights.Name = "chkWeights" - Me.chkWeights.Size = New System.Drawing.Size(65, 17) - Me.chkWeights.TabIndex = 8 - Me.chkWeights.Tag = "Weights" - Me.chkWeights.Text = "Weights" - Me.chkWeights.UseVisualStyleBackColor = True + Me.ucrSelectorSummaryTables.bShowHiddenColumns = False + Me.ucrSelectorSummaryTables.bUseCurrentFilter = True + Me.ucrSelectorSummaryTables.Location = New System.Drawing.Point(10, 10) + Me.ucrSelectorSummaryTables.Margin = New System.Windows.Forms.Padding(0) + Me.ucrSelectorSummaryTables.Name = "ucrSelectorSummaryTables" + Me.ucrSelectorSummaryTables.Size = New System.Drawing.Size(210, 180) + Me.ucrSelectorSummaryTables.TabIndex = 11 ' - 'chkTobeImplementedLater + 'ucrReceiverFactor ' - Me.chkTobeImplementedLater.AutoSize = True - Me.chkTobeImplementedLater.Location = New System.Drawing.Point(12, 272) - Me.chkTobeImplementedLater.Name = "chkTobeImplementedLater" - Me.chkTobeImplementedLater.Size = New System.Drawing.Size(139, 17) - Me.chkTobeImplementedLater.TabIndex = 10 - Me.chkTobeImplementedLater.Text = "To be implemented later" - Me.chkTobeImplementedLater.UseVisualStyleBackColor = True + Me.ucrReceiverFactor.frmParent = Me + Me.ucrReceiverFactor.Location = New System.Drawing.Point(272, 60) + Me.ucrReceiverFactor.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverFactor.Name = "ucrReceiverFactor" + Me.ucrReceiverFactor.Selector = Nothing + Me.ucrReceiverFactor.Size = New System.Drawing.Size(120, 93) + Me.ucrReceiverFactor.TabIndex = 12 + ' + 'ucrReceiverVariate + ' + Me.ucrReceiverVariate.frmParent = Me + Me.ucrReceiverVariate.Location = New System.Drawing.Point(272, 178) + Me.ucrReceiverVariate.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverVariate.Name = "ucrReceiverVariate" + Me.ucrReceiverVariate.Selector = Nothing + Me.ucrReceiverVariate.Size = New System.Drawing.Size(120, 93) + Me.ucrReceiverVariate.TabIndex = 13 + ' + 'ucrChkDisplayMargins + ' + Me.ucrChkDisplayMargins.Checked = False + Me.ucrChkDisplayMargins.Location = New System.Drawing.Point(6, 19) + Me.ucrChkDisplayMargins.Name = "ucrChkDisplayMargins" + Me.ucrChkDisplayMargins.Size = New System.Drawing.Size(100, 20) + Me.ucrChkDisplayMargins.TabIndex = 16 + ' + 'ucrChkMeans + ' + Me.ucrChkMeans.Checked = False + Me.ucrChkMeans.Location = New System.Drawing.Point(11, 45) + Me.ucrChkMeans.Name = "ucrChkMeans" + Me.ucrChkMeans.Size = New System.Drawing.Size(100, 20) + Me.ucrChkMeans.TabIndex = 17 + ' + 'ucrChkTotals + ' + Me.ucrChkTotals.Checked = False + Me.ucrChkTotals.Location = New System.Drawing.Point(11, 19) + Me.ucrChkTotals.Name = "ucrChkTotals" + Me.ucrChkTotals.Size = New System.Drawing.Size(100, 20) + Me.ucrChkTotals.TabIndex = 18 + ' + 'ucrChkTrtSCFactor + ' + Me.ucrChkTrtSCFactor.Checked = False + Me.ucrChkTrtSCFactor.Location = New System.Drawing.Point(10, 227) + Me.ucrChkTrtSCFactor.Name = "ucrChkTrtSCFactor" + Me.ucrChkTrtSCFactor.Size = New System.Drawing.Size(207, 20) + Me.ucrChkTrtSCFactor.TabIndex = 19 + ' + 'ucrChkWeights + ' + Me.ucrChkWeights.Checked = False + Me.ucrChkWeights.Location = New System.Drawing.Point(10, 201) + Me.ucrChkWeights.Name = "ucrChkWeights" + Me.ucrChkWeights.Size = New System.Drawing.Size(100, 20) + Me.ucrChkWeights.TabIndex = 20 + ' + 'ucrInputColumnFactors + ' + Me.ucrInputColumnFactors.AddQuotesIfUnrecognised = True + Me.ucrInputColumnFactors.IsMultiline = False + Me.ucrInputColumnFactors.IsReadOnly = False + Me.ucrInputColumnFactors.Location = New System.Drawing.Point(89, 42) + Me.ucrInputColumnFactors.Name = "ucrInputColumnFactors" + Me.ucrInputColumnFactors.Size = New System.Drawing.Size(50, 21) + Me.ucrInputColumnFactors.TabIndex = 17 + ' + 'ucrNudDecimals + ' + Me.ucrNudDecimals.DecimalPlaces = New Decimal(New Integer() {0, 0, 0, 0}) + Me.ucrNudDecimals.Increment = New Decimal(New Integer() {1, 0, 0, 0}) + Me.ucrNudDecimals.Location = New System.Drawing.Point(89, 69) + Me.ucrNudDecimals.Maximum = New Decimal(New Integer() {100, 0, 0, 0}) + Me.ucrNudDecimals.Minimum = New Decimal(New Integer() {0, 0, 0, 0}) + Me.ucrNudDecimals.Name = "ucrNudDecimals" + Me.ucrNudDecimals.Size = New System.Drawing.Size(50, 20) + Me.ucrNudDecimals.TabIndex = 18 + Me.ucrNudDecimals.Value = New Decimal(New Integer() {0, 0, 0, 0}) ' 'dlgSummaryTables ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(408, 350) - Me.Controls.Add(Me.chkTobeImplementedLater) + Me.ClientSize = New System.Drawing.Size(417, 441) + Me.Controls.Add(Me.ucrChkWeights) + Me.Controls.Add(Me.ucrChkTrtSCFactor) + Me.Controls.Add(Me.ucrReceiverVariate) + Me.Controls.Add(Me.ucrReceiverFactor) + Me.Controls.Add(Me.ucrSelectorSummaryTables) Me.Controls.Add(Me.cboWeights) - Me.Controls.Add(Me.chkWeights) Me.Controls.Add(Me.grpSummaryStat) Me.Controls.Add(Me.grpTwoways) Me.Controls.Add(Me.lblVariates) Me.Controls.Add(Me.lblFactors) - Me.Controls.Add(Me.ucrReceiverVariate) - Me.Controls.Add(Me.ucrReceiverFactor) - Me.Controls.Add(Me.ucrAddRemove) Me.Controls.Add(Me.ucrBase) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False @@ -261,31 +255,29 @@ Partial Class dlgSummaryTables Me.Text = "Summary Tables" Me.grpTwoways.ResumeLayout(False) Me.grpTwoways.PerformLayout() - CType(Me.nudDecimals, System.ComponentModel.ISupportInitialize).EndInit() Me.grpSummaryStat.ResumeLayout(False) - Me.grpSummaryStat.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents ucrBase As ucrButtons - Friend WithEvents ucrAddRemove As ucrSelectorAddRemove - Friend WithEvents ucrReceiverFactor As ucrReceiverMultiple - Friend WithEvents ucrReceiverVariate As ucrReceiverMultiple Friend WithEvents lblFactors As Label Friend WithEvents lblVariates As Label Friend WithEvents grpTwoways As GroupBox Friend WithEvents grpSummaryStat As GroupBox Friend WithEvents cmdMore As Button - Friend WithEvents chkMeans As CheckBox - Friend WithEvents chkTotals As CheckBox Friend WithEvents cboWeights As ComboBox - Friend WithEvents chkWeights As CheckBox - Friend WithEvents chkTobeImplementedLater As CheckBox Friend WithEvents lblDecimals As Label - Friend WithEvents nudDecimals As NumericUpDown Friend WithEvents lblColumnFactors As Label - Friend WithEvents txtColumnFactors As TextBox - Friend WithEvents chkDisplayMargins As CheckBox + Friend WithEvents ucrSelectorSummaryTables As ucrSelectorByDataFrameAddRemove + Friend WithEvents ucrReceiverFactor As ucrReceiverMultiple + Friend WithEvents ucrReceiverVariate As ucrReceiverMultiple + Friend WithEvents ucrChkWeights As ucrCheck + Friend WithEvents ucrChkTrtSCFactor As ucrCheck + Friend WithEvents ucrChkTotals As ucrCheck + Friend WithEvents ucrChkMeans As ucrCheck + Friend WithEvents ucrChkDisplayMargins As ucrCheck + Friend WithEvents ucrNudDecimals As ucrNud + Friend WithEvents ucrInputColumnFactors As ucrInputTextBox End Class diff --git a/instat/dlgSummaryTables.vb b/instat/dlgSummaryTables.vb index d795f3f0c38..f5c53b36ffb 100644 --- a/instat/dlgSummaryTables.vb +++ b/instat/dlgSummaryTables.vb @@ -13,23 +13,37 @@ ' ' You should have received a copy of the GNU General Public License k ' along with this program. If not, see . -Imports instat Imports instat.Translations -Public Class dlgSummaryTables - Private Sub dlgSummaryTables_Load(sender As Object, e As EventArgs) Handles MyBase.Load +Public Class dlgSummaryTables + Private bFirstload As Boolean = True + Private Sub dlgSummaryTables_Load(sender As Object, e As EventArgs) Handles MyBase.Load + autoTranslate(Me) + If bFirstload Then + InitialiseDialog() + bFirstload = False + End If + TestOkEnabled() + End Sub + + Private Sub InitialiseDialog() cboWeights.Visible = False ucrBase.clsRsyntax.SetFunction("summary") ucrBase.clsRsyntax.iCallType = 2 autoTranslate(Me) - ucrReceiverFactor.Selector = ucrAddRemove + ucrReceiverFactor.Selector = ucrSelectorSummaryTables ucrReceiverFactor.SetMeAsReceiver() - ucrReceiverVariate.Selector = ucrAddRemove + ucrReceiverVariate.Selector = ucrSelectorSummaryTables + ucrChkDisplayMargins.SetText("Display Margins") + ucrChkMeans.SetText("Means") + ucrChkTotals.SetText("Totals") + ucrChkTrtSCFactor.SetText("Treat Summary Column as Factor") + ucrChkWeights.SetText("Weights") End Sub - Private Sub chkWeights_CheckedChanged(sender As Object, e As EventArgs) Handles chkWeights.CheckedChanged - If chkWeights.Checked = True Then + Private Sub chkWeights_CheckedChanged(sender As Object, e As EventArgs) + If ucrChkWeights.Checked = True Then cboWeights.Visible = True Else cboWeights.Visible = False @@ -45,15 +59,15 @@ Public Class dlgSummaryTables ucrBase.OKEnabled(False) End Sub - Private Sub ucrReceiverFactor_Leave(sender As Object, e As EventArgs) Handles ucrReceiverFactor.Leave + Private Sub ucrReceiverFactor_Leave(sender As Object, e As EventArgs) ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrReceiverFactor.GetVariables()) End Sub - Private Sub ucrReceiverVariate_Leave(sender As Object, e As EventArgs) Handles ucrReceiverVariate.Leave + Private Sub ucrReceiverVariate_Leave(sender As Object, e As EventArgs) ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrReceiverVariate.GetVariables()) End Sub - Private Sub ucrReceiverFactor_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFactor.ControlContentsChanged, ucrReceiverVariate.ControlContentsChanged + Private Sub ucrReceiverFactor_ControlContentsChanged(ucrChangedControl As ucrCore) TestOkEnabled() End Sub End Class \ No newline at end of file diff --git a/instat/frmMain.Designer.vb b/instat/frmMain.Designer.vb index 5b5cf39f0d5..31a5c96ade4 100644 --- a/instat/frmMain.Designer.vb +++ b/instat/frmMain.Designer.vb @@ -159,6 +159,7 @@ Partial Class frmMain Me.mnuClimatic = New System.Windows.Forms.ToolStripMenuItem() Me.mnuClimaticFile = New System.Windows.Forms.ToolStripMenuItem() Me.mnuClimaticFileOpensst = New System.Windows.Forms.ToolStripMenuItem() + Me.mnuClimaticFileImportGriddedData = New System.Windows.Forms.ToolStripMenuItem() Me.OpenNetCDFToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.mnuClimateFileClimSoft = New System.Windows.Forms.ToolStripMenuItem() Me.mnuClimaticFileCliData = New System.Windows.Forms.ToolStripMenuItem() @@ -460,7 +461,7 @@ Partial Class frmMain Me.splDataOutput = New System.Windows.Forms.SplitContainer() Me.ucrDataViewer = New instat.ucrDataView() Me.ucrOutput = New instat.ucrOutputWindow() - Me.mnuClimaticFileImportGriddedData = New System.Windows.Forms.ToolStripMenuItem() + Me.RatingDataToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.stsStrip.SuspendLayout() Me.Tool_strip.SuspendLayout() Me.mnuBar.SuspendLayout() @@ -496,7 +497,7 @@ Partial Class frmMain ' 'mnuDescribeOneVariable ' - Me.mnuDescribeOneVariable.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuDescribeOneVariableSummarise, Me.mnuDescribeOneVariableGraph, Me.ToolStripSeparator33, Me.mnuDescribeOneVariableFrequencies}) + Me.mnuDescribeOneVariable.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuDescribeOneVariableSummarise, Me.mnuDescribeOneVariableGraph, Me.ToolStripSeparator33, Me.mnuDescribeOneVariableFrequencies, Me.RatingDataToolStripMenuItem}) Me.mnuDescribeOneVariable.Name = "mnuDescribeOneVariable" Me.mnuDescribeOneVariable.Size = New System.Drawing.Size(172, 22) Me.mnuDescribeOneVariable.Tag = "One_Variable" @@ -505,26 +506,26 @@ Partial Class frmMain 'mnuDescribeOneVariableSummarise ' Me.mnuDescribeOneVariableSummarise.Name = "mnuDescribeOneVariableSummarise" - Me.mnuDescribeOneVariableSummarise.Size = New System.Drawing.Size(146, 22) + Me.mnuDescribeOneVariableSummarise.Size = New System.Drawing.Size(152, 22) Me.mnuDescribeOneVariableSummarise.Tag = "Summarise..." Me.mnuDescribeOneVariableSummarise.Text = "Summarise..." ' 'mnuDescribeOneVariableGraph ' Me.mnuDescribeOneVariableGraph.Name = "mnuDescribeOneVariableGraph" - Me.mnuDescribeOneVariableGraph.Size = New System.Drawing.Size(146, 22) + Me.mnuDescribeOneVariableGraph.Size = New System.Drawing.Size(152, 22) Me.mnuDescribeOneVariableGraph.Tag = "Graph..." Me.mnuDescribeOneVariableGraph.Text = "Graph..." ' 'ToolStripSeparator33 ' Me.ToolStripSeparator33.Name = "ToolStripSeparator33" - Me.ToolStripSeparator33.Size = New System.Drawing.Size(143, 6) + Me.ToolStripSeparator33.Size = New System.Drawing.Size(149, 6) ' 'mnuDescribeOneVariableFrequencies ' Me.mnuDescribeOneVariableFrequencies.Name = "mnuDescribeOneVariableFrequencies" - Me.mnuDescribeOneVariableFrequencies.Size = New System.Drawing.Size(146, 22) + Me.mnuDescribeOneVariableFrequencies.Size = New System.Drawing.Size(152, 22) Me.mnuDescribeOneVariableFrequencies.Text = "Frequencies..." ' 'mnuDescribeTwoVariables @@ -1430,36 +1431,42 @@ Partial Class frmMain 'mnuClimaticFileOpensst ' Me.mnuClimaticFileOpensst.Name = "mnuClimaticFileOpensst" - Me.mnuClimaticFileOpensst.Size = New System.Drawing.Size(206, 22) + Me.mnuClimaticFileOpensst.Size = New System.Drawing.Size(215, 22) Me.mnuClimaticFileOpensst.Text = "Open SST..." ' + 'mnuClimaticFileImportGriddedData + ' + Me.mnuClimaticFileImportGriddedData.Name = "mnuClimaticFileImportGriddedData" + Me.mnuClimaticFileImportGriddedData.Size = New System.Drawing.Size(215, 22) + Me.mnuClimaticFileImportGriddedData.Text = "Import Gridded Data (IRI)..." + ' 'OpenNetCDFToolStripMenuItem ' Me.OpenNetCDFToolStripMenuItem.Name = "OpenNetCDFToolStripMenuItem" - Me.OpenNetCDFToolStripMenuItem.Size = New System.Drawing.Size(206, 22) + Me.OpenNetCDFToolStripMenuItem.Size = New System.Drawing.Size(215, 22) Me.OpenNetCDFToolStripMenuItem.Text = "Open NetCDF..." ' 'mnuClimateFileClimSoft ' Me.mnuClimateFileClimSoft.Name = "mnuClimateFileClimSoft" - Me.mnuClimateFileClimSoft.Size = New System.Drawing.Size(206, 22) + Me.mnuClimateFileClimSoft.Size = New System.Drawing.Size(215, 22) Me.mnuClimateFileClimSoft.Text = "ClimSoft..." ' 'mnuClimaticFileCliData ' Me.mnuClimaticFileCliData.Name = "mnuClimaticFileCliData" - Me.mnuClimaticFileCliData.Size = New System.Drawing.Size(206, 22) + Me.mnuClimaticFileCliData.Size = New System.Drawing.Size(215, 22) Me.mnuClimaticFileCliData.Text = "CliData..." ' 'ToolStripSeparator15 ' Me.ToolStripSeparator15.Name = "ToolStripSeparator15" - Me.ToolStripSeparator15.Size = New System.Drawing.Size(203, 6) + Me.ToolStripSeparator15.Size = New System.Drawing.Size(212, 6) ' 'mnuClimaticFileExportToCPT ' Me.mnuClimaticFileExportToCPT.Name = "mnuClimaticFileExportToCPT" - Me.mnuClimaticFileExportToCPT.Size = New System.Drawing.Size(206, 22) + Me.mnuClimaticFileExportToCPT.Size = New System.Drawing.Size(215, 22) Me.mnuClimaticFileExportToCPT.Tag = "Export_to_CPT" Me.mnuClimaticFileExportToCPT.Text = "Export to CPT..." ' @@ -3627,11 +3634,11 @@ Partial Class frmMain Me.ucrOutput.Size = New System.Drawing.Size(295, 113) Me.ucrOutput.TabIndex = 0 ' - 'mnuClimaticFileImportGriddedData + 'RatingDataToolStripMenuItem ' - Me.mnuClimaticFileImportGriddedData.Name = "mnuClimaticFileImportGriddedData" - Me.mnuClimaticFileImportGriddedData.Size = New System.Drawing.Size(215, 22) - Me.mnuClimaticFileImportGriddedData.Text = "Import Gridded Data (IRI)..." + Me.RatingDataToolStripMenuItem.Name = "RatingDataToolStripMenuItem" + Me.RatingDataToolStripMenuItem.Size = New System.Drawing.Size(152, 22) + Me.RatingDataToolStripMenuItem.Text = "Rating Data..." ' 'frmMain ' @@ -4118,4 +4125,5 @@ Partial Class frmMain Friend WithEvents ucrLogWindow As ucrLog Friend WithEvents ucrScriptWindow As ucrScript Friend WithEvents mnuClimaticFileImportGriddedData As ToolStripMenuItem + Friend WithEvents RatingDataToolStripMenuItem As ToolStripMenuItem End Class diff --git a/instat/frmMain.vb b/instat/frmMain.vb index 8e0cce4a758..b017ffb9c91 100644 --- a/instat/frmMain.vb +++ b/instat/frmMain.vb @@ -1341,6 +1341,10 @@ Public Class frmMain dlgImportGriddedData.ShowDialog() End Sub + Private Sub RatingDataToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RatingDataToolStripMenuItem.Click + dlgRatingScales.ShowDialog() + End Sub + 'Private Sub TESTToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TESTToolStripMenuItem.Click ' 'TEST temporary ' 'TESTING TO BE ERASED !!!!!!! diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 67ff68fd12d..2f0b33abecf 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -210,7 +210,7 @@ data_object$set("public", "set_keys", function(new_keys) { # # } # #} # for(col in colnames(self$get_data_frame())) { -# if(!self$is_variables_metadata(display_decimal_label, col)) self$append_to_variables_metadata(col, display_decimal_label, get_default_decimal_places(self$get_columns_from_data(col, use_current_filter = FALSE))) +# if(!self$is_variables_metadata(signif_figures_label, col)) self$append_to_variables_metadata(col, signif_figures_label, get_default_significant_figures(self$get_columns_from_data(col, use_current_filter = FALSE))) # #self$append_to_variables_metadata(col, data_type_label, class(private$data[[col]])) # self$append_to_variables_metadata(col, name_label, col) # } @@ -274,7 +274,7 @@ data_object$set("public", "get_data_frame", function(convert_to_character = FALS } if(convert_to_character) { - decimal_places = self$get_variables_metadata(property = display_decimal_label, column = names(out)) + decimal_places = self$get_variables_metadata(property = signif_figures_label, column = names(out), error_if_no_property = FALSE) decimal_places[is.na(decimal_places)] <- 0 return(convert_to_character_matrix(out, TRUE, decimal_places)) } @@ -294,16 +294,17 @@ data_object$set("public", "get_variables_metadata", function(data_type = "all", } else { i = 1 - out = list() + out <- list() for(col in self$get_data_frame(use_current_filter = FALSE)) { - ind = which(names(attributes(col)) == "levels") + ind <- which(names(attributes(col)) == "levels") if(length(ind) > 0) col_attributes <- attributes(col)[-ind] - else col_attributes = attributes(col) + else col_attributes <- attributes(col) if(is.null(col_attributes)) col_attributes <- list() col_attributes[[data_type_label]] <- class(col) for(att_name in names(col_attributes)) { #TODO Think how to do this more generally and cover all cases - if(is.list(col_attributes[[att_name]]) || length(col_attributes[[att_name]]) > 1) col_attributes[[att_name]] <- paste(unlist(col_attributes[[att_name]]), collapse = ",") + if(att_name == "labels") col_attributes[[att_name]] <- paste(names(col_attributes[[att_name]]), "=", col_attributes[[att_name]], collapse = ", ") + else if(is.list(col_attributes[[att_name]]) || length(col_attributes[[att_name]]) > 1) col_attributes[[att_name]] <- paste(unlist(col_attributes[[att_name]]), collapse = ",") # TODO Possible alternative to include names of list # TODO See how to have data frame properly containing lists #if(is.list(col_attributes[[att_name]]) || length(col_attributes[[att_name]]) > 1) col_attributes[[att_name]] <- paste(names(unlist(col_attributes[[att_name]])), unlist(col_attributes[[att_name]]), collapse = ",") @@ -318,13 +319,15 @@ data_object$set("public", "get_variables_metadata", function(data_type = "all", #RLink crashes with bind_rows for data frames with ~50+ columns out <- rbind.fill(out) out <- as.data.frame(out) - row.names(out) <- names(self$get_data_frame(use_current_filter = FALSE)) + if(all(c(name_label, label_label) %in% names(out))) out <- out[ ,c(c(name_label, label_label), setdiff(names(out), c(name_label, label_label)))] + else if(name_label %in% names(out)) out <- out[ ,c(name_label, setdiff(names(out), name_label))] + row.names(out) <- self$get_column_names() if(data_type != "all") { if(data_type == "numeric") { - out = out[out[[data_type_label]] %in% c("numeric", "integer"), ] + out <- out[out[[data_type_label]] %in% c("numeric", "integer"), ] } else { - out = out[out[[data_type_label]] == data_type, ] + out <- out[out[[data_type_label]] == data_type, ] } } not_found <- FALSE @@ -334,12 +337,12 @@ data_object$set("public", "get_variables_metadata", function(data_type = "all", not_found <- TRUE } if(!missing(column)) { - if(!all(column %in% names(self$get_data_frame(use_current_filter = FALSE)))) stop(column, " not found in data") + if(!all(column %in% self$get_column_names())) stop(column, " not found in data") if(not_found) out <- rep(NA, length(column)) else out <- out[column, property] } else { - if(not_found) out <- rep(NA, length(names(self$get_data_frame(use_current_filter = FALSE)))) + if(not_found) out <- rep(NA, length(self$get_column_names())) else out <- out[, property] } } @@ -456,7 +459,7 @@ data_object$set("public", "add_columns_to_data", function(col_name = "", col_dat if(is.matrix(curr_col) || is.data.frame(curr_col)) curr_col = curr_col[,1] if(use_col_name_as_prefix) curr_col_name = self$get_next_default_column_name(col_name) else curr_col_name = col_name[[i]] - if(curr_col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) { + if(curr_col_name %in% self$get_column_names()) { message(paste("A column named", curr_col_name, "already exists. The column will be replaced in the data")) self$append_to_changes(list(Replaced_col, curr_col_name)) replaced = TRUE @@ -468,7 +471,9 @@ data_object$set("public", "add_columns_to_data", function(col_name = "", col_dat self$data_changed <- TRUE self$append_to_variables_metadata(curr_col_name, is_hidden_label, hidden) self$append_to_variables_metadata(curr_col_name, name_label, curr_col_name) - self$append_to_variables_metadata(curr_col_name, display_decimal_label, get_default_decimal_places(self$get_columns_from_data(curr_col_name, use_current_filter = FALSE))) + self$append_to_variables_metadata(curr_col_name, signif_figures_label, get_default_significant_figures(self$get_columns_from_data(curr_col_name, use_current_filter = FALSE))) + self$append_to_variables_metadata(curr_col_name, label_label, "") + self$append_to_variables_metadata(curr_col_name, scientific_label, FALSE) self$variables_metadata_changed <- TRUE } if(!replaced) { @@ -483,7 +488,7 @@ data_object$set("public", "add_columns_to_data", function(col_name = "", col_dat data_object$set("public", "get_columns_from_data", function(col_names, force_as_data_frame = FALSE, use_current_filter = TRUE) { if(missing(col_names)) stop("no col_names to return") - if(!all(col_names %in% names(self$get_data_frame(use_current_filter = FALSE)))) stop("Not all column names were found in data") + if(!all(col_names %in% self$get_column_names())) stop("Not all column names were found in data") if(length(col_names)==1) { if(force_as_data_frame) return(self$get_data_frame(use_current_filter = use_current_filter)[col_names]) @@ -562,7 +567,7 @@ data_object$set("public", "remove_columns_in_data", function(cols=c()) { stop("Column name must be of type: character") } - else if (!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))) { + else if(!(col_name %in% self$get_column_names())) { stop(paste0("Column :'", col_name, " was not found in the data.")) } @@ -757,14 +762,14 @@ data_object$set("public", "append_to_variables_metadata", function(col_names, pr if(missing(property)) stop("property must be specified.") if(!is.character(property)) stop("property must be a character") if(!missing(col_names)) { - if(!all(col_names %in% names(self$get_data_frame(use_current_filter = FALSE)))) stop("Not all of ", paste(col_names, collapse = ","), " found in data.") + if(!all(col_names %in% self$get_column_names())) stop("Not all of ", paste(col_names, collapse = ","), " found in data.") for(curr_col in col_names) { attr(private$data[[curr_col]], property) <- new_val self$append_to_changes(list(Added_variables_metadata, curr_col, property)) } } else { - for(col_name in names(self$get_data_frame(use_current_filter = FALSE))) { + for(col_name in self$get_column_names()) { attr(private$data[[col_name]], property) <- new_val } self$append_to_changes(list(Added_variables_metadata, property, new_val)) @@ -791,8 +796,10 @@ data_object$set("public", "is_metadata", function(str) { ) data_object$set("public", "is_variables_metadata", function(str, col, return_vector = FALSE) { - if(!str %in% names(self$get_variables_metadata())) return(FALSE) - if(missing(col)) return(TRUE) + if(str == data_type_label) return(TRUE) + if(missing(col)) { + return(any(sapply(self$get_column_names(), function(x) str %in% names(attributes(self$get_columns_from_data(x, use_current_filter = FALSE)))), na.rm = TRUE)) + } else { out <- sapply(col, function(x) str %in% names(attributes(self$get_columns_from_data(x, use_current_filter = FALSE)))) if(return_vector) return(out) @@ -803,26 +810,25 @@ data_object$set("public", "is_variables_metadata", function(str, col, return_vec data_object$set("public", "add_defaults_meta", function() { if(!self$is_metadata(is_calculated_label)) self$append_to_metadata(is_calculated_label, FALSE) + if(!self$is_metadata(label_label)) self$append_to_metadata(label_label, "") } ) data_object$set("public", "add_defaults_variables_metadata", function() { - invisible(sapply(colnames(self$get_data_frame(use_current_filter = FALSE)), function(x) self$append_to_variables_metadata(x, name_label, x))) - has_hidden <- self$is_variables_metadata(is_hidden_label) && !is.na(self$get_variables_metadata(property = is_hidden_label)) && self$get_variables_metadata(property = is_hidden_label) - if(has_hidden) { - for(column in colnames(self$get_data_frame(use_current_filter = FALSE))) { - if(!self$is_variables_metadata(is_hidden_label, column)) { - self$append_to_variables_metadata(column, property = is_hidden_label, new_val = FALSE) - } + for(column in self$get_column_names()) { + self$append_to_variables_metadata(column, name_label, column) + if(!self$is_variables_metadata(is_hidden_label, column)) { + self$append_to_variables_metadata(column, property = is_hidden_label, new_val = FALSE) } - } - else self$append_to_variables_metadata(property = is_hidden_label, new_val = FALSE) - for(column in colnames(self$get_data_frame(use_current_filter = FALSE))) { - if(has_hidden) { - if(!self$is_variables_metadata(is_hidden_label, column)) self$append_to_variables_metadata(column, property = is_hidden_label, new_val = FALSE) + if(!self$is_variables_metadata(label_label, column)) { + self$append_to_variables_metadata(column, label_label, "") + } + if(!self$is_variables_metadata(scientific_label, column)) { + self$append_to_variables_metadata(column, scientific_label, FALSE) + } + if(!self$is_variables_metadata(scientific_label, column)) { + self$append_to_variables_metadata(column, signif_figures_label, get_default_significant_figures(self$get_columns_from_data(column, use_current_filter = FALSE))) } - self$append_to_variables_metadata(column, name_label, column) - self$append_to_variables_metadata(column, display_decimal_label, get_default_decimal_places(self$get_columns_from_data(column, use_current_filter = FALSE))) } } ) @@ -838,8 +844,8 @@ data_object$set("public", "remove_rows_in_data", function(row_names) { ) data_object$set("public", "get_next_default_column_name", function(prefix) { - next_default_item(prefix = prefix, existing_names = names(self$get_data_frame(use_current_filter = FALSE))) -} + return(next_default_item(prefix = prefix, existing_names = self$get_column_names())) +} ) data_object$set("public", "reorder_columns_in_data", function(col_order) { @@ -913,7 +919,7 @@ data_object$set("public", "get_data_frame_length", function(use_current_filter = ) data_object$set("public", "get_factor_data_frame", function(col_name = "") { - if(!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))){ + if(!(col_name %in% self$get_column_names())) { stop(col_name, " is not a column in", get_metadata(data_name_label)) } if(!(is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE)))){ @@ -927,7 +933,7 @@ data_object$set("public", "get_factor_data_frame", function(col_name = "") { ) data_object$set("public", "get_column_factor_levels", function(col_name = "") { - if(!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))){ + if(!(col_name %in% self$get_column_names())) { stop(col_name, " is not a column in", get_metadata(data_name_label)) } @@ -971,7 +977,7 @@ data_object$set("public", "sort_dataframe", function(col_names = c(), decreasing data_object$set("public", "convert_column_to_type", function(col_names = c(), to_type, factor_numeric = "by_levels", set_digits, set_decimals = FALSE) { for(col_name in col_names){ - if(!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))){ + if(!(col_name %in% self$get_column_names())) { stop(col_name, " is not a column in ", get_metadata(data_name_label)) } } @@ -1023,7 +1029,7 @@ data_object$set("public", "convert_column_to_type", function(col_names = c(), to else if(to_type == "character") { self$add_columns_to_data(col_name = col_name, col_data = as.character(curr_col)) } - self$append_to_variables_metadata(property = display_decimal_label, col_names = col_name, new_val = get_default_decimal_places(curr_col)) + self$append_to_variables_metadata(property = signif_figures_label, col_names = col_name, new_val = get_default_significant_figures(curr_col)) } self$data_changed <- TRUE self$variables_metadata_changed <- TRUE @@ -1032,7 +1038,7 @@ data_object$set("public", "convert_column_to_type", function(col_names = c(), to data_object$set("public", "copy_columns", function(col_names = "") { for(col_name in col_names){ - if(!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))){ + if(!(col_name %in% self$get_column_names())) { stop(col_name, " is not a column in ", get_metadata(data_name_label)) } } @@ -1048,7 +1054,7 @@ data_object$set("public", "copy_columns", function(col_names = "") { ) data_object$set("public", "drop_unused_factor_levels", function(col_name) { - if(!col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(paste(col_name,"not found in data.")) + if(!col_name %in% self$get_column_names()) stop(paste(col_name,"not found in data.")) if(!is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(col_name,"is not a factor.")) self$add_columns_to_data(col_name, droplevels(self$get_columns_from_data(col_name, use_current_filter = FALSE))) @@ -1056,7 +1062,7 @@ data_object$set("public", "drop_unused_factor_levels", function(col_name) { ) data_object$set("public", "set_factor_levels", function(col_name, new_levels) { - if(!col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(paste(col_name,"not found in data.")) + if(!col_name %in% self$get_column_names()) stop(paste(col_name,"not found in data.")) if(!is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(col_name,"is not a factor.")) if(length(new_levels) < length(levels(self$get_columns_from_data(col_name, use_current_filter = FALSE)))) stop("There must be at least as many new levels as current levels.") @@ -1068,7 +1074,7 @@ data_object$set("public", "set_factor_levels", function(col_name, new_levels) { ) data_object$set("public", "edit_factor_level", function(col_name, old_level, new_level) { - if(!col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(paste(col_name,"not found in data.")) + if(!col_name %in% self$get_column_names()) stop(paste(col_name,"not found in data.")) if(!is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(col_name,"is not a factor.")) self$add_columns_to_data(col_name, mapvalues(x = self$get_columns_from_data(col_name, use_current_filter = FALSE), from = old_level, to = new_level)) self$data_changed <- TRUE @@ -1078,7 +1084,7 @@ data_object$set("public", "edit_factor_level", function(col_name, old_level, new data_object$set("public", "set_factor_reference_level", function(col_name, new_ref_level) { - if(!col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(paste(col_name,"not found in data.")) + if(!col_name %in% self$get_column_names()) stop(paste(col_name,"not found in data.")) if(!is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(col_name,"is not a factor.")) if(!new_ref_level %in% levels(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(new_ref_level, "is not a level of the factor")) @@ -1087,7 +1093,7 @@ data_object$set("public", "set_factor_reference_level", function(col_name, new_r ) data_object$set("public", "reorder_factor_levels", function(col_name, new_level_names) { - if(!col_name %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(paste(col_name,"not found in data.")) + if(!col_name %in% self$get_column_names()) stop(paste(col_name,"not found in data.")) if(!is.factor(self$get_columns_from_data(col_name, use_current_filter = FALSE))) stop(paste(col_name,"is not a factor.")) if(length(new_level_names)!=length(levels(self$get_columns_from_data(col_name, use_current_filter = FALSE)))) stop("Incorrect number of new level names given.") if(!all(new_level_names %in% levels(self$get_columns_from_data(col_name, use_current_filter = FALSE)))) stop(paste("new_level_names must be a reordering of the current levels:",paste(levels(data[[col_name]]), collapse = " "))) @@ -1102,27 +1108,30 @@ data_object$set("public", "get_column_count", function(col_name, new_level_names ) data_object$set("public", "get_column_names", function(as_list = FALSE, include = list(), exclude = list(), excluded_items = c()) { - if(data_type_label %in% names(include) && "numeric" %in% include[[data_type_label]]) { - include[[data_type_label]] = c(include[[data_type_label]], "integer") - } - if(data_type_label %in% names(exclude) && "numeric" %in% exclude[[data_type_label]]) { - exclude[[data_type_label]] = c(exclude[[data_type_label]], "integer") - } - - col_names = names(self$get_data_frame(use_current_filter = FALSE)) - var_metadata = self$get_variables_metadata() - out = c() - i = 1 - for(col in col_names) { - if(length(include) > 0 || length(exclude) > 0) { - curr_var_metadata = var_metadata[i, ] - if(all(c(names(include), names(exclude)) %in% names(curr_var_metadata)) && all(sapply(names(include), function(prop) curr_var_metadata[[prop]] %in% include[[prop]])) - && all(sapply(names(exclude), function(prop) !curr_var_metadata[[prop]] %in% exclude[[prop]]))) { - out <- c(out, col) + if(length(include) == 0 && length(exclude) == 0) out <- names(private$data) + else { + if(data_type_label %in% names(include) && "numeric" %in% include[[data_type_label]]) { + include[[data_type_label]] = c(include[[data_type_label]], "integer") + } + if(data_type_label %in% names(exclude) && "numeric" %in% exclude[[data_type_label]]) { + exclude[[data_type_label]] = c(exclude[[data_type_label]], "integer") + } + + col_names <- self$get_column_names() + var_metadata <- self$get_variables_metadata() + out = c() + i = 1 + for(col in col_names) { + if(length(include) > 0 || length(exclude) > 0) { + curr_var_metadata = var_metadata[i, ] + if(all(c(names(include), names(exclude)) %in% names(curr_var_metadata)) && all(sapply(names(include), function(prop) curr_var_metadata[[prop]] %in% include[[prop]])) + && all(sapply(names(exclude), function(prop) !curr_var_metadata[[prop]] %in% exclude[[prop]]))) { + out <- c(out, col) + } } + else out <- c(out, col) + i = i + 1 } - else out <- c(out, col) - i = i + 1 } if(length(excluded_items) > 0) { ex_ind = which(out %in% excluded_items) @@ -1140,7 +1149,7 @@ data_object$set("public", "get_column_names", function(as_list = FALSE, include #TODO: Are there other types needed here? data_object$set("public", "get_data_type", function(col_name = "") { - if(!(col_name %in% names(self$get_data_frame(use_current_filter = FALSE)))){ + if(!(col_name %in% self$get_column_names())) { stop(paste(col_name, "is not a column in", get_metadata(data_name_label))) } type = "" @@ -1212,20 +1221,13 @@ data_object$set("public", "set_col_names", function(col_names) { ) data_object$set("public", "get_row_names", function() { - return(rownames(self$get_data_frame(use_current_filter = FALSE))) + return(rownames(private$data)) } - ) -data_object$set("public", "get_col_names", function() { - return(names(self$get_data_frame(use_current_filter = FALSE))) -} - -) data_object$set("public", "get_dim_dataframe", function() { return(dim(self$get_data_frame(use_current_filter = FALSE))) } - ) data_object$set("public", "set_protected_columns", function(col_names) { @@ -1245,7 +1247,7 @@ data_object$set("public", "add_filter", function(filter, filter_name = "", repla if(length(condition) != 3 || !all(sort(names(condition)) == c("column", "operation", "value"))) { stop("filter must be a list of conditions containing: column, operation and value") } - if(!condition[["column"]] %in% names(self$get_data_frame(use_current_filter = FALSE))) stop(condition[["column"]], " not found in data.") + if(!condition[["column"]] %in% self$get_column_names()) stop(condition[["column"]], " not found in data.") } if(filter_name %in% names(private$filters) && !replace) { warning("A filter named ", filter_name, " already exists. It will not be replaced.") @@ -1513,7 +1515,7 @@ data_object$set("public", "remove_key", function(key_name) { ) data_object$set("public", "set_structure_columns", function(struc_type_1, struc_type_2, struc_type_3) { - if(!all(c(struc_type_1,struc_type_2,struc_type_3) %in% names(self$get_data_frame(use_current_filter = FALSE)))) stop("Some column names not recognised.") + if(!all(c(struc_type_1,struc_type_2,struc_type_3) %in% self$get_column_names())) stop("Some column names not recognised.") if(length(intersect(struc_type_1,struc_type_2)) > 0 || length(intersect(struc_type_1,struc_type_3)) > 0 || length(intersect(struc_type_2,struc_type_3)) > 0) { stop("Each column can only be assign one structure type.") } @@ -1521,7 +1523,7 @@ data_object$set("public", "set_structure_columns", function(struc_type_1, struc_ if(length(struc_type_2) > 0) self$append_to_variables_metadata(struc_type_2, structure_label, structure_type_2_label) if(length(struc_type_3) > 0) self$append_to_variables_metadata(struc_type_3, structure_label, structure_type_3_label) all <- union(union(struc_type_1, struc_type_2), struc_type_3) - other <- setdiff(names(self$get_data_frame(use_current_filter = FALSE)), all) + other <- setdiff(self$get_column_names(), all) self$append_to_variables_metadata(other, structure_label, NA) } ) @@ -1546,7 +1548,7 @@ data_object$set("public", "add_dependent_columns", function(columns, dependent_c ) data_object$set("public", "set_column_colours", function(columns, colours) { - if(missing(columns)) columns <- names(self$get_data_frame(use_current_filter = TRUE)) + if(missing(columns)) columns <- self$get_column_names() if(length(columns) != length(colours)) stop("columns must be the same length as colours") for(i in 1:length(columns)) { @@ -1771,7 +1773,7 @@ data_object$set("public","make_date_yeardoy", function(year, doy, year_format = ) data_object$set("public","set_contrasts_of_factor", function(col_name, new_contrasts, defined_contr_matrix) { - if(!col_name %in% names(self$get_data_frame())) stop(col_name, " not found in the data") + if(!col_name %in% self$get_column_names()) stop(col_name, " not found in the data") if(!is.factor(self$get_columns_from_data(col_name))) stop(factor, " is not a factor column.") factor_col <- self$get_columns_from_data(col_name) contr_col <- nlevels(factor_col) - 1 diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 9e109c8c528..9d228184c3d 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -277,6 +277,8 @@ instat_object$set("public", "get_combined_metadata", function(convert_to_charact if(length(templist[[j]]) > 1) templist[[j]] <- paste(as.character(templist[[j]]), collapse = ",") retlist[i, names(templist[j])] = templist[[j]] } + if(all(c(data_name_label, label_label) %in% names(retlist))) retlist <- retlist[ ,c(c(data_name_label, label_label), setdiff(names(retlist), c(data_name_label, label_label)))] + else if(data_name_label %in% names(retlist)) retlist <- retlist[ ,c(data_name_label, setdiff(names(retlist), data_name_label))] i = i + 1 } if(convert_to_character) return(convert_to_character_matrix(retlist, FALSE)) diff --git a/instat/static/InstatObject/R/labels_and_defaults.R b/instat/static/InstatObject/R/labels_and_defaults.R index 7a2f4df300a..62fe7080152 100644 --- a/instat/static/InstatObject/R/labels_and_defaults.R +++ b/instat/static/InstatObject/R/labels_and_defaults.R @@ -30,7 +30,9 @@ column_count_label="Column_Count" is_linkable="Is_Linkable" #variables_metadata labels -display_decimal_label="Display_Decimal" +label_label="label" +signif_figures_label="Signif_Figures" +scientific_label="Scientific" name_label="Name" is_factor_label="Is_Factor" #changes because attributes default is class diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index c69ef795247..c8aac01f004 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -1,18 +1,5 @@ -get_default_decimal_places <- function(data) { - if(is.numeric(data)) { - min_data <- min(data, na.rm = TRUE) - if(is.integer(data) || min_data > 100 || all((data %% 1) == 0, na.rm = TRUE)) { - return(0) - } - else { - if(min_data > 10) { - return(1) - } - else { - return(2) - } - } - } +get_default_significant_figures <- function(data) { + if(is.numeric(data)) return(3) else return(NA) } @@ -23,14 +10,14 @@ convert_to_character_matrix <- function(data, format_decimal_places = TRUE, deci else { out = matrix(nrow = nrow(data), ncol = ncol(data)) if(!format_decimal_places) decimal_places=rep(NA, ncol(data)) - else if(missing(decimal_places)) decimal_places = sapply(data, get_default_decimal_places) + else if(missing(decimal_places)) decimal_places = sapply(data, get_default_significant_figures) i = 1 for(curr_col in colnames(data)) { if(is.na(decimal_places[i])) { out[,i] <- as.character(data[[i]]) } else { - out[,i] <- as.character(format(data[[i]], nsmall = decimal_places[i], scientific = FALSE)) + out[,i] <- format(data[[i]], digits = decimal_places[i], scientific = FALSE) } i = i + 1 } diff --git a/instat/ucrCheck.vb b/instat/ucrCheck.vb index 52cbdeb1f19..04147d2db88 100644 --- a/instat/ucrCheck.vb +++ b/instat/ucrCheck.vb @@ -61,9 +61,13 @@ Public Class ucrCheck Private Sub chkCheck_CheckedChanged(sender As Object, e As EventArgs) Handles chkCheck.CheckedChanged If bChangeParameterValue AndAlso clsParameter IsNot Nothing Then If chkCheck.Checked Then - clsParameter.SetArgumentValue(strValueIfChecked) + If strValueIfChecked <> "" Then + clsParameter.SetArgumentValue(strValueIfChecked) + End If Else - clsParameter.SetArgumentValue(strValueIfUnchecked) + If strValueIfUnchecked <> "" Then + clsParameter.SetArgumentValue(strValueIfUnchecked) + End If End If End If UpdateRCode() diff --git a/instat/ucrColumnMetadata.vb b/instat/ucrColumnMetadata.vb index 2c836498cfe..c8cb4cbcfd5 100644 --- a/instat/ucrColumnMetadata.vb +++ b/instat/ucrColumnMetadata.vb @@ -20,6 +20,7 @@ Public Class ucrColumnMetadata 'Public context As New frmEditor Public WithEvents grdCurrSheet As unvell.ReoGrid.Worksheet Public strPreviousCellText As String + Private lstNonEditableColumns As New List(Of String) Private Sub frmVariables_Load(sender As Object, e As EventArgs) Handles Me.Load loadForm() @@ -29,6 +30,7 @@ Public Class ucrColumnMetadata grdVariables.CurrentWorksheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_Readonly, True) grdVariables.SheetTabNewButtonVisible = False grdVariables.SheetTabWidth = 250 + lstNonEditableColumns.AddRange({"class", "Is_Hidden", "Is_Key", "Is_Calculated", "Has_Dependants", "Dependent_Columns", "Calculated_By", "Dependencies", "Colour", "Scientific"}) 'grdVariables.CurrentWorksheet.Resize(5, 5) 'grdVariables.ColumnHeaderContextMenuStrip = context.grdData.ColumnHeaderContextMenuStrip 'grdVariables.RowHeaderContextMenuStrip = context.grdData.RowHeaderContextMenuStrip @@ -39,7 +41,7 @@ Public Class ucrColumnMetadata Private Sub grdVariables_CurrentWorksheetChanged(sender As Object, e As EventArgs) Handles grdVariables.CurrentWorksheetChanged, Me.Load, grdVariables.WorksheetInserted grdCurrSheet = grdVariables.CurrentWorksheet grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False) - grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_Readonly, True) + 'grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_Readonly, True) grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False) grdCurrSheet.SelectionForwardDirection = unvell.ReoGrid.SelectionForwardDirection.Down End Sub @@ -47,42 +49,78 @@ Public Class ucrColumnMetadata Private Sub grdCurrSheet_AfterCellEdit(sender As Object, e As CellAfterEditEventArgs) Handles grdCurrSheet.AfterCellEdit Dim strScript As String = "" Dim strComment As String = "" - Dim strDecimalLabel As String = "DisplayDecimal" + Dim strSignifFiguresLabel As String = "Signif_Figures" Dim strNameLabel As String = "Name" Dim strDataTypeLabel As String = "DataType" - Dim strColumn = grdCurrSheet(e.Cell.Row, 0).ToString() - Dim bRunScript As Boolean = False + Dim strProperty As String = grdCurrSheet.ColumnHeaders(e.Cell.Column).Text + Dim strColumn As String + Dim iTemp As Integer + Dim iNameColumn As Integer = -1 + Dim strNewValue As String - If grdCurrSheet.ColumnHeaders(e.Cell.Column).Text = strNameLabel Then - strScript = frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data(data_name =" & Chr(34) & grdCurrSheet.Name & Chr(34) & ",column_name = " & Chr(34) & strPreviousCellText & Chr(34) & ",new_val=" & Chr(34) & e.NewData & Chr(34) & ")" - strComment = "Renamed column" - bRunScript = True - ElseIf grdCurrSheet.ColumnHeaders(e.Cell.Column).Text = strDataTypeLabel Then - If e.NewData.ToString() <> "factor" AndAlso e.NewData.ToString() <> "numeric" AndAlso e.NewData.ToString() <> "character" Then - e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + If e.NewData.ToString() = strPreviousCellText Then + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + End If + + For i As Integer = 0 To grdCurrSheet.ColumnCount - 1 + If grdCurrSheet.ColumnHeaders(i).Text = strNameLabel Then + iNameColumn = i + Exit For + End If + Next + If iNameColumn <> -1 Then + strColumn = grdCurrSheet(e.Cell.Row, iNameColumn).ToString() + If strProperty = strSignifFiguresLabel Then + If Not (Integer.TryParse(e.NewData, iTemp) AndAlso iTemp >= 0 AndAlso iTemp <= 22) Then + MsgBox("Significant Figures must be an integer between 0 and 22", MsgBoxStyle.Information, "Invalid Significant Figures") + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + Else + strNewValue = iTemp + End If Else - strScript = frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type(data_name =" & Chr(34) & grdCurrSheet.Name & Chr(34) & ",col_names = " & Chr(34) & strColumn & Chr(34) & ",to_type=" & Chr(34) & e.NewData & Chr(34) & ")" - strComment = "Converted column type" - bRunScript = True + If Decimal.TryParse(e.NewData, iTemp) Then + strNewValue = e.NewData + Else + strNewValue = Chr(34) & e.NewData & Chr(34) + End If End If - ElseIf grdCurrSheet.ColumnHeaders(e.Cell.Column).Text = strDecimalLabel Then - If Integer.TryParse(e.NewData, 0) AndAlso e.NewData >= 0 Then - strScript = frmMain.clsRLink.strInstatDataObject & "$append_to_variables_metadata(data_name =" & Chr(34) & grdCurrSheet.Name & Chr(34) & ",col_names = " & Chr(34) & strColumn & Chr(34) & ",property=" & Chr(34) & strDecimalLabel & Chr(34) & ",new_val=" & e.NewData & ")" - strComment = "Edited variables metadata value" - bRunScript = True + If strProperty = strNameLabel Then + If frmMain.clsRLink.IsValidText(e.NewData) Then + If frmMain.clsRLink.GetColumnNames(grdCurrSheet.Name).Contains(e.NewData.ToString()) Then + MsgBox(e.NewData.ToString() & " is an existing column name.", MsgBoxStyle.Information, "Invalid Column Name") + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + Else + strScript = frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data(data_name =" & Chr(34) & grdCurrSheet.Name & Chr(34) & ",column_name = " & Chr(34) & strPreviousCellText & Chr(34) & ",new_val=" & strNewValue & ")" + strComment = "Renamed column" + End If + Else + MsgBox(e.NewData & " is not a valid column name.", MsgBoxStyle.Information, "Invalid Column Name") + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + End If Else - e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + strScript = frmMain.clsRLink.strInstatDataObject & "$append_to_variables_metadata(data_name =" & Chr(34) & grdCurrSheet.Name & Chr(34) & ",col_names = " & Chr(34) & strColumn & Chr(34) & ",property=" & Chr(34) & strProperty & Chr(34) & ",new_val=" & strNewValue & ")" + strComment = "Edited variables metadata value" End If + Try + frmMain.clsRLink.RunScript(strScript, strComment:=strComment) + Catch + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + End Try + Else + MsgBox("Developer error: Cannot find Name column in column metadata grid.", MsgBoxStyle.Critical, "Canont find Name column") End If - Try - frmMain.clsRLink.RunScript(strScript, strComment:=strComment) - Catch - e.EndReason = unvell.ReoGrid.EndEditReason.Cancel - End Try End Sub Private Sub grdCurrSheet_BeforeCellEdit(sender As Object, e As CellBeforeEditEventArgs) Handles grdCurrSheet.BeforeCellEdit - strPreviousCellText = e.Cell.Data.ToString() + If lstNonEditableColumns.Contains(grdCurrSheet.ColumnHeaders(e.Cell.Column).Text) Then + e.IsCancelled = True + Else + strPreviousCellText = e.Cell.Data.ToString() + End If End Sub Private Sub grdCurrSheet_BeforeCut(sender As Object, e As BeforeRangeOperationEventArgs) Handles grdCurrSheet.BeforeCut diff --git a/instat/ucrCore.vb b/instat/ucrCore.vb index 99e9d9a8770..0884a4d76e2 100644 --- a/instat/ucrCore.vb +++ b/instat/ucrCore.vb @@ -85,6 +85,11 @@ Public Class ucrCore Public bIsVisible As Boolean = True + ' Values which the parameter associated to the control may have but which shouldn't be used to set the control's value + ' Individual controls can determine what value to set when a parameter value is contained in strValuesToIgnore + ' (Currently only implemented for receivers) + Protected strValuesToIgnore As String() + 'Update the control based on the code in RCodeStructure 'bReset : should the control reset to the default value if the parameter is not present in the code Public Overridable Sub UpdateControl(Optional bReset As Boolean = False) @@ -442,4 +447,8 @@ Public Class ucrCore clsParameter.SetArgumentValue(strNewValue) End If End Sub + + Public Sub SetValuesToIgnore(strValues() As String) + strValuesToIgnore = strValues + End Sub End Class \ No newline at end of file diff --git a/instat/ucrDataFrameMetadata.vb b/instat/ucrDataFrameMetadata.vb index c8c36404a2f..eaf18f39e88 100644 --- a/instat/ucrDataFrameMetadata.vb +++ b/instat/ucrDataFrameMetadata.vb @@ -19,6 +19,7 @@ Imports unvell.ReoGrid.Events Public Class ucrDataFrameMetadata Public WithEvents grdCurrSheet As unvell.ReoGrid.Worksheet Public strPreviousCellText As String + Private lstNonEditableColumns As New List(Of String) Private Sub frmMetaData_Load(sender As Object, e As EventArgs) Handles Me.Load LoadForm() @@ -26,48 +27,84 @@ Public Class ucrDataFrameMetadata ' TODO this needs tidying up Private Sub LoadForm() + lstNonEditableColumns.AddRange({"class", "Is_Hidden", "Row_Count", "Column_Count", "Is_Linkable", "Is_Calculated"}) grdMetaData.Worksheets(0).Name = "metadata" grdMetaData.SetSettings(unvell.ReoGrid.WorkbookSettings.View_ShowSheetTabControl, False) grdMetaData.SetSettings(unvell.ReoGrid.WorkbookSettings.View_ShowHorScroll, False) grdMetaData.SheetTabNewButtonVisible = False - 'grdMetaData.ColumnHeaderContextMenuStrip = context.grdData.ColumnHeaderContextMenuStrip - 'grdMetaData.ContextMenuStrip = context.grdData.ContextMenuStrip - 'grdMetaData.RowHeaderContextMenuStrip = context.grdData.RowHeaderContextMenuStrip End Sub Private Sub grdMetaData_CurrentWorksheetChanged(sender As Object, e As EventArgs) Handles grdMetaData.CurrentWorksheetChanged, Me.Load, grdMetaData.WorksheetInserted grdCurrSheet = grdMetaData.CurrentWorksheet grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False) - grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_Readonly, True) grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False) grdCurrSheet.SelectionForwardDirection = unvell.ReoGrid.SelectionForwardDirection.Down End Sub Private Sub grdCurrSheet_BeforeCellEdit(sender As Object, e As CellBeforeEditEventArgs) Handles grdCurrSheet.BeforeCellEdit - 'strPreviousCellText = e.Cell.Data.ToString() - e.IsCancelled = True + If lstNonEditableColumns.Contains(grdCurrSheet.ColumnHeaders(e.Cell.Column).Text) OrElse grdCurrSheet.ColumnHeaders(e.Cell.Column).Text.Substring(0, 3) = "key" Then + e.IsCancelled = True + Else + strPreviousCellText = e.Cell.Data.ToString() + End If End Sub Private Sub grdCurrSheet_AfterCellEdit(sender As Object, e As CellAfterEditEventArgs) Handles grdCurrSheet.AfterCellEdit Dim strScript As String = "" Dim strComment As String = "" - Dim bRunScript As Boolean = False + Dim strSignifFiguresLabel As String = "Signif_Figures" + Dim strNameLabel As String = "data_name" + Dim strDataTypeLabel As String = "DataType" + Dim strProperty As String = grdCurrSheet.ColumnHeaders(e.Cell.Column).Text + Dim strDataName As String + Dim iTemp As Integer + Dim iNameColumn As Integer = -1 + Dim strNewValue As String - If e.Cell.Column = 0 Then - 'TODO fix bug with this not updating grid correctly after renaming - 'strScript = frmMain.clsRLink.strInstatDataObject & "$rename_dataframe(data_name =" & Chr(34) & strPreviousCellText & Chr(34) & ", new_val = " & Chr(34) & e.NewData & Chr(34) & ")" - 'strComment = "Renamed sheet" - Else - strScript = frmMain.clsRLink.strInstatDataObject & "$append_to_dataframe_metadata(data_name =" & Chr(34) & grdCurrSheet(e.Cell.Row, 0).ToString() & Chr(34) & ", property = " & Chr(34) & grdCurrSheet.ColumnHeaders(e.Cell.Column).Text & "new_value = " & Chr(34) & e.NewData & Chr(34) & ")" - strComment = "Changed metadata value" - bRunScript = True + If e.NewData.ToString() = strPreviousCellText Then + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub End If - If bRunScript Then + + For i As Integer = 0 To grdCurrSheet.ColumnCount - 1 + If grdCurrSheet.ColumnHeaders(i).Text = strNameLabel Then + iNameColumn = i + Exit For + End If + Next + If iNameColumn <> -1 Then + strDataName = grdCurrSheet(e.Cell.Row, iNameColumn).ToString() + If Decimal.TryParse(e.NewData, iTemp) Then + strNewValue = e.NewData + Else + strNewValue = Chr(34) & e.NewData & Chr(34) + End If + If strProperty = strNameLabel Then + If frmMain.clsRLink.IsValidText(e.NewData) Then + If frmMain.clsRLink.GetDataFrameNames().Contains(e.NewData.ToString()) Then + MsgBox(e.NewData.ToString() & " is an existing data frame name.", MsgBoxStyle.Information, "Invalid Data Frame Name") + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + Else + strScript = frmMain.clsRLink.strInstatDataObject & "$rename_dataframe(data_name =" & Chr(34) & strPreviousCellText & Chr(34) & ", new_val = " & strNewValue & ")" + strComment = "Renamed data frame" + End If + Else + MsgBox(e.NewData & " is not a valid data frame name.", MsgBoxStyle.Information, "Invalid Data Frame Name") + e.EndReason = unvell.ReoGrid.EndEditReason.Cancel + Exit Sub + End If + Else + strScript = frmMain.clsRLink.strInstatDataObject & "$append_to_dataframe_metadata(data_name =" & Chr(34) & strDataName & Chr(34) & ", property = " & Chr(34) & strProperty & Chr(34) & ", new_val = " & strNewValue & ")" + strComment = "Edited data frame metadata value" + End If Try frmMain.clsRLink.RunScript(strScript, strComment:=strComment) Catch e.EndReason = unvell.ReoGrid.EndEditReason.Cancel End Try + Else + MsgBox("Developer error: Cannot find Name column in data frame metadata grid.", MsgBoxStyle.Critical, "Canont find Name column") End If End Sub @@ -104,4 +141,4 @@ Public Class ucrDataFrameMetadata grdCurrSheet.SelectAll() End If End Sub -End Class +End Class \ No newline at end of file diff --git a/instat/ucrReceiver.vb b/instat/ucrReceiver.vb index 8796254d952..9523929b582 100644 --- a/instat/ucrReceiver.vb +++ b/instat/ucrReceiver.vb @@ -328,9 +328,11 @@ Public Class ucrReceiver If clsParameter IsNot Nothing Then If bChangeParameterValue Then If bParameterIsString AndAlso clsParameter.bIsString Then - lstCurrentVariables = ExtractItemsFromRList(clsParameter.strArgumentValue) + If strValuesToIgnore Is Nothing OrElse (Not strValuesToIgnore.Contains(clsParameter.strArgumentValue)) Then + lstCurrentVariables = ExtractItemsFromRList(clsParameter.strArgumentValue) + End If ElseIf bParameterIsRFunction AndAlso clsParameter.bIsFunction Then - clsTempDataParameter = clsParameter.clsArgumentCodeStructure.GetParameter(strColumnsParameterNameInRFunction) + clsTempDataParameter = clsParameter.clsArgumentCodeStructure.GetParameter(strColumnsParameterNameInRFunction) If clsTempDataParameter IsNot Nothing Then lstCurrentVariables = ExtractItemsFromRList(clsParameter.clsArgumentCodeStructure.GetParameter(strColumnsParameterNameInRFunction).strArgumentValue) End If