mattercontrol/MatterControlLib/PartPreviewWindow/ViewControls3D.cs

779 lines
23 KiB
C#
Raw Normal View History

2015-08-15 16:38:07 -07:00
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
2015-08-15 16:38:07 -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.
*/
2015-04-08 15:20:10 -07:00
using System;
using System.Collections.Generic;
2017-07-07 12:25:31 -07:00
using System.Collections.ObjectModel;
2015-04-08 15:20:10 -07:00
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
2017-08-14 12:34:44 -07:00
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrintLibrary;
2018-10-17 17:38:20 -07:00
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MeshVisualizer;
2017-08-14 12:34:44 -07:00
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public enum ViewControls3DButtons
{
Rotate,
Scale,
Translate,
PartSelect
}
2017-10-19 09:01:07 -07:00
public enum PartViewMode
{
Layers2D,
Layers3D,
Model
}
public class ViewModeChangedEventArgs : EventArgs
{
public PartViewMode ViewMode { get; set; }
}
public class TransformStateChangedEventArgs : EventArgs
{
public ViewControls3DButtons TransformMode { get; set; }
}
public class ViewControls3D : OverflowBar
2015-04-08 15:20:10 -07:00
{
public event EventHandler ResetView;
2017-10-19 09:01:07 -07:00
public event EventHandler<TransformStateChangedEventArgs> TransformStateChanged;
private RadioIconButton translateButton;
private RadioIconButton rotateButton;
private RadioIconButton scaleButton;
private RadioIconButton partSelectButton;
private View3DWidget view3DWidget;
private BedConfig sceneContext;
private ViewControls3DButtons activeTransformState = ViewControls3DButtons.PartSelect;
private List<(GuiWidget button, SceneSelectionOperation operation)> operationButtons;
private PartPreviewContent partPreviewContent = null;
private PopupMenuButton bedMenuButton;
private ThemeConfig theme;
2018-08-08 07:08:08 -07:00
internal void NotifyResetView()
{
this.ResetView.Invoke(this, null);
}
public bool IsPrinterMode { get; }
public ViewControls3DButtons ActiveButton
{
get
{
return activeTransformState;
}
set
{
this.activeTransformState = value;
switch (this.activeTransformState)
{
case ViewControls3DButtons.Rotate:
2017-07-05 13:55:38 -07:00
if (rotateButton != null)
{
rotateButton.Checked = true;
}
break;
case ViewControls3DButtons.Translate:
2017-07-05 13:55:38 -07:00
if (translateButton != null)
{
translateButton.Checked = true;
}
break;
case ViewControls3DButtons.Scale:
2017-07-05 13:55:38 -07:00
if (scaleButton != null)
{
scaleButton.Checked = true;
}
break;
case ViewControls3DButtons.PartSelect:
if (partSelectButton != null)
{
partSelectButton.Checked = true;
}
break;
}
TransformStateChanged?.Invoke(this, new TransformStateChangedEventArgs()
{
TransformMode = activeTransformState
});
}
}
internal void SetView3DWidget(View3DWidget view3DWidget)
{
this.view3DWidget = view3DWidget;
var workspaceActions = view3DWidget.WorkspaceActions;
bedMenuButton.DynamicPopupContent = () =>
{
var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);
var actions = new NamedAction[] {
new ActionSeparator(),
workspaceActions["Cut"],
workspaceActions["Copy"],
workspaceActions["Paste"],
new ActionSeparator(),
new NamedAction()
{
ID = "Export",
Title = "Export".Localize(),
Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16),
Action = () =>
{
UiThread.RunOnIdle(async () =>
{
DialogWindow.Show(
new ExportPrintItemPage(new[]
{
new InMemoryLibraryItem(sceneContext.Scene)
}, false));
});
},
IsEnabled = () => sceneContext.EditableScene
|| (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset
&& string.Equals(Path.GetExtension(libraryAsset.FileName) ,".gcode" ,StringComparison.OrdinalIgnoreCase))
},
new NamedAction()
{
ID = "ArrangeAll",
Title = "Arrange All Parts".Localize(),
Action = () =>
{
sceneContext.Scene.AutoArrangeChildren(view3DWidget);
},
IsEnabled = () => sceneContext.EditableScene
},
new ActionSeparator(),
new NamedAction()
{
ID = "ClearBed",
Title = "Clear Bed".Localize(),
Action = () =>
{
UiThread.RunOnIdle(() =>
{
view3DWidget.ClearPlate();
});
}
}
};
theme.CreateMenuItems(popupMenu, actions, emptyMenu: false);
return popupMenu;
};
}
public ViewControls3D(BedConfig sceneContext, ThemeConfig theme, UndoBuffer undoBuffer, bool isPrinterType, bool showPrintButton)
: base(theme)
2015-04-08 15:20:10 -07:00
{
this.theme = theme;
this.ActionArea.Click += (s, e) =>
{
view3DWidget.InteractionLayer.Focus();
};
this.IsPrinterMode = isPrinterType;
this.sceneContext = sceneContext;
2017-03-15 16:17:06 -07:00
string iconPath;
2015-04-08 15:20:10 -07:00
this.AddChild(CreateAddButton(sceneContext, theme));
2018-05-17 13:52:29 -07:00
this.AddChild(new ToolbarSeparator(theme));
bedMenuButton = new PopupMenuButton(AggContext.StaticData.LoadIcon("bed.png", 16, 16, theme.InvertIcons), theme)
{
Name = "Bed Options Menu",
//ToolTipText = "Options",
Enabled = true,
Margin = theme.ButtonSpacing,
2018-10-19 18:17:27 -07:00
VAnchor = VAnchor.Center,
DrawArrow = true
};
this.AddChild(bedMenuButton);
this.AddChild(new ToolbarSeparator(theme));
var undoButton = new IconButton(AggContext.StaticData.LoadIcon("Undo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
{
Name = "3D View Undo",
ToolTipText = "Undo",
Enabled = false,
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing,
VAnchor = VAnchor.Center
};
2017-08-14 12:34:44 -07:00
undoButton.Click += (sender, e) =>
{
var selectedItem = sceneContext.Scene.SelectedItem;
sceneContext.Scene.SelectedItem = null;
2017-08-14 12:34:44 -07:00
undoBuffer.Undo();
view3DWidget.InteractionLayer.Focus();
// if the item we had selected is still in the scene, re-select it
if(sceneContext.Scene.Children.Contains(selectedItem))
{
sceneContext.Scene.SelectedItem = selectedItem;
}
2017-08-14 12:34:44 -07:00
};
this.AddChild(undoButton);
var redoButton = new IconButton(AggContext.StaticData.LoadIcon("Redo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
{
Name = "3D View Redo",
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing,
ToolTipText = "Redo",
Enabled = false,
VAnchor = VAnchor.Center
};
2017-08-14 12:34:44 -07:00
redoButton.Click += (sender, e) =>
{
var selectedItem = sceneContext.Scene.SelectedItem;
sceneContext.Scene.SelectedItem = null;
2017-08-14 12:34:44 -07:00
undoBuffer.Redo();
view3DWidget.InteractionLayer.Focus();
// if the item we had selected is still in the scene, re-select it
if (sceneContext.Scene.Children.Contains(selectedItem))
{
sceneContext.Scene.SelectedItem = selectedItem;
}
2017-08-14 12:34:44 -07:00
};
this.AddChild(redoButton);
this.AddChild(CreateSaveButton(theme));
2018-10-15 15:13:40 -07:00
if (showPrintButton)
{
2018-10-17 14:42:01 -07:00
var printButton = new TextButton("Print", theme)
{
2018-10-17 17:38:20 -07:00
Name = "Print Button",
2018-10-17 14:42:01 -07:00
BackgroundColor = theme.AccentMimimalOverlay
};
printButton.Click += (s, e) =>
{
2018-10-17 17:38:20 -07:00
if (ProfileManager.Instance.Profiles.Count <= 0)
{
2018-10-17 17:38:20 -07:00
//Launch window to prompt user to sign in
UiThread.RunOnIdle(() => DialogWindow.Show(new SetupStepMakeModelName()));
}
// If no active printer but profiles exist, show select printer
// If printer exists, stash plate with undo operation, then load this scene onto the printer bed
else if (ApplicationController.Instance.ActivePrinter is PrinterConfig printer && printer.Settings.PrinterSelected)
{
Task.Run(async () =>
{
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges);
// Clear bed to get new MCX on disk for this item
printer.Bed.ClearPlate();
var editContext = sceneContext.EditContext;
await printer.Bed.LoadContent(editContext);
bool allInBounds = true;
foreach (var item in printer.Bed.Scene.Children)
{
allInBounds &= printer.InsideBuildVolume(item);
}
if(!allInBounds)
{
await printer.Bed.Scene.AutoArrangeChildren(view3DWidget);
}
// Switch to printer
ApplicationController.Instance.AppView.TabControl.SelectedTabKey = printer.Settings.GetValue(SettingsKey.printer_name);
// Slice and print
// Save any pending changes before starting print operation
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges);
await ApplicationController.Instance.PrintPart(
printer.Bed.EditContext,
printer,
null,
2018-10-19 18:17:27 -07:00
CancellationToken.None);
});
}
};
2018-10-15 15:13:40 -07:00
this.AddChild(printButton);
}
2018-05-17 13:52:29 -07:00
this.AddChild(new ToolbarSeparator(theme));
2017-08-14 12:34:44 -07:00
undoBuffer.Changed += (sender, e) =>
{
undoButton.Enabled = undoBuffer.UndoCount > 0;
redoButton.Enabled = undoBuffer.RedoCount > 0;
};
undoButton.Enabled = undoBuffer.UndoCount > 0;
redoButton.Enabled = undoBuffer.RedoCount > 0;
2017-07-07 12:25:31 -07:00
var buttonGroupA = new ObservableCollection<GuiWidget>();
2017-07-05 13:55:38 -07:00
if (UserSettings.Instance.IsTouchScreen)
{
iconPath = Path.Combine("ViewTransformControls", "rotate.png");
rotateButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
{
SiblingRadioButtonList = buttonGroupA,
ToolTipText = "Rotate (Alt + Left Mouse)".Localize(),
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing
};
2017-07-05 13:55:38 -07:00
rotateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Rotate;
2017-07-07 12:25:31 -07:00
buttonGroupA.Add(rotateButton);
2017-07-05 13:55:38 -07:00
AddChild(rotateButton);
iconPath = Path.Combine("ViewTransformControls", "translate.png");
translateButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
{
SiblingRadioButtonList = buttonGroupA,
ToolTipText = "Move (Shift + Left Mouse)".Localize(),
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing
};
2017-07-05 13:55:38 -07:00
translateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Translate;
2017-07-07 12:25:31 -07:00
buttonGroupA.Add(translateButton);
2017-07-05 13:55:38 -07:00
AddChild(translateButton);
iconPath = Path.Combine("ViewTransformControls", "scale.png");
scaleButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
{
SiblingRadioButtonList = buttonGroupA,
ToolTipText = "Zoom (Ctrl + Left Mouse)".Localize(),
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing
};
2017-07-05 13:55:38 -07:00
scaleButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Scale;
2017-07-07 12:25:31 -07:00
buttonGroupA.Add(scaleButton);
2017-07-05 13:55:38 -07:00
AddChild(scaleButton);
rotateButton.Checked = true;
2015-04-08 15:20:10 -07:00
// Add vertical separator
2018-05-17 13:52:29 -07:00
this.AddChild(new ToolbarSeparator(theme));
2015-04-08 15:20:10 -07:00
iconPath = Path.Combine("ViewTransformControls", "partSelect.png");
partSelectButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
{
SiblingRadioButtonList = buttonGroupA,
ToolTipText = "Select Part".Localize(),
2018-06-25 08:39:57 -07:00
Margin = theme.ButtonSpacing
};
partSelectButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.PartSelect;
buttonGroupA.Add(partSelectButton);
AddChild(partSelectButton);
}
2015-04-08 15:20:10 -07:00
operationButtons = new List<(GuiWidget, SceneSelectionOperation)>();
// Add Selected IObject3D -> Operations to toolbar
foreach (var namedAction in ApplicationController.Instance.RegisteredSceneOperations)
{
if (namedAction is SceneSelectionSeparator)
{
2018-05-17 13:52:29 -07:00
this.AddChild(new ToolbarSeparator(theme));
continue;
}
GuiWidget button;
if (namedAction.Icon != null)
{
button = new IconButton(namedAction.Icon, theme)
{
Name = namedAction.Title + " Button",
ToolTipText = namedAction.Title,
Margin = theme.ButtonSpacing,
BackgroundColor = theme.ToolbarButtonBackground,
HoverColor = theme.ToolbarButtonHover,
MouseDownColor = theme.ToolbarButtonDown,
};
}
else
{
button = new TextButton(namedAction.Title, theme)
{
Name = namedAction.Title + " Button",
Margin = theme.ButtonSpacing,
BackgroundColor = theme.ToolbarButtonBackground,
HoverColor = theme.ToolbarButtonHover,
MouseDownColor = theme.ToolbarButtonDown,
};
}
operationButtons.Add((button, namedAction));
button.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
namedAction.Action.Invoke(sceneContext.Scene);
var partTab = button.Parents<PartTabPage>().FirstOrDefault();
var view3D = partTab.Descendants<View3DWidget>().FirstOrDefault();
view3D.InteractionLayer.Focus();
});
};
this.AddChild(button);
}
sceneContext.Scene.SelectionChanged += Scene_SelectionChanged;
// Run on load
Scene_SelectionChanged(null, null);
}
private void Scene_SelectionChanged(object sender, EventArgs e)
{
// Set enabled level based on operation rules
foreach(var item in operationButtons)
{
item.button.Enabled = item.operation.IsEnabled?.Invoke(sceneContext.Scene) ?? false;
}
}
private GuiWidget CreateAddButton(BedConfig sceneContext, ThemeConfig theme)
{
var buttonView = new TextIconButton(
"",
AggContext.StaticData.LoadIcon("cube_add.png", 16, 16, theme.InvertIcons),
theme);
// Remove right Padding for drop style
buttonView.Padding = buttonView.Padding.Clone(right: 0);
var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme)
2018-01-21 21:07:14 -08:00
{
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Fit,
};
PopupMenuButton libraryPopup = null;
libraryPopup = new PopupMenuButton(buttonView, theme)
{
MakeScrollable = false,
2018-10-10 13:33:16 -07:00
Name = "Add Content Menu",
ToolTipText = "Add Content".Localize(),
AlwaysKeepOpen = true,
DynamicPopupContent = () =>
{
if (partPreviewContent == null)
{
partPreviewContent = this.Parents<PartPreviewContent>().FirstOrDefault();
}
var verticalResizeContainer = new VerticalResizeContainer(theme, GrabBarSide.Right)
{
BackgroundColor = theme.TabBarBackground,
Padding = new BorderDouble(theme.DefaultContainerPadding / 2, 0),
MinimumSize = new Vector2(120, 50),
Height = libraryPopup.TransformToScreenSpace(libraryPopup.Position).Y,
};
double.TryParse(UserSettings.Instance.get(UserSettingsKey.PopupLibraryWidth), out double controlWidth);
if (controlWidth == 0)
{
controlWidth = 400;
}
verticalResizeContainer.Width = controlWidth;
verticalResizeContainer.BoundsChanged += (s2, e2) =>
{
UserSettings.Instance.set(UserSettingsKey.PopupLibraryWidth, verticalResizeContainer.Width.ToString());
};
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
var printLibraryWidget = new PrintLibraryWidget(partPreviewContent, theme)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Absolute,
Height = libraryPopup.TransformToScreenSpace(libraryPopup.Position).Y,
Margin = new BorderDouble(left: verticalResizeContainer.SplitterWidth)
};
systemWindow.SizeChanged += (s, e) =>
{
printLibraryWidget.Height = libraryPopup.TransformToScreenSpace(libraryPopup.Position).Y;
};
verticalResizeContainer.AddChild(printLibraryWidget);
systemWindow.MouseDown += systemWindownMouseDown;
void systemWindownMouseDown(object s2, MouseEventArgs mouseEvent)
{
// MouseUp on our SystemWindow outside of our bounds should call close
var resizeContainerMousePosition = verticalResizeContainer.TransformFromScreenSpace(mouseEvent.Position);
bool mouseUpOnWidget = resizeContainerMousePosition.X >= 0 && resizeContainerMousePosition.X <= verticalResizeContainer.Width
&& resizeContainerMousePosition.Y >= 0 && resizeContainerMousePosition.Y <= verticalResizeContainer.Height;
if (!mouseUpOnWidget)
{
libraryPopup.CloseMenu();
systemWindow.MouseDown -= systemWindownMouseDown;
}
};
return verticalResizeContainer;
},
BackgroundColor = theme.ToolbarButtonBackground,
HoverColor = theme.ToolbarButtonHover,
MouseDownColor = theme.ToolbarButtonDown,
DrawArrow = true,
Margin = theme.ButtonSpacing,
};
libraryPopup.ConfigurePopup += (s, e) =>
{
e.HAnchor = HAnchor.Fit;
e.VAnchor = VAnchor.Fit;
};
return libraryPopup;
}
private GuiWidget CreateSaveButton(ThemeConfig theme)
{
var iconButton = new IconButton(
AggContext.StaticData.LoadIcon("save_grey_16x.png", 16, 16, theme.InvertIcons),
theme)
{
ToolTipText = "Save".Localize(),
};
iconButton.Click += (s, e) =>
{
ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges).ConfigureAwait(false);
};
// Remove right Padding for drop style
iconButton.Padding = iconButton.Padding.Clone(right: 0);
var button = new PopupMenuButton(iconButton, theme)
{
Name = "Save SplitButton",
ToolTipText = "Save As".Localize(),
DynamicPopupContent = () =>
{
var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);
var saveAs = popupMenu.CreateMenuItem("Save As".Localize());
saveAs.Click += (s, e) => UiThread.RunOnIdle(() =>
{
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(
new SaveAsPage(
async (newName, destinationContainer) =>
{
// Save to the destination provider
if (destinationContainer is ILibraryWritableContainer writableContainer)
{
// Wrap stream with ReadOnlyStream library item and add to container
writableContainer.Add(new[]
{
new InMemoryLibraryItem(sceneContext.Scene)
{
Name = newName
}
});
destinationContainer.Dispose();
}
}));
});
});
return popupMenu;
},
BackgroundColor = theme.ToolbarButtonBackground,
HoverColor = theme.ToolbarButtonHover,
MouseDownColor = theme.ToolbarButtonDown,
DrawArrow = true,
Margin = theme.ButtonSpacing,
};
iconButton.Selectable = true;
return button;
}
public static async void LoadAndAddPartsToPlate(GuiWidget originatingWidget, string[] filesToLoad, BedConfig sceneContext)
{
if (filesToLoad != null && filesToLoad.Length > 0)
{
await Task.Run(() => loadAndAddPartsToPlate(filesToLoad, sceneContext));
if (originatingWidget.HasBeenClosed)
{
return;
}
var scene = sceneContext.Scene;
bool addingOnlyOneItem = scene.Children.Count == scene.Children.Count + 1;
if (scene.HasChildren())
{
if (addingOnlyOneItem)
{
// if we are only adding one part to the plate set the selection to it
scene.SelectLastChild();
}
}
2018-06-20 08:09:35 -07:00
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Content, null));
}
}
private static async Task loadAndAddPartsToPlate(string[] filesToLoadIncludingZips, BedConfig sceneContext)
{
if (filesToLoadIncludingZips?.Any() == true)
{
var scene = sceneContext.Scene;
2018-09-26 15:26:54 -07:00
// When a single gcode file is selected, swap the plate to the new GCode content
if (filesToLoadIncludingZips.Count() == 1
&& filesToLoadIncludingZips.FirstOrDefault() is string firstFilePath
&& Path.GetExtension(firstFilePath).ToUpper() == ".GCODE")
{
// Drop handler for special case of GCode or similar (change loaded scene to new context)
await sceneContext.LoadContent(
new EditContext()
{
SourceItem = new FileSystemFileItem(firstFilePath),
// No content store for GCode, otherwise PlatingHistory
ContentStore = sceneContext.EditContext.ContentStore
});
return;
}
List<string> filesToLoad = new List<string>();
foreach (string loadedFileName in filesToLoadIncludingZips)
{
string extension = Path.GetExtension(loadedFileName).ToUpper();
if ((extension != ""
&& extension != ".ZIP"
2018-09-26 15:26:54 -07:00
&& extension != ".GCODE"
&& ApplicationController.Instance.Library.IsContentFileType(loadedFileName))
)
{
filesToLoad.Add(loadedFileName);
}
else if (extension == ".ZIP")
{
List<PrintItem> partFiles = ProjectFileHandler.ImportFromProjectArchive(loadedFileName);
if (partFiles != null)
{
foreach (PrintItem part in partFiles)
{
2018-09-26 15:26:54 -07:00
string itemExtension = Path.GetExtension(part.FileLocation).ToUpper();
if (itemExtension != ".GCODE")
{
filesToLoad.Add(part.FileLocation);
}
}
}
}
}
var itemCache = new Dictionary<string, IObject3D>();
foreach (string filePath in filesToLoad)
{
var libraryItem = new FileSystemFileItem(filePath);
IObject3D object3D = null;
await ApplicationController.Instance.Tasks.Execute("Loading".Localize() + " " + Path.GetFileName(filePath), async (progressReporter, cancellationToken) =>
{
var progressStatus = new ProgressStatus();
progressReporter.Report(progressStatus);
object3D = await libraryItem.CreateContent((double progress0To1, string processingState) =>
{
progressStatus.Progress0To1 = progress0To1;
progressStatus.Status = processingState;
progressReporter.Report(progressStatus);
});
});
if (object3D != null)
{
scene.Children.Modify(list => list.Add(object3D));
PlatingHelper.MoveToOpenPositionRelativeGroup(object3D, scene.Children);
}
}
}
}
public override void OnClosed(EventArgs e)
2015-04-08 15:20:10 -07:00
{
2018-04-12 21:28:55 -07:00
sceneContext.Scene.SelectionChanged -= Scene_SelectionChanged;
2015-04-08 15:20:10 -07:00
base.OnClosed(e);
}
}
}