예제 #1
0
 protected virtual void OnPropertyChanged(String property)
 {
     if (this.PropertyChanged != null)
     {
         if (property.Contains('C'))
         {
             temp = CalculateFieldplan();
         }
         if (property.Contains('D'))
         {
             if (temp.colors == null)
             {
                 temp = CalculateFieldplan();
             }
             TempHTML = GenerateHTMLFieldPlan(temp);
         }
         this.PropertyChanged(this, new PropertyChangedEventArgs(null));
     }
 }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     p = FieldPlanDocument.CalculateFieldplan(field, BlockSize);
     ReDraw();
     MaxRows.Content = p.colors.GetLength(0);
 }
예제 #3
0
        // old version of drawing, replaced by html
        // possibly needed for xps export
        public void DrawFieldPlan(FieldPlanHelper helper)
        {
            FlowDocument d = new FlowDocument();

            d.PageWidth = 5000;
            Table table1 = new Table();

            d.Blocks.Add(new Paragraph(new Run(m_title))
            {
                FontSize = 20
            });
            d.Blocks.Add(table1);

            table1.CellSpacing = 5;
            table1.Background  = Brushes.White;

            for (int i = 0; i < helper.cellcount; i++)
            {
                table1.Columns.Add(new TableColumn()
                {
                    Width = new GridLength(100)
                });
            }
            table1.RowGroups.Add(new TableRowGroup());
            for (int i = 0; i < 10; i++)
            {
                TableRow tr = new TableRow();
                tr.Cells.Add(new TableCell(new Paragraph(new Run(((BaseDoc.horizontal == true) ? "Row" : "Column") + " " + (i + 1)))));
                for (int j = 0; j < helper.colors.GetLength(1); j++) // foreach block
                {
                    for (int k = 0; k < helper.colors[i, j].Length; k++)
                    {
                        TableCell td = new TableCell();
                        switch (m_back_color_mode)
                        {
                        case ColorMode.Normal: td.Background = new SolidColorBrush(helper.colors[i, j][k].rgb); break;                             // normal color

                        case ColorMode.Inverted: td.Background = new SolidColorBrush(SDtoSM(Invert(helper.colors[i, j][k].rgb))); break;           // inverted color

                        case ColorMode.Intelligent: td.Background = new SolidColorBrush(SDtoSM(IntelligentBW(helper.colors[i, j][k].rgb))); break; // intelligent BW
                        }

                        if (k == helper.colors[i, j].Length - 1) // if end of block, draw right border in intelligent black/white
                        {
                            td.BorderThickness = new Thickness(0, 0, 5, 0);
                            td.BorderBrush     = Brushes.Black;
                        }
                        Paragraph p = new Paragraph();
                        Run       r = new Run();
                        switch (m_fore_color_mode)
                        {
                        case ColorMode.Normal: r.Foreground = new SolidColorBrush(helper.colors[i, j][k].rgb); break;                             // normal color

                        case ColorMode.Inverted: r.Foreground = new SolidColorBrush(SDtoSM(Invert(helper.colors[i, j][k].rgb))); break;           // inverted color

                        case ColorMode.Intelligent: r.Foreground = new SolidColorBrush(SDtoSM(IntelligentBW(helper.colors[i, j][k].rgb))); break; // intelligent BW
                        }
                        r.Text = ParseRegex(helper.colors[i, j][k], helper.counts[i, j][k]);

                        p.Inlines.Add(r);
                        td.Blocks.Add(p);
                        tr.Cells.Add(td);
                    }
                }
                table1.RowGroups[0].Rows.Add(tr);
            }
            if (helper.colors.GetLength(0) > 10)
            {
                d.Blocks.Add(new Paragraph(new Run("+ additional " + (helper.colors.GetLength(0) - 10) + "rows")));
            }
            autoresizeColumns(table1);
            doc = d;
        }
