コード例 #1
0
ファイル: ImportFixations.cs プロジェクト: DeSciL/Ogama
 /// <summary>
 ///   Initializes static members of the ImportFixations class.
 /// </summary>
 static ImportFixations()
 {
   SubjectList = new List<SubjectsData>();
   TrialList = new List<TrialsData>();
   FixationDataList = new List<FixationData>();
   detectionSetting = new DetectionSettings();
   asciiSetting = new ASCIISettings();
 }
コード例 #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Construction and Initializing methods                                     //
        ///////////////////////////////////////////////////////////////////////////////

        #region CONSTRUCTION

        /// <summary>
        /// Initializes a new instance of the ImportImagesDialog class.
        /// </summary>
        /// <param name="newAsciiSettings">Ref. The <see cref="ASCIISettings"/> to use.</param>
        /// <param name="newDetectionSettings">Ref. The <see cref="DetectionSettings"/> to use.</param>
        public ImportImagesDialog(ref ASCIISettings newAsciiSettings, ref DetectionSettings newDetectionSettings)
        {
            this.InitializeComponent();
            this.numberOfImportLines    = 20000;
            this.detectionSetting       = newDetectionSettings;
            this.asciiSetting           = newAsciiSettings;
            this.imagesImportRows       = new List <string[]>();
            this.imagefileColumnHeaders = new List <string>();
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////////////
        // Construction and Initializing methods                                     //
        ///////////////////////////////////////////////////////////////////////////////
        #region CONSTRUCTION

        /// <summary>
        /// Initializes a new instance of the ImportTrialsDialog class.
        /// </summary>
        /// <param name="newAsciiSettings">Ref. The <see cref="ASCIISettings"/> to use.</param>
        /// <param name="newDetectionSettings">Ref. The <see cref="DetectionSettings"/> to use.</param>
        public ImportTrialsDialog(ref ASCIISettings newAsciiSettings, ref DetectionSettings newDetectionSettings)
        {
            this.InitializeComponent();
            this.numberOfImportLines       = 20000;
            this.detectionSetting          = newDetectionSettings;
            this.asciiSetting              = newAsciiSettings;
            this.trialImportRows           = new List <string[]>();
            this.trialColumnHeaders        = new List <string>();
            this.cbbTimeUnit.SelectedIndex = 1;
        }
コード例 #4
0
ファイル: ImportFixations.cs プロジェクト: DeSciL/Ogama
    /// <summary>
    /// Reads an OGAMA import settings file.
    /// </summary>
    /// <param name="filePath">
    /// A <see cref="string"/> with the path to the
    ///   OGAMA import settings xml file.
    /// </param>
    private static void DeserializeSettings(string filePath)
    {
      try
      {
        using (var fs = new FileStream(filePath, FileMode.Open))
        {
          // Create an instance of the XmlSerializer class;
          // specify the type of object to be deserialized 
          var serializer = new XmlSerializer(typeof(MergedSettings));

          /* Use the Deserialize method to restore the object's state with
          data from the XML document. */
          var settings = (MergedSettings)serializer.Deserialize(fs);

          asciiSetting = settings.AsciiSetting;
          detectionSetting = settings.DetectionSetting;
        }
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);
      }
    }
