/// <summary> /// Initializes a new instance of the Trial class by cloning the given <see cref="Trial"/> /// </summary> /// <param name="newTrial">A <see cref="Trial"/> with the trial to clone.</param> public Trial(Trial newTrial) { this.Name = newTrial.Name; this.ID = newTrial.ID; foreach (Slide slide in newTrial) { this.Add((Slide)slide.Clone()); } }
/// <summary> /// This method iterates the given shuffled object collection recursively /// to return the one dimensional <see cref="TrialCollection"/> that is used /// during presentation. /// </summary> /// <param name="collection">A <see cref="List{Object}"/> with the shuffled trials separated in /// shuffle groups.</param> /// <param name="trials">Ref. The output <see cref="TrialCollection"/>.</param> private void GetTrialsFromObjectCollection(List <object> collection, ref TrialCollection trials) { foreach (object item in collection) { if (item is Trial) { Trial trial = item as Trial; trials.Add(trial); } else if (item is List <object> ) { this.GetTrialsFromObjectCollection((List <object>)item, ref trials); } } }
/// <summary> /// This method iterates recursively through the tree to return only the trials /// contained in the tree. /// </summary> /// <param name="trials">Ref. The output <see cref="TrialCollection"/> of trials.</param> /// <param name="node">The <see cref="TreeNode"/> to parse.</param> private void ParseNodeForTrials(ref TrialCollection trials, TreeNode node) { Trial trial = null; // Add trial if this node is marked to be a trial if (node.Tag != null && node.Tag.ToString() == "Trial") { trial = new Trial(node.Text, GetIdOfNode(node)); trials.Add(trial); } foreach (TreeNode subNode in node.Nodes) { SlideshowTreeNode subSlideNode = subNode as SlideshowTreeNode; Slide slide = subSlideNode.Slide; if (slide != null) { // By default use a new trial for each slide trial = new Trial(subNode.Text, GetIdOfNode(subNode)); // If parent is already marked as trial use this // instead. if (subNode.Parent != null && subNode.Parent.Tag != null && subNode.Parent.Tag.ToString() == "Trial") { trial = trials[trials.Count - 1]; } // Add slide to correct trial trial.Add(slide); } // Iterate through the tree. this.ParseNodeForTrials(ref trials, subNode); // If a trial was found, add it to the list. if (trial != null && !trials.Contains(trial)) { trials.Add(trial); } } }
/// <summary> /// Inserts the pre slide trials. /// </summary> /// <param name="trials">The trials.</param> private void InsertPreSlideTrials(ref TrialCollection trials) { var trialsWithPreSlideTrials = new TrialCollection(); foreach (var trial in trials) { foreach (var slideobject in trial) { // if we have a preslide fixation trial add this trial before var preSlideTrialID = slideobject.IdOfPreSlideFixationTrial; if (preSlideTrialID != -1) { var preSlideNode = this.GetNodeByID(preSlideTrialID); var preTrial = new Trial(preSlideNode.Text, preSlideTrialID); preTrial.AddRange(this.GetPreSlideTrialSlides(preSlideNode)); trialsWithPreSlideTrials.Add(preTrial); } } trialsWithPreSlideTrials.Add(trial); } trials = trialsWithPreSlideTrials; }
/// <summary> /// This method iterates the slideshow recursively to find the /// trial with the given ID. /// </summary> /// <param name="trialID">An <see cref="Int32"/> with the trial id to search for.</param> /// <returns>The <see cref="Trial"/> that matches the trial id.</returns> public Trial GetTrialByID(int trialID) { SlideshowTreeNode trialNode = IterateTreeNodes(trialID.ToString(), this, true); if (trialNode != null) { Trial trial = new Trial(trialNode.Text, trialID); if (trialNode.Slide != null) { if (trialNode.Parent.Tag != null && trialNode.Parent.Tag.ToString() == "Trial") { trial = new Trial(trialNode.Parent.Text, Convert.ToInt32(trialNode.Parent.Name)); foreach (SlideshowTreeNode slideNode in trialNode.Parent.Nodes) { trial.Add((Slide)slideNode.Slide.Clone()); } } else { trial.Add((Slide)trialNode.Slide.Clone()); } } else if (trialNode.Nodes.Count > 0 && (trialNode.Tag != null && trialNode.Tag.ToString() == "Trial")) { foreach (SlideshowTreeNode slideNode in trialNode.Nodes) { trial.Add((Slide)slideNode.Slide.Clone()); } } return(trial); } return(null); }
/// <summary> /// This method iterates recursively through the tree to return a /// shuffled trial collection. /// </summary> /// <param name="node">The <see cref="TreeNode"/> to parse.</param> /// <returns>A <see cref="List{Object}"/> with the shuffled trials separated in /// shuffle groups.</returns> private List <object> ParseNodeForRandomizedTrials(TreeNode node) { var items = new List <object>(); var parentNode = node as SlideshowTreeNode; if (this.shuffling.UseThisCustomShuffling) { if (Convert.ToInt32(parentNode.Name) == this.shuffling.ShuffleSectionsParentNodeID) { return(this.ParseNodeForCustomShuffledTrials(node)); } } if (parentNode.Tag != null && parentNode.Tag.ToString() == "Trial") { var trial = new Trial(parentNode.Text, GetIdOfNode(parentNode)); foreach (SlideshowTreeNode subNode in parentNode.Nodes) { var slide = subNode.Slide; if (slide != null && !slide.IsDisabled) { //// if we have a preslide fixation trial add the slides before //var preSlideTrialID = slide.IdOfPreSlideFixationTrial; //if (preSlideTrialID != -1) //{ // var preSlideNode = this.GetNodeByID(preSlideTrialID); // trial.AddRange(this.GetPreSlideTrialSlides(preSlideNode)); //} trial.Add(slide); } } if (trial.Count > 0) { items.Add(trial); } } else { foreach (TreeNode subNode in node.Nodes) { var subCollectionNode = subNode as SlideshowTreeNode; if (subCollectionNode is BrowserTreeNode) { var trial = new Trial(subNode.Text, GetIdOfNode(subNode)); var browserSlide = this.CreateBrowserSlide(subCollectionNode as BrowserTreeNode); if (!browserSlide.IsDisabled) { //// if we have a preslide fixation trial add this trial before //var preSlideTrialID = browserSlide.IdOfPreSlideFixationTrial; //if (preSlideTrialID != -1) //{ // var preSlideNode = this.GetNodeByID(preSlideTrialID); // var preTrial = new Trial(preSlideNode.Text, preSlideTrialID); // preTrial.AddRange(this.GetPreSlideTrialSlides(preSlideNode)); // items.Add(preTrial); //} trial.Add(browserSlide); items.Add(trial); } } else { var slide = subCollectionNode.Slide; if (slide != null && !slide.IsDisabled) { var trial = new Trial(subNode.Text, GetIdOfNode(subNode)); //// if we have a preslide fixation trial add this trial before //var preSlideTrialID = slide.IdOfPreSlideFixationTrial; //if (preSlideTrialID != -1) //{ // var preSlideNode = this.GetNodeByID(preSlideTrialID); // var preTrial = new Trial(preSlideNode.Text, preSlideTrialID); // preTrial.AddRange(this.GetPreSlideTrialSlides(preSlideNode)); // items.Add(preTrial); //} trial.Add(slide); items.Add(trial); } else { items.Add(this.ParseNodeForRandomizedTrials(subNode)); } } } if (parentNode.Randomize) { items = (List <object>) CollectionUtils <object> .Shuffle(items); if (parentNode.NumberOfItemsToUse != 0) { items.RemoveRange(parentNode.NumberOfItemsToUse, items.Count - parentNode.NumberOfItemsToUse); } } } return(items); }