/// <summary> /// Creates choice box view model from choice box model /// </summary> /// <param name="choiceBox">Choice box model data</param> /// <param name="templateViewModel">Parent template</param> /// <returns>Created choice box view model</returns> private static ChoiceBoxViewModel CreateChoiceBoxViewModel(ChoiceBoxElement choiceBox, TemplateViewModel templateViewModel) { ChoiceBoxViewModel choiceBoxViewModel = new ChoiceBoxViewModel( choiceBox.Name, choiceBox.Top, choiceBox.Left, choiceBox.Width, choiceBox.Height, templateViewModel, null); foreach (OmrBubble modelBubble in choiceBox.Bubbles) { BubbleViewModel bubbleViewModel = new BubbleViewModel( choiceBox.BubbleWidth, choiceBox.BubbleHeight, modelBubble.Top - choiceBox.Top, modelBubble.Left - choiceBox.Left, choiceBoxViewModel); bubbleViewModel.Name = modelBubble.Value; bubbleViewModel.IsValid = modelBubble.IsValid; choiceBoxViewModel.Bubbles.Add(bubbleViewModel); } return(choiceBoxViewModel); }
/// <summary> /// Apply changes to question /// </summary> /// <param name="i">Index of the question to process</param> /// <param name="op">Operation to apply</param> private void ProcessQuestion(int i, Func <double, double, double> op) { this.selectedItems[i].Width = op(this.selectedItems[i].Width, this.widthKoef); this.selectedItems[i].Height = op(this.selectedItems[i].Height, this.heightKoef); if (this.selectedItems[i] is ChoiceBoxViewModel) { this.ResizeBubbles((ChoiceBoxViewModel)this.selectedItems[i], op); } else if (this.selectedItems[i] is GridViewModel) { GridViewModel grid = (GridViewModel)this.selectedItems[i]; for (int j = 0; j < grid.ChoiceBoxes.Count; j++) { ChoiceBoxViewModel childChoiceBox = grid.ChoiceBoxes[j]; childChoiceBox.Width = op(childChoiceBox.Width, this.widthKoef); childChoiceBox.Height = op(childChoiceBox.Height, this.heightKoef); childChoiceBox.Top = op(childChoiceBox.Top, this.heightKoef); childChoiceBox.Left = op(childChoiceBox.Left, this.widthKoef); this.ResizeBubbles(childChoiceBox, op); } } }
/// <summary> /// Resize child bubbles /// </summary> /// <param name="choiceBox">Parent choice box</param> /// <param name="op">Operaion that needs to be applied</param> private void ResizeBubbles(ChoiceBoxViewModel choiceBox, Func <double, double, double> op) { for (int j = 0; j < choiceBox.BubblesCount; j++) { choiceBox.Bubbles[j].Width = op(choiceBox.Bubbles[j].Width, this.widthKoef); choiceBox.Bubbles[j].Height = op(choiceBox.Bubbles[j].Height, this.heightKoef); choiceBox.Bubbles[j].Top = op(choiceBox.Bubbles[j].Top, this.heightKoef); choiceBox.Bubbles[j].Left = op(choiceBox.Bubbles[j].Left, this.widthKoef); } }
/// <summary> /// Initializes a new instance of the <see cref="BubbleViewModel"/> class. /// </summary> /// <param name="width">Bubble width</param> /// <param name="height">Bubble height</param> /// <param name="top">Bubble top position</param> /// <param name="left">Bubble left position</param> /// <param name="parentQuestion">Parent question containing bubble</param> public BubbleViewModel(double width, double height, double top, double left, ChoiceBoxViewModel parentQuestion) { this.width = width; this.height = height; this.top = top; this.left = left; this.isValid = true; this.fontSize = (int)(this.defaultFontSize / TemplateViewModel.ZoomKoefficient); this.ParentQuestion = parentQuestion; }
/// <summary> /// Converts template data model to template view model /// </summary> /// <param name="template">OmrTemplate to convert</param> /// <returns>Resulting TemplateViewModel</returns> public static TemplateViewModel ConvertModelToViewModel(OmrTemplate template) { TemplateViewModel templateViewModel = new TemplateViewModel(template.FinalizationComplete, template.TemplateId); templateViewModel.TemplateName = template.Name; templateViewModel.IsGeneratedTemplate = template.IsGenerated; OmrPage page = template.Pages[0]; templateViewModel.TemplateImageName = page.ImageName; templateViewModel.ImageFileFormat = page.ImageFormat; templateViewModel.PageWidth = page.Width; templateViewModel.PageHeight = page.Height; List <BaseQuestionViewModel> elements = new List <BaseQuestionViewModel>(); List <ReferencePointElement> refPoints = new List <ReferencePointElement>(); foreach (OmrElement modelElement in page.Elements) { if (modelElement is ChoiceBoxElement) { ChoiceBoxViewModel choiceBoxViewModel = CreateChoiceBoxViewModel((ChoiceBoxElement)modelElement, templateViewModel); elements.Add(choiceBoxViewModel); } else if (modelElement is GridElement) { GridViewModel gridViewModel = CreateGridViewModel((GridElement)modelElement, templateViewModel); elements.Add(gridViewModel); } else if (modelElement is BarcodeElement) { BarcodeViewModel barcodeViewModel = CreateBarcodeViewModel((BarcodeElement)modelElement, templateViewModel); elements.Add(barcodeViewModel); } else if (modelElement is ClipAreaElement) { ClipAreaViewModel clipViewModel = CreateClipAreaViewModel((ClipAreaElement)modelElement, templateViewModel); elements.Add(clipViewModel); } else if (modelElement is ReferencePointElement) { refPoints.Add((ReferencePointElement)modelElement); } } templateViewModel.AddQuestions(elements); templateViewModel.ReferencePointsModels = refPoints.ToArray(); templateViewModel.IsDirty = false; return(templateViewModel); }
/// <summary> /// Apply changes for specific choice box /// </summary> /// <param name="source">Item to change</param> /// <param name="target">Target item</param> private void ApplyChanges(ChoiceBoxViewModel source, ChoiceBoxViewModel target) { for (var i = 0; i < source.Bubbles.Count; i++) { source.Bubbles[i].Top = target.Bubbles[i].Top; source.Bubbles[i].Left = target.Bubbles[i].Left; } source.Top = target.Top; source.Left = target.Left; source.Width = target.Width; source.Height = target.Height; }
/// <summary> /// Creates grid view model from grid model /// </summary> /// <param name="gridElement">Grid model data</param> /// <param name="templateViewModel">Parent template</param> /// <returns>Created grid view model</returns> private static GridViewModel CreateGridViewModel(GridElement gridElement, TemplateViewModel templateViewModel) { GridViewModel gridViewModel = new GridViewModel( gridElement.Name, gridElement.Top, gridElement.Left, gridElement.Width, gridElement.Height, templateViewModel, gridElement.Orientation); gridViewModel.ChoiceBoxes.Clear(); List <ChoiceBoxViewModel> choiceBoxes = new List <ChoiceBoxViewModel>(); foreach (var omrElement in gridElement.ChoiceBoxes) { var choiceBox = (ChoiceBoxElement)omrElement; ChoiceBoxViewModel choiceBoxViewModel = new ChoiceBoxViewModel( choiceBox.Name, choiceBox.Top - gridElement.Top, choiceBox.Left - gridElement.Left, choiceBox.Width, choiceBox.Height, null, gridViewModel); foreach (OmrBubble modelBubble in choiceBox.Bubbles) { BubbleViewModel bubbleViewModel = new BubbleViewModel( choiceBox.BubbleWidth, choiceBox.BubbleHeight, modelBubble.Top - choiceBox.Top, modelBubble.Left - choiceBox.Left, choiceBoxViewModel); bubbleViewModel.Name = modelBubble.Value; bubbleViewModel.IsValid = modelBubble.IsValid; choiceBoxViewModel.Bubbles.Add(bubbleViewModel); } choiceBoxes.Add(choiceBoxViewModel); } gridViewModel.InitiWithChoiceBoxes(choiceBoxes); return(gridViewModel); }
private void ChangeOriginalQuestions(int i, BaseQuestionViewModel ethalonQuestion) { if (this.questions[i] is ChoiceBoxViewModel) { ChoiceBoxViewModel choiceBox = (ChoiceBoxViewModel)this.questions[i]; ChoiceBoxViewModel target = (ChoiceBoxViewModel)ethalonQuestion; this.ApplyChanges(choiceBox, target); } else if (this.questions[i] is GridViewModel) { GridViewModel grid = (GridViewModel)this.questions[i]; GridViewModel target = (GridViewModel)ethalonQuestion; this.ApplyChanges(grid, target); } }
/// <summary> /// Apply changes to questions /// </summary> /// <param name="models">Model to use to restore questions states</param> private void ChangeOriginalQuestions(List <BaseQuestionViewModel> models) { for (int i = 0; i < this.questions.Count; i++) { if (this.questions[i] is ChoiceBoxViewModel) { ChoiceBoxViewModel choiceBox = (ChoiceBoxViewModel)this.questions[i]; ChoiceBoxViewModel target = (ChoiceBoxViewModel)models[i]; this.ApplyChanges(choiceBox, target); } else if (this.questions[i] is GridViewModel) { GridViewModel grid = (GridViewModel)this.questions[i]; GridViewModel target = (GridViewModel)models[i]; this.ApplyChanges(grid, target); } } }
/// <summary> /// Creates grid view model from grid model /// </summary> /// <param name="gridElement">Grid model data</param> /// <returns>Created grid view model</returns> private static GridViewModel CreateGridViewModel(GridElement gridElement) { GridViewModel gridViewModel = new GridViewModel( gridElement.Name, gridElement.Top, gridElement.Left, gridElement.Width, gridElement.Height); gridViewModel.Orientation = gridElement.Orientation; gridViewModel.ChoiceBoxes.Clear(); foreach (var omrElement in gridElement.ChoiceBoxes) { var choiceBox = (ChoiceBoxElement)omrElement; ChoiceBoxViewModel choiceBoxViewModel = new ChoiceBoxViewModel( choiceBox.Name, choiceBox.Top - gridElement.Top, choiceBox.Left - gridElement.Left, choiceBox.Width, choiceBox.Height); foreach (OmrBubble modelBubble in choiceBox.Bubbles) { BubbleViewModel bubbleViewModel = new BubbleViewModel( choiceBox.BubbleWidth, choiceBox.BubbleHeight, modelBubble.Top - choiceBox.Top, modelBubble.Left - choiceBox.Left); bubbleViewModel.Name = modelBubble.Value; bubbleViewModel.IsValid = modelBubble.IsValid; choiceBoxViewModel.Bubbles.Add(bubbleViewModel); } gridViewModel.ChoiceBoxes.Add(choiceBoxViewModel); } return(gridViewModel); }
/// <summary> /// Creates ChoiceBox element from ChoiceBoxViewModel and adds to the OmrPage /// </summary> /// <param name="page">Page to add element to</param> /// <param name="choiceBoxViewModel">ViewModel to take data from</param> private static void AddChoiceBoxElement(OmrPage page, ChoiceBoxViewModel choiceBoxViewModel) { ChoiceBoxElement choiceBox = page.AddChoiceBoxElement( choiceBoxViewModel.Name, (int)choiceBoxViewModel.Width, (int)choiceBoxViewModel.Height, (int)choiceBoxViewModel.Top, (int)choiceBoxViewModel.Left); foreach (var bubble in choiceBoxViewModel.Bubbles) { choiceBox.AddBubble( bubble.Name, (int)bubble.Width, (int)bubble.Height, (int)(choiceBoxViewModel.Top + bubble.Top), (int)(choiceBoxViewModel.Left + bubble.Left), bubble.IsValid); } }
/// <summary> /// Tracks changes to bubbles count in choice box question /// </summary> /// <param name="choiceBox">Changed choice box question</param> /// <param name="bubblesBefore">Child bubbles before the change</param> /// <param name="bubblesAfter">Child bubbles after the change</param> public static void TrackChangeBubblesCount(ChoiceBoxViewModel choiceBox, List <BubbleViewModel> bubblesBefore, List <BubbleViewModel> bubblesAfter) { ChangeBubblesCountAction action = new ChangeBubblesCountAction(choiceBox, bubblesBefore, bubblesAfter); TrackAction(action); }
/// <summary> /// Initializes a new instance of the <see cref="ChoiceBoxViewModel"/> class /// </summary> /// <param name="choiceBox">Changed choice box question</param> /// <param name="bubblesBefore">Child bubbles before the change</param> /// <param name="bubblesAfter">Child bubbles after the change</param> public ChangeBubblesCountAction(ChoiceBoxViewModel choiceBox, List <BubbleViewModel> bubblesBefore, List <BubbleViewModel> bubblesAfter) { this.choiceBox = choiceBox; this.bubblesBefore = bubblesBefore; this.bubblesAfter = bubblesAfter; }