public void DeleteElement(BaseElement el) { if ((el == null) || (el is ConnectorElement)) return; //Delete link if (el is BaseLinkElement) { var lnk = (BaseLinkElement) el; DeleteLink(lnk); return; } //Delete node if (el is NodeElement) { var conn = ((NodeElement) el); foreach (var elconn in conn.Connectors) { for (var i = elconn.Links.Count - 1; i>=0; i--) { var lnk = (BaseLinkElement) elconn.Links[i]; DeleteLink(lnk); } } if (SelectedNodes.Contains(el)) SelectedNodes.Remove(el); } if (SelectedElements.Contains(el)) SelectedElements.Remove(el); Elements.Remove(el); OnAppearancePropertyChanged(new EventArgs()); }
private void SelectedElement(T item) { if (!SelectedElements.Any(e => e.Equals(item))) { SelectedElements.Add(item); } }
private void OnTreeSelectionChanged(object sender, EventArgs e) { var info = _treeControl.SelectedItemInfo; if (info.Branch != null) { var options = 0; var selObj = info.Branch.GetObject(info.Row, info.Column, TreeGridDesignerBranch.BrowsingObject, ref options); if (selObj != null) { var willNotUpdateSelection = SelectedElements.Contains(selObj); SetSelectedComponents(new[] { selObj }); // SetSelectedComponents will not fire selection events if the row has not changed // the column might have changed so we keep/compare state in order to fire the event if ((_previouslySelectedColumn == null || TreeControl.CurrentColumn != _previouslySelectedColumn) && willNotUpdateSelection) { OnSelectionChanged(EventArgs.Empty); } _previouslySelectedColumn = TreeControl.CurrentColumn; } else { SetSelectedComponents(new object[] { }); } } }
/// <summary> /// Reads a portion of a binary stream to populate this building config. /// </summary> /// <param name="binaryReader">The <see cref="BinaryReader"/> encapsulating the binary information to read</param> /// <returns>True if the read succeeded, false otherwise</returns> public bool ReadBinary(BinaryReader binaryReader) { try { Offset = new Vector2I(binaryReader.ReadInt32(), binaryReader.ReadInt32()); BuildingDef = Assets.GetBuildingDef(binaryReader.ReadString()); int selectedElementCount = binaryReader.ReadInt32(); for (int i = 0; i < selectedElementCount; ++i) { Tag elementTag; //Only add the tag to the list if it describes a valid element in game. if (ElementLoader.GetElement(elementTag = new Tag(binaryReader.ReadInt32())) != null) { SelectedElements.Add(elementTag); } } Orientation = (Orientation)binaryReader.ReadInt32(); Flags = binaryReader.ReadInt32(); return(true); } catch (System.Exception) { return(false); } }
/// <summary> /// 删除选中元素 /// </summary> /// <param name="element"></param> private void SelectedElementRemove(UIElement element) { if (SelectedElements.Contains(element)) { SelectedElements.Remove(element); ((IControlBase)element).SetUnFocus(); } }
/// <summary> /// 添加选中元素 /// </summary> /// <param name="element"></param> private void SelectedElementAdd(UIElement element) { if (!SelectedElements.Contains(element)) { SelectedElements.Add(element); this.ReorderZindex(); ((IControlBase)element).SetFocus(); } }
public override void SetupCustomUIElements(object ui) { var nodeUI = ui as dynNodeView; //add a button to the inputGrid on the dynElement _selectButton = new dynNodeButton { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center }; _selectButton.Click += selectButton_Click; _tb = new TextBlock { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center, Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)), TextWrapping = TextWrapping.Wrap, TextTrimming = TextTrimming.WordEllipsis, MaxWidth = 200, MaxHeight = 100 }; if (SelectedElements == null || !SelectedElements.Any() || !SelectionText.Any() || !SelectButtonContent.Any()) { SelectionText = "Nothing Selected"; SelectButtonContent = "Select Instances"; } nodeUI.inputGrid.RowDefinitions.Add(new RowDefinition()); nodeUI.inputGrid.RowDefinitions.Add(new RowDefinition()); nodeUI.inputGrid.Children.Add(_tb); nodeUI.inputGrid.Children.Add(_selectButton); System.Windows.Controls.Grid.SetRow(_selectButton, 0); System.Windows.Controls.Grid.SetRow(_tb, 1); _tb.DataContext = this; _selectButton.DataContext = this; var selectTextBinding = new System.Windows.Data.Binding("SelectionText") { Mode = BindingMode.TwoWay, }; _tb.SetBinding(TextBlock.TextProperty, selectTextBinding); var buttonTextBinding = new System.Windows.Data.Binding("SelectButtonContent") { Mode = BindingMode.TwoWay, }; _selectButton.SetBinding(ContentControl.ContentProperty, buttonTextBinding); }
public void WriteBinary(BinaryWriter binaryWriter) { binaryWriter.Write(Offset.X); binaryWriter.Write(Offset.y); binaryWriter.Write(BuildingDef.PrefabID); binaryWriter.Write(SelectedElements.Count); SelectedElements.ForEach(selectedElement => binaryWriter.Write(selectedElement.GetHash())); binaryWriter.Write((int)Orientation); binaryWriter.Write(Flags); }
private void HandleDragOver(T item) { if (!item.Equals(draggedItem)) { var dragElementIndex = SelectedElements.IndexOf(draggedItem); var elementIndex = SelectedElements.IndexOf(item); SelectedElements[elementIndex] = draggedItem; SelectedElements[dragElementIndex] = item; } }
public void SelectElement(BaseElement el) { SelectedElements.Add(el); if (el is NodeElement) { SelectedNodes.Add(el); } if (_canFireEvents) OnElementSelection(this, new ElementSelectionEventArgs(SelectedElements)); }
//TODO: This has not been revisited yet. /* * private void MouseMove_DragMoving_OLD(MouseEventArgs e) * { * Point gridLocation = TranslateLocation(e.Location); * * // if we don't have anything selected, there's no point dragging anything... * if (SelectedElements.Count() == 0) * return; * * Point d = new Point(e.X - m_lastMouseLocation.X, e.Y - m_lastMouseLocation.Y); * m_lastMouseLocation = e.Location; * * // calculate the points at which we should start dragging; ie. account for any selected elements. * // (we subtract VisibleTimeStart to make it relative to the control, instead of the grid canvas.) * TimeSpan earliestTime = GetEarliestTimeForElements(SelectedElements); * TimeSpan latestTime = GetLatestTimeForElements(SelectedElements); * int leftBoundary = (int)timeToPixels(earliestTime - VisibleTimeStart + DragTimeLeftOver); * int rightBoundary = (int)timeToPixels(latestTime - VisibleTimeStart + DragTimeLeftOver); * * // if the mouse moved left, only add it to the scroll size if: * // 1) the elements are hard left (or more) in the viewport * // 2) the elements are hard right, and we are moving right. This provides deceleration. * // Cap this value to 0. * if (d.X < 0) * { * if (leftBoundary <= 0) * m_dragAutoscrollDistance.Width += d.X; * else if (rightBoundary >= ClientSize.Width && m_dragAutoscrollDistance.Width > 0) * m_dragAutoscrollDistance.Width = Math.Max(0, m_dragAutoscrollDistance.Width + d.X); * } * * // if the mouse moved right, do the inverse of the above rules. * if (d.X > 0) * { * if (rightBoundary >= ClientSize.Width) * m_dragAutoscrollDistance.Width += d.X; * else if (leftBoundary <= 0 && m_dragAutoscrollDistance.Width < 0) * m_dragAutoscrollDistance.Width = Math.Min(0, m_dragAutoscrollDistance.Width + d.X); * } * * // if the left and right boundaries are within the viewport, then stop all * // horizontal scrolling. This can happen if the user scrolls, and mouse-wheels * // (to zoom out). the control is stuck scrolling, and can't be stopped. * if (leftBoundary > 0 && rightBoundary < ClientSize.Width) * m_dragAutoscrollDistance.Width = 0; * * m_dragAutoscrollDistance.Height = (e.Y < 0) ? e.Y : ((e.Y > ClientSize.Height) ? e.Y - ClientSize.Height : 0); * * // if we're scrolling, start the timer if needed. If not, vice-versa. * if (m_dragAutoscrollDistance.Width != 0 || m_dragAutoscrollDistance.Height != 0) * { * if (!ScrollTimer.Enabled) * ScrollTimer.Start(); * } * else * { * if (ScrollTimer.Enabled) * ScrollTimer.Stop(); * } * * // only move the elements here if we aren't going to be auto-dragging while scrolling in the timer events. * if (d.X != 0 && m_dragAutoscrollDistance.Width == 0) * { * TimeSpan desiredMoveTime = DragTimeLeftOver + pixelsToTime(d.X); * TimeSpan realMoveTime = OffsetElementsByTime(SelectedElements, desiredMoveTime); * DragTimeLeftOver = desiredMoveTime - realMoveTime; * } * * // if we've moved vertically, we may need to move elements between rows * if (d.Y != 0 && !ResizingElement) * { * MoveElementsVerticallyToLocation(SelectedElements, gridLocation); * } * } */ /// <summary> /// Handles mouse move events while in the "Moving" state. /// </summary> /// <param name="gridLocation">Mouse location on the grid.</param> private void MouseMove_DragMoving(Point gridLocation) { // if we don't have anything selected, there's no point dragging anything... if (!SelectedElements.Any()) { return; } TimeSpan dt = pixelsToTime(gridLocation.X - m_elemMoveInfo.InitialGridLocation.X); int dy = gridLocation.Y - m_elemMoveInfo.InitialGridLocation.Y; // If we didn't move, get outta here. if (dt == TimeSpan.Zero && dy == 0) { return; } // Calculate what our actual dt value will be. TimeSpan earliest = m_elemMoveInfo.OriginalElements.Values.Min(x => x.StartTime); if ((earliest + dt) < TimeSpan.Zero) { dt = -earliest; } TimeSpan latest = m_elemMoveInfo.OriginalElements.Values.Max(x => x.EndTime); if ((latest + dt) > TimeInfo.TotalTime) { dt = TimeInfo.TotalTime - latest; } // modify the dt time based on snap points (ie. marks, and borders of other elements) dt = FindSnapTimeForElements(SelectedElements, dt, ResizeZone.None); foreach (var elem in SelectedElements) { // Get this elemenent's original times (before resize started) ElementTimeInfo orig = m_elemMoveInfo.OriginalElements[elem]; elem.StartTime = orig.StartTime + dt; //Control when the time changed event happens. elem.UpdateNotifyTimeChanged(); } // if we've moved vertically, we may need to move elements between rows if (dy != 0) { SuppressInvalidate = true; MoveElementsVerticallyToLocation(SelectedElements, gridLocation); SuppressInvalidate = false; } Invalidate(); }
public void Update(Command command) { if (command.CommandDefinition is DeleteCommandDefinition) { command.Enabled = SelectedElements.Any() || Connections.Any(x => x.IsSelected); } else if (command.CommandDefinition is DrawConnectLineCommandDefinition) { command.Enabled = true; } }
public void SelectElements(Rectangle selectionRectangle) { SelectedElements.EnabledCalc = false; SelectedNodes.EnabledCalc = false; // Add all "hitable" elements foreach (BaseElement element in Elements) { if (!(element is IControllable)) { continue; } var ctrl = ((IControllable)element).GetController(); if (!ctrl.HitTest(selectionRectangle)) { continue; } if (!(element is ConnectorElement)) { SelectedElements.Add(element); } if (element is NodeElement) { SelectedNodes.Add(element); } } //if the seleciont isn't a expecific link, remove links // without 2 elements in selection if (SelectedElements.Count > 1) { foreach (BaseElement el in Elements) { var lnk = el as BaseLinkElement; if (lnk == null) { continue; } if ((!SelectedElements.Contains(lnk.Connector1.ParentElement)) || (!SelectedElements.Contains(lnk.Connector2.ParentElement))) { SelectedElements.Remove(lnk); } } } SelectedElements.EnabledCalc = true; SelectedNodes.EnabledCalc = true; OnElementSelection(this, new ElementSelectionEventArgs(SelectedElements)); }
private void UpdateButtons() { buttonRunHelperSetup.Enabled = comboBoxSetupHelperType.SelectedIndex >= 0; buttonAddTemplate.Enabled = comboBoxNewItemType.SelectedIndex >= 0; List <ElementNode> elementList = SelectedElements.ToList(); buttonRunHelperSetup.Enabled = (elementList.Any()); buttonAddProperty.Enabled = (elementList.Any()); buttonRemoveProperty.Enabled = listViewProperties.Items.Count > 0 && listViewProperties.SelectedItems.Count > 0; buttonConfigureProperty.Enabled = listViewProperties.Items.Count > 0 && listViewProperties.SelectedItems.Count == 1; }
/// <summary> /// 删除所有元素 /// </summary> private void SelectedElementRemoveAll() { if (SelectedElements == null || SelectedElements.Count == 0) { return; } for (int i = SelectedElements.Count - 1; i >= 0; i--) { ((IControlBase)SelectedElements[i]).SetUnFocus(); SelectedElements.RemoveAt(i); } }
/// <summary> /// Reads a JSON object to populate this building config. /// </summary> /// <param name="rootObject">The <see cref="JObject"/> to use to read from</param> public void ReadJSON(JObject rootObject) { JToken offsetToken = rootObject.SelectToken("offset"); JToken buildingDefToken = rootObject.SelectToken("buildingdef"); JToken selectedElementsToken = rootObject.SelectToken("selected_elements"); JToken orientationToken = rootObject.SelectToken("orientation"); JToken flagsToken = rootObject.SelectToken("flags"); if (offsetToken != null && offsetToken.Type == JTokenType.Object) { JToken xToken = offsetToken.SelectToken("x"); JToken yToken = offsetToken.SelectToken("y"); if (xToken != null && xToken.Type == JTokenType.Integer || yToken != null && yToken.Type == JTokenType.Integer) { Offset = new Vector2I(xToken == null ? 0 : xToken.Value <int>(), yToken == null ? 0 : yToken.Value <int>()); } } if (buildingDefToken != null && buildingDefToken.Type == JTokenType.String) { BuildingDef = Assets.GetBuildingDef(buildingDefToken.Value <string>()); } if (selectedElementsToken != null && selectedElementsToken.Type == JTokenType.Array) { JArray selectedElementTokens = selectedElementsToken.Value <JArray>(); if (selectedElementTokens != null) { foreach (JToken selectedElement in selectedElementTokens) { Tag elementTag; if (selectedElement.Type == JTokenType.Integer && ElementLoader.GetElement(elementTag = new Tag(selectedElement.Value <int>())) != null) { SelectedElements.Add(elementTag); } } } } if (orientationToken != null && orientationToken.Type == JTokenType.Integer) { Orientation = (Orientation)orientationToken.Value <int>(); } if (flagsToken != null && flagsToken.Type == JTokenType.Integer) { Flags = flagsToken.Value <int>(); } }
/// <summary> /// Writes the building config to the given JSON writer. /// Doesn't write unnecessary information to save space. /// </summary> /// <param name="jsonWriter">The <see cref="JsonWriter"/> encsapsulating the stream to write to</param> public void WriteJSON(JsonWriter jsonWriter) { if (BuildingDef == null) { Debug.Log("Error when writing building config: No building definition."); return; } jsonWriter.WriteStartObject(); if (Offset.x != 0 || Offset.y != 0) { jsonWriter.WritePropertyName("offset"); jsonWriter.WriteStartObject(); if (Offset.x != 0) { jsonWriter.WritePropertyName("x"); jsonWriter.WriteValue(Offset.x); } if (Offset.y != 0) { jsonWriter.WritePropertyName("y"); jsonWriter.WriteValue(Offset.y); } jsonWriter.WriteEndObject(); } jsonWriter.WritePropertyName("buildingdef"); jsonWriter.WriteValue(BuildingDef.PrefabID); jsonWriter.WritePropertyName("selected_elements"); jsonWriter.WriteStartArray(); SelectedElements.ForEach(elementTag => jsonWriter.WriteValue(elementTag.GetHash())); jsonWriter.WriteEndArray(); if (Orientation != 0) { jsonWriter.WritePropertyName("orientation"); jsonWriter.WriteValue((int)Orientation); } if (Flags != 0) { jsonWriter.WritePropertyName("flags"); jsonWriter.WriteValue(Flags); } jsonWriter.WriteEndObject(); }
public void OnSelectionChanged() { var selectedElements = SelectedElements.ToList(); if (selectedElements.Count == 1) { _inspectorTool.SelectedObject = new InspectableObjectBuilder() .WithObjectProperties(selectedElements[0], x => true) .ToInspectableObject(); } //else // _inspectorTool.SelectedObject = null; }
protected override void OnSelectClick() { if (SelectedElements != null) { SelectedElements.Clear(); SelectedElements = null; } SelectedElements = dynRevitSettings.SelectionHelper .RequestMultipleCurveElementsSelection("Select a set of Revit Elements."); RaisePropertyChanged("SelectionText"); }
public void DeleteLink(BaseLinkElement lnk, bool callHandler = true) { if (lnk == null) return; lnk.Connector1.RemoveLink(lnk); lnk.Connector2.RemoveLink(lnk); if (Elements.Contains(lnk)) Elements.Remove(lnk); if (SelectedElements.Contains(lnk)) SelectedElements.Remove(lnk); if (callHandler) OnLinkRemoved(new ElementEventArgs(lnk)); OnAppearancePropertyChanged(new EventArgs()); }
private void DoSelection(UIElement source) { var fElement = source as FrameworkElement; if (fElement != null) { // Save a reference to the adorned UIElement for removing later SelectedUiElement.Add(source); SelectedElements.Add(fElement.DataContext as ShapeViewModel); SelectedElement = fElement.DataContext as ShapeViewModel; AddAdorner(source); setRibbonSelection(true); } }
private void HighlightOnlySelectedElements() { Cursor = Cursors.Arrow; FirstResizeVisual.IsVisible = false; SecondResizeVisual.IsVisible = false; foreach (var element in HighlightBoxVisuals.Where(x => !SelectedElements.Contains(x.Key)).Select(x => x.Value)) { element.Opacity = 0.0; } highlighted.Clear(); }
public void WriteBinary(BinaryWriter binaryWriter) { if (BuildingDef == null) { Debug.Log("Error when writing building config: No building definition."); return; } binaryWriter.Write(Offset.X); binaryWriter.Write(Offset.y); binaryWriter.Write(BuildingDef.PrefabID); binaryWriter.Write(SelectedElements.Count); SelectedElements.ForEach(selectedElement => binaryWriter.Write(selectedElement.GetHash())); binaryWriter.Write((int)Orientation); binaryWriter.Write(Flags); }
private void beginDragSelect(Point gridLocation) { m_dragState = DragState.Selecting; if (!ShiftPressed) { ClearSelectedElements(); } else { tempSelectedElements = SelectedElements.ToList(); } ClearSelectedRows(m_mouseDownElementRow); ClearActiveRows(m_mouseDownElementRow); SelectionArea = new Rectangle(gridLocation.X, gridLocation.Y, 0, 0); m_selectionRectangleStart = gridLocation; }
private void InternalSelectedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (SuppressNotificationsCounter > 0) { return; } try { SuppressNotifications(); switch (e.Action) { case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Replace: if (e.OldItems != null) { foreach (var item in e.OldItems.Cast <FieldExposer <T_Item> >()) { if (SelectedElements.Contains(item.InnerItem)) { SelectedElements.Remove(item.InnerItem); } } } if (e.NewItems != null) { foreach (var item in e.NewItems.Cast <FieldExposer <T_Item> >()) { if (!SelectedElements.Contains(item.InnerItem)) { SelectedElements.Add(item.InnerItem); } } } break; case NotifyCollectionChangedAction.Reset: SelectedElements.Clear(); break; } } finally { AllowNotifications(); } }
private void Button_OnClick(UIElement sender) { ISelectable element = (sender as ISelectable); if (element.GetStatus()) { SelectedElements.Add(element); } else { SelectedElements.Remove(element); } if (SelectedCountChanded != null) { SelectedCountChanded(SelectedElements.Count); } }
public void DeleteElement(BaseElement el) { if ((el != null) && !(el is ConnectorElement)) { //Delete link if (el is BaseLinkElement) { BaseLinkElement lnk = (BaseLinkElement)el; DeleteLink(lnk); return; } //Delete node if (el is NodeElement) { NodeElement conn = ((NodeElement)el); foreach (ConnectorElement elconn in conn.Connectors) { BaseLinkElement lnk; for (int i = elconn.Links.Count - 1; i >= 0; i--) { lnk = (BaseLinkElement)elconn.Links[i]; DeleteLink(lnk); } } if (selectedNodes.Contains(el)) { selectedNodes.Remove(el); } } if (SelectedElements.Contains(el)) { selectedElements.Remove(el); } elements.Remove(el); el.OnRemovedFromDocument(new DocumentEventArgs { Document = this }); OnAppearancePropertyChanged(new EventArgs()); } el = null; }
public void SelectAllElements() { SelectedElements.EnabledCalc = false; SelectedNodes.EnabledCalc = false; foreach(BaseElement element in Elements) { if (!(element is ConnectorElement)) SelectedElements.Add(element); if (element is NodeElement) SelectedNodes.Add(element); } SelectedElements.EnabledCalc = true; SelectedNodes.EnabledCalc = true; }
public void DeleteLink(BaseLinkElement linkElement) { if (linkElement != null) { linkElement.Connector1.RemoveLink(linkElement); linkElement.Connector2.RemoveLink(linkElement); if (_elements.Contains(linkElement)) { _elements.Remove(linkElement); } if (SelectedElements.Contains(linkElement)) { SelectedElements.Remove(linkElement); } OnAppearancePropertyChanged(new EventArgs()); } }
/// <summary> /// Act when the source collection has been changed. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The kind of modification</param> private void Source_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { Elements.Add(new FieldExposer <T_Item>(DataAccessor, (T_Item)item)); } break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: if (e.OldItems.Count == 1) { T_Item item = (T_Item)e.OldItems[0]; var found = Elements.Where(element => element.InnerItem.Equals(item)).FirstOrDefault(); if (found == null) { throw new InvalidOperationException("Unexpected behavior: element not in list!"); } Elements.Remove(found); var selected = SelectedElements.Where(element => element.Equals(item)).FirstOrDefault(); if (selected != null) { SelectedElements.Remove(selected); } } else { throw new InvalidOperationException("Cannot remove more than one item at once!"); } break; default: Elements = new ObservableCollection <FieldExposer <T_Item> >(); foreach (var item in (ObservableCollection <T_Item>)sender) { Elements.Add(new FieldExposer <T_Item>(DataAccessor, (T_Item)item)); } RaisePropertyChanged("Elements"); break; } }