Esempio n. 1
0
        private async void Paste(Avalonia.Point dominoPoint, PointerReleasedEventArgs e)
        {
            bool pasteFailed = true;

            try
            {
                if (!(CurrentProject is ICopyPasteable))
                {
                    await Errorhandler.RaiseMessage(_("Copy/Paste is not supported in this project."), _("Paste"), Errorhandler.MessageType.Warning);
                }
                // find closest domino
                int domino = FindDominoAtPosition(dominoPoint, int.MaxValue).idx;
                if (PossiblePastePositions.Contains(domino))
                {
                    PasteFilter paste = new PasteFilter(CurrentProject as ICopyPasteable, startindex, toCopy.ToArray(), domino);
                    paste.Apply();
                    undoStack.Push(paste);
                    pasteFailed = false;
                    if (e.KeyModifiers != KeyModifiers.Control)
                    {
                        SelectionTool.Select(paste.paste_target, true);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                await Errorhandler.RaiseMessage(ex.Message, _("Error"), Errorhandler.MessageType.Error);
            }
            finally
            {
                FinalizePaste(e.KeyModifiers != KeyModifiers.Control && !pasteFailed);
            }
        }
Esempio n. 2
0
        public async void AddColumn(bool addRight, int index = -1, IDominoShape colorReference = null)
        {
            var selected = GetSelectedDominoes();

            try
            {
                if (selected.Count > 0 || index != -1)
                {
                    int selDomino = selected.Count > 0 ? selected.First() : index;
                    int color     = (colorReference ?? dominoTransfer[selDomino]).Color;
                    if (CurrentProject is IRowColumnAddableDeletable)
                    {
                        AddColumns addRows = new AddColumns((CurrentProject as IRowColumnAddableDeletable), selDomino, 1, color, addRight);
                        ClearCanvas();
                        ExecuteOperation(addRows);

                        RecreateCanvasViewModel();
                        SelectionTool.Select(addRows.added_indizes, true);
                        UpdateUIElements();
                        DisplaySettingsTool.SliceImage();
                    }
                    else
                    {
                        await Errorhandler.RaiseMessage(_("Adding columns is not supported in this project."), _("Add Row"), Errorhandler.MessageType.Warning);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                await Errorhandler.RaiseMessage(ex.Message, _("Error"), Errorhandler.MessageType.Error);
            }
        }
        private void RemoveSelRows()
        {
            try
            {
                if (CurrentProject is IRowColumnAddableDeletable)
                {
                    if (selectedDominoes.Count > 0)
                    {
                        DeleteRows deleteRows = new DeleteRows((CurrentProject as IRowColumnAddableDeletable), selectedDominoes.ToArray());
                        ClearCanvas();
                        ExecuteOperation(deleteRows);

                        DisplaySettingsTool.ResetCanvas();
                    }
                }
                else
                {
                    Errorhandler.RaiseMessage("Could not remove a row in this project.", "Remove Row", Errorhandler.MessageType.Warning);
                }
            }
            catch (InvalidOperationException ex)
            {
                Errorhandler.RaiseMessage(ex.Message, "Error", Errorhandler.MessageType.Error);
            }
        }
Esempio n. 4
0
        private async void Copy()
        {
            if (!(CurrentProject is ICopyPasteable))
            {
                await Errorhandler.RaiseMessage(_("Copy/Paste is not supported in this project."), "Copy", Errorhandler.MessageType.Warning);
            }
            ClearPastePositions();
            var selected = GetSelectedDominoes();

            if (selected.Count <= 0)
            {
                await Errorhandler.RaiseMessage(_("Nothing to copy!"), _("No selection"), Errorhandler.MessageType.Error);

                return;
            }
            iscopying  = true;
            toCopy     = new List <int>(selected);
            startindex = selected.Min();
            ClearFullSelection(true);
            try
            {
                int[] validPositions = ((ICopyPasteable)this.CurrentProject).GetValidPastePositions(startindex);
                HighlightPastePositions(validPositions);
            }
            catch (InvalidOperationException ex)
            {
                await Errorhandler.RaiseMessage(ex.Message, _("Error"), Errorhandler.MessageType.Error);

                FinalizePaste(true);
            }
            UpdateUIElements();
        }
        private void AddColumn(bool addRight)
        {
            try
            {
                if (selectedDominoes.Count > 0)
                {
                    int selDomino = selectedDominoes.First();
                    if (CurrentProject is IRowColumnAddableDeletable)
                    {
                        AddColumns addRows = new AddColumns((CurrentProject as IRowColumnAddableDeletable), selDomino, 1, dominoTransfer[selDomino].color, addRight);
                        ClearCanvas();
                        ExecuteOperation(addRows);

                        DisplaySettingsTool.ResetCanvas();
                        SelectionTool.Select(addRows.added_indizes, true);
                        UpdateUIElements();
                    }
                    else
                    {
                        Errorhandler.RaiseMessage("Could not add a row in this project.", "Add Row", Errorhandler.MessageType.Warning);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Errorhandler.RaiseMessage(ex.Message, "Error", Errorhandler.MessageType.Error);
            }
        }
 private void Paste()
 {
     try
     {
         if (!(CurrentProject is ICopyPasteable))
         {
             Errorhandler.RaiseMessage("Could not paste in this project.", "Paste", Errorhandler.MessageType.Warning);
         }
         if (selectedDominoes.Count == 0)
         {
             return;
         }
         int pasteindex = selectedDominoes.First();
         RemoveFromSelectedDominoes(pasteindex);
         ClearFullSelection(true);
         PasteFilter paste = new PasteFilter(CurrentProject as ICopyPasteable, startindex, toCopy.ToArray(), pasteindex);
         paste.Apply();
         undoStack.Push(paste);
         DisplaySettingsTool.ClearPastePositions();
         UpdateUIElements();
     }
     catch (InvalidOperationException ex)
     {
         Errorhandler.RaiseMessage(ex.Message, "Error", Errorhandler.MessageType.Error);
     }
 }
 private void Copy()
 {
     if (!(CurrentProject is ICopyPasteable))
     {
         Errorhandler.RaiseMessage("Could not copy in this project.", "Copy", Errorhandler.MessageType.Warning);
     }
     DisplaySettingsTool.ClearPastePositions();
     if (selectedDominoes.Count < 0)
     {
         Errorhandler.RaiseMessage("Nothing to copy!", "No selection", Errorhandler.MessageType.Error);
         return;
     }
     toCopy     = new List <int>(selectedDominoes);
     startindex = selectedDominoes.Min();
     ClearFullSelection(true);
     try
     {
         int[] validPositions = ((ICopyPasteable)this.CurrentProject).GetValidPastePositions(startindex);
         DisplaySettingsTool.HighlightPastePositions(validPositions);
     }
     catch (InvalidOperationException ex)
     {
         Errorhandler.RaiseMessage(ex.Message, "Error", Errorhandler.MessageType.Error);
     }
     UpdateUIElements();
 }
Esempio n. 8
0
        async Task <int[]> AddProjectCounts(AssemblyNode assy)
        {
            int[] sum = new int[assy.Obj.Colors.Length];
            foreach (var child in assy?.Obj.children)
            {
                if (child is AssemblyNode child_as)
                {
                    try
                    {
                        if (Path.GetFullPath(child_as.Obj.AbsoluteColorPath) == Path.GetFullPath(assy.Obj.AbsoluteColorPath))
                        {
                            sum = sum.Zip(await AddProjectCounts(child_as), (x, y) => x + y).ToArray();
                        }
                    }
                    catch
                    {
                        await Errorhandler.RaiseMessage(string.Format(_("Unable to load counts from project {0}"), Path.GetFileNameWithoutExtension(child_as.Path)), _("Error"), Errorhandler.MessageType.Warning);
                    }
                }
                if (child is DocumentNode dn)
                {
                    try
                    {
                        string relpath = dn.RelativePath;
                        var    counts2 = Workspace.LoadColorList <IDominoProviderPreview>(ref relpath, assy.Obj);
                        dn.RelativePath = relpath;
                        if (Path.GetFullPath(counts2.Item1) == Path.GetFullPath(assy.Obj.AbsoluteColorPath))
                        {
                            var currentColors = (counts2.Item2 ?? new int[1]).ToList();
                            while (currentColors.Count < assy.Obj.Colors.Length)
                            {
                                // Edge case: A color has been added, but the count of the project has not been refreshed yet.
                                // This means that we just have to add zeros in the end.
                                // The other direction (more colors in the project than in the color list) should *never* happen, as we save the color list when we save the project.

                                currentColors.Add(0);
                            }
                            sum = sum.Zip(currentColors, (x, y) => x + y).ToArray();
                            for (int i = 0; i < currentColors.Count; i++)
                            {
                                _ColorList[i].ProjectCount.Add(currentColors[i]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //await Errorhandler.RaiseMessage($"Unable to load counts from project {Path.GetFileNameWithoutExtension(dn.RelativePath)}.", "Error", Errorhandler.MessageType.Warning);
                    }
                }
            }
            for (int i = 0; i < sum.Length; i++)
            {
                _ColorList[i].ProjectCount.Add(sum[i]);
            }
            return(sum);
        }
Esempio n. 9
0
        internal override void ResetContent()
        {
            ShowProjects = true;
            //if (DifColumns == null)
            DifColumns = new ObservableCollection <DataGridColumn>();
            //DifColumns.Clear();
            foreach (ColorListEntry cle in _ColorList)
            {
                cle.ProjectCount.Clear();
            }

            List <string> warningfiles = new List <string>();

            if (DominoAssembly != null)
            {
                foreach (DocumentNode project in DominoAssembly?.children.OfType <DocumentNode>())
                {
                    try
                    {
                        var counts2 = Workspace.LoadColorList <IDominoProviderPreview>(project.relativePath, DominoAssembly);
                        if (Path.GetFullPath(counts2.Item1) != Path.GetFullPath(FilePath))
                        {
                            //Errorhandler.RaiseMessage($"The file {Path.GetFileNameWithoutExtension(project.relativePath)} uses a different color table. It is not shown in this view.", "Different colors", Errorhandler.MessageType.Warning);
                            warningfiles.Add(Path.GetFileNameWithoutExtension(project.relativePath));
                            continue;
                        }
                        for (int i = 0; i < counts2.Item2.Length; i++)
                        {
                            _ColorList[i].ProjectCount.Add(counts2.Item2[i]);
                        }
                        for (int i = counts2.Item2.Length; i < _ColorList.Count; i++)
                        {
                            _ColorList[i].ProjectCount.Add(0);
                        }
                        AddProjectCountsColumn(Path.GetFileNameWithoutExtension(project.relativePath));
                    }
                    catch
                    {
                        Errorhandler.RaiseMessage($"Unable to load counts from file {Path.GetFileNameWithoutExtension(project.relativePath)}.", "Error", Errorhandler.MessageType.Warning);
                    }
                }
                for (int i = 0; i < warningfiles.Count; i++)
                {
                    warningfiles[i] = "\"" + warningfiles[i] + "\"";
                }
                if (warningfiles.Count == 1)
                {
                    WarningLabelText = $"The file {warningfiles[0]} uses a different color table and is not shown in this view.";
                }
                else if (warningfiles.Count > 1)
                {
                    WarningLabelText = $"The files {string.Join(", ", warningfiles.ToArray())} use a different color table and are not shown in this view.";
                }
            }
        }
Esempio n. 10
0
        public async void RemoveSelColumns(int index = -1)
        {
            var selected = GetSelectedDominoes();

            try
            {
                if (CurrentProject is IRowColumnAddableDeletable)
                {
                    int[] deletionIndices = null;
                    if (index != -1)
                    {
                        deletionIndices = new int[] { index };
                    }
                    if (selected.Count > 0)
                    {
                        deletionIndices = selected.ToArray();
                    }
                    if (deletionIndices != null)
                    {
                        DeleteColumns deleteColumns = new DeleteColumns((CurrentProject as IRowColumnAddableDeletable), deletionIndices);
                        ClearCanvas();
                        ExecuteOperation(deleteColumns);
                        RecreateCanvasViewModel();
                        DisplaySettingsTool.SliceImage();
                    }
                }
                else
                {
                    await Errorhandler.RaiseMessage(_("Removing columns is not supported in this project."), _("Remove Column"), Errorhandler.MessageType.Warning);
                }
            }
            catch (InvalidOperationException ex)
            {
                await Errorhandler.RaiseMessage(ex.Message, _("Error"), Errorhandler.MessageType.Error);
            }
        }
Esempio n. 11
0
        private void ExportXLSX()
        {
            using (var p = new ExcelPackage())
            {
                // content
                var ws = p.Workbook.Worksheets.Add("Overview");
                ws.Cells["A1"].Value           = "Color Usage Overview";
                ws.Cells["A1"].Style.Font.Size = 15;
                ws.Cells["B3"].Value           = "Color";
                ws.Cells["C3"].Value           = "Available";

                // Write project titles
                for (int i = 0; i < DifColumns.Count; i++)
                {
                    ws.Cells[3, 4 + i].Value = DifColumns[i].Header;

                    ws.Cells[4 + ColorList.Count, 4 + i].Formula
                        = "SUM(" + ws.Cells[4, 4 + i].Address + ":" + ws.Cells[3 + ColorList.Count, 4 + i].Address + ")";
                }
                ws.Cells[4 + ColorList.Count, 3].Formula
                    = "SUM(" + ws.Cells[4, 3].Address + ":" + ws.Cells[3 + ColorList.Count, 3].Address + ")";
                ws.Cells[ColorList.Count + 4, 4 + DifColumns.Count].Formula =
                    "SUM(" + ws.Cells[4, 4 + DifColumns.Count].Address + ":" + ws.Cells[3 + ColorList.Count, 4 + DifColumns.Count].Address + ")";
                if (DifColumns.Count != 0)
                {
                    ws.Cells[3, 4 + DifColumns.Count].Value = "Sum";
                }
                ws.Cells[4 + ColorList.Count, 2].Value = "Sum";
                // fill color counts
                for (int i = 0; i < ColorList.Count; i++)
                {
                    ws.Cells[i + 4, 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                    ws.Cells[i + 4, 1].Style.Fill.BackgroundColor.SetColor(ColorList[i].DominoColor.mediaColor.ToSD());
                    ws.Cells[i + 4, 2].Value = ColorList[i].DominoColor.name;
                    ws.Cells[i + 4, 3].Value = ColorList[i].DominoColor.count;
                    for (int j = 0; j < ColorList[i].ProjectCount.Count; j++)
                    {
                        ws.Cells[4 + i, 4 + j].Value = ColorList[i].ProjectCount[j];
                    }
                    if (DifColumns.Count != 0)
                    {
                        ws.Cells[4 + i, 4 + DifColumns.Count].Formula
                            = "SUM(" + ws.Cells[4 + i, 4].Address + ":"
                              + ws.Cells[4 + i, 3 + DifColumns.Count].Address + ")";
                    }
                }

                ws.Cells["C4"].Value = ""; // Count of empty domino
                ws.Calculate();

                //styling

                ws.Cells[3, 4 + DifColumns.Count, 4 + ColorList.Count, 4 + DifColumns.Count].Style.Font.Bold = true;
                ws.Cells[4 + ColorList.Count, 2, 4 + ColorList.Count, 4 + DifColumns.Count].Style.Font.Bold  = true;

                ws.Cells[3, 1, 3, 4 + DifColumns.Count].Style.Font.Bold           = true;
                ws.Cells[3, 1, 3, 4 + DifColumns.Count].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
                ws.Cells[3, 3, 4 + ColorList.Count, 3].Style.Font.Bold            = true;
                ws.Cells[3, 3, 4 + ColorList.Count, 3].Style.Border.Right.Style   = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
                if (DifColumns.Count != 0)
                {
                    ws.Cells[3, 4, 4 + ColorList.Count, 3 + DifColumns.Count].Style.Border.Right.Style
                        = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                    ws.Cells[4, 2, 3 + ColorList.Count, 4 + DifColumns.Count].Style.Border.Bottom.Style
                        = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                }

                ws.Cells[4 + ColorList.Count, 2, 4 + ColorList.Count, 4 + DifColumns.Count].Style.Border.Top.Style
                    = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
                ws.Cells[3, 4 + DifColumns.Count, 4 + ColorList.Count, 4 + DifColumns.Count].Style.Border.Left.Style
                    = OfficeOpenXml.Style.ExcelBorderStyle.Thick;

                SaveFileDialog dlg = new SaveFileDialog();
                dlg.FileName   = "ColorList";
                dlg.DefaultExt = ".xlsx";
                dlg.Filter     = "Excel files (.xlsx)|*.xlsx|All Files (*.*)|*";
                if (dlg.ShowDialog() == true)
                {
                    try
                    {
                        p.SaveAs(new FileInfo(dlg.FileName));
                        Process.Start(dlg.FileName);
                    }
                    catch
                    {
                        Errorhandler.RaiseMessage("Save failed", "Fail", Errorhandler.MessageType.Error);
                    }
                }
            }
        }
Esempio n. 12
0
        private async void ExportXLSX()
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using var p = new ExcelPackage();
            // content
            var ws = p.Workbook.Worksheets.Add(_("Overview"));

            ws.Cells["A1"].Value           = _("Color Usage Overview");
            ws.Cells["A1"].Style.Font.Size = 15;
            var HeaderRow = ProjectColorList.GetDepth(DominoAssembly);
            //
            var offset = HeaderRow + 4;

            ws.Cells[offset - 1, 2].Value = _("Color");
            ws.Cells[offset - 1, 3].Value = GetParticularString("Total color count available", "Available");
            ColorListWithoutDeleted       = ColorList.Where(x => x.GetColorState() != DominoColorState.Deleted).ToList();
            var TotalColors = ColorListWithoutDeleted.Count;

            for (int i = 0; i < TotalColors; i++)
            {
                ws.Cells[offset + i, 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                ws.Cells[offset + i, 1].Style.Fill.BackgroundColor.SetColor(ColorListWithoutDeleted[i].DominoColor.mediaColor.ToSD());
                ws.Cells[offset + i, 2].Value = ColorListWithoutDeleted[i].DominoColor.name;
                ws.Cells[offset + i, 3].Value = ColorListWithoutDeleted[i].DominoColor.count;
                if (ColorListWithoutDeleted[i].GetColorState() == DominoColorState.Inactive)
                {
                    // mark deleted colors gray
                    ws.Cells[offset + i, 1, offset + i, 3].Style.Font.Color.SetColor(255, 100, 100, 100);
                }
            }
            ws.Cells[offset, 3].Value = ""; // Count of empty domino

            var length = ExportAssemblyToExcel(ws, DominoAssembly, 0, 0, 0, HeaderRow);
            int index  = length.Item1;


            // add lines
            ws.Cells[3, 3, 4 + TotalColors + HeaderRow, 3 + index].Style.Border.Right.Style
                = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
            ws.Cells[2, 1, 3 + TotalColors + HeaderRow, 3 + index].Style.Border.Bottom.Style
                = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
            ws.Cells[3 + HeaderRow, 1, 3 + HeaderRow, 3 + index].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
            ws.Cells[3 + HeaderRow + TotalColors, 1, 3 + HeaderRow + TotalColors, 3 + index].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thick;
            ws.Calculate();
            // auto fit unfortunately doesn't work for merged cells (project headers)
            //ws.Cells.AutoFitColumns();


            SaveFileDialog dlg = new SaveFileDialog
            {
                InitialFileName = GetParticularString("Default filename for color list", "ColorList"),
                Filters         = new List <FileDialogFilter>()
                {
                    new FileDialogFilter()
                    {
                        Extensions = new List <string> {
                            "xlsx"
                        }, Name = _("Excel files")
                    },
                    new FileDialogFilter()
                    {
                        Extensions = new List <string> {
                            "*"
                        }, Name = _("All files")
                    }
                },
                Directory = DialogExtensions.GetCurrentProjectPath()
            };
            var result = await dlg.ShowAsyncWithParent <MainWindow>();

            if (!string.IsNullOrEmpty(result))
            {
                try
                {
                    p.SaveAs(new FileInfo(result));
                    var process = new Process();
                    process.StartInfo = new ProcessStartInfo(result)
                    {
                        UseShellExecute = true
                    };
                    process.Start();
                }
                catch (Exception ex)
                {
                    await Errorhandler.RaiseMessage(string.Format(_("Save failed: {0}"), ex.Message), _("Error"), Errorhandler.MessageType.Error);
                }
            }
        }