Extract distinct volumes from mesh on Ungroup

- Rename event to clarify intent
This commit is contained in:
John Lewin 2017-03-28 10:31:43 -07:00
parent c872d52ceb
commit 78b0834e7d
3 changed files with 42 additions and 7 deletions

View file

@ -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<IObject3D>();
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);

@ -1 +1 @@
Subproject commit 900df38c2816e1388b4fa82dcb84afe59abd1af9
Subproject commit 0608c69b94172c1a34ac868b6c158e899d1436b0

View file

@ -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