예제 #1
0
        public PartsBar(PartPreviewContent partPreviewContent, ThemeConfig theme)
            : base("Parts".Localize(), theme)
        {
            var emptyPlateButton = new ImageWidget(AggContext.StaticData.LoadIcon("new-part.png", 70, 70))
            {
                Margin          = new BorderDouble(right: 5),
                Selectable      = true,
                BackgroundColor = theme.MinimalShade,
                Cursor          = Cursors.Hand,
                Name            = "Create Part Button"
            };

            emptyPlateButton.Click += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    UiThread.RunOnIdle(async() =>
                    {
                        var workspace = new BedConfig();
                        await workspace.LoadContent(
                            new EditContext()
                        {
                            ContentStore = ApplicationController.Instance.Library.PartHistory,
                            SourceItem   = BedConfig.NewPlatingItem(ApplicationController.Instance.Library.PartHistory)
                        });

                        ApplicationController.Instance.Workspaces.Add(workspace);

                        partPreviewContent.CreatePartTab("New Part", workspace, theme);
                    });
                }
            };
            toolbar.AddChild(emptyPlateButton);

            var recentParts = new DirectoryInfo(ApplicationDataStorage.Instance.PartHistoryDirectory).GetFiles("*.mcx").OrderByDescending(f => f.LastWriteTime);

            foreach (var item in recentParts.Where(f => f.Length > 500).Select(f => new SceneReplacementFileItem(f.FullName)).Take(10).ToList <ILibraryItem>())
            {
                var iconButton = new IconViewItem(new ListViewItem(item, ApplicationController.Instance.Library.PlatingHistory), 70, 70, theme)
                {
                    Margin     = new BorderDouble(right: 5),
                    Selectable = true,
                };

                iconButton.Click += async(s, e) =>
                {
                    // Activate selected item tab
                    if (partPreviewContent.TabControl.AllTabs.FirstOrDefault(t => t.Text == item.Name) is ChromeTab existingItemTab)
                    {
                        partPreviewContent.TabControl.ActiveTab = existingItemTab;
                    }
                    else
                    {
                        // Create tab for selected item
                        if (this.PositionWithinLocalBounds(e.X, e.Y) &&
                            e.Button == MouseButtons.Left)
                        {
                            var workspace = new BedConfig();
                            await workspace.LoadContent(
                                new EditContext()
                            {
                                ContentStore = ApplicationController.Instance.Library.PartHistory,
                                SourceItem   = item
                            });

                            ApplicationController.Instance.Workspaces.Add(workspace);

                            partPreviewContent.CreatePartTab(item.Name, workspace, theme);
                        }
                    }
                };

                toolbar.AddChild(iconButton);
            }
        }
예제 #2
0
        private void RebuildPlateOptions(PartPreviewContent partPreviewContent, ThemeConfig theme)
        {
            toolbar.ActionArea.CloseAllChildren();

            var lastProfileID = ProfileManager.Instance.LastProfileID;
            var lastProfile   = ProfileManager.Instance[lastProfileID];

            if (lastProfile == null)
            {
                if (ProfileManager.Instance.Profiles.Count > 0)
                {
                    toolbar.AddChild(new TextWidget("Select a printer to continue".Localize() + "...", textColor: theme.Colors.PrimaryTextColor, pointSize: theme.DefaultFontSize)
                    {
                        Margin = 15
                    });
                }
                else
                {
                    toolbar.AddChild(new TextWidget("Create a printer to continue".Localize() + "...", textColor: theme.Colors.PrimaryTextColor, pointSize: theme.DefaultFontSize)
                    {
                        Margin = 15
                    });
                }
            }
            else
            {
                var emptyPlateButton = new ImageWidget(AggContext.StaticData.LoadIcon("empty-workspace.png", 70, 70))
                {
                    Margin          = new BorderDouble(right: 5),
                    Selectable      = true,
                    BackgroundColor = theme.MinimalShade,
                    Name            = "Open Empty Plate Button",
                    Cursor          = Cursors.Hand
                };
                emptyPlateButton.Click += (s, e) =>
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        UiThread.RunOnIdle(async() =>
                        {
                            var printer = await ProfileManager.Instance.LoadPrinter();
                            printer.ViewState.ViewMode = PartViewMode.Model;

                            // Load empty plate
                            await printer.Bed.LoadContent(
                                new EditContext()
                            {
                                ContentStore = ApplicationController.Instance.Library.PlatingHistory,
                                SourceItem   = BedConfig.NewPlatingItem(ApplicationController.Instance.Library.PlatingHistory)
                            });

                            // Always switch to printer tab after changing plate
                            partPreviewContent.TabControl.SelectedTabIndex = 1;
                        });
                    }
                };

                toolbar.AddChild(emptyPlateButton);

                // Select the 25 most recent files and project onto FileSystemItems
                var recentFiles = new DirectoryInfo(ApplicationDataStorage.Instance.PlatingDirectory).GetFiles("*.mcx").OrderByDescending(f => f.LastWriteTime);
                foreach (var item in recentFiles.Where(f => f.Length > 500).Select(f => new SceneReplacementFileItem(f.FullName)).Take(10).ToList <ILibraryItem>())
                {
                    var iconButton = new IconViewItem(new ListViewItem(item, ApplicationController.Instance.Library.PlatingHistory), 70, 70, theme)
                    {
                        Margin     = new BorderDouble(right: 5),
                        Selectable = true,
                        Cursor     = Cursors.Hand
                    };

                    iconButton.Click += (s, e) =>
                    {
                        if (this.PositionWithinLocalBounds(e.X, e.Y) &&
                            e.Button == MouseButtons.Left)
                        {
                            UiThread.RunOnIdle(async() =>
                            {
                                await ProfileManager.Instance.LoadPrinterOpenItem(item);

                                var printer = ApplicationController.Instance.ActivePrinter;
                                printer.ViewState.ViewMode = PartViewMode.Model;

                                // Always switch to printer tab after changing plate
                                partPreviewContent.TabControl.SelectedTabIndex = 1;
                            });
                        }
                    };

                    toolbar.AddChild(iconButton);
                }
            }
        }