public FixedDocument CreateFixedDocument(IEnumerable<string> diagrams,
            Size areaExtent,
            Size areaOrigin,
            bool fixedStrokeThickness,
            DiagramTable table)
        {
            var origin = new Point(areaOrigin.Width, areaOrigin.Height);
            var area = new Rect(origin, areaExtent);
            var scale = Math.Min(areaExtent.Width / PageWidth, areaExtent.Height / PageHeight);

            var fixedDocument = new FixedDocument() { Name = "diagrams" };
            //fixedDocument.DocumentPaginator.PageSize = new Size(areaExtent.Width, areaExtent.Height);

            SetElementResources(fixedDocument.Resources, fixedStrokeThickness);

            foreach (var diagram in diagrams)
            {
                var pageContent = new PageContent();
                var fixedPage = new FixedPage();

                //pageContent.Child = fixedPage;
                ((IAddChild)pageContent).AddChild(fixedPage);

                fixedDocument.Pages.Add(pageContent);

                fixedPage.Width = areaExtent.Width;
                fixedPage.Height = areaExtent.Height;

                var element = CreateDiagramElement(diagram,
                    areaExtent,
                    origin,
                    area,
                    fixedStrokeThickness,
                    fixedDocument.Resources,
                    table);

                // transform and scale for print
                element.LayoutTransform = new ScaleTransform(scale, scale);

                // set element position
                FixedPage.SetLeft(element, areaOrigin.Width);
                FixedPage.SetTop(element, areaOrigin.Height);

                // add element to page
                fixedPage.Children.Add(element);

                // update fixed page layout
                //fixedPage.Measure(areaExtent);
                //fixedPage.Arrange(area);
            }

            return fixedDocument;
        }
        private string DxfGenerate(string model,
            bool shortenStart,
            bool shortenEnd,
            DxfAcadVer version,
            DiagramTable table)
        {
            var dxf = new DxfDiagramCreator()
            {
                ShortenStart = shortenStart,
                ShortenEnd = shortenEnd,
                DiagramProperties = Editor.Context.CurrentCanvas.GetProperties(),
                Tags = Editor.Context.Tags
            };

            return dxf.GenerateDxf(model, version, table);
        }
        private void DxfExportDlg(bool shortenStart, bool shortenEnd, DiagramTable table)
        {
            var dlg = new Microsoft.Win32.SaveFileDialog()
            {
                Filter = "Dxf R12 (*.dxf)|*.dxf|Dxf AutoCAD 2000 (*.dxf)|*.dxf|All Files (*.*)|*.*",
                FilterIndex = 2,
                Title = "Export Diagram to Dxf",
                FileName = "diagram"
            };

            var res = dlg.ShowDialog();
            if (res == true)
            {
                var filter = dlg.FilterIndex;
                var fileName = dlg.FileName;
                var canvas = Editor.Context.CurrentCanvas;

                DxfExportDiagram(fileName,
                    canvas,
                    shortenStart, shortenEnd,
                    FilterToAcadVer(filter),
                    table);
            }
        }
        private void DxfExportDiagram(string fileName,
            ICanvas canvas,
            bool shortenStart,
            bool shortenEnd,
            DxfAcadVer version,
            DiagramTable table)
        {
            string model = ModelEditor.GenerateDiagram(canvas, null, canvas.GetProperties());

            string dxf = DxfGenerate(model, shortenStart, shortenEnd, version, table);

            DxfSave(fileName, dxf);
        }
 private void UpdateCurrentTable(DiagramTable table)
 {
     TableGrid.SetData(this, null);
     TableGrid.SetData(this, table);
 }
        private void SetCurrentTable()
        {
            var table = new DiagramTable()
            {
                Id = 0,
                Revision1 = new Revision()
                {
                    Version = "",
                    Date = "",
                    Remarks = "",
                },
                Revision2 = new Revision()
                {
                    Version = "",
                    Date = "",
                    Remarks = "",
                },
                Revision3 = new Revision()
                {
                    Version = "",
                    Date = "",
                    Remarks = "",
                },
                PathLogo1 = "",
                PathLogo2 = "",
                Drawn = new Person()
                {
                    Name = "user",
                    Date = DateTime.Today.ToString("yyyy-MM-dd")
                },
                Checked = new Person()
                {
                    Name = "user",
                    Date = DateTime.Today.ToString("yyyy-MM-dd")
                },
                Approved = new Person()
                {
                    Name = "user",
                    Date = DateTime.Today.ToString("yyyy-MM-dd")
                },
                Title = "LOGIC DIAGRAM",
                SubTitle1 = "DIAGRAM",
                SubTitle2 = "",
                SubTitle3 = "",
                Rev = "0",
                Status = "-",
                Page = "-",
                Pages = "-",
                Project = "Sample",
                OrderNo = "",
                DocumentNo = "",
                ArchiveNo = ""
            };

            TableGrid.SetData(this, table);
        }
        private FixedDocumentSequence CreateFixedDocumentSequence(IEnumerable<IEnumerable<string>> projects,
            Size areaExtent,
            Size areaOrigin,
            bool fixedStrokeThickness,
            DiagramTable table)
        {
            var fixedDocumentSeq = new FixedDocumentSequence() { Name = "diagrams" };

            foreach (var diagrams in projects)
            {
                var fixedDocument = CreateFixedDocument(diagrams,
                    areaExtent,
                    areaOrigin,
                    fixedStrokeThickness,
                    table);

                var documentRef = new DocumentReference();
                documentRef.BeginInit();
                documentRef.SetDocument(fixedDocument);
                documentRef.EndInit();

                (fixedDocumentSeq as IAddChild).AddChild(documentRef);
            }

            return fixedDocumentSeq;
        }
        private FrameworkElement CreateDiagramElement(string diagram,
            Size areaExtent,
            Point origin,
            Rect area,
            bool fixedStrokeThickness,
            ResourceDictionary resources,
            DiagramTable table)
        {
            var grid = new Grid()
            {
                ClipToBounds = true,
                Resources = resources
            };

            var template = new Control()
            {
                Template = grid.Resources[ResourceConstants.KeyLandscapePageTemplate] as ControlTemplate
            };

            var canvas = new DiagramCanvas()
            {
                Width = PageWidth,
                Height = PageHeight
            };

            ModelEditor.Parse(diagram,
                canvas, this.DiagramCreator,
                0, 0,
                false, false, false, true);

            grid.Children.Add(template);
            grid.Children.Add(canvas);

            LineEx.SetShortenStart(grid, ShortenStart);
            LineEx.SetShortenEnd(grid, ShortenEnd);

            TableGrid.SetData(grid, table);

            return grid;
        }
        public void PrintSequence(IEnumerable<IEnumerable<string>> projects, string name, DiagramTable table)
        {
            if (projects == null)
                throw new ArgumentNullException();

            var dlg = new PrintDialog();
            ShowPrintDialog(dlg);

            var caps = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
            var areaExtent = new Size(caps.PageImageableArea.ExtentWidth, caps.PageImageableArea.ExtentHeight);
            var areaOrigin = new Size(caps.PageImageableArea.OriginWidth, caps.PageImageableArea.OriginHeight);

            var fixedDocumentSeq = CreateFixedDocumentSequence(projects,
                areaExtent,
                areaOrigin,
                false,
                table);

            dlg.PrintDocument(fixedDocumentSeq.DocumentPaginator, name);
        }