void ungroupSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string makingCopyLabel     = LocalizedString.Get("Ungrouping");
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            int indexBeingReplaced = SelectedMeshGroupIndex;

            asynchMeshGroups[indexBeingReplaced].Transform(asynchMeshGroupTransforms[indexBeingReplaced].TotalTransform);
            List <Mesh> discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asynchMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
            {
                BackgroundWorker_ProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
            });

            asynchMeshGroups.RemoveAt(indexBeingReplaced);
            asynchPlatingDatas.RemoveAt(indexBeingReplaced);
            asynchMeshGroupTransforms.RemoveAt(indexBeingReplaced);
            double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count;
            double currentRatioDone     = 0;

            for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asynchPlatingDatas.Add(newInfo);
                asynchMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex]));
                int       addedMeshIndex = asynchMeshGroups.Count - 1;
                MeshGroup addedMeshGroup = asynchMeshGroups[addedMeshIndex];

                ScaleRotateTranslate transform = ScaleRotateTranslate.Identity();
                transform.SetCenteringForMeshGroup(addedMeshGroup);
                asynchMeshGroupTransforms.Add(transform);

                //PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, addedMeshIndex, false);

                // and create selection info
                PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    BackgroundWorker_ProgressChanged(progress0To1 * .5 + .5, processingState, out continueProcessing);
                });
                currentRatioDone += ratioPerDiscreetMesh;
            }
        }
Example #2
0
        public static async void UngroupSelection(this InteractiveScene scene)
        {
            var selectedItem = scene.SelectedItem;

            if (selectedItem != null)
            {
                if (selectedItem.CanFlatten)
                {
                    selectedItem.Flatten(scene.UndoBuffer);
                    scene.SelectedItem = null;
                    return;
                }

                bool isGroupItemType = selectedItem.Children.Count > 0;

                // If not a Group ItemType, look for mesh volumes and split into distinct objects if found
                if (isGroupItemType)
                {
                    // Create and perform the delete operation
                    // Store the operation for undo/redo
                    scene.UndoBuffer.AddAndDo(new UngroupCommand(scene, selectedItem));
                }
                else if (!selectedItem.HasChildren() &&
                         selectedItem.Mesh != null)
                {
                    await ApplicationController.Instance.Tasks.Execute(
                        "Ungroup".Localize(),
                        null,
                        (reporter, cancellationToken) =>
                    {
                        var progressStatus = new ProgressStatus();
                        reporter.Report(progressStatus);
                        // clear the selection
                        scene.SelectedItem    = null;
                        progressStatus.Status = "Copy".Localize();
                        reporter.Report(progressStatus);

                        // try to cut it up into multiple meshes
                        progressStatus.Status = "Split".Localize();
                        var discreetMeshes    = CreateDiscreteMeshes.SplitVolumesIntoMeshes(selectedItem.Mesh, cancellationToken, (double progress0To1, string processingState) =>
                        {
                            progressStatus.Progress0To1 = .5 + progress0To1 * .5;
                            progressStatus.Status       = processingState;
                            reporter.Report(progressStatus);
                        });
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return(Task.CompletedTask);
                        }

                        if (discreetMeshes.Count == 1)
                        {
                            // restore the selection
                            scene.SelectedItem = selectedItem;
                            // No further processing needed, nothing to ungroup
                            return(Task.CompletedTask);
                        }

                        // build the ungroup list
                        List <IObject3D> addItems = new List <IObject3D>(discreetMeshes.Select(mesh => new Object3D()
                        {
                            Mesh = mesh,
                        }));

                        foreach (var item in addItems)
                        {
                            item.CopyProperties(selectedItem, Object3DPropertyFlags.All);
                            item.Visible = true;
                        }

                        // add and do the undo data
                        scene.UndoBuffer.AddAndDo(new ReplaceCommand(new[] { selectedItem }, addItems));

                        foreach (var item in addItems)
                        {
                            item.MakeNameNonColliding();
                        }

                        return(Task.CompletedTask);
                    });
                }

                // leave no selection
                scene.SelectedItem = null;
            }
        }
