Example #1
0
        /// <summary>
        /// Determines whether two <see cref="KeyStopCondition"/> instances are equal.
        /// </summary>
        /// <param name="obj">The <see cref="Object"/> to compare with the current
        /// <see cref="KeyStopCondition"/>.</param>
        /// <returns><strong>True</strong> if the specified Object is equal
        /// to the current <see cref="KeyStopCondition"/>; otherwise, <strong>false</strong>. </returns>
        public override bool Equals(object obj)
        {
            if (obj is KeyStopCondition)
            {
                KeyStopCondition ksc = (KeyStopCondition)obj;
                if (ksc.stopKey == this.StopKey &&
                    ksc.CanBeAnyInputOfThisType == this.CanBeAnyInputOfThisType)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Small helping Methods                                                     //
        ///////////////////////////////////////////////////////////////////////////////
        #region HELPER

        /// <summary>
        /// Reads the StopConditionCollection and converts them into a stop condition string.
        /// </summary>
        /// <returns>A <see cref="string"/> with the stop condition.</returns>
        private string GenerateStopConditionString()
        {
            string stopConditionDescription = string.Empty;

            if (this.Count == 1)
            {
                if (this.List[0] is TimeStopCondition)
                {
                    TimeStopCondition tsc            = (TimeStopCondition)this.List[0];
                    float             duration       = (float)(tsc.Duration / 1000f);
                    string            durationString = duration.ToString("N3");
                    stopConditionDescription = "Show for " + durationString + " seconds";
                }
                else if (this.List[0] is MouseStopCondition)
                {
                    MouseStopCondition msc = (MouseStopCondition)this.List[0];
                    StringBuilder      sb  = new StringBuilder();
                    stopConditionDescription = "Show until user pressed " +
                                               msc.ToString() + ".";
                }
                else if (this.List[0] is KeyStopCondition)
                {
                    KeyStopCondition ksc = (KeyStopCondition)this.List[0];
                    stopConditionDescription = "Show until user hits " +
                                               ksc.ToString() + ".";
                }
            }
            else if (this.Count == 0)
            {
                stopConditionDescription = "No stop condition !";
            }
            else
            {
                stopConditionDescription = "Multiple stop conditions";
            }

            return(stopConditionDescription);
        }
Example #3
0
    /// <summary>
    /// Overridden <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,object)"/>
    /// Converts the given value to the type of this converter.</summary>
    /// <param name="context">An <see cref="ITypeDescriptorContext"/> that 
    /// provides a format context.</param>
    /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
    /// <param name="value">The <see cref="Object"/> to convert.</param>
    /// <returns>An <strong>Object</strong> that represents the converted value.
    /// In this implementation that can be any <see cref="StopCondition"/></returns>
    public override object ConvertFrom(
      ITypeDescriptorContext context,
      CultureInfo culture,
      object value)
    {
      if (value is string)
      {
        try
        {
          if (value.ToString() == string.Empty)
          {
            return null;
          }

          // Old Ogama V1.1 versions supplied "None" for the Response when there was no response
          // Convert them to null.
          if (value.ToString() == "None")
          {
            return null;
          }

          // Old Ogama V1.1 versions supplied "Left" for a left mouse response
          if (value.ToString() == "Left")
          {
            return new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, Point.Empty);
          }

          // Old Ogama V1.1 versions supplied "Right" for a right mouse response
          if (value.ToString() == "Right")
          {
            return new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, Point.Empty);
          }

          string s = (string)value;
          int colon = s.IndexOf(':');
          int point = s.IndexOf('.');
          int target = s.IndexOf("target");
          int parenthesisOpen = s.IndexOf('(');
          int parenthesisClose = s.IndexOf(')');

          if (colon != -1)
          {
            StopCondition stopCondition = null;

            string type = s.Substring(0, colon).Trim();
            if (type == "Time")
            {
              string duration = s.Substring(colon + 1, s.Length - colon - 3).Trim();
              stopCondition = new TimeStopCondition(Convert.ToInt32(duration));
            }
            else if (type == "Key")
            {
              string key = s.Substring(colon + 1, point > -1 ? point - colon - 1 : s.Length - colon - 1).Trim();
              if (key == "any key")
              {
                stopCondition = new KeyStopCondition(Keys.None, false, null);
              }
              else
              {
                stopCondition = new KeyStopCondition((Keys)Enum.Parse(typeof(Keys), key), false, null);
              }
            }
            else if (type.Contains("Mouse"))
            {
              string button = MouseButtons.None.ToString();
              Point location = Point.Empty;

              // Older versions (Ogama 1.X) did not write the location in parenthesises.
              if (parenthesisOpen == -1)
              {
                button = s.Substring(colon + 1).Trim();
                int space = button.IndexOf(" ");
                if (space != -1)
                {
                  button = button.Substring(0, space);
                }

                // Do not set location because it is not known
              }
              else
              {
                button = s.Substring(colon + 1, parenthesisOpen - colon - 1).Trim();
                location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
              }

              stopCondition = new MouseStopCondition(
                (MouseButtons)Enum.Parse(typeof(MouseButtons), button), false, string.Empty, null, location);

              if (button == "any mouse button")
              {
                ((MouseStopCondition)stopCondition).CanBeAnyInputOfThisType = true;
              }

              if (target != -1)
              {
                int colon2 = button.IndexOf(':');
                if (colon2 != -1)
                {
                  string targetName = button.Substring(colon2).Trim();
                  ((MouseStopCondition)stopCondition).Target = targetName;
                }
                else
                {
                  ((MouseStopCondition)stopCondition).Target = "Any";
                }
              }
            }
            else if (type == "http")
            {
              stopCondition = new NavigatedStopCondition(new Uri(s));
            }

            // Parse correct answer.
            if (s.Contains("."))
            {
              if (s.Contains("Correct"))
              {
                stopCondition.IsCorrectResponse = true;
              }
              else
              {
                stopCondition.IsCorrectResponse = false;
              }
            }

            // Parse trial ID of links.
            if (s.Contains("-"))
            {
              int sharp = s.IndexOf('#');
              if (sharp != -1)
              {
                string trialIDString = s.Substring(sharp).Trim();
                int trialID = 0;
                if (int.TryParse(trialIDString, out trialID))
                {
                  ((InputStopCondition)stopCondition).TrialID = trialID;
                }
              }
            }

            return stopCondition;
          }
          else if (value.ToString().Contains("Left"))
          {
            Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
            MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, location);
            return stopCondition;
          }
          else if (value.ToString().Contains("Right"))
          {
            Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
            MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, location);
            return stopCondition;
          }
        }
        catch
        {
          throw new ArgumentException(
              " '" + (string)value + "' could not be converted to StopCondition type.");
        }
      }

      return base.ConvertFrom(context, culture, value);
    }
