/// <summary> /// Creates cliparea view model from clip area model element /// </summary> /// <param name="clipAreaElement">ClipArea model</param> /// <param name="templateViewModel">Parent template</param> /// <returns>Created cliparea view model</returns> private static ClipAreaViewModel CreateClipAreaViewModel(ClipAreaElement clipAreaElement, TemplateViewModel templateViewModel) { ClipAreaViewModel clipAreaViewModel = new ClipAreaViewModel( clipAreaElement.Name, new Rect(clipAreaElement.Left, clipAreaElement.Top, clipAreaElement.Width, clipAreaElement.Height), templateViewModel); clipAreaViewModel.JpegQuality = clipAreaElement.JpegQuality; return(clipAreaViewModel); }
/// <summary> /// Creates Clip Area element from ClipAreaViewModel and adds to the OmrPage /// </summary> /// <param name="page">Page to add element to</param> /// <param name="clipAreaViewModel">ViewModel to take data from</param> private static void AddClipAreaElement(OmrPage page, ClipAreaViewModel clipAreaViewModel) { ClipAreaElement clipArea = page.AddClipAreaElement( clipAreaViewModel.Name, (int)clipAreaViewModel.Width, (int)clipAreaViewModel.Height, (int)clipAreaViewModel.Top, (int)clipAreaViewModel.Left); clipArea.JpegQuality = clipAreaViewModel.JpegQuality; }
/// <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); }