2017-09-15 15:17:56 -07:00
|
|
|
|
/*
|
2018-05-22 22:06:20 -07:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2017-09-15 15:17:56 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-10-07 11:36:52 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2018-10-25 17:38:58 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2021-05-14 07:55:08 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-10-07 11:36:52 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MatterControl.Library;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2022-02-02 17:31:44 -08:00
|
|
|
|
public class DesignTabPage : TabPage
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2018-05-22 22:06:20 -07:00
|
|
|
|
// TODO: Don't change casing... almost certainly none of these should be exposed
|
2017-10-06 12:23:32 -07:00
|
|
|
|
internal View3DWidget view3DWidget;
|
2019-02-01 16:12:12 -08:00
|
|
|
|
internal ISceneContext sceneContext;
|
2021-09-13 21:47:46 -07:00
|
|
|
|
protected ViewToolBarControls viewToolBarControls;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
protected ThemeConfig theme;
|
|
|
|
|
|
protected GuiWidget view3DContainer;
|
|
|
|
|
|
protected FlowLayoutWidget topToBottom;
|
|
|
|
|
|
protected FlowLayoutWidget leftToRight;
|
2018-10-25 13:22:03 -07:00
|
|
|
|
protected LibraryListView favoritesBar;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
|
2020-12-30 10:35:47 -08:00
|
|
|
|
public PrinterConfig Printer => Workspace.Printer;
|
|
|
|
|
|
|
2022-02-02 17:31:44 -08:00
|
|
|
|
public DesignTabPage(PartWorkspace workspace, ThemeConfig theme, string tabTitle)
|
2019-04-24 11:40:25 -07:00
|
|
|
|
: base(tabTitle)
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2018-12-12 17:12:06 -08:00
|
|
|
|
this.sceneContext = workspace.SceneContext;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
this.theme = theme;
|
2018-11-03 09:50:09 -07:00
|
|
|
|
this.BackgroundColor = theme.BackgroundColor;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
this.Padding = 0;
|
2019-04-24 11:41:41 -07:00
|
|
|
|
this.Workspace = workspace;
|
2017-09-15 15:17:56 -07:00
|
|
|
|
|
2018-01-08 23:34:40 -08:00
|
|
|
|
bool isPrinterType = this is PrinterTabPage;
|
2018-02-16 18:47:28 -08:00
|
|
|
|
|
2018-10-14 17:50:54 -07:00
|
|
|
|
var favoritesBarAndView3DWidget = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-09-13 21:47:46 -07:00
|
|
|
|
viewToolBarControls = new ViewToolBarControls(workspace, theme, sceneContext.Scene.UndoBuffer, isPrinterType, !(this is PrinterTabPage))
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2017-10-31 13:50:20 -07:00
|
|
|
|
VAnchor = VAnchor.Top | VAnchor.Fit,
|
|
|
|
|
|
HAnchor = HAnchor.Left | HAnchor.Stretch,
|
2017-09-15 15:17:56 -07:00
|
|
|
|
Visible = true,
|
|
|
|
|
|
};
|
2020-09-22 17:52:57 -07:00
|
|
|
|
|
|
|
|
|
|
// Shade border if toolbar is secondary rather than primary
|
2021-09-13 21:47:46 -07:00
|
|
|
|
theme.ApplyBottomBorder(viewToolBarControls, shadedBorder: this is PrinterTabPage);
|
2018-07-15 10:07:30 -07:00
|
|
|
|
|
2021-09-13 21:47:46 -07:00
|
|
|
|
viewToolBarControls.ResetView += (sender, e) =>
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2017-10-06 12:23:32 -07:00
|
|
|
|
if (view3DWidget.Visible)
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2017-10-06 12:23:32 -07:00
|
|
|
|
this.view3DWidget.ResetView();
|
2017-09-15 15:17:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2017-11-11 17:28:03 -08:00
|
|
|
|
|
2017-09-15 15:17:56 -07:00
|
|
|
|
// The 3D model view
|
2017-10-06 12:23:32 -07:00
|
|
|
|
view3DWidget = new View3DWidget(
|
2020-12-30 10:35:47 -08:00
|
|
|
|
Printer,
|
2017-09-15 16:49:21 -07:00
|
|
|
|
sceneContext,
|
2021-09-13 21:47:46 -07:00
|
|
|
|
viewToolBarControls,
|
2017-09-15 15:17:56 -07:00
|
|
|
|
theme,
|
2017-10-16 17:09:00 -07:00
|
|
|
|
this,
|
2020-09-22 17:52:57 -07:00
|
|
|
|
editorType: isPrinterType ? Object3DControlsLayer.EditorType.Printer : Object3DControlsLayer.EditorType.Part);
|
2017-09-15 15:17:56 -07:00
|
|
|
|
|
2021-09-16 16:31:14 -07:00
|
|
|
|
// add in the task display
|
|
|
|
|
|
view3DWidget.AddChild(new RunningTasksWidget(theme, Printer)
|
|
|
|
|
|
{
|
|
|
|
|
|
MinimumSize = new Vector2(100, 0),
|
|
|
|
|
|
Margin = new BorderDouble(9, 0, 0, 9),
|
|
|
|
|
|
VAnchor = VAnchor.Top | VAnchor.Fit,
|
|
|
|
|
|
HAnchor = HAnchor.Left | HAnchor.Fit,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-09-13 21:47:46 -07:00
|
|
|
|
viewToolBarControls.SetView3DWidget(view3DWidget);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2017-11-09 00:02:21 -08:00
|
|
|
|
this.AddChild(topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
});
|
2017-10-31 13:50:20 -07:00
|
|
|
|
|
2017-11-09 00:02:21 -08:00
|
|
|
|
topToBottom.AddChild(leftToRight = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "View3DContainerParent",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
});
|
2017-09-15 15:17:56 -07:00
|
|
|
|
|
2017-11-09 00:02:21 -08:00
|
|
|
|
view3DContainer = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
2017-09-15 15:17:56 -07:00
|
|
|
|
|
2017-11-09 00:02:21 -08:00
|
|
|
|
var toolbarAndView3DWidget = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
2021-09-13 21:47:46 -07:00
|
|
|
|
toolbarAndView3DWidget.AddChild(viewToolBarControls);
|
2018-10-07 11:36:52 -07:00
|
|
|
|
|
2018-10-25 13:22:03 -07:00
|
|
|
|
var favoritesBarContext = new LibraryConfig()
|
2018-10-07 11:36:52 -07:00
|
|
|
|
{
|
2018-10-25 13:22:03 -07:00
|
|
|
|
ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
|
2018-10-07 11:36:52 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-10-26 12:09:07 -07:00
|
|
|
|
var leftBar = new GuiWidget()
|
2018-10-25 17:38:58 -07:00
|
|
|
|
{
|
2018-10-26 12:09:07 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
2018-11-02 19:50:14 -07:00
|
|
|
|
HAnchor = HAnchor.Fit,
|
|
|
|
|
|
Border = new BorderDouble(top: 1, right: 1),
|
|
|
|
|
|
BorderColor = theme.BorderColor20,
|
2018-10-25 17:38:58 -07:00
|
|
|
|
};
|
|
|
|
|
|
favoritesBarAndView3DWidget.AddChild(leftBar);
|
|
|
|
|
|
|
|
|
|
|
|
bool expanded = UserSettings.Instance.get(UserSettingsKey.FavoritesBarExpansion) != "0";
|
|
|
|
|
|
|
2018-10-25 13:22:03 -07:00
|
|
|
|
favoritesBar = new LibraryListView(favoritesBarContext, theme)
|
2018-10-07 11:36:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
Name = "LibraryView",
|
|
|
|
|
|
// Drop containers
|
|
|
|
|
|
ContainerFilter = (container) => false,
|
2020-08-04 14:56:27 -07:00
|
|
|
|
// HAnchor = HAnchor.Fit,
|
2018-10-07 11:36:52 -07:00
|
|
|
|
HAnchor = HAnchor.Absolute,
|
2018-10-26 12:09:07 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch,
|
2018-10-25 17:38:58 -07:00
|
|
|
|
AllowContextMenu = false,
|
2020-09-22 17:52:57 -07:00
|
|
|
|
ActiveSort = SortKey.ModifiedDate,
|
|
|
|
|
|
Ascending = true,
|
2018-10-25 17:38:58 -07:00
|
|
|
|
// restore to state for favorites bar size
|
2020-08-04 08:15:20 -07:00
|
|
|
|
Width = expanded ? 55 * GuiWidget.DeviceScale : 33 * GuiWidget.DeviceScale,
|
|
|
|
|
|
ListContentView = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale)
|
2018-11-02 19:52:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Fit | VAnchor.Top
|
|
|
|
|
|
},
|
2018-10-25 17:38:58 -07:00
|
|
|
|
};
|
2020-09-22 17:52:57 -07:00
|
|
|
|
|
2020-08-04 14:56:27 -07:00
|
|
|
|
// favoritesBar.ScrollArea.HAnchor = HAnchor.Fit;
|
|
|
|
|
|
favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
|
2018-10-25 17:38:58 -07:00
|
|
|
|
leftBar.AddChild(favoritesBar);
|
|
|
|
|
|
|
2020-08-04 14:56:27 -07:00
|
|
|
|
void UpdateWidth(object s, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (s is GuiWidget widget)
|
|
|
|
|
|
{
|
|
|
|
|
|
favoritesBar.Width = widget.Width;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
favoritesBar.ListContentView.BoundsChanged += UpdateWidth;
|
|
|
|
|
|
|
2018-11-02 19:52:44 -07:00
|
|
|
|
favoritesBar.ScrollArea.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
|
2021-05-14 07:55:08 -07:00
|
|
|
|
favoritesBar.VerticalScrollBar.Show = ScrollBar.ShowState.Never;
|
|
|
|
|
|
|
2021-05-21 15:23:25 -07:00
|
|
|
|
var expandedImage = StaticData.Instance.LoadIcon("expand.png", 16, 16).SetToColor(theme.TextColor);
|
|
|
|
|
|
var collapsedImage = StaticData.Instance.LoadIcon("collapse.png", 16, 16).SetToColor(theme.TextColor);
|
2018-10-25 17:38:58 -07:00
|
|
|
|
|
2022-07-16 07:46:44 -07:00
|
|
|
|
var expandBarButton = new ThemedIconButton(expanded ? collapsedImage : expandedImage, theme)
|
2018-10-25 17:38:58 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Center,
|
2018-10-26 12:09:07 -07:00
|
|
|
|
VAnchor = VAnchor.Absolute | VAnchor.Bottom,
|
|
|
|
|
|
Margin = new BorderDouble(bottom: 3, top: 3),
|
2020-08-04 08:15:20 -07:00
|
|
|
|
Height = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
|
2021-05-14 07:55:08 -07:00
|
|
|
|
Width = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
|
|
|
|
|
|
ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize(),
|
2018-10-07 11:36:52 -07:00
|
|
|
|
};
|
2018-10-26 12:09:07 -07:00
|
|
|
|
|
2020-08-04 14:56:27 -07:00
|
|
|
|
expandBarButton.Click += (s, e) => UiThread.RunOnIdle(async () =>
|
2018-10-25 17:38:58 -07:00
|
|
|
|
{
|
|
|
|
|
|
expanded = !expanded;
|
|
|
|
|
|
|
2020-08-04 14:56:27 -07:00
|
|
|
|
// remove from the one we are deleting
|
|
|
|
|
|
favoritesBar.ListContentView.BoundsChanged -= UpdateWidth;
|
2018-10-25 17:38:58 -07:00
|
|
|
|
UserSettings.Instance.set(UserSettingsKey.FavoritesBarExpansion, expanded ? "1" : "0");
|
2020-08-04 08:15:20 -07:00
|
|
|
|
favoritesBar.ListContentView = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale);
|
2020-08-04 14:56:27 -07:00
|
|
|
|
favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
|
|
|
|
|
|
// add to the one we created
|
|
|
|
|
|
favoritesBar.ListContentView.BoundsChanged += UpdateWidth;
|
2018-10-25 17:38:58 -07:00
|
|
|
|
expandBarButton.SetIcon(expanded ? collapsedImage : expandedImage);
|
|
|
|
|
|
expandBarButton.Invalidate();
|
2021-05-14 07:55:08 -07:00
|
|
|
|
expandBarButton.ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize();
|
2018-10-25 17:38:58 -07:00
|
|
|
|
|
2020-08-04 14:56:27 -07:00
|
|
|
|
await favoritesBar.Reload();
|
|
|
|
|
|
UpdateWidth(favoritesBar.ListContentView, null);
|
2018-10-25 17:38:58 -07:00
|
|
|
|
});
|
|
|
|
|
|
leftBar.AddChild(expandBarButton);
|
2018-10-26 12:09:07 -07:00
|
|
|
|
|
|
|
|
|
|
favoritesBar.Margin = new BorderDouble(bottom: expandBarButton.Height + expandBarButton.Margin.Height);
|
2018-11-02 19:52:44 -07:00
|
|
|
|
|
2018-10-07 11:36:52 -07:00
|
|
|
|
favoritesBarAndView3DWidget.AddChild(view3DWidget);
|
|
|
|
|
|
toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);
|
|
|
|
|
|
|
2017-11-09 00:02:21 -08:00
|
|
|
|
view3DContainer.AddChild(toolbarAndView3DWidget);
|
2017-10-21 12:05:44 -07:00
|
|
|
|
|
2017-09-15 15:17:56 -07:00
|
|
|
|
leftToRight.AddChild(view3DContainer);
|
|
|
|
|
|
|
2017-09-16 01:28:05 -07:00
|
|
|
|
if (sceneContext.World.RotationMatrix == Matrix4X4.Identity)
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2017-10-06 12:23:32 -07:00
|
|
|
|
this.view3DWidget.ResetView();
|
2017-09-15 15:17:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.AnchorAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 11:41:41 -07:00
|
|
|
|
public PartWorkspace Workspace { get; }
|
|
|
|
|
|
|
2018-02-06 15:43:23 -08:00
|
|
|
|
public override void OnFocusChanged(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnFocusChanged(e);
|
|
|
|
|
|
view3DWidget.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-21 21:07:14 -08:00
|
|
|
|
protected virtual void GetViewControls3DOverflowMenu(PopupMenu popupMenu)
|
2017-09-15 15:17:56 -07:00
|
|
|
|
{
|
2018-01-21 21:07:14 -08:00
|
|
|
|
view3DWidget.ShowOverflowMenu(popupMenu);
|
2017-09-15 15:17:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|