Пример #1
0
        /// <summary>
        /// A new trial Form. This constructor is used if an existing block of trial are subject to change.
        /// </summary>
        /// <param name="sessionForm">The sessionForm which invoked this form.</param>
        /// <param name="editNumber">The trial block number that has to be changed.</param>
        public TrialForm(SessionForm sessionForm, int editNumber)
        {
            addTrial        = false;
            this.editNumber = editNumber;
            InitializeComponent();
            this.sessionForm               = sessionForm;
            this.trial                     = sessionForm.Experiment.SessionList.TrialList[editNumber];
            trialNumberFromTextBox.Text    = trial.NumberTrials.ToString();
            groupNameTextBox.Text          = trial.TrialName;
            durationTextBox.Text           = trial.Duration.ToString();
            fixationMarkerCheckBox.Checked = trial.FixationMarker;
            horizontalCheckBox.Checked     = trial.GridDisplayHorizontal;
            verticalCheckBox.Checked       = trial.GridDisplayVertical;
            bouncingCheckBox.Checked       = trial.Bouncing;

            if (trial.Bouncing == true)
            {
                bouncingTextBox.Text = trial.BouncingDistance.ToString();
            }
            startingDistanceTextBox.Text        = trial.StartingDistance.ToString();
            backgroundPictureBox.BackColor      = Color.FromArgb(trial.BackgroundColor);
            foregroundColorPictureBox.BackColor = Color.FromArgb(trial.ForegroundColor);

            this.mObjectList = sessionForm.Experiment.SessionList.TrialList[editNumber].MObjectList;
            maxObjectsNumber = trial.NumberObjects;
            updateObjectList(maxObjectsNumber);
            checkButtonStatus();
        }
Пример #2
0
        /// <summary>
        /// Swaps two trial blocks.
        /// </summary>
        /// <param name="trialPosition1">Trial to be swapped</param>
        /// <param name="trialPosition2">Trial to be swapped</param>
        private void swapTrials(int trialPosition1, int trialPosition2)
        {
            TrialDescriptor temp_trial = experiment.SessionList.TrialList[trialPosition1];

            experiment.SessionList.TrialList[trialPosition1] = experiment.SessionList.TrialList[trialPosition2];
            experiment.SessionList.TrialList[trialPosition2] = temp_trial;
        }
