public DeleteShapeCommand(ObservableCollection<Shape> _shapes, ObservableCollection<Connection> _connections, Shape _shapeToDelete) { shapes = _shapes; connections = _connections; shapeToDelete = _shapeToDelete; // if x,y of either of connection endpoint shapes, remove connection // TODO alternatively use id connectionsToDelete = _connections.Where(x => (_shapeToDelete.X == x.End.X && _shapeToDelete.Y == x.End.Y) || (_shapeToDelete.X == x.Start.X && _shapeToDelete.Y == x.Start.Y)).ToList(); //TODO check if it works }
public Connection(Shape _start, string _startMultiplicity, Shape _end, string _endMultiplicity, ConnectionType _type) { start = _start; startMultiplicity = _startMultiplicity; end = _end; endMultiplicity = _endMultiplicity; type = _type; //double vec0X = 1; //double vec0Y = 0; //double vec1X = _end.CanvasCenterX - _start.CanvasCenterX; //double vec1Y = _end.CanvasCenterY - _start.CanvasCenterY; //double phi1 = Math.Acos((vec0X * vec1X) / (Math.Sqrt(Math.Pow(vec1X, 2) + Math.Pow(vec1Y, 2)))); //double phi2 = Math.Acos((vec0Y * vec1Y) / (Math.Sqrt(Math.Pow(vec1X, 2) + Math.Pow(vec1Y, 2)))); //if (Math.Abs(_start.CanvasCenterX - _end.CanvasCenterX) < _start.Width) //{ // startX = _start.CanvasCenterX; //} //else if(_start.CanvasCenterX > _end.CanvasCenterX) //{ // startX = _start.CanvasCenterX - _start.Width/2; //} //else //{ // startX = _start.CanvasCenterX + _start.Width/2; //} //if(Math.Abs(_start.CanvasCenterY - _end.CanvasCenterY) < _start.Height) //{ // startY = _start.CanvasCenterY; //}else if(_start.CanvasCenterY > _end.CanvasCenterY) //{ // startY = _start.CanvasCenterY - _start.Height/2; //} //else //{ // startY = _start.CanvasCenterY + _start.Height/2; //} startPoint = new Point(); p1 = new Point(); p2 = new Point(); endPoint = new Point(); startPoint.X = _start.CanvasCenterX;// + (_start.CanvasCenterX < _end.CanvasCenterX ? _start.Width / 2 : -_start.Width / 2); startPoint.Y = _start.CanvasCenterY;// + (_start.CanvasCenterY < _end.CanvasCenterY ? _start.Height / 2 : -_start.Height / 2); endPoint.X = _end.CanvasCenterX;// + (_start.CanvasCenterX < _end.CanvasCenterX ? -_end.Width / 2 : _end.Width / 2); endPoint.Y = _end.CanvasCenterY;// + (_start.CanvasCenterY < _end.CanvasCenterY ? -_end.Height / 2 : _end.Height / 2); p1.X = _start.CanvasCenterX; p1.Y = (_start.CanvasCenterY + _end.CanvasCenterY) / 2.0; p2.Y = P1.Y; p2.X = _end.CanvasCenterX; }