コード例 #1
0
ファイル: ServerAgent.cs プロジェクト: ixmilia/bcad
        public async Task <string> GetPlotPreview(ClientPlotSettings settings)
        {
            var htmlDialogService = (HtmlDialogService)Workspace.DialogService;
            var viewModel         = (SvgPlotterViewModel)htmlDialogService.CreateAndPopulateViewModel(settings, Workspace.Drawing.Settings, plotTypeOverride: "svg"); // force to svg for preview

            viewModel.PlotAsDocument = false;
            viewModel.OutputWidth    = settings.PreviewMaxSize;
            viewModel.OutputHeight   = settings.PreviewMaxSize;
            if (settings.Width > settings.Height)
            {
                // keep width, reset height
                viewModel.OutputHeight = settings.Height / settings.Width * settings.PreviewMaxSize;
            }
            else
            {
                // keep height, reset width
                viewModel.OutputWidth = settings.Width / settings.Height * settings.PreviewMaxSize;
            }

            var drawing = Workspace.Drawing.UpdateColors(settings.ColorType);

            using (var stream = await htmlDialogService.PlotToStream(viewModel, drawing, Workspace.ActiveViewPort))
                using (var reader = new StreamReader(stream))
                {
                    var contents = await reader.ReadToEndAsync();

                    return(contents);
                }
        }
コード例 #2
0
        public ViewPortViewModelBase CreateAndPopulateViewModel(ClientPlotSettings settings, DrawingSettings drawingSettings, string plotTypeOverride = null)
        {
            ViewPortViewModelBase viewModel = null;

            switch (plotTypeOverride ?? settings.PlotType)
            {
            case "pdf":
                var pdfViewModel = (PdfPlotterViewModel)_pdfPlotterFactory.CreatePlotterViewModel();
                pdfViewModel.DisplayWidth  = settings.Width;
                pdfViewModel.DisplayHeight = settings.Height;
                viewModel = pdfViewModel;
                break;

            case "svg":
                var svgViewModel = (SvgPlotterViewModel)_svgPlotterFactory.CreatePlotterViewModel();
                svgViewModel.PlotAsDocument = true;
                svgViewModel.DisplayWidth   = settings.Width;
                svgViewModel.DisplayHeight  = settings.Height;
                svgViewModel.OutputWidth    = settings.Width;
                svgViewModel.OutputHeight   = settings.Height;
                viewModel = svgViewModel;
                break;
            }

            if (viewModel is object)
            {
                var transform   = _workspace.ActiveViewPort.GetTransformationMatrixWindowsStyle(Agent.Width, Agent.Height).Inverse();
                var topLeft     = transform.Transform(settings.Viewport.TopLeft.ToPoint());
                var bottomRight = transform.Transform(settings.Viewport.BottomRight.ToPoint());
                viewModel.ViewPortType = settings.ViewPortType;
                viewModel.ScalingType  = settings.ScalingType;
                var(scaleA, scaleB)    = settings.GetUnitAdjustedScale(drawingSettings);
                viewModel.ScaleA       = scaleA;
                viewModel.ScaleB       = scaleB;
                viewModel.BottomLeft   = new Point(topLeft.X, bottomRight.Y, 0.0);
                viewModel.TopRight     = new Point(bottomRight.X, topLeft.Y, 0.0);
            }

            return(viewModel);
        }