Example #4
0
    /// <summary>
    /// This method steps through each of the stop conditions of the current slide.
    ///   If any of them matches the current state, check for
    ///   response correctness and set bChangeStimulus=true;
    /// </summary>
    /// <param name="slideContainer">
    /// The <see cref="SlidePresentationContainer"/> for which the slide should be parsed.
    /// </param>
    /// <param name="changeSlide">
    /// Out. <strong>True</strong> if new slide should be shown.
    /// </param>
    /// <param name="response">
    /// Out. The <see cref="StopCondition"/> that ended the slide.
    /// </param>
    private void CheckResponses(
      SlidePresentationContainer slideContainer,
      out bool changeSlide,
      out StopCondition response)
    {
      changeSlide = false;
      response = null;

      foreach (StopCondition condition in slideContainer.Slide.StopConditions)
      {
        if (condition is MouseStopCondition)
        {
          var msc = (MouseStopCondition)condition;
          if ((msc.CanBeAnyInputOfThisType && this.currentMousebutton != MouseButtons.None)
              || (this.currentMousebutton == msc.StopMouseButton))
          {
            foreach (VGElement shape in slideContainer.Slide.TargetShapes)
            {
              if (shape.Contains(this.PointToClient(MousePosition)))
              {
                response = new MouseStopCondition(msc.StopMouseButton, false, shape.Name, null, MousePosition);
                if (msc.Target != string.Empty && (shape.Name == msc.Target || msc.Target == "Any"))
                {
                  changeSlide = true;
                }

                break;
              }
            }

            if (msc.Target == string.Empty)
            {
              changeSlide = true;
              if (response == null)
              {
                response = new MouseStopCondition(msc.StopMouseButton, false, string.Empty, null, MousePosition);
              }
            }

            if (changeSlide)
            {
              // Check testing condition if specified.
              foreach (StopCondition correctCondition in slideContainer.Slide.CorrectResponses)
              {
                if (msc.Equals(correctCondition))
                {
                  response.IsCorrectResponse = true;
                  break;
                }

                response.IsCorrectResponse = false;
              }

              this.currentMousebutton = MouseButtons.None;
            }
          }
        }
        else if (condition is KeyStopCondition)
        {
          var ksc = (KeyStopCondition)condition;
          if ((ksc.CanBeAnyInputOfThisType && this.currentKey != Keys.None) || (this.currentKey == ksc.StopKey))
          {
            changeSlide = true;
            response = new KeyStopCondition(ksc.StopKey, false, null);

            // Check testing condition if specified.
            if (slideContainer.Slide.CorrectResponses != null)
            {
              // Check testing condition if specified.
              foreach (StopCondition correctCondition in slideContainer.Slide.CorrectResponses)
              {
                if (ksc.Equals(correctCondition))
                {
                  response.IsCorrectResponse = true;
                  break;
                }

                response.IsCorrectResponse = false;
              }
            }

            this.currentKey = Keys.None;
            break;
          }
        }
      }
    }