Example #3
0
        public static async void UngroupSelection(this InteractiveScene scene)
        {
            if (scene.HasSelection)
            {
                await Task.Run(() =>
                {
                    var selectedItem     = scene.SelectedItem;
                    bool isGroupItemType = scene.HasSelection && selectedItem.Children.Count > 0;

                    // If not a Group ItemType, look for mesh volumes and split into distinct objects if found
                    if (!isGroupItemType &&
                        !selectedItem.HasChildren() &&
                        selectedItem.Mesh != null)
                    {
                        var ungroupItem = scene.SelectedItem;
                        // clear the selection
                        scene.SelectedItem = null;
                        var ungroupMesh    = ungroupItem.Mesh;

                        if (!ungroupMesh.Vertices.Sorted)
                        {
                            ungroupMesh.CleanAndMergeMesh(CancellationToken.None);
                        }

                        // try to cut it up into multiple meshes
                        var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(ungroupMesh, CancellationToken.None, (double progress0To1, string processingState) =>
                        {
                            //view3DWidget.ReportProgressChanged(progress0To1 * .5, processingState);
                        });

                        if (discreetMeshes.Count == 1)
                        {
                            // restore the selection
                            scene.SelectedItem = ungroupItem;
                            // No further processing needed, nothing to ungroup
                            return;
                        }

                        // build the ungroup list
                        List <IObject3D> addItems = new List <IObject3D>(discreetMeshes.Select(mesh => new Object3D()
                        {
                            Mesh   = mesh,
                            Matrix = ungroupItem.Matrix,
                        }));

                        // add and do the undo data
                        scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List <IObject3D> {
                            ungroupItem
                        }, addItems));
                    }

                    if (isGroupItemType)
                    {
                        // Create and perform the delete operation
                        // Store the operation for undo/redo
                        scene.UndoBuffer.AddAndDo(new UngroupCommand(scene, scene.SelectedItem));
                    }
                });

                // leave no selection
                scene.SelectedItem = null;
            }
        }
Example #4
0
        private void UngroupSelected()
        {
            if (SelectedMeshGroupIndex == -1)
            {
                SelectedMeshGroupIndex = 0;
            }
            string makingCopyLabel     = LocalizedString.Get("Ungrouping");
            string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);

            processingProgressControl.ProcessType = makingCopyLabelFull;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY);

            int         indexBeingReplaced = SelectedMeshGroupIndex;
            List <Mesh> discreetMeshes     = new List <Mesh>();

            asyncMeshGroups[indexBeingReplaced].Transform(asyncMeshGroupTransforms[indexBeingReplaced]);
            // if there are multiple meshes than just make them separate groups
            if (asyncMeshGroups[indexBeingReplaced].Meshes.Count > 1)
            {
                foreach (Mesh mesh in asyncMeshGroups[indexBeingReplaced].Meshes)
                {
                    discreetMeshes.Add(mesh);
                }
            }
            else             // actually try and cut up the mesh into separate parts
            {
                discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asyncMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
                });
            }

            asyncMeshGroups.RemoveAt(indexBeingReplaced);
            asyncPlatingDatas.RemoveAt(indexBeingReplaced);
            asyncMeshGroupTransforms.RemoveAt(indexBeingReplaced);
            double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count;
            double currentRatioDone     = 0;

            for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++)
            {
                PlatingMeshGroupData newInfo = new PlatingMeshGroupData();
                asyncPlatingDatas.Add(newInfo);
                asyncMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex]));
                int       addedMeshIndex = asyncMeshGroups.Count - 1;
                MeshGroup addedMeshGroup = asyncMeshGroups[addedMeshIndex];

                Matrix4X4 transform = Matrix4X4.Identity;
                asyncMeshGroupTransforms.Add(transform);

                //PlatingHelper.PlaceMeshGroupOnBed(asyncMeshGroups, asyncMeshGroupTransforms, addedMeshIndex, false);

                // and create selection info
                PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
                {
                    ReportProgressChanged(.5 + progress0To1 * .5 * currentRatioDone, processingState, out continueProcessing);
                });
                currentRatioDone += ratioPerDiscreetMesh;
            }
        }