Exemplo n.º 1
0
        private void Save(object arg)
        {
            try
            {
                DisableCommands();

                var parameter = (Tuple <string, BaseType>)arg;

                _messageManager.Refresh();
                var buildings = parameter.Item2 == BaseType.War
                    ? _messageManager.GetWarParticipant().WarMap.Buildings
                    : Player.PlayerModel.Map.Buildings;

                var lm = new LayoutSaver();
                lm.Save(buildings, parameter.Item1);
                MessageBox.Show("Layout saved");
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
            finally
            {
                EnableCommands();
            }
        }
Exemplo n.º 2
0
        Composite
        (
            Double compositeWidth,
            Double compositeHeight,
            String headerText,
            String footerText,
            System.Drawing.Font headerFooterFont,
            IEnumerable <LegendControlBase> legendControls
        )
        {
            Debug.Assert(compositeWidth > 0);
            Debug.Assert(compositeHeight > 0);
            Debug.Assert(headerFooterFont != null);
            Debug.Assert(legendControls != null);
            AssertValid();

            // Note:
            //
            // Don't try taking a shortcut by using
            // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and
            // then compositing the image with the other elements.  That would work
            // if the caller were creating an image, but if it were creating an XPS
            // document, the graph would no longer be scalable.

            Double dScreenDpi =
                WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width;

            // The NodeXLControl can't be a child of two logical trees, so
            // disconnect it from its parent after saving the current vertex
            // locations.

            m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph);

            Debug.Assert(m_oNodeXLControl.Parent is Panel);
            m_oParentPanel = (Panel)m_oNodeXLControl.Parent;
            UIElementCollection oParentChildren = m_oParentPanel.Children;

            m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl);
            oParentChildren.Remove(m_oNodeXLControl);

            m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl);

            m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer(
                m_oNodeXLControl);

            // The header and footer are rendered as Label controls.  The legend is
            // rendered as a set of Image controls.

            Label oHeaderLabel, oFooterLabel;
            IEnumerable <Image> oLegendImages;
            Double dHeaderHeight, dTotalLegendHeight, dFooterHeight;

            CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont,
                                      out oHeaderLabel, out dHeaderHeight);

            CreateLegendImages(legendControls, compositeWidth, out oLegendImages,
                               out dTotalLegendHeight);

            CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont,
                                      out oFooterLabel, out dFooterHeight);

            m_oNodeXLControl.Width = compositeWidth;

            m_oNodeXLControl.Height = Math.Max(10,
                                               compositeHeight - dHeaderHeight - dTotalLegendHeight
                                               - dFooterHeight);

            // Adjust the control's graph scale so that the graph's vertices and
            // edges will be the same relative size in the composite that they are
            // in the control.

            m_oGraphImageScaler.SetGraphScale(
                (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi),
                (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi),
                dScreenDpi);

            // Adjust the NodeXLControl's translate transforms so that the
            // composite will be centered on the same point on the graph that the
            // NodeXLControl is centered on.

            m_oGraphImageCenterer.CenterGraphImage(new Size(compositeWidth,
                                                            m_oNodeXLControl.Height));

            StackPanel          oStackPanel         = new StackPanel();
            UIElementCollection oStackPanelChildren = oStackPanel.Children;

            // To avoid a solid black line at the bottom of the header or the top
            // of the footer, which is caused by rounding errors, make the
            // StackPanel background color the same as the header and footer.

            oStackPanel.Background = HeaderFooterBackgroundBrush;

            if (oHeaderLabel != null)
            {
                oStackPanelChildren.Add(oHeaderLabel);
            }

            // Wrap the NodeXLControl in a Grid to clip it.

            m_oGrid              = new Grid();
            m_oGrid.Width        = m_oNodeXLControl.Width;
            m_oGrid.Height       = m_oNodeXLControl.Height;
            m_oGrid.ClipToBounds = true;
            m_oGrid.Children.Add(m_oNodeXLControl);

            oStackPanelChildren.Add(m_oGrid);

            foreach (Image oLegendImage in oLegendImages)
            {
                oStackPanelChildren.Add(oLegendImage);
            }

            if (oFooterLabel != null)
            {
                oStackPanelChildren.Add(oFooterLabel);
            }

            Size oCompositeSize      = new Size(compositeWidth, compositeHeight);
            Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize);

            oStackPanel.Measure(oCompositeSize);
            oStackPanel.Arrange(oCompositeRectangle);
            oStackPanel.UpdateLayout();

            return(oStackPanel);
        }
Exemplo n.º 3
0
        SaveToXps
        (
            Size imageSize,
            String fileName
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(fileName));
            AssertValid();

            CheckIfLayingOutGraph("SaveToXps");

            // This control will be rehosted by a FixedPage.  It can't be a child
            // of logical trees, so disconnect it from its parent after saving the
            // current vertex locations.

            LayoutSaver oLayoutSaver = new LayoutSaver(this.Graph);

            Debug.Assert(this.Parent is Panel);
            Panel oParentPanel = (Panel)this.Parent;
            UIElementCollection oParentChildren = oParentPanel.Children;
            Int32 iChildIndex = oParentChildren.IndexOf(this);

            oParentChildren.Remove(this);

            GraphImageCenterer oGraphImageCenterer = new GraphImageCenterer(this);

            FixedDocument oFixedDocument = new FixedDocument();

            oFixedDocument.DocumentPaginator.PageSize = imageSize;
            PageContent oPageContent = new PageContent();

            FixedPage oFixedPage = new FixedPage();

            oFixedPage.Width  = imageSize.Width;
            oFixedPage.Height = imageSize.Height;

            this.Width  = imageSize.Width;
            this.Height = imageSize.Height;

            // Adjust the control's translate transforms so that the image will be
            // centered on the same point on the graph that the control is centered
            // on.

            oGraphImageCenterer.CenterGraphImage(imageSize);

            oFixedPage.Children.Add(this);
            oFixedPage.Measure(imageSize);

            oFixedPage.Arrange(new System.Windows.Rect(
                                   new System.Windows.Point(), imageSize));

            oFixedPage.UpdateLayout();

            ((System.Windows.Markup.IAddChild)oPageContent).AddChild(
                oFixedPage);

            oFixedDocument.Pages.Add(oPageContent);

            try
            {
                XpsDocument oXpsDocument = new XpsDocument(fileName,
                                                           FileAccess.Write);

                XpsDocumentWriter oXpsDocumentWriter =
                    XpsDocument.CreateXpsDocumentWriter(oXpsDocument);

                oXpsDocumentWriter.Write(oFixedDocument);
                oXpsDocument.Close();
            }
            finally
            {
                // Reconnect the NodeXLControl to its original parent.  Reset the
                // size to Auto in the process.

                oFixedPage.Children.Remove(this);
                this.Width  = Double.NaN;
                this.Height = Double.NaN;
                oGraphImageCenterer.RestoreCenter();
                oParentChildren.Insert(iChildIndex, this);

                // The graph may have shrunk when it was connected to the
                // FixedPage, and even though it will be expanded to its original
                // dimensions when UpdateLayout() is called below, the layout may
                // have lost "resolution" and the results may be poor.
                //
                // Fix this by restoring the original layout and redrawing the
                // graph.

                this.UpdateLayout();
                oLayoutSaver.RestoreLayout();
                this.DrawGraph(false);
            }
        }