コード例 #5
0
ファイル: ImportFixations.cs プロジェクト: DeSciL/Ogama
    /// <summary>
    ///   Starts a multiple dialog routine (fixations import assistant)
    ///   for reading fixation log files into OGAMAs database.
    /// </summary>
    public static void Start()//(MainForm mainWindow)
    {
      try
      {
        asciiSetting = new ASCIISettings();
        detectionSetting = new DetectionSettings();

        var objfrmImportAssistent = new ImportFixationsAssistentDialog();
        if (objfrmImportAssistent.ShowDialog() == DialogResult.OK)
        {
        OpenFile:
          if (asciiSetting.FileDialog.ShowDialog() == DialogResult.OK)
          {
            // Save filename
            string filename = asciiSetting.FileDialog.FileName;

            // Ask the user to use a settings file
            // and loads it into the importsettings, if true.
            AskforUsingSettingsFile();

            // Save import file
            asciiSetting.Filename = filename;

            // Set import mode
            detectionSetting.ImportType = ImportTypes.Fixations;

            var objfrmImportReadFile = new ImportParseFileDialog(ref asciiSetting);
          ReadFile:
            DialogResult resultRawData = objfrmImportReadFile.ShowDialog();
            if (resultRawData == DialogResult.OK)
            {
              var objfrmImportFixationsAssignColumns = new ImportFixationsAssignColumnsDialog();

            MakeAssignments:
              DialogResult resultAssign = objfrmImportFixationsAssignColumns.ShowDialog();
              if (resultAssign == DialogResult.OK)
              {
                var objfrmImportTrials = new ImportTrialsDialog(ref asciiSetting, ref detectionSetting);

                //CheckTrials:
                DialogResult resultTrials = objfrmImportTrials.ShowDialog();
                if (resultTrials == DialogResult.OK)
                {
                  //var objfrmImportImages = new ImportImagesDialog(ref asciiSetting, ref detectionSetting);

                  //DialogResult resultImages = objfrmImportImages.ShowDialog();
                  //if (resultImages == DialogResult.OK)
                  //{
                  if (InformationDialog.Show(
                    "Save ?",
                    "Would you like to save the import settings ?",
                    true,
                    MessageBoxIcon.Question) == DialogResult.Yes)
                  {
                    SaveImportSettings();
                  }

                  // Inform user about deletion.
                  string cleanupMessage = "If you continue the import process, " + Environment.NewLine + "all existing "
                                   + "gaze fixation data is deleted before the imported fixations "
                                   + "are written to the database.";
                  if (MessageBox.Show(
                    cleanupMessage,
                    Application.ProductName,
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information) == DialogResult.Cancel)
                  {
                    return;
                  }

                  // Show import splash window
                  asciiSetting.WaitingSplash.RunWorkerAsync();

                  // Give some time to show the splash ...
                  Application.DoEvents();

                  // Read log file again, but complete
                  if (!GenerateOgamaFixationDataList(-1))
                  {
                    asciiSetting.WaitingSplash.CancelAsync();
                    return;
                  }

                  // Generate the trials
                  GenerateOgamaSubjectAndTrialList();

                  // Save the import into ogamas database and the mdf file.
                  var successful = SaveImportIntoTablesAndDB();

                  //// Create slideshow trials
                  //ImportRawData.GenerateOgamaSlideshowTrials(detectionSetting, mainWindow);

                  // Import has finished.
                  asciiSetting.WaitingSplash.CancelAsync();

                  // Inform user about success.
                  if (successful)
                  {
                    string message = "Fixation data successfully written to database.";// + Environment.NewLine +
                    //"Please don´t forget to move the stimuli images to the SlideResources subfolder" +
                    //"of the experiment, otherwise no images will be shown.";
                    ExceptionMethods.ProcessMessage("Success", message);
                  }
                  else
                  {
                    string message = "Import had errors. Some or all of the import data " +
                      "could not be written the database.";
                    ExceptionMethods.ProcessErrorMessage(message);
                  }
                  //}
                  //else if (resultImages == DialogResult.Cancel)
                  //{
                  //  goto CheckTrials;
                  //}
                }
                else if (resultTrials == DialogResult.Cancel)
                {
                  goto MakeAssignments;
                }
                else if (resultTrials == DialogResult.Abort)
                {

                }
              }
              else if (resultAssign == DialogResult.Cancel)
              {
                goto ReadFile;
              }
            }
            else if (resultRawData == DialogResult.Cancel)
            {
              goto OpenFile;
            }
          }
        }
      }
      catch (Exception ex)
      {
        string message = "Something failed during import." + Environment.NewLine
                         + "Please try again with other settings." + Environment.NewLine + "Error: " + ex.Message;
        ExceptionMethods.ProcessErrorMessage(message);

        if (asciiSetting.WaitingSplash.IsBusy)
        {
          asciiSetting.WaitingSplash.CancelAsync();
        }
      }
    }
コード例 #6
0
ファイル: ImportImagesDialog.cs プロジェクト: DeSciL/Ogama
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////

    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the ImportImagesDialog class.
    /// </summary>
    /// <param name="newAsciiSettings">Ref. The <see cref="ASCIISettings"/> to use.</param>
    /// <param name="newDetectionSettings">Ref. The <see cref="DetectionSettings"/> to use.</param>
    public ImportImagesDialog(ref ASCIISettings newAsciiSettings, ref DetectionSettings newDetectionSettings)
    {
      this.InitializeComponent();
      this.numberOfImportLines = 20000;
      this.detectionSetting = newDetectionSettings;
      this.asciiSetting = newAsciiSettings;
      this.imagesImportRows = new List<string[]>();
      this.imagefileColumnHeaders = new List<string>();
    }
コード例 #7
0
ファイル: ImportRawData.cs プロジェクト: DeSciL/Ogama
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region Constructors and Destructors

    /// <summary>
    ///   Initializes static members of the ImportRawData class.
    /// </summary>
    static ImportRawData()
    {
      SubjectList = new List<SubjectsData>();
      TrialList = new List<TrialsData>();
      RawDataList = new List<RawData>();

      detectionSetting = new DetectionSettings();
      asciiSetting = new ASCIISettings();
    }
