/// <summary>
        /// Loads template image located by specified path
        /// </summary>
        /// <param name="path">Path to image</param>
        private void LoadTemplateImageFromFile(string path)
        {
            double monitorWidth, monitorHeight;

            ResolutionUtility.GetMonitorResolution(out monitorWidth, out monitorHeight);

            FileInfo fileInfo = new FileInfo(path);

            this.ImageSizeInBytes  = fileInfo.Length;
            this.TemplateImageName = fileInfo.Name;
            this.ImageFileFormat   = fileInfo.Extension;

            if (!ResolutionUtility.CheckImageSize(fileInfo))
            {
                return;
            }

            this.TemplateImage = new BitmapImage(new Uri("file://" + path));

            if (this.TemplateImage.PixelWidth < 1200 || this.TemplateImage.PixelHeight < 1700)
            {
                DialogManager.ShowImageSizeWarning();
            }

            ZoomKoefficient = monitorWidth / this.TemplateImage.PixelWidth < 1
                ? monitorWidth / this.TemplateImage.PixelWidth
                : 1;

            this.OnPropertyChanged(nameof(this.PageScale));
        }
Exemple #2
0
        /// <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("Loaded template");

            templateViewModel.TemplateId           = template.TemplateId;
            templateViewModel.FinalizationComplete = template.FinalizationComplete;

            OmrPage page = template.Pages[0];

            templateViewModel.TemplateImageName = page.ImageName;
            templateViewModel.ImageFileFormat   = page.ImageFormat;

            List <BaseQuestionViewModel> elements = new List <BaseQuestionViewModel>();

            foreach (OmrElement modelElement in page.Elements)
            {
                if (modelElement is ChoiceBoxElement)
                {
                    var choiceBoxViewModel = CreateChoiceBoxViewModel((ChoiceBoxElement)modelElement);
                    elements.Add(choiceBoxViewModel);
                }
                else if (modelElement is GridElement)
                {
                    var gridViewModel = CreateGridViewModel((GridElement)modelElement);
                    elements.Add(gridViewModel);
                }
            }

            templateViewModel.AddQuestions(elements);

            if (page.ImageData != null)
            {
                // loading from file
                double monitorWidth, monitorHeight;
                ResolutionUtility.GetMonitorResolution(out monitorWidth, out monitorHeight);

                var image = TemplateSerializer.DecompressImage(page.ImageData);

                templateViewModel.TemplateImage = image;
                templateViewModel.PageWidth     = page.Width;
                templateViewModel.PageHeight    = page.Height;

                TemplateViewModel.ZoomKoefficient = image.PixelWidth / page.Width < 1
                    ? image.PixelWidth / page.Width
                    : 1;
            }
            else
            {
                // processing server response
                templateViewModel.PageWidth  = page.Width;
                templateViewModel.PageHeight = page.Height;
            }

            return(templateViewModel);
        }
Exemple #3
0
        /// <summary>
        /// Updates images at main area according to selected preview image
        /// </summary>
        private void UpdateMainImage()
        {
            string path = this.SelectedPreviewImage.PathToImage;

            this.MainImage = new BitmapImage(new Uri("file://" + path));

            double monitorWidth, monitorHeight;

            ResolutionUtility.GetMonitorResolution(out monitorWidth, out monitorHeight);

            ZoomKoefficient = monitorWidth / this.MainImage.PixelWidth < 1
                ? monitorWidth / this.MainImage.PixelWidth
                : 1;

            this.OnPropertyChanged(nameof(this.PageScale));
        }