From db996ee53d3554789e5da0e342c9aa7d321cd26f Mon Sep 17 00:00:00 2001 From: dannyparsons Date: Wed, 3 Aug 2016 20:17:20 +0100 Subject: [PATCH 1/2] added new receiver for calculator and modified RSyntax for calculations --- instat/clsRSyntax.vb | 140 +++++++++++++++++++++++ instat/dlgCalculator.designer.vb | 76 ++++++------ instat/dlgCalculator.vb | 29 +++++ instat/frmMain.Designer.vb | 27 +++-- instat/instat.vbproj | 15 +++ instat/ucrReceiver.vb | 7 ++ instat/ucrReceiverExpression.Designer.vb | 49 ++++++++ instat/ucrReceiverExpression.fr-FR.resx | 15 +++ instat/ucrReceiverExpression.resx | 120 +++++++++++++++++++ instat/ucrReceiverExpression.sw-KE.resx | 15 +++ instat/ucrReceiverExpression.vb | 132 +++++++++++++++++++++ instat/ucrReceiverMultiple.vb | 6 +- instat/ucrReceiverSingle.vb | 6 +- 13 files changed, 576 insertions(+), 61 deletions(-) create mode 100644 instat/ucrReceiverExpression.Designer.vb create mode 100644 instat/ucrReceiverExpression.fr-FR.resx create mode 100644 instat/ucrReceiverExpression.resx create mode 100644 instat/ucrReceiverExpression.sw-KE.resx create mode 100644 instat/ucrReceiverExpression.vb diff --git a/instat/clsRSyntax.vb b/instat/clsRSyntax.vb index 296caffcde2..05282ef1321 100644 --- a/instat/clsRSyntax.vb +++ b/instat/clsRSyntax.vb @@ -18,12 +18,24 @@ Public Class RSyntax Public clsBaseFunction As New RFunction Public clsBaseOperator As New ROperator + Public strCommandString As String = "" Public bUseBaseFunction As Boolean = False Public bUseBaseOperator As Boolean = False + Public bUseCommandString As Boolean = False Public iCallType As Integer = 0 Public strScript As String Public i As Integer Public bExcludeAssignedFunctionOutput As Boolean = True + Private strAssignTo As String + Private strAssignToDataframe As String + Private strAssignToColumn As String + Private strAssignToModel As String + Private strAssignToGraph As String + Public bToBeAssigned As Boolean = False + Public bIsAssigned As Boolean = False + Private bAssignToIsPrefix As Boolean + Private bAssignToColumnWithoutNames As String + Private bInsertColumnBefore As String Public Sub SetFunction(strFunctionName As String, Optional ByRef clsFunction As RFunction = Nothing) If clsFunction Is Nothing Then @@ -32,18 +44,28 @@ Public Class RSyntax clsFunction.SetRCommand(strFunctionName) bUseBaseFunction = True bUseBaseOperator = False + bUseCommandString = False End Sub Public Sub SetBaseRFunction(clsFunction As RFunction) clsBaseFunction = clsFunction bUseBaseFunction = True bUseBaseOperator = False + bUseCommandString = False + End Sub + + Public Sub SetCommandString(strCommand As String) + strCommandString = strCommand + bUseBaseFunction = False + bUseBaseOperator = False + bUseCommandString = True End Sub Public Sub SetOperation(strOp As String, Optional bBracketTemp As Boolean = True) clsBaseOperator.SetOperation(strOp, bBracketTemp) bUseBaseFunction = False bUseBaseOperator = True + bUseCommandString = False End Sub Public Sub SetAssignTo(strAssignToName As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False, Optional bAssignToColumnWithoutNames As Boolean = False, Optional bInsertColumnBefore As Boolean = False) @@ -53,6 +75,26 @@ Public Class RSyntax If bUseBaseFunction Then clsBaseFunction.SetAssignTo(strAssignToName, strTempDataframe:=strTempDataframe, strTempColumn:=strTempColumn, strTempModel:=strTempModel, strTempGraph:=strTempGraph, bAssignToIsPrefix:=bAssignToIsPrefix, bAssignToColumnWithoutNames:=bAssignToColumnWithoutNames, bInsertColumnBefore:=bInsertColumnBefore) End If + If bUseCommandString Then + strAssignTo = strAssignToName + If Not strTempDataframe = "" Then + strAssignToDataframe = strTempDataframe + If Not strTempColumn = "" Then + strAssignToColumn = strTempColumn + End If + End If + If Not strTempModel = "" Then + strAssignToModel = strTempModel + End If + If Not strTempGraph = "" Then + strAssignToGraph = strTempGraph + End If + Me.bAssignToIsPrefix = bAssignToIsPrefix + Me.bAssignToColumnWithoutNames = bAssignToColumnWithoutNames + Me.bInsertColumnBefore = bInsertColumnBefore + bToBeAssigned = True + bIsAssigned = False + End If End Sub Public Sub RemoveAssignTo() @@ -120,6 +162,104 @@ Public Class RSyntax If bUseBaseOperator Then strTemp = clsBaseOperator.ToScript(strScript) End If + If bUseCommandString Then + Dim clsAddColumns As New RFunction + Dim clsGetColumns As New RFunction + Dim clsAddData As New RFunction + Dim clsGetData As New RFunction + Dim clsAddModels As New RFunction + Dim clsGetModels As New RFunction + Dim clsAddGraphs As New RFunction + Dim clsGetGraphs As New RFunction + Dim clsDataList As New RFunction + + strTemp = strCommandString + If bToBeAssigned Then + If Not frmMain.clsRLink.bInstatObjectExists Then + frmMain.clsRLink.CreateNewInstatObject() + End If + strScript = strScript & strAssignTo & " <- " & strTemp & vbCrLf + If Not strAssignToDataframe = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then + clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data") + clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + If bAssignToColumnWithoutNames Then + clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34)) + End If + clsAddColumns.AddParameter("col_data", strAssignTo) + If bAssignToIsPrefix Then + clsAddColumns.AddParameter("use_col_name_as_prefix", "TRUE") + Else + If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then + clsAddColumns.AddParameter("use_col_name_as_prefix", "FALSE") + End If + End If + If bInsertColumnBefore Then + clsAddColumns.AddParameter("before", "TRUE") + Else + If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then + clsAddColumns.AddParameter("before", "FALSE") + End If + End If + strScript = strScript & clsAddColumns.ToScript() & vbCrLf + + clsGetColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_columns_from_data") + clsGetColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + clsGetColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34)) + strAssignTo = clsGetColumns.ToScript() + + bIsAssigned = True + bToBeAssigned = False + ElseIf Not strAssignToModel = "" Then + clsAddModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_model") + clsAddModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34)) + clsAddModels.AddParameter("model", strAssignTo) + If Not strAssignToDataframe = "" Then + clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + clsGetModels.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + End If + strScript = strScript & clsAddModels.ToScript() & vbCrLf + + clsGetModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_models") + clsGetModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34)) + strAssignTo = clsGetModels.ToScript() + + bIsAssigned = True + bToBeAssigned = False + ElseIf Not strAssignToGraph = "" Then + clsAddGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_graph") + clsAddGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34)) + clsAddGraphs.AddParameter("graph", strAssignTo) + If Not strAssignToDataframe = "" Then + clsAddGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + clsGetGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + End If + strScript = strScript & clsAddGraphs.ToScript() & vbCrLf + + clsGetGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_graphs") + clsGetGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34)) + strAssignTo = clsGetGraphs.ToScript() + + bIsAssigned = True + bToBeAssigned = False + ElseIf Not strAssignToDataframe = "" Then + clsAddData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$import_data") + clsDataList.SetRCommand("list") + clsDataList.AddParameter(strAssignToDataframe, strAssignTo) + clsAddData.AddParameter("data_tables", clsRFunctionParameter:=clsDataList) + strScript = strScript & clsAddData.ToScript() & vbCrLf + + clsGetData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") + clsGetData.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) + strAssignTo = clsGetData.ToScript() + + bIsAssigned = True + bToBeAssigned = False + End If + strTemp = strAssignTo + Else + 'Return strTemp + End If + End If Else strTemp = clsFunction.ToScript(strScript) End If diff --git a/instat/dlgCalculator.designer.vb b/instat/dlgCalculator.designer.vb index 05ca346e1ca..cc4f90abf8c 100644 --- a/instat/dlgCalculator.designer.vb +++ b/instat/dlgCalculator.designer.vb @@ -40,16 +40,16 @@ Partial Class dlgCalculator Me.cmdPower = New System.Windows.Forms.Button() Me.cmdDelete = New System.Windows.Forms.Button() Me.cmdBackSpace = New System.Windows.Forms.Button() - Me.ucrBase = New instat.ucrButtons() - Me.ucrSelectorForCalculations = New instat.ucrSelectorByDataFrameAddRemove() Me.lblExpression = New System.Windows.Forms.Label() - Me.ucrInputExpression = New instat.ucrInputComboBox() Me.cmdTry = New System.Windows.Forms.Button() - Me.ucrSpaceToMangeResult = New instat.ucrInputTextBox() Me.chkSaveResultInto = New System.Windows.Forms.CheckBox() Me.chkDefaultCalculationName = New System.Windows.Forms.CheckBox() Me.cmdGreaterThan = New System.Windows.Forms.Button() Me.ucrSaveResultInto = New instat.ucrInputComboBox() + Me.ucrSpaceToMangeResult = New instat.ucrInputTextBox() + Me.ucrSelectorForCalculations = New instat.ucrSelectorByDataFrameAddRemove() + Me.ucrBase = New instat.ucrButtons() + Me.ucrReceiverForCalculation = New instat.ucrReceiverExpression() Me.SuspendLayout() ' 'cmd1 @@ -215,22 +215,6 @@ Partial Class dlgCalculator Me.cmdBackSpace.Text = "<" Me.cmdBackSpace.UseVisualStyleBackColor = True ' - 'ucrBase - ' - Me.ucrBase.Location = New System.Drawing.Point(9, 306) - Me.ucrBase.Name = "ucrBase" - Me.ucrBase.Size = New System.Drawing.Size(404, 50) - Me.ucrBase.TabIndex = 0 - ' - 'ucrSelectorForCalculations - ' - Me.ucrSelectorForCalculations.bShowHiddenColumns = False - Me.ucrSelectorForCalculations.Location = New System.Drawing.Point(9, 36) - Me.ucrSelectorForCalculations.Margin = New System.Windows.Forms.Padding(0) - Me.ucrSelectorForCalculations.Name = "ucrSelectorForCalculations" - Me.ucrSelectorForCalculations.Size = New System.Drawing.Size(210, 180) - Me.ucrSelectorForCalculations.TabIndex = 106 - ' 'lblExpression ' Me.lblExpression.AutoSize = True @@ -241,14 +225,6 @@ Partial Class dlgCalculator Me.lblExpression.Tag = "Expression" Me.lblExpression.Text = "Expression" ' - 'ucrInputExpression - ' - Me.ucrInputExpression.IsReadOnly = False - Me.ucrInputExpression.Location = New System.Drawing.Point(98, 12) - Me.ucrInputExpression.Name = "ucrInputExpression" - Me.ucrInputExpression.Size = New System.Drawing.Size(399, 21) - Me.ucrInputExpression.TabIndex = 108 - ' 'cmdTry ' Me.cmdTry.Location = New System.Drawing.Point(9, 228) @@ -258,14 +234,6 @@ Partial Class dlgCalculator Me.cmdTry.Text = "Try" Me.cmdTry.UseVisualStyleBackColor = True ' - 'ucrSpaceToMangeResult - ' - Me.ucrSpaceToMangeResult.IsReadOnly = False - Me.ucrSpaceToMangeResult.Location = New System.Drawing.Point(91, 229) - Me.ucrSpaceToMangeResult.Name = "ucrSpaceToMangeResult" - Me.ucrSpaceToMangeResult.Size = New System.Drawing.Size(284, 21) - Me.ucrSpaceToMangeResult.TabIndex = 111 - ' 'chkSaveResultInto ' Me.chkSaveResultInto.AutoSize = True @@ -303,18 +271,50 @@ Partial Class dlgCalculator Me.ucrSaveResultInto.Size = New System.Drawing.Size(256, 21) Me.ucrSaveResultInto.TabIndex = 117 ' + 'ucrSpaceToMangeResult + ' + Me.ucrSpaceToMangeResult.IsReadOnly = False + Me.ucrSpaceToMangeResult.Location = New System.Drawing.Point(91, 229) + Me.ucrSpaceToMangeResult.Name = "ucrSpaceToMangeResult" + Me.ucrSpaceToMangeResult.Size = New System.Drawing.Size(284, 21) + Me.ucrSpaceToMangeResult.TabIndex = 111 + ' + 'ucrSelectorForCalculations + ' + Me.ucrSelectorForCalculations.bShowHiddenColumns = False + Me.ucrSelectorForCalculations.Location = New System.Drawing.Point(9, 36) + Me.ucrSelectorForCalculations.Margin = New System.Windows.Forms.Padding(0) + Me.ucrSelectorForCalculations.Name = "ucrSelectorForCalculations" + Me.ucrSelectorForCalculations.Size = New System.Drawing.Size(210, 180) + Me.ucrSelectorForCalculations.TabIndex = 106 + ' + 'ucrBase + ' + Me.ucrBase.Location = New System.Drawing.Point(9, 306) + Me.ucrBase.Name = "ucrBase" + Me.ucrBase.Size = New System.Drawing.Size(404, 50) + Me.ucrBase.TabIndex = 0 + ' + 'ucrReceiverForCalculation + ' + Me.ucrReceiverForCalculation.Location = New System.Drawing.Point(90, 16) + Me.ucrReceiverForCalculation.Name = "ucrReceiverForCalculation" + Me.ucrReceiverForCalculation.Selector = Nothing + Me.ucrReceiverForCalculation.Size = New System.Drawing.Size(284, 20) + Me.ucrReceiverForCalculation.TabIndex = 118 + ' 'dlgCalculator ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(505, 363) + Me.Controls.Add(Me.ucrReceiverForCalculation) Me.Controls.Add(Me.ucrSaveResultInto) Me.Controls.Add(Me.cmdGreaterThan) Me.Controls.Add(Me.chkDefaultCalculationName) Me.Controls.Add(Me.chkSaveResultInto) Me.Controls.Add(Me.ucrSpaceToMangeResult) Me.Controls.Add(Me.cmdTry) - Me.Controls.Add(Me.ucrInputExpression) Me.Controls.Add(Me.lblExpression) Me.Controls.Add(Me.ucrSelectorForCalculations) Me.Controls.Add(Me.cmdBackSpace) @@ -368,11 +368,11 @@ Partial Class dlgCalculator Friend WithEvents cmdBackSpace As Button Friend WithEvents ucrSelectorForCalculations As ucrSelectorByDataFrameAddRemove Friend WithEvents lblExpression As Label - Friend WithEvents ucrInputExpression As ucrInputComboBox Friend WithEvents cmdTry As Button Friend WithEvents ucrSpaceToMangeResult As ucrInputTextBox Friend WithEvents chkSaveResultInto As CheckBox Friend WithEvents chkDefaultCalculationName As CheckBox Friend WithEvents cmdGreaterThan As Button Friend WithEvents ucrSaveResultInto As ucrInputComboBox + Friend WithEvents ucrReceiverForCalculation As ucrReceiverExpression End Class diff --git a/instat/dlgCalculator.vb b/instat/dlgCalculator.vb index 6e82245cc51..8ecc85c8106 100644 --- a/instat/dlgCalculator.vb +++ b/instat/dlgCalculator.vb @@ -1,12 +1,23 @@ Imports RDotNet Public Class dlgCalculator Dim dataset As DataFrame + Dim clsAttach As New RFunction + Dim clsDetach As New RFunction Private Sub dlgCalculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load ucrBase.OKEnabled(False) cmdBackSpace.Enabled = True 'txtCalcLine.Select() ucrBase.iHelpTopicID = 14 + InitialiseDialog() + End Sub + + Private Sub InitialiseDialog() + ucrReceiverForCalculation.Selector = ucrSelectorForCalculations + ucrReceiverForCalculation.SetMeAsReceiver() + clsAttach.SetRCommand("attach") + clsDetach.SetRCommand("detach") + ucrBase.clsRsyntax.SetCommandString("") End Sub Private Sub AddText(strVar As String, Optional intStepsBack As Integer = 0, Optional bolInsertSelected As Boolean = False) @@ -31,6 +42,7 @@ Public Class dlgCalculator Private Sub cmd1_Click(sender As Object, e As EventArgs) Handles cmd1.Click AddText("1") + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("1") End Sub Private Sub cmd2_Click(sender As Object, e As EventArgs) Handles cmd2.Click @@ -150,5 +162,22 @@ Public Class dlgCalculator AddText("exp()", 1, True) End Sub + Private Sub ucrSaveResultInto_NameChanged() Handles ucrSaveResultInto.NameChanged + ucrBase.clsRsyntax.SetAssignTo(ucrSaveResultInto.GetText(), strTempColumn:=ucrSaveResultInto.GetText(), strTempDataframe:=ucrSelectorForCalculations.ucrAvailableDataFrames.cboAvailableDataFrames.Text) + End Sub + + Private Sub ucrBase_BeforeClickOk(sender As Object, e As EventArgs) Handles ucrBase.BeforeClickOk + clsAttach.AddParameter("what", clsRFunctionParameter:=ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame) + frmMain.clsRLink.RunScript(clsAttach.ToScript()) + End Sub + + Private Sub ucrBase_ClickOk(sender As Object, e As EventArgs) Handles ucrBase.ClickOk + clsDetach.AddParameter("what", clsRFunctionParameter:=ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame) + frmMain.clsRLink.RunScript(clsDetach.ToScript()) + End Sub + Private Sub ucrReceiverForCalculation_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverForCalculation.SelectionChanged + ucrBase.clsRsyntax.SetCommandString(ucrReceiverForCalculation.GetVariableNames(False)) + ucrBase.OKEnabled(True) + End Sub End Class \ No newline at end of file diff --git a/instat/frmMain.Designer.vb b/instat/frmMain.Designer.vb index 22dc4269287..f84b9d7983d 100644 --- a/instat/frmMain.Designer.vb +++ b/instat/frmMain.Designer.vb @@ -877,28 +877,28 @@ Partial Class frmMain 'mnuModelOtherTwoVariablesTwoSamples ' Me.mnuModelOtherTwoVariablesTwoSamples.Name = "mnuModelOtherTwoVariablesTwoSamples" - Me.mnuModelOtherTwoVariablesTwoSamples.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesTwoSamples.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesTwoSamples.Tag = "Two_Samples..." Me.mnuModelOtherTwoVariablesTwoSamples.Text = "Two Samples..." ' 'mnuModelOtherTwoVariablesSummaryData ' Me.mnuModelOtherTwoVariablesSummaryData.Name = "mnuModelOtherTwoVariablesSummaryData" - Me.mnuModelOtherTwoVariablesSummaryData.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesSummaryData.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesSummaryData.Tag = "Summary_Data" Me.mnuModelOtherTwoVariablesSummaryData.Text = "Summary Data..." ' 'mnuModelOtherTwoVariablesSimpleRegression ' Me.mnuModelOtherTwoVariablesSimpleRegression.Name = "mnuModelOtherTwoVariablesSimpleRegression" - Me.mnuModelOtherTwoVariablesSimpleRegression.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesSimpleRegression.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesSimpleRegression.Tag = "Simple_Regression" Me.mnuModelOtherTwoVariablesSimpleRegression.Text = "Simple Regression..." ' 'mnuModelOtherTwoVariablesOneWayANOVA ' Me.mnuModelOtherTwoVariablesOneWayANOVA.Name = "mnuModelOtherTwoVariablesOneWayANOVA" - Me.mnuModelOtherTwoVariablesOneWayANOVA.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesOneWayANOVA.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesOneWayANOVA.Tag = "One_Way_ANOVA" Me.mnuModelOtherTwoVariablesOneWayANOVA.Text = "One Way ANOVA..." ' @@ -906,14 +906,14 @@ Partial Class frmMain ' Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Enabled = False Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Name = "mnuModelOtherTwoVariablesNonParametricTwoSamples" - Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Tag = "Non_Parameteric_Two_Samples" Me.mnuModelOtherTwoVariablesNonParametricTwoSamples.Text = "Non Parametric Two Samples..." ' 'mnuModelOtherTwoVariablesNonParametricOneWayANOVA ' Me.mnuModelOtherTwoVariablesNonParametricOneWayANOVA.Name = "mnuModelOtherTwoVariablesNonParametricOneWayANOVA" - Me.mnuModelOtherTwoVariablesNonParametricOneWayANOVA.Size = New System.Drawing.Size(266, 22) + Me.mnuModelOtherTwoVariablesNonParametricOneWayANOVA.Size = New System.Drawing.Size(267, 22) Me.mnuModelOtherTwoVariablesNonParametricOneWayANOVA.Tag = "Non_Parameteric_One_Way_ANOVA..." Me.mnuModelOtherTwoVariablesNonParametricOneWayANOVA.Text = "Non Parameteric One Way ANOVA..." ' @@ -929,21 +929,21 @@ Partial Class frmMain ' Me.mnuModelOtherThreeVariablesSimpleWithGroups.Enabled = False Me.mnuModelOtherThreeVariablesSimpleWithGroups.Name = "mnuModelOtherThreeVariablesSimpleWithGroups" - Me.mnuModelOtherThreeVariablesSimpleWithGroups.Size = New System.Drawing.Size(260, 22) + Me.mnuModelOtherThreeVariablesSimpleWithGroups.Size = New System.Drawing.Size(262, 22) Me.mnuModelOtherThreeVariablesSimpleWithGroups.Tag = "Simple_with_groups" Me.mnuModelOtherThreeVariablesSimpleWithGroups.Text = "Simple With Groups..." ' 'mnuModelOtherThreeVariablesNonParametricTwoWayANOVA ' Me.mnuModelOtherThreeVariablesNonParametricTwoWayANOVA.Name = "mnuModelOtherThreeVariablesNonParametricTwoWayANOVA" - Me.mnuModelOtherThreeVariablesNonParametricTwoWayANOVA.Size = New System.Drawing.Size(260, 22) + Me.mnuModelOtherThreeVariablesNonParametricTwoWayANOVA.Size = New System.Drawing.Size(262, 22) Me.mnuModelOtherThreeVariablesNonParametricTwoWayANOVA.Tag = "Non_Parametric_Two_Way_ANOVA..." Me.mnuModelOtherThreeVariablesNonParametricTwoWayANOVA.Text = "Non Parametric Two Way ANOVA..." ' 'mnuModelOtherThreeVariablesChisquareTest ' Me.mnuModelOtherThreeVariablesChisquareTest.Name = "mnuModelOtherThreeVariablesChisquareTest" - Me.mnuModelOtherThreeVariablesChisquareTest.Size = New System.Drawing.Size(260, 22) + Me.mnuModelOtherThreeVariablesChisquareTest.Size = New System.Drawing.Size(262, 22) Me.mnuModelOtherThreeVariablesChisquareTest.Tag = "Chi-square_Test" Me.mnuModelOtherThreeVariablesChisquareTest.Text = "Chi-square Test..." ' @@ -958,21 +958,21 @@ Partial Class frmMain 'mnuModelOtherGeneralANOVAGeneral ' Me.mnuModelOtherGeneralANOVAGeneral.Name = "mnuModelOtherGeneralANOVAGeneral" - Me.mnuModelOtherGeneralANOVAGeneral.Size = New System.Drawing.Size(166, 22) + Me.mnuModelOtherGeneralANOVAGeneral.Size = New System.Drawing.Size(167, 22) Me.mnuModelOtherGeneralANOVAGeneral.Tag = "ANOVA_General..." Me.mnuModelOtherGeneralANOVAGeneral.Text = "ANOVA General..." ' 'mnuModelOtherGeneralRegression ' Me.mnuModelOtherGeneralRegression.Name = "mnuModelOtherGeneralRegression" - Me.mnuModelOtherGeneralRegression.Size = New System.Drawing.Size(166, 22) + Me.mnuModelOtherGeneralRegression.Size = New System.Drawing.Size(167, 22) Me.mnuModelOtherGeneralRegression.Tag = "Regression" Me.mnuModelOtherGeneralRegression.Text = "Regression..." ' 'mnuModelOtherGeneralLogLinear ' Me.mnuModelOtherGeneralLogLinear.Name = "mnuModelOtherGeneralLogLinear" - Me.mnuModelOtherGeneralLogLinear.Size = New System.Drawing.Size(166, 22) + Me.mnuModelOtherGeneralLogLinear.Size = New System.Drawing.Size(167, 22) Me.mnuModelOtherGeneralLogLinear.Tag = "Log_Linear" Me.mnuModelOtherGeneralLogLinear.Text = "Log Linear..." ' @@ -1925,7 +1925,6 @@ Partial Class frmMain ' 'mnuOrganiseColumnCalculateCalculations ' - Me.mnuOrganiseColumnCalculateCalculations.Enabled = False Me.mnuOrganiseColumnCalculateCalculations.Name = "mnuOrganiseColumnCalculateCalculations" Me.mnuOrganiseColumnCalculateCalculations.Size = New System.Drawing.Size(160, 22) Me.mnuOrganiseColumnCalculateCalculations.Tag = "Calculations..." @@ -2632,7 +2631,7 @@ Partial Class frmMain ' Me.mnuTools.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuToolsRunRCode, Me.mnuToolsRestartR, Me.mnuToolsCheckForUpdates, Me.mnuToolsClearOutputWindow, Me.ToolStripSeparator5, Me.mnuToolsSaveCurrentOptions, Me.mnuToolsLoadOptions, Me.mnuToolsOptions}) Me.mnuTools.Name = "mnuTools" - Me.mnuTools.Size = New System.Drawing.Size(47, 20) + Me.mnuTools.Size = New System.Drawing.Size(48, 20) Me.mnuTools.Text = "Tools" ' 'mnuToolsRunRCode diff --git a/instat/instat.vbproj b/instat/instat.vbproj index 0ecaf447119..fac151f5624 100644 --- a/instat/instat.vbproj +++ b/instat/instat.vbproj @@ -1643,6 +1643,12 @@ UserControl + + ucrReceiverExpression.vb + + + UserControl + ucrReceiverMetadataProperty.vb @@ -3890,6 +3896,15 @@ ucrNewColumnName.vb + + ucrReceiverExpression.vb + + + ucrReceiverExpression.vb + + + ucrReceiverExpression.vb + ucrReceiverMetadataProperty.vb diff --git a/instat/ucrReceiver.vb b/instat/ucrReceiver.vb index 72035dbe025..806829884e8 100644 --- a/instat/ucrReceiver.vb +++ b/instat/ucrReceiver.vb @@ -25,6 +25,7 @@ Public Class ucrReceiver Public bTypeSet As Boolean Protected strType As String Public bExcludeFromSelector As Boolean = False + Public Event SelectionChanged(sender As Object, e As EventArgs) Public Sub New() ' This call is required by the designer. @@ -242,4 +243,10 @@ Public Class ucrReceiver ' End If 'Next End Sub + + Public Sub OnSelectionChanged() + Dim sender As New Object + Dim e As New EventArgs + RaiseEvent SelectionChanged(sender, e) + End Sub End Class diff --git a/instat/ucrReceiverExpression.Designer.vb b/instat/ucrReceiverExpression.Designer.vb new file mode 100644 index 00000000000..adb02a56e30 --- /dev/null +++ b/instat/ucrReceiverExpression.Designer.vb @@ -0,0 +1,49 @@ + _ +Partial Class ucrReceiverExpression + Inherits instat.ucrReceiver + + 'UserControl overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + '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.cboExpression = New System.Windows.Forms.ComboBox() + Me.SuspendLayout() + ' + 'cboExpression + ' + Me.cboExpression.Dock = System.Windows.Forms.DockStyle.Fill + Me.cboExpression.FormattingEnabled = True + Me.cboExpression.Location = New System.Drawing.Point(0, 0) + Me.cboExpression.Name = "cboExpression" + Me.cboExpression.Size = New System.Drawing.Size(250, 21) + Me.cboExpression.TabIndex = 0 + ' + 'ucrReceiverExpression + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.Controls.Add(Me.cboExpression) + Me.Name = "ucrReceiverExpression" + Me.Size = New System.Drawing.Size(250, 20) + Me.ResumeLayout(False) + + End Sub + + Friend WithEvents cboExpression As ComboBox +End Class diff --git a/instat/ucrReceiverExpression.fr-FR.resx b/instat/ucrReceiverExpression.fr-FR.resx new file mode 100644 index 00000000000..a3df4f013d3 --- /dev/null +++ b/instat/ucrReceiverExpression.fr-FR.resx @@ -0,0 +1,15 @@ + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/instat/ucrReceiverExpression.resx b/instat/ucrReceiverExpression.resx new file mode 100644 index 00000000000..1af7de150c9 --- /dev/null +++ b/instat/ucrReceiverExpression.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/instat/ucrReceiverExpression.sw-KE.resx b/instat/ucrReceiverExpression.sw-KE.resx new file mode 100644 index 00000000000..a3df4f013d3 --- /dev/null +++ b/instat/ucrReceiverExpression.sw-KE.resx @@ -0,0 +1,15 @@ + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/instat/ucrReceiverExpression.vb b/instat/ucrReceiverExpression.vb new file mode 100644 index 00000000000..cd0e4fa2350 --- /dev/null +++ b/instat/ucrReceiverExpression.vb @@ -0,0 +1,132 @@ +' Instat-R +' Copyright (C) 2015 +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License k +' along with this program. If not, see . + +Imports RDotNet + +Public Class ucrReceiverExpression + Private lstItemsInExpression As List(Of KeyValuePair(Of String, String)) + Private lstDataFrames As List(Of String) + Private iCurrentPosition As Integer = 0 + + Public Sub New() + ' This call is required by the designer. + InitializeComponent() + + ' Add any initialization after the InitializeComponent() call. + lstItemsInExpression = New List(Of KeyValuePair(Of String, String)) + lstDataFrames = New List(Of String) + End Sub + + Public Overrides Sub AddSelected() + If Selector.lstAvailableVariable.SelectedItems.Count = 1 Then + Add(Selector.lstAvailableVariable.SelectedItems.Item(0).Text, Selector.lstAvailableVariable.SelectedItems.Item(0).Tag) + Else + 'Error? + End If + End Sub + + Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "") + Dim strCurrentItemType As String + Dim kvpItem As KeyValuePair(Of String, String) + + MyBase.Add(strItem, strDataFrame) + + If bTypeSet Then + strCurrentItemType = strType + Else + strCurrentItemType = Selector.GetItemType() + End If + If cboExpression.Enabled Then + If strCurrentItemType = "column" Then + If strDataFrame = "" Then + SetMeAsReceiver() + For i = 0 To Selector.lstAvailableVariable.Items.Count - 1 + If Selector.lstAvailableVariable.Items(i).Text = strItem Then + strDataFrame = Selector.lstAvailableVariable.Items(i).Tag + End If + Next + End If + End If + If Not lstDataFrames.Contains(strDataFrame) Then + lstDataFrames.Add(strDataFrame) + End If + kvpItem = New KeyValuePair(Of String, String)(strDataFrame, strItem) + AddToItemsInExpressionList(kvpItem) + AddToReceiverAtCursorPosition(strItem) + Selector.AddToVariablesList(strItem) + OnSelectionChanged() + End If + End Sub + + Private Sub AddToItemsInExpressionList(kvpItem As KeyValuePair(Of String, String)) + If Not lstItemsInExpression.Contains(kvpItem) Then + lstItemsInExpression.Add(kvpItem) + End If + End Sub + + Public Sub AddToReceiverAtPosition(strText As String, iPosition As Integer) + cboExpression.Text = cboExpression.Text.Insert(iPosition, strText) + iCurrentPosition = iCurrentPosition + strText.Length + cboExpression.SelectionStart = iCurrentPosition + cboExpression.SelectedText = "" + End Sub + + Public Sub AddToReceiverAtCursorPosition(strText As String) + AddToReceiverAtPosition(strText, iCurrentPosition) + End Sub + + Public Overrides Sub RemoveSelected() + Dim kvpItem As KeyValuePair(Of String, String) + + If cboExpression.Enabled Then + If Selector IsNot Nothing Then + For Each kvpItem In lstItemsInExpression + Selector.RemoveFromVariablesList(kvpItem.Value) + Next + End If + cboExpression.Text = "" + End If + MyBase.RemoveSelected() + End Sub + + Public Overrides Sub Clear() + RemoveSelected() + End Sub + + Public Overrides Function IsEmpty() As Boolean + Return cboExpression.Text = "" + End Function + + Private Sub cboExpression_KeyUp(sender As Object, e As KeyEventArgs) Handles cboExpression.KeyUp + iCurrentPosition = cboExpression.SelectionStart + End Sub + + Private Sub cboExpression_MouseDown(sender As Object, e As MouseEventArgs) Handles cboExpression.MouseDown + iCurrentPosition = cboExpression.SelectionStart + End Sub + + Private Sub cboExpression_TextChanged(sender As Object, e As EventArgs) Handles cboExpression.TextChanged + OnSelectionChanged() + End Sub + + Public Overrides Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String + If bWithQuotes Then + Return Chr(34) & cboExpression.Text & Chr(34) + Else + Return cboExpression.Text + End If + End Function +End Class diff --git a/instat/ucrReceiverMultiple.vb b/instat/ucrReceiverMultiple.vb index d7b7f8a84f6..e6262e20c92 100644 --- a/instat/ucrReceiverMultiple.vb +++ b/instat/ucrReceiverMultiple.vb @@ -26,8 +26,6 @@ Public Class ucrReceiverMultiple End If End Sub - Public Event SelectionChanged() - Public Overrides Sub AddSelected() Dim lstItems(Selector.lstAvailableVariable.SelectedItems.Count - 1) As KeyValuePair(Of String, String) Dim lviTemp As ListViewItem @@ -71,7 +69,7 @@ Public Class ucrReceiverMultiple Selector.RemoveFromVariablesList(objItem.Text) Next End If - RaiseEvent SelectionChanged() + OnSelectionChanged() MyBase.RemoveSelected() End Sub @@ -304,7 +302,7 @@ Public Class ucrReceiverMultiple Selector.AddToVariablesList(kvpTempItem.Value) End If Next - RaiseEvent SelectionChanged() + OnSelectionChanged() End Sub Public Overrides Sub Add(strItem As String, Optional strDataFrame As String = "") diff --git a/instat/ucrReceiverSingle.vb b/instat/ucrReceiverSingle.vb index 2a5e906ffdf..52fc3ee4bd3 100644 --- a/instat/ucrReceiverSingle.vb +++ b/instat/ucrReceiverSingle.vb @@ -179,13 +179,9 @@ Public Class ucrReceiverSingle Return strDataFrameName End Function - Public Event SelectionChanged(sender As Object, e As EventArgs) - - - Private Sub txtReceiverSingle_TextChanged(sender As Object, e As EventArgs) Handles txtReceiverSingle.TextChanged OnValueChanged(sender, e) - RaiseEvent SelectionChanged(sender, e) + OnSelectionChanged() End Sub Public Overrides Sub SetColor() From d351c1019fe340e29808493fd2769ddbbe662b75 Mon Sep 17 00:00:00 2001 From: dannyparsons Date: Thu, 4 Aug 2016 10:15:01 +0100 Subject: [PATCH 2/2] fixed calculator assignment --- instat/clsRSyntax.vb | 4 ++-- instat/dlgCalculator.vb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/instat/clsRSyntax.vb b/instat/clsRSyntax.vb index 05282ef1321..1447876feb3 100644 --- a/instat/clsRSyntax.vb +++ b/instat/clsRSyntax.vb @@ -34,7 +34,7 @@ Public Class RSyntax Public bToBeAssigned As Boolean = False Public bIsAssigned As Boolean = False Private bAssignToIsPrefix As Boolean - Private bAssignToColumnWithoutNames As String + Private bAssignToColumnWithoutNames As Boolean Private bInsertColumnBefore As String Public Sub SetFunction(strFunctionName As String, Optional ByRef clsFunction As RFunction = Nothing) @@ -182,7 +182,7 @@ Public Class RSyntax If Not strAssignToDataframe = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data") clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34)) - If bAssignToColumnWithoutNames Then + If Not bAssignToColumnWithoutNames Then clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34)) End If clsAddColumns.AddParameter("col_data", strAssignTo) diff --git a/instat/dlgCalculator.vb b/instat/dlgCalculator.vb index 8ecc85c8106..c6692378581 100644 --- a/instat/dlgCalculator.vb +++ b/instat/dlgCalculator.vb @@ -17,6 +17,7 @@ Public Class dlgCalculator ucrReceiverForCalculation.SetMeAsReceiver() clsAttach.SetRCommand("attach") clsDetach.SetRCommand("detach") + clsDetach.AddParameter("unload", "TRUE") ucrBase.clsRsyntax.SetCommandString("") End Sub @@ -167,13 +168,19 @@ Public Class dlgCalculator End Sub Private Sub ucrBase_BeforeClickOk(sender As Object, e As EventArgs) Handles ucrBase.BeforeClickOk + Dim strScript As String = "" + Dim strFunc As String clsAttach.AddParameter("what", clsRFunctionParameter:=ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame) - frmMain.clsRLink.RunScript(clsAttach.ToScript()) + strFunc = clsAttach.ToScript(strScript) + frmMain.clsRLink.RunScript(strScript & strFunc) End Sub Private Sub ucrBase_ClickOk(sender As Object, e As EventArgs) Handles ucrBase.ClickOk - clsDetach.AddParameter("what", clsRFunctionParameter:=ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame) - frmMain.clsRLink.RunScript(clsDetach.ToScript()) + Dim strScript As String = "" + Dim strFunc As String + clsDetach.AddParameter("name", clsRFunctionParameter:=ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame) + strFunc = clsDetach.ToScript(strScript) + frmMain.clsRLink.RunScript(strScript & strFunc) End Sub Private Sub ucrReceiverForCalculation_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverForCalculation.SelectionChanged