Ejemplo n.º 1
0
        public ICommand Replace(int startIndex, int len, string newText)
        {
            var command = new ReplaceCommand(this, startIndex, len, newText);

            command.Do();
            return(command);
        }
Ejemplo n.º 2
0
        public static void FlattenToPathObject(this IObject3D item, UndoBuffer undoBuffer)
        {
            if (item is IPathObject pathObject)
            {
                using (item.RebuildLock())
                {
                    var newPathObject = new PathObject3D();
                    newPathObject.VertexSource = new VertexStorage(pathObject.VertexSource);

                    // and replace us with the children
                    var replaceCommand = new ReplaceCommand(new[] { item }, new[] { newPathObject });

                    if (undoBuffer != null)
                    {
                        undoBuffer.AddAndDo(replaceCommand);
                    }
                    else
                    {
                        replaceCommand.Do();
                    }

                    newPathObject.MakeNameNonColliding();
                }
            }
        }
        public override void Remove(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                List <IObject3D> newChildren = new List <IObject3D>();
                // push our matrix into a copy of our children
                foreach (var child in this.SourceContainer.Children)
                {
                    var newChild = child.Clone();
                    newChildren.Add(newChild);
                    newChild.Matrix *= this.Matrix;
                    var flags = Object3DPropertyFlags.Visible;
                    if (this.Color.alpha != 0)
                    {
                        flags |= Object3DPropertyFlags.Color;
                    }
                    if (this.OutputType != PrintOutputTypes.Default)
                    {
                        flags |= Object3DPropertyFlags.OutputType;
                    }
                    if (this.MaterialIndex != -1)
                    {
                        flags |= Object3DPropertyFlags.MaterialIndex;
                    }
                    newChild.CopyProperties(this, flags);
                }

                // and replace us with the children
                var replaceCommand = new ReplaceCommand(new[] { this }, newChildren, false);
                if (undoBuffer != null)
                {
                    undoBuffer.AddAndDo(replaceCommand);
                }
                else
                {
                    replaceCommand.Do();
                }
            }

            Invalidate(InvalidateType.Children);
        }
Ejemplo n.º 4
0
        public override void Remove(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                var thisClone = this.Clone();

                using (thisClone.RebuildLock())
                {
                    // remove all the mesh wrappers that we own
                    var meshWrappers = thisClone.Descendants().Where(o => o.OwnerID == thisClone.ID).ToArray();
                    foreach (var meshWrapper in meshWrappers)
                    {
                        meshWrapper.Remove(null);
                    }
                    foreach (var child in thisClone.Children)
                    {
                        child.OutputType = PrintOutputTypes.Default;

                        // push our matrix into a copy of our children (so they don't jump away)
                        using (child.RebuildLock())
                        {
                            child.Matrix *= thisClone.Matrix;
                        }
                    }

                    // collapse our children into our parent
                    // and replace us with the children
                    var replaceCommand = new ReplaceCommand(new[] { this }, thisClone.Children.ToList(), false);
                    if (undoBuffer != null)
                    {
                        undoBuffer.AddAndDo(replaceCommand);
                    }
                    else
                    {
                        replaceCommand.Do();
                    }
                }
            }

            Invalidate(InvalidateType.Children);
        }
        public override void Flatten(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                List <IObject3D> newChildren = new List <IObject3D>();
                // push our matrix into a copy of our children
                foreach (var child in this.Children)
                {
                    if (!(child is OperationSourceObject3D))
                    {
                        var newChild = child.Clone();
                        newChildren.Add(newChild);
                        newChild.Matrix *= this.Matrix;
                        var flags = Object3DPropertyFlags.Visible;
                        if (this.Color.alpha != 0)
                        {
                            flags |= Object3DPropertyFlags.Color;
                        }
                        if (this.OutputType != PrintOutputTypes.Default)
                        {
                            flags |= Object3DPropertyFlags.OutputType;
                        }
                        if (this.MaterialIndex != -1)
                        {
                            flags |= Object3DPropertyFlags.MaterialIndex;
                        }
                        newChild.CopyProperties(this, flags);
                    }
                }

                if (newChildren.Count > 1)
                {
                    // wrap the children in an object so they remain a group
                    var group = new Object3D();
                    group.Children.Modify((groupList) =>
                    {
                        groupList.AddRange(newChildren);
                    });

                    newChildren.Clear();
                    newChildren.Add(group);
                }

                if (newChildren.Count == 0)
                {
                    newChildren = this.Children.Select(i => i.Clone()).ToList();
                }

                // add flatten to the name to show what happened
                newChildren[0].Name = this.Name + " - " + "Flattened".Localize();

                // and replace us with the children
                var replaceCommand = new ReplaceCommand(new[] { this }, newChildren);

                if (undoBuffer != null)
                {
                    undoBuffer.AddAndDo(replaceCommand);
                }
                else
                {
                    replaceCommand.Do();
                }

                foreach (var child in newChildren[0].DescendantsAndSelf())
                {
                    child.MakeNameNonColliding();
                }
            }

            Invalidate(InvalidateType.Children);
        }
