/// <summary>
        /// Overridden <see cref="TypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,object,Type)"/>
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that
        /// provides a format context.</param>
        /// <param name="culture">A <see cref="CultureInfo"/>. If a null reference
        /// is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <param name="destinationType">The <see cref="Type"/> to convert the
        /// <strong>value</strong> parameter to.</param>
        /// <returns>An <strong>Object</strong> that represents the converted value.
        /// In this implementation that is a <see cref="string"/>.</returns>
        public override object ConvertTo(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value,
            Type destinationType)
        {
            if (destinationType == typeof(string) && value is StopCondition)
            {
                StopCondition stopCondition = (StopCondition)value;
                return(stopCondition.ToString());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
 /// <summary>
 /// Removes the first occurrence of a specific
 /// <see cref="StopCondition"/> from the collection. 
 /// </summary>
 /// <param name="stc">The <see cref="StopCondition"/>
 /// to remove from the collection.</param>
 public void Remove(StopCondition stc)
 {
   this.List.Remove(stc);
 }
 /// <summary>
 /// Determines whether the collection contains a specific element.
 /// </summary>
 /// <param name="stc">The Object to locate in the collection.</param>
 /// <returns><strong>True</strong> if the collection
 /// contains the specified value; otherwise, <strong>false</strong>.</returns>
 public bool Contains(StopCondition stc)
 {
   return this.List.Contains(stc);
 }
    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    #region EVENTS

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
    ///////////////////////////////////////////////////////////////////////////////
    #region WINDOWSEVENTHANDLER
    #endregion //WINDOWSEVENTHANDLER

    ///////////////////////////////////////////////////////////////////////////////
    // 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 METHODS

    /// <summary>
    /// Adds an object to the end of the collection.
    /// </summary>
    /// <param name="stc">The <see cref="StopCondition"/> to be 
    /// added to the end of the collection.</param>
    public void Add(StopCondition stc)
    {
      this.List.Add(stc);
    }
Exemple #5
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;
          }
        }
      }
    }
Exemple #6
0
    /// <summary>
    /// This method checks the <see cref="Slide.Links"/> collection,
    ///   if the given response is in it, if so it sets the newTrialID
    ///   ouput parameter, otherwise it will be -1.
    /// </summary>
    /// <param name="slideContainer">
    /// The <see cref="SlidePresentationContainer"/> for which to check the links for.
    /// </param>
    /// <param name="response">
    /// A <see cref="StopCondition"/> with the current response.
    /// </param>
    /// <param name="isLink">
    /// Out. <strong>True</strong> if this response is a link, otherwise <strong>false</strong>.
    /// </param>
    /// <param name="newTrialID">
    /// Out. An <see cref="Int32"/> with the new trial ID to link to.
    /// </param>
    private void CheckLinks(
      SlidePresentationContainer slideContainer,
      StopCondition response,
      out bool isLink,
      out int newTrialID)
    {
      isLink = false;
      newTrialID = -1;
      foreach (StopCondition condition in slideContainer.Slide.Links)
      {
        if (condition is MouseStopCondition && response is MouseStopCondition)
        {
          var linkMsc = (MouseStopCondition)condition;
          var responseMsc = (MouseStopCondition)response;
          if (linkMsc.StopMouseButton == responseMsc.StopMouseButton && linkMsc.Target == responseMsc.Target)
          {
            if (linkMsc.TrialID != null)
            {
              newTrialID = linkMsc.TrialID.Value;
            }

            isLink = true;
            break;
          }
        }
        else if (condition is KeyStopCondition && response is KeyStopCondition)
        {
          var linkKsc = (KeyStopCondition)condition;
          var responseKsc = (KeyStopCondition)response;
          if (linkKsc.StopKey == responseKsc.StopKey)
          {
            if (linkKsc.TrialID != null)
            {
              newTrialID = linkKsc.TrialID.Value;
            }

            isLink = true;
            break;
          }
        }
      }
    }
        /// <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));
        }
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the SlideChangedEventArgs class.
    /// </summary>
    /// <param name="newNextSlide">A <see cref="Slide"/> The <see cref="Slide"/> that is the new slide to show.</param>
    /// <param name="newResponse">The response of type <see cref="StopCondition"/>
    /// that ended the trial.</param>
    /// <param name="newSlideCounter">The index of the current visible slide
    /// in the current trial.</param>
    public SlideChangedEventArgs(Slide newNextSlide, StopCondition newResponse, int newSlideCounter)
    {
      this.nextSlide = newNextSlide;
      this.response = newResponse;
      this.slideCounter = newSlideCounter;
    }
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the TrialChangedEventArgs class.
    /// </summary>
    /// <param name="newFinishedTrial">Finished trial.</param>
    /// <param name="newNextTrial">Next trial.</param>
    /// <param name="newResponse">The response of type <see cref="StopCondition"/>
    /// that ended the trial.</param>
    /// <param name="newCategory">A <see cref="string"/> with the
    /// slides category.</param>
    /// <param name="newTrialCounter">The index of the current visible trial
    /// in the current trial list.</param>
    /// <param name="newWebcamTime">The time in milliseconds of the begin of the 
    /// webcams video section.</param>
    public TrialChangedEventArgs(
      Trial newFinishedTrial,
      Trial newNextTrial,
      StopCondition newResponse,
      string newCategory,
      int newTrialCounter,
      long newWebcamTime)
    {
      this.finishedTrial = newFinishedTrial;
      this.nextTrial = newNextTrial;
      this.response = newResponse;
      this.category = newCategory;
      this.trialCounter = newTrialCounter;
      this.webcamTime = newWebcamTime;
    }
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the ResponseChangedEventArgs class.
    /// </summary>
    /// <param name="newResponse">The response of type <see cref="StopCondition"/></param>
    public ResponseChangedEventArgs(StopCondition newResponse)
    {
      this.response = newResponse;
    }
