Skip to content

v2.1.0

Latest
Compare
Choose a tag to compare
@ledjon-behluli ledjon-behluli released this 11 Apr 19:54
· 3 commits to master since this release

This release enhances the APIs responsible for making the connections between the Simulink elements. The outcome is a much nicer looking block diagram.

It is worth to mention that this is not a breaking release, as the new functionalities are optional additions to the current methods used to build the connections. Your program will compile and run just fine.

The Samples project includes usages of the new APIs.


2 new interfaces have been added:

  • IPathDirection
  • IPathDirectionDistance

Interfaces

IPathDirection

Contains 4 methods that are used to tell the library in which direction it should move or branch from the source to the destination element in the diagram.

Signature

public interface IPathDirection
{
    IPathDirectionDistance Upward();
    IPathDirectionDistance Downward();
    IPathDirectionDistance Leftward();
    IPathDirectionDistance Rightward();
}

Used by

The following methods now take an Action<IPathDirection> as an optional parameter.

ISystemBranch Towards(string destinationBlockName, uint destinationBlockPort = 1, Action<IPathDirection> direction = null);
ISystemBranch ThanConnect(string destinationBlockName, uint destinationBlockPort = 1, Action<IPathDirection> direction = null);
ISystemLine Connect(string sourceBlockName, string destinationBlockName, uint sourceBlockPort = 1, uint destinationBlockPort = 1, Action<IPathDirection> direction = null);
ISystemLine ThanConnect(string destinationBlockName, uint destinationBlockPort = 1, Action<IPathDirection> direction = null);

IPathDirectionDistance

Contains 2 methods that are used to tell the library whether you want to apply manual corrections by either lengthening or shortening the current line.

Signature

public interface IPathDirectionDistance
{
    void Lengthen(uint distance);
    void Shorten(uint distance);
}
  • Lengthen - By specifying this, you tell the library that you want to extend the current connection line length, by the specified distance.
  • Shorten- By specifying this, you tell the library that you want to contract the current connection line length, by the specified distance.

Used by

Used internally by the implementation component of IPathDirection, to apply the specified distance.

Example (Unformatted)

The following code (available in v2.0.0):

cs.AddConnections("Step", c =>
	c.ThanConnect("Sum")
	 .ThanConnect("PID Controller")
	 .ThanConnect("TransferFcn")
	 .Branch(b => b.Towards("Scope"))
	 .Branch(b =>
	     b.Towards("Gain")
	      .ThanConnect("Sum", 2))
	 .Branch(b => b.Towards("Product", 1))
	 .Branch(b =>
	     b.Towards("Product", 2)
	      .ThanConnect("Gain1")
	      .ThanConnect("Scope1"))
	 .Branch(b =>
	     b.Towards("Gain2")
	      .ThanConnect("Add", 1))
	 .Branch(b =>
	     b.Towards("Gain3")
	      .ThanConnect("Add", 2)
	      .ThanConnect("Scope2"))
	 .Connect("Constant", "Scope", 1, 2)
);

Generates the block diagram shown below.

alt text

Example (Formatted)

The APIs exposed by IPathDirection can be used to build upon the existing API.

The following code:

cs.AddConnections("Step", c =>
	c.ThanConnect("Sum")
	 .ThanConnect("PID Controller")
	 .ThanConnect("TransferFcn")
	 .Branch(b => b.Towards("Scope"))
	 .Branch(b =>
	     b.Towards("Gain", direction: x => x.Downward())
	      .ThanConnect("Sum", 2, x => x.Leftward()))
	 .Branch(b => b.Towards("Product", 1, x => x.Upward()))
	 .Branch(b =>
	     b.Towards("Product", 2, x => x.Upward())
	      .ThanConnect("Gain1")
	      .ThanConnect("Scope1"))
	 .Branch(b =>
	     b.Towards("Gain2", direction: x => x.Downward())
	      .ThanConnect("Add", 1, x => x.Downward()))
	 .Branch(b =>
	     b.Towards("Gain3", direction: x => x.Downward())
	      .ThanConnect("Add", 2, x => x.Upward())
	      .ThanConnect("Scope2"))
	 .Connect("Constant", "Scope", 1, 2, x => x.Rightward())
);

Generates the block diagram shown below. Which is much nicer looking.

alt text

Example (Formatted and corrected)

Although the above example shows a much cleaner diagram (which you can easily tweak inside Simulink to make it perfect).
You can go 1 step further and apply corrections by yourself, using the APIs exposed by IPathDirectionDistance.

The following code:

cs.AddConnections("Step", c =>
	c.ThanConnect("Sum")
     .ThanConnect("PID Controller")
     .ThanConnect("TransferFcn")
     .Branch(b => b.Towards("Scope"))
     .Branch(b =>
         b.Towards("Gain", direction: x => x.Downward())
          .ThanConnect("Sum", 2, x => x.Leftward().Lengthen(10)))
     .Branch(b => b.Towards("Product", 1, x => x.Upward().Lengthen(5)))
     .Branch(b =>
         b.Towards("Product", 2, x => x.Upward().Shorten(10))
          .ThanConnect("Gain1")
          .ThanConnect("Scope1"))
     .Branch(b =>
         b.Towards("Gain2", direction: x => x.Downward())
          .ThanConnect("Add", 1, x => x.Downward().Shorten(5)))
     .Branch(b =>
         b.Towards("Gain3", direction: x => x.Downward())
          .ThanConnect("Add", 2, x => x.Upward().Shorten(10))
          .ThanConnect("Scope2"))
     .Connect("Constant", "Scope", 1, 2, x => x.Rightward().Shorten(50))
);

Generates the block diagram shown below. Which is an even better looking.

alt text