/// <summary> /// /// </summary> /// <param name="item"></param> protected override void SetCopyOfTag(DiagramDesigner.DesignerItem item) { string name = item.Renderer.Text; DiagramDesigner.DesignerItem dItem = GetDesignerItemByName(name); if (dItem == null) { return; } object tag = ((DiagramDesigner.DesignerItem)dItem).Tag; if (tag != null && (tag is Entity || tag is string)) { JavaScriptSerializer serial = new JavaScriptSerializer(); Entity entity = (tag is Kernel.Domain.Entity) ? (Entity)tag : serial.Deserialize <Kernel.Domain.Entity>((string)tag); entity = entity.GetCopy(); entity.name = getNewName(entity.name, true); item.Tag = entity; item.Renderer.Text = entity.name; } else { item.Tag = tag; } }
protected override void onEdit(DiagramDesigner.DesignerItem item, string name) { if (item != null && item.Tag != null && item.Tag is Entity) { DiagramDesigner.DesignerItem block = GetBlockByName(name); Entity entity = (Entity)item.Tag; if (string.IsNullOrWhiteSpace(name)) { Kernel.Util.MessageDisplayer.DisplayError("Empty name", "The name can't be empty!"); item.Renderer.Text = entity.name; EditCurrentSelection(); return; } if (block != null && !block.Equals(item)) { Kernel.Util.MessageDisplayer.DisplayError("Duplicate name", "There is another block named: " + name + "."); item.Renderer.Text = entity.name; EditCurrentSelection(); return; } entity.name = name; this.SelectionService.SelectItem(item); notifyModifyBlock(item); } }
public DesignerItem ChangeParent(DesignerItem designerItem) { HideOthers(designerItem); var newParent = GetNewParent(designerItem); _diagramControl.DesignerItems.ToList().ForEach(x => { x.IsNewParent = false; }); if (newParent != null) newParent.IsNewParent = true; return newParent; }
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e) { this.designerItem = DataContext as DesignerItem; if (this.designerItem != null) { this.designerCanvas = VisualTreeHelper.GetParent(this.designerItem) as DesignerCanvas; } }
void HideOthers/*隐藏了除了drag item以外的selected items*/ (DesignerItem selectedItem) { var selectedItems = GetSelectedItems(); selectedItem.IsExpanderVisible = false; foreach (var designerItem in selectedItems.Where(x => x.ItemId != selectedItem.ItemId)) { designerItem.Visibility = Visibility.Hidden; } }
public void FinishChangeParent(DesignerItem newParent) { ShowOthers(); /*恢复显示选中元素,之前调用了HideOthers隐藏了除了drag item以外的selected items*/ RemoveHelperConnection(); /*移除找parent的辅助红线*/ ChangeShadowConnectionsToOriginalItem(); /*将连接到shadow上的连线,恢复到item上*/ _diagramControl.DesignerItems.ToList().ForEach(x => { x.IsNewParent = false; x.YIndex = Canvas.GetTop(x); }); ConnectToNewParent(newParent); /*根据取得的newParent,改变特定item的连线*/ RemoveShadows(); /*移除所有shadow*/ ArrangeWithRootItems(); /*重新布局*/ }
private void SetItemFontColor/*设定元素文字颜色*/ (DesignerItem item, SolidColorBrush fontColorBrush) { var textBlock = GetTextBlock(item); if (textBlock == null) { return; } textBlock.SetValue(TextBlock.ForegroundProperty, fontColorBrush); }
public void notifyModifyBlock(DesignerItem item) { if (ModifyBlock != null) { ModifyBlock(item); } if (Changed != null) { Changed(); } }
private void raiseDesignerItemRemoved(object item, DesignerItem designerItem) { var x = ItemRemoved; if (x != null) { x(item, designerItem); } raiseDesignerCanvasChanged(); }
public DesignerItem AddDesignerItem(FrameworkElement item, Point position, Size?size, int layer = 0, bool insertInBackground = false, Guid?itemGuid = null) { DesignerItem newItem = new DesignerItem(); if (itemGuid != null) { newItem.ID = itemGuid.Value; } newItem.Content = item; newItem.Layer = layer; if (size.HasValue) { newItem.Width = size.Value.Width; newItem.Height = size.Value.Height; } DesignerCanvas.SetLeft(newItem, position.X); DesignerCanvas.SetTop(newItem, position.Y); //Canvas.SetZIndex(newItem, this.Children.Count); newItem.ZIndex = this.Children.Count; if (insertInBackground) { newItem.ZIndex = 0; this.Children.Insert(0, newItem); } else { this.Children.Add(newItem); } SetConnectorDecoratorTemplate(newItem); //update selection //this.SelectionService.SelectItem(newItem); //newItem.Focus(); raiseDesignerItemAdded(item, newItem); bool layerVisible = false; if (!visibleLayers.TryGetValue(layer, out layerVisible) || layerVisible) { item.Visibility = System.Windows.Visibility.Visible; } else { item.Visibility = System.Windows.Visibility.Hidden; } //updateVisibleDesigneritems(); return(newItem); }
void Scroll(DesignerItem designerItem) { if (designerItem == null) { return; } var sv = (ScrollViewer)_diagramControl.Template.FindName("DesignerScrollViewer", _diagramControl); sv.ScrollToVerticalOffset(Canvas.GetTop(designerItem) - 400); sv.ScrollToHorizontalOffset(Canvas.GetLeft(designerItem) - 400); }
public void notifyAddBlock(DesignerItem item) { if (AddBlock != null) { AddBlock(item); } if (Changed != null) { Changed(); } }
public Connector GetConnector(object item, String connectorName) { DesignerItem designerItem = (from i in this.Children.OfType <DesignerItem>() where i.Content == item select i).FirstOrDefault(); Control connectorDecorator = designerItem.Template.FindName("PART_ConnectorDecorator", designerItem) as Control; connectorDecorator.ApplyTemplate(); return(connectorDecorator.Template.FindName(connectorName, connectorDecorator) as Connector); }
protected override void OnMouseUp(MouseButtonEventArgs e) { if (HitConnector != null && !HitConnector.ConnectorHasConnected && !this.sourceConnector.ConnectorHasConnected && this.sourceConnector.NextType == this.HitConnector.SelfType) { Connector sourceConnector = this.sourceConnector; Connector sinkConnector = this.HitConnector; Connection newConnection = new Connection(sourceConnector, sinkConnector); DesignerItem sourceDesignerItem = sourceConnector.ParentDesignerItem; DesignerItem sinkDesignerItem = sinkConnector.ParentDesignerItem; sourceDesignerItem.leftConnectionList.Add(newConnection); sinkDesignerItem.rightConnectionList.Add(newConnection); if (sinkDesignerItem.ItemType.Equals("ConditionAndExp") && sourceDesignerItem.ItemType.Equals("Condition")) { this.designerCanvas.AndConnectionList.Add(newConnection); //ComboBox tempBox = sinkConnector.Content as ComboBox; //this.designerCanvas.andOrder[sourceConnector.ParentDesignerItem.ItemOrder] = ((ComboBoxItem)tempBox.SelectedItem).Content.ToString(); } if (sinkDesignerItem.ItemType.Equals("ConditionOrExp") && sourceDesignerItem.ItemType.Equals("Condition")) { this.designerCanvas.OrConnectionList.Add(newConnection); //this.designerCanvas.orOrder.Add(sourceConnector.ParentDesignerItem.ItemOrder); } //DesignerItem parentItem = sourceConnector.ParentDesignerItem; //DesignerItem childItem = sinkConnector.ParentDesignerItem; //parentItem.childNodeItem.Add(childItem); sinkConnector.ConnectorHasConnected = sinkConnector.DataType != ConnectorDataType.MultiLinker ? true : false; sourceConnector.ConnectorHasConnected = sourceConnector.DataType != ConnectorDataType.MultiLinker ? true : false; Canvas.SetZIndex(newConnection, designerCanvas.Children.Count); this.designerCanvas.Children.Add(newConnection); //this.designerCanvas.connectionList.Add(newConnection); } if (HitDesignerItem != null) { this.HitDesignerItem.IsDragConnectionOver = false; } if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas); if (adornerLayer != null) { adornerLayer.Remove(this); } }
private void SetConnectorDecoratorTemplate(DesignerItem item) { /* * if (item.ApplyTemplate() && item.Content is UIElement) * { * ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement); * Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; * if (decorator != null && template != null) * decorator.Template = template; * } */ }
void DrawDesignerItem/*创建元素*/ (DesignerItem item, double topOffset = 0d, double leftOffset = 0d) { if (item.Data == null) { return; } GenerateDesignerItemContent(item, DEFAULT_FONT_COLOR_BRUSH); _diagramControl.DesignerCanvas.Children.Add(item); _diagramControl.UpdateLayout(); Canvas.SetTop(item, topOffset); Canvas.SetLeft(item, leftOffset); }
private DesignerItem CreateItem(BaseResource resource, int size) { DesignerItem item = new DesignerItem(resource.Name, resource.DesignerID); item.Width = size; item.Height = size; item.BoundLogicItem = resource; item.dispName = resource.Name; item.Tag = resource.Name; return(item); }
Connector GetItemConnector/*根据名称,取得元素连接点*/ (DesignerItem item, string name) { var itemConnectorDecorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; if (itemConnectorDecorator == null) { return(null); } var itemConnector = itemConnectorDecorator.Template.FindName(name, itemConnectorDecorator) as Connector; return(itemConnector); }
public DesignerItem ChangeParent(DesignerItem designerItem) { HideOthers(designerItem); var newParent = GetNewParent(designerItem); _diagramControl.DesignerItems.ToList().ForEach(x => { x.IsNewParent = false; }); if (newParent != null) { newParent.IsNewParent = true; } return(newParent); }
protected void SetConnectorDecoratorTemplate(DesignerItem item) { if (item.ApplyTemplate() && item.Content is UIElement) { ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement); Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; if (decorator != null && template != null) { decorator.Template = template; } } }
private Connector GetConnector(Guid itemID, String connectorName) { DesignerItem designerItem = (from item in this.Children.OfType <DesignerItem>() where item.ID == itemID select item).FirstOrDefault(); Control connectorDecorator = designerItem.Template.FindName("PART_ConnectorDecorator", designerItem) as Control; connectorDecorator.ApplyTemplate(); return(connectorDecorator.Template.FindName(connectorName, connectorDecorator) as Connector); }
public void MoveUpAndDown(DesignerItem parent, DesignerItem selectedItem) { if (parent == null) { return; } var itemTop = Canvas.GetTop(selectedItem) - selectedItem.ActualHeight / 2; var itemsOnCanvas = _diagramControl.DesignerCanvas.Children; var designerItemsOnCanvas = itemsOnCanvas.OfType <DesignerItem>().ToList(); var downItems = designerItemsOnCanvas.Where(x => x.Oldy > itemTop && x.ItemId != selectedItem.ItemId ).ToList();/*比元素大的,全部向下移*/ foreach (var designerItem in downItems) { Canvas.SetTop(designerItem, designerItem.Oldy + selectedItem.ActualHeight); } var upItems = designerItemsOnCanvas.Where(x => x.Oldy <itemTop && x.Oldy> Canvas.GetTop(parent) && x.ItemId != selectedItem.ItemId ).ToList();/*比父节点大的,比元素小的,恢复位置*/ foreach (var designerItem in upItems) { //Canvas.SetTop(designerItem, designerItem.Data.YIndex); //var item = designerItem.IsShadow ? designerItem.ShadowOrignal : designerItem; //var x1 = GetAllSubItems(item); //if (x1 == null || !x1.Any()) continue; //var list = designerItemsOnCanvas.Where(x => // x.Oldy <= x1.Aggregate((a, b) => a.Oldy > b.Oldy ? a : b).Oldy // && x.ID != selectedItem.ID // ).ToList(); //list.ForEach(x => { Canvas.SetTop(x, x.Data.YIndex); }); Canvas.SetTop(designerItem, designerItem.Oldy); var item = designerItem.IsShadow ? designerItem.ShadowOrignal : designerItem; var x1 = GetAllSubItems(item); if (x1 == null || !x1.Any()) { continue; } var list = designerItemsOnCanvas.Where(x => x.Oldy <= x1.Aggregate((a, b) => a.Oldy > b.Oldy ? a : b).Oldy && x.ItemId != selectedItem.ItemId ).ToList(); list.ForEach(x => { Canvas.SetTop(x, x.Oldy); }); } }
void DesignerItem_Loaded(object sender, RoutedEventArgs e) { if (base.Template != null) { ContentPresenter contentPresenter = this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter; if (contentPresenter != null) { UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement; if (contentVisual != null) { DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb; if (thumb != null) { ControlTemplate template = DesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate; if (template != null) { thumb.Template = template; } //Para que sea responsive this.Height = (double)contentVisual.GetAnimationBaseValue(HeightProperty); this.Width = (double)contentVisual.GetAnimationBaseValue(WidthProperty); /*Traigo la TAG del elemento hijo y la convierto en string*/ var tag = (contentVisual.GetAnimationBaseValue(TagProperty) ?? "").ToString(); if (tag == "DIAG") { this.Tag = "DIAG"; //Le pongo la TAG al item del diagram designer } else if (tag == "COND") //Si es un nodo_condicion le cambio la altura { this.Height = 60; } else if (tag == "REFR") { this.Tag = "REFR"; } /*Traigo el Uid del elemento hijo y la convierto en string*/ var uid = (contentVisual.GetAnimationBaseValue(UidProperty) ?? "").ToString(); if (uid == "Principal") { this.Uid = "Principal"; //Le pongo la uid al item del diagram designer } } } } } }
protected void AddNewBlock(UIElement block, object tag) { DesignerItem newItem = DisplayBlock(block, tag); if (AddBlock != null) { AddBlock(newItem); } if (Changed != null) { Changed(); } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(dragObject.Tag); newItem.Content = content; var temp = newItem as ContentControl; var abc = temp.Content as TextBox; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); EnsureComponentUniqueName(newItem); newItem.Focus(); } e.Handled = true; } }
public void DeleteFromList(DesignerItem item) { int index; int index_2; switch (item.ItemType) { case "Trigger": index = triggerList.IndexOf(item); triggerList.RemoveAt(index); break; case "Condition": index = conditionList.IndexOf(item); conditionList.RemoveAt(index); conditionLinker.Remove(item.ItemOrder); andOrder.Remove(item.ItemOrder); orOrder.Remove(item.ItemOrder); for (int i = 0; i < item.rightConnectionList.Count; ++i) { index_2 = AndConnectionList.IndexOf(item.rightConnectionList[i]); if (index_2 != -1) { AndConnectionList.RemoveAt(index_2); } index_2 = OrConnectionList.IndexOf(item.rightConnectionList[i]); if (index_2 != -1) { OrConnectionList.RemoveAt(index_2); } } break; case "ConditionAndExp": AndConnectionList.Clear(); andOrder.Clear(); break; case "ConditionOrExp": OrConnectionList.Clear(); orOrder.Clear(); break; case "Action": index = actionList.IndexOf(item); actionList.RemoveAt(index); actionLinker.Remove(item.ItemOrder); break; } }
private DesignerItem CreateDMP(Double OffsetY, Double OffsetX) { DesignerItem item = new DesignerItem("DMP", Guid.NewGuid()); //item size must be dynamically defined, this is temporary solution item.Width = 78; item.Height = 78; //item postion on canvas Canvas.SetLeft(item, OffsetX); Canvas.SetTop(item, OffsetY); return(item); }
private static DesignerItem DeserializeDesignerItem(XElement itemXML, Guid id, double OffsetX, double OffsetY) { DesignerItem item = new DesignerItem(id); item.Width = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture); item.Height = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture); item.ParentID = new Guid(itemXML.Element("ParentID").Value); item.IsGroup = Boolean.Parse(itemXML.Element("IsGroup").Value); Canvas.SetLeft(item, Double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + OffsetX); Canvas.SetTop(item, Double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + OffsetY); Canvas.SetZIndex(item, Int32.Parse(itemXML.Element("zIndex").Value)); Object content = XamlReader.Load(XmlReader.Create(new StringReader(itemXML.Element("Content").Value))); item.Content = content; return item; }
/// <summary> /// /// </summary> /// <param name="item"></param> protected override void SetCopyOfTag(DiagramDesigner.DesignerItem item) { string name = item.Renderer.Text; DiagramDesigner.DesignerItem dItem = GetDesignerItemByName(name); bool isCutMode = dItem == null; dItem = dItem != null ? dItem : item; object tag = ((DiagramDesigner.DesignerItem)dItem).Tag; if (tag != null && (tag is TransformationTreeItem || tag is string)) { JavaScriptSerializer serial = new JavaScriptSerializer(); TransformationTreeItem transformationTreeItem = tag is TransformationTreeItem ? (TransformationTreeItem)tag : serial.Deserialize <TransformationTreeItem>((string)tag); if (transformationTreeItem == null) { return; } TransformationTreeItem currenItem = null; if (transformationTreeItem.IsLoop) { currenItem = transformationTreeItem.GetCopy(isCutMode); } else if (transformationTreeItem.IsAction) { currenItem = transformationTreeItem.GetCopy(isCutMode); SourcingServiceFactory tableServiceFactory = new SourcingServiceFactory(Kernel.Application.ApplicationManager.Instance); currenItem = transformationTreeItem.setCopyReport(currenItem, tableServiceFactory.GetInputTableService()); Kernel.Service.TransformationTreeService treeService = new Kernel.Service.TransformationTreeService(); if (PastingAction != null) { PastingAction(item, currenItem); } } if (currenItem != null) { currenItem.name = getNewName(currenItem.name, true); item.Tag = currenItem; item.Renderer.Text = currenItem.name; ((DiagramDesigner.DesignerItem)dItem).Tag = transformationTreeItem; } } else { item.Tag = tag; } }
private DesignerItem CreateItem(Guid designerID, string name, Double OffsetY, Double OffsetX, int size) { DesignerItem item = new DesignerItem(designerID, name); //item size must be dynamically defined, this is temporary solution item.Width = size; item.Height = size; //item postion on canvas Canvas.SetLeft(item, OffsetX); Canvas.SetTop(item, OffsetY); return(item); }
private static Point changeColor(DesignerItem node, Brush color, Double thickness = 1) { Grid grid = (Grid)node.Content; Path shape = grid.Children[0] as Path; // Devuelve null si NO puede castearlo if (shape != null) { shape.Stroke = color; shape.StrokeThickness = thickness; } return(new Point(node.VisualOffset.X, node.VisualOffset.Y)); }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); Console.WriteLine("Dropped"); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; newItem.primaryField = (Window.GetWindow(this) as Window1).tbComponentName.Text; newItem.secondaryField = (Window.GetWindow(this) as Window1).tbComponentDesc.Text; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; Console.WriteLine("handled creation"); } }
public void RestoreDiagram(XElement root) { if (root == null) { return; } this.Children.Clear(); this.SelectionService.ClearSelection(); IEnumerable <XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem"); foreach (XElement itemXML in itemsXML) { Guid id = new Guid(itemXML.Element("ID").Value); DesignerItem item = DeserializeDesignerItem(itemXML, id, 0, 0); this.Children.Add(item); SetConnectorDecoratorTemplate(item); raiseDesignerItemAdded(item.Content, item); } this.InvalidateVisual(); IEnumerable <XElement> connectionsXML = root.Elements("Connections").Elements("Connection"); foreach (XElement connectionXML in connectionsXML) { Guid sourceID = new Guid(connectionXML.Element("SourceID").Value); Guid sinkID = new Guid(connectionXML.Element("SinkID").Value); String sourceConnectorName = connectionXML.Element("SourceConnectorName").Value; String sinkConnectorName = connectionXML.Element("SinkConnectorName").Value; PathFinderTypes pathFinder = (PathFinderTypes)Enum.Parse(typeof(PathFinderTypes), connectionXML.Element("PathFinder").Value); SolidColorBrush color = (SolidColorBrush) new BrushConverter().ConvertFromString(connectionXML.Element("Color").Value); double strokeThickness = Double.Parse(connectionXML.Element("StrokeThickness")?.Value); Connector sourceConnector = GetConnector(sourceID, sourceConnectorName); Connector sinkConnector = GetConnector(sinkID, sinkConnectorName); Connection connection = ConnectionGenerator(sourceConnector, sinkConnector, pathFinder); //Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value)); connection.ShowShadow = bool.Parse(connectionXML.Element("ShowShadow").Value); connection.ZIndex = Int32.Parse(connectionXML.Element("zIndex").Value); connection.Color = color; connection.StrokeThickness = strokeThickness; this.Children.Add(connection); } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); if (content.GetType() == typeof(ImageLayout)) { ((ImageLayout)content).ShowTitle(); } } e.Handled = true; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2; ; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }
/*取得直接子节点*/ List<DesignerItem> GetDirectSubItems(DesignerItem item) { var list = _diagramControl.DesignerItems.Where(x => x.ItemParentId == item.ItemId).OrderBy(x => x.YIndex).ToList(); if (item.CanCollapsed == false) { item.IsExpanderVisible = false; } else if (list.Any()) { item.IsExpanderVisible = true; } else { item.IsExpanderVisible = false; } return list; }
void thumbDragThumb_DragStarted(object sender, DragStartedEventArgs e) { this.HitDesignerItem = null; this.HitConnector = null; this.pathGeometry = null; this.Cursor = Cursors.Cross; this.connection.StrokeDashArray = new DoubleCollection(new double[] { 1, 2 }); if (sender == sourceDragThumb) { fixConnector = connection.Sink; dragConnector = connection.Source; } else if (sender == sinkDragThumb) { dragConnector = connection.Sink; fixConnector = connection.Source; } }
/*创建元素内容,固定结构*/ void GenerateDesignerItemContent(DesignerItem item, SolidColorBrush fontColorBrush) { if (item == null) return; var textblock = new TextBlock() { Name = "DesignerItemText", IsHitTestVisible = false, VerticalAlignment = VerticalAlignment.Center, Padding = new Thickness(5, 2, 5, 2), FontFamily = new FontFamily("Arial"), FontSize = FONT_SIZE, Foreground = fontColorBrush, DataContext = item.Data }; textblock.SetBinding(TextBlock.TextProperty, new Binding("Text")); item.Content = textblock; }
private void Group_Executed(object sender, ExecutedRoutedEventArgs e) { var items = from item in this.SelectionService.CurrentSelection.OfType<DesignerItem>() where item.ParentID == Guid.Empty select item; Rect rect = GetBoundingRectangle(items); DesignerItem groupItem = new DesignerItem(); groupItem.IsGroup = true; groupItem.Width = rect.Width; groupItem.Height = rect.Height; Canvas.SetLeft(groupItem, rect.Left); Canvas.SetTop(groupItem, rect.Top); Canvas groupCanvas = new Canvas(); groupItem.Content = groupCanvas; Canvas.SetZIndex(groupItem, this.Children.Count); this.Children.Add(groupItem); foreach (DesignerItem item in items) item.ParentID = groupItem.ID; this.SelectionService.SelectItem(groupItem); }
void Scroll(DesignerItem designerItem) { if (designerItem == null) return; var sv = (ScrollViewer)_diagramControl.Template.FindName("DesignerScrollViewer", _diagramControl); sv.ScrollToVerticalOffset(Canvas.GetTop(designerItem) - 400); sv.ScrollToHorizontalOffset(Canvas.GetLeft(designerItem) - 400); }
private void raiseDesignerItemRemoved(object item, DesignerItem designerItem) { var x = ItemRemoved; if (x != null) x(item, designerItem); raiseDesignerCanvasChanged(); }
double GetWidth(DesignerItem designerItem) { if (designerItem.Data != null && designerItem.Text != null) { string text = designerItem.Text; FormattedText formattedText = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), FONT_SIZE, Brushes.Black); double width = formattedText.Width + 12; double height = formattedText.Height; return width < MIN_ITEM_WIDTH ? MIN_ITEM_WIDTH : width; } else { return MIN_ITEM_WIDTH; } }
private void HitTesting(Point hitPoint) { bool hitConnectorFlag = false; DependencyObject hitObject = designerCanvas.InputHitTest(hitPoint) as DependencyObject; while (hitObject != null && hitObject != sourceConnector.ParentDesignerItem && hitObject.GetType() != typeof(DesignerCanvas)) { if (hitObject is Connector) { HitConnector = hitObject as Connector; hitConnectorFlag = true; } if (hitObject is DesignerItem) { HitDesignerItem = hitObject as DesignerItem; if (!hitConnectorFlag) HitConnector = null; return; } hitObject = VisualTreeHelper.GetParent(hitObject); } HitConnector = null; HitDesignerItem = null; }
/*元素文字控件*/ private TextBlock GetTextBlock(DesignerItem item) { return item.Content as TextBlock; }
public DesignerItem getElement(DragObject data) { if(data.data == null) { Debugger.Break(); // отсутствие данных return new DesignerItem { }; } if(data.data.ToString() == Class_Element.ElementName) { var refRes = new DesignerItem { Content = new Class_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Interface_Element.ElementName) { var refRes = new DesignerItem { Content = new Interface_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Objects_Element.ElementName) { var refRes = new DesignerItem { Content = new Objects_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Node_Element.ElementName) { var refRes = new DesignerItem { Content = new Node_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Package_Element.ElementName) { var refRes = new DesignerItem { Content = new Package_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Component_Element.ElementName) { var refRes = new DesignerItem { Content = new Component_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Remark_Element.ElementName) { var refRes = new DesignerItem { Content = new Remark_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Scenario_Element.ElementName) { var refRes = new DesignerItem { Content = new Scenario_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } if(data.data.ToString() == Actor_Element.ElementName) { var refRes = new DesignerItem { Content = new Actor_Element() }; refRes.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"), new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"), new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right") }; return refRes; } Debugger.Break(); // непредусмотренное название фигуры var res = new DesignerItem { }; res.Connectors = new Connector[]{ new Connector(ConnectorOrientation.Top, res, 0.5, 0, "Top"), new Connector(ConnectorOrientation.Bottom, res, 0.33, 1, "Bottom_Left"), new Connector(ConnectorOrientation.Bottom, res, 0.67, 1, "Bottom_Right"), new Connector(ConnectorOrientation.None, res, 0.5, 1, "Bottom_Center") }; return res; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } this.Children.Add(newItem); //update selection foreach (ISelectable item in this.SelectedItems) item.IsSelected = false; SelectedItems.Clear(); newItem.IsSelected = true; this.SelectedItems.Add(newItem); } e.Handled = true; } }
public DesignerItem AddDesignerItem(FrameworkElement item, Point position, Size? size, int layer = 0, bool insertInBackground = false, Guid? itemGuid = null) { DesignerItem newItem = new DesignerItem(); if (itemGuid != null) newItem.ID = itemGuid.Value; newItem.Content = item; newItem.Layer = layer; if (size.HasValue) { newItem.Width = size.Value.Width; newItem.Height = size.Value.Height; } DesignerCanvas.SetLeft(newItem, position.X); DesignerCanvas.SetTop(newItem, position.Y); //Canvas.SetZIndex(newItem, this.Children.Count); newItem.ZIndex = this.Children.Count; if (insertInBackground) { newItem.ZIndex = 0; this.Children.Insert(0, newItem); } else this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection //this.SelectionService.SelectItem(newItem); //newItem.Focus(); raiseDesignerItemAdded(item, newItem); bool layerVisible = false; if (!visibleLayers.TryGetValue(layer, out layerVisible) || layerVisible) { item.Visibility = System.Windows.Visibility.Visible; } else { item.Visibility = System.Windows.Visibility.Hidden; } //updateVisibleDesigneritems(); return newItem; }
List<DesignerItem> DrawDesignerItems(DesignerItem parentItem) { var designerItems = new List<DesignerItem>(); if (parentItem == null) return designerItems; if (designerItems.All(x => !x.ItemId.Equals(parentItem.ItemId)) && String.IsNullOrEmpty(parentItem.ItemParentId)) { DrawRoot(parentItem, parentItem.YIndex, parentItem.XIndex); } var childs = _diagramControl.DesignerItems.Where(x => x.ItemParentId == (parentItem.ItemId)); foreach (var childItem in childs) { if (designerItems.All(x => !x.ItemId.Equals(childItem.ItemId))) { DrawChild(parentItem, childItem); } designerItems.AddRange(DrawDesignerItems(childItem)); } return designerItems; }
internal void raiseLayerChanged(DesignerItem item, int layer) { var e = ItemLayerChanged; if (e != null) e(this, item, layer); }
/*隐藏了除了drag item以外的selected items*/ void HideOthers(DesignerItem selectedItem) { var selectedItems = GetSelectedItems(); selectedItem.IsExpanderVisible = false; foreach (var designerItem in selectedItems.Where(x => x.ItemId != selectedItem.ItemId)) { designerItem.Visibility = Visibility.Hidden; } }
private void SetConnectorDecoratorTemplate(DesignerItem item) { if (item.ApplyTemplate() && item.Content is UIElement) { ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement); Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; if (decorator != null && template != null) decorator.Template = template; } }
/*取得所有连接点*/ List<Connector> GetItemConnectors(DesignerItem designerItem) { var connectors = new List<Connector>(); var leftItemConnector = GetItemConnector(designerItem, "Left"); if (leftItemConnector != null) connectors.Add(leftItemConnector); var bottomItemConnector = GetItemConnector(designerItem, "Bottom"); if (bottomItemConnector != null) connectors.Add(bottomItemConnector); var topItemConnector = GetItemConnector(designerItem, "Top"); if (topItemConnector != null) connectors.Add(topItemConnector); var rightItemConnector = GetItemConnector(designerItem, "Right"); if (rightItemConnector != null) connectors.Add(rightItemConnector); return connectors; }
public void CreateHelperConnection(DesignerItem newParent, DesignerItem dragItem) { RemoveHelperConnection(); if (newParent == null) return; var source = GetItemConnector(newParent, PARENT_CONNECTOR); var sink = GetItemConnector(dragItem, CHILD_CONNECTOR); var connection = new Connection(source, sink); connection.toNewParent = true; source.Connections.Add(connection); _diagramControl.DesignerCanvas.Children.Add(connection); SetConnectionColor(connection, Brushes.Red); BringToFront(connection); }
/*根据名称,取得元素连接点*/ Connector GetItemConnector(DesignerItem item, string name) { var itemConnectorDecorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control; if (itemConnectorDecorator == null) return null; var itemConnector = itemConnectorDecorator.Template.FindName(name, itemConnectorDecorator) as Connector; return itemConnector; }
/*取得直接及间接的子节点*/ List<DesignerItem> GetAllSubItems(DesignerItem item/*某个节点*/) { var result = new List<DesignerItem>(); var child = new List<DesignerItem>(); var list = _diagramControl.DesignerItems .Where(x => x.ItemParentId == item.ItemId) .OrderBy(x => x.YIndex).ToList(); foreach (var subItem in list.Where(subItem => !result.Contains(subItem))) { child.Add(subItem); result.Add(subItem); foreach (var designerItem in child) { result.AddRange(GetAllSubItems(designerItem)); } } return result; }
/*取得所有连线*/ List<Connection> GetItemConnections(DesignerItem designerItem) { var connections = new List<Connection>(); var list = GetItemConnectors(designerItem); if (list.Count == 0) return connections; foreach (var c in list.Select(connector => connector.Connections.Where(x => x.Source != null && x.Sink != null)).Where(c => c.Any())) { connections.AddRange(c); } return connections; }
/*创建根节点*/ void DrawRoot(DesignerItem item, double topOffset, double leftOffset) { DrawDesignerItem(item, topOffset, leftOffset); item.CanCollapsed = false; item.IsExpanderVisible = false; }
void thumbDragThumb_DragCompleted(object sender, DragCompletedEventArgs e) { if (HitConnector != null) { if (connection != null) { if (connection.Source == fixConnector) connection.Sink = this.HitConnector; else connection.Source = this.HitConnector; } } this.HitDesignerItem = null; this.HitConnector = null; this.pathGeometry = null; this.connection.StrokeDashArray = null; this.InvalidateVisual(); }
/*取得元素上方最接近的元素*/ DesignerItem GetNewParent(DesignerItem selectedItem) { var selectedItems = GetSelectedItems(); //取得所有子节点,让parent不能为子节点 var subitems = new List<DesignerItem>(); foreach (var designerItem in selectedItems) { subitems.AddRange(GetAllSubItems(designerItem)); } subitems.AddRange(selectedItems); var pre = _diagramControl.DesignerItems.Where(x => x.Visibility.Equals(Visibility.Visible)); var list = (from designerItem in pre let parentTop = Canvas.GetTop(designerItem) + designerItem.ActualHeight - 13 let parentLeft = Canvas.GetLeft(designerItem) + designerItem.ActualWidth * 0.1 let parentRight = parentLeft + designerItem.ActualWidth where Canvas.GetTop(selectedItem) >= parentTop /*top位置小于自己的top位置*/ && Canvas.GetLeft(selectedItem) >= parentLeft && Canvas.GetLeft(selectedItem) <= parentRight && !Equals(designerItem, selectedItem) /*让parent不能为自己*/ && !subitems.Contains(designerItem) /*让parent不能为子节点*/ && designerItem.IsShadow == false select designerItem).ToList(); if (!list.Any()) return null; var parent = list.Aggregate((a, b) => a.YIndex > b.YIndex ? a : b); return parent; }
/*设定元素文字颜色*/ private void SetItemFontColor(DesignerItem item, SolidColorBrush fontColorBrush) { var textBlock = GetTextBlock(item); if (textBlock == null) return; textBlock.SetValue(TextBlock.ForegroundProperty, fontColorBrush); }