예제 #4
0
        public ExcelPackage GenerateExcelFieldplan(FieldPlanHelper helper, ExcelPackage pack)
        {
            ExcelWorksheet ws         = pack.Workbook.Worksheets.Add(title);
            int            cols       = 0;
            int            rowcounter = 1;

            for (int i = 0; i < helper.colors.GetLength(0); i++) // foreach row
            {
                int        cellcounter = 1;
                ExcelRange cell1       = ws.Cells[++rowcounter, cellcounter++];
                cell1.Value = ((BaseDoc.horizontal == true) ? "Row" : "Column") + " " + (i + 1);
                cell1.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                cell1.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);
                for (int j = 0; j < helper.colors.GetLength(1); j++) // foreach block
                {
                    for (int k = 0; k < helper.colors[i, j].Length; k++)
                    {
                        if (helper.colors[i, j][k] != null) // for all non-empty dominoes
                        {
                            using (ExcelRange cell = ws.Cells[rowcounter, cellcounter++])
                            {
                                System.Drawing.Color b = System.Drawing.Color.Black;
                                switch (m_back_color_mode)
                                {
                                case ColorMode.Normal: b = SMtoSD(helper.colors[i, j][k].rgb); break;   // normal color

                                case ColorMode.Inverted: b = Invert(helper.colors[i, j][k].rgb); break; // inverted color

                                case ColorMode.Fixed: b = SMtoSD(m_fixed_back_color); break;            // intelligent BW
                                }
                                cell.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                                cell.Style.Fill.BackgroundColor.SetColor(b);

                                if (k == helper.colors[i, j].Length - 1) // if end of block, draw right border in intelligent black/white
                                {
                                    System.Drawing.Color border = IntelligentBW(helper.colors[i, j][k].rgb);
                                    cell.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
                                    cell.Style.Border.Right.Color.SetColor(border);
                                }
                                System.Drawing.Color f = System.Drawing.Color.Black;
                                switch (m_fore_color_mode)
                                {
                                case ColorMode.Normal: f = SMtoSD(helper.colors[i, j][k].rgb); break;   // normal color

                                case ColorMode.Inverted: f = Invert(helper.colors[i, j][k].rgb); break; // inverted color

                                case ColorMode.Intelligent: f = IntelligentBW(SDtoSM(b)); break;        // intelligent BW

                                case ColorMode.Fixed: f = SMtoSD(m_fixed_fore_color); break;
                                }
                                cell.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                                cell.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);
                                cell.Style.Font.Color.SetColor(f);
                                cell.Style.Numberformat.Format = "@";
                                cell.Value = ParseRegex(helper.colors[i, j][k], helper.counts[i, j][k]);
                            }
                        }
                    }
                }
                if (cellcounter > cols)
                {
                    cols = cellcounter;
                }
            }
            // those two assignments are needed for whatever reason (see http://stackoverflow.com/questions/38860557/strange-behavior-in-autofitcolumns-using-epplus)
            ws.Cells[1, 1].Value = "a";
            ws.Cells[1, 2].Value = "b";
            // apply font scheme to all cells
            ws.Cells[1, 1, rowcounter, cols].Style.Font.SetFromFont(StringToFont(text_format));
            // resize cells
            ws.Cells.AutoFitColumns(0);
            // add title
            ws.Cells[1, 2].Clear();
            ws.Cells[1, 1].Value                   = title;
            ws.Cells[1, 1].Style.Font.Size         = 15;
            ws.Cells[1, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Top;
            ws.Row(1).Height = 27;
            // add small summary
            if (summary_selection != SummaryEnum.None)
            {
                ExcelRange cell1 = ws.Cells[rowcounter + 2, 1];
                if (BaseDoc.horizontal == true)
                {
                    cell1.Value = "Rows: " + BaseDoc.dominoes.GetLength(1) + ", Columns: " + BaseDoc.dominoes.GetLength(0);
                }
                else
                {
                    cell1.Value = "Columns: " + BaseDoc.dominoes.GetLength(0) + ", Rows: " + BaseDoc.dominoes.GetLength(1);
                }
                ws.Cells[rowcounter + 3, 1].Value = "Total Number of dominoes: " + BaseDoc.dominoes.GetLength(0) * BaseDoc.dominoes.GetLength(1);
                ws.Cells[rowcounter + 2, 1, rowcounter + 3, 1].Style.Font.SetFromFont(StringToFont(text_format));
            }
            rowcounter += 4;
            // set footer
            ws.HeaderFooter.FirstFooter.CenteredText     = String.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.EvenFooter.CenteredText      = String.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.OddFooter.CenteredText       = String.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.OddHeader.RightAlignedText   = DateTime.Today.ToShortDateString();
            ws.HeaderFooter.EvenHeader.RightAlignedText  = DateTime.Today.ToShortDateString();
            ws.HeaderFooter.FirstHeader.LeftAlignedText  = "Project: " + new DirectoryInfo(System.IO.Path.GetDirectoryName(BaseDoc.path)).Name;
            ws.HeaderFooter.OddHeader.LeftAlignedText    = title;
            ws.HeaderFooter.EvenHeader.LeftAlignedText   = title;
            ws.HeaderFooter.FirstHeader.RightAlignedText = "Go to View -> Page Break Preview for page overview";
            ws.HeaderFooter.OddHeader.CenteredText       = "Project: " + new DirectoryInfo(System.IO.Path.GetDirectoryName(BaseDoc.path)).Name;
            ws.HeaderFooter.EvenHeader.CenteredText      = "Project: " + new DirectoryInfo(System.IO.Path.GetDirectoryName(BaseDoc.path)).Name;
            ws.PrinterSettings.TopMargin    = (decimal)0.5;
            ws.PrinterSettings.LeftMargin   = (decimal)0.4;
            ws.PrinterSettings.RightMargin  = (decimal)0.4;
            ws.PrinterSettings.BottomMargin = (decimal)0.5;
            ws.PrinterSettings.HeaderMargin = (decimal)0.2;
            ws.PrinterSettings.FooterMargin = (decimal)0.2;
            if (summary_selection == SummaryEnum.Large)
            {
                // The list is first stored to a new workbook to get the minimum size of each column.
                ExcelWorksheet summary = pack.Workbook.Worksheets.Add("Summary");
                summary.Cells[1, 1].Value = " ";
                summary.Cells[1, 2].Value = "Color";
                summary.Cells[1, 3].Value = "Total";
                summary.Cells[1, 4].Value = "Used";
                int[] counts = new int[BaseDoc.Colors.Count + 1];
                // count dominoes
                for (int i = 0; i < BaseDoc.dominoes.GetLength(0); i++)
                {
                    for (int j = 0; j < BaseDoc.dominoes.GetLength(1); j++)
                    {
                        counts[(BaseDoc.dominoes[i, j] > -1) ? BaseDoc.dominoes[i, j] : BaseDoc.Colors.Count]++;
                    }
                }
                int non_empty_cols = 0;
                for (int i = 0; i < counts.Length - 1; i++)
                {
                    if (counts[i] != 0)
                    {
                        summary.Cells[i + 2, 2].Value = BaseDoc.Colors[i].name;
                        summary.Cells[i + 2, 3].Value = BaseDoc.Colors[i].count;
                        summary.Cells[i + 2, 4].Value = counts[i];
                        non_empty_cols++;
                    }
                }
                summary.Cells[1, 1, counts.Length, 4].Style.Font.SetFromFont(StringToFont(text_format));
                summary.Cells.AutoFitColumns(0);
                double[] widths = new double[] { summary.Column(1).Width, summary.Column(2).Width, summary.Column(3).Width, summary.Column(4).Width };
                // the sheet is not needed anymore
                pack.Workbook.Worksheets.Delete(summary);

                ws.Cells[rowcounter + 1, 1].Value = "Overview of used dominoes:";
                int[] indices = new int[3]; // fist item: end index of name column,...
                for (int i = 0; i < 3; i++)
                {
                    int    endindex = (i == 0) ? 2 : indices[i - 1] + 1;
                    double width    = ws.Column(endindex).Width;
                    while (width < widths[i + 1])
                    {
                        endindex++;
                        width += ws.Column(endindex).Width;
                    }
                    indices[i] = endindex;
                }
                System.Drawing.Font textfont = StringToFont(text_format);
                ws.Cells[rowcounter + 1, 1].Style.Font.SetFromFont(textfont);
                rowcounter += 2;
                using (ExcelRange Color_Header = ws.Cells[rowcounter, 2, rowcounter, indices[0]])
                {
                    Color_Header.Merge = true;
                    Color_Header.Value = "Color";
                    Color_Header.Style.Font.SetFromFont(textfont);
                    SetAllBorders(Color_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Color_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                using (ExcelRange Count_Header = ws.Cells[rowcounter, indices[0] + 1, rowcounter, indices[1]])
                {
                    Count_Header.Merge = true;
                    Count_Header.Value = "Count";
                    Count_Header.Style.Font.SetFromFont(textfont);
                    SetAllBorders(Count_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Count_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                using (ExcelRange Used_Header = ws.Cells[rowcounter, indices[1] + 1, rowcounter, indices[2]])
                {
                    Used_Header.Merge = true;
                    Used_Header.Value = "Used";
                    Used_Header.Style.Font.SetFromFont(textfont);
                    SetAllBorders(Used_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Used_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                for (int i = 0; i < counts.Length - 1; i++)
                {
                    if (counts[i] > 0)
                    {
                        rowcounter++;
                        using (ExcelRange color_cell = ws.Cells[rowcounter, 1])
                        {
                            color_cell.Value = " ";
                            color_cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
                            color_cell.Style.Fill.BackgroundColor.SetColor(SMtoSD(BaseDoc.Colors[i].rgb));
                            SetAllBorders(color_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                        }
                        using (ExcelRange name_cell = ws.Cells[rowcounter, 2, rowcounter, indices[0]])
                        {
                            name_cell.Merge = true;
                            name_cell.Value = BaseDoc.Colors[i].name;
                            SetAllBorders(name_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            name_cell.Style.Font.SetFromFont(textfont);
                        }
                        using (ExcelRange count_cell = ws.Cells[rowcounter, indices[0] + 1, rowcounter, indices[1]])
                        {
                            count_cell.Merge = true;
                            count_cell.Value = BaseDoc.Colors[i].count;
                            SetAllBorders(count_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            count_cell.Style.Font.SetFromFont(textfont);
                        }
                        using (ExcelRange used_cell = ws.Cells[rowcounter, indices[1] + 1, rowcounter, indices[2]])
                        {
                            used_cell.Merge = true;
                            used_cell.Value = counts[i];
                            SetAllBorders(used_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            used_cell.Style.Font.SetFromFont(textfont);
                        }
                    }
                }
                ws.Cells[rowcounter + 1, 1, rowcounter + non_empty_cols + 1, indices[2]].Style.Font.SetFromFont(StringToFont(text_format));
            }
            return(pack);
        }
예제 #5
0
        public String GenerateHTMLFieldPlan(FieldPlanHelper helper)
        {
            // html head
            StringBuilder html = new StringBuilder();

            html.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"
                        + "<html>\n"
                        + "    <head>\n"
                        + "    <meta http-equiv=\"Content-Style-Type\" content=\"text/css\">   <title>" + (m_title + " Fieldplan")
                        + "</title>\n    <meta http-equiv=\"Content-Type\" content=\"text/css\"; charset=UTF-8\">\n    </head>\n    <body>");
            html.AppendLine(m_text_format + "    <h3 align=\"left\">" + m_title + "</h3>");
            html.AppendLine("        <table border=0 cellspacing=3 cellpadding=5 style=\"border-collapse:"
                            + ((m_collapse_borders == CollapsedMode.Collapsed) ? "collapse" : "separate") + "\">");
            if (helper.colors == null)
            {
                return("Hmmm, irgendwas ist schiefgegangen...");
            }
            for (int i = 0; i < helper.colors.GetLength(0); i++) // foreach row
            {
                html.AppendLine("            <tr>");
                html.AppendLine("                <td>" + ((BaseDoc.horizontal == true) ? "Row" : "Column") + "&nbsp;" + (i + 1) + "</td>");
                for (int j = 0; j < helper.colors.GetLength(1); j++) // foreach block
                {
                    for (int k = 0; k < helper.colors[i, j].Length; k++)
                    {
                        if (helper.colors[i, j][k] != null) // for all non-empty dominoes
                        {
                            System.Drawing.Color c = System.Drawing.Color.Black;
                            switch (m_back_color_mode)
                            {
                            case ColorMode.Normal: c = SMtoSD(helper.colors[i, j][k].rgb); break;   // normal color

                            case ColorMode.Inverted: c = Invert(helper.colors[i, j][k].rgb); break; // inverted color

                            case ColorMode.Fixed: c = SMtoSD(m_fixed_back_color); break;            // intelligent BW
                            }
                            html.Append("                <td bgcolor='");
                            html.Append(System.Drawing.ColorTranslator.ToHtml(c));
                            html.Append("'");
                            if (k == helper.colors[i, j].Length - 1) // if end of block, draw right border in intelligent black/white
                            {
                                html.Append(" style='width:115.15pt;border-right:solid " + System.Drawing.ColorTranslator.ToHtml(IntelligentBW(helper.colors[i, j][k].rgb)) + " 5.0pt'");
                            }
                            html.Append("> <font color='");
                            switch (m_fore_color_mode)
                            {
                            case ColorMode.Normal: html.Append(System.Drawing.ColorTranslator.ToHtml(SMtoSD(helper.colors[i, j][k].rgb))); break;   // normal color

                            case ColorMode.Inverted: html.Append(System.Drawing.ColorTranslator.ToHtml(Invert(helper.colors[i, j][k].rgb))); break; // inverted color

                            case ColorMode.Intelligent: html.Append(System.Drawing.ColorTranslator.ToHtml(IntelligentBW(SDtoSM(c)))); break;        // intelligent BW

                            case ColorMode.Fixed: html.Append(System.Drawing.ColorTranslator.ToHtml(SMtoSD(m_fixed_fore_color))); break;
                            }
                            html.Append("'>");
                            html.Append(ParseRegex(helper.colors[i, j][k], helper.counts[i, j][k]) + "</font></td>\n");
                        }
                    }
                }
                html.AppendLine("            </tr>");
            }
            html.AppendLine("        </table>");
            html.AppendLine("\n" + GetSmallDominoBalance());
            html.AppendLine("\n" + GetLargeDominoBalance());
            html.AppendLine("\n        </font>\n    </body>\n</html>");
            //Dateistream wird beendet und der temporaere Dateiname zurueckgegeben.
            return(html.ToString());
        }
예제 #6
0
        public static FieldPlanHelper CalculateFieldplan(FieldDocument BaseDoc, int TemplateLength, bool?reverse = false)
        {
            int[,] dominoes = BaseDoc.dominoes;
            if (BaseDoc.horizontal == false)
            {
                // if direction = vertical, then translate the field
                dominoes = new int[dominoes.GetLength(1), dominoes.GetLength(0)];
                for (int i = 0; i < dominoes.GetLength(0); i++)
                {
                    for (int j = 0; j < dominoes.GetLength(1); j++)
                    {
                        dominoes[i, j] = BaseDoc.dominoes[j, dominoes.GetLength(0) - 1 - i];
                    }
                }
            }
            int[,] tempdominoes = dominoes;
            if (reverse == true)
            {
                // if reversed building direction
                dominoes = new int[dominoes.GetLength(0), dominoes.GetLength(1)];
                for (int i = 0; i < dominoes.GetLength(0); i++)
                {
                    for (int j = 0; j < dominoes.GetLength(1); j++)
                    {
                        dominoes[i, j] = tempdominoes[dominoes.GetLength(0) - i - 1, dominoes.GetLength(1) - j - 1];
                    }
                }
            }
            int             blocks = (int)Math.Ceiling((double)((double)dominoes.GetLength(0) / (double)TemplateLength));
            FieldPlanHelper b      = new FieldPlanHelper();

            b.counts = new int[dominoes.GetLength(1), blocks][];
            b.colors = new DominoColor[dominoes.GetLength(1), blocks][];

            for (int i = 0; i < b.counts.GetLength(0); i++)     // foreach line
            {
                for (int j = 0; j < b.counts.GetLength(1); j++) // foreach block in this line
                {
                    int                initial_x     = j * TemplateLength;
                    int                pos_x         = 0;
                    int                currentcount  = 0;
                    DominoColor        currentColor  = null;
                    List <DominoColor> currentColors = new List <DominoColor>();
                    List <int>         currentCounts = new List <int>();
                    while (pos_x < TemplateLength && (initial_x + pos_x) < dominoes.GetLength(0))
                    {
                        if (dominoes[initial_x + pos_x, i] != -1 && BaseDoc.Colors[dominoes[initial_x + pos_x, i]] == currentColor)
                        {
                            currentcount++;
                        }
                        else
                        {
                            if (currentColor != null)
                            {
                                currentColors.Add(currentColor);
                                currentCounts.Add(currentcount);
                            }

                            currentcount = 1;
                            currentColor = (dominoes[initial_x + pos_x, i] == -1) ? null : BaseDoc.Colors[dominoes[initial_x + pos_x, i]];
                        }
                        pos_x++;
                    }
                    currentColors.Add(currentColor);
                    currentCounts.Add(currentcount);
                    b.colors[i, j] = currentColors.ToArray();
                    b.counts[i, j] = currentCounts.ToArray();
                }
            }
            int numberofcolumns = 0;

            for (int i = 0; i < b.colors.GetLength(0); i++)
            {
                int tempnum = 0;
                // get the number of cells for each line
                for (int j = 0; j < b.colors.GetLength(1); j++)
                {
                    tempnum += b.colors[i, j].Length;
                }
                if (tempnum > numberofcolumns)
                {
                    numberofcolumns = tempnum;
                }
            }
            b.cellcount = numberofcolumns;
            return(b);
        }