Exemple #11
0
    /// <summary>
    /// Returns the name and group of the AOI that was under the mouse
    /// cursor when the trial was finished.
    /// Only valid, when the response was a mouse response
    /// </summary>
    /// <param name="trialRow">Trial table row for current subject.</param>
    /// <param name="response">The response <see cref="StopCondition"/>.</param>
    /// <returns>The AOI name and group that was clicked.
    /// <strong>-1</strong> if response was not a mouse response.
    /// <strong>-2</strong> if no AOI were defined
    /// <strong>-3</strong> if no AOI was hit</returns>
    private static string GetResponsesAOI(DataRowView trialRow, StopCondition response)
    {
      string subjectName = trialRow["SubjectName"].ToString();
      int trialID = (int)trialRow["TrialID"];
      int trialSequence = (int)trialRow["TrialSequence"];

      if (!(response is MouseStopCondition))
      {
        return "-1"; // Response was not a mouse response.
      }

      // Get AOIData
      DataTable aoiTable
        = Document.ActiveDocument.DocDataSet.AOIsAdapter.GetDataByTrialID(trialID);

      if (aoiTable.Rows.Count == 0)
      {
        return "-2"; // No AOI defined
      }

      Point clickLocation = ((MouseStopCondition)response).ClickLocation;

      string aoiGroup = string.Empty;
      string aoiName = string.Empty;
      foreach (DataRow aoiRow in aoiTable.Rows)
      {
        string strPtList = Convert.ToString(aoiRow["ShapePts"]);
        string aoiType = Convert.ToString(aoiRow["ShapeType"]);
        string name = aoiRow["ShapeName"].ToString();
        string shapeGroup = aoiRow["ShapeGroup"].ToString();

        VGElement aoiElement = Queries.GetVGElementFromDatabase(aoiType, name, shapeGroup, strPtList);

        if (aoiElement.Contains(clickLocation, tolerance))
        {
          string group = aoiRow["ShapeGroup"].ToString();
          if (group != "SearchRect")
          {
            aoiGroup = group;
            aoiName = name;
            break;
          }
        }
      }

      aoiTable.Dispose();

      // no AOI hitted.
      string aoi = "-3";

      if ((aoiName != string.Empty && aoiName != " ")
        || (aoiGroup != string.Empty && aoiGroup != " "))
      {
        aoi = aoiName + "(Group: " + aoiGroup + ")";
      }

      return aoi;
    }
Exemple #12
0
 /// <summary>
 /// Removes the first occurrence of a specific
 /// <see cref="StopCondition"/> from the collection.
 /// </summary>
 /// <param name="stc">The <see cref="StopCondition"/>
 /// to remove from the collection.</param>
 public void Remove(StopCondition stc)
 {
     this.List.Remove(stc);
 }
Exemple #13
0
 /// <summary>
 /// Determines whether the collection contains a specific element.
 /// </summary>
 /// <param name="stc">The Object to locate in the collection.</param>
 /// <returns><strong>True</strong> if the collection
 /// contains the specified value; otherwise, <strong>false</strong>.</returns>
 public bool Contains(StopCondition stc)
 {
     return(this.List.Contains(stc));
 }
Exemple #14
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region WINDOWSEVENTHANDLER
        #endregion //WINDOWSEVENTHANDLER

        ///////////////////////////////////////////////////////////////////////////////
        // 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 METHODS

        /// <summary>
        /// Adds an object to the end of the collection.
        /// </summary>
        /// <param name="stc">The <see cref="StopCondition"/> to be
        /// added to the end of the collection.</param>
        public void Add(StopCondition stc)
        {
            this.List.Add(stc);
        }