2014-10-30 14:42:00 -07:00
|
|
|
|
/*
|
2017-06-10 18:40:57 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker
|
2014-10-30 14:42:00 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-10-30 14:42:00 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-10-30 14:42:00 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-10-30 14:42:00 -07:00
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-10-30 14:42:00 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-07-06 12:22:56 -07:00
|
|
|
|
using System;
|
2017-08-15 12:32:09 -07:00
|
|
|
|
using System.Linq;
|
2014-10-30 14:42:00 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2017-09-05 15:44:22 -07:00
|
|
|
|
using MatterHackers.MatterControl.AboutPage;
|
2017-11-17 17:46:58 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2017-11-28 14:37:38 -08:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow.PlusTab;
|
2017-09-29 23:54:40 -07:00
|
|
|
|
using MatterHackers.MatterControl.SettingsManagement;
|
2014-10-30 14:42:00 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2014-10-30 14:42:00 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2017-05-24 19:11:51 -07:00
|
|
|
|
public class PartPreviewContent : FlowLayoutWidget
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-07-27 14:25:21 -07:00
|
|
|
|
private EventHandler unregisterEvents;
|
2017-09-15 15:19:38 -07:00
|
|
|
|
private MainTab printerTab = null;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
private ChromeTabs tabControl;
|
2017-09-29 21:30:51 -07:00
|
|
|
|
|
2017-09-15 18:45:21 -07:00
|
|
|
|
public PartPreviewContent()
|
2017-11-11 17:28:03 -08:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-09-17 14:23:28 -07:00
|
|
|
|
var printer = ApplicationController.Instance.ActivePrinter;
|
2017-08-16 22:45:46 -07:00
|
|
|
|
var theme = ApplicationController.Instance.Theme;
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.AnchorAll();
|
2017-03-15 16:17:06 -07:00
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
var extensionArea = new FlowLayoutWidget();
|
2017-08-15 12:32:09 -07:00
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
tabControl = new ChromeTabs(extensionArea, theme)
|
2017-11-07 14:58:43 -08:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor,
|
|
|
|
|
|
NewTabPage = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return new PlusTabPage(this, tabControl, theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tabControl.ActiveTabChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage)
|
2017-11-07 14:58:43 -08:00
|
|
|
|
{
|
|
|
|
|
|
var dragDropData = ApplicationController.Instance.DragDropData;
|
|
|
|
|
|
|
|
|
|
|
|
// Set reference on tab change
|
|
|
|
|
|
dragDropData.View3DWidget = tabPage.view3DWidget;
|
|
|
|
|
|
dragDropData.SceneContext = tabPage.sceneContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
tabControl.TabBar.BorderColor = theme.ActiveTabColor;
|
2017-11-11 17:28:03 -08:00
|
|
|
|
tabControl.TabBar.Padding = new BorderDouble(top: 4);
|
2017-11-17 16:07:06 -08:00
|
|
|
|
tabControl.TabBar.Border = new BorderDouble(bottom: 2);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
Color selectedTabColor = ActiveTheme.Instance.TabLabelSelected;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-05-24 19:11:51 -07:00
|
|
|
|
// Add a tab for the current printer
|
2017-09-15 09:23:53 -07:00
|
|
|
|
if (ActiveSliceSettings.Instance.PrinterSelected)
|
|
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
string tabTitle = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
|
2017-09-17 14:23:28 -07:00
|
|
|
|
printerTab = CreatePrinterTab(printer, theme, tabTitle);
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
2017-09-15 09:23:53 -07:00
|
|
|
|
tabControl.AddTab(printerTab);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-11-29 08:52:29 -08:00
|
|
|
|
BedConfig bed;
|
2017-11-16 07:15:18 -08:00
|
|
|
|
this.CreatePartTab(
|
2017-11-21 11:11:07 -08:00
|
|
|
|
"New Part",
|
2017-11-29 08:52:29 -08:00
|
|
|
|
bed = new BedConfig(),
|
2017-11-21 11:11:07 -08:00
|
|
|
|
theme);
|
2017-11-29 08:52:29 -08:00
|
|
|
|
|
|
|
|
|
|
bed.LoadContent(
|
|
|
|
|
|
new EditContext()
|
|
|
|
|
|
{
|
|
|
|
|
|
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
|
|
|
|
|
|
SourceItem = BedConfig.NewPlatingItem()
|
|
|
|
|
|
}).ConfigureAwait(false);
|
2017-09-15 09:23:53 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-09-05 15:44:22 -07:00
|
|
|
|
// add in the update available button
|
2017-11-11 17:28:03 -08:00
|
|
|
|
Button updateAvailableButton = theme.LinkButtonFactory.Generate("Update Available");
|
2017-09-05 15:44:22 -07:00
|
|
|
|
updateAvailableButton.Name = "Update Available Link";
|
|
|
|
|
|
updateAvailableButton.Visible = UpdateControlData.Instance.UpdateStatus == UpdateControlData.UpdateStatusStates.UpdateAvailable;
|
|
|
|
|
|
updateAvailableButton.ToolTipText = "There is a new update available for download".Localize();
|
|
|
|
|
|
updateAvailableButton.VAnchor = VAnchor.Center;
|
|
|
|
|
|
updateAvailableButton.Margin = new Agg.BorderDouble(10, 0);
|
|
|
|
|
|
updateAvailableButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateControlData.Instance.CheckForUpdateUserRequested();
|
2017-11-08 15:56:37 -08:00
|
|
|
|
DialogWindow.Show<CheckForUpdatesPage>();
|
2017-09-05 15:44:22 -07:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
2017-11-17 17:46:58 -08:00
|
|
|
|
tabControl.TabBar.ActionBar.AddChild(updateAvailableButton);
|
2017-09-05 15:44:22 -07:00
|
|
|
|
|
|
|
|
|
|
UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
updateAvailableButton.Visible = UpdateControlData.Instance.UpdateStatus == UpdateControlData.UpdateStatusStates.UpdateAvailable;
|
|
|
|
|
|
}, ref unregisterEvents);
|
|
|
|
|
|
|
|
|
|
|
|
// this causes the update button to be centered
|
2017-11-11 17:28:03 -08:00
|
|
|
|
//tabControl.TabBar.AddChild(new HorizontalSpacer());
|
2017-08-07 14:19:28 -07:00
|
|
|
|
|
2017-08-12 00:40:40 -07:00
|
|
|
|
//rightPanelArea.AddChild(
|
|
|
|
|
|
// new ImageWidget(
|
2017-08-20 02:34:39 -07:00
|
|
|
|
// AggContext.StaticData.LoadImage(Path.Combine("Images", "minimize.png")))
|
2017-08-12 00:40:40 -07:00
|
|
|
|
// {
|
|
|
|
|
|
// VAnchor = VAnchor.Top,
|
|
|
|
|
|
// DebugShowBounds = true
|
|
|
|
|
|
// });
|
2017-07-27 14:25:21 -07:00
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
//this.AddChild(tabControl);
|
2017-08-07 14:19:28 -07:00
|
|
|
|
|
|
|
|
|
|
this.AddChild(tabControl);
|
2017-09-15 09:23:53 -07:00
|
|
|
|
|
2017-07-27 14:25:21 -07:00
|
|
|
|
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
|
|
|
|
|
|
{
|
2017-09-15 09:23:53 -07:00
|
|
|
|
if (e is StringEventArgs stringEvent
|
|
|
|
|
|
&& stringEvent.Data == SettingsKey.printer_name
|
|
|
|
|
|
&& printerTab != null)
|
2017-07-27 14:25:21 -07:00
|
|
|
|
{
|
2017-11-11 17:28:03 -08:00
|
|
|
|
printerTab.Text = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
|
2017-07-27 14:25:21 -07:00
|
|
|
|
}
|
2017-09-15 09:23:53 -07:00
|
|
|
|
|
2017-07-27 14:25:21 -07:00
|
|
|
|
}, ref unregisterEvents);
|
|
|
|
|
|
|
2017-08-07 14:19:28 -07:00
|
|
|
|
ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);
|
|
|
|
|
|
|
|
|
|
|
|
// When the application is first started, plugins are loaded after the MainView control has been initialized,
|
|
|
|
|
|
// and as such they not around when this constructor executes. In that case, we run the AddRightElement
|
|
|
|
|
|
// delegate after the plugins have been initialized via the PluginsLoaded event
|
|
|
|
|
|
ApplicationController.Instance.PluginsLoaded.RegisterEvent((s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);
|
|
|
|
|
|
}, ref unregisterEvents);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
private MainTab CreatePrinterTab(PrinterConfig printer, ThemeConfig theme, string tabTitle)
|
2017-09-15 09:23:53 -07:00
|
|
|
|
{
|
2017-09-29 23:54:40 -07:00
|
|
|
|
string oemName = printer.Settings.GetValue(SettingsKey.make);
|
|
|
|
|
|
|
|
|
|
|
|
OemSettings.Instance.OemUrls.TryGetValue(oemName, out string oemUrl);
|
|
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
return new MainTab(
|
2017-09-15 09:23:53 -07:00
|
|
|
|
tabTitle,
|
2017-11-11 17:28:03 -08:00
|
|
|
|
tabControl,
|
2017-09-29 23:54:40 -07:00
|
|
|
|
new PrinterTabPage(printer, theme, tabTitle.ToUpper()),
|
2017-11-21 11:11:07 -08:00
|
|
|
|
theme,
|
2017-11-11 17:28:03 -08:00
|
|
|
|
"https://www.google.com/s2/favicons?domain=" + oemUrl ?? "www.matterhackers.com")
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "3D View Tab",
|
|
|
|
|
|
MinimumSize = new Vector2(120, theme.shortButtonHeight)
|
|
|
|
|
|
};
|
2017-09-15 09:23:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-01 12:17:01 -08:00
|
|
|
|
public MainTab CreatePartTab(string tabTitle, BedConfig sceneContext, ThemeConfig theme)
|
2017-09-29 21:30:51 -07:00
|
|
|
|
{
|
|
|
|
|
|
var partTab = new MainTab(
|
|
|
|
|
|
tabTitle,
|
2017-11-11 17:28:03 -08:00
|
|
|
|
tabControl,
|
2017-11-07 14:55:45 -08:00
|
|
|
|
new PartTabPage(null, sceneContext, theme, "xxxxx"),
|
2017-11-21 11:11:07 -08:00
|
|
|
|
theme,
|
2017-11-11 17:28:03 -08:00
|
|
|
|
"https://i.imgur.com/nkeYgfU.png")
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "newPart" + tabControl.AllTabs.Count(),
|
|
|
|
|
|
MinimumSize = new Vector2(120, theme.shortButtonHeight)
|
|
|
|
|
|
};
|
2017-09-29 21:30:51 -07:00
|
|
|
|
|
2017-11-11 17:28:03 -08:00
|
|
|
|
tabControl.AddTab(partTab);
|
2017-09-29 21:30:51 -07:00
|
|
|
|
|
|
|
|
|
|
return partTab;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-07 14:19:28 -07:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
|
|
|
|
|
base.OnClosed(e);
|
2017-05-24 19:11:51 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|