Example #5
0
    /// <summary>
    /// Overridden <see cref="ProcessCmdKey(ref Message,Keys)"/> method.
    ///   Captures all pressed keys including
    ///   Alt, Ctrl, Space, Esc that are normally not raised as KeyDown in a form.
    /// </summary>
    /// <param name="msg">
    /// This parameter contains the Windows Message, such as WM_KEYDOWN
    /// </param>
    /// <param name="keyData">
    /// The keyData parameter contains the key code of the key that was pressed. If CTRL or ALT was also
    ///   pressed, the keyData parameter contains the ModifierKey information.
    /// </param>
    /// <returns>
    /// True if Key should be processed ?
    /// </returns>
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
      const int WM_KEYDOWN = 0x100;
      const int WM_SYSKEYDOWN = 0x104;

      if (((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN)) && (!this.closing))
      {
        long eventTime = -1;
        if (this.getTimeMethod != null)
        {
          eventTime = this.getTimeMethod();
        }

        if (this.watch.ElapsedMilliseconds > MINIMUMKEYPRESSINTERVALLMS)
        {
          // Check for markers
          if (keyData == Keys.F12)
          {
            // Store marker event
            var keyEvent = new MediaEvent { Type = EventType.Marker, Task = MediaEventTask.None, Param = string.Empty };
            this.OnTrialEventOccured(new TrialEventOccuredEventArgs(keyEvent, eventTime));
          }
          else
          {
            this.currentKey = keyData;

            if (!this.CheckforSlideChange(false))
            {
              // Store key event only when slide has not changed
              // otherwise the event will be stored during
              // trialchanged event.
              var keyEvent = new InputEvent { Type = EventType.Key, Task = InputEventTask.Down };
              var ksc = new KeyStopCondition(keyData, false, null);
              keyEvent.Param = ksc.ToString();
              this.OnTrialEventOccured(new TrialEventOccuredEventArgs(keyEvent, eventTime));
            }

            this.watch.Reset();
            this.watch.Start();
          }
        }
      }

      return base.ProcessCmdKey(ref msg, keyData);
    }
Example #6
0
    /// <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.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);
        }
      }
    }
Example #7
0
    /// <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);
          }
        }
      }
    }
