コード例 #1
0
 private void Window_Loaded(object sender, System.EventArgs e)
 {
     if (fld != null)
     {
         FieldDocument fd = new FieldDocument(fld.path, fld.SourcePath, CloneDominoColors(fld.Colors), fld.length);
         fd.dominoes = (int[, ])fld.dominoes.Clone();
         temp        = fd;
         CheckColors();
     }
 }
コード例 #2
0
 public FieldPlanDocument(FieldDocument BaseDocument)
 {
     m_title             = System.IO.Path.GetFileNameWithoutExtension(BaseDocument.path);
     BaseDoc             = BaseDocument;
     m_use_template      = Properties.Settings.Default.UseTemplate;
     m_template_length   = Properties.Settings.Default.TemplateLength;
     m_hide_text         = Properties.Settings.Default.FieldPlanHideText;
     m_summary_selection = (SummaryEnum)Enum.Parse(typeof(SummaryEnum), Properties.Settings.Default.FieldPlanPropertyMode);
     m_text_format       = Properties.Settings.Default.FieldPlanFormatString;
     m_text_regex        = Properties.Settings.Default.FieldPlanRegex;
     m_fore_color_mode   = (ColorMode)Enum.Parse(typeof(ColorMode), Properties.Settings.Default.FieldPlanForeColorMode);
     m_back_color_mode   = (ColorMode)Enum.Parse(typeof(ColorMode), Properties.Settings.Default.FieldPlanBackColorMode);
     m_build_reverse     = false;
     TempHTML            = GenerateHTMLFieldPlan(CalculateFieldplan());
     m_fixed_fore_color  = SDtoSM(Properties.Settings.Default.FieldPlanFixedForeColor);
     m_fixed_back_color  = SDtoSM(Properties.Settings.Default.FieldPlanFixedBackColor);
 }
コード例 #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (ListBoxMain.SelectedIndex == 0) // Field
            {
                if (image_path != null)
                {
                    // read properties from settings
                    string prop = Properties.Settings.Default.FieldTemplates.Split('\n')[field_index];
                    prop = prop.Trim('\r').Split(':')[1];
                    string[] distance_properties = prop.Split('*');
                    int      a = int.Parse(distance_properties[0]);
                    int      b = int.Parse(distance_properties[1]);
                    int      c = int.Parse(distance_properties[2]);
                    int      d = int.Parse(distance_properties[3]);

                    String      filename = TextBoxFileName.Text;
                    BitmapImage bit      = new BitmapImage(new Uri(image_path));
                    String      ct       = GetVisualChild <TextBox>(ContentC).Text;
                    int         minimum  = Int32.MaxValue;
                    int         length   = 1;
                    while (true)
                    {
                        length++;

                        int height     = (int)Math.Round(((double)length * (a + b) / (c + d) * bit.PixelHeight / bit.PixelWidth));
                        int difference = Math.Abs(length * height - int.Parse(ct));
                        if (difference <= minimum)
                        {
                            minimum = difference;
                        }
                        else
                        {
                            length--;
                            break;
                        }
                    }

                    // Copy Image
                    String newpath = System.IO.Path.Combine(project_path, "Source Images", filename + System.IO.Path.GetExtension(image_path));
                    if (!(System.IO.File.Exists(System.IO.Path.Combine(project_path, filename + ".fld")) || File.Exists(newpath)))
                    {
                        File.Copy(image_path, newpath, false);
                        File.SetAttributes(newpath, FileAttributes.Normal);
                        doc          = new FieldDocument(System.IO.Path.Combine(project_path, filename + ".fld"), newpath, colors, length, a, b, c, d);
                        DialogResult = true;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("A field with this name already exists. Please choose another name.");
                    }
                }
                else
                {
                    MessageBox.Show("Please select an image.");
                }
            }
            if (ListBoxMain.SelectedIndex == 1) // Structure
            {
                if (image_path != null)
                {
                    String      filename = TextBoxFileName.Text;
                    BitmapImage bit      = new BitmapImage(new Uri(image_path));

                    string           templates     = Properties.Settings.Default.StructureTemplates;
                    XElement         xml           = XElement.Parse(templates);
                    ClusterStructure d             = new ClusterStructure(xml.Elements("StructureDefinition").ToArray()[structure_index]);
                    float            center_width  = d.cells[1, 1].width;
                    float            center_height = d.cells[1, 1].height;
                    float            add_width     = d.cells[0, 0].width + d.cells[2, 2].width;
                    float            add_height    = d.cells[0, 0].height + d.cells[2, 2].height;
                    int s_width  = 1;
                    int s_height = 1;
                    int minimum  = int.MaxValue;
                    while (true)
                    {
                        s_height = (int)((((center_width * s_width + add_width) * (float)bit.PixelHeight / (float)bit.PixelWidth) - add_height) / center_height);
                        int difference = dominoes - d.GenerateStructure(s_width, s_height).dominoes.Length;
                        if (Math.Abs(difference) <= minimum)
                        {
                            minimum = difference;
                        }
                        else
                        {
                            s_width--;
                            s_height = (int)((((center_width * s_width + add_width) * (float)bit.PixelHeight / (float)bit.PixelWidth) - add_height) / center_height);
                            break;
                        }
                        s_width++;
                    }

                    if (s_width == 0)
                    {
                        s_width++;
                    }
                    if (s_height == 0)
                    {
                        s_height++;
                    }
                    // Copy Image
                    String newpath = System.IO.Path.Combine(project_path, "Source Images", filename + System.IO.Path.GetExtension(image_path));
                    if (!(System.IO.File.Exists(System.IO.Path.Combine(project_path, filename + ".sct")) || File.Exists(newpath)))
                    {
                        File.Copy(image_path, newpath, false);
                        File.SetAttributes(newpath, FileAttributes.Normal);
                        doc          = new StructureDocument(System.IO.Path.Combine(project_path, filename + ".sct"), newpath, colors, new ClusterStructureProvider(s_width, s_height, structure_index));
                        DialogResult = true;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("A structure with this name already exists. Please choose another name.");
                    }
                }
                else
                {
                    MessageBox.Show("Please select an image.");
                }
            }
        }
コード例 #4
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);
        }