internal ISystemLine Build(string sourceBlockName, string destinationBlockName, uint sourceBlockPort = 1, uint destinationBlockPort = 1, Action <IPathDirection> direction = null) { if (string.IsNullOrEmpty(sourceBlockName)) { throw new SimulinkModelGeneratorException("Source block name can not be null or empty."); } if (string.IsNullOrEmpty(destinationBlockName)) { throw new SimulinkModelGeneratorException("Destination block name can not be null or empty."); } if (sourceBlockPort == 0) { throw new SimulinkModelGeneratorException("Source block port number can not be zero."); } if (destinationBlockPort == 0) { throw new SimulinkModelGeneratorException("Destination block port number can not be zero."); } PathDirectionBuilder builder = new PathDirectionBuilder(model); Line newLine = new Line() { P = new List <Parameter>() { new Parameter() { Name = "SrcBlock", Text = sourceBlockName }, new Parameter() { Name = "SrcPort", Text = sourceBlockPort.ToString() }, builder.CalculateBranchPoint(sourceBlockName, destinationBlockName, direction), new Parameter() { Name = "DstBlock", Text = destinationBlockName }, new Parameter() { Name = "DstPort", Text = destinationBlockPort.ToString() }, } }; if (this.model.System.Line.Exists(newLine)) { throw new SimulinkModelGeneratorException("Connection already exists!"); } this.model.System.Line.Add(newLine); this.previousBlockName = destinationBlockName; return(this); }
public ISystemBranch Towards(string destinationBlockName, uint destinationBlockPort = 1, Action <IPathDirection> direction = null) { PathDirectionBuilder builder = new PathDirectionBuilder(model); Line matchedLine = this.model.System.Line.FirstOrDefault(l => l.P.Any(p => p.Name == "SrcBlock" && p.Text == previousBlockName)); if (matchedLine == null) { this.model.System.Line.Add(new Line() { P = new List <Parameter>() { new Parameter() { Name = "SrcBlock", Text = previousBlockName }, new Parameter() { Name = "SrcPort", Text = "1" }, new Parameter() { Name = "Points", Text = CalculateMidPoint(previousBlockName, destinationBlockName) } }, Branch = new List <Branch>() { new Branch() { Parameters = new List <Parameter>() { builder.CalculateBranchPoint(previousBlockName, destinationBlockName, direction), // Important: 'Points' needs to be the first parameter in the list new Parameter() { Name = "DstBlock", Text = destinationBlockName }, new Parameter() { Name = "DstPort", Text = destinationBlockPort.ToString() } } } } }); } else { matchedLine.Branch.Add(new Branch() { Parameters = new List <Parameter>() { builder.CalculateBranchPoint(previousBlockName, destinationBlockName, direction), // Important: 'Points' needs to be the first parameter in the list new Parameter() { Name = "DstBlock", Text = destinationBlockName }, new Parameter() { Name = "DstPort", Text = destinationBlockPort.ToString() } } }); } this.previousBlockName = destinationBlockName; return(this); }