protected override void OnDrop(DragEventArgs e) { if (SelectionCount > 1) { return; } base.OnDrop(e); if (e.Data.GetData("shape") is GraphShape _shape) { Point _p = e.GetPosition(this); GraphShape _newShape = graphControl.ToDragAndDrop; Point _point = AddShapeOnGraph(_newShape, _p.X, _p.Y); _shape.TypeInfo.LeftPosition = _p.X; _shape.TypeInfo.TopPosition = _p.Y; Project.AddShape(_shape.TypeInfo); if (SelectedItem != null && SelectedItem is GraphShape _current) { Connect(_current, _newShape); _current.LinkTo(_newShape); } SelectedItem = _newShape; } }
/// <summary> /// Retire la ShapeTypeInfo de _shape du GraphProject. /// Suprime physiquement la shape du graph, ainsi que ses connections entrantes (lignes), /// appèle _shape.LinkedBy.TypeInfo.Remove(_shape.TypeInfo), /// puis suprime en cascade les shapes qui lui sont liées en connection sortantes. /// </summary> private void RemoveShapeFromGraph(GraphShape _shape) { if (_shape != null) { Project.ShapeInfos.Remove(_shape.TypeInfo); List <RadDiagramConnection> _connectionsToRemove = new List <RadDiagramConnection>(); foreach (RadDiagramConnection _connection in _shape.IncomingLinks) { _connectionsToRemove.Add(_connection); } foreach (RadDiagramConnection _connection in _connectionsToRemove) { RemoveConnection(_connection); } SelectedItem = _shape; Delete(); // if (_shape.LinkedBy != null) { _shape.LinkedBy.Remove(_shape.TypeInfo); } // // supression en cascade des shapes liée en connection sortante ShapeTypeInfo[] _accepteds = _shape.TypeInfo.AcceptedShapes.ToArray(); foreach (ShapeTypeInfo _typeInfo in _accepteds) { RemoveShapeFromGraph(Shape(_typeInfo)); } } graphControl.CurrentShape = null; }
protected override void OnDeleteCommandExecutedOverride(object sender, ExecutedRoutedEventArgs e) { GraphShape _selected = SelectedItem as GraphShape; RemoveShapeFromGraph(_selected); base.OnDeleteCommandExecutedOverride(sender, e); }
/// <summary> /// Ajoute une GraphShape sur le graph à la position indiquée par _left, _top. /// </summary> public Point AddShapeOnGraph(GraphShape _shape, double _left, double _top) { double _zoom = Zoom; _left = (_left + Viewport.Left); _top = (_top + Viewport.Top); AddShape(_shape, new Point(_left, _top)); _shape.TypeInfo.IsOnGraph = true; return(new Point(_left, _top)); }
private void Connect(GraphShape _source, GraphShape _target) { RadDiagramConnection _connection = new RadDiagramConnection(); _connection.AllowDelete = false; _connection.AllowCut = false; _connection.AllowCopy = false; _connection.ConnectionType = Telerik.Windows.Diagrams.Core.ConnectionType.Bezier; _connection.Source = _source; _connection.Target = _target; AddConnection(_connection); }
private void SetShapesOnLayoutReusables() { __layoutReusableShapes.Clear(); __layoutReusableShapes.MaxWidth = 150; foreach (ShapeTypeInfo _type in ReusableShapesTypeInfos()) { GraphShape _shape = new GraphShape(_type); _shape.Height = _type.Height + 10; if (_type.Width + 10 > __layoutReusableShapes.MaxWidth) { __layoutReusableShapes.MaxWidth = _type.Width + 10; } __layoutReusableShapes.Add(_shape); } }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonDown(e); __oldMousePos = e.GetPosition(null); ToDragAndDrop = ShapeUnderMouse(); if (ToDragAndDrop != null) { GraphShape _new = __typesDescription.ShapeFactory(ToDragAndDrop.TypeInfo.TypeName); if (ToDragAndDrop.TypeInfo.IsOnGraph == true) { _new.TypeInfo.EditableComponents.Clear(); foreach (Base _component in ToDragAndDrop.TypeInfo.EditableComponents) { _new.TypeInfo.AddEditableComponent(_component); } } ToDragAndDrop = _new; } }
private void SetShapesOnLayoutShapes() { List <string> _types = null; if (__graph.Shapes.Count == 0) { _types = new List <string>() { __typesDescription.RootType().TypeName } } ; else { _types = __currentShape?.TypeInfo.CanAcceptList(); } __layoutShapes.Clear(); __layoutShapes.MaxWidth = 150; if (_types == null) { return; } foreach (string _type in _types) { GraphShape _shape = __typesDescription.ShapeFactory(_type); _shape.Height = _shape.TypeInfo.Height + 10; if (_shape.TypeInfo.Width + 10 > __layoutShapes.MaxWidth) { __layoutShapes.MaxWidth = _shape.TypeInfo.Width + 10; } __layoutShapes.Add(_shape); } }
public void LinkTo(GraphShape _shape) { TypeInfo.Accept(_shape.TypeInfo); _shape.LinkedBy = this.TypeInfo; }