Exemplo n.º 1
0
 /// <summary>
 /// Display a pop-up window which waits for a valid name of the experiment and starts the creation process.
 /// </summary>
 /// <param name="experiment">The experiment dataa</param>
 public NameForm(ExperimentDescriptor experiment)
 {
     InitializeComponent();
     this.experiment = experiment;
     FileGenerator.getInstance().createDefaultDir();
     FileGenerator.getInstance().createSubDirs();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes the experiment object in a file.
        /// </summary>
        /// <param name="experiment">Experiment object to be serialized</param>
        /// <param name="fileName">The file name for the object. </param>
        /// <returns>True when the generation was succesful.</returns>
        public bool saveExperiment(ExperimentDescriptor experiment, string fileName)
        {
            IFormatter formatter = new BinaryFormatter();

            using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                formatter.Serialize(stream, experiment);
            }
            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Displays the open-file dialog and load the experiment data in this file.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void loadToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             actualFilename = openFileDialog.FileName;
             experiment     = FileGenerator.getInstance().loadExperiment(actualFilename);
         }
         updateTrialList();
     }
     catch (Exception ex)
     {
         actualFilename = "";
     }
 }
Exemplo n.º 4
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);
        }