Пример #3
0
        /// <summary>
        /// Generate the Session files in the specified experiment folder.
        /// </summary>
        /// <param name="experiment">The experiment object containing all the experiment data.</param>
        /// <returns>True if the file generation was succesful.</returns>
        public bool generateSessionFiles(ExperimentDescriptor experiment)
        {
            Random randTrial = new Random();
            Random randBlock = new Random();

            Directory.CreateDirectory(experiment.ExperimentFolder);
            Directory.CreateDirectory(experiment.ExperimentFolder + @"\" + ImageSubDir);
            for (int s = 1; s <= experiment.NumberSessionFiles; s++)
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding    = Encoding.GetEncoding("ISO-8859-1");
                settings.Indent      = true;
                settings.IndentChars = ("    ");
                Directory.CreateDirectory(experiment.ExperimentFolder + @"\" + sessionDirPrefix + s);
                //Directory.CreateDirectory(experiment.ExperimentFolder + @"\" + sessionDirPrefix+s+@"\"+ImageSubDir);
                using (XmlWriter writer = XmlWriter.Create(experiment.ExperimentFolder + @"\" + sessionDirPrefix + s + @"\" + experiment.ExperimentName + "_" + sessionDirPrefix + s + ".session", settings))
                {
                    writer.WriteStartElement("experiment");

                    writer.WriteStartElement("session");

                    writer.WriteElementString("expName", experiment.ExperimentName);
                    writer.WriteElementString("sessNum", s.ToString());
                    writer.WriteElementString("displayX", experiment.DisplayX.ToString());
                    writer.WriteElementString("displayY", experiment.DisplayY.ToString());
                    writer.WriteElementString("numTrials", experiment.NumberTrials.ToString());


                    writer.WriteStartElement("trials");

                    List <int> trialBlockRand = new List <int>(experiment.SessionList.TrialList.Count);

                    int trialCount = 0;
                    for (int count = 0; count < experiment.SessionList.TrialList.Count; count++)
                    {
                        int nextTrialNumber = 0;
                        do
                        {
                            nextTrialNumber = randBlock.Next(0, experiment.SessionList.TrialList.Count);
                        } while (trialBlockRand.Contains(nextTrialNumber));
                        trialBlockRand.Add(nextTrialNumber);

                        TrialDescriptor trial = experiment.SessionList.TrialList[nextTrialNumber];
                        for (int i = 0; i < trial.NumberTrials; i++)
                        {
                            writer.WriteStartElement("trial");
                            writer.WriteAttributeString("number", (++trialCount).ToString());

                            writer.WriteStartElement("condition");
                            //writer.WriteElementString("condition", trial.TrialName);
                            int conditionNr      = count;
                            int conditionNrCount = 0;
                            foreach (TrialDescriptor findConditionNumber in experiment.SessionList.TrialList)
                            {
                                conditionNrCount++;
                                if (findConditionNumber.TrialName.Equals(trial.TrialName))
                                {
                                    conditionNr = conditionNrCount;
                                    break;
                                }
                            }
                            writer.WriteAttributeString("number", conditionNr.ToString());
                            writer.WriteString(trial.TrialName);
                            writer.WriteEndElement();

                            if (trial.FixationMarker)
                            {
                                writer.WriteElementString("isFixMarker", "1");
                            }
                            else
                            {
                                writer.WriteElementString("isFixMarker", "0");
                            }

                            int duration_ms = trial.Duration * 1000;
                            writer.WriteElementString("duration", duration_ms.ToString());

                            if (trial.GridDisplayVertical && trial.GridDisplayHorizontal)
                            {
                                writer.WriteElementString("gridDisplay", "3");
                            }
                            else if (trial.GridDisplayVertical && !trial.GridDisplayHorizontal)
                            {
                                writer.WriteElementString("gridDisplay", "2");
                            }
                            else if (!trial.GridDisplayVertical && trial.GridDisplayHorizontal)
                            {
                                writer.WriteElementString("gridDisplay", "1");
                            }
                            else
                            {
                                writer.WriteElementString("gridDisplay", "0");
                            }

                            writer.WriteElementString("bgColorA", Color.FromArgb(trial.BackgroundColor).A.ToString());
                            writer.WriteElementString("bgColorR", Color.FromArgb(trial.BackgroundColor).R.ToString());
                            writer.WriteElementString("bgColorG", Color.FromArgb(trial.BackgroundColor).G.ToString());
                            writer.WriteElementString("bgColorB", Color.FromArgb(trial.BackgroundColor).B.ToString());

                            writer.WriteElementString("fgColorA", Color.FromArgb(trial.ForegroundColor).A.ToString());
                            writer.WriteElementString("fgColorR", Color.FromArgb(trial.ForegroundColor).R.ToString());
                            writer.WriteElementString("fgColorG", Color.FromArgb(trial.ForegroundColor).G.ToString());
                            writer.WriteElementString("fgColorB", Color.FromArgb(trial.ForegroundColor).B.ToString());

                            if (trial.Bouncing)
                            {
                                writer.WriteElementString("isBounce", "1");
                            }
                            else
                            {
                                writer.WriteElementString("isBounce", "0");
                            }

                            if (trial.Bouncing)
                            {
                                writer.WriteElementString("minBounceDist", trial.BouncingDistance.ToString());
                            }
                            else
                            {
                                writer.WriteElementString("minBounceDist", "");
                            }

                            writer.WriteElementString("minStartDist", trial.StartingDistance.ToString());

                            writer.WriteElementString("numObjects", trial.MObjectList.Count.ToString());

                            int numTargets = 0;
                            foreach (MObjectDescriptor mObject in trial.MObjectList)
                            {
                                if (mObject.TargetObject)
                                {
                                    numTargets++;
                                }
                            }
                            writer.WriteElementString("numTargets", numTargets.ToString());

                            writer.WriteStartElement("objects");
                            int objectCount = 0;
                            foreach (MObjectDescriptor mObject in trial.MObjectList)
                            {
                                writer.WriteStartElement("object");
                                writer.WriteAttributeString("number", (++objectCount).ToString());

                                string filename = "";
                                if (mObject.Type.Contains("Rectangle"))
                                {
                                    filename = "rect_" + mObject.Width.ToString() + "x" + mObject.Height.ToString() + "_" + mObject.Color.ToString() + ".bmp";
                                    if (!(File.Exists(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename)))
                                    {
                                        Bitmap objectBMP = createBMP(mObject.Type, mObject.Width, mObject.Height, Color.FromArgb(mObject.Color), Color.FromArgb(trial.BackgroundColor));
                                        objectBMP.Save(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename);
                                    }
                                }
                                else if (mObject.Type.Contains("Circle"))
                                {
                                    filename = "elli_" + mObject.Width.ToString() + "x" + mObject.Height.ToString() + "_" + mObject.Color.ToString() + ".bmp";
                                    if (!(File.Exists(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename)))
                                    {
                                        Bitmap objectBMP = createBMP(mObject.Type, mObject.Width, mObject.Height, Color.FromArgb(mObject.Color), Color.FromArgb(trial.BackgroundColor));
                                        objectBMP.Save(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename);
                                    }
                                }
                                else if (mObject.Type.Contains("File"))
                                {
                                    filename = mObject.Filename.Substring(mObject.Filename.LastIndexOf("\\") + 1);
                                    if (!(File.Exists(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename)))
                                    {
                                        Bitmap objectBMP = new Bitmap(mObject.Filename);
                                        objectBMP.Save(experiment.ExperimentFolder + @"\" + ImageSubDir + @"\" + filename);
                                    }
                                }

                                writer.WriteElementString("objPath", experiment.ExperimentFolder.Replace("\\", "\\\\") + @"\\" + ImageSubDir + @"\\" + filename);

                                if (mObject.TargetObject)
                                {
                                    writer.WriteElementString("objIsTarget", "1");
                                }
                                else
                                {
                                    writer.WriteElementString("objIsTarget", "0");
                                }

                                writer.WriteElementString("objPanel", mObject.StartPanel.ToString());

                                writer.WriteElementString("objMinSpeedH", mObject.MinSpeedHorizontal.ToString());
                                writer.WriteElementString("objMaxSpeedH", mObject.MaxSpeedHorizontal.ToString());
                                writer.WriteElementString("objMinSpeedV", mObject.MinSpeedVertical.ToString());
                                writer.WriteElementString("objMaxSpeedV", mObject.MaxSpeedVertical.ToString());


                                writer.WriteEndElement(); //end object-tag
                            }
                            writer.WriteEndElement();     //end objects-tag


                            writer.WriteEndElement(); //end trial-tag
                        }
                    }


                    writer.WriteEndElement(); //end trials-tag
                    writer.WriteEndElement(); //end session-Tag
                    writer.WriteEndElement(); //end experiment-Tag

                    writer.Flush();
                }
            }
            return(true);
        }