From 78b0834e7db7948812f28fff72482f0d8d179bc4 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 28 Mar 2017 10:31:43 -0700 Subject: [PATCH] Extract distinct volumes from mesh on Ungroup - Rename event to clarify intent --- PartPreviewWindow/View3D/View3DUngroup.cs | 38 +++++++++++++++++++++-- Submodules/agg-sharp | 2 +- Utilities/AuthenticationData.cs | 9 +++--- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/PartPreviewWindow/View3D/View3DUngroup.cs b/PartPreviewWindow/View3D/View3DUngroup.cs index da14a5e49..743ca0e5e 100644 --- a/PartPreviewWindow/View3D/View3DUngroup.cs +++ b/PartPreviewWindow/View3D/View3DUngroup.cs @@ -29,6 +29,8 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.DataConverters3D; using System.Threading.Tasks; +using MatterHackers.PolygonMesh; +using System.Linq; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -36,7 +38,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { private async void UngroupSelectedMeshGroup() { - if (Scene.HasChildren) + if (Scene.HasSelection) { processingProgressControl.PercentComplete = 0; processingProgressControl.Visible = true; @@ -45,7 +47,39 @@ namespace MatterHackers.MatterControl.PartPreviewWindow await Task.Run(() => { - if (Scene.IsSelected(Object3DTypes.Group)) + var selectedItem = Scene.SelectedItem; + bool isGroupItemType = Scene.IsSelected(Object3DTypes.Group); + + // If not a Group ItemType, look for mesh volumes and split into disctinct objects if found + if (!isGroupItemType + && !selectedItem.HasChildren + && selectedItem.Mesh != null) + { + var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(Scene.SelectedItem.Mesh, (double progress0To1, string processingState, out bool continueProcessing) => + { + ReportProgressChanged(progress0To1 * .5, processingState, out continueProcessing); + }); + + if (discreetMeshes.Count == 1) + { + // No further processing needed, nothing to ungroup + return; + } + + selectedItem.Children = discreetMeshes.Select(mesh => new Object3D() + { + ItemType = Object3DTypes.Model, + Mesh = mesh + }).ToList(); + + selectedItem.Mesh = null; + selectedItem.MeshPath = null; + selectedItem.ItemType = Object3DTypes.Group; + + isGroupItemType = true; + } + + if (isGroupItemType) { // Create and perform the delete operation var operation = new UngroupCommand(this, Scene.SelectedItem); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 900df38c2..0608c69b9 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 900df38c2816e1388b4fa82dcb84afe59abd1af9 +Subproject commit 0608c69b94172c1a34ac868b6c158e899d1436b0 diff --git a/Utilities/AuthenticationData.cs b/Utilities/AuthenticationData.cs index b6745add9..af036b28c 100644 --- a/Utilities/AuthenticationData.cs +++ b/Utilities/AuthenticationData.cs @@ -9,12 +9,13 @@ using System.Runtime.Serialization.Formatters.Binary; using MatterHackers.Localizations; using System.Text.RegularExpressions; using Newtonsoft.Json; +using MatterHackers.Agg.UI; namespace MatterHackers.MatterControl { public class AuthenticationData { - public RootedObjectEventHandler SessionUpdateTrigger = new RootedObjectEventHandler(); + public RootedObjectEventHandler AuthSessionChanged = new RootedObjectEventHandler(); static int failedRequestCount = int.MaxValue; public bool IsConnected @@ -53,7 +54,7 @@ namespace MatterHackers.MatterControl public void SessionRefresh() { //Called after completing a purchase (for example) - SessionUpdateTrigger.CallEvents(null, null); + AuthSessionChanged.CallEvents(null, null); } public void ClearActiveSession() @@ -64,7 +65,7 @@ namespace MatterHackers.MatterControl this.ActiveClientToken = null; ApplicationController.Instance.ChangeCloudSyncStatus(userAuthenticated: false, reason: "Session Cleared".Localize()); - SessionUpdateTrigger.CallEvents(null, null); + AuthSessionChanged.CallEvents(null, null); } public void SetActiveSession(string userName, string userEmail, string sessionKey, string clientToken) @@ -75,7 +76,7 @@ namespace MatterHackers.MatterControl this.ActiveClientToken = clientToken; ApplicationController.Instance.ChangeCloudSyncStatus(userAuthenticated: true); - SessionUpdateTrigger.CallEvents(null, null); + AuthSessionChanged.CallEvents(null, null); } public bool ClientAuthenticatedSessionValid