public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var n = new NumericUpDown { Maximum = _max, Minimum = _min, DecimalPlaces = _decimals, Name = Name, Anchor = AnchorStyles.Top | AnchorStyles.Right, Increment = (_decimals > 0) ? (1m / (_decimals * 10m)) : (1), Width = 80, Value = _defaultValue }; Location(n, qf, false); n.Location = new Point(qf.ClientSize.Width - QuickForm.ItemPadding - n.Width, n.Location.Y); controls.Add(n); return(controls); }
private void EditHotkey(Hotkey hk) { using (var qf = new QuickForm("Enter New Hotkey") .Item(new HotkeyQuickFormItem("Hotkey", hk.HotkeyString)) .OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var key = qf.String("Hotkey"); if (String.IsNullOrWhiteSpace(key)) { return; } var conflict = _hotkeys.FirstOrDefault(x => x.HotkeyString == key && x != hk); if (conflict != null) { if (MessageBox.Show(key + " is already assigned to \"" + Hotkeys.GetHotkeyDefinition(conflict.ID) + "\".\n" + "Continue anyway?", "Conflict Detected", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } hk.HotkeyString = key; UpdateHotkeyList(); } }
public void GoToBrushID() { using (var qf = new QuickForm("Enter Brush ID") { LabelWidth = 100, UseShortcutKeys = true } .TextBox("Brush ID") .OkCancel()) { qf.ClientSize = new Size(230, qf.ClientSize.Height); if (qf.ShowDialog() != DialogResult.OK) { return; } long id; if (!long.TryParse(qf.String("Brush ID"), out id)) { return; } var obj = _document.Map.WorldSpawn.FindByID(id); if (obj == null) { return; } // Select and go to the brush _document.PerformAction("Select brush ID " + id, new ChangeSelection(new[] { obj }, _document.Selection.GetSelectedObjects())); ViewportManager.Viewports.ForEach(x => x.FocusOn(obj.BoundingBox)); } }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var length = _actions.Count; for (var i = 0; i < _labels.Count; i++) { var action = _actions[i]; var label = _labels[i]; var result = _results[i]; var button = new Button(); if (action != null) button.Click += (sender, e) => action(((Control) sender).Parent as QuickForm); button.Click += (s, e) => qf.DialogResult = result; button.Click += qf.Close; button.Anchor = AnchorStyles.Top | AnchorStyles.Right; button.Width = 80; button.Text = label; button.DialogResult = result; Location(button, qf, false); button.Location = new Point(qf.ClientSize.Width - (QuickForm.ItemPadding + button.Width) * (length - i), button.Location.Y); controls.Add(button); } return controls; }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var length = _actions.Count; for (var i = 0; i < _labels.Count; i++) { var action = _actions[i]; var label = _labels[i]; var result = _results[i]; var button = new Button(); if (action != null) { button.Click += (sender, e) => action(((Control)sender).Parent as QuickForm); } button.Click += (s, e) => qf.DialogResult = result; button.Click += qf.Close; button.Anchor = AnchorStyles.Top | AnchorStyles.Right; button.Width = 80; button.Text = label; button.DialogResult = result; Location(button, qf, false); button.Location = new Point(qf.ClientSize.Width - (QuickForm.ItemPadding + button.Width) * (length - i), button.Location.Y); controls.Add(button); } return(controls); }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var t = new TextBox { Name = Name }; Anchor(t); Location(t, qf, false); var textBoxWidth = qf.ClientSize.Width - (QuickForm.ItemPadding * 2); textBoxWidth -= qf.LabelWidth; textBoxWidth -= 60; // Button width textBoxWidth -= QuickForm.ItemPadding * 2; var h = QuickForm.ItemHeight; t.Size = new Size(textBoxWidth, h); controls.Add(t); var b = new Button {Text = "Browse", Width = 60, Anchor = AnchorStyles.Top | AnchorStyles.Right}; Location(b, qf, false); b.Location = new Point(qf.ClientSize.Width - QuickForm.ItemPadding - b.Width, b.Location.Y); b.Click += (s,e) => ShowBrowseDialog(t); controls.Add(b); return controls; }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var cb = new ComboBox { Name = Name, Anchor = AnchorStyles.Top | AnchorStyles.Right, DropDownStyle = ComboBoxStyle.DropDownList }; cb.Items.AddRange(_items.ToArray()); cb.SelectedIndex = 0; Location(cb, qf, false); Size(cb, qf, qf.LabelWidth); controls.Add(cb); return(controls); }
private void RenameProfileButtonClicked(object sender, EventArgs e) { if (_profile == null) { return; } using (var qf = new QuickForm("Rename Build Profile").TextBox("Name", _profile.Name).OkCancel()) { if (qf.ShowDialog() == DialogResult.OK) { var name = qf.String("Name"); if (_build.Profiles.Any(x => String.Equals(name, x.Name, StringComparison.InvariantCultureIgnoreCase))) { MessageBox.Show("There is already a profile with that name, please type a unique name.", "Cannot rename profile"); name = null; } if (!String.IsNullOrWhiteSpace(name) && _profile.Name != name) { _profile.Name = name; SettingsManager.Write(); UpdateProfiles(); } } } }
protected void Location(Control c, QuickForm qf, bool isLabel) { var x = QuickForm.ItemPadding; if (!isLabel) x += qf.LabelWidth + QuickForm.ItemPadding; var y = qf.CurrentOffset; c.Location = new Point(x, y); }
public void GoToCoordinates() { using (var qf = new QuickForm("Enter Coordinates") { LabelWidth = 50, UseShortcutKeys = true } .TextBox("X", "0") .TextBox("Y", "0") .TextBox("Z", "0") .OkCancel()) { qf.ClientSize = new Size(180, qf.ClientSize.Height); if (qf.ShowDialog() != DialogResult.OK) { return; } decimal x, y, z; if (!Decimal.TryParse(qf.String("X"), out x)) { return; } if (!Decimal.TryParse(qf.String("Y"), out y)) { return; } if (!Decimal.TryParse(qf.String("Z"), out z)) { return; } var coordinate = new Coordinate(x, y, z); ViewportManager.Viewports.ForEach(vp => vp.FocusOn(coordinate)); } }
public void VisgroupCreateNew() { using (var qf = new QuickForm("Create New Visgroup") { UseShortcutKeys = true }.TextBox("Name").CheckBox("Add selection to visgroup", true).OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var ids = _document.Map.Visgroups.Where(x => !x.IsAutomatic).Select(x => x.ID).ToList(); var id = Math.Max(1, ids.Any() ? ids.Max() + 1 : 1); var name = qf.String("Name"); if (String.IsNullOrWhiteSpace(name)) { name = "Visgroup " + id.ToString(); } var vg = new Visgroup { ID = id, Colour = Colour.GetRandomLightColour(), Name = name, Visible = true }; IAction action = new CreateEditDeleteVisgroups(new[] { vg }, new Visgroup[0], new Visgroup[0]); if (qf.Bool("Add selection to visgroup") && !_document.Selection.IsEmpty()) { action = new ActionCollection(action, new EditObjectVisgroups(_document.Selection.GetSelectedObjects(), new[] { id }, new int[0])); } _document.PerformAction("Create visgroup", action); } }
public override List <Control> GetControls(QuickForm qf) { var ctrls = base.GetControls(qf); ctrls.OfType <TextBox>().First().KeyDown += HotkeyDown; return(ctrls); }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var cb = new ComboBox { Name = Name, Anchor = AnchorStyles.Top | AnchorStyles.Right, DropDownStyle = ComboBoxStyle.DropDownList }; cb.Items.AddRange(_items.ToArray()); cb.SelectedIndex = 0; Location(cb, qf, false); Size(cb, qf, qf.LabelWidth); controls.Add(cb); return controls; }
void OnFormShown(object sender, EventArgs eventArgs) { openedForm = (QuickForm)sender; openedForm.Font = PluginBase.Settings.DefaultFont; openedForm.ContextMenuStrip = new ContextMenuStrip { Renderer = new DockPanelStripRenderer(false) }; }
protected void Size(Control c, QuickForm qf, int offset) { var w = qf.ClientSize.Width - (QuickForm.ItemPadding * 2); if (offset > 0) { w -= offset; w -= QuickForm.ItemPadding; } var h = QuickForm.ItemHeight; c.Size = new Size(w, h); }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var c = new CheckBox {Text = Name, Name = Name, Checked = _value}; Size(c, qf, 0); c.TextAlign = ContentAlignment.MiddleLeft; Location(c, qf, true); c.Location = new Point(c.Location.X + QuickForm.ItemPadding, c.Location.Y); controls.Add(c); return controls; }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var l = new Label {Text = Name}; Anchor(l); Location(l, qf, true); Size(l, qf, 0); TextAlign(l); controls.Add(l); return controls; }
protected void Location(Control c, QuickForm qf, bool isLabel) { var x = QuickForm.ItemPadding; if (!isLabel) { x += qf.LabelWidth + QuickForm.ItemPadding; } var y = qf.CurrentOffset; c.Location = new Point(x, y); }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var c = new CheckBox { Text = Name, Name = Name, Checked = _value }; Size(c, qf, 0); c.TextAlign = ContentAlignment.MiddleLeft; Location(c, qf, true); c.Location = new Point(c.Location.X + QuickForm.ItemPadding, c.Location.Y); controls.Add(c); return(controls); }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var l = new Label { Text = Name }; Anchor(l); Location(l, qf, true); Size(l, qf, 0); TextAlign(l); controls.Add(l); return(controls); }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var b = new Button(); b.Click += (sender, e) => _clickevent(); b.Width = 120; b.Text = Name; Location(b, qf, true); controls.Add(b); return(controls); }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var t = new TextBox { Name = Name, Text = _defaultValue }; Anchor(t); Location(t, qf, false); Size(t, qf, qf.LabelWidth); controls.Add(t); return controls; }
public void MakeHollow() { if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection) { return; } var solids = _document.Selection.GetSelectedObjects().OfType <Solid>().ToList(); if (!solids.Any()) { return; } if (solids.Count > 1) { if (MessageBox.Show("This will hollow out every selected solid, are you sure?", "Multiple solids selected", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } var qf = new QuickForm("Select wall width") { UseShortcutKeys = true }.NumericUpDown("Wall width (negative to hollow outwards)", -1024, 1024, 0, 32).OkCancel(); decimal width; do { if (qf.ShowDialog() == DialogResult.Cancel) { return; } width = qf.Decimal("Wall width (negative to hollow outwards)"); if (width == 0) { MessageBox.Show("Please select a non-zero value."); } } while (width == 0); _document.PerformAction("Make objects hollow", new MakeHollow(solids, width)); }
private string PromptName(string name) { var qf = new QuickForm(ProfileName) { UseShortcutKeys = true }; qf.TextBox("ProfileName", ProfileName, name); qf.OkCancel(OK, Cancel); if (qf.ShowDialog() != DialogResult.OK) { return(null); } var n = qf.String("ProfileName"); return(String.IsNullOrEmpty(n) ? null : n); }
private void SaveProfileAsButtonClicked(object sender, EventArgs e) { using (var qf = new QuickForm("Save Build Profile As...").TextBox("Name").OkCancel()) { if (qf.ShowDialog() == DialogResult.OK) { var name = qf.String("Name"); if (_build.Profiles.Any(x => String.Equals(name, x.Name, StringComparison.InvariantCultureIgnoreCase))) { MessageBox.Show("There is already a profile with that name, please type a unique name.", "Cannot create profile"); name = null; } if (!String.IsNullOrWhiteSpace(name)) { _profile = SaveAsProfile(name); UpdateProfiles(); } } } }
private void AddFavouriteFolderButtonClicked(object sender, EventArgs e) { FavouriteTextureFolder parent = null; var selected = FavouritesTree.SelectedNode; if (selected != null) { parent = selected.Tag as FavouriteTextureFolder; } var siblings = parent != null ? parent.Children : SettingsManager.FavouriteTextureFolders; using (var qf = new QuickForm("Enter Folder Name") { UseShortcutKeys = true }.TextBox("Name").OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var name = qf.String("Name"); var uniqName = name; if (String.IsNullOrWhiteSpace(name)) { return; } var counter = 1; while (siblings.Any(x => x.Name == uniqName)) { uniqName = name + "_" + counter; counter++; } siblings.Add(new FavouriteTextureFolder { Name = uniqName }); UpdateFavouritesList(); } }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var t = new TextBox { Name = Name, Text = _defaultValue }; Anchor(t); Location(t, qf, false); Size(t, qf, qf.LabelWidth); controls.Add(t); return(controls); }
protected override async Task Invoke(MapDocument document, CommandParameters parameters) { using (var qf = new QuickForm(Title) { UseShortcutKeys = true }.TextBox("ObjectID", ObjectID).OkCancel(OK, Cancel)) { qf.ClientSize = new Size(230, qf.ClientSize.Height); if (await qf.ShowDialogAsync() != DialogResult.OK) { return; } if (!long.TryParse(qf.String("ObjectID"), out var id)) { return; } var obj = document.Map.Root.FindByID(id); if (obj == null) { return; } var tran = new Transaction( new Deselect(document.Selection), new Select(obj) ); await MapDocumentOperation.Perform(document, tran); var box = obj.BoundingBox; await Task.WhenAll( Oy.Publish("MapDocument:Viewport:Focus3D", box), Oy.Publish("MapDocument:Viewport:Focus2D", box) ); } }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var t = new TextBox { Name = Name }; Anchor(t); Location(t, qf, false); var textBoxWidth = qf.ClientSize.Width - (QuickForm.ItemPadding * 2); textBoxWidth -= qf.LabelWidth; textBoxWidth -= 60; // Button width textBoxWidth -= QuickForm.ItemPadding * 2; var h = QuickForm.ItemHeight; t.Size = new Size(textBoxWidth, h); controls.Add(t); var b = new Button { Text = "Browse", Width = 60, Anchor = AnchorStyles.Top | AnchorStyles.Right }; Location(b, qf, false); b.Location = new Point(qf.ClientSize.Width - QuickForm.ItemPadding - b.Width, b.Location.Y); b.Click += (s, e) => ShowBrowseDialog(t); controls.Add(b); return(controls); }
private void AddPropertyClicked(object sender, EventArgs e) { if (_changingClass) { return; } using (var qf = new QuickForm("Add Property") { UseShortcutKeys = true }.TextBox("Key").TextBox("Value").OkCancel()) { if (qf.ShowDialog(this) != DialogResult.OK) { return; } var name = qf.String("Key"); var newName = name; var num = 1; while (_values.Any(x => String.Equals(x.OriginalKey, newName, StringComparison.InvariantCultureIgnoreCase))) { newName = name + "#" + (num++); } _values.Add(new TableValue { Class = Class.Text, OriginalKey = newName, NewKey = newName, Value = qf.String("Value"), IsAdded = true, IsModified = true, IsRemoved = false }); PropertyValueChanged(this, newName, qf.String("Value")); } }
public override List <Control> GetControls(QuickForm qf) { var controls = new List <Control>(); var b1 = new Button(); if (_okevent != null) { b1.Click += (sender, e) => _okevent(((Control)sender).Parent as QuickForm); } b1.Click += (s, e) => qf.DialogResult = DialogResult.OK; b1.Click += qf.Close; b1.Anchor = AnchorStyles.Top | AnchorStyles.Right; b1.Width = 80; b1.Text = "OK"; b1.DialogResult = DialogResult.OK; Location(b1, qf, false); b1.Location = new Point(qf.ClientSize.Width - (QuickForm.ItemPadding + b1.Width) * 2, b1.Location.Y); controls.Add(b1); var b2 = new Button(); if (_cancelevent != null) { b2.Click += (sender, e) => _cancelevent(((Control)sender).Parent as QuickForm); } b2.Click += (s, e) => qf.DialogResult = DialogResult.Cancel; b2.Click += qf.Close; b2.Anchor = AnchorStyles.Top | AnchorStyles.Right; b2.Width = 80; b2.Text = "Cancel"; b2.DialogResult = DialogResult.Cancel; Location(b2, qf, false); b2.Location = new Point(qf.ClientSize.Width - QuickForm.ItemPadding - b2.Width, b2.Location.Y); controls.Add(b2); return(controls); }
protected override async Task Invoke(MapDocument document, CommandParameters parameters) { using (var qf = new QuickForm(Title) { UseShortcutKeys = true }.TextBox("X", "X", "0").TextBox("Y", "Y", "0").TextBox("Z", "Z", "0").OkCancel(OK, Cancel)) { qf.ClientSize = new Size(180, qf.ClientSize.Height); if (await qf.ShowDialogAsync() != DialogResult.OK) { return; } if (!Decimal.TryParse(qf.String("X"), out var x)) { return; } if (!Decimal.TryParse(qf.String("Y"), out var y)) { return; } if (!Decimal.TryParse(qf.String("Z"), out var z)) { return; } var coordinate = new Vector3((float)x, (float)y, (float)z); var box = new Box(coordinate - (Vector3.One * 10), coordinate + (Vector3.One * 10)); await Task.WhenAll( Oy.Publish("MapDocument:Viewport:Focus3D", box), Oy.Publish("MapDocument:Viewport:Focus2D", box) ); } }
public override List<Control> GetControls(QuickForm qf) { var controls = new List<Control>(); var l = new Label { Text = Name }; Location(l, qf, true); Size(l, qf.LabelWidth); TextAlign(l); controls.Add(l); var n = new NumericUpDown { Maximum = _max, Minimum = _min, DecimalPlaces = _decimals, Name = Name, Anchor = AnchorStyles.Top | AnchorStyles.Right, Increment = (_decimals > 0) ? (1m / (_decimals * 10m)) : (1), Width = 80, Value = _defaultValue }; Location(n, qf, false); n.Location = new Point(qf.ClientSize.Width - QuickForm.ItemPadding - n.Width, n.Location.Y); controls.Add(n); return controls; }
public void ScreenshotViewport(object parameter) { var focused = (parameter as ViewportBase) ?? ViewportManager.Viewports.FirstOrDefault(x => x.IsFocused); if (focused == null) { return; } var screen = Screen.FromControl(this); var area = screen.Bounds; using (var qf = new QuickForm("Select screenshot size") { UseShortcutKeys = true } .NumericUpDown("Width", 640, 5000, 0, area.Width) .NumericUpDown("Height", 480, 5000, 0, area.Height) .OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var shot = ViewportManager.CreateScreenshot(focused, (int)qf.Decimal("Width"), (int)qf.Decimal("Height")); if (shot == null) { return; } var ext = focused is Viewport2D || (focused is Viewport3D && ((Viewport3D)focused).Type != Viewport3D.ViewType.Textured) ? ".png" : ".jpg"; using (var sfd = new SaveFileDialog()) { sfd.FileName = "Sledge - " + (DocumentManager.CurrentDocument != null ? DocumentManager.CurrentDocument.MapFileName : "untitled") + " - " + DateTime.Now.ToString("yyyy-MM-ddThh-mm-ss") + ext; sfd.Filter = "Image Files (*.png, *.jpg, *.bmp)|*.png;*.jpg;*.bmp"; if (sfd.ShowDialog() == DialogResult.OK) { if (sfd.FileName.EndsWith("jpg")) { var encoder = GetJpegEncoder(); if (encoder != null) { var p = new EncoderParameter(Encoder.Quality, 90L); var ep = new EncoderParameters(1); ep.Param[0] = p; shot.Save(sfd.FileName, encoder, ep); } else { shot.Save(sfd.FileName); } } else { shot.Save(sfd.FileName); } } } shot.Dispose(); } }
protected override async Task Invoke(MapDocument document, CommandParameters parameters) { var existingEntities = document.Selection.OfType <Entity>().ToList(); Entity existing = null; var confirmed = false; if (existingEntities.Count == 0) { // No entities selected, just create it straight up confirmed = true; } else if (existingEntities.Count == 1) { // One entity selected, user chooses to merge or create a new entity using ( var qf = new QuickForm(EntitySelectedTitle) { Width = 400 } .Label(String.Format(OneEntitySelectedMessage, existingEntities[0].EntityData?.Name)) .DialogButtons( (KeepExisting, DialogResult.Yes), (CreateNew, DialogResult.No), (Cancel, DialogResult.Cancel) ) ) { var result = await qf.ShowDialogAsync(); if (result == DialogResult.Yes) { existing = existingEntities[0]; } confirmed = result != DialogResult.Cancel; } } else if (existingEntities.Count > 1) { // Multiple entities selected, user chooses which one to keep using ( var qf = new QuickForm(EntitySelectedTitle) { Width = 400 } .Label(MultipleEntitiesSelectedMessage) .ComboBox("Entity", "", existingEntities.Select(x => new EntityContainer { Entity = x })) .OkCancel(OK, Cancel) ) { var result = await qf.ShowDialogAsync(); if (result == DialogResult.OK) { existing = (qf.Object("Entity") as EntityContainer)?.Entity; } confirmed = result != DialogResult.Cancel; } } if (!confirmed) { return; } var ops = new List <IOperation>(); var gameData = await document.Environment.GetGameData(); var def = document.Environment.DefaultBrushEntity; var defaultEntityClass = ( from g in gameData.Classes where g.ClassType == ClassType.Solid orderby String.Equals(g.Name, def, StringComparison.InvariantCultureIgnoreCase) ? 0 : 1, String.Equals(g.Name, "trigger_once", StringComparison.InvariantCultureIgnoreCase) ? 0 : 1, g.Description.ToLower() select g ).FirstOrDefault() ?? new GameDataObject("trigger_once", "", ClassType.Solid); if (existing == null) { // If the entity doesn't exist we need to create it existing = new Entity(document.Map.NumberGenerator.Next("MapObject")) { Data = { new EntityData { Name = defaultEntityClass.Name }, new ObjectColor(Colour.GetDefaultEntityColour()) } }; ops.Add(new Attach(document.Map.Root.ID, existing)); } else { // If the entity is a descendant of the selection, it would cause havok ops.Add(new Detatch(existing.Hierarchy.Parent.ID, existing)); ops.Add(new Attach(document.Map.Root.ID, existing)); } // Any other entities in the selection should be destroyed foreach (var entity in existingEntities.Where(x => !ReferenceEquals(x, existing))) { var children = entity.Hierarchy.Where(x => !(x is Entity)).ToList(); ops.Add(new Detatch(entity.ID, children)); ops.Add(new Attach(existing.ID, children)); ops.Add(new Detatch(entity.Hierarchy.Parent.ID, entity)); } // All other parents should be added to the entity foreach (var obj in document.Selection.GetSelectedParents().Except(existingEntities)) { ops.Add(new Detatch(obj.Hierarchy.Parent.ID, obj)); ops.Add(new Attach(existing.ID, obj)); } if (ops.Any()) { ops.Add(new Select(document.Selection.Except(existingEntities).Union(new[] { existing }))); await MapDocumentOperation.Perform(document, new Transaction(ops)); await Oy.Publish("Context:Add", new ContextInfo("BspEditor:ObjectProperties")); } }
protected override async Task Invoke(MapDocument document, CommandParameters parameters) { var objects = document.Selection.OfType <Solid>().ToList(); // Prompt the user for the wall width. If more than 1 solid is selected, show a little warning notice. var qf = new QuickForm(PromptTitle) { UseShortcutKeys = true }; if (objects.Count > 1) { qf.Label(String.Format(WarningMessage, objects.Count)); } qf.NumericUpDown("Width", PromptWallWidth, -1024, 1024, 0, 32); qf.OkCancel(OK, Cancel); if (await qf.ShowDialogAsync() != DialogResult.OK) { return; } var width = (float)qf.Decimal("Width"); var ops = new List <IOperation>(); foreach (var obj in objects) { var split = false; var solid = obj; // Make a scaled version of the solid for the "inside" of the hollowed solid var origin = solid.BoundingBox.Center; var current = obj.BoundingBox.Dimensions; var target = current - new Vector3(width, width, width) * 2; // Double the width to take from both sides // Ensure we don't have any invalid target sizes if (target.X < 1) { target.X = 1; } if (target.Y < 1) { target.Y = 1; } if (target.Z < 1) { target.Z = 1; } // Clone and scale the solid var scale = Vector3.Divide(target, current); var carver = (Solid)solid.Clone(); carver.Transform(Matrix4x4.CreateTranslation(-origin) * Matrix4x4.CreateScale(scale) * Matrix4x4.CreateTranslation(origin)); // For a negative width, we want the original solid to be the inside instead if (width < 0) { var temp = carver; carver = solid; solid = temp; } // Carve the outside solid with the inside solid foreach (var plane in carver.Faces.Select(x => x.Plane)) { // Split solid by plane Solid back, front; try { if (!solid.Split(document.Map.NumberGenerator, plane, out back, out front)) { continue; } } catch { // We're not too fussy about over-complicated carving, just get out if we've broken it. break; } split = true; if (front != null) { // Retain the front solid if (solid.IsSelected) { front.IsSelected = true; } ops.Add(new Attach(obj.Hierarchy.Parent.ID, front)); } if (back == null || !back.IsValid()) { break; } // Use the back solid as the new clipping target if (solid.IsSelected) { back.IsSelected = true; } solid = back; } if (!split) { continue; } ops.Add(new Detatch(obj.Hierarchy.Parent.ID, obj)); } if (ops.Any()) { await MapDocumentOperation.Perform(document, new Transaction(ops)); } }
public abstract List<Control> GetControls(QuickForm qf);
void OnFormClosing(object sender, CancelEventArgs cancelEventArgs) => openedForm = null;
public abstract List <Control> GetControls(QuickForm qf);