Example #8
0
    /// <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>
        /// Overridden <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,object)"/>
        /// Converts the given value to the type of this converter.</summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that
        /// provides a format context.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <strong>Object</strong> that represents the converted value.
        /// In this implementation that can be any <see cref="StopCondition"/></returns>
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            if (value is string)
            {
                try
                {
                    if (value.ToString() == string.Empty)
                    {
                        return(null);
                    }

                    // Old Ogama V1.1 versions supplied "None" for the Response when there was no response
                    // Convert them to null.
                    if (value.ToString() == "None")
                    {
                        return(null);
                    }

                    // Old Ogama V1.1 versions supplied "Left" for a left mouse response
                    if (value.ToString() == "Left")
                    {
                        return(new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, Point.Empty));
                    }

                    // Old Ogama V1.1 versions supplied "Right" for a right mouse response
                    if (value.ToString() == "Right")
                    {
                        return(new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, Point.Empty));
                    }

                    string s                = (string)value;
                    int    colon            = s.IndexOf(':');
                    int    point            = s.IndexOf('.');
                    int    target           = s.IndexOf("target");
                    int    parenthesisOpen  = s.IndexOf('(');
                    int    parenthesisClose = s.IndexOf(')');

                    if (colon != -1)
                    {
                        StopCondition stopCondition = null;

                        string type = s.Substring(0, colon).Trim();
                        if (type == "Time")
                        {
                            string duration = s.Substring(colon + 1, s.Length - colon - 3).Trim();
                            stopCondition = new TimeStopCondition(Convert.ToInt32(duration));
                        }
                        else if (type == "Key")
                        {
                            string key = s.Substring(colon + 1, point > -1 ? point - colon - 1 : s.Length - colon - 1).Trim();
                            if (key == "any key")
                            {
                                stopCondition = new KeyStopCondition(Keys.None, false, null);
                            }
                            else
                            {
                                stopCondition = new KeyStopCondition((Keys)Enum.Parse(typeof(Keys), key), false, null);
                            }
                        }
                        else if (type.Contains("Mouse"))
                        {
                            string button   = MouseButtons.None.ToString();
                            Point  location = Point.Empty;

                            // Older versions (Ogama 1.X) did not write the location in parenthesises.
                            if (parenthesisOpen == -1)
                            {
                                button = s.Substring(colon + 1).Trim();
                                int space = button.IndexOf(" ");
                                if (space != -1)
                                {
                                    button = button.Substring(0, space);
                                }

                                // Do not set location because it is not known
                            }
                            else
                            {
                                button   = s.Substring(colon + 1, parenthesisOpen - colon - 1).Trim();
                                location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                            }

                            stopCondition = new MouseStopCondition(
                                (MouseButtons)Enum.Parse(typeof(MouseButtons), button), false, string.Empty, null, location);

                            if (button == "any mouse button")
                            {
                                ((MouseStopCondition)stopCondition).CanBeAnyInputOfThisType = true;
                            }

                            if (target != -1)
                            {
                                int colon2 = button.IndexOf(':');
                                if (colon2 != -1)
                                {
                                    string targetName = button.Substring(colon2).Trim();
                                    ((MouseStopCondition)stopCondition).Target = targetName;
                                }
                                else
                                {
                                    ((MouseStopCondition)stopCondition).Target = "Any";
                                }
                            }
                        }
                        else if (type == "http")
                        {
                            stopCondition = new NavigatedStopCondition(new Uri(s));
                        }

                        // Parse correct answer.
                        if (s.Contains("."))
                        {
                            if (s.Contains("Correct"))
                            {
                                stopCondition.IsCorrectResponse = true;
                            }
                            else
                            {
                                stopCondition.IsCorrectResponse = false;
                            }
                        }

                        // Parse trial ID of links.
                        if (s.Contains("-"))
                        {
                            int sharp = s.IndexOf('#');
                            if (sharp != -1)
                            {
                                string trialIDString = s.Substring(sharp).Trim();
                                int    trialID       = 0;
                                if (int.TryParse(trialIDString, out trialID))
                                {
                                    ((InputStopCondition)stopCondition).TrialID = trialID;
                                }
                            }
                        }

                        return(stopCondition);
                    }
                    else if (value.ToString().Contains("Left"))
                    {
                        Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                        MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, location);
                        return(stopCondition);
                    }
                    else if (value.ToString().Contains("Right"))
                    {
                        Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                        MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, location);
                        return(stopCondition);
                    }
                }
                catch
                {
                    throw new ArgumentException(
                              " '" + (string)value + "' could not be converted to StopCondition type.");
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
    ///////////////////////////////////////////////////////////////////////////////
    // 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;
    }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the KeyStopCondition class.
 /// Clone Constructor.
 /// </summary>
 /// <param name="cloneCondition">The <see cref="KeyStopCondition"/>
 /// to be cloned.</param>
 public KeyStopCondition(KeyStopCondition cloneCondition)
   : base(cloneCondition)
 {
   this.stopKey = cloneCondition.StopKey;
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the KeyStopCondition class.
 /// Clone Constructor.
 /// </summary>
 /// <param name="cloneCondition">The <see cref="KeyStopCondition"/>
 /// to be cloned.</param>
 public KeyStopCondition(KeyStopCondition cloneCondition)
     : base(cloneCondition)
 {
     this.stopKey = cloneCondition.StopKey;
 }