/// <summary> /// Checks validity of current route. /// </summary> /// <returns>Validated wire route.</returns> public override ValidatedRoute GetValidated() { ValidatedRoute validatedRoute = new ValidatedRoute(); // Less than thee nodes is always valid from the nodes point of view. var nodes = this.ToArray(); if (NumNodes < 3) { for (int i = 0; i < NumNodes; ++i) { validatedRoute.Nodes.Add(new ValidatedNode() { Node = nodes[i], Valid = true }); } } // More than two nodes. Intermediate nodes may not be body fixed, connecting or winch. else { validatedRoute.Nodes.Add(new ValidatedNode() { Node = nodes[0], Valid = true }); for (int i = 1; i < NumNodes - 1; ++i) { WireRouteNode node = nodes[i]; string errorString = node.Type == Wire.NodeType.BodyFixedNode || node.Type == Wire.NodeType.ConnectingNode || node.Type == Wire.NodeType.WinchNode ? node.Type.ToString().SplitCamelCase() + " can only be at the begin or at the end of a wire." : string.Empty; validatedRoute.Nodes.Add(new ValidatedNode() { Node = node, Valid = (errorString == string.Empty), ErrorString = errorString }); } validatedRoute.Nodes.Add(new ValidatedNode() { Node = nodes[NumNodes - 1], Valid = true }); } if (NumNodes < 2) { validatedRoute.Valid = false; validatedRoute.ErrorString = "Route has to contain at least two or more nodes."; } else { bool nodesValid = true; foreach (var validatedNode in validatedRoute.Nodes) { nodesValid &= validatedNode.Valid; } validatedRoute.Valid = nodesValid; validatedRoute.ErrorString = "One or more nodes are wrong."; } return(validatedRoute); }
public virtual ValidatedRoute GetValidated() { ValidatedRoute validatedRoute = new ValidatedRoute(); foreach ( var node in this ) validatedRoute.Nodes.Add( new ValidatedNode() { Node = node, Valid = true } ); return validatedRoute; }