Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
Improve Edit and load, create duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavWeisler committed Nov 20, 2021
1 parent 3955d44 commit a02f968
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 307 deletions.
378 changes: 232 additions & 146 deletions PopUp_Researcher/BrmsForm.Designer.cs

Large diffs are not rendered by default.

139 changes: 106 additions & 33 deletions PopUp_Researcher/BrmsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class BrmsForm : Form
/// <summary>
/// Return fullscreen for edit
/// </summary>
public FullScreen ReturnEdit;
public Brms ReturnEdit;

/// <summary>
/// Already exist bRMS names
Expand All @@ -57,7 +57,7 @@ public partial class BrmsForm : Form
/// <summary>
/// Basic Constructors
/// </summary>
public BrmsForm(Brms _existingTrial=null, List<string> existingTrialsNames = null)
public BrmsForm(Brms _existingTrial = null, List<string> existingTrialsNames = null)
{
InitializeComponent();
if (this.Helper == null)
Expand All @@ -76,6 +76,7 @@ public BrmsForm(Brms _existingTrial=null, List<string> existingTrialsNames = nul
if(_existingTrial != null)
{
this.existingTrial = _existingTrial;
this.StimulusGroup.Enabled = false;
UpdateExistingTrial();
}

Expand Down Expand Up @@ -131,22 +132,8 @@ private void HelpCsvTextBox_DoubleClick(object sender, EventArgs e)
HelpCsvTextBox.Text = string.Empty;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddButton_Click(object sender, EventArgs e)
private Brms getNewBrms()
{
if(TagsListView.SelectedItems.Count < 1) { return; }

var validationString = ValidateBeforeAdd();
if(!string.IsNullOrEmpty(validationString))
{
MessageBox.Show(validationString);
return;
}

var newBrms = new Brms
{
block = this.BlockNumeric.Value,
Expand All @@ -173,15 +160,15 @@ private void AddButton_Click(object sender, EventArgs e)
this.MaskedControlRadioButton.Checked ? "Masked" : "UNMASK";

newBrms.two_side = this.doubleTagCheckBox.Checked;
if(newBrms.two_side)
if (newBrms.two_side)
{
newBrms.tags2 = new List<string>();
foreach (ListViewItem tag in secondTagsListView.SelectedItems)
{
newBrms.tags2.Add(tag.Text);
}
}

newBrms.fade_in_time = this.FadeInTimeNumeric.Value;
newBrms.fade_out_time = this.FacdeOutTimeNumeric.Value;
newBrms.mondrian_count = this.MondrianCountNumeric.Value;
Expand Down Expand Up @@ -212,6 +199,24 @@ private void AddButton_Click(object sender, EventArgs e)
}
newBrms.choices = choicesList;

return newBrms;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddButton_Click(object sender, EventArgs e)
{
var validationString = ValidateBeforeAdd();
if (!string.IsNullOrEmpty(validationString))
{
MessageBox.Show(validationString);
return;
}

var newBrms = getNewBrms();
this.BrmsNames.Add(newBrms.name);
this.brmsTrials[newBrms.name] = newBrms;
brms_count++;
Expand All @@ -223,7 +228,12 @@ private void AddButton_Click(object sender, EventArgs e)
/// </summary>
private void UpdateExistingTrial()
{
this.BlockNumeric.Value = existingTrial.block;
this.NameTextBox.Text = this.existingTrial.name;
this.NameGroupBox.Enabled = false;
this.AllBRMSGroupBox.Enabled = false;
this.AddButton.Enabled = false;

this.BlockNumeric.Value = this.existingTrial.block;
this.SubBlockNumeric.Value = this.existingTrial.sub_block;
this.FadeInTimeNumeric.Value = this.existingTrial.fade_in_time;
this.FacdeOutTimeNumeric.Value = this.existingTrial.fade_out_time;
Expand All @@ -242,6 +252,35 @@ private void UpdateExistingTrial()
this.RectWidthNumeric.Value = this.existingTrial.rectangle_width;
this.RectHeightNumeric.Value = this.existingTrial.rectangle_height;
this.StimulusDurationNumeric.Value = this.existingTrial.stimulus_duration;
this.doubleTagCheckBox.Checked = this.existingTrial.two_side;

foreach(string choice in this.existingTrial.choices)
{
AddNewChoice(choice);
}

foreach(string tag in this.existingTrial.StimulusDictionary.Keys)
{
this.TagsListView.Items.Add(tag);
this.secondTagsListView.Items.Add(tag);
}

if (this.existingTrial.tags1 != null)
{
foreach (string tag in this.existingTrial.tags1)
{
this.TagsListView.FindItemWithText(tag).Selected = true;
//this.TagsListView.Items[tag].Selected = true;
}
}

if (this.existingTrial.tags2 != null)
{
foreach (string tag in this.existingTrial.tags2)
{
this.secondTagsListView.FindItemWithText(tag).Selected = true;
}
}
}

/// <summary>
Expand Down Expand Up @@ -286,7 +325,10 @@ private void PageEnabled()
{
var enabled = !string.IsNullOrEmpty(HelpCsvTextBox.Text);
AllBRMSGroupBox.Enabled = enabled;
ParamsGroupBox.Enabled = enabled;
if(this.existingTrial == null)
{
ParamsGroupBox.Enabled = enabled;
}
EnableSecondStimulus();
}

Expand All @@ -301,20 +343,28 @@ private string ValidateBeforeAdd()
{
return ErrMsg.NameMissingError;
}
if(this.TagsListView.SelectedItems.Count == 0)
{
return "Missing Tags";
}
foreach (var name in BrmsNames)
{
if (name.Equals(NameTextBox.Text))
{
return ErrMsg.NameAlreadyExistError;
}
}
foreach (var name in this.existingNames)
if(this.existingTrial == null)
{
if (name.Equals(NameTextBox.Text))
foreach (var name in this.existingNames)
{
return ErrMsg.NameAlreadyExistError;
if (name.Equals(NameTextBox.Text))
{
return ErrMsg.NameAlreadyExistError;
}
}
}
}

return string.Empty;
}

Expand Down Expand Up @@ -367,9 +417,31 @@ private void UpButton_Click(object sender, EventArgs e)
/// <param name="e"></param>
private void SaveButton_Click(object sender, EventArgs e)
{
if (BrmsNames.Count <= 0) return;
MainForm.AddBrms(brmsTrials);
Close();
if(this.existingTrial != null)
{
var validationString = ValidateBeforeAdd();
if (!string.IsNullOrEmpty(validationString))
{
MessageBox.Show(validationString);
return;
}
this.ReturnEdit = getNewBrms();
}
else
{
if (BrmsNames.Count <= 0) return;
MainForm.AddBrms(brmsTrials);
Close();
}
}

private void AddNewChoice(string choice)
{
this.ChoicesTextBox.Text += choice;
if (!string.IsNullOrEmpty(this.ChoicesTextBox.Text))
{
this.ChoicesTextBox.Text += ",";
}
}

/// <summary>
Expand All @@ -395,11 +467,7 @@ private void ChoicesButton_Click(object sender, EventArgs e)
}
else
{
this.ChoicesTextBox.Text += this.AddChoiceTextBox.Text;
if (!string.IsNullOrEmpty(this.ChoicesTextBox.Text))
{
this.ChoicesTextBox.Text += ",";
}
this.AddNewChoice(this.AddChoiceTextBox.Text);
this.AddChoiceTextBox.Text = string.Empty;
}
}
Expand All @@ -415,5 +483,10 @@ private void EnableSecondStimulus()
{
this.secondTagsGroupBox.Enabled = this.doubleTagCheckBox.Checked;
}

private void ChoicesResetButton_Click(object sender, EventArgs e)
{
this.ChoicesTextBox.Text = string.Empty;
}
}
}
Loading

0 comments on commit a02f968

Please sign in to comment.