コード例 #8
0
ファイル: ImportRawData.cs プロジェクト: DeSciL/Ogama
    /// <summary>
    /// This static method creates a slide with a sized image
    ///   for each trial and adds it to the slideshow.
    /// </summary>
    /// <param name="detectonSettings">
    /// The <see cref="DetectionSettings"/>
    ///   used in this import.
    /// </param>
    /// <param name="mainWindow">
    /// The <see cref="MainForm"/> to get access to the status label.
    /// </param>
    public static void GenerateOgamaSlideshowTrials(DetectionSettings detectonSettings, MainForm mainWindow)
    {
      // Stores found stimuli files
      List<string> trialNames = Document.ActiveDocument.ExperimentSettings.SlideShow.GetTrialNames();

      foreach (KeyValuePair<int, int> kvp in detectonSettings.TrialSequenceToTrialIDAssignments)
      {
        int trialID = kvp.Value;
        string file = string.Empty;
        if (detectonSettings.TrialIDToImageAssignments.ContainsKey(trialID))
        {
          file = detectonSettings.TrialIDToImageAssignments[trialID];
        }

        string filename = Path.GetFileNameWithoutExtension(file);

        // Create slide
        var stopConditions = new StopConditionCollection
                               {
                                 new MouseStopCondition(
                                   MouseButtons.Left, 
                                   true, 
                                   string.Empty, 
                                   null, 
                                   Point.Empty)
                               };

        VGImage stimulusImage = null;

        if (file != string.Empty)
        {
          stimulusImage = new VGImage(
            ShapeDrawAction.None,
            Pens.Black,
            Brushes.Black,
            SystemFonts.MenuFont,
            Color.White,
            Path.GetFileName(file),
            Document.ActiveDocument.ExperimentSettings.SlideResourcesPath,
            ImageLayout.Zoom,
            1f,
            Document.ActiveDocument.PresentationSize,
            VGStyleGroup.None,
            filename,
            string.Empty,
            true)
            {
              Size = Document.ActiveDocument.PresentationSize
            };
        }

        var newSlide = new Slide(
          filename,
          Color.White,
          null,
          stopConditions,
          null,
          string.Empty,
          Document.ActiveDocument.PresentationSize) { Modified = true, MouseCursorVisible = true };

        // Only add stimulus if an image exists
        if (file != string.Empty)
        {
          newSlide.VGStimuli.Add(stimulusImage);
        }
        else
        {
          newSlide.Name = "No stimulus detected";
        }

        // Create trial
        if (Document.ActiveDocument.ExperimentSettings.SlideShow.GetNodeByID(trialID) != null)
        {
          // trialID = int.Parse(Document.ActiveDocument.ExperimentSettings.SlideShow.GetUnusedNodeID());
          // var message = string.Format("The trial with the ID:{0} exists already in the slideshow so it will not be created."
          // + Environment.NewLine + "Delete the trial with this ID in the slideshow design module if you want it to be newly created by the importer, or assign a new ID to the imported data.", trialID);
          // ExceptionMethods.ProcessMessage("This trial exists already", message);
          continue;
        }

        var newTrial = new Trial(filename, trialID) { Name = filename };

        newTrial.Add(newSlide);

        if (trialNames.Contains(filename) || (filename == string.Empty && trialNames.Contains("No stimulus detected")))
        {
          // Trial already exists
          continue;
        }

        trialNames.Add(filename);

        // Create slide node
        var slideNode = new SlideshowTreeNode(newSlide.Name)
                          {
                            Name = trialID.ToString(CultureInfo.InvariantCulture),
                            Slide = newSlide
                          };

        // Add slide node to slideshow
        Document.ActiveDocument.ExperimentSettings.SlideShow.Nodes.Add(slideNode);
        Document.ActiveDocument.Modified = true;
      }

      mainWindow.StatusLabel.Text = "Saving slideshow to file ...";
      if (!Document.ActiveDocument.SaveSettingsToFile(Document.ActiveDocument.ExperimentSettings.DocumentFilename))
      {
        ExceptionMethods.ProcessErrorMessage("Couldn't save slideshow to experiment settings.");
      }

      mainWindow.StatusLabel.Text = "Refreshing context panel ...";
      mainWindow.RefreshContextPanelImageTabs();
      mainWindow.StatusLabel.Text = "Ready ...";
      mainWindow.StatusProgressbar.Value = 0;
    }
コード例 #9
0
ファイル: ImportTrialsDialog.cs プロジェクト: DeSciL/Ogama
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the ImportTrialsDialog class.
    /// </summary>
    /// <param name="newAsciiSettings">Ref. The <see cref="ASCIISettings"/> to use.</param>
    /// <param name="newDetectionSettings">Ref. The <see cref="DetectionSettings"/> to use.</param>
    public ImportTrialsDialog(ref ASCIISettings newAsciiSettings, ref DetectionSettings newDetectionSettings)
    {
      this.InitializeComponent();
      this.numberOfImportLines = 20000;
      this.detectionSetting = newDetectionSettings;
      this.asciiSetting = newAsciiSettings;
      this.trialImportRows = new List<string[]>();
      this.trialColumnHeaders = new List<string>();
      this.cbbTimeUnit.SelectedIndex = 1;
    }