/// <summary> /// <see cref="Control.Click"/> event handler /// for the <see cref="btnAddCondition"/> <see cref="Button"/> /// Updates the <see cref="lsbStopConditions"/> items with the new /// stop condition, resp. response. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">An empty <see cref="EventArgs"/></param> private void btnAddCondition_Click(object sender, EventArgs e) { if (this.rdbTime.Checked) { TimeStopCondition tsc = new TimeStopCondition((int)(this.nudTime.Value * 1000)); // Remove existing TimeConditions, because only one can be valid... TimeStopCondition oldTimeCondition = null; foreach (object condition in this.lsbStopConditions.Items) { if (condition is TimeStopCondition) { oldTimeCondition = (TimeStopCondition)condition; } } if (oldTimeCondition != null) { this.lsbStopConditions.Items.Remove(oldTimeCondition); } this.lsbStopConditions.Items.Add(tsc); } else if (this.rdbMouse.Checked) { string selectedItemMouse = (string)this.cbbMouseButtons.SelectedItem; MouseStopCondition msc = new MouseStopCondition(); msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false; if (!msc.CanBeAnyInputOfThisType) { msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse); } msc.Target = this.chbOnlyWhenInTarget.Checked ? "Any" : string.Empty; if (!this.lsbStopConditions.Items.Contains(msc)) { this.lsbStopConditions.Items.Add(msc); } } else if (this.rdbKey.Checked) { string selectedItemKeys = (string)this.cbbKeys.SelectedItem; KeyStopCondition ksc = new KeyStopCondition(); if (selectedItemKeys == "Any") { ksc.CanBeAnyInputOfThisType = true; } else { ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys); } if (!this.lsbStopConditions.Items.Contains(ksc)) { this.lsbStopConditions.Items.Add(ksc); } } }
/// <summary> /// <see cref="Control.Click"/> event handler /// for the <see cref="Button"/> <see cref="btnAddCorrectResponse"/> /// Adds a new <see cref="StopCondition"/> (response condition) to the slide /// according to the settings made in the UI. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">An empty <see cref="EventArgs"/></param> private void btnAddCorrectResponse_Click(object sender, EventArgs e) { if (this.rdbTestingMouse.Checked) { MouseStopCondition msc = new MouseStopCondition(); string selectedItemMouse = (string)this.cbbTestingMouseButtons.SelectedItem; msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false; msc.Target = this.cbbTestingTargets.Text; if (!msc.CanBeAnyInputOfThisType) { msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse); } if (!this.lsbCorrectResponses.Items.Contains(msc)) { this.lsbCorrectResponses.Items.Add(msc); } // Add this stop condition to the stopcondition list. if (!this.lsbStopConditions.Items.Contains((MouseStopCondition)msc.Clone())) { this.lsbStopConditions.Items.Add(msc); } } else if (this.rdbTestingKey.Checked) { KeyStopCondition ksc = new KeyStopCondition(); string selectedItemKeys = (string)this.cbbTestingKeys.SelectedItem; ksc.CanBeAnyInputOfThisType = selectedItemKeys == "Any" ? true : false; if (!ksc.CanBeAnyInputOfThisType) { ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys); } // Add this condition to the stopcondition list. if (!this.lsbStopConditions.Items.Contains(ksc)) { this.lsbStopConditions.Items.Add((KeyStopCondition)ksc.Clone()); } // Add this condition to the testing list. if (!this.lsbCorrectResponses.Items.Contains(ksc)) { this.lsbCorrectResponses.Items.Add(ksc); } } }
/// <summary> /// <see cref="Control.Click"/> event handler /// for the <see cref="Button"/> <see cref="btnAddLink"/> /// Adds a new <see cref="StopCondition"/> (as link condition) to the slide /// according to the settings made in the UI. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">An empty <see cref="EventArgs"/></param> private void btnAddLink_Click(object sender, EventArgs e) { if (this.rdbLinksMouse.Checked) { MouseStopCondition msc = new MouseStopCondition(); string selectedItemMouse = (string)this.cbbLinksMouseButtons.SelectedItem; msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false; msc.Target = this.cbbLinksTargets.Text; if (!msc.CanBeAnyInputOfThisType) { msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse); } Trial selectedTrial = (Trial)this.cbbLinksTrial.SelectedItem; if (selectedTrial != null) { msc.TrialID = selectedTrial.ID; // Add this link to the link list. if (!this.lsbLinks.Items.Contains(msc)) { this.lsbLinks.Items.Add((MouseStopCondition)msc.Clone()); } if (msc.Target != string.Empty) { msc.Target = "Any"; } msc.TrialID = null; // Add this link to the stopcondition list. if (!this.lsbStopConditions.Items.Contains(msc)) { this.lsbStopConditions.Items.Add(msc); } } } else if (this.rdbLinksKey.Checked) { KeyStopCondition ksc = new KeyStopCondition(); string selectedItemKeys = (string)this.cbbLinksKeys.SelectedItem; ksc.CanBeAnyInputOfThisType = selectedItemKeys == "Any" ? true : false; if (!ksc.CanBeAnyInputOfThisType) { ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys); } Trial selectedTrial = (Trial)this.cbbLinksTrial.SelectedItem; if (selectedTrial != null) { ksc.TrialID = selectedTrial.ID; // Add this link to the link list. if (!this.lsbLinks.Items.Contains(ksc)) { this.lsbLinks.Items.Add((KeyStopCondition)ksc.Clone()); } // Add this link to the stopcondition list. if (!this.lsbStopConditions.Items.Contains(ksc)) { this.lsbStopConditions.Items.Add(ksc); } } } }
/// <summary> /// This method returns the mouse clicks for the list of subjects /// on the trial with the given trial id. /// </summary> /// <param name="trialID">An <see cref="Int32"/> with the trial id.</param> /// <param name="checkedSubjects">A <see cref="List{String}"/> with the subject names.</param> /// <returns>A <see cref="SQLiteOgamaDataSet.MouseFixationsDataTable"/> /// with the mouse clicks.</returns> private DataTable GetFilteredMouseClicks(int trialID, List <string> checkedSubjects) { var clickTable = new SQLiteOgamaDataSet.MouseFixationsDataTable(); foreach (string entry in checkedSubjects) { // Ignore trials marked to be eliminated in analysis. DataTable currentTrial = Document.ActiveDocument.DocDataSet.TrialsAdapter.GetDataBySubjectAndTrialID(entry, trialID); if (currentTrial.Rows.Count > 0) { if (currentTrial.Rows[0]["EliminateData"] != null && currentTrial.Rows[0]["EliminateData"].ToString() != string.Empty) { continue; } else { int trialSequence = (int)currentTrial.Rows[0]["TrialSequence"]; DataTable trialEvents = Document.ActiveDocument.DocDataSet.TrialEventsAdapter.GetDataBySubjectAndSequence(entry, trialSequence); foreach (DataRow trialEvent in trialEvents.Rows) { string typeString = trialEvent["EventType"].ToString(); EventType type = EventType.None; try { type = (EventType)Enum.Parse(typeof(EventType), typeString, true); } catch (ArgumentException) { continue; } if (type == EventType.Mouse) { string taskString = trialEvent["EventTask"].ToString(); string paramString = trialEvent["EventParam"].ToString(); MouseStopCondition msc = (MouseStopCondition)TypeDescriptor.GetConverter(typeof(StopCondition)).ConvertFrom(paramString); InputEventTask task = (InputEventTask)Enum.Parse(typeof(InputEventTask), taskString, true); switch (task) { case InputEventTask.Down: SQLiteOgamaDataSet.MouseFixationsRow newRow = clickTable.NewMouseFixationsRow(); newRow.PosX = msc.ClickLocation.X; newRow.PosY = msc.ClickLocation.Y; newRow.SubjectName = entry; newRow.TrialID = trialID; newRow.TrialSequence = trialSequence; clickTable.AddMouseFixationsRow(newRow); break; } } else if (type == EventType.Response) { string taskString = trialEvent["EventTask"].ToString(); string paramString = trialEvent["EventParam"].ToString(); StopCondition sc = (StopCondition)TypeDescriptor.GetConverter(typeof(StopCondition)).ConvertFrom(paramString); if (sc is MouseStopCondition) { MouseStopCondition msc = sc as MouseStopCondition; InputEventTask task = (InputEventTask)Enum.Parse(typeof(InputEventTask), taskString, true); SQLiteOgamaDataSet.MouseFixationsRow newRow = clickTable.NewMouseFixationsRow(); newRow.PosX = msc.ClickLocation.X; newRow.PosY = msc.ClickLocation.Y; newRow.SubjectName = entry; newRow.TrialID = trialID; newRow.TrialSequence = trialSequence; clickTable.AddMouseFixationsRow(newRow); break; } } } } } } return(clickTable); }
/////////////////////////////////////////////////////////////////////////////// // Eventhandler for Custom Defined Events // /////////////////////////////////////////////////////////////////////////////// #region CUSTOMEVENTHANDLER #endregion //CUSTOMEVENTHANDLER #endregion //EVENTS /////////////////////////////////////////////////////////////////////////////// // Methods and Eventhandling for Background tasks // /////////////////////////////////////////////////////////////////////////////// #region BACKGROUNDWORKER #endregion //BACKGROUNDWORKER /////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// This method does the parsing of the given path and creates for each readable /// image or media file a trial with the defined conditions. /// </summary> /// <returns>A <see cref="List{Slide}"/> to be imported in the slideshow of /// the experiment.</returns> private List <Slide> GetSlides() { var newSlides = new List <Slide>(); var dirInfoStimuli = new DirectoryInfo(this.txbFolder.Text); if (dirInfoStimuli.Exists) { var files = dirInfoStimuli.GetFiles(); Array.Sort(files, new NumericComparer()); foreach (var file in files) { var extension = file.Extension.ToLower(); // Ignore files with unrecognized extensions switch (extension) { case ".bmp": case ".png": case ".jpg": case ".wmf": case ".mp3": case ".wav": case ".wma": break; default: continue; } // Ignore hidden and MAC files if (file.Name.StartsWith(".")) { continue; } var newSlide = new Slide { BackgroundColor = this.clbBackground.CurrentColor, Modified = true, MouseCursorVisible = this.chbShowMouseCursor.Checked, MouseInitialPosition = this.psbMouseCursor.CurrentPosition, Name = Path.GetFileNameWithoutExtension(file.Name), PresentationSize = Document.ActiveDocument.PresentationSize }; StopCondition stop = null; if (this.rdbTime.Checked) { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } else if (this.rdbKey.Checked) { string selectedItemKeys = (string)this.cbbKeys.SelectedItem; KeyStopCondition ksc = new KeyStopCondition(); if (selectedItemKeys == "Any") { ksc.CanBeAnyInputOfThisType = true; } else { ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys); } stop = ksc; } else if (this.rdbMouse.Checked) { string selectedItemMouse = (string)this.cbbMouseButtons.SelectedItem; MouseStopCondition msc = new MouseStopCondition(); msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false; if (!msc.CanBeAnyInputOfThisType) { msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse); } msc.Target = string.Empty; stop = msc; } else if (this.rdbDuration.Checked) { if (extension == ".mp3" || extension == ".wav" || extension == ".wma") { int duration = this.GetAudioFileLength(file.FullName); if (duration != 0) { stop = new TimeStopCondition(duration + (int)this.nudLatency.Value); } else { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } } else { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } } newSlide.StopConditions.Add(stop); foreach (VGElement element in this.lsbStandardItems.Items) { newSlide.VGStimuli.Add(element); } string destination = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, file.Name); switch (extension) { case ".bmp": case ".png": case ".jpg": case ".wmf": if (!File.Exists(destination)) { File.Copy(file.FullName, destination, true); } VGImage image = new VGImage( ShapeDrawAction.None, Pens.Red, Brushes.Red, SystemFonts.MenuFont, Color.Red, file.Name, Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, ImageLayout.Stretch, 1f, Document.ActiveDocument.PresentationSize, VGStyleGroup.None, file.Name, string.Empty, true); newSlide.VGStimuli.Add(image); newSlides.Add(newSlide); break; case ".mp3": case ".wav": case ".wma": File.Copy(file.FullName, destination, true); VGSound sound = new VGSound(ShapeDrawAction.None, Pens.Red, new Rectangle(0, 0, 200, 300)); sound.Center = newSlide.MouseInitialPosition; sound.Size = new SizeF(50, 50); AudioFile audioFile = new AudioFile(); audioFile.Filename = file.Name; audioFile.Filepath = Document.ActiveDocument.ExperimentSettings.SlideResourcesPath; audioFile.Loop = false; audioFile.ShouldPlay = true; audioFile.ShowOnClick = false; sound.Sound = audioFile; newSlide.VGStimuli.Add(sound); newSlides.Add(newSlide); break; } } } return(newSlides); }