Ejemplo n.º 6
0
        public override void Flatten(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                var thisCopy = this.Clone();

                using (thisCopy.RebuilLockAll())
                {
                    var ownedMeshWrappers = thisCopy.Descendants().Where(o => o.OwnerID == thisCopy.ID).ToList();

                    var newMeshObjects = new List <IObject3D>();

                    // remove all the meshWrappers (collapse the children)
                    foreach (var ownedMeshWrapper in ownedMeshWrappers)
                    {
                        var wrapperParent = ownedMeshWrapper.Parent;
                        if (ownedMeshWrapper.Visible)
                        {
                            var newMesh = new Object3D()
                            {
                                Mesh = ownedMeshWrapper.Mesh.Copy(CancellationToken.None)
                            };
                            newMesh.CopyProperties(ownedMeshWrapper, Object3DPropertyFlags.All);
                            // move the mesh to the actual new position
                            var matrix = ownedMeshWrapper.WorldMatrix(thisCopy);
                            newMesh.Mesh.Transform(matrix);
                            // then set the matrix to identity
                            newMesh.Matrix = Matrix4X4.Identity;
                            newMesh.Name   = thisCopy.Name;
                            newMeshObjects.Add(newMesh);
                        }

                        // remove it
                        wrapperParent.Children.Remove(ownedMeshWrapper);
                    }

                    thisCopy.Matrix = Matrix4X4.Identity;

                    thisCopy.Children.Modify(children =>
                    {
                        children.Clear();
                        children.AddRange(newMeshObjects);
                        foreach (var child in children)
                        {
                            child.MakeNameNonColliding();
                        }
                    });

                    List <IObject3D> newChildren = new List <IObject3D>();
                    // push our matrix into a copy of our children
                    foreach (var child in thisCopy.Children)
                    {
                        var newChild = child.Clone();
                        newChildren.Add(newChild);
                        newChild.Matrix *= thisCopy.Matrix;
                        var flags = Object3DPropertyFlags.Visible;
                        if (thisCopy.Color.alpha != 0)
                        {
                            flags |= Object3DPropertyFlags.Color;
                        }
                        if (thisCopy.OutputType != PrintOutputTypes.Default)
                        {
                            flags |= Object3DPropertyFlags.OutputType;
                        }
                        if (thisCopy.MaterialIndex != -1)
                        {
                            flags |= Object3DPropertyFlags.MaterialIndex;
                        }
                        newChild.CopyProperties(thisCopy, flags);
                    }

                    // and replace us with the children
                    var replaceCommand = new ReplaceCommand(new List <IObject3D> {
                        this
                    }, newChildren, false);
                    if (undoBuffer != null)
                    {
                        undoBuffer.AddAndDo(replaceCommand);
                    }
                    else
                    {
                        replaceCommand.Do();
                    }
                }
            }

            Invalidate(InvalidateType.Children);
        }
Ejemplo n.º 7
0
 public ICommand Replace(int startIndex, int len, string newText)
 {
     var command = new ReplaceCommand(this, startIndex, len, newText);
     command.Do();
     return command;
 }