/// <summary> /// 拖动下面 /// </summary> /// <param name="scale"></param> /// <param name="item"></param> /// <param name="selectionService"></param> private void DragBottom(double scale, DesignerContainer item, SelectionService selectionService) { ///改变图元大小 var oldbottom = Canvas.GetTop(item); var oldheigth = item.Height; item.Height = (int)(oldheigth * scale); //计算更新后图元宽度 var newscale = item.Height / oldheigth; //计算更新后图元宽度由于取整数导致变更比例变化 var delta = (item.Height - oldheigth); //计算宽度差 //Canvas.SetTop(Item, oldleft - delta < 0 ? 0 : (oldleft - delta));//设置新图元左侧位置 ///遍历child图元,改变图元相对宽度与左侧位置 EnumAndChangeGroupChild(item, selectionService, oldbottom, (parent, child, oldparentleft) => { var oldchildbottom = Canvas.GetTop(child); child.Height = (child.Height * newscale); var newchildbottom = Canvas.GetTop(parent) + (oldchildbottom - oldparentleft) * newscale; Canvas.SetTop(child, newchildbottom); return(oldchildbottom); }); //else //{ // double groupItemwidth = Item.Width; // Item.Width = (Item.Width * scale); // double delta = (Item.Width - groupItemwidth); // double groupItemLeft = Canvas.GetLeft(Item); // Canvas.SetLeft(Item, groupItemLeft - delta < 0 ? 0 : (groupItemLeft - delta)); //} }
public static DesignerContainer Group(DesignerCanvas dc, IEnumerable <DesignerContainer> items) { if (items != null && dc != null) { var rect = GetBoundingRectangle(items); var groupItem = new DesignerContainer(); groupItem.IsGroup = true; groupItem.Width = rect.Width; groupItem.Height = rect.Height; m_oldLeft = rect.Left; m_oldTop = rect.Top; Canvas.SetLeft(groupItem, rect.Left); Canvas.SetTop(groupItem, rect.Top); var groupCanvas = new Canvas(); groupItem.Content = groupCanvas; Panel.SetZIndex(groupItem, dc.Children.Count); dc.Add(groupItem); foreach (var item in items) { item.ParentID = groupItem.ID; } dc.SelectionService.SelectItem(groupItem); groupItem.NameVisible = false; ///SaveOpt(mgr.CurrentCanvas, mgr); return(groupItem); } return(null); }
public void SelectContainer(DesignerContainer item) { //if (item == null || !item.Editable) return; if ((Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.None) { if (item.IsSelected) { SelectionService.RemoveFromSelection(item); } else { SelectionService.AddToSelection(item); } } else if (!item.IsSelected) { SelectionService.SelectItem(item); } item.Focus(); var pv = FindName("pv") as PropertyView; if (pv != null) { pv.InitProView(); if (this.DesignMode == MODE.RUN) { pv.ShowProView(true); } else { pv.ShowProView(false); } } }
public override bool UnRun(CommandManager mgr) { if (mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer.Count > 0) { DesignerContainer items = null; for (var i = 0; i < mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer.Count; i++) { items = mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer[i] as DesignerContainer; Canvas.SetLeft(items, m_oldLeft[i]); Canvas.SetTop(items, m_oldTop[i]); items.Width = m_oldWidth[i]; items.Height = m_oldHeight[i]; for (var j = 0; j <= m_angle.Count - 1; j++) { items.Angle = (m_angle[j] - 90) % 360; if (m_angleRedo == null) { m_angleRedo = new List <double>(); } m_angleRedo.Add(items.Angle); } } return(true); } return(false); }
public override bool Run(CommandManager mgr, params object[] param) { filename = param[0].ToString(); newfilename = param[0].ToString(); if (!String.IsNullOrEmpty(filename)) { foreach (var item in mgr.CurrentCanvas.Children.OfType <ISelectable>()) { var di = item as DesignerContainer; var idx = Panel.GetZIndex(di); if (idx == int.MinValue) { if (oldpicture == null) { oldpicture = new List <DesignerContainer>(); } oldpicture.Add(di); mgr.CurrentCanvas.Remove(di); break; } } #region //Image img = new Image(); //img.Source = new BitmapImage(new Uri(newFileName, UriKind.Relative)); //img.Stretch = Stretch.Fill; //CustomImage ci = new CustomImage(); //ci.FileName = filename.Substring(filename.LastIndexOf("\\") + 1, filename.Length - filename.LastIndexOf("\\") - 1); //ci.Style = mgr.CurrentCanvas.FindResource("ciStyle") as Style; //ci.NameVisible = false; //ci.Width = (this.Parent as Viewbox).ActualWidth; //ci.Height = (this.Parent as Viewbox).ActualHeight; #endregion var diBg = new DesignerContainer(); //diBg.Width = AppParams.CanvasWidth;// (this.Parent as Viewbox).ActualWidth; //diBg.Height = AppParams.CanvasHeight; //(this.Parent as Viewbox).ActualHeight; //diBg.Content = ci; diBg.StyleName = "ciStyle"; diBg.Focusable = false; diBg.IsEnabled = false; diBg.IsHitTestVisible = false; diBg.NameVisible = false; Canvas.SetLeft(diBg, 0); Canvas.SetTop(diBg, 0); Panel.SetZIndex(diBg, int.MinValue); if (newpicture == null) { newpicture = new List <DesignerContainer>(); } newpicture.Add(diBg); mgr.CurrentCanvas.Add(diBg); return(true); } return(false); }
//更新当前选择的图元的集合 private void UpdateSelection() { designerCanvas.SelectionService.ClearSelection(); if (startPoint != null && endPoint != null) { Rect rubberBand = new Rect(startPoint.Value, endPoint.Value); foreach (FrameworkElement item in designerCanvas.Children) { DesignerContainer di = item as DesignerContainer; if (di == null || !di.Editable) { continue; } //Rect itemRect = VisualTreeHelper.GetDescendantBounds(Item); //Rect itemBounds = Item.TransformToAncestor(designerCanvas).TransformBounds(itemRect); FrameworkElement content = di.Item; if (content == null) { continue; } Rect itemRect = VisualTreeHelper.GetDescendantBounds(content); Rect itemBounds = content.TransformToAncestor(designerCanvas).TransformBounds(itemRect); if (!rubberBand.Contains(itemBounds)) { continue; } //if (Item is Connection) // designerCanvas.SelectionService.AddToSelection(Item as ISelectable); //else //{ //DesignerItem di = Item as DesignerItem; int idx = Panel.GetZIndex(di); if (idx == int.MinValue) { continue; } if (di.ParentID == Guid.Empty) { designerCanvas.SelectionService.AddToSelection(di); } //} } } if (designerCanvas.SelectionService.SelectedDesignerContainer.Count > 0) { PropertyView pv = designerCanvas.FindName("pv") as PropertyView; if (pv != null) { pv.ShowProView(false); } } }
public static void Run(CommandManager cmgr, DesignerContainer di, string NewName, string OldName) { var Pa = new object[3]; Pa[0] = di; Pa[1] = NewName; Pa[2] = OldName; cmgr.Run <CommandChangeName>(Pa); }
private void Item_PreviewMouseMove(object sender, MouseEventArgs e) { DesignerContainer dci = sender as DesignerContainer; DesignerItem di = dci.Content as DesignerItem; if (di._DShowWindow != null) { di._DShowWindow(di); } }
protected override void OnPreviewMouseRightButtonDown(MouseButtonEventArgs e)//右击显示图元类型 { base.OnPreviewMouseRightButtonDown(e); DesignerContainer item = e.Source as DesignerContainer; if (item != null) { DesignerItem o = item.Content as DesignerItem; o._controlID = item.ID; o.ShowWindow(); } }
private static void EnumAndChangeGroupChild(DesignerContainer parent, double oldsize, Func <DesignerContainer, DesignerContainer, double, double> changeact) { if (parent.IsGroup && parent.ParentCanvas.SelectionService != null) //如果是图元组 { ///遍历child图元,改变图元相对大小 var childs = parent.ParentCanvas.SelectionService.GetGroupChilds(parent).Cast <DesignerContainer>(); foreach (var child in childs) { var chlidoldsize = changeact(parent, child, oldsize); EnumAndChangeGroupChild(child, chlidoldsize, changeact); } } }
public override bool UnRun(CommandManager mgr) { foreach (var de in m_de) { di = CommandGroupOperate.Group(mgr.CurrentCanvas, de); if (di == null) { return(false); } } return(true); }
public List <DesignerContainer> DeserializeDesignerItems(XElement root)// 从xml文件解析图元 { //CommandOpen.Run(CommManager, root); Dictionary <Guid, DesignerContainer> items = new Dictionary <Guid, DesignerContainer>(); IEnumerable <XElement> itemsXml = root.Elements("DesignerContainers").Elements(); foreach (XElement itemXml in itemsXml) { #region xml /* * <DesignerElement Version="1.0" Type="Wss.Foundation.Controls.DesignerContainer, Wss.Foundation"> * <Name>换热器</Name> * <Canvas.Left>522</Canvas.Left> * <Canvas.Top>257</Canvas.Top> * <Width>142</Width> * <Height>200</Height> * <Panel.ZIndex>20</Panel.ZIndex> * <ItemOpacity>1</ItemOpacity> * <LockDesign>False</LockDesign> * <WindowTip>False</WindowTip> * <NameVisible>True</NameVisible> * <NamePosition></NamePosition> * <Angle>0</Angle> * <BaseContainer.ScaleX>1</BaseContainer.ScaleX> * <BaseContainer.ScaleY>1</BaseContainer.ScaleY> * <BaseContainer.ID>ba33c2e8-f1d9-4d37-9d54-4d7a4800d720</BaseContainer.ID> * <BaseContainer.ParentID>00000000-0000-0000-0000-000000000000</BaseContainer.ParentID> * <BaseContainer.IsGroup>False</BaseContainer.IsGroup> * <DesignerElement Version="1.0" Type="Common.Package.HeatExchanger, Common.Package" /> * </DesignerElement> */ #endregion DesignerContainer item = DesignAttributeService.DeSerializFromXElement(itemXml) as DesignerContainer; // itemXml.ToDesignerContainer(); //从xml序列化成控件 Add(item); //item.Content有值的 if (!items.ContainsKey(item.ID)) { items.Add(item.ID, item); PropertyInfo[] ps = item.Content.GetType().GetProperties(); item.IsHitTestVisible = !(GetZIndex(item).Equals(int.MinValue)); item.Focusable = item.IsHitTestVisible; item.IsEnabled = item.IsHitTestVisible; item.IsSelected = false; item.PreviewMouseMove += Item_PreviewMouseMove; } } //InvalidateVisual(); return(items.Values.ToList()); }
public override bool UnRun(CommandManager mgr) { if (m_di.Count > 0) { DesignerContainer di = null; for (var i = 0; i <= m_di.Count - 1; i++) { di = m_di[i]; di.Height = m_oldheight[i]; } return(true); } return(false); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { _dragStartPoint = null; } if (!_dragStartPoint.HasValue) { return; } var di = Content as DesignerItem; if (di != null) { var dcontainer = new DesignerContainer(); dcontainer.Content = di; var panel = VisualTreeHelper.GetParent(this) as WrapPanel; var dataObject = new DragObject(); dataObject.Xaml = DesignAttributeService.SerializToXElement(dcontainer).ToString(); if (panel != null) { // desired size for DesignerCanvas is the stretched Toolbox Item size var scale = 1.0; dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); #region 用 //var dcontainer = new DesignerContainer(); //dcontainer.Content = item; //WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel; //DragObject dataObject = new DragObject(); //dataObject.Xaml= System.Windows.Markup.XamlWriter.Save(item);//dataObject.Xaml = DesignAttributeService.SerializToXElement(di).ToString(); //if (panel != null) //{ // var scale = 1.0; // dataObject.DesiredSize = new Size(panel.ItemWidth*scale, panel.ItemHeight*scale); //} ////DragDrop.DoDragDrop(this, di, DragDropEffects.Copy); //DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); #endregion } e.Handled = true; }
public override bool Run(CommandManager mgr, params object[] param) { var di = param[0] as DesignerContainer; m_di = di; if (di != null) { var idx = Panel.GetZIndex(di); if (idx == int.MinValue) { mgr.CurrentCanvas.Remove(di); } return(true); } return(false); }
public override bool Run(CommandManager mgr, params object[] param) { if (param != null) { if (param.Length == 3) { m_de = param[0] as DesignerContainer; m_NewName = param[1].ToString(); m_OldName = param[2].ToString(); return(true); } return(false); } return(false); }
//选择画布上的所有图元 internal void SelectAll() { ClearSelection(); //_currentSelection.AddRange(_designerCanvas.Children.OfType<ISelectable>()); //_currentSelection.ForEach(Item => { if ((Item as UIElement).IsEnabled) { Item.IsSelected = true; }}); foreach (var item in _designerCanvas.Children.OfType <ISelectable>()) { DesignerContainer di = (item as DesignerContainer); item.IsSelected = di == null ? true : di.IsEnabled && di.Editable; if (item.IsSelected) { SelectedDesignerContainer.Add(item); } } _dragResizeAdorner.UpdateAdorner(); }
public override bool UnRun(CommandManager mgr) { if (m_delist.Count > 0) { DesignerContainer di = null; for (var i = 0; i <= m_delist.Count - 1; i++) { di = m_delist[i]; if (di != null) { Canvas.SetLeft(di, m_oldPlaceList[i]); } } return(true); } return(false); }
public override bool ReRun(CommandManager mgr) { if (m_delist.Count > 0) { DesignerContainer di = null; for (var i = m_delist.Count - 1; i > -1; i--) { di = m_delist[i]; if (di != null) { Canvas.SetTop(di, m_newPlaceList[i] - m_delt[i]); } } return(true); } return(false); }
//等比缩放 public void UniformScale(DesignerContainer item, double scale, DragDeltaEventArgs e) { if (VerticalAlignment == VerticalAlignment.Top && HorizontalAlignment == HorizontalAlignment.Left) { if (Canvas.GetLeft(item) + e.VerticalChange < 0 || Canvas.GetTop(item) + e.VerticalChange < 0) { scale = 1; } DragTop(scale, item, Designer.SelectionService); DragLeft(scale, item, Designer.SelectionService); } else if (VerticalAlignment == VerticalAlignment.Top && HorizontalAlignment == HorizontalAlignment.Right) { if (Canvas.GetLeft(item) + item.Width - e.VerticalChange > Designer.ActualWidth || Canvas.GetTop(item) + e.VerticalChange < 0) { scale = 1; } DragTop(scale, item, Designer.SelectionService); DragRight(scale, item, Designer.SelectionService); } else if (VerticalAlignment == VerticalAlignment.Bottom && HorizontalAlignment == HorizontalAlignment.Left) { if (Canvas.GetLeft(item) - e.VerticalChange < 0 || Canvas.GetTop(item) + item.Height + e.VerticalChange > Designer.ActualHeight) { scale = 1; } DragBottom(scale, item, Designer.SelectionService); DragLeft(scale, item, Designer.SelectionService); } else if (VerticalAlignment == VerticalAlignment.Bottom && HorizontalAlignment == HorizontalAlignment.Right) { if (Canvas.GetLeft(item) + item.Width + e.VerticalChange > Designer.ActualWidth || Canvas.GetTop(item) + item.Height + e.VerticalChange > Designer.ActualHeight) { scale = 1; } DragBottom(scale, item, Designer.SelectionService); DragRight(scale, item, Designer.SelectionService); } }
public override bool ReRun(CommandManager mgr) { foreach (var item in mgr.CurrentCanvas.Children.OfType <ISelectable>()) { var di = item as DesignerContainer; if (oldpicture == null) { oldpicture = new List <DesignerContainer>(); } oldpicture.Add(di); var idx = Panel.GetZIndex(di); if (idx == int.MinValue) { mgr.CurrentCanvas.Remove(di); break; } } var diBg = new DesignerContainer(); //diBg.Width = AppParams.CanvasWidth;// (this.Parent as Viewbox).ActualWidth; //diBg.Height = AppParams.CanvasHeight; //(this.Parent as Viewbox).ActualHeight; //diBg.Content = ci; diBg.StyleName = "ciStyle"; diBg.Focusable = false; diBg.IsEnabled = false; diBg.IsHitTestVisible = false; diBg.NameVisible = false; Canvas.SetLeft(diBg, 0); Canvas.SetTop(diBg, 0); Panel.SetZIndex(diBg, int.MinValue); if (newpicture == null) { newpicture = new List <DesignerContainer>(); } newpicture.Add(diBg); mgr.CurrentCanvas.Add(diBg); return(true); }
public override bool ReRun(CommandManager mgr) { if (m_DesignerContainer.Count() > 1) { DesignerContainer di = null; for (var i = m_DesignerContainer.Count - 1; i > -1; i--) { di = m_DesignerContainer[i]; if (di != null) { Canvas.SetLeft(di, newleft[i] - m_delta[i]); } } return(true); } return(false); }
public override bool ReRun(CommandManager mgr) { if (M_list.Count > 0) { DesignerContainer di = null; for (var j = 0; j < mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer.Count; j++) { di = mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer[j] as DesignerContainer; if (m_newscaleX != null) { for (var i = 0; i <= m_newscaleX.Count - 1; i++) { di.ScaleX = m_newscaleX[i]; } } } return(true); } return(false); }
public override bool UnRun(CommandManager mgr) { if (m_DesignerContainer.Count() > 1) { DesignerContainer di = null; for (var i = 0; i <= m_DesignerContainer.Count - 1; i++) { di = m_DesignerContainer[i]; if (di != null) { Canvas.SetLeft(di, oldleft[i]); } } return(true); } return(false); }
public override bool ReRun(CommandManager mgr) { if (mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer.Count > 0) { DesignerContainer item = null; for (var i = 0; i < mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer.Count; i++) { item = mgr.CurrentCanvas.SelectionService.SelectedDesignerContainer[i] as DesignerContainer; Canvas.SetLeft(item, m_newLeft[i]); Canvas.SetTop(item, m_newTop[i]); item.Height = m_newWidth[i]; item.Width = m_newHeight[i]; for (var j = 0; j <= m_angle.Count - 1; j++) { item.Angle = (m_angle[j]) % 360; } } return(true); } return(false); }
public string CreateNewName(CommandManager mgr, DesignerContainer di) { var name = "新建图元"; //name = name.Length > 4 ? name.Substring(0, 4) : name; //if (string.IsNullOrEmpty(name)) //{ // name = "新建图元"; //} index = 0; var nameList = mgr.CurrentCanvas.Children.OfType <DesignerContainer>() .ToDictionary(item => item.Name, item => item.ID); int i = nameList.Count - 1; while (nameList.ContainsKey(name)) { i++; name = "新建图元" + i; } return(name); }
public override bool UnRun(CommandManager mgr) { DesignerContainer item = null; for (var i = 0; i < M_list.Count; i++) { item = M_list[i] as DesignerContainer; Canvas.SetLeft(item, m_oldLeft[i]); Canvas.SetTop(item, m_oldTop[i]); item.Width = m_oldWidth[i]; item.Height = m_oldHeight[i]; for (var j = 0; j <= m_angle.Count - 1; j++) { //Item.Angle = (m_angle[i] ) % 360; item.Angle = (m_angle[j] + 90) % 360; if (m_angleRedo == null) { m_angleRedo = new List <double>(); } m_angleRedo.Add(item.Angle); } } return(true); }
public override bool ReRun(CommandManager mgr) { DesignerContainer item = null; if (M_list.Count > 0) { for (var i = 0; i < M_list.Count; i++) { item = M_list[i] as DesignerContainer; Canvas.SetTop(item, m_newTop[i]); Canvas.SetLeft(item, m_newLeft[i]); item.Height = m_newWidth[i]; item.Width = m_newHeight[i]; for (var j = 0; j <= m_angle.Count - 1; j++) { item.Angle = (m_angle[j]) % 360; } } return(true); } return(false); }
public override bool Run(CommandManager mgr, params object[] param) { dc = param[0] as DesignerCanvas; var di = param[1] as DesignerContainer; if (dc != null) { m_di = di; dc.Add(di); dc.SelectionService.SelectItem(di); } var adornerLayer = AdornerLayer.GetAdornerLayer(dc); // PolylineAdorner adorner = dc.m_pAdorner; //if (adornerLayer != null && adorner != null) //{ // if (adorner.IsMouseCaptured) // { // adorner.ReleaseMouseCapture(); // } // adornerLayer.Remove(adorner); //} return(true); }
public static void Run(CommandManager cmgr, DesignerContainer item) { cmgr.Run <CommandDeleteBg>(item); }