コード例 #1
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.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);
        }
      }
    }
コード例 #2
0
ファイル: TimeStopCondition.cs プロジェクト: zhjh-stack/ogama
        /// <summary>
        /// Determines whether two <see cref="TimeStopCondition"/> instances are equal.
        /// </summary>
        /// <param name="obj">The <see cref="Object"/> to compare with the current
        /// <see cref="TimeStopCondition"/>.</param>
        /// <returns><strong>True</strong> if the specified Object is equal
        /// to the current <see cref="TimeStopCondition"/>; otherwise, <strong>false</strong>. </returns>
        public override bool Equals(object obj)
        {
            if (obj is TimeStopCondition)
            {
                TimeStopCondition tsc = (TimeStopCondition)obj;
                if (tsc.Duration == this.Duration)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
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);
        }
コード例 #4
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);
    }
コード例 #5
0
ファイル: PresenterModule.cs プロジェクト: DeSciL/Ogama
    /// <summary>
    ///   This method creates the initialization trial.
    /// </summary>
    private void InitializeFirstTrial()
    {
      var coll = new StopConditionCollection();
      var stc = new TimeStopCondition(5000);
      coll.Add(stc);

      this.preparedSlideOne.Slide = new Slide(
        "OgamaDummyStartTrial6gsj2",
        Color.Gray,
        Images.CreateRecordInstructionImage(
          Document.ActiveDocument.ExperimentSettings.WidthStimulusScreen,
          Document.ActiveDocument.ExperimentSettings.HeightStimulusScreen),
        coll,
        new StopConditionCollection(),
        string.Empty,
        Document.ActiveDocument.PresentationSize);
      var wait = new VGText(
        ShapeDrawAction.None,
        "Initializing ...",
        new Font("Verdana", 40f),
        Color.WhiteSmoke,
        HorizontalAlignment.Center,
        1,
        6,
        Pens.Red,
        Brushes.Red,
        SystemFonts.MenuFont,
        Color.Black,
        new RectangleF(100, 100, 400, 200),
        VGStyleGroup.None,
        "Text",
        string.Empty,
        null);
      this.preparedSlideOne.Slide.VGStimuli.Add(wait);

      // Reset the cursor position to initial location if applicable
      var newPoint = new Point(
        this.presentationBounds.Left + this.presentationBounds.Width / 2,
        this.presentationBounds.Top + this.presentationBounds.Height / 2);
      Cursor.Position = newPoint;

      Cursor.Hide();
      this.hiddenCursor = true;

      // Prepare preparation slide 
      this.preparedSlideOne.Trial = new Trial("DummyTrial", -1);
      this.preparedSlideOne.Trial.Add(this.preparedSlideOne.Slide);
      this.preparedSlideOne.Timer.Period = 2000;
      this.preparedSlideOne.Timer.Mode = TimerMode.OneShot;
      this.preparedSlideOne.Timer.SynchronizingObject = this;
      this.preparedSlideOne.Timer.Tick += this.TimerTick;

      this.DrawToBuffer(this.preparedSlideOne);
      this.PresentPreparedSlide();

      // Prepare first slide of trial list
      this.preparedSlideTwo.Trial = this.trials[0];
      this.preparedSlideTwo.Slide = this.trials[0][0];
      this.preparedSlideTwo.Timer.Period = 200;
      this.preparedSlideTwo.Timer.Mode = TimerMode.OneShot;
      this.preparedSlideTwo.Timer.SynchronizingObject = this;
      this.preparedSlideTwo.Timer.Tick += this.TimerTick;
      this.InitializeNextSlide(this.preparedSlideTwo);
      this.DrawToBuffer(this.preparedSlideTwo);
      this.PrepareScreenCapture(-1);
    }
コード例 #6
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));
        }
コード例 #7
0
    ///////////////////////////////////////////////////////////////////////////////
    // 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;
    }