// This pastes a prefab. Returns false when paste was cancelled. internal void PastePrefab(Stream filedata, PasteOptions options) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Inserted prefab."); General.Map.UndoRedo.CreateUndo("Insert prefab"); // Decompress stream MemoryStream decompressed = new MemoryStream((int)filedata.Length * 3); filedata.Seek(0, SeekOrigin.Begin); BZip2.Decompress(filedata, decompressed); MemoryStream memstream = new MemoryStream(decompressed.ToArray()); decompressed.Dispose(); // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read data stream UniversalStreamReader reader = new UniversalStreamReader(); reader.StrictChecking = false; General.Map.Map.BeginAddRemove(); reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } // Done memstream.Dispose(); General.Map.Map.UpdateConfiguration(); General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options); General.Plugins.OnPasteEnd(options); }
// This performs the paste. Returns false when paste was cancelled. private bool DoPasteSelection(PasteOptions options) { // Check if possible to copy/paste if (General.Editing.Mode.Attributes.AllowCopyPaste) { // Anything to paste? if (Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT)) { // Cancel volatile mode General.Editing.DisengageVolatileMode(); // Let the plugins know if (General.Plugins.OnPasteBegin(options)) { // Ask the editing mode to prepare selection for pasting. if (General.Editing.Mode.OnPasteBegin(options.Copy())) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements."); General.Map.UndoRedo.CreateUndo("Paste"); // Read from clipboard Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT); memstream.Seek(0, SeekOrigin.Begin); // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read data stream UniversalStreamReader reader = new UniversalStreamReader(); reader.StrictChecking = false; General.Map.Map.BeginAddRemove(); reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } // Clean up memstream.Dispose(); // Check if anything was pasted int totalpasted = General.Map.Map.GetMarkedThings(true).Count; totalpasted += General.Map.Map.GetMarkedVertices(true).Count; totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSectors(true).Count; if (totalpasted > 0) { General.Map.Map.UpdateConfiguration(); General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options.Copy()); General.Plugins.OnPasteEnd(options); } return(true); } } // Aborted return(false); } else { // Nothing usefull on the clipboard General.MessageBeep(MessageBeepType.Warning); return(false); } } else { // Paste not allowed General.MessageBeep(MessageBeepType.Warning); return(false); } }
// This pastes a prefab. Returns false when paste was cancelled. internal void PastePrefab(Stream filedata, PasteOptions options) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Inserted prefab."); General.Map.UndoRedo.CreateUndo("Insert prefab"); // Decompress stream MemoryStream memstream; //mxd try { memstream = Data.SharpCompressHelper.DecompressStream(filedata); //mxd memstream.Seek(0, SeekOrigin.Begin); } catch (Exception e) { General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while reading prefab from file: " + e.Message); Logger.WriteLogLine(e.StackTrace); General.ShowErrorMessage("Unable to load prefab. See log file for error details.", MessageBoxButtons.OK); return; } // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read data stream UniversalStreamReader reader = new UniversalStreamReader(); reader.StrictChecking = false; General.Map.Map.BeginAddRemove(); reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } // Done memstream.Dispose(); General.Map.Map.UpdateConfiguration(); General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options); General.Plugins.OnPasteEnd(options); }
// This performs the paste. Returns false when paste was cancelled. private static void DoPasteSelection(PasteOptions options) { // Check if possible to copy/paste if (General.Editing.Mode.Attributes.AllowCopyPaste) { bool havepastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT); //mxd bool havedb2pastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT_DB2); //mxd // Anything to paste? if (havepastedata || havedb2pastedata) { // Cancel volatile mode General.Editing.DisengageVolatileMode(); // Let the plugins know if (General.Plugins.OnPasteBegin(options)) { // Ask the editing mode to prepare selection for pasting. if (General.Editing.Mode.OnPasteBegin(options.Copy())) { // Create undo General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements."); General.Map.UndoRedo.CreateUndo("Paste"); // Mark all current geometry General.Map.Map.ClearAllMarks(true); // Read from clipboard if (havepastedata) { using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT)) { // Rewind before use memstream.Seek(0, SeekOrigin.Begin); // Read data stream ClipboardStreamReader reader = new ClipboardStreamReader(); //mxd General.Map.Map.BeginAddRemove(); bool success = reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); if (!success) //mxd { General.Map.UndoRedo.WithdrawUndo(); // This will also mess with the marks... General.Map.Map.ClearAllMarks(true); // So re-mark all current geometry... } } } // mxd. DB2/DB64 interop else if (havedb2pastedata) { using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT_DB2)) { // Read data stream UniversalStreamReader reader = new UniversalStreamReader(new Dictionary <MapElementType, Dictionary <string, UniversalType> >()); reader.StrictChecking = false; General.Map.Map.BeginAddRemove(); reader.Read(General.Map.Map, memstream); General.Map.Map.EndAddRemove(); } } else { throw new NotImplementedException("Unknown clipboard data format!"); } // The new geometry is not marked, so invert the marks to get it marked General.Map.Map.InvertAllMarks(); // Check if anything was pasted List <Thing> things = General.Map.Map.GetMarkedThings(true); //mxd int totalpasted = things.Count; totalpasted += General.Map.Map.GetMarkedVertices(true).Count; totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count; totalpasted += General.Map.Map.GetMarkedSectors(true).Count; if (totalpasted > 0) { // Convert UDMF fields back to flags and activations, if needed if (!(General.Map.FormatInterface is UniversalMapSetIO)) { General.Map.Map.TranslateFromUDMF(); } // Modify tags and actions if preferred if (options.ChangeTags == PasteOptions.TAGS_REMOVE) { Tools.RemoveMarkedTags(); } if (options.ChangeTags == PasteOptions.TAGS_RENUMBER) { Tools.RenumberMarkedTags(); } if (options.RemoveActions) { Tools.RemoveMarkedActions(); } foreach (Thing t in things) { t.UpdateConfiguration(); //mxd } General.Map.ThingsFilter.Update(); General.Editing.Mode.OnPasteEnd(options.Copy()); General.Plugins.OnPasteEnd(options); } } } } else { // Nothing useful on the clipboard // [ZZ] don't beep if 3D mode is currently engaged. the 3D mode allows you to copy/paste non-geometry stuff. // note that this is a hack and probably needs to be fixed properly by making it beep elsewhere so that the current active mode can decide this. if (!(General.Editing.Mode is VisualMode)) { General.MessageBeep(MessageBeepType.Warning); } } } else { // Paste not allowed General.MessageBeep(MessageBeepType.Warning); } }