/// <summary> /// Deletes an element and its connections /// </summary> private void Delete() { if (SelectedObject is Connector) { RemoveConnectionByConnector(SelectedObject as Connector); } if (SelectedObject is Node) { var node = SelectedObject as Node; Connectors.Where(x => x.Start == node || x.End == node).ToList().ForEach(x => RemoveConnectionByConnector(x)); Nodes.Remove(node); } if (SelectedObject is Transition) { var transition = SelectedObject as Transition; Connectors.Where(x => x.Start == transition || x.End == transition).ToList().ForEach(x => RemoveConnectionByConnector(x)); Transitions.Remove(transition); } if (SelectedObject is InputLadder) { var input = SelectedObject as InputLadder; Connectors.Where(x => x.Start == input || x.End == input).ToList().ForEach(x => RemoveConnectionByConnector(x)); Inputs.Remove(input); } if (SelectedObject is OutputLadder) { var output = SelectedObject as OutputLadder; Connectors.Where(x => x.Start == output || x.End == output).ToList().ForEach(x => RemoveConnectionByConnector(x)); Outputs.Remove(output); } if (SelectedObject is NotInputLadder) { var notInput = SelectedObject as NotInputLadder; Connectors.Where(x => x.Start == notInput || x.End == notInput).ToList().ForEach(x => RemoveConnectionByConnector(x)); NotInputs.Remove(notInput); } if (SelectedObject is NotOutputLadder) { var notOutput = SelectedObject as NotOutputLadder; Connectors.Where(x => x.Start == notOutput || x.End == notOutput).ToList().ForEach(x => RemoveConnectionByConnector(x)); NotOutputs.Remove(notOutput); } if (SelectedObject is InterNode) { var interNode = SelectedObject as InterNode; if (Connections.First(x => InterNodes.Contains(interNode)) != null) { RemoveConnectionByConnector(Connectors.First(x => x.Start == interNode || x.End == interNode)); } else { Connectors.Where(x => x.Start == interNode || x.End == interNode).ToList().ForEach(x => Connectors.Remove(x)); InterNodes.Remove(interNode); } } }
public void CreateNewConnection() { // Create a new interNode that will be previewed as the SelectedObject var newInterNode = new InterNode() { Name = "InterNode" + (InterNodes.Count + 1), IsNew = true }; InterNodes.Add(newInterNode); SelectedObject = newInterNode; // Create a connector that will be referenced as interConnector and connect the PreviousObject with the new Internode var connector = new Connector() { Name = "Connector" + (Connectors.Count + 1), IsNew = true, }; Connectors.Add(connector); interConnector = connector; interConnector.Start = PreviousObject; // We only create a logic connection if it is starting from a Logic Element // Because if the PreviousObject is not a logic element, that means it is an interNode // and we're still building a connection. if (PreviousObject is LogicElement) { newConnection = new Connection(); Connections.Add(newConnection); newConnection.Start = PreviousObject as LogicElement; newConnection.Connectors.Add(connector); } }
/// <summary> /// Clear all observable collections /// </summary> private void ClearData() { InterNodes.Clear(); Connections.Clear(); Connectors.Clear(); Nodes.Clear(); Transitions.Clear(); Inputs.Clear(); Outputs.Clear(); NotInputs.Clear(); NotOutputs.Clear(); }
/// <summary> /// Removes the Objects that are still in preview mode /// </summary> public void RemoveNewObjects() { Connectors.Where(x => (x.Start != null && x.Start.IsNew) || (x.End != null && x.End.IsNew)).ToList().ForEach(x => Connectors.Remove(x)); Nodes.Where(x => x.IsNew).ToList().ForEach(x => Nodes.Remove(x)); Transitions.Where(x => x.IsNew).ToList().ForEach(x => Transitions.Remove(x)); InterNodes.Where(x => x.IsNew).ToList().ForEach(x => InterNodes.Remove(x)); Connectors.Where(x => x.IsNew).ToList().ForEach(x => Connectors.Remove(x)); Inputs.Where(x => x.IsNew).ToList().ForEach(x => Inputs.Remove(x)); NotInputs.Where(x => x.IsNew).ToList().ForEach(x => NotInputs.Remove(x)); Outputs.Where(x => x.IsNew).ToList().ForEach(x => Outputs.Remove(x)); NotOutputs.Where(x => x.IsNew).ToList().ForEach(x => NotOutputs.Remove(x)); }
/// <summary> /// Searches for a DiagramObject in the observable collections of the DiagramData with the sames coordinates as the DiagramObject parameter /// This only makes sense if the user doesn't places two DiagramObject on the same coordinates of the Grid /// </summary> /// <param name="diagramObject">Diagram object parameter</param> /// <returns>Null or the DiagramObject</returns> internal DiagramObject GetDiagramObject(DiagramObject diagramObject) { if (diagramObject == null) { return(null); } DiagramObject diag; diag = Nodes.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = InterNodes.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = Transitions.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = Inputs.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = Outputs.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = NotInputs.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); if (diag != null) { return(diag); } diag = NotOutputs.ToList().Find(e => e != null && !e.IsNew && e.X == diagramObject.X && e.Y == diagramObject.Y); return(diag); }