private void MmiCut_Click(object sender, RoutedEventArgs e) { _copies.Clear(); foreach (var child in canvas.Children) { PrimitiveBase pb = child as PrimitiveBase; PrimitiveBase pbNew = null; if (pb != null && pb.IsSelected) { pbNew = pb.Clone() as PrimitiveBase; _copies.Add(pbNew); } } for (int i = canvas.Children.Count - 1; i >= 0; i--) { PrimitiveBase pb = canvas.Children[i] as PrimitiveBase; if (pb != null && pb.IsSelected) { canvas.Children.RemoveAt(i); if (PrimitiveDeleted != null) { PrimitiveDeleted(this, EventArgs.Empty); } } } }
private void Select(Rect rect) { for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null) { if (rect.Contains(g.RenderedGeometry.Bounds)) { g.IsSelected = true; //RectangleGeometry rects = new RectangleGeometry(rect); //System.Windows.Shapes. Path myPath = new System.Windows.Shapes.Path(); //myPath.Stroke = Brushes.Black; //myPath.StrokeThickness = 1; //myPath.Data = rects; //canvas.Children.Add(myPath); } } } }
private void MmiPaste_Click(object sender, RoutedEventArgs e) { List <PrimitiveBase> bsList = new List <PrimitiveBase>(); foreach (PrimitiveBase pb in _copies) { PrimitiveBase clone = pb.Clone() as PrimitiveBase; clone.Move(5, -5); canvas.Children.Add(clone); clone.cmdActionType = "add"; bsList.Add(clone); //ToolManager.Instance._undoStk.Push(clone); if (PrimitiveAdded != null) { PrimitiveAdded(this, EventArgs.Empty); } } if (bsList.Count > 0) { PrimitiveStackChanged(CommandActionType.Add, bsList); } btnPointer.IsChecked = true; }
public void Add(PrimitiveBase prim) { prim.Scale = scale.ScaleX; prim.Moved += Primitive_Moved; canvas.Children.Add(prim); if (PrimitiveAdded != null) { PrimitiveAdded(this, EventArgs.Empty); } }
private void CanHit(bool hit) { for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null) { g.IsHitTestVisible = hit; } } }
private void SetScale(double scale) { for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null) { g.Scale = scale; } } }
public void Unselect(int index) { PrimitiveBase prim = canvas.Children[index + 1] as PrimitiveBase; prim.IsSelected = false; if (SelectionChanged != null) { SelectionChanged(this, EventArgs.Empty); } }
public void Invalidate() { for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase prim = canvas.Children[i] as PrimitiveBase; if (prim != null) { prim.InvalidateVisual(); } } }
private void SelectAll(bool select) { for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null) { g.IsSelected = select; } } }
private void MmiCopy_Click(object sender, RoutedEventArgs e) { _copies.Clear(); foreach (var child in canvas.Children) { PrimitiveBase pb = child as PrimitiveBase; if (pb != null && pb.IsSelected) { _copies.Add(pb); } } }
private List <PrimitiveBase> GetSelections() { _selections.Clear(); for (int i = 1; i < canvas.Children.Count; ++i) { PrimitiveBase prim = canvas.Children[i] as PrimitiveBase; if (prim != null && prim.IsSelected) { _selections.Add(prim); } } return(_selections); }
public void Select(int index) { PrimitiveBase prim = null; if (index < 0) { } else { prim = canvas.Children[index + 1] as PrimitiveBase; prim.IsSelected = true; if (SelectionChanged != null) { SelectionChanged(this, EventArgs.Empty); } } }
private void Cm_Opened(object sender, RoutedEventArgs e) { bool found = false; foreach (var child in canvas.Children) { PrimitiveBase pb = child as PrimitiveBase; if (pb != null && pb.IsSelected) { found = true; } } ContextMenu cm = sender as ContextMenu; ((MenuItem)(cm.Items[0])).IsEnabled = found; ((MenuItem)(cm.Items[1])).IsEnabled = found; ((MenuItem)(cm.Items[2])).IsEnabled = _copies.Count > 0 || _cutsList.Count > 0; ((MenuItem)(cm.Items[2])).IsEnabled = _polyLine != null; }
private void WorldListView_SelectedIndexChanged(object sender, EventArgs e) { ListView listView = sender as ListView; if (listView != null && listView.SelectedItems.Count > 0) { WorldListViewItem selectItem = listView.SelectedItems[0] as WorldListViewItem; if (selectItem != null && selectItem.rtObject != null) { if (selectItem.rtObject is PrimitiveBase) { PrimitiveBase primitive = selectItem.rtObject as PrimitiveBase; if (primitive != null) { primitive.Select(); } } ActivePropertyPanel(selectItem.rtObject); } } }
public void Clear() { for (int i = canvas.Children.Count - 1; i >= 1; --i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null) { canvas.Children.Remove(g); } } if (PrimitiveDeleted != null) { PrimitiveDeleted(this, EventArgs.Empty); } if (SelectionChanged != null) { SelectionChanged(this, EventArgs.Empty); } }
private void Delete() { bool deleted = false; List <PrimitiveBase> bsList = new List <PrimitiveBase>(); for (int i = canvas.Children.Count - 1; i >= 1; --i) { PrimitiveBase g = canvas.Children[i] as PrimitiveBase; if (g != null && g.IsSelected) { g.cmdActionType = "del"; g.PrmIndex = i; bsList.Add(g); canvas.Children.Remove(g); deleted = true; } } if (deleted) { if (bsList.Count > 0) { var tlist = bsList.OrderBy(d => d.PrmIndex).ToList(); PrimitiveStackChanged(CommandActionType.Del, tlist); } if (PrimitiveDeleted != null) { PrimitiveDeleted(this, EventArgs.Empty); } if (SelectionChanged != null) { SelectionChanged(this, EventArgs.Empty); } } }
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ToolManager.Instance.Get(_tool).MouseUp(canvas, e, canvas.ScreenToWorld); if (_tool == ToolType.Polyline) { return; } List <PrimitiveBase> pbsList = new List <PrimitiveBase>(); if (_tool != ToolType.Pointer) { PrimitiveBase prim = canvas.Children[canvas.Children.Count - 1] as PrimitiveBase; pbsList = new List <PrimitiveBase>(); _canvasList.Add(prim); prim.cmdActionType = "add"; prim.PrmIndex = canvas.Children.Count - 1; prim.Moved += Primitive_Moved; if (PrimitiveAdded != null) { PrimitiveAdded(this, EventArgs.Empty); pbsList.Add(prim); PrimitiveStackChanged(CommandActionType.Add, pbsList); } } else { if (GetSelections().Count > 0) { PrimitiveBase prim = GetSelections()[0]; pbsList = new List <PrimitiveBase>(); if (prim.cmdActionType == "move" || (prim.cmdActionType == string.Empty && prim.IsChange > 0)) { //bool d=canvas.Children.Contains(prim); if (prim.GetType().Name.ToLower() == "line" || prim.GetType().Name.ToLower() == "axis" || prim.GetType().Name.ToLower() == "dot" || prim.GetType().Name.ToLower() == "polyline" || prim.GetType().Name.ToLower() == "rectangle") { if (PrimitiveStackChanged != null) { pbsList.Add(prim); prim.PrmIndex = canvas.Children.IndexOf(prim); PrimitiveStackChanged(CommandActionType.Move, pbsList); prim.cmdActionType = string.Empty; prim.IsChange = -1; } } } } else { foreach (var childPrim in canvas.Children) { PrimitiveBase prm = childPrim as PrimitiveBase; if (prm != null && !prm.IsSelected) { prm.cmdActionType = string.Empty; prm.IsChange = -1; } } } } btnPointer.IsChecked = true; }